Lines Matching +full:data +full:- +full:bus

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2007 - 2009 Intel Corp
6 * Copyright (C) 2007 - 2009 Shaohua Li <shaohua.li@intel.com>
28 * that using MSI for PCIe PME signaling doesn't play well with PCIe PME-based
29 * wake-up from system sleep states.
50 * pcie_pme_interrupt_enable - Enable/disable PCIe PME interrupt generation.
65 * pcie_pme_walk_bus - Scan a PCI bus for devices asserting PME#.
66 * @bus: PCI bus to scan.
68 * Scan given PCI bus and all buses under it for devices asserting PME#.
70 static bool pcie_pme_walk_bus(struct pci_bus *bus) in pcie_pme_walk_bus() argument
75 list_for_each_entry(dev, &bus->devices, bus_list) { in pcie_pme_walk_bus()
78 if (dev->pme_poll) in pcie_pme_walk_bus()
79 dev->pme_poll = false; in pcie_pme_walk_bus()
82 pm_request_resume(&dev->dev); in pcie_pme_walk_bus()
86 if (dev->subordinate && pcie_pme_walk_bus(dev->subordinate)) in pcie_pme_walk_bus()
94 * pcie_pme_from_pci_bridge - Check if PCIe-PCI bridge generated a PME.
95 * @bus: Secondary bus of the bridge.
98 * PME from PCI devices under a PCIe-PCI bridge may be converted to an in-band
100 * of device/function number 0 on its secondary bus.
102 static bool pcie_pme_from_pci_bridge(struct pci_bus *bus, u8 devfn) in pcie_pme_from_pci_bridge() argument
110 dev = pci_dev_get(bus->self); in pcie_pme_from_pci_bridge()
116 if (pcie_pme_walk_bus(bus)) in pcie_pme_from_pci_bridge()
126 * pcie_pme_handle_request - Find device that generated PME and handle it.
133 struct pci_bus *bus; in pcie_pme_handle_request() local
138 if (port->devfn == devfn && port->bus->number == busnr) { in pcie_pme_handle_request()
139 if (port->pme_poll) in pcie_pme_handle_request()
140 port->pme_poll = false; in pcie_pme_handle_request()
143 pm_request_resume(&port->dev); in pcie_pme_handle_request()
148 * of a non-PCIe device downstream. If this is done by in pcie_pme_handle_request()
155 found = pcie_pme_walk_bus(port->subordinate); in pcie_pme_handle_request()
161 /* Second, find the bus the source device is on. */ in pcie_pme_handle_request()
162 bus = pci_find_bus(pci_domain_nr(port->bus), busnr); in pcie_pme_handle_request()
163 if (!bus) in pcie_pme_handle_request()
166 /* Next, check if the PME is from a PCIe-PCI bridge. */ in pcie_pme_handle_request()
167 found = pcie_pme_from_pci_bridge(bus, devfn); in pcie_pme_handle_request()
171 /* Finally, try to find the PME source on the bus. */ in pcie_pme_handle_request()
173 list_for_each_entry(dev, &bus->devices, bus_list) { in pcie_pme_handle_request()
175 if (dev->devfn == devfn) { in pcie_pme_handle_request()
187 if (dev->pme_poll) in pcie_pme_handle_request()
188 dev->pme_poll = false; in pcie_pme_handle_request()
191 pm_request_resume(&dev->dev); in pcie_pme_handle_request()
197 * assuming that the PME was reported by a PCIe-PCI bridge that in pcie_pme_handle_request()
200 pci_info(port, "interrupt generated for non-existent device %02x:%02x.%d\n", in pcie_pme_handle_request()
202 found = pcie_pme_from_pci_bridge(bus, 0); in pcie_pme_handle_request()
211 * pcie_pme_work_fn - Work handler for PCIe PME interrupt.
212 * @work: Work structure giving access to service data.
216 struct pcie_pme_service_data *data = in pcie_pme_work_fn() local
218 struct pci_dev *port = data->srv->port; in pcie_pme_work_fn()
221 spin_lock_irq(&data->lock); in pcie_pme_work_fn()
224 if (data->noirq) in pcie_pme_work_fn()
238 spin_unlock_irq(&data->lock); in pcie_pme_work_fn()
241 spin_lock_irq(&data->lock); in pcie_pme_work_fn()
250 spin_unlock_irq(&data->lock); in pcie_pme_work_fn()
252 spin_lock_irq(&data->lock); in pcie_pme_work_fn()
255 if (!data->noirq) in pcie_pme_work_fn()
258 spin_unlock_irq(&data->lock); in pcie_pme_work_fn()
262 * pcie_pme_irq - Interrupt handler for PCIe root port PME interrupt.
269 struct pcie_pme_service_data *data; in pcie_pme_irq() local
273 port = ((struct pcie_device *)context)->port; in pcie_pme_irq()
274 data = get_service_data((struct pcie_device *)context); in pcie_pme_irq()
276 spin_lock_irqsave(&data->lock, flags); in pcie_pme_irq()
280 spin_unlock_irqrestore(&data->lock, flags); in pcie_pme_irq()
285 spin_unlock_irqrestore(&data->lock, flags); in pcie_pme_irq()
288 schedule_work(&data->work); in pcie_pme_irq()
294 * pcie_pme_can_wakeup - Set the wakeup capability flag.
300 device_set_wakeup_capable(&dev->dev, true); in pcie_pme_can_wakeup()
305 * pcie_pme_mark_devices - Set the wakeup flag for devices below a port.
310 * set the flag indicating that it can signal run-time wake-up events.
318 else if (port->subordinate) in pcie_pme_mark_devices()
319 pci_walk_bus(port->subordinate, pcie_pme_can_wakeup, NULL); in pcie_pme_mark_devices()
323 * pcie_pme_probe - Initialize PCIe PME service for given root port.
328 struct pci_dev *port = srv->port; in pcie_pme_probe()
329 struct pcie_pme_service_data *data; in pcie_pme_probe() local
336 return -ENODEV; in pcie_pme_probe()
338 data = kzalloc(sizeof(*data), GFP_KERNEL); in pcie_pme_probe()
339 if (!data) in pcie_pme_probe()
340 return -ENOMEM; in pcie_pme_probe()
342 spin_lock_init(&data->lock); in pcie_pme_probe()
343 INIT_WORK(&data->work, pcie_pme_work_fn); in pcie_pme_probe()
344 data->srv = srv; in pcie_pme_probe()
345 set_service_data(srv, data); in pcie_pme_probe()
350 ret = request_irq(srv->irq, pcie_pme_irq, IRQF_SHARED, "PCIe PME", srv); in pcie_pme_probe()
352 kfree(data); in pcie_pme_probe()
356 pci_info(port, "Signaling with IRQ %d\n", srv->irq); in pcie_pme_probe()
363 static bool pcie_pme_check_wakeup(struct pci_bus *bus) in pcie_pme_check_wakeup() argument
367 if (!bus) in pcie_pme_check_wakeup()
370 list_for_each_entry(dev, &bus->devices, bus_list) in pcie_pme_check_wakeup()
371 if (device_may_wakeup(&dev->dev) in pcie_pme_check_wakeup()
372 || pcie_pme_check_wakeup(dev->subordinate)) in pcie_pme_check_wakeup()
379 struct pcie_pme_service_data *data) in pcie_pme_disable_interrupt() argument
381 spin_lock_irq(&data->lock); in pcie_pme_disable_interrupt()
384 data->noirq = true; in pcie_pme_disable_interrupt()
385 spin_unlock_irq(&data->lock); in pcie_pme_disable_interrupt()
389 * pcie_pme_suspend - Suspend PCIe PME service device.
394 struct pcie_pme_service_data *data = get_service_data(srv); in pcie_pme_suspend() local
395 struct pci_dev *port = srv->port; in pcie_pme_suspend()
399 if (device_may_wakeup(&port->dev)) { in pcie_pme_suspend()
403 wakeup = pcie_pme_check_wakeup(port->subordinate); in pcie_pme_suspend()
407 ret = enable_irq_wake(srv->irq); in pcie_pme_suspend()
412 pcie_pme_disable_interrupt(port, data); in pcie_pme_suspend()
414 synchronize_irq(srv->irq); in pcie_pme_suspend()
420 * pcie_pme_resume - Resume PCIe PME service device.
425 struct pcie_pme_service_data *data = get_service_data(srv); in pcie_pme_resume() local
427 spin_lock_irq(&data->lock); in pcie_pme_resume()
428 if (data->noirq) { in pcie_pme_resume()
429 struct pci_dev *port = srv->port; in pcie_pme_resume()
433 data->noirq = false; in pcie_pme_resume()
435 disable_irq_wake(srv->irq); in pcie_pme_resume()
437 spin_unlock_irq(&data->lock); in pcie_pme_resume()
443 * pcie_pme_remove - Prepare PCIe PME service device for removal.
448 struct pcie_pme_service_data *data = get_service_data(srv); in pcie_pme_remove() local
450 pcie_pme_disable_interrupt(srv->port, data); in pcie_pme_remove()
451 free_irq(srv->irq, srv); in pcie_pme_remove()
452 cancel_work_sync(&data->work); in pcie_pme_remove()
453 kfree(data); in pcie_pme_remove()
468 * pcie_pme_init - Register the PCIe PME service driver.