aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/Kconfig4
-rw-r--r--drivers/pci/access.c75
-rw-r--r--drivers/pci/hotplug/acpi_pcihp.c2
-rw-r--r--drivers/pci/hotplug/acpiphp.h6
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c41
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c16
-rw-r--r--drivers/pci/hotplug/acpiphp_ibm.c1
-rw-r--r--drivers/pci/hotplug/cpci_hotplug_core.c2
-rw-r--r--drivers/pci/hotplug/cpci_hotplug_pci.c2
-rw-r--r--drivers/pci/hotplug/cpcihp_generic.c4
-rw-r--r--drivers/pci/hotplug/cpqphp.h1
-rw-r--r--drivers/pci/hotplug/cpqphp_core.c1
-rw-r--r--drivers/pci/hotplug/cpqphp_ctrl.c1
-rw-r--r--drivers/pci/hotplug/cpqphp_nvram.c1
-rw-r--r--drivers/pci/hotplug/cpqphp_pci.c1
-rw-r--r--drivers/pci/hotplug/cpqphp_sysfs.c1
-rw-r--r--drivers/pci/hotplug/fakephp.c13
-rw-r--r--drivers/pci/hotplug/ibmphp.h2
-rw-r--r--drivers/pci/hotplug/ibmphp_hpc.c2
-rw-r--r--drivers/pci/hotplug/ibmphp_pci.c4
-rw-r--r--drivers/pci/hotplug/pci_hotplug.h236
-rw-r--r--drivers/pci/hotplug/pci_hotplug_core.c11
-rw-r--r--drivers/pci/hotplug/pciehp.h11
-rw-r--r--drivers/pci/hotplug/pciehp_core.c13
-rw-r--r--drivers/pci/hotplug/pciehp_ctrl.c104
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c4
-rw-r--r--drivers/pci/hotplug/pcihp_skeleton.c2
-rw-r--r--drivers/pci/hotplug/rpadlpar_core.c2
-rw-r--r--drivers/pci/hotplug/rpadlpar_sysfs.c2
-rw-r--r--drivers/pci/hotplug/rpaphp.h2
-rw-r--r--drivers/pci/hotplug/rpaphp_core.c4
-rw-r--r--drivers/pci/hotplug/sgi_hotplug.c37
-rw-r--r--drivers/pci/hotplug/shpchp.h4
-rw-r--r--drivers/pci/hotplug/shpchp_hpc.c82
-rw-r--r--drivers/pci/htirq.c101
-rw-r--r--drivers/pci/msi.c16
-rw-r--r--drivers/pci/msi.h8
-rw-r--r--drivers/pci/pci-acpi.c10
-rw-r--r--drivers/pci/pci-driver.c24
-rw-r--r--drivers/pci/pci-sysfs.c36
-rw-r--r--drivers/pci/pci.c123
-rw-r--r--drivers/pci/pci.h1
-rw-r--r--drivers/pci/pcie/portdrv.h4
-rw-r--r--drivers/pci/pcie/portdrv_core.c3
-rw-r--r--drivers/pci/pcie/portdrv_pci.c2
-rw-r--r--drivers/pci/probe.c119
-rw-r--r--drivers/pci/quirks.c166
-rw-r--r--drivers/pci/rom.c15
-rw-r--r--drivers/pci/search.c72
49 files changed, 701 insertions, 693 deletions
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index ecc50db8585a..f1dd81a1d592 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -27,14 +27,14 @@ config PCI_MULTITHREAD_PROBE
27 smaller speedup on single processor machines. 27 smaller speedup on single processor machines.
28 28
29 But it can also cause lots of bad things to happen. A number 29 But it can also cause lots of bad things to happen. A number
30 of PCI drivers can not properly handle running in this way, 30 of PCI drivers cannot properly handle running in this way,
31 some will just not work properly at all, while others might 31 some will just not work properly at all, while others might
32 decide to blow up power supplies with a huge load all at once, 32 decide to blow up power supplies with a huge load all at once,
33 so use this option at your own risk. 33 so use this option at your own risk.
34 34
35 It is very unwise to use this option if you are not using a 35 It is very unwise to use this option if you are not using a
36 boot process that can handle devices being created in any 36 boot process that can handle devices being created in any
37 order. A program that can create persistant block and network 37 order. A program that can create persistent block and network
38 device names (like udev) is a good idea if you wish to use 38 device names (like udev) is a good idea if you wish to use
39 this option. 39 this option.
40 40
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index ea16805a153c..73a58c73d526 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -1,6 +1,7 @@
1#include <linux/pci.h> 1#include <linux/pci.h>
2#include <linux/module.h> 2#include <linux/module.h>
3#include <linux/ioport.h> 3#include <linux/ioport.h>
4#include <linux/wait.h>
4 5
5#include "pci.h" 6#include "pci.h"
6 7
@@ -63,30 +64,42 @@ EXPORT_SYMBOL(pci_bus_write_config_byte);
63EXPORT_SYMBOL(pci_bus_write_config_word); 64EXPORT_SYMBOL(pci_bus_write_config_word);
64EXPORT_SYMBOL(pci_bus_write_config_dword); 65EXPORT_SYMBOL(pci_bus_write_config_dword);
65 66
66static u32 pci_user_cached_config(struct pci_dev *dev, int pos) 67/*
67{ 68 * The following routines are to prevent the user from accessing PCI config
68 u32 data; 69 * space when it's unsafe to do so. Some devices require this during BIST and
70 * we're required to prevent it during D-state transitions.
71 *
72 * We have a bit per device to indicate it's blocked and a global wait queue
73 * for callers to sleep on until devices are unblocked.
74 */
75static DECLARE_WAIT_QUEUE_HEAD(pci_ucfg_wait);
69 76
70 data = dev->saved_config_space[pos/sizeof(dev->saved_config_space[0])]; 77static noinline void pci_wait_ucfg(struct pci_dev *dev)
71 data >>= (pos % sizeof(dev->saved_config_space[0])) * 8; 78{
72 return data; 79 DECLARE_WAITQUEUE(wait, current);
80
81 __add_wait_queue(&pci_ucfg_wait, &wait);
82 do {
83 set_current_state(TASK_UNINTERRUPTIBLE);
84 spin_unlock_irq(&pci_lock);
85 schedule();
86 spin_lock_irq(&pci_lock);
87 } while (dev->block_ucfg_access);
88 __remove_wait_queue(&pci_ucfg_wait, &wait);
73} 89}
74 90
75#define PCI_USER_READ_CONFIG(size,type) \ 91#define PCI_USER_READ_CONFIG(size,type) \
76int pci_user_read_config_##size \ 92int pci_user_read_config_##size \
77 (struct pci_dev *dev, int pos, type *val) \ 93 (struct pci_dev *dev, int pos, type *val) \
78{ \ 94{ \
79 unsigned long flags; \
80 int ret = 0; \ 95 int ret = 0; \
81 u32 data = -1; \ 96 u32 data = -1; \
82 if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER; \ 97 if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER; \
83 spin_lock_irqsave(&pci_lock, flags); \ 98 spin_lock_irq(&pci_lock); \
84 if (likely(!dev->block_ucfg_access)) \ 99 if (unlikely(dev->block_ucfg_access)) pci_wait_ucfg(dev); \
85 ret = dev->bus->ops->read(dev->bus, dev->devfn, \ 100 ret = dev->bus->ops->read(dev->bus, dev->devfn, \
86 pos, sizeof(type), &data); \ 101 pos, sizeof(type), &data); \
87 else if (pos < sizeof(dev->saved_config_space)) \ 102 spin_unlock_irq(&pci_lock); \
88 data = pci_user_cached_config(dev, pos); \
89 spin_unlock_irqrestore(&pci_lock, flags); \
90 *val = (type)data; \ 103 *val = (type)data; \
91 return ret; \ 104 return ret; \
92} 105}
@@ -95,14 +108,13 @@ int pci_user_read_config_##size \
95int pci_user_write_config_##size \ 108int pci_user_write_config_##size \
96 (struct pci_dev *dev, int pos, type val) \ 109 (struct pci_dev *dev, int pos, type val) \
97{ \ 110{ \
98 unsigned long flags; \
99 int ret = -EIO; \ 111 int ret = -EIO; \
100 if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER; \ 112 if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER; \
101 spin_lock_irqsave(&pci_lock, flags); \ 113 spin_lock_irq(&pci_lock); \
102 if (likely(!dev->block_ucfg_access)) \ 114 if (unlikely(dev->block_ucfg_access)) pci_wait_ucfg(dev); \
103 ret = dev->bus->ops->write(dev->bus, dev->devfn, \ 115 ret = dev->bus->ops->write(dev->bus, dev->devfn, \
104 pos, sizeof(type), val); \ 116 pos, sizeof(type), val); \
105 spin_unlock_irqrestore(&pci_lock, flags); \ 117 spin_unlock_irq(&pci_lock); \
106 return ret; \ 118 return ret; \
107} 119}
108 120
@@ -117,21 +129,23 @@ PCI_USER_WRITE_CONFIG(dword, u32)
117 * pci_block_user_cfg_access - Block userspace PCI config reads/writes 129 * pci_block_user_cfg_access - Block userspace PCI config reads/writes
118 * @dev: pci device struct 130 * @dev: pci device struct
119 * 131 *
120 * This function blocks any userspace PCI config accesses from occurring. 132 * When user access is blocked, any reads or writes to config space will
121 * When blocked, any writes will be bit bucketed and reads will return the 133 * sleep until access is unblocked again. We don't allow nesting of
122 * data saved using pci_save_state for the first 64 bytes of config 134 * block/unblock calls.
123 * space and return 0xff for all other config reads. 135 */
124 **/
125void pci_block_user_cfg_access(struct pci_dev *dev) 136void pci_block_user_cfg_access(struct pci_dev *dev)
126{ 137{
127 unsigned long flags; 138 unsigned long flags;
139 int was_blocked;
128 140
129 pci_save_state(dev);
130
131 /* spinlock to synchronize with anyone reading config space now */
132 spin_lock_irqsave(&pci_lock, flags); 141 spin_lock_irqsave(&pci_lock, flags);
142 was_blocked = dev->block_ucfg_access;
133 dev->block_ucfg_access = 1; 143 dev->block_ucfg_access = 1;
134 spin_unlock_irqrestore(&pci_lock, flags); 144 spin_unlock_irqrestore(&pci_lock, flags);
145
146 /* If we BUG() inside the pci_lock, we're guaranteed to hose
147 * the machine */
148 BUG_ON(was_blocked);
135} 149}
136EXPORT_SYMBOL_GPL(pci_block_user_cfg_access); 150EXPORT_SYMBOL_GPL(pci_block_user_cfg_access);
137 151
@@ -140,14 +154,19 @@ EXPORT_SYMBOL_GPL(pci_block_user_cfg_access);
140 * @dev: pci device struct 154 * @dev: pci device struct
141 * 155 *
142 * This function allows userspace PCI config accesses to resume. 156 * This function allows userspace PCI config accesses to resume.
143 **/ 157 */
144void pci_unblock_user_cfg_access(struct pci_dev *dev) 158void pci_unblock_user_cfg_access(struct pci_dev *dev)
145{ 159{
146 unsigned long flags; 160 unsigned long flags;
147 161
148 /* spinlock to synchronize with anyone reading saved config space */
149 spin_lock_irqsave(&pci_lock, flags); 162 spin_lock_irqsave(&pci_lock, flags);
163
164 /* This indicates a problem in the caller, but we don't need
165 * to kill them, unlike a double-block above. */
166 WARN_ON(!dev->block_ucfg_access);
167
150 dev->block_ucfg_access = 0; 168 dev->block_ucfg_access = 0;
169 wake_up_all(&pci_ucfg_wait);
151 spin_unlock_irqrestore(&pci_lock, flags); 170 spin_unlock_irqrestore(&pci_lock, flags);
152} 171}
153EXPORT_SYMBOL_GPL(pci_unblock_user_cfg_access); 172EXPORT_SYMBOL_GPL(pci_unblock_user_cfg_access);
diff --git a/drivers/pci/hotplug/acpi_pcihp.c b/drivers/pci/hotplug/acpi_pcihp.c
index 51cb9f817c22..270a33cc08f6 100644
--- a/drivers/pci/hotplug/acpi_pcihp.c
+++ b/drivers/pci/hotplug/acpi_pcihp.c
@@ -29,10 +29,10 @@
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/types.h> 30#include <linux/types.h>
31#include <linux/pci.h> 31#include <linux/pci.h>
32#include <linux/pci_hotplug.h>
32#include <acpi/acpi.h> 33#include <acpi/acpi.h>
33#include <acpi/acpi_bus.h> 34#include <acpi/acpi_bus.h>
34#include <acpi/actypes.h> 35#include <acpi/actypes.h>
35#include "pci_hotplug.h"
36 36
37#define MY_NAME "acpi_pcihp" 37#define MY_NAME "acpi_pcihp"
38 38
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index 7fff07e877c7..ddbadd95387e 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -38,7 +38,7 @@
38#include <linux/acpi.h> 38#include <linux/acpi.h>
39#include <linux/kobject.h> /* for KOBJ_NAME_LEN */ 39#include <linux/kobject.h> /* for KOBJ_NAME_LEN */
40#include <linux/mutex.h> 40#include <linux/mutex.h>
41#include "pci_hotplug.h" 41#include <linux/pci_hotplug.h>
42 42
43#define dbg(format, arg...) \ 43#define dbg(format, arg...) \
44 do { \ 44 do { \
@@ -62,10 +62,10 @@ struct acpiphp_slot;
62struct slot { 62struct slot {
63 struct hotplug_slot *hotplug_slot; 63 struct hotplug_slot *hotplug_slot;
64 struct acpiphp_slot *acpi_slot; 64 struct acpiphp_slot *acpi_slot;
65 struct hotplug_slot_info info;
66 char name[SLOT_NAME_SIZE];
65}; 67};
66 68
67
68
69/** 69/**
70 * struct acpiphp_bridge - PCI bridge information 70 * struct acpiphp_bridge - PCI bridge information
71 * 71 *
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index e2fef60c2d06..40c79b03c7ef 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -37,10 +37,10 @@
37 37
38#include <linux/kernel.h> 38#include <linux/kernel.h>
39#include <linux/pci.h> 39#include <linux/pci.h>
40#include <linux/pci_hotplug.h>
40#include <linux/slab.h> 41#include <linux/slab.h>
41#include <linux/smp.h> 42#include <linux/smp.h>
42#include <linux/smp_lock.h> 43#include <linux/smp_lock.h>
43#include "pci_hotplug.h"
44#include "acpiphp.h" 44#include "acpiphp.h"
45 45
46#define MY_NAME "acpiphp" 46#define MY_NAME "acpiphp"
@@ -303,25 +303,15 @@ static int __init init_acpi(void)
303 /* read initial number of slots */ 303 /* read initial number of slots */
304 if (!retval) { 304 if (!retval) {
305 num_slots = acpiphp_get_num_slots(); 305 num_slots = acpiphp_get_num_slots();
306 if (num_slots == 0) 306 if (num_slots == 0) {
307 acpiphp_glue_exit();
307 retval = -ENODEV; 308 retval = -ENODEV;
309 }
308 } 310 }
309 311
310 return retval; 312 return retval;
311} 313}
312 314
313
314/**
315 * make_slot_name - make a slot name that appears in pcihpfs
316 * @slot: slot to name
317 *
318 */
319static void make_slot_name(struct slot *slot)
320{
321 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%u",
322 slot->acpi_slot->sun);
323}
324
325/** 315/**
326 * release_slot - free up the memory used by a slot 316 * release_slot - free up the memory used by a slot
327 * @hotplug_slot: slot to free 317 * @hotplug_slot: slot to free
@@ -332,8 +322,6 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
332 322
333 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 323 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
334 324
335 kfree(slot->hotplug_slot->info);
336 kfree(slot->hotplug_slot->name);
337 kfree(slot->hotplug_slot); 325 kfree(slot->hotplug_slot);
338 kfree(slot); 326 kfree(slot);
339} 327}
@@ -342,26 +330,19 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
342int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot) 330int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
343{ 331{
344 struct slot *slot; 332 struct slot *slot;
345 struct hotplug_slot *hotplug_slot;
346 struct hotplug_slot_info *hotplug_slot_info;
347 int retval = -ENOMEM; 333 int retval = -ENOMEM;
348 334
349 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 335 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
350 if (!slot) 336 if (!slot)
351 goto error; 337 goto error;
352 338
353 slot->hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL); 339 slot->hotplug_slot = kzalloc(sizeof(*slot->hotplug_slot), GFP_KERNEL);
354 if (!slot->hotplug_slot) 340 if (!slot->hotplug_slot)
355 goto error_slot; 341 goto error_slot;
356 342
357 slot->hotplug_slot->info = kzalloc(sizeof(*hotplug_slot_info), 343 slot->hotplug_slot->info = &slot->info;
358 GFP_KERNEL);
359 if (!slot->hotplug_slot->info)
360 goto error_hpslot;
361 344
362 slot->hotplug_slot->name = kzalloc(SLOT_NAME_SIZE, GFP_KERNEL); 345 slot->hotplug_slot->name = slot->name;
363 if (!slot->hotplug_slot->name)
364 goto error_info;
365 346
366 slot->hotplug_slot->private = slot; 347 slot->hotplug_slot->private = slot;
367 slot->hotplug_slot->release = &release_slot; 348 slot->hotplug_slot->release = &release_slot;
@@ -376,21 +357,17 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
376 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN; 357 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;
377 358
378 acpiphp_slot->slot = slot; 359 acpiphp_slot->slot = slot;
379 make_slot_name(slot); 360 snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun);
380 361
381 retval = pci_hp_register(slot->hotplug_slot); 362 retval = pci_hp_register(slot->hotplug_slot);
382 if (retval) { 363 if (retval) {
383 err("pci_hp_register failed with error %d\n", retval); 364 err("pci_hp_register failed with error %d\n", retval);
384 goto error_name; 365 goto error_hpslot;
385 } 366 }
386 367
387 info("Slot [%s] registered\n", slot->hotplug_slot->name); 368 info("Slot [%s] registered\n", slot->hotplug_slot->name);
388 369
389 return 0; 370 return 0;
390error_name:
391 kfree(slot->hotplug_slot->name);
392error_info:
393 kfree(slot->hotplug_slot->info);
394error_hpslot: 371error_hpslot:
395 kfree(slot->hotplug_slot); 372 kfree(slot->hotplug_slot);
396error_slot: 373error_slot:
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 83e8e4412de5..0b9d0db1590a 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -45,11 +45,11 @@
45 45
46#include <linux/kernel.h> 46#include <linux/kernel.h>
47#include <linux/pci.h> 47#include <linux/pci.h>
48#include <linux/pci_hotplug.h>
48#include <linux/smp_lock.h> 49#include <linux/smp_lock.h>
49#include <linux/mutex.h> 50#include <linux/mutex.h>
50 51
51#include "../pci.h" 52#include "../pci.h"
52#include "pci_hotplug.h"
53#include "acpiphp.h" 53#include "acpiphp.h"
54 54
55static LIST_HEAD(bridge_list); 55static LIST_HEAD(bridge_list);
@@ -1693,14 +1693,10 @@ void __exit acpiphp_glue_exit(void)
1693 */ 1693 */
1694int __init acpiphp_get_num_slots(void) 1694int __init acpiphp_get_num_slots(void)
1695{ 1695{
1696 struct list_head *node;
1697 struct acpiphp_bridge *bridge; 1696 struct acpiphp_bridge *bridge;
1698 int num_slots; 1697 int num_slots = 0;
1699
1700 num_slots = 0;
1701 1698
1702 list_for_each (node, &bridge_list) { 1699 list_for_each_entry (bridge, &bridge_list, list) {
1703 bridge = (struct acpiphp_bridge *)node;
1704 dbg("Bus %04x:%02x has %d slot%s\n", 1700 dbg("Bus %04x:%02x has %d slot%s\n",
1705 pci_domain_nr(bridge->pci_bus), 1701 pci_domain_nr(bridge->pci_bus),
1706 bridge->pci_bus->number, bridge->nr_slots, 1702 bridge->pci_bus->number, bridge->nr_slots,
@@ -1807,8 +1803,8 @@ u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
1807 1803
1808 1804
1809/* 1805/*
1810 * latch closed: 1 1806 * latch open: 1
1811 * latch open: 0 1807 * latch closed: 0
1812 */ 1808 */
1813u8 acpiphp_get_latch_status(struct acpiphp_slot *slot) 1809u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1814{ 1810{
@@ -1816,7 +1812,7 @@ u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1816 1812
1817 sta = get_slot_status(slot); 1813 sta = get_slot_status(slot);
1818 1814
1819 return (sta & ACPI_STA_SHOW_IN_UI) ? 1 : 0; 1815 return (sta & ACPI_STA_SHOW_IN_UI) ? 0 : 1;
1820} 1816}
1821 1817
1822 1818
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index d0a07d9ab30c..bd40aee10e16 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -35,7 +35,6 @@
35#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
36 36
37#include "acpiphp.h" 37#include "acpiphp.h"
38#include "pci_hotplug.h"
39 38
40#define DRIVER_VERSION "1.0.1" 39#define DRIVER_VERSION "1.0.1"
41#define DRIVER_AUTHOR "Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>" 40#define DRIVER_AUTHOR "Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c
index d06ab4045134..684551559d44 100644
--- a/drivers/pci/hotplug/cpci_hotplug_core.c
+++ b/drivers/pci/hotplug/cpci_hotplug_core.c
@@ -29,12 +29,12 @@
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/pci.h> 31#include <linux/pci.h>
32#include <linux/pci_hotplug.h>
32#include <linux/init.h> 33#include <linux/init.h>
33#include <linux/interrupt.h> 34#include <linux/interrupt.h>
34#include <linux/smp_lock.h> 35#include <linux/smp_lock.h>
35#include <asm/atomic.h> 36#include <asm/atomic.h>
36#include <linux/delay.h> 37#include <linux/delay.h>
37#include "pci_hotplug.h"
38#include "cpci_hotplug.h" 38#include "cpci_hotplug.h"
39 39
40#define DRIVER_AUTHOR "Scott Murray <scottm@somanetworks.com>" 40#define DRIVER_AUTHOR "Scott Murray <scottm@somanetworks.com>"
diff --git a/drivers/pci/hotplug/cpci_hotplug_pci.c b/drivers/pci/hotplug/cpci_hotplug_pci.c
index 4afcaffd031c..7b1beaad2752 100644
--- a/drivers/pci/hotplug/cpci_hotplug_pci.c
+++ b/drivers/pci/hotplug/cpci_hotplug_pci.c
@@ -26,9 +26,9 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/pci_hotplug.h>
29#include <linux/proc_fs.h> 30#include <linux/proc_fs.h>
30#include "../pci.h" 31#include "../pci.h"
31#include "pci_hotplug.h"
32#include "cpci_hotplug.h" 32#include "cpci_hotplug.h"
33 33
34#define MY_NAME "cpci_hotplug" 34#define MY_NAME "cpci_hotplug"
diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
index e847f0d6c7fe..f3852a6b74ea 100644
--- a/drivers/pci/hotplug/cpcihp_generic.c
+++ b/drivers/pci/hotplug/cpcihp_generic.c
@@ -84,7 +84,7 @@ static int __init validate_parameters(void)
84 84
85 if(!bridge) { 85 if(!bridge) {
86 info("not configured, disabling."); 86 info("not configured, disabling.");
87 return 1; 87 return -EINVAL;
88 } 88 }
89 str = bridge; 89 str = bridge;
90 if(!*str) 90 if(!*str)
@@ -147,7 +147,7 @@ static int __init cpcihp_generic_init(void)
147 147
148 info(DRIVER_DESC " version: " DRIVER_VERSION); 148 info(DRIVER_DESC " version: " DRIVER_VERSION);
149 status = validate_parameters(); 149 status = validate_parameters();
150 if(status != 0) 150 if (status)
151 return status; 151 return status;
152 152
153 r = request_region(port, 1, "#ENUM hotswap signal register"); 153 r = request_region(port, 1, "#ENUM hotswap signal register");
diff --git a/drivers/pci/hotplug/cpqphp.h b/drivers/pci/hotplug/cpqphp.h
index ea040c32f47d..298ad7f3f4f4 100644
--- a/drivers/pci/hotplug/cpqphp.h
+++ b/drivers/pci/hotplug/cpqphp.h
@@ -28,7 +28,6 @@
28#ifndef _CPQPHP_H 28#ifndef _CPQPHP_H
29#define _CPQPHP_H 29#define _CPQPHP_H
30 30
31#include "pci_hotplug.h"
32#include <linux/interrupt.h> 31#include <linux/interrupt.h>
33#include <asm/io.h> /* for read? and write? functions */ 32#include <asm/io.h> /* for read? and write? functions */
34#include <linux/delay.h> /* for delays */ 33#include <linux/delay.h> /* for delays */
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index 1fc259913b68..5617cfdadc5c 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -37,6 +37,7 @@
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/workqueue.h> 38#include <linux/workqueue.h>
39#include <linux/pci.h> 39#include <linux/pci.h>
40#include <linux/pci_hotplug.h>
40#include <linux/init.h> 41#include <linux/init.h>
41#include <linux/interrupt.h> 42#include <linux/interrupt.h>
42 43
diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
index 3ec2ad7db49a..79ff6b4de3a6 100644
--- a/drivers/pci/hotplug/cpqphp_ctrl.c
+++ b/drivers/pci/hotplug/cpqphp_ctrl.c
@@ -36,6 +36,7 @@
36#include <linux/wait.h> 36#include <linux/wait.h>
37#include <linux/smp_lock.h> 37#include <linux/smp_lock.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/pci_hotplug.h>
39#include "cpqphp.h" 40#include "cpqphp.h"
40 41
41static u32 configure_new_device(struct controller* ctrl, struct pci_func *func, 42static u32 configure_new_device(struct controller* ctrl, struct pci_func *func,
diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
index cf0878917537..298a6cfd8406 100644
--- a/drivers/pci/hotplug/cpqphp_nvram.c
+++ b/drivers/pci/hotplug/cpqphp_nvram.c
@@ -33,6 +33,7 @@
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/workqueue.h> 34#include <linux/workqueue.h>
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/pci_hotplug.h>
36#include <linux/init.h> 37#include <linux/init.h>
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
38#include "cpqphp.h" 39#include "cpqphp.h"
diff --git a/drivers/pci/hotplug/cpqphp_pci.c b/drivers/pci/hotplug/cpqphp_pci.c
index 0d9688952f4a..fc7c74d72595 100644
--- a/drivers/pci/hotplug/cpqphp_pci.c
+++ b/drivers/pci/hotplug/cpqphp_pci.c
@@ -33,6 +33,7 @@
33#include <linux/workqueue.h> 33#include <linux/workqueue.h>
34#include <linux/proc_fs.h> 34#include <linux/proc_fs.h>
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/pci_hotplug.h>
36#include "../pci.h" 37#include "../pci.h"
37#include "cpqphp.h" 38#include "cpqphp.h"
38#include "cpqphp_nvram.h" 39#include "cpqphp_nvram.h"
diff --git a/drivers/pci/hotplug/cpqphp_sysfs.c b/drivers/pci/hotplug/cpqphp_sysfs.c
index 5bab666cd67e..634f74d919d3 100644
--- a/drivers/pci/hotplug/cpqphp_sysfs.c
+++ b/drivers/pci/hotplug/cpqphp_sysfs.c
@@ -32,6 +32,7 @@
32#include <linux/proc_fs.h> 32#include <linux/proc_fs.h>
33#include <linux/workqueue.h> 33#include <linux/workqueue.h>
34#include <linux/pci.h> 34#include <linux/pci.h>
35#include <linux/pci_hotplug.h>
35#include <linux/debugfs.h> 36#include <linux/debugfs.h>
36#include "cpqphp.h" 37#include "cpqphp.h"
37 38
diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
index 05a4f0f90186..e27907c91d92 100644
--- a/drivers/pci/hotplug/fakephp.c
+++ b/drivers/pci/hotplug/fakephp.c
@@ -35,10 +35,10 @@
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/pci.h> 37#include <linux/pci.h>
38#include <linux/pci_hotplug.h>
38#include <linux/init.h> 39#include <linux/init.h>
39#include <linux/string.h> 40#include <linux/string.h>
40#include <linux/slab.h> 41#include <linux/slab.h>
41#include "pci_hotplug.h"
42#include "../pci.h" 42#include "../pci.h"
43 43
44#if !defined(MODULE) 44#if !defined(MODULE)
@@ -181,7 +181,9 @@ static void pci_rescan_slot(struct pci_dev *temp)
181 181
182 if (!pci_read_config_byte(temp, PCI_HEADER_TYPE, &hdr_type)) { 182 if (!pci_read_config_byte(temp, PCI_HEADER_TYPE, &hdr_type)) {
183 temp->hdr_type = hdr_type & 0x7f; 183 temp->hdr_type = hdr_type & 0x7f;
184 if (!pci_find_slot(bus->number, temp->devfn)) { 184 if ((dev = pci_get_slot(bus, temp->devfn)) != NULL)
185 pci_dev_put(dev);
186 else {
185 dev = pci_scan_single_device(bus, temp->devfn); 187 dev = pci_scan_single_device(bus, temp->devfn);
186 if (dev) { 188 if (dev) {
187 dbg("New device on %s function %x:%x\n", 189 dbg("New device on %s function %x:%x\n",
@@ -205,7 +207,9 @@ static void pci_rescan_slot(struct pci_dev *temp)
205 continue; 207 continue;
206 temp->hdr_type = hdr_type & 0x7f; 208 temp->hdr_type = hdr_type & 0x7f;
207 209
208 if (!pci_find_slot(bus->number, temp->devfn)) { 210 if ((dev = pci_get_slot(bus, temp->devfn)) != NULL)
211 pci_dev_put(dev);
212 else {
209 dev = pci_scan_single_device(bus, temp->devfn); 213 dev = pci_scan_single_device(bus, temp->devfn);
210 if (dev) { 214 if (dev) {
211 dbg("New device on %s function %x:%x\n", 215 dbg("New device on %s function %x:%x\n",
@@ -305,7 +309,7 @@ static int disable_slot(struct hotplug_slot *slot)
305 /* search for subfunctions and disable them first */ 309 /* search for subfunctions and disable them first */
306 if (!(dslot->dev->devfn & 7)) { 310 if (!(dslot->dev->devfn & 7)) {
307 for (func = 1; func < 8; func++) { 311 for (func = 1; func < 8; func++) {
308 dev = pci_find_slot(dslot->dev->bus->number, 312 dev = pci_get_slot(dslot->dev->bus,
309 dslot->dev->devfn + func); 313 dslot->dev->devfn + func);
310 if (dev) { 314 if (dev) {
311 hslot = get_slot_from_dev(dev); 315 hslot = get_slot_from_dev(dev);
@@ -315,6 +319,7 @@ static int disable_slot(struct hotplug_slot *slot)
315 err("Hotplug slot not found for subfunction of PCI device\n"); 319 err("Hotplug slot not found for subfunction of PCI device\n");
316 return -ENODEV; 320 return -ENODEV;
317 } 321 }
322 pci_dev_put(dev);
318 } else 323 } else
319 dbg("No device in slot found\n"); 324 dbg("No device in slot found\n");
320 } 325 }
diff --git a/drivers/pci/hotplug/ibmphp.h b/drivers/pci/hotplug/ibmphp.h
index dba6d8ca9bda..612d96301509 100644
--- a/drivers/pci/hotplug/ibmphp.h
+++ b/drivers/pci/hotplug/ibmphp.h
@@ -30,7 +30,7 @@
30 * 30 *
31 */ 31 */
32 32
33#include "pci_hotplug.h" 33#include <linux/pci_hotplug.h>
34 34
35extern int ibmphp_debug; 35extern int ibmphp_debug;
36 36
diff --git a/drivers/pci/hotplug/ibmphp_hpc.c b/drivers/pci/hotplug/ibmphp_hpc.c
index c3ac98a0a6a6..f55ac3885cb3 100644
--- a/drivers/pci/hotplug/ibmphp_hpc.c
+++ b/drivers/pci/hotplug/ibmphp_hpc.c
@@ -531,7 +531,7 @@ static u8 hpc_readcmdtoindex (u8 cmd, u8 index)
531* 531*
532* Action: issue a READ command to HPC 532* Action: issue a READ command to HPC
533* 533*
534* Input: pslot - can not be NULL for READ_ALLSTAT 534* Input: pslot - cannot be NULL for READ_ALLSTAT
535* pstatus - can be NULL for READ_ALLSTAT 535* pstatus - can be NULL for READ_ALLSTAT
536* 536*
537* Return 0 or error codes 537* Return 0 or error codes
diff --git a/drivers/pci/hotplug/ibmphp_pci.c b/drivers/pci/hotplug/ibmphp_pci.c
index d87a9e3eaeeb..d8f05d7a3c72 100644
--- a/drivers/pci/hotplug/ibmphp_pci.c
+++ b/drivers/pci/hotplug/ibmphp_pci.c
@@ -1371,12 +1371,12 @@ static int unconfigure_boot_bridge (u8 busno, u8 device, u8 function)
1371 } 1371 }
1372 1372
1373 bus = ibmphp_find_res_bus (sec_number); 1373 bus = ibmphp_find_res_bus (sec_number);
1374 debug ("bus->busno is %x\n", bus->busno);
1375 debug ("sec_number is %x\n", sec_number);
1376 if (!bus) { 1374 if (!bus) {
1377 err ("cannot find Bus structure for the bridged device\n"); 1375 err ("cannot find Bus structure for the bridged device\n");
1378 return -EINVAL; 1376 return -EINVAL;
1379 } 1377 }
1378 debug("bus->busno is %x\n", bus->busno);
1379 debug("sec_number is %x\n", sec_number);
1380 1380
1381 ibmphp_remove_bus (bus, busno); 1381 ibmphp_remove_bus (bus, busno);
1382 1382
diff --git a/drivers/pci/hotplug/pci_hotplug.h b/drivers/pci/hotplug/pci_hotplug.h
deleted file mode 100644
index 772523dc3860..000000000000
--- a/drivers/pci/hotplug/pci_hotplug.h
+++ /dev/null
@@ -1,236 +0,0 @@
1/*
2 * PCI HotPlug Core Functions
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 *
8 * All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18 * NON INFRINGEMENT. See the GNU General Public License for more
19 * details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * Send feedback to <greg@kroah.com>
26 *
27 */
28#ifndef _PCI_HOTPLUG_H
29#define _PCI_HOTPLUG_H
30
31
32/* These values come from the PCI Hotplug Spec */
33enum pci_bus_speed {
34 PCI_SPEED_33MHz = 0x00,
35 PCI_SPEED_66MHz = 0x01,
36 PCI_SPEED_66MHz_PCIX = 0x02,
37 PCI_SPEED_100MHz_PCIX = 0x03,
38 PCI_SPEED_133MHz_PCIX = 0x04,
39 PCI_SPEED_66MHz_PCIX_ECC = 0x05,
40 PCI_SPEED_100MHz_PCIX_ECC = 0x06,
41 PCI_SPEED_133MHz_PCIX_ECC = 0x07,
42 PCI_SPEED_66MHz_PCIX_266 = 0x09,
43 PCI_SPEED_100MHz_PCIX_266 = 0x0a,
44 PCI_SPEED_133MHz_PCIX_266 = 0x0b,
45 PCI_SPEED_66MHz_PCIX_533 = 0x11,
46 PCI_SPEED_100MHz_PCIX_533 = 0x12,
47 PCI_SPEED_133MHz_PCIX_533 = 0x13,
48 PCI_SPEED_UNKNOWN = 0xff,
49};
50
51/* These values come from the PCI Express Spec */
52enum pcie_link_width {
53 PCIE_LNK_WIDTH_RESRV = 0x00,
54 PCIE_LNK_X1 = 0x01,
55 PCIE_LNK_X2 = 0x02,
56 PCIE_LNK_X4 = 0x04,
57 PCIE_LNK_X8 = 0x08,
58 PCIE_LNK_X12 = 0x0C,
59 PCIE_LNK_X16 = 0x10,
60 PCIE_LNK_X32 = 0x20,
61 PCIE_LNK_WIDTH_UNKNOWN = 0xFF,
62};
63
64enum pcie_link_speed {
65 PCIE_2PT5GB = 0x14,
66 PCIE_LNK_SPEED_UNKNOWN = 0xFF,
67};
68
69struct hotplug_slot;
70struct hotplug_slot_attribute {
71 struct attribute attr;
72 ssize_t (*show)(struct hotplug_slot *, char *);
73 ssize_t (*store)(struct hotplug_slot *, const char *, size_t);
74};
75#define to_hotplug_attr(n) container_of(n, struct hotplug_slot_attribute, attr);
76
77/**
78 * struct hotplug_slot_ops -the callbacks that the hotplug pci core can use
79 * @owner: The module owner of this structure
80 * @enable_slot: Called when the user wants to enable a specific pci slot
81 * @disable_slot: Called when the user wants to disable a specific pci slot
82 * @set_attention_status: Called to set the specific slot's attention LED to
83 * the specified value
84 * @hardware_test: Called to run a specified hardware test on the specified
85 * slot.
86 * @get_power_status: Called to get the current power status of a slot.
87 * If this field is NULL, the value passed in the struct hotplug_slot_info
88 * will be used when this value is requested by a user.
89 * @get_attention_status: Called to get the current attention status of a slot.
90 * If this field is NULL, the value passed in the struct hotplug_slot_info
91 * will be used when this value is requested by a user.
92 * @get_latch_status: Called to get the current latch status of a slot.
93 * If this field is NULL, the value passed in the struct hotplug_slot_info
94 * will be used when this value is requested by a user.
95 * @get_adapter_status: Called to get see if an adapter is present in the slot or not.
96 * If this field is NULL, the value passed in the struct hotplug_slot_info
97 * will be used when this value is requested by a user.
98 * @get_address: Called to get pci address of a slot.
99 * If this field is NULL, the value passed in the struct hotplug_slot_info
100 * will be used when this value is requested by a user.
101 * @get_max_bus_speed: Called to get the max bus speed for a slot.
102 * If this field is NULL, the value passed in the struct hotplug_slot_info
103 * will be used when this value is requested by a user.
104 * @get_cur_bus_speed: Called to get the current bus speed for a slot.
105 * If this field is NULL, the value passed in the struct hotplug_slot_info
106 * will be used when this value is requested by a user.
107 *
108 * The table of function pointers that is passed to the hotplug pci core by a
109 * hotplug pci driver. These functions are called by the hotplug pci core when
110 * the user wants to do something to a specific slot (query it for information,
111 * set an LED, enable / disable power, etc.)
112 */
113struct hotplug_slot_ops {
114 struct module *owner;
115 int (*enable_slot) (struct hotplug_slot *slot);
116 int (*disable_slot) (struct hotplug_slot *slot);
117 int (*set_attention_status) (struct hotplug_slot *slot, u8 value);
118 int (*hardware_test) (struct hotplug_slot *slot, u32 value);
119 int (*get_power_status) (struct hotplug_slot *slot, u8 *value);
120 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
121 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
122 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
123 int (*get_address) (struct hotplug_slot *slot, u32 *value);
124 int (*get_max_bus_speed) (struct hotplug_slot *slot, enum pci_bus_speed *value);
125 int (*get_cur_bus_speed) (struct hotplug_slot *slot, enum pci_bus_speed *value);
126};
127
128/**
129 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
130 * @power: if power is enabled or not (1/0)
131 * @attention_status: if the attention light is enabled or not (1/0)
132 * @latch_status: if the latch (if any) is open or closed (1/0)
133 * @adapter_present: if there is a pci board present in the slot or not (1/0)
134 * @address: (domain << 16 | bus << 8 | dev)
135 *
136 * Used to notify the hotplug pci core of the status of a specific slot.
137 */
138struct hotplug_slot_info {
139 u8 power_status;
140 u8 attention_status;
141 u8 latch_status;
142 u8 adapter_status;
143 u32 address;
144 enum pci_bus_speed max_bus_speed;
145 enum pci_bus_speed cur_bus_speed;
146};
147
148/**
149 * struct hotplug_slot - used to register a physical slot with the hotplug pci core
150 * @name: the name of the slot being registered. This string must
151 * be unique amoung slots registered on this system.
152 * @ops: pointer to the &struct hotplug_slot_ops to be used for this slot
153 * @info: pointer to the &struct hotplug_slot_info for the initial values for
154 * this slot.
155 * @release: called during pci_hp_deregister to free memory allocated in a
156 * hotplug_slot structure.
157 * @private: used by the hotplug pci controller driver to store whatever it
158 * needs.
159 */
160struct hotplug_slot {
161 char *name;
162 struct hotplug_slot_ops *ops;
163 struct hotplug_slot_info *info;
164 void (*release) (struct hotplug_slot *slot);
165 void *private;
166
167 /* Variables below this are for use only by the hotplug pci core. */
168 struct list_head slot_list;
169 struct kobject kobj;
170};
171#define to_hotplug_slot(n) container_of(n, struct hotplug_slot, kobj)
172
173extern int pci_hp_register (struct hotplug_slot *slot);
174extern int pci_hp_deregister (struct hotplug_slot *slot);
175extern int __must_check pci_hp_change_slot_info (struct hotplug_slot *slot,
176 struct hotplug_slot_info *info);
177extern struct subsystem pci_hotplug_slots_subsys;
178
179/* PCI Setting Record (Type 0) */
180struct hpp_type0 {
181 u32 revision;
182 u8 cache_line_size;
183 u8 latency_timer;
184 u8 enable_serr;
185 u8 enable_perr;
186};
187
188/* PCI-X Setting Record (Type 1) */
189struct hpp_type1 {
190 u32 revision;
191 u8 max_mem_read;
192 u8 avg_max_split;
193 u16 tot_max_split;
194};
195
196/* PCI Express Setting Record (Type 2) */
197struct hpp_type2 {
198 u32 revision;
199 u32 unc_err_mask_and;
200 u32 unc_err_mask_or;
201 u32 unc_err_sever_and;
202 u32 unc_err_sever_or;
203 u32 cor_err_mask_and;
204 u32 cor_err_mask_or;
205 u32 adv_err_cap_and;
206 u32 adv_err_cap_or;
207 u16 pci_exp_devctl_and;
208 u16 pci_exp_devctl_or;
209 u16 pci_exp_lnkctl_and;
210 u16 pci_exp_lnkctl_or;
211 u32 sec_unc_err_sever_and;
212 u32 sec_unc_err_sever_or;
213 u32 sec_unc_err_mask_and;
214 u32 sec_unc_err_mask_or;
215};
216
217struct hotplug_params {
218 struct hpp_type0 *t0; /* Type0: NULL if not available */
219 struct hpp_type1 *t1; /* Type1: NULL if not available */
220 struct hpp_type2 *t2; /* Type2: NULL if not available */
221 struct hpp_type0 type0_data;
222 struct hpp_type1 type1_data;
223 struct hpp_type2 type2_data;
224};
225
226#ifdef CONFIG_ACPI
227#include <acpi/acpi.h>
228#include <acpi/acpi_bus.h>
229#include <acpi/actypes.h>
230extern acpi_status acpi_run_oshp(acpi_handle handle);
231extern acpi_status acpi_get_hp_params_from_firmware(struct pci_bus *bus,
232 struct hotplug_params *hpp);
233int acpi_root_bridge(acpi_handle handle);
234#endif
235#endif
236
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index e2823ea9c4ed..f5d632e72323 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -21,9 +21,7 @@
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * 23 *
24 * Send feedback to <greg@kroah.com> 24 * Send feedback to <kristen.c.accardi@intel.com>
25 *
26 * Filesystem portion based on work done by Pat Mochel on ddfs/driverfs
27 * 25 *
28 */ 26 */
29 27
@@ -32,6 +30,8 @@
32#include <linux/kernel.h> 30#include <linux/kernel.h>
33#include <linux/types.h> 31#include <linux/types.h>
34#include <linux/list.h> 32#include <linux/list.h>
33#include <linux/kobject.h>
34#include <linux/sysfs.h>
35#include <linux/pagemap.h> 35#include <linux/pagemap.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/smp_lock.h> 37#include <linux/smp_lock.h>
@@ -39,11 +39,8 @@
39#include <linux/mount.h> 39#include <linux/mount.h>
40#include <linux/namei.h> 40#include <linux/namei.h>
41#include <linux/pci.h> 41#include <linux/pci.h>
42#include <linux/pci_hotplug.h>
42#include <asm/uaccess.h> 43#include <asm/uaccess.h>
43#include <linux/kobject.h>
44#include <linux/sysfs.h>
45#include "pci_hotplug.h"
46
47 44
48#define MY_NAME "pci_hotplug" 45#define MY_NAME "pci_hotplug"
49 46
diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
index eaea9d36a1bb..4fb12fcda563 100644
--- a/drivers/pci/hotplug/pciehp.h
+++ b/drivers/pci/hotplug/pciehp.h
@@ -31,11 +31,11 @@
31 31
32#include <linux/types.h> 32#include <linux/types.h>
33#include <linux/pci.h> 33#include <linux/pci.h>
34#include <linux/pci_hotplug.h>
34#include <linux/delay.h> 35#include <linux/delay.h>
35#include <linux/sched.h> /* signal_pending() */ 36#include <linux/sched.h> /* signal_pending() */
36#include <linux/pcieport_if.h> 37#include <linux/pcieport_if.h>
37#include <linux/mutex.h> 38#include <linux/mutex.h>
38#include "pci_hotplug.h"
39 39
40#define MY_NAME "pciehp" 40#define MY_NAME "pciehp"
41 41
@@ -92,6 +92,7 @@ struct php_ctlr_state_s {
92struct controller { 92struct controller {
93 struct controller *next; 93 struct controller *next;
94 struct mutex crit_sect; /* critical section mutex */ 94 struct mutex crit_sect; /* critical section mutex */
95 struct mutex ctrl_lock; /* controller lock */
95 struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */ 96 struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */
96 int num_slots; /* Number of slots on ctlr */ 97 int num_slots; /* Number of slots on ctlr */
97 int slot_num_inc; /* 1 or -1 */ 98 int slot_num_inc; /* 1 or -1 */
@@ -166,10 +167,10 @@ struct controller {
166 * error Messages 167 * error Messages
167 */ 168 */
168#define msg_initialization_err "Initialization failure, error=%d\n" 169#define msg_initialization_err "Initialization failure, error=%d\n"
169#define msg_button_on "PCI slot #%d - powering on due to button press.\n" 170#define msg_button_on "PCI slot #%s - powering on due to button press.\n"
170#define msg_button_off "PCI slot #%d - powering off due to button press.\n" 171#define msg_button_off "PCI slot #%s - powering off due to button press.\n"
171#define msg_button_cancel "PCI slot #%d - action canceled due to button press.\n" 172#define msg_button_cancel "PCI slot #%s - action canceled due to button press.\n"
172#define msg_button_ignore "PCI slot #%d - button press ignored. (action in progress...)\n" 173#define msg_button_ignore "PCI slot #%s - button press ignored. (action in progress...)\n"
173 174
174/* controller functions */ 175/* controller functions */
175extern int pciehp_event_start_thread (void); 176extern int pciehp_event_start_thread (void);
diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
index c67b7c3f1ddf..f13f31323e85 100644
--- a/drivers/pci/hotplug/pciehp_core.c
+++ b/drivers/pci/hotplug/pciehp_core.c
@@ -448,7 +448,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
448 } 448 }
449 449
450 /* Wait for exclusive access to hardware */ 450 /* Wait for exclusive access to hardware */
451 mutex_lock(&ctrl->crit_sect); 451 mutex_lock(&ctrl->ctrl_lock);
452 452
453 t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */ 453 t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */
454 454
@@ -456,7 +456,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
456 rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/ 456 rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/
457 if (rc) { 457 if (rc) {
458 /* Done with exclusive hardware access */ 458 /* Done with exclusive hardware access */
459 mutex_unlock(&ctrl->crit_sect); 459 mutex_unlock(&ctrl->ctrl_lock);
460 goto err_out_free_ctrl_slot; 460 goto err_out_free_ctrl_slot;
461 } else 461 } else
462 /* Wait for the command to complete */ 462 /* Wait for the command to complete */
@@ -464,7 +464,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
464 } 464 }
465 465
466 /* Done with exclusive hardware access */ 466 /* Done with exclusive hardware access */
467 mutex_unlock(&ctrl->crit_sect); 467 mutex_unlock(&ctrl->ctrl_lock);
468 468
469 return 0; 469 return 0;
470 470
@@ -521,14 +521,9 @@ static void __exit unload_pciehpd(void)
521 521
522} 522}
523 523
524static int hpdriver_context = 0;
525
526static void pciehp_remove (struct pcie_device *device) 524static void pciehp_remove (struct pcie_device *device)
527{ 525{
528 printk("%s ENTRY\n", __FUNCTION__); 526 /* XXX - Needs to be adapted to device driver model */
529 printk("%s -> Call free_irq for irq = %d\n",
530 __FUNCTION__, device->irq);
531 free_irq(device->irq, &hpdriver_context);
532} 527}
533 528
534#ifdef CONFIG_PM 529#ifdef CONFIG_PM
diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
index 41290a106bd8..372c63e35aa9 100644
--- a/drivers/pci/hotplug/pciehp_ctrl.c
+++ b/drivers/pci/hotplug/pciehp_ctrl.c
@@ -43,6 +43,11 @@ static int event_finished;
43static unsigned long pushbutton_pending; /* = 0 */ 43static unsigned long pushbutton_pending; /* = 0 */
44static unsigned long surprise_rm_pending; /* = 0 */ 44static unsigned long surprise_rm_pending; /* = 0 */
45 45
46static inline char *slot_name(struct slot *p_slot)
47{
48 return p_slot->hotplug_slot->name;
49}
50
46u8 pciehp_handle_attention_button(u8 hp_slot, void *inst_id) 51u8 pciehp_handle_attention_button(u8 hp_slot, void *inst_id)
47{ 52{
48 struct controller *ctrl = (struct controller *) inst_id; 53 struct controller *ctrl = (struct controller *) inst_id;
@@ -68,7 +73,7 @@ u8 pciehp_handle_attention_button(u8 hp_slot, void *inst_id)
68 /* 73 /*
69 * Button pressed - See if need to TAKE ACTION!!! 74 * Button pressed - See if need to TAKE ACTION!!!
70 */ 75 */
71 info("Button pressed on Slot(%d)\n", ctrl->first_slot + hp_slot); 76 info("Button pressed on Slot(%s)\n", slot_name(p_slot));
72 taskInfo->event_type = INT_BUTTON_PRESS; 77 taskInfo->event_type = INT_BUTTON_PRESS;
73 78
74 if ((p_slot->state == BLINKINGON_STATE) 79 if ((p_slot->state == BLINKINGON_STATE)
@@ -78,7 +83,7 @@ u8 pciehp_handle_attention_button(u8 hp_slot, void *inst_id)
78 * or hot-remove 83 * or hot-remove
79 */ 84 */
80 taskInfo->event_type = INT_BUTTON_CANCEL; 85 taskInfo->event_type = INT_BUTTON_CANCEL;
81 info("Button cancel on Slot(%d)\n", ctrl->first_slot + hp_slot); 86 info("Button cancel on Slot(%s)\n", slot_name(p_slot));
82 } else if ((p_slot->state == POWERON_STATE) 87 } else if ((p_slot->state == POWERON_STATE)
83 || (p_slot->state == POWEROFF_STATE)) { 88 || (p_slot->state == POWEROFF_STATE)) {
84 /* Ignore if the slot is on power-on or power-off state; this 89 /* Ignore if the slot is on power-on or power-off state; this
@@ -86,7 +91,7 @@ u8 pciehp_handle_attention_button(u8 hp_slot, void *inst_id)
86 * hot-remove is undergoing 91 * hot-remove is undergoing
87 */ 92 */
88 taskInfo->event_type = INT_BUTTON_IGNORE; 93 taskInfo->event_type = INT_BUTTON_IGNORE;
89 info("Button ignore on Slot(%d)\n", ctrl->first_slot + hp_slot); 94 info("Button ignore on Slot(%s)\n", slot_name(p_slot));
90 } 95 }
91 96
92 if (rc) 97 if (rc)
@@ -122,13 +127,13 @@ u8 pciehp_handle_switch_change(u8 hp_slot, void *inst_id)
122 /* 127 /*
123 * Switch opened 128 * Switch opened
124 */ 129 */
125 info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot); 130 info("Latch open on Slot(%s)\n", slot_name(p_slot));
126 taskInfo->event_type = INT_SWITCH_OPEN; 131 taskInfo->event_type = INT_SWITCH_OPEN;
127 } else { 132 } else {
128 /* 133 /*
129 * Switch closed 134 * Switch closed
130 */ 135 */
131 info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot); 136 info("Latch close on Slot(%s)\n", slot_name(p_slot));
132 taskInfo->event_type = INT_SWITCH_CLOSE; 137 taskInfo->event_type = INT_SWITCH_CLOSE;
133 } 138 }
134 139
@@ -166,13 +171,13 @@ u8 pciehp_handle_presence_change(u8 hp_slot, void *inst_id)
166 /* 171 /*
167 * Card Present 172 * Card Present
168 */ 173 */
169 info("Card present on Slot(%d)\n", ctrl->first_slot + hp_slot); 174 info("Card present on Slot(%s)\n", slot_name(p_slot));
170 taskInfo->event_type = INT_PRESENCE_ON; 175 taskInfo->event_type = INT_PRESENCE_ON;
171 } else { 176 } else {
172 /* 177 /*
173 * Not Present 178 * Not Present
174 */ 179 */
175 info("Card not present on Slot(%d)\n", ctrl->first_slot + hp_slot); 180 info("Card not present on Slot(%s)\n", slot_name(p_slot));
176 taskInfo->event_type = INT_PRESENCE_OFF; 181 taskInfo->event_type = INT_PRESENCE_OFF;
177 } 182 }
178 183
@@ -206,13 +211,13 @@ u8 pciehp_handle_power_fault(u8 hp_slot, void *inst_id)
206 /* 211 /*
207 * power fault Cleared 212 * power fault Cleared
208 */ 213 */
209 info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot); 214 info("Power fault cleared on Slot(%s)\n", slot_name(p_slot));
210 taskInfo->event_type = INT_POWER_FAULT_CLEAR; 215 taskInfo->event_type = INT_POWER_FAULT_CLEAR;
211 } else { 216 } else {
212 /* 217 /*
213 * power fault 218 * power fault
214 */ 219 */
215 info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot); 220 info("Power fault on Slot(%s)\n", slot_name(p_slot));
216 taskInfo->event_type = INT_POWER_FAULT; 221 taskInfo->event_type = INT_POWER_FAULT;
217 info("power fault bit %x set\n", hp_slot); 222 info("power fault bit %x set\n", hp_slot);
218 } 223 }
@@ -229,13 +234,13 @@ u8 pciehp_handle_power_fault(u8 hp_slot, void *inst_id)
229static void set_slot_off(struct controller *ctrl, struct slot * pslot) 234static void set_slot_off(struct controller *ctrl, struct slot * pslot)
230{ 235{
231 /* Wait for exclusive access to hardware */ 236 /* Wait for exclusive access to hardware */
232 mutex_lock(&ctrl->crit_sect); 237 mutex_lock(&ctrl->ctrl_lock);
233 238
234 /* turn off slot, turn on Amber LED, turn off Green LED if supported*/ 239 /* turn off slot, turn on Amber LED, turn off Green LED if supported*/
235 if (POWER_CTRL(ctrl->ctrlcap)) { 240 if (POWER_CTRL(ctrl->ctrlcap)) {
236 if (pslot->hpc_ops->power_off_slot(pslot)) { 241 if (pslot->hpc_ops->power_off_slot(pslot)) {
237 err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__); 242 err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__);
238 mutex_unlock(&ctrl->crit_sect); 243 mutex_unlock(&ctrl->ctrl_lock);
239 return; 244 return;
240 } 245 }
241 wait_for_ctrl_irq (ctrl); 246 wait_for_ctrl_irq (ctrl);
@@ -249,14 +254,14 @@ static void set_slot_off(struct controller *ctrl, struct slot * pslot)
249 if (ATTN_LED(ctrl->ctrlcap)) { 254 if (ATTN_LED(ctrl->ctrlcap)) {
250 if (pslot->hpc_ops->set_attention_status(pslot, 1)) { 255 if (pslot->hpc_ops->set_attention_status(pslot, 1)) {
251 err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__); 256 err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__);
252 mutex_unlock(&ctrl->crit_sect); 257 mutex_unlock(&ctrl->ctrl_lock);
253 return; 258 return;
254 } 259 }
255 wait_for_ctrl_irq (ctrl); 260 wait_for_ctrl_irq (ctrl);
256 } 261 }
257 262
258 /* Done with exclusive hardware access */ 263 /* Done with exclusive hardware access */
259 mutex_unlock(&ctrl->crit_sect); 264 mutex_unlock(&ctrl->ctrl_lock);
260} 265}
261 266
262/** 267/**
@@ -279,13 +284,13 @@ static int board_added(struct slot *p_slot)
279 ctrl->slot_device_offset, hp_slot); 284 ctrl->slot_device_offset, hp_slot);
280 285
281 /* Wait for exclusive access to hardware */ 286 /* Wait for exclusive access to hardware */
282 mutex_lock(&ctrl->crit_sect); 287 mutex_lock(&ctrl->ctrl_lock);
283 288
284 if (POWER_CTRL(ctrl->ctrlcap)) { 289 if (POWER_CTRL(ctrl->ctrlcap)) {
285 /* Power on slot */ 290 /* Power on slot */
286 rc = p_slot->hpc_ops->power_on_slot(p_slot); 291 rc = p_slot->hpc_ops->power_on_slot(p_slot);
287 if (rc) { 292 if (rc) {
288 mutex_unlock(&ctrl->crit_sect); 293 mutex_unlock(&ctrl->ctrl_lock);
289 return -1; 294 return -1;
290 } 295 }
291 296
@@ -301,7 +306,7 @@ static int board_added(struct slot *p_slot)
301 } 306 }
302 307
303 /* Done with exclusive hardware access */ 308 /* Done with exclusive hardware access */
304 mutex_unlock(&ctrl->crit_sect); 309 mutex_unlock(&ctrl->ctrl_lock);
305 310
306 /* Wait for ~1 second */ 311 /* Wait for ~1 second */
307 wait_for_ctrl_irq (ctrl); 312 wait_for_ctrl_irq (ctrl);
@@ -335,7 +340,7 @@ static int board_added(struct slot *p_slot)
335 pci_fixup_device(pci_fixup_final, ctrl->pci_dev); 340 pci_fixup_device(pci_fixup_final, ctrl->pci_dev);
336 if (PWR_LED(ctrl->ctrlcap)) { 341 if (PWR_LED(ctrl->ctrlcap)) {
337 /* Wait for exclusive access to hardware */ 342 /* Wait for exclusive access to hardware */
338 mutex_lock(&ctrl->crit_sect); 343 mutex_lock(&ctrl->ctrl_lock);
339 344
340 p_slot->hpc_ops->green_led_on(p_slot); 345 p_slot->hpc_ops->green_led_on(p_slot);
341 346
@@ -343,7 +348,7 @@ static int board_added(struct slot *p_slot)
343 wait_for_ctrl_irq (ctrl); 348 wait_for_ctrl_irq (ctrl);
344 349
345 /* Done with exclusive hardware access */ 350 /* Done with exclusive hardware access */
346 mutex_unlock(&ctrl->crit_sect); 351 mutex_unlock(&ctrl->ctrl_lock);
347 } 352 }
348 return 0; 353 return 0;
349 354
@@ -375,14 +380,14 @@ static int remove_board(struct slot *p_slot)
375 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot); 380 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
376 381
377 /* Wait for exclusive access to hardware */ 382 /* Wait for exclusive access to hardware */
378 mutex_lock(&ctrl->crit_sect); 383 mutex_lock(&ctrl->ctrl_lock);
379 384
380 if (POWER_CTRL(ctrl->ctrlcap)) { 385 if (POWER_CTRL(ctrl->ctrlcap)) {
381 /* power off slot */ 386 /* power off slot */
382 rc = p_slot->hpc_ops->power_off_slot(p_slot); 387 rc = p_slot->hpc_ops->power_off_slot(p_slot);
383 if (rc) { 388 if (rc) {
384 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); 389 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
385 mutex_unlock(&ctrl->crit_sect); 390 mutex_unlock(&ctrl->ctrl_lock);
386 return rc; 391 return rc;
387 } 392 }
388 /* Wait for the command to complete */ 393 /* Wait for the command to complete */
@@ -398,7 +403,7 @@ static int remove_board(struct slot *p_slot)
398 } 403 }
399 404
400 /* Done with exclusive hardware access */ 405 /* Done with exclusive hardware access */
401 mutex_unlock(&ctrl->crit_sect); 406 mutex_unlock(&ctrl->ctrl_lock);
402 407
403 return 0; 408 return 0;
404} 409}
@@ -445,7 +450,7 @@ static void pciehp_pushbutton_thread(unsigned long slot)
445 450
446 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) { 451 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
447 /* Wait for exclusive access to hardware */ 452 /* Wait for exclusive access to hardware */
448 mutex_lock(&p_slot->ctrl->crit_sect); 453 mutex_lock(&p_slot->ctrl->ctrl_lock);
449 454
450 p_slot->hpc_ops->green_led_off(p_slot); 455 p_slot->hpc_ops->green_led_off(p_slot);
451 456
@@ -453,7 +458,7 @@ static void pciehp_pushbutton_thread(unsigned long slot)
453 wait_for_ctrl_irq (p_slot->ctrl); 458 wait_for_ctrl_irq (p_slot->ctrl);
454 459
455 /* Done with exclusive hardware access */ 460 /* Done with exclusive hardware access */
456 mutex_unlock(&p_slot->ctrl->crit_sect); 461 mutex_unlock(&p_slot->ctrl->ctrl_lock);
457 } 462 }
458 p_slot->state = STATIC_STATE; 463 p_slot->state = STATIC_STATE;
459 } 464 }
@@ -495,7 +500,7 @@ static void pciehp_surprise_rm_thread(unsigned long slot)
495 500
496 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) { 501 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
497 /* Wait for exclusive access to hardware */ 502 /* Wait for exclusive access to hardware */
498 mutex_lock(&p_slot->ctrl->crit_sect); 503 mutex_lock(&p_slot->ctrl->ctrl_lock);
499 504
500 p_slot->hpc_ops->green_led_off(p_slot); 505 p_slot->hpc_ops->green_led_off(p_slot);
501 506
@@ -503,7 +508,7 @@ static void pciehp_surprise_rm_thread(unsigned long slot)
503 wait_for_ctrl_irq (p_slot->ctrl); 508 wait_for_ctrl_irq (p_slot->ctrl);
504 509
505 /* Done with exclusive hardware access */ 510 /* Done with exclusive hardware access */
506 mutex_unlock(&p_slot->ctrl->crit_sect); 511 mutex_unlock(&p_slot->ctrl->ctrl_lock);
507 } 512 }
508 p_slot->state = STATIC_STATE; 513 p_slot->state = STATIC_STATE;
509 } 514 }
@@ -616,7 +621,7 @@ static void interrupt_event_handler(struct controller *ctrl)
616 switch (p_slot->state) { 621 switch (p_slot->state) {
617 case BLINKINGOFF_STATE: 622 case BLINKINGOFF_STATE:
618 /* Wait for exclusive access to hardware */ 623 /* Wait for exclusive access to hardware */
619 mutex_lock(&ctrl->crit_sect); 624 mutex_lock(&ctrl->ctrl_lock);
620 625
621 if (PWR_LED(ctrl->ctrlcap)) { 626 if (PWR_LED(ctrl->ctrlcap)) {
622 p_slot->hpc_ops->green_led_on(p_slot); 627 p_slot->hpc_ops->green_led_on(p_slot);
@@ -630,11 +635,11 @@ static void interrupt_event_handler(struct controller *ctrl)
630 wait_for_ctrl_irq (ctrl); 635 wait_for_ctrl_irq (ctrl);
631 } 636 }
632 /* Done with exclusive hardware access */ 637 /* Done with exclusive hardware access */
633 mutex_unlock(&ctrl->crit_sect); 638 mutex_unlock(&ctrl->ctrl_lock);
634 break; 639 break;
635 case BLINKINGON_STATE: 640 case BLINKINGON_STATE:
636 /* Wait for exclusive access to hardware */ 641 /* Wait for exclusive access to hardware */
637 mutex_lock(&ctrl->crit_sect); 642 mutex_lock(&ctrl->ctrl_lock);
638 643
639 if (PWR_LED(ctrl->ctrlcap)) { 644 if (PWR_LED(ctrl->ctrlcap)) {
640 p_slot->hpc_ops->green_led_off(p_slot); 645 p_slot->hpc_ops->green_led_off(p_slot);
@@ -647,14 +652,14 @@ static void interrupt_event_handler(struct controller *ctrl)
647 wait_for_ctrl_irq (ctrl); 652 wait_for_ctrl_irq (ctrl);
648 } 653 }
649 /* Done with exclusive hardware access */ 654 /* Done with exclusive hardware access */
650 mutex_unlock(&ctrl->crit_sect); 655 mutex_unlock(&ctrl->ctrl_lock);
651 656
652 break; 657 break;
653 default: 658 default:
654 warn("Not a valid state\n"); 659 warn("Not a valid state\n");
655 return; 660 return;
656 } 661 }
657 info(msg_button_cancel, p_slot->number); 662 info(msg_button_cancel, slot_name(p_slot));
658 p_slot->state = STATIC_STATE; 663 p_slot->state = STATIC_STATE;
659 } 664 }
660 /* ***********Button Pressed (No action on 1st press...) */ 665 /* ***********Button Pressed (No action on 1st press...) */
@@ -667,16 +672,16 @@ static void interrupt_event_handler(struct controller *ctrl)
667 /* slot is on */ 672 /* slot is on */
668 dbg("slot is on\n"); 673 dbg("slot is on\n");
669 p_slot->state = BLINKINGOFF_STATE; 674 p_slot->state = BLINKINGOFF_STATE;
670 info(msg_button_off, p_slot->number); 675 info(msg_button_off, slot_name(p_slot));
671 } else { 676 } else {
672 /* slot is off */ 677 /* slot is off */
673 dbg("slot is off\n"); 678 dbg("slot is off\n");
674 p_slot->state = BLINKINGON_STATE; 679 p_slot->state = BLINKINGON_STATE;
675 info(msg_button_on, p_slot->number); 680 info(msg_button_on, slot_name(p_slot));
676 } 681 }
677 682
678 /* Wait for exclusive access to hardware */ 683 /* Wait for exclusive access to hardware */
679 mutex_lock(&ctrl->crit_sect); 684 mutex_lock(&ctrl->ctrl_lock);
680 685
681 /* blink green LED and turn off amber */ 686 /* blink green LED and turn off amber */
682 if (PWR_LED(ctrl->ctrlcap)) { 687 if (PWR_LED(ctrl->ctrlcap)) {
@@ -693,7 +698,7 @@ static void interrupt_event_handler(struct controller *ctrl)
693 } 698 }
694 699
695 /* Done with exclusive hardware access */ 700 /* Done with exclusive hardware access */
696 mutex_unlock(&ctrl->crit_sect); 701 mutex_unlock(&ctrl->ctrl_lock);
697 702
698 init_timer(&p_slot->task_event); 703 init_timer(&p_slot->task_event);
699 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */ 704 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
@@ -708,7 +713,7 @@ static void interrupt_event_handler(struct controller *ctrl)
708 if (POWER_CTRL(ctrl->ctrlcap)) { 713 if (POWER_CTRL(ctrl->ctrlcap)) {
709 dbg("power fault\n"); 714 dbg("power fault\n");
710 /* Wait for exclusive access to hardware */ 715 /* Wait for exclusive access to hardware */
711 mutex_lock(&ctrl->crit_sect); 716 mutex_lock(&ctrl->ctrl_lock);
712 717
713 if (ATTN_LED(ctrl->ctrlcap)) { 718 if (ATTN_LED(ctrl->ctrlcap)) {
714 p_slot->hpc_ops->set_attention_status(p_slot, 1); 719 p_slot->hpc_ops->set_attention_status(p_slot, 1);
@@ -721,7 +726,7 @@ static void interrupt_event_handler(struct controller *ctrl)
721 } 726 }
722 727
723 /* Done with exclusive hardware access */ 728 /* Done with exclusive hardware access */
724 mutex_unlock(&ctrl->crit_sect); 729 mutex_unlock(&ctrl->ctrl_lock);
725 } 730 }
726 } 731 }
727 /***********SURPRISE REMOVAL********************/ 732 /***********SURPRISE REMOVAL********************/
@@ -760,14 +765,16 @@ int pciehp_enable_slot(struct slot *p_slot)
760 765
761 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 766 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
762 if (rc || !getstatus) { 767 if (rc || !getstatus) {
763 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); 768 info("%s: no adapter on slot(%s)\n", __FUNCTION__,
769 slot_name(p_slot));
764 mutex_unlock(&p_slot->ctrl->crit_sect); 770 mutex_unlock(&p_slot->ctrl->crit_sect);
765 return -ENODEV; 771 return -ENODEV;
766 } 772 }
767 if (MRL_SENS(p_slot->ctrl->ctrlcap)) { 773 if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
768 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 774 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
769 if (rc || getstatus) { 775 if (rc || getstatus) {
770 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); 776 info("%s: latch open on slot(%s)\n", __FUNCTION__,
777 slot_name(p_slot));
771 mutex_unlock(&p_slot->ctrl->crit_sect); 778 mutex_unlock(&p_slot->ctrl->crit_sect);
772 return -ENODEV; 779 return -ENODEV;
773 } 780 }
@@ -776,12 +783,12 @@ int pciehp_enable_slot(struct slot *p_slot)
776 if (POWER_CTRL(p_slot->ctrl->ctrlcap)) { 783 if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
777 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 784 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
778 if (rc || getstatus) { 785 if (rc || getstatus) {
779 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number); 786 info("%s: already enabled on slot(%s)\n", __FUNCTION__,
787 slot_name(p_slot));
780 mutex_unlock(&p_slot->ctrl->crit_sect); 788 mutex_unlock(&p_slot->ctrl->crit_sect);
781 return -EINVAL; 789 return -EINVAL;
782 } 790 }
783 } 791 }
784 mutex_unlock(&p_slot->ctrl->crit_sect);
785 792
786 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 793 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
787 794
@@ -790,9 +797,9 @@ int pciehp_enable_slot(struct slot *p_slot)
790 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 797 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
791 } 798 }
792 799
793 if (p_slot) 800 update_slot_info(p_slot);
794 update_slot_info(p_slot);
795 801
802 mutex_unlock(&p_slot->ctrl->crit_sect);
796 return rc; 803 return rc;
797} 804}
798 805
@@ -811,7 +818,8 @@ int pciehp_disable_slot(struct slot *p_slot)
811 if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) { 818 if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) {
812 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 819 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
813 if (ret || !getstatus) { 820 if (ret || !getstatus) {
814 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); 821 info("%s: no adapter on slot(%s)\n", __FUNCTION__,
822 slot_name(p_slot));
815 mutex_unlock(&p_slot->ctrl->crit_sect); 823 mutex_unlock(&p_slot->ctrl->crit_sect);
816 return -ENODEV; 824 return -ENODEV;
817 } 825 }
@@ -820,7 +828,8 @@ int pciehp_disable_slot(struct slot *p_slot)
820 if (MRL_SENS(p_slot->ctrl->ctrlcap)) { 828 if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
821 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 829 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
822 if (ret || getstatus) { 830 if (ret || getstatus) {
823 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); 831 info("%s: latch open on slot(%s)\n", __FUNCTION__,
832 slot_name(p_slot));
824 mutex_unlock(&p_slot->ctrl->crit_sect); 833 mutex_unlock(&p_slot->ctrl->crit_sect);
825 return -ENODEV; 834 return -ENODEV;
826 } 835 }
@@ -829,16 +838,17 @@ int pciehp_disable_slot(struct slot *p_slot)
829 if (POWER_CTRL(p_slot->ctrl->ctrlcap)) { 838 if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
830 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 839 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
831 if (ret || !getstatus) { 840 if (ret || !getstatus) {
832 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number); 841 info("%s: already disabled slot(%s)\n", __FUNCTION__,
842 slot_name(p_slot));
833 mutex_unlock(&p_slot->ctrl->crit_sect); 843 mutex_unlock(&p_slot->ctrl->crit_sect);
834 return -EINVAL; 844 return -EINVAL;
835 } 845 }
836 } 846 }
837 847
838 mutex_unlock(&p_slot->ctrl->crit_sect);
839
840 ret = remove_board(p_slot); 848 ret = remove_board(p_slot);
841 update_slot_info(p_slot); 849 update_slot_info(p_slot);
850
851 mutex_unlock(&p_slot->ctrl->crit_sect);
842 return ret; 852 return ret;
843} 853}
844 854
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 703a64a39fe8..6d3f580f2666 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -718,8 +718,6 @@ static void hpc_release_ctlr(struct controller *ctrl)
718 if (php_ctlr->irq) { 718 if (php_ctlr->irq) {
719 free_irq(php_ctlr->irq, ctrl); 719 free_irq(php_ctlr->irq, ctrl);
720 php_ctlr->irq = 0; 720 php_ctlr->irq = 0;
721 if (!pcie_mch_quirk)
722 pci_disable_msi(php_ctlr->pci_dev);
723 } 721 }
724 } 722 }
725 if (php_ctlr->pci_dev) 723 if (php_ctlr->pci_dev)
@@ -1402,6 +1400,8 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1402 pdev->subsystem_vendor, pdev->subsystem_device); 1400 pdev->subsystem_vendor, pdev->subsystem_device);
1403 1401
1404 mutex_init(&ctrl->crit_sect); 1402 mutex_init(&ctrl->crit_sect);
1403 mutex_init(&ctrl->ctrl_lock);
1404
1405 /* setup wait queue */ 1405 /* setup wait queue */
1406 init_waitqueue_head(&ctrl->queue); 1406 init_waitqueue_head(&ctrl->queue);
1407 1407
diff --git a/drivers/pci/hotplug/pcihp_skeleton.c b/drivers/pci/hotplug/pcihp_skeleton.c
index 2b9e10e38613..50bcd3fe61da 100644
--- a/drivers/pci/hotplug/pcihp_skeleton.c
+++ b/drivers/pci/hotplug/pcihp_skeleton.c
@@ -33,8 +33,8 @@
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/pci_hotplug.h>
36#include <linux/init.h> 37#include <linux/init.h>
37#include "pci_hotplug.h"
38 38
39#define SLOT_NAME_SIZE 10 39#define SLOT_NAME_SIZE 10
40struct slot { 40struct slot {
diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
index 46825fee3ae4..72383467a0d5 100644
--- a/drivers/pci/hotplug/rpadlpar_core.c
+++ b/drivers/pci/hotplug/rpadlpar_core.c
@@ -63,7 +63,7 @@ static struct device_node *find_php_slot_pci_node(char *drc_name,
63 char *type; 63 char *type;
64 int rc; 64 int rc;
65 65
66 while ((np = of_find_node_by_type(np, "pci"))) { 66 while ((np = of_find_node_by_name(np, "pci"))) {
67 rc = rpaphp_get_drc_props(np, NULL, &name, &type, NULL); 67 rc = rpaphp_get_drc_props(np, NULL, &name, &type, NULL);
68 if (rc == 0) 68 if (rc == 0)
69 if (!strcmp(drc_name, name) && !strcmp(drc_type, type)) 69 if (!strcmp(drc_name, name) && !strcmp(drc_type, type))
diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c
index db69be85b458..6c5be3ff578c 100644
--- a/drivers/pci/hotplug/rpadlpar_sysfs.c
+++ b/drivers/pci/hotplug/rpadlpar_sysfs.c
@@ -14,7 +14,7 @@
14 */ 14 */
15#include <linux/kobject.h> 15#include <linux/kobject.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include "pci_hotplug.h" 17#include <linux/pci_hotplug.h>
18#include "rpadlpar.h" 18#include "rpadlpar.h"
19 19
20#define DLPAR_KOBJ_NAME "control" 20#define DLPAR_KOBJ_NAME "control"
diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h
index 310b6186c0e5..2e7accf0f734 100644
--- a/drivers/pci/hotplug/rpaphp.h
+++ b/drivers/pci/hotplug/rpaphp.h
@@ -28,7 +28,7 @@
28#define _PPC64PHP_H 28#define _PPC64PHP_H
29 29
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include "pci_hotplug.h" 31#include <linux/pci_hotplug.h>
32 32
33#define DR_INDICATOR 9002 33#define DR_INDICATOR 9002
34#define DR_ENTITY_SENSE 9003 34#define DR_ENTITY_SENSE 9003
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index 7288a3eccfb3..71a2cb8baa4a 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -26,6 +26,7 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/pci_hotplug.h>
29#include <linux/slab.h> 30#include <linux/slab.h>
30#include <linux/smp.h> 31#include <linux/smp.h>
31#include <linux/smp_lock.h> 32#include <linux/smp_lock.h>
@@ -36,7 +37,6 @@
36#include "../pci.h" /* for pci_add_new_bus */ 37#include "../pci.h" /* for pci_add_new_bus */
37 /* and pci_do_scan_bus */ 38 /* and pci_do_scan_bus */
38#include "rpaphp.h" 39#include "rpaphp.h"
39#include "pci_hotplug.h"
40 40
41int debug; 41int debug;
42static struct semaphore rpaphp_sem; 42static struct semaphore rpaphp_sem;
@@ -356,7 +356,7 @@ static int __init rpaphp_init(void)
356 info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); 356 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
357 init_MUTEX(&rpaphp_sem); 357 init_MUTEX(&rpaphp_sem);
358 358
359 while ((dn = of_find_node_by_type(dn, "pci"))) 359 while ((dn = of_find_node_by_name(dn, "pci")))
360 rpaphp_add_slot(dn); 360 rpaphp_add_slot(dn);
361 361
362 return 0; 362 return 0;
diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c
index f31d83c2c633..5d188c558386 100644
--- a/drivers/pci/hotplug/sgi_hotplug.c
+++ b/drivers/pci/hotplug/sgi_hotplug.c
@@ -13,6 +13,7 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/pci.h> 15#include <linux/pci.h>
16#include <linux/pci_hotplug.h>
16#include <linux/proc_fs.h> 17#include <linux/proc_fs.h>
17#include <linux/types.h> 18#include <linux/types.h>
18#include <linux/mutex.h> 19#include <linux/mutex.h>
@@ -29,7 +30,6 @@
29#include <asm/sn/types.h> 30#include <asm/sn/types.h>
30 31
31#include "../pci.h" 32#include "../pci.h"
32#include "pci_hotplug.h"
33 33
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35MODULE_AUTHOR("SGI (prarit@sgi.com, dickie@sgi.com, habeck@sgi.com)"); 35MODULE_AUTHOR("SGI (prarit@sgi.com, dickie@sgi.com, habeck@sgi.com)");
@@ -205,21 +205,6 @@ static struct hotplug_slot * sn_hp_destroy(void)
205 return bss_hotplug_slot; 205 return bss_hotplug_slot;
206} 206}
207 207
208static void sn_bus_alloc_data(struct pci_dev *dev)
209{
210 struct pci_bus *subordinate_bus;
211 struct pci_dev *child;
212
213 sn_pci_fixup_slot(dev);
214
215 /* Recursively sets up the sn_irq_info structs */
216 if (dev->subordinate) {
217 subordinate_bus = dev->subordinate;
218 list_for_each_entry(child, &subordinate_bus->devices, bus_list)
219 sn_bus_alloc_data(child);
220 }
221}
222
223static void sn_bus_free_data(struct pci_dev *dev) 208static void sn_bus_free_data(struct pci_dev *dev)
224{ 209{
225 struct pci_bus *subordinate_bus; 210 struct pci_bus *subordinate_bus;
@@ -337,6 +322,11 @@ static int sn_slot_disable(struct hotplug_slot *bss_hotplug_slot,
337 return rc; 322 return rc;
338} 323}
339 324
325/*
326 * Power up and configure the slot via a SAL call to PROM.
327 * Scan slot (and any children), do any platform specific fixup,
328 * and find device driver.
329 */
340static int enable_slot(struct hotplug_slot *bss_hotplug_slot) 330static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
341{ 331{
342 struct slot *slot = bss_hotplug_slot->private; 332 struct slot *slot = bss_hotplug_slot->private;
@@ -345,6 +335,7 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
345 int func, num_funcs; 335 int func, num_funcs;
346 int new_ppb = 0; 336 int new_ppb = 0;
347 int rc; 337 int rc;
338 void pcibios_fixup_device_resources(struct pci_dev *);
348 339
349 /* Serialize the Linux PCI infrastructure */ 340 /* Serialize the Linux PCI infrastructure */
350 mutex_lock(&sn_hotplug_mutex); 341 mutex_lock(&sn_hotplug_mutex);
@@ -367,9 +358,6 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
367 return -ENODEV; 358 return -ENODEV;
368 } 359 }
369 360
370 sn_pci_controller_fixup(pci_domain_nr(slot->pci_bus),
371 slot->pci_bus->number,
372 slot->pci_bus);
373 /* 361 /*
374 * Map SN resources for all functions on the card 362 * Map SN resources for all functions on the card
375 * to the Linux PCI interface and tell the drivers 363 * to the Linux PCI interface and tell the drivers
@@ -380,6 +368,13 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
380 PCI_DEVFN(slot->device_num + 1, 368 PCI_DEVFN(slot->device_num + 1,
381 PCI_FUNC(func))); 369 PCI_FUNC(func)));
382 if (dev) { 370 if (dev) {
371 /* Need to do slot fixup on PPB before fixup of children
372 * (PPB's pcidev_info needs to be in pcidev_info list
373 * before child's SN_PCIDEV_INFO() call to setup
374 * pdi_host_pcidev_info).
375 */
376 pcibios_fixup_device_resources(dev);
377 sn_pci_fixup_slot(dev);
383 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { 378 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
384 unsigned char sec_bus; 379 unsigned char sec_bus;
385 pci_read_config_byte(dev, PCI_SECONDARY_BUS, 380 pci_read_config_byte(dev, PCI_SECONDARY_BUS,
@@ -387,12 +382,8 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
387 new_bus = pci_add_new_bus(dev->bus, dev, 382 new_bus = pci_add_new_bus(dev->bus, dev,
388 sec_bus); 383 sec_bus);
389 pci_scan_child_bus(new_bus); 384 pci_scan_child_bus(new_bus);
390 sn_pci_controller_fixup(pci_domain_nr(new_bus),
391 new_bus->number,
392 new_bus);
393 new_ppb = 1; 385 new_ppb = 1;
394 } 386 }
395 sn_bus_alloc_data(dev);
396 pci_dev_put(dev); 387 pci_dev_put(dev);
397 } 388 }
398 } 389 }
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
index c7103ac5cd06..ea2087c34149 100644
--- a/drivers/pci/hotplug/shpchp.h
+++ b/drivers/pci/hotplug/shpchp.h
@@ -31,12 +31,11 @@
31 31
32#include <linux/types.h> 32#include <linux/types.h>
33#include <linux/pci.h> 33#include <linux/pci.h>
34#include <linux/pci_hotplug.h>
34#include <linux/delay.h> 35#include <linux/delay.h>
35#include <linux/sched.h> /* signal_pending(), struct timer_list */ 36#include <linux/sched.h> /* signal_pending(), struct timer_list */
36#include <linux/mutex.h> 37#include <linux/mutex.h>
37 38
38#include "pci_hotplug.h"
39
40#if !defined(MODULE) 39#if !defined(MODULE)
41 #define MY_NAME "shpchp" 40 #define MY_NAME "shpchp"
42#else 41#else
@@ -103,7 +102,6 @@ struct controller {
103 u32 cap_offset; 102 u32 cap_offset;
104 unsigned long mmio_base; 103 unsigned long mmio_base;
105 unsigned long mmio_size; 104 unsigned long mmio_size;
106 volatile int cmd_busy;
107}; 105};
108 106
109 107
diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c
index 4d8aee119134..83a5226ba9ed 100644
--- a/drivers/pci/hotplug/shpchp_hpc.c
+++ b/drivers/pci/hotplug/shpchp_hpc.c
@@ -302,21 +302,51 @@ static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec)
302 add_timer(&php_ctlr->int_poll_timer); 302 add_timer(&php_ctlr->int_poll_timer);
303} 303}
304 304
305static inline int is_ctrl_busy(struct controller *ctrl)
306{
307 u16 cmd_status = shpc_readw(ctrl, CMD_STATUS);
308 return cmd_status & 0x1;
309}
310
311/*
312 * Returns 1 if SHPC finishes executing a command within 1 sec,
313 * otherwise returns 0.
314 */
315static inline int shpc_poll_ctrl_busy(struct controller *ctrl)
316{
317 int i;
318
319 if (!is_ctrl_busy(ctrl))
320 return 1;
321
322 /* Check every 0.1 sec for a total of 1 sec */
323 for (i = 0; i < 10; i++) {
324 msleep(100);
325 if (!is_ctrl_busy(ctrl))
326 return 1;
327 }
328
329 return 0;
330}
331
305static inline int shpc_wait_cmd(struct controller *ctrl) 332static inline int shpc_wait_cmd(struct controller *ctrl)
306{ 333{
307 int retval = 0; 334 int retval = 0;
308 unsigned int timeout_msec = shpchp_poll_mode ? 2000 : 1000; 335 unsigned long timeout = msecs_to_jiffies(1000);
309 unsigned long timeout = msecs_to_jiffies(timeout_msec); 336 int rc;
310 int rc = wait_event_interruptible_timeout(ctrl->queue, 337
311 !ctrl->cmd_busy, timeout); 338 if (shpchp_poll_mode)
312 if (!rc) { 339 rc = shpc_poll_ctrl_busy(ctrl);
340 else
341 rc = wait_event_interruptible_timeout(ctrl->queue,
342 !is_ctrl_busy(ctrl), timeout);
343 if (!rc && is_ctrl_busy(ctrl)) {
313 retval = -EIO; 344 retval = -EIO;
314 err("Command not completed in %d msec\n", timeout_msec); 345 err("Command not completed in 1000 msec\n");
315 } else if (rc < 0) { 346 } else if (rc < 0) {
316 retval = -EINTR; 347 retval = -EINTR;
317 info("Command was interrupted by a signal\n"); 348 info("Command was interrupted by a signal\n");
318 } 349 }
319 ctrl->cmd_busy = 0;
320 350
321 return retval; 351 return retval;
322} 352}
@@ -327,26 +357,15 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
327 u16 cmd_status; 357 u16 cmd_status;
328 int retval = 0; 358 int retval = 0;
329 u16 temp_word; 359 u16 temp_word;
330 int i;
331 360
332 DBG_ENTER_ROUTINE 361 DBG_ENTER_ROUTINE
333 362
334 mutex_lock(&slot->ctrl->cmd_lock); 363 mutex_lock(&slot->ctrl->cmd_lock);
335 364
336 for (i = 0; i < 10; i++) { 365 if (!shpc_poll_ctrl_busy(ctrl)) {
337 cmd_status = shpc_readw(ctrl, CMD_STATUS);
338
339 if (!(cmd_status & 0x1))
340 break;
341 /* Check every 0.1 sec for a total of 1 sec*/
342 msleep(100);
343 }
344
345 cmd_status = shpc_readw(ctrl, CMD_STATUS);
346
347 if (cmd_status & 0x1) {
348 /* After 1 sec and and the controller is still busy */ 366 /* After 1 sec and and the controller is still busy */
349 err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__); 367 err("%s : Controller is still busy after 1 sec.\n",
368 __FUNCTION__);
350 retval = -EBUSY; 369 retval = -EBUSY;
351 goto out; 370 goto out;
352 } 371 }
@@ -358,7 +377,6 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
358 /* To make sure the Controller Busy bit is 0 before we send out the 377 /* To make sure the Controller Busy bit is 0 before we send out the
359 * command. 378 * command.
360 */ 379 */
361 slot->ctrl->cmd_busy = 1;
362 shpc_writew(ctrl, CMD, temp_word); 380 shpc_writew(ctrl, CMD, temp_word);
363 381
364 /* 382 /*
@@ -908,7 +926,6 @@ static irqreturn_t shpc_isr(int irq, void *dev_id)
908 serr_int &= ~SERR_INTR_RSVDZ_MASK; 926 serr_int &= ~SERR_INTR_RSVDZ_MASK;
909 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); 927 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
910 928
911 ctrl->cmd_busy = 0;
912 wake_up_interruptible(&ctrl->queue); 929 wake_up_interruptible(&ctrl->queue);
913 } 930 }
914 931
@@ -1101,7 +1118,7 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1101{ 1118{
1102 struct php_ctlr_state_s *php_ctlr, *p; 1119 struct php_ctlr_state_s *php_ctlr, *p;
1103 void *instance_id = ctrl; 1120 void *instance_id = ctrl;
1104 int rc, num_slots = 0; 1121 int rc = -1, num_slots = 0;
1105 u8 hp_slot; 1122 u8 hp_slot;
1106 u32 shpc_base_offset; 1123 u32 shpc_base_offset;
1107 u32 tempdword, slot_reg, slot_config; 1124 u32 tempdword, slot_reg, slot_config;
@@ -1167,11 +1184,15 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1167 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor, 1184 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor,
1168 pdev->subsystem_device); 1185 pdev->subsystem_device);
1169 1186
1170 if (pci_enable_device(pdev)) 1187 rc = pci_enable_device(pdev);
1188 if (rc) {
1189 err("%s: pci_enable_device failed\n", __FUNCTION__);
1171 goto abort_free_ctlr; 1190 goto abort_free_ctlr;
1191 }
1172 1192
1173 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) { 1193 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
1174 err("%s: cannot reserve MMIO region\n", __FUNCTION__); 1194 err("%s: cannot reserve MMIO region\n", __FUNCTION__);
1195 rc = -1;
1175 goto abort_free_ctlr; 1196 goto abort_free_ctlr;
1176 } 1197 }
1177 1198
@@ -1180,6 +1201,7 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1180 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__, 1201 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
1181 ctrl->mmio_size, ctrl->mmio_base); 1202 ctrl->mmio_size, ctrl->mmio_base);
1182 release_mem_region(ctrl->mmio_base, ctrl->mmio_size); 1203 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
1204 rc = -1;
1183 goto abort_free_ctlr; 1205 goto abort_free_ctlr;
1184 } 1206 }
1185 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg); 1207 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);
@@ -1282,8 +1304,10 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1282 */ 1304 */
1283 if (atomic_add_return(1, &shpchp_num_controllers) == 1) { 1305 if (atomic_add_return(1, &shpchp_num_controllers) == 1) {
1284 shpchp_wq = create_singlethread_workqueue("shpchpd"); 1306 shpchp_wq = create_singlethread_workqueue("shpchpd");
1285 if (!shpchp_wq) 1307 if (!shpchp_wq) {
1286 return -ENOMEM; 1308 rc = -ENOMEM;
1309 goto abort_free_ctlr;
1310 }
1287 } 1311 }
1288 1312
1289 /* 1313 /*
@@ -1313,8 +1337,10 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1313 1337
1314 /* We end up here for the many possible ways to fail this API. */ 1338 /* We end up here for the many possible ways to fail this API. */
1315abort_free_ctlr: 1339abort_free_ctlr:
1340 if (php_ctlr->creg)
1341 iounmap(php_ctlr->creg);
1316 kfree(php_ctlr); 1342 kfree(php_ctlr);
1317abort: 1343abort:
1318 DBG_LEAVE_ROUTINE 1344 DBG_LEAVE_ROUTINE
1319 return -1; 1345 return rc;
1320} 1346}
diff --git a/drivers/pci/htirq.c b/drivers/pci/htirq.c
index 0e27f2404a83..0a8d1cce9fa0 100644
--- a/drivers/pci/htirq.c
+++ b/drivers/pci/htirq.c
@@ -25,97 +25,72 @@ static DEFINE_SPINLOCK(ht_irq_lock);
25 25
26struct ht_irq_cfg { 26struct ht_irq_cfg {
27 struct pci_dev *dev; 27 struct pci_dev *dev;
28 /* Update callback used to cope with buggy hardware */
29 ht_irq_update_t *update;
28 unsigned pos; 30 unsigned pos;
29 unsigned idx; 31 unsigned idx;
32 struct ht_irq_msg msg;
30}; 33};
31 34
32void write_ht_irq_low(unsigned int irq, u32 data)
33{
34 struct ht_irq_cfg *cfg = get_irq_data(irq);
35 unsigned long flags;
36 spin_lock_irqsave(&ht_irq_lock, flags);
37 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
38 pci_write_config_dword(cfg->dev, cfg->pos + 4, data);
39 spin_unlock_irqrestore(&ht_irq_lock, flags);
40}
41 35
42void write_ht_irq_high(unsigned int irq, u32 data) 36void write_ht_irq_msg(unsigned int irq, struct ht_irq_msg *msg)
43{ 37{
44 struct ht_irq_cfg *cfg = get_irq_data(irq); 38 struct ht_irq_cfg *cfg = get_irq_data(irq);
45 unsigned long flags; 39 unsigned long flags;
46 spin_lock_irqsave(&ht_irq_lock, flags); 40 spin_lock_irqsave(&ht_irq_lock, flags);
47 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx + 1); 41 if (cfg->msg.address_lo != msg->address_lo) {
48 pci_write_config_dword(cfg->dev, cfg->pos + 4, data); 42 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
49 spin_unlock_irqrestore(&ht_irq_lock, flags); 43 pci_write_config_dword(cfg->dev, cfg->pos + 4, msg->address_lo);
50} 44 }
51 45 if (cfg->msg.address_hi != msg->address_hi) {
52u32 read_ht_irq_low(unsigned int irq) 46 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx + 1);
53{ 47 pci_write_config_dword(cfg->dev, cfg->pos + 4, msg->address_hi);
54 struct ht_irq_cfg *cfg = get_irq_data(irq); 48 }
55 unsigned long flags; 49 if (cfg->update)
56 u32 data; 50 cfg->update(cfg->dev, irq, msg);
57 spin_lock_irqsave(&ht_irq_lock, flags);
58 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
59 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data);
60 spin_unlock_irqrestore(&ht_irq_lock, flags); 51 spin_unlock_irqrestore(&ht_irq_lock, flags);
61 return data; 52 cfg->msg = *msg;
62} 53}
63 54
64u32 read_ht_irq_high(unsigned int irq) 55void fetch_ht_irq_msg(unsigned int irq, struct ht_irq_msg *msg)
65{ 56{
66 struct ht_irq_cfg *cfg = get_irq_data(irq); 57 struct ht_irq_cfg *cfg = get_irq_data(irq);
67 unsigned long flags; 58 *msg = cfg->msg;
68 u32 data;
69 spin_lock_irqsave(&ht_irq_lock, flags);
70 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx + 1);
71 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data);
72 spin_unlock_irqrestore(&ht_irq_lock, flags);
73 return data;
74} 59}
75 60
76void mask_ht_irq(unsigned int irq) 61void mask_ht_irq(unsigned int irq)
77{ 62{
78 struct ht_irq_cfg *cfg; 63 struct ht_irq_cfg *cfg;
79 unsigned long flags; 64 struct ht_irq_msg msg;
80 u32 data;
81 65
82 cfg = get_irq_data(irq); 66 cfg = get_irq_data(irq);
83 67
84 spin_lock_irqsave(&ht_irq_lock, flags); 68 msg = cfg->msg;
85 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx); 69 msg.address_lo |= 1;
86 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data); 70 write_ht_irq_msg(irq, &msg);
87 data |= 1;
88 pci_write_config_dword(cfg->dev, cfg->pos + 4, data);
89 spin_unlock_irqrestore(&ht_irq_lock, flags);
90} 71}
91 72
92void unmask_ht_irq(unsigned int irq) 73void unmask_ht_irq(unsigned int irq)
93{ 74{
94 struct ht_irq_cfg *cfg; 75 struct ht_irq_cfg *cfg;
95 unsigned long flags; 76 struct ht_irq_msg msg;
96 u32 data;
97 77
98 cfg = get_irq_data(irq); 78 cfg = get_irq_data(irq);
99 79
100 spin_lock_irqsave(&ht_irq_lock, flags); 80 msg = cfg->msg;
101 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx); 81 msg.address_lo &= ~1;
102 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data); 82 write_ht_irq_msg(irq, &msg);
103 data &= ~1;
104 pci_write_config_dword(cfg->dev, cfg->pos + 4, data);
105 spin_unlock_irqrestore(&ht_irq_lock, flags);
106} 83}
107 84
108/** 85/**
109 * ht_create_irq - create an irq and attach it to a device. 86 * __ht_create_irq - create an irq and attach it to a device.
110 * @dev: The hypertransport device to find the irq capability on. 87 * @dev: The hypertransport device to find the irq capability on.
111 * @idx: Which of the possible irqs to attach to. 88 * @idx: Which of the possible irqs to attach to.
112 * 89 * @update: Function to be called when changing the htirq message
113 * ht_create_irq is needs to be called for all hypertransport devices
114 * that generate irqs.
115 * 90 *
116 * The irq number of the new irq or a negative error value is returned. 91 * The irq number of the new irq or a negative error value is returned.
117 */ 92 */
118int ht_create_irq(struct pci_dev *dev, int idx) 93int __ht_create_irq(struct pci_dev *dev, int idx, ht_irq_update_t *update)
119{ 94{
120 struct ht_irq_cfg *cfg; 95 struct ht_irq_cfg *cfg;
121 unsigned long flags; 96 unsigned long flags;
@@ -150,8 +125,12 @@ int ht_create_irq(struct pci_dev *dev, int idx)
150 return -ENOMEM; 125 return -ENOMEM;
151 126
152 cfg->dev = dev; 127 cfg->dev = dev;
128 cfg->update = update;
153 cfg->pos = pos; 129 cfg->pos = pos;
154 cfg->idx = 0x10 + (idx * 2); 130 cfg->idx = 0x10 + (idx * 2);
131 /* Initialize msg to a value that will never match the first write. */
132 cfg->msg.address_lo = 0xffffffff;
133 cfg->msg.address_hi = 0xffffffff;
155 134
156 irq = create_irq(); 135 irq = create_irq();
157 if (irq < 0) { 136 if (irq < 0) {
@@ -169,6 +148,21 @@ int ht_create_irq(struct pci_dev *dev, int idx)
169} 148}
170 149
171/** 150/**
151 * ht_create_irq - create an irq and attach it to a device.
152 * @dev: The hypertransport device to find the irq capability on.
153 * @idx: Which of the possible irqs to attach to.
154 *
155 * ht_create_irq needs to be called for all hypertransport devices
156 * that generate irqs.
157 *
158 * The irq number of the new irq or a negative error value is returned.
159 */
160int ht_create_irq(struct pci_dev *dev, int idx)
161{
162 return __ht_create_irq(dev, idx, NULL);
163}
164
165/**
172 * ht_destroy_irq - destroy an irq created with ht_create_irq 166 * ht_destroy_irq - destroy an irq created with ht_create_irq
173 * 167 *
174 * This reverses ht_create_irq removing the specified irq from 168 * This reverses ht_create_irq removing the specified irq from
@@ -186,5 +180,6 @@ void ht_destroy_irq(unsigned int irq)
186 kfree(cfg); 180 kfree(cfg);
187} 181}
188 182
183EXPORT_SYMBOL(__ht_create_irq);
189EXPORT_SYMBOL(ht_create_irq); 184EXPORT_SYMBOL(ht_create_irq);
190EXPORT_SYMBOL(ht_destroy_irq); 185EXPORT_SYMBOL(ht_destroy_irq);
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index f9fdc54473c4..9fc9a34ef24a 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -627,22 +627,24 @@ static int msix_capability_init(struct pci_dev *dev,
627 * pci_msi_supported - check whether MSI may be enabled on device 627 * pci_msi_supported - check whether MSI may be enabled on device
628 * @dev: pointer to the pci_dev data structure of MSI device function 628 * @dev: pointer to the pci_dev data structure of MSI device function
629 * 629 *
630 * MSI must be globally enabled and supported by the device and its root 630 * Look at global flags, the device itself, and its parent busses
631 * bus. But, the root bus is not easy to find since some architectures 631 * to return 0 if MSI are supported for the device.
632 * have virtual busses on top of the PCI hierarchy (for instance the
633 * hypertransport bus), while the actual bus where MSI must be supported
634 * is below. So we test the MSI flag on all parent busses and assume
635 * that no quirk will ever set the NO_MSI flag on a non-root bus.
636 **/ 632 **/
637static 633static
638int pci_msi_supported(struct pci_dev * dev) 634int pci_msi_supported(struct pci_dev * dev)
639{ 635{
640 struct pci_bus *bus; 636 struct pci_bus *bus;
641 637
638 /* MSI must be globally enabled and supported by the device */
642 if (!pci_msi_enable || !dev || dev->no_msi) 639 if (!pci_msi_enable || !dev || dev->no_msi)
643 return -EINVAL; 640 return -EINVAL;
644 641
645 /* check MSI flags of all parent busses */ 642 /* Any bridge which does NOT route MSI transactions from it's
643 * secondary bus to it's primary bus must set NO_MSI flag on
644 * the secondary pci_bus.
645 * We expect only arch-specific PCI host bus controller driver
646 * or quirks for specific PCI bridges to be setting NO_MSI.
647 */
646 for (bus = dev->bus; bus; bus = bus->parent) 648 for (bus = dev->bus; bus; bus = bus->parent)
647 if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI) 649 if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI)
648 return -EINVAL; 650 return -EINVAL;
diff --git a/drivers/pci/msi.h b/drivers/pci/msi.h
index f0cca1772f9c..3898f5237144 100644
--- a/drivers/pci/msi.h
+++ b/drivers/pci/msi.h
@@ -6,14 +6,6 @@
6#ifndef MSI_H 6#ifndef MSI_H
7#define MSI_H 7#define MSI_H
8 8
9/*
10 * MSI-X Address Register
11 */
12#define PCI_MSIX_FLAGS_QSIZE 0x7FF
13#define PCI_MSIX_FLAGS_ENABLE (1 << 15)
14#define PCI_MSIX_FLAGS_BIRMASK (7 << 0)
15#define PCI_MSIX_FLAGS_BITMASK (1 << 0)
16
17#define PCI_MSIX_ENTRY_SIZE 16 9#define PCI_MSIX_ENTRY_SIZE 16
18#define PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET 0 10#define PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET 0
19#define PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET 4 11#define PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET 4
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index bb7456c1dbac..a064f36a0805 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -36,6 +36,7 @@ acpi_query_osc (
36 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; 36 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
37 union acpi_object *out_obj; 37 union acpi_object *out_obj;
38 u32 osc_dw0; 38 u32 osc_dw0;
39 acpi_status *ret_status = (acpi_status *)retval;
39 40
40 41
41 /* Setting up input parameters */ 42 /* Setting up input parameters */
@@ -56,6 +57,7 @@ acpi_query_osc (
56 if (ACPI_FAILURE (status)) { 57 if (ACPI_FAILURE (status)) {
57 printk(KERN_DEBUG 58 printk(KERN_DEBUG
58 "Evaluate _OSC Set fails. Status = 0x%04x\n", status); 59 "Evaluate _OSC Set fails. Status = 0x%04x\n", status);
60 *ret_status = status;
59 return status; 61 return status;
60 } 62 }
61 out_obj = output.pointer; 63 out_obj = output.pointer;
@@ -90,6 +92,7 @@ acpi_query_osc (
90 92
91query_osc_out: 93query_osc_out:
92 kfree(output.pointer); 94 kfree(output.pointer);
95 *ret_status = status;
93 return status; 96 return status;
94} 97}
95 98
@@ -166,6 +169,7 @@ run_osc_out:
166acpi_status pci_osc_support_set(u32 flags) 169acpi_status pci_osc_support_set(u32 flags)
167{ 170{
168 u32 temp; 171 u32 temp;
172 acpi_status retval;
169 173
170 if (!(flags & OSC_SUPPORT_MASKS)) { 174 if (!(flags & OSC_SUPPORT_MASKS)) {
171 return AE_TYPE; 175 return AE_TYPE;
@@ -179,9 +183,13 @@ acpi_status pci_osc_support_set(u32 flags)
179 acpi_get_devices ( PCI_ROOT_HID_STRING, 183 acpi_get_devices ( PCI_ROOT_HID_STRING,
180 acpi_query_osc, 184 acpi_query_osc,
181 ctrlset_buf, 185 ctrlset_buf,
182 NULL ); 186 (void **) &retval );
183 ctrlset_buf[OSC_QUERY_TYPE] = !OSC_QUERY_ENABLE; 187 ctrlset_buf[OSC_QUERY_TYPE] = !OSC_QUERY_ENABLE;
184 ctrlset_buf[OSC_CONTROL_TYPE] = temp; 188 ctrlset_buf[OSC_CONTROL_TYPE] = temp;
189 if (ACPI_FAILURE(retval)) {
190 /* no osc support at all */
191 ctrlset_buf[OSC_SUPPORT_TYPE] = 0;
192 }
185 return AE_OK; 193 return AE_OK;
186} 194}
187EXPORT_SYMBOL(pci_osc_support_set); 195EXPORT_SYMBOL(pci_osc_support_set);
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index b1c0c707d96c..e5ae3a0c13bb 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -265,6 +265,13 @@ static int pci_device_remove(struct device * dev)
265 } 265 }
266 266
267 /* 267 /*
268 * If the device is still on, set the power state as "unknown",
269 * since it might change by the next time we load the driver.
270 */
271 if (pci_dev->current_state == PCI_D0)
272 pci_dev->current_state = PCI_UNKNOWN;
273
274 /*
268 * We would love to complain here if pci_dev->is_enabled is set, that 275 * We would love to complain here if pci_dev->is_enabled is set, that
269 * the driver should have called pci_disable_device(), but the 276 * the driver should have called pci_disable_device(), but the
270 * unfortunate fact is there are too many odd BIOS and bridge setups 277 * unfortunate fact is there are too many odd BIOS and bridge setups
@@ -288,6 +295,12 @@ static int pci_device_suspend(struct device * dev, pm_message_t state)
288 suspend_report_result(drv->suspend, i); 295 suspend_report_result(drv->suspend, i);
289 } else { 296 } else {
290 pci_save_state(pci_dev); 297 pci_save_state(pci_dev);
298 /*
299 * mark its power state as "unknown", since we don't know if
300 * e.g. the BIOS will change its device state when we suspend.
301 */
302 if (pci_dev->current_state == PCI_D0)
303 pci_dev->current_state = PCI_UNKNOWN;
291 } 304 }
292 return i; 305 return i;
293} 306}
@@ -316,8 +329,8 @@ static int pci_default_resume(struct pci_dev *pci_dev)
316 /* restore the PCI config space */ 329 /* restore the PCI config space */
317 pci_restore_state(pci_dev); 330 pci_restore_state(pci_dev);
318 /* if the device was enabled before suspend, reenable */ 331 /* if the device was enabled before suspend, reenable */
319 if (pci_dev->is_enabled) 332 if (atomic_read(&pci_dev->enable_cnt))
320 retval = pci_enable_device(pci_dev); 333 retval = __pci_enable_device(pci_dev);
321 /* if the device was busmaster before the suspend, make it busmaster again */ 334 /* if the device was busmaster before the suspend, make it busmaster again */
322 if (pci_dev->is_busmaster) 335 if (pci_dev->is_busmaster)
323 pci_set_master(pci_dev); 336 pci_set_master(pci_dev);
@@ -432,9 +445,12 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner)
432 445
433 /* register with core */ 446 /* register with core */
434 error = driver_register(&drv->driver); 447 error = driver_register(&drv->driver);
448 if (error)
449 return error;
435 450
436 if (!error) 451 error = pci_create_newid_file(drv);
437 error = pci_create_newid_file(drv); 452 if (error)
453 driver_unregister(&drv->driver);
438 454
439 return error; 455 return error;
440} 456}
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index a1d2e979b17f..7a94076752d0 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -42,7 +42,6 @@ pci_config_attr(subsystem_vendor, "0x%04x\n");
42pci_config_attr(subsystem_device, "0x%04x\n"); 42pci_config_attr(subsystem_device, "0x%04x\n");
43pci_config_attr(class, "0x%06x\n"); 43pci_config_attr(class, "0x%06x\n");
44pci_config_attr(irq, "%u\n"); 44pci_config_attr(irq, "%u\n");
45pci_config_attr(is_enabled, "%u\n");
46 45
47static ssize_t broken_parity_status_show(struct device *dev, 46static ssize_t broken_parity_status_show(struct device *dev,
48 struct device_attribute *attr, 47 struct device_attribute *attr,
@@ -112,26 +111,36 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
112 (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8), 111 (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8),
113 (u8)(pci_dev->class)); 112 (u8)(pci_dev->class));
114} 113}
115static ssize_t 114
116is_enabled_store(struct device *dev, struct device_attribute *attr, 115static ssize_t is_enabled_store(struct device *dev,
117 const char *buf, size_t count) 116 struct device_attribute *attr, const char *buf,
117 size_t count)
118{ 118{
119 ssize_t result = -EINVAL;
119 struct pci_dev *pdev = to_pci_dev(dev); 120 struct pci_dev *pdev = to_pci_dev(dev);
120 int retval = 0;
121 121
122 /* this can crash the machine when done on the "wrong" device */ 122 /* this can crash the machine when done on the "wrong" device */
123 if (!capable(CAP_SYS_ADMIN)) 123 if (!capable(CAP_SYS_ADMIN))
124 return count; 124 return count;
125 125
126 if (*buf == '0') 126 if (*buf == '0') {
127 pci_disable_device(pdev); 127 if (atomic_read(&pdev->enable_cnt) != 0)
128 pci_disable_device(pdev);
129 else
130 result = -EIO;
131 } else if (*buf == '1')
132 result = pci_enable_device(pdev);
133
134 return result < 0 ? result : count;
135}
128 136
129 if (*buf == '1') 137static ssize_t is_enabled_show(struct device *dev,
130 retval = pci_enable_device(pdev); 138 struct device_attribute *attr, char *buf)
139{
140 struct pci_dev *pdev;
131 141
132 if (retval) 142 pdev = to_pci_dev (dev);
133 return retval; 143 return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt));
134 return count;
135} 144}
136 145
137static ssize_t 146static ssize_t
@@ -642,6 +651,9 @@ err:
642 */ 651 */
643void pci_remove_sysfs_dev_files(struct pci_dev *pdev) 652void pci_remove_sysfs_dev_files(struct pci_dev *pdev)
644{ 653{
654 if (!sysfs_initialized)
655 return;
656
645 if (pdev->cfg_size < 4096) 657 if (pdev->cfg_size < 4096)
646 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr); 658 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
647 else 659 else
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index a544997399b3..5a14b73cf3a1 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -490,6 +490,47 @@ static void pci_restore_pcie_state(struct pci_dev *dev)
490 kfree(save_state); 490 kfree(save_state);
491} 491}
492 492
493
494static int pci_save_pcix_state(struct pci_dev *dev)
495{
496 int pos, i = 0;
497 struct pci_cap_saved_state *save_state;
498 u16 *cap;
499
500 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
501 if (pos <= 0)
502 return 0;
503
504 save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL);
505 if (!save_state) {
506 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
507 return -ENOMEM;
508 }
509 cap = (u16 *)&save_state->data[0];
510
511 pci_read_config_word(dev, pos + PCI_X_CMD, &cap[i++]);
512 pci_add_saved_cap(dev, save_state);
513 return 0;
514}
515
516static void pci_restore_pcix_state(struct pci_dev *dev)
517{
518 int i = 0, pos;
519 struct pci_cap_saved_state *save_state;
520 u16 *cap;
521
522 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX);
523 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
524 if (!save_state || pos <= 0)
525 return;
526 cap = (u16 *)&save_state->data[0];
527
528 pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
529 pci_remove_saved_cap(save_state);
530 kfree(save_state);
531}
532
533
493/** 534/**
494 * pci_save_state - save the PCI configuration space of a device before suspending 535 * pci_save_state - save the PCI configuration space of a device before suspending
495 * @dev: - PCI device that we're dealing with 536 * @dev: - PCI device that we're dealing with
@@ -507,6 +548,8 @@ pci_save_state(struct pci_dev *dev)
507 return i; 548 return i;
508 if ((i = pci_save_pcie_state(dev)) != 0) 549 if ((i = pci_save_pcie_state(dev)) != 0)
509 return i; 550 return i;
551 if ((i = pci_save_pcix_state(dev)) != 0)
552 return i;
510 return 0; 553 return 0;
511} 554}
512 555
@@ -538,6 +581,7 @@ pci_restore_state(struct pci_dev *dev)
538 dev->saved_config_space[i]); 581 dev->saved_config_space[i]);
539 } 582 }
540 } 583 }
584 pci_restore_pcix_state(dev);
541 pci_restore_msi_state(dev); 585 pci_restore_msi_state(dev);
542 pci_restore_msix_state(dev); 586 pci_restore_msix_state(dev);
543 return 0; 587 return 0;
@@ -568,30 +612,51 @@ pci_enable_device_bars(struct pci_dev *dev, int bars)
568} 612}
569 613
570/** 614/**
571 * pci_enable_device - Initialize device before it's used by a driver. 615 * __pci_enable_device - Initialize device before it's used by a driver.
572 * @dev: PCI device to be initialized 616 * @dev: PCI device to be initialized
573 * 617 *
574 * Initialize device before it's used by a driver. Ask low-level code 618 * Initialize device before it's used by a driver. Ask low-level code
575 * to enable I/O and memory. Wake up the device if it was suspended. 619 * to enable I/O and memory. Wake up the device if it was suspended.
576 * Beware, this function can fail. 620 * Beware, this function can fail.
621 *
622 * Note this function is a backend and is not supposed to be called by
623 * normal code, use pci_enable_device() instead.
577 */ 624 */
578int 625int
579pci_enable_device(struct pci_dev *dev) 626__pci_enable_device(struct pci_dev *dev)
580{ 627{
581 int err; 628 int err;
582 629
583 if (dev->is_enabled)
584 return 0;
585
586 err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1); 630 err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
587 if (err) 631 if (err)
588 return err; 632 return err;
589 pci_fixup_device(pci_fixup_enable, dev); 633 pci_fixup_device(pci_fixup_enable, dev);
590 dev->is_enabled = 1;
591 return 0; 634 return 0;
592} 635}
593 636
594/** 637/**
638 * pci_enable_device - Initialize device before it's used by a driver.
639 * @dev: PCI device to be initialized
640 *
641 * Initialize device before it's used by a driver. Ask low-level code
642 * to enable I/O and memory. Wake up the device if it was suspended.
643 * Beware, this function can fail.
644 *
645 * Note we don't actually enable the device many times if we call
646 * this function repeatedly (we just increment the count).
647 */
648int pci_enable_device(struct pci_dev *dev)
649{
650 int result;
651 if (atomic_add_return(1, &dev->enable_cnt) > 1)
652 return 0; /* already enabled */
653 result = __pci_enable_device(dev);
654 if (result < 0)
655 atomic_dec(&dev->enable_cnt);
656 return result;
657}
658
659/**
595 * pcibios_disable_device - disable arch specific PCI resources for device dev 660 * pcibios_disable_device - disable arch specific PCI resources for device dev
596 * @dev: the PCI device to disable 661 * @dev: the PCI device to disable
597 * 662 *
@@ -607,12 +672,18 @@ void __attribute__ ((weak)) pcibios_disable_device (struct pci_dev *dev) {}
607 * 672 *
608 * Signal to the system that the PCI device is not in use by the system 673 * Signal to the system that the PCI device is not in use by the system
609 * anymore. This only involves disabling PCI bus-mastering, if active. 674 * anymore. This only involves disabling PCI bus-mastering, if active.
675 *
676 * Note we don't actually disable the device until all callers of
677 * pci_device_enable() have called pci_device_disable().
610 */ 678 */
611void 679void
612pci_disable_device(struct pci_dev *dev) 680pci_disable_device(struct pci_dev *dev)
613{ 681{
614 u16 pci_command; 682 u16 pci_command;
615 683
684 if (atomic_sub_return(1, &dev->enable_cnt) != 0)
685 return;
686
616 if (dev->msi_enabled) 687 if (dev->msi_enabled)
617 disable_msi_mode(dev, pci_find_capability(dev, PCI_CAP_ID_MSI), 688 disable_msi_mode(dev, pci_find_capability(dev, PCI_CAP_ID_MSI),
618 PCI_CAP_ID_MSI); 689 PCI_CAP_ID_MSI);
@@ -628,7 +699,6 @@ pci_disable_device(struct pci_dev *dev)
628 dev->is_busmaster = 0; 699 dev->is_busmaster = 0;
629 700
630 pcibios_disable_device(dev); 701 pcibios_disable_device(dev);
631 dev->is_enabled = 0;
632} 702}
633 703
634/** 704/**
@@ -831,22 +901,38 @@ pci_set_master(struct pci_dev *dev)
831 pcibios_set_master(dev); 901 pcibios_set_master(dev);
832} 902}
833 903
834#ifndef HAVE_ARCH_PCI_MWI 904#ifdef PCI_DISABLE_MWI
905int pci_set_mwi(struct pci_dev *dev)
906{
907 return 0;
908}
909
910void pci_clear_mwi(struct pci_dev *dev)
911{
912}
913
914#else
915
916#ifndef PCI_CACHE_LINE_BYTES
917#define PCI_CACHE_LINE_BYTES L1_CACHE_BYTES
918#endif
919
835/* This can be overridden by arch code. */ 920/* This can be overridden by arch code. */
836u8 pci_cache_line_size = L1_CACHE_BYTES >> 2; 921/* Don't forget this is measured in 32-bit words, not bytes */
922u8 pci_cache_line_size = PCI_CACHE_LINE_BYTES / 4;
837 923
838/** 924/**
839 * pci_generic_prep_mwi - helper function for pci_set_mwi 925 * pci_set_cacheline_size - ensure the CACHE_LINE_SIZE register is programmed
840 * @dev: the PCI device for which MWI is enabled 926 * @dev: the PCI device for which MWI is to be enabled
841 * 927 *
842 * Helper function for generic implementation of pcibios_prep_mwi 928 * Helper function for pci_set_mwi.
843 * function. Originally copied from drivers/net/acenic.c. 929 * Originally copied from drivers/net/acenic.c.
844 * Copyright 1998-2001 by Jes Sorensen, <jes@trained-monkey.org>. 930 * Copyright 1998-2001 by Jes Sorensen, <jes@trained-monkey.org>.
845 * 931 *
846 * RETURNS: An appropriate -ERRNO error value on error, or zero for success. 932 * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
847 */ 933 */
848static int 934static int
849pci_generic_prep_mwi(struct pci_dev *dev) 935pci_set_cacheline_size(struct pci_dev *dev)
850{ 936{
851 u8 cacheline_size; 937 u8 cacheline_size;
852 938
@@ -872,7 +958,6 @@ pci_generic_prep_mwi(struct pci_dev *dev)
872 958
873 return -EINVAL; 959 return -EINVAL;
874} 960}
875#endif /* !HAVE_ARCH_PCI_MWI */
876 961
877/** 962/**
878 * pci_set_mwi - enables memory-write-invalidate PCI transaction 963 * pci_set_mwi - enables memory-write-invalidate PCI transaction
@@ -890,12 +975,7 @@ pci_set_mwi(struct pci_dev *dev)
890 int rc; 975 int rc;
891 u16 cmd; 976 u16 cmd;
892 977
893#ifdef HAVE_ARCH_PCI_MWI 978 rc = pci_set_cacheline_size(dev);
894 rc = pcibios_prep_mwi(dev);
895#else
896 rc = pci_generic_prep_mwi(dev);
897#endif
898
899 if (rc) 979 if (rc)
900 return rc; 980 return rc;
901 981
@@ -926,6 +1006,7 @@ pci_clear_mwi(struct pci_dev *dev)
926 pci_write_config_word(dev, PCI_COMMAND, cmd); 1006 pci_write_config_word(dev, PCI_COMMAND, cmd);
927 } 1007 }
928} 1008}
1009#endif /* ! PCI_DISABLE_MWI */
929 1010
930/** 1011/**
931 * pci_intx - enables/disables PCI INTx for device dev 1012 * pci_intx - enables/disables PCI INTx for device dev
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 6bf327db5c5e..398852f526a6 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -1,5 +1,6 @@
1/* Functions internal to the PCI core code */ 1/* Functions internal to the PCI core code */
2 2
3extern int __must_check __pci_enable_device(struct pci_dev *);
3extern int pci_uevent(struct device *dev, char **envp, int num_envp, 4extern int pci_uevent(struct device *dev, char **envp, int num_envp,
4 char *buffer, int buffer_size); 5 char *buffer, int buffer_size);
5extern int pci_create_sysfs_dev_files(struct pci_dev *pdev); 6extern int pci_create_sysfs_dev_files(struct pci_dev *pdev);
diff --git a/drivers/pci/pcie/portdrv.h b/drivers/pci/pcie/portdrv.h
index 67fcd176babd..3656e0349dd1 100644
--- a/drivers/pci/pcie/portdrv.h
+++ b/drivers/pci/pcie/portdrv.h
@@ -9,6 +9,8 @@
9#ifndef _PORTDRV_H_ 9#ifndef _PORTDRV_H_
10#define _PORTDRV_H_ 10#define _PORTDRV_H_
11 11
12#include <linux/compiler.h>
13
12#if !defined(PCI_CAP_ID_PME) 14#if !defined(PCI_CAP_ID_PME)
13#define PCI_CAP_ID_PME 1 15#define PCI_CAP_ID_PME 1
14#endif 16#endif
@@ -39,7 +41,7 @@ extern int pcie_port_device_suspend(struct pci_dev *dev, pm_message_t state);
39extern int pcie_port_device_resume(struct pci_dev *dev); 41extern int pcie_port_device_resume(struct pci_dev *dev);
40#endif 42#endif
41extern void pcie_port_device_remove(struct pci_dev *dev); 43extern void pcie_port_device_remove(struct pci_dev *dev);
42extern int pcie_port_bus_register(void); 44extern int __must_check pcie_port_bus_register(void);
43extern void pcie_port_bus_unregister(void); 45extern void pcie_port_bus_unregister(void);
44 46
45#endif /* _PORTDRV_H_ */ 47#endif /* _PORTDRV_H_ */
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index bd6615b4d40e..b20a9b81dae2 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -6,7 +6,6 @@
6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com) 6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
7 */ 7 */
8 8
9#include <linux/compiler.h>
10#include <linux/module.h> 9#include <linux/module.h>
11#include <linux/pci.h> 10#include <linux/pci.h>
12#include <linux/kernel.h> 11#include <linux/kernel.h>
@@ -401,7 +400,7 @@ void pcie_port_device_remove(struct pci_dev *dev)
401 pci_disable_msi(dev); 400 pci_disable_msi(dev);
402} 401}
403 402
404int __must_check pcie_port_bus_register(void) 403int pcie_port_bus_register(void)
405{ 404{
406 return bus_register(&pcie_port_bus_type); 405 return bus_register(&pcie_port_bus_type);
407} 406}
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index 037690e08f5f..b4da7954611e 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -37,7 +37,6 @@ static int pcie_portdrv_save_config(struct pci_dev *dev)
37 return pci_save_state(dev); 37 return pci_save_state(dev);
38} 38}
39 39
40#ifdef CONFIG_PM
41static int pcie_portdrv_restore_config(struct pci_dev *dev) 40static int pcie_portdrv_restore_config(struct pci_dev *dev)
42{ 41{
43 int retval; 42 int retval;
@@ -50,6 +49,7 @@ static int pcie_portdrv_restore_config(struct pci_dev *dev)
50 return 0; 49 return 0;
51} 50}
52 51
52#ifdef CONFIG_PM
53static int pcie_portdrv_suspend(struct pci_dev *dev, pm_message_t state) 53static int pcie_portdrv_suspend(struct pci_dev *dev, pm_message_t state)
54{ 54{
55 int ret = pcie_port_device_suspend(dev, state); 55 int ret = pcie_port_device_suspend(dev, state);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index a3b0a5eb5054..0eeac60042b3 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -679,6 +679,33 @@ static int pci_setup_device(struct pci_dev * dev)
679 pci_read_bases(dev, 6, PCI_ROM_ADDRESS); 679 pci_read_bases(dev, 6, PCI_ROM_ADDRESS);
680 pci_read_config_word(dev, PCI_SUBSYSTEM_VENDOR_ID, &dev->subsystem_vendor); 680 pci_read_config_word(dev, PCI_SUBSYSTEM_VENDOR_ID, &dev->subsystem_vendor);
681 pci_read_config_word(dev, PCI_SUBSYSTEM_ID, &dev->subsystem_device); 681 pci_read_config_word(dev, PCI_SUBSYSTEM_ID, &dev->subsystem_device);
682
683 /*
684 * Do the ugly legacy mode stuff here rather than broken chip
685 * quirk code. Legacy mode ATA controllers have fixed
686 * addresses. These are not always echoed in BAR0-3, and
687 * BAR0-3 in a few cases contain junk!
688 */
689 if (class == PCI_CLASS_STORAGE_IDE) {
690 u8 progif;
691 pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
692 if ((progif & 1) == 0) {
693 dev->resource[0].start = 0x1F0;
694 dev->resource[0].end = 0x1F7;
695 dev->resource[0].flags = IORESOURCE_IO;
696 dev->resource[1].start = 0x3F6;
697 dev->resource[1].end = 0x3F6;
698 dev->resource[1].flags = IORESOURCE_IO;
699 }
700 if ((progif & 4) == 0) {
701 dev->resource[2].start = 0x170;
702 dev->resource[2].end = 0x177;
703 dev->resource[2].flags = IORESOURCE_IO;
704 dev->resource[3].start = 0x376;
705 dev->resource[3].end = 0x376;
706 dev->resource[3].flags = IORESOURCE_IO;
707 }
708 }
682 break; 709 break;
683 710
684 case PCI_HEADER_TYPE_BRIDGE: /* bridge header */ 711 case PCI_HEADER_TYPE_BRIDGE: /* bridge header */
@@ -1067,3 +1094,95 @@ EXPORT_SYMBOL(pci_scan_bridge);
1067EXPORT_SYMBOL(pci_scan_single_device); 1094EXPORT_SYMBOL(pci_scan_single_device);
1068EXPORT_SYMBOL_GPL(pci_scan_child_bus); 1095EXPORT_SYMBOL_GPL(pci_scan_child_bus);
1069#endif 1096#endif
1097
1098static int __init pci_sort_bf_cmp(const struct pci_dev *a, const struct pci_dev *b)
1099{
1100 if (pci_domain_nr(a->bus) < pci_domain_nr(b->bus)) return -1;
1101 else if (pci_domain_nr(a->bus) > pci_domain_nr(b->bus)) return 1;
1102
1103 if (a->bus->number < b->bus->number) return -1;
1104 else if (a->bus->number > b->bus->number) return 1;
1105
1106 if (a->devfn < b->devfn) return -1;
1107 else if (a->devfn > b->devfn) return 1;
1108
1109 return 0;
1110}
1111
1112/*
1113 * Yes, this forcably breaks the klist abstraction temporarily. It
1114 * just wants to sort the klist, not change reference counts and
1115 * take/drop locks rapidly in the process. It does all this while
1116 * holding the lock for the list, so objects can't otherwise be
1117 * added/removed while we're swizzling.
1118 */
1119static void __init pci_insertion_sort_klist(struct pci_dev *a, struct list_head *list)
1120{
1121 struct list_head *pos;
1122 struct klist_node *n;
1123 struct device *dev;
1124 struct pci_dev *b;
1125
1126 list_for_each(pos, list) {
1127 n = container_of(pos, struct klist_node, n_node);
1128 dev = container_of(n, struct device, knode_bus);
1129 b = to_pci_dev(dev);
1130 if (pci_sort_bf_cmp(a, b) <= 0) {
1131 list_move_tail(&a->dev.knode_bus.n_node, &b->dev.knode_bus.n_node);
1132 return;
1133 }
1134 }
1135 list_move_tail(&a->dev.knode_bus.n_node, list);
1136}
1137
1138static void __init pci_sort_breadthfirst_klist(void)
1139{
1140 LIST_HEAD(sorted_devices);
1141 struct list_head *pos, *tmp;
1142 struct klist_node *n;
1143 struct device *dev;
1144 struct pci_dev *pdev;
1145
1146 spin_lock(&pci_bus_type.klist_devices.k_lock);
1147 list_for_each_safe(pos, tmp, &pci_bus_type.klist_devices.k_list) {
1148 n = container_of(pos, struct klist_node, n_node);
1149 dev = container_of(n, struct device, knode_bus);
1150 pdev = to_pci_dev(dev);
1151 pci_insertion_sort_klist(pdev, &sorted_devices);
1152 }
1153 list_splice(&sorted_devices, &pci_bus_type.klist_devices.k_list);
1154 spin_unlock(&pci_bus_type.klist_devices.k_lock);
1155}
1156
1157static void __init pci_insertion_sort_devices(struct pci_dev *a, struct list_head *list)
1158{
1159 struct pci_dev *b;
1160
1161 list_for_each_entry(b, list, global_list) {
1162 if (pci_sort_bf_cmp(a, b) <= 0) {
1163 list_move_tail(&a->global_list, &b->global_list);
1164 return;
1165 }
1166 }
1167 list_move_tail(&a->global_list, list);
1168}
1169
1170static void __init pci_sort_breadthfirst_devices(void)
1171{
1172 LIST_HEAD(sorted_devices);
1173 struct pci_dev *dev, *tmp;
1174
1175 down_write(&pci_bus_sem);
1176 list_for_each_entry_safe(dev, tmp, &pci_devices, global_list) {
1177 pci_insertion_sort_devices(dev, &sorted_devices);
1178 }
1179 list_splice(&sorted_devices, &pci_devices);
1180 up_write(&pci_bus_sem);
1181}
1182
1183void __init pci_sort_breadthfirst(void)
1184{
1185 pci_sort_breadthfirst_devices();
1186 pci_sort_breadthfirst_klist();
1187}
1188
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 23b599d6a9d5..9ca9b9bf6160 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -453,6 +453,12 @@ static void __devinit quirk_ich6_lpc_acpi(struct pci_dev *dev)
453} 453}
454DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0, quirk_ich6_lpc_acpi ); 454DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0, quirk_ich6_lpc_acpi );
455DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, quirk_ich6_lpc_acpi ); 455DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, quirk_ich6_lpc_acpi );
456DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0, quirk_ich6_lpc_acpi );
457DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1, quirk_ich6_lpc_acpi );
458DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31, quirk_ich6_lpc_acpi );
459DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_0, quirk_ich6_lpc_acpi );
460DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_2, quirk_ich6_lpc_acpi );
461DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_3, quirk_ich6_lpc_acpi );
456 462
457/* 463/*
458 * VIA ACPI: One IO region pointed to by longword at 464 * VIA ACPI: One IO region pointed to by longword at
@@ -648,11 +654,43 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_vi
648 * Some of the on-chip devices are actually '586 devices' so they are 654 * Some of the on-chip devices are actually '586 devices' so they are
649 * listed here. 655 * listed here.
650 */ 656 */
657
658static int via_irq_fixup_needed = -1;
659
660/*
661 * As some VIA hardware is available in PCI-card form, we need to restrict
662 * this quirk to VIA PCI hardware built onto VIA-based motherboards only.
663 * We try to locate a VIA southbridge before deciding whether the quirk
664 * should be applied.
665 */
666static const struct pci_device_id via_irq_fixup_tbl[] = {
667 {
668 .vendor = PCI_VENDOR_ID_VIA,
669 .device = PCI_ANY_ID,
670 .subvendor = PCI_ANY_ID,
671 .subdevice = PCI_ANY_ID,
672 .class = PCI_CLASS_BRIDGE_ISA << 8,
673 .class_mask = 0xffff00,
674 },
675 { 0, },
676};
677
651static void quirk_via_irq(struct pci_dev *dev) 678static void quirk_via_irq(struct pci_dev *dev)
652{ 679{
653 u8 irq, new_irq; 680 u8 irq, new_irq;
654 681
655 new_irq = dev->irq & 0xf; 682 if (via_irq_fixup_needed == -1)
683 via_irq_fixup_needed = pci_dev_present(via_irq_fixup_tbl);
684
685 if (!via_irq_fixup_needed)
686 return;
687
688 new_irq = dev->irq;
689
690 /* Don't quirk interrupts outside the legacy IRQ range */
691 if (!new_irq || new_irq > 15)
692 return;
693
656 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq); 694 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
657 if (new_irq != irq) { 695 if (new_irq != irq) {
658 printk(KERN_INFO "PCI: VIA IRQ fixup for %s, from %d to %d\n", 696 printk(KERN_INFO "PCI: VIA IRQ fixup for %s, from %d to %d\n",
@@ -661,14 +699,7 @@ static void quirk_via_irq(struct pci_dev *dev)
661 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq); 699 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq);
662 } 700 }
663} 701}
664DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_0, quirk_via_irq); 702DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_irq);
665DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, quirk_via_irq);
666DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_2, quirk_via_irq);
667DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_via_irq);
668DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235_USB_2, quirk_via_irq);
669DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_irq);
670DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_via_irq);
671DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, quirk_via_irq);
672 703
673/* 704/*
674 * VIA VT82C598 has its device ID settable and many BIOSes 705 * VIA VT82C598 has its device ID settable and many BIOSes
@@ -683,33 +714,6 @@ static void __devinit quirk_vt82c598_id(struct pci_dev *dev)
683} 714}
684DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C597_0, quirk_vt82c598_id ); 715DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C597_0, quirk_vt82c598_id );
685 716
686#ifdef CONFIG_ACPI_SLEEP
687
688/*
689 * Some VIA systems boot with the abnormal status flag set. This can cause
690 * the BIOS to re-POST the system on resume rather than passing control
691 * back to the OS. Clear the flag on boot
692 */
693static void __devinit quirk_via_abnormal_poweroff(struct pci_dev *dev)
694{
695 u32 reg;
696
697 acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS,
698 &reg);
699
700 if (reg & 0x800) {
701 printk("Clearing abnormal poweroff flag\n");
702 acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
703 ACPI_REGISTER_PM1_STATUS,
704 (u16)0x800);
705 }
706}
707
708DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_via_abnormal_poweroff);
709DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_abnormal_poweroff);
710
711#endif
712
713/* 717/*
714 * CardBus controllers have a legacy base address that enables them 718 * CardBus controllers have a legacy base address that enables them
715 * to respond as i82365 pcmcia controllers. We don't want them to 719 * to respond as i82365 pcmcia controllers. We don't want them to
@@ -793,56 +797,6 @@ static void __init quirk_mediagx_master(struct pci_dev *dev)
793DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master ); 797DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master );
794 798
795/* 799/*
796 * As per PCI spec, ignore base address registers 0-3 of the IDE controllers
797 * running in Compatible mode (bits 0 and 2 in the ProgIf for primary and
798 * secondary channels respectively). If the device reports Compatible mode
799 * but does use BAR0-3 for address decoding, we assume that firmware has
800 * programmed these BARs with standard values (0x1f0,0x3f4 and 0x170,0x374).
801 * Exceptions (if they exist) must be handled in chip/architecture specific
802 * fixups.
803 *
804 * Note: for non x86 people. You may need an arch specific quirk to handle
805 * moving IDE devices to native mode as well. Some plug in card devices power
806 * up in compatible mode and assume the BIOS will adjust them.
807 *
808 * Q: should we load the 0x1f0,0x3f4 into the registers or zap them as
809 * we do now ? We don't want is pci_enable_device to come along
810 * and assign new resources. Both approaches work for that.
811 */
812static void __devinit quirk_ide_bases(struct pci_dev *dev)
813{
814 struct resource *res;
815 int first_bar = 2, last_bar = 0;
816
817 if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
818 return;
819
820 res = &dev->resource[0];
821
822 /* primary channel: ProgIf bit 0, BAR0, BAR1 */
823 if (!(dev->class & 1) && (res[0].flags || res[1].flags)) {
824 res[0].start = res[0].end = res[0].flags = 0;
825 res[1].start = res[1].end = res[1].flags = 0;
826 first_bar = 0;
827 last_bar = 1;
828 }
829
830 /* secondary channel: ProgIf bit 2, BAR2, BAR3 */
831 if (!(dev->class & 4) && (res[2].flags || res[3].flags)) {
832 res[2].start = res[2].end = res[2].flags = 0;
833 res[3].start = res[3].end = res[3].flags = 0;
834 last_bar = 3;
835 }
836
837 if (!last_bar)
838 return;
839
840 printk(KERN_INFO "PCI: Ignoring BAR%d-%d of IDE controller %s\n",
841 first_bar, last_bar, pci_name(dev));
842}
843DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, quirk_ide_bases);
844
845/*
846 * Ensure C0 rev restreaming is off. This is normally done by 800 * Ensure C0 rev restreaming is off. This is normally done by
847 * the BIOS but in the odd case it is not the results are corruption 801 * the BIOS but in the odd case it is not the results are corruption
848 * hence the presence of a Linux check 802 * hence the presence of a Linux check
@@ -876,11 +830,10 @@ static void __devinit quirk_svwks_csb5ide(struct pci_dev *pdev)
876 prog &= ~5; 830 prog &= ~5;
877 pdev->class &= ~5; 831 pdev->class &= ~5;
878 pci_write_config_byte(pdev, PCI_CLASS_PROG, prog); 832 pci_write_config_byte(pdev, PCI_CLASS_PROG, prog);
879 /* need to re-assign BARs for compat mode */ 833 /* PCI layer will sort out resources */
880 quirk_ide_bases(pdev);
881 } 834 }
882} 835}
883DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, quirk_svwks_csb5ide ); 836DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, quirk_svwks_csb5ide );
884 837
885/* 838/*
886 * Intel 82801CAM ICH3-M datasheet says IDE modes must be the same 839 * Intel 82801CAM ICH3-M datasheet says IDE modes must be the same
@@ -896,11 +849,9 @@ static void __init quirk_ide_samemode(struct pci_dev *pdev)
896 prog &= ~5; 849 prog &= ~5;
897 pdev->class &= ~5; 850 pdev->class &= ~5;
898 pci_write_config_byte(pdev, PCI_CLASS_PROG, prog); 851 pci_write_config_byte(pdev, PCI_CLASS_PROG, prog);
899 /* need to re-assign BARs for compat mode */
900 quirk_ide_bases(pdev);
901 } 852 }
902} 853}
903DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_10, quirk_ide_samemode); 854DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_10, quirk_ide_samemode);
904 855
905/* This was originally an Alpha specific thing, but it really fits here. 856/* This was originally an Alpha specific thing, but it really fits here.
906 * The i82375 PCI/EISA bridge appears as non-classified. Fix that. 857 * The i82375 PCI/EISA bridge appears as non-classified. Fix that.
@@ -1456,33 +1407,6 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2609, quirk_intel_pcie_pm);
1456DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x260a, quirk_intel_pcie_pm); 1407DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x260a, quirk_intel_pcie_pm);
1457DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x260b, quirk_intel_pcie_pm); 1408DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x260b, quirk_intel_pcie_pm);
1458 1409
1459/*
1460 * Fixup the cardbus bridges on the IBM Dock II docking station
1461 */
1462static void __devinit quirk_ibm_dock2_cardbus(struct pci_dev *dev)
1463{
1464 u32 val;
1465
1466 /*
1467 * tie the 2 interrupt pins to INTA, and configure the
1468 * multifunction routing register to handle this.
1469 */
1470 if ((dev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
1471 (dev->subsystem_device == 0x0148)) {
1472 printk(KERN_INFO "PCI: Found IBM Dock II Cardbus Bridge "
1473 "applying quirk\n");
1474 pci_read_config_dword(dev, 0x8c, &val);
1475 val = ((val & 0xffffff00) | 0x1002);
1476 pci_write_config_dword(dev, 0x8c, val);
1477 pci_read_config_dword(dev, 0x80, &val);
1478 val = ((val & 0x00ffff00) | 0x2864c077);
1479 pci_write_config_dword(dev, 0x80, val);
1480 }
1481}
1482
1483DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1420,
1484 quirk_ibm_dock2_cardbus);
1485
1486static void __devinit quirk_netmos(struct pci_dev *dev) 1410static void __devinit quirk_netmos(struct pci_dev *dev)
1487{ 1411{
1488 unsigned int num_parallel = (dev->subsystem_device & 0xf0) >> 4; 1412 unsigned int num_parallel = (dev->subsystem_device & 0xf0) >> 4;
@@ -1588,7 +1512,6 @@ static void __devinit fixup_rev1_53c810(struct pci_dev* dev)
1588} 1512}
1589DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NCR, PCI_DEVICE_ID_NCR_53C810, fixup_rev1_53c810); 1513DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NCR, PCI_DEVICE_ID_NCR_53C810, fixup_rev1_53c810);
1590 1514
1591
1592static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f, struct pci_fixup *end) 1515static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f, struct pci_fixup *end)
1593{ 1516{
1594 while (f < end) { 1517 while (f < end) {
@@ -1764,7 +1687,7 @@ static void __devinit quirk_nvidia_ck804_msi_ht_cap(struct pci_dev *dev)
1764 /* check HT MSI cap on this chipset and the root one. 1687 /* check HT MSI cap on this chipset and the root one.
1765 * a single one having MSI is enough to be sure that MSI are supported. 1688 * a single one having MSI is enough to be sure that MSI are supported.
1766 */ 1689 */
1767 pdev = pci_find_slot(dev->bus->number, 0); 1690 pdev = pci_get_slot(dev->bus, 0);
1768 if (dev->subordinate && !msi_ht_cap_enabled(dev) 1691 if (dev->subordinate && !msi_ht_cap_enabled(dev)
1769 && !msi_ht_cap_enabled(pdev)) { 1692 && !msi_ht_cap_enabled(pdev)) {
1770 printk(KERN_WARNING "PCI: MSI quirk detected. " 1693 printk(KERN_WARNING "PCI: MSI quirk detected. "
@@ -1772,6 +1695,7 @@ static void __devinit quirk_nvidia_ck804_msi_ht_cap(struct pci_dev *dev)
1772 pci_name(dev)); 1695 pci_name(dev));
1773 dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI; 1696 dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
1774 } 1697 }
1698 pci_dev_put(pdev);
1775} 1699}
1776DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, 1700DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1777 quirk_nvidia_ck804_msi_ht_cap); 1701 quirk_nvidia_ck804_msi_ht_cap);
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index f5ee7ce16fa6..d087e0817715 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -71,13 +71,18 @@ void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
71 void __iomem *image; 71 void __iomem *image;
72 int last_image; 72 int last_image;
73 73
74 /* IORESOURCE_ROM_SHADOW only set on x86 */ 74 /*
75 * IORESOURCE_ROM_SHADOW set on x86, x86_64 and IA64 supports legacy
76 * memory map if the VGA enable bit of the Bridge Control register is
77 * set for embedded VGA.
78 */
75 if (res->flags & IORESOURCE_ROM_SHADOW) { 79 if (res->flags & IORESOURCE_ROM_SHADOW) {
76 /* primary video rom always starts here */ 80 /* primary video rom always starts here */
77 start = (loff_t)0xC0000; 81 start = (loff_t)0xC0000;
78 *size = 0x20000; /* cover C000:0 through E000:0 */ 82 *size = 0x20000; /* cover C000:0 through E000:0 */
79 } else { 83 } else {
80 if (res->flags & IORESOURCE_ROM_COPY) { 84 if (res->flags &
85 (IORESOURCE_ROM_COPY | IORESOURCE_ROM_BIOS_COPY)) {
81 *size = pci_resource_len(pdev, PCI_ROM_RESOURCE); 86 *size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
82 return (void __iomem *)(unsigned long) 87 return (void __iomem *)(unsigned long)
83 pci_resource_start(pdev, PCI_ROM_RESOURCE); 88 pci_resource_start(pdev, PCI_ROM_RESOURCE);
@@ -161,7 +166,8 @@ void __iomem *pci_map_rom_copy(struct pci_dev *pdev, size_t *size)
161 if (!rom) 166 if (!rom)
162 return NULL; 167 return NULL;
163 168
164 if (res->flags & (IORESOURCE_ROM_COPY | IORESOURCE_ROM_SHADOW)) 169 if (res->flags & (IORESOURCE_ROM_COPY | IORESOURCE_ROM_SHADOW |
170 IORESOURCE_ROM_BIOS_COPY))
165 return rom; 171 return rom;
166 172
167 res->start = (unsigned long)kmalloc(*size, GFP_KERNEL); 173 res->start = (unsigned long)kmalloc(*size, GFP_KERNEL);
@@ -187,7 +193,7 @@ void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom)
187{ 193{
188 struct resource *res = &pdev->resource[PCI_ROM_RESOURCE]; 194 struct resource *res = &pdev->resource[PCI_ROM_RESOURCE];
189 195
190 if (res->flags & IORESOURCE_ROM_COPY) 196 if (res->flags & (IORESOURCE_ROM_COPY | IORESOURCE_ROM_BIOS_COPY))
191 return; 197 return;
192 198
193 iounmap(rom); 199 iounmap(rom);
@@ -211,6 +217,7 @@ void pci_remove_rom(struct pci_dev *pdev)
211 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr); 217 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
212 if (!(res->flags & (IORESOURCE_ROM_ENABLE | 218 if (!(res->flags & (IORESOURCE_ROM_ENABLE |
213 IORESOURCE_ROM_SHADOW | 219 IORESOURCE_ROM_SHADOW |
220 IORESOURCE_ROM_BIOS_COPY |
214 IORESOURCE_ROM_COPY))) 221 IORESOURCE_ROM_COPY)))
215 pci_disable_rom(pdev); 222 pci_disable_rom(pdev);
216} 223}
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index d529462d1b53..2f13eba5d5ae 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -140,6 +140,31 @@ struct pci_dev * pci_get_slot(struct pci_bus *bus, unsigned int devfn)
140} 140}
141 141
142/** 142/**
143 * pci_get_bus_and_slot - locate PCI device from a given PCI slot
144 * @bus: number of PCI bus on which desired PCI device resides
145 * @devfn: encodes number of PCI slot in which the desired PCI
146 * device resides and the logical device number within that slot
147 * in case of multi-function devices.
148 *
149 * Given a PCI bus and slot/function number, the desired PCI device
150 * is located in system global list of PCI devices. If the device
151 * is found, a pointer to its data structure is returned. If no
152 * device is found, %NULL is returned. The returned device has its
153 * reference count bumped by one.
154 */
155
156struct pci_dev * pci_get_bus_and_slot(unsigned int bus, unsigned int devfn)
157{
158 struct pci_dev *dev = NULL;
159
160 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
161 if (dev->bus->number == bus && dev->devfn == devfn)
162 return dev;
163 }
164 return NULL;
165}
166
167/**
143 * pci_find_subsys - begin or continue searching for a PCI device by vendor/subvendor/device/subdevice id 168 * pci_find_subsys - begin or continue searching for a PCI device by vendor/subvendor/device/subdevice id
144 * @vendor: PCI vendor id to match, or %PCI_ANY_ID to match all vendor ids 169 * @vendor: PCI vendor id to match, or %PCI_ANY_ID to match all vendor ids
145 * @device: PCI device id to match, or %PCI_ANY_ID to match all device ids 170 * @device: PCI device id to match, or %PCI_ANY_ID to match all device ids
@@ -274,6 +299,45 @@ pci_get_device(unsigned int vendor, unsigned int device, struct pci_dev *from)
274 return pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from); 299 return pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
275} 300}
276 301
302/**
303 * pci_get_device_reverse - begin or continue searching for a PCI device by vendor/device id
304 * @vendor: PCI vendor id to match, or %PCI_ANY_ID to match all vendor ids
305 * @device: PCI device id to match, or %PCI_ANY_ID to match all device ids
306 * @from: Previous PCI device found in search, or %NULL for new search.
307 *
308 * Iterates through the list of known PCI devices in the reverse order of
309 * pci_get_device.
310 * If a PCI device is found with a matching @vendor and @device, the reference
311 * count to the device is incremented and a pointer to its device structure
312 * is returned Otherwise, %NULL is returned. A new search is initiated by
313 * passing %NULL as the @from argument. Otherwise if @from is not %NULL,
314 * searches continue from next device on the global list. The reference
315 * count for @from is always decremented if it is not %NULL.
316 */
317struct pci_dev *
318pci_get_device_reverse(unsigned int vendor, unsigned int device, struct pci_dev *from)
319{
320 struct list_head *n;
321 struct pci_dev *dev;
322
323 WARN_ON(in_interrupt());
324 down_read(&pci_bus_sem);
325 n = from ? from->global_list.prev : pci_devices.prev;
326
327 while (n && (n != &pci_devices)) {
328 dev = pci_dev_g(n);
329 if ((vendor == PCI_ANY_ID || dev->vendor == vendor) &&
330 (device == PCI_ANY_ID || dev->device == device))
331 goto exit;
332 n = n->prev;
333 }
334 dev = NULL;
335exit:
336 dev = pci_dev_get(dev);
337 up_read(&pci_bus_sem);
338 pci_dev_put(from);
339 return dev;
340}
277 341
278/** 342/**
279 * pci_find_device_reverse - begin or continue searching for a PCI device by vendor/device id 343 * pci_find_device_reverse - begin or continue searching for a PCI device by vendor/device id
@@ -382,12 +446,16 @@ exit:
382} 446}
383EXPORT_SYMBOL(pci_dev_present); 447EXPORT_SYMBOL(pci_dev_present);
384 448
385EXPORT_SYMBOL(pci_find_bus);
386EXPORT_SYMBOL(pci_find_next_bus);
387EXPORT_SYMBOL(pci_find_device); 449EXPORT_SYMBOL(pci_find_device);
388EXPORT_SYMBOL(pci_find_device_reverse); 450EXPORT_SYMBOL(pci_find_device_reverse);
389EXPORT_SYMBOL(pci_find_slot); 451EXPORT_SYMBOL(pci_find_slot);
452/* For boot time work */
453EXPORT_SYMBOL(pci_find_bus);
454EXPORT_SYMBOL(pci_find_next_bus);
455/* For everyone */
390EXPORT_SYMBOL(pci_get_device); 456EXPORT_SYMBOL(pci_get_device);
457EXPORT_SYMBOL(pci_get_device_reverse);
391EXPORT_SYMBOL(pci_get_subsys); 458EXPORT_SYMBOL(pci_get_subsys);
392EXPORT_SYMBOL(pci_get_slot); 459EXPORT_SYMBOL(pci_get_slot);
460EXPORT_SYMBOL(pci_get_bus_and_slot);
393EXPORT_SYMBOL(pci_get_class); 461EXPORT_SYMBOL(pci_get_class);