bmd.c revision 1.1.2.2 1 1.1.2.2 thorpej /* $NetBSD: bmd.c,v 1.1.2.2 2002/12/11 06:12:47 thorpej Exp $ */
2 1.1.2.2 thorpej
3 1.1.2.2 thorpej /*
4 1.1.2.2 thorpej * Copyright (c) 2002 Tetsuya Isaki. All rights reserved.
5 1.1.2.2 thorpej *
6 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
7 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
8 1.1.2.2 thorpej * are met:
9 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
10 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
11 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
13 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
14 1.1.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
15 1.1.2.2 thorpej * must display the following acknowledgement:
16 1.1.2.2 thorpej * This product includes software developed by Tetsuya Isaki.
17 1.1.2.2 thorpej * 4. The name of the author may not be used to endorse or promote products
18 1.1.2.2 thorpej * derived from this software without specific prior written permission
19 1.1.2.2 thorpej *
20 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1.2.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1.2.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1.2.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 1.1.2.2 thorpej * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 1.1.2.2 thorpej * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 1.1.2.2 thorpej * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 1.1.2.2 thorpej * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.1.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.1.2.2 thorpej * SUCH DAMAGE.
31 1.1.2.2 thorpej */
32 1.1.2.2 thorpej
33 1.1.2.2 thorpej /*
34 1.1.2.2 thorpej * Nereid bank memory disk
35 1.1.2.2 thorpej */
36 1.1.2.2 thorpej
37 1.1.2.2 thorpej #include <sys/param.h>
38 1.1.2.2 thorpej #include <sys/systm.h>
39 1.1.2.2 thorpej #include <sys/buf.h>
40 1.1.2.2 thorpej #include <sys/conf.h>
41 1.1.2.2 thorpej #include <sys/device.h>
42 1.1.2.2 thorpej #include <sys/kernel.h>
43 1.1.2.2 thorpej #include <sys/stat.h>
44 1.1.2.2 thorpej #include <sys/disk.h>
45 1.1.2.2 thorpej #include <sys/disklabel.h>
46 1.1.2.2 thorpej #include <sys/ioctl.h>
47 1.1.2.2 thorpej #include <sys/fcntl.h>
48 1.1.2.2 thorpej #include <sys/proc.h>
49 1.1.2.2 thorpej
50 1.1.2.2 thorpej #include <machine/bus.h>
51 1.1.2.2 thorpej #include <machine/cpu.h>
52 1.1.2.2 thorpej
53 1.1.2.2 thorpej #include <arch/x68k/dev/intiovar.h>
54 1.1.2.2 thorpej
55 1.1.2.2 thorpej #define BMD_ADDR1 (0xece3f0)
56 1.1.2.2 thorpej #define BMD_ADDR2 (0xecebf0)
57 1.1.2.2 thorpej
58 1.1.2.2 thorpej #define BMD_PAGESIZE (0x10000) /* 64KB */
59 1.1.2.2 thorpej #define BMD_BSIZE (512)
60 1.1.2.2 thorpej #define BLKS_PER_PAGE (BMD_PAGESIZE / BMD_BSIZE)
61 1.1.2.2 thorpej
62 1.1.2.2 thorpej #define BMD_PAGE (0)
63 1.1.2.2 thorpej #define BMD_CTRL (1)
64 1.1.2.2 thorpej #define BMD_CTRL_ENABLE (0x80) /* DIP8: 1=Enable, 0=Disable */
65 1.1.2.2 thorpej #define BMD_CTRL_MEMORY (0x40) /* 1=16M available, 0=4M available */
66 1.1.2.2 thorpej #define BMD_CTRL_WINDOW (0x20) /* DIP6: 1=0xee0000, 0=0xef0000 */
67 1.1.2.2 thorpej
68 1.1.2.2 thorpej
69 1.1.2.2 thorpej #define BMD_UNIT(dev) (minor(dev) / 8)
70 1.1.2.2 thorpej
71 1.1.2.2 thorpej #ifdef BMD_DEBUG
72 1.1.2.2 thorpej #define DPRINTF(x) printf x
73 1.1.2.2 thorpej #else
74 1.1.2.2 thorpej #define DPRINTF(x) /* nothing */
75 1.1.2.2 thorpej #endif
76 1.1.2.2 thorpej
77 1.1.2.2 thorpej struct bmd_softc {
78 1.1.2.2 thorpej struct device sc_dev;
79 1.1.2.2 thorpej struct disk sc_dkdev;
80 1.1.2.2 thorpej bus_space_tag_t sc_iot;
81 1.1.2.2 thorpej bus_space_handle_t sc_ioh;
82 1.1.2.2 thorpej bus_space_handle_t sc_bank;
83 1.1.2.2 thorpej
84 1.1.2.2 thorpej int sc_maxpage;
85 1.1.2.2 thorpej int sc_window;
86 1.1.2.2 thorpej
87 1.1.2.2 thorpej int sc_flags;
88 1.1.2.2 thorpej #define BMD_OPENBLK (0x01)
89 1.1.2.2 thorpej #define BMD_OPENCHR (0x02)
90 1.1.2.2 thorpej #define BMD_OPEN (BMD_OPENBLK | BMD_OPENCHR)
91 1.1.2.2 thorpej };
92 1.1.2.2 thorpej
93 1.1.2.2 thorpej static int bmd_match(struct device *, struct cfdata *, void *);
94 1.1.2.2 thorpej static void bmd_attach(struct device *, struct device *, void *);
95 1.1.2.2 thorpej static int bmd_getdisklabel(struct bmd_softc *, dev_t);
96 1.1.2.2 thorpej
97 1.1.2.2 thorpej extern struct cfdriver bmd_cd;
98 1.1.2.2 thorpej
99 1.1.2.2 thorpej CFATTACH_DECL(bmd, sizeof(struct bmd_softc),
100 1.1.2.2 thorpej bmd_match, bmd_attach, NULL, NULL);
101 1.1.2.2 thorpej
102 1.1.2.2 thorpej dev_type_open(bmdopen);
103 1.1.2.2 thorpej dev_type_close(bmdclose);
104 1.1.2.2 thorpej dev_type_read(bmdread);
105 1.1.2.2 thorpej dev_type_write(bmdwrite);
106 1.1.2.2 thorpej dev_type_ioctl(bmdioctl);
107 1.1.2.2 thorpej dev_type_strategy(bmdstrategy);
108 1.1.2.2 thorpej dev_type_dump(bmddump);
109 1.1.2.2 thorpej dev_type_size(bmdsize);
110 1.1.2.2 thorpej
111 1.1.2.2 thorpej const struct bdevsw bmd_bdevsw = {
112 1.1.2.2 thorpej bmdopen, bmdclose, bmdstrategy, bmdioctl, bmddump, bmdsize, D_DISK
113 1.1.2.2 thorpej };
114 1.1.2.2 thorpej
115 1.1.2.2 thorpej const struct cdevsw bmd_cdevsw = {
116 1.1.2.2 thorpej bmdopen, bmdclose, bmdread, bmdwrite, bmdioctl,
117 1.1.2.2 thorpej nostop, notty, nopoll, nommap, nokqfilter, D_DISK
118 1.1.2.2 thorpej };
119 1.1.2.2 thorpej
120 1.1.2.2 thorpej struct dkdriver bmddkdriver = { bmdstrategy };
121 1.1.2.2 thorpej
122 1.1.2.2 thorpej static int
123 1.1.2.2 thorpej bmd_match(struct device *parent, struct cfdata *cf, void *aux)
124 1.1.2.2 thorpej {
125 1.1.2.2 thorpej struct intio_attach_args *ia = aux;
126 1.1.2.2 thorpej bus_space_tag_t iot = ia->ia_bst;
127 1.1.2.2 thorpej bus_space_handle_t ioh;
128 1.1.2.2 thorpej
129 1.1.2.2 thorpej if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
130 1.1.2.2 thorpej ia->ia_addr = BMD_ADDR1;
131 1.1.2.2 thorpej
132 1.1.2.2 thorpej /* fixed parameter */
133 1.1.2.2 thorpej if (ia->ia_addr != BMD_ADDR1 && ia->ia_addr != BMD_ADDR2)
134 1.1.2.2 thorpej return (0);
135 1.1.2.2 thorpej
136 1.1.2.2 thorpej if (badaddr((caddr_t)INTIO_ADDR(ia->ia_addr)))
137 1.1.2.2 thorpej return (0);
138 1.1.2.2 thorpej
139 1.1.2.2 thorpej ia->ia_size = 2;
140 1.1.2.2 thorpej if (bus_space_map(iot, ia->ia_addr, ia->ia_size, 0, &ioh))
141 1.1.2.2 thorpej return (0);
142 1.1.2.2 thorpej
143 1.1.2.2 thorpej bus_space_unmap(iot, ioh, ia->ia_size);
144 1.1.2.2 thorpej
145 1.1.2.2 thorpej return (1);
146 1.1.2.2 thorpej }
147 1.1.2.2 thorpej
148 1.1.2.2 thorpej static void
149 1.1.2.2 thorpej bmd_attach(struct device *parent, struct device *self, void *aux)
150 1.1.2.2 thorpej {
151 1.1.2.2 thorpej struct bmd_softc *sc = (struct bmd_softc *)self;
152 1.1.2.2 thorpej struct intio_attach_args *ia = aux;
153 1.1.2.2 thorpej bus_space_tag_t iot = ia->ia_bst;
154 1.1.2.2 thorpej bus_space_handle_t ioh;
155 1.1.2.2 thorpej u_int8_t r;
156 1.1.2.2 thorpej
157 1.1.2.2 thorpej printf(": Nereid Bank Memory Disk\n");
158 1.1.2.2 thorpej printf("%s: ", sc->sc_dev.dv_xname);
159 1.1.2.2 thorpej
160 1.1.2.2 thorpej /* Map I/O space */
161 1.1.2.2 thorpej ia->ia_size = 2;
162 1.1.2.2 thorpej if (bus_space_map(iot, ia->ia_addr, ia->ia_size, 0, &ioh)) {
163 1.1.2.2 thorpej printf("can't map I/O space\n");
164 1.1.2.2 thorpej return;
165 1.1.2.2 thorpej }
166 1.1.2.2 thorpej
167 1.1.2.2 thorpej sc->sc_iot = iot;
168 1.1.2.2 thorpej sc->sc_ioh = ioh;
169 1.1.2.2 thorpej
170 1.1.2.2 thorpej /* read control register */
171 1.1.2.2 thorpej r = bus_space_read_1(sc->sc_iot, sc->sc_ioh, BMD_CTRL);
172 1.1.2.2 thorpej
173 1.1.2.2 thorpej /* check enable-bit */
174 1.1.2.2 thorpej if ((r & BMD_CTRL_ENABLE) == 0) {
175 1.1.2.2 thorpej printf("disabled by DIP-SW 8\n");
176 1.1.2.2 thorpej return;
177 1.1.2.2 thorpej }
178 1.1.2.2 thorpej
179 1.1.2.2 thorpej if ((r & BMD_CTRL_MEMORY))
180 1.1.2.2 thorpej sc->sc_maxpage = 256;
181 1.1.2.2 thorpej else
182 1.1.2.2 thorpej sc->sc_maxpage = 64;
183 1.1.2.2 thorpej
184 1.1.2.2 thorpej if ((r & BMD_CTRL_WINDOW))
185 1.1.2.2 thorpej sc->sc_window = 0xef0000;
186 1.1.2.2 thorpej else
187 1.1.2.2 thorpej sc->sc_window = 0xee0000;
188 1.1.2.2 thorpej
189 1.1.2.2 thorpej /* Map bank area */
190 1.1.2.2 thorpej if (bus_space_map(iot, sc->sc_window, BMD_PAGESIZE, 0, &sc->sc_bank)) {
191 1.1.2.2 thorpej printf("can't map bank area: 0x%x\n", sc->sc_window);
192 1.1.2.2 thorpej return;
193 1.1.2.2 thorpej }
194 1.1.2.2 thorpej
195 1.1.2.2 thorpej printf("%d MB, 0x%x(64KB) x %d pages\n",
196 1.1.2.2 thorpej (sc->sc_maxpage / 16), sc->sc_window, sc->sc_maxpage);
197 1.1.2.2 thorpej
198 1.1.2.2 thorpej sc->sc_dkdev.dk_driver = &bmddkdriver;
199 1.1.2.2 thorpej sc->sc_dkdev.dk_name = sc->sc_dev.dv_xname;
200 1.1.2.2 thorpej disk_attach(&sc->sc_dkdev);
201 1.1.2.2 thorpej }
202 1.1.2.2 thorpej
203 1.1.2.2 thorpej int
204 1.1.2.2 thorpej bmdopen(dev_t dev, int oflags, int devtype, struct proc *p)
205 1.1.2.2 thorpej {
206 1.1.2.2 thorpej int unit = BMD_UNIT(dev);
207 1.1.2.2 thorpej struct bmd_softc *sc;
208 1.1.2.2 thorpej
209 1.1.2.2 thorpej DPRINTF(("%s%d\n", __FUNCTION__, unit));
210 1.1.2.2 thorpej
211 1.1.2.2 thorpej if (unit >= bmd_cd.cd_ndevs)
212 1.1.2.2 thorpej return ENXIO;
213 1.1.2.2 thorpej
214 1.1.2.2 thorpej sc = bmd_cd.cd_devs[unit];
215 1.1.2.2 thorpej if (sc == NULL)
216 1.1.2.2 thorpej return ENXIO;
217 1.1.2.2 thorpej
218 1.1.2.2 thorpej switch (devtype) {
219 1.1.2.2 thorpej case S_IFCHR:
220 1.1.2.2 thorpej sc->sc_flags |= BMD_OPENCHR;
221 1.1.2.2 thorpej break;
222 1.1.2.2 thorpej case S_IFBLK:
223 1.1.2.2 thorpej sc->sc_flags |= BMD_OPENBLK;
224 1.1.2.2 thorpej break;
225 1.1.2.2 thorpej }
226 1.1.2.2 thorpej
227 1.1.2.2 thorpej bmd_getdisklabel(sc, dev);
228 1.1.2.2 thorpej
229 1.1.2.2 thorpej return (0);
230 1.1.2.2 thorpej }
231 1.1.2.2 thorpej
232 1.1.2.2 thorpej int
233 1.1.2.2 thorpej bmdclose(dev_t dev, int fflag, int devtype, struct proc *p)
234 1.1.2.2 thorpej {
235 1.1.2.2 thorpej int unit = BMD_UNIT(dev);
236 1.1.2.2 thorpej struct bmd_softc *sc = bmd_cd.cd_devs[unit];
237 1.1.2.2 thorpej
238 1.1.2.2 thorpej DPRINTF(("%s%d\n", __FUNCTION__, unit));
239 1.1.2.2 thorpej
240 1.1.2.2 thorpej switch (devtype) {
241 1.1.2.2 thorpej case S_IFCHR:
242 1.1.2.2 thorpej sc->sc_flags &= ~BMD_OPENCHR;
243 1.1.2.2 thorpej break;
244 1.1.2.2 thorpej case S_IFBLK:
245 1.1.2.2 thorpej sc->sc_flags &= ~BMD_OPENBLK;
246 1.1.2.2 thorpej break;
247 1.1.2.2 thorpej }
248 1.1.2.2 thorpej
249 1.1.2.2 thorpej return (0);
250 1.1.2.2 thorpej }
251 1.1.2.2 thorpej
252 1.1.2.2 thorpej void
253 1.1.2.2 thorpej bmdstrategy(struct buf *bp)
254 1.1.2.2 thorpej {
255 1.1.2.2 thorpej int unit = BMD_UNIT(bp->b_dev);
256 1.1.2.2 thorpej struct bmd_softc *sc;
257 1.1.2.2 thorpej int offset, disksize, resid;
258 1.1.2.2 thorpej int page, pg_offset, pg_resid;
259 1.1.2.2 thorpej caddr_t data;
260 1.1.2.2 thorpej
261 1.1.2.2 thorpej if (unit >= bmd_cd.cd_ndevs) {
262 1.1.2.2 thorpej bp->b_error = ENXIO;
263 1.1.2.2 thorpej goto bad;
264 1.1.2.2 thorpej }
265 1.1.2.2 thorpej
266 1.1.2.2 thorpej sc = bmd_cd.cd_devs[unit];
267 1.1.2.2 thorpej if (sc == NULL) {
268 1.1.2.2 thorpej bp->b_error = ENXIO;
269 1.1.2.2 thorpej goto bad;
270 1.1.2.2 thorpej }
271 1.1.2.2 thorpej
272 1.1.2.2 thorpej DPRINTF(("bmdstrategy: %s blkno %d bcount %ld:",
273 1.1.2.2 thorpej (bp->b_flags & B_READ) ? "read " : "write",
274 1.1.2.2 thorpej bp->b_blkno, bp->b_bcount));
275 1.1.2.2 thorpej
276 1.1.2.2 thorpej bp->b_resid = bp->b_bcount;
277 1.1.2.2 thorpej offset = (bp->b_blkno << DEV_BSHIFT);
278 1.1.2.2 thorpej disksize = sc->sc_maxpage * BMD_PAGESIZE;
279 1.1.2.2 thorpej if (offset >= disksize) {
280 1.1.2.2 thorpej /* EOF if read, EIO if write */
281 1.1.2.2 thorpej if (bp->b_flags & B_READ)
282 1.1.2.2 thorpej goto done;
283 1.1.2.2 thorpej bp->b_error = EIO;
284 1.1.2.2 thorpej goto bad;
285 1.1.2.2 thorpej }
286 1.1.2.2 thorpej
287 1.1.2.2 thorpej resid = bp->b_resid;
288 1.1.2.2 thorpej if (resid > disksize - offset)
289 1.1.2.2 thorpej resid = disksize - offset;
290 1.1.2.2 thorpej
291 1.1.2.2 thorpej data = bp->b_data;
292 1.1.2.2 thorpej do {
293 1.1.2.2 thorpej page = offset / BMD_PAGESIZE;
294 1.1.2.2 thorpej pg_offset = offset % BMD_PAGESIZE;
295 1.1.2.2 thorpej
296 1.1.2.2 thorpej /* length */
297 1.1.2.2 thorpej pg_resid = MIN(resid, BMD_PAGESIZE - pg_offset);
298 1.1.2.2 thorpej
299 1.1.2.2 thorpej /* switch bank page */
300 1.1.2.2 thorpej bus_space_write_1(sc->sc_iot, sc->sc_ioh, BMD_PAGE, page);
301 1.1.2.2 thorpej
302 1.1.2.2 thorpej /* XXX we should use DMA transfer? */
303 1.1.2.2 thorpej if ((bp->b_flags & B_READ)) {
304 1.1.2.2 thorpej bus_space_read_region_1(sc->sc_iot, sc->sc_bank,
305 1.1.2.2 thorpej pg_offset, data, pg_resid);
306 1.1.2.2 thorpej } else {
307 1.1.2.2 thorpej bus_space_write_region_1(sc->sc_iot, sc->sc_bank,
308 1.1.2.2 thorpej pg_offset, data, pg_resid);
309 1.1.2.2 thorpej }
310 1.1.2.2 thorpej
311 1.1.2.2 thorpej data += pg_resid;
312 1.1.2.2 thorpej offset += pg_resid;
313 1.1.2.2 thorpej resid -= pg_resid;
314 1.1.2.2 thorpej bp->b_resid -= pg_resid;
315 1.1.2.2 thorpej } while (resid > 0);
316 1.1.2.2 thorpej
317 1.1.2.2 thorpej DPRINTF(("\n"));
318 1.1.2.2 thorpej
319 1.1.2.2 thorpej done:
320 1.1.2.2 thorpej biodone(bp);
321 1.1.2.2 thorpej return;
322 1.1.2.2 thorpej
323 1.1.2.2 thorpej bad:
324 1.1.2.2 thorpej bp->b_flags |= B_ERROR;
325 1.1.2.2 thorpej goto done;
326 1.1.2.2 thorpej }
327 1.1.2.2 thorpej
328 1.1.2.2 thorpej int
329 1.1.2.2 thorpej bmdioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
330 1.1.2.2 thorpej {
331 1.1.2.2 thorpej int unit = BMD_UNIT(dev);
332 1.1.2.2 thorpej struct bmd_softc *sc;
333 1.1.2.2 thorpej struct disklabel dl;
334 1.1.2.2 thorpej int error;
335 1.1.2.2 thorpej
336 1.1.2.2 thorpej DPRINTF(("%s%d %ld\n", __FUNCTION__, unit, cmd));
337 1.1.2.2 thorpej
338 1.1.2.2 thorpej if (unit >= bmd_cd.cd_ndevs)
339 1.1.2.2 thorpej return ENXIO;
340 1.1.2.2 thorpej
341 1.1.2.2 thorpej sc = bmd_cd.cd_devs[unit];
342 1.1.2.2 thorpej if (sc == NULL)
343 1.1.2.2 thorpej return ENXIO;
344 1.1.2.2 thorpej
345 1.1.2.2 thorpej switch (cmd) {
346 1.1.2.2 thorpej case DIOCGDINFO:
347 1.1.2.2 thorpej *(struct disklabel *)data = *(sc->sc_dkdev.dk_label);
348 1.1.2.2 thorpej break;
349 1.1.2.2 thorpej
350 1.1.2.2 thorpej case DIOCWDINFO:
351 1.1.2.2 thorpej if ((flag & FWRITE) == 0)
352 1.1.2.2 thorpej return EBADF;
353 1.1.2.2 thorpej
354 1.1.2.2 thorpej error = setdisklabel(&dl, (struct disklabel *)data, 0, NULL);
355 1.1.2.2 thorpej if (error)
356 1.1.2.2 thorpej return error;
357 1.1.2.2 thorpej error = writedisklabel(dev, bmdstrategy, &dl, NULL);
358 1.1.2.2 thorpej return error;
359 1.1.2.2 thorpej
360 1.1.2.2 thorpej default:
361 1.1.2.2 thorpej return EINVAL;
362 1.1.2.2 thorpej }
363 1.1.2.2 thorpej return 0;
364 1.1.2.2 thorpej }
365 1.1.2.2 thorpej
366 1.1.2.2 thorpej int
367 1.1.2.2 thorpej bmddump(dev_t dev, daddr_t blkno, caddr_t va, size_t size)
368 1.1.2.2 thorpej {
369 1.1.2.2 thorpej
370 1.1.2.2 thorpej DPRINTF(("%s%d ", __FUNCTION__, BMD_UNIT(dev)));
371 1.1.2.2 thorpej return ENODEV;
372 1.1.2.2 thorpej }
373 1.1.2.2 thorpej
374 1.1.2.2 thorpej int
375 1.1.2.2 thorpej bmdsize(dev_t dev)
376 1.1.2.2 thorpej {
377 1.1.2.2 thorpej int unit = BMD_UNIT(dev);
378 1.1.2.2 thorpej struct bmd_softc *sc;
379 1.1.2.2 thorpej
380 1.1.2.2 thorpej DPRINTF(("%s%d ", __FUNCTION__, unit));
381 1.1.2.2 thorpej
382 1.1.2.2 thorpej if (unit >= bmd_cd.cd_ndevs)
383 1.1.2.2 thorpej return 0;
384 1.1.2.2 thorpej
385 1.1.2.2 thorpej sc = bmd_cd.cd_devs[unit];
386 1.1.2.2 thorpej if (sc == NULL)
387 1.1.2.2 thorpej return 0;
388 1.1.2.2 thorpej
389 1.1.2.2 thorpej return (sc->sc_maxpage * BMD_PAGESIZE) >> DEV_BSHIFT;
390 1.1.2.2 thorpej }
391 1.1.2.2 thorpej
392 1.1.2.2 thorpej int
393 1.1.2.2 thorpej bmdread(dev_t dev, struct uio *uio, int ioflag)
394 1.1.2.2 thorpej {
395 1.1.2.2 thorpej return physio(bmdstrategy, NULL, dev, B_READ, minphys, uio);
396 1.1.2.2 thorpej }
397 1.1.2.2 thorpej
398 1.1.2.2 thorpej int
399 1.1.2.2 thorpej bmdwrite(dev_t dev, struct uio *uio, int ioflag)
400 1.1.2.2 thorpej {
401 1.1.2.2 thorpej return physio(bmdstrategy, NULL, dev, B_WRITE, minphys, uio);
402 1.1.2.2 thorpej }
403 1.1.2.2 thorpej
404 1.1.2.2 thorpej static int
405 1.1.2.2 thorpej bmd_getdisklabel(struct bmd_softc *sc, dev_t dev)
406 1.1.2.2 thorpej {
407 1.1.2.2 thorpej struct disklabel *lp;
408 1.1.2.2 thorpej int part;
409 1.1.2.2 thorpej
410 1.1.2.2 thorpej part = DISKPART(dev);
411 1.1.2.2 thorpej lp = sc->sc_dkdev.dk_label;
412 1.1.2.2 thorpej memset(lp, 0, sizeof(struct disklabel));
413 1.1.2.2 thorpej
414 1.1.2.2 thorpej lp->d_secsize = BMD_BSIZE;
415 1.1.2.2 thorpej lp->d_nsectors = BLKS_PER_PAGE;
416 1.1.2.2 thorpej lp->d_ntracks = sc->sc_maxpage;
417 1.1.2.2 thorpej lp->d_ncylinders = 1;
418 1.1.2.2 thorpej lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks;
419 1.1.2.2 thorpej lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;
420 1.1.2.2 thorpej
421 1.1.2.2 thorpej lp->d_type = DTYPE_LD;
422 1.1.2.2 thorpej lp->d_rpm = 300; /* dummy */
423 1.1.2.2 thorpej lp->d_interleave = 1; /* dummy? */
424 1.1.2.2 thorpej
425 1.1.2.2 thorpej lp->d_npartitions = part + 1;
426 1.1.2.2 thorpej lp->d_bbsize = 8192;
427 1.1.2.2 thorpej lp->d_sbsize = 8192; /* ? */
428 1.1.2.2 thorpej
429 1.1.2.2 thorpej lp->d_magic = DISKMAGIC;
430 1.1.2.2 thorpej lp->d_magic2 = DISKMAGIC;
431 1.1.2.2 thorpej lp->d_checksum = dkcksum(lp);
432 1.1.2.2 thorpej
433 1.1.2.2 thorpej lp->d_partitions[part].p_size = lp->d_secperunit;
434 1.1.2.2 thorpej lp->d_partitions[part].p_fstype = FS_BSDFFS;
435 1.1.2.2 thorpej lp->d_partitions[part].p_fsize = 1024;
436 1.1.2.2 thorpej lp->d_partitions[part].p_frag = 8;
437 1.1.2.2 thorpej
438 1.1.2.2 thorpej return (0);
439 1.1.2.2 thorpej }
440