Linux 2.6.34-rc3
[pohmelfs.git] / drivers / pci / hotplug / pciehp_acpi.c
blobb09b083011d69ad43e743490bad963266f6af36b
1 /*
2 * ACPI related functions for PCI Express Hot Plug driver.
4 * Copyright (C) 2008 Kenji Kaneshige
5 * Copyright (C) 2008 Fujitsu Limited.
7 * All rights reserved.
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
18 * details.
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>
27 #include <linux/pci.h>
28 #include <linux/pci_hotplug.h>
29 #include "pciehp.h"
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
36 struct dummy_slot {
37 u32 number;
38 struct list_head list;
41 static int slot_detection_mode;
42 static char *pciehp_detect_mode;
43 module_param(pciehp_detect_mode, charp, 0444);
44 MODULE_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");
51 int pciehp_acpi_slot_detection_check(struct pci_dev *dev)
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;
60 static int __init parse_detect_mode(void)
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;
75 static int __initdata dup_slot_id;
76 static int __initdata acpi_slot_detected;
77 static struct list_head __initdata dummy_slots = LIST_HEAD_INIT(dummy_slots);
79 /* Dummy driver for dumplicate name detection */
80 static int __init dummy_probe(struct pcie_device *dev)
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 /* Note: pciehp_detect_mode != PCIEHP_DETECT_ACPI here */
88 if (pciehp_get_hp_hw_control_from_firmware(pdev))
89 return -ENODEV;
90 pos = pci_pcie_cap(pdev);
91 if (!pos)
92 return -ENODEV;
93 pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, &slot_cap);
94 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
95 if (!slot)
96 return -ENOMEM;
97 slot->number = slot_cap >> 19;
98 list_for_each_entry(tmp, &dummy_slots, list) {
99 if (tmp->number == slot->number)
100 dup_slot_id++;
102 list_add_tail(&slot->list, &dummy_slots);
103 handle = DEVICE_ACPI_HANDLE(&pdev->dev);
104 if (!acpi_slot_detected && acpi_pci_detect_ejectable(handle))
105 acpi_slot_detected = 1;
106 return -ENODEV; /* dummy driver always returns error */
109 static struct pcie_port_service_driver __initdata dummy_driver = {
110 .name = "pciehp_dummy",
111 .port_type = PCIE_ANY_PORT,
112 .service = PCIE_PORT_SERVICE_HP,
113 .probe = dummy_probe,
116 static int __init select_detection_mode(void)
118 struct dummy_slot *slot, *tmp;
119 pcie_port_service_register(&dummy_driver);
120 pcie_port_service_unregister(&dummy_driver);
121 list_for_each_entry_safe(slot, tmp, &dummy_slots, list) {
122 list_del(&slot->list);
123 kfree(slot);
125 if (acpi_slot_detected && dup_slot_id)
126 return PCIEHP_DETECT_ACPI;
127 return PCIEHP_DETECT_PCIE;
130 void __init pciehp_acpi_slot_detection_init(void)
132 slot_detection_mode = parse_detect_mode();
133 if (slot_detection_mode != PCIEHP_DETECT_AUTO)
134 goto out;
135 slot_detection_mode = select_detection_mode();
136 out:
137 if (slot_detection_mode == PCIEHP_DETECT_ACPI)
138 info("Using ACPI for slot detection.\n");