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/pci-acpi.h>
50 #include <linux/mutex.h>
55 static LIST_HEAD(bridge_list
);
56 static LIST_HEAD(ioapic_list
);
57 static DEFINE_SPINLOCK(ioapic_list_lock
);
59 #define MY_NAME "acpiphp_glue"
61 static void handle_hotplug_event_bridge (acpi_handle
, u32
, void *);
62 static void acpiphp_sanitize_bus(struct pci_bus
*bus
);
63 static void acpiphp_set_hpp_values(acpi_handle handle
, struct pci_bus
*bus
);
64 static void handle_hotplug_event_func(acpi_handle handle
, u32 type
, void *context
);
66 /* callback routine to check for the existence of a pci dock device */
68 is_pci_dock_device(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
70 int *count
= (int *)context
;
72 if (is_dock_device(handle
)) {
74 return AE_CTRL_TERMINATE
;
81 * the _DCK method can do funny things... and sometimes not
84 * TBD - figure out a way to only call fixups for
85 * systems that require them.
87 static int post_dock_fixups(struct notifier_block
*nb
, unsigned long val
,
90 struct acpiphp_func
*func
= container_of(nb
, struct acpiphp_func
, nb
);
91 struct pci_bus
*bus
= func
->slot
->bridge
->pci_bus
;
97 /* fixup bad _DCK function that rewrites
98 * secondary bridge on slot
100 pci_read_config_dword(bus
->self
,
104 if (((buses
>> 8) & 0xff) != bus
->secondary
) {
105 buses
= (buses
& 0xff000000)
106 | ((unsigned int)(bus
->primary
) << 0)
107 | ((unsigned int)(bus
->secondary
) << 8)
108 | ((unsigned int)(bus
->subordinate
) << 16);
109 pci_write_config_dword(bus
->self
, PCI_PRIMARY_BUS
, buses
);
115 static struct acpi_dock_ops acpiphp_dock_ops
= {
116 .handler
= handle_hotplug_event_func
,
119 /* callback routine to register each ACPI PCI slot object */
121 register_slot(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
123 struct acpiphp_bridge
*bridge
= (struct acpiphp_bridge
*)context
;
124 struct acpiphp_slot
*slot
;
125 struct acpiphp_func
*newfunc
;
127 acpi_status status
= AE_OK
;
128 unsigned long long adr
, sun
;
129 int device
, function
, retval
;
130 struct pci_bus
*pbus
= bridge
->pci_bus
;
132 if (!acpi_pci_check_ejectable(pbus
, handle
) && !is_dock_device(handle
))
135 acpi_evaluate_integer(handle
, "_ADR", NULL
, &adr
);
136 device
= (adr
>> 16) & 0xffff;
137 function
= adr
& 0xffff;
139 newfunc
= kzalloc(sizeof(struct acpiphp_func
), GFP_KERNEL
);
143 INIT_LIST_HEAD(&newfunc
->sibling
);
144 newfunc
->handle
= handle
;
145 newfunc
->function
= function
;
147 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_EJ0", &tmp
)))
148 newfunc
->flags
= FUNC_HAS_EJ0
;
150 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_STA", &tmp
)))
151 newfunc
->flags
|= FUNC_HAS_STA
;
153 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_PS0", &tmp
)))
154 newfunc
->flags
|= FUNC_HAS_PS0
;
156 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_PS3", &tmp
)))
157 newfunc
->flags
|= FUNC_HAS_PS3
;
159 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_DCK", &tmp
)))
160 newfunc
->flags
|= FUNC_HAS_DCK
;
162 status
= acpi_evaluate_integer(handle
, "_SUN", NULL
, &sun
);
163 if (ACPI_FAILURE(status
)) {
165 * use the count of the number of slots we've found
166 * for the number of the slot
168 sun
= bridge
->nr_slots
+1;
171 /* search for objects that share the same slot */
172 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
)
173 if (slot
->device
== device
) {
174 if (slot
->sun
!= sun
)
175 warn("sibling found, but _SUN doesn't match!\n");
180 slot
= kzalloc(sizeof(struct acpiphp_slot
), GFP_KERNEL
);
186 slot
->bridge
= bridge
;
187 slot
->device
= device
;
189 INIT_LIST_HEAD(&slot
->funcs
);
190 mutex_init(&slot
->crit_sect
);
192 slot
->next
= bridge
->slots
;
193 bridge
->slots
= slot
;
197 dbg("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
198 slot
->sun
, pci_domain_nr(pbus
), pbus
->number
, device
);
199 retval
= acpiphp_register_hotplug_slot(slot
);
201 if (retval
== -EBUSY
)
202 warn("Slot %llu already registered by another "
203 "hotplug driver\n", slot
->sun
);
205 warn("acpiphp_register_hotplug_slot failed "
206 "(err code = 0x%x)\n", retval
);
211 newfunc
->slot
= slot
;
212 list_add_tail(&newfunc
->sibling
, &slot
->funcs
);
214 /* associate corresponding pci_dev */
215 newfunc
->pci_dev
= pci_get_slot(pbus
, PCI_DEVFN(device
, function
));
216 if (newfunc
->pci_dev
) {
217 slot
->flags
|= (SLOT_ENABLED
| SLOT_POWEREDON
);
220 if (is_dock_device(handle
)) {
221 /* we don't want to call this device's _EJ0
222 * because we want the dock notify handler
223 * to call it after it calls _DCK
225 newfunc
->flags
&= ~FUNC_HAS_EJ0
;
226 if (register_hotplug_dock_device(handle
,
227 &acpiphp_dock_ops
, newfunc
))
228 dbg("failed to register dock device\n");
230 /* we need to be notified when dock events happen
231 * outside of the hotplug operation, since we may
232 * need to do fixups before we can hotplug.
234 newfunc
->nb
.notifier_call
= post_dock_fixups
;
235 if (register_dock_notifier(&newfunc
->nb
))
236 dbg("failed to register a dock notifier");
239 /* install notify handler */
240 if (!(newfunc
->flags
& FUNC_HAS_DCK
)) {
241 status
= acpi_install_notify_handler(handle
,
243 handle_hotplug_event_func
,
246 if (ACPI_FAILURE(status
))
247 err("failed to register interrupt notify handler\n");
255 bridge
->slots
= slot
->next
;
263 /* see if it's worth looking at this bridge */
264 static int detect_ejectable_slots(struct pci_bus
*pbus
)
266 int found
= acpi_pci_detect_ejectable(pbus
);
268 acpi_handle bridge_handle
= acpi_pci_get_bridge_handle(pbus
);
269 acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge_handle
, (u32
)1,
270 is_pci_dock_device
, (void *)&found
, NULL
);
276 /* decode ACPI 2.0 _HPP hot plug parameters */
277 static void decode_hpp(struct acpiphp_bridge
*bridge
)
281 status
= acpi_get_hp_params_from_firmware(bridge
->pci_bus
, &bridge
->hpp
);
282 if (ACPI_FAILURE(status
) ||
283 !bridge
->hpp
.t0
|| (bridge
->hpp
.t0
->revision
> 1)) {
284 /* use default numbers */
286 "%s: Could not get hotplug parameters. Use defaults\n",
288 bridge
->hpp
.t0
= &bridge
->hpp
.type0_data
;
289 bridge
->hpp
.t0
->revision
= 0;
290 bridge
->hpp
.t0
->cache_line_size
= 0x10;
291 bridge
->hpp
.t0
->latency_timer
= 0x40;
292 bridge
->hpp
.t0
->enable_serr
= 0;
293 bridge
->hpp
.t0
->enable_perr
= 0;
299 /* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */
300 static void init_bridge_misc(struct acpiphp_bridge
*bridge
)
304 /* decode ACPI 2.0 _HPP (hot plug parameters) */
307 /* must be added to the list prior to calling register_slot */
308 list_add(&bridge
->list
, &bridge_list
);
310 /* register all slot objects under this bridge */
311 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge
->handle
, (u32
)1,
312 register_slot
, bridge
, NULL
);
313 if (ACPI_FAILURE(status
)) {
314 list_del(&bridge
->list
);
318 /* install notify handler */
319 if (bridge
->type
!= BRIDGE_TYPE_HOST
) {
320 if ((bridge
->flags
& BRIDGE_HAS_EJ0
) && bridge
->func
) {
321 status
= acpi_remove_notify_handler(bridge
->func
->handle
,
323 handle_hotplug_event_func
);
324 if (ACPI_FAILURE(status
))
325 err("failed to remove notify handler\n");
327 status
= acpi_install_notify_handler(bridge
->handle
,
329 handle_hotplug_event_bridge
,
332 if (ACPI_FAILURE(status
)) {
333 err("failed to register interrupt notify handler\n");
339 /* find acpiphp_func from acpiphp_bridge */
340 static struct acpiphp_func
*acpiphp_bridge_handle_to_function(acpi_handle handle
)
342 struct list_head
*node
, *l
;
343 struct acpiphp_bridge
*bridge
;
344 struct acpiphp_slot
*slot
;
345 struct acpiphp_func
*func
;
347 list_for_each(node
, &bridge_list
) {
348 bridge
= list_entry(node
, struct acpiphp_bridge
, list
);
349 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
350 list_for_each(l
, &slot
->funcs
) {
351 func
= list_entry(l
, struct acpiphp_func
,
353 if (func
->handle
== handle
)
363 static inline void config_p2p_bridge_flags(struct acpiphp_bridge
*bridge
)
365 acpi_handle dummy_handle
;
367 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
368 "_STA", &dummy_handle
)))
369 bridge
->flags
|= BRIDGE_HAS_STA
;
371 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
372 "_EJ0", &dummy_handle
)))
373 bridge
->flags
|= BRIDGE_HAS_EJ0
;
375 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
376 "_PS0", &dummy_handle
)))
377 bridge
->flags
|= BRIDGE_HAS_PS0
;
379 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
380 "_PS3", &dummy_handle
)))
381 bridge
->flags
|= BRIDGE_HAS_PS3
;
383 /* is this ejectable p2p bridge? */
384 if (bridge
->flags
& BRIDGE_HAS_EJ0
) {
385 struct acpiphp_func
*func
;
387 dbg("found ejectable p2p bridge\n");
389 /* make link between PCI bridge and PCI function */
390 func
= acpiphp_bridge_handle_to_function(bridge
->handle
);
394 func
->bridge
= bridge
;
399 /* allocate and initialize host bridge data structure */
400 static void add_host_bridge(acpi_handle
*handle
, struct pci_bus
*pci_bus
)
402 struct acpiphp_bridge
*bridge
;
404 bridge
= kzalloc(sizeof(struct acpiphp_bridge
), GFP_KERNEL
);
408 bridge
->type
= BRIDGE_TYPE_HOST
;
409 bridge
->handle
= handle
;
411 bridge
->pci_bus
= pci_bus
;
413 spin_lock_init(&bridge
->res_lock
);
415 init_bridge_misc(bridge
);
419 /* allocate and initialize PCI-to-PCI bridge data structure */
420 static void add_p2p_bridge(acpi_handle
*handle
, struct pci_dev
*pci_dev
)
422 struct acpiphp_bridge
*bridge
;
424 bridge
= kzalloc(sizeof(struct acpiphp_bridge
), GFP_KERNEL
);
425 if (bridge
== NULL
) {
426 err("out of memory\n");
430 bridge
->type
= BRIDGE_TYPE_P2P
;
431 bridge
->handle
= handle
;
432 config_p2p_bridge_flags(bridge
);
434 bridge
->pci_dev
= pci_dev_get(pci_dev
);
435 bridge
->pci_bus
= pci_dev
->subordinate
;
436 if (!bridge
->pci_bus
) {
437 err("This is not a PCI-to-PCI bridge!\n");
441 spin_lock_init(&bridge
->res_lock
);
443 init_bridge_misc(bridge
);
446 pci_dev_put(pci_dev
);
452 /* callback routine to find P2P bridges */
454 find_p2p_bridge(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
457 acpi_handle dummy_handle
;
458 unsigned long long tmp
;
459 int device
, function
;
461 struct pci_bus
*pci_bus
= context
;
463 status
= acpi_get_handle(handle
, "_ADR", &dummy_handle
);
464 if (ACPI_FAILURE(status
))
465 return AE_OK
; /* continue */
467 status
= acpi_evaluate_integer(handle
, "_ADR", NULL
, &tmp
);
468 if (ACPI_FAILURE(status
)) {
469 dbg("%s: _ADR evaluation failure\n", __func__
);
473 device
= (tmp
>> 16) & 0xffff;
474 function
= tmp
& 0xffff;
476 dev
= pci_get_slot(pci_bus
, PCI_DEVFN(device
, function
));
478 if (!dev
|| !dev
->subordinate
)
481 /* check if this bridge has ejectable slots */
482 if ((detect_ejectable_slots(dev
->subordinate
) > 0)) {
483 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev
));
484 add_p2p_bridge(handle
, dev
);
487 /* search P2P bridges under this p2p bridge */
488 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
489 find_p2p_bridge
, dev
->subordinate
, NULL
);
490 if (ACPI_FAILURE(status
))
491 warn("find_p2p_bridge failed (error code = 0x%x)\n", status
);
499 /* find hot-pluggable slots, and then find P2P bridge */
500 static int add_bridge(acpi_handle handle
)
503 unsigned long long tmp
;
505 acpi_handle dummy_handle
;
506 struct pci_bus
*pci_bus
;
508 /* if the bridge doesn't have _STA, we assume it is always there */
509 status
= acpi_get_handle(handle
, "_STA", &dummy_handle
);
510 if (ACPI_SUCCESS(status
)) {
511 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &tmp
);
512 if (ACPI_FAILURE(status
)) {
513 dbg("%s: _STA evaluation failure\n", __func__
);
516 if ((tmp
& ACPI_STA_FUNCTIONING
) == 0)
517 /* don't register this object */
521 /* get PCI segment number */
522 status
= acpi_evaluate_integer(handle
, "_SEG", NULL
, &tmp
);
524 seg
= ACPI_SUCCESS(status
) ? tmp
: 0;
526 /* get PCI bus number */
527 status
= acpi_evaluate_integer(handle
, "_BBN", NULL
, &tmp
);
529 if (ACPI_SUCCESS(status
)) {
532 warn("can't get bus number, assuming 0\n");
536 pci_bus
= pci_find_bus(seg
, bus
);
538 err("Can't find bus %04x:%02x\n", seg
, bus
);
542 /* check if this bridge has ejectable slots */
543 if (detect_ejectable_slots(pci_bus
) > 0) {
544 dbg("found PCI host-bus bridge with hot-pluggable slots\n");
545 add_host_bridge(handle
, pci_bus
);
548 /* search P2P bridges under this host bridge */
549 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
550 find_p2p_bridge
, pci_bus
, NULL
);
552 if (ACPI_FAILURE(status
))
553 warn("find_p2p_bridge failed (error code = 0x%x)\n", status
);
558 static struct acpiphp_bridge
*acpiphp_handle_to_bridge(acpi_handle handle
)
560 struct list_head
*head
;
561 list_for_each(head
, &bridge_list
) {
562 struct acpiphp_bridge
*bridge
= list_entry(head
,
563 struct acpiphp_bridge
, list
);
564 if (bridge
->handle
== handle
)
571 static void cleanup_bridge(struct acpiphp_bridge
*bridge
)
573 struct list_head
*list
, *tmp
;
574 struct acpiphp_slot
*slot
;
576 acpi_handle handle
= bridge
->handle
;
578 status
= acpi_remove_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
579 handle_hotplug_event_bridge
);
580 if (ACPI_FAILURE(status
))
581 err("failed to remove notify handler\n");
583 if ((bridge
->type
!= BRIDGE_TYPE_HOST
) &&
584 ((bridge
->flags
& BRIDGE_HAS_EJ0
) && bridge
->func
)) {
585 status
= acpi_install_notify_handler(bridge
->func
->handle
,
587 handle_hotplug_event_func
,
589 if (ACPI_FAILURE(status
))
590 err("failed to install interrupt notify handler\n");
593 slot
= bridge
->slots
;
595 struct acpiphp_slot
*next
= slot
->next
;
596 list_for_each_safe (list
, tmp
, &slot
->funcs
) {
597 struct acpiphp_func
*func
;
598 func
= list_entry(list
, struct acpiphp_func
, sibling
);
599 if (is_dock_device(func
->handle
)) {
600 unregister_hotplug_dock_device(func
->handle
);
601 unregister_dock_notifier(&func
->nb
);
603 if (!(func
->flags
& FUNC_HAS_DCK
)) {
604 status
= acpi_remove_notify_handler(func
->handle
,
606 handle_hotplug_event_func
);
607 if (ACPI_FAILURE(status
))
608 err("failed to remove notify handler\n");
610 pci_dev_put(func
->pci_dev
);
614 acpiphp_unregister_hotplug_slot(slot
);
615 list_del(&slot
->funcs
);
620 pci_dev_put(bridge
->pci_dev
);
621 list_del(&bridge
->list
);
626 cleanup_p2p_bridge(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
628 struct acpiphp_bridge
*bridge
;
630 /* cleanup p2p bridges under this P2P bridge
631 in a depth-first manner */
632 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
633 cleanup_p2p_bridge
, NULL
, NULL
);
635 bridge
= acpiphp_handle_to_bridge(handle
);
637 cleanup_bridge(bridge
);
642 static void remove_bridge(acpi_handle handle
)
644 struct acpiphp_bridge
*bridge
;
646 /* cleanup p2p bridges under this host bridge
647 in a depth-first manner */
648 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
649 (u32
)1, cleanup_p2p_bridge
, NULL
, NULL
);
652 * On root bridges with hotplug slots directly underneath (ie,
653 * no p2p bridge inbetween), we call cleanup_bridge().
655 * The else clause cleans up root bridges that either had no
656 * hotplug slots at all, or had a p2p bridge underneath.
658 bridge
= acpiphp_handle_to_bridge(handle
);
660 cleanup_bridge(bridge
);
662 acpi_remove_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
663 handle_hotplug_event_bridge
);
666 static struct pci_dev
* get_apic_pci_info(acpi_handle handle
)
668 struct acpi_pci_id id
;
672 if (ACPI_FAILURE(acpi_get_pci_id(handle
, &id
)))
675 bus
= pci_find_bus(id
.segment
, id
.bus
);
679 dev
= pci_get_slot(bus
, PCI_DEVFN(id
.device
, id
.function
));
683 if ((dev
->class != PCI_CLASS_SYSTEM_PIC_IOAPIC
) &&
684 (dev
->class != PCI_CLASS_SYSTEM_PIC_IOXAPIC
))
693 static int get_gsi_base(acpi_handle handle
, u32
*gsi_base
)
697 unsigned long long gsb
;
698 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
699 union acpi_object
*obj
;
702 status
= acpi_evaluate_integer(handle
, "_GSB", NULL
, &gsb
);
703 if (ACPI_SUCCESS(status
)) {
704 *gsi_base
= (u32
)gsb
;
708 status
= acpi_evaluate_object(handle
, "_MAT", NULL
, &buffer
);
709 if (ACPI_FAILURE(status
) || !buffer
.length
|| !buffer
.pointer
)
712 obj
= buffer
.pointer
;
713 if (obj
->type
!= ACPI_TYPE_BUFFER
)
716 table
= obj
->buffer
.pointer
;
717 switch (((struct acpi_subtable_header
*)table
)->type
) {
718 case ACPI_MADT_TYPE_IO_SAPIC
:
719 *gsi_base
= ((struct acpi_madt_io_sapic
*)table
)->global_irq_base
;
722 case ACPI_MADT_TYPE_IO_APIC
:
723 *gsi_base
= ((struct acpi_madt_io_apic
*)table
)->global_irq_base
;
730 kfree(buffer
.pointer
);
735 ioapic_add(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
738 unsigned long long sta
;
740 struct pci_dev
*pdev
;
743 struct acpiphp_ioapic
*ioapic
;
745 /* Evaluate _STA if present */
746 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &sta
);
747 if (ACPI_SUCCESS(status
) && sta
!= ACPI_STA_ALL
)
748 return AE_CTRL_DEPTH
;
750 /* Scan only PCI bus scope */
751 status
= acpi_get_handle(handle
, "_HID", &tmp
);
752 if (ACPI_SUCCESS(status
))
753 return AE_CTRL_DEPTH
;
755 if (get_gsi_base(handle
, &gsi_base
))
758 ioapic
= kmalloc(sizeof(*ioapic
), GFP_KERNEL
);
762 pdev
= get_apic_pci_info(handle
);
766 if (pci_enable_device(pdev
))
767 goto exit_pci_dev_put
;
769 pci_set_master(pdev
);
771 if (pci_request_region(pdev
, 0, "I/O APIC(acpiphp)"))
772 goto exit_pci_disable_device
;
774 phys_addr
= pci_resource_start(pdev
, 0);
775 if (acpi_register_ioapic(handle
, phys_addr
, gsi_base
))
776 goto exit_pci_release_region
;
778 ioapic
->gsi_base
= gsi_base
;
780 spin_lock(&ioapic_list_lock
);
781 list_add_tail(&ioapic
->list
, &ioapic_list
);
782 spin_unlock(&ioapic_list_lock
);
786 exit_pci_release_region
:
787 pci_release_region(pdev
, 0);
788 exit_pci_disable_device
:
789 pci_disable_device(pdev
);
799 ioapic_remove(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
802 unsigned long long sta
;
805 struct acpiphp_ioapic
*pos
, *n
, *ioapic
= NULL
;
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 acpi_unregister_ioapic(handle
, gsi_base
);
822 spin_lock(&ioapic_list_lock
);
823 list_for_each_entry_safe(pos
, n
, &ioapic_list
, list
) {
824 if (pos
->gsi_base
!= gsi_base
)
827 list_del(&ioapic
->list
);
830 spin_unlock(&ioapic_list_lock
);
835 pci_release_region(ioapic
->dev
, 0);
836 pci_disable_device(ioapic
->dev
);
837 pci_dev_put(ioapic
->dev
);
843 static int acpiphp_configure_ioapics(acpi_handle handle
)
845 ioapic_add(handle
, 0, NULL
, NULL
);
846 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
847 ACPI_UINT32_MAX
, ioapic_add
, NULL
, NULL
);
851 static int acpiphp_unconfigure_ioapics(acpi_handle handle
)
853 ioapic_remove(handle
, 0, NULL
, NULL
);
854 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
855 ACPI_UINT32_MAX
, ioapic_remove
, NULL
, NULL
);
859 static int power_on_slot(struct acpiphp_slot
*slot
)
862 struct acpiphp_func
*func
;
866 /* if already enabled, just skip */
867 if (slot
->flags
& SLOT_POWEREDON
)
870 list_for_each (l
, &slot
->funcs
) {
871 func
= list_entry(l
, struct acpiphp_func
, sibling
);
873 if (func
->flags
& FUNC_HAS_PS0
) {
874 dbg("%s: executing _PS0\n", __func__
);
875 status
= acpi_evaluate_object(func
->handle
, "_PS0", NULL
, NULL
);
876 if (ACPI_FAILURE(status
)) {
877 warn("%s: _PS0 failed\n", __func__
);
885 /* TBD: evaluate _STA to check if the slot is enabled */
887 slot
->flags
|= SLOT_POWEREDON
;
894 static int power_off_slot(struct acpiphp_slot
*slot
)
897 struct acpiphp_func
*func
;
902 /* if already disabled, just skip */
903 if ((slot
->flags
& SLOT_POWEREDON
) == 0)
906 list_for_each (l
, &slot
->funcs
) {
907 func
= list_entry(l
, struct acpiphp_func
, sibling
);
909 if (func
->flags
& FUNC_HAS_PS3
) {
910 status
= acpi_evaluate_object(func
->handle
, "_PS3", NULL
, NULL
);
911 if (ACPI_FAILURE(status
)) {
912 warn("%s: _PS3 failed\n", __func__
);
920 /* TBD: evaluate _STA to check if the slot is disabled */
922 slot
->flags
&= (~SLOT_POWEREDON
);
931 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
932 * @bus: bus to start search with
934 static unsigned char acpiphp_max_busnr(struct pci_bus
*bus
)
936 struct list_head
*tmp
;
937 unsigned char max
, n
;
940 * pci_bus_max_busnr will return the highest
941 * reserved busnr for all these children.
942 * that is equivalent to the bus->subordinate
943 * value. We don't want to use the parent's
944 * bus->subordinate value because it could have
947 max
= bus
->secondary
;
949 list_for_each(tmp
, &bus
->children
) {
950 n
= pci_bus_max_busnr(pci_bus_b(tmp
));
959 * acpiphp_bus_add - add a new bus to acpi subsystem
960 * @func: acpiphp_func of the bridge
962 static int acpiphp_bus_add(struct acpiphp_func
*func
)
965 struct acpi_device
*device
, *pdevice
;
968 acpi_get_parent(func
->handle
, &phandle
);
969 if (acpi_bus_get_device(phandle
, &pdevice
)) {
970 dbg("no parent device, assuming NULL\n");
973 if (!acpi_bus_get_device(func
->handle
, &device
)) {
974 dbg("bus exists... trim\n");
975 /* this shouldn't be in here, so remove
976 * the bus then re-add it...
978 ret_val
= acpi_bus_trim(device
, 1);
979 dbg("acpi_bus_trim return %x\n", ret_val
);
982 ret_val
= acpi_bus_add(&device
, pdevice
, func
->handle
,
983 ACPI_BUS_TYPE_DEVICE
);
985 dbg("error adding bus, %x\n",
987 goto acpiphp_bus_add_out
;
990 * try to start anyway. We could have failed to add
991 * simply because this bus had previously been added
992 * on another add. Don't bother with the return value
993 * we just keep going.
995 ret_val
= acpi_bus_start(device
);
1003 * acpiphp_bus_trim - trim a bus from acpi subsystem
1004 * @handle: handle to acpi namespace
1006 static int acpiphp_bus_trim(acpi_handle handle
)
1008 struct acpi_device
*device
;
1011 retval
= acpi_bus_get_device(handle
, &device
);
1013 dbg("acpi_device not found\n");
1017 retval
= acpi_bus_trim(device
, 1);
1019 err("cannot remove from acpi list\n");
1025 * enable_device - enable, configure a slot
1026 * @slot: slot to be enabled
1028 * This function should be called per *physical slot*,
1029 * not per each slot object in ACPI namespace.
1031 static int __ref
enable_device(struct acpiphp_slot
*slot
)
1033 struct pci_dev
*dev
;
1034 struct pci_bus
*bus
= slot
->bridge
->pci_bus
;
1035 struct list_head
*l
;
1036 struct acpiphp_func
*func
;
1041 if (slot
->flags
& SLOT_ENABLED
)
1044 /* sanity check: dev should be NULL when hot-plugged in */
1045 dev
= pci_get_slot(bus
, PCI_DEVFN(slot
->device
, 0));
1047 /* This case shouldn't happen */
1048 err("pci_dev structure already exists.\n");
1054 num
= pci_scan_slot(bus
, PCI_DEVFN(slot
->device
, 0));
1056 err("No new device found\n");
1061 max
= acpiphp_max_busnr(bus
);
1062 for (pass
= 0; pass
< 2; pass
++) {
1063 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1064 if (PCI_SLOT(dev
->devfn
) != slot
->device
)
1066 if (dev
->hdr_type
== PCI_HEADER_TYPE_BRIDGE
||
1067 dev
->hdr_type
== PCI_HEADER_TYPE_CARDBUS
) {
1068 max
= pci_scan_bridge(bus
, dev
, max
, pass
);
1069 if (pass
&& dev
->subordinate
)
1070 pci_bus_size_bridges(dev
->subordinate
);
1075 list_for_each (l
, &slot
->funcs
) {
1076 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1077 acpiphp_bus_add(func
);
1080 pci_bus_assign_resources(bus
);
1081 acpiphp_sanitize_bus(bus
);
1082 acpiphp_set_hpp_values(slot
->bridge
->handle
, bus
);
1083 list_for_each_entry(func
, &slot
->funcs
, sibling
)
1084 acpiphp_configure_ioapics(func
->handle
);
1085 pci_enable_bridges(bus
);
1086 pci_bus_add_devices(bus
);
1088 /* associate pci_dev to our representation */
1089 list_for_each (l
, &slot
->funcs
) {
1090 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1091 func
->pci_dev
= pci_get_slot(bus
, PCI_DEVFN(slot
->device
,
1096 if (func
->pci_dev
->hdr_type
!= PCI_HEADER_TYPE_BRIDGE
&&
1097 func
->pci_dev
->hdr_type
!= PCI_HEADER_TYPE_CARDBUS
)
1100 status
= find_p2p_bridge(func
->handle
, (u32
)1, bus
, NULL
);
1101 if (ACPI_FAILURE(status
))
1102 warn("find_p2p_bridge failed (error code = 0x%x)\n",
1106 slot
->flags
|= SLOT_ENABLED
;
1112 static void disable_bridges(struct pci_bus
*bus
)
1114 struct pci_dev
*dev
;
1115 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1116 if (dev
->subordinate
) {
1117 disable_bridges(dev
->subordinate
);
1118 pci_disable_device(dev
);
1124 * disable_device - disable a slot
1125 * @slot: ACPI PHP slot
1127 static int disable_device(struct acpiphp_slot
*slot
)
1130 struct acpiphp_func
*func
;
1131 struct list_head
*l
;
1133 /* is this slot already disabled? */
1134 if (!(slot
->flags
& SLOT_ENABLED
))
1137 list_for_each (l
, &slot
->funcs
) {
1138 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1141 /* cleanup p2p bridges under this P2P bridge */
1142 cleanup_p2p_bridge(func
->bridge
->handle
,
1143 (u32
)1, NULL
, NULL
);
1144 func
->bridge
= NULL
;
1147 if (func
->pci_dev
) {
1148 pci_stop_bus_device(func
->pci_dev
);
1149 if (func
->pci_dev
->subordinate
) {
1150 disable_bridges(func
->pci_dev
->subordinate
);
1151 pci_disable_device(func
->pci_dev
);
1156 list_for_each (l
, &slot
->funcs
) {
1157 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1159 acpiphp_unconfigure_ioapics(func
->handle
);
1160 acpiphp_bus_trim(func
->handle
);
1161 /* try to remove anyway.
1162 * acpiphp_bus_add might have been failed */
1167 pci_remove_bus_device(func
->pci_dev
);
1168 pci_dev_put(func
->pci_dev
);
1169 func
->pci_dev
= NULL
;
1172 slot
->flags
&= (~SLOT_ENABLED
);
1180 * get_slot_status - get ACPI slot status
1181 * @slot: ACPI PHP slot
1183 * If a slot has _STA for each function and if any one of them
1184 * returned non-zero status, return it.
1186 * If a slot doesn't have _STA and if any one of its functions'
1187 * configuration space is configured, return 0x0f as a _STA.
1189 * Otherwise return 0.
1191 static unsigned int get_slot_status(struct acpiphp_slot
*slot
)
1194 unsigned long long sta
= 0;
1196 struct list_head
*l
;
1197 struct acpiphp_func
*func
;
1199 list_for_each (l
, &slot
->funcs
) {
1200 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1202 if (func
->flags
& FUNC_HAS_STA
) {
1203 status
= acpi_evaluate_integer(func
->handle
, "_STA", NULL
, &sta
);
1204 if (ACPI_SUCCESS(status
) && sta
)
1207 pci_bus_read_config_dword(slot
->bridge
->pci_bus
,
1208 PCI_DEVFN(slot
->device
,
1210 PCI_VENDOR_ID
, &dvid
);
1211 if (dvid
!= 0xffffffff) {
1218 return (unsigned int)sta
;
1222 * acpiphp_eject_slot - physically eject the slot
1223 * @slot: ACPI PHP slot
1225 int acpiphp_eject_slot(struct acpiphp_slot
*slot
)
1228 struct acpiphp_func
*func
;
1229 struct list_head
*l
;
1230 struct acpi_object_list arg_list
;
1231 union acpi_object arg
;
1233 list_for_each (l
, &slot
->funcs
) {
1234 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1236 /* We don't want to call _EJ0 on non-existing functions. */
1237 if ((func
->flags
& FUNC_HAS_EJ0
)) {
1238 /* _EJ0 method take one argument */
1240 arg_list
.pointer
= &arg
;
1241 arg
.type
= ACPI_TYPE_INTEGER
;
1242 arg
.integer
.value
= 1;
1244 status
= acpi_evaluate_object(func
->handle
, "_EJ0", &arg_list
, NULL
);
1245 if (ACPI_FAILURE(status
)) {
1246 warn("%s: _EJ0 failed\n", __func__
);
1256 * acpiphp_check_bridge - re-enumerate devices
1257 * @bridge: where to begin re-enumeration
1259 * Iterate over all slots under this bridge and make sure that if a
1260 * card is present they are enabled, and if not they are disabled.
1262 static int acpiphp_check_bridge(struct acpiphp_bridge
*bridge
)
1264 struct acpiphp_slot
*slot
;
1266 int enabled
, disabled
;
1268 enabled
= disabled
= 0;
1270 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
1271 unsigned int status
= get_slot_status(slot
);
1272 if (slot
->flags
& SLOT_ENABLED
) {
1273 if (status
== ACPI_STA_ALL
)
1275 retval
= acpiphp_disable_slot(slot
);
1277 err("Error occurred in disabling\n");
1280 acpiphp_eject_slot(slot
);
1284 if (status
!= ACPI_STA_ALL
)
1286 retval
= acpiphp_enable_slot(slot
);
1288 err("Error occurred in enabling\n");
1295 dbg("%s: %d enabled, %d disabled\n", __func__
, enabled
, disabled
);
1301 static void program_hpp(struct pci_dev
*dev
, struct acpiphp_bridge
*bridge
)
1303 u16 pci_cmd
, pci_bctl
;
1304 struct pci_dev
*cdev
;
1306 /* Program hpp values for this device */
1307 if (!(dev
->hdr_type
== PCI_HEADER_TYPE_NORMAL
||
1308 (dev
->hdr_type
== PCI_HEADER_TYPE_BRIDGE
&&
1309 (dev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
)))
1312 if ((dev
->class >> 8) == PCI_CLASS_BRIDGE_HOST
)
1315 pci_write_config_byte(dev
, PCI_CACHE_LINE_SIZE
,
1316 bridge
->hpp
.t0
->cache_line_size
);
1317 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
,
1318 bridge
->hpp
.t0
->latency_timer
);
1319 pci_read_config_word(dev
, PCI_COMMAND
, &pci_cmd
);
1320 if (bridge
->hpp
.t0
->enable_serr
)
1321 pci_cmd
|= PCI_COMMAND_SERR
;
1323 pci_cmd
&= ~PCI_COMMAND_SERR
;
1324 if (bridge
->hpp
.t0
->enable_perr
)
1325 pci_cmd
|= PCI_COMMAND_PARITY
;
1327 pci_cmd
&= ~PCI_COMMAND_PARITY
;
1328 pci_write_config_word(dev
, PCI_COMMAND
, pci_cmd
);
1330 /* Program bridge control value and child devices */
1331 if ((dev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
) {
1332 pci_write_config_byte(dev
, PCI_SEC_LATENCY_TIMER
,
1333 bridge
->hpp
.t0
->latency_timer
);
1334 pci_read_config_word(dev
, PCI_BRIDGE_CONTROL
, &pci_bctl
);
1335 if (bridge
->hpp
.t0
->enable_serr
)
1336 pci_bctl
|= PCI_BRIDGE_CTL_SERR
;
1338 pci_bctl
&= ~PCI_BRIDGE_CTL_SERR
;
1339 if (bridge
->hpp
.t0
->enable_perr
)
1340 pci_bctl
|= PCI_BRIDGE_CTL_PARITY
;
1342 pci_bctl
&= ~PCI_BRIDGE_CTL_PARITY
;
1343 pci_write_config_word(dev
, PCI_BRIDGE_CONTROL
, pci_bctl
);
1344 if (dev
->subordinate
) {
1345 list_for_each_entry(cdev
, &dev
->subordinate
->devices
,
1347 program_hpp(cdev
, bridge
);
1352 static void acpiphp_set_hpp_values(acpi_handle handle
, struct pci_bus
*bus
)
1354 struct acpiphp_bridge bridge
;
1355 struct pci_dev
*dev
;
1357 memset(&bridge
, 0, sizeof(bridge
));
1358 bridge
.handle
= handle
;
1359 bridge
.pci_bus
= bus
;
1360 bridge
.pci_dev
= bus
->self
;
1361 decode_hpp(&bridge
);
1362 list_for_each_entry(dev
, &bus
->devices
, bus_list
)
1363 program_hpp(dev
, &bridge
);
1368 * Remove devices for which we could not assign resources, call
1369 * arch specific code to fix-up the bus
1371 static void acpiphp_sanitize_bus(struct pci_bus
*bus
)
1373 struct pci_dev
*dev
;
1375 unsigned long type_mask
= IORESOURCE_IO
| IORESOURCE_MEM
;
1377 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1378 for (i
=0; i
<PCI_BRIDGE_RESOURCES
; i
++) {
1379 struct resource
*res
= &dev
->resource
[i
];
1380 if ((res
->flags
& type_mask
) && !res
->start
&&
1382 /* Could not assign a required resources
1383 * for this device, remove it */
1384 pci_remove_bus_device(dev
);
1391 /* Program resources in newly inserted bridge */
1392 static int acpiphp_configure_bridge (acpi_handle handle
)
1394 struct acpi_pci_id pci_id
;
1395 struct pci_bus
*bus
;
1397 if (ACPI_FAILURE(acpi_get_pci_id(handle
, &pci_id
))) {
1398 err("cannot get PCI domain and bus number for bridge\n");
1401 bus
= pci_find_bus(pci_id
.segment
, pci_id
.bus
);
1403 err("cannot find bus %d:%d\n",
1404 pci_id
.segment
, pci_id
.bus
);
1408 pci_bus_size_bridges(bus
);
1409 pci_bus_assign_resources(bus
);
1410 acpiphp_sanitize_bus(bus
);
1411 acpiphp_set_hpp_values(handle
, bus
);
1412 pci_enable_bridges(bus
);
1413 acpiphp_configure_ioapics(handle
);
1417 static void handle_bridge_insertion(acpi_handle handle
, u32 type
)
1419 struct acpi_device
*device
, *pdevice
;
1420 acpi_handle phandle
;
1422 if ((type
!= ACPI_NOTIFY_BUS_CHECK
) &&
1423 (type
!= ACPI_NOTIFY_DEVICE_CHECK
)) {
1424 err("unexpected notification type %d\n", type
);
1428 acpi_get_parent(handle
, &phandle
);
1429 if (acpi_bus_get_device(phandle
, &pdevice
)) {
1430 dbg("no parent device, assuming NULL\n");
1433 if (acpi_bus_add(&device
, pdevice
, handle
, ACPI_BUS_TYPE_DEVICE
)) {
1434 err("cannot add bridge to acpi list\n");
1437 if (!acpiphp_configure_bridge(handle
) &&
1438 !acpi_bus_start(device
))
1441 err("cannot configure and start bridge\n");
1446 * ACPI event handlers
1450 count_sub_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1452 int *count
= (int *)context
;
1453 struct acpiphp_bridge
*bridge
;
1455 bridge
= acpiphp_handle_to_bridge(handle
);
1462 check_sub_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1464 struct acpiphp_bridge
*bridge
;
1466 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1467 .pointer
= objname
};
1469 bridge
= acpiphp_handle_to_bridge(handle
);
1471 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1472 dbg("%s: re-enumerating slots under %s\n",
1474 acpiphp_check_bridge(bridge
);
1480 * handle_hotplug_event_bridge - handle ACPI event on bridges
1481 * @handle: Notify()'ed acpi_handle
1482 * @type: Notify code
1483 * @context: pointer to acpiphp_bridge structure
1485 * Handles ACPI event notification on {host,p2p} bridges.
1487 static void handle_hotplug_event_bridge(acpi_handle handle
, u32 type
, void *context
)
1489 struct acpiphp_bridge
*bridge
;
1491 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1492 .pointer
= objname
};
1493 struct acpi_device
*device
;
1494 int num_sub_bridges
= 0;
1496 if (acpi_bus_get_device(handle
, &device
)) {
1497 /* This bridge must have just been physically inserted */
1498 handle_bridge_insertion(handle
, type
);
1502 bridge
= acpiphp_handle_to_bridge(handle
);
1503 if (type
== ACPI_NOTIFY_BUS_CHECK
) {
1504 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, ACPI_UINT32_MAX
,
1505 count_sub_bridges
, &num_sub_bridges
, NULL
);
1508 if (!bridge
&& !num_sub_bridges
) {
1509 err("cannot get bridge info\n");
1513 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1516 case ACPI_NOTIFY_BUS_CHECK
:
1517 /* bus re-enumerate */
1518 dbg("%s: Bus check notify on %s\n", __func__
, objname
);
1520 dbg("%s: re-enumerating slots under %s\n",
1522 acpiphp_check_bridge(bridge
);
1524 if (num_sub_bridges
)
1525 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
1526 ACPI_UINT32_MAX
, check_sub_bridges
, NULL
, NULL
);
1529 case ACPI_NOTIFY_DEVICE_CHECK
:
1531 dbg("%s: Device check notify on %s\n", __func__
, objname
);
1532 acpiphp_check_bridge(bridge
);
1535 case ACPI_NOTIFY_DEVICE_WAKE
:
1537 dbg("%s: Device wake notify on %s\n", __func__
, objname
);
1540 case ACPI_NOTIFY_EJECT_REQUEST
:
1541 /* request device eject */
1542 dbg("%s: Device eject notify on %s\n", __func__
, objname
);
1543 if ((bridge
->type
!= BRIDGE_TYPE_HOST
) &&
1544 (bridge
->flags
& BRIDGE_HAS_EJ0
)) {
1545 struct acpiphp_slot
*slot
;
1546 slot
= bridge
->func
->slot
;
1547 if (!acpiphp_disable_slot(slot
))
1548 acpiphp_eject_slot(slot
);
1552 case ACPI_NOTIFY_FREQUENCY_MISMATCH
:
1553 printk(KERN_ERR
"Device %s cannot be configured due"
1554 " to a frequency mismatch\n", objname
);
1557 case ACPI_NOTIFY_BUS_MODE_MISMATCH
:
1558 printk(KERN_ERR
"Device %s cannot be configured due"
1559 " to a bus mode mismatch\n", objname
);
1562 case ACPI_NOTIFY_POWER_FAULT
:
1563 printk(KERN_ERR
"Device %s has suffered a power fault\n",
1568 warn("notify_handler: unknown event type 0x%x for %s\n", type
, objname
);
1574 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
1575 * @handle: Notify()'ed acpi_handle
1576 * @type: Notify code
1577 * @context: pointer to acpiphp_func structure
1579 * Handles ACPI event notification on slots.
1581 static void handle_hotplug_event_func(acpi_handle handle
, u32 type
, void *context
)
1583 struct acpiphp_func
*func
;
1585 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1586 .pointer
= objname
};
1588 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1590 func
= (struct acpiphp_func
*)context
;
1593 case ACPI_NOTIFY_BUS_CHECK
:
1594 /* bus re-enumerate */
1595 dbg("%s: Bus check notify on %s\n", __func__
, objname
);
1596 acpiphp_enable_slot(func
->slot
);
1599 case ACPI_NOTIFY_DEVICE_CHECK
:
1600 /* device check : re-enumerate from parent bus */
1601 dbg("%s: Device check notify on %s\n", __func__
, objname
);
1602 acpiphp_check_bridge(func
->slot
->bridge
);
1605 case ACPI_NOTIFY_DEVICE_WAKE
:
1607 dbg("%s: Device wake notify on %s\n", __func__
, objname
);
1610 case ACPI_NOTIFY_EJECT_REQUEST
:
1611 /* request device eject */
1612 dbg("%s: Device eject notify on %s\n", __func__
, objname
);
1613 if (!(acpiphp_disable_slot(func
->slot
)))
1614 acpiphp_eject_slot(func
->slot
);
1618 warn("notify_handler: unknown event type 0x%x for %s\n", type
, objname
);
1625 find_root_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1627 int *count
= (int *)context
;
1629 if (acpi_root_bridge(handle
)) {
1630 acpi_install_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
1631 handle_hotplug_event_bridge
, NULL
);
1637 static struct acpi_pci_driver acpi_pci_hp_driver
= {
1639 .remove
= remove_bridge
,
1643 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
1645 int __init
acpiphp_glue_init(void)
1649 acpi_walk_namespace(ACPI_TYPE_DEVICE
, ACPI_ROOT_OBJECT
,
1650 ACPI_UINT32_MAX
, find_root_bridges
, &num
, NULL
);
1655 acpi_pci_register_driver(&acpi_pci_hp_driver
);
1662 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures
1664 * This function frees all data allocated in acpiphp_glue_init().
1666 void acpiphp_glue_exit(void)
1668 acpi_pci_unregister_driver(&acpi_pci_hp_driver
);
1673 * acpiphp_get_num_slots - count number of slots in a system
1675 int __init
acpiphp_get_num_slots(void)
1677 struct acpiphp_bridge
*bridge
;
1680 list_for_each_entry (bridge
, &bridge_list
, list
) {
1681 dbg("Bus %04x:%02x has %d slot%s\n",
1682 pci_domain_nr(bridge
->pci_bus
),
1683 bridge
->pci_bus
->number
, bridge
->nr_slots
,
1684 bridge
->nr_slots
== 1 ? "" : "s");
1685 num_slots
+= bridge
->nr_slots
;
1688 dbg("Total %d slots\n", num_slots
);
1695 * acpiphp_for_each_slot - call function for each slot
1696 * @fn: callback function
1697 * @data: context to be passed to callback function
1699 static int acpiphp_for_each_slot(acpiphp_callback fn
, void *data
)
1701 struct list_head
*node
;
1702 struct acpiphp_bridge
*bridge
;
1703 struct acpiphp_slot
*slot
;
1706 list_for_each (node
, &bridge_list
) {
1707 bridge
= (struct acpiphp_bridge
*)node
;
1708 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
1709 retval
= fn(slot
, data
);
1722 * acpiphp_enable_slot - power on slot
1723 * @slot: ACPI PHP slot
1725 int acpiphp_enable_slot(struct acpiphp_slot
*slot
)
1729 mutex_lock(&slot
->crit_sect
);
1731 /* wake up all functions */
1732 retval
= power_on_slot(slot
);
1736 if (get_slot_status(slot
) == ACPI_STA_ALL
) {
1737 /* configure all functions */
1738 retval
= enable_device(slot
);
1740 power_off_slot(slot
);
1742 dbg("%s: Slot status is not ACPI_STA_ALL\n", __func__
);
1743 power_off_slot(slot
);
1747 mutex_unlock(&slot
->crit_sect
);
1752 * acpiphp_disable_slot - power off slot
1753 * @slot: ACPI PHP slot
1755 int acpiphp_disable_slot(struct acpiphp_slot
*slot
)
1759 mutex_lock(&slot
->crit_sect
);
1761 /* unconfigure all functions */
1762 retval
= disable_device(slot
);
1766 /* power off all functions */
1767 retval
= power_off_slot(slot
);
1772 mutex_unlock(&slot
->crit_sect
);
1781 u8
acpiphp_get_power_status(struct acpiphp_slot
*slot
)
1783 return (slot
->flags
& SLOT_POWEREDON
);
1791 u8
acpiphp_get_latch_status(struct acpiphp_slot
*slot
)
1795 sta
= get_slot_status(slot
);
1797 return (sta
& ACPI_STA_SHOW_IN_UI
) ? 0 : 1;
1802 * adapter presence : 1
1805 u8
acpiphp_get_adapter_status(struct acpiphp_slot
*slot
)
1809 sta
= get_slot_status(slot
);
1811 return (sta
== 0) ? 0 : 1;