sun3kmap.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * linux/arch/m68k/mm/sun3kmap.c
  3. *
  4. * Copyright (C) 2002 Sam Creasey <sammy@sammy.net>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/mm.h>
  14. #include <linux/vmalloc.h>
  15. #include <asm/page.h>
  16. #include <asm/pgtable.h>
  17. #include <asm/io.h>
  18. #include <asm/sun3mmu.h>
  19. #undef SUN3_KMAP_DEBUG
  20. #ifdef SUN3_KMAP_DEBUG
  21. extern void print_pte_vaddr(unsigned long vaddr);
  22. #endif
  23. extern void mmu_emu_map_pmeg (int context, int vaddr);
  24. static inline void do_page_mapin(unsigned long phys, unsigned long virt,
  25. unsigned long type)
  26. {
  27. unsigned long pte;
  28. pte_t ptep;
  29. ptep = pfn_pte(phys >> PAGE_SHIFT, PAGE_KERNEL);
  30. pte = pte_val(ptep);
  31. pte |= type;
  32. sun3_put_pte(virt, pte);
  33. #ifdef SUN3_KMAP_DEBUG
  34. pr_info("mapin:");
  35. print_pte_vaddr(virt);
  36. #endif
  37. }
  38. static inline void do_pmeg_mapin(unsigned long phys, unsigned long virt,
  39. unsigned long type, int pages)
  40. {
  41. if(sun3_get_segmap(virt & ~SUN3_PMEG_MASK) == SUN3_INVALID_PMEG)
  42. mmu_emu_map_pmeg(sun3_get_context(), virt);
  43. while(pages) {
  44. do_page_mapin(phys, virt, type);
  45. phys += PAGE_SIZE;
  46. virt += PAGE_SIZE;
  47. pages--;
  48. }
  49. }
  50. void __iomem *sun3_ioremap(unsigned long phys, unsigned long size,
  51. unsigned long type)
  52. {
  53. struct vm_struct *area;
  54. unsigned long offset, virt, ret;
  55. int pages;
  56. if(!size)
  57. return NULL;
  58. /* page align */
  59. offset = phys & (PAGE_SIZE-1);
  60. phys &= ~(PAGE_SIZE-1);
  61. size += offset;
  62. size = PAGE_ALIGN(size);
  63. if((area = get_vm_area(size, VM_IOREMAP)) == NULL)
  64. return NULL;
  65. #ifdef SUN3_KMAP_DEBUG
  66. pr_info("ioremap: got virt %p size %lx(%lx)\n", area->addr, size,
  67. area->size);
  68. #endif
  69. pages = size / PAGE_SIZE;
  70. virt = (unsigned long)area->addr;
  71. ret = virt + offset;
  72. while(pages) {
  73. int seg_pages;
  74. seg_pages = (SUN3_PMEG_SIZE - (virt & SUN3_PMEG_MASK)) / PAGE_SIZE;
  75. if(seg_pages > pages)
  76. seg_pages = pages;
  77. do_pmeg_mapin(phys, virt, type, seg_pages);
  78. pages -= seg_pages;
  79. phys += seg_pages * PAGE_SIZE;
  80. virt += seg_pages * PAGE_SIZE;
  81. }
  82. return (void __iomem *)ret;
  83. }
  84. EXPORT_SYMBOL(sun3_ioremap);
  85. void __iomem *__ioremap(unsigned long phys, unsigned long size, int cache)
  86. {
  87. return sun3_ioremap(phys, size, SUN3_PAGE_TYPE_IO);
  88. }
  89. EXPORT_SYMBOL(__ioremap);
  90. void iounmap(void __iomem *addr)
  91. {
  92. vfree((void *)(PAGE_MASK & (unsigned long)addr));
  93. }
  94. EXPORT_SYMBOL(iounmap);
  95. /* sun3_map_test(addr, val) -- Reads a byte from addr, storing to val,
  96. * trapping the potential read fault. Returns 0 if the access faulted,
  97. * 1 on success.
  98. *
  99. * This function is primarily used to check addresses on the VME bus.
  100. *
  101. * Mucking with the page fault handler seems a little hackish to me, but
  102. * SunOS, NetBSD, and Mach all implemented this check in such a manner,
  103. * so I figure we're allowed.
  104. */
  105. int sun3_map_test(unsigned long addr, char *val)
  106. {
  107. int ret = 0;
  108. __asm__ __volatile__
  109. (".globl _sun3_map_test_start\n"
  110. "_sun3_map_test_start:\n"
  111. "1: moveb (%2), (%0)\n"
  112. " moveq #1, %1\n"
  113. "2:\n"
  114. ".section .fixup,\"ax\"\n"
  115. ".even\n"
  116. "3: moveq #0, %1\n"
  117. " jmp 2b\n"
  118. ".previous\n"
  119. ".section __ex_table,\"a\"\n"
  120. ".align 4\n"
  121. ".long 1b,3b\n"
  122. ".previous\n"
  123. ".globl _sun3_map_test_end\n"
  124. "_sun3_map_test_end:\n"
  125. : "=a"(val), "=r"(ret)
  126. : "a"(addr));
  127. return ret;
  128. }
  129. EXPORT_SYMBOL(sun3_map_test);