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

📄 ide-io.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
 		printk("ns=0x%02x ", args[2]); 		printk("sc=0x%02x ", args[3]); 		printk("lcyl=0x%02x ", args[4]); 		printk("hcyl=0x%02x ", args[5]); 		printk("sel=0x%02x\n", args[6]);#endif 		hwif->OUTB(args[1], IDE_FEATURE_REG); 		hwif->OUTB(args[3], IDE_SECTOR_REG); 		hwif->OUTB(args[4], IDE_LCYL_REG); 		hwif->OUTB(args[5], IDE_HCYL_REG); 		hwif->OUTB((args[6] & 0xEF)|drive->select.all, IDE_SELECT_REG); 		ide_cmd(drive, args[0], args[2], &drive_cmd_intr); 		return ide_started; 	} else if (rq->cmd_type == REQ_TYPE_ATA_CMD) { 		u8 *args = rq->buffer;		if (!args)			goto done;#ifdef DEBUG 		printk("%s: DRIVE_CMD ", drive->name); 		printk("cmd=0x%02x ", args[0]); 		printk("sc=0x%02x ", args[1]); 		printk("fr=0x%02x ", args[2]); 		printk("xx=0x%02x\n", args[3]);#endif 		if (args[0] == WIN_SMART) { 			hwif->OUTB(0x4f, IDE_LCYL_REG); 			hwif->OUTB(0xc2, IDE_HCYL_REG); 			hwif->OUTB(args[2],IDE_FEATURE_REG); 			hwif->OUTB(args[1],IDE_SECTOR_REG); 			ide_cmd(drive, args[0], args[3], &drive_cmd_intr); 			return ide_started; 		} 		hwif->OUTB(args[2],IDE_FEATURE_REG); 		ide_cmd(drive, args[0], args[1], &drive_cmd_intr); 		return ide_started; 	}done: 	/* 	 * NULL is actually a valid way of waiting for 	 * all current requests to be flushed from the queue. 	 */#ifdef DEBUG 	printk("%s: DRIVE_CMD (null)\n", drive->name);#endif 	ide_end_drive_cmd(drive,			hwif->INB(IDE_STATUS_REG),			hwif->INB(IDE_ERROR_REG)); 	return ide_stopped;}static void ide_check_pm_state(ide_drive_t *drive, struct request *rq){	struct request_pm_state *pm = rq->data;	if (blk_pm_suspend_request(rq) &&	    pm->pm_step == ide_pm_state_start_suspend)		/* Mark drive blocked when starting the suspend sequence. */		drive->blocked = 1;	else if (blk_pm_resume_request(rq) &&		 pm->pm_step == ide_pm_state_start_resume) {		/* 		 * The first thing we do on wakeup is to wait for BSY bit to		 * go away (with a looong timeout) as a drive on this hwif may		 * just be POSTing itself.		 * We do that before even selecting as the "other" device on		 * the bus may be broken enough to walk on our toes at this		 * point.		 */		int rc;#ifdef DEBUG_PM		printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name);#endif		rc = ide_wait_not_busy(HWIF(drive), 35000);		if (rc)			printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name);		SELECT_DRIVE(drive);		if (IDE_CONTROL_REG)			HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG);		rc = ide_wait_not_busy(HWIF(drive), 100000);		if (rc)			printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);	}}/** *	start_request	-	start of I/O and command issuing for IDE * *	start_request() initiates handling of a new I/O request. It *	accepts commands and I/O (read/write) requests. It also does *	the final remapping for weird stuff like EZDrive. Once  *	device mapper can work sector level the EZDrive stuff can go away * *	FIXME: this function needs a rename */ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq){	ide_startstop_t startstop;	sector_t block;	BUG_ON(!blk_rq_started(rq));#ifdef DEBUG	printk("%s: start_request: current=0x%08lx\n",		HWIF(drive)->name, (unsigned long) rq);#endif	/* bail early if we've exceeded max_failures */	if (drive->max_failures && (drive->failures > drive->max_failures)) {		goto kill_rq;	}	block    = rq->sector;	if (blk_fs_request(rq) &&	    (drive->media == ide_disk || drive->media == ide_floppy)) {		block += drive->sect0;	}	/* Yecch - this will shift the entire interval,	   possibly killing some innocent following sector */	if (block == 0 && drive->remap_0_to_1 == 1)		block = 1;  /* redirect MBR access to EZ-Drive partn table */	if (blk_pm_request(rq))		ide_check_pm_state(drive, rq);	SELECT_DRIVE(drive);	if (ide_wait_stat(&startstop, drive, drive->ready_stat, BUSY_STAT|DRQ_STAT, WAIT_READY)) {		printk(KERN_ERR "%s: drive not ready for command\n", drive->name);		return startstop;	}	if (!drive->special.all) {		ide_driver_t *drv;		/*		 * We reset the drive so we need to issue a SETFEATURES.		 * Do it _after_ do_special() restored device parameters.		 */		if (drive->current_speed == 0xff)			ide_config_drive_speed(drive, drive->desired_speed);		if (rq->cmd_type == REQ_TYPE_ATA_CMD ||		    rq->cmd_type == REQ_TYPE_ATA_TASK ||		    rq->cmd_type == REQ_TYPE_ATA_TASKFILE)			return execute_drive_cmd(drive, rq);		else if (blk_pm_request(rq)) {			struct request_pm_state *pm = rq->data;#ifdef DEBUG_PM			printk("%s: start_power_step(step: %d)\n",				drive->name, rq->pm->pm_step);#endif			startstop = ide_start_power_step(drive, rq);			if (startstop == ide_stopped &&			    pm->pm_step == ide_pm_state_completed)				ide_complete_pm_request(drive, rq);			return startstop;		}		drv = *(ide_driver_t **)rq->rq_disk->private_data;		return drv->do_request(drive, rq, block);	}	return do_special(drive);kill_rq:	ide_kill_rq(drive, rq);	return ide_stopped;}/** *	ide_stall_queue		-	pause an IDE device *	@drive: drive to stall *	@timeout: time to stall for (jiffies) * *	ide_stall_queue() can be used by a drive to give excess bandwidth back *	to the hwgroup by sleeping for timeout jiffies. */ void ide_stall_queue (ide_drive_t *drive, unsigned long timeout){	if (timeout > WAIT_WORSTCASE)		timeout = WAIT_WORSTCASE;	drive->sleep = timeout + jiffies;	drive->sleeping = 1;}EXPORT_SYMBOL(ide_stall_queue);#define WAKEUP(drive)	((drive)->service_start + 2 * (drive)->service_time)/** *	choose_drive		-	select a drive to service *	@hwgroup: hardware group to select on * *	choose_drive() selects the next drive which will be serviced. *	This is necessary because the IDE layer can't issue commands *	to both drives on the same cable, unlike SCSI. */ static inline ide_drive_t *choose_drive (ide_hwgroup_t *hwgroup){	ide_drive_t *drive, *best;repeat:		best = NULL;	drive = hwgroup->drive;	/*	 * drive is doing pre-flush, ordered write, post-flush sequence. even	 * though that is 3 requests, it must be seen as a single transaction.	 * we must not preempt this drive until that is complete	 */	if (blk_queue_flushing(drive->queue)) {		/*		 * small race where queue could get replugged during		 * the 3-request flush cycle, just yank the plug since		 * we want it to finish asap		 */		blk_remove_plug(drive->queue);		return drive;	}	do {		if ((!drive->sleeping || time_after_eq(jiffies, drive->sleep))		    && !elv_queue_empty(drive->queue)) {			if (!best			 || (drive->sleeping && (!best->sleeping || time_before(drive->sleep, best->sleep)))			 || (!best->sleeping && time_before(WAKEUP(drive), WAKEUP(best))))			{				if (!blk_queue_plugged(drive->queue))					best = drive;			}		}	} while ((drive = drive->next) != hwgroup->drive);	if (best && best->nice1 && !best->sleeping && best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) {		long t = (signed long)(WAKEUP(best) - jiffies);		if (t >= WAIT_MIN_SLEEP) {		/*		 * We *may* have some time to spare, but first let's see if		 * someone can potentially benefit from our nice mood today..		 */			drive = best->next;			do {				if (!drive->sleeping				 && time_before(jiffies - best->service_time, WAKEUP(drive))				 && time_before(WAKEUP(drive), jiffies + t))				{					ide_stall_queue(best, min_t(long, t, 10 * WAIT_MIN_SLEEP));					goto repeat;				}			} while ((drive = drive->next) != best);		}	}	return best;}/* * Issue a new request to a drive from hwgroup * Caller must have already done spin_lock_irqsave(&ide_lock, ..); * * A hwgroup is a serialized group of IDE interfaces.  Usually there is * exactly one hwif (interface) per hwgroup, but buggy controllers (eg. CMD640) * may have both interfaces in a single hwgroup to "serialize" access. * Or possibly multiple ISA interfaces can share a common IRQ by being grouped * together into one hwgroup for serialized access. * * Note also that several hwgroups can end up sharing a single IRQ, * possibly along with many other devices.  This is especially common in * PCI-based systems with off-board IDE controller cards. * * The IDE driver uses the single global ide_lock spinlock to protect * access to the request queues, and to protect the hwgroup->busy flag. * * The first thread into the driver for a particular hwgroup sets the * hwgroup->busy flag to indicate that this hwgroup is now active, * and then initiates processing of the top request from the request queue. * * Other threads attempting entry notice the busy setting, and will simply * queue their new requests and exit immediately.  Note that hwgroup->busy * remains set even when the driver is merely awaiting the next interrupt. * Thus, the meaning is "this hwgroup is busy processing a request". * * When processing of a request completes, the completing thread or IRQ-handler * will start the next request from the queue.  If no more work remains, * the driver will clear the hwgroup->busy flag and exit. * * The ide_lock (spinlock) is used to protect all access to the * hwgroup->busy flag, but is otherwise not needed for most processing in * the driver.  This makes the driver much more friendlier to shared IRQs * than previous designs, while remaining 100% (?) SMP safe and capable. */static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq){	ide_drive_t	*drive;	ide_hwif_t	*hwif;	struct request	*rq;	ide_startstop_t	startstop;	int             loops = 0;	/* for atari only: POSSIBLY BROKEN HERE(?) */	ide_get_lock(ide_intr, hwgroup);	/* caller must own ide_lock */	BUG_ON(!irqs_disabled());	while (!hwgroup->busy) {		hwgroup->busy = 1;		drive = choose_drive(hwgroup);		if (drive == NULL) {			int sleeping = 0;			unsigned long sleep = 0; /* shut up, gcc */			hwgroup->rq = NULL;			drive = hwgroup->drive;			do {				if (drive->sleeping && (!sleeping || time_before(drive->sleep, sleep))) {					sleeping = 1;					sleep = drive->sleep;				}			} while ((drive = drive->next) != hwgroup->drive);			if (sleeping) {		/*		 * Take a short snooze, and then wake up this hwgroup again.		 * This gives other hwgroups on the same a chance to		 * play fairly with us, just in case there are big differences		 * in relative throughputs.. don't want to hog the cpu too much.		 */				if (time_before(sleep, jiffies + WAIT_MIN_SLEEP))					sleep = jiffies + WAIT_MIN_SLEEP;#if 1				if (timer_pending(&hwgroup->timer))					printk(KERN_CRIT "ide_set_handler: timer already active\n");#endif				/* so that ide_timer_expiry knows what to do */				hwgroup->sleeping = 1;				hwgroup->req_gen_timer = hwgroup->req_gen;				mod_timer(&hwgroup->timer, sleep);				/* we purposely leave hwgroup->busy==1				 * while sleeping */			} else {				/* Ugly, but how can we sleep for the lock				 * otherwise? perhaps from tq_disk?				 */				/* for atari only */				ide_release_lock();				hwgroup->busy = 0;			}			/* no more work for this hwgroup (for now) */			return;		}	again:		hwif = HWIF(drive);		if (hwgroup->hwif->sharing_irq &&		    hwif != hwgroup->hwif &&		    hwif->io_ports[IDE_CONTROL_OFFSET]) {			/* set nIEN for previous hwif */			SELECT_INTERRUPT(drive);		}		hwgroup->hwif = hwif;		hwgroup->drive = drive;		drive->sleeping = 0;		drive->service_start = jiffies;		if (blk_queue_plugged(drive->queue)) {			printk(KERN_ERR "ide: huh? queue was plugged!\n");			break;		}		/*		 * we know that the queue isn't empty, but this can happen		 * if the q->prep_rq_fn() decides to kill a request		 */		rq = elv_next_request(drive->queue);		if (!rq) {			hwgroup->busy = 0;			break;		}		/*		 * Sanity: don't accept a request that isn't a PM request		 * if we are currently power managed. This is very important as		 * blk_stop_queue() doesn't prevent the elv_next_request()		 * above to return us whatever is in the queue. Since we call		 * ide_do_request() ourselves, we end up taking requests while		 * the queue is blocked...		 * 		 * We let requests forced at head of queue with ide-preempt		 * though. I hope that doesn't happen too much, hopefully not		 * unless the subdriver triggers such a thing in its own PM		 * state machine.		 *		 * We count how many times we loop here to make sure we service		 * all drives in the hwgroup without looping for ever		 */		if (drive->blocked && !blk_pm_request(rq) && !(rq->cmd_flags & REQ_PREEMPT)) {			drive = drive->next ? drive->next : hwgroup->drive;			if (loops++ < 4 && !blk_queue_plugged(drive->queue))				goto again;			/* We clear busy, there should be no pending ATA command at this point. */			hwgroup->busy = 0;			break;		}		hwgroup->rq = rq;		/*		 * Some systems have trouble with IDE IRQs arriving while		 * the driver is still setting things up.  So, here we disable		 * the IRQ used by this interface while the request is being started.		 * This may look bad at first, but pretty much the same thing		 * happens anyway when any interrupt comes in, IDE or otherwise		 *  -- the kernel masks the IRQ while it is being handled.		 */		if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq)			disable_irq_nosync(hwif->irq);		spin_unlock(&ide_lock);		local_irq_enable_in_hardirq();			/* allow other IRQs while we start this request */		startstop = start_request(drive, rq);		spin_lock_irq(&ide_lock);		if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq)			enable_irq(hwif->irq);		if (startstop == ide_stopped)			hwgroup->busy = 0;	}}/* * Passes the stuff to ide_do_request */void do_ide_request(struct request_queue *q){	ide_drive_t *drive = q->queuedata;	ide_do_request(HWGROUP(drive), IDE_NO_IRQ);}/* * un-busy the hwgroup etc, and clear any pending DMA status. we want to * retry the current request in pio mode instead of risking tossing it * all away */static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error){	ide_hwif_t *hwif = HWIF(drive);	struct request *rq;	ide_startstop_t ret = ide_stopped;

⌨️ 快捷键说明

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