hikey_common.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <arch_helpers.h>
  8. #include <common/bl_common.h>
  9. #include <common/debug.h>
  10. #include <lib/mmio.h>
  11. #include <lib/xlat_tables/xlat_tables.h>
  12. #include <plat/common/platform.h>
  13. #include <hikey_def.h>
  14. #include <hikey_layout.h>
  15. #define MAP_DDR MAP_REGION_FLAT(DDR_BASE, \
  16. DDR_SIZE - DDR_SEC_SIZE, \
  17. MT_DEVICE | MT_RW | MT_NS)
  18. #define MAP_DEVICE MAP_REGION_FLAT(DEVICE_BASE, \
  19. DEVICE_SIZE, \
  20. MT_DEVICE | MT_RW | MT_SECURE)
  21. #define MAP_TSP_MEM MAP_REGION_FLAT(TSP_SEC_MEM_BASE, \
  22. TSP_SEC_MEM_SIZE, \
  23. MT_MEMORY | MT_RW | MT_SECURE)
  24. #define MAP_ROM_PARAM MAP_REGION_FLAT(XG2RAM0_BASE, \
  25. BL1_XG2RAM0_OFFSET, \
  26. MT_DEVICE | MT_RO | MT_SECURE)
  27. #define MAP_SRAM MAP_REGION_FLAT(SRAM_BASE, \
  28. SRAM_SIZE, \
  29. MT_DEVICE | MT_RW | MT_SECURE)
  30. /*
  31. * BL1 needs to access the areas of MMC_SRAM.
  32. * BL1 loads BL2 from eMMC into SRAM before DDR initialized.
  33. */
  34. #define MAP_MMC_SRAM MAP_REGION_FLAT(HIKEY_BL1_MMC_DESC_BASE, \
  35. HIKEY_BL1_MMC_DESC_SIZE + \
  36. HIKEY_BL1_MMC_DATA_SIZE, \
  37. MT_DEVICE | MT_RW | MT_SECURE)
  38. /*
  39. * Table of regions for different BL stages to map using the MMU.
  40. * This doesn't include Trusted RAM as the 'mem_layout' argument passed to
  41. * hikey_init_mmu_elx() will give the available subset of that,
  42. */
  43. #ifdef IMAGE_BL1
  44. static const mmap_region_t hikey_mmap[] = {
  45. MAP_DEVICE,
  46. MAP_ROM_PARAM,
  47. MAP_MMC_SRAM,
  48. {0}
  49. };
  50. #endif
  51. #ifdef IMAGE_BL2
  52. static const mmap_region_t hikey_mmap[] = {
  53. MAP_DDR,
  54. MAP_DEVICE,
  55. MAP_TSP_MEM,
  56. MAP_SRAM,
  57. {0}
  58. };
  59. #endif
  60. #ifdef IMAGE_BL31
  61. static const mmap_region_t hikey_mmap[] = {
  62. MAP_DEVICE,
  63. MAP_SRAM,
  64. MAP_TSP_MEM,
  65. {0}
  66. };
  67. #endif
  68. #ifdef IMAGE_BL32
  69. static const mmap_region_t hikey_mmap[] = {
  70. MAP_DEVICE,
  71. MAP_DDR,
  72. {0}
  73. };
  74. #endif
  75. /*
  76. * Macro generating the code for the function setting up the pagetables as per
  77. * the platform memory map & initialize the mmu, for the given exception level
  78. */
  79. #define HIKEY_CONFIGURE_MMU_EL(_el) \
  80. void hikey_init_mmu_el##_el(unsigned long total_base, \
  81. unsigned long total_size, \
  82. unsigned long ro_start, \
  83. unsigned long ro_limit, \
  84. unsigned long coh_start, \
  85. unsigned long coh_limit) \
  86. { \
  87. mmap_add_region(total_base, total_base, \
  88. total_size, \
  89. MT_MEMORY | MT_RW | MT_SECURE); \
  90. mmap_add_region(ro_start, ro_start, \
  91. ro_limit - ro_start, \
  92. MT_MEMORY | MT_RO | MT_SECURE); \
  93. mmap_add_region(coh_start, coh_start, \
  94. coh_limit - coh_start, \
  95. MT_DEVICE | MT_RW | MT_SECURE); \
  96. mmap_add(hikey_mmap); \
  97. init_xlat_tables(); \
  98. \
  99. enable_mmu_el##_el(0); \
  100. }
  101. /* Define EL1 and EL3 variants of the function initialising the MMU */
  102. HIKEY_CONFIGURE_MMU_EL(1)
  103. HIKEY_CONFIGURE_MMU_EL(3)
  104. unsigned long plat_get_ns_image_entrypoint(void)
  105. {
  106. return HIKEY_NS_IMAGE_OFFSET;
  107. }
  108. unsigned int plat_get_syscnt_freq2(void)
  109. {
  110. return 1200000;
  111. }