sun3kmap.c 3.2 KB

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