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