iha_pci.c revision 1.10
1/*	$NetBSD: iha_pci.c,v 1.10 2005/06/16 14:32:09 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@ceres.dti.ne.jp> 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.10 2005/06/16 14:32:09 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(struct device *, struct cfdata *, void *);
60static void iha_pci_attach(struct device *, struct device *, void *);
61
62CFATTACH_DECL(iha_pci, sizeof(struct iha_softc),
63    iha_pci_match, iha_pci_attach, NULL, NULL);
64
65static int
66iha_pci_match(struct device *parent, struct cfdata *match, 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(struct device *parent, struct device *self, void *aux)
84{
85	struct pci_attach_args *pa = aux;
86	bus_space_tag_t iot;
87	bus_space_handle_t ioh;
88	pci_intr_handle_t ih;
89	struct iha_softc *sc = (struct iha_softc *)self;
90	const char *intrstr;
91	pcireg_t command;
92	int ioh_valid;
93	char devinfo[256];
94
95	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
96	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
97
98	command  = pci_conf_read(pa->pa_pc,pa->pa_tag,PCI_COMMAND_STATUS_REG);
99	command |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_PARITY_ENABLE;
100
101	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
102
103	/*
104	 * XXX - Tried memory mapping (using code from adw and ahc)
105	 *	 rather that IO mapping, but it didn't work at all..
106	 */
107	ioh_valid = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0,
108	    &iot, &ioh, NULL, NULL);
109
110	if (ioh_valid != 0) {
111		printf("%s: unable to map registers\n", sc->sc_dev.dv_xname);
112		return;
113	}
114
115	sc->sc_iot  = iot;
116	sc->sc_ioh  = ioh;
117	sc->sc_dmat = pa->pa_dmat;
118
119	if (pci_intr_map(pa, &ih)) {
120		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
121		return;
122	}
123	intrstr = pci_intr_string(pa->pa_pc, ih);
124
125	sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, iha_intr, sc);
126
127	if (sc->sc_ih == NULL) {
128		printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
129		if (intrstr != NULL)
130			printf(" at %s", intrstr);
131		printf("\n");
132		return;
133	}
134	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
135
136	iha_attach(sc);
137}
138