2 * linux/arch/arm/mm/nommu.c
4 * ARM uCLinux supporting functions.
6 #include <linux/module.h>
8 #include <linux/pagemap.h>
10 #include <linux/memblock.h>
11 #include <linux/kernel.h>
13 #include <asm/cacheflush.h>
14 #include <asm/sections.h>
16 #include <asm/setup.h>
17 #include <asm/traps.h>
18 #include <asm/mach/arch.h>
19 #include <asm/cputype.h>
21 #include <asm/procinfo.h>
26 struct mpu_rgn_info mpu_rgn_info
;
29 static void rgnr_write(u32 v
)
31 asm("mcr p15, 0, %0, c6, c2, 0" : : "r" (v
));
34 /* Data-side / unified region attributes */
36 /* Region access control register */
37 static void dracr_write(u32 v
)
39 asm("mcr p15, 0, %0, c6, c1, 4" : : "r" (v
));
42 /* Region size register */
43 static void drsr_write(u32 v
)
45 asm("mcr p15, 0, %0, c6, c1, 2" : : "r" (v
));
48 /* Region base address register */
49 static void drbar_write(u32 v
)
51 asm("mcr p15, 0, %0, c6, c1, 0" : : "r" (v
));
54 static u32
drbar_read(void)
57 asm("mrc p15, 0, %0, c6, c1, 0" : "=r" (v
));
60 /* Optional instruction-side region attributes */
62 /* I-side Region access control register */
63 static void iracr_write(u32 v
)
65 asm("mcr p15, 0, %0, c6, c1, 5" : : "r" (v
));
68 /* I-side Region size register */
69 static void irsr_write(u32 v
)
71 asm("mcr p15, 0, %0, c6, c1, 3" : : "r" (v
));
74 /* I-side Region base address register */
75 static void irbar_write(u32 v
)
77 asm("mcr p15, 0, %0, c6, c1, 1" : : "r" (v
));
80 static unsigned long irbar_read(void)
83 asm("mrc p15, 0, %0, c6, c1, 1" : "=r" (v
));
87 /* MPU initialisation functions */
88 void __init
sanity_check_meminfo_mpu(void)
91 struct membank
*bank
= meminfo
.bank
;
92 phys_addr_t phys_offset
= PHYS_OFFSET
;
93 phys_addr_t aligned_region_size
, specified_mem_size
, rounded_mem_size
;
95 /* Initially only use memory continuous from PHYS_OFFSET */
96 if (bank_phys_start(&bank
[0]) != phys_offset
)
97 panic("First memory bank must be contiguous from PHYS_OFFSET");
99 /* Banks have already been sorted by start address */
100 for (i
= 1; i
< meminfo
.nr_banks
; i
++) {
101 if (bank
[i
].start
<= bank_phys_end(&bank
[0]) &&
102 bank_phys_end(&bank
[i
]) > bank_phys_end(&bank
[0])) {
103 bank
[0].size
= bank_phys_end(&bank
[i
]) - bank
[0].start
;
105 pr_notice("Ignoring RAM after 0x%.8lx. "
106 "First non-contiguous (ignored) bank start: 0x%.8lx\n",
107 (unsigned long)bank_phys_end(&bank
[0]),
108 (unsigned long)bank_phys_start(&bank
[i
]));
112 /* All contiguous banks are now merged in to the first bank */
113 meminfo
.nr_banks
= 1;
114 specified_mem_size
= bank
[0].size
;
117 * MPU has curious alignment requirements: Size must be power of 2, and
118 * region start must be aligned to the region size
120 if (phys_offset
!= 0)
121 pr_info("PHYS_OFFSET != 0 => MPU Region size constrained by alignment requirements\n");
124 * Maximum aligned region might overflow phys_addr_t if phys_offset is
125 * 0. Hence we keep everything below 4G until we take the smaller of
126 * the aligned_region_size and rounded_mem_size, one of which is
127 * guaranteed to be smaller than the maximum physical address.
129 aligned_region_size
= (phys_offset
- 1) ^ (phys_offset
);
130 /* Find the max power-of-two sized region that fits inside our bank */
131 rounded_mem_size
= (1 << __fls(bank
[0].size
)) - 1;
133 /* The actual region size is the smaller of the two */
134 aligned_region_size
= aligned_region_size
< rounded_mem_size
135 ? aligned_region_size
+ 1
136 : rounded_mem_size
+ 1;
138 if (aligned_region_size
!= specified_mem_size
)
139 pr_warn("Truncating memory from 0x%.8lx to 0x%.8lx (MPU region constraints)",
140 (unsigned long)specified_mem_size
,
141 (unsigned long)aligned_region_size
);
143 meminfo
.bank
[0].size
= aligned_region_size
;
144 pr_debug("MPU Region from 0x%.8lx size 0x%.8lx (end 0x%.8lx))\n",
145 (unsigned long)phys_offset
,
146 (unsigned long)aligned_region_size
,
147 (unsigned long)bank_phys_end(&bank
[0]));
151 static int mpu_present(void)
153 return ((read_cpuid_ext(CPUID_EXT_MMFR0
) & MMFR0_PMSA
) == MMFR0_PMSAv7
);
156 static int mpu_max_regions(void)
159 * We don't support a different number of I/D side regions so if we
160 * have separate instruction and data memory maps then return
161 * whichever side has a smaller number of supported regions.
163 u32 dregions
, iregions
, mpuir
;
164 mpuir
= read_cpuid(CPUID_MPUIR
);
166 dregions
= iregions
= (mpuir
& MPUIR_DREGION_SZMASK
) >> MPUIR_DREGION
;
168 /* Check for separate d-side and i-side memory maps */
169 if (mpuir
& MPUIR_nU
)
170 iregions
= (mpuir
& MPUIR_IREGION_SZMASK
) >> MPUIR_IREGION
;
172 /* Use the smallest of the two maxima */
173 return min(dregions
, iregions
);
176 static int mpu_iside_independent(void)
178 /* MPUIR.nU specifies whether there is *not* a unified memory map */
179 return read_cpuid(CPUID_MPUIR
) & MPUIR_nU
;
182 static int mpu_min_region_order(void)
184 u32 drbar_result
, irbar_result
;
185 /* We've kept a region free for this probing */
186 rgnr_write(MPU_PROBE_REGION
);
189 * As per ARM ARM, write 0xFFFFFFFC to DRBAR to find the minimum
192 drbar_write(0xFFFFFFFC);
193 drbar_result
= irbar_result
= drbar_read();
195 /* If the MPU is non-unified, we use the larger of the two minima*/
196 if (mpu_iside_independent()) {
197 irbar_write(0xFFFFFFFC);
198 irbar_result
= irbar_read();
201 isb(); /* Ensure that MPU region operations have completed */
202 /* Return whichever result is larger */
203 return __ffs(max(drbar_result
, irbar_result
));
206 static int mpu_setup_region(unsigned int number
, phys_addr_t start
,
207 unsigned int size_order
, unsigned int properties
)
211 /* We kept a region free for probing resolution of MPU regions*/
212 if (number
> mpu_max_regions() || number
== MPU_PROBE_REGION
)
218 if (size_order
< mpu_min_region_order())
221 /* Writing N to bits 5:1 (RSR_SZ) specifies region size 2^N+1 */
222 size_data
= ((size_order
- 1) << MPU_RSR_SZ
) | 1 << MPU_RSR_EN
;
224 dsb(); /* Ensure all previous data accesses occur with old mappings */
228 dracr_write(properties
);
229 isb(); /* Propagate properties before enabling region */
230 drsr_write(size_data
);
232 /* Check for independent I-side registers */
233 if (mpu_iside_independent()) {
235 iracr_write(properties
);
237 irsr_write(size_data
);
241 /* Store region info (we treat i/d side the same, so only store d) */
242 mpu_rgn_info
.rgns
[number
].dracr
= properties
;
243 mpu_rgn_info
.rgns
[number
].drbar
= start
;
244 mpu_rgn_info
.rgns
[number
].drsr
= size_data
;
249 * Set up default MPU regions, doing nothing if there is no MPU
251 void __init
mpu_setup(void)
257 region_err
= mpu_setup_region(MPU_RAM_REGION
, PHYS_OFFSET
,
258 ilog2(meminfo
.bank
[0].size
),
259 MPU_AP_PL1RW_PL0RW
| MPU_RGN_NORMAL
);
261 panic("MPU region initialization failure! %d", region_err
);
263 pr_info("Using ARMv7 PMSA Compliant MPU. "
264 "Region independence: %s, Max regions: %d\n",
265 mpu_iside_independent() ? "Yes" : "No",
270 static void sanity_check_meminfo_mpu(void) {}
271 static void __init
mpu_setup(void) {}
272 #endif /* CONFIG_ARM_MPU */
274 void __init
arm_mm_memblock_reserve(void)
276 #ifndef CONFIG_CPU_V7M
278 * Register the exception vector page.
279 * some architectures which the DRAM is the exception vector to trap,
280 * alloc_page breaks with error, although it is not NULL, but "0."
282 memblock_reserve(CONFIG_VECTORS_BASE
, PAGE_SIZE
);
283 #else /* ifndef CONFIG_CPU_V7M */
285 * There is no dedicated vector page on V7-M. So nothing needs to be
291 void __init
sanity_check_meminfo(void)
294 sanity_check_meminfo_mpu();
295 end
= bank_phys_end(&meminfo
.bank
[meminfo
.nr_banks
- 1]);
296 high_memory
= __va(end
- 1) + 1;
300 * early_paging_init() recreates boot time page table setup, allowing machines
301 * to switch over to a high (>4G) address space on LPAE systems
303 void __init
early_paging_init(const struct machine_desc
*mdesc
,
304 struct proc_info_list
*procinfo
)
309 * paging_init() sets up the page tables, initialises the zone memory
310 * maps, and sets up the zero page, bad page and bad page tables.
312 void __init
paging_init(const struct machine_desc
*mdesc
)
314 early_trap_init((void *)CONFIG_VECTORS_BASE
);
320 * We don't need to do anything here for nommu machines.
322 void setup_mm_for_reboot(void)
326 void flush_dcache_page(struct page
*page
)
328 __cpuc_flush_dcache_area(page_address(page
), PAGE_SIZE
);
330 EXPORT_SYMBOL(flush_dcache_page
);
332 void flush_kernel_dcache_page(struct page
*page
)
334 __cpuc_flush_dcache_area(page_address(page
), PAGE_SIZE
);
336 EXPORT_SYMBOL(flush_kernel_dcache_page
);
338 void copy_to_user_page(struct vm_area_struct
*vma
, struct page
*page
,
339 unsigned long uaddr
, void *dst
, const void *src
,
342 memcpy(dst
, src
, len
);
343 if (vma
->vm_flags
& VM_EXEC
)
344 __cpuc_coherent_user_range(uaddr
, uaddr
+ len
);
347 void __iomem
*__arm_ioremap_pfn(unsigned long pfn
, unsigned long offset
,
348 size_t size
, unsigned int mtype
)
350 if (pfn
>= (0x100000000ULL
>> PAGE_SHIFT
))
352 return (void __iomem
*) (offset
+ (pfn
<< PAGE_SHIFT
));
354 EXPORT_SYMBOL(__arm_ioremap_pfn
);
356 void __iomem
*__arm_ioremap_pfn_caller(unsigned long pfn
, unsigned long offset
,
357 size_t size
, unsigned int mtype
, void *caller
)
359 return __arm_ioremap_pfn(pfn
, offset
, size
, mtype
);
362 void __iomem
*__arm_ioremap(phys_addr_t phys_addr
, size_t size
,
365 return (void __iomem
*)phys_addr
;
367 EXPORT_SYMBOL(__arm_ioremap
);
369 void __iomem
* (*arch_ioremap_caller
)(phys_addr_t
, size_t, unsigned int, void *);
371 void __iomem
*__arm_ioremap_caller(phys_addr_t phys_addr
, size_t size
,
372 unsigned int mtype
, void *caller
)
374 return __arm_ioremap(phys_addr
, size
, mtype
);
377 void (*arch_iounmap
)(volatile void __iomem
*);
379 void __arm_iounmap(volatile void __iomem
*addr
)
382 EXPORT_SYMBOL(__arm_iounmap
);