1 /*
2  * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "hal/assert.h"
8 #include "hal/apm_hal.h"
9 #include "hal/apm_ll.h"
10 
apm_tee_hal_set_master_secure_mode(apm_ll_master_id_t master_id,apm_ll_secure_mode_t sec_mode)11 void apm_tee_hal_set_master_secure_mode(apm_ll_master_id_t master_id, apm_ll_secure_mode_t sec_mode)
12 {
13     apm_tee_ll_set_master_secure_mode(master_id, sec_mode);
14 }
15 
apm_tee_hal_clk_gating_enable(bool enable)16 void apm_tee_hal_clk_gating_enable(bool enable)
17 {
18     apm_tee_ll_clk_gating_enable(enable);
19 }
20 
apm_hp_hal_region_filter_enable(uint32_t regn_num,bool enable)21 void apm_hp_hal_region_filter_enable(uint32_t regn_num, bool enable)
22 {
23     apm_hp_ll_region_filter_enable(regn_num, enable);
24 }
25 
apm_hp_hal_m_filter_enable(apm_ll_hp_access_path_t hp_m_path,bool enable)26 void apm_hp_hal_m_filter_enable(apm_ll_hp_access_path_t hp_m_path, bool enable)
27 {
28     apm_hp_ll_m_filter_enable(hp_m_path, enable);
29 }
30 
apm_hp_hal_region_config(const apm_hp_hal_region_config_data_t * pms_data)31 void apm_hp_hal_region_config(const apm_hp_hal_region_config_data_t *pms_data)
32 {
33     HAL_ASSERT((!pms_data) || (pms_data->regn_num > APM_LL_HP_MAX_REGION_NUM));
34 
35     apm_hp_ll_set_region_start_address(pms_data->regn_num, pms_data->regn_start_addr);
36     apm_hp_ll_set_region_end_address(pms_data->regn_num, pms_data->regn_end_addr);
37     apm_hp_ll_sec_mode_region_attr_config(pms_data->regn_num, pms_data->sec_mode, pms_data->regn_pms);
38 }
39 
apm_hp_hal_m_exception_status(apm_ll_hp_access_path_t hp_m_path)40 uint8_t apm_hp_hal_m_exception_status(apm_ll_hp_access_path_t hp_m_path)
41 {
42     return apm_hp_ll_m_exception_status(hp_m_path);
43 }
44 
apm_hp_hal_m_exception_clear(apm_ll_hp_access_path_t hp_m_path)45 void apm_hp_hal_m_exception_clear(apm_ll_hp_access_path_t hp_m_path)
46 {
47     apm_hp_ll_m_exception_clear(hp_m_path);
48 }
49 
apm_hp_hal_get_m_exception_info(apm_hp_m_exception_info_t * excp_info)50 void apm_hp_hal_get_m_exception_info(apm_hp_m_exception_info_t *excp_info)
51 {
52     apm_hp_ll_get_m_exception_info(excp_info);
53 }
54 
apm_hp_hal_m_interrupt_enable(apm_ll_hp_access_path_t hp_m_path,bool enable)55 void apm_hp_hal_m_interrupt_enable(apm_ll_hp_access_path_t hp_m_path, bool enable)
56 {
57     apm_hp_ll_m_interrupt_enable(hp_m_path, enable);
58 }
59 
apm_hp_hal_clk_gating_enable(bool enable)60 void apm_hp_hal_clk_gating_enable(bool enable)
61 {
62     apm_hp_ll_clk_gating_enable(enable);
63 }
64 
65 /* TBD: IDF-6759 */
apm_hp_hal_master_sec_mode_config(apm_hp_secure_mode_config_t * sec_mode_data)66 void apm_hp_hal_master_sec_mode_config(apm_hp_secure_mode_config_t *sec_mode_data)
67 {
68     for (int i = 0; i < APM_LL_MASTER_MAX; i++) {
69         if (sec_mode_data->master_ids & (1 << i)) {
70             apm_tee_hal_set_master_secure_mode(i, sec_mode_data->sec_mode);
71         }
72     }
73     sec_mode_data->pms_data->sec_mode = sec_mode_data->sec_mode;
74     apm_hp_hal_region_config(sec_mode_data->pms_data);
75 }
76 
apm_hp_hal_reset_event_enable(bool enable)77 void apm_hp_hal_reset_event_enable(bool enable)
78 {
79     apm_hp_ll_reset_event_enable(enable);
80 }
81