sr_ioctl.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. #include <linux/kernel.h>
  2. #include <linux/mm.h>
  3. #include <linux/fs.h>
  4. #include <linux/errno.h>
  5. #include <linux/string.h>
  6. #include <linux/blkdev.h>
  7. #include <linux/module.h>
  8. #include <linux/blkpg.h>
  9. #include <linux/cdrom.h>
  10. #include <linux/delay.h>
  11. #include <linux/slab.h>
  12. #include <asm/io.h>
  13. #include <asm/uaccess.h>
  14. #include <scsi/scsi.h>
  15. #include <scsi/scsi_dbg.h>
  16. #include <scsi/scsi_device.h>
  17. #include <scsi/scsi_eh.h>
  18. #include <scsi/scsi_host.h>
  19. #include <scsi/scsi_ioctl.h>
  20. #include <scsi/scsi_cmnd.h>
  21. #include "sr.h"
  22. #if 0
  23. #define DEBUG
  24. #endif
  25. /* The sr_is_xa() seems to trigger firmware bugs with some drives :-(
  26. * It is off by default and can be turned on with this module parameter */
  27. static int xa_test = 0;
  28. module_param(xa_test, int, S_IRUGO | S_IWUSR);
  29. /* primitive to determine whether we need to have GFP_DMA set based on
  30. * the status of the unchecked_isa_dma flag in the host structure */
  31. #define SR_GFP_DMA(cd) (((cd)->device->host->unchecked_isa_dma) ? GFP_DMA : 0)
  32. static int sr_read_tochdr(struct cdrom_device_info *cdi,
  33. struct cdrom_tochdr *tochdr)
  34. {
  35. struct scsi_cd *cd = cdi->handle;
  36. struct packet_command cgc;
  37. int result;
  38. unsigned char *buffer;
  39. buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
  40. if (!buffer)
  41. return -ENOMEM;
  42. memset(&cgc, 0, sizeof(struct packet_command));
  43. cgc.timeout = IOCTL_TIMEOUT;
  44. cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
  45. cgc.cmd[8] = 12; /* LSB of length */
  46. cgc.buffer = buffer;
  47. cgc.buflen = 12;
  48. cgc.quiet = 1;
  49. cgc.data_direction = DMA_FROM_DEVICE;
  50. result = sr_do_ioctl(cd, &cgc);
  51. tochdr->cdth_trk0 = buffer[2];
  52. tochdr->cdth_trk1 = buffer[3];
  53. kfree(buffer);
  54. return result;
  55. }
  56. static int sr_read_tocentry(struct cdrom_device_info *cdi,
  57. struct cdrom_tocentry *tocentry)
  58. {
  59. struct scsi_cd *cd = cdi->handle;
  60. struct packet_command cgc;
  61. int result;
  62. unsigned char *buffer;
  63. buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
  64. if (!buffer)
  65. return -ENOMEM;
  66. memset(&cgc, 0, sizeof(struct packet_command));
  67. cgc.timeout = IOCTL_TIMEOUT;
  68. cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
  69. cgc.cmd[1] |= (tocentry->cdte_format == CDROM_MSF) ? 0x02 : 0;
  70. cgc.cmd[6] = tocentry->cdte_track;
  71. cgc.cmd[8] = 12; /* LSB of length */
  72. cgc.buffer = buffer;
  73. cgc.buflen = 12;
  74. cgc.data_direction = DMA_FROM_DEVICE;
  75. result = sr_do_ioctl(cd, &cgc);
  76. tocentry->cdte_ctrl = buffer[5] & 0xf;
  77. tocentry->cdte_adr = buffer[5] >> 4;
  78. tocentry->cdte_datamode = (tocentry->cdte_ctrl & 0x04) ? 1 : 0;
  79. if (tocentry->cdte_format == CDROM_MSF) {
  80. tocentry->cdte_addr.msf.minute = buffer[9];
  81. tocentry->cdte_addr.msf.second = buffer[10];
  82. tocentry->cdte_addr.msf.frame = buffer[11];
  83. } else
  84. tocentry->cdte_addr.lba = (((((buffer[8] << 8) + buffer[9]) << 8)
  85. + buffer[10]) << 8) + buffer[11];
  86. kfree(buffer);
  87. return result;
  88. }
  89. #define IOCTL_RETRIES 3
  90. /* ATAPI drives don't have a SCMD_PLAYAUDIO_TI command. When these drives
  91. are emulating a SCSI device via the idescsi module, they need to have
  92. CDROMPLAYTRKIND commands translated into CDROMPLAYMSF commands for them */
  93. static int sr_fake_playtrkind(struct cdrom_device_info *cdi, struct cdrom_ti *ti)
  94. {
  95. struct cdrom_tocentry trk0_te, trk1_te;
  96. struct cdrom_tochdr tochdr;
  97. struct packet_command cgc;
  98. int ntracks, ret;
  99. ret = sr_read_tochdr(cdi, &tochdr);
  100. if (ret)
  101. return ret;
  102. ntracks = tochdr.cdth_trk1 - tochdr.cdth_trk0 + 1;
  103. if (ti->cdti_trk1 == ntracks)
  104. ti->cdti_trk1 = CDROM_LEADOUT;
  105. else if (ti->cdti_trk1 != CDROM_LEADOUT)
  106. ti->cdti_trk1 ++;
  107. trk0_te.cdte_track = ti->cdti_trk0;
  108. trk0_te.cdte_format = CDROM_MSF;
  109. trk1_te.cdte_track = ti->cdti_trk1;
  110. trk1_te.cdte_format = CDROM_MSF;
  111. ret = sr_read_tocentry(cdi, &trk0_te);
  112. if (ret)
  113. return ret;
  114. ret = sr_read_tocentry(cdi, &trk1_te);
  115. if (ret)
  116. return ret;
  117. memset(&cgc, 0, sizeof(struct packet_command));
  118. cgc.cmd[0] = GPCMD_PLAY_AUDIO_MSF;
  119. cgc.cmd[3] = trk0_te.cdte_addr.msf.minute;
  120. cgc.cmd[4] = trk0_te.cdte_addr.msf.second;
  121. cgc.cmd[5] = trk0_te.cdte_addr.msf.frame;
  122. cgc.cmd[6] = trk1_te.cdte_addr.msf.minute;
  123. cgc.cmd[7] = trk1_te.cdte_addr.msf.second;
  124. cgc.cmd[8] = trk1_te.cdte_addr.msf.frame;
  125. cgc.data_direction = DMA_NONE;
  126. cgc.timeout = IOCTL_TIMEOUT;
  127. return sr_do_ioctl(cdi->handle, &cgc);
  128. }
  129. static int sr_play_trkind(struct cdrom_device_info *cdi,
  130. struct cdrom_ti *ti)
  131. {
  132. struct scsi_cd *cd = cdi->handle;
  133. struct packet_command cgc;
  134. int result;
  135. memset(&cgc, 0, sizeof(struct packet_command));
  136. cgc.timeout = IOCTL_TIMEOUT;
  137. cgc.cmd[0] = GPCMD_PLAYAUDIO_TI;
  138. cgc.cmd[4] = ti->cdti_trk0;
  139. cgc.cmd[5] = ti->cdti_ind0;
  140. cgc.cmd[7] = ti->cdti_trk1;
  141. cgc.cmd[8] = ti->cdti_ind1;
  142. cgc.data_direction = DMA_NONE;
  143. result = sr_do_ioctl(cd, &cgc);
  144. if (result == -EDRIVE_CANT_DO_THIS)
  145. result = sr_fake_playtrkind(cdi, ti);
  146. return result;
  147. }
  148. /* We do our own retries because we want to know what the specific
  149. error code is. Normally the UNIT_ATTENTION code will automatically
  150. clear after one error */
  151. int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
  152. {
  153. struct scsi_device *SDev;
  154. struct scsi_sense_hdr sshdr;
  155. int result, err = 0, retries = 0;
  156. struct request_sense *sense = cgc->sense;
  157. SDev = cd->device;
  158. if (!sense) {
  159. sense = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
  160. if (!sense) {
  161. err = -ENOMEM;
  162. goto out;
  163. }
  164. }
  165. retry:
  166. if (!scsi_block_when_processing_errors(SDev)) {
  167. err = -ENODEV;
  168. goto out;
  169. }
  170. memset(sense, 0, sizeof(*sense));
  171. result = scsi_execute(SDev, cgc->cmd, cgc->data_direction,
  172. cgc->buffer, cgc->buflen, (char *)sense,
  173. cgc->timeout, IOCTL_RETRIES, 0, NULL);
  174. scsi_normalize_sense((char *)sense, sizeof(*sense), &sshdr);
  175. /* Minimal error checking. Ignore cases we know about, and report the rest. */
  176. if (driver_byte(result) != 0) {
  177. switch (sshdr.sense_key) {
  178. case UNIT_ATTENTION:
  179. SDev->changed = 1;
  180. if (!cgc->quiet)
  181. printk(KERN_INFO "%s: disc change detected.\n", cd->cdi.name);
  182. if (retries++ < 10)
  183. goto retry;
  184. err = -ENOMEDIUM;
  185. break;
  186. case NOT_READY: /* This happens if there is no disc in drive */
  187. if (sshdr.asc == 0x04 &&
  188. sshdr.ascq == 0x01) {
  189. /* sense: Logical unit is in process of becoming ready */
  190. if (!cgc->quiet)
  191. printk(KERN_INFO "%s: CDROM not ready yet.\n", cd->cdi.name);
  192. if (retries++ < 10) {
  193. /* sleep 2 sec and try again */
  194. ssleep(2);
  195. goto retry;
  196. } else {
  197. /* 20 secs are enough? */
  198. err = -ENOMEDIUM;
  199. break;
  200. }
  201. }
  202. if (!cgc->quiet)
  203. printk(KERN_INFO "%s: CDROM not ready. Make sure there is a disc in the drive.\n", cd->cdi.name);
  204. #ifdef DEBUG
  205. scsi_print_sense_hdr("sr", &sshdr);
  206. #endif
  207. err = -ENOMEDIUM;
  208. break;
  209. case ILLEGAL_REQUEST:
  210. err = -EIO;
  211. if (sshdr.asc == 0x20 &&
  212. sshdr.ascq == 0x00)
  213. /* sense: Invalid command operation code */
  214. err = -EDRIVE_CANT_DO_THIS;
  215. #ifdef DEBUG
  216. __scsi_print_command(cgc->cmd);
  217. scsi_print_sense_hdr("sr", &sshdr);
  218. #endif
  219. break;
  220. default:
  221. printk(KERN_ERR "%s: CDROM (ioctl) error, command: ", cd->cdi.name);
  222. __scsi_print_command(cgc->cmd);
  223. scsi_print_sense_hdr("sr", &sshdr);
  224. err = -EIO;
  225. }
  226. }
  227. /* Wake up a process waiting for device */
  228. out:
  229. if (!cgc->sense)
  230. kfree(sense);
  231. cgc->stat = err;
  232. return err;
  233. }
  234. /* ---------------------------------------------------------------------- */
  235. /* interface to cdrom.c */
  236. int sr_tray_move(struct cdrom_device_info *cdi, int pos)
  237. {
  238. Scsi_CD *cd = cdi->handle;
  239. struct packet_command cgc;
  240. memset(&cgc, 0, sizeof(struct packet_command));
  241. cgc.cmd[0] = GPCMD_START_STOP_UNIT;
  242. cgc.cmd[4] = (pos == 0) ? 0x03 /* close */ : 0x02 /* eject */ ;
  243. cgc.data_direction = DMA_NONE;
  244. cgc.timeout = IOCTL_TIMEOUT;
  245. return sr_do_ioctl(cd, &cgc);
  246. }
  247. int sr_lock_door(struct cdrom_device_info *cdi, int lock)
  248. {
  249. Scsi_CD *cd = cdi->handle;
  250. return scsi_set_medium_removal(cd->device, lock ?
  251. SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
  252. }
  253. int sr_drive_status(struct cdrom_device_info *cdi, int slot)
  254. {
  255. struct scsi_cd *cd = cdi->handle;
  256. struct scsi_sense_hdr sshdr;
  257. struct media_event_desc med;
  258. if (CDSL_CURRENT != slot) {
  259. /* we have no changer support */
  260. return -EINVAL;
  261. }
  262. if (!scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
  263. return CDS_DISC_OK;
  264. /* SK/ASC/ASCQ of 2/4/1 means "unit is becoming ready" */
  265. if (scsi_sense_valid(&sshdr) && sshdr.sense_key == NOT_READY
  266. && sshdr.asc == 0x04 && sshdr.ascq == 0x01)
  267. return CDS_DRIVE_NOT_READY;
  268. if (!cdrom_get_media_event(cdi, &med)) {
  269. if (med.media_present)
  270. return CDS_DISC_OK;
  271. else if (med.door_open)
  272. return CDS_TRAY_OPEN;
  273. else
  274. return CDS_NO_DISC;
  275. }
  276. /*
  277. * SK/ASC/ASCQ of 2/4/2 means "initialization required"
  278. * Using CD_TRAY_OPEN results in an START_STOP_UNIT to close
  279. * the tray, which resolves the initialization requirement.
  280. */
  281. if (scsi_sense_valid(&sshdr) && sshdr.sense_key == NOT_READY
  282. && sshdr.asc == 0x04 && sshdr.ascq == 0x02)
  283. return CDS_TRAY_OPEN;
  284. /*
  285. * 0x04 is format in progress .. but there must be a disc present!
  286. */
  287. if (sshdr.sense_key == NOT_READY && sshdr.asc == 0x04)
  288. return CDS_DISC_OK;
  289. /*
  290. * If not using Mt Fuji extended media tray reports,
  291. * just return TRAY_OPEN since ATAPI doesn't provide
  292. * any other way to detect this...
  293. */
  294. if (scsi_sense_valid(&sshdr) &&
  295. /* 0x3a is medium not present */
  296. sshdr.asc == 0x3a)
  297. return CDS_NO_DISC;
  298. else
  299. return CDS_TRAY_OPEN;
  300. return CDS_DRIVE_NOT_READY;
  301. }
  302. int sr_disk_status(struct cdrom_device_info *cdi)
  303. {
  304. Scsi_CD *cd = cdi->handle;
  305. struct cdrom_tochdr toc_h;
  306. struct cdrom_tocentry toc_e;
  307. int i, rc, have_datatracks = 0;
  308. /* look for data tracks */
  309. rc = sr_read_tochdr(cdi, &toc_h);
  310. if (rc)
  311. return (rc == -ENOMEDIUM) ? CDS_NO_DISC : CDS_NO_INFO;
  312. for (i = toc_h.cdth_trk0; i <= toc_h.cdth_trk1; i++) {
  313. toc_e.cdte_track = i;
  314. toc_e.cdte_format = CDROM_LBA;
  315. if (sr_read_tocentry(cdi, &toc_e))
  316. return CDS_NO_INFO;
  317. if (toc_e.cdte_ctrl & CDROM_DATA_TRACK) {
  318. have_datatracks = 1;
  319. break;
  320. }
  321. }
  322. if (!have_datatracks)
  323. return CDS_AUDIO;
  324. if (cd->xa_flag)
  325. return CDS_XA_2_1;
  326. else
  327. return CDS_DATA_1;
  328. }
  329. int sr_get_last_session(struct cdrom_device_info *cdi,
  330. struct cdrom_multisession *ms_info)
  331. {
  332. Scsi_CD *cd = cdi->handle;
  333. ms_info->addr.lba = cd->ms_offset;
  334. ms_info->xa_flag = cd->xa_flag || cd->ms_offset > 0;
  335. return 0;
  336. }
  337. int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
  338. {
  339. Scsi_CD *cd = cdi->handle;
  340. struct packet_command cgc;
  341. char *buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
  342. int result;
  343. if (!buffer)
  344. return -ENOMEM;
  345. memset(&cgc, 0, sizeof(struct packet_command));
  346. cgc.cmd[0] = GPCMD_READ_SUBCHANNEL;
  347. cgc.cmd[2] = 0x40; /* I do want the subchannel info */
  348. cgc.cmd[3] = 0x02; /* Give me medium catalog number info */
  349. cgc.cmd[8] = 24;
  350. cgc.buffer = buffer;
  351. cgc.buflen = 24;
  352. cgc.data_direction = DMA_FROM_DEVICE;
  353. cgc.timeout = IOCTL_TIMEOUT;
  354. result = sr_do_ioctl(cd, &cgc);
  355. memcpy(mcn->medium_catalog_number, buffer + 9, 13);
  356. mcn->medium_catalog_number[13] = 0;
  357. kfree(buffer);
  358. return result;
  359. }
  360. int sr_reset(struct cdrom_device_info *cdi)
  361. {
  362. return 0;
  363. }
  364. int sr_select_speed(struct cdrom_device_info *cdi, int speed)
  365. {
  366. Scsi_CD *cd = cdi->handle;
  367. struct packet_command cgc;
  368. if (speed == 0)
  369. speed = 0xffff; /* set to max */
  370. else
  371. speed *= 177; /* Nx to kbyte/s */
  372. memset(&cgc, 0, sizeof(struct packet_command));
  373. cgc.cmd[0] = GPCMD_SET_SPEED; /* SET CD SPEED */
  374. cgc.cmd[2] = (speed >> 8) & 0xff; /* MSB for speed (in kbytes/sec) */
  375. cgc.cmd[3] = speed & 0xff; /* LSB */
  376. cgc.data_direction = DMA_NONE;
  377. cgc.timeout = IOCTL_TIMEOUT;
  378. if (sr_do_ioctl(cd, &cgc))
  379. return -EIO;
  380. return 0;
  381. }
  382. /* ----------------------------------------------------------------------- */
  383. /* this is called by the generic cdrom driver. arg is a _kernel_ pointer, */
  384. /* because the generic cdrom driver does the user access stuff for us. */
  385. /* only cdromreadtochdr and cdromreadtocentry are left - for use with the */
  386. /* sr_disk_status interface for the generic cdrom driver. */
  387. int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
  388. {
  389. switch (cmd) {
  390. case CDROMREADTOCHDR:
  391. return sr_read_tochdr(cdi, arg);
  392. case CDROMREADTOCENTRY:
  393. return sr_read_tocentry(cdi, arg);
  394. case CDROMPLAYTRKIND:
  395. return sr_play_trkind(cdi, arg);
  396. default:
  397. return -EINVAL;
  398. }
  399. }
  400. /* -----------------------------------------------------------------------
  401. * a function to read all sorts of funny cdrom sectors using the READ_CD
  402. * scsi-3 mmc command
  403. *
  404. * lba: linear block address
  405. * format: 0 = data (anything)
  406. * 1 = audio
  407. * 2 = data (mode 1)
  408. * 3 = data (mode 2)
  409. * 4 = data (mode 2 form1)
  410. * 5 = data (mode 2 form2)
  411. * blksize: 2048 | 2336 | 2340 | 2352
  412. */
  413. static int sr_read_cd(Scsi_CD *cd, unsigned char *dest, int lba, int format, int blksize)
  414. {
  415. struct packet_command cgc;
  416. #ifdef DEBUG
  417. printk("%s: sr_read_cd lba=%d format=%d blksize=%d\n",
  418. cd->cdi.name, lba, format, blksize);
  419. #endif
  420. memset(&cgc, 0, sizeof(struct packet_command));
  421. cgc.cmd[0] = GPCMD_READ_CD; /* READ_CD */
  422. cgc.cmd[1] = ((format & 7) << 2);
  423. cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
  424. cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
  425. cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
  426. cgc.cmd[5] = (unsigned char) lba & 0xff;
  427. cgc.cmd[8] = 1;
  428. switch (blksize) {
  429. case 2336:
  430. cgc.cmd[9] = 0x58;
  431. break;
  432. case 2340:
  433. cgc.cmd[9] = 0x78;
  434. break;
  435. case 2352:
  436. cgc.cmd[9] = 0xf8;
  437. break;
  438. default:
  439. cgc.cmd[9] = 0x10;
  440. break;
  441. }
  442. cgc.buffer = dest;
  443. cgc.buflen = blksize;
  444. cgc.data_direction = DMA_FROM_DEVICE;
  445. cgc.timeout = IOCTL_TIMEOUT;
  446. return sr_do_ioctl(cd, &cgc);
  447. }
  448. /*
  449. * read sectors with blocksizes other than 2048
  450. */
  451. static int sr_read_sector(Scsi_CD *cd, int lba, int blksize, unsigned char *dest)
  452. {
  453. struct packet_command cgc;
  454. int rc;
  455. /* we try the READ CD command first... */
  456. if (cd->readcd_known) {
  457. rc = sr_read_cd(cd, dest, lba, 0, blksize);
  458. if (-EDRIVE_CANT_DO_THIS != rc)
  459. return rc;
  460. cd->readcd_known = 0;
  461. printk("CDROM does'nt support READ CD (0xbe) command\n");
  462. /* fall & retry the other way */
  463. }
  464. /* ... if this fails, we switch the blocksize using MODE SELECT */
  465. if (blksize != cd->device->sector_size) {
  466. if (0 != (rc = sr_set_blocklength(cd, blksize)))
  467. return rc;
  468. }
  469. #ifdef DEBUG
  470. printk("%s: sr_read_sector lba=%d blksize=%d\n", cd->cdi.name, lba, blksize);
  471. #endif
  472. memset(&cgc, 0, sizeof(struct packet_command));
  473. cgc.cmd[0] = GPCMD_READ_10;
  474. cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
  475. cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
  476. cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
  477. cgc.cmd[5] = (unsigned char) lba & 0xff;
  478. cgc.cmd[8] = 1;
  479. cgc.buffer = dest;
  480. cgc.buflen = blksize;
  481. cgc.data_direction = DMA_FROM_DEVICE;
  482. cgc.timeout = IOCTL_TIMEOUT;
  483. rc = sr_do_ioctl(cd, &cgc);
  484. return rc;
  485. }
  486. /*
  487. * read a sector in raw mode to check the sector format
  488. * ret: 1 == mode2 (XA), 0 == mode1, <0 == error
  489. */
  490. int sr_is_xa(Scsi_CD *cd)
  491. {
  492. unsigned char *raw_sector;
  493. int is_xa;
  494. if (!xa_test)
  495. return 0;
  496. raw_sector = kmalloc(2048, GFP_KERNEL | SR_GFP_DMA(cd));
  497. if (!raw_sector)
  498. return -ENOMEM;
  499. if (0 == sr_read_sector(cd, cd->ms_offset + 16,
  500. CD_FRAMESIZE_RAW1, raw_sector)) {
  501. is_xa = (raw_sector[3] == 0x02) ? 1 : 0;
  502. } else {
  503. /* read a raw sector failed for some reason. */
  504. is_xa = -1;
  505. }
  506. kfree(raw_sector);
  507. #ifdef DEBUG
  508. printk("%s: sr_is_xa: %d\n", cd->cdi.name, is_xa);
  509. #endif
  510. return is_xa;
  511. }