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