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
41 * - When a P2P bridge is present, we elevate the refcount on the subordinate
42 * bus. It loses the refcount when the the driver unloads.
45 #include <linux/init.h>
46 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/pci.h>
50 #include <linux/pci_hotplug.h>
51 #include <linux/pci-acpi.h>
52 #include <linux/mutex.h>
57 static LIST_HEAD(bridge_list
);
58 static LIST_HEAD(ioapic_list
);
59 static DEFINE_SPINLOCK(ioapic_list_lock
);
61 #define MY_NAME "acpiphp_glue"
63 static void handle_hotplug_event_bridge (acpi_handle
, u32
, void *);
64 static void acpiphp_sanitize_bus(struct pci_bus
*bus
);
65 static void acpiphp_set_hpp_values(acpi_handle handle
, struct pci_bus
*bus
);
66 static void handle_hotplug_event_func(acpi_handle handle
, u32 type
, void *context
);
68 /* callback routine to check for the existence of a pci dock device */
70 is_pci_dock_device(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
72 int *count
= (int *)context
;
74 if (is_dock_device(handle
)) {
76 return AE_CTRL_TERMINATE
;
83 * the _DCK method can do funny things... and sometimes not
86 * TBD - figure out a way to only call fixups for
87 * systems that require them.
89 static int post_dock_fixups(struct notifier_block
*nb
, unsigned long val
,
92 struct acpiphp_func
*func
= container_of(nb
, struct acpiphp_func
, nb
);
93 struct pci_bus
*bus
= func
->slot
->bridge
->pci_bus
;
99 /* fixup bad _DCK function that rewrites
100 * secondary bridge on slot
102 pci_read_config_dword(bus
->self
,
106 if (((buses
>> 8) & 0xff) != bus
->secondary
) {
107 buses
= (buses
& 0xff000000)
108 | ((unsigned int)(bus
->primary
) << 0)
109 | ((unsigned int)(bus
->secondary
) << 8)
110 | ((unsigned int)(bus
->subordinate
) << 16);
111 pci_write_config_dword(bus
->self
, PCI_PRIMARY_BUS
, buses
);
117 static struct acpi_dock_ops acpiphp_dock_ops
= {
118 .handler
= handle_hotplug_event_func
,
121 /* callback routine to register each ACPI PCI slot object */
123 register_slot(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
125 struct acpiphp_bridge
*bridge
= (struct acpiphp_bridge
*)context
;
126 struct acpiphp_slot
*slot
;
127 struct acpiphp_func
*newfunc
;
129 acpi_status status
= AE_OK
;
130 unsigned long long adr
, sun
;
131 int device
, function
, retval
;
132 struct pci_bus
*pbus
= bridge
->pci_bus
;
134 if (!acpi_pci_check_ejectable(pbus
, handle
) && !is_dock_device(handle
))
137 acpi_evaluate_integer(handle
, "_ADR", NULL
, &adr
);
138 device
= (adr
>> 16) & 0xffff;
139 function
= adr
& 0xffff;
141 newfunc
= kzalloc(sizeof(struct acpiphp_func
), GFP_KERNEL
);
145 INIT_LIST_HEAD(&newfunc
->sibling
);
146 newfunc
->handle
= handle
;
147 newfunc
->function
= function
;
149 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_EJ0", &tmp
)))
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 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_DCK", &tmp
)))
162 newfunc
->flags
|= FUNC_HAS_DCK
;
164 status
= acpi_evaluate_integer(handle
, "_SUN", NULL
, &sun
);
165 if (ACPI_FAILURE(status
)) {
167 * use the count of the number of slots we've found
168 * for the number of the slot
170 sun
= bridge
->nr_slots
+1;
173 /* search for objects that share the same slot */
174 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
)
175 if (slot
->device
== device
) {
176 if (slot
->sun
!= sun
)
177 warn("sibling found, but _SUN doesn't match!\n");
182 slot
= kzalloc(sizeof(struct acpiphp_slot
), GFP_KERNEL
);
188 slot
->bridge
= bridge
;
189 slot
->device
= device
;
191 INIT_LIST_HEAD(&slot
->funcs
);
192 mutex_init(&slot
->crit_sect
);
194 slot
->next
= bridge
->slots
;
195 bridge
->slots
= slot
;
199 dbg("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
200 slot
->sun
, pci_domain_nr(pbus
), pbus
->number
, device
);
201 retval
= acpiphp_register_hotplug_slot(slot
);
203 if (retval
== -EBUSY
)
204 warn("Slot %llu already registered by another "
205 "hotplug driver\n", slot
->sun
);
207 warn("acpiphp_register_hotplug_slot failed "
208 "(err code = 0x%x)\n", retval
);
213 newfunc
->slot
= slot
;
214 list_add_tail(&newfunc
->sibling
, &slot
->funcs
);
216 /* associate corresponding pci_dev */
217 newfunc
->pci_dev
= pci_get_slot(pbus
, PCI_DEVFN(device
, function
));
218 if (newfunc
->pci_dev
) {
219 slot
->flags
|= (SLOT_ENABLED
| SLOT_POWEREDON
);
222 if (is_dock_device(handle
)) {
223 /* we don't want to call this device's _EJ0
224 * because we want the dock notify handler
225 * to call it after it calls _DCK
227 newfunc
->flags
&= ~FUNC_HAS_EJ0
;
228 if (register_hotplug_dock_device(handle
,
229 &acpiphp_dock_ops
, newfunc
))
230 dbg("failed to register dock device\n");
232 /* we need to be notified when dock events happen
233 * outside of the hotplug operation, since we may
234 * need to do fixups before we can hotplug.
236 newfunc
->nb
.notifier_call
= post_dock_fixups
;
237 if (register_dock_notifier(&newfunc
->nb
))
238 dbg("failed to register a dock notifier");
241 /* install notify handler */
242 if (!(newfunc
->flags
& FUNC_HAS_DCK
)) {
243 status
= acpi_install_notify_handler(handle
,
245 handle_hotplug_event_func
,
248 if (ACPI_FAILURE(status
))
249 err("failed to register interrupt notify handler\n");
257 bridge
->slots
= slot
->next
;
265 /* see if it's worth looking at this bridge */
266 static int detect_ejectable_slots(struct pci_bus
*pbus
)
268 int found
= acpi_pci_detect_ejectable(pbus
);
270 acpi_handle bridge_handle
= acpi_pci_get_bridge_handle(pbus
);
273 acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge_handle
, (u32
)1,
274 is_pci_dock_device
, (void *)&found
, NULL
);
280 /* decode ACPI 2.0 _HPP hot plug parameters */
281 static void decode_hpp(struct acpiphp_bridge
*bridge
)
285 status
= acpi_get_hp_params_from_firmware(bridge
->pci_bus
, &bridge
->hpp
);
286 if (ACPI_FAILURE(status
) ||
287 !bridge
->hpp
.t0
|| (bridge
->hpp
.t0
->revision
> 1)) {
288 /* use default numbers */
290 "%s: Could not get hotplug parameters. Use defaults\n",
292 bridge
->hpp
.t0
= &bridge
->hpp
.type0_data
;
293 bridge
->hpp
.t0
->revision
= 0;
294 bridge
->hpp
.t0
->cache_line_size
= 0x10;
295 bridge
->hpp
.t0
->latency_timer
= 0x40;
296 bridge
->hpp
.t0
->enable_serr
= 0;
297 bridge
->hpp
.t0
->enable_perr
= 0;
303 /* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */
304 static void init_bridge_misc(struct acpiphp_bridge
*bridge
)
308 /* decode ACPI 2.0 _HPP (hot plug parameters) */
311 /* must be added to the list prior to calling register_slot */
312 list_add(&bridge
->list
, &bridge_list
);
314 /* register all slot objects under this bridge */
315 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge
->handle
, (u32
)1,
316 register_slot
, bridge
, NULL
);
317 if (ACPI_FAILURE(status
)) {
318 list_del(&bridge
->list
);
322 /* install notify handler */
323 if (bridge
->type
!= BRIDGE_TYPE_HOST
) {
324 if ((bridge
->flags
& BRIDGE_HAS_EJ0
) && bridge
->func
) {
325 status
= acpi_remove_notify_handler(bridge
->func
->handle
,
327 handle_hotplug_event_func
);
328 if (ACPI_FAILURE(status
))
329 err("failed to remove notify handler\n");
331 status
= acpi_install_notify_handler(bridge
->handle
,
333 handle_hotplug_event_bridge
,
336 if (ACPI_FAILURE(status
)) {
337 err("failed to register interrupt notify handler\n");
343 /* find acpiphp_func from acpiphp_bridge */
344 static struct acpiphp_func
*acpiphp_bridge_handle_to_function(acpi_handle handle
)
346 struct list_head
*node
, *l
;
347 struct acpiphp_bridge
*bridge
;
348 struct acpiphp_slot
*slot
;
349 struct acpiphp_func
*func
;
351 list_for_each(node
, &bridge_list
) {
352 bridge
= list_entry(node
, struct acpiphp_bridge
, list
);
353 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
354 list_for_each(l
, &slot
->funcs
) {
355 func
= list_entry(l
, struct acpiphp_func
,
357 if (func
->handle
== handle
)
367 static inline void config_p2p_bridge_flags(struct acpiphp_bridge
*bridge
)
369 acpi_handle dummy_handle
;
371 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
372 "_STA", &dummy_handle
)))
373 bridge
->flags
|= BRIDGE_HAS_STA
;
375 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
376 "_EJ0", &dummy_handle
)))
377 bridge
->flags
|= BRIDGE_HAS_EJ0
;
379 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
380 "_PS0", &dummy_handle
)))
381 bridge
->flags
|= BRIDGE_HAS_PS0
;
383 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
384 "_PS3", &dummy_handle
)))
385 bridge
->flags
|= BRIDGE_HAS_PS3
;
387 /* is this ejectable p2p bridge? */
388 if (bridge
->flags
& BRIDGE_HAS_EJ0
) {
389 struct acpiphp_func
*func
;
391 dbg("found ejectable p2p bridge\n");
393 /* make link between PCI bridge and PCI function */
394 func
= acpiphp_bridge_handle_to_function(bridge
->handle
);
398 func
->bridge
= bridge
;
403 /* allocate and initialize host bridge data structure */
404 static void add_host_bridge(acpi_handle
*handle
, struct pci_bus
*pci_bus
)
406 struct acpiphp_bridge
*bridge
;
408 bridge
= kzalloc(sizeof(struct acpiphp_bridge
), GFP_KERNEL
);
412 bridge
->type
= BRIDGE_TYPE_HOST
;
413 bridge
->handle
= handle
;
415 bridge
->pci_bus
= pci_bus
;
417 spin_lock_init(&bridge
->res_lock
);
419 init_bridge_misc(bridge
);
423 /* allocate and initialize PCI-to-PCI bridge data structure */
424 static void add_p2p_bridge(acpi_handle
*handle
, struct pci_dev
*pci_dev
)
426 struct acpiphp_bridge
*bridge
;
428 bridge
= kzalloc(sizeof(struct acpiphp_bridge
), GFP_KERNEL
);
429 if (bridge
== NULL
) {
430 err("out of memory\n");
434 bridge
->type
= BRIDGE_TYPE_P2P
;
435 bridge
->handle
= handle
;
436 config_p2p_bridge_flags(bridge
);
438 bridge
->pci_dev
= pci_dev_get(pci_dev
);
439 bridge
->pci_bus
= pci_dev
->subordinate
;
440 if (!bridge
->pci_bus
) {
441 err("This is not a PCI-to-PCI bridge!\n");
446 * Grab a ref to the subordinate PCI bus in case the bus is
447 * removed via PCI core logical hotplug. The ref pins the bus
448 * (which we access during module unload).
450 get_device(&bridge
->pci_bus
->dev
);
451 spin_lock_init(&bridge
->res_lock
);
453 init_bridge_misc(bridge
);
456 pci_dev_put(pci_dev
);
462 /* callback routine to find P2P bridges */
464 find_p2p_bridge(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
467 acpi_handle dummy_handle
;
468 unsigned long long tmp
;
469 int device
, function
;
471 struct pci_bus
*pci_bus
= context
;
473 status
= acpi_get_handle(handle
, "_ADR", &dummy_handle
);
474 if (ACPI_FAILURE(status
))
475 return AE_OK
; /* continue */
477 status
= acpi_evaluate_integer(handle
, "_ADR", NULL
, &tmp
);
478 if (ACPI_FAILURE(status
)) {
479 dbg("%s: _ADR evaluation failure\n", __func__
);
483 device
= (tmp
>> 16) & 0xffff;
484 function
= tmp
& 0xffff;
486 dev
= pci_get_slot(pci_bus
, PCI_DEVFN(device
, function
));
488 if (!dev
|| !dev
->subordinate
)
491 /* check if this bridge has ejectable slots */
492 if ((detect_ejectable_slots(dev
->subordinate
) > 0)) {
493 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev
));
494 add_p2p_bridge(handle
, dev
);
497 /* search P2P bridges under this p2p bridge */
498 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
499 find_p2p_bridge
, dev
->subordinate
, NULL
);
500 if (ACPI_FAILURE(status
))
501 warn("find_p2p_bridge failed (error code = 0x%x)\n", status
);
509 /* find hot-pluggable slots, and then find P2P bridge */
510 static int add_bridge(acpi_handle handle
)
513 unsigned long long tmp
;
515 acpi_handle dummy_handle
;
516 struct pci_bus
*pci_bus
;
518 /* if the bridge doesn't have _STA, we assume it is always there */
519 status
= acpi_get_handle(handle
, "_STA", &dummy_handle
);
520 if (ACPI_SUCCESS(status
)) {
521 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &tmp
);
522 if (ACPI_FAILURE(status
)) {
523 dbg("%s: _STA evaluation failure\n", __func__
);
526 if ((tmp
& ACPI_STA_FUNCTIONING
) == 0)
527 /* don't register this object */
531 /* get PCI segment number */
532 status
= acpi_evaluate_integer(handle
, "_SEG", NULL
, &tmp
);
534 seg
= ACPI_SUCCESS(status
) ? tmp
: 0;
536 /* get PCI bus number */
537 status
= acpi_evaluate_integer(handle
, "_BBN", NULL
, &tmp
);
539 if (ACPI_SUCCESS(status
)) {
542 warn("can't get bus number, assuming 0\n");
546 pci_bus
= pci_find_bus(seg
, bus
);
548 err("Can't find bus %04x:%02x\n", seg
, bus
);
552 /* check if this bridge has ejectable slots */
553 if (detect_ejectable_slots(pci_bus
) > 0) {
554 dbg("found PCI host-bus bridge with hot-pluggable slots\n");
555 add_host_bridge(handle
, pci_bus
);
558 /* search P2P bridges under this host bridge */
559 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
560 find_p2p_bridge
, pci_bus
, NULL
);
562 if (ACPI_FAILURE(status
))
563 warn("find_p2p_bridge failed (error code = 0x%x)\n", status
);
568 static struct acpiphp_bridge
*acpiphp_handle_to_bridge(acpi_handle handle
)
570 struct list_head
*head
;
571 list_for_each(head
, &bridge_list
) {
572 struct acpiphp_bridge
*bridge
= list_entry(head
,
573 struct acpiphp_bridge
, list
);
574 if (bridge
->handle
== handle
)
581 static void cleanup_bridge(struct acpiphp_bridge
*bridge
)
583 struct list_head
*list
, *tmp
;
584 struct acpiphp_slot
*slot
;
586 acpi_handle handle
= bridge
->handle
;
588 status
= acpi_remove_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
589 handle_hotplug_event_bridge
);
590 if (ACPI_FAILURE(status
))
591 err("failed to remove notify handler\n");
593 if ((bridge
->type
!= BRIDGE_TYPE_HOST
) &&
594 ((bridge
->flags
& BRIDGE_HAS_EJ0
) && bridge
->func
)) {
595 status
= acpi_install_notify_handler(bridge
->func
->handle
,
597 handle_hotplug_event_func
,
599 if (ACPI_FAILURE(status
))
600 err("failed to install interrupt notify handler\n");
603 slot
= bridge
->slots
;
605 struct acpiphp_slot
*next
= slot
->next
;
606 list_for_each_safe (list
, tmp
, &slot
->funcs
) {
607 struct acpiphp_func
*func
;
608 func
= list_entry(list
, struct acpiphp_func
, sibling
);
609 if (is_dock_device(func
->handle
)) {
610 unregister_hotplug_dock_device(func
->handle
);
611 unregister_dock_notifier(&func
->nb
);
613 if (!(func
->flags
& FUNC_HAS_DCK
)) {
614 status
= acpi_remove_notify_handler(func
->handle
,
616 handle_hotplug_event_func
);
617 if (ACPI_FAILURE(status
))
618 err("failed to remove notify handler\n");
620 pci_dev_put(func
->pci_dev
);
624 acpiphp_unregister_hotplug_slot(slot
);
625 list_del(&slot
->funcs
);
631 * Only P2P bridges have a pci_dev
634 put_device(&bridge
->pci_bus
->dev
);
636 pci_dev_put(bridge
->pci_dev
);
637 list_del(&bridge
->list
);
642 cleanup_p2p_bridge(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
644 struct acpiphp_bridge
*bridge
;
646 /* cleanup p2p bridges under this P2P bridge
647 in a depth-first manner */
648 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
649 cleanup_p2p_bridge
, NULL
, NULL
);
651 bridge
= acpiphp_handle_to_bridge(handle
);
653 cleanup_bridge(bridge
);
658 static void remove_bridge(acpi_handle handle
)
660 struct acpiphp_bridge
*bridge
;
662 /* cleanup p2p bridges under this host bridge
663 in a depth-first manner */
664 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
665 (u32
)1, cleanup_p2p_bridge
, NULL
, NULL
);
668 * On root bridges with hotplug slots directly underneath (ie,
669 * no p2p bridge inbetween), we call cleanup_bridge().
671 * The else clause cleans up root bridges that either had no
672 * hotplug slots at all, or had a p2p bridge underneath.
674 bridge
= acpiphp_handle_to_bridge(handle
);
676 cleanup_bridge(bridge
);
678 acpi_remove_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
679 handle_hotplug_event_bridge
);
682 static struct pci_dev
* get_apic_pci_info(acpi_handle handle
)
684 struct acpi_pci_id id
;
688 if (ACPI_FAILURE(acpi_get_pci_id(handle
, &id
)))
691 bus
= pci_find_bus(id
.segment
, id
.bus
);
695 dev
= pci_get_slot(bus
, PCI_DEVFN(id
.device
, id
.function
));
699 if ((dev
->class != PCI_CLASS_SYSTEM_PIC_IOAPIC
) &&
700 (dev
->class != PCI_CLASS_SYSTEM_PIC_IOXAPIC
))
709 static int get_gsi_base(acpi_handle handle
, u32
*gsi_base
)
713 unsigned long long gsb
;
714 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
715 union acpi_object
*obj
;
718 status
= acpi_evaluate_integer(handle
, "_GSB", NULL
, &gsb
);
719 if (ACPI_SUCCESS(status
)) {
720 *gsi_base
= (u32
)gsb
;
724 status
= acpi_evaluate_object(handle
, "_MAT", NULL
, &buffer
);
725 if (ACPI_FAILURE(status
) || !buffer
.length
|| !buffer
.pointer
)
728 obj
= buffer
.pointer
;
729 if (obj
->type
!= ACPI_TYPE_BUFFER
)
732 table
= obj
->buffer
.pointer
;
733 switch (((struct acpi_subtable_header
*)table
)->type
) {
734 case ACPI_MADT_TYPE_IO_SAPIC
:
735 *gsi_base
= ((struct acpi_madt_io_sapic
*)table
)->global_irq_base
;
738 case ACPI_MADT_TYPE_IO_APIC
:
739 *gsi_base
= ((struct acpi_madt_io_apic
*)table
)->global_irq_base
;
746 kfree(buffer
.pointer
);
751 ioapic_add(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
754 unsigned long long sta
;
756 struct pci_dev
*pdev
;
759 struct acpiphp_ioapic
*ioapic
;
761 /* Evaluate _STA if present */
762 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &sta
);
763 if (ACPI_SUCCESS(status
) && sta
!= ACPI_STA_ALL
)
764 return AE_CTRL_DEPTH
;
766 /* Scan only PCI bus scope */
767 status
= acpi_get_handle(handle
, "_HID", &tmp
);
768 if (ACPI_SUCCESS(status
))
769 return AE_CTRL_DEPTH
;
771 if (get_gsi_base(handle
, &gsi_base
))
774 ioapic
= kmalloc(sizeof(*ioapic
), GFP_KERNEL
);
778 pdev
= get_apic_pci_info(handle
);
782 if (pci_enable_device(pdev
))
783 goto exit_pci_dev_put
;
785 pci_set_master(pdev
);
787 if (pci_request_region(pdev
, 0, "I/O APIC(acpiphp)"))
788 goto exit_pci_disable_device
;
790 phys_addr
= pci_resource_start(pdev
, 0);
791 if (acpi_register_ioapic(handle
, phys_addr
, gsi_base
))
792 goto exit_pci_release_region
;
794 ioapic
->gsi_base
= gsi_base
;
796 spin_lock(&ioapic_list_lock
);
797 list_add_tail(&ioapic
->list
, &ioapic_list
);
798 spin_unlock(&ioapic_list_lock
);
802 exit_pci_release_region
:
803 pci_release_region(pdev
, 0);
804 exit_pci_disable_device
:
805 pci_disable_device(pdev
);
815 ioapic_remove(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
818 unsigned long long sta
;
821 struct acpiphp_ioapic
*pos
, *n
, *ioapic
= NULL
;
823 /* Evaluate _STA if present */
824 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &sta
);
825 if (ACPI_SUCCESS(status
) && sta
!= ACPI_STA_ALL
)
826 return AE_CTRL_DEPTH
;
828 /* Scan only PCI bus scope */
829 status
= acpi_get_handle(handle
, "_HID", &tmp
);
830 if (ACPI_SUCCESS(status
))
831 return AE_CTRL_DEPTH
;
833 if (get_gsi_base(handle
, &gsi_base
))
836 acpi_unregister_ioapic(handle
, gsi_base
);
838 spin_lock(&ioapic_list_lock
);
839 list_for_each_entry_safe(pos
, n
, &ioapic_list
, list
) {
840 if (pos
->gsi_base
!= gsi_base
)
843 list_del(&ioapic
->list
);
846 spin_unlock(&ioapic_list_lock
);
851 pci_release_region(ioapic
->dev
, 0);
852 pci_disable_device(ioapic
->dev
);
853 pci_dev_put(ioapic
->dev
);
859 static int acpiphp_configure_ioapics(acpi_handle handle
)
861 ioapic_add(handle
, 0, NULL
, NULL
);
862 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
863 ACPI_UINT32_MAX
, ioapic_add
, NULL
, NULL
);
867 static int acpiphp_unconfigure_ioapics(acpi_handle handle
)
869 ioapic_remove(handle
, 0, NULL
, NULL
);
870 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
871 ACPI_UINT32_MAX
, ioapic_remove
, NULL
, NULL
);
875 static int power_on_slot(struct acpiphp_slot
*slot
)
878 struct acpiphp_func
*func
;
882 /* if already enabled, just skip */
883 if (slot
->flags
& SLOT_POWEREDON
)
886 list_for_each (l
, &slot
->funcs
) {
887 func
= list_entry(l
, struct acpiphp_func
, sibling
);
889 if (func
->flags
& FUNC_HAS_PS0
) {
890 dbg("%s: executing _PS0\n", __func__
);
891 status
= acpi_evaluate_object(func
->handle
, "_PS0", NULL
, NULL
);
892 if (ACPI_FAILURE(status
)) {
893 warn("%s: _PS0 failed\n", __func__
);
901 /* TBD: evaluate _STA to check if the slot is enabled */
903 slot
->flags
|= SLOT_POWEREDON
;
910 static int power_off_slot(struct acpiphp_slot
*slot
)
913 struct acpiphp_func
*func
;
918 /* if already disabled, just skip */
919 if ((slot
->flags
& SLOT_POWEREDON
) == 0)
922 list_for_each (l
, &slot
->funcs
) {
923 func
= list_entry(l
, struct acpiphp_func
, sibling
);
925 if (func
->flags
& FUNC_HAS_PS3
) {
926 status
= acpi_evaluate_object(func
->handle
, "_PS3", NULL
, NULL
);
927 if (ACPI_FAILURE(status
)) {
928 warn("%s: _PS3 failed\n", __func__
);
936 /* TBD: evaluate _STA to check if the slot is disabled */
938 slot
->flags
&= (~SLOT_POWEREDON
);
947 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
948 * @bus: bus to start search with
950 static unsigned char acpiphp_max_busnr(struct pci_bus
*bus
)
952 struct list_head
*tmp
;
953 unsigned char max
, n
;
956 * pci_bus_max_busnr will return the highest
957 * reserved busnr for all these children.
958 * that is equivalent to the bus->subordinate
959 * value. We don't want to use the parent's
960 * bus->subordinate value because it could have
963 max
= bus
->secondary
;
965 list_for_each(tmp
, &bus
->children
) {
966 n
= pci_bus_max_busnr(pci_bus_b(tmp
));
975 * acpiphp_bus_add - add a new bus to acpi subsystem
976 * @func: acpiphp_func of the bridge
978 static int acpiphp_bus_add(struct acpiphp_func
*func
)
981 struct acpi_device
*device
, *pdevice
;
984 acpi_get_parent(func
->handle
, &phandle
);
985 if (acpi_bus_get_device(phandle
, &pdevice
)) {
986 dbg("no parent device, assuming NULL\n");
989 if (!acpi_bus_get_device(func
->handle
, &device
)) {
990 dbg("bus exists... trim\n");
991 /* this shouldn't be in here, so remove
992 * the bus then re-add it...
994 ret_val
= acpi_bus_trim(device
, 1);
995 dbg("acpi_bus_trim return %x\n", ret_val
);
998 ret_val
= acpi_bus_add(&device
, pdevice
, func
->handle
,
999 ACPI_BUS_TYPE_DEVICE
);
1001 dbg("error adding bus, %x\n",
1003 goto acpiphp_bus_add_out
;
1006 * try to start anyway. We could have failed to add
1007 * simply because this bus had previously been added
1008 * on another add. Don't bother with the return value
1009 * we just keep going.
1011 ret_val
= acpi_bus_start(device
);
1013 acpiphp_bus_add_out
:
1019 * acpiphp_bus_trim - trim a bus from acpi subsystem
1020 * @handle: handle to acpi namespace
1022 static int acpiphp_bus_trim(acpi_handle handle
)
1024 struct acpi_device
*device
;
1027 retval
= acpi_bus_get_device(handle
, &device
);
1029 dbg("acpi_device not found\n");
1033 retval
= acpi_bus_trim(device
, 1);
1035 err("cannot remove from acpi list\n");
1041 * enable_device - enable, configure a slot
1042 * @slot: slot to be enabled
1044 * This function should be called per *physical slot*,
1045 * not per each slot object in ACPI namespace.
1047 static int __ref
enable_device(struct acpiphp_slot
*slot
)
1049 struct pci_dev
*dev
;
1050 struct pci_bus
*bus
= slot
->bridge
->pci_bus
;
1051 struct list_head
*l
;
1052 struct acpiphp_func
*func
;
1057 if (slot
->flags
& SLOT_ENABLED
)
1060 /* sanity check: dev should be NULL when hot-plugged in */
1061 dev
= pci_get_slot(bus
, PCI_DEVFN(slot
->device
, 0));
1063 /* This case shouldn't happen */
1064 err("pci_dev structure already exists.\n");
1070 num
= pci_scan_slot(bus
, PCI_DEVFN(slot
->device
, 0));
1072 err("No new device found\n");
1077 max
= acpiphp_max_busnr(bus
);
1078 for (pass
= 0; pass
< 2; pass
++) {
1079 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1080 if (PCI_SLOT(dev
->devfn
) != slot
->device
)
1082 if (dev
->hdr_type
== PCI_HEADER_TYPE_BRIDGE
||
1083 dev
->hdr_type
== PCI_HEADER_TYPE_CARDBUS
) {
1084 max
= pci_scan_bridge(bus
, dev
, max
, pass
);
1085 if (pass
&& dev
->subordinate
)
1086 pci_bus_size_bridges(dev
->subordinate
);
1091 list_for_each (l
, &slot
->funcs
) {
1092 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1093 acpiphp_bus_add(func
);
1096 pci_bus_assign_resources(bus
);
1097 acpiphp_sanitize_bus(bus
);
1098 acpiphp_set_hpp_values(slot
->bridge
->handle
, bus
);
1099 list_for_each_entry(func
, &slot
->funcs
, sibling
)
1100 acpiphp_configure_ioapics(func
->handle
);
1101 pci_enable_bridges(bus
);
1102 pci_bus_add_devices(bus
);
1104 /* associate pci_dev to our representation */
1105 list_for_each (l
, &slot
->funcs
) {
1106 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1107 func
->pci_dev
= pci_get_slot(bus
, PCI_DEVFN(slot
->device
,
1112 if (func
->pci_dev
->hdr_type
!= PCI_HEADER_TYPE_BRIDGE
&&
1113 func
->pci_dev
->hdr_type
!= PCI_HEADER_TYPE_CARDBUS
)
1116 status
= find_p2p_bridge(func
->handle
, (u32
)1, bus
, NULL
);
1117 if (ACPI_FAILURE(status
))
1118 warn("find_p2p_bridge failed (error code = 0x%x)\n",
1122 slot
->flags
|= SLOT_ENABLED
;
1128 static void disable_bridges(struct pci_bus
*bus
)
1130 struct pci_dev
*dev
;
1131 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1132 if (dev
->subordinate
) {
1133 disable_bridges(dev
->subordinate
);
1134 pci_disable_device(dev
);
1140 * disable_device - disable a slot
1141 * @slot: ACPI PHP slot
1143 static int disable_device(struct acpiphp_slot
*slot
)
1146 struct acpiphp_func
*func
;
1147 struct list_head
*l
;
1149 /* is this slot already disabled? */
1150 if (!(slot
->flags
& SLOT_ENABLED
))
1153 list_for_each (l
, &slot
->funcs
) {
1154 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1157 /* cleanup p2p bridges under this P2P bridge */
1158 cleanup_p2p_bridge(func
->bridge
->handle
,
1159 (u32
)1, NULL
, NULL
);
1160 func
->bridge
= NULL
;
1163 if (func
->pci_dev
) {
1164 pci_stop_bus_device(func
->pci_dev
);
1165 if (func
->pci_dev
->subordinate
) {
1166 disable_bridges(func
->pci_dev
->subordinate
);
1167 pci_disable_device(func
->pci_dev
);
1172 list_for_each (l
, &slot
->funcs
) {
1173 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1175 acpiphp_unconfigure_ioapics(func
->handle
);
1176 acpiphp_bus_trim(func
->handle
);
1177 /* try to remove anyway.
1178 * acpiphp_bus_add might have been failed */
1183 pci_remove_bus_device(func
->pci_dev
);
1184 pci_dev_put(func
->pci_dev
);
1185 func
->pci_dev
= NULL
;
1188 slot
->flags
&= (~SLOT_ENABLED
);
1196 * get_slot_status - get ACPI slot status
1197 * @slot: ACPI PHP slot
1199 * If a slot has _STA for each function and if any one of them
1200 * returned non-zero status, return it.
1202 * If a slot doesn't have _STA and if any one of its functions'
1203 * configuration space is configured, return 0x0f as a _STA.
1205 * Otherwise return 0.
1207 static unsigned int get_slot_status(struct acpiphp_slot
*slot
)
1210 unsigned long long sta
= 0;
1212 struct list_head
*l
;
1213 struct acpiphp_func
*func
;
1215 list_for_each (l
, &slot
->funcs
) {
1216 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1218 if (func
->flags
& FUNC_HAS_STA
) {
1219 status
= acpi_evaluate_integer(func
->handle
, "_STA", NULL
, &sta
);
1220 if (ACPI_SUCCESS(status
) && sta
)
1223 pci_bus_read_config_dword(slot
->bridge
->pci_bus
,
1224 PCI_DEVFN(slot
->device
,
1226 PCI_VENDOR_ID
, &dvid
);
1227 if (dvid
!= 0xffffffff) {
1234 return (unsigned int)sta
;
1238 * acpiphp_eject_slot - physically eject the slot
1239 * @slot: ACPI PHP slot
1241 int acpiphp_eject_slot(struct acpiphp_slot
*slot
)
1244 struct acpiphp_func
*func
;
1245 struct list_head
*l
;
1246 struct acpi_object_list arg_list
;
1247 union acpi_object arg
;
1249 list_for_each (l
, &slot
->funcs
) {
1250 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1252 /* We don't want to call _EJ0 on non-existing functions. */
1253 if ((func
->flags
& FUNC_HAS_EJ0
)) {
1254 /* _EJ0 method take one argument */
1256 arg_list
.pointer
= &arg
;
1257 arg
.type
= ACPI_TYPE_INTEGER
;
1258 arg
.integer
.value
= 1;
1260 status
= acpi_evaluate_object(func
->handle
, "_EJ0", &arg_list
, NULL
);
1261 if (ACPI_FAILURE(status
)) {
1262 warn("%s: _EJ0 failed\n", __func__
);
1272 * acpiphp_check_bridge - re-enumerate devices
1273 * @bridge: where to begin re-enumeration
1275 * Iterate over all slots under this bridge and make sure that if a
1276 * card is present they are enabled, and if not they are disabled.
1278 static int acpiphp_check_bridge(struct acpiphp_bridge
*bridge
)
1280 struct acpiphp_slot
*slot
;
1282 int enabled
, disabled
;
1284 enabled
= disabled
= 0;
1286 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
1287 unsigned int status
= get_slot_status(slot
);
1288 if (slot
->flags
& SLOT_ENABLED
) {
1289 if (status
== ACPI_STA_ALL
)
1291 retval
= acpiphp_disable_slot(slot
);
1293 err("Error occurred in disabling\n");
1296 acpiphp_eject_slot(slot
);
1300 if (status
!= ACPI_STA_ALL
)
1302 retval
= acpiphp_enable_slot(slot
);
1304 err("Error occurred in enabling\n");
1311 dbg("%s: %d enabled, %d disabled\n", __func__
, enabled
, disabled
);
1317 static void program_hpp(struct pci_dev
*dev
, struct acpiphp_bridge
*bridge
)
1319 u16 pci_cmd
, pci_bctl
;
1320 struct pci_dev
*cdev
;
1322 /* Program hpp values for this device */
1323 if (!(dev
->hdr_type
== PCI_HEADER_TYPE_NORMAL
||
1324 (dev
->hdr_type
== PCI_HEADER_TYPE_BRIDGE
&&
1325 (dev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
)))
1328 if ((dev
->class >> 8) == PCI_CLASS_BRIDGE_HOST
)
1331 pci_write_config_byte(dev
, PCI_CACHE_LINE_SIZE
,
1332 bridge
->hpp
.t0
->cache_line_size
);
1333 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
,
1334 bridge
->hpp
.t0
->latency_timer
);
1335 pci_read_config_word(dev
, PCI_COMMAND
, &pci_cmd
);
1336 if (bridge
->hpp
.t0
->enable_serr
)
1337 pci_cmd
|= PCI_COMMAND_SERR
;
1339 pci_cmd
&= ~PCI_COMMAND_SERR
;
1340 if (bridge
->hpp
.t0
->enable_perr
)
1341 pci_cmd
|= PCI_COMMAND_PARITY
;
1343 pci_cmd
&= ~PCI_COMMAND_PARITY
;
1344 pci_write_config_word(dev
, PCI_COMMAND
, pci_cmd
);
1346 /* Program bridge control value and child devices */
1347 if ((dev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
) {
1348 pci_write_config_byte(dev
, PCI_SEC_LATENCY_TIMER
,
1349 bridge
->hpp
.t0
->latency_timer
);
1350 pci_read_config_word(dev
, PCI_BRIDGE_CONTROL
, &pci_bctl
);
1351 if (bridge
->hpp
.t0
->enable_serr
)
1352 pci_bctl
|= PCI_BRIDGE_CTL_SERR
;
1354 pci_bctl
&= ~PCI_BRIDGE_CTL_SERR
;
1355 if (bridge
->hpp
.t0
->enable_perr
)
1356 pci_bctl
|= PCI_BRIDGE_CTL_PARITY
;
1358 pci_bctl
&= ~PCI_BRIDGE_CTL_PARITY
;
1359 pci_write_config_word(dev
, PCI_BRIDGE_CONTROL
, pci_bctl
);
1360 if (dev
->subordinate
) {
1361 list_for_each_entry(cdev
, &dev
->subordinate
->devices
,
1363 program_hpp(cdev
, bridge
);
1368 static void acpiphp_set_hpp_values(acpi_handle handle
, struct pci_bus
*bus
)
1370 struct acpiphp_bridge bridge
;
1371 struct pci_dev
*dev
;
1373 memset(&bridge
, 0, sizeof(bridge
));
1374 bridge
.handle
= handle
;
1375 bridge
.pci_bus
= bus
;
1376 bridge
.pci_dev
= bus
->self
;
1377 decode_hpp(&bridge
);
1378 list_for_each_entry(dev
, &bus
->devices
, bus_list
)
1379 program_hpp(dev
, &bridge
);
1384 * Remove devices for which we could not assign resources, call
1385 * arch specific code to fix-up the bus
1387 static void acpiphp_sanitize_bus(struct pci_bus
*bus
)
1389 struct pci_dev
*dev
;
1391 unsigned long type_mask
= IORESOURCE_IO
| IORESOURCE_MEM
;
1393 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1394 for (i
=0; i
<PCI_BRIDGE_RESOURCES
; i
++) {
1395 struct resource
*res
= &dev
->resource
[i
];
1396 if ((res
->flags
& type_mask
) && !res
->start
&&
1398 /* Could not assign a required resources
1399 * for this device, remove it */
1400 pci_remove_bus_device(dev
);
1407 /* Program resources in newly inserted bridge */
1408 static int acpiphp_configure_bridge (acpi_handle handle
)
1410 struct acpi_pci_id pci_id
;
1411 struct pci_bus
*bus
;
1413 if (ACPI_FAILURE(acpi_get_pci_id(handle
, &pci_id
))) {
1414 err("cannot get PCI domain and bus number for bridge\n");
1417 bus
= pci_find_bus(pci_id
.segment
, pci_id
.bus
);
1419 err("cannot find bus %d:%d\n",
1420 pci_id
.segment
, pci_id
.bus
);
1424 pci_bus_size_bridges(bus
);
1425 pci_bus_assign_resources(bus
);
1426 acpiphp_sanitize_bus(bus
);
1427 acpiphp_set_hpp_values(handle
, bus
);
1428 pci_enable_bridges(bus
);
1429 acpiphp_configure_ioapics(handle
);
1433 static void handle_bridge_insertion(acpi_handle handle
, u32 type
)
1435 struct acpi_device
*device
, *pdevice
;
1436 acpi_handle phandle
;
1438 if ((type
!= ACPI_NOTIFY_BUS_CHECK
) &&
1439 (type
!= ACPI_NOTIFY_DEVICE_CHECK
)) {
1440 err("unexpected notification type %d\n", type
);
1444 acpi_get_parent(handle
, &phandle
);
1445 if (acpi_bus_get_device(phandle
, &pdevice
)) {
1446 dbg("no parent device, assuming NULL\n");
1449 if (acpi_bus_add(&device
, pdevice
, handle
, ACPI_BUS_TYPE_DEVICE
)) {
1450 err("cannot add bridge to acpi list\n");
1453 if (!acpiphp_configure_bridge(handle
) &&
1454 !acpi_bus_start(device
))
1457 err("cannot configure and start bridge\n");
1462 * ACPI event handlers
1466 count_sub_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1468 int *count
= (int *)context
;
1469 struct acpiphp_bridge
*bridge
;
1471 bridge
= acpiphp_handle_to_bridge(handle
);
1478 check_sub_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1480 struct acpiphp_bridge
*bridge
;
1482 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1483 .pointer
= objname
};
1485 bridge
= acpiphp_handle_to_bridge(handle
);
1487 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1488 dbg("%s: re-enumerating slots under %s\n",
1490 acpiphp_check_bridge(bridge
);
1496 * handle_hotplug_event_bridge - handle ACPI event on bridges
1497 * @handle: Notify()'ed acpi_handle
1498 * @type: Notify code
1499 * @context: pointer to acpiphp_bridge structure
1501 * Handles ACPI event notification on {host,p2p} bridges.
1503 static void handle_hotplug_event_bridge(acpi_handle handle
, u32 type
, void *context
)
1505 struct acpiphp_bridge
*bridge
;
1507 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1508 .pointer
= objname
};
1509 struct acpi_device
*device
;
1510 int num_sub_bridges
= 0;
1512 if (acpi_bus_get_device(handle
, &device
)) {
1513 /* This bridge must have just been physically inserted */
1514 handle_bridge_insertion(handle
, type
);
1518 bridge
= acpiphp_handle_to_bridge(handle
);
1519 if (type
== ACPI_NOTIFY_BUS_CHECK
) {
1520 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, ACPI_UINT32_MAX
,
1521 count_sub_bridges
, &num_sub_bridges
, NULL
);
1524 if (!bridge
&& !num_sub_bridges
) {
1525 err("cannot get bridge info\n");
1529 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1532 case ACPI_NOTIFY_BUS_CHECK
:
1533 /* bus re-enumerate */
1534 dbg("%s: Bus check notify on %s\n", __func__
, objname
);
1536 dbg("%s: re-enumerating slots under %s\n",
1538 acpiphp_check_bridge(bridge
);
1540 if (num_sub_bridges
)
1541 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
1542 ACPI_UINT32_MAX
, check_sub_bridges
, NULL
, NULL
);
1545 case ACPI_NOTIFY_DEVICE_CHECK
:
1547 dbg("%s: Device check notify on %s\n", __func__
, objname
);
1548 acpiphp_check_bridge(bridge
);
1551 case ACPI_NOTIFY_DEVICE_WAKE
:
1553 dbg("%s: Device wake notify on %s\n", __func__
, objname
);
1556 case ACPI_NOTIFY_EJECT_REQUEST
:
1557 /* request device eject */
1558 dbg("%s: Device eject notify on %s\n", __func__
, objname
);
1559 if ((bridge
->type
!= BRIDGE_TYPE_HOST
) &&
1560 (bridge
->flags
& BRIDGE_HAS_EJ0
)) {
1561 struct acpiphp_slot
*slot
;
1562 slot
= bridge
->func
->slot
;
1563 if (!acpiphp_disable_slot(slot
))
1564 acpiphp_eject_slot(slot
);
1568 case ACPI_NOTIFY_FREQUENCY_MISMATCH
:
1569 printk(KERN_ERR
"Device %s cannot be configured due"
1570 " to a frequency mismatch\n", objname
);
1573 case ACPI_NOTIFY_BUS_MODE_MISMATCH
:
1574 printk(KERN_ERR
"Device %s cannot be configured due"
1575 " to a bus mode mismatch\n", objname
);
1578 case ACPI_NOTIFY_POWER_FAULT
:
1579 printk(KERN_ERR
"Device %s has suffered a power fault\n",
1584 warn("notify_handler: unknown event type 0x%x for %s\n", type
, objname
);
1590 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
1591 * @handle: Notify()'ed acpi_handle
1592 * @type: Notify code
1593 * @context: pointer to acpiphp_func structure
1595 * Handles ACPI event notification on slots.
1597 static void handle_hotplug_event_func(acpi_handle handle
, u32 type
, void *context
)
1599 struct acpiphp_func
*func
;
1601 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1602 .pointer
= objname
};
1604 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1606 func
= (struct acpiphp_func
*)context
;
1609 case ACPI_NOTIFY_BUS_CHECK
:
1610 /* bus re-enumerate */
1611 dbg("%s: Bus check notify on %s\n", __func__
, objname
);
1612 acpiphp_enable_slot(func
->slot
);
1615 case ACPI_NOTIFY_DEVICE_CHECK
:
1616 /* device check : re-enumerate from parent bus */
1617 dbg("%s: Device check notify on %s\n", __func__
, objname
);
1618 acpiphp_check_bridge(func
->slot
->bridge
);
1621 case ACPI_NOTIFY_DEVICE_WAKE
:
1623 dbg("%s: Device wake notify on %s\n", __func__
, objname
);
1626 case ACPI_NOTIFY_EJECT_REQUEST
:
1627 /* request device eject */
1628 dbg("%s: Device eject notify on %s\n", __func__
, objname
);
1629 if (!(acpiphp_disable_slot(func
->slot
)))
1630 acpiphp_eject_slot(func
->slot
);
1634 warn("notify_handler: unknown event type 0x%x for %s\n", type
, objname
);
1641 find_root_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1643 int *count
= (int *)context
;
1645 if (acpi_root_bridge(handle
)) {
1646 acpi_install_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
1647 handle_hotplug_event_bridge
, NULL
);
1653 static struct acpi_pci_driver acpi_pci_hp_driver
= {
1655 .remove
= remove_bridge
,
1659 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
1661 int __init
acpiphp_glue_init(void)
1665 acpi_walk_namespace(ACPI_TYPE_DEVICE
, ACPI_ROOT_OBJECT
,
1666 ACPI_UINT32_MAX
, find_root_bridges
, &num
, NULL
);
1671 acpi_pci_register_driver(&acpi_pci_hp_driver
);
1678 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures
1680 * This function frees all data allocated in acpiphp_glue_init().
1682 void acpiphp_glue_exit(void)
1684 acpi_pci_unregister_driver(&acpi_pci_hp_driver
);
1689 * acpiphp_get_num_slots - count number of slots in a system
1691 int __init
acpiphp_get_num_slots(void)
1693 struct acpiphp_bridge
*bridge
;
1696 list_for_each_entry (bridge
, &bridge_list
, list
) {
1697 dbg("Bus %04x:%02x has %d slot%s\n",
1698 pci_domain_nr(bridge
->pci_bus
),
1699 bridge
->pci_bus
->number
, bridge
->nr_slots
,
1700 bridge
->nr_slots
== 1 ? "" : "s");
1701 num_slots
+= bridge
->nr_slots
;
1704 dbg("Total %d slots\n", num_slots
);
1711 * acpiphp_for_each_slot - call function for each slot
1712 * @fn: callback function
1713 * @data: context to be passed to callback function
1715 static int acpiphp_for_each_slot(acpiphp_callback fn
, void *data
)
1717 struct list_head
*node
;
1718 struct acpiphp_bridge
*bridge
;
1719 struct acpiphp_slot
*slot
;
1722 list_for_each (node
, &bridge_list
) {
1723 bridge
= (struct acpiphp_bridge
*)node
;
1724 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
1725 retval
= fn(slot
, data
);
1738 * acpiphp_enable_slot - power on slot
1739 * @slot: ACPI PHP slot
1741 int acpiphp_enable_slot(struct acpiphp_slot
*slot
)
1745 mutex_lock(&slot
->crit_sect
);
1747 /* wake up all functions */
1748 retval
= power_on_slot(slot
);
1752 if (get_slot_status(slot
) == ACPI_STA_ALL
) {
1753 /* configure all functions */
1754 retval
= enable_device(slot
);
1756 power_off_slot(slot
);
1758 dbg("%s: Slot status is not ACPI_STA_ALL\n", __func__
);
1759 power_off_slot(slot
);
1763 mutex_unlock(&slot
->crit_sect
);
1768 * acpiphp_disable_slot - power off slot
1769 * @slot: ACPI PHP slot
1771 int acpiphp_disable_slot(struct acpiphp_slot
*slot
)
1775 mutex_lock(&slot
->crit_sect
);
1777 /* unconfigure all functions */
1778 retval
= disable_device(slot
);
1782 /* power off all functions */
1783 retval
= power_off_slot(slot
);
1788 mutex_unlock(&slot
->crit_sect
);
1797 u8
acpiphp_get_power_status(struct acpiphp_slot
*slot
)
1799 return (slot
->flags
& SLOT_POWEREDON
);
1807 u8
acpiphp_get_latch_status(struct acpiphp_slot
*slot
)
1811 sta
= get_slot_status(slot
);
1813 return (sta
& ACPI_STA_SHOW_IN_UI
) ? 0 : 1;
1818 * adapter presence : 1
1821 u8
acpiphp_get_adapter_status(struct acpiphp_slot
*slot
)
1825 sta
= get_slot_status(slot
);
1827 return (sta
== 0) ? 0 : 1;