[352] | 1 | /**************************************************************************//**
|
---|
| 2 | * @file mmu_Renesas_RZ_A1.c
|
---|
| 3 | * @brief MMU Startup File for
|
---|
| 4 | * mmu_Renesas_RZ_A1 Device Series
|
---|
| 5 | * @version V1.01
|
---|
| 6 | * @date 2 Aug 2013
|
---|
| 7 | *
|
---|
| 8 | * @note
|
---|
| 9 | *
|
---|
| 10 | ******************************************************************************/
|
---|
| 11 | /* Copyright (c) 2011 - 2013 ARM LIMITED
|
---|
| 12 |
|
---|
| 13 | All rights reserved.
|
---|
| 14 | Redistribution and use in source and binary forms, with or without
|
---|
| 15 | modification, are permitted provided that the following conditions are met:
|
---|
| 16 | - Redistributions of source code must retain the above copyright
|
---|
| 17 | notice, this list of conditions and the following disclaimer.
|
---|
| 18 | - Redistributions in binary form must reproduce the above copyright
|
---|
| 19 | notice, this list of conditions and the following disclaimer in the
|
---|
| 20 | documentation and/or other materials provided with the distribution.
|
---|
| 21 | - Neither the name of ARM nor the names of its contributors may be used
|
---|
| 22 | to endorse or promote products derived from this software without
|
---|
| 23 | specific prior written permission.
|
---|
| 24 | *
|
---|
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
| 26 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 27 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 28 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
---|
| 29 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
---|
| 30 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
---|
| 31 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
| 32 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
| 33 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
---|
| 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
---|
| 35 | POSSIBILITY OF SUCH DAMAGE.
|
---|
| 36 | ---------------------------------------------------------------------------*/
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | #define Renesas_RZ_A1_SPI_MIO_BASE (0x3fe00000UL) /*!< (SPI_MIO ) Base Address */
|
---|
| 40 | #define Renesas_RZ_A1_BSC_BASE (0x3ff00000UL) /*!< (BSC ) Base Address */
|
---|
| 41 | #define Renesas_RZ_A1_PERIPH_BASE0 (0xe8000000UL) /*!< (PERIPH0 ) Base Address */
|
---|
| 42 | #define Renesas_RZ_A1_PERIPH_BASE1 (0xfcf00000UL) /*!< (PERIPH1 ) Base Address */
|
---|
| 43 | // L1 Cache info and restrictions about architecture of the caches (CCSIR register):
|
---|
| 44 | // Write-Through support *not* available
|
---|
| 45 | // Write-Back support available.
|
---|
| 46 | // Read allocation support available.
|
---|
| 47 | // Write allocation support available.
|
---|
| 48 |
|
---|
| 49 | //Note: You should use the Shareable attribute carefully.
|
---|
| 50 | //For cores without coherency logic (such as SCU) marking a region as shareable forces the processor to not cache that region regardless the inner cache settings.
|
---|
| 51 | //CA9-RTX uses LDREX/STREX instructions relying on Local monitors. Local monitors will be used only when the region gets cached, regions that are not cached will use the Global Monitor.
|
---|
| 52 | //Some A9 implementations does not include Global Monitors, so wrongly setting the attribute Shareable may cause STREX to fail.
|
---|
| 53 |
|
---|
| 54 | //Recall: When the Shareable attribute is applied to a memory region that is not Write-Back, Normal memory, data held in this region is treated as Non-cacheable.
|
---|
| 55 | //When SMP bit = 0, Inner WB/WA Cacheable Shareable attributes are treated as Non-cacheable.
|
---|
| 56 | //When SMP bit = 1, Inner WB/WA Cacheable Shareable attributes are treated as Cacheable.
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | //Following MMU configuration is expected
|
---|
| 60 | //SCTLR.AFE == 1 (Simplified access permissions model - AP[2:1] define access permissions, AP[0] is an access flag)
|
---|
| 61 | //SCTLR.TRE == 0 (TEX remap disabled, so memory type and attributes are described directly by bits in the descriptor)
|
---|
| 62 | //Domain 0 is always the Client domain
|
---|
| 63 | //Descriptors place all memory in domain 0
|
---|
| 64 | //There are no restrictions by privilege level (PL0 can access all memory)
|
---|
| 65 |
|
---|
| 66 | #include <stdint.h>
|
---|
| 67 | #include "MBRZA1H.h"
|
---|
| 68 |
|
---|
| 69 | //Import symbols from linker
|
---|
| 70 | extern uint32_t Image$$VECTORS$$Base;
|
---|
| 71 | extern uint32_t Image$$RO_DATA$$Base;
|
---|
| 72 | extern uint32_t Image$$RW_DATA$$Base;
|
---|
| 73 | extern uint32_t Image$$RW_IRAM1$$Base;
|
---|
| 74 | #if !defined ( __ICCARM__ )
|
---|
| 75 | extern uint32_t Image$$TTB$$ZI$$Base;
|
---|
| 76 | #endif
|
---|
| 77 |
|
---|
| 78 | #if defined( __CC_ARM )
|
---|
| 79 | #elif defined( __ICCARM__ )
|
---|
| 80 | #else
|
---|
| 81 | extern uint32_t Image$$RW_DATA_NC$$Base;
|
---|
| 82 | extern uint32_t Image$$ZI_DATA_NC$$Base;
|
---|
| 83 | #endif
|
---|
| 84 |
|
---|
| 85 | extern uint32_t Image$$VECTORS$$Limit;
|
---|
| 86 | extern uint32_t Image$$RO_DATA$$Limit;
|
---|
| 87 | extern uint32_t Image$$RW_DATA$$Limit;
|
---|
| 88 | extern uint32_t Image$$RW_IRAM1$$Limit;
|
---|
| 89 | #if defined( __CC_ARM )
|
---|
| 90 | #else
|
---|
| 91 | extern uint32_t Image$$RW_DATA_NC$$Limit;
|
---|
| 92 | extern uint32_t Image$$ZI_DATA_NC$$Limit;
|
---|
| 93 | #endif
|
---|
| 94 |
|
---|
| 95 | #if defined( __ICCARM__ )
|
---|
| 96 | #define VECTORS_SIZE (((uint32_t)Image$$VECTORS$$Limit >> 20) - ((uint32_t)Image$$VECTORS$$Base >> 20) + 1)
|
---|
| 97 | #define RO_DATA_SIZE (((uint32_t)Image$$RO_DATA$$Limit >> 20) - ((uint32_t)Image$$RO_DATA$$Base >> 20) + 1)
|
---|
| 98 | #define RW_DATA_SIZE (((uint32_t)Image$$RW_DATA$$Limit >> 20) - ((uint32_t)Image$$RW_DATA$$Base >> 20) + 1)
|
---|
| 99 | #define RW_IRAM1_SIZE (((uint32_t)Image$$RW_IRAM1$$Limit >> 20) - ((uint32_t)Image$$RW_IRAM1$$Base >> 20) + 1)
|
---|
| 100 | #else
|
---|
| 101 | #define VECTORS_SIZE (((uint32_t)&Image$$VECTORS$$Limit >> 20) - ((uint32_t)&Image$$VECTORS$$Base >> 20) + 1)
|
---|
| 102 | #define RO_DATA_SIZE (((uint32_t)&Image$$RO_DATA$$Limit >> 20) - ((uint32_t)&Image$$RO_DATA$$Base >> 20) + 1)
|
---|
| 103 | #define RW_DATA_SIZE (((uint32_t)&Image$$RW_DATA$$Limit >> 20) - ((uint32_t)&Image$$RW_DATA$$Base >> 20) + 1)
|
---|
| 104 | #define RW_IRAM1_SIZE (((uint32_t)&Image$$RW_IRAM1$$Limit >> 20) - ((uint32_t)&Image$$RW_IRAM1$$Base >> 20) + 1)
|
---|
| 105 | #endif
|
---|
| 106 |
|
---|
| 107 | #if defined( __CC_ARM )
|
---|
| 108 | #else
|
---|
| 109 | #define RW_DATA_NC_SIZE (((uint32_t)&Image$$RW_DATA_NC$$Limit >> 20) - ((uint32_t)&Image$$RW_DATA_NC$$Base >> 20) + 1)
|
---|
| 110 | #define ZI_DATA_NC_SIZE (((uint32_t)&Image$$ZI_DATA_NC$$Limit >> 20) - ((uint32_t)&Image$$ZI_DATA_NC$$Base >> 20) + 1)
|
---|
| 111 | #endif
|
---|
| 112 |
|
---|
| 113 | static uint32_t Sect_Normal; //outer & inner wb/wa, non-shareable, executable, rw, domain 0, base addr 0
|
---|
| 114 | static uint32_t Sect_Normal_NC; //non-shareable, non-executable, rw, domain 0, base addr 0
|
---|
| 115 | static uint32_t Sect_Normal_Cod; //outer & inner wb/wa, non-shareable, executable, ro, domain 0, base addr 0
|
---|
| 116 | static uint32_t Sect_Normal_RO; //as Sect_Normal_Cod, but not executable
|
---|
| 117 | static uint32_t Sect_Normal_RW; //as Sect_Normal_Cod, but writeable and not executable
|
---|
| 118 | static uint32_t Sect_Device_RO; //device, non-shareable, non-executable, ro, domain 0, base addr 0
|
---|
| 119 | static uint32_t Sect_Device_RW; //as Sect_Device_RO, but writeable
|
---|
| 120 |
|
---|
| 121 | /* Define global descriptors */
|
---|
| 122 | static uint32_t Page_L1_4k = 0x0; //generic
|
---|
| 123 | static uint32_t Page_L1_64k = 0x0; //generic
|
---|
| 124 | static uint32_t Page_4k_Device_RW; //Shared device, not executable, rw, domain 0
|
---|
| 125 | static uint32_t Page_64k_Device_RW; //Shared device, not executable, rw, domain 0
|
---|
| 126 |
|
---|
| 127 | #if defined ( __ICCARM__ )
|
---|
| 128 | __no_init uint32_t Image$$TTB$$ZI$$Base @ ".retram";
|
---|
| 129 | uint32_t Image$$VECTORS$$Base;
|
---|
| 130 | uint32_t Image$$RO_DATA$$Base;
|
---|
| 131 | uint32_t Image$$RW_DATA$$Base;
|
---|
| 132 | uint32_t Image$$RW_IRAM1$$Base;
|
---|
| 133 |
|
---|
| 134 | uint32_t Image$$VECTORS$$Limit;
|
---|
| 135 | uint32_t Image$$RO_DATA$$Limit;
|
---|
| 136 | uint32_t Image$$RW_DATA$$Limit;
|
---|
| 137 | uint32_t Image$$RW_IRAM1$$Limit;
|
---|
| 138 | #endif
|
---|
| 139 |
|
---|
| 140 | void create_translation_table(void)
|
---|
| 141 | {
|
---|
| 142 | mmu_region_attributes_Type region;
|
---|
| 143 | #if defined ( __ICCARM__ )
|
---|
| 144 | #pragma section=".intvec"
|
---|
| 145 | #pragma section=".rodata"
|
---|
| 146 | #pragma section=".rwdata"
|
---|
| 147 | #pragma section=".bss"
|
---|
| 148 |
|
---|
| 149 | Image$$VECTORS$$Base = (uint32_t) __section_begin(".intvec");
|
---|
| 150 | Image$$VECTORS$$Limit= ((uint32_t)__section_begin(".intvec")+(uint32_t)__section_size(".intvec"));
|
---|
| 151 | Image$$RO_DATA$$Base = (uint32_t) __section_begin(".rodata");
|
---|
| 152 | Image$$RO_DATA$$Limit= ((uint32_t)__section_begin(".rodata")+(uint32_t)__section_size(".rodata"));
|
---|
| 153 | Image$$RW_DATA$$Base = (uint32_t) __section_begin(".rwdata");
|
---|
| 154 | Image$$RW_DATA$$Limit= ((uint32_t)__section_begin(".rwdata")+(uint32_t)__section_size(".rwdata"));
|
---|
| 155 | Image$$RW_IRAM1$$Base = (uint32_t) __section_begin(".bss");
|
---|
| 156 | Image$$RW_IRAM1$$Limit= ((uint32_t)__section_begin(".bss")+(uint32_t)__section_size(".bss"));
|
---|
| 157 | #endif
|
---|
| 158 | /*
|
---|
| 159 | * Generate descriptors. Refer to MBRZA1H.h to get information about attributes
|
---|
| 160 | *
|
---|
| 161 | */
|
---|
| 162 | //Create descriptors for Vectors, RO, RW, ZI sections
|
---|
| 163 | section_normal(Sect_Normal, region);
|
---|
| 164 | section_normal_cod(Sect_Normal_Cod, region);
|
---|
| 165 | section_normal_ro(Sect_Normal_RO, region);
|
---|
| 166 | section_normal_rw(Sect_Normal_RW, region);
|
---|
| 167 | //Create descriptors for peripherals
|
---|
| 168 | section_device_ro(Sect_Device_RO, region);
|
---|
| 169 | section_device_rw(Sect_Device_RW, region);
|
---|
| 170 | section_normal_nc(Sect_Normal_NC, region);
|
---|
| 171 | //Create descriptors for 64k pages
|
---|
| 172 | page64k_device_rw(Page_L1_64k, Page_64k_Device_RW, region);
|
---|
| 173 | //Create descriptors for 4k pages
|
---|
| 174 | page4k_device_rw(Page_L1_4k, Page_4k_Device_RW, region);
|
---|
| 175 |
|
---|
| 176 | /*
|
---|
| 177 | * Define MMU flat-map regions and attributes
|
---|
| 178 | *
|
---|
| 179 | */
|
---|
| 180 |
|
---|
| 181 | //Create 4GB of faulting entries
|
---|
| 182 | __TTSection (&Image$$TTB$$ZI$$Base, 0, 4096, DESCRIPTOR_FAULT);
|
---|
| 183 |
|
---|
| 184 | // R7S72100 memory map.
|
---|
| 185 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_NORFLASH_BASE0 , 64, Sect_Normal_RO);
|
---|
| 186 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_NORFLASH_BASE1 , 64, Sect_Normal_RO);
|
---|
| 187 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_SDRAM_BASE0 , 64, Sect_Normal_RW);
|
---|
| 188 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_SDRAM_BASE1 , 64, Sect_Normal_RW);
|
---|
| 189 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_USER_AREA0 , 64, Sect_Normal_RW);
|
---|
| 190 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_USER_AREA1 , 64, Sect_Normal_RW);
|
---|
| 191 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_SPI_IO0 , 64, Sect_Normal_RO);
|
---|
| 192 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_SPI_IO1 , 64, Sect_Normal_RO);
|
---|
| 193 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_ONCHIP_SRAM_BASE , 10, Sect_Normal_RW);
|
---|
| 194 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_SPI_MIO_BASE , 1, Sect_Device_RW);
|
---|
| 195 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_BSC_BASE , 1, Sect_Device_RW);
|
---|
| 196 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_PERIPH_BASE0 , 3, Sect_Device_RW);
|
---|
| 197 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_PERIPH_BASE1 , 49, Sect_Device_RW);
|
---|
| 198 |
|
---|
| 199 | #if defined( __ICCARM__ )
|
---|
| 200 | //Define Image
|
---|
| 201 | __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)Image$$RO_DATA$$Base, RO_DATA_SIZE, Sect_Normal_Cod);
|
---|
| 202 | __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)Image$$VECTORS$$Base, VECTORS_SIZE, Sect_Normal_Cod);
|
---|
| 203 | __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)Image$$RW_DATA$$Base, RW_DATA_SIZE, Sect_Normal_RW);
|
---|
| 204 | __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)Image$$RW_IRAM1$$Base, RW_IRAM1_SIZE, Sect_Normal_RW);
|
---|
| 205 | #else
|
---|
| 206 | //Define Image
|
---|
| 207 | __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$RO_DATA$$Base, RO_DATA_SIZE, Sect_Normal_RO);
|
---|
| 208 | __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$VECTORS$$Base, VECTORS_SIZE, Sect_Normal_Cod);
|
---|
| 209 | __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$RW_DATA$$Base, RW_DATA_SIZE, Sect_Normal_RW);
|
---|
| 210 | __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$RW_IRAM1$$Base, RW_IRAM1_SIZE, Sect_Normal_RW);
|
---|
| 211 | #endif
|
---|
| 212 |
|
---|
| 213 | #if defined( __CC_ARM )
|
---|
| 214 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_ONCHIP_SRAM_NC_BASE, 10, Sect_Normal_NC);
|
---|
| 215 | #elif defined ( __ICCARM__ )
|
---|
| 216 | __TTSection (&Image$$TTB$$ZI$$Base, Renesas_RZ_A1_ONCHIP_SRAM_NC_BASE, 10, Sect_Normal_NC);
|
---|
| 217 |
|
---|
| 218 | #else
|
---|
| 219 | __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$RW_DATA_NC$$Base, RW_DATA_NC_SIZE, Sect_Normal_NC);
|
---|
| 220 | __TTSection (&Image$$TTB$$ZI$$Base, (uint32_t)&Image$$ZI_DATA_NC$$Base, ZI_DATA_NC_SIZE, Sect_Normal_NC);
|
---|
| 221 | #endif
|
---|
| 222 |
|
---|
| 223 | /* Set location of level 1 page table
|
---|
| 224 | ; 31:14 - Translation table base addr (31:14-TTBCR.N, TTBCR.N is 0 out of reset)
|
---|
| 225 | ; 13:7 - 0x0
|
---|
| 226 | ; 6 - IRGN[0] 0x0 (Inner WB WA)
|
---|
| 227 | ; 5 - NOS 0x0 (Non-shared)
|
---|
| 228 | ; 4:3 - RGN 0x1 (Outer WB WA)
|
---|
| 229 | ; 2 - IMP 0x0 (Implementation Defined)
|
---|
| 230 | ; 1 - S 0x0 (Non-shared)
|
---|
| 231 | ; 0 - IRGN[1] 0x1 (Inner WB WA) */
|
---|
| 232 | __set_TTBR0(((uint32_t)&Image$$TTB$$ZI$$Base) | 9);
|
---|
| 233 |
|
---|
| 234 | /* Set up domain access control register
|
---|
| 235 | ; We set domain 0 to Client and all other domains to No Access.
|
---|
| 236 | ; All translation table entries specify domain 0 */
|
---|
| 237 | __set_DACR(1);
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 |
|
---|
| 241 | /*----------------------------------------------------------------------------
|
---|
| 242 | * end of file
|
---|
| 243 | *---------------------------------------------------------------------------*/
|
---|