1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
/* $NetBSD: sun3x.c,v 1.14 2020/06/20 18:46:14 riastradh Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jeremy Cooper and Gordon Ross
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Standalone functions specific to the Sun3X.
*/
#define _SUN3X_ XXX
#include <sys/param.h>
#include <machine/mon.h>
#include <stand.h>
#include "libsa.h"
#include "dvma.h"
#include "saio.h" /* enum MAPTYPES */
#include <arch/sun3/include/pte3x.h>
#include <arch/sun3/sun3x/iommu.h>
#include <arch/sun3/sun3x/vme.h>
/* Names, names... */
#define MON_LOMEM_BASE 0
#define MON_LOMEM_SIZE 0x400000
#define MON_LOMEM_END (MON_LOMEM_BASE+MON_LOMEM_SIZE)
#define MON_KDB_BASE SUN3X_MON_KDB_BASE
#define MON_KDB_SIZE SUN3X_MON_KDB_SIZE
#define MON_KDB_END (MON_KDB_BASE+MON_KDB_SIZE)
#define MON_DVMA_BASE SUN3X_MON_DVMA_BASE
#define MON_DVMA_SIZE SUN3X_MON_DVMA_SIZE
static void mmu_atc_flush(vaddr_t);
static void set_iommupte(vaddr_t, paddr_t);
#ifdef DEBUG_PROM
static u_int sun3x_get_pte(vaddr_t);
#endif
static void sun3x_set_pte(vaddr_t, paddr_t);
static void dvma3x_init(void);
static char * dvma3x_alloc(int);
static void dvma3x_free(char *, int);
static char * dvma3x_mapin(char *, int);
static void dvma3x_mapout(char *, int);
static char * dev3x_mapin(int, u_long, int);
struct mapinfo {
int maptype;
u_int base;
u_int mask;
};
struct mapinfo
sun3x_mapinfo[MAP__NTYPES] = {
/* On-board memory, I/O */
{ MAP_MAINMEM, 0, ~0 },
{ MAP_OBIO, 0, ~0 },
/* Multibus adapter (A24,A16) */
{ MAP_MBMEM, VME24D16_BASE, VME24_MASK },
{ MAP_MBIO, VME16D16_BASE, VME16_MASK },
/* VME A16 */
{ MAP_VME16A16D, VME16D16_BASE, VME16_MASK },
{ MAP_VME16A32D, VME16D32_BASE, VME16_MASK },
/* VME A24 */
{ MAP_VME24A16D, VME24D16_BASE, VME24_MASK },
{ MAP_VME24A32D, VME24D32_BASE, VME24_MASK },
/* VME A32 */
{ MAP_VME32A16D, VME32D16_BASE, VME32_MASK },
{ MAP_VME32A32D, VME32D32_BASE, VME32_MASK },
};
/* The virtual address we will use for PROM device mappings. */
u_int sun3x_devmap = MON_KDB_BASE;
static char *
dev3x_mapin(int maptype, u_long physaddr, int length)
{
u_int i, pa, pte, pgva, va;
if ((sun3x_devmap + length) > (MON_KDB_BASE + MON_KDB_SIZE))
panic("dev3x_mapin: length=%d", length);
for (i = 0; i < MAP__NTYPES; i++)
if (sun3x_mapinfo[i].maptype == maptype)
goto found;
panic("dev3x_mapin: bad maptype");
found:
if (physaddr & ~(sun3x_mapinfo[i].mask))
panic("dev3x_mapin: bad address");
pa = sun3x_mapinfo[i].base + physaddr;
pte = pa | MMU_DT_PAGE | MMU_SHORT_PTE_CI;
va = pgva = sun3x_devmap;
do {
sun3x_set_pte(pgva, pte);
pgva += NBPG;
pte += NBPG;
length -= NBPG;
} while (length > 0);
sun3x_devmap = pgva;
va += (physaddr & PGOFSET);
#ifdef DEBUG_PROM
if (debug)
printf("dev3x_mapin: va=0x%x pte=0x%x\n",
va, sun3x_get_pte(va));
#endif
return ((char*)va);
}
/*****************************************************************
* DVMA support
*/
#define SA_MIN_VA 0x200000
#define SA_MAX_VA (SA_MIN_VA + MON_DVMA_SIZE - (8 * NBPG))
#define MON_DVMA_MAPLEN (MON_DVMA_SIZE - NBPG)
/* This points to the end of the free DVMA space. */
u_int dvma3x_end = MON_DVMA_BASE + MON_DVMA_MAPLEN;
static void
dvma3x_init(void)
{
u_int va, pa;
pa = SA_MIN_VA;
va = MON_DVMA_BASE;
while (pa < SA_MAX_VA) {
sun3x_set_pte(va, pa | MMU_DT_PAGE | MMU_SHORT_PTE_CI);
set_iommupte(va, pa | IOMMU_PDE_DT_VALID | IOMMU_PDE_CI);
va += NBPG;
pa += NBPG;
}
}
/* Convert a local address to a DVMA address. */
char *
dvma3x_mapin(char *addr, int len)
{
int va = (int)addr;
/* Make sure the address is in the DVMA map. */
if ((va < SA_MIN_VA) || (va >= SA_MAX_VA))
panic("dvma3x_mapin");
va -= SA_MIN_VA;
va += MON_DVMA_BASE;
return ((char *) va);
}
/* Convert a DVMA address to a local address. */
static void
dvma3x_mapout(char *addr, int len)
{
int va = (int)addr;
/* Make sure the address is in the DVMA map. */
if ((va < MON_DVMA_BASE) ||
(va >= (MON_DVMA_BASE + MON_DVMA_MAPLEN)))
panic("dvma3x_mapout");
}
static char *
dvma3x_alloc(int len)
{
len = m68k_round_page(len);
dvma3x_end -= len;
return((char *)dvma3x_end);
}
static void
dvma3x_free(char *dvma, int len)
{
/* not worth the trouble */
}
/*****************************************************************
* MMU (and I/O MMU) support
*/
#ifdef DEBUG_PROM
static u_int
sun3x_get_pte(vaddr_t va)
{
u_int pn;
mmu_short_pte_t *tbl;
if (va >= MON_LOMEM_BASE && va < MON_LOMEM_END) {
tbl = (mmu_short_pte_t *) *romVectorPtr->lomemptaddr;
} else if (va >= MON_KDB_BASE && va < MON_KDB_END) {
va -= MON_KDB_BASE;
tbl = (mmu_short_pte_t *) *romVectorPtr->monptaddr;
} else if (va >= MON_DVMA_BASE) {
va -= MON_DVMA_BASE;
tbl = (mmu_short_pte_t *) *romVectorPtr->shadowpteaddr;
} else {
return 0;
}
/* Calculate the page number within the selected table. */
pn = (va >> MMU_PAGE_SHIFT);
/* Extract the PTE from the table. */
return tbl[pn].attr.raw;
}
#endif
static void
sun3x_set_pte(vaddr_t va, paddr_t pa)
{
u_int pn;
mmu_short_pte_t *tbl;
if (va >= MON_LOMEM_BASE && va < (MON_LOMEM_BASE + MON_LOMEM_SIZE)) {
/*
* Main memory range.
*/
tbl = (mmu_short_pte_t *) *romVectorPtr->lomemptaddr;
} else if (va >= MON_KDB_BASE && va < (MON_KDB_BASE + MON_KDB_SIZE)) {
/*
* Kernel Debugger range.
*/
va -= MON_KDB_BASE;
tbl = (mmu_short_pte_t *) *romVectorPtr->monptaddr;
} else if (va >= MON_DVMA_BASE) {
/*
* DVMA range.
*/
va -= MON_DVMA_BASE;
tbl = (mmu_short_pte_t *) *romVectorPtr->shadowpteaddr;
} else {
/* invalid range */
return;
}
/* Calculate the page number within the selected table. */
pn = (va >> MMU_PAGE_SHIFT);
/* Enter the PTE into the table. */
tbl[pn].attr.raw = pa;
/* Flush the ATC of any cached entries for the va. */
mmu_atc_flush(va);
}
static void
mmu_atc_flush(vaddr_t va)
{
__asm volatile ("pflush #0,#0,%0@" : : "a" (va));
}
static void
set_iommupte(vaddr_t va, paddr_t pa)
{
iommu_pde_t *iommu_va;
int pn;
iommu_va = (iommu_pde_t *) *romVectorPtr->dvmaptaddr;
/* Adjust the virtual address into an offset within the DVMA map. */
va -= MON_DVMA_BASE;
/* Convert the slave address into a page index. */
pn = IOMMU_BTOP(va);
iommu_va[pn].addr.raw = pa;
}
/*****************************************************************
* Init our function pointers, etc.
*/
void
sun3x_init(void)
{
/* Set the function pointers. */
dev_mapin_p = dev3x_mapin;
dvma_alloc_p = dvma3x_alloc;
dvma_free_p = dvma3x_free;
dvma_mapin_p = dvma3x_mapin;
dvma_mapout_p = dvma3x_mapout;
dvma3x_init();
}
|