blob: 1bc0c172726fbac923bac76985e032ef9d442cd9 [file] [log] [blame]
Bjorn Helgaase9b0a072006-03-26 01:37:06 -08001/*
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 Helgaas32e62c62006-05-05 17:19:50 -060014#include <asm/meminit.h>
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080015
16static inline void __iomem *
Bjorn Helgaasc4add2e2007-03-30 10:33:11 -060017__ioremap (unsigned long phys_addr, unsigned long size)
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080018{
Bjorn Helgaasc4add2e2007-03-30 10:33:11 -060019 return (void __iomem *) (__IA64_UNCACHED_OFFSET | phys_addr);
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080020}
21
22void __iomem *
Bjorn Helgaasc4add2e2007-03-30 10:33:11 -060023ioremap (unsigned long phys_addr, unsigned long size)
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080024{
Bjorn Helgaas32e62c62006-05-05 17:19:50 -060025 u64 attr;
26 unsigned long gran_base, gran_size;
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080027
Bjorn Helgaas32e62c62006-05-05 17:19:50 -060028 /*
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 Helgaasc4add2e2007-03-30 10:33:11 -060033 attr = kern_mem_attribute(phys_addr, size);
Bjorn Helgaas32e62c62006-05-05 17:19:50 -060034 if (attr & EFI_MEMORY_WB)
Bjorn Helgaasc4add2e2007-03-30 10:33:11 -060035 return (void __iomem *) phys_to_virt(phys_addr);
Bjorn Helgaas32e62c62006-05-05 17:19:50 -060036 else if (attr & EFI_MEMORY_UC)
Bjorn Helgaasc4add2e2007-03-30 10:33:11 -060037 return __ioremap(phys_addr, size);
Bjorn Helgaasc1c57d72006-03-30 09:53:39 -070038
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080039 /*
Bjorn Helgaas32e62c62006-05-05 17:19:50 -060040 * Some chipsets don't support UC access to memory. If
41 * WB is supported for the whole granule, we prefer that.
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080042 */
Bjorn Helgaasc4add2e2007-03-30 10:33:11 -060043 gran_base = GRANULEROUNDDOWN(phys_addr);
44 gran_size = GRANULEROUNDUP(phys_addr + size) - gran_base;
Bjorn Helgaas32e62c62006-05-05 17:19:50 -060045 if (efi_mem_attribute(gran_base, gran_size) & EFI_MEMORY_WB)
Bjorn Helgaasc4add2e2007-03-30 10:33:11 -060046 return (void __iomem *) phys_to_virt(phys_addr);
Bjorn Helgaas32e62c62006-05-05 17:19:50 -060047
Bjorn Helgaasc4add2e2007-03-30 10:33:11 -060048 return __ioremap(phys_addr, size);
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080049}
50EXPORT_SYMBOL(ioremap);
51
52void __iomem *
Bjorn Helgaasc4add2e2007-03-30 10:33:11 -060053ioremap_nocache (unsigned long phys_addr, unsigned long size)
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080054{
Bjorn Helgaasc4add2e2007-03-30 10:33:11 -060055 if (kern_mem_attribute(phys_addr, size) & EFI_MEMORY_WB)
Keith Owense037cda2006-07-17 15:41:59 +100056 return NULL;
Bjorn Helgaas32e62c62006-05-05 17:19:50 -060057
Bjorn Helgaasc4add2e2007-03-30 10:33:11 -060058 return __ioremap(phys_addr, size);
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080059}
60EXPORT_SYMBOL(ioremap_nocache);