rbus_ppb.c revision 1.24 1 /* $NetBSD: rbus_ppb.c,v 1.24 2008/07/09 16:27:12 joerg Exp $ */
2
3 /*
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Michael Richardson <mcr (at) sandelman.ottawa.on.ca>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * CardBus front-end for the Intel/Digital DECchip 21152 PCI-PCI bridge
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: rbus_ppb.c,v 1.24 2008/07/09 16:27:12 joerg Exp $");
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/mbuf.h>
42 #include <sys/malloc.h>
43 #include <sys/kernel.h>
44 #include <sys/socket.h>
45 #include <sys/ioctl.h>
46 #include <sys/errno.h>
47 #include <sys/device.h>
48
49 #if NRND > 0
50 #include <sys/rnd.h>
51 #endif
52
53 #include <machine/endian.h>
54
55 #include <sys/bus.h>
56 #include <sys/intr.h>
57
58 #include <dev/pci/pcivar.h>
59 #include <dev/pci/pcireg.h>
60 #include <dev/pci/pcidevs.h>
61 #include <dev/pci/ppbreg.h>
62
63 #include <dev/ic/i82365reg.h>
64 #include <dev/ic/i82365var.h>
65
66 #include <dev/pci/pccbbreg.h>
67 #include <dev/pci/pccbbvar.h>
68
69 #include <dev/cardbus/cardbusvar.h>
70 #include <dev/pci/pcidevs.h>
71
72 #include <x86/pci/pci_addr_fixup.h>
73 #include <x86/pci/pci_bus_fixup.h>
74 #include <i386/pci/pci_intr_fixup.h>
75 #include <i386/pci/pcibios.h>
76
77 struct ppb_softc;
78
79 static int ppb_cardbus_match(struct device *, struct cfdata *, void *);
80 static void ppb_cardbus_attach(struct device *, struct device *, void *);
81 static int ppb_cardbus_detach(struct device * self, int flags);
82 /*static*/ void ppb_cardbus_setup(struct ppb_softc * sc);
83 /*static*/ int ppb_cardbus_enable(struct ppb_softc * sc);
84 /*static*/ void ppb_cardbus_disable(struct ppb_softc * sc);
85 static int ppb_activate(struct device *, enum devact);
86 int rppbprint(void *, const char *);
87 int rbus_intr_fixup(pci_chipset_tag_t, int, int, int);
88 void rbus_do_header_fixup(pci_chipset_tag_t, pcitag_t, void *);
89
90 static void rbus_pci_phys_allocate(pci_chipset_tag_t, pcitag_t, void *);
91
92 static int rbus_do_phys_allocate(pci_chipset_tag_t, pcitag_t, int,
93 void *, int, bus_addr_t *, bus_size_t);
94
95 static void rbus_pci_phys_countspace(pci_chipset_tag_t, pcitag_t, void *);
96
97 static int rbus_do_phys_countspace(pci_chipset_tag_t, pcitag_t, int,
98 void *, int, bus_addr_t *, bus_size_t);
99
100 unsigned int rbus_round_up(unsigned int, unsigned int);
101
102
103 struct ppb_cardbus_softc {
104 struct device sc_dev;
105 pcitag_t sc_tag;
106 int foo;
107 };
108
109 CFATTACH_DECL(rbus_ppb, sizeof(struct ppb_cardbus_softc),
110 ppb_cardbus_match, ppb_cardbus_attach, ppb_cardbus_detach, ppb_activate);
111
112 #ifdef CBB_DEBUG
113 int rbus_ppb_debug = 0; /* hack with kdb */
114 #define DPRINTF(X) if(rbus_ppb_debug) printf X
115 #else
116 #define DPRINTF(X)
117 #endif
118
119 static int
120 ppb_cardbus_match(parent, match, aux)
121 struct device *parent;
122 struct cfdata *match;
123 void *aux;
124 {
125 struct cardbus_attach_args *ca = aux;
126
127 if (CARDBUS_VENDOR(ca->ca_id) == PCI_VENDOR_DEC &&
128 CARDBUS_PRODUCT(ca->ca_id) == PCI_PRODUCT_DEC_21152)
129 return (1);
130
131 if(PCI_CLASS(ca->ca_class) == PCI_CLASS_BRIDGE &&
132 PCI_SUBCLASS(ca->ca_class) == PCI_SUBCLASS_BRIDGE_PCI) {
133 /* XXX */
134 printf("recognizing generic bridge chip\n");
135 }
136
137 return (0);
138 }
139
140
141 int
142 rppbprint(aux, pnp)
143 void *aux;
144 const char *pnp;
145 {
146 struct pcibus_attach_args *pba = aux;
147
148 /* only PCIs can attach to PPBs; easy. */
149 if (pnp)
150 aprint_normal("pci at %s", pnp);
151 aprint_normal(" bus %d (rbus)", pba->pba_bus);
152 return (UNCONF);
153 }
154
155 int
156 rbus_intr_fixup(pci_chipset_tag_t pc,
157 int minbus,
158 int maxbus,
159 int line)
160 {
161 pci_device_foreach_min(pc, minbus,
162 maxbus, rbus_do_header_fixup, (void *)&line);
163 return 0;
164 }
165
166 void
167 rbus_do_header_fixup(pc, tag, context)
168 pci_chipset_tag_t pc;
169 pcitag_t tag;
170 void *context;
171 {
172 int pin, irq;
173 int bus, device, function;
174 pcireg_t intr, id;
175 int *pline = (int *)context;
176 int line = *pline;
177
178 pci_decompose_tag(pc, tag, &bus, &device, &function);
179 id = pci_conf_read(pc, tag, PCI_ID_REG);
180
181 intr = pci_conf_read(pc, tag, PCI_INTERRUPT_REG);
182 pin = PCI_INTERRUPT_PIN(intr);
183 irq = PCI_INTERRUPT_LINE(intr);
184
185 #if 0
186 printf("do_header %02x:%02x:%02x pin=%d => line %d\n",
187 bus, device, function, pin, line);
188 #endif
189
190 intr &= ~(PCI_INTERRUPT_LINE_MASK << PCI_INTERRUPT_LINE_SHIFT);
191 intr |= (line << PCI_INTERRUPT_LINE_SHIFT);
192 pci_conf_write(pc, tag, PCI_INTERRUPT_REG, intr);
193
194 }
195
196 /*
197 * This function takes a range of PCI bus numbers and
198 * allocates space for all devices found in this space (the BARs) from
199 * the rbus space maps (I/O and memory).
200 *
201 * It assumes that "rbus" is defined. The whole concept does.
202 *
203 * It uses pci_device_foreach_min() to call rbus_pci_phys_allocate.
204 * This function is mostly stolen from
205 * pci_addr_fixup.c:pciaddr_resource_reserve.
206 *
207 */
208 struct rbus_pci_addr_fixup_context {
209 struct ppb_cardbus_softc *csc;
210 cardbus_chipset_tag_t ct;
211 struct cardbus_softc *sc;
212 struct cardbus_attach_args *caa;
213 int minbus;
214 int maxbus;
215 bus_size_t *bussize_ioreqs;
216 bus_size_t *bussize_memreqs;
217 rbus_tag_t *iobustags;
218 rbus_tag_t *membustags;
219 };
220
221 unsigned int
222 rbus_round_up(unsigned int size, unsigned int minval)
223 {
224 unsigned int power2;
225
226 if(size == 0) {
227 return 0;
228 }
229
230 power2=minval;
231
232 while(power2 < (1 << 31) &&
233 power2 < size) {
234 power2 = power2 << 1;
235 }
236
237 return power2;
238 }
239
240 static void
241 rbus_pci_addr_fixup(struct ppb_cardbus_softc *csc,
242 cardbus_chipset_tag_t ct,
243 struct cardbus_softc *sc,
244 pci_chipset_tag_t pc,
245 struct cardbus_attach_args *caa,
246 int minbus, int maxbus)
247 {
248 struct rbus_pci_addr_fixup_context rct;
249 int size, busnum;
250 bus_addr_t start;
251 bus_space_handle_t handle;
252 u_int32_t reg;
253
254 rct.csc=csc;
255 rct.ct=ct;
256 rct.sc=sc;
257 rct.caa=caa;
258 rct.minbus = minbus;
259 rct.maxbus = maxbus;
260 size = sizeof(bus_size_t)*(maxbus+1);
261 rct.bussize_ioreqs = alloca(size);
262 rct.bussize_memreqs = alloca(size);
263 rct.iobustags = alloca(maxbus * sizeof(rbus_tag_t));
264 rct.membustags = alloca(maxbus * sizeof(rbus_tag_t));
265
266 bzero(rct.bussize_ioreqs, size);
267 bzero(rct.bussize_memreqs, size);
268
269 printf("%s: sizing buses %d-%d\n",
270 device_xname(&rct.csc->sc_dev),
271 minbus, maxbus);
272
273 pci_device_foreach_min(pc, minbus, maxbus,
274 rbus_pci_phys_countspace, &rct);
275
276 /*
277 * we need to determine amount of address space for each
278 * bus. To do this, we have to roll up amounts and then
279 * we need to divide up the cardbus's extent to allocate
280 * some space to each bus.
281 */
282
283 for(busnum=maxbus; busnum > minbus; busnum--) {
284 if(pci_bus_parent[busnum] != 0) {
285 if(pci_bus_parent[busnum] < minbus ||
286 pci_bus_parent[busnum] >= maxbus) {
287 printf("%s: bus %d has illegal parent %d\n",
288 device_xname(&rct.csc->sc_dev),
289 busnum, pci_bus_parent[busnum]);
290 continue;
291 }
292
293 /* first round amount of space up */
294 rct.bussize_ioreqs[busnum] =
295 rbus_round_up(rct.bussize_ioreqs[busnum], PPB_IO_MIN);
296 rct.bussize_ioreqs[pci_bus_parent[busnum]] +=
297 rct.bussize_ioreqs[busnum];
298
299 rct.bussize_memreqs[busnum] =
300 rbus_round_up(rct.bussize_memreqs[busnum], PPB_MEM_MIN);
301 rct.bussize_memreqs[pci_bus_parent[busnum]] +=
302 rct.bussize_memreqs[busnum];
303
304 }
305 }
306
307 rct.bussize_ioreqs[minbus] =
308 rbus_round_up(rct.bussize_ioreqs[minbus], 4096);
309 rct.bussize_memreqs[minbus] =
310 rbus_round_up(rct.bussize_memreqs[minbus], 8);
311
312 printf("%s: total needs IO %08lx and MEM %08lx\n",
313 device_xname(&rct.csc->sc_dev),
314 rct.bussize_ioreqs[minbus], rct.bussize_memreqs[minbus]);
315
316 if(!caa->ca_rbus_iot) {
317 panic("no iot bus");
318 }
319
320 if(rct.bussize_ioreqs[minbus]) {
321 if(rbus_space_alloc(caa->ca_rbus_iot, 0,
322 rct.bussize_ioreqs[minbus],
323 rct.bussize_ioreqs[minbus]-1 /* mask */,
324 rct.bussize_ioreqs[minbus] /* align */,
325 /* flags */ 0,
326 &start,
327 &handle) != 0) {
328 panic("rbus_ppb: can not allocate %ld bytes in IO bus %d",
329 rct.bussize_ioreqs[minbus], minbus);
330 }
331 rct.iobustags[minbus]=rbus_new(caa->ca_rbus_iot,
332 start,
333 rct.bussize_ioreqs[minbus],
334 0 /* offset to add to physical address
335 to make processor address */,
336 RBUS_SPACE_DEDICATE);
337 }
338
339 if(rct.bussize_memreqs[minbus]) {
340 if(rbus_space_alloc(caa->ca_rbus_memt, 0,
341 rct.bussize_memreqs[minbus],
342 rct.bussize_memreqs[minbus]-1 /* mask */,
343 rct.bussize_memreqs[minbus] /* align */,
344 /* flags */ 0,
345 &start,
346 &handle) != 0) {
347 panic("%s: can not allocate %ld bytes in MEM bus %d",
348 device_xname(&rct.csc->sc_dev),
349 rct.bussize_memreqs[minbus], minbus);
350 }
351 rct.membustags[minbus]=rbus_new(caa->ca_rbus_memt,
352 start,
353 rct.bussize_memreqs[minbus],
354 0 /* offset to add to physical
355 address to make processor
356 address */,
357 RBUS_SPACE_DEDICATE);
358 }
359
360 for(busnum=minbus+1; busnum <= maxbus; busnum++) {
361 int busparent;
362
363 busparent = pci_bus_parent[busnum];
364
365 printf("%s: bus %d (parent=%d) needs IO %08lx and MEM %08lx\n",
366 device_xname(&rct.csc->sc_dev),
367 busnum,
368 busparent,
369 rct.bussize_ioreqs[busnum],
370 rct.bussize_memreqs[busnum]);
371
372 if(busparent > maxbus) {
373 panic("rbus_ppb: illegal parent");
374 }
375
376 if(rct.bussize_ioreqs[busnum]) {
377 if(rbus_space_alloc(rct.iobustags[busparent],
378 0,
379 rct.bussize_ioreqs[busnum],
380 rct.bussize_ioreqs[busnum]-1 /*mask */,
381 rct.bussize_ioreqs[busnum] /* align */,
382 /* flags */ 0,
383 &start,
384 &handle) != 0) {
385 panic("rbus_ppb: can not allocate %ld bytes in IO bus %d",
386 rct.bussize_ioreqs[busnum], busnum);
387 }
388 rct.iobustags[busnum]=rbus_new(rct.iobustags[busparent],
389 start,
390 rct.bussize_ioreqs[busnum],
391 0 /* offset to add to physical
392 address
393 to make processor address */,
394 RBUS_SPACE_DEDICATE);
395
396 /* program the bridge */
397
398 /* enable I/O space */
399 reg = pci_conf_read(pc, pci_bus_tag[busnum],
400 PCI_COMMAND_STATUS_REG);
401 reg |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MASTER_ENABLE;
402 pci_conf_write(pc, pci_bus_tag[busnum],
403 PCI_COMMAND_STATUS_REG, reg);
404
405 /* now init the limit register for I/O */
406 pci_conf_write(pc, pci_bus_tag[busnum], PPB_REG_IOSTATUS,
407 (((start & 0xf000) >> 8) << PPB_IOBASE_SHIFT) |
408 ((((start +
409 rct.bussize_ioreqs[busnum] +
410 4095) & 0xf000) >> 8) << PPB_IOLIMIT_SHIFT));
411 }
412
413 if(rct.bussize_memreqs[busnum]) {
414 if(rbus_space_alloc(rct.membustags[busparent],
415 0,
416 rct.bussize_memreqs[busnum] /* size */,
417 rct.bussize_memreqs[busnum]-1 /*mask */,
418 rct.bussize_memreqs[busnum] /* align */,
419 /* flags */ 0,
420 &start,
421 &handle) != 0) {
422 panic("rbus_ppb: can not allocate %ld bytes in MEM bus %d",
423 rct.bussize_memreqs[busnum], busnum);
424 }
425 rct.membustags[busnum]=rbus_new(rct.membustags[busparent],
426 start,
427 rct.bussize_memreqs[busnum],
428 0 /* offset to add to physical
429 address to make processor
430 address */,
431 RBUS_SPACE_DEDICATE);
432
433 /* program the bridge */
434 /* enable memory space */
435 reg = pci_conf_read(pc, pci_bus_tag[busnum],
436 PCI_COMMAND_STATUS_REG);
437 reg |= PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE;
438 pci_conf_write(pc, pci_bus_tag[busnum],
439 PCI_COMMAND_STATUS_REG, reg);
440
441 /* now init the limit register for memory */
442 pci_conf_write(pc, pci_bus_tag[busnum], PPB_REG_MEM,
443 ((start & PPB_MEM_MASK)
444 >> PPB_MEM_SHIFT) << PPB_MEMBASE_SHIFT |
445 (((start +
446 rct.bussize_memreqs[busnum] +
447 PPB_MEM_MIN-1) >> PPB_MEM_SHIFT)
448 << PPB_MEMLIMIT_SHIFT));
449
450 /* and set the prefetchable limits as well */
451 pci_conf_write(pc, pci_bus_tag[busnum], PPB_REG_PREFMEM,
452 ((start & PPB_MEM_MASK)
453 >> PPB_MEM_SHIFT) << PPB_MEMBASE_SHIFT |
454 (((start +
455 rct.bussize_memreqs[busnum] +
456 PPB_MEM_MIN-1) >> PPB_MEM_SHIFT)
457 << PPB_MEMLIMIT_SHIFT));
458
459 /* pci_conf_print(pc, pci_bus_tag[busnum], NULL); */
460 }
461 }
462
463 printf("%s: configuring buses %d-%d\n",
464 device_xname(&rct.csc->sc_dev),
465 minbus, maxbus);
466 pci_device_foreach_min(pc, minbus, maxbus,
467 rbus_pci_phys_allocate, &rct);
468 }
469
470 static void
471 rbus_pci_phys_countspace(pc, tag, context)
472 pci_chipset_tag_t pc;
473 pcitag_t tag;
474 void *context;
475 {
476 int bus, device, function;
477 struct rbus_pci_addr_fixup_context *rct =
478 (struct rbus_pci_addr_fixup_context *)context;
479
480 pci_decompose_tag(pc, tag, &bus, &device, &function);
481
482 printf("%s: configuring device %02x:%02x:%02x\n",
483 device_xname(&rct->csc->sc_dev),
484 bus, device, function);
485
486 pciaddr_resource_manage(pc, tag,
487 rbus_do_phys_countspace, context);
488 }
489
490
491 int
492 rbus_do_phys_countspace(pc, tag, mapreg, ctx, type, addr, size)
493 pci_chipset_tag_t pc;
494 pcitag_t tag;
495 void *ctx;
496 int mapreg, type;
497 bus_addr_t *addr;
498 bus_size_t size;
499 {
500 struct rbus_pci_addr_fixup_context *rct =
501 (struct rbus_pci_addr_fixup_context *)ctx;
502 int bus, device, function;
503
504 pci_decompose_tag(pc, tag, &bus, &device, &function);
505
506 if(size > (1<<24)) {
507 printf("%s: skipping huge space request of size=%08x\n",
508 device_xname(&rct->csc->sc_dev), (unsigned int)size);
509 return 0;
510 }
511
512 if(PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_IO) {
513 rct->bussize_ioreqs[bus] += size;
514 } else {
515 rct->bussize_memreqs[bus]+= size;
516 }
517
518 return 0;
519 }
520
521 static void
522 rbus_pci_phys_allocate(pc, tag, context)
523 pci_chipset_tag_t pc;
524 pcitag_t tag;
525 void *context;
526 {
527 int bus, device, function, command;
528 struct rbus_pci_addr_fixup_context *rct =
529 (struct rbus_pci_addr_fixup_context *)context;
530 //cardbus_chipset_tag_t ct = rct->ct;
531 // struct cardbus_softc *sc = rct->sc;
532
533 pci_decompose_tag(pc, tag, &bus, &device, &function);
534
535 printf("%s: configuring device %02x:%02x:%02x\n",
536 device_xname(&rct->csc->sc_dev),
537 bus, device, function);
538
539 pciaddr_resource_manage(pc, tag,
540 rbus_do_phys_allocate, context);
541
542 /* now turn the device's memory and I/O on */
543 command = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
544 command |= PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE;
545 pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, command);
546 }
547
548 int
549 rbus_do_phys_allocate(pc, tag, mapreg, ctx, type, addr, size)
550 pci_chipset_tag_t pc;
551 pcitag_t tag;
552 void *ctx;
553 int mapreg, type;
554 bus_addr_t *addr;
555 bus_size_t size;
556 {
557 struct rbus_pci_addr_fixup_context *rct =
558 (struct rbus_pci_addr_fixup_context *)ctx;
559 cardbus_chipset_tag_t ct = rct->ct;
560 struct cardbus_softc *sc = rct->sc;
561 cardbus_function_t *cf = sc->sc_cf;
562 rbus_tag_t rbustag;
563 bus_space_tag_t bustag;
564 bus_addr_t mask = size -1;
565 bus_addr_t base = 0;
566 bus_space_handle_t handle;
567 int busflags = 0;
568 int flags = 0;
569 const char *bustype;
570 int bus, device, function;
571
572 pci_decompose_tag(pc, tag, &bus, &device, &function);
573
574 /*
575 * some devices come up with garbage in them (Tulip?)
576 * we are in charge here, so give them address
577 * space anyway.
578 *
579 * XXX this may be due to no secondary PCI reset!!!
580 */
581 #if 0
582 if (*addr) {
583 printf("Already allocated space at %08x\n",
584 (unsigned int)*addr);
585 return (0);
586 }
587 #endif
588
589 if(size > (1<<24)) {
590 printf("%s: skipping huge space request of size=%08x\n",
591 device_xname(&rct->csc->sc_dev), (unsigned int)size);
592 return 0;
593 }
594
595 if(PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_IO) {
596 bustag = sc->sc_iot;
597 rbustag = rct->iobustags[bus];
598 bustype = "io";
599 } else {
600 bustag = sc->sc_memt;
601 rbustag = rct->membustags[bus];
602 bustype = "mem";
603 }
604
605 if((*cf->cardbus_space_alloc)(ct, rbustag, base, size,
606 mask, size, busflags|flags,
607 addr, &handle)) {
608 printf("%s: no available resources (size=%08x) for bar %2d. fixup failed\n",
609 device_xname(&rct->csc->sc_dev), (unsigned int)size, mapreg);
610
611 *addr = 0;
612 pci_conf_write(pc, tag, mapreg, *addr);
613 return (1);
614 }
615
616 printf("%s: alloc %s space of size %08x for %02d:%02d:%02d -> %08x\n",
617 device_xname(&rct->csc->sc_dev),
618 bustype,
619 (unsigned int)size,
620 bus, device, function, (unsigned int)*addr);
621
622 /* write new address to PCI device configuration header */
623 pci_conf_write(pc, tag, mapreg, *addr);
624
625 /* check */
626 {
627 DPRINTF(("%s: pci_addr_fixup: ",
628 device_xname(&rct->csc->sc_dev)));
629 #ifdef CBB_DEBUG
630 if(rbus_ppb_debug) { pciaddr_print_devid(pc, tag); }
631 #endif
632 }
633
634 /* double check that the value got inserted correctly */
635 if (pciaddr_ioaddr(pci_conf_read(pc, tag, mapreg)) != *addr) {
636 pci_conf_write(pc, tag, mapreg, 0); /* clear */
637 printf("%s: fixup failed. (new address=%#x)\n",
638 device_xname(&rct->csc->sc_dev),
639 (unsigned)*addr);
640 return (1);
641 }
642
643 DPRINTF(("new address 0x%08x\n",
644 (unsigned)*addr));
645
646 return (0);
647 }
648
649 static void
650 ppb_cardbus_attach(device_t parent, device_t self, void aux)
651 {
652 struct ppb_cardbus_softc *csc = device_private(self);
653 struct cardbus_softc *parent_sc = device_private(parent);
654 struct cardbus_attach_args *ca = aux;
655 cardbus_devfunc_t ct = ca->ca_ct;
656 cardbus_chipset_tag_t cc = ct->ct_cc;
657 cardbus_function_tag_t cf = ct->ct_cf;
658 struct pccbb_softc *psc = (struct pccbb_softc *)cc;
659 struct pcibus_attach_args pba;
660 char devinfo[256];
661 pcireg_t busdata;
662 int mybus, rv;
663 u_int16_t pciirq;
664 int minbus, maxbus;
665
666 mybus = ct->ct_bus;
667 pciirq = 0;
668 rv = 0;
669
670 /* shut up compiler */
671 csc->foo = parent_sc->sc_intrline;
672
673
674 pci_devinfo(ca->ca_id, ca->ca_class, 0, devinfo, sizeof(devinfo));
675 printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(ca->ca_class));
676
677 csc->sc_tag = ca->ca_tag; /* XXX cardbustag_t == pcitag_t */
678
679 busdata = cardbus_conf_read(cc, cf, ca->ca_tag, PPB_REG_BUSINFO);
680 minbus = pcibios_max_bus;
681 maxbus = minbus; /* XXX; gcc */
682
683 if (PPB_BUSINFO_SECONDARY(busdata) == 0) {
684 aprint_error_dev(self, "not configured by system firmware calling pci_bus_fixup(%d)\n", 0);
685
686 /*
687 * first, pull the reset wire on the secondary bridge
688 * to clear all devices
689 */
690 busdata = cardbus_conf_read(cc, cf, ca->ca_tag,
691 PPB_REG_BRIDGECONTROL);
692 cardbus_conf_write(cc, cf, ca->ca_tag, PPB_REG_BRIDGECONTROL,
693 busdata | PPB_BC_SECONDARY_RESET);
694 delay(1);
695 cardbus_conf_write(cc, cf, ca->ca_tag, PPB_REG_BRIDGECONTROL,
696 busdata);
697
698 /* then go initialize the bridge control registers */
699 maxbus = pci_bus_fixup(psc->sc_pc, 0);
700 }
701
702 busdata = cardbus_conf_read(cc, cf, ca->ca_tag, PPB_REG_BUSINFO);
703 if(PPB_BUSINFO_SECONDARY(busdata) == 0) {
704 aprint_error_dev(self, "still not configured, not fixable.\n");
705 return;
706 }
707
708 #if 0
709 minbus = PPB_BUSINFO_SECONDARY(busdata);
710 maxbus = PPB_BUSINFO_SUBORDINATE(busdata);
711 #endif
712
713 /* now, go and assign addresses for the new devices */
714 rbus_pci_addr_fixup(csc, cc, parent_sc,
715 psc->sc_pc,
716 ca,
717 minbus, maxbus);
718
719 /*
720 * now configure all connected devices to the IRQ which
721 * was assigned to this slot, as they will all arrive from
722 * that IRQ.
723 */
724 rbus_intr_fixup(psc->sc_pc, minbus, maxbus, ca->ca_intrline);
725
726 /*
727 * enable direct routing of interrupts. We do this because
728 * we can not manage to get pccb_intr_establish() called until
729 * PCI subsystem is merged with rbus. The major thing that this
730 * routine does is avoid calling the driver's interrupt routine
731 * when the card has been removed.
732 *
733 * The rbus_ppb.c can not cope with card desertions until the merging
734 * anyway.
735 */
736 pccbb_intr_route(psc);
737
738 /*
739 * Attach the PCI bus than hangs off of it.
740 *
741 * XXX Don't pass-through Memory Read Multiple. Should we?
742 * XXX Consult the spec...
743 */
744 pba.pba_iot = ca->ca_iot;
745 pba.pba_memt = ca->ca_memt;
746 pba.pba_dmat = ca->ca_dmat;
747 pba.pba_pc = psc->sc_pc;
748 pba.pba_flags = PCI_FLAGS_IO_ENABLED|PCI_FLAGS_MEM_ENABLED;
749 pba.pba_bus = PPB_BUSINFO_SECONDARY(busdata);
750 pba.pba_bridgetag = &csc->sc_tag;
751 /*pba.pba_intrswiz = parent_sc->sc_intrswiz; */
752 pba.pba_intrtag = psc->sc_pa.pa_intrtag;
753
754 config_found_ia(self, "pcibus", &pba, rppbprint);
755 }
756
757 void
758 ppb_cardbus_setup(struct ppb_softc * sc)
759 {
760 struct ppb_cardbus_softc *csc = (struct ppb_cardbus_softc *) sc;
761 #if 0
762 cardbus_chipset_tag_t cc = psc->sc_cc;
763 cardbus_function_tag_t cf = psc->sc_cf;
764 #endif
765
766 /* shut up compiler */
767 csc->foo=2;
768
769 printf("ppb_cardbus_setup called\n");
770 #if 0
771 /* not sure what to do here */
772 cardbustag_t tag = cardbus_make_tag(cc, cf, csc->ct->ct_bus,
773 csc->ct->ct_dev, csc->ct->ct_func);
774
775 command = Cardbus_conf_read(csc->ct, tag, CARDBUS_COMMAND_STATUS_REG);
776 if (csc->base0_reg) {
777 Cardbus_conf_write(csc->ct, tag,
778 CARDBUS_BASE0_REG, csc->base0_reg);
779 (cf->cardbus_ctrl) (cc, CARDBUS_MEM_ENABLE);
780 command |= CARDBUS_COMMAND_MEM_ENABLE |
781 CARDBUS_COMMAND_MASTER_ENABLE;
782 } else if (csc->base1_reg) {
783 Cardbus_conf_write(csc->ct, tag,
784 CARDBUS_BASE1_REG, csc->base1_reg);
785 (cf->cardbus_ctrl) (cc, CARDBUS_IO_ENABLE);
786 command |= (CARDBUS_COMMAND_IO_ENABLE |
787 CARDBUS_COMMAND_MASTER_ENABLE);
788 }
789
790 (cf->cardbus_ctrl) (cc, CARDBUS_BM_ENABLE);
791
792 /* enable the card */
793 Cardbus_conf_write(csc->ct, tag, CARDBUS_COMMAND_STATUS_REG, command);
794 #endif
795 }
796
797 int
798 ppb_cardbus_enable(struct ppb_softc * sc)
799 {
800 #if 0
801 struct ppb_cardbus_softc *csc = (struct fxp_cardbus_softc *) sc;
802 struct cardbus_softc *psc = device_private(device_parent(&sc->sc_dev));
803 cardbus_chipset_tag_t cc = psc->sc_cc;
804 cardbus_function_tag_t cf = psc->sc_cf;
805
806 Cardbus_function_enable(csc->ct);
807
808 fxp_cardbus_setup(sc);
809
810 /* Map and establish the interrupt. */
811
812 sc->sc_ih = cardbus_intr_establish(cc, cf, psc->sc_intrline, IPL_NET,
813 fxp_intr, sc);
814 if (NULL == sc->sc_ih) {
815 aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt\n");
816 return 1;
817 }
818
819 printf("%s: interrupting at %d\n", device_xname(&sc->sc_dev),
820 psc->sc_intrline);
821
822 #endif
823 return 0;
824 }
825
826 void
827 ppb_cardbus_disable(struct ppb_softc * sc)
828 {
829 #if 0
830 struct cardbus_softc *psc = device_private(device_parent(&sc->sc_dev));
831 cardbus_chipset_tag_t cc = psc->sc_cc;
832 cardbus_function_tag_t cf = psc->sc_cf;
833
834 /* Remove interrupt handler. */
835 cardbus_intr_disestablish(cc, cf, sc->sc_ih);
836
837 Cardbus_function_disable(((struct fxp_cardbus_softc *) sc)->ct);
838 #endif
839 }
840
841 static int
842 ppb_cardbus_detach(self, flags)
843 struct device *self;
844 int flags;
845 {
846 /* struct ppb_softc *sc = device_private(self);*/
847 struct ppb_cardbus_softc *csc = device_private(self);
848
849 #if 0
850 struct cardbus_devfunc *ct = csc->ct;
851 int rv, reg;
852
853 #ifdef DIAGNOSTIC
854 if (ct == NULL)
855 panic("%s: data structure lacks", device_xname(&sc->sc_dev));
856 #endif
857
858 rv = fxp_detach(sc);
859 if (rv == 0) {
860 /*
861 * Unhook the interrupt handler.
862 */
863 cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, sc->sc_ih);
864
865 /*
866 * release bus space and close window
867 */
868 if (csc->base0_reg)
869 reg = CARDBUS_BASE0_REG;
870 else
871 reg = CARDBUS_BASE1_REG;
872 Cardbus_mapreg_unmap(ct, reg, sc->sc_st, sc->sc_sh, csc->size);
873 }
874 return (rv);
875
876 #endif
877 csc->foo=1;
878 return 0;
879
880 }
881
882 int
883 ppb_activate(self, act)
884 struct device *self;
885 enum devact act;
886 {
887 printf("ppb_activate called\n");
888 return 0;
889 }
890
891