From 1c0c5443de5f1f03ae2abce569fb673377f0fd0e Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:37:02 +0100 Subject: ACPI / hotplug / PCI: Simplify disable_slot() After recent PCI core changes related to the rescan/remove locking, the ACPIPHP's disable_slot() function is only called under the general PCI rescan/remove lock, so it doesn't have to use dev_in_slot() any more to avoid race conditions. Make it simply walk the devices on the bus and drop the ones in the slot being disabled and drop dev_in_slot() which has no more users. Moreover, to avoid problems described in the changelog of commit 29ed1f29b68a (PCI: pciehp: Fix null pointer deref when hot-removing SR-IOV device), make disable_slot() carry out the list walk in reverse order. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp_glue.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index e2a783fdb98f..f24c19c8f8c4 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -625,32 +625,15 @@ static void __ref enable_slot(struct acpiphp_slot *slot) } } -/* return first device in slot, acquiring a reference on it */ -static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot) -{ - struct pci_bus *bus = slot->bus; - struct pci_dev *dev; - struct pci_dev *ret = NULL; - - down_read(&pci_bus_sem); - list_for_each_entry(dev, &bus->devices, bus_list) - if (PCI_SLOT(dev->devfn) == slot->device) { - ret = pci_dev_get(dev); - break; - } - up_read(&pci_bus_sem); - - return ret; -} - /** * disable_slot - disable a slot * @slot: ACPI PHP slot */ static void disable_slot(struct acpiphp_slot *slot) { + struct pci_bus *bus = slot->bus; + struct pci_dev *dev, *prev; struct acpiphp_func *func; - struct pci_dev *pdev; /* * enable_slot() enumerates all functions in this device via @@ -658,10 +641,9 @@ static void disable_slot(struct acpiphp_slot *slot) * methods (_EJ0, etc.) or not. Therefore, we remove all functions * here. */ - while ((pdev = dev_in_slot(slot))) { - pci_stop_and_remove_bus_device(pdev); - pci_dev_put(pdev); - } + list_for_each_entry_safe_reverse(dev, prev, &bus->devices, bus_list) + if (PCI_SLOT(dev->devfn) == slot->device) + pci_stop_and_remove_bus_device(dev); list_for_each_entry(func, &slot->funcs, sibling) acpiphp_bus_trim(func_to_handle(func)); -- cgit v1.2.3 From 454481adf54417ef59b97e92ccb3dc69f3cd02c7 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:37:35 +0100 Subject: ACPI / hotplug / PCI: Proper kerneldoc comments for enumeration/removal Add proper kerneldoc comments describing acpiphp_enumerate_slots() and acpiphp_remove_slots(). Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp_glue.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index f24c19c8f8c4..4bc716b2bbaa 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -1001,9 +1001,12 @@ static void handle_hotplug_event(acpi_handle handle, u32 type, void *data) acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL); } -/* - * Create hotplug slots for the PCI bus. - * It should always return 0 to avoid skipping following notifiers. +/** + * acpiphp_enumerate_slots - Enumerate PCI slots for a given bus. + * @bus: PCI bus to enumerate the slots for. + * + * A "slot" is an object associated with a PCI device number. All functions + * (PCI devices) with the same bus and device number belong to the same slot. */ void acpiphp_enumerate_slots(struct pci_bus *bus) { @@ -1076,7 +1079,10 @@ void acpiphp_enumerate_slots(struct pci_bus *bus) } } -/* Destroy hotplug slots associated with the PCI bus */ +/** + * acpiphp_remove_slots - Remove slot objects associated with a given bus. + * @bus: PCI bus to remove the slot objects for. + */ void acpiphp_remove_slots(struct pci_bus *bus) { struct acpiphp_bridge *bridge; -- cgit v1.2.3 From 146fc68a4bdd78e49d56f1530f6b8072034cf3ef Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:38:15 +0100 Subject: ACPI / hotplug / PCI: Simplify register_slot() The err label in register_slot() is only jumped to from one place, so move the code under the label to that place and drop the label. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp_glue.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 4bc716b2bbaa..c97454c74c26 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -335,8 +335,10 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL); if (!slot) { - status = AE_NO_MEMORY; - goto err; + mutex_lock(&acpiphp_context_lock); + acpiphp_put_context(context); + mutex_unlock(&acpiphp_context_lock); + return AE_NO_MEMORY; } slot->bus = bridge->pci_bus; @@ -404,12 +406,6 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, } return AE_OK; - - err: - mutex_lock(&acpiphp_context_lock); - acpiphp_put_context(context); - mutex_unlock(&acpiphp_context_lock); - return status; } static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) -- cgit v1.2.3 From 4dc3082dc1dd1415177d71f15d4b19bebb1365c0 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:38:52 +0100 Subject: ACPI / hotplug / PCI: Drop acpiphp_bus_trim() If trim_stale_devices() calls acpi_bus_trim() directly, we can save a potentially costly acpi_bus_get_device() invocation. After making that change acpiphp_bus_trim() would only be called from one place, so move the code from it to that place and drop it. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp_glue.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index c97454c74c26..caeef648287a 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -488,19 +488,6 @@ static unsigned char acpiphp_max_busnr(struct pci_bus *bus) return max; } -/** - * acpiphp_bus_trim - Trim device objects in an ACPI namespace subtree. - * @handle: ACPI device object handle to start from. - */ -static void acpiphp_bus_trim(acpi_handle handle) -{ - struct acpi_device *adev = NULL; - - acpi_bus_get_device(handle, &adev); - if (adev) - acpi_bus_trim(adev); -} - /** * acpiphp_bus_add - Scan ACPI namespace subtree. * @handle: ACPI object handle to start the scan from. @@ -641,8 +628,12 @@ static void disable_slot(struct acpiphp_slot *slot) if (PCI_SLOT(dev->devfn) == slot->device) pci_stop_and_remove_bus_device(dev); - list_for_each_entry(func, &slot->funcs, sibling) - acpiphp_bus_trim(func_to_handle(func)); + list_for_each_entry(func, &slot->funcs, sibling) { + struct acpi_device *adev; + + if (!acpi_bus_get_device(func_to_handle(func), &adev)) + acpi_bus_trim(adev); + } slot->flags &= (~SLOT_ENABLED); } @@ -714,11 +705,12 @@ static unsigned int get_slot_status(struct acpiphp_slot *slot) */ static void trim_stale_devices(struct pci_dev *dev) { - acpi_handle handle = ACPI_HANDLE(&dev->dev); + struct acpi_device *adev = ACPI_COMPANION(&dev->dev); struct pci_bus *bus = dev->subordinate; bool alive = false; - if (handle) { + if (adev) { + acpi_handle handle = adev->handle; acpi_status status; unsigned long long sta; @@ -734,8 +726,8 @@ static void trim_stale_devices(struct pci_dev *dev) } if (!alive) { pci_stop_and_remove_bus_device(dev); - if (handle) - acpiphp_bus_trim(handle); + if (adev) + acpi_bus_trim(adev); } else if (bus) { struct pci_dev *child, *tmp; -- cgit v1.2.3 From b2118d6a4073e394312072b6666cb576e18653b2 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:39:20 +0100 Subject: ACPI / hotplug / PCI: Rework acpiphp_no_hotplug() If a struct acpi_device pointer is passed to acpiphp_no_hotplug() instead of an ACPI handle, the function won't need to call acpi_bus_get_device(), which may be costly, any more. Then, trim_stale_devices() can call acpiphp_no_hotplug() passing the struct acpi_device object it already has directly to that function. Make those changes and update slot_no_hotplug() accordingly. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp_glue.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index caeef648287a..a0d6c83ac27b 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -638,11 +638,8 @@ static void disable_slot(struct acpiphp_slot *slot) slot->flags &= (~SLOT_ENABLED); } -static bool acpiphp_no_hotplug(acpi_handle handle) +static bool acpiphp_no_hotplug(struct acpi_device *adev) { - struct acpi_device *adev = NULL; - - acpi_bus_get_device(handle, &adev); return adev && adev->flags.no_hotplug; } @@ -650,10 +647,13 @@ static bool slot_no_hotplug(struct acpiphp_slot *slot) { struct acpiphp_func *func; - list_for_each_entry(func, &slot->funcs, sibling) - if (acpiphp_no_hotplug(func_to_handle(func))) - return true; + list_for_each_entry(func, &slot->funcs, sibling) { + struct acpi_device *adev = NULL; + acpi_bus_get_device(func_to_handle(func), &adev); + if (acpiphp_no_hotplug(adev)) + return true; + } return false; } @@ -710,13 +710,12 @@ static void trim_stale_devices(struct pci_dev *dev) bool alive = false; if (adev) { - acpi_handle handle = adev->handle; acpi_status status; unsigned long long sta; - status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); + status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta); alive = (ACPI_SUCCESS(status) && sta == ACPI_STA_ALL) - || acpiphp_no_hotplug(handle); + || acpiphp_no_hotplug(adev); } if (!alive) { u32 v; -- cgit v1.2.3 From bbcbfc0eed6220591ccc5752edd079099bb1920c Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:39:33 +0100 Subject: ACPI / hotplug / PCI: Store acpi_device pointer in acpiphp_context After recent modifications of the ACPI core making it create a struct acpi_device object for every namespace node representing a device regardless of the current status of that device the ACPIPHP code can store a struct acpi_device pointer instead of an ACPI handle in struct acpiphp_context. This immediately makes it possible to avoid making potentially costly calls to acpi_bus_get_device() in two places and allows some more simplifications to be made going forward. The reason why that is correct is because ACPIPHP only installs hotify handlers for namespace nodes that exist when acpiphp_enumerate_slots() is called for their parent bridge. That only happens if the parent bridge has an ACPI companion associated with it, which means that the ACPI namespace scope in question has been scanned already at that point. That, in turn, means that struct acpi_device objects have been created for all namespace nodes in that scope and pointers to those objects can be stored directly instead of their ACPI handles. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp.h | 9 ++++++-- drivers/pci/hotplug/acpiphp_glue.c | 46 ++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 26 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h index b6162be4df40..098ff425f850 100644 --- a/drivers/pci/hotplug/acpiphp.h +++ b/drivers/pci/hotplug/acpiphp.h @@ -117,8 +117,8 @@ struct acpiphp_func { }; struct acpiphp_context { - acpi_handle handle; struct acpiphp_func func; + struct acpi_device *adev; struct acpiphp_bridge *bridge; unsigned int refcount; }; @@ -128,9 +128,14 @@ static inline struct acpiphp_context *func_to_context(struct acpiphp_func *func) return container_of(func, struct acpiphp_context, func); } +static inline struct acpi_device *func_to_acpi_device(struct acpiphp_func *func) +{ + return func_to_context(func)->adev; +} + static inline acpi_handle func_to_handle(struct acpiphp_func *func) { - return func_to_context(func)->handle; + return func_to_acpi_device(func)->handle; } /* diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index a0d6c83ac27b..896a13bf2e02 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -73,11 +73,11 @@ static void acpiphp_context_handler(acpi_handle handle, void *context) /** * acpiphp_init_context - Create hotplug context and grab a reference to it. - * @handle: ACPI object handle to create the context for. + * @adev: ACPI device object to create the context for. * * Call under acpiphp_context_lock. */ -static struct acpiphp_context *acpiphp_init_context(acpi_handle handle) +static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev) { struct acpiphp_context *context; acpi_status status; @@ -86,9 +86,9 @@ static struct acpiphp_context *acpiphp_init_context(acpi_handle handle) if (!context) return NULL; - context->handle = handle; + context->adev = adev; context->refcount = 1; - status = acpi_attach_data(handle, acpiphp_context_handler, context); + status = acpi_attach_data(adev->handle, acpiphp_context_handler, context); if (ACPI_FAILURE(status)) { kfree(context); return NULL; @@ -118,7 +118,7 @@ static struct acpiphp_context *acpiphp_get_context(acpi_handle handle) /** * acpiphp_put_context - Drop a reference to ACPI hotplug context. - * @handle: ACPI object handle to put the context for. + * @context: ACPI hotplug context to drop a reference to. * * The context object is removed if there are no more references to it. * @@ -130,7 +130,7 @@ static void acpiphp_put_context(struct acpiphp_context *context) return; WARN_ON(context->bridge); - acpi_detach_data(context->handle, acpiphp_context_handler); + acpi_detach_data(context->adev->handle, acpiphp_context_handler); kfree(context); } @@ -216,7 +216,7 @@ static void dock_event(acpi_handle handle, u32 type, void *data) mutex_lock(&acpiphp_context_lock); context = acpiphp_get_context(handle); - if (!context || WARN_ON(context->handle != handle) + if (!context || WARN_ON(context->adev->handle != handle) || context->func.parent->is_going_away) { mutex_unlock(&acpiphp_context_lock); return; @@ -284,6 +284,7 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, { struct acpiphp_bridge *bridge = data; struct acpiphp_context *context; + struct acpi_device *adev; struct acpiphp_slot *slot; struct acpiphp_func *newfunc; acpi_status status = AE_OK; @@ -303,12 +304,14 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, "can't evaluate _ADR (%#x)\n", status); return AE_OK; } + if (acpi_bus_get_device(handle, &adev)) + return AE_OK; device = (adr >> 16) & 0xffff; function = adr & 0xffff; mutex_lock(&acpiphp_context_lock); - context = acpiphp_init_context(handle); + context = acpiphp_init_context(adev); if (!context) { mutex_unlock(&acpiphp_context_lock); acpi_handle_err(handle, "No hotplug context\n"); @@ -628,12 +631,8 @@ static void disable_slot(struct acpiphp_slot *slot) if (PCI_SLOT(dev->devfn) == slot->device) pci_stop_and_remove_bus_device(dev); - list_for_each_entry(func, &slot->funcs, sibling) { - struct acpi_device *adev; - - if (!acpi_bus_get_device(func_to_handle(func), &adev)) - acpi_bus_trim(adev); - } + list_for_each_entry(func, &slot->funcs, sibling) + acpi_bus_trim(func_to_acpi_device(func)); slot->flags &= (~SLOT_ENABLED); } @@ -647,13 +646,10 @@ static bool slot_no_hotplug(struct acpiphp_slot *slot) { struct acpiphp_func *func; - list_for_each_entry(func, &slot->funcs, sibling) { - struct acpi_device *adev = NULL; - - acpi_bus_get_device(func_to_handle(func), &adev); - if (acpiphp_no_hotplug(adev)) + list_for_each_entry(func, &slot->funcs, sibling) + if (acpiphp_no_hotplug(func_to_acpi_device(func))) return true; - } + return false; } @@ -908,7 +904,7 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) static void hotplug_event_work(void *data, u32 type) { struct acpiphp_context *context = data; - acpi_handle handle = context->handle; + acpi_handle handle = context->adev->handle; acpi_scan_lock_acquire(); @@ -967,7 +963,7 @@ static void handle_hotplug_event(acpi_handle handle, u32 type, void *data) mutex_lock(&acpiphp_context_lock); context = acpiphp_get_context(handle); - if (!context || WARN_ON(context->handle != handle) + if (!context || WARN_ON(context->adev->handle != handle) || context->func.parent->is_going_away) goto err_out; @@ -998,16 +994,18 @@ static void handle_hotplug_event(acpi_handle handle, u32 type, void *data) void acpiphp_enumerate_slots(struct pci_bus *bus) { struct acpiphp_bridge *bridge; + struct acpi_device *adev; acpi_handle handle; acpi_status status; if (acpiphp_disabled) return; - handle = ACPI_HANDLE(bus->bridge); - if (!handle) + adev = ACPI_COMPANION(bus->bridge); + if (!adev) return; + handle = adev->handle; bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL); if (!bridge) { acpi_handle_err(handle, "No memory for bridge object\n"); -- cgit v1.2.3 From b6708fbf98ac01d27c8d4d7f7b4fa87583b658cc Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:39:58 +0100 Subject: ACPI / hotplug / PCI: Drop acpiphp_bus_add() acpiphp_bus_add() is only called from one place, so move the code out of it into that place and drop it. Also make that code use func_to_acpi_device() to get the struct acpi_device pointer it needs instead of calling acpi_bus_get_device() which may be costly. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp_glue.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 896a13bf2e02..27abd501c258 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -491,20 +491,6 @@ static unsigned char acpiphp_max_busnr(struct pci_bus *bus) return max; } -/** - * acpiphp_bus_add - Scan ACPI namespace subtree. - * @handle: ACPI object handle to start the scan from. - */ -static void acpiphp_bus_add(acpi_handle handle) -{ - struct acpi_device *adev = NULL; - - acpi_bus_scan(handle); - acpi_bus_get_device(handle, &adev); - if (acpi_device_enumerated(adev)) - acpi_device_set_power(adev, ACPI_STATE_D0); -} - static void acpiphp_set_acpi_region(struct acpiphp_slot *slot) { struct acpiphp_func *func; @@ -544,9 +530,13 @@ static int acpiphp_rescan_slot(struct acpiphp_slot *slot) { struct acpiphp_func *func; - list_for_each_entry(func, &slot->funcs, sibling) - acpiphp_bus_add(func_to_handle(func)); + list_for_each_entry(func, &slot->funcs, sibling) { + struct acpi_device *adev = func_to_acpi_device(func); + acpi_bus_scan(adev->handle); + if (acpi_device_enumerated(adev)) + acpi_device_set_power(adev, ACPI_STATE_D0); + } return pci_scan_slot(slot->bus, PCI_DEVFN(slot->device, 0)); } -- cgit v1.2.3 From 661b40644190eb5987907584920cb11a4a2c7a9e Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:40:25 +0100 Subject: ACPI / hotplug / PCI: Drop crit_sect locking After recent PCI core changes related to the rescan/remove locking, the code sections under crit_sect mutexes from ACPIPHP slot objects are always executed under the general PCI rescan/remove lock. For this reason, the crit_sect mutexes are simply redundant, so drop them. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp.h | 1 - drivers/pci/hotplug/acpiphp_glue.c | 23 +++-------------------- 2 files changed, 3 insertions(+), 21 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h index 098ff425f850..373c7aa3b4a6 100644 --- a/drivers/pci/hotplug/acpiphp.h +++ b/drivers/pci/hotplug/acpiphp.h @@ -93,7 +93,6 @@ struct acpiphp_slot { struct list_head funcs; /* one slot may have different objects (i.e. for each function) */ struct slot *slot; - struct mutex crit_sect; u8 device; /* pci device# */ u32 flags; /* see below */ diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 27abd501c258..0961911c706e 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -347,7 +347,6 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, slot->bus = bridge->pci_bus; slot->device = device; INIT_LIST_HEAD(&slot->funcs); - mutex_init(&slot->crit_sect); list_add_tail(&slot->node, &bridge->slots); @@ -744,7 +743,6 @@ static void acpiphp_check_bridge(struct acpiphp_bridge *bridge) struct pci_bus *bus = slot->bus; struct pci_dev *dev, *tmp; - mutex_lock(&slot->crit_sect); if (slot_no_hotplug(slot)) { ; /* do nothing */ } else if (get_slot_status(slot) == ACPI_STA_ALL) { @@ -759,7 +757,6 @@ static void acpiphp_check_bridge(struct acpiphp_bridge *bridge) } else { disable_slot(slot); } - mutex_unlock(&slot->crit_sect); } } @@ -846,12 +843,8 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) } else { struct acpiphp_slot *slot = func->slot; - if (slot->flags & SLOT_IS_GOING_AWAY) - break; - - mutex_lock(&slot->crit_sect); - enable_slot(slot); - mutex_unlock(&slot->crit_sect); + if (!(slot->flags & SLOT_IS_GOING_AWAY)) + enable_slot(slot); } break; @@ -862,7 +855,6 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) acpiphp_check_bridge(bridge); } else { struct acpiphp_slot *slot = func->slot; - int ret; if (slot->flags & SLOT_IS_GOING_AWAY) break; @@ -871,10 +863,7 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) * Check if anything has changed in the slot and rescan * from the parent if that's the case. */ - mutex_lock(&slot->crit_sect); - ret = acpiphp_rescan_slot(slot); - mutex_unlock(&slot->crit_sect); - if (ret) + if (acpiphp_rescan_slot(slot)) acpiphp_check_bridge(func->parent); } break; @@ -1088,13 +1077,10 @@ int acpiphp_enable_slot(struct acpiphp_slot *slot) if (slot->flags & SLOT_IS_GOING_AWAY) return -ENODEV; - mutex_lock(&slot->crit_sect); /* configure all functions */ if (!(slot->flags & SLOT_ENABLED)) enable_slot(slot); - mutex_unlock(&slot->crit_sect); - pci_unlock_rescan_remove(); return 0; } @@ -1110,8 +1096,6 @@ static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot) if (slot->flags & SLOT_IS_GOING_AWAY) return -ENODEV; - mutex_lock(&slot->crit_sect); - /* unconfigure all functions */ disable_slot(slot); @@ -1125,7 +1109,6 @@ static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot) break; } - mutex_unlock(&slot->crit_sect); return 0; } -- cgit v1.2.3 From b75cece1a79a6259185442004e040511ed3a7341 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:40:46 +0100 Subject: ACPI / hotplug / PCI: Simplify hotplug_event() A few lines of code can be cut from hotplug_event() by defining and initializing the slot variable at the top of the function, so do that. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp_glue.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 0961911c706e..d00da68752ea 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -817,6 +817,7 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) { struct acpiphp_context *context = data; struct acpiphp_func *func = &context->func; + struct acpiphp_slot *slot = func->slot; struct acpiphp_bridge *bridge; char objname[64]; struct acpi_buffer buffer = { .length = sizeof(objname), @@ -838,14 +839,11 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) pr_debug("%s: Bus check notify on %s\n", __func__, objname); pr_debug("%s: re-enumerating slots under %s\n", __func__, objname); - if (bridge) { + if (bridge) acpiphp_check_bridge(bridge); - } else { - struct acpiphp_slot *slot = func->slot; + else if (!(slot->flags & SLOT_IS_GOING_AWAY)) + enable_slot(slot); - if (!(slot->flags & SLOT_IS_GOING_AWAY)) - enable_slot(slot); - } break; case ACPI_NOTIFY_DEVICE_CHECK: @@ -853,12 +851,7 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) pr_debug("%s: Device check notify on %s\n", __func__, objname); if (bridge) { acpiphp_check_bridge(bridge); - } else { - struct acpiphp_slot *slot = func->slot; - - if (slot->flags & SLOT_IS_GOING_AWAY) - break; - + } else if (!(slot->flags & SLOT_IS_GOING_AWAY)) { /* * Check if anything has changed in the slot and rescan * from the parent if that's the case. @@ -871,7 +864,7 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) case ACPI_NOTIFY_EJECT_REQUEST: /* request device eject */ pr_debug("%s: Device eject notify on %s\n", __func__, objname); - acpiphp_disable_and_eject_slot(func->slot); + acpiphp_disable_and_eject_slot(slot); break; } -- cgit v1.2.3 From 1d4a5b610e500fe860570db4ceb64e45255221ab Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:41:52 +0100 Subject: ACPI / hotplug / PCI: Use acpi_handle_debug() in hotplug_event() Make hotplug_event() use acpi_handle_debug() instead of an open-coded debug message printing and clean up the messages printed by it. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp_glue.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index d00da68752ea..64ad6eed983f 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -819,9 +819,6 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) struct acpiphp_func *func = &context->func; struct acpiphp_slot *slot = func->slot; struct acpiphp_bridge *bridge; - char objname[64]; - struct acpi_buffer buffer = { .length = sizeof(objname), - .pointer = objname }; mutex_lock(&acpiphp_context_lock); bridge = context->bridge; @@ -831,14 +828,11 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) mutex_unlock(&acpiphp_context_lock); pci_lock_rescan_remove(); - acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); switch (type) { case ACPI_NOTIFY_BUS_CHECK: /* bus re-enumerate */ - pr_debug("%s: Bus check notify on %s\n", __func__, objname); - pr_debug("%s: re-enumerating slots under %s\n", - __func__, objname); + acpi_handle_debug(handle, "Bus check in %s()\n", __func__); if (bridge) acpiphp_check_bridge(bridge); else if (!(slot->flags & SLOT_IS_GOING_AWAY)) @@ -848,7 +842,7 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) case ACPI_NOTIFY_DEVICE_CHECK: /* device check */ - pr_debug("%s: Device check notify on %s\n", __func__, objname); + acpi_handle_debug(handle, "Device check in %s()\n", __func__); if (bridge) { acpiphp_check_bridge(bridge); } else if (!(slot->flags & SLOT_IS_GOING_AWAY)) { @@ -863,7 +857,7 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) case ACPI_NOTIFY_EJECT_REQUEST: /* request device eject */ - pr_debug("%s: Device eject notify on %s\n", __func__, objname); + acpi_handle_debug(handle, "Eject request in %s()\n", __func__); acpiphp_disable_and_eject_slot(slot); break; } -- cgit v1.2.3 From d3a1ebb063cc45d5f4a5655534b87c3547fd9bbf Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:42:20 +0100 Subject: ACPI / hotplug / PCI: Do not pass ACPI handle to hotplug_event() Since hotplug_event() can get the ACPI handle needed for debug printouts from its context argument, there's no need to pass the handle to it. Moreover, the second argument's type may be changed to (struct acpiphp_context *), because that's what is always passed to hotplug_event() as the second argument anyway. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp_glue.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 64ad6eed983f..5da32eff3bc3 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -63,7 +63,7 @@ static DEFINE_MUTEX(acpiphp_context_lock); static void handle_hotplug_event(acpi_handle handle, u32 type, void *data); static void acpiphp_sanitize_bus(struct pci_bus *bus); static void acpiphp_set_hpp_values(struct pci_bus *bus); -static void hotplug_event(acpi_handle handle, u32 type, void *data); +static void hotplug_event(u32 type, struct acpiphp_context *context); static void free_bridge(struct kref *kref); static void acpiphp_context_handler(acpi_handle handle, void *context) @@ -225,7 +225,7 @@ static void dock_event(acpi_handle handle, u32 type, void *data) acpiphp_put_context(context); mutex_unlock(&acpiphp_context_lock); - hotplug_event(handle, type, data); + hotplug_event(type, context); put_bridge(context->func.parent); } @@ -813,9 +813,9 @@ void acpiphp_check_host_bridge(acpi_handle handle) static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot); -static void hotplug_event(acpi_handle handle, u32 type, void *data) +static void hotplug_event(u32 type, struct acpiphp_context *context) { - struct acpiphp_context *context = data; + acpi_handle handle = context->adev->handle; struct acpiphp_func *func = &context->func; struct acpiphp_slot *slot = func->slot; struct acpiphp_bridge *bridge; @@ -870,14 +870,14 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data) static void hotplug_event_work(void *data, u32 type) { struct acpiphp_context *context = data; - acpi_handle handle = context->adev->handle; acpi_scan_lock_acquire(); - hotplug_event(handle, type, context); + hotplug_event(type, context); acpi_scan_lock_release(); - acpi_evaluate_hotplug_ost(handle, type, ACPI_OST_SC_SUCCESS, NULL); + acpi_evaluate_hotplug_ost(context->adev->handle, type, + ACPI_OST_SC_SUCCESS, NULL); put_bridge(context->func.parent); } -- cgit v1.2.3 From e525506fcb67a9bbd94f01eac84af802139004eb Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:43:17 +0100 Subject: ACPI / hotplug / PCI: Define hotplug context lock in the core Subsequent changes will require the ACPI core to acquire the lock protecting the ACPIPHP hotplug contexts, so move the definition of the lock to the core and change its name to be more generic. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/acpi/scan.c | 11 ++++++++ drivers/pci/hotplug/acpiphp_glue.c | 51 +++++++++++++++++++------------------- include/acpi/acpi_bus.h | 2 ++ 3 files changed, 38 insertions(+), 26 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 59eba29a6066..d64a5826ef35 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -41,6 +41,7 @@ static DEFINE_MUTEX(acpi_scan_lock); static LIST_HEAD(acpi_scan_handlers_list); DEFINE_MUTEX(acpi_device_lock); LIST_HEAD(acpi_wakeup_device_list); +static DEFINE_MUTEX(acpi_hp_context_lock); struct acpi_device_bus_id{ char bus_id[15]; @@ -60,6 +61,16 @@ void acpi_scan_lock_release(void) } EXPORT_SYMBOL_GPL(acpi_scan_lock_release); +void acpi_lock_hp_context(void) +{ + mutex_lock(&acpi_hp_context_lock); +} + +void acpi_unlock_hp_context(void) +{ + mutex_unlock(&acpi_hp_context_lock); +} + int acpi_scan_add_handler(struct acpi_scan_handler *handler) { if (!handler || !handler->attach) diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 5da32eff3bc3..8139a4b0d389 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -58,7 +58,6 @@ static LIST_HEAD(bridge_list); static DEFINE_MUTEX(bridge_mutex); -static DEFINE_MUTEX(acpiphp_context_lock); static void handle_hotplug_event(acpi_handle handle, u32 type, void *data); static void acpiphp_sanitize_bus(struct pci_bus *bus); @@ -75,7 +74,7 @@ static void acpiphp_context_handler(acpi_handle handle, void *context) * acpiphp_init_context - Create hotplug context and grab a reference to it. * @adev: ACPI device object to create the context for. * - * Call under acpiphp_context_lock. + * Call under acpi_hp_context_lock. */ static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev) { @@ -100,7 +99,7 @@ static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev) * acpiphp_get_context - Get hotplug context and grab a reference to it. * @handle: ACPI object handle to get the context for. * - * Call under acpiphp_context_lock. + * Call under acpi_hp_context_lock. */ static struct acpiphp_context *acpiphp_get_context(acpi_handle handle) { @@ -122,7 +121,7 @@ static struct acpiphp_context *acpiphp_get_context(acpi_handle handle) * * The context object is removed if there are no more references to it. * - * Call under acpiphp_context_lock. + * Call under acpi_hp_context_lock. */ static void acpiphp_put_context(struct acpiphp_context *context) { @@ -151,7 +150,7 @@ static void free_bridge(struct kref *kref) struct acpiphp_slot *slot, *next; struct acpiphp_func *func, *tmp; - mutex_lock(&acpiphp_context_lock); + acpi_lock_hp_context(); bridge = container_of(kref, struct acpiphp_bridge, ref); @@ -175,7 +174,7 @@ static void free_bridge(struct kref *kref) pci_dev_put(bridge->pci_dev); kfree(bridge); - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); } /* @@ -214,16 +213,16 @@ static void dock_event(acpi_handle handle, u32 type, void *data) { struct acpiphp_context *context; - mutex_lock(&acpiphp_context_lock); + acpi_lock_hp_context(); context = acpiphp_get_context(handle); if (!context || WARN_ON(context->adev->handle != handle) || context->func.parent->is_going_away) { - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); return; } get_bridge(context->func.parent); acpiphp_put_context(context); - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); hotplug_event(type, context); @@ -310,17 +309,17 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, device = (adr >> 16) & 0xffff; function = adr & 0xffff; - mutex_lock(&acpiphp_context_lock); + acpi_lock_hp_context(); context = acpiphp_init_context(adev); if (!context) { - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); acpi_handle_err(handle, "No hotplug context\n"); return AE_NOT_EXIST; } newfunc = &context->func; newfunc->function = function; newfunc->parent = bridge; - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); if (acpi_has_method(handle, "_EJ0")) newfunc->flags = FUNC_HAS_EJ0; @@ -338,9 +337,9 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL); if (!slot) { - mutex_lock(&acpiphp_context_lock); + acpi_lock_hp_context(); acpiphp_put_context(context); - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); return AE_NO_MEMORY; } @@ -415,7 +414,7 @@ static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) struct acpiphp_context *context; struct acpiphp_bridge *bridge = NULL; - mutex_lock(&acpiphp_context_lock); + acpi_lock_hp_context(); context = acpiphp_get_context(handle); if (context) { bridge = context->bridge; @@ -424,7 +423,7 @@ static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) acpiphp_put_context(context); } - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); return bridge; } @@ -458,9 +457,9 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge) list_del(&bridge->list); mutex_unlock(&bridge_mutex); - mutex_lock(&acpiphp_context_lock); + acpi_lock_hp_context(); bridge->is_going_away = true; - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); } /** @@ -820,12 +819,12 @@ static void hotplug_event(u32 type, struct acpiphp_context *context) struct acpiphp_slot *slot = func->slot; struct acpiphp_bridge *bridge; - mutex_lock(&acpiphp_context_lock); + acpi_lock_hp_context(); bridge = context->bridge; if (bridge) get_bridge(bridge); - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); pci_lock_rescan_remove(); @@ -927,7 +926,7 @@ static void handle_hotplug_event(acpi_handle handle, u32 type, void *data) goto out; } - mutex_lock(&acpiphp_context_lock); + acpi_lock_hp_context(); context = acpiphp_get_context(handle); if (!context || WARN_ON(context->adev->handle != handle) || context->func.parent->is_going_away) @@ -937,13 +936,13 @@ static void handle_hotplug_event(acpi_handle handle, u32 type, void *data) acpiphp_put_context(context); status = acpi_hotplug_execute(hotplug_event_work, context, type); if (ACPI_SUCCESS(status)) { - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); return; } put_bridge(context->func.parent); err_out: - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; out: @@ -999,10 +998,10 @@ void acpiphp_enumerate_slots(struct pci_bus *bus) * parent is going to be handled by pciehp, in which case this * bridge is not interesting to us either. */ - mutex_lock(&acpiphp_context_lock); + acpi_lock_hp_context(); context = acpiphp_get_context(handle); if (!context) { - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); put_device(&bus->dev); pci_dev_put(bridge->pci_dev); kfree(bridge); @@ -1012,7 +1011,7 @@ void acpiphp_enumerate_slots(struct pci_bus *bus) context->bridge = bridge; /* Get a reference to the parent bridge. */ get_bridge(context->func.parent); - mutex_unlock(&acpiphp_context_lock); + acpi_unlock_hp_context(); } /* must be added to the list prior to calling register_slot */ diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 94fd61a0456d..0c82708ff08a 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -404,6 +404,8 @@ static inline bool acpi_bus_can_wakeup(acpi_handle handle) { return false; } void acpi_scan_lock_acquire(void); void acpi_scan_lock_release(void); +void acpi_lock_hp_context(void); +void acpi_unlock_hp_context(void); int acpi_scan_add_handler(struct acpi_scan_handler *handler); int acpi_bus_register_driver(struct acpi_driver *driver); void acpi_bus_unregister_driver(struct acpi_driver *driver); -- cgit v1.2.3 From 3c2cc7ff9e2522e42468f8e81a7277be386c5ec4 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 6 Feb 2014 17:31:37 +0100 Subject: ACPI / hotplug / PCI: Consolidate ACPIPHP with ACPI core hotplug The ACPI-based PCI hotplug (ACPIPHP) code currently attaches its hotplug context objects directly to ACPI namespace nodes representing hotplug devices. However, after recent changes causing struct acpi_device to be created for every namespace node representing a device (regardless of its status), that is not necessary any more. Moreover, it's vulnerable to the theoretical issue that the ACPI handle passed in the context between handle_hotplug_event() and hotplug_event_work() may become invalid in the meantime (as a result of a concurrent table unload). In principle, this issue might be addressed by adding a non-empty release handler for ACPIPHP hotplug context objects analogous to acpi_scan_drop_device(), but that would duplicate the code in that function and in acpi_device_del_work_fn(). For this reason, it's better to modify ACPIPHP to attach its device hotplug contexts to struct device objects representing hotplug devices and make it use acpi_hotplug_notify_cb() as its notify handler. At the same time, acpi_device_hotplug() can be modified to dispatch the new .hp.event() callback pointing to acpiphp_hotplug_event() from ACPI device objects associated with PCI devices or use the generic ACPI device hotplug code for device objects with matching scan handlers. This allows the existing code duplication between ACPIPHP and the ACPI core to be reduced too and makes further ACPI-based device hotplug consolidation possible. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/scan.c | 137 +++++++++++++++++++----------- drivers/pci/hotplug/acpiphp.h | 9 +- drivers/pci/hotplug/acpiphp_glue.c | 168 +++++++++---------------------------- include/acpi/acpi_bus.h | 25 +++++- 4 files changed, 158 insertions(+), 181 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index d64a5826ef35..984eaff235df 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -450,43 +450,61 @@ static int acpi_scan_bus_check(struct acpi_device *adev) return 0; } +static int acpi_generic_hotplug_event(struct acpi_device *adev, u32 type) +{ + switch (type) { + case ACPI_NOTIFY_BUS_CHECK: + return acpi_scan_bus_check(adev); + case ACPI_NOTIFY_DEVICE_CHECK: + return acpi_scan_device_check(adev); + case ACPI_NOTIFY_EJECT_REQUEST: + case ACPI_OST_EC_OSPM_EJECT: + return acpi_scan_hot_remove(adev); + } + return -EINVAL; +} + static void acpi_device_hotplug(void *data, u32 src) { u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; struct acpi_device *adev = data; - int error; + int error = -ENODEV; lock_device_hotplug(); mutex_lock(&acpi_scan_lock); /* * The device object's ACPI handle cannot become invalid as long as we - * are holding acpi_scan_lock, but it may have become invalid before + * are holding acpi_scan_lock, but it might have become invalid before * that lock was acquired. */ if (adev->handle == INVALID_ACPI_HANDLE) - goto out; + goto err_out; - switch (src) { - case ACPI_NOTIFY_BUS_CHECK: - error = acpi_scan_bus_check(adev); - break; - case ACPI_NOTIFY_DEVICE_CHECK: - error = acpi_scan_device_check(adev); - break; - case ACPI_NOTIFY_EJECT_REQUEST: - case ACPI_OST_EC_OSPM_EJECT: - error = acpi_scan_hot_remove(adev); - break; - default: - error = -EINVAL; - break; + if (adev->flags.hotplug_notify) { + error = acpi_generic_hotplug_event(adev, src); + } else { + int (*event)(struct acpi_device *, u32); + + acpi_lock_hp_context(); + event = adev->hp ? adev->hp->event : NULL; + acpi_unlock_hp_context(); + /* + * There may be additional notify handlers for device objects + * without the .event() callback, so ignore them here. + */ + if (event) + error = event(adev, src); + else + goto out; } if (!error) ost_code = ACPI_OST_SC_SUCCESS; - out: + err_out: acpi_evaluate_hotplug_ost(adev->handle, src, ost_code, NULL); + + out: acpi_bus_put_acpi_device(adev); mutex_unlock(&acpi_scan_lock); unlock_device_hotplug(); @@ -494,8 +512,8 @@ static void acpi_device_hotplug(void *data, u32 src) static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data) { - u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; struct acpi_scan_handler *handler = data; + u32 ost_code = ACPI_OST_SC_SUCCESS; struct acpi_device *adev; acpi_status status; @@ -503,26 +521,49 @@ static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data) case ACPI_NOTIFY_BUS_CHECK: acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n"); break; + case ACPI_NOTIFY_DEVICE_CHECK: acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n"); break; + case ACPI_NOTIFY_EJECT_REQUEST: acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n"); - if (!handler->hotplug.enabled) { + if (handler && !handler->hotplug.enabled) { acpi_handle_err(handle, "Eject disabled\n"); ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED; - goto err_out; + goto out; } acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST, ACPI_OST_SC_EJECT_IN_PROGRESS, NULL); break; - default: - /* non-hotplug event; possibly handled by other handler */ + + case ACPI_NOTIFY_DEVICE_WAKE: return; + + case ACPI_NOTIFY_FREQUENCY_MISMATCH: + acpi_handle_err(handle, "Device cannot be configured due " + "to a frequency mismatch\n"); + goto out; + + case ACPI_NOTIFY_BUS_MODE_MISMATCH: + acpi_handle_err(handle, "Device cannot be configured due " + "to a bus mode mismatch\n"); + goto out; + + case ACPI_NOTIFY_POWER_FAULT: + acpi_handle_err(handle, "Device has suffered a power fault\n"); + goto out; + + default: + acpi_handle_warn(handle, "Unsupported event type 0x%x\n", type); + ost_code = ACPI_OST_SC_UNRECOGNIZED_NOTIFY; + goto out; } + + ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; adev = acpi_bus_get_acpi_device(handle); if (!adev) - goto err_out; + goto out; status = acpi_hotplug_execute(acpi_device_hotplug, adev, type); if (ACPI_SUCCESS(status)) @@ -530,10 +571,22 @@ static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data) acpi_bus_put_acpi_device(adev); - err_out: + out: acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL); } +void acpi_install_hotplug_notify_handler(acpi_handle handle, void *data) +{ + acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, + acpi_hotplug_notify_cb, data); +} + +void acpi_remove_hotplug_notify_handler(acpi_handle handle) +{ + acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, + acpi_hotplug_notify_cb); +} + static ssize_t real_power_state_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -1976,33 +2029,21 @@ void acpi_scan_hotplug_enabled(struct acpi_hotplug_profile *hotplug, bool val) mutex_unlock(&acpi_scan_lock); } -static void acpi_scan_init_hotplug(acpi_handle handle, int type) +static void acpi_scan_init_hotplug(struct acpi_device *adev) { - struct acpi_device_pnp pnp = {}; struct acpi_hardware_id *hwid; - struct acpi_scan_handler *handler; - INIT_LIST_HEAD(&pnp.ids); - acpi_set_pnp_ids(handle, &pnp, type); - - if (!pnp.type.hardware_id) - goto out; + list_for_each_entry(hwid, &adev->pnp.ids, list) { + struct acpi_scan_handler *handler; - /* - * This relies on the fact that acpi_install_notify_handler() will not - * install the same notify handler routine twice for the same handle. - */ - list_for_each_entry(hwid, &pnp.ids, list) { handler = acpi_scan_match_handler(hwid->id, NULL); - if (handler) { - acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, - acpi_hotplug_notify_cb, handler); - break; - } - } + if (!handler) + continue; -out: - acpi_free_pnp_ids(&pnp); + acpi_install_hotplug_notify_handler(adev->handle, handler); + adev->flags.hotplug_notify = true; + break; + } } static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, @@ -2026,12 +2067,12 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, return AE_OK; } - acpi_scan_init_hotplug(handle, type); - acpi_add_single_object(&device, handle, type, sta); if (!device) return AE_CTRL_DEPTH; + acpi_scan_init_hotplug(device); + out: if (!*return_value) *return_value = device; diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h index 373c7aa3b4a6..d7c1fc9712ad 100644 --- a/drivers/pci/hotplug/acpiphp.h +++ b/drivers/pci/hotplug/acpiphp.h @@ -116,12 +116,17 @@ struct acpiphp_func { }; struct acpiphp_context { + struct acpi_hotplug_context hp; struct acpiphp_func func; - struct acpi_device *adev; struct acpiphp_bridge *bridge; unsigned int refcount; }; +static inline struct acpiphp_context *to_acpiphp_context(struct acpi_hotplug_context *hp) +{ + return container_of(hp, struct acpiphp_context, hp); +} + static inline struct acpiphp_context *func_to_context(struct acpiphp_func *func) { return container_of(func, struct acpiphp_context, func); @@ -129,7 +134,7 @@ static inline struct acpiphp_context *func_to_context(struct acpiphp_func *func) static inline struct acpi_device *func_to_acpi_device(struct acpiphp_func *func) { - return func_to_context(func)->adev; + return func_to_context(func)->hp.self; } static inline acpi_handle func_to_handle(struct acpiphp_func *func) diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 8139a4b0d389..7c498d663eb3 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -59,17 +59,12 @@ static LIST_HEAD(bridge_list); static DEFINE_MUTEX(bridge_mutex); -static void handle_hotplug_event(acpi_handle handle, u32 type, void *data); +static int acpiphp_hotplug_event(struct acpi_device *adev, u32 type); static void acpiphp_sanitize_bus(struct pci_bus *bus); static void acpiphp_set_hpp_values(struct pci_bus *bus); static void hotplug_event(u32 type, struct acpiphp_context *context); static void free_bridge(struct kref *kref); -static void acpiphp_context_handler(acpi_handle handle, void *context) -{ - /* Intentionally empty. */ -} - /** * acpiphp_init_context - Create hotplug context and grab a reference to it. * @adev: ACPI device object to create the context for. @@ -79,39 +74,31 @@ static void acpiphp_context_handler(acpi_handle handle, void *context) static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev) { struct acpiphp_context *context; - acpi_status status; context = kzalloc(sizeof(*context), GFP_KERNEL); if (!context) return NULL; - context->adev = adev; context->refcount = 1; - status = acpi_attach_data(adev->handle, acpiphp_context_handler, context); - if (ACPI_FAILURE(status)) { - kfree(context); - return NULL; - } + acpi_set_hp_context(adev, &context->hp, acpiphp_hotplug_event); return context; } /** * acpiphp_get_context - Get hotplug context and grab a reference to it. - * @handle: ACPI object handle to get the context for. + * @adev: ACPI device object to get the context for. * * Call under acpi_hp_context_lock. */ -static struct acpiphp_context *acpiphp_get_context(acpi_handle handle) +static struct acpiphp_context *acpiphp_get_context(struct acpi_device *adev) { - struct acpiphp_context *context = NULL; - acpi_status status; - void *data; + struct acpiphp_context *context; - status = acpi_get_data(handle, acpiphp_context_handler, &data); - if (ACPI_SUCCESS(status)) { - context = data; - context->refcount++; - } + if (!adev->hp) + return NULL; + + context = to_acpiphp_context(adev->hp); + context->refcount++; return context; } @@ -129,7 +116,7 @@ static void acpiphp_put_context(struct acpiphp_context *context) return; WARN_ON(context->bridge); - acpi_detach_data(context->adev->handle, acpiphp_context_handler); + context->hp.self->hp = NULL; kfree(context); } @@ -211,22 +198,13 @@ static void post_dock_fixups(acpi_handle not_used, u32 event, void *data) static void dock_event(acpi_handle handle, u32 type, void *data) { - struct acpiphp_context *context; + struct acpi_device *adev; - acpi_lock_hp_context(); - context = acpiphp_get_context(handle); - if (!context || WARN_ON(context->adev->handle != handle) - || context->func.parent->is_going_away) { - acpi_unlock_hp_context(); - return; + adev = acpi_bus_get_acpi_device(handle); + if (adev) { + acpiphp_hotplug_event(adev, type); + acpi_bus_put_acpi_device(adev); } - get_bridge(context->func.parent); - acpiphp_put_context(context); - acpi_unlock_hp_context(); - - hotplug_event(type, context); - - put_bridge(context->func.parent); } static const struct acpi_dock_ops acpiphp_dock_ops = { @@ -397,25 +375,23 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, } /* install notify handler */ - if (!(newfunc->flags & FUNC_HAS_DCK)) { - status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, - handle_hotplug_event, - context); - if (ACPI_FAILURE(status)) - acpi_handle_err(handle, - "failed to install notify handler\n"); - } + if (!(newfunc->flags & FUNC_HAS_DCK)) + acpi_install_hotplug_notify_handler(handle, NULL); return AE_OK; } static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) { + struct acpi_device *adev = acpi_bus_get_acpi_device(handle); struct acpiphp_context *context; struct acpiphp_bridge *bridge = NULL; + if (!adev) + return NULL; + acpi_lock_hp_context(); - context = acpiphp_get_context(handle); + context = acpiphp_get_context(adev); if (context) { bridge = context->bridge; if (bridge) @@ -424,6 +400,7 @@ static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) acpiphp_put_context(context); } acpi_unlock_hp_context(); + acpi_bus_put_acpi_device(adev); return bridge; } @@ -431,7 +408,6 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge) { struct acpiphp_slot *slot; struct acpiphp_func *func; - acpi_status status; list_for_each_entry(slot, &bridge->slots, node) { list_for_each_entry(func, &slot->funcs, sibling) { @@ -440,13 +416,8 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge) if (is_dock_device(handle)) unregister_hotplug_dock_device(handle); - if (!(func->flags & FUNC_HAS_DCK)) { - status = acpi_remove_notify_handler(handle, - ACPI_SYSTEM_NOTIFY, - handle_hotplug_event); - if (ACPI_FAILURE(status)) - pr_err("failed to remove notify handler\n"); - } + if (!(func->flags & FUNC_HAS_DCK)) + acpi_remove_hotplug_notify_handler(handle); } slot->flags |= SLOT_IS_GOING_AWAY; if (slot->slot) @@ -814,7 +785,7 @@ static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot); static void hotplug_event(u32 type, struct acpiphp_context *context) { - acpi_handle handle = context->adev->handle; + acpi_handle handle = context->hp.self->handle; struct acpiphp_func *func = &context->func; struct acpiphp_slot *slot = func->slot; struct acpiphp_bridge *bridge; @@ -866,87 +837,24 @@ static void hotplug_event(u32 type, struct acpiphp_context *context) put_bridge(bridge); } -static void hotplug_event_work(void *data, u32 type) -{ - struct acpiphp_context *context = data; - - acpi_scan_lock_acquire(); - - hotplug_event(type, context); - - acpi_scan_lock_release(); - acpi_evaluate_hotplug_ost(context->adev->handle, type, - ACPI_OST_SC_SUCCESS, NULL); - put_bridge(context->func.parent); -} - -/** - * handle_hotplug_event - handle ACPI hotplug event - * @handle: Notify()'ed acpi_handle - * @type: Notify code - * @data: pointer to acpiphp_context structure - * - * Handles ACPI event notification on slots. - */ -static void handle_hotplug_event(acpi_handle handle, u32 type, void *data) +static int acpiphp_hotplug_event(struct acpi_device *adev, u32 type) { struct acpiphp_context *context; - u32 ost_code = ACPI_OST_SC_SUCCESS; - acpi_status status; - - switch (type) { - case ACPI_NOTIFY_BUS_CHECK: - case ACPI_NOTIFY_DEVICE_CHECK: - break; - case ACPI_NOTIFY_EJECT_REQUEST: - ost_code = ACPI_OST_SC_EJECT_IN_PROGRESS; - acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL); - break; - - case ACPI_NOTIFY_DEVICE_WAKE: - return; - - case ACPI_NOTIFY_FREQUENCY_MISMATCH: - acpi_handle_err(handle, "Device cannot be configured due " - "to a frequency mismatch\n"); - goto out; - - case ACPI_NOTIFY_BUS_MODE_MISMATCH: - acpi_handle_err(handle, "Device cannot be configured due " - "to a bus mode mismatch\n"); - goto out; - - case ACPI_NOTIFY_POWER_FAULT: - acpi_handle_err(handle, "Device has suffered a power fault\n"); - goto out; - - default: - acpi_handle_warn(handle, "Unsupported event type 0x%x\n", type); - ost_code = ACPI_OST_SC_UNRECOGNIZED_NOTIFY; - goto out; - } acpi_lock_hp_context(); - context = acpiphp_get_context(handle); - if (!context || WARN_ON(context->adev->handle != handle) - || context->func.parent->is_going_away) - goto err_out; - - get_bridge(context->func.parent); - acpiphp_put_context(context); - status = acpi_hotplug_execute(hotplug_event_work, context, type); - if (ACPI_SUCCESS(status)) { + context = acpiphp_get_context(adev); + if (!context || context->func.parent->is_going_away) { acpi_unlock_hp_context(); - return; + return -ENODATA; } - put_bridge(context->func.parent); - - err_out: + get_bridge(context->func.parent); + acpiphp_put_context(context); acpi_unlock_hp_context(); - ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; - out: - acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL); + hotplug_event(type, context); + + put_bridge(context->func.parent); + return 0; } /** @@ -999,7 +907,7 @@ void acpiphp_enumerate_slots(struct pci_bus *bus) * bridge is not interesting to us either. */ acpi_lock_hp_context(); - context = acpiphp_get_context(handle); + context = acpiphp_get_context(adev); if (!context) { acpi_unlock_hp_context(); put_device(&bus->dev); diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 0c82708ff08a..53ce357f6335 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -136,6 +136,16 @@ struct acpi_scan_handler { struct acpi_hotplug_profile hotplug; }; +/* + * ACPI Hotplug Context + * -------------------- + */ + +struct acpi_hotplug_context { + struct acpi_device *self; + int (*event)(struct acpi_device *, u32); +}; + /* * ACPI Driver * ----------- @@ -190,7 +200,8 @@ struct acpi_device_flags { u32 initialized:1; u32 visited:1; u32 no_hotplug:1; - u32 reserved:24; + u32 hotplug_notify:1; + u32 reserved:23; }; /* File System */ @@ -329,6 +340,7 @@ struct acpi_device { struct acpi_device_perf performance; struct acpi_device_dir dir; struct acpi_scan_handler *handler; + struct acpi_hotplug_context *hp; struct acpi_driver *driver; void *driver_data; struct device dev; @@ -351,6 +363,15 @@ static inline void acpi_set_device_status(struct acpi_device *adev, u32 sta) *((u32 *)&adev->status) = sta; } +static inline void acpi_set_hp_context(struct acpi_device *adev, + struct acpi_hotplug_context *hp, + int (*event)(struct acpi_device *, u32)) +{ + hp->self = adev; + hp->event = event; + adev->hp = hp; +} + /* acpi_device.dev.bus == &acpi_bus_type */ extern struct bus_type acpi_bus_type; @@ -425,6 +446,8 @@ static inline bool acpi_device_enumerated(struct acpi_device *adev) typedef void (*acpi_hp_callback)(void *data, u32 src); acpi_status acpi_hotplug_execute(acpi_hp_callback func, void *data, u32 src); +void acpi_install_hotplug_notify_handler(acpi_handle handle, void *data); +void acpi_remove_hotplug_notify_handler(acpi_handle handle); /** * module_acpi_driver(acpi_driver) - Helper macro for registering an ACPI driver -- cgit v1.2.3 From 5e6f236c263117cef5f0d68e3fec241ba2adc4fc Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 6 Feb 2014 13:57:58 +0100 Subject: ACPI / hotplug / PCI: Simplify acpi_install_hotplug_notify_handler() Since acpi_hotplug_notify_cb() does not use its data argument any more, the second argument of acpi_install_hotplug_notify_handler() can be dropped, so do that and update its callers accordingly. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/scan.c | 6 +++--- drivers/pci/hotplug/acpiphp_glue.c | 2 +- include/acpi/acpi_bus.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index a3f5d6eabe46..59f9e272562e 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -577,10 +577,10 @@ static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data) acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL); } -void acpi_install_hotplug_notify_handler(acpi_handle handle, void *data) +void acpi_install_hotplug_notify_handler(acpi_handle handle) { acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, - acpi_hotplug_notify_cb, data); + acpi_hotplug_notify_cb, NULL); } void acpi_remove_hotplug_notify_handler(acpi_handle handle) @@ -2040,7 +2040,7 @@ static void acpi_scan_init_hotplug(struct acpi_device *adev) if (!handler) continue; - acpi_install_hotplug_notify_handler(adev->handle, handler); + acpi_install_hotplug_notify_handler(adev->handle); adev->flags.hotplug_notify = true; break; } diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 7c498d663eb3..f3c49c442d93 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -376,7 +376,7 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, /* install notify handler */ if (!(newfunc->flags & FUNC_HAS_DCK)) - acpi_install_hotplug_notify_handler(handle, NULL); + acpi_install_hotplug_notify_handler(handle); return AE_OK; } diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 53ce357f6335..907d5078f78a 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -446,7 +446,7 @@ static inline bool acpi_device_enumerated(struct acpi_device *adev) typedef void (*acpi_hp_callback)(void *data, u32 src); acpi_status acpi_hotplug_execute(acpi_hp_callback func, void *data, u32 src); -void acpi_install_hotplug_notify_handler(acpi_handle handle, void *data); +void acpi_install_hotplug_notify_handler(acpi_handle handle); void acpi_remove_hotplug_notify_handler(acpi_handle handle); /** -- cgit v1.2.3 From 1a699476e25814343766342672c655fb135224cc Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 6 Feb 2014 13:58:13 +0100 Subject: ACPI / hotplug / PCI: Hotplug notifications from acpi_bus_notify() Since acpi_bus_notify() is executed on all notifications for all devices anyway, make it execute acpi_device_hotplug() for all hotplug events instead of installing notify handlers pointing to the same function for all hotplug devices. This change reduces both the size and complexity of ACPI-based device hotplug code. Moreover, since acpi_device_hotplug() only does significant things for devices that have either an ACPI scan handler, or a hotplug context with .eject() defined, and those devices had notify handlers pointing to acpi_hotplug_notify_cb() installed before anyway, this modification shouldn't change functionality. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/bus.c | 61 +++++++++++++++++----------- drivers/acpi/internal.h | 1 + drivers/acpi/scan.c | 81 +++----------------------------------- drivers/pci/hotplug/acpiphp.h | 1 - drivers/pci/hotplug/acpiphp_glue.c | 24 +++++------ include/acpi/acpi_bus.h | 2 - 6 files changed, 57 insertions(+), 113 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index c3237774632f..e61e7b8a2eaf 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -340,62 +340,77 @@ static void acpi_bus_osc_support(void) */ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data) { - struct acpi_device *device; + struct acpi_device *adev; struct acpi_driver *driver; - - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n", - type, handle)); + acpi_status status; + u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; switch (type) { - case ACPI_NOTIFY_BUS_CHECK: - /* TBD */ + acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n"); break; case ACPI_NOTIFY_DEVICE_CHECK: - /* TBD */ + acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n"); break; case ACPI_NOTIFY_DEVICE_WAKE: - /* TBD */ + acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_WAKE event\n"); break; case ACPI_NOTIFY_EJECT_REQUEST: - /* TBD */ + acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n"); break; case ACPI_NOTIFY_DEVICE_CHECK_LIGHT: + acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK_LIGHT event\n"); /* TBD: Exactly what does 'light' mean? */ break; case ACPI_NOTIFY_FREQUENCY_MISMATCH: - /* TBD */ + acpi_handle_err(handle, "Device cannot be configured due " + "to a frequency mismatch\n"); break; case ACPI_NOTIFY_BUS_MODE_MISMATCH: - /* TBD */ + acpi_handle_err(handle, "Device cannot be configured due " + "to a bus mode mismatch\n"); break; case ACPI_NOTIFY_POWER_FAULT: - /* TBD */ + acpi_handle_err(handle, "Device has suffered a power fault\n"); break; default: - ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "Received unknown/unsupported notification [%08x]\n", - type)); - break; + acpi_handle_warn(handle, "Unsupported event type 0x%x\n", type); + ost_code = ACPI_OST_SC_UNRECOGNIZED_NOTIFY; + goto err; } - device = acpi_bus_get_acpi_device(handle); - if (device) { - driver = device->driver; - if (driver && driver->ops.notify && - (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS)) - driver->ops.notify(device, type); + adev = acpi_bus_get_acpi_device(handle); + if (!adev) + goto err; - acpi_bus_put_acpi_device(device); + driver = adev->driver; + if (driver && driver->ops.notify && + (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS)) + driver->ops.notify(adev, type); + + switch (type) { + case ACPI_NOTIFY_BUS_CHECK: + case ACPI_NOTIFY_DEVICE_CHECK: + case ACPI_NOTIFY_EJECT_REQUEST: + status = acpi_hotplug_execute(acpi_device_hotplug, adev, type); + if (ACPI_SUCCESS(status)) + return; + default: + break; } + acpi_bus_put_acpi_device(adev); + return; + + err: + acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL); } /* -------------------------------------------------------------------------- diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index dedbb2d802f1..143d5df5ec32 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -73,6 +73,7 @@ static inline void acpi_lpss_init(void) {} #endif bool acpi_queue_hotplug_work(struct work_struct *work); +void acpi_device_hotplug(void *data, u32 src); bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent); /* -------------------------------------------------------------------------- diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 59f9e272562e..8bb48bfab1df 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -470,7 +470,7 @@ static int acpi_generic_hotplug_event(struct acpi_device *adev, u32 type) return -EINVAL; } -static void acpi_device_hotplug(void *data, u32 src) +void acpi_device_hotplug(void *data, u32 src) { u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; struct acpi_device *adev = data; @@ -520,75 +520,6 @@ static void acpi_device_hotplug(void *data, u32 src) unlock_device_hotplug(); } -static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data) -{ - u32 ost_code = ACPI_OST_SC_SUCCESS; - struct acpi_device *adev; - acpi_status status; - - switch (type) { - case ACPI_NOTIFY_BUS_CHECK: - acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n"); - break; - - case ACPI_NOTIFY_DEVICE_CHECK: - acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n"); - break; - - case ACPI_NOTIFY_EJECT_REQUEST: - acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n"); - break; - - case ACPI_NOTIFY_DEVICE_WAKE: - return; - - case ACPI_NOTIFY_FREQUENCY_MISMATCH: - acpi_handle_err(handle, "Device cannot be configured due " - "to a frequency mismatch\n"); - goto out; - - case ACPI_NOTIFY_BUS_MODE_MISMATCH: - acpi_handle_err(handle, "Device cannot be configured due " - "to a bus mode mismatch\n"); - goto out; - - case ACPI_NOTIFY_POWER_FAULT: - acpi_handle_err(handle, "Device has suffered a power fault\n"); - goto out; - - default: - acpi_handle_warn(handle, "Unsupported event type 0x%x\n", type); - ost_code = ACPI_OST_SC_UNRECOGNIZED_NOTIFY; - goto out; - } - - ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; - adev = acpi_bus_get_acpi_device(handle); - if (!adev) - goto out; - - status = acpi_hotplug_execute(acpi_device_hotplug, adev, type); - if (ACPI_SUCCESS(status)) - return; - - acpi_bus_put_acpi_device(adev); - - out: - acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL); -} - -void acpi_install_hotplug_notify_handler(acpi_handle handle) -{ - acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, - acpi_hotplug_notify_cb, NULL); -} - -void acpi_remove_hotplug_notify_handler(acpi_handle handle) -{ - acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, - acpi_hotplug_notify_cb); -} - static ssize_t real_power_state_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -2037,12 +1968,10 @@ static void acpi_scan_init_hotplug(struct acpi_device *adev) struct acpi_scan_handler *handler; handler = acpi_scan_match_handler(hwid->id, NULL); - if (!handler) - continue; - - acpi_install_hotplug_notify_handler(adev->handle); - adev->flags.hotplug_notify = true; - break; + if (handler) { + adev->flags.hotplug_notify = true; + break; + } } } diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h index d7c1fc9712ad..2b859249303b 100644 --- a/drivers/pci/hotplug/acpiphp.h +++ b/drivers/pci/hotplug/acpiphp.h @@ -167,7 +167,6 @@ struct acpiphp_attention_info #define FUNC_HAS_STA (0x00000001) #define FUNC_HAS_EJ0 (0x00000002) -#define FUNC_HAS_DCK (0x00000004) /* function prototypes */ diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index f3c49c442d93..b7342d2e819b 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -297,7 +297,6 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, newfunc = &context->func; newfunc->function = function; newfunc->parent = bridge; - acpi_unlock_hp_context(); if (acpi_has_method(handle, "_EJ0")) newfunc->flags = FUNC_HAS_EJ0; @@ -305,8 +304,14 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, if (acpi_has_method(handle, "_STA")) newfunc->flags |= FUNC_HAS_STA; + /* + * Dock stations' notify handler should be used for dock devices instead + * of the common one, so clear hp.event in their contexts. + */ if (acpi_has_method(handle, "_DCK")) - newfunc->flags |= FUNC_HAS_DCK; + context->hp.event = NULL; + + acpi_unlock_hp_context(); /* search for objects that share the same slot */ list_for_each_entry(slot, &bridge->slots, node) @@ -374,10 +379,6 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, pr_debug("failed to register dock device\n"); } - /* install notify handler */ - if (!(newfunc->flags & FUNC_HAS_DCK)) - acpi_install_hotplug_notify_handler(handle); - return AE_OK; } @@ -411,13 +412,14 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge) list_for_each_entry(slot, &bridge->slots, node) { list_for_each_entry(func, &slot->funcs, sibling) { - acpi_handle handle = func_to_handle(func); + struct acpi_device *adev = func_to_acpi_device(func); - if (is_dock_device(handle)) - unregister_hotplug_dock_device(handle); + if (is_dock_device(adev->handle)) + unregister_hotplug_dock_device(adev->handle); - if (!(func->flags & FUNC_HAS_DCK)) - acpi_remove_hotplug_notify_handler(handle); + acpi_lock_hp_context(); + adev->hp->event = NULL; + acpi_unlock_hp_context(); } slot->flags |= SLOT_IS_GOING_AWAY; if (slot->slot) diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 907d5078f78a..32f90c7bcb03 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -446,8 +446,6 @@ static inline bool acpi_device_enumerated(struct acpi_device *adev) typedef void (*acpi_hp_callback)(void *data, u32 src); acpi_status acpi_hotplug_execute(acpi_hp_callback func, void *data, u32 src); -void acpi_install_hotplug_notify_handler(acpi_handle handle); -void acpi_remove_hotplug_notify_handler(acpi_handle handle); /** * module_acpi_driver(acpi_driver) - Helper macro for registering an ACPI driver -- cgit v1.2.3 From 1f7c164b6f2a8a028bfc36097fc42bf061c5212e Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Feb 2014 00:45:13 +0100 Subject: ACPI / hotplug / PCI: Rework acpiphp_check_host_bridge() Since the only existing caller of acpiphp_check_host_bridge(), which is acpi_pci_root_scan_dependent(), already has a struct acpi_device pointer needed to obtain the ACPIPHP context, it doesn't make sense to execute acpi_bus_get_device() on its handle in acpiphp_handle_to_bridge() just in order to get that pointer back. For this reason, modify acpiphp_check_host_bridge() to take a struct acpi_device pointer as its argument and rearrange the code accordingly. Signed-off-by: Rafael J. Wysocki Tested-by: Mika Westerberg --- drivers/acpi/pci_root.c | 2 +- drivers/pci/hotplug/acpiphp_glue.c | 11 +++-------- include/linux/pci-acpi.h | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index c1c4102e6478..c288ff3c6998 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -51,7 +51,7 @@ static void acpi_pci_root_remove(struct acpi_device *device); static int acpi_pci_root_scan_dependent(struct acpi_device *adev) { - acpiphp_check_host_bridge(adev->handle); + acpiphp_check_host_bridge(adev); return 0; } diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index b7342d2e819b..11a6117fb358 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -382,15 +382,11 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, return AE_OK; } -static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) +static struct acpiphp_bridge *acpiphp_dev_to_bridge(struct acpi_device *adev) { - struct acpi_device *adev = acpi_bus_get_acpi_device(handle); struct acpiphp_context *context; struct acpiphp_bridge *bridge = NULL; - if (!adev) - return NULL; - acpi_lock_hp_context(); context = acpiphp_get_context(adev); if (context) { @@ -401,7 +397,6 @@ static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) acpiphp_put_context(context); } acpi_unlock_hp_context(); - acpi_bus_put_acpi_device(adev); return bridge; } @@ -768,11 +763,11 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus) * ACPI event handlers */ -void acpiphp_check_host_bridge(acpi_handle handle) +void acpiphp_check_host_bridge(struct acpi_device *adev) { struct acpiphp_bridge *bridge; - bridge = acpiphp_handle_to_bridge(handle); + bridge = acpiphp_dev_to_bridge(adev); if (bridge) { pci_lock_rescan_remove(); diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h index 5a462c4e5009..637a608ded0b 100644 --- a/include/linux/pci-acpi.h +++ b/include/linux/pci-acpi.h @@ -59,12 +59,12 @@ static inline void acpi_pci_slot_remove(struct pci_bus *bus) { } void acpiphp_init(void); void acpiphp_enumerate_slots(struct pci_bus *bus); void acpiphp_remove_slots(struct pci_bus *bus); -void acpiphp_check_host_bridge(acpi_handle handle); +void acpiphp_check_host_bridge(struct acpi_device *adev); #else static inline void acpiphp_init(void) { } static inline void acpiphp_enumerate_slots(struct pci_bus *bus) { } static inline void acpiphp_remove_slots(struct pci_bus *bus) { } -static inline void acpiphp_check_host_bridge(acpi_handle handle) { } +static inline void acpiphp_check_host_bridge(struct acpi_device *adev) { } #endif #else /* CONFIG_ACPI */ -- cgit v1.2.3 From 21369c77477a7f937174833c8094154f0f995710 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 10 Feb 2014 13:36:26 +0100 Subject: ACPI / hotplug / PCI: Execute _EJ0 under the ACPI scan lock Since acpi_device_hotplug() assumes that ACPI handles of device objects passed to it will not become invalid while acpi_scan_lock is being held, make acpiphp_disable_slot() acquire acpi_scan_lock, because it generally causes _EJ0 to be executed for one of the devices in the slot and that may cause its ACPI handle to become invalid. Signed-off-by: Rafael J. Wysocki --- drivers/pci/hotplug/acpiphp_glue.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 11a6117fb358..fa8fe7441952 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -1007,9 +1007,15 @@ int acpiphp_disable_slot(struct acpiphp_slot *slot) { int ret; + /* + * Acquire acpi_scan_lock to ensure that the execution of _EJ0 in + * acpiphp_disable_and_eject_slot() will be synchronized properly. + */ + acpi_scan_lock_acquire(); pci_lock_rescan_remove(); ret = acpiphp_disable_and_eject_slot(slot); pci_unlock_rescan_remove(); + acpi_scan_lock_release(); return ret; } -- cgit v1.2.3 From 3799c5a032aefb258e2a19dfdb1e3780b78ee3ad Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Sun, 16 Feb 2014 00:12:00 +0100 Subject: ACPI / hotplug / PCI: Rename register_slot() to acpiphp_add_context() The name of register_slot() doesn't really reflect what the function is does, so rename it to acpiphp_add_context() and add a proper kerneldoc comment to it. Signed-off-by: Rafael J. Wysocki --- drivers/pci/hotplug/acpiphp_glue.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 91276f9fe268..903af4d4a383 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -255,9 +255,15 @@ static void acpiphp_dock_release(void *data) put_bridge(context->func.parent); } -/* callback routine to register each ACPI PCI slot object */ -static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, - void **rv) +/** + * acpiphp_add_context - Add ACPIPHP context to an ACPI device object. + * @handle: ACPI handle of the object to add a context to. + * @lvl: Not used. + * @data: The object's parent ACPIPHP bridge. + * @rv: Not used. + */ +static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data, + void **rv) { struct acpiphp_bridge *bridge = data; struct acpiphp_context *context; @@ -930,14 +936,14 @@ void acpiphp_enumerate_slots(struct pci_bus *bus) acpi_unlock_hp_context(); } - /* must be added to the list prior to calling register_slot */ + /* Must be added to the list prior to calling acpiphp_add_context(). */ mutex_lock(&bridge_mutex); list_add(&bridge->list, &bridge_list); mutex_unlock(&bridge_mutex); /* register all slot objects under this bridge */ status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1, - register_slot, NULL, bridge, NULL); + acpiphp_add_context, NULL, bridge, NULL); if (ACPI_FAILURE(status)) { acpi_handle_err(handle, "failed to register slots\n"); cleanup_bridge(bridge); -- cgit v1.2.3 From cc6254e00eb676dda6501655f8185aef7b761b4f Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Sun, 16 Feb 2014 00:12:09 +0100 Subject: ACPI / hotplug / PCI: Add ACPIPHP contexts to devices handled by PCIeHP Currently, ACPIPHP does not add hotplug context to devices that should be handled by the native PCI hotplug (PCIeHP) code. The reason why was because PCIeHP didn't know about the devices' connections with ACPI and would not clean up things properly during an eject of an ACPI-backed device, for example. However, after recent changes that made the ACPI core create struct acpi_device objects for all namespace nodes regardless of the underlying devices' status and added PCI rescan-remove locking to both ACPIPHP and PCIeHP, that concern is not valid any more. Namely, after those changes PCIeHP need not care about the ACPI side of things any more and it should be serialized with respect to ACPIPHP and they won't be running concurrently with each other in any case. For this reason, make ACPIPHP to add its hotplug context to all devices with ACPI companions, even the ones that should be handled by PCIeHP in principle. That may work around hotplug issues on some systems where PCIeHP is supposed to work, but it doesn't and the ACPI hotplug signaling works instead. Signed-off-by: Rafael J. Wysocki --- drivers/pci/hotplug/acpiphp_glue.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 903af4d4a383..f2f460cba5f7 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -277,9 +277,6 @@ static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data, struct pci_dev *pdev = bridge->pci_dev; u32 val; - if (pdev && device_is_managed_by_native_pciehp(pdev)) - return AE_OK; - status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); if (ACPI_FAILURE(status)) { if (status != AE_NOT_FOUND) @@ -338,8 +335,14 @@ static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data, list_add_tail(&slot->node, &bridge->slots); - /* Register slots for ejectable functions only. */ - if (acpi_pci_check_ejectable(pbus, handle) || is_dock_device(handle)) { + /* + * Expose slots to user space for functions that have _EJ0 or _RMV or + * are located in dock stations. Do not expose them for devices handled + * by the native PCIe hotplug (PCIeHP), becuase that code is supposed to + * expose slots to user space in those cases. + */ + if ((acpi_pci_check_ejectable(pbus, handle) || is_dock_device(handle)) + && !(pdev && device_is_managed_by_native_pciehp(pdev))) { unsigned long long sun; int retval; -- cgit v1.2.3 From d7c7c0256b936901eb7a70fbc6d674a6bdfd463e Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Fri, 21 Feb 2014 01:08:42 +0100 Subject: ACPI / hotplug / PCI: Do not clear event callback pointer for docks After recent changes adding dock station handling to the ACPI hotplug core, it is not necessary to clear the .event() pointer in the ACPIPHP device hotplug context for dock stations any more, so don't do that. Signed-off-by: Rafael J. Wysocki --- drivers/pci/hotplug/acpiphp_glue.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 91276f9fe268..db81412cacb0 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -304,13 +304,6 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, if (acpi_has_method(handle, "_STA")) newfunc->flags |= FUNC_HAS_STA; - /* - * Dock stations' notify handler should be used for dock devices instead - * of the common one, so clear hp.event in their contexts. - */ - if (acpi_has_method(handle, "_DCK")) - context->hp.event = NULL; - acpi_unlock_hp_context(); /* search for objects that share the same slot */ -- cgit v1.2.3 From 59b42fa01fe2d84f3c3f28ee6f25510820ace35b Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Fri, 21 Feb 2014 01:08:51 +0100 Subject: ACPI / hotplug: Add .fixup() callback to struct acpi_hotplug_context In order for the ACPI dock station code to be able to use the callbacks pointed to by the ACPI device objects' hotplug contexts add a .fixup() callback pointer to struct acpi_hotplug_context. That callback will be useful to handle PCI devices located in dock stations. Signed-off-by: Rafael J. Wysocki --- drivers/pci/hotplug/acpiphp_glue.c | 2 +- include/acpi/acpi_bus.h | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index db81412cacb0..4228c67ceffe 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -80,7 +80,7 @@ static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev) return NULL; context->refcount = 1; - acpi_set_hp_context(adev, &context->hp, acpiphp_hotplug_event); + acpi_set_hp_context(adev, &context->hp, acpiphp_hotplug_event, NULL); return context; } diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 8fb297b5307c..007fe99e29f5 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -144,6 +144,7 @@ struct acpi_scan_handler { struct acpi_hotplug_context { struct acpi_device *self; int (*event)(struct acpi_device *, u32); + void (*fixup)(struct acpi_device *); }; /* @@ -366,10 +367,12 @@ static inline void acpi_set_device_status(struct acpi_device *adev, u32 sta) static inline void acpi_set_hp_context(struct acpi_device *adev, struct acpi_hotplug_context *hp, - int (*event)(struct acpi_device *, u32)) + int (*event)(struct acpi_device *, u32), + void (*fixup)(struct acpi_device *)) { hp->self = adev; hp->event = event; + hp->fixup = fixup; adev->hp = hp; } -- cgit v1.2.3 From 3b52b21fa1f44c8956e21dfba645eda959111b5e Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Fri, 21 Feb 2014 01:10:09 +0100 Subject: ACPI / dock: Use ACPI device object pointers instead of ACPI handles Rework the ACPI dock station driver to store ACPI device object pointers instead of ACPI handles in its internal data structures. The purpose is moslty to make subsequent simplifications possible, but also this allows the overall code size to be reduced slightly. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/dock.c | 104 +++++++++++++++---------------------- drivers/pci/hotplug/acpiphp_glue.c | 6 +-- include/acpi/acpi_drivers.h | 4 +- 3 files changed, 47 insertions(+), 67 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 3199ce950e05..8c3967cb4830 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -72,7 +72,7 @@ static DEFINE_MUTEX(hotplug_lock); struct dock_dependent_device { struct list_head list; - acpi_handle handle; + struct acpi_device *adev; const struct acpi_dock_ops *hp_ops; void *hp_context; unsigned int hp_refcount; @@ -98,12 +98,13 @@ enum dock_callback_type { *****************************************************************************/ /** * add_dock_dependent_device - associate a device with the dock station - * @ds: The dock station - * @handle: handle of the dependent device + * @ds: Dock station. + * @adev: Dependent ACPI device object. * * Add the dependent device to the dock's dependent device list. */ -static int add_dock_dependent_device(struct dock_station *ds, acpi_handle handle) +static int add_dock_dependent_device(struct dock_station *ds, + struct acpi_device *adev) { struct dock_dependent_device *dd; @@ -111,7 +112,7 @@ static int add_dock_dependent_device(struct dock_station *ds, acpi_handle handle if (!dd) return -ENOMEM; - dd->handle = handle; + dd->adev = adev; INIT_LIST_HEAD(&dd->list); list_add_tail(&dd->list, &ds->dependent_devices); @@ -212,7 +213,7 @@ static void dock_hotplug_event(struct dock_dependent_device *dd, u32 event, return; if (cb) - cb(dd->handle, event, dd->hp_context); + cb(dd->adev->handle, event, dd->hp_context); dock_release_hotplug(dd); } @@ -231,18 +232,18 @@ static struct dock_station *find_dock_station(acpi_handle handle) /** * find_dock_dependent_device - get a device dependent on this dock * @ds: the dock station - * @handle: the acpi_handle of the device we want + * @adev: ACPI device object to find. * * iterate over the dependent device list for this dock. If the * dependent device matches the handle, return. */ static struct dock_dependent_device * -find_dock_dependent_device(struct dock_station *ds, acpi_handle handle) +find_dock_dependent_device(struct dock_station *ds, struct acpi_device *adev) { struct dock_dependent_device *dd; list_for_each_entry(dd, &ds->dependent_devices, list) - if (handle == dd->handle) + if (adev == dd->adev) return dd; return NULL; @@ -252,10 +253,9 @@ void register_dock_dependent_device(struct acpi_device *adev, acpi_handle dshandle) { struct dock_station *ds = find_dock_station(dshandle); - acpi_handle handle = adev->handle; - if (ds && !find_dock_dependent_device(ds, handle)) - add_dock_dependent_device(ds, handle); + if (ds && !find_dock_dependent_device(ds, adev)) + add_dock_dependent_device(ds, adev); } /***************************************************************************** @@ -264,24 +264,24 @@ void register_dock_dependent_device(struct acpi_device *adev, /** * is_dock_device - see if a device is on a dock station - * @handle: acpi handle of the device + * @adev: ACPI device object to check. * * If this device is either the dock station itself, * or is a device dependent on the dock station, then it * is a dock device */ -int is_dock_device(acpi_handle handle) +int is_dock_device(struct acpi_device *adev) { struct dock_station *dock_station; if (!dock_station_count) return 0; - if (acpi_dock_match(handle)) + if (acpi_dock_match(adev->handle)) return 1; list_for_each_entry(dock_station, &dock_stations, sibling) - if (find_dock_dependent_device(dock_station, handle)) + if (find_dock_dependent_device(dock_station, adev)) return 1; return 0; @@ -308,43 +308,6 @@ static int dock_present(struct dock_station *ds) return 0; } -/** - * dock_create_acpi_device - add new devices to acpi - * @handle - handle of the device to add - * - * This function will create a new acpi_device for the given - * handle if one does not exist already. This should cause - * acpi to scan for drivers for the given devices, and call - * matching driver's add routine. - */ -static void dock_create_acpi_device(acpi_handle handle) -{ - struct acpi_device *device = NULL; - int ret; - - acpi_bus_get_device(handle, &device); - if (!acpi_device_enumerated(device)) { - ret = acpi_bus_scan(handle); - if (ret) - pr_debug("error adding bus, %x\n", -ret); - } -} - -/** - * dock_remove_acpi_device - remove the acpi_device struct from acpi - * @handle - the handle of the device to remove - * - * Tell acpi to remove the acpi_device. This should cause any loaded - * driver to have it's remove routine called. - */ -static void dock_remove_acpi_device(acpi_handle handle) -{ - struct acpi_device *device; - - if (!acpi_bus_get_device(handle, &device)) - acpi_bus_trim(device); -} - /** * hot_remove_dock_devices - Remove dock station devices. * @ds: Dock station. @@ -362,7 +325,7 @@ static void hot_remove_dock_devices(struct dock_station *ds) dock_hotplug_event(dd, ACPI_NOTIFY_EJECT_REQUEST, false); list_for_each_entry_reverse(dd, &ds->dependent_devices, list) - dock_remove_acpi_device(dd->handle); + acpi_bus_trim(dd->adev); } /** @@ -388,12 +351,20 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event) dock_hotplug_event(dd, event, DOCK_CALL_HANDLER); /* - * Now make sure that an acpi_device is created for each dependent - * device. That will cause scan handlers to be attached to device - * objects or acpi_drivers to be stopped/started if they are present. + * Check if all devices have been enumerated already. If not, run + * acpi_bus_scan() for them and that will cause scan handlers to be + * attached to device objects or acpi_drivers to be stopped/started if + * they are present. */ - list_for_each_entry(dd, &ds->dependent_devices, list) - dock_create_acpi_device(dd->handle); + list_for_each_entry(dd, &ds->dependent_devices, list) { + struct acpi_device *adev = dd->adev; + + if (!acpi_device_enumerated(adev)) { + int ret = acpi_bus_scan(adev->handle); + if (ret) + dev_dbg(&adev->dev, "scan error %d\n", -ret); + } + } } static void dock_event(struct dock_station *ds, u32 event, int num) @@ -514,6 +485,7 @@ int register_hotplug_dock_device(acpi_handle handle, { struct dock_dependent_device *dd; struct dock_station *dock_station; + struct acpi_device *adev; int ret = -EINVAL; if (WARN_ON(!context)) @@ -522,6 +494,10 @@ int register_hotplug_dock_device(acpi_handle handle, if (!dock_station_count) return -ENODEV; + ret = acpi_bus_get_device(handle, &adev); + if (ret) + return ret; + /* * make sure this handle is for a device dependent on the dock, * this would include the dock station itself @@ -532,7 +508,7 @@ int register_hotplug_dock_device(acpi_handle handle, * separately, so there are two 'dock stations' which need the * ops */ - dd = find_dock_dependent_device(dock_station, handle); + dd = find_dock_dependent_device(dock_station, adev); if (dd && !dock_init_hotplug(dd, ops, context, init, release)) ret = 0; } @@ -549,12 +525,16 @@ void unregister_hotplug_dock_device(acpi_handle handle) { struct dock_dependent_device *dd; struct dock_station *dock_station; + struct acpi_device *adev; if (!dock_station_count) return; + if (acpi_bus_get_device(handle, &adev)) + return; + list_for_each_entry(dock_station, &dock_stations, sibling) { - dd = find_dock_dependent_device(dock_station, handle); + dd = find_dock_dependent_device(dock_station, adev); if (dd) dock_release_hotplug(dd); } @@ -807,7 +787,7 @@ void acpi_dock_add(struct acpi_device *adev) goto err_unregister; /* add the dock station as a device dependent on itself */ - ret = add_dock_dependent_device(dock_station, handle); + ret = add_dock_dependent_device(dock_station, adev); if (ret) goto err_rmgroup; diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index d3d2cc6bb40a..cd886725c42e 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -334,7 +334,7 @@ static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data, * by the native PCIe hotplug (PCIeHP), becuase that code is supposed to * expose slots to user space in those cases. */ - if ((acpi_pci_check_ejectable(pbus, handle) || is_dock_device(handle)) + if ((acpi_pci_check_ejectable(pbus, handle) || is_dock_device(adev)) && !(pdev && device_is_managed_by_native_pciehp(pdev))) { unsigned long long sun; int retval; @@ -369,7 +369,7 @@ static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data, &val, 60*1000)) slot->flags |= SLOT_ENABLED; - if (is_dock_device(handle)) { + if (is_dock_device(adev)) { /* we don't want to call this device's _EJ0 * because we want the dock notify handler * to call it after it calls _DCK @@ -411,7 +411,7 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge) list_for_each_entry(func, &slot->funcs, sibling) { struct acpi_device *adev = func_to_acpi_device(func); - if (is_dock_device(adev->handle)) + if (is_dock_device(adev)) unregister_hotplug_dock_device(adev->handle); acpi_lock_hp_context(); diff --git a/include/acpi/acpi_drivers.h b/include/acpi/acpi_drivers.h index b124fdb26046..d6c98b9cbe38 100644 --- a/include/acpi/acpi_drivers.h +++ b/include/acpi/acpi_drivers.h @@ -116,7 +116,7 @@ struct acpi_dock_ops { }; #ifdef CONFIG_ACPI_DOCK -extern int is_dock_device(acpi_handle handle); +extern int is_dock_device(struct acpi_device *adev); extern int register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops, void *context, @@ -124,7 +124,7 @@ extern int register_hotplug_dock_device(acpi_handle handle, void (*release)(void *)); extern void unregister_hotplug_dock_device(acpi_handle handle); #else -static inline int is_dock_device(acpi_handle handle) +static inline int is_dock_device(struct acpi_device *adev) { return 0; } -- cgit v1.2.3 From edf5bf34d40804fbef32f240a79b74ffc69a658b Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Fri, 21 Feb 2014 01:10:18 +0100 Subject: ACPI / dock: Use callback pointers from devices' ACPI hotplug contexts Instead of requiring a set of special dock operations to be registered via register_hotplug_dock_device() for each ACPI dock device, it is much more straightforward to use callback pointers from the devices' hotplug contexts if available. For this reason, modify dock_hotplug_event() to use callback pointers from the hotplug contexts of ACPI devices and fall back to using the special dock operarions only if those callbacks are missing. Also make the ACPI-based PCI hotplug (ACPIPHP) subsystem set the .fixup callback pointer in the hotplug contexts of devices handled by it to a new function, acpiphp_post_dock_fixup(), so that the dock station driver can use the callbacks from those contexts instead of special dock operations registered via register_hotplug_dock_device(). Along with the above changes drop the ACPIPHP's dock operations that are not necessary any more. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/dock.c | 29 +++++++++ drivers/pci/hotplug/acpiphp_glue.c | 119 +++++++++++++++---------------------- 2 files changed, 78 insertions(+), 70 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 8c3967cb4830..78c4ee7a422e 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -185,9 +185,38 @@ static void dock_release_hotplug(struct dock_dependent_device *dd) static void dock_hotplug_event(struct dock_dependent_device *dd, u32 event, enum dock_callback_type cb_type) { + struct acpi_device *adev = dd->adev; acpi_notify_handler cb = NULL; bool run = false; + acpi_lock_hp_context(); + + if (!adev->hp) + goto no_context; + + if (cb_type == DOCK_CALL_FIXUP) { + void (*fixup)(struct acpi_device *); + + fixup = adev->hp->fixup; + if (fixup) { + acpi_unlock_hp_context(); + fixup(adev); + return; + } + } else { + int (*notify)(struct acpi_device *, u32); + + notify = adev->hp->event; + if (notify) { + acpi_unlock_hp_context(); + notify(adev, event); + return; + } + } + + no_context: + acpi_unlock_hp_context(); + mutex_lock(&hotplug_lock); if (dd->hp_context) { diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index cd886725c42e..15865aeebbb5 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -60,6 +60,7 @@ static LIST_HEAD(bridge_list); static DEFINE_MUTEX(bridge_mutex); static int acpiphp_hotplug_event(struct acpi_device *adev, u32 type); +static void acpiphp_post_dock_fixup(struct acpi_device *adev); static void acpiphp_sanitize_bus(struct pci_bus *bus); static void acpiphp_set_hpp_values(struct pci_bus *bus); static void hotplug_event(u32 type, struct acpiphp_context *context); @@ -80,7 +81,8 @@ static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev) return NULL; context->refcount = 1; - acpi_set_hp_context(adev, &context->hp, acpiphp_hotplug_event, NULL); + acpi_set_hp_context(adev, &context->hp, acpiphp_hotplug_event, + acpiphp_post_dock_fixup); return context; } @@ -130,6 +132,27 @@ static inline void put_bridge(struct acpiphp_bridge *bridge) kref_put(&bridge->ref, free_bridge); } +static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev) +{ + struct acpiphp_context *context; + + acpi_lock_hp_context(); + context = acpiphp_get_context(adev); + if (!context || context->func.parent->is_going_away) { + acpi_unlock_hp_context(); + return NULL; + } + get_bridge(context->func.parent); + acpiphp_put_context(context); + acpi_unlock_hp_context(); + return context; +} + +static void acpiphp_let_context_go(struct acpiphp_context *context) +{ + put_bridge(context->func.parent); +} + static void free_bridge(struct kref *kref) { struct acpiphp_context *context; @@ -164,28 +187,29 @@ static void free_bridge(struct kref *kref) acpi_unlock_hp_context(); } -/* - * the _DCK method can do funny things... and sometimes not - * hah-hah funny. +/** + * acpiphp_post_dock_fixup - Post-dock fixups for PCI devices. + * @adev: ACPI device object corresponding to a PCI device. * - * TBD - figure out a way to only call fixups for - * systems that require them. + * TBD - figure out a way to only call fixups for systems that require them. */ -static void post_dock_fixups(acpi_handle not_used, u32 event, void *data) +static void acpiphp_post_dock_fixup(struct acpi_device *adev) { - struct acpiphp_context *context = data; - struct pci_bus *bus = context->func.slot->bus; + struct acpiphp_context *context = acpiphp_grab_context(adev); + struct pci_bus *bus; u32 buses; - if (!bus->self) + if (!context) return; + bus = context->func.slot->bus; + if (!bus->self) + goto out; + /* fixup bad _DCK function that rewrites * secondary bridge on slot */ - pci_read_config_dword(bus->self, - PCI_PRIMARY_BUS, - &buses); + pci_read_config_dword(bus->self, PCI_PRIMARY_BUS, &buses); if (((buses >> 8) & 0xff) != bus->busn_res.start) { buses = (buses & 0xff000000) @@ -194,24 +218,11 @@ static void post_dock_fixups(acpi_handle not_used, u32 event, void *data) | ((unsigned int)(bus->busn_res.end) << 16); pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses); } -} -static void dock_event(acpi_handle handle, u32 type, void *data) -{ - struct acpi_device *adev; - - adev = acpi_bus_get_acpi_device(handle); - if (adev) { - acpiphp_hotplug_event(adev, type); - acpi_bus_put_acpi_device(adev); - } + out: + acpiphp_let_context_go(context); } -static const struct acpi_dock_ops acpiphp_dock_ops = { - .fixup = post_dock_fixups, - .handler = dock_event, -}; - /* Check whether the PCI device is managed by native PCIe hotplug driver */ static bool device_is_managed_by_native_pciehp(struct pci_dev *pdev) { @@ -241,20 +252,6 @@ static bool device_is_managed_by_native_pciehp(struct pci_dev *pdev) return true; } -static void acpiphp_dock_init(void *data) -{ - struct acpiphp_context *context = data; - - get_bridge(context->func.parent); -} - -static void acpiphp_dock_release(void *data) -{ - struct acpiphp_context *context = data; - - put_bridge(context->func.parent); -} - /** * acpiphp_add_context - Add ACPIPHP context to an ACPI device object. * @handle: ACPI handle of the object to add a context to. @@ -300,15 +297,18 @@ static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data, newfunc = &context->func; newfunc->function = function; newfunc->parent = bridge; + acpi_unlock_hp_context(); - if (acpi_has_method(handle, "_EJ0")) + /* + * If this is a dock device, its _EJ0 should be executed by the dock + * notify handler after calling _DCK. + */ + if (!is_dock_device(adev) && acpi_has_method(handle, "_EJ0")) newfunc->flags = FUNC_HAS_EJ0; if (acpi_has_method(handle, "_STA")) newfunc->flags |= FUNC_HAS_STA; - acpi_unlock_hp_context(); - /* search for objects that share the same slot */ list_for_each_entry(slot, &bridge->slots, node) if (slot->device == device) @@ -369,18 +369,6 @@ static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data, &val, 60*1000)) slot->flags |= SLOT_ENABLED; - if (is_dock_device(adev)) { - /* we don't want to call this device's _EJ0 - * because we want the dock notify handler - * to call it after it calls _DCK - */ - newfunc->flags &= ~FUNC_HAS_EJ0; - if (register_hotplug_dock_device(handle, - &acpiphp_dock_ops, context, - acpiphp_dock_init, acpiphp_dock_release)) - pr_debug("failed to register dock device\n"); - } - return AE_OK; } @@ -411,11 +399,9 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge) list_for_each_entry(func, &slot->funcs, sibling) { struct acpi_device *adev = func_to_acpi_device(func); - if (is_dock_device(adev)) - unregister_hotplug_dock_device(adev->handle); - acpi_lock_hp_context(); adev->hp->event = NULL; + adev->hp->fixup = NULL; acpi_unlock_hp_context(); } slot->flags |= SLOT_IS_GOING_AWAY; @@ -851,19 +837,12 @@ static int acpiphp_hotplug_event(struct acpi_device *adev, u32 type) { struct acpiphp_context *context; - acpi_lock_hp_context(); - context = acpiphp_get_context(adev); - if (!context || context->func.parent->is_going_away) { - acpi_unlock_hp_context(); + context = acpiphp_grab_context(adev); + if (!context) return -ENODATA; - } - get_bridge(context->func.parent); - acpiphp_put_context(context); - acpi_unlock_hp_context(); hotplug_event(type, context); - - put_bridge(context->func.parent); + acpiphp_let_context_go(context); return 0; } -- cgit v1.2.3 From be27b3dcb02335ec093b81053fc8c84b32d3106e Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Fri, 21 Feb 2014 01:10:27 +0100 Subject: ACPI / dock: Add .uevent() callback to struct acpi_hotplug_context In order to avoid the need to register special ACPI dock operations for SATA devices add a .uevent() callback pointer to struct acpi_hotplug_context and make dock_hotplug_event() use that callback if available. Also rename the existing .event() callback in struct acpi_hotplug_context to .notify() to avoid possible confusion in the future. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/dock.c | 11 ++++++++++- drivers/acpi/scan.c | 8 ++++---- drivers/pci/hotplug/acpiphp_glue.c | 8 ++++---- include/acpi/acpi_bus.h | 9 ++++++--- 4 files changed, 24 insertions(+), 12 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 78c4ee7a422e..a88fad9ff234 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -203,10 +203,19 @@ static void dock_hotplug_event(struct dock_dependent_device *dd, u32 event, fixup(adev); return; } + } else if (cb_type == DOCK_CALL_UEVENT) { + void (*uevent)(struct acpi_device *, u32); + + uevent = adev->hp->uevent; + if (uevent) { + acpi_unlock_hp_context(); + uevent(adev, event); + return; + } } else { int (*notify)(struct acpi_device *, u32); - notify = adev->hp->event; + notify = adev->hp->notify; if (notify) { acpi_unlock_hp_context(); notify(adev, event); diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 518aae461a00..e7d951032f85 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -496,17 +496,17 @@ void acpi_device_hotplug(void *data, u32 src) goto err_out; } } else { - int (*event)(struct acpi_device *, u32); + int (*notify)(struct acpi_device *, u32); acpi_lock_hp_context(); - event = adev->hp ? adev->hp->event : NULL; + notify = adev->hp ? adev->hp->notify : NULL; acpi_unlock_hp_context(); /* * There may be additional notify handlers for device objects * without the .event() callback, so ignore them here. */ - if (event) - error = event(adev, src); + if (notify) + error = notify(adev, src); else goto out; } diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 15865aeebbb5..a92b8b017901 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -59,7 +59,7 @@ static LIST_HEAD(bridge_list); static DEFINE_MUTEX(bridge_mutex); -static int acpiphp_hotplug_event(struct acpi_device *adev, u32 type); +static int acpiphp_hotplug_notify(struct acpi_device *adev, u32 type); static void acpiphp_post_dock_fixup(struct acpi_device *adev); static void acpiphp_sanitize_bus(struct pci_bus *bus); static void acpiphp_set_hpp_values(struct pci_bus *bus); @@ -81,7 +81,7 @@ static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev) return NULL; context->refcount = 1; - acpi_set_hp_context(adev, &context->hp, acpiphp_hotplug_event, + acpi_set_hp_context(adev, &context->hp, acpiphp_hotplug_notify, NULL, acpiphp_post_dock_fixup); return context; } @@ -400,7 +400,7 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge) struct acpi_device *adev = func_to_acpi_device(func); acpi_lock_hp_context(); - adev->hp->event = NULL; + adev->hp->notify = NULL; adev->hp->fixup = NULL; acpi_unlock_hp_context(); } @@ -833,7 +833,7 @@ static void hotplug_event(u32 type, struct acpiphp_context *context) put_bridge(bridge); } -static int acpiphp_hotplug_event(struct acpi_device *adev, u32 type) +static int acpiphp_hotplug_notify(struct acpi_device *adev, u32 type) { struct acpiphp_context *context; diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 007fe99e29f5..738278606677 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -143,7 +143,8 @@ struct acpi_scan_handler { struct acpi_hotplug_context { struct acpi_device *self; - int (*event)(struct acpi_device *, u32); + int (*notify)(struct acpi_device *, u32); + void (*uevent)(struct acpi_device *, u32); void (*fixup)(struct acpi_device *); }; @@ -367,11 +368,13 @@ static inline void acpi_set_device_status(struct acpi_device *adev, u32 sta) static inline void acpi_set_hp_context(struct acpi_device *adev, struct acpi_hotplug_context *hp, - int (*event)(struct acpi_device *, u32), + int (*notify)(struct acpi_device *, u32), + void (*uevent)(struct acpi_device *, u32), void (*fixup)(struct acpi_device *)) { hp->self = adev; - hp->event = event; + hp->notify = notify; + hp->uevent = uevent; hp->fixup = fixup; adev->hp = hp; } -- cgit v1.2.3 From 7cd0602d7836c0056fe9bdab014d5ac5ec5cb291 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Wed, 26 Feb 2014 01:00:30 +0100 Subject: PCI / PM: Resume runtime-suspended devices later during system suspend Runtime-suspended devices are resumed during system suspend by pci_pm_prepare() for two reasons: First, because they may need to be reprogrammed in order to change their wakeup settings and, second, because they may need to be operatonal for their children to be successfully suspended. That is a problem, though, if there are many runtime-suspended devices that need to be resumed this way during system suspend, because the .prepare() PM callbacks of devices are executed sequentially and the times taken by them accumulate, which may increase the total system suspend time quite a bit. For this reason, move the resume of runtime-suspended devices up to the next phase of device suspend (during system suspend), except for the ones that have power.ignore_children set. The exception is made, because the devices with power.ignore_children set may still be necessary for their children to be successfully suspended (during system suspend) and they won't be resumed automatically as a result of the runtime resume of their children. Signed-off-by: Rafael J. Wysocki Acked-by: Bjorn Helgaas --- drivers/pci/pci-driver.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 25f0bc659164..d911e0c1f359 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -616,15 +616,11 @@ static int pci_pm_prepare(struct device *dev) int error = 0; /* - * PCI devices suspended at run time need to be resumed at this - * point, because in general it is necessary to reconfigure them for - * system suspend. Namely, if the device is supposed to wake up the - * system from the sleep state, we may need to reconfigure it for this - * purpose. In turn, if the device is not supposed to wake up the - * system from the sleep state, we'll have to prevent it from signaling - * wake-up. + * Devices having power.ignore_children set may still be necessary for + * suspending their children in the next phase of device suspend. */ - pm_runtime_resume(dev); + if (dev->power.ignore_children) + pm_runtime_resume(dev); if (drv && drv->pm && drv->pm->prepare) error = drv->pm->prepare(dev); @@ -654,6 +650,16 @@ static int pci_pm_suspend(struct device *dev) goto Fixup; } + /* + * PCI devices suspended at run time need to be resumed at this point, + * because in general it is necessary to reconfigure them for system + * suspend. Namely, if the device is supposed to wake up the system + * from the sleep state, we may need to reconfigure it for this purpose. + * In turn, if the device is not supposed to wake up the system from the + * sleep state, we'll have to prevent it from signaling wake-up. + */ + pm_runtime_resume(dev); + pci_dev->state_saved = false; if (pm->suspend) { pci_power_t prev = pci_dev->current_state; @@ -808,6 +814,14 @@ static int pci_pm_freeze(struct device *dev) return 0; } + /* + * This used to be done in pci_pm_prepare() for all devices and some + * drivers may depend on it, so do it here. Ideally, runtime-suspended + * devices should not be touched during freeze/thaw transitions, + * however. + */ + pm_runtime_resume(dev); + pci_dev->state_saved = false; if (pm->freeze) { int error; @@ -915,6 +929,9 @@ static int pci_pm_poweroff(struct device *dev) goto Fixup; } + /* The reason to do that is the same as in pci_pm_suspend(). */ + pm_runtime_resume(dev); + pci_dev->state_saved = false; if (pm->poweroff) { int error; -- cgit v1.2.3 From b8a62d540240387c7e97a69127cab3ab9cadc70a Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 4 Mar 2014 00:48:57 +0100 Subject: ACPI / hotplug / PCI: Use pci_device_is_present() Make the ACPI-based PCI hotplug (ACPIPHP) code use pci_device_is_present() for checking if devices are present instead of open coding the same thing. Signed-off-by: Rafael J. Wysocki Reviewed-by: Mika Westerberg --- drivers/pci/hotplug/acpiphp_glue.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index f2f460cba5f7..2d51bf7e9fe0 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -689,12 +689,9 @@ static void trim_stale_devices(struct pci_dev *dev) alive = (ACPI_SUCCESS(status) && device_status_valid(sta)) || acpiphp_no_hotplug(adev); } - if (!alive) { - u32 v; + if (!alive) + alive = pci_device_is_present(dev); - /* Check if the device responds. */ - alive = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &v, 0); - } if (!alive) { pci_stop_and_remove_bus_device(dev); if (adev) -- cgit v1.2.3