Skip to content

Commit

Permalink
Merge tag 'gpu-pull-request' of https://gitlab.com/marcandre.lureau/qemu
Browse files Browse the repository at this point in the history
 into staging

virtio-gpu rutabaga support

# -----BEGIN PGP SIGNATURE-----
#
# iQJQBAABCAA6FiEEh6m9kz+HxgbSdvYt2ujhCXWWnOUFAmUtP5YcHG1hcmNhbmRy
# ZS5sdXJlYXVAcmVkaGF0LmNvbQAKCRDa6OEJdZac5X9CD/4s1n/GZyDr9bh04V03
# otAqtq2CSyuUOviqBrqxYgraCosUD1AuX8WkDy5cCPtnKC4FxRjgVlm9s7K/yxOW
# xZ78e4oVgB1F3voOq6LgtKK6BRG/BPqNzq9kuGcayCHQbSxg7zZVwa702Y18r2ZD
# pjOhbZCrJTSfASL7C3e/rm7798Wk/hzSrClGR56fbRAVgQ6Lww2L97/g0nHyDsWK
# DrCBrdqFtKjpLeUHmcqqS4AwdpG2SyCgqE7RehH/wOhvGTxh/JQvHbLGWK2mDC3j
# Qvs8mClC5bUlyNQuUz7lZtXYpzCW6VGMWlz8bIu+ncgSt6RK1TRbdEfDJPGoS4w9
# ZCGgcTxTG/6BEO76J/VpydfTWDo1FwQCQ0Vv7EussGoRTLrFC3ZRFgDWpqCw85yi
# AjPtc0C49FHBZhK0l1CoJGV4gGTDtD9jTYN0ffsd+aQesOjcsgivAWBaCOOQWUc8
# KOv9sr4kLLxcnuCnP7p/PuVRQD4eg0TmpdS8bXfnCzLSH8fCm+n76LuJEpGxEBey
# 3KPJPj/1BNBgVgew+znSLD/EYM6YhdK2gF5SNrYsdR6UcFdrPED/xmdhzFBeVym/
# xbBWqicDw4HLn5YrJ4tzqXje5XUz5pmJoT5zrRMXTHiu4pjBkEXO/lOdAoFwSy8M
# WNOtmSyB69uCrbyLw6xE2/YX8Q==
# =5a/Z
# -----END PGP SIGNATURE-----
# gpg: Signature made Mon 16 Oct 2023 09:50:14 EDT
# gpg:                using RSA key 87A9BD933F87C606D276F62DDAE8E10975969CE5
# gpg:                issuer "marcandre.lureau@redhat.com"
# gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>" [full]
# gpg:                 aka "Marc-André Lureau <marcandre.lureau@gmail.com>" [full]
# Primary key fingerprint: 87A9 BD93 3F87 C606 D276  F62D DAE8 E109 7596 9CE5

* tag 'gpu-pull-request' of https://gitlab.com/marcandre.lureau/qemu:
  docs/system: add basic virtio-gpu documentation
  gfxstream + rutabaga: enable rutabaga
  gfxstream + rutabaga: meson support
  gfxstream + rutabaga: add initial support for gfxstream
  gfxstream + rutabaga prep: added need defintions, fields, and options
  virtio-gpu: blob prep
  virtio-gpu: hostmem
  virtio-gpu: CONTEXT_INIT feature
  virtio: Add shared memory capability

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
stefanhaRH committed Oct 17, 2023
2 parents 8004857 + 773f61e commit 0193b3b
Show file tree
Hide file tree
Showing 19 changed files with 1,495 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/system/device-emulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Emulated Devices
devices/nvme.rst
devices/usb.rst
devices/vhost-user.rst
devices/virtio-gpu.rst
devices/virtio-pmem.rst
devices/vhost-user-rng.rst
devices/canokey.rst
Expand Down
112 changes: 112 additions & 0 deletions docs/system/devices/virtio-gpu.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
..
SPDX-License-Identifier: GPL-2.0-or-later
virtio-gpu
==========

This document explains the setup and usage of the virtio-gpu device.
The virtio-gpu device paravirtualizes the GPU and display controller.

Linux kernel support
--------------------

virtio-gpu requires a guest Linux kernel built with the
``CONFIG_DRM_VIRTIO_GPU`` option.

QEMU virtio-gpu variants
------------------------

QEMU virtio-gpu device variants come in the following form:

* ``virtio-vga[-BACKEND]``
* ``virtio-gpu[-BACKEND][-INTERFACE]``
* ``vhost-user-vga``
* ``vhost-user-pci``

**Backends:** QEMU provides a 2D virtio-gpu backend, and two accelerated
backends: virglrenderer ('gl' device label) and rutabaga_gfx ('rutabaga'
device label). There is a vhost-user backend that runs the graphics stack
in a separate process for improved isolation.

