drivers/pci/xen-pcifront.c
Source file repositories/reference/linux-study-clean/drivers/pci/xen-pcifront.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pci/xen-pcifront.c- Extension
.c- Size
- 26183 bytes
- Lines
- 1095
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/init.hlinux/mm.hxen/xenbus.hxen/events.hxen/grant_table.hxen/page.hlinux/spinlock.hlinux/pci.hlinux/msi.hxen/interface/io/pciif.hasm/xen/pci.hlinux/interrupt.hlinux/atomic.hlinux/workqueue.hlinux/bitops.hlinux/time.hlinux/ktime.hxen/platform_pci.hasm/xen/swiotlb-xen.h
Detected Declarations
struct pci_bus_entrystruct pcifront_devicestruct pcifront_sdfunction pcifront_get_pdevfunction pcifront_init_sdfunction errno_to_pcibios_errfunction schedule_pcifront_aer_opfunction do_pci_opfunction pcifront_bus_readfunction pcifront_bus_writefunction pci_frontend_enable_msixfunction pci_frontend_disable_msixfunction pci_frontend_enable_msifunction pci_frontend_disable_msifunction pci_frontend_registrarfunction pci_frontend_registrarfunction pcifront_claim_resourcefunction pci_dev_for_each_resourcefunction pcifront_scan_busfunction pcifront_scan_rootfunction pcifront_rescan_rootfunction free_root_bus_devsfunction pcifront_free_rootsfunction pcifront_common_processfunction pcifront_do_aerfunction pcifront_handler_aerfunction pcifront_connect_and_init_dmafunction pcifront_disconnectfunction free_pdevfunction pcifront_publish_infofunction pcifront_connectfunction pcifront_try_connectfunction pcifront_try_disconnectfunction pcifront_attach_devicesfunction pcifront_detach_devicesfunction pcifront_backend_changedfunction pcifront_xenbus_probefunction pcifront_xenbus_removefunction pcifront_initfunction pcifront_cleanupmodule init pcifront_init
Annotated Snippet
struct pci_driver *pdrv;
int bus = pdev->sh_info->aer_op.bus;
int devfn = pdev->sh_info->aer_op.devfn;
int domain = pdev->sh_info->aer_op.domain;
struct pci_dev *pcidev;
dev_dbg(&pdev->xdev->dev,
"pcifront AER process: cmd %x (bus:%x, devfn%x)",
cmd, bus, devfn);
pcidev = pci_get_domain_bus_and_slot(domain, bus, devfn);
if (!pcidev || !pcidev->dev.driver) {
dev_err(&pdev->xdev->dev, "device or AER driver is NULL\n");
pci_dev_put(pcidev);
return PCI_ERS_RESULT_NONE;
}
pdrv = to_pci_driver(pcidev->dev.driver);
if (pdrv->err_handler && pdrv->err_handler->error_detected) {
pci_dbg(pcidev, "trying to call AER service\n");
switch (cmd) {
case XEN_PCI_OP_aer_detected:
return pdrv->err_handler->error_detected(pcidev, state);
case XEN_PCI_OP_aer_mmio:
return pdrv->err_handler->mmio_enabled(pcidev);
case XEN_PCI_OP_aer_slotreset:
return pdrv->err_handler->slot_reset(pcidev);
case XEN_PCI_OP_aer_resume:
pdrv->err_handler->resume(pcidev);
return PCI_ERS_RESULT_NONE;
default:
dev_err(&pdev->xdev->dev,
"bad request in aer recovery operation!\n");
}
}
return PCI_ERS_RESULT_NONE;
}
static void pcifront_do_aer(struct work_struct *data)
{
struct pcifront_device *pdev =
container_of(data, struct pcifront_device, op_work);
int cmd = pdev->sh_info->aer_op.cmd;
pci_channel_state_t state =
(pci_channel_state_t)pdev->sh_info->aer_op.err;
/*
* If a pci_conf op is in progress, we have to wait until it is done
* before service aer op
*/
dev_dbg(&pdev->xdev->dev,
"pcifront service aer bus %x devfn %x\n",
pdev->sh_info->aer_op.bus, pdev->sh_info->aer_op.devfn);
pdev->sh_info->aer_op.err = pcifront_common_process(cmd, pdev, state);
/* Post the operation to the guest. */
wmb();
clear_bit(_XEN_PCIB_active, (unsigned long *)&pdev->sh_info->flags);
notify_remote_via_evtchn(pdev->evtchn);
/*in case of we lost an aer request in four lines time_window*/
smp_mb__before_atomic();
clear_bit(_PDEVB_op_active, &pdev->flags);
smp_mb__after_atomic();
schedule_pcifront_aer_op(pdev);
}
static irqreturn_t pcifront_handler_aer(int irq, void *dev)
{
struct pcifront_device *pdev = dev;
schedule_pcifront_aer_op(pdev);
return IRQ_HANDLED;
}
static int pcifront_connect_and_init_dma(struct pcifront_device *pdev)
{
int err = 0;
spin_lock(&pcifront_dev_lock);
if (!pcifront_dev) {
dev_info(&pdev->xdev->dev, "Installing PCI frontend\n");
pcifront_dev = pdev;
} else
err = -EEXIST;
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/mm.h`, `xen/xenbus.h`, `xen/events.h`, `xen/grant_table.h`, `xen/page.h`, `linux/spinlock.h`.
- Detected declarations: `struct pci_bus_entry`, `struct pcifront_device`, `struct pcifront_sd`, `function pcifront_get_pdev`, `function pcifront_init_sd`, `function errno_to_pcibios_err`, `function schedule_pcifront_aer_op`, `function do_pci_op`, `function pcifront_bus_read`, `function pcifront_bus_write`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.