blob: d1268cb46837b258cd721f992546c7f1084d6345 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/kernel.h>
2#include <linux/sched.h>
3#include <linux/mm.h>
4#include <linux/fs.h>
5#include <linux/errno.h>
6#include <linux/string.h>
7#include <linux/blkdev.h>
8#include <linux/blkpg.h>
9#include <linux/cdrom.h>
10#include <linux/delay.h>
11#include <asm/io.h>
12#include <asm/uaccess.h>
13
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>
James Bottomley820732b2005-06-12 22:21:29 -050020#include <scsi/scsi_cmnd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include "sr.h"
23
24#if 0
25#define DEBUG
26#endif
27
28/* The sr_is_xa() seems to trigger firmware bugs with some drives :-(
29 * It is off by default and can be turned on with this module parameter */
30static int xa_test = 0;
31
32module_param(xa_test, int, S_IRUGO | S_IWUSR);
33
Christoph Hellwiga09c6312006-01-11 14:28:06 +010034/* primitive to determine whether we need to have GFP_DMA set based on
35 * the status of the unchecked_isa_dma flag in the host structure */
36#define SR_GFP_DMA(cd) (((cd)->device->host->unchecked_isa_dma) ? GFP_DMA : 0)
37
38
39static int sr_read_tochdr(struct cdrom_device_info *cdi,
40 struct cdrom_tochdr *tochdr)
41{
42 struct scsi_cd *cd = cdi->handle;
43 struct packet_command cgc;
44 int result;
45 unsigned char *buffer;
46
47 buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
48 if (!buffer)
49 return -ENOMEM;
50
51 memset(&cgc, 0, sizeof(struct packet_command));
52 cgc.timeout = IOCTL_TIMEOUT;
53 cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
54 cgc.cmd[8] = 12; /* LSB of length */
55 cgc.buffer = buffer;
56 cgc.buflen = 12;
57 cgc.quiet = 1;
58 cgc.data_direction = DMA_FROM_DEVICE;
59
60 result = sr_do_ioctl(cd, &cgc);
61
62 tochdr->cdth_trk0 = buffer[2];
63 tochdr->cdth_trk1 = buffer[3];
64
65 kfree(buffer);
66 return result;
67}
68
69static int sr_read_tocentry(struct cdrom_device_info *cdi,
70 struct cdrom_tocentry *tocentry)
71{
72 struct scsi_cd *cd = cdi->handle;
73 struct packet_command cgc;
74 int result;
75 unsigned char *buffer;
76
77 buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
78 if (!buffer)
79 return -ENOMEM;
80
81 memset(&cgc, 0, sizeof(struct packet_command));
82 cgc.timeout = IOCTL_TIMEOUT;
83 cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
84 cgc.cmd[1] |= (tocentry->cdte_format == CDROM_MSF) ? 0x02 : 0;
85 cgc.cmd[6] = tocentry->cdte_track;
86 cgc.cmd[8] = 12; /* LSB of length */
87 cgc.buffer = buffer;
88 cgc.buflen = 12;
89 cgc.data_direction = DMA_FROM_DEVICE;
90
91 result = sr_do_ioctl(cd, &cgc);
92
93 tocentry->cdte_ctrl = buffer[5] & 0xf;
94 tocentry->cdte_adr = buffer[5] >> 4;
95 tocentry->cdte_datamode = (tocentry->cdte_ctrl & 0x04) ? 1 : 0;
96 if (tocentry->cdte_format == CDROM_MSF) {
97 tocentry->cdte_addr.msf.minute = buffer[9];
98 tocentry->cdte_addr.msf.second = buffer[10];
99 tocentry->cdte_addr.msf.frame = buffer[11];
100 } else
101 tocentry->cdte_addr.lba = (((((buffer[8] << 8) + buffer[9]) << 8)
102 + buffer[10]) << 8) + buffer[11];
103
104 kfree(buffer);
105 return result;
106}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108#define IOCTL_RETRIES 3
109
110/* ATAPI drives don't have a SCMD_PLAYAUDIO_TI command. When these drives
111 are emulating a SCSI device via the idescsi module, they need to have
112 CDROMPLAYTRKIND commands translated into CDROMPLAYMSF commands for them */
113
114static int sr_fake_playtrkind(struct cdrom_device_info *cdi, struct cdrom_ti *ti)
115{
116 struct cdrom_tocentry trk0_te, trk1_te;
117 struct cdrom_tochdr tochdr;
118 struct packet_command cgc;
119 int ntracks, ret;
120
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100121 ret = sr_read_tochdr(cdi, &tochdr);
122 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 return ret;
124
125 ntracks = tochdr.cdth_trk1 - tochdr.cdth_trk0 + 1;
126
127 if (ti->cdti_trk1 == ntracks)
128 ti->cdti_trk1 = CDROM_LEADOUT;
129 else if (ti->cdti_trk1 != CDROM_LEADOUT)
130 ti->cdti_trk1 ++;
131
132 trk0_te.cdte_track = ti->cdti_trk0;
133 trk0_te.cdte_format = CDROM_MSF;
134 trk1_te.cdte_track = ti->cdti_trk1;
135 trk1_te.cdte_format = CDROM_MSF;
136
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100137 ret = sr_read_tocentry(cdi, &trk0_te);
138 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 return ret;
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100140 ret = sr_read_tocentry(cdi, &trk1_te);
141 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return ret;
143
144 memset(&cgc, 0, sizeof(struct packet_command));
145 cgc.cmd[0] = GPCMD_PLAY_AUDIO_MSF;
146 cgc.cmd[3] = trk0_te.cdte_addr.msf.minute;
147 cgc.cmd[4] = trk0_te.cdte_addr.msf.second;
148 cgc.cmd[5] = trk0_te.cdte_addr.msf.frame;
149 cgc.cmd[6] = trk1_te.cdte_addr.msf.minute;
150 cgc.cmd[7] = trk1_te.cdte_addr.msf.second;
151 cgc.cmd[8] = trk1_te.cdte_addr.msf.frame;
152 cgc.data_direction = DMA_NONE;
153 cgc.timeout = IOCTL_TIMEOUT;
154 return sr_do_ioctl(cdi->handle, &cgc);
155}
156
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100157static int sr_play_trkind(struct cdrom_device_info *cdi,
158 struct cdrom_ti *ti)
159
160{
161 struct scsi_cd *cd = cdi->handle;
162 struct packet_command cgc;
163 int result;
164
165 memset(&cgc, 0, sizeof(struct packet_command));
166 cgc.timeout = IOCTL_TIMEOUT;
167 cgc.cmd[0] = GPCMD_PLAYAUDIO_TI;
168 cgc.cmd[4] = ti->cdti_trk0;
169 cgc.cmd[5] = ti->cdti_ind0;
170 cgc.cmd[7] = ti->cdti_trk1;
171 cgc.cmd[8] = ti->cdti_ind1;
172 cgc.data_direction = DMA_NONE;
173
174 result = sr_do_ioctl(cd, &cgc);
175 if (result == -EDRIVE_CANT_DO_THIS)
176 result = sr_fake_playtrkind(cdi, ti);
177
178 return result;
179}
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181/* We do our own retries because we want to know what the specific
182 error code is. Normally the UNIT_ATTENTION code will automatically
183 clear after one error */
184
185int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
186{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 struct scsi_device *SDev;
James Bottomley820732b2005-06-12 22:21:29 -0500188 struct scsi_sense_hdr sshdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 int result, err = 0, retries = 0;
James Bottomley820732b2005-06-12 22:21:29 -0500190 struct request_sense *sense = cgc->sense;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 SDev = cd->device;
James Bottomley820732b2005-06-12 22:21:29 -0500193
194 if (!sense) {
Linus Torvaldsf716d832006-03-06 17:41:44 -0800195 sense = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
James Bottomley820732b2005-06-12 22:21:29 -0500196 if (!sense) {
197 err = -ENOMEM;
198 goto out;
199 }
200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 retry:
203 if (!scsi_block_when_processing_errors(SDev)) {
204 err = -ENODEV;
James Bottomley820732b2005-06-12 22:21:29 -0500205 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 }
207
James Bottomley820732b2005-06-12 22:21:29 -0500208 memset(sense, 0, sizeof(*sense));
209 result = scsi_execute(SDev, cgc->cmd, cgc->data_direction,
210 cgc->buffer, cgc->buflen, (char *)sense,
211 cgc->timeout, IOCTL_RETRIES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
James Bottomley820732b2005-06-12 22:21:29 -0500213 scsi_normalize_sense((char *)sense, sizeof(*sense), &sshdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 /* Minimal error checking. Ignore cases we know about, and report the rest. */
216 if (driver_byte(result) != 0) {
James Bottomley820732b2005-06-12 22:21:29 -0500217 switch (sshdr.sense_key) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 case UNIT_ATTENTION:
219 SDev->changed = 1;
220 if (!cgc->quiet)
221 printk(KERN_INFO "%s: disc change detected.\n", cd->cdi.name);
222 if (retries++ < 10)
223 goto retry;
224 err = -ENOMEDIUM;
225 break;
226 case NOT_READY: /* This happens if there is no disc in drive */
James Bottomley820732b2005-06-12 22:21:29 -0500227 if (sshdr.asc == 0x04 &&
228 sshdr.ascq == 0x01) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 /* sense: Logical unit is in process of becoming ready */
230 if (!cgc->quiet)
231 printk(KERN_INFO "%s: CDROM not ready yet.\n", cd->cdi.name);
232 if (retries++ < 10) {
233 /* sleep 2 sec and try again */
234 ssleep(2);
235 goto retry;
236 } else {
237 /* 20 secs are enough? */
238 err = -ENOMEDIUM;
239 break;
240 }
241 }
242 if (!cgc->quiet)
243 printk(KERN_INFO "%s: CDROM not ready. Make sure there is a disc in the drive.\n", cd->cdi.name);
244#ifdef DEBUG
James Bottomley820732b2005-06-12 22:21:29 -0500245 scsi_print_sense_hdr("sr", &sshdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246#endif
247 err = -ENOMEDIUM;
248 break;
249 case ILLEGAL_REQUEST:
250 err = -EIO;
James Bottomley820732b2005-06-12 22:21:29 -0500251 if (sshdr.asc == 0x20 &&
252 sshdr.ascq == 0x00)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 /* sense: Invalid command operation code */
254 err = -EDRIVE_CANT_DO_THIS;
255#ifdef DEBUG
256 __scsi_print_command(cgc->cmd);
James Bottomley820732b2005-06-12 22:21:29 -0500257 scsi_print_sense_hdr("sr", &sshdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#endif
259 break;
260 default:
261 printk(KERN_ERR "%s: CDROM (ioctl) error, command: ", cd->cdi.name);
262 __scsi_print_command(cgc->cmd);
James Bottomley820732b2005-06-12 22:21:29 -0500263 scsi_print_sense_hdr("sr", &sshdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 err = -EIO;
265 }
266 }
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 /* Wake up a process waiting for device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 out:
James Bottomley820732b2005-06-12 22:21:29 -0500270 if (!cgc->sense)
271 kfree(sense);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 cgc->stat = err;
273 return err;
274}
275
276/* ---------------------------------------------------------------------- */
277/* interface to cdrom.c */
278
279static int test_unit_ready(Scsi_CD *cd)
280{
281 struct packet_command cgc;
282
283 memset(&cgc, 0, sizeof(struct packet_command));
284 cgc.cmd[0] = GPCMD_TEST_UNIT_READY;
285 cgc.quiet = 1;
286 cgc.data_direction = DMA_NONE;
287 cgc.timeout = IOCTL_TIMEOUT;
288 return sr_do_ioctl(cd, &cgc);
289}
290
291int sr_tray_move(struct cdrom_device_info *cdi, int pos)
292{
293 Scsi_CD *cd = cdi->handle;
294 struct packet_command cgc;
295
296 memset(&cgc, 0, sizeof(struct packet_command));
297 cgc.cmd[0] = GPCMD_START_STOP_UNIT;
298 cgc.cmd[4] = (pos == 0) ? 0x03 /* close */ : 0x02 /* eject */ ;
299 cgc.data_direction = DMA_NONE;
300 cgc.timeout = IOCTL_TIMEOUT;
301 return sr_do_ioctl(cd, &cgc);
302}
303
304int sr_lock_door(struct cdrom_device_info *cdi, int lock)
305{
306 Scsi_CD *cd = cdi->handle;
307
308 return scsi_set_medium_removal(cd->device, lock ?
309 SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
310}
311
312int sr_drive_status(struct cdrom_device_info *cdi, int slot)
313{
314 if (CDSL_CURRENT != slot) {
315 /* we have no changer support */
316 return -EINVAL;
317 }
318 if (0 == test_unit_ready(cdi->handle))
319 return CDS_DISC_OK;
320
321 return CDS_TRAY_OPEN;
322}
323
324int sr_disk_status(struct cdrom_device_info *cdi)
325{
326 Scsi_CD *cd = cdi->handle;
327 struct cdrom_tochdr toc_h;
328 struct cdrom_tocentry toc_e;
329 int i, rc, have_datatracks = 0;
330
331 /* look for data tracks */
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100332 rc = sr_read_tochdr(cdi, &toc_h);
333 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 return (rc == -ENOMEDIUM) ? CDS_NO_DISC : CDS_NO_INFO;
335
336 for (i = toc_h.cdth_trk0; i <= toc_h.cdth_trk1; i++) {
337 toc_e.cdte_track = i;
338 toc_e.cdte_format = CDROM_LBA;
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100339 if (sr_read_tocentry(cdi, &toc_e))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return CDS_NO_INFO;
341 if (toc_e.cdte_ctrl & CDROM_DATA_TRACK) {
342 have_datatracks = 1;
343 break;
344 }
345 }
346 if (!have_datatracks)
347 return CDS_AUDIO;
348
349 if (cd->xa_flag)
350 return CDS_XA_2_1;
351 else
352 return CDS_DATA_1;
353}
354
355int sr_get_last_session(struct cdrom_device_info *cdi,
356 struct cdrom_multisession *ms_info)
357{
358 Scsi_CD *cd = cdi->handle;
359
360 ms_info->addr.lba = cd->ms_offset;
361 ms_info->xa_flag = cd->xa_flag || cd->ms_offset > 0;
362
363 return 0;
364}
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
367{
368 Scsi_CD *cd = cdi->handle;
369 struct packet_command cgc;
370 char *buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
371 int result;
372
Nate Dailey3a73e8c2005-04-21 16:14:05 -0400373 if (!buffer)
374 return -ENOMEM;
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 memset(&cgc, 0, sizeof(struct packet_command));
377 cgc.cmd[0] = GPCMD_READ_SUBCHANNEL;
378 cgc.cmd[2] = 0x40; /* I do want the subchannel info */
379 cgc.cmd[3] = 0x02; /* Give me medium catalog number info */
380 cgc.cmd[8] = 24;
381 cgc.buffer = buffer;
382 cgc.buflen = 24;
383 cgc.data_direction = DMA_FROM_DEVICE;
384 cgc.timeout = IOCTL_TIMEOUT;
385 result = sr_do_ioctl(cd, &cgc);
386
387 memcpy(mcn->medium_catalog_number, buffer + 9, 13);
388 mcn->medium_catalog_number[13] = 0;
389
390 kfree(buffer);
391 return result;
392}
393
394int sr_reset(struct cdrom_device_info *cdi)
395{
396 return 0;
397}
398
399int sr_select_speed(struct cdrom_device_info *cdi, int speed)
400{
401 Scsi_CD *cd = cdi->handle;
402 struct packet_command cgc;
403
404 if (speed == 0)
405 speed = 0xffff; /* set to max */
406 else
407 speed *= 177; /* Nx to kbyte/s */
408
409 memset(&cgc, 0, sizeof(struct packet_command));
410 cgc.cmd[0] = GPCMD_SET_SPEED; /* SET CD SPEED */
411 cgc.cmd[2] = (speed >> 8) & 0xff; /* MSB for speed (in kbytes/sec) */
412 cgc.cmd[3] = speed & 0xff; /* LSB */
413 cgc.data_direction = DMA_NONE;
414 cgc.timeout = IOCTL_TIMEOUT;
415
416 if (sr_do_ioctl(cd, &cgc))
417 return -EIO;
418 return 0;
419}
420
421/* ----------------------------------------------------------------------- */
422/* this is called by the generic cdrom driver. arg is a _kernel_ pointer, */
423/* because the generic cdrom driver does the user access stuff for us. */
424/* only cdromreadtochdr and cdromreadtocentry are left - for use with the */
425/* sr_disk_status interface for the generic cdrom driver. */
426
427int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
428{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 switch (cmd) {
430 case CDROMREADTOCHDR:
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100431 return sr_read_tochdr(cdi, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 case CDROMREADTOCENTRY:
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100433 return sr_read_tocentry(cdi, arg);
434 case CDROMPLAYTRKIND:
435 return sr_play_trkind(cdi, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 default:
Christoph Hellwiga09c6312006-01-11 14:28:06 +0100437 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439}
440
441/* -----------------------------------------------------------------------
442 * a function to read all sorts of funny cdrom sectors using the READ_CD
443 * scsi-3 mmc command
444 *
445 * lba: linear block address
446 * format: 0 = data (anything)
447 * 1 = audio
448 * 2 = data (mode 1)
449 * 3 = data (mode 2)
450 * 4 = data (mode 2 form1)
451 * 5 = data (mode 2 form2)
452 * blksize: 2048 | 2336 | 2340 | 2352
453 */
454
455static int sr_read_cd(Scsi_CD *cd, unsigned char *dest, int lba, int format, int blksize)
456{
457 struct packet_command cgc;
458
459#ifdef DEBUG
460 printk("%s: sr_read_cd lba=%d format=%d blksize=%d\n",
461 cd->cdi.name, lba, format, blksize);
462#endif
463
464 memset(&cgc, 0, sizeof(struct packet_command));
465 cgc.cmd[0] = GPCMD_READ_CD; /* READ_CD */
466 cgc.cmd[1] = ((format & 7) << 2);
467 cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
468 cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
469 cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
470 cgc.cmd[5] = (unsigned char) lba & 0xff;
471 cgc.cmd[8] = 1;
472 switch (blksize) {
473 case 2336:
474 cgc.cmd[9] = 0x58;
475 break;
476 case 2340:
477 cgc.cmd[9] = 0x78;
478 break;
479 case 2352:
480 cgc.cmd[9] = 0xf8;
481 break;
482 default:
483 cgc.cmd[9] = 0x10;
484 break;
485 }
486 cgc.buffer = dest;
487 cgc.buflen = blksize;
488 cgc.data_direction = DMA_FROM_DEVICE;
489 cgc.timeout = IOCTL_TIMEOUT;
490 return sr_do_ioctl(cd, &cgc);
491}
492
493/*
494 * read sectors with blocksizes other than 2048
495 */
496
497static int sr_read_sector(Scsi_CD *cd, int lba, int blksize, unsigned char *dest)
498{
499 struct packet_command cgc;
500 int rc;
501
502 /* we try the READ CD command first... */
503 if (cd->readcd_known) {
504 rc = sr_read_cd(cd, dest, lba, 0, blksize);
505 if (-EDRIVE_CANT_DO_THIS != rc)
506 return rc;
507 cd->readcd_known = 0;
508 printk("CDROM does'nt support READ CD (0xbe) command\n");
509 /* fall & retry the other way */
510 }
511 /* ... if this fails, we switch the blocksize using MODE SELECT */
512 if (blksize != cd->device->sector_size) {
513 if (0 != (rc = sr_set_blocklength(cd, blksize)))
514 return rc;
515 }
516#ifdef DEBUG
517 printk("%s: sr_read_sector lba=%d blksize=%d\n", cd->cdi.name, lba, blksize);
518#endif
519
520 memset(&cgc, 0, sizeof(struct packet_command));
521 cgc.cmd[0] = GPCMD_READ_10;
522 cgc.cmd[2] = (unsigned char) (lba >> 24) & 0xff;
523 cgc.cmd[3] = (unsigned char) (lba >> 16) & 0xff;
524 cgc.cmd[4] = (unsigned char) (lba >> 8) & 0xff;
525 cgc.cmd[5] = (unsigned char) lba & 0xff;
526 cgc.cmd[8] = 1;
527 cgc.buffer = dest;
528 cgc.buflen = blksize;
529 cgc.data_direction = DMA_FROM_DEVICE;
530 cgc.timeout = IOCTL_TIMEOUT;
531 rc = sr_do_ioctl(cd, &cgc);
532
533 return rc;
534}
535
536/*
537 * read a sector in raw mode to check the sector format
538 * ret: 1 == mode2 (XA), 0 == mode1, <0 == error
539 */
540
541int sr_is_xa(Scsi_CD *cd)
542{
543 unsigned char *raw_sector;
544 int is_xa;
545
546 if (!xa_test)
547 return 0;
548
549 raw_sector = (unsigned char *) kmalloc(2048, GFP_KERNEL | SR_GFP_DMA(cd));
550 if (!raw_sector)
551 return -ENOMEM;
552 if (0 == sr_read_sector(cd, cd->ms_offset + 16,
553 CD_FRAMESIZE_RAW1, raw_sector)) {
554 is_xa = (raw_sector[3] == 0x02) ? 1 : 0;
555 } else {
556 /* read a raw sector failed for some reason. */
557 is_xa = -1;
558 }
559 kfree(raw_sector);
560#ifdef DEBUG
561 printk("%s: sr_is_xa: %d\n", cd->cdi.name, is_xa);
562#endif
563 return is_xa;
564}