arm_tzc_dmc500.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <platform_def.h>
  8. #include <common/debug.h>
  9. #include <drivers/arm/tzc_dmc500.h>
  10. #include <plat/arm/common/plat_arm.h>
  11. /*******************************************************************************
  12. * Initialize the DMC500-TrustZone Controller for ARM standard platforms.
  13. * When booting an EL3 payload, this is simplified: we configure region 0 with
  14. * secure access only and do not enable any other region.
  15. ******************************************************************************/
  16. void arm_tzc_dmc500_setup(tzc_dmc500_driver_data_t *plat_driver_data,
  17. const arm_tzc_regions_info_t *tzc_regions)
  18. {
  19. #ifndef EL3_PAYLOAD_BASE
  20. unsigned int region_index = 1U;
  21. const arm_tzc_regions_info_t *p;
  22. const arm_tzc_regions_info_t init_tzc_regions[] = {
  23. ARM_TZC_REGIONS_DEF,
  24. {0}
  25. };
  26. #endif
  27. assert(plat_driver_data);
  28. INFO("Configuring DMC-500 TZ Settings\n");
  29. tzc_dmc500_driver_init(plat_driver_data);
  30. #ifndef EL3_PAYLOAD_BASE
  31. if (tzc_regions == NULL)
  32. p = init_tzc_regions;
  33. else
  34. p = tzc_regions;
  35. /* Region 0 set to no access by default */
  36. tzc_dmc500_configure_region0(TZC_REGION_S_NONE, 0);
  37. /* Rest Regions set according to tzc_regions array */
  38. for (; p->base != 0ULL; p++) {
  39. tzc_dmc500_configure_region(region_index, p->base, p->end,
  40. p->sec_attr, p->nsaid_permissions);
  41. region_index++;
  42. }
  43. INFO("Total %u regions set.\n", region_index);
  44. #else
  45. /* Allow secure access only to DRAM for EL3 payloads */
  46. tzc_dmc500_configure_region0(TZC_REGION_S_RDWR, 0);
  47. #endif
  48. /*
  49. * Raise an exception if a NS device tries to access secure memory
  50. * TODO: Add interrupt handling support.
  51. */
  52. tzc_dmc500_set_action(TZC_ACTION_RV_LOWERR);
  53. /*
  54. * Flush the configuration settings to have an affect. Validate
  55. * flush by checking FILTER_EN is set on region 1 attributes
  56. * register.
  57. */
  58. tzc_dmc500_config_complete();
  59. /*
  60. * Wait for the flush to complete.
  61. * TODO: Have a timeout for this loop
  62. */
  63. while (tzc_dmc500_verify_complete())
  64. ;
  65. }