X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fide%2Fsetup-pci.c;h=695e23904d3030e61c4f2ba24d88740415847a07;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=b485e6b706c89a4ffb1f84327f27c4316ab7677d;hpb=9213980e6a70d8473e0ffd4b39ab5b6caaba9ff5;p=linux-2.6.git diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c index b485e6b70..695e23904 100644 --- a/drivers/ide/setup-pci.c +++ b/drivers/ide/setup-pci.c @@ -18,7 +18,6 @@ * configuration of all PCI IDE interfaces present in a system. */ -#include #include #include #include @@ -28,6 +27,7 @@ #include #include #include +#include #include #include @@ -101,7 +101,7 @@ static ide_hwif_t *ide_match_hwif(unsigned long io_base, u8 bootable, const char return hwif; /* pick an unused entry */ } } - for (h = 0; h < 2; ++h) { + for (h = 0; h < 2 && h < MAX_HWIFS; ++h) { hwif = ide_hwifs + h; if (hwif->chipset == ide_unknown) return hwif; /* pick an unused entry */ @@ -185,19 +185,16 @@ static unsigned long ide_get_or_set_dma_base (ide_hwif_t *hwif) second_chance_to_dma: #endif /* CONFIG_BLK_DEV_IDEDMA_FORCED */ - if ((hwif->mmio) && (hwif->dma_base)) + if (hwif->mmio) return hwif->dma_base; if (hwif->mate && hwif->mate->dma_base) { dma_base = hwif->mate->dma_base - (hwif->channel ? 0 : 8); } else { - dma_base = (hwif->mmio) ? - ((unsigned long) hwif->hwif_data) : - (pci_resource_start(dev, 4)); + dma_base = pci_resource_start(dev, 4); if (!dma_base) { - printk(KERN_ERR "%s: dma_base is invalid (0x%04lx)\n", - hwif->cds->name, dma_base); - dma_base = 0; + printk(KERN_ERR "%s: dma_base is invalid\n", + hwif->cds->name); } } @@ -231,6 +228,7 @@ second_chance_to_dma: case PCI_DEVICE_ID_AMD_VIPER_7409: case PCI_DEVICE_ID_CMD_643: case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE: + case PCI_DEVICE_ID_REVOLUTION: simplex_stat = hwif->INB(dma_base + 2); hwif->OUTB((simplex_stat&0x60),(dma_base + 2)); simplex_stat = hwif->INB(dma_base + 2); @@ -251,7 +249,6 @@ second_chance_to_dma: simplex_stat = hwif->INB(dma_base + 2); if (simplex_stat & 0x80) { /* simplex device? */ -#if 0 /* * At this point we haven't probed the drives so we can't make the * appropriate decision. Really we should defer this problem @@ -259,18 +256,7 @@ second_chance_to_dma: * to be the DMA end. This has to be become dynamic to handle hot * plug. */ - /* Don't enable DMA on a simplex channel with no drives */ - if (!hwif->drives[0].present && !hwif->drives[1].present) - { - printk(KERN_INFO "%s: simplex device with no drives: DMA disabled\n", - hwif->cds->name); - dma_base = 0; - } - /* If our other channel has DMA then we cannot */ - else -#endif - if(hwif->mate && hwif->mate->dma_base) - { + if (hwif->mate && hwif->mate->dma_base) { printk(KERN_INFO "%s: simplex device: " "DMA disabled\n", hwif->cds->name); @@ -305,14 +291,16 @@ EXPORT_SYMBOL_GPL(ide_setup_pci_noise); static int ide_pci_enable(struct pci_dev *dev, ide_pci_device_t *d) { - + int ret; + if (pci_enable_device(dev)) { - if (pci_enable_device_bars(dev, 1 << 4)) { + ret = pci_enable_device_bars(dev, 1 << 4); + if (ret < 0) { printk(KERN_WARNING "%s: (ide_setup_pci_device:) " "Could not enable device.\n", d->name); - return -EBUSY; - } else - printk(KERN_WARNING "%s: BIOS configuration fixed.\n", d->name); + goto out; + } + printk(KERN_WARNING "%s: BIOS configuration fixed.\n", d->name); } /* @@ -320,18 +308,21 @@ static int ide_pci_enable(struct pci_dev *dev, ide_pci_device_t *d) * dma mask field to the ide_pci_device_t if we need it (or let * lower level driver set the dma mask) */ - if (pci_set_dma_mask(dev, 0xffffffff)) { + ret = pci_set_dma_mask(dev, DMA_32BIT_MASK); + if (ret < 0) { printk(KERN_ERR "%s: can't set dma mask\n", d->name); - return -EBUSY; + goto out; } - + /* FIXME: Temporary - until we put in the hotplug interface logic - Check that the bits we want are not in use by someone else */ - if (pci_request_region(dev, 4, "ide_tmp")) - return -EBUSY; + Check that the bits we want are not in use by someone else. */ + ret = pci_request_region(dev, 4, "ide_tmp"); + if (ret < 0) + goto out; + pci_release_region(dev, 4); - - return 0; +out: + return ret; } /** @@ -440,7 +431,12 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, ide_pci_device_t *d, if (hwif->io_ports[IDE_DATA_OFFSET] != base || hwif->io_ports[IDE_CONTROL_OFFSET] != (ctl | 2)) { memset(&hwif->hw, 0, sizeof(hwif->hw)); +#ifndef IDE_ARCH_OBSOLETE_INIT + ide_std_init_ports(&hwif->hw, base, (ctl | 2)); + hwif->hw.io_ports[IDE_IRQ_OFFSET] = 0; +#else ide_init_hwif_ports(&hwif->hw, base, (ctl | 2), NULL); +#endif memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports)); hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET]; } @@ -488,13 +484,8 @@ static void ide_hwif_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwi * Set up BM-DMA capability * (PnP BIOS should have done this) */ - if ((d->flags & IDEPCI_FLAG_FORCE_MASTER) == 0) { - /* - * default DMA off if we had to - * configure it here - */ - hwif->autodma = 0; - } + /* default DMA off if we had to configure it here */ + hwif->autodma = 0; pci_set_master(dev); if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) { printk(KERN_ERR "%s: %s error updating PCICMD\n", @@ -514,6 +505,11 @@ static void ide_hwif_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwi } } } + +#ifndef CONFIG_IDEDMA_PCI_AUTO +#warning CONFIG_IDEDMA_PCI_AUTO=n support is obsolete, and will be removed soon. +#endif + #endif /* CONFIG_BLK_DEV_IDEDMA_PCI*/ /** @@ -530,28 +526,26 @@ static void ide_hwif_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwi static int ide_setup_pci_controller(struct pci_dev *dev, ide_pci_device_t *d, int noisy, int *config) { - int ret = 0; + int ret; u32 class_rev; u16 pcicmd; - if (!noautodma) - ret = 1; - if (noisy) ide_setup_pci_noise(dev, d); - if (ide_pci_enable(dev, d)) - return -EBUSY; - - if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) { + ret = ide_pci_enable(dev, d); + if (ret < 0) + goto out; + + ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd); + if (ret < 0) { printk(KERN_ERR "%s: error accessing PCI regs\n", d->name); - return -EIO; + goto out; } if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */ - if (ide_pci_configure(dev, d)) - return -ENODEV; - /* default DMA off if we had to configure it here */ - ret = 0; + ret = ide_pci_configure(dev, d); + if (ret < 0) + goto out; *config = 1; printk(KERN_INFO "%s: device enabled (Linux)\n", d->name); } @@ -560,6 +554,7 @@ static int ide_setup_pci_controller(struct pci_dev *dev, ide_pci_device_t *d, in class_rev &= 0xff; if (noisy) printk(KERN_INFO "%s: chipset revision %d\n", d->name, class_rev); +out: return ret; } @@ -567,7 +562,6 @@ static int ide_setup_pci_controller(struct pci_dev *dev, ide_pci_device_t *d, in * ide_pci_setup_ports - configure ports/devices on PCI IDE * @dev: PCI device * @d: IDE pci device info - * @autodma: Should we enable DMA * @pciirq: IRQ line * @index: ata index to update * @@ -580,12 +574,11 @@ static int ide_setup_pci_controller(struct pci_dev *dev, ide_pci_device_t *d, in * where the chipset setup is not the default PCI IDE one. */ -void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int autodma, int pciirq, ata_index_t *index) +void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, ata_index_t *index) { int port; int at_least_one_hwif_enabled = 0; ide_hwif_t *hwif, *mate = NULL; - static int secondpdc = 0; u8 tmp; index->all = 0xf0f0; @@ -597,21 +590,9 @@ void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int autodma, for (port = 0; port <= 1; ++port) { ide_pci_enablebit_t *e = &(d->enablebits[port]); - /* - * If this is a Promise FakeRaid controller, - * the 2nd controller will be marked as - * disabled while it is actually there and enabled - * by the bios for raid purposes. - * Skip the normal "is it enabled" test for those. - */ - if ((d->flags & IDEPCI_FLAG_FORCE_PDC) && - (secondpdc++==1) && (port==1)) - goto controller_ok; - if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || (tmp & e->mask) != e->val)) continue; /* port not enabled */ -controller_ok: if (d->channels <= port) break; @@ -634,11 +615,7 @@ controller_ok: if (d->autodma == NODMA) goto bypass_legacy_dma; - if (d->autodma == NOAUTODMA) - autodma = 0; - if (autodma) - hwif->autodma = 1; - + if(d->init_setup_dma) d->init_setup_dma(dev, d, hwif); else @@ -669,15 +646,16 @@ EXPORT_SYMBOL_GPL(ide_pci_setup_ports); * we "know" about, this information is in the ide_pci_device_t struct; * for all other chipsets, we just assume both interfaces are enabled. */ -static ata_index_t do_ide_setup_pci_device (struct pci_dev *dev, ide_pci_device_t *d, u8 noisy) +static int do_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t *d, + ata_index_t *index, u8 noisy) { - int autodma = 0; - int pciirq = 0; + static ata_index_t ata_index = { .b = { .low = 0xff, .high = 0xff } }; int tried_config = 0; - ata_index_t index = { .b = { .low = 0xff, .high = 0xff } }; + int pciirq, ret; - if((autodma = ide_setup_pci_controller(dev, d, noisy, &tried_config)) < 0) - return index; + ret = ide_setup_pci_controller(dev, d, noisy, &tried_config); + if (ret < 0) + goto out; /* * Can we trust the reported IRQ? @@ -695,7 +673,10 @@ static ata_index_t do_ide_setup_pci_device (struct pci_dev *dev, ide_pci_device_ * space, place chipset into init-mode, and/or preserve * an interrupt if the card is not native ide support. */ - pciirq = (d->init_chipset) ? d->init_chipset(dev, d->name) : 0; + ret = d->init_chipset ? d->init_chipset(dev, d->name) : 0; + if (ret < 0) + goto out; + pciirq = ret; } else if (tried_config) { if (noisy) printk(KERN_INFO "%s: will probe irqs later\n", d->name); @@ -706,58 +687,75 @@ static ata_index_t do_ide_setup_pci_device (struct pci_dev *dev, ide_pci_device_ d->name, pciirq); pciirq = 0; } else { - if (d->init_chipset) - { - if(d->init_chipset(dev, d->name) < 0) - return index; + if (d->init_chipset) { + ret = d->init_chipset(dev, d->name); + if (ret < 0) + goto out; } if (noisy) -#ifdef __sparc__ - printk(KERN_INFO "%s: 100%% native mode on irq %s\n", - d->name, __irq_itoa(pciirq)); -#else printk(KERN_INFO "%s: 100%% native mode on irq %d\n", d->name, pciirq); -#endif } - - if(pciirq < 0) /* Error not an IRQ */ - return index; - ide_pci_setup_ports(dev, d, autodma, pciirq, &index); + /* FIXME: silent failure can happen */ - return index; + *index = ata_index; + ide_pci_setup_ports(dev, d, pciirq, index); +out: + return ret; } -void ide_setup_pci_device (struct pci_dev *dev, ide_pci_device_t *d) +int ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t *d) { - ata_index_t index_list = do_ide_setup_pci_device(dev, d, 1); + ata_index_t index_list; + int ret; + + ret = do_ide_setup_pci_device(dev, d, &index_list, 1); + if (ret < 0) + goto out; if ((index_list.b.low & 0xf0) != 0xf0) - probe_hwif_init(&ide_hwifs[index_list.b.low]); + probe_hwif_init_with_fixup(&ide_hwifs[index_list.b.low], d->fixup); if ((index_list.b.high & 0xf0) != 0xf0) - probe_hwif_init(&ide_hwifs[index_list.b.high]); + probe_hwif_init_with_fixup(&ide_hwifs[index_list.b.high], d->fixup); create_proc_ide_interfaces(); +out: + return ret; } EXPORT_SYMBOL_GPL(ide_setup_pci_device); -void ide_setup_pci_devices (struct pci_dev *dev, struct pci_dev *dev2, ide_pci_device_t *d) +int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2, + ide_pci_device_t *d) { - ata_index_t index_list = do_ide_setup_pci_device(dev, d, 1); - ata_index_t index_list2 = do_ide_setup_pci_device(dev2, d, 0); + struct pci_dev *pdev[] = { dev1, dev2 }; + ata_index_t index_list[2]; + int ret, i; - if ((index_list.b.low & 0xf0) != 0xf0) - probe_hwif_init(&ide_hwifs[index_list.b.low]); - if ((index_list.b.high & 0xf0) != 0xf0) - probe_hwif_init(&ide_hwifs[index_list.b.high]); - if ((index_list2.b.low & 0xf0) != 0xf0) - probe_hwif_init(&ide_hwifs[index_list2.b.low]); - if ((index_list2.b.high & 0xf0) != 0xf0) - probe_hwif_init(&ide_hwifs[index_list2.b.high]); + for (i = 0; i < 2; i++) { + ret = do_ide_setup_pci_device(pdev[i], d, index_list + i, !i); + /* + * FIXME: Mom, mom, they stole me the helper function to undo + * do_ide_setup_pci_device() on the first device! + */ + if (ret < 0) + goto out; + } + + for (i = 0; i < 2; i++) { + u8 idx[2] = { index_list[i].b.low, index_list[i].b.high }; + int j; + + for (j = 0; j < 2; j++) { + if ((idx[j] & 0xf0) != 0xf0) + probe_hwif_init(ide_hwifs + idx[j]); + } + } create_proc_ide_interfaces(); +out: + return ret; } EXPORT_SYMBOL_GPL(ide_setup_pci_devices); @@ -770,8 +768,9 @@ static int pre_init = 1; /* Before first ordered IDE scan */ static LIST_HEAD(ide_pci_drivers); /* - * ide_register_pci_driver - attach IDE driver + * __ide_pci_register_driver - attach IDE driver * @driver: pci driver + * @module: owner module of the driver * * Registers a driver with the IDE layer. The IDE layer arranges that * boot time setup is done in the expected device order and then @@ -784,33 +783,16 @@ static LIST_HEAD(ide_pci_drivers); * Returns are the same as for pci_register_driver */ -int ide_pci_register_driver(struct pci_driver *driver) +int __ide_pci_register_driver(struct pci_driver *driver, struct module *module) { if(!pre_init) - return pci_module_init(driver); + return __pci_register_driver(driver, module); + driver->driver.owner = module; list_add_tail(&driver->node, &ide_pci_drivers); return 0; } -EXPORT_SYMBOL_GPL(ide_pci_register_driver); - -/** - * ide_unregister_pci_driver - unregister an IDE driver - * @driver: driver to remove - * - * Unregister a currently installed IDE driver. Returns are the same - * as for pci_unregister_driver - */ - -void ide_pci_unregister_driver(struct pci_driver *driver) -{ - if(!pre_init) - pci_unregister_driver(driver); - else - list_del(&driver->node); -} - -EXPORT_SYMBOL_GPL(ide_pci_unregister_driver); +EXPORT_SYMBOL_GPL(__ide_pci_register_driver); /** * ide_scan_pcidev - find an IDE driver for a device @@ -831,7 +813,7 @@ static int __init ide_scan_pcidev(struct pci_dev *dev) d = list_entry(l, struct pci_driver, node); if(d->id_table) { - const struct pci_device_id *id = pci_match_device(d->id_table, dev); + const struct pci_device_id *id = pci_match_id(d->id_table, dev); if(id != NULL) { if(d->probe(dev, id) >= 0) @@ -862,11 +844,11 @@ void __init ide_scan_pcibus (int scan_direction) pre_init = 0; if (!scan_direction) { - while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { + while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { ide_scan_pcidev(dev); } } else { - while ((dev = pci_find_device_reverse(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { + while ((dev = pci_get_device_reverse(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { ide_scan_pcidev(dev); } } @@ -880,6 +862,6 @@ void __init ide_scan_pcibus (int scan_direction) { list_del(l); d = list_entry(l, struct pci_driver, node); - pci_register_driver(d); + __pci_register_driver(d, d->driver.owner); } }