1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 2003 Bob Bishop
5 * All rights reserved.
6 * [Ported for FreeBSD]
7 * Copyright (c) 2000
8 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
9 * All rights reserved.
10 * [NetBSD for NEC PC-98 series]
11 * Copyright (c) 1996, 1997, 1998
12 * NetBSD/pc98 porting staff. All rights reserved.
13 * Copyright (c) 1996, 1997, 1998
14 * Naofumi HONDA. All rights reserved.
15 * Copyright (c) 1996, 1997, 1998
16 * Kouichi Matsuda. All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. The name of the author may not be used to endorse or promote products
27 * derived from this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
30 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 */
41
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD: releng/12.0/sys/dev/stg/tmc18c30_pci.c 326255 2017-11-27 14:52:40Z pfg $");
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
48 #include <sys/module.h>
49 #include <sys/bus.h>
50 #include <sys/malloc.h>
51 #include <sys/errno.h>
52
53 #include <machine/bus.h>
54 #include <machine/resource.h>
55 #include <sys/rman.h>
56
57 #include <dev/pci/pcireg.h>
58 #include <dev/pci/pcivar.h>
59
60 #include <cam/scsi/scsi_low.h>
61
62 #include <dev/stg/tmc18c30reg.h>
63 #include <dev/stg/tmc18c30var.h>
64 #include <dev/stg/tmc18c30.h>
65
66 static struct _pcsid
67 {
68 u_int32_t type;
69 const char *desc;
70 } pci_ids[] = {
71 { 0x00001036, "Adaptec AHA-2920/A,Future Domain TMC-18XX/3260" },
72 { 0x00000000, NULL }
73 };
74
75 static int
76 stg_pci_probe(device_t dev)
77 {
78 u_int32_t type = pci_get_devid(dev);
79 struct _pcsid *stg = pci_ids;
80
81 while (stg->type && stg->type != type)
82 ++stg;
83 if (stg->desc) {
84 device_set_desc(dev, stg->desc);
85 return (BUS_PROBE_DEFAULT);
86 }
87 return (ENXIO);
88 }
89
90 static int
91 stg_pci_attach(device_t dev)
92 {
93 struct stg_softc *sc = device_get_softc(dev);
94 int error;
95
96 sc->port_rid = PCIR_BAR(0);
97 sc->irq_rid = 0;
98 error = stg_alloc_resource(dev);
99 if (error) {
100 return(error);
101 }
102
103 /* XXXX remove INTR_ENTROPY below for MFC */
104 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY |
105 INTR_MPSAFE, NULL, stg_intr, sc, &sc->stg_intrhand);
106 if (error) {
107 stg_release_resource(dev);
108 return(error);
109 }
110
111 if (stg_attach(dev) == 0) {
112 stg_release_resource(dev);
113 return(ENXIO);
114 }
115
116 return(0);
117 }
118
119 static device_method_t stg_pci_methods[] = {
120 /* Device interface */
121 DEVMETHOD(device_probe, stg_pci_probe),
122 DEVMETHOD(device_attach, stg_pci_attach),
123 DEVMETHOD(device_detach, stg_detach),
124
125 { 0, 0 }
126 };
127
128 static driver_t stg_pci_driver = {
129 "stg",
130 stg_pci_methods,
131 sizeof(struct stg_softc),
132 };
133
134 DRIVER_MODULE(stg, pci, stg_pci_driver, stg_devclass, 0, 0);
135 MODULE_DEPEND(stg, scsi_low, 1, 1, 1);
136 MODULE_DEPEND(stg, pci, 1, 1, 1);
Cache object: 58af8580a0fcfe8d7069a97aa924380d
|