3 * Purpose: PCI Express Port Bus Driver
5 * Copyright (C) 2004 Intel
6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/pcieport_if.h>
17 #include <linux/aer.h>
18 #include <linux/dmi.h>
21 #include "aer/aerdrv.h"
26 #define DRIVER_VERSION "v1.0"
27 #define DRIVER_AUTHOR "tom.l.nguyen@intel.com"
28 #define DRIVER_DESC "PCIe Port Bus Driver"
29 MODULE_AUTHOR(DRIVER_AUTHOR
);
30 MODULE_DESCRIPTION(DRIVER_DESC
);
31 MODULE_LICENSE("GPL");
35 static int pcie_portdrv_restore_config(struct pci_dev
*dev
)
39 retval
= pci_enable_device(dev
);
47 static const struct dev_pm_ops pcie_portdrv_pm_ops
= {
48 .suspend
= pcie_port_device_suspend
,
49 .resume
= pcie_port_device_resume
,
50 .freeze
= pcie_port_device_suspend
,
51 .thaw
= pcie_port_device_resume
,
52 .poweroff
= pcie_port_device_suspend
,
53 .restore
= pcie_port_device_resume
,
56 #define PCIE_PORTDRV_PM_OPS (&pcie_portdrv_pm_ops)
60 #define PCIE_PORTDRV_PM_OPS NULL
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
71 static int __devinit
pcie_portdrv_probe(struct pci_dev
*dev
,
72 const struct pci_device_id
*id
)
76 if (!pci_is_pcie(dev
) ||
77 ((dev
->pcie_type
!= PCI_EXP_TYPE_ROOT_PORT
) &&
78 (dev
->pcie_type
!= PCI_EXP_TYPE_UPSTREAM
) &&
79 (dev
->pcie_type
!= PCI_EXP_TYPE_DOWNSTREAM
)))
82 if (!dev
->irq
&& dev
->pin
) {
83 dev_warn(&dev
->dev
, "device [%04x:%04x] has invalid IRQ; "
84 "check vendor BIOS\n", dev
->vendor
, dev
->device
);
86 status
= pcie_port_device_register(dev
);
95 static void pcie_portdrv_remove(struct pci_dev
*dev
)
97 pcie_port_device_remove(dev
);
98 pci_disable_device(dev
);
101 static int error_detected_iter(struct device
*device
, void *data
)
103 struct pcie_device
*pcie_device
;
104 struct pcie_port_service_driver
*driver
;
105 struct aer_broadcast_data
*result_data
;
106 pci_ers_result_t status
;
108 result_data
= (struct aer_broadcast_data
*) data
;
110 if (device
->bus
== &pcie_port_bus_type
&& device
->driver
) {
111 driver
= to_service_driver(device
->driver
);
113 !driver
->err_handler
||
114 !driver
->err_handler
->error_detected
)
117 pcie_device
= to_pcie_device(device
);
119 /* Forward error detected message to service drivers */
120 status
= driver
->err_handler
->error_detected(
123 result_data
->result
=
124 merge_result(result_data
->result
, status
);
130 static pci_ers_result_t
pcie_portdrv_error_detected(struct pci_dev
*dev
,
131 enum pci_channel_state error
)
133 struct aer_broadcast_data data
= {error
, PCI_ERS_RESULT_CAN_RECOVER
};
137 ret
= device_for_each_child(&dev
->dev
, &data
, error_detected_iter
);
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
);
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(
160 *result
= merge_result(*result
, status
);
167 static pci_ers_result_t
pcie_portdrv_mmio_enabled(struct pci_dev
*dev
)
169 pci_ers_result_t status
= PCI_ERS_RESULT_RECOVERED
;
172 /* get true return value from &status */
173 retval
= device_for_each_child(&dev
->dev
, &status
, mmio_enabled_iter
);
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
);
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(
195 *result
= merge_result(*result
, status
);
202 static pci_ers_result_t
pcie_portdrv_slot_reset(struct pci_dev
*dev
)
204 pci_ers_result_t status
= PCI_ERS_RESULT_RECOVERED
;
207 /* If fatal, restore cfg space for possible link reset at upstream */
208 if (dev
->error_state
== pci_channel_io_frozen
) {
209 dev
->state_saved
= true;
210 pci_restore_state(dev
);
211 pcie_portdrv_restore_config(dev
);
212 pci_enable_pcie_error_reporting(dev
);
215 /* get true return value from &status */
216 retval
= device_for_each_child(&dev
->dev
, &status
, slot_reset_iter
);
221 static int resume_iter(struct device
*device
, void *data
)
223 struct pcie_device
*pcie_device
;
224 struct pcie_port_service_driver
*driver
;
226 if (device
->bus
== &pcie_port_bus_type
&& device
->driver
) {
227 driver
= to_service_driver(device
->driver
);
229 driver
->err_handler
&&
230 driver
->err_handler
->resume
) {
231 pcie_device
= to_pcie_device(device
);
233 /* Forward error message to service drivers */
234 driver
->err_handler
->resume(pcie_device
->port
);
241 static void pcie_portdrv_err_resume(struct pci_dev
*dev
)
244 /* nothing to do with error value, if it ever happens */
245 retval
= device_for_each_child(&dev
->dev
, NULL
, resume_iter
);
249 * LINUX Device Driver Model
251 static const struct pci_device_id port_pci_ids
[] = { {
252 /* handle any PCI-Express port */
253 PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI
<< 8) | 0x00), ~0),
254 }, { /* end: all zeroes */ }
256 MODULE_DEVICE_TABLE(pci
, port_pci_ids
);
258 static struct pci_error_handlers pcie_portdrv_err_handler
= {
259 .error_detected
= pcie_portdrv_error_detected
,
260 .mmio_enabled
= pcie_portdrv_mmio_enabled
,
261 .slot_reset
= pcie_portdrv_slot_reset
,
262 .resume
= pcie_portdrv_err_resume
,
265 static struct pci_driver pcie_portdriver
= {
267 .id_table
= &port_pci_ids
[0],
269 .probe
= pcie_portdrv_probe
,
270 .remove
= pcie_portdrv_remove
,
272 .err_handler
= &pcie_portdrv_err_handler
,
274 .driver
.pm
= PCIE_PORTDRV_PM_OPS
,
277 static int __init
dmi_pcie_pme_disable_msi(const struct dmi_system_id
*d
)
279 pr_notice("%s detected: will not use MSI for PCIe PME signaling\n",
281 pcie_pme_disable_msi();
285 static struct dmi_system_id __initdata pcie_portdrv_dmi_table
[] = {
287 * Boxes that should not use MSI for PCIe PME signaling.
290 .callback
= dmi_pcie_pme_disable_msi
,
291 .ident
= "MSI Wind U-100",
293 DMI_MATCH(DMI_SYS_VENDOR
,
294 "MICRO-STAR INTERNATIONAL CO., LTD"),
295 DMI_MATCH(DMI_PRODUCT_NAME
, "U-100"),
301 static int __init
pcie_portdrv_init(void)
305 dmi_check_system(pcie_portdrv_dmi_table
);
307 retval
= pcie_port_bus_register();
309 printk(KERN_WARNING
"PCIE: bus_register error: %d\n", retval
);
312 retval
= pci_register_driver(&pcie_portdriver
);
314 pcie_port_bus_unregister();
319 static void __exit
pcie_portdrv_exit(void)
321 pci_unregister_driver(&pcie_portdriver
);
322 pcie_port_bus_unregister();
325 module_init(pcie_portdrv_init
);
326 module_exit(pcie_portdrv_exit
);