ioremap.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/vmalloc.h>
  9. #include <linux/init.h>
  10. #include <linux/module.h>
  11. #include <linux/io.h>
  12. #include <linux/mm.h>
  13. #include <linux/slab.h>
  14. #include <asm/cache.h>
  15. void __iomem *ioremap(unsigned long paddr, unsigned long size)
  16. {
  17. unsigned long vaddr;
  18. struct vm_struct *area;
  19. unsigned long off, end;
  20. const pgprot_t prot = PAGE_KERNEL_NO_CACHE;
  21. /* Don't allow wraparound or zero size */
  22. end = paddr + size - 1;
  23. if (!size || (end < paddr))
  24. return NULL;
  25. /* If the region is h/w uncached, nothing special needed */
  26. if (paddr >= ARC_UNCACHED_ADDR_SPACE)
  27. return (void __iomem *)paddr;
  28. /* An early platform driver might end up here */
  29. if (!slab_is_available())
  30. return NULL;
  31. /* Mappings have to be page-aligned, page-sized */
  32. off = paddr & ~PAGE_MASK;
  33. paddr &= PAGE_MASK;
  34. size = PAGE_ALIGN(end + 1) - paddr;
  35. /*
  36. * Ok, go for it..
  37. */
  38. area = get_vm_area(size, VM_IOREMAP);
  39. if (!area)
  40. return NULL;
  41. area->phys_addr = paddr;
  42. vaddr = (unsigned long)area->addr;
  43. if (ioremap_page_range(vaddr, vaddr + size, paddr, prot)) {
  44. vfree(area->addr);
  45. return NULL;
  46. }
  47. return (void __iomem *)(off + (char __iomem *)vaddr);
  48. }
  49. EXPORT_SYMBOL(ioremap);
  50. void iounmap(const void __iomem *addr)
  51. {
  52. if (addr >= (void __force __iomem *)ARC_UNCACHED_ADDR_SPACE)
  53. return;
  54. vfree((void *)(PAGE_MASK & (unsigned long __force)addr));
  55. }
  56. EXPORT_SYMBOL(iounmap);