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