Merge commit 'upstream/master'
[pandora-kernel.git] / drivers / ide / setup-pci.c
index b15cad5..a8e9e8a 100644 (file)
@@ -39,17 +39,18 @@ static int ide_setup_pci_baseregs(struct pci_dev *dev, const char *name)
        if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
                         (progif & 5) != 5) {
                if ((progif & 0xa) != 0xa) {
-                       printk(KERN_INFO "%s: device not capable of full "
-                               "native PCI mode\n", name);
+                       printk(KERN_INFO "%s %s: device not capable of full "
+                               "native PCI mode\n", name, pci_name(dev));
                        return -EOPNOTSUPP;
                }
-               printk("%s: placing both ports into native PCI mode\n", name);
+               printk(KERN_INFO "%s %s: placing both ports into native PCI "
+                       "mode\n", name, pci_name(dev));
                (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
                if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
                    (progif & 5) != 5) {
-                       printk(KERN_ERR "%s: rewrite of PROGIF failed, wanted "
-                               "0x%04x, got 0x%04x\n",
-                               name, progif|5, progif);
+                       printk(KERN_ERR "%s %s: rewrite of PROGIF failed, "
+                               "wanted 0x%04x, got 0x%04x\n",
+                               name, pci_name(dev), progif | 5, progif);
                        return -EOPNOTSUPP;
                }
        }
@@ -57,14 +58,14 @@ static int ide_setup_pci_baseregs(struct pci_dev *dev, const char *name)
 }
 
 #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
-static void ide_pci_clear_simplex(unsigned long dma_base, const char *name)
+static int ide_pci_clear_simplex(unsigned long dma_base, const char *name)
 {
        u8 dma_stat = inb(dma_base + 2);
 
        outb(dma_stat & 0x60, dma_base + 2);
        dma_stat = inb(dma_base + 2);
-       if (dma_stat & 0x80)
-               printk(KERN_INFO "%s: simplex device: DMA forced\n", name);
+
+       return (dma_stat & 0x80) ? 1 : 0;
 }
 
 /**
@@ -91,7 +92,8 @@ unsigned long ide_pci_dma_base(ide_hwif_t *hwif, const struct ide_port_info *d)
                dma_base = pci_resource_start(dev, baridx);
 
                if (dma_base == 0) {
-                       printk(KERN_ERR "%s: DMA base is invalid\n", d->name);
+                       printk(KERN_ERR "%s %s: DMA base is invalid\n",
+                               d->name, pci_name(dev));
                        return 0;
                }
        }
@@ -105,13 +107,16 @@ EXPORT_SYMBOL_GPL(ide_pci_dma_base);
 
 int ide_pci_check_simplex(ide_hwif_t *hwif, const struct ide_port_info *d)
 {
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
        u8 dma_stat;
 
        if (d->host_flags & (IDE_HFLAG_MMIO | IDE_HFLAG_CS5520))
                goto out;
 
        if (d->host_flags & IDE_HFLAG_CLEAR_SIMPLEX) {
-               ide_pci_clear_simplex(hwif->dma_base, d->name);
+               if (ide_pci_clear_simplex(hwif->dma_base, d->name))
+                       printk(KERN_INFO "%s %s: simplex device: DMA forced\n",
+                               d->name, pci_name(dev));
                goto out;
        }
 
@@ -127,7 +132,8 @@ int ide_pci_check_simplex(ide_hwif_t *hwif, const struct ide_port_info *d)
         */
        dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
        if ((dma_stat & 0x80) && hwif->mate && hwif->mate->dma_base) {
-               printk(KERN_INFO "%s: simplex device: DMA disabled\n", d->name);
+               printk(KERN_INFO "%s %s: simplex device: DMA disabled\n",
+                       d->name, pci_name(dev));
                return -1;
        }
 out:
@@ -149,8 +155,8 @@ int ide_pci_set_master(struct pci_dev *dev, const char *name)
 
                if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) ||
                    (pcicmd & PCI_COMMAND_MASTER) == 0) {
-                       printk(KERN_ERR "%s: error updating PCICMD on %s\n",
-                                       name, pci_name(dev));
+                       printk(KERN_ERR "%s %s: error updating PCICMD\n",
+                               name, pci_name(dev));
                        return -EIO;
                }
        }
