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.c129
1 files changed, 31 insertions, 98 deletions
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index f7ede0e42881..6302010fd8e2 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -20,73 +20,6 @@
20#include <asm/io.h> 20#include <asm/io.h>
21#include <asm/irq.h> 21#include <asm/irq.h>
22 22
23
24/**
25 * ide_match_hwif - match a PCI IDE against an ide_hwif
26 * @io_base: I/O base of device
27 * @bootable: set if its bootable
28 * @name: name of device
29 *
30 * Match a PCI IDE port against an entry in ide_hwifs[],
31 * based on io_base port if possible. Return the matching hwif,
32 * or a new hwif. If we find an error (clashing, out of devices, etc)
33 * return NULL
34 *
35 * FIXME: we need to handle mmio matches here too
36 */
37
38static ide_hwif_t *ide_match_hwif(unsigned long io_base, u8 bootable, const char *name)
39{
40 int h;
41 ide_hwif_t *hwif;
42
43 /*
44 * Look for a hwif with matching io_base default value.
45 * If chipset is "ide_unknown", then claim that hwif slot.
46 * Otherwise, some other chipset has already claimed it.. :(
47 */
48 for (h = 0; h < MAX_HWIFS; ++h) {
49 hwif = &ide_hwifs[h];
50 if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) {
51 if (hwif->chipset == ide_unknown)
52 return hwif; /* match */
53 printk(KERN_ERR "%s: port 0x%04lx already claimed by %s\n",
54 name, io_base, hwif->name);
55 return NULL; /* already claimed */
56 }
57 }
58 /*
59 * Okay, there is no hwif matching our io_base,
60 * so we'll just claim an unassigned slot.
61 * Give preference to claiming other slots before claiming ide0/ide1,
62 * just in case there's another interface yet-to-be-scanned
63 * which uses ports 1f0/170 (the ide0/ide1 defaults).
64 *
65 * Unless there is a bootable card that does not use the standard
66 * ports 1f0/170 (the ide0/ide1 defaults). The (bootable) flag.
67 */
68 if (bootable) {
69 for (h = 0; h < MAX_HWIFS; ++h) {
70 hwif = &ide_hwifs[h];
71 if (hwif->chipset == ide_unknown)
72 return hwif; /* pick an unused entry */
73 }
74 } else {
75 for (h = 2; h < MAX_HWIFS; ++h) {
76 hwif = ide_hwifs + h;
77 if (hwif->chipset == ide_unknown)
78 return hwif; /* pick an unused entry */
79 }
80 }
81 for (h = 0; h < 2 && h < MAX_HWIFS; ++h) {
82 hwif = ide_hwifs + h;
83 if (hwif->chipset == ide_unknown)
84 return hwif; /* pick an unused entry */
85 }
86 printk(KERN_ERR "%s: too many IDE interfaces, no room in table\n", name);
87 return NULL;
88}
89
90/** 23/**
91 * ide_setup_pci_baseregs - place a PCI IDE controller native 24 * ide_setup_pci_baseregs - place a PCI IDE controller native
92 * @dev: PCI device of interface to switch native 25 * @dev: PCI device of interface to switch native
@@ -94,13 +27,13 @@ static ide_hwif_t *ide_match_hwif(unsigned long io_base, u8 bootable, const char
94 * 27 *
95 * We attempt to place the PCI interface into PCI native mode. If 28 * We attempt to place the PCI interface into PCI native mode. If
96 * we succeed the BARs are ok and the controller is in PCI mode. 29 * we succeed the BARs are ok and the controller is in PCI mode.
97 * Returns 0 on success or an errno code. 30 * Returns 0 on success or an errno code.
98 * 31 *
99 * FIXME: if we program the interface and then fail to set the BARS 32 * FIXME: if we program the interface and then fail to set the BARS
100 * we don't switch it back to legacy mode. Do we actually care ?? 33 * we don't switch it back to legacy mode. Do we actually care ??
101 */ 34 */
102 35
103static int ide_setup_pci_baseregs (struct pci_dev *dev, const char *name) 36static int ide_setup_pci_baseregs(struct pci_dev *dev, const char *name)
104{ 37{
105 u8 progif = 0; 38 u8 progif = 0;
106 39
@@ -207,7 +140,6 @@ void ide_setup_pci_noise(struct pci_dev *dev, const struct ide_port_info *d)
207 " PCI slot %s\n", d->name, dev->vendor, dev->device, 140 " PCI slot %s\n", d->name, dev->vendor, dev->device,
208 dev->revision, pci_name(dev)); 141 dev->revision, pci_name(dev));
209} 142}
210
211EXPORT_SYMBOL_GPL(ide_setup_pci_noise); 143EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
212 144
213 145
@@ -220,7 +152,7 @@ EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
220 * but if that fails then we only need IO space. The PCI code should 152 * but if that fails then we only need IO space. The PCI code should
221 * have setup the proper resources for us already for controllers in 153 * have setup the proper resources for us already for controllers in
222 * legacy mode. 154 * legacy mode.
223 * 155 *
224 * Returns zero on success or an error code 156 * Returns zero on success or an error code
225 */ 157 */
226 158
@@ -279,8 +211,8 @@ static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d)
279 * Maybe the user deliberately *disabled* the device, 211 * Maybe the user deliberately *disabled* the device,
280 * but we'll eventually ignore it again if no drives respond. 212 * but we'll eventually ignore it again if no drives respond.
281 */ 213 */
282 if (ide_setup_pci_baseregs(dev, d->name) || pci_write_config_word(dev, PCI_COMMAND, pcicmd|PCI_COMMAND_IO)) 214 if (ide_setup_pci_baseregs(dev, d->name) ||
283 { 215 pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_IO)) {
284 printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name); 216 printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name);
285 return -ENODEV; 217 return -ENODEV;
286 } 218 }
@@ -301,26 +233,24 @@ static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d)
301 * @d: IDE port info 233 * @d: IDE port info
302 * @bar: BAR number 234 * @bar: BAR number
303 * 235 *
304 * Checks if a BAR is configured and points to MMIO space. If so 236 * Checks if a BAR is configured and points to MMIO space. If so,
305 * print an error and return an error code. Otherwise return 0 237 * return an error code. Otherwise return 0
306 */ 238 */
307 239
308static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *d, int bar) 240static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *d,
241 int bar)
309{ 242{
310 ulong flags = pci_resource_flags(dev, bar); 243 ulong flags = pci_resource_flags(dev, bar);
311 244
312 /* Unconfigured ? */ 245 /* Unconfigured ? */
313 if (!flags || pci_resource_len(dev, bar) == 0) 246 if (!flags || pci_resource_len(dev, bar) == 0)
314 return 0; 247 return 0;
315 248
316 /* I/O space */ 249 /* I/O space */
317 if(flags & PCI_BASE_ADDRESS_IO_MASK) 250 if (flags & IORESOURCE_IO)
318 return 0; 251 return 0;
319 252
320 /* Bad */ 253 /* Bad */
321 printk(KERN_ERR "%s: IO baseregs (BIOS) are reported "
322 "as MEM, report to "
323 "<andre@linux-ide.org>.\n", d->name);
324 return -EINVAL; 254 return -EINVAL;
325} 255}
326 256
@@ -344,14 +274,16 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev,
344{ 274{
345 unsigned long ctl = 0, base = 0; 275 unsigned long ctl = 0, base = 0;
346 ide_hwif_t *hwif; 276 ide_hwif_t *hwif;
347 u8 bootable = (d->host_flags & IDE_HFLAG_BOOTABLE) ? 1 : 0;
348 struct hw_regs_s hw; 277 struct hw_regs_s hw;
349 278
350 if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) { 279 if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) {
351 /* Possibly we should fail if these checks report true */ 280 if (ide_pci_check_iomem(dev, d, 2 * port) ||
352 ide_pci_check_iomem(dev, d, 2*port); 281 ide_pci_check_iomem(dev, d, 2 * port + 1)) {
353 ide_pci_check_iomem(dev, d, 2*port+1); 282 printk(KERN_ERR "%s: I/O baseregs (BIOS) are reported "
354 283 "as MEM for port %d!\n", d->name, port);
284 return NULL;
285 }
286
355 ctl = pci_resource_start(dev, 2*port+1); 287 ctl = pci_resource_start(dev, 2*port+1);
356 base = pci_resource_start(dev, 2*port); 288 base = pci_resource_start(dev, 2*port);
357 if ((ctl && !base) || (base && !ctl)) { 289 if ((ctl && !base) || (base && !ctl)) {
@@ -360,14 +292,18 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev,
360 return NULL; 292 return NULL;
361 } 293 }
362 } 294 }
363 if (!ctl) 295 if (!ctl) {
364 {
365 /* Use default values */ 296 /* Use default values */
366 ctl = port ? 0x374 : 0x3f4; 297 ctl = port ? 0x374 : 0x3f4;
367 base = port ? 0x170 : 0x1f0; 298 base = port ? 0x170 : 0x1f0;
368 } 299 }
369 if ((hwif = ide_match_hwif(base, bootable, d->name)) == NULL) 300
370 return NULL; /* no room in ide_hwifs[] */ 301 hwif = ide_find_port_slot(d);
302 if (hwif == NULL) {
303 printk(KERN_ERR "%s: too many IDE interfaces, no room in "
304 "table\n", d->name);
305 return NULL;
306 }
371 307
372 memset(&hw, 0, sizeof(hw)); 308 memset(&hw, 0, sizeof(hw));
373 hw.irq = irq; 309 hw.irq = irq;
@@ -407,9 +343,9 @@ void ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
407 unsigned long dma_base = ide_get_or_set_dma_base(d, hwif); 343 unsigned long dma_base = ide_get_or_set_dma_base(d, hwif);
408 if (dma_base && !(pcicmd & PCI_COMMAND_MASTER)) { 344 if (dma_base && !(pcicmd & PCI_COMMAND_MASTER)) {
409 /* 345 /*
410 * Set up BM-DMA capability 346 * Set up BM-DMA capability
411 * (PnP BIOS should have done this) 347 * (PnP BIOS should have done this)
412 */ 348 */
413 pci_set_master(dev); 349 pci_set_master(dev);
414 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) { 350 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) {
415 printk(KERN_ERR "%s: %s error updating PCICMD\n", 351 printk(KERN_ERR "%s: %s error updating PCICMD\n",
@@ -514,7 +450,6 @@ void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d, int
514 *(idx + port) = hwif->index; 450 *(idx + port) = hwif->index;
515 } 451 }
516} 452}
517
518EXPORT_SYMBOL_GPL(ide_pci_setup_ports); 453EXPORT_SYMBOL_GPL(ide_pci_setup_ports);
519 454
520/* 455/*
@@ -597,7 +532,6 @@ int ide_setup_pci_device(struct pci_dev *dev, const struct ide_port_info *d)
597 532
598 return ret; 533 return ret;
599} 534}
600
601EXPORT_SYMBOL_GPL(ide_setup_pci_device); 535EXPORT_SYMBOL_GPL(ide_setup_pci_device);
602 536
603int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2, 537int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
@@ -621,5 +555,4 @@ int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
621out: 555out:
622 return ret; 556 return ret;
623} 557}
624
625EXPORT_SYMBOL_GPL(ide_setup_pci_devices); 558EXPORT_SYMBOL_GPL(ide_setup_pci_devices);