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