@@ -162,9 +168,9 @@ EXPORT_SYMBOL_GPL(ide_pci_set_master);
 
 void ide_setup_pci_noise(struct pci_dev *dev, const struct ide_port_info *d)
 {
-       printk(KERN_INFO "%s: IDE controller (0x%04x:0x%04x rev 0x%02x) at "
-                        " PCI slot %s\n", d->name, dev->vendor, dev->device,
-                        dev->revision, pci_name(dev));
+       printk(KERN_INFO "%s %s: IDE controller (0x%04x:0x%04x rev 0x%02x)\n",
+               d->name, pci_name(dev),
+               dev->vendor, dev->device, dev->revision);
 }
 EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
 
@@ -189,11 +195,12 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
        if (pci_enable_device(dev)) {
                ret = pci_enable_device_io(dev);
                if (ret < 0) {
-                       printk(KERN_WARNING "%s: (ide_setup_pci_device:) "
-                               "Could not enable device.\n", d->name);
+                       printk(KERN_WARNING "%s %s: couldn't enable device\n",
+                               d->name, pci_name(dev));
                        goto out;
                }
-               printk(KERN_WARNING "%s: BIOS configuration fixed.\n", d->name);
+               printk(KERN_WARNING "%s %s: BIOS configuration fixed\n",
+                       d->name, pci_name(dev));
        }
 
        /*
@@ -203,7 +210,8 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
         */
        ret = pci_set_dma_mask(dev, DMA_32BIT_MASK);
        if (ret < 0) {
-               printk(KERN_ERR "%s: can't set dma mask\n", d->name);
+               printk(KERN_ERR "%s %s: can't set DMA mask\n",
+                       d->name, pci_name(dev));
                goto out;
        }
 
@@ -221,7 +229,8 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
 
        ret = pci_request_selected_regions(dev, bars, d->name);
        if (ret < 0)
-               printk(KERN_ERR "%s: can't reserve resources\n", d->name);
+               printk(KERN_ERR "%s %s: can't reserve resources\n",
+                       d->name, pci_name(dev));
 out:
        return ret;
 }
@@ -247,15 +256,18 @@ static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d)
         */
        if (ide_setup_pci_baseregs(dev, d->name) ||
            pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_IO)) {
-               printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name);
+               printk(KERN_INFO "%s %s: device disabled (BIOS)\n",
+                       d->name, pci_name(dev));
                return -ENODEV;
        }
        if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) {
-               printk(KERN_ERR "%s: error accessing PCI regs\n", d->name);
+               printk(KERN_ERR "%s %s: error accessing PCI regs\n",
+                       d->name, pci_name(dev));
                return -EIO;
        }
        if (!(pcicmd & PCI_COMMAND_IO)) {
-               printk(KERN_ERR "%s: unable to enable IDE controller\n", d->name);
+               printk(KERN_ERR "%s %s: unable to enable IDE controller\n",
+                       d->name, pci_name(dev));
                return -ENXIO;
        }
        return 0;
@@ -311,8 +323,9 @@ static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d,
        if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) {
                if (ide_pci_check_iomem(dev, d, 2 * port) ||
                    ide_pci_check_iomem(dev, d, 2 * port + 1)) {
-                       printk(KERN_ERR "%s: I/O baseregs (BIOS) are reported "
-                                       "as MEM for port %d!\n", d->name, port);
+                       printk(KERN_ERR "%s %s: I/O baseregs (BIOS) are "
+                               "reported as MEM for port %d!\n",
+                               d->name, pci_name(dev), port);
                        return -EINVAL;
                }
 
@@ -325,8 +338,8 @@ static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d,
        }
 
        if (!base || !ctl) {
-               printk(KERN_ERR "%s: bad PCI BARs for port %d, skipping\n",
-                               d->name, port);
+               printk(KERN_ERR "%s %s: bad PCI BARs for port %d, skipping\n",
+                       d->name, pci_name(dev), port);
                return -EINVAL;
        }
 
@@ -393,14 +406,14 @@ int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
  *     @dev: PCI device
  *     @d: IDE port info
  *     @noisy: verbose flag
- *     @config: returned as 1 if we configured the hardware
  *
  *     Set up the PCI and controller side of the IDE interface. This brings
  *     up the PCI side of the device, checks that the device is enabled
  *     and enables it if need be
  */
 
