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