24 #include <sys/types.h>
28 #define MAKE_DEV(major, minor) \
29 ((dev_t) ((minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12)))
45 uid_t uid =
get_param(proc_path,
"DeviceFileUID");
46 gid_t gid =
get_param(proc_path,
"DeviceFileGID");
47 mode_t mode =
get_param(proc_path,
"DeviceFileMode");
50 if (mknod(path, mode | S_IFCHR, dev) == -1) {
55 if (chown(path, uid, gid) == -1)
58 fd = open(path, O_RDWR | O_CLOEXEC);
67 const char *params =
"/proc/driver/nvidia/params";
69 int32_t major =
get_major(
"nvidia-frontend");
73 sprintf(path,
"/dev/nvidiactl");
75 sprintf(path,
"/dev/nvidia%d", minor);
77 return nv_open(major, minor, path, params);
84 const char *params =
"/proc/driver/nvidia/params";
86 int32_t major =
get_major(
"nvidia-vgpu-vfio");
89 sprintf(path,
"/dev/nvidia-vgpu%d", minor);
91 return nv_open(major, minor, path, params);
int nv_open_dev(uint16_t minor)
Opens a traditional NVIDIA device.
int nv_open(int32_t major, uint16_t minor, const char *path, const char *proc_path)
Opens a Nvidia device.
int nv_open_mdev(uint16_t minor)
Opens a Mediated NVIDIA device.
#define MAKE_DEV(major, minor)
uint8_t device_exists(const char *device_name)
Does a device file exist?
int32_t get_major(const char *device)
Gets the device major id from /proc/devices.
int32_t get_param(const char *filename, const char *parameter)
Gets a parameter from a driver param file.