Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 1 | /* |
Bjorn Helgaas | 9b50ffb | 2007-03-30 10:34:05 -0600 | [diff] [blame] | 2 | * (c) Copyright 2006, 2007 Hewlett-Packard Development Company, L.P. |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 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> |
Bjorn Helgaas | 9b50ffb | 2007-03-30 10:34:05 -0600 | [diff] [blame] | 13 | #include <linux/io.h> |
| 14 | #include <linux/vmalloc.h> |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 15 | #include <asm/io.h> |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 16 | #include <asm/meminit.h> |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 17 | |
| 18 | static inline void __iomem * |
Bjorn Helgaas | 9b50ffb | 2007-03-30 10:34:05 -0600 | [diff] [blame] | 19 | __ioremap (unsigned long phys_addr) |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 20 | { |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame] | 21 | return (void __iomem *) (__IA64_UNCACHED_OFFSET | phys_addr); |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | void __iomem * |
Luck, Tony | cd7bcf3 | 2009-12-14 20:00:36 +0000 | [diff] [blame] | 25 | early_ioremap (unsigned long phys_addr, unsigned long size) |
| 26 | { |
| 27 | return __ioremap(phys_addr); |
| 28 | } |
| 29 | |
| 30 | void __iomem * |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame] | 31 | ioremap (unsigned long phys_addr, unsigned long size) |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 32 | { |
Bjorn Helgaas | 9b50ffb | 2007-03-30 10:34:05 -0600 | [diff] [blame] | 33 | void __iomem *addr; |
| 34 | struct vm_struct *area; |
| 35 | unsigned long offset; |
| 36 | pgprot_t prot; |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 37 | u64 attr; |
| 38 | unsigned long gran_base, gran_size; |
Bjorn Helgaas | 9b50ffb | 2007-03-30 10:34:05 -0600 | [diff] [blame] | 39 | unsigned long page_base; |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 40 | |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 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 | */ |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame] | 46 | attr = kern_mem_attribute(phys_addr, size); |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 47 | if (attr & EFI_MEMORY_WB) |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame] | 48 | return (void __iomem *) phys_to_virt(phys_addr); |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 49 | else if (attr & EFI_MEMORY_UC) |
Bjorn Helgaas | 9b50ffb | 2007-03-30 10:34:05 -0600 | [diff] [blame] | 50 | return __ioremap(phys_addr); |
Bjorn Helgaas | c1c57d7 | 2006-03-30 09:53:39 -0700 | [diff] [blame] | 51 | |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 52 | /* |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 53 | * Some chipsets don't support UC access to memory. If |
| 54 | * WB is supported for the whole granule, we prefer that. |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 55 | */ |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame] | 56 | gran_base = GRANULEROUNDDOWN(phys_addr); |
| 57 | gran_size = GRANULEROUNDUP(phys_addr + size) - gran_base; |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 58 | if (efi_mem_attribute(gran_base, gran_size) & EFI_MEMORY_WB) |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame] | 59 | return (void __iomem *) phys_to_virt(phys_addr); |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 60 | |
Bjorn Helgaas | 9b50ffb | 2007-03-30 10:34:05 -0600 | [diff] [blame] | 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); |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 97 | } |
| 98 | EXPORT_SYMBOL(ioremap); |
| 99 | |
| 100 | void __iomem * |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame] | 101 | ioremap_nocache (unsigned long phys_addr, unsigned long size) |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 102 | { |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame] | 103 | if (kern_mem_attribute(phys_addr, size) & EFI_MEMORY_WB) |
Keith Owens | e037cda | 2006-07-17 15:41:59 +1000 | [diff] [blame] | 104 | return NULL; |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 105 | |
Bjorn Helgaas | 9b50ffb | 2007-03-30 10:34:05 -0600 | [diff] [blame] | 106 | return __ioremap(phys_addr); |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 107 | } |
| 108 | EXPORT_SYMBOL(ioremap_nocache); |
Bjorn Helgaas | 9b50ffb | 2007-03-30 10:34:05 -0600 | [diff] [blame] | 109 | |
| 110 | void |
Luck, Tony | cd7bcf3 | 2009-12-14 20:00:36 +0000 | [diff] [blame] | 111 | early_iounmap (volatile void __iomem *addr, unsigned long size) |
| 112 | { |
| 113 | } |
| 114 | |
| 115 | void |
Bjorn Helgaas | 9b50ffb | 2007-03-30 10:34:05 -0600 | [diff] [blame] | 116 | iounmap (volatile void __iomem *addr) |
| 117 | { |
| 118 | if (REGION_NUMBER(addr) == RGN_GATE) |
| 119 | vunmap((void *) ((unsigned long) addr & PAGE_MASK)); |
| 120 | } |
| 121 | EXPORT_SYMBOL(iounmap); |