drivers/xen/xen-pciback/xenbus.c
Source file repositories/reference/linux-study-clean/drivers/xen/xen-pciback/xenbus.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/xen-pciback/xenbus.c- Extension
.c- Size
- 19175 bytes
- Lines
- 759
- Domain
- Driver Families
- Bucket
- drivers/xen
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/moduleparam.hlinux/init.hlinux/list.hlinux/vmalloc.hlinux/workqueue.hxen/xenbus.hxen/events.hxen/pci.hpciback.h
Detected Declarations
function xen_pcibk_disconnectfunction free_pdevfunction xen_pcibk_do_attachfunction xen_pcibk_attachfunction xen_pcibk_publish_pci_devfunction xen_pcibk_export_devicefunction xen_pcibk_remove_devicefunction xen_pcibk_publish_pci_rootfunction xen_pcibk_reconfigurefunction xen_pcibk_frontend_changedfunction xen_pcibk_setup_backendfunction xen_pcibk_be_watchfunction xen_pcibk_xenbus_probefunction xen_pcibk_xenbus_removefunction xen_pcibk_xenbus_registerfunction xen_pcibk_xenbus_unregister
Annotated Snippet
if (unlikely(len >= (sizeof(str) - 1))) {
err = -ENOMEM;
goto out;
}
err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
str, "%x:%x", &d, &b);
if (err < 0)
goto out;
if (err != 2) {
err = -EINVAL;
goto out;
}
if (d == domain && b == bus) {
err = 0;
goto out;
}
}
len = snprintf(str, sizeof(str), "root-%d", root_num);
if (unlikely(len >= (sizeof(str) - 1))) {
err = -ENOMEM;
goto out;
}
dev_dbg(&pdev->xdev->dev, "writing root %d at %04x:%02x\n",
root_num, domain, bus);
err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str,
"%04x:%02x", domain, bus);
if (err)
goto out;
err = xenbus_printf(XBT_NIL, pdev->xdev->nodename,
"root_num", "%d", (root_num + 1));
out:
return err;
}
static int xen_pcibk_reconfigure(struct xen_pcibk_device *pdev,
enum xenbus_state state)
{
int err = 0;
int num_devs;
int domain, bus, slot, func;
unsigned int substate;
int i, len;
char state_str[64];
char dev_str[64];
dev_dbg(&pdev->xdev->dev, "Reconfiguring device ...\n");
mutex_lock(&pdev->dev_lock);
if (xenbus_read_driver_state(pdev->xdev, pdev->xdev->nodename) != state)
goto out;
err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d",
&num_devs);
if (err != 1) {
if (err >= 0)
err = -EINVAL;
xenbus_dev_fatal(pdev->xdev, err,
"Error reading number of devices");
goto out;
}
for (i = 0; i < num_devs; i++) {
len = snprintf(state_str, sizeof(state_str), "state-%d", i);
if (unlikely(len >= (sizeof(state_str) - 1))) {
err = -ENOMEM;
xenbus_dev_fatal(pdev->xdev, err,
"String overflow while reading "
"configuration");
goto out;
}
substate = xenbus_read_unsigned(pdev->xdev->nodename, state_str,
XenbusStateUnknown);
switch (substate) {
case XenbusStateInitialising:
dev_dbg(&pdev->xdev->dev, "Attaching dev-%d ...\n", i);
len = snprintf(dev_str, sizeof(dev_str), "dev-%d", i);
if (unlikely(len >= (sizeof(dev_str) - 1))) {
err = -ENOMEM;
xenbus_dev_fatal(pdev->xdev, err,
"String overflow while "
Annotation
- Immediate include surface: `linux/moduleparam.h`, `linux/init.h`, `linux/list.h`, `linux/vmalloc.h`, `linux/workqueue.h`, `xen/xenbus.h`, `xen/events.h`, `xen/pci.h`.
- Detected declarations: `function xen_pcibk_disconnect`, `function free_pdev`, `function xen_pcibk_do_attach`, `function xen_pcibk_attach`, `function xen_pcibk_publish_pci_dev`, `function xen_pcibk_export_device`, `function xen_pcibk_remove_device`, `function xen_pcibk_publish_pci_root`, `function xen_pcibk_reconfigure`, `function xen_pcibk_frontend_changed`.
- Atlas domain: Driver Families / drivers/xen.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.