Merge branch 'perf-fixes-for-linus-2' of git://git.kernel.org/pub/scm/linux/kernel...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / ia64 / mm / ioremap.c
CommitLineData
e9b0a071 1/*
9b50ffb0 2 * (c) Copyright 2006, 2007 Hewlett-Packard Development Company, L.P.
e9b0a071
BH
3 * Bjorn Helgaas <bjorn.helgaas@hp.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/compiler.h>
11#include <linux/module.h>
12#include <linux/efi.h>
9b50ffb0
BH
13#include <linux/io.h>
14#include <linux/vmalloc.h>
e9b0a071 15#include <asm/io.h>
32e62c63 16#include <asm/meminit.h>
e9b0a071
BH
17
18static inline void __iomem *
9b50ffb0 19__ioremap (unsigned long phys_addr)
e9b0a071 20{
c4add2e5 21 return (void __iomem *) (__IA64_UNCACHED_OFFSET | phys_addr);
e9b0a071
BH
22}
23
cd7bcf32
TL
24void __iomem *
25early_ioremap (unsigned long phys_addr, unsigned long size)
26{
27 return __ioremap(phys_addr);
28}
29
e9b0a071 30void __iomem *
c4add2e5 31ioremap (unsigned long phys_addr, unsigned long size)
e9b0a071 32{
9b50ffb0
BH
33 void __iomem *addr;
34 struct vm_struct *area;
35 unsigned long offset;
36 pgprot_t prot;
32e62c63
BH
37 u64 attr;
38 unsigned long gran_base, gran_size;
9b50ffb0 39 unsigned long page_base;
e9b0a071 40
32e62c63
BH
41 /*
42 * For things in kern_memmap, we must use the same attribute
43 * as the rest of the kernel. For more details, see
44 * Documentation/ia64/aliasing.txt.
45 */
c4add2e5 46 attr = kern_mem_attribute(phys_addr, size);
32e62c63 47 if (attr & EFI_MEMORY_WB)
c4add2e5 48 return (void __iomem *) phys_to_virt(phys_addr);
32e62c63 49 else if (attr & EFI_MEMORY_UC)
9b50ffb0 50 return __ioremap(phys_addr);
c1c57d76 51
e9b0a071 52 /*
32e62c63
BH
53 * Some chipsets don't support UC access to memory. If
54 * WB is supported for the whole granule, we prefer that.
e9b0a071 55 */
c4add2e5
BH
56 gran_base = GRANULEROUNDDOWN(phys_addr);
57 gran_size = GRANULEROUNDUP(phys_addr + size) - gran_base;
32e62c63 58 if (efi_mem_attribute(gran_base, gran_size) & EFI_MEMORY_WB)
c4add2e5 59 return (void __iomem *) phys_to_virt(phys_addr);
32e62c63 60
9b50ffb0
BH
61 /*
62 * WB is not supported for the whole granule, so we can't use
63 * the region 7 identity mapping. If we can safely cover the
64 * area with kernel page table mappings, we can use those
65 * instead.
66 */
67 page_base = phys_addr & PAGE_MASK;
68 size = PAGE_ALIGN(phys_addr + size) - page_base;
69 if (efi_mem_attribute(page_base, size) & EFI_MEMORY_WB) {
70 prot = PAGE_KERNEL;
71
72 /*
73 * Mappings have to be page-aligned
74 */
75 offset = phys_addr & ~PAGE_MASK;
76 phys_addr &= PAGE_MASK;
77
78 /*
79 * Ok, go for it..
80 */
81 area = get_vm_area(size, VM_IOREMAP);
82 if (!area)
83 return NULL;
84
85 area->phys_addr = phys_addr;
86 addr = (void __iomem *) area->addr;
87 if (ioremap_page_range((unsigned long) addr,
88 (unsigned long) addr + size, phys_addr, prot)) {
89 vunmap((void __force *) addr);
90 return NULL;
91 }
92
93 return (void __iomem *) (offset + (char __iomem *)addr);
94 }
95
96 return __ioremap(phys_addr);
e9b0a071
BH
97}
98EXPORT_SYMBOL(ioremap);
99
100void __iomem *
c4add2e5 101ioremap_nocache (unsigned long phys_addr, unsigned long size)
e9b0a071 102{
c4add2e5 103 if (kern_mem_attribute(phys_addr, size) & EFI_MEMORY_WB)
e037cda5 104 return NULL;
32e62c63 105
9b50ffb0 106 return __ioremap(phys_addr);
e9b0a071
BH
107}
108EXPORT_SYMBOL(ioremap_nocache);
9b50ffb0 109
cd7bcf32
TL
110void
111early_iounmap (volatile void __iomem *addr, unsigned long size)
112{
113}
114
9b50ffb0
BH
115void
116iounmap (volatile void __iomem *addr)
117{
118 if (REGION_NUMBER(addr) == RGN_GATE)
119 vunmap((void *) ((unsigned long) addr & PAGE_MASK));
120}
121EXPORT_SYMBOL(iounmap);