2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* ACPI PCI HotPlug glue functions to ACPI CA subsystem
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
|
|
|
|
* Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
|
|
|
|
* Copyright (C) 2002,2003 NEC Corporation
|
2005-04-28 14:25:53 +07:00
|
|
|
* Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
|
|
|
|
* Copyright (C) 2003-2005 Hewlett Packard
|
2005-04-28 14:25:56 +07:00
|
|
|
* Copyright (C) 2005 Rajesh Shah (rajesh.shah@intel.com)
|
|
|
|
* Copyright (C) 2005 Intel Corporation
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
|
|
|
|
* NON INFRINGEMENT. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
2006-07-27 00:52:33 +07:00
|
|
|
* Send feedback to <kristen.c.accardi@intel.com>
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-04-28 14:25:53 +07:00
|
|
|
/*
|
|
|
|
* Lifetime rules for pci_dev:
|
|
|
|
* - The one in acpiphp_bridge has its refcount elevated by pci_get_slot()
|
|
|
|
* when the bridge is scanned and it loses a refcount when the bridge
|
|
|
|
* is removed.
|
2009-03-30 23:50:14 +07:00
|
|
|
* - When a P2P bridge is present, we elevate the refcount on the subordinate
|
|
|
|
* bus. It loses the refcount when the the driver unloads.
|
2005-04-28 14:25:53 +07:00
|
|
|
*/
|
|
|
|
|
2013-09-25 07:11:48 +07:00
|
|
|
#define pr_fmt(fmt) "acpiphp_glue: " fmt
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pci.h>
|
2006-10-14 10:05:19 +07:00
|
|
|
#include <linux/pci_hotplug.h>
|
2008-12-17 10:09:12 +07:00
|
|
|
#include <linux/pci-acpi.h>
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
#include <linux/pm_runtime.h>
|
2006-01-13 22:02:15 +07:00
|
|
|
#include <linux/mutex.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2011-09-29 06:40:53 +07:00
|
|
|
#include <linux/acpi.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#include "../pci.h"
|
|
|
|
#include "acpiphp.h"
|
|
|
|
|
|
|
|
static LIST_HEAD(bridge_list);
|
2013-04-12 12:44:28 +07:00
|
|
|
static DEFINE_MUTEX(bridge_mutex);
|
2013-07-14 04:27:24 +07:00
|
|
|
static DEFINE_MUTEX(acpiphp_context_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
static void handle_hotplug_event(acpi_handle handle, u32 type, void *data);
|
2005-10-19 07:21:40 +07:00
|
|
|
static void acpiphp_sanitize_bus(struct pci_bus *bus);
|
2009-09-15 05:35:10 +07:00
|
|
|
static void acpiphp_set_hpp_values(struct pci_bus *bus);
|
2013-07-14 04:27:24 +07:00
|
|
|
static void hotplug_event(acpi_handle handle, u32 type, void *data);
|
2013-04-12 12:44:28 +07:00
|
|
|
static void free_bridge(struct kref *kref);
|
2005-10-19 07:21:40 +07:00
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
static void acpiphp_context_handler(acpi_handle handle, void *context)
|
|
|
|
{
|
|
|
|
/* Intentionally empty. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* acpiphp_init_context - Create hotplug context and grab a reference to it.
|
|
|
|
* @handle: ACPI object handle to create the context for.
|
|
|
|
*
|
|
|
|
* Call under acpiphp_context_lock.
|
|
|
|
*/
|
|
|
|
static struct acpiphp_context *acpiphp_init_context(acpi_handle handle)
|
|
|
|
{
|
|
|
|
struct acpiphp_context *context;
|
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
context = kzalloc(sizeof(*context), GFP_KERNEL);
|
|
|
|
if (!context)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
context->handle = handle;
|
|
|
|
context->refcount = 1;
|
|
|
|
status = acpi_attach_data(handle, acpiphp_context_handler, context);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
kfree(context);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
static struct acpiphp_context *acpiphp_get_context(acpi_handle handle)
|
|
|
|
{
|
|
|
|
struct acpiphp_context *context = NULL;
|
|
|
|
acpi_status status;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
status = acpi_get_data(handle, acpiphp_context_handler, &data);
|
|
|
|
if (ACPI_SUCCESS(status)) {
|
|
|
|
context = data;
|
|
|
|
context->refcount++;
|
|
|
|
}
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* acpiphp_put_context - Drop a reference to ACPI hotplug context.
|
|
|
|
* @handle: ACPI object handle to put the context for.
|
|
|
|
*
|
|
|
|
* The context object is removed if there are no more references to it.
|
|
|
|
*
|
|
|
|
* Call under acpiphp_context_lock.
|
|
|
|
*/
|
|
|
|
static void acpiphp_put_context(struct acpiphp_context *context)
|
|
|
|
{
|
|
|
|
if (--context->refcount)
|
|
|
|
return;
|
|
|
|
|
2013-07-14 04:27:25 +07:00
|
|
|
WARN_ON(context->bridge);
|
2013-07-14 04:27:24 +07:00
|
|
|
acpi_detach_data(context->handle, acpiphp_context_handler);
|
|
|
|
kfree(context);
|
|
|
|
}
|
|
|
|
|
2013-04-12 12:44:28 +07:00
|
|
|
static inline void get_bridge(struct acpiphp_bridge *bridge)
|
|
|
|
{
|
|
|
|
kref_get(&bridge->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void put_bridge(struct acpiphp_bridge *bridge)
|
|
|
|
{
|
|
|
|
kref_put(&bridge->ref, free_bridge);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_bridge(struct kref *kref)
|
|
|
|
{
|
2013-07-14 04:27:24 +07:00
|
|
|
struct acpiphp_context *context;
|
2013-04-12 12:44:28 +07:00
|
|
|
struct acpiphp_bridge *bridge;
|
|
|
|
struct acpiphp_slot *slot, *next;
|
|
|
|
struct acpiphp_func *func, *tmp;
|
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
mutex_lock(&acpiphp_context_lock);
|
|
|
|
|
2013-04-12 12:44:28 +07:00
|
|
|
bridge = container_of(kref, struct acpiphp_bridge, ref);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(slot, next, &bridge->slots, node) {
|
2013-07-14 04:27:25 +07:00
|
|
|
list_for_each_entry_safe(func, tmp, &slot->funcs, sibling)
|
|
|
|
acpiphp_put_context(func_to_context(func));
|
|
|
|
|
2013-04-12 12:44:28 +07:00
|
|
|
kfree(slot);
|
|
|
|
}
|
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
context = bridge->context;
|
2013-07-14 04:27:24 +07:00
|
|
|
/* Root bridges will not have hotplug context. */
|
|
|
|
if (context) {
|
|
|
|
/* Release the reference taken by acpiphp_enumerate_slots(). */
|
2013-07-14 04:27:25 +07:00
|
|
|
put_bridge(context->func.parent);
|
2013-07-14 04:27:24 +07:00
|
|
|
context->bridge = NULL;
|
|
|
|
acpiphp_put_context(context);
|
|
|
|
}
|
2013-07-14 04:27:24 +07:00
|
|
|
|
2013-04-12 12:44:28 +07:00
|
|
|
put_device(&bridge->pci_bus->dev);
|
|
|
|
pci_dev_put(bridge->pci_dev);
|
|
|
|
kfree(bridge);
|
2013-07-14 04:27:24 +07:00
|
|
|
|
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
2013-04-12 12:44:28 +07:00
|
|
|
}
|
|
|
|
|
2006-06-28 14:08:06 +07:00
|
|
|
/*
|
|
|
|
* the _DCK method can do funny things... and sometimes not
|
|
|
|
* hah-hah funny.
|
|
|
|
*
|
|
|
|
* TBD - figure out a way to only call fixups for
|
|
|
|
* systems that require them.
|
|
|
|
*/
|
2013-07-05 08:03:25 +07:00
|
|
|
static void post_dock_fixups(acpi_handle not_used, u32 event, void *data)
|
2006-06-28 14:08:06 +07:00
|
|
|
{
|
2013-07-14 04:27:24 +07:00
|
|
|
struct acpiphp_context *context = data;
|
2013-07-14 04:27:25 +07:00
|
|
|
struct pci_bus *bus = context->func.slot->bus;
|
2006-06-28 14:08:06 +07:00
|
|
|
u32 buses;
|
|
|
|
|
|
|
|
if (!bus->self)
|
2013-07-05 08:03:25 +07:00
|
|
|
return;
|
2006-06-28 14:08:06 +07:00
|
|
|
|
|
|
|
/* fixup bad _DCK function that rewrites
|
|
|
|
* secondary bridge on slot
|
|
|
|
*/
|
|
|
|
pci_read_config_dword(bus->self,
|
|
|
|
PCI_PRIMARY_BUS,
|
|
|
|
&buses);
|
|
|
|
|
2012-05-18 08:51:11 +07:00
|
|
|
if (((buses >> 8) & 0xff) != bus->busn_res.start) {
|
2006-06-28 14:08:06 +07:00
|
|
|
buses = (buses & 0xff000000)
|
2008-12-12 01:17:55 +07:00
|
|
|
| ((unsigned int)(bus->primary) << 0)
|
2012-05-18 08:51:11 +07:00
|
|
|
| ((unsigned int)(bus->busn_res.start) << 8)
|
|
|
|
| ((unsigned int)(bus->busn_res.end) << 16);
|
2006-06-28 14:08:06 +07:00
|
|
|
pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-04 04:30:15 +07:00
|
|
|
static void dock_event(acpi_handle handle, u32 type, void *data)
|
|
|
|
{
|
|
|
|
struct acpiphp_context *context;
|
|
|
|
|
|
|
|
mutex_lock(&acpiphp_context_lock);
|
|
|
|
context = acpiphp_get_context(handle);
|
|
|
|
if (!context || WARN_ON(context->handle != handle)
|
|
|
|
|| context->func.parent->is_going_away) {
|
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
get_bridge(context->func.parent);
|
|
|
|
acpiphp_put_context(context);
|
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
|
|
|
|
|
|
|
hotplug_event(handle, type, data);
|
|
|
|
|
|
|
|
put_bridge(context->func.parent);
|
|
|
|
}
|
2006-06-28 14:08:06 +07:00
|
|
|
|
2011-06-26 00:07:52 +07:00
|
|
|
static const struct acpi_dock_ops acpiphp_dock_ops = {
|
2013-07-05 08:03:25 +07:00
|
|
|
.fixup = post_dock_fixups,
|
2014-02-04 04:30:15 +07:00
|
|
|
.handler = dock_event,
|
2008-08-28 09:06:16 +07:00
|
|
|
};
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-08-22 22:16:45 +07:00
|
|
|
/* Check whether the PCI device is managed by native PCIe hotplug driver */
|
|
|
|
static bool device_is_managed_by_native_pciehp(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
u32 reg32;
|
|
|
|
acpi_handle tmp;
|
|
|
|
struct acpi_pci_root *root;
|
|
|
|
|
|
|
|
/* Check whether the PCIe port supports native PCIe hotplug */
|
|
|
|
if (pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, ®32))
|
|
|
|
return false;
|
|
|
|
if (!(reg32 & PCI_EXP_SLTCAP_HPC))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether native PCIe hotplug has been enabled for
|
|
|
|
* this PCIe hierarchy.
|
|
|
|
*/
|
|
|
|
tmp = acpi_find_root_bridge_handle(pdev);
|
|
|
|
if (!tmp)
|
|
|
|
return false;
|
|
|
|
root = acpi_pci_find_root(tmp);
|
|
|
|
if (!root)
|
|
|
|
return false;
|
|
|
|
if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
ACPI / dock / PCI: Synchronous handling of dock events for PCI devices
The interactions between the ACPI dock driver and the ACPI-based PCI
hotplug (acpiphp) are currently problematic because of ordering
issues during hot-remove operations.
First of all, the current ACPI glue code expects that physical
devices will always be deleted before deleting the companion ACPI
device objects. Otherwise, acpi_unbind_one() will fail with a
warning message printed to the kernel log, for example:
[ 185.026073] usb usb5: Oops, 'acpi_handle' corrupt
[ 185.035150] pci 0000:1b:00.0: Oops, 'acpi_handle' corrupt
[ 185.035515] pci 0000:18:02.0: Oops, 'acpi_handle' corrupt
[ 180.013656] port1: Oops, 'acpi_handle' corrupt
This means, in particular, that struct pci_dev objects have to
be deleted before the struct acpi_device objects they are "glued"
with.
Now, the following happens the during the undocking of an ACPI-based
dock station:
1) hotplug_dock_devices() invokes registered hotplug callbacks to
destroy physical devices associated with the ACPI device objects
depending on the dock station. It calls dd->ops->handler() for
each of those device objects.
2) For PCI devices dd->ops->handler() points to
handle_hotplug_event_func() that queues up a separate work item
to execute _handle_hotplug_event_func() for the given device and
returns immediately. That work item will be executed later.
3) hotplug_dock_devices() calls dock_remove_acpi_device() for each
device depending on the dock station. This runs acpi_bus_trim()
for each of them, which causes the underlying ACPI device object
to be destroyed, but the work items queued up by
handle_hotplug_event_func() haven't been started yet.
4) _handle_hotplug_event_func() queued up in step 2) are executed
and cause the above failure to happen, because the PCI devices
they handle do not have the companion ACPI device objects any
more (those objects have been deleted in step 3).
The possible breakage doesn't end here, though, because
hotplug_dock_devices() may return before at least some of the
_handle_hotplug_event_func() work items spawned by it have a
chance to complete and then undock() will cause _DCK to be
evaluated and that will cause the devices handled by the
_handle_hotplug_event_func() to go away possibly while they are
being accessed.
This means that dd->ops->handler() for PCI devices should not point
to handle_hotplug_event_func(). Instead, it should point to a
function that will do the work of _handle_hotplug_event_func()
synchronously. For this reason, introduce such a function,
hotplug_event_func(), and modity acpiphp_dock_ops to point to
it as the handler.
Unfortunately, however, this is not sufficient, because if the dock
code were not changed further, hotplug_event_func() would now
deadlock with hotplug_dock_devices() that called it, since it would
run unregister_hotplug_dock_device() which in turn would attempt to
acquire the dock station's hp_lock mutex already acquired by
hotplug_dock_devices().
To resolve that deadlock use the observation that
unregister_hotplug_dock_device() won't need to acquire hp_lock
if PCI bridges the devices on the dock station depend on are
prevented from being removed prematurely while the first loop in
hotplug_dock_devices() is in progress.
To make that possible, introduce a mechanism by which the callers of
register_hotplug_dock_device() can provide "init" and "release"
routines that will be executed, respectively, during the addition
and removal of the physical device object associated with the
given ACPI device handle. Make acpiphp use two new functions,
acpiphp_dock_init() and acpiphp_dock_release(), that call
get_bridge() and put_bridge(), respectively, on the acpiphp bridge
holding the given device, for this purpose.
In addition to that, remove the dock station's list of
"hotplug devices" and make the dock code always walk the whole list
of "dependent devices" instead in such a way that the loops in
hotplug_dock_devices() and dock_event() (replacing the loops over
"hotplug devices") will take references to the list entries that
register_hotplug_dock_device() has been called for. That prevents
the "release" routines associated with those entries from being
called while the given entry is being processed and for PCI
devices this means that their bridges won't be removed (by a
concurrent thread) while hotplug_event_func() handling them is
being executed.
This change is based on two earlier patches from Jiang Liu.
References: https://bugzilla.kernel.org/show_bug.cgi?id=59501
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tracked-down-by: Jiang Liu <jiang.liu@huawei.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
2013-06-24 16:22:53 +07:00
|
|
|
static void acpiphp_dock_init(void *data)
|
|
|
|
{
|
2013-07-14 04:27:24 +07:00
|
|
|
struct acpiphp_context *context = data;
|
ACPI / dock / PCI: Synchronous handling of dock events for PCI devices
The interactions between the ACPI dock driver and the ACPI-based PCI
hotplug (acpiphp) are currently problematic because of ordering
issues during hot-remove operations.
First of all, the current ACPI glue code expects that physical
devices will always be deleted before deleting the companion ACPI
device objects. Otherwise, acpi_unbind_one() will fail with a
warning message printed to the kernel log, for example:
[ 185.026073] usb usb5: Oops, 'acpi_handle' corrupt
[ 185.035150] pci 0000:1b:00.0: Oops, 'acpi_handle' corrupt
[ 185.035515] pci 0000:18:02.0: Oops, 'acpi_handle' corrupt
[ 180.013656] port1: Oops, 'acpi_handle' corrupt
This means, in particular, that struct pci_dev objects have to
be deleted before the struct acpi_device objects they are "glued"
with.
Now, the following happens the during the undocking of an ACPI-based
dock station:
1) hotplug_dock_devices() invokes registered hotplug callbacks to
destroy physical devices associated with the ACPI device objects
depending on the dock station. It calls dd->ops->handler() for
each of those device objects.
2) For PCI devices dd->ops->handler() points to
handle_hotplug_event_func() that queues up a separate work item
to execute _handle_hotplug_event_func() for the given device and
returns immediately. That work item will be executed later.
3) hotplug_dock_devices() calls dock_remove_acpi_device() for each
device depending on the dock station. This runs acpi_bus_trim()
for each of them, which causes the underlying ACPI device object
to be destroyed, but the work items queued up by
handle_hotplug_event_func() haven't been started yet.
4) _handle_hotplug_event_func() queued up in step 2) are executed
and cause the above failure to happen, because the PCI devices
they handle do not have the companion ACPI device objects any
more (those objects have been deleted in step 3).
The possible breakage doesn't end here, though, because
hotplug_dock_devices() may return before at least some of the
_handle_hotplug_event_func() work items spawned by it have a
chance to complete and then undock() will cause _DCK to be
evaluated and that will cause the devices handled by the
_handle_hotplug_event_func() to go away possibly while they are
being accessed.
This means that dd->ops->handler() for PCI devices should not point
to handle_hotplug_event_func(). Instead, it should point to a
function that will do the work of _handle_hotplug_event_func()
synchronously. For this reason, introduce such a function,
hotplug_event_func(), and modity acpiphp_dock_ops to point to
it as the handler.
Unfortunately, however, this is not sufficient, because if the dock
code were not changed further, hotplug_event_func() would now
deadlock with hotplug_dock_devices() that called it, since it would
run unregister_hotplug_dock_device() which in turn would attempt to
acquire the dock station's hp_lock mutex already acquired by
hotplug_dock_devices().
To resolve that deadlock use the observation that
unregister_hotplug_dock_device() won't need to acquire hp_lock
if PCI bridges the devices on the dock station depend on are
prevented from being removed prematurely while the first loop in
hotplug_dock_devices() is in progress.
To make that possible, introduce a mechanism by which the callers of
register_hotplug_dock_device() can provide "init" and "release"
routines that will be executed, respectively, during the addition
and removal of the physical device object associated with the
given ACPI device handle. Make acpiphp use two new functions,
acpiphp_dock_init() and acpiphp_dock_release(), that call
get_bridge() and put_bridge(), respectively, on the acpiphp bridge
holding the given device, for this purpose.
In addition to that, remove the dock station's list of
"hotplug devices" and make the dock code always walk the whole list
of "dependent devices" instead in such a way that the loops in
hotplug_dock_devices() and dock_event() (replacing the loops over
"hotplug devices") will take references to the list entries that
register_hotplug_dock_device() has been called for. That prevents
the "release" routines associated with those entries from being
called while the given entry is being processed and for PCI
devices this means that their bridges won't be removed (by a
concurrent thread) while hotplug_event_func() handling them is
being executed.
This change is based on two earlier patches from Jiang Liu.
References: https://bugzilla.kernel.org/show_bug.cgi?id=59501
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tracked-down-by: Jiang Liu <jiang.liu@huawei.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
2013-06-24 16:22:53 +07:00
|
|
|
|
2013-07-14 04:27:25 +07:00
|
|
|
get_bridge(context->func.parent);
|
ACPI / dock / PCI: Synchronous handling of dock events for PCI devices
The interactions between the ACPI dock driver and the ACPI-based PCI
hotplug (acpiphp) are currently problematic because of ordering
issues during hot-remove operations.
First of all, the current ACPI glue code expects that physical
devices will always be deleted before deleting the companion ACPI
device objects. Otherwise, acpi_unbind_one() will fail with a
warning message printed to the kernel log, for example:
[ 185.026073] usb usb5: Oops, 'acpi_handle' corrupt
[ 185.035150] pci 0000:1b:00.0: Oops, 'acpi_handle' corrupt
[ 185.035515] pci 0000:18:02.0: Oops, 'acpi_handle' corrupt
[ 180.013656] port1: Oops, 'acpi_handle' corrupt
This means, in particular, that struct pci_dev objects have to
be deleted before the struct acpi_device objects they are "glued"
with.
Now, the following happens the during the undocking of an ACPI-based
dock station:
1) hotplug_dock_devices() invokes registered hotplug callbacks to
destroy physical devices associated with the ACPI device objects
depending on the dock station. It calls dd->ops->handler() for
each of those device objects.
2) For PCI devices dd->ops->handler() points to
handle_hotplug_event_func() that queues up a separate work item
to execute _handle_hotplug_event_func() for the given device and
returns immediately. That work item will be executed later.
3) hotplug_dock_devices() calls dock_remove_acpi_device() for each
device depending on the dock station. This runs acpi_bus_trim()
for each of them, which causes the underlying ACPI device object
to be destroyed, but the work items queued up by
handle_hotplug_event_func() haven't been started yet.
4) _handle_hotplug_event_func() queued up in step 2) are executed
and cause the above failure to happen, because the PCI devices
they handle do not have the companion ACPI device objects any
more (those objects have been deleted in step 3).
The possible breakage doesn't end here, though, because
hotplug_dock_devices() may return before at least some of the
_handle_hotplug_event_func() work items spawned by it have a
chance to complete and then undock() will cause _DCK to be
evaluated and that will cause the devices handled by the
_handle_hotplug_event_func() to go away possibly while they are
being accessed.
This means that dd->ops->handler() for PCI devices should not point
to handle_hotplug_event_func(). Instead, it should point to a
function that will do the work of _handle_hotplug_event_func()
synchronously. For this reason, introduce such a function,
hotplug_event_func(), and modity acpiphp_dock_ops to point to
it as the handler.
Unfortunately, however, this is not sufficient, because if the dock
code were not changed further, hotplug_event_func() would now
deadlock with hotplug_dock_devices() that called it, since it would
run unregister_hotplug_dock_device() which in turn would attempt to
acquire the dock station's hp_lock mutex already acquired by
hotplug_dock_devices().
To resolve that deadlock use the observation that
unregister_hotplug_dock_device() won't need to acquire hp_lock
if PCI bridges the devices on the dock station depend on are
prevented from being removed prematurely while the first loop in
hotplug_dock_devices() is in progress.
To make that possible, introduce a mechanism by which the callers of
register_hotplug_dock_device() can provide "init" and "release"
routines that will be executed, respectively, during the addition
and removal of the physical device object associated with the
given ACPI device handle. Make acpiphp use two new functions,
acpiphp_dock_init() and acpiphp_dock_release(), that call
get_bridge() and put_bridge(), respectively, on the acpiphp bridge
holding the given device, for this purpose.
In addition to that, remove the dock station's list of
"hotplug devices" and make the dock code always walk the whole list
of "dependent devices" instead in such a way that the loops in
hotplug_dock_devices() and dock_event() (replacing the loops over
"hotplug devices") will take references to the list entries that
register_hotplug_dock_device() has been called for. That prevents
the "release" routines associated with those entries from being
called while the given entry is being processed and for PCI
devices this means that their bridges won't be removed (by a
concurrent thread) while hotplug_event_func() handling them is
being executed.
This change is based on two earlier patches from Jiang Liu.
References: https://bugzilla.kernel.org/show_bug.cgi?id=59501
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tracked-down-by: Jiang Liu <jiang.liu@huawei.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
2013-06-24 16:22:53 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void acpiphp_dock_release(void *data)
|
|
|
|
{
|
2013-07-14 04:27:24 +07:00
|
|
|
struct acpiphp_context *context = data;
|
ACPI / dock / PCI: Synchronous handling of dock events for PCI devices
The interactions between the ACPI dock driver and the ACPI-based PCI
hotplug (acpiphp) are currently problematic because of ordering
issues during hot-remove operations.
First of all, the current ACPI glue code expects that physical
devices will always be deleted before deleting the companion ACPI
device objects. Otherwise, acpi_unbind_one() will fail with a
warning message printed to the kernel log, for example:
[ 185.026073] usb usb5: Oops, 'acpi_handle' corrupt
[ 185.035150] pci 0000:1b:00.0: Oops, 'acpi_handle' corrupt
[ 185.035515] pci 0000:18:02.0: Oops, 'acpi_handle' corrupt
[ 180.013656] port1: Oops, 'acpi_handle' corrupt
This means, in particular, that struct pci_dev objects have to
be deleted before the struct acpi_device objects they are "glued"
with.
Now, the following happens the during the undocking of an ACPI-based
dock station:
1) hotplug_dock_devices() invokes registered hotplug callbacks to
destroy physical devices associated with the ACPI device objects
depending on the dock station. It calls dd->ops->handler() for
each of those device objects.
2) For PCI devices dd->ops->handler() points to
handle_hotplug_event_func() that queues up a separate work item
to execute _handle_hotplug_event_func() for the given device and
returns immediately. That work item will be executed later.
3) hotplug_dock_devices() calls dock_remove_acpi_device() for each
device depending on the dock station. This runs acpi_bus_trim()
for each of them, which causes the underlying ACPI device object
to be destroyed, but the work items queued up by
handle_hotplug_event_func() haven't been started yet.
4) _handle_hotplug_event_func() queued up in step 2) are executed
and cause the above failure to happen, because the PCI devices
they handle do not have the companion ACPI device objects any
more (those objects have been deleted in step 3).
The possible breakage doesn't end here, though, because
hotplug_dock_devices() may return before at least some of the
_handle_hotplug_event_func() work items spawned by it have a
chance to complete and then undock() will cause _DCK to be
evaluated and that will cause the devices handled by the
_handle_hotplug_event_func() to go away possibly while they are
being accessed.
This means that dd->ops->handler() for PCI devices should not point
to handle_hotplug_event_func(). Instead, it should point to a
function that will do the work of _handle_hotplug_event_func()
synchronously. For this reason, introduce such a function,
hotplug_event_func(), and modity acpiphp_dock_ops to point to
it as the handler.
Unfortunately, however, this is not sufficient, because if the dock
code were not changed further, hotplug_event_func() would now
deadlock with hotplug_dock_devices() that called it, since it would
run unregister_hotplug_dock_device() which in turn would attempt to
acquire the dock station's hp_lock mutex already acquired by
hotplug_dock_devices().
To resolve that deadlock use the observation that
unregister_hotplug_dock_device() won't need to acquire hp_lock
if PCI bridges the devices on the dock station depend on are
prevented from being removed prematurely while the first loop in
hotplug_dock_devices() is in progress.
To make that possible, introduce a mechanism by which the callers of
register_hotplug_dock_device() can provide "init" and "release"
routines that will be executed, respectively, during the addition
and removal of the physical device object associated with the
given ACPI device handle. Make acpiphp use two new functions,
acpiphp_dock_init() and acpiphp_dock_release(), that call
get_bridge() and put_bridge(), respectively, on the acpiphp bridge
holding the given device, for this purpose.
In addition to that, remove the dock station's list of
"hotplug devices" and make the dock code always walk the whole list
of "dependent devices" instead in such a way that the loops in
hotplug_dock_devices() and dock_event() (replacing the loops over
"hotplug devices") will take references to the list entries that
register_hotplug_dock_device() has been called for. That prevents
the "release" routines associated with those entries from being
called while the given entry is being processed and for PCI
devices this means that their bridges won't be removed (by a
concurrent thread) while hotplug_event_func() handling them is
being executed.
This change is based on two earlier patches from Jiang Liu.
References: https://bugzilla.kernel.org/show_bug.cgi?id=59501
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tracked-down-by: Jiang Liu <jiang.liu@huawei.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
2013-06-24 16:22:53 +07:00
|
|
|
|
2013-07-14 04:27:25 +07:00
|
|
|
put_bridge(context->func.parent);
|
ACPI / dock / PCI: Synchronous handling of dock events for PCI devices
The interactions between the ACPI dock driver and the ACPI-based PCI
hotplug (acpiphp) are currently problematic because of ordering
issues during hot-remove operations.
First of all, the current ACPI glue code expects that physical
devices will always be deleted before deleting the companion ACPI
device objects. Otherwise, acpi_unbind_one() will fail with a
warning message printed to the kernel log, for example:
[ 185.026073] usb usb5: Oops, 'acpi_handle' corrupt
[ 185.035150] pci 0000:1b:00.0: Oops, 'acpi_handle' corrupt
[ 185.035515] pci 0000:18:02.0: Oops, 'acpi_handle' corrupt
[ 180.013656] port1: Oops, 'acpi_handle' corrupt
This means, in particular, that struct pci_dev objects have to
be deleted before the struct acpi_device objects they are "glued"
with.
Now, the following happens the during the undocking of an ACPI-based
dock station:
1) hotplug_dock_devices() invokes registered hotplug callbacks to
destroy physical devices associated with the ACPI device objects
depending on the dock station. It calls dd->ops->handler() for
each of those device objects.
2) For PCI devices dd->ops->handler() points to
handle_hotplug_event_func() that queues up a separate work item
to execute _handle_hotplug_event_func() for the given device and
returns immediately. That work item will be executed later.
3) hotplug_dock_devices() calls dock_remove_acpi_device() for each
device depending on the dock station. This runs acpi_bus_trim()
for each of them, which causes the underlying ACPI device object
to be destroyed, but the work items queued up by
handle_hotplug_event_func() haven't been started yet.
4) _handle_hotplug_event_func() queued up in step 2) are executed
and cause the above failure to happen, because the PCI devices
they handle do not have the companion ACPI device objects any
more (those objects have been deleted in step 3).
The possible breakage doesn't end here, though, because
hotplug_dock_devices() may return before at least some of the
_handle_hotplug_event_func() work items spawned by it have a
chance to complete and then undock() will cause _DCK to be
evaluated and that will cause the devices handled by the
_handle_hotplug_event_func() to go away possibly while they are
being accessed.
This means that dd->ops->handler() for PCI devices should not point
to handle_hotplug_event_func(). Instead, it should point to a
function that will do the work of _handle_hotplug_event_func()
synchronously. For this reason, introduce such a function,
hotplug_event_func(), and modity acpiphp_dock_ops to point to
it as the handler.
Unfortunately, however, this is not sufficient, because if the dock
code were not changed further, hotplug_event_func() would now
deadlock with hotplug_dock_devices() that called it, since it would
run unregister_hotplug_dock_device() which in turn would attempt to
acquire the dock station's hp_lock mutex already acquired by
hotplug_dock_devices().
To resolve that deadlock use the observation that
unregister_hotplug_dock_device() won't need to acquire hp_lock
if PCI bridges the devices on the dock station depend on are
prevented from being removed prematurely while the first loop in
hotplug_dock_devices() is in progress.
To make that possible, introduce a mechanism by which the callers of
register_hotplug_dock_device() can provide "init" and "release"
routines that will be executed, respectively, during the addition
and removal of the physical device object associated with the
given ACPI device handle. Make acpiphp use two new functions,
acpiphp_dock_init() and acpiphp_dock_release(), that call
get_bridge() and put_bridge(), respectively, on the acpiphp bridge
holding the given device, for this purpose.
In addition to that, remove the dock station's list of
"hotplug devices" and make the dock code always walk the whole list
of "dependent devices" instead in such a way that the loops in
hotplug_dock_devices() and dock_event() (replacing the loops over
"hotplug devices") will take references to the list entries that
register_hotplug_dock_device() has been called for. That prevents
the "release" routines associated with those entries from being
called while the given entry is being processed and for PCI
devices this means that their bridges won't be removed (by a
concurrent thread) while hotplug_event_func() handling them is
being executed.
This change is based on two earlier patches from Jiang Liu.
References: https://bugzilla.kernel.org/show_bug.cgi?id=59501
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tracked-down-by: Jiang Liu <jiang.liu@huawei.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
2013-06-24 16:22:53 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* callback routine to register each ACPI PCI slot object */
|
2013-07-14 04:27:24 +07:00
|
|
|
static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data,
|
|
|
|
void **rv)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-07-14 04:27:24 +07:00
|
|
|
struct acpiphp_bridge *bridge = data;
|
|
|
|
struct acpiphp_context *context;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct acpiphp_slot *slot;
|
|
|
|
struct acpiphp_func *newfunc;
|
|
|
|
acpi_status status = AE_OK;
|
2013-07-14 04:27:24 +07:00
|
|
|
unsigned long long adr;
|
|
|
|
int device, function;
|
2008-12-17 10:09:12 +07:00
|
|
|
struct pci_bus *pbus = bridge->pci_bus;
|
2013-07-14 04:27:24 +07:00
|
|
|
struct pci_dev *pdev = bridge->pci_dev;
|
2013-04-12 12:44:26 +07:00
|
|
|
u32 val;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
if (pdev && device_is_managed_by_native_pciehp(pdev))
|
2005-04-17 05:20:36 +07:00
|
|
|
return AE_OK;
|
|
|
|
|
2012-06-21 05:18:29 +07:00
|
|
|
status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
2013-11-28 03:33:09 +07:00
|
|
|
if (status != AE_NOT_FOUND)
|
|
|
|
acpi_handle_warn(handle,
|
|
|
|
"can't evaluate _ADR (%#x)\n", status);
|
2012-06-21 05:18:29 +07:00
|
|
|
return AE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
device = (adr >> 16) & 0xffff;
|
|
|
|
function = adr & 0xffff;
|
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
mutex_lock(&acpiphp_context_lock);
|
|
|
|
context = acpiphp_init_context(handle);
|
|
|
|
if (!context) {
|
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
|
|
|
acpi_handle_err(handle, "No hotplug context\n");
|
|
|
|
return AE_NOT_EXIST;
|
|
|
|
}
|
2013-07-14 04:27:25 +07:00
|
|
|
newfunc = &context->func;
|
|
|
|
newfunc->function = function;
|
2013-07-14 04:27:25 +07:00
|
|
|
newfunc->parent = bridge;
|
2013-07-14 04:27:24 +07:00
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
|
|
|
|
2013-06-28 23:24:43 +07:00
|
|
|
if (acpi_has_method(handle, "_EJ0"))
|
2006-02-24 08:56:03 +07:00
|
|
|
newfunc->flags = FUNC_HAS_EJ0;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-06-28 23:24:43 +07:00
|
|
|
if (acpi_has_method(handle, "_STA"))
|
2005-04-17 05:20:36 +07:00
|
|
|
newfunc->flags |= FUNC_HAS_STA;
|
|
|
|
|
2013-06-28 23:24:43 +07:00
|
|
|
if (acpi_has_method(handle, "_DCK"))
|
2006-02-24 08:56:03 +07:00
|
|
|
newfunc->flags |= FUNC_HAS_DCK;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* search for objects that share the same slot */
|
2013-04-12 12:44:27 +07:00
|
|
|
list_for_each_entry(slot, &bridge->slots, node)
|
2013-07-14 04:27:24 +07:00
|
|
|
if (slot->device == device)
|
2013-07-14 04:27:24 +07:00
|
|
|
goto slot_found;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
|
|
|
|
if (!slot) {
|
|
|
|
status = AE_NO_MEMORY;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2013-07-14 04:27:25 +07:00
|
|
|
slot->bus = bridge->pci_bus;
|
2013-07-14 04:27:24 +07:00
|
|
|
slot->device = device;
|
|
|
|
INIT_LIST_HEAD(&slot->funcs);
|
|
|
|
mutex_init(&slot->crit_sect);
|
|
|
|
|
|
|
|
list_add_tail(&slot->node, &bridge->slots);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-11-15 01:28:18 +07:00
|
|
|
/* Register slots for ejectable functions only. */
|
2013-07-14 04:27:24 +07:00
|
|
|
if (acpi_pci_check_ejectable(pbus, handle) || is_dock_device(handle)) {
|
|
|
|
unsigned long long sun;
|
|
|
|
int retval;
|
2013-07-14 04:27:24 +07:00
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
bridge->nr_slots++;
|
|
|
|
status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
sun = bridge->nr_slots;
|
|
|
|
|
2013-09-25 07:11:48 +07:00
|
|
|
pr_debug("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
|
2013-07-14 04:27:25 +07:00
|
|
|
sun, pci_domain_nr(pbus), pbus->number, device);
|
2013-07-14 04:27:24 +07:00
|
|
|
|
2013-07-14 04:27:25 +07:00
|
|
|
retval = acpiphp_register_hotplug_slot(slot, sun);
|
2013-07-14 04:27:24 +07:00
|
|
|
if (retval) {
|
2013-08-18 03:16:33 +07:00
|
|
|
slot->slot = NULL;
|
2013-07-14 04:27:24 +07:00
|
|
|
bridge->nr_slots--;
|
|
|
|
if (retval == -EBUSY)
|
2013-09-25 07:11:48 +07:00
|
|
|
pr_warn("Slot %llu already registered by another "
|
2013-07-14 04:27:25 +07:00
|
|
|
"hotplug driver\n", sun);
|
2013-07-14 04:27:24 +07:00
|
|
|
else
|
2013-09-25 07:11:48 +07:00
|
|
|
pr_warn("acpiphp_register_hotplug_slot failed "
|
2013-07-14 04:27:24 +07:00
|
|
|
"(err code = 0x%x)\n", retval);
|
|
|
|
}
|
|
|
|
/* Even if the slot registration fails, we can still use it. */
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
slot_found:
|
2005-04-17 05:20:36 +07:00
|
|
|
newfunc->slot = slot;
|
|
|
|
list_add_tail(&newfunc->sibling, &slot->funcs);
|
|
|
|
|
2013-04-12 12:44:26 +07:00
|
|
|
if (pci_bus_read_dev_vendor_id(pbus, PCI_DEVFN(device, function),
|
|
|
|
&val, 60*1000))
|
2013-07-14 04:27:26 +07:00
|
|
|
slot->flags |= SLOT_ENABLED;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-06-28 14:08:06 +07:00
|
|
|
if (is_dock_device(handle)) {
|
|
|
|
/* we don't want to call this device's _EJ0
|
|
|
|
* because we want the dock notify handler
|
|
|
|
* to call it after it calls _DCK
|
2006-02-24 08:56:03 +07:00
|
|
|
*/
|
|
|
|
newfunc->flags &= ~FUNC_HAS_EJ0;
|
2006-06-28 14:08:06 +07:00
|
|
|
if (register_hotplug_dock_device(handle,
|
2013-07-14 04:27:24 +07:00
|
|
|
&acpiphp_dock_ops, context,
|
ACPI / dock / PCI: Synchronous handling of dock events for PCI devices
The interactions between the ACPI dock driver and the ACPI-based PCI
hotplug (acpiphp) are currently problematic because of ordering
issues during hot-remove operations.
First of all, the current ACPI glue code expects that physical
devices will always be deleted before deleting the companion ACPI
device objects. Otherwise, acpi_unbind_one() will fail with a
warning message printed to the kernel log, for example:
[ 185.026073] usb usb5: Oops, 'acpi_handle' corrupt
[ 185.035150] pci 0000:1b:00.0: Oops, 'acpi_handle' corrupt
[ 185.035515] pci 0000:18:02.0: Oops, 'acpi_handle' corrupt
[ 180.013656] port1: Oops, 'acpi_handle' corrupt
This means, in particular, that struct pci_dev objects have to
be deleted before the struct acpi_device objects they are "glued"
with.
Now, the following happens the during the undocking of an ACPI-based
dock station:
1) hotplug_dock_devices() invokes registered hotplug callbacks to
destroy physical devices associated with the ACPI device objects
depending on the dock station. It calls dd->ops->handler() for
each of those device objects.
2) For PCI devices dd->ops->handler() points to
handle_hotplug_event_func() that queues up a separate work item
to execute _handle_hotplug_event_func() for the given device and
returns immediately. That work item will be executed later.
3) hotplug_dock_devices() calls dock_remove_acpi_device() for each
device depending on the dock station. This runs acpi_bus_trim()
for each of them, which causes the underlying ACPI device object
to be destroyed, but the work items queued up by
handle_hotplug_event_func() haven't been started yet.
4) _handle_hotplug_event_func() queued up in step 2) are executed
and cause the above failure to happen, because the PCI devices
they handle do not have the companion ACPI device objects any
more (those objects have been deleted in step 3).
The possible breakage doesn't end here, though, because
hotplug_dock_devices() may return before at least some of the
_handle_hotplug_event_func() work items spawned by it have a
chance to complete and then undock() will cause _DCK to be
evaluated and that will cause the devices handled by the
_handle_hotplug_event_func() to go away possibly while they are
being accessed.
This means that dd->ops->handler() for PCI devices should not point
to handle_hotplug_event_func(). Instead, it should point to a
function that will do the work of _handle_hotplug_event_func()
synchronously. For this reason, introduce such a function,
hotplug_event_func(), and modity acpiphp_dock_ops to point to
it as the handler.
Unfortunately, however, this is not sufficient, because if the dock
code were not changed further, hotplug_event_func() would now
deadlock with hotplug_dock_devices() that called it, since it would
run unregister_hotplug_dock_device() which in turn would attempt to
acquire the dock station's hp_lock mutex already acquired by
hotplug_dock_devices().
To resolve that deadlock use the observation that
unregister_hotplug_dock_device() won't need to acquire hp_lock
if PCI bridges the devices on the dock station depend on are
prevented from being removed prematurely while the first loop in
hotplug_dock_devices() is in progress.
To make that possible, introduce a mechanism by which the callers of
register_hotplug_dock_device() can provide "init" and "release"
routines that will be executed, respectively, during the addition
and removal of the physical device object associated with the
given ACPI device handle. Make acpiphp use two new functions,
acpiphp_dock_init() and acpiphp_dock_release(), that call
get_bridge() and put_bridge(), respectively, on the acpiphp bridge
holding the given device, for this purpose.
In addition to that, remove the dock station's list of
"hotplug devices" and make the dock code always walk the whole list
of "dependent devices" instead in such a way that the loops in
hotplug_dock_devices() and dock_event() (replacing the loops over
"hotplug devices") will take references to the list entries that
register_hotplug_dock_device() has been called for. That prevents
the "release" routines associated with those entries from being
called while the given entry is being processed and for PCI
devices this means that their bridges won't be removed (by a
concurrent thread) while hotplug_event_func() handling them is
being executed.
This change is based on two earlier patches from Jiang Liu.
References: https://bugzilla.kernel.org/show_bug.cgi?id=59501
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tracked-down-by: Jiang Liu <jiang.liu@huawei.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
2013-06-24 16:22:53 +07:00
|
|
|
acpiphp_dock_init, acpiphp_dock_release))
|
2013-09-25 07:11:48 +07:00
|
|
|
pr_debug("failed to register dock device\n");
|
2006-02-24 08:56:03 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* install notify handler */
|
2006-02-24 08:56:03 +07:00
|
|
|
if (!(newfunc->flags & FUNC_HAS_DCK)) {
|
2013-07-14 04:27:24 +07:00
|
|
|
status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
|
|
|
|
handle_hotplug_event,
|
|
|
|
context);
|
2013-07-14 04:27:24 +07:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
acpi_handle_err(handle,
|
|
|
|
"failed to install notify handler\n");
|
2013-07-14 04:27:23 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-07-14 04:27:23 +07:00
|
|
|
return AE_OK;
|
2006-02-24 08:56:08 +07:00
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
err:
|
|
|
|
mutex_lock(&acpiphp_context_lock);
|
|
|
|
acpiphp_put_context(context);
|
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
|
|
|
return status;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2005-04-28 14:25:53 +07:00
|
|
|
static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
|
|
|
|
{
|
2013-07-14 04:27:24 +07:00
|
|
|
struct acpiphp_context *context;
|
|
|
|
struct acpiphp_bridge *bridge = NULL;
|
2009-10-27 10:25:27 +07:00
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
mutex_lock(&acpiphp_context_lock);
|
|
|
|
context = acpiphp_get_context(handle);
|
|
|
|
if (context) {
|
|
|
|
bridge = context->bridge;
|
|
|
|
if (bridge)
|
2013-04-12 12:44:28 +07:00
|
|
|
get_bridge(bridge);
|
2005-04-28 14:25:53 +07:00
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
acpiphp_put_context(context);
|
|
|
|
}
|
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
|
|
|
return bridge;
|
2005-04-28 14:25:53 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-04-28 14:25:54 +07:00
|
|
|
static void cleanup_bridge(struct acpiphp_bridge *bridge)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-04-12 12:44:28 +07:00
|
|
|
struct acpiphp_slot *slot;
|
|
|
|
struct acpiphp_func *func;
|
2005-04-28 14:25:53 +07:00
|
|
|
acpi_status status;
|
|
|
|
|
2013-04-12 12:44:28 +07:00
|
|
|
list_for_each_entry(slot, &bridge->slots, node) {
|
|
|
|
list_for_each_entry(func, &slot->funcs, sibling) {
|
2013-07-14 04:27:25 +07:00
|
|
|
acpi_handle handle = func_to_handle(func);
|
|
|
|
|
|
|
|
if (is_dock_device(handle))
|
|
|
|
unregister_hotplug_dock_device(handle);
|
|
|
|
|
2006-02-24 08:56:03 +07:00
|
|
|
if (!(func->flags & FUNC_HAS_DCK)) {
|
2013-07-14 04:27:25 +07:00
|
|
|
status = acpi_remove_notify_handler(handle,
|
2013-07-14 04:27:24 +07:00
|
|
|
ACPI_SYSTEM_NOTIFY,
|
|
|
|
handle_hotplug_event);
|
2006-02-24 08:56:03 +07:00
|
|
|
if (ACPI_FAILURE(status))
|
2013-09-25 07:11:48 +07:00
|
|
|
pr_err("failed to remove notify handler\n");
|
2006-02-24 08:56:03 +07:00
|
|
|
}
|
2005-04-28 14:25:53 +07:00
|
|
|
}
|
2014-01-10 21:24:41 +07:00
|
|
|
slot->flags |= SLOT_IS_GOING_AWAY;
|
2013-08-18 03:16:33 +07:00
|
|
|
if (slot->slot)
|
|
|
|
acpiphp_unregister_hotplug_slot(slot);
|
2005-04-28 14:25:53 +07:00
|
|
|
}
|
|
|
|
|
2013-04-12 12:44:28 +07:00
|
|
|
mutex_lock(&bridge_mutex);
|
2005-04-28 14:25:53 +07:00
|
|
|
list_del(&bridge->list);
|
2013-04-12 12:44:28 +07:00
|
|
|
mutex_unlock(&bridge_mutex);
|
2014-01-10 21:24:41 +07:00
|
|
|
|
2014-02-04 04:30:06 +07:00
|
|
|
mutex_lock(&acpiphp_context_lock);
|
2014-01-10 21:24:41 +07:00
|
|
|
bridge->is_going_away = true;
|
2014-02-04 04:30:06 +07:00
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2006-02-24 08:55:58 +07:00
|
|
|
/**
|
2007-11-29 00:04:30 +07:00
|
|
|
* acpiphp_max_busnr - return the highest reserved bus number under the given bus.
|
2006-02-24 08:55:58 +07:00
|
|
|
* @bus: bus to start search with
|
|
|
|
*/
|
|
|
|
static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
struct list_head *tmp;
|
|
|
|
unsigned char max, n;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pci_bus_max_busnr will return the highest
|
|
|
|
* reserved busnr for all these children.
|
|
|
|
* that is equivalent to the bus->subordinate
|
|
|
|
* value. We don't want to use the parent's
|
|
|
|
* bus->subordinate value because it could have
|
|
|
|
* padding in it.
|
|
|
|
*/
|
2012-05-18 08:51:11 +07:00
|
|
|
max = bus->busn_res.start;
|
2006-02-24 08:55:58 +07:00
|
|
|
|
|
|
|
list_for_each(tmp, &bus->children) {
|
|
|
|
n = pci_bus_max_busnr(pci_bus_b(tmp));
|
|
|
|
if (n > max)
|
|
|
|
max = n;
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-14 04:27:25 +07:00
|
|
|
* acpiphp_bus_trim - Trim device objects in an ACPI namespace subtree.
|
|
|
|
* @handle: ACPI device object handle to start from.
|
2006-02-24 08:55:58 +07:00
|
|
|
*/
|
2013-07-14 04:27:25 +07:00
|
|
|
static void acpiphp_bus_trim(acpi_handle handle)
|
2006-02-24 08:55:58 +07:00
|
|
|
{
|
2013-07-14 04:27:25 +07:00
|
|
|
struct acpi_device *adev = NULL;
|
2006-02-24 08:55:58 +07:00
|
|
|
|
2013-07-14 04:27:25 +07:00
|
|
|
acpi_bus_get_device(handle, &adev);
|
|
|
|
if (adev)
|
|
|
|
acpi_bus_trim(adev);
|
2006-02-24 08:55:58 +07:00
|
|
|
}
|
|
|
|
|
2006-03-22 12:49:09 +07:00
|
|
|
/**
|
2013-07-14 04:27:25 +07:00
|
|
|
* acpiphp_bus_add - Scan ACPI namespace subtree.
|
|
|
|
* @handle: ACPI object handle to start the scan from.
|
2006-03-22 12:49:09 +07:00
|
|
|
*/
|
2013-07-14 04:27:25 +07:00
|
|
|
static void acpiphp_bus_add(acpi_handle handle)
|
2006-03-22 12:49:09 +07:00
|
|
|
{
|
2013-07-14 04:27:26 +07:00
|
|
|
struct acpi_device *adev = NULL;
|
|
|
|
|
2013-07-14 04:27:25 +07:00
|
|
|
acpi_bus_scan(handle);
|
2013-07-14 04:27:26 +07:00
|
|
|
acpi_bus_get_device(handle, &adev);
|
ACPI / scan: Add acpi_device objects for all device nodes in the namespace
Modify the ACPI namespace scanning code to register a struct
acpi_device object for every namespace node representing a device,
processor and so on, even if the device represented by that namespace
node is reported to be not present and not functional by _STA.
There are multiple reasons to do that. First of all, it avoids
quite a lot of overhead when struct acpi_device objects are
deleted every time acpi_bus_trim() is run and then added again
by a subsequent acpi_bus_scan() for the same scope, although the
namespace objects they correspond to stay in memory all the time
(which always is the case on a vast majority of systems).
Second, it will allow user space to see that there are namespace
nodes representing devices that are not present at the moment and may
be added to the system. It will also allow user space to evaluate
_SUN for those nodes to check what physical slots the "missing"
devices may be put into and it will make sense to add a sysfs
attribute for _STA evaluation after this change (that will be
useful for thermal management on some systems).
Next, it will help to consolidate the ACPI hotplug handling among
subsystems by making it possible to store hotplug-related information
in struct acpi_device objects in a standard common way.
Finally, it will help to avoid a race condition related to the
deletion of ACPI namespace nodes. Namely, namespace nodes may be
deleted as a result of a table unload triggered by _EJ0 or _DCK.
If a hotplug notification for one of those nodes is triggered
right before the deletion and it executes a hotplug callback
via acpi_hotplug_execute(), the ACPI handle passed to that
callback may be stale when the callback actually runs. One way
to work around that is to always pass struct acpi_device pointers
to hotplug callbacks after doing a get_device() on the objects in
question which eliminates the use-after-free possibility (the ACPI
handles in those objects are invalidated by acpi_scan_drop_device(),
so they will trigger ACPICA errors on attempts to use them).
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-11-23 03:54:37 +07:00
|
|
|
if (acpi_device_enumerated(adev))
|
2013-07-14 04:27:26 +07:00
|
|
|
acpi_device_set_power(adev, ACPI_STATE_D0);
|
2006-03-22 12:49:09 +07:00
|
|
|
}
|
2006-02-24 08:55:58 +07:00
|
|
|
|
2010-02-25 09:59:34 +07:00
|
|
|
static void acpiphp_set_acpi_region(struct acpiphp_slot *slot)
|
|
|
|
{
|
|
|
|
struct acpiphp_func *func;
|
|
|
|
union acpi_object params[2];
|
|
|
|
struct acpi_object_list arg_list;
|
|
|
|
|
|
|
|
list_for_each_entry(func, &slot->funcs, sibling) {
|
|
|
|
arg_list.count = 2;
|
|
|
|
arg_list.pointer = params;
|
|
|
|
params[0].type = ACPI_TYPE_INTEGER;
|
|
|
|
params[0].integer.value = ACPI_ADR_SPACE_PCI_CONFIG;
|
|
|
|
params[1].type = ACPI_TYPE_INTEGER;
|
|
|
|
params[1].integer.value = 1;
|
|
|
|
/* _REG is optional, we don't care about if there is failure */
|
2013-07-14 04:27:25 +07:00
|
|
|
acpi_evaluate_object(func_to_handle(func), "_REG", &arg_list,
|
|
|
|
NULL);
|
2010-02-25 09:59:34 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 04:20:42 +07:00
|
|
|
static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
struct acpiphp_func *func;
|
|
|
|
|
|
|
|
/* quirk, or pcie could set it already */
|
|
|
|
if (dev->is_hotplug_bridge)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list_for_each_entry(func, &slot->funcs, sibling) {
|
|
|
|
if (PCI_FUNC(dev->devfn) == func->function) {
|
2013-07-14 04:27:24 +07:00
|
|
|
dev->is_hotplug_bridge = 1;
|
2013-01-22 04:20:42 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-12 12:44:26 +07:00
|
|
|
|
ACPI / hotplug / PCI: Avoid parent bus rescans on spurious device checks
In the current ACPIPHP notify handler we always go directly for a
rescan of the parent bus if we get a device check notification for
a device that is not a bridge. However, this obviously is
overzealous if nothing really changes, because this way we may rescan
the whole PCI hierarchy pretty much in vain.
That happens on Alex Williamson's machine whose ACPI tables contain
device objects that are supposed to coresspond to PCIe root ports,
but those ports aren't physically present (or at least they aren't
visible in the PCI config space to us). The BIOS generates multiple
device check notifies for those objects during boot and for each of
them we go straight for the parent bus rescan, but the parent bus is
the root bus in this particular case. In consequence, we rescan the
whole PCI bus from the top several times in a row, which is
completely unnecessary, increases boot time by 50% (after previous
fixes) and generates excess dmesg output from the PCI subsystem.
Fix the problem by checking if we can find anything new in the
slot corresponding to the device we've got a device check notify
for and doing nothig if that's not the case.
The spec (ACPI 5.0, Section 5.6.6) appears to mandate this behavior,
as it says:
Device Check. Used to notify OSPM that the device either appeared
or disappeared. If the device has appeared, OSPM will re-enumerate
from the parent. If the device has disappeared, OSPM will
invalidate the state of the device. OSPM may optimize out
re-enumeration.
Therefore, according to the spec, we are free to do nothing if
nothing changes.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60865
Reported-and-tested-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-09-08 05:07:28 +07:00
|
|
|
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));
|
|
|
|
|
|
|
|
return pci_scan_slot(slot->bus, PCI_DEVFN(slot->device, 0));
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
2013-07-14 04:27:26 +07:00
|
|
|
* enable_slot - enable, configure a slot
|
2005-04-17 05:20:36 +07:00
|
|
|
* @slot: slot to be enabled
|
|
|
|
*
|
|
|
|
* This function should be called per *physical slot*,
|
|
|
|
* not per each slot object in ACPI namespace.
|
|
|
|
*/
|
2013-07-14 04:27:26 +07:00
|
|
|
static void __ref enable_slot(struct acpiphp_slot *slot)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct pci_dev *dev;
|
2013-07-14 04:27:25 +07:00
|
|
|
struct pci_bus *bus = slot->bus;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct acpiphp_func *func;
|
2013-07-14 04:27:26 +07:00
|
|
|
int max, pass;
|
PCI / ACPI: Use boot-time resource allocation rules during hotplug
On x86 platforms, the kernel respects PCI resource assignments from
the BIOS and only reassigns resources for unassigned BARs at boot
time. However, with the ACPI-based hotplug (acpiphp), it ignores the
BIOS' PCI resource assignments completely and reassigns all resources
by itself. This causes differences in PCI resource allocation
between boot time and runtime hotplug to occur, which is generally
undesirable and sometimes actively breaks things.
Namely, if there are enough resources, reassigning all PCI resources
during runtime hotplug should work, but it may fail if the resources
are constrained. This may happen, for instance, when some PCI
devices with huge MMIO BARs are involved in the runtime hotplug
operations, because the current PCI MMIO alignment algorithm may
waste huge chunks of MMIO address space in those cases.
On the Alexander's Sony VAIO VPCZ23A4R the BIOS allocates limited
MMIO resources for the dock station which contains a device
(graphics adapter) with a 256MB MMIO BAR. An attempt to reassign
that during runtime hotplug causes the dock station MMIO window to be
exhausted and acpiphp fails to allocate resources for the majority
of devices on the dock station as a result.
To prevent that from happening, modify acpiphp to follow the boot
time resources allocation behavior so that the BIOS' resource
assignments are respected during runtime hotplug too.
[rjw: Changelog]
References: https://bugzilla.kernel.org/show_bug.cgi?id=56531
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-06-23 06:01:35 +07:00
|
|
|
LIST_HEAD(add_list);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-10-30 19:40:36 +07:00
|
|
|
acpiphp_rescan_slot(slot);
|
2006-02-24 08:55:58 +07:00
|
|
|
max = acpiphp_max_busnr(bus);
|
2005-04-28 14:25:53 +07:00
|
|
|
for (pass = 0; pass < 2; pass++) {
|
|
|
|
list_for_each_entry(dev, &bus->devices, bus_list) {
|
|
|
|
if (PCI_SLOT(dev->devfn) != slot->device)
|
|
|
|
continue;
|
2013-07-14 04:27:26 +07:00
|
|
|
|
2005-04-28 14:25:53 +07:00
|
|
|
if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
|
2005-12-15 00:37:26 +07:00
|
|
|
dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
|
2005-04-28 14:25:53 +07:00
|
|
|
max = pci_scan_bridge(bus, dev, max, pass);
|
2013-01-22 04:20:42 +07:00
|
|
|
if (pass && dev->subordinate) {
|
|
|
|
check_hotplug_bridge(slot, dev);
|
PCI / ACPI: Use boot-time resource allocation rules during hotplug
On x86 platforms, the kernel respects PCI resource assignments from
the BIOS and only reassigns resources for unassigned BARs at boot
time. However, with the ACPI-based hotplug (acpiphp), it ignores the
BIOS' PCI resource assignments completely and reassigns all resources
by itself. This causes differences in PCI resource allocation
between boot time and runtime hotplug to occur, which is generally
undesirable and sometimes actively breaks things.
Namely, if there are enough resources, reassigning all PCI resources
during runtime hotplug should work, but it may fail if the resources
are constrained. This may happen, for instance, when some PCI
devices with huge MMIO BARs are involved in the runtime hotplug
operations, because the current PCI MMIO alignment algorithm may
waste huge chunks of MMIO address space in those cases.
On the Alexander's Sony VAIO VPCZ23A4R the BIOS allocates limited
MMIO resources for the dock station which contains a device
(graphics adapter) with a 256MB MMIO BAR. An attempt to reassign
that during runtime hotplug causes the dock station MMIO window to be
exhausted and acpiphp fails to allocate resources for the majority
of devices on the dock station as a result.
To prevent that from happening, modify acpiphp to follow the boot
time resources allocation behavior so that the BIOS' resource
assignments are respected during runtime hotplug too.
[rjw: Changelog]
References: https://bugzilla.kernel.org/show_bug.cgi?id=56531
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-06-23 06:01:35 +07:00
|
|
|
pcibios_resource_survey_bus(dev->subordinate);
|
|
|
|
__pci_bus_size_bridges(dev->subordinate,
|
|
|
|
&add_list);
|
2013-01-22 04:20:42 +07:00
|
|
|
}
|
2005-12-15 00:37:26 +07:00
|
|
|
}
|
2005-04-28 14:25:53 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
PCI / ACPI: Use boot-time resource allocation rules during hotplug
On x86 platforms, the kernel respects PCI resource assignments from
the BIOS and only reassigns resources for unassigned BARs at boot
time. However, with the ACPI-based hotplug (acpiphp), it ignores the
BIOS' PCI resource assignments completely and reassigns all resources
by itself. This causes differences in PCI resource allocation
between boot time and runtime hotplug to occur, which is generally
undesirable and sometimes actively breaks things.
Namely, if there are enough resources, reassigning all PCI resources
during runtime hotplug should work, but it may fail if the resources
are constrained. This may happen, for instance, when some PCI
devices with huge MMIO BARs are involved in the runtime hotplug
operations, because the current PCI MMIO alignment algorithm may
waste huge chunks of MMIO address space in those cases.
On the Alexander's Sony VAIO VPCZ23A4R the BIOS allocates limited
MMIO resources for the dock station which contains a device
(graphics adapter) with a 256MB MMIO BAR. An attempt to reassign
that during runtime hotplug causes the dock station MMIO window to be
exhausted and acpiphp fails to allocate resources for the majority
of devices on the dock station as a result.
To prevent that from happening, modify acpiphp to follow the boot
time resources allocation behavior so that the BIOS' resource
assignments are respected during runtime hotplug too.
[rjw: Changelog]
References: https://bugzilla.kernel.org/show_bug.cgi?id=56531
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-06-23 06:01:35 +07:00
|
|
|
__pci_bus_assign_resources(bus, &add_list, NULL);
|
2013-09-06 20:41:32 +07:00
|
|
|
|
2005-10-19 07:21:40 +07:00
|
|
|
acpiphp_sanitize_bus(bus);
|
2009-09-15 05:35:10 +07:00
|
|
|
acpiphp_set_hpp_values(bus);
|
2010-02-25 09:59:34 +07:00
|
|
|
acpiphp_set_acpi_region(slot);
|
2011-05-11 23:00:32 +07:00
|
|
|
|
|
|
|
list_for_each_entry(dev, &bus->devices, bus_list) {
|
|
|
|
/* Assume that newly added devices are powered on already. */
|
|
|
|
if (!dev->is_added)
|
|
|
|
dev->current_state = PCI_D0;
|
|
|
|
}
|
|
|
|
|
2005-04-28 14:25:53 +07:00
|
|
|
pci_bus_add_devices(bus);
|
|
|
|
|
PCI: Can continually add funcs after adding func0
Boot up a KVM guest, and hotplug multifunction
devices(func1,func2,func0,func3) to guest.
for i in 1 2 0 3;do
qemu-img create /tmp/resize$i.qcow2 1G -f qcow2
(qemu) drive_add 0x11.$i id=drv11$i,if=none,file=/tmp/resize$i.qcow2
(qemu) device_add virtio-blk-pci,id=dev11$i,drive=drv11$i,addr=0x11.$i,multifunction=on
done
In linux kernel, when func0 of the slot is hot-added, the whole
slot will be marked as 'enabled', then driver will ignore other new
hotadded funcs.
But in Win7 & WinXP, we can continaully add other funcs after adding
func0, all funcs will be added in guest.
drivers/pci/hotplug/acpiphp_glue.c:
static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
{
....
for (slot = bridge->slots; slot; slot = slot->next) {
if (slot->flags & SLOT_ENABLED) {
acpiphp_disable_slot()
else
acpiphp_enable_slot()
.... |
} v
enable_device()
|
v
//only don't enable slot if func0 is not added
list_for_each_entry(func, &slot->funcs, sibling) {
...
}
slot->flags |= SLOT_ENABLED; //mark slot to 'enabled'
This patch just make pci driver can continaully add funcs after adding
func 0. Only mark slot to 'enabled' when all funcs are added.
For pci multifunction hotplug, we can add functions one by one(func 0 is
necessary), and all functions will be removed in one time.
Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2011-11-25 14:03:07 +07:00
|
|
|
slot->flags |= SLOT_ENABLED;
|
2009-10-27 10:25:27 +07:00
|
|
|
list_for_each_entry(func, &slot->funcs, sibling) {
|
2009-05-22 05:21:15 +07:00
|
|
|
dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
|
|
|
|
func->function));
|
PCI: Can continually add funcs after adding func0
Boot up a KVM guest, and hotplug multifunction
devices(func1,func2,func0,func3) to guest.
for i in 1 2 0 3;do
qemu-img create /tmp/resize$i.qcow2 1G -f qcow2
(qemu) drive_add 0x11.$i id=drv11$i,if=none,file=/tmp/resize$i.qcow2
(qemu) device_add virtio-blk-pci,id=dev11$i,drive=drv11$i,addr=0x11.$i,multifunction=on
done
In linux kernel, when func0 of the slot is hot-added, the whole
slot will be marked as 'enabled', then driver will ignore other new
hotadded funcs.
But in Win7 & WinXP, we can continaully add other funcs after adding
func0, all funcs will be added in guest.
drivers/pci/hotplug/acpiphp_glue.c:
static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
{
....
for (slot = bridge->slots; slot; slot = slot->next) {
if (slot->flags & SLOT_ENABLED) {
acpiphp_disable_slot()
else
acpiphp_enable_slot()
.... |
} v
enable_device()
|
v
//only don't enable slot if func0 is not added
list_for_each_entry(func, &slot->funcs, sibling) {
...
}
slot->flags |= SLOT_ENABLED; //mark slot to 'enabled'
This patch just make pci driver can continaully add funcs after adding
func 0. Only mark slot to 'enabled' when all funcs are added.
For pci multifunction hotplug, we can add functions one by one(func 0 is
necessary), and all functions will be removed in one time.
Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2011-11-25 14:03:07 +07:00
|
|
|
if (!dev) {
|
|
|
|
/* Do not set SLOT_ENABLED flag if some funcs
|
|
|
|
are not added. */
|
|
|
|
slot->flags &= (~SLOT_ENABLED);
|
2006-03-22 12:49:20 +07:00
|
|
|
continue;
|
PCI: Can continually add funcs after adding func0
Boot up a KVM guest, and hotplug multifunction
devices(func1,func2,func0,func3) to guest.
for i in 1 2 0 3;do
qemu-img create /tmp/resize$i.qcow2 1G -f qcow2
(qemu) drive_add 0x11.$i id=drv11$i,if=none,file=/tmp/resize$i.qcow2
(qemu) device_add virtio-blk-pci,id=dev11$i,drive=drv11$i,addr=0x11.$i,multifunction=on
done
In linux kernel, when func0 of the slot is hot-added, the whole
slot will be marked as 'enabled', then driver will ignore other new
hotadded funcs.
But in Win7 & WinXP, we can continaully add other funcs after adding
func0, all funcs will be added in guest.
drivers/pci/hotplug/acpiphp_glue.c:
static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
{
....
for (slot = bridge->slots; slot; slot = slot->next) {
if (slot->flags & SLOT_ENABLED) {
acpiphp_disable_slot()
else
acpiphp_enable_slot()
.... |
} v
enable_device()
|
v
//only don't enable slot if func0 is not added
list_for_each_entry(func, &slot->funcs, sibling) {
...
}
slot->flags |= SLOT_ENABLED; //mark slot to 'enabled'
This patch just make pci driver can continaully add funcs after adding
func 0. Only mark slot to 'enabled' when all funcs are added.
For pci multifunction hotplug, we can add functions one by one(func 0 is
necessary), and all functions will be removed in one time.
Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2011-11-25 14:03:07 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-23 23:20:35 +07:00
|
|
|
/* return first device in slot, acquiring a reference on it */
|
|
|
|
static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot)
|
|
|
|
{
|
2013-07-14 04:27:25 +07:00
|
|
|
struct pci_bus *bus = slot->bus;
|
2012-05-23 23:20:35 +07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
2013-07-14 04:27:26 +07:00
|
|
|
* disable_slot - disable a slot
|
2007-11-29 00:04:30 +07:00
|
|
|
* @slot: ACPI PHP slot
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2013-07-14 04:27:26 +07:00
|
|
|
static void disable_slot(struct acpiphp_slot *slot)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct acpiphp_func *func;
|
2009-05-22 05:21:15 +07:00
|
|
|
struct pci_dev *pdev;
|
2006-03-22 12:49:20 +07:00
|
|
|
|
2012-05-23 23:20:35 +07:00
|
|
|
/*
|
2013-07-14 04:27:26 +07:00
|
|
|
* enable_slot() enumerates all functions in this device via
|
2012-05-23 23:20:35 +07:00
|
|
|
* pci_scan_slot(), whether they have associated ACPI hotplug
|
|
|
|
* methods (_EJ0, etc.) or not. Therefore, we remove all functions
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
while ((pdev = dev_in_slot(slot))) {
|
2012-08-17 23:03:47 +07:00
|
|
|
pci_stop_and_remove_bus_device(pdev);
|
2012-05-23 23:20:35 +07:00
|
|
|
pci_dev_put(pdev);
|
2006-09-13 00:22:53 +07:00
|
|
|
}
|
|
|
|
|
2013-07-14 04:27:25 +07:00
|
|
|
list_for_each_entry(func, &slot->funcs, sibling)
|
|
|
|
acpiphp_bus_trim(func_to_handle(func));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
slot->flags &= (~SLOT_ENABLED);
|
|
|
|
}
|
|
|
|
|
ACPIPHP / radeon / nouveau: Fix VGA switcheroo problem related to hotplug
The changes in the ACPI-based PCI hotplug (ACPIPHP) subsystem made
during the 3.12 development cycle uncovered a problem with VGA
switcheroo that on some systems, when the device-specific method
(ATPX in the radeon case, _DSM in the nouveau case) is used to turn
off the discrete graphics, the BIOS generates ACPI hotplug events for
that device and those events cause ACPIPHP to attempt to remove the
device from the system (they are events for a device that was present
previously and is not present any more, so that's what should be done
according to the spec). Then, the system stops functioning correctly.
Since the hotplug events in question were simply silently ignored
previously, the least intrusive way to address that problem is to
make ACPIPHP ignore them again. For this purpose, introduce a new
ACPI device flag, no_hotplug, and modify ACPIPHP to ignore hotplug
events for PCI devices whose ACPI companions have that flag set.
Next, make the radeon and nouveau switcheroo detection code set the
no_hotplug flag for the discrete graphics' ACPI companion.
Fixes: bbd34fcdd1b2 (ACPI / hotplug / PCI: Register all devices under the given bridge)
References: https://bugzilla.kernel.org/show_bug.cgi?id=61891
References: https://bugzilla.kernel.org/show_bug.cgi?id=64891
Reported-and-tested-by: Mike Lothian <mike@fireburn.co.uk>
Reported-and-tested-by: <madcatx@atlas.cz>
Reported-and-tested-by: Joaquín Aramendía <samsagax@gmail.com>
Cc: Alex Deucher <alexdeucher@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Cc: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: 3.12+ <stable@vger.kernel.org> # 3.12+
2013-12-31 19:39:42 +07:00
|
|
|
static bool acpiphp_no_hotplug(acpi_handle handle)
|
|
|
|
{
|
|
|
|
struct acpi_device *adev = NULL;
|
|
|
|
|
|
|
|
acpi_bus_get_device(handle, &adev);
|
|
|
|
return adev && adev->flags.no_hotplug;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get_slot_status - get ACPI slot status
|
2007-11-29 00:04:30 +07:00
|
|
|
* @slot: ACPI PHP slot
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2007-11-29 00:04:30 +07:00
|
|
|
* If a slot has _STA for each function and if any one of them
|
|
|
|
* returned non-zero status, return it.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2007-11-29 00:04:30 +07:00
|
|
|
* If a slot doesn't have _STA and if any one of its functions'
|
|
|
|
* configuration space is configured, return 0x0f as a _STA.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2007-11-29 00:04:30 +07:00
|
|
|
* Otherwise return 0.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
static unsigned int get_slot_status(struct acpiphp_slot *slot)
|
|
|
|
{
|
2008-10-10 13:22:59 +07:00
|
|
|
unsigned long long sta = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct acpiphp_func *func;
|
|
|
|
|
2009-10-27 10:25:27 +07:00
|
|
|
list_for_each_entry(func, &slot->funcs, sibling) {
|
2005-04-17 05:20:36 +07:00
|
|
|
if (func->flags & FUNC_HAS_STA) {
|
2013-07-14 04:27:25 +07:00
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
status = acpi_evaluate_integer(func_to_handle(func),
|
|
|
|
"_STA", NULL, &sta);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (ACPI_SUCCESS(status) && sta)
|
|
|
|
break;
|
|
|
|
} else {
|
2013-07-14 04:27:25 +07:00
|
|
|
u32 dvid;
|
|
|
|
|
2013-07-14 04:27:25 +07:00
|
|
|
pci_bus_read_config_dword(slot->bus,
|
2005-04-17 05:20:36 +07:00
|
|
|
PCI_DEVFN(slot->device,
|
|
|
|
func->function),
|
|
|
|
PCI_VENDOR_ID, &dvid);
|
|
|
|
if (dvid != 0xffffffff) {
|
|
|
|
sta = ACPI_STA_ALL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (unsigned int)sta;
|
|
|
|
}
|
|
|
|
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
/**
|
|
|
|
* trim_stale_devices - remove PCI devices that are not responding.
|
|
|
|
* @dev: PCI device to start walking the hierarchy from.
|
|
|
|
*/
|
|
|
|
static void trim_stale_devices(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
acpi_handle handle = ACPI_HANDLE(&dev->dev);
|
|
|
|
struct pci_bus *bus = dev->subordinate;
|
|
|
|
bool alive = false;
|
|
|
|
|
|
|
|
if (handle) {
|
|
|
|
acpi_status status;
|
|
|
|
unsigned long long sta;
|
|
|
|
|
|
|
|
status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
|
ACPIPHP / radeon / nouveau: Fix VGA switcheroo problem related to hotplug
The changes in the ACPI-based PCI hotplug (ACPIPHP) subsystem made
during the 3.12 development cycle uncovered a problem with VGA
switcheroo that on some systems, when the device-specific method
(ATPX in the radeon case, _DSM in the nouveau case) is used to turn
off the discrete graphics, the BIOS generates ACPI hotplug events for
that device and those events cause ACPIPHP to attempt to remove the
device from the system (they are events for a device that was present
previously and is not present any more, so that's what should be done
according to the spec). Then, the system stops functioning correctly.
Since the hotplug events in question were simply silently ignored
previously, the least intrusive way to address that problem is to
make ACPIPHP ignore them again. For this purpose, introduce a new
ACPI device flag, no_hotplug, and modify ACPIPHP to ignore hotplug
events for PCI devices whose ACPI companions have that flag set.
Next, make the radeon and nouveau switcheroo detection code set the
no_hotplug flag for the discrete graphics' ACPI companion.
Fixes: bbd34fcdd1b2 (ACPI / hotplug / PCI: Register all devices under the given bridge)
References: https://bugzilla.kernel.org/show_bug.cgi?id=61891
References: https://bugzilla.kernel.org/show_bug.cgi?id=64891
Reported-and-tested-by: Mike Lothian <mike@fireburn.co.uk>
Reported-and-tested-by: <madcatx@atlas.cz>
Reported-and-tested-by: Joaquín Aramendía <samsagax@gmail.com>
Cc: Alex Deucher <alexdeucher@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Cc: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: 3.12+ <stable@vger.kernel.org> # 3.12+
2013-12-31 19:39:42 +07:00
|
|
|
alive = (ACPI_SUCCESS(status) && sta == ACPI_STA_ALL)
|
|
|
|
|| acpiphp_no_hotplug(handle);
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
}
|
|
|
|
if (!alive) {
|
|
|
|
u32 v;
|
|
|
|
|
|
|
|
/* 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 (handle)
|
|
|
|
acpiphp_bus_trim(handle);
|
|
|
|
} else if (bus) {
|
|
|
|
struct pci_dev *child, *tmp;
|
|
|
|
|
|
|
|
/* The device is a bridge. so check the bus below it. */
|
|
|
|
pm_runtime_get_sync(&dev->dev);
|
2014-02-03 08:22:07 +07:00
|
|
|
list_for_each_entry_safe_reverse(child, tmp, &bus->devices, bus_list)
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
trim_stale_devices(child);
|
|
|
|
|
|
|
|
pm_runtime_put(&dev->dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
|
|
|
* acpiphp_check_bridge - re-enumerate devices
|
2007-11-29 00:04:30 +07:00
|
|
|
* @bridge: where to begin re-enumeration
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Iterate over all slots under this bridge and make sure that if a
|
|
|
|
* card is present they are enabled, and if not they are disabled.
|
|
|
|
*/
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
static void acpiphp_check_bridge(struct acpiphp_bridge *bridge)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct acpiphp_slot *slot;
|
|
|
|
|
2014-01-10 21:24:41 +07:00
|
|
|
/* Bail out if the bridge is going away. */
|
|
|
|
if (bridge->is_going_away)
|
|
|
|
return;
|
|
|
|
|
2013-04-12 12:44:27 +07:00
|
|
|
list_for_each_entry(slot, &bridge->slots, node) {
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
struct pci_bus *bus = slot->bus;
|
|
|
|
struct pci_dev *dev, *tmp;
|
|
|
|
|
|
|
|
mutex_lock(&slot->crit_sect);
|
ACPIPHP / radeon / nouveau: Fix VGA switcheroo problem related to hotplug
The changes in the ACPI-based PCI hotplug (ACPIPHP) subsystem made
during the 3.12 development cycle uncovered a problem with VGA
switcheroo that on some systems, when the device-specific method
(ATPX in the radeon case, _DSM in the nouveau case) is used to turn
off the discrete graphics, the BIOS generates ACPI hotplug events for
that device and those events cause ACPIPHP to attempt to remove the
device from the system (they are events for a device that was present
previously and is not present any more, so that's what should be done
according to the spec). Then, the system stops functioning correctly.
Since the hotplug events in question were simply silently ignored
previously, the least intrusive way to address that problem is to
make ACPIPHP ignore them again. For this purpose, introduce a new
ACPI device flag, no_hotplug, and modify ACPIPHP to ignore hotplug
events for PCI devices whose ACPI companions have that flag set.
Next, make the radeon and nouveau switcheroo detection code set the
no_hotplug flag for the discrete graphics' ACPI companion.
Fixes: bbd34fcdd1b2 (ACPI / hotplug / PCI: Register all devices under the given bridge)
References: https://bugzilla.kernel.org/show_bug.cgi?id=61891
References: https://bugzilla.kernel.org/show_bug.cgi?id=64891
Reported-and-tested-by: Mike Lothian <mike@fireburn.co.uk>
Reported-and-tested-by: <madcatx@atlas.cz>
Reported-and-tested-by: Joaquín Aramendía <samsagax@gmail.com>
Cc: Alex Deucher <alexdeucher@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Cc: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: 3.12+ <stable@vger.kernel.org> # 3.12+
2013-12-31 19:39:42 +07:00
|
|
|
if (slot_no_hotplug(slot)) {
|
|
|
|
; /* do nothing */
|
|
|
|
} else if (get_slot_status(slot) == ACPI_STA_ALL) {
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
/* remove stale devices if any */
|
2014-02-03 08:22:07 +07:00
|
|
|
list_for_each_entry_safe_reverse(dev, tmp,
|
|
|
|
&bus->devices, bus_list)
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
if (PCI_SLOT(dev->devfn) == slot->device)
|
|
|
|
trim_stale_devices(dev);
|
|
|
|
|
|
|
|
/* configure all functions */
|
2013-07-14 04:27:26 +07:00
|
|
|
enable_slot(slot);
|
2005-04-17 05:20:36 +07:00
|
|
|
} else {
|
2013-07-14 04:27:26 +07:00
|
|
|
disable_slot(slot);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
mutex_unlock(&slot->crit_sect);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-15 05:35:10 +07:00
|
|
|
static void acpiphp_set_hpp_values(struct pci_bus *bus)
|
2005-04-28 14:25:56 +07:00
|
|
|
{
|
|
|
|
struct pci_dev *dev;
|
|
|
|
|
2009-09-15 05:35:35 +07:00
|
|
|
list_for_each_entry(dev, &bus->devices, bus_list)
|
|
|
|
pci_configure_slot(dev);
|
2005-04-28 14:25:56 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove devices for which we could not assign resources, call
|
|
|
|
* arch specific code to fix-up the bus
|
|
|
|
*/
|
|
|
|
static void acpiphp_sanitize_bus(struct pci_bus *bus)
|
|
|
|
{
|
2013-04-12 12:44:17 +07:00
|
|
|
struct pci_dev *dev, *tmp;
|
2005-04-28 14:25:56 +07:00
|
|
|
int i;
|
|
|
|
unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
|
|
|
|
|
2014-02-03 08:22:07 +07:00
|
|
|
list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list) {
|
2005-04-28 14:25:56 +07:00
|
|
|
for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
|
|
|
|
struct resource *res = &dev->resource[i];
|
|
|
|
if ((res->flags & type_mask) && !res->start &&
|
|
|
|
res->end) {
|
|
|
|
/* Could not assign a required resources
|
|
|
|
* for this device, remove it */
|
2012-02-26 04:54:20 +07:00
|
|
|
pci_stop_and_remove_bus_device(dev);
|
2005-04-28 14:25:56 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* ACPI event handlers
|
|
|
|
*/
|
|
|
|
|
2013-05-08 00:06:03 +07:00
|
|
|
void acpiphp_check_host_bridge(acpi_handle handle)
|
|
|
|
{
|
|
|
|
struct acpiphp_bridge *bridge;
|
|
|
|
|
|
|
|
bridge = acpiphp_handle_to_bridge(handle);
|
|
|
|
if (bridge) {
|
2014-02-03 08:22:27 +07:00
|
|
|
pci_lock_rescan_remove();
|
|
|
|
|
2013-05-08 00:06:03 +07:00
|
|
|
acpiphp_check_bridge(bridge);
|
2014-02-03 08:22:27 +07:00
|
|
|
|
|
|
|
pci_unlock_rescan_remove();
|
2013-05-08 00:06:03 +07:00
|
|
|
put_bridge(bridge);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 21:24:41 +07:00
|
|
|
static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot);
|
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
static void hotplug_event(acpi_handle handle, u32 type, void *data)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-07-14 04:27:24 +07:00
|
|
|
struct acpiphp_context *context = data;
|
2013-07-14 04:27:25 +07:00
|
|
|
struct acpiphp_func *func = &context->func;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct acpiphp_bridge *bridge;
|
|
|
|
char objname[64];
|
|
|
|
struct acpi_buffer buffer = { .length = sizeof(objname),
|
|
|
|
.pointer = objname };
|
2011-09-29 06:40:53 +07:00
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
mutex_lock(&acpiphp_context_lock);
|
2013-07-14 04:27:24 +07:00
|
|
|
bridge = context->bridge;
|
2013-07-14 04:27:24 +07:00
|
|
|
if (bridge)
|
|
|
|
get_bridge(bridge);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
ACPI / hotplug: Fix concurrency issues and memory leaks
This changeset is aimed at fixing a few different but related
problems in the ACPI hotplug infrastructure.
First of all, since notify handlers may be run in parallel with
acpi_bus_scan(), acpi_bus_trim() and acpi_bus_hot_remove_device()
and some of them are installed for ACPI handles that have no struct
acpi_device objects attached (i.e. before those objects are created),
those notify handlers have to take acpi_scan_lock to prevent races
from taking place (e.g. a struct acpi_device is found to be present
for the given ACPI handle, but right after that it is removed by
acpi_bus_trim() running in parallel to the given notify handler).
Moreover, since some of them call acpi_bus_scan() and
acpi_bus_trim(), this leads to the conclusion that acpi_scan_lock
should be acquired by the callers of these two funtions rather by
these functions themselves.
For these reasons, make all notify handlers that can handle device
addition and eject events take acpi_scan_lock and remove the
acpi_scan_lock locking from acpi_bus_scan() and acpi_bus_trim().
Accordingly, update all of their users to make sure that they
are always called under acpi_scan_lock.
Furthermore, since eject operations are carried out asynchronously
with respect to the notify events that trigger them, with the help
of acpi_bus_hot_remove_device(), even if notify handlers take the
ACPI scan lock, it still is possible that, for example,
acpi_bus_trim() will run between acpi_bus_hot_remove_device() and
the notify handler that scheduled its execution and that
acpi_bus_trim() will remove the device node passed to
acpi_bus_hot_remove_device() for ejection. In that case, the struct
acpi_device object obtained by acpi_bus_hot_remove_device() will be
invalid and not-so-funny things will ensue. To protect agaist that,
make the users of acpi_bus_hot_remove_device() run get_device() on
ACPI device node objects that are about to be passed to it and make
acpi_bus_hot_remove_device() run put_device() on them and check if
their ACPI handles are not NULL (make acpi_device_unregister() clear
the device nodes' ACPI handles for that check to work).
Finally, observe that acpi_os_hotplug_execute() actually can fail,
in which case its caller ought to free memory allocated for the
context object to prevent leaks from happening. It also needs to
run put_device() on the device node that it ran get_device() on
previously in that case. Modify the code accordingly.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
2013-02-13 20:36:47 +07:00
|
|
|
|
2014-02-03 08:22:17 +07:00
|
|
|
pci_lock_rescan_remove();
|
2005-04-17 05:20:36 +07:00
|
|
|
acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ACPI_NOTIFY_BUS_CHECK:
|
|
|
|
/* bus re-enumerate */
|
2013-09-25 07:11:48 +07:00
|
|
|
pr_debug("%s: Bus check notify on %s\n", __func__, objname);
|
|
|
|
pr_debug("%s: re-enumerating slots under %s\n",
|
|
|
|
__func__, objname);
|
2013-07-14 04:27:24 +07:00
|
|
|
if (bridge) {
|
|
|
|
acpiphp_check_bridge(bridge);
|
|
|
|
} else {
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
struct acpiphp_slot *slot = func->slot;
|
|
|
|
|
2014-01-10 21:24:41 +07:00
|
|
|
if (slot->flags & SLOT_IS_GOING_AWAY)
|
|
|
|
break;
|
|
|
|
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
mutex_lock(&slot->crit_sect);
|
2013-07-14 04:27:26 +07:00
|
|
|
enable_slot(slot);
|
ACPI / hotplug / PCI: Check for new devices on enabled slots
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is
ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not
ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy
chaining case properly, however, because in that case the bus
behind the already enabled slot needs to be rescanned for new
devices.
For this reason, modify acpiphp_check_bridge() so that slots are
disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't
respond are trimmed using a new function, trim_stale_devices(),
introduced specifically for this purpose. That function walks
the given bus and checks each device on it. If the device doesn't
respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been
removed, acpiphp_check_bridge() will start looking for new devices
that might have appeared on the given bus. It will do that even if
the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore
SLOT_ENABLED and go for enable_device() directly if bridge is NULL,
so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov
and Mika Westerberg.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-07-17 03:10:35 +07:00
|
|
|
mutex_unlock(&slot->crit_sect);
|
2013-07-14 04:27:24 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_NOTIFY_DEVICE_CHECK:
|
|
|
|
/* device check */
|
2013-09-25 07:11:48 +07:00
|
|
|
pr_debug("%s: Device check notify on %s\n", __func__, objname);
|
ACPI / hotplug / PCI: Avoid parent bus rescans on spurious device checks
In the current ACPIPHP notify handler we always go directly for a
rescan of the parent bus if we get a device check notification for
a device that is not a bridge. However, this obviously is
overzealous if nothing really changes, because this way we may rescan
the whole PCI hierarchy pretty much in vain.
That happens on Alex Williamson's machine whose ACPI tables contain
device objects that are supposed to coresspond to PCIe root ports,
but those ports aren't physically present (or at least they aren't
visible in the PCI config space to us). The BIOS generates multiple
device check notifies for those objects during boot and for each of
them we go straight for the parent bus rescan, but the parent bus is
the root bus in this particular case. In consequence, we rescan the
whole PCI bus from the top several times in a row, which is
completely unnecessary, increases boot time by 50% (after previous
fixes) and generates excess dmesg output from the PCI subsystem.
Fix the problem by checking if we can find anything new in the
slot corresponding to the device we've got a device check notify
for and doing nothig if that's not the case.
The spec (ACPI 5.0, Section 5.6.6) appears to mandate this behavior,
as it says:
Device Check. Used to notify OSPM that the device either appeared
or disappeared. If the device has appeared, OSPM will re-enumerate
from the parent. If the device has disappeared, OSPM will
invalidate the state of the device. OSPM may optimize out
re-enumeration.
Therefore, according to the spec, we are free to do nothing if
nothing changes.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60865
Reported-and-tested-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-09-08 05:07:28 +07:00
|
|
|
if (bridge) {
|
2013-07-14 04:27:24 +07:00
|
|
|
acpiphp_check_bridge(bridge);
|
ACPI / hotplug / PCI: Avoid parent bus rescans on spurious device checks
In the current ACPIPHP notify handler we always go directly for a
rescan of the parent bus if we get a device check notification for
a device that is not a bridge. However, this obviously is
overzealous if nothing really changes, because this way we may rescan
the whole PCI hierarchy pretty much in vain.
That happens on Alex Williamson's machine whose ACPI tables contain
device objects that are supposed to coresspond to PCIe root ports,
but those ports aren't physically present (or at least they aren't
visible in the PCI config space to us). The BIOS generates multiple
device check notifies for those objects during boot and for each of
them we go straight for the parent bus rescan, but the parent bus is
the root bus in this particular case. In consequence, we rescan the
whole PCI bus from the top several times in a row, which is
completely unnecessary, increases boot time by 50% (after previous
fixes) and generates excess dmesg output from the PCI subsystem.
Fix the problem by checking if we can find anything new in the
slot corresponding to the device we've got a device check notify
for and doing nothig if that's not the case.
The spec (ACPI 5.0, Section 5.6.6) appears to mandate this behavior,
as it says:
Device Check. Used to notify OSPM that the device either appeared
or disappeared. If the device has appeared, OSPM will re-enumerate
from the parent. If the device has disappeared, OSPM will
invalidate the state of the device. OSPM may optimize out
re-enumeration.
Therefore, according to the spec, we are free to do nothing if
nothing changes.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60865
Reported-and-tested-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-09-08 05:07:28 +07:00
|
|
|
} else {
|
|
|
|
struct acpiphp_slot *slot = func->slot;
|
|
|
|
int ret;
|
2013-07-14 04:27:24 +07:00
|
|
|
|
2014-01-10 21:24:41 +07:00
|
|
|
if (slot->flags & SLOT_IS_GOING_AWAY)
|
|
|
|
break;
|
|
|
|
|
ACPI / hotplug / PCI: Avoid parent bus rescans on spurious device checks
In the current ACPIPHP notify handler we always go directly for a
rescan of the parent bus if we get a device check notification for
a device that is not a bridge. However, this obviously is
overzealous if nothing really changes, because this way we may rescan
the whole PCI hierarchy pretty much in vain.
That happens on Alex Williamson's machine whose ACPI tables contain
device objects that are supposed to coresspond to PCIe root ports,
but those ports aren't physically present (or at least they aren't
visible in the PCI config space to us). The BIOS generates multiple
device check notifies for those objects during boot and for each of
them we go straight for the parent bus rescan, but the parent bus is
the root bus in this particular case. In consequence, we rescan the
whole PCI bus from the top several times in a row, which is
completely unnecessary, increases boot time by 50% (after previous
fixes) and generates excess dmesg output from the PCI subsystem.
Fix the problem by checking if we can find anything new in the
slot corresponding to the device we've got a device check notify
for and doing nothig if that's not the case.
The spec (ACPI 5.0, Section 5.6.6) appears to mandate this behavior,
as it says:
Device Check. Used to notify OSPM that the device either appeared
or disappeared. If the device has appeared, OSPM will re-enumerate
from the parent. If the device has disappeared, OSPM will
invalidate the state of the device. OSPM may optimize out
re-enumeration.
Therefore, according to the spec, we are free to do nothing if
nothing changes.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60865
Reported-and-tested-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-09-08 05:07:28 +07:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
acpiphp_check_bridge(func->parent);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_NOTIFY_EJECT_REQUEST:
|
|
|
|
/* request device eject */
|
2013-09-25 07:11:48 +07:00
|
|
|
pr_debug("%s: Device eject notify on %s\n", __func__, objname);
|
2013-07-14 04:27:26 +07:00
|
|
|
acpiphp_disable_and_eject_slot(func->slot);
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
}
|
2011-09-29 06:40:53 +07:00
|
|
|
|
2014-02-03 08:22:17 +07:00
|
|
|
pci_unlock_rescan_remove();
|
2013-07-14 04:27:24 +07:00
|
|
|
if (bridge)
|
|
|
|
put_bridge(bridge);
|
ACPI / dock / PCI: Synchronous handling of dock events for PCI devices
The interactions between the ACPI dock driver and the ACPI-based PCI
hotplug (acpiphp) are currently problematic because of ordering
issues during hot-remove operations.
First of all, the current ACPI glue code expects that physical
devices will always be deleted before deleting the companion ACPI
device objects. Otherwise, acpi_unbind_one() will fail with a
warning message printed to the kernel log, for example:
[ 185.026073] usb usb5: Oops, 'acpi_handle' corrupt
[ 185.035150] pci 0000:1b:00.0: Oops, 'acpi_handle' corrupt
[ 185.035515] pci 0000:18:02.0: Oops, 'acpi_handle' corrupt
[ 180.013656] port1: Oops, 'acpi_handle' corrupt
This means, in particular, that struct pci_dev objects have to
be deleted before the struct acpi_device objects they are "glued"
with.
Now, the following happens the during the undocking of an ACPI-based
dock station:
1) hotplug_dock_devices() invokes registered hotplug callbacks to
destroy physical devices associated with the ACPI device objects
depending on the dock station. It calls dd->ops->handler() for
each of those device objects.
2) For PCI devices dd->ops->handler() points to
handle_hotplug_event_func() that queues up a separate work item
to execute _handle_hotplug_event_func() for the given device and
returns immediately. That work item will be executed later.
3) hotplug_dock_devices() calls dock_remove_acpi_device() for each
device depending on the dock station. This runs acpi_bus_trim()
for each of them, which causes the underlying ACPI device object
to be destroyed, but the work items queued up by
handle_hotplug_event_func() haven't been started yet.
4) _handle_hotplug_event_func() queued up in step 2) are executed
and cause the above failure to happen, because the PCI devices
they handle do not have the companion ACPI device objects any
more (those objects have been deleted in step 3).
The possible breakage doesn't end here, though, because
hotplug_dock_devices() may return before at least some of the
_handle_hotplug_event_func() work items spawned by it have a
chance to complete and then undock() will cause _DCK to be
evaluated and that will cause the devices handled by the
_handle_hotplug_event_func() to go away possibly while they are
being accessed.
This means that dd->ops->handler() for PCI devices should not point
to handle_hotplug_event_func(). Instead, it should point to a
function that will do the work of _handle_hotplug_event_func()
synchronously. For this reason, introduce such a function,
hotplug_event_func(), and modity acpiphp_dock_ops to point to
it as the handler.
Unfortunately, however, this is not sufficient, because if the dock
code were not changed further, hotplug_event_func() would now
deadlock with hotplug_dock_devices() that called it, since it would
run unregister_hotplug_dock_device() which in turn would attempt to
acquire the dock station's hp_lock mutex already acquired by
hotplug_dock_devices().
To resolve that deadlock use the observation that
unregister_hotplug_dock_device() won't need to acquire hp_lock
if PCI bridges the devices on the dock station depend on are
prevented from being removed prematurely while the first loop in
hotplug_dock_devices() is in progress.
To make that possible, introduce a mechanism by which the callers of
register_hotplug_dock_device() can provide "init" and "release"
routines that will be executed, respectively, during the addition
and removal of the physical device object associated with the
given ACPI device handle. Make acpiphp use two new functions,
acpiphp_dock_init() and acpiphp_dock_release(), that call
get_bridge() and put_bridge(), respectively, on the acpiphp bridge
holding the given device, for this purpose.
In addition to that, remove the dock station's list of
"hotplug devices" and make the dock code always walk the whole list
of "dependent devices" instead in such a way that the loops in
hotplug_dock_devices() and dock_event() (replacing the loops over
"hotplug devices") will take references to the list entries that
register_hotplug_dock_device() has been called for. That prevents
the "release" routines associated with those entries from being
called while the given entry is being processed and for PCI
devices this means that their bridges won't be removed (by a
concurrent thread) while hotplug_event_func() handling them is
being executed.
This change is based on two earlier patches from Jiang Liu.
References: https://bugzilla.kernel.org/show_bug.cgi?id=59501
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tracked-down-by: Jiang Liu <jiang.liu@huawei.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
2013-06-24 16:22:53 +07:00
|
|
|
}
|
|
|
|
|
ACPI / hotplug: Consolidate deferred execution of ACPI hotplug routines
There are two different interfaces for queuing up work items on the
ACPI hotplug workqueue, alloc_acpi_hp_work() used by PCI and PCI host
bridge hotplug code and acpi_os_hotplug_execute() used by the common
ACPI hotplug code and docking stations. They both are somewhat
cumbersome to use and work slightly differently.
The users of alloc_acpi_hp_work() have to submit a work function that
will extract the necessary data items from a struct acpi_hp_work
object allocated by alloc_acpi_hp_work() and then will free that
object, while it would be more straightforward to simply use a work
function with one more argument and let the interface take care of
the execution details.
The users of acpi_os_hotplug_execute() also have to deal with the
fact that it takes only one argument in addition to the work function
pointer, although acpi_os_execute_deferred() actually takes care of
the allocation and freeing of memory, so it would have been able to
pass more arguments to the work function if it hadn't been
constrained by the connection with acpi_os_execute().
Moreover, while alloc_acpi_hp_work() makes GFP_KERNEL memory
allocations, which is correct, because hotplug work items are
always queued up from process context, acpi_os_hotplug_execute()
uses GFP_ATOMIC, as that is needed by acpi_os_execute(). Also,
acpi_os_execute_deferred() queued up by it waits for the ACPI event
workqueues to flush before executing the work function, whereas
alloc_acpi_hp_work() can't do anything similar. That leads to
somewhat arbitrary differences in behavior between various ACPI
hotplug code paths and has to be straightened up.
For this reason, replace both alloc_acpi_hp_work() and
acpi_os_hotplug_execute() with a single interface,
acpi_hotplug_execute(), combining their behavior and being more
friendly to its users than any of the two.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-11-07 07:45:40 +07:00
|
|
|
static void hotplug_event_work(void *data, u32 type)
|
ACPI / dock / PCI: Synchronous handling of dock events for PCI devices
The interactions between the ACPI dock driver and the ACPI-based PCI
hotplug (acpiphp) are currently problematic because of ordering
issues during hot-remove operations.
First of all, the current ACPI glue code expects that physical
devices will always be deleted before deleting the companion ACPI
device objects. Otherwise, acpi_unbind_one() will fail with a
warning message printed to the kernel log, for example:
[ 185.026073] usb usb5: Oops, 'acpi_handle' corrupt
[ 185.035150] pci 0000:1b:00.0: Oops, 'acpi_handle' corrupt
[ 185.035515] pci 0000:18:02.0: Oops, 'acpi_handle' corrupt
[ 180.013656] port1: Oops, 'acpi_handle' corrupt
This means, in particular, that struct pci_dev objects have to
be deleted before the struct acpi_device objects they are "glued"
with.
Now, the following happens the during the undocking of an ACPI-based
dock station:
1) hotplug_dock_devices() invokes registered hotplug callbacks to
destroy physical devices associated with the ACPI device objects
depending on the dock station. It calls dd->ops->handler() for
each of those device objects.
2) For PCI devices dd->ops->handler() points to
handle_hotplug_event_func() that queues up a separate work item
to execute _handle_hotplug_event_func() for the given device and
returns immediately. That work item will be executed later.
3) hotplug_dock_devices() calls dock_remove_acpi_device() for each
device depending on the dock station. This runs acpi_bus_trim()
for each of them, which causes the underlying ACPI device object
to be destroyed, but the work items queued up by
handle_hotplug_event_func() haven't been started yet.
4) _handle_hotplug_event_func() queued up in step 2) are executed
and cause the above failure to happen, because the PCI devices
they handle do not have the companion ACPI device objects any
more (those objects have been deleted in step 3).
The possible breakage doesn't end here, though, because
hotplug_dock_devices() may return before at least some of the
_handle_hotplug_event_func() work items spawned by it have a
chance to complete and then undock() will cause _DCK to be
evaluated and that will cause the devices handled by the
_handle_hotplug_event_func() to go away possibly while they are
being accessed.
This means that dd->ops->handler() for PCI devices should not point
to handle_hotplug_event_func(). Instead, it should point to a
function that will do the work of _handle_hotplug_event_func()
synchronously. For this reason, introduce such a function,
hotplug_event_func(), and modity acpiphp_dock_ops to point to
it as the handler.
Unfortunately, however, this is not sufficient, because if the dock
code were not changed further, hotplug_event_func() would now
deadlock with hotplug_dock_devices() that called it, since it would
run unregister_hotplug_dock_device() which in turn would attempt to
acquire the dock station's hp_lock mutex already acquired by
hotplug_dock_devices().
To resolve that deadlock use the observation that
unregister_hotplug_dock_device() won't need to acquire hp_lock
if PCI bridges the devices on the dock station depend on are
prevented from being removed prematurely while the first loop in
hotplug_dock_devices() is in progress.
To make that possible, introduce a mechanism by which the callers of
register_hotplug_dock_device() can provide "init" and "release"
routines that will be executed, respectively, during the addition
and removal of the physical device object associated with the
given ACPI device handle. Make acpiphp use two new functions,
acpiphp_dock_init() and acpiphp_dock_release(), that call
get_bridge() and put_bridge(), respectively, on the acpiphp bridge
holding the given device, for this purpose.
In addition to that, remove the dock station's list of
"hotplug devices" and make the dock code always walk the whole list
of "dependent devices" instead in such a way that the loops in
hotplug_dock_devices() and dock_event() (replacing the loops over
"hotplug devices") will take references to the list entries that
register_hotplug_dock_device() has been called for. That prevents
the "release" routines associated with those entries from being
called while the given entry is being processed and for PCI
devices this means that their bridges won't be removed (by a
concurrent thread) while hotplug_event_func() handling them is
being executed.
This change is based on two earlier patches from Jiang Liu.
References: https://bugzilla.kernel.org/show_bug.cgi?id=59501
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tracked-down-by: Jiang Liu <jiang.liu@huawei.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
2013-06-24 16:22:53 +07:00
|
|
|
{
|
ACPI / hotplug: Consolidate deferred execution of ACPI hotplug routines
There are two different interfaces for queuing up work items on the
ACPI hotplug workqueue, alloc_acpi_hp_work() used by PCI and PCI host
bridge hotplug code and acpi_os_hotplug_execute() used by the common
ACPI hotplug code and docking stations. They both are somewhat
cumbersome to use and work slightly differently.
The users of alloc_acpi_hp_work() have to submit a work function that
will extract the necessary data items from a struct acpi_hp_work
object allocated by alloc_acpi_hp_work() and then will free that
object, while it would be more straightforward to simply use a work
function with one more argument and let the interface take care of
the execution details.
The users of acpi_os_hotplug_execute() also have to deal with the
fact that it takes only one argument in addition to the work function
pointer, although acpi_os_execute_deferred() actually takes care of
the allocation and freeing of memory, so it would have been able to
pass more arguments to the work function if it hadn't been
constrained by the connection with acpi_os_execute().
Moreover, while alloc_acpi_hp_work() makes GFP_KERNEL memory
allocations, which is correct, because hotplug work items are
always queued up from process context, acpi_os_hotplug_execute()
uses GFP_ATOMIC, as that is needed by acpi_os_execute(). Also,
acpi_os_execute_deferred() queued up by it waits for the ACPI event
workqueues to flush before executing the work function, whereas
alloc_acpi_hp_work() can't do anything similar. That leads to
somewhat arbitrary differences in behavior between various ACPI
hotplug code paths and has to be straightened up.
For this reason, replace both alloc_acpi_hp_work() and
acpi_os_hotplug_execute() with a single interface,
acpi_hotplug_execute(), combining their behavior and being more
friendly to its users than any of the two.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-11-07 07:45:40 +07:00
|
|
|
struct acpiphp_context *context = data;
|
|
|
|
acpi_handle handle = context->handle;
|
ACPI / dock / PCI: Synchronous handling of dock events for PCI devices
The interactions between the ACPI dock driver and the ACPI-based PCI
hotplug (acpiphp) are currently problematic because of ordering
issues during hot-remove operations.
First of all, the current ACPI glue code expects that physical
devices will always be deleted before deleting the companion ACPI
device objects. Otherwise, acpi_unbind_one() will fail with a
warning message printed to the kernel log, for example:
[ 185.026073] usb usb5: Oops, 'acpi_handle' corrupt
[ 185.035150] pci 0000:1b:00.0: Oops, 'acpi_handle' corrupt
[ 185.035515] pci 0000:18:02.0: Oops, 'acpi_handle' corrupt
[ 180.013656] port1: Oops, 'acpi_handle' corrupt
This means, in particular, that struct pci_dev objects have to
be deleted before the struct acpi_device objects they are "glued"
with.
Now, the following happens the during the undocking of an ACPI-based
dock station:
1) hotplug_dock_devices() invokes registered hotplug callbacks to
destroy physical devices associated with the ACPI device objects
depending on the dock station. It calls dd->ops->handler() for
each of those device objects.
2) For PCI devices dd->ops->handler() points to
handle_hotplug_event_func() that queues up a separate work item
to execute _handle_hotplug_event_func() for the given device and
returns immediately. That work item will be executed later.
3) hotplug_dock_devices() calls dock_remove_acpi_device() for each
device depending on the dock station. This runs acpi_bus_trim()
for each of them, which causes the underlying ACPI device object
to be destroyed, but the work items queued up by
handle_hotplug_event_func() haven't been started yet.
4) _handle_hotplug_event_func() queued up in step 2) are executed
and cause the above failure to happen, because the PCI devices
they handle do not have the companion ACPI device objects any
more (those objects have been deleted in step 3).
The possible breakage doesn't end here, though, because
hotplug_dock_devices() may return before at least some of the
_handle_hotplug_event_func() work items spawned by it have a
chance to complete and then undock() will cause _DCK to be
evaluated and that will cause the devices handled by the
_handle_hotplug_event_func() to go away possibly while they are
being accessed.
This means that dd->ops->handler() for PCI devices should not point
to handle_hotplug_event_func(). Instead, it should point to a
function that will do the work of _handle_hotplug_event_func()
synchronously. For this reason, introduce such a function,
hotplug_event_func(), and modity acpiphp_dock_ops to point to
it as the handler.
Unfortunately, however, this is not sufficient, because if the dock
code were not changed further, hotplug_event_func() would now
deadlock with hotplug_dock_devices() that called it, since it would
run unregister_hotplug_dock_device() which in turn would attempt to
acquire the dock station's hp_lock mutex already acquired by
hotplug_dock_devices().
To resolve that deadlock use the observation that
unregister_hotplug_dock_device() won't need to acquire hp_lock
if PCI bridges the devices on the dock station depend on are
prevented from being removed prematurely while the first loop in
hotplug_dock_devices() is in progress.
To make that possible, introduce a mechanism by which the callers of
register_hotplug_dock_device() can provide "init" and "release"
routines that will be executed, respectively, during the addition
and removal of the physical device object associated with the
given ACPI device handle. Make acpiphp use two new functions,
acpiphp_dock_init() and acpiphp_dock_release(), that call
get_bridge() and put_bridge(), respectively, on the acpiphp bridge
holding the given device, for this purpose.
In addition to that, remove the dock station's list of
"hotplug devices" and make the dock code always walk the whole list
of "dependent devices" instead in such a way that the loops in
hotplug_dock_devices() and dock_event() (replacing the loops over
"hotplug devices") will take references to the list entries that
register_hotplug_dock_device() has been called for. That prevents
the "release" routines associated with those entries from being
called while the given entry is being processed and for PCI
devices this means that their bridges won't be removed (by a
concurrent thread) while hotplug_event_func() handling them is
being executed.
This change is based on two earlier patches from Jiang Liu.
References: https://bugzilla.kernel.org/show_bug.cgi?id=59501
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tracked-down-by: Jiang Liu <jiang.liu@huawei.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
2013-06-24 16:22:53 +07:00
|
|
|
|
|
|
|
acpi_scan_lock_acquire();
|
|
|
|
|
ACPI / hotplug: Consolidate deferred execution of ACPI hotplug routines
There are two different interfaces for queuing up work items on the
ACPI hotplug workqueue, alloc_acpi_hp_work() used by PCI and PCI host
bridge hotplug code and acpi_os_hotplug_execute() used by the common
ACPI hotplug code and docking stations. They both are somewhat
cumbersome to use and work slightly differently.
The users of alloc_acpi_hp_work() have to submit a work function that
will extract the necessary data items from a struct acpi_hp_work
object allocated by alloc_acpi_hp_work() and then will free that
object, while it would be more straightforward to simply use a work
function with one more argument and let the interface take care of
the execution details.
The users of acpi_os_hotplug_execute() also have to deal with the
fact that it takes only one argument in addition to the work function
pointer, although acpi_os_execute_deferred() actually takes care of
the allocation and freeing of memory, so it would have been able to
pass more arguments to the work function if it hadn't been
constrained by the connection with acpi_os_execute().
Moreover, while alloc_acpi_hp_work() makes GFP_KERNEL memory
allocations, which is correct, because hotplug work items are
always queued up from process context, acpi_os_hotplug_execute()
uses GFP_ATOMIC, as that is needed by acpi_os_execute(). Also,
acpi_os_execute_deferred() queued up by it waits for the ACPI event
workqueues to flush before executing the work function, whereas
alloc_acpi_hp_work() can't do anything similar. That leads to
somewhat arbitrary differences in behavior between various ACPI
hotplug code paths and has to be straightened up.
For this reason, replace both alloc_acpi_hp_work() and
acpi_os_hotplug_execute() with a single interface,
acpi_hotplug_execute(), combining their behavior and being more
friendly to its users than any of the two.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-11-07 07:45:40 +07:00
|
|
|
hotplug_event(handle, type, context);
|
2011-09-29 06:40:53 +07:00
|
|
|
|
ACPI / hotplug: Fix concurrency issues and memory leaks
This changeset is aimed at fixing a few different but related
problems in the ACPI hotplug infrastructure.
First of all, since notify handlers may be run in parallel with
acpi_bus_scan(), acpi_bus_trim() and acpi_bus_hot_remove_device()
and some of them are installed for ACPI handles that have no struct
acpi_device objects attached (i.e. before those objects are created),
those notify handlers have to take acpi_scan_lock to prevent races
from taking place (e.g. a struct acpi_device is found to be present
for the given ACPI handle, but right after that it is removed by
acpi_bus_trim() running in parallel to the given notify handler).
Moreover, since some of them call acpi_bus_scan() and
acpi_bus_trim(), this leads to the conclusion that acpi_scan_lock
should be acquired by the callers of these two funtions rather by
these functions themselves.
For these reasons, make all notify handlers that can handle device
addition and eject events take acpi_scan_lock and remove the
acpi_scan_lock locking from acpi_bus_scan() and acpi_bus_trim().
Accordingly, update all of their users to make sure that they
are always called under acpi_scan_lock.
Furthermore, since eject operations are carried out asynchronously
with respect to the notify events that trigger them, with the help
of acpi_bus_hot_remove_device(), even if notify handlers take the
ACPI scan lock, it still is possible that, for example,
acpi_bus_trim() will run between acpi_bus_hot_remove_device() and
the notify handler that scheduled its execution and that
acpi_bus_trim() will remove the device node passed to
acpi_bus_hot_remove_device() for ejection. In that case, the struct
acpi_device object obtained by acpi_bus_hot_remove_device() will be
invalid and not-so-funny things will ensue. To protect agaist that,
make the users of acpi_bus_hot_remove_device() run get_device() on
ACPI device node objects that are about to be passed to it and make
acpi_bus_hot_remove_device() run put_device() on them and check if
their ACPI handles are not NULL (make acpi_device_unregister() clear
the device nodes' ACPI handles for that check to work).
Finally, observe that acpi_os_hotplug_execute() actually can fail,
in which case its caller ought to free memory allocated for the
context object to prevent leaks from happening. It also needs to
run put_device() on the device node that it ran get_device() on
previously in that case. Modify the code accordingly.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
2013-02-13 20:36:47 +07:00
|
|
|
acpi_scan_lock_release();
|
ACPI / hotplug: Consolidate deferred execution of ACPI hotplug routines
There are two different interfaces for queuing up work items on the
ACPI hotplug workqueue, alloc_acpi_hp_work() used by PCI and PCI host
bridge hotplug code and acpi_os_hotplug_execute() used by the common
ACPI hotplug code and docking stations. They both are somewhat
cumbersome to use and work slightly differently.
The users of alloc_acpi_hp_work() have to submit a work function that
will extract the necessary data items from a struct acpi_hp_work
object allocated by alloc_acpi_hp_work() and then will free that
object, while it would be more straightforward to simply use a work
function with one more argument and let the interface take care of
the execution details.
The users of acpi_os_hotplug_execute() also have to deal with the
fact that it takes only one argument in addition to the work function
pointer, although acpi_os_execute_deferred() actually takes care of
the allocation and freeing of memory, so it would have been able to
pass more arguments to the work function if it hadn't been
constrained by the connection with acpi_os_execute().
Moreover, while alloc_acpi_hp_work() makes GFP_KERNEL memory
allocations, which is correct, because hotplug work items are
always queued up from process context, acpi_os_hotplug_execute()
uses GFP_ATOMIC, as that is needed by acpi_os_execute(). Also,
acpi_os_execute_deferred() queued up by it waits for the ACPI event
workqueues to flush before executing the work function, whereas
alloc_acpi_hp_work() can't do anything similar. That leads to
somewhat arbitrary differences in behavior between various ACPI
hotplug code paths and has to be straightened up.
For this reason, replace both alloc_acpi_hp_work() and
acpi_os_hotplug_execute() with a single interface,
acpi_hotplug_execute(), combining their behavior and being more
friendly to its users than any of the two.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2013-11-07 07:45:40 +07:00
|
|
|
acpi_evaluate_hotplug_ost(handle, type, ACPI_OST_SC_SUCCESS, NULL);
|
2013-07-14 04:27:25 +07:00
|
|
|
put_bridge(context->func.parent);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:40:53 +07:00
|
|
|
/**
|
2013-07-14 04:27:24 +07:00
|
|
|
* handle_hotplug_event - handle ACPI hotplug event
|
2011-09-29 06:40:53 +07:00
|
|
|
* @handle: Notify()'ed acpi_handle
|
|
|
|
* @type: Notify code
|
2013-07-14 04:27:24 +07:00
|
|
|
* @data: pointer to acpiphp_context structure
|
2011-09-29 06:40:53 +07:00
|
|
|
*
|
|
|
|
* Handles ACPI event notification on slots.
|
|
|
|
*/
|
2013-07-14 04:27:24 +07:00
|
|
|
static void handle_hotplug_event(acpi_handle handle, u32 type, void *data)
|
2011-09-29 06:40:53 +07:00
|
|
|
{
|
2013-07-14 04:27:24 +07:00
|
|
|
struct acpiphp_context *context;
|
2013-09-06 20:41:41 +07:00
|
|
|
u32 ost_code = ACPI_OST_SC_SUCCESS;
|
2014-02-04 04:30:06 +07:00
|
|
|
acpi_status status;
|
2013-07-14 04:27:24 +07:00
|
|
|
|
2013-07-14 04:27:26 +07:00
|
|
|
switch (type) {
|
|
|
|
case ACPI_NOTIFY_BUS_CHECK:
|
|
|
|
case ACPI_NOTIFY_DEVICE_CHECK:
|
2013-09-06 20:41:41 +07:00
|
|
|
break;
|
2013-07-14 04:27:26 +07:00
|
|
|
case ACPI_NOTIFY_EJECT_REQUEST:
|
2013-09-06 20:41:41 +07:00
|
|
|
ost_code = ACPI_OST_SC_EJECT_IN_PROGRESS;
|
|
|
|
acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL);
|
2013-07-14 04:27:26 +07:00
|
|
|
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");
|
2013-09-06 20:41:41 +07:00
|
|
|
goto out;
|
2013-07-14 04:27:26 +07:00
|
|
|
|
|
|
|
case ACPI_NOTIFY_BUS_MODE_MISMATCH:
|
|
|
|
acpi_handle_err(handle, "Device cannot be configured due "
|
|
|
|
"to a bus mode mismatch\n");
|
2013-09-06 20:41:41 +07:00
|
|
|
goto out;
|
2013-07-14 04:27:26 +07:00
|
|
|
|
|
|
|
case ACPI_NOTIFY_POWER_FAULT:
|
|
|
|
acpi_handle_err(handle, "Device has suffered a power fault\n");
|
2013-09-06 20:41:41 +07:00
|
|
|
goto out;
|
2013-07-14 04:27:26 +07:00
|
|
|
|
|
|
|
default:
|
|
|
|
acpi_handle_warn(handle, "Unsupported event type 0x%x\n", type);
|
2013-09-06 20:41:41 +07:00
|
|
|
ost_code = ACPI_OST_SC_UNRECOGNIZED_NOTIFY;
|
|
|
|
goto out;
|
2013-07-14 04:27:26 +07:00
|
|
|
}
|
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
mutex_lock(&acpiphp_context_lock);
|
|
|
|
context = acpiphp_get_context(handle);
|
2014-02-04 04:30:06 +07:00
|
|
|
if (!context || WARN_ON(context->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)) {
|
2013-09-06 20:41:41 +07:00
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
|
|
|
return;
|
2013-07-14 04:27:24 +07:00
|
|
|
}
|
2014-02-04 04:30:06 +07:00
|
|
|
put_bridge(context->func.parent);
|
|
|
|
|
|
|
|
err_out:
|
2013-07-14 04:27:24 +07:00
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
2013-09-06 20:41:41 +07:00
|
|
|
ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
|
|
|
|
|
|
|
|
out:
|
|
|
|
acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL);
|
2005-04-28 14:25:56 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-04-12 12:44:26 +07:00
|
|
|
/*
|
|
|
|
* Create hotplug slots for the PCI bus.
|
|
|
|
* It should always return 0 to avoid skipping following notifiers.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2013-07-14 04:27:23 +07:00
|
|
|
void acpiphp_enumerate_slots(struct pci_bus *bus)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-04-12 12:44:26 +07:00
|
|
|
struct acpiphp_bridge *bridge;
|
2013-07-14 04:27:23 +07:00
|
|
|
acpi_handle handle;
|
|
|
|
acpi_status status;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-04-12 12:44:26 +07:00
|
|
|
if (acpiphp_disabled)
|
|
|
|
return;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-07-14 04:27:23 +07:00
|
|
|
handle = ACPI_HANDLE(bus->bridge);
|
2013-07-14 04:27:24 +07:00
|
|
|
if (!handle)
|
2013-04-12 12:44:26 +07:00
|
|
|
return;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-04-12 12:44:26 +07:00
|
|
|
bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
|
2013-07-14 04:27:24 +07:00
|
|
|
if (!bridge) {
|
|
|
|
acpi_handle_err(handle, "No memory for bridge object\n");
|
2013-04-12 12:44:26 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-12 12:44:27 +07:00
|
|
|
INIT_LIST_HEAD(&bridge->slots);
|
2013-04-12 12:44:28 +07:00
|
|
|
kref_init(&bridge->ref);
|
2013-04-12 12:44:26 +07:00
|
|
|
bridge->pci_dev = pci_dev_get(bus->self);
|
|
|
|
bridge->pci_bus = bus;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab a ref to the subordinate PCI bus in case the bus is
|
|
|
|
* removed via PCI core logical hotplug. The ref pins the bus
|
|
|
|
* (which we access during module unload).
|
|
|
|
*/
|
|
|
|
get_device(&bus->dev);
|
|
|
|
|
2013-07-14 04:27:24 +07:00
|
|
|
if (!pci_is_root_bus(bridge->pci_bus)) {
|
|
|
|
struct acpiphp_context *context;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This bridge should have been registered as a hotplug function
|
2013-10-12 06:49:48 +07:00
|
|
|
* under its parent, so the context should be there, unless the
|
|
|
|
* parent is going to be handled by pciehp, in which case this
|
|
|
|
* bridge is not interesting to us either.
|
2013-07-14 04:27:24 +07:00
|
|
|
*/
|
|
|
|
mutex_lock(&acpiphp_context_lock);
|
|
|
|
context = acpiphp_get_context(handle);
|
2013-10-12 06:49:48 +07:00
|
|
|
if (!context) {
|
2013-07-14 04:27:24 +07:00
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
|
|
|
put_device(&bus->dev);
|
2013-10-11 18:20:50 +07:00
|
|
|
pci_dev_put(bridge->pci_dev);
|
2013-07-14 04:27:24 +07:00
|
|
|
kfree(bridge);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bridge->context = context;
|
|
|
|
context->bridge = bridge;
|
|
|
|
/* Get a reference to the parent bridge. */
|
2013-07-14 04:27:25 +07:00
|
|
|
get_bridge(context->func.parent);
|
2013-07-14 04:27:24 +07:00
|
|
|
mutex_unlock(&acpiphp_context_lock);
|
|
|
|
}
|
|
|
|
|
2013-07-14 04:27:23 +07:00
|
|
|
/* must be added to the list prior to calling register_slot */
|
|
|
|
mutex_lock(&bridge_mutex);
|
|
|
|
list_add(&bridge->list, &bridge_list);
|
|
|
|
mutex_unlock(&bridge_mutex);
|
|
|
|
|
|
|
|
/* register all slot objects under this bridge */
|
2013-07-14 04:27:25 +07:00
|
|
|
status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
|
2013-07-14 04:27:23 +07:00
|
|
|
register_slot, NULL, bridge, NULL);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
2013-07-14 04:27:25 +07:00
|
|
|
acpi_handle_err(handle, "failed to register slots\n");
|
2013-07-14 04:27:24 +07:00
|
|
|
cleanup_bridge(bridge);
|
|
|
|
put_bridge(bridge);
|
2013-07-14 04:27:23 +07:00
|
|
|
}
|
2013-04-12 12:44:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Destroy hotplug slots associated with the PCI bus */
|
|
|
|
void acpiphp_remove_slots(struct pci_bus *bus)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-07-14 04:27:26 +07:00
|
|
|
struct acpiphp_bridge *bridge;
|
2013-04-12 12:44:26 +07:00
|
|
|
|
|
|
|
if (acpiphp_disabled)
|
|
|
|
return;
|
|
|
|
|
2013-07-14 04:27:26 +07:00
|
|
|
mutex_lock(&bridge_mutex);
|
|
|
|
list_for_each_entry(bridge, &bridge_list, list)
|
2013-04-12 12:44:26 +07:00
|
|
|
if (bridge->pci_bus == bus) {
|
2013-07-14 04:27:26 +07:00
|
|
|
mutex_unlock(&bridge_mutex);
|
2013-04-12 12:44:26 +07:00
|
|
|
cleanup_bridge(bridge);
|
2013-04-12 12:44:28 +07:00
|
|
|
put_bridge(bridge);
|
2013-07-14 04:27:26 +07:00
|
|
|
return;
|
2013-04-12 12:44:26 +07:00
|
|
|
}
|
2013-07-14 04:27:26 +07:00
|
|
|
|
|
|
|
mutex_unlock(&bridge_mutex);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* acpiphp_enable_slot - power on slot
|
2007-11-29 00:04:30 +07:00
|
|
|
* @slot: ACPI PHP slot
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
int acpiphp_enable_slot(struct acpiphp_slot *slot)
|
|
|
|
{
|
2014-01-10 21:24:41 +07:00
|
|
|
pci_lock_rescan_remove();
|
|
|
|
|
|
|
|
if (slot->flags & SLOT_IS_GOING_AWAY)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2006-01-13 22:02:15 +07:00
|
|
|
mutex_lock(&slot->crit_sect);
|
2013-07-14 04:27:26 +07:00
|
|
|
/* configure all functions */
|
2013-07-14 04:27:26 +07:00
|
|
|
if (!(slot->flags & SLOT_ENABLED))
|
2013-07-14 04:27:26 +07:00
|
|
|
enable_slot(slot);
|
2013-07-14 04:27:26 +07:00
|
|
|
|
2006-01-13 22:02:15 +07:00
|
|
|
mutex_unlock(&slot->crit_sect);
|
2014-01-10 21:24:41 +07:00
|
|
|
|
|
|
|
pci_unlock_rescan_remove();
|
2013-07-14 04:27:26 +07:00
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-14 04:27:26 +07:00
|
|
|
* acpiphp_disable_and_eject_slot - power off and eject slot
|
2007-11-29 00:04:30 +07:00
|
|
|
* @slot: ACPI PHP slot
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2014-01-10 21:24:41 +07:00
|
|
|
static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-07-14 04:27:26 +07:00
|
|
|
struct acpiphp_func *func;
|
2014-01-10 21:24:41 +07:00
|
|
|
|
|
|
|
if (slot->flags & SLOT_IS_GOING_AWAY)
|
|
|
|
return -ENODEV;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-01-13 22:02:15 +07:00
|
|
|
mutex_lock(&slot->crit_sect);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* unconfigure all functions */
|
2013-07-14 04:27:26 +07:00
|
|
|
disable_slot(slot);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-07-14 04:27:26 +07:00
|
|
|
list_for_each_entry(func, &slot->funcs, sibling)
|
|
|
|
if (func->flags & FUNC_HAS_EJ0) {
|
|
|
|
acpi_handle handle = func_to_handle(func);
|
|
|
|
|
|
|
|
if (ACPI_FAILURE(acpi_evaluate_ej0(handle)))
|
|
|
|
acpi_handle_err(handle, "_EJ0 failed\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-01-13 22:02:15 +07:00
|
|
|
mutex_unlock(&slot->crit_sect);
|
2014-01-10 21:24:41 +07:00
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2014-01-10 21:24:41 +07:00
|
|
|
int acpiphp_disable_slot(struct acpiphp_slot *slot)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pci_lock_rescan_remove();
|
|
|
|
ret = acpiphp_disable_and_eject_slot(slot);
|
|
|
|
pci_unlock_rescan_remove();
|
|
|
|
return ret;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* slot enabled: 1
|
|
|
|
* slot disabled: 0
|
|
|
|
*/
|
|
|
|
u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
|
|
|
|
{
|
2013-07-14 04:27:26 +07:00
|
|
|
return (slot->flags & SLOT_ENABLED);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-10-26 01:44:57 +07:00
|
|
|
* latch open: 1
|
|
|
|
* latch closed: 0
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
|
|
|
|
{
|
2013-07-14 04:27:26 +07:00
|
|
|
return !(get_slot_status(slot) & ACPI_STA_DEVICE_UI);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* adapter presence : 1
|
|
|
|
* absence : 0
|
|
|
|
*/
|
|
|
|
u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
|
|
|
|
{
|
2013-07-14 04:27:26 +07:00
|
|
|
return !!get_slot_status(slot);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|