Home | History | Annotate | Line # | Download | only in cardbus
rbus_ppb.c revision 1.37
      1 /*	$NetBSD: rbus_ppb.c,v 1.37 2010/03/04 18:31:57 dyoung 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.37 2010/03/04 18:31:57 dyoung 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 
     65 #include <dev/pci/pccbbreg.h>
     66 #include <dev/pci/pccbbvar.h>
     67 
     68 #include <dev/cardbus/cardbusvar.h>
     69 #include <dev/pci/pcidevs.h>
     70 
     71 #include <x86/pci/pci_addr_fixup.h>
     72 #include <x86/pci/pci_bus_fixup.h>
     73 #include <i386/pci/pci_intr_fixup.h>
     74 #include <i386/pci/pcibios.h>
     75 
     76 struct ppb_softc;
     77 
     78 static int  ppb_cardbus_match(device_t, cfdata_t, void *);
     79 static void ppb_cardbus_attach(device_t, device_t, void *);
     80 static int  ppb_cardbus_detach(device_t  self, int flags);
     81 static int  ppb_activate(device_t, enum devact);
     82 int rppbprint(void *, const char *);
     83 int rbus_intr_fixup(pci_chipset_tag_t, int, int, int);
     84 void rbus_do_header_fixup(pci_chipset_tag_t, pcitag_t, void *);
     85 
     86 static void rbus_pci_phys_allocate(pci_chipset_tag_t, pcitag_t, void *);
     87 
     88 static int rbus_do_phys_allocate(pci_chipset_tag_t, pcitag_t, int,
     89 				 void *, int, bus_addr_t *, bus_size_t);
     90 
     91 static void rbus_pci_phys_countspace(pci_chipset_tag_t, pcitag_t, void *);
     92 
     93 static int rbus_do_phys_countspace(pci_chipset_tag_t, pcitag_t, int,
     94 				   void *, int, bus_addr_t *, bus_size_t);
     95 
     96 unsigned int rbus_round_up(unsigned int, unsigned int);
     97 
     98 
     99 struct ppb_cardbus_softc {
    100   device_t sc_dev;
    101   pcitag_t sc_tag;
    102   int foo;
    103 };
    104 
    105 CFATTACH_DECL_NEW(rbus_ppb, sizeof(struct ppb_cardbus_softc),
    106     ppb_cardbus_match, ppb_cardbus_attach, ppb_cardbus_detach, ppb_activate);
    107 
    108 #ifdef  CBB_DEBUG
    109 int rbus_ppb_debug = 0;   /* hack with kdb */
    110 #define DPRINTF(X) if(rbus_ppb_debug) printf X
    111 #else
    112 #define DPRINTF(X)
    113 #endif
    114 
    115 static int
    116 ppb_cardbus_match(device_t parent, cfdata_t match, void *aux)
    117 {
    118 	struct cardbus_attach_args *ca = aux;
    119 
    120 	if (PCI_VENDOR(ca->ca_id) ==  PCI_VENDOR_DEC &&
    121 	    PCI_PRODUCT(ca->ca_id) == PCI_PRODUCT_DEC_21152)
    122 		return (1);
    123 
    124 	if(PCI_CLASS(ca->ca_class) == PCI_CLASS_BRIDGE &&
    125 	   PCI_SUBCLASS(ca->ca_class) == PCI_SUBCLASS_BRIDGE_PCI) {
    126 	  /* XXX */
    127 	  printf("recognizing generic bridge chip\n");
    128 	}
    129 
    130 	return (0);
    131 }
    132 
    133 
    134 int
    135 rppbprint(void *aux, const char *pnp)
    136 {
    137 	struct pcibus_attach_args *pba = aux;
    138 
    139 	/* only PCIs can attach to PPBs; easy. */
    140 	if (pnp)
    141 		aprint_normal("pci at %s", pnp);
    142 	aprint_normal(" bus %d (rbus)", pba->pba_bus);
    143 	return (UNCONF);
    144 }
    145 
    146 int
    147 rbus_intr_fixup(pci_chipset_tag_t pc,
    148 		int minbus,
    149 		int maxbus,
    150 		int line)
    151 {
    152   pci_device_foreach_min(pc, minbus,
    153 			 maxbus, rbus_do_header_fixup, (void *)&line);
    154   return 0;
    155 }
    156 
    157 void
    158 rbus_do_header_fixup(pci_chipset_tag_t pc, pcitag_t tag, void *context)
    159 {
    160   int pin, irq;
    161   int bus, device, function;
    162   pcireg_t intr, id;
    163   int *pline = (int *)context;
    164   int line = *pline;
    165 
    166   pci_decompose_tag(pc, tag, &bus, &device, &function);
    167   id = pci_conf_read(pc, tag, PCI_ID_REG);
    168 
    169   intr = pci_conf_read(pc, tag, PCI_INTERRUPT_REG);
    170   pin = PCI_INTERRUPT_PIN(intr);
    171   irq = PCI_INTERRUPT_LINE(intr);
    172 
    173 #if 0
    174   printf("do_header %02x:%02x:%02x pin=%d => line %d\n",
    175 	 bus, device, function, pin, line);
    176 #endif
    177 
    178   intr &= ~(PCI_INTERRUPT_LINE_MASK << PCI_INTERRUPT_LINE_SHIFT);
    179   intr |= (line << PCI_INTERRUPT_LINE_SHIFT);
    180   pci_conf_write(pc, tag, PCI_INTERRUPT_REG, intr);
    181 
    182 }
    183 
    184 /*
    185  * This function takes a range of PCI bus numbers and
    186  * allocates space for all devices found in this space (the BARs) from
    187  * the rbus space maps (I/O and memory).
    188  *
    189  * It assumes that "rbus" is defined. The whole concept does.
    190  *
    191  * It uses pci_device_foreach_min() to call rbus_pci_phys_allocate.
    192  * This function is mostly stolen from
    193  *     pci_addr_fixup.c:pciaddr_resource_reserve.
    194  *
    195  */
    196 struct rbus_pci_addr_fixup_context {
    197   struct ppb_cardbus_softc *csc;
    198   cardbus_chipset_tag_t ct;
    199   struct cardbus_softc *sc;
    200   struct cardbus_attach_args *caa;
    201   int    minbus;
    202   int    maxbus;
    203   bus_size_t  *bussize_ioreqs;
    204   bus_size_t  *bussize_memreqs;
    205   rbus_tag_t   *iobustags;
    206   rbus_tag_t   *membustags;
    207 };
    208 
    209 unsigned int
    210 rbus_round_up(unsigned int size, unsigned int minval)
    211 {
    212   unsigned int power2;
    213 
    214   if(size == 0) {
    215     return 0;
    216   }
    217 
    218   power2=minval;
    219 
    220   while(power2 < (1 << 31) &&
    221 	power2 < size) {
    222     power2 = power2 << 1;
    223   }
    224 
    225   return power2;
    226 }
    227 
    228 static void
    229 rbus_pci_addr_fixup(struct ppb_cardbus_softc *csc,
    230 		    cardbus_chipset_tag_t ct,
    231 		    struct cardbus_softc *sc,
    232 		    pci_chipset_tag_t     pc,
    233 		    struct cardbus_attach_args *caa,
    234 		    int minbus, int maxbus)
    235 {
    236 	struct rbus_pci_addr_fixup_context rct;
    237 	int    size, busnum;
    238 	bus_addr_t start;
    239 	bus_space_handle_t handle;
    240 	u_int32_t reg;
    241 
    242 	rct.csc=csc;
    243 	rct.ct=ct;
    244 	rct.sc=sc;
    245 	rct.caa=caa;
    246 	rct.minbus = minbus;
    247 	rct.maxbus = maxbus;
    248 	size = sizeof(bus_size_t)*(maxbus+1);
    249 	rct.bussize_ioreqs  = alloca(size);
    250 	rct.bussize_memreqs = alloca(size);
    251 	rct.iobustags = alloca(maxbus * sizeof(rbus_tag_t));
    252 	rct.membustags = alloca(maxbus * sizeof(rbus_tag_t));
    253 
    254 	memset(rct.bussize_ioreqs, 0, size);
    255 	memset(rct.bussize_memreqs, 0, size);
    256 
    257 	printf("%s: sizing buses %d-%d\n",
    258 	       device_xname(rct.csc->sc_dev),
    259 	       minbus, maxbus);
    260 
    261 	pci_device_foreach_min(pc, minbus, maxbus,
    262 			       rbus_pci_phys_countspace, &rct);
    263 
    264 	/*
    265 	 * we need to determine amount of address space for each
    266 	 * bus. To do this, we have to roll up amounts and then
    267 	 * we need to divide up the cardbus's extent to allocate
    268 	 * some space to each bus.
    269 	 */
    270 
    271 	for(busnum=maxbus; busnum > minbus; busnum--) {
    272 	  if(pci_bus_parent[busnum] != 0) {
    273 	    if(pci_bus_parent[busnum] < minbus ||
    274 	       pci_bus_parent[busnum] >= maxbus) {
    275 	      printf("%s: bus %d has illegal parent %d\n",
    276 		     device_xname(rct.csc->sc_dev),
    277 		     busnum, pci_bus_parent[busnum]);
    278 	      continue;
    279 	    }
    280 
    281 	    /* first round amount of space up */
    282 	    rct.bussize_ioreqs[busnum] =
    283 	      rbus_round_up(rct.bussize_ioreqs[busnum],  PPB_IO_MIN);
    284 	    rct.bussize_ioreqs[pci_bus_parent[busnum]] +=
    285 	      rct.bussize_ioreqs[busnum];
    286 
    287 	    rct.bussize_memreqs[busnum] =
    288 	      rbus_round_up(rct.bussize_memreqs[busnum], PPB_MEM_MIN);
    289 	    rct.bussize_memreqs[pci_bus_parent[busnum]] +=
    290 	      rct.bussize_memreqs[busnum];
    291 
    292 	  }
    293 	}
    294 
    295 	rct.bussize_ioreqs[minbus] =
    296 	  rbus_round_up(rct.bussize_ioreqs[minbus], 4096);
    297 	rct.bussize_memreqs[minbus] =
    298 	  rbus_round_up(rct.bussize_memreqs[minbus], 8);
    299 
    300 	printf("%s: total needs IO %08lx and MEM %08lx\n",
    301 	       device_xname(rct.csc->sc_dev),
    302 	       rct.bussize_ioreqs[minbus], rct.bussize_memreqs[minbus]);
    303 
    304 	if(!caa->ca_rbus_iot) {
    305 	  panic("no iot bus");
    306 	}
    307 
    308 	if(rct.bussize_ioreqs[minbus]) {
    309 	  if(rbus_space_alloc(caa->ca_rbus_iot, 0,
    310 			      rct.bussize_ioreqs[minbus],
    311 			      rct.bussize_ioreqs[minbus]-1 /* mask  */,
    312 			      rct.bussize_ioreqs[minbus] /* align */,
    313 			      /* flags */ 0,
    314 			      &start,
    315 			      &handle) != 0) {
    316 	    panic("rbus_ppb: can not allocate %ld bytes in IO bus %d",
    317 		  rct.bussize_ioreqs[minbus], minbus);
    318 	  }
    319 	  rct.iobustags[minbus]=rbus_new(caa->ca_rbus_iot,
    320 					 start,
    321 					 rct.bussize_ioreqs[minbus],
    322 					 0 /* offset to add to physical address
    323 					      to make processor address */,
    324 					 RBUS_SPACE_DEDICATE);
    325 	}
    326 
    327 	if(rct.bussize_memreqs[minbus]) {
    328 	  if(rbus_space_alloc(caa->ca_rbus_memt, 0,
    329 			      rct.bussize_memreqs[minbus],
    330 			      rct.bussize_memreqs[minbus]-1 /* mask */,
    331 			      rct.bussize_memreqs[minbus] /* align */,
    332 			      /* flags */ 0,
    333 			      &start,
    334 			      &handle) != 0) {
    335 	    panic("%s: can not allocate %ld bytes in MEM bus %d",
    336 		  device_xname(rct.csc->sc_dev),
    337 		  rct.bussize_memreqs[minbus], minbus);
    338 	  }
    339 	  rct.membustags[minbus]=rbus_new(caa->ca_rbus_memt,
    340 					  start,
    341 					  rct.bussize_memreqs[minbus],
    342 					  0 /* offset to add to physical
    343 					       address to make processor
    344 					       address */,
    345 					  RBUS_SPACE_DEDICATE);
    346 	}
    347 
    348 	for(busnum=minbus+1; busnum <= maxbus; busnum++) {
    349 	  int busparent;
    350 
    351 	  busparent = pci_bus_parent[busnum];
    352 
    353 	  printf("%s: bus %d (parent=%d) needs IO %08lx and MEM %08lx\n",
    354 		 device_xname(rct.csc->sc_dev),
    355 		 busnum,
    356 		 busparent,
    357 		 rct.bussize_ioreqs[busnum],
    358 		 rct.bussize_memreqs[busnum]);
    359 
    360 	  if(busparent > maxbus) {
    361 	    panic("rbus_ppb: illegal parent");
    362 	  }
    363 
    364 	  if(rct.bussize_ioreqs[busnum]) {
    365 	    if(rbus_space_alloc(rct.iobustags[busparent],
    366 				0,
    367 				rct.bussize_ioreqs[busnum],
    368 				rct.bussize_ioreqs[busnum]-1 /*mask */,
    369 				rct.bussize_ioreqs[busnum] /* align */,
    370 				/* flags */ 0,
    371 				&start,
    372 				&handle) != 0) {
    373 	      panic("rbus_ppb: can not allocate %ld bytes in IO bus %d",
    374 		    rct.bussize_ioreqs[busnum], busnum);
    375 	    }
    376 	    rct.iobustags[busnum]=rbus_new(rct.iobustags[busparent],
    377 					   start,
    378 					   rct.bussize_ioreqs[busnum],
    379 					   0 /* offset to add to physical
    380 						address
    381 						to make processor address */,
    382 					   RBUS_SPACE_DEDICATE);
    383 
    384 	    /* program the bridge */
    385 
    386 	    /* enable I/O space */
    387 	    reg = pci_conf_read(pc, pci_bus_tag[busnum],
    388 				PCI_COMMAND_STATUS_REG);
    389 	    reg |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MASTER_ENABLE;
    390 	    pci_conf_write(pc, pci_bus_tag[busnum],
    391 			   PCI_COMMAND_STATUS_REG, reg);
    392 
    393 	    /* now init the limit register for I/O */
    394 	    pci_conf_write(pc, pci_bus_tag[busnum], PPB_REG_IOSTATUS,
    395 			   (((start & 0xf000) >> 8) << PPB_IOBASE_SHIFT) |
    396 			   ((((start +
    397 			       rct.bussize_ioreqs[busnum] +
    398 			       4095) & 0xf000) >> 8) << PPB_IOLIMIT_SHIFT));
    399 	  }
    400 
    401 	  if(rct.bussize_memreqs[busnum]) {
    402 	    if(rbus_space_alloc(rct.membustags[busparent],
    403 				0,
    404 				rct.bussize_memreqs[busnum] /* size  */,
    405 				rct.bussize_memreqs[busnum]-1 /*mask */,
    406 				rct.bussize_memreqs[busnum] /* align */,
    407 				/* flags */ 0,
    408 				&start,
    409 				&handle) != 0) {
    410 	      panic("rbus_ppb: can not allocate %ld bytes in MEM bus %d",
    411 		    rct.bussize_memreqs[busnum], busnum);
    412 	    }
    413 	    rct.membustags[busnum]=rbus_new(rct.membustags[busparent],
    414 					    start,
    415 					    rct.bussize_memreqs[busnum],
    416 					    0 /* offset to add to physical
    417 						 address to make processor
    418 						 address */,
    419 					    RBUS_SPACE_DEDICATE);
    420 
    421 	    /* program the bridge */
    422 	    /* enable memory space */
    423 	    reg = pci_conf_read(pc, pci_bus_tag[busnum],
    424 				PCI_COMMAND_STATUS_REG);
    425 	    reg |= PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE;
    426 	    pci_conf_write(pc, pci_bus_tag[busnum],
    427 			   PCI_COMMAND_STATUS_REG, reg);
    428 
    429 	    /* now init the limit register for memory */
    430 	    pci_conf_write(pc, pci_bus_tag[busnum], PPB_REG_MEM,
    431 			   ((start & PPB_MEM_MASK)
    432 			    >> PPB_MEM_SHIFT) << PPB_MEMBASE_SHIFT |
    433 			   (((start +
    434 			     rct.bussize_memreqs[busnum] +
    435 			      PPB_MEM_MIN-1) >> PPB_MEM_SHIFT)
    436 			    << PPB_MEMLIMIT_SHIFT));
    437 
    438 	    /* and set the prefetchable limits as well */
    439 	    pci_conf_write(pc, pci_bus_tag[busnum], PPB_REG_PREFMEM,
    440 			   ((start & PPB_MEM_MASK)
    441 			    >> PPB_MEM_SHIFT) << PPB_MEMBASE_SHIFT |
    442 			   (((start +
    443 			     rct.bussize_memreqs[busnum] +
    444 			      PPB_MEM_MIN-1) >> PPB_MEM_SHIFT)
    445 			    << PPB_MEMLIMIT_SHIFT));
    446 
    447 	    /* pci_conf_print(pc, pci_bus_tag[busnum], NULL); */
    448 	  }
    449 	}
    450 
    451 	printf("%s: configuring buses %d-%d\n",
    452 		device_xname(rct.csc->sc_dev),
    453 	       minbus, maxbus);
    454 	pci_device_foreach_min(pc, minbus, maxbus,
    455 			       rbus_pci_phys_allocate, &rct);
    456 }
    457 
    458 static void
    459 rbus_pci_phys_countspace(pci_chipset_tag_t pc, pcitag_t tag, void *context)
    460 {
    461         int bus, device, function;
    462 	struct  rbus_pci_addr_fixup_context *rct =
    463 	  (struct  rbus_pci_addr_fixup_context *)context;
    464 
    465 	pci_decompose_tag(pc, tag, &bus, &device, &function);
    466 
    467 	printf("%s: configuring device %02x:%02x:%02x\n",
    468 	       device_xname(rct->csc->sc_dev),
    469 	       bus, device, function);
    470 
    471 	pciaddr_resource_manage(pc, tag,
    472 				rbus_do_phys_countspace, context);
    473 }
    474 
    475 
    476 int
    477 rbus_do_phys_countspace(pci_chipset_tag_t pc, pcitag_t tag, int mapreg, void *ctx, int type, bus_addr_t *addr, bus_size_t size)
    478 {
    479 	struct  rbus_pci_addr_fixup_context *rct =
    480 	  (struct  rbus_pci_addr_fixup_context *)ctx;
    481 	int bus, device, function;
    482 
    483 	pci_decompose_tag(pc, tag, &bus, &device, &function);
    484 
    485 	if(size > (1<<24)) {
    486 	  printf("%s: skipping huge space request of size=%08x\n",
    487 		 device_xname(rct->csc->sc_dev), (unsigned int)size);
    488 	  return 0;
    489 	}
    490 
    491 	if(PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_IO) {
    492 	  rct->bussize_ioreqs[bus] += size;
    493 	} else {
    494 	  rct->bussize_memreqs[bus]+= size;
    495 	}
    496 
    497 	return 0;
    498 }
    499 
    500 static void
    501 rbus_pci_phys_allocate(pci_chipset_tag_t pc, pcitag_t tag, void *context)
    502 {
    503         int bus, device, function, command;
    504 	struct rbus_pci_addr_fixup_context *rct =
    505 	  (struct rbus_pci_addr_fixup_context *)context;
    506 	//cardbus_chipset_tag_t ct = rct->ct;
    507 	//	struct cardbus_softc *sc = rct->sc;
    508 
    509 	pci_decompose_tag(pc, tag, &bus, &device, &function);
    510 
    511 	printf("%s: configuring device %02x:%02x:%02x\n",
    512 	       device_xname(rct->csc->sc_dev),
    513 	       bus, device, function);
    514 
    515 	pciaddr_resource_manage(pc, tag,
    516 				rbus_do_phys_allocate, context);
    517 
    518 	/* now turn the device's memory and I/O on */
    519 	command = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    520 	command |= PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE;
    521 	pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, command);
    522 }
    523 
    524 int
    525 rbus_do_phys_allocate(pci_chipset_tag_t pc, pcitag_t tag, int mapreg, void *ctx, int type, bus_addr_t *addr, bus_size_t size)
    526 {
    527 	struct  rbus_pci_addr_fixup_context *rct =
    528 	  (struct  rbus_pci_addr_fixup_context *)ctx;
    529 	cardbus_chipset_tag_t ct     = rct->ct;
    530 	struct cardbus_softc *sc     = rct->sc;
    531 	cardbus_function_t       *cf = sc->sc_cf;
    532 	rbus_tag_t          rbustag;
    533 	bus_space_tag_t     bustag;
    534 	bus_addr_t mask = size -1;
    535 	bus_addr_t base = 0;
    536 	bus_space_handle_t handle;
    537 	int busflags = 0;
    538 	int flags    = 0;
    539 	const char *bustype;
    540 	int bus, device, function;
    541 
    542 	pci_decompose_tag(pc, tag, &bus, &device, &function);
    543 
    544 	/*
    545 	 * some devices come up with garbage in them (Tulip?)
    546 	 * we are in charge here, so give them address
    547 	 * space anyway.
    548 	 *
    549 	 * XXX this may be due to no secondary PCI reset!!!
    550 	 */
    551 #if 0
    552 	if (*addr) {
    553 		printf("Already allocated space at %08x\n",
    554 		       (unsigned int)*addr);
    555 		return (0);
    556 	}
    557 #endif
    558 
    559 	if(size > (1<<24)) {
    560 	  printf("%s: skipping huge space request of size=%08x\n",
    561 		 device_xname(rct->csc->sc_dev), (unsigned int)size);
    562 	  return 0;
    563 	}
    564 
    565 	if(PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_IO) {
    566 	  bustag  = sc->sc_iot;
    567 	  rbustag = rct->iobustags[bus];
    568 	  bustype = "io";
    569 	} else {
    570 	  bustag  = sc->sc_memt;
    571 	  rbustag = rct->membustags[bus];
    572 	  bustype = "mem";
    573 	}
    574 
    575 	if((*cf->cardbus_space_alloc)(ct, rbustag, base, size,
    576 				      mask, size, busflags|flags,
    577 				      addr, &handle)) {
    578 	  printf("%s: no available resources (size=%08x) for bar %2d. fixup failed\n",
    579 		 device_xname(rct->csc->sc_dev), (unsigned int)size, mapreg);
    580 
    581 	  *addr = 0;
    582 	  pci_conf_write(pc, tag, mapreg, *addr);
    583 	  return (1);
    584 	}
    585 
    586 	printf("%s: alloc %s space of size %08x for %02d:%02d:%02d -> %08x\n",
    587 	       device_xname(rct->csc->sc_dev),
    588 	       bustype,
    589 	       (unsigned int)size,
    590 	       bus, device, function, (unsigned int)*addr);
    591 
    592 	/* write new address to PCI device configuration header */
    593 	pci_conf_write(pc, tag, mapreg, *addr);
    594 
    595 	/* check */
    596 	{
    597 		DPRINTF(("%s: pci_addr_fixup: ",
    598 			 device_xname(rct->csc->sc_dev)));
    599 #ifdef  CBB_DEBUG
    600 		if(rbus_ppb_debug) { pciaddr_print_devid(pc, tag); }
    601 #endif
    602 	}
    603 
    604 	/* double check that the value got inserted correctly */
    605 	if (pciaddr_ioaddr(pci_conf_read(pc, tag, mapreg)) != *addr) {
    606 		pci_conf_write(pc, tag, mapreg, 0); /* clear */
    607 		printf("%s: fixup failed. (new address=%#x)\n",
    608 		       device_xname(rct->csc->sc_dev),
    609 		       (unsigned)*addr);
    610 		return (1);
    611 	}
    612 
    613 	DPRINTF(("new address 0x%08x\n",
    614 		 (unsigned)*addr));
    615 
    616 	return (0);
    617 }
    618 
    619 static void
    620 ppb_cardbus_attach(device_t parent, device_t self, void *aux)
    621 {
    622 	struct ppb_cardbus_softc *csc = device_private(self);
    623 	struct cardbus_softc *parent_sc = device_private(parent);
    624 	struct cardbus_attach_args *ca = aux;
    625 	cardbus_devfunc_t ct = ca->ca_ct;
    626 	cardbus_chipset_tag_t cc = ct->ct_cc;
    627 	cardbus_function_tag_t cf = ct->ct_cf;
    628 	struct pccbb_softc *psc = (struct pccbb_softc *)cc;
    629 	struct pcibus_attach_args pba;
    630 	char devinfo[256];
    631 	pcireg_t busdata;
    632 	int mybus, rv;
    633 	u_int16_t pciirq;
    634 	int minbus, maxbus;
    635 
    636 	csc->sc_dev = self;
    637 
    638 	mybus = ct->ct_bus;
    639 	pciirq = 0;
    640 	rv = 0;
    641 
    642 	/* shut up compiler */
    643 	csc->foo = parent_sc->sc_intrline;
    644 
    645 
    646 	pci_devinfo(ca->ca_id, ca->ca_class, 0, devinfo, sizeof(devinfo));
    647 	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(ca->ca_class));
    648 
    649 	csc->sc_tag = ca->ca_tag;
    650 
    651 	busdata = Cardbus_conf_read(ct, ca->ca_tag, PPB_REG_BUSINFO);
    652 	minbus = pcibios_max_bus;
    653 	maxbus = minbus;		/* XXX; gcc */
    654 
    655 	if (PPB_BUSINFO_SECONDARY(busdata) == 0) {
    656 		aprint_error_dev(self, "not configured by system firmware calling pci_bus_fixup(%d)\n", 0);
    657 
    658 	  /*
    659 	   * first, pull the reset wire on the secondary bridge
    660 	   * to clear all devices
    661 	   */
    662 	  busdata = Cardbus_conf_read(ct, ca->ca_tag,
    663 				      PPB_REG_BRIDGECONTROL);
    664 	  Cardbus_conf_write(ct, ca->ca_tag, PPB_REG_BRIDGECONTROL,
    665 			     busdata | PPB_BC_SECONDARY_RESET);
    666 	  delay(1);
    667 	  Cardbus_conf_write(ct, ca->ca_tag, PPB_REG_BRIDGECONTROL,
    668 			     busdata);
    669 
    670 	  /* then go initialize the bridge control registers */
    671 	  maxbus = pci_bus_fixup(psc->sc_pc, 0);
    672 	}
    673 
    674 	busdata = Cardbus_conf_read(ct, ca->ca_tag, PPB_REG_BUSINFO);
    675 	if(PPB_BUSINFO_SECONDARY(busdata) == 0) {
    676 		aprint_error_dev(self, "still not configured, not fixable.\n");
    677 		return;
    678 	}
    679 
    680 #if 0
    681 	minbus = PPB_BUSINFO_SECONDARY(busdata);
    682 	maxbus = PPB_BUSINFO_SUBORDINATE(busdata);
    683 #endif
    684 
    685 	/* now, go and assign addresses for the new devices */
    686 	rbus_pci_addr_fixup(csc, cc, parent_sc,
    687 			    psc->sc_pc,
    688 			    ca,
    689 			    minbus, maxbus);
    690 
    691 	/*
    692 	 * now configure all connected devices to the IRQ which
    693 	 * was assigned to this slot, as they will all arrive from
    694 	 * that IRQ.
    695 	 */
    696 	rbus_intr_fixup(psc->sc_pc, minbus, maxbus, ca->ca_intrline);
    697 
    698 	/*
    699 	 * enable direct routing of interrupts. We do this because
    700 	 * we can not manage to get pccb_intr_establish() called until
    701 	 * PCI subsystem is merged with rbus. The major thing that this
    702 	 * routine does is avoid calling the driver's interrupt routine
    703 	 * when the card has been removed.
    704 	 *
    705 	 * The rbus_ppb.c can not cope with card desertions until the merging
    706 	 * anyway.
    707 	 */
    708 	pccbb_intr_route(psc);
    709 
    710 	/*
    711 	 * Attach the PCI bus than hangs off of it.
    712 	 *
    713 	 * XXX Don't pass-through Memory Read Multiple.  Should we?
    714 	 * XXX Consult the spec...
    715 	 */
    716 	pba.pba_iot  = ca->ca_iot;
    717 	pba.pba_memt = ca->ca_memt;
    718 	pba.pba_dmat = ca->ca_dmat;
    719 	pba.pba_pc   = psc->sc_pc;
    720 	pba.pba_flags    = PCI_FLAGS_IO_ENABLED|PCI_FLAGS_MEM_ENABLED;
    721 	pba.pba_bus      = PPB_BUSINFO_SECONDARY(busdata);
    722 	pba.pba_bridgetag = &csc->sc_tag;
    723 	/*pba.pba_intrswiz = parent_sc->sc_intrswiz; */
    724 	pba.pba_intrtag  = psc->sc_pa.pa_intrtag;
    725 
    726 	config_found_ia(self, "pcibus", &pba, rppbprint);
    727 }
    728 
    729 static int
    730 ppb_cardbus_detach(device_t self, int flags)
    731 {
    732   /* struct ppb_softc *sc = device_private(self);*/
    733 	struct ppb_cardbus_softc *csc = device_private(self);
    734 
    735 #if 0
    736 	struct cardbus_devfunc *ct = csc->ct;
    737 	int rv, reg;
    738 
    739 #ifdef DIAGNOSTIC
    740 	if (ct == NULL)
    741 		panic("%s: data structure lacks", device_xname(sc->sc_dev));
    742 #endif
    743 
    744 	rv = fxp_detach(sc);
    745 	if (rv == 0) {
    746 		/*
    747 		 * Unhook the interrupt handler.
    748 		 */
    749 		Cardbus_intr_disestablish(ct, sc->sc_ih);
    750 
    751 		/*
    752 		 * release bus space and close window
    753 		 */
    754 		if (csc->base0_reg)
    755 			reg = PCI_BAR0;
    756 		else
    757 			reg = PCI_BAR1;
    758 		Cardbus_mapreg_unmap(ct, reg, sc->sc_st, sc->sc_sh, csc->size);
    759 	}
    760 	return (rv);
    761 
    762 #endif
    763 	csc->foo=1;
    764 	return 0;
    765 
    766 }
    767 
    768 int
    769 ppb_activate(device_t self, enum devact act)
    770 {
    771   printf("ppb_activate called\n");
    772   return 0;
    773 }
    774 
    775