Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 1 | /* |
| 2 | * (c) Copyright 2006 Hewlett-Packard Development Company, L.P. |
| 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> |
| 13 | #include <asm/io.h> |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 14 | #include <asm/meminit.h> |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 15 | |
| 16 | static inline void __iomem * |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 17 | __ioremap (unsigned long phys_addr, unsigned long size) |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 18 | { |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 19 | return (void __iomem *) (__IA64_UNCACHED_OFFSET | phys_addr); |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | void __iomem * |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 23 | ioremap (unsigned long phys_addr, unsigned long size) |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 24 | { |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 25 | u64 attr; |
| 26 | unsigned long gran_base, gran_size; |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 27 | |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 28 | /* |
| 29 | * For things in kern_memmap, we must use the same attribute |
| 30 | * as the rest of the kernel. For more details, see |
| 31 | * Documentation/ia64/aliasing.txt. |
| 32 | */ |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 33 | attr = kern_mem_attribute(phys_addr, size); |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 34 | if (attr & EFI_MEMORY_WB) |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 35 | return (void __iomem *) phys_to_virt(phys_addr); |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 36 | else if (attr & EFI_MEMORY_UC) |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 37 | return __ioremap(phys_addr, size); |
Bjorn Helgaas | c1c57d7 | 2006-03-30 09:53:39 -0700 | [diff] [blame] | 38 | |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 39 | /* |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 40 | * Some chipsets don't support UC access to memory. If |
| 41 | * WB is supported for the whole granule, we prefer that. |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 42 | */ |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 43 | gran_base = GRANULEROUNDDOWN(phys_addr); |
| 44 | gran_size = GRANULEROUNDUP(phys_addr + size) - gran_base; |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 45 | if (efi_mem_attribute(gran_base, gran_size) & EFI_MEMORY_WB) |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 46 | return (void __iomem *) phys_to_virt(phys_addr); |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 47 | |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 48 | return __ioremap(phys_addr, size); |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 49 | } |
| 50 | EXPORT_SYMBOL(ioremap); |
| 51 | |
| 52 | void __iomem * |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 53 | ioremap_nocache (unsigned long phys_addr, unsigned long size) |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 54 | { |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 55 | if (kern_mem_attribute(phys_addr, size) & EFI_MEMORY_WB) |
Keith Owens | e037cda | 2006-07-17 15:41:59 +1000 | [diff] [blame] | 56 | return NULL; |
Bjorn Helgaas | 32e62c6 | 2006-05-05 17:19:50 -0600 | [diff] [blame] | 57 | |
Bjorn Helgaas | c4add2e | 2007-03-30 10:33:11 -0600 | [diff] [blame^] | 58 | return __ioremap(phys_addr, size); |
Bjorn Helgaas | e9b0a07 | 2006-03-26 01:37:06 -0800 | [diff] [blame] | 59 | } |
| 60 | EXPORT_SYMBOL(ioremap_nocache); |