/Ethereal-msm8939-beta9/arch/metag/mm/ioremap.c

https://bitbucket.org/MilosStamenkovic95/etherealos · C · 89 lines · 52 code · 11 blank · 26 comment · 7 complexity · c2e4aab6076c9fea1723f5ec2f88f77a MD5 · raw file

  1. /*
  2. * Re-map IO memory to kernel address space so that we can access it.
  3. * Needed for memory-mapped I/O devices mapped outside our normal DRAM
  4. * window (that is, all memory-mapped I/O devices).
  5. *
  6. * Copyright (C) 1995,1996 Linus Torvalds
  7. *
  8. * Meta port based on CRIS-port by Axis Communications AB
  9. */
  10. #include <linux/vmalloc.h>
  11. #include <linux/io.h>
  12. #include <linux/export.h>
  13. #include <linux/slab.h>
  14. #include <linux/mm.h>
  15. #include <asm/pgtable.h>
  16. /*
  17. * Remap an arbitrary physical address space into the kernel virtual
  18. * address space. Needed when the kernel wants to access high addresses
  19. * directly.
  20. *
  21. * NOTE! We need to allow non-page-aligned mappings too: we will obviously
  22. * have to convert them into an offset in a page-aligned mapping, but the
  23. * caller shouldn't need to know that small detail.
  24. */
  25. void __iomem *__ioremap(unsigned long phys_addr, size_t size,
  26. unsigned long flags)
  27. {
  28. unsigned long addr;
  29. struct vm_struct *area;
  30. unsigned long offset, last_addr;
  31. pgprot_t prot;
  32. /* Don't allow wraparound or zero size */
  33. last_addr = phys_addr + size - 1;
  34. if (!size || last_addr < phys_addr)
  35. return NULL;
  36. /* Custom region addresses are accessible and uncached by default. */
  37. if (phys_addr >= LINSYSCUSTOM_BASE &&
  38. phys_addr < (LINSYSCUSTOM_BASE + LINSYSCUSTOM_LIMIT))
  39. return (__force void __iomem *) phys_addr;
  40. /*
  41. * Mappings have to be page-aligned
  42. */
  43. offset = phys_addr & ~PAGE_MASK;
  44. phys_addr &= PAGE_MASK;
  45. size = PAGE_ALIGN(last_addr+1) - phys_addr;
  46. prot = __pgprot(_PAGE_PRESENT | _PAGE_WRITE | _PAGE_DIRTY |
  47. _PAGE_ACCESSED | _PAGE_KERNEL | _PAGE_CACHE_WIN0 |
  48. flags);
  49. /*
  50. * Ok, go for it..
  51. */
  52. area = get_vm_area(size, VM_IOREMAP);
  53. if (!area)
  54. return NULL;
  55. area->phys_addr = phys_addr;
  56. addr = (unsigned long) area->addr;
  57. if (ioremap_page_range(addr, addr + size, phys_addr, prot)) {
  58. vunmap((void *) addr);
  59. return NULL;
  60. }
  61. return (__force void __iomem *) (offset + (char *)addr);
  62. }
  63. EXPORT_SYMBOL(__ioremap);
  64. void __iounmap(void __iomem *addr)
  65. {
  66. struct vm_struct *p;
  67. if ((__force unsigned long)addr >= LINSYSCUSTOM_BASE &&
  68. (__force unsigned long)addr < (LINSYSCUSTOM_BASE +
  69. LINSYSCUSTOM_LIMIT))
  70. return;
  71. p = remove_vm_area((void *)(PAGE_MASK & (unsigned long __force)addr));
  72. if (unlikely(!p)) {
  73. pr_err("iounmap: bad address %p\n", addr);
  74. return;
  75. }
  76. kfree(p);
  77. }
  78. EXPORT_SYMBOL(__iounmap);