nommu.c 5.87 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
2 3 4 5 6 7
/*
 *  linux/arch/arm/mm/nommu.c
 *
 * ARM uCLinux supporting functions.
 */
#include <linux/module.h>
8 9
#include <linux/mm.h>
#include <linux/pagemap.h>
10
#include <linux/io.h>
Russell King's avatar
Russell King committed
11
#include <linux/memblock.h>
12
#include <linux/kernel.h>
13

14
#include <asm/cacheflush.h>
15
#include <asm/cp15.h>
Russell King's avatar
Russell King committed
16
#include <asm/sections.h>
17
#include <asm/page.h>
18
#include <asm/setup.h>
19
#include <asm/traps.h>
Russell King's avatar
Russell King committed
20
#include <asm/mach/arch.h>
21 22
#include <asm/cputype.h>
#include <asm/mpu.h>
Russell King's avatar
Russell King committed
23
#include <asm/procinfo.h>
24

25 26
#include "mm.h"

27 28
unsigned long vectors_base;

29 30
#ifdef CONFIG_ARM_MPU
struct mpu_rgn_info mpu_rgn_info;
31
#endif
32

33 34
#ifdef CONFIG_CPU_CP15
#ifdef CONFIG_CPU_HIGH_VECTOR
35
unsigned long setup_vectors_base(void)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
{
	unsigned long reg = get_cr();

	set_cr(reg | CR_V);
	return 0xffff0000;
}
#else /* CONFIG_CPU_HIGH_VECTOR */
/* Write exception base address to VBAR */
static inline void set_vbar(unsigned long val)
{
	asm("mcr p15, 0, %0, c12, c0, 0" : : "r" (val) : "cc");
}

/*
 * Security extensions, bits[7:4], permitted values,
 * 0b0000 - not implemented, 0b0001/0b0010 - implemented
 */
static inline bool security_extensions_enabled(void)
{
55 56
	/* Check CPUID Identification Scheme before ID_PFR1 read */
	if ((read_cpuid_id() & 0x000f0000) == 0x000f0000)
57 58
		return cpuid_feature_extract(CPUID_EXT_PFR1, 4) ||
			cpuid_feature_extract(CPUID_EXT_PFR1, 20);
59
	return 0;
60 61
}

62
unsigned long setup_vectors_base(void)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
{
	unsigned long base = 0, reg = get_cr();

	set_cr(reg & ~CR_V);
	if (security_extensions_enabled()) {
		if (IS_ENABLED(CONFIG_REMAP_VECTORS_TO_RAM))
			base = CONFIG_DRAM_BASE;
		set_vbar(base);
	} else if (IS_ENABLED(CONFIG_REMAP_VECTORS_TO_RAM)) {
		if (CONFIG_DRAM_BASE != 0)
			pr_err("Security extensions not enabled, vectors cannot be remapped to RAM, vectors base will be 0x00000000\n");
	}

	return base;
}
#endif /* CONFIG_CPU_HIGH_VECTOR */
#endif /* CONFIG_CPU_CP15 */

Russell King's avatar
Russell King committed
81
void __init arm_mm_memblock_reserve(void)
82
{
83
#ifndef CONFIG_CPU_V7M
84
	vectors_base = IS_ENABLED(CONFIG_CPU_CP15) ? setup_vectors_base() : 0;
85 86 87 88 89
	/*
	 * Register the exception vector page.
	 * some architectures which the DRAM is the exception vector to trap,
	 * alloc_page breaks with error, although it is not NULL, but "0."
	 */
90
	memblock_reserve(vectors_base, 2 * PAGE_SIZE);
91 92 93 94 95 96
#else /* ifndef CONFIG_CPU_V7M */
	/*
	 * There is no dedicated vector page on V7-M. So nothing needs to be
	 * reserved here.
	 */
#endif
97 98 99 100 101
	/*
	 * In any case, always ensure address 0 is never used as many things
	 * get very confused if 0 is returned as a legitimate address.
	 */
	memblock_reserve(0, 1);
102 103
}

104 105 106 107 108 109 110 111
static void __init adjust_lowmem_bounds_mpu(void)
{
	unsigned long pmsa = read_cpuid_ext(CPUID_EXT_MMFR0) & MMFR0_PMSA;

	switch (pmsa) {
	case MMFR0_PMSAv7:
		pmsav7_adjust_lowmem_bounds();
		break;
112 113 114
	case MMFR0_PMSAv8:
		pmsav8_adjust_lowmem_bounds();
		break;
115 116 117 118 119 120 121 122 123 124 125 126 127
	default:
		break;
	}
}

