powerpc: Estimate G5 cpufreq transition latency
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / powerpc / mm / pgtable_64.c
CommitLineData
14cf11af
PM
1/*
2 * This file contains ioremap and related functions for 64-bit machines.
3 *
4 * Derived from arch/ppc64/mm/init.c
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 *
7 * Modifications by Paul Mackerras (PowerMac) (paulus@samba.org)
8 * and Cort Dougan (PReP) (cort@cs.nmt.edu)
9 * Copyright (C) 1996 Paul Mackerras
14cf11af
PM
10 *
11 * Derived from "arch/i386/mm/init.c"
12 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
13 *
14 * Dave Engebretsen <engebret@us.ibm.com>
15 * Rework for PPC64 port.
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
21 *
22 */
23
14cf11af
PM
24#include <linux/signal.h>
25#include <linux/sched.h>
26#include <linux/kernel.h>
27#include <linux/errno.h>
28#include <linux/string.h>
29#include <linux/types.h>
30#include <linux/mman.h>
31#include <linux/mm.h>
32#include <linux/swap.h>
33#include <linux/stddef.h>
34#include <linux/vmalloc.h>
35#include <linux/init.h>
14cf11af
PM
36
37#include <asm/pgalloc.h>
38#include <asm/page.h>
39#include <asm/prom.h>
14cf11af
PM
40#include <asm/io.h>
41#include <asm/mmu_context.h>
42#include <asm/pgtable.h>
43#include <asm/mmu.h>
14cf11af
PM
44#include <asm/smp.h>
45#include <asm/machdep.h>
46#include <asm/tlb.h>
14cf11af 47#include <asm/processor.h>
14cf11af 48#include <asm/cputable.h>
14cf11af
PM
49#include <asm/sections.h>
50#include <asm/system.h>
14cf11af 51#include <asm/abs_addr.h>
5e203d68 52#include <asm/firmware.h>
800fc3ee
DG
53
54#include "mmu_decl.h"
14cf11af 55
3d5134ee 56unsigned long ioremap_bot = IOREMAP_BASE;
14cf11af 57
14cf11af
PM
58/*
59 * map_io_page currently only called by __ioremap
60 * map_io_page adds an entry to the ioremap page table
61 * and adds an entry to the HPT, possibly bolting it
62 */
63static int map_io_page(unsigned long ea, unsigned long pa, int flags)
64{
65 pgd_t *pgdp;
66 pud_t *pudp;
67 pmd_t *pmdp;
68 pte_t *ptep;
14cf11af
PM
69
70 if (mem_init_done) {
14cf11af
PM
71 pgdp = pgd_offset_k(ea);
72 pudp = pud_alloc(&init_mm, pgdp, ea);
73 if (!pudp)
74 return -ENOMEM;
75 pmdp = pmd_alloc(&init_mm, pudp, ea);
76 if (!pmdp)
77 return -ENOMEM;
23fd0775 78 ptep = pte_alloc_kernel(pmdp, ea);
14cf11af
PM
79 if (!ptep)
80 return -ENOMEM;
81 set_pte_at(&init_mm, ea, ptep, pfn_pte(pa >> PAGE_SHIFT,
82 __pgprot(flags)));
14cf11af 83 } else {
14cf11af
PM
84 /*
85 * If the mm subsystem is not fully up, we cannot create a
86 * linux page table entry for this mapping. Simply bolt an
87 * entry in the hardware page table.
3c726f8d 88 *
14cf11af 89 */
1189be65
PM
90 if (htab_bolt_mapping(ea, ea + PAGE_SIZE, pa, flags,
91 mmu_io_psize, mmu_kernel_ssize)) {
77ac166f
BH
92 printk(KERN_ERR "Failed to do bolted mapping IO "
93 "memory at %016lx !\n", pa);
94 return -ENOMEM;
95 }
14cf11af
PM
96 }
97 return 0;
98}
99
100
3d5134ee
BH
101/**
102 * __ioremap_at - Low level function to establish the page tables
103 * for an IO mapping
104 */
105void __iomem * __ioremap_at(phys_addr_t pa, void *ea, unsigned long size,
14cf11af
PM
106 unsigned long flags)
107{
108 unsigned long i;
109
a1f242ff 110 /* Make sure we have the base flags */
14cf11af
PM
111 if ((flags & _PAGE_PRESENT) == 0)
112 flags |= pgprot_val(PAGE_KERNEL);
113
a1f242ff
BH
114 /* Non-cacheable page cannot be coherent */
115 if (flags & _PAGE_NO_CACHE)
116 flags &= ~_PAGE_COHERENT;
117
118 /* We don't support the 4K PFN hack with ioremap */
119 if (flags & _PAGE_4K_PFN)
120 return NULL;
121
3d5134ee
BH
122 WARN_ON(pa & ~PAGE_MASK);
123 WARN_ON(((unsigned long)ea) & ~PAGE_MASK);
124 WARN_ON(size & ~PAGE_MASK);
125
14cf11af 126 for (i = 0; i < size; i += PAGE_SIZE)
3d5134ee 127 if (map_io_page((unsigned long)ea+i, pa+i, flags))
14cf11af
PM
128 return NULL;
129
3d5134ee
BH
130 return (void __iomem *)ea;
131}
132
133/**
134 * __iounmap_from - Low level function to tear down the page tables
135 * for an IO mapping. This is used for mappings that
136 * are manipulated manually, like partial unmapping of
137 * PCI IOs or ISA space.
138 */
139void __iounmap_at(void *ea, unsigned long size)
140{
141 WARN_ON(((unsigned long)ea) & ~PAGE_MASK);
142 WARN_ON(size & ~PAGE_MASK);
143
144 unmap_kernel_range((unsigned long)ea, size);
14cf11af
PM
145}
146
68a64357 147void __iomem * __ioremap(phys_addr_t addr, unsigned long size,
14cf11af
PM
148 unsigned long flags)
149{
3d5134ee 150 phys_addr_t paligned;
14cf11af
PM
151 void __iomem *ret;
152
153 /*
154 * Choose an address to map it to.
155 * Once the imalloc system is running, we use it.
156 * Before that, we map using addresses going
157 * up from ioremap_bot. imalloc will use
158 * the addresses from ioremap_bot through
159 * IMALLOC_END
160 *
161 */
3d5134ee
BH
162 paligned = addr & PAGE_MASK;
163 size = PAGE_ALIGN(addr + size) - paligned;
14cf11af 164
3d5134ee 165 if ((size == 0) || (paligned == 0))
14cf11af
PM
166 return NULL;
167
168 if (mem_init_done) {
169 struct vm_struct *area;
3d5134ee
BH
170
171 area = __get_vm_area(size, VM_IOREMAP,
172 ioremap_bot, IOREMAP_END);
14cf11af
PM
173 if (area == NULL)
174 return NULL;
3d5134ee 175 ret = __ioremap_at(paligned, area->addr, size, flags);
14cf11af 176 if (!ret)
3d5134ee 177 vunmap(area->addr);
14cf11af 178 } else {
3d5134ee 179 ret = __ioremap_at(paligned, (void *)ioremap_bot, size, flags);
14cf11af
PM
180 if (ret)
181 ioremap_bot += size;
182 }
3d5134ee
BH
183
184 if (ret)
185 ret += addr & ~PAGE_MASK;
14cf11af
PM
186 return ret;
187}
188
4cb3cee0 189
68a64357 190void __iomem * ioremap(phys_addr_t addr, unsigned long size)
4cb3cee0
BH
191{
192 unsigned long flags = _PAGE_NO_CACHE | _PAGE_GUARDED;
193
194 if (ppc_md.ioremap)
195 return ppc_md.ioremap(addr, size, flags);
196 return __ioremap(addr, size, flags);
197}
198
68a64357 199void __iomem * ioremap_flags(phys_addr_t addr, unsigned long size,
4cb3cee0
BH
200 unsigned long flags)
201{
a1f242ff
BH
202 /* writeable implies dirty for kernel addresses */
203 if (flags & _PAGE_RW)
204 flags |= _PAGE_DIRTY;
205
206 /* we don't want to let _PAGE_USER and _PAGE_EXEC leak out */
207 flags &= ~(_PAGE_USER | _PAGE_EXEC);
208
4cb3cee0
BH
209 if (ppc_md.ioremap)
210 return ppc_md.ioremap(addr, size, flags);
211 return __ioremap(addr, size, flags);
212}
213
214
14cf11af
PM
215/*
216 * Unmap an IO region and remove it from imalloc'd list.
217 * Access to IO memory should be serialized by driver.
14cf11af 218 */
68a64357 219void __iounmap(volatile void __iomem *token)
14cf11af
PM
220{
221 void *addr;
222
223 if (!mem_init_done)
224 return;
225
3d5134ee
BH
226 addr = (void *) ((unsigned long __force)
227 PCI_FIX_ADDR(token) & PAGE_MASK);
228 if ((unsigned long)addr < ioremap_bot) {
229 printk(KERN_WARNING "Attempt to iounmap early bolted mapping"
230 " at 0x%p\n", addr);
231 return;
232 }
233 vunmap(addr);
14cf11af
PM
234}
235
68a64357 236void iounmap(volatile void __iomem *token)
4cb3cee0
BH
237{
238 if (ppc_md.iounmap)
239 ppc_md.iounmap(token);
240 else
241 __iounmap(token);
242}
243
14cf11af 244EXPORT_SYMBOL(ioremap);
4cb3cee0 245EXPORT_SYMBOL(ioremap_flags);
14cf11af 246EXPORT_SYMBOL(__ioremap);
a302cb9d 247EXPORT_SYMBOL(__ioremap_at);
14cf11af 248EXPORT_SYMBOL(iounmap);
4cb3cee0 249EXPORT_SYMBOL(__iounmap);
a302cb9d 250EXPORT_SYMBOL(__iounmap_at);