1 /* $NetBSD: pmb.c,v 1.2 2020/08/04 02:09:57 uwe Exp $ */
2 /*
3 * Copyright (c) 2020 Valery Ushakov
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #include <sys/cdefs.h>
28 __KERNEL_RCSID(0, "$NetBSD: pmb.c,v 1.2 2020/08/04 02:09:57 uwe Exp $");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33
34 #include <sh3/devreg.h>
35 #include <sh3/mmu_sh4.h>
36 #include <sh3/pmb.h>
37
38
39 static void st40_pmb_dump(int se_mode, int ub29);
40
41
42
43 void
st40_pmb_init(int product)44 st40_pmb_init(int product)
45 {
46 uint32_t pascr = 0; /* XXX: -Wuninitialized */
47 int se_mode;
48 int ub29;
49 char bits[64];
50
51 switch (product) {
52
53 /* ST40-300 */
54 case CPU_PRODUCT_STX7105: {
55 pascr = _reg_read_4(ST40_PASCR);
56 snprintb(bits, sizeof(bits), ST40_PASCR_BITS, pascr);
57 printf("PMB: PASCR=%s\n", bits);
58
59 se_mode = (pascr & ST40_PASCR_SE);
60 ub29 = pascr & ST40_PASCR_UB_MASK;
61 break;
62 }
63
64 #if 0
65 /* ST40-200, ST40-500 */
66 case 0xdeadbabe: {
67 uint32_t mmucr = _reg_read_4(SH4_MMUCR);
68
69 se_mode = (mmucr & ST40_MMUCR_SE);
70 ub29 = -1;
71 break;
72 }
73 #endif
74
75 /* No PMB */
76 default:
77 return;
78 }
79
80 st40_pmb_dump(se_mode, ub29);
81 }
82
83
84 static void
st40_pmb_dump(int se_mode,int ub29)85 st40_pmb_dump(int se_mode, int ub29)
86 {
87 char bits[64] __unused;
88
89 if (!se_mode) {
90 printf("PMB: 29-bit mode\n");
91 if (ub29 == -1)
92 return;
93
94 for (int area = 0; area < 8; ++area) {
95 bool unbuffered = !!((uint32_t)ub29 & (1u << area));
96 printf("PMB: area%d %s\n", area,
97 unbuffered ? "UB" : "--");
98 }
99 return;
100 }
101
102 printf("PMB: 32-bit mode\n");
103 for (unsigned int i = 0; i < ST40_PMB_ENTRY; ++i) {
104 uint32_t offset = (i << ST40_PMB_E_SHIFT);
105
106 uint32_t addr = _reg_read_4(ST40_PMB_AA + offset);
107 #if 0
108 snprintb(bits, sizeof(bits), ST40_PMB_AA_BITS, addr);
109 printf("PMB[%02d] A=%s", i, bits);
110 #endif
111 uint32_t data = _reg_read_4(ST40_PMB_DA + offset);
112 #if 0
113 snprintb(bits, sizeof(bits), ST40_PMB_DA_BITS, data);
114 printf(" D=%s\n", bits);
115 #endif
116 if ((addr & ST40_PMB_AA_V) == 0)
117 continue;
118
119 uint32_t vpn = addr & ST40_PMB_AA_VPN_MASK;
120 uint32_t ppn = data & ST40_PMB_DA_PPN_MASK;
121 uint32_t szbits = data & ST40_PMB_DA_SZ_MASK;
122
123 vpn >>= ST40_PMB_AA_VPN_SHIFT;
124 ppn >>= ST40_PMB_DA_PPN_SHIFT;
125
126 unsigned int sz = 0;
127 switch (szbits) {
128 case ST40_PMB_DA_SZ_16M:
129 sz = 1;
130 break;
131 case ST40_PMB_DA_SZ_64M:
132 sz = 4;
133 break;
134 case ST40_PMB_DA_SZ_128M:
135 sz = 8;
136 break;
137 case ST40_PMB_DA_SZ_512M:
138 sz = 32;
139 break;
140 }
141
142 printf("PMB[%02d] = %02x..%02x -> %02x..%02x"
143 " %3uM %s %s %s\n",
144 i,
145 vpn, vpn + sz - 1,
146 ppn, ppn + sz - 1,
147 sz << 4,
148 data & ST40_PMB_DA_UB ? "UB" : "--",
149 data & ST40_PMB_DA_C ? "C" : "-",
150 data & ST40_PMB_DA_C ?
151 (data & ST40_PMB_DA_WT ? "WT" : "CB") : "--");
152 }
153 }
154