xref: /netbsd-src/sys/arch/sh3/sh3/mmu.c (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /*	$NetBSD: mmu.c,v 1.18 2008/04/28 20:23:35 martin Exp $	*/
2780de330Such 
3780de330Such /*-
4780de330Such  * Copyright (c) 2002 The NetBSD Foundation, Inc.
5780de330Such  * All rights reserved.
6780de330Such  *
7780de330Such  * This code is derived from software contributed to The NetBSD Foundation
8780de330Such  * by UCHIYAMA Yasushi.
9780de330Such  *
10780de330Such  * Redistribution and use in source and binary forms, with or without
11780de330Such  * modification, are permitted provided that the following conditions
12780de330Such  * are met:
13780de330Such  * 1. Redistributions of source code must retain the above copyright
14780de330Such  *    notice, this list of conditions and the following disclaimer.
15780de330Such  * 2. Redistributions in binary form must reproduce the above copyright
16780de330Such  *    notice, this list of conditions and the following disclaimer in the
17780de330Such  *    documentation and/or other materials provided with the distribution.
18780de330Such  *
19780de330Such  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20780de330Such  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21780de330Such  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22780de330Such  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23780de330Such  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24780de330Such  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25780de330Such  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26780de330Such  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27780de330Such  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28780de330Such  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29780de330Such  * POSSIBILITY OF SUCH DAMAGE.
30780de330Such  */
31780de330Such 
32ed517291Slukem #include <sys/cdefs.h>
33*ce099b40Smartin __KERNEL_RCSID(0, "$NetBSD: mmu.c,v 1.18 2008/04/28 20:23:35 martin Exp $");
34ed517291Slukem 
35780de330Such #include <sys/param.h>
36780de330Such #include <sys/systm.h>
37780de330Such 
38780de330Such #include <sh3/mmu.h>
39780de330Such #include <sh3/mmu_sh3.h>
40780de330Such #include <sh3/mmu_sh4.h>
41780de330Such 
4225196f3eSuwe #if defined(SH3) && defined(SH4)
43780de330Such void (*__sh_mmu_start)(void);
44780de330Such void (*__sh_tlb_invalidate_addr)(int, vaddr_t);
45780de330Such void (*__sh_tlb_invalidate_asid)(int);
46780de330Such void (*__sh_tlb_invalidate_all)(void);
472e71b70dSuwe void (*__sh_tlb_update)(int, vaddr_t, uint32_t);
4825196f3eSuwe #endif /* SH3 && SH4 */
4925196f3eSuwe 
50780de330Such 
51780de330Such void
sh_mmu_init(void)5225196f3eSuwe sh_mmu_init(void)
53780de330Such {
5425196f3eSuwe 
55780de330Such 	/*
5625196f3eSuwe 	 * Assign function hooks but only if both SH3 and SH4 are defined.
5725196f3eSuwe 	 * They are called directly otherwise.  See <sh3/mmu.h>.
58780de330Such 	 */
5925196f3eSuwe #if defined(SH3) && defined(SH4)
60780de330Such 	if (CPU_IS_SH3) {
61780de330Such 		__sh_mmu_start = sh3_mmu_start;
62780de330Such 		__sh_tlb_invalidate_addr = sh3_tlb_invalidate_addr;
63780de330Such 		__sh_tlb_invalidate_asid = sh3_tlb_invalidate_asid;
64780de330Such 		__sh_tlb_invalidate_all = sh3_tlb_invalidate_all;
65bf93dc9bSuch 		__sh_tlb_update = sh3_tlb_update;
66bbc655c4Such 	}
6725196f3eSuwe 	else if (CPU_IS_SH4) {
68780de330Such 		__sh_mmu_start = sh4_mmu_start;
69780de330Such 		__sh_tlb_invalidate_addr = sh4_tlb_invalidate_addr;
70780de330Such 		__sh_tlb_invalidate_asid = sh4_tlb_invalidate_asid;
71780de330Such 		__sh_tlb_invalidate_all = sh4_tlb_invalidate_all;
72bf93dc9bSuch 		__sh_tlb_update = sh4_tlb_update;
73780de330Such 	}
7425196f3eSuwe #endif /* SH3 && SH4 */
75780de330Such }
76780de330Such 
77780de330Such void
sh_mmu_information(void)7825196f3eSuwe sh_mmu_information(void)
79f3b18820Such {
802e71b70dSuwe 	uint32_t r;
81bf93dc9bSuch #ifdef SH3
82f3b18820Such 	if (CPU_IS_SH3) {
8388c74cddSuwe 		aprint_normal("cpu0: 4-way set-associative 128 TLB entries\n");
84f3b18820Such 		r = _reg_read_4(SH3_MMUCR);
8588c74cddSuwe 		aprint_normal("cpu0: %s mode, %s virtual storage mode\n",
86e968ab94Suwe 		    r & SH3_MMUCR_IX ? "ASID+VPN" : "VPN",
87f3b18820Such 		    r & SH3_MMUCR_SV ? "single" : "multiple");
88f3b18820Such 	}
89bf93dc9bSuch #endif
90bf93dc9bSuch #ifdef SH4
91f3b18820Such 	if (CPU_IS_SH4) {
9266575b7bSuwe 		unsigned int urb;
9388c74cddSuwe 		aprint_normal("cpu0: full-associative"
9488c74cddSuwe 			      " 4 ITLB, 64 UTLB entries\n");
95f3b18820Such 		r = _reg_read_4(SH4_MMUCR);
9666575b7bSuwe 		urb = (r & SH4_MMUCR_URB_MASK) >> SH4_MMUCR_URB_SHIFT;
9788c74cddSuwe 		aprint_normal("cpu0: %s virtual storage mode,"
9888c74cddSuwe 			      " SQ access: kernel%s,"
9988c74cddSuwe 			      " wired %d\n",
100f3b18820Such 		    r & SH3_MMUCR_SV ? "single" : "multiple",
10188c74cddSuwe 		    r & SH4_MMUCR_SQMD ? "" : "/user",
10266575b7bSuwe 		    urb ? 64 - urb : 0);
103f3b18820Such 	}
104bf93dc9bSuch #endif
105f3b18820Such }
106f3b18820Such 
107f3b18820Such void
sh_tlb_set_asid(int asid)108780de330Such sh_tlb_set_asid(int asid)
109780de330Such {
110780de330Such 
111bf93dc9bSuch 	_reg_write_4(SH_(PTEH), asid);
112780de330Such }
113