bha_isa.c revision 1.2
1/*	$NetBSD: bha_isa.c,v 1.2 1996/09/01 00:20:23 mycroft Exp $	*/
2
3/*
4 * Copyright (c) 1994, 1996 Charles M. Hannum.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *	This product includes software developed by Charles M. Hannum.
17 * 4. The name of the author may not be used to endorse or promote products
18 *    derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <sys/types.h>
33#include <sys/param.h>
34#include <sys/device.h>
35
36#include <machine/bus.h>
37#include <machine/intr.h>
38
39#include <scsi/scsi_all.h>
40#include <scsi/scsiconf.h>
41
42#include <dev/isa/isavar.h>
43#include <dev/isa/isadmavar.h>
44
45#include <dev/ic/bhareg.h>
46#include <dev/ic/bhavar.h>
47
48#define	BHA_ISA_IOSIZE	4
49
50int	bha_isa_probe __P((struct device *, void *, void *));
51void	bha_isa_attach __P((struct device *, struct device *, void *));
52
53struct cfattach bha_isa_ca = {
54	sizeof(struct bha_softc), bha_isa_probe, bha_isa_attach
55};
56
57/*
58 * Check the slots looking for a board we recognise
59 * If we find one, note it's address (slot) and call
60 * the actual probe routine to check it out.
61 */
62int
63bha_isa_probe(parent, match, aux)
64	struct device *parent;
65	void *match, *aux;
66{
67	struct isa_attach_args *ia = aux;
68	struct bha_softc sc;
69	bus_chipset_tag_t bc = ia->ia_bc;
70	bus_io_handle_t ioh;
71	isa_chipset_tag_t ic = ia->ia_ic;
72	int rv;
73
74	if (bus_io_map(bc, ia->ia_iobase, BHA_ISA_IOSIZE, &ioh))
75		return (0);
76
77	rv = bha_find(bc, ioh, &sc);
78
79	bus_io_unmap(bc, ioh, BHA_ISA_IOSIZE);
80
81	if (rv) {
82		if (ia->ia_irq != -1 && ia->ia_irq != sc.sc_irq)
83			return (0);
84		if (ia->ia_drq != -1 && ia->ia_drq != sc.sc_drq)
85			return (0);
86		ia->ia_irq = sc.sc_irq;
87		ia->ia_drq = sc.sc_drq;
88		ia->ia_msize = 0;
89		ia->ia_iosize = BHA_ISA_IOSIZE;
90	}
91	return (rv);
92}
93
94/*
95 * Attach all the sub-devices we can find
96 */
97void
98bha_isa_attach(parent, self, aux)
99	struct device *parent, *self;
100	void *aux;
101{
102	struct isa_attach_args *ia = aux;
103	struct bha_softc *sc = (void *)self;
104	bus_chipset_tag_t bc = ia->ia_bc;
105	bus_io_handle_t ioh;
106	isa_chipset_tag_t ic = ia->ia_ic;
107
108	printf("\n");
109
110	if (bus_io_map(bc, ia->ia_iobase, BHA_ISA_IOSIZE, &ioh))
111		panic("bha_attach: bus_io_map failed!");
112
113	sc->sc_bc = bc;
114	sc->sc_ioh = ioh;
115	if (!bha_find(bc, ioh, sc))
116		panic("bha_attach: bha_find failed!");
117
118	if (sc->sc_drq != -1)
119		isa_dmacascade(sc->sc_drq);
120
121	sc->sc_ih = isa_intr_establish(ic, sc->sc_irq, IST_EDGE, IPL_BIO,
122	    bha_intr, sc);
123	if (sc->sc_ih == NULL) {
124		printf("%s: couldn't establish interrupt\n",
125		    sc->sc_dev.dv_xname);
126		return;
127	}
128
129	bha_attach(sc);
130}
131