2 * ACPI PCI HotPlug glue functions to ACPI CA subsystem
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
7 * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
8 * Copyright (C) 2003-2005 Hewlett Packard
10 * All rights reserved.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
20 * NON INFRINGEMENT. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * Send feedback to <t-kochi@bq.jp.nec.com>
32 * Lifetime rules for pci_dev:
33 * - The one in acpiphp_func has its refcount elevated by pci_get_slot()
34 * when the driver is loaded or when an insertion event occurs. It loses
35 * a refcount when its ejected or the driver unloads.
36 * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot()
37 * when the bridge is scanned and it loses a refcount when the bridge
41 #include <linux/init.h>
42 #include <linux/module.h>
44 #include <linux/kernel.h>
45 #include <linux/pci.h>
46 #include <linux/smp_lock.h>
47 #include <asm/semaphore.h>
50 #include "pci_hotplug.h"
53 static LIST_HEAD(bridge_list);
55 #define MY_NAME "acpiphp_glue"
57 static void handle_hotplug_event_bridge (acpi_handle, u32, void *);
58 static void handle_hotplug_event_func (acpi_handle, u32, void *);
61 * initialization & terminatation routines
65 * is_ejectable - determine if a slot is ejectable
66 * @handle: handle to acpi namespace
68 * Ejectable slot should satisfy at least these conditions:
81 static int is_ejectable(acpi_handle handle)
86 status = acpi_get_handle(handle, "_ADR", &tmp);
87 if (ACPI_FAILURE(status)) {
91 status = acpi_get_handle(handle, "_EJ0", &tmp);
92 if (ACPI_FAILURE(status)) {
100 /* callback routine to check the existence of ejectable slots */
102 is_ejectable_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
104 int *count = (int *)context;
106 if (is_ejectable(handle)) {
108 /* only one ejectable slot is enough */
109 return AE_CTRL_TERMINATE;
116 /* callback routine to register each ACPI PCI slot object */
118 register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
120 struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context;
121 struct acpiphp_slot *slot;
122 struct acpiphp_func *newfunc;
124 acpi_status status = AE_OK;
125 unsigned long adr, sun;
126 int device, function;
127 static int num_slots = 0; /* XXX if we support I/O node hotplug... */
129 status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
131 if (ACPI_FAILURE(status))
134 status = acpi_get_handle(handle, "_EJ0", &tmp);
136 if (ACPI_FAILURE(status))
139 device = (adr >> 16) & 0xffff;
140 function = adr & 0xffff;
142 newfunc = kmalloc(sizeof(struct acpiphp_func), GFP_KERNEL);
145 memset(newfunc, 0, sizeof(struct acpiphp_func));
147 INIT_LIST_HEAD(&newfunc->sibling);
148 newfunc->handle = handle;
149 newfunc->function = function;
150 newfunc->flags = FUNC_HAS_EJ0;
152 if (ACPI_SUCCESS(acpi_get_handle(handle, "_STA", &tmp)))
153 newfunc->flags |= FUNC_HAS_STA;
155 if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS0", &tmp)))
156 newfunc->flags |= FUNC_HAS_PS0;
158 if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS3", &tmp)))
159 newfunc->flags |= FUNC_HAS_PS3;
161 status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
162 if (ACPI_FAILURE(status))
165 /* search for objects that share the same slot */
166 for (slot = bridge->slots; slot; slot = slot->next)
167 if (slot->device == device) {
168 if (slot->sun != sun)
169 warn("sibling found, but _SUN doesn't match!\n");
174 slot = kmalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
180 memset(slot, 0, sizeof(struct acpiphp_slot));
181 slot->bridge = bridge;
182 slot->id = num_slots++;
183 slot->device = device;
185 INIT_LIST_HEAD(&slot->funcs);
186 init_MUTEX(&slot->crit_sect);
188 slot->next = bridge->slots;
189 bridge->slots = slot;
193 dbg("found ACPI PCI Hotplug slot %d at PCI %04x:%02x:%02x\n",
194 slot->sun, pci_domain_nr(bridge->pci_bus),
195 bridge->pci_bus->number, slot->device);
198 newfunc->slot = slot;
199 list_add_tail(&newfunc->sibling, &slot->funcs);
201 /* associate corresponding pci_dev */
202 newfunc->pci_dev = pci_get_slot(bridge->pci_bus,
203 PCI_DEVFN(device, function));
204 if (newfunc->pci_dev) {
205 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
208 /* install notify handler */
209 status = acpi_install_notify_handler(handle,
211 handle_hotplug_event_func,
214 if (ACPI_FAILURE(status)) {
215 err("failed to register interrupt notify handler\n");
223 /* see if it's worth looking at this bridge */
224 static int detect_ejectable_slots(acpi_handle *bridge_handle)
231 /* only check slots defined directly below bridge object */
232 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle, (u32)1,
233 is_ejectable_slot, (void *)&count, NULL);
239 /* decode ACPI 2.0 _HPP hot plug parameters */
240 static void decode_hpp(struct acpiphp_bridge *bridge)
243 struct acpi_buffer buffer = { .length = ACPI_ALLOCATE_BUFFER,
245 union acpi_object *package;
248 /* default numbers */
249 bridge->hpp.cache_line_size = 0x10;
250 bridge->hpp.latency_timer = 0x40;
251 bridge->hpp.enable_SERR = 0;
252 bridge->hpp.enable_PERR = 0;
254 status = acpi_evaluate_object(bridge->handle, "_HPP", NULL, &buffer);
256 if (ACPI_FAILURE(status)) {
257 dbg("_HPP evaluation failed\n");
261 package = (union acpi_object *) buffer.pointer;
263 if (!package || package->type != ACPI_TYPE_PACKAGE ||
264 package->package.count != 4 || !package->package.elements) {
265 err("invalid _HPP object; ignoring\n");
269 for (i = 0; i < 4; i++) {
270 if (package->package.elements[i].type != ACPI_TYPE_INTEGER) {
271 err("invalid _HPP parameter type; ignoring\n");
276 bridge->hpp.cache_line_size = package->package.elements[0].integer.value;
277 bridge->hpp.latency_timer = package->package.elements[1].integer.value;
278 bridge->hpp.enable_SERR = package->package.elements[2].integer.value;
279 bridge->hpp.enable_PERR = package->package.elements[3].integer.value;
281 dbg("_HPP parameter = (%02x, %02x, %02x, %02x)\n",
282 bridge->hpp.cache_line_size,
283 bridge->hpp.latency_timer,
284 bridge->hpp.enable_SERR,
285 bridge->hpp.enable_PERR);
287 bridge->flags |= BRIDGE_HAS_HPP;
290 kfree(buffer.pointer);
294 /* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */
295 static void init_bridge_misc(struct acpiphp_bridge *bridge)
299 /* decode ACPI 2.0 _HPP (hot plug parameters) */
302 /* register all slot objects under this bridge */
303 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1,
304 register_slot, bridge, NULL);
306 /* install notify handler */
307 status = acpi_install_notify_handler(bridge->handle,
309 handle_hotplug_event_bridge,
312 if (ACPI_FAILURE(status)) {
313 err("failed to register interrupt notify handler\n");
316 list_add(&bridge->list, &bridge_list);
320 /* allocate and initialize host bridge data structure */
321 static void add_host_bridge(acpi_handle *handle, struct pci_bus *pci_bus)
323 struct acpiphp_bridge *bridge;
325 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
329 memset(bridge, 0, sizeof(struct acpiphp_bridge));
331 bridge->type = BRIDGE_TYPE_HOST;
332 bridge->handle = handle;
334 bridge->pci_bus = pci_bus;
336 spin_lock_init(&bridge->res_lock);
338 init_bridge_misc(bridge);
342 /* allocate and initialize PCI-to-PCI bridge data structure */
343 static void add_p2p_bridge(acpi_handle *handle, struct pci_dev *pci_dev)
345 struct acpiphp_bridge *bridge;
347 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
348 if (bridge == NULL) {
349 err("out of memory\n");
353 memset(bridge, 0, sizeof(struct acpiphp_bridge));
355 bridge->type = BRIDGE_TYPE_P2P;
356 bridge->handle = handle;
358 bridge->pci_dev = pci_dev_get(pci_dev);
359 bridge->pci_bus = pci_dev->subordinate;
360 if (!bridge->pci_bus) {
361 err("This is not a PCI-to-PCI bridge!\n");
365 spin_lock_init(&bridge->res_lock);
367 init_bridge_misc(bridge);
370 pci_dev_put(pci_dev);
376 /* callback routine to find P2P bridges */
378 find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
381 acpi_handle dummy_handle;
383 int device, function;
385 struct pci_bus *pci_bus = context;
387 status = acpi_get_handle(handle, "_ADR", &dummy_handle);
388 if (ACPI_FAILURE(status))
389 return AE_OK; /* continue */
391 status = acpi_evaluate_integer(handle, "_ADR", NULL, &tmp);
392 if (ACPI_FAILURE(status)) {
393 dbg("%s: _ADR evaluation failure\n", __FUNCTION__);
397 device = (tmp >> 16) & 0xffff;
398 function = tmp & 0xffff;
400 dev = pci_get_slot(pci_bus, PCI_DEVFN(device, function));
402 if (!dev || !dev->subordinate)
405 /* check if this bridge has ejectable slots */
406 if (detect_ejectable_slots(handle) > 0) {
407 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev));
408 add_p2p_bridge(handle, dev);
417 /* find hot-pluggable slots, and then find P2P bridge */
418 static int add_bridge(acpi_handle handle)
423 acpi_handle dummy_handle;
424 struct pci_bus *pci_bus;
426 /* if the bridge doesn't have _STA, we assume it is always there */
427 status = acpi_get_handle(handle, "_STA", &dummy_handle);
428 if (ACPI_SUCCESS(status)) {
429 status = acpi_evaluate_integer(handle, "_STA", NULL, &tmp);
430 if (ACPI_FAILURE(status)) {
431 dbg("%s: _STA evaluation failure\n", __FUNCTION__);
434 if ((tmp & ACPI_STA_FUNCTIONING) == 0)
435 /* don't register this object */
439 /* get PCI segment number */
440 status = acpi_evaluate_integer(handle, "_SEG", NULL, &tmp);
442 seg = ACPI_SUCCESS(status) ? tmp : 0;
444 /* get PCI bus number */
445 status = acpi_evaluate_integer(handle, "_BBN", NULL, &tmp);
447 if (ACPI_SUCCESS(status)) {
450 warn("can't get bus number, assuming 0\n");
454 pci_bus = pci_find_bus(seg, bus);
456 err("Can't find bus %04x:%02x\n", seg, bus);
460 /* check if this bridge has ejectable slots */
461 if (detect_ejectable_slots(handle) > 0) {
462 dbg("found PCI host-bus bridge with hot-pluggable slots\n");
463 add_host_bridge(handle, pci_bus);
467 /* search P2P bridges under this host bridge */
468 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
469 find_p2p_bridge, pci_bus, NULL);
471 if (ACPI_FAILURE(status))
472 warn("find_p2p_bridge faied (error code = 0x%x)\n",status);
477 static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
479 struct list_head *head;
480 list_for_each(head, &bridge_list) {
481 struct acpiphp_bridge *bridge = list_entry(head,
482 struct acpiphp_bridge, list);
483 if (bridge->handle == handle)
490 static void cleanup_bridge(struct acpiphp_bridge *bridge)
492 struct list_head *list, *tmp;
493 struct acpiphp_slot *slot;
495 acpi_handle handle = bridge->handle;
497 status = acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
498 handle_hotplug_event_bridge);
499 if (ACPI_FAILURE(status))
500 err("failed to remove notify handler\n");
502 slot = bridge->slots;
504 struct acpiphp_slot *next = slot->next;
505 list_for_each_safe (list, tmp, &slot->funcs) {
506 struct acpiphp_func *func;
507 func = list_entry(list, struct acpiphp_func, sibling);
508 status = acpi_remove_notify_handler(func->handle,
510 handle_hotplug_event_func);
511 if (ACPI_FAILURE(status))
512 err("failed to remove notify handler\n");
513 pci_dev_put(func->pci_dev);
521 pci_dev_put(bridge->pci_dev);
522 list_del(&bridge->list);
527 cleanup_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
529 struct acpiphp_bridge *bridge;
531 if (!(bridge = acpiphp_handle_to_bridge(handle)))
533 cleanup_bridge(bridge);
537 static void remove_bridge(acpi_handle handle)
539 struct acpiphp_bridge *bridge;
541 bridge = acpiphp_handle_to_bridge(handle);
543 cleanup_bridge(bridge);
545 /* clean-up p2p bridges under this host bridge */
546 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
547 (u32)1, cleanup_p2p_bridge, NULL, NULL);
551 static int power_on_slot(struct acpiphp_slot *slot)
554 struct acpiphp_func *func;
558 /* if already enabled, just skip */
559 if (slot->flags & SLOT_POWEREDON)
562 list_for_each (l, &slot->funcs) {
563 func = list_entry(l, struct acpiphp_func, sibling);
565 if (func->flags & FUNC_HAS_PS0) {
566 dbg("%s: executing _PS0\n", __FUNCTION__);
567 status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL);
568 if (ACPI_FAILURE(status)) {
569 warn("%s: _PS0 failed\n", __FUNCTION__);
577 /* TBD: evaluate _STA to check if the slot is enabled */
579 slot->flags |= SLOT_POWEREDON;
586 static int power_off_slot(struct acpiphp_slot *slot)
589 struct acpiphp_func *func;
591 struct acpi_object_list arg_list;
592 union acpi_object arg;
596 /* if already disabled, just skip */
597 if ((slot->flags & SLOT_POWEREDON) == 0)
600 list_for_each (l, &slot->funcs) {
601 func = list_entry(l, struct acpiphp_func, sibling);
603 if (func->pci_dev && (func->flags & FUNC_HAS_PS3)) {
604 status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL);
605 if (ACPI_FAILURE(status)) {
606 warn("%s: _PS3 failed\n", __FUNCTION__);
614 list_for_each (l, &slot->funcs) {
615 func = list_entry(l, struct acpiphp_func, sibling);
617 /* We don't want to call _EJ0 on non-existing functions. */
618 if (func->pci_dev && (func->flags & FUNC_HAS_EJ0)) {
619 /* _EJ0 method take one argument */
621 arg_list.pointer = &arg;
622 arg.type = ACPI_TYPE_INTEGER;
623 arg.integer.value = 1;
625 status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL);
626 if (ACPI_FAILURE(status)) {
627 warn("%s: _EJ0 failed\n", __FUNCTION__);
635 /* TBD: evaluate _STA to check if the slot is disabled */
637 slot->flags &= (~SLOT_POWEREDON);
645 * enable_device - enable, configure a slot
646 * @slot: slot to be enabled
648 * This function should be called per *physical slot*,
649 * not per each slot object in ACPI namespace.
652 static int enable_device(struct acpiphp_slot *slot)
655 struct pci_bus *bus = slot->bridge->pci_bus;
657 struct acpiphp_func *func;
661 if (slot->flags & SLOT_ENABLED)
664 /* sanity check: dev should be NULL when hot-plugged in */
665 dev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0));
667 /* This case shouldn't happen */
668 err("pci_dev structure already exists.\n");
674 num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0));
676 err("No new device found\n");
681 max = bus->secondary;
682 for (pass = 0; pass < 2; pass++) {
683 list_for_each_entry(dev, &bus->devices, bus_list) {
684 if (PCI_SLOT(dev->devfn) != slot->device)
686 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
687 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
688 max = pci_scan_bridge(bus, dev, max, pass);
692 pci_bus_assign_resources(bus);
693 pci_bus_add_devices(bus);
695 /* associate pci_dev to our representation */
696 list_for_each (l, &slot->funcs) {
697 func = list_entry(l, struct acpiphp_func, sibling);
698 func->pci_dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
702 slot->flags |= SLOT_ENABLED;
710 * disable_device - disable a slot
712 static int disable_device(struct acpiphp_slot *slot)
715 struct acpiphp_func *func;
718 /* is this slot already disabled? */
719 if (!(slot->flags & SLOT_ENABLED))
722 list_for_each (l, &slot->funcs) {
723 func = list_entry(l, struct acpiphp_func, sibling);
727 pci_remove_bus_device(func->pci_dev);
728 pci_dev_put(func->pci_dev);
729 func->pci_dev = NULL;
732 slot->flags &= (~SLOT_ENABLED);
740 * get_slot_status - get ACPI slot status
742 * if a slot has _STA for each function and if any one of them
743 * returned non-zero status, return it
745 * if a slot doesn't have _STA and if any one of its functions'
746 * configuration space is configured, return 0x0f as a _STA
750 static unsigned int get_slot_status(struct acpiphp_slot *slot)
753 unsigned long sta = 0;
756 struct acpiphp_func *func;
758 list_for_each (l, &slot->funcs) {
759 func = list_entry(l, struct acpiphp_func, sibling);
761 if (func->flags & FUNC_HAS_STA) {
762 status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta);
763 if (ACPI_SUCCESS(status) && sta)
766 pci_bus_read_config_dword(slot->bridge->pci_bus,
767 PCI_DEVFN(slot->device,
769 PCI_VENDOR_ID, &dvid);
770 if (dvid != 0xffffffff) {
777 return (unsigned int)sta;
781 * acpiphp_check_bridge - re-enumerate devices
783 * Iterate over all slots under this bridge and make sure that if a
784 * card is present they are enabled, and if not they are disabled.
786 static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
788 struct acpiphp_slot *slot;
790 int enabled, disabled;
792 enabled = disabled = 0;
794 for (slot = bridge->slots; slot; slot = slot->next) {
795 unsigned int status = get_slot_status(slot);
796 if (slot->flags & SLOT_ENABLED) {
797 if (status == ACPI_STA_ALL)
799 retval = acpiphp_disable_slot(slot);
801 err("Error occurred in disabling\n");
806 if (status != ACPI_STA_ALL)
808 retval = acpiphp_enable_slot(slot);
810 err("Error occurred in enabling\n");
817 dbg("%s: %d enabled, %d disabled\n", __FUNCTION__, enabled, disabled);
824 * ACPI event handlers
828 * handle_hotplug_event_bridge - handle ACPI event on bridges
830 * @handle: Notify()'ed acpi_handle
832 * @context: pointer to acpiphp_bridge structure
834 * handles ACPI event notification on {host,p2p} bridges
837 static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *context)
839 struct acpiphp_bridge *bridge;
841 struct acpi_buffer buffer = { .length = sizeof(objname),
842 .pointer = objname };
844 bridge = (struct acpiphp_bridge *)context;
846 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
849 case ACPI_NOTIFY_BUS_CHECK:
850 /* bus re-enumerate */
851 dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname);
852 acpiphp_check_bridge(bridge);
855 case ACPI_NOTIFY_DEVICE_CHECK:
857 dbg("%s: Device check notify on %s\n", __FUNCTION__, objname);
858 acpiphp_check_bridge(bridge);
861 case ACPI_NOTIFY_DEVICE_WAKE:
863 dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname);
866 case ACPI_NOTIFY_EJECT_REQUEST:
867 /* request device eject */
868 dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);
871 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
872 printk(KERN_ERR "Device %s cannot be configured due"
873 " to a frequency mismatch\n", objname);
876 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
877 printk(KERN_ERR "Device %s cannot be configured due"
878 " to a bus mode mismatch\n", objname);
881 case ACPI_NOTIFY_POWER_FAULT:
882 printk(KERN_ERR "Device %s has suffered a power fault\n",
887 warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
894 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
896 * @handle: Notify()'ed acpi_handle
898 * @context: pointer to acpiphp_func structure
900 * handles ACPI event notification on slots
903 static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context)
905 struct acpiphp_func *func;
907 struct acpi_buffer buffer = { .length = sizeof(objname),
908 .pointer = objname };
910 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
912 func = (struct acpiphp_func *)context;
915 case ACPI_NOTIFY_BUS_CHECK:
916 /* bus re-enumerate */
917 dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname);
918 acpiphp_enable_slot(func->slot);
921 case ACPI_NOTIFY_DEVICE_CHECK:
922 /* device check : re-enumerate from parent bus */
923 dbg("%s: Device check notify on %s\n", __FUNCTION__, objname);
924 acpiphp_check_bridge(func->slot->bridge);
927 case ACPI_NOTIFY_DEVICE_WAKE:
929 dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname);
932 case ACPI_NOTIFY_EJECT_REQUEST:
933 /* request device eject */
934 dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);
935 acpiphp_disable_slot(func->slot);
939 warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
945 static struct acpi_pci_driver acpi_pci_hp_driver = {
947 .remove = remove_bridge,
951 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
954 int __init acpiphp_glue_init(void)
958 if (list_empty(&pci_root_buses))
961 num = acpi_pci_register_driver(&acpi_pci_hp_driver);
971 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures
973 * This function frees all data allocated in acpiphp_glue_init()
975 void __exit acpiphp_glue_exit(void)
977 acpi_pci_unregister_driver(&acpi_pci_hp_driver);
982 * acpiphp_get_num_slots - count number of slots in a system
984 int __init acpiphp_get_num_slots(void)
986 struct list_head *node;
987 struct acpiphp_bridge *bridge;
992 list_for_each (node, &bridge_list) {
993 bridge = (struct acpiphp_bridge *)node;
994 dbg("Bus %04x:%02x has %d slot%s\n",
995 pci_domain_nr(bridge->pci_bus),
996 bridge->pci_bus->number, bridge->nr_slots,
997 bridge->nr_slots == 1 ? "" : "s");
998 num_slots += bridge->nr_slots;
1001 dbg("Total %d slots\n", num_slots);
1008 * acpiphp_for_each_slot - call function for each slot
1009 * @fn: callback function
1010 * @data: context to be passed to callback function
1013 static int acpiphp_for_each_slot(acpiphp_callback fn, void *data)
1015 struct list_head *node;
1016 struct acpiphp_bridge *bridge;
1017 struct acpiphp_slot *slot;
1020 list_for_each (node, &bridge_list) {
1021 bridge = (struct acpiphp_bridge *)node;
1022 for (slot = bridge->slots; slot; slot = slot->next) {
1023 retval = fn(slot, data);
1034 /* search matching slot from id */
1035 struct acpiphp_slot *get_slot_from_id(int id)
1037 struct list_head *node;
1038 struct acpiphp_bridge *bridge;
1039 struct acpiphp_slot *slot;
1041 list_for_each (node, &bridge_list) {
1042 bridge = (struct acpiphp_bridge *)node;
1043 for (slot = bridge->slots; slot; slot = slot->next)
1048 /* should never happen! */
1049 err("%s: no object for id %d\n", __FUNCTION__, id);
1056 * acpiphp_enable_slot - power on slot
1058 int acpiphp_enable_slot(struct acpiphp_slot *slot)
1062 down(&slot->crit_sect);
1064 /* wake up all functions */
1065 retval = power_on_slot(slot);
1069 if (get_slot_status(slot) == ACPI_STA_ALL)
1070 /* configure all functions */
1071 retval = enable_device(slot);
1074 up(&slot->crit_sect);
1080 * acpiphp_disable_slot - power off slot
1082 int acpiphp_disable_slot(struct acpiphp_slot *slot)
1086 down(&slot->crit_sect);
1088 /* unconfigure all functions */
1089 retval = disable_device(slot);
1093 /* power off all functions */
1094 retval = power_off_slot(slot);
1099 up(&slot->crit_sect);
1108 u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
1112 sta = get_slot_status(slot);
1114 return (sta & ACPI_STA_ENABLED) ? 1 : 0;
1122 u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1126 sta = get_slot_status(slot);
1128 return (sta & ACPI_STA_SHOW_IN_UI) ? 1 : 0;
1133 * adapter presence : 1
1136 u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1140 sta = get_slot_status(slot);
1142 return (sta == 0) ? 0 : 1;
1147 * pci address (seg/bus/dev)
1149 u32 acpiphp_get_address(struct acpiphp_slot *slot)
1152 struct pci_bus *pci_bus = slot->bridge->pci_bus;
1154 address = (pci_domain_nr(pci_bus) << 16) |
1155 (pci_bus->number << 8) |