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