1 /*
2 * Copyright (c) 2016-2017 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "Driver_MPC.h"
17
18 #include "cmsis.h"
19 #include "platform_retarget_dev.h"
20 #include "RTE_Device.h"
21
22 /* driver version */
23 #define ARM_MPC_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,0)
24
25 /* Driver Version */
26 static const ARM_DRIVER_VERSION DriverVersion = {
27 ARM_MPC_API_VERSION,
28 ARM_MPC_DRV_VERSION
29 };
30
ARM_MPC_GetVersion(void)31 static ARM_DRIVER_VERSION ARM_MPC_GetVersion(void)
32 {
33 return DriverVersion;
34 }
35
36 /*
37 * \brief Translates error codes from native API to CMSIS API.
38 *
39 * \param[in] err Error code to translate (\ref mpc_sie200_error_t).
40 *
41 * \return Returns CMSIS error code.
42 */
error_trans(enum mpc_sie200_error_t err)43 static int32_t error_trans(enum mpc_sie200_error_t err)
44 {
45 switch(err) {
46 case MPC_SIE200_ERR_NONE:
47 return ARM_DRIVER_OK;
48 case MPC_SIE200_INVALID_ARG:
49 return ARM_DRIVER_ERROR_PARAMETER;
50 case MPC_SIE200_NOT_INIT:
51 return ARM_MPC_ERR_NOT_INIT;
52 case MPC_SIE200_ERR_NOT_IN_RANGE:
53 return ARM_MPC_ERR_NOT_IN_RANGE;
54 case MPC_SIE200_ERR_NOT_ALIGNED:
55 return ARM_MPC_ERR_NOT_ALIGNED;
56 case MPC_SIE200_ERR_INVALID_RANGE:
57 return ARM_MPC_ERR_INVALID_RANGE;
58 case MPC_SIE200_ERR_RANGE_SEC_ATTR_NON_COMPATIBLE:
59 return ARM_MPC_ERR_RANGE_SEC_ATTR_NON_COMPATIBLE;
60 /* default: The default is not defined intentionally to force the
61 * compiler to check that all the enumeration values are
62 * covered in the switch.
63 */
64 }
65 }
66
67 #if (RTE_ISRAM0_MPC)
68 /* Ranges controlled by this ISRAM0_MPC */
69 static struct mpc_sie200_memory_range_t MPC_ISRAM0_RANGE_S = {
70 .base = MPC_ISRAM0_RANGE_BASE_S,
71 .limit = MPC_ISRAM0_RANGE_LIMIT_S,
72 .attr = MPC_SIE200_SEC_ATTR_SECURE
73 };
74
75 static struct mpc_sie200_memory_range_t MPC_ISRAM0_RANGE_NS = {
76 .base = MPC_ISRAM0_RANGE_BASE_NS,
77 .limit = MPC_ISRAM0_RANGE_LIMIT_NS,
78 .attr = MPC_SIE200_SEC_ATTR_NONSECURE
79 };
80
81 #define MPC_ISRAM0_RANGE_LIST_LEN 2u
82 static const struct mpc_sie200_memory_range_t* MPC_ISRAM0_RANGE_LIST[MPC_ISRAM0_RANGE_LIST_LEN]=
83 {&MPC_ISRAM0_RANGE_S, &MPC_ISRAM0_RANGE_NS};
84
85 /* ISRAM0_MPC Driver wrapper functions */
ISRAM0_MPC_Initialize(void)86 static int32_t ISRAM0_MPC_Initialize(void)
87 {
88 enum mpc_sie200_error_t ret;
89
90 ret = mpc_sie200_init(&MPC_ISRAM0_DEV_S,
91 MPC_ISRAM0_RANGE_LIST,
92 MPC_ISRAM0_RANGE_LIST_LEN);
93
94 return error_trans(ret);
95 }
96
ISRAM0_MPC_Uninitialize(void)97 static int32_t ISRAM0_MPC_Uninitialize(void)
98 {
99 /* Nothing to be done */
100 return ARM_DRIVER_OK;
101 }
102
ISRAM0_MPC_GetBlockSize(uint32_t * blk_size)103 static int32_t ISRAM0_MPC_GetBlockSize(uint32_t* blk_size)
104 {
105 enum mpc_sie200_error_t ret;
106
107 ret = mpc_sie200_get_block_size(&MPC_ISRAM0_DEV_S, blk_size);
108
109 return error_trans(ret);
110 }
111
ISRAM0_MPC_GetCtrlConfig(uint32_t * ctrl_val)112 static int32_t ISRAM0_MPC_GetCtrlConfig(uint32_t* ctrl_val)
113 {
114 enum mpc_sie200_error_t ret;
115
116 ret = mpc_sie200_get_ctrl(&MPC_ISRAM0_DEV_S, ctrl_val);
117
118 return error_trans(ret);
119 }
120
ISRAM0_MPC_SetCtrlConfig(uint32_t ctrl)121 static int32_t ISRAM0_MPC_SetCtrlConfig(uint32_t ctrl)
122 {
123 enum mpc_sie200_error_t ret;
124
125 ret = mpc_sie200_set_ctrl(&MPC_ISRAM0_DEV_S, ctrl);
126
127 return error_trans(ret);
128 }
129
ISRAM0_MPC_GetRegionConfig(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR * attr)130 static int32_t ISRAM0_MPC_GetRegionConfig(uintptr_t base,
131 uintptr_t limit,
132 ARM_MPC_SEC_ATTR* attr)
133 {
134 enum mpc_sie200_error_t ret;
135
136 ret = mpc_sie200_get_region_config(&MPC_ISRAM0_DEV_S, base, limit,
137 (enum mpc_sie200_sec_attr_t*)attr);
138
139 return error_trans(ret);
140 }
141
ISRAM0_MPC_ConfigRegion(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR attr)142 static int32_t ISRAM0_MPC_ConfigRegion(uintptr_t base,
143 uintptr_t limit,
144 ARM_MPC_SEC_ATTR attr)
145 {
146 enum mpc_sie200_error_t ret;
147
148 ret = mpc_sie200_config_region(&MPC_ISRAM0_DEV_S, base, limit,
149 (enum mpc_sie200_sec_attr_t)attr);
150
151 return error_trans(ret);
152 }
153
ISRAM0_MPC_EnableInterrupt(void)154 static int32_t ISRAM0_MPC_EnableInterrupt(void)
155 {
156 enum mpc_sie200_error_t ret;
157
158 ret = mpc_sie200_irq_enable(&MPC_ISRAM0_DEV_S);
159
160 return error_trans(ret);
161 }
162
ISRAM0_MPC_DisableInterrupt(void)163 static void ISRAM0_MPC_DisableInterrupt(void)
164 {
165 mpc_sie200_irq_disable(&MPC_ISRAM0_DEV_S);
166 }
167
168
ISRAM0_MPC_ClearInterrupt(void)169 static void ISRAM0_MPC_ClearInterrupt(void)
170 {
171 mpc_sie200_clear_irq(&MPC_ISRAM0_DEV_S);
172 }
173
ISRAM0_MPC_InterruptState(void)174 static uint32_t ISRAM0_MPC_InterruptState(void)
175 {
176 return mpc_sie200_irq_state(&MPC_ISRAM0_DEV_S);
177 }
178
ISRAM0_MPC_LockDown(void)179 static int32_t ISRAM0_MPC_LockDown(void)
180 {
181 return mpc_sie200_lock_down(&MPC_ISRAM0_DEV_S);
182 }
183
184 /* ISRAM0_MPC Driver CMSIS access structure */
185 extern ARM_DRIVER_MPC Driver_ISRAM0_MPC;
186 ARM_DRIVER_MPC Driver_ISRAM0_MPC = {
187 .GetVersion = ARM_MPC_GetVersion,
188 .Initialize = ISRAM0_MPC_Initialize,
189 .Uninitialize = ISRAM0_MPC_Uninitialize,
190 .GetBlockSize = ISRAM0_MPC_GetBlockSize,
191 .GetCtrlConfig = ISRAM0_MPC_GetCtrlConfig,
192 .SetCtrlConfig = ISRAM0_MPC_SetCtrlConfig,
193 .ConfigRegion = ISRAM0_MPC_ConfigRegion,
194 .GetRegionConfig = ISRAM0_MPC_GetRegionConfig,
195 .EnableInterrupt = ISRAM0_MPC_EnableInterrupt,
196 .DisableInterrupt = ISRAM0_MPC_DisableInterrupt,
197 .ClearInterrupt = ISRAM0_MPC_ClearInterrupt,
198 .InterruptState = ISRAM0_MPC_InterruptState,
199 .LockDown = ISRAM0_MPC_LockDown,
200 };
201 #endif /* RTE_ISRAM0_MPC */
202
203 #if (RTE_ISRAM1_MPC)
204 /* Ranges controlled by this ISRAM1_MPC */
205 static struct mpc_sie200_memory_range_t MPC_ISRAM1_RANGE_S = {
206 .base = MPC_ISRAM1_RANGE_BASE_S,
207 .limit = MPC_ISRAM1_RANGE_LIMIT_S,
208 .attr = MPC_SIE200_SEC_ATTR_SECURE
209 };
210
211 static struct mpc_sie200_memory_range_t MPC_ISRAM1_RANGE_NS = {
212 .base = MPC_ISRAM1_RANGE_BASE_NS,
213 .limit = MPC_ISRAM1_RANGE_LIMIT_NS,
214 .attr = MPC_SIE200_SEC_ATTR_NONSECURE
215 };
216
217 #define MPC_ISRAM1_RANGE_LIST_LEN 2u
218 static const struct mpc_sie200_memory_range_t* MPC_ISRAM1_RANGE_LIST[MPC_ISRAM1_RANGE_LIST_LEN]=
219 {&MPC_ISRAM1_RANGE_S, &MPC_ISRAM1_RANGE_NS};
220
221 /* ISRAM1_MPC Driver wrapper functions */
ISRAM1_MPC_Initialize(void)222 static int32_t ISRAM1_MPC_Initialize(void)
223 {
224 enum mpc_sie200_error_t ret;
225
226 ret = mpc_sie200_init(&MPC_ISRAM1_DEV_S,
227 MPC_ISRAM1_RANGE_LIST,
228 MPC_ISRAM1_RANGE_LIST_LEN);
229
230 return error_trans(ret);
231 }
232
ISRAM1_MPC_Uninitialize(void)233 static int32_t ISRAM1_MPC_Uninitialize(void)
234 {
235 /* Nothing to be done */
236 return ARM_DRIVER_OK;
237 }
238
ISRAM1_MPC_GetBlockSize(uint32_t * blk_size)239 static int32_t ISRAM1_MPC_GetBlockSize(uint32_t* blk_size)
240 {
241 enum mpc_sie200_error_t ret;
242
243 ret = mpc_sie200_get_block_size(&MPC_ISRAM1_DEV_S, blk_size);
244
245 return error_trans(ret);
246 }
247
ISRAM1_MPC_GetCtrlConfig(uint32_t * ctrl_val)248 static int32_t ISRAM1_MPC_GetCtrlConfig(uint32_t* ctrl_val)
249 {
250 enum mpc_sie200_error_t ret;
251
252 ret = mpc_sie200_get_ctrl(&MPC_ISRAM1_DEV_S, ctrl_val);
253
254 return error_trans(ret);
255 }
256
ISRAM1_MPC_SetCtrlConfig(uint32_t ctrl)257 static int32_t ISRAM1_MPC_SetCtrlConfig(uint32_t ctrl)
258 {
259 enum mpc_sie200_error_t ret;
260
261 ret = mpc_sie200_set_ctrl(&MPC_ISRAM1_DEV_S, ctrl);
262
263 return error_trans(ret);
264 }
265
ISRAM1_MPC_GetRegionConfig(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR * attr)266 static int32_t ISRAM1_MPC_GetRegionConfig(uintptr_t base,
267 uintptr_t limit,
268 ARM_MPC_SEC_ATTR* attr)
269 {
270 enum mpc_sie200_error_t ret;
271
272 ret = mpc_sie200_get_region_config(&MPC_ISRAM1_DEV_S, base, limit,
273 (enum mpc_sie200_sec_attr_t*)attr);
274
275 return error_trans(ret);
276 }
277
ISRAM1_MPC_ConfigRegion(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR attr)278 static int32_t ISRAM1_MPC_ConfigRegion(uintptr_t base,
279 uintptr_t limit,
280 ARM_MPC_SEC_ATTR attr)
281 {
282 enum mpc_sie200_error_t ret;
283
284 ret = mpc_sie200_config_region(&MPC_ISRAM1_DEV_S, base, limit,
285 (enum mpc_sie200_sec_attr_t)attr);
286
287 return error_trans(ret);
288 }
289
ISRAM1_MPC_EnableInterrupt(void)290 static int32_t ISRAM1_MPC_EnableInterrupt(void)
291 {
292 enum mpc_sie200_error_t ret;
293
294 ret = mpc_sie200_irq_enable(&MPC_ISRAM1_DEV_S);
295
296 return error_trans(ret);
297 }
298
ISRAM1_MPC_DisableInterrupt(void)299 static void ISRAM1_MPC_DisableInterrupt(void)
300 {
301 mpc_sie200_irq_disable(&MPC_ISRAM1_DEV_S);
302 }
303
304
ISRAM1_MPC_ClearInterrupt(void)305 static void ISRAM1_MPC_ClearInterrupt(void)
306 {
307 mpc_sie200_clear_irq(&MPC_ISRAM1_DEV_S);
308 }
309
ISRAM1_MPC_InterruptState(void)310 static uint32_t ISRAM1_MPC_InterruptState(void)
311 {
312 return mpc_sie200_irq_state(&MPC_ISRAM1_DEV_S);
313 }
314
ISRAM1_MPC_LockDown(void)315 static int32_t ISRAM1_MPC_LockDown(void)
316 {
317 return mpc_sie200_lock_down(&MPC_ISRAM1_DEV_S);
318 }
319
320 /* ISRAM1_MPC Driver CMSIS access structure */
321 extern ARM_DRIVER_MPC Driver_ISRAM1_MPC;
322 ARM_DRIVER_MPC Driver_ISRAM1_MPC = {
323 .GetVersion = ARM_MPC_GetVersion,
324 .Initialize = ISRAM1_MPC_Initialize,
325 .Uninitialize = ISRAM1_MPC_Uninitialize,
326 .GetBlockSize = ISRAM1_MPC_GetBlockSize,
327 .GetCtrlConfig = ISRAM1_MPC_GetCtrlConfig,
328 .SetCtrlConfig = ISRAM1_MPC_SetCtrlConfig,
329 .ConfigRegion = ISRAM1_MPC_ConfigRegion,
330 .GetRegionConfig = ISRAM1_MPC_GetRegionConfig,
331 .EnableInterrupt = ISRAM1_MPC_EnableInterrupt,
332 .DisableInterrupt = ISRAM1_MPC_DisableInterrupt,
333 .ClearInterrupt = ISRAM1_MPC_ClearInterrupt,
334 .InterruptState = ISRAM1_MPC_InterruptState,
335 .LockDown = ISRAM1_MPC_LockDown,
336 };
337 #endif /* RTE_ISRAM1_MPC */
338
339 #if (RTE_ISRAM2_MPC)
340 /* Ranges controlled by this ISRAM2_MPC */
341 static struct mpc_sie200_memory_range_t MPC_ISRAM2_RANGE_S = {
342 .base = MPC_ISRAM2_RANGE_BASE_S,
343 .limit = MPC_ISRAM2_RANGE_LIMIT_S,
344 .attr = MPC_SIE200_SEC_ATTR_SECURE
345 };
346
347 static struct mpc_sie200_memory_range_t MPC_ISRAM2_RANGE_NS = {
348 .base = MPC_ISRAM2_RANGE_BASE_NS,
349 .limit = MPC_ISRAM2_RANGE_LIMIT_NS,
350 .attr = MPC_SIE200_SEC_ATTR_NONSECURE
351 };
352
353 #define MPC_ISRAM2_RANGE_LIST_LEN 2u
354 static const struct mpc_sie200_memory_range_t* MPC_ISRAM2_RANGE_LIST[MPC_ISRAM2_RANGE_LIST_LEN]=
355 {&MPC_ISRAM2_RANGE_S, &MPC_ISRAM2_RANGE_NS};
356
357 /* ISRAM2_MPC Driver wrapper functions */
ISRAM2_MPC_Initialize(void)358 static int32_t ISRAM2_MPC_Initialize(void)
359 {
360 enum mpc_sie200_error_t ret;
361
362 ret = mpc_sie200_init(&MPC_ISRAM2_DEV_S,
363 MPC_ISRAM2_RANGE_LIST,
364 MPC_ISRAM2_RANGE_LIST_LEN);
365
366 return error_trans(ret);
367 }
368
ISRAM2_MPC_Uninitialize(void)369 static int32_t ISRAM2_MPC_Uninitialize(void)
370 {
371 /* Nothing to be done */
372 return ARM_DRIVER_OK;
373 }
374
ISRAM2_MPC_GetBlockSize(uint32_t * blk_size)375 static int32_t ISRAM2_MPC_GetBlockSize(uint32_t* blk_size)
376 {
377 enum mpc_sie200_error_t ret;
378
379 ret = mpc_sie200_get_block_size(&MPC_ISRAM2_DEV_S, blk_size);
380
381 return error_trans(ret);
382 }
383
ISRAM2_MPC_GetCtrlConfig(uint32_t * ctrl_val)384 static int32_t ISRAM2_MPC_GetCtrlConfig(uint32_t* ctrl_val)
385 {
386 enum mpc_sie200_error_t ret;
387
388 ret = mpc_sie200_get_ctrl(&MPC_ISRAM2_DEV_S, ctrl_val);
389
390 return error_trans(ret);
391 }
392
ISRAM2_MPC_SetCtrlConfig(uint32_t ctrl)393 static int32_t ISRAM2_MPC_SetCtrlConfig(uint32_t ctrl)
394 {
395 enum mpc_sie200_error_t ret;
396
397 ret = mpc_sie200_set_ctrl(&MPC_ISRAM2_DEV_S, ctrl);
398
399 return error_trans(ret);
400 }
401
ISRAM2_MPC_GetRegionConfig(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR * attr)402 static int32_t ISRAM2_MPC_GetRegionConfig(uintptr_t base,
403 uintptr_t limit,
404 ARM_MPC_SEC_ATTR* attr)
405 {
406 enum mpc_sie200_error_t ret;
407
408 ret = mpc_sie200_get_region_config(&MPC_ISRAM2_DEV_S, base, limit,
409 (enum mpc_sie200_sec_attr_t*)attr);
410
411 return error_trans(ret);
412 }
413
ISRAM2_MPC_ConfigRegion(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR attr)414 static int32_t ISRAM2_MPC_ConfigRegion(uintptr_t base,
415 uintptr_t limit,
416 ARM_MPC_SEC_ATTR attr)
417 {
418 enum mpc_sie200_error_t ret;
419
420 ret = mpc_sie200_config_region(&MPC_ISRAM2_DEV_S, base, limit,
421 (enum mpc_sie200_sec_attr_t)attr);
422
423 return error_trans(ret);
424 }
425
ISRAM2_MPC_EnableInterrupt(void)426 static int32_t ISRAM2_MPC_EnableInterrupt(void)
427 {
428 enum mpc_sie200_error_t ret;
429
430 ret = mpc_sie200_irq_enable(&MPC_ISRAM2_DEV_S);
431
432 return error_trans(ret);
433 }
434
ISRAM2_MPC_DisableInterrupt(void)435 static void ISRAM2_MPC_DisableInterrupt(void)
436 {
437 mpc_sie200_irq_disable(&MPC_ISRAM2_DEV_S);
438 }
439
440
ISRAM2_MPC_ClearInterrupt(void)441 static void ISRAM2_MPC_ClearInterrupt(void)
442 {
443 mpc_sie200_clear_irq(&MPC_ISRAM2_DEV_S);
444 }
445
ISRAM2_MPC_InterruptState(void)446 static uint32_t ISRAM2_MPC_InterruptState(void)
447 {
448 return mpc_sie200_irq_state(&MPC_ISRAM2_DEV_S);
449 }
450
ISRAM2_MPC_LockDown(void)451 static int32_t ISRAM2_MPC_LockDown(void)
452 {
453 return mpc_sie200_lock_down(&MPC_ISRAM2_DEV_S);
454 }
455
456 /* ISRAM2_MPC Driver CMSIS access structure */
457 extern ARM_DRIVER_MPC Driver_ISRAM2_MPC;
458 ARM_DRIVER_MPC Driver_ISRAM2_MPC = {
459 .GetVersion = ARM_MPC_GetVersion,
460 .Initialize = ISRAM2_MPC_Initialize,
461 .Uninitialize = ISRAM2_MPC_Uninitialize,
462 .GetBlockSize = ISRAM2_MPC_GetBlockSize,
463 .GetCtrlConfig = ISRAM2_MPC_GetCtrlConfig,
464 .SetCtrlConfig = ISRAM2_MPC_SetCtrlConfig,
465 .ConfigRegion = ISRAM2_MPC_ConfigRegion,
466 .GetRegionConfig = ISRAM2_MPC_GetRegionConfig,
467 .EnableInterrupt = ISRAM2_MPC_EnableInterrupt,
468 .DisableInterrupt = ISRAM2_MPC_DisableInterrupt,
469 .ClearInterrupt = ISRAM2_MPC_ClearInterrupt,
470 .InterruptState = ISRAM2_MPC_InterruptState,
471 .LockDown = ISRAM2_MPC_LockDown,
472 };
473 #endif /* RTE_ISRAM2_MPC */
474
475 #if (RTE_ISRAM3_MPC)
476 /* Ranges controlled by this ISRAM3_MPC */
477 static struct mpc_sie200_memory_range_t MPC_ISRAM3_RANGE_S = {
478 .base = MPC_ISRAM3_RANGE_BASE_S,
479 .limit = MPC_ISRAM3_RANGE_LIMIT_S,
480 .attr = MPC_SIE200_SEC_ATTR_SECURE
481 };
482
483 static struct mpc_sie200_memory_range_t MPC_ISRAM3_RANGE_NS = {
484 .base = MPC_ISRAM3_RANGE_BASE_NS,
485 .limit = MPC_ISRAM3_RANGE_LIMIT_NS,
486 .attr = MPC_SIE200_SEC_ATTR_NONSECURE
487 };
488
489 #define MPC_ISRAM3_RANGE_LIST_LEN 2u
490 static const struct mpc_sie200_memory_range_t* MPC_ISRAM3_RANGE_LIST[MPC_ISRAM3_RANGE_LIST_LEN]=
491 {&MPC_ISRAM3_RANGE_S, &MPC_ISRAM3_RANGE_NS};
492
493 /* ISRAM3_MPC Driver wrapper functions */
ISRAM3_MPC_Initialize(void)494 static int32_t ISRAM3_MPC_Initialize(void)
495 {
496 enum mpc_sie200_error_t ret;
497
498 ret = mpc_sie200_init(&MPC_ISRAM3_DEV_S,
499 MPC_ISRAM3_RANGE_LIST,
500 MPC_ISRAM3_RANGE_LIST_LEN);
501
502 return error_trans(ret);
503 }
504
ISRAM3_MPC_Uninitialize(void)505 static int32_t ISRAM3_MPC_Uninitialize(void)
506 {
507 /* Nothing to be done */
508 return ARM_DRIVER_OK;
509 }
510
ISRAM3_MPC_GetBlockSize(uint32_t * blk_size)511 static int32_t ISRAM3_MPC_GetBlockSize(uint32_t* blk_size)
512 {
513 enum mpc_sie200_error_t ret;
514
515 ret = mpc_sie200_get_block_size(&MPC_ISRAM3_DEV_S, blk_size);
516
517 return error_trans(ret);
518 }
519
ISRAM3_MPC_GetCtrlConfig(uint32_t * ctrl_val)520 static int32_t ISRAM3_MPC_GetCtrlConfig(uint32_t* ctrl_val)
521 {
522 enum mpc_sie200_error_t ret;
523
524 ret = mpc_sie200_get_ctrl(&MPC_ISRAM3_DEV_S, ctrl_val);
525
526 return error_trans(ret);
527 }
528
ISRAM3_MPC_SetCtrlConfig(uint32_t ctrl)529 static int32_t ISRAM3_MPC_SetCtrlConfig(uint32_t ctrl)
530 {
531 enum mpc_sie200_error_t ret;
532
533 ret = mpc_sie200_set_ctrl(&MPC_ISRAM3_DEV_S, ctrl);
534
535 return error_trans(ret);
536 }
537
ISRAM3_MPC_GetRegionConfig(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR * attr)538 static int32_t ISRAM3_MPC_GetRegionConfig(uintptr_t base,
539 uintptr_t limit,
540 ARM_MPC_SEC_ATTR* attr)
541 {
542 enum mpc_sie200_error_t ret;
543
544 ret = mpc_sie200_get_region_config(&MPC_ISRAM3_DEV_S, base, limit,
545 (enum mpc_sie200_sec_attr_t*)attr);
546
547 return error_trans(ret);
548 }
549
ISRAM3_MPC_ConfigRegion(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR attr)550 static int32_t ISRAM3_MPC_ConfigRegion(uintptr_t base,
551 uintptr_t limit,
552 ARM_MPC_SEC_ATTR attr)
553 {
554 enum mpc_sie200_error_t ret;
555
556 ret = mpc_sie200_config_region(&MPC_ISRAM3_DEV_S, base, limit,
557 (enum mpc_sie200_sec_attr_t)attr);
558
559 return error_trans(ret);
560 }
561
ISRAM3_MPC_EnableInterrupt(void)562 static int32_t ISRAM3_MPC_EnableInterrupt(void)
563 {
564 enum mpc_sie200_error_t ret;
565
566 ret = mpc_sie200_irq_enable(&MPC_ISRAM3_DEV_S);
567
568 return error_trans(ret);
569 }
570
ISRAM3_MPC_DisableInterrupt(void)571 static void ISRAM3_MPC_DisableInterrupt(void)
572 {
573 mpc_sie200_irq_disable(&MPC_ISRAM3_DEV_S);
574 }
575
576
ISRAM3_MPC_ClearInterrupt(void)577 static void ISRAM3_MPC_ClearInterrupt(void)
578 {
579 mpc_sie200_clear_irq(&MPC_ISRAM3_DEV_S);
580 }
581
ISRAM3_MPC_InterruptState(void)582 static uint32_t ISRAM3_MPC_InterruptState(void)
583 {
584 return mpc_sie200_irq_state(&MPC_ISRAM3_DEV_S);
585 }
586
ISRAM3_MPC_LockDown(void)587 static int32_t ISRAM3_MPC_LockDown(void)
588 {
589 return mpc_sie200_lock_down(&MPC_ISRAM3_DEV_S);
590 }
591
592 /* ISRAM3_MPC Driver CMSIS access structure */
593 extern ARM_DRIVER_MPC Driver_ISRAM3_MPC;
594 ARM_DRIVER_MPC Driver_ISRAM3_MPC = {
595 .GetVersion = ARM_MPC_GetVersion,
596 .Initialize = ISRAM3_MPC_Initialize,
597 .Uninitialize = ISRAM3_MPC_Uninitialize,
598 .GetBlockSize = ISRAM3_MPC_GetBlockSize,
599 .GetCtrlConfig = ISRAM3_MPC_GetCtrlConfig,
600 .SetCtrlConfig = ISRAM3_MPC_SetCtrlConfig,
601 .ConfigRegion = ISRAM3_MPC_ConfigRegion,
602 .GetRegionConfig = ISRAM3_MPC_GetRegionConfig,
603 .EnableInterrupt = ISRAM3_MPC_EnableInterrupt,
604 .DisableInterrupt = ISRAM3_MPC_DisableInterrupt,
605 .ClearInterrupt = ISRAM3_MPC_ClearInterrupt,
606 .InterruptState = ISRAM3_MPC_InterruptState,
607 .LockDown = ISRAM3_MPC_LockDown,
608 };
609 #endif /* RTE_ISRAM3_MPC */
610
611 #if (RTE_CODE_SRAM1_MPC)
612 /* Ranges controlled by this SRAM1_MPC */
613 static struct mpc_sie200_memory_range_t MPC_CODE_SRAM1_RANGE_S = {
614 .base = MPC_CODE_SRAM1_RANGE_BASE_S,
615 .limit = MPC_CODE_SRAM1_RANGE_LIMIT_S,
616 .attr = MPC_SIE200_SEC_ATTR_SECURE
617 };
618
619 static struct mpc_sie200_memory_range_t MPC_CODE_SRAM1_RANGE_NS = {
620 .base = MPC_CODE_SRAM1_RANGE_BASE_NS,
621 .limit = MPC_CODE_SRAM1_RANGE_LIMIT_NS,
622 .attr = MPC_SIE200_SEC_ATTR_NONSECURE
623 };
624
625 #define MPC_CODE_SRAM1_RANGE_LIST_LEN 2u
626 static const struct mpc_sie200_memory_range_t* MPC_CODE_SRAM1_RANGE_LIST[MPC_CODE_SRAM1_RANGE_LIST_LEN]=
627 {&MPC_CODE_SRAM1_RANGE_S, &MPC_CODE_SRAM1_RANGE_NS};
628
629 /* SRAM1_MPC Driver wrapper functions */
SRAM1_MPC_Initialize(void)630 static int32_t SRAM1_MPC_Initialize(void)
631 {
632 enum mpc_sie200_error_t ret;
633
634 ret = mpc_sie200_init(&MPC_CODE_SRAM1_DEV_S,
635 MPC_CODE_SRAM1_RANGE_LIST,
636 MPC_CODE_SRAM1_RANGE_LIST_LEN);
637
638 return error_trans(ret);
639 }
640
SRAM1_MPC_Uninitialize(void)641 static int32_t SRAM1_MPC_Uninitialize(void)
642 {
643 /* Nothing to be done */
644 return ARM_DRIVER_OK;
645 }
646
SRAM1_MPC_GetBlockSize(uint32_t * blk_size)647 static int32_t SRAM1_MPC_GetBlockSize(uint32_t* blk_size)
648 {
649 enum mpc_sie200_error_t ret;
650
651 ret = mpc_sie200_get_block_size(&MPC_CODE_SRAM1_DEV_S, blk_size);
652
653 return error_trans(ret);
654 }
655
SRAM1_MPC_GetCtrlConfig(uint32_t * ctrl_val)656 static int32_t SRAM1_MPC_GetCtrlConfig(uint32_t* ctrl_val)
657 {
658 enum mpc_sie200_error_t ret;
659
660 ret = mpc_sie200_get_ctrl(&MPC_CODE_SRAM1_DEV_S, ctrl_val);
661
662 return error_trans(ret);
663 }
664
SRAM1_MPC_SetCtrlConfig(uint32_t ctrl)665 static int32_t SRAM1_MPC_SetCtrlConfig(uint32_t ctrl)
666 {
667 enum mpc_sie200_error_t ret;
668
669 ret = mpc_sie200_set_ctrl(&MPC_CODE_SRAM1_DEV_S, ctrl);
670
671 return error_trans(ret);
672 }
673
SRAM1_MPC_GetRegionConfig(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR * attr)674 static int32_t SRAM1_MPC_GetRegionConfig(uintptr_t base,
675 uintptr_t limit,
676 ARM_MPC_SEC_ATTR* attr)
677 {
678 enum mpc_sie200_error_t ret;
679
680 ret = mpc_sie200_get_region_config(&MPC_CODE_SRAM1_DEV_S, base, limit,
681 (enum mpc_sie200_sec_attr_t*)attr);
682
683 return error_trans(ret);
684 }
685
SRAM1_MPC_ConfigRegion(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR attr)686 static int32_t SRAM1_MPC_ConfigRegion(uintptr_t base,
687 uintptr_t limit,
688 ARM_MPC_SEC_ATTR attr)
689 {
690 enum mpc_sie200_error_t ret;
691
692 ret = mpc_sie200_config_region(&MPC_CODE_SRAM1_DEV_S, base, limit,
693 (enum mpc_sie200_sec_attr_t)attr);
694
695 return error_trans(ret);
696 }
697
SRAM1_MPC_EnableInterrupt(void)698 static int32_t SRAM1_MPC_EnableInterrupt(void)
699 {
700 enum mpc_sie200_error_t ret;
701
702 ret = mpc_sie200_irq_enable(&MPC_CODE_SRAM1_DEV_S);
703
704 return error_trans(ret);
705 }
706
SRAM1_MPC_DisableInterrupt(void)707 static void SRAM1_MPC_DisableInterrupt(void)
708 {
709 mpc_sie200_irq_disable(&MPC_CODE_SRAM1_DEV_S);
710 }
711
712
SRAM1_MPC_ClearInterrupt(void)713 static void SRAM1_MPC_ClearInterrupt(void)
714 {
715 mpc_sie200_clear_irq(&MPC_CODE_SRAM1_DEV_S);
716 }
717
SRAM1_MPC_InterruptState(void)718 static uint32_t SRAM1_MPC_InterruptState(void)
719 {
720 return mpc_sie200_irq_state(&MPC_CODE_SRAM1_DEV_S);
721 }
722
SRAM1_MPC_LockDown(void)723 static int32_t SRAM1_MPC_LockDown(void)
724 {
725 return mpc_sie200_lock_down(&MPC_CODE_SRAM1_DEV_S);
726 }
727
728 /* SRAM1_MPC Driver CMSIS access structure */
729 extern ARM_DRIVER_MPC Driver_SRAM1_MPC;
730 ARM_DRIVER_MPC Driver_SRAM1_MPC = {
731 .GetVersion = ARM_MPC_GetVersion,
732 .Initialize = SRAM1_MPC_Initialize,
733 .Uninitialize = SRAM1_MPC_Uninitialize,
734 .GetBlockSize = SRAM1_MPC_GetBlockSize,
735 .GetCtrlConfig = SRAM1_MPC_GetCtrlConfig,
736 .SetCtrlConfig = SRAM1_MPC_SetCtrlConfig,
737 .ConfigRegion = SRAM1_MPC_ConfigRegion,
738 .GetRegionConfig = SRAM1_MPC_GetRegionConfig,
739 .EnableInterrupt = SRAM1_MPC_EnableInterrupt,
740 .DisableInterrupt = SRAM1_MPC_DisableInterrupt,
741 .ClearInterrupt = SRAM1_MPC_ClearInterrupt,
742 .InterruptState = SRAM1_MPC_InterruptState,
743 .LockDown = SRAM1_MPC_LockDown,
744 };
745 #endif /* RTE_CODE_SRAM1_MPC */
746
747 #if (RTE_CODE_SRAM2_MPC)
748 /* Ranges controlled by this SRAM2_MPC */
749 static struct mpc_sie200_memory_range_t MPC_CODE_SRAM2_RANGE_S = {
750 .base = MPC_CODE_SRAM2_RANGE_BASE_S,
751 .limit = MPC_CODE_SRAM2_RANGE_LIMIT_S,
752 .attr = MPC_SIE200_SEC_ATTR_SECURE
753 };
754
755 static struct mpc_sie200_memory_range_t MPC_CODE_SRAM2_RANGE_NS = {
756 .base = MPC_CODE_SRAM2_RANGE_BASE_NS,
757 .limit = MPC_CODE_SRAM2_RANGE_LIMIT_NS,
758 .attr = MPC_SIE200_SEC_ATTR_NONSECURE
759 };
760
761 #define MPC_CODE_SRAM2_RANGE_LIST_LEN 2u
762 static const struct mpc_sie200_memory_range_t* MPC_CODE_SRAM2_RANGE_LIST[MPC_CODE_SRAM2_RANGE_LIST_LEN]=
763 {&MPC_CODE_SRAM2_RANGE_S, &MPC_CODE_SRAM2_RANGE_NS};
764
765 /* SRAM2_MPC Driver wrapper functions */
SRAM2_MPC_Initialize(void)766 static int32_t SRAM2_MPC_Initialize(void)
767 {
768 enum mpc_sie200_error_t ret;
769
770 ret = mpc_sie200_init(&MPC_CODE_SRAM2_DEV_S,
771 MPC_CODE_SRAM2_RANGE_LIST,
772 MPC_CODE_SRAM2_RANGE_LIST_LEN);
773
774 return error_trans(ret);
775 }
776
SRAM2_MPC_Uninitialize(void)777 static int32_t SRAM2_MPC_Uninitialize(void)
778 {
779 /* Nothing to be done */
780 return ARM_DRIVER_OK;
781 }
782
SRAM2_MPC_GetBlockSize(uint32_t * blk_size)783 static int32_t SRAM2_MPC_GetBlockSize(uint32_t* blk_size)
784 {
785 enum mpc_sie200_error_t ret;
786
787 ret = mpc_sie200_get_block_size(&MPC_CODE_SRAM2_DEV_S, blk_size);
788
789 return error_trans(ret);
790 }
791
SRAM2_MPC_GetCtrlConfig(uint32_t * ctrl_val)792 static int32_t SRAM2_MPC_GetCtrlConfig(uint32_t* ctrl_val)
793 {
794 enum mpc_sie200_error_t ret;
795
796 ret = mpc_sie200_get_ctrl(&MPC_CODE_SRAM2_DEV_S, ctrl_val);
797
798 return error_trans(ret);
799 }
800
SRAM2_MPC_SetCtrlConfig(uint32_t ctrl)801 static int32_t SRAM2_MPC_SetCtrlConfig(uint32_t ctrl)
802 {
803 enum mpc_sie200_error_t ret;
804
805 ret = mpc_sie200_set_ctrl(&MPC_CODE_SRAM2_DEV_S, ctrl);
806
807 return error_trans(ret);
808 }
809
SRAM2_MPC_GetRegionConfig(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR * attr)810 static int32_t SRAM2_MPC_GetRegionConfig(uintptr_t base,
811 uintptr_t limit,
812 ARM_MPC_SEC_ATTR* attr)
813 {
814 enum mpc_sie200_error_t ret;
815
816 ret = mpc_sie200_get_region_config(&MPC_CODE_SRAM2_DEV_S, base, limit,
817 (enum mpc_sie200_sec_attr_t*)attr);
818
819 return error_trans(ret);
820 }
821
SRAM2_MPC_ConfigRegion(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR attr)822 static int32_t SRAM2_MPC_ConfigRegion(uintptr_t base,
823 uintptr_t limit,
824 ARM_MPC_SEC_ATTR attr)
825 {
826 enum mpc_sie200_error_t ret;
827
828 ret = mpc_sie200_config_region(&MPC_CODE_SRAM2_DEV_S, base, limit,
829 (enum mpc_sie200_sec_attr_t)attr);
830
831 return error_trans(ret);
832 }
833
SRAM2_MPC_EnableInterrupt(void)834 static int32_t SRAM2_MPC_EnableInterrupt(void)
835 {
836 enum mpc_sie200_error_t ret;
837
838 ret = mpc_sie200_irq_enable(&MPC_CODE_SRAM2_DEV_S);
839
840 return error_trans(ret);
841 }
842
SRAM2_MPC_DisableInterrupt(void)843 static void SRAM2_MPC_DisableInterrupt(void)
844 {
845 mpc_sie200_irq_disable(&MPC_CODE_SRAM2_DEV_S);
846 }
847
848
SRAM2_MPC_ClearInterrupt(void)849 static void SRAM2_MPC_ClearInterrupt(void)
850 {
851 mpc_sie200_clear_irq(&MPC_CODE_SRAM2_DEV_S);
852 }
853
SRAM2_MPC_InterruptState(void)854 static uint32_t SRAM2_MPC_InterruptState(void)
855 {
856 return mpc_sie200_irq_state(&MPC_CODE_SRAM2_DEV_S);
857 }
858
SRAM2_MPC_LockDown(void)859 static int32_t SRAM2_MPC_LockDown(void)
860 {
861 return mpc_sie200_lock_down(&MPC_CODE_SRAM2_DEV_S);
862 }
863
864 /* SRAM2_MPC Driver CMSIS access structure */
865 extern ARM_DRIVER_MPC Driver_SRAM2_MPC;
866 ARM_DRIVER_MPC Driver_SRAM2_MPC = {
867 .GetVersion = ARM_MPC_GetVersion,
868 .Initialize = SRAM2_MPC_Initialize,
869 .Uninitialize = SRAM2_MPC_Uninitialize,
870 .GetBlockSize = SRAM2_MPC_GetBlockSize,
871 .GetCtrlConfig = SRAM2_MPC_GetCtrlConfig,
872 .SetCtrlConfig = SRAM2_MPC_SetCtrlConfig,
873 .ConfigRegion = SRAM2_MPC_ConfigRegion,
874 .GetRegionConfig = SRAM2_MPC_GetRegionConfig,
875 .EnableInterrupt = SRAM2_MPC_EnableInterrupt,
876 .DisableInterrupt = SRAM2_MPC_DisableInterrupt,
877 .ClearInterrupt = SRAM2_MPC_ClearInterrupt,
878 .InterruptState = SRAM2_MPC_InterruptState,
879 .LockDown = SRAM2_MPC_LockDown,
880 };
881 #endif /* RTE_CODE_SRAM2_MPC */
882
883 #if (RTE_CODE_SRAM3_MPC)
884 /* Ranges controlled by this SRAM3_MPC */
885 static struct mpc_sie200_memory_range_t MPC_CODE_SRAM3_RANGE_S = {
886 .base = MPC_CODE_SRAM3_RANGE_BASE_S,
887 .limit = MPC_CODE_SRAM3_RANGE_LIMIT_S,
888 .attr = MPC_SIE200_SEC_ATTR_SECURE
889 };
890
891 static struct mpc_sie200_memory_range_t MPC_CODE_SRAM3_RANGE_NS = {
892 .base = MPC_CODE_SRAM3_RANGE_BASE_NS,
893 .limit = MPC_CODE_SRAM3_RANGE_LIMIT_NS,
894 .attr = MPC_SIE200_SEC_ATTR_NONSECURE
895 };
896
897 #define MPC_CODE_SRAM3_RANGE_LIST_LEN 2u
898 static const struct mpc_sie200_memory_range_t* MPC_CODE_SRAM3_RANGE_LIST[MPC_CODE_SRAM3_RANGE_LIST_LEN]=
899 {&MPC_CODE_SRAM3_RANGE_S, &MPC_CODE_SRAM3_RANGE_NS};
900
901 /* SRAM3_MPC Driver wrapper functions */
SRAM3_MPC_Initialize(void)902 static int32_t SRAM3_MPC_Initialize(void)
903 {
904 enum mpc_sie200_error_t ret;
905
906 ret = mpc_sie200_init(&MPC_CODE_SRAM3_DEV_S,
907 MPC_CODE_SRAM3_RANGE_LIST,
908 MPC_CODE_SRAM3_RANGE_LIST_LEN);
909
910 return error_trans(ret);
911 }
912
SRAM3_MPC_Uninitialize(void)913 static int32_t SRAM3_MPC_Uninitialize(void)
914 {
915 /* Nothing to be done */
916 return ARM_DRIVER_OK;
917 }
918
SRAM3_MPC_GetBlockSize(uint32_t * blk_size)919 static int32_t SRAM3_MPC_GetBlockSize(uint32_t* blk_size)
920 {
921 enum mpc_sie200_error_t ret;
922
923 ret = mpc_sie200_get_block_size(&MPC_CODE_SRAM3_DEV_S, blk_size);
924
925 return error_trans(ret);
926 }
927
SRAM3_MPC_GetCtrlConfig(uint32_t * ctrl_val)928 static int32_t SRAM3_MPC_GetCtrlConfig(uint32_t* ctrl_val)
929 {
930 enum mpc_sie200_error_t ret;
931
932 ret = mpc_sie200_get_ctrl(&MPC_CODE_SRAM3_DEV_S, ctrl_val);
933
934 return error_trans(ret);
935 }
936
SRAM3_MPC_SetCtrlConfig(uint32_t ctrl)937 static int32_t SRAM3_MPC_SetCtrlConfig(uint32_t ctrl)
938 {
939 enum mpc_sie200_error_t ret;
940
941 ret = mpc_sie200_set_ctrl(&MPC_CODE_SRAM3_DEV_S, ctrl);
942
943 return error_trans(ret);
944 }
945
SRAM3_MPC_GetRegionConfig(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR * attr)946 static int32_t SRAM3_MPC_GetRegionConfig(uintptr_t base,
947 uintptr_t limit,
948 ARM_MPC_SEC_ATTR* attr)
949 {
950 enum mpc_sie200_error_t ret;
951
952 ret = mpc_sie200_get_region_config(&MPC_CODE_SRAM3_DEV_S, base, limit,
953 (enum mpc_sie200_sec_attr_t*)attr);
954
955 return error_trans(ret);
956 }
957
SRAM3_MPC_ConfigRegion(uintptr_t base,uintptr_t limit,ARM_MPC_SEC_ATTR attr)958 static int32_t SRAM3_MPC_ConfigRegion(uintptr_t base,
959 uintptr_t limit,
960 ARM_MPC_SEC_ATTR attr)
961 {
962 enum mpc_sie200_error_t ret;
963
964 ret = mpc_sie200_config_region(&MPC_CODE_SRAM3_DEV_S, base, limit,
965 (enum mpc_sie200_sec_attr_t)attr);
966
967 return error_trans(ret);
968 }
969
SRAM3_MPC_EnableInterrupt(void)970 static int32_t SRAM3_MPC_EnableInterrupt(void)
971 {
972 enum mpc_sie200_error_t ret;
973
974 ret = mpc_sie200_irq_enable(&MPC_CODE_SRAM3_DEV_S);
975
976 return error_trans(ret);
977 }
978
SRAM3_MPC_DisableInterrupt(void)979 static void SRAM3_MPC_DisableInterrupt(void)
980 {
981 mpc_sie200_irq_disable(&MPC_CODE_SRAM3_DEV_S);
982 }
983
984
SRAM3_MPC_ClearInterrupt(void)985 static void SRAM3_MPC_ClearInterrupt(void)
986 {
987 mpc_sie200_clear_irq(&MPC_CODE_SRAM3_DEV_S);
988 }
989
SRAM3_MPC_InterruptState(void)990 static uint32_t SRAM3_MPC_InterruptState(void)
991 {
992 return mpc_sie200_irq_state(&MPC_CODE_SRAM3_DEV_S);
993 }
994
SRAM3_MPC_LockDown(void)995 static int32_t SRAM3_MPC_LockDown(void)
996 {
997 return mpc_sie200_lock_down(&MPC_CODE_SRAM3_DEV_S);
998 }
999
1000 /* SRAM3_MPC Driver CMSIS access structure */
1001 extern ARM_DRIVER_MPC Driver_SRAM3_MPC;
1002 ARM_DRIVER_MPC Driver_SRAM3_MPC = {
1003 .GetVersion = ARM_MPC_GetVersion,
1004 .Initialize = SRAM3_MPC_Initialize,
1005 .Uninitialize = SRAM3_MPC_Uninitialize,
1006 .GetBlockSize = SRAM3_MPC_GetBlockSize,
1007 .GetCtrlConfig = SRAM3_MPC_GetCtrlConfig,
1008 .SetCtrlConfig = SRAM3_MPC_SetCtrlConfig,
1009 .ConfigRegion = SRAM3_MPC_ConfigRegion,
1010 .GetRegionConfig = SRAM3_MPC_GetRegionConfig,
1011 .EnableInterrupt = SRAM3_MPC_EnableInterrupt,
1012 .DisableInterrupt = SRAM3_MPC_DisableInterrupt,
1013 .ClearInterrupt = SRAM3_MPC_ClearInterrupt,
1014 .InterruptState = SRAM3_MPC_InterruptState,
1015 .LockDown = SRAM3_MPC_LockDown,
1016 };
1017 #endif /* RTE_CODE_SRAM3_MPC */
1018