[MIPS] Use common definitions from asm-generic/signal.h
[linux-2.6/linux-mips/linux-dm7025.git] / arch / powerpc / mm / pgtable_64.c
blobb1da0316549601745d6c21e49f6fd78098e766e0
1 /*
2 * This file contains ioremap and related functions for 64-bit machines.
4 * Derived from arch/ppc64/mm/init.c
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * Modifications by Paul Mackerras (PowerMac) (paulus@samba.org)
8 * and Cort Dougan (PReP) (cort@cs.nmt.edu)
9 * Copyright (C) 1996 Paul Mackerras
10 * Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
12 * Derived from "arch/i386/mm/init.c"
13 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
15 * Dave Engebretsen <engebret@us.ibm.com>
16 * Rework for PPC64 port.
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
25 #include <linux/signal.h>
26 #include <linux/sched.h>
27 #include <linux/kernel.h>
28 #include <linux/errno.h>
29 #include <linux/string.h>
30 #include <linux/types.h>
31 #include <linux/mman.h>
32 #include <linux/mm.h>
33 #include <linux/swap.h>
34 #include <linux/stddef.h>
35 #include <linux/vmalloc.h>
36 #include <linux/init.h>
37 #include <linux/delay.h>
38 #include <linux/bootmem.h>
39 #include <linux/highmem.h>
40 #include <linux/idr.h>
41 #include <linux/nodemask.h>
42 #include <linux/module.h>
44 #include <asm/pgalloc.h>
45 #include <asm/page.h>
46 #include <asm/prom.h>
47 #include <asm/lmb.h>
48 #include <asm/rtas.h>
49 #include <asm/io.h>
50 #include <asm/mmu_context.h>
51 #include <asm/pgtable.h>
52 #include <asm/mmu.h>
53 #include <asm/uaccess.h>
54 #include <asm/smp.h>
55 #include <asm/machdep.h>
56 #include <asm/tlb.h>
57 #include <asm/eeh.h>
58 #include <asm/processor.h>
59 #include <asm/mmzone.h>
60 #include <asm/cputable.h>
61 #include <asm/sections.h>
62 #include <asm/system.h>
63 #include <asm/iommu.h>
64 #include <asm/abs_addr.h>
65 #include <asm/vdso.h>
67 #include "mmu_decl.h"
69 unsigned long ioremap_bot = IMALLOC_BASE;
70 static unsigned long phbs_io_bot = PHBS_IO_BASE;
72 #ifdef CONFIG_PPC_ISERIES
74 void __iomem *ioremap(unsigned long addr, unsigned long size)
76 return (void __iomem *)addr;
79 extern void __iomem *__ioremap(unsigned long addr, unsigned long size,
80 unsigned long flags)
82 return (void __iomem *)addr;
85 void iounmap(volatile void __iomem *addr)
87 return;
90 #else
93 * map_io_page currently only called by __ioremap
94 * map_io_page adds an entry to the ioremap page table
95 * and adds an entry to the HPT, possibly bolting it
97 static int map_io_page(unsigned long ea, unsigned long pa, int flags)
99 pgd_t *pgdp;
100 pud_t *pudp;
101 pmd_t *pmdp;
102 pte_t *ptep;
104 if (mem_init_done) {
105 pgdp = pgd_offset_k(ea);
106 pudp = pud_alloc(&init_mm, pgdp, ea);
107 if (!pudp)
108 return -ENOMEM;
109 pmdp = pmd_alloc(&init_mm, pudp, ea);
110 if (!pmdp)
111 return -ENOMEM;
112 ptep = pte_alloc_kernel(pmdp, ea);
113 if (!ptep)
114 return -ENOMEM;
115 set_pte_at(&init_mm, ea, ptep, pfn_pte(pa >> PAGE_SHIFT,
116 __pgprot(flags)));
117 } else {
119 * If the mm subsystem is not fully up, we cannot create a
120 * linux page table entry for this mapping. Simply bolt an
121 * entry in the hardware page table.
124 if (htab_bolt_mapping(ea, ea + PAGE_SIZE, pa, flags,
125 mmu_virtual_psize)) {
126 printk(KERN_ERR "Failed to do bolted mapping IO "
127 "memory at %016lx !\n", pa);
128 return -ENOMEM;
131 return 0;
135 static void __iomem * __ioremap_com(unsigned long addr, unsigned long pa,
136 unsigned long ea, unsigned long size,
137 unsigned long flags)
139 unsigned long i;
141 if ((flags & _PAGE_PRESENT) == 0)
142 flags |= pgprot_val(PAGE_KERNEL);
144 for (i = 0; i < size; i += PAGE_SIZE)
145 if (map_io_page(ea+i, pa+i, flags))
146 return NULL;
148 return (void __iomem *) (ea + (addr & ~PAGE_MASK));
152 void __iomem *
153 ioremap(unsigned long addr, unsigned long size)
155 return __ioremap(addr, size, _PAGE_NO_CACHE | _PAGE_GUARDED);
158 void __iomem * __ioremap(unsigned long addr, unsigned long size,
159 unsigned long flags)
161 unsigned long pa, ea;
162 void __iomem *ret;
165 * Choose an address to map it to.
166 * Once the imalloc system is running, we use it.
167 * Before that, we map using addresses going
168 * up from ioremap_bot. imalloc will use
169 * the addresses from ioremap_bot through
170 * IMALLOC_END
173 pa = addr & PAGE_MASK;
174 size = PAGE_ALIGN(addr + size) - pa;
176 if ((size == 0) || (pa == 0))
177 return NULL;
179 if (mem_init_done) {
180 struct vm_struct *area;
181 area = im_get_free_area(size);
182 if (area == NULL)
183 return NULL;
184 ea = (unsigned long)(area->addr);
185 ret = __ioremap_com(addr, pa, ea, size, flags);
186 if (!ret)
187 im_free(area->addr);
188 } else {
189 ea = ioremap_bot;
190 ret = __ioremap_com(addr, pa, ea, size, flags);
191 if (ret)
192 ioremap_bot += size;
194 return ret;
197 #define IS_PAGE_ALIGNED(_val) ((_val) == ((_val) & PAGE_MASK))
199 int __ioremap_explicit(unsigned long pa, unsigned long ea,
200 unsigned long size, unsigned long flags)
202 struct vm_struct *area;
203 void __iomem *ret;
205 /* For now, require page-aligned values for pa, ea, and size */
206 if (!IS_PAGE_ALIGNED(pa) || !IS_PAGE_ALIGNED(ea) ||
207 !IS_PAGE_ALIGNED(size)) {
208 printk(KERN_ERR "unaligned value in %s\n", __FUNCTION__);
209 return 1;
212 if (!mem_init_done) {
213 /* Two things to consider in this case:
214 * 1) No records will be kept (imalloc, etc) that the region
215 * has been remapped
216 * 2) It won't be easy to iounmap() the region later (because
217 * of 1)
220 } else {
221 area = im_get_area(ea, size,
222 IM_REGION_UNUSED|IM_REGION_SUBSET|IM_REGION_EXISTS);
223 if (area == NULL) {
224 /* Expected when PHB-dlpar is in play */
225 return 1;
227 if (ea != (unsigned long) area->addr) {
228 printk(KERN_ERR "unexpected addr return from "
229 "im_get_area\n");
230 return 1;
234 ret = __ioremap_com(pa, pa, ea, size, flags);
235 if (ret == NULL) {
236 printk(KERN_ERR "ioremap_explicit() allocation failure !\n");
237 return 1;
239 if (ret != (void *) ea) {
240 printk(KERN_ERR "__ioremap_com() returned unexpected addr\n");
241 return 1;
244 return 0;
248 * Unmap an IO region and remove it from imalloc'd list.
249 * Access to IO memory should be serialized by driver.
250 * This code is modeled after vmalloc code - unmap_vm_area()
252 * XXX what about calls before mem_init_done (ie python_countermeasures())
254 void iounmap(volatile void __iomem *token)
256 void *addr;
258 if (!mem_init_done)
259 return;
261 addr = (void *) ((unsigned long __force) token & PAGE_MASK);
263 im_free(addr);
266 static int iounmap_subset_regions(unsigned long addr, unsigned long size)
268 struct vm_struct *area;
270 /* Check whether subsets of this region exist */
271 area = im_get_area(addr, size, IM_REGION_SUPERSET);
272 if (area == NULL)
273 return 1;
275 while (area) {
276 iounmap((void __iomem *) area->addr);
277 area = im_get_area(addr, size,
278 IM_REGION_SUPERSET);
281 return 0;
284 int iounmap_explicit(volatile void __iomem *start, unsigned long size)
286 struct vm_struct *area;
287 unsigned long addr;
288 int rc;
290 addr = (unsigned long __force) start & PAGE_MASK;
292 /* Verify that the region either exists or is a subset of an existing
293 * region. In the latter case, split the parent region to create
294 * the exact region
296 area = im_get_area(addr, size,
297 IM_REGION_EXISTS | IM_REGION_SUBSET);
298 if (area == NULL) {
299 /* Determine whether subset regions exist. If so, unmap */
300 rc = iounmap_subset_regions(addr, size);
301 if (rc) {
302 printk(KERN_ERR
303 "%s() cannot unmap nonexistent range 0x%lx\n",
304 __FUNCTION__, addr);
305 return 1;
307 } else {
308 iounmap((void __iomem *) area->addr);
311 * FIXME! This can't be right:
312 iounmap(area->addr);
313 * Maybe it should be "iounmap(area);"
315 return 0;
318 #endif
320 EXPORT_SYMBOL(ioremap);
321 EXPORT_SYMBOL(__ioremap);
322 EXPORT_SYMBOL(iounmap);
324 void __iomem * reserve_phb_iospace(unsigned long size)
326 void __iomem *virt_addr;
328 if (phbs_io_bot >= IMALLOC_BASE)
329 panic("reserve_phb_iospace(): phb io space overflow\n");
331 virt_addr = (void __iomem *) phbs_io_bot;
332 phbs_io_bot += size;
334 return virt_addr;