root/drivers/block/ide-cd.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. cdrom_decode_status
  2. cdrom_start_packet_command
  3. cdrom_transfer_packet_command
  4. cdrom_read_intr_2
  5. cdrom_read_intr
  6. cdrom_start_read_continuation
  7. cdrom_start_read
  8. cdrom_pc_intr
  9. cdrom_do_pc_continuation
  10. cdrom_do_packet_command
  11. cdrom_queue_packet_command
  12. do_rw_cdrom
  13. byte_swap_word
  14. byte_swap_long
  15. bin2bcd
  16. lba_to_msf
  17. msf_to_lba
  18. cdrom_check_status
  19. cdrom_request_sense
  20. cdrom_lockdoor
  21. cdrom_eject
  22. cdrom_pause
  23. cdrom_startstop
  24. cdrom_read_tocentry
  25. cdrom_read_toc
  26. cdrom_read_subchannel
  27. cdrom_mode_sense
  28. cdrom_mode_select
  29. cdrom_play_lba_range_play12
  30. cdrom_play_lba_range_msf
  31. cdrom_play_lba_range
  32. cdrom_get_toc_entry
  33. ide_cdrom_ioctl
  34. cdrom_check_media_change
  35. cdrom_open
  36. cdrom_release
  37. cdrom_setup

   1 /*
   2  * linux/drivers/block/ide-cd.c  (ALPHA)
   3  *
   4  * 1.00  Oct 31, 1994 -- Initial version.
   5  * 1.01  Nov  2, 1994 -- Fixed problem with starting request in
   6  *                       cdrom_check_status.
   7  * 1.03  Nov 25, 1994 -- leaving unmask_intr[] as a user-setting (as for disks)
   8  * (from mlord)       -- minor changes to cdrom_setup()
   9  *                    -- renamed ide_dev_s to ide_dev_t, enable irq on command
  10  * 2.00  Nov 27, 1994 -- Generalize packet command interface;
  11  *                       add audio ioctls.
  12  * 2.01  Dec  3, 1994 -- Rework packet command interface to handle devices
  13  *                       which send an interrupt when ready for a command.
  14  * 2.02  Dec 11, 1994 -- Cache the TOC in the driver.
  15  *                       Don't use SCMD_PLAYAUDIO_TI; it's not included
  16  *                       in the current version of ATAPI.
  17  *                       Try to use LBA instead of track or MSF addressing
  18  *                       when possible.
  19  *                       Don't wait for READY_STAT.
  20  *
  21  * ATAPI cd-rom driver.  To be used with ide.c.
  22  *
  23  * Copyright (C) 1994  scott snyder  <snyder@fnald0.fnal.gov>
  24  */
  25 
  26 #include <linux/cdrom.h>
  27 
  28 #define BLOCKS_PER_FRAME (CD_FRAMESIZE / 512)
  29 
  30 #define OUT_WORDS(b,n)  outsw (IDE_PORT (HD_DATA, dev->hwif), (b), (n))
  31 #define IN_WORDS(b,n)   insw  (IDE_PORT (HD_DATA, dev->hwif), (b), (n))
  32 
  33 /* special command codes for strategy routine. */
  34 #define PACKET_COMMAND 4315
  35 
  36 #define WIN_PACKETCMD 0xa0  /* Send a packet command. */
  37 
  38 /* Some ATAPI command opcodes (just like SCSI).
  39    (Some other cdrom-specific codes are in cdrom.h.) */
  40 #define TEST_UNIT_READY         0x00
  41 #define REQUEST_SENSE           0x03
  42 #define START_STOP              0x1b
  43 #define ALLOW_MEDIUM_REMOVAL    0x1e
  44 #define READ_10                 0x28
  45 #define MODE_SENSE_10           0x5a
  46 #define MODE_SELECT_10          0x55
  47 
  48 struct packet_command {
  49   char *buffer;
  50   int buflen;
  51   int stat;
  52   unsigned char c[12];
  53 };
  54 
  55 
  56 struct atapi_request_sense {
  57   unsigned char error_code : 7;
  58   unsigned char valid      : 1;
  59   byte reserved1;
  60   unsigned char sense_key  : 4;
  61   unsigned char reserved2  : 1;
  62   unsigned char ili        : 1;
  63   unsigned char reserved3  : 2;
  64   byte info[4];
  65   byte sense_len;
  66   byte command_info[4];
  67   byte asc;
  68   byte ascq;
  69   byte fru;
  70   byte sense_key_specific[3];
  71 };
  72 
  73 /* We want some additional flags for cd-rom drives.
  74    To save space in the ide_dev_t struct, use one of the fields which
  75    doesn't make sense for cd-roms -- `bios_sect'. */
  76 
  77 struct ide_cd_flags {
  78   unsigned drq_interrupt : 1; /* Device sends an interrupt when ready
  79                                  for a packet command. */
  80   unsigned no_playaudio12: 1; /* The PLAYAUDIO12 command is not supported. */
  81 
  82   unsigned media_changed : 1; /* Driver has noticed a media change. */
  83   unsigned toc_valid     : 1; /* Saved TOC information is current. */
  84   unsigned reserved : 4;
  85 };
  86 
  87 #define CDROM_FLAGS(dev) ((struct ide_cd_flags *)&((dev)->bios_sect))
  88 
  89 
  90 /* Space to hold the disk TOC. */
  91 
  92 #define MAX_TRACKS 99
  93 struct atapi_toc_header {
  94   unsigned short toc_length;
  95   byte first_track;
  96   byte last_track;
  97 };
  98 
  99 struct atapi_toc_entry {
 100   byte reserved1;
 101   unsigned control : 4;
 102   unsigned adr     : 4;
 103   byte track;
 104   byte reserved2;
 105   unsigned lba;
 106 };
 107 
 108 struct atapi_toc {
 109   struct atapi_toc_header hdr;
 110   struct atapi_toc_entry  ent[MAX_TRACKS+1];
 111 };
 112 
 113 
 114 static struct atapi_toc *cdrom_toc[2][MAX_DRIVES];
 115 
 116 
 117 
 118 /****************************************************************************
 119  * Generic packet command support routines.
 120  */
 121 
 122 /* Returns 0 if the request should be continued.
 123    Returns 1 if the request was ended. */
 124 static int cdrom_decode_status (ide_dev_t *dev, int good_stat, int *stat_ret)
     /* [previous][next][first][last][top][bottom][index][help] */
 125 {
 126   struct request *rq = ide_cur_rq[dev->hwif];
 127   int stat, err;
 128 
 129   /* Check for errors. */
 130   stat = GET_STAT (dev->hwif);
 131   *stat_ret = stat;
 132 
 133   if (OK_STAT (stat, good_stat, BAD_RW_STAT))
 134     return 0;
 135 
 136   /* Got an error. */
 137   err = IN_BYTE (HD_ERROR, dev->hwif);
 138 
 139   /* Check for tray open */
 140   if ((err & 0xf0) == 0x20)
 141     {
 142       struct packet_command *pc;
 143       CDROM_FLAGS (dev)->media_changed = 1;
 144       CDROM_FLAGS (dev)->toc_valid = 0;
 145 
 146       /* Fail the request if this is a read command. */
 147       if (rq->cmd == READ)
 148         {
 149           printk ("%s : tray open\n", dev->name);
 150           end_request (0, dev->hwif);
 151         }
 152 
 153       else
 154         {
 155           /* Otherwise, it's some other packet command.
 156              Print an error message to the syslog.
 157              Exception: don't print anything if this is a read subchannel
 158              command.  This is because workman constantly polls the drive
 159              with this command, and we don't want to uselessly fill up
 160              the syslog. */
 161           pc = (struct packet_command *)rq->buffer;
 162           if (pc->c[0] != SCMD_READ_SUBCHANNEL)
 163             printk ("%s : tray open\n", dev->name);
 164 
 165           /* Set the error flag and complete the request. */
 166           pc->stat = 1;
 167           end_request (1, dev->hwif);
 168         }
 169     }
 170 
 171   /* Check for media change. */
 172   else if ((err & 0xf0) == 0x60)
 173     {
 174       CDROM_FLAGS (dev)->media_changed = 1;
 175       CDROM_FLAGS (dev)->toc_valid = 0;
 176       printk ("%s: media changed\n", dev->name);
 177 
 178       /* We're going to retry this command.
 179          But be sure to give up if we've retried too many times. */
 180       if ((++rq->errors > ERROR_MAX))
 181         {
 182           end_request (0, dev->hwif);
 183         }
 184     }
 185 
 186   /* Don't attempt to retry if this was a packet command. */
 187   else if (rq->cmd == PACKET_COMMAND)
 188     {
 189       struct packet_command *pc = (struct packet_command *)rq->buffer;
 190       dump_status (dev->hwif, "packet command error", stat);
 191       pc->stat = 1;  /* signal error */
 192       end_request (1, dev->hwif);
 193     }
 194 
 195   /* If there were other errors, go to the default handler. */
 196   else if ((err & ~ABRT_ERR) != 0)
 197     {
 198       ide_error (dev, "cdrom_read_intr", stat);
 199     }
 200 
 201   /* Else, abort if we've racked up too many retries. */
 202   else if ((++rq->errors > ERROR_MAX))
 203     {
 204       end_request (0, dev->hwif);
 205     }
 206 
 207   /* Retry, or handle the next request. */
 208   DO_REQUEST;
 209   return 1;
 210 }
 211 
 212 
 213 /* Set up the device registers for transferring a packet command on DEV,
 214    expecting to later transfer XFERLEN bytes.  This should be followed
 215    by a call to cdrom_transfer_packet_command; however, if this is a
 216    drq_interrupt device, one must wait for an interrupt first. */
 217 static int cdrom_start_packet_command (ide_dev_t *dev, int xferlen)
     /* [previous][next][first][last][top][bottom][index][help] */
 218 {
 219   /* Wait for the controller to be idle. */
 220   if (wait_stat (dev, 0, BUSY_STAT, WAIT_READY)) return 1;
 221 
 222   /* Set up the controller registers. */
 223   OUT_BYTE (0, HD_FEATURE);
 224   OUT_BYTE (0, HD_NSECTOR);
 225   OUT_BYTE (0, HD_SECTOR);
 226 
 227   OUT_BYTE (xferlen & 0xff, HD_LCYL);
 228   OUT_BYTE (xferlen >> 8  , HD_HCYL);
 229   OUT_BYTE (dev->ctl, HD_CMD);
 230   OUT_BYTE (WIN_PACKETCMD, HD_COMMAND); /* packet command */
 231 
 232   return 0;
 233 }
 234 
 235 
 236 /* Send a packet command to DEV described by CMD_BUF and CMD_LEN.
 237    The device registers must have already been prepared
 238    by cdrom_start_packet_command. */
 239 static int cdrom_transfer_packet_command (ide_dev_t *dev,
     /* [previous][next][first][last][top][bottom][index][help] */
 240                                           char *cmd_buf, int cmd_len)
 241 {
 242   if (CDROM_FLAGS (dev)->drq_interrupt)
 243     {
 244       /* Here we should have been called after receiving an interrupt
 245          from the device.  DRQ should how be set. */
 246       int stat_dum;
 247 
 248       /* Check for errors. */
 249       if (cdrom_decode_status (dev, DRQ_STAT, &stat_dum)) return 1;
 250     }
 251   else
 252     {
 253       /* Otherwise, we must wait for DRQ to get set. */
 254       if (wait_stat (dev, DRQ_STAT, BAD_STAT, WAIT_READY)) return 1;
 255     }
 256 
 257   /* Send the command to the device. */
 258   OUT_WORDS (cmd_buf, cmd_len/2);
 259 
 260   return 0;
 261 }
 262 
 263 
 264 
 265 /****************************************************************************
 266  * Block read functions.
 267  */
 268 
 269 static int cdrom_start_read (ide_dev_t *dev, unsigned int block);
 270 
 271 
 272 /*
 273  * Interrupt routine to read the final status from a transfer.
 274  */
 275 static void cdrom_read_intr_2 (ide_dev_t *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 276 {
 277   int stat;
 278   struct request *rq = ide_cur_rq[dev->hwif];
 279 
 280   stat = GET_STAT (dev->hwif);
 281 
 282   if (OK_STAT (stat, 0, BAD_STAT))
 283     {
 284       if (rq->current_nr_sectors <= 0)
 285         {
 286           end_request (1, dev->hwif);
 287         }
 288 
 289       if (rq->current_nr_sectors > 0)
 290         {
 291           cdrom_start_read (dev, rq->sector);
 292           return;
 293         }
 294     }
 295   else
 296     ide_error (dev, "cdrom_read_intr_2", stat);
 297 
 298   DO_REQUEST;
 299 }
 300 
 301 
 302 /*
 303  * Interrupt routine.  Called when a read request has completed.
 304  */
 305 static void cdrom_read_intr (ide_dev_t *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 306 {
 307   int stat_dum, len;
 308   struct request *rq = ide_cur_rq[dev->hwif];
 309 
 310   /* Check for errors. */
 311   if (cdrom_decode_status (dev, DRQ_STAT, &stat_dum)) return;
 312 
 313   /* Error bit not set.
 314      Read the device registers to see how much data is waiting. */
 315   len = IN_BYTE (HD_LCYL, dev->hwif) + 256 * IN_BYTE (HD_HCYL, dev->hwif);
 316 
 317   if (len != CD_FRAMESIZE)
 318     {
 319       printk ("cdrom_read_intr: funny value for read length %d\n", len);
 320       if (len > CD_FRAMESIZE) len = CD_FRAMESIZE;
 321     }
 322 
 323   IN_WORDS (rq->buffer, len/2);
 324 
 325   rq->current_nr_sectors -= BLOCKS_PER_FRAME;
 326   rq->nr_sectors -= BLOCKS_PER_FRAME;
 327   rq->sector += BLOCKS_PER_FRAME;
 328   rq->buffer += CD_FRAMESIZE;
 329 
 330   /* Wait for another interrupt with the final status. */
 331   ide_handler[dev->hwif] = cdrom_read_intr_2;
 332 }
 333 
 334 
 335 /*
 336  * Routine to send a read packet command to the drive.
 337  * This is usually called directly from cdrom_start_read.
 338  * However, for drq_interrupt devices, it is called from an interrupt
 339  * when the drive is ready to accept the command.
 340  */
 341 static int cdrom_start_read_continuation (ide_dev_t *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 342 {
 343   struct packet_command pc;
 344   struct request *rq = ide_cur_rq[dev->hwif];
 345 
 346   /* Set up the command */
 347   memset (&pc.c, 0, sizeof (pc.c));
 348   pc.c[0] = READ_10;
 349   pc.c[8] = 1;  /* lsb of transfer length */
 350 
 351   /* Write the sector address into the command image. */
 352   {
 353     union {
 354       struct {unsigned char b0, b1, b2, b3;} b;
 355       struct {unsigned long l0;} l;
 356     } conv;
 357     conv.l.l0 = rq->sector / BLOCKS_PER_FRAME;
 358     pc.c[2] = conv.b.b3;
 359     pc.c[3] = conv.b.b2;
 360     pc.c[4] = conv.b.b1;
 361     pc.c[5] = conv.b.b0;
 362   }
 363 
 364   if (cdrom_transfer_packet_command (dev, pc.c, sizeof (pc.c)))
 365     return 1;
 366 
 367   /* Set up our interrupt handler and return. */
 368   ide_handler[dev->hwif] = cdrom_read_intr;
 369 
 370   return 0;
 371 }
 372 
 373 
 374 /*
 375  * Start a read request from the CD-ROM.
 376  * Returns 0 if the request was started successfully,
 377  *  1 if there was an error and we should either retry or move on to the
 378  *  next request.
 379  */
 380 static int cdrom_start_read (ide_dev_t *dev, unsigned int block)
     /* [previous][next][first][last][top][bottom][index][help] */
 381 {
 382   struct request *rq = ide_cur_rq[dev->hwif];
 383 
 384   if (rq->cmd == READ &&
 385       (rq->current_nr_sectors != BLOCKS_PER_FRAME ||
 386        (rq->sector & (BLOCKS_PER_FRAME-1)) != 0))
 387         {
 388           printk ("cdrom_start_read: funny request 0x%lx 0x%lx\n",
 389                   rq->current_nr_sectors, rq->sector);
 390           end_request (0, dev->hwif);
 391           return 1;
 392         }
 393 
 394   if (cdrom_start_packet_command (dev, CD_FRAMESIZE))
 395     return 1;
 396 
 397   if (CDROM_FLAGS (dev)->drq_interrupt)
 398     ide_handler[dev->hwif] = (void (*)(ide_dev_t *))cdrom_start_read_continuation;
 399   else
 400     {
 401       if (cdrom_start_read_continuation (dev))
 402         return 1;
 403     }
 404 
 405   return 0;
 406 }
 407 
 408 
 409 
 410 /****************************************************************************
 411  * Execute all other packet commands.
 412  */
 413 
 414 static void cdrom_pc_intr (ide_dev_t *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 415 {
 416   int ireason, len, stat, thislen;
 417   struct request *rq = ide_cur_rq[dev->hwif];
 418   struct packet_command *pc = (struct packet_command *)rq->buffer;
 419 
 420   /* Check for errors. */
 421   if (cdrom_decode_status (dev, 0, &stat)) return;
 422 
 423   /* Read the interrupt reason and the transfer length. */
 424   ireason = IN_BYTE (HD_NSECTOR, dev->hwif);
 425   len = IN_BYTE (HD_LCYL, dev->hwif) + 256 * IN_BYTE (HD_HCYL, dev->hwif);
 426 
 427   /* If DRQ is clear, the command has completed.
 428      Complain if we still have data left to transfer. */
 429   if ((stat & DRQ_STAT) == 0)
 430     {
 431       if (pc->buflen == 0)
 432         end_request (1, dev->hwif);
 433       else
 434         {
 435           printk ("%s: cdrom_pc_intr: data underrun %d\n",
 436                   dev->name, pc->buflen);
 437           pc->stat = 1;
 438           end_request (1, dev->hwif);
 439         }
 440       DO_REQUEST;
 441       return;
 442     }
 443 
 444   /* Figure out how much data to transfer. */
 445   thislen = pc->buflen;
 446   if (thislen < 0) thislen = -thislen;
 447   if (thislen > len) thislen = len;
 448 
 449   /* The drive wants to be written to. */
 450   if ((ireason & 3) == 0)
 451     {
 452       /* Check that we want to write. */
 453       if (pc->buflen > 0)
 454         {
 455           printk ("%s: cdrom_pc_intr: Drive wants to transfer data the wrong way!\n",
 456                   dev->name);
 457           pc->stat = 1;
 458           thislen = 0;
 459         }
 460 
 461       /* Transfer the data. */
 462       OUT_WORDS (pc->buffer, thislen / 2);
 463 
 464       /* If we haven't moved enough data to satisfy the drive,
 465          add some padding. */
 466       while (len > thislen)
 467         {
 468           short dum = 0;
 469           OUT_WORDS (&dum, 1);
 470           len -= 2;
 471         }
 472 
 473       /* Keep count of how much data we've moved. */
 474       pc->buffer += thislen;
 475       pc->buflen += thislen;
 476     }
 477 
 478   /* Same drill for reading. */
 479   else if ((ireason & 3) == 2)
 480     {
 481       /* Check that we want to read. */
 482       if (pc->buflen < 0)
 483         {
 484           printk ("%s: cdrom_pc_intr: Drive wants to transfer data the wrong way!\n",
 485                   dev->name);
 486           pc->stat = 1;
 487           thislen = 0;
 488         }
 489 
 490       /* Transfer the data. */
 491       IN_WORDS (pc->buffer, thislen / 2);
 492 
 493       /* If we haven't moved enough data to satisfy the drive,
 494          add some padding. */
 495       while (len > thislen)
 496         {
 497           short dum = 0;
 498           IN_WORDS (&dum, 1);
 499           len -= 2;
 500         }
 501 
 502       /* Keep count of how much data we've moved. */
 503       pc->buffer += thislen;
 504       pc->buflen -= thislen;
 505     }
 506 
 507   else
 508     {
 509       printk ("%s: cdrom_pc_intr: The drive appears confused (ireason = 0x%2x)\n",
 510               dev->name, ireason);
 511       pc->stat = 1;
 512     }
 513 
 514   /* Now we wait for another interrupt. */
 515   ide_handler[dev->hwif] = cdrom_pc_intr;
 516 }
 517 
 518 
 519 static int cdrom_do_pc_continuation (ide_dev_t *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 520 {
 521   struct request *rq = ide_cur_rq[dev->hwif];
 522   struct packet_command *pc = (struct packet_command *)rq->buffer;
 523 
 524   if (cdrom_transfer_packet_command (dev, pc->c, sizeof (pc->c)))
 525     return 1;
 526 
 527   /* Set up our interrupt handler and return. */
 528   ide_handler[dev->hwif] = cdrom_pc_intr;
 529 
 530   return 0;
 531 }
 532 
 533 
 534 static int cdrom_do_packet_command (ide_dev_t *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 535 {
 536   int len;
 537   struct request *rq = ide_cur_rq[dev->hwif];
 538   struct packet_command *pc = (struct packet_command *)rq->buffer;
 539 
 540   len = pc->buflen;
 541   if (len < 0) len = -len;
 542 
 543   pc->stat = 0;
 544 
 545   if (cdrom_start_packet_command (dev, len))
 546     return 1;
 547 
 548   if (CDROM_FLAGS (dev)->drq_interrupt)
 549     ide_handler[dev->hwif] = (void (*)(ide_dev_t *))cdrom_do_pc_continuation;
 550   else
 551     {
 552       if (cdrom_do_pc_continuation (dev))
 553         return 1;
 554     }
 555 
 556   return 0;
 557 }
 558 
 559 
 560 static
 561 int cdrom_queue_packet_command (ide_dev_t *dev, struct packet_command *pc)
     /* [previous][next][first][last][top][bottom][index][help] */
 562 {
 563   unsigned long flags;
 564   struct request req, **p, **pfirst;
 565   struct semaphore sem = MUTEX_LOCKED;
 566   int major = ide_major[dev->hwif];
 567 
 568   req.dev = MKDEV (major, (dev->select.b.drive) << PARTN_BITS);
 569   req.cmd = PACKET_COMMAND;
 570   req.errors = 0;
 571   req.sector = 0;
 572   req.nr_sectors = 0;
 573   req.current_nr_sectors = 0;
 574   req.buffer = (char *)pc;
 575   req.sem = &sem;
 576   req.bh = NULL;
 577   req.bhtail = NULL;
 578   req.next = NULL;
 579 
 580   save_flags (flags);
 581   cli ();
 582 
 583   p = &blk_dev[major].current_request;
 584   pfirst = p;
 585   while ((*p) != NULL)
 586     {
 587       p = &((*p)->next);
 588     }
 589   *p = &req;
 590   if (p == pfirst)
 591     blk_dev[major].request_fn ();
 592 
 593   restore_flags (flags);
 594 
 595   down (&sem);
 596 
 597   if (pc->stat != 0)
 598     return -EIO;
 599   else
 600     return 0;
 601 }
 602 
 603 
 604 
 605 /****************************************************************************
 606  * cdrom driver request routine.
 607  */
 608 
 609 static int do_rw_cdrom (ide_dev_t *dev, unsigned long block)
     /* [previous][next][first][last][top][bottom][index][help] */
 610 {
 611   struct request *rq = ide_cur_rq[dev->hwif];
 612 
 613   if (rq -> cmd == PACKET_COMMAND)
 614     return cdrom_do_packet_command (dev);
 615 
 616   if (rq -> cmd != READ)
 617     {
 618       printk ("ide-cd: bad cmd %d\n", rq -> cmd);
 619       end_request (0, dev->hwif);
 620       return 1;
 621     }
 622 
 623   if (rq->cmd == READ)
 624     {
 625       /* This can happen if there was an I/O error on the previous
 626          buffer in this request. */
 627       if ((rq->nr_sectors & (BLOCKS_PER_FRAME-1)) == BLOCKS_PER_FRAME-1 &&
 628           (rq->sector & (BLOCKS_PER_FRAME-1)) == 1 &&
 629           (rq->current_nr_sectors & (BLOCKS_PER_FRAME-1)) == 0)
 630         {
 631           rq->nr_sectors &= (BLOCKS_PER_FRAME-1);
 632           rq->sector = (rq->sector+BLOCKS_PER_FRAME) & (BLOCKS_PER_FRAME-1);
 633         }
 634     }
 635 
 636   return cdrom_start_read (dev, block);
 637 }
 638 
 639 
 640 
 641 /****************************************************************************
 642  * ioctl handling.
 643  */
 644 
 645 static inline
 646 void byte_swap_word (unsigned short *x)
     /* [previous][next][first][last][top][bottom][index][help] */
 647 {
 648   char *c = (char *)x;
 649   char d = c[0];
 650   c[0] = c[1];
 651   c[1] = d;
 652 }
 653 
 654 
 655 static inline
 656 void byte_swap_long (unsigned *x)
     /* [previous][next][first][last][top][bottom][index][help] */
 657 {
 658   char *c = (char *)x;
 659   char d = c[0];
 660   c[0] = c[3];
 661   c[3] = d;
 662   d = c[1];
 663   c[1] = c[2];
 664   c[2] = d;
 665 }
 666 
 667 
 668 static
 669 int bin2bcd (int x)
     /* [previous][next][first][last][top][bottom][index][help] */
 670 {
 671   return (x%10) | ((x/10) << 4);
 672 }
 673 
 674 
 675 static inline
 676 void lba_to_msf (int lba, byte *m, byte *s, byte *f)
     /* [previous][next][first][last][top][bottom][index][help] */
 677 {
 678   lba += CD_BLOCK_OFFSET;
 679   lba &= 0xffffff;  /* negative lbas use only 24 bits */
 680   *m = lba / (CD_SECS * CD_FRAMES);
 681   lba %= (CD_SECS * CD_FRAMES);
 682   *s = lba / CD_FRAMES;
 683   *f = lba % CD_FRAMES;
 684 }
 685 
 686 
 687 static inline
 688 int msf_to_lba (byte m, byte s, byte f)
     /* [previous][next][first][last][top][bottom][index][help] */
 689 {
 690   return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_BLOCK_OFFSET;
 691 }
 692 
 693 
 694 static void
 695 cdrom_check_status (ide_dev_t  *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 696 {
 697   struct packet_command pc;
 698 
 699   memset (&pc, 0, sizeof (pc));
 700 
 701   pc.c[0] = TEST_UNIT_READY;
 702 
 703   (void) cdrom_queue_packet_command (dev, &pc);
 704 }
 705 
 706 
 707 static int
 708 cdrom_request_sense (ide_dev_t *dev, struct atapi_request_sense *reqbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
 709 {
 710   struct packet_command pc;
 711 
 712   memset (&pc, 0, sizeof (pc));
 713 
 714   pc.c[0] = REQUEST_SENSE;
 715   pc.c[4] = sizeof (*reqbuf);
 716   pc.buffer = (char *)reqbuf;
 717   pc.buflen = sizeof (*reqbuf);
 718 
 719   return cdrom_queue_packet_command (dev, &pc);
 720 }
 721 
 722 
 723 #if 0
 724 /* Lock the door if LOCKFLAG is nonzero; unlock it otherwise. */
 725 static int
 726 cdrom_lockdoor (ide_dev_t *dev, int lockflag)
     /* [previous][next][first][last][top][bottom][index][help] */
 727 {
 728   struct packet_command pc;
 729 
 730   memset (&pc, 0, sizeof (pc));
 731 
 732   pc.c[0] = ALLOW_MEDIUM_REMOVAL;
 733   pc.c[4] = (lockflag != 0);
 734   return cdrom_queue_packet_command (dev, &pc);
 735 }
 736 #endif
 737 
 738 
 739 /* Eject the disk if EJECTFLAG is 0.
 740    If EJECTFLAG is 1, try to reload the disk. */
 741 static int
 742 cdrom_eject (ide_dev_t *dev, int ejectflag)
     /* [previous][next][first][last][top][bottom][index][help] */
 743 {
 744   struct packet_command pc;
 745 
 746   memset (&pc, 0, sizeof (pc));
 747 
 748   pc.c[0] = START_STOP;
 749   pc.c[4] = 2 + (ejectflag != 0);
 750   return cdrom_queue_packet_command (dev, &pc);
 751 }
 752 
 753 
 754 static int
 755 cdrom_pause (ide_dev_t *dev, int pauseflag)
     /* [previous][next][first][last][top][bottom][index][help] */
 756 {
 757   struct packet_command pc;
 758 
 759   memset (&pc, 0, sizeof (pc));
 760 
 761   pc.c[0] = SCMD_PAUSE_RESUME;
 762   pc.c[8] = !pauseflag;
 763   return cdrom_queue_packet_command (dev, &pc);
 764 }
 765 
 766 
 767 static int
 768 cdrom_startstop (ide_dev_t *dev, int startflag)
     /* [previous][next][first][last][top][bottom][index][help] */
 769 {
 770   struct packet_command pc;
 771 
 772   memset (&pc, 0, sizeof (pc));
 773 
 774   pc.c[0] = START_STOP;
 775   pc.c[1] = 1;
 776   pc.c[4] = startflag;
 777   return cdrom_queue_packet_command (dev, &pc);
 778 }
 779 
 780 
 781 static int
 782 cdrom_read_tocentry (ide_dev_t *dev, int trackno, int msf_flag,
     /* [previous][next][first][last][top][bottom][index][help] */
 783                      char *buf, int buflen)
 784 {
 785   struct packet_command pc;
 786 
 787   memset (&pc, 0, sizeof (pc));
 788 
 789   pc.buffer =  buf;
 790   pc.buflen = buflen;
 791   pc.c[0] = SCMD_READ_TOC;
 792   pc.c[6] = trackno;
 793   pc.c[7] = (buflen >> 8);
 794   pc.c[8] = (buflen & 0xff);
 795   if (msf_flag) pc.c[1] = 2;
 796   return cdrom_queue_packet_command (dev, &pc);
 797 }
 798 
 799 
 800 /* Try to read the entire TOC for the disk into our internal buffer. */
 801 static int
 802 cdrom_read_toc (ide_dev_t *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 803 {
 804   int stat, ntracks, i;
 805   struct atapi_toc *toc = cdrom_toc[dev->hwif][dev->select.b.drive];
 806 
 807   if (toc == NULL)
 808     {
 809       /* Try to allocate space. */
 810       toc = (struct atapi_toc *) kmalloc (sizeof (struct atapi_toc),
 811                                           GFP_KERNEL);
 812       cdrom_toc[dev->hwif][dev->select.b.drive] = toc;
 813     }
 814 
 815   if (toc == NULL)
 816     {
 817       printk ("%s: No cdrom TOC buffer!\n", dev->name);
 818       return -EIO;
 819     }
 820 
 821   /* Check to see if the existing data is still valid.
 822      If it is, just return. */
 823   if (CDROM_FLAGS (dev)->toc_valid)
 824     cdrom_check_status (dev);
 825 
 826   if (CDROM_FLAGS (dev)->toc_valid) return 0;
 827 
 828   /* First read just the header, so we know how long the TOC is. */
 829   stat = cdrom_read_tocentry (dev, 0, 0, (char *)toc,
 830                               sizeof (struct atapi_toc_header) +
 831                               sizeof (struct atapi_toc_entry));
 832   if (stat) return stat;
 833 
 834   ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
 835   if (ntracks <= 0) return -EIO;
 836   if (ntracks > MAX_TRACKS) ntracks = MAX_TRACKS;
 837 
 838   /* Now read the whole schmeer. */
 839   stat = cdrom_read_tocentry (dev, 0, 0, (char *)toc,
 840                               sizeof (struct atapi_toc_header) +
 841                               (ntracks+1) * sizeof (struct atapi_toc_entry));
 842   if (stat) return stat;
 843   byte_swap_word (&toc->hdr.toc_length);
 844   for (i=0; i<=ntracks; i++)
 845     byte_swap_long (&toc->ent[i].lba);
 846 
 847   /* Remember that we've read this stuff. */
 848   CDROM_FLAGS (dev)->toc_valid = 1;
 849 
 850   return 0;
 851 }
 852 
 853 
 854 static int
 855 cdrom_read_subchannel (ide_dev_t *dev,
     /* [previous][next][first][last][top][bottom][index][help] */
 856                        char *buf, int buflen)
 857 {
 858   struct packet_command pc;
 859 
 860   memset (&pc, 0, sizeof (pc));
 861 
 862   pc.buffer =  buf;
 863   pc.buflen = buflen;
 864   pc.c[0] = SCMD_READ_SUBCHANNEL;
 865   pc.c[2] = 0x40;  /* request subQ data */
 866   pc.c[3] = 0x01;  /* Format 1: current position */
 867   pc.c[7] = (buflen >> 8);
 868   pc.c[8] = (buflen & 0xff);
 869   return cdrom_queue_packet_command (dev, &pc);
 870 }
 871 
 872 
 873 /* modeflag: 0 = current, 1 = changeable mask, 2 = default, 3 = saved */
 874 static int
 875 cdrom_mode_sense (ide_dev_t *dev, int pageno, int modeflag,
     /* [previous][next][first][last][top][bottom][index][help] */
 876                   char *buf, int buflen)
 877 {
 878   struct packet_command pc;
 879 
 880   memset (&pc, 0, sizeof (pc));
 881 
 882   pc.buffer =  buf;
 883   pc.buflen = buflen;
 884   pc.c[0] = MODE_SENSE_10;
 885   pc.c[2] = pageno | (modeflag << 6);
 886   pc.c[7] = (buflen >> 8);
 887   pc.c[8] = (buflen & 0xff);
 888   return cdrom_queue_packet_command (dev, &pc);
 889 }
 890 
 891 
 892 static int
 893 cdrom_mode_select (ide_dev_t *dev, char *buf, int buflen)
     /* [previous][next][first][last][top][bottom][index][help] */
 894 {
 895   struct packet_command pc;
 896 
 897   memset (&pc, 0, sizeof (pc));
 898 
 899   pc.buffer =  buf;
 900   pc.buflen = - buflen;
 901   pc.c[0] = MODE_SELECT_10;
 902   pc.c[1] = 0x10;
 903   pc.c[7] = (buflen >> 8);
 904   pc.c[8] = (buflen & 0xff);
 905   return cdrom_queue_packet_command (dev, &pc);
 906 }
 907 
 908 
 909 static int
 910 cdrom_play_lba_range_play12 (ide_dev_t *dev, int lba_start, int lba_end)
     /* [previous][next][first][last][top][bottom][index][help] */
 911 {
 912   struct packet_command pc;
 913 
 914   memset (&pc, 0, sizeof (pc));
 915 
 916   pc.c[0] = SCMD_PLAYAUDIO12;
 917   *(int *)(&pc.c[2]) = lba_start;
 918   *(int *)(&pc.c[6]) = lba_end - lba_start;
 919   byte_swap_long ((int *)(&pc.c[2]));
 920   byte_swap_long ((int *)(&pc.c[6]));
 921 
 922   return cdrom_queue_packet_command (dev, &pc);
 923 }
 924 
 925 
 926 static int
 927 cdrom_play_lba_range_msf (ide_dev_t *dev, int lba_start, int lba_end)
     /* [previous][next][first][last][top][bottom][index][help] */
 928 {
 929   struct packet_command pc;
 930 
 931   memset (&pc, 0, sizeof (pc));
 932 
 933   pc.c[0] = SCMD_PLAYAUDIO_MSF;
 934   lba_to_msf (lba_start, &pc.c[3], &pc.c[4], &pc.c[5]);
 935   lba_to_msf (lba_end-1, &pc.c[6], &pc.c[7], &pc.c[8]);
 936 
 937   pc.c[3] = bin2bcd (pc.c[3]);
 938   pc.c[4] = bin2bcd (pc.c[4]);
 939   pc.c[5] = bin2bcd (pc.c[5]);
 940   pc.c[6] = bin2bcd (pc.c[6]);
 941   pc.c[7] = bin2bcd (pc.c[7]);
 942   pc.c[8] = bin2bcd (pc.c[8]);
 943 
 944   return cdrom_queue_packet_command (dev, &pc);
 945 }
 946 
 947 
 948 /* Play audio starting at LBA LBA_START and finishing with the
 949    LBA before LBA_END. */
 950 static int
 951 cdrom_play_lba_range (ide_dev_t *dev, int lba_start, int lba_end)
     /* [previous][next][first][last][top][bottom][index][help] */
 952 {
 953   /* This is rather annoying.
 954      My NEC-260 won't recognize group 5 commands such as PLAYAUDIO12;
 955      the only way to get it to play more than 64k of blocks at once
 956      seems to be the PLAYAUDIO_MSF command.  However, the parameters
 957      the NEC 260 wants for the PLAYMSF command are incompatible with
 958      the new version of the spec.
 959 
 960      So what i'll try is this.  First try for PLAYAUDIO12.  If it works,
 961      great.  Otherwise, if the drive reports an illegal command code,
 962      try PLAYAUDIO_MSF using the NEC 260-style bcd parameters. */
 963 
 964   if (CDROM_FLAGS (dev)->no_playaudio12)
 965     return cdrom_play_lba_range_msf (dev, lba_start, lba_end);
 966   else
 967     {
 968       int stat, stat2;
 969       struct atapi_request_sense reqbuf;
 970 
 971       stat = cdrom_play_lba_range_play12 (dev, lba_start, lba_end);
 972       if (stat == 0) return 0;
 973 
 974       /* It failed.  Try to find out why. */
 975       stat2 = cdrom_request_sense (dev, &reqbuf);
 976       if (stat2) return stat;
 977 
 978       if (reqbuf.sense_key == 0x05 && reqbuf.asc == 0x20)
 979         {
 980           /* The drive didn't recognize the command.
 981              Retry with the MSF variant. */
 982           printk ("%s: Drive does not support PLAYAUDIO12; "
 983                   "trying PLAYAUDIO_MSF\n", dev->name);
 984           CDROM_FLAGS (dev)->no_playaudio12 = 1;
 985           return cdrom_play_lba_range_msf (dev, lba_start, lba_end);
 986         }
 987 
 988       /* Failed for some other reason.  Give up. */
 989       return stat;
 990     }
 991 }
 992 
 993 
 994 static
 995 int cdrom_get_toc_entry (ide_dev_t *dev, int track,
     /* [previous][next][first][last][top][bottom][index][help] */
 996                          struct atapi_toc_entry **ent)
 997 {
 998   int stat, ntracks;
 999   struct atapi_toc *toc;
1000 
1001   /* Make sure our saved TOC is valid. */
1002   stat = cdrom_read_toc (dev);
1003   if (stat) return stat;
1004 
1005   toc = cdrom_toc[dev->hwif][dev->select.b.drive];
1006 
1007   /* Check validity of requested track number. */
1008   ntracks = toc->hdr.last_track - toc->hdr.first_track + 1;
1009   if (track == CDROM_LEADOUT)
1010     *ent = &toc->ent[ntracks];
1011   else if (track < toc->hdr.first_track ||
1012            track > toc->hdr.last_track)
1013     return -EINVAL;
1014   else
1015     *ent = &toc->ent[track - toc->hdr.first_track];
1016 
1017   return 0;
1018 }
1019 
1020 
1021 static int ide_cdrom_ioctl (ide_dev_t *dev, struct inode *inode,
     /* [previous][next][first][last][top][bottom][index][help] */
1022                         struct file *file, unsigned int cmd, unsigned long arg)
1023 {
1024   switch (cmd)
1025     {
1026     case CDROMEJECT:
1027       return cdrom_eject (dev, 0);
1028 
1029     case CDROMPAUSE:
1030       return cdrom_pause (dev, 1);
1031 
1032     case CDROMRESUME:
1033       return cdrom_pause (dev, 0);
1034 
1035     case CDROMSTART:
1036       return cdrom_startstop (dev, 1);
1037 
1038     case CDROMSTOP:
1039       return cdrom_startstop (dev, 0);
1040 
1041     case CDROMPLAYMSF:
1042       {
1043         struct cdrom_msf msf;
1044         int stat, lba_start, lba_end;
1045 
1046         stat = verify_area (VERIFY_READ, (void *)arg, sizeof (msf));
1047         if (stat) return stat;
1048 
1049         memcpy_fromfs (&msf, (void *) arg, sizeof(msf));
1050 
1051         lba_start = msf_to_lba (msf.cdmsf_min0, msf.cdmsf_sec0,
1052                                 msf.cdmsf_frame0);
1053         lba_end = msf_to_lba (msf.cdmsf_min1, msf.cdmsf_sec1,
1054                               msf.cdmsf_frame1) + 1;
1055 
1056         if (lba_end <= lba_start) return -EINVAL;
1057 
1058         return cdrom_play_lba_range (dev, lba_start, lba_end);
1059       }
1060 
1061     /* Like just about every other Linux cdrom driver, we ignore the
1062        index part of the request here. */
1063     case CDROMPLAYTRKIND:
1064       {
1065         int stat, lba_start, lba_end;
1066         struct cdrom_ti ti;
1067         struct atapi_toc_entry *first_toc, *last_toc;
1068 
1069         stat = verify_area (VERIFY_READ, (void *)arg, sizeof (ti));
1070         if (stat) return stat;
1071 
1072         memcpy_fromfs (&ti, (void *) arg, sizeof(ti));
1073 
1074         stat = cdrom_get_toc_entry (dev, ti.cdti_trk0, &first_toc);
1075         if (stat) return stat;
1076         stat = cdrom_get_toc_entry (dev, ti.cdti_trk1, &last_toc);
1077         if (stat) return stat;
1078 
1079         if (ti.cdti_trk1 != CDROM_LEADOUT) ++last_toc;
1080         lba_start = first_toc->lba;
1081         lba_end   = last_toc->lba;
1082 
1083         if (lba_end <= lba_start) return -EINVAL;
1084 
1085         return cdrom_play_lba_range (dev, lba_start, lba_end);
1086       }
1087 
1088     case CDROMREADTOCHDR:
1089       {
1090         int stat;
1091         struct cdrom_tochdr tochdr;
1092         struct atapi_toc *toc;
1093 
1094         stat = verify_area (VERIFY_WRITE, (void *) arg, sizeof (tochdr));
1095         if (stat) return stat;
1096 
1097         /* Make sure our saved TOC is valid. */
1098         stat = cdrom_read_toc (dev);
1099         if (stat) return stat;
1100 
1101         toc = cdrom_toc[dev->hwif][dev->select.b.drive];
1102         tochdr.cdth_trk0 = toc->hdr.first_track;
1103         tochdr.cdth_trk1 = toc->hdr.last_track;
1104 
1105         memcpy_tofs ((void *) arg, &tochdr, sizeof (tochdr));
1106 
1107         return stat;
1108       }
1109 
1110     case CDROMREADTOCENTRY:
1111       {
1112         int stat;
1113         struct cdrom_tocentry tocentry;
1114         struct atapi_toc_entry *toce;
1115 
1116         stat = verify_area (VERIFY_READ, (void *) arg, sizeof (tocentry));
1117         if (stat) return stat;
1118         stat = verify_area (VERIFY_WRITE, (void *) arg, sizeof (tocentry));
1119         if (stat) return stat;
1120 
1121         memcpy_fromfs (&tocentry, (void *) arg, sizeof (tocentry));
1122 
1123         stat = cdrom_get_toc_entry (dev, tocentry.cdte_track, &toce);
1124         if (stat) return stat;
1125 
1126         tocentry.cdte_ctrl = toce->control;
1127         tocentry.cdte_adr  = toce->adr;
1128 
1129         if (tocentry.cdte_format == CDROM_MSF)
1130           {
1131             /* convert to MSF */
1132             lba_to_msf (toce->lba,
1133                         &tocentry.cdte_addr.msf.minute,
1134                         &tocentry.cdte_addr.msf.second,
1135                         &tocentry.cdte_addr.msf.frame);
1136           }
1137         else
1138           tocentry.cdte_addr.lba = toce->lba;
1139 
1140         memcpy_tofs ((void *) arg, &tocentry, sizeof (tocentry));
1141 
1142         return stat;
1143       }
1144 
1145     case CDROMSUBCHNL:
1146       {
1147         char buffer[16];
1148         int stat, abs_lba, rel_lba;
1149         struct cdrom_subchnl subchnl;
1150 
1151         stat = verify_area (VERIFY_WRITE, (void *) arg, sizeof (subchnl));
1152         if (stat) return stat;
1153         stat = verify_area (VERIFY_READ, (void *) arg, sizeof (subchnl));
1154         if (stat) return stat;
1155 
1156         memcpy_fromfs (&subchnl, (void *) arg, sizeof (subchnl));
1157 
1158         stat = cdrom_read_subchannel (dev, buffer, sizeof (buffer));
1159         if (stat) return stat;
1160 
1161         abs_lba = *(int *)&buffer[8];
1162         rel_lba = *(int *)&buffer[12];
1163         byte_swap_long (&abs_lba);
1164         byte_swap_long (&rel_lba);
1165 
1166         if (subchnl.cdsc_format == CDROM_MSF)
1167           {
1168             lba_to_msf (abs_lba,
1169                         &subchnl.cdsc_absaddr.msf.minute,
1170                         &subchnl.cdsc_absaddr.msf.second,
1171                         &subchnl.cdsc_absaddr.msf.frame);
1172             lba_to_msf (rel_lba,
1173                         &subchnl.cdsc_reladdr.msf.minute,
1174                         &subchnl.cdsc_reladdr.msf.second,
1175                         &subchnl.cdsc_reladdr.msf.frame);
1176           }
1177         else
1178           {
1179             subchnl.cdsc_absaddr.lba = abs_lba;
1180             subchnl.cdsc_reladdr.lba = rel_lba;
1181           }
1182 
1183         subchnl.cdsc_audiostatus = buffer[1];
1184         subchnl.cdsc_ctrl = buffer[5] & 0xf;
1185         subchnl.cdsc_trk = buffer[6];
1186         subchnl.cdsc_ind = buffer[7];
1187 
1188         memcpy_tofs ((void *) arg, &subchnl, sizeof (subchnl));
1189 
1190         return stat;
1191       }
1192 
1193     case CDROMVOLCTRL:
1194       {
1195         struct cdrom_volctrl volctrl;
1196         char buffer[24], mask[24];
1197         int stat;
1198 
1199         stat = verify_area (VERIFY_READ, (void *) arg, sizeof (volctrl));
1200         if (stat) return stat;
1201         memcpy_fromfs (&volctrl, (void *) arg, sizeof (volctrl));
1202 
1203         stat = cdrom_mode_sense (dev, 0x0e, 0, buffer, sizeof (buffer));
1204         if (stat) return stat;
1205         stat = cdrom_mode_sense (dev, 0x0e, 1, mask  , sizeof (buffer));
1206         if (stat) return stat;
1207 
1208         buffer[1] = buffer[2] = 0;
1209 
1210         buffer[17] = volctrl.channel0 & mask[17];
1211         buffer[19] = volctrl.channel1 & mask[19];
1212         buffer[21] = volctrl.channel2 & mask[21];
1213         buffer[23] = volctrl.channel3 & mask[23];
1214 
1215         return cdrom_mode_select (dev, buffer, sizeof (buffer));
1216       }
1217 
1218 #ifdef TEST
1219     case 0x1234:
1220       {
1221         int stat;
1222         struct packet_command pc;
1223 
1224         memset (&pc, 0, sizeof (pc));
1225 
1226         stat = verify_area (VERIFY_READ, (void *) arg, sizeof (pc.c));
1227         if (stat) return stat;
1228         memcpy_fromfs (&pc.c, (void *) arg, sizeof (pc.c));
1229 
1230         return cdrom_queue_packet_command (dev, &pc);
1231       }
1232 
1233     case 0x1235:
1234       {
1235         int stat;
1236         struct atapi_request_sense reqbuf;
1237 
1238         stat = verify_area (VERIFY_WRITE, (void *) arg, sizeof (reqbuf));
1239         if (stat) return stat;
1240 
1241         stat = cdrom_request_sense (dev, &reqbuf);
1242 
1243         memcpy_tofs ((void *) arg, &reqbuf, sizeof (reqbuf));
1244 
1245         return stat;
1246       }
1247 #endif
1248 
1249     default:
1250       return -EPERM;
1251     }
1252 
1253 }
1254 
1255 
1256 
1257 /****************************************************************************
1258  * Other driver requests (open, close, check media change).
1259  */
1260 
1261 static int cdrom_check_media_change (ide_dev_t *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1262 {
1263   int retval;
1264 
1265   cdrom_check_status (dev);
1266 
1267   retval = CDROM_FLAGS (dev)->media_changed;
1268   CDROM_FLAGS (dev)->media_changed = 0;
1269 
1270   return retval;
1271 }
1272 
1273 
1274 static int
1275 cdrom_open (struct inode *ip, struct file *fp, ide_dev_t *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1276 {
1277   /* no write access */
1278   if (fp->f_mode & 2) return -EROFS;
1279 
1280 #if 0 /* With this, one cannot eject a disk with workman */
1281   /* If this is the first open, lock the door. */
1282   if (dev->usage == 1)
1283     (void) cdrom_lockdoor (dev, 1);
1284 #endif
1285 
1286   /* Should check that there's a disk in the drive? */
1287   return 0;
1288 }
1289 
1290 
1291 /*
1292  * Close down the device.  Invalidate all cached blocks.
1293  */
1294 
1295 static void
1296 cdrom_release (struct inode *inode, struct file *file, ide_dev_t *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1297 {
1298   if (dev->usage == 0)
1299     {
1300       invalidate_buffers (inode->i_rdev);
1301 
1302 #if 0
1303       /* Unlock the door. */
1304       (void) cdrom_lockdoor (dev, 0);
1305 #endif
1306     }
1307 }
1308 
1309 
1310 
1311 /****************************************************************************
1312  * Device initialization.
1313  */
1314 
1315 static void cdrom_setup (ide_dev_t *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1316 {
1317   /* Just guess at capacity for now. */
1318   ide_capacity[dev->hwif][dev->select.b.drive] = 0x1fffff;
1319 
1320   ide_blksizes[dev->hwif][dev->select.b.drive << PARTN_BITS] = CD_FRAMESIZE;
1321 
1322   dev->special.all = 0;
1323 
1324   CDROM_FLAGS (dev)->media_changed = 0;
1325   CDROM_FLAGS (dev)->toc_valid     = 0;
1326 
1327   CDROM_FLAGS (dev)->no_playaudio12 = 0;
1328   CDROM_FLAGS (dev)->drq_interrupt = ((dev->id->config & 0x0060) == 0x20);
1329 
1330   cdrom_toc[dev->hwif][dev->select.b.drive] = NULL;
1331 }
1332 
1333 
1334 
1335 
1336 /*
1337  * TODO:
1338  *  Retrieve and interpret extended ATAPI error codes.
1339  *  Transfer multiple sectors at once.
1340  *  Read actual disk capacity.
1341  *  Support demand-paged executables (1k block sizes?).
1342  *  Multisession support.
1343  *  Direct reading of audio data.
1344  *  Eject-on-dismount.
1345  *  Lock door while there's a mounted volume.
1346  */
1347 

/* [previous][next][first][last][top][bottom][index][help] */