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