Home | History | Annotate | Line # | Download | only in pci
iop_pci.c revision 1.22.4.2
      1  1.22.4.2      yamt /*	$NetBSD: iop_pci.c,v 1.22.4.2 2009/05/16 10:41:35 yamt Exp $	*/
      2       1.1        ad 
      3       1.1        ad /*-
      4      1.12        ad  * 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  *
     19       1.1        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1        ad  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1        ad  */
     31       1.1        ad 
     32       1.1        ad /*
     33       1.1        ad  * PCI front-end for `iop' driver.
     34       1.1        ad  */
     35       1.7     lukem 
     36       1.7     lukem #include <sys/cdefs.h>
     37  1.22.4.2      yamt __KERNEL_RCSID(0, "$NetBSD: iop_pci.c,v 1.22.4.2 2009/05/16 10:41:35 yamt Exp $");
     38       1.1        ad 
     39       1.1        ad #include <sys/param.h>
     40       1.1        ad #include <sys/systm.h>
     41       1.1        ad #include <sys/kernel.h>
     42       1.1        ad #include <sys/device.h>
     43       1.1        ad #include <sys/queue.h>
     44       1.1        ad #include <sys/proc.h>
     45       1.1        ad 
     46       1.1        ad #include <machine/endian.h>
     47      1.21        ad #include <sys/bus.h>
     48       1.1        ad 
     49       1.1        ad #include <dev/pci/pcidevs.h>
     50       1.1        ad #include <dev/pci/pcivar.h>
     51       1.1        ad 
     52       1.1        ad #include <dev/i2o/i2o.h>
     53       1.1        ad #include <dev/i2o/iopreg.h>
     54       1.4        ad #include <dev/i2o/iopio.h>
     55       1.1        ad #include <dev/i2o/iopvar.h>
     56       1.1        ad 
     57       1.5        ad #define	PCI_INTERFACE_I2O_POLLED	0x00
     58       1.5        ad #define	PCI_INTERFACE_I2O_INTRDRIVEN	0x01
     59       1.1        ad 
     60  1.22.4.2      yamt static void	iop_pci_attach(device_t, device_t, void *);
     61  1.22.4.2      yamt static int	iop_pci_match(device_t, cfdata_t, void *);
     62       1.1        ad 
     63       1.9   thorpej CFATTACH_DECL(iop_pci, sizeof(struct iop_softc),
     64      1.10   thorpej     iop_pci_match, iop_pci_attach, NULL, NULL);
     65       1.1        ad 
     66       1.1        ad static int
     67  1.22.4.2      yamt iop_pci_match(device_t parent, cfdata_t match, void *aux)
     68       1.1        ad {
     69       1.1        ad 	struct pci_attach_args *pa;
     70      1.14        ad 	u_int product, vendor;
     71      1.14        ad 	pcireg_t reg;
     72       1.2        ad 
     73       1.2        ad 	pa = aux;
     74       1.1        ad 
     75      1.15     perry 	/*
     76       1.1        ad 	 * Look for an "intelligent I/O processor" that adheres to the I2O
     77       1.1        ad 	 * specification.  Ignore the device if it doesn't support interrupt
     78       1.1        ad 	 * driven operation.
     79       1.1        ad 	 */
     80       1.1        ad 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_I2O &&
     81       1.1        ad 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_I2O_STANDARD &&
     82       1.1        ad 	    PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_I2O_INTRDRIVEN)
     83       1.1        ad 		return (1);
     84      1.12        ad 
     85      1.12        ad 	/*
     86      1.14        ad 	 * Match boards that don't conform exactly to the spec.
     87      1.12        ad 	 */
     88      1.14        ad 	vendor = PCI_VENDOR(pa->pa_id);
     89      1.14        ad 	product = PCI_PRODUCT(pa->pa_id);
     90      1.14        ad 
     91      1.15     perry 	if (vendor == PCI_VENDOR_DPT &&
     92      1.14        ad 	    (product == PCI_PRODUCT_DPT_RAID_I2O ||
     93      1.14        ad 	    product == PCI_PRODUCT_DPT_RAID_2005S))
     94      1.11   msaitoh 		return (1);
     95       1.1        ad 
     96      1.14        ad 	if (vendor == PCI_VENDOR_INTEL &&
     97      1.14        ad 	    (product == PCI_PRODUCT_INTEL_80960RM_2 ||
     98      1.14        ad 	    product == PCI_PRODUCT_INTEL_80960_RP)) {
     99      1.14        ad 		reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
    100      1.14        ad 		if (PCI_VENDOR(reg) == PCI_VENDOR_PROMISE)
    101      1.14        ad 			return (1);
    102      1.14        ad 	}
    103      1.14        ad 
    104       1.1        ad 	return (0);
    105       1.1        ad }
    106       1.1        ad 
    107       1.1        ad static void
    108  1.22.4.2      yamt iop_pci_attach(device_t parent, device_t self, void *aux)
    109       1.1        ad {
    110       1.1        ad 	struct pci_attach_args *pa;
    111       1.1        ad 	struct iop_softc *sc;
    112       1.1        ad 	pci_chipset_tag_t pc;
    113       1.1        ad 	pci_intr_handle_t ih;
    114       1.1        ad 	const char *intrstr;
    115       1.1        ad 	pcireg_t reg;
    116       1.5        ad 	int i;
    117       1.2        ad 
    118  1.22.4.2      yamt 	sc = device_private(self);
    119       1.1        ad 	pa = (struct pci_attach_args *)aux;
    120       1.1        ad 	pc = pa->pa_pc;
    121       1.1        ad 	printf(": ");
    122       1.1        ad 
    123       1.2        ad 	/*
    124       1.2        ad 	 * The kernel always uses the first memory mapping to communicate
    125       1.1        ad 	 * with the IOP.
    126       1.1        ad 	 */
    127       1.1        ad 	for (i = PCI_MAPREG_START; i < PCI_MAPREG_END; i += 4) {
    128       1.1        ad 		reg = pci_conf_read(pc, pa->pa_tag, i);
    129       1.6        ad 		if (PCI_MAPREG_TYPE(reg) == PCI_MAPREG_TYPE_MEM) {
    130       1.6        ad 			sc->sc_memaddr = PCI_MAPREG_MEM_ADDR(reg);
    131       1.1        ad 			break;
    132       1.6        ad 		}
    133       1.1        ad 	}
    134       1.1        ad 	if (i == PCI_MAPREG_END) {
    135       1.1        ad 		printf("can't find mapping\n");
    136       1.1        ad 		return;
    137       1.1        ad 	}
    138       1.1        ad 
    139       1.5        ad 	/* Map the register window. */
    140       1.5        ad 	if (pci_mapreg_map(pa, i, PCI_MAPREG_TYPE_MEM, 0, &sc->sc_iot,
    141       1.5        ad 	    &sc->sc_ioh, NULL, NULL)) {
    142      1.22    cegger 		aprint_error_dev(&sc->sc_dv, "can't map register window\n");
    143       1.1        ad 		return;
    144      1.11   msaitoh 	}
    145      1.11   msaitoh 
    146      1.11   msaitoh 	/* Map the 2nd register window. */
    147      1.14        ad 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_DPT &&
    148      1.14        ad 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_DPT_RAID_2005S) {
    149      1.11   msaitoh 		i += 4;	/* next BAR */
    150      1.11   msaitoh 		if (i == PCI_MAPREG_END) {
    151      1.11   msaitoh 			printf("can't find mapping\n");
    152      1.11   msaitoh 			return;
    153      1.11   msaitoh 		}
    154      1.11   msaitoh 
    155      1.11   msaitoh #if 0
    156      1.11   msaitoh 		/* Should we check it? (see FreeBSD's asr driver) */
    157      1.11   msaitoh 		reg = pci_conf_read(pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
    158      1.11   msaitoh 		printf("subid %x, %x\n", PCI_VENDOR(reg), PCI_PRODUCT(reg));
    159      1.11   msaitoh #endif
    160      1.11   msaitoh 		if (pci_mapreg_map(pa, i, PCI_MAPREG_TYPE_MEM, 0,
    161      1.12        ad 		    &sc->sc_msg_iot, &sc->sc_msg_ioh, NULL, NULL)) {
    162      1.22    cegger 			aprint_error_dev(&sc->sc_dv, "can't map 2nd register window\n");
    163      1.11   msaitoh 			return;
    164      1.11   msaitoh 		}
    165      1.11   msaitoh 	} else {
    166      1.11   msaitoh 		/* iop devices other than 2005S */
    167      1.12        ad 		sc->sc_msg_iot = sc->sc_iot;
    168      1.12        ad 		sc->sc_msg_ioh = sc->sc_ioh;
    169       1.1        ad 	}
    170       1.1        ad 
    171       1.6        ad 	sc->sc_pcibus = pa->pa_bus;
    172       1.6        ad 	sc->sc_pcidev = pa->pa_device;
    173       1.1        ad 	sc->sc_dmat = pa->pa_dmat;
    174       1.5        ad 	sc->sc_bus_memt = pa->pa_memt;
    175       1.5        ad 	sc->sc_bus_iot = pa->pa_iot;
    176       1.1        ad 
    177       1.1        ad 	/* Enable the device. */
    178       1.1        ad 	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    179       1.1        ad 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    180       1.1        ad 		       reg | PCI_COMMAND_MASTER_ENABLE);
    181       1.1        ad 
    182      1.20        ad 	/* Map and establish the interrupt.. */
    183       1.3  sommerfe 	if (pci_intr_map(pa, &ih)) {
    184       1.1        ad 		printf("can't map interrupt\n");
    185       1.1        ad 		return;
    186       1.1        ad 	}
    187       1.1        ad 	intrstr = pci_intr_string(pc, ih);
    188       1.1        ad 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, iop_intr, sc);
    189       1.1        ad 	if (sc->sc_ih == NULL) {
    190       1.1        ad 		printf("can't establish interrupt");
    191       1.1        ad 		if (intrstr != NULL)
    192       1.1        ad 			printf(" at %s", intrstr);
    193       1.1        ad 		printf("\n");
    194       1.1        ad 		return;
    195       1.1        ad 	}
    196       1.1        ad 
    197       1.1        ad 	/* Attach to the bus-independent code. */
    198       1.1        ad 	iop_init(sc, intrstr);
    199       1.1        ad }
    200