**Interfaces:** QEMU further categorizes virtio-gpu device variants based
on the interface exposed to the guest. The interfaces can be classified
into VGA and non-VGA variants. The VGA ones are prefixed with virtio-vga
or vhost-user-vga while the non-VGA ones are prefixed with virtio-gpu or
vhost-user-gpu.

The VGA ones always use the PCI interface, but for the non-VGA ones, the
user can further pick between MMIO or PCI. For MMIO, the user can suffix
the device name with -device, though vhost-user-gpu does not support MMIO.
For PCI, the user can suffix it with -pci. Without these suffixes, the
platform default will be chosen.

virtio-gpu 2d
-------------

The default 2D backend only performs 2D operations. The guest needs to
employ a software renderer for 3D graphics.

Typically, the software renderer is provided by `Mesa`_ or `SwiftShader`_.
Mesa's implementations (LLVMpipe, Lavapipe and virgl below) work out of box
on typical modern Linux distributions.

.. parsed-literal::
-device virtio-gpu
.. _Mesa: https://www.mesa3d.org/
.. _SwiftShader: https://github.com/google/swiftshader

virtio-gpu virglrenderer
------------------------

When using virgl accelerated graphics mode in the guest, OpenGL API calls
are translated into an intermediate representation (see `Gallium3D`_). The
intermediate representation is communicated to the host and the
`virglrenderer`_ library on the host translates the intermediate
representation back to OpenGL API calls.

.. parsed-literal::
-device virtio-gpu-gl
.. _Gallium3D: https://www.freedesktop.org/wiki/Software/gallium/
.. _virglrenderer: https://gitlab.freedesktop.org/virgl/virglrenderer/

virtio-gpu rutabaga
-------------------

virtio-gpu can also leverage rutabaga_gfx to provide `gfxstream`_
rendering and `Wayland display passthrough`_. With the gfxstream rendering
mode, GLES and Vulkan calls are forwarded to the host with minimal
modification.

The crosvm book provides directions on how to build a `gfxstream-enabled
rutabaga`_ and launch a `guest Wayland proxy`_.

This device does require host blob support (``hostmem`` field below). The
``hostmem`` field specifies the size of virtio-gpu host memory window.
This is typically between 256M and 8G.

At least one virtio-gpu capability set ("capset") must be specified when
starting the device. The currently capsets supported are ``gfxstream-vulkan``
and ``cross-domain`` for Linux guests. For Android guests, the experimental
``x-gfxstream-gles`` and ``x-gfxstream-composer`` capsets are also supported.

The device will try to auto-detect the wayland socket path if the
``cross-domain`` capset name is set. The user may optionally specify
``wayland-socket-path`` for non-standard paths.

The ``wsi`` option can be set to ``surfaceless`` or ``headless``.
Surfaceless doesn't create a native window surface, but does copy from the
render target to the Pixman buffer if a virtio-gpu 2D hypercall is issued.
Headless is like surfaceless, but doesn't copy to the Pixman buffer.
Surfaceless is the default if ``wsi`` is not specified.

.. parsed-literal::
-device virtio-gpu-rutabaga,gfxstream-vulkan=on,cross-domain=on,
hostmem=8G,wayland-socket-path=/tmp/nonstandard/mock_wayland.sock,
wsi=headless
.. _gfxstream: https://android.googlesource.com/platform/hardware/google/gfxstream/
.. _Wayland display passthrough: https://www.youtube.com/watch?v=OZJiHMtIQ2M
.. _gfxstream-enabled rutabaga: https://crosvm.dev/book/appendix/rutabaga_gfx.html
.. _guest Wayland proxy: https://crosvm.dev/book/devices/wayland.html
22 changes: 22 additions & 0 deletions hw/display/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU')
if_true: [files('virtio-gpu-gl.c', 'virtio-gpu-virgl.c'), pixman, virgl])
hw_display_modules += {'virtio-gpu-gl': virtio_gpu_gl_ss}
endif

if rutabaga.found()
virtio_gpu_rutabaga_ss = ss.source_set()
virtio_gpu_rutabaga_ss.add(when: ['CONFIG_VIRTIO_GPU', rutabaga],
if_true: [files('virtio-gpu-rutabaga.c'), pixman])
hw_display_modules += {'virtio-gpu-rutabaga': virtio_gpu_rutabaga_ss}
endif
endif

if config_all_devices.has_key('CONFIG_VIRTIO_PCI')
Expand All @@ -96,6 +103,12 @@ if config_all_devices.has_key('CONFIG_VIRTIO_PCI')
if_true: [files('virtio-gpu-pci-gl.c'), pixman])
hw_display_modules += {'virtio-gpu-pci-gl': virtio_gpu_pci_gl_ss}
endif
if rutabaga.found()
virtio_gpu_pci_rutabaga_ss = ss.source_set()
virtio_gpu_pci_rutabaga_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PCI', rutabaga],
if_true: [files('virtio-gpu-pci-rutabaga.c'), pixman])
hw_display_modules += {'virtio-gpu-pci-rutabaga': virtio_gpu_pci_rutabaga_ss}
endif
endif

