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