optee.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #define OPTEE_MAGIC 0x4554504f
  12. #define OPTEE_VERSION 1
  13. #define OPTEE_ARCH_ARM32 0
  14. #define OPTEE_ARCH_ARM64 1
  15. struct optee_header {
  16. uint32_t magic;
  17. uint8_t version;
  18. uint8_t arch;
  19. uint16_t flags;
  20. uint32_t init_size;
  21. uint32_t init_load_addr_hi;
  22. uint32_t init_load_addr_lo;
  23. uint32_t init_mem_usage;
  24. uint32_t paged_size;
  25. };
  26. static inline uint32_t optee_image_get_entry_point(const image_header_t *hdr)
  27. {
  28. struct optee_header *optee_hdr = (struct optee_header *)(hdr + 1);
  29. return optee_hdr->init_load_addr_lo;
  30. }
  31. static inline uint32_t optee_image_get_load_addr(const image_header_t *hdr)
  32. {
  33. return optee_image_get_entry_point(hdr) - sizeof(struct optee_header);
  34. }
  35. #if defined(CONFIG_OPTEE)
  36. int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start,
  37. unsigned long tzdram_len, unsigned long image_len);
  38. #else
  39. static inline int optee_verify_image(struct optee_header *hdr,
  40. unsigned long tzdram_start,
  41. unsigned long tzdram_len,
  42. unsigned long image_len)
  43. {
  44. return -EPERM;
  45. }
  46. #endif
  47. #if defined(CONFIG_OPTEE)
  48. int optee_verify_bootm_image(unsigned long image_addr,
  49. unsigned long image_load_addr,
  50. unsigned long image_len);
  51. #else
  52. static inline int optee_verify_bootm_image(unsigned long image_addr,
  53. unsigned long image_load_addr,
  54. unsigned long image_len)
  55. {
  56. return -EPERM;
  57. }
  58. #endif
  59. #if defined(CONFIG_OPTEE) && defined(CONFIG_OF_LIBFDT)
  60. int optee_copy_fdt_nodes(const void *old_blob, void *new_blob);
  61. #else
  62. static inline int optee_copy_fdt_nodes(const void *old_blob, void *new_blob)
  63. {
  64. return 0;
  65. }
  66. #endif
  67. #endif /* _OPTEE_H */