Home | History | Annotate | Line # | Download | only in pci
sbpcihb.c revision 1.1.2.1
      1 /* $NetBSD: sbpcihb.c,v 1.1.2.1 2010/01/21 04:22:33 matt Exp $ */
      2 
      3 /*
      4  * Copyright 2000, 2001
      5  * Broadcom Corporation. All rights reserved.
      6  *
      7  * This software is furnished under license and may be used and copied only
      8  * in accordance with the following terms and conditions.  Subject to these
      9  * conditions, you may download, copy, install, use, modify and distribute
     10  * modified or unmodified copies of this software in source and/or binary
     11  * form. No title or ownership is transferred hereby.
     12  *
     13  * 1) Any source code used, modified or distributed must reproduce and
     14  *    retain this copyright notice and list of conditions as they appear in
     15  *    the source file.
     16  *
     17  * 2) No right is granted to use any trade name, trademark, or logo of
     18  *    Broadcom Corporation. Neither the "Broadcom Corporation" name nor any
     19  *    trademark or logo of Broadcom Corporation may be used to endorse or
     20  *    promote products derived from this software without the prior written
     21  *    permission of Broadcom Corporation.
     22  *
     23  * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
     24  *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
     25  *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
     26  *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
     27  *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
     28  *    LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     31  *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     32  *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     33  *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  */
     35 
     36 /*
     37  * Driver for SB-1250 PCI Host Bridge.
     38  *
     39  * Doesn't have to do much at all.
     40  */
     41 
     42 #include <sys/param.h>
     43 #include <sys/device.h>
     44 #include <sys/systm.h>
     45 
     46 #include <dev/pci/pcireg.h>
     47 #include <dev/pci/pcivar.h>
     48 #include <dev/pci/ppbreg.h>
     49 #include <dev/pci/pcidevs.h>
     50 
     51 #include <machine/locore.h>
     52 #include <mips/sibyte/include/sb1250_regs.h>
     53 #include <mips/sibyte/include/sb1250_scd.h>
     54 
     55 static int	sbpcihb_match(device_t, cfdata_t, void *);
     56 static void	sbpcihb_attach(device_t, device_t, void *);
     57 static int	sbpcihb_print(void *, const char *);
     58 
     59 CFATTACH_DECL_NEW(sbpcihb, 0,
     60     sbpcihb_match, sbpcihb_attach, NULL, NULL);
     61 
     62 bool sbpcihbfound;
     63 
     64 static int
     65 sbpcihb_match(device_t parent, cfdata_t match, void *aux)
     66 {
     67 	struct pci_attach_args *pa = aux;
     68 
     69 	if (sbpcihbfound) {
     70 		return(0);
     71 	}
     72 
     73 	/* Check for a vendor/device match.  */
     74 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SIBYTE &&
     75 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SIBYTE_BCM1250_PCIHB)
     76 		return (1);
     77 
     78 	return (0);
     79 }
     80 
     81 static void
     82 sbpcihb_attach(device_t parent, device_t self, void *aux)
     83 {
     84 	uint64_t regval;
     85 	int host;
     86 
     87 	sbpcihbfound = true;
     88 
     89 	/* Tell the user whether it's host or device mode. */
     90 printf("\n\tA_SCD_SYSTEM_CFG: %x\n", A_SCD_SYSTEM_CFG);
     91 	regval = mips3_ld((void *)MIPS_PHYS_TO_KSEG0(A_SCD_SYSTEM_CFG));
     92 	host = (regval & M_SYS_PCI_HOST) != 0;
     93 printf("\tregval: %"PRIx64"\n", regval);
     94 printf("\thost: %x\n", host);
     95 
     96 	aprint_normal(": %s mode\n", host ? "host" : "device");
     97 
     98 #if 1
     99         struct pci_attach_args *pa = aux;
    100         pci_chipset_tag_t pc = pa->pa_pc;
    101         struct pcibus_attach_args pba;
    102         pcireg_t busdata;
    103         char devinfo[256];
    104 
    105         pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    106         aprint_normal(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
    107 
    108 printf("\tpc: %p\n", pc);
    109 printf("\tpa: %p\n", pa);
    110 printf("\tpa->pa_tag: %"PRIxPTR"\n", (uintptr_t)(pa->pa_tag));
    111 printf("\tPPB_REG_BUSINFO %x\n", PPB_REG_BUSINFO);
    112         busdata = pci_conf_read(pc, pa->pa_tag, PPB_REG_BUSINFO);
    113 printf("\tbusdata is: %"PRIx32"\n", busdata);
    114 
    115         if (PPB_BUSINFO_PRIMARY(busdata) == 0 &&
    116             PPB_BUSINFO_SECONDARY(busdata) == 0) {
    117                 aprint_normal_dev(self, "not configured by system firmware\n");
    118                 return;
    119         }
    120 
    121         /*
    122          * Attach the PCI bus than hangs off of it.
    123          *
    124          * XXX Don't pass-through Memory Read Multiple.  Should we?
    125          * XXX Consult the spec...
    126          */
    127 //      pba.pba_busname = "pci";        /* XXX should be pci_ppb attachment */
    128         pba.pba_iot = pa->pa_iot;
    129         pba.pba_memt = pa->pa_memt;
    130         pba.pba_dmat = pa->pa_dmat;                             /* XXXLDT??? */
    131         pba.pba_pc = pc;                                        /* XXXLDT??? */
    132         pba.pba_flags = pa->pa_flags & ~PCI_FLAGS_MRM_OKAY;     /* XXXLDT??? */
    133         pba.pba_bus = PPB_BUSINFO_SECONDARY(busdata);
    134         pba.pba_intrswiz = pa->pa_intrswiz;                     /* XXXLDT??? */
    135         pba.pba_intrtag = pa->pa_intrtag;                       /* XXXLDT??? */
    136 
    137         config_found(self, &pba, sbpcihb_print);
    138 #endif
    139 }
    140 
    141 int
    142 sbpcihb_print( void *aux, const char *pnp)
    143 {
    144 	struct pcibus_attach_args *pba = aux;
    145 
    146 	/* only PCIs can attach to PPBs; easy. */
    147 	if (pnp)
    148 		printf("pci at %s", pnp);
    149 	printf(" bus %d", pba->pba_bus);
    150 	return (UNCONF);
    151 }
    152 
    153