optee.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /*
  3. * OP-TEE related definitions
  4. *
  5. * (C) Copyright 2016 Linaro Limited
  6. * Andrew F. Davis <andrew.davis@linaro.org>
  7. */
  8. #ifndef _OPTEE_H
  9. #define _OPTEE_H
  10. #include <linux/errno.h>
  11. #include <image.h>
  12. #define OPTEE_MAGIC 0x4554504f
  13. #define OPTEE_VERSION 1
  14. #define OPTEE_ARCH_ARM32 0
  15. #define OPTEE_ARCH_ARM64 1
  16. struct optee_header {
  17. uint32_t magic;
  18. uint8_t version;
  19. uint8_t arch;
  20. uint16_t flags;
  21. uint32_t init_size;
  22. uint32_t init_load_addr_hi;
  23. uint32_t init_load_addr_lo;
  24. uint32_t init_mem_usage;
  25. uint32_t paged_size;
  26. };
  27. static inline uint32_t
  28. optee_image_get_entry_point(const struct image_header *hdr)
  29. {
  30. struct optee_header *optee_hdr = (struct optee_header *)(hdr + 1);
  31. return optee_hdr->init_load_addr_lo;
  32. }
  33. static inline uint32_t
  34. optee_image_get_load_addr(const struct image_header *hdr)
  35. {
  36. return optee_image_get_entry_point(hdr) - sizeof(struct optee_header);
  37. }
  38. #if defined(CONFIG_OPTEE)
  39. int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start,
  40. unsigned long tzdram_len, unsigned long image_len);
  41. #else
  42. static inline int optee_verify_image(struct optee_header *hdr,
  43. unsigned long tzdram_start,
  44. unsigned long tzdram_len,
  45. unsigned long image_len)
  46. {
  47. return -EPERM;
  48. }
  49. #endif
  50. #if defined(CONFIG_OPTEE)
  51. int optee_verify_bootm_image(unsigned long image_addr,
  52. unsigned long image_load_addr,
  53. unsigned long image_len);
  54. #else
  55. static inline int optee_verify_bootm_image(unsigned long image_addr,
  56. unsigned long image_load_addr,
  57. unsigned long image_len)
  58. {
  59. return -EPERM;
  60. }
  61. #endif
  62. #if defined(CONFIG_OPTEE) && defined(CONFIG_OF_LIBFDT)
  63. int optee_copy_fdt_nodes(const void *old_blob, void *new_blob);
  64. #else
  65. static inline int optee_copy_fdt_nodes(const void *old_blob, void *new_blob)
  66. {
  67. return 0;
  68. }
  69. #endif
  70. #endif /* _OPTEE_H */