27 #include <sys/select.h>
39 return 0xDAE00000 | (t << 8) | i;
76 set_notify.
event = notify;
79 RM_CTRL(ctl_fd, res, 0x00000501, set_notify);
91 struct VmMgr ret = {};
93 for (
int i = 0; i < 32 && mgr->gpus[i] != NULL; ++i) {
96 uint32_t persistence = 0;
100 if (persistence == 1) {
106 printf(
"Persistence set correctly.\n");
110 ret.
root = mgr->res->client;
112 printf(
"Events initialized for start and bind VM.\n");
131 select(n_fds, &read_fds, NULL, NULL, NULL);
134 printf(
"Got a start request from the NVIDIA kernel module\n");
136 }
else if (FD_ISSET(mgr->
event_bind, &read_fds)) {
137 printf(
"Got a bind request from the NVIDIA kernel module\n");
147 RM_CTRL(mdev_mgr->
fd, mdev_mgr->
res, 0x00000C01, vm_start_info);
149 struct UUID uuid = vm_start_info.
uuid;
150 struct UUID vm_uuid = {};
157 vm_uuid.
node[0] = 0x1E;
158 vm_uuid.
node[1] = 0xF6;
159 vm_uuid.
node[2] = 0x67;
160 vm_uuid.
node[3] = 0x54;
161 vm_uuid.
node[4] = 0x9D;
162 vm_uuid.
node[5] = 0xE5;
165 "MDEV UUID: %.8X-%.4X-%.4X-%.2X%.2X-%.2X%.2X%.2X%.2X%.2X%.2X\n"
166 "Got config \"%s\" for QEMU PID 0x%.8X\n"
178 notify_start.
mdev = uuid;
179 notify_start.
vm = vm_uuid;
180 strcpy(notify_start.
name,
"GVM VM");
182 printf(
"Opened /dev/nvidia-vgpu%d\n", vm_start_info.
mdev_id);
186 for (
int i = 0; i < 32 && mdev_mgr->
gpus[i] != NULL; ++i) {
193 printf(
"Started VM\n");
uint8_t rm_alloc_os_event(int fd, uint32_t client_id, uint32_t device_id)
Allocates an Operating System Event.
#define RM_CTRL(fd, res, cmd, data)
Controls a RM Resource.
struct NvResource * rm_alloc_res(int fd, struct NvResource *parent, uint32_t object, uint32_t rm_class, void *data)
Allocates a Node for a resource.
int nv_open_dev(uint16_t minor)
Opens a traditional NVIDIA device.
int nv_open_mdev(uint16_t minor)
Opens a Mediated NVIDIA device.
struct VmMgr init_nv_vm_mgr(struct NvMdev *mgr)
Initializes a NVIDIA VM manager to connect to a VM.
static uint32_t compose_vm_id(uint32_t t, uint32_t i)
Inline function to create VM specific Event IDs.
const uint32_t RM_EVENT
RM Event ID.
void handle_vm_start(struct VmMgr *mgr, struct NvMdev *mdev_mgr)
Handles a start request.
void start_vm(struct VmMgr *mgr, struct NvMdev *mdev_mgr)
Connects the VM to the user program.
static int event_init(int ctl_fd, struct NvResource *res, uint32_t event, uint32_t notify, uint32_t flags)
Code to initialize events for the VM manager.
uint32_t identifier
Identifier for the GPU.
Control Mechanism for the NVIDIA GPU.
struct Gpu * gpu
GPU structure corresponding to the GPU.
Structure for managing the mediated stack.
int fd
Control file descriptor.
struct NvMdevGpu * gpus[32]
Available GPUs.
struct NvResource * res
Resource tree.
Resource for managing NVIDIA kernel module objects.
uint32_t client
All resources require a client/root.
uint32_t object
Object of the resource.
uint32_t parent
Parent of the event.
uint64_t event_data
Data for the event.
uint32_t notify
Notification of the event.
uint32_t event_class
Class of the event.
Sets the type of notification to use.
uint32_t action
Action to use for the notification.
uint32_t event
Event to set the notification structure.
Notifies the start of a VM.
struct UUID mdev
MDEV UUID.
Reverse engineered start vm info structure.
char config[1024]
Config for starting the MDEV.
uint32_t qemu_pid
QEMU PID.
struct UUID uuid
UUID for the MDEV.
uint8_t clock_seq_hi_and_reserved
uint16_t time_hi_and_version
Structure for VM management.
int event_bind
Event bind fd.
int mdev_fd
MDEV file descriptor.
uint32_t root
Root of the VM manager.
int event_start
Event start fd.