ioremap.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include <linux/compiler.h>
  10. #include <linux/module.h>
  11. #include <linux/efi.h>
  12. #include <asm/io.h>
  13. #include <asm/meminit.h>
  14. static inline void __iomem *
  15. __ioremap (unsigned long offset, unsigned long size)
  16. {
  17. return (void __iomem *) (__IA64_UNCACHED_OFFSET | offset);
  18. }
  19. void __iomem *
  20. ioremap (unsigned long offset, unsigned long size)
  21. {
  22. u64 attr;
  23. unsigned long gran_base, gran_size;
  24. /*
  25. * For things in kern_memmap, we must use the same attribute
  26. * as the rest of the kernel. For more details, see
  27. * Documentation/ia64/aliasing.txt.
  28. */
  29. attr = kern_mem_attribute(offset, size);
  30. if (attr & EFI_MEMORY_WB)
  31. return (void __iomem *) phys_to_virt(offset);
  32. else if (attr & EFI_MEMORY_UC)
  33. return __ioremap(offset, size);
  34. /*
  35. * Some chipsets don't support UC access to memory. If
  36. * WB is supported for the whole granule, we prefer that.
  37. */
  38. gran_base = GRANULEROUNDDOWN(offset);
  39. gran_size = GRANULEROUNDUP(offset + size) - gran_base;
  40. if (efi_mem_attribute(gran_base, gran_size) & EFI_MEMORY_WB)
  41. return (void __iomem *) phys_to_virt(offset);
  42. return __ioremap(offset, size);
  43. }
  44. EXPORT_SYMBOL(ioremap);
  45. void __iomem *
  46. ioremap_nocache (unsigned long offset, unsigned long size)
  47. {
  48. if (kern_mem_attribute(offset, size) & EFI_MEMORY_WB)
  49. return NULL;
  50. return __ioremap(offset, size);
  51. }
  52. EXPORT_SYMBOL(ioremap_nocache);