2 * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
6 * The code contained herein is licensed under the GNU General Public
7 * License. You may obtain a copy of the GNU General Public License
8 * Version 2 or later at the following locations:
10 * http://www.opensource.org/licenses/gpl-license.html
11 * http://www.gnu.org/copyleft/gpl.html
14 #ifndef __ARM_ARCH_MMU_H
15 #define __ARM_ARCH_MMU_H
17 #include <linux/types.h>
20 * Translation Table Base Bit Masks
22 #define ARM_TRANSLATION_TABLE_MASK 0xFFFFC000
25 * Domain Access Control Bit Masks
27 #define ARM_ACCESS_TYPE_NO_ACCESS(domain_num) (0x0 << (domain_num)*2)
28 #define ARM_ACCESS_TYPE_CLIENT(domain_num) (0x1 << (domain_num)*2)
29 #define ARM_ACCESS_TYPE_MANAGER(domain_num) (0x3 << (domain_num)*2)
31 struct ARM_MMU_FIRST_LEVEL_FAULT {
36 #define ARM_MMU_FIRST_LEVEL_FAULT_ID 0x0
38 struct ARM_MMU_FIRST_LEVEL_PAGE_TABLE {
41 unsigned int domain:4;
43 unsigned int base_address:23;
46 #define ARM_MMU_FIRST_LEVEL_PAGE_TABLE_ID 0x1
48 struct ARM_MMU_FIRST_LEVEL_SECTION {
53 unsigned int domain:4;
57 unsigned int base_address:12;
60 #define ARM_MMU_FIRST_LEVEL_SECTION_ID 0x2
62 struct ARM_MMU_FIRST_LEVEL_RESERVED {
67 #define ARM_MMU_FIRST_LEVEL_RESERVED_ID 0x3
69 #define ARM_MMU_FIRST_LEVEL_DESCRIPTOR_ADDRESS(ttb_base, table_index) \
70 (unsigned long *)((unsigned long)(ttb_base) + ((table_index) << 2))
72 #define ARM_FIRST_LEVEL_PAGE_TABLE_SIZE 0x4000
74 #define ARM_MMU_SECTION(ttb_base, actual_base, virtual_base, \
75 cacheable, bufferable, perm) \
77 register union ARM_MMU_FIRST_LEVEL_DESCRIPTOR desc; \
79 desc.section.id = ARM_MMU_FIRST_LEVEL_SECTION_ID; \
80 desc.section.domain = 0; \
81 desc.section.c = (cacheable); \
82 desc.section.b = (bufferable); \
83 desc.section.ap = (perm); \
84 desc.section.base_address = (actual_base); \
85 *ARM_MMU_FIRST_LEVEL_DESCRIPTOR_ADDRESS(ttb_base, (virtual_base)) \
89 #define X_ARM_MMU_SECTION(abase, vbase, size, cache, buff, access) \
91 int i; int j = abase; int k = vbase; \
92 for (i = size; i > 0 ; i--, j++, k++) \
93 ARM_MMU_SECTION(ttb_base, j, k, cache, buff, access); \
96 union ARM_MMU_FIRST_LEVEL_DESCRIPTOR {
98 struct ARM_MMU_FIRST_LEVEL_FAULT fault;
99 struct ARM_MMU_FIRST_LEVEL_PAGE_TABLE page_table;
100 struct ARM_MMU_FIRST_LEVEL_SECTION section;
101 struct ARM_MMU_FIRST_LEVEL_RESERVED reserved;
104 #define ARM_UNCACHEABLE 0
105 #define ARM_CACHEABLE 1
106 #define ARM_UNBUFFERABLE 0
107 #define ARM_BUFFERABLE 1
109 #define ARM_ACCESS_PERM_NONE_NONE 0
110 #define ARM_ACCESS_PERM_RO_NONE 0
111 #define ARM_ACCESS_PERM_RO_RO 0
112 #define ARM_ACCESS_PERM_RW_NONE 1
113 #define ARM_ACCESS_PERM_RW_RO 2
114 #define ARM_ACCESS_PERM_RW_RW 3
117 * Initialization for the Domain Access Control Register
119 #define ARM_ACCESS_DACR_DEFAULT ( \
120 ARM_ACCESS_TYPE_MANAGER(0) | \
121 ARM_ACCESS_TYPE_NO_ACCESS(1) | \
122 ARM_ACCESS_TYPE_NO_ACCESS(2) | \
123 ARM_ACCESS_TYPE_NO_ACCESS(3) | \
124 ARM_ACCESS_TYPE_NO_ACCESS(4) | \
125 ARM_ACCESS_TYPE_NO_ACCESS(5) | \
126 ARM_ACCESS_TYPE_NO_ACCESS(6) | \
127 ARM_ACCESS_TYPE_NO_ACCESS(7) | \
128 ARM_ACCESS_TYPE_NO_ACCESS(8) | \
129 ARM_ACCESS_TYPE_NO_ACCESS(9) | \
130 ARM_ACCESS_TYPE_NO_ACCESS(10) | \
131 ARM_ACCESS_TYPE_NO_ACCESS(11) | \
132 ARM_ACCESS_TYPE_NO_ACCESS(12) | \
133 ARM_ACCESS_TYPE_NO_ACCESS(13) | \
134 ARM_ACCESS_TYPE_NO_ACCESS(14) | \
135 ARM_ACCESS_TYPE_NO_ACCESS(15))
138 * Translate the virtual address of ram space to physical address
139 * It is dependent on the implementation of mmu_init
141 inline void *iomem_to_phys(unsigned long virt)
143 if (virt >= 0xB0000000)
144 return (void *)((virt - 0xB0000000) + PHYS_SDRAM_1);
150 * remap the physical address of ram space to uncacheable virtual address space
151 * It is dependent on the implementation of hal_mmu_init
153 void *__ioremap(unsigned long offset, size_t size, unsigned long flags)
156 if (offset >= PHYS_SDRAM_1 &&
157 offset < (PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE))
158 return (void *)(offset - PHYS_SDRAM_1) + 0xB0000000;
162 return (void *)offset;
166 * Remap the physical address of ram space to uncacheable virtual address space
167 * It is dependent on the implementation of hal_mmu_init
169 void __iounmap(void *addr)