sun3kmap.c 3.3 KB

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