summaryrefslogtreecommitdiffstats
path: root/scripts/create_mdev.sh
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 /scripts/create_mdev.sh
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 'scripts/create_mdev.sh')
-rwxr-xr-xscripts/create_mdev.sh86
1 files changed, 86 insertions, 0 deletions
diff --git a/scripts/create_mdev.sh b/scripts/create_mdev.sh
new file mode 100755
index 0000000..f6c76ed
--- /dev/null
+++ b/scripts/create_mdev.sh
@@ -0,0 +1,86 @@
+#!/bin/bash
+# create_mdev.sh - Create NVIDIA vGPU mediated device for QEMU
+# Usage: ./create_mdev.sh [PCI_ADDRESS] [VGPU_TYPE]
+
+set -euo pipefail
+
+PCI_ADDR="${1:-}"
+VGPU_TYPE="${2:-nvidia-vgpu-turing}"
+
+# Supported vGPU types
+VALID_TYPES=("nvidia-vgpu-ampere" "nvidia-vgpu-hopper" "nvidia-vgpu-turing" "nvidia-vgpu-pascal")
+
+# Find NVIDIA GPU if not specified
+if [[ -z "$PCI_ADDR" ]]; then
+ echo "Scanning for NVIDIA GPUs..."
+ mapfile -t GPUS < <(lspci -D -d 10de: | grep -E "VGA|3D controller" | awk '{print $1}')
+ if [[ ${#GPUS[@]} -eq 0 ]]; then
+ echo "ERROR: No NVIDIA GPU found"
+ exit 1
+ elif [[ ${#GPUS[@]} -eq 1 ]]; then
+ PCI_ADDR="${GPUS[0]}"
+ echo "Auto-selected GPU: $PCI_ADDR"
+ else
+ echo "Multiple GPUs found:"
+ for i in "${!GPUS[@]}"; do
+ echo " [$i] ${GPUS[$i]}"
+ done
+ read -p "Select GPU [0-$((${#GPUS[@]}-1))]: " idx
+ PCI_ADDR="${GPUS[$idx]}"
+ fi
+fi
+
+# Validate PCI address format
+if [[ ! "$PCI_ADDR" =~ ^[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]$ ]]; then
+ echo "ERROR: Invalid PCI address format. Expected: dddd:bb:dd.f"
+ exit 1
+fi
+
+# Check if GPU exists
+if [[ ! -e "/sys/bus/pci/devices/$PCI_ADDR" ]]; then
+ echo "ERROR: PCI device $PCI_ADDR not found"
+ exit 1
+fi
+
+# Validate vGPU type
+if [[ ! " ${VALID_TYPES[*]} " =~ " ${VGPU_TYPE} " ]]; then
+ echo "ERROR: Invalid vGPU type. Valid types: ${VALID_TYPES[*]}"
+ exit 1
+fi
+
+MDEV_TYPE_PATH="/sys/bus/pci/devices/$PCI_ADDR/mdev_supported_types/$VGPU_TYPE"
+
+if [[ ! -d "$MDEV_TYPE_PATH" ]]; then
+ echo "ERROR: vGPU type $VGPU_TYPE not supported on $PCI_ADDR"
+ echo "Available types:"
+ ls "/sys/bus/pci/devices/$PCI_ADDR/mdev_supported_types/" 2>/dev/null || echo " (none - check driver loaded)"
+ exit 1
+fi
+
+# Check available instances
+AVAILABLE=$(cat "$MDEV_TYPE_PATH/available_instances" 2>/dev/null || echo "0")
+if [[ "$AVAILABLE" -le 0 ]]; then
+ echo "ERROR: No available instances for $VGPU_TYPE on $PCI_ADDR"
+ exit 1
+fi
+
+echo "Creating $VGPU_TYPE on $PCI_ADDR..."
+
+# Generate UUID
+UUID=$(uuidgen)
+echo "$UUID" | sudo tee "$MDEV_TYPE_PATH/create" > /dev/null
+
+# Verify creation
+MDEV_PATH="/sys/bus/mdev/devices/$UUID"
+if [[ -d "$MDEV_PATH" ]]; then
+ echo "SUCCESS: Created mdev device $UUID"
+ echo " Path: $MDEV_PATH"
+ echo " PCI: $PCI_ADDR"
+ echo " Type: $VGPU_TYPE"
+ echo ""
+ echo "For QEMU, use:"
+ echo " -device vfio-pci,sysfsdev=$MDEV_PATH,display=off"
+else
+ echo "ERROR: Failed to create mdev device"
+ exit 1
+fi \ No newline at end of file