blob: 07bd02b6c3724fc8a2979413971fc3ec48fd61da [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 *
17__ioremap (unsigned long offset, unsigned long size)
18{
19 return (void __iomem *) (__IA64_UNCACHED_OFFSET | offset);
20}
21
22void __iomem *
23ioremap (unsigned long offset, unsigned long size)
24{
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 */
33 attr = kern_mem_attribute(offset, size);
34 if (attr & EFI_MEMORY_WB)
35 return phys_to_virt(offset);
36 else if (attr & EFI_MEMORY_UC)
Bjorn Helgaasc1c57d72006-03-30 09:53:39 -070037 return __ioremap(offset, size);
38
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 Helgaas32e62c62006-05-05 17:19:50 -060043 gran_base = GRANULEROUNDDOWN(offset);
44 gran_size = GRANULEROUNDUP(offset + size) - gran_base;
45 if (efi_mem_attribute(gran_base, gran_size) & EFI_MEMORY_WB)
46 return phys_to_virt(offset);
47
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080048 return __ioremap(offset, size);
49}
50EXPORT_SYMBOL(ioremap);
51
52void __iomem *
53ioremap_nocache (unsigned long offset, unsigned long size)
54{
Bjorn Helgaas32e62c62006-05-05 17:19:50 -060055 if (kern_mem_attribute(offset, size) & EFI_MEMORY_WB)
56 return 0;
57
Bjorn Helgaase9b0a072006-03-26 01:37:06 -080058 return __ioremap(offset, size);
59}
60EXPORT_SYMBOL(ioremap_nocache);