apm_hal.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "hal/assert.h"
  7. #include "hal/apm_hal.h"
  8. #include "hal/apm_ll.h"
  9. #include "hal/log.h"
  10. void apm_tee_hal_set_master_secure_mode(apm_ll_apm_ctrl_t apm_ctrl, apm_ll_master_id_t master_id, apm_ll_secure_mode_t sec_mode)
  11. {
  12. apm_tee_ll_set_master_secure_mode(apm_ctrl, master_id, sec_mode);
  13. }
  14. void apm_tee_hal_clk_gating_enable(bool enable)
  15. {
  16. apm_tee_ll_clk_gating_enable(enable);
  17. }
  18. void apm_hal_apm_ctrl_region_filter_enable(apm_ll_apm_ctrl_t apm_ctrl, uint32_t regn_num, bool enable)
  19. {
  20. apm_ll_apm_ctrl_region_filter_enable(apm_ctrl, regn_num, enable);
  21. }
  22. void apm_hal_apm_ctrl_filter_enable(apm_ctrl_path_t *apm_path, bool enable)
  23. {
  24. apm_ll_apm_ctrl_filter_enable(apm_path->apm_ctrl, apm_path->apm_m_path, enable);
  25. }
  26. void apm_hal_apm_ctrl_filter_enable_all(bool enable)
  27. {
  28. apm_ctrl_path_t apm_path;
  29. for (int i = 0; i < HP_APM_MAX_ACCESS_PATH; i++) {
  30. apm_path.apm_ctrl = HP_APM_CTRL;
  31. apm_path.apm_m_path = i;
  32. apm_hal_apm_ctrl_filter_enable(&apm_path, enable);
  33. }
  34. for (int i = 0; i < LP_APM_MAX_ACCESS_PATH; i++) {
  35. apm_path.apm_ctrl = LP_APM_CTRL;
  36. apm_path.apm_m_path = i;
  37. apm_hal_apm_ctrl_filter_enable(&apm_path, enable);
  38. }
  39. #if CONFIG_IDF_TARGET_ESP32C6
  40. for (int i = 0; i < LP_APM0_MAX_ACCESS_PATH; i++) {
  41. apm_path.apm_ctrl = LP_APM0_CTRL;
  42. apm_path.apm_m_path = i;
  43. apm_hal_apm_ctrl_filter_enable(&apm_path, enable);
  44. }
  45. #endif
  46. }
  47. void apm_hal_apm_ctrl_region_config(const apm_ctrl_region_config_data_t *pms_data)
  48. {
  49. HAL_ASSERT(pms_data);
  50. apm_ll_apm_ctrl_set_region_start_address(pms_data->apm_ctrl, pms_data->regn_num, pms_data->regn_start_addr);
  51. apm_ll_apm_ctrl_set_region_end_address(pms_data->apm_ctrl, pms_data->regn_num, pms_data->regn_end_addr);
  52. apm_ll_apm_ctrl_sec_mode_region_attr_config(pms_data->apm_ctrl, pms_data->regn_num, pms_data->sec_mode, pms_data->regn_pms);
  53. }
  54. uint8_t apm_hal_apm_ctrl_exception_status(apm_ctrl_path_t *apm_path)
  55. {
  56. return apm_ll_apm_ctrl_exception_status(apm_path->apm_ctrl, apm_path->apm_m_path);
  57. }
  58. void apm_hal_apm_ctrl_exception_clear(apm_ctrl_path_t *apm_path)
  59. {
  60. apm_ll_apm_ctrl_exception_clear(apm_path->apm_ctrl, apm_path->apm_m_path);
  61. }
  62. void apm_hal_apm_ctrl_get_exception_info(apm_ctrl_exception_info_t *excp_info)
  63. {
  64. apm_ll_apm_ctrl_get_exception_info(excp_info);
  65. }
  66. void apm_hal_apm_ctrl_interrupt_enable(apm_ctrl_path_t *apm_path, bool enable)
  67. {
  68. apm_ll_apm_ctrl_interrupt_enable(apm_path->apm_ctrl, apm_path->apm_m_path, enable);
  69. }
  70. void apm_hal_apm_ctrl_clk_gating_enable(apm_ll_apm_ctrl_t apm_ctrl, bool enable)
  71. {
  72. apm_ll_apm_ctrl_clk_gating_enable(apm_ctrl, enable);
  73. }
  74. void apm_hal_apm_ctrl_master_sec_mode_config(apm_ctrl_secure_mode_config_t *sec_mode_data)
  75. {
  76. apm_ctrl_path_t apm_path;
  77. /* Configure given secure mode for all specified Masters. */
  78. for (int i = 0; i < APM_LL_MASTER_MAX; i++) {
  79. if (sec_mode_data->master_ids & (1 << i)) {
  80. apm_tee_hal_set_master_secure_mode(sec_mode_data->apm_ctrl, i, sec_mode_data->sec_mode);
  81. }
  82. }
  83. /* Configure the given APM Ctrl for all Masters for the:
  84. * - Secure mode,
  85. * - Regions range,
  86. * - access permissions and
  87. * - region filter
  88. */
  89. for (int i = 0; i < sec_mode_data->regn_count; i++) {
  90. sec_mode_data->pms_data[i].sec_mode = sec_mode_data->sec_mode;
  91. sec_mode_data->pms_data[i].apm_ctrl = sec_mode_data->apm_ctrl;
  92. apm_hal_apm_ctrl_region_config(&sec_mode_data->pms_data[i]);
  93. apm_hal_apm_ctrl_region_filter_enable(sec_mode_data->pms_data[i].apm_ctrl, i,
  94. sec_mode_data->pms_data[i].filter_enable);
  95. }
  96. /* Configure APM Ctrl access path(M[0:n]) */
  97. for (int i = 0; i < sec_mode_data->apm_m_cnt; i++) {
  98. apm_path.apm_ctrl = sec_mode_data->apm_ctrl;
  99. apm_path.apm_m_path = i;
  100. apm_hal_apm_ctrl_filter_enable(&apm_path, 1);
  101. }
  102. }
  103. void apm_hal_apm_ctrl_reset_event_enable(bool enable)
  104. {
  105. apm_ll_apm_ctrl_reset_event_enable(enable);
  106. }
  107. esp_err_t apm_hal_apm_ctrl_get_int_src_num(apm_ctrl_path_t *apm_path)
  108. {
  109. return apm_ll_apm_ctrl_get_int_src_num(apm_path->apm_ctrl, apm_path->apm_m_path);
  110. }