diff options
Diffstat (limited to 'drivers/pci/hotplug/pciehp_acpi.c')
-rw-r--r-- | drivers/pci/hotplug/pciehp_acpi.c | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/drivers/pci/hotplug/pciehp_acpi.c b/drivers/pci/hotplug/pciehp_acpi.c new file mode 100644 index 000000000000..438d795f9fe3 --- /dev/null +++ b/drivers/pci/hotplug/pciehp_acpi.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * ACPI related functions for PCI Express Hot Plug driver. | ||
3 | * | ||
4 | * Copyright (C) 2008 Kenji Kaneshige | ||
5 | * Copyright (C) 2008 Fujitsu Limited. | ||
6 | * | ||
7 | * All rights reserved. | ||
8 | * | ||
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. | ||
13 | * | ||
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 | ||
18 | * details. | ||
19 | * | ||
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. | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include <linux/acpi.h> | ||
27 | #include <linux/pci.h> | ||
28 | #include <linux/pci_hotplug.h> | ||
29 | #include "pciehp.h" | ||
30 | |||
31 | #define PCIEHP_DETECT_PCIE (0) | ||
32 | #define PCIEHP_DETECT_ACPI (1) | ||
33 | #define PCIEHP_DETECT_AUTO (2) | ||
34 | #define PCIEHP_DETECT_DEFAULT PCIEHP_DETECT_AUTO | ||
35 | |||
36 | static int slot_detection_mode; | ||
37 | static char *pciehp_detect_mode; | ||
38 | module_param(pciehp_detect_mode, charp, 0444); | ||
39 | MODULE_PARM_DESC(pciehp_detect_mode, | ||
40 | "Slot detection mode: pcie, acpi, auto\n" | ||
41 | " pcie - Use PCIe based slot detection\n" | ||
42 | " acpi - Use ACPI for slot detection\n" | ||
43 | " auto(default) - Auto select mode. Use acpi option if duplicate\n" | ||
44 | " slot ids are found. Otherwise, use pcie option\n"); | ||
45 | |||
46 | int pciehp_acpi_slot_detection_check(struct pci_dev *dev) | ||
47 | { | ||
48 | if (slot_detection_mode != PCIEHP_DETECT_ACPI) | ||
49 | return 0; | ||
50 | if (acpi_pci_detect_ejectable(dev->subordinate)) | ||
51 | return 0; | ||
52 | return -ENODEV; | ||
53 | } | ||
54 | |||
55 | static int __init parse_detect_mode(void) | ||
56 | { | ||
57 | if (!pciehp_detect_mode) | ||
58 | return PCIEHP_DETECT_DEFAULT; | ||
59 | if (!strcmp(pciehp_detect_mode, "pcie")) | ||
60 | return PCIEHP_DETECT_PCIE; | ||
61 | if (!strcmp(pciehp_detect_mode, "acpi")) | ||
62 | return PCIEHP_DETECT_ACPI; | ||
63 | if (!strcmp(pciehp_detect_mode, "auto")) | ||
64 | return PCIEHP_DETECT_AUTO; | ||
65 | warn("bad specifier '%s' for pciehp_detect_mode. Use default\n", | ||
66 | pciehp_detect_mode); | ||
67 | return PCIEHP_DETECT_DEFAULT; | ||
68 | } | ||
69 | |||
70 | static struct pcie_port_service_id __initdata port_pci_ids[] = { | ||
71 | { | ||
72 | .vendor = PCI_ANY_ID, | ||
73 | .device = PCI_ANY_ID, | ||
74 | .port_type = PCIE_ANY_PORT, | ||
75 | .service_type = PCIE_PORT_SERVICE_HP, | ||
76 | .driver_data = 0, | ||
77 | }, { /* end: all zeroes */ } | ||
78 | }; | ||
79 | |||
80 | static int __initdata dup_slot_id; | ||
81 | static int __initdata acpi_slot_detected; | ||
82 | static struct list_head __initdata dummy_slots = LIST_HEAD_INIT(dummy_slots); | ||
83 | |||
84 | /* Dummy driver for dumplicate name detection */ | ||
85 | static int __init dummy_probe(struct pcie_device *dev, | ||
86 | const struct pcie_port_service_id *id) | ||
87 | { | ||
88 | int pos; | ||
89 | u32 slot_cap; | ||
90 | struct slot *slot, *tmp; | ||
91 | struct pci_dev *pdev = dev->port; | ||
92 | struct pci_bus *pbus = pdev->subordinate; | ||
93 | if (!(slot = kzalloc(sizeof(*slot), GFP_KERNEL))) | ||
94 | return -ENOMEM; | ||
95 | /* Note: pciehp_detect_mode != PCIEHP_DETECT_ACPI here */ | ||
96 | if (pciehp_get_hp_hw_control_from_firmware(pdev)) | ||
97 | return -ENODEV; | ||
98 | if (!(pos = pci_find_capability(pdev, PCI_CAP_ID_EXP))) | ||
99 | return -ENODEV; | ||
100 | pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, &slot_cap); | ||
101 | slot->number = slot_cap >> 19; | ||
102 | list_for_each_entry(tmp, &dummy_slots, slot_list) { | ||
103 | if (tmp->number == slot->number) | ||
104 | dup_slot_id++; | ||
105 | } | ||
106 | list_add_tail(&slot->slot_list, &dummy_slots); | ||
107 | if (!acpi_slot_detected && acpi_pci_detect_ejectable(pbus)) | ||
108 | acpi_slot_detected = 1; | ||
109 | return -ENODEV; /* dummy driver always returns error */ | ||
110 | } | ||
111 | |||
112 | static struct pcie_port_service_driver __initdata dummy_driver = { | ||
113 | .name = "pciehp_dummy", | ||
114 | .id_table = port_pci_ids, | ||
115 | .probe = dummy_probe, | ||
116 | }; | ||
117 | |||
118 | static int __init select_detection_mode(void) | ||
119 | { | ||
120 | struct slot *slot, *tmp; | ||
121 | pcie_port_service_register(&dummy_driver); | ||
122 | pcie_port_service_unregister(&dummy_driver); | ||
123 | list_for_each_entry_safe(slot, tmp, &dummy_slots, slot_list) { | ||
124 | list_del(&slot->slot_list); | ||
125 | kfree(slot); | ||
126 | } | ||
127 | if (acpi_slot_detected && dup_slot_id) | ||
128 | return PCIEHP_DETECT_ACPI; | ||
129 | return PCIEHP_DETECT_PCIE; | ||
130 | } | ||
131 | |||
132 | void __init pciehp_acpi_slot_detection_init(void) | ||
133 | { | ||
134 | slot_detection_mode = parse_detect_mode(); | ||
135 | if (slot_detection_mode != PCIEHP_DETECT_AUTO) | ||
136 | goto out; | ||
137 | slot_detection_mode = select_detection_mode(); | ||
138 | out: | ||
139 | if (slot_detection_mode == PCIEHP_DETECT_ACPI) | ||
140 | info("Using ACPI for slot detection.\n"); | ||
141 | } | ||