|
| 1 | +/* |
| 2 | + * Copyright 2025 NXP |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/devicetree.h> |
| 8 | +#include <zephyr/arch/arm/cortex_m/arm_mpu_mem_cfg.h> |
| 9 | + |
| 10 | +#define MEMORY_REGION_SIZE_KB(SIZE) (SIZE / 1024) |
| 11 | + |
| 12 | +#define ITCM_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(itcm), 0) |
| 13 | +#define DTCM_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(dtcm), 0) |
| 14 | +#define OCRAM1_SHM_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(ocram1), 0) |
| 15 | +#define OCRAM2_SHM_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(ocram2), 0) |
| 16 | +#define HYPER_RAM_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(flexspi2), 1) |
| 17 | +#define QSPI_FLASH_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(flexspi), 1) |
| 18 | +#define PERIPHERAL_SIZE DT_REG_SIZE_BY_IDX(DT_NODELABEL(peripheral), 0) |
| 19 | + |
| 20 | +#define REGION_ITCM_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(itcm), 0) |
| 21 | +#define REGION_ITCM_SIZE \ |
| 22 | + REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(ITCM_SIZE)) |
| 23 | +#define REGION_DTCM_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(dtcm), 0) |
| 24 | +#define REGION_DTCM_SIZE \ |
| 25 | + REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(DTCM_SIZE)) |
| 26 | +#define REGION_OCRAM1_SHM_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(ocram1), 0) |
| 27 | +#define REGION_OCRAM1_SHM_SIZE \ |
| 28 | + REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(OCRAM1_SHM_SIZE)) |
| 29 | +#define REGION_OCRAM2_SHM_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(ocram2), 0) |
| 30 | +#define REGION_OCRAM2_SHM_SIZE \ |
| 31 | + REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(OCRAM2_SHM_SIZE)) |
| 32 | +#define REGION_HYPER_RAM_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(flexspi2), 1) |
| 33 | +#define REGION_HYPER_RAM_SIZE \ |
| 34 | + REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(HYPER_RAM_SIZE)) |
| 35 | +#define REGION_QSPI_FLASH_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(flexspi), 1) |
| 36 | +#define REGION_QSPI_FLASH_SIZE \ |
| 37 | + REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(QSPI_FLASH_SIZE)) |
| 38 | +#define REGION_PERIPHERAL_BASE_ADDRESS DT_REG_ADDR_BY_IDX(DT_NODELABEL(peripheral), 0) |
| 39 | +#define REGION_PERIPHERAL_SIZE \ |
| 40 | + REGION_CUSTOMED_MEMORY_SIZE(MEMORY_REGION_SIZE_KB(PERIPHERAL_SIZE)) |
| 41 | + |
| 42 | +static const struct arm_mpu_region mpu_regions[] = { |
| 43 | + /* |
| 44 | + * Add "UNMAPPED" region to deny access to whole address space to |
| 45 | + * workaround speculative prefetch. |
| 46 | + * Refer to Arm errata 1013783-B for more details. |
| 47 | + */ |
| 48 | + MPU_REGION_ENTRY("UNMAPPED", 0, |
| 49 | + {REGION_4G | MPU_RASR_XN_Msk | P_NA_U_NA_Msk}), |
| 50 | + |
| 51 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(itcm), okay) |
| 52 | + MPU_REGION_ENTRY("ITCM", REGION_ITCM_BASE_ADDRESS, |
| 53 | + REGION_FLASH_ATTR(REGION_ITCM_SIZE)), |
| 54 | +#endif |
| 55 | + |
| 56 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(dtcm), okay) |
| 57 | + MPU_REGION_ENTRY("DTCM", REGION_DTCM_BASE_ADDRESS, |
| 58 | + REGION_RAM_NOCACHE_ATTR(REGION_DTCM_SIZE)), |
| 59 | +#endif |
| 60 | + |
| 61 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(ocram1), okay) |
| 62 | + MPU_REGION_ENTRY("OCRAM1", REGION_OCRAM1_SHM_BASE_ADDRESS, |
| 63 | + REGION_RAM_ATTR(REGION_OCRAM1_SHM_SIZE)), |
| 64 | +#endif |
| 65 | + |
| 66 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(ocram2), okay) |
| 67 | + MPU_REGION_ENTRY("OCRAM2", REGION_OCRAM2_SHM_BASE_ADDRESS, |
| 68 | + REGION_RAM_NOCACHE_ATTR(REGION_OCRAM2_SHM_SIZE)), |
| 69 | +#endif |
| 70 | + |
| 71 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(hyperram0), okay) |
| 72 | + MPU_REGION_ENTRY("HYPER_RAM", REGION_HYPER_RAM_BASE_ADDRESS, |
| 73 | + REGION_RAM_ATTR(REGION_HYPER_RAM_SIZE)), |
| 74 | +#endif |
| 75 | + |
| 76 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(w25q128jw), okay) |
| 77 | + MPU_REGION_ENTRY("QSPI_FLASH", REGION_QSPI_FLASH_BASE_ADDRESS, |
| 78 | + REGION_FLASH_ATTR(REGION_QSPI_FLASH_SIZE)), |
| 79 | +#endif |
| 80 | + |
| 81 | + MPU_REGION_ENTRY("PERIPHERAL", REGION_PERIPHERAL_BASE_ADDRESS, |
| 82 | + REGION_PPB_ATTR(REGION_PERIPHERAL_SIZE)), |
| 83 | +}; |
| 84 | + |
| 85 | +const struct arm_mpu_config mpu_config = { |
| 86 | + .num_regions = ARRAY_SIZE(mpu_regions), |
| 87 | + .mpu_regions = mpu_regions, |
| 88 | +}; |
0 commit comments