summaryrefslogtreecommitdiffstats
path: root/kernel/include/nvidia-vgpu-vfio.h
diff options
context:
space:
mode:
authorArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-13 18:36:21 -0400
committerArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-13 18:36:21 -0400
commit00e54c13c7c9030c4d5f7151467f2d85a3730e29 (patch)
tree17a45239df8d2e4912ff3697ed06e85a10b969de /kernel/include/nvidia-vgpu-vfio.h
downloadopen-iov-00e54c13c7c9030c4d5f7151467f2d85a3730e29.tar.gz
open-iov-00e54c13c7c9030c4d5f7151467f2d85a3730e29.zip
Initial commit: Open-IOV vGPU-IO complete stack
- Firmware decompilation: GSP 570.144W (28.5MB ELF, RV64IMAC), 132 decompiled C files - Kernel modules: nvidia.ko (34MB, OpenRM), open-iov-vfio.ko (2.8MB, VFIO mdev), gsp-vgpu.ko (1.8MB, guest driver) - Userspace: libiov.so/libvgpu.so (76KB), example_vgpu (28KB), rpc_emulator.c - PCI config space emulation (256B with PM, MSI, MSI-X, PCIe caps) - 12 RPC types fully mapped from firmware decompilation - BAR trap, WPR, scheduling, notification, migration emulation - Helper scripts: load_vgpu_stack, create_mdev, launch_qemu_vgpu, test_vgpu_stack, setup_guest_driver, unload_vgpu_stack - Architecture documentation - Wiki: 10 technical documents - Git LFS for large binaries (.ko, .bin, .iso, .img, .o, ghidra repos) - nvidia-open-gpu-kernel-modules as submodule
Diffstat (limited to 'kernel/include/nvidia-vgpu-vfio.h')
-rw-r--r--kernel/include/nvidia-vgpu-vfio.h194
1 files changed, 194 insertions, 0 deletions
diff --git a/kernel/include/nvidia-vgpu-vfio.h b/kernel/include/nvidia-vgpu-vfio.h
new file mode 100644
index 0000000..7f778ee
--- /dev/null
+++ b/kernel/include/nvidia-vgpu-vfio.h
@@ -0,0 +1,194 @@
+#ifndef _NVIDIA_VGPU_VFIO_H_
+#define _NVIDIA_VGPU_VFIO_H_
+
+#include <linux/types.h>
+#include <linux/mutex.h>
+#include <linux/list.h>
+#include <linux/workqueue.h>
+#include <linux/vfio.h>
+#include <linux/mdev.h>
+#include <linux/pci.h>
+#include <linux/dma-mapping.h>
+#include <linux/atomic.h>
+
+#define OPEN_IOV_VFIO_VERSION "0.1.0"
+#define OPEN_IOV_VFIO_NAME "open-iov-vfio"
+
+#define NVIDIA_VGPU_VFIO_VERSION OPEN_IOV_VFIO_VERSION
+#define NVIDIA_VGPU_VFIO_NAME OPEN_IOV_VFIO_NAME
+
+#define NVIDIA_VGPU_MAX_VF_COUNT 32
+#define NVIDIA_VGPU_MAX_REGIONS 8
+#define NVIDIA_VGPU_MAX_IRQS 16
+
+#define NV_VGPU_MAX_REGIONS NVIDIA_VGPU_MAX_REGIONS
+#define NV_VGPU_MAX_IRQS NVIDIA_VGPU_MAX_IRQS
+
+#define NV_VGPU_BAR0_SIZE (16 * 1024 * 1024)
+#define NV_VGPU_BAR1_SIZE (256 * 1024 * 1024)
+#define NV_VGPU_BAR2_SIZE (32 * 1024 * 1024)
+#define NV_VGPU_BAR3_SIZE (32 * 1024 * 1024)
+
+enum nv_vgpu_type {
+ NV_VGPU_TYPE_UNKNOWN = 0,
+ NV_VGPU_TYPE_AMPERE,
+ NV_VGPU_TYPE_HOPPER,
+ NV_VGPU_TYPE_TURING,
+ NV_VGPU_TYPE_PASCAL,
+ NV_VGPU_TYPE_MAXWELL,
+ NV_VGPU_TYPE_KEPLER,
+};
+
+enum nv_vgpu_state {
+ NV_VGPU_STATE_UNINITIALIZED = 0,
+ NV_VGPU_STATE_INITIALIZING,
+ NV_VGPU_STATE_READY,
+ NV_VGPU_STATE_RUNNING,
+ NV_VGPU_STATE_SUSPENDED,
+ NV_VGPU_STATE_ERROR,
+ NV_VGPU_STATE_MIGRATING,
+};
+
+struct nv_vgpu_bar {
+ u64 gpa;
+ u64 size;
+ u64 iova;
+ void *vaddr;
+ bool mapped;
+ bool trapped;
+ struct mutex lock;
+};
+
+struct nv_vgpu_irq {
+ int virq;
+ int type;
+ bool masked;
+ struct eventfd_ctx *trigger;
+ struct irq_domain *domain;
+};
+
+struct nv_vgpu_region {
+ u64 offset;
+ u64 size;
+ u64 iova;
+ int fd;
+ void *vaddr;
+ bool readonly;
+};
+
+struct nv_vgpu_migration_ctx;
+
+struct nv_vgpu_migration_state {
+ u32 version;
+ u32 flags;
+ u64 timestamp;
+ u8 *data;
+ size_t data_size;
+ struct completion done;
+ int result;
+ struct nv_vgpu_migration_ctx *ctx;
+};
+
+struct nv_vgpu_device {
+ struct mdev_device *mdev;
+ struct pci_dev *pdev;
+ struct device dev;
+ struct mutex lock;
+ enum nv_vgpu_type type;
+ enum nv_vgpu_state state;
+ u32 vgpu_id;
+ u32 gpu_instance_id;
+ u32 compute_instance_id;
+
+ struct nv_vgpu_bar bars[NV_VGPU_MAX_REGIONS];
+ struct nv_vgpu_irq irqs[NV_VGPU_MAX_IRQS];
+ struct nv_vgpu_region regions[NV_VGPU_MAX_REGIONS];
+
+ struct nv_vgpu_migration_state migration;
+
+ struct work_struct init_work;
+ struct work_struct cleanup_work;
+
+ void *gsp_comm_ctx;
+ void *bar_emul_ctx;
+ void *mm_ctx;
+ void *irq_ctx;
+
+ u64 fb_base;
+ u64 fb_size;
+ u64 bar0_config_base;
+
+ struct list_head list;
+
+ bool dry_run;
+
+ /* PCI Config Space for VFIO mdev */
+ u8 pci_config[256];
+ bool config_space_dirty;
+};
+
+struct nv_vgpu_driver_data {
+ struct mutex lock;
+ struct list_head devices;
+ u32 device_count;
+ struct class *class;
+ struct bus_type *bus;
+};
+
+extern struct nv_vgpu_driver_data nv_vgpu_driver;
+
+int nv_vgpu_device_create(struct mdev_device *mdev);
+void nv_vgpu_device_destroy(struct mdev_device *mdev);
+int nv_vgpu_device_init(struct nv_vgpu_device *vgpu);
+void nv_vgpu_device_cleanup(struct nv_vgpu_device *vgpu);
+
+int nv_vgpu_bar_init(struct nv_vgpu_device *vgpu);
+void nv_vgpu_bar_cleanup(struct nv_vgpu_device *vgpu);
+int nv_vgpu_bar_trap(struct nv_vgpu_device *vgpu, int bar_idx);
+void nv_vgpu_bar_untrap(struct nv_vgpu_device *vgpu, int bar_idx);
+
+int nv_vgpu_irq_init(struct nv_vgpu_device *vgpu);
+void nv_vgpu_irq_cleanup(struct nv_vgpu_device *vgpu);
+int nv_vgpu_irq_enable(struct nv_vgpu_device *vgpu, int irq_idx);
+int nv_vgpu_irq_disable(struct nv_vgpu_device *vgpu, int irq_idx);
+
+int nv_vgpu_memory_init(struct nv_vgpu_device *vgpu);
+void nv_vgpu_memory_cleanup(struct nv_vgpu_device *vgpu);
+int nv_vgpu_memory_map(struct nv_vgpu_device *vgpu, u64 gpa, u64 size, u64 *iova);
+int nv_vgpu_memory_unmap(struct nv_vgpu_device *vgpu, u64 iova, u64 size);
+
+int nv_vgpu_gsp_init(struct nv_vgpu_device *vgpu);
+void nv_vgpu_gsp_cleanup(struct nv_vgpu_device *vgpu);
+int nv_vgpu_gsp_send_rpc(struct nv_vgpu_device *vgpu, void *msg, size_t size);
+int nv_vgpu_gsp_recv_rpc(struct nv_vgpu_device *vgpu, void *msg, size_t size, int timeout_ms);
+int nv_vgpu_gsp_load_firmware(struct nv_vgpu_device *vgpu);
+void nv_vgpu_gsp_release_firmware(struct nv_vgpu_device *vgpu);
+int nv_vgpu_gsp_boot(struct nv_vgpu_device *vgpu);
+
+int nv_vgpu_migration_init(struct nv_vgpu_device *vgpu);
+void nv_vgpu_migration_cleanup(struct nv_vgpu_device *vgpu);
+int nv_vgpu_migration_save_state(struct nv_vgpu_device *vgpu, u8 **data, size_t *size);
+int nv_vgpu_migration_restore_state(struct nv_vgpu_device *vgpu, u8 *data, size_t size);
+int nv_vgpu_migration_prepare(struct nv_vgpu_device *vgpu);
+int nv_vgpu_migration_complete(struct nv_vgpu_device *vgpu);
+int nv_vgpu_migration_cancel(struct nv_vgpu_device *vgpu);
+u8 *nv_vgpu_migration_get_data(struct nv_vgpu_device *vgpu, size_t *size);
+
+static inline struct nv_vgpu_device *mdev_to_vgpu(struct mdev_device *mdev)
+{
+ return dev_get_drvdata(&mdev->dev);
+}
+
+#define nv_vgpu_dbg(vgpu, fmt, ...) \
+ dev_dbg(&(vgpu)->dev, "%s: " fmt, __func__, ##__VA_ARGS__)
+
+#define nv_vgpu_info(vgpu, fmt, ...) \
+ dev_info(&(vgpu)->dev, "%s: " fmt, __func__, ##__VA_ARGS__)
+
+#define nv_vgpu_warn(vgpu, fmt, ...) \
+ dev_warn(&(vgpu)->dev, "%s: " fmt, __func__, ##__VA_ARGS__)
+
+#define nv_vgpu_err(vgpu, fmt, ...) \
+ dev_err(&(vgpu)->dev, "%s: " fmt, __func__, ##__VA_ARGS__)
+
+#endif \ No newline at end of file