Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 1 | /* |
| 2 | * cdrom.c IOCTLs handling for ide-cd driver. |
| 3 | * |
| 4 | * Copyright (C) 1994-1996 Scott Snyder <snyder@fnald0.fnal.gov> |
| 5 | * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org> |
| 6 | * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/cdrom.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/gfp.h> |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 12 | #include <linux/ide.h> |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 13 | #include <scsi/scsi.h> |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 14 | |
| 15 | #include "ide-cd.h" |
| 16 | |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 17 | /**************************************************************************** |
| 18 | * Other driver requests (open, close, check media change). |
| 19 | */ |
| 20 | int ide_cdrom_open_real(struct cdrom_device_info *cdi, int purpose) |
| 21 | { |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | /* |
| 26 | * Close down the device. Invalidate all cached blocks. |
| 27 | */ |
| 28 | void ide_cdrom_release_real(struct cdrom_device_info *cdi) |
| 29 | { |
| 30 | ide_drive_t *drive = cdi->handle; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 31 | |
| 32 | if (!cdi->use_count) |
Borislav Petkov | 570f89e | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 33 | drive->atapi_flags &= ~IDE_AFLAG_TOC_VALID; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /* |
| 37 | * add logic to try GET_EVENT command first to check for media and tray |
| 38 | * status. this should be supported by newer cd-r/w and all DVD etc |
| 39 | * drives |
| 40 | */ |
| 41 | int ide_cdrom_drive_status(struct cdrom_device_info *cdi, int slot_nr) |
| 42 | { |
| 43 | ide_drive_t *drive = cdi->handle; |
| 44 | struct media_event_desc med; |
| 45 | struct request_sense sense; |
| 46 | int stat; |
| 47 | |
| 48 | if (slot_nr != CDSL_CURRENT) |
| 49 | return -EINVAL; |
| 50 | |
| 51 | stat = cdrom_check_status(drive, &sense); |
| 52 | if (!stat || sense.sense_key == UNIT_ATTENTION) |
| 53 | return CDS_DISC_OK; |
| 54 | |
| 55 | if (!cdrom_get_media_event(cdi, &med)) { |
| 56 | if (med.media_present) |
| 57 | return CDS_DISC_OK; |
| 58 | else if (med.door_open) |
| 59 | return CDS_TRAY_OPEN; |
| 60 | else |
| 61 | return CDS_NO_DISC; |
| 62 | } |
| 63 | |
| 64 | if (sense.sense_key == NOT_READY && sense.asc == 0x04 |
| 65 | && sense.ascq == 0x04) |
| 66 | return CDS_DISC_OK; |
| 67 | |
| 68 | /* |
| 69 | * If not using Mt Fuji extended media tray reports, |
| 70 | * just return TRAY_OPEN since ATAPI doesn't provide |
| 71 | * any other way to detect this... |
| 72 | */ |
| 73 | if (sense.sense_key == NOT_READY) { |
| 74 | if (sense.asc == 0x3a && sense.ascq == 1) |
| 75 | return CDS_NO_DISC; |
| 76 | else |
| 77 | return CDS_TRAY_OPEN; |
| 78 | } |
| 79 | return CDS_DRIVE_NOT_READY; |
| 80 | } |
| 81 | |
| 82 | int ide_cdrom_check_media_change_real(struct cdrom_device_info *cdi, |
| 83 | int slot_nr) |
| 84 | { |
| 85 | ide_drive_t *drive = cdi->handle; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 86 | int retval; |
| 87 | |
| 88 | if (slot_nr == CDSL_CURRENT) { |
| 89 | (void) cdrom_check_status(drive, NULL); |
Bartlomiej Zolnierkiewicz | fe11edf | 2008-10-17 18:09:11 +0200 | [diff] [blame] | 90 | retval = (drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED) ? 1 : 0; |
| 91 | drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 92 | return retval; |
| 93 | } else { |
| 94 | return -EINVAL; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /* Eject the disk if EJECTFLAG is 0. |
| 99 | If EJECTFLAG is 1, try to reload the disk. */ |
| 100 | static |
| 101 | int cdrom_eject(ide_drive_t *drive, int ejectflag, |
| 102 | struct request_sense *sense) |
| 103 | { |
| 104 | struct cdrom_info *cd = drive->driver_data; |
| 105 | struct cdrom_device_info *cdi = &cd->devinfo; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 106 | char loej = 0x02; |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 107 | unsigned char cmd[BLK_MAX_CDB]; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 108 | |
Borislav Petkov | 570f89e | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 109 | if ((drive->atapi_flags & IDE_AFLAG_NO_EJECT) && !ejectflag) |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 110 | return -EDRIVE_CANT_DO_THIS; |
| 111 | |
| 112 | /* reload fails on some drives, if the tray is locked */ |
Borislav Petkov | 570f89e | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 113 | if ((drive->atapi_flags & IDE_AFLAG_DOOR_LOCKED) && ejectflag) |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 114 | return 0; |
| 115 | |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 116 | /* only tell drive to close tray if open, if it can do that */ |
| 117 | if (ejectflag && (cdi->mask & CDC_CLOSE_TRAY)) |
| 118 | loej = 0; |
| 119 | |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 120 | memset(cmd, 0, BLK_MAX_CDB); |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 121 | |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 122 | cmd[0] = GPCMD_START_STOP_UNIT; |
| 123 | cmd[4] = loej | (ejectflag != 0); |
| 124 | |
Harvey Harrison | 1a677ab | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 125 | return ide_cd_queue_pc(drive, cmd, 0, NULL, NULL, sense, 0, 0); |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /* Lock the door if LOCKFLAG is nonzero; unlock it otherwise. */ |
| 129 | static |
| 130 | int ide_cd_lockdoor(ide_drive_t *drive, int lockflag, |
| 131 | struct request_sense *sense) |
| 132 | { |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 133 | struct request_sense my_sense; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 134 | int stat; |
| 135 | |
| 136 | if (sense == NULL) |
| 137 | sense = &my_sense; |
| 138 | |
| 139 | /* If the drive cannot lock the door, just pretend. */ |
Bartlomiej Zolnierkiewicz | 42619d3 | 2008-10-17 18:09:11 +0200 | [diff] [blame] | 140 | if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0) { |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 141 | stat = 0; |
| 142 | } else { |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 143 | unsigned char cmd[BLK_MAX_CDB]; |
| 144 | |
| 145 | memset(cmd, 0, BLK_MAX_CDB); |
| 146 | |
| 147 | cmd[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL; |
| 148 | cmd[4] = lockflag ? 1 : 0; |
| 149 | |
Harvey Harrison | 1a677ab | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 150 | stat = ide_cd_queue_pc(drive, cmd, 0, NULL, NULL, |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 151 | sense, 0, 0); |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /* If we got an illegal field error, the drive |
| 155 | probably cannot lock the door. */ |
| 156 | if (stat != 0 && |
| 157 | sense->sense_key == ILLEGAL_REQUEST && |
| 158 | (sense->asc == 0x24 || sense->asc == 0x20)) { |
| 159 | printk(KERN_ERR "%s: door locking not supported\n", |
| 160 | drive->name); |
Bartlomiej Zolnierkiewicz | 42619d3 | 2008-10-17 18:09:11 +0200 | [diff] [blame] | 161 | drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 162 | stat = 0; |
| 163 | } |
| 164 | |
| 165 | /* no medium, that's alright. */ |
| 166 | if (stat != 0 && sense->sense_key == NOT_READY && sense->asc == 0x3a) |
| 167 | stat = 0; |
| 168 | |
| 169 | if (stat == 0) { |
| 170 | if (lockflag) |
Borislav Petkov | 570f89e | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 171 | drive->atapi_flags |= IDE_AFLAG_DOOR_LOCKED; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 172 | else |
Borislav Petkov | 570f89e | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 173 | drive->atapi_flags &= ~IDE_AFLAG_DOOR_LOCKED; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | return stat; |
| 177 | } |
| 178 | |
| 179 | int ide_cdrom_tray_move(struct cdrom_device_info *cdi, int position) |
| 180 | { |
| 181 | ide_drive_t *drive = cdi->handle; |
| 182 | struct request_sense sense; |
| 183 | |
| 184 | if (position) { |
| 185 | int stat = ide_cd_lockdoor(drive, 0, &sense); |
| 186 | |
| 187 | if (stat) |
| 188 | return stat; |
| 189 | } |
| 190 | |
| 191 | return cdrom_eject(drive, !position, &sense); |
| 192 | } |
| 193 | |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 194 | int ide_cdrom_lock_door(struct cdrom_device_info *cdi, int lock) |
| 195 | { |
| 196 | ide_drive_t *drive = cdi->handle; |
| 197 | |
| 198 | return ide_cd_lockdoor(drive, lock, NULL); |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | * ATAPI devices are free to select the speed you request or any slower |
| 203 | * rate. :-( Requesting too fast a speed will _not_ produce an error. |
| 204 | */ |
| 205 | int ide_cdrom_select_speed(struct cdrom_device_info *cdi, int speed) |
| 206 | { |
| 207 | ide_drive_t *drive = cdi->handle; |
| 208 | struct cdrom_info *cd = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 209 | struct request_sense sense; |
| 210 | u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE]; |
| 211 | int stat; |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 212 | unsigned char cmd[BLK_MAX_CDB]; |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 213 | |
| 214 | if (speed == 0) |
| 215 | speed = 0xffff; /* set to max */ |
| 216 | else |
| 217 | speed *= 177; /* Nx to kbytes/s */ |
| 218 | |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 219 | memset(cmd, 0, BLK_MAX_CDB); |
| 220 | |
| 221 | cmd[0] = GPCMD_SET_SPEED; |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 222 | /* Read Drive speed in kbytes/second MSB/LSB */ |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 223 | cmd[2] = (speed >> 8) & 0xff; |
| 224 | cmd[3] = speed & 0xff; |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 225 | if ((cdi->mask & (CDC_CD_R | CDC_CD_RW | CDC_DVD_R)) != |
| 226 | (CDC_CD_R | CDC_CD_RW | CDC_DVD_R)) { |
| 227 | /* Write Drive speed in kbytes/second MSB/LSB */ |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 228 | cmd[4] = (speed >> 8) & 0xff; |
| 229 | cmd[5] = speed & 0xff; |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 230 | } |
| 231 | |
Harvey Harrison | 1a677ab | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 232 | stat = ide_cd_queue_pc(drive, cmd, 0, NULL, NULL, &sense, 0, 0); |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 233 | |
| 234 | if (!ide_cdrom_get_capabilities(drive, buf)) { |
| 235 | ide_cdrom_update_speed(drive, buf); |
| 236 | cdi->speed = cd->current_speed; |
| 237 | } |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | int ide_cdrom_get_last_session(struct cdrom_device_info *cdi, |
| 243 | struct cdrom_multisession *ms_info) |
| 244 | { |
| 245 | struct atapi_toc *toc; |
| 246 | ide_drive_t *drive = cdi->handle; |
| 247 | struct cdrom_info *info = drive->driver_data; |
| 248 | struct request_sense sense; |
| 249 | int ret; |
| 250 | |
Borislav Petkov | 570f89e | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 251 | if ((drive->atapi_flags & IDE_AFLAG_TOC_VALID) == 0 || !info->toc) { |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 252 | ret = ide_cd_read_toc(drive, &sense); |
| 253 | if (ret) |
| 254 | return ret; |
| 255 | } |
| 256 | |
| 257 | toc = info->toc; |
| 258 | ms_info->addr.lba = toc->last_session_lba; |
| 259 | ms_info->xa_flag = toc->xa_flag; |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | int ide_cdrom_get_mcn(struct cdrom_device_info *cdi, |
| 265 | struct cdrom_mcn *mcn_info) |
| 266 | { |
| 267 | ide_drive_t *drive = cdi->handle; |
| 268 | int stat, mcnlen; |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 269 | char buf[24]; |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 270 | unsigned char cmd[BLK_MAX_CDB]; |
| 271 | unsigned len = sizeof(buf); |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 272 | |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 273 | memset(cmd, 0, BLK_MAX_CDB); |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 274 | |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 275 | cmd[0] = GPCMD_READ_SUBCHANNEL; |
| 276 | cmd[1] = 2; /* MSF addressing */ |
| 277 | cmd[2] = 0x40; /* request subQ data */ |
| 278 | cmd[3] = 2; /* format */ |
| 279 | cmd[8] = len; |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 280 | |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 281 | stat = ide_cd_queue_pc(drive, cmd, 0, buf, &len, NULL, 0, 0); |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 282 | if (stat) |
| 283 | return stat; |
| 284 | |
| 285 | mcnlen = sizeof(mcn_info->medium_catalog_number) - 1; |
| 286 | memcpy(mcn_info->medium_catalog_number, buf + 9, mcnlen); |
| 287 | mcn_info->medium_catalog_number[mcnlen] = '\0'; |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | int ide_cdrom_reset(struct cdrom_device_info *cdi) |
| 293 | { |
| 294 | ide_drive_t *drive = cdi->handle; |
| 295 | struct cdrom_info *cd = drive->driver_data; |
| 296 | struct request_sense sense; |
FUJITA Tomonori | 0ef4c4d | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 297 | struct request *rq; |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 298 | int ret; |
| 299 | |
FUJITA Tomonori | 0ef4c4d | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 300 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); |
| 301 | rq->cmd_type = REQ_TYPE_SPECIAL; |
| 302 | rq->cmd_flags = REQ_QUIET; |
| 303 | ret = blk_execute_rq(drive->queue, cd->disk, rq, 0); |
| 304 | blk_put_request(rq); |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 305 | /* |
| 306 | * A reset will unlock the door. If it was previously locked, |
| 307 | * lock it again. |
| 308 | */ |
Borislav Petkov | 570f89e | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 309 | if (drive->atapi_flags & IDE_AFLAG_DOOR_LOCKED) |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 310 | (void)ide_cd_lockdoor(drive, 1, &sense); |
| 311 | |
| 312 | return ret; |
| 313 | } |
| 314 | |
| 315 | static int ide_cd_get_toc_entry(ide_drive_t *drive, int track, |
| 316 | struct atapi_toc_entry **ent) |
| 317 | { |
| 318 | struct cdrom_info *info = drive->driver_data; |
| 319 | struct atapi_toc *toc = info->toc; |
| 320 | int ntracks; |
| 321 | |
| 322 | /* |
| 323 | * don't serve cached data, if the toc isn't valid |
| 324 | */ |
Borislav Petkov | 570f89e | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 325 | if ((drive->atapi_flags & IDE_AFLAG_TOC_VALID) == 0) |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 326 | return -EINVAL; |
| 327 | |
| 328 | /* Check validity of requested track number. */ |
| 329 | ntracks = toc->hdr.last_track - toc->hdr.first_track + 1; |
| 330 | |
| 331 | if (toc->hdr.first_track == CDROM_LEADOUT) |
| 332 | ntracks = 0; |
| 333 | |
| 334 | if (track == CDROM_LEADOUT) |
| 335 | *ent = &toc->ent[ntracks]; |
| 336 | else if (track < toc->hdr.first_track || track > toc->hdr.last_track) |
| 337 | return -EINVAL; |
| 338 | else |
| 339 | *ent = &toc->ent[track - toc->hdr.first_track]; |
| 340 | |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | static int ide_cd_fake_play_trkind(ide_drive_t *drive, void *arg) |
| 345 | { |
| 346 | struct cdrom_ti *ti = arg; |
| 347 | struct atapi_toc_entry *first_toc, *last_toc; |
| 348 | unsigned long lba_start, lba_end; |
| 349 | int stat; |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 350 | struct request_sense sense; |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 351 | unsigned char cmd[BLK_MAX_CDB]; |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 352 | |
| 353 | stat = ide_cd_get_toc_entry(drive, ti->cdti_trk0, &first_toc); |
| 354 | if (stat) |
| 355 | return stat; |
| 356 | |
| 357 | stat = ide_cd_get_toc_entry(drive, ti->cdti_trk1, &last_toc); |
| 358 | if (stat) |
| 359 | return stat; |
| 360 | |
| 361 | if (ti->cdti_trk1 != CDROM_LEADOUT) |
| 362 | ++last_toc; |
| 363 | lba_start = first_toc->addr.lba; |
| 364 | lba_end = last_toc->addr.lba; |
| 365 | |
| 366 | if (lba_end <= lba_start) |
| 367 | return -EINVAL; |
| 368 | |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 369 | memset(cmd, 0, BLK_MAX_CDB); |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 370 | |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 371 | cmd[0] = GPCMD_PLAY_AUDIO_MSF; |
| 372 | lba_to_msf(lba_start, &cmd[3], &cmd[4], &cmd[5]); |
| 373 | lba_to_msf(lba_end - 1, &cmd[6], &cmd[7], &cmd[8]); |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 374 | |
Harvey Harrison | 1a677ab | 2008-07-23 19:56:02 +0200 | [diff] [blame] | 375 | return ide_cd_queue_pc(drive, cmd, 0, NULL, NULL, &sense, 0, 0); |
Bartlomiej Zolnierkiewicz | 1780299 | 2008-02-01 23:09:25 +0100 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | static int ide_cd_read_tochdr(ide_drive_t *drive, void *arg) |
| 379 | { |
| 380 | struct cdrom_info *cd = drive->driver_data; |
| 381 | struct cdrom_tochdr *tochdr = arg; |
| 382 | struct atapi_toc *toc; |
| 383 | int stat; |
| 384 | |
| 385 | /* Make sure our saved TOC is valid. */ |
| 386 | stat = ide_cd_read_toc(drive, NULL); |
| 387 | if (stat) |
| 388 | return stat; |
| 389 | |
| 390 | toc = cd->toc; |
| 391 | tochdr->cdth_trk0 = toc->hdr.first_track; |
| 392 | tochdr->cdth_trk1 = toc->hdr.last_track; |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static int ide_cd_read_tocentry(ide_drive_t *drive, void *arg) |
| 398 | { |
| 399 | struct cdrom_tocentry *tocentry = arg; |
| 400 | struct atapi_toc_entry *toce; |
| 401 | int stat; |
| 402 | |
| 403 | stat = ide_cd_get_toc_entry(drive, tocentry->cdte_track, &toce); |
| 404 | if (stat) |
| 405 | return stat; |
| 406 | |
| 407 | tocentry->cdte_ctrl = toce->control; |
| 408 | tocentry->cdte_adr = toce->adr; |
| 409 | if (tocentry->cdte_format == CDROM_MSF) { |
| 410 | lba_to_msf(toce->addr.lba, |
| 411 | &tocentry->cdte_addr.msf.minute, |
| 412 | &tocentry->cdte_addr.msf.second, |
| 413 | &tocentry->cdte_addr.msf.frame); |
| 414 | } else |
| 415 | tocentry->cdte_addr.lba = toce->addr.lba; |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | int ide_cdrom_audio_ioctl(struct cdrom_device_info *cdi, |
| 421 | unsigned int cmd, void *arg) |
| 422 | { |
| 423 | ide_drive_t *drive = cdi->handle; |
| 424 | |
| 425 | switch (cmd) { |
| 426 | /* |
| 427 | * emulate PLAY_AUDIO_TI command with PLAY_AUDIO_10, since |
| 428 | * atapi doesn't support it |
| 429 | */ |
| 430 | case CDROMPLAYTRKIND: |
| 431 | return ide_cd_fake_play_trkind(drive, arg); |
| 432 | case CDROMREADTOCHDR: |
| 433 | return ide_cd_read_tochdr(drive, arg); |
| 434 | case CDROMREADTOCENTRY: |
| 435 | return ide_cd_read_tocentry(drive, arg); |
| 436 | default: |
| 437 | return -EINVAL; |
| 438 | } |
| 439 | } |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 440 | |
| 441 | /* the generic packet interface to cdrom.c */ |
| 442 | int ide_cdrom_packet(struct cdrom_device_info *cdi, |
| 443 | struct packet_command *cgc) |
| 444 | { |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 445 | ide_drive_t *drive = cdi->handle; |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 446 | unsigned int flags = 0; |
| 447 | unsigned len = cgc->buflen; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 448 | |
| 449 | if (cgc->timeout <= 0) |
| 450 | cgc->timeout = ATAPI_WAIT_PC; |
| 451 | |
| 452 | /* here we queue the commands from the uniform CD-ROM |
| 453 | layer. the packet must be complete, as we do not |
| 454 | touch it at all. */ |
Bartlomiej Zolnierkiewicz | b348487 | 2008-03-07 21:53:49 +0100 | [diff] [blame] | 455 | |
| 456 | if (cgc->data_direction == CGC_DATA_WRITE) |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 457 | flags |= REQ_WRITE; |
Bartlomiej Zolnierkiewicz | b348487 | 2008-03-07 21:53:49 +0100 | [diff] [blame] | 458 | |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 459 | if (cgc->sense) |
| 460 | memset(cgc->sense, 0, sizeof(struct request_sense)); |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 461 | |
| 462 | if (cgc->quiet) |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 463 | flags |= REQ_QUIET; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 464 | |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 465 | cgc->stat = ide_cd_queue_pc(drive, cgc->cmd, |
| 466 | cgc->data_direction == CGC_DATA_WRITE, |
| 467 | cgc->buffer, &len, |
| 468 | cgc->sense, cgc->timeout, flags); |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 469 | if (!cgc->stat) |
FUJITA Tomonori | 5f82854 | 2008-07-15 21:21:42 +0200 | [diff] [blame] | 470 | cgc->buflen -= len; |
Borislav Petkov | f9afd18 | 2008-02-01 23:09:29 +0100 | [diff] [blame] | 471 | return cgc->stat; |
| 472 | } |