From 33151e16a22ee694ca2a72dbeae3e09716ee3efc Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 27 Oct 2021 13:01:28 -0700 Subject: [PATCH] Linux: Implements virtio ioctls for 32-bit This makes running Steam under parallels more sane --- Source/Tests/LinuxSyscalls/x32/Ioctl/drm.h | 1 + .../LinuxSyscalls/x32/Ioctl/virtio_drm.inl | 9 ++++++ .../LinuxSyscalls/x32/IoctlEmulation.cpp | 29 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 Source/Tests/LinuxSyscalls/x32/Ioctl/virtio_drm.inl diff --git a/Source/Tests/LinuxSyscalls/x32/Ioctl/drm.h b/Source/Tests/LinuxSyscalls/x32/Ioctl/drm.h index 1db72f80c..baef4f800 100644 --- a/Source/Tests/LinuxSyscalls/x32/Ioctl/drm.h +++ b/Source/Tests/LinuxSyscalls/x32/Ioctl/drm.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #define CPYT(x) val.x = x diff --git a/Source/Tests/LinuxSyscalls/x32/Ioctl/virtio_drm.inl b/Source/Tests/LinuxSyscalls/x32/Ioctl/virtio_drm.inl new file mode 100644 index 000000000..cde293bd8 --- /dev/null +++ b/Source/Tests/LinuxSyscalls/x32/Ioctl/virtio_drm.inl @@ -0,0 +1,9 @@ +_BASIC_META(DRM_IOCTL_VIRTGPU_MAP) +_BASIC_META(DRM_IOCTL_VIRTGPU_EXECBUFFER) +_BASIC_META(DRM_IOCTL_VIRTGPU_GETPARAM) +_BASIC_META(DRM_IOCTL_VIRTGPU_RESOURCE_CREATE) +_BASIC_META(DRM_IOCTL_VIRTGPU_RESOURCE_INFO) +_BASIC_META(DRM_IOCTL_VIRTGPU_TRANSFER_FROM_HOST) +_BASIC_META(DRM_IOCTL_VIRTGPU_TRANSFER_TO_HOST) +_BASIC_META(DRM_IOCTL_VIRTGPU_WAIT) +_BASIC_META(DRM_IOCTL_VIRTGPU_GET_CAPS) diff --git a/Source/Tests/LinuxSyscalls/x32/IoctlEmulation.cpp b/Source/Tests/LinuxSyscalls/x32/IoctlEmulation.cpp index c151879e7..31b994c5e 100644 --- a/Source/Tests/LinuxSyscalls/x32/IoctlEmulation.cpp +++ b/Source/Tests/LinuxSyscalls/x32/IoctlEmulation.cpp @@ -409,6 +409,31 @@ namespace FEX::HLE::x32 { return -EPERM; } + uint32_t Virtio_Handler(int fd, uint32_t cmd, uint32_t args) { + switch (_IOC_NR(cmd)) { +#define _BASIC_META(x) case _IOC_NR(x): +#define _BASIC_META_VAR(x, args...) case _IOC_NR(x): +#define _CUSTOM_META(name, ioctl_num) +#define _CUSTOM_META_OFFSET(name, ioctl_num, offset) + // DRM +#include "Tests/LinuxSyscalls/x32/Ioctl/virtio_drm.inl" + { + uint64_t Result = ::ioctl(fd, cmd, args); + SYSCALL_ERRNO(); + break; + } + default: + UnhandledIoctl("Virtio", fd, cmd, args); + return -EPERM; + break; + } +#undef _BASIC_META +#undef _BASIC_META_VAR +#undef _CUSTOM_META +#undef _CUSTOM_META_OFFSET + return -EPERM; + } + void AssignDeviceTypeToFD(int fd, drm_version const &Version) { if (Version.name) { if (strcmp(Version.name, "amdgpu") == 0) { @@ -435,6 +460,9 @@ namespace FEX::HLE::x32 { else if (strcmp(Version.name, "v3d") == 0) { FDToHandler.SetFDHandler(fd, V3D_Handler); } + else if (strcmp(Version.name, "virtio_gpu") == 0) { + FDToHandler.SetFDHandler(fd, Virtio_Handler); + } else { LogMan::Msg::E("Unknown DRM device: '%s'", Version.name); } @@ -589,6 +617,7 @@ namespace FEX::HLE::x32 { #include "Tests/LinuxSyscalls/x32/Ioctl/nouveau_drm.inl" #include "Tests/LinuxSyscalls/x32/Ioctl/vc4_drm.inl" #include "Tests/LinuxSyscalls/x32/Ioctl/v3d_drm.inl" +#include "Tests/LinuxSyscalls/x32/Ioctl/virtio_drm.inl" #undef _BASIC_META #undef _BASIC_META_VAR