📄 ide-cd.c
字号:
/* #define VERBOSE_IDE_CD_ERRORS 1 *//* * linux/drivers/block/ide-cd.c * ATAPI cd-rom driver. To be used with ide.c. * See Documentation/cdrom/ide-cd for usage information. * * Copyright (C) 1994, 1995, 1996 scott snyder <snyder@fnald0.fnal.gov> * Copyright (C) 1996, 1997 Erik Andersen <andersee@debian.org> * Copyright (C) 1998 Jens Axboe and Chris Zwilling * * May be copied or modified under the terms of the GNU General Public License * see linux/COPYING for more information. * * 1.00 Oct 31, 1994 -- Initial version. * 1.01 Nov 2, 1994 -- Fixed problem with starting request in * cdrom_check_status. * 1.03 Nov 25, 1994 -- leaving unmask_intr[] as a user-setting (as for disks) * (from mlord) -- minor changes to cdrom_setup() * -- renamed ide_dev_s to ide_drive_t, enable irq on command * 2.00 Nov 27, 1994 -- Generalize packet command interface; * add audio ioctls. * 2.01 Dec 3, 1994 -- Rework packet command interface to handle devices * which send an interrupt when ready for a command. * 2.02 Dec 11, 1994 -- Cache the TOC in the driver. * Don't use SCMD_PLAYAUDIO_TI; it's not included * in the current version of ATAPI. * Try to use LBA instead of track or MSF addressing * when possible. * Don't wait for READY_STAT. * 2.03 Jan 10, 1995 -- Rewrite block read routines to handle block sizes * other than 2k and to move multiple sectors in a * single transaction. * 2.04 Apr 21, 1995 -- Add work-around for Creative Labs CD220E drives. * Thanks to Nick Saw <cwsaw@pts7.pts.mot.com> for * help in figuring this out. Ditto for Acer and * Aztech drives, which seem to have the same problem. * 2.04b May 30, 1995 -- Fix to match changes in ide.c version 3.16 -ml * 2.05 Jun 8, 1995 -- Don't attempt to retry after an illegal request * or data protect error. * Use HWIF and DEV_HWIF macros as in ide.c. * Always try to do a request_sense after * a failed command. * Include an option to give textual descriptions * of ATAPI errors. * Fix a bug in handling the sector cache which * showed up if the drive returned data in 512 byte * blocks (like Pioneer drives). Thanks to * Richard Hirst <srh@gpt.co.uk> for diagnosing this. * Properly supply the page number field in the * MODE_SELECT command. * PLAYAUDIO12 is broken on the Aztech; work around it. * 2.05x Aug 11, 1995 -- lots of data structure renaming/restructuring in ide.c * (my apologies to Scott, but now ide-cd.c is independent) * 3.00 Aug 22, 1995 -- Implement CDROMMULTISESSION ioctl. * Implement CDROMREADAUDIO ioctl (UNTESTED). * Use input_ide_data() and output_ide_data(). * Add door locking. * Fix usage count leak in cdrom_open, which happened * when a read-write mount was attempted. * Try to load the disk on open. * Implement CDROMEJECT_SW ioctl (off by default). * Read total cdrom capacity during open. * Rearrange logic in cdrom_decode_status. Issue * request sense commands for failed packet commands * from here instead of from cdrom_queue_packet_command. * Fix a race condition in retrieving error information. * Suppress printing normal unit attention errors and * some drive not ready errors. * Implement CDROMVOLREAD ioctl. * Implement CDROMREADMODE1/2 ioctls. * Fix race condition in setting up interrupt handlers * when the `serialize' option is used. * 3.01 Sep 2, 1995 -- Fix ordering of reenabling interrupts in * cdrom_queue_request. * Another try at using ide_[input,output]_data. * 3.02 Sep 16, 1995 -- Stick total disk capacity in partition table as well. * Make VERBOSE_IDE_CD_ERRORS dump failed command again. * Dump out more information for ILLEGAL REQUEST errs. * Fix handling of errors occurring before the * packet command is transferred. * Fix transfers with odd bytelengths. * 3.03 Oct 27, 1995 -- Some Creative drives have an id of just `CD'. * `DCI-2S10' drives are broken too. * 3.04 Nov 20, 1995 -- So are Vertos drives. * 3.05 Dec 1, 1995 -- Changes to go with overhaul of ide.c and ide-tape.c * 3.06 Dec 16, 1995 -- Add support needed for partitions. * More workarounds for Vertos bugs (based on patches * from Holger Dietze <dietze@aix520.informatik.uni-leipzig.de>). * Try to eliminate byteorder assumptions. * Use atapi_cdrom_subchnl struct definition. * Add STANDARD_ATAPI compilation option. * 3.07 Jan 29, 1996 -- More twiddling for broken drives: Sony 55D, * Vertos 300. * Add NO_DOOR_LOCKING configuration option. * Handle drive_cmd requests w/NULL args (for hdparm -t). * Work around sporadic Sony55e audio play problem. * 3.07a Feb 11, 1996 -- check drive->id for NULL before dereferencing, to fix * problem with "hde=cdrom" with no drive present. -ml * 3.08 Mar 6, 1996 -- More Vertos workarounds. * 3.09 Apr 5, 1996 -- Add CDROMCLOSETRAY ioctl. * Switch to using MSF addressing for audio commands. * Reformat to match kernel tabbing style. * Add CDROM_GET_UPC ioctl. * 3.10 Apr 10, 1996 -- Fix compilation error with STANDARD_ATAPI. * 3.11 Apr 29, 1996 -- Patch from Heiko Eissfeldt <heiko@colossus.escape.de> * to remove redundant verify_area calls. * 3.12 May 7, 1996 -- Rudimentary changer support. Based on patches * from Gerhard Zuber <zuber@berlin.snafu.de>. * Let open succeed even if there's no loaded disc. * 3.13 May 19, 1996 -- Fixes for changer code. * 3.14 May 29, 1996 -- Add work-around for Vertos 600. * (From Hennus Bergman <hennus@sky.ow.nl>.) * 3.15 July 2, 1996 -- Added support for Sanyo 3 CD changers * from Ben Galliart <bgallia@luc.edu> with * special help from Jeff Lightfoot * <jeffml@netcom.com> * 3.15a July 9, 1996 -- Improved Sanyo 3 CD changer identification * 3.16 Jul 28, 1996 -- Fix from Gadi to reduce kernel stack usage for ioctl. * 3.17 Sep 17, 1996 -- Tweak audio reads for some drives. * Start changing CDROMLOADFROMSLOT to CDROM_SELECT_DISC. * * 3.19 Nov 5, 1996 -- New ide-cd maintainer: * Erik B. Andersen <andersee@debian.org> * 3.20 Jan 13,1997 -- Bug Fixes: * Fix errors on CDROMSTOP (If you have a "Dolphin", * you must define IHAVEADOLPHIN) * Added identifier so new Sanyo CD-changer works * Better detection if door locking isn't supported * 3.21 Jun 16,1997 -- Add work-around for GCD-R580B * * 3.22 Nov 13, 1998 -- New ide-cd maintainers: * Jens Axboe <axboe@image.dk> * Chris Zwilling <chris@cloudnet.com> * * NOTE: Direct audio reads will only work on some types of drive. * So far, i've received reports of success for Sony and Toshiba drives. * * ALSO NOTE: * * The ide cdrom driver has undergone extensive changes for the * latest development kernel. If you wish to add new features to * this driver, make your changes to the latest version in the * development kernel. Only Bug fixes will be accepted for this * version. * * For those wishing to work on this driver, please be sure you download * and comply with the latest ATAPI standard. This document can be * obtained by anonymous ftp from fission.dt.wdc.com in directory: * /pub/standards/atapi/spec/SFF8020-r2.6/PDF/8020r26.pdf * *//***************************************************************************/#include <linux/types.h>#include <linux/kernel.h>#include <linux/delay.h>#include <linux/timer.h>#include <linux/malloc.h>#include <linux/ioport.h>#include <linux/interrupt.h>#include <linux/blkdev.h>#include <linux/errno.h>#include <linux/hdreg.h>#include <linux/cdrom.h>#include <linux/ucdrom.h>#include <asm/irq.h>#include <asm/io.h>#include <asm/byteorder.h>#include <asm/segment.h>#include <asm/unaligned.h>#include "ide.h"/* Turn this on to have the driver print out the meanings of the ATAPI error codes. This will use up additional kernel-space memory, though. */#ifndef VERBOSE_IDE_CD_ERRORS#define VERBOSE_IDE_CD_ERRORS 0#endif/* Turning this on will remove code to work around various nonstandard ATAPI implementations. If you know your drive follows the standard, this will give you a slightly smaller kernel. */#ifndef STANDARD_ATAPI#define STANDARD_ATAPI 0#endif/* Turning this on will disable the door-locking functionality. This is apparently needed for supermount. */#ifndef NO_DOOR_LOCKING#define NO_DOOR_LOCKING 0#endif/* Size of buffer to allocate, in blocks, for audio reads. */#ifndef CDROM_NBLOCKS_BUFFER#define CDROM_NBLOCKS_BUFFER 8#endif/************************************************************************/#define SECTOR_SIZE 512#define SECTOR_BITS 9#define SECTORS_PER_FRAME (CD_FRAMESIZE / SECTOR_SIZE)#define MIN(a,b) ((a) < (b) ? (a) : (b))/* special command codes for strategy routine. */#define PACKET_COMMAND 4315#define REQUEST_SENSE_COMMAND 4316#define RESET_DRIVE_COMMAND 4317/* Some ATAPI command opcodes (just like SCSI). (Some other cdrom-specific codes are in cdrom.h.) */#define TEST_UNIT_READY 0x00#define REQUEST_SENSE 0x03#define START_STOP 0x1b#define ALLOW_MEDIUM_REMOVAL 0x1e#define READ_CAPACITY 0x25#define READ_10 0x28#define MODE_SENSE_10 0x5a#define MODE_SELECT_10 0x55#define READ_CD 0xbe#define LOAD_UNLOAD 0xa6/* ATAPI sense keys (mostly copied from scsi.h). */#define NO_SENSE 0x00#define RECOVERED_ERROR 0x01#define NOT_READY 0x02#define MEDIUM_ERROR 0x03#define HARDWARE_ERROR 0x04#define ILLEGAL_REQUEST 0x05#define UNIT_ATTENTION 0x06#define DATA_PROTECT 0x07#define ABORTED_COMMAND 0x0b#define MISCOMPARE 0x0e/* We want some additional flags for cd-rom drives. To save space in the ide_drive_t struct, use some fields which doesn't make sense for cd-roms -- `bios_sect' and `bios_head'. *//* Configuration flags. These describe the capabilities of the drive. They generally do not change after initialization, unless we learn more about the drive from stuff failing. */struct ide_cd_config_flags { __u8 drq_interrupt : 1; /* Device sends an interrupt when ready for a packet command. */ __u8 no_doorlock : 1; /* Drive cannot lock the door. */#if ! STANDARD_ATAPI __u8 old_readcd : 1; /* Drive uses old READ CD opcode. */ __u8 playmsf_as_bcd : 1; /* PLAYMSF command takes BCD args. */ __u8 tocaddr_as_bcd : 1; /* TOC addresses are in BCD. */ __u8 toctracks_as_bcd : 1; /* TOC track numbers are in BCD. */ __u8 subchan_as_bcd : 1; /* Subchannel info is in BCD. */#endif /* not STANDARD_ATAPI */ __u8 reserved : 1;};#define CDROM_CONFIG_FLAGS(drive) ((struct ide_cd_config_flags *)&((drive)->bios_sect)) /* State flags. These give information about the current state of the drive, and will change during normal operation. */struct ide_cd_state_flags { __u8 media_changed : 1; /* Driver has noticed a media change. */ __u8 toc_valid : 1; /* Saved TOC information is current. */ __u8 door_locked : 1; /* We think that the drive door is locked. */ __u8 eject_on_close: 1; /* Drive should eject when device is closed. */ __u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */ __u8 reserved : 2;};#define CDROM_STATE_FLAGS(drive) ((struct ide_cd_state_flags *)&((drive)->bios_head))#define SECTOR_BUFFER_SIZE CD_FRAMESIZE/**************************************************************************** * Routines to read and write data from/to the drive, using * the routines input_ide_data() and output_ide_data() from ide.c. * * These routines will round up any request for an odd number of bytes, * so if an odd bytecount is specified, be sure that there's at least one * extra byte allocated for the buffer. */static inlinevoid cdrom_in_bytes (ide_drive_t *drive, void *buffer, uint bytecount){ ++bytecount; ide_input_data (drive, buffer, bytecount / 4); if ((bytecount & 0x03) >= 2) { insw (IDE_DATA_REG, ((byte *)buffer) + (bytecount & ~0x03), 1); }}static inlinevoid cdrom_out_bytes (ide_drive_t *drive, void *buffer, uint bytecount){ ++bytecount; ide_output_data (drive, buffer, bytecount / 4); if ((bytecount & 0x03) >= 2) { outsw (IDE_DATA_REG, ((byte *)buffer) + (bytecount & ~0x03), 1); }}/**************************************************************************** * Descriptions of ATAPI error codes. */#define ARY_LEN(a) ((sizeof(a) / sizeof(a[0])))#if VERBOSE_IDE_CD_ERRORS/* From Table 124 of the ATAPI 1.2 spec. */char *sense_key_texts[16] = { "No sense data", "Recovered error", "Not ready", "Medium error", "Hardware error", "Illegal request", "Unit attention", "Data protect", "(reserved)", "(reserved)", "(reserved)", "Aborted command", "(reserved)", "(reserved)", "Miscompare", "(reserved)",};/* From Table 125 of the ATAPI 1.2 spec. */struct { short asc_ascq; char *text;} sense_data_texts[] = { { 0x0000, "No additional sense information" }, { 0x0011, "Audio play operation in progress" }, { 0x0012, "Audio play operation paused" }, { 0x0013, "Audio play operation successfully completed" }, { 0x0014, "Audio play operation stopped due to error" }, { 0x0015, "No current audio status to return" }, { 0x0200, "No seek complete" }, { 0x0400, "Logical unit not ready - cause not reportable" }, { 0x0401, "Logical unit not ready - in progress (sic) of becoming ready" }, { 0x0402, "Logical unit not ready - initializing command required" }, { 0x0403, "Logical unit not ready - manual intervention required" }, { 0x0600, "No reference position found" }, { 0x0900, "Track following error" }, { 0x0901, "Tracking servo failure" }, { 0x0902, "Focus servo failure" }, { 0x0903, "Spindle servo failure" }, { 0x1100, "Unrecovered read error" }, { 0x1106, "CIRC unrecovered error" }, { 0x1500, "Random positioning error" }, { 0x1501, "Mechanical positioning error" }, { 0x1502, "Positioning error detected by read of medium" }, { 0x1700, "Recovered data with no error correction applied" }, { 0x1701, "Recovered data with retries" }, { 0x1702, "Recovered data with positive head offset" }, { 0x1703, "Recovered data with negative head offset" }, { 0x1704, "Recovered data with retries and/or CIRC applied" }, { 0x1705, "Recovered data using previous sector ID" }, { 0x1800, "Recovered data with error correction applied" }, { 0x1801, "Recovered data with error correction and retries applied" }, { 0x1802, "Recovered data - the data was auto-reallocated" }, { 0x1803, "Recovered data with CIRC" }, { 0x1804, "Recovered data with L-EC" }, { 0x1805, "Recovered data - recommend reassignment" }, { 0x1806, "Recovered data - recommend rewrite" }, { 0x1a00, "Parameter list length error" }, { 0x2000, "Invalid command operation code" }, { 0x2100, "Logical block address out of range" }, { 0x2400, "Invalid field in command packet" }, { 0x2600, "Invalid field in parameter list" }, { 0x2601, "Parameter not supported" }, { 0x2602, "Parameter value invalid" }, { 0x2603, "Threshold parameters not supported" }, { 0x2800, "Not ready to ready transition, medium may have changed" }, { 0x2900, "Power on, reset or bus device reset occurred" }, { 0x2a00, "Parameters changed" }, { 0x2a01, "Mode parameters changed" }, { 0x3000, "Incompatible medium installed" }, { 0x3001, "Cannot read medium - unknown format" }, { 0x3002, "Cannot read medium - incompatible format" }, { 0x3700, "Rounded parameter" }, { 0x3900, "Saving parameters not supported" }, { 0x3a00, "Medium not present" }, { 0x3f00, "ATAPI CD-ROM drive operating conditions have changed" }, { 0x3f01, "Microcode has been changed" }, { 0x3f02, "Changed operating definition" }, { 0x3f03, "Inquiry data has changed" }, { 0x4000, "Diagnostic failure on component (ASCQ)" }, { 0x4400, "Internal ATAPI CD-ROM drive failure" }, { 0x4e00, "Overlapped commands attempted" }, { 0x5300, "Media load or eject failed" },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -