2 * linux/arch/m68k/mm/sun3kmap.c
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
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/kernel.h>
15 #include <linux/vmalloc.h>
19 #include <asm/sun3mmu.h>
21 #include "../sun3/sun3.h"
23 #undef SUN3_KMAP_DEBUG
25 extern void mmu_emu_map_pmeg (int context, int vaddr);
27 static inline void do_page_mapin(unsigned long phys, unsigned long virt,
33 ptep = pfn_pte(phys >> PAGE_SHIFT, PAGE_KERNEL);
37 sun3_put_pte(virt, pte);
39 #ifdef SUN3_KMAP_DEBUG
41 print_pte_vaddr(virt);
46 static inline void do_pmeg_mapin(unsigned long phys, unsigned long virt,
47 unsigned long type, int pages)
50 if(sun3_get_segmap(virt & ~SUN3_PMEG_MASK) == SUN3_INVALID_PMEG)
51 mmu_emu_map_pmeg(sun3_get_context(), virt);
54 do_page_mapin(phys, virt, type);
61 void __iomem *sun3_ioremap(unsigned long phys, unsigned long size,
64 struct vm_struct *area;
65 unsigned long offset, virt, ret;
72 offset = phys & (PAGE_SIZE-1);
73 phys &= ~(PAGE_SIZE-1);
76 size = PAGE_ALIGN(size);
77 if((area = get_vm_area(size, VM_IOREMAP)) == NULL)
80 #ifdef SUN3_KMAP_DEBUG
81 pr_info("ioremap: got virt %p size %lx(%lx)\n", area->addr, size,
85 pages = size / PAGE_SIZE;
86 virt = (unsigned long)area->addr;
92 seg_pages = (SUN3_PMEG_SIZE - (virt & SUN3_PMEG_MASK)) / PAGE_SIZE;
96 do_pmeg_mapin(phys, virt, type, seg_pages);
99 phys += seg_pages * PAGE_SIZE;
100 virt += seg_pages * PAGE_SIZE;
103 return (void __iomem *)ret;
106 EXPORT_SYMBOL(sun3_ioremap);
109 void __iomem *__ioremap(unsigned long phys, unsigned long size, int cache)
112 return sun3_ioremap(phys, size, SUN3_PAGE_TYPE_IO);
115 EXPORT_SYMBOL(__ioremap);
117 void iounmap(void __iomem *addr)
119 vfree((void *)(PAGE_MASK & (unsigned long)addr));
121 EXPORT_SYMBOL(iounmap);
123 /* sun3_map_test(addr, val) -- Reads a byte from addr, storing to val,
124 * trapping the potential read fault. Returns 0 if the access faulted,
127 * This function is primarily used to check addresses on the VME bus.
129 * Mucking with the page fault handler seems a little hackish to me, but
130 * SunOS, NetBSD, and Mach all implemented this check in such a manner,
131 * so I figure we're allowed.
133 int sun3_map_test(unsigned long addr, char *val)
138 (".globl _sun3_map_test_start\n"
139 "_sun3_map_test_start:\n"
140 "1: moveb (%2), (%0)\n"
143 ".section .fixup,\"ax\"\n"
148 ".section __ex_table,\"a\"\n"
152 ".globl _sun3_map_test_end\n"
153 "_sun3_map_test_end:\n"
154 : "=a"(val), "=r"(ret)
159 EXPORT_SYMBOL(sun3_map_test);