-static int ide_setup_pci_controller(struct pci_dev *dev, const struct ide_port_info *d, int noisy, int *config)
+static int ide_setup_pci_controller(struct pci_dev *dev,
+                                   const struct ide_port_info *d, int noisy)
 {
        int ret;
        u16 pcicmd;
@@ -414,15 +427,16 @@ static int ide_setup_pci_controller(struct pci_dev *dev, const struct ide_port_i
 
        ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
        if (ret < 0) {
-               printk(KERN_ERR "%s: error accessing PCI regs\n", d->name);
+               printk(KERN_ERR "%s %s: error accessing PCI regs\n",
+                       d->name, pci_name(dev));
                goto out;
        }
        if (!(pcicmd & PCI_COMMAND_IO)) {       /* is device disabled? */
                ret = ide_pci_configure(dev, d);
                if (ret < 0)
                        goto out;
-               *config = 1;
-               printk(KERN_INFO "%s: device enabled (Linux)\n", d->name);
+               printk(KERN_INFO "%s %s: device enabled (Linux)\n",
+                       d->name, pci_name(dev));
        }
 
 out:
@@ -461,7 +475,8 @@ void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d,
 
                if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
                    (tmp & e->mask) != e->val)) {
-                       printk(KERN_INFO "%s: IDE port disabled\n", d->name);
+                       printk(KERN_INFO "%s %s: IDE port disabled\n",
+                               d->name, pci_name(dev));
                        continue;       /* port not enabled */
                }
 
@@ -487,51 +502,35 @@ static int do_ide_setup_pci_device(struct pci_dev *dev,
                                   const struct ide_port_info *d,
                                   u8 noisy)
 {
-       int tried_config = 0;
        int pciirq, ret;
 
-       ret = ide_setup_pci_controller(dev, d, noisy, &tried_config);
-       if (ret < 0)
-               goto out;
-
        /*
         * Can we trust the reported IRQ?
         */
        pciirq = dev->irq;
 
+       /*
+        * This allows offboard ide-pci cards the enable a BIOS,
+        * verify interrupt settings of split-mirror pci-config
+        * space, place chipset into init-mode, and/or preserve
+        * an interrupt if the card is not native ide support.
+        */
+       ret = d->init_chipset ? d->init_chipset(dev) : 0;
+       if (ret < 0)
+               goto out;
+
        /* Is it an "IDE storage" device in non-PCI mode? */
        if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) {
                if (noisy)
-                       printk(KERN_INFO "%s: not 100%% native mode: "
-                               "will probe irqs later\n", d->name);
-               /*
-                * This allows offboard ide-pci cards the enable a BIOS,
-                * verify interrupt settings of split-mirror pci-config
-                * space, place chipset into init-mode, and/or preserve
-                * an interrupt if the card is not native ide support.
-                */
-               ret = d->init_chipset ? d->init_chipset(dev, d->name) : 0;
-               if (ret < 0)
-                       goto out;
+                       printk(KERN_INFO "%s %s: not 100%% native mode: will "
+                               "probe irqs later\n", d->name, pci_name(dev));
                pciirq = ret;
-       } else if (tried_config) {
-               if (noisy)
-                       printk(KERN_INFO "%s: will probe irqs later\n", d->name);
-               pciirq = 0;
-       } else if (!pciirq) {
-               if (noisy)
-                       printk(KERN_WARNING "%s: bad irq (%d): will probe later\n",
-                               d->name, pciirq);
-               pciirq = 0;
-       } else {
-               if (d->init_chipset) {
-                       ret = d->init_chipset(dev, d->name);
-                       if (ret < 0)
-                               goto out;
-               }
-               if (noisy)
-                       printk(KERN_INFO "%s: 100%% native mode on irq %d\n",
-                               d->name, pciirq);
+       } else if (!pciirq && noisy) {
+               printk(KERN_WARNING "%s %s: bad irq (%d): will probe later\n",
+                       d->name, pci_name(dev), pciirq);
+       } else if (noisy) {
+               printk(KERN_INFO "%s %s: 100%% native mode on irq %d\n",
+                       d->name, pci_name(dev), pciirq);
        }
 
        ret = pciirq;
