9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
14 #include <linux/string.h>
15 #include <linux/slab.h>
31 __setup(
"pcie_hp=", pciehp_setup);
40 static void release_pcie_device(
struct device *
dev)
53 static int pcie_port_msix_add_entry(
54 struct msix_entry *
entries,
int new_entry,
int nr_entries)
58 for (j = 0; j < nr_entries; j++)
59 if (entries[j].
entry == new_entry)
62 entries[
j].entry = new_entry;
76 struct msix_entry *msix_entries;
88 msix_entries = kzalloc(
sizeof(*msix_entries) * nr_entries,
GFP_KERNEL);
98 for (i = 0; i < nr_entries; i++)
99 msix_entries[i].
entry = i;
123 pos = pci_pcie_cap(dev);
126 if (entry >= nr_entries)
129 i = pcie_port_msix_add_entry(msix_entries, entry, nvec);
152 if (entry >= nr_entries)
155 i = pcie_port_msix_add_entry(msix_entries, entry, nvec);
167 if (nvec == nr_entries) {
180 vectors[i] = idx[i] >= 0 ? msix_entries[idx[i]].
vector : -1;
199 static int init_service_irqs(
struct pci_dev *dev,
int *irqs,
int mask)
215 if (!pcie_port_enable_msix(dev, irqs, mask))
223 if (!pci_enable_msi(dev) || dev->
irq)
236 static void cleanup_service_irqs(
struct pci_dev *dev)
254 static int get_port_device_capability(
struct pci_dev *dev)
264 err = pcie_port_platform_notify(dev, &cap_mask);
266 cap_mask = PCIE_PORT_SERVICE_PME | PCIE_PORT_SERVICE_HP
275 if ((cap_mask & PCIE_PORT_SERVICE_HP) &&
290 if ((cap_mask & PCIE_PORT_SERVICE_AER)
303 if ((cap_mask & PCIE_PORT_SERVICE_PME)
323 static int pcie_device_init(
struct pci_dev *pdev,
int service,
int irq)
339 device->
release = release_pcie_device;
344 device_enable_async_suspend(device);
372 capabilities = get_port_device_capability(dev);
381 status = init_service_irqs(dev, irqs, capabilities);
392 int service = 1 <<
i;
393 if (!(capabilities & service))
395 if (!pcie_device_init(dev, service, irqs[i]))
399 goto error_cleanup_irqs;
404 cleanup_service_irqs(dev);
411 static int suspend_iter(
struct device *dev,
void *
data)
427 int pcie_port_device_suspend(
struct device *dev)
432 static int resume_iter(
struct device *dev,
void *data)
439 if (service_driver->
resume)
449 int pcie_port_device_resume(
struct device *dev)
455 static int remove_iter(
struct device *dev,
void *data)
474 cleanup_service_irqs(dev);
486 static int pcie_port_probe_service(
struct device *dev)
496 if (!driver || !driver->
probe)
500 status = driver->
probe(pciedev);
502 dev_printk(
KERN_DEBUG, dev,
"service driver %s loaded\n",
518 static int pcie_port_remove_service(
struct device *dev)
528 if (driver && driver->
remove) {
529 dev_printk(
KERN_DEBUG, dev,
"unloading service driver %s\n",
546 static void pcie_port_shutdown_service(
struct device *dev) {}
557 new->driver.name = (
char *)new->name;
559 new->driver.probe = pcie_port_probe_service;
560 new->driver.remove = pcie_port_remove_service;
561 new->driver.shutdown = pcie_port_shutdown_service;