summaryrefslogtreecommitdiffstats
path: root/arch/arm/cpu/mmu-early.c
blob: 7c30526b94991b3953e30109a91aa28cd4605036 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <common.h>
#include <asm/mmu.h>
#include <errno.h>
#include <linux/sizes.h>
#include <asm/memory.h>
#include <asm/system.h>
#include <asm/cache.h>
#include <asm-generic/sections.h>

#include "mmu.h"

static uint32_t *ttb;

static inline void map_region(unsigned long start, unsigned long size,
			      uint64_t flags)

{
	start = ALIGN_DOWN(start, SZ_1M);
	size  = ALIGN(size, SZ_1M);

	create_sections(ttb, start, start + size - 1, flags);
}

void mmu_early_enable(unsigned long membase, unsigned long memsize,
		      unsigned long _ttb)
{
	ttb = (uint32_t *)_ttb;

	arm_set_cache_functions();

	set_ttbr(ttb);

	/* For the XN bit to take effect, we can't be using DOMAIN_MANAGER. */
	if (cpu_architecture() >= CPU_ARCH_ARMv7)
		set_domain(DOMAIN_CLIENT);
	else
		set_domain(DOMAIN_MANAGER);

	/*
	 * This marks the whole address space as uncachable as well as
	 * unexecutable if possible
	 */
	create_flat_mapping(ttb);

	/*
	 * There can be SoCs that have a section shared between device memory
	 * and the on-chip RAM hosting the PBL. Thus mark this section
	 * uncachable, but executable.
	 * On such SoCs, executing from OCRAM could cause the instruction
	 * prefetcher to speculatively access that device memory, triggering
	 * potential errant behavior.
	 *
	 * If your SoC has such a memory layout, you should rewrite the code
	 * here to map the OCRAM page-wise.
	 */
	map_region((unsigned long)_stext, _etext - _stext, PMD_SECT_DEF_UNCACHED);

	/* maps main memory as cachable */
	map_region(membase, memsize, PMD_SECT_DEF_CACHED);

	__mmu_cache_on();
}