Home | History | Annotate | Line # | Download | only in dev
sbgbus.c revision 1.2
      1 /* $NetBSD: sbgbus.c,v 1.2 2002/09/27 03:17:59 thorpej 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 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/device.h>
     39 
     40 #include <machine/locore.h>
     41 #include <machine/sb1250/sb1250_regs.h>
     42 #include <machine/sb1250/sb1250_genbus.h>
     43 #include <sbmips/dev/sbobio/sbobiovar.h>
     44 #include <sbmips/dev/sbgbus/sbgbusvar.h>
     45 
     46 extern struct cfdriver sbgbus_cd;
     47 
     48 static int	sbgbus_match(struct device *, struct cfdata *, void *);
     49 static void	sbgbus_attach(struct device *, struct device *, void *);
     50 
     51 const struct cfattach sbgbus_ca = {
     52 	sizeof(struct device), sbgbus_match, sbgbus_attach,
     53 };
     54 
     55 static int	sbgbussearch(struct device *, struct cfdata *, void *);
     56 static int	sbgbusprint(void *, const char *);
     57 
     58 static int
     59 sbgbus_match(struct device *parent, struct cfdata *match, void *aux)
     60 {
     61 	struct sbobio_attach_args *sap = aux;
     62 
     63 	if (sap->sa_locs.sa_type != SBOBIO_DEVTYPE_GBUS)
     64 		return (0);
     65 
     66 	return 1;
     67 }
     68 
     69 static void
     70 sbgbus_attach(struct device *parent, struct device *self, void *aux)
     71 {
     72 
     73 	/* Configure children using indirect configuration. */
     74 	config_search(sbgbussearch, self, NULL);
     75 }
     76 
     77 static int
     78 sbgbusprint(void *aux, const char *pnp)
     79 {
     80 	struct sbgbus_attach_args *sga = aux;
     81 
     82 	if (sga->sga_chipsel != SBGBUS_CHIPSEL_NONE)
     83 		printf(" chipsel %u", sga->sga_chipsel);
     84 	if (sga->sga_offset != 0)
     85 		printf(" offset 0x%x", sga->sga_offset);
     86 	if (sga->sga_intr[0] != SBGBUS_INTR_NONE) {
     87 		printf(" intr %u", sga->sga_intr[0]);
     88 		if (sga->sga_intr[1] != SBGBUS_INTR_NONE) {
     89 			printf(",%u", sga->sga_intr[1]);
     90 		}
     91 	}
     92 	return (UNCONF);
     93 }
     94 
     95 static int
     96 sbgbussearch(struct device *parent, struct cfdata *cf, void *aux)
     97 {
     98 	struct sbgbus_attach_args sga;
     99 	int tryagain;
    100 
    101 	do {
    102 		/* Fill in sga */
    103 		sga.sga_chipsel = cf->cf_loc[SBGBUSCF_CHIPSEL];
    104 		sga.sga_offset = cf->cf_loc[SBGBUSCF_OFFSET];
    105 		sga.sga_intr[0] = cf->cf_loc[SBGBUSCF_INTR];
    106 		sga.sga_intr[1] = cf->cf_loc[SBGBUSCF_INTR_1];
    107 
    108 		/* Some quick sanity checks. */
    109 		if (sga.sga_intr[0] == SBGBUS_INTR_NONE &&
    110 		    sga.sga_intr[1] != SBGBUS_INTR_NONE) {
    111 			/* XXX probably should print */
    112 			return (0);
    113 		}
    114 		if (sga.sga_chipsel == SBGBUS_CHIPSEL_NONE &&
    115 		    sga.sga_offset != 0) {
    116 			/* XXX probably should print */
    117 			return (0);
    118 		}
    119 		if (sga.sga_chipsel >= IO_EXT_CFG_COUNT) {
    120 			/* XXX probably should print */
    121 			return (0);
    122 		}
    123 
    124 		/* XXX check for PCMCIA. */
    125 
    126 		if (sga.sga_chipsel == SBGBUS_CHIPSEL_NONE) {
    127 			sga.sga_startphys = 0;
    128 			sga.sga_size = 0;
    129 		} else {
    130 			uint64_t rv;
    131 
    132 			rv = mips3_ld((void *)MIPS_PHYS_TO_KSEG1(
    133 			    A_IO_EXT_CS_BASE(sga.sga_chipsel) +
    134 			    R_IO_EXT_START_ADDR));
    135 			sga.sga_startphys = (rv & M_IO_START_ADDR) << S_IO_ADDRBASE;
    136 			rv = mips3_ld((void *)MIPS_PHYS_TO_KSEG1(
    137 			    A_IO_EXT_CS_BASE(sga.sga_chipsel) +
    138 			    R_IO_EXT_MULT_SIZE));
    139 			sga.sga_size = (rv & M_IO_MULT_SIZE) << S_IO_REGSIZE;
    140 
    141 			/* Make sure that region is enabled.  */
    142 			if (sga.sga_size == 0 ||
    143 			    sga.sga_startphys < A_PHYS_GENBUS ||
    144 			    sga.sga_startphys >= A_PHYS_GENBUS_END)
    145 				return (0);
    146 
    147 			/* Report to child only the space they can access. */
    148 			if (sga.sga_startphys + sga.sga_size > A_PHYS_GENBUS_END)
    149 			    sga.sga_size = A_PHYS_GENBUS_END - sga.sga_startphys;
    150 		}
    151 
    152 		tryagain = 0;
    153 		if (config_match(parent, cf, &sga) > 0) {
    154 			config_attach(parent, cf, &sga, sbgbusprint);
    155 			tryagain = (cf->cf_fstate == FSTATE_STAR);
    156 		}
    157 	} while (tryagain);
    158 
    159 	return (0);
    160 }
    161