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