diff options
Diffstat (limited to 'drivers/ide/setup-pci.c')
-rw-r--r-- | drivers/ide/setup-pci.c | 226 |
1 files changed, 92 insertions, 134 deletions
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c index f7ede0e42881..5171601fb255 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 | |||
38 | static 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 | ||
103 | static int ide_setup_pci_baseregs (struct pci_dev *dev, const char *name) | 36 | static int ide_setup_pci_baseregs(struct pci_dev *dev, const char *name) |
104 | { | 37 | { |
105 | u8 progif = 0; | 38 | u8 progif = 0; |
106 | 39 | ||
@@ -139,16 +72,16 @@ static void ide_pci_clear_simplex(unsigned long dma_base, const char *name) | |||
139 | } | 72 | } |
140 | 73 | ||
141 | /** | 74 | /** |
142 | * ide_get_or_set_dma_base - setup BMIBA | 75 | * ide_pci_dma_base - setup BMIBA |
143 | * @d: IDE port info | ||
144 | * @hwif: IDE interface | 76 | * @hwif: IDE interface |
77 | * @d: IDE port info | ||
145 | * | 78 | * |
146 | * Fetch the DMA Bus-Master-I/O-Base-Address (BMIBA) from PCI space. | 79 | * Fetch the DMA Bus-Master-I/O-Base-Address (BMIBA) from PCI space. |
147 | * Where a device has a partner that is already in DMA mode we check | 80 | * Where a device has a partner that is already in DMA mode we check |
148 | * and enforce IDE simplex rules. | 81 | * and enforce IDE simplex rules. |
149 | */ | 82 | */ |
150 | 83 | ||
151 | static unsigned long ide_get_or_set_dma_base(const struct ide_port_info *d, ide_hwif_t *hwif) | 84 | unsigned long ide_pci_dma_base(ide_hwif_t *hwif, const struct ide_port_info *d) |
152 | { | 85 | { |
153 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 86 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
154 | unsigned long dma_base = 0; | 87 | unsigned long dma_base = 0; |
@@ -199,6 +132,31 @@ static unsigned long ide_get_or_set_dma_base(const struct ide_port_info *d, ide_ | |||
199 | out: | 132 | out: |
200 | return dma_base; | 133 | return dma_base; |
201 | } | 134 | } |
135 | EXPORT_SYMBOL_GPL(ide_pci_dma_base); | ||
136 | |||
137 | /* | ||
138 | * Set up BM-DMA capability (PnP BIOS should have done this) | ||
139 | */ | ||
140 | int ide_pci_set_master(struct pci_dev *dev, const char *name) | ||
141 | { | ||
142 | u16 pcicmd; | ||
143 | |||
144 | pci_read_config_word(dev, PCI_COMMAND, &pcicmd); | ||
145 | |||
146 | if ((pcicmd & PCI_COMMAND_MASTER) == 0) { | ||
147 | pci_set_master(dev); | ||
148 | |||
149 | if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || | ||
150 | (pcicmd & PCI_COMMAND_MASTER) == 0) { | ||
151 | printk(KERN_ERR "%s: error updating PCICMD on %s\n", | ||
152 | name, pci_name(dev)); | ||
153 | return -EIO; | ||
154 | } | ||
155 | } | ||
156 | |||
157 | return 0; | ||
158 | } | ||
159 | EXPORT_SYMBOL_GPL(ide_pci_set_master); | ||
202 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ | 160 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ |
203 | 161 | ||
204 | void ide_setup_pci_noise(struct pci_dev *dev, const struct ide_port_info *d) | 162 | void ide_setup_pci_noise(struct pci_dev *dev, const struct ide_port_info *d) |
@@ -207,7 +165,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, | 165 | " PCI slot %s\n", d->name, dev->vendor, dev->device, |
208 | dev->revision, pci_name(dev)); | 166 | dev->revision, pci_name(dev)); |
209 | } | 167 | } |
210 | |||
211 | EXPORT_SYMBOL_GPL(ide_setup_pci_noise); | 168 | EXPORT_SYMBOL_GPL(ide_setup_pci_noise); |
212 | 169 | ||
213 | 170 | ||
@@ -220,13 +177,13 @@ EXPORT_SYMBOL_GPL(ide_setup_pci_noise); | |||
220 | * but if that fails then we only need IO space. The PCI code should | 177 | * 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 | 178 | * have setup the proper resources for us already for controllers in |
222 | * legacy mode. | 179 | * legacy mode. |
223 | * | 180 | * |
224 | * Returns zero on success or an error code | 181 | * Returns zero on success or an error code |
225 | */ | 182 | */ |
226 | 183 | ||
227 | static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d) | 184 | static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d) |
228 | { | 185 | { |
229 | int ret; | 186 | int ret, bars; |
230 | 187 | ||
231 | if (pci_enable_device(dev)) { | 188 | if (pci_enable_device(dev)) { |
232 | ret = pci_enable_device_io(dev); | 189 | ret = pci_enable_device_io(dev); |
@@ -249,13 +206,21 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d) | |||
249 | goto out; | 206 | goto out; |
250 | } | 207 | } |
251 | 208 | ||
252 | /* FIXME: Temporary - until we put in the hotplug interface logic | 209 | if (d->host_flags & IDE_HFLAG_SINGLE) |
253 | Check that the bits we want are not in use by someone else. */ | 210 | bars = (1 << 2) - 1; |
254 | ret = pci_request_region(dev, 4, "ide_tmp"); | 211 | else |
255 | if (ret < 0) | 212 | bars = (1 << 4) - 1; |
256 | goto out; | 213 | |
214 | if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) { | ||
215 | if (d->host_flags & IDE_HFLAG_CS5520) | ||
216 | bars |= (1 << 2); | ||
217 | else | ||
218 | bars |= (1 << 4); | ||
219 | } | ||
257 | 220 | ||
258 | pci_release_region(dev, 4); | 221 | ret = pci_request_selected_regions(dev, bars, d->name); |
222 | if (ret < 0) | ||
223 | printk(KERN_ERR "%s: can't reserve resources\n", d->name); | ||
259 | out: | 224 | out: |
260 | return ret; | 225 | return ret; |
261 | } | 226 | } |
@@ -279,8 +244,8 @@ static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d) | |||
279 | * Maybe the user deliberately *disabled* the device, | 244 | * Maybe the user deliberately *disabled* the device, |
280 | * but we'll eventually ignore it again if no drives respond. | 245 | * but we'll eventually ignore it again if no drives respond. |
281 | */ | 246 | */ |
282 | if (ide_setup_pci_baseregs(dev, d->name) || pci_write_config_word(dev, PCI_COMMAND, pcicmd|PCI_COMMAND_IO)) | 247 | if (ide_setup_pci_baseregs(dev, d->name) || |
283 | { | 248 | pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_IO)) { |
284 | printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name); | 249 | printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name); |
285 | return -ENODEV; | 250 | return -ENODEV; |
286 | } | 251 | } |
@@ -301,26 +266,24 @@ static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d) | |||
301 | * @d: IDE port info | 266 | * @d: IDE port info |
302 | * @bar: BAR number | 267 | * @bar: BAR number |
303 | * | 268 | * |
304 | * Checks if a BAR is configured and points to MMIO space. If so | 269 | * 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 | 270 | * return an error code. Otherwise return 0 |
306 | */ | 271 | */ |
307 | 272 | ||
308 | static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *d, int bar) | 273 | static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *d, |
274 | int bar) | ||
309 | { | 275 | { |
310 | ulong flags = pci_resource_flags(dev, bar); | 276 | ulong flags = pci_resource_flags(dev, bar); |
311 | 277 | ||
312 | /* Unconfigured ? */ | 278 | /* Unconfigured ? */ |
313 | if (!flags || pci_resource_len(dev, bar) == 0) | 279 | if (!flags || pci_resource_len(dev, bar) == 0) |
314 | return 0; | 280 | return 0; |
315 | 281 | ||
316 | /* I/O space */ | 282 | /* I/O space */ |
317 | if(flags & PCI_BASE_ADDRESS_IO_MASK) | 283 | if (flags & IORESOURCE_IO) |
318 | return 0; | 284 | return 0; |
319 | 285 | ||
320 | /* Bad */ | 286 | /* 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; | 287 | return -EINVAL; |
325 | } | 288 | } |
326 | 289 | ||
@@ -344,14 +307,16 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, | |||
344 | { | 307 | { |
345 | unsigned long ctl = 0, base = 0; | 308 | unsigned long ctl = 0, base = 0; |
346 | ide_hwif_t *hwif; | 309 | ide_hwif_t *hwif; |
347 | u8 bootable = (d->host_flags & IDE_HFLAG_BOOTABLE) ? 1 : 0; | ||
348 | struct hw_regs_s hw; | 310 | struct hw_regs_s hw; |
349 | 311 | ||
350 | if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) { | 312 | if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) { |
351 | /* Possibly we should fail if these checks report true */ | 313 | if (ide_pci_check_iomem(dev, d, 2 * port) || |
352 | ide_pci_check_iomem(dev, d, 2*port); | 314 | ide_pci_check_iomem(dev, d, 2 * port + 1)) { |
353 | ide_pci_check_iomem(dev, d, 2*port+1); | 315 | printk(KERN_ERR "%s: I/O baseregs (BIOS) are reported " |
354 | 316 | "as MEM for port %d!\n", d->name, port); | |
317 | return NULL; | ||
318 | } | ||
319 | |||
355 | ctl = pci_resource_start(dev, 2*port+1); | 320 | ctl = pci_resource_start(dev, 2*port+1); |
356 | base = pci_resource_start(dev, 2*port); | 321 | base = pci_resource_start(dev, 2*port); |
357 | if ((ctl && !base) || (base && !ctl)) { | 322 | if ((ctl && !base) || (base && !ctl)) { |
@@ -360,14 +325,18 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, | |||
360 | return NULL; | 325 | return NULL; |
361 | } | 326 | } |
362 | } | 327 | } |
363 | if (!ctl) | 328 | if (!ctl) { |
364 | { | ||
365 | /* Use default values */ | 329 | /* Use default values */ |
366 | ctl = port ? 0x374 : 0x3f4; | 330 | ctl = port ? 0x374 : 0x3f4; |
367 | base = port ? 0x170 : 0x1f0; | 331 | base = port ? 0x170 : 0x1f0; |
368 | } | 332 | } |
369 | if ((hwif = ide_match_hwif(base, bootable, d->name)) == NULL) | 333 | |
370 | return NULL; /* no room in ide_hwifs[] */ | 334 | hwif = ide_find_port_slot(d); |
335 | if (hwif == NULL) { | ||
336 | printk(KERN_ERR "%s: too many IDE interfaces, no room in " | ||
337 | "table\n", d->name); | ||
338 | return NULL; | ||
339 | } | ||
371 | 340 | ||
372 | memset(&hw, 0, sizeof(hw)); | 341 | memset(&hw, 0, sizeof(hw)); |
373 | hw.irq = irq; | 342 | hw.irq = irq; |
@@ -378,7 +347,6 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, | |||
378 | ide_init_port_hw(hwif, &hw); | 347 | ide_init_port_hw(hwif, &hw); |
379 | 348 | ||
380 | hwif->dev = &dev->dev; | 349 | hwif->dev = &dev->dev; |
381 | hwif->cds = d; | ||
382 | 350 | ||
383 | return hwif; | 351 | return hwif; |
384 | } | 352 | } |
@@ -394,40 +362,33 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, | |||
394 | * state | 362 | * state |
395 | */ | 363 | */ |
396 | 364 | ||
397 | void ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d) | 365 | int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d) |
398 | { | 366 | { |
399 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 367 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
400 | u16 pcicmd; | ||
401 | |||
402 | pci_read_config_word(dev, PCI_COMMAND, &pcicmd); | ||
403 | 368 | ||
404 | if ((d->host_flags & IDE_HFLAG_NO_AUTODMA) == 0 || | 369 | if ((d->host_flags & IDE_HFLAG_NO_AUTODMA) == 0 || |
405 | ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && | 370 | ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && |
406 | (dev->class & 0x80))) { | 371 | (dev->class & 0x80))) { |
407 | unsigned long dma_base = ide_get_or_set_dma_base(d, hwif); | 372 | unsigned long base = ide_pci_dma_base(hwif, d); |
408 | if (dma_base && !(pcicmd & PCI_COMMAND_MASTER)) { | 373 | |
409 | /* | 374 | if (base == 0 || ide_pci_set_master(dev, d->name) < 0) |
410 | * Set up BM-DMA capability | 375 | return -1; |
411 | * (PnP BIOS should have done this) | 376 | |
412 | */ | 377 | if (hwif->mmio) |
413 | pci_set_master(dev); | 378 | printk(KERN_INFO " %s: MMIO-DMA\n", hwif->name); |
414 | if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) { | 379 | else |
415 | printk(KERN_ERR "%s: %s error updating PCICMD\n", | 380 | printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx\n", |
416 | hwif->name, d->name); | 381 | hwif->name, base, base + 7); |
417 | dma_base = 0; | 382 | |
418 | } | 383 | hwif->extra_base = base + (hwif->channel ? 8 : 16); |
419 | } | 384 | |
420 | if (dma_base) { | 385 | if (ide_allocate_dma_engine(hwif)) |
421 | if (d->init_dma) { | 386 | return -1; |
422 | d->init_dma(hwif, dma_base); | 387 | |
423 | } else { | 388 | ide_setup_dma(hwif, base); |
424 | ide_setup_dma(hwif, dma_base); | ||
425 | } | ||
426 | } else { | ||
427 | printk(KERN_INFO "%s: %s Bus-Master DMA disabled " | ||
428 | "(BIOS)\n", hwif->name, d->name); | ||
429 | } | ||
430 | } | 389 | } |
390 | |||
391 | return 0; | ||
431 | } | 392 | } |
432 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ | 393 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ |
433 | 394 | ||
@@ -514,7 +475,6 @@ void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d, int | |||
514 | *(idx + port) = hwif->index; | 475 | *(idx + port) = hwif->index; |
515 | } | 476 | } |
516 | } | 477 | } |
517 | |||
518 | EXPORT_SYMBOL_GPL(ide_pci_setup_ports); | 478 | EXPORT_SYMBOL_GPL(ide_pci_setup_ports); |
519 | 479 | ||
520 | /* | 480 | /* |
@@ -597,7 +557,6 @@ int ide_setup_pci_device(struct pci_dev *dev, const struct ide_port_info *d) | |||
597 | 557 | ||
598 | return ret; | 558 | return ret; |
599 | } | 559 | } |
600 | |||
601 | EXPORT_SYMBOL_GPL(ide_setup_pci_device); | 560 | EXPORT_SYMBOL_GPL(ide_setup_pci_device); |
602 | 561 | ||
603 | int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2, | 562 | int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2, |
@@ -621,5 +580,4 @@ int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2, | |||
621 | out: | 580 | out: |
622 | return ret; | 581 | return ret; |
623 | } | 582 | } |
624 | |||
625 | EXPORT_SYMBOL_GPL(ide_setup_pci_devices); | 583 | EXPORT_SYMBOL_GPL(ide_setup_pci_devices); |