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