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