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