mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 22:21:40 +00:00
5a0e3ad6af
percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
326 lines
7.6 KiB
C
326 lines
7.6 KiB
C
/*
|
|
* File: portdrv_pci.c
|
|
* Purpose: PCI Express Port Bus Driver
|
|
*
|
|
* Copyright (C) 2004 Intel
|
|
* Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/pci.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/pm.h>
|
|
#include <linux/init.h>
|
|
#include <linux/pcieport_if.h>
|
|
#include <linux/aer.h>
|
|
#include <linux/dmi.h>
|
|
|
|
#include "portdrv.h"
|
|
#include "aer/aerdrv.h"
|
|
|
|
/*
|
|
* Version Information
|
|
*/
|
|
#define DRIVER_VERSION "v1.0"
|
|
#define DRIVER_AUTHOR "tom.l.nguyen@intel.com"
|
|
#define DRIVER_DESC "PCIe Port Bus Driver"
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
MODULE_LICENSE("GPL");
|
|
|
|
/* global data */
|
|
|
|
static int pcie_portdrv_restore_config(struct pci_dev *dev)
|
|
{
|
|
int retval;
|
|
|
|
retval = pci_enable_device(dev);
|
|
if (retval)
|
|
return retval;
|
|
pci_set_master(dev);
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_PM
|
|
static const struct dev_pm_ops pcie_portdrv_pm_ops = {
|
|
.suspend = pcie_port_device_suspend,
|
|
.resume = pcie_port_device_resume,
|
|
.freeze = pcie_port_device_suspend,
|
|
.thaw = pcie_port_device_resume,
|
|
.poweroff = pcie_port_device_suspend,
|
|
.restore = pcie_port_device_resume,
|
|
};
|
|
|
|
#define PCIE_PORTDRV_PM_OPS (&pcie_portdrv_pm_ops)
|
|
|
|
#else /* !PM */
|
|
|
|
#define PCIE_PORTDRV_PM_OPS NULL
|
|
#endif /* !PM */
|
|
|
|
/*
|
|
* pcie_portdrv_probe - Probe PCI-Express port devices
|
|
* @dev: PCI-Express port device being probed
|
|
*
|
|
* If detected invokes the pcie_port_device_register() method for
|
|
* this port device.
|
|
*
|
|
*/
|
|
static int __devinit pcie_portdrv_probe(struct pci_dev *dev,
|
|
const struct pci_device_id *id)
|
|
{
|
|
int status;
|
|
|
|
if (!pci_is_pcie(dev) ||
|
|
((dev->pcie_type != PCI_EXP_TYPE_ROOT_PORT) &&
|
|
(dev->pcie_type != PCI_EXP_TYPE_UPSTREAM) &&
|
|
(dev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)))
|
|
return -ENODEV;
|
|
|
|
if (!dev->irq && dev->pin) {
|
|
dev_warn(&dev->dev, "device [%04x:%04x] has invalid IRQ; "
|
|
"check vendor BIOS\n", dev->vendor, dev->device);
|
|
}
|
|
status = pcie_port_device_register(dev);
|
|
if (status)
|
|
return status;
|
|
|
|
pci_save_state(dev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void pcie_portdrv_remove(struct pci_dev *dev)
|
|
{
|
|
pcie_port_device_remove(dev);
|
|
pci_disable_device(dev);
|
|
}
|
|
|
|
static int error_detected_iter(struct device *device, void *data)
|
|
{
|
|
struct pcie_device *pcie_device;
|
|
struct pcie_port_service_driver *driver;
|
|
struct aer_broadcast_data *result_data;
|
|
pci_ers_result_t status;
|
|
|
|
result_data = (struct aer_broadcast_data *) data;
|
|
|
|
if (device->bus == &pcie_port_bus_type && device->driver) {
|
|
driver = to_service_driver(device->driver);
|
|
if (!driver ||
|
|
!driver->err_handler ||
|
|
!driver->err_handler->error_detected)
|
|
return 0;
|
|
|
|
pcie_device = to_pcie_device(device);
|
|
|
|
/* Forward error detected message to service drivers */
|
|
status = driver->err_handler->error_detected(
|
|
pcie_device->port,
|
|
result_data->state);
|
|
result_data->result =
|
|
merge_result(result_data->result, status);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev,
|
|
enum pci_channel_state error)
|
|
{
|
|
struct aer_broadcast_data data = {error, PCI_ERS_RESULT_CAN_RECOVER};
|
|
int ret;
|
|
|
|
/* can not fail */
|
|
ret = device_for_each_child(&dev->dev, &data, error_detected_iter);
|
|
|
|
return data.result;
|
|
}
|
|
|
|
static int mmio_enabled_iter(struct device *device, void *data)
|
|
{
|
|
struct pcie_device *pcie_device;
|
|
struct pcie_port_service_driver *driver;
|
|
pci_ers_result_t status, *result;
|
|
|
|
result = (pci_ers_result_t *) data;
|
|
|
|
if (device->bus == &pcie_port_bus_type && device->driver) {
|
|
driver = to_service_driver(device->driver);
|
|
if (driver &&
|
|
driver->err_handler &&
|
|
driver->err_handler->mmio_enabled) {
|
|
pcie_device = to_pcie_device(device);
|
|
|
|
/* Forward error message to service drivers */
|
|
status = driver->err_handler->mmio_enabled(
|
|
pcie_device->port);
|
|
*result = merge_result(*result, status);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static pci_ers_result_t pcie_portdrv_mmio_enabled(struct pci_dev *dev)
|
|
{
|
|
pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
|
|
int retval;
|
|
|
|
/* get true return value from &status */
|
|
retval = device_for_each_child(&dev->dev, &status, mmio_enabled_iter);
|
|
return status;
|
|
}
|
|
|
|
static int slot_reset_iter(struct device *device, void *data)
|
|
{
|
|
struct pcie_device *pcie_device;
|
|
struct pcie_port_service_driver *driver;
|
|
pci_ers_result_t status, *result;
|
|
|
|
result = (pci_ers_result_t *) data;
|
|
|
|
if (device->bus == &pcie_port_bus_type && device->driver) {
|
|
driver = to_service_driver(device->driver);
|
|
if (driver &&
|
|
driver->err_handler &&
|
|
driver->err_handler->slot_reset) {
|
|
pcie_device = to_pcie_device(device);
|
|
|
|
/* Forward error message to service drivers */
|
|
status = driver->err_handler->slot_reset(
|
|
pcie_device->port);
|
|
*result = merge_result(*result, status);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
|
|
{
|
|
pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
|
|
int retval;
|
|
|
|
/* If fatal, restore cfg space for possible link reset at upstream */
|
|
if (dev->error_state == pci_channel_io_frozen) {
|
|
dev->state_saved = true;
|
|
pci_restore_state(dev);
|
|
pcie_portdrv_restore_config(dev);
|
|
pci_enable_pcie_error_reporting(dev);
|
|
}
|
|
|
|
/* get true return value from &status */
|
|
retval = device_for_each_child(&dev->dev, &status, slot_reset_iter);
|
|
|
|
return status;
|
|
}
|
|
|
|
static int resume_iter(struct device *device, void *data)
|
|
{
|
|
struct pcie_device *pcie_device;
|
|
struct pcie_port_service_driver *driver;
|
|
|
|
if (device->bus == &pcie_port_bus_type && device->driver) {
|
|
driver = to_service_driver(device->driver);
|
|
if (driver &&
|
|
driver->err_handler &&
|
|
driver->err_handler->resume) {
|
|
pcie_device = to_pcie_device(device);
|
|
|
|
/* Forward error message to service drivers */
|
|
driver->err_handler->resume(pcie_device->port);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void pcie_portdrv_err_resume(struct pci_dev *dev)
|
|
{
|
|
int retval;
|
|
/* nothing to do with error value, if it ever happens */
|
|
retval = device_for_each_child(&dev->dev, NULL, resume_iter);
|
|
}
|
|
|
|
/*
|
|
* LINUX Device Driver Model
|
|
*/
|
|
static const struct pci_device_id port_pci_ids[] = { {
|
|
/* handle any PCI-Express port */
|
|
PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
|
|
}, { /* end: all zeroes */ }
|
|
};
|
|
MODULE_DEVICE_TABLE(pci, port_pci_ids);
|
|
|
|
static struct pci_error_handlers pcie_portdrv_err_handler = {
|
|
.error_detected = pcie_portdrv_error_detected,
|
|
.mmio_enabled = pcie_portdrv_mmio_enabled,
|
|
.slot_reset = pcie_portdrv_slot_reset,
|
|
.resume = pcie_portdrv_err_resume,
|
|
};
|
|
|
|
static struct pci_driver pcie_portdriver = {
|
|
.name = "pcieport",
|
|
.id_table = &port_pci_ids[0],
|
|
|
|
.probe = pcie_portdrv_probe,
|
|
.remove = pcie_portdrv_remove,
|
|
|
|
.err_handler = &pcie_portdrv_err_handler,
|
|
|
|
.driver.pm = PCIE_PORTDRV_PM_OPS,
|
|
};
|
|
|
|
static int __init dmi_pcie_pme_disable_msi(const struct dmi_system_id *d)
|
|
{
|
|
pr_notice("%s detected: will not use MSI for PCIe PME signaling\n",
|
|
d->ident);
|
|
pcie_pme_disable_msi();
|
|
return 0;
|
|
}
|
|
|
|
static struct dmi_system_id __initdata pcie_portdrv_dmi_table[] = {
|
|
/*
|
|
* Boxes that should not use MSI for PCIe PME signaling.
|
|
*/
|
|
{
|
|
.callback = dmi_pcie_pme_disable_msi,
|
|
.ident = "MSI Wind U-100",
|
|
.matches = {
|
|
DMI_MATCH(DMI_SYS_VENDOR,
|
|
"MICRO-STAR INTERNATIONAL CO., LTD"),
|
|
DMI_MATCH(DMI_PRODUCT_NAME, "U-100"),
|
|
},
|
|
},
|
|
{}
|
|
};
|
|
|
|
static int __init pcie_portdrv_init(void)
|
|
{
|
|
int retval;
|
|
|
|
dmi_check_system(pcie_portdrv_dmi_table);
|
|
|
|
retval = pcie_port_bus_register();
|
|
if (retval) {
|
|
printk(KERN_WARNING "PCIE: bus_register error: %d\n", retval);
|
|
goto out;
|
|
}
|
|
retval = pci_register_driver(&pcie_portdriver);
|
|
if (retval)
|
|
pcie_port_bus_unregister();
|
|
out:
|
|
return retval;
|
|
}
|
|
|
|
static void __exit pcie_portdrv_exit(void)
|
|
{
|
|
pci_unregister_driver(&pcie_portdriver);
|
|
pcie_port_bus_unregister();
|
|
}
|
|
|
|
module_init(pcie_portdrv_init);
|
|
module_exit(pcie_portdrv_exit);
|