blob: 68c3809ed7ceaac4c8c3e070832f79653ba7039a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ACPI PCI HotPlug glue functions to ACPI CA subsystem
3 *
4 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
5 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
6 * Copyright (C) 2002,2003 NEC Corporation
Rajesh Shah42f49a62005-04-28 00:25:53 -07007 * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
8 * Copyright (C) 2003-2005 Hewlett Packard
Rajesh Shah8e7561c2005-04-28 00:25:56 -07009 * Copyright (C) 2005 Rajesh Shah (rajesh.shah@intel.com)
10 * Copyright (C) 2005 Intel Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
12 * All rights reserved.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or (at
17 * your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
22 * NON INFRINGEMENT. See the GNU General Public License for more
23 * details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
Kristen Carlson Accardi998be202006-07-26 10:52:33 -070029 * Send feedback to <kristen.c.accardi@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 *
31 */
32
Rajesh Shah42f49a62005-04-28 00:25:53 -070033/*
34 * Lifetime rules for pci_dev:
Rajesh Shah42f49a62005-04-28 00:25:53 -070035 * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot()
36 * when the bridge is scanned and it loses a refcount when the bridge
37 * is removed.
Alex Chiang5d4a4b22009-03-30 10:50:14 -060038 * - When a P2P bridge is present, we elevate the refcount on the subordinate
39 * bus. It loses the refcount when the the driver unloads.
Rajesh Shah42f49a62005-04-28 00:25:53 -070040 */
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/init.h>
43#include <linux/module.h>
44
45#include <linux/kernel.h>
46#include <linux/pci.h>
Greg Kroah-Hartman7a54f252006-10-13 20:05:19 -070047#include <linux/pci_hotplug.h>
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +090048#include <linux/pci-acpi.h>
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +010049#include <linux/mutex.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090050#include <linux/slab.h>
Prarit Bhargava6af8bef2011-09-28 19:40:53 -040051#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include "../pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include "acpiphp.h"
55
56static LIST_HEAD(bridge_list);
Jiang Liu3d54a312013-04-12 05:44:28 +000057static DEFINE_MUTEX(bridge_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59#define MY_NAME "acpiphp_glue"
60
61static void handle_hotplug_event_bridge (acpi_handle, u32, void *);
Kristen Accardi8e5dce32005-10-18 17:21:40 -070062static void acpiphp_sanitize_bus(struct pci_bus *bus);
Bjorn Helgaasfca68252009-09-14 16:35:10 -060063static void acpiphp_set_hpp_values(struct pci_bus *bus);
Rafael J. Wysocki21a31012013-06-24 11:22:53 +020064static void hotplug_event_func(acpi_handle handle, u32 type, void *context);
Len Brown2b85e132006-06-27 01:50:14 -040065static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context);
Jiang Liu3d54a312013-04-12 05:44:28 +000066static void free_bridge(struct kref *kref);
Kristen Accardi8e5dce32005-10-18 17:21:40 -070067
MUNEDA Takahiro5a340ed2007-11-09 19:07:02 +090068/* callback routine to check for the existence of a pci dock device */
Kristen Accardi4e8662b2006-06-28 03:08:06 -040069static acpi_status
70is_pci_dock_device(acpi_handle handle, u32 lvl, void *context, void **rv)
71{
72 int *count = (int *)context;
73
74 if (is_dock_device(handle)) {
75 (*count)++;
76 return AE_CTRL_TERMINATE;
77 } else {
78 return AE_OK;
79 }
80}
81
Jiang Liu3d54a312013-04-12 05:44:28 +000082static inline void get_bridge(struct acpiphp_bridge *bridge)
83{
84 kref_get(&bridge->ref);
85}
86
87static inline void put_bridge(struct acpiphp_bridge *bridge)
88{
89 kref_put(&bridge->ref, free_bridge);
90}
91
92static void free_bridge(struct kref *kref)
93{
94 struct acpiphp_bridge *bridge;
95 struct acpiphp_slot *slot, *next;
96 struct acpiphp_func *func, *tmp;
97
98 bridge = container_of(kref, struct acpiphp_bridge, ref);
99
100 list_for_each_entry_safe(slot, next, &bridge->slots, node) {
101 list_for_each_entry_safe(func, tmp, &slot->funcs, sibling) {
102 kfree(func);
103 }
104 kfree(slot);
105 }
106
107 /* Release reference acquired by acpiphp_bridge_handle_to_function() */
108 if ((bridge->flags & BRIDGE_HAS_EJ0) && bridge->func)
109 put_bridge(bridge->func->slot->bridge);
110 put_device(&bridge->pci_bus->dev);
111 pci_dev_put(bridge->pci_dev);
112 kfree(bridge);
113}
114
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400115/*
116 * the _DCK method can do funny things... and sometimes not
117 * hah-hah funny.
118 *
119 * TBD - figure out a way to only call fixups for
120 * systems that require them.
121 */
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200122static void post_dock_fixups(acpi_handle not_used, u32 event, void *data)
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400123{
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200124 struct acpiphp_func *func = data;
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400125 struct pci_bus *bus = func->slot->bridge->pci_bus;
126 u32 buses;
127
128 if (!bus->self)
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200129 return;
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400130
131 /* fixup bad _DCK function that rewrites
132 * secondary bridge on slot
133 */
134 pci_read_config_dword(bus->self,
135 PCI_PRIMARY_BUS,
136 &buses);
137
Yinghai Lub918c622012-05-17 18:51:11 -0700138 if (((buses >> 8) & 0xff) != bus->busn_res.start) {
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400139 buses = (buses & 0xff000000)
Alex Chiang2a9d3522008-12-11 11:17:55 -0700140 | ((unsigned int)(bus->primary) << 0)
Yinghai Lub918c622012-05-17 18:51:11 -0700141 | ((unsigned int)(bus->busn_res.start) << 8)
142 | ((unsigned int)(bus->busn_res.end) << 16);
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400143 pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses);
144 }
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400145}
146
147
Vasiliy Kulikov9c8b04b2011-06-25 21:07:52 +0400148static const struct acpi_dock_ops acpiphp_dock_ops = {
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200149 .fixup = post_dock_fixups,
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200150 .handler = hotplug_event_func,
Shaohua Li1253f7a2008-08-28 10:06:16 +0800151};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Jiang Liu5ba113f2012-08-22 23:16:45 +0800153/* Check whether the PCI device is managed by native PCIe hotplug driver */
154static bool device_is_managed_by_native_pciehp(struct pci_dev *pdev)
155{
156 u32 reg32;
157 acpi_handle tmp;
158 struct acpi_pci_root *root;
159
160 /* Check whether the PCIe port supports native PCIe hotplug */
161 if (pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, &reg32))
162 return false;
163 if (!(reg32 & PCI_EXP_SLTCAP_HPC))
164 return false;
165
166 /*
167 * Check whether native PCIe hotplug has been enabled for
168 * this PCIe hierarchy.
169 */
170 tmp = acpi_find_root_bridge_handle(pdev);
171 if (!tmp)
172 return false;
173 root = acpi_pci_find_root(tmp);
174 if (!root)
175 return false;
176 if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL))
177 return false;
178
179 return true;
180}
181
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200182static void acpiphp_dock_init(void *data)
183{
184 struct acpiphp_func *func = data;
185
186 get_bridge(func->slot->bridge);
187}
188
189static void acpiphp_dock_release(void *data)
190{
191 struct acpiphp_func *func = data;
192
193 put_bridge(func->slot->bridge);
194}
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196/* callback routine to register each ACPI PCI slot object */
197static acpi_status
198register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
199{
200 struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context;
201 struct acpiphp_slot *slot;
202 struct acpiphp_func *newfunc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 acpi_status status = AE_OK;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400204 unsigned long long adr, sun;
Yijing Wangad41dd92013-04-12 05:44:27 +0000205 int device, function, retval, found = 0;
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +0900206 struct pci_bus *pbus = bridge->pci_bus;
Alex Chiang9d911d72009-05-21 16:21:15 -0600207 struct pci_dev *pdev;
Jiang Liu3b63aaa2013-04-12 05:44:26 +0000208 u32 val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +0900210 if (!acpi_pci_check_ejectable(pbus, handle) && !is_dock_device(handle))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return AE_OK;
212
Bjorn Helgaasdfb117b2012-06-20 16:18:29 -0600213 status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
214 if (ACPI_FAILURE(status)) {
215 warn("can't evaluate _ADR (%#x)\n", status);
216 return AE_OK;
217 }
218
219 device = (adr >> 16) & 0xffff;
220 function = adr & 0xffff;
221
Jiang Liu3d54a312013-04-12 05:44:28 +0000222 pdev = bridge->pci_dev;
Jiang Liu5ba113f2012-08-22 23:16:45 +0800223 if (pdev && device_is_managed_by_native_pciehp(pdev))
224 return AE_OK;
Rafael J. Wysocki619a5182011-12-13 00:02:28 +0100225
Eric Sesterhennf5afe802006-02-28 15:34:49 +0100226 newfunc = kzalloc(sizeof(struct acpiphp_func), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 if (!newfunc)
228 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 newfunc->handle = handle;
231 newfunc->function = function;
Matthew Garrett56ee3252008-11-25 21:48:14 +0000232
Jiang Liuecd046d2013-06-29 00:24:43 +0800233 if (acpi_has_method(handle, "_EJ0"))
Kristen Accardi20416ea2006-02-23 17:56:03 -0800234 newfunc->flags = FUNC_HAS_EJ0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Jiang Liuecd046d2013-06-29 00:24:43 +0800236 if (acpi_has_method(handle, "_STA"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 newfunc->flags |= FUNC_HAS_STA;
238
Jiang Liuecd046d2013-06-29 00:24:43 +0800239 if (acpi_has_method(handle, "_PS0"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 newfunc->flags |= FUNC_HAS_PS0;
241
Jiang Liuecd046d2013-06-29 00:24:43 +0800242 if (acpi_has_method(handle, "_PS3"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 newfunc->flags |= FUNC_HAS_PS3;
244
Jiang Liuecd046d2013-06-29 00:24:43 +0800245 if (acpi_has_method(handle, "_DCK"))
Kristen Accardi20416ea2006-02-23 17:56:03 -0800246 newfunc->flags |= FUNC_HAS_DCK;
Kristen Accardi20416ea2006-02-23 17:56:03 -0800247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
Kristen Accardi95b38b32006-06-28 03:09:54 -0400249 if (ACPI_FAILURE(status)) {
250 /*
251 * use the count of the number of slots we've found
252 * for the number of the slot
253 */
254 sun = bridge->nr_slots+1;
255 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 /* search for objects that share the same slot */
Yijing Wangad41dd92013-04-12 05:44:27 +0000258 list_for_each_entry(slot, &bridge->slots, node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 if (slot->device == device) {
260 if (slot->sun != sun)
261 warn("sibling found, but _SUN doesn't match!\n");
Yijing Wangad41dd92013-04-12 05:44:27 +0000262 found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 break;
264 }
265
Yijing Wangad41dd92013-04-12 05:44:27 +0000266 if (!found) {
Eric Sesterhennf5afe802006-02-28 15:34:49 +0100267 slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 if (!slot) {
269 kfree(newfunc);
270 return AE_NO_MEMORY;
271 }
272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 slot->bridge = bridge;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 slot->device = device;
275 slot->sun = sun;
276 INIT_LIST_HEAD(&slot->funcs);
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +0100277 mutex_init(&slot->crit_sect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Jiang Liu3d54a312013-04-12 05:44:28 +0000279 mutex_lock(&bridge_mutex);
Yijing Wangad41dd92013-04-12 05:44:27 +0000280 list_add_tail(&slot->node, &bridge->slots);
Jiang Liu3d54a312013-04-12 05:44:28 +0000281 mutex_unlock(&bridge_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 bridge->nr_slots++;
283
Justin Chenb6adc192008-12-11 11:16:44 -0700284 dbg("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +0900285 slot->sun, pci_domain_nr(pbus), pbus->number, device);
MUNEDA Takahiroe27da382006-02-23 17:56:08 -0800286 retval = acpiphp_register_hotplug_slot(slot);
287 if (retval) {
Alex Chiangf46753c2008-06-10 15:28:50 -0600288 if (retval == -EBUSY)
Justin Chenb6adc192008-12-11 11:16:44 -0700289 warn("Slot %llu already registered by another "
Alex Chiangf46753c2008-06-10 15:28:50 -0600290 "hotplug driver\n", slot->sun);
291 else
292 warn("acpiphp_register_hotplug_slot failed "
293 "(err code = 0x%x)\n", retval);
MUNEDA Takahiroe27da382006-02-23 17:56:08 -0800294 goto err_exit;
295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 }
297
298 newfunc->slot = slot;
Jiang Liu3d54a312013-04-12 05:44:28 +0000299 mutex_lock(&bridge_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 list_add_tail(&newfunc->sibling, &slot->funcs);
Jiang Liu3d54a312013-04-12 05:44:28 +0000301 mutex_unlock(&bridge_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Jiang Liu3b63aaa2013-04-12 05:44:26 +0000303 if (pci_bus_read_dev_vendor_id(pbus, PCI_DEVFN(device, function),
304 &val, 60*1000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400307 if (is_dock_device(handle)) {
308 /* we don't want to call this device's _EJ0
309 * because we want the dock notify handler
310 * to call it after it calls _DCK
Kristen Accardi20416ea2006-02-23 17:56:03 -0800311 */
312 newfunc->flags &= ~FUNC_HAS_EJ0;
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400313 if (register_hotplug_dock_device(handle,
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200314 &acpiphp_dock_ops, newfunc,
315 acpiphp_dock_init, acpiphp_dock_release))
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400316 dbg("failed to register dock device\n");
Kristen Accardi20416ea2006-02-23 17:56:03 -0800317 }
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 /* install notify handler */
Kristen Accardi20416ea2006-02-23 17:56:03 -0800320 if (!(newfunc->flags & FUNC_HAS_DCK)) {
321 status = acpi_install_notify_handler(handle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 ACPI_SYSTEM_NOTIFY,
323 handle_hotplug_event_func,
324 newfunc);
325
Kristen Accardi20416ea2006-02-23 17:56:03 -0800326 if (ACPI_FAILURE(status))
327 err("failed to register interrupt notify handler\n");
328 } else
329 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Kristen Accardi20416ea2006-02-23 17:56:03 -0800331 return status;
MUNEDA Takahiroe27da382006-02-23 17:56:08 -0800332
333 err_exit:
334 bridge->nr_slots--;
Jiang Liu3d54a312013-04-12 05:44:28 +0000335 mutex_lock(&bridge_mutex);
Yijing Wangad41dd92013-04-12 05:44:27 +0000336 list_del(&slot->node);
Jiang Liu3d54a312013-04-12 05:44:28 +0000337 mutex_unlock(&bridge_mutex);
MUNEDA Takahiroe27da382006-02-23 17:56:08 -0800338 kfree(slot);
339 kfree(newfunc);
340
341 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
344
345/* see if it's worth looking at this bridge */
Alex Chiang6edd7672009-09-10 12:34:04 -0600346static int detect_ejectable_slots(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Alex Chiang7f538662009-09-10 12:34:09 -0600348 int found = acpi_pci_detect_ejectable(handle);
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +0900349 if (!found) {
Alex Chiang6edd7672009-09-10 12:34:04 -0600350 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
Lin Ming22635762009-11-13 10:06:08 +0800351 is_pci_dock_device, NULL, (void *)&found, NULL);
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +0900352 }
353 return found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900357/* find acpiphp_func from acpiphp_bridge */
358static struct acpiphp_func *acpiphp_bridge_handle_to_function(acpi_handle handle)
359{
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900360 struct acpiphp_bridge *bridge;
361 struct acpiphp_slot *slot;
Jiang Liu3d54a312013-04-12 05:44:28 +0000362 struct acpiphp_func *func = NULL;
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900363
Jiang Liu3d54a312013-04-12 05:44:28 +0000364 mutex_lock(&bridge_mutex);
Alex Chiang58c08622009-10-26 21:25:27 -0600365 list_for_each_entry(bridge, &bridge_list, list) {
Yijing Wangad41dd92013-04-12 05:44:27 +0000366 list_for_each_entry(slot, &bridge->slots, node) {
Alex Chiang58c08622009-10-26 21:25:27 -0600367 list_for_each_entry(func, &slot->funcs, sibling) {
Jiang Liu3d54a312013-04-12 05:44:28 +0000368 if (func->handle == handle) {
369 get_bridge(func->slot->bridge);
370 mutex_unlock(&bridge_mutex);
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900371 return func;
Jiang Liu3d54a312013-04-12 05:44:28 +0000372 }
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900373 }
374 }
375 }
Jiang Liu3d54a312013-04-12 05:44:28 +0000376 mutex_unlock(&bridge_mutex);
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900377
378 return NULL;
379}
380
381
Rajesh Shah42f49a62005-04-28 00:25:53 -0700382static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
383{
Alex Chiang58c08622009-10-26 21:25:27 -0600384 struct acpiphp_bridge *bridge;
385
Jiang Liu3d54a312013-04-12 05:44:28 +0000386 mutex_lock(&bridge_mutex);
Alex Chiang58c08622009-10-26 21:25:27 -0600387 list_for_each_entry(bridge, &bridge_list, list)
Jiang Liu3d54a312013-04-12 05:44:28 +0000388 if (bridge->handle == handle) {
389 get_bridge(bridge);
390 mutex_unlock(&bridge_mutex);
Rajesh Shah42f49a62005-04-28 00:25:53 -0700391 return bridge;
Jiang Liu3d54a312013-04-12 05:44:28 +0000392 }
393 mutex_unlock(&bridge_mutex);
Rajesh Shah42f49a62005-04-28 00:25:53 -0700394
395 return NULL;
396}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Rajesh Shah364d5092005-04-28 00:25:54 -0700398static void cleanup_bridge(struct acpiphp_bridge *bridge)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Jiang Liu3d54a312013-04-12 05:44:28 +0000400 struct acpiphp_slot *slot;
401 struct acpiphp_func *func;
Rajesh Shah42f49a62005-04-28 00:25:53 -0700402 acpi_status status;
Rajesh Shah364d5092005-04-28 00:25:54 -0700403 acpi_handle handle = bridge->handle;
Rajesh Shah42f49a62005-04-28 00:25:53 -0700404
Jiang Liube6d2862013-01-31 00:10:10 +0800405 if (!pci_is_root_bus(bridge->pci_bus)) {
Yinghai Lu668192b2013-01-21 13:20:48 -0800406 status = acpi_remove_notify_handler(handle,
407 ACPI_SYSTEM_NOTIFY,
Rajesh Shah42f49a62005-04-28 00:25:53 -0700408 handle_hotplug_event_bridge);
Yinghai Lu668192b2013-01-21 13:20:48 -0800409 if (ACPI_FAILURE(status))
410 err("failed to remove notify handler\n");
411 }
Rajesh Shah42f49a62005-04-28 00:25:53 -0700412
Jiang Liube6d2862013-01-31 00:10:10 +0800413 if ((bridge->flags & BRIDGE_HAS_EJ0) && bridge->func) {
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900414 status = acpi_install_notify_handler(bridge->func->handle,
415 ACPI_SYSTEM_NOTIFY,
416 handle_hotplug_event_func,
417 bridge->func);
418 if (ACPI_FAILURE(status))
419 err("failed to install interrupt notify handler\n");
420 }
421
Jiang Liu3d54a312013-04-12 05:44:28 +0000422 list_for_each_entry(slot, &bridge->slots, node) {
423 list_for_each_entry(func, &slot->funcs, sibling) {
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400424 if (is_dock_device(func->handle)) {
425 unregister_hotplug_dock_device(func->handle);
Kristen Accardi4e8662b2006-06-28 03:08:06 -0400426 }
Kristen Accardi20416ea2006-02-23 17:56:03 -0800427 if (!(func->flags & FUNC_HAS_DCK)) {
428 status = acpi_remove_notify_handler(func->handle,
Rajesh Shah42f49a62005-04-28 00:25:53 -0700429 ACPI_SYSTEM_NOTIFY,
430 handle_hotplug_event_func);
Kristen Accardi20416ea2006-02-23 17:56:03 -0800431 if (ACPI_FAILURE(status))
432 err("failed to remove notify handler\n");
433 }
Rajesh Shah42f49a62005-04-28 00:25:53 -0700434 }
MUNEDA Takahiroe27da382006-02-23 17:56:08 -0800435 acpiphp_unregister_hotplug_slot(slot);
Rajesh Shah42f49a62005-04-28 00:25:53 -0700436 }
437
Jiang Liu3d54a312013-04-12 05:44:28 +0000438 mutex_lock(&bridge_mutex);
Rajesh Shah42f49a62005-04-28 00:25:53 -0700439 list_del(&bridge->list);
Jiang Liu3d54a312013-04-12 05:44:28 +0000440 mutex_unlock(&bridge_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441}
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443static int power_on_slot(struct acpiphp_slot *slot)
444{
445 acpi_status status;
446 struct acpiphp_func *func;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 int retval = 0;
448
449 /* if already enabled, just skip */
450 if (slot->flags & SLOT_POWEREDON)
451 goto err_exit;
452
Alex Chiang58c08622009-10-26 21:25:27 -0600453 list_for_each_entry(func, &slot->funcs, sibling) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 if (func->flags & FUNC_HAS_PS0) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800455 dbg("%s: executing _PS0\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL);
457 if (ACPI_FAILURE(status)) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800458 warn("%s: _PS0 failed\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 retval = -1;
460 goto err_exit;
461 } else
462 break;
463 }
464 }
465
466 /* TBD: evaluate _STA to check if the slot is enabled */
467
468 slot->flags |= SLOT_POWEREDON;
469
470 err_exit:
471 return retval;
472}
473
474
475static int power_off_slot(struct acpiphp_slot *slot)
476{
477 acpi_status status;
478 struct acpiphp_func *func;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 int retval = 0;
481
482 /* if already disabled, just skip */
483 if ((slot->flags & SLOT_POWEREDON) == 0)
484 goto err_exit;
485
Alex Chiang58c08622009-10-26 21:25:27 -0600486 list_for_each_entry(func, &slot->funcs, sibling) {
Rajesh Shah2f523b12005-04-28 00:25:55 -0700487 if (func->flags & FUNC_HAS_PS3) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL);
489 if (ACPI_FAILURE(status)) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800490 warn("%s: _PS3 failed\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 retval = -1;
492 goto err_exit;
493 } else
494 break;
495 }
496 }
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 /* TBD: evaluate _STA to check if the slot is disabled */
499
500 slot->flags &= (~SLOT_POWEREDON);
501
502 err_exit:
503 return retval;
504}
505
506
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800507
508/**
Randy Dunlap26e6c662007-11-28 09:04:30 -0800509 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800510 * @bus: bus to start search with
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800511 */
512static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
513{
514 struct list_head *tmp;
515 unsigned char max, n;
516
517 /*
518 * pci_bus_max_busnr will return the highest
519 * reserved busnr for all these children.
520 * that is equivalent to the bus->subordinate
521 * value. We don't want to use the parent's
522 * bus->subordinate value because it could have
523 * padding in it.
524 */
Yinghai Lub918c622012-05-17 18:51:11 -0700525 max = bus->busn_res.start;
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800526
527 list_for_each(tmp, &bus->children) {
528 n = pci_bus_max_busnr(pci_bus_b(tmp));
529 if (n > max)
530 max = n;
531 }
532 return max;
533}
534
535
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800536/**
537 * acpiphp_bus_add - add a new bus to acpi subsystem
538 * @func: acpiphp_func of the bridge
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800539 */
540static int acpiphp_bus_add(struct acpiphp_func *func)
541{
Rafael J. Wysocki636458d2012-12-21 00:36:47 +0100542 struct acpi_device *device;
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800543 int ret_val;
544
Kristen Accardi20416ea2006-02-23 17:56:03 -0800545 if (!acpi_bus_get_device(func->handle, &device)) {
546 dbg("bus exists... trim\n");
547 /* this shouldn't be in here, so remove
548 * the bus then re-add it...
549 */
Rafael J. Wysockibfee26d2013-01-26 00:27:44 +0100550 acpi_bus_trim(device);
Kristen Accardi20416ea2006-02-23 17:56:03 -0800551 }
552
Rafael J. Wysockib8bd7592013-01-19 01:27:35 +0100553 ret_val = acpi_bus_scan(func->handle);
Rafael J. Wysocki0cd6ac52012-12-21 00:36:49 +0100554 if (!ret_val)
555 ret_val = acpi_bus_get_device(func->handle, &device);
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800556
Rafael J. Wysocki0cd6ac52012-12-21 00:36:49 +0100557 if (ret_val)
558 dbg("error adding bus, %x\n", -ret_val);
559
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800560 return ret_val;
561}
562
563
MUNEDA Takahiro92c9be92006-03-22 14:49:09 +0900564/**
565 * acpiphp_bus_trim - trim a bus from acpi subsystem
566 * @handle: handle to acpi namespace
MUNEDA Takahiro92c9be92006-03-22 14:49:09 +0900567 */
Adrian Bunk6d47a5e2006-08-14 23:07:38 -0700568static int acpiphp_bus_trim(acpi_handle handle)
MUNEDA Takahiro92c9be92006-03-22 14:49:09 +0900569{
570 struct acpi_device *device;
571 int retval;
572
573 retval = acpi_bus_get_device(handle, &device);
574 if (retval) {
575 dbg("acpi_device not found\n");
576 return retval;
577 }
578
Rafael J. Wysockibfee26d2013-01-26 00:27:44 +0100579 acpi_bus_trim(device);
580 return 0;
MUNEDA Takahiro92c9be92006-03-22 14:49:09 +0900581}
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800582
Shaohua Lid0607052010-02-25 10:59:34 +0800583static void acpiphp_set_acpi_region(struct acpiphp_slot *slot)
584{
585 struct acpiphp_func *func;
586 union acpi_object params[2];
587 struct acpi_object_list arg_list;
588
589 list_for_each_entry(func, &slot->funcs, sibling) {
590 arg_list.count = 2;
591 arg_list.pointer = params;
592 params[0].type = ACPI_TYPE_INTEGER;
593 params[0].integer.value = ACPI_ADR_SPACE_PCI_CONFIG;
594 params[1].type = ACPI_TYPE_INTEGER;
595 params[1].integer.value = 1;
596 /* _REG is optional, we don't care about if there is failure */
597 acpi_evaluate_object(func->handle, "_REG", &arg_list, NULL);
598 }
599}
600
Yinghai Lu1f96a962013-01-21 13:20:42 -0800601static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev)
602{
603 struct acpiphp_func *func;
604
605 if (!dev->subordinate)
606 return;
607
608 /* quirk, or pcie could set it already */
609 if (dev->is_hotplug_bridge)
610 return;
611
612 if (PCI_SLOT(dev->devfn) != slot->device)
613 return;
614
615 list_for_each_entry(func, &slot->funcs, sibling) {
616 if (PCI_FUNC(dev->devfn) == func->function) {
617 /* check if this bridge has ejectable slots */
618 if ((detect_ejectable_slots(func->handle) > 0))
619 dev->is_hotplug_bridge = 1;
620 break;
621 }
622 }
623}
Jiang Liu3b63aaa2013-04-12 05:44:26 +0000624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625/**
626 * enable_device - enable, configure a slot
627 * @slot: slot to be enabled
628 *
629 * This function should be called per *physical slot*,
630 * not per each slot object in ACPI namespace.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 */
Sam Ravnborg0ab2b572008-02-17 10:45:28 +0100632static int __ref enable_device(struct acpiphp_slot *slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 struct pci_dev *dev;
Rajesh Shah42f49a62005-04-28 00:25:53 -0700635 struct pci_bus *bus = slot->bridge->pci_bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 struct acpiphp_func *func;
Rajesh Shah42f49a62005-04-28 00:25:53 -0700637 int num, max, pass;
Jiang Liud66ecb72013-06-23 01:01:35 +0200638 LIST_HEAD(add_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 if (slot->flags & SLOT_ENABLED)
641 goto err_exit;
642
Jiang Liu2ca344e2013-01-31 00:10:09 +0800643 list_for_each_entry(func, &slot->funcs, sibling)
644 acpiphp_bus_add(func);
645
Rajesh Shah42f49a62005-04-28 00:25:53 -0700646 num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0));
647 if (num == 0) {
Amos Kongf382a082011-11-25 15:03:07 +0800648 /* Maybe only part of funcs are added. */
649 dbg("No new device found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 goto err_exit;
651 }
652
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800653 max = acpiphp_max_busnr(bus);
Rajesh Shah42f49a62005-04-28 00:25:53 -0700654 for (pass = 0; pass < 2; pass++) {
655 list_for_each_entry(dev, &bus->devices, bus_list) {
656 if (PCI_SLOT(dev->devfn) != slot->device)
657 continue;
658 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
Kristen Accardic64b5ee2005-12-14 09:37:26 -0800659 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
Rajesh Shah42f49a62005-04-28 00:25:53 -0700660 max = pci_scan_bridge(bus, dev, max, pass);
Yinghai Lu1f96a962013-01-21 13:20:42 -0800661 if (pass && dev->subordinate) {
662 check_hotplug_bridge(slot, dev);
Jiang Liud66ecb72013-06-23 01:01:35 +0200663 pcibios_resource_survey_bus(dev->subordinate);
664 __pci_bus_size_bridges(dev->subordinate,
665 &add_list);
Yinghai Lu1f96a962013-01-21 13:20:42 -0800666 }
Kristen Accardic64b5ee2005-12-14 09:37:26 -0800667 }
Rajesh Shah42f49a62005-04-28 00:25:53 -0700668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 }
670
Jiang Liud66ecb72013-06-23 01:01:35 +0200671 __pci_bus_assign_resources(bus, &add_list, NULL);
Kristen Accardi8e5dce32005-10-18 17:21:40 -0700672 acpiphp_sanitize_bus(bus);
Bjorn Helgaasfca68252009-09-14 16:35:10 -0600673 acpiphp_set_hpp_values(bus);
Shaohua Lid0607052010-02-25 10:59:34 +0800674 acpiphp_set_acpi_region(slot);
Kristen Accardi8e5dce32005-10-18 17:21:40 -0700675 pci_enable_bridges(bus);
Ian Campbell69643e42011-05-11 17:00:32 +0100676
677 list_for_each_entry(dev, &bus->devices, bus_list) {
678 /* Assume that newly added devices are powered on already. */
679 if (!dev->is_added)
680 dev->current_state = PCI_D0;
681 }
682
Rajesh Shah42f49a62005-04-28 00:25:53 -0700683 pci_bus_add_devices(bus);
684
Amos Kongf382a082011-11-25 15:03:07 +0800685 slot->flags |= SLOT_ENABLED;
Alex Chiang58c08622009-10-26 21:25:27 -0600686 list_for_each_entry(func, &slot->funcs, sibling) {
Alex Chiang9d911d72009-05-21 16:21:15 -0600687 dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
688 func->function));
Amos Kongf382a082011-11-25 15:03:07 +0800689 if (!dev) {
690 /* Do not set SLOT_ENABLED flag if some funcs
691 are not added. */
692 slot->flags &= (~SLOT_ENABLED);
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900693 continue;
Amos Kongf382a082011-11-25 15:03:07 +0800694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 }
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 err_exit:
Jiang Liu3d54a312013-04-12 05:44:28 +0000699 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700}
701
Amos Kongce29ca32012-05-23 10:20:35 -0600702/* return first device in slot, acquiring a reference on it */
703static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot)
704{
705 struct pci_bus *bus = slot->bridge->pci_bus;
706 struct pci_dev *dev;
707 struct pci_dev *ret = NULL;
708
709 down_read(&pci_bus_sem);
710 list_for_each_entry(dev, &bus->devices, bus_list)
711 if (PCI_SLOT(dev->devfn) == slot->device) {
712 ret = pci_dev_get(dev);
713 break;
714 }
715 up_read(&pci_bus_sem);
716
717 return ret;
718}
719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720/**
721 * disable_device - disable a slot
Randy Dunlap26e6c662007-11-28 09:04:30 -0800722 * @slot: ACPI PHP slot
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 */
724static int disable_device(struct acpiphp_slot *slot)
725{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 struct acpiphp_func *func;
Alex Chiang9d911d72009-05-21 16:21:15 -0600727 struct pci_dev *pdev;
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900728
Amos Kongce29ca32012-05-23 10:20:35 -0600729 /*
730 * enable_device() enumerates all functions in this device via
731 * pci_scan_slot(), whether they have associated ACPI hotplug
732 * methods (_EJ0, etc.) or not. Therefore, we remove all functions
733 * here.
734 */
735 while ((pdev = dev_in_slot(slot))) {
Bjorn Helgaas34e54842012-08-17 10:03:47 -0600736 pci_stop_and_remove_bus_device(pdev);
Amos Kongce29ca32012-05-23 10:20:35 -0600737 pci_dev_put(pdev);
Satoru Takeuchi600812e2006-09-12 10:22:53 -0700738 }
Satoru Takeuchi0dad3512006-09-12 10:17:46 -0700739
Alex Chiang9d911d72009-05-21 16:21:15 -0600740 list_for_each_entry(func, &slot->funcs, sibling) {
MUNEDA Takahiro92c9be92006-03-22 14:49:09 +0900741 acpiphp_bus_trim(func->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 }
743
744 slot->flags &= (~SLOT_ENABLED);
745
Alex Chiang9d911d72009-05-21 16:21:15 -0600746 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747}
748
749
750/**
751 * get_slot_status - get ACPI slot status
Randy Dunlap26e6c662007-11-28 09:04:30 -0800752 * @slot: ACPI PHP slot
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800754 * If a slot has _STA for each function and if any one of them
755 * returned non-zero status, return it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800757 * If a slot doesn't have _STA and if any one of its functions'
758 * configuration space is configured, return 0x0f as a _STA.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800760 * Otherwise return 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 */
762static unsigned int get_slot_status(struct acpiphp_slot *slot)
763{
764 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400765 unsigned long long sta = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 u32 dvid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 struct acpiphp_func *func;
768
Alex Chiang58c08622009-10-26 21:25:27 -0600769 list_for_each_entry(func, &slot->funcs, sibling) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 if (func->flags & FUNC_HAS_STA) {
771 status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta);
772 if (ACPI_SUCCESS(status) && sta)
773 break;
774 } else {
775 pci_bus_read_config_dword(slot->bridge->pci_bus,
776 PCI_DEVFN(slot->device,
777 func->function),
778 PCI_VENDOR_ID, &dvid);
779 if (dvid != 0xffffffff) {
780 sta = ACPI_STA_ALL;
781 break;
782 }
783 }
784 }
785
786 return (unsigned int)sta;
787}
788
789/**
Rajesh Shah8d50e332005-04-28 00:25:57 -0700790 * acpiphp_eject_slot - physically eject the slot
Randy Dunlap26e6c662007-11-28 09:04:30 -0800791 * @slot: ACPI PHP slot
Rajesh Shah8d50e332005-04-28 00:25:57 -0700792 */
Gary Hadebfceafc2007-07-05 11:10:46 -0700793int acpiphp_eject_slot(struct acpiphp_slot *slot)
Rajesh Shah8d50e332005-04-28 00:25:57 -0700794{
Rajesh Shah8d50e332005-04-28 00:25:57 -0700795 struct acpiphp_func *func;
Rajesh Shah8d50e332005-04-28 00:25:57 -0700796
Alex Chiang58c08622009-10-26 21:25:27 -0600797 list_for_each_entry(func, &slot->funcs, sibling) {
Rajesh Shah8d50e332005-04-28 00:25:57 -0700798 /* We don't want to call _EJ0 on non-existing functions. */
799 if ((func->flags & FUNC_HAS_EJ0)) {
Jiang Liuecd046d2013-06-29 00:24:43 +0800800 if (ACPI_FAILURE(acpi_evaluate_ej0(func->handle)))
Rajesh Shah8d50e332005-04-28 00:25:57 -0700801 return -1;
Jiang Liuecd046d2013-06-29 00:24:43 +0800802 else
Rajesh Shah8d50e332005-04-28 00:25:57 -0700803 break;
804 }
805 }
806 return 0;
807}
808
809/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 * acpiphp_check_bridge - re-enumerate devices
Randy Dunlap26e6c662007-11-28 09:04:30 -0800811 * @bridge: where to begin re-enumeration
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 *
813 * Iterate over all slots under this bridge and make sure that if a
814 * card is present they are enabled, and if not they are disabled.
815 */
816static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
817{
818 struct acpiphp_slot *slot;
819 int retval = 0;
820 int enabled, disabled;
821
822 enabled = disabled = 0;
823
Yijing Wangad41dd92013-04-12 05:44:27 +0000824 list_for_each_entry(slot, &bridge->slots, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 unsigned int status = get_slot_status(slot);
826 if (slot->flags & SLOT_ENABLED) {
827 if (status == ACPI_STA_ALL)
828 continue;
829 retval = acpiphp_disable_slot(slot);
830 if (retval) {
831 err("Error occurred in disabling\n");
832 goto err_exit;
Rajesh Shah8d50e332005-04-28 00:25:57 -0700833 } else {
834 acpiphp_eject_slot(slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
836 disabled++;
837 } else {
838 if (status != ACPI_STA_ALL)
839 continue;
840 retval = acpiphp_enable_slot(slot);
841 if (retval) {
842 err("Error occurred in enabling\n");
843 goto err_exit;
844 }
845 enabled++;
846 }
847 }
848
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800849 dbg("%s: %d enabled, %d disabled\n", __func__, enabled, disabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 err_exit:
852 return retval;
853}
854
Bjorn Helgaasfca68252009-09-14 16:35:10 -0600855static void acpiphp_set_hpp_values(struct pci_bus *bus)
Rajesh Shah8e7561c2005-04-28 00:25:56 -0700856{
Rajesh Shah8e7561c2005-04-28 00:25:56 -0700857 struct pci_dev *dev;
858
Bjorn Helgaase81995b2009-09-14 16:35:35 -0600859 list_for_each_entry(dev, &bus->devices, bus_list)
860 pci_configure_slot(dev);
Rajesh Shah8e7561c2005-04-28 00:25:56 -0700861}
862
863/*
864 * Remove devices for which we could not assign resources, call
865 * arch specific code to fix-up the bus
866 */
867static void acpiphp_sanitize_bus(struct pci_bus *bus)
868{
Yijing Wangd65eba62013-04-12 05:44:17 +0000869 struct pci_dev *dev, *tmp;
Rajesh Shah8e7561c2005-04-28 00:25:56 -0700870 int i;
871 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
872
Yijing Wangd65eba62013-04-12 05:44:17 +0000873 list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) {
Rajesh Shah8e7561c2005-04-28 00:25:56 -0700874 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
875 struct resource *res = &dev->resource[i];
876 if ((res->flags & type_mask) && !res->start &&
877 res->end) {
878 /* Could not assign a required resources
879 * for this device, remove it */
Yinghai Lu210647a2012-02-25 13:54:20 -0800880 pci_stop_and_remove_bus_device(dev);
Rajesh Shah8e7561c2005-04-28 00:25:56 -0700881 break;
882 }
883 }
884 }
885}
886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887/*
888 * ACPI event handlers
889 */
890
Gary Hade0bbd6422007-07-05 11:10:48 -0700891static acpi_status
Gary Hade0bbd6422007-07-05 11:10:48 -0700892check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
893{
894 struct acpiphp_bridge *bridge;
895 char objname[64];
896 struct acpi_buffer buffer = { .length = sizeof(objname),
897 .pointer = objname };
898
899 bridge = acpiphp_handle_to_bridge(handle);
900 if (bridge) {
901 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
902 dbg("%s: re-enumerating slots under %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800903 __func__, objname);
Gary Hade0bbd6422007-07-05 11:10:48 -0700904 acpiphp_check_bridge(bridge);
Jiang Liu3d54a312013-04-12 05:44:28 +0000905 put_bridge(bridge);
Gary Hade0bbd6422007-07-05 11:10:48 -0700906 }
907 return AE_OK ;
908}
909
Yinghai Lu3f327e32013-05-07 11:06:03 -0600910void acpiphp_check_host_bridge(acpi_handle handle)
911{
912 struct acpiphp_bridge *bridge;
913
914 bridge = acpiphp_handle_to_bridge(handle);
915 if (bridge) {
916 acpiphp_check_bridge(bridge);
917 put_bridge(bridge);
918 }
919
920 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
921 ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL, NULL);
922}
923
Prarit Bhargava6af8bef2011-09-28 19:40:53 -0400924static void _handle_hotplug_event_bridge(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925{
926 struct acpiphp_bridge *bridge;
927 char objname[64];
928 struct acpi_buffer buffer = { .length = sizeof(objname),
929 .pointer = objname };
Yinghai Lu92d8aff2013-01-21 13:20:47 -0800930 struct acpi_hp_work *hp_work;
Prarit Bhargava6af8bef2011-09-28 19:40:53 -0400931 acpi_handle handle;
932 u32 type;
933
Yinghai Lu92d8aff2013-01-21 13:20:47 -0800934 hp_work = container_of(work, struct acpi_hp_work, work);
Prarit Bhargava6af8bef2011-09-28 19:40:53 -0400935 handle = hp_work->handle;
936 type = hp_work->type;
Jiang Liube6d2862013-01-31 00:10:10 +0800937 bridge = (struct acpiphp_bridge *)hp_work->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Rafael J. Wysocki3757b942013-02-13 14:36:47 +0100939 acpi_scan_lock_acquire();
940
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
942
943 switch (type) {
944 case ACPI_NOTIFY_BUS_CHECK:
945 /* bus re-enumerate */
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800946 dbg("%s: Bus check notify on %s\n", __func__, objname);
Jiang Liube6d2862013-01-31 00:10:10 +0800947 dbg("%s: re-enumerating slots under %s\n", __func__, objname);
948 acpiphp_check_bridge(bridge);
949 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
950 ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 break;
952
953 case ACPI_NOTIFY_DEVICE_CHECK:
954 /* device check */
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800955 dbg("%s: Device check notify on %s\n", __func__, objname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 acpiphp_check_bridge(bridge);
957 break;
958
959 case ACPI_NOTIFY_DEVICE_WAKE:
960 /* wake event */
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800961 dbg("%s: Device wake notify on %s\n", __func__, objname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 break;
963
964 case ACPI_NOTIFY_EJECT_REQUEST:
965 /* request device eject */
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800966 dbg("%s: Device eject notify on %s\n", __func__, objname);
Jiang Liube6d2862013-01-31 00:10:10 +0800967 if ((bridge->flags & BRIDGE_HAS_EJ0) && bridge->func) {
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900968 struct acpiphp_slot *slot;
969 slot = bridge->func->slot;
970 if (!acpiphp_disable_slot(slot))
971 acpiphp_eject_slot(slot);
972 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 break;
974
975 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
976 printk(KERN_ERR "Device %s cannot be configured due"
977 " to a frequency mismatch\n", objname);
978 break;
979
980 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
981 printk(KERN_ERR "Device %s cannot be configured due"
982 " to a bus mode mismatch\n", objname);
983 break;
984
985 case ACPI_NOTIFY_POWER_FAULT:
986 printk(KERN_ERR "Device %s has suffered a power fault\n",
987 objname);
988 break;
989
990 default:
991 warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
992 break;
993 }
Prarit Bhargava6af8bef2011-09-28 19:40:53 -0400994
Rafael J. Wysocki3757b942013-02-13 14:36:47 +0100995 acpi_scan_lock_release();
Prarit Bhargava6af8bef2011-09-28 19:40:53 -0400996 kfree(hp_work); /* allocated in handle_hotplug_event_bridge */
Jiang Liu3d54a312013-04-12 05:44:28 +0000997 put_bridge(bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998}
999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000/**
Prarit Bhargava6af8bef2011-09-28 19:40:53 -04001001 * handle_hotplug_event_bridge - handle ACPI event on bridges
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 * @handle: Notify()'ed acpi_handle
1003 * @type: Notify code
Prarit Bhargava6af8bef2011-09-28 19:40:53 -04001004 * @context: pointer to acpiphp_bridge structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 *
Prarit Bhargava6af8bef2011-09-28 19:40:53 -04001006 * Handles ACPI event notification on {host,p2p} bridges.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 */
Prarit Bhargava6af8bef2011-09-28 19:40:53 -04001008static void handle_hotplug_event_bridge(acpi_handle handle, u32 type,
1009 void *context)
1010{
Jiang Liu3d54a312013-04-12 05:44:28 +00001011 struct acpiphp_bridge *bridge = context;
1012
Prarit Bhargava6af8bef2011-09-28 19:40:53 -04001013 /*
1014 * Currently the code adds all hotplug events to the kacpid_wq
1015 * queue when it should add hotplug events to the kacpi_hotplug_wq.
1016 * The proper way to fix this is to reorganize the code so that
1017 * drivers (dock, etc.) do not call acpi_os_execute(), etc.
1018 * For now just re-add this work to the kacpi_hotplug_wq so we
1019 * don't deadlock on hotplug actions.
1020 */
Jiang Liu3d54a312013-04-12 05:44:28 +00001021 get_bridge(bridge);
Yinghai Lu92d8aff2013-01-21 13:20:47 -08001022 alloc_acpi_hp_work(handle, type, context, _handle_hotplug_event_bridge);
Prarit Bhargava6af8bef2011-09-28 19:40:53 -04001023}
1024
Rafael J. Wysocki21a31012013-06-24 11:22:53 +02001025static void hotplug_event_func(acpi_handle handle, u32 type, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026{
Rafael J. Wysocki21a31012013-06-24 11:22:53 +02001027 struct acpiphp_func *func = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 char objname[64];
1029 struct acpi_buffer buffer = { .length = sizeof(objname),
1030 .pointer = objname };
Rafael J. Wysocki3757b942013-02-13 14:36:47 +01001031
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1033
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 switch (type) {
1035 case ACPI_NOTIFY_BUS_CHECK:
1036 /* bus re-enumerate */
Harvey Harrison66bef8c2008-03-03 19:09:46 -08001037 dbg("%s: Bus check notify on %s\n", __func__, objname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 acpiphp_enable_slot(func->slot);
1039 break;
1040
1041 case ACPI_NOTIFY_DEVICE_CHECK:
1042 /* device check : re-enumerate from parent bus */
Harvey Harrison66bef8c2008-03-03 19:09:46 -08001043 dbg("%s: Device check notify on %s\n", __func__, objname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 acpiphp_check_bridge(func->slot->bridge);
1045 break;
1046
1047 case ACPI_NOTIFY_DEVICE_WAKE:
1048 /* wake event */
Harvey Harrison66bef8c2008-03-03 19:09:46 -08001049 dbg("%s: Device wake notify on %s\n", __func__, objname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 break;
1051
1052 case ACPI_NOTIFY_EJECT_REQUEST:
1053 /* request device eject */
Harvey Harrison66bef8c2008-03-03 19:09:46 -08001054 dbg("%s: Device eject notify on %s\n", __func__, objname);
Rajesh Shah8d50e332005-04-28 00:25:57 -07001055 if (!(acpiphp_disable_slot(func->slot)))
1056 acpiphp_eject_slot(func->slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 break;
1058
1059 default:
1060 warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
1061 break;
1062 }
Rafael J. Wysocki21a31012013-06-24 11:22:53 +02001063}
1064
1065static void _handle_hotplug_event_func(struct work_struct *work)
1066{
1067 struct acpi_hp_work *hp_work;
1068 struct acpiphp_func *func;
1069
1070 hp_work = container_of(work, struct acpi_hp_work, work);
1071 func = hp_work->context;
1072 acpi_scan_lock_acquire();
1073
1074 hotplug_event_func(hp_work->handle, hp_work->type, func);
Prarit Bhargava6af8bef2011-09-28 19:40:53 -04001075
Rafael J. Wysocki3757b942013-02-13 14:36:47 +01001076 acpi_scan_lock_release();
Prarit Bhargava6af8bef2011-09-28 19:40:53 -04001077 kfree(hp_work); /* allocated in handle_hotplug_event_func */
Jiang Liu3d54a312013-04-12 05:44:28 +00001078 put_bridge(func->slot->bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079}
1080
Prarit Bhargava6af8bef2011-09-28 19:40:53 -04001081/**
1082 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
1083 * @handle: Notify()'ed acpi_handle
1084 * @type: Notify code
1085 * @context: pointer to acpiphp_func structure
1086 *
1087 * Handles ACPI event notification on slots.
1088 */
1089static void handle_hotplug_event_func(acpi_handle handle, u32 type,
1090 void *context)
1091{
Jiang Liu3d54a312013-04-12 05:44:28 +00001092 struct acpiphp_func *func = context;
1093
Prarit Bhargava6af8bef2011-09-28 19:40:53 -04001094 /*
1095 * Currently the code adds all hotplug events to the kacpid_wq
1096 * queue when it should add hotplug events to the kacpi_hotplug_wq.
1097 * The proper way to fix this is to reorganize the code so that
1098 * drivers (dock, etc.) do not call acpi_os_execute(), etc.
1099 * For now just re-add this work to the kacpi_hotplug_wq so we
1100 * don't deadlock on hotplug actions.
1101 */
Jiang Liu3d54a312013-04-12 05:44:28 +00001102 get_bridge(func->slot->bridge);
Yinghai Lu92d8aff2013-01-21 13:20:47 -08001103 alloc_acpi_hp_work(handle, type, context, _handle_hotplug_event_func);
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001104}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Jiang Liu3b63aaa2013-04-12 05:44:26 +00001106/*
1107 * Create hotplug slots for the PCI bus.
1108 * It should always return 0 to avoid skipping following notifiers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 */
Rafael J. Wysockibe1c9de2013-07-13 23:27:23 +02001110void acpiphp_enumerate_slots(struct pci_bus *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
Jiang Liu3b63aaa2013-04-12 05:44:26 +00001112 struct acpiphp_bridge *bridge;
Rafael J. Wysocki25520022013-07-13 23:27:23 +02001113 acpi_handle handle;
1114 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Jiang Liu3b63aaa2013-04-12 05:44:26 +00001116 if (acpiphp_disabled)
1117 return;
1118
Rafael J. Wysockibe1c9de2013-07-13 23:27:23 +02001119 handle = ACPI_HANDLE(bus->bridge);
1120 if (!handle || detect_ejectable_slots(handle) <= 0)
Jiang Liu3b63aaa2013-04-12 05:44:26 +00001121 return;
1122
1123 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
1124 if (bridge == NULL) {
1125 err("out of memory\n");
1126 return;
1127 }
1128
Yijing Wangad41dd92013-04-12 05:44:27 +00001129 INIT_LIST_HEAD(&bridge->slots);
Jiang Liu3d54a312013-04-12 05:44:28 +00001130 kref_init(&bridge->ref);
Jiang Liu3b63aaa2013-04-12 05:44:26 +00001131 bridge->handle = handle;
1132 bridge->pci_dev = pci_dev_get(bus->self);
1133 bridge->pci_bus = bus;
1134
1135 /*
1136 * Grab a ref to the subordinate PCI bus in case the bus is
1137 * removed via PCI core logical hotplug. The ref pins the bus
1138 * (which we access during module unload).
1139 */
1140 get_device(&bus->dev);
1141
Rafael J. Wysocki25520022013-07-13 23:27:23 +02001142 /* must be added to the list prior to calling register_slot */
1143 mutex_lock(&bridge_mutex);
1144 list_add(&bridge->list, &bridge_list);
1145 mutex_unlock(&bridge_mutex);
1146
1147 /* register all slot objects under this bridge */
1148 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, 1,
1149 register_slot, NULL, bridge, NULL);
1150 if (ACPI_FAILURE(status)) {
1151 acpi_handle_err(bridge->handle, "failed to register slots\n");
1152 goto err;
Jiang Liu3b63aaa2013-04-12 05:44:26 +00001153 }
1154
Rafael J. Wysocki25520022013-07-13 23:27:23 +02001155 if (pci_is_root_bus(bridge->pci_bus))
1156 return;
1157
1158 /* install notify handler for P2P bridges */
1159 status = acpi_install_notify_handler(bridge->handle, ACPI_SYSTEM_NOTIFY,
1160 handle_hotplug_event_bridge,
1161 bridge);
1162 if (ACPI_FAILURE(status)) {
1163 acpi_handle_err(bridge->handle,
1164 "failed to register notify handler\n");
1165 goto err;
1166 }
1167
1168 if (!acpi_has_method(bridge->handle, "_EJ0"))
1169 return;
1170
1171 dbg("found ejectable p2p bridge\n");
1172 bridge->flags |= BRIDGE_HAS_EJ0;
1173 bridge->func = acpiphp_bridge_handle_to_function(bridge->handle);
1174 if (bridge->func) {
1175 status = acpi_remove_notify_handler(bridge->func->handle,
1176 ACPI_SYSTEM_NOTIFY,
1177 handle_hotplug_event_func);
1178 if (ACPI_FAILURE(status))
1179 acpi_handle_err(bridge->func->handle,
1180 "failed to remove notify handler\n");
1181 }
1182 return;
1183
1184 err:
1185 cleanup_bridge(bridge);
1186 put_bridge(bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
Jiang Liu3b63aaa2013-04-12 05:44:26 +00001189/* Destroy hotplug slots associated with the PCI bus */
1190void acpiphp_remove_slots(struct pci_bus *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191{
Jiang Liu3b63aaa2013-04-12 05:44:26 +00001192 struct acpiphp_bridge *bridge, *tmp;
1193
1194 if (acpiphp_disabled)
1195 return;
1196
1197 list_for_each_entry_safe(bridge, tmp, &bridge_list, list)
1198 if (bridge->pci_bus == bus) {
1199 cleanup_bridge(bridge);
Jiang Liu3d54a312013-04-12 05:44:28 +00001200 put_bridge(bridge);
Jiang Liu3b63aaa2013-04-12 05:44:26 +00001201 break;
1202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203}
1204
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205/**
1206 * acpiphp_enable_slot - power on slot
Randy Dunlap26e6c662007-11-28 09:04:30 -08001207 * @slot: ACPI PHP slot
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 */
1209int acpiphp_enable_slot(struct acpiphp_slot *slot)
1210{
1211 int retval;
1212
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001213 mutex_lock(&slot->crit_sect);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
1215 /* wake up all functions */
1216 retval = power_on_slot(slot);
1217 if (retval)
1218 goto err_exit;
1219
MUNEDA Takahirocde0e5d2006-03-22 14:49:33 +09001220 if (get_slot_status(slot) == ACPI_STA_ALL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 /* configure all functions */
1222 retval = enable_device(slot);
MUNEDA Takahirocde0e5d2006-03-22 14:49:33 +09001223 if (retval)
1224 power_off_slot(slot);
1225 } else {
Harvey Harrison66bef8c2008-03-03 19:09:46 -08001226 dbg("%s: Slot status is not ACPI_STA_ALL\n", __func__);
MUNEDA Takahirocde0e5d2006-03-22 14:49:33 +09001227 power_off_slot(slot);
1228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 err_exit:
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001231 mutex_unlock(&slot->crit_sect);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 return retval;
1233}
1234
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235/**
1236 * acpiphp_disable_slot - power off slot
Randy Dunlap26e6c662007-11-28 09:04:30 -08001237 * @slot: ACPI PHP slot
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 */
1239int acpiphp_disable_slot(struct acpiphp_slot *slot)
1240{
1241 int retval = 0;
1242
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001243 mutex_lock(&slot->crit_sect);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
1245 /* unconfigure all functions */
1246 retval = disable_device(slot);
1247 if (retval)
1248 goto err_exit;
1249
1250 /* power off all functions */
1251 retval = power_off_slot(slot);
1252 if (retval)
1253 goto err_exit;
1254
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 err_exit:
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001256 mutex_unlock(&slot->crit_sect);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 return retval;
1258}
1259
1260
1261/*
1262 * slot enabled: 1
1263 * slot disabled: 0
1264 */
1265u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
1266{
Rajesh Shah8d50e332005-04-28 00:25:57 -07001267 return (slot->flags & SLOT_POWEREDON);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268}
1269
1270
1271/*
MUNEDA Takahiro35ae61a2006-10-25 11:44:57 -07001272 * latch open: 1
1273 * latch closed: 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 */
1275u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1276{
1277 unsigned int sta;
1278
1279 sta = get_slot_status(slot);
1280
Jiang Liuce15d872013-04-12 05:44:19 +00001281 return (sta & ACPI_STA_DEVICE_UI) ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282}
1283
1284
1285/*
1286 * adapter presence : 1
1287 * absence : 0
1288 */
1289u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1290{
1291 unsigned int sta;
1292
1293 sta = get_slot_status(slot);
1294
1295 return (sta == 0) ? 0 : 1;
1296}