2 * ACPI related functions for PCI Express Hot Plug driver.
4 * Copyright (C) 2008 Kenji Kaneshige
5 * Copyright (C) 2008 Fujitsu Limited.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
17 * NON INFRINGEMENT. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/acpi.h>
29 #define PCIEHP_DETECT_PCIE (0)
30 #define PCIEHP_DETECT_ACPI (1)
31 #define PCIEHP_DETECT_DEFAULT PCIEHP_DETECT_PCIE
33 static int slot_detection_mode;
34 static char *pciehp_detect_mode;
35 module_param(pciehp_detect_mode, charp, 0444);
36 MODULE_PARM_DESC(pciehp_detect_mode,
37 "Slot detection mode: pcie, acpi\n"
38 " pcie - Use PCIe based slot detection (default)\n"
39 " acpi - Use ACPI for slot detection\n");
41 static int is_ejectable(acpi_handle handle)
45 unsigned long long removable;
46 status = acpi_get_handle(handle, "_ADR", &tmp);
47 if (ACPI_FAILURE(status))
49 status = acpi_get_handle(handle, "_EJ0", &tmp);
50 if (ACPI_SUCCESS(status))
52 status = acpi_evaluate_integer(handle, "_RMV", NULL, &removable);
53 if (ACPI_SUCCESS(status) && removable)
59 check_hotplug(acpi_handle handle, u32 lvl, void *context, void **rv)
61 int *found = (int *)context;
62 if (is_ejectable(handle)) {
64 return AE_CTRL_TERMINATE;
69 static int pciehp_detect_acpi_slot(struct pci_bus *pbus)
72 struct pci_dev *pdev = pbus->self;
76 int seg = pci_domain_nr(pbus), busnr = pbus->number;
77 handle = acpi_get_pci_rootbridge_handle(seg, busnr);
79 handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
84 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
85 check_hotplug, (void *)&found, NULL);
89 int pciehp_acpi_slot_detection_check(struct pci_dev *dev)
91 if (slot_detection_mode != PCIEHP_DETECT_ACPI)
93 if (pciehp_detect_acpi_slot(dev->subordinate))
98 static int __init parse_detect_mode(void)
100 if (!pciehp_detect_mode)
101 return PCIEHP_DETECT_DEFAULT;
102 if (!strcmp(pciehp_detect_mode, "pcie"))
103 return PCIEHP_DETECT_PCIE;
104 if (!strcmp(pciehp_detect_mode, "acpi"))
105 return PCIEHP_DETECT_ACPI;
106 warn("bad specifier '%s' for pciehp_detect_mode. Use default\n",
108 return PCIEHP_DETECT_DEFAULT;
111 void __init pciehp_acpi_slot_detection_init(void)
113 slot_detection_mode = parse_detect_mode();