Staging: strip: delete the driver
[linux/fpc-iii.git] / drivers / pci / pcie / portdrv_pci.c
blob3debed25e46bb63f4e70e4a58b0d9abff3fd33be
1 /*
2 * File: portdrv_pci.c
3 * Purpose: PCI Express Port Bus Driver
5 * Copyright (C) 2004 Intel
6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
7 */
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/pm.h>
14 #include <linux/init.h>
15 #include <linux/pcieport_if.h>
16 #include <linux/aer.h>
17 #include <linux/dmi.h>
19 #include "portdrv.h"
20 #include "aer/aerdrv.h"
23 * Version Information
25 #define DRIVER_VERSION "v1.0"
26 #define DRIVER_AUTHOR "tom.l.nguyen@intel.com"
27 #define DRIVER_DESC "PCIe Port Bus Driver"
28 MODULE_AUTHOR(DRIVER_AUTHOR);
29 MODULE_DESCRIPTION(DRIVER_DESC);
30 MODULE_LICENSE("GPL");
32 /* global data */
34 static int pcie_portdrv_restore_config(struct pci_dev *dev)
36 int retval;
38 retval = pci_enable_device(dev);
39 if (retval)
40 return retval;
41 pci_set_master(dev);
42 return 0;
45 #ifdef CONFIG_PM
46 static const struct dev_pm_ops pcie_portdrv_pm_ops = {
47 .suspend = pcie_port_device_suspend,
48 .resume = pcie_port_device_resume,
49 .freeze = pcie_port_device_suspend,
50 .thaw = pcie_port_device_resume,
51 .poweroff = pcie_port_device_suspend,
52 .restore = pcie_port_device_resume,
55 #define PCIE_PORTDRV_PM_OPS (&pcie_portdrv_pm_ops)
57 #else /* !PM */
59 #define PCIE_PORTDRV_PM_OPS NULL
60 #endif /* !PM */
63 * pcie_portdrv_probe - Probe PCI-Express port devices
64 * @dev: PCI-Express port device being probed
66 * If detected invokes the pcie_port_device_register() method for
67 * this port device.
70 static int __devinit pcie_portdrv_probe(struct pci_dev *dev,
71 const struct pci_device_id *id)
73 int status;
75 if (!pci_is_pcie(dev) ||
76 ((dev->pcie_type != PCI_EXP_TYPE_ROOT_PORT) &&
77 (dev->pcie_type != PCI_EXP_TYPE_UPSTREAM) &&
78 (dev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)))
79 return -ENODEV;
81 if (!dev->irq && dev->pin) {
82 dev_warn(&dev->dev, "device [%04x:%04x] has invalid IRQ; "
83 "check vendor BIOS\n", dev->vendor, dev->device);
85 status = pcie_port_device_register(dev);
86 if (status)
87 return status;
89 pci_save_state(dev);
91 return 0;
94 static void pcie_portdrv_remove(struct pci_dev *dev)
96 pcie_port_device_remove(dev);
97 pci_disable_device(dev);
100 static int error_detected_iter(struct device *device, void *data)
102 struct pcie_device *pcie_device;
103 struct pcie_port_service_driver *driver;
104 struct aer_broadcast_data *result_data;
105 pci_ers_result_t status;
107 result_data = (struct aer_broadcast_data *) data;
109 if (device->bus == &pcie_port_bus_type && device->driver) {
110 driver = to_service_driver(device->driver);
111 if (!driver ||
112 !driver->err_handler ||
113 !driver->err_handler->error_detected)
114 return 0;
116 pcie_device = to_pcie_device(device);
118 /* Forward error detected message to service drivers */
119 status = driver->err_handler->error_detected(
120 pcie_device->port,
121 result_data->state);
122 result_data->result =
123 merge_result(result_data->result, status);
126 return 0;
129 static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev,
130 enum pci_channel_state error)
132 struct aer_broadcast_data data = {error, PCI_ERS_RESULT_CAN_RECOVER};
133 int ret;
135 /* can not fail */
136 ret = device_for_each_child(&dev->dev, &data, error_detected_iter);
138 return data.result;
141 static int mmio_enabled_iter(struct device *device, void *data)
143 struct pcie_device *pcie_device;
144 struct pcie_port_service_driver *driver;
145 pci_ers_result_t status, *result;
147 result = (pci_ers_result_t *) data;
149 if (device->bus == &pcie_port_bus_type && device->driver) {
150 driver = to_service_driver(device->driver);
151 if (driver &&
152 driver->err_handler &&
153 driver->err_handler->mmio_enabled) {
154 pcie_device = to_pcie_device(device);
156 /* Forward error message to service drivers */
157 status = driver->err_handler->mmio_enabled(
158 pcie_device->port);
159 *result = merge_result(*result, status);
163 return 0;
166 static pci_ers_result_t pcie_portdrv_mmio_enabled(struct pci_dev *dev)
168 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
169 int retval;
171 /* get true return value from &status */
172 retval = device_for_each_child(&dev->dev, &status, mmio_enabled_iter);
173 return status;
176 static int slot_reset_iter(struct device *device, void *data)
178 struct pcie_device *pcie_device;
179 struct pcie_port_service_driver *driver;
180 pci_ers_result_t status, *result;
182 result = (pci_ers_result_t *) data;
184 if (device->bus == &pcie_port_bus_type && device->driver) {
185 driver = to_service_driver(device->driver);
186 if (driver &&
187 driver->err_handler &&
188 driver->err_handler->slot_reset) {
189 pcie_device = to_pcie_device(device);
191 /* Forward error message to service drivers */
192 status = driver->err_handler->slot_reset(
193 pcie_device->port);
194 *result = merge_result(*result, status);
198 return 0;
201 static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
203 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
204 int retval;
206 /* If fatal, restore cfg space for possible link reset at upstream */
207 if (dev->error_state == pci_channel_io_frozen) {
208 dev->state_saved = true;
209 pci_restore_state(dev);
210 pcie_portdrv_restore_config(dev);
211 pci_enable_pcie_error_reporting(dev);
214 /* get true return value from &status */
215 retval = device_for_each_child(&dev->dev, &status, slot_reset_iter);
217 return status;
220 static int resume_iter(struct device *device, void *data)
222 struct pcie_device *pcie_device;
223 struct pcie_port_service_driver *driver;
225 if (device->bus == &pcie_port_bus_type && device->driver) {
226 driver = to_service_driver(device->driver);
227 if (driver &&
228 driver->err_handler &&
229 driver->err_handler->resume) {
230 pcie_device = to_pcie_device(device);
232 /* Forward error message to service drivers */
233 driver->err_handler->resume(pcie_device->port);
237 return 0;
240 static void pcie_portdrv_err_resume(struct pci_dev *dev)
242 int retval;
243 /* nothing to do with error value, if it ever happens */
244 retval = device_for_each_child(&dev->dev, NULL, resume_iter);
248 * LINUX Device Driver Model
250 static const struct pci_device_id port_pci_ids[] = { {
251 /* handle any PCI-Express port */
252 PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
253 }, { /* end: all zeroes */ }
255 MODULE_DEVICE_TABLE(pci, port_pci_ids);
257 static struct pci_error_handlers pcie_portdrv_err_handler = {
258 .error_detected = pcie_portdrv_error_detected,
259 .mmio_enabled = pcie_portdrv_mmio_enabled,
260 .slot_reset = pcie_portdrv_slot_reset,
261 .resume = pcie_portdrv_err_resume,
264 static struct pci_driver pcie_portdriver = {
265 .name = "pcieport",
266 .id_table = &port_pci_ids[0],
268 .probe = pcie_portdrv_probe,
269 .remove = pcie_portdrv_remove,
271 .err_handler = &pcie_portdrv_err_handler,
273 .driver.pm = PCIE_PORTDRV_PM_OPS,
276 static int __init dmi_pcie_pme_disable_msi(const struct dmi_system_id *d)
278 pr_notice("%s detected: will not use MSI for PCIe PME signaling\n",
279 d->ident);
280 pcie_pme_disable_msi();
281 return 0;
284 static struct dmi_system_id __initdata pcie_portdrv_dmi_table[] = {
286 * Boxes that should not use MSI for PCIe PME signaling.
289 .callback = dmi_pcie_pme_disable_msi,
290 .ident = "MSI Wind U-100",
291 .matches = {
292 DMI_MATCH(DMI_SYS_VENDOR,
293 "MICRO-STAR INTERNATIONAL CO., LTD"),
294 DMI_MATCH(DMI_PRODUCT_NAME, "U-100"),
300 static int __init pcie_portdrv_init(void)
302 int retval;
304 dmi_check_system(pcie_portdrv_dmi_table);
306 retval = pcie_port_bus_register();
307 if (retval) {
308 printk(KERN_WARNING "PCIE: bus_register error: %d\n", retval);
309 goto out;
311 retval = pci_register_driver(&pcie_portdriver);
312 if (retval)
313 pcie_port_bus_unregister();
314 out:
315 return retval;
318 static void __exit pcie_portdrv_exit(void)
320 pci_unregister_driver(&pcie_portdriver);
321 pcie_port_bus_unregister();
324 module_init(pcie_portdrv_init);
325 module_exit(pcie_portdrv_exit);