Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/cardbus cardbus attachment for PCI-PCI bridges



details:   https://anonhg.NetBSD.org/src/rev/6b47029cfca6
branches:  trunk
changeset: 512139:6b47029cfca6
user:      mcr <mcr%NetBSD.org@localhost>
date:      Fri Jul 06 18:05:59 2001 +0000

description:
cardbus attachment for PCI-PCI bridges

diffstat:

 sys/dev/cardbus/files.cardbus |    8 +-
 sys/dev/cardbus/rbus_ppb.c    |  919 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 926 insertions(+), 1 deletions(-)

diffs (truncated from 945 to 300 lines):

diff -r ea61dbf98592 -r 6b47029cfca6 sys/dev/cardbus/files.cardbus
--- a/sys/dev/cardbus/files.cardbus     Fri Jul 06 18:05:25 2001 +0000
+++ b/sys/dev/cardbus/files.cardbus     Fri Jul 06 18:05:59 2001 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.cardbus,v 1.15 2001/05/09 12:07:40 augustss Exp $
+#      $NetBSD: files.cardbus,v 1.16 2001/07/06 18:05:59 mcr Exp $
 #
 # files.cardbus
 #
@@ -59,6 +59,12 @@
 file   dev/cardbus/ahc_cardbus.c       ahc_cardbus
 
 #
+# PCI bridge
+#
+attach  ppb at cardbus with rbus_ppb
+file   dev/cardbus/rbus_ppb.c          rbus_ppb
+
+#
 # RealTek 8139
 #
 attach rtk at cardbus with rtk_cardbus
