aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 12:30:25 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 12:30:25 -0400
commit96a3e8af5a54c324535472ca946215d5bafe6539 (patch)
treee59b48aa3fa2b8c6c1f59f76b7b4c71f9c694093 /drivers
parenta87451052fb914744571fc3ab39fcbf4fa4ef944 (diff)
parentd4f09c5d7fbabd1389a5f03f5c9329d790f544e3 (diff)
Merge tag 'pci-v3.10-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci
Pull PCI updates from Bjorn Helgaas: "PCI changes for the v3.10 merge window: PCI device hotplug - Remove ACPI PCI subdrivers (Jiang Liu, Myron Stowe) - Make acpiphp builtin only, not modular (Jiang Liu) - Add acpiphp mutual exclusion (Jiang Liu) Power management - Skip "PME enabled/disabled" messages when not supported (Rafael Wysocki) - Fix fallback to PCI_D0 (Rafael Wysocki) Miscellaneous - Factor quirk_io_region (Yinghai Lu) - Cache MSI capability offsets & cleanup (Gavin Shan, Bjorn Helgaas) - Clean up EISA resource initialization and logging (Bjorn Helgaas) - Fix prototype warnings (Andy Shevchenko, Bjorn Helgaas) - MIPS: Initialize of_node before scanning bus (Gabor Juhos) - Fix pcibios_get_phb_of_node() declaration "weak" annotation (Gabor Juhos) - Add MSI INTX_DISABLE quirks for AR8161/AR8162/etc (Xiong Huang) - Fix aer_inject return values (Prarit Bhargava) - Remove PME/ACPI dependency (Andrew Murray) - Use shared PCI_BUS_NUM() and PCI_DEVID() (Shuah Khan)" * tag 'pci-v3.10-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci: (63 commits) vfio-pci: Use cached MSI/MSI-X capabilities vfio-pci: Use PCI_MSIX_TABLE_BIR, not PCI_MSIX_FLAGS_BIRMASK PCI: Remove "extern" from function declarations PCI: Use PCI_MSIX_TABLE_BIR, not PCI_MSIX_FLAGS_BIRMASK PCI: Drop msi_mask_reg() and remove drivers/pci/msi.h PCI: Use msix_table_size() directly, drop multi_msix_capable() PCI: Drop msix_table_offset_reg() and msix_pba_offset_reg() macros PCI: Drop is_64bit_address() and is_mask_bit_support() macros PCI: Drop msi_data_reg() macro PCI: Drop msi_lower_address_reg() and msi_upper_address_reg() macros PCI: Drop msi_control_reg() macro and use PCI_MSI_FLAGS directly PCI: Use cached MSI/MSI-X offsets from dev, not from msi_desc PCI: Clean up MSI/MSI-X capability #defines PCI: Use cached MSI-X cap while enabling MSI-X PCI: Use cached MSI cap while enabling MSI interrupts PCI: Remove MSI/MSI-X cap check in pci_msi_check_device() PCI: Cache MSI/MSI-X capability offsets in struct pci_dev PCI: Use u8, not int, for PM capability offset [SCSI] megaraid_sas: Use correct #define for MSI-X capability PCI: Remove "extern" from function declarations ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/pci_root.c48
-rw-r--r--drivers/acpi/pci_slot.c170
-rw-r--r--drivers/acpi/scan.c1
-rw-r--r--drivers/ata/ahci.c10
-rw-r--r--drivers/eisa/eisa-bus.c82
-rw-r--r--drivers/eisa/pci_eisa.c5
-rw-r--r--drivers/iommu/amd_iommu.c14
-rw-r--r--drivers/iommu/amd_iommu_init.c40
-rw-r--r--drivers/iommu/amd_iommu_types.h11
-rw-r--r--drivers/pci/bus.c14
-rw-r--r--drivers/pci/hotplug/Kconfig7
-rw-r--r--drivers/pci/hotplug/acpiphp.h35
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c30
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c415
-rw-r--r--drivers/pci/hotplug/cpci_hotplug.h44
-rw-r--r--drivers/pci/hotplug/cpqphp.h70
-rw-r--r--drivers/pci/hotplug/cpqphp_nvram.h12
-rw-r--r--drivers/pci/hotplug/ibmphp.h66
-rw-r--r--drivers/pci/hotplug/pci_hotplug_core.c15
-rw-r--r--drivers/pci/hotplug/pciehp.h22
-rw-r--r--drivers/pci/hotplug/pciehp_acpi.c2
-rw-r--r--drivers/pci/hotplug/rpadlpar.h8
-rw-r--r--drivers/pci/hotplug/rpaphp.h16
-rw-r--r--drivers/pci/hotplug/shpchp.h26
-rw-r--r--drivers/pci/hotplug/shpchp_sysfs.c2
-rw-r--r--drivers/pci/msi.c180
-rw-r--r--drivers/pci/msi.h24
-rw-r--r--drivers/pci/pci-acpi.c30
-rw-r--r--drivers/pci/pci-sysfs.c2
-rw-r--r--drivers/pci/pci.c25
-rw-r--r--drivers/pci/pci.h89
-rw-r--r--drivers/pci/pcie/Kconfig2
-rw-r--r--drivers/pci/pcie/aer/aer_inject.c10
-rw-r--r--drivers/pci/pcie/aer/aerdrv.h14
-rw-r--r--drivers/pci/pcie/aer/aerdrv_core.c4
-rw-r--r--drivers/pci/pcie/pme.c2
-rw-r--r--drivers/pci/pcie/portdrv.h18
-rw-r--r--drivers/pci/pcie/portdrv_acpi.c1
-rw-r--r--drivers/pci/pcie/portdrv_pci.c17
-rw-r--r--drivers/pci/probe.c15
-rw-r--r--drivers/pci/quirks.c148
-rw-r--r--drivers/pci/remove.c4
-rw-r--r--drivers/pci/setup-bus.c4
-rw-r--r--drivers/pci/setup-res.c2
-rw-r--r--drivers/pci/slot.c7
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h3
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_base.c4
-rw-r--r--drivers/scsi/mvsas/mv_init.c6
-rw-r--r--drivers/scsi/mvumi.c4
-rw-r--r--drivers/scsi/mvumi.h1
-rw-r--r--drivers/vfio/pci/vfio_pci.c10
51 files changed, 699 insertions, 1092 deletions
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 6ae5e440436e..ac8688b89705 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -65,44 +65,12 @@ static struct acpi_scan_handler pci_root_handler = {
65 .detach = acpi_pci_root_remove, 65 .detach = acpi_pci_root_remove,
66}; 66};
67 67
68/* Lock to protect both acpi_pci_roots and acpi_pci_drivers lists */ 68/* Lock to protect both acpi_pci_roots lists */
69static DEFINE_MUTEX(acpi_pci_root_lock); 69static DEFINE_MUTEX(acpi_pci_root_lock);
70static LIST_HEAD(acpi_pci_roots); 70static LIST_HEAD(acpi_pci_roots);
71static LIST_HEAD(acpi_pci_drivers);
72 71
73static DEFINE_MUTEX(osc_lock); 72static DEFINE_MUTEX(osc_lock);
74 73
75int acpi_pci_register_driver(struct acpi_pci_driver *driver)
76{
77 int n = 0;
78 struct acpi_pci_root *root;
79
80 mutex_lock(&acpi_pci_root_lock);
81 list_add_tail(&driver->node, &acpi_pci_drivers);
82 if (driver->add)
83 list_for_each_entry(root, &acpi_pci_roots, node) {
84 driver->add(root);
85 n++;
86 }
87 mutex_unlock(&acpi_pci_root_lock);
88
89 return n;
90}
91EXPORT_SYMBOL(acpi_pci_register_driver);
92
93void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
94{
95 struct acpi_pci_root *root;
96
97 mutex_lock(&acpi_pci_root_lock);
98 list_del(&driver->node);
99 if (driver->remove)
100 list_for_each_entry(root, &acpi_pci_roots, node)
101 driver->remove(root);
102 mutex_unlock(&acpi_pci_root_lock);
103}
104EXPORT_SYMBOL(acpi_pci_unregister_driver);
105
106/** 74/**
107 * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge 75 * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
108 * @handle - the ACPI CA node in question. 76 * @handle - the ACPI CA node in question.
@@ -413,7 +381,6 @@ static int acpi_pci_root_add(struct acpi_device *device,
413 acpi_status status; 381 acpi_status status;
414 int result; 382 int result;
415 struct acpi_pci_root *root; 383 struct acpi_pci_root *root;
416 struct acpi_pci_driver *driver;
417 u32 flags, base_flags; 384 u32 flags, base_flags;
418 385
419 root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL); 386 root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
@@ -571,12 +538,6 @@ static int acpi_pci_root_add(struct acpi_device *device,
571 pci_assign_unassigned_bus_resources(root->bus); 538 pci_assign_unassigned_bus_resources(root->bus);
572 } 539 }
573 540
574 mutex_lock(&acpi_pci_root_lock);
575 list_for_each_entry(driver, &acpi_pci_drivers, node)
576 if (driver->add)
577 driver->add(root);
578 mutex_unlock(&acpi_pci_root_lock);
579
580 /* need to after hot-added ioapic is registered */ 541 /* need to after hot-added ioapic is registered */
581 if (system_state != SYSTEM_BOOTING) 542 if (system_state != SYSTEM_BOOTING)
582 pci_enable_bridges(root->bus); 543 pci_enable_bridges(root->bus);
@@ -597,16 +558,9 @@ end:
597static void acpi_pci_root_remove(struct acpi_device *device) 558static void acpi_pci_root_remove(struct acpi_device *device)
598{ 559{
599 struct acpi_pci_root *root = acpi_driver_data(device); 560 struct acpi_pci_root *root = acpi_driver_data(device);
600 struct acpi_pci_driver *driver;
601 561
602 pci_stop_root_bus(root->bus); 562 pci_stop_root_bus(root->bus);
603 563
604 mutex_lock(&acpi_pci_root_lock);
605 list_for_each_entry_reverse(driver, &acpi_pci_drivers, node)
606 if (driver->remove)
607 driver->remove(root);
608 mutex_unlock(&acpi_pci_root_lock);
609
610 device_set_run_wake(root->bus->bridge, false); 564 device_set_run_wake(root->bus->bridge, false);
611 pci_acpi_remove_bus_pm_notifier(device); 565 pci_acpi_remove_bus_pm_notifier(device);
612 566
diff --git a/drivers/acpi/pci_slot.c b/drivers/acpi/pci_slot.c
index cd1434eb1de8..033d1179bdb5 100644
--- a/drivers/acpi/pci_slot.c
+++ b/drivers/acpi/pci_slot.c
@@ -9,6 +9,9 @@
9 * Copyright (C) 2007-2008 Hewlett-Packard Development Company, L.P. 9 * Copyright (C) 2007-2008 Hewlett-Packard Development Company, L.P.
10 * Alex Chiang <achiang@hp.com> 10 * Alex Chiang <achiang@hp.com>
11 * 11 *
12 * Copyright (C) 2013 Huawei Tech. Co., Ltd.
13 * Jiang Liu <jiang.liu@huawei.com>
14 *
12 * This program is free software; you can redistribute it and/or modify it 15 * This program is free software; you can redistribute it and/or modify it
13 * under the terms and conditions of the GNU General Public License, 16 * under the terms and conditions of the GNU General Public License,
14 * version 2, as published by the Free Software Foundation. 17 * version 2, as published by the Free Software Foundation.
@@ -28,10 +31,9 @@
28#include <linux/init.h> 31#include <linux/init.h>
29#include <linux/slab.h> 32#include <linux/slab.h>
30#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/list.h>
31#include <linux/pci.h> 35#include <linux/pci.h>
32#include <linux/acpi.h> 36#include <linux/acpi.h>
33#include <acpi/acpi_bus.h>
34#include <acpi/acpi_drivers.h>
35#include <linux/dmi.h> 37#include <linux/dmi.h>
36 38
37static bool debug; 39static bool debug;
@@ -61,20 +63,12 @@ ACPI_MODULE_NAME("pci_slot");
61#define SLOT_NAME_SIZE 21 /* Inspired by #define in acpiphp.h */ 63#define SLOT_NAME_SIZE 21 /* Inspired by #define in acpiphp.h */
62 64
63struct acpi_pci_slot { 65struct acpi_pci_slot {
64 acpi_handle root_handle; /* handle of the root bridge */
65 struct pci_slot *pci_slot; /* corresponding pci_slot */ 66 struct pci_slot *pci_slot; /* corresponding pci_slot */
66 struct list_head list; /* node in the list of slots */ 67 struct list_head list; /* node in the list of slots */
67}; 68};
68 69
69static int acpi_pci_slot_add(struct acpi_pci_root *root);
70static void acpi_pci_slot_remove(struct acpi_pci_root *root);
71
72static LIST_HEAD(slot_list); 70static LIST_HEAD(slot_list);
73static DEFINE_MUTEX(slot_list_lock); 71static DEFINE_MUTEX(slot_list_lock);
74static struct acpi_pci_driver acpi_pci_slot_driver = {
75 .add = acpi_pci_slot_add,
76 .remove = acpi_pci_slot_remove,
77};
78 72
79static int 73static int
80check_slot(acpi_handle handle, unsigned long long *sun) 74check_slot(acpi_handle handle, unsigned long long *sun)
@@ -113,21 +107,8 @@ out:
113 return device; 107 return device;
114} 108}
115 109
116struct callback_args {
117 acpi_walk_callback user_function; /* only for walk_p2p_bridge */
118 struct pci_bus *pci_bus;
119 acpi_handle root_handle;
120};
121
122/* 110/*
123 * register_slot 111 * Check whether handle has an associated slot and create PCI slot if it has.
124 *
125 * Called once for each SxFy object in the namespace. Don't worry about
126 * calling pci_create_slot multiple times for the same pci_bus:device,
127 * since each subsequent call simply bumps the refcount on the pci_slot.
128 *
129 * The number of calls to pci_destroy_slot from unregister_slot is
130 * symmetrical.
131 */ 112 */
132static acpi_status 113static acpi_status
133register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) 114register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
@@ -137,13 +118,22 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
137 char name[SLOT_NAME_SIZE]; 118 char name[SLOT_NAME_SIZE];
138 struct acpi_pci_slot *slot; 119 struct acpi_pci_slot *slot;
139 struct pci_slot *pci_slot; 120 struct pci_slot *pci_slot;
140 struct callback_args *parent_context = context; 121 struct pci_bus *pci_bus = context;
141 struct pci_bus *pci_bus = parent_context->pci_bus;
142 122
143 device = check_slot(handle, &sun); 123 device = check_slot(handle, &sun);
144 if (device < 0) 124 if (device < 0)
145 return AE_OK; 125 return AE_OK;
146 126
127 /*
128 * There may be multiple PCI functions associated with the same slot.
129 * Check whether PCI slot has already been created for this PCI device.
130 */
131 list_for_each_entry(slot, &slot_list, list) {
132 pci_slot = slot->pci_slot;
133 if (pci_slot->bus == pci_bus && pci_slot->number == device)
134 return AE_OK;
135 }
136
147 slot = kmalloc(sizeof(*slot), GFP_KERNEL); 137 slot = kmalloc(sizeof(*slot), GFP_KERNEL);
148 if (!slot) { 138 if (!slot) {
149 err("%s: cannot allocate memory\n", __func__); 139 err("%s: cannot allocate memory\n", __func__);
@@ -158,12 +148,8 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
158 return AE_OK; 148 return AE_OK;
159 } 149 }
160 150
161 slot->root_handle = parent_context->root_handle;
162 slot->pci_slot = pci_slot; 151 slot->pci_slot = pci_slot;
163 INIT_LIST_HEAD(&slot->list);
164 mutex_lock(&slot_list_lock);
165 list_add(&slot->list, &slot_list); 152 list_add(&slot->list, &slot_list);
166 mutex_unlock(&slot_list_lock);
167 153
168 get_device(&pci_bus->dev); 154 get_device(&pci_bus->dev);
169 155
@@ -173,131 +159,24 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
173 return AE_OK; 159 return AE_OK;
174} 160}
175 161
176/* 162void acpi_pci_slot_enumerate(struct pci_bus *bus, acpi_handle handle)
177 * walk_p2p_bridge - discover and walk p2p bridges
178 * @handle: points to an acpi_pci_root
179 * @context: p2p_bridge_context pointer
180 *
181 * Note that when we call ourselves recursively, we pass a different
182 * value of pci_bus in the child_context.
183 */
184static acpi_status
185walk_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
186{
187 int device, function;
188 unsigned long long adr;
189 acpi_status status;
190 acpi_handle dummy_handle;
191 acpi_walk_callback user_function;
192
193 struct pci_dev *dev;
194 struct pci_bus *pci_bus;
195 struct callback_args child_context;
196 struct callback_args *parent_context = context;
197
198 pci_bus = parent_context->pci_bus;
199 user_function = parent_context->user_function;
200
201 status = acpi_get_handle(handle, "_ADR", &dummy_handle);
202 if (ACPI_FAILURE(status))
203 return AE_OK;
204
205 status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
206 if (ACPI_FAILURE(status))
207 return AE_OK;
208
209 device = (adr >> 16) & 0xffff;
210 function = adr & 0xffff;
211
212 dev = pci_get_slot(pci_bus, PCI_DEVFN(device, function));
213 if (!dev || !dev->subordinate)
214 goto out;
215
216 child_context.pci_bus = dev->subordinate;
217 child_context.user_function = user_function;
218 child_context.root_handle = parent_context->root_handle;
219
220 dbg("p2p bridge walk, pci_bus = %x\n", dev->subordinate->number);
221 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
222 user_function, NULL, &child_context, NULL);
223 if (ACPI_FAILURE(status))
224 goto out;
225
226 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
227 walk_p2p_bridge, NULL, &child_context, NULL);
228out:
229 pci_dev_put(dev);
230 return AE_OK;
231}
232
233/*
234 * walk_root_bridge - generic root bridge walker
235 * @root: poiner of an acpi_pci_root
236 * @user_function: user callback for slot objects
237 *
238 * Call user_function for all objects underneath this root bridge.
239 * Walk p2p bridges underneath us and call user_function on those too.
240 */
241static int
242walk_root_bridge(struct acpi_pci_root *root, acpi_walk_callback user_function)
243{
244 acpi_status status;
245 acpi_handle handle = root->device->handle;
246 struct pci_bus *pci_bus = root->bus;
247 struct callback_args context;
248
249 context.pci_bus = pci_bus;
250 context.user_function = user_function;
251 context.root_handle = handle;
252
253 dbg("root bridge walk, pci_bus = %x\n", pci_bus->number);
254 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
255 user_function, NULL, &context, NULL);
256 if (ACPI_FAILURE(status))
257 return status;
258
259 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
260 walk_p2p_bridge, NULL, &context, NULL);
261 if (ACPI_FAILURE(status))
262 err("%s: walk_p2p_bridge failure - %d\n", __func__, status);
263
264 return status;
265}
266
267/*
268 * acpi_pci_slot_add
269 * @handle: points to an acpi_pci_root
270 */
271static int
272acpi_pci_slot_add(struct acpi_pci_root *root)
273{ 163{
274 acpi_status status; 164 mutex_lock(&slot_list_lock);
275 165 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
276 status = walk_root_bridge(root, register_slot); 166 register_slot, NULL, bus, NULL);
277 if (ACPI_FAILURE(status)) 167 mutex_unlock(&slot_list_lock);
278 err("%s: register_slot failure - %d\n", __func__, status);
279
280 return status;
281} 168}
282 169
283/* 170void acpi_pci_slot_remove(struct pci_bus *bus)
284 * acpi_pci_slot_remove
285 * @handle: points to an acpi_pci_root
286 */
287static void
288acpi_pci_slot_remove(struct acpi_pci_root *root)
289{ 171{
290 struct acpi_pci_slot *slot, *tmp; 172 struct acpi_pci_slot *slot, *tmp;
291 struct pci_bus *pbus;
292 acpi_handle handle = root->device->handle;
293 173
294 mutex_lock(&slot_list_lock); 174 mutex_lock(&slot_list_lock);
295 list_for_each_entry_safe(slot, tmp, &slot_list, list) { 175 list_for_each_entry_safe(slot, tmp, &slot_list, list) {
296 if (slot->root_handle == handle) { 176 if (slot->pci_slot->bus == bus) {
297 list_del(&slot->list); 177 list_del(&slot->list);
298 pbus = slot->pci_slot->bus;
299 pci_destroy_slot(slot->pci_slot); 178 pci_destroy_slot(slot->pci_slot);
300 put_device(&pbus->dev); 179 put_device(&bus->dev);
301 kfree(slot); 180 kfree(slot);
302 } 181 }
303 } 182 }
@@ -332,5 +211,4 @@ static struct dmi_system_id acpi_pci_slot_dmi_table[] __initdata = {
332void __init acpi_pci_slot_init(void) 211void __init acpi_pci_slot_init(void)
333{ 212{
334 dmi_check_system(acpi_pci_slot_dmi_table); 213 dmi_check_system(acpi_pci_slot_dmi_table);
335 acpi_pci_register_driver(&acpi_pci_slot_driver);
336} 214}
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 5e7e991717d7..f54d1985e594 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1790,7 +1790,6 @@ int __init acpi_scan_init(void)
1790 acpi_platform_init(); 1790 acpi_platform_init();
1791 acpi_csrt_init(); 1791 acpi_csrt_init();
1792 acpi_container_init(); 1792 acpi_container_init();
1793 acpi_pci_slot_init();
1794 1793
1795 mutex_lock(&acpi_scan_lock); 1794 mutex_lock(&acpi_scan_lock);
1796 /* 1795 /*
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 6a67b07de494..251e57d38942 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -415,17 +415,17 @@ static const struct pci_device_id ahci_pci_tbl[] = {
415 /* Marvell */ 415 /* Marvell */
416 { PCI_VDEVICE(MARVELL, 0x6145), board_ahci_mv }, /* 6145 */ 416 { PCI_VDEVICE(MARVELL, 0x6145), board_ahci_mv }, /* 6145 */
417 { PCI_VDEVICE(MARVELL, 0x6121), board_ahci_mv }, /* 6121 */ 417 { PCI_VDEVICE(MARVELL, 0x6121), board_ahci_mv }, /* 6121 */
418 { PCI_DEVICE(0x1b4b, 0x9123), 418 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9123),
419 .class = PCI_CLASS_STORAGE_SATA_AHCI, 419 .class = PCI_CLASS_STORAGE_SATA_AHCI,
420 .class_mask = 0xffffff, 420 .class_mask = 0xffffff,
421 .driver_data = board_ahci_yes_fbs }, /* 88se9128 */ 421 .driver_data = board_ahci_yes_fbs }, /* 88se9128 */
422 { PCI_DEVICE(0x1b4b, 0x9125), 422 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9125),
423 .driver_data = board_ahci_yes_fbs }, /* 88se9125 */ 423 .driver_data = board_ahci_yes_fbs }, /* 88se9125 */
424 { PCI_DEVICE(0x1b4b, 0x917a), 424 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x917a),
425 .driver_data = board_ahci_yes_fbs }, /* 88se9172 */ 425 .driver_data = board_ahci_yes_fbs }, /* 88se9172 */
426 { PCI_DEVICE(0x1b4b, 0x9192), 426 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9192),
427 .driver_data = board_ahci_yes_fbs }, /* 88se9172 on some Gigabyte */ 427 .driver_data = board_ahci_yes_fbs }, /* 88se9172 on some Gigabyte */
428 { PCI_DEVICE(0x1b4b, 0x91a3), 428 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x91a3),
429 .driver_data = board_ahci_yes_fbs }, 429 .driver_data = board_ahci_yes_fbs },
430 430
431 /* Promise */ 431 /* Promise */
diff --git a/drivers/eisa/eisa-bus.c b/drivers/eisa/eisa-bus.c
index 806c77bfd434..272a3ec35957 100644
--- a/drivers/eisa/eisa-bus.c
+++ b/drivers/eisa/eisa-bus.c
@@ -275,19 +275,18 @@ static int __init eisa_request_resources(struct eisa_root_device *root,
275 } 275 }
276 276
277 if (slot) { 277 if (slot) {
278 edev->res[i].name = NULL;
279 edev->res[i].start = SLOT_ADDRESS(root, slot) 278 edev->res[i].start = SLOT_ADDRESS(root, slot)
280 + (i * 0x400); 279 + (i * 0x400);
281 edev->res[i].end = edev->res[i].start + 0xff; 280 edev->res[i].end = edev->res[i].start + 0xff;
282 edev->res[i].flags = IORESOURCE_IO; 281 edev->res[i].flags = IORESOURCE_IO;
283 } else { 282 } else {
284 edev->res[i].name = NULL;
285 edev->res[i].start = SLOT_ADDRESS(root, slot) 283 edev->res[i].start = SLOT_ADDRESS(root, slot)
286 + EISA_VENDOR_ID_OFFSET; 284 + EISA_VENDOR_ID_OFFSET;
287 edev->res[i].end = edev->res[i].start + 3; 285 edev->res[i].end = edev->res[i].start + 3;
288 edev->res[i].flags = IORESOURCE_BUSY; 286 edev->res[i].flags = IORESOURCE_IO | IORESOURCE_BUSY;
289 } 287 }
290 288
289 dev_printk(KERN_DEBUG, &edev->dev, "%pR\n", &edev->res[i]);
291 if (request_resource(root->res, &edev->res[i])) 290 if (request_resource(root->res, &edev->res[i]))
292 goto failed; 291 goto failed;
293 } 292 }
@@ -314,41 +313,40 @@ static int __init eisa_probe(struct eisa_root_device *root)
314{ 313{
315 int i, c; 314 int i, c;
316 struct eisa_device *edev; 315 struct eisa_device *edev;
316 char *enabled_str;
317 317
318 printk(KERN_INFO "EISA: Probing bus %d at %s\n", 318 dev_info(root->dev, "Probing EISA bus %d\n", root->bus_nr);
319 root->bus_nr, dev_name(root->dev));
320 319
321 /* First try to get hold of slot 0. If there is no device 320 /* First try to get hold of slot 0. If there is no device
322 * here, simply fail, unless root->force_probe is set. */ 321 * here, simply fail, unless root->force_probe is set. */
323 322
324 edev = kzalloc(sizeof(*edev), GFP_KERNEL); 323 edev = kzalloc(sizeof(*edev), GFP_KERNEL);
325 if (!edev) { 324 if (!edev) {
326 printk(KERN_ERR "EISA: Couldn't allocate mainboard slot\n"); 325 dev_err(root->dev, "EISA: Couldn't allocate mainboard slot\n");
327 return -ENOMEM; 326 return -ENOMEM;
328 } 327 }
329 328
330 if (eisa_request_resources(root, edev, 0)) { 329 if (eisa_init_device(root, edev, 0)) {
331 printk(KERN_WARNING \
332 "EISA: Cannot allocate resource for mainboard\n");
333 kfree(edev); 330 kfree(edev);
334 if (!root->force_probe) 331 if (!root->force_probe)
335 return -EBUSY; 332 return -ENODEV;
336 goto force_probe; 333 goto force_probe;
337 } 334 }
338 335
339 if (eisa_init_device(root, edev, 0)) { 336 if (eisa_request_resources(root, edev, 0)) {
340 eisa_release_resources(edev); 337 dev_warn(root->dev,
338 "EISA: Cannot allocate resource for mainboard\n");
341 kfree(edev); 339 kfree(edev);
342 if (!root->force_probe) 340 if (!root->force_probe)
343 return -ENODEV; 341 return -EBUSY;
344 goto force_probe; 342 goto force_probe;
345 } 343 }
346 344
347 printk(KERN_INFO "EISA: Mainboard %s detected.\n", edev->id.sig); 345 dev_info(&edev->dev, "EISA: Mainboard %s detected\n", edev->id.sig);
348 346
349 if (eisa_register_device(edev)) { 347 if (eisa_register_device(edev)) {
350 printk(KERN_ERR "EISA: Failed to register %s\n", 348 dev_err(&edev->dev, "EISA: Failed to register %s\n",
351 edev->id.sig); 349 edev->id.sig);
352 eisa_release_resources(edev); 350 eisa_release_resources(edev);
353 kfree(edev); 351 kfree(edev);
354 } 352 }
@@ -358,55 +356,47 @@ static int __init eisa_probe(struct eisa_root_device *root)
358 for (c = 0, i = 1; i <= root->slots; i++) { 356 for (c = 0, i = 1; i <= root->slots; i++) {
359 edev = kzalloc(sizeof(*edev), GFP_KERNEL); 357 edev = kzalloc(sizeof(*edev), GFP_KERNEL);
360 if (!edev) { 358 if (!edev) {
361 printk(KERN_ERR "EISA: Out of memory for slot %d\n", i); 359 dev_err(root->dev, "EISA: Out of memory for slot %d\n",
360 i);
362 continue; 361 continue;
363 } 362 }
364 363
365 if (eisa_request_resources(root, edev, i)) { 364 if (eisa_init_device(root, edev, i)) {
366 printk(KERN_WARNING \
367 "Cannot allocate resource for EISA slot %d\n",
368 i);
369 kfree(edev); 365 kfree(edev);
370 continue; 366 continue;
371 } 367 }
372 368
373 if (eisa_init_device(root, edev, i)) { 369 if (eisa_request_resources(root, edev, i)) {
374 eisa_release_resources(edev); 370 dev_warn(root->dev,
371 "Cannot allocate resource for EISA slot %d\n",
372 i);
375 kfree(edev); 373 kfree(edev);
376 continue; 374 continue;
377 } 375 }
378 376
379 printk(KERN_INFO "EISA: slot %d : %s detected", 377 if (edev->state == (EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED))
380 i, edev->id.sig); 378 enabled_str = " (forced enabled)";
381 379 else if (edev->state == EISA_CONFIG_FORCED)
382 switch (edev->state) { 380 enabled_str = " (forced disabled)";
383 case EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED: 381 else if (edev->state == 0)
384 printk(" (forced enabled)"); 382 enabled_str = " (disabled)";
385 break; 383 else
386 384 enabled_str = "";
387 case EISA_CONFIG_FORCED: 385
388 printk(" (forced disabled)"); 386 dev_info(&edev->dev, "EISA: slot %d: %s detected%s\n", i,
389 break; 387 edev->id.sig, enabled_str);
390
391 case 0:
392 printk(" (disabled)");
393 break;
394 }
395
396 printk (".\n");
397 388
398 c++; 389 c++;
399 390
400 if (eisa_register_device(edev)) { 391 if (eisa_register_device(edev)) {
401 printk(KERN_ERR "EISA: Failed to register %s\n", 392 dev_err(&edev->dev, "EISA: Failed to register %s\n",
402 edev->id.sig); 393 edev->id.sig);
403 eisa_release_resources(edev); 394 eisa_release_resources(edev);
404 kfree(edev); 395 kfree(edev);
405 } 396 }
406 } 397 }
407 398
408 printk(KERN_INFO "EISA: Detected %d card%s.\n", c, c == 1 ? "" : "s"); 399 dev_info(root->dev, "EISA: Detected %d card%s\n", c, c == 1 ? "" : "s");
409
410 return 0; 400 return 0;
411} 401}
412 402
diff --git a/drivers/eisa/pci_eisa.c b/drivers/eisa/pci_eisa.c
index 6c3fca97d346..a333bf3517de 100644
--- a/drivers/eisa/pci_eisa.c
+++ b/drivers/eisa/pci_eisa.c
@@ -25,8 +25,7 @@ static int __init pci_eisa_init(struct pci_dev *pdev)
25 struct resource *res, *bus_res = NULL; 25 struct resource *res, *bus_res = NULL;
26 26
27 if ((rc = pci_enable_device (pdev))) { 27 if ((rc = pci_enable_device (pdev))) {
28 printk (KERN_ERR "pci_eisa : Could not enable device %s\n", 28 dev_err(&pdev->dev, "Could not enable device\n");
29 pci_name(pdev));
30 return rc; 29 return rc;
31 } 30 }
32 31
@@ -59,7 +58,7 @@ static int __init pci_eisa_init(struct pci_dev *pdev)
59 dev_set_drvdata(pci_eisa_root.dev, &pci_eisa_root); 58 dev_set_drvdata(pci_eisa_root.dev, &pci_eisa_root);
60 59
61 if (eisa_root_register (&pci_eisa_root)) { 60 if (eisa_root_register (&pci_eisa_root)) {
62 printk (KERN_ERR "pci_eisa : Could not register EISA root\n"); 61 dev_err(&pdev->dev, "Could not register EISA root\n");
63 return -1; 62 return -1;
64 } 63 }
65 64
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index b287ca33833d..830183737b0f 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -173,7 +173,7 @@ static inline u16 get_device_id(struct device *dev)
173{ 173{
174 struct pci_dev *pdev = to_pci_dev(dev); 174 struct pci_dev *pdev = to_pci_dev(dev);
175 175
176 return calc_devid(pdev->bus->number, pdev->devfn); 176 return PCI_DEVID(pdev->bus->number, pdev->devfn);
177} 177}
178 178
179static struct iommu_dev_data *get_dev_data(struct device *dev) 179static struct iommu_dev_data *get_dev_data(struct device *dev)
@@ -649,26 +649,26 @@ retry:
649 case EVENT_TYPE_ILL_DEV: 649 case EVENT_TYPE_ILL_DEV:
650 printk("ILLEGAL_DEV_TABLE_ENTRY device=%02x:%02x.%x " 650 printk("ILLEGAL_DEV_TABLE_ENTRY device=%02x:%02x.%x "
651 "address=0x%016llx flags=0x%04x]\n", 651 "address=0x%016llx flags=0x%04x]\n",
652 PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), 652 PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
653 address, flags); 653 address, flags);
654 dump_dte_entry(devid); 654 dump_dte_entry(devid);
655 break; 655 break;
656 case EVENT_TYPE_IO_FAULT: 656 case EVENT_TYPE_IO_FAULT:
657 printk("IO_PAGE_FAULT device=%02x:%02x.%x " 657 printk("IO_PAGE_FAULT device=%02x:%02x.%x "
658 "domain=0x%04x address=0x%016llx flags=0x%04x]\n", 658 "domain=0x%04x address=0x%016llx flags=0x%04x]\n",
659 PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), 659 PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
660 domid, address, flags); 660 domid, address, flags);
661 break; 661 break;
662 case EVENT_TYPE_DEV_TAB_ERR: 662 case EVENT_TYPE_DEV_TAB_ERR:
663 printk("DEV_TAB_HARDWARE_ERROR device=%02x:%02x.%x " 663 printk("DEV_TAB_HARDWARE_ERROR device=%02x:%02x.%x "
664 "address=0x%016llx flags=0x%04x]\n", 664 "address=0x%016llx flags=0x%04x]\n",
665 PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), 665 PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
666 address, flags); 666 address, flags);
667 break; 667 break;
668 case EVENT_TYPE_PAGE_TAB_ERR: 668 case EVENT_TYPE_PAGE_TAB_ERR:
669 printk("PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x " 669 printk("PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x "
670 "domain=0x%04x address=0x%016llx flags=0x%04x]\n", 670 "domain=0x%04x address=0x%016llx flags=0x%04x]\n",
671 PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), 671 PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
672 domid, address, flags); 672 domid, address, flags);
673 break; 673 break;
674 case EVENT_TYPE_ILL_CMD: 674 case EVENT_TYPE_ILL_CMD:
@@ -682,13 +682,13 @@ retry:
682 case EVENT_TYPE_IOTLB_INV_TO: 682 case EVENT_TYPE_IOTLB_INV_TO:
683 printk("IOTLB_INV_TIMEOUT device=%02x:%02x.%x " 683 printk("IOTLB_INV_TIMEOUT device=%02x:%02x.%x "
684 "address=0x%016llx]\n", 684 "address=0x%016llx]\n",
685 PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), 685 PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
686 address); 686 address);
687 break; 687 break;
688 case EVENT_TYPE_INV_DEV_REQ: 688 case EVENT_TYPE_INV_DEV_REQ:
689 printk("INVALID_DEVICE_REQUEST device=%02x:%02x.%x " 689 printk("INVALID_DEVICE_REQUEST device=%02x:%02x.%x "
690 "address=0x%016llx flags=0x%04x]\n", 690 "address=0x%016llx flags=0x%04x]\n",
691 PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), 691 PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
692 address, flags); 692 address, flags);
693 break; 693 break;
694 default: 694 default:
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index e3c2d74b7684..2f46881256a2 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -406,7 +406,7 @@ static int __init find_last_devid_on_pci(int bus, int dev, int fn, int cap_ptr)
406 u32 cap; 406 u32 cap;
407 407
408 cap = read_pci_config(bus, dev, fn, cap_ptr+MMIO_RANGE_OFFSET); 408 cap = read_pci_config(bus, dev, fn, cap_ptr+MMIO_RANGE_OFFSET);
409 update_last_devid(calc_devid(MMIO_GET_BUS(cap), MMIO_GET_LD(cap))); 409 update_last_devid(PCI_DEVID(MMIO_GET_BUS(cap), MMIO_GET_LD(cap)));
410 410
411 return 0; 411 return 0;
412} 412}
@@ -423,7 +423,7 @@ static int __init find_last_devid_from_ivhd(struct ivhd_header *h)
423 p += sizeof(*h); 423 p += sizeof(*h);
424 end += h->length; 424 end += h->length;
425 425
426 find_last_devid_on_pci(PCI_BUS(h->devid), 426 find_last_devid_on_pci(PCI_BUS_NUM(h->devid),
427 PCI_SLOT(h->devid), 427 PCI_SLOT(h->devid),
428 PCI_FUNC(h->devid), 428 PCI_FUNC(h->devid),
429 h->cap_ptr); 429 h->cap_ptr);
@@ -784,10 +784,10 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
784 784
785 DUMP_printk(" DEV_ALL\t\t\t first devid: %02x:%02x.%x" 785 DUMP_printk(" DEV_ALL\t\t\t first devid: %02x:%02x.%x"
786 " last device %02x:%02x.%x flags: %02x\n", 786 " last device %02x:%02x.%x flags: %02x\n",
787 PCI_BUS(iommu->first_device), 787 PCI_BUS_NUM(iommu->first_device),
788 PCI_SLOT(iommu->first_device), 788 PCI_SLOT(iommu->first_device),
789 PCI_FUNC(iommu->first_device), 789 PCI_FUNC(iommu->first_device),
790 PCI_BUS(iommu->last_device), 790 PCI_BUS_NUM(iommu->last_device),
791 PCI_SLOT(iommu->last_device), 791 PCI_SLOT(iommu->last_device),
792 PCI_FUNC(iommu->last_device), 792 PCI_FUNC(iommu->last_device),
793 e->flags); 793 e->flags);
@@ -801,7 +801,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
801 801
802 DUMP_printk(" DEV_SELECT\t\t\t devid: %02x:%02x.%x " 802 DUMP_printk(" DEV_SELECT\t\t\t devid: %02x:%02x.%x "
803 "flags: %02x\n", 803 "flags: %02x\n",
804 PCI_BUS(e->devid), 804 PCI_BUS_NUM(e->devid),
805 PCI_SLOT(e->devid), 805 PCI_SLOT(e->devid),
806 PCI_FUNC(e->devid), 806 PCI_FUNC(e->devid),
807 e->flags); 807 e->flags);
@@ -813,7 +813,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
813 813
814 DUMP_printk(" DEV_SELECT_RANGE_START\t " 814 DUMP_printk(" DEV_SELECT_RANGE_START\t "
815 "devid: %02x:%02x.%x flags: %02x\n", 815 "devid: %02x:%02x.%x flags: %02x\n",
816 PCI_BUS(e->devid), 816 PCI_BUS_NUM(e->devid),
817 PCI_SLOT(e->devid), 817 PCI_SLOT(e->devid),
818 PCI_FUNC(e->devid), 818 PCI_FUNC(e->devid),
819 e->flags); 819 e->flags);
@@ -827,11 +827,11 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
827 827
828 DUMP_printk(" DEV_ALIAS\t\t\t devid: %02x:%02x.%x " 828 DUMP_printk(" DEV_ALIAS\t\t\t devid: %02x:%02x.%x "
829 "flags: %02x devid_to: %02x:%02x.%x\n", 829 "flags: %02x devid_to: %02x:%02x.%x\n",
830 PCI_BUS(e->devid), 830 PCI_BUS_NUM(e->devid),
831 PCI_SLOT(e->devid), 831 PCI_SLOT(e->devid),
832 PCI_FUNC(e->devid), 832 PCI_FUNC(e->devid),
833 e->flags, 833 e->flags,
834 PCI_BUS(e->ext >> 8), 834 PCI_BUS_NUM(e->ext >> 8),
835 PCI_SLOT(e->ext >> 8), 835 PCI_SLOT(e->ext >> 8),
836 PCI_FUNC(e->ext >> 8)); 836 PCI_FUNC(e->ext >> 8));
837 837
@@ -846,11 +846,11 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
846 DUMP_printk(" DEV_ALIAS_RANGE\t\t " 846 DUMP_printk(" DEV_ALIAS_RANGE\t\t "
847 "devid: %02x:%02x.%x flags: %02x " 847 "devid: %02x:%02x.%x flags: %02x "
848 "devid_to: %02x:%02x.%x\n", 848 "devid_to: %02x:%02x.%x\n",
849 PCI_BUS(e->devid), 849 PCI_BUS_NUM(e->devid),
850 PCI_SLOT(e->devid), 850 PCI_SLOT(e->devid),
851 PCI_FUNC(e->devid), 851 PCI_FUNC(e->devid),
852 e->flags, 852 e->flags,
853 PCI_BUS(e->ext >> 8), 853 PCI_BUS_NUM(e->ext >> 8),
854 PCI_SLOT(e->ext >> 8), 854 PCI_SLOT(e->ext >> 8),
855 PCI_FUNC(e->ext >> 8)); 855 PCI_FUNC(e->ext >> 8));
856 856
@@ -864,7 +864,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
864 864
865 DUMP_printk(" DEV_EXT_SELECT\t\t devid: %02x:%02x.%x " 865 DUMP_printk(" DEV_EXT_SELECT\t\t devid: %02x:%02x.%x "
866 "flags: %02x ext: %08x\n", 866 "flags: %02x ext: %08x\n",
867 PCI_BUS(e->devid), 867 PCI_BUS_NUM(e->devid),
868 PCI_SLOT(e->devid), 868 PCI_SLOT(e->devid),
869 PCI_FUNC(e->devid), 869 PCI_FUNC(e->devid),
870 e->flags, e->ext); 870 e->flags, e->ext);
@@ -877,7 +877,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
877 877
878 DUMP_printk(" DEV_EXT_SELECT_RANGE\t devid: " 878 DUMP_printk(" DEV_EXT_SELECT_RANGE\t devid: "
879 "%02x:%02x.%x flags: %02x ext: %08x\n", 879 "%02x:%02x.%x flags: %02x ext: %08x\n",
880 PCI_BUS(e->devid), 880 PCI_BUS_NUM(e->devid),
881 PCI_SLOT(e->devid), 881 PCI_SLOT(e->devid),
882 PCI_FUNC(e->devid), 882 PCI_FUNC(e->devid),
883 e->flags, e->ext); 883 e->flags, e->ext);
@@ -890,7 +890,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
890 case IVHD_DEV_RANGE_END: 890 case IVHD_DEV_RANGE_END:
891 891
892 DUMP_printk(" DEV_RANGE_END\t\t devid: %02x:%02x.%x\n", 892 DUMP_printk(" DEV_RANGE_END\t\t devid: %02x:%02x.%x\n",
893 PCI_BUS(e->devid), 893 PCI_BUS_NUM(e->devid),
894 PCI_SLOT(e->devid), 894 PCI_SLOT(e->devid),
895 PCI_FUNC(e->devid)); 895 PCI_FUNC(e->devid));
896 896
@@ -924,7 +924,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
924 924
925 DUMP_printk(" DEV_SPECIAL(%s[%d])\t\tdevid: %02x:%02x.%x\n", 925 DUMP_printk(" DEV_SPECIAL(%s[%d])\t\tdevid: %02x:%02x.%x\n",
926 var, (int)handle, 926 var, (int)handle,
927 PCI_BUS(devid), 927 PCI_BUS_NUM(devid),
928 PCI_SLOT(devid), 928 PCI_SLOT(devid),
929 PCI_FUNC(devid)); 929 PCI_FUNC(devid));
930 930
@@ -1086,7 +1086,7 @@ static int __init init_iommu_all(struct acpi_table_header *table)
1086 1086
1087 DUMP_printk("device: %02x:%02x.%01x cap: %04x " 1087 DUMP_printk("device: %02x:%02x.%01x cap: %04x "
1088 "seg: %d flags: %01x info %04x\n", 1088 "seg: %d flags: %01x info %04x\n",
1089 PCI_BUS(h->devid), PCI_SLOT(h->devid), 1089 PCI_BUS_NUM(h->devid), PCI_SLOT(h->devid),
1090 PCI_FUNC(h->devid), h->cap_ptr, 1090 PCI_FUNC(h->devid), h->cap_ptr,
1091 h->pci_seg, h->flags, h->info); 1091 h->pci_seg, h->flags, h->info);
1092 DUMP_printk(" mmio-addr: %016llx\n", 1092 DUMP_printk(" mmio-addr: %016llx\n",
@@ -1116,7 +1116,7 @@ static int iommu_init_pci(struct amd_iommu *iommu)
1116 int cap_ptr = iommu->cap_ptr; 1116 int cap_ptr = iommu->cap_ptr;
1117 u32 range, misc, low, high; 1117 u32 range, misc, low, high;
1118 1118
1119 iommu->dev = pci_get_bus_and_slot(PCI_BUS(iommu->devid), 1119 iommu->dev = pci_get_bus_and_slot(PCI_BUS_NUM(iommu->devid),
1120 iommu->devid & 0xff); 1120 iommu->devid & 0xff);
1121 if (!iommu->dev) 1121 if (!iommu->dev)
1122 return -ENODEV; 1122 return -ENODEV;
@@ -1128,9 +1128,9 @@ static int iommu_init_pci(struct amd_iommu *iommu)
1128 pci_read_config_dword(iommu->dev, cap_ptr + MMIO_MISC_OFFSET, 1128 pci_read_config_dword(iommu->dev, cap_ptr + MMIO_MISC_OFFSET,
1129 &misc); 1129 &misc);
1130 1130
1131 iommu->first_device = calc_devid(MMIO_GET_BUS(range), 1131 iommu->first_device = PCI_DEVID(MMIO_GET_BUS(range),
1132 MMIO_GET_FD(range)); 1132 MMIO_GET_FD(range));
1133 iommu->last_device = calc_devid(MMIO_GET_BUS(range), 1133 iommu->last_device = PCI_DEVID(MMIO_GET_BUS(range),
1134 MMIO_GET_LD(range)); 1134 MMIO_GET_LD(range));
1135 1135
1136 if (!(iommu->cap & (1 << IOMMU_CAP_IOTLB))) 1136 if (!(iommu->cap & (1 << IOMMU_CAP_IOTLB)))
@@ -1388,8 +1388,8 @@ static int __init init_unity_map_range(struct ivmd_header *m)
1388 1388
1389 DUMP_printk("%s devid_start: %02x:%02x.%x devid_end: %02x:%02x.%x" 1389 DUMP_printk("%s devid_start: %02x:%02x.%x devid_end: %02x:%02x.%x"
1390 " range_start: %016llx range_end: %016llx flags: %x\n", s, 1390 " range_start: %016llx range_end: %016llx flags: %x\n", s,
1391 PCI_BUS(e->devid_start), PCI_SLOT(e->devid_start), 1391 PCI_BUS_NUM(e->devid_start), PCI_SLOT(e->devid_start),
1392 PCI_FUNC(e->devid_start), PCI_BUS(e->devid_end), 1392 PCI_FUNC(e->devid_start), PCI_BUS_NUM(e->devid_end),
1393 PCI_SLOT(e->devid_end), PCI_FUNC(e->devid_end), 1393 PCI_SLOT(e->devid_end), PCI_FUNC(e->devid_end),
1394 e->address_start, e->address_end, m->flags); 1394 e->address_start, e->address_end, m->flags);
1395 1395
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index e38ab438bb34..ec36cf63e0ca 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -24,6 +24,7 @@
24#include <linux/mutex.h> 24#include <linux/mutex.h>
25#include <linux/list.h> 25#include <linux/list.h>
26#include <linux/spinlock.h> 26#include <linux/spinlock.h>
27#include <linux/pci.h>
27 28
28/* 29/*
29 * Maximum number of IOMMUs supported 30 * Maximum number of IOMMUs supported
@@ -315,9 +316,6 @@
315 316
316#define MAX_DOMAIN_ID 65536 317#define MAX_DOMAIN_ID 65536
317 318
318/* FIXME: move this macro to <linux/pci.h> */
319#define PCI_BUS(x) (((x) >> 8) & 0xff)
320
321/* Protection domain flags */ 319/* Protection domain flags */
322#define PD_DMA_OPS_MASK (1UL << 0) /* domain used for dma_ops */ 320#define PD_DMA_OPS_MASK (1UL << 0) /* domain used for dma_ops */
323#define PD_DEFAULT_MASK (1UL << 1) /* domain is a default dma_ops 321#define PD_DEFAULT_MASK (1UL << 1) /* domain is a default dma_ops
@@ -703,13 +701,6 @@ extern int amd_iommu_max_glx_val;
703 */ 701 */
704extern void iommu_flush_all_caches(struct amd_iommu *iommu); 702extern void iommu_flush_all_caches(struct amd_iommu *iommu);
705 703
706/* takes bus and device/function and returns the device id
707 * FIXME: should that be in generic PCI code? */
708static inline u16 calc_devid(u8 bus, u8 devfn)
709{
710 return (((u16)bus) << 8) | devfn;
711}
712
713static inline int get_ioapic_devid(int id) 704static inline int get_ioapic_devid(int id)
714{ 705{
715 struct devid_map *entry; 706 struct devid_map *entry;
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 8647dc6f52d0..748f8f3e9ff5 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -202,20 +202,16 @@ void pci_bus_add_devices(const struct pci_bus *bus)
202 if (dev->is_added) 202 if (dev->is_added)
203 continue; 203 continue;
204 retval = pci_bus_add_device(dev); 204 retval = pci_bus_add_device(dev);
205 if (retval)
206 dev_err(&dev->dev, "Error adding device (%d)\n",
207 retval);
205 } 208 }
206 209
207 list_for_each_entry(dev, &bus->devices, bus_list) { 210 list_for_each_entry(dev, &bus->devices, bus_list) {
208 BUG_ON(!dev->is_added); 211 BUG_ON(!dev->is_added);
209
210 child = dev->subordinate; 212 child = dev->subordinate;
211 213 if (child)
212 if (!child) 214 pci_bus_add_devices(child);
213 continue;
214 pci_bus_add_devices(child);
215
216 if (child->is_added)
217 continue;
218 child->is_added = 1;
219 } 215 }
220} 216}
221 217
diff --git a/drivers/pci/hotplug/Kconfig b/drivers/pci/hotplug/Kconfig
index 13e9e63a7266..9fcb87f353d4 100644
--- a/drivers/pci/hotplug/Kconfig
+++ b/drivers/pci/hotplug/Kconfig
@@ -52,15 +52,12 @@ config HOTPLUG_PCI_IBM
52 When in doubt, say N. 52 When in doubt, say N.
53 53
54config HOTPLUG_PCI_ACPI 54config HOTPLUG_PCI_ACPI
55 tristate "ACPI PCI Hotplug driver" 55 bool "ACPI PCI Hotplug driver"
56 depends on (!ACPI_DOCK && ACPI) || (ACPI_DOCK) 56 depends on HOTPLUG_PCI=y && ((!ACPI_DOCK && ACPI) || (ACPI_DOCK))
57 help 57 help
58 Say Y here if you have a system that supports PCI Hotplug using 58 Say Y here if you have a system that supports PCI Hotplug using
59 ACPI. 59 ACPI.
60 60
61 To compile this driver as a module, choose M here: the
62 module will be called acpiphp.
63
64 When in doubt, say N. 61 When in doubt, say N.
65 62
66config HOTPLUG_PCI_ACPI_IBM 63config HOTPLUG_PCI_ACPI_IBM
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index b70ac00a117e..6fdd49c6f0b9 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -73,8 +73,9 @@ static inline const char *slot_name(struct slot *slot)
73 */ 73 */
74struct acpiphp_bridge { 74struct acpiphp_bridge {
75 struct list_head list; 75 struct list_head list;
76 struct list_head slots;
77 struct kref ref;
76 acpi_handle handle; 78 acpi_handle handle;
77 struct acpiphp_slot *slots;
78 79
79 /* Ejectable PCI-to-PCI bridge (PCI bridge and PCI function) */ 80 /* Ejectable PCI-to-PCI bridge (PCI bridge and PCI function) */
80 struct acpiphp_func *func; 81 struct acpiphp_func *func;
@@ -97,7 +98,7 @@ struct acpiphp_bridge {
97 * PCI slot information for each *physical* PCI slot 98 * PCI slot information for each *physical* PCI slot
98 */ 99 */
99struct acpiphp_slot { 100struct acpiphp_slot {
100 struct acpiphp_slot *next; 101 struct list_head node;
101 struct acpiphp_bridge *bridge; /* parent */ 102 struct acpiphp_bridge *bridge; /* parent */
102 struct list_head funcs; /* one slot may have different 103 struct list_head funcs; /* one slot may have different
103 objects (i.e. for each function) */ 104 objects (i.e. for each function) */
@@ -119,7 +120,6 @@ struct acpiphp_slot {
119 */ 120 */
120struct acpiphp_func { 121struct acpiphp_func {
121 struct acpiphp_slot *slot; /* parent */ 122 struct acpiphp_slot *slot; /* parent */
122 struct acpiphp_bridge *bridge; /* Ejectable PCI-to-PCI bridge */
123 123
124 struct list_head sibling; 124 struct list_head sibling;
125 struct notifier_block nb; 125 struct notifier_block nb;
@@ -146,10 +146,6 @@ struct acpiphp_attention_info
146#define ACPI_PCI_HOST_HID "PNP0A03" 146#define ACPI_PCI_HOST_HID "PNP0A03"
147 147
148/* ACPI _STA method value (ignore bit 4; battery present) */ 148/* ACPI _STA method value (ignore bit 4; battery present) */
149#define ACPI_STA_PRESENT (0x00000001)
150#define ACPI_STA_ENABLED (0x00000002)
151#define ACPI_STA_SHOW_IN_UI (0x00000004)
152#define ACPI_STA_FUNCTIONING (0x00000008)
153#define ACPI_STA_ALL (0x0000000f) 149#define ACPI_STA_ALL (0x0000000f)
154 150
155/* bridge flags */ 151/* bridge flags */
@@ -174,25 +170,24 @@ struct acpiphp_attention_info
174/* function prototypes */ 170/* function prototypes */
175 171
176/* acpiphp_core.c */ 172/* acpiphp_core.c */
177extern int acpiphp_register_attention(struct acpiphp_attention_info*info); 173int acpiphp_register_attention(struct acpiphp_attention_info*info);
178extern int acpiphp_unregister_attention(struct acpiphp_attention_info *info); 174int acpiphp_unregister_attention(struct acpiphp_attention_info *info);
179extern int acpiphp_register_hotplug_slot(struct acpiphp_slot *slot); 175int acpiphp_register_hotplug_slot(struct acpiphp_slot *slot);
180extern void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *slot); 176void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *slot);
181 177
182/* acpiphp_glue.c */ 178/* acpiphp_glue.c */
183extern int acpiphp_glue_init (void);
184extern void acpiphp_glue_exit (void);
185typedef int (*acpiphp_callback)(struct acpiphp_slot *slot, void *data); 179typedef int (*acpiphp_callback)(struct acpiphp_slot *slot, void *data);
186 180
187extern int acpiphp_enable_slot (struct acpiphp_slot *slot); 181int acpiphp_enable_slot(struct acpiphp_slot *slot);
188extern int acpiphp_disable_slot (struct acpiphp_slot *slot); 182int acpiphp_disable_slot(struct acpiphp_slot *slot);
189extern int acpiphp_eject_slot (struct acpiphp_slot *slot); 183int acpiphp_eject_slot(struct acpiphp_slot *slot);
190extern u8 acpiphp_get_power_status (struct acpiphp_slot *slot); 184u8 acpiphp_get_power_status(struct acpiphp_slot *slot);
191extern u8 acpiphp_get_attention_status (struct acpiphp_slot *slot); 185u8 acpiphp_get_attention_status(struct acpiphp_slot *slot);
192extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot); 186u8 acpiphp_get_latch_status(struct acpiphp_slot *slot);
193extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot); 187u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot);
194 188
195/* variables */ 189/* variables */
196extern bool acpiphp_debug; 190extern bool acpiphp_debug;
191extern bool acpiphp_disabled;
197 192
198#endif /* _ACPIPHP_H */ 193#endif /* _ACPIPHP_H */
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index c2fd3095701f..ca8127950fcd 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -37,6 +37,7 @@
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-acpi.h>
40#include <linux/pci_hotplug.h> 41#include <linux/pci_hotplug.h>
41#include <linux/slab.h> 42#include <linux/slab.h>
42#include <linux/smp.h> 43#include <linux/smp.h>
@@ -48,6 +49,7 @@
48#define SLOT_NAME_SIZE 21 /* {_SUN} */ 49#define SLOT_NAME_SIZE 21 /* {_SUN} */
49 50
50bool acpiphp_debug; 51bool acpiphp_debug;
52bool acpiphp_disabled;
51 53
52/* local variables */ 54/* local variables */
53static struct acpiphp_attention_info *attention_info; 55static struct acpiphp_attention_info *attention_info;
@@ -60,7 +62,9 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
60MODULE_DESCRIPTION(DRIVER_DESC); 62MODULE_DESCRIPTION(DRIVER_DESC);
61MODULE_LICENSE("GPL"); 63MODULE_LICENSE("GPL");
62MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); 64MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
65MODULE_PARM_DESC(disable, "disable acpiphp driver");
63module_param_named(debug, acpiphp_debug, bool, 0644); 66module_param_named(debug, acpiphp_debug, bool, 0644);
67module_param_named(disable, acpiphp_disabled, bool, 0444);
64 68
65/* export the attention callback registration methods */ 69/* export the attention callback registration methods */
66EXPORT_SYMBOL_GPL(acpiphp_register_attention); 70EXPORT_SYMBOL_GPL(acpiphp_register_attention);
@@ -351,27 +355,9 @@ void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
351} 355}
352 356
353 357
354static int __init acpiphp_init(void) 358void __init acpiphp_init(void)
355{ 359{
356 info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); 360 info(DRIVER_DESC " version: " DRIVER_VERSION "%s\n",
357 361 acpiphp_disabled ? ", disabled by user; please report a bug"
358 if (acpi_pci_disabled) 362 : "");
359 return 0;
360
361 /* read all the ACPI info from the system */
362 /* initialize internal data structure etc. */
363 return acpiphp_glue_init();
364}
365
366
367static void __exit acpiphp_exit(void)
368{
369 if (acpi_pci_disabled)
370 return;
371
372 /* deallocate internal data structures etc. */
373 acpiphp_glue_exit();
374} 363}
375
376module_init(acpiphp_init);
377module_exit(acpiphp_exit);
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 270fdbadc19c..96fed19c6d90 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -54,6 +54,7 @@
54#include "acpiphp.h" 54#include "acpiphp.h"
55 55
56static LIST_HEAD(bridge_list); 56static LIST_HEAD(bridge_list);
57static DEFINE_MUTEX(bridge_mutex);
57 58
58#define MY_NAME "acpiphp_glue" 59#define MY_NAME "acpiphp_glue"
59 60
@@ -61,6 +62,7 @@ static void handle_hotplug_event_bridge (acpi_handle, u32, void *);
61static void acpiphp_sanitize_bus(struct pci_bus *bus); 62static void acpiphp_sanitize_bus(struct pci_bus *bus);
62static void acpiphp_set_hpp_values(struct pci_bus *bus); 63static void acpiphp_set_hpp_values(struct pci_bus *bus);
63static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context); 64static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context);
65static void free_bridge(struct kref *kref);
64 66
65/* callback routine to check for the existence of a pci dock device */ 67/* callback routine to check for the existence of a pci dock device */
66static acpi_status 68static acpi_status
@@ -76,6 +78,39 @@ is_pci_dock_device(acpi_handle handle, u32 lvl, void *context, void **rv)
76 } 78 }
77} 79}
78 80
81static inline void get_bridge(struct acpiphp_bridge *bridge)
82{
83 kref_get(&bridge->ref);
84}
85
86static inline void put_bridge(struct acpiphp_bridge *bridge)
87{
88 kref_put(&bridge->ref, free_bridge);
89}
90
91static void free_bridge(struct kref *kref)
92{
93 struct acpiphp_bridge *bridge;
94 struct acpiphp_slot *slot, *next;
95 struct acpiphp_func *func, *tmp;
96
97 bridge = container_of(kref, struct acpiphp_bridge, ref);
98
99 list_for_each_entry_safe(slot, next, &bridge->slots, node) {
100 list_for_each_entry_safe(func, tmp, &slot->funcs, sibling) {
101 kfree(func);
102 }
103 kfree(slot);
104 }
105
106 /* Release reference acquired by acpiphp_bridge_handle_to_function() */
107 if ((bridge->flags & BRIDGE_HAS_EJ0) && bridge->func)
108 put_bridge(bridge->func->slot->bridge);
109 put_device(&bridge->pci_bus->dev);
110 pci_dev_put(bridge->pci_dev);
111 kfree(bridge);
112}
113
79/* 114/*
80 * the _DCK method can do funny things... and sometimes not 115 * the _DCK method can do funny things... and sometimes not
81 * hah-hah funny. 116 * hah-hah funny.
@@ -154,9 +189,10 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
154 acpi_handle tmp; 189 acpi_handle tmp;
155 acpi_status status = AE_OK; 190 acpi_status status = AE_OK;
156 unsigned long long adr, sun; 191 unsigned long long adr, sun;
157 int device, function, retval; 192 int device, function, retval, found = 0;
158 struct pci_bus *pbus = bridge->pci_bus; 193 struct pci_bus *pbus = bridge->pci_bus;
159 struct pci_dev *pdev; 194 struct pci_dev *pdev;
195 u32 val;
160 196
161 if (!acpi_pci_check_ejectable(pbus, handle) && !is_dock_device(handle)) 197 if (!acpi_pci_check_ejectable(pbus, handle) && !is_dock_device(handle))
162 return AE_OK; 198 return AE_OK;
@@ -170,7 +206,7 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
170 device = (adr >> 16) & 0xffff; 206 device = (adr >> 16) & 0xffff;
171 function = adr & 0xffff; 207 function = adr & 0xffff;
172 208
173 pdev = pbus->self; 209 pdev = bridge->pci_dev;
174 if (pdev && device_is_managed_by_native_pciehp(pdev)) 210 if (pdev && device_is_managed_by_native_pciehp(pdev))
175 return AE_OK; 211 return AE_OK;
176 212
@@ -178,7 +214,6 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
178 if (!newfunc) 214 if (!newfunc)
179 return AE_NO_MEMORY; 215 return AE_NO_MEMORY;
180 216
181 INIT_LIST_HEAD(&newfunc->sibling);
182 newfunc->handle = handle; 217 newfunc->handle = handle;
183 newfunc->function = function; 218 newfunc->function = function;
184 219
@@ -207,14 +242,15 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
207 } 242 }
208 243
209 /* search for objects that share the same slot */ 244 /* search for objects that share the same slot */
210 for (slot = bridge->slots; slot; slot = slot->next) 245 list_for_each_entry(slot, &bridge->slots, node)
211 if (slot->device == device) { 246 if (slot->device == device) {
212 if (slot->sun != sun) 247 if (slot->sun != sun)
213 warn("sibling found, but _SUN doesn't match!\n"); 248 warn("sibling found, but _SUN doesn't match!\n");
249 found = 1;
214 break; 250 break;
215 } 251 }
216 252
217 if (!slot) { 253 if (!found) {
218 slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL); 254 slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
219 if (!slot) { 255 if (!slot) {
220 kfree(newfunc); 256 kfree(newfunc);
@@ -227,9 +263,9 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
227 INIT_LIST_HEAD(&slot->funcs); 263 INIT_LIST_HEAD(&slot->funcs);
228 mutex_init(&slot->crit_sect); 264 mutex_init(&slot->crit_sect);
229 265
230 slot->next = bridge->slots; 266 mutex_lock(&bridge_mutex);
231 bridge->slots = slot; 267 list_add_tail(&slot->node, &bridge->slots);
232 268 mutex_unlock(&bridge_mutex);
233 bridge->nr_slots++; 269 bridge->nr_slots++;
234 270
235 dbg("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n", 271 dbg("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
@@ -247,13 +283,13 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
247 } 283 }
248 284
249 newfunc->slot = slot; 285 newfunc->slot = slot;
286 mutex_lock(&bridge_mutex);
250 list_add_tail(&newfunc->sibling, &slot->funcs); 287 list_add_tail(&newfunc->sibling, &slot->funcs);
288 mutex_unlock(&bridge_mutex);
251 289
252 pdev = pci_get_slot(pbus, PCI_DEVFN(device, function)); 290 if (pci_bus_read_dev_vendor_id(pbus, PCI_DEVFN(device, function),
253 if (pdev) { 291 &val, 60*1000))
254 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON); 292 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
255 pci_dev_put(pdev);
256 }
257 293
258 if (is_dock_device(handle)) { 294 if (is_dock_device(handle)) {
259 /* we don't want to call this device's _EJ0 295 /* we don't want to call this device's _EJ0
@@ -290,7 +326,9 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
290 326
291 err_exit: 327 err_exit:
292 bridge->nr_slots--; 328 bridge->nr_slots--;
293 bridge->slots = slot->next; 329 mutex_lock(&bridge_mutex);
330 list_del(&slot->node);
331 mutex_unlock(&bridge_mutex);
294 kfree(slot); 332 kfree(slot);
295 kfree(newfunc); 333 kfree(newfunc);
296 334
@@ -315,13 +353,17 @@ static void init_bridge_misc(struct acpiphp_bridge *bridge)
315 acpi_status status; 353 acpi_status status;
316 354
317 /* must be added to the list prior to calling register_slot */ 355 /* must be added to the list prior to calling register_slot */
356 mutex_lock(&bridge_mutex);
318 list_add(&bridge->list, &bridge_list); 357 list_add(&bridge->list, &bridge_list);
358 mutex_unlock(&bridge_mutex);
319 359
320 /* register all slot objects under this bridge */ 360 /* register all slot objects under this bridge */
321 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1, 361 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1,
322 register_slot, NULL, bridge, NULL); 362 register_slot, NULL, bridge, NULL);
323 if (ACPI_FAILURE(status)) { 363 if (ACPI_FAILURE(status)) {
364 mutex_lock(&bridge_mutex);
324 list_del(&bridge->list); 365 list_del(&bridge->list);
366 mutex_unlock(&bridge_mutex);
325 return; 367 return;
326 } 368 }
327 369
@@ -351,178 +393,46 @@ static struct acpiphp_func *acpiphp_bridge_handle_to_function(acpi_handle handle
351{ 393{
352 struct acpiphp_bridge *bridge; 394 struct acpiphp_bridge *bridge;
353 struct acpiphp_slot *slot; 395 struct acpiphp_slot *slot;
354 struct acpiphp_func *func; 396 struct acpiphp_func *func = NULL;
355 397
398 mutex_lock(&bridge_mutex);
356 list_for_each_entry(bridge, &bridge_list, list) { 399 list_for_each_entry(bridge, &bridge_list, list) {
357 for (slot = bridge->slots; slot; slot = slot->next) { 400 list_for_each_entry(slot, &bridge->slots, node) {
358 list_for_each_entry(func, &slot->funcs, sibling) { 401 list_for_each_entry(func, &slot->funcs, sibling) {
359 if (func->handle == handle) 402 if (func->handle == handle) {
403 get_bridge(func->slot->bridge);
404 mutex_unlock(&bridge_mutex);
360 return func; 405 return func;
406 }
361 } 407 }
362 } 408 }
363 } 409 }
410 mutex_unlock(&bridge_mutex);
364 411
365 return NULL; 412 return NULL;
366} 413}
367 414
368 415
369static inline void config_p2p_bridge_flags(struct acpiphp_bridge *bridge)
370{
371 acpi_handle dummy_handle;
372 struct acpiphp_func *func;
373
374 if (ACPI_SUCCESS(acpi_get_handle(bridge->handle,
375 "_EJ0", &dummy_handle))) {
376 bridge->flags |= BRIDGE_HAS_EJ0;
377
378 dbg("found ejectable p2p bridge\n");
379
380 /* make link between PCI bridge and PCI function */
381 func = acpiphp_bridge_handle_to_function(bridge->handle);
382 if (!func)
383 return;
384 bridge->func = func;
385 func->bridge = bridge;
386 }
387}
388
389
390/* allocate and initialize host bridge data structure */
391static void add_host_bridge(struct acpi_pci_root *root)
392{
393 struct acpiphp_bridge *bridge;
394 acpi_handle handle = root->device->handle;
395
396 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
397 if (bridge == NULL)
398 return;
399
400 bridge->handle = handle;
401
402 bridge->pci_bus = root->bus;
403
404 init_bridge_misc(bridge);
405}
406
407
408/* allocate and initialize PCI-to-PCI bridge data structure */
409static void add_p2p_bridge(acpi_handle *handle)
410{
411 struct acpiphp_bridge *bridge;
412
413 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
414 if (bridge == NULL) {
415 err("out of memory\n");
416 return;
417 }
418
419 bridge->handle = handle;
420 config_p2p_bridge_flags(bridge);
421
422 bridge->pci_dev = acpi_get_pci_dev(handle);
423 bridge->pci_bus = bridge->pci_dev->subordinate;
424 if (!bridge->pci_bus) {
425 err("This is not a PCI-to-PCI bridge!\n");
426 goto err;
427 }
428
429 /*
430 * Grab a ref to the subordinate PCI bus in case the bus is
431 * removed via PCI core logical hotplug. The ref pins the bus
432 * (which we access during module unload).
433 */
434 get_device(&bridge->pci_bus->dev);
435
436 init_bridge_misc(bridge);
437 return;
438 err:
439 pci_dev_put(bridge->pci_dev);
440 kfree(bridge);
441 return;
442}
443
444
445/* callback routine to find P2P bridges */
446static acpi_status
447find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
448{
449 acpi_status status;
450 struct pci_dev *dev;
451
452 dev = acpi_get_pci_dev(handle);
453 if (!dev || !dev->subordinate)
454 goto out;
455
456 /* check if this bridge has ejectable slots */
457 if ((detect_ejectable_slots(handle) > 0)) {
458 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev));
459 add_p2p_bridge(handle);
460 }
461
462 /* search P2P bridges under this p2p bridge */
463 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
464 find_p2p_bridge, NULL, NULL, NULL);
465 if (ACPI_FAILURE(status))
466 warn("find_p2p_bridge failed (error code = 0x%x)\n", status);
467
468 out:
469 pci_dev_put(dev);
470 return AE_OK;
471}
472
473
474/* find hot-pluggable slots, and then find P2P bridge */
475static int add_bridge(struct acpi_pci_root *root)
476{
477 acpi_status status;
478 unsigned long long tmp;
479 acpi_handle dummy_handle;
480 acpi_handle handle = root->device->handle;
481
482 /* if the bridge doesn't have _STA, we assume it is always there */
483 status = acpi_get_handle(handle, "_STA", &dummy_handle);
484 if (ACPI_SUCCESS(status)) {
485 status = acpi_evaluate_integer(handle, "_STA", NULL, &tmp);
486 if (ACPI_FAILURE(status)) {
487 dbg("%s: _STA evaluation failure\n", __func__);
488 return 0;
489 }
490 if ((tmp & ACPI_STA_FUNCTIONING) == 0)
491 /* don't register this object */
492 return 0;
493 }
494
495 /* check if this bridge has ejectable slots */
496 if (detect_ejectable_slots(handle) > 0) {
497 dbg("found PCI host-bus bridge with hot-pluggable slots\n");
498 add_host_bridge(root);
499 }
500
501 /* search P2P bridges under this host bridge */
502 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
503 find_p2p_bridge, NULL, NULL, NULL);
504
505 if (ACPI_FAILURE(status))
506 warn("find_p2p_bridge failed (error code = 0x%x)\n", status);
507
508 return 0;
509}
510
511static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) 416static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
512{ 417{
513 struct acpiphp_bridge *bridge; 418 struct acpiphp_bridge *bridge;
514 419
420 mutex_lock(&bridge_mutex);
515 list_for_each_entry(bridge, &bridge_list, list) 421 list_for_each_entry(bridge, &bridge_list, list)
516 if (bridge->handle == handle) 422 if (bridge->handle == handle) {
423 get_bridge(bridge);
424 mutex_unlock(&bridge_mutex);
517 return bridge; 425 return bridge;
426 }
427 mutex_unlock(&bridge_mutex);
518 428
519 return NULL; 429 return NULL;
520} 430}
521 431
522static void cleanup_bridge(struct acpiphp_bridge *bridge) 432static void cleanup_bridge(struct acpiphp_bridge *bridge)
523{ 433{
524 struct acpiphp_slot *slot, *next; 434 struct acpiphp_slot *slot;
525 struct acpiphp_func *func, *tmp; 435 struct acpiphp_func *func;
526 acpi_status status; 436 acpi_status status;
527 acpi_handle handle = bridge->handle; 437 acpi_handle handle = bridge->handle;
528 438
@@ -543,10 +453,8 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge)
543 err("failed to install interrupt notify handler\n"); 453 err("failed to install interrupt notify handler\n");
544 } 454 }
545 455
546 slot = bridge->slots; 456 list_for_each_entry(slot, &bridge->slots, node) {
547 while (slot) { 457 list_for_each_entry(func, &slot->funcs, sibling) {
548 next = slot->next;
549 list_for_each_entry_safe(func, tmp, &slot->funcs, sibling) {
550 if (is_dock_device(func->handle)) { 458 if (is_dock_device(func->handle)) {
551 unregister_hotplug_dock_device(func->handle); 459 unregister_hotplug_dock_device(func->handle);
552 unregister_dock_notifier(&func->nb); 460 unregister_dock_notifier(&func->nb);
@@ -558,63 +466,13 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge)
558 if (ACPI_FAILURE(status)) 466 if (ACPI_FAILURE(status))
559 err("failed to remove notify handler\n"); 467 err("failed to remove notify handler\n");
560 } 468 }
561 list_del(&func->sibling);
562 kfree(func);
563 } 469 }
564 acpiphp_unregister_hotplug_slot(slot); 470 acpiphp_unregister_hotplug_slot(slot);
565 list_del(&slot->funcs);
566 kfree(slot);
567 slot = next;
568 } 471 }
569 472
570 /* 473 mutex_lock(&bridge_mutex);
571 * Only P2P bridges have a pci_dev
572 */
573 if (bridge->pci_dev)
574 put_device(&bridge->pci_bus->dev);
575
576 pci_dev_put(bridge->pci_dev);
577 list_del(&bridge->list); 474 list_del(&bridge->list);
578 kfree(bridge); 475 mutex_unlock(&bridge_mutex);
579}
580
581static acpi_status
582cleanup_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
583{
584 struct acpiphp_bridge *bridge;
585
586 /* cleanup p2p bridges under this P2P bridge
587 in a depth-first manner */
588 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
589 cleanup_p2p_bridge, NULL, NULL, NULL);
590
591 bridge = acpiphp_handle_to_bridge(handle);
592 if (bridge)
593 cleanup_bridge(bridge);
594
595 return AE_OK;
596}
597
598static void remove_bridge(struct acpi_pci_root *root)
599{
600 struct acpiphp_bridge *bridge;
601 acpi_handle handle = root->device->handle;
602
603 /* cleanup p2p bridges under this host bridge
604 in a depth-first manner */
605 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
606 (u32)1, cleanup_p2p_bridge, NULL, NULL, NULL);
607
608 /*
609 * On root bridges with hotplug slots directly underneath (ie,
610 * no p2p bridge between), we call cleanup_bridge().
611 *
612 * The else clause cleans up root bridges that either had no
613 * hotplug slots at all, or had a p2p bridge underneath.
614 */
615 bridge = acpiphp_handle_to_bridge(handle);
616 if (bridge)
617 cleanup_bridge(bridge);
618} 476}
619 477
620static int power_on_slot(struct acpiphp_slot *slot) 478static int power_on_slot(struct acpiphp_slot *slot)
@@ -798,6 +656,7 @@ static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev)
798 } 656 }
799 } 657 }
800} 658}
659
801/** 660/**
802 * enable_device - enable, configure a slot 661 * enable_device - enable, configure a slot
803 * @slot: slot to be enabled 662 * @slot: slot to be enabled
@@ -810,9 +669,7 @@ static int __ref enable_device(struct acpiphp_slot *slot)
810 struct pci_dev *dev; 669 struct pci_dev *dev;
811 struct pci_bus *bus = slot->bridge->pci_bus; 670 struct pci_bus *bus = slot->bridge->pci_bus;
812 struct acpiphp_func *func; 671 struct acpiphp_func *func;
813 int retval = 0;
814 int num, max, pass; 672 int num, max, pass;
815 acpi_status status;
816 673
817 if (slot->flags & SLOT_ENABLED) 674 if (slot->flags & SLOT_ENABLED)
818 goto err_exit; 675 goto err_exit;
@@ -867,23 +724,11 @@ static int __ref enable_device(struct acpiphp_slot *slot)
867 slot->flags &= (~SLOT_ENABLED); 724 slot->flags &= (~SLOT_ENABLED);
868 continue; 725 continue;
869 } 726 }
870
871 if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE &&
872 dev->hdr_type != PCI_HEADER_TYPE_CARDBUS) {
873 pci_dev_put(dev);
874 continue;
875 }
876
877 status = find_p2p_bridge(func->handle, (u32)1, bus, NULL);
878 if (ACPI_FAILURE(status))
879 warn("find_p2p_bridge failed (error code = 0x%x)\n",
880 status);
881 pci_dev_put(dev);
882 } 727 }
883 728
884 729
885 err_exit: 730 err_exit:
886 return retval; 731 return 0;
887} 732}
888 733
889/* return first device in slot, acquiring a reference on it */ 734/* return first device in slot, acquiring a reference on it */
@@ -912,23 +757,6 @@ static int disable_device(struct acpiphp_slot *slot)
912{ 757{
913 struct acpiphp_func *func; 758 struct acpiphp_func *func;
914 struct pci_dev *pdev; 759 struct pci_dev *pdev;
915 struct pci_bus *bus = slot->bridge->pci_bus;
916
917 /* The slot will be enabled when func 0 is added, so check
918 func 0 before disable the slot. */
919 pdev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0));
920 if (!pdev)
921 goto err_exit;
922 pci_dev_put(pdev);
923
924 list_for_each_entry(func, &slot->funcs, sibling) {
925 if (func->bridge) {
926 /* cleanup p2p bridges under this P2P bridge */
927 cleanup_p2p_bridge(func->bridge->handle,
928 (u32)1, NULL, NULL);
929 func->bridge = NULL;
930 }
931 }
932 760
933 /* 761 /*
934 * enable_device() enumerates all functions in this device via 762 * enable_device() enumerates all functions in this device via
@@ -947,7 +775,6 @@ static int disable_device(struct acpiphp_slot *slot)
947 775
948 slot->flags &= (~SLOT_ENABLED); 776 slot->flags &= (~SLOT_ENABLED);
949 777
950err_exit:
951 return 0; 778 return 0;
952} 779}
953 780
@@ -1037,7 +864,7 @@ static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
1037 864
1038 enabled = disabled = 0; 865 enabled = disabled = 0;
1039 866
1040 for (slot = bridge->slots; slot; slot = slot->next) { 867 list_for_each_entry(slot, &bridge->slots, node) {
1041 unsigned int status = get_slot_status(slot); 868 unsigned int status = get_slot_status(slot);
1042 if (slot->flags & SLOT_ENABLED) { 869 if (slot->flags & SLOT_ENABLED) {
1043 if (status == ACPI_STA_ALL) 870 if (status == ACPI_STA_ALL)
@@ -1082,11 +909,11 @@ static void acpiphp_set_hpp_values(struct pci_bus *bus)
1082 */ 909 */
1083static void acpiphp_sanitize_bus(struct pci_bus *bus) 910static void acpiphp_sanitize_bus(struct pci_bus *bus)
1084{ 911{
1085 struct pci_dev *dev; 912 struct pci_dev *dev, *tmp;
1086 int i; 913 int i;
1087 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM; 914 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
1088 915
1089 list_for_each_entry(dev, &bus->devices, bus_list) { 916 list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) {
1090 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) { 917 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
1091 struct resource *res = &dev->resource[i]; 918 struct resource *res = &dev->resource[i];
1092 if ((res->flags & type_mask) && !res->start && 919 if ((res->flags & type_mask) && !res->start &&
@@ -1118,6 +945,7 @@ check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
1118 dbg("%s: re-enumerating slots under %s\n", 945 dbg("%s: re-enumerating slots under %s\n",
1119 __func__, objname); 946 __func__, objname);
1120 acpiphp_check_bridge(bridge); 947 acpiphp_check_bridge(bridge);
948 put_bridge(bridge);
1121 } 949 }
1122 return AE_OK ; 950 return AE_OK ;
1123} 951}
@@ -1195,6 +1023,7 @@ static void _handle_hotplug_event_bridge(struct work_struct *work)
1195 1023
1196 acpi_scan_lock_release(); 1024 acpi_scan_lock_release();
1197 kfree(hp_work); /* allocated in handle_hotplug_event_bridge */ 1025 kfree(hp_work); /* allocated in handle_hotplug_event_bridge */
1026 put_bridge(bridge);
1198} 1027}
1199 1028
1200/** 1029/**
@@ -1208,6 +1037,8 @@ static void _handle_hotplug_event_bridge(struct work_struct *work)
1208static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, 1037static void handle_hotplug_event_bridge(acpi_handle handle, u32 type,
1209 void *context) 1038 void *context)
1210{ 1039{
1040 struct acpiphp_bridge *bridge = context;
1041
1211 /* 1042 /*
1212 * Currently the code adds all hotplug events to the kacpid_wq 1043 * Currently the code adds all hotplug events to the kacpid_wq
1213 * queue when it should add hotplug events to the kacpi_hotplug_wq. 1044 * queue when it should add hotplug events to the kacpi_hotplug_wq.
@@ -1216,6 +1047,7 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type,
1216 * For now just re-add this work to the kacpi_hotplug_wq so we 1047 * For now just re-add this work to the kacpi_hotplug_wq so we
1217 * don't deadlock on hotplug actions. 1048 * don't deadlock on hotplug actions.
1218 */ 1049 */
1050 get_bridge(bridge);
1219 alloc_acpi_hp_work(handle, type, context, _handle_hotplug_event_bridge); 1051 alloc_acpi_hp_work(handle, type, context, _handle_hotplug_event_bridge);
1220} 1052}
1221 1053
@@ -1270,6 +1102,7 @@ static void _handle_hotplug_event_func(struct work_struct *work)
1270 1102
1271 acpi_scan_lock_release(); 1103 acpi_scan_lock_release();
1272 kfree(hp_work); /* allocated in handle_hotplug_event_func */ 1104 kfree(hp_work); /* allocated in handle_hotplug_event_func */
1105 put_bridge(func->slot->bridge);
1273} 1106}
1274 1107
1275/** 1108/**
@@ -1283,6 +1116,8 @@ static void _handle_hotplug_event_func(struct work_struct *work)
1283static void handle_hotplug_event_func(acpi_handle handle, u32 type, 1116static void handle_hotplug_event_func(acpi_handle handle, u32 type,
1284 void *context) 1117 void *context)
1285{ 1118{
1119 struct acpiphp_func *func = context;
1120
1286 /* 1121 /*
1287 * Currently the code adds all hotplug events to the kacpid_wq 1122 * Currently the code adds all hotplug events to the kacpid_wq
1288 * queue when it should add hotplug events to the kacpi_hotplug_wq. 1123 * queue when it should add hotplug events to the kacpi_hotplug_wq.
@@ -1291,33 +1126,69 @@ static void handle_hotplug_event_func(acpi_handle handle, u32 type,
1291 * For now just re-add this work to the kacpi_hotplug_wq so we 1126 * For now just re-add this work to the kacpi_hotplug_wq so we
1292 * don't deadlock on hotplug actions. 1127 * don't deadlock on hotplug actions.
1293 */ 1128 */
1129 get_bridge(func->slot->bridge);
1294 alloc_acpi_hp_work(handle, type, context, _handle_hotplug_event_func); 1130 alloc_acpi_hp_work(handle, type, context, _handle_hotplug_event_func);
1295} 1131}
1296 1132
1297static struct acpi_pci_driver acpi_pci_hp_driver = { 1133/*
1298 .add = add_bridge, 1134 * Create hotplug slots for the PCI bus.
1299 .remove = remove_bridge, 1135 * It should always return 0 to avoid skipping following notifiers.
1300};
1301
1302/**
1303 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
1304 */ 1136 */
1305int __init acpiphp_glue_init(void) 1137void acpiphp_enumerate_slots(struct pci_bus *bus, acpi_handle handle)
1306{ 1138{
1307 acpi_pci_register_driver(&acpi_pci_hp_driver); 1139 acpi_handle dummy_handle;
1140 struct acpiphp_bridge *bridge;
1308 1141
1309 return 0; 1142 if (acpiphp_disabled)
1310} 1143 return;
1311 1144
1145 if (detect_ejectable_slots(handle) <= 0)
1146 return;
1312 1147
1313/** 1148 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
1314 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures 1149 if (bridge == NULL) {
1315 * 1150 err("out of memory\n");
1316 * This function frees all data allocated in acpiphp_glue_init(). 1151 return;
1317 */ 1152 }
1318void acpiphp_glue_exit(void) 1153
1154 INIT_LIST_HEAD(&bridge->slots);
1155 kref_init(&bridge->ref);
1156 bridge->handle = handle;
1157 bridge->pci_dev = pci_dev_get(bus->self);
1158 bridge->pci_bus = bus;
1159
1160 /*
1161 * Grab a ref to the subordinate PCI bus in case the bus is
1162 * removed via PCI core logical hotplug. The ref pins the bus
1163 * (which we access during module unload).
1164 */
1165 get_device(&bus->dev);
1166
1167 if (!pci_is_root_bus(bridge->pci_bus) &&
1168 ACPI_SUCCESS(acpi_get_handle(bridge->handle,
1169 "_EJ0", &dummy_handle))) {
1170 dbg("found ejectable p2p bridge\n");
1171 bridge->flags |= BRIDGE_HAS_EJ0;
1172 bridge->func = acpiphp_bridge_handle_to_function(handle);
1173 }
1174
1175 init_bridge_misc(bridge);
1176}
1177
1178/* Destroy hotplug slots associated with the PCI bus */
1179void acpiphp_remove_slots(struct pci_bus *bus)
1319{ 1180{
1320 acpi_pci_unregister_driver(&acpi_pci_hp_driver); 1181 struct acpiphp_bridge *bridge, *tmp;
1182
1183 if (acpiphp_disabled)
1184 return;
1185
1186 list_for_each_entry_safe(bridge, tmp, &bridge_list, list)
1187 if (bridge->pci_bus == bus) {
1188 cleanup_bridge(bridge);
1189 put_bridge(bridge);
1190 break;
1191 }
1321} 1192}
1322 1193
1323/** 1194/**
@@ -1396,7 +1267,7 @@ u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1396 1267
1397 sta = get_slot_status(slot); 1268 sta = get_slot_status(slot);
1398 1269
1399 return (sta & ACPI_STA_SHOW_IN_UI) ? 0 : 1; 1270 return (sta & ACPI_STA_DEVICE_UI) ? 0 : 1;
1400} 1271}
1401 1272
1402 1273
diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
index 9fff878cf026..1356211431d0 100644
--- a/drivers/pci/hotplug/cpci_hotplug.h
+++ b/drivers/pci/hotplug/cpci_hotplug.h
@@ -75,28 +75,36 @@ static inline const char *slot_name(struct slot *slot)
75 return hotplug_slot_name(slot->hotplug_slot); 75 return hotplug_slot_name(slot->hotplug_slot);
76} 76}
77 77
78extern int cpci_hp_register_controller(struct cpci_hp_controller *controller); 78int cpci_hp_register_controller(struct cpci_hp_controller *controller);
79extern int cpci_hp_unregister_controller(struct cpci_hp_controller *controller); 79int cpci_hp_unregister_controller(struct cpci_hp_controller *controller);
80extern int cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last); 80int cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last);
81extern int cpci_hp_unregister_bus(struct pci_bus *bus); 81int cpci_hp_unregister_bus(struct pci_bus *bus);
82extern int cpci_hp_start(void); 82int cpci_hp_start(void);
83extern int cpci_hp_stop(void); 83int cpci_hp_stop(void);
84 84
85/* 85/*
86 * Internal function prototypes, these functions should not be used by 86 * Internal function prototypes, these functions should not be used by
87 * board/chassis drivers. 87 * board/chassis drivers.
88 */ 88 */
89extern u8 cpci_get_attention_status(struct slot *slot); 89u8 cpci_get_attention_status(struct slot *slot);
90extern u8 cpci_get_latch_status(struct slot *slot); 90u8 cpci_get_latch_status(struct slot *slot);
91extern u8 cpci_get_adapter_status(struct slot *slot); 91u8 cpci_get_adapter_status(struct slot *slot);
92extern u16 cpci_get_hs_csr(struct slot * slot); 92u16 cpci_get_hs_csr(struct slot * slot);
93extern int cpci_set_attention_status(struct slot *slot, int status); 93int cpci_set_attention_status(struct slot *slot, int status);
94extern int cpci_check_and_clear_ins(struct slot * slot); 94int cpci_check_and_clear_ins(struct slot * slot);
95extern int cpci_check_ext(struct slot * slot); 95int cpci_check_ext(struct slot * slot);
96extern int cpci_clear_ext(struct slot * slot); 96int cpci_clear_ext(struct slot * slot);
97extern int cpci_led_on(struct slot * slot); 97int cpci_led_on(struct slot * slot);
98extern int cpci_led_off(struct slot * slot); 98int cpci_led_off(struct slot * slot);
99extern int cpci_configure_slot(struct slot *slot); 99int cpci_configure_slot(struct slot *slot);
100extern int cpci_unconfigure_slot(struct slot *slot); 100int cpci_unconfigure_slot(struct slot *slot);
101
102#ifdef CONFIG_HOTPLUG_PCI_CPCI
103int cpci_hotplug_init(int debug);
104void cpci_hotplug_exit(void);
105#else
106static inline int cpci_hotplug_init(int debug) { return 0; }
107static inline void cpci_hotplug_exit(void) { }
108#endif
101 109
102#endif /* _CPCI_HOTPLUG_H */ 110#endif /* _CPCI_HOTPLUG_H */
diff --git a/drivers/pci/hotplug/cpqphp.h b/drivers/pci/hotplug/cpqphp.h
index d8ffc7366801..516b87738b6e 100644
--- a/drivers/pci/hotplug/cpqphp.h
+++ b/drivers/pci/hotplug/cpqphp.h
@@ -404,50 +404,44 @@ struct resource_lists {
404 404
405 405
406/* debugfs functions for the hotplug controller info */ 406/* debugfs functions for the hotplug controller info */
407extern void cpqhp_initialize_debugfs(void); 407void cpqhp_initialize_debugfs(void);
408extern void cpqhp_shutdown_debugfs(void); 408void cpqhp_shutdown_debugfs(void);
409extern void cpqhp_create_debugfs_files(struct controller *ctrl); 409void cpqhp_create_debugfs_files(struct controller *ctrl);
410extern void cpqhp_remove_debugfs_files(struct controller *ctrl); 410void cpqhp_remove_debugfs_files(struct controller *ctrl);
411 411
412/* controller functions */ 412/* controller functions */
413extern void cpqhp_pushbutton_thread(unsigned long event_pointer); 413void cpqhp_pushbutton_thread(unsigned long event_pointer);
414extern irqreturn_t cpqhp_ctrl_intr(int IRQ, void *data); 414irqreturn_t cpqhp_ctrl_intr(int IRQ, void *data);
415extern int cpqhp_find_available_resources(struct controller *ctrl, 415int cpqhp_find_available_resources(struct controller *ctrl,
416 void __iomem *rom_start); 416 void __iomem *rom_start);
417extern int cpqhp_event_start_thread(void); 417int cpqhp_event_start_thread(void);
418extern void cpqhp_event_stop_thread(void); 418void cpqhp_event_stop_thread(void);
419extern struct pci_func *cpqhp_slot_create(unsigned char busnumber); 419struct pci_func *cpqhp_slot_create(unsigned char busnumber);
420extern struct pci_func *cpqhp_slot_find(unsigned char bus, unsigned char device, 420struct pci_func *cpqhp_slot_find(unsigned char bus, unsigned char device,
421 unsigned char index); 421 unsigned char index);
422extern int cpqhp_process_SI(struct controller *ctrl, struct pci_func *func); 422int cpqhp_process_SI(struct controller *ctrl, struct pci_func *func);
423extern int cpqhp_process_SS(struct controller *ctrl, struct pci_func *func); 423int cpqhp_process_SS(struct controller *ctrl, struct pci_func *func);
424extern int cpqhp_hardware_test(struct controller *ctrl, int test_num); 424int cpqhp_hardware_test(struct controller *ctrl, int test_num);
425 425
426/* resource functions */ 426/* resource functions */
427extern int cpqhp_resource_sort_and_combine (struct pci_resource **head); 427int cpqhp_resource_sort_and_combine (struct pci_resource **head);
428 428
429/* pci functions */ 429/* pci functions */
430extern int cpqhp_set_irq(u8 bus_num, u8 dev_num, u8 int_pin, u8 irq_num); 430int cpqhp_set_irq(u8 bus_num, u8 dev_num, u8 int_pin, u8 irq_num);
431extern int cpqhp_get_bus_dev(struct controller *ctrl, u8 *bus_num, u8 *dev_num, 431int cpqhp_get_bus_dev(struct controller *ctrl, u8 *bus_num, u8 *dev_num,
432 u8 slot); 432 u8 slot);
433extern int cpqhp_save_config(struct controller *ctrl, int busnumber, 433int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug);
434 int is_hot_plug); 434int cpqhp_save_base_addr_length(struct controller *ctrl, struct pci_func *func);
435extern int cpqhp_save_base_addr_length(struct controller *ctrl, 435int cpqhp_save_used_resources(struct controller *ctrl, struct pci_func *func);
436 struct pci_func *func); 436int cpqhp_configure_board(struct controller *ctrl, struct pci_func *func);
437extern int cpqhp_save_used_resources(struct controller *ctrl, 437int cpqhp_save_slot_config(struct controller *ctrl, struct pci_func *new_slot);
438 struct pci_func *func); 438int cpqhp_valid_replace(struct controller *ctrl, struct pci_func *func);
439extern int cpqhp_configure_board(struct controller *ctrl, 439void cpqhp_destroy_board_resources(struct pci_func *func);
440 struct pci_func *func); 440int cpqhp_return_board_resources(struct pci_func *func,
441extern int cpqhp_save_slot_config(struct controller *ctrl, 441 struct resource_lists *resources);
442 struct pci_func *new_slot); 442void cpqhp_destroy_resource_list(struct resource_lists *resources);
443extern int cpqhp_valid_replace(struct controller *ctrl, struct pci_func *func); 443int cpqhp_configure_device(struct controller *ctrl, struct pci_func *func);
444extern void cpqhp_destroy_board_resources(struct pci_func *func); 444int cpqhp_unconfigure_device(struct pci_func *func);
445extern int cpqhp_return_board_resources (struct pci_func *func,
446 struct resource_lists *resources);
447extern void cpqhp_destroy_resource_list(struct resource_lists *resources);
448extern int cpqhp_configure_device(struct controller *ctrl,
449 struct pci_func *func);
450extern int cpqhp_unconfigure_device(struct pci_func *func);
451 445
452/* Global variables */ 446/* Global variables */
453extern int cpqhp_debug; 447extern int cpqhp_debug;
diff --git a/drivers/pci/hotplug/cpqphp_nvram.h b/drivers/pci/hotplug/cpqphp_nvram.h
index e89c0702119d..34e4e54fcf15 100644
--- a/drivers/pci/hotplug/cpqphp_nvram.h
+++ b/drivers/pci/hotplug/cpqphp_nvram.h
@@ -30,26 +30,26 @@
30 30
31#ifndef CONFIG_HOTPLUG_PCI_COMPAQ_NVRAM 31#ifndef CONFIG_HOTPLUG_PCI_COMPAQ_NVRAM
32 32
33static inline void compaq_nvram_init (void __iomem *rom_start) 33static inline void compaq_nvram_init(void __iomem *rom_start)
34{ 34{
35 return; 35 return;
36} 36}
37 37
38static inline int compaq_nvram_load (void __iomem *rom_start, struct controller *ctrl) 38static inline int compaq_nvram_load(void __iomem *rom_start, struct controller *ctrl)
39{ 39{
40 return 0; 40 return 0;
41} 41}
42 42
43static inline int compaq_nvram_store (void __iomem *rom_start) 43static inline int compaq_nvram_store(void __iomem *rom_start)
44{ 44{
45 return 0; 45 return 0;
46} 46}
47 47
48#else 48#else
49 49
50extern void compaq_nvram_init (void __iomem *rom_start); 50void compaq_nvram_init(void __iomem *rom_start);
51extern int compaq_nvram_load (void __iomem *rom_start, struct controller *ctrl); 51int compaq_nvram_load(void __iomem *rom_start, struct controller *ctrl);
52extern int compaq_nvram_store (void __iomem *rom_start); 52int compaq_nvram_store(void __iomem *rom_start);
53 53
54#endif 54#endif
55 55
diff --git a/drivers/pci/hotplug/ibmphp.h b/drivers/pci/hotplug/ibmphp.h
index a8d391a4957d..8c5b25871d02 100644
--- a/drivers/pci/hotplug/ibmphp.h
+++ b/drivers/pci/hotplug/ibmphp.h
@@ -275,17 +275,17 @@ extern struct list_head ibmphp_slot_head;
275* FUNCTION PROTOTYPES * 275* FUNCTION PROTOTYPES *
276***********************************************************/ 276***********************************************************/
277 277
278extern void ibmphp_free_ebda_hpc_queue (void); 278void ibmphp_free_ebda_hpc_queue(void);
279extern int ibmphp_access_ebda (void); 279int ibmphp_access_ebda(void);
280extern struct slot *ibmphp_get_slot_from_physical_num (u8); 280struct slot *ibmphp_get_slot_from_physical_num(u8);
281extern int ibmphp_get_total_hp_slots (void); 281int ibmphp_get_total_hp_slots(void);
282extern void ibmphp_free_ibm_slot (struct slot *); 282void ibmphp_free_ibm_slot(struct slot *);
283extern void ibmphp_free_bus_info_queue (void); 283void ibmphp_free_bus_info_queue(void);
284extern void ibmphp_free_ebda_pci_rsrc_queue (void); 284void ibmphp_free_ebda_pci_rsrc_queue(void);
285extern struct bus_info *ibmphp_find_same_bus_num (u32); 285struct bus_info *ibmphp_find_same_bus_num(u32);
286extern int ibmphp_get_bus_index (u8); 286int ibmphp_get_bus_index(u8);
287extern u16 ibmphp_get_total_controllers (void); 287u16 ibmphp_get_total_controllers(void);
288extern int ibmphp_register_pci (void); 288int ibmphp_register_pci(void);
289 289
290/* passed parameters */ 290/* passed parameters */
291#define MEM 0 291#define MEM 0
@@ -381,24 +381,24 @@ struct res_needed {
381 381
382/* functions */ 382/* functions */
383 383
384extern int ibmphp_rsrc_init (void); 384int ibmphp_rsrc_init(void);
385extern int ibmphp_add_resource (struct resource_node *); 385int ibmphp_add_resource(struct resource_node *);
386extern int ibmphp_remove_resource (struct resource_node *); 386int ibmphp_remove_resource(struct resource_node *);
387extern int ibmphp_find_resource (struct bus_node *, u32, struct resource_node **, int); 387int ibmphp_find_resource(struct bus_node *, u32, struct resource_node **, int);
388extern int ibmphp_check_resource (struct resource_node *, u8); 388int ibmphp_check_resource(struct resource_node *, u8);
389extern int ibmphp_remove_bus (struct bus_node *, u8); 389int ibmphp_remove_bus(struct bus_node *, u8);
390extern void ibmphp_free_resources (void); 390void ibmphp_free_resources(void);
391extern int ibmphp_add_pfmem_from_mem (struct resource_node *); 391int ibmphp_add_pfmem_from_mem(struct resource_node *);
392extern struct bus_node *ibmphp_find_res_bus (u8); 392struct bus_node *ibmphp_find_res_bus(u8);
393extern void ibmphp_print_test (void); /* for debugging purposes */ 393void ibmphp_print_test(void); /* for debugging purposes */
394 394
395extern void ibmphp_hpc_initvars (void); 395void ibmphp_hpc_initvars(void);
396extern int ibmphp_hpc_readslot (struct slot *, u8, u8 *); 396int ibmphp_hpc_readslot(struct slot *, u8, u8 *);
397extern int ibmphp_hpc_writeslot (struct slot *, u8); 397int ibmphp_hpc_writeslot(struct slot *, u8);
398extern void ibmphp_lock_operations (void); 398void ibmphp_lock_operations(void);
399extern void ibmphp_unlock_operations (void); 399void ibmphp_unlock_operations(void);
400extern int ibmphp_hpc_start_poll_thread (void); 400int ibmphp_hpc_start_poll_thread(void);
401extern void ibmphp_hpc_stop_poll_thread (void); 401void ibmphp_hpc_stop_poll_thread(void);
402 402
403//---------------------------------------------------------------------------- 403//----------------------------------------------------------------------------
404 404
@@ -749,11 +749,11 @@ struct controller {
749 749
750/* Functions */ 750/* Functions */
751 751
752extern int ibmphp_init_devno (struct slot **); /* This function is called from EBDA, so we need it not be static */ 752int ibmphp_init_devno(struct slot **); /* This function is called from EBDA, so we need it not be static */
753extern int ibmphp_do_disable_slot (struct slot *slot_cur); 753int ibmphp_do_disable_slot(struct slot *slot_cur);
754extern int ibmphp_update_slot_info (struct slot *); /* This function is called from HPC, so we need it to not be be static */ 754int ibmphp_update_slot_info(struct slot *); /* This function is called from HPC, so we need it to not be be static */
755extern int ibmphp_configure_card (struct pci_func *, u8); 755int ibmphp_configure_card(struct pci_func *, u8);
756extern int ibmphp_unconfigure_card (struct slot **, int); 756int ibmphp_unconfigure_card(struct slot **, int);
757extern struct hotplug_slot_ops ibmphp_hotplug_slot_ops; 757extern struct hotplug_slot_ops ibmphp_hotplug_slot_ops;
758 758
759#endif //__IBMPHP_H 759#endif //__IBMPHP_H
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index 202f4a969eb5..ec20f74c8981 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -41,6 +41,7 @@
41#include <linux/pci_hotplug.h> 41#include <linux/pci_hotplug.h>
42#include <asm/uaccess.h> 42#include <asm/uaccess.h>
43#include "../pci.h" 43#include "../pci.h"
44#include "cpci_hotplug.h"
44 45
45#define MY_NAME "pci_hotplug" 46#define MY_NAME "pci_hotplug"
46 47
@@ -63,14 +64,6 @@ static bool debug;
63static LIST_HEAD(pci_hotplug_slot_list); 64static LIST_HEAD(pci_hotplug_slot_list);
64static DEFINE_MUTEX(pci_hp_mutex); 65static DEFINE_MUTEX(pci_hp_mutex);
65 66
66#ifdef CONFIG_HOTPLUG_PCI_CPCI
67extern int cpci_hotplug_init(int debug);
68extern void cpci_hotplug_exit(void);
69#else
70static inline int cpci_hotplug_init(int debug) { return 0; }
71static inline void cpci_hotplug_exit(void) { }
72#endif
73
74/* Weee, fun with macros... */ 67/* Weee, fun with macros... */
75#define GET_STATUS(name,type) \ 68#define GET_STATUS(name,type) \
76static int get_##name (struct hotplug_slot *slot, type *value) \ 69static int get_##name (struct hotplug_slot *slot, type *value) \
@@ -524,13 +517,11 @@ int pci_hp_deregister(struct hotplug_slot *hotplug)
524 * 517 *
525 * Returns 0 if successful, anything else for an error. 518 * Returns 0 if successful, anything else for an error.
526 */ 519 */
527int __must_check pci_hp_change_slot_info(struct hotplug_slot *hotplug, 520int pci_hp_change_slot_info(struct hotplug_slot *hotplug,
528 struct hotplug_slot_info *info) 521 struct hotplug_slot_info *info)
529{ 522{
530 struct pci_slot *slot;
531 if (!hotplug || !info) 523 if (!hotplug || !info)
532 return -ENODEV; 524 return -ENODEV;
533 slot = hotplug->pci_slot;
534 525
535 memcpy(hotplug->info, info, sizeof(struct hotplug_slot_info)); 526 memcpy(hotplug->info, info, sizeof(struct hotplug_slot_info));
536 527
diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
index 2c113de94323..7fb326983ed6 100644
--- a/drivers/pci/hotplug/pciehp.h
+++ b/drivers/pci/hotplug/pciehp.h
@@ -127,15 +127,15 @@ struct controller {
127#define NO_CMD_CMPL(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_NCCS) 127#define NO_CMD_CMPL(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_NCCS)
128#define PSN(ctrl) ((ctrl)->slot_cap >> 19) 128#define PSN(ctrl) ((ctrl)->slot_cap >> 19)
129 129
130extern int pciehp_sysfs_enable_slot(struct slot *slot); 130int pciehp_sysfs_enable_slot(struct slot *slot);
131extern int pciehp_sysfs_disable_slot(struct slot *slot); 131int pciehp_sysfs_disable_slot(struct slot *slot);
132extern u8 pciehp_handle_attention_button(struct slot *p_slot); 132u8 pciehp_handle_attention_button(struct slot *p_slot);
133extern u8 pciehp_handle_switch_change(struct slot *p_slot); 133u8 pciehp_handle_switch_change(struct slot *p_slot);
134extern u8 pciehp_handle_presence_change(struct slot *p_slot); 134u8 pciehp_handle_presence_change(struct slot *p_slot);
135extern u8 pciehp_handle_power_fault(struct slot *p_slot); 135u8 pciehp_handle_power_fault(struct slot *p_slot);
136extern int pciehp_configure_device(struct slot *p_slot); 136int pciehp_configure_device(struct slot *p_slot);
137extern int pciehp_unconfigure_device(struct slot *p_slot); 137int pciehp_unconfigure_device(struct slot *p_slot);
138extern void pciehp_queue_pushbutton_work(struct work_struct *work); 138void pciehp_queue_pushbutton_work(struct work_struct *work);
139struct controller *pcie_init(struct pcie_device *dev); 139struct controller *pcie_init(struct pcie_device *dev);
140int pcie_init_notification(struct controller *ctrl); 140int pcie_init_notification(struct controller *ctrl);
141int pciehp_enable_slot(struct slot *p_slot); 141int pciehp_enable_slot(struct slot *p_slot);
@@ -166,8 +166,8 @@ static inline const char *slot_name(struct slot *slot)
166#include <acpi/acpi_bus.h> 166#include <acpi/acpi_bus.h>
167#include <linux/pci-acpi.h> 167#include <linux/pci-acpi.h>
168 168
169extern void __init pciehp_acpi_slot_detection_init(void); 169void __init pciehp_acpi_slot_detection_init(void);
170extern int pciehp_acpi_slot_detection_check(struct pci_dev *dev); 170int pciehp_acpi_slot_detection_check(struct pci_dev *dev);
171 171
172static inline void pciehp_firmware_init(void) 172static inline void pciehp_firmware_init(void)
173{ 173{
diff --git a/drivers/pci/hotplug/pciehp_acpi.c b/drivers/pci/hotplug/pciehp_acpi.c
index 24d709b7388c..ead7c534095e 100644
--- a/drivers/pci/hotplug/pciehp_acpi.c
+++ b/drivers/pci/hotplug/pciehp_acpi.c
@@ -90,7 +90,7 @@ static int __init dummy_probe(struct pcie_device *dev)
90 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 90 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
91 if (!slot) 91 if (!slot)
92 return -ENOMEM; 92 return -ENOMEM;
93 slot->number = slot_cap >> 19; 93 slot->number = (slot_cap & PCI_EXP_SLTCAP_PSN) >> 19;
94 list_for_each_entry(tmp, &dummy_slots, list) { 94 list_for_each_entry(tmp, &dummy_slots, list) {
95 if (tmp->number == slot->number) 95 if (tmp->number == slot->number)
96 dup_slot_id++; 96 dup_slot_id++;
diff --git a/drivers/pci/hotplug/rpadlpar.h b/drivers/pci/hotplug/rpadlpar.h
index 4a0a59b82eae..81df93931ad0 100644
--- a/drivers/pci/hotplug/rpadlpar.h
+++ b/drivers/pci/hotplug/rpadlpar.h
@@ -15,10 +15,10 @@
15#ifndef _RPADLPAR_IO_H_ 15#ifndef _RPADLPAR_IO_H_
16#define _RPADLPAR_IO_H_ 16#define _RPADLPAR_IO_H_
17 17
18extern int dlpar_sysfs_init(void); 18int dlpar_sysfs_init(void);
19extern void dlpar_sysfs_exit(void); 19void dlpar_sysfs_exit(void);
20 20
21extern int dlpar_add_slot(char *drc_name); 21int dlpar_add_slot(char *drc_name);
22extern int dlpar_remove_slot(char *drc_name); 22int dlpar_remove_slot(char *drc_name);
23 23
24#endif 24#endif
diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h
index df5677440a08..3135856e5e1c 100644
--- a/drivers/pci/hotplug/rpaphp.h
+++ b/drivers/pci/hotplug/rpaphp.h
@@ -86,18 +86,18 @@ extern struct list_head rpaphp_slot_head;
86/* function prototypes */ 86/* function prototypes */
87 87
88/* rpaphp_pci.c */ 88/* rpaphp_pci.c */
89extern int rpaphp_enable_slot(struct slot *slot); 89int rpaphp_enable_slot(struct slot *slot);
90extern int rpaphp_get_sensor_state(struct slot *slot, int *state); 90int rpaphp_get_sensor_state(struct slot *slot, int *state);
91 91
92/* rpaphp_core.c */ 92/* rpaphp_core.c */
93extern int rpaphp_add_slot(struct device_node *dn); 93int rpaphp_add_slot(struct device_node *dn);
94extern int rpaphp_get_drc_props(struct device_node *dn, int *drc_index, 94int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
95 char **drc_name, char **drc_type, int *drc_power_domain); 95 char **drc_name, char **drc_type, int *drc_power_domain);
96 96
97/* rpaphp_slot.c */ 97/* rpaphp_slot.c */
98extern void dealloc_slot_struct(struct slot *slot); 98void dealloc_slot_struct(struct slot *slot);
99extern struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_name, int power_domain); 99struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_name, int power_domain);
100extern int rpaphp_register_slot(struct slot *slot); 100int rpaphp_register_slot(struct slot *slot);
101extern int rpaphp_deregister_slot(struct slot *slot); 101int rpaphp_deregister_slot(struct slot *slot);
102 102
103#endif /* _PPC64PHP_H */ 103#endif /* _PPC64PHP_H */
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
index b849f995075a..e260f207a90e 100644
--- a/drivers/pci/hotplug/shpchp.h
+++ b/drivers/pci/hotplug/shpchp.h
@@ -168,19 +168,19 @@ struct controller {
168#define WRONG_BUS_FREQUENCY 0x0000000D 168#define WRONG_BUS_FREQUENCY 0x0000000D
169#define POWER_FAILURE 0x0000000E 169#define POWER_FAILURE 0x0000000E
170 170
171extern int __must_check shpchp_create_ctrl_files(struct controller *ctrl); 171int __must_check shpchp_create_ctrl_files(struct controller *ctrl);
172extern void shpchp_remove_ctrl_files(struct controller *ctrl); 172void shpchp_remove_ctrl_files(struct controller *ctrl);
173extern int shpchp_sysfs_enable_slot(struct slot *slot); 173int shpchp_sysfs_enable_slot(struct slot *slot);
174extern int shpchp_sysfs_disable_slot(struct slot *slot); 174int shpchp_sysfs_disable_slot(struct slot *slot);
175extern u8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl); 175u8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl);
176extern u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl); 176u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl);
177extern u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl); 177u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl);
178extern u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl); 178u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl);
179extern int shpchp_configure_device(struct slot *p_slot); 179int shpchp_configure_device(struct slot *p_slot);
180extern int shpchp_unconfigure_device(struct slot *p_slot); 180int shpchp_unconfigure_device(struct slot *p_slot);
181extern void cleanup_slots(struct controller *ctrl); 181void cleanup_slots(struct controller *ctrl);
182extern void shpchp_queue_pushbutton_work(struct work_struct *work); 182void shpchp_queue_pushbutton_work(struct work_struct *work);
183extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev); 183int shpc_init( struct controller *ctrl, struct pci_dev *pdev);
184 184
185static inline const char *slot_name(struct slot *slot) 185static inline const char *slot_name(struct slot *slot)
186{ 186{
diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpchp_sysfs.c
index eeb23ceae4a8..e8c31fe20566 100644
--- a/drivers/pci/hotplug/shpchp_sysfs.c
+++ b/drivers/pci/hotplug/shpchp_sysfs.c
@@ -85,7 +85,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha
85} 85}
86static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL); 86static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL);
87 87
88int __must_check shpchp_create_ctrl_files (struct controller *ctrl) 88int shpchp_create_ctrl_files (struct controller *ctrl)
89{ 89{
90 return device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl); 90 return device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl);
91} 91}
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 00cc78c7aa04..d40bed726769 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -22,10 +22,12 @@
22#include <linux/slab.h> 22#include <linux/slab.h>
23 23
24#include "pci.h" 24#include "pci.h"
25#include "msi.h"
26 25
27static int pci_msi_enable = 1; 26static int pci_msi_enable = 1;
28 27
28#define msix_table_size(flags) ((flags & PCI_MSIX_FLAGS_QSIZE) + 1)
29
30
29/* Arch hooks */ 31/* Arch hooks */
30 32
31#ifndef arch_msi_check_device 33#ifndef arch_msi_check_device
@@ -111,32 +113,26 @@ void default_restore_msi_irqs(struct pci_dev *dev, int irq)
111} 113}
112#endif 114#endif
113 115
114static void msi_set_enable(struct pci_dev *dev, int pos, int enable) 116static void msi_set_enable(struct pci_dev *dev, int enable)
115{ 117{
116 u16 control; 118 u16 control;
117 119
118 BUG_ON(!pos); 120 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
119
120 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control);
121 control &= ~PCI_MSI_FLAGS_ENABLE; 121 control &= ~PCI_MSI_FLAGS_ENABLE;
122 if (enable) 122 if (enable)
123 control |= PCI_MSI_FLAGS_ENABLE; 123 control |= PCI_MSI_FLAGS_ENABLE;
124 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control); 124 pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
125} 125}
126 126
127static void msix_set_enable(struct pci_dev *dev, int enable) 127static void msix_set_enable(struct pci_dev *dev, int enable)
128{ 128{
129 int pos;
130 u16 control; 129 u16 control;
131 130
132 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 131 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
133 if (pos) { 132 control &= ~PCI_MSIX_FLAGS_ENABLE;
134 pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control); 133 if (enable)
135 control &= ~PCI_MSIX_FLAGS_ENABLE; 134 control |= PCI_MSIX_FLAGS_ENABLE;
136 if (enable) 135 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
137 control |= PCI_MSIX_FLAGS_ENABLE;
138 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control);
139 }
140} 136}
141 137
142static inline __attribute_const__ u32 msi_mask(unsigned x) 138static inline __attribute_const__ u32 msi_mask(unsigned x)
@@ -247,18 +243,18 @@ void __read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
247 msg->data = readl(base + PCI_MSIX_ENTRY_DATA); 243 msg->data = readl(base + PCI_MSIX_ENTRY_DATA);
248 } else { 244 } else {
249 struct pci_dev *dev = entry->dev; 245 struct pci_dev *dev = entry->dev;
250 int pos = entry->msi_attrib.pos; 246 int pos = dev->msi_cap;
251 u16 data; 247 u16 data;
252 248
253 pci_read_config_dword(dev, msi_lower_address_reg(pos), 249 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,
254 &msg->address_lo); 250 &msg->address_lo);
255 if (entry->msi_attrib.is_64) { 251 if (entry->msi_attrib.is_64) {
256 pci_read_config_dword(dev, msi_upper_address_reg(pos), 252 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
257 &msg->address_hi); 253 &msg->address_hi);
258 pci_read_config_word(dev, msi_data_reg(pos, 1), &data); 254 pci_read_config_word(dev, pos + PCI_MSI_DATA_64, &data);
259 } else { 255 } else {
260 msg->address_hi = 0; 256 msg->address_hi = 0;
261 pci_read_config_word(dev, msi_data_reg(pos, 0), &data); 257 pci_read_config_word(dev, pos + PCI_MSI_DATA_32, &data);
262 } 258 }
263 msg->data = data; 259 msg->data = data;
264 } 260 }
@@ -302,24 +298,24 @@ void __write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
302 writel(msg->data, base + PCI_MSIX_ENTRY_DATA); 298 writel(msg->data, base + PCI_MSIX_ENTRY_DATA);
303 } else { 299 } else {
304 struct pci_dev *dev = entry->dev; 300 struct pci_dev *dev = entry->dev;
305 int pos = entry->msi_attrib.pos; 301 int pos = dev->msi_cap;
306 u16 msgctl; 302 u16 msgctl;
307 303
308 pci_read_config_word(dev, msi_control_reg(pos), &msgctl); 304 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl);
309 msgctl &= ~PCI_MSI_FLAGS_QSIZE; 305 msgctl &= ~PCI_MSI_FLAGS_QSIZE;
310 msgctl |= entry->msi_attrib.multiple << 4; 306 msgctl |= entry->msi_attrib.multiple << 4;
311 pci_write_config_word(dev, msi_control_reg(pos), msgctl); 307 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl);
312 308
313 pci_write_config_dword(dev, msi_lower_address_reg(pos), 309 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,
314 msg->address_lo); 310 msg->address_lo);
315 if (entry->msi_attrib.is_64) { 311 if (entry->msi_attrib.is_64) {
316 pci_write_config_dword(dev, msi_upper_address_reg(pos), 312 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
317 msg->address_hi); 313 msg->address_hi);
318 pci_write_config_word(dev, msi_data_reg(pos, 1), 314 pci_write_config_word(dev, pos + PCI_MSI_DATA_64,
319 msg->data); 315 msg->data);
320 } else { 316 } else {
321 pci_write_config_word(dev, msi_data_reg(pos, 0), 317 pci_write_config_word(dev, pos + PCI_MSI_DATA_32,
322 msg->data); 318 msg->data);
323 } 319 }
324 } 320 }
325 entry->msg = *msg; 321 entry->msg = *msg;
@@ -391,7 +387,6 @@ static void pci_intx_for_msi(struct pci_dev *dev, int enable)
391 387
392static void __pci_restore_msi_state(struct pci_dev *dev) 388static void __pci_restore_msi_state(struct pci_dev *dev)
393{ 389{
394 int pos;
395 u16 control; 390 u16 control;
396 struct msi_desc *entry; 391 struct msi_desc *entry;
397 392
@@ -399,22 +394,20 @@ static void __pci_restore_msi_state(struct pci_dev *dev)
399 return; 394 return;
400 395
401 entry = irq_get_msi_desc(dev->irq); 396 entry = irq_get_msi_desc(dev->irq);
402 pos = entry->msi_attrib.pos;
403 397
404 pci_intx_for_msi(dev, 0); 398 pci_intx_for_msi(dev, 0);
405 msi_set_enable(dev, pos, 0); 399 msi_set_enable(dev, 0);
406 arch_restore_msi_irqs(dev, dev->irq); 400 arch_restore_msi_irqs(dev, dev->irq);
407 401
408 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); 402 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
409 msi_mask_irq(entry, msi_capable_mask(control), entry->masked); 403 msi_mask_irq(entry, msi_capable_mask(control), entry->masked);
410 control &= ~PCI_MSI_FLAGS_QSIZE; 404 control &= ~PCI_MSI_FLAGS_QSIZE;
411 control |= (entry->msi_attrib.multiple << 4) | PCI_MSI_FLAGS_ENABLE; 405 control |= (entry->msi_attrib.multiple << 4) | PCI_MSI_FLAGS_ENABLE;
412 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control); 406 pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
413} 407}
414 408
415static void __pci_restore_msix_state(struct pci_dev *dev) 409static void __pci_restore_msix_state(struct pci_dev *dev)
416{ 410{
417 int pos;
418 struct msi_desc *entry; 411 struct msi_desc *entry;
419 u16 control; 412 u16 control;
420 413
@@ -422,13 +415,12 @@ static void __pci_restore_msix_state(struct pci_dev *dev)
422 return; 415 return;
423 BUG_ON(list_empty(&dev->msi_list)); 416 BUG_ON(list_empty(&dev->msi_list));
424 entry = list_first_entry(&dev->msi_list, struct msi_desc, list); 417 entry = list_first_entry(&dev->msi_list, struct msi_desc, list);
425 pos = entry->msi_attrib.pos; 418 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
426 pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control);
427 419
428 /* route the table */ 420 /* route the table */
429 pci_intx_for_msi(dev, 0); 421 pci_intx_for_msi(dev, 0);
430 control |= PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL; 422 control |= PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL;
431 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); 423 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
432 424
433 list_for_each_entry(entry, &dev->msi_list, list) { 425 list_for_each_entry(entry, &dev->msi_list, list) {
434 arch_restore_msi_irqs(dev, entry->irq); 426 arch_restore_msi_irqs(dev, entry->irq);
@@ -436,7 +428,7 @@ static void __pci_restore_msix_state(struct pci_dev *dev)
436 } 428 }
437 429
438 control &= ~PCI_MSIX_FLAGS_MASKALL; 430 control &= ~PCI_MSIX_FLAGS_MASKALL;
439 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); 431 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
440} 432}
441 433
442void pci_restore_msi_state(struct pci_dev *dev) 434void pci_restore_msi_state(struct pci_dev *dev)
@@ -484,12 +476,12 @@ static struct msi_attribute mode_attribute =
484 __ATTR(mode, S_IRUGO, show_msi_mode, NULL); 476 __ATTR(mode, S_IRUGO, show_msi_mode, NULL);
485 477
486 478
487struct attribute *msi_irq_default_attrs[] = { 479static struct attribute *msi_irq_default_attrs[] = {
488 &mode_attribute.attr, 480 &mode_attribute.attr,
489 NULL 481 NULL
490}; 482};
491 483
492void msi_kobj_release(struct kobject *kobj) 484static void msi_kobj_release(struct kobject *kobj)
493{ 485{
494 struct msi_desc *entry = to_msi_desc(kobj); 486 struct msi_desc *entry = to_msi_desc(kobj);
495 487
@@ -552,27 +544,27 @@ out_unroll:
552static int msi_capability_init(struct pci_dev *dev, int nvec) 544static int msi_capability_init(struct pci_dev *dev, int nvec)
553{ 545{
554 struct msi_desc *entry; 546 struct msi_desc *entry;
555 int pos, ret; 547 int ret;
556 u16 control; 548 u16 control;
557 unsigned mask; 549 unsigned mask;
558 550
559 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 551 msi_set_enable(dev, 0); /* Disable MSI during set up */
560 msi_set_enable(dev, pos, 0); /* Disable MSI during set up */
561 552
562 pci_read_config_word(dev, msi_control_reg(pos), &control); 553 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
563 /* MSI Entry Initialization */ 554 /* MSI Entry Initialization */
564 entry = alloc_msi_entry(dev); 555 entry = alloc_msi_entry(dev);
565 if (!entry) 556 if (!entry)
566 return -ENOMEM; 557 return -ENOMEM;
567 558
568 entry->msi_attrib.is_msix = 0; 559 entry->msi_attrib.is_msix = 0;
569 entry->msi_attrib.is_64 = is_64bit_address(control); 560 entry->msi_attrib.is_64 = !!(control & PCI_MSI_FLAGS_64BIT);
570 entry->msi_attrib.entry_nr = 0; 561 entry->msi_attrib.entry_nr = 0;
571 entry->msi_attrib.maskbit = is_mask_bit_support(control); 562 entry->msi_attrib.maskbit = !!(control & PCI_MSI_FLAGS_MASKBIT);
572 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ 563 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */
573 entry->msi_attrib.pos = pos; 564 entry->msi_attrib.pos = dev->msi_cap;
574 565
575 entry->mask_pos = msi_mask_reg(pos, entry->msi_attrib.is_64); 566 entry->mask_pos = dev->msi_cap + (control & PCI_MSI_FLAGS_64BIT) ?
567 PCI_MSI_MASK_64 : PCI_MSI_MASK_32;
576 /* All MSIs are unmasked by default, Mask them all */ 568 /* All MSIs are unmasked by default, Mask them all */
577 if (entry->msi_attrib.maskbit) 569 if (entry->msi_attrib.maskbit)
578 pci_read_config_dword(dev, entry->mask_pos, &entry->masked); 570 pci_read_config_dword(dev, entry->mask_pos, &entry->masked);
@@ -598,31 +590,30 @@ static int msi_capability_init(struct pci_dev *dev, int nvec)
598 590
599 /* Set MSI enabled bits */ 591 /* Set MSI enabled bits */
600 pci_intx_for_msi(dev, 0); 592 pci_intx_for_msi(dev, 0);
601 msi_set_enable(dev, pos, 1); 593 msi_set_enable(dev, 1);
602 dev->msi_enabled = 1; 594 dev->msi_enabled = 1;
603 595
604 dev->irq = entry->irq; 596 dev->irq = entry->irq;
605 return 0; 597 return 0;
606} 598}
607 599
608static void __iomem *msix_map_region(struct pci_dev *dev, unsigned pos, 600static void __iomem *msix_map_region(struct pci_dev *dev, unsigned nr_entries)
609 unsigned nr_entries)
610{ 601{
611 resource_size_t phys_addr; 602 resource_size_t phys_addr;
612 u32 table_offset; 603 u32 table_offset;
613 u8 bir; 604 u8 bir;
614 605
615 pci_read_config_dword(dev, msix_table_offset_reg(pos), &table_offset); 606 pci_read_config_dword(dev, dev->msix_cap + PCI_MSIX_TABLE,
616 bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK); 607 &table_offset);
617 table_offset &= ~PCI_MSIX_FLAGS_BIRMASK; 608 bir = (u8)(table_offset & PCI_MSIX_TABLE_BIR);
609 table_offset &= PCI_MSIX_TABLE_OFFSET;
618 phys_addr = pci_resource_start(dev, bir) + table_offset; 610 phys_addr = pci_resource_start(dev, bir) + table_offset;
619 611
620 return ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE); 612 return ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE);
621} 613}
622 614
623static int msix_setup_entries(struct pci_dev *dev, unsigned pos, 615static int msix_setup_entries(struct pci_dev *dev, void __iomem *base,
624 void __iomem *base, struct msix_entry *entries, 616 struct msix_entry *entries, int nvec)
625 int nvec)
626{ 617{
627 struct msi_desc *entry; 618 struct msi_desc *entry;
628 int i; 619 int i;
@@ -642,7 +633,7 @@ static int msix_setup_entries(struct pci_dev *dev, unsigned pos,
642 entry->msi_attrib.is_64 = 1; 633 entry->msi_attrib.is_64 = 1;
643 entry->msi_attrib.entry_nr = entries[i].entry; 634 entry->msi_attrib.entry_nr = entries[i].entry;
644 entry->msi_attrib.default_irq = dev->irq; 635 entry->msi_attrib.default_irq = dev->irq;
645 entry->msi_attrib.pos = pos; 636 entry->msi_attrib.pos = dev->msix_cap;
646 entry->mask_base = base; 637 entry->mask_base = base;
647 638
648 list_add_tail(&entry->list, &dev->msi_list); 639 list_add_tail(&entry->list, &dev->msi_list);
@@ -652,7 +643,7 @@ static int msix_setup_entries(struct pci_dev *dev, unsigned pos,
652} 643}
653 644
654static void msix_program_entries(struct pci_dev *dev, 645static void msix_program_entries(struct pci_dev *dev,
655 struct msix_entry *entries) 646 struct msix_entry *entries)
656{ 647{
657 struct msi_desc *entry; 648 struct msi_desc *entry;
658 int i = 0; 649 int i = 0;
@@ -682,23 +673,22 @@ static void msix_program_entries(struct pci_dev *dev,
682static int msix_capability_init(struct pci_dev *dev, 673static int msix_capability_init(struct pci_dev *dev,
683 struct msix_entry *entries, int nvec) 674 struct msix_entry *entries, int nvec)
684{ 675{
685 int pos, ret; 676 int ret;
686 u16 control; 677 u16 control;
687 void __iomem *base; 678 void __iomem *base;
688 679
689 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 680 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
690 pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control);
691 681
692 /* Ensure MSI-X is disabled while it is set up */ 682 /* Ensure MSI-X is disabled while it is set up */
693 control &= ~PCI_MSIX_FLAGS_ENABLE; 683 control &= ~PCI_MSIX_FLAGS_ENABLE;
694 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); 684 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
695 685
696 /* Request & Map MSI-X table region */ 686 /* Request & Map MSI-X table region */
697 base = msix_map_region(dev, pos, multi_msix_capable(control)); 687 base = msix_map_region(dev, msix_table_size(control));
698 if (!base) 688 if (!base)
699 return -ENOMEM; 689 return -ENOMEM;
700 690
701 ret = msix_setup_entries(dev, pos, base, entries, nvec); 691 ret = msix_setup_entries(dev, base, entries, nvec);
702 if (ret) 692 if (ret)
703 return ret; 693 return ret;
704 694
@@ -712,7 +702,7 @@ static int msix_capability_init(struct pci_dev *dev,
712 * interrupts coming in before they're fully set up. 702 * interrupts coming in before they're fully set up.
713 */ 703 */
714 control |= PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE; 704 control |= PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE;
715 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); 705 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
716 706
717 msix_program_entries(dev, entries); 707 msix_program_entries(dev, entries);
718 708
@@ -727,7 +717,7 @@ static int msix_capability_init(struct pci_dev *dev,
727 dev->msix_enabled = 1; 717 dev->msix_enabled = 1;
728 718
729 control &= ~PCI_MSIX_FLAGS_MASKALL; 719 control &= ~PCI_MSIX_FLAGS_MASKALL;
730 pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); 720 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
731 721
732 return 0; 722 return 0;
733 723
@@ -795,9 +785,6 @@ static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type)
795 if (ret) 785 if (ret)
796 return ret; 786 return ret;
797 787
798 if (!pci_find_capability(dev, type))
799 return -EINVAL;
800
801 return 0; 788 return 0;
802} 789}
803 790
@@ -816,13 +803,13 @@ static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type)
816 */ 803 */
817int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec) 804int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec)
818{ 805{
819 int status, pos, maxvec; 806 int status, maxvec;
820 u16 msgctl; 807 u16 msgctl;
821 808
822 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 809 if (!dev->msi_cap)
823 if (!pos)
824 return -EINVAL; 810 return -EINVAL;
825 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); 811
812 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
826 maxvec = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1); 813 maxvec = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1);
827 if (nvec > maxvec) 814 if (nvec > maxvec)
828 return maxvec; 815 return maxvec;
@@ -847,14 +834,13 @@ EXPORT_SYMBOL(pci_enable_msi_block);
847 834
848int pci_enable_msi_block_auto(struct pci_dev *dev, unsigned int *maxvec) 835int pci_enable_msi_block_auto(struct pci_dev *dev, unsigned int *maxvec)
849{ 836{
850 int ret, pos, nvec; 837 int ret, nvec;
851 u16 msgctl; 838 u16 msgctl;
852 839
853 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 840 if (!dev->msi_cap)
854 if (!pos)
855 return -EINVAL; 841 return -EINVAL;
856 842
857 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); 843 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
858 ret = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1); 844 ret = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1);
859 845
860 if (maxvec) 846 if (maxvec)
@@ -876,21 +862,19 @@ void pci_msi_shutdown(struct pci_dev *dev)
876 struct msi_desc *desc; 862 struct msi_desc *desc;
877 u32 mask; 863 u32 mask;
878 u16 ctrl; 864 u16 ctrl;
879 unsigned pos;
880 865
881 if (!pci_msi_enable || !dev || !dev->msi_enabled) 866 if (!pci_msi_enable || !dev || !dev->msi_enabled)
882 return; 867 return;
883 868
884 BUG_ON(list_empty(&dev->msi_list)); 869 BUG_ON(list_empty(&dev->msi_list));
885 desc = list_first_entry(&dev->msi_list, struct msi_desc, list); 870 desc = list_first_entry(&dev->msi_list, struct msi_desc, list);
886 pos = desc->msi_attrib.pos;
887 871
888 msi_set_enable(dev, pos, 0); 872 msi_set_enable(dev, 0);
889 pci_intx_for_msi(dev, 1); 873 pci_intx_for_msi(dev, 1);
890 dev->msi_enabled = 0; 874 dev->msi_enabled = 0;
891 875
892 /* Return the device with MSI unmasked as initial states */ 876 /* Return the device with MSI unmasked as initial states */
893 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &ctrl); 877 pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &ctrl);
894 mask = msi_capable_mask(ctrl); 878 mask = msi_capable_mask(ctrl);
895 /* Keep cached state to be restored */ 879 /* Keep cached state to be restored */
896 __msi_mask_irq(desc, mask, ~mask); 880 __msi_mask_irq(desc, mask, ~mask);
@@ -917,15 +901,13 @@ EXPORT_SYMBOL(pci_disable_msi);
917 */ 901 */
918int pci_msix_table_size(struct pci_dev *dev) 902int pci_msix_table_size(struct pci_dev *dev)
919{ 903{
920 int pos;
921 u16 control; 904 u16 control;
922 905
923 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 906 if (!dev->msix_cap)
924 if (!pos)
925 return 0; 907 return 0;
926 908
927 pci_read_config_word(dev, msi_control_reg(pos), &control); 909 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
928 return multi_msix_capable(control); 910 return msix_table_size(control);
929} 911}
930 912
931/** 913/**
@@ -948,7 +930,7 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
948 int status, nr_entries; 930 int status, nr_entries;
949 int i, j; 931 int i, j;
950 932
951 if (!entries) 933 if (!entries || !dev->msix_cap)
952 return -EINVAL; 934 return -EINVAL;
953 935
954 status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSIX); 936 status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSIX);
@@ -1048,15 +1030,17 @@ EXPORT_SYMBOL(pci_msi_enabled);
1048 1030
1049void pci_msi_init_pci_dev(struct pci_dev *dev) 1031void pci_msi_init_pci_dev(struct pci_dev *dev)
1050{ 1032{
1051 int pos;
1052 INIT_LIST_HEAD(&dev->msi_list); 1033 INIT_LIST_HEAD(&dev->msi_list);
1053 1034
1054 /* Disable the msi hardware to avoid screaming interrupts 1035 /* Disable the msi hardware to avoid screaming interrupts
1055 * during boot. This is the power on reset default so 1036 * during boot. This is the power on reset default so
1056 * usually this should be a noop. 1037 * usually this should be a noop.
1057 */ 1038 */
1058 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 1039 dev->msi_cap = pci_find_capability(dev, PCI_CAP_ID_MSI);
1059 if (pos) 1040 if (dev->msi_cap)
1060 msi_set_enable(dev, pos, 0); 1041 msi_set_enable(dev, 0);
1061 msix_set_enable(dev, 0); 1042
1043 dev->msix_cap = pci_find_capability(dev, PCI_CAP_ID_MSIX);
1044 if (dev->msix_cap)
1045 msix_set_enable(dev, 0);
1062} 1046}
diff --git a/drivers/pci/msi.h b/drivers/pci/msi.h
deleted file mode 100644
index 65c42f80f23e..000000000000
--- a/drivers/pci/msi.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/*
2 * Copyright (C) 2003-2004 Intel
3 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
4 */
5
6#ifndef MSI_H
7#define MSI_H
8
9#define msi_control_reg(base) (base + PCI_MSI_FLAGS)
10#define msi_lower_address_reg(base) (base + PCI_MSI_ADDRESS_LO)
11#define msi_upper_address_reg(base) (base + PCI_MSI_ADDRESS_HI)
12#define msi_data_reg(base, is64bit) \
13 (base + ((is64bit == 1) ? PCI_MSI_DATA_64 : PCI_MSI_DATA_32))
14#define msi_mask_reg(base, is64bit) \
15 (base + ((is64bit == 1) ? PCI_MSI_MASK_64 : PCI_MSI_MASK_32))
16#define is_64bit_address(control) (!!(control & PCI_MSI_FLAGS_64BIT))
17#define is_mask_bit_support(control) (!!(control & PCI_MSI_FLAGS_MASKBIT))
18
19#define msix_table_offset_reg(base) (base + PCI_MSIX_TABLE)
20#define msix_pba_offset_reg(base) (base + PCI_MSIX_PBA)
21#define msix_table_size(control) ((control & PCI_MSIX_FLAGS_QSIZE)+1)
22#define multi_msix_capable(control) msix_table_size((control))
23
24#endif /* MSI_H */
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 5147c210df52..e4b1fb2c0f5d 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -288,6 +288,32 @@ static struct pci_platform_pm_ops acpi_pci_platform_pm = {
288 .run_wake = acpi_pci_run_wake, 288 .run_wake = acpi_pci_run_wake,
289}; 289};
290 290
291void acpi_pci_add_bus(struct pci_bus *bus)
292{
293 acpi_handle handle = NULL;
294
295 if (bus->bridge)
296 handle = ACPI_HANDLE(bus->bridge);
297 if (acpi_pci_disabled || handle == NULL)
298 return;
299
300 acpi_pci_slot_enumerate(bus, handle);
301 acpiphp_enumerate_slots(bus, handle);
302}
303
304void acpi_pci_remove_bus(struct pci_bus *bus)
305{
306 /*
307 * bus->bridge->acpi_node.handle has already been reset to NULL
308 * when acpi_pci_remove_bus() is called, so don't check ACPI handle.
309 */
310 if (acpi_pci_disabled)
311 return;
312
313 acpiphp_remove_slots(bus);
314 acpi_pci_slot_remove(bus);
315}
316
291/* ACPI bus type */ 317/* ACPI bus type */
292static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) 318static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
293{ 319{
@@ -362,7 +388,11 @@ static int __init acpi_pci_init(void)
362 ret = register_acpi_bus_type(&acpi_pci_bus); 388 ret = register_acpi_bus_type(&acpi_pci_bus);
363 if (ret) 389 if (ret)
364 return 0; 390 return 0;
391
365 pci_set_platform_pm(&acpi_pci_platform_pm); 392 pci_set_platform_pm(&acpi_pci_platform_pm);
393 acpi_pci_slot_init();
394 acpiphp_init();
395
366 return 0; 396 return 0;
367} 397}
368arch_initcall(acpi_pci_init); 398arch_initcall(acpi_pci_init);
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 9c6e9bb674ec..5b4a9d9cd200 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -897,7 +897,7 @@ int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
897 897
898 if (pci_resource_len(pdev, resno) == 0) 898 if (pci_resource_len(pdev, resno) == 0)
899 return 0; 899 return 0;
900 nr = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; 900 nr = vma_pages(vma);
901 start = vma->vm_pgoff; 901 start = vma->vm_pgoff;
902 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1; 902 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
903 pci_start = (mmap_api == PCI_MMAP_PROCFS) ? 903 pci_start = (mmap_api == PCI_MMAP_PROCFS) ?
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b099e0025d2b..a899d8bb190d 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -646,15 +646,11 @@ static int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state)
646 error = platform_pci_set_power_state(dev, state); 646 error = platform_pci_set_power_state(dev, state);
647 if (!error) 647 if (!error)
648 pci_update_current_state(dev, state); 648 pci_update_current_state(dev, state);
649 /* Fall back to PCI_D0 if native PM is not supported */ 649 } else
650 if (!dev->pm_cap)
651 dev->current_state = PCI_D0;
652 } else {
653 error = -ENODEV; 650 error = -ENODEV;
654 /* Fall back to PCI_D0 if native PM is not supported */ 651
655 if (!dev->pm_cap) 652 if (error && !dev->pm_cap) /* Fall back to PCI_D0 */
656 dev->current_state = PCI_D0; 653 dev->current_state = PCI_D0;
657 }
658 654
659 return error; 655 return error;
660} 656}
@@ -1575,7 +1571,7 @@ void pci_pme_active(struct pci_dev *dev, bool enable)
1575{ 1571{
1576 u16 pmcsr; 1572 u16 pmcsr;
1577 1573
1578 if (!dev->pm_cap) 1574 if (!dev->pme_support)
1579 return; 1575 return;
1580 1576
1581 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); 1577 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
@@ -1924,6 +1920,7 @@ void pci_pm_init(struct pci_dev *dev)
1924 dev->wakeup_prepared = false; 1920 dev->wakeup_prepared = false;
1925 1921
1926 dev->pm_cap = 0; 1922 dev->pm_cap = 0;
1923 dev->pme_support = 0;
1927 1924
1928 /* find PCI PM capability in list */ 1925 /* find PCI PM capability in list */
1929 pm = pci_find_capability(dev, PCI_CAP_ID_PM); 1926 pm = pci_find_capability(dev, PCI_CAP_ID_PM);
@@ -1975,8 +1972,6 @@ void pci_pm_init(struct pci_dev *dev)
1975 device_set_wakeup_capable(&dev->dev, true); 1972 device_set_wakeup_capable(&dev->dev, true);
1976 /* Disable the PME# generation functionality */ 1973 /* Disable the PME# generation functionality */
1977 pci_pme_active(dev, false); 1974 pci_pme_active(dev, false);
1978 } else {
1979 dev->pme_support = 0;
1980 } 1975 }
1981} 1976}
1982 1977
@@ -2619,7 +2614,7 @@ void pci_release_selected_regions(struct pci_dev *pdev, int bars)
2619 pci_release_region(pdev, i); 2614 pci_release_region(pdev, i);
2620} 2615}
2621 2616
2622int __pci_request_selected_regions(struct pci_dev *pdev, int bars, 2617static int __pci_request_selected_regions(struct pci_dev *pdev, int bars,
2623 const char *res_name, int excl) 2618 const char *res_name, int excl)
2624{ 2619{
2625 int i; 2620 int i;
@@ -3699,7 +3694,7 @@ static DEFINE_SPINLOCK(resource_alignment_lock);
3699 * RETURNS: Resource alignment if it is specified. 3694 * RETURNS: Resource alignment if it is specified.
3700 * Zero if it is not specified. 3695 * Zero if it is not specified.
3701 */ 3696 */
3702resource_size_t pci_specified_resource_alignment(struct pci_dev *dev) 3697static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev)
3703{ 3698{
3704 int seg, bus, slot, func, align_order, count; 3699 int seg, bus, slot, func, align_order, count;
3705 resource_size_t align = 0; 3700 resource_size_t align = 0;
@@ -3812,7 +3807,7 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev)
3812 } 3807 }
3813} 3808}
3814 3809
3815ssize_t pci_set_resource_alignment_param(const char *buf, size_t count) 3810static ssize_t pci_set_resource_alignment_param(const char *buf, size_t count)
3816{ 3811{
3817 if (count > RESOURCE_ALIGNMENT_PARAM_SIZE - 1) 3812 if (count > RESOURCE_ALIGNMENT_PARAM_SIZE - 1)
3818 count = RESOURCE_ALIGNMENT_PARAM_SIZE - 1; 3813 count = RESOURCE_ALIGNMENT_PARAM_SIZE - 1;
@@ -3823,7 +3818,7 @@ ssize_t pci_set_resource_alignment_param(const char *buf, size_t count)
3823 return count; 3818 return count;
3824} 3819}
3825 3820
3826ssize_t pci_get_resource_alignment_param(char *buf, size_t size) 3821static ssize_t pci_get_resource_alignment_param(char *buf, size_t size)
3827{ 3822{
3828 size_t count; 3823 size_t count;
3829 spin_lock(&resource_alignment_lock); 3824 spin_lock(&resource_alignment_lock);
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 7346ee68f47d..68678ed76b0d 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -8,26 +8,25 @@
8 8
9/* Functions internal to the PCI core code */ 9/* Functions internal to the PCI core code */
10 10
11extern int pci_create_sysfs_dev_files(struct pci_dev *pdev); 11int pci_create_sysfs_dev_files(struct pci_dev *pdev);
12extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev); 12void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
13#if !defined(CONFIG_DMI) && !defined(CONFIG_ACPI) 13#if !defined(CONFIG_DMI) && !defined(CONFIG_ACPI)
14static inline void pci_create_firmware_label_files(struct pci_dev *pdev) 14static inline void pci_create_firmware_label_files(struct pci_dev *pdev)
15{ return; } 15{ return; }
16static inline void pci_remove_firmware_label_files(struct pci_dev *pdev) 16static inline void pci_remove_firmware_label_files(struct pci_dev *pdev)
17{ return; } 17{ return; }
18#else 18#else
19extern void pci_create_firmware_label_files(struct pci_dev *pdev); 19void pci_create_firmware_label_files(struct pci_dev *pdev);
20extern void pci_remove_firmware_label_files(struct pci_dev *pdev); 20void pci_remove_firmware_label_files(struct pci_dev *pdev);
21#endif 21#endif
22extern void pci_cleanup_rom(struct pci_dev *dev); 22void pci_cleanup_rom(struct pci_dev *dev);
23#ifdef HAVE_PCI_MMAP 23#ifdef HAVE_PCI_MMAP
24enum pci_mmap_api { 24enum pci_mmap_api {
25 PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */ 25 PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */
26 PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */ 26 PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */
27}; 27};
28extern int pci_mmap_fits(struct pci_dev *pdev, int resno, 28int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai,
29 struct vm_area_struct *vmai, 29 enum pci_mmap_api mmap_api);
30 enum pci_mmap_api mmap_api);
31#endif 30#endif
32int pci_probe_reset_function(struct pci_dev *dev); 31int pci_probe_reset_function(struct pci_dev *dev);
33 32
@@ -60,17 +59,17 @@ struct pci_platform_pm_ops {
60 int (*run_wake)(struct pci_dev *dev, bool enable); 59 int (*run_wake)(struct pci_dev *dev, bool enable);
61}; 60};
62 61
63extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops); 62int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
64extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state); 63void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
65extern void pci_power_up(struct pci_dev *dev); 64void pci_power_up(struct pci_dev *dev);
66extern void pci_disable_enabled_device(struct pci_dev *dev); 65void pci_disable_enabled_device(struct pci_dev *dev);
67extern int pci_finish_runtime_suspend(struct pci_dev *dev); 66int pci_finish_runtime_suspend(struct pci_dev *dev);
68extern int __pci_pme_wakeup(struct pci_dev *dev, void *ign); 67int __pci_pme_wakeup(struct pci_dev *dev, void *ign);
69extern void pci_wakeup_bus(struct pci_bus *bus); 68void pci_wakeup_bus(struct pci_bus *bus);
70extern void pci_config_pm_runtime_get(struct pci_dev *dev); 69void pci_config_pm_runtime_get(struct pci_dev *dev);
71extern void pci_config_pm_runtime_put(struct pci_dev *dev); 70void pci_config_pm_runtime_put(struct pci_dev *dev);
72extern void pci_pm_init(struct pci_dev *dev); 71void pci_pm_init(struct pci_dev *dev);
73extern void pci_allocate_cap_save_buffers(struct pci_dev *dev); 72void pci_allocate_cap_save_buffers(struct pci_dev *dev);
74void pci_free_cap_save_buffers(struct pci_dev *dev); 73void pci_free_cap_save_buffers(struct pci_dev *dev);
75 74
76static inline void pci_wakeup_event(struct pci_dev *dev) 75static inline void pci_wakeup_event(struct pci_dev *dev)
@@ -96,7 +95,7 @@ struct pci_vpd {
96 struct bin_attribute *attr; /* descriptor for sysfs VPD entry */ 95 struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
97}; 96};
98 97
99extern int pci_vpd_pci22_init(struct pci_dev *dev); 98int pci_vpd_pci22_init(struct pci_dev *dev);
100static inline void pci_vpd_release(struct pci_dev *dev) 99static inline void pci_vpd_release(struct pci_dev *dev)
101{ 100{
102 if (dev->vpd) 101 if (dev->vpd)
@@ -105,9 +104,9 @@ static inline void pci_vpd_release(struct pci_dev *dev)
105 104
106/* PCI /proc functions */ 105/* PCI /proc functions */
107#ifdef CONFIG_PROC_FS 106#ifdef CONFIG_PROC_FS
108extern int pci_proc_attach_device(struct pci_dev *dev); 107int pci_proc_attach_device(struct pci_dev *dev);
109extern int pci_proc_detach_device(struct pci_dev *dev); 108int pci_proc_detach_device(struct pci_dev *dev);
110extern int pci_proc_detach_bus(struct pci_bus *bus); 109int pci_proc_detach_bus(struct pci_bus *bus);
111#else 110#else
112static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; } 111static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; }
113static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; } 112static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; }
@@ -118,8 +117,8 @@ static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
118int pci_hp_add_bridge(struct pci_dev *dev); 117int pci_hp_add_bridge(struct pci_dev *dev);
119 118
120#ifdef HAVE_PCI_LEGACY 119#ifdef HAVE_PCI_LEGACY
121extern void pci_create_legacy_files(struct pci_bus *bus); 120void pci_create_legacy_files(struct pci_bus *bus);
122extern void pci_remove_legacy_files(struct pci_bus *bus); 121void pci_remove_legacy_files(struct pci_bus *bus);
123#else 122#else
124static inline void pci_create_legacy_files(struct pci_bus *bus) { return; } 123static inline void pci_create_legacy_files(struct pci_bus *bus) { return; }
125static inline void pci_remove_legacy_files(struct pci_bus *bus) { return; } 124static inline void pci_remove_legacy_files(struct pci_bus *bus) { return; }
@@ -134,7 +133,7 @@ extern unsigned int pci_pm_d3_delay;
134 133
135#ifdef CONFIG_PCI_MSI 134#ifdef CONFIG_PCI_MSI
136void pci_no_msi(void); 135void pci_no_msi(void);
137extern void pci_msi_init_pci_dev(struct pci_dev *dev); 136void pci_msi_init_pci_dev(struct pci_dev *dev);
138#else 137#else
139static inline void pci_no_msi(void) { } 138static inline void pci_no_msi(void) { }
140static inline void pci_msi_init_pci_dev(struct pci_dev *dev) { } 139static inline void pci_msi_init_pci_dev(struct pci_dev *dev) { }
@@ -198,12 +197,11 @@ enum pci_bar_type {
198 197
199bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl, 198bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
200 int crs_timeout); 199 int crs_timeout);
201extern int pci_setup_device(struct pci_dev *dev); 200int pci_setup_device(struct pci_dev *dev);
202extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, 201int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
203 struct resource *res, unsigned int reg); 202 struct resource *res, unsigned int reg);
204extern int pci_resource_bar(struct pci_dev *dev, int resno, 203int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type);
205 enum pci_bar_type *type); 204void pci_configure_ari(struct pci_dev *dev);
206extern void pci_configure_ari(struct pci_dev *dev);
207 205
208/** 206/**
209 * pci_ari_enabled - query ARI forwarding status 207 * pci_ari_enabled - query ARI forwarding status
@@ -217,7 +215,7 @@ static inline int pci_ari_enabled(struct pci_bus *bus)
217} 215}
218 216
219void pci_reassigndev_resource_alignment(struct pci_dev *dev); 217void pci_reassigndev_resource_alignment(struct pci_dev *dev);
220extern void pci_disable_bridge_window(struct pci_dev *dev); 218void pci_disable_bridge_window(struct pci_dev *dev);
221 219
222/* Single Root I/O Virtualization */ 220/* Single Root I/O Virtualization */
223struct pci_sriov { 221struct pci_sriov {
@@ -241,7 +239,7 @@ struct pci_sriov {
241}; 239};
242 240
243#ifdef CONFIG_PCI_ATS 241#ifdef CONFIG_PCI_ATS
244extern void pci_restore_ats_state(struct pci_dev *dev); 242void pci_restore_ats_state(struct pci_dev *dev);
245#else 243#else
246static inline void pci_restore_ats_state(struct pci_dev *dev) 244static inline void pci_restore_ats_state(struct pci_dev *dev)
247{ 245{
@@ -249,14 +247,13 @@ static inline void pci_restore_ats_state(struct pci_dev *dev)
249#endif /* CONFIG_PCI_ATS */ 247#endif /* CONFIG_PCI_ATS */
250 248
251#ifdef CONFIG_PCI_IOV 249#ifdef CONFIG_PCI_IOV
252extern int pci_iov_init(struct pci_dev *dev); 250int pci_iov_init(struct pci_dev *dev);
253extern void pci_iov_release(struct pci_dev *dev); 251void pci_iov_release(struct pci_dev *dev);
254extern int pci_iov_resource_bar(struct pci_dev *dev, int resno, 252int pci_iov_resource_bar(struct pci_dev *dev, int resno,
255 enum pci_bar_type *type); 253 enum pci_bar_type *type);
256extern resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, 254resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
257 int resno); 255void pci_restore_iov_state(struct pci_dev *dev);
258extern void pci_restore_iov_state(struct pci_dev *dev); 256int pci_iov_bus_range(struct pci_bus *bus);
259extern int pci_iov_bus_range(struct pci_bus *bus);
260 257
261#else 258#else
262static inline int pci_iov_init(struct pci_dev *dev) 259static inline int pci_iov_init(struct pci_dev *dev)
@@ -282,10 +279,10 @@ static inline int pci_iov_bus_range(struct pci_bus *bus)
282 279
283#endif /* CONFIG_PCI_IOV */ 280#endif /* CONFIG_PCI_IOV */
284 281
285extern unsigned long pci_cardbus_resource_alignment(struct resource *); 282unsigned long pci_cardbus_resource_alignment(struct resource *);
286 283
287static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, 284static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
288 struct resource *res) 285 struct resource *res)
289{ 286{
290#ifdef CONFIG_PCI_IOV 287#ifdef CONFIG_PCI_IOV
291 int resno = res - dev->resource; 288 int resno = res - dev->resource;
@@ -298,7 +295,7 @@ static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
298 return resource_alignment(res); 295 return resource_alignment(res);
299} 296}
300 297
301extern void pci_enable_acs(struct pci_dev *dev); 298void pci_enable_acs(struct pci_dev *dev);
302 299
303struct pci_dev_reset_methods { 300struct pci_dev_reset_methods {
304 u16 vendor; 301 u16 vendor;
@@ -307,7 +304,7 @@ struct pci_dev_reset_methods {
307}; 304};
308 305
309#ifdef CONFIG_PCI_QUIRKS 306#ifdef CONFIG_PCI_QUIRKS
310extern int pci_dev_specific_reset(struct pci_dev *dev, int probe); 307int pci_dev_specific_reset(struct pci_dev *dev, int probe);
311#else 308#else
312static inline int pci_dev_specific_reset(struct pci_dev *dev, int probe) 309static inline int pci_dev_specific_reset(struct pci_dev *dev, int probe)
313{ 310{
diff --git a/drivers/pci/pcie/Kconfig b/drivers/pci/pcie/Kconfig
index fde4a32a0295..569f82fc9e22 100644
--- a/drivers/pci/pcie/Kconfig
+++ b/drivers/pci/pcie/Kconfig
@@ -82,4 +82,4 @@ endchoice
82 82
83config PCIE_PME 83config PCIE_PME
84 def_bool y 84 def_bool y
85 depends on PCIEPORTBUS && PM_RUNTIME && ACPI 85 depends on PCIEPORTBUS && PM_RUNTIME
diff --git a/drivers/pci/pcie/aer/aer_inject.c b/drivers/pci/pcie/aer/aer_inject.c
index 4e24cb8a94ae..587e7e853107 100644
--- a/drivers/pci/pcie/aer/aer_inject.c
+++ b/drivers/pci/pcie/aer/aer_inject.c
@@ -212,8 +212,8 @@ out:
212 return ops->read(bus, devfn, where, size, val); 212 return ops->read(bus, devfn, where, size, val);
213} 213}
214 214
215int pci_write_aer(struct pci_bus *bus, unsigned int devfn, int where, int size, 215static int pci_write_aer(struct pci_bus *bus, unsigned int devfn, int where,
216 u32 val) 216 int size, u32 val)
217{ 217{
218 u32 *sim; 218 u32 *sim;
219 struct aer_error *err; 219 struct aer_error *err;
@@ -334,13 +334,13 @@ static int aer_inject(struct aer_error_inj *einj)
334 return -ENODEV; 334 return -ENODEV;
335 rpdev = pcie_find_root_port(dev); 335 rpdev = pcie_find_root_port(dev);
336 if (!rpdev) { 336 if (!rpdev) {
337 ret = -ENOTTY; 337 ret = -ENODEV;
338 goto out_put; 338 goto out_put;
339 } 339 }
340 340
341 pos_cap_err = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); 341 pos_cap_err = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
342 if (!pos_cap_err) { 342 if (!pos_cap_err) {
343 ret = -ENOTTY; 343 ret = -EPERM;
344 goto out_put; 344 goto out_put;
345 } 345 }
346 pci_read_config_dword(dev, pos_cap_err + PCI_ERR_UNCOR_SEVER, &sever); 346 pci_read_config_dword(dev, pos_cap_err + PCI_ERR_UNCOR_SEVER, &sever);
@@ -350,7 +350,7 @@ static int aer_inject(struct aer_error_inj *einj)
350 350
351 rp_pos_cap_err = pci_find_ext_capability(rpdev, PCI_EXT_CAP_ID_ERR); 351 rp_pos_cap_err = pci_find_ext_capability(rpdev, PCI_EXT_CAP_ID_ERR);
352 if (!rp_pos_cap_err) { 352 if (!rp_pos_cap_err) {
353 ret = -ENOTTY; 353 ret = -EPERM;
354 goto out_put; 354 goto out_put;
355 } 355 }
356 356
diff --git a/drivers/pci/pcie/aer/aerdrv.h b/drivers/pci/pcie/aer/aerdrv.h
index 22f840f4dda1..d12c77cd6991 100644
--- a/drivers/pci/pcie/aer/aerdrv.h
+++ b/drivers/pci/pcie/aer/aerdrv.h
@@ -110,15 +110,15 @@ static inline pci_ers_result_t merge_result(enum pci_ers_result orig,
110} 110}
111 111
112extern struct bus_type pcie_port_bus_type; 112extern struct bus_type pcie_port_bus_type;
113extern void aer_do_secondary_bus_reset(struct pci_dev *dev); 113void aer_do_secondary_bus_reset(struct pci_dev *dev);
114extern int aer_init(struct pcie_device *dev); 114int aer_init(struct pcie_device *dev);
115extern void aer_isr(struct work_struct *work); 115void aer_isr(struct work_struct *work);
116extern void aer_print_error(struct pci_dev *dev, struct aer_err_info *info); 116void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
117extern void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info); 117void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info);
118extern irqreturn_t aer_irq(int irq, void *context); 118irqreturn_t aer_irq(int irq, void *context);
119 119
120#ifdef CONFIG_ACPI_APEI 120#ifdef CONFIG_ACPI_APEI
121extern int pcie_aer_get_firmware_first(struct pci_dev *pci_dev); 121int pcie_aer_get_firmware_first(struct pci_dev *pci_dev);
122#else 122#else
123static inline int pcie_aer_get_firmware_first(struct pci_dev *pci_dev) 123static inline int pcie_aer_get_firmware_first(struct pci_dev *pci_dev)
124{ 124{
diff --git a/drivers/pci/pcie/aer/aerdrv_core.c b/drivers/pci/pcie/aer/aerdrv_core.c
index 564d97f94b6c..8ec8b4f48560 100644
--- a/drivers/pci/pcie/aer/aerdrv_core.c
+++ b/drivers/pci/pcie/aer/aerdrv_core.c
@@ -89,8 +89,6 @@ static int add_error_device(struct aer_err_info *e_info, struct pci_dev *dev)
89 return -ENOSPC; 89 return -ENOSPC;
90} 90}
91 91
92#define PCI_BUS(x) (((x) >> 8) & 0xff)
93
94/** 92/**
95 * is_error_source - check whether the device is source of reported error 93 * is_error_source - check whether the device is source of reported error
96 * @dev: pointer to pci_dev to be checked 94 * @dev: pointer to pci_dev to be checked
@@ -106,7 +104,7 @@ static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info)
106 * When bus id is equal to 0, it might be a bad id 104 * When bus id is equal to 0, it might be a bad id
107 * reported by root port. 105 * reported by root port.
108 */ 106 */
109 if (!nosourceid && (PCI_BUS(e_info->id) != 0)) { 107 if (!nosourceid && (PCI_BUS_NUM(e_info->id) != 0)) {
110 /* Device ID match? */ 108 /* Device ID match? */
111 if (e_info->id == ((dev->bus->number << 8) | dev->devfn)) 109 if (e_info->id == ((dev->bus->number << 8) | dev->devfn))
112 return true; 110 return true;
diff --git a/drivers/pci/pcie/pme.c b/drivers/pci/pcie/pme.c
index 9ca0dc9ffd84..795db1f9d50c 100644
--- a/drivers/pci/pcie/pme.c
+++ b/drivers/pci/pcie/pme.c
@@ -19,8 +19,6 @@
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/pcieport_if.h> 21#include <linux/pcieport_if.h>
22#include <linux/acpi.h>
23#include <linux/pci-acpi.h>
24#include <linux/pm_runtime.h> 22#include <linux/pm_runtime.h>
25 23
26#include "../pci.h" 24#include "../pci.h"
diff --git a/drivers/pci/pcie/portdrv.h b/drivers/pci/pcie/portdrv.h
index eea2ca2375e6..d2eb80aab569 100644
--- a/drivers/pci/pcie/portdrv.h
+++ b/drivers/pci/pcie/portdrv.h
@@ -21,18 +21,18 @@
21#define get_descriptor_id(type, service) (((type - 4) << 4) | service) 21#define get_descriptor_id(type, service) (((type - 4) << 4) | service)
22 22
23extern struct bus_type pcie_port_bus_type; 23extern struct bus_type pcie_port_bus_type;
24extern int pcie_port_device_register(struct pci_dev *dev); 24int pcie_port_device_register(struct pci_dev *dev);
25#ifdef CONFIG_PM 25#ifdef CONFIG_PM
26extern int pcie_port_device_suspend(struct device *dev); 26int pcie_port_device_suspend(struct device *dev);
27extern int pcie_port_device_resume(struct device *dev); 27int pcie_port_device_resume(struct device *dev);
28#endif 28#endif
29extern void pcie_port_device_remove(struct pci_dev *dev); 29void pcie_port_device_remove(struct pci_dev *dev);
30extern int __must_check pcie_port_bus_register(void); 30int __must_check pcie_port_bus_register(void);
31extern void pcie_port_bus_unregister(void); 31void pcie_port_bus_unregister(void);
32 32
33struct pci_dev; 33struct pci_dev;
34 34
35extern void pcie_clear_root_pme_status(struct pci_dev *dev); 35void pcie_clear_root_pme_status(struct pci_dev *dev);
36 36
37#ifdef CONFIG_HOTPLUG_PCI_PCIE 37#ifdef CONFIG_HOTPLUG_PCI_PCIE
38extern bool pciehp_msi_disabled; 38extern bool pciehp_msi_disabled;
@@ -59,7 +59,7 @@ static inline bool pcie_pme_no_msi(void)
59 return pcie_pme_msi_disabled; 59 return pcie_pme_msi_disabled;
60} 60}
61 61
62extern void pcie_pme_interrupt_enable(struct pci_dev *dev, bool enable); 62void pcie_pme_interrupt_enable(struct pci_dev *dev, bool enable);
63#else /* !CONFIG_PCIE_PME */ 63#else /* !CONFIG_PCIE_PME */
64static inline void pcie_pme_disable_msi(void) {} 64static inline void pcie_pme_disable_msi(void) {}
65static inline bool pcie_pme_no_msi(void) { return false; } 65static inline bool pcie_pme_no_msi(void) { return false; }
@@ -67,7 +67,7 @@ static inline void pcie_pme_interrupt_enable(struct pci_dev *dev, bool en) {}
67#endif /* !CONFIG_PCIE_PME */ 67#endif /* !CONFIG_PCIE_PME */
68 68
69#ifdef CONFIG_ACPI 69#ifdef CONFIG_ACPI
70extern int pcie_port_acpi_setup(struct pci_dev *port, int *mask); 70int pcie_port_acpi_setup(struct pci_dev *port, int *mask);
71 71
72static inline int pcie_port_platform_notify(struct pci_dev *port, int *mask) 72static inline int pcie_port_platform_notify(struct pci_dev *port, int *mask)
73{ 73{
diff --git a/drivers/pci/pcie/portdrv_acpi.c b/drivers/pci/pcie/portdrv_acpi.c
index a86b56e5f2f2..b4d2894ee3fc 100644
--- a/drivers/pci/pcie/portdrv_acpi.c
+++ b/drivers/pci/pcie/portdrv_acpi.c
@@ -17,6 +17,7 @@
17 17
18#include "aer/aerdrv.h" 18#include "aer/aerdrv.h"
19#include "../pci.h" 19#include "../pci.h"
20#include "portdrv.h"
20 21
21/** 22/**
22 * pcie_port_acpi_setup - Request the BIOS to release control of PCIe services. 23 * pcie_port_acpi_setup - Request the BIOS to release control of PCIe services.
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index ed4d09498337..696caed5fdf5 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -259,11 +259,9 @@ static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev,
259 enum pci_channel_state error) 259 enum pci_channel_state error)
260{ 260{
261 struct aer_broadcast_data data = {error, PCI_ERS_RESULT_CAN_RECOVER}; 261 struct aer_broadcast_data data = {error, PCI_ERS_RESULT_CAN_RECOVER};
262 int ret;
263
264 /* can not fail */
265 ret = device_for_each_child(&dev->dev, &data, error_detected_iter);
266 262
263 /* get true return value from &data */
264 device_for_each_child(&dev->dev, &data, error_detected_iter);
267 return data.result; 265 return data.result;
268} 266}
269 267
@@ -295,10 +293,9 @@ static int mmio_enabled_iter(struct device *device, void *data)
295static pci_ers_result_t pcie_portdrv_mmio_enabled(struct pci_dev *dev) 293static pci_ers_result_t pcie_portdrv_mmio_enabled(struct pci_dev *dev)
296{ 294{
297 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED; 295 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
298 int retval;
299 296
300 /* get true return value from &status */ 297 /* get true return value from &status */
301 retval = device_for_each_child(&dev->dev, &status, mmio_enabled_iter); 298 device_for_each_child(&dev->dev, &status, mmio_enabled_iter);
302 return status; 299 return status;
303} 300}
304 301
@@ -330,7 +327,6 @@ static int slot_reset_iter(struct device *device, void *data)
330static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev) 327static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
331{ 328{
332 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED; 329 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
333 int retval;
334 330
335 /* If fatal, restore cfg space for possible link reset at upstream */ 331 /* If fatal, restore cfg space for possible link reset at upstream */
336 if (dev->error_state == pci_channel_io_frozen) { 332 if (dev->error_state == pci_channel_io_frozen) {
@@ -341,8 +337,7 @@ static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
341 } 337 }
342 338
343 /* get true return value from &status */ 339 /* get true return value from &status */
344 retval = device_for_each_child(&dev->dev, &status, slot_reset_iter); 340 device_for_each_child(&dev->dev, &status, slot_reset_iter);
345
346 return status; 341 return status;
347} 342}
348 343
@@ -368,9 +363,7 @@ static int resume_iter(struct device *device, void *data)
368 363
369static void pcie_portdrv_err_resume(struct pci_dev *dev) 364static void pcie_portdrv_err_resume(struct pci_dev *dev)
370{ 365{
371 int retval; 366 device_for_each_child(&dev->dev, NULL, resume_iter);
372 /* nothing to do with error value, if it ever happens */
373 retval = device_for_each_child(&dev->dev, NULL, resume_iter);
374} 367}
375 368
376/* 369/*
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index b494066ef32f..43ece5d41d36 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -673,6 +673,8 @@ add_dev:
673 ret = device_register(&child->dev); 673 ret = device_register(&child->dev);
674 WARN_ON(ret < 0); 674 WARN_ON(ret < 0);
675 675
676 pcibios_add_bus(child);
677
676 /* Create legacy_io and legacy_mem files for this bus */ 678 /* Create legacy_io and legacy_mem files for this bus */
677 pci_create_legacy_files(child); 679 pci_create_legacy_files(child);
678 680
@@ -1627,8 +1629,7 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus)
1627 if (!bus->is_added) { 1629 if (!bus->is_added) {
1628 dev_dbg(&bus->dev, "fixups for bus\n"); 1630 dev_dbg(&bus->dev, "fixups for bus\n");
1629 pcibios_fixup_bus(bus); 1631 pcibios_fixup_bus(bus);
1630 if (pci_is_root_bus(bus)) 1632 bus->is_added = 1;
1631 bus->is_added = 1;
1632 } 1633 }
1633 1634
1634 for (pass=0; pass < 2; pass++) 1635 for (pass=0; pass < 2; pass++)
@@ -1661,6 +1662,14 @@ int __weak pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
1661 return 0; 1662 return 0;
1662} 1663}
1663 1664
1665void __weak pcibios_add_bus(struct pci_bus *bus)
1666{
1667}
1668
1669void __weak pcibios_remove_bus(struct pci_bus *bus)
1670{
1671}
1672
1664struct pci_bus *pci_create_root_bus(struct device *parent, int bus, 1673struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
1665 struct pci_ops *ops, void *sysdata, struct list_head *resources) 1674 struct pci_ops *ops, void *sysdata, struct list_head *resources)
1666{ 1675{
@@ -1715,6 +1724,8 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
1715 if (error) 1724 if (error)
1716 goto class_dev_reg_err; 1725 goto class_dev_reg_err;
1717 1726
1727 pcibios_add_bus(b);
1728
1718 /* Create legacy_io and legacy_mem files for this bus */ 1729 /* Create legacy_io and legacy_mem files for this bus */
1719 pci_create_legacy_files(b); 1730 pci_create_legacy_files(b);
1720 1731
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 0369fb6fc1da..7d68aeebf56b 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -324,29 +324,30 @@ static void quirk_cs5536_vsa(struct pci_dev *dev)
324} 324}
325DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA, quirk_cs5536_vsa); 325DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA, quirk_cs5536_vsa);
326 326
327static void quirk_io_region(struct pci_dev *dev, unsigned region, 327static void quirk_io_region(struct pci_dev *dev, int port,
328 unsigned size, int nr, const char *name) 328 unsigned size, int nr, const char *name)
329{ 329{
330 region &= ~(size-1); 330 u16 region;
331 if (region) { 331 struct pci_bus_region bus_region;
332 struct pci_bus_region bus_region; 332 struct resource *res = dev->resource + nr;
333 struct resource *res = dev->resource + nr;
334 333
335 res->name = pci_name(dev); 334 pci_read_config_word(dev, port, &region);
336 res->start = region; 335 region &= ~(size - 1);
337 res->end = region + size - 1;
338 res->flags = IORESOURCE_IO;
339 336
340 /* Convert from PCI bus to resource space. */ 337 if (!region)
341 bus_region.start = res->start; 338 return;
342 bus_region.end = res->end;
343 pcibios_bus_to_resource(dev, res, &bus_region);
344 339
345 if (pci_claim_resource(dev, nr) == 0) 340 res->name = pci_name(dev);
346 dev_info(&dev->dev, "quirk: %pR claimed by %s\n", 341 res->flags = IORESOURCE_IO;
347 res, name); 342
348 } 343 /* Convert from PCI bus to resource space */
349} 344 bus_region.start = region;
345 bus_region.end = region + size - 1;
346 pcibios_bus_to_resource(dev, res, &bus_region);
347
348 if (!pci_claim_resource(dev, nr))
349 dev_info(&dev->dev, "quirk: %pR claimed by %s\n", res, name);
350}
350 351
351/* 352/*
352 * ATI Northbridge setups MCE the processor if you even 353 * ATI Northbridge setups MCE the processor if you even
@@ -374,12 +375,8 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS100, quirk_ati_
374 */ 375 */
375static void quirk_ali7101_acpi(struct pci_dev *dev) 376static void quirk_ali7101_acpi(struct pci_dev *dev)
376{ 377{
377 u16 region; 378 quirk_io_region(dev, 0xE0, 64, PCI_BRIDGE_RESOURCES, "ali7101 ACPI");
378 379 quirk_io_region(dev, 0xE2, 32, PCI_BRIDGE_RESOURCES+1, "ali7101 SMB");
379 pci_read_config_word(dev, 0xE0, &region);
380 quirk_io_region(dev, region, 64, PCI_BRIDGE_RESOURCES, "ali7101 ACPI");
381 pci_read_config_word(dev, 0xE2, &region);
382 quirk_io_region(dev, region, 32, PCI_BRIDGE_RESOURCES+1, "ali7101 SMB");
383} 380}
384DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, quirk_ali7101_acpi); 381DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, quirk_ali7101_acpi);
385 382
@@ -442,12 +439,10 @@ static void piix4_mem_quirk(struct pci_dev *dev, const char *name, unsigned int
442 */ 439 */
443static void quirk_piix4_acpi(struct pci_dev *dev) 440static void quirk_piix4_acpi(struct pci_dev *dev)
444{ 441{
445 u32 region, res_a; 442 u32 res_a;
446 443
447 pci_read_config_dword(dev, 0x40, &region); 444 quirk_io_region(dev, 0x40, 64, PCI_BRIDGE_RESOURCES, "PIIX4 ACPI");
448 quirk_io_region(dev, region, 64, PCI_BRIDGE_RESOURCES, "PIIX4 ACPI"); 445 quirk_io_region(dev, 0x90, 16, PCI_BRIDGE_RESOURCES+1, "PIIX4 SMB");
449 pci_read_config_dword(dev, 0x90, &region);
450 quirk_io_region(dev, region, 16, PCI_BRIDGE_RESOURCES+1, "PIIX4 SMB");
451 446
452 /* Device resource A has enables for some of the other ones */ 447 /* Device resource A has enables for some of the other ones */
453 pci_read_config_dword(dev, 0x5c, &res_a); 448 pci_read_config_dword(dev, 0x5c, &res_a);
@@ -491,7 +486,6 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3, qui
491 */ 486 */
492static void quirk_ich4_lpc_acpi(struct pci_dev *dev) 487static void quirk_ich4_lpc_acpi(struct pci_dev *dev)
493{ 488{
494 u32 region;
495 u8 enable; 489 u8 enable;
496 490
497 /* 491 /*
@@ -503,22 +497,14 @@ static void quirk_ich4_lpc_acpi(struct pci_dev *dev)
503 */ 497 */
504 498
505 pci_read_config_byte(dev, ICH_ACPI_CNTL, &enable); 499 pci_read_config_byte(dev, ICH_ACPI_CNTL, &enable);
506 if (enable & ICH4_ACPI_EN) { 500 if (enable & ICH4_ACPI_EN)
507 pci_read_config_dword(dev, ICH_PMBASE, &region); 501 quirk_io_region(dev, ICH_PMBASE, 128, PCI_BRIDGE_RESOURCES,
508 region &= PCI_BASE_ADDRESS_IO_MASK; 502 "ICH4 ACPI/GPIO/TCO");
509 if (region >= PCIBIOS_MIN_IO)
510 quirk_io_region(dev, region, 128, PCI_BRIDGE_RESOURCES,
511 "ICH4 ACPI/GPIO/TCO");
512 }
513 503
514 pci_read_config_byte(dev, ICH4_GPIO_CNTL, &enable); 504 pci_read_config_byte(dev, ICH4_GPIO_CNTL, &enable);
515 if (enable & ICH4_GPIO_EN) { 505 if (enable & ICH4_GPIO_EN)
516 pci_read_config_dword(dev, ICH4_GPIOBASE, &region); 506 quirk_io_region(dev, ICH4_GPIOBASE, 64, PCI_BRIDGE_RESOURCES+1,
517 region &= PCI_BASE_ADDRESS_IO_MASK; 507 "ICH4 GPIO");
518 if (region >= PCIBIOS_MIN_IO)
519 quirk_io_region(dev, region, 64,
520 PCI_BRIDGE_RESOURCES + 1, "ICH4 GPIO");
521 }
522} 508}
523DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, quirk_ich4_lpc_acpi); 509DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, quirk_ich4_lpc_acpi);
524DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0, quirk_ich4_lpc_acpi); 510DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0, quirk_ich4_lpc_acpi);
@@ -533,26 +519,17 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1, qui
533 519
534static void ich6_lpc_acpi_gpio(struct pci_dev *dev) 520static void ich6_lpc_acpi_gpio(struct pci_dev *dev)
535{ 521{
536 u32 region;
537 u8 enable; 522 u8 enable;
538 523
539 pci_read_config_byte(dev, ICH_ACPI_CNTL, &enable); 524 pci_read_config_byte(dev, ICH_ACPI_CNTL, &enable);
540 if (enable & ICH6_ACPI_EN) { 525 if (enable & ICH6_ACPI_EN)
541 pci_read_config_dword(dev, ICH_PMBASE, &region); 526 quirk_io_region(dev, ICH_PMBASE, 128, PCI_BRIDGE_RESOURCES,
542 region &= PCI_BASE_ADDRESS_IO_MASK; 527 "ICH6 ACPI/GPIO/TCO");
543 if (region >= PCIBIOS_MIN_IO)
544 quirk_io_region(dev, region, 128, PCI_BRIDGE_RESOURCES,
545 "ICH6 ACPI/GPIO/TCO");
546 }
547 528
548 pci_read_config_byte(dev, ICH6_GPIO_CNTL, &enable); 529 pci_read_config_byte(dev, ICH6_GPIO_CNTL, &enable);
549 if (enable & ICH6_GPIO_EN) { 530 if (enable & ICH6_GPIO_EN)
550 pci_read_config_dword(dev, ICH6_GPIOBASE, &region); 531 quirk_io_region(dev, ICH6_GPIOBASE, 64, PCI_BRIDGE_RESOURCES+1,
551 region &= PCI_BASE_ADDRESS_IO_MASK; 532 "ICH6 GPIO");
552 if (region >= PCIBIOS_MIN_IO)
553 quirk_io_region(dev, region, 64,
554 PCI_BRIDGE_RESOURCES + 1, "ICH6 GPIO");
555 }
556} 533}
557 534
558static void ich6_lpc_generic_decode(struct pci_dev *dev, unsigned reg, const char *name, int dynsize) 535static void ich6_lpc_generic_decode(struct pci_dev *dev, unsigned reg, const char *name, int dynsize)
@@ -650,13 +627,9 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_1, qui
650 */ 627 */
651static void quirk_vt82c586_acpi(struct pci_dev *dev) 628static void quirk_vt82c586_acpi(struct pci_dev *dev)
652{ 629{
653 u32 region; 630 if (dev->revision & 0x10)
654 631 quirk_io_region(dev, 0x48, 256, PCI_BRIDGE_RESOURCES,
655 if (dev->revision & 0x10) { 632 "vt82c586 ACPI");
656 pci_read_config_dword(dev, 0x48, &region);
657 region &= PCI_BASE_ADDRESS_IO_MASK;
658 quirk_io_region(dev, region, 256, PCI_BRIDGE_RESOURCES, "vt82c586 ACPI");
659 }
660} 633}
661DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_vt82c586_acpi); 634DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_vt82c586_acpi);
662 635
@@ -668,18 +641,12 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_vt
668 */ 641 */
669static void quirk_vt82c686_acpi(struct pci_dev *dev) 642static void quirk_vt82c686_acpi(struct pci_dev *dev)
670{ 643{
671 u16 hm;
672 u32 smb;
673
674 quirk_vt82c586_acpi(dev); 644 quirk_vt82c586_acpi(dev);
675 645
676 pci_read_config_word(dev, 0x70, &hm); 646 quirk_io_region(dev, 0x70, 128, PCI_BRIDGE_RESOURCES+1,
677 hm &= PCI_BASE_ADDRESS_IO_MASK; 647 "vt82c686 HW-mon");
678 quirk_io_region(dev, hm, 128, PCI_BRIDGE_RESOURCES + 1, "vt82c686 HW-mon");
679 648
680 pci_read_config_dword(dev, 0x90, &smb); 649 quirk_io_region(dev, 0x90, 16, PCI_BRIDGE_RESOURCES+2, "vt82c686 SMB");
681 smb &= PCI_BASE_ADDRESS_IO_MASK;
682 quirk_io_region(dev, smb, 16, PCI_BRIDGE_RESOURCES + 2, "vt82c686 SMB");
683} 650}
684DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_vt82c686_acpi); 651DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_vt82c686_acpi);
685 652
@@ -690,15 +657,8 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_vt
690 */ 657 */
691static void quirk_vt8235_acpi(struct pci_dev *dev) 658static void quirk_vt8235_acpi(struct pci_dev *dev)
692{ 659{
693 u16 pm, smb; 660 quirk_io_region(dev, 0x88, 128, PCI_BRIDGE_RESOURCES, "vt8235 PM");
694 661 quirk_io_region(dev, 0xd0, 16, PCI_BRIDGE_RESOURCES+1, "vt8235 SMB");
695 pci_read_config_word(dev, 0x88, &pm);
696 pm &= PCI_BASE_ADDRESS_IO_MASK;
697 quirk_io_region(dev, pm, 128, PCI_BRIDGE_RESOURCES, "vt8235 PM");
698
699 pci_read_config_word(dev, 0xd0, &smb);
700 smb &= PCI_BASE_ADDRESS_IO_MASK;
701 quirk_io_region(dev, smb, 16, PCI_BRIDGE_RESOURCES + 1, "vt8235 SMB");
702} 662}
703DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_vt8235_acpi); 663DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_vt8235_acpi);
704 664
@@ -2594,6 +2554,14 @@ static void quirk_msi_intx_disable_ati_bug(struct pci_dev *dev)
2594 dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG; 2554 dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
2595 pci_dev_put(p); 2555 pci_dev_put(p);
2596} 2556}
2557static void quirk_msi_intx_disable_qca_bug(struct pci_dev *dev)
2558{
2559 /* AR816X/AR817X/E210X MSI is fixed at HW level from revision 0x18 */
2560 if (dev->revision < 0x18) {
2561 dev_info(&dev->dev, "set MSI_INTX_DISABLE_BUG flag\n");
2562 dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
2563 }
2564}
2597DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM, 2565DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2598 PCI_DEVICE_ID_TIGON3_5780, 2566 PCI_DEVICE_ID_TIGON3_5780,
2599 quirk_msi_intx_disable_bug); 2567 quirk_msi_intx_disable_bug);
@@ -2643,6 +2611,16 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1073,
2643 quirk_msi_intx_disable_bug); 2611 quirk_msi_intx_disable_bug);
2644DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1083, 2612DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1083,
2645 quirk_msi_intx_disable_bug); 2613 quirk_msi_intx_disable_bug);
2614DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1090,
2615 quirk_msi_intx_disable_qca_bug);
2616DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1091,
2617 quirk_msi_intx_disable_qca_bug);
2618DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x10a0,
2619 quirk_msi_intx_disable_qca_bug);
2620DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x10a1,
2621 quirk_msi_intx_disable_qca_bug);
2622DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0xe091,
2623 quirk_msi_intx_disable_qca_bug);
2646#endif /* CONFIG_PCI_MSI */ 2624#endif /* CONFIG_PCI_MSI */
2647 2625
2648/* Allow manual resource allocation for PCI hotplug bridges 2626/* Allow manual resource allocation for PCI hotplug bridges
diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index cc875e6ed159..8fc54b7327bc 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -50,10 +50,8 @@ void pci_remove_bus(struct pci_bus *bus)
50 list_del(&bus->node); 50 list_del(&bus->node);
51 pci_bus_release_busn_res(bus); 51 pci_bus_release_busn_res(bus);
52 up_write(&pci_bus_sem); 52 up_write(&pci_bus_sem);
53 if (!bus->is_added)
54 return;
55
56 pci_remove_legacy_files(bus); 53 pci_remove_legacy_files(bus);
54 pcibios_remove_bus(bus);
57 device_unregister(&bus->dev); 55 device_unregister(&bus->dev);
58} 56}
59EXPORT_SYMBOL(pci_remove_bus); 57EXPORT_SYMBOL(pci_remove_bus);
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 7e8739e25b9e..16abaaa1f83c 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1044,7 +1044,7 @@ handle_done:
1044 ; 1044 ;
1045} 1045}
1046 1046
1047void __ref __pci_bus_size_bridges(struct pci_bus *bus, 1047static void __ref __pci_bus_size_bridges(struct pci_bus *bus,
1048 struct list_head *realloc_head) 1048 struct list_head *realloc_head)
1049{ 1049{
1050 struct pci_dev *dev; 1050 struct pci_dev *dev;
@@ -1545,6 +1545,8 @@ again:
1545 1545
1546enable_all: 1546enable_all:
1547 retval = pci_reenable_device(bridge); 1547 retval = pci_reenable_device(bridge);
1548 if (retval)
1549 dev_err(&bridge->dev, "Error reenabling bridge (%d)\n", retval);
1548 pci_set_master(bridge); 1550 pci_set_master(bridge);
1549 pci_enable_bridges(parent); 1551 pci_enable_bridges(parent);
1550} 1552}
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 81b88bda7930..07f2eddc09ce 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -261,7 +261,6 @@ int pci_assign_resource(struct pci_dev *dev, int resno)
261{ 261{
262 struct resource *res = dev->resource + resno; 262 struct resource *res = dev->resource + resno;
263 resource_size_t align, size; 263 resource_size_t align, size;
264 struct pci_bus *bus;
265 int ret; 264 int ret;
266 265
267 align = pci_resource_alignment(dev, res); 266 align = pci_resource_alignment(dev, res);
@@ -271,7 +270,6 @@ int pci_assign_resource(struct pci_dev *dev, int resno)
271 return -EINVAL; 270 return -EINVAL;
272 } 271 }
273 272
274 bus = dev->bus;
275 size = resource_size(res); 273 size = resource_size(res);
276 ret = _pci_assign_resource(dev, resno, size, align); 274 ret = _pci_assign_resource(dev, resno, size, align);
277 275
diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
index ac6412fb8d6f..c1e9284a677b 100644
--- a/drivers/pci/slot.c
+++ b/drivers/pci/slot.c
@@ -377,14 +377,17 @@ void pci_hp_create_module_link(struct pci_slot *pci_slot)
377{ 377{
378 struct hotplug_slot *slot = pci_slot->hotplug; 378 struct hotplug_slot *slot = pci_slot->hotplug;
379 struct kobject *kobj = NULL; 379 struct kobject *kobj = NULL;
380 int no_warn; 380 int ret;
381 381
382 if (!slot || !slot->ops) 382 if (!slot || !slot->ops)
383 return; 383 return;
384 kobj = kset_find_obj(module_kset, slot->ops->mod_name); 384 kobj = kset_find_obj(module_kset, slot->ops->mod_name);
385 if (!kobj) 385 if (!kobj)
386 return; 386 return;
387 no_warn = sysfs_create_link(&pci_slot->kobj, kobj, "module"); 387 ret = sysfs_create_link(&pci_slot->kobj, kobj, "module");
388 if (ret)
389 dev_err(&pci_slot->bus->dev, "Error creating sysfs link (%d)\n",
390 ret);
388 kobject_put(kobj); 391 kobject_put(kobj);
389} 392}
390EXPORT_SYMBOL_GPL(pci_hp_create_module_link); 393EXPORT_SYMBOL_GPL(pci_hp_create_module_link);
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 408d2548a748..684cc343cf09 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -1488,7 +1488,4 @@ struct megasas_mgmt_info {
1488 int max_index; 1488 int max_index;
1489}; 1489};
1490 1490
1491#define msi_control_reg(base) (base + PCI_MSI_FLAGS)
1492#define PCI_MSIX_FLAGS_ENABLE (1 << 15)
1493
1494#endif /*LSI_MEGARAID_SAS_H */ 1491#endif /*LSI_MEGARAID_SAS_H */
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 9d53540207ec..7c90d57b867e 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -3984,12 +3984,12 @@ static int megasas_probe_one(struct pci_dev *pdev,
3984 if (reset_devices) { 3984 if (reset_devices) {
3985 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); 3985 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
3986 if (pos) { 3986 if (pos) {
3987 pci_read_config_word(pdev, msi_control_reg(pos), 3987 pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS,
3988 &control); 3988 &control);
3989 if (control & PCI_MSIX_FLAGS_ENABLE) { 3989 if (control & PCI_MSIX_FLAGS_ENABLE) {
3990 dev_info(&pdev->dev, "resetting MSI-X\n"); 3990 dev_info(&pdev->dev, "resetting MSI-X\n");
3991 pci_write_config_word(pdev, 3991 pci_write_config_word(pdev,
3992 msi_control_reg(pos), 3992 pos + PCI_MSIX_FLAGS,
3993 control & 3993 control &
3994 ~PCI_MSIX_FLAGS_ENABLE); 3994 ~PCI_MSIX_FLAGS_ENABLE);
3995 } 3995 }
diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
index ce90d0546cdd..74550922ad55 100644
--- a/drivers/scsi/mvsas/mv_init.c
+++ b/drivers/scsi/mvsas/mv_init.c
@@ -703,7 +703,7 @@ static struct pci_device_id mvs_pci_table[] = {
703 { PCI_VDEVICE(TTI, 0x2744), chip_9480 }, 703 { PCI_VDEVICE(TTI, 0x2744), chip_9480 },
704 { PCI_VDEVICE(TTI, 0x2760), chip_9480 }, 704 { PCI_VDEVICE(TTI, 0x2760), chip_9480 },
705 { 705 {
706 .vendor = 0x1b4b, 706 .vendor = PCI_VENDOR_ID_MARVELL_EXT,
707 .device = 0x9480, 707 .device = 0x9480,
708 .subvendor = PCI_ANY_ID, 708 .subvendor = PCI_ANY_ID,
709 .subdevice = 0x9480, 709 .subdevice = 0x9480,
@@ -712,7 +712,7 @@ static struct pci_device_id mvs_pci_table[] = {
712 .driver_data = chip_9480, 712 .driver_data = chip_9480,
713 }, 713 },
714 { 714 {
715 .vendor = 0x1b4b, 715 .vendor = PCI_VENDOR_ID_MARVELL_EXT,
716 .device = 0x9445, 716 .device = 0x9445,
717 .subvendor = PCI_ANY_ID, 717 .subvendor = PCI_ANY_ID,
718 .subdevice = 0x9480, 718 .subdevice = 0x9480,
@@ -721,7 +721,7 @@ static struct pci_device_id mvs_pci_table[] = {
721 .driver_data = chip_9445, 721 .driver_data = chip_9445,
722 }, 722 },
723 { 723 {
724 .vendor = 0x1b4b, 724 .vendor = PCI_VENDOR_ID_MARVELL_EXT,
725 .device = 0x9485, 725 .device = 0x9485,
726 .subvendor = PCI_ANY_ID, 726 .subvendor = PCI_ANY_ID,
727 .subdevice = 0x9480, 727 .subdevice = 0x9480,
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 4594ccaaf49b..c3601b57a80c 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -49,8 +49,8 @@ MODULE_AUTHOR("jyli@marvell.com");
49MODULE_DESCRIPTION("Marvell UMI Driver"); 49MODULE_DESCRIPTION("Marvell UMI Driver");
50 50
51static DEFINE_PCI_DEVICE_TABLE(mvumi_pci_table) = { 51static DEFINE_PCI_DEVICE_TABLE(mvumi_pci_table) = {
52 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_2, PCI_DEVICE_ID_MARVELL_MV9143) }, 52 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, PCI_DEVICE_ID_MARVELL_MV9143) },
53 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_2, PCI_DEVICE_ID_MARVELL_MV9580) }, 53 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, PCI_DEVICE_ID_MARVELL_MV9580) },
54 { 0 } 54 { 0 }
55}; 55};
56 56
diff --git a/drivers/scsi/mvumi.h b/drivers/scsi/mvumi.h
index e360135fd1bd..41f168702ac7 100644
--- a/drivers/scsi/mvumi.h
+++ b/drivers/scsi/mvumi.h
@@ -32,7 +32,6 @@
32#define VER_BUILD 1500 32#define VER_BUILD 1500
33 33
34#define MV_DRIVER_NAME "mvumi" 34#define MV_DRIVER_NAME "mvumi"
35#define PCI_VENDOR_ID_MARVELL_2 0x1b4b
36#define PCI_DEVICE_ID_MARVELL_MV9143 0x9143 35#define PCI_DEVICE_ID_MARVELL_MV9143 0x9143
37#define PCI_DEVICE_ID_MARVELL_MV9580 0x9580 36#define PCI_DEVICE_ID_MARVELL_MV9580 0x9580
38 37
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 7abc5c81af2c..09d2e3ffd6fc 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -70,7 +70,7 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev)
70 pci_write_config_word(pdev, PCI_COMMAND, cmd); 70 pci_write_config_word(pdev, PCI_COMMAND, cmd);
71 } 71 }
72 72
73 msix_pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); 73 msix_pos = pdev->msix_cap;
74 if (msix_pos) { 74 if (msix_pos) {
75 u16 flags; 75 u16 flags;
76 u32 table; 76 u32 table;
@@ -78,8 +78,8 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev)
78 pci_read_config_word(pdev, msix_pos + PCI_MSIX_FLAGS, &flags); 78 pci_read_config_word(pdev, msix_pos + PCI_MSIX_FLAGS, &flags);
79 pci_read_config_dword(pdev, msix_pos + PCI_MSIX_TABLE, &table); 79 pci_read_config_dword(pdev, msix_pos + PCI_MSIX_TABLE, &table);
80 80
81 vdev->msix_bar = table & PCI_MSIX_FLAGS_BIRMASK; 81 vdev->msix_bar = table & PCI_MSIX_TABLE_BIR;
82 vdev->msix_offset = table & ~PCI_MSIX_FLAGS_BIRMASK; 82 vdev->msix_offset = table & PCI_MSIX_TABLE_OFFSET;
83 vdev->msix_size = ((flags & PCI_MSIX_FLAGS_QSIZE) + 1) * 16; 83 vdev->msix_size = ((flags & PCI_MSIX_FLAGS_QSIZE) + 1) * 16;
84 } else 84 } else
85 vdev->msix_bar = 0xFF; 85 vdev->msix_bar = 0xFF;
@@ -183,7 +183,7 @@ static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type)
183 u8 pos; 183 u8 pos;
184 u16 flags; 184 u16 flags;
185 185
186 pos = pci_find_capability(vdev->pdev, PCI_CAP_ID_MSI); 186 pos = vdev->pdev->msi_cap;
187 if (pos) { 187 if (pos) {
188 pci_read_config_word(vdev->pdev, 188 pci_read_config_word(vdev->pdev,
189 pos + PCI_MSI_FLAGS, &flags); 189 pos + PCI_MSI_FLAGS, &flags);
@@ -194,7 +194,7 @@ static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type)
194 u8 pos; 194 u8 pos;
195 u16 flags; 195 u16 flags;
196 196
197 pos = pci_find_capability(vdev->pdev, PCI_CAP_ID_MSIX); 197 pos = vdev->pdev->msix_cap;
198 if (pos) { 198 if (pos) {
199 pci_read_config_word(vdev->pdev, 199 pci_read_config_word(vdev->pdev,
200 pos + PCI_MSIX_FLAGS, &flags); 200 pos + PCI_MSIX_FLAGS, &flags);