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