Deleted Added
sdiff udiff text old ( 56178 ) new ( 59082 )
full compact
1/*
2 * Device probe and attach routines for the following
3 * Advanced Systems Inc. SCSI controllers:
4 *
5 * Connectivity Products:
6 * ABP510/5150 - Bus-Master ISA (240 CDB) *
7 * ABP5140 - Bus-Master ISA PnP (16 CDB) * **
8 * ABP5142 - Bus-Master ISA PnP with floppy (16 CDB) ***

--- 30 unchanged lines hidden (view full) ---

39 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 *
47 * $FreeBSD: head/sys/dev/advansys/adv_isa.c 56178 2000-01-17 12:49:54Z nyan $
48 */
49
50#include <sys/param.h>
51#include <sys/systm.h>
52
53#include <machine/bus_pio.h>
54#include <machine/bus.h>
55
56#include <i386/isa/isa_device.h>
57
58#include <dev/advansys/advansys.h>
59
60#include <cam/scsi/scsi_all.h>
61
62#define ADV_ISA_MAX_DMA_ADDR (0x00FFFFFFL)
63#define ADV_ISA_MAX_DMA_COUNT (0x00FFFFFFL)
64

--- 21 unchanged lines hidden (view full) ---

86 0x210, /* Fifth selection in BIOS setup */
87 0x230, /* Sixth selection in BIOS setup */
88 0x250, /* Seventh selection in BIOS setup */
89 0x330 /* Eighth and default selection in BIOS setup */
90};
91
92#define MAX_ISA_IOPORT_INDEX (sizeof(adv_isa_ioports)/sizeof(u_int16_t) - 1)
93
94static int advisaprobe(struct isa_device *id);
95static int advisaattach(struct isa_device *id);
96static void adv_set_isapnp_wait_for_key(void);
97static int adv_get_isa_dma_channel(struct adv_softc *adv);
98static int adv_set_isa_dma_settings(struct adv_softc *adv);
99
100static void adv_isa_intr(void *unit);
101
102struct isa_driver advdriver =
103{
104 advisaprobe,
105 advisaattach,
106 "adv"
107};
108
109static int
110advisaprobe(struct isa_device *id)
111{
112 int port_index;
113 int max_port_index;
114
115 /*
116 * Default to scanning all possible device locations.
117 */
118 port_index = 0;
119 max_port_index = MAX_ISA_IOPORT_INDEX;
120
121 if (id->id_iobase > 0) {
122 for (;port_index <= max_port_index; port_index++)
123 if (id->id_iobase <= adv_isa_ioports[port_index])
124 break;
125 if ((port_index > max_port_index)
126 || (id->id_iobase != adv_isa_ioports[port_index])) {
127 printf("adv%d: Invalid baseport of 0x%x specified. "
128 "Neerest valid baseport is 0x%x. Failing "
129 "probe.\n", id->id_unit, id->id_iobase,
130 (port_index <= max_port_index) ?
131 adv_isa_ioports[port_index] :
132 adv_isa_ioports[max_port_index]);
133 return 0;
134 }
135 max_port_index = port_index;
136 }
137
138 /* Perform the actual probing */
139 adv_set_isapnp_wait_for_key();
140 for (;port_index <= max_port_index; port_index++) {
141 u_int16_t port_addr = adv_isa_ioports[port_index];
142 bus_size_t maxsegsz;
143 bus_size_t maxsize;
144 bus_addr_t lowaddr;
145 int error;
146
147 if (port_addr == 0)
148 /* Already been attached */
149 continue;
150 id->id_iobase = port_addr;
151 if (haveseen_iobase(id, 1)) /* XXX real portsize? */
152 continue;
153
154 if (adv_find_signature(I386_BUS_SPACE_IO, port_addr)) {
155 /*
156 * Got one. Now allocate our softc
157 * and see if we can initialize the card.
158 */
159 struct adv_softc *adv;
160 adv = adv_alloc(id->id_unit, I386_BUS_SPACE_IO,
161 port_addr);
162 if (adv == NULL)
163 return (0);
164
165 adv_unit++;
166
167 id->id_iobase = adv->bsh;
168
169 /*
170 * Stop the chip.
171 */
172 ADV_OUTB(adv, ADV_CHIP_CTRL, ADV_CC_HALT);
173 ADV_OUTW(adv, ADV_CHIP_STATUS, 0);
174 /*
175 * Determine the chip version.
176 */
177 adv->chip_version = ADV_INB(adv,
178 ADV_NONEISA_CHIP_REVISION);
179 if ((adv->chip_version >= ADV_CHIP_MIN_VER_VL)
180 && (adv->chip_version <= ADV_CHIP_MAX_VER_VL)) {
181 adv->type = ADV_VL;
182 maxsegsz = ADV_VL_MAX_DMA_COUNT;
183 maxsize = BUS_SPACE_MAXSIZE_32BIT;
184 lowaddr = ADV_VL_MAX_DMA_ADDR;
185 id->id_drq = -1;
186 } else if ((adv->chip_version >= ADV_CHIP_MIN_VER_ISA)
187 && (adv->chip_version <= ADV_CHIP_MAX_VER_ISA)) {
188 if (adv->chip_version >= ADV_CHIP_MIN_VER_ISA_PNP) {
189 adv->type = ADV_ISAPNP;
190 ADV_OUTB(adv, ADV_REG_IFC,
191 ADV_IFC_INIT_DEFAULT);
192 } else {
193 adv->type = ADV_ISA;
194 }
195 maxsegsz = ADV_ISA_MAX_DMA_COUNT;
196 maxsize = BUS_SPACE_MAXSIZE_24BIT;
197 lowaddr = ADV_ISA_MAX_DMA_ADDR;
198 adv->isa_dma_speed = ADV_DEF_ISA_DMA_SPEED;
199 adv->isa_dma_channel =
200 adv_get_isa_dma_channel(adv);
201 id->id_drq = adv->isa_dma_channel;
202 } else {
203 panic("advisaprobe: Unknown card revision\n");
204 }
205
206 /*
207 * Allocate a parent dmatag for all tags created
208 * by the MI portions of the advansys driver
209 */

--- 11 unchanged lines hidden (view full) ---

221 maxsegsz,
222 /*flags*/0,
223 &adv->parent_dmat);
224
225 if (error != 0) {
226 printf("%s: Could not allocate DMA tag - error %d\n",
227 adv_name(adv), error);
228 adv_free(adv);
229 return (0);
230 }
231
232 adv->init_level++;
233
234 if (overrun_buf == NULL) {
235 /* Need to allocate our overrun buffer */
236 if (bus_dma_tag_create(adv->parent_dmat,
237 /*alignment*/8,
238 /*boundary*/0,
239 ADV_ISA_MAX_DMA_ADDR,
240 BUS_SPACE_MAXADDR,
241 /*filter*/NULL,
242 /*filterarg*/NULL,
243 ADV_OVERRUN_BSIZE,
244 /*nsegments*/1,
245 BUS_SPACE_MAXSIZE_32BIT,
246 /*flags*/0,
247 &overrun_dmat) != 0) {
248 adv_free(adv);
249 return (0);
250 }
251 if (bus_dmamem_alloc(overrun_dmat,
252 (void **)&overrun_buf,
253 BUS_DMA_NOWAIT,
254 &overrun_dmamap) != 0) {
255 bus_dma_tag_destroy(overrun_dmat);
256 adv_free(adv);
257 return (0);
258 }
259 /* And permanently map it in */
260 bus_dmamap_load(overrun_dmat, overrun_dmamap,
261 overrun_buf, ADV_OVERRUN_BSIZE,
262 adv_map, &overrun_physbase,
263 /*flags*/0);
264 }
265
266 adv->overrun_physbase = overrun_physbase;
267
268 if (adv_init(adv) != 0) {
269 adv_free(adv);
270 return (0);
271 }
272
273 switch (adv->type) {
274 case ADV_ISAPNP:
275 if (adv->chip_version == ADV_CHIP_VER_ASYN_BUG){
276 adv->bug_fix_control
277 |= ADV_BUG_FIX_ASYN_USE_SYN;
278 adv->fix_asyn_xfer = ~0;

--- 9 unchanged lines hidden (view full) ---

288 adv->max_dma_count = ADV_VL_MAX_DMA_COUNT;
289 adv->max_dma_addr = ADV_VL_MAX_DMA_ADDR;
290 break;
291 default:
292 panic("advisaprobe: Invalid card type\n");
293 }
294
295 /* Determine our IRQ */
296 if (id->id_irq == 0 /* irq ? */)
297 id->id_irq = 1 << adv_get_chip_irq(adv);
298 else
299 adv_set_chip_irq(adv, ffs(id->id_irq) - 1);
300
301 id->id_intr = adv_isa_intr;
302
303 /* Mark as probed */
304 adv_isa_ioports[port_index] = 0;
305 return 1; /* XXX what is the real portsize? */
306 }
307 }
308
309 return 0;
310}
311
312static int
313advisaattach(struct isa_device *id)
314{
315 struct adv_softc *adv;
316
317 adv = advsoftcs[id->id_unit];
318 return (adv_attach(adv));
319}
320
321static int
322adv_get_isa_dma_channel(struct adv_softc *adv)
323{
324 int channel;
325

--- 34 unchanged lines hidden (view full) ---

360adv_set_isapnp_wait_for_key(void)
361{
362 static int isapnp_wait_set = 0;
363 if (isapnp_wait_set == 0) {
364 outb(ADV_ISA_PNP_PORT_ADDR, 0x02);
365 outb(ADV_ISA_PNP_PORT_WRITE, 0x02);
366 isapnp_wait_set++;
367 }
368 return;
369}
370
371/*
372 * Handle an ISA interrupt.
373 * XXX should go away as soon as ISA interrupt handlers
374 * take a (void *) arg.
375 */
376static void
377adv_isa_intr(void *unit)
378{
379 struct adv_softc *arg = advsoftcs[(int)unit];
380 adv_intr((void *)arg);
381}