MT7687 API Reference  LinkIt SDK v4
hal_mpu.h
1 /* Copyright Statement:
2  *
3  * (C) 2005-2016 MediaTek Inc. All rights reserved.
4  *
5  * This software/firmware and related documentation ("MediaTek Software") are
6  * protected under relevant copyright laws. The information contained herein
7  * is confidential and proprietary to MediaTek Inc. ("MediaTek") and/or its licensors.
8  * Without the prior written permission of MediaTek and/or its licensors,
9  * any reproduction, modification, use or disclosure of MediaTek Software,
10  * and information contained herein, in whole or in part, shall be strictly prohibited.
11  * You may only use, reproduce, modify, or distribute (as applicable) MediaTek Software
12  * if you have agreed to and been bound by the applicable license agreement with
13  * MediaTek ("License Agreement") and been granted explicit permission to do so within
14  * the License Agreement ("Permitted User"). If you are not a Permitted User,
15  * please cease any access or use of MediaTek Software immediately.
16  * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
17  * THAT MEDIATEK SOFTWARE RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES
18  * ARE PROVIDED TO RECEIVER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
19  * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
21  * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
22  * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
23  * SUPPLIED WITH MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
24  * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
25  * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
26  * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
27  * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
28  * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
29  * CUMULATIVE LIABILITY WITH RESPECT TO MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
30  * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE MEDIATEK SOFTWARE AT ISSUE,
31  * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
32  * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
33  */
34 
35 #ifndef __HAL_MPU_H__
36 #define __HAL_MPU_H__
37 #include "hal_platform.h"
38 
39 #ifdef HAL_MPU_MODULE_ENABLED
40 
128 #ifdef __cplusplus
129 extern "C" {
130 #endif
131 
132 
133 /*****************************************************************************
134  * Enums
135  *****************************************************************************/
136 
142 typedef enum {
143  HAL_MPU_STATUS_INVALID_PARAMETER = -6,
144  HAL_MPU_STATUS_ERROR_BUSY = -5,
145  HAL_MPU_STATUS_ERROR_REGION = -4,
146  HAL_MPU_STATUS_ERROR_REGION_ADDRESS = -3,
147  HAL_MPU_STATUS_ERROR_REGION_SIZE = -2,
148  HAL_MPU_STATUS_ERROR = -1,
149  HAL_MPU_STATUS_OK = 0
150 } hal_mpu_status_t;
151 
153 typedef enum {
154  HAL_MPU_REGION_0 = 0,
155  HAL_MPU_REGION_1 = 1,
156  HAL_MPU_REGION_2 = 2,
157  HAL_MPU_REGION_3 = 3,
158  HAL_MPU_REGION_4 = 4,
159  HAL_MPU_REGION_5 = 5,
160  HAL_MPU_REGION_6 = 6,
161  HAL_MPU_REGION_7 = 7,
162  HAL_MPU_REGION_MAX
163 } hal_mpu_region_t;
164 
166 typedef enum {
167  HAL_MPU_REGION_SIZE_MIN = 3,
168  HAL_MPU_REGION_SIZE_32B = 4,
169  HAL_MPU_REGION_SIZE_64B = 5,
170  HAL_MPU_REGION_SIZE_128B = 6,
171  HAL_MPU_REGION_SIZE_256B = 7,
172  HAL_MPU_REGION_SIZE_512B = 8,
173  HAL_MPU_REGION_SIZE_1KB = 9,
174  HAL_MPU_REGION_SIZE_2KB = 10,
175  HAL_MPU_REGION_SIZE_4KB = 11,
176  HAL_MPU_REGION_SIZE_8KB = 12,
177  HAL_MPU_REGION_SIZE_16KB = 13,
178  HAL_MPU_REGION_SIZE_32KB = 14,
179  HAL_MPU_REGION_SIZE_64KB = 15,
180  HAL_MPU_REGION_SIZE_128KB = 16,
181  HAL_MPU_REGION_SIZE_256KB = 17,
182  HAL_MPU_REGION_SIZE_512KB = 18,
183  HAL_MPU_REGION_SIZE_1MB = 19,
184  HAL_MPU_REGION_SIZE_2MB = 20,
185  HAL_MPU_REGION_SIZE_4MB = 21,
186  HAL_MPU_REGION_SIZE_8MB = 22,
187  HAL_MPU_REGION_SIZE_16MB = 23,
188  HAL_MPU_REGION_SIZE_32MB = 24,
189  HAL_MPU_REGION_SIZE_64MB = 25,
190  HAL_MPU_REGION_SIZE_128MB = 26,
191  HAL_MPU_REGION_SIZE_256MB = 27,
192  HAL_MPU_REGION_SIZE_512MB = 28,
193  HAL_MPU_REGION_SIZE_1GB = 29,
194  HAL_MPU_REGION_SIZE_2GB = 30,
195  HAL_MPU_REGION_SIZE_4GB = 31,
196  HAL_MPU_REGION_SIZE_MAX
197 } hal_mpu_region_size_t;
198 
200 typedef enum {
201  HAL_MPU_NO_ACCESS = 0,
202  HAL_MPU_PRIVILEGED_ACCESS_ONLY = 1,
203  HAL_MPU_PRIVILEGED_READ_WRITE_UNPRIVILEGED_READ_ONLY = 2,
204  HAL_MPU_FULL_ACCESS = 3,
205  HAL_MPU_UNPREDICTABLE = 4,
206  HAL_MPU_PRIVILEGED_READ_ONLY = 5,
207  HAL_MPU_READONLY = 6
208 } hal_mpu_access_permission_t;
209 
214 /*****************************************************************************
215  * Structures
216  *****************************************************************************/
217 
223 typedef struct {
224  bool privdefena;
225  bool hfnmiena;
226 } hal_mpu_config_t;
227 
229 typedef struct {
230  uint32_t mpu_region_address;
231  hal_mpu_region_size_t mpu_region_size;
232  hal_mpu_access_permission_t mpu_region_access_permission;
233  uint8_t mpu_subregion_mask;
234  bool mpu_xn;
235 } hal_mpu_region_config_t;
236 
241 /*****************************************************************************
242  * Functions
243  *****************************************************************************/
244 
253 hal_mpu_status_t hal_mpu_init(const hal_mpu_config_t *mpu_config);
254 
260 hal_mpu_status_t hal_mpu_deinit(void);
261 
267 hal_mpu_status_t hal_mpu_enable(void);
268 
274 hal_mpu_status_t hal_mpu_disable(void);
275 
283 hal_mpu_status_t hal_mpu_region_enable(hal_mpu_region_t region);
284 
292 hal_mpu_status_t hal_mpu_region_disable(hal_mpu_region_t region);
293 
305 hal_mpu_status_t hal_mpu_region_configure(hal_mpu_region_t region, const hal_mpu_region_config_t *region_config);
306 
307 #ifdef __cplusplus
308 }
309 #endif
310 
316 #endif /* HAL_MPU_MODULE_ENABLED */
317 #endif /* __HAL_MPU_H__ */
318