aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/setup-pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide/setup-pci.c')
-rw-r--r--drivers/ide/setup-pci.c240
1 files changed, 158 insertions, 82 deletions
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index b15cad58dc81..a8e9e8a69a52 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -39,17 +39,18 @@ static int ide_setup_pci_baseregs(struct pci_dev *dev, const char *name)
39 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) || 39 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
40 (progif & 5) != 5) { 40 (progif & 5) != 5) {
41 if ((progif & 0xa) != 0xa) { 41 if ((progif & 0xa) != 0xa) {
42 printk(KERN_INFO "%s: device not capable of full " 42 printk(KERN_INFO "%s %s: device not capable of full "
43 "native PCI mode\n", name); 43 "native PCI mode\n", name, pci_name(dev));
44 return -EOPNOTSUPP; 44 return -EOPNOTSUPP;
45 } 45 }
46 printk("%s: placing both ports into native PCI mode\n", name); 46 printk(KERN_INFO "%s %s: placing both ports into native PCI "
47 "mode\n", name, pci_name(dev));
47 (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5); 48 (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
48 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) || 49 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
49 (progif & 5) != 5) { 50 (progif & 5) != 5) {
50 printk(KERN_ERR "%s: rewrite of PROGIF failed, wanted " 51 printk(KERN_ERR "%s %s: rewrite of PROGIF failed, "
51 "0x%04x, got 0x%04x\n", 52 "wanted 0x%04x, got 0x%04x\n",
52 name, progif|5, progif); 53 name, pci_name(dev), progif | 5, progif);
53 return -EOPNOTSUPP; 54 return -EOPNOTSUPP;
54 } 55 }
55 } 56 }
@@ -57,14 +58,14 @@ static int ide_setup_pci_baseregs(struct pci_dev *dev, const char *name)
57} 58}
58 59
59#ifdef CONFIG_BLK_DEV_IDEDMA_PCI 60#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
60static void ide_pci_clear_simplex(unsigned long dma_base, const char *name) 61static int ide_pci_clear_simplex(unsigned long dma_base, const char *name)
61{ 62{
62 u8 dma_stat = inb(dma_base + 2); 63 u8 dma_stat = inb(dma_base + 2);
63 64
64 outb(dma_stat & 0x60, dma_base + 2); 65 outb(dma_stat & 0x60, dma_base + 2);
65 dma_stat = inb(dma_base + 2); 66 dma_stat = inb(dma_base + 2);
66 if (dma_stat & 0x80) 67
67 printk(KERN_INFO "%s: simplex device: DMA forced\n", name); 68 return (dma_stat & 0x80) ? 1 : 0;
68} 69}
69 70
70/** 71/**
@@ -91,7 +92,8 @@ unsigned long ide_pci_dma_base(ide_hwif_t *hwif, const struct ide_port_info *d)
91 dma_base = pci_resource_start(dev, baridx); 92 dma_base = pci_resource_start(dev, baridx);
92 93
93 if (dma_base == 0) { 94 if (dma_base == 0) {
94 printk(KERN_ERR "%s: DMA base is invalid\n", d->name); 95 printk(KERN_ERR "%s %s: DMA base is invalid\n",
96 d->name, pci_name(dev));
95 return 0; 97 return 0;
96 } 98 }
97 } 99 }
@@ -105,13 +107,16 @@ EXPORT_SYMBOL_GPL(ide_pci_dma_base);
105 107
106int ide_pci_check_simplex(ide_hwif_t *hwif, const struct ide_port_info *d) 108int ide_pci_check_simplex(ide_hwif_t *hwif, const struct ide_port_info *d)
107{ 109{
110 struct pci_dev *dev = to_pci_dev(hwif->dev);
108 u8 dma_stat; 111 u8 dma_stat;
109 112
110 if (d->host_flags & (IDE_HFLAG_MMIO | IDE_HFLAG_CS5520)) 113 if (d->host_flags & (IDE_HFLAG_MMIO | IDE_HFLAG_CS5520))
111 goto out; 114 goto out;
112 115
113 if (d->host_flags & IDE_HFLAG_CLEAR_SIMPLEX) { 116 if (d->host_flags & IDE_HFLAG_CLEAR_SIMPLEX) {
114 ide_pci_clear_simplex(hwif->dma_base, d->name); 117 if (ide_pci_clear_simplex(hwif->dma_base, d->name))
118 printk(KERN_INFO "%s %s: simplex device: DMA forced\n",
119 d->name, pci_name(dev));
115 goto out; 120 goto out;
116 } 121 }
117 122
@@ -127,7 +132,8 @@ int ide_pci_check_simplex(ide_hwif_t *hwif, const struct ide_port_info *d)
127 */ 132 */
128 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); 133 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
129 if ((dma_stat & 0x80) && hwif->mate && hwif->mate->dma_base) { 134 if ((dma_stat & 0x80) && hwif->mate && hwif->mate->dma_base) {
130 printk(KERN_INFO "%s: simplex device: DMA disabled\n", d->name); 135 printk(KERN_INFO "%s %s: simplex device: DMA disabled\n",
136 d->name, pci_name(dev));
131 return -1; 137 return -1;
132 } 138 }
133out: 139out:
@@ -149,8 +155,8 @@ int ide_pci_set_master(struct pci_dev *dev, const char *name)
149 155
150 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || 156 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) ||
151 (pcicmd & PCI_COMMAND_MASTER) == 0) { 157 (pcicmd & PCI_COMMAND_MASTER) == 0) {
152 printk(KERN_ERR "%s: error updating PCICMD on %s\n", 158 printk(KERN_ERR "%s %s: error updating PCICMD\n",
153 name, pci_name(dev)); 159 name, pci_name(dev));
154 return -EIO; 160 return -EIO;
155 } 161 }
156 } 162 }
@@ -162,9 +168,9 @@ EXPORT_SYMBOL_GPL(ide_pci_set_master);
162 168
163void ide_setup_pci_noise(struct pci_dev *dev, const struct ide_port_info *d) 169void ide_setup_pci_noise(struct pci_dev *dev, const struct ide_port_info *d)
164{ 170{
165 printk(KERN_INFO "%s: IDE controller (0x%04x:0x%04x rev 0x%02x) at " 171 printk(KERN_INFO "%s %s: IDE controller (0x%04x:0x%04x rev 0x%02x)\n",
166 " PCI slot %s\n", d->name, dev->vendor, dev->device, 172 d->name, pci_name(dev),
167 dev->revision, pci_name(dev)); 173 dev->vendor, dev->device, dev->revision);
168} 174}
169EXPORT_SYMBOL_GPL(ide_setup_pci_noise); 175EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
170 176
@@ -189,11 +195,12 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
189 if (pci_enable_device(dev)) { 195 if (pci_enable_device(dev)) {
190 ret = pci_enable_device_io(dev); 196 ret = pci_enable_device_io(dev);
191 if (ret < 0) { 197 if (ret < 0) {
192 printk(KERN_WARNING "%s: (ide_setup_pci_device:) " 198 printk(KERN_WARNING "%s %s: couldn't enable device\n",
193 "Could not enable device.\n", d->name); 199 d->name, pci_name(dev));
194 goto out; 200 goto out;
195 } 201 }
196 printk(KERN_WARNING "%s: BIOS configuration fixed.\n", d->name); 202 printk(KERN_WARNING "%s %s: BIOS configuration fixed\n",
203 d->name, pci_name(dev));
197 } 204 }
198 205
199 /* 206 /*
@@ -203,7 +210,8 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
203 */ 210 */
204 ret = pci_set_dma_mask(dev, DMA_32BIT_MASK); 211 ret = pci_set_dma_mask(dev, DMA_32BIT_MASK);
205 if (ret < 0) { 212 if (ret < 0) {
206 printk(KERN_ERR "%s: can't set dma mask\n", d->name); 213 printk(KERN_ERR "%s %s: can't set DMA mask\n",
214 d->name, pci_name(dev));
207 goto out; 215 goto out;
208 } 216 }
209 217
@@ -221,7 +229,8 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
221 229
222 ret = pci_request_selected_regions(dev, bars, d->name); 230 ret = pci_request_selected_regions(dev, bars, d->name);
223 if (ret < 0) 231 if (ret < 0)
224 printk(KERN_ERR "%s: can't reserve resources\n", d->name); 232 printk(KERN_ERR "%s %s: can't reserve resources\n",
233 d->name, pci_name(dev));
225out: 234out:
226 return ret; 235 return ret;
227} 236}
@@ -247,15 +256,18 @@ static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d)
247 */ 256 */
248 if (ide_setup_pci_baseregs(dev, d->name) || 257 if (ide_setup_pci_baseregs(dev, d->name) ||
249 pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_IO)) { 258 pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_IO)) {
250 printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name); 259 printk(KERN_INFO "%s %s: device disabled (BIOS)\n",
260 d->name, pci_name(dev));
251 return -ENODEV; 261 return -ENODEV;
252 } 262 }
253 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) { 263 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) {
254 printk(KERN_ERR "%s: error accessing PCI regs\n", d->name); 264 printk(KERN_ERR "%s %s: error accessing PCI regs\n",
265 d->name, pci_name(dev));
255 return -EIO; 266 return -EIO;
256 } 267 }
257 if (!(pcicmd & PCI_COMMAND_IO)) { 268 if (!(pcicmd & PCI_COMMAND_IO)) {
258 printk(KERN_ERR "%s: unable to enable IDE controller\n", d->name); 269 printk(KERN_ERR "%s %s: unable to enable IDE controller\n",
270 d->name, pci_name(dev));
259 return -ENXIO; 271 return -ENXIO;
260 } 272 }
261 return 0; 273 return 0;
@@ -311,8 +323,9 @@ static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d,
311 if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) { 323 if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) {
312 if (ide_pci_check_iomem(dev, d, 2 * port) || 324 if (ide_pci_check_iomem(dev, d, 2 * port) ||
313 ide_pci_check_iomem(dev, d, 2 * port + 1)) { 325 ide_pci_check_iomem(dev, d, 2 * port + 1)) {
314 printk(KERN_ERR "%s: I/O baseregs (BIOS) are reported " 326 printk(KERN_ERR "%s %s: I/O baseregs (BIOS) are "
315 "as MEM for port %d!\n", d->name, port); 327 "reported as MEM for port %d!\n",
328 d->name, pci_name(dev), port);
316 return -EINVAL; 329 return -EINVAL;
317 } 330 }
318 331
@@ -325,8 +338,8 @@ static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d,
325 } 338 }
326 339
327 if (!base || !ctl) { 340 if (!base || !ctl) {
328 printk(KERN_ERR "%s: bad PCI BARs for port %d, skipping\n", 341 printk(KERN_ERR "%s %s: bad PCI BARs for port %d, skipping\n",
329 d->name, port); 342 d->name, pci_name(dev), port);
330 return -EINVAL; 343 return -EINVAL;
331 } 344 }
332 345
@@ -393,14 +406,14 @@ int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
393 * @dev: PCI device 406 * @dev: PCI device
394 * @d: IDE port info 407 * @d: IDE port info
395 * @noisy: verbose flag 408 * @noisy: verbose flag
396 * @config: returned as 1 if we configured the hardware
397 * 409 *
398 * Set up the PCI and controller side of the IDE interface. This brings 410 * Set up the PCI and controller side of the IDE interface. This brings
399 * up the PCI side of the device, checks that the device is enabled 411 * up the PCI side of the device, checks that the device is enabled
400 * and enables it if need be 412 * and enables it if need be
401 */ 413 */
402 414
403static int ide_setup_pci_controller(struct pci_dev *dev, const struct ide_port_info *d, int noisy, int *config) 415static int ide_setup_pci_controller(struct pci_dev *dev,
416 const struct ide_port_info *d, int noisy)
404{ 417{
405 int ret; 418 int ret;
406 u16 pcicmd; 419 u16 pcicmd;
@@ -414,15 +427,16 @@ static int ide_setup_pci_controller(struct pci_dev *dev, const struct ide_port_i
414 427
415 ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd); 428 ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
416 if (ret < 0) { 429 if (ret < 0) {
417 printk(KERN_ERR "%s: error accessing PCI regs\n", d->name); 430 printk(KERN_ERR "%s %s: error accessing PCI regs\n",
431 d->name, pci_name(dev));
418 goto out; 432 goto out;
419 } 433 }
420 if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */ 434 if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */
421 ret = ide_pci_configure(dev, d); 435 ret = ide_pci_configure(dev, d);
422 if (ret < 0) 436 if (ret < 0)
423 goto out; 437 goto out;
424 *config = 1; 438 printk(KERN_INFO "%s %s: device enabled (Linux)\n",
425 printk(KERN_INFO "%s: device enabled (Linux)\n", d->name); 439 d->name, pci_name(dev));
426 } 440 }
427 441
428out: 442out:
@@ -461,7 +475,8 @@ void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d,
461 475
462 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || 476 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
463 (tmp & e->mask) != e->val)) { 477 (tmp & e->mask) != e->val)) {
464 printk(KERN_INFO "%s: IDE port disabled\n", d->name); 478 printk(KERN_INFO "%s %s: IDE port disabled\n",
479 d->name, pci_name(dev));
465 continue; /* port not enabled */ 480 continue; /* port not enabled */
466 } 481 }
467 482
@@ -487,51 +502,35 @@ static int do_ide_setup_pci_device(struct pci_dev *dev,
487 const struct ide_port_info *d, 502 const struct ide_port_info *d,
488 u8 noisy) 503 u8 noisy)
489{ 504{
490 int tried_config = 0;
491 int pciirq, ret; 505 int pciirq, ret;
492 506
493 ret = ide_setup_pci_controller(dev, d, noisy, &tried_config);
494 if (ret < 0)
495 goto out;
496
497 /* 507 /*
498 * Can we trust the reported IRQ? 508 * Can we trust the reported IRQ?
499 */ 509 */
500 pciirq = dev->irq; 510 pciirq = dev->irq;
501 511
512 /*
513 * This allows offboard ide-pci cards the enable a BIOS,
514 * verify interrupt settings of split-mirror pci-config
515 * space, place chipset into init-mode, and/or preserve
516 * an interrupt if the card is not native ide support.
517 */
518 ret = d->init_chipset ? d->init_chipset(dev) : 0;
519 if (ret < 0)
520 goto out;
521
502 /* Is it an "IDE storage" device in non-PCI mode? */ 522 /* Is it an "IDE storage" device in non-PCI mode? */
503 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) { 523 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) {
504 if (noisy) 524 if (noisy)
505 printk(KERN_INFO "%s: not 100%% native mode: " 525 printk(KERN_INFO "%s %s: not 100%% native mode: will "
506 "will probe irqs later\n", d->name); 526 "probe irqs later\n", d->name, pci_name(dev));
507 /*
508 * This allows offboard ide-pci cards the enable a BIOS,
509 * verify interrupt settings of split-mirror pci-config
510 * space, place chipset into init-mode, and/or preserve
511 * an interrupt if the card is not native ide support.
512 */
513 ret = d->init_chipset ? d->init_chipset(dev, d->name) : 0;
514 if (ret < 0)
515 goto out;
516 pciirq = ret; 527 pciirq = ret;
517 } else if (tried_config) { 528 } else if (!pciirq && noisy) {
518 if (noisy) 529 printk(KERN_WARNING "%s %s: bad irq (%d): will probe later\n",
519 printk(KERN_INFO "%s: will probe irqs later\n", d->name); 530 d->name, pci_name(dev), pciirq);
520 pciirq = 0; 531 } else if (noisy) {
521 } else if (!pciirq) { 532 printk(KERN_INFO "%s %s: 100%% native mode on irq %d\n",
522 if (noisy) 533 d->name, pci_name(dev), pciirq);
523 printk(KERN_WARNING "%s: bad irq (%d): will probe later\n",
524 d->name, pciirq);
525 pciirq = 0;
526 } else {
527 if (d->init_chipset) {
528 ret = d->init_chipset(dev, d->name);
529 if (ret < 0)
530 goto out;
531 }
532 if (noisy)
533 printk(KERN_INFO "%s: 100%% native mode on irq %d\n",
534 d->name, pciirq);
535 } 534 }
536 535
537 ret = pciirq; 536 ret = pciirq;
@@ -539,32 +538,77 @@ out:
539 return ret; 538 return ret;
540} 539}
541 540
542int ide_setup_pci_device(struct pci_dev *dev, const struct ide_port_info *d) 541int ide_pci_init_one(struct pci_dev *dev, const struct ide_port_info *d,
542 void *priv)
543{ 543{
544 struct ide_host *host;
544 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL }; 545 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
545 int ret; 546 int ret;
546 547
547 ret = do_ide_setup_pci_device(dev, d, 1); 548 ret = ide_setup_pci_controller(dev, d, 1);
549 if (ret < 0)
550 goto out;
548 551
549 if (ret >= 0) { 552 ide_pci_setup_ports(dev, d, 0, &hw[0], &hws[0]);
550 /* FIXME: silent failure can happen */
551 ide_pci_setup_ports(dev, d, ret, &hw[0], &hws[0]);
552 553
553 ret = ide_host_add(d, hws, NULL); 554 host = ide_host_alloc(d, hws);
555 if (host == NULL) {
556 ret = -ENOMEM;
557 goto out;
554 } 558 }
555 559
560 host->dev[0] = &dev->dev;
561
562 host->host_priv = priv;
563
564 pci_set_drvdata(dev, host);
565
566 ret = do_ide_setup_pci_device(dev, d, 1);
567 if (ret < 0)
568 goto out;
569
570 /* fixup IRQ */
571 hw[1].irq = hw[0].irq = ret;
572
573 ret = ide_host_register(host, d, hws);
574 if (ret)
575 ide_host_free(host);
576out:
556 return ret; 577 return ret;
557} 578}
558EXPORT_SYMBOL_GPL(ide_setup_pci_device); 579EXPORT_SYMBOL_GPL(ide_pci_init_one);
559 580
560int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2, 581int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
561 const struct ide_port_info *d) 582 const struct ide_port_info *d, void *priv)
562{ 583{
563 struct pci_dev *pdev[] = { dev1, dev2 }; 584 struct pci_dev *pdev[] = { dev1, dev2 };
585 struct ide_host *host;
564 int ret, i; 586 int ret, i;
565 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL }; 587 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
566 588
567 for (i = 0; i < 2; i++) { 589 for (i = 0; i < 2; i++) {
590 ret = ide_setup_pci_controller(pdev[i], d, !i);
591 if (ret < 0)
592 goto out;
593
594 ide_pci_setup_ports(pdev[i], d, 0, &hw[i*2], &hws[i*2]);
595 }
596
597 host = ide_host_alloc(d, hws);
598 if (host == NULL) {
599 ret = -ENOMEM;
600 goto out;
601 }
602
603 host->dev[0] = &dev1->dev;
604 host->dev[1] = &dev2->dev;
605
606 host->host_priv = priv;
607
608 pci_set_drvdata(pdev[0], host);
609 pci_set_drvdata(pdev[1], host);
610
611 for (i = 0; i < 2; i++) {
568 ret = do_ide_setup_pci_device(pdev[i], d, !i); 612 ret = do_ide_setup_pci_device(pdev[i], d, !i);
569 613
570 /* 614 /*
@@ -574,12 +618,44 @@ int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
574 if (ret < 0) 618 if (ret < 0)
575 goto out; 619 goto out;
576 620
577 /* FIXME: silent failure can happen */ 621 /* fixup IRQ */
578 ide_pci_setup_ports(pdev[i], d, ret, &hw[i*2], &hws[i*2]); 622 hw[i*2 + 1].irq = hw[i*2].irq = ret;
579 } 623 }
580 624
581 ret = ide_host_add(d, hws, NULL); 625 ret = ide_host_register(host, d, hws);
626 if (ret)
627 ide_host_free(host);
582out: 628out:
583 return ret; 629 return ret;
584} 630}
585EXPORT_SYMBOL_GPL(ide_setup_pci_devices); 631EXPORT_SYMBOL_GPL(ide_pci_init_two);
632
633void ide_pci_remove(struct pci_dev *dev)
634{
635 struct ide_host *host = pci_get_drvdata(dev);
636 struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
637 int bars;
638
639 if (host->host_flags & IDE_HFLAG_SINGLE)
640 bars = (1 << 2) - 1;
641 else
642 bars = (1 << 4) - 1;
643
644 if ((host->host_flags & IDE_HFLAG_NO_DMA) == 0) {
645 if (host->host_flags & IDE_HFLAG_CS5520)
646 bars |= (1 << 2);
647 else
648 bars |= (1 << 4);
649 }
650
651 ide_host_remove(host);
652
653 if (dev2)
654 pci_release_selected_regions(dev2, bars);
655 pci_release_selected_regions(dev, bars);
656
657 if (dev2)
658 pci_disable_device(dev2);
659 pci_disable_device(dev);
660}
661EXPORT_SYMBOL_GPL(ide_pci_remove);