blob: d370f999782e9575793299203154d5970e695eb9 [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 *
29 * Send feedback to <t-kochi@bq.jp.nec.com>
30 *
31 */
32
Rajesh Shah42f49a62005-04-28 00:25:53 -070033/*
34 * Lifetime rules for pci_dev:
35 * - The one in acpiphp_func has its refcount elevated by pci_get_slot()
36 * when the driver is loaded or when an insertion event occurs. It loses
37 * a refcount when its ejected or the driver unloads.
38 * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot()
39 * when the bridge is scanned and it loses a refcount when the bridge
40 * is removed.
41 */
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/init.h>
44#include <linux/module.h>
45
46#include <linux/kernel.h>
47#include <linux/pci.h>
48#include <linux/smp_lock.h>
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +010049#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#include "../pci.h"
52#include "pci_hotplug.h"
53#include "acpiphp.h"
54
55static LIST_HEAD(bridge_list);
56
57#define MY_NAME "acpiphp_glue"
58
59static void handle_hotplug_event_bridge (acpi_handle, u32, void *);
Kristen Accardi8e5dce32005-10-18 17:21:40 -070060static void acpiphp_sanitize_bus(struct pci_bus *bus);
61static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus);
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64/*
65 * initialization & terminatation routines
66 */
67
68/**
69 * is_ejectable - determine if a slot is ejectable
70 * @handle: handle to acpi namespace
71 *
72 * Ejectable slot should satisfy at least these conditions:
73 *
74 * 1. has _ADR method
75 * 2. has _EJ0 method
76 *
77 * optionally
78 *
79 * 1. has _STA method
80 * 2. has _PS0 method
81 * 3. has _PS3 method
82 * 4. ..
83 *
84 */
85static int is_ejectable(acpi_handle handle)
86{
87 acpi_status status;
88 acpi_handle tmp;
89
90 status = acpi_get_handle(handle, "_ADR", &tmp);
91 if (ACPI_FAILURE(status)) {
92 return 0;
93 }
94
95 status = acpi_get_handle(handle, "_EJ0", &tmp);
96 if (ACPI_FAILURE(status)) {
97 return 0;
98 }
99
100 return 1;
101}
102
103
104/* callback routine to check the existence of ejectable slots */
105static acpi_status
106is_ejectable_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
107{
108 int *count = (int *)context;
109
110 if (is_ejectable(handle)) {
111 (*count)++;
112 /* only one ejectable slot is enough */
113 return AE_CTRL_TERMINATE;
114 } else {
115 return AE_OK;
116 }
117}
118
119
120/* callback routine to register each ACPI PCI slot object */
121static acpi_status
122register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
123{
124 struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context;
125 struct acpiphp_slot *slot;
126 struct acpiphp_func *newfunc;
Kristen Accardi20416ea2006-02-23 17:56:03 -0800127 struct dependent_device *dd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 acpi_handle tmp;
129 acpi_status status = AE_OK;
130 unsigned long adr, sun;
MUNEDA Takahiroe27da382006-02-23 17:56:08 -0800131 int device, function, retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
134
135 if (ACPI_FAILURE(status))
136 return AE_OK;
137
138 status = acpi_get_handle(handle, "_EJ0", &tmp);
139
Kristen Accardi20416ea2006-02-23 17:56:03 -0800140 if (ACPI_FAILURE(status) && !(is_dependent_device(handle)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 return AE_OK;
142
143 device = (adr >> 16) & 0xffff;
144 function = adr & 0xffff;
145
Eric Sesterhennf5afe802006-02-28 15:34:49 +0100146 newfunc = kzalloc(sizeof(struct acpiphp_func), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 if (!newfunc)
148 return AE_NO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 INIT_LIST_HEAD(&newfunc->sibling);
151 newfunc->handle = handle;
152 newfunc->function = function;
Kristen Accardi20416ea2006-02-23 17:56:03 -0800153 if (ACPI_SUCCESS(status))
154 newfunc->flags = FUNC_HAS_EJ0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 if (ACPI_SUCCESS(acpi_get_handle(handle, "_STA", &tmp)))
157 newfunc->flags |= FUNC_HAS_STA;
158
159 if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS0", &tmp)))
160 newfunc->flags |= FUNC_HAS_PS0;
161
162 if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS3", &tmp)))
163 newfunc->flags |= FUNC_HAS_PS3;
164
Kristen Accardi20416ea2006-02-23 17:56:03 -0800165 if (ACPI_SUCCESS(acpi_get_handle(handle, "_DCK", &tmp))) {
166 newfunc->flags |= FUNC_HAS_DCK;
167 /* add to devices dependent on dock station,
168 * because this may actually be the dock bridge
169 */
170 dd = alloc_dependent_device(handle);
171 if (!dd)
172 err("Can't allocate memory for "
173 "new dependent device!\n");
174 else
175 add_dependent_device(dd);
176 }
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
179 if (ACPI_FAILURE(status))
180 sun = -1;
181
182 /* search for objects that share the same slot */
183 for (slot = bridge->slots; slot; slot = slot->next)
184 if (slot->device == device) {
185 if (slot->sun != sun)
186 warn("sibling found, but _SUN doesn't match!\n");
187 break;
188 }
189
190 if (!slot) {
Eric Sesterhennf5afe802006-02-28 15:34:49 +0100191 slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 if (!slot) {
193 kfree(newfunc);
194 return AE_NO_MEMORY;
195 }
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 slot->bridge = bridge;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 slot->device = device;
199 slot->sun = sun;
200 INIT_LIST_HEAD(&slot->funcs);
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +0100201 mutex_init(&slot->crit_sect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 slot->next = bridge->slots;
204 bridge->slots = slot;
205
206 bridge->nr_slots++;
207
Rajesh Shah42f49a62005-04-28 00:25:53 -0700208 dbg("found ACPI PCI Hotplug slot %d at PCI %04x:%02x:%02x\n",
209 slot->sun, pci_domain_nr(bridge->pci_bus),
210 bridge->pci_bus->number, slot->device);
MUNEDA Takahiroe27da382006-02-23 17:56:08 -0800211 retval = acpiphp_register_hotplug_slot(slot);
212 if (retval) {
213 warn("acpiphp_register_hotplug_slot failed(err code = 0x%x)\n", retval);
214 goto err_exit;
215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 }
217
218 newfunc->slot = slot;
219 list_add_tail(&newfunc->sibling, &slot->funcs);
220
221 /* associate corresponding pci_dev */
Rajesh Shah42f49a62005-04-28 00:25:53 -0700222 newfunc->pci_dev = pci_get_slot(bridge->pci_bus,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 PCI_DEVFN(device, function));
224 if (newfunc->pci_dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
226 }
227
Kristen Accardi20416ea2006-02-23 17:56:03 -0800228 /* if this is a device dependent on a dock station,
229 * associate the acpiphp_func to the dependent_device
230 * struct.
231 */
232 if ((dd = get_dependent_device(handle))) {
233 newfunc->flags |= FUNC_IS_DD;
234 /*
235 * we don't want any devices which is dependent
236 * on the dock to have it's _EJ0 method executed.
237 * because we need to run _DCK first.
238 */
239 newfunc->flags &= ~FUNC_HAS_EJ0;
240 dd->func = newfunc;
241 add_pci_dependent_device(dd);
242 }
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 /* install notify handler */
Kristen Accardi20416ea2006-02-23 17:56:03 -0800245 if (!(newfunc->flags & FUNC_HAS_DCK)) {
246 status = acpi_install_notify_handler(handle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 ACPI_SYSTEM_NOTIFY,
248 handle_hotplug_event_func,
249 newfunc);
250
Kristen Accardi20416ea2006-02-23 17:56:03 -0800251 if (ACPI_FAILURE(status))
252 err("failed to register interrupt notify handler\n");
253 } else
254 status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Kristen Accardi20416ea2006-02-23 17:56:03 -0800256 return status;
MUNEDA Takahiroe27da382006-02-23 17:56:08 -0800257
258 err_exit:
259 bridge->nr_slots--;
260 bridge->slots = slot->next;
261 kfree(slot);
262 kfree(newfunc);
263
264 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265}
266
267
268/* see if it's worth looking at this bridge */
269static int detect_ejectable_slots(acpi_handle *bridge_handle)
270{
271 acpi_status status;
272 int count;
273
274 count = 0;
275
276 /* only check slots defined directly below bridge object */
277 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle, (u32)1,
278 is_ejectable_slot, (void *)&count, NULL);
279
280 return count;
281}
282
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284/* decode ACPI 2.0 _HPP hot plug parameters */
285static void decode_hpp(struct acpiphp_bridge *bridge)
286{
287 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900289 status = acpi_get_hp_params_from_firmware(bridge->pci_bus, &bridge->hpp);
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900290 if (ACPI_FAILURE(status) ||
291 !bridge->hpp.t0 || (bridge->hpp.t0->revision > 1)) {
Kristen Accardi783c49f2006-03-03 10:16:05 -0800292 /* use default numbers */
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900293 printk(KERN_WARNING
294 "%s: Could not get hotplug parameters. Use defaults\n",
295 __FUNCTION__);
296 bridge->hpp.t0 = &bridge->hpp.type0_data;
297 bridge->hpp.t0->revision = 0;
298 bridge->hpp.t0->cache_line_size = 0x10;
299 bridge->hpp.t0->latency_timer = 0x40;
300 bridge->hpp.t0->enable_serr = 0;
301 bridge->hpp.t0->enable_perr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303}
304
305
Kristen Accardi783c49f2006-03-03 10:16:05 -0800306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307/* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */
308static void init_bridge_misc(struct acpiphp_bridge *bridge)
309{
310 acpi_status status;
311
312 /* decode ACPI 2.0 _HPP (hot plug parameters) */
313 decode_hpp(bridge);
314
MUNEDA Takahiroe27da382006-02-23 17:56:08 -0800315 /* must be added to the list prior to calling register_slot */
316 list_add(&bridge->list, &bridge_list);
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 /* register all slot objects under this bridge */
319 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1,
320 register_slot, bridge, NULL);
MUNEDA Takahiroe27da382006-02-23 17:56:08 -0800321 if (ACPI_FAILURE(status)) {
322 list_del(&bridge->list);
323 return;
324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 /* install notify handler */
Rajesh Shah8e7561c2005-04-28 00:25:56 -0700327 if (bridge->type != BRIDGE_TYPE_HOST) {
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900328 if ((bridge->flags & BRIDGE_HAS_EJ0) && bridge->func) {
329 status = acpi_remove_notify_handler(bridge->func->handle,
330 ACPI_SYSTEM_NOTIFY,
331 handle_hotplug_event_func);
332 if (ACPI_FAILURE(status))
333 err("failed to remove notify handler\n");
334 }
Rajesh Shah8e7561c2005-04-28 00:25:56 -0700335 status = acpi_install_notify_handler(bridge->handle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 ACPI_SYSTEM_NOTIFY,
337 handle_hotplug_event_bridge,
338 bridge);
339
Rajesh Shah8e7561c2005-04-28 00:25:56 -0700340 if (ACPI_FAILURE(status)) {
341 err("failed to register interrupt notify handler\n");
342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344}
345
346
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900347/* find acpiphp_func from acpiphp_bridge */
348static struct acpiphp_func *acpiphp_bridge_handle_to_function(acpi_handle handle)
349{
350 struct list_head *node, *l;
351 struct acpiphp_bridge *bridge;
352 struct acpiphp_slot *slot;
353 struct acpiphp_func *func;
354
355 list_for_each(node, &bridge_list) {
356 bridge = list_entry(node, struct acpiphp_bridge, list);
357 for (slot = bridge->slots; slot; slot = slot->next) {
358 list_for_each(l, &slot->funcs) {
359 func = list_entry(l, struct acpiphp_func,
360 sibling);
361 if (func->handle == handle)
362 return func;
363 }
364 }
365 }
366
367 return NULL;
368}
369
370
371static inline void config_p2p_bridge_flags(struct acpiphp_bridge *bridge)
372{
373 acpi_handle dummy_handle;
374
375 if (ACPI_SUCCESS(acpi_get_handle(bridge->handle,
376 "_STA", &dummy_handle)))
377 bridge->flags |= BRIDGE_HAS_STA;
378
379 if (ACPI_SUCCESS(acpi_get_handle(bridge->handle,
380 "_EJ0", &dummy_handle)))
381 bridge->flags |= BRIDGE_HAS_EJ0;
382
383 if (ACPI_SUCCESS(acpi_get_handle(bridge->handle,
384 "_PS0", &dummy_handle)))
385 bridge->flags |= BRIDGE_HAS_PS0;
386
387 if (ACPI_SUCCESS(acpi_get_handle(bridge->handle,
388 "_PS3", &dummy_handle)))
389 bridge->flags |= BRIDGE_HAS_PS3;
390
391 /* is this ejectable p2p bridge? */
392 if (bridge->flags & BRIDGE_HAS_EJ0) {
393 struct acpiphp_func *func;
394
395 dbg("found ejectable p2p bridge\n");
396
397 /* make link between PCI bridge and PCI function */
398 func = acpiphp_bridge_handle_to_function(bridge->handle);
399 if (!func)
400 return;
401 bridge->func = func;
402 func->bridge = bridge;
403 }
404}
405
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407/* allocate and initialize host bridge data structure */
Rajesh Shah42f49a62005-04-28 00:25:53 -0700408static void add_host_bridge(acpi_handle *handle, struct pci_bus *pci_bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 struct acpiphp_bridge *bridge;
411
Eric Sesterhennf5afe802006-02-28 15:34:49 +0100412 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 if (bridge == NULL)
414 return;
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 bridge->type = BRIDGE_TYPE_HOST;
417 bridge->handle = handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Rajesh Shah42f49a62005-04-28 00:25:53 -0700419 bridge->pci_bus = pci_bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421 spin_lock_init(&bridge->res_lock);
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 init_bridge_misc(bridge);
424}
425
426
427/* allocate and initialize PCI-to-PCI bridge data structure */
Rajesh Shah42f49a62005-04-28 00:25:53 -0700428static void add_p2p_bridge(acpi_handle *handle, struct pci_dev *pci_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
430 struct acpiphp_bridge *bridge;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Eric Sesterhennf5afe802006-02-28 15:34:49 +0100432 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 if (bridge == NULL) {
434 err("out of memory\n");
435 return;
436 }
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 bridge->type = BRIDGE_TYPE_P2P;
439 bridge->handle = handle;
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900440 config_p2p_bridge_flags(bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Rajesh Shah42f49a62005-04-28 00:25:53 -0700442 bridge->pci_dev = pci_dev_get(pci_dev);
443 bridge->pci_bus = pci_dev->subordinate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 if (!bridge->pci_bus) {
445 err("This is not a PCI-to-PCI bridge!\n");
Rajesh Shah42f49a62005-04-28 00:25:53 -0700446 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 }
448
449 spin_lock_init(&bridge->res_lock);
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 init_bridge_misc(bridge);
Rajesh Shah42f49a62005-04-28 00:25:53 -0700452 return;
453 err:
454 pci_dev_put(pci_dev);
455 kfree(bridge);
456 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457}
458
459
460/* callback routine to find P2P bridges */
461static acpi_status
462find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
463{
464 acpi_status status;
465 acpi_handle dummy_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 unsigned long tmp;
Rajesh Shah42f49a62005-04-28 00:25:53 -0700467 int device, function;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 struct pci_dev *dev;
Rajesh Shah42f49a62005-04-28 00:25:53 -0700469 struct pci_bus *pci_bus = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 status = acpi_get_handle(handle, "_ADR", &dummy_handle);
472 if (ACPI_FAILURE(status))
473 return AE_OK; /* continue */
474
475 status = acpi_evaluate_integer(handle, "_ADR", NULL, &tmp);
476 if (ACPI_FAILURE(status)) {
477 dbg("%s: _ADR evaluation failure\n", __FUNCTION__);
478 return AE_OK;
479 }
480
481 device = (tmp >> 16) & 0xffff;
482 function = tmp & 0xffff;
483
Rajesh Shah42f49a62005-04-28 00:25:53 -0700484 dev = pci_get_slot(pci_bus, PCI_DEVFN(device, function));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Rajesh Shah42f49a62005-04-28 00:25:53 -0700486 if (!dev || !dev->subordinate)
487 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 /* check if this bridge has ejectable slots */
Kristen Accardi20416ea2006-02-23 17:56:03 -0800490 if ((detect_ejectable_slots(handle) > 0) ||
491 (detect_dependent_devices(handle) > 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev));
Rajesh Shah42f49a62005-04-28 00:25:53 -0700493 add_p2p_bridge(handle, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 }
495
Kenji Kaneshige7c8f25d2006-02-27 22:15:49 +0900496 /* search P2P bridges under this p2p bridge */
497 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
498 find_p2p_bridge, dev->subordinate, NULL);
499 if (ACPI_FAILURE(status))
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900500 warn("find_p2p_bridge failed (error code = 0x%x)\n", status);
Kenji Kaneshige7c8f25d2006-02-27 22:15:49 +0900501
Rajesh Shah42f49a62005-04-28 00:25:53 -0700502 out:
503 pci_dev_put(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 return AE_OK;
505}
506
507
508/* find hot-pluggable slots, and then find P2P bridge */
509static int add_bridge(acpi_handle handle)
510{
511 acpi_status status;
512 unsigned long tmp;
513 int seg, bus;
514 acpi_handle dummy_handle;
Rajesh Shah42f49a62005-04-28 00:25:53 -0700515 struct pci_bus *pci_bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 /* if the bridge doesn't have _STA, we assume it is always there */
518 status = acpi_get_handle(handle, "_STA", &dummy_handle);
519 if (ACPI_SUCCESS(status)) {
520 status = acpi_evaluate_integer(handle, "_STA", NULL, &tmp);
521 if (ACPI_FAILURE(status)) {
522 dbg("%s: _STA evaluation failure\n", __FUNCTION__);
523 return 0;
524 }
525 if ((tmp & ACPI_STA_FUNCTIONING) == 0)
526 /* don't register this object */
527 return 0;
528 }
529
530 /* get PCI segment number */
531 status = acpi_evaluate_integer(handle, "_SEG", NULL, &tmp);
532
533 seg = ACPI_SUCCESS(status) ? tmp : 0;
534
535 /* get PCI bus number */
536 status = acpi_evaluate_integer(handle, "_BBN", NULL, &tmp);
537
538 if (ACPI_SUCCESS(status)) {
539 bus = tmp;
540 } else {
541 warn("can't get bus number, assuming 0\n");
542 bus = 0;
543 }
544
Rajesh Shah42f49a62005-04-28 00:25:53 -0700545 pci_bus = pci_find_bus(seg, bus);
546 if (!pci_bus) {
547 err("Can't find bus %04x:%02x\n", seg, bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 return 0;
549 }
550
Rajesh Shah42f49a62005-04-28 00:25:53 -0700551 /* check if this bridge has ejectable slots */
552 if (detect_ejectable_slots(handle) > 0) {
553 dbg("found PCI host-bus bridge with hot-pluggable slots\n");
554 add_host_bridge(handle, pci_bus);
Rajesh Shah42f49a62005-04-28 00:25:53 -0700555 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 /* search P2P bridges under this host bridge */
558 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
Rajesh Shah42f49a62005-04-28 00:25:53 -0700559 find_p2p_bridge, pci_bus, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
561 if (ACPI_FAILURE(status))
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900562 warn("find_p2p_bridge failed (error code = 0x%x)\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564 return 0;
565}
566
Rajesh Shah42f49a62005-04-28 00:25:53 -0700567static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
568{
569 struct list_head *head;
570 list_for_each(head, &bridge_list) {
571 struct acpiphp_bridge *bridge = list_entry(head,
572 struct acpiphp_bridge, list);
573 if (bridge->handle == handle)
574 return bridge;
575 }
576
577 return NULL;
578}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Rajesh Shah364d5092005-04-28 00:25:54 -0700580static void cleanup_bridge(struct acpiphp_bridge *bridge)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Rajesh Shah42f49a62005-04-28 00:25:53 -0700582 struct list_head *list, *tmp;
Rajesh Shah42f49a62005-04-28 00:25:53 -0700583 struct acpiphp_slot *slot;
584 acpi_status status;
Rajesh Shah364d5092005-04-28 00:25:54 -0700585 acpi_handle handle = bridge->handle;
Rajesh Shah42f49a62005-04-28 00:25:53 -0700586
587 status = acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
588 handle_hotplug_event_bridge);
589 if (ACPI_FAILURE(status))
590 err("failed to remove notify handler\n");
591
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900592 if ((bridge->type != BRIDGE_TYPE_HOST) &&
593 ((bridge->flags & BRIDGE_HAS_EJ0) && bridge->func)) {
594 status = acpi_install_notify_handler(bridge->func->handle,
595 ACPI_SYSTEM_NOTIFY,
596 handle_hotplug_event_func,
597 bridge->func);
598 if (ACPI_FAILURE(status))
599 err("failed to install interrupt notify handler\n");
600 }
601
Rajesh Shah42f49a62005-04-28 00:25:53 -0700602 slot = bridge->slots;
603 while (slot) {
604 struct acpiphp_slot *next = slot->next;
605 list_for_each_safe (list, tmp, &slot->funcs) {
606 struct acpiphp_func *func;
607 func = list_entry(list, struct acpiphp_func, sibling);
Kristen Accardi20416ea2006-02-23 17:56:03 -0800608 if (!(func->flags & FUNC_HAS_DCK)) {
609 status = acpi_remove_notify_handler(func->handle,
Rajesh Shah42f49a62005-04-28 00:25:53 -0700610 ACPI_SYSTEM_NOTIFY,
611 handle_hotplug_event_func);
Kristen Accardi20416ea2006-02-23 17:56:03 -0800612 if (ACPI_FAILURE(status))
613 err("failed to remove notify handler\n");
614 }
Rajesh Shah42f49a62005-04-28 00:25:53 -0700615 pci_dev_put(func->pci_dev);
616 list_del(list);
617 kfree(func);
618 }
MUNEDA Takahiroe27da382006-02-23 17:56:08 -0800619 acpiphp_unregister_hotplug_slot(slot);
620 list_del(&slot->funcs);
Rajesh Shah42f49a62005-04-28 00:25:53 -0700621 kfree(slot);
622 slot = next;
623 }
624
625 pci_dev_put(bridge->pci_dev);
626 list_del(&bridge->list);
627 kfree(bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628}
629
Rajesh Shah364d5092005-04-28 00:25:54 -0700630static acpi_status
631cleanup_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
632{
633 struct acpiphp_bridge *bridge;
634
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900635 /* cleanup p2p bridges under this P2P bridge
636 in a depth-first manner */
637 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
638 cleanup_p2p_bridge, NULL, NULL);
639
Rajesh Shah364d5092005-04-28 00:25:54 -0700640 if (!(bridge = acpiphp_handle_to_bridge(handle)))
641 return AE_OK;
642 cleanup_bridge(bridge);
643 return AE_OK;
644}
645
646static void remove_bridge(acpi_handle handle)
647{
648 struct acpiphp_bridge *bridge;
649
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900650 /* cleanup p2p bridges under this host bridge
651 in a depth-first manner */
652 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
653 (u32)1, cleanup_p2p_bridge, NULL, NULL);
654
Rajesh Shah364d5092005-04-28 00:25:54 -0700655 bridge = acpiphp_handle_to_bridge(handle);
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900656 if (bridge)
Rajesh Shah364d5092005-04-28 00:25:54 -0700657 cleanup_bridge(bridge);
Rajesh Shah364d5092005-04-28 00:25:54 -0700658}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Kenji Kaneshigea0d399a2005-04-28 00:25:59 -0700660static struct pci_dev * get_apic_pci_info(acpi_handle handle)
661{
662 struct acpi_pci_id id;
663 struct pci_bus *bus;
664 struct pci_dev *dev;
665
666 if (ACPI_FAILURE(acpi_get_pci_id(handle, &id)))
667 return NULL;
668
669 bus = pci_find_bus(id.segment, id.bus);
670 if (!bus)
671 return NULL;
672
673 dev = pci_get_slot(bus, PCI_DEVFN(id.device, id.function));
674 if (!dev)
675 return NULL;
676
677 if ((dev->class != PCI_CLASS_SYSTEM_PIC_IOAPIC) &&
678 (dev->class != PCI_CLASS_SYSTEM_PIC_IOXAPIC))
679 {
680 pci_dev_put(dev);
681 return NULL;
682 }
683
684 return dev;
685}
686
687static int get_gsi_base(acpi_handle handle, u32 *gsi_base)
688{
689 acpi_status status;
690 int result = -1;
691 unsigned long gsb;
692 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
693 union acpi_object *obj;
694 void *table;
695
696 status = acpi_evaluate_integer(handle, "_GSB", NULL, &gsb);
697 if (ACPI_SUCCESS(status)) {
698 *gsi_base = (u32)gsb;
699 return 0;
700 }
701
702 status = acpi_evaluate_object(handle, "_MAT", NULL, &buffer);
703 if (ACPI_FAILURE(status) || !buffer.length || !buffer.pointer)
704 return -1;
705
706 obj = buffer.pointer;
707 if (obj->type != ACPI_TYPE_BUFFER)
708 goto out;
709
710 table = obj->buffer.pointer;
711 switch (((acpi_table_entry_header *)table)->type) {
712 case ACPI_MADT_IOSAPIC:
713 *gsi_base = ((struct acpi_table_iosapic *)table)->global_irq_base;
714 result = 0;
715 break;
716 case ACPI_MADT_IOAPIC:
717 *gsi_base = ((struct acpi_table_ioapic *)table)->global_irq_base;
718 result = 0;
719 break;
720 default:
721 break;
722 }
723 out:
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700724 kfree(buffer.pointer);
Kenji Kaneshigea0d399a2005-04-28 00:25:59 -0700725 return result;
726}
727
728static acpi_status
729ioapic_add(acpi_handle handle, u32 lvl, void *context, void **rv)
730{
731 acpi_status status;
732 unsigned long sta;
733 acpi_handle tmp;
734 struct pci_dev *pdev;
735 u32 gsi_base;
736 u64 phys_addr;
737
738 /* Evaluate _STA if present */
739 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
740 if (ACPI_SUCCESS(status) && sta != ACPI_STA_ALL)
741 return AE_CTRL_DEPTH;
742
743 /* Scan only PCI bus scope */
744 status = acpi_get_handle(handle, "_HID", &tmp);
745 if (ACPI_SUCCESS(status))
746 return AE_CTRL_DEPTH;
747
748 if (get_gsi_base(handle, &gsi_base))
749 return AE_OK;
750
751 pdev = get_apic_pci_info(handle);
752 if (!pdev)
753 return AE_OK;
754
755 if (pci_enable_device(pdev)) {
756 pci_dev_put(pdev);
757 return AE_OK;
758 }
759
760 pci_set_master(pdev);
761
762 if (pci_request_region(pdev, 0, "I/O APIC(acpiphp)")) {
763 pci_disable_device(pdev);
764 pci_dev_put(pdev);
765 return AE_OK;
766 }
767
768 phys_addr = pci_resource_start(pdev, 0);
769 if (acpi_register_ioapic(handle, phys_addr, gsi_base)) {
770 pci_release_region(pdev, 0);
771 pci_disable_device(pdev);
772 pci_dev_put(pdev);
773 return AE_OK;
774 }
775
776 return AE_OK;
777}
778
779static int acpiphp_configure_ioapics(acpi_handle handle)
780{
781 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
782 ACPI_UINT32_MAX, ioapic_add, NULL, NULL);
783 return 0;
784}
785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786static int power_on_slot(struct acpiphp_slot *slot)
787{
788 acpi_status status;
789 struct acpiphp_func *func;
790 struct list_head *l;
791 int retval = 0;
792
793 /* if already enabled, just skip */
794 if (slot->flags & SLOT_POWEREDON)
795 goto err_exit;
796
797 list_for_each (l, &slot->funcs) {
798 func = list_entry(l, struct acpiphp_func, sibling);
799
800 if (func->flags & FUNC_HAS_PS0) {
801 dbg("%s: executing _PS0\n", __FUNCTION__);
802 status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL);
803 if (ACPI_FAILURE(status)) {
804 warn("%s: _PS0 failed\n", __FUNCTION__);
805 retval = -1;
806 goto err_exit;
807 } else
808 break;
809 }
810 }
811
812 /* TBD: evaluate _STA to check if the slot is enabled */
813
814 slot->flags |= SLOT_POWEREDON;
815
816 err_exit:
817 return retval;
818}
819
820
821static int power_off_slot(struct acpiphp_slot *slot)
822{
823 acpi_status status;
824 struct acpiphp_func *func;
825 struct list_head *l;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 int retval = 0;
828
829 /* if already disabled, just skip */
830 if ((slot->flags & SLOT_POWEREDON) == 0)
831 goto err_exit;
832
833 list_for_each (l, &slot->funcs) {
834 func = list_entry(l, struct acpiphp_func, sibling);
835
Rajesh Shah2f523b12005-04-28 00:25:55 -0700836 if (func->flags & FUNC_HAS_PS3) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL);
838 if (ACPI_FAILURE(status)) {
839 warn("%s: _PS3 failed\n", __FUNCTION__);
840 retval = -1;
841 goto err_exit;
842 } else
843 break;
844 }
845 }
846
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 /* TBD: evaluate _STA to check if the slot is disabled */
848
849 slot->flags &= (~SLOT_POWEREDON);
850
851 err_exit:
852 return retval;
853}
854
855
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800856
857/**
858 * acpiphp_max_busnr - return the highest reserved bus number under
859 * the given bus.
860 * @bus: bus to start search with
861 *
862 */
863static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
864{
865 struct list_head *tmp;
866 unsigned char max, n;
867
868 /*
869 * pci_bus_max_busnr will return the highest
870 * reserved busnr for all these children.
871 * that is equivalent to the bus->subordinate
872 * value. We don't want to use the parent's
873 * bus->subordinate value because it could have
874 * padding in it.
875 */
876 max = bus->secondary;
877
878 list_for_each(tmp, &bus->children) {
879 n = pci_bus_max_busnr(pci_bus_b(tmp));
880 if (n > max)
881 max = n;
882 }
883 return max;
884}
885
886
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800887/**
888 * acpiphp_bus_add - add a new bus to acpi subsystem
889 * @func: acpiphp_func of the bridge
890 *
891 */
892static int acpiphp_bus_add(struct acpiphp_func *func)
893{
894 acpi_handle phandle;
895 struct acpi_device *device, *pdevice;
896 int ret_val;
897
898 acpi_get_parent(func->handle, &phandle);
899 if (acpi_bus_get_device(phandle, &pdevice)) {
900 dbg("no parent device, assuming NULL\n");
901 pdevice = NULL;
902 }
Kristen Accardi20416ea2006-02-23 17:56:03 -0800903 if (!acpi_bus_get_device(func->handle, &device)) {
904 dbg("bus exists... trim\n");
905 /* this shouldn't be in here, so remove
906 * the bus then re-add it...
907 */
908 ret_val = acpi_bus_trim(device, 1);
909 dbg("acpi_bus_trim return %x\n", ret_val);
910 }
911
912 ret_val = acpi_bus_add(&device, pdevice, func->handle,
913 ACPI_BUS_TYPE_DEVICE);
914 if (ret_val) {
915 dbg("error adding bus, %x\n",
916 -ret_val);
917 goto acpiphp_bus_add_out;
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800918 }
919 /*
920 * try to start anyway. We could have failed to add
921 * simply because this bus had previously been added
922 * on another add. Don't bother with the return value
923 * we just keep going.
924 */
925 ret_val = acpi_bus_start(device);
926
927acpiphp_bus_add_out:
928 return ret_val;
929}
930
931
MUNEDA Takahiro92c9be92006-03-22 14:49:09 +0900932/**
933 * acpiphp_bus_trim - trim a bus from acpi subsystem
934 * @handle: handle to acpi namespace
935 *
936 */
937int acpiphp_bus_trim(acpi_handle handle)
938{
939 struct acpi_device *device;
940 int retval;
941
942 retval = acpi_bus_get_device(handle, &device);
943 if (retval) {
944 dbg("acpi_device not found\n");
945 return retval;
946 }
947
948 retval = acpi_bus_trim(device, 1);
949 if (retval)
950 err("cannot remove from acpi list\n");
951
952 return retval;
953}
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955/**
956 * enable_device - enable, configure a slot
957 * @slot: slot to be enabled
958 *
959 * This function should be called per *physical slot*,
960 * not per each slot object in ACPI namespace.
961 *
962 */
963static int enable_device(struct acpiphp_slot *slot)
964{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 struct pci_dev *dev;
Rajesh Shah42f49a62005-04-28 00:25:53 -0700966 struct pci_bus *bus = slot->bridge->pci_bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 struct list_head *l;
968 struct acpiphp_func *func;
969 int retval = 0;
Rajesh Shah42f49a62005-04-28 00:25:53 -0700970 int num, max, pass;
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +0900971 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 if (slot->flags & SLOT_ENABLED)
974 goto err_exit;
975
976 /* sanity check: dev should be NULL when hot-plugged in */
Rajesh Shah42f49a62005-04-28 00:25:53 -0700977 dev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 if (dev) {
979 /* This case shouldn't happen */
980 err("pci_dev structure already exists.\n");
Rajesh Shah42f49a62005-04-28 00:25:53 -0700981 pci_dev_put(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 retval = -1;
983 goto err_exit;
984 }
985
Rajesh Shah42f49a62005-04-28 00:25:53 -0700986 num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0));
987 if (num == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 err("No new device found\n");
989 retval = -1;
990 goto err_exit;
991 }
992
Kristen Accardi15a1ae72006-02-23 17:55:58 -0800993 max = acpiphp_max_busnr(bus);
Rajesh Shah42f49a62005-04-28 00:25:53 -0700994 for (pass = 0; pass < 2; pass++) {
995 list_for_each_entry(dev, &bus->devices, bus_list) {
996 if (PCI_SLOT(dev->devfn) != slot->device)
997 continue;
998 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
Kristen Accardic64b5ee2005-12-14 09:37:26 -0800999 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
Rajesh Shah42f49a62005-04-28 00:25:53 -07001000 max = pci_scan_bridge(bus, dev, max, pass);
MUNEDA Takahiro92c9be92006-03-22 14:49:09 +09001001 if (pass && dev->subordinate)
Kristen Accardic64b5ee2005-12-14 09:37:26 -08001002 pci_bus_size_bridges(dev->subordinate);
1003 }
Rajesh Shah42f49a62005-04-28 00:25:53 -07001004 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 }
1006
MUNEDA Takahiro92c9be92006-03-22 14:49:09 +09001007 list_for_each (l, &slot->funcs) {
1008 func = list_entry(l, struct acpiphp_func, sibling);
1009 acpiphp_bus_add(func);
1010 }
1011
Rajesh Shah42f49a62005-04-28 00:25:53 -07001012 pci_bus_assign_resources(bus);
Kristen Accardi8e5dce32005-10-18 17:21:40 -07001013 acpiphp_sanitize_bus(bus);
1014 pci_enable_bridges(bus);
Rajesh Shah42f49a62005-04-28 00:25:53 -07001015 pci_bus_add_devices(bus);
MUNEDA Takahiro0cccd0c2006-02-24 17:46:04 +09001016 acpiphp_set_hpp_values(slot->bridge->handle, bus);
1017 acpiphp_configure_ioapics(slot->bridge->handle);
Rajesh Shah42f49a62005-04-28 00:25:53 -07001018
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 /* associate pci_dev to our representation */
1020 list_for_each (l, &slot->funcs) {
1021 func = list_entry(l, struct acpiphp_func, sibling);
Rajesh Shah42f49a62005-04-28 00:25:53 -07001022 func->pci_dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 func->function));
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +09001024 if (!func->pci_dev)
1025 continue;
1026
1027 if (func->pci_dev->hdr_type != PCI_HEADER_TYPE_BRIDGE &&
1028 func->pci_dev->hdr_type != PCI_HEADER_TYPE_CARDBUS)
1029 continue;
1030
1031 status = find_p2p_bridge(func->handle, (u32)1, bus, NULL);
1032 if (ACPI_FAILURE(status))
1033 warn("find_p2p_bridge failed (error code = 0x%x)\n",
1034 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 }
1036
1037 slot->flags |= SLOT_ENABLED;
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 err_exit:
1040 return retval;
1041}
1042
1043
1044/**
1045 * disable_device - disable a slot
1046 */
1047static int disable_device(struct acpiphp_slot *slot)
1048{
1049 int retval = 0;
1050 struct acpiphp_func *func;
1051 struct list_head *l;
1052
1053 /* is this slot already disabled? */
1054 if (!(slot->flags & SLOT_ENABLED))
1055 goto err_exit;
1056
1057 list_for_each (l, &slot->funcs) {
1058 func = list_entry(l, struct acpiphp_func, sibling);
MUNEDA Takahiro92c9be92006-03-22 14:49:09 +09001059
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +09001060 if (func->bridge) {
1061 /* cleanup p2p bridges under this P2P bridge */
1062 cleanup_p2p_bridge(func->bridge->handle,
1063 (u32)1, NULL, NULL);
1064 func->bridge = NULL;
1065 }
1066
MUNEDA Takahiro92c9be92006-03-22 14:49:09 +09001067 acpiphp_bus_trim(func->handle);
1068 /* try to remove anyway.
1069 * acpiphp_bus_add might have been failed */
1070
Rajesh Shah42f49a62005-04-28 00:25:53 -07001071 if (!func->pci_dev)
1072 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Rajesh Shah42f49a62005-04-28 00:25:53 -07001074 pci_remove_bus_device(func->pci_dev);
1075 pci_dev_put(func->pci_dev);
1076 func->pci_dev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 }
1078
1079 slot->flags &= (~SLOT_ENABLED);
1080
1081 err_exit:
1082 return retval;
1083}
1084
1085
1086/**
1087 * get_slot_status - get ACPI slot status
1088 *
1089 * if a slot has _STA for each function and if any one of them
1090 * returned non-zero status, return it
1091 *
1092 * if a slot doesn't have _STA and if any one of its functions'
1093 * configuration space is configured, return 0x0f as a _STA
1094 *
1095 * otherwise return 0
1096 */
1097static unsigned int get_slot_status(struct acpiphp_slot *slot)
1098{
1099 acpi_status status;
1100 unsigned long sta = 0;
1101 u32 dvid;
1102 struct list_head *l;
1103 struct acpiphp_func *func;
1104
1105 list_for_each (l, &slot->funcs) {
1106 func = list_entry(l, struct acpiphp_func, sibling);
1107
1108 if (func->flags & FUNC_HAS_STA) {
1109 status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta);
1110 if (ACPI_SUCCESS(status) && sta)
1111 break;
1112 } else {
1113 pci_bus_read_config_dword(slot->bridge->pci_bus,
1114 PCI_DEVFN(slot->device,
1115 func->function),
1116 PCI_VENDOR_ID, &dvid);
1117 if (dvid != 0xffffffff) {
1118 sta = ACPI_STA_ALL;
1119 break;
1120 }
1121 }
1122 }
1123
1124 return (unsigned int)sta;
1125}
1126
1127/**
Rajesh Shah8d50e332005-04-28 00:25:57 -07001128 * acpiphp_eject_slot - physically eject the slot
1129 */
1130static int acpiphp_eject_slot(struct acpiphp_slot *slot)
1131{
1132 acpi_status status;
1133 struct acpiphp_func *func;
1134 struct list_head *l;
1135 struct acpi_object_list arg_list;
1136 union acpi_object arg;
1137
1138 list_for_each (l, &slot->funcs) {
1139 func = list_entry(l, struct acpiphp_func, sibling);
1140
1141 /* We don't want to call _EJ0 on non-existing functions. */
1142 if ((func->flags & FUNC_HAS_EJ0)) {
1143 /* _EJ0 method take one argument */
1144 arg_list.count = 1;
1145 arg_list.pointer = &arg;
1146 arg.type = ACPI_TYPE_INTEGER;
1147 arg.integer.value = 1;
1148
1149 status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL);
1150 if (ACPI_FAILURE(status)) {
1151 warn("%s: _EJ0 failed\n", __FUNCTION__);
1152 return -1;
1153 } else
1154 break;
1155 }
1156 }
1157 return 0;
1158}
1159
1160/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 * acpiphp_check_bridge - re-enumerate devices
1162 *
1163 * Iterate over all slots under this bridge and make sure that if a
1164 * card is present they are enabled, and if not they are disabled.
1165 */
1166static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
1167{
1168 struct acpiphp_slot *slot;
1169 int retval = 0;
1170 int enabled, disabled;
1171
1172 enabled = disabled = 0;
1173
1174 for (slot = bridge->slots; slot; slot = slot->next) {
1175 unsigned int status = get_slot_status(slot);
1176 if (slot->flags & SLOT_ENABLED) {
1177 if (status == ACPI_STA_ALL)
1178 continue;
1179 retval = acpiphp_disable_slot(slot);
1180 if (retval) {
1181 err("Error occurred in disabling\n");
1182 goto err_exit;
Rajesh Shah8d50e332005-04-28 00:25:57 -07001183 } else {
1184 acpiphp_eject_slot(slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 }
1186 disabled++;
1187 } else {
1188 if (status != ACPI_STA_ALL)
1189 continue;
1190 retval = acpiphp_enable_slot(slot);
1191 if (retval) {
1192 err("Error occurred in enabling\n");
1193 goto err_exit;
1194 }
1195 enabled++;
1196 }
1197 }
1198
1199 dbg("%s: %d enabled, %d disabled\n", __FUNCTION__, enabled, disabled);
1200
1201 err_exit:
1202 return retval;
1203}
1204
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001205static void program_hpp(struct pci_dev *dev, struct acpiphp_bridge *bridge)
1206{
1207 u16 pci_cmd, pci_bctl;
1208 struct pci_dev *cdev;
1209
1210 /* Program hpp values for this device */
1211 if (!(dev->hdr_type == PCI_HEADER_TYPE_NORMAL ||
1212 (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&
1213 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)))
1214 return;
Kenji Kaneshigee22b73502006-05-02 10:57:14 +09001215
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001216 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
Kenji Kaneshigee22b73502006-05-02 10:57:14 +09001217 bridge->hpp.t0->cache_line_size);
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001218 pci_write_config_byte(dev, PCI_LATENCY_TIMER,
Kenji Kaneshigee22b73502006-05-02 10:57:14 +09001219 bridge->hpp.t0->latency_timer);
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001220 pci_read_config_word(dev, PCI_COMMAND, &pci_cmd);
Kenji Kaneshigee22b73502006-05-02 10:57:14 +09001221 if (bridge->hpp.t0->enable_serr)
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001222 pci_cmd |= PCI_COMMAND_SERR;
1223 else
1224 pci_cmd &= ~PCI_COMMAND_SERR;
Kenji Kaneshigee22b73502006-05-02 10:57:14 +09001225 if (bridge->hpp.t0->enable_perr)
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001226 pci_cmd |= PCI_COMMAND_PARITY;
1227 else
1228 pci_cmd &= ~PCI_COMMAND_PARITY;
1229 pci_write_config_word(dev, PCI_COMMAND, pci_cmd);
1230
1231 /* Program bridge control value and child devices */
1232 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
1233 pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER,
Kenji Kaneshigee22b73502006-05-02 10:57:14 +09001234 bridge->hpp.t0->latency_timer);
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001235 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl);
Kenji Kaneshigee22b73502006-05-02 10:57:14 +09001236 if (bridge->hpp.t0->enable_serr)
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001237 pci_bctl |= PCI_BRIDGE_CTL_SERR;
1238 else
1239 pci_bctl &= ~PCI_BRIDGE_CTL_SERR;
Kenji Kaneshigee22b73502006-05-02 10:57:14 +09001240 if (bridge->hpp.t0->enable_perr)
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001241 pci_bctl |= PCI_BRIDGE_CTL_PARITY;
1242 else
1243 pci_bctl &= ~PCI_BRIDGE_CTL_PARITY;
1244 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, pci_bctl);
1245 if (dev->subordinate) {
1246 list_for_each_entry(cdev, &dev->subordinate->devices,
1247 bus_list)
1248 program_hpp(cdev, bridge);
1249 }
1250 }
1251}
1252
1253static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus)
1254{
1255 struct acpiphp_bridge bridge;
1256 struct pci_dev *dev;
1257
1258 memset(&bridge, 0, sizeof(bridge));
1259 bridge.handle = handle;
Kenji Kaneshige7430e342006-05-02 10:54:50 +09001260 bridge.pci_bus = bus;
Kristen Accardi783c49f2006-03-03 10:16:05 -08001261 bridge.pci_dev = bus->self;
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001262 decode_hpp(&bridge);
1263 list_for_each_entry(dev, &bus->devices, bus_list)
1264 program_hpp(dev, &bridge);
1265
1266}
1267
1268/*
1269 * Remove devices for which we could not assign resources, call
1270 * arch specific code to fix-up the bus
1271 */
1272static void acpiphp_sanitize_bus(struct pci_bus *bus)
1273{
1274 struct pci_dev *dev;
1275 int i;
1276 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
1277
1278 list_for_each_entry(dev, &bus->devices, bus_list) {
1279 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
1280 struct resource *res = &dev->resource[i];
1281 if ((res->flags & type_mask) && !res->start &&
1282 res->end) {
1283 /* Could not assign a required resources
1284 * for this device, remove it */
1285 pci_remove_bus_device(dev);
1286 break;
1287 }
1288 }
1289 }
1290}
1291
1292/* Program resources in newly inserted bridge */
1293static int acpiphp_configure_bridge (acpi_handle handle)
1294{
1295 struct acpi_pci_id pci_id;
1296 struct pci_bus *bus;
1297
1298 if (ACPI_FAILURE(acpi_get_pci_id(handle, &pci_id))) {
1299 err("cannot get PCI domain and bus number for bridge\n");
1300 return -EINVAL;
1301 }
1302 bus = pci_find_bus(pci_id.segment, pci_id.bus);
1303 if (!bus) {
1304 err("cannot find bus %d:%d\n",
1305 pci_id.segment, pci_id.bus);
1306 return -EINVAL;
1307 }
1308
1309 pci_bus_size_bridges(bus);
1310 pci_bus_assign_resources(bus);
1311 acpiphp_sanitize_bus(bus);
1312 acpiphp_set_hpp_values(handle, bus);
1313 pci_enable_bridges(bus);
Kenji Kaneshigea0d399a2005-04-28 00:25:59 -07001314 acpiphp_configure_ioapics(handle);
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001315 return 0;
1316}
1317
1318static void handle_bridge_insertion(acpi_handle handle, u32 type)
1319{
1320 struct acpi_device *device, *pdevice;
1321 acpi_handle phandle;
1322
1323 if ((type != ACPI_NOTIFY_BUS_CHECK) &&
1324 (type != ACPI_NOTIFY_DEVICE_CHECK)) {
1325 err("unexpected notification type %d\n", type);
1326 return;
1327 }
1328
1329 acpi_get_parent(handle, &phandle);
1330 if (acpi_bus_get_device(phandle, &pdevice)) {
1331 dbg("no parent device, assuming NULL\n");
1332 pdevice = NULL;
1333 }
1334 if (acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE)) {
1335 err("cannot add bridge to acpi list\n");
1336 return;
1337 }
1338 if (!acpiphp_configure_bridge(handle) &&
1339 !acpi_bus_start(device))
1340 add_bridge(handle);
1341 else
1342 err("cannot configure and start bridge\n");
1343
1344}
1345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346/*
1347 * ACPI event handlers
1348 */
1349
1350/**
1351 * handle_hotplug_event_bridge - handle ACPI event on bridges
1352 *
1353 * @handle: Notify()'ed acpi_handle
1354 * @type: Notify code
1355 * @context: pointer to acpiphp_bridge structure
1356 *
1357 * handles ACPI event notification on {host,p2p} bridges
1358 *
1359 */
1360static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *context)
1361{
1362 struct acpiphp_bridge *bridge;
1363 char objname[64];
1364 struct acpi_buffer buffer = { .length = sizeof(objname),
1365 .pointer = objname };
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001366 struct acpi_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001368 if (acpi_bus_get_device(handle, &device)) {
1369 /* This bridge must have just been physically inserted */
1370 handle_bridge_insertion(handle, type);
1371 return;
1372 }
1373
1374 bridge = acpiphp_handle_to_bridge(handle);
1375 if (!bridge) {
1376 err("cannot get bridge info\n");
1377 return;
1378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
1380 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1381
1382 switch (type) {
1383 case ACPI_NOTIFY_BUS_CHECK:
1384 /* bus re-enumerate */
1385 dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname);
1386 acpiphp_check_bridge(bridge);
1387 break;
1388
1389 case ACPI_NOTIFY_DEVICE_CHECK:
1390 /* device check */
1391 dbg("%s: Device check notify on %s\n", __FUNCTION__, objname);
1392 acpiphp_check_bridge(bridge);
1393 break;
1394
1395 case ACPI_NOTIFY_DEVICE_WAKE:
1396 /* wake event */
1397 dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname);
1398 break;
1399
1400 case ACPI_NOTIFY_EJECT_REQUEST:
1401 /* request device eject */
1402 dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);
MUNEDA Takahiro551bcb72006-03-22 14:49:20 +09001403 if ((bridge->type != BRIDGE_TYPE_HOST) &&
1404 (bridge->flags & BRIDGE_HAS_EJ0)) {
1405 struct acpiphp_slot *slot;
1406 slot = bridge->func->slot;
1407 if (!acpiphp_disable_slot(slot))
1408 acpiphp_eject_slot(slot);
1409 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 break;
1411
1412 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
1413 printk(KERN_ERR "Device %s cannot be configured due"
1414 " to a frequency mismatch\n", objname);
1415 break;
1416
1417 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
1418 printk(KERN_ERR "Device %s cannot be configured due"
1419 " to a bus mode mismatch\n", objname);
1420 break;
1421
1422 case ACPI_NOTIFY_POWER_FAULT:
1423 printk(KERN_ERR "Device %s has suffered a power fault\n",
1424 objname);
1425 break;
1426
1427 default:
1428 warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
1429 break;
1430 }
1431}
1432
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433/**
1434 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
1435 *
1436 * @handle: Notify()'ed acpi_handle
1437 * @type: Notify code
1438 * @context: pointer to acpiphp_func structure
1439 *
1440 * handles ACPI event notification on slots
1441 *
1442 */
Kristen Accardi20416ea2006-02-23 17:56:03 -08001443void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
1445 struct acpiphp_func *func;
1446 char objname[64];
1447 struct acpi_buffer buffer = { .length = sizeof(objname),
1448 .pointer = objname };
1449
1450 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1451
1452 func = (struct acpiphp_func *)context;
1453
1454 switch (type) {
1455 case ACPI_NOTIFY_BUS_CHECK:
1456 /* bus re-enumerate */
1457 dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname);
1458 acpiphp_enable_slot(func->slot);
1459 break;
1460
1461 case ACPI_NOTIFY_DEVICE_CHECK:
1462 /* device check : re-enumerate from parent bus */
1463 dbg("%s: Device check notify on %s\n", __FUNCTION__, objname);
1464 acpiphp_check_bridge(func->slot->bridge);
1465 break;
1466
1467 case ACPI_NOTIFY_DEVICE_WAKE:
1468 /* wake event */
1469 dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname);
1470 break;
1471
1472 case ACPI_NOTIFY_EJECT_REQUEST:
1473 /* request device eject */
1474 dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);
Rajesh Shah8d50e332005-04-28 00:25:57 -07001475 if (!(acpiphp_disable_slot(func->slot)))
1476 acpiphp_eject_slot(func->slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 break;
1478
1479 default:
1480 warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
1481 break;
1482 }
1483}
1484
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001485
1486static acpi_status
1487find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
1488{
1489 int *count = (int *)context;
1490
Kristen Accardi783c49f2006-03-03 10:16:05 -08001491 if (acpi_root_bridge(handle)) {
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001492 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
1493 handle_hotplug_event_bridge, NULL);
1494 (*count)++;
1495 }
1496 return AE_OK ;
1497}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
1499static struct acpi_pci_driver acpi_pci_hp_driver = {
1500 .add = add_bridge,
1501 .remove = remove_bridge,
1502};
1503
1504/**
1505 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
1506 *
1507 */
1508int __init acpiphp_glue_init(void)
1509{
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001510 int num = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001512 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1513 ACPI_UINT32_MAX, find_root_bridges, &num, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
1515 if (num <= 0)
1516 return -1;
Rajesh Shah8e7561c2005-04-28 00:25:56 -07001517 else
1518 acpi_pci_register_driver(&acpi_pci_hp_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
1520 return 0;
1521}
1522
1523
1524/**
1525 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures
1526 *
1527 * This function frees all data allocated in acpiphp_glue_init()
1528 */
1529void __exit acpiphp_glue_exit(void)
1530{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 acpi_pci_unregister_driver(&acpi_pci_hp_driver);
1532}
1533
1534
1535/**
1536 * acpiphp_get_num_slots - count number of slots in a system
1537 */
1538int __init acpiphp_get_num_slots(void)
1539{
1540 struct list_head *node;
1541 struct acpiphp_bridge *bridge;
1542 int num_slots;
1543
1544 num_slots = 0;
1545
1546 list_for_each (node, &bridge_list) {
1547 bridge = (struct acpiphp_bridge *)node;
Rajesh Shah42f49a62005-04-28 00:25:53 -07001548 dbg("Bus %04x:%02x has %d slot%s\n",
1549 pci_domain_nr(bridge->pci_bus),
1550 bridge->pci_bus->number, bridge->nr_slots,
1551 bridge->nr_slots == 1 ? "" : "s");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 num_slots += bridge->nr_slots;
1553 }
1554
Rajesh Shah42f49a62005-04-28 00:25:53 -07001555 dbg("Total %d slots\n", num_slots);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 return num_slots;
1557}
1558
1559
1560#if 0
1561/**
1562 * acpiphp_for_each_slot - call function for each slot
1563 * @fn: callback function
1564 * @data: context to be passed to callback function
1565 *
1566 */
1567static int acpiphp_for_each_slot(acpiphp_callback fn, void *data)
1568{
1569 struct list_head *node;
1570 struct acpiphp_bridge *bridge;
1571 struct acpiphp_slot *slot;
1572 int retval = 0;
1573
1574 list_for_each (node, &bridge_list) {
1575 bridge = (struct acpiphp_bridge *)node;
1576 for (slot = bridge->slots; slot; slot = slot->next) {
1577 retval = fn(slot, data);
1578 if (!retval)
1579 goto err_exit;
1580 }
1581 }
1582
1583 err_exit:
1584 return retval;
1585}
1586#endif
1587
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
1589/**
1590 * acpiphp_enable_slot - power on slot
1591 */
1592int acpiphp_enable_slot(struct acpiphp_slot *slot)
1593{
1594 int retval;
1595
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001596 mutex_lock(&slot->crit_sect);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
1598 /* wake up all functions */
1599 retval = power_on_slot(slot);
1600 if (retval)
1601 goto err_exit;
1602
MUNEDA Takahirocde0e5d2006-03-22 14:49:33 +09001603 if (get_slot_status(slot) == ACPI_STA_ALL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 /* configure all functions */
1605 retval = enable_device(slot);
MUNEDA Takahirocde0e5d2006-03-22 14:49:33 +09001606 if (retval)
1607 power_off_slot(slot);
1608 } else {
1609 dbg("%s: Slot status is not ACPI_STA_ALL\n", __FUNCTION__);
1610 power_off_slot(slot);
1611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
1613 err_exit:
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001614 mutex_unlock(&slot->crit_sect);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 return retval;
1616}
1617
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618/**
1619 * acpiphp_disable_slot - power off slot
1620 */
1621int acpiphp_disable_slot(struct acpiphp_slot *slot)
1622{
1623 int retval = 0;
1624
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001625 mutex_lock(&slot->crit_sect);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
1627 /* unconfigure all functions */
1628 retval = disable_device(slot);
1629 if (retval)
1630 goto err_exit;
1631
1632 /* power off all functions */
1633 retval = power_off_slot(slot);
1634 if (retval)
1635 goto err_exit;
1636
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 err_exit:
Ingo Molnar6aa4cdd2006-01-13 16:02:15 +01001638 mutex_unlock(&slot->crit_sect);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 return retval;
1640}
1641
1642
1643/*
1644 * slot enabled: 1
1645 * slot disabled: 0
1646 */
1647u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
1648{
Rajesh Shah8d50e332005-04-28 00:25:57 -07001649 return (slot->flags & SLOT_POWEREDON);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
1651
1652
1653/*
1654 * latch closed: 1
1655 * latch open: 0
1656 */
1657u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1658{
1659 unsigned int sta;
1660
1661 sta = get_slot_status(slot);
1662
1663 return (sta & ACPI_STA_SHOW_IN_UI) ? 1 : 0;
1664}
1665
1666
1667/*
1668 * adapter presence : 1
1669 * absence : 0
1670 */
1671u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1672{
1673 unsigned int sta;
1674
1675 sta = get_slot_status(slot);
1676
1677 return (sta == 0) ? 0 : 1;
1678}
1679
1680
1681/*
1682 * pci address (seg/bus/dev)
1683 */
1684u32 acpiphp_get_address(struct acpiphp_slot *slot)
1685{
1686 u32 address;
Rajesh Shah42f49a62005-04-28 00:25:53 -07001687 struct pci_bus *pci_bus = slot->bridge->pci_bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Rajesh Shah42f49a62005-04-28 00:25:53 -07001689 address = (pci_domain_nr(pci_bus) << 16) |
1690 (pci_bus->number << 8) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 slot->device;
1692
1693 return address;
1694}