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