sun3kmap.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. print_pte_vaddr(virt);
  35. #endif
  36. }
  37. static inline void do_pmeg_mapin(unsigned long phys, unsigned long virt,
  38. unsigned long type, int pages)
  39. {
  40. if(sun3_get_segmap(virt & ~SUN3_PMEG_MASK) == SUN3_INVALID_PMEG)
  41. mmu_emu_map_pmeg(sun3_get_context(), virt);
  42. while(pages) {
  43. do_page_mapin(phys, virt, type);
  44. phys += PAGE_SIZE;
  45. virt += PAGE_SIZE;
  46. pages--;
  47. }
  48. }
  49. void __iomem *sun3_ioremap(unsigned long phys, unsigned long size,
  50. unsigned long type)
  51. {
  52. struct vm_struct *area;
  53. unsigned long offset, virt, ret;
  54. int pages;
  55. if(!size)
  56. return NULL;
  57. /* page align */
  58. offset = phys & (PAGE_SIZE-1);
  59. phys &= ~(PAGE_SIZE-1);
  60. size += offset;
  61. size = PAGE_ALIGN(size);
  62. if((area = get_vm_area(size, VM_IOREMAP)) == NULL)
  63. return NULL;
  64. #ifdef SUN3_KMAP_DEBUG
  65. printk("ioremap: got virt %p size %lx(%lx)\n",
  66. area->addr, size, area->size);
  67. #endif
  68. pages = size / PAGE_SIZE;
  69. virt = (unsigned long)area->addr;
  70. ret = virt + offset;
  71. while(pages) {
  72. int seg_pages;
  73. seg_pages = (SUN3_PMEG_SIZE - (virt & SUN3_PMEG_MASK)) / PAGE_SIZE;
  74. if(seg_pages > pages)
  75. seg_pages = pages;
  76. do_pmeg_mapin(phys, virt, type, seg_pages);
  77. pages -= seg_pages;
  78. phys += seg_pages * PAGE_SIZE;
  79. virt += seg_pages * PAGE_SIZE;
  80. }
  81. return (void __iomem *)ret;
  82. }
  83. EXPORT_SYMBOL(sun3_ioremap);
  84. void __iomem *__ioremap(unsigned long phys, unsigned long size, int cache)
  85. {
  86. return sun3_ioremap(phys, size, SUN3_PAGE_TYPE_IO);
  87. }
  88. EXPORT_SYMBOL(__ioremap);
  89. void iounmap(void __iomem *addr)
  90. {
  91. vfree((void *)(PAGE_MASK & (unsigned long)addr));
  92. }
  93. EXPORT_SYMBOL(iounmap);
  94. /* sun3_map_test(addr, val) -- Reads a byte from addr, storing to val,
  95. * trapping the potential read fault. Returns 0 if the access faulted,
  96. * 1 on success.
  97. *
  98. * This function is primarily used to check addresses on the VME bus.
  99. *
  100. * Mucking with the page fault handler seems a little hackish to me, but
  101. * SunOS, NetBSD, and Mach all implemented this check in such a manner,
  102. * so I figure we're allowed.
  103. */
  104. int sun3_map_test(unsigned long addr, char *val)
  105. {
  106. int ret = 0;
  107. __asm__ __volatile__
  108. (".globl _sun3_map_test_start\n"
  109. "_sun3_map_test_start:\n"
  110. "1: moveb (%2), (%0)\n"
  111. " moveq #1, %1\n"
  112. "2:\n"
  113. ".section .fixup,\"ax\"\n"
  114. ".even\n"
  115. "3: moveq #0, %1\n"
  116. " jmp 2b\n"
  117. ".previous\n"
  118. ".section __ex_table,\"a\"\n"
  119. ".align 4\n"
  120. ".long 1b,3b\n"
  121. ".previous\n"
  122. ".globl _sun3_map_test_end\n"
  123. "_sun3_map_test_end:\n"
  124. : "=a"(val), "=r"(ret)
  125. : "a"(addr));
  126. return ret;
  127. }
  128. EXPORT_SYMBOL(sun3_map_test);