📄 ide-probe.c
字号:
rc = 3; } if (drive->select.b.unit != 0) { /* exit with drive0 selected */ SELECT_DRIVE(&hwif->drives[0]); msleep(50); /* 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); msleep(50); hwif->OUTB(EXABYTE_ENABLE_NEST, IDE_COMMAND_REG); timeout = jiffies + WAIT_WORSTCASE; do { if (time_after(jiffies, timeout)) { printk("failed (timeout)\n"); return; } msleep(50); } while ((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT); msleep(50); 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 = kzalloc(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; } 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 (!drive->present) /* drive not found */ return 0; if (strstr(drive->id->model, "E X A B Y T E N E S T")) enable_nest(drive); /* 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 == 0) { generic_id(drive); return 1; } if (drive->media == ide_disk) { ide_disk_init_chs(drive); ide_disk_init_mult_count(drive); } return drive->present;}static void hwif_release_dev (struct device *dev){ ide_hwif_t *hwif = container_of(dev, ide_hwif_t, gendev); complete(&hwif->gendev_rel_comp);}static void hwif_register (ide_hwif_t *hwif){ int ret; /* register with global device tree */ strlcpy(hwif->gendev.bus_id,hwif->name,BUS_ID_SIZE); hwif->gendev.driver_data = hwif; if (hwif->gendev.parent == NULL) { if (hwif->pci_dev) hwif->gendev.parent = &hwif->pci_dev->dev; else /* Would like to do = &device_legacy */ hwif->gendev.parent = NULL; } hwif->gendev.release = hwif_release_dev; ret = device_register(&hwif->gendev); if (ret < 0) printk(KERN_WARNING "IDE: %s: device_register error: %d\n", __FUNCTION__, ret);}static int wait_hwif_ready(ide_hwif_t *hwif){ int unit, rc; printk(KERN_DEBUG "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 = ide_wait_not_busy(hwif, 35000); if (rc) return rc; /* Now make sure both master & slave are ready */ for (unit = 0; unit < MAX_DRIVES; unit++) { ide_drive_t *drive = &hwif->drives[unit]; /* Ignore disks that we will not probe for later. */ if (!drive->noprobe || drive->present) { SELECT_DRIVE(drive); if (IDE_CONTROL_REG) hwif->OUTB(drive->ctl, IDE_CONTROL_REG); mdelay(2); rc = ide_wait_not_busy(hwif, 35000); if (rc) goto out; } else printk(KERN_DEBUG "%s: ide_wait_not_busy() skipped\n", drive->name); }out: /* Exit function with master reselected (let's be sane) */ if (unit) SELECT_DRIVE(&hwif->drives[0]); return rc;}/** * ide_undecoded_slave - look for bad CF adapters * @hwif: interface * * Analyse the drives on the interface and attempt to decide if we * have the same drive viewed twice. This occurs with crap CF adapters * and PCMCIA sometimes. */void ide_undecoded_slave(ide_hwif_t *hwif){ ide_drive_t *drive0 = &hwif->drives[0]; ide_drive_t *drive1 = &hwif->drives[1]; if (drive0->present == 0 || drive1->present == 0) return; /* If the models don't match they are not the same product */ if (strcmp(drive0->id->model, drive1->id->model)) return; /* Serial numbers do not match */ if (strncmp(drive0->id->serial_no, drive1->id->serial_no, 20)) return; /* No serial number, thankfully very rare for CF */ if (drive0->id->serial_no[0] == 0) return; /* Appears to be an IDE flash adapter with decode bugs */ printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n"); drive1->present = 0;}EXPORT_SYMBOL_GPL(ide_undecoded_slave);/* * 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. */static void probe_hwif(ide_hwif_t *hwif){ unsigned long flags; unsigned int irqd; int unit; if (hwif->noprobe) return; if ((hwif->chipset != ide_4drives || !hwif->mate || !hwif->mate->present) && (ide_hwif_request_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); /* 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) == -EBUSY) printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name); /* * Need to probe slave device first to make it release PDIAG-. */ for (unit = MAX_DRIVES - 1; unit >= 0; unit--) { ide_drive_t *drive = &hwif->drives[unit]; drive->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 { msleep(50); 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); if (!hwif->present) { ide_hwif_release_regions(hwif); return; } if (hwif->fixup) hwif->fixup(hwif); for (unit = 0; unit < MAX_DRIVES; ++unit) { ide_drive_t *drive = &hwif->drives[unit]; if (drive->present) { if (drive->autotune == IDE_TUNE_AUTO) ide_set_max_pio(drive); if (drive->autotune != IDE_TUNE_DEFAULT && drive->autotune != IDE_TUNE_AUTO) continue; drive->nice1 = 1; if (hwif->ide_dma_on) { /* * Force DMAing for the beginning of the check. * Some chipsets appear to do interesting * things, if not checked and cleared. * PARANOIA!!! */ hwif->dma_off_quietly(drive); ide_set_dma(drive); } } } for (unit = 0; unit < MAX_DRIVES; ++unit) { ide_drive_t *drive = &hwif->drives[unit]; if (hwif->no_io_32bit) drive->no_io_32bit = 1; else drive->no_io_32bit = drive->id->dword_io ? 1 : 0; }}static int hwif_init(ide_hwif_t *hwif);static void hwif_register_devices(ide_hwif_t *hwif);static int probe_hwif_init(ide_hwif_t *hwif){ probe_hwif(hwif); if (!hwif_init(hwif)) { printk(KERN_INFO "%s: failed to initialize IDE interface\n", hwif->name); return -1; } if (hwif->present) hwif_register_devices(hwif); return 0;}#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. */static 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); } if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */ *match = new;}#endif /* MAX_HWIFS > 1 *//* * init request queue */static int ide_init_queue(ide_drive_t *drive){ struct request_queue *q; ide_hwif_t *hwif = HWIF(drive); int max_sectors = 256; int max_sg_entries = PRD_ENTRIES; /* * Our default set up assumes the normal IDE case, * that is 64K segmenting, standard PRD setup * and LBA28. Some drivers then impose their own * limits and LBA48 we could raise it but as yet * do not. */ q = blk_init_queue_node(do_ide_request, &ide_lock, hwif_to_node(hwif)); if (!q) return 1; q->queuedata = drive; blk_queue_segment_boundary(q, 0xffff); if (!hwif->rqsize) { if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) || (hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA)) hwif->rqsize = 256; else hwif->rqsize = 65536; } if (hwif->rqsize < max_sectors) max_sectors = hwif->rqsize; blk_queue_max_sectors(q, max_sectors);#ifdef CONFIG_PCI /* When we have an IOMMU, we may have a problem where pci_map_sg() * creates segments that don't completely match our boundary * requirements and thus need to be broken up again. Because it * doesn't align properly either, we may actually have to break up * to more segments than what was we got in the first place, a max * worst case is twice as many. * This will be fixed once we teach pci_map_sg() about our boundary * requirements, hopefully soon. *FIXME* */ if (!PCI_DMA_BUS_IS_PHYS) max_sg_entries >>= 1;#endif /* CONFIG_PCI */ blk_queue_max_hw_segments(q, max_sg_entries);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -