summaryrefslogtreecommitdiffstats
path: root/arch/arm/mm/mm-armv.c
blob: 4481fc32b437297dee9c31558d6cb2348dfa4aec (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
63
64
65
66
67
68
69
70
71
72
/*
 * arch/arm/mm/mm-armv.c
 *
 * Common routines for ARM v3 and v4 architectures.
 *
 * Copyright (C) 1998 Russell King
 *
 * Do not compile this file directly!
 */

#ifndef MAPPING
#error MAPPING not defined - do not compile this file individually
#endif

static const struct mapping {
	unsigned long virtual;
	unsigned long physical;
	unsigned long length;
	int domain:4,
	    prot_read:1,
	    prot_write:1;
} mapping[] __initdata = {
	MAPPING
};

#define SIZEOFMAP (sizeof(mapping) / sizeof(mapping[0]))

__initfunc(unsigned long setup_io_pagetables(unsigned long start_mem))
{
	const struct mapping *mp;
	int i;

	for (i = 0, mp = mapping; i < SIZEOFMAP; i++, mp++) {
		unsigned long virtual, physical, length;
		int prot;

		virtual = mp->virtual;
		physical = mp->physical;
		length = mp->length;
		prot = (mp->prot_read ? L_PTE_USER : 0) | (mp->prot_write ? L_PTE_WRITE : 0)
			| L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY;

		while ((virtual & 1048575 || physical & 1048575) && length >= PAGE_SIZE) {
			alloc_init_page(&start_mem, virtual, physical, mp->domain, prot);
			length -= PAGE_SIZE;
			virtual += PAGE_SIZE;
			physical += PAGE_SIZE;
		}

		prot = (mp->prot_read ? PMD_SECT_AP_READ : 0) |
		       (mp->prot_write ? PMD_SECT_AP_WRITE : 0);

		while (length >= 1048576) {
			alloc_init_section(&start_mem, virtual, physical, mp->domain, prot);
			length -= 1048576;
			virtual += 1048576;
			physical += 1048576;
		}

		prot = (mp->prot_read ? L_PTE_USER : 0) | (mp->prot_write ? L_PTE_WRITE : 0)
			| L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY;

		while (length >= PAGE_SIZE) {
			alloc_init_page(&start_mem, virtual, physical, mp->domain, prot);
			length -= PAGE_SIZE;
			virtual += PAGE_SIZE;
			physical += PAGE_SIZE;
		}
	}

	return start_mem;
}