aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/Makefile2
-rw-r--r--drivers/pci/hotplug/acpi_pcihp.c85
-rw-r--r--drivers/pci/hotplug/acpiphp.h1
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c25
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c23
-rw-r--r--drivers/pci/hotplug/acpiphp_ibm.c6
-rw-r--r--drivers/pci/hotplug/cpci_hotplug_core.c2
-rw-r--r--drivers/pci/hotplug/cpqphp_core.c4
-rw-r--r--drivers/pci/hotplug/fakephp.c86
-rw-r--r--drivers/pci/hotplug/ibmphp_ebda.c3
-rw-r--r--drivers/pci/hotplug/pci_hotplug_core.c284
-rw-r--r--drivers/pci/hotplug/pciehp.h16
-rw-r--r--drivers/pci/hotplug/pciehp_core.c127
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c318
-rw-r--r--drivers/pci/hotplug/rpadlpar_sysfs.c5
-rw-r--r--drivers/pci/hotplug/rpaphp_slot.c44
-rw-r--r--drivers/pci/hotplug/sgi_hotplug.c12
-rw-r--r--drivers/pci/hotplug/shpchp.h14
-rw-r--r--drivers/pci/hotplug/shpchp_core.c37
-rw-r--r--drivers/pci/hotplug/shpchp_hpc.c1
-rw-r--r--drivers/pci/intel-iommu.c3
-rw-r--r--drivers/pci/msi.c22
-rw-r--r--drivers/pci/pci-acpi.c277
-rw-r--r--drivers/pci/pci-driver.c388
-rw-r--r--drivers/pci/pci.c479
-rw-r--r--drivers/pci/pci.h48
-rw-r--r--drivers/pci/pcie/aer/aerdrv.c9
-rw-r--r--drivers/pci/pcie/aer/aerdrv_acpi.c8
-rw-r--r--drivers/pci/pcie/aer/aerdrv_core.c24
-rw-r--r--drivers/pci/pcie/portdrv_bus.c1
-rw-r--r--drivers/pci/pcie/portdrv_core.c22
-rw-r--r--drivers/pci/pcie/portdrv_pci.c5
-rw-r--r--drivers/pci/probe.c38
-rw-r--r--drivers/pci/proc.c4
-rw-r--r--drivers/pci/quirks.c134
-rw-r--r--drivers/pci/setup-bus.c43
-rw-r--r--drivers/pci/setup-irq.c3
-rw-r--r--drivers/pci/setup-res.c70
-rw-r--r--drivers/pci/slot.c233
39 files changed, 1789 insertions, 1117 deletions
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 4d1ce2e7361e..7d63f8ced24b 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -2,7 +2,7 @@
2# Makefile for the PCI bus specific drivers. 2# Makefile for the PCI bus specific drivers.
3# 3#
4 4
5obj-y += access.o bus.o probe.o remove.o pci.o quirks.o \ 5obj-y += access.o bus.o probe.o remove.o pci.o quirks.o slot.o \
6 pci-driver.o search.o pci-sysfs.o rom.o setup-res.o 6 pci-driver.o search.o pci-sysfs.o rom.o setup-res.o
7obj-$(CONFIG_PROC_FS) += proc.o 7obj-$(CONFIG_PROC_FS) += proc.o
8 8
diff --git a/drivers/pci/hotplug/acpi_pcihp.c b/drivers/pci/hotplug/acpi_pcihp.c
index f8c187a763bd..93e37f0666ab 100644
--- a/drivers/pci/hotplug/acpi_pcihp.c
+++ b/drivers/pci/hotplug/acpi_pcihp.c
@@ -30,6 +30,7 @@
30#include <linux/types.h> 30#include <linux/types.h>
31#include <linux/pci.h> 31#include <linux/pci.h>
32#include <linux/pci_hotplug.h> 32#include <linux/pci_hotplug.h>
33#include <linux/pci-acpi.h>
33#include <acpi/acpi.h> 34#include <acpi/acpi.h>
34#include <acpi/acpi_bus.h> 35#include <acpi/acpi_bus.h>
35#include <acpi/actypes.h> 36#include <acpi/actypes.h>
@@ -299,7 +300,7 @@ free_and_return:
299 * 300 *
300 * @handle - the handle of the hotplug controller. 301 * @handle - the handle of the hotplug controller.
301 */ 302 */
302acpi_status acpi_run_oshp(acpi_handle handle) 303static acpi_status acpi_run_oshp(acpi_handle handle)
303{ 304{
304 acpi_status status; 305 acpi_status status;
305 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; 306 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -322,9 +323,6 @@ acpi_status acpi_run_oshp(acpi_handle handle)
322 kfree(string.pointer); 323 kfree(string.pointer);
323 return status; 324 return status;
324} 325}
325EXPORT_SYMBOL_GPL(acpi_run_oshp);
326
327
328 326
329/* acpi_get_hp_params_from_firmware 327/* acpi_get_hp_params_from_firmware
330 * 328 *
@@ -374,6 +372,85 @@ acpi_status acpi_get_hp_params_from_firmware(struct pci_bus *bus,
374} 372}
375EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware); 373EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
376 374
375/**
376 * acpi_get_hp_hw_control_from_firmware
377 * @dev: the pci_dev of the bridge that has a hotplug controller
378 * @flags: requested control bits for _OSC
379 *
380 * Attempt to take hotplug control from firmware.
381 */
382int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
383{
384 acpi_status status;
385 acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
386 struct pci_dev *pdev = dev;
387 struct pci_bus *parent;
388 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
389
390 flags &= (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL |
391 OSC_SHPC_NATIVE_HP_CONTROL |
392 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
393 if (!flags) {
394 err("Invalid flags %u specified!\n", flags);
395 return -EINVAL;
396 }
397
398 /*
399 * Per PCI firmware specification, we should run the ACPI _OSC
400 * method to get control of hotplug hardware before using it. If
401 * an _OSC is missing, we look for an OSHP to do the same thing.
402 * To handle different BIOS behavior, we look for _OSC and OSHP
403 * within the scope of the hotplug controller and its parents,
404 * upto the host bridge under which this controller exists.
405 */
406 while (!handle) {
407 /*
408 * This hotplug controller was not listed in the ACPI name
409 * space at all. Try to get acpi handle of parent pci bus.
410 */
411 if (!pdev || !pdev->bus->parent)
412 break;
413 parent = pdev->bus->parent;
414 dbg("Could not find %s in acpi namespace, trying parent\n",
415 pci_name(pdev));
416 if (!parent->self)
417 /* Parent must be a host bridge */
418 handle = acpi_get_pci_rootbridge_handle(
419 pci_domain_nr(parent),
420 parent->number);
421 else
422 handle = DEVICE_ACPI_HANDLE(&(parent->self->dev));
423 pdev = parent->self;
424 }
425
426 while (handle) {
427 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
428 dbg("Trying to get hotplug control for %s \n",
429 (char *)string.pointer);
430 status = pci_osc_control_set(handle, flags);
431 if (status == AE_NOT_FOUND)
432 status = acpi_run_oshp(handle);
433 if (ACPI_SUCCESS(status)) {
434 dbg("Gained control for hotplug HW for pci %s (%s)\n",
435 pci_name(dev), (char *)string.pointer);
436 kfree(string.pointer);
437 return 0;
438 }
439 if (acpi_root_bridge(handle))
440 break;
441 chandle = handle;
442 status = acpi_get_parent(chandle, &handle);
443 if (ACPI_FAILURE(status))
444 break;
445 }
446
447 dbg("Cannot get control of hotplug hardware for pci %s\n",
448 pci_name(dev));
449
450 kfree(string.pointer);
451 return -ENODEV;
452}
453EXPORT_SYMBOL(acpi_get_hp_hw_control_from_firmware);
377 454
378/* acpi_root_bridge - check to see if this acpi object is a root bridge 455/* acpi_root_bridge - check to see if this acpi object is a root bridge
379 * 456 *
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index 7a29164d4b32..eecf7cbf4139 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -215,7 +215,6 @@ extern u8 acpiphp_get_power_status (struct acpiphp_slot *slot);
215extern u8 acpiphp_get_attention_status (struct acpiphp_slot *slot); 215extern u8 acpiphp_get_attention_status (struct acpiphp_slot *slot);
216extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot); 216extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot);
217extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot); 217extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot);
218extern u32 acpiphp_get_address (struct acpiphp_slot *slot);
219 218
220/* variables */ 219/* variables */
221extern int acpiphp_debug; 220extern int acpiphp_debug;
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index 7af68ba27903..0e496e866a84 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -70,7 +70,6 @@ static int disable_slot (struct hotplug_slot *slot);
70static int set_attention_status (struct hotplug_slot *slot, u8 value); 70static int set_attention_status (struct hotplug_slot *slot, u8 value);
71static int get_power_status (struct hotplug_slot *slot, u8 *value); 71static int get_power_status (struct hotplug_slot *slot, u8 *value);
72static int get_attention_status (struct hotplug_slot *slot, u8 *value); 72static int get_attention_status (struct hotplug_slot *slot, u8 *value);
73static int get_address (struct hotplug_slot *slot, u32 *value);
74static int get_latch_status (struct hotplug_slot *slot, u8 *value); 73static int get_latch_status (struct hotplug_slot *slot, u8 *value);
75static int get_adapter_status (struct hotplug_slot *slot, u8 *value); 74static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
76 75
@@ -83,7 +82,6 @@ static struct hotplug_slot_ops acpi_hotplug_slot_ops = {
83 .get_attention_status = get_attention_status, 82 .get_attention_status = get_attention_status,
84 .get_latch_status = get_latch_status, 83 .get_latch_status = get_latch_status,
85 .get_adapter_status = get_adapter_status, 84 .get_adapter_status = get_adapter_status,
86 .get_address = get_address,
87}; 85};
88 86
89 87
@@ -274,23 +272,6 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
274 return 0; 272 return 0;
275} 273}
276 274
277
278/**
279 * get_address - get pci address of a slot
280 * @hotplug_slot: slot to get status
281 * @value: pointer to struct pci_busdev (seg, bus, dev)
282 */
283static int get_address(struct hotplug_slot *hotplug_slot, u32 *value)
284{
285 struct slot *slot = hotplug_slot->private;
286
287 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
288
289 *value = acpiphp_get_address(slot->acpi_slot);
290
291 return 0;
292}
293
294static int __init init_acpi(void) 275static int __init init_acpi(void)
295{ 276{
296 int retval; 277 int retval;
@@ -357,7 +338,11 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
357 acpiphp_slot->slot = slot; 338 acpiphp_slot->slot = slot;
358 snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun); 339 snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun);
359 340
360 retval = pci_hp_register(slot->hotplug_slot); 341 retval = pci_hp_register(slot->hotplug_slot,
342 acpiphp_slot->bridge->pci_bus,
343 acpiphp_slot->device);
344 if (retval == -EBUSY)
345 goto error_hpslot;
361 if (retval) { 346 if (retval) {
362 err("pci_hp_register failed with error %d\n", retval); 347 err("pci_hp_register failed with error %d\n", retval);
363 goto error_hpslot; 348 goto error_hpslot;
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 91156f85a926..a3e4705dd8f0 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -258,7 +258,12 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
258 bridge->pci_bus->number, slot->device); 258 bridge->pci_bus->number, slot->device);
259 retval = acpiphp_register_hotplug_slot(slot); 259 retval = acpiphp_register_hotplug_slot(slot);
260 if (retval) { 260 if (retval) {
261 warn("acpiphp_register_hotplug_slot failed(err code = 0x%x)\n", retval); 261 if (retval == -EBUSY)
262 warn("Slot %d already registered by another "
263 "hotplug driver\n", slot->sun);
264 else
265 warn("acpiphp_register_hotplug_slot failed "
266 "(err code = 0x%x)\n", retval);
262 goto err_exit; 267 goto err_exit;
263 } 268 }
264 } 269 }
@@ -1878,19 +1883,3 @@ u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1878 1883
1879 return (sta == 0) ? 0 : 1; 1884 return (sta == 0) ? 0 : 1;
1880} 1885}
1881
1882
1883/*
1884 * pci address (seg/bus/dev)
1885 */
1886u32 acpiphp_get_address(struct acpiphp_slot *slot)
1887{
1888 u32 address;
1889 struct pci_bus *pci_bus = slot->bridge->pci_bus;
1890
1891 address = (pci_domain_nr(pci_bus) << 16) |
1892 (pci_bus->number << 8) |
1893 slot->device;
1894
1895 return address;
1896}
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index ede9051fdb5d..2b7c45e39370 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -33,8 +33,10 @@
33#include <linux/kobject.h> 33#include <linux/kobject.h>
34#include <asm/uaccess.h> 34#include <asm/uaccess.h>
35#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
36#include <linux/pci.h>
36 37
37#include "acpiphp.h" 38#include "acpiphp.h"
39#include "../pci.h"
38 40
39#define DRIVER_VERSION "1.0.1" 41#define DRIVER_VERSION "1.0.1"
40#define DRIVER_AUTHOR "Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>" 42#define DRIVER_AUTHOR "Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
@@ -430,7 +432,7 @@ static int __init ibm_acpiphp_init(void)
430 int retval = 0; 432 int retval = 0;
431 acpi_status status; 433 acpi_status status;
432 struct acpi_device *device; 434 struct acpi_device *device;
433 struct kobject *sysdir = &pci_hotplug_slots_kset->kobj; 435 struct kobject *sysdir = &pci_slots_kset->kobj;
434 436
435 dbg("%s\n", __func__); 437 dbg("%s\n", __func__);
436 438
@@ -477,7 +479,7 @@ init_return:
477static void __exit ibm_acpiphp_exit(void) 479static void __exit ibm_acpiphp_exit(void)
478{ 480{
479 acpi_status status; 481 acpi_status status;
480 struct kobject *sysdir = &pci_hotplug_slots_kset->kobj; 482 struct kobject *sysdir = &pci_slots_kset->kobj;
481 483
482 dbg("%s\n", __func__); 484 dbg("%s\n", __func__);
483 485
diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c
index d8a6b80ab42a..935947991dc9 100644
--- a/drivers/pci/hotplug/cpci_hotplug_core.c
+++ b/drivers/pci/hotplug/cpci_hotplug_core.c
@@ -285,7 +285,7 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
285 info->attention_status = cpci_get_attention_status(slot); 285 info->attention_status = cpci_get_attention_status(slot);
286 286
287 dbg("registering slot %s", slot->hotplug_slot->name); 287 dbg("registering slot %s", slot->hotplug_slot->name);
288 status = pci_hp_register(slot->hotplug_slot); 288 status = pci_hp_register(slot->hotplug_slot, bus, i);
289 if (status) { 289 if (status) {
290 err("pci_hp_register failed with error %d", status); 290 err("pci_hp_register failed with error %d", status);
291 goto error_name; 291 goto error_name;
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index 36b115b27b0b..54defec51d08 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -434,7 +434,9 @@ static int ctrl_slot_setup(struct controller *ctrl,
434 slot->bus, slot->device, 434 slot->bus, slot->device,
435 slot->number, ctrl->slot_device_offset, 435 slot->number, ctrl->slot_device_offset,
436 slot_number); 436 slot_number);
437 result = pci_hp_register(hotplug_slot); 437 result = pci_hp_register(hotplug_slot,
438 ctrl->pci_dev->subordinate,
439 slot->device);
438 if (result) { 440 if (result) {
439 err("pci_hp_register failed with error %d\n", result); 441 err("pci_hp_register failed with error %d\n", result);
440 goto error_name; 442 goto error_name;
diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
index 7e9a827c2687..40337a06c18a 100644
--- a/drivers/pci/hotplug/fakephp.c
+++ b/drivers/pci/hotplug/fakephp.c
@@ -66,6 +66,7 @@ struct dummy_slot {
66 struct pci_dev *dev; 66 struct pci_dev *dev;
67 struct work_struct remove_work; 67 struct work_struct remove_work;
68 unsigned long removed; 68 unsigned long removed;
69 char name[8];
69}; 70};
70 71
71static int debug; 72static int debug;
@@ -100,6 +101,7 @@ static int add_slot(struct pci_dev *dev)
100 struct dummy_slot *dslot; 101 struct dummy_slot *dslot;
101 struct hotplug_slot *slot; 102 struct hotplug_slot *slot;
102 int retval = -ENOMEM; 103 int retval = -ENOMEM;
104 static int count = 1;
103 105
104 slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL); 106 slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
105 if (!slot) 107 if (!slot)
@@ -113,18 +115,18 @@ static int add_slot(struct pci_dev *dev)
113 slot->info->max_bus_speed = PCI_SPEED_UNKNOWN; 115 slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
114 slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN; 116 slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;
115 117
116 slot->name = &dev->dev.bus_id[0];
117 dbg("slot->name = %s\n", slot->name);
118
119 dslot = kzalloc(sizeof(struct dummy_slot), GFP_KERNEL); 118 dslot = kzalloc(sizeof(struct dummy_slot), GFP_KERNEL);
120 if (!dslot) 119 if (!dslot)
121 goto error_info; 120 goto error_info;
122 121
122 slot->name = dslot->name;
123 snprintf(slot->name, sizeof(dslot->name), "fake%d", count++);
124 dbg("slot->name = %s\n", slot->name);
123 slot->ops = &dummy_hotplug_slot_ops; 125 slot->ops = &dummy_hotplug_slot_ops;
124 slot->release = &dummy_release; 126 slot->release = &dummy_release;
125 slot->private = dslot; 127 slot->private = dslot;
126 128
127 retval = pci_hp_register(slot); 129 retval = pci_hp_register(slot, dev->bus, PCI_SLOT(dev->devfn));
128 if (retval) { 130 if (retval) {
129 err("pci_hp_register failed with error %d\n", retval); 131 err("pci_hp_register failed with error %d\n", retval);
130 goto error_dslot; 132 goto error_dslot;
@@ -148,17 +150,17 @@ error:
148static int __init pci_scan_buses(void) 150static int __init pci_scan_buses(void)
149{ 151{
150 struct pci_dev *dev = NULL; 152 struct pci_dev *dev = NULL;
151 int retval = 0; 153 int lastslot = 0;
152 154
153 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 155 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
154 retval = add_slot(dev); 156 if (PCI_FUNC(dev->devfn) > 0 &&
155 if (retval) { 157 lastslot == PCI_SLOT(dev->devfn))
156 pci_dev_put(dev); 158 continue;
157 break; 159 lastslot = PCI_SLOT(dev->devfn);
158 } 160 add_slot(dev);
159 } 161 }
160 162
161 return retval; 163 return 0;
162} 164}
163 165
164static void remove_slot(struct dummy_slot *dslot) 166static void remove_slot(struct dummy_slot *dslot)
@@ -296,23 +298,9 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
296 return 0; 298 return 0;
297} 299}
298 300
299/* find the hotplug_slot for the pci_dev */
300static struct hotplug_slot *get_slot_from_dev(struct pci_dev *dev)
301{
302 struct dummy_slot *dslot;
303
304 list_for_each_entry(dslot, &slot_list, node) {
305 if (dslot->dev == dev)
306 return dslot->slot;
307 }
308 return NULL;
309}
310
311
312static int disable_slot(struct hotplug_slot *slot) 301static int disable_slot(struct hotplug_slot *slot)
313{ 302{
314 struct dummy_slot *dslot; 303 struct dummy_slot *dslot;
315 struct hotplug_slot *hslot;
316 struct pci_dev *dev; 304 struct pci_dev *dev;
317 int func; 305 int func;
318 306
@@ -322,41 +310,27 @@ static int disable_slot(struct hotplug_slot *slot)
322 310
323 dbg("%s - physical_slot = %s\n", __func__, slot->name); 311 dbg("%s - physical_slot = %s\n", __func__, slot->name);
324 312
325 /* don't disable bridged devices just yet, we can't handle them easily... */ 313 for (func = 7; func >= 0; func--) {
326 if (dslot->dev->subordinate) { 314 dev = pci_get_slot(dslot->dev->bus, dslot->dev->devfn + func);
327 err("Can't remove PCI devices with other PCI devices behind it yet.\n"); 315 if (!dev)
328 return -ENODEV; 316 continue;
329 } 317
330 if (test_and_set_bit(0, &dslot->removed)) { 318 if (test_and_set_bit(0, &dslot->removed)) {
331 dbg("Slot already scheduled for removal\n"); 319 dbg("Slot already scheduled for removal\n");
332 return -ENODEV; 320 return -ENODEV;
333 }
334 /* search for subfunctions and disable them first */
335 if (!(dslot->dev->devfn & 7)) {
336 for (func = 1; func < 8; func++) {
337 dev = pci_get_slot(dslot->dev->bus,
338 dslot->dev->devfn + func);
339 if (dev) {
340 hslot = get_slot_from_dev(dev);
341 if (hslot)
342 disable_slot(hslot);
343 else {
344 err("Hotplug slot not found for subfunction of PCI device\n");
345 return -ENODEV;
346 }
347 pci_dev_put(dev);
348 } else
349 dbg("No device in slot found\n");
350 } 321 }
351 }
352 322
353 /* remove the device from the pci core */ 323 /* queue work item to blow away this sysfs entry and other
354 pci_remove_bus_device(dslot->dev); 324 * parts.
325 */
326 INIT_WORK(&dslot->remove_work, remove_slot_worker);
327 queue_work(dummyphp_wq, &dslot->remove_work);
355 328
356 /* queue work item to blow away this sysfs entry and other parts. */ 329 /* blow away this sysfs entry and other parts. */
357 INIT_WORK(&dslot->remove_work, remove_slot_worker); 330 remove_slot(dslot);
358 queue_work(dummyphp_wq, &dslot->remove_work);
359 331
332 pci_dev_put(dev);
333 }
360 return 0; 334 return 0;
361} 335}
362 336
diff --git a/drivers/pci/hotplug/ibmphp_ebda.c b/drivers/pci/hotplug/ibmphp_ebda.c
index dca7efc14be2..8467d0287325 100644
--- a/drivers/pci/hotplug/ibmphp_ebda.c
+++ b/drivers/pci/hotplug/ibmphp_ebda.c
@@ -1001,7 +1001,8 @@ static int __init ebda_rsrc_controller (void)
1001 tmp_slot = list_entry (list, struct slot, ibm_slot_list); 1001 tmp_slot = list_entry (list, struct slot, ibm_slot_list);
1002 1002
1003 snprintf (tmp_slot->hotplug_slot->name, 30, "%s", create_file_name (tmp_slot)); 1003 snprintf (tmp_slot->hotplug_slot->name, 30, "%s", create_file_name (tmp_slot));
1004 pci_hp_register (tmp_slot->hotplug_slot); 1004 pci_hp_register(tmp_slot->hotplug_slot,
1005 pci_find_bus(0, tmp_slot->bus), tmp_slot->device);
1005 } 1006 }
1006 1007
1007 print_ebda_hpc (); 1008 print_ebda_hpc ();
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index a11021e8ce37..5f85b1b120e3 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -40,6 +40,7 @@
40#include <linux/pci.h> 40#include <linux/pci.h>
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 44
44#define MY_NAME "pci_hotplug" 45#define MY_NAME "pci_hotplug"
45 46
@@ -60,41 +61,7 @@ static int debug;
60////////////////////////////////////////////////////////////////// 61//////////////////////////////////////////////////////////////////
61 62
62static LIST_HEAD(pci_hotplug_slot_list); 63static LIST_HEAD(pci_hotplug_slot_list);
63 64static DEFINE_SPINLOCK(pci_hotplug_slot_list_lock);
64struct kset *pci_hotplug_slots_kset;
65
66static ssize_t hotplug_slot_attr_show(struct kobject *kobj,
67 struct attribute *attr, char *buf)
68{
69 struct hotplug_slot *slot = to_hotplug_slot(kobj);
70 struct hotplug_slot_attribute *attribute = to_hotplug_attr(attr);
71 return attribute->show ? attribute->show(slot, buf) : -EIO;
72}
73
74static ssize_t hotplug_slot_attr_store(struct kobject *kobj,
75 struct attribute *attr, const char *buf, size_t len)
76{
77 struct hotplug_slot *slot = to_hotplug_slot(kobj);
78 struct hotplug_slot_attribute *attribute = to_hotplug_attr(attr);
79 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
80}
81
82static struct sysfs_ops hotplug_slot_sysfs_ops = {
83 .show = hotplug_slot_attr_show,
84 .store = hotplug_slot_attr_store,
85};
86
87static void hotplug_slot_release(struct kobject *kobj)
88{
89 struct hotplug_slot *slot = to_hotplug_slot(kobj);
90 if (slot->release)
91 slot->release(slot);
92}
93
94static struct kobj_type hotplug_slot_ktype = {
95 .sysfs_ops = &hotplug_slot_sysfs_ops,
96 .release = &hotplug_slot_release,
97};
98 65
99/* these strings match up with the values in pci_bus_speed */ 66/* these strings match up with the values in pci_bus_speed */
100static char *pci_bus_speed_strings[] = { 67static char *pci_bus_speed_strings[] = {
@@ -149,16 +116,15 @@ GET_STATUS(power_status, u8)
149GET_STATUS(attention_status, u8) 116GET_STATUS(attention_status, u8)
150GET_STATUS(latch_status, u8) 117GET_STATUS(latch_status, u8)
151GET_STATUS(adapter_status, u8) 118GET_STATUS(adapter_status, u8)
152GET_STATUS(address, u32)
153GET_STATUS(max_bus_speed, enum pci_bus_speed) 119GET_STATUS(max_bus_speed, enum pci_bus_speed)
154GET_STATUS(cur_bus_speed, enum pci_bus_speed) 120GET_STATUS(cur_bus_speed, enum pci_bus_speed)
155 121
156static ssize_t power_read_file (struct hotplug_slot *slot, char *buf) 122static ssize_t power_read_file(struct pci_slot *slot, char *buf)
157{ 123{
158 int retval; 124 int retval;
159 u8 value; 125 u8 value;
160 126
161 retval = get_power_status (slot, &value); 127 retval = get_power_status(slot->hotplug, &value);
162 if (retval) 128 if (retval)
163 goto exit; 129 goto exit;
164 retval = sprintf (buf, "%d\n", value); 130 retval = sprintf (buf, "%d\n", value);
@@ -166,9 +132,10 @@ exit:
166 return retval; 132 return retval;
167} 133}
168 134
169static ssize_t power_write_file (struct hotplug_slot *slot, const char *buf, 135static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf,
170 size_t count) 136 size_t count)
171{ 137{
138 struct hotplug_slot *slot = pci_slot->hotplug;
172 unsigned long lpower; 139 unsigned long lpower;
173 u8 power; 140 u8 power;
174 int retval = 0; 141 int retval = 0;
@@ -204,29 +171,30 @@ exit:
204 return count; 171 return count;
205} 172}
206 173
207static struct hotplug_slot_attribute hotplug_slot_attr_power = { 174static struct pci_slot_attribute hotplug_slot_attr_power = {
208 .attr = {.name = "power", .mode = S_IFREG | S_IRUGO | S_IWUSR}, 175 .attr = {.name = "power", .mode = S_IFREG | S_IRUGO | S_IWUSR},
209 .show = power_read_file, 176 .show = power_read_file,
210 .store = power_write_file 177 .store = power_write_file
211}; 178};
212 179
213static ssize_t attention_read_file (struct hotplug_slot *slot, char *buf) 180static ssize_t attention_read_file(struct pci_slot *slot, char *buf)
214{ 181{
215 int retval; 182 int retval;
216 u8 value; 183 u8 value;
217 184
218 retval = get_attention_status (slot, &value); 185 retval = get_attention_status(slot->hotplug, &value);
219 if (retval) 186 if (retval)
220 goto exit; 187 goto exit;
221 retval = sprintf (buf, "%d\n", value); 188 retval = sprintf(buf, "%d\n", value);
222 189
223exit: 190exit:
224 return retval; 191 return retval;
225} 192}
226 193
227static ssize_t attention_write_file (struct hotplug_slot *slot, const char *buf, 194static ssize_t attention_write_file(struct pci_slot *slot, const char *buf,
228 size_t count) 195 size_t count)
229{ 196{
197 struct hotplug_slot_ops *ops = slot->hotplug->ops;
230 unsigned long lattention; 198 unsigned long lattention;
231 u8 attention; 199 u8 attention;
232 int retval = 0; 200 int retval = 0;
@@ -235,13 +203,13 @@ static ssize_t attention_write_file (struct hotplug_slot *slot, const char *buf,
235 attention = (u8)(lattention & 0xff); 203 attention = (u8)(lattention & 0xff);
236 dbg (" - attention = %d\n", attention); 204 dbg (" - attention = %d\n", attention);
237 205
238 if (!try_module_get(slot->ops->owner)) { 206 if (!try_module_get(ops->owner)) {
239 retval = -ENODEV; 207 retval = -ENODEV;
240 goto exit; 208 goto exit;
241 } 209 }
242 if (slot->ops->set_attention_status) 210 if (ops->set_attention_status)
243 retval = slot->ops->set_attention_status(slot, attention); 211 retval = ops->set_attention_status(slot->hotplug, attention);
244 module_put(slot->ops->owner); 212 module_put(ops->owner);
245 213
246exit: 214exit:
247 if (retval) 215 if (retval)
@@ -249,18 +217,18 @@ exit:
249 return count; 217 return count;
250} 218}
251 219
252static struct hotplug_slot_attribute hotplug_slot_attr_attention = { 220static struct pci_slot_attribute hotplug_slot_attr_attention = {
253 .attr = {.name = "attention", .mode = S_IFREG | S_IRUGO | S_IWUSR}, 221 .attr = {.name = "attention", .mode = S_IFREG | S_IRUGO | S_IWUSR},
254 .show = attention_read_file, 222 .show = attention_read_file,
255 .store = attention_write_file 223 .store = attention_write_file
256}; 224};
257 225
258static ssize_t latch_read_file (struct hotplug_slot *slot, char *buf) 226static ssize_t latch_read_file(struct pci_slot *slot, char *buf)
259{ 227{
260 int retval; 228 int retval;
261 u8 value; 229 u8 value;
262 230
263 retval = get_latch_status (slot, &value); 231 retval = get_latch_status(slot->hotplug, &value);
264 if (retval) 232 if (retval)
265 goto exit; 233 goto exit;
266 retval = sprintf (buf, "%d\n", value); 234 retval = sprintf (buf, "%d\n", value);
@@ -269,17 +237,17 @@ exit:
269 return retval; 237 return retval;
270} 238}
271 239
272static struct hotplug_slot_attribute hotplug_slot_attr_latch = { 240static struct pci_slot_attribute hotplug_slot_attr_latch = {
273 .attr = {.name = "latch", .mode = S_IFREG | S_IRUGO}, 241 .attr = {.name = "latch", .mode = S_IFREG | S_IRUGO},
274 .show = latch_read_file, 242 .show = latch_read_file,
275}; 243};
276 244
277static ssize_t presence_read_file (struct hotplug_slot *slot, char *buf) 245static ssize_t presence_read_file(struct pci_slot *slot, char *buf)
278{ 246{
279 int retval; 247 int retval;
280 u8 value; 248 u8 value;
281 249
282 retval = get_adapter_status (slot, &value); 250 retval = get_adapter_status(slot->hotplug, &value);
283 if (retval) 251 if (retval)
284 goto exit; 252 goto exit;
285 retval = sprintf (buf, "%d\n", value); 253 retval = sprintf (buf, "%d\n", value);
@@ -288,42 +256,20 @@ exit:
288 return retval; 256 return retval;
289} 257}
290 258
291static struct hotplug_slot_attribute hotplug_slot_attr_presence = { 259static struct pci_slot_attribute hotplug_slot_attr_presence = {
292 .attr = {.name = "adapter", .mode = S_IFREG | S_IRUGO}, 260 .attr = {.name = "adapter", .mode = S_IFREG | S_IRUGO},
293 .show = presence_read_file, 261 .show = presence_read_file,
294}; 262};
295 263
296static ssize_t address_read_file (struct hotplug_slot *slot, char *buf)
297{
298 int retval;
299 u32 address;
300
301 retval = get_address (slot, &address);
302 if (retval)
303 goto exit;
304 retval = sprintf (buf, "%04x:%02x:%02x\n",
305 (address >> 16) & 0xffff,
306 (address >> 8) & 0xff,
307 address & 0xff);
308
309exit:
310 return retval;
311}
312
313static struct hotplug_slot_attribute hotplug_slot_attr_address = {
314 .attr = {.name = "address", .mode = S_IFREG | S_IRUGO},
315 .show = address_read_file,
316};
317
318static char *unknown_speed = "Unknown bus speed"; 264static char *unknown_speed = "Unknown bus speed";
319 265
320static ssize_t max_bus_speed_read_file (struct hotplug_slot *slot, char *buf) 266static ssize_t max_bus_speed_read_file(struct pci_slot *slot, char *buf)
321{ 267{
322 char *speed_string; 268 char *speed_string;
323 int retval; 269 int retval;
324 enum pci_bus_speed value; 270 enum pci_bus_speed value;
325 271
326 retval = get_max_bus_speed (slot, &value); 272 retval = get_max_bus_speed(slot->hotplug, &value);
327 if (retval) 273 if (retval)
328 goto exit; 274 goto exit;
329 275
@@ -338,18 +284,18 @@ exit:
338 return retval; 284 return retval;
339} 285}
340 286
341static struct hotplug_slot_attribute hotplug_slot_attr_max_bus_speed = { 287static struct pci_slot_attribute hotplug_slot_attr_max_bus_speed = {
342 .attr = {.name = "max_bus_speed", .mode = S_IFREG | S_IRUGO}, 288 .attr = {.name = "max_bus_speed", .mode = S_IFREG | S_IRUGO},
343 .show = max_bus_speed_read_file, 289 .show = max_bus_speed_read_file,
344}; 290};
345 291
346static ssize_t cur_bus_speed_read_file (struct hotplug_slot *slot, char *buf) 292static ssize_t cur_bus_speed_read_file(struct pci_slot *slot, char *buf)
347{ 293{
348 char *speed_string; 294 char *speed_string;
349 int retval; 295 int retval;
350 enum pci_bus_speed value; 296 enum pci_bus_speed value;
351 297
352 retval = get_cur_bus_speed (slot, &value); 298 retval = get_cur_bus_speed(slot->hotplug, &value);
353 if (retval) 299 if (retval)
354 goto exit; 300 goto exit;
355 301
@@ -364,14 +310,15 @@ exit:
364 return retval; 310 return retval;
365} 311}
366 312
367static struct hotplug_slot_attribute hotplug_slot_attr_cur_bus_speed = { 313static struct pci_slot_attribute hotplug_slot_attr_cur_bus_speed = {
368 .attr = {.name = "cur_bus_speed", .mode = S_IFREG | S_IRUGO}, 314 .attr = {.name = "cur_bus_speed", .mode = S_IFREG | S_IRUGO},
369 .show = cur_bus_speed_read_file, 315 .show = cur_bus_speed_read_file,
370}; 316};
371 317
372static ssize_t test_write_file (struct hotplug_slot *slot, const char *buf, 318static ssize_t test_write_file(struct pci_slot *pci_slot, const char *buf,
373 size_t count) 319 size_t count)
374{ 320{
321 struct hotplug_slot *slot = pci_slot->hotplug;
375 unsigned long ltest; 322 unsigned long ltest;
376 u32 test; 323 u32 test;
377 int retval = 0; 324 int retval = 0;
@@ -394,13 +341,14 @@ exit:
394 return count; 341 return count;
395} 342}
396 343
397static struct hotplug_slot_attribute hotplug_slot_attr_test = { 344static struct pci_slot_attribute hotplug_slot_attr_test = {
398 .attr = {.name = "test", .mode = S_IFREG | S_IRUGO | S_IWUSR}, 345 .attr = {.name = "test", .mode = S_IFREG | S_IRUGO | S_IWUSR},
399 .store = test_write_file 346 .store = test_write_file
400}; 347};
401 348
402static int has_power_file (struct hotplug_slot *slot) 349static int has_power_file(struct pci_slot *pci_slot)
403{ 350{
351 struct hotplug_slot *slot = pci_slot->hotplug;
404 if ((!slot) || (!slot->ops)) 352 if ((!slot) || (!slot->ops))
405 return -ENODEV; 353 return -ENODEV;
406 if ((slot->ops->enable_slot) || 354 if ((slot->ops->enable_slot) ||
@@ -410,8 +358,9 @@ static int has_power_file (struct hotplug_slot *slot)
410 return -ENOENT; 358 return -ENOENT;
411} 359}
412 360
413static int has_attention_file (struct hotplug_slot *slot) 361static int has_attention_file(struct pci_slot *pci_slot)
414{ 362{
363 struct hotplug_slot *slot = pci_slot->hotplug;
415 if ((!slot) || (!slot->ops)) 364 if ((!slot) || (!slot->ops))
416 return -ENODEV; 365 return -ENODEV;
417 if ((slot->ops->set_attention_status) || 366 if ((slot->ops->set_attention_status) ||
@@ -420,8 +369,9 @@ static int has_attention_file (struct hotplug_slot *slot)
420 return -ENOENT; 369 return -ENOENT;
421} 370}
422 371
423static int has_latch_file (struct hotplug_slot *slot) 372static int has_latch_file(struct pci_slot *pci_slot)
424{ 373{
374 struct hotplug_slot *slot = pci_slot->hotplug;
425 if ((!slot) || (!slot->ops)) 375 if ((!slot) || (!slot->ops))
426 return -ENODEV; 376 return -ENODEV;
427 if (slot->ops->get_latch_status) 377 if (slot->ops->get_latch_status)
@@ -429,8 +379,9 @@ static int has_latch_file (struct hotplug_slot *slot)
429 return -ENOENT; 379 return -ENOENT;
430} 380}
431 381
432static int has_adapter_file (struct hotplug_slot *slot) 382static int has_adapter_file(struct pci_slot *pci_slot)
433{ 383{
384 struct hotplug_slot *slot = pci_slot->hotplug;
434 if ((!slot) || (!slot->ops)) 385 if ((!slot) || (!slot->ops))
435 return -ENODEV; 386 return -ENODEV;
436 if (slot->ops->get_adapter_status) 387 if (slot->ops->get_adapter_status)
@@ -438,17 +389,9 @@ static int has_adapter_file (struct hotplug_slot *slot)
438 return -ENOENT; 389 return -ENOENT;
439} 390}
440 391
441static int has_address_file (struct hotplug_slot *slot) 392static int has_max_bus_speed_file(struct pci_slot *pci_slot)
442{
443 if ((!slot) || (!slot->ops))
444 return -ENODEV;
445 if (slot->ops->get_address)
446 return 0;
447 return -ENOENT;
448}
449
450static int has_max_bus_speed_file (struct hotplug_slot *slot)
451{ 393{
394 struct hotplug_slot *slot = pci_slot->hotplug;
452 if ((!slot) || (!slot->ops)) 395 if ((!slot) || (!slot->ops))
453 return -ENODEV; 396 return -ENODEV;
454 if (slot->ops->get_max_bus_speed) 397 if (slot->ops->get_max_bus_speed)
@@ -456,8 +399,9 @@ static int has_max_bus_speed_file (struct hotplug_slot *slot)
456 return -ENOENT; 399 return -ENOENT;
457} 400}
458 401
459static int has_cur_bus_speed_file (struct hotplug_slot *slot) 402static int has_cur_bus_speed_file(struct pci_slot *pci_slot)
460{ 403{
404 struct hotplug_slot *slot = pci_slot->hotplug;
461 if ((!slot) || (!slot->ops)) 405 if ((!slot) || (!slot->ops))
462 return -ENODEV; 406 return -ENODEV;
463 if (slot->ops->get_cur_bus_speed) 407 if (slot->ops->get_cur_bus_speed)
@@ -465,8 +409,9 @@ static int has_cur_bus_speed_file (struct hotplug_slot *slot)
465 return -ENOENT; 409 return -ENOENT;
466} 410}
467 411
468static int has_test_file (struct hotplug_slot *slot) 412static int has_test_file(struct pci_slot *pci_slot)
469{ 413{
414 struct hotplug_slot *slot = pci_slot->hotplug;
470 if ((!slot) || (!slot->ops)) 415 if ((!slot) || (!slot->ops))
471 return -ENODEV; 416 return -ENODEV;
472 if (slot->ops->hardware_test) 417 if (slot->ops->hardware_test)
@@ -474,7 +419,7 @@ static int has_test_file (struct hotplug_slot *slot)
474 return -ENOENT; 419 return -ENOENT;
475} 420}
476 421
477static int fs_add_slot (struct hotplug_slot *slot) 422static int fs_add_slot(struct pci_slot *slot)
478{ 423{
479 int retval = 0; 424 int retval = 0;
480 425
@@ -505,13 +450,6 @@ static int fs_add_slot (struct hotplug_slot *slot)
505 goto exit_adapter; 450 goto exit_adapter;
506 } 451 }
507 452
508 if (has_address_file(slot) == 0) {
509 retval = sysfs_create_file(&slot->kobj,
510 &hotplug_slot_attr_address.attr);
511 if (retval)
512 goto exit_address;
513 }
514
515 if (has_max_bus_speed_file(slot) == 0) { 453 if (has_max_bus_speed_file(slot) == 0) {
516 retval = sysfs_create_file(&slot->kobj, 454 retval = sysfs_create_file(&slot->kobj,
517 &hotplug_slot_attr_max_bus_speed.attr); 455 &hotplug_slot_attr_max_bus_speed.attr);
@@ -544,10 +482,6 @@ exit_cur_speed:
544 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr); 482 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr);
545 483
546exit_max_speed: 484exit_max_speed:
547 if (has_address_file(slot) == 0)
548 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr);
549
550exit_address:
551 if (has_adapter_file(slot) == 0) 485 if (has_adapter_file(slot) == 0)
552 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr); 486 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr);
553 487
@@ -567,7 +501,7 @@ exit:
567 return retval; 501 return retval;
568} 502}
569 503
570static void fs_remove_slot (struct hotplug_slot *slot) 504static void fs_remove_slot(struct pci_slot *slot)
571{ 505{
572 if (has_power_file(slot) == 0) 506 if (has_power_file(slot) == 0)
573 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr); 507 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr);
@@ -581,9 +515,6 @@ static void fs_remove_slot (struct hotplug_slot *slot)
581 if (has_adapter_file(slot) == 0) 515 if (has_adapter_file(slot) == 0)
582 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr); 516 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr);
583 517
584 if (has_address_file(slot) == 0)
585 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr);
586
587 if (has_max_bus_speed_file(slot) == 0) 518 if (has_max_bus_speed_file(slot) == 0)
588 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr); 519 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr);
589 520
@@ -599,27 +530,33 @@ static struct hotplug_slot *get_slot_from_name (const char *name)
599 struct hotplug_slot *slot; 530 struct hotplug_slot *slot;
600 struct list_head *tmp; 531 struct list_head *tmp;
601 532
533 spin_lock(&pci_hotplug_slot_list_lock);
602 list_for_each (tmp, &pci_hotplug_slot_list) { 534 list_for_each (tmp, &pci_hotplug_slot_list) {
603 slot = list_entry (tmp, struct hotplug_slot, slot_list); 535 slot = list_entry (tmp, struct hotplug_slot, slot_list);
604 if (strcmp(slot->name, name) == 0) 536 if (strcmp(slot->name, name) == 0)
605 return slot; 537 goto out;
606 } 538 }
607 return NULL; 539 slot = NULL;
540out:
541 spin_unlock(&pci_hotplug_slot_list_lock);
542 return slot;
608} 543}
609 544
610/** 545/**
611 * pci_hp_register - register a hotplug_slot with the PCI hotplug subsystem 546 * pci_hp_register - register a hotplug_slot with the PCI hotplug subsystem
547 * @bus: bus this slot is on
612 * @slot: pointer to the &struct hotplug_slot to register 548 * @slot: pointer to the &struct hotplug_slot to register
549 * @slot_nr: slot number
613 * 550 *
614 * Registers a hotplug slot with the pci hotplug subsystem, which will allow 551 * Registers a hotplug slot with the pci hotplug subsystem, which will allow
615 * userspace interaction to the slot. 552 * userspace interaction to the slot.
616 * 553 *
617 * Returns 0 if successful, anything else for an error. 554 * Returns 0 if successful, anything else for an error.
618 */ 555 */
619int pci_hp_register (struct hotplug_slot *slot) 556int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr)
620{ 557{
621 int result; 558 int result;
622 struct hotplug_slot *tmp; 559 struct pci_slot *pci_slot;
623 560
624 if (slot == NULL) 561 if (slot == NULL)
625 return -ENODEV; 562 return -ENODEV;
@@ -632,57 +569,89 @@ int pci_hp_register (struct hotplug_slot *slot)
632 } 569 }
633 570
634 /* Check if we have already registered a slot with the same name. */ 571 /* Check if we have already registered a slot with the same name. */
635 tmp = get_slot_from_name(slot->name); 572 if (get_slot_from_name(slot->name))
636 if (tmp)
637 return -EEXIST; 573 return -EEXIST;
638 574
639 slot->kobj.kset = pci_hotplug_slots_kset; 575 /*
640 result = kobject_init_and_add(&slot->kobj, &hotplug_slot_ktype, NULL, 576 * No problems if we call this interface from both ACPI_PCI_SLOT
641 "%s", slot->name); 577 * driver and call it here again. If we've already created the
642 if (result) { 578 * pci_slot, the interface will simply bump the refcount.
643 err("Unable to register kobject '%s'", slot->name); 579 */
644 return -EINVAL; 580 pci_slot = pci_create_slot(bus, slot_nr, slot->name);
581 if (IS_ERR(pci_slot))
582 return PTR_ERR(pci_slot);
583
584 if (pci_slot->hotplug) {
585 dbg("%s: already claimed\n", __func__);
586 pci_destroy_slot(pci_slot);
587 return -EBUSY;
645 } 588 }
646 589
647 list_add (&slot->slot_list, &pci_hotplug_slot_list); 590 slot->pci_slot = pci_slot;
591 pci_slot->hotplug = slot;
592
593 /*
594 * Allow pcihp drivers to override the ACPI_PCI_SLOT name.
595 */
596 if (strcmp(kobject_name(&pci_slot->kobj), slot->name)) {
597 result = kobject_rename(&pci_slot->kobj, slot->name);
598 if (result) {
599 pci_destroy_slot(pci_slot);
600 return result;
601 }
602 }
603
604 spin_lock(&pci_hotplug_slot_list_lock);
605 list_add(&slot->slot_list, &pci_hotplug_slot_list);
606 spin_unlock(&pci_hotplug_slot_list_lock);
607
608 result = fs_add_slot(pci_slot);
609 kobject_uevent(&pci_slot->kobj, KOBJ_ADD);
610 dbg("Added slot %s to the list\n", slot->name);
611
648 612
649 result = fs_add_slot (slot);
650 kobject_uevent(&slot->kobj, KOBJ_ADD);
651 dbg ("Added slot %s to the list\n", slot->name);
652 return result; 613 return result;
653} 614}
654 615
655/** 616/**
656 * pci_hp_deregister - deregister a hotplug_slot with the PCI hotplug subsystem 617 * pci_hp_deregister - deregister a hotplug_slot with the PCI hotplug subsystem
657 * @slot: pointer to the &struct hotplug_slot to deregister 618 * @hotplug: pointer to the &struct hotplug_slot to deregister
658 * 619 *
659 * The @slot must have been registered with the pci hotplug subsystem 620 * The @slot must have been registered with the pci hotplug subsystem
660 * previously with a call to pci_hp_register(). 621 * previously with a call to pci_hp_register().
661 * 622 *
662 * Returns 0 if successful, anything else for an error. 623 * Returns 0 if successful, anything else for an error.
663 */ 624 */
664int pci_hp_deregister (struct hotplug_slot *slot) 625int pci_hp_deregister(struct hotplug_slot *hotplug)
665{ 626{
666 struct hotplug_slot *temp; 627 struct hotplug_slot *temp;
628 struct pci_slot *slot;
667 629
668 if (slot == NULL) 630 if (!hotplug)
669 return -ENODEV; 631 return -ENODEV;
670 632
671 temp = get_slot_from_name (slot->name); 633 temp = get_slot_from_name(hotplug->name);
672 if (temp != slot) { 634 if (temp != hotplug)
673 return -ENODEV; 635 return -ENODEV;
674 }
675 list_del (&slot->slot_list);
676 636
677 fs_remove_slot (slot); 637 spin_lock(&pci_hotplug_slot_list_lock);
678 dbg ("Removed slot %s from the list\n", slot->name); 638 list_del(&hotplug->slot_list);
679 kobject_put(&slot->kobj); 639 spin_unlock(&pci_hotplug_slot_list_lock);
640
641 slot = hotplug->pci_slot;
642 fs_remove_slot(slot);
643 dbg("Removed slot %s from the list\n", hotplug->name);
644
645 hotplug->release(hotplug);
646 slot->hotplug = NULL;
647 pci_destroy_slot(slot);
648
680 return 0; 649 return 0;
681} 650}
682 651
683/** 652/**
684 * pci_hp_change_slot_info - changes the slot's information structure in the core 653 * pci_hp_change_slot_info - changes the slot's information structure in the core
685 * @slot: pointer to the slot whose info has changed 654 * @hotplug: pointer to the slot whose info has changed
686 * @info: pointer to the info copy into the slot's info structure 655 * @info: pointer to the info copy into the slot's info structure
687 * 656 *
688 * @slot must have been registered with the pci 657 * @slot must have been registered with the pci
@@ -690,13 +659,15 @@ int pci_hp_deregister (struct hotplug_slot *slot)
690 * 659 *
691 * Returns 0 if successful, anything else for an error. 660 * Returns 0 if successful, anything else for an error.
692 */ 661 */
693int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot, 662int __must_check pci_hp_change_slot_info(struct hotplug_slot *hotplug,
694 struct hotplug_slot_info *info) 663 struct hotplug_slot_info *info)
695{ 664{
696 if ((slot == NULL) || (info == NULL)) 665 struct pci_slot *slot;
666 if (!hotplug || !info)
697 return -ENODEV; 667 return -ENODEV;
668 slot = hotplug->pci_slot;
698 669
699 memcpy (slot->info, info, sizeof (struct hotplug_slot_info)); 670 memcpy(hotplug->info, info, sizeof(struct hotplug_slot_info));
700 671
701 return 0; 672 return 0;
702} 673}
@@ -704,36 +675,22 @@ int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot,
704static int __init pci_hotplug_init (void) 675static int __init pci_hotplug_init (void)
705{ 676{
706 int result; 677 int result;
707 struct kset *pci_bus_kset;
708 678
709 pci_bus_kset = bus_get_kset(&pci_bus_type);
710
711 pci_hotplug_slots_kset = kset_create_and_add("slots", NULL,
712 &pci_bus_kset->kobj);
713 if (!pci_hotplug_slots_kset) {
714 result = -ENOMEM;
715 err("Register subsys error\n");
716 goto exit;
717 }
718 result = cpci_hotplug_init(debug); 679 result = cpci_hotplug_init(debug);
719 if (result) { 680 if (result) {
720 err ("cpci_hotplug_init with error %d\n", result); 681 err ("cpci_hotplug_init with error %d\n", result);
721 goto err_subsys; 682 goto err_cpci;
722 } 683 }
723 684
724 info (DRIVER_DESC " version: " DRIVER_VERSION "\n"); 685 info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
725 goto exit;
726 686
727err_subsys: 687err_cpci:
728 kset_unregister(pci_hotplug_slots_kset);
729exit:
730 return result; 688 return result;
731} 689}
732 690
733static void __exit pci_hotplug_exit (void) 691static void __exit pci_hotplug_exit (void)
734{ 692{
735 cpci_hotplug_exit(); 693 cpci_hotplug_exit();
736 kset_unregister(pci_hotplug_slots_kset);
737} 694}
738 695
739module_init(pci_hotplug_init); 696module_init(pci_hotplug_init);
@@ -745,7 +702,6 @@ MODULE_LICENSE("GPL");
745module_param(debug, bool, 0644); 702module_param(debug, bool, 0644);
746MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); 703MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
747 704
748EXPORT_SYMBOL_GPL(pci_hotplug_slots_kset);
749EXPORT_SYMBOL_GPL(pci_hp_register); 705EXPORT_SYMBOL_GPL(pci_hp_register);
750EXPORT_SYMBOL_GPL(pci_hp_deregister); 706EXPORT_SYMBOL_GPL(pci_hp_deregister);
751EXPORT_SYMBOL_GPL(pci_hp_change_slot_info); 707EXPORT_SYMBOL_GPL(pci_hp_change_slot_info);
diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
index 79c9ddaad3fb..e3a1e7e7dba2 100644
--- a/drivers/pci/hotplug/pciehp.h
+++ b/drivers/pci/hotplug/pciehp.h
@@ -43,6 +43,7 @@ extern int pciehp_poll_mode;
43extern int pciehp_poll_time; 43extern int pciehp_poll_time;
44extern int pciehp_debug; 44extern int pciehp_debug;
45extern int pciehp_force; 45extern int pciehp_force;
46extern int pciehp_slot_with_bus;
46extern struct workqueue_struct *pciehp_wq; 47extern struct workqueue_struct *pciehp_wq;
47 48
48#define dbg(format, arg...) \ 49#define dbg(format, arg...) \
@@ -96,7 +97,7 @@ struct controller {
96 u32 slot_cap; 97 u32 slot_cap;
97 u8 cap_base; 98 u8 cap_base;
98 struct timer_list poll_timer; 99 struct timer_list poll_timer;
99 volatile int cmd_busy; 100 int cmd_busy;
100 unsigned int no_cmd_complete:1; 101 unsigned int no_cmd_complete:1;
101}; 102};
102 103
@@ -156,10 +157,10 @@ extern u8 pciehp_handle_power_fault(struct slot *p_slot);
156extern int pciehp_configure_device(struct slot *p_slot); 157extern int pciehp_configure_device(struct slot *p_slot);
157extern int pciehp_unconfigure_device(struct slot *p_slot); 158extern int pciehp_unconfigure_device(struct slot *p_slot);
158extern void pciehp_queue_pushbutton_work(struct work_struct *work); 159extern void pciehp_queue_pushbutton_work(struct work_struct *work);
159int pcie_init(struct controller *ctrl, struct pcie_device *dev); 160struct controller *pcie_init(struct pcie_device *dev);
160int pciehp_enable_slot(struct slot *p_slot); 161int pciehp_enable_slot(struct slot *p_slot);
161int pciehp_disable_slot(struct slot *p_slot); 162int pciehp_disable_slot(struct slot *p_slot);
162int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev); 163int pcie_enable_notification(struct controller *ctrl);
163 164
164static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device) 165static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device)
165{ 166{
@@ -202,8 +203,13 @@ struct hpc_ops {
202#include <acpi/actypes.h> 203#include <acpi/actypes.h>
203#include <linux/pci-acpi.h> 204#include <linux/pci-acpi.h>
204 205
205#define pciehp_get_hp_hw_control_from_firmware(dev) \ 206static inline int pciehp_get_hp_hw_control_from_firmware(struct pci_dev *dev)
206 pciehp_acpi_get_hp_hw_control_from_firmware(dev) 207{
208 u32 flags = (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL |
209 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
210 return acpi_get_hp_hw_control_from_firmware(dev, flags);
211}
212
207static inline int pciehp_get_hp_params_from_firmware(struct pci_dev *dev, 213static inline int pciehp_get_hp_params_from_firmware(struct pci_dev *dev,
208 struct hotplug_params *hpp) 214 struct hotplug_params *hpp)
209{ 215{
diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
index 48a2ed378914..3677495c4f91 100644
--- a/drivers/pci/hotplug/pciehp_core.c
+++ b/drivers/pci/hotplug/pciehp_core.c
@@ -72,7 +72,6 @@ static int get_power_status (struct hotplug_slot *slot, u8 *value);
72static int get_attention_status (struct hotplug_slot *slot, u8 *value); 72static int get_attention_status (struct hotplug_slot *slot, u8 *value);
73static int get_latch_status (struct hotplug_slot *slot, u8 *value); 73static int get_latch_status (struct hotplug_slot *slot, u8 *value);
74static int get_adapter_status (struct hotplug_slot *slot, u8 *value); 74static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
75static int get_address (struct hotplug_slot *slot, u32 *value);
76static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); 75static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
77static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); 76static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
78 77
@@ -85,7 +84,6 @@ static struct hotplug_slot_ops pciehp_hotplug_slot_ops = {
85 .get_attention_status = get_attention_status, 84 .get_attention_status = get_attention_status,
86 .get_latch_status = get_latch_status, 85 .get_latch_status = get_latch_status,
87 .get_adapter_status = get_adapter_status, 86 .get_adapter_status = get_adapter_status,
88 .get_address = get_address,
89 .get_max_bus_speed = get_max_bus_speed, 87 .get_max_bus_speed = get_max_bus_speed,
90 .get_cur_bus_speed = get_cur_bus_speed, 88 .get_cur_bus_speed = get_cur_bus_speed,
91}; 89};
@@ -185,23 +183,10 @@ static struct hotplug_slot_attribute hotplug_slot_attr_lock = {
185 */ 183 */
186static void release_slot(struct hotplug_slot *hotplug_slot) 184static void release_slot(struct hotplug_slot *hotplug_slot)
187{ 185{
188 struct slot *slot = hotplug_slot->private;
189
190 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); 186 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
191 187
192 kfree(slot->hotplug_slot->info); 188 kfree(hotplug_slot->info);
193 kfree(slot->hotplug_slot); 189 kfree(hotplug_slot);
194 kfree(slot);
195}
196
197static void make_slot_name(struct slot *slot)
198{
199 if (pciehp_slot_with_bus)
200 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d",
201 slot->bus, slot->number);
202 else
203 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%d",
204 slot->number);
205} 190}
206 191
207static int init_slots(struct controller *ctrl) 192static int init_slots(struct controller *ctrl)
@@ -210,49 +195,34 @@ static int init_slots(struct controller *ctrl)
210 struct hotplug_slot *hotplug_slot; 195 struct hotplug_slot *hotplug_slot;
211 struct hotplug_slot_info *info; 196 struct hotplug_slot_info *info;
212 int retval = -ENOMEM; 197 int retval = -ENOMEM;
213 int i;
214
215 for (i = 0; i < ctrl->num_slots; i++) {
216 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
217 if (!slot)
218 goto error;
219 198
199 list_for_each_entry(slot, &ctrl->slot_list, slot_list) {
220 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL); 200 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
221 if (!hotplug_slot) 201 if (!hotplug_slot)
222 goto error_slot; 202 goto error;
223 slot->hotplug_slot = hotplug_slot;
224 203
225 info = kzalloc(sizeof(*info), GFP_KERNEL); 204 info = kzalloc(sizeof(*info), GFP_KERNEL);
226 if (!info) 205 if (!info)
227 goto error_hpslot; 206 goto error_hpslot;
228 hotplug_slot->info = info;
229
230 hotplug_slot->name = slot->name;
231
232 slot->hp_slot = i;
233 slot->ctrl = ctrl;
234 slot->bus = ctrl->pci_dev->subordinate->number;
235 slot->device = ctrl->slot_device_offset + i;
236 slot->hpc_ops = ctrl->hpc_ops;
237 slot->number = ctrl->first_slot;
238 mutex_init(&slot->lock);
239 INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work);
240 207
241 /* register this slot with the hotplug pci core */ 208 /* register this slot with the hotplug pci core */
209 hotplug_slot->info = info;
210 hotplug_slot->name = slot->name;
242 hotplug_slot->private = slot; 211 hotplug_slot->private = slot;
243 hotplug_slot->release = &release_slot; 212 hotplug_slot->release = &release_slot;
244 make_slot_name(slot);
245 hotplug_slot->ops = &pciehp_hotplug_slot_ops; 213 hotplug_slot->ops = &pciehp_hotplug_slot_ops;
246
247 get_power_status(hotplug_slot, &info->power_status); 214 get_power_status(hotplug_slot, &info->power_status);
248 get_attention_status(hotplug_slot, &info->attention_status); 215 get_attention_status(hotplug_slot, &info->attention_status);
249 get_latch_status(hotplug_slot, &info->latch_status); 216 get_latch_status(hotplug_slot, &info->latch_status);
250 get_adapter_status(hotplug_slot, &info->adapter_status); 217 get_adapter_status(hotplug_slot, &info->adapter_status);
218 slot->hotplug_slot = hotplug_slot;
251 219
252 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " 220 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
253 "slot_device_offset=%x\n", slot->bus, slot->device, 221 "slot_device_offset=%x\n", slot->bus, slot->device,
254 slot->hp_slot, slot->number, ctrl->slot_device_offset); 222 slot->hp_slot, slot->number, ctrl->slot_device_offset);
255 retval = pci_hp_register(hotplug_slot); 223 retval = pci_hp_register(hotplug_slot,
224 ctrl->pci_dev->subordinate,
225 slot->device);
256 if (retval) { 226 if (retval) {
257 err("pci_hp_register failed with error %d\n", retval); 227 err("pci_hp_register failed with error %d\n", retval);
258 if (retval == -EEXIST) 228 if (retval == -EEXIST)
@@ -263,7 +233,7 @@ static int init_slots(struct controller *ctrl)
263 } 233 }
264 /* create additional sysfs entries */ 234 /* create additional sysfs entries */
265 if (EMI(ctrl)) { 235 if (EMI(ctrl)) {
266 retval = sysfs_create_file(&hotplug_slot->kobj, 236 retval = sysfs_create_file(&hotplug_slot->pci_slot->kobj,
267 &hotplug_slot_attr_lock.attr); 237 &hotplug_slot_attr_lock.attr);
268 if (retval) { 238 if (retval) {
269 pci_hp_deregister(hotplug_slot); 239 pci_hp_deregister(hotplug_slot);
@@ -271,8 +241,6 @@ static int init_slots(struct controller *ctrl)
271 goto error_info; 241 goto error_info;
272 } 242 }
273 } 243 }
274
275 list_add(&slot->slot_list, &ctrl->slot_list);
276 } 244 }
277 245
278 return 0; 246 return 0;
@@ -280,27 +248,18 @@ error_info:
280 kfree(info); 248 kfree(info);
281error_hpslot: 249error_hpslot:
282 kfree(hotplug_slot); 250 kfree(hotplug_slot);
283error_slot:
284 kfree(slot);
285error: 251error:
286 return retval; 252 return retval;
287} 253}
288 254
289static void cleanup_slots(struct controller *ctrl) 255static void cleanup_slots(struct controller *ctrl)
290{ 256{
291 struct list_head *tmp;
292 struct list_head *next;
293 struct slot *slot; 257 struct slot *slot;
294 258
295 list_for_each_safe(tmp, next, &ctrl->slot_list) { 259 list_for_each_entry(slot, &ctrl->slot_list, slot_list) {
296 slot = list_entry(tmp, struct slot, slot_list);
297 list_del(&slot->slot_list);
298 if (EMI(ctrl)) 260 if (EMI(ctrl))
299 sysfs_remove_file(&slot->hotplug_slot->kobj, 261 sysfs_remove_file(&slot->hotplug_slot->pci_slot->kobj,
300 &hotplug_slot_attr_lock.attr); 262 &hotplug_slot_attr_lock.attr);
301 cancel_delayed_work(&slot->work);
302 flush_scheduled_work();
303 flush_workqueue(pciehp_wq);
304 pci_hp_deregister(slot->hotplug_slot); 263 pci_hp_deregister(slot->hotplug_slot);
305 } 264 }
306} 265}
@@ -398,19 +357,8 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
398 return 0; 357 return 0;
399} 358}
400 359
401static int get_address(struct hotplug_slot *hotplug_slot, u32 *value) 360static int get_max_bus_speed(struct hotplug_slot *hotplug_slot,
402{ 361 enum pci_bus_speed *value)
403 struct slot *slot = hotplug_slot->private;
404 struct pci_bus *bus = slot->ctrl->pci_dev->subordinate;
405
406 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
407
408 *value = (pci_domain_nr(bus) << 16) | (slot->bus << 8) | slot->device;
409
410 return 0;
411}
412
413static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
414{ 362{
415 struct slot *slot = hotplug_slot->private; 363 struct slot *slot = hotplug_slot->private;
416 int retval; 364 int retval;
@@ -444,34 +392,30 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
444 struct controller *ctrl; 392 struct controller *ctrl;
445 struct slot *t_slot; 393 struct slot *t_slot;
446 u8 value; 394 u8 value;
447 struct pci_dev *pdev; 395 struct pci_dev *pdev = dev->port;
448 396
449 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); 397 if (pciehp_force)
450 if (!ctrl) { 398 dbg("Bypassing BIOS check for pciehp use on %s\n",
451 err("%s : out of memory\n", __func__); 399 pci_name(pdev));
400 else if (pciehp_get_hp_hw_control_from_firmware(pdev))
452 goto err_out_none; 401 goto err_out_none;
453 }
454 INIT_LIST_HEAD(&ctrl->slot_list);
455
456 pdev = dev->port;
457 ctrl->pci_dev = pdev;
458 402
459 rc = pcie_init(ctrl, dev); 403 ctrl = pcie_init(dev);
460 if (rc) { 404 if (!ctrl) {
461 dbg("%s: controller initialization failed\n", PCIE_MODULE_NAME); 405 dbg("%s: controller initialization failed\n", PCIE_MODULE_NAME);
462 goto err_out_free_ctrl; 406 goto err_out_none;
463 } 407 }
464 408 set_service_data(dev, ctrl);
465 pci_set_drvdata(pdev, ctrl);
466
467 dbg("%s: ctrl bus=0x%x, device=%x, function=%x, irq=%x\n",
468 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
469 PCI_FUNC(pdev->devfn), pdev->irq);
470 409
471 /* Setup the slot information structures */ 410 /* Setup the slot information structures */
472 rc = init_slots(ctrl); 411 rc = init_slots(ctrl);
473 if (rc) { 412 if (rc) {
474 err("%s: slot initialization failed\n", PCIE_MODULE_NAME); 413 if (rc == -EBUSY)
414 warn("%s: slot already registered by another "
415 "hotplug driver\n", PCIE_MODULE_NAME);
416 else
417 err("%s: slot initialization failed\n",
418 PCIE_MODULE_NAME);
475 goto err_out_release_ctlr; 419 goto err_out_release_ctlr;
476 } 420 }
477 421
@@ -495,20 +439,16 @@ err_out_free_ctrl_slot:
495 cleanup_slots(ctrl); 439 cleanup_slots(ctrl);
496err_out_release_ctlr: 440err_out_release_ctlr:
497 ctrl->hpc_ops->release_ctlr(ctrl); 441 ctrl->hpc_ops->release_ctlr(ctrl);
498err_out_free_ctrl:
499 kfree(ctrl);
500err_out_none: 442err_out_none:
501 return -ENODEV; 443 return -ENODEV;
502} 444}
503 445
504static void pciehp_remove (struct pcie_device *dev) 446static void pciehp_remove (struct pcie_device *dev)
505{ 447{
506 struct pci_dev *pdev = dev->port; 448 struct controller *ctrl = get_service_data(dev);
507 struct controller *ctrl = pci_get_drvdata(pdev);
508 449
509 cleanup_slots(ctrl); 450 cleanup_slots(ctrl);
510 ctrl->hpc_ops->release_ctlr(ctrl); 451 ctrl->hpc_ops->release_ctlr(ctrl);
511 kfree(ctrl);
512} 452}
513 453
514#ifdef CONFIG_PM 454#ifdef CONFIG_PM
@@ -522,13 +462,12 @@ static int pciehp_resume (struct pcie_device *dev)
522{ 462{
523 printk("%s ENTRY\n", __func__); 463 printk("%s ENTRY\n", __func__);
524 if (pciehp_force) { 464 if (pciehp_force) {
525 struct pci_dev *pdev = dev->port; 465 struct controller *ctrl = get_service_data(dev);
526 struct controller *ctrl = pci_get_drvdata(pdev);
527 struct slot *t_slot; 466 struct slot *t_slot;
528 u8 status; 467 u8 status;
529 468
530 /* reinitialize the chipset's event detection logic */ 469 /* reinitialize the chipset's event detection logic */
531 pcie_init_hardware_part2(ctrl, dev); 470 pcie_enable_notification(ctrl);
532 471
533 t_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset); 472 t_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset);
534 473
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 79f104963166..1323a43285d7 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -247,30 +247,32 @@ static inline void pciehp_free_irq(struct controller *ctrl)
247 free_irq(ctrl->pci_dev->irq, ctrl); 247 free_irq(ctrl->pci_dev->irq, ctrl);
248} 248}
249 249
250static inline int pcie_poll_cmd(struct controller *ctrl) 250static int pcie_poll_cmd(struct controller *ctrl)
251{ 251{
252 u16 slot_status; 252 u16 slot_status;
253 int timeout = 1000; 253 int timeout = 1000;
254 254
255 if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) 255 if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) {
256 if (slot_status & CMD_COMPLETED) 256 if (slot_status & CMD_COMPLETED) {
257 goto completed; 257 pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED);
258 for (timeout = 1000; timeout > 0; timeout -= 100) { 258 return 1;
259 msleep(100); 259 }
260 if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) 260 }
261 if (slot_status & CMD_COMPLETED) 261 while (timeout > 1000) {
262 goto completed; 262 msleep(10);
263 timeout -= 10;
264 if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) {
265 if (slot_status & CMD_COMPLETED) {
266 pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED);
267 return 1;
268 }
269 }
263 } 270 }
264 return 0; /* timeout */ 271 return 0; /* timeout */
265
266completed:
267 pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED);
268 return timeout;
269} 272}
270 273
271static inline int pcie_wait_cmd(struct controller *ctrl, int poll) 274static void pcie_wait_cmd(struct controller *ctrl, int poll)
272{ 275{
273 int retval = 0;
274 unsigned int msecs = pciehp_poll_mode ? 2500 : 1000; 276 unsigned int msecs = pciehp_poll_mode ? 2500 : 1000;
275 unsigned long timeout = msecs_to_jiffies(msecs); 277 unsigned long timeout = msecs_to_jiffies(msecs);
276 int rc; 278 int rc;
@@ -278,16 +280,9 @@ static inline int pcie_wait_cmd(struct controller *ctrl, int poll)
278 if (poll) 280 if (poll)
279 rc = pcie_poll_cmd(ctrl); 281 rc = pcie_poll_cmd(ctrl);
280 else 282 else
281 rc = wait_event_interruptible_timeout(ctrl->queue, 283 rc = wait_event_timeout(ctrl->queue, !ctrl->cmd_busy, timeout);
282 !ctrl->cmd_busy, timeout);
283 if (!rc) 284 if (!rc)
284 dbg("Command not completed in 1000 msec\n"); 285 dbg("Command not completed in 1000 msec\n");
285 else if (rc < 0) {
286 retval = -EINTR;
287 info("Command was interrupted by a signal\n");
288 }
289
290 return retval;
291} 286}
292 287
293/** 288/**
@@ -342,10 +337,6 @@ static int pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask)
342 337
343 slot_ctrl &= ~mask; 338 slot_ctrl &= ~mask;
344 slot_ctrl |= (cmd & mask); 339 slot_ctrl |= (cmd & mask);
345 /* Don't enable command completed if caller is changing it. */
346 if (!(mask & CMD_CMPL_INTR_ENABLE))
347 slot_ctrl |= CMD_CMPL_INTR_ENABLE;
348
349 ctrl->cmd_busy = 1; 340 ctrl->cmd_busy = 1;
350 smp_mb(); 341 smp_mb();
351 retval = pciehp_writew(ctrl, SLOTCTRL, slot_ctrl); 342 retval = pciehp_writew(ctrl, SLOTCTRL, slot_ctrl);
@@ -365,7 +356,7 @@ static int pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask)
365 if (!(slot_ctrl & HP_INTR_ENABLE) || 356 if (!(slot_ctrl & HP_INTR_ENABLE) ||
366 !(slot_ctrl & CMD_CMPL_INTR_ENABLE)) 357 !(slot_ctrl & CMD_CMPL_INTR_ENABLE))
367 poll = 1; 358 poll = 1;
368 retval = pcie_wait_cmd(ctrl, poll); 359 pcie_wait_cmd(ctrl, poll);
369 } 360 }
370 out: 361 out:
371 mutex_unlock(&ctrl->ctrl_lock); 362 mutex_unlock(&ctrl->ctrl_lock);
@@ -614,23 +605,6 @@ static void hpc_set_green_led_blink(struct slot *slot)
614 __func__, ctrl->cap_base + SLOTCTRL, slot_cmd); 605 __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
615} 606}
616 607
617static void hpc_release_ctlr(struct controller *ctrl)
618{
619 /* Mask Hot-plug Interrupt Enable */
620 if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE))
621 err("%s: Cannot mask hotplut interrupt enable\n", __func__);
622
623 /* Free interrupt handler or interrupt polling timer */
624 pciehp_free_irq(ctrl);
625
626 /*
627 * If this is the last controller to be released, destroy the
628 * pciehp work queue
629 */
630 if (atomic_dec_and_test(&pciehp_num_controllers))
631 destroy_workqueue(pciehp_wq);
632}
633
634static int hpc_power_on_slot(struct slot * slot) 608static int hpc_power_on_slot(struct slot * slot)
635{ 609{
636 struct controller *ctrl = slot->ctrl; 610 struct controller *ctrl = slot->ctrl;
@@ -785,7 +759,7 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
785 intr_loc |= detected; 759 intr_loc |= detected;
786 if (!intr_loc) 760 if (!intr_loc)
787 return IRQ_NONE; 761 return IRQ_NONE;
788 if (pciehp_writew(ctrl, SLOTSTATUS, detected)) { 762 if (detected && pciehp_writew(ctrl, SLOTSTATUS, detected)) {
789 err("%s: Cannot write to SLOTSTATUS\n", __func__); 763 err("%s: Cannot write to SLOTSTATUS\n", __func__);
790 return IRQ_NONE; 764 return IRQ_NONE;
791 } 765 }
@@ -797,25 +771,13 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
797 if (intr_loc & CMD_COMPLETED) { 771 if (intr_loc & CMD_COMPLETED) {
798 ctrl->cmd_busy = 0; 772 ctrl->cmd_busy = 0;
799 smp_mb(); 773 smp_mb();
800 wake_up_interruptible(&ctrl->queue); 774 wake_up(&ctrl->queue);
801 } 775 }
802 776
803 if (!(intr_loc & ~CMD_COMPLETED)) 777 if (!(intr_loc & ~CMD_COMPLETED))
804 return IRQ_HANDLED; 778 return IRQ_HANDLED;
805 779
806 /*
807 * Return without handling events if this handler routine is
808 * called before controller initialization is done. This may
809 * happen if hotplug event or another interrupt that shares
810 * the IRQ with pciehp arrives before slot initialization is
811 * done after interrupt handler is registered.
812 *
813 * FIXME - Need more structural fixes. We need to be ready to
814 * handle the event before installing interrupt handler.
815 */
816 p_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset); 780 p_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset);
817 if (!p_slot || !p_slot->hpc_ops)
818 return IRQ_HANDLED;
819 781
820 /* Check MRL Sensor Changed */ 782 /* Check MRL Sensor Changed */
821 if (intr_loc & MRL_SENS_CHANGED) 783 if (intr_loc & MRL_SENS_CHANGED)
@@ -992,6 +954,7 @@ static int hpc_get_cur_lnk_width(struct slot *slot,
992 return retval; 954 return retval;
993} 955}
994 956
957static void pcie_release_ctrl(struct controller *ctrl);
995static struct hpc_ops pciehp_hpc_ops = { 958static struct hpc_ops pciehp_hpc_ops = {
996 .power_on_slot = hpc_power_on_slot, 959 .power_on_slot = hpc_power_on_slot,
997 .power_off_slot = hpc_power_off_slot, 960 .power_off_slot = hpc_power_off_slot,
@@ -1013,97 +976,11 @@ static struct hpc_ops pciehp_hpc_ops = {
1013 .green_led_off = hpc_set_green_led_off, 976 .green_led_off = hpc_set_green_led_off,
1014 .green_led_blink = hpc_set_green_led_blink, 977 .green_led_blink = hpc_set_green_led_blink,
1015 978
1016 .release_ctlr = hpc_release_ctlr, 979 .release_ctlr = pcie_release_ctrl,
1017 .check_lnk_status = hpc_check_lnk_status, 980 .check_lnk_status = hpc_check_lnk_status,
1018}; 981};
1019 982
1020#ifdef CONFIG_ACPI 983int pcie_enable_notification(struct controller *ctrl)
1021static int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev)
1022{
1023 acpi_status status;
1024 acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
1025 struct pci_dev *pdev = dev;
1026 struct pci_bus *parent;
1027 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
1028
1029 /*
1030 * Per PCI firmware specification, we should run the ACPI _OSC
1031 * method to get control of hotplug hardware before using it.
1032 * If an _OSC is missing, we look for an OSHP to do the same thing.
1033 * To handle different BIOS behavior, we look for _OSC and OSHP
1034 * within the scope of the hotplug controller and its parents, upto
1035 * the host bridge under which this controller exists.
1036 */
1037 while (!handle) {
1038 /*
1039 * This hotplug controller was not listed in the ACPI name
1040 * space at all. Try to get acpi handle of parent pci bus.
1041 */
1042 if (!pdev || !pdev->bus->parent)
1043 break;
1044 parent = pdev->bus->parent;
1045 dbg("Could not find %s in acpi namespace, trying parent\n",
1046 pci_name(pdev));
1047 if (!parent->self)
1048 /* Parent must be a host bridge */
1049 handle = acpi_get_pci_rootbridge_handle(
1050 pci_domain_nr(parent),
1051 parent->number);
1052 else
1053 handle = DEVICE_ACPI_HANDLE(
1054 &(parent->self->dev));
1055 pdev = parent->self;
1056 }
1057
1058 while (handle) {
1059 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
1060 dbg("Trying to get hotplug control for %s \n",
1061 (char *)string.pointer);
1062 status = pci_osc_control_set(handle,
1063 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL |
1064 OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
1065 if (status == AE_NOT_FOUND)
1066 status = acpi_run_oshp(handle);
1067 if (ACPI_SUCCESS(status)) {
1068 dbg("Gained control for hotplug HW for pci %s (%s)\n",
1069 pci_name(dev), (char *)string.pointer);
1070 kfree(string.pointer);
1071 return 0;
1072 }
1073 if (acpi_root_bridge(handle))
1074 break;
1075 chandle = handle;
1076 status = acpi_get_parent(chandle, &handle);
1077 if (ACPI_FAILURE(status))
1078 break;
1079 }
1080
1081 dbg("Cannot get control of hotplug hardware for pci %s\n",
1082 pci_name(dev));
1083
1084 kfree(string.pointer);
1085 return -1;
1086}
1087#endif
1088
1089static int pcie_init_hardware_part1(struct controller *ctrl,
1090 struct pcie_device *dev)
1091{
1092 /* Clear all remaining event bits in Slot Status register */
1093 if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f)) {
1094 err("%s: Cannot write to SLOTSTATUS register\n", __func__);
1095 return -1;
1096 }
1097
1098 /* Mask Hot-plug Interrupt Enable */
1099 if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE)) {
1100 err("%s: Cannot mask hotplug interrupt enable\n", __func__);
1101 return -1;
1102 }
1103 return 0;
1104}
1105
1106int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev)
1107{ 984{
1108 u16 cmd, mask; 985 u16 cmd, mask;
1109 986
@@ -1115,30 +992,83 @@ int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev)
1115 if (MRL_SENS(ctrl)) 992 if (MRL_SENS(ctrl))
1116 cmd |= MRL_DETECT_ENABLE; 993 cmd |= MRL_DETECT_ENABLE;
1117 if (!pciehp_poll_mode) 994 if (!pciehp_poll_mode)
1118 cmd |= HP_INTR_ENABLE; 995 cmd |= HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE;
1119 996
1120 mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE | 997 mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE | MRL_DETECT_ENABLE |
1121 PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE | HP_INTR_ENABLE; 998 PWR_FAULT_DETECT_ENABLE | HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE;
1122 999
1123 if (pcie_write_cmd(ctrl, cmd, mask)) { 1000 if (pcie_write_cmd(ctrl, cmd, mask)) {
1124 err("%s: Cannot enable software notification\n", __func__); 1001 err("%s: Cannot enable software notification\n", __func__);
1125 goto abort; 1002 return -1;
1126 } 1003 }
1004 return 0;
1005}
1127 1006
1128 if (pciehp_force) 1007static void pcie_disable_notification(struct controller *ctrl)
1129 dbg("Bypassing BIOS check for pciehp use on %s\n", 1008{
1130 pci_name(ctrl->pci_dev)); 1009 u16 mask;
1131 else if (pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev)) 1010 mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE | MRL_DETECT_ENABLE |
1132 goto abort_disable_intr; 1011 PWR_FAULT_DETECT_ENABLE | HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE;
1012 if (pcie_write_cmd(ctrl, 0, mask))
1013 warn("%s: Cannot disable software notification\n", __func__);
1014}
1133 1015
1016static int pcie_init_notification(struct controller *ctrl)
1017{
1018 if (pciehp_request_irq(ctrl))
1019 return -1;
1020 if (pcie_enable_notification(ctrl)) {
1021 pciehp_free_irq(ctrl);
1022 return -1;
1023 }
1134 return 0; 1024 return 0;
1025}
1135 1026
1136 /* We end up here for the many possible ways to fail this API. */ 1027static void pcie_shutdown_notification(struct controller *ctrl)
1137abort_disable_intr: 1028{
1138 if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE)) 1029 pcie_disable_notification(ctrl);
1139 err("%s : disabling interrupts failed\n", __func__); 1030 pciehp_free_irq(ctrl);
1140abort: 1031}
1141 return -1; 1032
1033static void make_slot_name(struct slot *slot)
1034{
1035 if (pciehp_slot_with_bus)
1036 snprintf(slot->name, SLOT_NAME_SIZE, "%04d_%04d",
1037 slot->bus, slot->number);
1038 else
1039 snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number);
1040}
1041
1042static int pcie_init_slot(struct controller *ctrl)
1043{
1044 struct slot *slot;
1045
1046 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
1047 if (!slot)
1048 return -ENOMEM;
1049
1050 slot->hp_slot = 0;
1051 slot->ctrl = ctrl;
1052 slot->bus = ctrl->pci_dev->subordinate->number;
1053 slot->device = ctrl->slot_device_offset + slot->hp_slot;
1054 slot->hpc_ops = ctrl->hpc_ops;
1055 slot->number = ctrl->first_slot;
1056 make_slot_name(slot);
1057 mutex_init(&slot->lock);
1058 INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work);
1059 list_add(&slot->slot_list, &ctrl->slot_list);
1060 return 0;
1061}
1062
1063static void pcie_cleanup_slot(struct controller *ctrl)
1064{
1065 struct slot *slot;
1066 slot = list_first_entry(&ctrl->slot_list, struct slot, slot_list);
1067 list_del(&slot->slot_list);
1068 cancel_delayed_work(&slot->work);
1069 flush_scheduled_work();
1070 flush_workqueue(pciehp_wq);
1071 kfree(slot);
1142} 1072}
1143 1073
1144static inline void dbg_ctrl(struct controller *ctrl) 1074static inline void dbg_ctrl(struct controller *ctrl)
@@ -1176,15 +1106,23 @@ static inline void dbg_ctrl(struct controller *ctrl)
1176 dbg(" Comamnd Completed : %3s\n", NO_CMD_CMPL(ctrl)? "no" : "yes"); 1106 dbg(" Comamnd Completed : %3s\n", NO_CMD_CMPL(ctrl)? "no" : "yes");
1177 pciehp_readw(ctrl, SLOTSTATUS, &reg16); 1107 pciehp_readw(ctrl, SLOTSTATUS, &reg16);
1178 dbg("Slot Status : 0x%04x\n", reg16); 1108 dbg("Slot Status : 0x%04x\n", reg16);
1179 pciehp_readw(ctrl, SLOTSTATUS, &reg16); 1109 pciehp_readw(ctrl, SLOTCTRL, &reg16);
1180 dbg("Slot Control : 0x%04x\n", reg16); 1110 dbg("Slot Control : 0x%04x\n", reg16);
1181} 1111}
1182 1112
1183int pcie_init(struct controller *ctrl, struct pcie_device *dev) 1113struct controller *pcie_init(struct pcie_device *dev)
1184{ 1114{
1115 struct controller *ctrl;
1185 u32 slot_cap; 1116 u32 slot_cap;
1186 struct pci_dev *pdev = dev->port; 1117 struct pci_dev *pdev = dev->port;
1187 1118
1119 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
1120 if (!ctrl) {
1121 err("%s : out of memory\n", __func__);
1122 goto abort;
1123 }
1124 INIT_LIST_HEAD(&ctrl->slot_list);
1125
1188 ctrl->pci_dev = pdev; 1126 ctrl->pci_dev = pdev;
1189 ctrl->cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP); 1127 ctrl->cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP);
1190 if (!ctrl->cap_base) { 1128 if (!ctrl->cap_base) {
@@ -1215,15 +1153,12 @@ int pcie_init(struct controller *ctrl, struct pcie_device *dev)
1215 !(POWER_CTRL(ctrl) | ATTN_LED(ctrl) | PWR_LED(ctrl) | EMI(ctrl))) 1153 !(POWER_CTRL(ctrl) | ATTN_LED(ctrl) | PWR_LED(ctrl) | EMI(ctrl)))
1216 ctrl->no_cmd_complete = 1; 1154 ctrl->no_cmd_complete = 1;
1217 1155
1218 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", 1156 /* Clear all remaining event bits in Slot Status register */
1219 pdev->vendor, pdev->device, 1157 if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f))
1220 pdev->subsystem_vendor, pdev->subsystem_device); 1158 goto abort_ctrl;
1221 1159
1222 if (pcie_init_hardware_part1(ctrl, dev)) 1160 /* Disable sotfware notification */
1223 goto abort; 1161 pcie_disable_notification(ctrl);
1224
1225 if (pciehp_request_irq(ctrl))
1226 goto abort;
1227 1162
1228 /* 1163 /*
1229 * If this is the first controller to be initialized, 1164 * If this is the first controller to be initialized,
@@ -1231,18 +1166,39 @@ int pcie_init(struct controller *ctrl, struct pcie_device *dev)
1231 */ 1166 */
1232 if (atomic_add_return(1, &pciehp_num_controllers) == 1) { 1167 if (atomic_add_return(1, &pciehp_num_controllers) == 1) {
1233 pciehp_wq = create_singlethread_workqueue("pciehpd"); 1168 pciehp_wq = create_singlethread_workqueue("pciehpd");
1234 if (!pciehp_wq) { 1169 if (!pciehp_wq)
1235 goto abort_free_irq; 1170 goto abort_ctrl;
1236 }
1237 } 1171 }
1238 1172
1239 if (pcie_init_hardware_part2(ctrl, dev)) 1173 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n",
1240 goto abort_free_irq; 1174 pdev->vendor, pdev->device,
1175 pdev->subsystem_vendor, pdev->subsystem_device);
1176
1177 if (pcie_init_slot(ctrl))
1178 goto abort_ctrl;
1241 1179
1242 return 0; 1180 if (pcie_init_notification(ctrl))
1181 goto abort_slot;
1243 1182
1244abort_free_irq: 1183 return ctrl;
1245 pciehp_free_irq(ctrl); 1184
1185abort_slot:
1186 pcie_cleanup_slot(ctrl);
1187abort_ctrl:
1188 kfree(ctrl);
1246abort: 1189abort:
1247 return -1; 1190 return NULL;
1191}
1192
1193void pcie_release_ctrl(struct controller *ctrl)
1194{
1195 pcie_shutdown_notification(ctrl);
1196 pcie_cleanup_slot(ctrl);
1197 /*
1198 * If this is the last controller to be released, destroy the
1199 * pciehp work queue
1200 */
1201 if (atomic_dec_and_test(&pciehp_num_controllers))
1202 destroy_workqueue(pciehp_wq);
1203 kfree(ctrl);
1248} 1204}
diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c
index 779c5db71be4..a796301ea03f 100644
--- a/drivers/pci/hotplug/rpadlpar_sysfs.c
+++ b/drivers/pci/hotplug/rpadlpar_sysfs.c
@@ -14,8 +14,10 @@
14 */ 14 */
15#include <linux/kobject.h> 15#include <linux/kobject.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/pci.h>
17#include <linux/pci_hotplug.h> 18#include <linux/pci_hotplug.h>
18#include "rpadlpar.h" 19#include "rpadlpar.h"
20#include "../pci.h"
19 21
20#define DLPAR_KOBJ_NAME "control" 22#define DLPAR_KOBJ_NAME "control"
21 23
@@ -27,7 +29,6 @@
27 29
28#define MAX_DRC_NAME_LEN 64 30#define MAX_DRC_NAME_LEN 64
29 31
30
31static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr, 32static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
32 const char *buf, size_t nbytes) 33 const char *buf, size_t nbytes)
33{ 34{
@@ -112,7 +113,7 @@ int dlpar_sysfs_init(void)
112 int error; 113 int error;
113 114
114 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME, 115 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
115 &pci_hotplug_slots_kset->kobj); 116 &pci_slots_kset->kobj);
116 if (!dlpar_kobj) 117 if (!dlpar_kobj)
117 return -EINVAL; 118 return -EINVAL;
118 119
diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c
index 56197b600d36..9b714ea93d20 100644
--- a/drivers/pci/hotplug/rpaphp_slot.c
+++ b/drivers/pci/hotplug/rpaphp_slot.c
@@ -33,33 +33,6 @@
33#include <asm/rtas.h> 33#include <asm/rtas.h>
34#include "rpaphp.h" 34#include "rpaphp.h"
35 35
36static ssize_t address_read_file (struct hotplug_slot *php_slot, char *buf)
37{
38 int retval;
39 struct slot *slot = (struct slot *)php_slot->private;
40 struct pci_bus *bus;
41
42 if (!slot)
43 return -ENOENT;
44
45 bus = slot->bus;
46 if (!bus)
47 return -ENOENT;
48
49 if (bus->self)
50 retval = sprintf(buf, pci_name(bus->self));
51 else
52 retval = sprintf(buf, "%04x:%02x:00.0",
53 pci_domain_nr(bus), bus->number);
54
55 return retval;
56}
57
58static struct hotplug_slot_attribute php_attr_address = {
59 .attr = {.name = "address", .mode = S_IFREG | S_IRUGO},
60 .show = address_read_file,
61};
62
63/* free up the memory used by a slot */ 36/* free up the memory used by a slot */
64static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot) 37static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot)
65{ 38{
@@ -135,9 +108,6 @@ int rpaphp_deregister_slot(struct slot *slot)
135 108
136 list_del(&slot->rpaphp_slot_list); 109 list_del(&slot->rpaphp_slot_list);
137 110
138 /* remove "address" file */
139 sysfs_remove_file(&php_slot->kobj, &php_attr_address.attr);
140
141 retval = pci_hp_deregister(php_slot); 111 retval = pci_hp_deregister(php_slot);
142 if (retval) 112 if (retval)
143 err("Problem unregistering a slot %s\n", slot->name); 113 err("Problem unregistering a slot %s\n", slot->name);
@@ -151,6 +121,7 @@ int rpaphp_register_slot(struct slot *slot)
151{ 121{
152 struct hotplug_slot *php_slot = slot->hotplug_slot; 122 struct hotplug_slot *php_slot = slot->hotplug_slot;
153 int retval; 123 int retval;
124 int slotno;
154 125
155 dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n", 126 dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n",
156 __func__, slot->dn->full_name, slot->index, slot->name, 127 __func__, slot->dn->full_name, slot->index, slot->name,
@@ -162,19 +133,16 @@ int rpaphp_register_slot(struct slot *slot)
162 return -EAGAIN; 133 return -EAGAIN;
163 } 134 }
164 135
165 retval = pci_hp_register(php_slot); 136 if (slot->dn->child)
137 slotno = PCI_SLOT(PCI_DN(slot->dn->child)->devfn);
138 else
139 slotno = -1;
140 retval = pci_hp_register(php_slot, slot->bus, slotno);
166 if (retval) { 141 if (retval) {
167 err("pci_hp_register failed with error %d\n", retval); 142 err("pci_hp_register failed with error %d\n", retval);
168 return retval; 143 return retval;
169 } 144 }
170 145
171 /* create "address" file */
172 retval = sysfs_create_file(&php_slot->kobj, &php_attr_address.attr);
173 if (retval) {
174 err("sysfs_create_file failed with error %d\n", retval);
175 goto sysfs_fail;
176 }
177
178 /* add slot to our internal list */ 146 /* add slot to our internal list */
179 list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head); 147 list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head);
180 info("Slot [%s] registered\n", slot->name); 148 info("Slot [%s] registered\n", slot->name);
diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c
index 2fe37cd85b69..410fe0394a8e 100644
--- a/drivers/pci/hotplug/sgi_hotplug.c
+++ b/drivers/pci/hotplug/sgi_hotplug.c
@@ -197,13 +197,15 @@ static int sn_hp_slot_private_alloc(struct hotplug_slot *bss_hotplug_slot,
197static struct hotplug_slot * sn_hp_destroy(void) 197static struct hotplug_slot * sn_hp_destroy(void)
198{ 198{
199 struct slot *slot; 199 struct slot *slot;
200 struct pci_slot *pci_slot;
200 struct hotplug_slot *bss_hotplug_slot = NULL; 201 struct hotplug_slot *bss_hotplug_slot = NULL;
201 202
202 list_for_each_entry(slot, &sn_hp_list, hp_list) { 203 list_for_each_entry(slot, &sn_hp_list, hp_list) {
203 bss_hotplug_slot = slot->hotplug_slot; 204 bss_hotplug_slot = slot->hotplug_slot;
205 pci_slot = bss_hotplug_slot->pci_slot;
204 list_del(&((struct slot *)bss_hotplug_slot->private)-> 206 list_del(&((struct slot *)bss_hotplug_slot->private)->
205 hp_list); 207 hp_list);
206 sysfs_remove_file(&bss_hotplug_slot->kobj, 208 sysfs_remove_file(&pci_slot->kobj,
207 &sn_slot_path_attr.attr); 209 &sn_slot_path_attr.attr);
208 break; 210 break;
209 } 211 }
@@ -614,6 +616,7 @@ static void sn_release_slot(struct hotplug_slot *bss_hotplug_slot)
614static int sn_hotplug_slot_register(struct pci_bus *pci_bus) 616static int sn_hotplug_slot_register(struct pci_bus *pci_bus)
615{ 617{
616 int device; 618 int device;
619 struct pci_slot *pci_slot;
617 struct hotplug_slot *bss_hotplug_slot; 620 struct hotplug_slot *bss_hotplug_slot;
618 int rc = 0; 621 int rc = 0;
619 622
@@ -650,11 +653,12 @@ static int sn_hotplug_slot_register(struct pci_bus *pci_bus)
650 bss_hotplug_slot->ops = &sn_hotplug_slot_ops; 653 bss_hotplug_slot->ops = &sn_hotplug_slot_ops;
651 bss_hotplug_slot->release = &sn_release_slot; 654 bss_hotplug_slot->release = &sn_release_slot;
652 655
653 rc = pci_hp_register(bss_hotplug_slot); 656 rc = pci_hp_register(bss_hotplug_slot, pci_bus, device);
654 if (rc) 657 if (rc)
655 goto register_err; 658 goto register_err;
656 659
657 rc = sysfs_create_file(&bss_hotplug_slot->kobj, 660 pci_slot = bss_hotplug_slot->pci_slot;
661 rc = sysfs_create_file(&pci_slot->kobj,
658 &sn_slot_path_attr.attr); 662 &sn_slot_path_attr.attr);
659 if (rc) 663 if (rc)
660 goto register_err; 664 goto register_err;
@@ -664,7 +668,7 @@ static int sn_hotplug_slot_register(struct pci_bus *pci_bus)
664 668
665register_err: 669register_err:
666 dev_dbg(&pci_bus->self->dev, "bus failed to register with err = %d\n", 670 dev_dbg(&pci_bus->self->dev, "bus failed to register with err = %d\n",
667 rc); 671 rc);
668 672
669alloc_err: 673alloc_err:
670 if (rc == -ENOMEM) 674 if (rc == -ENOMEM)
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
index f66e8d6315ab..8a026f750deb 100644
--- a/drivers/pci/hotplug/shpchp.h
+++ b/drivers/pci/hotplug/shpchp.h
@@ -170,6 +170,7 @@ extern void shpchp_queue_pushbutton_work(struct work_struct *work);
170extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev); 170extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev);
171 171
172#ifdef CONFIG_ACPI 172#ifdef CONFIG_ACPI
173#include <linux/pci-acpi.h>
173static inline int get_hp_params_from_firmware(struct pci_dev *dev, 174static inline int get_hp_params_from_firmware(struct pci_dev *dev,
174 struct hotplug_params *hpp) 175 struct hotplug_params *hpp)
175{ 176{
@@ -177,14 +178,15 @@ static inline int get_hp_params_from_firmware(struct pci_dev *dev,
177 return -ENODEV; 178 return -ENODEV;
178 return 0; 179 return 0;
179} 180}
180#define get_hp_hw_control_from_firmware(pdev) \ 181
181 do { \ 182static inline int get_hp_hw_control_from_firmware(struct pci_dev *dev)
182 if (DEVICE_ACPI_HANDLE(&(pdev->dev))) \ 183{
183 acpi_run_oshp(DEVICE_ACPI_HANDLE(&(pdev->dev)));\ 184 u32 flags = OSC_SHPC_NATIVE_HP_CONTROL;
184 } while (0) 185 return acpi_get_hp_hw_control_from_firmware(dev, flags);
186}
185#else 187#else
186#define get_hp_params_from_firmware(dev, hpp) (-ENODEV) 188#define get_hp_params_from_firmware(dev, hpp) (-ENODEV)
187#define get_hp_hw_control_from_firmware(dev) do { } while (0) 189#define get_hp_hw_control_from_firmware(dev) (0)
188#endif 190#endif
189 191
190struct ctrl_reg { 192struct ctrl_reg {
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index 97848654652a..a8cbd039b85b 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -39,7 +39,7 @@
39int shpchp_debug; 39int shpchp_debug;
40int shpchp_poll_mode; 40int shpchp_poll_mode;
41int shpchp_poll_time; 41int shpchp_poll_time;
42int shpchp_slot_with_bus; 42static int shpchp_slot_with_bus;
43struct workqueue_struct *shpchp_wq; 43struct workqueue_struct *shpchp_wq;
44 44
45#define DRIVER_VERSION "0.4" 45#define DRIVER_VERSION "0.4"
@@ -68,7 +68,6 @@ static int get_power_status (struct hotplug_slot *slot, u8 *value);
68static int get_attention_status (struct hotplug_slot *slot, u8 *value); 68static int get_attention_status (struct hotplug_slot *slot, u8 *value);
69static int get_latch_status (struct hotplug_slot *slot, u8 *value); 69static int get_latch_status (struct hotplug_slot *slot, u8 *value);
70static int get_adapter_status (struct hotplug_slot *slot, u8 *value); 70static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
71static int get_address (struct hotplug_slot *slot, u32 *value);
72static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); 71static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
73static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); 72static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
74 73
@@ -81,7 +80,6 @@ static struct hotplug_slot_ops shpchp_hotplug_slot_ops = {
81 .get_attention_status = get_attention_status, 80 .get_attention_status = get_attention_status,
82 .get_latch_status = get_latch_status, 81 .get_latch_status = get_latch_status,
83 .get_adapter_status = get_adapter_status, 82 .get_adapter_status = get_adapter_status,
84 .get_address = get_address,
85 .get_max_bus_speed = get_max_bus_speed, 83 .get_max_bus_speed = get_max_bus_speed,
86 .get_cur_bus_speed = get_cur_bus_speed, 84 .get_cur_bus_speed = get_cur_bus_speed,
87}; 85};
@@ -159,7 +157,8 @@ static int init_slots(struct controller *ctrl)
159 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " 157 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
160 "slot_device_offset=%x\n", slot->bus, slot->device, 158 "slot_device_offset=%x\n", slot->bus, slot->device,
161 slot->hp_slot, slot->number, ctrl->slot_device_offset); 159 slot->hp_slot, slot->number, ctrl->slot_device_offset);
162 retval = pci_hp_register(slot->hotplug_slot); 160 retval = pci_hp_register(slot->hotplug_slot,
161 ctrl->pci_dev->subordinate, slot->device);
163 if (retval) { 162 if (retval) {
164 err("pci_hp_register failed with error %d\n", retval); 163 err("pci_hp_register failed with error %d\n", retval);
165 if (retval == -EEXIST) 164 if (retval == -EEXIST)
@@ -288,19 +287,8 @@ static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
288 return 0; 287 return 0;
289} 288}
290 289
291static int get_address (struct hotplug_slot *hotplug_slot, u32 *value) 290static int get_max_bus_speed(struct hotplug_slot *hotplug_slot,
292{ 291 enum pci_bus_speed *value)
293 struct slot *slot = get_slot(hotplug_slot);
294 struct pci_bus *bus = slot->ctrl->pci_dev->subordinate;
295
296 dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name);
297
298 *value = (pci_domain_nr(bus) << 16) | (slot->bus << 8) | slot->device;
299
300 return 0;
301}
302
303static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
304{ 292{
305 struct slot *slot = get_slot(hotplug_slot); 293 struct slot *slot = get_slot(hotplug_slot);
306 int retval; 294 int retval;
@@ -330,13 +318,14 @@ static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp
330 318
331static int is_shpc_capable(struct pci_dev *dev) 319static int is_shpc_capable(struct pci_dev *dev)
332{ 320{
333 if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device == 321 if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device ==
334 PCI_DEVICE_ID_AMD_GOLAM_7450)) 322 PCI_DEVICE_ID_AMD_GOLAM_7450))
335 return 1; 323 return 1;
336 if (pci_find_capability(dev, PCI_CAP_ID_SHPC)) 324 if (!pci_find_capability(dev, PCI_CAP_ID_SHPC))
337 return 1; 325 return 0;
338 326 if (get_hp_hw_control_from_firmware(dev))
339 return 0; 327 return 0;
328 return 1;
340} 329}
341 330
342static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 331static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c
index 7d770b2cd889..7a0bff364cd4 100644
--- a/drivers/pci/hotplug/shpchp_hpc.c
+++ b/drivers/pci/hotplug/shpchp_hpc.c
@@ -1084,7 +1084,6 @@ int shpc_init(struct controller *ctrl, struct pci_dev *pdev)
1084 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __func__, 1084 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __func__,
1085 pdev->bus->number, PCI_SLOT(pdev->devfn), 1085 pdev->bus->number, PCI_SLOT(pdev->devfn),
1086 PCI_FUNC(pdev->devfn), pdev->irq); 1086 PCI_FUNC(pdev->devfn), pdev->irq);
1087 get_hp_hw_control_from_firmware(pdev);
1088 1087
1089 /* 1088 /*
1090 * If this is the first controller to be initialized, 1089 * If this is the first controller to be initialized,
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index bb0642318a95..8d0e60ac849c 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -37,7 +37,7 @@
37#include "intel-iommu.h" 37#include "intel-iommu.h"
38#include <asm/proto.h> /* force_iommu in this header in x86-64*/ 38#include <asm/proto.h> /* force_iommu in this header in x86-64*/
39#include <asm/cacheflush.h> 39#include <asm/cacheflush.h>
40#include <asm/gart.h> 40#include <asm/iommu.h>
41#include "pci.h" 41#include "pci.h"
42 42
43#define IS_GFX_DEVICE(pdev) ((pdev->class >> 16) == PCI_BASE_CLASS_DISPLAY) 43#define IS_GFX_DEVICE(pdev) ((pdev->class >> 16) == PCI_BASE_CLASS_DISPLAY)
@@ -1748,7 +1748,6 @@ int __init init_dmars(void)
1748 deferred_flush = kzalloc(g_num_of_iommus * 1748 deferred_flush = kzalloc(g_num_of_iommus *
1749 sizeof(struct deferred_flush_tables), GFP_KERNEL); 1749 sizeof(struct deferred_flush_tables), GFP_KERNEL);
1750 if (!deferred_flush) { 1750 if (!deferred_flush) {
1751 kfree(g_iommus);
1752 ret = -ENOMEM; 1751 ret = -ENOMEM;
1753 goto error; 1752 goto error;
1754 } 1753 }
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 8c61304cbb37..15af618d36e2 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -70,12 +70,10 @@ arch_teardown_msi_irqs(struct pci_dev *dev)
70 } 70 }
71} 71}
72 72
73static void msi_set_enable(struct pci_dev *dev, int enable) 73static void __msi_set_enable(struct pci_dev *dev, int pos, int enable)
74{ 74{
75 int pos;
76 u16 control; 75 u16 control;
77 76
78 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
79 if (pos) { 77 if (pos) {
80 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); 78 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control);
81 control &= ~PCI_MSI_FLAGS_ENABLE; 79 control &= ~PCI_MSI_FLAGS_ENABLE;
@@ -85,6 +83,11 @@ static void msi_set_enable(struct pci_dev *dev, int enable)
85 } 83 }
86} 84}
87 85
86static void msi_set_enable(struct pci_dev *dev, int enable)
87{
88 __msi_set_enable(dev, pci_find_capability(dev, PCI_CAP_ID_MSI), enable);
89}
90
88static void msix_set_enable(struct pci_dev *dev, int enable) 91static void msix_set_enable(struct pci_dev *dev, int enable)
89{ 92{
90 int pos; 93 int pos;
@@ -141,7 +144,8 @@ static void msi_set_mask_bits(unsigned int irq, u32 mask, u32 flag)
141 mask_bits |= flag & mask; 144 mask_bits |= flag & mask;
142 pci_write_config_dword(entry->dev, pos, mask_bits); 145 pci_write_config_dword(entry->dev, pos, mask_bits);
143 } else { 146 } else {
144 msi_set_enable(entry->dev, !flag); 147 __msi_set_enable(entry->dev, entry->msi_attrib.pos,
148 !flag);
145 } 149 }
146 break; 150 break;
147 case PCI_CAP_ID_MSIX: 151 case PCI_CAP_ID_MSIX:
@@ -561,9 +565,8 @@ int pci_enable_msi(struct pci_dev* dev)
561 565
562 /* Check whether driver already requested for MSI-X irqs */ 566 /* Check whether driver already requested for MSI-X irqs */
563 if (dev->msix_enabled) { 567 if (dev->msix_enabled) {
564 printk(KERN_INFO "PCI: %s: Can't enable MSI. " 568 dev_info(&dev->dev, "can't enable MSI "
565 "Device already has MSI-X enabled\n", 569 "(MSI-X already enabled)\n");
566 pci_name(dev));
567 return -EINVAL; 570 return -EINVAL;
568 } 571 }
569 status = msi_capability_init(dev); 572 status = msi_capability_init(dev);
@@ -686,9 +689,8 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
686 689
687 /* Check whether driver already requested for MSI irq */ 690 /* Check whether driver already requested for MSI irq */
688 if (dev->msi_enabled) { 691 if (dev->msi_enabled) {
689 printk(KERN_INFO "PCI: %s: Can't enable MSI-X. " 692 dev_info(&dev->dev, "can't enable MSI-X "
690 "Device already has an MSI irq assigned\n", 693 "(MSI IRQ already assigned)\n");
691 pci_name(dev));
692 return -EINVAL; 694 return -EINVAL;
693 } 695 }
694 status = msix_capability_init(dev, entries, nvec); 696 status = msix_capability_init(dev, entries, nvec);
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 9d6fc8e6285d..7764768b6a0e 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -21,12 +21,19 @@
21 21
22struct acpi_osc_data { 22struct acpi_osc_data {
23 acpi_handle handle; 23 acpi_handle handle;
24 u32 ctrlset_buf[3]; 24 u32 support_set;
25 u32 global_ctrlsets; 25 u32 control_set;
26 int is_queried;
27 u32 query_result;
26 struct list_head sibiling; 28 struct list_head sibiling;
27}; 29};
28static LIST_HEAD(acpi_osc_data_list); 30static LIST_HEAD(acpi_osc_data_list);
29 31
32struct acpi_osc_args {
33 u32 capbuf[3];
34 u32 query_result;
35};
36
30static struct acpi_osc_data *acpi_get_osc_data(acpi_handle handle) 37static struct acpi_osc_data *acpi_get_osc_data(acpi_handle handle)
31{ 38{
32 struct acpi_osc_data *data; 39 struct acpi_osc_data *data;
@@ -44,42 +51,18 @@ static struct acpi_osc_data *acpi_get_osc_data(acpi_handle handle)
44 return data; 51 return data;
45} 52}
46 53
47static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40, 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66}; 54static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40,
55 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66};
48 56
49static acpi_status 57static acpi_status acpi_run_osc(acpi_handle handle,
50acpi_query_osc ( 58 struct acpi_osc_args *osc_args)
51 acpi_handle handle,
52 u32 level,
53 void *context,
54 void **retval )
55{ 59{
56 acpi_status status; 60 acpi_status status;
57 struct acpi_object_list input; 61 struct acpi_object_list input;
58 union acpi_object in_params[4]; 62 union acpi_object in_params[4];
59 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; 63 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
60 union acpi_object *out_obj; 64 union acpi_object *out_obj;
61 u32 osc_dw0; 65 u32 osc_dw0, flags = osc_args->capbuf[OSC_QUERY_TYPE];
62 acpi_status *ret_status = (acpi_status *)retval;
63 struct acpi_osc_data *osc_data;
64 u32 flags = (unsigned long)context, temp;
65 acpi_handle tmp;
66
67 status = acpi_get_handle(handle, "_OSC", &tmp);
68 if (ACPI_FAILURE(status))
69 return status;
70
71 osc_data = acpi_get_osc_data(handle);
72 if (!osc_data) {
73 printk(KERN_ERR "acpi osc data array is full\n");
74 return AE_ERROR;
75 }
76
77 osc_data->ctrlset_buf[OSC_SUPPORT_TYPE] |= (flags & OSC_SUPPORT_MASKS);
78
79 /* do _OSC query for all possible controls */
80 temp = osc_data->ctrlset_buf[OSC_CONTROL_TYPE];
81 osc_data->ctrlset_buf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
82 osc_data->ctrlset_buf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS;
83 66
84 /* Setting up input parameters */ 67 /* Setting up input parameters */
85 input.count = 4; 68 input.count = 4;
@@ -93,20 +76,19 @@ acpi_query_osc (
93 in_params[2].integer.value = 3; 76 in_params[2].integer.value = 3;
94 in_params[3].type = ACPI_TYPE_BUFFER; 77 in_params[3].type = ACPI_TYPE_BUFFER;
95 in_params[3].buffer.length = 12; 78 in_params[3].buffer.length = 12;
96 in_params[3].buffer.pointer = (u8 *)osc_data->ctrlset_buf; 79 in_params[3].buffer.pointer = (u8 *)osc_args->capbuf;
97 80
98 status = acpi_evaluate_object(handle, "_OSC", &input, &output); 81 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
99 if (ACPI_FAILURE(status)) 82 if (ACPI_FAILURE(status))
100 goto out_nofree; 83 return status;
101 out_obj = output.pointer;
102 84
85 out_obj = output.pointer;
103 if (out_obj->type != ACPI_TYPE_BUFFER) { 86 if (out_obj->type != ACPI_TYPE_BUFFER) {
104 printk(KERN_DEBUG 87 printk(KERN_DEBUG "Evaluate _OSC returns wrong type\n");
105 "Evaluate _OSC returns wrong type\n");
106 status = AE_TYPE; 88 status = AE_TYPE;
107 goto query_osc_out; 89 goto out_kfree;
108 } 90 }
109 osc_dw0 = *((u32 *) out_obj->buffer.pointer); 91 osc_dw0 = *((u32 *)out_obj->buffer.pointer);
110 if (osc_dw0) { 92 if (osc_dw0) {
111 if (osc_dw0 & OSC_REQUEST_ERROR) 93 if (osc_dw0 & OSC_REQUEST_ERROR)
112 printk(KERN_DEBUG "_OSC request fails\n"); 94 printk(KERN_DEBUG "_OSC request fails\n");
@@ -115,93 +97,58 @@ acpi_query_osc (
115 if (osc_dw0 & OSC_INVALID_REVISION_ERROR) 97 if (osc_dw0 & OSC_INVALID_REVISION_ERROR)
116 printk(KERN_DEBUG "_OSC invalid revision\n"); 98 printk(KERN_DEBUG "_OSC invalid revision\n");
117 if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) { 99 if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) {
118 /* Update Global Control Set */ 100 if (flags & OSC_QUERY_ENABLE)
119 osc_data->global_ctrlsets = 101 goto out_success;
120 *((u32 *)(out_obj->buffer.pointer + 8)); 102 printk(KERN_DEBUG "_OSC FW not grant req. control\n");
121 status = AE_OK; 103 status = AE_SUPPORT;
122 goto query_osc_out; 104 goto out_kfree;
123 } 105 }
124 status = AE_ERROR; 106 status = AE_ERROR;
125 goto query_osc_out; 107 goto out_kfree;
126 } 108 }
127 109out_success:
128 /* Update Global Control Set */ 110 if (flags & OSC_QUERY_ENABLE)
129 osc_data->global_ctrlsets = *((u32 *)(out_obj->buffer.pointer + 8)); 111 osc_args->query_result =
112 *((u32 *)(out_obj->buffer.pointer + 8));
130 status = AE_OK; 113 status = AE_OK;
131 114
132query_osc_out: 115out_kfree:
133 kfree(output.pointer); 116 kfree(output.pointer);
134out_nofree:
135 *ret_status = status;
136
137 osc_data->ctrlset_buf[OSC_QUERY_TYPE] = !OSC_QUERY_ENABLE;
138 osc_data->ctrlset_buf[OSC_CONTROL_TYPE] = temp;
139 if (ACPI_FAILURE(status)) {
140 /* no osc support at all */
141 osc_data->ctrlset_buf[OSC_SUPPORT_TYPE] = 0;
142 }
143
144 return status; 117 return status;
145} 118}
146 119
147 120static acpi_status acpi_query_osc(acpi_handle handle,
148static acpi_status 121 u32 level, void *context, void **retval)
149acpi_run_osc (
150 acpi_handle handle,
151 void *context)
152{ 122{
153 acpi_status status; 123 acpi_status status;
154 struct acpi_object_list input; 124 struct acpi_osc_data *osc_data;
155 union acpi_object in_params[4]; 125 u32 flags = (unsigned long)context, support_set;
156 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; 126 acpi_handle tmp;
157 union acpi_object *out_obj; 127 struct acpi_osc_args osc_args;
158 u32 osc_dw0;
159
160 /* Setting up input parameters */
161 input.count = 4;
162 input.pointer = in_params;
163 in_params[0].type = ACPI_TYPE_BUFFER;
164 in_params[0].buffer.length = 16;
165 in_params[0].buffer.pointer = OSC_UUID;
166 in_params[1].type = ACPI_TYPE_INTEGER;
167 in_params[1].integer.value = 1;
168 in_params[2].type = ACPI_TYPE_INTEGER;
169 in_params[2].integer.value = 3;
170 in_params[3].type = ACPI_TYPE_BUFFER;
171 in_params[3].buffer.length = 12;
172 in_params[3].buffer.pointer = (u8 *)context;
173 128
174 status = acpi_evaluate_object(handle, "_OSC", &input, &output); 129 status = acpi_get_handle(handle, "_OSC", &tmp);
175 if (ACPI_FAILURE (status)) 130 if (ACPI_FAILURE(status))
176 return status; 131 return status;
177 132
178 out_obj = output.pointer; 133 osc_data = acpi_get_osc_data(handle);
179 if (out_obj->type != ACPI_TYPE_BUFFER) { 134 if (!osc_data) {
180 printk(KERN_DEBUG 135 printk(KERN_ERR "acpi osc data array is full\n");
181 "Evaluate _OSC returns wrong type\n"); 136 return AE_ERROR;
182 status = AE_TYPE;
183 goto run_osc_out;
184 } 137 }
185 osc_dw0 = *((u32 *) out_obj->buffer.pointer); 138
186 if (osc_dw0) { 139 /* do _OSC query for all possible controls */
187 if (osc_dw0 & OSC_REQUEST_ERROR) 140 support_set = osc_data->support_set | (flags & OSC_SUPPORT_MASKS);
188 printk(KERN_DEBUG "_OSC request fails\n"); 141 osc_args.capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
189 if (osc_dw0 & OSC_INVALID_UUID_ERROR) 142 osc_args.capbuf[OSC_SUPPORT_TYPE] = support_set;
190 printk(KERN_DEBUG "_OSC invalid UUID\n"); 143 osc_args.capbuf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS;
191 if (osc_dw0 & OSC_INVALID_REVISION_ERROR) 144
192 printk(KERN_DEBUG "_OSC invalid revision\n"); 145 status = acpi_run_osc(handle, &osc_args);
193 if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) { 146 if (ACPI_SUCCESS(status)) {
194 printk(KERN_DEBUG "_OSC FW not grant req. control\n"); 147 osc_data->support_set = support_set;
195 status = AE_SUPPORT; 148 osc_data->query_result = osc_args.query_result;
196 goto run_osc_out; 149 osc_data->is_queried = 1;
197 }
198 status = AE_ERROR;
199 goto run_osc_out;
200 } 150 }
201 status = AE_OK;
202 151
203run_osc_out:
204 kfree(output.pointer);
205 return status; 152 return status;
206} 153}
207 154
@@ -215,15 +162,11 @@ run_osc_out:
215 **/ 162 **/
216acpi_status __pci_osc_support_set(u32 flags, const char *hid) 163acpi_status __pci_osc_support_set(u32 flags, const char *hid)
217{ 164{
218 acpi_status retval = AE_NOT_FOUND; 165 if (!(flags & OSC_SUPPORT_MASKS))
219
220 if (!(flags & OSC_SUPPORT_MASKS)) {
221 return AE_TYPE; 166 return AE_TYPE;
222 } 167
223 acpi_get_devices(hid, 168 acpi_get_devices(hid, acpi_query_osc,
224 acpi_query_osc, 169 (void *)(unsigned long)flags, NULL);
225 (void *)(unsigned long)flags,
226 (void **) &retval );
227 return AE_OK; 170 return AE_OK;
228} 171}
229 172
@@ -236,10 +179,11 @@ acpi_status __pci_osc_support_set(u32 flags, const char *hid)
236 **/ 179 **/
237acpi_status pci_osc_control_set(acpi_handle handle, u32 flags) 180acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
238{ 181{
239 acpi_status status; 182 acpi_status status;
240 u32 ctrlset; 183 u32 ctrlset, control_set;
241 acpi_handle tmp; 184 acpi_handle tmp;
242 struct acpi_osc_data *osc_data; 185 struct acpi_osc_data *osc_data;
186 struct acpi_osc_args osc_args;
243 187
244 status = acpi_get_handle(handle, "_OSC", &tmp); 188 status = acpi_get_handle(handle, "_OSC", &tmp);
245 if (ACPI_FAILURE(status)) 189 if (ACPI_FAILURE(status))
@@ -252,24 +196,25 @@ acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
252 } 196 }
253 197
254 ctrlset = (flags & OSC_CONTROL_MASKS); 198 ctrlset = (flags & OSC_CONTROL_MASKS);
255 if (!ctrlset) { 199 if (!ctrlset)
256 return AE_TYPE; 200 return AE_TYPE;
257 } 201
258 if (osc_data->ctrlset_buf[OSC_SUPPORT_TYPE] && 202 if (osc_data->is_queried &&
259 ((osc_data->global_ctrlsets & ctrlset) != ctrlset)) { 203 ((osc_data->query_result & ctrlset) != ctrlset))
260 return AE_SUPPORT; 204 return AE_SUPPORT;
261 } 205
262 osc_data->ctrlset_buf[OSC_CONTROL_TYPE] |= ctrlset; 206 control_set = osc_data->control_set | ctrlset;
263 status = acpi_run_osc(handle, osc_data->ctrlset_buf); 207 osc_args.capbuf[OSC_QUERY_TYPE] = 0;
264 if (ACPI_FAILURE (status)) { 208 osc_args.capbuf[OSC_SUPPORT_TYPE] = osc_data->support_set;
265 osc_data->ctrlset_buf[OSC_CONTROL_TYPE] &= ~ctrlset; 209 osc_args.capbuf[OSC_CONTROL_TYPE] = control_set;
266 } 210 status = acpi_run_osc(handle, &osc_args);
267 211 if (ACPI_SUCCESS(status))
212 osc_data->control_set = control_set;
213
268 return status; 214 return status;
269} 215}
270EXPORT_SYMBOL(pci_osc_control_set); 216EXPORT_SYMBOL(pci_osc_control_set);
271 217
272#ifdef CONFIG_ACPI_SLEEP
273/* 218/*
274 * _SxD returns the D-state with the highest power 219 * _SxD returns the D-state with the highest power
275 * (lowest D-state number) supported in the S-state "x". 220 * (lowest D-state number) supported in the S-state "x".
@@ -293,13 +238,11 @@ EXPORT_SYMBOL(pci_osc_control_set);
293 * choose highest power _SxD or any lower power 238 * choose highest power _SxD or any lower power
294 */ 239 */
295 240
296static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev, 241static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
297 pm_message_t state)
298{ 242{
299 int acpi_state; 243 int acpi_state;
300 244
301 acpi_state = acpi_pm_device_sleep_state(&pdev->dev, 245 acpi_state = acpi_pm_device_sleep_state(&pdev->dev, NULL);
302 device_may_wakeup(&pdev->dev), NULL);
303 if (acpi_state < 0) 246 if (acpi_state < 0)
304 return PCI_POWER_ERROR; 247 return PCI_POWER_ERROR;
305 248
@@ -315,7 +258,13 @@ static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev,
315 } 258 }
316 return PCI_POWER_ERROR; 259 return PCI_POWER_ERROR;
317} 260}
318#endif 261
262static bool acpi_pci_power_manageable(struct pci_dev *dev)
263{
264 acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
265
266 return handle ? acpi_bus_power_manageable(handle) : false;
267}
319 268
320static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) 269static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
321{ 270{
@@ -328,12 +277,11 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
328 [PCI_D3hot] = ACPI_STATE_D3, 277 [PCI_D3hot] = ACPI_STATE_D3,
329 [PCI_D3cold] = ACPI_STATE_D3 278 [PCI_D3cold] = ACPI_STATE_D3
330 }; 279 };
280 int error = -EINVAL;
331 281
332 if (!handle)
333 return -ENODEV;
334 /* If the ACPI device has _EJ0, ignore the device */ 282 /* If the ACPI device has _EJ0, ignore the device */
335 if (ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp))) 283 if (!handle || ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp)))
336 return 0; 284 return -ENODEV;
337 285
338 switch (state) { 286 switch (state) {
339 case PCI_D0: 287 case PCI_D0:
@@ -341,11 +289,41 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
341 case PCI_D2: 289 case PCI_D2:
342 case PCI_D3hot: 290 case PCI_D3hot:
343 case PCI_D3cold: 291 case PCI_D3cold:
344 return acpi_bus_set_power(handle, state_conv[state]); 292 error = acpi_bus_set_power(handle, state_conv[state]);
345 } 293 }
346 return -EINVAL; 294
295 if (!error)
296 dev_printk(KERN_INFO, &dev->dev,
297 "power state changed by ACPI to D%d\n", state);
298
299 return error;
300}
301
302static bool acpi_pci_can_wakeup(struct pci_dev *dev)
303{
304 acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
305
306 return handle ? acpi_bus_can_wakeup(handle) : false;
307}
308
309static int acpi_pci_sleep_wake(struct pci_dev *dev, bool enable)
310{
311 int error = acpi_pm_device_sleep_wake(&dev->dev, enable);
312
313 if (!error)
314 dev_printk(KERN_INFO, &dev->dev,
315 "wake-up capability %s by ACPI\n",
316 enable ? "enabled" : "disabled");
317 return error;
347} 318}
348 319
320static struct pci_platform_pm_ops acpi_pci_platform_pm = {
321 .is_manageable = acpi_pci_power_manageable,
322 .set_state = acpi_pci_set_power_state,
323 .choose_state = acpi_pci_choose_state,
324 .can_wakeup = acpi_pci_can_wakeup,
325 .sleep_wake = acpi_pci_sleep_wake,
326};
349 327
350/* ACPI bus type */ 328/* ACPI bus type */
351static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) 329static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
@@ -397,10 +375,7 @@ static int __init acpi_pci_init(void)
397 ret = register_acpi_bus_type(&acpi_pci_bus); 375 ret = register_acpi_bus_type(&acpi_pci_bus);
398 if (ret) 376 if (ret)
399 return 0; 377 return 0;
400#ifdef CONFIG_ACPI_SLEEP 378 pci_set_platform_pm(&acpi_pci_platform_pm);
401 platform_pci_choose_state = acpi_pci_choose_state;
402#endif
403 platform_pci_set_power_state = acpi_pci_set_power_state;
404 return 0; 379 return 0;
405} 380}
406arch_initcall(acpi_pci_init); 381arch_initcall(acpi_pci_init);
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index e1637bd82b8e..a13f53486114 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -274,7 +274,57 @@ static int pci_device_remove(struct device * dev)
274 return 0; 274 return 0;
275} 275}
276 276
277static int pci_device_suspend(struct device * dev, pm_message_t state) 277static void pci_device_shutdown(struct device *dev)
278{
279 struct pci_dev *pci_dev = to_pci_dev(dev);
280 struct pci_driver *drv = pci_dev->driver;
281
282 if (drv && drv->shutdown)
283 drv->shutdown(pci_dev);
284 pci_msi_shutdown(pci_dev);
285 pci_msix_shutdown(pci_dev);
286}
287
288#ifdef CONFIG_PM_SLEEP
289
290/*
291 * Default "suspend" method for devices that have no driver provided suspend,
292 * or not even a driver at all.
293 */
294static void pci_default_pm_suspend(struct pci_dev *pci_dev)
295{
296 pci_save_state(pci_dev);
297 /*
298 * mark its power state as "unknown", since we don't know if
299 * e.g. the BIOS will change its device state when we suspend.
300 */
301 if (pci_dev->current_state == PCI_D0)
302 pci_dev->current_state = PCI_UNKNOWN;
303}
304
305/*
306 * Default "resume" method for devices that have no driver provided resume,
307 * or not even a driver at all.
308 */
309static int pci_default_pm_resume(struct pci_dev *pci_dev)
310{
311 int retval = 0;
312
313 /* restore the PCI config space */
314 pci_restore_state(pci_dev);
315 /* if the device was enabled before suspend, reenable */
316 retval = pci_reenable_device(pci_dev);
317 /*
318 * if the device was busmaster before the suspend, make it busmaster
319 * again
320 */
321 if (pci_dev->is_busmaster)
322 pci_set_master(pci_dev);
323
324 return retval;
325}
326
327static int pci_legacy_suspend(struct device *dev, pm_message_t state)
278{ 328{
279 struct pci_dev * pci_dev = to_pci_dev(dev); 329 struct pci_dev * pci_dev = to_pci_dev(dev);
280 struct pci_driver * drv = pci_dev->driver; 330 struct pci_driver * drv = pci_dev->driver;
@@ -284,18 +334,12 @@ static int pci_device_suspend(struct device * dev, pm_message_t state)
284 i = drv->suspend(pci_dev, state); 334 i = drv->suspend(pci_dev, state);
285 suspend_report_result(drv->suspend, i); 335 suspend_report_result(drv->suspend, i);
286 } else { 336 } else {
287 pci_save_state(pci_dev); 337 pci_default_pm_suspend(pci_dev);
288 /*
289 * mark its power state as "unknown", since we don't know if
290 * e.g. the BIOS will change its device state when we suspend.
291 */
292 if (pci_dev->current_state == PCI_D0)
293 pci_dev->current_state = PCI_UNKNOWN;
294 } 338 }
295 return i; 339 return i;
296} 340}
297 341
298static int pci_device_suspend_late(struct device * dev, pm_message_t state) 342static int pci_legacy_suspend_late(struct device *dev, pm_message_t state)
299{ 343{
300 struct pci_dev * pci_dev = to_pci_dev(dev); 344 struct pci_dev * pci_dev = to_pci_dev(dev);
301 struct pci_driver * drv = pci_dev->driver; 345 struct pci_driver * drv = pci_dev->driver;
@@ -308,26 +352,7 @@ static int pci_device_suspend_late(struct device * dev, pm_message_t state)
308 return i; 352 return i;
309} 353}
310 354
311/* 355static int pci_legacy_resume(struct device *dev)
312 * Default resume method for devices that have no driver provided resume,
313 * or not even a driver at all.
314 */
315static int pci_default_resume(struct pci_dev *pci_dev)
316{
317 int retval = 0;
318
319 /* restore the PCI config space */
320 pci_restore_state(pci_dev);
321 /* if the device was enabled before suspend, reenable */
322 retval = pci_reenable_device(pci_dev);
323 /* if the device was busmaster before the suspend, make it busmaster again */
324 if (pci_dev->is_busmaster)
325 pci_set_master(pci_dev);
326
327 return retval;
328}
329
330static int pci_device_resume(struct device * dev)
331{ 356{
332 int error; 357 int error;
333 struct pci_dev * pci_dev = to_pci_dev(dev); 358 struct pci_dev * pci_dev = to_pci_dev(dev);
@@ -336,34 +361,313 @@ static int pci_device_resume(struct device * dev)
336 if (drv && drv->resume) 361 if (drv && drv->resume)
337 error = drv->resume(pci_dev); 362 error = drv->resume(pci_dev);
338 else 363 else
339 error = pci_default_resume(pci_dev); 364 error = pci_default_pm_resume(pci_dev);
340 return error; 365 return error;
341} 366}
342 367
343static int pci_device_resume_early(struct device * dev) 368static int pci_legacy_resume_early(struct device *dev)
344{ 369{
345 int error = 0; 370 int error = 0;
346 struct pci_dev * pci_dev = to_pci_dev(dev); 371 struct pci_dev * pci_dev = to_pci_dev(dev);
347 struct pci_driver * drv = pci_dev->driver; 372 struct pci_driver * drv = pci_dev->driver;
348 373
349 pci_fixup_device(pci_fixup_resume, pci_dev);
350
351 if (drv && drv->resume_early) 374 if (drv && drv->resume_early)
352 error = drv->resume_early(pci_dev); 375 error = drv->resume_early(pci_dev);
353 return error; 376 return error;
354} 377}
355 378
356static void pci_device_shutdown(struct device *dev) 379static int pci_pm_prepare(struct device *dev)
380{
381 struct device_driver *drv = dev->driver;
382 int error = 0;
383
384 if (drv && drv->pm && drv->pm->prepare)
385 error = drv->pm->prepare(dev);
386
387 return error;
388}
389
390static void pci_pm_complete(struct device *dev)
391{
392 struct device_driver *drv = dev->driver;
393
394 if (drv && drv->pm && drv->pm->complete)
395 drv->pm->complete(dev);
396}
397
398#ifdef CONFIG_SUSPEND
399
400static int pci_pm_suspend(struct device *dev)
401{
402 struct pci_dev *pci_dev = to_pci_dev(dev);
403 struct device_driver *drv = dev->driver;
404 int error = 0;
405
406 if (drv && drv->pm) {
407 if (drv->pm->suspend) {
408 error = drv->pm->suspend(dev);
409 suspend_report_result(drv->pm->suspend, error);
410 } else {
411 pci_default_pm_suspend(pci_dev);
412 }
413 } else {
414 error = pci_legacy_suspend(dev, PMSG_SUSPEND);
415 }
416 pci_fixup_device(pci_fixup_suspend, pci_dev);
417
418 return error;
419}
420
421static int pci_pm_suspend_noirq(struct device *dev)
357{ 422{
358 struct pci_dev *pci_dev = to_pci_dev(dev); 423 struct pci_dev *pci_dev = to_pci_dev(dev);
359 struct pci_driver *drv = pci_dev->driver; 424 struct pci_driver *drv = pci_dev->driver;
425 int error = 0;
360 426
361 if (drv && drv->shutdown) 427 if (drv && drv->pm) {
362 drv->shutdown(pci_dev); 428 if (drv->pm->suspend_noirq) {
363 pci_msi_shutdown(pci_dev); 429 error = drv->pm->suspend_noirq(dev);
364 pci_msix_shutdown(pci_dev); 430 suspend_report_result(drv->pm->suspend_noirq, error);
431 }
432 } else {
433 error = pci_legacy_suspend_late(dev, PMSG_SUSPEND);
434 }
435
436 return error;
365} 437}
366 438
439static int pci_pm_resume(struct device *dev)
440{
441 struct pci_dev *pci_dev = to_pci_dev(dev);
442 struct device_driver *drv = dev->driver;
443 int error;
444
445 pci_fixup_device(pci_fixup_resume, pci_dev);
446
447 if (drv && drv->pm) {
448 error = drv->pm->resume ? drv->pm->resume(dev) :
449 pci_default_pm_resume(pci_dev);
450 } else {
451 error = pci_legacy_resume(dev);
452 }
453
454 return error;
455}
456
457static int pci_pm_resume_noirq(struct device *dev)
458{
459 struct pci_dev *pci_dev = to_pci_dev(dev);
460 struct pci_driver *drv = pci_dev->driver;
461 int error = 0;
462
463 pci_fixup_device(pci_fixup_resume_early, pci_dev);
464
465 if (drv && drv->pm) {
466 if (drv->pm->resume_noirq)
467 error = drv->pm->resume_noirq(dev);
468 } else {
469 error = pci_legacy_resume_early(dev);
470 }
471
472 return error;
473}
474
475#else /* !CONFIG_SUSPEND */
476
477#define pci_pm_suspend NULL
478#define pci_pm_suspend_noirq NULL
479#define pci_pm_resume NULL
480#define pci_pm_resume_noirq NULL
481
482#endif /* !CONFIG_SUSPEND */
483
484#ifdef CONFIG_HIBERNATION
485
486static int pci_pm_freeze(struct device *dev)
487{
488 struct pci_dev *pci_dev = to_pci_dev(dev);
489 struct device_driver *drv = dev->driver;
490 int error = 0;
491
492 if (drv && drv->pm) {
493 if (drv->pm->freeze) {
494 error = drv->pm->freeze(dev);
495 suspend_report_result(drv->pm->freeze, error);
496 } else {
497 pci_default_pm_suspend(pci_dev);
498 }
499 } else {
500 error = pci_legacy_suspend(dev, PMSG_FREEZE);
501 pci_fixup_device(pci_fixup_suspend, pci_dev);
502 }
503
504 return error;
505}
506
507static int pci_pm_freeze_noirq(struct device *dev)
508{
509 struct pci_dev *pci_dev = to_pci_dev(dev);
510 struct pci_driver *drv = pci_dev->driver;
511 int error = 0;
512
513 if (drv && drv->pm) {
514 if (drv->pm->freeze_noirq) {
515 error = drv->pm->freeze_noirq(dev);
516 suspend_report_result(drv->pm->freeze_noirq, error);
517 }
518 } else {
519 error = pci_legacy_suspend_late(dev, PMSG_FREEZE);
520 }
521
522 return error;
523}
524
525static int pci_pm_thaw(struct device *dev)
526{
527 struct device_driver *drv = dev->driver;
528 int error = 0;
529
530 if (drv && drv->pm) {
531 if (drv->pm->thaw)
532 error = drv->pm->thaw(dev);
533 } else {
534 pci_fixup_device(pci_fixup_resume, to_pci_dev(dev));
535 error = pci_legacy_resume(dev);
536 }
537
538 return error;
539}
540
541static int pci_pm_thaw_noirq(struct device *dev)
542{
543 struct pci_dev *pci_dev = to_pci_dev(dev);
544 struct pci_driver *drv = pci_dev->driver;
545 int error = 0;
546
547 if (drv && drv->pm) {
548 if (drv->pm->thaw_noirq)
549 error = drv->pm->thaw_noirq(dev);
550 } else {
551 pci_fixup_device(pci_fixup_resume_early, pci_dev);
552 error = pci_legacy_resume_early(dev);
553 }
554
555 return error;
556}
557
558static int pci_pm_poweroff(struct device *dev)
559{
560 struct device_driver *drv = dev->driver;
561 int error = 0;
562
563 pci_fixup_device(pci_fixup_suspend, to_pci_dev(dev));
564
565 if (drv && drv->pm) {
566 if (drv->pm->poweroff) {
567 error = drv->pm->poweroff(dev);
568 suspend_report_result(drv->pm->poweroff, error);
569 }
570 } else {
571 error = pci_legacy_suspend(dev, PMSG_HIBERNATE);
572 }
573
574 return error;
575}
576
577static int pci_pm_poweroff_noirq(struct device *dev)
578{
579 struct pci_dev *pci_dev = to_pci_dev(dev);
580 struct pci_driver *drv = pci_dev->driver;
581 int error = 0;
582
583 if (drv && drv->pm) {
584 if (drv->pm->poweroff_noirq) {
585 error = drv->pm->poweroff_noirq(dev);
586 suspend_report_result(drv->pm->poweroff_noirq, error);
587 }
588 } else {
589 error = pci_legacy_suspend_late(dev, PMSG_HIBERNATE);
590 }
591
592 return error;
593}
594
595static int pci_pm_restore(struct device *dev)
596{
597 struct pci_dev *pci_dev = to_pci_dev(dev);
598 struct device_driver *drv = dev->driver;
599 int error;
600
601 if (drv && drv->pm) {
602 error = drv->pm->restore ? drv->pm->restore(dev) :
603 pci_default_pm_resume(pci_dev);
604 } else {
605 error = pci_legacy_resume(dev);
606 }
607 pci_fixup_device(pci_fixup_resume, pci_dev);
608
609 return error;
610}
611
612static int pci_pm_restore_noirq(struct device *dev)
613{
614 struct pci_dev *pci_dev = to_pci_dev(dev);
615 struct pci_driver *drv = pci_dev->driver;
616 int error = 0;
617
618 pci_fixup_device(pci_fixup_resume, pci_dev);
619
620 if (drv && drv->pm) {
621 if (drv->pm->restore_noirq)
622 error = drv->pm->restore_noirq(dev);
623 } else {
624 error = pci_legacy_resume_early(dev);
625 }
626 pci_fixup_device(pci_fixup_resume_early, pci_dev);
627
628 return error;
629}
630
631#else /* !CONFIG_HIBERNATION */
632
633#define pci_pm_freeze NULL
634#define pci_pm_freeze_noirq NULL
635#define pci_pm_thaw NULL
636#define pci_pm_thaw_noirq NULL
637#define pci_pm_poweroff NULL
638#define pci_pm_poweroff_noirq NULL
639#define pci_pm_restore NULL
640#define pci_pm_restore_noirq NULL
641
642#endif /* !CONFIG_HIBERNATION */
643
644struct pm_ext_ops pci_pm_ops = {
645 .base = {
646 .prepare = pci_pm_prepare,
647 .complete = pci_pm_complete,
648 .suspend = pci_pm_suspend,
649 .resume = pci_pm_resume,
650 .freeze = pci_pm_freeze,
651 .thaw = pci_pm_thaw,
652 .poweroff = pci_pm_poweroff,
653 .restore = pci_pm_restore,
654 },
655 .suspend_noirq = pci_pm_suspend_noirq,
656 .resume_noirq = pci_pm_resume_noirq,
657 .freeze_noirq = pci_pm_freeze_noirq,
658 .thaw_noirq = pci_pm_thaw_noirq,
659 .poweroff_noirq = pci_pm_poweroff_noirq,
660 .restore_noirq = pci_pm_restore_noirq,
661};
662
663#define PCI_PM_OPS_PTR &pci_pm_ops
664
665#else /* !CONFIG_PM_SLEEP */
666
667#define PCI_PM_OPS_PTR NULL
668
669#endif /* !CONFIG_PM_SLEEP */
670
367/** 671/**
368 * __pci_register_driver - register a new pci driver 672 * __pci_register_driver - register a new pci driver
369 * @drv: the driver structure to register 673 * @drv: the driver structure to register
@@ -386,6 +690,9 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner,
386 drv->driver.owner = owner; 690 drv->driver.owner = owner;
387 drv->driver.mod_name = mod_name; 691 drv->driver.mod_name = mod_name;
388 692
693 if (drv->pm)
694 drv->driver.pm = &drv->pm->base;
695
389 spin_lock_init(&drv->dynids.lock); 696 spin_lock_init(&drv->dynids.lock);
390 INIT_LIST_HEAD(&drv->dynids.list); 697 INIT_LIST_HEAD(&drv->dynids.list);
391 698
@@ -511,12 +818,9 @@ struct bus_type pci_bus_type = {
511 .uevent = pci_uevent, 818 .uevent = pci_uevent,
512 .probe = pci_device_probe, 819 .probe = pci_device_probe,
513 .remove = pci_device_remove, 820 .remove = pci_device_remove,
514 .suspend = pci_device_suspend,
515 .suspend_late = pci_device_suspend_late,
516 .resume_early = pci_device_resume_early,
517 .resume = pci_device_resume,
518 .shutdown = pci_device_shutdown, 821 .shutdown = pci_device_shutdown,
519 .dev_attrs = pci_dev_attrs, 822 .dev_attrs = pci_dev_attrs,
823 .pm = PCI_PM_OPS_PTR,
520}; 824};
521 825
522static int __init pci_driver_init(void) 826static int __init pci_driver_init(void)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e4548ab2a93c..44a46c92b721 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: pci.c,v 1.91 1999/01/21 13:34:01 davem Exp $
3 *
4 * PCI Bus Services, see include/linux/pci.h for further explanation. 2 * PCI Bus Services, see include/linux/pci.h for further explanation.
5 * 3 *
6 * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter, 4 * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter,
@@ -19,6 +17,7 @@
19#include <linux/string.h> 17#include <linux/string.h>
20#include <linux/log2.h> 18#include <linux/log2.h>
21#include <linux/pci-aspm.h> 19#include <linux/pci-aspm.h>
20#include <linux/pm_wakeup.h>
22#include <asm/dma.h> /* isa_dma_bridge_buggy */ 21#include <asm/dma.h> /* isa_dma_bridge_buggy */
23#include "pci.h" 22#include "pci.h"
24 23
@@ -378,74 +377,90 @@ pci_restore_bars(struct pci_dev *dev)
378 pci_update_resource(dev, &dev->resource[i], i); 377 pci_update_resource(dev, &dev->resource[i], i);
379} 378}
380 379
381int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t); 380static struct pci_platform_pm_ops *pci_platform_pm;
382 381
383/** 382int pci_set_platform_pm(struct pci_platform_pm_ops *ops)
384 * pci_set_power_state - Set the power state of a PCI device
385 * @dev: PCI device to be suspended
386 * @state: PCI power state (D0, D1, D2, D3hot, D3cold) we're entering
387 *
388 * Transition a device to a new power state, using the Power Management
389 * Capabilities in the device's config space.
390 *
391 * RETURN VALUE:
392 * -EINVAL if trying to enter a lower state than we're already in.
393 * 0 if we're already in the requested state.
394 * -EIO if device does not support PCI PM.
395 * 0 if we can successfully change the power state.
396 */
397int
398pci_set_power_state(struct pci_dev *dev, pci_power_t state)
399{ 383{
400 int pm, need_restore = 0; 384 if (!ops->is_manageable || !ops->set_state || !ops->choose_state
401 u16 pmcsr, pmc; 385 || !ops->sleep_wake || !ops->can_wakeup)
386 return -EINVAL;
387 pci_platform_pm = ops;
388 return 0;
389}
402 390
403 /* bound the state we're entering */ 391static inline bool platform_pci_power_manageable(struct pci_dev *dev)
404 if (state > PCI_D3hot) 392{
405 state = PCI_D3hot; 393 return pci_platform_pm ? pci_platform_pm->is_manageable(dev) : false;
394}
406 395
407 /* 396static inline int platform_pci_set_power_state(struct pci_dev *dev,
408 * If the device or the parent bridge can't support PCI PM, ignore 397 pci_power_t t)
409 * the request if we're doing anything besides putting it into D0 398{
410 * (which would only happen on boot). 399 return pci_platform_pm ? pci_platform_pm->set_state(dev, t) : -ENOSYS;
411 */ 400}
412 if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
413 return 0;
414 401
415 /* find PCI PM capability in list */ 402static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev)
416 pm = pci_find_capability(dev, PCI_CAP_ID_PM); 403{
404 return pci_platform_pm ?
405 pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR;
406}
417 407
418 /* abort if the device doesn't support PM capabilities */ 408static inline bool platform_pci_can_wakeup(struct pci_dev *dev)
419 if (!pm) 409{
410 return pci_platform_pm ? pci_platform_pm->can_wakeup(dev) : false;
411}
412
413static inline int platform_pci_sleep_wake(struct pci_dev *dev, bool enable)
414{
415 return pci_platform_pm ?
416 pci_platform_pm->sleep_wake(dev, enable) : -ENODEV;
417}
418
419/**
420 * pci_raw_set_power_state - Use PCI PM registers to set the power state of
421 * given PCI device
422 * @dev: PCI device to handle.
423 * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
424 *
425 * RETURN VALUE:
426 * -EINVAL if the requested state is invalid.
427 * -EIO if device does not support PCI PM or its PM capabilities register has a
428 * wrong version, or device doesn't support the requested state.
429 * 0 if device already is in the requested state.
430 * 0 if device's power state has been successfully changed.
431 */
432static int
433pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state)
434{
435 u16 pmcsr;
436 bool need_restore = false;
437
438 if (!dev->pm_cap)
420 return -EIO; 439 return -EIO;
421 440
441 if (state < PCI_D0 || state > PCI_D3hot)
442 return -EINVAL;
443
422 /* Validate current state: 444 /* Validate current state:
423 * Can enter D0 from any state, but if we can only go deeper 445 * Can enter D0 from any state, but if we can only go deeper
424 * to sleep if we're already in a low power state 446 * to sleep if we're already in a low power state
425 */ 447 */
426 if (state != PCI_D0 && dev->current_state > state) { 448 if (dev->current_state == state) {
427 printk(KERN_ERR "%s(): %s: state=%d, current state=%d\n", 449 /* we're already there */
428 __func__, pci_name(dev), state, dev->current_state); 450 return 0;
451 } else if (state != PCI_D0 && dev->current_state <= PCI_D3cold
452 && dev->current_state > state) {
453 dev_err(&dev->dev, "invalid power transition "
454 "(from state %d to %d)\n", dev->current_state, state);
429 return -EINVAL; 455 return -EINVAL;
430 } else if (dev->current_state == state)
431 return 0; /* we're already there */
432
433
434 pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc);
435 if ((pmc & PCI_PM_CAP_VER_MASK) > 3) {
436 printk(KERN_DEBUG
437 "PCI: %s has unsupported PM cap regs version (%u)\n",
438 pci_name(dev), pmc & PCI_PM_CAP_VER_MASK);
439 return -EIO;
440 } 456 }
441 457
442 /* check if this device supports the desired state */ 458 /* check if this device supports the desired state */
443 if (state == PCI_D1 && !(pmc & PCI_PM_CAP_D1)) 459 if ((state == PCI_D1 && !dev->d1_support)
444 return -EIO; 460 || (state == PCI_D2 && !dev->d2_support))
445 else if (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2))
446 return -EIO; 461 return -EIO;
447 462
448 pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr); 463 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
449 464
450 /* If we're (effectively) in D3, force entire word to 0. 465 /* If we're (effectively) in D3, force entire word to 0.
451 * This doesn't affect PME_Status, disables PME_En, and 466 * This doesn't affect PME_Status, disables PME_En, and
@@ -461,7 +476,7 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
461 case PCI_UNKNOWN: /* Boot-up */ 476 case PCI_UNKNOWN: /* Boot-up */
462 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot 477 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
463 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) 478 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
464 need_restore = 1; 479 need_restore = true;
465 /* Fall-through: force to D0 */ 480 /* Fall-through: force to D0 */
466 default: 481 default:
467 pmcsr = 0; 482 pmcsr = 0;
@@ -469,7 +484,7 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
469 } 484 }
470 485
471 /* enter specified state */ 486 /* enter specified state */
472 pci_write_config_word(dev, pm + PCI_PM_CTRL, pmcsr); 487 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr);
473 488
474 /* Mandatory power management transition delays */ 489 /* Mandatory power management transition delays */
475 /* see PCI PM 1.1 5.6.1 table 18 */ 490 /* see PCI PM 1.1 5.6.1 table 18 */
@@ -478,13 +493,6 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
478 else if (state == PCI_D2 || dev->current_state == PCI_D2) 493 else if (state == PCI_D2 || dev->current_state == PCI_D2)
479 udelay(200); 494 udelay(200);
480 495
481 /*
482 * Give firmware a chance to be called, such as ACPI _PRx, _PSx
483 * Firmware method after native method ?
484 */
485 if (platform_pci_set_power_state)
486 platform_pci_set_power_state(dev, state);
487
488 dev->current_state = state; 496 dev->current_state = state;
489 497
490 /* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT 498 /* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
@@ -508,8 +516,77 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
508 return 0; 516 return 0;
509} 517}
510 518
511pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state); 519/**
512 520 * pci_update_current_state - Read PCI power state of given device from its
521 * PCI PM registers and cache it
522 * @dev: PCI device to handle.
523 */
524static void pci_update_current_state(struct pci_dev *dev)
525{
526 if (dev->pm_cap) {
527 u16 pmcsr;
528
529 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
530 dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
531 }
532}
533
534/**
535 * pci_set_power_state - Set the power state of a PCI device
536 * @dev: PCI device to handle.
537 * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
538 *
539 * Transition a device to a new power state, using the platform formware and/or
540 * the device's PCI PM registers.
541 *
542 * RETURN VALUE:
543 * -EINVAL if the requested state is invalid.
544 * -EIO if device does not support PCI PM or its PM capabilities register has a
545 * wrong version, or device doesn't support the requested state.
546 * 0 if device already is in the requested state.
547 * 0 if device's power state has been successfully changed.
548 */
549int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
550{
551 int error;
552
553 /* bound the state we're entering */
554 if (state > PCI_D3hot)
555 state = PCI_D3hot;
556 else if (state < PCI_D0)
557 state = PCI_D0;
558 else if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
559 /*
560 * If the device or the parent bridge do not support PCI PM,
561 * ignore the request if we're doing anything other than putting
562 * it into D0 (which would only happen on boot).
563 */
564 return 0;
565
566 if (state == PCI_D0 && platform_pci_power_manageable(dev)) {
567 /*
568 * Allow the platform to change the state, for example via ACPI
569 * _PR0, _PS0 and some such, but do not trust it.
570 */
571 int ret = platform_pci_set_power_state(dev, PCI_D0);
572 if (!ret)
573 pci_update_current_state(dev);
574 }
575
576 error = pci_raw_set_power_state(dev, state);
577
578 if (state > PCI_D0 && platform_pci_power_manageable(dev)) {
579 /* Allow the platform to finalize the transition */
580 int ret = platform_pci_set_power_state(dev, state);
581 if (!ret) {
582 pci_update_current_state(dev);
583 error = 0;
584 }
585 }
586
587 return error;
588}
589
513/** 590/**
514 * pci_choose_state - Choose the power state of a PCI device 591 * pci_choose_state - Choose the power state of a PCI device
515 * @dev: PCI device to be suspended 592 * @dev: PCI device to be suspended
@@ -527,11 +604,9 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
527 if (!pci_find_capability(dev, PCI_CAP_ID_PM)) 604 if (!pci_find_capability(dev, PCI_CAP_ID_PM))
528 return PCI_D0; 605 return PCI_D0;
529 606
530 if (platform_pci_choose_state) { 607 ret = platform_pci_choose_state(dev);
531 ret = platform_pci_choose_state(dev, state); 608 if (ret != PCI_POWER_ERROR)
532 if (ret != PCI_POWER_ERROR) 609 return ret;
533 return ret;
534 }
535 610
536 switch (state.event) { 611 switch (state.event) {
537 case PM_EVENT_ON: 612 case PM_EVENT_ON:
@@ -543,7 +618,8 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
543 case PM_EVENT_HIBERNATE: 618 case PM_EVENT_HIBERNATE:
544 return PCI_D3hot; 619 return PCI_D3hot;
545 default: 620 default:
546 printk("Unrecognized suspend event %d\n", state.event); 621 dev_info(&dev->dev, "unrecognized suspend event %d\n",
622 state.event);
547 BUG(); 623 BUG();
548 } 624 }
549 return PCI_D0; 625 return PCI_D0;
@@ -568,7 +644,7 @@ static int pci_save_pcie_state(struct pci_dev *dev)
568 else 644 else
569 found = 1; 645 found = 1;
570 if (!save_state) { 646 if (!save_state) {
571 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); 647 dev_err(&dev->dev, "out of memory in pci_save_pcie_state\n");
572 return -ENOMEM; 648 return -ENOMEM;
573 } 649 }
574 cap = (u16 *)&save_state->data[0]; 650 cap = (u16 *)&save_state->data[0];
@@ -619,7 +695,7 @@ static int pci_save_pcix_state(struct pci_dev *dev)
619 else 695 else
620 found = 1; 696 found = 1;
621 if (!save_state) { 697 if (!save_state) {
622 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); 698 dev_err(&dev->dev, "out of memory in pci_save_pcie_state\n");
623 return -ENOMEM; 699 return -ENOMEM;
624 } 700 }
625 cap = (u16 *)&save_state->data[0]; 701 cap = (u16 *)&save_state->data[0];
@@ -685,10 +761,9 @@ pci_restore_state(struct pci_dev *dev)
685 for (i = 15; i >= 0; i--) { 761 for (i = 15; i >= 0; i--) {
686 pci_read_config_dword(dev, i * 4, &val); 762 pci_read_config_dword(dev, i * 4, &val);
687 if (val != dev->saved_config_space[i]) { 763 if (val != dev->saved_config_space[i]) {
688 printk(KERN_DEBUG "PM: Writing back config space on " 764 dev_printk(KERN_DEBUG, &dev->dev, "restoring config "
689 "device %s at offset %x (was %x, writing %x)\n", 765 "space at offset %#x (was %#x, writing %#x)\n",
690 pci_name(dev), i, 766 i, val, (int)dev->saved_config_space[i]);
691 val, (int)dev->saved_config_space[i]);
692 pci_write_config_dword(dev,i * 4, 767 pci_write_config_dword(dev,i * 4,
693 dev->saved_config_space[i]); 768 dev->saved_config_space[i]);
694 } 769 }
@@ -961,6 +1036,46 @@ int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
961} 1036}
962 1037
963/** 1038/**
1039 * pci_pme_capable - check the capability of PCI device to generate PME#
1040 * @dev: PCI device to handle.
1041 * @state: PCI state from which device will issue PME#.
1042 */
1043static bool pci_pme_capable(struct pci_dev *dev, pci_power_t state)
1044{
1045 if (!dev->pm_cap)
1046 return false;
1047
1048 return !!(dev->pme_support & (1 << state));
1049}
1050
1051/**
1052 * pci_pme_active - enable or disable PCI device's PME# function
1053 * @dev: PCI device to handle.
1054 * @enable: 'true' to enable PME# generation; 'false' to disable it.
1055 *
1056 * The caller must verify that the device is capable of generating PME# before
1057 * calling this function with @enable equal to 'true'.
1058 */
1059static void pci_pme_active(struct pci_dev *dev, bool enable)
1060{
1061 u16 pmcsr;
1062
1063 if (!dev->pm_cap)
1064 return;
1065
1066 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
1067 /* Clear PME_Status by writing 1 to it and enable PME# */
1068 pmcsr |= PCI_PM_CTRL_PME_STATUS | PCI_PM_CTRL_PME_ENABLE;
1069 if (!enable)
1070 pmcsr &= ~PCI_PM_CTRL_PME_ENABLE;
1071
1072 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr);
1073
1074 dev_printk(KERN_INFO, &dev->dev, "PME# %s\n",
1075 enable ? "enabled" : "disabled");
1076}
1077
1078/**
964 * pci_enable_wake - enable PCI device as wakeup event source 1079 * pci_enable_wake - enable PCI device as wakeup event source
965 * @dev: PCI device affected 1080 * @dev: PCI device affected
966 * @state: PCI state from which device will issue wakeup events 1081 * @state: PCI state from which device will issue wakeup events
@@ -971,66 +1086,173 @@ int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
971 * called automatically by this routine. 1086 * called automatically by this routine.
972 * 1087 *
973 * Devices with legacy power management (no standard PCI PM capabilities) 1088 * Devices with legacy power management (no standard PCI PM capabilities)
974 * always require such platform hooks. Depending on the platform, devices 1089 * always require such platform hooks.
975 * supporting the standard PCI PME# signal may require such platform hooks;
976 * they always update bits in config space to allow PME# generation.
977 * 1090 *
978 * -EIO is returned if the device can't ever be a wakeup event source. 1091 * RETURN VALUE:
979 * -EINVAL is returned if the device can't generate wakeup events from 1092 * 0 is returned on success
980 * the specified PCI state. Returns zero if the operation is successful. 1093 * -EINVAL is returned if device is not supposed to wake up the system
1094 * Error code depending on the platform is returned if both the platform and
1095 * the native mechanism fail to enable the generation of wake-up events
981 */ 1096 */
982int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) 1097int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
983{ 1098{
984 int pm; 1099 int error = 0;
985 int status; 1100 bool pme_done = false;
986 u16 value; 1101
987 1102 if (!device_may_wakeup(&dev->dev))
988 /* Note that drivers should verify device_may_wakeup(&dev->dev) 1103 return -EINVAL;
989 * before calling this function. Platform code should report 1104
990 * errors when drivers try to enable wakeup on devices that 1105 /*
991 * can't issue wakeups, or on which wakeups were disabled by 1106 * According to "PCI System Architecture" 4th ed. by Tom Shanley & Don
992 * userspace updating the /sys/devices.../power/wakeup file. 1107 * Anderson we should be doing PME# wake enable followed by ACPI wake
1108 * enable. To disable wake-up we call the platform first, for symmetry.
993 */ 1109 */
994 1110
995 status = call_platform_enable_wakeup(&dev->dev, enable); 1111 if (!enable && platform_pci_can_wakeup(dev))
1112 error = platform_pci_sleep_wake(dev, false);
996 1113
997 /* find PCI PM capability in list */ 1114 if (!enable || pci_pme_capable(dev, state)) {
998 pm = pci_find_capability(dev, PCI_CAP_ID_PM); 1115 pci_pme_active(dev, enable);
1116 pme_done = true;
1117 }
999 1118
1000 /* If device doesn't support PM Capabilities, but caller wants to 1119 if (enable && platform_pci_can_wakeup(dev))
1001 * disable wake events, it's a NOP. Otherwise fail unless the 1120 error = platform_pci_sleep_wake(dev, true);
1002 * platform hooks handled this legacy device already.
1003 */
1004 if (!pm)
1005 return enable ? status : 0;
1006 1121
1007 /* Check device's ability to generate PME# */ 1122 return pme_done ? 0 : error;
1008 pci_read_config_word(dev,pm+PCI_PM_PMC,&value); 1123}
1009 1124
1010 value &= PCI_PM_CAP_PME_MASK; 1125/**
1011 value >>= ffs(PCI_PM_CAP_PME_MASK) - 1; /* First bit of mask */ 1126 * pci_prepare_to_sleep - prepare PCI device for system-wide transition into
1127 * a sleep state
1128 * @dev: Device to handle.
1129 *
1130 * Choose the power state appropriate for the device depending on whether
1131 * it can wake up the system and/or is power manageable by the platform
1132 * (PCI_D3hot is the default) and put the device into that state.
1133 */
1134int pci_prepare_to_sleep(struct pci_dev *dev)
1135{
1136 pci_power_t target_state = PCI_D3hot;
1137 int error;
1012 1138
1013 /* Check if it can generate PME# from requested state. */ 1139 if (platform_pci_power_manageable(dev)) {
1014 if (!value || !(value & (1 << state))) { 1140 /*
1015 /* if it can't, revert what the platform hook changed, 1141 * Call the platform to choose the target state of the device
1016 * always reporting the base "EINVAL, can't PME#" error 1142 * and enable wake-up from this state if supported.
1017 */ 1143 */
1018 if (enable) 1144 pci_power_t state = platform_pci_choose_state(dev);
1019 call_platform_enable_wakeup(&dev->dev, 0); 1145
1020 return enable ? -EINVAL : 0; 1146 switch (state) {
1147 case PCI_POWER_ERROR:
1148 case PCI_UNKNOWN:
1149 break;
1150 case PCI_D1:
1151 case PCI_D2:
1152 if (pci_no_d1d2(dev))
1153 break;
1154 default:
1155 target_state = state;
1156 }
1157 } else if (device_may_wakeup(&dev->dev)) {
1158 /*
1159 * Find the deepest state from which the device can generate
1160 * wake-up events, make it the target state and enable device
1161 * to generate PME#.
1162 */
1163 if (!dev->pm_cap)
1164 return -EIO;
1165
1166 if (dev->pme_support) {
1167 while (target_state
1168 && !(dev->pme_support & (1 << target_state)))
1169 target_state--;
1170 }
1021 } 1171 }
1022 1172
1023 pci_read_config_word(dev, pm + PCI_PM_CTRL, &value); 1173 pci_enable_wake(dev, target_state, true);
1024 1174
1025 /* Clear PME_Status by writing 1 to it and enable PME# */ 1175 error = pci_set_power_state(dev, target_state);
1026 value |= PCI_PM_CTRL_PME_STATUS | PCI_PM_CTRL_PME_ENABLE;
1027 1176
1028 if (!enable) 1177 if (error)
1029 value &= ~PCI_PM_CTRL_PME_ENABLE; 1178 pci_enable_wake(dev, target_state, false);
1030 1179
1031 pci_write_config_word(dev, pm + PCI_PM_CTRL, value); 1180 return error;
1181}
1032 1182
1033 return 0; 1183/**
1184 * pci_back_from_sleep - turn PCI device on during system-wide transition into
1185 * the working state a sleep state
1186 * @dev: Device to handle.
1187 *
1188 * Disable device's sytem wake-up capability and put it into D0.
1189 */
1190int pci_back_from_sleep(struct pci_dev *dev)
1191{
1192 pci_enable_wake(dev, PCI_D0, false);
1193 return pci_set_power_state(dev, PCI_D0);
1194}
1195
1196/**
1197 * pci_pm_init - Initialize PM functions of given PCI device
1198 * @dev: PCI device to handle.
1199 */
1200void pci_pm_init(struct pci_dev *dev)
1201{
1202 int pm;
1203 u16 pmc;
1204
1205 dev->pm_cap = 0;
1206
1207 /* find PCI PM capability in list */
1208 pm = pci_find_capability(dev, PCI_CAP_ID_PM);
1209 if (!pm)
1210 return;
1211 /* Check device's ability to generate PME# */
1212 pci_read_config_word(dev, pm + PCI_PM_PMC, &pmc);
1213
1214 if ((pmc & PCI_PM_CAP_VER_MASK) > 3) {
1215 dev_err(&dev->dev, "unsupported PM cap regs version (%u)\n",
1216 pmc & PCI_PM_CAP_VER_MASK);
1217 return;
1218 }
1219
1220 dev->pm_cap = pm;
1221
1222 dev->d1_support = false;
1223 dev->d2_support = false;
1224 if (!pci_no_d1d2(dev)) {
1225 if (pmc & PCI_PM_CAP_D1) {
1226 dev_printk(KERN_DEBUG, &dev->dev, "supports D1\n");
1227 dev->d1_support = true;
1228 }
1229 if (pmc & PCI_PM_CAP_D2) {
1230 dev_printk(KERN_DEBUG, &dev->dev, "supports D2\n");
1231 dev->d2_support = true;
1232 }
1233 }
1234
1235 pmc &= PCI_PM_CAP_PME_MASK;
1236 if (pmc) {
1237 dev_printk(KERN_INFO, &dev->dev,
1238 "PME# supported from%s%s%s%s%s\n",
1239 (pmc & PCI_PM_CAP_PME_D0) ? " D0" : "",
1240 (pmc & PCI_PM_CAP_PME_D1) ? " D1" : "",
1241 (pmc & PCI_PM_CAP_PME_D2) ? " D2" : "",
1242 (pmc & PCI_PM_CAP_PME_D3) ? " D3hot" : "",
1243 (pmc & PCI_PM_CAP_PME_D3cold) ? " D3cold" : "");
1244 dev->pme_support = pmc >> PCI_PM_CAP_PME_SHIFT;
1245 /*
1246 * Make device's PM flags reflect the wake-up capability, but
1247 * let the user space enable it to wake up the system as needed.
1248 */
1249 device_set_wakeup_capable(&dev->dev, true);
1250 device_set_wakeup_enable(&dev->dev, false);
1251 /* Disable the PME# generation functionality */
1252 pci_pme_active(dev, false);
1253 } else {
1254 dev->pme_support = 0;
1255 }
1034} 1256}
1035 1257
1036int 1258int
@@ -1116,13 +1338,11 @@ int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
1116 return 0; 1338 return 0;
1117 1339
1118err_out: 1340err_out:
1119 printk (KERN_WARNING "PCI: Unable to reserve %s region #%d:%llx@%llx " 1341 dev_warn(&pdev->dev, "BAR %d: can't reserve %s region [%#llx-%#llx]\n",
1120 "for device %s\n", 1342 bar,
1121 pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem", 1343 pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem",
1122 bar + 1, /* PCI BAR # */ 1344 (unsigned long long)pci_resource_start(pdev, bar),
1123 (unsigned long long)pci_resource_len(pdev, bar), 1345 (unsigned long long)pci_resource_end(pdev, bar));
1124 (unsigned long long)pci_resource_start(pdev, bar),
1125 pci_name(pdev));
1126 return -EBUSY; 1346 return -EBUSY;
1127} 1347}
1128 1348
@@ -1214,7 +1434,7 @@ pci_set_master(struct pci_dev *dev)
1214 1434
1215 pci_read_config_word(dev, PCI_COMMAND, &cmd); 1435 pci_read_config_word(dev, PCI_COMMAND, &cmd);
1216 if (! (cmd & PCI_COMMAND_MASTER)) { 1436 if (! (cmd & PCI_COMMAND_MASTER)) {
1217 pr_debug("PCI: Enabling bus mastering for device %s\n", pci_name(dev)); 1437 dev_dbg(&dev->dev, "enabling bus mastering\n");
1218 cmd |= PCI_COMMAND_MASTER; 1438 cmd |= PCI_COMMAND_MASTER;
1219 pci_write_config_word(dev, PCI_COMMAND, cmd); 1439 pci_write_config_word(dev, PCI_COMMAND, cmd);
1220 } 1440 }
@@ -1279,8 +1499,8 @@ pci_set_cacheline_size(struct pci_dev *dev)
1279 if (cacheline_size == pci_cache_line_size) 1499 if (cacheline_size == pci_cache_line_size)
1280 return 0; 1500 return 0;
1281 1501
1282 printk(KERN_DEBUG "PCI: cache line size of %d is not supported " 1502 dev_printk(KERN_DEBUG, &dev->dev, "cache line size of %d is not "
1283 "by device %s\n", pci_cache_line_size << 2, pci_name(dev)); 1503 "supported\n", pci_cache_line_size << 2);
1284 1504
1285 return -EINVAL; 1505 return -EINVAL;
1286} 1506}
@@ -1305,8 +1525,7 @@ pci_set_mwi(struct pci_dev *dev)
1305 1525
1306 pci_read_config_word(dev, PCI_COMMAND, &cmd); 1526 pci_read_config_word(dev, PCI_COMMAND, &cmd);
1307 if (! (cmd & PCI_COMMAND_INVALIDATE)) { 1527 if (! (cmd & PCI_COMMAND_INVALIDATE)) {
1308 pr_debug("PCI: Enabling Mem-Wr-Inval for device %s\n", 1528 dev_dbg(&dev->dev, "enabling Mem-Wr-Inval\n");
1309 pci_name(dev));
1310 cmd |= PCI_COMMAND_INVALIDATE; 1529 cmd |= PCI_COMMAND_INVALIDATE;
1311 pci_write_config_word(dev, PCI_COMMAND, cmd); 1530 pci_write_config_word(dev, PCI_COMMAND, cmd);
1312 } 1531 }
@@ -1702,5 +1921,7 @@ EXPORT_SYMBOL(pci_set_power_state);
1702EXPORT_SYMBOL(pci_save_state); 1921EXPORT_SYMBOL(pci_save_state);
1703EXPORT_SYMBOL(pci_restore_state); 1922EXPORT_SYMBOL(pci_restore_state);
1704EXPORT_SYMBOL(pci_enable_wake); 1923EXPORT_SYMBOL(pci_enable_wake);
1924EXPORT_SYMBOL(pci_prepare_to_sleep);
1925EXPORT_SYMBOL(pci_back_from_sleep);
1705EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state); 1926EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state);
1706 1927
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 00408c97e5fc..d807cd786f20 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -5,11 +5,36 @@ extern int pci_create_sysfs_dev_files(struct pci_dev *pdev);
5extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev); 5extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
6extern void pci_cleanup_rom(struct pci_dev *dev); 6extern void pci_cleanup_rom(struct pci_dev *dev);
7 7
8/* Firmware callbacks */ 8/**
9extern pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev, 9 * Firmware PM callbacks
10 pm_message_t state); 10 *
11extern int (*platform_pci_set_power_state)(struct pci_dev *dev, 11 * @is_manageable - returns 'true' if given device is power manageable by the
12 pci_power_t state); 12 * platform firmware
13 *
14 * @set_state - invokes the platform firmware to set the device's power state
15 *
16 * @choose_state - returns PCI power state of given device preferred by the
17 * platform; to be used during system-wide transitions from a
18 * sleeping state to the working state and vice versa
19 *
20 * @can_wakeup - returns 'true' if given device is capable of waking up the
21 * system from a sleeping state
22 *
23 * @sleep_wake - enables/disables the system wake up capability of given device
24 *
25 * If given platform is generally capable of power managing PCI devices, all of
26 * these callbacks are mandatory.
27 */
28struct pci_platform_pm_ops {
29 bool (*is_manageable)(struct pci_dev *dev);
30 int (*set_state)(struct pci_dev *dev, pci_power_t state);
31 pci_power_t (*choose_state)(struct pci_dev *dev);
32 bool (*can_wakeup)(struct pci_dev *dev);
33 int (*sleep_wake)(struct pci_dev *dev, bool enable);
34};
35
36extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
37extern void pci_pm_init(struct pci_dev *dev);
13 38
14extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val); 39extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
15extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val); 40extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
@@ -106,3 +131,16 @@ pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
106} 131}
107 132
108struct pci_dev *pci_find_upstream_pcie_bridge(struct pci_dev *pdev); 133struct pci_dev *pci_find_upstream_pcie_bridge(struct pci_dev *pdev);
134
135/* PCI slot sysfs helper code */
136#define to_pci_slot(s) container_of(s, struct pci_slot, kobj)
137
138extern struct kset *pci_slots_kset;
139
140struct pci_slot_attribute {
141 struct attribute attr;
142 ssize_t (*show)(struct pci_slot *, char *);
143 ssize_t (*store)(struct pci_slot *, const char *, size_t);
144};
145#define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr)
146
diff --git a/drivers/pci/pcie/aer/aerdrv.c b/drivers/pci/pcie/aer/aerdrv.c
index 07c3bdb6edc2..77036f46acfe 100644
--- a/drivers/pci/pcie/aer/aerdrv.c
+++ b/drivers/pci/pcie/aer/aerdrv.c
@@ -26,6 +26,7 @@
26#include <linux/pcieport_if.h> 26#include <linux/pcieport_if.h>
27 27
28#include "aerdrv.h" 28#include "aerdrv.h"
29#include "../../pci.h"
29 30
30/* 31/*
31 * Version Information 32 * Version Information
@@ -219,8 +220,7 @@ static int __devinit aer_probe (struct pcie_device *dev,
219 220
220 /* Alloc rpc data structure */ 221 /* Alloc rpc data structure */
221 if (!(rpc = aer_alloc_rpc(dev))) { 222 if (!(rpc = aer_alloc_rpc(dev))) {
222 printk(KERN_DEBUG "%s: Alloc rpc fails on PCIE device[%s]\n", 223 dev_printk(KERN_DEBUG, device, "alloc rpc failed\n");
223 __func__, device->bus_id);
224 aer_remove(dev); 224 aer_remove(dev);
225 return -ENOMEM; 225 return -ENOMEM;
226 } 226 }
@@ -228,8 +228,7 @@ static int __devinit aer_probe (struct pcie_device *dev,
228 /* Request IRQ ISR */ 228 /* Request IRQ ISR */
229 if ((status = request_irq(dev->irq, aer_irq, IRQF_SHARED, "aerdrv", 229 if ((status = request_irq(dev->irq, aer_irq, IRQF_SHARED, "aerdrv",
230 dev))) { 230 dev))) {
231 printk(KERN_DEBUG "%s: Request ISR fails on PCIE device[%s]\n", 231 dev_printk(KERN_DEBUG, device, "request IRQ failed\n");
232 __func__, device->bus_id);
233 aer_remove(dev); 232 aer_remove(dev);
234 return status; 233 return status;
235 } 234 }
@@ -273,7 +272,7 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev)
273 * to issue Configuration Requests to those devices. 272 * to issue Configuration Requests to those devices.
274 */ 273 */
275 msleep(200); 274 msleep(200);
276 printk(KERN_DEBUG "Complete link reset at Root[%s]\n", dev->dev.bus_id); 275 dev_printk(KERN_DEBUG, &dev->dev, "Root Port link has been reset\n");
277 276
278 /* Enable Root Port's interrupt in response to error messages */ 277 /* Enable Root Port's interrupt in response to error messages */
279 pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &status); 278 pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &status);
diff --git a/drivers/pci/pcie/aer/aerdrv_acpi.c b/drivers/pci/pcie/aer/aerdrv_acpi.c
index d39a78dbd026..30f581b8791f 100644
--- a/drivers/pci/pcie/aer/aerdrv_acpi.c
+++ b/drivers/pci/pcie/aer/aerdrv_acpi.c
@@ -50,10 +50,10 @@ int aer_osc_setup(struct pcie_device *pciedev)
50 } 50 }
51 51
52 if (ACPI_FAILURE(status)) { 52 if (ACPI_FAILURE(status)) {
53 printk(KERN_DEBUG "AER service couldn't init device %s - %s\n", 53 dev_printk(KERN_DEBUG, &pciedev->device, "AER service couldn't "
54 pciedev->device.bus_id, 54 "init device: %s\n",
55 (status == AE_SUPPORT || status == AE_NOT_FOUND) ? 55 (status == AE_SUPPORT || status == AE_NOT_FOUND) ?
56 "no _OSC support" : "Run ACPI _OSC fails"); 56 "no _OSC support" : "_OSC failed");
57 return -1; 57 return -1;
58 } 58 }
59 59
diff --git a/drivers/pci/pcie/aer/aerdrv_core.c b/drivers/pci/pcie/aer/aerdrv_core.c
index aaa82392d1dc..ee5e7b5176d0 100644
--- a/drivers/pci/pcie/aer/aerdrv_core.c
+++ b/drivers/pci/pcie/aer/aerdrv_core.c
@@ -221,9 +221,9 @@ static void report_error_detected(struct pci_dev *dev, void *data)
221 * of a driver for this device is unaware of 221 * of a driver for this device is unaware of
222 * its hw state. 222 * its hw state.
223 */ 223 */
224 printk(KERN_DEBUG "Device ID[%s] has %s\n", 224 dev_printk(KERN_DEBUG, &dev->dev, "device has %s\n",
225 dev->dev.bus_id, (dev->driver) ? 225 dev->driver ?
226 "no AER-aware driver" : "no driver"); 226 "no AER-aware driver" : "no driver");
227 } 227 }
228 return; 228 return;
229 } 229 }
@@ -304,7 +304,7 @@ static pci_ers_result_t broadcast_error_message(struct pci_dev *dev,
304{ 304{
305 struct aer_broadcast_data result_data; 305 struct aer_broadcast_data result_data;
306 306
307 printk(KERN_DEBUG "Broadcast %s message\n", error_mesg); 307 dev_printk(KERN_DEBUG, &dev->dev, "broadcast %s message\n", error_mesg);
308 result_data.state = state; 308 result_data.state = state;
309 if (cb == report_error_detected) 309 if (cb == report_error_detected)
310 result_data.result = PCI_ERS_RESULT_CAN_RECOVER; 310 result_data.result = PCI_ERS_RESULT_CAN_RECOVER;
@@ -404,18 +404,16 @@ static pci_ers_result_t reset_link(struct pcie_device *aerdev,
404 data.aer_driver = 404 data.aer_driver =
405 to_service_driver(aerdev->device.driver); 405 to_service_driver(aerdev->device.driver);
406 } else { 406 } else {
407 printk(KERN_DEBUG "No link-reset support to Device ID" 407 dev_printk(KERN_DEBUG, &dev->dev, "no link-reset "
408 "[%s]\n", 408 "support\n");
409 dev->dev.bus_id);
410 return PCI_ERS_RESULT_DISCONNECT; 409 return PCI_ERS_RESULT_DISCONNECT;
411 } 410 }
412 } 411 }
413 412
414 status = data.aer_driver->reset_link(udev); 413 status = data.aer_driver->reset_link(udev);
415 if (status != PCI_ERS_RESULT_RECOVERED) { 414 if (status != PCI_ERS_RESULT_RECOVERED) {
416 printk(KERN_DEBUG "Link reset at upstream Device ID" 415 dev_printk(KERN_DEBUG, &dev->dev, "link reset at upstream "
417 "[%s] failed\n", 416 "device %s failed\n", pci_name(udev));
418 udev->dev.bus_id);
419 return PCI_ERS_RESULT_DISCONNECT; 417 return PCI_ERS_RESULT_DISCONNECT;
420 } 418 }
421 419
@@ -511,10 +509,12 @@ static void handle_error_source(struct pcie_device * aerdev,
511 } else { 509 } else {
512 status = do_recovery(aerdev, dev, info.severity); 510 status = do_recovery(aerdev, dev, info.severity);
513 if (status == PCI_ERS_RESULT_RECOVERED) { 511 if (status == PCI_ERS_RESULT_RECOVERED) {
514 printk(KERN_DEBUG "AER driver successfully recovered\n"); 512 dev_printk(KERN_DEBUG, &dev->dev, "AER driver "
513 "successfully recovered\n");
515 } else { 514 } else {
516 /* TODO: Should kernel panic here? */ 515 /* TODO: Should kernel panic here? */
517 printk(KERN_DEBUG "AER driver didn't recover\n"); 516 dev_printk(KERN_DEBUG, &dev->dev, "AER driver didn't "
517 "recover\n");
518 } 518 }
519 } 519 }
520} 520}
diff --git a/drivers/pci/pcie/portdrv_bus.c b/drivers/pci/pcie/portdrv_bus.c
index 3f0976868eda..359fe5568df1 100644
--- a/drivers/pci/pcie/portdrv_bus.c
+++ b/drivers/pci/pcie/portdrv_bus.c
@@ -13,6 +13,7 @@
13#include <linux/pm.h> 13#include <linux/pm.h>
14 14
15#include <linux/pcieport_if.h> 15#include <linux/pcieport_if.h>
16#include "portdrv.h"
16 17
17static int pcie_port_bus_match(struct device *dev, struct device_driver *drv); 18static int pcie_port_bus_match(struct device *dev, struct device_driver *drv);
18static int pcie_port_bus_suspend(struct device *dev, pm_message_t state); 19static int pcie_port_bus_suspend(struct device *dev, pm_message_t state);
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index fb0abfa508dc..890f0d2b370a 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -23,20 +23,20 @@ static int pcie_port_probe_service(struct device *dev)
23{ 23{
24 struct pcie_device *pciedev; 24 struct pcie_device *pciedev;
25 struct pcie_port_service_driver *driver; 25 struct pcie_port_service_driver *driver;
26 int status = -ENODEV; 26 int status;
27 27
28 if (!dev || !dev->driver) 28 if (!dev || !dev->driver)
29 return status; 29 return -ENODEV;
30 30
31 driver = to_service_driver(dev->driver); 31 driver = to_service_driver(dev->driver);
32 if (!driver || !driver->probe) 32 if (!driver || !driver->probe)
33 return status; 33 return -ENODEV;
34 34
35 pciedev = to_pcie_device(dev); 35 pciedev = to_pcie_device(dev);
36 status = driver->probe(pciedev, driver->id_table); 36 status = driver->probe(pciedev, driver->id_table);
37 if (!status) { 37 if (!status) {
38 printk(KERN_DEBUG "Load service driver %s on pcie device %s\n", 38 dev_printk(KERN_DEBUG, dev, "service driver %s loaded\n",
39 driver->name, dev->bus_id); 39 driver->name);
40 get_device(dev); 40 get_device(dev);
41 } 41 }
42 return status; 42 return status;
@@ -53,8 +53,8 @@ static int pcie_port_remove_service(struct device *dev)
53 pciedev = to_pcie_device(dev); 53 pciedev = to_pcie_device(dev);
54 driver = to_service_driver(dev->driver); 54 driver = to_service_driver(dev->driver);
55 if (driver && driver->remove) { 55 if (driver && driver->remove) {
56 printk(KERN_DEBUG "Unload service driver %s on pcie device %s\n", 56 dev_printk(KERN_DEBUG, dev, "unloading service driver %s\n",
57 driver->name, dev->bus_id); 57 driver->name);
58 driver->remove(pciedev); 58 driver->remove(pciedev);
59 put_device(dev); 59 put_device(dev);
60 } 60 }
@@ -103,7 +103,7 @@ static int pcie_port_resume_service(struct device *dev)
103 */ 103 */
104static void release_pcie_device(struct device *dev) 104static void release_pcie_device(struct device *dev)
105{ 105{
106 printk(KERN_DEBUG "Free Port Service[%s]\n", dev->bus_id); 106 dev_printk(KERN_DEBUG, dev, "free port service\n");
107 kfree(to_pcie_device(dev)); 107 kfree(to_pcie_device(dev));
108} 108}
109 109
@@ -150,7 +150,7 @@ static int assign_interrupt_mode(struct pci_dev *dev, int *vectors, int mask)
150 if (pos) { 150 if (pos) {
151 struct msix_entry msix_entries[PCIE_PORT_DEVICE_MAXSERVICES] = 151 struct msix_entry msix_entries[PCIE_PORT_DEVICE_MAXSERVICES] =
152 {{0, 0}, {0, 1}, {0, 2}, {0, 3}}; 152 {{0, 0}, {0, 1}, {0, 2}, {0, 3}};
153 printk("%s Found MSIX capability\n", __func__); 153 dev_info(&dev->dev, "found MSI-X capability\n");
154 status = pci_enable_msix(dev, msix_entries, nvec); 154 status = pci_enable_msix(dev, msix_entries, nvec);
155 if (!status) { 155 if (!status) {
156 int j = 0; 156 int j = 0;
@@ -165,7 +165,7 @@ static int assign_interrupt_mode(struct pci_dev *dev, int *vectors, int mask)
165 if (status) { 165 if (status) {
166 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 166 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
167 if (pos) { 167 if (pos) {
168 printk("%s Found MSI capability\n", __func__); 168 dev_info(&dev->dev, "found MSI capability\n");
169 status = pci_enable_msi(dev); 169 status = pci_enable_msi(dev);
170 if (!status) { 170 if (!status) {
171 interrupt_mode = PCIE_PORT_MSI_MODE; 171 interrupt_mode = PCIE_PORT_MSI_MODE;
@@ -252,7 +252,7 @@ static struct pcie_device* alloc_pcie_device(struct pci_dev *parent,
252 return NULL; 252 return NULL;
253 253
254 pcie_device_init(parent, device, port_type, service_type, irq,irq_mode); 254 pcie_device_init(parent, device, port_type, service_type, irq,irq_mode);
255 printk(KERN_DEBUG "Allocate Port Service[%s]\n", device->device.bus_id); 255 dev_printk(KERN_DEBUG, &device->device, "allocate port service\n");
256 return device; 256 return device;
257} 257}
258 258
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index 51d163238d93..367c9c20000d 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -91,9 +91,8 @@ static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
91 91
92 pci_set_master(dev); 92 pci_set_master(dev);
93 if (!dev->irq && dev->pin) { 93 if (!dev->irq && dev->pin) {
94 printk(KERN_WARNING 94 dev_warn(&dev->dev, "device [%04x/%04x] has invalid IRQ; "
95 "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n", 95 "check vendor BIOS\n", dev->vendor, dev->device);
96 __func__, dev->vendor, dev->device);
97 } 96 }
98 if (pcie_port_device_register(dev)) { 97 if (pcie_port_device_register(dev)) {
99 pci_disable_device(dev); 98 pci_disable_device(dev);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 3706ce7972dd..b1724cf31b66 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -277,8 +277,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
277 res->end = res->start + sz64; 277 res->end = res->start + sz64;
278#else 278#else
279 if (sz64 > 0x100000000ULL) { 279 if (sz64 > 0x100000000ULL) {
280 printk(KERN_ERR "PCI: Unable to handle 64-bit " 280 dev_err(&dev->dev, "BAR %d: can't handle 64-bit"
281 "BAR for device %s\n", pci_name(dev)); 281 " BAR\n", pos);
282 res->start = 0; 282 res->start = 0;
283 res->flags = 0; 283 res->flags = 0;
284 } else if (lhi) { 284 } else if (lhi) {
@@ -329,7 +329,7 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
329 return; 329 return;
330 330
331 if (dev->transparent) { 331 if (dev->transparent) {
332 printk(KERN_INFO "PCI: Transparent bridge - %s\n", pci_name(dev)); 332 dev_info(&dev->dev, "transparent bridge\n");
333 for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++) 333 for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)
334 child->resource[i] = child->parent->resource[i - 3]; 334 child->resource[i] = child->parent->resource[i - 3];
335 } 335 }
@@ -392,7 +392,8 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
392 limit |= ((long) mem_limit_hi) << 32; 392 limit |= ((long) mem_limit_hi) << 32;
393#else 393#else
394 if (mem_base_hi || mem_limit_hi) { 394 if (mem_base_hi || mem_limit_hi) {
395 printk(KERN_ERR "PCI: Unable to handle 64-bit address space for bridge %s\n", pci_name(dev)); 395 dev_err(&dev->dev, "can't handle 64-bit "
396 "address space for bridge\n");
396 return; 397 return;
397 } 398 }
398#endif 399#endif
@@ -414,6 +415,7 @@ static struct pci_bus * pci_alloc_bus(void)
414 INIT_LIST_HEAD(&b->node); 415 INIT_LIST_HEAD(&b->node);
415 INIT_LIST_HEAD(&b->children); 416 INIT_LIST_HEAD(&b->children);
416 INIT_LIST_HEAD(&b->devices); 417 INIT_LIST_HEAD(&b->devices);
418 INIT_LIST_HEAD(&b->slots);
417 } 419 }
418 return b; 420 return b;
419} 421}
@@ -511,8 +513,8 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
511 513
512 pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses); 514 pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses);
513 515
514 pr_debug("PCI: Scanning behind PCI bridge %s, config %06x, pass %d\n", 516 dev_dbg(&dev->dev, "scanning behind bridge, config %06x, pass %d\n",
515 pci_name(dev), buses & 0xffffff, pass); 517 buses & 0xffffff, pass);
516 518
517 /* Disable MasterAbortMode during probing to avoid reporting 519 /* Disable MasterAbortMode during probing to avoid reporting
518 of bus errors (in some architectures) */ 520 of bus errors (in some architectures) */
@@ -535,8 +537,8 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
535 * ignore it. This can happen with the i450NX chipset. 537 * ignore it. This can happen with the i450NX chipset.
536 */ 538 */
537 if (pci_find_bus(pci_domain_nr(bus), busnr)) { 539 if (pci_find_bus(pci_domain_nr(bus), busnr)) {
538 printk(KERN_INFO "PCI: Bus %04x:%02x already known\n", 540 dev_info(&dev->dev, "bus %04x:%02x already known\n",
539 pci_domain_nr(bus), busnr); 541 pci_domain_nr(bus), busnr);
540 goto out; 542 goto out;
541 } 543 }
542 544
@@ -711,8 +713,9 @@ static int pci_setup_device(struct pci_dev * dev)
711{ 713{
712 u32 class; 714 u32 class;
713 715
714 sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus), 716 dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus),
715 dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); 717 dev->bus->number, PCI_SLOT(dev->devfn),
718 PCI_FUNC(dev->devfn));
716 719
717 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class); 720 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class);
718 dev->revision = class & 0xff; 721 dev->revision = class & 0xff;
@@ -720,7 +723,7 @@ static int pci_setup_device(struct pci_dev * dev)
720 dev->class = class; 723 dev->class = class;
721 class >>= 8; 724 class >>= 8;
722 725
723 pr_debug("PCI: Found %s [%04x/%04x] %06x %02x\n", pci_name(dev), 726 dev_dbg(&dev->dev, "found [%04x/%04x] class %06x header type %02x\n",
724 dev->vendor, dev->device, class, dev->hdr_type); 727 dev->vendor, dev->device, class, dev->hdr_type);
725 728
726 /* "Unknown power state" */ 729 /* "Unknown power state" */
@@ -788,13 +791,13 @@ static int pci_setup_device(struct pci_dev * dev)
788 break; 791 break;
789 792
790 default: /* unknown header */ 793 default: /* unknown header */
791 printk(KERN_ERR "PCI: device %s has unknown header type %02x, ignoring.\n", 794 dev_err(&dev->dev, "unknown header type %02x, "
792 pci_name(dev), dev->hdr_type); 795 "ignoring device\n", dev->hdr_type);
793 return -1; 796 return -1;
794 797
795 bad: 798 bad:
796 printk(KERN_ERR "PCI: %s: class %x doesn't match header type %02x. Ignoring class.\n", 799 dev_err(&dev->dev, "ignoring class %02x (doesn't match header "
797 pci_name(dev), class, dev->hdr_type); 800 "type %02x)\n", class, dev->hdr_type);
798 dev->class = PCI_CLASS_NOT_DEFINED; 801 dev->class = PCI_CLASS_NOT_DEFINED;
799 } 802 }
800 803
@@ -927,7 +930,7 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)
927 return NULL; 930 return NULL;
928 /* Card hasn't responded in 60 seconds? Must be stuck. */ 931 /* Card hasn't responded in 60 seconds? Must be stuck. */
929 if (delay > 60 * 1000) { 932 if (delay > 60 * 1000) {
930 printk(KERN_WARNING "Device %04x:%02x:%02x.%d not " 933 printk(KERN_WARNING "pci %04x:%02x:%02x.%d: not "
931 "responding\n", pci_domain_nr(bus), 934 "responding\n", pci_domain_nr(bus),
932 bus->number, PCI_SLOT(devfn), 935 bus->number, PCI_SLOT(devfn),
933 PCI_FUNC(devfn)); 936 PCI_FUNC(devfn));
@@ -984,6 +987,9 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
984 /* Fix up broken headers */ 987 /* Fix up broken headers */
985 pci_fixup_device(pci_fixup_header, dev); 988 pci_fixup_device(pci_fixup_header, dev);
986 989
990 /* Initialize power management of the device */
991 pci_pm_init(dev);
992
987 /* 993 /*
988 * Add the device to our list of discovered devices 994 * Add the device to our list of discovered devices
989 * and the bus list for fixup functions, etc. 995 * and the bus list for fixup functions, etc.
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 963a97642ae9..4400dffbd93a 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: proc.c,v 1.13 1998/05/12 07:36:07 mj Exp $
3 *
4 * Procfs interface for the PCI bus. 2 * Procfs interface for the PCI bus.
5 * 3 *
6 * Copyright (c) 1997--1999 Martin Mares <mj@ucw.cz> 4 * Copyright (c) 1997--1999 Martin Mares <mj@ucw.cz>
@@ -482,5 +480,5 @@ static int __init pci_proc_init(void)
482 return 0; 480 return 0;
483} 481}
484 482
485__initcall(pci_proc_init); 483device_initcall(pci_proc_init);
486 484
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 338a3f94b4d4..12d489395fad 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -556,7 +556,7 @@ static void quirk_via_ioapic(struct pci_dev *dev)
556 pci_write_config_byte (dev, 0x58, tmp); 556 pci_write_config_byte (dev, 0x58, tmp);
557} 557}
558DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic); 558DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic);
559DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic); 559DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic);
560 560
561/* 561/*
562 * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit. 562 * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit.
@@ -576,7 +576,7 @@ static void quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev)
576 } 576 }
577} 577}
578DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); 578DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert);
579DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); 579DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert);
580 580
581/* 581/*
582 * The AMD io apic can hang the box when an apic irq is masked. 582 * The AMD io apic can hang the box when an apic irq is masked.
@@ -622,7 +622,7 @@ static void quirk_amd_8131_ioapic(struct pci_dev *dev)
622 } 622 }
623} 623}
624DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); 624DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic);
625DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); 625DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic);
626#endif /* CONFIG_X86_IO_APIC */ 626#endif /* CONFIG_X86_IO_APIC */
627 627
628/* 628/*
@@ -774,7 +774,7 @@ static void quirk_cardbus_legacy(struct pci_dev *dev)
774 pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0); 774 pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0);
775} 775}
776DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy); 776DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy);
777DECLARE_PCI_FIXUP_RESUME(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy); 777DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy);
778 778
779/* 779/*
780 * Following the PCI ordering rules is optional on the AMD762. I'm not 780 * Following the PCI ordering rules is optional on the AMD762. I'm not
@@ -797,7 +797,7 @@ static void quirk_amd_ordering(struct pci_dev *dev)
797 } 797 }
798} 798}
799DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering); 799DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering);
800DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering); 800DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering);
801 801
802/* 802/*
803 * DreamWorks provided workaround for Dunord I-3000 problem 803 * DreamWorks provided workaround for Dunord I-3000 problem
@@ -865,7 +865,7 @@ static void quirk_disable_pxb(struct pci_dev *pdev)
865 } 865 }
866} 866}
867DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb); 867DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb);
868DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb); 868DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb);
869 869
870static void __devinit quirk_amd_ide_mode(struct pci_dev *pdev) 870static void __devinit quirk_amd_ide_mode(struct pci_dev *pdev)
871{ 871{
@@ -885,9 +885,9 @@ static void __devinit quirk_amd_ide_mode(struct pci_dev *pdev)
885 } 885 }
886} 886}
887DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode); 887DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode);
888DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode); 888DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode);
889DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode); 889DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode);
890DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode); 890DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode);
891 891
892/* 892/*
893 * Serverworks CSB5 IDE does not fully support native mode 893 * Serverworks CSB5 IDE does not fully support native mode
@@ -1054,6 +1054,20 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
1054 * its on-board VGA controller */ 1054 * its on-board VGA controller */
1055 asus_hides_smbus = 1; 1055 asus_hides_smbus = 1;
1056 } 1056 }
1057 else if (dev->device == PCI_DEVICE_ID_INTEL_82845G_IG)
1058 switch(dev->subsystem_device) {
1059 case 0x00b8: /* Compaq Evo D510 CMT */
1060 case 0x00b9: /* Compaq Evo D510 SFF */
1061 asus_hides_smbus = 1;
1062 }
1063 else if (dev->device == PCI_DEVICE_ID_INTEL_82815_CGC)
1064 switch (dev->subsystem_device) {
1065 case 0x001A: /* Compaq Deskpro EN SSF P667 815E */
1066 /* Motherboard doesn't have host bridge
1067 * subvendor/subdevice IDs, therefore checking
1068 * its on-board VGA controller */
1069 asus_hides_smbus = 1;
1070 }
1057 } 1071 }
1058} 1072}
1059DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845_HB, asus_hides_smbus_hostbridge); 1073DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845_HB, asus_hides_smbus_hostbridge);
@@ -1068,6 +1082,8 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, as
1068DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge); 1082DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge);
1069 1083
1070DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3, asus_hides_smbus_hostbridge); 1084DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3, asus_hides_smbus_hostbridge);
1085DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845G_IG, asus_hides_smbus_hostbridge);
1086DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC, asus_hides_smbus_hostbridge);
1071 1087
1072static void asus_hides_smbus_lpc(struct pci_dev *dev) 1088static void asus_hides_smbus_lpc(struct pci_dev *dev)
1073{ 1089{
@@ -1093,31 +1109,61 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asu
1093DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc); 1109DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc);
1094DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc); 1110DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc);
1095DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc); 1111DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc);
1096DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, asus_hides_smbus_lpc); 1112DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, asus_hides_smbus_lpc);
1097DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc); 1113DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc);
1098DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc); 1114DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc);
1099DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc); 1115DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc);
1100DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc); 1116DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc);
1101DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc); 1117DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc);
1102DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc); 1118DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc);
1103 1119
1104static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev) 1120/* It appears we just have one such device. If not, we have a warning */
1121static void __iomem *asus_rcba_base;
1122static void asus_hides_smbus_lpc_ich6_suspend(struct pci_dev *dev)
1105{ 1123{
1106 u32 val, rcba; 1124 u32 rcba;
1107 void __iomem *base;
1108 1125
1109 if (likely(!asus_hides_smbus)) 1126 if (likely(!asus_hides_smbus))
1110 return; 1127 return;
1128 WARN_ON(asus_rcba_base);
1129
1111 pci_read_config_dword(dev, 0xF0, &rcba); 1130 pci_read_config_dword(dev, 0xF0, &rcba);
1112 base = ioremap_nocache(rcba & 0xFFFFC000, 0x4000); /* use bits 31:14, 16 kB aligned */ 1131 /* use bits 31:14, 16 kB aligned */
1113 if (base == NULL) return; 1132 asus_rcba_base = ioremap_nocache(rcba & 0xFFFFC000, 0x4000);
1114 val=readl(base + 0x3418); /* read the Function Disable register, dword mode only */ 1133 if (asus_rcba_base == NULL)
1115 writel(val & 0xFFFFFFF7, base + 0x3418); /* enable the SMBus device */ 1134 return;
1116 iounmap(base); 1135}
1136
1137static void asus_hides_smbus_lpc_ich6_resume_early(struct pci_dev *dev)
1138{
1139 u32 val;
1140
1141 if (likely(!asus_hides_smbus || !asus_rcba_base))
1142 return;
1143 /* read the Function Disable register, dword mode only */
1144 val = readl(asus_rcba_base + 0x3418);
1145 writel(val & 0xFFFFFFF7, asus_rcba_base + 0x3418); /* enable the SMBus device */
1146}
1147
1148static void asus_hides_smbus_lpc_ich6_resume(struct pci_dev *dev)
1149{
1150 if (likely(!asus_hides_smbus || !asus_rcba_base))
1151 return;
1152 iounmap(asus_rcba_base);
1153 asus_rcba_base = NULL;
1117 dev_info(&dev->dev, "Enabled ICH6/i801 SMBus device\n"); 1154 dev_info(&dev->dev, "Enabled ICH6/i801 SMBus device\n");
1118} 1155}
1156
1157static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
1158{
1159 asus_hides_smbus_lpc_ich6_suspend(dev);
1160 asus_hides_smbus_lpc_ich6_resume_early(dev);
1161 asus_hides_smbus_lpc_ich6_resume(dev);
1162}
1119DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6); 1163DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6);
1120DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6); 1164DECLARE_PCI_FIXUP_SUSPEND(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_suspend);
1165DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_resume);
1166DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_resume_early);
1121 1167
1122/* 1168/*
1123 * SiS 96x south bridge: BIOS typically hides SMBus device... 1169 * SiS 96x south bridge: BIOS typically hides SMBus device...
@@ -1135,10 +1181,10 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_
1135DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus); 1181DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus);
1136DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus); 1182DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus);
1137DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus); 1183DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus);
1138DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus); 1184DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus);
1139DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus); 1185DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus);
1140DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus); 1186DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus);
1141DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus); 1187DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus);
1142 1188
1143/* 1189/*
1144 * ... This is further complicated by the fact that some SiS96x south 1190 * ... This is further complicated by the fact that some SiS96x south
@@ -1172,7 +1218,7 @@ static void quirk_sis_503(struct pci_dev *dev)
1172 quirk_sis_96x_smbus(dev); 1218 quirk_sis_96x_smbus(dev);
1173} 1219}
1174DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503); 1220DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503);
1175DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503); 1221DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503);
1176 1222
1177 1223
1178/* 1224/*
@@ -1205,7 +1251,7 @@ static void asus_hides_ac97_lpc(struct pci_dev *dev)
1205 } 1251 }
1206} 1252}
1207DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc); 1253DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc);
1208DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc); 1254DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc);
1209 1255
1210#if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE) 1256#if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE)
1211 1257
@@ -1270,12 +1316,12 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, qui
1270DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata); 1316DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata);
1271DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata); 1317DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata);
1272DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata); 1318DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata);
1273DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata); 1319DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata);
1274DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata); 1320DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata);
1275DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata); 1321DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata);
1276DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata); 1322DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata);
1277DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata); 1323DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata);
1278DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata); 1324DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata);
1279 1325
1280#endif 1326#endif
1281 1327
@@ -1521,6 +1567,10 @@ extern struct pci_fixup __start_pci_fixups_enable[];
1521extern struct pci_fixup __end_pci_fixups_enable[]; 1567extern struct pci_fixup __end_pci_fixups_enable[];
1522extern struct pci_fixup __start_pci_fixups_resume[]; 1568extern struct pci_fixup __start_pci_fixups_resume[];
1523extern struct pci_fixup __end_pci_fixups_resume[]; 1569extern struct pci_fixup __end_pci_fixups_resume[];
1570extern struct pci_fixup __start_pci_fixups_resume_early[];
1571extern struct pci_fixup __end_pci_fixups_resume_early[];
1572extern struct pci_fixup __start_pci_fixups_suspend[];
1573extern struct pci_fixup __end_pci_fixups_suspend[];
1524 1574
1525 1575
1526void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev) 1576void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
@@ -1553,6 +1603,16 @@ void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
1553 end = __end_pci_fixups_resume; 1603 end = __end_pci_fixups_resume;
1554 break; 1604 break;
1555 1605
1606 case pci_fixup_resume_early:
1607 start = __start_pci_fixups_resume_early;
1608 end = __end_pci_fixups_resume_early;
1609 break;
1610
1611 case pci_fixup_suspend:
1612 start = __start_pci_fixups_suspend;
1613 end = __end_pci_fixups_suspend;
1614 break;
1615
1556 default: 1616 default:
1557 /* stupid compiler warning, you would think with an enum... */ 1617 /* stupid compiler warning, you would think with an enum... */
1558 return; 1618 return;
@@ -1629,7 +1689,7 @@ static void quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev)
1629} 1689}
1630DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, 1690DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1631 quirk_nvidia_ck804_pcie_aer_ext_cap); 1691 quirk_nvidia_ck804_pcie_aer_ext_cap);
1632DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, 1692DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1633 quirk_nvidia_ck804_pcie_aer_ext_cap); 1693 quirk_nvidia_ck804_pcie_aer_ext_cap);
1634 1694
1635static void __devinit quirk_via_cx700_pci_parking_caching(struct pci_dev *dev) 1695static void __devinit quirk_via_cx700_pci_parking_caching(struct pci_dev *dev)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 8ddb918f5f57..827c0a520e2b 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -27,13 +27,6 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28 28
29 29
30#define DEBUG_CONFIG 1
31#if DEBUG_CONFIG
32#define DBG(x...) printk(x)
33#else
34#define DBG(x...)
35#endif
36
37static void pbus_assign_resources_sorted(struct pci_bus *bus) 30static void pbus_assign_resources_sorted(struct pci_bus *bus)
38{ 31{
39 struct pci_dev *dev; 32 struct pci_dev *dev;
@@ -81,8 +74,8 @@ void pci_setup_cardbus(struct pci_bus *bus)
81 struct pci_dev *bridge = bus->self; 74 struct pci_dev *bridge = bus->self;
82 struct pci_bus_region region; 75 struct pci_bus_region region;
83 76
84 printk("PCI: Bus %d, cardbus bridge: %s\n", 77 dev_info(&bridge->dev, "CardBus bridge, secondary bus %04x:%02x\n",
85 bus->number, pci_name(bridge)); 78 pci_domain_nr(bus), bus->number);
86 79
87 pcibios_resource_to_bus(bridge, &region, bus->resource[0]); 80 pcibios_resource_to_bus(bridge, &region, bus->resource[0]);
88 if (bus->resource[0]->flags & IORESOURCE_IO) { 81 if (bus->resource[0]->flags & IORESOURCE_IO) {
@@ -90,7 +83,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
90 * The IO resource is allocated a range twice as large as it 83 * The IO resource is allocated a range twice as large as it
91 * would normally need. This allows us to set both IO regs. 84 * would normally need. This allows us to set both IO regs.
92 */ 85 */
93 printk(KERN_INFO " IO window: 0x%08lx-0x%08lx\n", 86 dev_info(&bridge->dev, " IO window: %#08lx-%#08lx\n",
94 (unsigned long)region.start, 87 (unsigned long)region.start,
95 (unsigned long)region.end); 88 (unsigned long)region.end);
96 pci_write_config_dword(bridge, PCI_CB_IO_BASE_0, 89 pci_write_config_dword(bridge, PCI_CB_IO_BASE_0,
@@ -101,7 +94,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
101 94
102 pcibios_resource_to_bus(bridge, &region, bus->resource[1]); 95 pcibios_resource_to_bus(bridge, &region, bus->resource[1]);
103 if (bus->resource[1]->flags & IORESOURCE_IO) { 96 if (bus->resource[1]->flags & IORESOURCE_IO) {
104 printk(KERN_INFO " IO window: 0x%08lx-0x%08lx\n", 97 dev_info(&bridge->dev, " IO window: %#08lx-%#08lx\n",
105 (unsigned long)region.start, 98 (unsigned long)region.start,
106 (unsigned long)region.end); 99 (unsigned long)region.end);
107 pci_write_config_dword(bridge, PCI_CB_IO_BASE_1, 100 pci_write_config_dword(bridge, PCI_CB_IO_BASE_1,
@@ -112,7 +105,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
112 105
113 pcibios_resource_to_bus(bridge, &region, bus->resource[2]); 106 pcibios_resource_to_bus(bridge, &region, bus->resource[2]);
114 if (bus->resource[2]->flags & IORESOURCE_MEM) { 107 if (bus->resource[2]->flags & IORESOURCE_MEM) {
115 printk(KERN_INFO " PREFETCH window: 0x%08lx-0x%08lx\n", 108 dev_info(&bridge->dev, " PREFETCH window: %#08lx-%#08lx\n",
116 (unsigned long)region.start, 109 (unsigned long)region.start,
117 (unsigned long)region.end); 110 (unsigned long)region.end);
118 pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0, 111 pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0,
@@ -123,7 +116,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
123 116
124 pcibios_resource_to_bus(bridge, &region, bus->resource[3]); 117 pcibios_resource_to_bus(bridge, &region, bus->resource[3]);
125 if (bus->resource[3]->flags & IORESOURCE_MEM) { 118 if (bus->resource[3]->flags & IORESOURCE_MEM) {
126 printk(KERN_INFO " MEM window: 0x%08lx-0x%08lx\n", 119 dev_info(&bridge->dev, " MEM window: %#08lx-%#08lx\n",
127 (unsigned long)region.start, 120 (unsigned long)region.start,
128 (unsigned long)region.end); 121 (unsigned long)region.end);
129 pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1, 122 pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1,
@@ -151,7 +144,8 @@ static void pci_setup_bridge(struct pci_bus *bus)
151 struct pci_bus_region region; 144 struct pci_bus_region region;
152 u32 l, bu, lu, io_upper16; 145 u32 l, bu, lu, io_upper16;
153 146
154 DBG(KERN_INFO "PCI: Bridge: %s\n", pci_name(bridge)); 147 dev_info(&bridge->dev, "PCI bridge, secondary bus %04x:%02x\n",
148 pci_domain_nr(bus), bus->number);
155 149
156 /* Set up the top and bottom of the PCI I/O segment for this bus. */ 150 /* Set up the top and bottom of the PCI I/O segment for this bus. */
157 pcibios_resource_to_bus(bridge, &region, bus->resource[0]); 151 pcibios_resource_to_bus(bridge, &region, bus->resource[0]);
@@ -162,7 +156,7 @@ static void pci_setup_bridge(struct pci_bus *bus)
162 l |= region.end & 0xf000; 156 l |= region.end & 0xf000;
163 /* Set up upper 16 bits of I/O base/limit. */ 157 /* Set up upper 16 bits of I/O base/limit. */
164 io_upper16 = (region.end & 0xffff0000) | (region.start >> 16); 158 io_upper16 = (region.end & 0xffff0000) | (region.start >> 16);
165 DBG(KERN_INFO " IO window: %04lx-%04lx\n", 159 dev_info(&bridge->dev, " IO window: %#04lx-%#04lx\n",
166 (unsigned long)region.start, 160 (unsigned long)region.start,
167 (unsigned long)region.end); 161 (unsigned long)region.end);
168 } 162 }
@@ -170,7 +164,7 @@ static void pci_setup_bridge(struct pci_bus *bus)
170 /* Clear upper 16 bits of I/O base/limit. */ 164 /* Clear upper 16 bits of I/O base/limit. */
171 io_upper16 = 0; 165 io_upper16 = 0;
172 l = 0x00f0; 166 l = 0x00f0;
173 DBG(KERN_INFO " IO window: disabled.\n"); 167 dev_info(&bridge->dev, " IO window: disabled\n");
174 } 168 }
175 /* Temporarily disable the I/O range before updating PCI_IO_BASE. */ 169 /* Temporarily disable the I/O range before updating PCI_IO_BASE. */
176 pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, 0x0000ffff); 170 pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, 0x0000ffff);
@@ -185,13 +179,13 @@ static void pci_setup_bridge(struct pci_bus *bus)
185 if (bus->resource[1]->flags & IORESOURCE_MEM) { 179 if (bus->resource[1]->flags & IORESOURCE_MEM) {
186 l = (region.start >> 16) & 0xfff0; 180 l = (region.start >> 16) & 0xfff0;
187 l |= region.end & 0xfff00000; 181 l |= region.end & 0xfff00000;
188 DBG(KERN_INFO " MEM window: 0x%08lx-0x%08lx\n", 182 dev_info(&bridge->dev, " MEM window: %#08lx-%#08lx\n",
189 (unsigned long)region.start, 183 (unsigned long)region.start,
190 (unsigned long)region.end); 184 (unsigned long)region.end);
191 } 185 }
192 else { 186 else {
193 l = 0x0000fff0; 187 l = 0x0000fff0;
194 DBG(KERN_INFO " MEM window: disabled.\n"); 188 dev_info(&bridge->dev, " MEM window: disabled\n");
195 } 189 }
196 pci_write_config_dword(bridge, PCI_MEMORY_BASE, l); 190 pci_write_config_dword(bridge, PCI_MEMORY_BASE, l);
197 191
@@ -208,13 +202,13 @@ static void pci_setup_bridge(struct pci_bus *bus)
208 l |= region.end & 0xfff00000; 202 l |= region.end & 0xfff00000;
209 bu = upper_32_bits(region.start); 203 bu = upper_32_bits(region.start);
210 lu = upper_32_bits(region.end); 204 lu = upper_32_bits(region.end);
211 DBG(KERN_INFO " PREFETCH window: 0x%016llx-0x%016llx\n", 205 dev_info(&bridge->dev, " PREFETCH window: %#016llx-%#016llx\n",
212 (unsigned long long)region.start, 206 (unsigned long long)region.start,
213 (unsigned long long)region.end); 207 (unsigned long long)region.end);
214 } 208 }
215 else { 209 else {
216 l = 0x0000fff0; 210 l = 0x0000fff0;
217 DBG(KERN_INFO " PREFETCH window: disabled.\n"); 211 dev_info(&bridge->dev, " PREFETCH window: disabled\n");
218 } 212 }
219 pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, l); 213 pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, l);
220 214
@@ -361,9 +355,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long
361 align = (i < PCI_BRIDGE_RESOURCES) ? r_size : r->start; 355 align = (i < PCI_BRIDGE_RESOURCES) ? r_size : r->start;
362 order = __ffs(align) - 20; 356 order = __ffs(align) - 20;
363 if (order > 11) { 357 if (order > 11) {
364 printk(KERN_WARNING "PCI: region %s/%d " 358 dev_warn(&dev->dev, "BAR %d too large: "
365 "too large: 0x%016llx-0x%016llx\n", 359 "%#016llx-%#016llx\n", i,
366 pci_name(dev), i,
367 (unsigned long long)r->start, 360 (unsigned long long)r->start,
368 (unsigned long long)r->end); 361 (unsigned long long)r->end);
369 r->flags = 0; 362 r->flags = 0;
@@ -529,8 +522,8 @@ void __ref pci_bus_assign_resources(struct pci_bus *bus)
529 break; 522 break;
530 523
531 default: 524 default:
532 printk(KERN_INFO "PCI: not setting up bridge %s " 525 dev_info(&dev->dev, "not setting up bridge for bus "
533 "for bus %d\n", pci_name(dev), b->number); 526 "%04x:%02x\n", pci_domain_nr(b), b->number);
534 break; 527 break;
535 } 528 }
536 } 529 }
diff --git a/drivers/pci/setup-irq.c b/drivers/pci/setup-irq.c
index 05ca2ed9eb51..aa795fd428de 100644
--- a/drivers/pci/setup-irq.c
+++ b/drivers/pci/setup-irq.c
@@ -47,8 +47,7 @@ pdev_fixup_irq(struct pci_dev *dev,
47 } 47 }
48 dev->irq = irq; 48 dev->irq = irq;
49 49
50 pr_debug("PCI: fixup irq: (%s) got %d\n", 50 dev_dbg(&dev->dev, "fixup irq: got %d\n", dev->irq);
51 kobject_name(&dev->dev.kobj), dev->irq);
52 51
53 /* Always tell the device, so the driver knows what is 52 /* Always tell the device, so the driver knows what is
54 the real IRQ to use; the device does not use it. */ 53 the real IRQ to use; the device does not use it. */
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 7d35cdf4579f..1a5fc83c71b3 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -26,8 +26,7 @@
26#include "pci.h" 26#include "pci.h"
27 27
28 28
29void 29void pci_update_resource(struct pci_dev *dev, struct resource *res, int resno)
30pci_update_resource(struct pci_dev *dev, struct resource *res, int resno)
31{ 30{
32 struct pci_bus_region region; 31 struct pci_bus_region region;
33 u32 new, check, mask; 32 u32 new, check, mask;
@@ -43,20 +42,20 @@ pci_update_resource(struct pci_dev *dev, struct resource *res, int resno)
43 /* 42 /*
44 * Ignore non-moveable resources. This might be legacy resources for 43 * Ignore non-moveable resources. This might be legacy resources for
45 * which no functional BAR register exists or another important 44 * which no functional BAR register exists or another important
46 * system resource we should better not move around in system address 45 * system resource we shouldn't move around.
47 * space.
48 */ 46 */
49 if (res->flags & IORESOURCE_PCI_FIXED) 47 if (res->flags & IORESOURCE_PCI_FIXED)
50 return; 48 return;
51 49
52 pcibios_resource_to_bus(dev, &region, res); 50 pcibios_resource_to_bus(dev, &region, res);
53 51
54 pr_debug(" got res [%llx:%llx] bus [%llx:%llx] flags %lx for " 52 dev_dbg(&dev->dev, "BAR %d: got res [%#llx-%#llx] bus [%#llx-%#llx] "
55 "BAR %d of %s\n", (unsigned long long)res->start, 53 "flags %#lx\n", resno,
54 (unsigned long long)res->start,
56 (unsigned long long)res->end, 55 (unsigned long long)res->end,
57 (unsigned long long)region.start, 56 (unsigned long long)region.start,
58 (unsigned long long)region.end, 57 (unsigned long long)region.end,
59 (unsigned long)res->flags, resno, pci_name(dev)); 58 (unsigned long)res->flags);
60 59
61 new = region.start | (res->flags & PCI_REGION_FLAG_MASK); 60 new = region.start | (res->flags & PCI_REGION_FLAG_MASK);
62 if (res->flags & IORESOURCE_IO) 61 if (res->flags & IORESOURCE_IO)
@@ -81,9 +80,8 @@ pci_update_resource(struct pci_dev *dev, struct resource *res, int resno)
81 pci_read_config_dword(dev, reg, &check); 80 pci_read_config_dword(dev, reg, &check);
82 81
83 if ((new ^ check) & mask) { 82 if ((new ^ check) & mask) {
84 printk(KERN_ERR "PCI: Error while updating region " 83 dev_err(&dev->dev, "BAR %d: error updating (%#08x != %#08x)\n",
85 "%s/%d (%08x != %08x)\n", pci_name(dev), resno, 84 resno, new, check);
86 new, check);
87 } 85 }
88 86
89 if ((new & (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK)) == 87 if ((new & (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK)) ==
@@ -92,15 +90,14 @@ pci_update_resource(struct pci_dev *dev, struct resource *res, int resno)
92 pci_write_config_dword(dev, reg + 4, new); 90 pci_write_config_dword(dev, reg + 4, new);
93 pci_read_config_dword(dev, reg + 4, &check); 91 pci_read_config_dword(dev, reg + 4, &check);
94 if (check != new) { 92 if (check != new) {
95 printk(KERN_ERR "PCI: Error updating region " 93 dev_err(&dev->dev, "BAR %d: error updating "
96 "%s/%d (high %08x != %08x)\n", 94 "(high %#08x != %#08x)\n", resno, new, check);
97 pci_name(dev), resno, new, check);
98 } 95 }
99 } 96 }
100 res->flags &= ~IORESOURCE_UNSET; 97 res->flags &= ~IORESOURCE_UNSET;
101 pr_debug("PCI: moved device %s resource %d (%lx) to %x\n", 98 dev_dbg(&dev->dev, "BAR %d: moved to bus [%#llx-%#llx] flags %#lx\n",
102 pci_name(dev), resno, res->flags, 99 resno, (unsigned long long)region.start,
103 new & ~PCI_REGION_FLAG_MASK); 100 (unsigned long long)region.end, res->flags);
104} 101}
105 102
106int pci_claim_resource(struct pci_dev *dev, int resource) 103int pci_claim_resource(struct pci_dev *dev, int resource)
@@ -117,10 +114,11 @@ int pci_claim_resource(struct pci_dev *dev, int resource)
117 err = insert_resource(root, res); 114 err = insert_resource(root, res);
118 115
119 if (err) { 116 if (err) {
120 printk(KERN_ERR "PCI: %s region %d of %s %s [%llx:%llx]\n", 117 dev_err(&dev->dev, "BAR %d: %s of %s [%#llx-%#llx]\n",
121 root ? "Address space collision on" : 118 resource,
122 "No parent found for", 119 root ? "address space collision on" :
123 resource, dtype, pci_name(dev), 120 "no parent found for",
121 dtype,
124 (unsigned long long)res->start, 122 (unsigned long long)res->start,
125 (unsigned long long)res->end); 123 (unsigned long long)res->end);
126 } 124 }
@@ -140,11 +138,10 @@ int pci_assign_resource(struct pci_dev *dev, int resno)
140 138
141 align = resource_alignment(res); 139 align = resource_alignment(res);
142 if (!align) { 140 if (!align) {
143 printk(KERN_ERR "PCI: Cannot allocate resource (bogus " 141 dev_err(&dev->dev, "BAR %d: can't allocate resource (bogus "
144 "alignment) %d [%llx:%llx] (flags %lx) of %s\n", 142 "alignment) [%#llx-%#llx] flags %#lx\n",
145 resno, (unsigned long long)res->start, 143 resno, (unsigned long long)res->start,
146 (unsigned long long)res->end, res->flags, 144 (unsigned long long)res->end, res->flags);
147 pci_name(dev));
148 return -EINVAL; 145 return -EINVAL;
149 } 146 }
150 147
@@ -165,11 +162,11 @@ int pci_assign_resource(struct pci_dev *dev, int resno)
165 } 162 }
166 163
167 if (ret) { 164 if (ret) {
168 printk(KERN_ERR "PCI: Failed to allocate %s resource " 165 dev_err(&dev->dev, "BAR %d: can't allocate %s resource "
169 "#%d:%llx@%llx for %s\n", 166 "[%#llx-%#llx]\n", resno,
170 res->flags & IORESOURCE_IO ? "I/O" : "mem", 167 res->flags & IORESOURCE_IO ? "I/O" : "mem",
171 resno, (unsigned long long)size, 168 (unsigned long long)res->start,
172 (unsigned long long)res->start, pci_name(dev)); 169 (unsigned long long)res->end);
173 } else { 170 } else {
174 res->flags &= ~IORESOURCE_STARTALIGN; 171 res->flags &= ~IORESOURCE_STARTALIGN;
175 if (resno < PCI_BRIDGE_RESOURCES) 172 if (resno < PCI_BRIDGE_RESOURCES)
@@ -205,11 +202,11 @@ int pci_assign_resource_fixed(struct pci_dev *dev, int resno)
205 } 202 }
206 203
207 if (ret) { 204 if (ret) {
208 printk(KERN_ERR "PCI: Failed to allocate %s resource " 205 dev_err(&dev->dev, "BAR %d: can't allocate %s resource "
209 "#%d:%llx@%llx for %s\n", 206 "[%#llx-%#llx\n]", resno,
210 res->flags & IORESOURCE_IO ? "I/O" : "mem", 207 res->flags & IORESOURCE_IO ? "I/O" : "mem",
211 resno, (unsigned long long)(res->end - res->start + 1), 208 (unsigned long long)res->start,
212 (unsigned long long)res->start, pci_name(dev)); 209 (unsigned long long)res->end);
213 } else if (resno < PCI_BRIDGE_RESOURCES) { 210 } else if (resno < PCI_BRIDGE_RESOURCES) {
214 pci_update_resource(dev, res, resno); 211 pci_update_resource(dev, res, resno);
215 } 212 }
@@ -239,11 +236,10 @@ void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
239 236
240 r_align = resource_alignment(r); 237 r_align = resource_alignment(r);
241 if (!r_align) { 238 if (!r_align) {
242 printk(KERN_WARNING "PCI: bogus alignment of resource " 239 dev_warn(&dev->dev, "BAR %d: bogus alignment "
243 "%d [%llx:%llx] (flags %lx) of %s\n", 240 "[%#llx-%#llx] flags %#lx\n",
244 i, (unsigned long long)r->start, 241 i, (unsigned long long)r->start,
245 (unsigned long long)r->end, r->flags, 242 (unsigned long long)r->end, r->flags);
246 pci_name(dev));
247 continue; 243 continue;
248 } 244 }
249 for (list = head; ; list = list->next) { 245 for (list = head; ; list = list->next) {
@@ -291,7 +287,7 @@ int pci_enable_resources(struct pci_dev *dev, int mask)
291 287
292 if (!r->parent) { 288 if (!r->parent) {
293 dev_err(&dev->dev, "device not available because of " 289 dev_err(&dev->dev, "device not available because of "
294 "BAR %d [%llx:%llx] collisions\n", i, 290 "BAR %d [%#llx-%#llx] collisions\n", i,
295 (unsigned long long) r->start, 291 (unsigned long long) r->start,
296 (unsigned long long) r->end); 292 (unsigned long long) r->end);
297 return -EINVAL; 293 return -EINVAL;
diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
new file mode 100644
index 000000000000..7e5b85cbd948
--- /dev/null
+++ b/drivers/pci/slot.c
@@ -0,0 +1,233 @@
1/*
2 * drivers/pci/slot.c
3 * Copyright (C) 2006 Matthew Wilcox <matthew@wil.cx>
4 * Copyright (C) 2006-2008 Hewlett-Packard Development Company, L.P.
5 * Alex Chiang <achiang@hp.com>
6 */
7
8#include <linux/kobject.h>
9#include <linux/pci.h>
10#include <linux/err.h>
11#include "pci.h"
12
13struct kset *pci_slots_kset;
14EXPORT_SYMBOL_GPL(pci_slots_kset);
15
16static ssize_t pci_slot_attr_show(struct kobject *kobj,
17 struct attribute *attr, char *buf)
18{
19 struct pci_slot *slot = to_pci_slot(kobj);
20 struct pci_slot_attribute *attribute = to_pci_slot_attr(attr);
21 return attribute->show ? attribute->show(slot, buf) : -EIO;
22}
23
24static ssize_t pci_slot_attr_store(struct kobject *kobj,
25 struct attribute *attr, const char *buf, size_t len)
26{
27 struct pci_slot *slot = to_pci_slot(kobj);
28 struct pci_slot_attribute *attribute = to_pci_slot_attr(attr);
29 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
30}
31
32static struct sysfs_ops pci_slot_sysfs_ops = {
33 .show = pci_slot_attr_show,
34 .store = pci_slot_attr_store,
35};
36
37static ssize_t address_read_file(struct pci_slot *slot, char *buf)
38{
39 if (slot->number == 0xff)
40 return sprintf(buf, "%04x:%02x\n",
41 pci_domain_nr(slot->bus),
42 slot->bus->number);
43 else
44 return sprintf(buf, "%04x:%02x:%02x\n",
45 pci_domain_nr(slot->bus),
46 slot->bus->number,
47 slot->number);
48}
49
50static void pci_slot_release(struct kobject *kobj)
51{
52 struct pci_slot *slot = to_pci_slot(kobj);
53
54 pr_debug("%s: releasing pci_slot on %x:%d\n", __func__,
55 slot->bus->number, slot->number);
56
57 list_del(&slot->list);
58
59 kfree(slot);
60}
61
62static struct pci_slot_attribute pci_slot_attr_address =
63 __ATTR(address, (S_IFREG | S_IRUGO), address_read_file, NULL);
64
65static struct attribute *pci_slot_default_attrs[] = {
66 &pci_slot_attr_address.attr,
67 NULL,
68};
69
70static struct kobj_type pci_slot_ktype = {
71 .sysfs_ops = &pci_slot_sysfs_ops,
72 .release = &pci_slot_release,
73 .default_attrs = pci_slot_default_attrs,
74};
75
76/**
77 * pci_create_slot - create or increment refcount for physical PCI slot
78 * @parent: struct pci_bus of parent bridge
79 * @slot_nr: PCI_SLOT(pci_dev->devfn) or -1 for placeholder
80 * @name: user visible string presented in /sys/bus/pci/slots/<name>
81 *
82 * PCI slots have first class attributes such as address, speed, width,
83 * and a &struct pci_slot is used to manage them. This interface will
84 * either return a new &struct pci_slot to the caller, or if the pci_slot
85 * already exists, its refcount will be incremented.
86 *
87 * Slots are uniquely identified by a @pci_bus, @slot_nr, @name tuple.
88 *
89 * Placeholder slots:
90 * In most cases, @pci_bus, @slot_nr will be sufficient to uniquely identify
91 * a slot. There is one notable exception - pSeries (rpaphp), where the
92 * @slot_nr cannot be determined until a device is actually inserted into
93 * the slot. In this scenario, the caller may pass -1 for @slot_nr.
94 *
95 * The following semantics are imposed when the caller passes @slot_nr ==
96 * -1. First, the check for existing %struct pci_slot is skipped, as the
97 * caller may know about several unpopulated slots on a given %struct
98 * pci_bus, and each slot would have a @slot_nr of -1. Uniqueness for
99 * these slots is then determined by the @name parameter. We expect
100 * kobject_init_and_add() to warn us if the caller attempts to create
101 * multiple slots with the same name. The other change in semantics is
102 * user-visible, which is the 'address' parameter presented in sysfs will
103 * consist solely of a dddd:bb tuple, where dddd is the PCI domain of the
104 * %struct pci_bus and bb is the bus number. In other words, the devfn of
105 * the 'placeholder' slot will not be displayed.
106 */
107
108struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
109 const char *name)
110{
111 struct pci_slot *slot;
112 int err;
113
114 down_write(&pci_bus_sem);
115
116 if (slot_nr == -1)
117 goto placeholder;
118
119 /* If we've already created this slot, bump refcount and return. */
120 list_for_each_entry(slot, &parent->slots, list) {
121 if (slot->number == slot_nr) {
122 kobject_get(&slot->kobj);
123 pr_debug("%s: inc refcount to %d on %04x:%02x:%02x\n",
124 __func__,
125 atomic_read(&slot->kobj.kref.refcount),
126 pci_domain_nr(parent), parent->number,
127 slot_nr);
128 goto out;
129 }
130 }
131
132placeholder:
133 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
134 if (!slot) {
135 slot = ERR_PTR(-ENOMEM);
136 goto out;
137 }
138
139 slot->bus = parent;
140 slot->number = slot_nr;
141
142 slot->kobj.kset = pci_slots_kset;
143 err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL,
144 "%s", name);
145 if (err) {
146 printk(KERN_ERR "Unable to register kobject %s\n", name);
147 goto err;
148 }
149
150 INIT_LIST_HEAD(&slot->list);
151 list_add(&slot->list, &parent->slots);
152
153 /* Don't care if debug printk has a -1 for slot_nr */
154 pr_debug("%s: created pci_slot on %04x:%02x:%02x\n",
155 __func__, pci_domain_nr(parent), parent->number, slot_nr);
156
157 out:
158 up_write(&pci_bus_sem);
159 return slot;
160 err:
161 kfree(slot);
162 slot = ERR_PTR(err);
163 goto out;
164}
165EXPORT_SYMBOL_GPL(pci_create_slot);
166
167/**
168 * pci_update_slot_number - update %struct pci_slot -> number
169 * @slot - %struct pci_slot to update
170 * @slot_nr - new number for slot
171 *
172 * The primary purpose of this interface is to allow callers who earlier
173 * created a placeholder slot in pci_create_slot() by passing a -1 as
174 * slot_nr, to update their %struct pci_slot with the correct @slot_nr.
175 */
176
177void pci_update_slot_number(struct pci_slot *slot, int slot_nr)
178{
179 int name_count = 0;
180 struct pci_slot *tmp;
181
182 down_write(&pci_bus_sem);
183
184 list_for_each_entry(tmp, &slot->bus->slots, list) {
185 WARN_ON(tmp->number == slot_nr);
186 if (!strcmp(kobject_name(&tmp->kobj), kobject_name(&slot->kobj)))
187 name_count++;
188 }
189
190 if (name_count > 1)
191 printk(KERN_WARNING "pci_update_slot_number found %d slots with the same name: %s\n", name_count, kobject_name(&slot->kobj));
192
193 slot->number = slot_nr;
194 up_write(&pci_bus_sem);
195}
196EXPORT_SYMBOL_GPL(pci_update_slot_number);
197
198/**
199 * pci_destroy_slot - decrement refcount for physical PCI slot
200 * @slot: struct pci_slot to decrement
201 *
202 * %struct pci_slot is refcounted, so destroying them is really easy; we
203 * just call kobject_put on its kobj and let our release methods do the
204 * rest.
205 */
206
207void pci_destroy_slot(struct pci_slot *slot)
208{
209 pr_debug("%s: dec refcount to %d on %04x:%02x:%02x\n", __func__,
210 atomic_read(&slot->kobj.kref.refcount) - 1,
211 pci_domain_nr(slot->bus), slot->bus->number, slot->number);
212
213 down_write(&pci_bus_sem);
214 kobject_put(&slot->kobj);
215 up_write(&pci_bus_sem);
216}
217EXPORT_SYMBOL_GPL(pci_destroy_slot);
218
219static int pci_slot_init(void)
220{
221 struct kset *pci_bus_kset;
222
223 pci_bus_kset = bus_get_kset(&pci_bus_type);
224 pci_slots_kset = kset_create_and_add("slots", NULL,
225 &pci_bus_kset->kobj);
226 if (!pci_slots_kset) {
227 printk(KERN_ERR "PCI: Slot initialization failure\n");
228 return -ENOMEM;
229 }
230 return 0;
231}
232
233subsys_initcall(pci_slot_init);