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