drivers/vfio/pci/vfio_pci_config.c
Source file repositories/reference/linux-study-clean/drivers/vfio/pci/vfio_pci_config.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vfio/pci/vfio_pci_config.c- Extension
.c- Size
- 56871 bytes
- Lines
- 2042
- Domain
- Driver Families
- Bucket
- drivers/vfio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/fs.hlinux/pci.hlinux/uaccess.hlinux/vfio.hlinux/slab.hvfio_pci_priv.h
Detected Declarations
struct perm_bitsfunction vfio_user_config_readfunction vfio_user_config_writefunction vfio_default_config_readfunction vfio_default_config_writefunction vfio_direct_config_readfunction vfio_raw_config_writefunction vfio_raw_config_readfunction vfio_virt_config_writefunction vfio_virt_config_readfunction free_perm_bitsfunction alloc_perm_bitsfunction p_setbfunction p_setwfunction p_setdfunction __vfio_pci_memory_enabledfunction vfio_bar_restorefunction vfio_generate_bar_flagsfunction vfio_bar_fixupfunction existsfunction vfio_basic_config_readfunction vfio_need_bar_restorefunction vfio_basic_config_writefunction init_pci_cap_basic_permfunction vfio_pci_set_power_statefunction vfio_pm_config_writefunction init_pci_cap_pm_permfunction vfio_vpd_config_writefunction init_pci_cap_vpd_permfunction init_pci_cap_pcix_permfunction vfio_exp_config_writefunction pcie_set_readrqfunction init_pci_cap_exp_permfunction vfio_af_config_writefunction init_pci_cap_af_permfunction init_pci_ext_cap_err_permfunction init_pci_ext_cap_pwr_permfunction vfio_pci_uninit_perm_bitsfunction vfio_pci_init_perm_bitsfunction vfio_find_cap_startfunction vfio_msi_config_readfunction vfio_msi_config_writefunction init_pci_cap_msi_permfunction vfio_msi_cap_lenfunction vfio_vc_cap_lenfunction vfio_cap_lenfunction vfio_ext_cap_lenfunction vfio_update_pm_vconfig_bytes
Annotated Snippet
struct perm_bits {
u8 *virt; /* read/write virtual data, not hw */
u8 *write; /* writeable bits */
int (*readfn)(struct vfio_pci_core_device *vdev, int pos, int count,
struct perm_bits *perm, int offset, __le32 *val);
int (*writefn)(struct vfio_pci_core_device *vdev, int pos, int count,
struct perm_bits *perm, int offset, __le32 val);
};
#define NO_VIRT 0
#define ALL_VIRT 0xFFFFFFFFU
#define NO_WRITE 0
#define ALL_WRITE 0xFFFFFFFFU
static int vfio_user_config_read(struct pci_dev *pdev, int offset,
__le32 *val, int count)
{
int ret = -EINVAL;
u32 tmp_val = 0;
switch (count) {
case 1:
{
u8 tmp;
ret = pci_user_read_config_byte(pdev, offset, &tmp);
tmp_val = tmp;
break;
}
case 2:
{
u16 tmp;
ret = pci_user_read_config_word(pdev, offset, &tmp);
tmp_val = tmp;
break;
}
case 4:
ret = pci_user_read_config_dword(pdev, offset, &tmp_val);
break;
}
*val = cpu_to_le32(tmp_val);
return ret;
}
static int vfio_user_config_write(struct pci_dev *pdev, int offset,
__le32 val, int count)
{
int ret = -EINVAL;
u32 tmp_val = le32_to_cpu(val);
switch (count) {
case 1:
ret = pci_user_write_config_byte(pdev, offset, tmp_val);
break;
case 2:
ret = pci_user_write_config_word(pdev, offset, tmp_val);
break;
case 4:
ret = pci_user_write_config_dword(pdev, offset, tmp_val);
break;
}
return ret;
}
static int vfio_default_config_read(struct vfio_pci_core_device *vdev, int pos,
int count, struct perm_bits *perm,
int offset, __le32 *val)
{
__le32 virt = 0;
memcpy(val, vdev->vconfig + pos, count);
memcpy(&virt, perm->virt + offset, count);
/* Any non-virtualized bits? */
if (cpu_to_le32(~0U >> (32 - (count * 8))) != virt) {
struct pci_dev *pdev = vdev->pdev;
__le32 phys_val = 0;
int ret;
ret = vfio_user_config_read(pdev, pos, &phys_val, count);
if (ret)
return ret;
*val = (phys_val & ~virt) | (*val & virt);
}
return count;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/pci.h`, `linux/uaccess.h`, `linux/vfio.h`, `linux/slab.h`, `vfio_pci_priv.h`.
- Detected declarations: `struct perm_bits`, `function vfio_user_config_read`, `function vfio_user_config_write`, `function vfio_default_config_read`, `function vfio_default_config_write`, `function vfio_direct_config_read`, `function vfio_raw_config_write`, `function vfio_raw_config_read`, `function vfio_virt_config_write`, `function vfio_virt_config_read`.
- Atlas domain: Driver Families / drivers/vfio.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.