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
10 * All rights reserved.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
20 * NON INFRINGEMENT. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * Send feedback to <t-kochi@bq.jp.nec.com>
32 * Lifetime rules for pci_dev:
33 * - The one in acpiphp_func has its refcount elevated by pci_get_slot()
34 * when the driver is loaded or when an insertion event occurs. It loses
35 * a refcount when its ejected or the driver unloads.
36 * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot()
37 * when the bridge is scanned and it loses a refcount when the bridge
41 #include <linux/init.h>
42 #include <linux/module.h>
44 #include <linux/kernel.h>
45 #include <linux/pci.h>
46 #include <linux/smp_lock.h>
47 #include <asm/semaphore.h>
50 #include "pci_hotplug.h"
53 static LIST_HEAD(bridge_list
);
55 #define MY_NAME "acpiphp_glue"
57 static void handle_hotplug_event_bridge (acpi_handle
, u32
, void *);
58 static void handle_hotplug_event_func (acpi_handle
, u32
, void *);
61 * initialization & terminatation routines
65 * is_ejectable - determine if a slot is ejectable
66 * @handle: handle to acpi namespace
68 * Ejectable slot should satisfy at least these conditions:
81 static int is_ejectable(acpi_handle handle
)
86 status
= acpi_get_handle(handle
, "_ADR", &tmp
);
87 if (ACPI_FAILURE(status
)) {
91 status
= acpi_get_handle(handle
, "_EJ0", &tmp
);
92 if (ACPI_FAILURE(status
)) {
100 /* callback routine to check the existence of ejectable slots */
102 is_ejectable_slot(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
104 int *count
= (int *)context
;
106 if (is_ejectable(handle
)) {
108 /* only one ejectable slot is enough */
109 return AE_CTRL_TERMINATE
;
116 /* callback routine to register each ACPI PCI slot object */
118 register_slot(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
120 struct acpiphp_bridge
*bridge
= (struct acpiphp_bridge
*)context
;
121 struct acpiphp_slot
*slot
;
122 struct acpiphp_func
*newfunc
;
124 acpi_status status
= AE_OK
;
125 unsigned long adr
, sun
;
126 int device
, function
;
127 static int num_slots
= 0; /* XXX if we support I/O node hotplug... */
129 status
= acpi_evaluate_integer(handle
, "_ADR", NULL
, &adr
);
131 if (ACPI_FAILURE(status
))
134 status
= acpi_get_handle(handle
, "_EJ0", &tmp
);
136 if (ACPI_FAILURE(status
))
139 device
= (adr
>> 16) & 0xffff;
140 function
= adr
& 0xffff;
142 newfunc
= kmalloc(sizeof(struct acpiphp_func
), GFP_KERNEL
);
145 memset(newfunc
, 0, sizeof(struct acpiphp_func
));
147 INIT_LIST_HEAD(&newfunc
->sibling
);
148 newfunc
->handle
= handle
;
149 newfunc
->function
= function
;
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 status
= acpi_evaluate_integer(handle
, "_SUN", NULL
, &sun
);
162 if (ACPI_FAILURE(status
))
165 /* search for objects that share the same slot */
166 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
)
167 if (slot
->device
== device
) {
168 if (slot
->sun
!= sun
)
169 warn("sibling found, but _SUN doesn't match!\n");
174 slot
= kmalloc(sizeof(struct acpiphp_slot
), GFP_KERNEL
);
180 memset(slot
, 0, sizeof(struct acpiphp_slot
));
181 slot
->bridge
= bridge
;
182 slot
->id
= num_slots
++;
183 slot
->device
= device
;
185 INIT_LIST_HEAD(&slot
->funcs
);
186 init_MUTEX(&slot
->crit_sect
);
188 slot
->next
= bridge
->slots
;
189 bridge
->slots
= slot
;
193 dbg("found ACPI PCI Hotplug slot %d at PCI %04x:%02x:%02x\n",
194 slot
->sun
, pci_domain_nr(bridge
->pci_bus
),
195 bridge
->pci_bus
->number
, slot
->device
);
198 newfunc
->slot
= slot
;
199 list_add_tail(&newfunc
->sibling
, &slot
->funcs
);
201 /* associate corresponding pci_dev */
202 newfunc
->pci_dev
= pci_get_slot(bridge
->pci_bus
,
203 PCI_DEVFN(device
, function
));
204 if (newfunc
->pci_dev
) {
205 slot
->flags
|= (SLOT_ENABLED
| SLOT_POWEREDON
);
208 /* install notify handler */
209 status
= acpi_install_notify_handler(handle
,
211 handle_hotplug_event_func
,
214 if (ACPI_FAILURE(status
)) {
215 err("failed to register interrupt notify handler\n");
223 /* see if it's worth looking at this bridge */
224 static int detect_ejectable_slots(acpi_handle
*bridge_handle
)
231 /* only check slots defined directly below bridge object */
232 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge_handle
, (u32
)1,
233 is_ejectable_slot
, (void *)&count
, NULL
);
239 /* decode ACPI 2.0 _HPP hot plug parameters */
240 static void decode_hpp(struct acpiphp_bridge
*bridge
)
243 struct acpi_buffer buffer
= { .length
= ACPI_ALLOCATE_BUFFER
,
245 union acpi_object
*package
;
248 /* default numbers */
249 bridge
->hpp
.cache_line_size
= 0x10;
250 bridge
->hpp
.latency_timer
= 0x40;
251 bridge
->hpp
.enable_SERR
= 0;
252 bridge
->hpp
.enable_PERR
= 0;
254 status
= acpi_evaluate_object(bridge
->handle
, "_HPP", NULL
, &buffer
);
256 if (ACPI_FAILURE(status
)) {
257 dbg("_HPP evaluation failed\n");
261 package
= (union acpi_object
*) buffer
.pointer
;
263 if (!package
|| package
->type
!= ACPI_TYPE_PACKAGE
||
264 package
->package
.count
!= 4 || !package
->package
.elements
) {
265 err("invalid _HPP object; ignoring\n");
269 for (i
= 0; i
< 4; i
++) {
270 if (package
->package
.elements
[i
].type
!= ACPI_TYPE_INTEGER
) {
271 err("invalid _HPP parameter type; ignoring\n");
276 bridge
->hpp
.cache_line_size
= package
->package
.elements
[0].integer
.value
;
277 bridge
->hpp
.latency_timer
= package
->package
.elements
[1].integer
.value
;
278 bridge
->hpp
.enable_SERR
= package
->package
.elements
[2].integer
.value
;
279 bridge
->hpp
.enable_PERR
= package
->package
.elements
[3].integer
.value
;
281 dbg("_HPP parameter = (%02x, %02x, %02x, %02x)\n",
282 bridge
->hpp
.cache_line_size
,
283 bridge
->hpp
.latency_timer
,
284 bridge
->hpp
.enable_SERR
,
285 bridge
->hpp
.enable_PERR
);
287 bridge
->flags
|= BRIDGE_HAS_HPP
;
290 kfree(buffer
.pointer
);
294 /* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */
295 static void init_bridge_misc(struct acpiphp_bridge
*bridge
)
299 /* decode ACPI 2.0 _HPP (hot plug parameters) */
302 /* register all slot objects under this bridge */
303 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, bridge
->handle
, (u32
)1,
304 register_slot
, bridge
, NULL
);
306 /* install notify handler */
307 status
= acpi_install_notify_handler(bridge
->handle
,
309 handle_hotplug_event_bridge
,
312 if (ACPI_FAILURE(status
)) {
313 err("failed to register interrupt notify handler\n");
316 list_add(&bridge
->list
, &bridge_list
);
320 /* allocate and initialize host bridge data structure */
321 static void add_host_bridge(acpi_handle
*handle
, struct pci_bus
*pci_bus
)
323 struct acpiphp_bridge
*bridge
;
325 bridge
= kmalloc(sizeof(struct acpiphp_bridge
), GFP_KERNEL
);
329 memset(bridge
, 0, sizeof(struct acpiphp_bridge
));
331 bridge
->type
= BRIDGE_TYPE_HOST
;
332 bridge
->handle
= handle
;
334 bridge
->pci_bus
= pci_bus
;
336 spin_lock_init(&bridge
->res_lock
);
338 init_bridge_misc(bridge
);
342 /* allocate and initialize PCI-to-PCI bridge data structure */
343 static void add_p2p_bridge(acpi_handle
*handle
, struct pci_dev
*pci_dev
)
345 struct acpiphp_bridge
*bridge
;
347 bridge
= kmalloc(sizeof(struct acpiphp_bridge
), GFP_KERNEL
);
348 if (bridge
== NULL
) {
349 err("out of memory\n");
353 memset(bridge
, 0, sizeof(struct acpiphp_bridge
));
355 bridge
->type
= BRIDGE_TYPE_P2P
;
356 bridge
->handle
= handle
;
358 bridge
->pci_dev
= pci_dev_get(pci_dev
);
359 bridge
->pci_bus
= pci_dev
->subordinate
;
360 if (!bridge
->pci_bus
) {
361 err("This is not a PCI-to-PCI bridge!\n");
365 spin_lock_init(&bridge
->res_lock
);
367 init_bridge_misc(bridge
);
370 pci_dev_put(pci_dev
);
376 /* callback routine to find P2P bridges */
378 find_p2p_bridge(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
381 acpi_handle dummy_handle
;
383 int device
, function
;
385 struct pci_bus
*pci_bus
= context
;
387 status
= acpi_get_handle(handle
, "_ADR", &dummy_handle
);
388 if (ACPI_FAILURE(status
))
389 return AE_OK
; /* continue */
391 status
= acpi_evaluate_integer(handle
, "_ADR", NULL
, &tmp
);
392 if (ACPI_FAILURE(status
)) {
393 dbg("%s: _ADR evaluation failure\n", __FUNCTION__
);
397 device
= (tmp
>> 16) & 0xffff;
398 function
= tmp
& 0xffff;
400 dev
= pci_get_slot(pci_bus
, PCI_DEVFN(device
, function
));
402 if (!dev
|| !dev
->subordinate
)
405 /* check if this bridge has ejectable slots */
406 if (detect_ejectable_slots(handle
) > 0) {
407 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev
));
408 add_p2p_bridge(handle
, dev
);
417 /* find hot-pluggable slots, and then find P2P bridge */
418 static int add_bridge(acpi_handle handle
)
423 acpi_handle dummy_handle
;
424 struct pci_bus
*pci_bus
;
426 /* if the bridge doesn't have _STA, we assume it is always there */
427 status
= acpi_get_handle(handle
, "_STA", &dummy_handle
);
428 if (ACPI_SUCCESS(status
)) {
429 status
= acpi_evaluate_integer(handle
, "_STA", NULL
, &tmp
);
430 if (ACPI_FAILURE(status
)) {
431 dbg("%s: _STA evaluation failure\n", __FUNCTION__
);
434 if ((tmp
& ACPI_STA_FUNCTIONING
) == 0)
435 /* don't register this object */
439 /* get PCI segment number */
440 status
= acpi_evaluate_integer(handle
, "_SEG", NULL
, &tmp
);
442 seg
= ACPI_SUCCESS(status
) ? tmp
: 0;
444 /* get PCI bus number */
445 status
= acpi_evaluate_integer(handle
, "_BBN", NULL
, &tmp
);
447 if (ACPI_SUCCESS(status
)) {
450 warn("can't get bus number, assuming 0\n");
454 pci_bus
= pci_find_bus(seg
, bus
);
456 err("Can't find bus %04x:%02x\n", seg
, bus
);
460 /* check if this bridge has ejectable slots */
461 if (detect_ejectable_slots(handle
) > 0) {
462 dbg("found PCI host-bus bridge with hot-pluggable slots\n");
463 add_host_bridge(handle
, pci_bus
);
467 /* search P2P bridges under this host bridge */
468 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
, handle
, (u32
)1,
469 find_p2p_bridge
, pci_bus
, NULL
);
471 if (ACPI_FAILURE(status
))
472 warn("find_p2p_bridge faied (error code = 0x%x)\n",status
);
477 static struct acpiphp_bridge
*acpiphp_handle_to_bridge(acpi_handle handle
)
479 struct list_head
*head
;
480 list_for_each(head
, &bridge_list
) {
481 struct acpiphp_bridge
*bridge
= list_entry(head
,
482 struct acpiphp_bridge
, list
);
483 if (bridge
->handle
== handle
)
490 static void remove_bridge(acpi_handle handle
)
492 struct list_head
*list
, *tmp
;
493 struct acpiphp_bridge
*bridge
;
494 struct acpiphp_slot
*slot
;
497 bridge
= acpiphp_handle_to_bridge(handle
);
499 err("Could not find bridge for handle %p\n", handle
);
503 status
= acpi_remove_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
504 handle_hotplug_event_bridge
);
505 if (ACPI_FAILURE(status
))
506 err("failed to remove notify handler\n");
508 slot
= bridge
->slots
;
510 struct acpiphp_slot
*next
= slot
->next
;
511 list_for_each_safe (list
, tmp
, &slot
->funcs
) {
512 struct acpiphp_func
*func
;
513 func
= list_entry(list
, struct acpiphp_func
, sibling
);
514 status
= acpi_remove_notify_handler(func
->handle
,
516 handle_hotplug_event_func
);
517 if (ACPI_FAILURE(status
))
518 err("failed to remove notify handler\n");
519 pci_dev_put(func
->pci_dev
);
527 pci_dev_put(bridge
->pci_dev
);
528 list_del(&bridge
->list
);
533 static int power_on_slot(struct acpiphp_slot
*slot
)
536 struct acpiphp_func
*func
;
540 /* if already enabled, just skip */
541 if (slot
->flags
& SLOT_POWEREDON
)
544 list_for_each (l
, &slot
->funcs
) {
545 func
= list_entry(l
, struct acpiphp_func
, sibling
);
547 if (func
->flags
& FUNC_HAS_PS0
) {
548 dbg("%s: executing _PS0\n", __FUNCTION__
);
549 status
= acpi_evaluate_object(func
->handle
, "_PS0", NULL
, NULL
);
550 if (ACPI_FAILURE(status
)) {
551 warn("%s: _PS0 failed\n", __FUNCTION__
);
559 /* TBD: evaluate _STA to check if the slot is enabled */
561 slot
->flags
|= SLOT_POWEREDON
;
568 static int power_off_slot(struct acpiphp_slot
*slot
)
571 struct acpiphp_func
*func
;
573 struct acpi_object_list arg_list
;
574 union acpi_object arg
;
578 /* if already disabled, just skip */
579 if ((slot
->flags
& SLOT_POWEREDON
) == 0)
582 list_for_each (l
, &slot
->funcs
) {
583 func
= list_entry(l
, struct acpiphp_func
, sibling
);
585 if (func
->pci_dev
&& (func
->flags
& FUNC_HAS_PS3
)) {
586 status
= acpi_evaluate_object(func
->handle
, "_PS3", NULL
, NULL
);
587 if (ACPI_FAILURE(status
)) {
588 warn("%s: _PS3 failed\n", __FUNCTION__
);
596 list_for_each (l
, &slot
->funcs
) {
597 func
= list_entry(l
, struct acpiphp_func
, sibling
);
599 /* We don't want to call _EJ0 on non-existing functions. */
600 if (func
->pci_dev
&& (func
->flags
& FUNC_HAS_EJ0
)) {
601 /* _EJ0 method take one argument */
603 arg_list
.pointer
= &arg
;
604 arg
.type
= ACPI_TYPE_INTEGER
;
605 arg
.integer
.value
= 1;
607 status
= acpi_evaluate_object(func
->handle
, "_EJ0", &arg_list
, NULL
);
608 if (ACPI_FAILURE(status
)) {
609 warn("%s: _EJ0 failed\n", __FUNCTION__
);
617 /* TBD: evaluate _STA to check if the slot is disabled */
619 slot
->flags
&= (~SLOT_POWEREDON
);
627 * enable_device - enable, configure a slot
628 * @slot: slot to be enabled
630 * This function should be called per *physical slot*,
631 * not per each slot object in ACPI namespace.
634 static int enable_device(struct acpiphp_slot
*slot
)
637 struct pci_bus
*bus
= slot
->bridge
->pci_bus
;
639 struct acpiphp_func
*func
;
643 if (slot
->flags
& SLOT_ENABLED
)
646 /* sanity check: dev should be NULL when hot-plugged in */
647 dev
= pci_get_slot(bus
, PCI_DEVFN(slot
->device
, 0));
649 /* This case shouldn't happen */
650 err("pci_dev structure already exists.\n");
656 num
= pci_scan_slot(bus
, PCI_DEVFN(slot
->device
, 0));
658 err("No new device found\n");
663 max
= bus
->secondary
;
664 for (pass
= 0; pass
< 2; pass
++) {
665 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
666 if (PCI_SLOT(dev
->devfn
) != slot
->device
)
668 if (dev
->hdr_type
== PCI_HEADER_TYPE_BRIDGE
||
669 dev
->hdr_type
== PCI_HEADER_TYPE_CARDBUS
)
670 max
= pci_scan_bridge(bus
, dev
, max
, pass
);
674 pci_bus_assign_resources(bus
);
675 pci_bus_add_devices(bus
);
677 /* associate pci_dev to our representation */
678 list_for_each (l
, &slot
->funcs
) {
679 func
= list_entry(l
, struct acpiphp_func
, sibling
);
680 func
->pci_dev
= pci_get_slot(bus
, PCI_DEVFN(slot
->device
,
684 slot
->flags
|= SLOT_ENABLED
;
692 * disable_device - disable a slot
694 static int disable_device(struct acpiphp_slot
*slot
)
697 struct acpiphp_func
*func
;
700 /* is this slot already disabled? */
701 if (!(slot
->flags
& SLOT_ENABLED
))
704 list_for_each (l
, &slot
->funcs
) {
705 func
= list_entry(l
, struct acpiphp_func
, sibling
);
709 pci_remove_bus_device(func
->pci_dev
);
710 pci_dev_put(func
->pci_dev
);
711 func
->pci_dev
= NULL
;
714 slot
->flags
&= (~SLOT_ENABLED
);
722 * get_slot_status - get ACPI slot status
724 * if a slot has _STA for each function and if any one of them
725 * returned non-zero status, return it
727 * if a slot doesn't have _STA and if any one of its functions'
728 * configuration space is configured, return 0x0f as a _STA
732 static unsigned int get_slot_status(struct acpiphp_slot
*slot
)
735 unsigned long sta
= 0;
738 struct acpiphp_func
*func
;
740 list_for_each (l
, &slot
->funcs
) {
741 func
= list_entry(l
, struct acpiphp_func
, sibling
);
743 if (func
->flags
& FUNC_HAS_STA
) {
744 status
= acpi_evaluate_integer(func
->handle
, "_STA", NULL
, &sta
);
745 if (ACPI_SUCCESS(status
) && sta
)
748 pci_bus_read_config_dword(slot
->bridge
->pci_bus
,
749 PCI_DEVFN(slot
->device
,
751 PCI_VENDOR_ID
, &dvid
);
752 if (dvid
!= 0xffffffff) {
759 return (unsigned int)sta
;
763 * acpiphp_check_bridge - re-enumerate devices
765 * Iterate over all slots under this bridge and make sure that if a
766 * card is present they are enabled, and if not they are disabled.
768 static int acpiphp_check_bridge(struct acpiphp_bridge
*bridge
)
770 struct acpiphp_slot
*slot
;
772 int enabled
, disabled
;
774 enabled
= disabled
= 0;
776 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
777 unsigned int status
= get_slot_status(slot
);
778 if (slot
->flags
& SLOT_ENABLED
) {
779 if (status
== ACPI_STA_ALL
)
781 retval
= acpiphp_disable_slot(slot
);
783 err("Error occurred in disabling\n");
788 if (status
!= ACPI_STA_ALL
)
790 retval
= acpiphp_enable_slot(slot
);
792 err("Error occurred in enabling\n");
799 dbg("%s: %d enabled, %d disabled\n", __FUNCTION__
, enabled
, disabled
);
806 * ACPI event handlers
810 * handle_hotplug_event_bridge - handle ACPI event on bridges
812 * @handle: Notify()'ed acpi_handle
814 * @context: pointer to acpiphp_bridge structure
816 * handles ACPI event notification on {host,p2p} bridges
819 static void handle_hotplug_event_bridge(acpi_handle handle
, u32 type
, void *context
)
821 struct acpiphp_bridge
*bridge
;
823 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
824 .pointer
= objname
};
826 bridge
= (struct acpiphp_bridge
*)context
;
828 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
831 case ACPI_NOTIFY_BUS_CHECK
:
832 /* bus re-enumerate */
833 dbg("%s: Bus check notify on %s\n", __FUNCTION__
, objname
);
834 acpiphp_check_bridge(bridge
);
837 case ACPI_NOTIFY_DEVICE_CHECK
:
839 dbg("%s: Device check notify on %s\n", __FUNCTION__
, objname
);
840 acpiphp_check_bridge(bridge
);
843 case ACPI_NOTIFY_DEVICE_WAKE
:
845 dbg("%s: Device wake notify on %s\n", __FUNCTION__
, objname
);
848 case ACPI_NOTIFY_EJECT_REQUEST
:
849 /* request device eject */
850 dbg("%s: Device eject notify on %s\n", __FUNCTION__
, objname
);
853 case ACPI_NOTIFY_FREQUENCY_MISMATCH
:
854 printk(KERN_ERR
"Device %s cannot be configured due"
855 " to a frequency mismatch\n", objname
);
858 case ACPI_NOTIFY_BUS_MODE_MISMATCH
:
859 printk(KERN_ERR
"Device %s cannot be configured due"
860 " to a bus mode mismatch\n", objname
);
863 case ACPI_NOTIFY_POWER_FAULT
:
864 printk(KERN_ERR
"Device %s has suffered a power fault\n",
869 warn("notify_handler: unknown event type 0x%x for %s\n", type
, objname
);
876 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
878 * @handle: Notify()'ed acpi_handle
880 * @context: pointer to acpiphp_func structure
882 * handles ACPI event notification on slots
885 static void handle_hotplug_event_func(acpi_handle handle
, u32 type
, void *context
)
887 struct acpiphp_func
*func
;
889 struct acpi_buffer buffer
= { .length
= sizeof(objname
),
890 .pointer
= objname
};
892 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
894 func
= (struct acpiphp_func
*)context
;
897 case ACPI_NOTIFY_BUS_CHECK
:
898 /* bus re-enumerate */
899 dbg("%s: Bus check notify on %s\n", __FUNCTION__
, objname
);
900 acpiphp_enable_slot(func
->slot
);
903 case ACPI_NOTIFY_DEVICE_CHECK
:
904 /* device check : re-enumerate from parent bus */
905 dbg("%s: Device check notify on %s\n", __FUNCTION__
, objname
);
906 acpiphp_check_bridge(func
->slot
->bridge
);
909 case ACPI_NOTIFY_DEVICE_WAKE
:
911 dbg("%s: Device wake notify on %s\n", __FUNCTION__
, objname
);
914 case ACPI_NOTIFY_EJECT_REQUEST
:
915 /* request device eject */
916 dbg("%s: Device eject notify on %s\n", __FUNCTION__
, objname
);
917 acpiphp_disable_slot(func
->slot
);
921 warn("notify_handler: unknown event type 0x%x for %s\n", type
, objname
);
927 static struct acpi_pci_driver acpi_pci_hp_driver
= {
929 .remove
= remove_bridge
,
933 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
936 int __init
acpiphp_glue_init(void)
940 if (list_empty(&pci_root_buses
))
943 num
= acpi_pci_register_driver(&acpi_pci_hp_driver
);
953 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures
955 * This function frees all data allocated in acpiphp_glue_init()
957 void __exit
acpiphp_glue_exit(void)
959 acpi_pci_unregister_driver(&acpi_pci_hp_driver
);
964 * acpiphp_get_num_slots - count number of slots in a system
966 int __init
acpiphp_get_num_slots(void)
968 struct list_head
*node
;
969 struct acpiphp_bridge
*bridge
;
974 list_for_each (node
, &bridge_list
) {
975 bridge
= (struct acpiphp_bridge
*)node
;
976 dbg("Bus %04x:%02x has %d slot%s\n",
977 pci_domain_nr(bridge
->pci_bus
),
978 bridge
->pci_bus
->number
, bridge
->nr_slots
,
979 bridge
->nr_slots
== 1 ? "" : "s");
980 num_slots
+= bridge
->nr_slots
;
983 dbg("Total %d slots\n", num_slots
);
990 * acpiphp_for_each_slot - call function for each slot
991 * @fn: callback function
992 * @data: context to be passed to callback function
995 static int acpiphp_for_each_slot(acpiphp_callback fn
, void *data
)
997 struct list_head
*node
;
998 struct acpiphp_bridge
*bridge
;
999 struct acpiphp_slot
*slot
;
1002 list_for_each (node
, &bridge_list
) {
1003 bridge
= (struct acpiphp_bridge
*)node
;
1004 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
) {
1005 retval
= fn(slot
, data
);
1016 /* search matching slot from id */
1017 struct acpiphp_slot
*get_slot_from_id(int id
)
1019 struct list_head
*node
;
1020 struct acpiphp_bridge
*bridge
;
1021 struct acpiphp_slot
*slot
;
1023 list_for_each (node
, &bridge_list
) {
1024 bridge
= (struct acpiphp_bridge
*)node
;
1025 for (slot
= bridge
->slots
; slot
; slot
= slot
->next
)
1030 /* should never happen! */
1031 err("%s: no object for id %d\n", __FUNCTION__
, id
);
1038 * acpiphp_enable_slot - power on slot
1040 int acpiphp_enable_slot(struct acpiphp_slot
*slot
)
1044 down(&slot
->crit_sect
);
1046 /* wake up all functions */
1047 retval
= power_on_slot(slot
);
1051 if (get_slot_status(slot
) == ACPI_STA_ALL
)
1052 /* configure all functions */
1053 retval
= enable_device(slot
);
1056 up(&slot
->crit_sect
);
1062 * acpiphp_disable_slot - power off slot
1064 int acpiphp_disable_slot(struct acpiphp_slot
*slot
)
1068 down(&slot
->crit_sect
);
1070 /* unconfigure all functions */
1071 retval
= disable_device(slot
);
1075 /* power off all functions */
1076 retval
= power_off_slot(slot
);
1081 up(&slot
->crit_sect
);
1090 u8
acpiphp_get_power_status(struct acpiphp_slot
*slot
)
1094 sta
= get_slot_status(slot
);
1096 return (sta
& ACPI_STA_ENABLED
) ? 1 : 0;
1104 u8
acpiphp_get_latch_status(struct acpiphp_slot
*slot
)
1108 sta
= get_slot_status(slot
);
1110 return (sta
& ACPI_STA_SHOW_IN_UI
) ? 1 : 0;
1115 * adapter presence : 1
1118 u8
acpiphp_get_adapter_status(struct acpiphp_slot
*slot
)
1122 sta
= get_slot_status(slot
);
1124 return (sta
== 0) ? 0 : 1;
1129 * pci address (seg/bus/dev)
1131 u32
acpiphp_get_address(struct acpiphp_slot
*slot
)
1134 struct pci_bus
*pci_bus
= slot
->bridge
->pci_bus
;
1136 address
= (pci_domain_nr(pci_bus
) << 16) |
1137 (pci_bus
->number
<< 8) |