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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
/* $NetBSD: obio.c,v 1.36 2021/08/07 16:19:06 thorpej Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Adam Glass and 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.36 2021/08/07 16:19:06 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <uvm/uvm_extern.h>
#define _SUN68K_BUS_DMA_PRIVATE
#include <machine/autoconf.h>
#include <machine/bus.h>
#include <machine/dvma.h>
#include <machine/mon.h>
#include <machine/pte.h>
#include <sun3/sun3/machdep.h>
#include <sun3/sun3x/obio.h>
static int obio_match(device_t, cfdata_t, void *);
static void obio_attach(device_t, device_t, void *);
static int obio_print(void *, const char *);
static int obio_submatch(device_t, cfdata_t, const int *, void *);
struct obio_softc {
device_t sc_dev;
bus_space_tag_t sc_bustag;
bus_dma_tag_t sc_dmatag;
};
CFATTACH_DECL_NEW(obio, sizeof(struct obio_softc),
obio_match, obio_attach, NULL, NULL);
static int obio_attached;
static int obio_bus_map(bus_space_tag_t, bus_type_t, bus_addr_t, bus_size_t,
int, vaddr_t, bus_space_handle_t *);
static paddr_t obio_bus_mmap(bus_space_tag_t, bus_type_t, bus_addr_t,
off_t, int, int);
static int obio_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
struct proc *, int);
static struct sun68k_bus_space_tag obio_space_tag = {
NULL, /* cookie */
NULL, /* parent bus space tag */
obio_bus_map, /* bus_space_map */
NULL, /* bus_space_unmap */
NULL, /* bus_space_subregion */
NULL, /* bus_space_barrier */
obio_bus_mmap, /* bus_space_mmap */
NULL, /* bus_intr_establish */
NULL, /* bus_space_peek_N */
NULL /* bus_space_poke_N */
};
static struct sun68k_bus_dma_tag obio_dma_tag;
static int
obio_match(device_t parent, cfdata_t cf, void *aux)
{
struct confargs *ca = aux;
if (obio_attached)
return 0;
if (ca->ca_bustype != BUS_OBIO)
return 0;
if (ca->ca_name != NULL && strcmp(cf->cf_name, ca->ca_name) != 0)
return 0;
return 1;
}
/*
* We need control over the order of attachment on OBIO,
* so do "direct" style autoconfiguration with addresses
* from the list below. OBIO addresses are fixed forever.
*
* Warning: This whole list is very carefully ordered!
* In general, anything not already shown here should
* be added at or near the end.
*/
static paddr_t obio_alist[] = {
/* This is used by the Ethernet and SCSI drivers. */
OBIO_IOMMU,
/* Misc. registers - needed by many things */
OBIO_ENABLEREG,
OBIO_BUSERRREG,
OBIO_DIAGREG, /* leds.c */
OBIO_IDPROM1, /* idprom.c (3/470) */
OBIO_MEMREG, /* memerr.c */
OBIO_INTERREG, /* intreg.c */
/* Zilog UARTs */
OBIO_ZS_KBD_MS,
OBIO_ZS_TTY_AB,
/* eeprom.c */
OBIO_EEPROM,
/* Note: This must come after OBIO_IDPROM1. */
OBIO_IDPROM2, /* idprom.c (3/80) */
/* Note: Must probe for the Intersil first! */
OBIO_CLOCK1, /* clock.c (3/470) */
OBIO_CLOCK2, /* clock.c (3/80) */
OBIO_INTEL_ETHER,
OBIO_LANCE_ETHER,
/* Need esp DMA before SCSI. */
OBIO_EMULEX_DMA, /* 3/80 only */
OBIO_EMULEX_SCSI, /* 3/80 only */
/* Memory subsystem */
OBIO_PCACHE_TAGS,
OBIO_ECCPARREG,
OBIO_IOC_TAGS,
OBIO_IOC_FLUSH,
OBIO_FDC, /* floppy disk (3/80) */
OBIO_PRINTER_PORT, /* printer port (3/80) */
};
#define OBIO_ALIST_LEN __arraycount(obio_alist)
static void
obio_attach(device_t parent, device_t self, void *aux)
{
struct confargs *ca = aux;
struct obio_softc *sc = device_private(self);
struct confargs oba;
int i;
obio_attached = 1;
sc->sc_dev = self;
aprint_normal("\n");
sc->sc_bustag = ca->ca_bustag;
sc->sc_dmatag = ca->ca_dmatag;
obio_space_tag.cookie = sc;
obio_space_tag.parent = sc->sc_bustag;
obio_dma_tag = *sc->sc_dmatag;
obio_dma_tag._cookie = sc;
obio_dma_tag._dmamap_load = obio_dmamap_load;
oba = *ca;
oba.ca_bustag = &obio_space_tag;
oba.ca_dmatag = &obio_dma_tag;
/* Configure these in the order listed above. */
for (i = 0; i < OBIO_ALIST_LEN; i++) {
/* Our parent set ca->ca_bustype already. */
oba.ca_paddr = obio_alist[i];
/* These are filled-in by obio_submatch. */
oba.ca_intpri = -1;
oba.ca_intvec = -1;
config_found(self, &oba, obio_print,
CFARGS(.submatch = obio_submatch));
}
}
/*
* Print out the confargs. The (parent) name is non-NULL
* when there was no match found by config_found().
*/
static int
obio_print(void *args, const char *name)
{
/* Be quiet about empty OBIO locations. */
if (name)
return QUIET;
/* Otherwise do the usual. */
return bus_print(args, name);
}
int
obio_submatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
{
struct confargs *ca = aux;
/*
* Note that a defaulted address locator can never match
* the value of ca->ca_paddr set by the obio_attach loop.
* Without this diagnostic, any device with a defaulted
* address locator would always be silently unmatched.
* Therefore, just disallow default addresses on OBIO.
*/
#ifdef DIAGNOSTIC
if (cf->cf_paddr == -1)
panic("%s: invalid address for: %s%d",
__func__, cf->cf_name, cf->cf_unit);
#endif
/*
* Note that obio_attach calls config_found_sm() with
* this function as the "submatch" and ca->ca_paddr
* set to each of the possible OBIO locations, so we
* want to reject any unmatched address here.
*/
if (cf->cf_paddr != ca->ca_paddr)
return 0;
/*
* Copy the locators into our confargs for the child.
* Note: ca->ca_bustype was set by our parent driver
* (mainbus) and ca->ca_paddr was set by obio_attach.
*/
ca->ca_intpri = cf->cf_intpri;
ca->ca_intvec = cf->cf_intvec;
/* Now call the match function of the potential child. */
return config_match(parent, cf, aux);
}
/*****************************************************************/
/*
* This is our record of "interesting" OBIO mappings that
* the PROM has left in the virtual space reserved for it.
* Each row of the array holds a virtual address and the
* physical address it maps to (if found).
*/
static struct prom_map {
paddr_t pa;
vaddr_t va;
} prom_mappings[] = {
{ OBIO_ENABLEREG, 0 }, /* regs: Sys ENA, Bus ERR, etc. */
{ OBIO_ZS_KBD_MS, 0 }, /* Keyboard and Mouse */
{ OBIO_ZS_TTY_AB, 0 }, /* Serial Ports */
{ OBIO_EEPROM, 0 }, /* EEPROM/IDPROM/clock */
};
#define PROM_MAP_CNT __arraycount(prom_mappings)
/*
* Find a virtual address for a device at physical address 'pa'.
* If one is found among the mappings already made by the PROM
* at power-up time, use it and return 0. Otherwise return errno
* as a sign that a mapping will have to be created.
*/
int
find_prom_map(paddr_t pa, bus_type_t iospace, int sz, vaddr_t *vap)
{
int i;
vsize_t off;
off = pa & PGOFSET;
pa -= off;
sz += off;
/* The saved mappings are all one page long. */
if (sz > PAGE_SIZE)
return EINVAL;
/* Linear search for it. The list is short. */
for (i = 0; i < PROM_MAP_CNT; i++) {
if (pa == prom_mappings[i].pa) {
*vap = prom_mappings[i].va + off;
return 0;
}
}
return ENOENT;
}
/*
* Search the PROM page tables for OBIO mappings that
* we would like to borrow.
*/
static void
save_prom_mappings(void)
{
int *mon_pte;
vaddr_t va;
paddr_t pa;
int i;
/* Note: mon_ctbl[0] maps SUN3X_MON_KDB_BASE */
mon_pte = *romVectorPtr->monptaddr;
for (va = SUN3X_MON_KDB_BASE; va < SUN3X_MONEND;
va += PAGE_SIZE, mon_pte++) {
/* Is this a valid mapping to OBIO? */
/* XXX - Some macros would be nice... */
if ((*mon_pte & 0xF0000003) != 0x60000001)
continue;
/* Yes it is. Is this a mapping we want? */
pa = *mon_pte & MMU_SHORT_PTE_BASEADDR;
for (i = 0; i < PROM_MAP_CNT; i++) {
if (pa != prom_mappings[i].pa)
continue;
/* Yes, we want it. Save the va? */
if (prom_mappings[i].va == 0) {
prom_mappings[i].va = va;
}
}
}
}
/*
* These are all the OBIO address that are required early in
* the life of the kernel. All are less than one page long.
* This function should make any required mappings that we
* were not able to find among the PROM monitor's mappings.
*/
static void
make_required_mappings(void)
{
int i;
for (i = 0; i < PROM_MAP_CNT; i++) {
if (prom_mappings[i].va == 0) {
/*
* Actually, the PROM always has all the
* "required" mappings we need, (smile)
* but this makes sure that is true.
*/
mon_printf("obio: no mapping for pa=0x%x\n",
prom_mappings[i].pa);
sunmon_abort(); /* Ancient PROM? */
}
}
}
/*
* Find mappings for devices that are needed before autoconfiguration.
* We first look for and record any useful PROM mappings, then call
* the "init" functions for drivers that we need to use before the
* normal autoconfiguration calls configure(). Warning: this is
* called before pmap_bootstrap, so no allocation allowed!
*/
void
obio_init(void)
{
save_prom_mappings();
make_required_mappings();
enable_init();
/*
* Find the interrupt reg mapping and turn off the
* interrupts, otherwise the PROM clock interrupt
* would poll the zs and toggle some LEDs...
*/
intreg_init();
}
int
obio_bus_map(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr,
bus_size_t size, int flags, vaddr_t vaddr, bus_space_handle_t *hp)
{
struct obio_softc *sc = t->cookie;
return bus_space_map2(sc->sc_bustag, PMAP_OBIO, paddr, size,
flags | _SUN68K_BUS_MAP_USE_PROM, vaddr, hp);
}
paddr_t
obio_bus_mmap(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr, off_t off,
int prot, int flags)
{
struct obio_softc *sc = t->cookie;
return bus_space_mmap2(sc->sc_bustag, PMAP_OBIO, paddr, off, prot,
flags);
}
static int
obio_dmamap_load(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
bus_size_t buflen, struct proc *p, int flags)
{
int error;
error = _bus_dmamap_load(t, map, buf, buflen, p, flags);
if (error == 0)
map->dm_segs[0].ds_addr &= DVMA_OBIO_SLAVE_MASK;
return error;
}
|