Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

683 lines
15 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1992 - 1999
  3. --*/
  4. #if DBG
  5. //
  6. // CdAudio debug level global variable
  7. //
  8. ULONG CdAudioDebug = 0;
  9. //
  10. // Remap CdDump to local routine
  11. //
  12. #define CdDump(X) CdAudioDebugPrint X
  13. VOID
  14. CdAudioDebugPrint(
  15. ULONG DebugPrintLevel,
  16. PCCHAR DebugMessage,
  17. ...
  18. );
  19. #else
  20. #define CdDump(X)
  21. #endif // DBG
  22. #define CDAUDIO_NOT_ACTIVE 0
  23. #define CDAUDIO_ATAPI 1
  24. #define CDAUDIO_CDS535 2
  25. #define CDAUDIO_CDS435 3
  26. #define CDAUDIO_DENON 4
  27. #define CDAUDIO_FUJITSU 5
  28. #define CDAUDIO_HITACHI 6
  29. #define CDAUDIO_HPCDR 7
  30. #define CDAUDIO_NEC 8
  31. #define CDAUDIO_PIONEER 9
  32. #define CDAUDIO_PIONEER624 10
  33. #define CDAUDIO_MAX_ACTIVE 10
  34. //
  35. // Registry values...
  36. //
  37. #define CDAUDIO_SEARCH_ACTIVE 0xFF
  38. #define CDAUDIO_ACTIVE_KEY_NAME (L"MapType")
  39. #define CDAUDIO_NOT_PAUSED 0
  40. #define CDAUDIO_PAUSED 1
  41. //
  42. // Device Extension
  43. //
  44. typedef struct _CD_DEVICE_EXTENSION {
  45. //
  46. // Target Device Object
  47. //
  48. PDEVICE_OBJECT TargetDeviceObject;
  49. //
  50. // Physical Device Object
  51. //
  52. PDEVICE_OBJECT TargetPdo;
  53. //
  54. // Back pointer to device object
  55. //
  56. PDEVICE_OBJECT DeviceObject;
  57. //
  58. // paging path count
  59. //
  60. ULONG PagingPathCount;
  61. KEVENT PagingPathCountEvent;
  62. //
  63. // A timer, DPC, and simple
  64. // synchronization to assert
  65. // on if non-serialized.
  66. //
  67. PRKDPC Dpc;
  68. PKTIMER Timer;
  69. LONG Sync;
  70. //
  71. // CdAudio active for this drive
  72. //
  73. UCHAR Active;
  74. //
  75. // For drives that don't support
  76. // PAUSE/RESUME (Denon), a flag
  77. // to signify when the drive is
  78. // paused.
  79. //
  80. UCHAR Paused;
  81. //
  82. // For drives that don't support
  83. // PAUSE/RESUME (Denon), this is the
  84. // current position on the disc when
  85. // a pause was last executed. This is
  86. // stored in either BCD or binary,
  87. // depending on the drive.
  88. //
  89. UCHAR PausedM;
  90. UCHAR PausedS;
  91. UCHAR PausedF;
  92. //
  93. // For drives that don't support
  94. // PAUSE/RESUME (Denon), this is the
  95. // last "ending" position on the disc when
  96. // a play was last executed. This is
  97. // stored in BCD or binary, depending on
  98. // the drive.
  99. //
  100. UCHAR LastEndM;
  101. UCHAR LastEndS;
  102. UCHAR LastEndF;
  103. //
  104. // Indicates the CD is currently playing music.
  105. //
  106. BOOLEAN PlayActive;
  107. } CD_DEVICE_EXTENSION, *PCD_DEVICE_EXTENSION;
  108. #define AUDIO_TIMEOUT 10
  109. #define CD_DEVICE_EXTENSION_SIZE sizeof(CD_DEVICE_EXTENSION)
  110. #define MAXIMUM_RETRIES 4
  111. //
  112. // Convert BCD character to decimal equivalent
  113. //
  114. #define BCD_TO_DEC(x) ((((x & 0xF0)>>4)*10) + (x & 0x0F))
  115. #define DEC_TO_BCD(x) (((x / 10) << 4) + (x % 10))
  116. //
  117. // Defines for NEC CDR cdrom drives
  118. //
  119. #define NEC_READ_TOC_CODE 0xDE
  120. #define NEC_AUDIO_TRACK_SEARCH_CODE 0xD8
  121. #define NEC_PLAY_AUDIO_CODE 0xD9
  122. #define NEC_STILL_CODE 0xDA
  123. #define NEC_EJECT_CODE 0xDC
  124. #define NEC_READ_SUB_Q_CHANNEL_CODE 0xDD
  125. #define NEC_Q_CHANNEL_TRANSFER_SIZE 10
  126. #define NEC_ENTER_PLAY_MODE 0x01
  127. #define NEC_TYPE_LOGICAL 0x00
  128. #define NEC_TYPE_ATIME 0x40
  129. #define NEC_TYPE_TRACK_NUMBER 0x80
  130. #define NEC_TYPE_NO_CHANGE 0xC0
  131. #define NEC_PLAY_STEREO 0x03
  132. #define NEC_TRANSFER_WHOLE_TOC 0x03
  133. #define NEC_TOC_TYPE_DISK 0xA0
  134. #define NEC_TOC_TYPE_SESSION 0xB0
  135. //
  136. // The NEC cdrom TOC size is:
  137. // 2 bytes for size
  138. // 10 bytes first track data
  139. // 10 bytes last track data
  140. // 10 bytes total disk data
  141. // 10 bytes per track 99 track maximum.
  142. //
  143. #define NEC_CDROM_TOC_SIZE 1022
  144. //
  145. // NEC SENSE CODES
  146. //
  147. #define NEC_SCSI_ERROR_NO_DISC 0x0B
  148. #define NEC_SCSI_ERROR_ILLEGAL_DISC 0x0C
  149. #define NEC_SCSI_ERROR_TRAY_OPEN 0x0D
  150. #define NEC_SCSI_ERROR_SEEK_ERROR 0x15
  151. #define NEC_SCSI_ERROR_MUSIC_AREA 0x1D
  152. #define NEC_SCSI_ERROR_DATA_AREA 0x1C
  153. #define NEC_SCSI_ERROR_PARITY_ERROR 0x30
  154. #define NEC_SCSI_ERROR_INVALID_COMMAND 0x20
  155. #define NEC_SCSI_ERROR_INVALID_ADDRESS 0x21
  156. #define NEC_SCSI_ERROR_INVALID_PARAMETER 0x22
  157. #define NEC_SCSI_ERROR_INVALID_CMD_SEQUENCE 0x24
  158. #define NEC_SCSI_ERROR_END_OF_VOLUME 0x25
  159. #define NEC_SCSI_ERROR_MEDIA_CHANGED 0x28
  160. #define NEC_SCSI_ERROR_DEVICE_RESET 0x29
  161. //
  162. // NEC 10-byte cdb definitions.
  163. //
  164. typedef union _NEC_CDB {
  165. //
  166. // NEC Read TOC CDB
  167. //
  168. struct _NEC_READ_TOC {
  169. UCHAR OperationCode;
  170. UCHAR Type : 2;
  171. UCHAR Reserved1 : 6;
  172. UCHAR TrackNumber;
  173. UCHAR Reserved2[6];
  174. UCHAR Control;
  175. } NEC_READ_TOC, *PNEC_READ_TOC;
  176. //
  177. // NEC Play CDB
  178. //
  179. struct _NEC_PLAY_AUDIO {
  180. UCHAR OperationCode;
  181. UCHAR PlayMode : 3;
  182. UCHAR Reserved1 : 5;
  183. UCHAR Minute;
  184. UCHAR Second;
  185. UCHAR Frame;
  186. UCHAR Reserved2[4];
  187. UCHAR Control;
  188. } NEC_PLAY_AUDIO, *PNEC_PLAY_AUDIO;
  189. //
  190. // NEC Seek Audio
  191. //
  192. struct _NEC_SEEK_AUDIO {
  193. UCHAR OperationCode;
  194. UCHAR Play : 1;
  195. UCHAR Reserved1 : 7;
  196. UCHAR Minute;
  197. UCHAR Second;
  198. UCHAR Frame;
  199. UCHAR Reserved2[4];
  200. UCHAR Control;
  201. } NEC_SEEK_AUDIO, *PNEC_SEEK_AUDIO;
  202. //
  203. // NEC Pause Audio
  204. //
  205. struct _NEC_PAUSE_AUDIO {
  206. UCHAR OperationCode;
  207. UCHAR Reserved1[8];
  208. UCHAR Control;
  209. } NEC_PAUSE_AUDIO, *PNEC_PAUSE_AUDIO;
  210. //
  211. // NEC Read Q Channel
  212. //
  213. struct _NEC_READ_Q_CHANNEL {
  214. UCHAR OperationCode;
  215. UCHAR TransferSize : 5;
  216. UCHAR Reserved1 : 3;
  217. UCHAR Reserved2[7];
  218. UCHAR Control;
  219. } NEC_READ_Q_CHANNEL, *PNEC_READ_Q_CHANNEL;
  220. //
  221. // NEC Eject Disc
  222. //
  223. struct _NEC_EJECT {
  224. UCHAR OperationCode;
  225. UCHAR Immediate : 1;
  226. UCHAR Reserved1 : 7;
  227. UCHAR Reserved2[7];
  228. UCHAR Control;
  229. } NEC_EJECT, *PNEC_EJECT;
  230. } NEC_CDB, *PNEC_CDB;
  231. //
  232. // Defines for PIONEER DRM-600
  233. //
  234. #define PIONEER_REZERO_UNIT_CODE 0x01
  235. #define PIONEER_EJECT_CODE 0xC0
  236. #define PIONEER_READ_TOC_CODE 0xC1
  237. #define PIONEER_READ_SUB_Q_CHANNEL_CODE 0xC2
  238. #define PIONEER_Q_CHANNEL_TRANSFER_SIZE 9
  239. #define PIONEER_AUDIO_STATUS_TRANSFER_SIZE 6
  240. #define PIONEER_AUDIO_TRACK_SEARCH_CODE 0xC8
  241. #define PIONEER_PLAY_AUDIO_CODE 0xC9
  242. #define PIONEER_PAUSE_CODE 0xCA
  243. #define PIONEER_AUDIO_STATUS_CODE 0xCC
  244. #define PIONEER_READ_STATUS_CODE 0xE0
  245. #define PIONEER_READ_FIRST_AND_LAST 0x00
  246. #define PIONEER_READ_TRACK_INFO 0x02
  247. #define PIONEER_READ_LEAD_OUT_INFO 0x01
  248. #define PIONEER_TRANSFER_SIZE 0x04
  249. #define PIONEER_TYPE_ATIME 0x01
  250. #define PIONEER_STOP_ADDRESS 0x10
  251. //
  252. // Page codes for the READ_STATUS command.
  253. //
  254. #define PIONEER_PC_DRIVE_STATUS 0x01
  255. #define PIONEER_PC_AUDIO_STATUS 0x02
  256. typedef struct _PIONEER_DRIVE_STATUS_BUFFER {
  257. UCHAR PageCode : 6;
  258. UCHAR Reserved : 2;
  259. UCHAR PageLengthMsb;
  260. UCHAR PageLengthLsb;
  261. UCHAR DriveStatusLsb;
  262. UCHAR DriveStatusMsb;
  263. } PIONEER_DRIVE_STATUS_BUFFER, *PPIONEER_DRIVE_STATUS_BUFFER;
  264. #define PIONEER_DISC_PRESENT 0x08
  265. //
  266. // Pioneer cdb definitions.
  267. //
  268. typedef union _PIONEER_CDB {
  269. //
  270. // Pioneer Start/Stop Unit
  271. //
  272. struct _PNR_START_STOP {
  273. UCHAR OperationCode;
  274. UCHAR Immediate : 1;
  275. UCHAR Reserved1 : 4;
  276. UCHAR Lun : 3;
  277. UCHAR Reserved2 : 7;
  278. UCHAR PCF : 1;
  279. UCHAR Reserved3;
  280. UCHAR Start : 1;
  281. UCHAR Eject : 1;
  282. UCHAR Reserved4 : 6;
  283. UCHAR Link : 1;
  284. UCHAR Flag : 1;
  285. UCHAR Reserved5 : 4;
  286. UCHAR Vendor : 2;
  287. } PNR_START_STOP, *PPNR_START_STOP;
  288. //
  289. // Pioneer Read TOC CDB
  290. //
  291. struct _PNR_READ_TOC {
  292. UCHAR OperationCode;
  293. UCHAR Reserved1 : 5;
  294. UCHAR Lun : 3;
  295. UCHAR Reserved2[3];
  296. UCHAR TrackNumber;
  297. UCHAR Reserved3;
  298. UCHAR AssignedLength[2];
  299. UCHAR Link : 1;
  300. UCHAR Flag : 1;
  301. UCHAR Reserved4 : 4;
  302. UCHAR Type : 2;
  303. } PNR_READ_TOC, *PPNR_READ_TOC;
  304. //
  305. // Pioneer Play CDB
  306. //
  307. struct _PNR_PLAY_AUDIO {
  308. UCHAR OperationCode;
  309. UCHAR PlayMode : 4;
  310. UCHAR StopAddr : 1;
  311. UCHAR Lun : 3;
  312. UCHAR Reserved1;
  313. UCHAR Minute;
  314. UCHAR Second;
  315. UCHAR Frame;
  316. UCHAR Reserved2[3];
  317. UCHAR Link : 1;
  318. UCHAR Flag : 1;
  319. UCHAR Reserved3 : 4;
  320. UCHAR Type : 2;
  321. } PNR_PLAY_AUDIO, *PPNR_PLAY_AUDIO;
  322. //
  323. // Pioneer Seek Audio
  324. //
  325. struct _PNR_SEEK_AUDIO {
  326. UCHAR OperationCode;
  327. UCHAR PlayMode : 4;
  328. UCHAR PlayBack : 1;
  329. UCHAR Lun : 3;
  330. UCHAR Reserved1;
  331. UCHAR Minute;
  332. UCHAR Second;
  333. UCHAR Frame;
  334. UCHAR Reserved2[3];
  335. UCHAR Link : 1;
  336. UCHAR Flag : 1;
  337. UCHAR Reserved3 : 4;
  338. UCHAR Type : 2;
  339. } PNR_SEEK_AUDIO, *PPNR_SEEK_AUDIO;
  340. //
  341. // Pioneer Pause Audio
  342. //
  343. struct _PNR_PAUSE_AUDIO {
  344. UCHAR OperationCode;
  345. UCHAR Reserved1 : 4;
  346. UCHAR Pause : 1;
  347. UCHAR Lun : 3;
  348. UCHAR Reserved2[7];
  349. UCHAR Link : 1;
  350. UCHAR Flag : 1;
  351. UCHAR Reserved3 : 4;
  352. UCHAR Reserved4 : 2;
  353. } PNR_PAUSE_AUDIO, *PPNR_PAUSE_AUDIO;
  354. //
  355. // Pioneer Audio Status
  356. //
  357. struct _PNR_AUDIO_STATUS {
  358. UCHAR OperationCode;
  359. UCHAR Reserved1 : 4;
  360. UCHAR Reserved2 : 1;
  361. UCHAR Lun : 3;
  362. UCHAR Reserved3[6];
  363. UCHAR AssignedLength;
  364. UCHAR Link : 1;
  365. UCHAR Flag : 1;
  366. UCHAR Reserved4 : 4;
  367. UCHAR Reserved5 : 2;
  368. } PNR_AUDIO_STATUS, *PPNR_AUDIO_STATUS;
  369. //
  370. // Pioneer Read Q Channel
  371. //
  372. struct _PNR_READ_Q_CHANNEL {
  373. UCHAR OperationCode;
  374. UCHAR Reserved1 : 4;
  375. UCHAR Reserved2 : 1;
  376. UCHAR Lun : 3;
  377. UCHAR Reserved3[6];
  378. UCHAR AssignedLength;
  379. UCHAR Link : 1;
  380. UCHAR Flag : 1;
  381. UCHAR Reserved4 : 4;
  382. UCHAR Reserved5 : 2;
  383. } PNR_READ_Q_CHANNEL, *PPNR_READ_Q_CHANNEL;
  384. //
  385. // Pioneer Eject Disc
  386. //
  387. struct _PNR_EJECT {
  388. UCHAR OperationCode;
  389. UCHAR Immediate : 1;
  390. UCHAR Reserved1 : 4;
  391. UCHAR Lun : 3;
  392. UCHAR Reserved2[7];
  393. UCHAR Link : 1;
  394. UCHAR Flag : 1;
  395. UCHAR Reserved4 : 4;
  396. UCHAR Reserved5 : 2;
  397. } PNR_EJECT, *PPNR_EJECT;
  398. struct _PNR_READ_STATUS {
  399. UCHAR OperationCode;
  400. UCHAR Reserved1 : 4;
  401. UCHAR Lun : 3;
  402. UCHAR PageCode : 5;
  403. UCHAR PCField : 1;
  404. UCHAR Reserved2[5];
  405. UCHAR AllocationLengthMsb;
  406. UCHAR AllocationLengthLsb;
  407. UCHAR Link : 1;
  408. UCHAR Flag : 1;
  409. UCHAR Reserved3 : 4;
  410. UCHAR Reserved4 : 2;
  411. } PNR_READ_STATUS, *PPNR_READ_STATUS;
  412. } PNR_CDB, *PPNR_CDB;
  413. //
  414. // Defines for DENON DRD-253
  415. //
  416. #define DENON_READ_TOC_CODE 0xE9
  417. #define DENON_EJECT_CODE 0xE6
  418. #define DENON_PLAY_AUDIO_EXTENDED_CODE 0x22
  419. #define DENON_STOP_AUDIO_CODE 0xE7
  420. #define DENON_READ_SUB_Q_CHANNEL_CODE 0xEB
  421. //
  422. // Defines for HITACHI 1750s
  423. //
  424. #define HITACHI_READ_TOC_CODE 0xE8
  425. #define HITACHI_EJECT_CODE 0xE4
  426. #define HITACHI_PLAY_AUDIO_MSF_CODE 0xE0
  427. #define HITACHI_PAUSE_AUDIO_CODE 0xE1
  428. #define HITACHI_READ_SUB_Q_CHANNEL_CODE 0xE5
  429. //
  430. // 12 byte cdbs for Hitachi and Atapi
  431. //
  432. typedef union _HITACHICDB {
  433. //
  434. // Disc Information
  435. //
  436. struct _READ_DISC_INFO {
  437. UCHAR OperationCode;
  438. UCHAR Reserved : 5;
  439. UCHAR LogicalUnitNumber : 3;
  440. UCHAR Reserved1[7];
  441. UCHAR AllocationLength[2];
  442. UCHAR Link : 1;
  443. UCHAR Flag : 1;
  444. UCHAR Reserved2 : 4;
  445. UCHAR VendorUniqueBits : 2;
  446. } READ_DISC_INFO, *PREAD_DISC_INFO;
  447. //
  448. // Play Audio
  449. //
  450. struct {
  451. UCHAR OperationCode;
  452. UCHAR Immediate : 1;
  453. UCHAR Right : 1;
  454. UCHAR Left : 1;
  455. UCHAR Reserved : 2;
  456. UCHAR Lun : 3;
  457. UCHAR StartingM;
  458. UCHAR StartingS;
  459. UCHAR StartingF;
  460. UCHAR Reserved1[2];
  461. UCHAR EndingM;
  462. UCHAR EndingS;
  463. UCHAR EndingF;
  464. UCHAR Reserved2;
  465. UCHAR Link : 1;
  466. UCHAR Flag : 1;
  467. UCHAR Reserved3 : 4;
  468. UCHAR VendorUniqueBits : 2;
  469. } PLAY_AUDIO, *PPLAY_AUDIO;
  470. //
  471. // Pause Audio
  472. //
  473. struct _PAUSE {
  474. UCHAR OperationCode;
  475. UCHAR Reserved : 5;
  476. UCHAR Lun : 3;
  477. UCHAR Reserved1[9];
  478. UCHAR Link : 1;
  479. UCHAR Flag : 1;
  480. UCHAR Reserved2 : 4;
  481. UCHAR VendorUnqiueBits : 2;
  482. } PAUSE_AUDIO, *PPAUSE_AUDIO;
  483. //
  484. // Eject media
  485. //
  486. struct _EJECT {
  487. UCHAR OperationCode;
  488. UCHAR Reserved : 5;
  489. UCHAR Lun : 3;
  490. UCHAR Reserved1[8];
  491. UCHAR Eject : 1;
  492. UCHAR Mode : 1;
  493. UCHAR Reserved2 : 6;
  494. UCHAR Link : 1;
  495. UCHAR Flag : 1;
  496. UCHAR Reserved3 : 4;
  497. UCHAR VendorUnqiueBits : 2;
  498. } EJECT, *PEJECT;
  499. //
  500. // Audio Status
  501. //
  502. struct _AUDIO_STATUS {
  503. UCHAR OperationCode;
  504. UCHAR Reserved : 5;
  505. UCHAR Lun : 3;
  506. UCHAR Reserved1[9];
  507. UCHAR Link : 1;
  508. UCHAR Flag : 1;
  509. UCHAR Reserved2 : 4;
  510. UCHAR VendorUnqiueBits : 2;
  511. } AUDIO_STATUS, *PAUDIO_STATUS;
  512. //
  513. // Stop play
  514. //
  515. struct _STOP_PLAY {
  516. UCHAR OperationCode;
  517. UCHAR Reserved[11];
  518. } STOP_PLAY, *PSTOP_PLAY;
  519. } HITACHICDB, *PHITACHICDB;
  520. //
  521. // Defines for Chinon CDS-535 CDROM Drive
  522. //
  523. #define CDS535_READ_TOC_CODE 0x43
  524. #define CDS535_EJECT_CODE 0xC0
  525. #define CDS535_READ_SUB_Q_CHANNEL_CODE 0x42
  526. #define CDS535_STOP_AUDIO 0xC6
  527. #define CDS535_GET_LAST_SESSION 0x26
  528. //
  529. // Defines for Chinon CDS-435 CDROM Drive
  530. //
  531. #define CDS435_READ_TOC_CODE 0x43
  532. #define CDS435_EJECT_CODE 0xC0
  533. #define CDS435_STOP_AUDIO_CODE 0xC6
  534. #define CDS435_PLAY_AUDIO_EXTENDED_CODE 0x47
  535. #define CDS435_READ_SUB_Q_CHANNEL_CODE 0x42
  536. //
  537. // Define for Fujitsu CDROM device.
  538. //
  539. #define FUJITSU_READ_TOC_CODE 0xE3
  540. //
  541. // Algebraically equal to:
  542. // 75*60*Minutes +
  543. // 75*Seconds +
  544. // Frames - 150
  545. //
  546. #define MSF_TO_LBA(Minutes,Seconds,Frames) \
  547. (ULONG)(75 * ((60 * (Minutes)) + (Seconds)) + (Frames) - 150)
  548. #define LBA_TO_MSF(Lba,Minutes,Seconds,Frames) \
  549. { \
  550. (Minutes) = (UCHAR)( (Lba) / (60 * 75) ); \
  551. (Seconds) = (UCHAR)(((Lba) % (60 * 75)) / 75); \
  552. (Frames) = (UCHAR)(((Lba) % (60 * 75)) % 75); \
  553. }