PCI: PCIe portdrv: Remove unnecessary function
[linux-2.6/verdex.git] / drivers / pci / pcie / portdrv_pci.c
blob94d0e2af9bad96b4e961d3c1d00b2be32b2c7d42
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/slab.h>
16 #include <linux/pcieport_if.h>
17 #include <linux/aer.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 */
33 static const char device_name[] = "pcieport-driver";
35 static int pcie_portdrv_restore_config(struct pci_dev *dev)
37 int retval;
39 retval = pci_enable_device(dev);
40 if (retval)
41 return retval;
42 pci_set_master(dev);
43 return 0;
46 #ifdef CONFIG_PM
47 static int pcie_portdrv_suspend(struct pci_dev *dev, pm_message_t state)
49 return pcie_port_device_suspend(dev, state);
53 static int pcie_portdrv_resume(struct pci_dev *dev)
55 pci_set_master(dev);
56 return pcie_port_device_resume(dev);
58 #else
59 #define pcie_portdrv_suspend NULL
60 #define pcie_portdrv_resume NULL
61 #endif
64 * pcie_portdrv_probe - Probe PCI-Express port devices
65 * @dev: PCI-Express port device being probed
67 * If detected invokes the pcie_port_device_register() method for
68 * this port device.
71 static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
72 const struct pci_device_id *id )
74 int status;
76 status = pcie_port_device_probe(dev);
77 if (status)
78 return status;
80 if (!dev->irq && dev->pin) {
81 dev_warn(&dev->dev, "device [%04x:%04x] has invalid IRQ; "
82 "check vendor BIOS\n", dev->vendor, dev->device);
84 status = pcie_port_device_register(dev);
85 if (status)
86 return status;
88 pci_save_state(dev);
90 return 0;
93 static void pcie_portdrv_remove (struct pci_dev *dev)
95 pcie_port_device_remove(dev);
96 pci_disable_device(dev);
97 kfree(pci_get_drvdata(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 result_data =
133 {error, PCI_ERS_RESULT_CAN_RECOVER};
134 int retval;
136 /* can not fail */
137 retval = device_for_each_child(&dev->dev, &result_data, error_detected_iter);
139 return result_data.result;
142 static int mmio_enabled_iter(struct device *device, void *data)
144 struct pcie_device *pcie_device;
145 struct pcie_port_service_driver *driver;
146 pci_ers_result_t status, *result;
148 result = (pci_ers_result_t *) data;
150 if (device->bus == &pcie_port_bus_type && device->driver) {
151 driver = to_service_driver(device->driver);
152 if (driver &&
153 driver->err_handler &&
154 driver->err_handler->mmio_enabled) {
155 pcie_device = to_pcie_device(device);
157 /* Forward error message to service drivers */
158 status = driver->err_handler->mmio_enabled(
159 pcie_device->port);
160 *result = merge_result(*result, status);
164 return 0;
167 static pci_ers_result_t pcie_portdrv_mmio_enabled(struct pci_dev *dev)
169 pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
170 int retval;
172 /* get true return value from &status */
173 retval = device_for_each_child(&dev->dev, &status, mmio_enabled_iter);
174 return status;
177 static int slot_reset_iter(struct device *device, void *data)
179 struct pcie_device *pcie_device;
180 struct pcie_port_service_driver *driver;
181 pci_ers_result_t status, *result;
183 result = (pci_ers_result_t *) data;
185 if (device->bus == &pcie_port_bus_type && device->driver) {
186 driver = to_service_driver(device->driver);
187 if (driver &&
188 driver->err_handler &&
189 driver->err_handler->slot_reset) {
190 pcie_device = to_pcie_device(device);
192 /* Forward error message to service drivers */
193 status = driver->err_handler->slot_reset(
194 pcie_device->port);
195 *result = merge_result(*result, status);
199 return 0;
202 static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
204 pci_ers_result_t status = PCI_ERS_RESULT_NONE;
205 int retval;
207 /* If fatal, restore cfg space for possible link reset at upstream */
208 if (dev->error_state == pci_channel_io_frozen) {
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 = (char *)device_name,
266 .id_table = &port_pci_ids[0],
268 .probe = pcie_portdrv_probe,
269 .remove = pcie_portdrv_remove,
271 .suspend = pcie_portdrv_suspend,
272 .resume = pcie_portdrv_resume,
274 .err_handler = &pcie_portdrv_err_handler,
277 static int __init pcie_portdrv_init(void)
279 int retval;
281 retval = pcie_port_bus_register();
282 if (retval) {
283 printk(KERN_WARNING "PCIE: bus_register error: %d\n", retval);
284 goto out;
286 retval = pci_register_driver(&pcie_portdriver);
287 if (retval)
288 pcie_port_bus_unregister();
289 out:
290 return retval;
293 static void __exit pcie_portdrv_exit(void)
295 pci_unregister_driver(&pcie_portdriver);
296 pcie_port_bus_unregister();
299 module_init(pcie_portdrv_init);
300 module_exit(pcie_portdrv_exit);