FreeBSD/Linux Kernel Cross Reference
sys/i386/isa/bs/bs_isa.c
1 /* $NecBSD: bs_isa.c,v 1.3 1997/10/31 17:43:35 honda Exp $ */
2 /* $NetBSD$ */
3 /*
4 * [NetBSD for NEC PC98 series]
5 * Copyright (c) 1995, 1996 NetBSD/pc98 porting staff.
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, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <i386/Cbus/dev/bs/bsif.h>
33
34 static int bs_isa_probe __P((struct device *, void *, void *));
35 static void bs_isa_attach __P((struct device *, struct device *, void *));
36 static void bs_args_copy
37 __P((struct bs_softc *, struct isa_attach_args *, struct bshw *));
38
39 struct cfattach bs_isa_ca = {
40 sizeof(struct bs_softc), bs_isa_probe, bs_isa_attach
41 };
42
43 static void
44 bs_args_copy(bsc, ia, hw)
45 struct bs_softc *bsc;
46 struct isa_attach_args *ia;
47 struct bshw *hw;
48 {
49
50 bsc->sc_hw = hw;
51 bsc->sc_iot = ia->ia_iot;
52 bsc->sc_memt = ia->ia_memt;
53 bsc->sc_dmat = ia->ia_dmat;
54 bsc->sc_delaybah = ia->ia_delaybah; /* should be die */
55 bsc->sc_iobase = ia->ia_iobase;
56 if (ia->ia_maddr != MADDRUNK)
57 bsc->sm_offset = BSHW_SMITFIFO_OFFSET;
58 else
59 bsc->sm_offset = 0;
60
61 bsc->sc_cfgflags = DVCFG_MINOR(ia->ia_cfgflags);
62 snprintf(bsc->sc_dvname, sizeof(bsc->sc_dvname),
63 "%s", bsc->sc_dev.dv_xname);
64 }
65
66 static int
67 bs_isa_probe(parent, match, aux)
68 struct device *parent;
69 void *match, *aux;
70 {
71 struct bs_softc *bsc = (void *) match;
72 struct isa_attach_args *ia = aux;
73 bus_space_handle_t ioh, memh = NULL;
74 bus_space_tag_t iot, memt;
75 struct bshw *hw;
76 u_int irq, drq;
77 int rv = 0;
78
79 hw = DVCFG_HW(&bshw_hwsel, DVCFG_MAJOR(ia->ia_cfgflags));
80 if (hw == NULL)
81 return rv;
82
83 iot = ia->ia_iot;
84 memt = ia->ia_memt;
85 if (ia->ia_iobase == IOBASEUNK)
86 {
87 printf("%s: iobase not specified. Assume default port(0x%x)\n",
88 bsc->sc_dvname, BSHW_DEFAULT_PORT);
89 ia->ia_iobase = BSHW_DEFAULT_PORT;
90 }
91
92 if (bus_space_map(iot, ia->ia_iobase, BSHW_IOSZ, 0, &ioh))
93 return rv;
94
95 if ((hw->hw_flags & BSHW_SMFIFO) != 0 && (ia->ia_maddr != MADDRUNK))
96 {
97 ia->ia_maddr = (ia->ia_maddr & (~((NBPG * 2) - 1))) + NBPG;
98 ia->ia_msize = NBPG;
99 if (bus_space_map(memt, ia->ia_maddr, NBPG, 0, &memh))
100 {
101 bus_space_unmap(iot, ioh, BSHW_IOSZ);
102 return 0;
103 }
104 }
105 else
106 ia->ia_maddr = MADDRUNK;
107
108 irq = IRQUNK;
109 drq = DRQUNK;
110 bsc->sc_ioh = ioh;
111 bsc->sc_memh = memh;
112 bs_args_copy(bsc, ia, hw);
113 if (bshw_board_probe(bsc, &drq, &irq))
114 goto bad;
115
116 ia->ia_irq = irq;
117 ia->ia_drq = drq;
118 ia->ia_iosize = BSHW_IOSZ;
119 rv = 1;
120
121 bad:
122 bus_space_unmap(iot, bsc->sc_ioh, BSHW_IOSZ);
123 if (ia->ia_maddr != MADDRUNK)
124 bus_space_unmap(memt, bsc->sc_memh, ia->ia_msize);
125 return rv;
126 }
127
128 static void
129 bs_isa_attach(parent, self, aux)
130 struct device *parent, *self;
131 void *aux;
132 {
133 extern struct scsi_adapter pc98texa55bs;
134 extern struct scsi_device bs_dev;
135 struct bs_softc *bsc = (void *) self;
136 struct isa_attach_args *ia = aux;
137 bus_space_tag_t iot, memt;
138 struct bshw *hw;
139 int i;
140
141 printf("\n");
142
143 hw = DVCFG_HW(&bshw_hwsel, DVCFG_MAJOR(ia->ia_cfgflags));
144 iot = ia->ia_iot;
145 memt = ia->ia_memt;
146
147 if (bus_space_map(iot, ia->ia_iobase, BSHW_IOSZ, 0, &bsc->sc_ioh))
148 panic("%s: bus io map failed\n", bsc->sc_dev.dv_xname);
149
150 if (ia->ia_maddr != MADDRUNK &&
151 bus_space_map(memt, ia->ia_maddr, NBPG, 0, &bsc->sc_memh))
152 panic("%s: bus mem map failed\n", bsc->sc_dev.dv_xname);
153
154 if (isa_dmamap_create(NULL, ia->ia_drq, MAXBSIZE, BUS_DMA_NOWAIT))
155 {
156 printf("%s: can't set up ISA DMA map\n", bsc->sc_dev.dv_xname);
157 return;
158 }
159
160 /* system initialize */
161 bs_args_copy(bsc, ia, hw);
162 bs_hostque_init(bsc);
163 for (i = 0; i < NTARGETS; i++)
164 {
165 if (i != bsc->sc_hostid)
166 bs_init_target_info(bsc, i);
167 }
168
169 bs_init_ccbque(BS_MAX_CCB);
170 bsc->sc_hstate = BSC_BOOTUP;
171 bsc->sc_retry = RETRIES;
172 bsc->sc_wc = delaycount * 250;
173 bs_reset_nexus(bsc);
174
175 /* link upper layer */
176 bsc->sc_link.adapter_target = bsc->sc_hostid;
177 bsc->sc_link.openings = XSMAX;
178 bsc->sc_link.max_target = 7;
179 bsc->sc_link.channel = SCSI_CHANNEL_ONLY_ONE;
180 bsc->sc_link.adapter_softc = bsc;
181 bsc->sc_link.adapter = &pc98texa55bs;
182 bsc->sc_link.device = &bs_dev;
183
184 config_found(self, &bsc->sc_link, bsprint);
185
186 bsc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
187 IPL_BIO, bsintr, bsc);
188 bs_start_timeout(bsc);
189 }
Cache object: 6d580c2d9a4fd8c6d7868326cfdda993
|