1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
|
/*
* Mach Operating System
* Copyright (c) 1993 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/*
* File: rz_audio.c
* Author: Alessandro Forin, Carnegie Mellon University
* Date: 3/93
*
* Top layer of the SCSI driver: interface with the MI.
* This file contains operations specific to audio CD-ROM devices.
* Unlike many others, it sits on top of the rz.c module.
*/
#include <mach/std_types.h>
#include <kern/strings.h>
#include <machine/machspl.h> /* spl definitions */
#include <vm/vm_kern.h>
#include <device/ds_routines.h>
#include <scsi/compat_30.h>
#include <scsi/scsi.h>
#include <scsi/scsi2.h>
#include <scsi/scsi_defs.h>
#include <scsi/rz.h>
#if (NSCSI > 0)
#define private static
/* some data is two BCD digits in one byte */
#define bcd_to_decimal(b) (((b)&0xf) + 10 * (((b) >> 4) & 0xf))
#define decimal_to_bcd(b) ((((b) / 10) << 4) | ((b) % 10))
/*
* Regular use of a CD-ROM is for data, and is handled
* by the default set of operations. Ours is for funtime..
*/
extern char *sccdrom_name();
int cd_strategy();
void cd_start();
private scsi_devsw_t scsi_audio = {
sccdrom_name, 0, 0, 0, cd_strategy, cd_start, 0, 0
};
private char unsupported[] = "Device does not support it.";
/*
* Unfortunately, none of the vendors appear to
* abide by the SCSI-2 standard and many of them
* violate or stretch even the SCSI-1 one.
* Therefore, we keep a red-list here of the worse
* offendors and how to deal with them.
* The user is notified of the problem and invited
* to solicit his vendor to upgrade the firmware.
* [They had plenty of time to do so]
*/
typedef struct red_list {
char *vendor;
char *product;
char *rev;
/*
* The standard MANDATES [par 13.1.6] the play_audio command
* at least as a way to discover if the device
* supports audio operations at all. This is the only way
* we need to use it.
*/
scsi_ret_t (*can_play_audio)( target_info_t *, char *, io_req_t);
/*
* The standard defines the use of start_stop_unit to
* cause the drive to eject the disk.
*/
scsi_ret_t (*eject)( target_info_t *, char *, io_req_t );
/*
* The standard defines read_subchannel as a way to
* get the current playing position.
*/
scsi_ret_t (*current_position)( target_info_t *, char *, io_req_t );
/*
* The standard defines read_table_of_content to get
* the listing of audio tracks available.
*/
scsi_ret_t (*read_toc)( target_info_t *, char *, io_req_t );
/*
* The standard defines read_subchannel as the way to
* report the current audio status (playing/stopped/...).
*/
scsi_ret_t (*get_status)( target_info_t *, char *, io_req_t );
/*
* The standard defines two ways to issue a play command,
* depending on the type of addressing used.
*/
scsi_ret_t (*play_msf)( target_info_t *, char *, io_req_t );
scsi_ret_t (*play_ti)( target_info_t *, char *, io_req_t );
/*
* The standard defines the pause_resume command to
* suspend or resume playback of audio data.
*/
scsi_ret_t (*pause_resume)( target_info_t *, char *, io_req_t );
/*
* The standard defines the audio page among the
* mode selection options as a way to control
* both volume and connectivity of the channels
*/
scsi_ret_t (*volume_control)( target_info_t *, char *, io_req_t );
} red_list_t;
#define if_it_can_do(some_cmd) \
if (tgt->dev_info.cdrom.violates_standards && \
tgt->dev_info.cdrom.violates_standards->some_cmd) \
rc = (*tgt->dev_info.cdrom.violates_standards->some_cmd) \
(tgt,cmd,ior); \
else
/*
* So now that you know what they should have implemented :-),
* check at the end of the file what the naughty boys did instead.
*/
/* private red_list_t audio_replacements[]; / * at end */
/*
* Forward decls
*/
private void decode_status( char *buf, unsigned char audio_status );
void zero_ior( io_req_t );
/*
* Open routine. Does some checking, sets up
* the replacement pointer.
*/
io_return_t
cd_open(
int dev,
dev_mode_t mode,
io_req_t req)
{
scsi_softc_t *sc = 0;
target_info_t *tgt;
int ret;
scsi_ret_t rc;
io_req_t ior = 0;
vm_offset_t mem = 0;
extern boolean_t rz_check();
if (!rz_check(dev, &sc, &tgt)) {
/*
* Probe it again: might have installed a new device
*/
if (!sc || !scsi_probe(sc, &tgt, rzslave(dev), ior))
return D_NO_SUCH_DEVICE;
bzero(&tgt->dev_info, sizeof(tgt->dev_info));
}
/*
* Check this is indeded a CD-ROM
*/
if (tgt->dev_ops != &scsi_devsw[SCSI_CDROM]) {
rz_close(dev);
return D_NO_SUCH_DEVICE;
}
/*
* Switch to audio ops, unless some wrong
*/
tgt->dev_ops = &scsi_audio;
/*
* Bring unit online
*/
ret = rz_open(dev, mode, req);
if (ret) goto bad;
/* Pessimistic */
ret = D_INVALID_OPERATION;
/*
* Check if this device is on the red list
*/
{
scsi2_inquiry_data_t *inq;
private void check_red_list();
scsi_inquiry(tgt, SCSI_INQ_STD_DATA);
inq = (scsi2_inquiry_data_t*)tgt->cmd_ptr;
check_red_list( tgt, inq );
}
/*
* Allocate dynamic data
*/
if (kmem_alloc(kernel_map, &mem, PAGE_SIZE) != KERN_SUCCESS)
return D_NO_MEMORY;
tgt->dev_info.cdrom.result = (void *)mem;
tgt->dev_info.cdrom.result_available = FALSE;
/*
* See if this CDROM can play audio data
*/
io_req_alloc(ior,0);
zero_ior( ior );
{
char *cmd = 0;
if_it_can_do(can_play_audio)
rc = scsi_play_audio( tgt, 0, 0, FALSE, ior);
}
if (rc != SCSI_RET_SUCCESS) goto bad;
io_req_free(ior);
return D_SUCCESS;
bad:
if (ior) io_req_free(ior);
if (mem) kmem_free(kernel_map, mem, PAGE_SIZE);
tgt->dev_ops = &scsi_devsw[SCSI_CDROM];
return ret;
}
/*
* Close routine.
*/
io_return_t
cd_close(
int dev)
{
scsi_softc_t *sc;
target_info_t *tgt;
vm_offset_t mem;
if (!rz_check(dev, &sc, &tgt))
return D_NO_SUCH_DEVICE;
if (!tgt || (tgt->dev_ops != &scsi_audio))
return D_NO_SUCH_DEVICE;
/*
* Cleanup state
*/
mem = (vm_offset_t) tgt->dev_info.cdrom.result;
tgt->dev_info.cdrom.result = (void *)0;
tgt->dev_info.cdrom.result_available = FALSE;
(void) kmem_free(kernel_map, mem, PAGE_SIZE);
(void) rz_close(dev);
tgt->dev_ops = &scsi_devsw[SCSI_CDROM];
return D_SUCCESS;
}
/*
* Write routine. It is passed an ASCII string
* with the command to be executed.
*/
io_return_t
cd_write(
int dev,
io_req_t ior)
{
register kern_return_t rc;
boolean_t wait = FALSE;
io_return_t ret;
int count;
register char *data;
vm_offset_t addr;
data = ior->io_data;
count = ior->io_count;
if (count == 0)
return D_SUCCESS;
if (!(ior->io_op & IO_INBAND)) {
/*
* Copy out-of-line data into kernel address space.
* Since data is copied as page list, it will be
* accessible.
*/
vm_map_copy_t copy = (vm_map_copy_t) data;
kern_return_t kr;
kr = vm_map_copyout(device_io_map, &addr, copy);
if (kr != KERN_SUCCESS)
return kr;
data = (char *) addr;
}
if (scsi_debug) printf("Got command '%s'\n", data);
ret = cd_command( dev, data, count, ior);
if (!(ior->io_op & IO_INBAND))
(void) vm_deallocate(device_io_map, addr, ior->io_count);
return D_SUCCESS;
}
/*
* Read routine. Returns an ASCII string with the results
* of the last command executed.
*/
io_return_t
cd_read(
int dev,
io_req_t ior)
{
target_info_t *tgt;
kern_return_t rc;
natural_t count;
/*
* Allocate memory for read buffer.
*/
count = (natural_t)ior->io_count;
if (count > PAGE_SIZE)
return D_INVALID_SIZE; /* sanity */
rc = device_read_alloc(ior, count);
if (rc != KERN_SUCCESS)
return rc;
if (scsi_debug) printf("Got read req for %d bytes\n", count);
/*
* See if last cmd left some to say
*/
tgt = scsi_softc[rzcontroller(dev)]->target[rzslave(dev)];
if (tgt->dev_info.cdrom.result_available) {
int len;
tgt->dev_info.cdrom.result_available = FALSE;
len = strlen(tgt->dev_info.cdrom.result)+1;
if (count > len)
count = len;
bcopy(tgt->dev_info.cdrom.result, ior->io_data, count);
} else {
# define noway "No results pending"
count = (count > sizeof(noway)) ? sizeof(noway) : count;
bcopy(noway, ior->io_data, count);
}
ior->io_residual = ior->io_count - count;
return D_SUCCESS;
}
/*
* This does all the work
*/
io_return_t
cd_command(
int dev,
char *cmd,
int count,
io_req_t req)
{
target_info_t *tgt;
io_req_t ior;
io_return_t ret = D_INVALID_OPERATION;
scsi_ret_t rc;
char *buf;
tgt = scsi_softc[rzcontroller(dev)]->target[rzslave(dev)];
buf = tgt->dev_info.cdrom.result;
tgt->dev_info.cdrom.result_available = FALSE;
io_req_alloc(ior,0);
zero_ior( ior );
switch (cmd[0]) {
case 'E':
/* "Eject" */
/* too many dont support it. Sigh */
tgt->flags |= TGT_OPTIONAL_CMD;
(void) scsi_medium_removal( tgt, TRUE, ior);
tgt->flags &= ~TGT_OPTIONAL_CMD;
zero_ior( ior );
if_it_can_do(eject)
rc = scsi_start_unit(tgt, SCSI_CMD_SS_EJECT, ior);
break;
case 'G':
switch (cmd[4]) {
case 'P':
/* "Get Position MSF|ABS" */
if_it_can_do(current_position) {
rc = scsi_read_subchannel(tgt,
cmd[13] == 'M',
SCSI_CMD_RS_FMT_CURPOS,
0,
ior);
if (rc == SCSI_RET_SUCCESS) {
cdrom_chan_curpos_t *st;
st = (cdrom_chan_curpos_t *)tgt->cmd_ptr;
if (cmd[13] == 'M')
sprintf(buf, "MSF Position %d %d %d %d %d %d",
(integer_t)st->subQ.absolute_address.msf.minute,
(integer_t)st->subQ.absolute_address.msf.second,
(integer_t)st->subQ.absolute_address.msf.frame,
(integer_t)st->subQ.relative_address.msf.minute,
(integer_t)st->subQ.relative_address.msf.second,
(integer_t)st->subQ.relative_address.msf.frame);
else
sprintf(buf, "ABS Position %d %d", (integer_t)
(st->subQ.absolute_address.lba.lba1<<24)+
(st->subQ.absolute_address.lba.lba2<<16)+
(st->subQ.absolute_address.lba.lba3<< 8)+
st->subQ.absolute_address.lba.lba4,
(integer_t)
(st->subQ.relative_address.lba.lba1<<24)+
(st->subQ.relative_address.lba.lba2<<16)+
(st->subQ.relative_address.lba.lba3<< 8)+
st->subQ.relative_address.lba.lba4);
tgt->dev_info.cdrom.result_available = TRUE;
}
}
break;
case 'T':
/* "Get TH" */
if_it_can_do(read_toc) {
rc = scsi_read_toc(tgt, TRUE, 1, PAGE_SIZE, ior);
if (rc == SCSI_RET_SUCCESS) {
cdrom_toc_t *toc = (cdrom_toc_t *)tgt->cmd_ptr;
sprintf(buf, "toc header: %d %d %d",
(toc->len1 << 8) + toc->len2,
toc->first_track,
toc->last_track);
tgt->dev_info.cdrom.result_available = TRUE;
}
}
break;
case 'S':
/* "Get Status" */
if_it_can_do(get_status) {
rc = scsi_read_subchannel(tgt,
TRUE,
SCSI_CMD_RS_FMT_CURPOS,
0,
ior);
if (rc == SCSI_RET_SUCCESS) {
cdrom_chan_curpos_t *st;
st = (cdrom_chan_curpos_t *)tgt->cmd_ptr;
decode_status(buf, st->audio_status);
tgt->dev_info.cdrom.result_available = TRUE;
}
}
break;
}
break;
case 'P':
switch (cmd[5]) {
case 'A':
/* "Play A startM startS startF endM endS endF" */
if_it_can_do(play_msf) {
int sm, ss, sf, em, es, ef;
sscanf(&cmd[7], "%d %d %d %d %d %d",
&sm, &ss, &sf, &em, &es, &ef);
rc = scsi_play_audio_msf(tgt,
sm, ss, sf,
em, es, ef,
ior);
}
break;
case 'T':
/* "Play TI startT startI endT endI" */
if_it_can_do(play_ti) {
int st, si, et, ei;
sscanf(&cmd[8], "%d %d %d %d",
&st, &si, &et, &ei);
rc = scsi_play_audio_track_index(tgt,
st, si, et, ei, ior);
}
break;
}
break;
case 'R':
/* "Resume" */
if_it_can_do(pause_resume)
rc = scsi_pause_resume(tgt, FALSE, ior);
break;
case 'S':
switch (cmd[2]) {
case 'a':
/* "Start" */
rc = scsi_start_unit(tgt, SCSI_CMD_SS_START, ior);
break;
case 'o':
/* "Stop" */
if_it_can_do(pause_resume)
rc = scsi_pause_resume(tgt, TRUE, ior);
break;
case 't':
/* "Set V chan0vol chan1vol chan2vol chan3vol" */
if_it_can_do(volume_control) {
int v0, v1, v2, v3;
cdrom_audio_page_t au, *aup;
rc = scsi_mode_sense(tgt,
SCSI_CD_AUDIO_PAGE,
sizeof(au),
ior);
if (rc == SCSI_RET_SUCCESS) {
sscanf(&cmd[6], "%d %d %d %d",
&v0, &v1, &v2, &v3);
aup = (cdrom_audio_page_t *) tgt->cmd_ptr;
au = *aup;
/* au.h.bdesc ... */
au.vol0 = v0;
au.vol1 = v1;
au.vol2 = v2;
au.vol3 = v3;
au.imm = 1;
au.aprv = 0;
zero_ior( ior );
rc = scsi2_mode_select(tgt, FALSE,
&au, sizeof(au), ior);
}
}
break;
}
break;
case 'T':
/* "Toc MSF|ABS trackno" */
if_it_can_do(read_toc) {
int t, m;
sscanf(&cmd[8], "%d", &t);
rc = scsi_read_toc( tgt, cmd[4]=='M', t, PAGE_SIZE, ior);
if (rc == SCSI_RET_SUCCESS) {
cdrom_toc_t *toc = (cdrom_toc_t *)tgt->cmd_ptr;
sprintf(buf, "TOC from track %d:\n", t);
m = (toc->len1 << 8) + toc->len2;
m -= 4; /* header */
for (t = 0; m > 0; t++, m -= sizeof(struct cdrom_toc_desc)) {
buf += strlen(buf);
if (cmd[4] == 'M')
sprintf(buf, "%d %d %d %d %d %d\n",
toc->descs[t].control,
toc->descs[t].adr,
toc->descs[t].trackno,
(integer_t)toc->descs[t].absolute_address.msf.minute,
(integer_t)toc->descs[t].absolute_address.msf.second,
(integer_t)toc->descs[t].absolute_address.msf.frame);
else
sprintf(buf, "%d %d %d %d\n",
toc->descs[t].control,
toc->descs[t].adr,
toc->descs[t].trackno,
(toc->descs[t].absolute_address.lba.lba1<<24)+
(toc->descs[t].absolute_address.lba.lba2<<16)+
(toc->descs[t].absolute_address.lba.lba3<<8)+
toc->descs[t].absolute_address.lba.lba4);
}
tgt->dev_info.cdrom.result_available = TRUE;
}
}
break;
}
if (rc == SCSI_RET_SUCCESS)
ret = D_SUCCESS;
/* We are stateless, but.. */
if (rc == SCSI_RET_NEED_SENSE) {
zero_ior( ior );
tgt->ior = ior;
scsi_request_sense(tgt, ior, 0);
iowait(ior);
if (scsi_check_sense_data(tgt, tgt->cmd_ptr))
scsi_print_sense_data(tgt->cmd_ptr);
}
io_req_free(ior);
return ret;
}
private char st_invalid [] = "Drive would not say";
private char st_playing [] = "Playing";
private char st_paused [] = "Suspended";
private char st_complete[] = "Done playing";
private char st_error [] = "Stopped in error";
private char st_nothing [] = "Idle";
private void
decode_status(
char *buf,
unsigned char audio_status)
{
switch (audio_status) {
case SCSI_CDST_INVALID:
sprintf(buf, st_invalid); break;
case SCSI_CDST_PLAYING:
sprintf(buf, st_playing); break;
case SCSI_CDST_PAUSED:
sprintf(buf, st_paused); break;
case SCSI_CDST_COMPLETED:
sprintf(buf, st_complete); break;
case SCSI_CDST_ERROR:
sprintf(buf, st_error); break;
case SCSI_CDST_NO_STATUS:
sprintf(buf, st_nothing); break;
}
}
/* some vendor specific use this instead */
private void
decode_status_1(
char *buf,
unsigned char audio_status)
{
switch (audio_status) {
case 0: sprintf(buf, st_playing ); break;
case 1:
case 2: sprintf(buf, st_paused ); break;
case 3: sprintf(buf, st_complete ); break;
default:
sprintf(buf, "Unknown status" ); break;
}
}
private void
curse_the_vendor(
red_list_t *list,
boolean_t not_really)
{
if (not_really) return;
printf("%s\n%s\n%s\n%s\n",
"The CDROM you use is not fully SCSI-2 compliant.",
"We invite You to contact Your vendor and ask",
"that they provide You with a firmware upgrade.",
"Here is a list of some known deficiencies");
printf("Vendor: %s Product: %s.. Revision: %s..\n",
list->vendor, list->product, list->rev);
#define check(x,y,z) \
if (list->x) printf("Command code x%x %s not supported\n", y, z);
check(can_play_audio, SCSI_CMD_PLAY_AUDIO, "PLAY_AUDIO");
check(eject, SCSI_CMD_START_STOP_UNIT,
"START_STOP_UNIT, flag EJECT(0x2) in byte 5");
check(current_position, SCSI_CMD_READ_SUBCH, "READ_SUBCHANNEL");
check(read_toc, SCSI_CMD_READ_TOC, "READ_TOC");
/* check(get_status, ...); duplicate of current_position */
check(play_msf, SCSI_CMD_PLAY_AUDIO_MSF, "PLAY_AUDIO_MSF");
check(play_ti, SCSI_CMD_PLAY_AUDIO_TI, "PLAY_AUDIO_TRACK_INDEX");
check(pause_resume, SCSI_CMD_PAUSE_RESUME, "PAUSE_RESUME");
check(volume_control, SCSI_CMD_MODE_SELECT,
"MODE_SELECT, AUDIO page(0xe)");
#undef check
printf("Will work around these problems...\n");
}
/*
* Ancillaries
*/
cd_strategy(ior)
register io_req_t ior;
{
return rz_simpleq_strategy( ior, cd_start);
}
void cd_start( tgt, done)
target_info_t *tgt;
boolean_t done;
{
io_req_t ior;
ior = tgt->ior;
if (done && ior) {
tgt->ior = 0;
iodone(ior);
return;
}
panic("cd start"); /* uhu? */
}
/*
* When the hardware cannot
*/
private scsi_ret_t
op_not_supported(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
/*
* The command is not implemented, no way around it
*/
sprintf(tgt->dev_info.cdrom.result, unsupported);
tgt->dev_info.cdrom.result_available = TRUE;
return SCSI_RET_SUCCESS;
}
/****************************************/
/* Vendor Specific Operations */
/****************************************/
/* DEC RRD42 */
#define SCSI_CMD_DEC_SET_ADDRESS_FORMAT 0xc0
# define scsi_cmd_saf_fmt scsi_cmd_xfer_len_2
#define SCSI_CMD_DEC_PLAYBACK_STATUS 0xc4
typedef struct {
unsigned char xxx;
BITFIELD_2(unsigned char,
is_msf: 1,
xxx1: 7);
unsigned char data_len1;
unsigned char data_len0;
unsigned char audio_status;
BITFIELD_2(unsigned char,
control : 4,
xxx2 : 4);
cdrom_addr_t address;
BITFIELD_2(unsigned char,
chan0_select : 4,
xxx3 : 4);
unsigned char chan0_volume;
BITFIELD_2(unsigned char,
chan1_select : 4,
xxx4 : 4);
unsigned char chan1_volume;
BITFIELD_2(unsigned char,
chan2_select : 4,
xxx5 : 4);
unsigned char chan2_volume;
BITFIELD_2(unsigned char,
chan3_select : 4,
xxx6 : 4);
unsigned char chan3_volume;
} dec_playback_status_t;
#define SCSI_CMD_DEC_PLAYBACK_CONTROL 0xc9
typedef struct {
unsigned char xxx0;
BITFIELD_2(unsigned char,
fmt : 1,
xxx1 : 7);
unsigned char xxx[8];
BITFIELD_2(unsigned char,
chan0_select : 4,
xxx3 : 4);
unsigned char chan0_volume;
BITFIELD_2(unsigned char,
chan1_select : 4,
xxx4 : 4);
unsigned char chan1_volume;
BITFIELD_2(unsigned char,
chan2_select : 4,
xxx5 : 4);
unsigned char chan2_volume;
BITFIELD_2(unsigned char,
chan3_select : 4,
xxx6 : 4);
unsigned char chan3_volume;
} dec_playback_control_t;
#if 0
private scsi_ret_t
rrd42_status(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_ret_t rc;
char *buf = tgt->dev_info.cdrom.result;
scsi_command_group_2 c;
dec_playback_status_t *st;
/* We might have to specify addressing fmt */
if (cmd[4] == 'P') {
scsi_command_group_2 saf;
bzero(&saf, sizeof(saf));
saf.scsi_cmd_code = SCSI_CMD_DEC_SET_ADDRESS_FORMAT;
saf.scsi_cmd_saf_fmt = (cmd[13] == 'A') ? 0 : 1;
rc = cdrom_vendor_specific(tgt, &saf, 0, 0, 0, ior);
if (rc != SCSI_RET_SUCCESS) return rc;
zero_ior( ior );
}
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_DEC_PLAYBACK_STATUS;
c.scsi_cmd_xfer_len_2 = sizeof(*st);
rc = cdrom_vendor_specific(tgt, &c, 0, 0, sizeof(*st), ior);
if (rc != SCSI_RET_SUCCESS) return rc;
st = (dec_playback_status_t *) tgt->cmd_ptr;
if (cmd[4] == 'S')
decode_status( buf, st->audio_status+0x11 );
else {
if (st->is_msf)
sprintf(buf, "MSF Position %d %d %d",
(integer_t)st->address.msf.minute,
(integer_t)st->address.msf.second,
(integer_t)st->address.msf.frame);
else
sprintf(buf, "ABS Position %d", (integer_t)
(st->address.lba.lba1<<24)+
(st->address.lba.lba2<<16)+
(st->address.lba.lba3<< 8)+
st->address.lba.lba4);
}
tgt->dev_info.cdrom.result_available = TRUE;
return rc;
}
#endif
private scsi_ret_t
rrd42_set_volume(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
dec_playback_control_t req;
int v0, v1, v2, v3;
sscanf(&cmd[6], "%d %d %d %d", &v0, &v1, &v2, &v3);
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_DEC_PLAYBACK_CONTROL;
c.scsi_cmd_xfer_len_2 = sizeof(req);
bzero(&req, sizeof(req));
if (v0) {
req.chan0_select = 1;
req.chan0_volume = v0;
}
if (v1) {
req.chan1_select = 2;
req.chan1_volume = v1;
}
if (v2) {
req.chan2_select = 4;
req.chan2_volume = v2;
}
if (v3) {
req.chan3_select = 8;
req.chan3_volume = v3;
}
return cdrom_vendor_specific(tgt, &c, &req, sizeof(req), 0, ior);
}
/* NEC CD-ROM */
#define SCSI_CMD_NEC_READ_TOC 0xde
typedef struct {
unsigned char xxx[9];
unsigned char first_track;
unsigned char xxx1[9];
unsigned char last_track;
unsigned char xxx2[9];
unsigned char lead_out_addr[3];
struct {
BITFIELD_2(unsigned char,
adr : 4,
ctrl : 4);
unsigned char xxx3[6];
unsigned char address[3];
} track_info[1]; /* VARSIZE */
} nec_toc_data_t;
#define SCSI_CMD_NEC_SEEK_TRK 0xd8
#define SCSI_CMD_NEC_PLAY_AUDIO 0xd9
#define SCSI_CMD_NEC_PAUSE 0xda
#define SCSI_CMD_NEC_EJECT 0xdc
#define SCSI_CMD_NEC_READ_SUBCH_Q 0xdd
typedef struct {
unsigned char audio_status; /* see decode_status_1 */
BITFIELD_2(unsigned char,
ctrl : 4,
xxx1 : 4);
unsigned char trackno;
unsigned char indexno;
unsigned char relative_address[3];
unsigned char absolute_address[3];
} nec_subch_data_t;
/*
* Reserved bits in byte1
*/
#define NEC_LR_PLAY_MODE 0x01 /* RelAdr bit overload */
#define NEC_LR_STEREO 0x02 /* mono/stereo */
/*
* Vendor specific bits in the control byte.
* NEC uses them to specify the addressing mode
*/
#define NEC_CTRL_A_ABS 0x00 /* XXX not sure about this */
#define NEC_CTRL_A_MSF 0x40 /* min/sec/frame */
#define NEC_CTRL_A_TI 0x80 /* track/index */
#define NEC_CTRL_A_CURRENT 0xc0 /* same as last specified */
private scsi_ret_t
nec_eject(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_NEC_EJECT;
return cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
}
private scsi_ret_t
nec_subchannel(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
nec_subch_data_t *st;
char *buf = tgt->dev_info.cdrom.result;
scsi_ret_t rc;
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_NEC_READ_SUBCH_Q;
c.scsi_cmd_lun_and_relbit = sizeof(*st); /* Sic! */
rc = cdrom_vendor_specific(tgt, &c, 0, 0, sizeof(*st), ior);
if (rc != SCSI_RET_SUCCESS) return rc;
st = (nec_subch_data_t *) tgt->cmd_ptr;
/* Status or Position ? */
if (cmd[4] == 'S') {
decode_status_1( buf, st->audio_status);
} else {
/* XXX can it do ABS addressing e.g. 'logical' ? */
sprintf(buf, "MSF Position %d %d %d %d %d %d",
(integer_t)bcd_to_decimal(st->absolute_address[0]), /* min */
(integer_t)bcd_to_decimal(st->absolute_address[1]), /* sec */
(integer_t)bcd_to_decimal(st->absolute_address[2]), /* frm */
(integer_t)bcd_to_decimal(st->relative_address[0]), /* min */
(integer_t)bcd_to_decimal(st->relative_address[1]), /* sec */
(integer_t)bcd_to_decimal(st->relative_address[2])); /* frm */
}
tgt->dev_info.cdrom.result_available = TRUE;
return SCSI_RET_SUCCESS;
}
private scsi_ret_t
nec_read_toc(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
nec_toc_data_t *t;
char *buf = tgt->dev_info.cdrom.result;
scsi_ret_t rc;
int first, last, i;
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_NEC_READ_TOC;
c.scsi_cmd_lun_and_relbit = NEC_LR_PLAY_MODE|NEC_LR_STEREO;
rc = cdrom_vendor_specific(tgt, &c, 0, 0, 512/*XXX*/, ior);
if (rc != SCSI_RET_SUCCESS) return rc;
t = (nec_toc_data_t *) tgt->cmd_ptr;
first = bcd_to_decimal(t->first_track);
last = bcd_to_decimal(t->last_track);
/*
* "Get TH" wants summary, "TOC MSF|ABS from_track" wants all
*/
if (cmd[0] == 'G') {
sprintf(buf, "toc header: %d %d %d",
sizeof(*t) + sizeof(t->track_info) * (last - first - 1),
first, last);
goto out;
}
/*
* The whole shebang
*/
sscanf(&cmd[8], "%d", &i);
sprintf(buf, "TOC from track %d:\n", i);
last -= first;
i -= first;
while ((i >= 0) && (i <= last)) {
buf += strlen(buf);
if (cmd[4] == 'M')
sprintf(buf, "%d %d %d %d %d %d\n",
t->track_info[i].ctrl,
t->track_info[i].adr,
first + i,
bcd_to_decimal(t->track_info[i].address[0]),
bcd_to_decimal(t->track_info[i].address[1]),
bcd_to_decimal(t->track_info[i].address[2]));
else
/* THIS IS WRONG */
sprintf(buf, "%d %d %d %d\n",
t->track_info[i].ctrl,
t->track_info[i].adr,
first + i,
bcd_to_decimal(t->track_info[i].address[0]) * 10000 +
bcd_to_decimal(t->track_info[i].address[1]) * 100 +
bcd_to_decimal(t->track_info[i].address[2]));
i++;
}
/* To know how long the last track is */
buf += strlen(buf);
if (cmd[4] == 'M')
sprintf(buf, "%d %d %d %d %d %d\n",
0, 1, 0xaa /* User expects this */,
bcd_to_decimal(t->lead_out_addr[0]),
bcd_to_decimal(t->lead_out_addr[1]),
bcd_to_decimal(t->lead_out_addr[2]));
else
/* THIS IS WRONG */
sprintf(buf, "%d %d %d %d\n",
0, 1, 0xaa /* User expects this */,
bcd_to_decimal(t->lead_out_addr[0]) * 10000 +
bcd_to_decimal(t->lead_out_addr[1]) * 100 +
bcd_to_decimal(t->lead_out_addr[2]));
out:
tgt->dev_info.cdrom.result_available = TRUE;
return SCSI_RET_SUCCESS;
}
private scsi_ret_t
nec_play(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
int sm, ss, sf, em, es, ef;
int st, si, et, ei;
scsi_ret_t rc;
/*
* Seek to desired position
*/
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_NEC_SEEK_TRK;
c.scsi_cmd_lun_and_relbit = NEC_LR_PLAY_MODE;
/*
* Play_msf or Play_ti
*/
if (cmd[5] == 'A') {
/* "Play A startM startS startF endM endS endF" */
sscanf(&cmd[7], "%d %d %d %d %d %d",
&sm, &ss, &sf, &em, &es, &ef);
c.scsi_cmd_lba1 = decimal_to_bcd(sm);
c.scsi_cmd_lba2 = decimal_to_bcd(ss);
c.scsi_cmd_lba3 = decimal_to_bcd(sf);
c.scsi_cmd_ctrl_byte = NEC_CTRL_A_MSF;
} else {
/* "Play TI startT startI endT endI" */
sscanf(&cmd[8], "%d %d %d %d", &st, &si, &et, &ei);
c.scsi_cmd_lba1 = decimal_to_bcd(st);
c.scsi_cmd_lba2 = decimal_to_bcd(si);
c.scsi_cmd_lba3 = 0;
c.scsi_cmd_ctrl_byte = NEC_CTRL_A_TI;
}
rc = cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
if (rc != SCSI_RET_SUCCESS) return rc;
/*
* Now ask it to play until..
*/
zero_ior( ior );
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_NEC_PLAY_AUDIO;
c.scsi_cmd_lun_and_relbit = NEC_LR_PLAY_MODE|NEC_LR_STEREO;
if (cmd[5] == 'A') {
c.scsi_cmd_lba1 = decimal_to_bcd(em);
c.scsi_cmd_lba2 = decimal_to_bcd(es);
c.scsi_cmd_lba3 = decimal_to_bcd(ef);
c.scsi_cmd_ctrl_byte = NEC_CTRL_A_MSF;
} else {
c.scsi_cmd_lba1 = decimal_to_bcd(et);
c.scsi_cmd_lba2 = decimal_to_bcd(ei);
c.scsi_cmd_lba3 = 0;
c.scsi_cmd_ctrl_byte = NEC_CTRL_A_TI;
}
return cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
}
private scsi_ret_t
nec_pause_resume(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
bzero(&c, sizeof(c));
/*
* "Resume" or "Stop"
*/
if (cmd[0] == 'R') {
c.scsi_cmd_code = SCSI_CMD_NEC_PLAY_AUDIO;
c.scsi_cmd_lun_and_relbit = NEC_LR_PLAY_MODE|NEC_LR_STEREO;
c.scsi_cmd_ctrl_byte = NEC_CTRL_A_CURRENT;
} else {
c.scsi_cmd_code = SCSI_CMD_NEC_PAUSE;
}
return cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
}
/* TOSHIBA CD-ROM DRIVE:XM 3232 */
#define SCSI_CMD_TOSHIBA_SEEK_TRK 0xc0
#define SCSI_CMD_TOSHIBA_PLAY_AUDIO 0xc1
#define SCSI_CMD_TOSHIBA_PAUSE_AUDIO 0xc2
#define SCSI_CMD_TOSHIBA_EJECT 0xc4
#define SCSI_CMD_TOSHIBA_READ_SUBCH_Q 0xc6
typedef nec_subch_data_t toshiba_subch_data_t;
/* audio status -> decode_status_1 */
#define SCSI_CMD_TOSHIBA_READ_TOC_ENTRY 0xc7
typedef struct {
unsigned char first_track;
unsigned char last_track;
unsigned char xxx[2];
} toshiba_toc_header_t;
typedef struct {
unsigned char address[4];
} toshiba_toc_data_t;
private scsi_ret_t
toshiba_eject(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_TOSHIBA_EJECT;
return cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
}
private scsi_ret_t
toshiba_subchannel(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
toshiba_subch_data_t *st;
char *buf = tgt->dev_info.cdrom.result;
scsi_ret_t rc;
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_TOSHIBA_READ_SUBCH_Q;
c.scsi_cmd_lun_and_relbit = sizeof(*st); /* Sic! */
rc = cdrom_vendor_specific(tgt, &c, 0, 0, sizeof(*st), ior);
if (rc != SCSI_RET_SUCCESS) return rc;
st = (toshiba_subch_data_t *) tgt->cmd_ptr;
/* Status or Position ? */
if (cmd[4] == 'S') {
decode_status_1( buf, st->audio_status);
} else {
/* XXX can it do ABS addressing e.g. 'logical' ? */
sprintf(buf, "MSF Position %d %d %d %d %d %d",
(integer_t)bcd_to_decimal(st->absolute_address[0]), /* min */
(integer_t)bcd_to_decimal(st->absolute_address[1]), /* sec */
(integer_t)bcd_to_decimal(st->absolute_address[2]), /* frm */
(integer_t)bcd_to_decimal(st->relative_address[0]), /* min */
(integer_t)bcd_to_decimal(st->relative_address[1]), /* sec */
(integer_t)bcd_to_decimal(st->relative_address[2])); /* frm */
}
tgt->dev_info.cdrom.result_available = TRUE;
return SCSI_RET_SUCCESS;
}
private scsi_ret_t
toshiba_read_toc(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
toshiba_toc_data_t *t;
toshiba_toc_header_t *th;
char *buf = tgt->dev_info.cdrom.result;
scsi_ret_t rc;
int first, last, i;
/* TOC header first */
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_TOSHIBA_READ_TOC_ENTRY;
c.scsi_cmd_lun_and_relbit = 0;
c.scsi_cmd_lba1 = 0;
rc = cdrom_vendor_specific(tgt, &c, 0, 0, sizeof(*th), ior);
if (rc != SCSI_RET_SUCCESS) return rc;
th = (toshiba_toc_header_t *) tgt->cmd_ptr;
first = bcd_to_decimal(th->first_track);
last = bcd_to_decimal(th->last_track);
/*
* "Get TH" wants summary, "TOC MSF|ABS from_track" wants all
*/
if (cmd[0] == 'G') {
sprintf(buf, "toc header: %d %d %d",
sizeof(*th) + sizeof(*t) * (last - first + 1),
first, last);
goto out;
}
/*
* The whole shebang
*/
sscanf(&cmd[8], "%d", &i);
sprintf(buf, "TOC from track %d:\n", i);
while (i <= last) {
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_TOSHIBA_READ_TOC_ENTRY;
c.scsi_cmd_lun_and_relbit = 2;
c.scsi_cmd_lba1 = decimal_to_bcd(i);
zero_ior( ior );
rc = cdrom_vendor_specific(tgt, &c, 0, 0, sizeof(*t), ior);
if (rc != SCSI_RET_SUCCESS) break;
t = (toshiba_toc_data_t *) tgt->cmd_ptr;
buf += strlen(buf);
if (cmd[4] == 'M')
sprintf(buf, "0 0 %d %d %d %d\n",
i,
bcd_to_decimal(t->address[0]),
bcd_to_decimal(t->address[1]),
bcd_to_decimal(t->address[2]));
else
/* THIS IS WRONG */
sprintf(buf, "0 0 %d %d\n",
i,
bcd_to_decimal(t->address[0]) * 10000 +
bcd_to_decimal(t->address[1]) * 100 +
bcd_to_decimal(t->address[2]));
i++;
}
/* Must simulate the lead-out track */
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_TOSHIBA_READ_TOC_ENTRY;
c.scsi_cmd_lun_and_relbit = 1;
c.scsi_cmd_lba1 = 0;
zero_ior( ior );
rc = cdrom_vendor_specific(tgt, &c, 0, 0, sizeof(*t), ior);
if (rc != SCSI_RET_SUCCESS) goto out;
t = (toshiba_toc_data_t *) tgt->cmd_ptr;
buf += strlen(buf);
if (cmd[4] == 'M')
sprintf(buf, "0 0 %d %d %d %d\n",
i,
bcd_to_decimal(t->address[0]),
bcd_to_decimal(t->address[1]),
bcd_to_decimal(t->address[2]));
else
/* THIS IS WRONG */
sprintf(buf, "0 0 %d %d\n",
i,
bcd_to_decimal(t->address[0]) * 10000 +
bcd_to_decimal(t->address[1]) * 100 +
bcd_to_decimal(t->address[2]));
i++;
out:
tgt->dev_info.cdrom.result_available = TRUE;
return SCSI_RET_SUCCESS;
}
private scsi_ret_t
toshiba_play(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
int sm, ss, sf, em, es, ef;
int st, si, et, ei;
scsi_ret_t rc;
/*
* Seek to desired position
*/
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_TOSHIBA_SEEK_TRK;
/*
* Play_msf or Play_ti
*/
if (cmd[5] == 'A') {
/* "Play A startM startS startF endM endS endF" */
sscanf(&cmd[7], "%d %d %d %d %d %d",
&sm, &ss, &sf, &em, &es, &ef);
c.scsi_cmd_lba1 = decimal_to_bcd(sm);
c.scsi_cmd_lba2 = decimal_to_bcd(ss);
c.scsi_cmd_lba3 = decimal_to_bcd(sf);
c.scsi_cmd_ctrl_byte = NEC_CTRL_A_MSF;
} else {
/* "Play TI startT startI endT endI" */
sscanf(&cmd[8], "%d %d %d %d", &st, &si, &et, &ei);
c.scsi_cmd_lba1 = decimal_to_bcd(st);
c.scsi_cmd_lba2 = decimal_to_bcd(si);
c.scsi_cmd_lba3 = 0;
c.scsi_cmd_ctrl_byte = NEC_CTRL_A_TI;
}
rc = cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
if (rc != SCSI_RET_SUCCESS) return rc;
/*
* Now ask it to play until..
*/
zero_ior( ior );
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_TOSHIBA_PLAY_AUDIO;
c.scsi_cmd_lun_and_relbit = NEC_LR_PLAY_MODE|NEC_LR_STEREO;
if (cmd[5] == 'A') {
c.scsi_cmd_lba1 = decimal_to_bcd(em);
c.scsi_cmd_lba2 = decimal_to_bcd(es);
c.scsi_cmd_lba3 = decimal_to_bcd(ef);
c.scsi_cmd_ctrl_byte = NEC_CTRL_A_MSF;
} else {
c.scsi_cmd_lba1 = decimal_to_bcd(et);
c.scsi_cmd_lba2 = decimal_to_bcd(ei);
c.scsi_cmd_lba3 = 0;
c.scsi_cmd_ctrl_byte = NEC_CTRL_A_TI;
}
return cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
}
private scsi_ret_t
toshiba_pause_resume(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
bzero(&c, sizeof(c));
/*
* "Resume" or "Stop"
*/
if (cmd[0] == 'R') {
/* ???? would have to remember last cmd ???? */
/* broken ! */
c.scsi_cmd_code = SCSI_CMD_TOSHIBA_PLAY_AUDIO;
c.scsi_cmd_lun_and_relbit = NEC_LR_PLAY_MODE|NEC_LR_STEREO;
c.scsi_cmd_ctrl_byte = NEC_CTRL_A_CURRENT;
} else {
c.scsi_cmd_code = SCSI_CMD_TOSHIBA_PAUSE_AUDIO;
}
return cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
}
#if 0
/* I have info on these drives, but no drive to test */
/* PIONEER DRM-600 */
#define SCSI_CMD_PIONEER_EJECT 0xc0
#define SCSI_CMD_PIONEER_READ_TOC 0xc1
typedef struct {
unsigned char first_track;
unsigned char last_track;
unsigned char xxx[2];
} pioneer_toc_hdr_t;
typedef struct {
unsigned char ctrl;
unsigned char address[3];
} pioneer_toc_info_t;
#define SCSI_CMD_PIONEER_READ_SUBCH 0xc2
typedef struct {
BITFIELD_2(unsigned char,
ctrl : 4,
xxx1 : 4);
unsigned char trackno;
unsigned char indexno;
unsigned char relative_address[3];
unsigned char absolute_address[3];
} pioneer_subch_data_t;
#define SCSI_CMD_PIONEER_SEEK_TRK 0xc8
#define SCSI_CMD_PIONEER_PLAY_AUDIO 0xc9
#define SCSI_CMD_PIONEER_PAUSE 0xca
#define SCSI_CMD_PIONEER_AUDIO_STATUS 0xcc
typedef struct {
unsigned char audio_status;
unsigned char xxx[5];
} pioneer_status_t;
/*
* Reserved bits in byte1
*/
#define PIONEER_LR_END_ADDR 0x10
#define PIONEER_LR_PAUSE 0x10
#define PIONEER_LR_RESUME 0x00
/*
* Vendor specific bits in the control byte.
*/
#define PIONEER_CTRL_TH 0x00 /* TOC header */
#define PIONEER_CTRL_TE 0x80 /* one TOC entry */
#define PIONEER_CTRL_LO 0x40 /* lead-out track info */
#define PIONEER_CTRL_A_MSF 0x40 /* min/sec/frame addr */
private scsi_ret_t
pioneer_eject(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_PIONEER_EJECT;
return cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
}
private scsi_ret_t
pioneer_position(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
scsi_ret_t rc;
char *buf = tgt->dev_info.cdrom.result;
pioneer_subch_data_t *st;
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_PIONEER_READ_SUBCH;
c.scsi_cmd_xfer_len_2 = sizeof(pioneer_subch_data_t); /* 9 bytes */
rc = cdrom_vendor_specific(tgt, &c, 0, 0, sizeof(pioneer_subch_data_t), ior);
if (rc != SCSI_RET_SUCCESS) return rc;
st = (pioneer_subch_data_t *) tgt->cmd_ptr;
/* XXX can it do ABS addressing e.g. 'logical' ? */
sprintf(buf, "MSF Position %d %d %d %d %d %d",
(integer_t)bcd_to_decimal(st->absolute_address[0]), /* min */
(integer_t)bcd_to_decimal(st->absolute_address[1]), /* sec */
(integer_t)bcd_to_decimal(st->absolute_address[2]), /* frm */
(integer_t)bcd_to_decimal(st->relative_address[0]), /* min */
(integer_t)bcd_to_decimal(st->relative_address[1]), /* sec */
(integer_t)bcd_to_decimal(st->relative_address[2])); /* frm */
tgt->dev_info.cdrom.result_available = TRUE;
return SCSI_RET_SUCCESS;
}
private scsi_ret_t
pioneer_toc(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
pioneer_toc_hdr_t *th;
pioneer_toc_info_t *t;
char *buf = tgt->dev_info.cdrom.result;
scsi_ret_t rc;
int first, last, i;
/* Read header first */
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_PIONEER_READ_TOC;
c.scsi_cmd_xfer_len_2 = sizeof(pioneer_toc_hdr_t);
c.scsi_cmd_ctrl_byte = PIONEER_CTRL_TH;
rc = cdrom_vendor_specific(tgt, &c, 0, 0, sizeof(pioneer_toc_hdr_t), ior);
if (rc != SCSI_RET_SUCCESS) return rc;
th = (pioneer_toc_hdr_t *)tgt->cmd_ptr;
first = bcd_to_decimal(th->first_track);
last = bcd_to_decimal(th->last_track);
/*
* "Get TH" wants summary, "TOC MSF|ABS from_track" wants all
*/
if (cmd[0] == 'G') {
sprintf(buf, "toc header: %d %d %d", 0, first, last);
goto out;
}
/*
* Must do it one track at a time
*/
sscanf(&cmd[8], "%d", &i);
sprintf(buf, "TOC from track %d:\n", i);
for ( ; i <= last; i++) {
zero_ior(ior);
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_PIONEER_READ_TOC;
c.scsi_cmd_lba4 = decimal_to_bcd(i);
c.scsi_cmd_xfer_len_2 = sizeof(pioneer_toc_info_t);
c.scsi_cmd_ctrl_byte = PIONEER_CTRL_TE;
rc = cdrom_vendor_specific(tgt, &c, 0, 0, sizeof(pioneer_toc_info_t), ior);
if (rc != SCSI_RET_SUCCESS) break;
t = (pioneer_toc_info_t *)tgt->cmd_ptr;
buf += strlen(buf);
if (cmd[4] == 'M')
sprintf(buf, "%d %d %d %d %d %d\n",
t->ctrl, 0, i,
bcd_to_decimal(t->address[0]),
bcd_to_decimal(t->address[1]),
bcd_to_decimal(t->address[2]));
else
/* THIS IS WRONG */
sprintf(buf, "%d %d %d %d\n",
t->ctrl, 0, i,
bcd_to_decimal(t->address[0]) * 10000 +
bcd_to_decimal(t->address[1]) * 100 +
bcd_to_decimal(t->address[2]));
}
/* To know how long the last track is */
zero_ior(ior);
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_PIONEER_READ_TOC;
c.scsi_cmd_xfer_len_2 = sizeof(pioneer_toc_info_t);
c.scsi_cmd_ctrl_byte = PIONEER_CTRL_LO;
rc = cdrom_vendor_specific(tgt, &c, 0, 0, sizeof(pioneer_toc_info_t), ior);
if (rc != SCSI_RET_SUCCESS) return rc;
buf += strlen(buf);
t = (pioneer_toc_info_t *)tgt->cmd_ptr;
if (cmd[4] == 'M')
sprintf(buf, "%d %d %d %d %d %d\n",
t->ctrl, 0, 0xaa /* User expects this */,
bcd_to_decimal(t->address[0]),
bcd_to_decimal(t->address[1]),
bcd_to_decimal(t->address[2]));
else
/* THIS IS WRONG */
sprintf(buf, "%d %d %d %d\n",
t->ctrl, 0, 0xaa /* User expects this */,
bcd_to_decimal(t->address[0]) * 10000 +
bcd_to_decimal(t->address[1]) * 100 +
bcd_to_decimal(t->address[2]));
out:
tgt->dev_info.cdrom.result_available = TRUE;
return SCSI_RET_SUCCESS;
}
private scsi_ret_t
pioneer_status(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
pioneer_status_t *st;
char *buf = tgt->dev_info.cdrom.result;
scsi_ret_t rc;
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_PIONEER_AUDIO_STATUS;
c.scsi_cmd_xfer_len_2 = sizeof(pioneer_status_t); /* 6 bytes */
rc = cdrom_vendor_specific(tgt, &c, 0, 0, sizeof(pioneer_status_t), ior);
if (rc != SCSI_RET_SUCCESS) return rc;
st = (pioneer_status_t*) tgt->cmd_ptr;
decode_status_1( buf, st->audio_status);
tgt->dev_info.cdrom.result_available = TRUE;
return SCSI_RET_SUCCESS;
}
private scsi_ret_t
pioneer_play(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
int sm, ss, sf, em, es, ef;
int st, si, et, ei;
scsi_ret_t rc;
/*
* Seek to desired position
*/
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_PIONEER_SEEK_TRK;
/*
* Play_msf or Play_ti
*/
if (cmd[5] == 'A') {
/* "Play A startM startS startF endM endS endF" */
sscanf(&cmd[7], "%d %d %d %d %d %d",
&sm, &ss, &sf, &em, &es, &ef);
c.scsi_cmd_lba2 = decimal_to_bcd(sm);
c.scsi_cmd_lba3 = decimal_to_bcd(ss);
c.scsi_cmd_lba4 = decimal_to_bcd(sf);
c.scsi_cmd_ctrl_byte = PIONEER_CTRL_A_MSF;
} else {
/* "Play TI startT startI endT endI" */
sscanf(&cmd[8], "%d %d %d %d", &st, &si, &et, &ei);
c.scsi_cmd_lba3 = decimal_to_bcd(st);
c.scsi_cmd_lba4 = decimal_to_bcd(si);
c.scsi_cmd_ctrl_byte = 0x80; /* Pure speculation!! */
}
rc = cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
if (rc != SCSI_RET_SUCCESS) return rc;
/*
* Now ask it to play until..
*/
zero_ior( ior );
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_PIONEER_PLAY_AUDIO;
c.scsi_cmd_lun_and_relbit = PIONEER_LR_END_ADDR;
if (cmd[5] == 'A') {
c.scsi_cmd_lba2 = decimal_to_bcd(em);
c.scsi_cmd_lba3 = decimal_to_bcd(es);
c.scsi_cmd_lba4 = decimal_to_bcd(ef);
c.scsi_cmd_ctrl_byte = PIONEER_CTRL_A_MSF;
} else {
c.scsi_cmd_lba3 = decimal_to_bcd(et);
c.scsi_cmd_lba4 = decimal_to_bcd(ei);
c.scsi_cmd_ctrl_byte = 0x80; /* Pure speculation! */
}
return cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
}
private scsi_ret_t
pioneer_pause_resume(
target_info_t *tgt,
char *cmd,
io_req_t ior)
{
scsi_command_group_2 c;
bzero(&c, sizeof(c));
c.scsi_cmd_code = SCSI_CMD_PIONEER_PAUSE;
/*
* "Resume" or "Stop"
*/
if (cmd[0] == 'S')
c.scsi_cmd_lun_and_relbit = PIONEER_LR_PAUSE;
else
c.scsi_cmd_lun_and_relbit = PIONEER_LR_RESUME;
return cdrom_vendor_specific(tgt, &c, 0, 0, 0, ior);
}
/* DENON DRD-253 */
#define SCSI_CMD_DENON_PLAY_AUDIO 0x22
#define SCSI_CMD_DENON_EJECT 0xe6
#define SCSI_CMD_DENON_PAUSE_AUDIO 0xe7
#define SCSI_CMD_DENON_READ_TOC 0xe9
#define SCSI_CMD_DENON_READ_SUBCH 0xeb
/* HITACHI 1750 */
#define SCSI_CMD_HITACHI_PLAY_AUDIO_MSF 0xe0
#define SCSI_CMD_HITACHI_PAUSE_AUDIO 0xe1
#define SCSI_CMD_HITACHI_EJECT 0xe4
#define SCSI_CMD_HITACHI_READ_SUBCH 0xe5
#define SCSI_CMD_HITACHI_READ_TOC 0xe8
#endif
/*
* Tabulate all of the above
*/
private red_list_t cdrom_exceptions[] = {
#if 0
For documentation purposes, here are some SCSI-2 compliant drives:
Vendor Product Rev Comments
"SONY " "CD-ROMCDU-541 " "2.6a" The NeXT drive
#endif
/* vendor, product, rev */
/* can_play_audio */
/* eject */
/* current_position */
/* read_toc */
/* get_status */
/* play_msf */
/* play_ti */
/* pause_resume */
/* volume_control */
/* We have seen a "RRD42(C)DEC " "4.5d" */
{ "DEC ", "RRD42", "",
0, 0, 0, 0, 0, 0, 0, 0, rrd42_set_volume },
/* We have seen a "CD-ROM DRIVE:84 " "1.0 " */
{ "NEC ", "CD-ROM DRIVE:84", "",
op_not_supported, nec_eject, nec_subchannel, nec_read_toc,
nec_subchannel, nec_play, nec_play, nec_pause_resume,
op_not_supported },
/* We have seen a "CD-ROM DRIVE:XM " "3232" */
{ "TOSHIBA ", "CD-ROM DRIVE:XM", "32",
op_not_supported, toshiba_eject, toshiba_subchannel, toshiba_read_toc,
toshiba_subchannel, toshiba_play, toshiba_play, toshiba_pause_resume,
op_not_supported },
{ "TOSHIBA ", "CD-ROM DRIVE:XM", "33",
op_not_supported, toshiba_eject, toshiba_subchannel, toshiba_read_toc,
toshiba_subchannel, toshiba_play, toshiba_play, toshiba_pause_resume,
op_not_supported },
#if 0
{ "PIONEER ", "???????DRM-6", "",
op_not_supported, pioneer_eject, pioneer_position, pioneer_toc,
pioneer_status, pioneer_play, pioneer_play, pioneer_pause_resume,
op_not_supported },
{ "DENON ", "DRD 25X", "", ...},
{ "HITACHI ", "CDR 1750S", "", ...},
{ "HITACHI ", "CDR 1650S", "", ...},
{ "HITACHI ", "CDR 3650", "", ...},
#endif
/* Zero terminate this list */
{ 0, }
};
private void
check_red_list(
target_info_t *tgt,
scsi2_inquiry_data_t *inq)
{
red_list_t *list;
for (list = &cdrom_exceptions[0]; list->vendor; list++) {
/*
* Prefix-Match all strings
*/
if ((strncmp(list->vendor, (const char *)inq->vendor_id,
strlen(list->vendor)) == 0) &&
(strncmp(list->product, (const char *)inq->product_id,
strlen(list->product)) == 0) &&
(strncmp(list->rev, (const char *)inq->product_rev,
strlen(list->rev)) == 0)) {
/*
* One of them..
*/
if (tgt->dev_info.cdrom.violates_standards != list) {
tgt->dev_info.cdrom.violates_standards = list;
curse_the_vendor( list, TRUE );
}
return;
}
}
}
#endif /* NSCSI > 0 */
|