cablePowerDataOperation.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * linux/arch/arm/mm/ioremap.c
  3. *
  4. * Re-map IO memory to kernel address space so that we can access it.
  5. *
  6. * (C) Copyright 1995 1996 Linus Torvalds
  7. *
  8. * Hacked for ARM by Phil Blundell <philb@gnu.org>
  9. * Hacked to allow all architectures to build, and various cleanups
  10. * by Russell King
  11. *
  12. * This allows a driver to remap an arbitrary region of bus memory into
  13. * virtual space. One should *only* use readl, writel, memcpy_toio and
  14. * so on with such remapped areas.
  15. *
  16. * Because the ARM only has a 32-bit address space we can't address the
  17. * whole of the (physical) PCI space at once. PCI huge-mode addressing
  18. * allows us to circumvent this restriction by splitting PCI space into
  19. * two 2GB chunks and mapping only one at a time into processor memory.
  20. * We use MMU protection domains to trap any attempt to access the bank
  21. * that is not currently mapped. (This isn't fully implemented yet.)
  22. */
  23. #include <linux/module.h>
  24. #include <linux/errno.h>
  25. #include <linux/mm.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/io.h>
  28. #include <linux/sizes.h>
  29. #include <asm/cp15.h>
  30. #include <asm/cputype.h>
  31. #include <asm/cacheflush.h>
  32. #include <asm/mmu_context.h>
  33. #include <asm/pgalloc.h>
  34. #include <asm/tlbflush.h>
  35. #include <asm/system_info.h>
  36. #include <asm/mach/map.h>
  37. #include <asm/mach/pci.h>
  38. #include "mm.h"
  39. int ioremap_page(unsigned long virt, unsigned long phys,
  40. const struct mem_type *mtype)
  41. {
  42. return ioremap_page_range(virt, virt + PAGE_SIZE, phys,
  43. __pgprot(mtype->prot_pte));
  44. }
  45. EXPORT_SYMBOL(ioremap_page);
  46. void __check_vmalloc_seq(struct mm_struct *mm)
  47. {
  48. unsigned int seq;
  49. do {
  50. seq = init_mm.context.vmalloc_seq;
  51. memcpy(pgd_offset(mm, VMALLOC_START),
  52. pgd_offset_k(VMALLOC_START),
  53. sizeof(pgd_t) * (pgd_index(VMALLOC_END) -
  54. pgd_index(VMALLOC_START)));
  55. mm->context.vmalloc_seq = seq;
  56. } while (seq != init_mm.context.vmalloc_seq);
  57. }
  58. #if !defined(CONFIG_SMP) && !defined(CONFIG_ARM_LPAE)
  59. /*
  60. * Section support is unsafe on SMP - If you iounmap and ioremap a region,
  61. * the other CPUs will not see this change until their next context switch.
  62. * Meanwhile, (eg) if an interrupt comes in on one of those other CPUs
  63. * which requires the new ioremap'd region to be referenced, the CPU will
  64. * reference the _old_ region.
  65. *
  66. * Note that get_vm_area_caller() allocates a guard 4K page, so we need to
  67. * mask the size back to 1MB aligned or we will overflow in the loop below.
  68. */
  69. static void unmap_area_sections(unsigned long virt, unsigned long size)
  70. {
  71. unsigned long addr = virt, end = virt + (size & ~(SZ_1M - 1));
  72. pgd_t *pgd;
  73. pud_t *pud;
  74. pmd_t *pmdp;
  75. flush_cache_vunmap(addr, end);
  76. pgd = pgd_offset_k(addr);
  77. pud = pud_offset(pgd, addr);
  78. pmdp = pmd_offset(pud, addr);
  79. do {
  80. pmd_t pmd = *pmdp;
  81. if (!pmd_none(pmd)) {
  82. /*
  83. * Clear the PMD from the page table, and
  84. * increment the vmalloc sequence so others
  85. * notice this change.
  86. *
  87. * Note: this is still racy on SMP machines.
  88. */
  89. pmd_clear(pmdp);
  90. init_mm.context.vmalloc_seq++;
  91. /*
  92. * Free the page table, if there was one.
  93. */
  94. if ((pmd_val(pmd) & PMD_TYPE_MASK) == PMD_TYPE_TABLE)
  95. pte_free_kernel(&init_mm, pmd_page_vaddr(pmd));
  96. }
  97. addr += PMD_SIZE;
  98. pmdp += 2;
  99. } while (addr < end);
  100. /*
  101. * Ensure that the active_mm is up to date - we want to
  102. * catch any use-after-iounmap cases.
  103. */
  104. if (current->active_mm->context.vmalloc_seq != init_mm.context.vmalloc_seq)
  105. __check_vmalloc_seq(current->active_mm);
  106. flush_tlb_kernel_range(virt, end);
  107. }
  108. static int
  109. remap_area_sections(unsigned long virt, unsigned long pfn,
  110. size_t size, const struct mem_type *type)
  111. {
  112. unsigned long addr = virt, end = virt + size;
  113. pgd_t *pgd;
  114. pud_t *pud;
  115. pmd_t *pmd;
  116. /*
  117. * Remove and free any PTE-based mapping, and
  118. * sync the current kernel mapping.
  119. */
  120. unmap_area_sections(virt, size);
  121. pgd = pgd_offset_k(addr);
  122. pud = pud_offset(pgd, addr);
  123. pmd = pmd_offset(pud, addr);
  124. do {
  125. pmd[0] = __pmd(__pfn_to_phys(pfn) | type->prot_sect);
  126. pfn += SZ_1M >> PAGE_SHIFT;
  127. pmd[1] = __pmd(__pfn_to_phys(pfn) | type->prot_sect);
  128. pfn += SZ_1M >> PAGE_SHIFT;
  129. flush_pmd_entry(pmd);
  130. addr += PMD_SIZE;
  131. pmd += 2;
  132. } while (addr < end);
  133. return 0;
  134. }
  135. static int
  136. remap_area_supersections(unsigned long virt, unsigned long pfn,
  137. size_t size, const struct mem_type *type)
  138. {