xref: /netbsd/sys/dev/pci/iha_pci.c (revision bf9ec67e)
1 /*	$NetBSD: iha_pci.c,v 1.3 2001/11/13 07:48:45 lukem 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/cdefs.h>
51 __KERNEL_RCSID(0, "$NetBSD: iha_pci.c,v 1.3 2001/11/13 07:48:45 lukem Exp $");
52 
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/device.h>
56 
57 #include <uvm/uvm_extern.h>
58 
59 #include <dev/pci/pcidevs.h>
60 #include <dev/pci/pcivar.h>
61 
62 #include <dev/scsipi/scsipi_all.h>
63 #include <dev/scsipi/scsi_all.h>
64 #include <dev/scsipi/scsiconf.h>
65 
66 #include <dev/ic/ihavar.h>
67 
68 static int  iha_pci_probe(struct device *, struct cfdata *, void *);
69 static void iha_pci_attach(struct device *, struct device *, void *);
70 
71 struct cfattach iha_pci_ca = {
72 	sizeof(struct iha_softc), iha_pci_probe, iha_pci_attach
73 };
74 
75 static int
76 iha_pci_probe(parent, match, aux)
77 	struct device *parent;
78 	struct cfdata *match;
79 	void *aux;
80 {
81 	struct pci_attach_args *pa = aux;
82 
83 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INITIO)
84 		return (0);
85 
86 	switch (PCI_PRODUCT(pa->pa_id)) {
87 	case PCI_PRODUCT_INITIO_I940:
88 	case PCI_PRODUCT_INITIO_I950:
89 		return (1);
90 	}
91 
92 	return (0);
93 }
94 
95 static void
96 iha_pci_attach(parent, self, aux)
97 	struct device *parent;
98 	struct device *self;
99 	void *aux;
100 {
101 	struct pci_attach_args *pa = aux;
102 	bus_space_tag_t iot;
103 	bus_space_handle_t ioh;
104 	pci_intr_handle_t ih;
105 	struct iha_softc *sc = (struct iha_softc *)self;
106 	const char *intrstr;
107 	pcireg_t command;
108 	int ioh_valid;
109 	char devinfo[256];
110 
111 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
112 	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
113 
114 	command  = pci_conf_read(pa->pa_pc,pa->pa_tag,PCI_COMMAND_STATUS_REG);
115 	command |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_PARITY_ENABLE;
116 
117 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
118 
119 	/*
120 	 * XXX - Tried memory mapping (using code from adw and ahc)
121 	 *	 rather that IO mapping, but it didn't work at all..
122 	 */
123 	ioh_valid = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0,
124 	    &iot, &ioh, NULL, NULL);
125 
126 	if (ioh_valid != 0) {
127 		printf("%s: unable to map registers\n", sc->sc_dev.dv_xname);
128 		return;
129 	}
130 
131 	sc->sc_iot  = iot;
132 	sc->sc_ioh  = ioh;
133 	sc->sc_dmat = pa->pa_dmat;
134 
135 	if (pci_intr_map(pa, &ih)) {
136 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
137 		return;
138 	}
139 	intrstr = pci_intr_string(pa->pa_pc, ih);
140 
141 	sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, iha_intr, sc);
142 
143 	if (sc->sc_ih == NULL) {
144 		printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
145 		if (intrstr != NULL)
146 			printf(" at %s", intrstr);
147 		printf("\n");
148 		return;
149 	}
150 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
151 
152 	iha_attach(sc);
153 }
154