Annotation of sys/dev/pci/trm_pci.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: trm_pci.c,v 1.4 2006/11/28 23:59:45 dlg Exp $
2: * ------------------------------------------------------------
3: * O.S : OpenBSD
4: * FILE NAME : trm_pci.c
5: * BY : Erich Chen (erich@tekram.com.tw)
6: * Description: Device Driver for Tekram DC395U/UW/F,DC315/U
7: * PCI SCSI Bus Master Host Adapter
8: * (SCSI chip set used Tekram ASIC TRM-S1040)
9: * (C)Copyright 1995-1999 Tekram Technology Co., Ltd.
10: * (C)Copyright 2001-2002 Ashley R. Martens and Kenneth R. Westerback
11: * ------------------------------------------------------------
12: * HISTORY:
13: *
14: * REV# DATE NAME DESCRIPTION
15: * 1.00 05/01/99 ERICH CHEN First released for NetBSD 1.4.x
16: * 1.01 00/00/00 MARTIN AKESSON Port to OpenBSD 2.8
17: * 1.02 Sep 19, 2001 ASHLEY MARTENS Cleanup and formatting
18: * ------------------------------------------------------------
19: *
20: * Redistribution and use in source and binary forms, with or without
21: * modification, are permitted provided that the following conditions
22: * are met:
23: * 1. Redistributions of source code must retain the above copyright
24: * notice, this list of conditions and the following disclaimer.
25: * 2. Redistributions in binary form must reproduce the above copyright
26: * notice, this list of conditions and the following disclaimer in the
27: * documentation and/or other materials provided with the distribution.
28: * 3. The name of the author may not be used to endorse or promote products
29: * derived from this software without specific prior written permission.
30: *
31: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
32: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
35: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41: *
42: * ------------------------------------------------------------
43: */
44:
45: #include <sys/param.h>
46: #include <sys/systm.h>
47: #include <sys/device.h>
48:
49: #include <dev/pci/pcidevs.h>
50: #include <dev/pci/pcivar.h>
51:
52: #include <scsi/scsi_all.h>
53: #include <scsi/scsiconf.h>
54:
55: #include <dev/ic/trm.h>
56:
57: int trm_pci_probe (struct device *, void *, void *);
58: void trm_pci_attach (struct device *, struct device *, void *);
59:
60: struct cfattach trm_pci_ca = {
61: sizeof(struct trm_softc),
62: trm_pci_probe,
63: trm_pci_attach,
64: NULL, /* Detach */
65: NULL, /* Activate */
66: };
67:
68:
69: /*
70: * ------------------------------------------------------------
71: * Function : trm_pci_probe
72: * Purpose : Check the slots looking for a board we recognize.
73: * If we find one, note ti's address (slot) and call
74: * the actual probe routine to check it out.
75: * Inputs :
76: * ------------------------------------------------------------
77: */
78: int
79: trm_pci_probe(struct device *parent, void *match, void *aux)
80: {
81: struct pci_attach_args *pa = aux;
82:
83: if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_TEKRAM2) {
84: switch (PCI_PRODUCT(pa->pa_id)) {
85: case PCI_PRODUCT_TEKRAM2_DC3X5U:
86: return 1;
87: }
88: }
89: return 0;
90: }
91:
92: /*
93: * ------------------------------------------------------------
94: * Function : trm_pci_attach
95: * Purpose :
96: * Inputs :
97: * ------------------------------------------------------------
98: */
99: void
100: trm_pci_attach(struct device *parent, struct device *self, void *aux)
101: {
102: struct pci_attach_args *pa = aux;
103: struct scsibus_attach_args saa;
104: bus_space_handle_t ioh;/* bus space handle */
105: pci_intr_handle_t ih;
106: struct trm_softc *sc = (void *)self;
107: bus_space_tag_t iot; /* bus space tag */
108: const char *intrstr;
109: int unit;
110:
111: unit = sc->sc_device.dv_unit;
112:
113: if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_TEKRAM2_DC3X5U)
114: return;
115:
116: /*
117: * mask for get correct base address of pci IO port
118: */
119: if (pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0,
120: &iot, &ioh, NULL, NULL, 0) != 0) {
121: printf("%s: unable to map registers\n", sc->sc_device.dv_xname);
122: return;
123: }
124:
125: /*
126: * test checksum of eeprom & initial "ACB" adapter control block
127: */
128: sc->sc_iotag = iot;
129: sc->sc_iohandle = ioh;
130: sc->sc_dmatag = pa->pa_dmat;
131:
132: if (trm_init(sc, unit) != 0) {
133: printf("%s: trm_init failed", sc->sc_device.dv_xname);
134: return;
135: }
136:
137: /*
138: * Map and establish interrupt
139: */
140: if (pci_intr_map(pa, &ih)) {
141: printf("%s: couldn't map interrupt\n", sc->sc_device.dv_xname);
142: return;
143: }
144: intrstr = pci_intr_string(pa->pa_pc, ih);
145:
146: if (pci_intr_establish(pa->pa_pc, ih, IPL_BIO, trm_Interrupt, sc,
147: sc->sc_device.dv_xname) == NULL) {
148: printf("\n%s: couldn't establish interrupt", sc->sc_device.dv_xname);
149: if (intrstr != NULL)
150: printf(" at %s", intrstr);
151: printf("\n");
152: } else {
153: if (intrstr != NULL)
154: printf(": %s\n", intrstr);
155:
156: bzero(&saa, sizeof(saa));
157: saa.saa_sc_link = &sc->sc_link;
158:
159: /* Tell SCSI layer about our SCSI bus */
160: config_found(&sc->sc_device, &saa, scsiprint);
161: }
162: }
CVSweb