⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ide-cd.c

📁 基于组件方式开发操作系统的OSKIT源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * linux/drivers/block/ide-cd.c * Copyright (C) 1994, 1995, 1996  scott snyder  <snyder@fnald0.fnal.gov> * Copyright (C) 1996-1998  Erik Andersen <andersee@debian.org> * Copyright (C) 1998, 1999 Jens Axboe * * May be copied or modified under the terms of the GNU General Public * License.  See linux/COPYING for more information. * * ATAPI CD-ROM driver.  To be used with ide.c. * See Documentation/cdrom/ide-cd for usage information. * * Suggestions are welcome. Patches that work are more welcome though. ;-) * 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: * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps * * Drives that deviate from the ATAPI standard will be accomodated as much * as possible via compile time or command-line options.  Since I only have * a few drives, you generally need to send me patches... * * ---------------------------------- * TO DO LIST: * -Implement Microsoft Media Status Notification per the spec at *   http://www.microsoft.com/hwdev/respec/storspec.htm *   This will allow us to get automagically notified when the media changes *   on ATAPI drives (something the stock ATAPI spec is lacking).  Looks *   very cool.  I discovered its existance the other day at work... * -Query the drive to find what features are available before trying to *   use them (like trying to close the tray in drives that can't). * -Make it so that Pioneer CD DR-A24X and friends don't get screwed up on *   boot * -Integrate DVD-ROM support in driver. Thanks to Merete Gots鎑-Petersen *   of Pioneer Denmark for providing me with a drive for testing. * -Implement Features and Profiles. * * * ---------------------------------- * 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.18  Oct 31, 1996 -- Added module and DMA support. *                        *                        * 4.00  Nov 5, 1996   -- New ide-cd maintainer, *                                 Erik B. Andersen <andersee@debian.org> *                     -- Newer Creative drives don't always set the error *                          register correctly.  Make sure we see media changes *                          regardless. *                     -- Integrate with generic cdrom driver. *                     -- CDROMGETSPINDOWN and CDROMSETSPINDOWN ioctls, based on *                          a patch from Ciro Cattuto <>. *                     -- Call set_device_ro. *                     -- Implement CDROMMECHANISMSTATUS and CDROMSLOTTABLE *                          ioctls, based on patch by Erik Andersen *                     -- Add some probes of drive capability during setup. * * 4.01  Nov 11, 1996  -- Split into ide-cd.c and ide-cd.h *                     -- Removed CDROMMECHANISMSTATUS and CDROMSLOTTABLE  *                          ioctls in favor of a generalized approach  *                          using the generic cdrom driver. *                     -- Fully integrated with the 2.1.X kernel. *                     -- Other stuff that I forgot (lots of changes) * * 4.02  Dec 01, 1996  -- Applied patch from Gadi Oxman <gadio@netvision.net.il> *                          to fix the drive door locking problems. * * 4.03  Dec 04, 1996  -- Added DSC overlap support. * 4.04  Dec 29, 1996  -- Added CDROMREADRAW ioclt based on patch  *                          by Ales Makarov (xmakarov@sun.felk.cvut.cz) * * 4.05  Nov 20, 1997  -- Modified to print more drive info on init *                        Minor other changes *                        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 * * 4.06  Dec 17, 1997  -- fixed endless "tray open" messages  -ml * 4.07  Dec 17, 1997  -- fallback to set pc->stat on "tray open" * 4.08  Dec 18, 1997  -- spew less noise when tray is empty *                     -- fix speed display for ACER 24X, 18X * 4.09  Jan 04, 1998  -- fix handling of the last block so we return *                         an end of file instead of an I/O error (Gadi) * 4.10  Jan 24, 1998  -- fixed a bug so now changers can change to a new *                         slot when there is no disc in the current slot. *                     -- Fixed a memory leak where info->changer_info was *                         malloc'ed but never free'd when closing the device. *                     -- Cleaned up the global namespace a bit by making more *                         functions static that should already have been. * 4.11  Mar 12, 1998  -- Added support for the CDROM_SELECT_SPEED ioctl *                         based on a patch for 2.0.33 by Jelle Foks  *                         <jelle@scintilla.utwente.nl>, a patch for 2.0.33 *                         by Toni Giorgino <toni@pcape2.pi.infn.it>, the SCSI *                         version, and my own efforts.  -erik *                     -- Fixed a stupid bug which egcs was kind enough to *                         inform me of where "Illegal mode for this track" *                         was never returned due to a comparison on data *                         types of limited range. * 4.12  Mar 29, 1998  -- Fixed bug in CDROM_SELECT_SPEED so write speed is  *                         now set ionly for CD-R and CD-RW drives.  I had  *                         removed this support because it produced errors. *                         It produced errors _only_ for non-writers. duh. * 4.13  May 05, 1998  -- Suppress useless "in progress of becoming ready" *                         messages, since this is not an error. *                     -- Change error messages to be const *                     -- Remove a "\t" which looks ugly in the syslogs * 4.14  July 17, 1998 -- Change to pointing to .ps version of ATAPI spec *                         since the .pdf version doesn't seem to work... *                     -- Updated the TODO list to something more current. * * 4.15  Aug 25, 1998  -- Updated ide-cd.h to respect mechine endianess,  *                         patch thanks to "Eddie C. Dost" <ecd@skynet.be> * * 4.50  Oct 19, 1998  -- New maintainers! *                         Jens Axboe <axboe@image.dk> *                         Chris Zwilling <chris@cloudnet.com> * * 4.51  Dec 23, 1998  -- Jens Axboe <axboe@image.dk> *                      - ide_cdrom_reset enabled since the ide subsystem *                         handles resets fine now. <axboe@image.dk> *                      - Transfer size fix for Samsung CD-ROMs, thanks to *                        "Ville Hallik" <ville.hallik@mail.ee>. *                      - other minor stuff. * * 4.52  Jan 19, 1999  -- Jens Axboe <axboe@image.dk> *                      - Detect DVD-ROM/RAM drives * * 4.53  Feb 22, 1999   - Include other model Samsung and one Goldstar *                         drive in transfer size limit. *                      - Fix the I/O error when doing eject without a medium *                         loaded on some drives. *                      - CDROMREADMODE2 is now implemented through *                         CDROMREADRAW, since many drives don't support *                         MODE2 (even though ATAPI 2.6 says they must). *                      - Added ignore parameter to ide-cd (as a module), eg *                         	insmod ide-cd ignore='hda hdb' *                         Useful when using ide-cd in conjunction with *                         ide-scsi. TODO: non-modular way of doing the *                         same. *                          * *************************************************************************/#define IDECD_VERSION "4.53"#include <linux/module.h>#include <linux/types.h>#include <linux/kernel.h>#include <linux/delay.h>#include <linux/timer.h>#include <linux/malloc.h>#include <linux/interrupt.h>#include <linux/errno.h>#include <linux/cdrom.h>#include <asm/irq.h>#include <asm/io.h>#include <asm/byteorder.h>#include <asm/uaccess.h>#include <asm/unaligned.h>#include "ide.h"#include "ide-cd.h"/**************************************************************************** * Generic packet command support and error handling routines. *//* Mark that we've seen a media change, and invalidate our internal   buffers. */static void cdrom_saw_media_change (ide_drive_t *drive){	struct cdrom_info *info = drive->driver_data;		CDROM_STATE_FLAGS (drive)->media_changed = 1;	CDROM_STATE_FLAGS (drive)->toc_valid = 0;	info->nsectors_buffered = 0;}staticvoid cdrom_analyze_sense_data (ide_drive_t *drive, 			       struct atapi_request_sense *reqbuf,			       struct packet_command *failed_command){	if (reqbuf->sense_key == NOT_READY ||	    reqbuf->sense_key == UNIT_ATTENTION) {		/* Make good and sure we've seen this potential media change.		   Some drives (i.e. Creative) fail to present the correct		   sense key in the error register. */		cdrom_saw_media_change (drive);		/* Don't print not ready or unit attention errors for		   READ_SUBCHANNEL.  Workman (and probably other programs)		   uses this command to poll the drive, and we don't want		   to fill the syslog with useless errors. */		if (failed_command &&		    failed_command->c[0] == SCMD_READ_SUBCHANNEL)			return;	}	if (reqbuf->error_code == 0x70 && reqbuf->sense_key  == 0x02	 && ((reqbuf->asc        == 0x3a && reqbuf->ascq       == 0x00) ||	     (reqbuf->asc        == 0x04 && reqbuf->ascq       == 0x01)))	{		/*		 * Suppress the following errors:		 * "Medium not present", and "in progress of becoming ready",		 * to keep the noise level down to a dull roar.		 */		return;	}#if VERBOSE_IDE_CD_ERRORS	{		int i;		const char *s;		char buf[80];		printk ("ATAPI device %s:\n", drive->name);		if (reqbuf->error_code==0x70)			printk("  Error: ");		else if (reqbuf->error_code==0x71)			printk("  Deferred Error: ");		else			printk("  Unknown Error Type: ");		if ( reqbuf->sense_key < ARY_LEN (sense_key_texts))			s = sense_key_texts[reqbuf->sense_key];		else			s = "bad sense key!";		printk ("%s -- (Sense key=0x%02x)\n", s, reqbuf->sense_key);		if (reqbuf->asc == 0x40) {			sprintf (buf, "Diagnostic failure on component 0x%02x",				 reqbuf->ascq);			s = buf;		} else {			int lo=0, mid, hi=ARY_LEN (sense_data_texts);			unsigned short key = (reqbuf->asc << 8);			if ( ! (reqbuf->ascq >= 0x80 && reqbuf->ascq <= 0xdd) )				key |= reqbuf->ascq;			s = NULL;			while (hi > lo) {				mid = (lo + hi) / 2;				if (sense_data_texts[mid].asc_ascq == key) {					s = sense_data_texts[mid].text;					break;				}				else if (sense_data_texts[mid].asc_ascq > key)					hi = mid;				else					lo = mid+1;			}		}		if (s == NULL) {			if (reqbuf->asc > 0x80)				s = "(vendor-specific error)";			else				s = "(reserved error code)";		}		printk ("  %s -- (asc=0x%02x, ascq=0x%02x)\n",			s, reqbuf->asc, reqbuf->ascq);		if (failed_command != NULL) {			int lo=0, mid, hi= ARY_LEN (packet_command_texts);			s = NULL;			while (hi > lo) {				mid = (lo + hi) / 2;				if (packet_command_texts[mid].packet_command == failed_command->c[0]) {					s = packet_command_texts[mid].text;					break;				}				else if (packet_command_texts[mid].packet_command > failed_command->c[0])					hi = mid;				else					lo = mid+1;			}			printk ("  The failed \"%s\" packet command was: \n  \"", s);			for (i=0; i<sizeof (failed_command->c); i++)				printk ("%02x ", failed_command->c[i]);			printk ("\"\n");		}		if (reqbuf->sense_key == ILLEGAL_REQUEST &&		    (reqbuf->sense_key_specific[0] & 0x80) != 0) {			printk ("  Error in %s byte %d",				(reqbuf->sense_key_specific[0] & 0x40) != 0				? "command packet"				: "command data",				(reqbuf->sense_key_specific[1] << 8) +				reqbuf->sense_key_specific[2]);			if ((reqbuf->sense_key_specific[0] & 0x40) != 0) {				printk (" bit %d",					reqbuf->sense_key_specific[0] & 0x07);			}			printk ("\n");		}	}#else /* not VERBOSE_IDE_CD_ERRORS */	/* Suppress printing unit attention and `in progress of becoming ready'	   errors when we're not being verbose. */	if (reqbuf->sense_key == UNIT_ATTENTION ||	    (reqbuf->sense_key == NOT_READY && (reqbuf->asc == 4 ||						reqbuf->asc == 0x3a)))		return;	printk ("%s: error code: 0x%02x  sense_key: 0x%02x  asc: 0x%02x  ascq: 0x%02x\n",		drive->name,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -