Home | History | Annotate | Line # | Download | only in pci
iop_pci.c revision 1.3.2.6
      1  1.3.2.6  christos /*	$NetBSD: iop_pci.c,v 1.3.2.6 2002/11/27 21:59:09 christos Exp $	*/
      2      1.1        ad 
      3      1.1        ad /*-
      4  1.3.2.6  christos  * Copyright (c) 2000, 2001, 2002 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 Andrew 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 `iop' driver.
     41      1.1        ad  */
     42  1.3.2.3   nathanw 
     43  1.3.2.3   nathanw #include <sys/cdefs.h>
     44  1.3.2.6  christos __KERNEL_RCSID(0, "$NetBSD: iop_pci.c,v 1.3.2.6 2002/11/27 21:59:09 christos Exp $");
     45      1.1        ad 
     46      1.1        ad #include "opt_i2o.h"
     47      1.1        ad 
     48      1.1        ad #include <sys/param.h>
     49      1.1        ad #include <sys/systm.h>
     50      1.1        ad #include <sys/kernel.h>
     51      1.1        ad #include <sys/device.h>
     52      1.1        ad #include <sys/queue.h>
     53      1.1        ad #include <sys/proc.h>
     54      1.1        ad 
     55      1.1        ad #include <machine/endian.h>
     56      1.1        ad #include <machine/bus.h>
     57      1.1        ad 
     58      1.1        ad #include <dev/pci/pcidevs.h>
     59      1.1        ad #include <dev/pci/pcivar.h>
     60      1.1        ad 
     61      1.1        ad #include <dev/i2o/i2o.h>
     62      1.1        ad #include <dev/i2o/iopreg.h>
     63  1.3.2.1   nathanw #include <dev/i2o/iopio.h>
     64      1.1        ad #include <dev/i2o/iopvar.h>
     65      1.1        ad 
     66  1.3.2.1   nathanw #define	PCI_INTERFACE_I2O_POLLED	0x00
     67  1.3.2.1   nathanw #define	PCI_INTERFACE_I2O_INTRDRIVEN	0x01
     68      1.1        ad 
     69      1.1        ad static void	iop_pci_attach(struct device *, struct device *, void *);
     70      1.1        ad static int	iop_pci_match(struct device *, struct cfdata *, void *);
     71      1.1        ad 
     72  1.3.2.4   nathanw CFATTACH_DECL(iop_pci, sizeof(struct iop_softc),
     73  1.3.2.4   nathanw     iop_pci_match, iop_pci_attach, NULL, NULL);
     74      1.1        ad 
     75      1.1        ad static int
     76      1.1        ad iop_pci_match(struct device *parent, struct cfdata *match, void *aux)
     77      1.1        ad {
     78      1.1        ad 	struct pci_attach_args *pa;
     79      1.2        ad 
     80      1.2        ad 	pa = aux;
     81      1.1        ad 
     82      1.1        ad 	/*
     83      1.1        ad 	 * Look for an "intelligent I/O processor" that adheres to the I2O
     84      1.1        ad 	 * specification.  Ignore the device if it doesn't support interrupt
     85      1.1        ad 	 * driven operation.
     86      1.1        ad 	 */
     87      1.1        ad 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_I2O &&
     88      1.1        ad 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_I2O_STANDARD &&
     89      1.1        ad 	    PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_I2O_INTRDRIVEN)
     90      1.1        ad 		return (1);
     91  1.3.2.6  christos 
     92  1.3.2.6  christos 	/*
     93  1.3.2.6  christos 	 * Match DPT/Adaptec boards that don't conform exactly to the spec.
     94  1.3.2.6  christos 	 */
     95  1.3.2.5   nathanw 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_DPT &&
     96  1.3.2.6  christos 	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_DPT_RAID_I2O ||
     97  1.3.2.6  christos 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_DPT_RAID_2005S))
     98  1.3.2.5   nathanw 		return (1);
     99      1.1        ad 
    100      1.1        ad 	return (0);
    101      1.1        ad }
    102      1.1        ad 
    103      1.1        ad static void
    104      1.1        ad iop_pci_attach(struct device *parent, struct device *self, void *aux)
    105      1.1        ad {
    106      1.1        ad 	struct pci_attach_args *pa;
    107      1.1        ad 	struct iop_softc *sc;
    108      1.1        ad 	pci_chipset_tag_t pc;
    109      1.1        ad 	pci_intr_handle_t ih;
    110      1.1        ad 	const char *intrstr;
    111      1.1        ad 	pcireg_t reg;
    112  1.3.2.1   nathanw 	int i;
    113      1.2        ad 
    114      1.1        ad 	sc = (struct iop_softc *)self;
    115      1.1        ad 	pa = (struct pci_attach_args *)aux;
    116      1.1        ad 	pc = pa->pa_pc;
    117      1.1        ad 	printf(": ");
    118      1.1        ad 
    119      1.2        ad 	/*
    120      1.2        ad 	 * The kernel always uses the first memory mapping to communicate
    121      1.1        ad 	 * with the IOP.
    122      1.1        ad 	 */
    123      1.1        ad 	for (i = PCI_MAPREG_START; i < PCI_MAPREG_END; i += 4) {
    124      1.1        ad 		reg = pci_conf_read(pc, pa->pa_tag, i);
    125  1.3.2.2   nathanw 		if (PCI_MAPREG_TYPE(reg) == PCI_MAPREG_TYPE_MEM) {
    126  1.3.2.2   nathanw 			sc->sc_memaddr = PCI_MAPREG_MEM_ADDR(reg);
    127      1.1        ad 			break;
    128  1.3.2.2   nathanw 		}
    129      1.1        ad 	}
    130      1.1        ad 	if (i == PCI_MAPREG_END) {
    131      1.1        ad 		printf("can't find mapping\n");
    132      1.1        ad 		return;
    133      1.1        ad 	}
    134      1.1        ad 
    135  1.3.2.1   nathanw 	/* Map the register window. */
    136  1.3.2.1   nathanw 	if (pci_mapreg_map(pa, i, PCI_MAPREG_TYPE_MEM, 0, &sc->sc_iot,
    137  1.3.2.1   nathanw 	    &sc->sc_ioh, NULL, NULL)) {
    138  1.3.2.1   nathanw 		printf("%s: can't map register window\n", sc->sc_dv.dv_xname);
    139      1.1        ad 		return;
    140  1.3.2.5   nathanw 	}
    141  1.3.2.5   nathanw 
    142  1.3.2.5   nathanw 	/* Map the 2nd register window. */
    143  1.3.2.5   nathanw 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_DPT_RAID_2005S) {
    144  1.3.2.5   nathanw 		i += 4;	/* next BAR */
    145  1.3.2.5   nathanw 		if (i == PCI_MAPREG_END) {
    146  1.3.2.5   nathanw 			printf("can't find mapping\n");
    147  1.3.2.5   nathanw 			return;
    148  1.3.2.5   nathanw 		}
    149  1.3.2.5   nathanw 
    150  1.3.2.5   nathanw #if 0
    151  1.3.2.5   nathanw 		/* Should we check it? (see FreeBSD's asr driver) */
    152  1.3.2.5   nathanw 		reg = pci_conf_read(pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
    153  1.3.2.5   nathanw 		printf("subid %x, %x\n", PCI_VENDOR(reg), PCI_PRODUCT(reg));
    154  1.3.2.5   nathanw #endif
    155  1.3.2.5   nathanw 		if (pci_mapreg_map(pa, i, PCI_MAPREG_TYPE_MEM, 0,
    156  1.3.2.6  christos 		    &sc->sc_msg_iot, &sc->sc_msg_ioh, NULL, NULL)) {
    157  1.3.2.6  christos 			printf("%s: can't map 2nd register window\n",
    158  1.3.2.6  christos 			    sc->sc_dv.dv_xname);
    159  1.3.2.5   nathanw 			return;
    160  1.3.2.5   nathanw 		}
    161  1.3.2.5   nathanw 	} else {
    162  1.3.2.5   nathanw 		/* iop devices other than 2005S */
    163  1.3.2.6  christos 		sc->sc_msg_iot = sc->sc_iot;
    164  1.3.2.6  christos 		sc->sc_msg_ioh = sc->sc_ioh;
    165      1.1        ad 	}
    166      1.1        ad 
    167  1.3.2.2   nathanw 	sc->sc_pcibus = pa->pa_bus;
    168  1.3.2.2   nathanw 	sc->sc_pcidev = pa->pa_device;
    169      1.1        ad 	sc->sc_dmat = pa->pa_dmat;
    170  1.3.2.1   nathanw 	sc->sc_bus_memt = pa->pa_memt;
    171  1.3.2.1   nathanw 	sc->sc_bus_iot = pa->pa_iot;
    172      1.1        ad 
    173      1.1        ad 	/* Enable the device. */
    174      1.1        ad 	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    175      1.1        ad 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    176      1.1        ad 		       reg | PCI_COMMAND_MASTER_ENABLE);
    177      1.1        ad 
    178      1.1        ad 	/* Map and establish the interrupt.  XXX IPL_BIO. */
    179      1.3  sommerfe 	if (pci_intr_map(pa, &ih)) {
    180      1.1        ad 		printf("can't map interrupt\n");
    181      1.1        ad 		return;
    182      1.1        ad 	}
    183      1.1        ad 	intrstr = pci_intr_string(pc, ih);
    184      1.1        ad 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, iop_intr, sc);
    185      1.1        ad 	if (sc->sc_ih == NULL) {
    186      1.1        ad 		printf("can't establish interrupt");
    187      1.1        ad 		if (intrstr != NULL)
    188      1.1        ad 			printf(" at %s", intrstr);
    189      1.1        ad 		printf("\n");
    190      1.1        ad 		return;
    191      1.1        ad 	}
    192      1.1        ad 
    193      1.1        ad 	/* Attach to the bus-independent code. */
    194      1.1        ad 	iop_init(sc, intrstr);
    195      1.1        ad }
    196