drtm_res_address_map.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2022 Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <plat/common/platform.h>
  8. #include <services/drtm_svc.h>
  9. #include <platform_def.h>
  10. /* Address map revision generated by this code. */
  11. #define DRTM_ADDRESS_MAP_REVISION U(0x0001)
  12. /* Amount of space needed for address map based on PLAT_DRTM_MMAP_ENTRIES */
  13. #define DRTM_ADDRESS_MAP_SIZE (sizeof(drtm_memory_region_descriptor_table_t) + \
  14. (sizeof(drtm_mem_region_t) * \
  15. PLAT_DRTM_MMAP_ENTRIES))
  16. /* Allocate space for DRTM-formatted address map to be constructed. */
  17. static uint8_t drtm_address_map[DRTM_ADDRESS_MAP_SIZE];
  18. static uint64_t drtm_address_map_size;
  19. drtm_memory_region_descriptor_table_t *drtm_build_address_map(void)
  20. {
  21. /* Set up pointer to DRTM memory map. */
  22. drtm_memory_region_descriptor_table_t *map =
  23. (drtm_memory_region_descriptor_table_t *)drtm_address_map;
  24. /* Get the platform memory map. */
  25. const mmap_region_t *mmap = plat_get_addr_mmap();
  26. unsigned int i;
  27. /* Set up header for address map structure. */
  28. map->revision = DRTM_ADDRESS_MAP_REVISION;
  29. map->reserved = 0x0000;
  30. /* Iterate through mmap and generate DRTM address map. */
  31. for (i = 0U; mmap[i].base_pa != 0UL; i++) {
  32. /* Set PA of region. */
  33. map->region[i].region_address = mmap[i].base_pa;
  34. /* Set size of region (in 4kb chunks). */
  35. map->region[i].region_size_type = 0;
  36. ARM_DRTM_REGION_SIZE_TYPE_SET_4K_PAGE_NUM(
  37. map->region[i].region_size_type,
  38. mmap[i].size / PAGE_SIZE_4KB);
  39. /* Set type and cacheability. */
  40. switch (MT_TYPE(mmap[i].attr)) {
  41. case MT_DEVICE:
  42. ARM_DRTM_REGION_SIZE_TYPE_SET_REGION_TYPE(
  43. map->region[i].region_size_type,
  44. ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_DEVICE);
  45. break;
  46. case MT_NON_CACHEABLE:
  47. ARM_DRTM_REGION_SIZE_TYPE_SET_REGION_TYPE(
  48. map->region[i].region_size_type,
  49. ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_NCAR);
  50. ARM_DRTM_REGION_SIZE_TYPE_SET_CACHEABILITY(
  51. map->region[i].region_size_type,
  52. ARM_DRTM_REGION_SIZE_TYPE_CACHEABILITY_NC);
  53. break;
  54. case MT_MEMORY:
  55. ARM_DRTM_REGION_SIZE_TYPE_SET_REGION_TYPE(
  56. map->region[i].region_size_type,
  57. ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_NORMAL);
  58. break;
  59. default:
  60. return NULL;
  61. }
  62. }
  63. map->num_regions = i;
  64. /* Store total size of address map. */
  65. drtm_address_map_size = sizeof(drtm_memory_region_descriptor_table_t);
  66. drtm_address_map_size += (i * sizeof(drtm_mem_region_t));
  67. return map;
  68. }
  69. uint64_t drtm_get_address_map_size(void)
  70. {
  71. return drtm_address_map_size;
  72. }