This source file includes following definitions.
- cdrom_in_bytes
- cdrom_out_bytes
- cdrom_analyze_sense_data
- restore_request
- cdrom_queue_request_sense
- cdrom_end_request
- cdrom_saw_media_change
- cdrom_decode_status
- cdrom_start_packet_command
- cdrom_transfer_packet_command
- cdrom_buffer_sectors
- cdrom_read_check_ireason
- cdrom_read_intr
- cdrom_read_from_buffer
- cdrom_start_read_continuation
- cdrom_start_read
- cdrom_pc_intr
- cdrom_do_pc_continuation
- cdrom_do_packet_command
- cdrom_sleep
- cdrom_queue_request
- cdrom_queue_packet_command
- ide_do_rw_cdrom
- byte_swap_word
- byte_swap_long
- bin2bcd
- lba_to_msf
- msf_to_lba
- cdrom_check_status
- cdrom_lockdoor
- cdrom_eject
- cdrom_pause
- cdrom_startstop
- cdrom_read_capacity
- cdrom_read_tocentry
- cdrom_read_toc
- cdrom_read_subchannel
- cdrom_mode_sense
- cdrom_mode_select
- cdrom_play_lba_range_play12
- cdrom_play_lba_range_msf
- cdrom_play_lba_range
- cdrom_get_toc_entry
- cdrom_read_block
- ide_cdrom_ioctl
- ide_cdrom_check_media_change
- ide_cdrom_open
- ide_cdrom_release
- ide_cdrom_setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 #include <linux/config.h>
85 #include <linux/types.h>
86 #include <linux/kernel.h>
87 #include <linux/delay.h>
88 #include <linux/timer.h>
89 #include <linux/malloc.h>
90 #include <linux/ioport.h>
91 #include <linux/interrupt.h>
92 #include <linux/blkdev.h>
93 #include <linux/errno.h>
94 #include <linux/hdreg.h>
95 #include <linux/cdrom.h>
96 #include <asm/irq.h>
97 #include <asm/io.h>
98
99 #define _IDE_CD_C
100 #include "ide.h"
101
102
103
104
105
106 #ifndef VERBOSE_IDE_CD_ERRORS
107 #define VERBOSE_IDE_CD_ERRORS 0
108 #endif
109
110 #define SECTOR_SIZE 512
111 #define SECTOR_BITS 9
112 #define SECTORS_PER_FRAME (CD_FRAMESIZE / SECTOR_SIZE)
113
114 #define MIN(a,b) ((a) < (b) ? (a) : (b))
115
116
117 #define PACKET_COMMAND 4315
118 #define REQUEST_SENSE_COMMAND 4316
119 #define RESET_DRIVE_COMMAND 4317
120
121
122
123 #define TEST_UNIT_READY 0x00
124 #define REQUEST_SENSE 0x03
125 #define START_STOP 0x1b
126 #define ALLOW_MEDIUM_REMOVAL 0x1e
127 #define READ_CAPACITY 0x25
128 #define READ_10 0x28
129 #define MODE_SENSE_10 0x5a
130 #define MODE_SELECT_10 0x55
131 #define READ_CD 0xbe
132
133
134
135
136 #define NO_SENSE 0x00
137 #define RECOVERED_ERROR 0x01
138 #define NOT_READY 0x02
139 #define MEDIUM_ERROR 0x03
140 #define HARDWARE_ERROR 0x04
141 #define ILLEGAL_REQUEST 0x05
142 #define UNIT_ATTENTION 0x06
143 #define DATA_PROTECT 0x07
144 #define ABORTED_COMMAND 0x0b
145 #define MISCOMPARE 0x0e
146
147
148
149
150
151
152
153
154 struct ide_cd_config_flags {
155 unsigned drq_interrupt : 1;
156
157 unsigned no_playaudio12: 1;
158
159 unsigned no_lba_toc : 1;
160 unsigned msf_as_bcd : 1;
161 unsigned no_doorlock : 1;
162 unsigned old_readcd : 1;
163 unsigned reserved : 2;
164 };
165 #define CDROM_CONFIG_FLAGS(drive) ((struct ide_cd_config_flags *)&((drive)->bios_sect))
166
167
168
169
170 struct ide_cd_state_flags {
171 unsigned media_changed : 1;
172 unsigned toc_valid : 1;
173 unsigned door_locked : 1;
174 unsigned eject_on_close: 1;
175 unsigned reserved : 4;
176 };
177 #define CDROM_STATE_FLAGS(drive) ((struct ide_cd_state_flags *)&((drive)->bios_head))
178
179
180 #define SECTOR_BUFFER_SIZE CD_FRAMESIZE
181
182
183
184
185
186
187
188
189
190
191
192 static inline
193 void cdrom_in_bytes (ide_drive_t *drive, void *buffer, uint bytecount)
194 {
195 ide_input_data (drive, buffer, bytecount / 4);
196 if ((bytecount & 0x03 >= 2))
197 {
198 insw (IDE_DATA_REG, buffer + (bytecount & ~0x03), 1);
199 }
200 }
201
202
203 static inline
204 void cdrom_out_bytes (ide_drive_t *drive, void *buffer, uint bytecount)
205 {
206 ide_output_data (drive, buffer, bytecount / 4);
207 if ((bytecount & 0x03 >= 2))
208 {
209 outsw (IDE_DATA_REG, buffer + (bytecount & ~0x03), 1);
210 }
211 }
212
213
214
215
216
217
218
219 #define ARY_LEN(a) ((sizeof(a) / sizeof(a[0])))
220
221 #if VERBOSE_IDE_CD_ERRORS
222
223
224
225 char *sense_key_texts[16] = {
226 "No sense data",
227 "Recovered error",
228 "Not ready",
229 "Medium error",
230 "Hardware error",
231 "Illegal request",
232 "Unit attention",
233 "Data protect",
234 "(reserved)",
235 "(reserved)",
236 "(reserved)",
237 "Aborted command",
238 "(reserved)",
239 "(reserved)",
240 "Miscompare",
241 "(reserved)",
242 };
243
244
245
246
247 struct {
248 short asc_ascq;
249 char *text;
250 } sense_data_texts[] = {
251 { 0x0000, "No additional sense information" },
252 { 0x0011, "Audio play operation in progress" },
253 { 0x0012, "Audio play operation paused" },
254 { 0x0013, "Audio play operation successfully completed" },
255 { 0x0014, "Audio play operation stopped due to error" },
256 { 0x0015, "No current audio status to return" },
257
258 { 0x0200, "No seek complete" },
259
260 { 0x0400, "Logical unit not ready - cause not reportable" },
261 { 0x0401, "Logical unit not ready - in progress (sic) of becoming ready" },
262 { 0x0402, "Logical unit not ready - initializing command required" },
263 { 0x0403, "Logical unit not ready - manual intervention required" },
264
265 { 0x0600, "No reference position found" },
266
267 { 0x0900, "Track following error" },
268 { 0x0901, "Tracking servo failure" },
269 { 0x0902, "Focus servo failure" },
270 { 0x0903, "Spindle servo failure" },
271
272 { 0x1100, "Unrecovered read error" },
273 { 0x1106, "CIRC unrecovered error" },
274
275 { 0x1500, "Random positioning error" },
276 { 0x1501, "Mechanical positioning error" },
277 { 0x1502, "Positioning error detected by read of medium" },
278
279 { 0x1700, "Recovered data with no error correction applied" },
280 { 0x1701, "Recovered data with retries" },
281 { 0x1702, "Recovered data with positive head offset" },
282 { 0x1703, "Recovered data with negative head offset" },
283 { 0x1704, "Recovered data with retries and/or CIRC applied" },
284 { 0x1705, "Recovered data using previous sector ID" },
285
286 { 0x1800, "Recovered data with error correction applied" },
287 { 0x1801, "Recovered data with error correction and retries applied" },
288 { 0x1802, "Recovered data - the data was auto-reallocated" },
289 { 0x1803, "Recovered data with CIRC" },
290 { 0x1804, "Recovered data with L-EC" },
291 { 0x1805, "Recovered data - recommend reassignment" },
292 { 0x1806, "Recovered data - recommend rewrite" },
293
294 { 0x1a00, "Parameter list length error" },
295
296 { 0x2000, "Invalid command operation code" },
297
298 { 0x2100, "Logical block address out of range" },
299
300 { 0x2400, "Invalid field in command packet" },
301
302 { 0x2600, "Invalid field in parameter list" },
303 { 0x2601, "Parameter not supported" },
304 { 0x2602, "Parameter value invalid" },
305 { 0x2603, "Threshold parameters not supported" },
306
307 { 0x2800, "Not ready to ready transition, medium may have changed" },
308
309 { 0x2900, "Power on, reset or bus device reset occurred" },
310
311 { 0x2a00, "Parameters changed" },
312 { 0x2a01, "Mode parameters changed" },
313
314 { 0x3000, "Incompatible medium installed" },
315 { 0x3001, "Cannot read medium - unknown format" },
316 { 0x3002, "Cannot read medium - incompatible format" },
317
318 { 0x3700, "Rounded parameter" },
319
320 { 0x3900, "Saving parameters not supported" },
321
322 { 0x3a00, "Medium not present" },
323
324 { 0x3f00, "ATAPI CD-ROM drive operating conditions have changed" },
325 { 0x3f01, "Microcode has been changed" },
326 { 0x3f02, "Changed operating definition" },
327 { 0x3f03, "Inquiry data has changed" },
328
329 { 0x4000, "Diagnostic failure on component (ASCQ)" },
330
331 { 0x4400, "Internal ATAPI CD-ROM drive failure" },
332
333 { 0x4e00, "Overlapped commands attempted" },
334
335 { 0x5300, "Media load or eject failed" },
336 { 0x5302, "Medium removal prevented" },
337
338 { 0x5700, "Unable to recover table of contents" },
339
340 { 0x5a00, "Operator request or state change input (unspecified)" },
341 { 0x5a01, "Operator medium removal request" },
342
343 { 0x5b00, "Threshold condition met" },
344
345 { 0x5c00, "Status change" },
346
347 { 0x6300, "End of user area encountered on this track" },
348
349 { 0x6400, "Illegal mode for this track" },
350
351 { 0xbf00, "Loss of streaming" },
352 };
353 #endif
354
355
356
357
358
359
360
361
362 static
363 void cdrom_analyze_sense_data (ide_drive_t *drive,
364 struct atapi_request_sense *reqbuf,
365 struct packet_command *failed_command)
366 {
367
368
369
370 if (failed_command &&
371 failed_command->c[0] == SCMD_READ_SUBCHANNEL &&
372 (reqbuf->sense_key == NOT_READY || reqbuf->sense_key == UNIT_ATTENTION))
373 return;
374
375 #if VERBOSE_IDE_CD_ERRORS
376 {
377 int i;
378 char *s;
379 char buf[80];
380
381 printk ("ATAPI device %s:\n", drive->name);
382
383 printk (" Error code: %x\n", reqbuf->error_code);
384
385 if (reqbuf->sense_key >= 0 &&
386 reqbuf->sense_key < ARY_LEN (sense_key_texts))
387 s = sense_key_texts[reqbuf->sense_key];
388 else
389 s = "(bad sense key)";
390
391 printk (" Sense key: %x - %s\n", reqbuf->sense_key, s);
392
393 if (reqbuf->asc == 0x40) {
394 sprintf (buf, "Diagnostic failure on component %x", reqbuf->ascq);
395 s = buf;
396 }
397
398 else {
399 int lo, hi;
400 int key = (reqbuf->asc << 8);
401 if ( ! (reqbuf->ascq >= 0x80 && reqbuf->ascq <= 0xdd) )
402 key |= reqbuf->ascq;
403
404 lo = 0;
405 hi = ARY_LEN (sense_data_texts);
406 s = NULL;
407
408 while (hi > lo) {
409 int mid = (lo + hi) / 2;
410 if (sense_data_texts[mid].asc_ascq == key) {
411 s = sense_data_texts[mid].text;
412 break;
413 }
414 else if (sense_data_texts[mid].asc_ascq > key)
415 hi = mid;
416 else
417 lo = mid+1;
418 }
419 }
420
421 if (s == NULL) {
422 if (reqbuf->asc > 0x80)
423 s = "(vendor-specific error)";
424 else
425 s = "(reserved error code)";
426 }
427
428 printk (" Additional sense data: %x, %x - %s\n",
429 reqbuf->asc, reqbuf->ascq, s);
430
431 if (failed_command != NULL) {
432 printk (" Failed packet command: ");
433 for (i=0; i<sizeof (failed_command->c); i++)
434 printk ("%02x ", failed_command->c[i]);
435 printk ("\n");
436 }
437 }
438
439 #else
440
441
442
443
444 if (reqbuf->sense_key == UNIT_ATTENTION ||
445 (reqbuf->sense_key == NOT_READY && (reqbuf->asc == 4 ||
446 reqbuf->asc == 0x3a)))
447 return;
448
449 printk ("%s: code: %x key: %x asc: %x ascq: %x\n",
450 drive->name,
451 reqbuf->error_code, reqbuf->sense_key, reqbuf->asc, reqbuf->ascq);
452 #endif
453 }
454
455
456
457
458 static void restore_request (struct request *rq)
459 {
460 if (rq->buffer != rq->bh->b_data)
461 {
462 int n = (rq->buffer - rq->bh->b_data) / SECTOR_SIZE;
463 rq->buffer = rq->bh->b_data;
464 rq->nr_sectors += n;
465 rq->sector -= n;
466 }
467 rq->current_nr_sectors = rq->bh->b_size >> SECTOR_BITS;
468 }
469
470
471 static void cdrom_queue_request_sense (ide_drive_t *drive,
472 struct semaphore *sem,
473 struct atapi_request_sense *reqbuf)
474 {
475 struct request *rq;
476 struct packet_command *pc;
477 unsigned long flags;
478 int len;
479
480 int major = HWIF(drive)->major;
481
482 save_flags (flags);
483 cli ();
484
485 rq = HWGROUP(drive)->rq;
486
487
488 if (rq != NULL)
489 {
490 restore_request (rq);
491 rq->next = blk_dev[major].current_request;
492 blk_dev[major].current_request = rq;
493 HWGROUP(drive)->rq = NULL;
494 }
495
496 restore_flags (flags);
497
498
499
500 if (reqbuf == NULL)
501 reqbuf = &drive->cdrom_info.sense_data;
502
503
504
505 pc = &HWIF(drive)->request_sense_pc;
506 memset (pc, 0, sizeof (*pc));
507
508
509
510
511
512 len = sizeof (*reqbuf) / 4;
513 len *= 4;
514
515 pc->c[0] = REQUEST_SENSE;
516 pc->c[4] = len;
517 pc->buffer = (char *)reqbuf;
518 pc->buflen = len;
519 pc->sense_data = reqbuf;
520
521
522
523 rq = &HWIF(drive)->request_sense_request;
524 rq->dev = MKDEV (major, (drive->select.b.unit) << PARTN_BITS);
525 rq->cmd = REQUEST_SENSE_COMMAND;
526 rq->errors = 0;
527 rq->sector = 0;
528 rq->nr_sectors = 0;
529 rq->current_nr_sectors = 0;
530 rq->buffer = (char *)pc;
531 rq->sem = sem;
532 rq->bh = NULL;
533 rq->bhtail = NULL;
534 rq->next = NULL;
535
536 save_flags (flags);
537 cli ();
538
539
540 rq->next = blk_dev[major].current_request;
541 blk_dev[major].current_request = rq;
542
543 restore_flags (flags);
544 }
545
546
547 static void cdrom_end_request (int uptodate, ide_drive_t *drive)
548 {
549 struct request *rq = HWGROUP(drive)->rq;
550
551
552
553 if (!uptodate && rq->bh != 0)
554 {
555 int adj = rq->current_nr_sectors - 1;
556 rq->current_nr_sectors -= adj;
557 rq->sector += adj;
558 }
559
560 if (rq->cmd == REQUEST_SENSE_COMMAND && uptodate)
561 {
562 struct packet_command *pc = (struct packet_command *)rq->buffer;
563 cdrom_analyze_sense_data (drive, pc->sense_data, NULL);
564 }
565
566 ide_end_request (uptodate, HWGROUP(drive));
567 }
568
569
570
571
572 static void cdrom_saw_media_change (ide_drive_t *drive)
573 {
574 CDROM_STATE_FLAGS (drive)->media_changed = 1;
575 CDROM_STATE_FLAGS (drive)->toc_valid = 0;
576 drive->cdrom_info.nsectors_buffered = 0;
577 }
578
579
580
581
582 static int cdrom_decode_status (ide_drive_t *drive, int good_stat, int *stat_ret)
583 {
584 struct request *rq = HWGROUP(drive)->rq;
585 int stat, err, sense_key, cmd;
586
587
588 stat = GET_STAT();
589 *stat_ret = stat;
590
591 if (OK_STAT (stat, good_stat, BAD_R_STAT))
592 return 0;
593
594
595 err = IN_BYTE (IDE_ERROR_REG);
596 sense_key = err >> 4;
597
598 if (rq == NULL)
599 printk ("%s : missing request in cdrom_decode_status\n", drive->name);
600 else
601 {
602 cmd = rq->cmd;
603
604 if (cmd == REQUEST_SENSE_COMMAND)
605 {
606
607
608
609
610 struct packet_command *pc = (struct packet_command *)rq->buffer;
611 pc->stat = 1;
612 cdrom_end_request (1, drive);
613 if (ide_error (drive, "request sense failure", stat))
614 return 1;
615 }
616
617 else if (cmd == PACKET_COMMAND)
618 {
619
620
621 struct packet_command *pc = (struct packet_command *)rq->buffer;
622 struct semaphore *sem = NULL;
623
624
625 if (sense_key == NOT_READY)
626 {
627 cdrom_saw_media_change (drive);
628
629
630
631
632
633
634 if (pc->c[0] != SCMD_READ_SUBCHANNEL)
635 printk ("%s : tray open or drive not ready\n", drive->name);
636 }
637
638
639 else if (sense_key == UNIT_ATTENTION)
640 {
641 cdrom_saw_media_change (drive);
642 printk ("%s: media changed\n", drive->name);
643 }
644
645
646 else
647 {
648 ide_dump_status (drive, "packet command error", stat);
649 }
650
651
652
653
654
655
656
657
658
659 if ((stat & ERR_STAT) != 0)
660 {
661 sem = rq->sem;
662 rq->sem = NULL;
663 }
664
665 pc->stat = 1;
666 cdrom_end_request (1, drive);
667
668 if ((stat & ERR_STAT) != 0)
669 cdrom_queue_request_sense (drive, sem, pc->sense_data);
670 }
671
672 else
673 {
674
675
676
677 if (sense_key == NOT_READY)
678 {
679 cdrom_saw_media_change (drive);
680
681
682 printk ("%s : tray open\n", drive->name);
683 cdrom_end_request (0, drive);
684 }
685
686
687 else if (sense_key == UNIT_ATTENTION)
688 {
689 cdrom_saw_media_change (drive);
690
691
692
693 if (++rq->errors > ERROR_MAX)
694 {
695 cdrom_end_request (0, drive);
696 }
697 }
698
699
700 else if (sense_key == ILLEGAL_REQUEST || sense_key == DATA_PROTECT)
701 {
702 ide_dump_status (drive, "command error", stat);
703 cdrom_end_request (0, drive);
704 }
705
706
707 else if ((err & ~ABRT_ERR) != 0)
708 {
709 if (ide_error (drive, "cdrom_decode_status", stat))
710 return 1;
711 }
712
713
714 else if ((++rq->errors > ERROR_MAX))
715 {
716 cdrom_end_request (0, drive);
717 }
718
719
720
721 if ((stat & ERR_STAT) != 0)
722 cdrom_queue_request_sense (drive, NULL, NULL);
723 }
724 }
725
726
727 IDE_DO_REQUEST;
728 return 1;
729 }
730
731
732
733
734
735
736
737
738
739 static int cdrom_start_packet_command (ide_drive_t *drive, int xferlen,
740 ide_handler_t *handler)
741 {
742
743 if (ide_wait_stat (drive, 0, BUSY_STAT, WAIT_READY)) return 1;
744
745
746 OUT_BYTE (0, IDE_FEATURE_REG);
747 OUT_BYTE (0, IDE_NSECTOR_REG);
748 OUT_BYTE (0, IDE_SECTOR_REG);
749
750 OUT_BYTE (xferlen & 0xff, IDE_LCYL_REG);
751 OUT_BYTE (xferlen >> 8 , IDE_HCYL_REG);
752 OUT_BYTE (drive->ctl, IDE_CONTROL_REG);
753
754 if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt)
755 {
756 ide_set_handler (drive, handler);
757 OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG);
758 }
759 else
760 {
761 OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG);
762 (*handler) (drive);
763 }
764
765 return 0;
766 }
767
768
769
770
771
772 static int cdrom_transfer_packet_command (ide_drive_t *drive,
773 char *cmd_buf, int cmd_len)
774 {
775 if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt)
776 {
777
778
779 int stat_dum;
780
781
782 if (cdrom_decode_status (drive, DRQ_STAT, &stat_dum)) return 1;
783 }
784 else
785 {
786
787 if (ide_wait_stat (drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) return 1;
788 }
789
790
791 cdrom_out_bytes (drive, cmd_buf, cmd_len);
792
793 return 0;
794 }
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809 static void cdrom_buffer_sectors (ide_drive_t *drive, unsigned long sector,
810 int sectors_to_transfer)
811 {
812 struct cdrom_info *info = &drive->cdrom_info;
813
814
815 int sectors_to_buffer = MIN (sectors_to_transfer,
816 (SECTOR_BUFFER_SIZE >> SECTOR_BITS) -
817 info->nsectors_buffered);
818
819 char *dest;
820
821
822
823
824 if (info->sector_buffer == NULL)
825 {
826 info->sector_buffer = (char *) kmalloc (SECTOR_BUFFER_SIZE, GFP_ATOMIC);
827
828
829 if (info->sector_buffer == NULL)
830 sectors_to_buffer = 0;
831 }
832
833
834 if (info->nsectors_buffered == 0)
835 info->sector_buffered = sector;
836
837
838 dest = info->sector_buffer + info->nsectors_buffered * SECTOR_SIZE;
839 while (sectors_to_buffer > 0)
840 {
841 cdrom_in_bytes (drive, dest, SECTOR_SIZE);
842 --sectors_to_buffer;
843 --sectors_to_transfer;
844 ++info->nsectors_buffered;
845 dest += SECTOR_SIZE;
846 }
847
848
849 while (sectors_to_transfer > 0)
850 {
851 char dum[SECTOR_SIZE];
852 cdrom_in_bytes (drive, dum, sizeof (dum));
853 --sectors_to_transfer;
854 }
855 }
856
857
858
859
860
861
862
863 static inline
864 int cdrom_read_check_ireason (ide_drive_t *drive, int len, int ireason)
865 {
866 ireason &= 3;
867 if (ireason == 2) return 0;
868
869 if (ireason == 0)
870 {
871
872 printk ("%s: cdrom_read_intr: "
873 "Drive wants to transfer data the wrong way!\n",
874 drive->name);
875
876
877
878 while (len > 0)
879 {
880 int dum = 0;
881 cdrom_out_bytes (drive, &dum, sizeof (dum));
882 len -= sizeof (dum);
883 }
884 }
885
886 else
887 {
888
889 printk ("%s: cdrom_read_intr: bad interrupt reason %d\n",
890 drive->name, ireason);
891 }
892
893 cdrom_end_request (0, drive);
894 IDE_DO_REQUEST;
895 return -1;
896 }
897
898
899
900
901
902 static void cdrom_read_intr (ide_drive_t *drive)
903 {
904 int stat;
905 int ireason, len, sectors_to_transfer, nskip;
906
907 struct request *rq = HWGROUP(drive)->rq;
908
909
910 if (cdrom_decode_status (drive, 0, &stat)) return;
911
912
913 ireason = IN_BYTE (IDE_NSECTOR_REG);
914 len = IN_BYTE (IDE_LCYL_REG) + 256 * IN_BYTE (IDE_HCYL_REG);
915
916
917 if ((stat & DRQ_STAT) == 0)
918 {
919
920
921 if (rq->current_nr_sectors > 0)
922 {
923 printk ("%s: cdrom_read_intr: data underrun (%ld blocks)\n",
924 drive->name, rq->current_nr_sectors);
925 cdrom_end_request (0, drive);
926 }
927 else
928 cdrom_end_request (1, drive);
929
930 IDE_DO_REQUEST;
931 return;
932 }
933
934
935 if (cdrom_read_check_ireason (drive, len, ireason)) return;
936
937
938
939 if ((len % SECTOR_SIZE) != 0)
940 {
941 printk ("%s: cdrom_read_intr: Bad transfer size %d\n",
942 drive->name, len);
943 printk (" This drive is not supported by this version of the driver\n");
944 cdrom_end_request (0, drive);
945 IDE_DO_REQUEST;
946 return;
947 }
948
949
950 sectors_to_transfer = len / SECTOR_SIZE;
951
952
953 nskip = MIN ((int)(rq->current_nr_sectors - (rq->bh->b_size >> SECTOR_BITS)),
954 sectors_to_transfer);
955
956 while (nskip > 0)
957 {
958
959 char dum[SECTOR_SIZE];
960 cdrom_in_bytes (drive, dum, sizeof (dum));
961
962 --rq->current_nr_sectors;
963 --nskip;
964 --sectors_to_transfer;
965 }
966
967
968 while (sectors_to_transfer > 0)
969 {
970 int this_transfer;
971
972
973
974 if (rq->current_nr_sectors == 0 &&
975 rq->nr_sectors > 0)
976 cdrom_end_request (1, drive);
977
978
979
980 if (rq->current_nr_sectors == 0)
981 {
982 cdrom_buffer_sectors (drive, rq->sector, sectors_to_transfer);
983 sectors_to_transfer = 0;
984 }
985 else
986 {
987
988
989
990 this_transfer = MIN (sectors_to_transfer,
991 rq->current_nr_sectors);
992
993
994 while (this_transfer > 0)
995 {
996 cdrom_in_bytes (drive, rq->buffer, SECTOR_SIZE);
997 rq->buffer += SECTOR_SIZE;
998 --rq->nr_sectors;
999 --rq->current_nr_sectors;
1000 ++rq->sector;
1001 --this_transfer;
1002 --sectors_to_transfer;
1003 }
1004 }
1005 }
1006
1007
1008
1009 ide_set_handler (drive, &cdrom_read_intr);
1010 }
1011
1012
1013
1014
1015
1016
1017 static int cdrom_read_from_buffer (ide_drive_t *drive)
1018 {
1019 struct cdrom_info *info = &drive->cdrom_info;
1020 struct request *rq = HWGROUP(drive)->rq;
1021
1022
1023 if (info->sector_buffer == NULL) return 0;
1024
1025
1026
1027 while (rq->nr_sectors > 0 &&
1028 rq->sector >= info->sector_buffered &&
1029 rq->sector < info->sector_buffered + info->nsectors_buffered)
1030 {
1031 if (rq->current_nr_sectors == 0)
1032 cdrom_end_request (1, drive);
1033
1034 memcpy (rq->buffer,
1035 info->sector_buffer +
1036 (rq->sector - info->sector_buffered) * SECTOR_SIZE,
1037 SECTOR_SIZE);
1038 rq->buffer += SECTOR_SIZE;
1039 --rq->current_nr_sectors;
1040 --rq->nr_sectors;
1041 ++rq->sector;
1042 }
1043
1044
1045 if (rq->nr_sectors == 0)
1046 {
1047 cdrom_end_request (1, drive);
1048 return -1;
1049 }
1050
1051
1052 if (rq->current_nr_sectors == 0)
1053 cdrom_end_request (1, drive);
1054
1055
1056
1057
1058
1059 if (rq->current_nr_sectors < (rq->bh->b_size >> SECTOR_BITS) &&
1060 (rq->sector % SECTORS_PER_FRAME) != 0)
1061 {
1062 printk ("%s: cdrom_read_from_buffer: buffer botch (%ld)\n",
1063 drive->name, rq->sector);
1064 cdrom_end_request (0, drive);
1065 return -1;
1066 }
1067
1068 return 0;
1069 }
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079 static void cdrom_start_read_continuation (ide_drive_t *drive)
1080 {
1081 struct packet_command pc;
1082 struct request *rq = HWGROUP(drive)->rq;
1083
1084 int nsect, sector, nframes, frame, nskip;
1085
1086
1087 nsect = rq->nr_sectors;
1088
1089
1090 sector = rq->sector;
1091
1092
1093
1094
1095
1096
1097
1098 nskip = (sector % SECTORS_PER_FRAME);
1099 if (nskip > 0)
1100 {
1101
1102 if (rq->current_nr_sectors != (rq->bh->b_size >> SECTOR_BITS))
1103 {
1104 printk ("%s: cdrom_start_read_continuation: buffer botch (%ld)\n",
1105 drive->name, rq->current_nr_sectors);
1106 cdrom_end_request (0, drive);
1107 IDE_DO_REQUEST;
1108 return;
1109 }
1110
1111 sector -= nskip;
1112 nsect += nskip;
1113 rq->current_nr_sectors += nskip;
1114 }
1115
1116
1117
1118 nframes = (nsect + SECTORS_PER_FRAME-1) / SECTORS_PER_FRAME;
1119 frame = sector / SECTORS_PER_FRAME;
1120
1121
1122 nframes = MIN (nframes, 65535);
1123
1124
1125 memset (&pc.c, 0, sizeof (pc.c));
1126 pc.c[0] = READ_10;
1127 pc.c[7] = (nframes >> 8);
1128 pc.c[8] = (nframes & 0xff);
1129
1130
1131 {
1132 union {
1133 struct {unsigned char b0, b1, b2, b3;} b;
1134 struct {unsigned long l0;} l;
1135 } conv;
1136 conv.l.l0 = frame;
1137 pc.c[2] = conv.b.b3;
1138 pc.c[3] = conv.b.b2;
1139 pc.c[4] = conv.b.b1;
1140 pc.c[5] = conv.b.b0;
1141 }
1142
1143
1144 ide_set_handler (drive, &cdrom_read_intr);
1145
1146
1147 (void) cdrom_transfer_packet_command (drive, pc.c, sizeof (pc.c));
1148 }
1149
1150
1151
1152
1153
1154 static void cdrom_start_read (ide_drive_t *drive, unsigned int block)
1155 {
1156 struct request *rq = HWGROUP(drive)->rq;
1157
1158
1159
1160 restore_request (rq);
1161
1162
1163 if (cdrom_read_from_buffer (drive))
1164 return;
1165
1166
1167 drive->cdrom_info.nsectors_buffered = 0;
1168
1169
1170 cdrom_start_packet_command (drive, 32768, cdrom_start_read_continuation);
1171 }
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181 static int
1182 cdrom_lockdoor (ide_drive_t *drive, int lockflag,
1183 struct atapi_request_sense *reqbuf);
1184
1185
1186
1187
1188 static void cdrom_pc_intr (ide_drive_t *drive)
1189 {
1190 int ireason, len, stat, thislen;
1191 struct request *rq = HWGROUP(drive)->rq;
1192 struct packet_command *pc = (struct packet_command *)rq->buffer;
1193
1194
1195 if (cdrom_decode_status (drive, 0, &stat)) return;
1196
1197
1198 ireason = IN_BYTE (IDE_NSECTOR_REG);
1199 len = IN_BYTE (IDE_LCYL_REG) + 256 * IN_BYTE (IDE_HCYL_REG);
1200
1201
1202
1203 if ((stat & DRQ_STAT) == 0)
1204 {
1205
1206
1207 if (pc->c[0] == REQUEST_SENSE && pc->buflen > 0 && pc->buflen <= 5) {
1208 while (pc->buflen > 0) {
1209 *pc->buffer++ = 0;
1210 --pc->buflen;
1211 }
1212 }
1213
1214 if (pc->buflen == 0)
1215 cdrom_end_request (1, drive);
1216 else
1217 {
1218 printk ("%s: cdrom_pc_intr: data underrun %d\n",
1219 drive->name, pc->buflen);
1220 pc->stat = 1;
1221 cdrom_end_request (1, drive);
1222 }
1223 IDE_DO_REQUEST;
1224 return;
1225 }
1226
1227
1228 thislen = pc->buflen;
1229 if (thislen < 0) thislen = -thislen;
1230 if (thislen > len) thislen = len;
1231
1232
1233 if ((ireason & 3) == 0)
1234 {
1235
1236 if (pc->buflen > 0)
1237 {
1238 printk ("%s: cdrom_pc_intr: Drive wants to transfer data the wrong way!\n",
1239 drive->name);
1240 pc->stat = 1;
1241 thislen = 0;
1242 }
1243
1244
1245 cdrom_out_bytes (drive, pc->buffer, thislen);
1246
1247
1248
1249 while (len > thislen)
1250 {
1251 int dum = 0;
1252 cdrom_out_bytes (drive, &dum, sizeof (dum));
1253 len -= sizeof (dum);
1254 }
1255
1256
1257 pc->buffer += thislen;
1258 pc->buflen += thislen;
1259 }
1260
1261
1262 else if ((ireason & 3) == 2)
1263 {
1264
1265 if (pc->buflen < 0)
1266 {
1267 printk ("%s: cdrom_pc_intr: Drive wants to transfer data the wrong way!\n",
1268 drive->name);
1269 pc->stat = 1;
1270 thislen = 0;
1271 }
1272
1273
1274 cdrom_in_bytes (drive, pc->buffer, thislen);
1275
1276
1277
1278 while (len > thislen)
1279 {
1280 int dum = 0;
1281 cdrom_in_bytes (drive, &dum, sizeof (dum));
1282 len -= sizeof (dum);
1283 }
1284
1285
1286 pc->buffer += thislen;
1287 pc->buflen -= thislen;
1288 }
1289
1290 else
1291 {
1292 printk ("%s: cdrom_pc_intr: The drive appears confused (ireason = 0x%2x)\n",
1293 drive->name, ireason);
1294 pc->stat = 1;
1295 }
1296
1297
1298 ide_set_handler (drive, &cdrom_pc_intr);
1299 }
1300
1301
1302 static void cdrom_do_pc_continuation (ide_drive_t *drive)
1303 {
1304 struct request *rq = HWGROUP(drive)->rq;
1305 struct packet_command *pc = (struct packet_command *)rq->buffer;
1306
1307
1308 ide_set_handler (drive, &cdrom_pc_intr);
1309
1310
1311 cdrom_transfer_packet_command (drive, pc->c, sizeof (pc->c));
1312 }
1313
1314
1315 static void cdrom_do_packet_command (ide_drive_t *drive)
1316 {
1317 int len;
1318 struct request *rq = HWGROUP(drive)->rq;
1319 struct packet_command *pc = (struct packet_command *)rq->buffer;
1320
1321 len = pc->buflen;
1322 if (len < 0) len = -len;
1323
1324 pc->stat = 0;
1325
1326
1327 cdrom_start_packet_command (drive, len, cdrom_do_pc_continuation);
1328 }
1329
1330
1331
1332
1333 static
1334 void cdrom_sleep (int time)
1335 {
1336 current->state = TASK_INTERRUPTIBLE;
1337 current->timeout = jiffies + time;
1338 schedule ();
1339 }
1340
1341
1342 static
1343 void cdrom_queue_request (ide_drive_t *drive, struct request *req)
1344 {
1345 unsigned long flags;
1346 struct request **p, **pfirst;
1347 int major = HWIF(drive)->major;
1348 struct semaphore sem = MUTEX_LOCKED;
1349
1350 req->dev = MKDEV (major, (drive->select.b.unit) << PARTN_BITS);
1351 req->sem = &sem;
1352 req->errors = 0;
1353 req->next = NULL;
1354
1355 save_flags (flags);
1356 cli ();
1357
1358 p = &blk_dev[major].current_request;
1359 pfirst = p;
1360 while ((*p) != NULL)
1361 {
1362 p = &((*p)->next);
1363 }
1364 *p = req;
1365 if (p == pfirst)
1366 blk_dev[major].request_fn ();
1367
1368 down (&sem);
1369
1370 restore_flags (flags);
1371 }
1372
1373
1374 static
1375 int cdrom_queue_packet_command (ide_drive_t *drive, struct packet_command *pc)
1376 {
1377 struct atapi_request_sense my_reqbuf;
1378 int retries = 10;
1379 struct request req;
1380
1381
1382
1383 if (pc->sense_data == NULL)
1384 pc->sense_data = &my_reqbuf;
1385 pc->sense_data->sense_key = 0;
1386
1387
1388 do {
1389 req.cmd = PACKET_COMMAND;
1390 req.sector = 0;
1391 req.nr_sectors = 0;
1392 req.current_nr_sectors = 0;
1393 req.buffer = (char *)pc;
1394 req.bh = NULL;
1395 req.bhtail = NULL;
1396
1397 cdrom_queue_request (drive, &req);
1398
1399 if (pc->stat != 0)
1400 {
1401
1402
1403 struct atapi_request_sense *reqbuf = pc->sense_data;
1404
1405 if (reqbuf->sense_key == UNIT_ATTENTION)
1406 ;
1407
1408
1409
1410
1411 else if (reqbuf->sense_key == NOT_READY && reqbuf->asc == 4)
1412 {
1413 cdrom_sleep (HZ);
1414 }
1415
1416
1417 else
1418 retries = 0;
1419
1420 --retries;
1421 }
1422
1423
1424 } while (pc->stat != 0 && retries >= 0);
1425
1426
1427
1428 if (pc->stat != 0)
1429 return -EIO;
1430
1431 else
1432 {
1433
1434
1435
1436
1437 if (CDROM_STATE_FLAGS (drive)->door_locked == 0 &&
1438 (pc->c[0] != REQUEST_SENSE &&
1439 pc->c[0] != ALLOW_MEDIUM_REMOVAL &&
1440 pc->c[0] != START_STOP))
1441 {
1442 (void) cdrom_lockdoor (drive, 1, NULL);
1443 }
1444 return 0;
1445 }
1446 }
1447
1448
1449
1450
1451
1452
1453
1454 void ide_do_rw_cdrom (ide_drive_t *drive, unsigned long block)
1455 {
1456 struct request *rq = HWGROUP(drive)->rq;
1457
1458 if (rq -> cmd == PACKET_COMMAND || rq -> cmd == REQUEST_SENSE_COMMAND)
1459 cdrom_do_packet_command (drive);
1460
1461 else if (rq -> cmd == RESET_DRIVE_COMMAND)
1462 {
1463 cdrom_end_request (1, drive);
1464 if (ide_do_reset (drive))
1465 return;
1466 }
1467
1468 else if (rq -> cmd != READ)
1469 {
1470 printk ("ide-cd: bad cmd %d\n", rq -> cmd);
1471 cdrom_end_request (0, drive);
1472 }
1473 else
1474 cdrom_start_read (drive, block);
1475 }
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489 static inline
1490 void byte_swap_word (unsigned short *x)
1491 {
1492 char *c = (char *)x;
1493 char d = c[0];
1494 c[0] = c[1];
1495 c[1] = d;
1496 }
1497
1498
1499 static inline
1500 void byte_swap_long (unsigned *x)
1501 {
1502 char *c = (char *)x;
1503 char d = c[0];
1504 c[0] = c[3];
1505 c[3] = d;
1506 d = c[1];
1507 c[1] = c[2];
1508 c[2] = d;
1509 }
1510
1511
1512 static
1513 int bin2bcd (int x)
1514 {
1515 return (x%10) | ((x/10) << 4);
1516 }
1517
1518
1519 static inline
1520 void lba_to_msf (int lba, byte *m, byte *s, byte *f)
1521 {
1522 lba += CD_BLOCK_OFFSET;
1523 lba &= 0xffffff;
1524 *m = lba / (CD_SECS * CD_FRAMES);
1525 lba %= (CD_SECS * CD_FRAMES);
1526 *s = lba / CD_FRAMES;
1527 *f = lba % CD_FRAMES;
1528 }
1529
1530
1531 static inline
1532 int msf_to_lba (byte m, byte s, byte f)
1533 {
1534 return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_BLOCK_OFFSET;
1535 }
1536
1537
1538 static int
1539 cdrom_check_status (ide_drive_t *drive,
1540 struct atapi_request_sense *reqbuf)
1541 {
1542 struct packet_command pc;
1543
1544 memset (&pc, 0, sizeof (pc));
1545
1546 pc.sense_data = reqbuf;
1547 pc.c[0] = TEST_UNIT_READY;
1548
1549 return cdrom_queue_packet_command (drive, &pc);
1550 }
1551
1552
1553
1554 static int
1555 cdrom_lockdoor (ide_drive_t *drive, int lockflag,
1556 struct atapi_request_sense *reqbuf)
1557 {
1558 struct atapi_request_sense my_reqbuf;
1559 int stat;
1560 struct packet_command pc;
1561
1562 if (reqbuf == NULL)
1563 reqbuf = &my_reqbuf;
1564
1565
1566 if (CDROM_CONFIG_FLAGS (drive)->no_doorlock)
1567 stat = 0;
1568 else
1569 {
1570 memset (&pc, 0, sizeof (pc));
1571 pc.sense_data = reqbuf;
1572
1573 pc.c[0] = ALLOW_MEDIUM_REMOVAL;
1574 pc.c[4] = (lockflag != 0);
1575 stat = cdrom_queue_packet_command (drive, &pc);
1576 }
1577
1578 if (stat == 0)
1579 CDROM_STATE_FLAGS (drive)->door_locked = lockflag;
1580 else
1581 {
1582
1583
1584 if (reqbuf->sense_key == ILLEGAL_REQUEST && reqbuf->asc == 0x24)
1585 {
1586 printk ("%s: door locking not supported\n", drive->name);
1587 CDROM_CONFIG_FLAGS (drive)->no_doorlock = 1;
1588 stat = 0;
1589 CDROM_STATE_FLAGS (drive)->door_locked = lockflag;
1590 }
1591 }
1592 return stat;
1593 }
1594
1595
1596
1597
1598 static int
1599 cdrom_eject (ide_drive_t *drive, int ejectflag,
1600 struct atapi_request_sense *reqbuf)
1601 {
1602 struct packet_command pc;
1603
1604 memset (&pc, 0, sizeof (pc));
1605 pc.sense_data = reqbuf;
1606
1607 pc.c[0] = START_STOP;
1608 pc.c[4] = 2 + (ejectflag != 0);
1609 return cdrom_queue_packet_command (drive, &pc);
1610 }
1611
1612
1613 static int
1614 cdrom_pause (ide_drive_t *drive, int pauseflag,
1615 struct atapi_request_sense *reqbuf)
1616 {
1617 struct packet_command pc;
1618
1619 memset (&pc, 0, sizeof (pc));
1620 pc.sense_data = reqbuf;
1621
1622 pc.c[0] = SCMD_PAUSE_RESUME;
1623 pc.c[8] = !pauseflag;
1624 return cdrom_queue_packet_command (drive, &pc);
1625 }
1626
1627
1628 static int
1629 cdrom_startstop (ide_drive_t *drive, int startflag,
1630 struct atapi_request_sense *reqbuf)
1631 {
1632 struct packet_command pc;
1633
1634 memset (&pc, 0, sizeof (pc));
1635 pc.sense_data = reqbuf;
1636
1637 pc.c[0] = START_STOP;
1638 pc.c[1] = 1;
1639 pc.c[4] = startflag;
1640 return cdrom_queue_packet_command (drive, &pc);
1641 }
1642
1643
1644 static int
1645 cdrom_read_capacity (ide_drive_t *drive, unsigned *capacity,
1646 struct atapi_request_sense *reqbuf)
1647 {
1648 struct {
1649 unsigned lba;
1650 unsigned blocklen;
1651 } capbuf;
1652
1653 int stat;
1654 struct packet_command pc;
1655
1656 memset (&pc, 0, sizeof (pc));
1657 pc.sense_data = reqbuf;
1658
1659 pc.c[0] = READ_CAPACITY;
1660 pc.buffer = (char *)&capbuf;
1661 pc.buflen = sizeof (capbuf);
1662
1663 stat = cdrom_queue_packet_command (drive, &pc);
1664 if (stat == 0)
1665 {
1666 byte_swap_long (&capbuf.lba);
1667 *capacity = capbuf.lba;
1668 }
1669
1670 return stat;
1671 }
1672
1673
1674 static int
1675 cdrom_read_tocentry (ide_drive_t *drive, int trackno, int msf_flag,
1676 int format, char *buf, int buflen,
1677 struct atapi_request_sense *reqbuf)
1678 {
1679 struct packet_command pc;
1680
1681 memset (&pc, 0, sizeof (pc));
1682 pc.sense_data = reqbuf;
1683
1684 pc.buffer = buf;
1685 pc.buflen = buflen;
1686 pc.c[0] = SCMD_READ_TOC;
1687 pc.c[6] = trackno;
1688 pc.c[7] = (buflen >> 8);
1689 pc.c[8] = (buflen & 0xff);
1690 pc.c[9] = (format << 6);
1691 if (msf_flag) pc.c[1] = 2;
1692 return cdrom_queue_packet_command (drive, &pc);
1693 }
1694
1695
1696
1697 static int
1698 cdrom_read_toc (ide_drive_t *drive,
1699 struct atapi_request_sense *reqbuf)
1700 {
1701 int msf_flag;
1702 int stat, ntracks, i;
1703 struct atapi_toc *toc = drive->cdrom_info.toc;
1704 struct {
1705 struct atapi_toc_header hdr;
1706 struct atapi_toc_entry ent;
1707 } ms_tmp;
1708
1709 if (toc == NULL)
1710 {
1711
1712 toc = (struct atapi_toc *) kmalloc (sizeof (struct atapi_toc),
1713 GFP_KERNEL);
1714 drive->cdrom_info.toc = toc;
1715 }
1716
1717 if (toc == NULL)
1718 {
1719 printk ("%s: No cdrom TOC buffer!\n", drive->name);
1720 return -EIO;
1721 }
1722
1723
1724
1725 if (CDROM_STATE_FLAGS (drive)->toc_valid)
1726 (void) cdrom_check_status (drive, NULL);
1727
1728 if (CDROM_STATE_FLAGS (drive)->toc_valid) return 0;
1729
1730
1731 msf_flag = (CDROM_CONFIG_FLAGS (drive)->no_lba_toc);
1732
1733
1734 stat = cdrom_read_tocentry (drive, 0, msf_flag, 0, (char *)&toc->hdr,
1735 sizeof (struct atapi_toc_header) +
1736 sizeof (struct atapi_toc_entry),
1737 reqbuf);
1738 if (stat) return stat;
1739
1740 ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
1741 if (ntracks <= 0) return -EIO;
1742 if (ntracks > MAX_TRACKS) ntracks = MAX_TRACKS;
1743
1744
1745 stat = cdrom_read_tocentry (drive, 0, msf_flag, 0, (char *)&toc->hdr,
1746 sizeof (struct atapi_toc_header) +
1747 (ntracks+1) * sizeof (struct atapi_toc_entry),
1748 reqbuf);
1749 if (stat) return stat;
1750 byte_swap_word (&toc->hdr.toc_length);
1751 for (i=0; i<=ntracks; i++)
1752 {
1753 if (msf_flag)
1754 {
1755 byte *adr = (byte *)&(toc->ent[i].lba);
1756 toc->ent[i].lba = msf_to_lba (adr[1], adr[2], adr[3]);
1757 }
1758 else
1759 byte_swap_long (&toc->ent[i].lba);
1760 }
1761
1762
1763 stat = cdrom_read_tocentry (drive, 0, msf_flag, 1,
1764 (char *)&ms_tmp, sizeof (ms_tmp),
1765 reqbuf);
1766 if (stat) return stat;
1767 if (msf_flag)
1768 {
1769 byte *adr = (byte *)&(ms_tmp.ent.lba);
1770 toc->last_session_lba = msf_to_lba (adr[1], adr[2], adr[3]);
1771 }
1772 else
1773 {
1774 byte_swap_long (&ms_tmp.ent.lba);
1775 toc->last_session_lba = ms_tmp.ent.lba;
1776 }
1777 toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track);
1778
1779
1780 stat = cdrom_read_capacity (drive, &toc->capacity, reqbuf);
1781 if (stat) toc->capacity = 0x1fffff;
1782
1783 HWIF(drive)->gd->sizes[drive->select.b.unit << PARTN_BITS]
1784 = toc->capacity * SECTORS_PER_FRAME;
1785
1786
1787 CDROM_STATE_FLAGS (drive)->toc_valid = 1;
1788
1789 return 0;
1790 }
1791
1792
1793 static int
1794 cdrom_read_subchannel (ide_drive_t *drive,
1795 char *buf, int buflen,
1796 struct atapi_request_sense *reqbuf)
1797 {
1798 struct packet_command pc;
1799
1800 memset (&pc, 0, sizeof (pc));
1801 pc.sense_data = reqbuf;
1802
1803 pc.buffer = buf;
1804 pc.buflen = buflen;
1805 pc.c[0] = SCMD_READ_SUBCHANNEL;
1806 pc.c[2] = 0x40;
1807 pc.c[3] = 0x01;
1808 pc.c[7] = (buflen >> 8);
1809 pc.c[8] = (buflen & 0xff);
1810 return cdrom_queue_packet_command (drive, &pc);
1811 }
1812
1813
1814
1815 static int
1816 cdrom_mode_sense (ide_drive_t *drive, int pageno, int modeflag,
1817 char *buf, int buflen,
1818 struct atapi_request_sense *reqbuf)
1819 {
1820 struct packet_command pc;
1821
1822 memset (&pc, 0, sizeof (pc));
1823 pc.sense_data = reqbuf;
1824
1825 pc.buffer = buf;
1826 pc.buflen = buflen;
1827 pc.c[0] = MODE_SENSE_10;
1828 pc.c[2] = pageno | (modeflag << 6);
1829 pc.c[7] = (buflen >> 8);
1830 pc.c[8] = (buflen & 0xff);
1831 return cdrom_queue_packet_command (drive, &pc);
1832 }
1833
1834
1835 static int
1836 cdrom_mode_select (ide_drive_t *drive, int pageno, char *buf, int buflen,
1837 struct atapi_request_sense *reqbuf)
1838 {
1839 struct packet_command pc;
1840
1841 memset (&pc, 0, sizeof (pc));
1842 pc.sense_data = reqbuf;
1843
1844 pc.buffer = buf;
1845 pc.buflen = - buflen;
1846 pc.c[0] = MODE_SELECT_10;
1847 pc.c[1] = 0x10;
1848 pc.c[2] = pageno;
1849 pc.c[7] = (buflen >> 8);
1850 pc.c[8] = (buflen & 0xff);
1851 return cdrom_queue_packet_command (drive, &pc);
1852 }
1853
1854
1855 static int
1856 cdrom_play_lba_range_play12 (ide_drive_t *drive, int lba_start, int lba_end,
1857 struct atapi_request_sense *reqbuf)
1858 {
1859 struct packet_command pc;
1860
1861 memset (&pc, 0, sizeof (pc));
1862 pc.sense_data = reqbuf;
1863
1864 pc.c[0] = SCMD_PLAYAUDIO12;
1865 *(int *)(&pc.c[2]) = lba_start;
1866 *(int *)(&pc.c[6]) = lba_end - lba_start;
1867 byte_swap_long ((int *)(&pc.c[2]));
1868 byte_swap_long ((int *)(&pc.c[6]));
1869
1870 return cdrom_queue_packet_command (drive, &pc);
1871 }
1872
1873
1874 static int
1875 cdrom_play_lba_range_msf (ide_drive_t *drive, int lba_start, int lba_end,
1876 struct atapi_request_sense *reqbuf)
1877 {
1878 struct packet_command pc;
1879
1880 memset (&pc, 0, sizeof (pc));
1881 pc.sense_data = reqbuf;
1882
1883 pc.c[0] = SCMD_PLAYAUDIO_MSF;
1884 lba_to_msf (lba_start, &pc.c[3], &pc.c[4], &pc.c[5]);
1885 lba_to_msf (lba_end-1, &pc.c[6], &pc.c[7], &pc.c[8]);
1886
1887 if (CDROM_CONFIG_FLAGS (drive)->msf_as_bcd)
1888 {
1889 pc.c[3] = bin2bcd (pc.c[3]);
1890 pc.c[4] = bin2bcd (pc.c[4]);
1891 pc.c[5] = bin2bcd (pc.c[5]);
1892 pc.c[6] = bin2bcd (pc.c[6]);
1893 pc.c[7] = bin2bcd (pc.c[7]);
1894 pc.c[8] = bin2bcd (pc.c[8]);
1895 }
1896
1897 return cdrom_queue_packet_command (drive, &pc);
1898 }
1899
1900
1901
1902
1903 static int
1904 cdrom_play_lba_range (ide_drive_t *drive, int lba_start, int lba_end,
1905 struct atapi_request_sense *reqbuf)
1906 {
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918 if (CDROM_CONFIG_FLAGS (drive)->no_playaudio12)
1919 return cdrom_play_lba_range_msf (drive, lba_start, lba_end, reqbuf);
1920 else
1921 {
1922 int stat;
1923 struct atapi_request_sense my_reqbuf;
1924
1925 if (reqbuf == NULL)
1926 reqbuf = &my_reqbuf;
1927
1928 stat = cdrom_play_lba_range_play12 (drive, lba_start, lba_end, reqbuf);
1929 if (stat == 0) return 0;
1930
1931
1932 if (reqbuf->sense_key == ILLEGAL_REQUEST && reqbuf->asc == 0x20)
1933 {
1934
1935
1936 printk ("%s: Drive does not support PLAYAUDIO12; "
1937 "trying PLAYAUDIO_MSF\n", drive->name);
1938 CDROM_CONFIG_FLAGS (drive)->no_playaudio12 = 1;
1939 CDROM_CONFIG_FLAGS (drive)->msf_as_bcd = 1;
1940 return cdrom_play_lba_range_msf (drive, lba_start, lba_end, reqbuf);
1941 }
1942
1943
1944 return stat;
1945 }
1946 }
1947
1948
1949 static
1950 int cdrom_get_toc_entry (ide_drive_t *drive, int track,
1951 struct atapi_toc_entry **ent,
1952 struct atapi_request_sense *reqbuf)
1953 {
1954 int stat, ntracks;
1955 struct atapi_toc *toc;
1956
1957
1958 stat = cdrom_read_toc (drive, reqbuf);
1959 if (stat) return stat;
1960
1961 toc = drive->cdrom_info.toc;
1962
1963
1964 ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
1965 if (track == CDROM_LEADOUT)
1966 *ent = &toc->ent[ntracks];
1967 else if (track < toc->hdr.first_track ||
1968 track > toc->hdr.last_track)
1969 return -EINVAL;
1970 else
1971 *ent = &toc->ent[track - toc->hdr.first_track];
1972
1973 return 0;
1974 }
1975
1976
1977 static int
1978 cdrom_read_block (ide_drive_t *drive, int format, int lba,
1979 char *buf, int buflen,
1980 struct atapi_request_sense *reqbuf)
1981 {
1982 struct packet_command pc;
1983 struct atapi_request_sense my_reqbuf;
1984 int stat;
1985
1986 if (reqbuf == NULL)
1987 reqbuf = &my_reqbuf;
1988
1989 memset (&pc, 0, sizeof (pc));
1990 pc.sense_data = reqbuf;
1991
1992 pc.buffer = buf;
1993 pc.buflen = buflen;
1994
1995 if (CDROM_CONFIG_FLAGS (drive)->old_readcd)
1996 pc.c[0] = 0xd4;
1997 else
1998 pc.c[0] = READ_CD;
1999
2000 pc.c[1] = (format << 2);
2001 *(int *)(&pc.c[2]) = lba;
2002 byte_swap_long ((int *)(&pc.c[2]));
2003 pc.c[8] = 1;
2004 pc.c[9] = 0x10;
2005
2006 stat = cdrom_queue_packet_command (drive, &pc);
2007
2008
2009
2010 if (stat && reqbuf->sense_key == ILLEGAL_REQUEST && reqbuf->asc == 0x20 &&
2011 CDROM_CONFIG_FLAGS (drive)->old_readcd == 0)
2012 {
2013 printk ("%s: Drive does not recognize READ_CD; trying opcode 0xd4\n",
2014 drive->name);
2015 CDROM_CONFIG_FLAGS (drive)->old_readcd = 1;
2016 return cdrom_read_block (drive, format, lba, buf, buflen, reqbuf);
2017 }
2018
2019 return stat;
2020 }
2021
2022
2023 int ide_cdrom_ioctl (ide_drive_t *drive, struct inode *inode,
2024 struct file *file, unsigned int cmd, unsigned long arg)
2025 {
2026 switch (cmd)
2027 {
2028 case CDROMEJECT:
2029 {
2030 int stat;
2031
2032 if (drive->usage > 1)
2033 return -EBUSY;
2034
2035 stat = cdrom_lockdoor (drive, 0, NULL);
2036 if (stat) return stat;
2037
2038 return cdrom_eject (drive, 0, NULL);
2039 }
2040
2041 case CDROMEJECT_SW:
2042 {
2043 CDROM_STATE_FLAGS (drive)->eject_on_close = arg;
2044 return 0;
2045 }
2046
2047 case CDROMPAUSE:
2048 return cdrom_pause (drive, 1, NULL);
2049
2050 case CDROMRESUME:
2051 return cdrom_pause (drive, 0, NULL);
2052
2053 case CDROMSTART:
2054 return cdrom_startstop (drive, 1, NULL);
2055
2056 case CDROMSTOP:
2057 {
2058 int stat;
2059
2060 stat = cdrom_startstop (drive, 0, NULL);
2061 if (stat) return stat;
2062
2063 return cdrom_eject (drive, 1, NULL);
2064 }
2065
2066 case CDROMPLAYMSF:
2067 {
2068 struct cdrom_msf msf;
2069 int stat, lba_start, lba_end;
2070
2071 stat = verify_area (VERIFY_READ, (void *)arg, sizeof (msf));
2072 if (stat) return stat;
2073
2074 memcpy_fromfs (&msf, (void *) arg, sizeof(msf));
2075
2076 lba_start = msf_to_lba (msf.cdmsf_min0, msf.cdmsf_sec0,
2077 msf.cdmsf_frame0);
2078 lba_end = msf_to_lba (msf.cdmsf_min1, msf.cdmsf_sec1,
2079 msf.cdmsf_frame1) + 1;
2080
2081 if (lba_end <= lba_start) return -EINVAL;
2082
2083 return cdrom_play_lba_range (drive, lba_start, lba_end, NULL);
2084 }
2085
2086
2087
2088 case CDROMPLAYTRKIND:
2089 {
2090 int stat, lba_start, lba_end;
2091 struct cdrom_ti ti;
2092 struct atapi_toc_entry *first_toc, *last_toc;
2093
2094 stat = verify_area (VERIFY_READ, (void *)arg, sizeof (ti));
2095 if (stat) return stat;
2096
2097 memcpy_fromfs (&ti, (void *) arg, sizeof(ti));
2098
2099 stat = cdrom_get_toc_entry (drive, ti.cdti_trk0, &first_toc, NULL);
2100 if (stat) return stat;
2101 stat = cdrom_get_toc_entry (drive, ti.cdti_trk1, &last_toc, NULL);
2102 if (stat) return stat;
2103
2104 if (ti.cdti_trk1 != CDROM_LEADOUT) ++last_toc;
2105 lba_start = first_toc->lba;
2106 lba_end = last_toc->lba;
2107
2108 if (lba_end <= lba_start) return -EINVAL;
2109
2110 return cdrom_play_lba_range (drive, lba_start, lba_end, NULL);
2111 }
2112
2113 case CDROMREADTOCHDR:
2114 {
2115 int stat;
2116 struct cdrom_tochdr tochdr;
2117 struct atapi_toc *toc;
2118
2119 stat = verify_area (VERIFY_WRITE, (void *) arg, sizeof (tochdr));
2120 if (stat) return stat;
2121
2122
2123 stat = cdrom_read_toc (drive, NULL);
2124 if (stat) return stat;
2125
2126 toc = drive->cdrom_info.toc;
2127 tochdr.cdth_trk0 = toc->hdr.first_track;
2128 tochdr.cdth_trk1 = toc->hdr.last_track;
2129
2130 memcpy_tofs ((void *) arg, &tochdr, sizeof (tochdr));
2131
2132 return stat;
2133 }
2134
2135 case CDROMREADTOCENTRY:
2136 {
2137 int stat;
2138 struct cdrom_tocentry tocentry;
2139 struct atapi_toc_entry *toce;
2140
2141 stat = verify_area (VERIFY_READ, (void *) arg, sizeof (tocentry));
2142 if (stat) return stat;
2143 stat = verify_area (VERIFY_WRITE, (void *) arg, sizeof (tocentry));
2144 if (stat) return stat;
2145
2146 memcpy_fromfs (&tocentry, (void *) arg, sizeof (tocentry));
2147
2148 stat = cdrom_get_toc_entry (drive, tocentry.cdte_track, &toce, NULL);
2149 if (stat) return stat;
2150
2151 tocentry.cdte_ctrl = toce->control;
2152 tocentry.cdte_adr = toce->adr;
2153
2154 if (tocentry.cdte_format == CDROM_MSF)
2155 {
2156
2157 lba_to_msf (toce->lba,
2158 &tocentry.cdte_addr.msf.minute,
2159 &tocentry.cdte_addr.msf.second,
2160 &tocentry.cdte_addr.msf.frame);
2161 }
2162 else
2163 tocentry.cdte_addr.lba = toce->lba;
2164
2165 memcpy_tofs ((void *) arg, &tocentry, sizeof (tocentry));
2166
2167 return stat;
2168 }
2169
2170 case CDROMSUBCHNL:
2171 {
2172 char buffer[16];
2173 int stat, abs_lba, rel_lba;
2174 struct cdrom_subchnl subchnl;
2175
2176 stat = verify_area (VERIFY_WRITE, (void *) arg, sizeof (subchnl));
2177 if (stat) return stat;
2178 stat = verify_area (VERIFY_READ, (void *) arg, sizeof (subchnl));
2179 if (stat) return stat;
2180
2181 memcpy_fromfs (&subchnl, (void *) arg, sizeof (subchnl));
2182
2183 stat = cdrom_read_subchannel (drive, buffer, sizeof (buffer), NULL);
2184 if (stat) return stat;
2185
2186 abs_lba = *(int *)&buffer[8];
2187 rel_lba = *(int *)&buffer[12];
2188 byte_swap_long (&abs_lba);
2189 byte_swap_long (&rel_lba);
2190
2191 if (subchnl.cdsc_format == CDROM_MSF)
2192 {
2193 lba_to_msf (abs_lba,
2194 &subchnl.cdsc_absaddr.msf.minute,
2195 &subchnl.cdsc_absaddr.msf.second,
2196 &subchnl.cdsc_absaddr.msf.frame);
2197 lba_to_msf (rel_lba,
2198 &subchnl.cdsc_reladdr.msf.minute,
2199 &subchnl.cdsc_reladdr.msf.second,
2200 &subchnl.cdsc_reladdr.msf.frame);
2201 }
2202 else
2203 {
2204 subchnl.cdsc_absaddr.lba = abs_lba;
2205 subchnl.cdsc_reladdr.lba = rel_lba;
2206 }
2207
2208 subchnl.cdsc_audiostatus = buffer[1];
2209 subchnl.cdsc_ctrl = buffer[5] & 0xf;
2210 subchnl.cdsc_trk = buffer[6];
2211 subchnl.cdsc_ind = buffer[7];
2212
2213 memcpy_tofs ((void *) arg, &subchnl, sizeof (subchnl));
2214
2215 return stat;
2216 }
2217
2218 case CDROMVOLCTRL:
2219 {
2220 struct cdrom_volctrl volctrl;
2221 char buffer[24], mask[24];
2222 int stat;
2223
2224 stat = verify_area (VERIFY_READ, (void *) arg, sizeof (volctrl));
2225 if (stat) return stat;
2226 memcpy_fromfs (&volctrl, (void *) arg, sizeof (volctrl));
2227
2228 stat = cdrom_mode_sense (drive, 0x0e, 0, buffer, sizeof (buffer),NULL);
2229 if (stat) return stat;
2230 stat = cdrom_mode_sense (drive, 0x0e, 1, mask , sizeof (buffer),NULL);
2231 if (stat) return stat;
2232
2233 buffer[1] = buffer[2] = 0;
2234
2235 buffer[17] = volctrl.channel0 & mask[17];
2236 buffer[19] = volctrl.channel1 & mask[19];
2237 buffer[21] = volctrl.channel2 & mask[21];
2238 buffer[23] = volctrl.channel3 & mask[23];
2239
2240 return cdrom_mode_select (drive, 0x0e, buffer, sizeof (buffer), NULL);
2241 }
2242
2243 case CDROMVOLREAD:
2244 {
2245 struct cdrom_volctrl volctrl;
2246 char buffer[24];
2247 int stat;
2248
2249 stat = verify_area (VERIFY_WRITE, (void *) arg, sizeof (volctrl));
2250 if (stat) return stat;
2251
2252 stat = cdrom_mode_sense (drive, 0x0e, 0, buffer, sizeof (buffer), NULL);
2253 if (stat) return stat;
2254
2255 volctrl.channel0 = buffer[17];
2256 volctrl.channel1 = buffer[19];
2257 volctrl.channel2 = buffer[21];
2258 volctrl.channel3 = buffer[23];
2259
2260 memcpy_tofs ((void *) arg, &volctrl, sizeof (volctrl));
2261
2262 return 0;
2263 }
2264
2265 case CDROMMULTISESSION:
2266 {
2267 struct cdrom_multisession ms_info;
2268 struct atapi_toc *toc;
2269 int stat;
2270
2271 stat = verify_area (VERIFY_READ, (void *)arg, sizeof (ms_info));
2272 if (stat) return stat;
2273 stat = verify_area (VERIFY_WRITE, (void *)arg, sizeof (ms_info));
2274 if (stat) return stat;
2275
2276 memcpy_fromfs (&ms_info, (void *)arg, sizeof (ms_info));
2277
2278
2279 stat = cdrom_read_toc (drive, NULL);
2280 if (stat) return stat;
2281
2282 toc = drive->cdrom_info.toc;
2283
2284 if (ms_info.addr_format == CDROM_MSF)
2285 lba_to_msf (toc->last_session_lba,
2286 &ms_info.addr.msf.minute,
2287 &ms_info.addr.msf.second,
2288 &ms_info.addr.msf.frame);
2289
2290 else if (ms_info.addr_format == CDROM_LBA)
2291 ms_info.addr.lba = toc->last_session_lba;
2292
2293 else
2294 return -EINVAL;
2295
2296 ms_info.xa_flag = toc->xa_flag;
2297
2298 memcpy_tofs ((void *)arg, &ms_info, sizeof (ms_info));
2299
2300 return 0;
2301 }
2302
2303
2304 case CDROMREADAUDIO:
2305 {
2306 int stat, lba;
2307 struct atapi_toc *toc;
2308 struct cdrom_read_audio ra;
2309 char buf[CD_FRAMESIZE_RAW];
2310
2311
2312 stat = cdrom_read_toc (drive, NULL);
2313 if (stat) return stat;
2314
2315 toc = drive->cdrom_info.toc;
2316
2317 stat = verify_area (VERIFY_READ, (char *)arg, sizeof (ra));
2318 if (stat) return stat;
2319
2320 memcpy_fromfs (&ra, (void *)arg, sizeof (ra));
2321
2322 if (ra.nframes < 0 || ra.nframes > toc->capacity)
2323 return -EINVAL;
2324 else if (ra.nframes == 0)
2325 return 0;
2326
2327 stat = verify_area (VERIFY_WRITE, (char *)ra.buf,
2328 ra.nframes * CD_FRAMESIZE_RAW);
2329 if (stat) return stat;
2330
2331 if (ra.addr_format == CDROM_MSF)
2332 lba = msf_to_lba (ra.addr.msf.minute, ra.addr.msf.second,
2333 ra.addr.msf.frame);
2334
2335 else if (ra.addr_format == CDROM_LBA)
2336 lba = ra.addr.lba;
2337
2338 else
2339 return -EINVAL;
2340
2341 if (lba < 0 || lba >= toc->capacity)
2342 return -EINVAL;
2343
2344 while (ra.nframes > 0)
2345 {
2346 stat = cdrom_read_block (drive, 1, lba, buf,
2347 CD_FRAMESIZE_RAW, NULL);
2348 if (stat) return stat;
2349 memcpy_tofs (ra.buf, buf, CD_FRAMESIZE_RAW);
2350 ra.buf += CD_FRAMESIZE_RAW;
2351 --ra.nframes;
2352 ++lba;
2353 }
2354
2355 return 0;
2356 }
2357
2358 case CDROMREADMODE1:
2359 case CDROMREADMODE2:
2360 {
2361 struct cdrom_msf msf;
2362 int blocksize, format, stat, lba;
2363 struct atapi_toc *toc;
2364 char buf[CD_FRAMESIZE_RAW0];
2365
2366 if (cmd == CDROMREADMODE1)
2367 {
2368 blocksize = CD_FRAMESIZE;
2369 format = 2;
2370 }
2371 else
2372 {
2373 blocksize = CD_FRAMESIZE_RAW0;
2374 format = 3;
2375 }
2376
2377 stat = verify_area (VERIFY_READ, (char *)arg, sizeof (msf));
2378 if (stat) return stat;
2379 stat = verify_area (VERIFY_WRITE, (char *)arg, blocksize);
2380 if (stat) return stat;
2381
2382 memcpy_fromfs (&msf, (void *)arg, sizeof (msf));
2383
2384 lba = msf_to_lba (msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0);
2385
2386
2387 stat = cdrom_read_toc (drive, NULL);
2388 if (stat) return stat;
2389
2390 toc = drive->cdrom_info.toc;
2391
2392 if (lba < 0 || lba >= toc->capacity)
2393 return -EINVAL;
2394
2395 stat = cdrom_read_block (drive, format, lba, buf, blocksize, NULL);
2396 if (stat) return stat;
2397
2398 memcpy_tofs ((char *)arg, buf, blocksize);
2399 return 0;
2400 }
2401
2402 #if 0
2403 case CDROMRESET:
2404 {
2405 struct request req;
2406 memset (&req, 0, sizeof (req));
2407 req.cmd = RESET_DRIVE_COMMAND;
2408 cdrom_queue_request (drive, &req);
2409 return 0;
2410 }
2411 #endif
2412
2413
2414 #ifdef TEST
2415 case 0x1234:
2416 {
2417 int stat;
2418 struct packet_command pc;
2419 int len, lena;
2420
2421 memset (&pc, 0, sizeof (pc));
2422
2423 stat = verify_area (VERIFY_READ, (void *) arg, sizeof (pc.c));
2424 if (stat) return stat;
2425 memcpy_fromfs (&pc.c, (void *) arg, sizeof (pc.c));
2426 arg += sizeof (pc.c);
2427
2428 stat = verify_area (VERIFY_READ, (void *) arg, sizeof (len));
2429 if (stat) return stat;
2430 memcpy_fromfs (&len, (void *) arg , sizeof (len));
2431 arg += sizeof (len);
2432
2433 if (len > 0) {
2434 stat = verify_area (VERIFY_WRITE, (void *) arg, len);
2435 if (stat) return stat;
2436 }
2437
2438 lena = len;
2439 if (lena < 0) lena = 0;
2440
2441 {
2442 char buf[lena];
2443 if (len > 0) {
2444 pc.buflen = len;
2445 pc.buffer = buf;
2446 }
2447
2448 stat = cdrom_queue_packet_command (drive, &pc);
2449
2450 if (len > 0)
2451 memcpy_tofs ((void *)arg, buf, len);
2452 }
2453
2454 return stat;
2455 }
2456 #endif
2457
2458 default:
2459 return -EPERM;
2460 }
2461
2462 }
2463
2464
2465
2466
2467
2468
2469
2470 int ide_cdrom_check_media_change (ide_drive_t *drive)
2471 {
2472 int retval;
2473
2474 (void) cdrom_check_status (drive, NULL);
2475
2476 retval = CDROM_STATE_FLAGS (drive)->media_changed;
2477 CDROM_STATE_FLAGS (drive)->media_changed = 0;
2478
2479 return retval;
2480 }
2481
2482
2483 int ide_cdrom_open (struct inode *ip, struct file *fp, ide_drive_t *drive)
2484 {
2485
2486 if (fp->f_mode & 2)
2487 {
2488 --drive->usage;
2489 return -EROFS;
2490 }
2491
2492
2493 if (drive->usage == 1)
2494 {
2495 int stat;
2496 struct atapi_request_sense my_reqbuf;
2497 my_reqbuf.sense_key = 0;
2498
2499
2500 stat = cdrom_check_status (drive, &my_reqbuf);
2501
2502
2503 if (stat && my_reqbuf.sense_key == NOT_READY)
2504 {
2505 cdrom_eject (drive, 1, &my_reqbuf);
2506 stat = cdrom_check_status (drive, &my_reqbuf);
2507 }
2508
2509
2510 if (stat && my_reqbuf.sense_key != UNIT_ATTENTION)
2511 {
2512 --drive->usage;
2513 return -ENXIO;
2514 }
2515
2516
2517 (void) cdrom_lockdoor (drive, 1, &my_reqbuf);
2518
2519
2520 (void) cdrom_read_toc (drive, &my_reqbuf);
2521 }
2522
2523 return 0;
2524 }
2525
2526
2527
2528
2529
2530
2531 void ide_cdrom_release (struct inode *inode, struct file *file, ide_drive_t *drive)
2532 {
2533 if (drive->usage == 0)
2534 {
2535 invalidate_buffers (inode->i_rdev);
2536
2537
2538 (void) cdrom_lockdoor (drive, 0, NULL);
2539
2540
2541 if (CDROM_STATE_FLAGS (drive)->eject_on_close)
2542 (void) cdrom_eject (drive, 0, NULL);
2543 }
2544 }
2545
2546
2547
2548
2549
2550
2551
2552 void ide_cdrom_setup (ide_drive_t *drive)
2553 {
2554 blksize_size[HWIF(drive)->major][drive->select.b.unit << PARTN_BITS] = CD_FRAMESIZE;
2555
2556 drive->special.all = 0;
2557 drive->ready_stat = 0;
2558
2559 CDROM_STATE_FLAGS (drive)->media_changed = 0;
2560 CDROM_STATE_FLAGS (drive)->toc_valid = 0;
2561 CDROM_STATE_FLAGS (drive)->door_locked = 0;
2562
2563
2564 CDROM_STATE_FLAGS (drive)->eject_on_close= 0;
2565
2566 CDROM_CONFIG_FLAGS (drive)->no_doorlock = 0;
2567 CDROM_CONFIG_FLAGS (drive)->no_playaudio12 = 0;
2568 CDROM_CONFIG_FLAGS (drive)->old_readcd = 0;
2569 CDROM_CONFIG_FLAGS (drive)->no_lba_toc = 0;
2570 CDROM_CONFIG_FLAGS (drive)->msf_as_bcd = 0;
2571 CDROM_CONFIG_FLAGS (drive)->drq_interrupt =
2572 ((drive->id->config & 0x0060) == 0x20);
2573
2574
2575 if (strcmp (drive->id->model, "CD220E") == 0)
2576 CDROM_CONFIG_FLAGS (drive)->no_lba_toc = 1;
2577
2578 else if (strcmp (drive->id->model, "TO-ICSLYAL") == 0 ||
2579 strcmp (drive->id->model, "OTI-SCYLLA") == 0)
2580 CDROM_CONFIG_FLAGS (drive)->no_lba_toc = 1;
2581
2582 else if (strcmp (drive->id->model, "CDA26803I SE") == 0)
2583 {
2584 CDROM_CONFIG_FLAGS (drive)->no_lba_toc = 1;
2585
2586
2587 CDROM_CONFIG_FLAGS (drive)->no_playaudio12 = 1;
2588 }
2589
2590 drive->cdrom_info.toc = NULL;
2591 drive->cdrom_info.sector_buffer = NULL;
2592 drive->cdrom_info.sector_buffered = 0;
2593 drive->cdrom_info.nsectors_buffered = 0;
2594 }
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607