podulebus.c revision 1.28 1 /* $NetBSD: podulebus.c,v 1.28 2014/09/13 18:08:38 matt Exp $ */
2
3 /*
4 * Copyright (c) 1994-1996 Mark Brinicombe.
5 * Copyright (c) 1994 Brini.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Brini.
19 * 4. The name of the company nor the name of the author may be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * RiscBSD kernel project
36 *
37 * podulebus.c
38 *
39 * Podule probe and configuration routines
40 *
41 * Created : 07/11/94
42 */
43
44 #include <sys/param.h>
45
46 __KERNEL_RCSID(0, "$NetBSD: podulebus.c,v 1.28 2014/09/13 18:08:38 matt Exp $");
47
48 #include <sys/systm.h>
49 #include <sys/kernel.h>
50 #include <sys/conf.h>
51 #include <sys/malloc.h>
52 #include <sys/device.h>
53 #include <uvm/uvm_extern.h>
54 #include <machine/io.h>
55 #include <arm/arm32/katelib.h>
56 #include <machine/intr.h>
57 #include <machine/bootconfig.h>
58 #include <machine/pmap.h>
59 #include <arm/iomd/iomdreg.h>
60 #include <arm/iomd/iomdvar.h>
61 #include <acorn32/podulebus/podulebus.h>
62 #include <dev/podulebus/podules.h>
63 #include <dev/podulebus/podule_data.h>
64
65 #include "locators.h"
66
67 /* Array of podule structures, one per possible podule */
68
69 podule_t podules[MAX_PODULES + MAX_NETSLOTS];
70
71 extern struct bus_space podulebus_bs_tag;
72
73 /* Declare prototypes */
74
75 u_int poduleread(u_int, int);
76 int podulebusmatch(device_t, cfdata_t, void *);
77 void podulebusattach(device_t, device_t, void *);
78 int podulebusprint(void *, const char *);
79 int podulebussubmatch(device_t, cfdata_t, const int *, void *);
80 void podulechunkdirectory(podule_t *);
81 void podulescan(device_t);
82
83 /*
84 * int podulebusmatch(device_t parent, void *match, void *aux)
85 *
86 * Probe for the podule bus. Currently all this does is return 1 to
87 * indicate that the podule bus was found.
88 */
89
90 int
91 podulebusmatch(device_t parent, cfdata_t cf, void *aux)
92 {
93 switch (IOMD_ID) {
94 case RPC600_IOMD_ID:
95 case ARM7500_IOC_ID:
96 case ARM7500FE_IOC_ID:
97 return(1);
98 }
99 return (0);
100 }
101
102
103 int
104 podulebusprint(void *aux, const char *name)
105 {
106 struct podule_attach_args *pa = aux;
107
108 if (name)
109 aprint_normal("podule at %s", name);
110 if (pa->pa_podule->slottype == SLOT_POD)
111 aprint_normal(" slot %d", pa->pa_podule_number);
112 else if (pa->pa_podule->slottype == SLOT_NET)
113 aprint_normal(" [ netslot %d ]",
114 pa->pa_podule_number - MAX_PODULES);
115 #ifdef DIAGNOSTIC
116 else
117 panic("Invalid slot type");
118 #endif
119
120 return (UNCONF);
121 }
122
123
124 int
125 podulebussubmatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
126 {
127 struct podule_attach_args *pa = aux;
128
129 /* Return priority 0 or 1 for wildcarded podule */
130
131 if (cf->cf_loc[PODULEBUSCF_SLOT] == PODULEBUSCF_SLOT_DEFAULT)
132 return(config_match(parent, cf, aux));
133
134 /* Return higher priority if we match the specific podule */
135
136 else if (cf->cf_loc[PODULEBUSCF_SLOT] == pa->pa_podule_number)
137 return(config_match(parent, cf, aux) * 8);
138
139 /* Fail */
140 return(0);
141 }
142
143
144 #if 0
145 void
146 dump_podule(podule_t *podule)
147 {
148 printf("podule%d: ", podule->podulenum);
149 printf("flags0=%02x ", podule->flags0);
150 printf("flags1=%02x ", podule->flags1);
151 printf("reserved=%02x ", podule->reserved);
152 printf("product=%02x ", podule->product);
153 printf("manufacturer=%02x ", podule->manufacturer);
154 printf("country=%02x ", podule->country);
155 printf("irq_addr=%08x ", podule->irq_addr);
156 printf("irq_mask=%02x ", podule->irq_mask);
157 printf("fiq_addr=%08x ", podule->fiq_addr);
158 printf("fiq_mask=%02x ", podule->fiq_mask);
159 printf("fast_base=%08x ", podule->fast_base);
160 printf("medium_base=%08x ", podule->medium_base);
161 printf("slow_base=%08x ", podule->slow_base);
162 printf("sync_base=%08x ", podule->sync_base);
163 printf("mod_base=%08x ", podule->mod_base);
164 printf("easi_base=%08x ", podule->easi_base);
165 printf("attached=%d ", podule->attached);
166 printf("slottype=%d ", podule->slottype);
167 printf("podulenum=%d ", podule->podulenum);
168 printf("description=%s ", podule->description);
169 printf("\n");
170 }
171 #endif
172
173 void
174 podulechunkdirectory(podule_t *podule)
175 {
176 u_int address;
177 u_int id;
178 u_int size;
179 u_int addr;
180 int loop;
181 int done_f5;
182
183 done_f5 = 0;
184 address = 0x40;
185
186 do {
187 id = podule->read_rom(podule->sync_base, address);
188 size = podule->read_rom(podule->sync_base, address + 4);
189 size |= (podule->read_rom(podule->sync_base, address + 8) << 8);
190 size |= (podule->read_rom(podule->sync_base, address + 12) << 16);
191 if (id == 0xf5) {
192 addr = podule->read_rom(podule->sync_base, address + 16);
193 addr |= (podule->read_rom(podule->sync_base, address + 20) << 8);
194 addr |= (podule->read_rom(podule->sync_base, address + 24) << 16);
195 addr |= (podule->read_rom(podule->sync_base, address + 28) << 24);
196 if (addr < 0x800 && done_f5 == 0) {
197 done_f5 = 1;
198 for (loop = 0; loop < size; ++loop) {
199 if (loop < PODULE_DESCRIPTION_LENGTH) {
200 podule->description[loop] =
201 podule->read_rom(podule->sync_base, (addr + loop)*4);
202 podule->description[loop + 1] = 0;
203 }
204 }
205 }
206 }
207 #ifdef DEBUG_CHUNK_DIR
208 if (id == 0xf5 || id == 0xf1 || id == 0xf2 || id == 0xf3 || id == 0xf4 || id == 0xf6) {
209 addr = podule->read_rom(podule->sync_base, address + 16);
210 addr |= (podule->read_rom(podule->sync_base, address + 20) << 8);
211 addr |= (podule->read_rom(podule->sync_base, address + 24) << 16);
212 addr |= (podule->read_rom(podule->sync_base, address + 28) << 24);
213 printf("<%04x.%04x.%04x.%04x>", id, address, addr, size);
214 if (addr < 0x800) {
215 for (loop = 0; loop < size; ++loop) {
216 printf("%c", podule->read_rom(podule->sync_base, (addr + loop)*4));
217 }
218 printf("\\n\n");
219 }
220 }
221 #endif
222 address += 32;
223 } while (id != 0 && address < 0x800);
224 }
225
226
227 void
228 poduleexamine(podule_t *podule, device_t dev, int slottype)
229 {
230 struct manufacturer_description *man_desc;
231 struct podule_description *pod_desc;
232
233 /* Test to see if the podule is present */
234
235 if ((podule->flags0 & 0x02) == 0x00) {
236 podule->slottype = slottype;
237 if (slottype == SLOT_NET)
238 printf("netslot%d at %s : ", podule->podulenum - MAX_PODULES,
239 device_xname(dev));
240 else
241 printf("podule%d at %s : ", podule->podulenum,
242 device_xname(dev));
243
244 /* Is it Acorn conformant ? */
245
246 if (podule->flags0 & 0x80)
247 printf("Non-Acorn conformant expansion card\n");
248 else {
249 int id;
250
251 /* Is it a simple podule ? */
252
253 id = (podule->flags0 >> 3) & 0x0f;
254 if (id != 0)
255 printf("Simple expansion card <%x>\n", id);
256 else {
257 /* Scan the chunk directory if present for tags we use */
258 if (podule->flags1 & PODULE_FLAGS_CD)
259 podulechunkdirectory(podule);
260
261 /* Do we know this manufacturer ? */
262 man_desc = known_manufacturers;
263 while (man_desc->description) {
264 if (man_desc->manufacturer_id ==
265 podule->manufacturer)
266 break;
267 ++man_desc;
268 }
269 if (!man_desc->description)
270 printf("man=%04x : ", podule->manufacturer);
271 else
272 printf("%s : ", man_desc->description);
273
274 /* Do we know this product ? */
275
276 pod_desc = known_podules;
277 while (pod_desc->description) {
278 if (pod_desc->product_id == podule->product)
279 break;
280 ++pod_desc;
281 }
282 if (!pod_desc->description)
283 printf("prod=%04x : ",
284 podule->product);
285 else
286 printf("%s : ", pod_desc->description);
287 printf("%s\n", podule->description);
288 }
289 }
290 }
291 }
292
293
294 u_int
295 poduleread(u_int address, int offset)
296 {
297
298 return(ReadByte(address + offset));
299 }
300
301 void
302 podulescan(device_t dev)
303 {
304 int loop;
305 podule_t *podule;
306 u_char *address;
307 u_int offset = 0;
308
309 /* Loop round all the podules */
310
311 for (loop = 0; loop < MAX_PODULES; ++loop, offset += SIMPLE_PODULE_SIZE) {
312 podule = &podules[loop];
313 podule->podulenum = loop;
314 podule->attached = 0;
315 podule->slottype = SLOT_NONE;
316 podule->interrupt = IRQ_PODULE;
317 podule->read_rom = poduleread;
318 podule->dma_channel = -1;
319 podule->dma_interrupt = -1;
320 podule->description[0] = 0;
321
322 if (loop == 4) offset += PODULE_GAP;
323 address = ((u_char *)SYNC_PODULE_BASE) + offset;
324
325 if ((address[0] & 0x02) == 0x00) {
326 podule->fast_base = FAST_PODULE_BASE + offset;
327 podule->medium_base = MEDIUM_PODULE_BASE + offset;
328 podule->slow_base = SLOW_PODULE_BASE + offset;
329 podule->sync_base = SYNC_PODULE_BASE + offset;
330 podule->mod_base = MOD_PODULE_BASE + offset;
331 podule->easi_base = EASI_BASE + loop * EASI_SIZE;
332 } else {
333 address = ((u_char *)EASI_BASE) + loop * EASI_SIZE;
334 if ((address[0] & 0x02) != 0x00)
335 continue;
336
337 podule->fast_base = 0;
338 podule->medium_base = 0;
339 podule->slow_base = 0;
340 podule->sync_base = 0;
341 podule->mod_base = 0;
342 podule->easi_base = EASI_BASE + loop * EASI_SIZE;
343 }
344
345 /* XXX - Really needs to be linked to a DMA manager */
346 if (IOMD_ID == RPC600_IOMD_ID) {
347 switch (loop) {
348 case 0:
349 podule->dma_channel = 2;
350 podule->dma_interrupt = IRQ_DMACH2;
351 break;
352 case 1:
353 podule->dma_channel = 3;
354 podule->dma_interrupt = IRQ_DMACH3;
355 break;
356 }
357 }
358
359 /* Get information from the podule header */
360
361 podule->flags0 = address[0];
362 if ((podule->flags0 & 0x78) == 0) {
363 podule->flags1 = address[4];
364 podule->reserved = address[8];
365 podule->product = address[12] + (address[16] << 8);
366 podule->manufacturer = address[20] + (address[24] << 8);
367 podule->country = address[28];
368 if (podule->flags1 & PODULE_FLAGS_IS) {
369 podule->irq_addr = address[52] + (address[56] << 8) + (address[60] << 16);
370 podule->irq_addr += podule->slow_base;
371 podule->irq_mask = address[48];
372 if (podule->irq_mask == 0)
373 podule->irq_mask = 0x01;
374 podule->fiq_addr = address[36] + (address[40] << 8) + (address[44] << 16);
375 podule->fiq_addr += podule->slow_base;
376 podule->fiq_mask = address[32];
377 if (podule->fiq_mask == 0)
378 podule->fiq_mask = 0x04;
379 } else {
380 podule->irq_addr = podule->slow_base;
381 podule->irq_mask = 0x01;
382 podule->fiq_addr = podule->slow_base;
383 podule->fiq_mask = 0x04;
384 }
385 }
386
387 poduleexamine(podule, dev, SLOT_POD);
388 }
389 }
390
391
392 /*
393 * void podulebusattach(device_t parent, device_t dev, void *aux)
394 *
395 * Attach podulebus.
396 * This probes all the podules and sets up the podules array with
397 * information found in the podule headers.
398 * After identifing all the podules, all the children of the podulebus
399 * are probed and attached.
400 */
401
402 void
403 podulebusattach(device_t parent, device_t self, void *aux)
404 {
405 int loop;
406 struct podule_attach_args pa;
407 #if 0
408 int easi_time;
409 int bit;
410 #endif
411 unsigned int value;
412 char argstring[20];
413
414 #if 0
415 easi_time = IOMD_READ_BYTE(IOMD_ECTCR);
416 printf(": easi timings=");
417 for (bit = 0x01; bit < 0x100; bit = bit << 1)
418 if (easi_time & bit)
419 printf("C");
420 else
421 printf("A");
422 #endif
423 printf("\n");
424
425
426 #if 0 /* XXXJRT */
427 /* Ok we need to map in the podulebus */
428 /* with the new pmap mappings have to be done when the L1 tables
429 * are built during initarm
430 */
431 /* Map the FAST and SYNC simple podules */
432 pmap_map_section((vaddr_t)pmap_kernel()->pm_pdir,
433 SYNC_PODULE_BASE & 0xfff00000, SYNC_PODULE_HW_BASE & 0xfff00000,
434 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
435 cpu_tlb_flushD();
436 /* Now map the EASI space */
437
438 for (loop = 0; loop < MAX_PODULES; ++loop) {
439 int loop1;
440
441 for (loop1 = loop * EASI_SIZE; loop1 < ((loop + 1) * EASI_SIZE);
442 loop1 += L1_S_SIZE)
443 pmap_map_section((vaddr_t)pmap_kernel()->pm_pdir,
444 EASI_BASE + loop1, EASI_HW_BASE + loop1,
445 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
446 }
447 cpu_tlb_flushD();
448 #endif
449 /*
450 * The MEDIUM and SLOW simple podules and the module space will have been
451 * mapped when the IOMD and COMBO we mapped in for the RPC
452 */
453
454 /* Find out what hardware is bolted on */
455
456 podulescan(self);
457 netslotscan(self);
458
459 /* Look for drivers to attach */
460
461 for (loop = 0; loop < MAX_PODULES+MAX_NETSLOTS; ++loop) {
462 #if 1
463 /* Provide backwards compat for a while */
464 snprintf(argstring, sizeof(argstring), "podule%d.disable", loop);
465 if (get_bootconf_option(boot_args, argstring,
466 BOOTOPT_TYPE_BOOLEAN, &value)) {
467 if (value) {
468 if (podules[loop].slottype != SLOT_NONE)
469 printf("podule%d: Disabled\n", loop);
470 continue;
471 }
472 }
473 #endif
474 snprintf(argstring, sizeof(argstring), "podule%d=", loop);
475 if (get_bootconf_option(boot_args, argstring,
476 BOOTOPT_TYPE_HEXINT, &value)) {
477 /* Override the ID */
478 podules[loop].manufacturer = value >> 16;
479 podules[loop].product = value & 0xffff;
480 /* Any old description is now wrong */
481 podules[loop].description[0] = 0;
482 if (value != 0xffff) {
483 printf("podule%d: ID overriden man=%04x prod=%04x\n",
484 loop, podules[loop].manufacturer,
485 podules[loop].product);
486 podules[loop].slottype = SLOT_POD;
487 pa.pa_podule_number = loop;
488 pa.pa_ih = pa.pa_podule_number;
489 pa.pa_podule = &podules[loop];
490 pa.pa_iot = &podulebus_bs_tag;
491 config_found_sm_loc(self, "podulebus", NULL, &pa,
492 podulebusprint, podulebussubmatch);
493 continue;
494 }
495 if (value == 0xffff) {
496 printf("podule%d: Disabled\n", loop);
497 continue;
498 }
499 }
500
501 if (podules[loop].slottype != SLOT_NONE) {
502 pa.pa_podule_number = loop;
503 pa.pa_ih = pa.pa_podule_number;
504 pa.pa_podule = &podules[loop];
505 pa.pa_iot = &podulebus_bs_tag;
506 config_found_sm_loc(self, "podulebus", NULL, &pa,
507 podulebusprint, podulebussubmatch);
508 }
509 }
510 }
511
512
513 CFATTACH_DECL_NEW(podulebus, 0,
514 podulebusmatch, podulebusattach, NULL, NULL);
515
516 /* Useful functions that drivers may share */
517
518 /*
519 * Match a podule structure with the specified parameters
520 * Returns 0 if the match failed
521 * The required_slot is not used at the moment.
522 */
523
524 int
525 matchpodule(struct podule_attach_args *pa, int manufacturer, int product, int required_slot)
526 {
527 if (pa->pa_podule->attached)
528 panic("podulebus: Podule already attached");
529
530 if (IS_PODULE(pa, manufacturer, product))
531 return(1);
532
533 return(0);
534 }
535
536 void *
537 podulebus_irq_establish(podulebus_intr_handle_t ih,
538 int ipl, int (*func)(void *), void *arg, struct evcnt *ev)
539 {
540
541 /* XXX We don't actually use the evcnt supplied, just its name. */
542 return intr_claim(podules[ih].interrupt, ipl, ev->ev_group, func,
543 arg);
544 }
545
546 /*
547 * Generate a bus_space_tag_t with the specified address-bus shift.
548 */
549 void
550 podulebus_shift_tag(bus_space_tag_t tag, u_int shift, bus_space_tag_t *tagp)
551 {
552
553 /*
554 * For the podulebus, the bus tag cookie is the shift to apply
555 * to registers, so duplicate the bus space tag and change the
556 * cookie.
557 */
558
559 /* XXX never freed, but podules are never detached anyway. */
560 *tagp = malloc(sizeof(struct bus_space), M_DEVBUF, M_WAITOK);
561 **tagp = *tag;
562 (*tagp)->bs_cookie = (void *)shift;
563 }
564
565 int
566 podulebus_initloader(struct podulebus_attach_args *pa)
567 {
568
569 /* No loader support at present on arm32, so always fail. */
570 return -1;
571 }
572
573 int
574 podloader_readbyte(struct podulebus_attach_args *pa, u_int addr)
575 {
576
577 panic("podloader_readbyte");
578 }
579
580 void
581 podloader_writebyte(struct podulebus_attach_args *pa, u_int addr, int val)
582 {
583
584 panic("podloader_writebyte");
585 }
586
587 void
588 podloader_reset(struct podulebus_attach_args *pa)
589 {
590
591 panic("podloader_reset");
592 }
593
594 int
595 podloader_callloader(struct podulebus_attach_args *pa, u_int r0, u_int r1)
596 {
597
598 panic("podloader_callloader");
599 }
600
601 /* End of podulebus.c */
602