2 * linux/arch/m68k/mm/sun3kmap.c
4 * Copyright (C) 2002 Sam Creasey <sammy@sammy.net>
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>
18 #include <asm/pgtable.h>
20 #include <asm/sun3mmu.h>
22 #undef SUN3_KMAP_DEBUG
24 #ifdef SUN3_KMAP_DEBUG
25 extern void print_pte_vaddr(unsigned long vaddr
);
28 extern void mmu_emu_map_pmeg (int context
, int vaddr
);
30 static inline void do_page_mapin(unsigned long phys
, unsigned long virt
,
36 ptep
= pfn_pte(phys
>> PAGE_SHIFT
, PAGE_KERNEL
);
40 sun3_put_pte(virt
, pte
);
42 #ifdef SUN3_KMAP_DEBUG
44 print_pte_vaddr(virt
);
49 static inline void do_pmeg_mapin(unsigned long phys
, unsigned long virt
,
50 unsigned long type
, int pages
)
53 if(sun3_get_segmap(virt
& ~SUN3_PMEG_MASK
) == SUN3_INVALID_PMEG
)
54 mmu_emu_map_pmeg(sun3_get_context(), virt
);
57 do_page_mapin(phys
, virt
, type
);
64 void __iomem
*sun3_ioremap(unsigned long phys
, unsigned long size
,
67 struct vm_struct
*area
;
68 unsigned long offset
, virt
, ret
;
75 offset
= phys
& (PAGE_SIZE
-1);
76 phys
&= ~(PAGE_SIZE
-1);
79 size
= PAGE_ALIGN(size
);
80 if((area
= get_vm_area(size
, VM_IOREMAP
)) == NULL
)
83 #ifdef SUN3_KMAP_DEBUG
84 pr_info("ioremap: got virt %p size %lx(%lx)\n", area
->addr
, size
,
88 pages
= size
/ PAGE_SIZE
;
89 virt
= (unsigned long)area
->addr
;
95 seg_pages
= (SUN3_PMEG_SIZE
- (virt
& SUN3_PMEG_MASK
)) / PAGE_SIZE
;
99 do_pmeg_mapin(phys
, virt
, type
, seg_pages
);
102 phys
+= seg_pages
* PAGE_SIZE
;
103 virt
+= seg_pages
* PAGE_SIZE
;
106 return (void __iomem
*)ret
;
109 EXPORT_SYMBOL(sun3_ioremap
);
112 void __iomem
*__ioremap(unsigned long phys
, unsigned long size
, int cache
)
115 return sun3_ioremap(phys
, size
, SUN3_PAGE_TYPE_IO
);
118 EXPORT_SYMBOL(__ioremap
);
120 void iounmap(void __iomem
*addr
)
122 vfree((void *)(PAGE_MASK
& (unsigned long)addr
));
124 EXPORT_SYMBOL(iounmap
);
126 /* sun3_map_test(addr, val) -- Reads a byte from addr, storing to val,
127 * trapping the potential read fault. Returns 0 if the access faulted,
130 * This function is primarily used to check addresses on the VME bus.
132 * Mucking with the page fault handler seems a little hackish to me, but
133 * SunOS, NetBSD, and Mach all implemented this check in such a manner,
134 * so I figure we're allowed.
136 int sun3_map_test(unsigned long addr
, char *val
)
141 (".globl _sun3_map_test_start\n"
142 "_sun3_map_test_start:\n"
143 "1: moveb (%2), (%0)\n"
146 ".section .fixup,\"ax\"\n"
151 ".section __ex_table,\"a\"\n"
155 ".globl _sun3_map_test_end\n"
156 "_sun3_map_test_end:\n"
157 : "=a"(val
), "=r"(ret
)
162 EXPORT_SYMBOL(sun3_map_test
);