mcd.c revision 1.60 1 1.60 drochner /* $NetBSD: mcd.c,v 1.60 1998/01/14 12:14:41 drochner Exp $ */
2 1.20 cgd
3 1.1 cgd /*
4 1.28 mycroft * Copyright (c) 1993, 1994, 1995 Charles M. Hannum. All rights reserved.
5 1.28 mycroft *
6 1.28 mycroft * Redistribution and use in source and binary forms, with or without
7 1.28 mycroft * modification, are permitted provided that the following conditions
8 1.28 mycroft * are met:
9 1.28 mycroft * 1. Redistributions of source code must retain the above copyright
10 1.28 mycroft * notice, this list of conditions and the following disclaimer.
11 1.28 mycroft * 2. Redistributions in binary form must reproduce the above copyright
12 1.28 mycroft * notice, this list of conditions and the following disclaimer in the
13 1.28 mycroft * documentation and/or other materials provided with the distribution.
14 1.28 mycroft * 3. All advertising materials mentioning features or use of this software
15 1.28 mycroft * must display the following acknowledgement:
16 1.28 mycroft * This product includes software developed by Charles M. Hannum.
17 1.28 mycroft * 4. The name of the author may not be used to endorse or promote products
18 1.28 mycroft * derived from this software without specific prior written permission.
19 1.28 mycroft *
20 1.1 cgd * Copyright 1993 by Holger Veit (data part)
21 1.1 cgd * Copyright 1993 by Brian Moore (audio part)
22 1.1 cgd * All rights reserved.
23 1.1 cgd *
24 1.1 cgd * Redistribution and use in source and binary forms, with or without
25 1.1 cgd * modification, are permitted provided that the following conditions
26 1.1 cgd * are met:
27 1.1 cgd * 1. Redistributions of source code must retain the above copyright
28 1.1 cgd * notice, this list of conditions and the following disclaimer.
29 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
30 1.1 cgd * notice, this list of conditions and the following disclaimer in the
31 1.1 cgd * documentation and/or other materials provided with the distribution.
32 1.1 cgd * 3. All advertising materials mentioning features or use of this software
33 1.1 cgd * must display the following acknowledgement:
34 1.1 cgd * This software was developed by Holger Veit and Brian Moore
35 1.1 cgd * for use with "386BSD" and similar operating systems.
36 1.1 cgd * "Similar operating systems" includes mainly non-profit oriented
37 1.1 cgd * systems for research and education, including but not restricted to
38 1.1 cgd * "NetBSD", "FreeBSD", "Mach" (by CMU).
39 1.1 cgd * 4. Neither the name of the developer(s) nor the name "386BSD"
40 1.1 cgd * may be used to endorse or promote products derived from this
41 1.1 cgd * software without specific prior written permission.
42 1.1 cgd *
43 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER(S) ``AS IS'' AND ANY
44 1.1 cgd * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46 1.1 cgd * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER(S) BE
47 1.1 cgd * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
48 1.1 cgd * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
49 1.1 cgd * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
50 1.1 cgd * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
51 1.1 cgd * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
52 1.1 cgd * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
53 1.1 cgd * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 1.1 cgd */
55 1.2 cgd
56 1.6 mycroft /*static char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore";*/
57 1.1 cgd
58 1.3 mycroft #include <sys/types.h>
59 1.3 mycroft #include <sys/param.h>
60 1.3 mycroft #include <sys/systm.h>
61 1.6 mycroft #include <sys/kernel.h>
62 1.6 mycroft #include <sys/proc.h>
63 1.3 mycroft #include <sys/conf.h>
64 1.3 mycroft #include <sys/file.h>
65 1.3 mycroft #include <sys/buf.h>
66 1.3 mycroft #include <sys/stat.h>
67 1.3 mycroft #include <sys/uio.h>
68 1.3 mycroft #include <sys/ioctl.h>
69 1.3 mycroft #include <sys/cdio.h>
70 1.3 mycroft #include <sys/errno.h>
71 1.3 mycroft #include <sys/disklabel.h>
72 1.6 mycroft #include <sys/device.h>
73 1.21 mycroft #include <sys/disk.h>
74 1.3 mycroft
75 1.6 mycroft #include <machine/cpu.h>
76 1.49 mycroft #include <machine/intr.h>
77 1.53 christos #include <machine/bus.h>
78 1.3 mycroft
79 1.37 cgd #include <dev/isa/isavar.h>
80 1.27 cgd #include <dev/isa/mcdreg.h>
81 1.1 cgd
82 1.6 mycroft #ifndef MCDDEBUG
83 1.1 cgd #define MCD_TRACE(fmt,a,b,c,d)
84 1.1 cgd #else
85 1.51 christos #define MCD_TRACE(fmt,a,b,c,d) {if (sc->debug) {printf("%s: st=%02x: ", sc->sc_dev.dv_xname, sc->status); printf(fmt,a,b,c,d);}}
86 1.1 cgd #endif
87 1.1 cgd
88 1.21 mycroft #define MCDPART(dev) DISKPART(dev)
89 1.21 mycroft #define MCDUNIT(dev) DISKUNIT(dev)
90 1.1 cgd
91 1.1 cgd /* toc */
92 1.1 cgd #define MCD_MAXTOCS 104 /* from the Linux driver */
93 1.1 cgd
94 1.1 cgd struct mcd_mbx {
95 1.28 mycroft int retry, count;
96 1.28 mycroft struct buf *bp;
97 1.28 mycroft daddr_t blkno;
98 1.28 mycroft int nblk;
99 1.1 cgd int sz;
100 1.1 cgd u_long skip;
101 1.28 mycroft int state;
102 1.28 mycroft #define MCD_S_IDLE 0
103 1.28 mycroft #define MCD_S_BEGIN 1
104 1.30 mycroft #define MCD_S_WAITMODE 2
105 1.30 mycroft #define MCD_S_WAITREAD 3
106 1.28 mycroft int mode;
107 1.1 cgd };
108 1.1 cgd
109 1.6 mycroft struct mcd_softc {
110 1.6 mycroft struct device sc_dev;
111 1.44 thorpej struct disk sc_dk;
112 1.37 cgd void *sc_ih;
113 1.6 mycroft
114 1.53 christos bus_space_tag_t sc_iot;
115 1.53 christos bus_space_handle_t sc_ioh;
116 1.53 christos
117 1.28 mycroft int irq, drq;
118 1.28 mycroft
119 1.28 mycroft char *type;
120 1.28 mycroft int flags;
121 1.28 mycroft #define MCDF_LOCKED 0x01
122 1.28 mycroft #define MCDF_WANTED 0x02
123 1.28 mycroft #define MCDF_WLABEL 0x04 /* label is writable */
124 1.28 mycroft #define MCDF_LABELLING 0x08 /* writing label */
125 1.28 mycroft #define MCDF_LOADED 0x10 /* parameters loaded */
126 1.1 cgd short status;
127 1.28 mycroft short audio_status;
128 1.1 cgd int blksize;
129 1.1 cgd u_long disksize;
130 1.6 mycroft struct mcd_volinfo volinfo;
131 1.28 mycroft union mcd_qchninfo toc[MCD_MAXTOCS];
132 1.28 mycroft struct mcd_command lastpb;
133 1.28 mycroft struct mcd_mbx mbx;
134 1.28 mycroft int lastmode;
135 1.28 mycroft #define MCD_MD_UNKNOWN -1
136 1.28 mycroft int lastupc;
137 1.28 mycroft #define MCD_UPC_UNKNOWN -1
138 1.21 mycroft struct buf buf_queue;
139 1.53 christos u_char readcmd;
140 1.53 christos u_char debug;
141 1.53 christos u_char probe;
142 1.8 mycroft };
143 1.1 cgd
144 1.1 cgd /* prototypes */
145 1.48 christos /* XXX does not belong here */
146 1.48 christos cdev_decl(mcd);
147 1.48 christos bdev_decl(mcd);
148 1.28 mycroft
149 1.28 mycroft static int bcd2bin __P((bcd_t));
150 1.28 mycroft static bcd_t bin2bcd __P((int));
151 1.28 mycroft static void hsg2msf __P((int, bcd_t *));
152 1.28 mycroft static daddr_t msf2hsg __P((bcd_t *, int));
153 1.28 mycroft
154 1.28 mycroft int mcd_playtracks __P((struct mcd_softc *, struct ioc_play_track *));
155 1.28 mycroft int mcd_playmsf __P((struct mcd_softc *, struct ioc_play_msf *));
156 1.28 mycroft int mcd_playblocks __P((struct mcd_softc *, struct ioc_play_blocks *));
157 1.28 mycroft int mcd_stop __P((struct mcd_softc *));
158 1.28 mycroft int mcd_eject __P((struct mcd_softc *));
159 1.28 mycroft int mcd_read_subchannel __P((struct mcd_softc *, struct ioc_read_subchannel *));
160 1.28 mycroft int mcd_pause __P((struct mcd_softc *));
161 1.28 mycroft int mcd_resume __P((struct mcd_softc *));
162 1.28 mycroft int mcd_toc_header __P((struct mcd_softc *, struct ioc_toc_header *));
163 1.28 mycroft int mcd_toc_entries __P((struct mcd_softc *, struct ioc_read_toc_entry *));
164 1.28 mycroft
165 1.28 mycroft int mcd_getreply __P((struct mcd_softc *));
166 1.28 mycroft int mcd_getstat __P((struct mcd_softc *));
167 1.28 mycroft int mcd_getresult __P((struct mcd_softc *, struct mcd_result *));
168 1.6 mycroft void mcd_setflags __P((struct mcd_softc *));
169 1.6 mycroft int mcd_get __P((struct mcd_softc *, char *, int));
170 1.28 mycroft int mcd_send __P((struct mcd_softc *, struct mcd_mbox *, int));
171 1.29 mycroft int mcdintr __P((void *));
172 1.28 mycroft void mcd_soft_reset __P((struct mcd_softc *));
173 1.28 mycroft int mcd_hard_reset __P((struct mcd_softc *));
174 1.13 cgd int mcd_setmode __P((struct mcd_softc *, int));
175 1.28 mycroft int mcd_setupc __P((struct mcd_softc *, int));
176 1.6 mycroft int mcd_read_toc __P((struct mcd_softc *));
177 1.28 mycroft int mcd_getqchan __P((struct mcd_softc *, union mcd_qchninfo *, int));
178 1.28 mycroft int mcd_setlock __P((struct mcd_softc *, int));
179 1.1 cgd
180 1.53 christos int mcd_find __P((bus_space_tag_t, bus_space_handle_t, struct mcd_softc *));
181 1.60 drochner #ifdef __BROKEN_INDIRECT_CONFIG
182 1.23 mycroft int mcdprobe __P((struct device *, void *, void *));
183 1.60 drochner #else
184 1.60 drochner int mcdprobe __P((struct device *, struct cfdata *, void *));
185 1.60 drochner #endif
186 1.23 mycroft void mcdattach __P((struct device *, struct device *, void *));
187 1.8 mycroft
188 1.46 thorpej struct cfattach mcd_ca = {
189 1.46 thorpej sizeof(struct mcd_softc), mcdprobe, mcdattach
190 1.46 thorpej };
191 1.46 thorpej
192 1.59 thorpej extern struct cfdriver mcd_cd;
193 1.1 cgd
194 1.55 thorpej void mcdgetdefaultlabel __P((struct mcd_softc *, struct disklabel *));
195 1.48 christos void mcdgetdisklabel __P((struct mcd_softc *));
196 1.48 christos int mcd_get_parms __P((struct mcd_softc *));
197 1.48 christos void mcdstrategy __P((struct buf *));
198 1.48 christos void mcdstart __P((struct mcd_softc *));
199 1.48 christos int mcdlock __P((struct mcd_softc *));
200 1.48 christos void mcdunlock __P((struct mcd_softc *));
201 1.48 christos void mcd_pseudointr __P((void *));
202 1.1 cgd
203 1.28 mycroft struct dkdriver mcddkdriver = { mcdstrategy };
204 1.1 cgd
205 1.28 mycroft #define MCD_RETRIES 3
206 1.28 mycroft #define MCD_RDRETRIES 3
207 1.1 cgd
208 1.1 cgd /* several delays */
209 1.1 cgd #define RDELAY_WAITMODE 300
210 1.1 cgd #define RDELAY_WAITREAD 800
211 1.1 cgd
212 1.28 mycroft #define DELAY_GRANULARITY 25 /* 25us */
213 1.28 mycroft #define DELAY_GETREPLY 100000 /* 100000 * 25us */
214 1.1 cgd
215 1.8 mycroft void
216 1.8 mycroft mcdattach(parent, self, aux)
217 1.8 mycroft struct device *parent, *self;
218 1.8 mycroft void *aux;
219 1.1 cgd {
220 1.8 mycroft struct mcd_softc *sc = (void *)self;
221 1.8 mycroft struct isa_attach_args *ia = aux;
222 1.53 christos bus_space_tag_t iot = ia->ia_iot;
223 1.53 christos bus_space_handle_t ioh;
224 1.28 mycroft struct mcd_mbox mbx;
225 1.28 mycroft
226 1.53 christos /* Map i/o space */
227 1.57 thorpej if (bus_space_map(iot, ia->ia_iobase, MCD_NPORT, 0, &ioh)) {
228 1.57 thorpej printf(": can't map i/o space\n");
229 1.57 thorpej return;
230 1.57 thorpej }
231 1.53 christos
232 1.53 christos sc->sc_iot = iot;
233 1.53 christos sc->sc_ioh = ioh;
234 1.53 christos
235 1.53 christos sc->probe = 0;
236 1.53 christos sc->debug = 0;
237 1.53 christos
238 1.57 thorpej if (!mcd_find(iot, ioh, sc)) {
239 1.57 thorpej printf(": mcd_find failed\n");
240 1.58 fvdl return;
241 1.57 thorpej }
242 1.53 christos
243 1.44 thorpej /*
244 1.44 thorpej * Initialize and attach the disk structure.
245 1.44 thorpej */
246 1.44 thorpej sc->sc_dk.dk_driver = &mcddkdriver;
247 1.44 thorpej sc->sc_dk.dk_name = sc->sc_dev.dv_xname;
248 1.44 thorpej disk_attach(&sc->sc_dk);
249 1.44 thorpej
250 1.51 christos printf(": model %s\n", sc->type != 0 ? sc->type : "unknown");
251 1.28 mycroft
252 1.31 mycroft (void) mcd_setlock(sc, MCD_LK_UNLOCK);
253 1.28 mycroft
254 1.28 mycroft mbx.cmd.opcode = MCD_CMDCONFIGDRIVE;
255 1.28 mycroft mbx.cmd.length = sizeof(mbx.cmd.data.config) - 1;
256 1.28 mycroft mbx.cmd.data.config.subcommand = MCD_CF_IRQENABLE;
257 1.28 mycroft mbx.cmd.data.config.data1 = 0x01;
258 1.28 mycroft mbx.res.length = 0;
259 1.28 mycroft (void) mcd_send(sc, &mbx, 0);
260 1.1 cgd
261 1.28 mycroft mcd_soft_reset(sc);
262 1.11 mycroft
263 1.47 cgd sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
264 1.47 cgd IPL_BIO, mcdintr, sc);
265 1.1 cgd }
266 1.1 cgd
267 1.34 mycroft /*
268 1.34 mycroft * Wait interruptibly for an exclusive lock.
269 1.34 mycroft *
270 1.34 mycroft * XXX
271 1.34 mycroft * Several drivers do this; it should be abstracted and made MP-safe.
272 1.34 mycroft */
273 1.6 mycroft int
274 1.34 mycroft mcdlock(sc)
275 1.28 mycroft struct mcd_softc *sc;
276 1.28 mycroft {
277 1.28 mycroft int error;
278 1.28 mycroft
279 1.28 mycroft while ((sc->flags & MCDF_LOCKED) != 0) {
280 1.28 mycroft sc->flags |= MCDF_WANTED;
281 1.28 mycroft if ((error = tsleep(sc, PRIBIO | PCATCH, "mcdlck", 0)) != 0)
282 1.28 mycroft return error;
283 1.28 mycroft }
284 1.34 mycroft sc->flags |= MCDF_LOCKED;
285 1.28 mycroft return 0;
286 1.28 mycroft }
287 1.28 mycroft
288 1.34 mycroft /*
289 1.34 mycroft * Unlock and wake up any waiters.
290 1.34 mycroft */
291 1.28 mycroft void
292 1.28 mycroft mcdunlock(sc)
293 1.28 mycroft struct mcd_softc *sc;
294 1.28 mycroft {
295 1.28 mycroft
296 1.28 mycroft sc->flags &= ~MCDF_LOCKED;
297 1.28 mycroft if ((sc->flags & MCDF_WANTED) != 0) {
298 1.28 mycroft sc->flags &= ~MCDF_WANTED;
299 1.28 mycroft wakeup(sc);
300 1.28 mycroft }
301 1.28 mycroft }
302 1.28 mycroft
303 1.28 mycroft int
304 1.21 mycroft mcdopen(dev, flag, fmt, p)
305 1.6 mycroft dev_t dev;
306 1.21 mycroft int flag, fmt;
307 1.21 mycroft struct proc *p;
308 1.1 cgd {
309 1.28 mycroft int error;
310 1.21 mycroft int unit, part;
311 1.6 mycroft struct mcd_softc *sc;
312 1.28 mycroft
313 1.6 mycroft unit = MCDUNIT(dev);
314 1.46 thorpej if (unit >= mcd_cd.cd_ndevs)
315 1.1 cgd return ENXIO;
316 1.46 thorpej sc = mcd_cd.cd_devs[unit];
317 1.8 mycroft if (!sc)
318 1.6 mycroft return ENXIO;
319 1.1 cgd
320 1.48 christos if ((error = mcdlock(sc)) != 0)
321 1.28 mycroft return error;
322 1.21 mycroft
323 1.28 mycroft if (sc->sc_dk.dk_openmask != 0) {
324 1.28 mycroft /*
325 1.28 mycroft * If any partition is open, but the disk has been invalidated,
326 1.28 mycroft * disallow further opens.
327 1.28 mycroft */
328 1.35 mycroft if ((sc->flags & MCDF_LOADED) == 0) {
329 1.35 mycroft error = EIO;
330 1.35 mycroft goto bad3;
331 1.35 mycroft }
332 1.28 mycroft } else {
333 1.28 mycroft /*
334 1.28 mycroft * Lock the drawer. This will also notice any pending disk
335 1.28 mycroft * change or door open indicator and clear the MCDF_LOADED bit
336 1.28 mycroft * if necessary.
337 1.28 mycroft */
338 1.28 mycroft (void) mcd_setlock(sc, MCD_LK_LOCK);
339 1.28 mycroft
340 1.28 mycroft if ((sc->flags & MCDF_LOADED) == 0) {
341 1.28 mycroft /* Partially reset the state. */
342 1.28 mycroft sc->lastmode = MCD_MD_UNKNOWN;
343 1.28 mycroft sc->lastupc = MCD_UPC_UNKNOWN;
344 1.28 mycroft
345 1.28 mycroft sc->flags |= MCDF_LOADED;
346 1.28 mycroft
347 1.28 mycroft /* Set the mode, causing the disk to spin up. */
348 1.28 mycroft if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
349 1.28 mycroft goto bad2;
350 1.28 mycroft
351 1.28 mycroft /* Load the physical device parameters. */
352 1.28 mycroft if (mcd_get_parms(sc) != 0) {
353 1.28 mycroft error = ENXIO;
354 1.28 mycroft goto bad2;
355 1.28 mycroft }
356 1.1 cgd
357 1.33 mycroft /* Read the table of contents. */
358 1.33 mycroft if ((error = mcd_read_toc(sc)) != 0)
359 1.33 mycroft goto bad2;
360 1.33 mycroft
361 1.28 mycroft /* Fabricate a disk label. */
362 1.28 mycroft mcdgetdisklabel(sc);
363 1.28 mycroft }
364 1.21 mycroft }
365 1.21 mycroft
366 1.6 mycroft MCD_TRACE("open: partition=%d disksize=%d blksize=%d\n", part,
367 1.6 mycroft sc->disksize, sc->blksize, 0);
368 1.1 cgd
369 1.34 mycroft part = MCDPART(dev);
370 1.34 mycroft
371 1.28 mycroft /* Check that the partition exists. */
372 1.6 mycroft if (part != RAW_PART &&
373 1.44 thorpej (part >= sc->sc_dk.dk_label->d_npartitions ||
374 1.44 thorpej sc->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
375 1.28 mycroft error = ENXIO;
376 1.28 mycroft goto bad;
377 1.28 mycroft }
378 1.1 cgd
379 1.21 mycroft /* Insure only one open at a time. */
380 1.21 mycroft switch (fmt) {
381 1.21 mycroft case S_IFCHR:
382 1.21 mycroft sc->sc_dk.dk_copenmask |= (1 << part);
383 1.21 mycroft break;
384 1.21 mycroft case S_IFBLK:
385 1.21 mycroft sc->sc_dk.dk_bopenmask |= (1 << part);
386 1.21 mycroft break;
387 1.21 mycroft }
388 1.21 mycroft sc->sc_dk.dk_openmask = sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
389 1.21 mycroft
390 1.34 mycroft mcdunlock(sc);
391 1.6 mycroft return 0;
392 1.28 mycroft
393 1.28 mycroft bad2:
394 1.28 mycroft sc->flags &= ~MCDF_LOADED;
395 1.28 mycroft
396 1.28 mycroft bad:
397 1.28 mycroft if (sc->sc_dk.dk_openmask == 0) {
398 1.28 mycroft #if 0
399 1.28 mycroft (void) mcd_setmode(sc, MCD_MD_SLEEP);
400 1.28 mycroft #endif
401 1.28 mycroft (void) mcd_setlock(sc, MCD_LK_UNLOCK);
402 1.28 mycroft }
403 1.28 mycroft
404 1.35 mycroft bad3:
405 1.34 mycroft mcdunlock(sc);
406 1.28 mycroft return error;
407 1.1 cgd }
408 1.1 cgd
409 1.6 mycroft int
410 1.48 christos mcdclose(dev, flag, fmt, p)
411 1.6 mycroft dev_t dev;
412 1.21 mycroft int flag, fmt;
413 1.48 christos struct proc *p;
414 1.1 cgd {
415 1.46 thorpej struct mcd_softc *sc = mcd_cd.cd_devs[MCDUNIT(dev)];
416 1.21 mycroft int part = MCDPART(dev);
417 1.34 mycroft int error;
418 1.1 cgd
419 1.21 mycroft MCD_TRACE("close: partition=%d\n", part, 0, 0, 0);
420 1.6 mycroft
421 1.48 christos if ((error = mcdlock(sc)) != 0)
422 1.34 mycroft return error;
423 1.34 mycroft
424 1.21 mycroft switch (fmt) {
425 1.21 mycroft case S_IFCHR:
426 1.21 mycroft sc->sc_dk.dk_copenmask &= ~(1 << part);
427 1.21 mycroft break;
428 1.21 mycroft case S_IFBLK:
429 1.21 mycroft sc->sc_dk.dk_bopenmask &= ~(1 << part);
430 1.21 mycroft break;
431 1.21 mycroft }
432 1.21 mycroft sc->sc_dk.dk_openmask = sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
433 1.1 cgd
434 1.28 mycroft if (sc->sc_dk.dk_openmask == 0) {
435 1.34 mycroft /* XXXX Must wait for I/O to complete! */
436 1.28 mycroft
437 1.28 mycroft #if 0
438 1.28 mycroft (void) mcd_setmode(sc, MCD_MD_SLEEP);
439 1.28 mycroft #endif
440 1.28 mycroft (void) mcd_setlock(sc, MCD_LK_UNLOCK);
441 1.28 mycroft }
442 1.28 mycroft
443 1.34 mycroft mcdunlock(sc);
444 1.1 cgd return 0;
445 1.1 cgd }
446 1.1 cgd
447 1.6 mycroft void
448 1.6 mycroft mcdstrategy(bp)
449 1.6 mycroft struct buf *bp;
450 1.1 cgd {
451 1.46 thorpej struct mcd_softc *sc = mcd_cd.cd_devs[MCDUNIT(bp->b_dev)];
452 1.1 cgd int s;
453 1.1 cgd
454 1.6 mycroft /* Test validity. */
455 1.6 mycroft MCD_TRACE("strategy: buf=0x%lx blkno=%ld bcount=%ld\n", bp,
456 1.6 mycroft bp->b_blkno, bp->b_bcount, 0);
457 1.28 mycroft if (bp->b_blkno < 0 ||
458 1.28 mycroft (bp->b_bcount % sc->blksize) != 0) {
459 1.51 christos printf("%s: strategy: blkno = %d bcount = %ld\n",
460 1.6 mycroft sc->sc_dev.dv_xname, bp->b_blkno, bp->b_bcount);
461 1.1 cgd bp->b_error = EINVAL;
462 1.1 cgd goto bad;
463 1.1 cgd }
464 1.1 cgd
465 1.6 mycroft /* If device invalidated (e.g. media change, door open), error. */
466 1.28 mycroft if ((sc->flags & MCDF_LOADED) == 0) {
467 1.6 mycroft MCD_TRACE("strategy: drive not valid\n", 0, 0, 0, 0);
468 1.1 cgd bp->b_error = EIO;
469 1.1 cgd goto bad;
470 1.1 cgd }
471 1.1 cgd
472 1.6 mycroft /* No data to read. */
473 1.1 cgd if (bp->b_bcount == 0)
474 1.1 cgd goto done;
475 1.1 cgd
476 1.28 mycroft /*
477 1.28 mycroft * Do bounds checking, adjust transfer. if error, process.
478 1.28 mycroft * If end of partition, just return.
479 1.28 mycroft */
480 1.36 mycroft if (MCDPART(bp->b_dev) != RAW_PART &&
481 1.44 thorpej bounds_check_with_label(bp, sc->sc_dk.dk_label,
482 1.28 mycroft (sc->flags & (MCDF_WLABEL|MCDF_LABELLING)) != 0) <= 0)
483 1.28 mycroft goto done;
484 1.1 cgd
485 1.6 mycroft /* Queue it. */
486 1.1 cgd s = splbio();
487 1.28 mycroft disksort(&sc->buf_queue, bp);
488 1.1 cgd splx(s);
489 1.28 mycroft if (!sc->buf_queue.b_active)
490 1.28 mycroft mcdstart(sc);
491 1.1 cgd return;
492 1.1 cgd
493 1.1 cgd bad:
494 1.1 cgd bp->b_flags |= B_ERROR;
495 1.1 cgd done:
496 1.1 cgd bp->b_resid = bp->b_bcount;
497 1.1 cgd biodone(bp);
498 1.1 cgd }
499 1.1 cgd
500 1.28 mycroft void
501 1.28 mycroft mcdstart(sc)
502 1.6 mycroft struct mcd_softc *sc;
503 1.1 cgd {
504 1.28 mycroft struct buf *bp, *dp = &sc->buf_queue;
505 1.21 mycroft int s;
506 1.1 cgd
507 1.21 mycroft loop:
508 1.21 mycroft s = splbio();
509 1.21 mycroft
510 1.28 mycroft bp = dp->b_actf;
511 1.28 mycroft if (bp == NULL) {
512 1.28 mycroft /* Nothing to do. */
513 1.28 mycroft dp->b_active = 0;
514 1.1 cgd splx(s);
515 1.1 cgd return;
516 1.1 cgd }
517 1.1 cgd
518 1.21 mycroft /* Block found to process; dequeue. */
519 1.21 mycroft MCD_TRACE("start: found block bp=0x%x\n", bp, 0, 0, 0);
520 1.28 mycroft dp->b_actf = bp->b_actf;
521 1.21 mycroft splx(s);
522 1.21 mycroft
523 1.6 mycroft /* Changed media? */
524 1.28 mycroft if ((sc->flags & MCDF_LOADED) == 0) {
525 1.6 mycroft MCD_TRACE("start: drive not valid\n", 0, 0, 0, 0);
526 1.21 mycroft bp->b_error = EIO;
527 1.21 mycroft bp->b_flags |= B_ERROR;
528 1.21 mycroft biodone(bp);
529 1.21 mycroft goto loop;
530 1.1 cgd }
531 1.1 cgd
532 1.28 mycroft dp->b_active = 1;
533 1.28 mycroft
534 1.44 thorpej /* Instrumentation. */
535 1.44 thorpej s = splbio();
536 1.44 thorpej disk_busy(&sc->sc_dk);
537 1.44 thorpej splx(s);
538 1.44 thorpej
539 1.28 mycroft sc->mbx.retry = MCD_RDRETRIES;
540 1.6 mycroft sc->mbx.bp = bp;
541 1.28 mycroft sc->mbx.blkno = bp->b_blkno / (sc->blksize / DEV_BSIZE);
542 1.28 mycroft if (MCDPART(bp->b_dev) != RAW_PART) {
543 1.28 mycroft struct partition *p;
544 1.44 thorpej p = &sc->sc_dk.dk_label->d_partitions[MCDPART(bp->b_dev)];
545 1.28 mycroft sc->mbx.blkno += p->p_offset;
546 1.28 mycroft }
547 1.28 mycroft sc->mbx.nblk = bp->b_bcount / sc->blksize;
548 1.28 mycroft sc->mbx.sz = sc->blksize;
549 1.28 mycroft sc->mbx.skip = 0;
550 1.28 mycroft sc->mbx.state = MCD_S_BEGIN;
551 1.28 mycroft sc->mbx.mode = MCD_MD_COOKED;
552 1.6 mycroft
553 1.28 mycroft s = splbio();
554 1.29 mycroft (void) mcdintr(sc);
555 1.28 mycroft splx(s);
556 1.40 mycroft }
557 1.40 mycroft
558 1.40 mycroft int
559 1.48 christos mcdread(dev, uio, flags)
560 1.40 mycroft dev_t dev;
561 1.40 mycroft struct uio *uio;
562 1.48 christos int flags;
563 1.40 mycroft {
564 1.40 mycroft
565 1.40 mycroft return (physio(mcdstrategy, NULL, dev, B_READ, minphys, uio));
566 1.40 mycroft }
567 1.40 mycroft
568 1.40 mycroft int
569 1.48 christos mcdwrite(dev, uio, flags)
570 1.40 mycroft dev_t dev;
571 1.40 mycroft struct uio *uio;
572 1.48 christos int flags;
573 1.40 mycroft {
574 1.40 mycroft
575 1.40 mycroft return (physio(mcdstrategy, NULL, dev, B_WRITE, minphys, uio));
576 1.6 mycroft }
577 1.6 mycroft
578 1.6 mycroft int
579 1.28 mycroft mcdioctl(dev, cmd, addr, flag, p)
580 1.6 mycroft dev_t dev;
581 1.22 cgd u_long cmd;
582 1.6 mycroft caddr_t addr;
583 1.28 mycroft int flag;
584 1.6 mycroft struct proc *p;
585 1.1 cgd {
586 1.46 thorpej struct mcd_softc *sc = mcd_cd.cd_devs[MCDUNIT(dev)];
587 1.28 mycroft int error;
588 1.1 cgd
589 1.28 mycroft MCD_TRACE("ioctl: cmd=0x%x\n", cmd, 0, 0, 0);
590 1.28 mycroft
591 1.28 mycroft if ((sc->flags & MCDF_LOADED) == 0)
592 1.1 cgd return EIO;
593 1.21 mycroft
594 1.1 cgd switch (cmd) {
595 1.28 mycroft case DIOCGDINFO:
596 1.44 thorpej *(struct disklabel *)addr = *(sc->sc_dk.dk_label);
597 1.28 mycroft return 0;
598 1.28 mycroft
599 1.28 mycroft case DIOCGPART:
600 1.44 thorpej ((struct partinfo *)addr)->disklab = sc->sc_dk.dk_label;
601 1.28 mycroft ((struct partinfo *)addr)->part =
602 1.44 thorpej &sc->sc_dk.dk_label->d_partitions[MCDPART(dev)];
603 1.28 mycroft return 0;
604 1.28 mycroft
605 1.28 mycroft case DIOCWDINFO:
606 1.28 mycroft case DIOCSDINFO:
607 1.28 mycroft if ((flag & FWRITE) == 0)
608 1.28 mycroft return EBADF;
609 1.28 mycroft
610 1.48 christos if ((error = mcdlock(sc)) != 0)
611 1.28 mycroft return error;
612 1.34 mycroft sc->flags |= MCDF_LABELLING;
613 1.28 mycroft
614 1.44 thorpej error = setdisklabel(sc->sc_dk.dk_label,
615 1.28 mycroft (struct disklabel *)addr, /*sc->sc_dk.dk_openmask : */0,
616 1.44 thorpej sc->sc_dk.dk_cpulabel);
617 1.28 mycroft if (error == 0) {
618 1.28 mycroft }
619 1.28 mycroft
620 1.28 mycroft sc->flags &= ~MCDF_LABELLING;
621 1.28 mycroft mcdunlock(sc);
622 1.28 mycroft return error;
623 1.28 mycroft
624 1.28 mycroft case DIOCWLABEL:
625 1.28 mycroft return EBADF;
626 1.28 mycroft
627 1.55 thorpej case DIOCGDEFLABEL:
628 1.55 thorpej mcdgetdefaultlabel(sc, (struct disklabel *)addr);
629 1.55 thorpej return 0;
630 1.55 thorpej
631 1.1 cgd case CDIOCPLAYTRACKS:
632 1.21 mycroft return mcd_playtracks(sc, (struct ioc_play_track *)addr);
633 1.28 mycroft case CDIOCPLAYMSF:
634 1.28 mycroft return mcd_playmsf(sc, (struct ioc_play_msf *)addr);
635 1.1 cgd case CDIOCPLAYBLOCKS:
636 1.28 mycroft return mcd_playblocks(sc, (struct ioc_play_blocks *)addr);
637 1.1 cgd case CDIOCREADSUBCHANNEL:
638 1.28 mycroft return mcd_read_subchannel(sc, (struct ioc_read_subchannel *)addr);
639 1.1 cgd case CDIOREADTOCHEADER:
640 1.21 mycroft return mcd_toc_header(sc, (struct ioc_toc_header *)addr);
641 1.1 cgd case CDIOREADTOCENTRYS:
642 1.28 mycroft return mcd_toc_entries(sc, (struct ioc_read_toc_entry *)addr);
643 1.1 cgd case CDIOCSETPATCH:
644 1.1 cgd case CDIOCGETVOL:
645 1.1 cgd case CDIOCSETVOL:
646 1.1 cgd case CDIOCSETMONO:
647 1.18 mycroft case CDIOCSETSTEREO:
648 1.1 cgd case CDIOCSETMUTE:
649 1.1 cgd case CDIOCSETLEFT:
650 1.1 cgd case CDIOCSETRIGHT:
651 1.1 cgd return EINVAL;
652 1.1 cgd case CDIOCRESUME:
653 1.6 mycroft return mcd_resume(sc);
654 1.1 cgd case CDIOCPAUSE:
655 1.6 mycroft return mcd_pause(sc);
656 1.1 cgd case CDIOCSTART:
657 1.1 cgd return EINVAL;
658 1.1 cgd case CDIOCSTOP:
659 1.6 mycroft return mcd_stop(sc);
660 1.45 thorpej case CDIOCEJECT: /* FALLTHROUGH */
661 1.45 thorpej case DIOCEJECT:
662 1.28 mycroft return mcd_eject(sc);
663 1.28 mycroft case CDIOCALLOW:
664 1.28 mycroft return mcd_setlock(sc, MCD_LK_UNLOCK);
665 1.28 mycroft case CDIOCPREVENT:
666 1.28 mycroft return mcd_setlock(sc, MCD_LK_LOCK);
667 1.45 thorpej case DIOCLOCK:
668 1.45 thorpej return mcd_setlock(sc,
669 1.45 thorpej (*(int *)addr) ? MCD_LK_LOCK : MCD_LK_UNLOCK);
670 1.1 cgd case CDIOCSETDEBUG:
671 1.6 mycroft sc->debug = 1;
672 1.1 cgd return 0;
673 1.1 cgd case CDIOCCLRDEBUG:
674 1.6 mycroft sc->debug = 0;
675 1.1 cgd return 0;
676 1.1 cgd case CDIOCRESET:
677 1.28 mycroft return mcd_hard_reset(sc);
678 1.29 mycroft
679 1.1 cgd default:
680 1.1 cgd return ENOTTY;
681 1.1 cgd }
682 1.28 mycroft
683 1.6 mycroft #ifdef DIAGNOSTIC
684 1.6 mycroft panic("mcdioctl: impossible");
685 1.6 mycroft #endif
686 1.1 cgd }
687 1.1 cgd
688 1.28 mycroft void
689 1.55 thorpej mcdgetdefaultlabel(sc, lp)
690 1.6 mycroft struct mcd_softc *sc;
691 1.55 thorpej struct disklabel *lp;
692 1.1 cgd {
693 1.55 thorpej
694 1.42 mycroft bzero(lp, sizeof(struct disklabel));
695 1.28 mycroft
696 1.42 mycroft lp->d_secsize = sc->blksize;
697 1.42 mycroft lp->d_ntracks = 1;
698 1.42 mycroft lp->d_nsectors = 100;
699 1.42 mycroft lp->d_ncylinders = (sc->disksize / 100) + 1;
700 1.42 mycroft lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
701 1.42 mycroft
702 1.42 mycroft strncpy(lp->d_typename, "Mitsumi CD-ROM", 16);
703 1.42 mycroft lp->d_type = 0; /* XXX */
704 1.42 mycroft strncpy(lp->d_packname, "fictitious", 16);
705 1.42 mycroft lp->d_secperunit = sc->disksize;
706 1.42 mycroft lp->d_rpm = 300;
707 1.42 mycroft lp->d_interleave = 1;
708 1.42 mycroft lp->d_flags = D_REMOVABLE;
709 1.42 mycroft
710 1.42 mycroft lp->d_partitions[0].p_offset = 0;
711 1.42 mycroft lp->d_partitions[0].p_size =
712 1.42 mycroft lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
713 1.42 mycroft lp->d_partitions[0].p_fstype = FS_ISO9660;
714 1.42 mycroft lp->d_partitions[RAW_PART].p_offset = 0;
715 1.42 mycroft lp->d_partitions[RAW_PART].p_size =
716 1.42 mycroft lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
717 1.42 mycroft lp->d_partitions[RAW_PART].p_fstype = FS_ISO9660;
718 1.42 mycroft lp->d_npartitions = RAW_PART + 1;
719 1.55 thorpej
720 1.42 mycroft lp->d_magic = DISKMAGIC;
721 1.42 mycroft lp->d_magic2 = DISKMAGIC;
722 1.42 mycroft lp->d_checksum = dkcksum(lp);
723 1.55 thorpej }
724 1.55 thorpej
725 1.55 thorpej /*
726 1.55 thorpej * This could have been taken from scsi/cd.c, but it is not clear
727 1.55 thorpej * whether the scsi cd driver is linked in.
728 1.55 thorpej */
729 1.55 thorpej void
730 1.55 thorpej mcdgetdisklabel(sc)
731 1.55 thorpej struct mcd_softc *sc;
732 1.55 thorpej {
733 1.55 thorpej struct disklabel *lp = sc->sc_dk.dk_label;
734 1.55 thorpej
735 1.55 thorpej bzero(sc->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
736 1.55 thorpej
737 1.55 thorpej mcdgetdefaultlabel(sc, lp);
738 1.28 mycroft }
739 1.28 mycroft
740 1.28 mycroft int
741 1.28 mycroft mcd_get_parms(sc)
742 1.28 mycroft struct mcd_softc *sc;
743 1.28 mycroft {
744 1.28 mycroft struct mcd_mbox mbx;
745 1.28 mycroft daddr_t size;
746 1.28 mycroft int error;
747 1.28 mycroft
748 1.28 mycroft /* Send volume info command. */
749 1.28 mycroft mbx.cmd.opcode = MCD_CMDGETVOLINFO;
750 1.28 mycroft mbx.cmd.length = 0;
751 1.28 mycroft mbx.res.length = sizeof(mbx.res.data.volinfo);
752 1.28 mycroft if ((error = mcd_send(sc, &mbx, 1)) != 0)
753 1.28 mycroft return error;
754 1.28 mycroft
755 1.28 mycroft if (mbx.res.data.volinfo.trk_low == 0x00 &&
756 1.28 mycroft mbx.res.data.volinfo.trk_high == 0x00)
757 1.28 mycroft return EINVAL;
758 1.28 mycroft
759 1.28 mycroft /* Volinfo is OK. */
760 1.28 mycroft sc->volinfo = mbx.res.data.volinfo;
761 1.28 mycroft sc->blksize = MCD_BLKSIZE_COOKED;
762 1.28 mycroft size = msf2hsg(sc->volinfo.vol_msf, 0);
763 1.28 mycroft sc->disksize = size * (MCD_BLKSIZE_COOKED / DEV_BSIZE);
764 1.1 cgd return 0;
765 1.1 cgd }
766 1.1 cgd
767 1.6 mycroft int
768 1.6 mycroft mcdsize(dev)
769 1.6 mycroft dev_t dev;
770 1.1 cgd {
771 1.1 cgd
772 1.28 mycroft /* CD-ROMs are read-only. */
773 1.1 cgd return -1;
774 1.15 mycroft }
775 1.15 mycroft
776 1.15 mycroft int
777 1.39 cgd mcddump(dev, blkno, va, size)
778 1.39 cgd dev_t dev;
779 1.39 cgd daddr_t blkno;
780 1.39 cgd caddr_t va;
781 1.39 cgd size_t size;
782 1.15 mycroft {
783 1.15 mycroft
784 1.15 mycroft /* Not implemented. */
785 1.39 cgd return ENXIO;
786 1.1 cgd }
787 1.1 cgd
788 1.53 christos /*
789 1.53 christos * Find the board and fill in the softc.
790 1.53 christos */
791 1.6 mycroft int
792 1.53 christos mcd_find(iot, ioh, sc)
793 1.53 christos bus_space_tag_t iot;
794 1.53 christos bus_space_handle_t ioh;
795 1.53 christos struct mcd_softc *sc;
796 1.8 mycroft {
797 1.1 cgd int i;
798 1.28 mycroft struct mcd_mbox mbx;
799 1.6 mycroft
800 1.53 christos sc->sc_iot = iot;
801 1.53 christos sc->sc_ioh = ioh;
802 1.1 cgd
803 1.6 mycroft /* Send a reset. */
804 1.53 christos bus_space_write_1(iot, ioh, MCD_RESET, 0);
805 1.17 mycroft delay(1000000);
806 1.6 mycroft /* Get any pending status and throw away. */
807 1.6 mycroft for (i = 10; i; i--)
808 1.53 christos bus_space_read_1(iot, ioh, MCD_STATUS);
809 1.7 mycroft delay(1000);
810 1.1 cgd
811 1.6 mycroft /* Send get status command. */
812 1.28 mycroft mbx.cmd.opcode = MCD_CMDGETSTAT;
813 1.28 mycroft mbx.cmd.length = 0;
814 1.28 mycroft mbx.res.length = 0;
815 1.28 mycroft if (mcd_send(sc, &mbx, 0) != 0)
816 1.6 mycroft return 0;
817 1.1 cgd
818 1.28 mycroft /* Get info about the drive. */
819 1.28 mycroft mbx.cmd.opcode = MCD_CMDCONTINFO;
820 1.28 mycroft mbx.cmd.length = 0;
821 1.28 mycroft mbx.res.length = sizeof(mbx.res.data.continfo);
822 1.28 mycroft if (mcd_send(sc, &mbx, 0) != 0)
823 1.6 mycroft return 0;
824 1.1 cgd
825 1.6 mycroft /*
826 1.6 mycroft * The following is code which is not guaranteed to work for all
827 1.6 mycroft * drives, because the meaning of the expected 'M' is not clear
828 1.6 mycroft * (M_itsumi is an obvious assumption, but I don't trust that).
829 1.6 mycroft * Also, the original hack had a bogus condition that always
830 1.6 mycroft * returned true.
831 1.28 mycroft *
832 1.28 mycroft * Note: Which models support interrupts? >=LU005S?
833 1.6 mycroft */
834 1.41 cgd sc->readcmd = MCD_CMDREADSINGLESPEED;
835 1.28 mycroft switch (mbx.res.data.continfo.code) {
836 1.28 mycroft case 'M':
837 1.28 mycroft if (mbx.res.data.continfo.version <= 2)
838 1.28 mycroft sc->type = "LU002S";
839 1.28 mycroft else if (mbx.res.data.continfo.version <= 5)
840 1.28 mycroft sc->type = "LU005S";
841 1.28 mycroft else
842 1.28 mycroft sc->type = "LU006S";
843 1.28 mycroft break;
844 1.28 mycroft case 'F':
845 1.28 mycroft sc->type = "FX001";
846 1.28 mycroft break;
847 1.28 mycroft case 'D':
848 1.28 mycroft sc->type = "FX001D";
849 1.41 cgd sc->readcmd = MCD_CMDREADDOUBLESPEED;
850 1.28 mycroft break;
851 1.28 mycroft default:
852 1.52 mikel #ifdef MCDDEBUG
853 1.51 christos printf("%s: unrecognized drive version %c%02x; will try to use it anyway\n",
854 1.28 mycroft sc->sc_dev.dv_xname,
855 1.28 mycroft mbx.res.data.continfo.code, mbx.res.data.continfo.version);
856 1.52 mikel #endif
857 1.28 mycroft sc->type = 0;
858 1.28 mycroft break;
859 1.1 cgd }
860 1.6 mycroft
861 1.8 mycroft return 1;
862 1.53 christos
863 1.53 christos }
864 1.53 christos
865 1.53 christos int
866 1.53 christos mcdprobe(parent, match, aux)
867 1.53 christos struct device *parent;
868 1.60 drochner #ifdef __BROKEN_INDIRECT_CONFIG
869 1.60 drochner void *match;
870 1.60 drochner #else
871 1.60 drochner struct cfdata *match;
872 1.60 drochner #endif
873 1.60 drochner void *aux;
874 1.53 christos {
875 1.53 christos struct isa_attach_args *ia = aux;
876 1.53 christos struct mcd_softc sc;
877 1.53 christos bus_space_tag_t iot = ia->ia_iot;
878 1.53 christos bus_space_handle_t ioh;
879 1.53 christos int rv;
880 1.56 thorpej
881 1.56 thorpej /* Disallow wildcarded i/o address. */
882 1.56 thorpej if (ia->ia_iobase == ISACF_PORT_DEFAULT)
883 1.56 thorpej return (0);
884 1.53 christos
885 1.53 christos /* Map i/o space */
886 1.53 christos if (bus_space_map(iot, ia->ia_iobase, MCD_NPORT, 0, &ioh))
887 1.53 christos return 0;
888 1.53 christos
889 1.53 christos sc.debug = 0;
890 1.53 christos sc.probe = 1;
891 1.53 christos
892 1.53 christos rv = mcd_find(iot, ioh, &sc);
893 1.53 christos
894 1.53 christos bus_space_unmap(iot, ioh, MCD_NPORT);
895 1.53 christos
896 1.53 christos if (rv) {
897 1.53 christos ia->ia_iosize = MCD_NPORT;
898 1.53 christos ia->ia_msize = 0;
899 1.53 christos }
900 1.53 christos
901 1.53 christos return (rv);
902 1.1 cgd }
903 1.1 cgd
904 1.6 mycroft int
905 1.28 mycroft mcd_getreply(sc)
906 1.28 mycroft struct mcd_softc *sc;
907 1.1 cgd {
908 1.53 christos bus_space_tag_t iot = sc->sc_iot;
909 1.53 christos bus_space_handle_t ioh = sc->sc_ioh;
910 1.1 cgd int i;
911 1.1 cgd
912 1.6 mycroft /* Wait until xfer port senses data ready. */
913 1.28 mycroft for (i = DELAY_GETREPLY; i; i--) {
914 1.53 christos if ((bus_space_read_1(iot, ioh, MCD_XFER) &
915 1.53 christos MCD_XF_STATUSUNAVAIL) == 0)
916 1.28 mycroft break;
917 1.28 mycroft delay(DELAY_GRANULARITY);
918 1.1 cgd }
919 1.28 mycroft if (!i)
920 1.28 mycroft return -1;
921 1.28 mycroft
922 1.28 mycroft /* Get the data. */
923 1.53 christos return bus_space_read_1(iot, ioh, MCD_STATUS);
924 1.1 cgd }
925 1.1 cgd
926 1.6 mycroft int
927 1.28 mycroft mcd_getstat(sc)
928 1.6 mycroft struct mcd_softc *sc;
929 1.6 mycroft {
930 1.28 mycroft struct mcd_mbox mbx;
931 1.1 cgd
932 1.28 mycroft mbx.cmd.opcode = MCD_CMDGETSTAT;
933 1.28 mycroft mbx.cmd.length = 0;
934 1.28 mycroft mbx.res.length = 0;
935 1.28 mycroft return mcd_send(sc, &mbx, 1);
936 1.1 cgd }
937 1.1 cgd
938 1.6 mycroft int
939 1.28 mycroft mcd_getresult(sc, res)
940 1.6 mycroft struct mcd_softc *sc;
941 1.28 mycroft struct mcd_result *res;
942 1.1 cgd {
943 1.28 mycroft int i, x;
944 1.28 mycroft
945 1.28 mycroft if (sc->debug)
946 1.51 christos printf("%s: mcd_getresult: %d", sc->sc_dev.dv_xname,
947 1.28 mycroft res->length);
948 1.28 mycroft
949 1.28 mycroft if ((x = mcd_getreply(sc)) < 0) {
950 1.28 mycroft if (sc->debug)
951 1.51 christos printf(" timeout\n");
952 1.53 christos else if (!sc->probe)
953 1.51 christos printf("%s: timeout in getresult\n", sc->sc_dev.dv_xname);
954 1.28 mycroft return EIO;
955 1.28 mycroft }
956 1.28 mycroft if (sc->debug)
957 1.51 christos printf(" %02x", (u_int)x);
958 1.28 mycroft sc->status = x;
959 1.28 mycroft mcd_setflags(sc);
960 1.28 mycroft
961 1.28 mycroft if ((sc->status & MCD_ST_CMDCHECK) != 0)
962 1.28 mycroft return EINVAL;
963 1.1 cgd
964 1.28 mycroft for (i = 0; i < res->length; i++) {
965 1.28 mycroft if ((x = mcd_getreply(sc)) < 0) {
966 1.28 mycroft if (sc->debug)
967 1.51 christos printf(" timeout\n");
968 1.28 mycroft else
969 1.51 christos printf("%s: timeout in getresult\n", sc->sc_dev.dv_xname);
970 1.28 mycroft return EIO;
971 1.28 mycroft }
972 1.28 mycroft if (sc->debug)
973 1.51 christos printf(" %02x", (u_int)x);
974 1.28 mycroft res->data.raw.data[i] = x;
975 1.6 mycroft }
976 1.1 cgd
977 1.28 mycroft if (sc->debug)
978 1.51 christos printf(" succeeded\n");
979 1.28 mycroft
980 1.38 mycroft #ifdef MCDDEBUG
981 1.28 mycroft delay(10);
982 1.53 christos while ((bus_space_read_1(sc->sc_iot, sc->sc_ioh, MCD_XFER) &
983 1.53 christos MCD_XF_STATUSUNAVAIL) == 0) {
984 1.53 christos x = bus_space_read_1(sc->sc_iot, sc->sc_ioh, MCD_STATUS);
985 1.51 christos printf("%s: got extra byte %02x during getstatus\n",
986 1.28 mycroft sc->sc_dev.dv_xname, (u_int)x);
987 1.28 mycroft delay(10);
988 1.28 mycroft }
989 1.28 mycroft #endif
990 1.1 cgd
991 1.28 mycroft return 0;
992 1.1 cgd }
993 1.1 cgd
994 1.6 mycroft void
995 1.6 mycroft mcd_setflags(sc)
996 1.6 mycroft struct mcd_softc *sc;
997 1.1 cgd {
998 1.6 mycroft
999 1.6 mycroft /* Check flags. */
1000 1.28 mycroft if ((sc->flags & MCDF_LOADED) != 0 &&
1001 1.28 mycroft (sc->status & (MCD_ST_DSKCHNG | MCD_ST_DSKIN | MCD_ST_DOOROPEN)) !=
1002 1.28 mycroft MCD_ST_DSKIN) {
1003 1.28 mycroft if ((sc->status & MCD_ST_DOOROPEN) != 0)
1004 1.51 christos printf("%s: door open\n", sc->sc_dev.dv_xname);
1005 1.28 mycroft else if ((sc->status & MCD_ST_DSKIN) == 0)
1006 1.51 christos printf("%s: no disk present\n", sc->sc_dev.dv_xname);
1007 1.28 mycroft else if ((sc->status & MCD_ST_DSKCHNG) != 0)
1008 1.51 christos printf("%s: media change\n", sc->sc_dev.dv_xname);
1009 1.28 mycroft sc->flags &= ~MCDF_LOADED;
1010 1.1 cgd }
1011 1.1 cgd
1012 1.28 mycroft if ((sc->status & MCD_ST_AUDIOBSY) != 0)
1013 1.6 mycroft sc->audio_status = CD_AS_PLAY_IN_PROGRESS;
1014 1.28 mycroft else if (sc->audio_status == CD_AS_PLAY_IN_PROGRESS ||
1015 1.28 mycroft sc->audio_status == CD_AS_AUDIO_INVALID)
1016 1.6 mycroft sc->audio_status = CD_AS_PLAY_COMPLETED;
1017 1.1 cgd }
1018 1.1 cgd
1019 1.6 mycroft int
1020 1.28 mycroft mcd_send(sc, mbx, diskin)
1021 1.6 mycroft struct mcd_softc *sc;
1022 1.28 mycroft struct mcd_mbox *mbx;
1023 1.28 mycroft int diskin;
1024 1.1 cgd {
1025 1.28 mycroft int retry, i, error;
1026 1.53 christos bus_space_tag_t iot = sc->sc_iot;
1027 1.53 christos bus_space_handle_t ioh = sc->sc_ioh;
1028 1.1 cgd
1029 1.28 mycroft if (sc->debug) {
1030 1.51 christos printf("%s: mcd_send: %d %02x", sc->sc_dev.dv_xname,
1031 1.28 mycroft mbx->cmd.length, (u_int)mbx->cmd.opcode);
1032 1.28 mycroft for (i = 0; i < mbx->cmd.length; i++)
1033 1.51 christos printf(" %02x", (u_int)mbx->cmd.data.raw.data[i]);
1034 1.51 christos printf("\n");
1035 1.1 cgd }
1036 1.1 cgd
1037 1.28 mycroft for (retry = MCD_RETRIES; retry; retry--) {
1038 1.53 christos bus_space_write_1(iot, ioh, MCD_COMMAND, mbx->cmd.opcode);
1039 1.28 mycroft for (i = 0; i < mbx->cmd.length; i++)
1040 1.53 christos bus_space_write_1(iot, ioh, MCD_COMMAND, mbx->cmd.data.raw.data[i]);
1041 1.28 mycroft if ((error = mcd_getresult(sc, &mbx->res)) == 0)
1042 1.1 cgd break;
1043 1.28 mycroft if (error == EINVAL)
1044 1.28 mycroft return error;
1045 1.1 cgd }
1046 1.28 mycroft if (!retry)
1047 1.28 mycroft return error;
1048 1.28 mycroft if (diskin && (sc->flags & MCDF_LOADED) == 0)
1049 1.28 mycroft return EIO;
1050 1.6 mycroft
1051 1.1 cgd return 0;
1052 1.1 cgd }
1053 1.1 cgd
1054 1.28 mycroft static int
1055 1.6 mycroft bcd2bin(b)
1056 1.6 mycroft bcd_t b;
1057 1.1 cgd {
1058 1.6 mycroft
1059 1.1 cgd return (b >> 4) * 10 + (b & 15);
1060 1.1 cgd }
1061 1.1 cgd
1062 1.28 mycroft static bcd_t
1063 1.6 mycroft bin2bcd(b)
1064 1.6 mycroft int b;
1065 1.1 cgd {
1066 1.6 mycroft
1067 1.1 cgd return ((b / 10) << 4) | (b % 10);
1068 1.1 cgd }
1069 1.1 cgd
1070 1.28 mycroft static void
1071 1.6 mycroft hsg2msf(hsg, msf)
1072 1.6 mycroft int hsg;
1073 1.6 mycroft bcd_t *msf;
1074 1.1 cgd {
1075 1.6 mycroft
1076 1.1 cgd hsg += 150;
1077 1.1 cgd F_msf(msf) = bin2bcd(hsg % 75);
1078 1.28 mycroft hsg /= 75;
1079 1.28 mycroft S_msf(msf) = bin2bcd(hsg % 60);
1080 1.28 mycroft hsg /= 60;
1081 1.28 mycroft M_msf(msf) = bin2bcd(hsg);
1082 1.1 cgd }
1083 1.1 cgd
1084 1.28 mycroft static daddr_t
1085 1.28 mycroft msf2hsg(msf, relative)
1086 1.6 mycroft bcd_t *msf;
1087 1.28 mycroft int relative;
1088 1.1 cgd {
1089 1.28 mycroft daddr_t blkno;
1090 1.6 mycroft
1091 1.28 mycroft blkno = bcd2bin(M_msf(msf)) * 75 * 60 +
1092 1.28 mycroft bcd2bin(S_msf(msf)) * 75 +
1093 1.28 mycroft bcd2bin(F_msf(msf));
1094 1.28 mycroft if (!relative)
1095 1.28 mycroft blkno -= 150;
1096 1.28 mycroft return blkno;
1097 1.1 cgd }
1098 1.1 cgd
1099 1.28 mycroft void
1100 1.48 christos mcd_pseudointr(v)
1101 1.48 christos void *v;
1102 1.1 cgd {
1103 1.48 christos struct mcd_softc *sc = v;
1104 1.28 mycroft int s;
1105 1.1 cgd
1106 1.28 mycroft s = splbio();
1107 1.29 mycroft (void) mcdintr(sc);
1108 1.28 mycroft splx(s);
1109 1.1 cgd }
1110 1.1 cgd
1111 1.6 mycroft /*
1112 1.6 mycroft * State machine to process read requests.
1113 1.30 mycroft * Initialize with MCD_S_BEGIN: calculate sizes, and set mode
1114 1.1 cgd * MCD_S_WAITMODE: waits for status reply from set mode, set read command
1115 1.6 mycroft * MCD_S_WAITREAD: wait for read ready, read data.
1116 1.1 cgd */
1117 1.29 mycroft int
1118 1.29 mycroft mcdintr(arg)
1119 1.13 cgd void *arg;
1120 1.13 cgd {
1121 1.28 mycroft struct mcd_softc *sc = arg;
1122 1.28 mycroft struct mcd_mbx *mbx = &sc->mbx;
1123 1.6 mycroft struct buf *bp = mbx->bp;
1124 1.53 christos bus_space_tag_t iot = sc->sc_iot;
1125 1.53 christos bus_space_handle_t ioh = sc->sc_ioh;
1126 1.1 cgd
1127 1.28 mycroft int i;
1128 1.28 mycroft u_char x;
1129 1.28 mycroft bcd_t msf[3];
1130 1.1 cgd
1131 1.14 mycroft switch (mbx->state) {
1132 1.28 mycroft case MCD_S_IDLE:
1133 1.29 mycroft return 0;
1134 1.28 mycroft
1135 1.1 cgd case MCD_S_BEGIN:
1136 1.28 mycroft tryagain:
1137 1.28 mycroft if (mbx->mode == sc->lastmode)
1138 1.28 mycroft goto firstblock;
1139 1.28 mycroft
1140 1.28 mycroft sc->lastmode = MCD_MD_UNKNOWN;
1141 1.53 christos bus_space_write_1(iot, ioh, MCD_COMMAND, MCD_CMDSETMODE);
1142 1.53 christos bus_space_write_1(iot, ioh, MCD_COMMAND, mbx->mode);
1143 1.14 mycroft
1144 1.14 mycroft mbx->count = RDELAY_WAITMODE;
1145 1.14 mycroft mbx->state = MCD_S_WAITMODE;
1146 1.14 mycroft
1147 1.1 cgd case MCD_S_WAITMODE:
1148 1.28 mycroft untimeout(mcd_pseudointr, sc);
1149 1.28 mycroft for (i = 20; i; i--) {
1150 1.53 christos x = bus_space_read_1(iot, ioh, MCD_XFER);
1151 1.28 mycroft if ((x & MCD_XF_STATUSUNAVAIL) == 0)
1152 1.28 mycroft break;
1153 1.28 mycroft delay(50);
1154 1.1 cgd }
1155 1.28 mycroft if (i == 0)
1156 1.28 mycroft goto hold;
1157 1.53 christos sc->status = bus_space_read_1(iot, ioh, MCD_STATUS);
1158 1.6 mycroft mcd_setflags(sc);
1159 1.28 mycroft if ((sc->flags & MCDF_LOADED) == 0)
1160 1.28 mycroft goto changed;
1161 1.6 mycroft MCD_TRACE("doread: got WAITMODE delay=%d\n",
1162 1.6 mycroft RDELAY_WAITMODE - mbx->count, 0, 0, 0);
1163 1.14 mycroft
1164 1.28 mycroft sc->lastmode = mbx->mode;
1165 1.1 cgd
1166 1.28 mycroft firstblock:
1167 1.28 mycroft MCD_TRACE("doread: read blkno=%d for bp=0x%x\n", mbx->blkno,
1168 1.28 mycroft bp, 0, 0);
1169 1.1 cgd
1170 1.6 mycroft /* Build parameter block. */
1171 1.28 mycroft hsg2msf(mbx->blkno, msf);
1172 1.1 cgd
1173 1.6 mycroft /* Send the read command. */
1174 1.53 christos bus_space_write_1(iot, ioh, MCD_COMMAND, sc->readcmd);
1175 1.53 christos bus_space_write_1(iot, ioh, MCD_COMMAND, msf[0]);
1176 1.53 christos bus_space_write_1(iot, ioh, MCD_COMMAND, msf[1]);
1177 1.53 christos bus_space_write_1(iot, ioh, MCD_COMMAND, msf[2]);
1178 1.53 christos bus_space_write_1(iot, ioh, MCD_COMMAND, 0);
1179 1.53 christos bus_space_write_1(iot, ioh, MCD_COMMAND, 0);
1180 1.53 christos bus_space_write_1(iot, ioh, MCD_COMMAND, mbx->nblk);
1181 1.14 mycroft
1182 1.1 cgd mbx->count = RDELAY_WAITREAD;
1183 1.14 mycroft mbx->state = MCD_S_WAITREAD;
1184 1.28 mycroft
1185 1.28 mycroft case MCD_S_WAITREAD:
1186 1.28 mycroft untimeout(mcd_pseudointr, sc);
1187 1.28 mycroft nextblock:
1188 1.28 mycroft loop:
1189 1.28 mycroft for (i = 20; i; i--) {
1190 1.53 christos x = bus_space_read_1(iot, ioh, MCD_XFER);
1191 1.28 mycroft if ((x & MCD_XF_DATAUNAVAIL) == 0)
1192 1.28 mycroft goto gotblock;
1193 1.28 mycroft if ((x & MCD_XF_STATUSUNAVAIL) == 0)
1194 1.28 mycroft break;
1195 1.28 mycroft delay(50);
1196 1.28 mycroft }
1197 1.28 mycroft if (i == 0)
1198 1.28 mycroft goto hold;
1199 1.53 christos sc->status = bus_space_read_1(iot, ioh, MCD_STATUS);
1200 1.28 mycroft mcd_setflags(sc);
1201 1.28 mycroft if ((sc->flags & MCDF_LOADED) == 0)
1202 1.28 mycroft goto changed;
1203 1.28 mycroft #if 0
1204 1.51 christos printf("%s: got status byte %02x during read\n",
1205 1.28 mycroft sc->sc_dev.dv_xname, (u_int)sc->status);
1206 1.28 mycroft #endif
1207 1.28 mycroft goto loop;
1208 1.28 mycroft
1209 1.28 mycroft gotblock:
1210 1.28 mycroft MCD_TRACE("doread: got data delay=%d\n",
1211 1.28 mycroft RDELAY_WAITREAD - mbx->count, 0, 0, 0);
1212 1.28 mycroft
1213 1.28 mycroft /* Data is ready. */
1214 1.53 christos bus_space_write_1(iot, ioh, MCD_CTL2, 0x04); /* XXX */
1215 1.53 christos bus_space_read_multi_1(iot, ioh, MCD_RDATA,
1216 1.53 christos bp->b_data + mbx->skip, mbx->sz);
1217 1.53 christos bus_space_write_1(iot, ioh, MCD_CTL2, 0x0c); /* XXX */
1218 1.28 mycroft mbx->blkno += 1;
1219 1.28 mycroft mbx->skip += mbx->sz;
1220 1.28 mycroft if (--mbx->nblk > 0)
1221 1.28 mycroft goto nextblock;
1222 1.28 mycroft
1223 1.28 mycroft mbx->state = MCD_S_IDLE;
1224 1.28 mycroft
1225 1.28 mycroft /* Return buffer. */
1226 1.28 mycroft bp->b_resid = 0;
1227 1.44 thorpej disk_unbusy(&sc->sc_dk, bp->b_bcount);
1228 1.28 mycroft biodone(bp);
1229 1.28 mycroft
1230 1.28 mycroft mcdstart(sc);
1231 1.29 mycroft return 1;
1232 1.6 mycroft
1233 1.28 mycroft hold:
1234 1.14 mycroft if (mbx->count-- < 0) {
1235 1.51 christos printf("%s: timeout in state %d",
1236 1.28 mycroft sc->sc_dev.dv_xname, mbx->state);
1237 1.1 cgd goto readerr;
1238 1.1 cgd }
1239 1.14 mycroft
1240 1.28 mycroft #if 0
1241 1.51 christos printf("%s: sleep in state %d\n", sc->sc_dev.dv_xname,
1242 1.28 mycroft mbx->state);
1243 1.28 mycroft #endif
1244 1.28 mycroft timeout(mcd_pseudointr, sc, hz / 100);
1245 1.29 mycroft return -1;
1246 1.1 cgd }
1247 1.1 cgd
1248 1.1 cgd readerr:
1249 1.1 cgd if (mbx->retry-- > 0) {
1250 1.51 christos printf("; retrying\n");
1251 1.28 mycroft goto tryagain;
1252 1.28 mycroft } else
1253 1.51 christos printf("; giving up\n");
1254 1.1 cgd
1255 1.28 mycroft changed:
1256 1.6 mycroft /* Invalidate the buffer. */
1257 1.1 cgd bp->b_flags |= B_ERROR;
1258 1.28 mycroft bp->b_resid = bp->b_bcount - mbx->skip;
1259 1.44 thorpej disk_unbusy(&sc->sc_dk, (bp->b_bcount - bp->b_resid));
1260 1.1 cgd biodone(bp);
1261 1.28 mycroft
1262 1.28 mycroft mcdstart(sc);
1263 1.29 mycroft return -1;
1264 1.1 cgd
1265 1.6 mycroft #ifdef notyet
1266 1.51 christos printf("%s: unit timeout; resetting\n", sc->sc_dev.dv_xname);
1267 1.53 christos bus_space_write_1(iot, ioh, MCD_RESET, MCD_CMDRESET);
1268 1.7 mycroft delay(300000);
1269 1.28 mycroft (void) mcd_getstat(sc, 1);
1270 1.28 mycroft (void) mcd_getstat(sc, 1);
1271 1.28 mycroft /*sc->status &= ~MCD_ST_DSKCHNG; */
1272 1.6 mycroft sc->debug = 1; /* preventive set debug mode */
1273 1.1 cgd #endif
1274 1.1 cgd }
1275 1.1 cgd
1276 1.28 mycroft void
1277 1.28 mycroft mcd_soft_reset(sc)
1278 1.28 mycroft struct mcd_softc *sc;
1279 1.28 mycroft {
1280 1.28 mycroft
1281 1.29 mycroft sc->debug = 0;
1282 1.28 mycroft sc->flags = 0;
1283 1.28 mycroft sc->lastmode = MCD_MD_UNKNOWN;
1284 1.28 mycroft sc->lastupc = MCD_UPC_UNKNOWN;
1285 1.28 mycroft sc->audio_status = CD_AS_AUDIO_INVALID;
1286 1.53 christos bus_space_write_1(sc->sc_iot, sc->sc_ioh, MCD_CTL2, 0x0c); /* XXX */
1287 1.28 mycroft }
1288 1.28 mycroft
1289 1.28 mycroft int
1290 1.28 mycroft mcd_hard_reset(sc)
1291 1.28 mycroft struct mcd_softc *sc;
1292 1.28 mycroft {
1293 1.28 mycroft struct mcd_mbox mbx;
1294 1.28 mycroft
1295 1.28 mycroft mcd_soft_reset(sc);
1296 1.28 mycroft
1297 1.28 mycroft mbx.cmd.opcode = MCD_CMDRESET;
1298 1.28 mycroft mbx.cmd.length = 0;
1299 1.28 mycroft mbx.res.length = 0;
1300 1.28 mycroft return mcd_send(sc, &mbx, 0);
1301 1.28 mycroft }
1302 1.28 mycroft
1303 1.6 mycroft int
1304 1.6 mycroft mcd_setmode(sc, mode)
1305 1.6 mycroft struct mcd_softc *sc;
1306 1.6 mycroft int mode;
1307 1.1 cgd {
1308 1.28 mycroft struct mcd_mbox mbx;
1309 1.28 mycroft int error;
1310 1.28 mycroft
1311 1.28 mycroft if (sc->lastmode == mode)
1312 1.28 mycroft return 0;
1313 1.28 mycroft if (sc->debug)
1314 1.51 christos printf("%s: setting mode to %d\n", sc->sc_dev.dv_xname, mode);
1315 1.28 mycroft sc->lastmode = MCD_MD_UNKNOWN;
1316 1.28 mycroft
1317 1.28 mycroft mbx.cmd.opcode = MCD_CMDSETMODE;
1318 1.28 mycroft mbx.cmd.length = sizeof(mbx.cmd.data.datamode);
1319 1.28 mycroft mbx.cmd.data.datamode.mode = mode;
1320 1.28 mycroft mbx.res.length = 0;
1321 1.28 mycroft if ((error = mcd_send(sc, &mbx, 1)) != 0)
1322 1.28 mycroft return error;
1323 1.28 mycroft
1324 1.28 mycroft sc->lastmode = mode;
1325 1.28 mycroft return 0;
1326 1.28 mycroft }
1327 1.28 mycroft
1328 1.28 mycroft int
1329 1.28 mycroft mcd_setupc(sc, upc)
1330 1.28 mycroft struct mcd_softc *sc;
1331 1.28 mycroft int upc;
1332 1.28 mycroft {
1333 1.28 mycroft struct mcd_mbox mbx;
1334 1.28 mycroft int error;
1335 1.28 mycroft
1336 1.28 mycroft if (sc->lastupc == upc)
1337 1.28 mycroft return 0;
1338 1.28 mycroft if (sc->debug)
1339 1.51 christos printf("%s: setting upc to %d\n", sc->sc_dev.dv_xname, upc);
1340 1.28 mycroft sc->lastupc = MCD_UPC_UNKNOWN;
1341 1.1 cgd
1342 1.28 mycroft mbx.cmd.opcode = MCD_CMDCONFIGDRIVE;
1343 1.28 mycroft mbx.cmd.length = sizeof(mbx.cmd.data.config) - 1;
1344 1.28 mycroft mbx.cmd.data.config.subcommand = MCD_CF_READUPC;
1345 1.28 mycroft mbx.cmd.data.config.data1 = upc;
1346 1.28 mycroft mbx.res.length = 0;
1347 1.28 mycroft if ((error = mcd_send(sc, &mbx, 1)) != 0)
1348 1.28 mycroft return error;
1349 1.1 cgd
1350 1.28 mycroft sc->lastupc = upc;
1351 1.28 mycroft return 0;
1352 1.1 cgd }
1353 1.1 cgd
1354 1.6 mycroft int
1355 1.6 mycroft mcd_toc_header(sc, th)
1356 1.6 mycroft struct mcd_softc *sc;
1357 1.6 mycroft struct ioc_toc_header *th;
1358 1.1 cgd {
1359 1.1 cgd
1360 1.28 mycroft if (sc->debug)
1361 1.51 christos printf("%s: mcd_toc_header: reading toc header\n",
1362 1.28 mycroft sc->sc_dev.dv_xname);
1363 1.1 cgd
1364 1.28 mycroft th->len = msf2hsg(sc->volinfo.vol_msf, 0);
1365 1.6 mycroft th->starting_track = bcd2bin(sc->volinfo.trk_low);
1366 1.6 mycroft th->ending_track = bcd2bin(sc->volinfo.trk_high);
1367 1.1 cgd
1368 1.1 cgd return 0;
1369 1.1 cgd }
1370 1.1 cgd
1371 1.6 mycroft int
1372 1.6 mycroft mcd_read_toc(sc)
1373 1.6 mycroft struct mcd_softc *sc;
1374 1.1 cgd {
1375 1.1 cgd struct ioc_toc_header th;
1376 1.28 mycroft union mcd_qchninfo q;
1377 1.28 mycroft int error, trk, idx, retry;
1378 1.1 cgd
1379 1.28 mycroft if ((error = mcd_toc_header(sc, &th)) != 0)
1380 1.28 mycroft return error;
1381 1.1 cgd
1382 1.28 mycroft if ((error = mcd_stop(sc)) != 0)
1383 1.28 mycroft return error;
1384 1.1 cgd
1385 1.6 mycroft if (sc->debug)
1386 1.51 christos printf("%s: read_toc: reading qchannel info\n",
1387 1.6 mycroft sc->sc_dev.dv_xname);
1388 1.28 mycroft
1389 1.6 mycroft for (trk = th.starting_track; trk <= th.ending_track; trk++)
1390 1.28 mycroft sc->toc[trk].toc.idx_no = 0x00;
1391 1.1 cgd trk = th.ending_track - th.starting_track + 1;
1392 1.6 mycroft for (retry = 300; retry && trk > 0; retry--) {
1393 1.28 mycroft if (mcd_getqchan(sc, &q, CD_TRACK_INFO) != 0)
1394 1.6 mycroft break;
1395 1.28 mycroft if (q.toc.trk_no != 0x00 || q.toc.idx_no == 0x00)
1396 1.28 mycroft continue;
1397 1.28 mycroft idx = bcd2bin(q.toc.idx_no);
1398 1.28 mycroft if (idx < MCD_MAXTOCS &&
1399 1.28 mycroft sc->toc[idx].toc.idx_no == 0x00) {
1400 1.6 mycroft sc->toc[idx] = q;
1401 1.6 mycroft trk--;
1402 1.6 mycroft }
1403 1.1 cgd }
1404 1.1 cgd
1405 1.33 mycroft /* Inform the drive that we're finished so it turns off the light. */
1406 1.33 mycroft if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
1407 1.33 mycroft return error;
1408 1.33 mycroft
1409 1.6 mycroft if (trk != 0)
1410 1.28 mycroft return EINVAL;
1411 1.1 cgd
1412 1.28 mycroft /* Add a fake last+1 for mcd_playtracks(). */
1413 1.1 cgd idx = th.ending_track + 1;
1414 1.28 mycroft sc->toc[idx].toc.control = sc->toc[idx-1].toc.control;
1415 1.28 mycroft sc->toc[idx].toc.addr_type = sc->toc[idx-1].toc.addr_type;
1416 1.28 mycroft sc->toc[idx].toc.trk_no = 0x00;
1417 1.28 mycroft sc->toc[idx].toc.idx_no = 0xaa;
1418 1.28 mycroft sc->toc[idx].toc.absolute_pos[0] = sc->volinfo.vol_msf[0];
1419 1.28 mycroft sc->toc[idx].toc.absolute_pos[1] = sc->volinfo.vol_msf[1];
1420 1.28 mycroft sc->toc[idx].toc.absolute_pos[2] = sc->volinfo.vol_msf[2];
1421 1.1 cgd
1422 1.1 cgd return 0;
1423 1.1 cgd }
1424 1.1 cgd
1425 1.6 mycroft int
1426 1.28 mycroft mcd_toc_entries(sc, te)
1427 1.6 mycroft struct mcd_softc *sc;
1428 1.6 mycroft struct ioc_read_toc_entry *te;
1429 1.1 cgd {
1430 1.28 mycroft int len = te->data_len;
1431 1.6 mycroft struct ret_toc {
1432 1.28 mycroft struct ioc_toc_header header;
1433 1.28 mycroft struct cd_toc_entry entries[MCD_MAXTOCS];
1434 1.28 mycroft } data;
1435 1.28 mycroft u_char trk;
1436 1.28 mycroft daddr_t lba;
1437 1.28 mycroft int error, n;
1438 1.28 mycroft
1439 1.28 mycroft if (len > sizeof(data.entries) ||
1440 1.28 mycroft len < sizeof(struct cd_toc_entry))
1441 1.28 mycroft return EINVAL;
1442 1.28 mycroft if (te->address_format != CD_MSF_FORMAT &&
1443 1.28 mycroft te->address_format != CD_LBA_FORMAT)
1444 1.28 mycroft return EINVAL;
1445 1.1 cgd
1446 1.28 mycroft /* Copy the TOC header. */
1447 1.28 mycroft if ((error = mcd_toc_header(sc, &data.header)) != 0)
1448 1.28 mycroft return error;
1449 1.1 cgd
1450 1.6 mycroft /* Verify starting track. */
1451 1.28 mycroft trk = te->starting_track;
1452 1.28 mycroft if (trk == 0x00)
1453 1.28 mycroft trk = data.header.starting_track;
1454 1.28 mycroft else if (trk == 0xaa)
1455 1.28 mycroft trk = data.header.ending_track + 1;
1456 1.28 mycroft else if (trk < data.header.starting_track ||
1457 1.28 mycroft trk > data.header.ending_track + 1)
1458 1.1 cgd return EINVAL;
1459 1.1 cgd
1460 1.6 mycroft /* Copy the TOC data. */
1461 1.28 mycroft for (n = 0; trk <= data.header.ending_track + 1; trk++) {
1462 1.28 mycroft if (sc->toc[trk].toc.idx_no == 0x00)
1463 1.28 mycroft continue;
1464 1.28 mycroft data.entries[n].control = sc->toc[trk].toc.control;
1465 1.28 mycroft data.entries[n].addr_type = sc->toc[trk].toc.addr_type;
1466 1.28 mycroft data.entries[n].track = bcd2bin(sc->toc[trk].toc.idx_no);
1467 1.28 mycroft switch (te->address_format) {
1468 1.28 mycroft case CD_MSF_FORMAT:
1469 1.54 thorpej data.entries[n].addr.addr[0] = 0;
1470 1.54 thorpej data.entries[n].addr.addr[1] = bcd2bin(sc->toc[trk].toc.absolute_pos[0]);
1471 1.54 thorpej data.entries[n].addr.addr[2] = bcd2bin(sc->toc[trk].toc.absolute_pos[1]);
1472 1.54 thorpej data.entries[n].addr.addr[3] = bcd2bin(sc->toc[trk].toc.absolute_pos[2]);
1473 1.28 mycroft break;
1474 1.28 mycroft case CD_LBA_FORMAT:
1475 1.28 mycroft lba = msf2hsg(sc->toc[trk].toc.absolute_pos, 0);
1476 1.54 thorpej data.entries[n].addr.addr[0] = lba >> 24;
1477 1.54 thorpej data.entries[n].addr.addr[1] = lba >> 16;
1478 1.54 thorpej data.entries[n].addr.addr[2] = lba >> 8;
1479 1.54 thorpej data.entries[n].addr.addr[3] = lba;
1480 1.28 mycroft break;
1481 1.28 mycroft }
1482 1.28 mycroft n++;
1483 1.1 cgd }
1484 1.1 cgd
1485 1.28 mycroft len = min(len, n * sizeof(struct cd_toc_entry));
1486 1.28 mycroft
1487 1.6 mycroft /* Copy the data back. */
1488 1.28 mycroft return copyout(&data.entries[0], te->data, len);
1489 1.1 cgd }
1490 1.1 cgd
1491 1.6 mycroft int
1492 1.6 mycroft mcd_stop(sc)
1493 1.6 mycroft struct mcd_softc *sc;
1494 1.1 cgd {
1495 1.28 mycroft struct mcd_mbox mbx;
1496 1.28 mycroft int error;
1497 1.28 mycroft
1498 1.28 mycroft if (sc->debug)
1499 1.51 christos printf("%s: mcd_stop: stopping play\n", sc->sc_dev.dv_xname);
1500 1.28 mycroft
1501 1.28 mycroft mbx.cmd.opcode = MCD_CMDSTOPAUDIO;
1502 1.28 mycroft mbx.cmd.length = 0;
1503 1.28 mycroft mbx.res.length = 0;
1504 1.28 mycroft if ((error = mcd_send(sc, &mbx, 1)) != 0)
1505 1.28 mycroft return error;
1506 1.1 cgd
1507 1.6 mycroft sc->audio_status = CD_AS_PLAY_COMPLETED;
1508 1.1 cgd return 0;
1509 1.1 cgd }
1510 1.1 cgd
1511 1.6 mycroft int
1512 1.28 mycroft mcd_getqchan(sc, q, qchn)
1513 1.6 mycroft struct mcd_softc *sc;
1514 1.28 mycroft union mcd_qchninfo *q;
1515 1.28 mycroft int qchn;
1516 1.1 cgd {
1517 1.28 mycroft struct mcd_mbox mbx;
1518 1.28 mycroft int error;
1519 1.28 mycroft
1520 1.28 mycroft if (qchn == CD_TRACK_INFO) {
1521 1.28 mycroft if ((error = mcd_setmode(sc, MCD_MD_TOC)) != 0)
1522 1.28 mycroft return error;
1523 1.28 mycroft } else {
1524 1.28 mycroft if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
1525 1.28 mycroft return error;
1526 1.28 mycroft }
1527 1.28 mycroft if (qchn == CD_MEDIA_CATALOG) {
1528 1.28 mycroft if ((error = mcd_setupc(sc, MCD_UPC_ENABLE)) != 0)
1529 1.28 mycroft return error;
1530 1.28 mycroft } else {
1531 1.28 mycroft if ((error = mcd_setupc(sc, MCD_UPC_DISABLE)) != 0)
1532 1.28 mycroft return error;
1533 1.28 mycroft }
1534 1.28 mycroft
1535 1.28 mycroft mbx.cmd.opcode = MCD_CMDGETQCHN;
1536 1.28 mycroft mbx.cmd.length = 0;
1537 1.28 mycroft mbx.res.length = sizeof(mbx.res.data.qchninfo);
1538 1.28 mycroft if ((error = mcd_send(sc, &mbx, 1)) != 0)
1539 1.28 mycroft return error;
1540 1.1 cgd
1541 1.28 mycroft *q = mbx.res.data.qchninfo;
1542 1.1 cgd return 0;
1543 1.1 cgd }
1544 1.1 cgd
1545 1.6 mycroft int
1546 1.28 mycroft mcd_read_subchannel(sc, ch)
1547 1.6 mycroft struct mcd_softc *sc;
1548 1.6 mycroft struct ioc_read_subchannel *ch;
1549 1.1 cgd {
1550 1.28 mycroft int len = ch->data_len;
1551 1.28 mycroft union mcd_qchninfo q;
1552 1.1 cgd struct cd_sub_channel_info data;
1553 1.28 mycroft daddr_t lba;
1554 1.28 mycroft int error;
1555 1.1 cgd
1556 1.6 mycroft if (sc->debug)
1557 1.51 christos printf("%s: subchan: af=%d df=%d\n", sc->sc_dev.dv_xname,
1558 1.6 mycroft ch->address_format, ch->data_format);
1559 1.1 cgd
1560 1.28 mycroft if (len > sizeof(data) ||
1561 1.28 mycroft len < sizeof(struct cd_sub_channel_header))
1562 1.28 mycroft return EINVAL;
1563 1.28 mycroft if (ch->address_format != CD_MSF_FORMAT &&
1564 1.28 mycroft ch->address_format != CD_LBA_FORMAT)
1565 1.28 mycroft return EINVAL;
1566 1.28 mycroft if (ch->data_format != CD_CURRENT_POSITION &&
1567 1.28 mycroft ch->data_format != CD_MEDIA_CATALOG)
1568 1.28 mycroft return EINVAL;
1569 1.28 mycroft
1570 1.28 mycroft if ((error = mcd_getqchan(sc, &q, ch->data_format)) != 0)
1571 1.28 mycroft return error;
1572 1.1 cgd
1573 1.6 mycroft data.header.audio_status = sc->audio_status;
1574 1.28 mycroft data.what.media_catalog.data_format = ch->data_format;
1575 1.28 mycroft
1576 1.28 mycroft switch (ch->data_format) {
1577 1.28 mycroft case CD_MEDIA_CATALOG:
1578 1.28 mycroft data.what.media_catalog.mc_valid = 1;
1579 1.28 mycroft #if 0
1580 1.28 mycroft data.what.media_catalog.mc_number =
1581 1.28 mycroft #endif
1582 1.28 mycroft break;
1583 1.28 mycroft
1584 1.28 mycroft case CD_CURRENT_POSITION:
1585 1.28 mycroft data.what.position.track_number = bcd2bin(q.current.trk_no);
1586 1.28 mycroft data.what.position.index_number = bcd2bin(q.current.idx_no);
1587 1.28 mycroft switch (ch->address_format) {
1588 1.28 mycroft case CD_MSF_FORMAT:
1589 1.54 thorpej data.what.position.reladdr.addr[0] = 0;
1590 1.54 thorpej data.what.position.reladdr.addr[1] = bcd2bin(q.current.relative_pos[0]);
1591 1.54 thorpej data.what.position.reladdr.addr[2] = bcd2bin(q.current.relative_pos[1]);
1592 1.54 thorpej data.what.position.reladdr.addr[3] = bcd2bin(q.current.relative_pos[2]);
1593 1.54 thorpej data.what.position.absaddr.addr[0] = 0;
1594 1.54 thorpej data.what.position.absaddr.addr[1] = bcd2bin(q.current.absolute_pos[0]);
1595 1.54 thorpej data.what.position.absaddr.addr[2] = bcd2bin(q.current.absolute_pos[1]);
1596 1.54 thorpej data.what.position.absaddr.addr[3] = bcd2bin(q.current.absolute_pos[2]);
1597 1.28 mycroft break;
1598 1.28 mycroft case CD_LBA_FORMAT:
1599 1.28 mycroft lba = msf2hsg(q.current.relative_pos, 1);
1600 1.28 mycroft /*
1601 1.28 mycroft * Pre-gap has index number of 0, and decreasing MSF
1602 1.28 mycroft * address. Must be converted to negative LBA, per
1603 1.28 mycroft * SCSI spec.
1604 1.28 mycroft */
1605 1.28 mycroft if (data.what.position.index_number == 0x00)
1606 1.28 mycroft lba = -lba;
1607 1.54 thorpej data.what.position.reladdr.addr[0] = lba >> 24;
1608 1.54 thorpej data.what.position.reladdr.addr[1] = lba >> 16;
1609 1.54 thorpej data.what.position.reladdr.addr[2] = lba >> 8;
1610 1.54 thorpej data.what.position.reladdr.addr[3] = lba;
1611 1.28 mycroft lba = msf2hsg(q.current.absolute_pos, 0);
1612 1.54 thorpej data.what.position.absaddr.addr[0] = lba >> 24;
1613 1.54 thorpej data.what.position.absaddr.addr[1] = lba >> 16;
1614 1.54 thorpej data.what.position.absaddr.addr[2] = lba >> 8;
1615 1.54 thorpej data.what.position.absaddr.addr[3] = lba;
1616 1.28 mycroft break;
1617 1.28 mycroft }
1618 1.28 mycroft break;
1619 1.28 mycroft }
1620 1.28 mycroft
1621 1.28 mycroft return copyout(&data, ch->data, len);
1622 1.28 mycroft }
1623 1.28 mycroft
1624 1.28 mycroft int
1625 1.28 mycroft mcd_playtracks(sc, p)
1626 1.28 mycroft struct mcd_softc *sc;
1627 1.28 mycroft struct ioc_play_track *p;
1628 1.28 mycroft {
1629 1.28 mycroft struct mcd_mbox mbx;
1630 1.28 mycroft int a = p->start_track;
1631 1.28 mycroft int z = p->end_track;
1632 1.28 mycroft int error;
1633 1.1 cgd
1634 1.28 mycroft if (sc->debug)
1635 1.51 christos printf("%s: playtracks: from %d:%d to %d:%d\n",
1636 1.28 mycroft sc->sc_dev.dv_xname,
1637 1.28 mycroft a, p->start_index, z, p->end_index);
1638 1.28 mycroft
1639 1.28 mycroft if (a < bcd2bin(sc->volinfo.trk_low) ||
1640 1.28 mycroft a > bcd2bin(sc->volinfo.trk_high) ||
1641 1.28 mycroft a > z ||
1642 1.28 mycroft z < bcd2bin(sc->volinfo.trk_low) ||
1643 1.28 mycroft z > bcd2bin(sc->volinfo.trk_high))
1644 1.28 mycroft return EINVAL;
1645 1.28 mycroft
1646 1.28 mycroft if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
1647 1.28 mycroft return error;
1648 1.28 mycroft
1649 1.41 cgd mbx.cmd.opcode = MCD_CMDREADSINGLESPEED;
1650 1.28 mycroft mbx.cmd.length = sizeof(mbx.cmd.data.play);
1651 1.28 mycroft mbx.cmd.data.play.start_msf[0] = sc->toc[a].toc.absolute_pos[0];
1652 1.28 mycroft mbx.cmd.data.play.start_msf[1] = sc->toc[a].toc.absolute_pos[1];
1653 1.28 mycroft mbx.cmd.data.play.start_msf[2] = sc->toc[a].toc.absolute_pos[2];
1654 1.28 mycroft mbx.cmd.data.play.end_msf[0] = sc->toc[z+1].toc.absolute_pos[0];
1655 1.28 mycroft mbx.cmd.data.play.end_msf[1] = sc->toc[z+1].toc.absolute_pos[1];
1656 1.28 mycroft mbx.cmd.data.play.end_msf[2] = sc->toc[z+1].toc.absolute_pos[2];
1657 1.28 mycroft sc->lastpb = mbx.cmd;
1658 1.28 mycroft mbx.res.length = 0;
1659 1.28 mycroft return mcd_send(sc, &mbx, 1);
1660 1.1 cgd }
1661 1.1 cgd
1662 1.6 mycroft int
1663 1.28 mycroft mcd_playmsf(sc, p)
1664 1.6 mycroft struct mcd_softc *sc;
1665 1.28 mycroft struct ioc_play_msf *p;
1666 1.1 cgd {
1667 1.28 mycroft struct mcd_mbox mbx;
1668 1.28 mycroft int error;
1669 1.1 cgd
1670 1.28 mycroft if (sc->debug)
1671 1.51 christos printf("%s: playmsf: from %d:%d.%d to %d:%d.%d\n",
1672 1.28 mycroft sc->sc_dev.dv_xname,
1673 1.28 mycroft p->start_m, p->start_s, p->start_f,
1674 1.28 mycroft p->end_m, p->end_s, p->end_f);
1675 1.1 cgd
1676 1.28 mycroft if ((p->start_m * 60 * 75 + p->start_s * 75 + p->start_f) >=
1677 1.28 mycroft (p->end_m * 60 * 75 + p->end_s * 75 + p->end_f))
1678 1.1 cgd return EINVAL;
1679 1.1 cgd
1680 1.28 mycroft if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
1681 1.28 mycroft return error;
1682 1.6 mycroft
1683 1.41 cgd mbx.cmd.opcode = MCD_CMDREADSINGLESPEED;
1684 1.28 mycroft mbx.cmd.length = sizeof(mbx.cmd.data.play);
1685 1.28 mycroft mbx.cmd.data.play.start_msf[0] = bin2bcd(p->start_m);
1686 1.28 mycroft mbx.cmd.data.play.start_msf[1] = bin2bcd(p->start_s);
1687 1.28 mycroft mbx.cmd.data.play.start_msf[2] = bin2bcd(p->start_f);
1688 1.28 mycroft mbx.cmd.data.play.end_msf[0] = bin2bcd(p->end_m);
1689 1.28 mycroft mbx.cmd.data.play.end_msf[1] = bin2bcd(p->end_s);
1690 1.28 mycroft mbx.cmd.data.play.end_msf[2] = bin2bcd(p->end_f);
1691 1.28 mycroft sc->lastpb = mbx.cmd;
1692 1.28 mycroft mbx.res.length = 0;
1693 1.28 mycroft return mcd_send(sc, &mbx, 1);
1694 1.6 mycroft }
1695 1.6 mycroft
1696 1.6 mycroft int
1697 1.28 mycroft mcd_playblocks(sc, p)
1698 1.6 mycroft struct mcd_softc *sc;
1699 1.28 mycroft struct ioc_play_blocks *p;
1700 1.1 cgd {
1701 1.28 mycroft struct mcd_mbox mbx;
1702 1.28 mycroft int error;
1703 1.1 cgd
1704 1.6 mycroft if (sc->debug)
1705 1.51 christos printf("%s: playblocks: blkno %d length %d\n",
1706 1.28 mycroft sc->sc_dev.dv_xname, p->blk, p->len);
1707 1.28 mycroft
1708 1.28 mycroft if (p->blk > sc->disksize || p->len > sc->disksize ||
1709 1.28 mycroft (p->blk + p->len) > sc->disksize)
1710 1.28 mycroft return 0;
1711 1.28 mycroft
1712 1.28 mycroft if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
1713 1.28 mycroft return error;
1714 1.6 mycroft
1715 1.41 cgd mbx.cmd.opcode = MCD_CMDREADSINGLESPEED;
1716 1.28 mycroft mbx.cmd.length = sizeof(mbx.cmd.data.play);
1717 1.28 mycroft hsg2msf(p->blk, mbx.cmd.data.play.start_msf);
1718 1.28 mycroft hsg2msf(p->blk + p->len, mbx.cmd.data.play.end_msf);
1719 1.28 mycroft sc->lastpb = mbx.cmd;
1720 1.28 mycroft mbx.res.length = 0;
1721 1.28 mycroft return mcd_send(sc, &mbx, 1);
1722 1.1 cgd }
1723 1.1 cgd
1724 1.6 mycroft int
1725 1.6 mycroft mcd_pause(sc)
1726 1.6 mycroft struct mcd_softc *sc;
1727 1.1 cgd {
1728 1.28 mycroft union mcd_qchninfo q;
1729 1.28 mycroft int error;
1730 1.1 cgd
1731 1.6 mycroft /* Verify current status. */
1732 1.6 mycroft if (sc->audio_status != CD_AS_PLAY_IN_PROGRESS) {
1733 1.51 christos printf("%s: pause: attempted when not playing\n",
1734 1.6 mycroft sc->sc_dev.dv_xname);
1735 1.1 cgd return EINVAL;
1736 1.1 cgd }
1737 1.1 cgd
1738 1.6 mycroft /* Get the current position. */
1739 1.28 mycroft if ((error = mcd_getqchan(sc, &q, CD_CURRENT_POSITION)) != 0)
1740 1.28 mycroft return error;
1741 1.1 cgd
1742 1.6 mycroft /* Copy it into lastpb. */
1743 1.28 mycroft sc->lastpb.data.seek.start_msf[0] = q.current.absolute_pos[0];
1744 1.28 mycroft sc->lastpb.data.seek.start_msf[1] = q.current.absolute_pos[1];
1745 1.28 mycroft sc->lastpb.data.seek.start_msf[2] = q.current.absolute_pos[2];
1746 1.1 cgd
1747 1.6 mycroft /* Stop playing. */
1748 1.28 mycroft if ((error = mcd_stop(sc)) != 0)
1749 1.28 mycroft return error;
1750 1.1 cgd
1751 1.6 mycroft /* Set the proper status and exit. */
1752 1.6 mycroft sc->audio_status = CD_AS_PLAY_PAUSED;
1753 1.1 cgd return 0;
1754 1.1 cgd }
1755 1.1 cgd
1756 1.6 mycroft int
1757 1.6 mycroft mcd_resume(sc)
1758 1.6 mycroft struct mcd_softc *sc;
1759 1.1 cgd {
1760 1.28 mycroft struct mcd_mbox mbx;
1761 1.28 mycroft int error;
1762 1.1 cgd
1763 1.6 mycroft if (sc->audio_status != CD_AS_PLAY_PAUSED)
1764 1.6 mycroft return EINVAL;
1765 1.28 mycroft
1766 1.28 mycroft if ((error = mcd_setmode(sc, MCD_MD_COOKED)) != 0)
1767 1.28 mycroft return error;
1768 1.28 mycroft
1769 1.28 mycroft mbx.cmd = sc->lastpb;
1770 1.28 mycroft mbx.res.length = 0;
1771 1.28 mycroft return mcd_send(sc, &mbx, 1);
1772 1.28 mycroft }
1773 1.28 mycroft
1774 1.28 mycroft int
1775 1.28 mycroft mcd_eject(sc)
1776 1.28 mycroft struct mcd_softc *sc;
1777 1.28 mycroft {
1778 1.28 mycroft struct mcd_mbox mbx;
1779 1.28 mycroft
1780 1.28 mycroft mbx.cmd.opcode = MCD_CMDEJECTDISK;
1781 1.28 mycroft mbx.cmd.length = 0;
1782 1.28 mycroft mbx.res.length = 0;
1783 1.28 mycroft return mcd_send(sc, &mbx, 0);
1784 1.28 mycroft }
1785 1.28 mycroft
1786 1.28 mycroft int
1787 1.28 mycroft mcd_setlock(sc, mode)
1788 1.28 mycroft struct mcd_softc *sc;
1789 1.28 mycroft int mode;
1790 1.28 mycroft {
1791 1.28 mycroft struct mcd_mbox mbx;
1792 1.28 mycroft
1793 1.28 mycroft mbx.cmd.opcode = MCD_CMDSETLOCK;
1794 1.28 mycroft mbx.cmd.length = sizeof(mbx.cmd.data.lockmode);
1795 1.28 mycroft mbx.cmd.data.lockmode.mode = mode;
1796 1.28 mycroft mbx.res.length = 0;
1797 1.28 mycroft return mcd_send(sc, &mbx, 1);
1798 1.1 cgd }
1799