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
);
172 static struct acpi_dock_ops acpiphp_dock_ops
= {
173 .handler
= handle_hotplug_event_func
,
176 /* callback routine to register each ACPI PCI slot object */
178 register_slot(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
180 struct acpiphp_bridge
*bridge
= (struct acpiphp_bridge
*)context
;
181 struct acpiphp_slot
*slot
;
182 struct acpiphp_func
*newfunc
;
184 acpi_status status
= AE_OK
;
185 unsigned long long adr
, sun
;
186 int device
, function
, retval
;
188 status
= acpi_evaluate_integer(handle
, "_ADR", NULL
, &adr
);
190 if (ACPI_FAILURE(status
))
193 status
= acpi_get_handle(handle
, "_EJ0", &tmp
);
195 if (ACPI_FAILURE(status
) && !(is_dock_device(handle
)))
198 device
= (adr
>> 16) & 0xffff;
199 function
= adr
& 0xffff;
201 newfunc
= kzalloc(sizeof(struct acpiphp_func
), GFP_KERNEL
);
205 INIT_LIST_HEAD(&newfunc
->sibling
);
206 newfunc
->handle
= handle
;
207 newfunc
->function
= function
;
208 if (ACPI_SUCCESS(status
))
209 newfunc
->flags
= FUNC_HAS_EJ0
;
211 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_STA", &tmp
)))
212 newfunc
->flags
|= FUNC_HAS_STA
;
214 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_PS0", &tmp
)))
215 newfunc
->flags
|= FUNC_HAS_PS0
;
217 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_PS3", &tmp
)))
218 newfunc
->flags
|= FUNC_HAS_PS3
;
220 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_DCK", &tmp
)))
221 newfunc
->flags
|= FUNC_HAS_DCK
;
223 status
= acpi_evaluate_integer(handle
, "_SUN", NULL
, &sun
);
224 if (ACPI_FAILURE(status
)) {
226 * use the count of the number of slots we've found
227 * for the number of the slot
229 sun
= bridge
->nr_slots
+1;
232 /* search for objects that share the same slot */
233 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
)
234 if (slot
->device
== device
) {
235 if (slot
->sun
!= sun
)
236 warn("sibling found, but _SUN doesn't match!\n");
241 slot
= kzalloc(sizeof(struct acpiphp_slot
), GFP_KERNEL
);
247 slot
->bridge
= bridge
;
248 slot
->device
= device
;
250 INIT_LIST_HEAD(&slot
->funcs
);
251 mutex_init(&slot
->crit_sect
);
253 slot
->next
= bridge
->slots
;
254 bridge
->slots
= slot
;
258 dbg("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
259 slot
->sun
, pci_domain_nr(bridge
->pci_bus
),
260 bridge
->pci_bus
->number
, slot
->device
);
261 retval
= acpiphp_register_hotplug_slot(slot
);
263 if (retval
== -EBUSY
)
264 warn("Slot %llu already registered by another "
265 "hotplug driver\n", slot
->sun
);
267 warn("acpiphp_register_hotplug_slot failed "
268 "(err code = 0x%x)\n", retval
);
273 newfunc
->slot
= slot
;
274 list_add_tail(&newfunc
->sibling
, &slot
->funcs
);
276 /* associate corresponding pci_dev */
277 newfunc
->pci_dev
= pci_get_slot(bridge
->pci_bus
,
278 PCI_DEVFN(device
, function
));
279 if (newfunc
->pci_dev
) {
280 slot
->flags
|= (SLOT_ENABLED
| SLOT_POWEREDON
);
283 if (is_dock_device(handle
)) {
284 /* we don't want to call this device's _EJ0
285 * because we want the dock notify handler
286 * to call it after it calls _DCK
288 newfunc
->flags
&= ~FUNC_HAS_EJ0
;
289 if (register_hotplug_dock_device(handle
,
290 &acpiphp_dock_ops
, newfunc
))
291 dbg("failed to register dock device\n");
293 /* we need to be notified when dock events happen
294 * outside of the hotplug operation, since we may
295 * need to do fixups before we can hotplug.
297 newfunc
->nb
.notifier_call
= post_dock_fixups
;
298 if (register_dock_notifier(&newfunc
->nb
))
299 dbg("failed to register a dock notifier");
302 /* install notify handler */
303 if (!(newfunc
->flags
& FUNC_HAS_DCK
)) {
304 status
= acpi_install_notify_handler(handle
,
306 handle_hotplug_event_func
,
309 if (ACPI_FAILURE(status
))
310 err("failed to register interrupt notify handler\n");
318 bridge
->slots
= slot
->next
;
326 /* see if it's worth looking at this bridge */
327 static int detect_ejectable_slots(acpi_handle
*bridge_handle
)
334 /* only check slots defined directly below bridge object */
335 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge_handle
, (u32
)1,
336 is_ejectable_slot
, (void *)&count
, NULL
);
339 * we also need to add this bridge if there is a dock bridge or
340 * other pci device on a dock station (removable)
343 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge_handle
,
344 (u32
)1, is_pci_dock_device
, (void *)&count
,
351 /* decode ACPI 2.0 _HPP hot plug parameters */
352 static void decode_hpp(struct acpiphp_bridge
*bridge
)
356 status
= acpi_get_hp_params_from_firmware(bridge
->pci_bus
, &bridge
->hpp
);
357 if (ACPI_FAILURE(status
) ||
358 !bridge
->hpp
.t0
|| (bridge
->hpp
.t0
->revision
> 1)) {
359 /* use default numbers */
361 "%s: Could not get hotplug parameters. Use defaults\n",
363 bridge
->hpp
.t0
= &bridge
->hpp
.type0_data
;
364 bridge
->hpp
.t0
->revision
= 0;
365 bridge
->hpp
.t0
->cache_line_size
= 0x10;
366 bridge
->hpp
.t0
->latency_timer
= 0x40;
367 bridge
->hpp
.t0
->enable_serr
= 0;
368 bridge
->hpp
.t0
->enable_perr
= 0;
374 /* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */
375 static void init_bridge_misc(struct acpiphp_bridge
*bridge
)
379 /* decode ACPI 2.0 _HPP (hot plug parameters) */
382 /* must be added to the list prior to calling register_slot */
383 list_add(&bridge
->list
, &bridge_list
);
385 /* register all slot objects under this bridge */
386 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge
->handle
, (u32
)1,
387 register_slot
, bridge
, NULL
);
388 if (ACPI_FAILURE(status
)) {
389 list_del(&bridge
->list
);
393 /* install notify handler */
394 if (bridge
->type
!= BRIDGE_TYPE_HOST
) {
395 if ((bridge
->flags
& BRIDGE_HAS_EJ0
) && bridge
->func
) {
396 status
= acpi_remove_notify_handler(bridge
->func
->handle
,
398 handle_hotplug_event_func
);
399 if (ACPI_FAILURE(status
))
400 err("failed to remove notify handler\n");
402 status
= acpi_install_notify_handler(bridge
->handle
,
404 handle_hotplug_event_bridge
,
407 if (ACPI_FAILURE(status
)) {
408 err("failed to register interrupt notify handler\n");
414 /* find acpiphp_func from acpiphp_bridge */
415 static struct acpiphp_func
*acpiphp_bridge_handle_to_function(acpi_handle handle
)
417 struct list_head
*node
, *l
;
418 struct acpiphp_bridge
*bridge
;
419 struct acpiphp_slot
*slot
;
420 struct acpiphp_func
*func
;
422 list_for_each(node
, &bridge_list
) {
423 bridge
= list_entry(node
, struct acpiphp_bridge
, list
);
424 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
425 list_for_each(l
, &slot
->funcs
) {
426 func
= list_entry(l
, struct acpiphp_func
,
428 if (func
->handle
== handle
)
438 static inline void config_p2p_bridge_flags(struct acpiphp_bridge
*bridge
)
440 acpi_handle dummy_handle
;
442 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
443 "_STA", &dummy_handle
)))
444 bridge
->flags
|= BRIDGE_HAS_STA
;
446 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
447 "_EJ0", &dummy_handle
)))
448 bridge
->flags
|= BRIDGE_HAS_EJ0
;
450 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
451 "_PS0", &dummy_handle
)))
452 bridge
->flags
|= BRIDGE_HAS_PS0
;
454 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
455 "_PS3", &dummy_handle
)))
456 bridge
->flags
|= BRIDGE_HAS_PS3
;
458 /* is this ejectable p2p bridge? */
459 if (bridge
->flags
& BRIDGE_HAS_EJ0
) {
460 struct acpiphp_func
*func
;
462 dbg("found ejectable p2p bridge\n");
464 /* make link between PCI bridge and PCI function */
465 func
= acpiphp_bridge_handle_to_function(bridge
->handle
);
469 func
->bridge
= bridge
;
474 /* allocate and initialize host bridge data structure */
475 static void add_host_bridge(acpi_handle
*handle
, struct pci_bus
*pci_bus
)
477 struct acpiphp_bridge
*bridge
;
479 bridge
= kzalloc(sizeof(struct acpiphp_bridge
), GFP_KERNEL
);
483 bridge
->type
= BRIDGE_TYPE_HOST
;
484 bridge
->handle
= handle
;
486 bridge
->pci_bus
= pci_bus
;
488 spin_lock_init(&bridge
->res_lock
);
490 init_bridge_misc(bridge
);
494 /* allocate and initialize PCI-to-PCI bridge data structure */
495 static void add_p2p_bridge(acpi_handle
*handle
, struct pci_dev
*pci_dev
)
497 struct acpiphp_bridge
*bridge
;
499 bridge
= kzalloc(sizeof(struct acpiphp_bridge
), GFP_KERNEL
);
500 if (bridge
== NULL
) {
501 err("out of memory\n");
505 bridge
->type
= BRIDGE_TYPE_P2P
;
506 bridge
->handle
= handle
;
507 config_p2p_bridge_flags(bridge
);
509 bridge
->pci_dev
= pci_dev_get(pci_dev
);
510 bridge
->pci_bus
= pci_dev
->subordinate
;
511 if (!bridge
->pci_bus
) {
512 err("This is not a PCI-to-PCI bridge!\n");
516 spin_lock_init(&bridge
->res_lock
);
518 init_bridge_misc(bridge
);
521 pci_dev_put(pci_dev
);
527 /* callback routine to find P2P bridges */
529 find_p2p_bridge(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
532 acpi_handle dummy_handle
;
533 unsigned long long tmp
;
534 int device
, function
;
536 struct pci_bus
*pci_bus
= context
;
538 status
= acpi_get_handle(handle
, "_ADR", &dummy_handle
);
539 if (ACPI_FAILURE(status
))
540 return AE_OK
; /* continue */
542 status
= acpi_evaluate_integer(handle
, "_ADR", NULL
, &tmp
);
543 if (ACPI_FAILURE(status
)) {
544 dbg("%s: _ADR evaluation failure\n", __func__
);
548 device
= (tmp
>> 16) & 0xffff;
549 function
= tmp
& 0xffff;
551 dev
= pci_get_slot(pci_bus
, PCI_DEVFN(device
, function
));
553 if (!dev
|| !dev
->subordinate
)
556 /* check if this bridge has ejectable slots */
557 if ((detect_ejectable_slots(handle
) > 0)) {
558 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev
));
559 add_p2p_bridge(handle
, dev
);
562 /* search P2P bridges under this p2p bridge */
563 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
564 find_p2p_bridge
, dev
->subordinate
, NULL
);
565 if (ACPI_FAILURE(status
))
566 warn("find_p2p_bridge failed (error code = 0x%x)\n", status
);
574 /* find hot-pluggable slots, and then find P2P bridge */
575 static int add_bridge(acpi_handle handle
)
578 unsigned long long tmp
;
580 acpi_handle dummy_handle
;
581 struct pci_bus
*pci_bus
;
583 /* if the bridge doesn't have _STA, we assume it is always there */
584 status
= acpi_get_handle(handle
, "_STA", &dummy_handle
);
585 if (ACPI_SUCCESS(status
)) {
586 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &tmp
);
587 if (ACPI_FAILURE(status
)) {
588 dbg("%s: _STA evaluation failure\n", __func__
);
591 if ((tmp
& ACPI_STA_FUNCTIONING
) == 0)
592 /* don't register this object */
596 /* get PCI segment number */
597 status
= acpi_evaluate_integer(handle
, "_SEG", NULL
, &tmp
);
599 seg
= ACPI_SUCCESS(status
) ? tmp
: 0;
601 /* get PCI bus number */
602 status
= acpi_evaluate_integer(handle
, "_BBN", NULL
, &tmp
);
604 if (ACPI_SUCCESS(status
)) {
607 warn("can't get bus number, assuming 0\n");
611 pci_bus
= pci_find_bus(seg
, bus
);
613 err("Can't find bus %04x:%02x\n", seg
, bus
);
617 /* check if this bridge has ejectable slots */
618 if (detect_ejectable_slots(handle
) > 0) {
619 dbg("found PCI host-bus bridge with hot-pluggable slots\n");
620 add_host_bridge(handle
, pci_bus
);
623 /* search P2P bridges under this host bridge */
624 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
625 find_p2p_bridge
, pci_bus
, NULL
);
627 if (ACPI_FAILURE(status
))
628 warn("find_p2p_bridge failed (error code = 0x%x)\n", status
);
633 static struct acpiphp_bridge
*acpiphp_handle_to_bridge(acpi_handle handle
)
635 struct list_head
*head
;
636 list_for_each(head
, &bridge_list
) {
637 struct acpiphp_bridge
*bridge
= list_entry(head
,
638 struct acpiphp_bridge
, list
);
639 if (bridge
->handle
== handle
)
646 static void cleanup_bridge(struct acpiphp_bridge
*bridge
)
648 struct list_head
*list
, *tmp
;
649 struct acpiphp_slot
*slot
;
651 acpi_handle handle
= bridge
->handle
;
653 status
= acpi_remove_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
654 handle_hotplug_event_bridge
);
655 if (ACPI_FAILURE(status
))
656 err("failed to remove notify handler\n");
658 if ((bridge
->type
!= BRIDGE_TYPE_HOST
) &&
659 ((bridge
->flags
& BRIDGE_HAS_EJ0
) && bridge
->func
)) {
660 status
= acpi_install_notify_handler(bridge
->func
->handle
,
662 handle_hotplug_event_func
,
664 if (ACPI_FAILURE(status
))
665 err("failed to install interrupt notify handler\n");
668 slot
= bridge
->slots
;
670 struct acpiphp_slot
*next
= slot
->next
;
671 list_for_each_safe (list
, tmp
, &slot
->funcs
) {
672 struct acpiphp_func
*func
;
673 func
= list_entry(list
, struct acpiphp_func
, sibling
);
674 if (is_dock_device(func
->handle
)) {
675 unregister_hotplug_dock_device(func
->handle
);
676 unregister_dock_notifier(&func
->nb
);
678 if (!(func
->flags
& FUNC_HAS_DCK
)) {
679 status
= acpi_remove_notify_handler(func
->handle
,
681 handle_hotplug_event_func
);
682 if (ACPI_FAILURE(status
))
683 err("failed to remove notify handler\n");
685 pci_dev_put(func
->pci_dev
);
689 acpiphp_unregister_hotplug_slot(slot
);
690 list_del(&slot
->funcs
);
695 pci_dev_put(bridge
->pci_dev
);
696 list_del(&bridge
->list
);
701 cleanup_p2p_bridge(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
703 struct acpiphp_bridge
*bridge
;
705 /* cleanup p2p bridges under this P2P bridge
706 in a depth-first manner */
707 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
708 cleanup_p2p_bridge
, NULL
, NULL
);
710 bridge
= acpiphp_handle_to_bridge(handle
);
712 cleanup_bridge(bridge
);
717 static void remove_bridge(acpi_handle handle
)
719 struct acpiphp_bridge
*bridge
;
721 /* cleanup p2p bridges under this host bridge
722 in a depth-first manner */
723 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
724 (u32
)1, cleanup_p2p_bridge
, NULL
, NULL
);
727 * On root bridges with hotplug slots directly underneath (ie,
728 * no p2p bridge inbetween), we call cleanup_bridge().
730 * The else clause cleans up root bridges that either had no
731 * hotplug slots at all, or had a p2p bridge underneath.
733 bridge
= acpiphp_handle_to_bridge(handle
);
735 cleanup_bridge(bridge
);
737 acpi_remove_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
738 handle_hotplug_event_bridge
);
741 static struct pci_dev
* get_apic_pci_info(acpi_handle handle
)
743 struct acpi_pci_id id
;
747 if (ACPI_FAILURE(acpi_get_pci_id(handle
, &id
)))
750 bus
= pci_find_bus(id
.segment
, id
.bus
);
754 dev
= pci_get_slot(bus
, PCI_DEVFN(id
.device
, id
.function
));
758 if ((dev
->class != PCI_CLASS_SYSTEM_PIC_IOAPIC
) &&
759 (dev
->class != PCI_CLASS_SYSTEM_PIC_IOXAPIC
))
768 static int get_gsi_base(acpi_handle handle
, u32
*gsi_base
)
772 unsigned long long gsb
;
773 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
774 union acpi_object
*obj
;
777 status
= acpi_evaluate_integer(handle
, "_GSB", NULL
, &gsb
);
778 if (ACPI_SUCCESS(status
)) {
779 *gsi_base
= (u32
)gsb
;
783 status
= acpi_evaluate_object(handle
, "_MAT", NULL
, &buffer
);
784 if (ACPI_FAILURE(status
) || !buffer
.length
|| !buffer
.pointer
)
787 obj
= buffer
.pointer
;
788 if (obj
->type
!= ACPI_TYPE_BUFFER
)
791 table
= obj
->buffer
.pointer
;
792 switch (((struct acpi_subtable_header
*)table
)->type
) {
793 case ACPI_MADT_TYPE_IO_SAPIC
:
794 *gsi_base
= ((struct acpi_madt_io_sapic
*)table
)->global_irq_base
;
797 case ACPI_MADT_TYPE_IO_APIC
:
798 *gsi_base
= ((struct acpi_madt_io_apic
*)table
)->global_irq_base
;
805 kfree(buffer
.pointer
);
810 ioapic_add(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
813 unsigned long long sta
;
815 struct pci_dev
*pdev
;
818 struct acpiphp_ioapic
*ioapic
;
820 /* Evaluate _STA if present */
821 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &sta
);
822 if (ACPI_SUCCESS(status
) && sta
!= ACPI_STA_ALL
)
823 return AE_CTRL_DEPTH
;
825 /* Scan only PCI bus scope */
826 status
= acpi_get_handle(handle
, "_HID", &tmp
);
827 if (ACPI_SUCCESS(status
))
828 return AE_CTRL_DEPTH
;
830 if (get_gsi_base(handle
, &gsi_base
))
833 ioapic
= kmalloc(sizeof(*ioapic
), GFP_KERNEL
);
837 pdev
= get_apic_pci_info(handle
);
841 if (pci_enable_device(pdev
))
842 goto exit_pci_dev_put
;
844 pci_set_master(pdev
);
846 if (pci_request_region(pdev
, 0, "I/O APIC(acpiphp)"))
847 goto exit_pci_disable_device
;
849 phys_addr
= pci_resource_start(pdev
, 0);
850 if (acpi_register_ioapic(handle
, phys_addr
, gsi_base
))
851 goto exit_pci_release_region
;
853 ioapic
->gsi_base
= gsi_base
;
855 spin_lock(&ioapic_list_lock
);
856 list_add_tail(&ioapic
->list
, &ioapic_list
);
857 spin_unlock(&ioapic_list_lock
);
861 exit_pci_release_region
:
862 pci_release_region(pdev
, 0);
863 exit_pci_disable_device
:
864 pci_disable_device(pdev
);
874 ioapic_remove(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
877 unsigned long long sta
;
880 struct acpiphp_ioapic
*pos
, *n
, *ioapic
= NULL
;
882 /* Evaluate _STA if present */
883 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &sta
);
884 if (ACPI_SUCCESS(status
) && sta
!= ACPI_STA_ALL
)
885 return AE_CTRL_DEPTH
;
887 /* Scan only PCI bus scope */
888 status
= acpi_get_handle(handle
, "_HID", &tmp
);
889 if (ACPI_SUCCESS(status
))
890 return AE_CTRL_DEPTH
;
892 if (get_gsi_base(handle
, &gsi_base
))
895 acpi_unregister_ioapic(handle
, gsi_base
);
897 spin_lock(&ioapic_list_lock
);
898 list_for_each_entry_safe(pos
, n
, &ioapic_list
, list
) {
899 if (pos
->gsi_base
!= gsi_base
)
902 list_del(&ioapic
->list
);
905 spin_unlock(&ioapic_list_lock
);
910 pci_release_region(ioapic
->dev
, 0);
911 pci_disable_device(ioapic
->dev
);
912 pci_dev_put(ioapic
->dev
);
918 static int acpiphp_configure_ioapics(acpi_handle handle
)
920 ioapic_add(handle
, 0, NULL
, NULL
);
921 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
922 ACPI_UINT32_MAX
, ioapic_add
, NULL
, NULL
);
926 static int acpiphp_unconfigure_ioapics(acpi_handle handle
)
928 ioapic_remove(handle
, 0, NULL
, NULL
);
929 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
930 ACPI_UINT32_MAX
, ioapic_remove
, NULL
, NULL
);
934 static int power_on_slot(struct acpiphp_slot
*slot
)
937 struct acpiphp_func
*func
;
941 /* if already enabled, just skip */
942 if (slot
->flags
& SLOT_POWEREDON
)
945 list_for_each (l
, &slot
->funcs
) {
946 func
= list_entry(l
, struct acpiphp_func
, sibling
);
948 if (func
->flags
& FUNC_HAS_PS0
) {
949 dbg("%s: executing _PS0\n", __func__
);
950 status
= acpi_evaluate_object(func
->handle
, "_PS0", NULL
, NULL
);
951 if (ACPI_FAILURE(status
)) {
952 warn("%s: _PS0 failed\n", __func__
);
960 /* TBD: evaluate _STA to check if the slot is enabled */
962 slot
->flags
|= SLOT_POWEREDON
;
969 static int power_off_slot(struct acpiphp_slot
*slot
)
972 struct acpiphp_func
*func
;
977 /* if already disabled, just skip */
978 if ((slot
->flags
& SLOT_POWEREDON
) == 0)
981 list_for_each (l
, &slot
->funcs
) {
982 func
= list_entry(l
, struct acpiphp_func
, sibling
);
984 if (func
->flags
& FUNC_HAS_PS3
) {
985 status
= acpi_evaluate_object(func
->handle
, "_PS3", NULL
, NULL
);
986 if (ACPI_FAILURE(status
)) {
987 warn("%s: _PS3 failed\n", __func__
);
995 /* TBD: evaluate _STA to check if the slot is disabled */
997 slot
->flags
&= (~SLOT_POWEREDON
);
1006 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
1007 * @bus: bus to start search with
1009 static unsigned char acpiphp_max_busnr(struct pci_bus
*bus
)
1011 struct list_head
*tmp
;
1012 unsigned char max
, n
;
1015 * pci_bus_max_busnr will return the highest
1016 * reserved busnr for all these children.
1017 * that is equivalent to the bus->subordinate
1018 * value. We don't want to use the parent's
1019 * bus->subordinate value because it could have
1022 max
= bus
->secondary
;
1024 list_for_each(tmp
, &bus
->children
) {
1025 n
= pci_bus_max_busnr(pci_bus_b(tmp
));
1034 * acpiphp_bus_add - add a new bus to acpi subsystem
1035 * @func: acpiphp_func of the bridge
1037 static int acpiphp_bus_add(struct acpiphp_func
*func
)
1039 acpi_handle phandle
;
1040 struct acpi_device
*device
, *pdevice
;
1043 acpi_get_parent(func
->handle
, &phandle
);
1044 if (acpi_bus_get_device(phandle
, &pdevice
)) {
1045 dbg("no parent device, assuming NULL\n");
1048 if (!acpi_bus_get_device(func
->handle
, &device
)) {
1049 dbg("bus exists... trim\n");
1050 /* this shouldn't be in here, so remove
1051 * the bus then re-add it...
1053 ret_val
= acpi_bus_trim(device
, 1);
1054 dbg("acpi_bus_trim return %x\n", ret_val
);
1057 ret_val
= acpi_bus_add(&device
, pdevice
, func
->handle
,
1058 ACPI_BUS_TYPE_DEVICE
);
1060 dbg("error adding bus, %x\n",
1062 goto acpiphp_bus_add_out
;
1065 * try to start anyway. We could have failed to add
1066 * simply because this bus had previously been added
1067 * on another add. Don't bother with the return value
1068 * we just keep going.
1070 ret_val
= acpi_bus_start(device
);
1072 acpiphp_bus_add_out
:
1078 * acpiphp_bus_trim - trim a bus from acpi subsystem
1079 * @handle: handle to acpi namespace
1081 static int acpiphp_bus_trim(acpi_handle handle
)
1083 struct acpi_device
*device
;
1086 retval
= acpi_bus_get_device(handle
, &device
);
1088 dbg("acpi_device not found\n");
1092 retval
= acpi_bus_trim(device
, 1);
1094 err("cannot remove from acpi list\n");
1100 * enable_device - enable, configure a slot
1101 * @slot: slot to be enabled
1103 * This function should be called per *physical slot*,
1104 * not per each slot object in ACPI namespace.
1106 static int __ref
enable_device(struct acpiphp_slot
*slot
)
1108 struct pci_dev
*dev
;
1109 struct pci_bus
*bus
= slot
->bridge
->pci_bus
;
1110 struct list_head
*l
;
1111 struct acpiphp_func
*func
;
1116 if (slot
->flags
& SLOT_ENABLED
)
1119 /* sanity check: dev should be NULL when hot-plugged in */
1120 dev
= pci_get_slot(bus
, PCI_DEVFN(slot
->device
, 0));
1122 /* This case shouldn't happen */
1123 err("pci_dev structure already exists.\n");
1129 num
= pci_scan_slot(bus
, PCI_DEVFN(slot
->device
, 0));
1131 err("No new device found\n");
1136 max
= acpiphp_max_busnr(bus
);
1137 for (pass
= 0; pass
< 2; pass
++) {
1138 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1139 if (PCI_SLOT(dev
->devfn
) != slot
->device
)
1141 if (dev
->hdr_type
== PCI_HEADER_TYPE_BRIDGE
||
1142 dev
->hdr_type
== PCI_HEADER_TYPE_CARDBUS
) {
1143 max
= pci_scan_bridge(bus
, dev
, max
, pass
);
1144 if (pass
&& dev
->subordinate
)
1145 pci_bus_size_bridges(dev
->subordinate
);
1150 list_for_each (l
, &slot
->funcs
) {
1151 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1152 acpiphp_bus_add(func
);
1155 pci_bus_assign_resources(bus
);
1156 acpiphp_sanitize_bus(bus
);
1157 acpiphp_set_hpp_values(slot
->bridge
->handle
, bus
);
1158 list_for_each_entry(func
, &slot
->funcs
, sibling
)
1159 acpiphp_configure_ioapics(func
->handle
);
1160 pci_enable_bridges(bus
);
1161 pci_bus_add_devices(bus
);
1163 /* associate pci_dev to our representation */
1164 list_for_each (l
, &slot
->funcs
) {
1165 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1166 func
->pci_dev
= pci_get_slot(bus
, PCI_DEVFN(slot
->device
,
1171 if (func
->pci_dev
->hdr_type
!= PCI_HEADER_TYPE_BRIDGE
&&
1172 func
->pci_dev
->hdr_type
!= PCI_HEADER_TYPE_CARDBUS
)
1175 status
= find_p2p_bridge(func
->handle
, (u32
)1, bus
, NULL
);
1176 if (ACPI_FAILURE(status
))
1177 warn("find_p2p_bridge failed (error code = 0x%x)\n",
1181 slot
->flags
|= SLOT_ENABLED
;
1187 static void disable_bridges(struct pci_bus
*bus
)
1189 struct pci_dev
*dev
;
1190 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1191 if (dev
->subordinate
) {
1192 disable_bridges(dev
->subordinate
);
1193 pci_disable_device(dev
);
1199 * disable_device - disable a slot
1200 * @slot: ACPI PHP slot
1202 static int disable_device(struct acpiphp_slot
*slot
)
1205 struct acpiphp_func
*func
;
1206 struct list_head
*l
;
1208 /* is this slot already disabled? */
1209 if (!(slot
->flags
& SLOT_ENABLED
))
1212 list_for_each (l
, &slot
->funcs
) {
1213 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1216 /* cleanup p2p bridges under this P2P bridge */
1217 cleanup_p2p_bridge(func
->bridge
->handle
,
1218 (u32
)1, NULL
, NULL
);
1219 func
->bridge
= NULL
;
1222 if (func
->pci_dev
) {
1223 pci_stop_bus_device(func
->pci_dev
);
1224 if (func
->pci_dev
->subordinate
) {
1225 disable_bridges(func
->pci_dev
->subordinate
);
1226 pci_disable_device(func
->pci_dev
);
1231 list_for_each (l
, &slot
->funcs
) {
1232 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1234 acpiphp_unconfigure_ioapics(func
->handle
);
1235 acpiphp_bus_trim(func
->handle
);
1236 /* try to remove anyway.
1237 * acpiphp_bus_add might have been failed */
1242 pci_remove_bus_device(func
->pci_dev
);
1243 pci_dev_put(func
->pci_dev
);
1244 func
->pci_dev
= NULL
;
1247 slot
->flags
&= (~SLOT_ENABLED
);
1255 * get_slot_status - get ACPI slot status
1256 * @slot: ACPI PHP slot
1258 * If a slot has _STA for each function and if any one of them
1259 * returned non-zero status, return it.
1261 * If a slot doesn't have _STA and if any one of its functions'
1262 * configuration space is configured, return 0x0f as a _STA.
1264 * Otherwise return 0.
1266 static unsigned int get_slot_status(struct acpiphp_slot
*slot
)
1269 unsigned long long sta
= 0;
1271 struct list_head
*l
;
1272 struct acpiphp_func
*func
;
1274 list_for_each (l
, &slot
->funcs
) {
1275 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1277 if (func
->flags
& FUNC_HAS_STA
) {
1278 status
= acpi_evaluate_integer(func
->handle
, "_STA", NULL
, &sta
);
1279 if (ACPI_SUCCESS(status
) && sta
)
1282 pci_bus_read_config_dword(slot
->bridge
->pci_bus
,
1283 PCI_DEVFN(slot
->device
,
1285 PCI_VENDOR_ID
, &dvid
);
1286 if (dvid
!= 0xffffffff) {
1293 return (unsigned int)sta
;
1297 * acpiphp_eject_slot - physically eject the slot
1298 * @slot: ACPI PHP slot
1300 int acpiphp_eject_slot(struct acpiphp_slot
*slot
)
1303 struct acpiphp_func
*func
;
1304 struct list_head
*l
;
1305 struct acpi_object_list arg_list
;
1306 union acpi_object arg
;
1308 list_for_each (l
, &slot
->funcs
) {
1309 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1311 /* We don't want to call _EJ0 on non-existing functions. */
1312 if ((func
->flags
& FUNC_HAS_EJ0
)) {
1313 /* _EJ0 method take one argument */
1315 arg_list
.pointer
= &arg
;
1316 arg
.type
= ACPI_TYPE_INTEGER
;
1317 arg
.integer
.value
= 1;
1319 status
= acpi_evaluate_object(func
->handle
, "_EJ0", &arg_list
, NULL
);
1320 if (ACPI_FAILURE(status
)) {
1321 warn("%s: _EJ0 failed\n", __func__
);
1331 * acpiphp_check_bridge - re-enumerate devices
1332 * @bridge: where to begin re-enumeration
1334 * Iterate over all slots under this bridge and make sure that if a
1335 * card is present they are enabled, and if not they are disabled.
1337 static int acpiphp_check_bridge(struct acpiphp_bridge
*bridge
)
1339 struct acpiphp_slot
*slot
;
1341 int enabled
, disabled
;
1343 enabled
= disabled
= 0;
1345 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
1346 unsigned int status
= get_slot_status(slot
);
1347 if (slot
->flags
& SLOT_ENABLED
) {
1348 if (status
== ACPI_STA_ALL
)
1350 retval
= acpiphp_disable_slot(slot
);
1352 err("Error occurred in disabling\n");
1355 acpiphp_eject_slot(slot
);
1359 if (status
!= ACPI_STA_ALL
)
1361 retval
= acpiphp_enable_slot(slot
);
1363 err("Error occurred in enabling\n");
1370 dbg("%s: %d enabled, %d disabled\n", __func__
, enabled
, disabled
);
1376 static void program_hpp(struct pci_dev
*dev
, struct acpiphp_bridge
*bridge
)
1378 u16 pci_cmd
, pci_bctl
;
1379 struct pci_dev
*cdev
;
1381 /* Program hpp values for this device */
1382 if (!(dev
->hdr_type
== PCI_HEADER_TYPE_NORMAL
||
1383 (dev
->hdr_type
== PCI_HEADER_TYPE_BRIDGE
&&
1384 (dev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
)))
1387 if ((dev
->class >> 8) == PCI_CLASS_BRIDGE_HOST
)
1390 pci_write_config_byte(dev
, PCI_CACHE_LINE_SIZE
,
1391 bridge
->hpp
.t0
->cache_line_size
);
1392 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
,
1393 bridge
->hpp
.t0
->latency_timer
);
1394 pci_read_config_word(dev
, PCI_COMMAND
, &pci_cmd
);
1395 if (bridge
->hpp
.t0
->enable_serr
)
1396 pci_cmd
|= PCI_COMMAND_SERR
;
1398 pci_cmd
&= ~PCI_COMMAND_SERR
;
1399 if (bridge
->hpp
.t0
->enable_perr
)
1400 pci_cmd
|= PCI_COMMAND_PARITY
;
1402 pci_cmd
&= ~PCI_COMMAND_PARITY
;
1403 pci_write_config_word(dev
, PCI_COMMAND
, pci_cmd
);
1405 /* Program bridge control value and child devices */
1406 if ((dev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
) {
1407 pci_write_config_byte(dev
, PCI_SEC_LATENCY_TIMER
,
1408 bridge
->hpp
.t0
->latency_timer
);
1409 pci_read_config_word(dev
, PCI_BRIDGE_CONTROL
, &pci_bctl
);
1410 if (bridge
->hpp
.t0
->enable_serr
)
1411 pci_bctl
|= PCI_BRIDGE_CTL_SERR
;
1413 pci_bctl
&= ~PCI_BRIDGE_CTL_SERR
;
1414 if (bridge
->hpp
.t0
->enable_perr
)
1415 pci_bctl
|= PCI_BRIDGE_CTL_PARITY
;
1417 pci_bctl
&= ~PCI_BRIDGE_CTL_PARITY
;
1418 pci_write_config_word(dev
, PCI_BRIDGE_CONTROL
, pci_bctl
);
1419 if (dev
->subordinate
) {
1420 list_for_each_entry(cdev
, &dev
->subordinate
->devices
,
1422 program_hpp(cdev
, bridge
);
1427 static void acpiphp_set_hpp_values(acpi_handle handle
, struct pci_bus
*bus
)
1429 struct acpiphp_bridge bridge
;
1430 struct pci_dev
*dev
;
1432 memset(&bridge
, 0, sizeof(bridge
));
1433 bridge
.handle
= handle
;
1434 bridge
.pci_bus
= bus
;
1435 bridge
.pci_dev
= bus
->self
;
1436 decode_hpp(&bridge
);
1437 list_for_each_entry(dev
, &bus
->devices
, bus_list
)
1438 program_hpp(dev
, &bridge
);
1443 * Remove devices for which we could not assign resources, call
1444 * arch specific code to fix-up the bus
1446 static void acpiphp_sanitize_bus(struct pci_bus
*bus
)
1448 struct pci_dev
*dev
;
1450 unsigned long type_mask
= IORESOURCE_IO
| IORESOURCE_MEM
;
1452 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1453 for (i
=0; i
<PCI_BRIDGE_RESOURCES
; i
++) {
1454 struct resource
*res
= &dev
->resource
[i
];
1455 if ((res
->flags
& type_mask
) && !res
->start
&&
1457 /* Could not assign a required resources
1458 * for this device, remove it */
1459 pci_remove_bus_device(dev
);
1466 /* Program resources in newly inserted bridge */
1467 static int acpiphp_configure_bridge (acpi_handle handle
)
1469 struct acpi_pci_id pci_id
;
1470 struct pci_bus
*bus
;
1472 if (ACPI_FAILURE(acpi_get_pci_id(handle
, &pci_id
))) {
1473 err("cannot get PCI domain and bus number for bridge\n");
1476 bus
= pci_find_bus(pci_id
.segment
, pci_id
.bus
);
1478 err("cannot find bus %d:%d\n",
1479 pci_id
.segment
, pci_id
.bus
);
1483 pci_bus_size_bridges(bus
);
1484 pci_bus_assign_resources(bus
);
1485 acpiphp_sanitize_bus(bus
);
1486 acpiphp_set_hpp_values(handle
, bus
);
1487 pci_enable_bridges(bus
);
1488 acpiphp_configure_ioapics(handle
);
1492 static void handle_bridge_insertion(acpi_handle handle
, u32 type
)
1494 struct acpi_device
*device
, *pdevice
;
1495 acpi_handle phandle
;
1497 if ((type
!= ACPI_NOTIFY_BUS_CHECK
) &&
1498 (type
!= ACPI_NOTIFY_DEVICE_CHECK
)) {
1499 err("unexpected notification type %d\n", type
);
1503 acpi_get_parent(handle
, &phandle
);
1504 if (acpi_bus_get_device(phandle
, &pdevice
)) {
1505 dbg("no parent device, assuming NULL\n");
1508 if (acpi_bus_add(&device
, pdevice
, handle
, ACPI_BUS_TYPE_DEVICE
)) {
1509 err("cannot add bridge to acpi list\n");
1512 if (!acpiphp_configure_bridge(handle
) &&
1513 !acpi_bus_start(device
))
1516 err("cannot configure and start bridge\n");
1521 * ACPI event handlers
1525 count_sub_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1527 int *count
= (int *)context
;
1528 struct acpiphp_bridge
*bridge
;
1530 bridge
= acpiphp_handle_to_bridge(handle
);
1537 check_sub_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1539 struct acpiphp_bridge
*bridge
;
1541 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1542 .pointer
= objname
};
1544 bridge
= acpiphp_handle_to_bridge(handle
);
1546 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1547 dbg("%s: re-enumerating slots under %s\n",
1549 acpiphp_check_bridge(bridge
);
1555 * handle_hotplug_event_bridge - handle ACPI event on bridges
1556 * @handle: Notify()'ed acpi_handle
1557 * @type: Notify code
1558 * @context: pointer to acpiphp_bridge structure
1560 * Handles ACPI event notification on {host,p2p} bridges.
1562 static void handle_hotplug_event_bridge(acpi_handle handle
, u32 type
, void *context
)
1564 struct acpiphp_bridge
*bridge
;
1566 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1567 .pointer
= objname
};
1568 struct acpi_device
*device
;
1569 int num_sub_bridges
= 0;
1571 if (acpi_bus_get_device(handle
, &device
)) {
1572 /* This bridge must have just been physically inserted */
1573 handle_bridge_insertion(handle
, type
);
1577 bridge
= acpiphp_handle_to_bridge(handle
);
1578 if (type
== ACPI_NOTIFY_BUS_CHECK
) {
1579 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, ACPI_UINT32_MAX
,
1580 count_sub_bridges
, &num_sub_bridges
, NULL
);
1583 if (!bridge
&& !num_sub_bridges
) {
1584 err("cannot get bridge info\n");
1588 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1591 case ACPI_NOTIFY_BUS_CHECK
:
1592 /* bus re-enumerate */
1593 dbg("%s: Bus check notify on %s\n", __func__
, objname
);
1595 dbg("%s: re-enumerating slots under %s\n",
1597 acpiphp_check_bridge(bridge
);
1599 if (num_sub_bridges
)
1600 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
1601 ACPI_UINT32_MAX
, check_sub_bridges
, NULL
, NULL
);
1604 case ACPI_NOTIFY_DEVICE_CHECK
:
1606 dbg("%s: Device check notify on %s\n", __func__
, objname
);
1607 acpiphp_check_bridge(bridge
);
1610 case ACPI_NOTIFY_DEVICE_WAKE
:
1612 dbg("%s: Device wake notify on %s\n", __func__
, objname
);
1615 case ACPI_NOTIFY_EJECT_REQUEST
:
1616 /* request device eject */
1617 dbg("%s: Device eject notify on %s\n", __func__
, objname
);
1618 if ((bridge
->type
!= BRIDGE_TYPE_HOST
) &&
1619 (bridge
->flags
& BRIDGE_HAS_EJ0
)) {
1620 struct acpiphp_slot
*slot
;
1621 slot
= bridge
->func
->slot
;
1622 if (!acpiphp_disable_slot(slot
))
1623 acpiphp_eject_slot(slot
);
1627 case ACPI_NOTIFY_FREQUENCY_MISMATCH
:
1628 printk(KERN_ERR
"Device %s cannot be configured due"
1629 " to a frequency mismatch\n", objname
);
1632 case ACPI_NOTIFY_BUS_MODE_MISMATCH
:
1633 printk(KERN_ERR
"Device %s cannot be configured due"
1634 " to a bus mode mismatch\n", objname
);
1637 case ACPI_NOTIFY_POWER_FAULT
:
1638 printk(KERN_ERR
"Device %s has suffered a power fault\n",
1643 warn("notify_handler: unknown event type 0x%x for %s\n", type
, objname
);
1649 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
1650 * @handle: Notify()'ed acpi_handle
1651 * @type: Notify code
1652 * @context: pointer to acpiphp_func structure
1654 * Handles ACPI event notification on slots.
1656 static void handle_hotplug_event_func(acpi_handle handle
, u32 type
, void *context
)
1658 struct acpiphp_func
*func
;
1660 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1661 .pointer
= objname
};
1663 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1665 func
= (struct acpiphp_func
*)context
;
1668 case ACPI_NOTIFY_BUS_CHECK
:
1669 /* bus re-enumerate */
1670 dbg("%s: Bus check notify on %s\n", __func__
, objname
);
1671 acpiphp_enable_slot(func
->slot
);
1674 case ACPI_NOTIFY_DEVICE_CHECK
:
1675 /* device check : re-enumerate from parent bus */
1676 dbg("%s: Device check notify on %s\n", __func__
, objname
);
1677 acpiphp_check_bridge(func
->slot
->bridge
);
1680 case ACPI_NOTIFY_DEVICE_WAKE
:
1682 dbg("%s: Device wake notify on %s\n", __func__
, objname
);
1685 case ACPI_NOTIFY_EJECT_REQUEST
:
1686 /* request device eject */
1687 dbg("%s: Device eject notify on %s\n", __func__
, objname
);
1688 if (!(acpiphp_disable_slot(func
->slot
)))
1689 acpiphp_eject_slot(func
->slot
);
1693 warn("notify_handler: unknown event type 0x%x for %s\n", type
, objname
);
1700 find_root_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1702 int *count
= (int *)context
;
1704 if (acpi_root_bridge(handle
)) {
1705 acpi_install_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
1706 handle_hotplug_event_bridge
, NULL
);
1712 static struct acpi_pci_driver acpi_pci_hp_driver
= {
1714 .remove
= remove_bridge
,
1718 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
1720 int __init
acpiphp_glue_init(void)
1724 acpi_walk_namespace(ACPI_TYPE_DEVICE
, ACPI_ROOT_OBJECT
,
1725 ACPI_UINT32_MAX
, find_root_bridges
, &num
, NULL
);
1730 acpi_pci_register_driver(&acpi_pci_hp_driver
);
1737 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures
1739 * This function frees all data allocated in acpiphp_glue_init().
1741 void acpiphp_glue_exit(void)
1743 acpi_pci_unregister_driver(&acpi_pci_hp_driver
);
1748 * acpiphp_get_num_slots - count number of slots in a system
1750 int __init
acpiphp_get_num_slots(void)
1752 struct acpiphp_bridge
*bridge
;
1755 list_for_each_entry (bridge
, &bridge_list
, list
) {
1756 dbg("Bus %04x:%02x has %d slot%s\n",
1757 pci_domain_nr(bridge
->pci_bus
),
1758 bridge
->pci_bus
->number
, bridge
->nr_slots
,
1759 bridge
->nr_slots
== 1 ? "" : "s");
1760 num_slots
+= bridge
->nr_slots
;
1763 dbg("Total %d slots\n", num_slots
);
1770 * acpiphp_for_each_slot - call function for each slot
1771 * @fn: callback function
1772 * @data: context to be passed to callback function
1774 static int acpiphp_for_each_slot(acpiphp_callback fn
, void *data
)
1776 struct list_head
*node
;
1777 struct acpiphp_bridge
*bridge
;
1778 struct acpiphp_slot
*slot
;
1781 list_for_each (node
, &bridge_list
) {
1782 bridge
= (struct acpiphp_bridge
*)node
;
1783 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
1784 retval
= fn(slot
, data
);
1797 * acpiphp_enable_slot - power on slot
1798 * @slot: ACPI PHP slot
1800 int acpiphp_enable_slot(struct acpiphp_slot
*slot
)
1804 mutex_lock(&slot
->crit_sect
);
1806 /* wake up all functions */
1807 retval
= power_on_slot(slot
);
1811 if (get_slot_status(slot
) == ACPI_STA_ALL
) {
1812 /* configure all functions */
1813 retval
= enable_device(slot
);
1815 power_off_slot(slot
);
1817 dbg("%s: Slot status is not ACPI_STA_ALL\n", __func__
);
1818 power_off_slot(slot
);
1822 mutex_unlock(&slot
->crit_sect
);
1827 * acpiphp_disable_slot - power off slot
1828 * @slot: ACPI PHP slot
1830 int acpiphp_disable_slot(struct acpiphp_slot
*slot
)
1834 mutex_lock(&slot
->crit_sect
);
1836 /* unconfigure all functions */
1837 retval
= disable_device(slot
);
1841 /* power off all functions */
1842 retval
= power_off_slot(slot
);
1847 mutex_unlock(&slot
->crit_sect
);
1856 u8
acpiphp_get_power_status(struct acpiphp_slot
*slot
)
1858 return (slot
->flags
& SLOT_POWEREDON
);
1866 u8
acpiphp_get_latch_status(struct acpiphp_slot
*slot
)
1870 sta
= get_slot_status(slot
);
1872 return (sta
& ACPI_STA_SHOW_IN_UI
) ? 0 : 1;
1877 * adapter presence : 1
1880 u8
acpiphp_get_adapter_status(struct acpiphp_slot
*slot
)
1884 sta
= get_slot_status(slot
);
1886 return (sta
== 0) ? 0 : 1;