iha_pci.c revision 1.5
1/*	$NetBSD: iha_pci.c,v 1.5 2002/09/30 20:37:46 thorpej 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.5 2002/09/30 20:37:46 thorpej 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
68static int  iha_pci_probe(struct device *, struct cfdata *, void *);
69static void iha_pci_attach(struct device *, struct device *, void *);
70
71CFATTACH_DECL(iha_pci, sizeof(struct iha_softc),
72    iha_pci_probe, iha_pci_attach, NULL, NULL)
73
74static int
75iha_pci_probe(parent, match, aux)
76	struct device *parent;
77	struct cfdata *match;
78	void *aux;
79{
80	struct pci_attach_args *pa = aux;
81
82	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INITIO)
83		return (0);
84
85	switch (PCI_PRODUCT(pa->pa_id)) {
86	case PCI_PRODUCT_INITIO_I940:
87	case PCI_PRODUCT_INITIO_I950:
88		return (1);
89	}
90
91	return (0);
92}
93
94static void
95iha_pci_attach(parent, self, aux)
96	struct device *parent;
97	struct device *self;
98	void *aux;
99{
100	struct pci_attach_args *pa = aux;
101	bus_space_tag_t iot;
102	bus_space_handle_t ioh;
103	pci_intr_handle_t ih;
104	struct iha_softc *sc = (struct iha_softc *)self;
105	const char *intrstr;
106	pcireg_t command;
107	int ioh_valid;
108	char devinfo[256];
109
110	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
111	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
112
113	command  = pci_conf_read(pa->pa_pc,pa->pa_tag,PCI_COMMAND_STATUS_REG);
114	command |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_PARITY_ENABLE;
115
116	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
117
118	/*
119	 * XXX - Tried memory mapping (using code from adw and ahc)
120	 *	 rather that IO mapping, but it didn't work at all..
121	 */
122	ioh_valid = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0,
123	    &iot, &ioh, NULL, NULL);
124
125	if (ioh_valid != 0) {
126		printf("%s: unable to map registers\n", sc->sc_dev.dv_xname);
127		return;
128	}
129
130	sc->sc_iot  = iot;
131	sc->sc_ioh  = ioh;
132	sc->sc_dmat = pa->pa_dmat;
133
134	if (pci_intr_map(pa, &ih)) {
135		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
136		return;
137	}
138	intrstr = pci_intr_string(pa->pa_pc, ih);
139
140	sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, iha_intr, sc);
141
142	if (sc->sc_ih == NULL) {
143		printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
144		if (intrstr != NULL)
145			printf(" at %s", intrstr);
146		printf("\n");
147		return;
148	}
149	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
150
151	iha_attach(sc);
152}
153