emi_mpu.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2022-2023, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef EMI_MPU_H
  7. #define EMI_MPU_H
  8. #include <emi_mpu_priv.h>
  9. #include <platform_def.h>
  10. #define NO_PROTECTION (0)
  11. #define SEC_RW (1)
  12. #define SEC_RW_NSEC_R (2)
  13. #define SEC_RW_NSEC_W (3)
  14. #define SEC_R_NSEC_R (4)
  15. #define FORBIDDEN (5)
  16. #define SEC_R_NSEC_RW (6)
  17. #define LOCK (1UL)
  18. #define UNLOCK (0)
  19. #if (EMI_MPU_DGROUP_NUM == 1)
  20. #define SET_ACCESS_PERMISSION(apc_ary, lock, d7, d6, d5, d4, d3, d2, d1, d0) \
  21. do { \
  22. apc_ary[1] = 0; \
  23. apc_ary[0] = \
  24. (((unsigned int) d7) << 21) | (((unsigned int) d6) << 18) | \
  25. (((unsigned int) d5) << 15) | (((unsigned int) d4) << 12) | \
  26. (((unsigned int) d3) << 9) | (((unsigned int) d2) << 6) | \
  27. (((unsigned int) d1) << 3) | ((unsigned int) d0) | \
  28. ((unsigned int) lock << 31); \
  29. } while (0)
  30. #elif (EMI_MPU_DGROUP_NUM == 2)
  31. #define SET_ACCESS_PERMISSION(apc_ary, lock, d15, d14, d13, d12, d11, d10, \
  32. d9, d8, d7, d6, d5, d4, d3, d2, d1, d0) \
  33. do { \
  34. apc_ary[1] = \
  35. (((unsigned int) d15) << 21) | (((unsigned int) d14) << 18) | \
  36. (((unsigned int) d13) << 15) | (((unsigned int) d12) << 12) | \
  37. (((unsigned int) d11) << 9) | (((unsigned int) d10) << 6) | \
  38. (((unsigned int) d9) << 3) | ((unsigned int) d8); \
  39. apc_ary[0] = \
  40. (((unsigned int) d7) << 21) | (((unsigned int) d6) << 18) | \
  41. (((unsigned int) d5) << 15) | (((unsigned int) d4) << 12) | \
  42. (((unsigned int) d3) << 9) | (((unsigned int) d2) << 6) | \
  43. (((unsigned int) d1) << 3) | ((unsigned int) d0) | \
  44. ((unsigned int) lock << 31); \
  45. } while (0)
  46. #endif
  47. struct emi_region_info_t {
  48. unsigned long long start;
  49. unsigned long long end;
  50. unsigned int region;
  51. unsigned int apc[EMI_MPU_DGROUP_NUM];
  52. };
  53. enum MPU_REQ_ORIGIN_ZONE_ID {
  54. MPU_REQ_ORIGIN_TEE_ZONE_SVP = 0,
  55. MPU_REQ_ORIGIN_TEE_ZONE_TUI = 1,
  56. MPU_REQ_ORIGIN_TEE_ZONE_WFD = 2,
  57. MPU_REQ_ORIGIN_TEE_ZONE_MAX = 3,
  58. MPU_REQ_ORIGIN_ZONE_INVALID = 0x7FFFFFFF,
  59. };
  60. int emi_mpu_init(void);
  61. int emi_mpu_optee_handler(uint64_t encoded_addr, uint64_t zone_size,
  62. uint64_t zone_info);
  63. int emi_mpu_set_protection(struct emi_region_info_t *region_info);
  64. int emi_mpu_clear_protection(unsigned int region);
  65. void set_emi_mpu_regions(void);
  66. int set_apu_emi_mpu_region(void);
  67. #endif