xref: /openbsd-src/sys/dev/pci/iha_pci.c (revision 91f110e064cd7c194e59e019b83bb7496c1c84d4)
1 /*	$OpenBSD: iha_pci.c,v 1.12 2007/10/18 21:10:58 otto Exp $ */
2 /*-------------------------------------------------------------------------
3  *
4  * Device driver for the INI-9XXXU/UW or INIC-940/950  PCI SCSI Controller.
5  *
6  * Written for 386bsd and FreeBSD by
7  *	Winston Hung		<winstonh@initio.com>
8  *
9  * Copyright (c) 1997-1999 Initio Corp
10  * Copyright (c) 2000-2002 Ken Westerback
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer,
17  *    without modification, immediately at the beginning of the file.
18  * 2. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *-------------------------------------------------------------------------
34  */
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 
39 #include <dev/pci/pcidevs.h>
40 #include <dev/pci/pcivar.h>
41 
42 #include <scsi/scsi_all.h>
43 #include <scsi/scsiconf.h>
44 
45 #include <dev/ic/iha.h>
46 
47 int  iha_pci_probe(struct device *, void *, void *);
48 void iha_pci_attach(struct device *, struct device *, void *);
49 
50 struct cfattach iha_pci_ca = {
51 	sizeof(struct iha_softc), iha_pci_probe, iha_pci_attach
52 };
53 
54 int
55 iha_pci_probe(parent, match, aux)
56 	struct device *parent;
57 	void *match;
58 	void *aux;
59 {
60 	struct pci_attach_args *pa = aux;
61 
62 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INITIO)
63 		switch (PCI_PRODUCT(pa->pa_id)) {
64 		case PCI_PRODUCT_INITIO_INIC940:
65 		case PCI_PRODUCT_INITIO_INIC941:
66 		case PCI_PRODUCT_INITIO_INIC950:
67 			return (1);
68 		}
69 
70 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_DTCTECH)
71 		switch (PCI_PRODUCT(pa->pa_id)) {
72 		case PCI_PRODUCT_DTCTECH_DMX3194U:
73 			return (1);
74 		}
75 
76 	return (0);
77 }
78 
79 void
80 iha_pci_attach(parent, self, aux)
81 	struct device *parent;
82 	struct device *self;
83 	void *aux;
84 {
85 	struct pci_attach_args *pa = aux;
86 	struct scsibus_attach_args saa;
87 	bus_space_handle_t ioh;
88 	pci_intr_handle_t ih;
89 	struct iha_softc *sc = (void *)self;
90 	bus_space_tag_t iot;
91 	const char *intrstr;
92 	int ioh_valid;
93 
94 	/*
95 	 * XXX - Tried memory mapping (using code from adw and ahc)
96 	 *	 rather that IO mapping, but it didn't work at all..
97 	 */
98 	ioh_valid = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0,
99 	    &iot, &ioh, NULL, NULL, 0);
100 
101 	if (ioh_valid != 0) {
102 		printf("%s: unable to map registers\n", sc->sc_dev.dv_xname);
103 		return;
104 	}
105 
106 	sc->sc_iot  = iot;
107 	sc->sc_ioh  = ioh;
108 	sc->sc_dmat = pa->pa_dmat;
109 
110 	if (pci_intr_map(pa, &ih)) {
111 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
112 		return;
113 	}
114 	intrstr = pci_intr_string(pa->pa_pc, ih);
115 
116 	sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, iha_intr, sc,
117 				       sc->sc_dev.dv_xname);
118 
119 	if (sc->sc_ih == NULL) {
120 		printf(": couldn't establish interrupt");
121 		if (intrstr != NULL)
122 			printf(" at %s", intrstr);
123 		printf("\n");
124 	} else {
125 		if (intrstr != NULL)
126 			printf(": %s\n", intrstr);
127 
128 		if (iha_init_tulip(sc) == 0) {
129 			bzero(&saa, sizeof(saa));
130 			saa.saa_sc_link = &sc->sc_link;
131 			config_found(&sc->sc_dev, &saa, scsiprint);
132 		}
133 	}
134 }
135