@@ -539,31 +538,76 @@ out:
        return ret;
 }
 
-int ide_setup_pci_device(struct pci_dev *dev, const struct ide_port_info *d)
+int ide_pci_init_one(struct pci_dev *dev, const struct ide_port_info *d,
+                    void *priv)
 {
+       struct ide_host *host;
        hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
        int ret;
 
-       ret = do_ide_setup_pci_device(dev, d, 1);
+       ret = ide_setup_pci_controller(dev, d, 1);
+       if (ret < 0)
+               goto out;
 
-       if (ret >= 0) {
-               /* FIXME: silent failure can happen */
-               ide_pci_setup_ports(dev, d, ret, &hw[0], &hws[0]);
+       ide_pci_setup_ports(dev, d, 0, &hw[0], &hws[0]);
 
-               ret = ide_host_add(d, hws, NULL);
+       host = ide_host_alloc(d, hws);
+       if (host == NULL) {
+               ret = -ENOMEM;
+               goto out;
        }
 
+       host->dev[0] = &dev->dev;
+
+       host->host_priv = priv;
+
+       pci_set_drvdata(dev, host);
+
+       ret = do_ide_setup_pci_device(dev, d, 1);
+       if (ret < 0)
+               goto out;
+
+       /* fixup IRQ */
+       hw[1].irq = hw[0].irq = ret;
+
+       ret = ide_host_register(host, d, hws);
+       if (ret)
+               ide_host_free(host);
+out:
        return ret;
 }
-EXPORT_SYMBOL_GPL(ide_setup_pci_device);
+EXPORT_SYMBOL_GPL(ide_pci_init_one);
 
-int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
-                         const struct ide_port_info *d)
+int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
+                    const struct ide_port_info *d, void *priv)
 {
        struct pci_dev *pdev[] = { dev1, dev2 };
+       struct ide_host *host;
        int ret, i;
        hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
 
+       for (i = 0; i < 2; i++) {
+               ret = ide_setup_pci_controller(pdev[i], d, !i);
+               if (ret < 0)
+                       goto out;
+
+               ide_pci_setup_ports(pdev[i], d, 0, &hw[i*2], &hws[i*2]);
+       }
+
+       host = ide_host_alloc(d, hws);
+       if (host == NULL) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       host->dev[0] = &dev1->dev;
+       host->dev[1] = &dev2->dev;
+
+       host->host_priv = priv;
+
+       pci_set_drvdata(pdev[0], host);
+       pci_set_drvdata(pdev[1], host);
+
        for (i = 0; i < 2; i++) {
                ret = do_ide_setup_pci_device(pdev[i], d, !i);
 
@@ -574,12 +618,44 @@ int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
                if (ret < 0)
                        goto out;
 
-               /* FIXME: silent failure can happen */
-               ide_pci_setup_ports(pdev[i], d, ret, &hw[i*2], &hws[i*2]);
+               /* fixup IRQ */
+               hw[i*2 + 1].irq = hw[i*2].irq = ret;
        }
 
-       ret = ide_host_add(d, hws, NULL);
+       ret = ide_host_register(host, d, hws);
+       if (ret)
+               ide_host_free(host);
 out:
        return ret;
 }
-EXPORT_SYMBOL_GPL(ide_setup_pci_devices);
+EXPORT_SYMBOL_GPL(ide_pci_init_two);
+
+void ide_pci_remove(struct pci_dev *dev)
+{
+       struct ide_host *host = pci_get_drvdata(dev);
+       struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
+       int bars;
+
+       if (host->host_flags & IDE_HFLAG_SINGLE)
+               bars = (1 << 2) - 1;
+       else
+               bars = (1 << 4) - 1;
+
+       if ((host->host_flags & IDE_HFLAG_NO_DMA) == 0) {
+               if (host->host_flags & IDE_HFLAG_CS5520)
+                       bars |= (1 << 2);
+               else
+                       bars |= (1 << 4);
+       }
+
+       ide_host_remove(host);
+
+       if (dev2)
+               pci_release_selected_regions(dev2, bars);
+       pci_release_selected_regions(dev, bars);
+
+       if (dev2)
+               pci_disable_device(dev2);
+       pci_disable_device(dev);
+}
+EXPORT_SYMBOL_GPL(ide_pci_remove);