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

📄 pcd.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* 	pcd.c	(c) 1997-8  Grant R. Guenther <grant@torque.net>		            Under the terms of the GNU General Public License.	This is a high-level driver for parallel port ATAPI CD-ROM        drives based on chips supported by the paride module.        By default, the driver will autoprobe for a single parallel        port ATAPI CD-ROM drive, but if their individual parameters are        specified, the driver can handle up to 4 drives.        The behaviour of the pcd driver can be altered by setting        some parameters from the insmod command line.  The following        parameters are adjustable:            drive0      These four arguments can be arrays of                   drive1      1-6 integers as follows:            drive2            drive3      <prt>,<pro>,<uni>,<mod>,<slv>,<dly>                        Where,                <prt>   is the base of the parallel port address for                        the corresponding drive.  (required)                <pro>   is the protocol number for the adapter that                        supports this drive.  These numbers are                        logged by 'paride' when the protocol modules                        are initialised.  (0 if not given)                <uni>   for those adapters that support chained                        devices, this is the unit selector for the                        chain of devices on the given port.  It should                        be zero for devices that don't support chaining.                        (0 if not given)                <mod>   this can be -1 to choose the best mode, or one                        of the mode numbers supported by the adapter.                        (-1 if not given)		<slv>   ATAPI CD-ROMs can be jumpered to master or slave.			Set this to 0 to choose the master drive, 1 to                        choose the slave, -1 (the default) to choose the			first drive found.                <dly>   some parallel ports require the driver to                         go more slowly.  -1 sets a default value that                        should work with the chosen protocol.  Otherwise,                        set this to a small integer, the larger it is                        the slower the port i/o.  In some cases, setting                        this to zero will speed up the device. (default -1)                                    major       You may use this parameter to overide the                        default major number (46) that this driver                        will use.  Be sure to change the device                        name as well.            name        This parameter is a character string that                        contains the name the kernel will use for this                        device (in /proc output, for instance).                        (default "pcd")            verbose     This parameter controls the amount of logging                        that the driver will do.  Set it to 0 for                        normal operation, 1 to see autoprobe progress                        messages, or 2 to see additional debugging                        output.  (default 0)              nice        This parameter controls the driver's use of                        idle CPU time, at the expense of some speed. 	If this driver is built into the kernel, you can use kernel        the following command line parameters, with the same values        as the corresponding module parameters listed above:	    pcd.drive0	    pcd.drive1	    pcd.drive2	    pcd.drive3	    pcd.nice        In addition, you can use the parameter pcd.disable to disable        the driver entirely.*//* Changes:	1.01	GRG 1998.01.24	Added test unit ready support	1.02    GRG 1998.05.06  Changes to pcd_completion, ready_wait,				and loosen interpretation of ATAPI			        standard for clearing error status.				Use spinlocks. Eliminate sti().	1.03    GRG 1998.06.16  Eliminated an Ugh	1.04	GRG 1998.08.15  Added extra debugging, improvements to				pcd_completion, use HZ in loop timing	1.05	GRG 1998.08.16	Conformed to "Uniform CD-ROM" standard	1.06    GRG 1998.08.19  Added audio ioctl support	1.07    GRG 1998.09.24  Increased reset timeout, added jumbo support*/#define	PCD_VERSION	"1.07"#define PCD_MAJOR	46#define PCD_NAME	"pcd"#define PCD_UNITS	4/* Here are things one can override from the insmod command.   Most are autoprobed by paride unless set here.  Verbose is off   by default.*/static int verbose = 0;static int major = PCD_MAJOR;static char *name = PCD_NAME;static int nice = 0;static int disable = 0;static int drive0[6] = { 0, 0, 0, -1, -1, -1 };static int drive1[6] = { 0, 0, 0, -1, -1, -1 };static int drive2[6] = { 0, 0, 0, -1, -1, -1 };static int drive3[6] = { 0, 0, 0, -1, -1, -1 };static int (*drives[4])[6] = {&drive0, &drive1, &drive2, &drive3};static int pcd_drive_count;enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};/* end of parameters */#include <linux/module.h>#include <linux/init.h>#include <linux/errno.h>#include <linux/fs.h>#include <linux/kernel.h>#include <linux/delay.h>#include <linux/cdrom.h>#include <linux/spinlock.h>#include <linux/blkdev.h>#include <asm/uaccess.h>static spinlock_t pcd_lock;#ifndef MODULE#include "setup.h"static STT pcd_stt[6] = {	{"drive0", 6, drive0},	{"drive1", 6, drive1},	{"drive2", 6, drive2},	{"drive3", 6, drive3},	{"disable", 1, &disable},	{"nice", 1, &nice}};void pcd_setup(char *str, int *ints){	generic_setup(pcd_stt, 6, str);}#endifMODULE_PARM(verbose, "i");MODULE_PARM(major, "i");MODULE_PARM(name, "s");MODULE_PARM(nice, "i");MODULE_PARM(drive0, "1-6i");MODULE_PARM(drive1, "1-6i");MODULE_PARM(drive2, "1-6i");MODULE_PARM(drive3, "1-6i");#include "paride.h"#include "pseudo.h"#define PCD_RETRIES	     5#define PCD_TMO		   800	/* timeout in jiffies */#define PCD_DELAY           50	/* spin delay in uS */#define PCD_READY_TMO	    20	/* in seconds */#define PCD_RESET_TMO	   100	/* in tenths of a second */#define PCD_SPIN	(1000000*PCD_TMO)/(HZ*PCD_DELAY)#define IDE_ERR		0x01#define IDE_DRQ         0x08#define IDE_READY       0x40#define IDE_BUSY        0x80static int pcd_open(struct cdrom_device_info *cdi, int purpose);static void pcd_release(struct cdrom_device_info *cdi);static int pcd_drive_status(struct cdrom_device_info *cdi, int slot_nr);static int pcd_media_changed(struct cdrom_device_info *cdi, int slot_nr);static int pcd_tray_move(struct cdrom_device_info *cdi, int position);static int pcd_lock_door(struct cdrom_device_info *cdi, int lock);static int pcd_drive_reset(struct cdrom_device_info *cdi);static int pcd_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn);static int pcd_audio_ioctl(struct cdrom_device_info *cdi,			   unsigned int cmd, void *arg);static int pcd_packet(struct cdrom_device_info *cdi,		      struct packet_command *cgc);static int pcd_detect(void);static void pcd_probe_capabilities(void);static void do_pcd_read_drq(void);static void do_pcd_request(request_queue_t * q);static void do_pcd_read(void);struct pcd_unit {	struct pi_adapter pia;	/* interface to paride layer */	struct pi_adapter *pi;	int drive;		/* master/slave */	int last_sense;		/* result of last request sense */	int changed;		/* media change seen */	int present;		/* does this unit exist ? */	char *name;		/* pcd0, pcd1, etc */	struct cdrom_device_info info;	/* uniform cdrom interface */	struct gendisk *disk;};struct pcd_unit pcd[PCD_UNITS];static char pcd_scratch[64];static char pcd_buffer[2048];	/* raw block buffer */static int pcd_bufblk = -1;	/* block in buffer, in CD units,				   -1 for nothing there. See also				   pd_unit.				 *//* the variables below are used mainly in the I/O request engine, which   processes only one request at a time.*/static struct pcd_unit *pcd_current; /* current request's drive */static struct request *pcd_req;static int pcd_retries;		/* retries on current request */static int pcd_busy;		/* request being processed ? */static int pcd_sector;		/* address of next requested sector */static int pcd_count;		/* number of blocks still to do */static char *pcd_buf;		/* buffer for request in progress */static int pcd_warned;		/* Have we logged a phase warning ? *//* kernel glue structures */static int pcd_block_open(struct inode *inode, struct file *file){	struct pcd_unit *cd = inode->i_bdev->bd_disk->private_data;	return cdrom_open(&cd->info, inode, file);}static int pcd_block_release(struct inode *inode, struct file *file){	struct pcd_unit *cd = inode->i_bdev->bd_disk->private_data;	return cdrom_release(&cd->info, file);}static int pcd_block_ioctl(struct inode *inode, struct file *file,				unsigned cmd, unsigned long arg){	struct pcd_unit *cd = inode->i_bdev->bd_disk->private_data;	return cdrom_ioctl(file, &cd->info, inode, cmd, arg);}static int pcd_block_media_changed(struct gendisk *disk){	struct pcd_unit *cd = disk->private_data;	return cdrom_media_changed(&cd->info);}static struct block_device_operations pcd_bdops = {	.owner		= THIS_MODULE,	.open		= pcd_block_open,	.release	= pcd_block_release,	.ioctl		= pcd_block_ioctl,	.media_changed	= pcd_block_media_changed,};static struct cdrom_device_ops pcd_dops = {	.open		= pcd_open,	.release	= pcd_release,	.drive_status	= pcd_drive_status,	.media_changed	= pcd_media_changed,	.tray_move	= pcd_tray_move,	.lock_door	= pcd_lock_door,	.get_mcn	= pcd_get_mcn,	.reset		= pcd_drive_reset,	.audio_ioctl	= pcd_audio_ioctl,	.generic_packet	= pcd_packet,	.capability	= CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK |			  CDC_MCN | CDC_MEDIA_CHANGED | CDC_RESET |			  CDC_PLAY_AUDIO | CDC_GENERIC_PACKET | CDC_CD_R |			  CDC_CD_RW,};static void pcd_init_units(void){	struct pcd_unit *cd;	int unit;	pcd_drive_count = 0;	for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {		struct gendisk *disk = alloc_disk(1);		if (!disk)			continue;		cd->disk = disk;		cd->pi = &cd->pia;		cd->present = 0;		cd->last_sense = 0;		cd->changed = 1;		cd->drive = (*drives[unit])[D_SLV];		if ((*drives[unit])[D_PRT])			pcd_drive_count++;		cd->name = &cd->info.name[0];		snprintf(cd->name, sizeof(cd->info.name), "%s%d", name, unit);		cd->info.ops = &pcd_dops;		cd->info.handle = cd;		cd->info.speed = 0;		cd->info.capacity = 1;		cd->info.mask = 0;		disk->major = major;		disk->first_minor = unit;		strcpy(disk->disk_name, cd->name);	/* umm... */		disk->fops = &pcd_bdops;	}}static int pcd_open(struct cdrom_device_info *cdi, int purpose){	struct pcd_unit *cd = cdi->handle;	if (!cd->present)		return -ENODEV;	return 0;}static void pcd_release(struct cdrom_device_info *cdi){}static inline int status_reg(struct pcd_unit *cd){	return pi_read_regr(cd->pi, 1, 6);}static inline int read_reg(struct pcd_unit *cd, int reg){	return pi_read_regr(cd->pi, 0, reg);}static inline void write_reg(struct pcd_unit *cd, int reg, int val){	pi_write_regr(cd->pi, 0, reg, val);}static int pcd_wait(struct pcd_unit *cd, int go, int stop, char *fun, char *msg){	int j, r, e, s, p;	j = 0;	while ((((r = status_reg(cd)) & go) || (stop && (!(r & stop))))	       && (j++ < PCD_SPIN))		udelay(PCD_DELAY);	if ((r & (IDE_ERR & stop)) || (j >= PCD_SPIN)) {		s = read_reg(cd, 7);		e = read_reg(cd, 1);		p = read_reg(cd, 2);		if (j >= PCD_SPIN)			e |= 0x100;		if (fun)			printk("%s: %s %s: alt=0x%x stat=0x%x err=0x%x"			       " loop=%d phase=%d\n",			       cd->name, fun, msg, r, s, e, j, p);		return (s << 8) + r;	}	return 0;}static int pcd_command(struct pcd_unit *cd, char *cmd, int dlen, char *fun){	pi_connect(cd->pi);	write_reg(cd, 6, 0xa0 + 0x10 * cd->drive);	if (pcd_wait(cd, IDE_BUSY | IDE_DRQ, 0, fun, "before command")) {		pi_disconnect(cd->pi);		return -1;	}	write_reg(cd, 4, dlen % 256);	write_reg(cd, 5, dlen / 256);	write_reg(cd, 7, 0xa0);	/* ATAPI packet command */	if (pcd_wait(cd, IDE_BUSY, IDE_DRQ, fun, "command DRQ")) {		pi_disconnect(cd->pi);		return -1;	}	if (read_reg(cd, 2) != 1) {		printk("%s: %s: command phase error\n", cd->name, fun);		pi_disconnect(cd->pi);		return -1;	}	pi_write_block(cd->pi, cmd, 12);	return 0;}static int pcd_completion(struct pcd_unit *cd, char *buf, char *fun){	int r, d, p, n, k, j;	r = -1;	k = 0;	j = 0;	if (!pcd_wait(cd, IDE_BUSY, IDE_DRQ | IDE_READY | IDE_ERR,		      fun, "completion")) {		r = 0;		while (read_reg(cd, 7) & IDE_DRQ) {			d = read_reg(cd, 4) + 256 * read_reg(cd, 5);			n = (d + 3) & 0xfffc;			p = read_reg(cd, 2) & 3;			if ((p == 2) && (n > 0) && (j == 0)) {				pi_read_block(cd->pi, buf, n);				if (verbose > 1)					printk("%s: %s: Read %d bytes\n",					       cd->name, fun, n);				r = 0;				j++;			} else {				if (verbose > 1)					printk					    ("%s: %s: Unexpected phase %d, d=%d, k=%d\n",					     cd->name, fun, p, d, k);				if ((verbose < 2) && !pcd_warned) {					pcd_warned = 1;					printk					    ("%s: WARNING: ATAPI phase errors\n",					     cd->name);				}				mdelay(1);			}			if (k++ > PCD_TMO) {				printk("%s: Stuck DRQ\n", cd->name);				break;			}			if (pcd_wait			    (cd, IDE_BUSY, IDE_DRQ | IDE_READY | IDE_ERR, fun,			     "completion")) {				r = -1;				break;			}		}	}	pi_disconnect(cd->pi);	return r;}static void pcd_req_sense(struct pcd_unit *cd, char *fun){	char rs_cmd[12] = { 0x03, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0 };	char buf[16];	int r, c;	r = pcd_command(cd, rs_cmd, 16, "Request sense");	mdelay(1);	if (!r)		pcd_completion(cd, buf, "Request sense");	cd->last_sense = -1;	c = 2;	if (!r) {		if (fun)			printk("%s: %s: Sense key: %x, ASC: %x, ASQ: %x\n",			       cd->name, fun, buf[2] & 0xf, buf[12], buf[13]);		c = buf[2] & 0xf;		cd->last_sense =		    c | ((buf[12] & 0xff) << 8) | ((buf[13] & 0xff) << 16);	}	if ((c == 2) || (c == 6))		cd->changed = 1;}static int pcd_atapi(struct pcd_unit *cd, char *cmd, int dlen, char *buf, char *fun){	int r;	r = pcd_command(cd, cmd, dlen, fun);	mdelay(1);	if (!r)

⌨️ 快捷键说明

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