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
9 * Copyright (C) 2005 Rajesh Shah (rajesh.shah@intel.com)
10 * Copyright (C) 2005 Intel Corporation
12 * All rights reserved.
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.
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
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.
29 * Send feedback to <kristen.c.accardi@intel.com>
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
43 #include <linux/init.h>
44 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/pci.h>
48 #include <linux/pci_hotplug.h>
49 #include <linux/mutex.h>
54 static LIST_HEAD(bridge_list);
55 static LIST_HEAD(ioapic_list);
56 static DEFINE_SPINLOCK(ioapic_list_lock);
58 #define MY_NAME "acpiphp_glue"
60 static void handle_hotplug_event_bridge (acpi_handle, u32, void *);
61 static void acpiphp_sanitize_bus(struct pci_bus *bus);
62 static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus);
63 static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context);
67 * initialization & terminatation routines
71 * is_ejectable - determine if a slot is ejectable
72 * @handle: handle to acpi namespace
74 * Ejectable slot should satisfy at least these conditions:
86 static int is_ejectable(acpi_handle handle)
91 status = acpi_get_handle(handle, "_ADR", &tmp);
92 if (ACPI_FAILURE(status)) {
96 status = acpi_get_handle(handle, "_EJ0", &tmp);
97 if (ACPI_FAILURE(status)) {
105 /* callback routine to check for the existence of ejectable slots */
107 is_ejectable_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
109 int *count = (int *)context;
111 if (is_ejectable(handle)) {
113 /* only one ejectable slot is enough */
114 return AE_CTRL_TERMINATE;
120 /* callback routine to check for the existence of a pci dock device */
122 is_pci_dock_device(acpi_handle handle, u32 lvl, void *context, void **rv)
124 int *count = (int *)context;
126 if (is_dock_device(handle)) {
128 return AE_CTRL_TERMINATE;
138 * the _DCK method can do funny things... and sometimes not
141 * TBD - figure out a way to only call fixups for
142 * systems that require them.
144 static int post_dock_fixups(struct notifier_block *nb, unsigned long val,
147 struct acpiphp_func *func = container_of(nb, struct acpiphp_func, nb);
148 struct pci_bus *bus = func->slot->bridge->pci_bus;
154 /* fixup bad _DCK function that rewrites
155 * secondary bridge on slot
157 pci_read_config_dword(bus->self,
161 if (((buses >> 8) & 0xff) != bus->secondary) {
162 buses = (buses & 0xff000000)
163 | ((unsigned int)(bus->primary) << 0)
164 | ((unsigned int)(bus->secondary) << 8)
165 | ((unsigned int)(bus->subordinate) << 16);
166 pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses);
174 /* callback routine to register each ACPI PCI slot object */
176 register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
178 struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context;
179 struct acpiphp_slot *slot;
180 struct acpiphp_func *newfunc;
182 acpi_status status = AE_OK;
183 unsigned long adr, sun;
184 int device, function, retval;
186 status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
188 if (ACPI_FAILURE(status))
191 status = acpi_get_handle(handle, "_EJ0", &tmp);
193 if (ACPI_FAILURE(status) && !(is_dock_device(handle)))
196 device = (adr >> 16) & 0xffff;
197 function = adr & 0xffff;
199 newfunc = kzalloc(sizeof(struct acpiphp_func), GFP_KERNEL);
203 INIT_LIST_HEAD(&newfunc->sibling);
204 newfunc->handle = handle;
205 newfunc->function = function;
206 if (ACPI_SUCCESS(status))
207 newfunc->flags = FUNC_HAS_EJ0;
209 if (ACPI_SUCCESS(acpi_get_handle(handle, "_STA", &tmp)))
210 newfunc->flags |= FUNC_HAS_STA;
212 if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS0", &tmp)))
213 newfunc->flags |= FUNC_HAS_PS0;
215 if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS3", &tmp)))
216 newfunc->flags |= FUNC_HAS_PS3;
218 if (ACPI_SUCCESS(acpi_get_handle(handle, "_DCK", &tmp)))
219 newfunc->flags |= FUNC_HAS_DCK;
221 status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
222 if (ACPI_FAILURE(status)) {
224 * use the count of the number of slots we've found
225 * for the number of the slot
227 sun = bridge->nr_slots+1;
230 /* search for objects that share the same slot */
231 for (slot = bridge->slots; slot; slot = slot->next)
232 if (slot->device == device) {
233 if (slot->sun != sun)
234 warn("sibling found, but _SUN doesn't match!\n");
239 slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
245 slot->bridge = bridge;
246 slot->device = device;
248 INIT_LIST_HEAD(&slot->funcs);
249 mutex_init(&slot->crit_sect);
251 slot->next = bridge->slots;
252 bridge->slots = slot;
256 dbg("found ACPI PCI Hotplug slot %d at PCI %04x:%02x:%02x\n",
257 slot->sun, pci_domain_nr(bridge->pci_bus),
258 bridge->pci_bus->number, slot->device);
259 retval = acpiphp_register_hotplug_slot(slot);
261 if (retval == -EBUSY)
262 warn("Slot %d already registered by another "
263 "hotplug driver\n", slot->sun);
265 warn("acpiphp_register_hotplug_slot failed "
266 "(err code = 0x%x)\n", retval);
271 newfunc->slot = slot;
272 list_add_tail(&newfunc->sibling, &slot->funcs);
274 /* associate corresponding pci_dev */
275 newfunc->pci_dev = pci_get_slot(bridge->pci_bus,
276 PCI_DEVFN(device, function));
277 if (newfunc->pci_dev) {
278 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
281 if (is_dock_device(handle)) {
282 /* we don't want to call this device's _EJ0
283 * because we want the dock notify handler
284 * to call it after it calls _DCK
286 newfunc->flags &= ~FUNC_HAS_EJ0;
287 if (register_hotplug_dock_device(handle,
288 handle_hotplug_event_func, newfunc))
289 dbg("failed to register dock device\n");
291 /* we need to be notified when dock events happen
292 * outside of the hotplug operation, since we may
293 * need to do fixups before we can hotplug.
295 newfunc->nb.notifier_call = post_dock_fixups;
296 if (register_dock_notifier(&newfunc->nb))
297 dbg("failed to register a dock notifier");
300 /* install notify handler */
301 if (!(newfunc->flags & FUNC_HAS_DCK)) {
302 status = acpi_install_notify_handler(handle,
304 handle_hotplug_event_func,
307 if (ACPI_FAILURE(status))
308 err("failed to register interrupt notify handler\n");
316 bridge->slots = slot->next;
324 /* see if it's worth looking at this bridge */
325 static int detect_ejectable_slots(acpi_handle *bridge_handle)
332 /* only check slots defined directly below bridge object */
333 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle, (u32)1,
334 is_ejectable_slot, (void *)&count, NULL);
337 * we also need to add this bridge if there is a dock bridge or
338 * other pci device on a dock station (removable)
341 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle,
342 (u32)1, is_pci_dock_device, (void *)&count,
349 /* decode ACPI 2.0 _HPP hot plug parameters */
350 static void decode_hpp(struct acpiphp_bridge *bridge)
354 status = acpi_get_hp_params_from_firmware(bridge->pci_bus, &bridge->hpp);
355 if (ACPI_FAILURE(status) ||
356 !bridge->hpp.t0 || (bridge->hpp.t0->revision > 1)) {
357 /* use default numbers */
359 "%s: Could not get hotplug parameters. Use defaults\n",
361 bridge->hpp.t0 = &bridge->hpp.type0_data;
362 bridge->hpp.t0->revision = 0;
363 bridge->hpp.t0->cache_line_size = 0x10;
364 bridge->hpp.t0->latency_timer = 0x40;
365 bridge->hpp.t0->enable_serr = 0;
366 bridge->hpp.t0->enable_perr = 0;
372 /* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */
373 static void init_bridge_misc(struct acpiphp_bridge *bridge)
377 /* decode ACPI 2.0 _HPP (hot plug parameters) */
380 /* must be added to the list prior to calling register_slot */
381 list_add(&bridge->list, &bridge_list);
383 /* register all slot objects under this bridge */
384 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1,
385 register_slot, bridge, NULL);
386 if (ACPI_FAILURE(status)) {
387 list_del(&bridge->list);
391 /* install notify handler */
392 if (bridge->type != BRIDGE_TYPE_HOST) {
393 if ((bridge->flags & BRIDGE_HAS_EJ0) && bridge->func) {
394 status = acpi_remove_notify_handler(bridge->func->handle,
396 handle_hotplug_event_func);
397 if (ACPI_FAILURE(status))
398 err("failed to remove notify handler\n");
400 status = acpi_install_notify_handler(bridge->handle,
402 handle_hotplug_event_bridge,
405 if (ACPI_FAILURE(status)) {
406 err("failed to register interrupt notify handler\n");
412 /* find acpiphp_func from acpiphp_bridge */
413 static struct acpiphp_func *acpiphp_bridge_handle_to_function(acpi_handle handle)
415 struct list_head *node, *l;
416 struct acpiphp_bridge *bridge;
417 struct acpiphp_slot *slot;
418 struct acpiphp_func *func;
420 list_for_each(node, &bridge_list) {
421 bridge = list_entry(node, struct acpiphp_bridge, list);
422 for (slot = bridge->slots; slot; slot = slot->next) {
423 list_for_each(l, &slot->funcs) {
424 func = list_entry(l, struct acpiphp_func,
426 if (func->handle == handle)
436 static inline void config_p2p_bridge_flags(struct acpiphp_bridge *bridge)
438 acpi_handle dummy_handle;
440 if (ACPI_SUCCESS(acpi_get_handle(bridge->handle,
441 "_STA", &dummy_handle)))
442 bridge->flags |= BRIDGE_HAS_STA;
444 if (ACPI_SUCCESS(acpi_get_handle(bridge->handle,
445 "_EJ0", &dummy_handle)))
446 bridge->flags |= BRIDGE_HAS_EJ0;
448 if (ACPI_SUCCESS(acpi_get_handle(bridge->handle,
449 "_PS0", &dummy_handle)))
450 bridge->flags |= BRIDGE_HAS_PS0;
452 if (ACPI_SUCCESS(acpi_get_handle(bridge->handle,
453 "_PS3", &dummy_handle)))
454 bridge->flags |= BRIDGE_HAS_PS3;
456 /* is this ejectable p2p bridge? */
457 if (bridge->flags & BRIDGE_HAS_EJ0) {
458 struct acpiphp_func *func;
460 dbg("found ejectable p2p bridge\n");
462 /* make link between PCI bridge and PCI function */
463 func = acpiphp_bridge_handle_to_function(bridge->handle);
467 func->bridge = bridge;
472 /* allocate and initialize host bridge data structure */
473 static void add_host_bridge(acpi_handle *handle, struct pci_bus *pci_bus)
475 struct acpiphp_bridge *bridge;
477 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
481 bridge->type = BRIDGE_TYPE_HOST;
482 bridge->handle = handle;
484 bridge->pci_bus = pci_bus;
486 spin_lock_init(&bridge->res_lock);
488 init_bridge_misc(bridge);
492 /* allocate and initialize PCI-to-PCI bridge data structure */
493 static void add_p2p_bridge(acpi_handle *handle, struct pci_dev *pci_dev)
495 struct acpiphp_bridge *bridge;
497 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
498 if (bridge == NULL) {
499 err("out of memory\n");
503 bridge->type = BRIDGE_TYPE_P2P;
504 bridge->handle = handle;
505 config_p2p_bridge_flags(bridge);
507 bridge->pci_dev = pci_dev_get(pci_dev);
508 bridge->pci_bus = pci_dev->subordinate;
509 if (!bridge->pci_bus) {
510 err("This is not a PCI-to-PCI bridge!\n");
514 spin_lock_init(&bridge->res_lock);
516 init_bridge_misc(bridge);
519 pci_dev_put(pci_dev);
525 /* callback routine to find P2P bridges */
527 find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
530 acpi_handle dummy_handle;
532 int device, function;
534 struct pci_bus *pci_bus = context;
536 status = acpi_get_handle(handle, "_ADR", &dummy_handle);
537 if (ACPI_FAILURE(status))
538 return AE_OK; /* continue */
540 status = acpi_evaluate_integer(handle, "_ADR", NULL, &tmp);
541 if (ACPI_FAILURE(status)) {
542 dbg("%s: _ADR evaluation failure\n", __func__);
546 device = (tmp >> 16) & 0xffff;
547 function = tmp & 0xffff;
549 dev = pci_get_slot(pci_bus, PCI_DEVFN(device, function));
551 if (!dev || !dev->subordinate)
554 /* check if this bridge has ejectable slots */
555 if ((detect_ejectable_slots(handle) > 0)) {
556 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev));
557 add_p2p_bridge(handle, dev);
560 /* search P2P bridges under this p2p bridge */
561 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
562 find_p2p_bridge, dev->subordinate, NULL);
563 if (ACPI_FAILURE(status))
564 warn("find_p2p_bridge failed (error code = 0x%x)\n", status);
572 /* find hot-pluggable slots, and then find P2P bridge */
573 static int add_bridge(acpi_handle handle)
578 acpi_handle dummy_handle;
579 struct pci_bus *pci_bus;
581 /* if the bridge doesn't have _STA, we assume it is always there */
582 status = acpi_get_handle(handle, "_STA", &dummy_handle);
583 if (ACPI_SUCCESS(status)) {
584 status = acpi_evaluate_integer(handle, "_STA", NULL, &tmp);
585 if (ACPI_FAILURE(status)) {
586 dbg("%s: _STA evaluation failure\n", __func__);
589 if ((tmp & ACPI_STA_FUNCTIONING) == 0)
590 /* don't register this object */
594 /* get PCI segment number */
595 status = acpi_evaluate_integer(handle, "_SEG", NULL, &tmp);
597 seg = ACPI_SUCCESS(status) ? tmp : 0;
599 /* get PCI bus number */
600 status = acpi_evaluate_integer(handle, "_BBN", NULL, &tmp);
602 if (ACPI_SUCCESS(status)) {
605 warn("can't get bus number, assuming 0\n");
609 pci_bus = pci_find_bus(seg, bus);
611 err("Can't find bus %04x:%02x\n", seg, bus);
615 /* check if this bridge has ejectable slots */
616 if (detect_ejectable_slots(handle) > 0) {
617 dbg("found PCI host-bus bridge with hot-pluggable slots\n");
618 add_host_bridge(handle, pci_bus);
621 /* search P2P bridges under this host bridge */
622 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
623 find_p2p_bridge, pci_bus, NULL);
625 if (ACPI_FAILURE(status))
626 warn("find_p2p_bridge failed (error code = 0x%x)\n", status);
631 static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
633 struct list_head *head;
634 list_for_each(head, &bridge_list) {
635 struct acpiphp_bridge *bridge = list_entry(head,
636 struct acpiphp_bridge, list);
637 if (bridge->handle == handle)
644 static void cleanup_bridge(struct acpiphp_bridge *bridge)
646 struct list_head *list, *tmp;
647 struct acpiphp_slot *slot;
649 acpi_handle handle = bridge->handle;
651 status = acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
652 handle_hotplug_event_bridge);
653 if (ACPI_FAILURE(status))
654 err("failed to remove notify handler\n");
656 if ((bridge->type != BRIDGE_TYPE_HOST) &&
657 ((bridge->flags & BRIDGE_HAS_EJ0) && bridge->func)) {
658 status = acpi_install_notify_handler(bridge->func->handle,
660 handle_hotplug_event_func,
662 if (ACPI_FAILURE(status))
663 err("failed to install interrupt notify handler\n");
666 slot = bridge->slots;
668 struct acpiphp_slot *next = slot->next;
669 list_for_each_safe (list, tmp, &slot->funcs) {
670 struct acpiphp_func *func;
671 func = list_entry(list, struct acpiphp_func, sibling);
672 if (is_dock_device(func->handle)) {
673 unregister_hotplug_dock_device(func->handle);
674 unregister_dock_notifier(&func->nb);
676 if (!(func->flags & FUNC_HAS_DCK)) {
677 status = acpi_remove_notify_handler(func->handle,
679 handle_hotplug_event_func);
680 if (ACPI_FAILURE(status))
681 err("failed to remove notify handler\n");
683 pci_dev_put(func->pci_dev);
687 acpiphp_unregister_hotplug_slot(slot);
688 list_del(&slot->funcs);
693 pci_dev_put(bridge->pci_dev);
694 list_del(&bridge->list);
699 cleanup_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
701 struct acpiphp_bridge *bridge;
703 /* cleanup p2p bridges under this P2P bridge
704 in a depth-first manner */
705 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
706 cleanup_p2p_bridge, NULL, NULL);
708 if (!(bridge = acpiphp_handle_to_bridge(handle)))
710 cleanup_bridge(bridge);
714 static void remove_bridge(acpi_handle handle)
716 struct acpiphp_bridge *bridge;
718 /* cleanup p2p bridges under this host bridge
719 in a depth-first manner */
720 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
721 (u32)1, cleanup_p2p_bridge, NULL, NULL);
723 bridge = acpiphp_handle_to_bridge(handle);
725 cleanup_bridge(bridge);
728 static struct pci_dev * get_apic_pci_info(acpi_handle handle)
730 struct acpi_pci_id id;
734 if (ACPI_FAILURE(acpi_get_pci_id(handle, &id)))
737 bus = pci_find_bus(id.segment, id.bus);
741 dev = pci_get_slot(bus, PCI_DEVFN(id.device, id.function));
745 if ((dev->class != PCI_CLASS_SYSTEM_PIC_IOAPIC) &&
746 (dev->class != PCI_CLASS_SYSTEM_PIC_IOXAPIC))
755 static int get_gsi_base(acpi_handle handle, u32 *gsi_base)
760 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
761 union acpi_object *obj;
764 status = acpi_evaluate_integer(handle, "_GSB", NULL, &gsb);
765 if (ACPI_SUCCESS(status)) {
766 *gsi_base = (u32)gsb;
770 status = acpi_evaluate_object(handle, "_MAT", NULL, &buffer);
771 if (ACPI_FAILURE(status) || !buffer.length || !buffer.pointer)
774 obj = buffer.pointer;
775 if (obj->type != ACPI_TYPE_BUFFER)
778 table = obj->buffer.pointer;
779 switch (((struct acpi_subtable_header *)table)->type) {
780 case ACPI_MADT_TYPE_IO_SAPIC:
781 *gsi_base = ((struct acpi_madt_io_sapic *)table)->global_irq_base;
784 case ACPI_MADT_TYPE_IO_APIC:
785 *gsi_base = ((struct acpi_madt_io_apic *)table)->global_irq_base;
792 kfree(buffer.pointer);
797 ioapic_add(acpi_handle handle, u32 lvl, void *context, void **rv)
802 struct pci_dev *pdev;
805 struct acpiphp_ioapic *ioapic;
807 /* Evaluate _STA if present */
808 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
809 if (ACPI_SUCCESS(status) && sta != ACPI_STA_ALL)
810 return AE_CTRL_DEPTH;
812 /* Scan only PCI bus scope */
813 status = acpi_get_handle(handle, "_HID", &tmp);
814 if (ACPI_SUCCESS(status))
815 return AE_CTRL_DEPTH;
817 if (get_gsi_base(handle, &gsi_base))
820 ioapic = kmalloc(sizeof(*ioapic), GFP_KERNEL);
824 pdev = get_apic_pci_info(handle);
828 if (pci_enable_device(pdev))
829 goto exit_pci_dev_put;
831 pci_set_master(pdev);
833 if (pci_request_region(pdev, 0, "I/O APIC(acpiphp)"))
834 goto exit_pci_disable_device;
836 phys_addr = pci_resource_start(pdev, 0);
837 if (acpi_register_ioapic(handle, phys_addr, gsi_base))
838 goto exit_pci_release_region;
840 ioapic->gsi_base = gsi_base;
842 spin_lock(&ioapic_list_lock);
843 list_add_tail(&ioapic->list, &ioapic_list);
844 spin_unlock(&ioapic_list_lock);
848 exit_pci_release_region:
849 pci_release_region(pdev, 0);
850 exit_pci_disable_device:
851 pci_disable_device(pdev);
861 ioapic_remove(acpi_handle handle, u32 lvl, void *context, void **rv)
867 struct acpiphp_ioapic *pos, *n, *ioapic = NULL;
869 /* Evaluate _STA if present */
870 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
871 if (ACPI_SUCCESS(status) && sta != ACPI_STA_ALL)
872 return AE_CTRL_DEPTH;
874 /* Scan only PCI bus scope */
875 status = acpi_get_handle(handle, "_HID", &tmp);
876 if (ACPI_SUCCESS(status))
877 return AE_CTRL_DEPTH;
879 if (get_gsi_base(handle, &gsi_base))
882 acpi_unregister_ioapic(handle, gsi_base);
884 spin_lock(&ioapic_list_lock);
885 list_for_each_entry_safe(pos, n, &ioapic_list, list) {
886 if (pos->gsi_base != gsi_base)
889 list_del(&ioapic->list);
892 spin_unlock(&ioapic_list_lock);
897 pci_release_region(ioapic->dev, 0);
898 pci_disable_device(ioapic->dev);
899 pci_dev_put(ioapic->dev);
905 static int acpiphp_configure_ioapics(acpi_handle handle)
907 ioapic_add(handle, 0, NULL, NULL);
908 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
909 ACPI_UINT32_MAX, ioapic_add, NULL, NULL);
913 static int acpiphp_unconfigure_ioapics(acpi_handle handle)
915 ioapic_remove(handle, 0, NULL, NULL);
916 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
917 ACPI_UINT32_MAX, ioapic_remove, NULL, NULL);
921 static int power_on_slot(struct acpiphp_slot *slot)
924 struct acpiphp_func *func;
928 /* if already enabled, just skip */
929 if (slot->flags & SLOT_POWEREDON)
932 list_for_each (l, &slot->funcs) {
933 func = list_entry(l, struct acpiphp_func, sibling);
935 if (func->flags & FUNC_HAS_PS0) {
936 dbg("%s: executing _PS0\n", __func__);
937 status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL);
938 if (ACPI_FAILURE(status)) {
939 warn("%s: _PS0 failed\n", __func__);
947 /* TBD: evaluate _STA to check if the slot is enabled */
949 slot->flags |= SLOT_POWEREDON;
956 static int power_off_slot(struct acpiphp_slot *slot)
959 struct acpiphp_func *func;
964 /* if already disabled, just skip */
965 if ((slot->flags & SLOT_POWEREDON) == 0)
968 list_for_each (l, &slot->funcs) {
969 func = list_entry(l, struct acpiphp_func, sibling);
971 if (func->flags & FUNC_HAS_PS3) {
972 status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL);
973 if (ACPI_FAILURE(status)) {
974 warn("%s: _PS3 failed\n", __func__);
982 /* TBD: evaluate _STA to check if the slot is disabled */
984 slot->flags &= (~SLOT_POWEREDON);
993 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
994 * @bus: bus to start search with
996 static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
998 struct list_head *tmp;
999 unsigned char max, n;
1002 * pci_bus_max_busnr will return the highest
1003 * reserved busnr for all these children.
1004 * that is equivalent to the bus->subordinate
1005 * value. We don't want to use the parent's
1006 * bus->subordinate value because it could have
1009 max = bus->secondary;
1011 list_for_each(tmp, &bus->children) {
1012 n = pci_bus_max_busnr(pci_bus_b(tmp));
1021 * acpiphp_bus_add - add a new bus to acpi subsystem
1022 * @func: acpiphp_func of the bridge
1024 static int acpiphp_bus_add(struct acpiphp_func *func)
1026 acpi_handle phandle;
1027 struct acpi_device *device, *pdevice;
1030 acpi_get_parent(func->handle, &phandle);
1031 if (acpi_bus_get_device(phandle, &pdevice)) {
1032 dbg("no parent device, assuming NULL\n");
1035 if (!acpi_bus_get_device(func->handle, &device)) {
1036 dbg("bus exists... trim\n");
1037 /* this shouldn't be in here, so remove
1038 * the bus then re-add it...
1040 ret_val = acpi_bus_trim(device, 1);
1041 dbg("acpi_bus_trim return %x\n", ret_val);
1044 ret_val = acpi_bus_add(&device, pdevice, func->handle,
1045 ACPI_BUS_TYPE_DEVICE);
1047 dbg("error adding bus, %x\n",
1049 goto acpiphp_bus_add_out;
1052 * try to start anyway. We could have failed to add
1053 * simply because this bus had previously been added
1054 * on another add. Don't bother with the return value
1055 * we just keep going.
1057 ret_val = acpi_bus_start(device);
1059 acpiphp_bus_add_out:
1065 * acpiphp_bus_trim - trim a bus from acpi subsystem
1066 * @handle: handle to acpi namespace
1068 static int acpiphp_bus_trim(acpi_handle handle)
1070 struct acpi_device *device;
1073 retval = acpi_bus_get_device(handle, &device);
1075 dbg("acpi_device not found\n");
1079 retval = acpi_bus_trim(device, 1);
1081 err("cannot remove from acpi list\n");
1087 * enable_device - enable, configure a slot
1088 * @slot: slot to be enabled
1090 * This function should be called per *physical slot*,
1091 * not per each slot object in ACPI namespace.
1093 static int __ref enable_device(struct acpiphp_slot *slot)
1095 struct pci_dev *dev;
1096 struct pci_bus *bus = slot->bridge->pci_bus;
1097 struct list_head *l;
1098 struct acpiphp_func *func;
1103 if (slot->flags & SLOT_ENABLED)
1106 /* sanity check: dev should be NULL when hot-plugged in */
1107 dev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0));
1109 /* This case shouldn't happen */
1110 err("pci_dev structure already exists.\n");
1116 num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0));
1118 err("No new device found\n");
1123 max = acpiphp_max_busnr(bus);
1124 for (pass = 0; pass < 2; pass++) {
1125 list_for_each_entry(dev, &bus->devices, bus_list) {
1126 if (PCI_SLOT(dev->devfn) != slot->device)
1128 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
1129 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
1130 max = pci_scan_bridge(bus, dev, max, pass);
1131 if (pass && dev->subordinate)
1132 pci_bus_size_bridges(dev->subordinate);
1137 list_for_each (l, &slot->funcs) {
1138 func = list_entry(l, struct acpiphp_func, sibling);
1139 acpiphp_bus_add(func);
1142 pci_bus_assign_resources(bus);
1143 acpiphp_sanitize_bus(bus);
1144 acpiphp_set_hpp_values(slot->bridge->handle, bus);
1145 list_for_each_entry(func, &slot->funcs, sibling)
1146 acpiphp_configure_ioapics(func->handle);
1147 pci_enable_bridges(bus);
1148 pci_bus_add_devices(bus);
1150 /* associate pci_dev to our representation */
1151 list_for_each (l, &slot->funcs) {
1152 func = list_entry(l, struct acpiphp_func, sibling);
1153 func->pci_dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
1158 if (func->pci_dev->hdr_type != PCI_HEADER_TYPE_BRIDGE &&
1159 func->pci_dev->hdr_type != PCI_HEADER_TYPE_CARDBUS)
1162 status = find_p2p_bridge(func->handle, (u32)1, bus, NULL);
1163 if (ACPI_FAILURE(status))
1164 warn("find_p2p_bridge failed (error code = 0x%x)\n",
1168 slot->flags |= SLOT_ENABLED;
1174 static void disable_bridges(struct pci_bus *bus)
1176 struct pci_dev *dev;
1177 list_for_each_entry(dev, &bus->devices, bus_list) {
1178 if (dev->subordinate) {
1179 disable_bridges(dev->subordinate);
1180 pci_disable_device(dev);
1186 * disable_device - disable a slot
1187 * @slot: ACPI PHP slot
1189 static int disable_device(struct acpiphp_slot *slot)
1192 struct acpiphp_func *func;
1193 struct list_head *l;
1195 /* is this slot already disabled? */
1196 if (!(slot->flags & SLOT_ENABLED))
1199 list_for_each (l, &slot->funcs) {
1200 func = list_entry(l, struct acpiphp_func, sibling);
1203 /* cleanup p2p bridges under this P2P bridge */
1204 cleanup_p2p_bridge(func->bridge->handle,
1205 (u32)1, NULL, NULL);
1206 func->bridge = NULL;
1209 if (func->pci_dev) {
1210 pci_stop_bus_device(func->pci_dev);
1211 if (func->pci_dev->subordinate) {
1212 disable_bridges(func->pci_dev->subordinate);
1213 pci_disable_device(func->pci_dev);
1218 list_for_each (l, &slot->funcs) {
1219 func = list_entry(l, struct acpiphp_func, sibling);
1221 acpiphp_unconfigure_ioapics(func->handle);
1222 acpiphp_bus_trim(func->handle);
1223 /* try to remove anyway.
1224 * acpiphp_bus_add might have been failed */
1229 pci_remove_bus_device(func->pci_dev);
1230 pci_dev_put(func->pci_dev);
1231 func->pci_dev = NULL;
1234 slot->flags &= (~SLOT_ENABLED);
1242 * get_slot_status - get ACPI slot status
1243 * @slot: ACPI PHP slot
1245 * If a slot has _STA for each function and if any one of them
1246 * returned non-zero status, return it.
1248 * If a slot doesn't have _STA and if any one of its functions'
1249 * configuration space is configured, return 0x0f as a _STA.
1251 * Otherwise return 0.
1253 static unsigned int get_slot_status(struct acpiphp_slot *slot)
1256 unsigned long sta = 0;
1258 struct list_head *l;
1259 struct acpiphp_func *func;
1261 list_for_each (l, &slot->funcs) {
1262 func = list_entry(l, struct acpiphp_func, sibling);
1264 if (func->flags & FUNC_HAS_STA) {
1265 status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta);
1266 if (ACPI_SUCCESS(status) && sta)
1269 pci_bus_read_config_dword(slot->bridge->pci_bus,
1270 PCI_DEVFN(slot->device,
1272 PCI_VENDOR_ID, &dvid);
1273 if (dvid != 0xffffffff) {
1280 return (unsigned int)sta;
1284 * acpiphp_eject_slot - physically eject the slot
1285 * @slot: ACPI PHP slot
1287 int acpiphp_eject_slot(struct acpiphp_slot *slot)
1290 struct acpiphp_func *func;
1291 struct list_head *l;
1292 struct acpi_object_list arg_list;
1293 union acpi_object arg;
1295 list_for_each (l, &slot->funcs) {
1296 func = list_entry(l, struct acpiphp_func, sibling);
1298 /* We don't want to call _EJ0 on non-existing functions. */
1299 if ((func->flags & FUNC_HAS_EJ0)) {
1300 /* _EJ0 method take one argument */
1302 arg_list.pointer = &arg;
1303 arg.type = ACPI_TYPE_INTEGER;
1304 arg.integer.value = 1;
1306 status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL);
1307 if (ACPI_FAILURE(status)) {
1308 warn("%s: _EJ0 failed\n", __func__);
1318 * acpiphp_check_bridge - re-enumerate devices
1319 * @bridge: where to begin re-enumeration
1321 * Iterate over all slots under this bridge and make sure that if a
1322 * card is present they are enabled, and if not they are disabled.
1324 static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
1326 struct acpiphp_slot *slot;
1328 int enabled, disabled;
1330 enabled = disabled = 0;
1332 for (slot = bridge->slots; slot; slot = slot->next) {
1333 unsigned int status = get_slot_status(slot);
1334 if (slot->flags & SLOT_ENABLED) {
1335 if (status == ACPI_STA_ALL)
1337 retval = acpiphp_disable_slot(slot);
1339 err("Error occurred in disabling\n");
1342 acpiphp_eject_slot(slot);
1346 if (status != ACPI_STA_ALL)
1348 retval = acpiphp_enable_slot(slot);
1350 err("Error occurred in enabling\n");
1357 dbg("%s: %d enabled, %d disabled\n", __func__, enabled, disabled);
1363 static void program_hpp(struct pci_dev *dev, struct acpiphp_bridge *bridge)
1365 u16 pci_cmd, pci_bctl;
1366 struct pci_dev *cdev;
1368 /* Program hpp values for this device */
1369 if (!(dev->hdr_type == PCI_HEADER_TYPE_NORMAL ||
1370 (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&
1371 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)))
1374 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_HOST)
1377 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
1378 bridge->hpp.t0->cache_line_size);
1379 pci_write_config_byte(dev, PCI_LATENCY_TIMER,
1380 bridge->hpp.t0->latency_timer);
1381 pci_read_config_word(dev, PCI_COMMAND, &pci_cmd);
1382 if (bridge->hpp.t0->enable_serr)
1383 pci_cmd |= PCI_COMMAND_SERR;
1385 pci_cmd &= ~PCI_COMMAND_SERR;
1386 if (bridge->hpp.t0->enable_perr)
1387 pci_cmd |= PCI_COMMAND_PARITY;
1389 pci_cmd &= ~PCI_COMMAND_PARITY;
1390 pci_write_config_word(dev, PCI_COMMAND, pci_cmd);
1392 /* Program bridge control value and child devices */
1393 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
1394 pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER,
1395 bridge->hpp.t0->latency_timer);
1396 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl);
1397 if (bridge->hpp.t0->enable_serr)
1398 pci_bctl |= PCI_BRIDGE_CTL_SERR;
1400 pci_bctl &= ~PCI_BRIDGE_CTL_SERR;
1401 if (bridge->hpp.t0->enable_perr)
1402 pci_bctl |= PCI_BRIDGE_CTL_PARITY;
1404 pci_bctl &= ~PCI_BRIDGE_CTL_PARITY;
1405 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, pci_bctl);
1406 if (dev->subordinate) {
1407 list_for_each_entry(cdev, &dev->subordinate->devices,
1409 program_hpp(cdev, bridge);
1414 static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus)
1416 struct acpiphp_bridge bridge;
1417 struct pci_dev *dev;
1419 memset(&bridge, 0, sizeof(bridge));
1420 bridge.handle = handle;
1421 bridge.pci_bus = bus;
1422 bridge.pci_dev = bus->self;
1423 decode_hpp(&bridge);
1424 list_for_each_entry(dev, &bus->devices, bus_list)
1425 program_hpp(dev, &bridge);
1430 * Remove devices for which we could not assign resources, call
1431 * arch specific code to fix-up the bus
1433 static void acpiphp_sanitize_bus(struct pci_bus *bus)
1435 struct pci_dev *dev;
1437 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
1439 list_for_each_entry(dev, &bus->devices, bus_list) {
1440 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
1441 struct resource *res = &dev->resource[i];
1442 if ((res->flags & type_mask) && !res->start &&
1444 /* Could not assign a required resources
1445 * for this device, remove it */
1446 pci_remove_bus_device(dev);
1453 /* Program resources in newly inserted bridge */
1454 static int acpiphp_configure_bridge (acpi_handle handle)
1456 struct acpi_pci_id pci_id;
1457 struct pci_bus *bus;
1459 if (ACPI_FAILURE(acpi_get_pci_id(handle, &pci_id))) {
1460 err("cannot get PCI domain and bus number for bridge\n");
1463 bus = pci_find_bus(pci_id.segment, pci_id.bus);
1465 err("cannot find bus %d:%d\n",
1466 pci_id.segment, pci_id.bus);
1470 pci_bus_size_bridges(bus);
1471 pci_bus_assign_resources(bus);
1472 acpiphp_sanitize_bus(bus);
1473 acpiphp_set_hpp_values(handle, bus);
1474 pci_enable_bridges(bus);
1475 acpiphp_configure_ioapics(handle);
1479 static void handle_bridge_insertion(acpi_handle handle, u32 type)
1481 struct acpi_device *device, *pdevice;
1482 acpi_handle phandle;
1484 if ((type != ACPI_NOTIFY_BUS_CHECK) &&
1485 (type != ACPI_NOTIFY_DEVICE_CHECK)) {
1486 err("unexpected notification type %d\n", type);
1490 acpi_get_parent(handle, &phandle);
1491 if (acpi_bus_get_device(phandle, &pdevice)) {
1492 dbg("no parent device, assuming NULL\n");
1495 if (acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE)) {
1496 err("cannot add bridge to acpi list\n");
1499 if (!acpiphp_configure_bridge(handle) &&
1500 !acpi_bus_start(device))
1503 err("cannot configure and start bridge\n");
1508 * ACPI event handlers
1512 count_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
1514 int *count = (int *)context;
1515 struct acpiphp_bridge *bridge;
1517 bridge = acpiphp_handle_to_bridge(handle);
1524 check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
1526 struct acpiphp_bridge *bridge;
1528 struct acpi_buffer buffer = { .length = sizeof(objname),
1529 .pointer = objname };
1531 bridge = acpiphp_handle_to_bridge(handle);
1533 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1534 dbg("%s: re-enumerating slots under %s\n",
1536 acpiphp_check_bridge(bridge);
1542 * handle_hotplug_event_bridge - handle ACPI event on bridges
1543 * @handle: Notify()'ed acpi_handle
1544 * @type: Notify code
1545 * @context: pointer to acpiphp_bridge structure
1547 * Handles ACPI event notification on {host,p2p} bridges.
1549 static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *context)
1551 struct acpiphp_bridge *bridge;
1553 struct acpi_buffer buffer = { .length = sizeof(objname),
1554 .pointer = objname };
1555 struct acpi_device *device;
1556 int num_sub_bridges = 0;
1558 if (acpi_bus_get_device(handle, &device)) {
1559 /* This bridge must have just been physically inserted */
1560 handle_bridge_insertion(handle, type);
1564 bridge = acpiphp_handle_to_bridge(handle);
1565 if (type == ACPI_NOTIFY_BUS_CHECK) {
1566 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, ACPI_UINT32_MAX,
1567 count_sub_bridges, &num_sub_bridges, NULL);
1570 if (!bridge && !num_sub_bridges) {
1571 err("cannot get bridge info\n");
1575 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1578 case ACPI_NOTIFY_BUS_CHECK:
1579 /* bus re-enumerate */
1580 dbg("%s: Bus check notify on %s\n", __func__, objname);
1582 dbg("%s: re-enumerating slots under %s\n",
1584 acpiphp_check_bridge(bridge);
1586 if (num_sub_bridges)
1587 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
1588 ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL);
1591 case ACPI_NOTIFY_DEVICE_CHECK:
1593 dbg("%s: Device check notify on %s\n", __func__, objname);
1594 acpiphp_check_bridge(bridge);
1597 case ACPI_NOTIFY_DEVICE_WAKE:
1599 dbg("%s: Device wake notify on %s\n", __func__, objname);
1602 case ACPI_NOTIFY_EJECT_REQUEST:
1603 /* request device eject */
1604 dbg("%s: Device eject notify on %s\n", __func__, objname);
1605 if ((bridge->type != BRIDGE_TYPE_HOST) &&
1606 (bridge->flags & BRIDGE_HAS_EJ0)) {
1607 struct acpiphp_slot *slot;
1608 slot = bridge->func->slot;
1609 if (!acpiphp_disable_slot(slot))
1610 acpiphp_eject_slot(slot);
1614 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
1615 printk(KERN_ERR "Device %s cannot be configured due"
1616 " to a frequency mismatch\n", objname);
1619 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
1620 printk(KERN_ERR "Device %s cannot be configured due"
1621 " to a bus mode mismatch\n", objname);
1624 case ACPI_NOTIFY_POWER_FAULT:
1625 printk(KERN_ERR "Device %s has suffered a power fault\n",
1630 warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
1636 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
1637 * @handle: Notify()'ed acpi_handle
1638 * @type: Notify code
1639 * @context: pointer to acpiphp_func structure
1641 * Handles ACPI event notification on slots.
1643 static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context)
1645 struct acpiphp_func *func;
1647 struct acpi_buffer buffer = { .length = sizeof(objname),
1648 .pointer = objname };
1650 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1652 func = (struct acpiphp_func *)context;
1655 case ACPI_NOTIFY_BUS_CHECK:
1656 /* bus re-enumerate */
1657 dbg("%s: Bus check notify on %s\n", __func__, objname);
1658 acpiphp_enable_slot(func->slot);
1661 case ACPI_NOTIFY_DEVICE_CHECK:
1662 /* device check : re-enumerate from parent bus */
1663 dbg("%s: Device check notify on %s\n", __func__, objname);
1664 acpiphp_check_bridge(func->slot->bridge);
1667 case ACPI_NOTIFY_DEVICE_WAKE:
1669 dbg("%s: Device wake notify on %s\n", __func__, objname);
1672 case ACPI_NOTIFY_EJECT_REQUEST:
1673 /* request device eject */
1674 dbg("%s: Device eject notify on %s\n", __func__, objname);
1675 if (!(acpiphp_disable_slot(func->slot)))
1676 acpiphp_eject_slot(func->slot);
1680 warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
1687 find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
1689 int *count = (int *)context;
1691 if (acpi_root_bridge(handle)) {
1692 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
1693 handle_hotplug_event_bridge, NULL);
1699 static struct acpi_pci_driver acpi_pci_hp_driver = {
1701 .remove = remove_bridge,
1705 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
1707 int __init acpiphp_glue_init(void)
1711 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1712 ACPI_UINT32_MAX, find_root_bridges, &num, NULL);
1717 acpi_pci_register_driver(&acpi_pci_hp_driver);
1724 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures
1726 * This function frees all data allocated in acpiphp_glue_init().
1728 void acpiphp_glue_exit(void)
1730 acpi_pci_unregister_driver(&acpi_pci_hp_driver);
1735 * acpiphp_get_num_slots - count number of slots in a system
1737 int __init acpiphp_get_num_slots(void)
1739 struct acpiphp_bridge *bridge;
1742 list_for_each_entry (bridge, &bridge_list, list) {
1743 dbg("Bus %04x:%02x has %d slot%s\n",
1744 pci_domain_nr(bridge->pci_bus),
1745 bridge->pci_bus->number, bridge->nr_slots,
1746 bridge->nr_slots == 1 ? "" : "s");
1747 num_slots += bridge->nr_slots;
1750 dbg("Total %d slots\n", num_slots);
1757 * acpiphp_for_each_slot - call function for each slot
1758 * @fn: callback function
1759 * @data: context to be passed to callback function
1761 static int acpiphp_for_each_slot(acpiphp_callback fn, void *data)
1763 struct list_head *node;
1764 struct acpiphp_bridge *bridge;
1765 struct acpiphp_slot *slot;
1768 list_for_each (node, &bridge_list) {
1769 bridge = (struct acpiphp_bridge *)node;
1770 for (slot = bridge->slots; slot; slot = slot->next) {
1771 retval = fn(slot, data);
1784 * acpiphp_enable_slot - power on slot
1785 * @slot: ACPI PHP slot
1787 int acpiphp_enable_slot(struct acpiphp_slot *slot)
1791 mutex_lock(&slot->crit_sect);
1793 /* wake up all functions */
1794 retval = power_on_slot(slot);
1798 if (get_slot_status(slot) == ACPI_STA_ALL) {
1799 /* configure all functions */
1800 retval = enable_device(slot);
1802 power_off_slot(slot);
1804 dbg("%s: Slot status is not ACPI_STA_ALL\n", __func__);
1805 power_off_slot(slot);
1809 mutex_unlock(&slot->crit_sect);
1814 * acpiphp_disable_slot - power off slot
1815 * @slot: ACPI PHP slot
1817 int acpiphp_disable_slot(struct acpiphp_slot *slot)
1821 mutex_lock(&slot->crit_sect);
1823 /* unconfigure all functions */
1824 retval = disable_device(slot);
1828 /* power off all functions */
1829 retval = power_off_slot(slot);
1834 mutex_unlock(&slot->crit_sect);
1843 u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
1845 return (slot->flags & SLOT_POWEREDON);
1853 u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1857 sta = get_slot_status(slot);
1859 return (sta & ACPI_STA_SHOW_IN_UI) ? 0 : 1;
1864 * adapter presence : 1
1867 u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1871 sta = get_slot_status(slot);
1873 return (sta == 0) ? 0 : 1;