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