1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
36struct dummy_slot {
37 u32 number;
38 struct list_head list;
39};
40
41static int slot_detection_mode;
42static char *pciehp_detect_mode;
43module_param(pciehp_detect_mode, charp, 0444);
44MODULE_PARM_DESC(pciehp_detect_mode,
45 "Slot detection mode: pcie, acpi, auto\n"
46 " pcie - Use PCIe based slot detection\n"
47 " acpi - Use ACPI for slot detection\n"
48 " auto(default) - Auto select mode. Use acpi option if duplicate\n"
49 " slot ids are found. Otherwise, use pcie option\n");
50
51int pciehp_acpi_slot_detection_check(struct pci_dev *dev)
52{
53 if (slot_detection_mode != PCIEHP_DETECT_ACPI)
54 return 0;
55 if (acpi_pci_detect_ejectable(DEVICE_ACPI_HANDLE(&dev->dev)))
56 return 0;
57 return -ENODEV;
58}
59
60static int __init parse_detect_mode(void)
61{
62 if (!pciehp_detect_mode)
63 return PCIEHP_DETECT_DEFAULT;
64 if (!strcmp(pciehp_detect_mode, "pcie"))
65 return PCIEHP_DETECT_PCIE;
66 if (!strcmp(pciehp_detect_mode, "acpi"))
67 return PCIEHP_DETECT_ACPI;
68 if (!strcmp(pciehp_detect_mode, "auto"))
69 return PCIEHP_DETECT_AUTO;
70 warn("bad specifier '%s' for pciehp_detect_mode. Use default\n",
71 pciehp_detect_mode);
72 return PCIEHP_DETECT_DEFAULT;
73}
74
75static int __initdata dup_slot_id;
76static int __initdata acpi_slot_detected;
77static struct list_head __initdata dummy_slots = LIST_HEAD_INIT(dummy_slots);
78
79
80static int __init dummy_probe(struct pcie_device *dev)
81{
82 int pos;
83 u32 slot_cap;
84 acpi_handle handle;
85 struct dummy_slot *slot, *tmp;
86 struct pci_dev *pdev = dev->port;
87
88 if (pciehp_get_hp_hw_control_from_firmware(pdev))
89 return -ENODEV;
90 if (!(pos = pci_find_capability(pdev, PCI_CAP_ID_EXP)))
91 return -ENODEV;
92 pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, &slot_cap);
93 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
94 if (!slot)
95 return -ENOMEM;
96 slot->number = slot_cap >> 19;
97 list_for_each_entry(tmp, &dummy_slots, list) {
98 if (tmp->number == slot->number)
99 dup_slot_id++;
100 }
101 list_add_tail(&slot->list, &dummy_slots);
102 handle = DEVICE_ACPI_HANDLE(&pdev->dev);
103 if (!acpi_slot_detected && acpi_pci_detect_ejectable(handle))
104 acpi_slot_detected = 1;
105 return -ENODEV;
106}
107
108static struct pcie_port_service_driver __initdata dummy_driver = {
109 .name = "pciehp_dummy",
110 .port_type = PCIE_ANY_PORT,
111 .service = PCIE_PORT_SERVICE_HP,
112 .probe = dummy_probe,
113};
114
115static int __init select_detection_mode(void)
116{
117 struct dummy_slot *slot, *tmp;
118 pcie_port_service_register(&dummy_driver);
119 pcie_port_service_unregister(&dummy_driver);
120 list_for_each_entry_safe(slot, tmp, &dummy_slots, list) {
121 list_del(&slot->list);
122 kfree(slot);
123 }
124 if (acpi_slot_detected && dup_slot_id)
125 return PCIEHP_DETECT_ACPI;
126 return PCIEHP_DETECT_PCIE;
127}
128
129void __init pciehp_acpi_slot_detection_init(void)
130{
131 slot_detection_mode = parse_detect_mode();
132 if (slot_detection_mode != PCIEHP_DETECT_AUTO)
133 goto out;
134 slot_detection_mode = select_detection_mode();
135out:
136 if (slot_detection_mode == PCIEHP_DETECT_ACPI)
137 info("Using ACPI for slot detection.\n");
138}
139