drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
Source file repositories/reference/linux-study-clean/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c- Extension
.c- Size
- 46215 bytes
- Lines
- 1742
- Domain
- Driver Families
- Bucket
- drivers/vfio
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/device.hlinux/eventfd.hlinux/file.hlinux/hisi_acc_qm.hlinux/interrupt.hlinux/module.hlinux/pci.hlinux/vfio.hlinux/vfio_pci_core.hlinux/anon_inodes.hhisi_acc_vfio_pci.h
Detected Declarations
function Copyrightfunction qm_check_reg_statefunction qm_read_regsfunction qm_write_regsfunction qm_get_vftfunction qm_xqc_reg_offsetsfunction qm_get_regsfunction qm_set_regsfunction qm_dbfunction pf_qm_get_qp_numfunction qm_dev_cmd_initfunction vf_qm_cache_wbfunction vf_qm_fun_resetfunction vf_qm_func_stopfunction vf_qm_version_checkfunction vf_qm_check_matchfunction vf_qm_get_match_datafunction vf_qm_xeqc_savefunction vf_qm_load_datafunction vf_qm_read_datafunction vf_qm_state_savefunction hisi_acc_check_int_statefunction hisi_acc_vf_disable_fdfunction hisi_acc_debug_migf_copyfunction hisi_acc_vf_disable_fdsfunction hisi_acc_vf_resetfunction hisi_acc_vf_start_devicefunction hisi_acc_vf_load_statefunction hisi_acc_vf_release_filefunction hisi_acc_vf_resume_writefunction hisi_acc_vf_pci_resumefunction hisi_acc_vf_precopy_ioctlfunction hisi_acc_vf_save_readfunction hisi_acc_open_saving_migffunction hisi_acc_vf_pre_copyfunction hisi_acc_vf_stop_copyfunction hisi_acc_vf_stop_devicefunction hisi_acc_vf_set_device_statefunction hisi_acc_vfio_pci_set_device_statefunction hisi_acc_vfio_pci_get_data_sizefunction hisi_acc_vfio_pci_get_device_statefunction hisi_acc_vf_pci_reset_preparefunction hisi_acc_vf_pci_aer_reset_donefunction hisi_acc_vf_qm_initfunction hisi_acc_get_resource_lenfunction hisi_acc_pci_rw_access_checkfunction hisi_acc_vfio_pci_mmapfunction hisi_acc_vfio_pci_write
Annotated Snippet
static const struct file_operations hisi_acc_vf_resume_fops = {
.owner = THIS_MODULE,
.write = hisi_acc_vf_resume_write,
.release = hisi_acc_vf_release_file,
};
static struct hisi_acc_vf_migration_file *
hisi_acc_vf_pci_resume(struct hisi_acc_vf_core_device *hisi_acc_vdev)
{
struct hisi_acc_vf_migration_file *migf;
migf = kzalloc_obj(*migf, GFP_KERNEL_ACCOUNT);
if (!migf)
return ERR_PTR(-ENOMEM);
migf->filp = anon_inode_getfile("hisi_acc_vf_mig", &hisi_acc_vf_resume_fops, migf,
O_WRONLY);
if (IS_ERR(migf->filp)) {
int err = PTR_ERR(migf->filp);
kfree(migf);
return ERR_PTR(err);
}
stream_open(migf->filp->f_inode, migf->filp);
mutex_init(&migf->lock);
migf->hisi_acc_vdev = hisi_acc_vdev;
return migf;
}
static long hisi_acc_vf_precopy_ioctl(struct file *filp,
unsigned int cmd, unsigned long arg)
{
struct hisi_acc_vf_migration_file *migf = filp->private_data;
struct hisi_acc_vf_core_device *hisi_acc_vdev = migf->hisi_acc_vdev;
loff_t *pos = &filp->f_pos;
struct vfio_precopy_info info;
int ret;
ret = vfio_check_precopy_ioctl(&hisi_acc_vdev->core_device.vdev, cmd,
arg, &info);
if (ret)
return ret;
mutex_lock(&hisi_acc_vdev->state_mutex);
if (hisi_acc_vdev->mig_state != VFIO_DEVICE_STATE_PRE_COPY) {
mutex_unlock(&hisi_acc_vdev->state_mutex);
return -EINVAL;
}
mutex_lock(&migf->lock);
if (migf->disabled) {
ret = -ENODEV;
goto out;
}
if (*pos > migf->total_length) {
ret = -EINVAL;
goto out;
}
info.dirty_bytes = 0;
info.initial_bytes = migf->total_length - *pos;
mutex_unlock(&migf->lock);
mutex_unlock(&hisi_acc_vdev->state_mutex);
return copy_to_user((void __user *)arg, &info,
offsetofend(struct vfio_precopy_info, dirty_bytes)) ? -EFAULT : 0;
out:
mutex_unlock(&migf->lock);
mutex_unlock(&hisi_acc_vdev->state_mutex);
return ret;
}
static ssize_t hisi_acc_vf_save_read(struct file *filp, char __user *buf, size_t len,
loff_t *pos)
{
struct hisi_acc_vf_migration_file *migf = filp->private_data;
ssize_t done = 0;
int ret;
if (pos)
return -ESPIPE;
pos = &filp->f_pos;
mutex_lock(&migf->lock);
if (*pos > migf->total_length) {
done = -EINVAL;
goto out_unlock;
Annotation
- Immediate include surface: `linux/device.h`, `linux/eventfd.h`, `linux/file.h`, `linux/hisi_acc_qm.h`, `linux/interrupt.h`, `linux/module.h`, `linux/pci.h`, `linux/vfio.h`.
- Detected declarations: `function Copyright`, `function qm_check_reg_state`, `function qm_read_regs`, `function qm_write_regs`, `function qm_get_vft`, `function qm_xqc_reg_offsets`, `function qm_get_regs`, `function qm_set_regs`, `function qm_db`, `function pf_qm_get_qp_num`.
- Atlas domain: Driver Families / drivers/vfio.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.