static void __init mpu_setup(void)
{
	unsigned long pmsa = read_cpuid_ext(CPUID_EXT_MMFR0) & MMFR0_PMSA;

	switch (pmsa) {
	case MMFR0_PMSAv7:
		pmsav7_setup();
		break;
128 129 130
	case MMFR0_PMSAv8:
		pmsav8_setup();
		break;
131 132 133 134 135
	default:
		break;
	}
}

136
void __init adjust_lowmem_bounds(void)
137
{
138
	phys_addr_t end;
139
	adjust_lowmem_bounds_mpu();
Laura Abbott's avatar
Laura Abbott committed
140
	end = memblock_end_of_DRAM();
141
	high_memory = __va(end - 1) + 1;
142
	memblock_set_current_limit(end);
143 144
}

145 146 147 148
/*
 * paging_init() sets up the page tables, initialises the zone memory
 * maps, and sets up the zero page, bad page and bad page tables.
 */
149
void __init paging_init(const struct machine_desc *mdesc)
150
{
151
	early_trap_init((void *)vectors_base);
152
	mpu_setup();
153
	bootmem_init();
154 155
}

156 157 158
/*
 * We don't need to do anything here for nommu machines.
 */
159
void setup_mm_for_reboot(void)
160 161 162
{
}

163 164
void flush_dcache_page(struct page *page)
{
165
	__cpuc_flush_dcache_area(page_address(page), PAGE_SIZE);
166
}
167
EXPORT_SYMBOL(flush_dcache_page);
168

169 170 171 172 173 174
void flush_kernel_dcache_page(struct page *page)
{
	__cpuc_flush_dcache_area(page_address(page), PAGE_SIZE);
}
EXPORT_SYMBOL(flush_kernel_dcache_page);

175 176 177 178 179 180 181 182 183
void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
		       unsigned long uaddr, void *dst, const void *src,
		       unsigned long len)
{
	memcpy(dst, src, len);
	if (vma->vm_flags & VM_EXEC)
		__cpuc_coherent_user_range(uaddr, uaddr + len);
}

184 185
void __iomem *__arm_ioremap_pfn(unsigned long pfn, unsigned long offset,
				size_t size, unsigned int mtype)
186 187 188 189 190
{
	if (pfn >= (0x100000000ULL >> PAGE_SHIFT))
		return NULL;
	return (void __iomem *) (offset + (pfn << PAGE_SHIFT));
}
191
EXPORT_SYMBOL(__arm_ioremap_pfn);
192

193 194
void __iomem *__arm_ioremap_caller(phys_addr_t phys_addr, size_t size,
				   unsigned int mtype, void *caller)
195
{
196
	return (void __iomem *)phys_addr;
197 198
}

199 200 201
void __iomem * (*arch_ioremap_caller)(phys_addr_t, size_t, unsigned int, void *);

void __iomem *ioremap(resource_size_t res_cookie, size_t size)
202
{
203 204
	return __arm_ioremap_caller(res_cookie, size, MT_DEVICE,
				    __builtin_return_address(0));
205
}
206
EXPORT_SYMBOL(ioremap);
207

208
void __iomem *ioremap_cache(resource_size_t res_cookie, size_t size)
209 210 211
	__alias(ioremap_cached);

void __iomem *ioremap_cached(resource_size_t res_cookie, size_t size)
212 213 214 215 216
{
	return __arm_ioremap_caller(res_cookie, size, MT_DEVICE_CACHED,
				    __builtin_return_address(0));
}
EXPORT_SYMBOL(ioremap_cache);
217
EXPORT_SYMBOL(ioremap_cached);
218

219 220 221 222 223 224 225
void __iomem *ioremap_wc(resource_size_t res_cookie, size_t size)
{
	return __arm_ioremap_caller(res_cookie, size, MT_DEVICE_WC,
				    __builtin_return_address(0));
}
EXPORT_SYMBOL(ioremap_wc);

226 227 228 229 230 231 232 233 234 235 236 237
#ifdef CONFIG_PCI

#include <asm/mach/map.h>

void __iomem *pci_remap_cfgspace(resource_size_t res_cookie, size_t size)
{
	return arch_ioremap_caller(res_cookie, size, MT_UNCACHED,
				   __builtin_return_address(0));
}
EXPORT_SYMBOL_GPL(pci_remap_cfgspace);
#endif

238 239 240 241 242
void *arch_memremap_wb(phys_addr_t phys_addr, size_t size)
{
	return (void *)phys_addr;
}

243
void __iounmap(volatile void __iomem *addr)
244 245
{
}
246
EXPORT_SYMBOL(__iounmap);
247

248 249
void (*arch_iounmap)(volatile void __iomem *);

250
void iounmap(volatile void __iomem *addr)
251 252
{
}
253
EXPORT_SYMBOL(iounmap);