diff options
author | Haavard Skinnemoen <hskinnemoen@atmel.com> | 2006-09-26 02:32:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-09-26 11:48:54 -0400 |
commit | 5f97f7f9400de47ae837170bb274e90ad3934386 (patch) | |
tree | 514451e6dc6b46253293a00035d375e77b1c65ed /arch/avr32/mm/ioremap.c | |
parent | 53e62d3aaa60590d4a69b4e07c29f448b5151047 (diff) |
[PATCH] avr32 architecture
This adds support for the Atmel AVR32 architecture as well as the AT32AP7000
CPU and the AT32STK1000 development board.
AVR32 is a new high-performance 32-bit RISC microprocessor core, designed for
cost-sensitive embedded applications, with particular emphasis on low power
consumption and high code density. The AVR32 architecture is not binary
compatible with earlier 8-bit AVR architectures.
The AVR32 architecture, including the instruction set, is described by the
AVR32 Architecture Manual, available from
http://www.atmel.com/dyn/resources/prod_documents/doc32000.pdf
The Atmel AT32AP7000 is the first CPU implementing the AVR32 architecture. It
features a 7-stage pipeline, 16KB instruction and data caches and a full
Memory Management Unit. It also comes with a large set of integrated
peripherals, many of which are shared with the AT91 ARM-based controllers from
Atmel.
Full data sheet is available from
http://www.atmel.com/dyn/resources/prod_documents/doc32003.pdf
while the CPU core implementation including caches and MMU is documented by
the AVR32 AP Technical Reference, available from
http://www.atmel.com/dyn/resources/prod_documents/doc32001.pdf
Information about the AT32STK1000 development board can be found at
http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3918
including a BSP CD image with an earlier version of this patch, development
tools (binaries and source/patches) and a root filesystem image suitable for
booting from SD card.
Alternatively, there's a preliminary "getting started" guide available at
http://avr32linux.org/twiki/bin/view/Main/GettingStarted which provides links
to the sources and patches you will need in order to set up a cross-compiling
environment for avr32-linux.
This patch, as well as the other patches included with the BSP and the
toolchain patches, is actively supported by Atmel Corporation.
[dmccr@us.ibm.com: Fix more pxx_page macro locations]
[bunk@stusta.de: fix `make defconfig']
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Dave McCracken <dmccr@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/avr32/mm/ioremap.c')
-rw-r--r-- | arch/avr32/mm/ioremap.c | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/arch/avr32/mm/ioremap.c b/arch/avr32/mm/ioremap.c new file mode 100644 index 000000000000..536021877df6 --- /dev/null +++ b/arch/avr32/mm/ioremap.c | |||
@@ -0,0 +1,197 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004-2006 Atmel Corporation | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | #include <linux/vmalloc.h> | ||
9 | #include <linux/module.h> | ||
10 | |||
11 | #include <asm/io.h> | ||
12 | #include <asm/pgtable.h> | ||
13 | #include <asm/cacheflush.h> | ||
14 | #include <asm/tlbflush.h> | ||
15 | #include <asm/addrspace.h> | ||
16 | |||
17 | static inline int remap_area_pte(pte_t *pte, unsigned long address, | ||
18 | unsigned long end, unsigned long phys_addr, | ||
19 | pgprot_t prot) | ||
20 | { | ||
21 | unsigned long pfn; | ||
22 | |||
23 | pfn = phys_addr >> PAGE_SHIFT; | ||
24 | do { | ||
25 | WARN_ON(!pte_none(*pte)); | ||
26 | |||
27 | set_pte(pte, pfn_pte(pfn, prot)); | ||
28 | address += PAGE_SIZE; | ||
29 | pfn++; | ||
30 | pte++; | ||
31 | } while (address && (address < end)); | ||
32 | |||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | static inline int remap_area_pmd(pmd_t *pmd, unsigned long address, | ||
37 | unsigned long end, unsigned long phys_addr, | ||
38 | pgprot_t prot) | ||
39 | { | ||
40 | unsigned long next; | ||
41 | |||
42 | phys_addr -= address; | ||
43 | |||
44 | do { | ||
45 | pte_t *pte = pte_alloc_kernel(pmd, address); | ||
46 | if (!pte) | ||
47 | return -ENOMEM; | ||
48 | |||
49 | next = (address + PMD_SIZE) & PMD_MASK; | ||
50 | if (remap_area_pte(pte, address, next, | ||
51 | address + phys_addr, prot)) | ||
52 | return -ENOMEM; | ||
53 | |||
54 | address = next; | ||
55 | pmd++; | ||
56 | } while (address && (address < end)); | ||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | static int remap_area_pud(pud_t *pud, unsigned long address, | ||
61 | unsigned long end, unsigned long phys_addr, | ||
62 | pgprot_t prot) | ||
63 | { | ||
64 | unsigned long next; | ||
65 | |||
66 | phys_addr -= address; | ||
67 | |||
68 | do { | ||
69 | pmd_t *pmd = pmd_alloc(&init_mm, pud, address); | ||
70 | if (!pmd) | ||
71 | return -ENOMEM; | ||
72 | next = (address + PUD_SIZE) & PUD_MASK; | ||
73 | if (remap_area_pmd(pmd, address, next, | ||
74 | phys_addr + address, prot)) | ||
75 | return -ENOMEM; | ||
76 | |||
77 | address = next; | ||
78 | pud++; | ||
79 | } while (address && address < end); | ||
80 | |||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | static int remap_area_pages(unsigned long address, unsigned long phys_addr, | ||
85 | size_t size, pgprot_t prot) | ||
86 | { | ||
87 | unsigned long end = address + size; | ||
88 | unsigned long next; | ||
89 | pgd_t *pgd; | ||
90 | int err = 0; | ||
91 | |||
92 | phys_addr -= address; | ||
93 | |||
94 | pgd = pgd_offset_k(address); | ||
95 | flush_cache_all(); | ||
96 | BUG_ON(address >= end); | ||
97 | |||
98 | spin_lock(&init_mm.page_table_lock); | ||
99 | do { | ||
100 | pud_t *pud = pud_alloc(&init_mm, pgd, address); | ||
101 | |||
102 | err = -ENOMEM; | ||
103 | if (!pud) | ||
104 | break; | ||
105 | |||
106 | next = (address + PGDIR_SIZE) & PGDIR_MASK; | ||
107 | if (next < address || next > end) | ||
108 | next = end; | ||
109 | err = remap_area_pud(pud, address, next, | ||
110 | phys_addr + address, prot); | ||
111 | if (err) | ||
112 | break; | ||
113 | |||
114 | address = next; | ||
115 | pgd++; | ||
116 | } while (address && (address < end)); | ||
117 | |||
118 | spin_unlock(&init_mm.page_table_lock); | ||
119 | flush_tlb_all(); | ||
120 | return err; | ||
121 | } | ||
122 | |||
123 | /* | ||
124 | * Re-map an arbitrary physical address space into the kernel virtual | ||
125 | * address space. Needed when the kernel wants to access physical | ||
126 | * memory directly. | ||
127 | */ | ||
128 | void __iomem *__ioremap(unsigned long phys_addr, size_t size, | ||
129 | unsigned long flags) | ||
130 | { | ||
131 | void *addr; | ||
132 | struct vm_struct *area; | ||
133 | unsigned long offset, last_addr; | ||
134 | pgprot_t prot; | ||
135 | |||
136 | /* | ||
137 | * Check if we can simply use the P4 segment. This area is | ||
138 | * uncacheable, so if caching/buffering is requested, we can't | ||
139 | * use it. | ||
140 | */ | ||
141 | if ((phys_addr >= P4SEG) && (flags == 0)) | ||
142 | return (void __iomem *)phys_addr; | ||
143 | |||
144 | /* Don't allow wraparound or zero size */ | ||
145 | last_addr = phys_addr + size - 1; | ||
146 | if (!size || last_addr < phys_addr) | ||
147 | return NULL; | ||
148 | |||
149 | /* | ||
150 | * XXX: When mapping regular RAM, we'd better make damn sure | ||
151 | * it's never used for anything else. But this is really the | ||
152 | * caller's responsibility... | ||
153 | */ | ||
154 | if (PHYSADDR(P2SEGADDR(phys_addr)) == phys_addr) | ||
155 | return (void __iomem *)P2SEGADDR(phys_addr); | ||
156 | |||
157 | /* Mappings have to be page-aligned */ | ||
158 | offset = phys_addr & ~PAGE_MASK; | ||
159 | phys_addr &= PAGE_MASK; | ||
160 | size = PAGE_ALIGN(last_addr + 1) - phys_addr; | ||
161 | |||
162 | prot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | ||
163 | | _PAGE_ACCESSED | _PAGE_TYPE_SMALL | flags); | ||
164 | |||
165 | /* | ||
166 | * Ok, go for it.. | ||
167 | */ | ||
168 | area = get_vm_area(size, VM_IOREMAP); | ||
169 | if (!area) | ||
170 | return NULL; | ||
171 | area->phys_addr = phys_addr; | ||
172 | addr = area->addr; | ||
173 | if (remap_area_pages((unsigned long)addr, phys_addr, size, prot)) { | ||
174 | vunmap(addr); | ||
175 | return NULL; | ||
176 | } | ||
177 | |||
178 | return (void __iomem *)(offset + (char *)addr); | ||
179 | } | ||
180 | EXPORT_SYMBOL(__ioremap); | ||
181 | |||
182 | void __iounmap(void __iomem *addr) | ||
183 | { | ||
184 | struct vm_struct *p; | ||
185 | |||
186 | if ((unsigned long)addr >= P4SEG) | ||
187 | return; | ||
188 | |||
189 | p = remove_vm_area((void *)(PAGE_MASK & (unsigned long __force)addr)); | ||
190 | if (unlikely(!p)) { | ||
191 | printk (KERN_ERR "iounmap: bad address %p\n", addr); | ||
192 | return; | ||
193 | } | ||
194 | |||
195 | kfree (p); | ||
196 | } | ||
197 | EXPORT_SYMBOL(__iounmap); | ||