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:
77 * 2. has _EJ0 method or _RMV method
86 static int is_ejectable(acpi_handle handle
)
90 unsigned long long removable
;
92 status
= acpi_get_handle(handle
, "_ADR", &tmp
);
93 if (ACPI_FAILURE(status
))
96 status
= acpi_get_handle(handle
, "_EJ0", &tmp
);
97 if (ACPI_SUCCESS(status
))
100 status
= acpi_get_handle(handle
, "_RMV", &tmp
);
101 if (ACPI_SUCCESS(status
)) {
102 status
= acpi_evaluate_integer(handle
, "_RMV", NULL
,
104 if (ACPI_SUCCESS(status
) && removable
)
112 /* callback routine to check for the existence of ejectable slots */
114 is_ejectable_slot(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
116 int *count
= (int *)context
;
118 if (is_ejectable(handle
)) {
120 /* only one ejectable slot is enough */
121 return AE_CTRL_TERMINATE
;
127 /* callback routine to check for the existence of a pci dock device */
129 is_pci_dock_device(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
131 int *count
= (int *)context
;
133 if (is_dock_device(handle
)) {
135 return AE_CTRL_TERMINATE
;
145 * the _DCK method can do funny things... and sometimes not
148 * TBD - figure out a way to only call fixups for
149 * systems that require them.
151 static int post_dock_fixups(struct notifier_block
*nb
, unsigned long val
,
154 struct acpiphp_func
*func
= container_of(nb
, struct acpiphp_func
, nb
);
155 struct pci_bus
*bus
= func
->slot
->bridge
->pci_bus
;
161 /* fixup bad _DCK function that rewrites
162 * secondary bridge on slot
164 pci_read_config_dword(bus
->self
,
168 if (((buses
>> 8) & 0xff) != bus
->secondary
) {
169 buses
= (buses
& 0xff000000)
170 | ((unsigned int)(bus
->primary
) << 0)
171 | ((unsigned int)(bus
->secondary
) << 8)
172 | ((unsigned int)(bus
->subordinate
) << 16);
173 pci_write_config_dword(bus
->self
, PCI_PRIMARY_BUS
, buses
);
179 static struct acpi_dock_ops acpiphp_dock_ops
= {
180 .handler
= handle_hotplug_event_func
,
183 /* callback routine to register each ACPI PCI slot object */
185 register_slot(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
187 struct acpiphp_bridge
*bridge
= (struct acpiphp_bridge
*)context
;
188 struct acpiphp_slot
*slot
;
189 struct acpiphp_func
*newfunc
;
191 acpi_status status
= AE_OK
;
192 unsigned long long adr
, sun
;
193 int device
, function
, retval
;
195 if (!is_ejectable(handle
) && !is_dock_device(handle
))
198 acpi_evaluate_integer(handle
, "_ADR", NULL
, &adr
);
199 device
= (adr
>> 16) & 0xffff;
200 function
= adr
& 0xffff;
202 newfunc
= kzalloc(sizeof(struct acpiphp_func
), GFP_KERNEL
);
206 INIT_LIST_HEAD(&newfunc
->sibling
);
207 newfunc
->handle
= handle
;
208 newfunc
->function
= function
;
210 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_EJ0", &tmp
)))
211 newfunc
->flags
= FUNC_HAS_EJ0
;
213 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_STA", &tmp
)))
214 newfunc
->flags
|= FUNC_HAS_STA
;
216 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_PS0", &tmp
)))
217 newfunc
->flags
|= FUNC_HAS_PS0
;
219 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_PS3", &tmp
)))
220 newfunc
->flags
|= FUNC_HAS_PS3
;
222 if (ACPI_SUCCESS(acpi_get_handle(handle
, "_DCK", &tmp
)))
223 newfunc
->flags
|= FUNC_HAS_DCK
;
225 status
= acpi_evaluate_integer(handle
, "_SUN", NULL
, &sun
);
226 if (ACPI_FAILURE(status
)) {
228 * use the count of the number of slots we've found
229 * for the number of the slot
231 sun
= bridge
->nr_slots
+1;
234 /* search for objects that share the same slot */
235 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
)
236 if (slot
->device
== device
) {
237 if (slot
->sun
!= sun
)
238 warn("sibling found, but _SUN doesn't match!\n");
243 slot
= kzalloc(sizeof(struct acpiphp_slot
), GFP_KERNEL
);
249 slot
->bridge
= bridge
;
250 slot
->device
= device
;
252 INIT_LIST_HEAD(&slot
->funcs
);
253 mutex_init(&slot
->crit_sect
);
255 slot
->next
= bridge
->slots
;
256 bridge
->slots
= slot
;
260 dbg("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
261 slot
->sun
, pci_domain_nr(bridge
->pci_bus
),
262 bridge
->pci_bus
->number
, slot
->device
);
263 retval
= acpiphp_register_hotplug_slot(slot
);
265 if (retval
== -EBUSY
)
266 warn("Slot %llu already registered by another "
267 "hotplug driver\n", slot
->sun
);
269 warn("acpiphp_register_hotplug_slot failed "
270 "(err code = 0x%x)\n", retval
);
275 newfunc
->slot
= slot
;
276 list_add_tail(&newfunc
->sibling
, &slot
->funcs
);
278 /* associate corresponding pci_dev */
279 newfunc
->pci_dev
= pci_get_slot(bridge
->pci_bus
,
280 PCI_DEVFN(device
, function
));
281 if (newfunc
->pci_dev
) {
282 slot
->flags
|= (SLOT_ENABLED
| SLOT_POWEREDON
);
285 if (is_dock_device(handle
)) {
286 /* we don't want to call this device's _EJ0
287 * because we want the dock notify handler
288 * to call it after it calls _DCK
290 newfunc
->flags
&= ~FUNC_HAS_EJ0
;
291 if (register_hotplug_dock_device(handle
,
292 &acpiphp_dock_ops
, newfunc
))
293 dbg("failed to register dock device\n");
295 /* we need to be notified when dock events happen
296 * outside of the hotplug operation, since we may
297 * need to do fixups before we can hotplug.
299 newfunc
->nb
.notifier_call
= post_dock_fixups
;
300 if (register_dock_notifier(&newfunc
->nb
))
301 dbg("failed to register a dock notifier");
304 /* install notify handler */
305 if (!(newfunc
->flags
& FUNC_HAS_DCK
)) {
306 status
= acpi_install_notify_handler(handle
,
308 handle_hotplug_event_func
,
311 if (ACPI_FAILURE(status
))
312 err("failed to register interrupt notify handler\n");
320 bridge
->slots
= slot
->next
;
328 /* see if it's worth looking at this bridge */
329 static int detect_ejectable_slots(acpi_handle
*bridge_handle
)
336 /* only check slots defined directly below bridge object */
337 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge_handle
, (u32
)1,
338 is_ejectable_slot
, (void *)&count
, NULL
);
341 * we also need to add this bridge if there is a dock bridge or
342 * other pci device on a dock station (removable)
345 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge_handle
,
346 (u32
)1, is_pci_dock_device
, (void *)&count
,
353 /* decode ACPI 2.0 _HPP hot plug parameters */
354 static void decode_hpp(struct acpiphp_bridge
*bridge
)
358 status
= acpi_get_hp_params_from_firmware(bridge
->pci_bus
, &bridge
->hpp
);
359 if (ACPI_FAILURE(status
) ||
360 !bridge
->hpp
.t0
|| (bridge
->hpp
.t0
->revision
> 1)) {
361 /* use default numbers */
363 "%s: Could not get hotplug parameters. Use defaults\n",
365 bridge
->hpp
.t0
= &bridge
->hpp
.type0_data
;
366 bridge
->hpp
.t0
->revision
= 0;
367 bridge
->hpp
.t0
->cache_line_size
= 0x10;
368 bridge
->hpp
.t0
->latency_timer
= 0x40;
369 bridge
->hpp
.t0
->enable_serr
= 0;
370 bridge
->hpp
.t0
->enable_perr
= 0;
376 /* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */
377 static void init_bridge_misc(struct acpiphp_bridge
*bridge
)
381 /* decode ACPI 2.0 _HPP (hot plug parameters) */
384 /* must be added to the list prior to calling register_slot */
385 list_add(&bridge
->list
, &bridge_list
);
387 /* register all slot objects under this bridge */
388 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge
->handle
, (u32
)1,
389 register_slot
, bridge
, NULL
);
390 if (ACPI_FAILURE(status
)) {
391 list_del(&bridge
->list
);
395 /* install notify handler */
396 if (bridge
->type
!= BRIDGE_TYPE_HOST
) {
397 if ((bridge
->flags
& BRIDGE_HAS_EJ0
) && bridge
->func
) {
398 status
= acpi_remove_notify_handler(bridge
->func
->handle
,
400 handle_hotplug_event_func
);
401 if (ACPI_FAILURE(status
))
402 err("failed to remove notify handler\n");
404 status
= acpi_install_notify_handler(bridge
->handle
,
406 handle_hotplug_event_bridge
,
409 if (ACPI_FAILURE(status
)) {
410 err("failed to register interrupt notify handler\n");
416 /* find acpiphp_func from acpiphp_bridge */
417 static struct acpiphp_func
*acpiphp_bridge_handle_to_function(acpi_handle handle
)
419 struct list_head
*node
, *l
;
420 struct acpiphp_bridge
*bridge
;
421 struct acpiphp_slot
*slot
;
422 struct acpiphp_func
*func
;
424 list_for_each(node
, &bridge_list
) {
425 bridge
= list_entry(node
, struct acpiphp_bridge
, list
);
426 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
427 list_for_each(l
, &slot
->funcs
) {
428 func
= list_entry(l
, struct acpiphp_func
,
430 if (func
->handle
== handle
)
440 static inline void config_p2p_bridge_flags(struct acpiphp_bridge
*bridge
)
442 acpi_handle dummy_handle
;
444 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
445 "_STA", &dummy_handle
)))
446 bridge
->flags
|= BRIDGE_HAS_STA
;
448 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
449 "_EJ0", &dummy_handle
)))
450 bridge
->flags
|= BRIDGE_HAS_EJ0
;
452 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
453 "_PS0", &dummy_handle
)))
454 bridge
->flags
|= BRIDGE_HAS_PS0
;
456 if (ACPI_SUCCESS(acpi_get_handle(bridge
->handle
,
457 "_PS3", &dummy_handle
)))
458 bridge
->flags
|= BRIDGE_HAS_PS3
;
460 /* is this ejectable p2p bridge? */
461 if (bridge
->flags
& BRIDGE_HAS_EJ0
) {
462 struct acpiphp_func
*func
;
464 dbg("found ejectable p2p bridge\n");
466 /* make link between PCI bridge and PCI function */
467 func
= acpiphp_bridge_handle_to_function(bridge
->handle
);
471 func
->bridge
= bridge
;
476 /* allocate and initialize host bridge data structure */
477 static void add_host_bridge(acpi_handle
*handle
, struct pci_bus
*pci_bus
)
479 struct acpiphp_bridge
*bridge
;
481 bridge
= kzalloc(sizeof(struct acpiphp_bridge
), GFP_KERNEL
);
485 bridge
->type
= BRIDGE_TYPE_HOST
;
486 bridge
->handle
= handle
;
488 bridge
->pci_bus
= pci_bus
;
490 spin_lock_init(&bridge
->res_lock
);
492 init_bridge_misc(bridge
);
496 /* allocate and initialize PCI-to-PCI bridge data structure */
497 static void add_p2p_bridge(acpi_handle
*handle
, struct pci_dev
*pci_dev
)
499 struct acpiphp_bridge
*bridge
;
501 bridge
= kzalloc(sizeof(struct acpiphp_bridge
), GFP_KERNEL
);
502 if (bridge
== NULL
) {
503 err("out of memory\n");
507 bridge
->type
= BRIDGE_TYPE_P2P
;
508 bridge
->handle
= handle
;
509 config_p2p_bridge_flags(bridge
);
511 bridge
->pci_dev
= pci_dev_get(pci_dev
);
512 bridge
->pci_bus
= pci_dev
->subordinate
;
513 if (!bridge
->pci_bus
) {
514 err("This is not a PCI-to-PCI bridge!\n");
518 spin_lock_init(&bridge
->res_lock
);
520 init_bridge_misc(bridge
);
523 pci_dev_put(pci_dev
);
529 /* callback routine to find P2P bridges */
531 find_p2p_bridge(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
534 acpi_handle dummy_handle
;
535 unsigned long long tmp
;
536 int device
, function
;
538 struct pci_bus
*pci_bus
= context
;
540 status
= acpi_get_handle(handle
, "_ADR", &dummy_handle
);
541 if (ACPI_FAILURE(status
))
542 return AE_OK
; /* continue */
544 status
= acpi_evaluate_integer(handle
, "_ADR", NULL
, &tmp
);
545 if (ACPI_FAILURE(status
)) {
546 dbg("%s: _ADR evaluation failure\n", __func__
);
550 device
= (tmp
>> 16) & 0xffff;
551 function
= tmp
& 0xffff;
553 dev
= pci_get_slot(pci_bus
, PCI_DEVFN(device
, function
));
555 if (!dev
|| !dev
->subordinate
)
558 /* check if this bridge has ejectable slots */
559 if ((detect_ejectable_slots(handle
) > 0)) {
560 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev
));
561 add_p2p_bridge(handle
, dev
);
564 /* search P2P bridges under this p2p bridge */
565 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
566 find_p2p_bridge
, dev
->subordinate
, NULL
);
567 if (ACPI_FAILURE(status
))
568 warn("find_p2p_bridge failed (error code = 0x%x)\n", status
);
576 /* find hot-pluggable slots, and then find P2P bridge */
577 static int add_bridge(acpi_handle handle
)
580 unsigned long long tmp
;
582 acpi_handle dummy_handle
;
583 struct pci_bus
*pci_bus
;
585 /* if the bridge doesn't have _STA, we assume it is always there */
586 status
= acpi_get_handle(handle
, "_STA", &dummy_handle
);
587 if (ACPI_SUCCESS(status
)) {
588 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &tmp
);
589 if (ACPI_FAILURE(status
)) {
590 dbg("%s: _STA evaluation failure\n", __func__
);
593 if ((tmp
& ACPI_STA_FUNCTIONING
) == 0)
594 /* don't register this object */
598 /* get PCI segment number */
599 status
= acpi_evaluate_integer(handle
, "_SEG", NULL
, &tmp
);
601 seg
= ACPI_SUCCESS(status
) ? tmp
: 0;
603 /* get PCI bus number */
604 status
= acpi_evaluate_integer(handle
, "_BBN", NULL
, &tmp
);
606 if (ACPI_SUCCESS(status
)) {
609 warn("can't get bus number, assuming 0\n");
613 pci_bus
= pci_find_bus(seg
, bus
);
615 err("Can't find bus %04x:%02x\n", seg
, bus
);
619 /* check if this bridge has ejectable slots */
620 if (detect_ejectable_slots(handle
) > 0) {
621 dbg("found PCI host-bus bridge with hot-pluggable slots\n");
622 add_host_bridge(handle
, pci_bus
);
625 /* search P2P bridges under this host bridge */
626 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
627 find_p2p_bridge
, pci_bus
, NULL
);
629 if (ACPI_FAILURE(status
))
630 warn("find_p2p_bridge failed (error code = 0x%x)\n", status
);
635 static struct acpiphp_bridge
*acpiphp_handle_to_bridge(acpi_handle handle
)
637 struct list_head
*head
;
638 list_for_each(head
, &bridge_list
) {
639 struct acpiphp_bridge
*bridge
= list_entry(head
,
640 struct acpiphp_bridge
, list
);
641 if (bridge
->handle
== handle
)
648 static void cleanup_bridge(struct acpiphp_bridge
*bridge
)
650 struct list_head
*list
, *tmp
;
651 struct acpiphp_slot
*slot
;
653 acpi_handle handle
= bridge
->handle
;
655 status
= acpi_remove_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
656 handle_hotplug_event_bridge
);
657 if (ACPI_FAILURE(status
))
658 err("failed to remove notify handler\n");
660 if ((bridge
->type
!= BRIDGE_TYPE_HOST
) &&
661 ((bridge
->flags
& BRIDGE_HAS_EJ0
) && bridge
->func
)) {
662 status
= acpi_install_notify_handler(bridge
->func
->handle
,
664 handle_hotplug_event_func
,
666 if (ACPI_FAILURE(status
))
667 err("failed to install interrupt notify handler\n");
670 slot
= bridge
->slots
;
672 struct acpiphp_slot
*next
= slot
->next
;
673 list_for_each_safe (list
, tmp
, &slot
->funcs
) {
674 struct acpiphp_func
*func
;
675 func
= list_entry(list
, struct acpiphp_func
, sibling
);
676 if (is_dock_device(func
->handle
)) {
677 unregister_hotplug_dock_device(func
->handle
);
678 unregister_dock_notifier(&func
->nb
);
680 if (!(func
->flags
& FUNC_HAS_DCK
)) {
681 status
= acpi_remove_notify_handler(func
->handle
,
683 handle_hotplug_event_func
);
684 if (ACPI_FAILURE(status
))
685 err("failed to remove notify handler\n");
687 pci_dev_put(func
->pci_dev
);
691 acpiphp_unregister_hotplug_slot(slot
);
692 list_del(&slot
->funcs
);
697 pci_dev_put(bridge
->pci_dev
);
698 list_del(&bridge
->list
);
703 cleanup_p2p_bridge(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
705 struct acpiphp_bridge
*bridge
;
707 /* cleanup p2p bridges under this P2P bridge
708 in a depth-first manner */
709 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
710 cleanup_p2p_bridge
, NULL
, NULL
);
712 bridge
= acpiphp_handle_to_bridge(handle
);
714 cleanup_bridge(bridge
);
719 static void remove_bridge(acpi_handle handle
)
721 struct acpiphp_bridge
*bridge
;
723 /* cleanup p2p bridges under this host bridge
724 in a depth-first manner */
725 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
726 (u32
)1, cleanup_p2p_bridge
, NULL
, NULL
);
729 * On root bridges with hotplug slots directly underneath (ie,
730 * no p2p bridge inbetween), we call cleanup_bridge().
732 * The else clause cleans up root bridges that either had no
733 * hotplug slots at all, or had a p2p bridge underneath.
735 bridge
= acpiphp_handle_to_bridge(handle
);
737 cleanup_bridge(bridge
);
739 acpi_remove_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
740 handle_hotplug_event_bridge
);
743 static struct pci_dev
* get_apic_pci_info(acpi_handle handle
)
745 struct acpi_pci_id id
;
749 if (ACPI_FAILURE(acpi_get_pci_id(handle
, &id
)))
752 bus
= pci_find_bus(id
.segment
, id
.bus
);
756 dev
= pci_get_slot(bus
, PCI_DEVFN(id
.device
, id
.function
));
760 if ((dev
->class != PCI_CLASS_SYSTEM_PIC_IOAPIC
) &&
761 (dev
->class != PCI_CLASS_SYSTEM_PIC_IOXAPIC
))
770 static int get_gsi_base(acpi_handle handle
, u32
*gsi_base
)
774 unsigned long long gsb
;
775 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
776 union acpi_object
*obj
;
779 status
= acpi_evaluate_integer(handle
, "_GSB", NULL
, &gsb
);
780 if (ACPI_SUCCESS(status
)) {
781 *gsi_base
= (u32
)gsb
;
785 status
= acpi_evaluate_object(handle
, "_MAT", NULL
, &buffer
);
786 if (ACPI_FAILURE(status
) || !buffer
.length
|| !buffer
.pointer
)
789 obj
= buffer
.pointer
;
790 if (obj
->type
!= ACPI_TYPE_BUFFER
)
793 table
= obj
->buffer
.pointer
;
794 switch (((struct acpi_subtable_header
*)table
)->type
) {
795 case ACPI_MADT_TYPE_IO_SAPIC
:
796 *gsi_base
= ((struct acpi_madt_io_sapic
*)table
)->global_irq_base
;
799 case ACPI_MADT_TYPE_IO_APIC
:
800 *gsi_base
= ((struct acpi_madt_io_apic
*)table
)->global_irq_base
;
807 kfree(buffer
.pointer
);
812 ioapic_add(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
815 unsigned long long sta
;
817 struct pci_dev
*pdev
;
820 struct acpiphp_ioapic
*ioapic
;
822 /* Evaluate _STA if present */
823 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &sta
);
824 if (ACPI_SUCCESS(status
) && sta
!= ACPI_STA_ALL
)
825 return AE_CTRL_DEPTH
;
827 /* Scan only PCI bus scope */
828 status
= acpi_get_handle(handle
, "_HID", &tmp
);
829 if (ACPI_SUCCESS(status
))
830 return AE_CTRL_DEPTH
;
832 if (get_gsi_base(handle
, &gsi_base
))
835 ioapic
= kmalloc(sizeof(*ioapic
), GFP_KERNEL
);
839 pdev
= get_apic_pci_info(handle
);
843 if (pci_enable_device(pdev
))
844 goto exit_pci_dev_put
;
846 pci_set_master(pdev
);
848 if (pci_request_region(pdev
, 0, "I/O APIC(acpiphp)"))
849 goto exit_pci_disable_device
;
851 phys_addr
= pci_resource_start(pdev
, 0);
852 if (acpi_register_ioapic(handle
, phys_addr
, gsi_base
))
853 goto exit_pci_release_region
;
855 ioapic
->gsi_base
= gsi_base
;
857 spin_lock(&ioapic_list_lock
);
858 list_add_tail(&ioapic
->list
, &ioapic_list
);
859 spin_unlock(&ioapic_list_lock
);
863 exit_pci_release_region
:
864 pci_release_region(pdev
, 0);
865 exit_pci_disable_device
:
866 pci_disable_device(pdev
);
876 ioapic_remove(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
879 unsigned long long sta
;
882 struct acpiphp_ioapic
*pos
, *n
, *ioapic
= NULL
;
884 /* Evaluate _STA if present */
885 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &sta
);
886 if (ACPI_SUCCESS(status
) && sta
!= ACPI_STA_ALL
)
887 return AE_CTRL_DEPTH
;
889 /* Scan only PCI bus scope */
890 status
= acpi_get_handle(handle
, "_HID", &tmp
);
891 if (ACPI_SUCCESS(status
))
892 return AE_CTRL_DEPTH
;
894 if (get_gsi_base(handle
, &gsi_base
))
897 acpi_unregister_ioapic(handle
, gsi_base
);
899 spin_lock(&ioapic_list_lock
);
900 list_for_each_entry_safe(pos
, n
, &ioapic_list
, list
) {
901 if (pos
->gsi_base
!= gsi_base
)
904 list_del(&ioapic
->list
);
907 spin_unlock(&ioapic_list_lock
);
912 pci_release_region(ioapic
->dev
, 0);
913 pci_disable_device(ioapic
->dev
);
914 pci_dev_put(ioapic
->dev
);
920 static int acpiphp_configure_ioapics(acpi_handle handle
)
922 ioapic_add(handle
, 0, NULL
, NULL
);
923 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
924 ACPI_UINT32_MAX
, ioapic_add
, NULL
, NULL
);
928 static int acpiphp_unconfigure_ioapics(acpi_handle handle
)
930 ioapic_remove(handle
, 0, NULL
, NULL
);
931 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
932 ACPI_UINT32_MAX
, ioapic_remove
, NULL
, NULL
);
936 static int power_on_slot(struct acpiphp_slot
*slot
)
939 struct acpiphp_func
*func
;
943 /* if already enabled, just skip */
944 if (slot
->flags
& SLOT_POWEREDON
)
947 list_for_each (l
, &slot
->funcs
) {
948 func
= list_entry(l
, struct acpiphp_func
, sibling
);
950 if (func
->flags
& FUNC_HAS_PS0
) {
951 dbg("%s: executing _PS0\n", __func__
);
952 status
= acpi_evaluate_object(func
->handle
, "_PS0", NULL
, NULL
);
953 if (ACPI_FAILURE(status
)) {
954 warn("%s: _PS0 failed\n", __func__
);
962 /* TBD: evaluate _STA to check if the slot is enabled */
964 slot
->flags
|= SLOT_POWEREDON
;
971 static int power_off_slot(struct acpiphp_slot
*slot
)
974 struct acpiphp_func
*func
;
979 /* if already disabled, just skip */
980 if ((slot
->flags
& SLOT_POWEREDON
) == 0)
983 list_for_each (l
, &slot
->funcs
) {
984 func
= list_entry(l
, struct acpiphp_func
, sibling
);
986 if (func
->flags
& FUNC_HAS_PS3
) {
987 status
= acpi_evaluate_object(func
->handle
, "_PS3", NULL
, NULL
);
988 if (ACPI_FAILURE(status
)) {
989 warn("%s: _PS3 failed\n", __func__
);
997 /* TBD: evaluate _STA to check if the slot is disabled */
999 slot
->flags
&= (~SLOT_POWEREDON
);
1008 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
1009 * @bus: bus to start search with
1011 static unsigned char acpiphp_max_busnr(struct pci_bus
*bus
)
1013 struct list_head
*tmp
;
1014 unsigned char max
, n
;
1017 * pci_bus_max_busnr will return the highest
1018 * reserved busnr for all these children.
1019 * that is equivalent to the bus->subordinate
1020 * value. We don't want to use the parent's
1021 * bus->subordinate value because it could have
1024 max
= bus
->secondary
;
1026 list_for_each(tmp
, &bus
->children
) {
1027 n
= pci_bus_max_busnr(pci_bus_b(tmp
));
1036 * acpiphp_bus_add - add a new bus to acpi subsystem
1037 * @func: acpiphp_func of the bridge
1039 static int acpiphp_bus_add(struct acpiphp_func
*func
)
1041 acpi_handle phandle
;
1042 struct acpi_device
*device
, *pdevice
;
1045 acpi_get_parent(func
->handle
, &phandle
);
1046 if (acpi_bus_get_device(phandle
, &pdevice
)) {
1047 dbg("no parent device, assuming NULL\n");
1050 if (!acpi_bus_get_device(func
->handle
, &device
)) {
1051 dbg("bus exists... trim\n");
1052 /* this shouldn't be in here, so remove
1053 * the bus then re-add it...
1055 ret_val
= acpi_bus_trim(device
, 1);
1056 dbg("acpi_bus_trim return %x\n", ret_val
);
1059 ret_val
= acpi_bus_add(&device
, pdevice
, func
->handle
,
1060 ACPI_BUS_TYPE_DEVICE
);
1062 dbg("error adding bus, %x\n",
1064 goto acpiphp_bus_add_out
;
1067 * try to start anyway. We could have failed to add
1068 * simply because this bus had previously been added
1069 * on another add. Don't bother with the return value
1070 * we just keep going.
1072 ret_val
= acpi_bus_start(device
);
1074 acpiphp_bus_add_out
:
1080 * acpiphp_bus_trim - trim a bus from acpi subsystem
1081 * @handle: handle to acpi namespace
1083 static int acpiphp_bus_trim(acpi_handle handle
)
1085 struct acpi_device
*device
;
1088 retval
= acpi_bus_get_device(handle
, &device
);
1090 dbg("acpi_device not found\n");
1094 retval
= acpi_bus_trim(device
, 1);
1096 err("cannot remove from acpi list\n");
1102 * enable_device - enable, configure a slot
1103 * @slot: slot to be enabled
1105 * This function should be called per *physical slot*,
1106 * not per each slot object in ACPI namespace.
1108 static int __ref
enable_device(struct acpiphp_slot
*slot
)
1110 struct pci_dev
*dev
;
1111 struct pci_bus
*bus
= slot
->bridge
->pci_bus
;
1112 struct list_head
*l
;
1113 struct acpiphp_func
*func
;
1118 if (slot
->flags
& SLOT_ENABLED
)
1121 /* sanity check: dev should be NULL when hot-plugged in */
1122 dev
= pci_get_slot(bus
, PCI_DEVFN(slot
->device
, 0));
1124 /* This case shouldn't happen */
1125 err("pci_dev structure already exists.\n");
1131 num
= pci_scan_slot(bus
, PCI_DEVFN(slot
->device
, 0));
1133 err("No new device found\n");
1138 max
= acpiphp_max_busnr(bus
);
1139 for (pass
= 0; pass
< 2; pass
++) {
1140 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1141 if (PCI_SLOT(dev
->devfn
) != slot
->device
)
1143 if (dev
->hdr_type
== PCI_HEADER_TYPE_BRIDGE
||
1144 dev
->hdr_type
== PCI_HEADER_TYPE_CARDBUS
) {
1145 max
= pci_scan_bridge(bus
, dev
, max
, pass
);
1146 if (pass
&& dev
->subordinate
)
1147 pci_bus_size_bridges(dev
->subordinate
);
1152 list_for_each (l
, &slot
->funcs
) {
1153 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1154 acpiphp_bus_add(func
);
1157 pci_bus_assign_resources(bus
);
1158 acpiphp_sanitize_bus(bus
);
1159 acpiphp_set_hpp_values(slot
->bridge
->handle
, bus
);
1160 list_for_each_entry(func
, &slot
->funcs
, sibling
)
1161 acpiphp_configure_ioapics(func
->handle
);
1162 pci_enable_bridges(bus
);
1163 pci_bus_add_devices(bus
);
1165 /* associate pci_dev to our representation */
1166 list_for_each (l
, &slot
->funcs
) {
1167 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1168 func
->pci_dev
= pci_get_slot(bus
, PCI_DEVFN(slot
->device
,
1173 if (func
->pci_dev
->hdr_type
!= PCI_HEADER_TYPE_BRIDGE
&&
1174 func
->pci_dev
->hdr_type
!= PCI_HEADER_TYPE_CARDBUS
)
1177 status
= find_p2p_bridge(func
->handle
, (u32
)1, bus
, NULL
);
1178 if (ACPI_FAILURE(status
))
1179 warn("find_p2p_bridge failed (error code = 0x%x)\n",
1183 slot
->flags
|= SLOT_ENABLED
;
1189 static void disable_bridges(struct pci_bus
*bus
)
1191 struct pci_dev
*dev
;
1192 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1193 if (dev
->subordinate
) {
1194 disable_bridges(dev
->subordinate
);
1195 pci_disable_device(dev
);
1201 * disable_device - disable a slot
1202 * @slot: ACPI PHP slot
1204 static int disable_device(struct acpiphp_slot
*slot
)
1207 struct acpiphp_func
*func
;
1208 struct list_head
*l
;
1210 /* is this slot already disabled? */
1211 if (!(slot
->flags
& SLOT_ENABLED
))
1214 list_for_each (l
, &slot
->funcs
) {
1215 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1218 /* cleanup p2p bridges under this P2P bridge */
1219 cleanup_p2p_bridge(func
->bridge
->handle
,
1220 (u32
)1, NULL
, NULL
);
1221 func
->bridge
= NULL
;
1224 if (func
->pci_dev
) {
1225 pci_stop_bus_device(func
->pci_dev
);
1226 if (func
->pci_dev
->subordinate
) {
1227 disable_bridges(func
->pci_dev
->subordinate
);
1228 pci_disable_device(func
->pci_dev
);
1233 list_for_each (l
, &slot
->funcs
) {
1234 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1236 acpiphp_unconfigure_ioapics(func
->handle
);
1237 acpiphp_bus_trim(func
->handle
);
1238 /* try to remove anyway.
1239 * acpiphp_bus_add might have been failed */
1244 pci_remove_bus_device(func
->pci_dev
);
1245 pci_dev_put(func
->pci_dev
);
1246 func
->pci_dev
= NULL
;
1249 slot
->flags
&= (~SLOT_ENABLED
);
1257 * get_slot_status - get ACPI slot status
1258 * @slot: ACPI PHP slot
1260 * If a slot has _STA for each function and if any one of them
1261 * returned non-zero status, return it.
1263 * If a slot doesn't have _STA and if any one of its functions'
1264 * configuration space is configured, return 0x0f as a _STA.
1266 * Otherwise return 0.
1268 static unsigned int get_slot_status(struct acpiphp_slot
*slot
)
1271 unsigned long long sta
= 0;
1273 struct list_head
*l
;
1274 struct acpiphp_func
*func
;
1276 list_for_each (l
, &slot
->funcs
) {
1277 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1279 if (func
->flags
& FUNC_HAS_STA
) {
1280 status
= acpi_evaluate_integer(func
->handle
, "_STA", NULL
, &sta
);
1281 if (ACPI_SUCCESS(status
) && sta
)
1284 pci_bus_read_config_dword(slot
->bridge
->pci_bus
,
1285 PCI_DEVFN(slot
->device
,
1287 PCI_VENDOR_ID
, &dvid
);
1288 if (dvid
!= 0xffffffff) {
1295 return (unsigned int)sta
;
1299 * acpiphp_eject_slot - physically eject the slot
1300 * @slot: ACPI PHP slot
1302 int acpiphp_eject_slot(struct acpiphp_slot
*slot
)
1305 struct acpiphp_func
*func
;
1306 struct list_head
*l
;
1307 struct acpi_object_list arg_list
;
1308 union acpi_object arg
;
1310 list_for_each (l
, &slot
->funcs
) {
1311 func
= list_entry(l
, struct acpiphp_func
, sibling
);
1313 /* We don't want to call _EJ0 on non-existing functions. */
1314 if ((func
->flags
& FUNC_HAS_EJ0
)) {
1315 /* _EJ0 method take one argument */
1317 arg_list
.pointer
= &arg
;
1318 arg
.type
= ACPI_TYPE_INTEGER
;
1319 arg
.integer
.value
= 1;
1321 status
= acpi_evaluate_object(func
->handle
, "_EJ0", &arg_list
, NULL
);
1322 if (ACPI_FAILURE(status
)) {
1323 warn("%s: _EJ0 failed\n", __func__
);
1333 * acpiphp_check_bridge - re-enumerate devices
1334 * @bridge: where to begin re-enumeration
1336 * Iterate over all slots under this bridge and make sure that if a
1337 * card is present they are enabled, and if not they are disabled.
1339 static int acpiphp_check_bridge(struct acpiphp_bridge
*bridge
)
1341 struct acpiphp_slot
*slot
;
1343 int enabled
, disabled
;
1345 enabled
= disabled
= 0;
1347 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
1348 unsigned int status
= get_slot_status(slot
);
1349 if (slot
->flags
& SLOT_ENABLED
) {
1350 if (status
== ACPI_STA_ALL
)
1352 retval
= acpiphp_disable_slot(slot
);
1354 err("Error occurred in disabling\n");
1357 acpiphp_eject_slot(slot
);
1361 if (status
!= ACPI_STA_ALL
)
1363 retval
= acpiphp_enable_slot(slot
);
1365 err("Error occurred in enabling\n");
1372 dbg("%s: %d enabled, %d disabled\n", __func__
, enabled
, disabled
);
1378 static void program_hpp(struct pci_dev
*dev
, struct acpiphp_bridge
*bridge
)
1380 u16 pci_cmd
, pci_bctl
;
1381 struct pci_dev
*cdev
;
1383 /* Program hpp values for this device */
1384 if (!(dev
->hdr_type
== PCI_HEADER_TYPE_NORMAL
||
1385 (dev
->hdr_type
== PCI_HEADER_TYPE_BRIDGE
&&
1386 (dev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
)))
1389 if ((dev
->class >> 8) == PCI_CLASS_BRIDGE_HOST
)
1392 pci_write_config_byte(dev
, PCI_CACHE_LINE_SIZE
,
1393 bridge
->hpp
.t0
->cache_line_size
);
1394 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
,
1395 bridge
->hpp
.t0
->latency_timer
);
1396 pci_read_config_word(dev
, PCI_COMMAND
, &pci_cmd
);
1397 if (bridge
->hpp
.t0
->enable_serr
)
1398 pci_cmd
|= PCI_COMMAND_SERR
;
1400 pci_cmd
&= ~PCI_COMMAND_SERR
;
1401 if (bridge
->hpp
.t0
->enable_perr
)
1402 pci_cmd
|= PCI_COMMAND_PARITY
;
1404 pci_cmd
&= ~PCI_COMMAND_PARITY
;
1405 pci_write_config_word(dev
, PCI_COMMAND
, pci_cmd
);
1407 /* Program bridge control value and child devices */
1408 if ((dev
->class >> 8) == PCI_CLASS_BRIDGE_PCI
) {
1409 pci_write_config_byte(dev
, PCI_SEC_LATENCY_TIMER
,
1410 bridge
->hpp
.t0
->latency_timer
);
1411 pci_read_config_word(dev
, PCI_BRIDGE_CONTROL
, &pci_bctl
);
1412 if (bridge
->hpp
.t0
->enable_serr
)
1413 pci_bctl
|= PCI_BRIDGE_CTL_SERR
;
1415 pci_bctl
&= ~PCI_BRIDGE_CTL_SERR
;
1416 if (bridge
->hpp
.t0
->enable_perr
)
1417 pci_bctl
|= PCI_BRIDGE_CTL_PARITY
;
1419 pci_bctl
&= ~PCI_BRIDGE_CTL_PARITY
;
1420 pci_write_config_word(dev
, PCI_BRIDGE_CONTROL
, pci_bctl
);
1421 if (dev
->subordinate
) {
1422 list_for_each_entry(cdev
, &dev
->subordinate
->devices
,
1424 program_hpp(cdev
, bridge
);
1429 static void acpiphp_set_hpp_values(acpi_handle handle
, struct pci_bus
*bus
)
1431 struct acpiphp_bridge bridge
;
1432 struct pci_dev
*dev
;
1434 memset(&bridge
, 0, sizeof(bridge
));
1435 bridge
.handle
= handle
;
1436 bridge
.pci_bus
= bus
;
1437 bridge
.pci_dev
= bus
->self
;
1438 decode_hpp(&bridge
);
1439 list_for_each_entry(dev
, &bus
->devices
, bus_list
)
1440 program_hpp(dev
, &bridge
);
1445 * Remove devices for which we could not assign resources, call
1446 * arch specific code to fix-up the bus
1448 static void acpiphp_sanitize_bus(struct pci_bus
*bus
)
1450 struct pci_dev
*dev
;
1452 unsigned long type_mask
= IORESOURCE_IO
| IORESOURCE_MEM
;
1454 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
1455 for (i
=0; i
<PCI_BRIDGE_RESOURCES
; i
++) {
1456 struct resource
*res
= &dev
->resource
[i
];
1457 if ((res
->flags
& type_mask
) && !res
->start
&&
1459 /* Could not assign a required resources
1460 * for this device, remove it */
1461 pci_remove_bus_device(dev
);
1468 /* Program resources in newly inserted bridge */
1469 static int acpiphp_configure_bridge (acpi_handle handle
)
1471 struct acpi_pci_id pci_id
;
1472 struct pci_bus
*bus
;
1474 if (ACPI_FAILURE(acpi_get_pci_id(handle
, &pci_id
))) {
1475 err("cannot get PCI domain and bus number for bridge\n");
1478 bus
= pci_find_bus(pci_id
.segment
, pci_id
.bus
);
1480 err("cannot find bus %d:%d\n",
1481 pci_id
.segment
, pci_id
.bus
);
1485 pci_bus_size_bridges(bus
);
1486 pci_bus_assign_resources(bus
);
1487 acpiphp_sanitize_bus(bus
);
1488 acpiphp_set_hpp_values(handle
, bus
);
1489 pci_enable_bridges(bus
);
1490 acpiphp_configure_ioapics(handle
);
1494 static void handle_bridge_insertion(acpi_handle handle
, u32 type
)
1496 struct acpi_device
*device
, *pdevice
;
1497 acpi_handle phandle
;
1499 if ((type
!= ACPI_NOTIFY_BUS_CHECK
) &&
1500 (type
!= ACPI_NOTIFY_DEVICE_CHECK
)) {
1501 err("unexpected notification type %d\n", type
);
1505 acpi_get_parent(handle
, &phandle
);
1506 if (acpi_bus_get_device(phandle
, &pdevice
)) {
1507 dbg("no parent device, assuming NULL\n");
1510 if (acpi_bus_add(&device
, pdevice
, handle
, ACPI_BUS_TYPE_DEVICE
)) {
1511 err("cannot add bridge to acpi list\n");
1514 if (!acpiphp_configure_bridge(handle
) &&
1515 !acpi_bus_start(device
))
1518 err("cannot configure and start bridge\n");
1523 * ACPI event handlers
1527 count_sub_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1529 int *count
= (int *)context
;
1530 struct acpiphp_bridge
*bridge
;
1532 bridge
= acpiphp_handle_to_bridge(handle
);
1539 check_sub_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1541 struct acpiphp_bridge
*bridge
;
1543 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1544 .pointer
= objname
};
1546 bridge
= acpiphp_handle_to_bridge(handle
);
1548 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1549 dbg("%s: re-enumerating slots under %s\n",
1551 acpiphp_check_bridge(bridge
);
1557 * handle_hotplug_event_bridge - handle ACPI event on bridges
1558 * @handle: Notify()'ed acpi_handle
1559 * @type: Notify code
1560 * @context: pointer to acpiphp_bridge structure
1562 * Handles ACPI event notification on {host,p2p} bridges.
1564 static void handle_hotplug_event_bridge(acpi_handle handle
, u32 type
, void *context
)
1566 struct acpiphp_bridge
*bridge
;
1568 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1569 .pointer
= objname
};
1570 struct acpi_device
*device
;
1571 int num_sub_bridges
= 0;
1573 if (acpi_bus_get_device(handle
, &device
)) {
1574 /* This bridge must have just been physically inserted */
1575 handle_bridge_insertion(handle
, type
);
1579 bridge
= acpiphp_handle_to_bridge(handle
);
1580 if (type
== ACPI_NOTIFY_BUS_CHECK
) {
1581 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, ACPI_UINT32_MAX
,
1582 count_sub_bridges
, &num_sub_bridges
, NULL
);
1585 if (!bridge
&& !num_sub_bridges
) {
1586 err("cannot get bridge info\n");
1590 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1593 case ACPI_NOTIFY_BUS_CHECK
:
1594 /* bus re-enumerate */
1595 dbg("%s: Bus check notify on %s\n", __func__
, objname
);
1597 dbg("%s: re-enumerating slots under %s\n",
1599 acpiphp_check_bridge(bridge
);
1601 if (num_sub_bridges
)
1602 acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
,
1603 ACPI_UINT32_MAX
, check_sub_bridges
, NULL
, NULL
);
1606 case ACPI_NOTIFY_DEVICE_CHECK
:
1608 dbg("%s: Device check notify on %s\n", __func__
, objname
);
1609 acpiphp_check_bridge(bridge
);
1612 case ACPI_NOTIFY_DEVICE_WAKE
:
1614 dbg("%s: Device wake notify on %s\n", __func__
, objname
);
1617 case ACPI_NOTIFY_EJECT_REQUEST
:
1618 /* request device eject */
1619 dbg("%s: Device eject notify on %s\n", __func__
, objname
);
1620 if ((bridge
->type
!= BRIDGE_TYPE_HOST
) &&
1621 (bridge
->flags
& BRIDGE_HAS_EJ0
)) {
1622 struct acpiphp_slot
*slot
;
1623 slot
= bridge
->func
->slot
;
1624 if (!acpiphp_disable_slot(slot
))
1625 acpiphp_eject_slot(slot
);
1629 case ACPI_NOTIFY_FREQUENCY_MISMATCH
:
1630 printk(KERN_ERR
"Device %s cannot be configured due"
1631 " to a frequency mismatch\n", objname
);
1634 case ACPI_NOTIFY_BUS_MODE_MISMATCH
:
1635 printk(KERN_ERR
"Device %s cannot be configured due"
1636 " to a bus mode mismatch\n", objname
);
1639 case ACPI_NOTIFY_POWER_FAULT
:
1640 printk(KERN_ERR
"Device %s has suffered a power fault\n",
1645 warn("notify_handler: unknown event type 0x%x for %s\n", type
, objname
);
1651 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
1652 * @handle: Notify()'ed acpi_handle
1653 * @type: Notify code
1654 * @context: pointer to acpiphp_func structure
1656 * Handles ACPI event notification on slots.
1658 static void handle_hotplug_event_func(acpi_handle handle
, u32 type
, void *context
)
1660 struct acpiphp_func
*func
;
1662 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
1663 .pointer
= objname
};
1665 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1667 func
= (struct acpiphp_func
*)context
;
1670 case ACPI_NOTIFY_BUS_CHECK
:
1671 /* bus re-enumerate */
1672 dbg("%s: Bus check notify on %s\n", __func__
, objname
);
1673 acpiphp_enable_slot(func
->slot
);
1676 case ACPI_NOTIFY_DEVICE_CHECK
:
1677 /* device check : re-enumerate from parent bus */
1678 dbg("%s: Device check notify on %s\n", __func__
, objname
);
1679 acpiphp_check_bridge(func
->slot
->bridge
);
1682 case ACPI_NOTIFY_DEVICE_WAKE
:
1684 dbg("%s: Device wake notify on %s\n", __func__
, objname
);
1687 case ACPI_NOTIFY_EJECT_REQUEST
:
1688 /* request device eject */
1689 dbg("%s: Device eject notify on %s\n", __func__
, objname
);
1690 if (!(acpiphp_disable_slot(func
->slot
)))
1691 acpiphp_eject_slot(func
->slot
);
1695 warn("notify_handler: unknown event type 0x%x for %s\n", type
, objname
);
1702 find_root_bridges(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1704 int *count
= (int *)context
;
1706 if (acpi_root_bridge(handle
)) {
1707 acpi_install_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
1708 handle_hotplug_event_bridge
, NULL
);
1714 static struct acpi_pci_driver acpi_pci_hp_driver
= {
1716 .remove
= remove_bridge
,
1720 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
1722 int __init
acpiphp_glue_init(void)
1726 acpi_walk_namespace(ACPI_TYPE_DEVICE
, ACPI_ROOT_OBJECT
,
1727 ACPI_UINT32_MAX
, find_root_bridges
, &num
, NULL
);
1732 acpi_pci_register_driver(&acpi_pci_hp_driver
);
1739 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures
1741 * This function frees all data allocated in acpiphp_glue_init().
1743 void acpiphp_glue_exit(void)
1745 acpi_pci_unregister_driver(&acpi_pci_hp_driver
);
1750 * acpiphp_get_num_slots - count number of slots in a system
1752 int __init
acpiphp_get_num_slots(void)
1754 struct acpiphp_bridge
*bridge
;
1757 list_for_each_entry (bridge
, &bridge_list
, list
) {
1758 dbg("Bus %04x:%02x has %d slot%s\n",
1759 pci_domain_nr(bridge
->pci_bus
),
1760 bridge
->pci_bus
->number
, bridge
->nr_slots
,
1761 bridge
->nr_slots
== 1 ? "" : "s");
1762 num_slots
+= bridge
->nr_slots
;
1765 dbg("Total %d slots\n", num_slots
);
1772 * acpiphp_for_each_slot - call function for each slot
1773 * @fn: callback function
1774 * @data: context to be passed to callback function
1776 static int acpiphp_for_each_slot(acpiphp_callback fn
, void *data
)
1778 struct list_head
*node
;
1779 struct acpiphp_bridge
*bridge
;
1780 struct acpiphp_slot
*slot
;
1783 list_for_each (node
, &bridge_list
) {
1784 bridge
= (struct acpiphp_bridge
*)node
;
1785 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
1786 retval
= fn(slot
, data
);
1799 * acpiphp_enable_slot - power on slot
1800 * @slot: ACPI PHP slot
1802 int acpiphp_enable_slot(struct acpiphp_slot
*slot
)
1806 mutex_lock(&slot
->crit_sect
);
1808 /* wake up all functions */
1809 retval
= power_on_slot(slot
);
1813 if (get_slot_status(slot
) == ACPI_STA_ALL
) {
1814 /* configure all functions */
1815 retval
= enable_device(slot
);
1817 power_off_slot(slot
);
1819 dbg("%s: Slot status is not ACPI_STA_ALL\n", __func__
);
1820 power_off_slot(slot
);
1824 mutex_unlock(&slot
->crit_sect
);
1829 * acpiphp_disable_slot - power off slot
1830 * @slot: ACPI PHP slot
1832 int acpiphp_disable_slot(struct acpiphp_slot
*slot
)
1836 mutex_lock(&slot
->crit_sect
);
1838 /* unconfigure all functions */
1839 retval
= disable_device(slot
);
1843 /* power off all functions */
1844 retval
= power_off_slot(slot
);
1849 mutex_unlock(&slot
->crit_sect
);
1858 u8
acpiphp_get_power_status(struct acpiphp_slot
*slot
)
1860 return (slot
->flags
& SLOT_POWEREDON
);
1868 u8
acpiphp_get_latch_status(struct acpiphp_slot
*slot
)
1872 sta
= get_slot_status(slot
);
1874 return (sta
& ACPI_STA_SHOW_IN_UI
) ? 0 : 1;
1879 * adapter presence : 1
1882 u8
acpiphp_get_adapter_status(struct acpiphp_slot
*slot
)
1886 sta
= get_slot_status(slot
);
1888 return (sta
== 0) ? 0 : 1;