2018-01-27 04:22:04 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-17 06:20:36 +08: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
|
2018-06-17 05:32:07 +08:00
|
|
|
* Copyright (C) 2003-2005 Matthew Wilcox (willy@infradead.org)
|
2005-04-28 15:25:53 +08:00
|
|
|
* Copyright (C) 2003-2005 Hewlett Packard
|
2005-04-28 15:25:56 +08:00
|
|
|
* Copyright (C) 2005 Rajesh Shah (rajesh.shah@intel.com)
|
|
|
|
* Copyright (C) 2005 Intel Corporation
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2006-07-27 01:52:33 +08:00
|
|
|
* Send feedback to <kristen.c.accardi@intel.com>
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-04-28 15:25:53 +08: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-31 00:50:14 +08: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 15:25:53 +08:00
|
|
|
*/
|
|
|
|
|
2013-09-25 08:11:48 +08:00
|
|
|
#define pr_fmt(fmt) "acpiphp_glue: " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pci.h>
|
2006-10-14 11:05:19 +08:00
|
|
|
#include <linux/pci_hotplug.h>
|
2008-12-17 11:09:12 +08: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 04:10:35 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2006-01-13 23:02:15 +08: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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-09-29 07:40:53 +08:00
|
|
|
#include <linux/acpi.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "../pci.h"
|
|
|
|
#include "acpiphp.h"
|
|
|
|
|
|
|
|
static LIST_HEAD(bridge_list);
|
2013-04-12 13:44:28 +08:00
|
|
|
static DEFINE_MUTEX(bridge_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-02-21 08:10:27 +08:00
|
|
|
static int acpiphp_hotplug_notify(struct acpi_device *adev, u32 type);
|
2014-02-21 08:10:18 +08:00
|
|
|
static void acpiphp_post_dock_fixup(struct acpi_device *adev);
|
2005-10-19 08:21:40 +08:00
|
|
|
static void acpiphp_sanitize_bus(struct pci_bus *bus);
|
2014-02-04 07:42:20 +08:00
|
|
|
static void hotplug_event(u32 type, struct acpiphp_context *context);
|
2013-04-12 13:44:28 +08:00
|
|
|
static void free_bridge(struct kref *kref);
|
2005-10-19 08:21:40 +08:00
|
|
|
|
2013-07-14 05:27:24 +08:00
|
|
|
/**
|
|
|
|
* acpiphp_init_context - Create hotplug context and grab a reference to it.
|
2014-02-04 07:39:33 +08:00
|
|
|
* @adev: ACPI device object to create the context for.
|
2013-07-14 05:27:24 +08:00
|
|
|
*
|
2014-02-04 07:43:17 +08:00
|
|
|
* Call under acpi_hp_context_lock.
|
2013-07-14 05:27:24 +08:00
|
|
|
*/
|
2014-02-04 07:39:33 +08:00
|
|
|
static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev)
|
2013-07-14 05:27:24 +08:00
|
|
|
{
|
|
|
|
struct acpiphp_context *context;
|
|
|
|
|
|
|
|
context = kzalloc(sizeof(*context), GFP_KERNEL);
|
|
|
|
if (!context)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
context->refcount = 1;
|
2014-07-16 04:03:22 +08:00
|
|
|
context->hp.notify = acpiphp_hotplug_notify;
|
|
|
|
context->hp.fixup = acpiphp_post_dock_fixup;
|
|
|
|
acpi_set_hp_context(adev, &context->hp);
|
2013-07-14 05:27:24 +08:00
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* acpiphp_get_context - Get hotplug context and grab a reference to it.
|
2014-02-07 00:31:37 +08:00
|
|
|
* @adev: ACPI device object to get the context for.
|
2013-07-14 05:27:24 +08:00
|
|
|
*
|
2014-02-04 07:43:17 +08:00
|
|
|
* Call under acpi_hp_context_lock.
|
2013-07-14 05:27:24 +08:00
|
|
|
*/
|
2014-02-07 00:31:37 +08:00
|
|
|
static struct acpiphp_context *acpiphp_get_context(struct acpi_device *adev)
|
2013-07-14 05:27:24 +08:00
|
|
|
{
|
2014-02-07 00:31:37 +08:00
|
|
|
struct acpiphp_context *context;
|
2013-07-14 05:27:24 +08:00
|
|
|
|
2014-02-07 00:31:37 +08:00
|
|
|
if (!adev->hp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
context = to_acpiphp_context(adev->hp);
|
|
|
|
context->refcount++;
|
2013-07-14 05:27:24 +08:00
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* acpiphp_put_context - Drop a reference to ACPI hotplug context.
|
2014-02-04 07:39:33 +08:00
|
|
|
* @context: ACPI hotplug context to drop a reference to.
|
2013-07-14 05:27:24 +08:00
|
|
|
*
|
|
|
|
* The context object is removed if there are no more references to it.
|
|
|
|
*
|
2014-02-04 07:43:17 +08:00
|
|
|
* Call under acpi_hp_context_lock.
|
2013-07-14 05:27:24 +08:00
|
|
|
*/
|
|
|
|
static void acpiphp_put_context(struct acpiphp_context *context)
|
|
|
|
{
|
|
|
|
if (--context->refcount)
|
|
|
|
return;
|
|
|
|
|
2013-07-14 05:27:25 +08:00
|
|
|
WARN_ON(context->bridge);
|
2014-02-07 00:31:37 +08:00
|
|
|
context->hp.self->hp = NULL;
|
2013-07-14 05:27:24 +08:00
|
|
|
kfree(context);
|
|
|
|
}
|
|
|
|
|
2013-04-12 13:44:28 +08: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);
|
|
|
|
}
|
|
|
|
|
2014-02-21 08:10:18 +08:00
|
|
|
static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev)
|
|
|
|
{
|
|
|
|
struct acpiphp_context *context;
|
|
|
|
|
|
|
|
acpi_lock_hp_context();
|
|
|
|
context = acpiphp_get_context(adev);
|
|
|
|
if (!context || context->func.parent->is_going_away) {
|
|
|
|
acpi_unlock_hp_context();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
get_bridge(context->func.parent);
|
|
|
|
acpiphp_put_context(context);
|
|
|
|
acpi_unlock_hp_context();
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void acpiphp_let_context_go(struct acpiphp_context *context)
|
|
|
|
{
|
|
|
|
put_bridge(context->func.parent);
|
|
|
|
}
|
|
|
|
|
2013-04-12 13:44:28 +08:00
|
|
|
static void free_bridge(struct kref *kref)
|
|
|
|
{
|
2013-07-14 05:27:24 +08:00
|
|
|
struct acpiphp_context *context;
|
2013-04-12 13:44:28 +08:00
|
|
|
struct acpiphp_bridge *bridge;
|
|
|
|
struct acpiphp_slot *slot, *next;
|
|
|
|
struct acpiphp_func *func, *tmp;
|
|
|
|
|
2014-02-04 07:43:17 +08:00
|
|
|
acpi_lock_hp_context();
|
2013-07-14 05:27:24 +08:00
|
|
|
|
2013-04-12 13:44:28 +08:00
|
|
|
bridge = container_of(kref, struct acpiphp_bridge, ref);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(slot, next, &bridge->slots, node) {
|
2013-07-14 05:27:25 +08:00
|
|
|
list_for_each_entry_safe(func, tmp, &slot->funcs, sibling)
|
|
|
|
acpiphp_put_context(func_to_context(func));
|
|
|
|
|
2013-04-12 13:44:28 +08:00
|
|
|
kfree(slot);
|
|
|
|
}
|
|
|
|
|
2013-07-14 05:27:24 +08:00
|
|
|
context = bridge->context;
|
2013-07-14 05:27:24 +08:00
|
|
|
/* Root bridges will not have hotplug context. */
|
|
|
|
if (context) {
|
|
|
|
/* Release the reference taken by acpiphp_enumerate_slots(). */
|
2013-07-14 05:27:25 +08:00
|
|
|
put_bridge(context->func.parent);
|
2013-07-14 05:27:24 +08:00
|
|
|
context->bridge = NULL;
|
|
|
|
acpiphp_put_context(context);
|
|
|
|
}
|
2013-07-14 05:27:24 +08:00
|
|
|
|
2013-04-12 13:44:28 +08:00
|
|
|
put_device(&bridge->pci_bus->dev);
|
|
|
|
pci_dev_put(bridge->pci_dev);
|
|
|
|
kfree(bridge);
|
2013-07-14 05:27:24 +08:00
|
|
|
|
2014-02-04 07:43:17 +08:00
|
|
|
acpi_unlock_hp_context();
|
2013-04-12 13:44:28 +08:00
|
|
|
}
|
|
|
|
|
2014-02-21 08:10:18 +08:00
|
|
|
/**
|
|
|
|
* acpiphp_post_dock_fixup - Post-dock fixups for PCI devices.
|
|
|
|
* @adev: ACPI device object corresponding to a PCI device.
|
2006-06-28 15:08:06 +08:00
|
|
|
*
|
2014-02-21 08:10:18 +08:00
|
|
|
* TBD - figure out a way to only call fixups for systems that require them.
|
2006-06-28 15:08:06 +08:00
|
|
|
*/
|
2014-02-21 08:10:18 +08:00
|
|
|
static void acpiphp_post_dock_fixup(struct acpi_device *adev)
|
2006-06-28 15:08:06 +08:00
|
|
|
{
|
2014-02-21 08:10:18 +08:00
|
|
|
struct acpiphp_context *context = acpiphp_grab_context(adev);
|
|
|
|
struct pci_bus *bus;
|
2006-06-28 15:08:06 +08:00
|
|
|
u32 buses;
|
|
|
|
|
2014-02-21 08:10:18 +08:00
|
|
|
if (!context)
|
2013-07-05 09:03:25 +08:00
|
|
|
return;
|
2006-06-28 15:08:06 +08:00
|
|
|
|
2014-02-21 08:10:18 +08:00
|
|
|
bus = context->func.slot->bus;
|
|
|
|
if (!bus->self)
|
|
|
|
goto out;
|
|
|
|
|
2006-06-28 15:08:06 +08:00
|
|
|
/* fixup bad _DCK function that rewrites
|
|
|
|
* secondary bridge on slot
|
|
|
|
*/
|
2014-02-21 08:10:18 +08:00
|
|
|
pci_read_config_dword(bus->self, PCI_PRIMARY_BUS, &buses);
|
2006-06-28 15:08:06 +08:00
|
|
|
|
2012-05-18 09:51:11 +08:00
|
|
|
if (((buses >> 8) & 0xff) != bus->busn_res.start) {
|
2006-06-28 15:08:06 +08:00
|
|
|
buses = (buses & 0xff000000)
|
2008-12-12 02:17:55 +08:00
|
|
|
| ((unsigned int)(bus->primary) << 0)
|
2012-05-18 09:51:11 +08:00
|
|
|
| ((unsigned int)(bus->busn_res.start) << 8)
|
|
|
|
| ((unsigned int)(bus->busn_res.end) << 16);
|
2006-06-28 15:08:06 +08:00
|
|
|
pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses);
|
|
|
|
}
|
|
|
|
|
2014-02-21 08:10:18 +08:00
|
|
|
out:
|
|
|
|
acpiphp_let_context_go(context);
|
2014-02-04 05:30:15 +08:00
|
|
|
}
|
2006-06-28 15:08:06 +08:00
|
|
|
|
2014-02-16 07:12:00 +08:00
|
|
|
/**
|
|
|
|
* acpiphp_add_context - Add ACPIPHP context to an ACPI device object.
|
|
|
|
* @handle: ACPI handle of the object to add a context to.
|
|
|
|
* @lvl: Not used.
|
|
|
|
* @data: The object's parent ACPIPHP bridge.
|
|
|
|
* @rv: Not used.
|
|
|
|
*/
|
|
|
|
static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data,
|
|
|
|
void **rv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-07-14 05:27:24 +08:00
|
|
|
struct acpiphp_bridge *bridge = data;
|
|
|
|
struct acpiphp_context *context;
|
2014-02-04 07:39:33 +08:00
|
|
|
struct acpi_device *adev;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct acpiphp_slot *slot;
|
|
|
|
struct acpiphp_func *newfunc;
|
|
|
|
acpi_status status = AE_OK;
|
2013-07-14 05:27:24 +08:00
|
|
|
unsigned long long adr;
|
|
|
|
int device, function;
|
2008-12-17 11:09:12 +08:00
|
|
|
struct pci_bus *pbus = bridge->pci_bus;
|
2013-07-14 05:27:24 +08:00
|
|
|
struct pci_dev *pdev = bridge->pci_dev;
|
2013-04-12 13:44:26 +08:00
|
|
|
u32 val;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-06-21 06:18:29 +08:00
|
|
|
status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
2013-11-28 04:33:09 +08:00
|
|
|
if (status != AE_NOT_FOUND)
|
|
|
|
acpi_handle_warn(handle,
|
|
|
|
"can't evaluate _ADR (%#x)\n", status);
|
2012-06-21 06:18:29 +08:00
|
|
|
return AE_OK;
|
|
|
|
}
|
2014-02-04 07:39:33 +08:00
|
|
|
if (acpi_bus_get_device(handle, &adev))
|
|
|
|
return AE_OK;
|
2012-06-21 06:18:29 +08:00
|
|
|
|
|
|
|
device = (adr >> 16) & 0xffff;
|
|
|
|
function = adr & 0xffff;
|
|
|
|
|
2014-02-04 07:43:17 +08:00
|
|
|
acpi_lock_hp_context();
|
2014-02-04 07:39:33 +08:00
|
|
|
context = acpiphp_init_context(adev);
|
2013-07-14 05:27:24 +08:00
|
|
|
if (!context) {
|
2014-02-04 07:43:17 +08:00
|
|
|
acpi_unlock_hp_context();
|
2013-07-14 05:27:24 +08:00
|
|
|
acpi_handle_err(handle, "No hotplug context\n");
|
|
|
|
return AE_NOT_EXIST;
|
|
|
|
}
|
2013-07-14 05:27:25 +08:00
|
|
|
newfunc = &context->func;
|
|
|
|
newfunc->function = function;
|
2013-07-14 05:27:25 +08:00
|
|
|
newfunc->parent = bridge;
|
2014-02-21 08:10:18 +08:00
|
|
|
acpi_unlock_hp_context();
|
2013-07-14 05:27:24 +08:00
|
|
|
|
2014-02-21 08:10:18 +08:00
|
|
|
/*
|
|
|
|
* If this is a dock device, its _EJ0 should be executed by the dock
|
|
|
|
* notify handler after calling _DCK.
|
|
|
|
*/
|
|
|
|
if (!is_dock_device(adev) && acpi_has_method(handle, "_EJ0"))
|
2006-02-24 09:56:03 +08:00
|
|
|
newfunc->flags = FUNC_HAS_EJ0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-06-29 00:24:43 +08:00
|
|
|
if (acpi_has_method(handle, "_STA"))
|
2005-04-17 06:20:36 +08:00
|
|
|
newfunc->flags |= FUNC_HAS_STA;
|
|
|
|
|
|
|
|
/* search for objects that share the same slot */
|
2013-04-12 13:44:27 +08:00
|
|
|
list_for_each_entry(slot, &bridge->slots, node)
|
2013-07-14 05:27:24 +08:00
|
|
|
if (slot->device == device)
|
2013-07-14 05:27:24 +08:00
|
|
|
goto slot_found;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-07-14 05:27:24 +08:00
|
|
|
slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
|
|
|
|
if (!slot) {
|
2014-02-04 07:43:17 +08:00
|
|
|
acpi_lock_hp_context();
|
2014-02-04 07:38:15 +08:00
|
|
|
acpiphp_put_context(context);
|
2014-02-04 07:43:17 +08:00
|
|
|
acpi_unlock_hp_context();
|
2014-02-04 07:38:15 +08:00
|
|
|
return AE_NO_MEMORY;
|
2013-07-14 05:27:24 +08:00
|
|
|
}
|
|
|
|
|
2013-07-14 05:27:25 +08:00
|
|
|
slot->bus = bridge->pci_bus;
|
2013-07-14 05:27:24 +08:00
|
|
|
slot->device = device;
|
|
|
|
INIT_LIST_HEAD(&slot->funcs);
|
|
|
|
|
|
|
|
list_add_tail(&slot->node, &bridge->slots);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-02-16 07:12:09 +08:00
|
|
|
/*
|
|
|
|
* Expose slots to user space for functions that have _EJ0 or _RMV or
|
|
|
|
* are located in dock stations. Do not expose them for devices handled
|
ACPI / hotplug / PCI: Don't scan bridges managed by native hotplug
When acpiphp re-enumerates a PCI hierarchy because of an ACPI Notify()
event, we should skip bridges managed by native hotplug (pciehp or shpchp).
We don't want to scan below a native hotplug bridge until the hotplug
controller generates a hot-add event.
A typical scenario is a Root Port leading to a Thunderbolt host router that
remains powered off until something is connected to it. See [1] for the
lspci details.
1. Before something is connected, only the Root Port exists. It has
PCI_EXP_SLTCAP_HPC set and pciehp is responsible for hotplug:
00:1b.0 Root Port (HotPlug+)
2. When a USB-C or Thunderbolt device is connected, the Switch in the
Thunderbolt host router is powered up, the Root Port signals a hotplug
add event and pciehp enumerates the Switch:
01:00.0 Switch Upstream Port to [bus 02-39]
02:00.0 Switch Downstream Port to [bus 03] (HotPlug-, to NHI)
02:01.0 Switch Downstream Port to [bus 04-38] (HotPlug+, to Thunderbolt connector)
02:02.0 Switch Downstream Port to [bus 39] (HotPlug-, to xHCI)
The 02:00.0 and 02:02.0 Ports lead to Endpoints that are not powered
up yet. The Ports have PCI_EXP_SLTCAP_HPC cleared, so pciehp doesn't
handle hotplug for them and we assign minimal resources to them.
The 02:01.0 Port has PCI_EXP_SLTCAP_HPC set, so pciehp handles native
hotplug events for it.
3. The BIOS powers up the xHCI controller. If a Thunderbolt device was
connected (not just a USB-C device), it also powers up the NHI. Then
it sends an ACPI Notify() to the Root Port, and acpiphp enumerates the
new device(s):
03:00.0 Thunderbolt Host Controller (NHI) Endpoint
39:00.0 xHCI Endpoint
4. If a Thunderbolt device was connected, the host router firmware uses
the NHI to set up Thunderbolt tunnels and triggers a native hotplug
event (via 02:01.0 in this example). Then pciehp enumerates the new
Thunderbolt devices:
04:00.0 Switch Upstream Port to [bus 05-38]
05:01.0 Switch Downstream Port to [bus 06-09] (HotPlug-)
05:04.0 Switch Downstream Port to [bus 0a-38] (HotPlug+)
In this example, 05:01.0 leads to another Switch and some NICs. This
subtree is static, so 05:01.0 doesn't support hotplug and has
PCI_EXP_SLTCAP_HPC cleared.
In step 3, acpiphp previously enumerated everything below the Root Port,
including things below the 02:01.0 Port. We don't want that because pciehp
expects to manage hotplug below that Port, and firmware on the host router
may be in the middle of configuring its Link so it may not be ready yet.
To make this work better with the native PCIe (pciehp) and standard PCI
(shpchp) hotplug drivers, we let them handle all slot management and
resource allocation for hotplug bridges and restrict ACPI hotplug to
non-hotplug bridges.
[1] https://bugzilla.kernel.org/show_bug.cgi?id=199581#c5
Link: https://lkml.kernel.org/r/20180529160155.1738-1-mika.westerberg@linux.intel.com
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
[bhelgaas: changelog, use hotplug_is_native() instead of
dev->is_hotplug_bridge]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2018-05-30 00:01:55 +08:00
|
|
|
* by the native PCIe hotplug (PCIeHP) or standard PCI hotplug
|
|
|
|
* (SHPCHP), because that code is supposed to expose slots to user
|
|
|
|
* space in those cases.
|
2014-02-16 07:12:09 +08:00
|
|
|
*/
|
2014-02-21 08:10:09 +08:00
|
|
|
if ((acpi_pci_check_ejectable(pbus, handle) || is_dock_device(adev))
|
ACPI / hotplug / PCI: Don't scan bridges managed by native hotplug
When acpiphp re-enumerates a PCI hierarchy because of an ACPI Notify()
event, we should skip bridges managed by native hotplug (pciehp or shpchp).
We don't want to scan below a native hotplug bridge until the hotplug
controller generates a hot-add event.
A typical scenario is a Root Port leading to a Thunderbolt host router that
remains powered off until something is connected to it. See [1] for the
lspci details.
1. Before something is connected, only the Root Port exists. It has
PCI_EXP_SLTCAP_HPC set and pciehp is responsible for hotplug:
00:1b.0 Root Port (HotPlug+)
2. When a USB-C or Thunderbolt device is connected, the Switch in the
Thunderbolt host router is powered up, the Root Port signals a hotplug
add event and pciehp enumerates the Switch:
01:00.0 Switch Upstream Port to [bus 02-39]
02:00.0 Switch Downstream Port to [bus 03] (HotPlug-, to NHI)
02:01.0 Switch Downstream Port to [bus 04-38] (HotPlug+, to Thunderbolt connector)
02:02.0 Switch Downstream Port to [bus 39] (HotPlug-, to xHCI)
The 02:00.0 and 02:02.0 Ports lead to Endpoints that are not powered
up yet. The Ports have PCI_EXP_SLTCAP_HPC cleared, so pciehp doesn't
handle hotplug for them and we assign minimal resources to them.
The 02:01.0 Port has PCI_EXP_SLTCAP_HPC set, so pciehp handles native
hotplug events for it.
3. The BIOS powers up the xHCI controller. If a Thunderbolt device was
connected (not just a USB-C device), it also powers up the NHI. Then
it sends an ACPI Notify() to the Root Port, and acpiphp enumerates the
new device(s):
03:00.0 Thunderbolt Host Controller (NHI) Endpoint
39:00.0 xHCI Endpoint
4. If a Thunderbolt device was connected, the host router firmware uses
the NHI to set up Thunderbolt tunnels and triggers a native hotplug
event (via 02:01.0 in this example). Then pciehp enumerates the new
Thunderbolt devices:
04:00.0 Switch Upstream Port to [bus 05-38]
05:01.0 Switch Downstream Port to [bus 06-09] (HotPlug-)
05:04.0 Switch Downstream Port to [bus 0a-38] (HotPlug+)
In this example, 05:01.0 leads to another Switch and some NICs. This
subtree is static, so 05:01.0 doesn't support hotplug and has
PCI_EXP_SLTCAP_HPC cleared.
In step 3, acpiphp previously enumerated everything below the Root Port,
including things below the 02:01.0 Port. We don't want that because pciehp
expects to manage hotplug below that Port, and firmware on the host router
may be in the middle of configuring its Link so it may not be ready yet.
To make this work better with the native PCIe (pciehp) and standard PCI
(shpchp) hotplug drivers, we let them handle all slot management and
resource allocation for hotplug bridges and restrict ACPI hotplug to
non-hotplug bridges.
[1] https://bugzilla.kernel.org/show_bug.cgi?id=199581#c5
Link: https://lkml.kernel.org/r/20180529160155.1738-1-mika.westerberg@linux.intel.com
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
[bhelgaas: changelog, use hotplug_is_native() instead of
dev->is_hotplug_bridge]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2018-05-30 00:01:55 +08:00
|
|
|
&& !(pdev && hotplug_is_native(pdev))) {
|
2013-07-14 05:27:24 +08:00
|
|
|
unsigned long long sun;
|
|
|
|
int retval;
|
2013-07-14 05:27:24 +08:00
|
|
|
|
2013-07-14 05:27:24 +08:00
|
|
|
bridge->nr_slots++;
|
|
|
|
status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
sun = bridge->nr_slots;
|
|
|
|
|
2013-09-25 08:11:48 +08:00
|
|
|
pr_debug("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
|
2013-07-14 05:27:25 +08:00
|
|
|
sun, pci_domain_nr(pbus), pbus->number, device);
|
2013-07-14 05:27:24 +08:00
|
|
|
|
2013-07-14 05:27:25 +08:00
|
|
|
retval = acpiphp_register_hotplug_slot(slot, sun);
|
2013-07-14 05:27:24 +08:00
|
|
|
if (retval) {
|
2013-08-18 04:16:33 +08:00
|
|
|
slot->slot = NULL;
|
2013-07-14 05:27:24 +08:00
|
|
|
bridge->nr_slots--;
|
|
|
|
if (retval == -EBUSY)
|
2014-04-19 08:13:50 +08:00
|
|
|
pr_warn("Slot %llu already registered by another hotplug driver\n", sun);
|
2013-07-14 05:27:24 +08:00
|
|
|
else
|
2014-04-19 08:13:50 +08:00
|
|
|
pr_warn("acpiphp_register_hotplug_slot failed (err code = 0x%x)\n", retval);
|
2013-07-14 05:27:24 +08:00
|
|
|
}
|
|
|
|
/* Even if the slot registration fails, we can still use it. */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-07-14 05:27:24 +08:00
|
|
|
slot_found:
|
2005-04-17 06:20:36 +08:00
|
|
|
newfunc->slot = slot;
|
|
|
|
list_add_tail(&newfunc->sibling, &slot->funcs);
|
|
|
|
|
2013-04-12 13:44:26 +08:00
|
|
|
if (pci_bus_read_dev_vendor_id(pbus, PCI_DEVFN(device, function),
|
|
|
|
&val, 60*1000))
|
2013-07-14 05:27:26 +08:00
|
|
|
slot->flags |= SLOT_ENABLED;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-07-14 05:27:23 +08:00
|
|
|
return AE_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-04-28 15:25:54 +08:00
|
|
|
static void cleanup_bridge(struct acpiphp_bridge *bridge)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-04-12 13:44:28 +08:00
|
|
|
struct acpiphp_slot *slot;
|
|
|
|
struct acpiphp_func *func;
|
2005-04-28 15:25:53 +08:00
|
|
|
|
2013-04-12 13:44:28 +08:00
|
|
|
list_for_each_entry(slot, &bridge->slots, node) {
|
|
|
|
list_for_each_entry(func, &slot->funcs, sibling) {
|
2014-02-06 20:58:13 +08:00
|
|
|
struct acpi_device *adev = func_to_acpi_device(func);
|
2013-07-14 05:27:25 +08:00
|
|
|
|
2014-02-06 20:58:13 +08:00
|
|
|
acpi_lock_hp_context();
|
2014-02-21 08:10:27 +08:00
|
|
|
adev->hp->notify = NULL;
|
2014-02-21 08:10:18 +08:00
|
|
|
adev->hp->fixup = NULL;
|
2014-02-06 20:58:13 +08:00
|
|
|
acpi_unlock_hp_context();
|
2005-04-28 15:25:53 +08:00
|
|
|
}
|
2014-01-10 22:24:41 +08:00
|
|
|
slot->flags |= SLOT_IS_GOING_AWAY;
|
2013-08-18 04:16:33 +08:00
|
|
|
if (slot->slot)
|
|
|
|
acpiphp_unregister_hotplug_slot(slot);
|
2005-04-28 15:25:53 +08:00
|
|
|
}
|
|
|
|
|
2013-04-12 13:44:28 +08:00
|
|
|
mutex_lock(&bridge_mutex);
|
2005-04-28 15:25:53 +08:00
|
|
|
list_del(&bridge->list);
|
2013-04-12 13:44:28 +08:00
|
|
|
mutex_unlock(&bridge_mutex);
|
2014-01-10 22:24:41 +08:00
|
|
|
|
2014-02-04 07:43:17 +08:00
|
|
|
acpi_lock_hp_context();
|
2014-01-10 22:24:41 +08:00
|
|
|
bridge->is_going_away = true;
|
2014-02-04 07:43:17 +08:00
|
|
|
acpi_unlock_hp_context();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-02-24 09:55:58 +08:00
|
|
|
/**
|
2007-11-29 01:04:30 +08:00
|
|
|
* acpiphp_max_busnr - return the highest reserved bus number under the given bus.
|
2006-02-24 09:55:58 +08:00
|
|
|
* @bus: bus to start search with
|
|
|
|
*/
|
|
|
|
static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
|
|
|
|
{
|
2014-02-13 21:13:58 +08:00
|
|
|
struct pci_bus *tmp;
|
2006-02-24 09:55:58 +08:00
|
|
|
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 09:51:11 +08:00
|
|
|
max = bus->busn_res.start;
|
2006-02-24 09:55:58 +08:00
|
|
|
|
2014-02-13 21:13:58 +08:00
|
|
|
list_for_each_entry(tmp, &bus->children, node) {
|
|
|
|
n = pci_bus_max_busnr(tmp);
|
2006-02-24 09:55:58 +08:00
|
|
|
if (n > max)
|
|
|
|
max = n;
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
2010-02-25 10:59:34 +08: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 05:27:25 +08:00
|
|
|
acpi_evaluate_object(func_to_handle(func), "_REG", &arg_list,
|
|
|
|
NULL);
|
2010-02-25 10:59:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 05:20:42 +08: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 05:27:24 +08:00
|
|
|
dev->is_hotplug_bridge = 1;
|
2013-01-22 05:20:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-12 13:44:26 +08: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 06:07:28 +08:00
|
|
|
static int acpiphp_rescan_slot(struct acpiphp_slot *slot)
|
|
|
|
{
|
|
|
|
struct acpiphp_func *func;
|
|
|
|
|
2014-02-04 07:39:58 +08:00
|
|
|
list_for_each_entry(func, &slot->funcs, sibling) {
|
|
|
|
struct acpi_device *adev = func_to_acpi_device(func);
|
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 06:07:28 +08:00
|
|
|
|
2014-02-04 07:39:58 +08:00
|
|
|
acpi_bus_scan(adev->handle);
|
|
|
|
if (acpi_device_enumerated(adev))
|
|
|
|
acpi_device_set_power(adev, ACPI_STATE_D0);
|
|
|
|
}
|
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 06:07:28 +08:00
|
|
|
return pci_scan_slot(slot->bus, PCI_DEVFN(slot->device, 0));
|
|
|
|
}
|
|
|
|
|
ACPI / hotplug / PCI: Don't scan bridges managed by native hotplug
When acpiphp re-enumerates a PCI hierarchy because of an ACPI Notify()
event, we should skip bridges managed by native hotplug (pciehp or shpchp).
We don't want to scan below a native hotplug bridge until the hotplug
controller generates a hot-add event.
A typical scenario is a Root Port leading to a Thunderbolt host router that
remains powered off until something is connected to it. See [1] for the
lspci details.
1. Before something is connected, only the Root Port exists. It has
PCI_EXP_SLTCAP_HPC set and pciehp is responsible for hotplug:
00:1b.0 Root Port (HotPlug+)
2. When a USB-C or Thunderbolt device is connected, the Switch in the
Thunderbolt host router is powered up, the Root Port signals a hotplug
add event and pciehp enumerates the Switch:
01:00.0 Switch Upstream Port to [bus 02-39]
02:00.0 Switch Downstream Port to [bus 03] (HotPlug-, to NHI)
02:01.0 Switch Downstream Port to [bus 04-38] (HotPlug+, to Thunderbolt connector)
02:02.0 Switch Downstream Port to [bus 39] (HotPlug-, to xHCI)
The 02:00.0 and 02:02.0 Ports lead to Endpoints that are not powered
up yet. The Ports have PCI_EXP_SLTCAP_HPC cleared, so pciehp doesn't
handle hotplug for them and we assign minimal resources to them.
The 02:01.0 Port has PCI_EXP_SLTCAP_HPC set, so pciehp handles native
hotplug events for it.
3. The BIOS powers up the xHCI controller. If a Thunderbolt device was
connected (not just a USB-C device), it also powers up the NHI. Then
it sends an ACPI Notify() to the Root Port, and acpiphp enumerates the
new device(s):
03:00.0 Thunderbolt Host Controller (NHI) Endpoint
39:00.0 xHCI Endpoint
4. If a Thunderbolt device was connected, the host router firmware uses
the NHI to set up Thunderbolt tunnels and triggers a native hotplug
event (via 02:01.0 in this example). Then pciehp enumerates the new
Thunderbolt devices:
04:00.0 Switch Upstream Port to [bus 05-38]
05:01.0 Switch Downstream Port to [bus 06-09] (HotPlug-)
05:04.0 Switch Downstream Port to [bus 0a-38] (HotPlug+)
In this example, 05:01.0 leads to another Switch and some NICs. This
subtree is static, so 05:01.0 doesn't support hotplug and has
PCI_EXP_SLTCAP_HPC cleared.
In step 3, acpiphp previously enumerated everything below the Root Port,
including things below the 02:01.0 Port. We don't want that because pciehp
expects to manage hotplug below that Port, and firmware on the host router
may be in the middle of configuring its Link so it may not be ready yet.
To make this work better with the native PCIe (pciehp) and standard PCI
(shpchp) hotplug drivers, we let them handle all slot management and
resource allocation for hotplug bridges and restrict ACPI hotplug to
non-hotplug bridges.
[1] https://bugzilla.kernel.org/show_bug.cgi?id=199581#c5
Link: https://lkml.kernel.org/r/20180529160155.1738-1-mika.westerberg@linux.intel.com
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
[bhelgaas: changelog, use hotplug_is_native() instead of
dev->is_hotplug_bridge]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2018-05-30 00:01:55 +08:00
|
|
|
static void acpiphp_native_scan_bridge(struct pci_dev *bridge)
|
|
|
|
{
|
|
|
|
struct pci_bus *bus = bridge->subordinate;
|
|
|
|
struct pci_dev *dev;
|
|
|
|
int max;
|
|
|
|
|
|
|
|
if (!bus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
max = bus->busn_res.start;
|
|
|
|
/* Scan already configured non-hotplug bridges */
|
|
|
|
for_each_pci_bridge(dev, bus) {
|
|
|
|
if (!hotplug_is_native(dev))
|
|
|
|
max = pci_scan_bridge(bus, dev, max, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scan non-hotplug bridges that need to be reconfigured */
|
|
|
|
for_each_pci_bridge(dev, bus) {
|
|
|
|
if (!hotplug_is_native(dev))
|
|
|
|
max = pci_scan_bridge(bus, dev, max, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
2013-07-14 05:27:26 +08:00
|
|
|
* enable_slot - enable, configure a slot
|
2005-04-17 06:20:36 +08:00
|
|
|
* @slot: slot to be enabled
|
2018-09-27 04:39:28 +08:00
|
|
|
* @bridge: true if enable is for the whole bridge (not a single slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This function should be called per *physical slot*,
|
|
|
|
* not per each slot object in ACPI namespace.
|
|
|
|
*/
|
2018-09-27 04:39:28 +08:00
|
|
|
static void enable_slot(struct acpiphp_slot *slot, bool bridge)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct pci_dev *dev;
|
2013-07-14 05:27:25 +08:00
|
|
|
struct pci_bus *bus = slot->bus;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct acpiphp_func *func;
|
|
|
|
|
2018-09-27 04:39:28 +08:00
|
|
|
if (bridge && bus->self && hotplug_is_native(bus->self)) {
|
ACPI / hotplug / PCI: Don't scan bridges managed by native hotplug
When acpiphp re-enumerates a PCI hierarchy because of an ACPI Notify()
event, we should skip bridges managed by native hotplug (pciehp or shpchp).
We don't want to scan below a native hotplug bridge until the hotplug
controller generates a hot-add event.
A typical scenario is a Root Port leading to a Thunderbolt host router that
remains powered off until something is connected to it. See [1] for the
lspci details.
1. Before something is connected, only the Root Port exists. It has
PCI_EXP_SLTCAP_HPC set and pciehp is responsible for hotplug:
00:1b.0 Root Port (HotPlug+)
2. When a USB-C or Thunderbolt device is connected, the Switch in the
Thunderbolt host router is powered up, the Root Port signals a hotplug
add event and pciehp enumerates the Switch:
01:00.0 Switch Upstream Port to [bus 02-39]
02:00.0 Switch Downstream Port to [bus 03] (HotPlug-, to NHI)
02:01.0 Switch Downstream Port to [bus 04-38] (HotPlug+, to Thunderbolt connector)
02:02.0 Switch Downstream Port to [bus 39] (HotPlug-, to xHCI)
The 02:00.0 and 02:02.0 Ports lead to Endpoints that are not powered
up yet. The Ports have PCI_EXP_SLTCAP_HPC cleared, so pciehp doesn't
handle hotplug for them and we assign minimal resources to them.
The 02:01.0 Port has PCI_EXP_SLTCAP_HPC set, so pciehp handles native
hotplug events for it.
3. The BIOS powers up the xHCI controller. If a Thunderbolt device was
connected (not just a USB-C device), it also powers up the NHI. Then
it sends an ACPI Notify() to the Root Port, and acpiphp enumerates the
new device(s):
03:00.0 Thunderbolt Host Controller (NHI) Endpoint
39:00.0 xHCI Endpoint
4. If a Thunderbolt device was connected, the host router firmware uses
the NHI to set up Thunderbolt tunnels and triggers a native hotplug
event (via 02:01.0 in this example). Then pciehp enumerates the new
Thunderbolt devices:
04:00.0 Switch Upstream Port to [bus 05-38]
05:01.0 Switch Downstream Port to [bus 06-09] (HotPlug-)
05:04.0 Switch Downstream Port to [bus 0a-38] (HotPlug+)
In this example, 05:01.0 leads to another Switch and some NICs. This
subtree is static, so 05:01.0 doesn't support hotplug and has
PCI_EXP_SLTCAP_HPC cleared.
In step 3, acpiphp previously enumerated everything below the Root Port,
including things below the 02:01.0 Port. We don't want that because pciehp
expects to manage hotplug below that Port, and firmware on the host router
may be in the middle of configuring its Link so it may not be ready yet.
To make this work better with the native PCIe (pciehp) and standard PCI
(shpchp) hotplug drivers, we let them handle all slot management and
resource allocation for hotplug bridges and restrict ACPI hotplug to
non-hotplug bridges.
[1] https://bugzilla.kernel.org/show_bug.cgi?id=199581#c5
Link: https://lkml.kernel.org/r/20180529160155.1738-1-mika.westerberg@linux.intel.com
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
[bhelgaas: changelog, use hotplug_is_native() instead of
dev->is_hotplug_bridge]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2018-05-30 00:01:55 +08:00
|
|
|
/*
|
|
|
|
* If native hotplug is used, it will take care of hotplug
|
|
|
|
* slot management and resource allocation for hotplug
|
|
|
|
* bridges. However, ACPI hotplug may still be used for
|
|
|
|
* non-hotplug bridges to bring in additional devices such
|
|
|
|
* as a Thunderbolt host controller.
|
|
|
|
*/
|
2017-10-21 04:38:54 +08:00
|
|
|
for_each_pci_bridge(dev, bus) {
|
ACPI / hotplug / PCI: Don't scan bridges managed by native hotplug
When acpiphp re-enumerates a PCI hierarchy because of an ACPI Notify()
event, we should skip bridges managed by native hotplug (pciehp or shpchp).
We don't want to scan below a native hotplug bridge until the hotplug
controller generates a hot-add event.
A typical scenario is a Root Port leading to a Thunderbolt host router that
remains powered off until something is connected to it. See [1] for the
lspci details.
1. Before something is connected, only the Root Port exists. It has
PCI_EXP_SLTCAP_HPC set and pciehp is responsible for hotplug:
00:1b.0 Root Port (HotPlug+)
2. When a USB-C or Thunderbolt device is connected, the Switch in the
Thunderbolt host router is powered up, the Root Port signals a hotplug
add event and pciehp enumerates the Switch:
01:00.0 Switch Upstream Port to [bus 02-39]
02:00.0 Switch Downstream Port to [bus 03] (HotPlug-, to NHI)
02:01.0 Switch Downstream Port to [bus 04-38] (HotPlug+, to Thunderbolt connector)
02:02.0 Switch Downstream Port to [bus 39] (HotPlug-, to xHCI)
The 02:00.0 and 02:02.0 Ports lead to Endpoints that are not powered
up yet. The Ports have PCI_EXP_SLTCAP_HPC cleared, so pciehp doesn't
handle hotplug for them and we assign minimal resources to them.
The 02:01.0 Port has PCI_EXP_SLTCAP_HPC set, so pciehp handles native
hotplug events for it.
3. The BIOS powers up the xHCI controller. If a Thunderbolt device was
connected (not just a USB-C device), it also powers up the NHI. Then
it sends an ACPI Notify() to the Root Port, and acpiphp enumerates the
new device(s):
03:00.0 Thunderbolt Host Controller (NHI) Endpoint
39:00.0 xHCI Endpoint
4. If a Thunderbolt device was connected, the host router firmware uses
the NHI to set up Thunderbolt tunnels and triggers a native hotplug
event (via 02:01.0 in this example). Then pciehp enumerates the new
Thunderbolt devices:
04:00.0 Switch Upstream Port to [bus 05-38]
05:01.0 Switch Downstream Port to [bus 06-09] (HotPlug-)
05:04.0 Switch Downstream Port to [bus 0a-38] (HotPlug+)
In this example, 05:01.0 leads to another Switch and some NICs. This
subtree is static, so 05:01.0 doesn't support hotplug and has
PCI_EXP_SLTCAP_HPC cleared.
In step 3, acpiphp previously enumerated everything below the Root Port,
including things below the 02:01.0 Port. We don't want that because pciehp
expects to manage hotplug below that Port, and firmware on the host router
may be in the middle of configuring its Link so it may not be ready yet.
To make this work better with the native PCIe (pciehp) and standard PCI
(shpchp) hotplug drivers, we let them handle all slot management and
resource allocation for hotplug bridges and restrict ACPI hotplug to
non-hotplug bridges.
[1] https://bugzilla.kernel.org/show_bug.cgi?id=199581#c5
Link: https://lkml.kernel.org/r/20180529160155.1738-1-mika.westerberg@linux.intel.com
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
[bhelgaas: changelog, use hotplug_is_native() instead of
dev->is_hotplug_bridge]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2018-05-30 00:01:55 +08:00
|
|
|
if (PCI_SLOT(dev->devfn) == slot->device)
|
|
|
|
acpiphp_native_scan_bridge(dev);
|
|
|
|
}
|
|
|
|
pci_assign_unassigned_bridge_resources(bus->self);
|
|
|
|
} else {
|
|
|
|
LIST_HEAD(add_list);
|
|
|
|
int max, pass;
|
|
|
|
|
|
|
|
acpiphp_rescan_slot(slot);
|
|
|
|
max = acpiphp_max_busnr(bus);
|
|
|
|
for (pass = 0; pass < 2; pass++) {
|
|
|
|
for_each_pci_bridge(dev, bus) {
|
|
|
|
if (PCI_SLOT(dev->devfn) != slot->device)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
max = pci_scan_bridge(bus, dev, max, pass);
|
|
|
|
if (pass && dev->subordinate) {
|
|
|
|
check_hotplug_bridge(slot, dev);
|
|
|
|
pcibios_resource_survey_bus(dev->subordinate);
|
|
|
|
__pci_bus_size_bridges(dev->subordinate,
|
|
|
|
&add_list);
|
|
|
|
}
|
2005-12-15 01:37:26 +08:00
|
|
|
}
|
2005-04-28 15:25:53 +08:00
|
|
|
}
|
ACPI / hotplug / PCI: Don't scan bridges managed by native hotplug
When acpiphp re-enumerates a PCI hierarchy because of an ACPI Notify()
event, we should skip bridges managed by native hotplug (pciehp or shpchp).
We don't want to scan below a native hotplug bridge until the hotplug
controller generates a hot-add event.
A typical scenario is a Root Port leading to a Thunderbolt host router that
remains powered off until something is connected to it. See [1] for the
lspci details.
1. Before something is connected, only the Root Port exists. It has
PCI_EXP_SLTCAP_HPC set and pciehp is responsible for hotplug:
00:1b.0 Root Port (HotPlug+)
2. When a USB-C or Thunderbolt device is connected, the Switch in the
Thunderbolt host router is powered up, the Root Port signals a hotplug
add event and pciehp enumerates the Switch:
01:00.0 Switch Upstream Port to [bus 02-39]
02:00.0 Switch Downstream Port to [bus 03] (HotPlug-, to NHI)
02:01.0 Switch Downstream Port to [bus 04-38] (HotPlug+, to Thunderbolt connector)
02:02.0 Switch Downstream Port to [bus 39] (HotPlug-, to xHCI)
The 02:00.0 and 02:02.0 Ports lead to Endpoints that are not powered
up yet. The Ports have PCI_EXP_SLTCAP_HPC cleared, so pciehp doesn't
handle hotplug for them and we assign minimal resources to them.
The 02:01.0 Port has PCI_EXP_SLTCAP_HPC set, so pciehp handles native
hotplug events for it.
3. The BIOS powers up the xHCI controller. If a Thunderbolt device was
connected (not just a USB-C device), it also powers up the NHI. Then
it sends an ACPI Notify() to the Root Port, and acpiphp enumerates the
new device(s):
03:00.0 Thunderbolt Host Controller (NHI) Endpoint
39:00.0 xHCI Endpoint
4. If a Thunderbolt device was connected, the host router firmware uses
the NHI to set up Thunderbolt tunnels and triggers a native hotplug
event (via 02:01.0 in this example). Then pciehp enumerates the new
Thunderbolt devices:
04:00.0 Switch Upstream Port to [bus 05-38]
05:01.0 Switch Downstream Port to [bus 06-09] (HotPlug-)
05:04.0 Switch Downstream Port to [bus 0a-38] (HotPlug+)
In this example, 05:01.0 leads to another Switch and some NICs. This
subtree is static, so 05:01.0 doesn't support hotplug and has
PCI_EXP_SLTCAP_HPC cleared.
In step 3, acpiphp previously enumerated everything below the Root Port,
including things below the 02:01.0 Port. We don't want that because pciehp
expects to manage hotplug below that Port, and firmware on the host router
may be in the middle of configuring its Link so it may not be ready yet.
To make this work better with the native PCIe (pciehp) and standard PCI
(shpchp) hotplug drivers, we let them handle all slot management and
resource allocation for hotplug bridges and restrict ACPI hotplug to
non-hotplug bridges.
[1] https://bugzilla.kernel.org/show_bug.cgi?id=199581#c5
Link: https://lkml.kernel.org/r/20180529160155.1738-1-mika.westerberg@linux.intel.com
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
[bhelgaas: changelog, use hotplug_is_native() instead of
dev->is_hotplug_bridge]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2018-05-30 00:01:55 +08:00
|
|
|
__pci_bus_assign_resources(bus, &add_list, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2013-09-06 21:41:32 +08:00
|
|
|
|
2005-10-19 08:21:40 +08:00
|
|
|
acpiphp_sanitize_bus(bus);
|
2014-08-29 01:59:41 +08:00
|
|
|
pcie_bus_configure_settings(bus);
|
2010-02-25 10:59:34 +08:00
|
|
|
acpiphp_set_acpi_region(slot);
|
2011-05-12 00:00:32 +08:00
|
|
|
|
|
|
|
list_for_each_entry(dev, &bus->devices, bus_list) {
|
|
|
|
/* Assume that newly added devices are powered on already. */
|
2018-07-03 17:05:41 +08:00
|
|
|
if (!pci_dev_is_added(dev))
|
2011-05-12 00:00:32 +08:00
|
|
|
dev->current_state = PCI_D0;
|
|
|
|
}
|
|
|
|
|
2005-04-28 15:25:53 +08: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 15:03:07 +08:00
|
|
|
slot->flags |= SLOT_ENABLED;
|
2009-10-27 11:25:27 +08:00
|
|
|
list_for_each_entry(func, &slot->funcs, sibling) {
|
2009-05-22 06:21:15 +08: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 15:03:07 +08:00
|
|
|
if (!dev) {
|
|
|
|
/* Do not set SLOT_ENABLED flag if some funcs
|
|
|
|
are not added. */
|
2018-05-25 02:25:15 +08:00
|
|
|
slot->flags &= ~SLOT_ENABLED;
|
2006-03-22 13:49:20 +08: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 15:03:07 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-14 05:27:26 +08:00
|
|
|
* disable_slot - disable a slot
|
2007-11-29 01:04:30 +08:00
|
|
|
* @slot: ACPI PHP slot
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2013-07-14 05:27:26 +08:00
|
|
|
static void disable_slot(struct acpiphp_slot *slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-02-04 07:37:02 +08:00
|
|
|
struct pci_bus *bus = slot->bus;
|
|
|
|
struct pci_dev *dev, *prev;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct acpiphp_func *func;
|
2006-03-22 13:49:20 +08:00
|
|
|
|
2012-05-24 00:20:35 +08:00
|
|
|
/*
|
2013-07-14 05:27:26 +08:00
|
|
|
* enable_slot() enumerates all functions in this device via
|
2012-05-24 00:20:35 +08:00
|
|
|
* pci_scan_slot(), whether they have associated ACPI hotplug
|
|
|
|
* methods (_EJ0, etc.) or not. Therefore, we remove all functions
|
|
|
|
* here.
|
|
|
|
*/
|
2014-02-04 07:37:02 +08:00
|
|
|
list_for_each_entry_safe_reverse(dev, prev, &bus->devices, bus_list)
|
|
|
|
if (PCI_SLOT(dev->devfn) == slot->device)
|
|
|
|
pci_stop_and_remove_bus_device(dev);
|
2006-09-13 01:22:53 +08:00
|
|
|
|
2013-07-14 05:27:25 +08:00
|
|
|
list_for_each_entry(func, &slot->funcs, sibling)
|
2014-02-04 07:39:33 +08:00
|
|
|
acpi_bus_trim(func_to_acpi_device(func));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-05-25 02:25:15 +08:00
|
|
|
slot->flags &= ~SLOT_ENABLED;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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 20:39:42 +08:00
|
|
|
static bool slot_no_hotplug(struct acpiphp_slot *slot)
|
|
|
|
{
|
PCI: Add pci_ignore_hotplug() to ignore hotplug events for a device
Powering off a hot-pluggable device, e.g., with pci_set_power_state(D3cold),
normally generates a hot-remove event that unbinds the driver.
Some drivers expect to remain bound to a device even while they power it
off and back on again. This can be dangerous, because if the device is
removed or replaced while it is powered off, the driver doesn't know that
anything changed. But some drivers accept that risk.
Add pci_ignore_hotplug() for use by drivers that know their device cannot
be removed. Using pci_ignore_hotplug() tells the PCI core that hot-plug
events for the device should be ignored.
The radeon and nouveau drivers use this to switch between a low-power,
integrated GPU and a higher-power, higher-performance discrete GPU. They
power off the unused GPU, but they want to remain bound to it.
This is a reimplementation of f244d8b623da ("ACPIPHP / radeon / nouveau:
Fix VGA switcheroo problem related to hotplug") but extends it to work with
both acpiphp and pciehp.
This fixes a problem where systems with dual GPUs using the radeon drivers
become unusable, freezing every few seconds (see bugzillas below). The
resume of the radeon device may also fail, e.g.,
This fixes problems on dual GPU systems where the radeon driver becomes
unusable because of problems while suspending the device, as in bug 79701:
[drm] radeon: finishing device.
radeon 0000:01:00.0: Userspace still has active objects !
radeon 0000:01:00.0: ffff8800cb4ec288 ffff8800cb4ec000 16384 4294967297 force free
...
WARNING: CPU: 0 PID: 67 at /home/apw/COD/linux/drivers/gpu/drm/radeon/radeon_gart.c:234 radeon_gart_unbind+0xd2/0xe0 [radeon]()
trying to unbind memory from uninitialized GART !
or while resuming it, as in bug 77261:
radeon 0000:01:00.0: ring 0 stalled for more than 10158msec
radeon 0000:01:00.0: GPU lockup ...
radeon 0000:01:00.0: GPU pci config reset
pciehp 0000:00:01.0:pcie04: Card not present on Slot(1-1)
radeon 0000:01:00.0: GPU reset succeeded, trying to resume
*ERROR* radeon: dpm resume failed
radeon 0000:01:00.0: Wait for MC idle timedout !
Link: https://bugzilla.kernel.org/show_bug.cgi?id=77261
Link: https://bugzilla.kernel.org/show_bug.cgi?id=79701
Reported-by: Shawn Starr <shawn.starr@rogers.com>
Reported-by: Jose P. <lbdkmjdf@sharklasers.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Rajat Jain <rajatxjain@gmail.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Dave Airlie <airlied@redhat.com>
CC: stable@vger.kernel.org # v3.15+
2014-09-11 03:45:01 +08:00
|
|
|
struct pci_bus *bus = slot->bus;
|
|
|
|
struct pci_dev *dev;
|
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 20:39:42 +08:00
|
|
|
|
PCI: Add pci_ignore_hotplug() to ignore hotplug events for a device
Powering off a hot-pluggable device, e.g., with pci_set_power_state(D3cold),
normally generates a hot-remove event that unbinds the driver.
Some drivers expect to remain bound to a device even while they power it
off and back on again. This can be dangerous, because if the device is
removed or replaced while it is powered off, the driver doesn't know that
anything changed. But some drivers accept that risk.
Add pci_ignore_hotplug() for use by drivers that know their device cannot
be removed. Using pci_ignore_hotplug() tells the PCI core that hot-plug
events for the device should be ignored.
The radeon and nouveau drivers use this to switch between a low-power,
integrated GPU and a higher-power, higher-performance discrete GPU. They
power off the unused GPU, but they want to remain bound to it.
This is a reimplementation of f244d8b623da ("ACPIPHP / radeon / nouveau:
Fix VGA switcheroo problem related to hotplug") but extends it to work with
both acpiphp and pciehp.
This fixes a problem where systems with dual GPUs using the radeon drivers
become unusable, freezing every few seconds (see bugzillas below). The
resume of the radeon device may also fail, e.g.,
This fixes problems on dual GPU systems where the radeon driver becomes
unusable because of problems while suspending the device, as in bug 79701:
[drm] radeon: finishing device.
radeon 0000:01:00.0: Userspace still has active objects !
radeon 0000:01:00.0: ffff8800cb4ec288 ffff8800cb4ec000 16384 4294967297 force free
...
WARNING: CPU: 0 PID: 67 at /home/apw/COD/linux/drivers/gpu/drm/radeon/radeon_gart.c:234 radeon_gart_unbind+0xd2/0xe0 [radeon]()
trying to unbind memory from uninitialized GART !
or while resuming it, as in bug 77261:
radeon 0000:01:00.0: ring 0 stalled for more than 10158msec
radeon 0000:01:00.0: GPU lockup ...
radeon 0000:01:00.0: GPU pci config reset
pciehp 0000:00:01.0:pcie04: Card not present on Slot(1-1)
radeon 0000:01:00.0: GPU reset succeeded, trying to resume
*ERROR* radeon: dpm resume failed
radeon 0000:01:00.0: Wait for MC idle timedout !
Link: https://bugzilla.kernel.org/show_bug.cgi?id=77261
Link: https://bugzilla.kernel.org/show_bug.cgi?id=79701
Reported-by: Shawn Starr <shawn.starr@rogers.com>
Reported-by: Jose P. <lbdkmjdf@sharklasers.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Rajat Jain <rajatxjain@gmail.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Dave Airlie <airlied@redhat.com>
CC: stable@vger.kernel.org # v3.15+
2014-09-11 03:45:01 +08:00
|
|
|
list_for_each_entry(dev, &bus->devices, bus_list) {
|
|
|
|
if (PCI_SLOT(dev->devfn) == slot->device && dev->ignore_hotplug)
|
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 20:39:42 +08:00
|
|
|
return true;
|
PCI: Add pci_ignore_hotplug() to ignore hotplug events for a device
Powering off a hot-pluggable device, e.g., with pci_set_power_state(D3cold),
normally generates a hot-remove event that unbinds the driver.
Some drivers expect to remain bound to a device even while they power it
off and back on again. This can be dangerous, because if the device is
removed or replaced while it is powered off, the driver doesn't know that
anything changed. But some drivers accept that risk.
Add pci_ignore_hotplug() for use by drivers that know their device cannot
be removed. Using pci_ignore_hotplug() tells the PCI core that hot-plug
events for the device should be ignored.
The radeon and nouveau drivers use this to switch between a low-power,
integrated GPU and a higher-power, higher-performance discrete GPU. They
power off the unused GPU, but they want to remain bound to it.
This is a reimplementation of f244d8b623da ("ACPIPHP / radeon / nouveau:
Fix VGA switcheroo problem related to hotplug") but extends it to work with
both acpiphp and pciehp.
This fixes a problem where systems with dual GPUs using the radeon drivers
become unusable, freezing every few seconds (see bugzillas below). The
resume of the radeon device may also fail, e.g.,
This fixes problems on dual GPU systems where the radeon driver becomes
unusable because of problems while suspending the device, as in bug 79701:
[drm] radeon: finishing device.
radeon 0000:01:00.0: Userspace still has active objects !
radeon 0000:01:00.0: ffff8800cb4ec288 ffff8800cb4ec000 16384 4294967297 force free
...
WARNING: CPU: 0 PID: 67 at /home/apw/COD/linux/drivers/gpu/drm/radeon/radeon_gart.c:234 radeon_gart_unbind+0xd2/0xe0 [radeon]()
trying to unbind memory from uninitialized GART !
or while resuming it, as in bug 77261:
radeon 0000:01:00.0: ring 0 stalled for more than 10158msec
radeon 0000:01:00.0: GPU lockup ...
radeon 0000:01:00.0: GPU pci config reset
pciehp 0000:00:01.0:pcie04: Card not present on Slot(1-1)
radeon 0000:01:00.0: GPU reset succeeded, trying to resume
*ERROR* radeon: dpm resume failed
radeon 0000:01:00.0: Wait for MC idle timedout !
Link: https://bugzilla.kernel.org/show_bug.cgi?id=77261
Link: https://bugzilla.kernel.org/show_bug.cgi?id=79701
Reported-by: Shawn Starr <shawn.starr@rogers.com>
Reported-by: Jose P. <lbdkmjdf@sharklasers.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Rajat Jain <rajatxjain@gmail.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Dave Airlie <airlied@redhat.com>
CC: stable@vger.kernel.org # v3.15+
2014-09-11 03:45:01 +08:00
|
|
|
}
|
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 20:39:42 +08:00
|
|
|
return false;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get_slot_status - get ACPI slot status
|
2007-11-29 01:04:30 +08:00
|
|
|
* @slot: ACPI PHP slot
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2007-11-29 01:04:30 +08:00
|
|
|
* If a slot has _STA for each function and if any one of them
|
|
|
|
* returned non-zero status, return it.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2007-11-29 01:04:30 +08: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 06:20:36 +08:00
|
|
|
*
|
2007-11-29 01:04:30 +08:00
|
|
|
* Otherwise return 0.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static unsigned int get_slot_status(struct acpiphp_slot *slot)
|
|
|
|
{
|
2008-10-10 14:22:59 +08:00
|
|
|
unsigned long long sta = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct acpiphp_func *func;
|
2018-02-12 18:55:23 +08:00
|
|
|
u32 dvid;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-10-27 11:25:27 +08:00
|
|
|
list_for_each_entry(func, &slot->funcs, sibling) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (func->flags & FUNC_HAS_STA) {
|
2013-07-14 05:27:25 +08:00
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
status = acpi_evaluate_integer(func_to_handle(func),
|
|
|
|
"_STA", NULL, &sta);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ACPI_SUCCESS(status) && sta)
|
|
|
|
break;
|
|
|
|
} else {
|
2018-02-12 18:55:23 +08:00
|
|
|
if (pci_bus_read_dev_vendor_id(slot->bus,
|
|
|
|
PCI_DEVFN(slot->device, func->function),
|
|
|
|
&dvid, 0)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
sta = ACPI_STA_ALL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-12 18:55:23 +08:00
|
|
|
if (!sta) {
|
|
|
|
/*
|
|
|
|
* Check for the slot itself since it may be that the
|
|
|
|
* ACPI slot is a device below PCIe upstream port so in
|
|
|
|
* that case it may not even be reachable yet.
|
|
|
|
*/
|
|
|
|
if (pci_bus_read_dev_vendor_id(slot->bus,
|
|
|
|
PCI_DEVFN(slot->device, 0), &dvid, 0)) {
|
|
|
|
sta = ACPI_STA_ALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return (unsigned int)sta;
|
|
|
|
}
|
|
|
|
|
2014-02-11 18:42:37 +08:00
|
|
|
static inline bool device_status_valid(unsigned int sta)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* ACPI spec says that _STA may return bit 0 clear with bit 3 set
|
|
|
|
* if the device is valid but does not require a device driver to be
|
|
|
|
* loaded (Section 6.3.7 of ACPI 5.0A).
|
|
|
|
*/
|
|
|
|
unsigned int mask = ACPI_STA_DEVICE_ENABLED | ACPI_STA_DEVICE_FUNCTIONING;
|
|
|
|
return (sta & mask) == mask;
|
|
|
|
}
|
|
|
|
|
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 04:10:35 +08: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)
|
|
|
|
{
|
2014-02-04 07:38:52 +08:00
|
|
|
struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
|
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 04:10:35 +08:00
|
|
|
struct pci_bus *bus = dev->subordinate;
|
2015-05-20 08:14:13 +08:00
|
|
|
bool alive = dev->ignore_hotplug;
|
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 04:10:35 +08:00
|
|
|
|
2014-02-04 07:38:52 +08:00
|
|
|
if (adev) {
|
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 04:10:35 +08:00
|
|
|
acpi_status status;
|
|
|
|
unsigned long long sta;
|
|
|
|
|
2014-02-04 07:39:20 +08:00
|
|
|
status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
|
2015-05-20 08:14:13 +08:00
|
|
|
alive = alive || (ACPI_SUCCESS(status) && device_status_valid(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 04:10:35 +08:00
|
|
|
}
|
2014-03-04 07:48:57 +08:00
|
|
|
if (!alive)
|
|
|
|
alive = pci_device_is_present(dev);
|
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 04:10:35 +08:00
|
|
|
|
|
|
|
if (!alive) {
|
2018-05-30 00:02:23 +08:00
|
|
|
pci_dev_set_disconnected(dev, NULL);
|
|
|
|
if (pci_has_subordinate(dev))
|
|
|
|
pci_walk_bus(dev->subordinate, pci_dev_set_disconnected,
|
|
|
|
NULL);
|
|
|
|
|
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 04:10:35 +08:00
|
|
|
pci_stop_and_remove_bus_device(dev);
|
2014-02-04 07:38:52 +08:00
|
|
|
if (adev)
|
|
|
|
acpi_bus_trim(adev);
|
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 04:10:35 +08:00
|
|
|
} 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 09:22:07 +08: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 04:10:35 +08:00
|
|
|
trim_stale_devices(child);
|
|
|
|
|
|
|
|
pm_runtime_put(&dev->dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* acpiphp_check_bridge - re-enumerate devices
|
2007-11-29 01:04:30 +08:00
|
|
|
* @bridge: where to begin re-enumeration
|
2005-04-17 06:20:36 +08: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 04:10:35 +08:00
|
|
|
static void acpiphp_check_bridge(struct acpiphp_bridge *bridge)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct acpiphp_slot *slot;
|
|
|
|
|
2014-01-10 22:24:41 +08:00
|
|
|
/* Bail out if the bridge is going away. */
|
|
|
|
if (bridge->is_going_away)
|
|
|
|
return;
|
|
|
|
|
2016-08-05 08:38:44 +08:00
|
|
|
if (bridge->pci_dev)
|
|
|
|
pm_runtime_get_sync(&bridge->pci_dev->dev);
|
|
|
|
|
2013-04-12 13:44:27 +08: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 04:10:35 +08:00
|
|
|
struct pci_bus *bus = slot->bus;
|
|
|
|
struct pci_dev *dev, *tmp;
|
|
|
|
|
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 20:39:42 +08:00
|
|
|
if (slot_no_hotplug(slot)) {
|
|
|
|
; /* do nothing */
|
2014-02-11 18:42:37 +08:00
|
|
|
} else if (device_status_valid(get_slot_status(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 04:10:35 +08:00
|
|
|
/* remove stale devices if any */
|
2014-02-03 09:22:07 +08: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 04:10:35 +08:00
|
|
|
if (PCI_SLOT(dev->devfn) == slot->device)
|
|
|
|
trim_stale_devices(dev);
|
|
|
|
|
|
|
|
/* configure all functions */
|
2018-09-27 04:39:28 +08:00
|
|
|
enable_slot(slot, true);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2013-07-14 05:27:26 +08:00
|
|
|
disable_slot(slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2016-08-05 08:38:44 +08:00
|
|
|
|
|
|
|
if (bridge->pci_dev)
|
|
|
|
pm_runtime_put(&bridge->pci_dev->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-04-28 15:25:56 +08: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 13:44:17 +08:00
|
|
|
struct pci_dev *dev, *tmp;
|
2005-04-28 15:25:56 +08:00
|
|
|
int i;
|
|
|
|
unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
|
|
|
|
|
2014-02-03 09:22:07 +08:00
|
|
|
list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list) {
|
2015-12-28 05:21:11 +08:00
|
|
|
for (i = 0; i < PCI_BRIDGE_RESOURCES; i++) {
|
2005-04-28 15:25:56 +08:00
|
|
|
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 05:54:20 +08:00
|
|
|
pci_stop_and_remove_bus_device(dev);
|
2005-04-28 15:25:56 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* ACPI event handlers
|
|
|
|
*/
|
|
|
|
|
2014-02-04 07:45:13 +08:00
|
|
|
void acpiphp_check_host_bridge(struct acpi_device *adev)
|
2013-05-08 01:06:03 +08:00
|
|
|
{
|
2014-07-16 04:03:14 +08:00
|
|
|
struct acpiphp_bridge *bridge = NULL;
|
2013-05-08 01:06:03 +08:00
|
|
|
|
2014-07-16 04:03:14 +08:00
|
|
|
acpi_lock_hp_context();
|
|
|
|
if (adev->hp) {
|
|
|
|
bridge = to_acpiphp_root_context(adev->hp)->root_bridge;
|
|
|
|
if (bridge)
|
|
|
|
get_bridge(bridge);
|
|
|
|
}
|
|
|
|
acpi_unlock_hp_context();
|
2013-05-08 01:06:03 +08:00
|
|
|
if (bridge) {
|
2014-02-03 09:22:27 +08:00
|
|
|
pci_lock_rescan_remove();
|
|
|
|
|
2013-05-08 01:06:03 +08:00
|
|
|
acpiphp_check_bridge(bridge);
|
2014-02-03 09:22:27 +08:00
|
|
|
|
|
|
|
pci_unlock_rescan_remove();
|
2013-05-08 01:06:03 +08:00
|
|
|
put_bridge(bridge);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 22:24:41 +08:00
|
|
|
static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot);
|
|
|
|
|
2014-02-04 07:42:20 +08:00
|
|
|
static void hotplug_event(u32 type, struct acpiphp_context *context)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-02-07 00:31:37 +08:00
|
|
|
acpi_handle handle = context->hp.self->handle;
|
2013-07-14 05:27:25 +08:00
|
|
|
struct acpiphp_func *func = &context->func;
|
2014-02-04 07:40:46 +08:00
|
|
|
struct acpiphp_slot *slot = func->slot;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct acpiphp_bridge *bridge;
|
2011-09-29 07:40:53 +08:00
|
|
|
|
2014-02-04 07:43:17 +08:00
|
|
|
acpi_lock_hp_context();
|
2013-07-14 05:27:24 +08:00
|
|
|
bridge = context->bridge;
|
2013-07-14 05:27:24 +08:00
|
|
|
if (bridge)
|
|
|
|
get_bridge(bridge);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-02-04 07:43:17 +08:00
|
|
|
acpi_unlock_hp_context();
|
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 21:36:47 +08:00
|
|
|
|
2014-02-03 09:22:17 +08:00
|
|
|
pci_lock_rescan_remove();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ACPI_NOTIFY_BUS_CHECK:
|
|
|
|
/* bus re-enumerate */
|
2014-02-04 07:41:52 +08:00
|
|
|
acpi_handle_debug(handle, "Bus check in %s()\n", __func__);
|
2014-02-04 07:40:46 +08:00
|
|
|
if (bridge)
|
2013-07-14 05:27:24 +08:00
|
|
|
acpiphp_check_bridge(bridge);
|
2014-02-04 07:40:46 +08:00
|
|
|
else if (!(slot->flags & SLOT_IS_GOING_AWAY))
|
2018-09-27 04:39:28 +08:00
|
|
|
enable_slot(slot, false);
|
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 04:10:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_NOTIFY_DEVICE_CHECK:
|
|
|
|
/* device check */
|
2014-02-04 07:41:52 +08:00
|
|
|
acpi_handle_debug(handle, "Device check in %s()\n", __func__);
|
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 06:07:28 +08:00
|
|
|
if (bridge) {
|
2013-07-14 05:27:24 +08:00
|
|
|
acpiphp_check_bridge(bridge);
|
2014-02-04 07:40:46 +08:00
|
|
|
} else if (!(slot->flags & SLOT_IS_GOING_AWAY)) {
|
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 06:07:28 +08:00
|
|
|
/*
|
|
|
|
* Check if anything has changed in the slot and rescan
|
|
|
|
* from the parent if that's the case.
|
|
|
|
*/
|
2014-02-04 07:40:25 +08:00
|
|
|
if (acpiphp_rescan_slot(slot))
|
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 06:07:28 +08:00
|
|
|
acpiphp_check_bridge(func->parent);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_NOTIFY_EJECT_REQUEST:
|
|
|
|
/* request device eject */
|
2014-02-04 07:41:52 +08:00
|
|
|
acpi_handle_debug(handle, "Eject request in %s()\n", __func__);
|
2014-02-04 07:40:46 +08:00
|
|
|
acpiphp_disable_and_eject_slot(slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-09-29 07:40:53 +08:00
|
|
|
|
2014-02-03 09:22:17 +08:00
|
|
|
pci_unlock_rescan_remove();
|
2013-07-14 05:27:24 +08: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 17:22:53 +08:00
|
|
|
}
|
|
|
|
|
2014-02-21 08:10:27 +08:00
|
|
|
static int acpiphp_hotplug_notify(struct acpi_device *adev, u32 type)
|
2011-09-29 07:40:53 +08:00
|
|
|
{
|
2013-07-14 05:27:24 +08:00
|
|
|
struct acpiphp_context *context;
|
|
|
|
|
2014-02-21 08:10:18 +08:00
|
|
|
context = acpiphp_grab_context(adev);
|
|
|
|
if (!context)
|
2014-02-07 00:31:37 +08:00
|
|
|
return -ENODATA;
|
2014-02-04 05:30:06 +08:00
|
|
|
|
2014-02-07 00:31:37 +08:00
|
|
|
hotplug_event(type, context);
|
2014-02-21 08:10:18 +08:00
|
|
|
acpiphp_let_context_go(context);
|
2014-02-07 00:31:37 +08:00
|
|
|
return 0;
|
2005-04-28 15:25:56 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-02-04 07:37:35 +08:00
|
|
|
/**
|
|
|
|
* acpiphp_enumerate_slots - Enumerate PCI slots for a given bus.
|
|
|
|
* @bus: PCI bus to enumerate the slots for.
|
|
|
|
*
|
|
|
|
* A "slot" is an object associated with a PCI device number. All functions
|
|
|
|
* (PCI devices) with the same bus and device number belong to the same slot.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2013-07-14 05:27:23 +08:00
|
|
|
void acpiphp_enumerate_slots(struct pci_bus *bus)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-04-12 13:44:26 +08:00
|
|
|
struct acpiphp_bridge *bridge;
|
2014-02-04 07:39:33 +08:00
|
|
|
struct acpi_device *adev;
|
2013-07-14 05:27:23 +08:00
|
|
|
acpi_handle handle;
|
|
|
|
acpi_status status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-04-12 13:44:26 +08:00
|
|
|
if (acpiphp_disabled)
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-02-04 07:39:33 +08:00
|
|
|
adev = ACPI_COMPANION(bus->bridge);
|
|
|
|
if (!adev)
|
2013-04-12 13:44:26 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-02-04 07:39:33 +08:00
|
|
|
handle = adev->handle;
|
2013-04-12 13:44:26 +08:00
|
|
|
bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
|
PCI: Remove unnecessary messages for memory allocation failures
Per ebfdc40969f2 ("checkpatch: attempt to find unnecessary 'out of memory'
messages"), when a memory allocation fails, the memory subsystem emits
generic "out of memory" messages (see slab_out_of_memory() for some of this
logging). Therefore, additional error messages in the caller don't add
much value.
Remove messages that merely report "out of memory".
This preserves some messages that report additional information, e.g.,
allocation failures that mean we drop hotplug events.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
[bhelgaas: changelog, squash patches, make similar changes to acpiphp,
cpqphp, ibmphp, keep warning when dropping hotplug event]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2017-12-29 19:15:16 +08:00
|
|
|
if (!bridge)
|
2013-04-12 13:44:26 +08:00
|
|
|
return;
|
|
|
|
|
2013-04-12 13:44:27 +08:00
|
|
|
INIT_LIST_HEAD(&bridge->slots);
|
2013-04-12 13:44:28 +08:00
|
|
|
kref_init(&bridge->ref);
|
2013-04-12 13:44:26 +08: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);
|
|
|
|
|
2014-06-11 04:46:35 +08:00
|
|
|
acpi_lock_hp_context();
|
|
|
|
if (pci_is_root_bus(bridge->pci_bus)) {
|
|
|
|
struct acpiphp_root_context *root_context;
|
|
|
|
|
|
|
|
root_context = kzalloc(sizeof(*root_context), GFP_KERNEL);
|
|
|
|
if (!root_context)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
root_context->root_bridge = bridge;
|
2014-07-16 04:03:22 +08:00
|
|
|
acpi_set_hp_context(adev, &root_context->hp);
|
2014-06-11 04:46:35 +08:00
|
|
|
} else {
|
2013-07-14 05:27:24 +08:00
|
|
|
struct acpiphp_context *context;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This bridge should have been registered as a hotplug function
|
2013-10-12 07:49:48 +08: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 05:27:24 +08:00
|
|
|
*/
|
2014-02-07 00:31:37 +08:00
|
|
|
context = acpiphp_get_context(adev);
|
2014-06-11 04:46:35 +08:00
|
|
|
if (!context)
|
|
|
|
goto err;
|
|
|
|
|
2013-07-14 05:27:24 +08:00
|
|
|
bridge->context = context;
|
|
|
|
context->bridge = bridge;
|
|
|
|
/* Get a reference to the parent bridge. */
|
2013-07-14 05:27:25 +08:00
|
|
|
get_bridge(context->func.parent);
|
2013-07-14 05:27:24 +08:00
|
|
|
}
|
2014-06-11 04:46:35 +08:00
|
|
|
acpi_unlock_hp_context();
|
2013-07-14 05:27:24 +08:00
|
|
|
|
2014-02-16 07:12:00 +08:00
|
|
|
/* Must be added to the list prior to calling acpiphp_add_context(). */
|
2013-07-14 05:27:23 +08:00
|
|
|
mutex_lock(&bridge_mutex);
|
|
|
|
list_add(&bridge->list, &bridge_list);
|
|
|
|
mutex_unlock(&bridge_mutex);
|
|
|
|
|
|
|
|
/* register all slot objects under this bridge */
|
2013-07-14 05:27:25 +08:00
|
|
|
status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
|
2014-02-16 07:12:00 +08:00
|
|
|
acpiphp_add_context, NULL, bridge, NULL);
|
2013-07-14 05:27:23 +08:00
|
|
|
if (ACPI_FAILURE(status)) {
|
2013-07-14 05:27:25 +08:00
|
|
|
acpi_handle_err(handle, "failed to register slots\n");
|
2013-07-14 05:27:24 +08:00
|
|
|
cleanup_bridge(bridge);
|
|
|
|
put_bridge(bridge);
|
2013-07-14 05:27:23 +08:00
|
|
|
}
|
2014-06-11 04:46:35 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
acpi_unlock_hp_context();
|
|
|
|
put_device(&bus->dev);
|
|
|
|
pci_dev_put(bridge->pci_dev);
|
|
|
|
kfree(bridge);
|
|
|
|
}
|
|
|
|
|
2014-07-20 13:34:43 +08:00
|
|
|
static void acpiphp_drop_bridge(struct acpiphp_bridge *bridge)
|
2014-06-11 04:46:35 +08:00
|
|
|
{
|
|
|
|
if (pci_is_root_bus(bridge->pci_bus)) {
|
|
|
|
struct acpiphp_root_context *root_context;
|
|
|
|
struct acpi_device *adev;
|
|
|
|
|
|
|
|
acpi_lock_hp_context();
|
|
|
|
adev = ACPI_COMPANION(bridge->pci_bus->bridge);
|
|
|
|
root_context = to_acpiphp_root_context(adev->hp);
|
|
|
|
adev->hp = NULL;
|
|
|
|
acpi_unlock_hp_context();
|
|
|
|
kfree(root_context);
|
|
|
|
}
|
|
|
|
cleanup_bridge(bridge);
|
|
|
|
put_bridge(bridge);
|
2013-04-12 13:44:26 +08:00
|
|
|
}
|
|
|
|
|
2014-02-04 07:37:35 +08:00
|
|
|
/**
|
|
|
|
* acpiphp_remove_slots - Remove slot objects associated with a given bus.
|
|
|
|
* @bus: PCI bus to remove the slot objects for.
|
|
|
|
*/
|
2013-04-12 13:44:26 +08:00
|
|
|
void acpiphp_remove_slots(struct pci_bus *bus)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-07-14 05:27:26 +08:00
|
|
|
struct acpiphp_bridge *bridge;
|
2013-04-12 13:44:26 +08:00
|
|
|
|
|
|
|
if (acpiphp_disabled)
|
|
|
|
return;
|
|
|
|
|
2013-07-14 05:27:26 +08:00
|
|
|
mutex_lock(&bridge_mutex);
|
|
|
|
list_for_each_entry(bridge, &bridge_list, list)
|
2013-04-12 13:44:26 +08:00
|
|
|
if (bridge->pci_bus == bus) {
|
2013-07-14 05:27:26 +08:00
|
|
|
mutex_unlock(&bridge_mutex);
|
2014-06-11 04:46:35 +08:00
|
|
|
acpiphp_drop_bridge(bridge);
|
2013-07-14 05:27:26 +08:00
|
|
|
return;
|
2013-04-12 13:44:26 +08:00
|
|
|
}
|
2013-07-14 05:27:26 +08:00
|
|
|
|
|
|
|
mutex_unlock(&bridge_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* acpiphp_enable_slot - power on slot
|
2007-11-29 01:04:30 +08:00
|
|
|
* @slot: ACPI PHP slot
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
int acpiphp_enable_slot(struct acpiphp_slot *slot)
|
|
|
|
{
|
2014-01-10 22:24:41 +08:00
|
|
|
pci_lock_rescan_remove();
|
|
|
|
|
2016-01-24 04:44:19 +08:00
|
|
|
if (slot->flags & SLOT_IS_GOING_AWAY) {
|
|
|
|
pci_unlock_rescan_remove();
|
2014-01-10 22:24:41 +08:00
|
|
|
return -ENODEV;
|
2016-01-24 04:44:19 +08:00
|
|
|
}
|
2014-01-10 22:24:41 +08:00
|
|
|
|
2013-07-14 05:27:26 +08:00
|
|
|
/* configure all functions */
|
2013-07-14 05:27:26 +08:00
|
|
|
if (!(slot->flags & SLOT_ENABLED))
|
2018-09-27 04:39:28 +08:00
|
|
|
enable_slot(slot, false);
|
2013-07-14 05:27:26 +08:00
|
|
|
|
2014-01-10 22:24:41 +08:00
|
|
|
pci_unlock_rescan_remove();
|
2013-07-14 05:27:26 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-14 05:27:26 +08:00
|
|
|
* acpiphp_disable_and_eject_slot - power off and eject slot
|
2007-11-29 01:04:30 +08:00
|
|
|
* @slot: ACPI PHP slot
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2014-01-10 22:24:41 +08:00
|
|
|
static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-07-14 05:27:26 +08:00
|
|
|
struct acpiphp_func *func;
|
2014-01-10 22:24:41 +08:00
|
|
|
|
|
|
|
if (slot->flags & SLOT_IS_GOING_AWAY)
|
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* unconfigure all functions */
|
2013-07-14 05:27:26 +08:00
|
|
|
disable_slot(slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-07-14 05:27:26 +08: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;
|
|
|
|
}
|
|
|
|
|
2014-01-10 22:24:41 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-01-10 22:24:41 +08:00
|
|
|
int acpiphp_disable_slot(struct acpiphp_slot *slot)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2014-02-10 20:36:26 +08:00
|
|
|
/*
|
|
|
|
* Acquire acpi_scan_lock to ensure that the execution of _EJ0 in
|
|
|
|
* acpiphp_disable_and_eject_slot() will be synchronized properly.
|
|
|
|
*/
|
|
|
|
acpi_scan_lock_acquire();
|
2014-01-10 22:24:41 +08:00
|
|
|
pci_lock_rescan_remove();
|
|
|
|
ret = acpiphp_disable_and_eject_slot(slot);
|
|
|
|
pci_unlock_rescan_remove();
|
2014-02-10 20:36:26 +08:00
|
|
|
acpi_scan_lock_release();
|
2014-01-10 22:24:41 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* slot enabled: 1
|
|
|
|
* slot disabled: 0
|
|
|
|
*/
|
|
|
|
u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
|
|
|
|
{
|
2013-07-14 05:27:26 +08:00
|
|
|
return (slot->flags & SLOT_ENABLED);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-10-26 02:44:57 +08:00
|
|
|
* latch open: 1
|
|
|
|
* latch closed: 0
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
|
|
|
|
{
|
2013-07-14 05:27:26 +08:00
|
|
|
return !(get_slot_status(slot) & ACPI_STA_DEVICE_UI);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* adapter presence : 1
|
|
|
|
* absence : 0
|
|
|
|
*/
|
|
|
|
u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
|
|
|
|
{
|
2013-07-14 05:27:26 +08:00
|
|
|
return !!get_slot_status(slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|