diff -r ea61dbf98592 -r 6b47029cfca6 sys/dev/cardbus/rbus_ppb.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/cardbus/rbus_ppb.c        Fri Jul 06 18:05:59 2001 +0000
@@ -0,0 +1,919 @@
+/*     $NetBSD: rbus_ppb.c,v 1.1 2001/07/06 18:05:59 mcr Exp $ */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Michael Richardson <mcr%sandelman.ottawa.on.ca@localhost>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * CardBus front-end for the Intel/Digital DECchip 21152 PCI-PCI bridge
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/errno.h>
+#include <sys/device.h>
+
+#if NRND > 0
+#include <sys/rnd.h>
+#endif
+
+#include <machine/endian.h>
+
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcidevs.h>
+#include <dev/pci/ppbreg.h>
+
+#include <dev/ic/i82365reg.h>
+#include <dev/ic/i82365var.h>
+
+#include <dev/pci/pccbbreg.h>
+#include <dev/pci/pccbbvar.h>
+
+#include <dev/cardbus/cardbusvar.h>
+#include <dev/cardbus/cardbusdevs.h>
+
+#include <i386/pci/pci_addr_fixup.h>
+#include <i386/pci/pci_bus_fixup.h>
+#include <i386/pci/pci_intr_fixup.h>
+#include <i386/pci/pcibios.h>
+
+struct ppb_softc;
+
+static int  ppb_cardbus_match   __P((struct device *, struct cfdata *, void *));
+static void ppb_cardbus_attach  __P((struct device *, struct device *, void *));
+static int  ppb_cardbus_detach  __P((struct device * self, int flags));
+/*static*/ void ppb_cardbus_setup   __P((struct ppb_softc * sc));
+/*static*/ int  ppb_cardbus_enable  __P((struct ppb_softc * sc));
+/*static*/ void ppb_cardbus_disable __P((struct ppb_softc * sc));
+static int  ppb_activate        __P((struct device *self, enum devact act));
+int rppbprint        __P((void *aux, const char *pnp));
+int rbus_intr_fixup  __P((pci_chipset_tag_t pc, int minbus,
+                         int maxbus, int line));
+void rbus_do_header_fixup __P((pci_chipset_tag_t pc, pcitag_t tag,
+                             void *context));
+
+static void rbus_pci_phys_allocate __P((pci_chipset_tag_t pc,
+                                       pcitag_t          tag,
+                                       void             *context));
+
+static int rbus_do_phys_allocate __P((pci_chipset_tag_t pc,
+                                     pcitag_t     tag,
+                                     int mapreg,
+                                     void        *ctx,
+                                     int type,
+                                     bus_addr_t *addr,
+                                     bus_size_t size));
+
+static void rbus_pci_phys_countspace __P((pci_chipset_tag_t pc,
+                                         pcitag_t          tag,
+                                         void             *context));
+
+static int rbus_do_phys_countspace __P((pci_chipset_tag_t pc,
+                                       pcitag_t     tag,
+                                       int mapreg,     
+                                       void        *ctx,
+                                       int type,
+                                       bus_addr_t *addr,
+                                       bus_size_t size));
+
+unsigned int rbus_round_up __P((unsigned int size, unsigned int min));
+
+
+struct ppb_cardbus_softc {
+  struct device sc_dev;
+  int foo;
+};
+
+struct cfattach rbus_ppb_ca = {
+       sizeof(struct ppb_cardbus_softc),
+       ppb_cardbus_match,
+       ppb_cardbus_attach,
+       ppb_cardbus_detach,
+       ppb_activate
+};
+
+#ifdef  CBB_DEBUG
+int rbus_ppb_debug = 0;   /* hack with kdb */
+#define DPRINTF(X) if(rbus_ppb_debug) printf X
+#else
+#define DPRINTF(X)
+#endif
+
+static int
+ppb_cardbus_match(parent, match, aux)
+       struct device *parent;
+       struct cfdata *match;
+       void   *aux;
+{
+       struct cardbus_attach_args *ca = aux;
+
+       if (CARDBUS_VENDOR(ca->ca_id) ==  PCI_VENDOR_DEC &&
+           CARDBUS_PRODUCT(ca->ca_id) == PCI_PRODUCT_DEC_21152)
+               return (1);
+
+       if(PCI_CLASS(ca->ca_class) == PCI_CLASS_BRIDGE &&
+          PCI_SUBCLASS(ca->ca_class) == PCI_SUBCLASS_BRIDGE_PCI) {
+         /* XXX */
+         printf("recognizing generic bridge chip\n");
+       }
+
+       return (0);
+}
+
+
+int
+rppbprint(aux, pnp)
+       void *aux;
+       const char *pnp;
+{
+       struct pcibus_attach_args *pba = aux;
+
+       /* only PCIs can attach to PPBs; easy. */
+       if (pnp)
+               printf("pci at %s", pnp);
+       printf(" bus %d (rbus)", pba->pba_bus);
+       return (UNCONF);
+}
+
+int
+rbus_intr_fixup(pci_chipset_tag_t pc,
+               int minbus,
+               int maxbus,
+               int line)
+{
+  pci_device_foreach_min(pc, minbus,
+                        maxbus, rbus_do_header_fixup, (void *)&line);
+  return 0;
+}
+
+void
+rbus_do_header_fixup(pc, tag, context)
+       pci_chipset_tag_t pc;
+       pcitag_t tag;
+       void *context;
+{
+  int pin, irq;
+  int bus, device, function;
+  pcireg_t intr, id;
+  int *pline = (int *)context;
+  int line = *pline;
+
+  pci_decompose_tag(pc, tag, &bus, &device, &function);
+  id = pci_conf_read(pc, tag, PCI_ID_REG);
+
+  intr = pci_conf_read(pc, tag, PCI_INTERRUPT_REG);
+  pin = PCI_INTERRUPT_PIN(intr);
+  irq = PCI_INTERRUPT_LINE(intr);
+
+#if 0
+  printf("do_header %02x:%02x:%02x pin=%d => line %d\n",
+        bus, device, function, pin, line);
+#endif
+
+  intr &= ~(PCI_INTERRUPT_LINE_MASK << PCI_INTERRUPT_LINE_SHIFT);
+  intr |= (line << PCI_INTERRUPT_LINE_SHIFT);
+  pci_conf_write(pc, tag, PCI_INTERRUPT_REG, intr);
+
+}
+
+/* 
+ * This function takes a range of PCI bus numbers and
+ * allocates space for all devices found in this space (the BARs) from
+ * the rbus space maps (I/O and memory).
+ *
+ * It assumes that "rbus" is defined. The whole concept does.
+ *
+ * It uses pci_device_foreach_min() to call rbus_pci_phys_allocate.
+ * This function is mostly stolen from
+ *     pci_addr_fixup.c:pciaddr_resource_reserve. 
+ *
+ */
+struct rbus_pci_addr_fixup_context {
+  struct ppb_cardbus_softc *csc;
+  cardbus_chipset_tag_t ct;
+  struct cardbus_softc *sc;
+  struct cardbus_attach_args *caa;
+  int    minbus;
+  int    maxbus;
+  bus_size_t  *bussize_ioreqs;
+  bus_size_t  *bussize_memreqs;
+  rbus_tag_t   *iobustags;
+  rbus_tag_t   *membustags;
+};  
+
+unsigned int 
+rbus_round_up(unsigned int size, unsigned int min)
+{
+  unsigned int power2;
+
+  if(size == 0) {
+    return 0;
+  }
+
+  power2=min;
+
+  while(power2 < (1 << 31) &&
+       power2 < size) {
+    power2 = power2 << 1;
+  }
+  
+  return power2;
+}
+    
+static void
+rbus_pci_addr_fixup(struct ppb_cardbus_softc *csc,
+                   cardbus_chipset_tag_t ct,
+                   struct cardbus_softc *sc,
+                   pci_chipset_tag_t     pc,
+                   struct cardbus_attach_args *caa,
+                   int minbus, int maxbus)
+{
+       struct rbus_pci_addr_fixup_context rct;
+       int    size, busnum;
+       bus_addr_t start;



Home | Main Index | Thread Index | Old Index