blob: 21734c311529c10012d94cb4e6f192b121b5a546 [file] [log] [blame]
Kenji Kaneshigec9ffa5a2008-12-17 12:07:38 +09001/*
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>
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +090027#include <linux/pci.h>
28#include <linux/pci_hotplug.h>
Kenji Kaneshigec9ffa5a2008-12-17 12:07:38 +090029#include "pciehp.h"
30
31#define PCIEHP_DETECT_PCIE (0)
32#define PCIEHP_DETECT_ACPI (1)
Kenji Kaneshigee046cbd2008-12-17 12:08:15 +090033#define PCIEHP_DETECT_AUTO (2)
34#define PCIEHP_DETECT_DEFAULT PCIEHP_DETECT_AUTO
Kenji Kaneshigec9ffa5a2008-12-17 12:07:38 +090035
36static int slot_detection_mode;
37static char *pciehp_detect_mode;
38module_param(pciehp_detect_mode, charp, 0444);
39MODULE_PARM_DESC(pciehp_detect_mode,
Kenji Kaneshigee046cbd2008-12-17 12:08:15 +090040 "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");
Kenji Kaneshigec9ffa5a2008-12-17 12:07:38 +090045
Kenji Kaneshigec9ffa5a2008-12-17 12:07:38 +090046int pciehp_acpi_slot_detection_check(struct pci_dev *dev)
47{
48 if (slot_detection_mode != PCIEHP_DETECT_ACPI)
49 return 0;
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +090050 if (acpi_pci_detect_ejectable(dev->subordinate))
Kenji Kaneshigec9ffa5a2008-12-17 12:07:38 +090051 return 0;
52 return -ENODEV;
53}
54
55static 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;
Kenji Kaneshigee046cbd2008-12-17 12:08:15 +090063 if (!strcmp(pciehp_detect_mode, "auto"))
64 return PCIEHP_DETECT_AUTO;
Kenji Kaneshigec9ffa5a2008-12-17 12:07:38 +090065 warn("bad specifier '%s' for pciehp_detect_mode. Use default\n",
66 pciehp_detect_mode);
67 return PCIEHP_DETECT_DEFAULT;
68}
69
Kenji Kaneshigee046cbd2008-12-17 12:08:15 +090070static int __initdata dup_slot_id;
71static int __initdata acpi_slot_detected;
72static struct list_head __initdata dummy_slots = LIST_HEAD_INIT(dummy_slots);
73
74/* Dummy driver for dumplicate name detection */
Rafael J. Wysocki0516c8b2009-01-13 14:44:19 +010075static int __init dummy_probe(struct pcie_device *dev)
Kenji Kaneshigee046cbd2008-12-17 12:08:15 +090076{
77 int pos;
78 u32 slot_cap;
79 struct slot *slot, *tmp;
80 struct pci_dev *pdev = dev->port;
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +090081 struct pci_bus *pbus = pdev->subordinate;
Kenji Kaneshigee046cbd2008-12-17 12:08:15 +090082 if (!(slot = kzalloc(sizeof(*slot), GFP_KERNEL)))
83 return -ENOMEM;
84 /* Note: pciehp_detect_mode != PCIEHP_DETECT_ACPI here */
85 if (pciehp_get_hp_hw_control_from_firmware(pdev))
86 return -ENODEV;
87 if (!(pos = pci_find_capability(pdev, PCI_CAP_ID_EXP)))
88 return -ENODEV;
89 pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, &slot_cap);
90 slot->number = slot_cap >> 19;
91 list_for_each_entry(tmp, &dummy_slots, slot_list) {
92 if (tmp->number == slot->number)
93 dup_slot_id++;
94 }
95 list_add_tail(&slot->slot_list, &dummy_slots);
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +090096 if (!acpi_slot_detected && acpi_pci_detect_ejectable(pbus))
Kenji Kaneshigee046cbd2008-12-17 12:08:15 +090097 acpi_slot_detected = 1;
98 return -ENODEV; /* dummy driver always returns error */
99}
100
101static struct pcie_port_service_driver __initdata dummy_driver = {
102 .name = "pciehp_dummy",
Rafael J. Wysocki22106362009-01-13 14:46:46 +0100103 .port_type = PCIE_ANY_PORT,
104 .service = PCIE_PORT_SERVICE_HP,
Kenji Kaneshigee046cbd2008-12-17 12:08:15 +0900105 .probe = dummy_probe,
106};
107
108static int __init select_detection_mode(void)
109{
110 struct slot *slot, *tmp;
111 pcie_port_service_register(&dummy_driver);
112 pcie_port_service_unregister(&dummy_driver);
113 list_for_each_entry_safe(slot, tmp, &dummy_slots, slot_list) {
114 list_del(&slot->slot_list);
115 kfree(slot);
116 }
117 if (acpi_slot_detected && dup_slot_id)
118 return PCIEHP_DETECT_ACPI;
119 return PCIEHP_DETECT_PCIE;
120}
121
Kenji Kaneshigec9ffa5a2008-12-17 12:07:38 +0900122void __init pciehp_acpi_slot_detection_init(void)
123{
124 slot_detection_mode = parse_detect_mode();
Kenji Kaneshigee046cbd2008-12-17 12:08:15 +0900125 if (slot_detection_mode != PCIEHP_DETECT_AUTO)
126 goto out;
127 slot_detection_mode = select_detection_mode();
128out:
129 if (slot_detection_mode == PCIEHP_DETECT_ACPI)
130 info("Using ACPI for slot detection.\n");
Kenji Kaneshigec9ffa5a2008-12-17 12:07:38 +0900131}