if config_all_devices.has_key('CONFIG_VIRTIO_VGA')
Expand All @@ -114,6 +127,15 @@ if config_all_devices.has_key('CONFIG_VIRTIO_VGA')
virtio_vga_gl_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-vga.c'),
if_false: files('acpi-vga-stub.c'))
hw_display_modules += {'virtio-vga-gl': virtio_vga_gl_ss}

if rutabaga.found()
virtio_vga_rutabaga_ss = ss.source_set()
virtio_vga_rutabaga_ss.add(when: ['CONFIG_VIRTIO_VGA', rutabaga],
if_true: [files('virtio-vga-rutabaga.c'), pixman])
virtio_vga_rutabaga_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-vga.c'),
if_false: files('acpi-vga-stub.c'))
hw_display_modules += {'virtio-vga-rutabaga': virtio_vga_rutabaga_ss}
endif
endif

system_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_lcdc.c'))
Expand Down
6 changes: 5 additions & 1 deletion hw/display/virtio-gpu-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
{
VirtIOGPUBase *g = VIRTIO_GPU_BASE(vdev);

if (virtio_gpu_virgl_enabled(g->conf)) {
if (virtio_gpu_virgl_enabled(g->conf) ||
virtio_gpu_rutabaga_enabled(g->conf)) {
features |= (1 << VIRTIO_GPU_F_VIRGL);
}
if (virtio_gpu_edid_enabled(g->conf)) {
Expand All @@ -232,6 +233,9 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
if (virtio_gpu_blob_enabled(g->conf)) {
features |= (1 << VIRTIO_GPU_F_RESOURCE_BLOB);
}
if (virtio_gpu_context_init_enabled(g->conf)) {
features |= (1 << VIRTIO_GPU_F_CONTEXT_INIT);
}

return features;
}
Expand Down
47 changes: 47 additions & 0 deletions hw/display/virtio-gpu-pci-rutabaga.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */

#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qemu/module.h"
#include "hw/pci/pci.h"
#include "hw/qdev-properties.h"
#include "hw/virtio/virtio.h"
#include "hw/virtio/virtio-bus.h"
#include "hw/virtio/virtio-gpu-pci.h"
#include "qom/object.h"

#define TYPE_VIRTIO_GPU_RUTABAGA_PCI "virtio-gpu-rutabaga-pci"
OBJECT_DECLARE_SIMPLE_TYPE(VirtIOGPURutabagaPCI, VIRTIO_GPU_RUTABAGA_PCI)

struct VirtIOGPURutabagaPCI {
VirtIOGPUPCIBase parent_obj;

VirtIOGPURutabaga vdev;
};

static void virtio_gpu_rutabaga_initfn(Object *obj)
{
VirtIOGPURutabagaPCI *dev = VIRTIO_GPU_RUTABAGA_PCI(obj);

virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_GPU_RUTABAGA);
VIRTIO_GPU_PCI_BASE(obj)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
}

static const TypeInfo virtio_gpu_rutabaga_pci_info[] = {
{
.name = TYPE_VIRTIO_GPU_RUTABAGA_PCI,
.parent = TYPE_VIRTIO_GPU_PCI_BASE,
.instance_size = sizeof(VirtIOGPURutabagaPCI),
.instance_init = virtio_gpu_rutabaga_initfn,
.interfaces = (InterfaceInfo[]) {
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
}
},
};

DEFINE_TYPES(virtio_gpu_rutabaga_pci_info)

module_obj(TYPE_VIRTIO_GPU_RUTABAGA_PCI);
module_kconfig(VIRTIO_PCI);
module_dep("hw-display-virtio-gpu-pci");
14 changes: 14 additions & 0 deletions hw/display/virtio-gpu-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
DeviceState *vdev = DEVICE(g);
int i;

if (virtio_gpu_hostmem_enabled(g->conf)) {
vpci_dev->msix_bar_idx = 1;
vpci_dev->modern_mem_bar_idx = 2;
memory_region_init(&g->hostmem, OBJECT(g), "virtio-gpu-hostmem",
g->conf.hostmem);
pci_register_bar(&vpci_dev->pci_dev, 4,
PCI_BASE_ADDRESS_SPACE_MEMORY |
PCI_BASE_ADDRESS_MEM_PREFETCH |
PCI_BASE_ADDRESS_MEM_TYPE_64,
&g->hostmem);
virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem,
VIRTIO_GPU_SHM_ID_HOST_VISIBLE);
}

virtio_pci_force_virtio_1(vpci_dev);
if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
return;
Expand Down

0 comments on commit 0193b3b

Please sign in to comment.