1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * 15 * Description: Provides PMP driver api \n 16 * 17 * History: \n 18 * 2022-09-26, Create file. \n 19 */ 20 #ifndef PMP_H 21 #define PMP_H 22 23 #include <stdint.h> 24 #include <stdbool.h> 25 #include "errcode.h" 26 27 #define PMPXCFG_NUM_PER_REG 4 28 #define MEMXATTR_NUM_PER_REG 8 29 #define PMPADDR_RIGHT_SHIFT_BIS 2 30 31 32 #ifdef __cplusplus 33 #if __cplusplus 34 extern "C" { 35 #endif /* __cplusplus */ 36 #endif /* __cplusplus */ 37 38 /** 39 * @defgroup drivers_driver_pmp PMP 40 * @ingroup drivers_driver 41 * @{ 42 */ 43 44 /** 45 * @if Eng 46 * @brief Definition of PMP attribute. 47 * @else 48 * @brief PMP属性定义。 49 * @endif 50 */ 51 typedef enum pmp_attr { 52 PMP_ATTR_DEVICE_NO_BUFFERABLE = 0, 53 PMP_ATTR_DEVICE_BUFFERABLE = 1, 54 PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE = 2, 55 PMP_ATTR_NO_CACHEABLE_AND_BUFFERABLE = 3, 56 PMP_ATTR_WRITETHROUGH_NO_ALLOCATE = 4, 57 PMP_ATTR_WRITETHROUGH_RALLOCATE = 6, 58 PMP_ATTR_WRITEBACK_RALLOCATE = 7, 59 PMP_ATTR_WRITEBACK_NO_ALLOCATE = 8, 60 PMP_ATTR_WRITETHROUGH_RWALLOCATE = 14, 61 PMP_ATTR_WRITEBACK_RWALLOCATE = 15 62 } pmp_attr_t; 63 64 /** 65 * @if Eng 66 * @brief Definition of PMP address match. 67 * @else 68 * @brief PMP地址匹配定义。 69 * @endif 70 */ 71 typedef enum addr_match { 72 PMPCFG_ADDR_MATCH_OFF = 0x0, 73 PMPCFG_ADDR_MATCH_TOR = 0x1, 74 PMPCFG_ADDR_MATCH_NA4 = 0x2, 75 PMPCFG_ADDR_MATCH_NAPOT = 0x3 76 } addr_match_t; 77 78 /** 79 * @if Eng 80 * @brief Definition of PMP read-write-execute permission. 81 * @else 82 * @brief PMP读写权限定义。 83 * @endif 84 */ 85 typedef enum rwx_permission { 86 PMPCFG_NO_ACCESS = 0x0, 87 PMPCFG_READ_ONLY_NEXECUTE = 0x1, 88 PMPCFG_RW_NEXECUTE = 0x3, 89 PMPCFG_READ_ONLY_EXECUTE = 0x5, 90 PMPCFG_RW_EXECUTE = 0x7 91 } rwx_permission_t; 92 93 /** 94 * @if Eng 95 * @brief Definition of PMP region configuration parameters. 96 * @else 97 * @brief PMP域配置参数。 98 * @endif 99 */ 100 typedef struct pmpx_config { 101 rwx_permission_t rwx_permission; /*!< @if Eng Read-Write-Execute permission. 102 @else 读写权限。 @endif */ 103 addr_match_t addr_match; /*!< @if Eng Address matching method. 104 @else 地址匹配方式。 @endif */ 105 bool lock; /*!< @if Eng Lock bit configuration. 106 @else Lock位配置。 @endif */ 107 pmp_attr_t pmp_attr; /*!< @if Eng Read-Write mode configuration. 108 @else 读写方式配置。 @endif */ 109 } pmpx_config_t; 110 111 /** 112 * @if Eng 113 * @brief Definition of PMP configuration parameters. 114 * @else 115 * @brief PMP配置参数。 116 * @endif 117 */ 118 typedef struct pmp_conf { 119 uint32_t idx; /*!< @if Eng Region number. 120 @else 域编号 @endif */ 121 uint32_t addr; /*!< @if Eng Base address, First Address in NAPOT mode and End Address in TOR mode. 122 @else 基地址,在NAPOT/NA4模式为首地址,TOR模式为尾地址。 @endif */ 123 uint32_t size; /*!< @if Eng Used in NAPOT mode. Size of memory unit. 124 @else 在NAPOT模式使用,内存单元的大小。 @endif */ 125 pmpx_config_t conf; /*!< @if Eng PMP region configuration parameters. 126 @else PMP域配置参数。 @endif */ 127 } pmp_conf_t; 128 129 /** 130 * @if Eng 131 * @brief Initialize and config PMP module. 132 * @param [in] config A set of PMP configurations. 133 * @param [in] length Number of PMP configurations. 134 * @retval ERRCODE_SUCC Success. 135 * @retval Other Failure. For details, see @ref errcode_t 136 * @else 137 * @brief 初始化并配置PMP模块。 138 * @param [in] config 一组PMP域配置。 139 * @param [in] length PMP配置的个数。 140 * @retval ERRCODE_SUCC 成功。 141 * @retval Other 失败,参考 @ref errcode_t 。 142 * @endif 143 */ 144 errcode_t uapi_pmp_config(const pmp_conf_t *config, uint32_t length); 145 146 /** 147 * @} 148 */ 149 150 #ifdef __cplusplus 151 #if __cplusplus 152 } 153 #endif /* __cplusplus */ 154 #endif /* __cplusplus */ 155 156 #endif 157