bus_alloc_resource -> bus_alloc_resource_any
[dragonfly.git] / sys / dev / disk / aic7xxx / ahc_eisa.c
CommitLineData
984263bc
MD
1/*
2 * FreeBSD, EISA product support functions
3 *
4 *
5 * Copyright (c) 1994-1998, 2000, 2001 Justin T. Gibbs.
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 immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
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 AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
750f3593 29 * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/ahc_eisa.c#13 $
984263bc 30 *
d18d1e00
PA
31 * $FreeBSD: src/sys/dev/aic7xxx/ahc_eisa.c,v 1.33 2004/03/17 17:50:25 njl Exp $
32 * $DragonFly: src/sys/dev/disk/aic7xxx/ahc_eisa.c,v 1.8 2007/07/06 01:11:07 pavalos Exp $
984263bc
MD
33 */
34
1f2de5d4 35#include "aic7xxx_osm.h"
984263bc 36
1f2de5d4 37#include <bus/eisa/eisaconf.h>
984263bc
MD
38
39static int
40aic7770_probe(device_t dev)
41{
42 struct aic7770_identity *entry;
43 struct resource *regs;
44 uint32_t iobase;
45 bus_space_handle_t bsh;
46 bus_space_tag_t tag;
47 u_int irq;
48 u_int intdef;
49 u_int hcntrl;
50 int shared;
51 int rid;
52 int error;
53
54 entry = aic7770_find_device(eisa_get_id(dev));
55 if (entry == NULL)
56 return (ENXIO);
57 device_set_desc(dev, entry->name);
58
59 iobase = (eisa_get_slot(dev) * EISA_SLOT_SIZE) + AHC_EISA_SLOT_OFFSET;
60
61 eisa_add_iospace(dev, iobase, AHC_EISA_IOSIZE, RESVADDR_NONE);
62
63 rid = 0;
d18d1e00 64 regs = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
984263bc
MD
65 if (regs == NULL) {
66 device_printf(dev, "Unable to map I/O space?!\n");
67 return ENOMEM;
68 }
69
70 tag = rman_get_bustag(regs);
71 bsh = rman_get_bushandle(regs);
72 error = 0;
73
74 /* Pause the card preseving the IRQ type */
75 hcntrl = bus_space_read_1(tag, bsh, HCNTRL) & IRQMS;
76 bus_space_write_1(tag, bsh, HCNTRL, hcntrl | PAUSE);
77 while ((bus_space_read_1(tag, bsh, HCNTRL) & PAUSE) == 0)
78 ;
79
80 /* Make sure we have a valid interrupt vector */
81 intdef = bus_space_read_1(tag, bsh, INTDEF);
82 shared = (intdef & EDGE_TRIG) ? EISA_TRIGGER_EDGE : EISA_TRIGGER_LEVEL;
83 irq = intdef & VECTOR;
84 switch (irq) {
85 case 9:
86 case 10:
87 case 11:
88 case 12:
89 case 14:
90 case 15:
91 break;
92 default:
e3869ec7 93 kprintf("aic7770 at slot %d: illegal irq setting %d\n",
984263bc
MD
94 eisa_get_slot(dev), intdef);
95 error = ENXIO;
96 }
97
98 if (error == 0)
99 eisa_add_intr(dev, irq, shared);
100
101 bus_release_resource(dev, SYS_RES_IOPORT, rid, regs);
102 return (error);
103}
104
105static int
106aic7770_attach(device_t dev)
107{
108 struct aic7770_identity *entry;
109 struct ahc_softc *ahc;
110 char *name;
111 int error;
112
113 entry = aic7770_find_device(eisa_get_id(dev));
114 if (entry == NULL)
115 return (ENXIO);
116
117 /*
118 * Allocate a softc for this card and
119 * set it up for attachment by our
120 * common detect routine.
121 */
efda3bd0 122 name = kmalloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_WAITOK);
984263bc
MD
123 strcpy(name, device_get_nameunit(dev));
124 ahc = ahc_alloc(dev, name);
125 if (ahc == NULL)
126 return (ENOMEM);
127
128 ahc_set_unit(ahc, device_get_unit(dev));
129
130 /* Allocate a dmatag for our SCB DMA maps */
131 /* XXX Should be a child of the PCI bus dma tag */
750f3593 132 error = aic_dma_tag_create(ahc, /*parent*/NULL, /*alignment*/1,
984263bc
MD
133 /*boundary*/0,
134 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
135 /*highaddr*/BUS_SPACE_MAXADDR,
136 /*filter*/NULL, /*filterarg*/NULL,
137 /*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
138 /*nsegments*/AHC_NSEG,
139 /*maxsegsz*/AHC_MAXTRANSFER_SIZE,
140 /*flags*/0,
141 &ahc->parent_dmat);
142
143 if (error != 0) {
e3869ec7 144 kprintf("ahc_eisa_attach: Could not allocate DMA tag "
984263bc
MD
145 "- error %d\n", error);
146 ahc_free(ahc);
147 return (ENOMEM);
148 }
149 ahc->dev_softc = dev;
150 error = aic7770_config(ahc, entry, /*unused ioport arg*/0);
151 if (error != 0) {
152 ahc_free(ahc);
153 return (error);
154 }
155
156 ahc_attach(ahc);
157 return (0);
158}
159
160int
161aic7770_map_registers(struct ahc_softc *ahc, u_int unused_ioport_arg)
162{
163 struct resource *regs;
164 int rid;
165
166 rid = 0;
d18d1e00
PA
167 regs = bus_alloc_resource_any(ahc->dev_softc, SYS_RES_IOPORT, &rid,
168 RF_ACTIVE);
984263bc
MD
169 if (regs == NULL) {
170 device_printf(ahc->dev_softc, "Unable to map I/O space?!\n");
171 return ENOMEM;
172 }
173 ahc->platform_data->regs_res_type = SYS_RES_IOPORT;
174 ahc->platform_data->regs_res_id = rid,
175 ahc->platform_data->regs = regs;
176 ahc->tag = rman_get_bustag(regs);
177 ahc->bsh = rman_get_bushandle(regs);
178 return (0);
179}
180
181int
182aic7770_map_int(struct ahc_softc *ahc, int irq)
183{
184 int zero;
185
186 zero = 0;
187 ahc->platform_data->irq =
d18d1e00
PA
188 bus_alloc_resource_any(ahc->dev_softc, SYS_RES_IRQ, &zero,
189 RF_ACTIVE);
984263bc
MD
190 if (ahc->platform_data->irq == NULL)
191 return (ENOMEM);
192 ahc->platform_data->irq_res_type = SYS_RES_IRQ;
193 return (ahc_map_int(ahc));
194}
195
196static device_method_t ahc_eisa_device_methods[] = {
197 /* Device interface */
198 DEVMETHOD(device_probe, aic7770_probe),
199 DEVMETHOD(device_attach, aic7770_attach),
200 DEVMETHOD(device_detach, ahc_detach),
201 { 0, 0 }
202};
203
204static driver_t ahc_eisa_driver = {
205 "ahc",
206 ahc_eisa_device_methods,
207 sizeof(struct ahc_softc)
208};
209
210DRIVER_MODULE(ahc_eisa, eisa, ahc_eisa_driver, ahc_devclass, 0, 0);
211MODULE_DEPEND(ahc_eisa, ahc, 1, 1, 1);
212MODULE_VERSION(ahc_eisa, 1);