Home | History | Annotate | Line # | Download | only in pci
cac_pci.c revision 1.2
      1 /*	$NetBSD: cac_pci.c,v 1.2 2000/03/21 13:45:16 ad Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Andy Doran.
      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  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * PCI front-end for cac(4) driver.
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: cac_pci.c,v 1.2 2000/03/21 13:45:16 ad Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/kernel.h>
     49 #include <sys/device.h>
     50 #include <sys/queue.h>
     51 #include <sys/proc.h>
     52 #include <sys/buf.h>
     53 
     54 #include <machine/endian.h>
     55 #include <machine/bus.h>
     56 
     57 #include <dev/pci/pcidevs.h>
     58 #include <dev/pci/pcivar.h>
     59 
     60 #include <dev/ic/cacreg.h>
     61 #include <dev/ic/cacvar.h>
     62 
     63 #define	PCI_CBIO	0x10	/* Configuration base I/O address */
     64 #define	PCI_CBMA	0x14	/* Configuration base memory address */
     65 
     66 static int	cac_pci_match __P((struct device *, struct cfdata *, void *));
     67 static void	cac_pci_attach __P((struct device *, struct device *, void *));
     68 
     69 static void	cac_pci_l0_submit __P((struct cac_softc *, paddr_t));
     70 static paddr_t	cac_pci_l0_completed __P((struct cac_softc *));
     71 static int	cac_pci_l0_intr_pending __P((struct cac_softc *));
     72 static void	cac_pci_l0_intr_enable __P((struct cac_softc *, int));
     73 static int	cac_pci_l0_fifo_full __P((struct cac_softc *));
     74 
     75 static void	cac_pci_l1_submit __P((struct cac_softc *, paddr_t));
     76 static paddr_t	cac_pci_l1_completed __P((struct cac_softc *));
     77 static int	cac_pci_l1_intr_pending __P((struct cac_softc *));
     78 static void	cac_pci_l1_intr_enable __P((struct cac_softc *, int));
     79 static int	cac_pci_l1_fifo_full __P((struct cac_softc *));
     80 
     81 struct cfattach cac_pci_ca = {
     82 	sizeof(struct cac_softc), cac_pci_match, cac_pci_attach
     83 };
     84 
     85 static struct cac_linkage cac_pci_l0 = {
     86 	cac_pci_l0_submit,
     87 	cac_pci_l0_completed,
     88 	cac_pci_l0_intr_pending,
     89 	cac_pci_l0_intr_enable,
     90 	cac_pci_l0_fifo_full
     91 };
     92 
     93 static struct cac_linkage cac_pci_l1 = {
     94 	cac_pci_l1_submit,
     95 	cac_pci_l1_completed,
     96 	cac_pci_l1_intr_pending,
     97 	cac_pci_l1_intr_enable,
     98 	cac_pci_l1_fifo_full
     99 };
    100 
    101 /* This block of code inspired by Compaq's Linux driver. */
    102 struct cac_type {
    103 	int	ct_id;				/* PCI ID */
    104 	int	ct_mmreg;			/* Memory mapped registers */
    105 	struct	cac_linkage *ct_linkage;	/* Command interface */
    106 	char	*ct_typestr;			/* Textual description */
    107 } static cac_type[] = {
    108 #ifdef notdef
    109 	{ 0x0040110e, 0, &cac_pci_lX, "IDA" },
    110 	{ 0x0140110e, 0, &cac_pci_lX, "IDA 2" },
    111 	{ 0x1040110e, 0, &cac_pci_lX, "IAES" },
    112 	{ 0x2040110e, 0, &cac_pci_lX, "SMART" },
    113 #endif
    114 	{ 0x3040110E, 0, &cac_pci_l0, "SMART-2/E" },
    115 	{ 0xae100e11, 1, &cac_pci_l0, "SMART-2/P" },	/* XXX also SA 211? */
    116 	{ 0x40300e11, 1, &cac_pci_l0, "SMART-2/P" },
    117 	{ 0x40310e11, 1, &cac_pci_l0, "SMART-2SL" },
    118 	{ 0x40320e11, 1, &cac_pci_l0, "Smart Array 3200" },
    119 	{ 0x40330e11, 1, &cac_pci_l0, "Smart Array 3100ES" },
    120 	{ 0x40340e11, 1, &cac_pci_l0, "Smart Array 221" },
    121 	{ 0x40400e11, 1, &cac_pci_l1, "Integrated Array" },
    122 	{ 0x40500e11, 1, &cac_pci_l1, "Smart Array 4200" },
    123 	{ 0x40510e11, 1, &cac_pci_l1, "Smart Array 4200ES" },
    124 	{ 0xffffffff, NULL, NULL },
    125 };
    126 
    127 static int
    128 cac_pci_match(parent, match, aux)
    129 	struct device *parent;
    130 	struct cfdata *match;
    131 	void *aux;
    132 {
    133 	struct pci_attach_args *pa;
    134 	int i;
    135 
    136 	pa = (struct pci_attach_args *)aux;
    137 
    138 	for (i = 0; cac_type[i].ct_linkage != NULL; i++)
    139 		if (pa->pa_id == cac_type[i].ct_id)
    140 			return (1);
    141 
    142 	return (0);
    143 }
    144 
    145 static void
    146 cac_pci_attach(parent, self, aux)
    147 	struct device *parent;
    148 	struct device *self;
    149 	void *aux;
    150 {
    151 	struct pci_attach_args *pa;
    152 	struct cac_type *ct;
    153 	struct cac_softc *sc;
    154 	pci_chipset_tag_t pc;
    155 	pci_intr_handle_t ih;
    156 	const char *intrstr;
    157 	pcireg_t csr;
    158 	int mmreg;
    159 
    160 	sc = (struct cac_softc *)self;
    161 	pa = (struct pci_attach_args *)aux;
    162 	pc = pa->pa_pc;
    163 	mmreg = 0;
    164 
    165 	printf(": ");
    166 
    167 	for (ct = cac_type; ct->ct_linkage != NULL; ct++)
    168 		if (pa->pa_id == ct->ct_id)
    169 			break;
    170 
    171 	if ((mmreg = ct->ct_mmreg) != 0)
    172 		if (pci_mapreg_map(pa, PCI_CBMA, PCI_MAPREG_TYPE_MEM, 0,
    173 		    &sc->sc_iot, &sc->sc_ioh, NULL, NULL))
    174 		    	mmreg = 0;
    175 
    176 	if (mmreg == 0)
    177 		if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
    178 		    &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
    179 			printf("can't map i/o space\n");
    180 			return;
    181 		}
    182 
    183 	sc->sc_dmat = pa->pa_dmat;
    184 
    185 	/* Enable the device. */
    186 	csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    187 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    188 		       csr | PCI_COMMAND_MASTER_ENABLE);
    189 
    190 	/* Map and establish the interrupt. */
    191 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    192 	    pa->pa_intrline, &ih)) {
    193 		printf("can't map interrupt\n");
    194 		return;
    195 	}
    196 	intrstr = pci_intr_string(pc, ih);
    197 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, cac_intr, sc);
    198 	if (sc->sc_ih == NULL) {
    199 		printf("can't establish interrupt");
    200 		if (intrstr != NULL)
    201 			printf(" at %s", intrstr);
    202 		printf("\n");
    203 		return;
    204 	}
    205 
    206 	/* Now attach to the bus-independent code */
    207 	sc->sc_typestr = ct->ct_typestr;
    208 	sc->sc_cl = ct->ct_linkage;
    209 	cac_init(sc, intrstr);
    210 }
    211 
    212 static void
    213 cac_pci_l0_submit(sc, addr)
    214 	struct cac_softc *sc;
    215 	paddr_t addr;
    216 {
    217 
    218 	cac_outl(sc, CAC_REG_CMD_FIFO, addr);
    219 }
    220 
    221 static paddr_t
    222 cac_pci_l0_completed(sc)
    223 	struct cac_softc *sc;
    224 {
    225 
    226 	return (cac_inl(sc, CAC_REG_DONE_FIFO));
    227 }
    228 
    229 static int
    230 cac_pci_l0_intr_pending(sc)
    231 	struct cac_softc *sc;
    232 {
    233 
    234 	return (cac_inl(sc, CAC_REG_INT_PENDING));
    235 }
    236 
    237 static void
    238 cac_pci_l0_intr_enable(sc, state)
    239 	struct cac_softc *sc;
    240 	int state;
    241 {
    242 
    243 	cac_outl(sc, CAC_REG_INT_MASK, state);
    244 }
    245 
    246 static int
    247 cac_pci_l0_fifo_full(sc)
    248 	struct cac_softc *sc;
    249 {
    250 
    251 	return (cac_inl(sc, CAC_REG_CMD_FIFO) == 0);
    252 }
    253 
    254 static void
    255 cac_pci_l1_submit(sc, addr)
    256 	struct cac_softc *sc;
    257 	paddr_t addr;
    258 {
    259 
    260 	cac_outl(sc, CAC_42REG_CMD_FIFO, addr);
    261 }
    262 
    263 static paddr_t
    264 cac_pci_l1_completed(sc)
    265 	struct cac_softc *sc;
    266 {
    267 	int32_t val;
    268 
    269 	if ((val = cac_inl(sc, CAC_42REG_DONE_FIFO)) == -1)
    270 		return (0);
    271 
    272 	cac_outl(sc, CAC_42REG_DONE_FIFO, 0);
    273 	return ((paddr_t)val);
    274 }
    275 
    276 static int
    277 cac_pci_l1_intr_pending(sc)
    278 	struct cac_softc *sc;
    279 {
    280 
    281 	return (cac_inl(sc, CAC_42REG_INT_PENDING) &
    282 	    cac_inl(sc, CAC_42REG_STATUS));
    283 }
    284 
    285 static void
    286 cac_pci_l1_intr_enable(sc, state)
    287 	struct cac_softc *sc;
    288 	int state;
    289 {
    290 
    291 	cac_outl(sc, CAC_REG_INT_MASK, (state ? 0 : 8));	/* XXX */
    292 }
    293 
    294 static int
    295 cac_pci_l1_fifo_full(sc)
    296 	struct cac_softc *sc;
    297 {
    298 
    299 	return (~cac_inl(sc, CAC_42REG_CMD_FIFO));
    300 }
    301