Home | History | Annotate | Line # | Download | only in pci
cac_pci.c revision 1.1
      1 /*	$NetBSD: cac_pci.c,v 1.1 2000/03/16 14:52:23 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.1 2000/03/16 14:52:23 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 	struct	cac_linkage *ct_linkage;	/* Command interface */
    105 	char	*ct_typestr;			/* Textual description */
    106 } static cac_type[] = {
    107 #ifdef notdef
    108 	{ 0x0040110e, &cac_pci_lX, "IDA" },
    109 	{ 0x0140110e, &cac_pci_lX, "IDA 2" },
    110 	{ 0x1040110e, &cac_pci_lX, "IAES" },
    111 	{ 0x2040110e, &cac_pci_lX, "SMART" },
    112 #endif
    113 	{ 0x3040110E, &cac_pci_l0, "SMART-2/E" },
    114 	{ 0xae100e11, &cac_pci_l0, "SMART-2/P" },	/* XXX also SA 211? */
    115 	{ 0x40300e11, &cac_pci_l0, "SMART-2/P" },
    116 	{ 0x40310e11, &cac_pci_l0, "SMART-2SL" },
    117 	{ 0x40320e11, &cac_pci_l0, "Smart Array 3200" },
    118 	{ 0x40330e11, &cac_pci_l0, "Smart Array 3100ES" },
    119 	{ 0x40340e11, &cac_pci_l0, "Smart Array 221" },
    120 	{ 0x40400e11, &cac_pci_l1, "Integrated Array" },
    121 	{ 0x40500e11, &cac_pci_l1, "Smart Array 4200" },
    122 	{ 0x40510e11, &cac_pci_l1, "Smart Array 4200ES" },
    123 	{ 0xffffffff, NULL, NULL },
    124 };
    125 
    126 static int
    127 cac_pci_match(parent, match, aux)
    128 	struct device *parent;
    129 	struct cfdata *match;
    130 	void *aux;
    131 {
    132 	struct pci_attach_args *pa;
    133 	int i;
    134 
    135 	pa = (struct pci_attach_args *)aux;
    136 
    137 	for (i = 0; cac_type[i].ct_linkage != NULL; i++)
    138 		if (pa->pa_id == cac_type[i].ct_id)
    139 			return (1);
    140 
    141 	return (0);
    142 }
    143 
    144 static void
    145 cac_pci_attach(parent, self, aux)
    146 	struct device *parent;
    147 	struct device *self;
    148 	void *aux;
    149 {
    150 	struct pci_attach_args *pa;
    151 	struct cac_softc *sc;
    152 	pci_chipset_tag_t pc;
    153 	pci_intr_handle_t ih;
    154 	const char *intrstr;
    155 	pcireg_t csr;
    156 	int i;
    157 
    158 	sc = (struct cac_softc *)self;
    159 	pa = (struct pci_attach_args *)aux;
    160 	pc = pa->pa_pc;
    161 
    162 	printf(": ");
    163 
    164 	if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, &sc->sc_iot,
    165 	    &sc->sc_ioh, NULL, NULL)) {
    166 		printf("can't map i/o space\n");
    167 		return;
    168 	}
    169 
    170 	sc->sc_dmat = pa->pa_dmat;
    171 
    172 	/* Enable the device. */
    173 	csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    174 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    175 		       csr | PCI_COMMAND_MASTER_ENABLE);
    176 
    177 	/* Map and establish the interrupt. */
    178 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    179 	    pa->pa_intrline, &ih)) {
    180 		printf("can't map interrupt\n");
    181 		return;
    182 	}
    183 	intrstr = pci_intr_string(pc, ih);
    184 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, cac_intr, sc);
    185 	if (sc->sc_ih == NULL) {
    186 		printf("can't establish interrupt");
    187 		if (intrstr != NULL)
    188 			printf(" at %s", intrstr);
    189 		printf("\n");
    190 		return;
    191 	}
    192 
    193 	/* Now attach to the bus-independent code */
    194 	for (i = 0; cac_type[i].ct_linkage != NULL; i++)
    195 		if (pa->pa_id == cac_type[i].ct_id)
    196 			break;
    197 	sc->sc_typestr = cac_type[i].ct_typestr;
    198 	sc->sc_cl = cac_type[i].ct_linkage;
    199 	cac_init(sc, intrstr);
    200 }
    201 
    202 static void
    203 cac_pci_l0_submit(sc, addr)
    204 	struct cac_softc *sc;
    205 	paddr_t addr;
    206 {
    207 
    208 	cac_outl(sc, CAC_REG_CMD_FIFO, addr);
    209 }
    210 
    211 static paddr_t
    212 cac_pci_l0_completed(sc)
    213 	struct cac_softc *sc;
    214 {
    215 
    216 	return (cac_inl(sc, CAC_REG_DONE_FIFO));
    217 }
    218 
    219 static int
    220 cac_pci_l0_intr_pending(sc)
    221 	struct cac_softc *sc;
    222 {
    223 
    224 	return (cac_inl(sc, CAC_REG_INT_PENDING));
    225 }
    226 
    227 static void
    228 cac_pci_l0_intr_enable(sc, state)
    229 	struct cac_softc *sc;
    230 	int state;
    231 {
    232 
    233 	cac_outl(sc, CAC_REG_INT_MASK, state);
    234 }
    235 
    236 static int
    237 cac_pci_l0_fifo_full(sc)
    238 	struct cac_softc *sc;
    239 {
    240 
    241 	return (cac_inl(sc, CAC_REG_CMD_FIFO) == 0);
    242 }
    243 
    244 static void
    245 cac_pci_l1_submit(sc, addr)
    246 	struct cac_softc *sc;
    247 	paddr_t addr;
    248 {
    249 
    250 	cac_outl(sc, CAC_42REG_CMD_FIFO, addr);
    251 }
    252 
    253 static paddr_t
    254 cac_pci_l1_completed(sc)
    255 	struct cac_softc *sc;
    256 {
    257 	int32_t val;
    258 
    259 	if ((val = cac_inl(sc, CAC_42REG_DONE_FIFO)) == -1)
    260 		return (0);
    261 
    262 	cac_outl(sc, CAC_42REG_DONE_FIFO, 0);
    263 	return ((paddr_t)val);
    264 }
    265 
    266 static int
    267 cac_pci_l1_intr_pending(sc)
    268 	struct cac_softc *sc;
    269 {
    270 
    271 	return (cac_inl(sc, CAC_42REG_INT_PENDING) &
    272 	    cac_inl(sc, CAC_42REG_STATUS));
    273 }
    274 
    275 static void
    276 cac_pci_l1_intr_enable(sc, state)
    277 	struct cac_softc *sc;
    278 	int state;
    279 {
    280 
    281 	cac_outl(sc, CAC_REG_INT_MASK, (state ? 0 : 8));	/* XXX */
    282 }
    283 
    284 static int
    285 cac_pci_l1_fifo_full(sc)
    286 	struct cac_softc *sc;
    287 {
    288 
    289 	return (~cac_inl(sc, CAC_42REG_CMD_FIFO));
    290 }
    291