emi_mpu.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2021, 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 <platform_def.h>
  9. #define ENABLE_EMI_MPU_SW_LOCK 1
  10. #define EMI_MPU_CTRL (EMI_MPU_BASE + 0x000)
  11. #define EMI_MPU_DBG (EMI_MPU_BASE + 0x004)
  12. #define EMI_MPU_SA0 (EMI_MPU_BASE + 0x100)
  13. #define EMI_MPU_EA0 (EMI_MPU_BASE + 0x200)
  14. #define EMI_MPU_SA(region) (EMI_MPU_SA0 + (region * 4))
  15. #define EMI_MPU_EA(region) (EMI_MPU_EA0 + (region * 4))
  16. #define EMI_MPU_APC0 (EMI_MPU_BASE + 0x300)
  17. #define EMI_MPU_APC(region, dgroup) (EMI_MPU_APC0 + (region * 4) + (dgroup * 0x100))
  18. #define EMI_MPU_CTRL_D0 (EMI_MPU_BASE + 0x800)
  19. #define EMI_MPU_CTRL_D(domain) (EMI_MPU_CTRL_D0 + (domain * 4))
  20. #define EMI_RG_MASK_D0 (EMI_MPU_BASE + 0x900)
  21. #define EMI_RG_MASK_D(domain) (EMI_RG_MASK_D0 + (domain * 4))
  22. #define EMI_MPU_START (0x000)
  23. #define EMI_MPU_END (0x93C)
  24. #define SUB_EMI_MPU_CTRL (SUB_EMI_MPU_BASE + 0x000)
  25. #define SUB_EMI_MPU_DBG (SUB_EMI_MPU_BASE + 0x004)
  26. #define SUB_EMI_MPU_SA0 (SUB_EMI_MPU_BASE + 0x100)
  27. #define SUB_EMI_MPU_EA0 (SUB_EMI_MPU_BASE + 0x200)
  28. #define SUB_EMI_MPU_SA(region) (SUB_EMI_MPU_SA0 + (region * 4))
  29. #define SUB_EMI_MPU_EA(region) (SUB_EMI_MPU_EA0 + (region * 4))
  30. #define SUB_EMI_MPU_APC0 (SUB_EMI_MPU_BASE + 0x300)
  31. #define SUB_EMI_MPU_APC(region, dgroup) (SUB_EMI_MPU_APC0 + (region * 4) + (dgroup * 0x100))
  32. #define SUB_EMI_MPU_CTRL_D0 (SUB_EMI_MPU_BASE + 0x800)
  33. #define SUB_EMI_MPU_CTRL_D(domain) (SUB_EMI_MPU_CTRL_D0 + (domain * 4))
  34. #define SUB_EMI_RG_MASK_D0 (SUB_EMI_MPU_BASE + 0x900)
  35. #define SUB_EMI_RG_MASK_D(domain) (SUB_EMI_RG_MASK_D0 + (domain * 4))
  36. #define EMI_MPU_DOMAIN_NUM (16)
  37. #define EMI_MPU_REGION_NUM (32)
  38. #define EMI_MPU_ALIGN_BITS (16)
  39. #define DRAM_OFFSET (0x40000000 >> EMI_MPU_ALIGN_BITS)
  40. #define NO_PROTECTION 0
  41. #define SEC_RW 1
  42. #define SEC_RW_NSEC_R 2
  43. #define SEC_RW_NSEC_W 3
  44. #define SEC_R_NSEC_R 4
  45. #define FORBIDDEN 5
  46. #define SEC_R_NSEC_RW 6
  47. #define LOCK 1
  48. #define UNLOCK 0
  49. #define EMI_MPU_DGROUP_NUM (EMI_MPU_DOMAIN_NUM / 8)
  50. #if (EMI_MPU_DGROUP_NUM == 1)
  51. #define SET_ACCESS_PERMISSION(apc_ary, lock, d7, d6, d5, d4, d3, d2, d1, d0) \
  52. do { \
  53. apc_ary[1] = 0; \
  54. apc_ary[0] = \
  55. (((unsigned int) d7) << 21) | (((unsigned int) d6) << 18) | \
  56. (((unsigned int) d5) << 15) | (((unsigned int) d4) << 12) | \
  57. (((unsigned int) d3) << 9) | (((unsigned int) d2) << 6) | \
  58. (((unsigned int) d1) << 3) | ((unsigned int) d0) | \
  59. ((unsigned int) lock << 31); \
  60. } while (0)
  61. #elif (EMI_MPU_DGROUP_NUM == 2)
  62. #define SET_ACCESS_PERMISSION(apc_ary, lock, d15, d14, d13, d12, d11, d10, \
  63. d9, d8, d7, d6, d5, d4, d3, d2, d1, d0) \
  64. do { \
  65. apc_ary[1] = \
  66. (((unsigned int) d15) << 21) | (((unsigned int) d14) << 18) | \
  67. (((unsigned int) d13) << 15) | (((unsigned int) d12) << 12) | \
  68. (((unsigned int) d11) << 9) | (((unsigned int) d10) << 6) | \
  69. (((unsigned int) d9) << 3) | ((unsigned int) d8); \
  70. apc_ary[0] = \
  71. (((unsigned int) d7) << 21) | (((unsigned int) d6) << 18) | \
  72. (((unsigned int) d5) << 15) | (((unsigned int) d4) << 12) | \
  73. (((unsigned int) d3) << 9) | (((unsigned int) d2) << 6) | \
  74. (((unsigned int) d1) << 3) | ((unsigned int) d0) | \
  75. ((unsigned int) lock << 31); \
  76. } while (0)
  77. #endif
  78. struct emi_region_info_t {
  79. unsigned long long start;
  80. unsigned long long end;
  81. unsigned int region;
  82. unsigned int apc[EMI_MPU_DGROUP_NUM];
  83. };
  84. void emi_mpu_init(void);
  85. #endif