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

📄 ide-probe.c

📁 ep9315平台下硬盘驱动的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
		if (hwif->INB(IDE_STATUS_REG) == (BUSY_STAT|READY_STAT))			return 4;		if ((rc == 1 && cmd == WIN_PIDENTIFY) &&			((drive->autotune == IDE_TUNE_DEFAULT) ||			(drive->autotune == IDE_TUNE_AUTO))) {			unsigned long timeout;			printk("%s: no response (status = 0x%02x), "				"resetting drive\n", drive->name,				hwif->INB(IDE_STATUS_REG));			ide_delay_50ms();			hwif->OUTB(drive->select.all, IDE_SELECT_REG);			ide_delay_50ms();			hwif->OUTB(WIN_SRST, IDE_COMMAND_REG);			timeout = jiffies;			while (((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) &&			       time_before(jiffies, timeout + WAIT_WORSTCASE))				ide_delay_50ms();			rc = try_to_identify(drive, cmd);		}		if (rc == 1)			printk("%s: no response (status = 0x%02x)\n",				drive->name, hwif->INB(IDE_STATUS_REG));		/* ensure drive irq is clear */		(void) hwif->INB(IDE_STATUS_REG);	} else {		/* not present or maybe ATAPI */		rc = 3;	}	if (drive->select.b.unit != 0) {		/* exit with drive0 selected */		SELECT_DRIVE(&hwif->drives[0]);		ide_delay_50ms();		/* ensure drive irq is clear */		(void) hwif->INB(IDE_STATUS_REG);	}	return rc;}/* * */static void enable_nest (ide_drive_t *drive){	ide_hwif_t *hwif = HWIF(drive);	unsigned long timeout;	printk("%s: enabling %s -- ", hwif->name, drive->id->model);	SELECT_DRIVE(drive);	ide_delay_50ms();	hwif->OUTB(EXABYTE_ENABLE_NEST, IDE_COMMAND_REG);	timeout = jiffies + WAIT_WORSTCASE;	do {		if (time_after(jiffies, timeout)) {			printk("failed (timeout)\n");			return;		}		ide_delay_50ms();	} while ((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT);	ide_delay_50ms();	if (!OK_STAT((hwif->INB(IDE_STATUS_REG)), 0, BAD_STAT)) {		printk("failed (status = 0x%02x)\n", hwif->INB(IDE_STATUS_REG));	} else {		printk("success\n");	}	/* if !(success||timed-out) */	if (do_probe(drive, WIN_IDENTIFY) >= 2) {		/* look for ATAPI device */		(void) do_probe(drive, WIN_PIDENTIFY);	}}/** *	probe_for_drives	-	upper level drive probe *	@drive: drive to probe for * *	probe_for_drive() tests for existence of a given drive using do_probe() *	and presents things to the user as needed. * *	Returns:	0  no device was found *			1  device was found (note: drive->present might *			   still be 0) */ static inline u8 probe_for_drive (ide_drive_t *drive){	/*	 *	In order to keep things simple we have an id	 *	block for all drives at all times. If the device	 *	is pre ATA or refuses ATA/ATAPI identify we	 *	will add faked data to this.	 *	 *	Also note that 0 everywhere means "can't do X"	 */	 	drive->id = kmalloc(SECTOR_WORDS *4, GFP_KERNEL);	drive->id_read = 0;	if(drive->id == NULL)	{		printk(KERN_ERR "ide: out of memory for id data.\n");		return 0;	}	memset(drive->id, 0, SECTOR_WORDS * 4);	strcpy(drive->id->model, "UNKNOWN");		/* skip probing? */	if (!drive->noprobe)	{		/* if !(success||timed-out) */		if (do_probe(drive, WIN_IDENTIFY) >= 2) {			/* look for ATAPI device */			(void) do_probe(drive, WIN_PIDENTIFY);		}		if (strstr(drive->id->model, "E X A B Y T E N E S T"))			enable_nest(drive);		if (!drive->present)			/* drive not found */			return 0;			/* identification failed? */		if (!drive->id_read) {			if (drive->media == ide_disk) {				printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n",					drive->name, drive->cyl,					drive->head, drive->sect);			} else if (drive->media == ide_cdrom) {				printk(KERN_INFO "%s: ATAPI cdrom (?)\n", drive->name);			} else {				/* nuke it */				printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name);				drive->present = 0;			}		}		/* drive was found */	}	if(!drive->present)		return 0;	/* The drive wasn't being helpful. Add generic info only */	if(!drive->id_read)		generic_id(drive);	return drive->present;}#define hwif_check_region(addr, num) \	((hwif->mmio) ? check_mem_region((addr),(num)) : check_region((addr),(num)))/** *	hwif_check_regions	-	check resources for IDE *	@hwif: interface to use * *	Checks if all the needed resources for an interface are free *	providing the interface is PIO. Right now core IDE code does *	this work which is deeply wrong. MMIO leaves it to the controller *	driver, PIO will migrate this way over time */ static int hwif_check_regions (ide_hwif_t *hwif){	u32 i		= 0;	int addr_errs	= 0;	if (hwif->mmio == 2)		return 0;	addr_errs  = hwif_check_region(hwif->io_ports[IDE_DATA_OFFSET], 1);	for (i = IDE_ERROR_OFFSET; i <= IDE_STATUS_OFFSET; i++)		addr_errs += hwif_check_region(hwif->io_ports[i], 1);	if (hwif->io_ports[IDE_CONTROL_OFFSET])		addr_errs += hwif_check_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);#if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)	if (hwif->io_ports[IDE_IRQ_OFFSET])		addr_errs += hwif_check_region(hwif->io_ports[IDE_IRQ_OFFSET], 1);#endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */	/* If any errors are return, we drop the hwif interface. */	hwif->straight8 = 0;	return(addr_errs);}//EXPORT_SYMBOL(hwif_check_regions);#define hwif_request_region(addr, num, name)	\	((hwif->mmio) ? request_mem_region((addr),(num),(name)) : request_region((addr),(num),(name)))static void hwif_register (ide_hwif_t *hwif){	u32 i = 0;	if (hwif->mmio == 2)		return;	if (hwif->io_ports[IDE_CONTROL_OFFSET])		hwif_request_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1, hwif->name);#if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)	if (hwif->io_ports[IDE_IRQ_OFFSET])		hwif_request_region(hwif->io_ports[IDE_IRQ_OFFSET], 1, hwif->name);#endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */	if (((unsigned long)hwif->io_ports[IDE_DATA_OFFSET] | 7) ==	    ((unsigned long)hwif->io_ports[IDE_STATUS_OFFSET])) {		hwif_request_region(hwif->io_ports[IDE_DATA_OFFSET], 8, hwif->name);		hwif->straight8 = 1;		return;	}	for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)		hwif_request_region(hwif->io_ports[i], 1, hwif->name);}//EXPORT_SYMBOL(hwif_register);/* Enable code below on all archs later, for now, I want it on PPC */#ifdef CONFIG_PPC/* * This function waits for the hwif to report a non-busy status * see comments in probe_hwif() */static int wait_not_busy(ide_hwif_t *hwif, unsigned long timeout){	u8 stat = 0;		while(timeout--) {		/* Turn this into a schedule() sleep once I'm sure		 * about locking issues (2.5 work ?)		 */		mdelay(1);		stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);		if ((stat & BUSY_STAT) == 0)			break;		/* Assume a value of 0xff means nothing is connected to		 * the interface and it doesn't implement the pull-down		 * resistor on D7		 */		if (stat == 0xff)			break;	}	return ((stat & BUSY_STAT) == 0) ? 0 : -EBUSY;}static int wait_hwif_ready(ide_hwif_t *hwif){	int rc;	printk(KERN_INFO "Probing IDE interface %s...\n", hwif->name);	/* Let HW settle down a bit from whatever init state we	 * come from */	mdelay(2);	/* Wait for BSY bit to go away, spec timeout is 30 seconds,	 * I know of at least one disk who takes 31 seconds, I use 35	 * here to be safe	 */	rc = wait_not_busy(hwif, 35000);	if (rc)		return rc;	/* Now make sure both master & slave are ready */	SELECT_DRIVE(&hwif->drives[0]);	hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);	mdelay(2);	rc = wait_not_busy(hwif, 10000);	if (rc)		return rc;	SELECT_DRIVE(&hwif->drives[1]);	hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);	mdelay(2);	rc = wait_not_busy(hwif, 10000);	/* Exit function with master reselected (let's be sane) */	SELECT_DRIVE(&hwif->drives[0]);		return rc;}#endif /* CONFIG_PPC *//* * This routine only knows how to look for drive units 0 and 1 * on an interface, so any setting of MAX_DRIVES > 2 won't work here. */void probe_hwif (ide_hwif_t *hwif){	unsigned int unit;	unsigned long flags;	unsigned int irqd;	if (hwif->noprobe)		return;#ifdef CONFIG_BLK_DEV_IDE	if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA) {		extern void probe_cmos_for_drives(ide_hwif_t *);		probe_cmos_for_drives(hwif);	}#endif	if ((hwif->chipset != ide_4drives || !hwif->mate || !hwif->mate->present) &&#if CONFIG_BLK_DEV_PDC4030	    (hwif->chipset != ide_pdc4030 || hwif->channel == 0) &&#endif /* CONFIG_BLK_DEV_PDC4030 */	    (hwif_check_regions(hwif))) {		u16 msgout = 0;		for (unit = 0; unit < MAX_DRIVES; ++unit) {			ide_drive_t *drive = &hwif->drives[unit];			if (drive->present) {				drive->present = 0;				printk(KERN_ERR "%s: ERROR, PORTS ALREADY IN USE\n",					drive->name);				msgout = 1;			}		}		if (!msgout)			printk(KERN_ERR "%s: ports already in use, skipping probe\n",				hwif->name);		return;		}	/*	 * We must always disable IRQ, as probe_for_drive will assert IRQ, but	 * we'll install our IRQ driver much later...	 */	irqd = hwif->irq;	if (irqd)		disable_irq(hwif->irq);	local_irq_set(flags);#ifdef CONFIG_PPC	/* This is needed on some PPCs and a bunch of BIOS-less embedded	 * platforms. Typical cases are:	 * 	 *  - The firmware hard reset the disk before booting the kernel,	 *    the drive is still doing it's poweron-reset sequence, that	 *    can take up to 30 seconds	 *  - The firmware does nothing (or no firmware), the device is	 *    still in POST state (same as above actually).	 *  - Some CD/DVD/Writer combo drives tend to drive the bus during	 *    their reset sequence even when they are non-selected slave	 *    devices, thus preventing discovery of the main HD	 *    	 *  Doing this wait-for-busy should not harm any existing configuration	 *  (at least things won't be worse than what current code does, that	 *  is blindly go & talk to the drive) and fix some issues like the	 *  above.	 *  	 *  BenH.	 */	if (wait_hwif_ready(hwif))		printk(KERN_WARNING "%s: Wait for ready failed before probe !\n", hwif->name);#endif /* CONFIG_PPC */	/*	 * Second drive should only exist if first drive was found,	 * but a lot of cdrom drives are configured as single slaves.	 */	for (unit = 0; unit < MAX_DRIVES; ++unit) {		ide_drive_t *drive = &hwif->drives[unit];		drive->dn = ((hwif->channel ? 2 : 0) + unit);		hwif->drives[unit].dn = ((hwif->channel ? 2 : 0) + unit);		(void) probe_for_drive(drive);		if (drive->present && !hwif->present) {			hwif->present = 1;			if (hwif->chipset != ide_4drives ||			    !hwif->mate || 			    !hwif->mate->present) {				hwif_register(hwif);			}		}	}	if (hwif->io_ports[IDE_CONTROL_OFFSET] && hwif->reset) {		unsigned long timeout = jiffies + WAIT_WORSTCASE;		u8 stat;		printk(KERN_WARNING "%s: reset\n", hwif->name);		hwif->OUTB(12, hwif->io_ports[IDE_CONTROL_OFFSET]);		udelay(10);		hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);		do {			ide_delay_50ms();			stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);		} while ((stat & BUSY_STAT) && time_after(timeout, jiffies));	}	local_irq_restore(flags);	/*	 * Use cached IRQ number. It might be (and is...) changed by probe	 * code above	 */	if (irqd)		enable_irq(irqd);	for (unit = 0; unit < MAX_DRIVES; ++unit) {		ide_drive_t *drive = &hwif->drives[unit];		int enable_dma = 1;		if (drive->present) {			if (hwif->tuneproc != NULL && 				drive->autotune == IDE_TUNE_AUTO)				/* auto-tune PIO mode */				hwif->tuneproc(drive, 255);#ifdef CONFIG_IDEDMA_ONLYDISK			if (drive->media != ide_disk)				enable_dma = 0;#endif			/*			 * MAJOR HACK BARF :-/			 *			 * FIXME: chipsets own this cruft!			 */			/*			 * Move here to prevent module loading clashing.			 */	//		drive->autodma = hwif->autodma;			if ((hwif->ide_dma_check) &&				((drive->autotune == IDE_TUNE_DEFAULT) ||				(drive->autotune == IDE_TUNE_AUTO))) {				/*				 * Force DMAing for the beginning of the check.				 * Some chipsets appear to do interesting				 * things, if not checked and cleared.				 *   PARANOIA!!!				 */				hwif->ide_dma_off_quietly(drive);				if (enable_dma)					hwif->ide_dma_check(drive);			}		}	}}EXPORT_SYMBOL(probe_hwif);#if 0int hwif_init (ide_hwif_t *hwif);int probe_hwif_init (ide_hwif_t *hwif){	hwif->initializing = 1;	probe_hwif(hwif);	hwif_init(hwif);#if 1	if (hwif->present) {		u16 unit = 0;		for (unit = 0; unit < MAX_DRIVES; ++unit) {			ide_drive_t *drive = &hwif->drives[unit];			if (drive->present) {				ata_attach(drive);			}		}	}#endif	hwif->initializing = 0;	return 0;}EXPORT_SYMBOL(probe_hwif_init);#endif#if MAX_HWIFS > 1/* * save_match() is used to simplify logic in init_irq() below. * * A loophole here is that we may not know about a particular * hwif's irq until after that hwif is actually probed/initialized.. * This could be a problem for the case where an hwif is on a * dual interface that requires serialization (eg. cmd640) and another * hwif using one of the same irqs is initialized beforehand. * * This routine detects and reports such situations, but does not fix them. */void save_match (ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match){	ide_hwif_t *m = *match;	if (m && m->hwgroup && m->hwgroup != new->hwgroup) {		if (!new->hwgroup)			return;		printk("%s: potential irq problem with %s and %s\n",			hwif->name, new->name, m->name);	}

⌨️ 快捷键说明

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