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
|
/* $NetBSD: sun3.c,v 1.11 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 Gordon W. 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 Sun3.
*/
#define _SUN3_ XXX
/*
* We need to get the sun3 NBSG definition, even if we're
* building this with a different sun68k target.
*/
#include <arch/sun3/include/pmap3.h>
#include <sys/param.h>
#include <machine/idprom.h>
#include <machine/mon.h>
#include <arch/sun3/include/pte3.h>
#include <arch/sun3/sun3/control.h>
#include <arch/sun3/sun3/vme.h>
#include <stand.h>
#include "libsa.h"
#include "dvma.h"
#include "saio.h" /* enum MAPTYPES */
#define OBIO_MASK 0xFFFFFF
#ifdef DEBUG_PROM
static u_int sun3_get_pte(vaddr_t);
#endif
static void sun3_set_pte(vaddr_t, u_int);
static void dvma3_init(void);
static char * dvma3_alloc(int);
static void dvma3_free(char *, int);
static char * dvma3_mapin(char *, int);
static void dvma3_mapout(char *, int);
static char * dev3_mapin(int, u_long, int);
static int sun3_get_segmap(vaddr_t);
static void sun3_set_segmap(vaddr_t, int);
struct mapinfo {
int maptype;
int pgtype;
u_int base;
u_int mask;
};
struct mapinfo
sun3_mapinfo[MAP__NTYPES] = {
/* On-board memory, I/O */
{ MAP_MAINMEM, PGT_OBMEM, 0, ~0 },
{ MAP_OBIO, PGT_OBIO, 0, OBIO_MASK },
/* Multibus adapter (A24,A16) */
{ MAP_MBMEM, PGT_VME_D16, VME24_BASE, VME24_MASK },
{ MAP_MBIO, PGT_VME_D16, VME16_BASE, VME16_MASK },
/* VME A16 */
{ MAP_VME16A16D, PGT_VME_D16, VME16_BASE, VME16_MASK },
{ MAP_VME16A32D, PGT_VME_D32, VME16_BASE, VME16_MASK },
/* VME A24 */
{ MAP_VME24A16D, PGT_VME_D16, VME24_BASE, VME24_MASK },
{ MAP_VME24A32D, PGT_VME_D32, VME24_BASE, VME24_MASK },
/* VME A32 */
{ MAP_VME32A16D, PGT_VME_D16, VME32_BASE, VME32_MASK },
{ MAP_VME32A32D, PGT_VME_D32, VME32_BASE, VME32_MASK },
};
/* The virtual address we will use for PROM device mappings. */
int sun3_devmap = SUN3_MONSHORTSEG;
static char *
dev3_mapin(int maptype, u_long physaddr, int length)
{
u_int i, pa, pte, pgva, va;
if ((sun3_devmap + length) > SUN3_MONSHORTPAGE)
panic("dev3_mapin: length=%d", length);
for (i = 0; i < MAP__NTYPES; i++)
if (sun3_mapinfo[i].maptype == maptype)
goto found;
panic("dev3_mapin: bad maptype");
found:
if (physaddr & ~(sun3_mapinfo[i].mask))
panic("dev3_mapin: bad address");
pa = sun3_mapinfo[i].base += physaddr;
pte = PA_PGNUM(pa) | PG_PERM | sun3_mapinfo[i].pgtype;
va = pgva = sun3_devmap;
do {
sun3_set_pte(pgva, pte);
pgva += NBPG;
pte += 1;
length -= NBPG;
} while (length > 0);
sun3_devmap = pgva;
va += (physaddr & PGOFSET);
#ifdef DEBUG_PROM
if (debug)
printf("dev3_mapin: va=0x%x pte=0x%x\n",
va, sun3_get_pte(va));
#endif
return ((char*)va);
}
/*****************************************************************
* DVMA support
*/
/*
* The easiest way to deal with the need for DVMA mappings is to
* create a DVMA alias mapping of the entire address range used by
* the boot program. That way, dvma_mapin can just compute the
* DVMA alias address, and dvma_mapout does nothing.
*
* Note that this assumes that standalone programs will do I/O
* operations only within range (SA_MIN_VA .. SA_MAX_VA) checked.
*/
#define DVMA_BASE 0xFFf00000
#define DVMA_MAPLEN 0xE0000 /* 1 MB - 128K (save MONSHORTSEG) */
#define SA_MIN_VA 0x200000
#define SA_MAX_VA (SA_MIN_VA + DVMA_MAPLEN)
/* This points to the end of the free DVMA space. */
u_int dvma3_end = DVMA_BASE + DVMA_MAPLEN;
static void
dvma3_init(void)
{
int segva, dmava, sme;
segva = SA_MIN_VA;
dmava = DVMA_BASE;
while (segva < SA_MAX_VA) {
sme = sun3_get_segmap(segva);
sun3_set_segmap(dmava, sme);
segva += NBSG;
dmava += NBSG;
}
}
/* Convert a local address to a DVMA address. */
static char *
dvma3_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("dvma3_mapin");
va -= SA_MIN_VA;
va += DVMA_BASE;
return ((char *) va);
}
/* Destroy a DVMA address alias. */
static void
dvma3_mapout(char *addr, int len)
{
int va = (int)addr;
/* Make sure the address is in the DVMA map. */
if ((va < DVMA_BASE) || (va >= (DVMA_BASE + DVMA_MAPLEN)))
panic("dvma3_mapout");
}
static char *
dvma3_alloc(int len)
{
len = m68k_round_page(len);
dvma3_end -= len;
return((char*)dvma3_end);
}
static void
dvma3_free(char *dvma, int len)
{
/* not worth the trouble */
}
/*****************************************************************
* Control space stuff...
*/
#ifdef DEBUG_PROM
static u_int
sun3_get_pte(vaddr_t va)
{
va = CONTROL_ADDR_BUILD(PGMAP_BASE, va);
return (get_control_word(va));
}
#endif
static void
sun3_set_pte(vaddr_t va, u_int pte)
{
va = CONTROL_ADDR_BUILD(PGMAP_BASE, va);
set_control_word(va, pte);
}
static int
sun3_get_segmap(vaddr_t va)
{
va = CONTROL_ADDR_BUILD(SEGMAP_BASE, va);
return (get_control_byte(va));
}
static void
sun3_set_segmap(vaddr_t va, int sme)
{
va = CONTROL_ADDR_BUILD(SEGMAP_BASE, va);
set_control_byte(va, sme);
}
/*
* Copy the IDPROM contents into the passed buffer.
* The caller (idprom.c) will do the checksum.
*/
void
sun3_getidprom(u_char *dst)
{
vaddr_t src; /* control space address */
int len, x;
src = IDPROM_BASE;
len = sizeof(struct idprom);
do {
x = get_control_byte(src++);
*dst++ = x;
} while (--len > 0);
}
/*****************************************************************
* Init our function pointers, etc.
*/
void
sun3_init(void)
{
/* Set the function pointers. */
dev_mapin_p = dev3_mapin;
dvma_alloc_p = dvma3_alloc;
dvma_free_p = dvma3_free;
dvma_mapin_p = dvma3_mapin;
dvma_mapout_p = dvma3_mapout;
/* Prepare DVMA segment. */
dvma3_init();
}
|