drivers/xen/xen-pciback/pci_stub.c
Source file repositories/reference/linux-study-clean/drivers/xen/xen-pciback/pci_stub.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/xen-pciback/pci_stub.c- Extension
.c- Size
- 43859 bytes
- Lines
- 1767
- Domain
- Driver Families
- Bucket
- drivers/xen
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/rwsem.hlinux/list.hlinux/spinlock.hlinux/kref.hlinux/pci.hlinux/wait.hlinux/sched.hlinux/atomic.hxen/events.hxen/pci.hxen/xen.hxen/acpi.hasm/xen/hypervisor.hxen/interface/physdev.hpciback.hconf_space.hconf_space_quirks.h
Detected Declarations
struct pcistub_device_idstruct pcistub_devicefunction pcistub_reset_device_statefunction pcistub_device_releasefunction pcistub_device_getfunction pcistub_device_putfunction list_for_each_entryfunction pcistub_get_gsi_from_sbdffunction pcistub_put_pci_devfunction list_for_each_entryfunction pcistub_match_onefunction pcistub_matchfunction pcistub_init_devicefunction pcistub_init_devices_latefunction pcistub_device_id_add_listfunction list_for_each_entryfunction pcistub_seizefunction pcistub_probefunction pcistub_removefunction list_for_each_entryfunction kill_domain_by_devicefunction common_processfunction xen_pcibk_slot_resetfunction xen_pcibk_mmio_enabledfunction xen_pcibk_error_detectedfunction xen_pcibk_error_resumefunction str_to_slotfunction str_to_quirkfunction pcistub_device_id_addfunction pcistub_device_id_removefunction pcistub_reg_addfunction new_slot_storefunction remove_slot_storefunction slots_showfunction irq_handlers_showfunction irq_handler_state_storefunction quirks_storefunction quirks_showfunction list_for_each_entryfunction permissive_storefunction permissive_showfunction allow_interrupt_control_storefunction allow_interrupt_control_showfunction pcistub_exitfunction pcistub_initfunction pci_stub_notifierfunction xen_pcibk_initfunction xen_pcibk_cleanup
Annotated Snippet
static struct pci_driver xen_pcibk_pci_driver;
/* Called when 'bind'. This means we must _NOT_ call pci_reset_function or
* other functions that take the sysfs lock. */
static int pcistub_probe(struct pci_dev *dev, const struct pci_device_id *id)
{
int err = 0, match;
struct pcistub_device_id *pci_dev_id = NULL;
dev_dbg(&dev->dev, "probing...\n");
match = pcistub_match(dev);
if (device_match_driver_override(&dev->dev,
&xen_pcibk_pci_driver.driver) > 0 ||
match) {
if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL
&& dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
dev_err(&dev->dev, "can't export pci devices that "
"don't have a normal (0) or bridge (1) "
"header type!\n");
err = -ENODEV;
goto out;
}
if (!match) {
pci_dev_id = kmalloc_obj(*pci_dev_id);
if (!pci_dev_id) {
err = -ENOMEM;
goto out;
}
}
dev_info(&dev->dev, "seizing device\n");
err = pcistub_seize(dev, pci_dev_id);
} else
/* Didn't find the device */
err = -ENODEV;
out:
return err;
}
/* Called when 'unbind'. This means we must _NOT_ call pci_reset_function or
* other functions that take the sysfs lock. */
static void pcistub_remove(struct pci_dev *dev)
{
struct pcistub_device *psdev, *found_psdev = NULL;
unsigned long flags;
dev_dbg(&dev->dev, "removing\n");
spin_lock_irqsave(&pcistub_devices_lock, flags);
xen_pcibk_config_quirk_release(dev);
list_for_each_entry(psdev, &pcistub_devices, dev_list) {
if (psdev->dev == dev) {
found_psdev = psdev;
break;
}
}
spin_unlock_irqrestore(&pcistub_devices_lock, flags);
if (found_psdev) {
dev_dbg(&dev->dev, "found device to remove %s\n",
found_psdev->pdev ? "- in-use" : "");
if (found_psdev->pdev) {
int domid = xen_find_device_domain_owner(dev);
dev_warn(&dev->dev, "****** removing device %s while still in-use by domain %d! ******\n",
pci_name(found_psdev->dev), domid);
dev_warn(&dev->dev, "****** driver domain may still access this device's i/o resources!\n");
dev_warn(&dev->dev, "****** shutdown driver domain before binding device\n");
dev_warn(&dev->dev, "****** to other drivers or domains\n");
/* N.B. This ends up calling pcistub_put_pci_dev which ends up
* doing the FLR. */
xen_pcibk_release_pci_dev(found_psdev->pdev,
found_psdev->dev,
false /* caller holds the lock. */);
}
spin_lock_irqsave(&pcistub_devices_lock, flags);
list_del(&found_psdev->dev_list);
spin_unlock_irqrestore(&pcistub_devices_lock, flags);
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/rwsem.h`, `linux/list.h`, `linux/spinlock.h`, `linux/kref.h`, `linux/pci.h`, `linux/wait.h`.
- Detected declarations: `struct pcistub_device_id`, `struct pcistub_device`, `function pcistub_reset_device_state`, `function pcistub_device_release`, `function pcistub_device_get`, `function pcistub_device_put`, `function list_for_each_entry`, `function pcistub_get_gsi_from_sbdf`, `function pcistub_put_pci_dev`, `function list_for_each_entry`.
- Atlas domain: Driver Families / drivers/xen.
- 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.