1/*-
2 * Copyright (c) 1999 Jonathan Lemon
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: ida_pci.c,v 1.3 1999/07/29 01:03:02 mdodd Exp $
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/malloc.h>
32#include <sys/kernel.h>
33
34#include <sys/buf.h>
35#include <sys/bus.h>
36#include <sys/device.h>
37#include <sys/devicestat.h>
38
39#include <machine/bus_memio.h>
40#include <machine/bus_pio.h>
41#include <machine/bus.h>
42#include <machine/resource.h>
43#include <sys/rman.h>
44
45#include <pci/pcireg.h>
46#include <pci/pcivar.h>
47
48#include <dev/ida/idavar.h>
49
50#define IDA_PCI_MAX_DMA_ADDR 0xFFFFFFFF
51#define IDA_PCI_MAX_DMA_COUNT 0xFFFFFFFF
52
53#define IDA_PCI_MEMADDR (PCIR_MAPS + 4) /* Mem I/O Address */
54
55#define IDA_DEVICEID_SMART 0xAE100E11
56
57static struct {
58 u_long board;
59 char *desc;
60} board_id[] = {
61 { 0x4030, "Compaq SMART-2/P array controller" },
62 { 0x4031, "Compaq SMART-2SL array controller" },
63 { 0x4032, "Compaq Smart Array 3200 controller" },
64 { 0x4033, "Compaq Smart Array 3100ES controller" },
65 { 0x4034, "Compaq Smart Array 221 controller" },
66
67 { 0, "" },
68};
69
70static int ida_pci_probe(device_t dev);
71static int ida_pci_attach(device_t dev);
72
73static device_method_t ida_pci_methods[] = {
74 DEVMETHOD(device_probe, ida_pci_probe),
75 DEVMETHOD(device_attach, ida_pci_attach),
76
77 DEVMETHOD(bus_print_child, bus_generic_print_child),
78
79 { 0, 0 }
80};
81
82static driver_t ida_pci_driver = {
83 "ida",
84 ida_pci_methods,
85 sizeof(struct ida_softc)
86};
87
88static devclass_t ida_devclass;
89
90static int
91ida_pci_probe(device_t dev)
92{
93 u_long board;
94 int i;
95
96 if (pci_get_devid(dev) == IDA_DEVICEID_SMART) {
97 board = pci_get_subdevice(dev);
98 for (i = 0; board_id[i].board; i++) {
99 if (board_id[i].board == board) {
100 device_set_desc(dev, board_id[i].desc);
101 return (0);
102 }
103 }
104 /*
105 * It's an unknown Compaq SMART device, but assume we
106 * can support it.
107 */
108 device_set_desc(dev, "Unknown Compaq Smart Array controller");
109 return (0);
110 }
111 return (ENXIO);
112}
113
114static int
115ida_pci_attach(device_t dev)
116{
117 struct ida_softc *ida;
118 u_int command;
119 int error, rid;
120
121 command = pci_read_config(dev, PCIR_COMMAND, 1);
122
123 /*
124 * for multiple card types, need to re-determine which type is
125 * being attached here
126 */
127
128 /*
129 * it appears that this board only does MEMIO access.
130 */
131 if ((command & PCIM_CMD_MEMEN) == 0) {
132 device_printf(dev, "Only memory mapped I/O is supported\n");
133 return (ENXIO);
134 }
135
136 ida = (struct ida_softc *)device_get_softc(dev);
137 ida->dev = dev;
138
139 ida->regs_res_type = SYS_RES_MEMORY;
140 ida->regs_res_id = IDA_PCI_MEMADDR;
141 ida->regs = bus_alloc_resource(dev, ida->regs_res_type,
142 &ida->regs_res_id, 0, ~0, 1, RF_ACTIVE);
143 if (ida->regs == NULL) {
144 device_printf(dev, "can't allocate register resources\n");
145 return (ENOMEM);
146 }
147
148 error = bus_dma_tag_create(/*parent*/NULL, /*alignment*/1,
149 /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
150 /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL,
151 /*maxsize*/MAXBSIZE, /*nsegments*/IDA_NSEG,
152 /*maxsegsize*/BUS_SPACE_MAXSIZE_32BIT, /*flags*/BUS_DMA_ALLOCNOW,
153 &ida->parent_dmat);
154 if (error != 0) {
155 device_printf(dev, "can't allocate DMA tag\n");
156 ida_free(ida);
157 return (ENOMEM);
158 }
159
160 rid = 0;
161 ida->irq_res_type = SYS_RES_IRQ;
162 ida->irq = bus_alloc_resource(dev, ida->irq_res_type, &rid,
163 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
164 if (ida->irq == NULL) {
165 ida_free(ida);
166 return (ENOMEM);
167 }
168 error = bus_setup_intr(dev, ida->irq, INTR_TYPE_BIO,
169 ida_intr, ida, &ida->ih);
170 if (error) {
171 device_printf(dev, "can't setup interrupt\n");
172 ida_free(ida);
173 return (ENOMEM);
174 }
175
176 error = ida_init(ida);
177 if (error) {
178 ida_free(ida);
179 return (error);
180 }
181 ida_attach(ida);
182 ida->flags = IDA_ATTACHED;
183
184 return (0);
185}
186
187DRIVER_MODULE(ida, pci, ida_pci_driver, ida_devclass, 0, 0);
2 * Copyright (c) 1999 Jonathan Lemon
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: ida_pci.c,v 1.3 1999/07/29 01:03:02 mdodd Exp $
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/malloc.h>
32#include <sys/kernel.h>
33
34#include <sys/buf.h>
35#include <sys/bus.h>
36#include <sys/device.h>
37#include <sys/devicestat.h>
38
39#include <machine/bus_memio.h>
40#include <machine/bus_pio.h>
41#include <machine/bus.h>
42#include <machine/resource.h>
43#include <sys/rman.h>
44
45#include <pci/pcireg.h>
46#include <pci/pcivar.h>
47
48#include <dev/ida/idavar.h>
49
50#define IDA_PCI_MAX_DMA_ADDR 0xFFFFFFFF
51#define IDA_PCI_MAX_DMA_COUNT 0xFFFFFFFF
52
53#define IDA_PCI_MEMADDR (PCIR_MAPS + 4) /* Mem I/O Address */
54
55#define IDA_DEVICEID_SMART 0xAE100E11
56
57static struct {
58 u_long board;
59 char *desc;
60} board_id[] = {
61 { 0x4030, "Compaq SMART-2/P array controller" },
62 { 0x4031, "Compaq SMART-2SL array controller" },
63 { 0x4032, "Compaq Smart Array 3200 controller" },
64 { 0x4033, "Compaq Smart Array 3100ES controller" },
65 { 0x4034, "Compaq Smart Array 221 controller" },
66
67 { 0, "" },
68};
69
70static int ida_pci_probe(device_t dev);
71static int ida_pci_attach(device_t dev);
72
73static device_method_t ida_pci_methods[] = {
74 DEVMETHOD(device_probe, ida_pci_probe),
75 DEVMETHOD(device_attach, ida_pci_attach),
76
77 DEVMETHOD(bus_print_child, bus_generic_print_child),
78
79 { 0, 0 }
80};
81
82static driver_t ida_pci_driver = {
83 "ida",
84 ida_pci_methods,
85 sizeof(struct ida_softc)
86};
87
88static devclass_t ida_devclass;
89
90static int
91ida_pci_probe(device_t dev)
92{
93 u_long board;
94 int i;
95
96 if (pci_get_devid(dev) == IDA_DEVICEID_SMART) {
97 board = pci_get_subdevice(dev);
98 for (i = 0; board_id[i].board; i++) {
99 if (board_id[i].board == board) {
100 device_set_desc(dev, board_id[i].desc);
101 return (0);
102 }
103 }
104 /*
105 * It's an unknown Compaq SMART device, but assume we
106 * can support it.
107 */
108 device_set_desc(dev, "Unknown Compaq Smart Array controller");
109 return (0);
110 }
111 return (ENXIO);
112}
113
114static int
115ida_pci_attach(device_t dev)
116{
117 struct ida_softc *ida;
118 u_int command;
119 int error, rid;
120
121 command = pci_read_config(dev, PCIR_COMMAND, 1);
122
123 /*
124 * for multiple card types, need to re-determine which type is
125 * being attached here
126 */
127
128 /*
129 * it appears that this board only does MEMIO access.
130 */
131 if ((command & PCIM_CMD_MEMEN) == 0) {
132 device_printf(dev, "Only memory mapped I/O is supported\n");
133 return (ENXIO);
134 }
135
136 ida = (struct ida_softc *)device_get_softc(dev);
137 ida->dev = dev;
138
139 ida->regs_res_type = SYS_RES_MEMORY;
140 ida->regs_res_id = IDA_PCI_MEMADDR;
141 ida->regs = bus_alloc_resource(dev, ida->regs_res_type,
142 &ida->regs_res_id, 0, ~0, 1, RF_ACTIVE);
143 if (ida->regs == NULL) {
144 device_printf(dev, "can't allocate register resources\n");
145 return (ENOMEM);
146 }
147
148 error = bus_dma_tag_create(/*parent*/NULL, /*alignment*/1,
149 /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
150 /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL,
151 /*maxsize*/MAXBSIZE, /*nsegments*/IDA_NSEG,
152 /*maxsegsize*/BUS_SPACE_MAXSIZE_32BIT, /*flags*/BUS_DMA_ALLOCNOW,
153 &ida->parent_dmat);
154 if (error != 0) {
155 device_printf(dev, "can't allocate DMA tag\n");
156 ida_free(ida);
157 return (ENOMEM);
158 }
159
160 rid = 0;
161 ida->irq_res_type = SYS_RES_IRQ;
162 ida->irq = bus_alloc_resource(dev, ida->irq_res_type, &rid,
163 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
164 if (ida->irq == NULL) {
165 ida_free(ida);
166 return (ENOMEM);
167 }
168 error = bus_setup_intr(dev, ida->irq, INTR_TYPE_BIO,
169 ida_intr, ida, &ida->ih);
170 if (error) {
171 device_printf(dev, "can't setup interrupt\n");
172 ida_free(ida);
173 return (ENOMEM);
174 }
175
176 error = ida_init(ida);
177 if (error) {
178 ida_free(ida);
179 return (error);
180 }
181 ida_attach(ida);
182 ida->flags = IDA_ATTACHED;
183
184 return (0);
185}
186
187DRIVER_MODULE(ida, pci, ida_pci_driver, ida_devclass, 0, 0);