ioremap.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * arch/parisc/mm/ioremap.c
  3. *
  4. * (C) Copyright 1995 1996 Linus Torvalds
  5. * (C) Copyright 2001-2006 Helge Deller <deller@gmx.de>
  6. * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org>
  7. */
  8. #include <linux/vmalloc.h>
  9. #include <linux/errno.h>
  10. #include <linux/module.h>
  11. #include <linux/io.h>
  12. #include <asm/pgalloc.h>
  13. /*
  14. * Generic mapping function (not visible outside):
  15. */
  16. /*
  17. * Remap an arbitrary physical address space into the kernel virtual
  18. * address space.
  19. *
  20. * NOTE! We need to allow non-page-aligned mappings too: we will obviously
  21. * have to convert them into an offset in a page-aligned mapping, but the
  22. * caller shouldn't need to know that small detail.
  23. */
  24. void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags)
  25. {
  26. void __iomem *addr;
  27. struct vm_struct *area;
  28. unsigned long offset, last_addr;
  29. pgprot_t pgprot;
  30. #ifdef CONFIG_EISA
  31. unsigned long end = phys_addr + size - 1;
  32. /* Support EISA addresses */
  33. if ((phys_addr >= 0x00080000 && end < 0x000fffff) ||
  34. (phys_addr >= 0x00500000 && end < 0x03bfffff)) {
  35. phys_addr |= F_EXTEND(0xfc000000);
  36. flags |= _PAGE_NO_CACHE;
  37. }
  38. #endif
  39. /* Don't allow wraparound or zero size */
  40. last_addr = phys_addr + size - 1;
  41. if (!size || last_addr < phys_addr)
  42. return NULL;
  43. /*
  44. * Don't allow anybody to remap normal RAM that we're using..
  45. */
  46. if (phys_addr < virt_to_phys(high_memory)) {
  47. char *t_addr, *t_end;
  48. struct page *page;
  49. t_addr = __va(phys_addr);
  50. t_end = t_addr + (size - 1);
  51. for (page = virt_to_page(t_addr);
  52. page <= virt_to_page(t_end); page++) {
  53. if(!PageReserved(page))
  54. return NULL;
  55. }
  56. }
  57. pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY |
  58. _PAGE_ACCESSED | flags);
  59. /*
  60. * Mappings have to be page-aligned
  61. */
  62. offset = phys_addr & ~PAGE_MASK;
  63. phys_addr &= PAGE_MASK;
  64. size = PAGE_ALIGN(last_addr + 1) - phys_addr;
  65. /*
  66. * Ok, go for it..
  67. */
  68. area = get_vm_area(size, VM_IOREMAP);
  69. if (!area)
  70. return NULL;
  71. addr = (void __iomem *) area->addr;
  72. if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
  73. phys_addr, pgprot)) {
  74. vfree(addr);
  75. return NULL;
  76. }
  77. return (void __iomem *) (offset + (char __iomem *)addr);
  78. }
  79. EXPORT_SYMBOL(__ioremap);
  80. void iounmap(const volatile void __iomem *addr)
  81. {
  82. if (addr > high_memory)
  83. return vfree((void *) (PAGE_MASK & (unsigned long __force) addr));
  84. }
  85. EXPORT_SYMBOL(iounmap);