Compare commits

...
Author SHA1 Message Date
Joelle van Dyne ad62ca9df7 HACK: workaround macOS memory space issue 2023-05-08 19:00:10 -07:00
Joelle van Dyne c592cda98b gfxstream + rutabaga: user backed memory mapping
Use user backed memory mapping for blobs.

Signed-off-by: Joelle van Dyne <[email protected]>
2023-05-08 19:00:10 -07:00
Joelle van Dyne 0fbf53b486 hvf: support user-backed memory mapping
This is largely taken from Android Emulator code. We break out internal
functions for mapping/unmapping and register them with the user backed
memory mapping functions.

Signed-off-by: Joelle van Dyne <[email protected]>
2023-05-07 23:23:02 -07:00
Lingfeng Yang c76ef530fd Allow address space device to work w/ TCG
bug: 156559140
bug: https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=52082

adds gpa2hva along with user backed ram map/unmap in a generic way so
that it can work with tcg

Test: Launch Fuchsia guest with TCG x86, Vulkan host rendering works
Change-Id: Ifa53dd89a8193132ed49a3f7d286f3992ccddc8f
2023-05-07 16:53:48 -07:00
Lingfeng Yang 1ba3a930f3 [qemu] API to directly control hypervisor mappings
This is convenient for if we want to add/remove host pointers
to the guest at runtime.

TODO: Need to expose this API to our opengl driver/translator
somewhere

Change-Id: I47fc36d33ff84e501fef7e37f3716d9b1028e35a
2023-05-07 16:53:31 -07:00
Lingfeng Yang cd5e931e1f [qemu] API to separately manage host backing of MemoryRegion
- memory_region_init_ram_user_backed
- memory_region_init_is_user_backed

This tells QEMU that we are reserving memory regions where
we will manage the hypervisor backing by ourselves.

Change-Id: I11b273565f021890313fdb7f54c49668f46edff0
2023-05-07 16:53:12 -07:00
Gurchetan Singh 31c7cb3c2c HACK: schedule fence return on main AIO context
gfxstream and both cross-domain (and even newer versions
virglrenderer: see VIRGL_RENDERER_ASYNC_FENCE_CB) like to signal
fence completion on threads ("callback threads") that are
different from the thread that processes the command queue
("main thread").

This is generally possible with locking, and this what we do
in crosvm and other virtio-gpu1.1 implementations.  However, on
QEMU a deadlock is observed if virtio_gpu_ctrl_response_nodata(..)
[used in the fence callback] is used from a thread that is not the
main thread.

The reason is the main thread takes the big QEMU lock (bql) somewhere
when processing the command queue, and virtio_gpu_ctrl_response_nodata(..)
needs that lock.  If you add in the lock needed to protect &g->fenceq
from concurrent access by the main thread and the callback threads,
you end can end up with deadlocks.

It's possible to workaround this by scheduling the return of the fence
descriptors via aio_bh_schedule_oneshot_full(..), but that somewhat
negates the rationale for the asynchronous callbacks.

I also played around with aio_context_acquire()/aio_context_release(),
doesn't seem to help.

Is signaling the virtio_queue outside of the main thread possible?  If
so, how?

Signed-off-by: Gurchetan Singh <[email protected]>
Message-Id: <[email protected]>
2023-05-07 16:52:34 -07:00
Gurchetan Singh aeb01a36ff gfxstream + rutabaga: enable rutabaga
This change enables rutabaga to receive virtio-gpu-3d hypercalls
when it is active.

Signed-off-by: Gurchetan Singh <[email protected]>
Message-Id: <[email protected]>
2023-05-05 22:21:43 -07:00
Gurchetan Singh 9d931f31d7 gfxstream + rutabaga: add initial support for gfxstream
This adds initial support for gfxstream and cross-domain.  Both
features rely on virtio-gpu blob resources and context types, which
are also implemented in this patch.

gfxstream has a long and illustrious history in Android graphics
paravirtualization.  It has been powering graphics in the Android
Studio Emulator for more than a decade, which is the main developer
platform.

Originally conceived by Jesse Hall, it was first known as "EmuGL" [a].
The key design characteristic was a 1:1 threading model and
auto-generation, which fit nicely with the OpenGLES spec.  It also
allowed easy layering with ANGLE on the host, which provides the GLES
implementations on Windows or MacOS enviroments.

gfxstream has traditionally been maintained by a single engineer, and
between 2015 to 2021, the iron throne passed to Frank Yang.  Just to
name a few accomplishments in a reign filled with many of them: newer
versions of GLES, address space graphics, snapshot support and CTS
compliant Vulkan [b].

One major drawback was the use of out-of-tree goldfish drivers.
Android engineers didn't know much about DRM/KMS and especially TTM so
a simple guest to host pipe was conceived.

Luckily, virtio-gpu 3D started to emerge in 2016 due to the work of
the Mesa/virglrenderer communities.  In 2018, the initial virtio-gpu
port of gfxstream was done by Cuttlefish enthusiast Alistair Delva.
It was a symbol compatible replacement of virglrenderer [c] and named
"AVDVirglrenderer".  This implementation forms the basis of the
current gfxstream host implementation still in use today.

cross-domain support follows a similar arc.  Originally conceived by
Wayland aficionado David Reveman and crosvm enjoyer Zach Reizner in
2018, it initially relied on the downstream "virtio-wl" device.

In 2020 and 2021, virtio-gpu was extended to include blob resources
and multiple timelines by yours truly, features gfxstream/cross-domain
both require to function correctly.

Right now, we stand at the precipice of a truly fantastic possibility:
the Android Emulator powered by upstream QEMU and upstream Linux
kernel.  gfxstream will then be packaged properfully, and app
developers can even fix gfxstream bugs on their own if they encounter
them.

It's been quite the ride, my friends.  Where will gfxstream head next,
nobody really knows.  I wouldn't be surprised if it's around for
another decade, maintained by a new generation of Android graphics
enthusiasts.  One thing is for sure, though -- it'll be filled with
friendship and magic!

Technical details:
  - Very simple initial display integration: just used Pixman
  - Largely, 1:1 mapping of virtio-gpu hypercalls to rutabaga function
    calls

[a] https://android-review.googlesource.com/c/platform/development/+/34470
[b] https://android-review.googlesource.com/q/topic:%22vulkan-hostconnection-start%22
[c] https://android-review.googlesource.com/c/device/generic/goldfish-opengl/+/761927

Signed-off-by: Gurchetan Singh <[email protected]>
Message-Id: <[email protected]>
2023-05-05 22:21:43 -07:00
Gurchetan Singh 0c94186492 gfxstream + rutabaga: add required meson changes
- Add meson detection of rutabaga_gfx
- Compile stubs when rutabaga_gfx_ffi is not installed
- Compile stubs when virglrenderer is not installed

Signed-off-by: Gurchetan Singh <[email protected]>
Message-Id: <[email protected]>
2023-05-05 22:21:43 -07:00
Gurchetan Singh 8c7dde0bcf gfxstream + rutabaga prep: added need defintions, fields, and options
This modifies the common virtio-gpu.h file have the fields and
defintions needed by gfxstream/rutabaga.  It also modifies VirtioGPUGL
to have the runtime options needed by rutabaga.  They are:

- a colon separated list of capset names, defined in the virtio spec
- a wayland socket path to enable guest Wayland passthrough

The command to run these would be:

-device virtio-vga-gl,capset_names=gfxstream:cross-domain, \
        wayland_socket_path=/run/user/1000/wayland-0,hostmem=8G  \

Signed-off-by: Gurchetan Singh <[email protected]>
Message-Id: <[email protected]>
2023-05-05 22:21:43 -07:00
Gurchetan Singh 278db8b669 gfxstream + rutabaga prep: define callbacks in realize function
This reduces the amount of renderer backend specific needed to
be exposed to the GL device.  We only need one realize function
per renderer backend.

Signed-off-by: Gurchetan Singh <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
2023-05-05 22:21:43 -07:00
Gurchetan Singh 39567fe521 gfxstream + rutabaga prep: make GL device more library agnostic
Rather than create a virtio-gpu-gfxstream device and it's
associated variants (vga, pci), let's just extend the GL device.

We need to:
    - Move all virgl functions to their own file
    - Only all needed class callbacks in the generic GL device

Signed-off-by: Gurchetan Singh <[email protected]>
Message-Id: <[email protected]>
2023-05-05 22:21:43 -07:00
Gurchetan Singh 06788ce54c gfxstream + rutabaga prep: virtio_gpu_gl -> virtio_gpu_virgl
The virtio-gpu GL device has a heavy dependence on virgl.
Acknowledge this by naming functions accurately.

Signed-off-by: Gurchetan Singh <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
2023-05-05 22:21:43 -07:00
Antonio Caggiano 5b48125a03 virtio-gpu: CONTEXT_INIT feature
The feature can be enabled when a backend wants it.

Signed-off-by: Antonio Caggiano <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Signed-off-by: Gurchetan Singh <[email protected]>
Message-Id: <[email protected]>
2023-05-05 22:21:43 -07:00
Antonio Caggiano f2a1033492 virtio-gpu blob prep: improve decoding and add memory region
This adds preparatory functions needed to:

     - decode blob cmds
     - track memory regions associated with mappable blobs
     - tracking iovecs

Signed-off-by: Antonio Caggiano <[email protected]>
Signed-off-by: Dmitry Osipenko <[email protected]>
Signed-off-by: Gurchetan Singh <[email protected]>
Message-Id: <[email protected]>
2023-05-05 22:21:43 -07:00
Gerd Hoffmann 1279855b6c virtio-gpu: hostmem
Use VIRTIO_GPU_SHM_ID_HOST_VISIBLE as id for virtio-gpu.

Signed-off-by: Antonio Caggiano <[email protected]>
Acked-by: Michael S. Tsirkin <[email protected]>
Message-Id: <[email protected]>
2023-05-05 22:21:43 -07:00
Dr. David Alan Gilbert 96cadd9af6 virtio: Add shared memory capability
Define a new capability type 'VIRTIO_PCI_CAP_SHARED_MEMORY_CFG' to allow
defining shared memory regions with sizes and offsets of 2^32 and more.
Multiple instances of the capability are allowed and distinguished
by a device-specific 'id'.

Signed-off-by: Dr. David Alan Gilbert <[email protected]>
Signed-off-by: Antonio Caggiano <[email protected]>
Message-Id: <[email protected]>
2023-05-05 22:21:42 -07:00
osy 689c8fd77a Merge tag 'v8.0.0' into utm-edition
v8.0.0 release
2023-04-30 20:14:13 -07:00
osy bd2fc471e7 Merge branch 'with_tcti_vectors' into utm-edition 2023-03-06 15:23:31 -08:00
Katherine Temkin 550af33ef5 meson tweaks for building with and _without_ JIT 2023-03-06 10:10:05 -08:00
osy 80c0e3099f vmnet: stop recieving events when VM is stopped
When the VM is stopped using the HMP command "stop", soon the handler will
stop reading from the vmnet interface. This causes a flood of
`VMNET_INTERFACE_PACKETS_AVAILABLE` events to arrive and puts the host CPU
at 100%. We fix this by removing the event handler from vmnet when the VM
is no longer in a running state and restore it when we return to a running
state.
2023-01-01 16:51:56 -08:00
osy c874e68e5a tcti: disable TARGET_TB_PCREL for TCTI
It is currently not supported.
2022-12-30 20:24:00 -08:00
osy 531da34587 hvf: support TSO mode (private feature)
Apple Silicon supports TSO mode which can be used for emulating strong
memory ordering in the guest. This feature requires the private entitlement
`com.apple.private.hypervisor` as well as a private function to modify
ACTLR_EL1 not exposed by the public Hypervisor framework.
2022-12-29 00:26:07 -08:00
osy 34b035535e spice-display: remove redundant glBindTexture 2022-12-24 17:08:52 -08:00
osy bb5c41eb13 spice-display: fix memory leak issues
1) Some of the error cases did not free GL memory.
2) Remove some unneeded logic and simplify the code.
3) Add a `eglMakeCurrent` to `spice_iosurface_destroy` to make sure we are
   freeing objects in the right context.
2022-12-20 15:56:07 -08:00
osy b3cf3579f5 Merge tag 'v7.2.0' into utm-edition
v7.2.0 release
2022-12-17 22:29:34 -08:00
osy 96e76ff0a1 Revert "egl-helpers: update EGL client version to 3.0"
This reverts commit f357b925b3.
2022-12-17 15:04:19 -08:00
osy 3ef0f0db05 Merge tag 'v7.1.0' into utm-edition
v7.1.0 release
2022-10-29 17:33:45 -07:00
osy f129a2b8db usbredir: avoid queuing hello packet on snapshot restore
When launching QEMU with "-loadvm", usbredir_create_parser() should avoid
setting up the hello packet (just as with "-incoming". On the latest version
of libusbredir, usbredirparser_unserialize() will return error if the parser
is not "pristine."
2022-08-08 16:13:20 -07:00
osy 6e9f737fcc vl: on -loadvm set run state to "restore-vm"
This allows us to differentiate between a fresh boot and a restore boot.
2022-08-08 16:11:21 -07:00
osy 51a16884c3 Revert "usbredir: avoid queuing hello packet on snapshot restore"
Run state is also in RUN_STATE_PRELAUNCH while "-S" is used.

This reverts commit 12d182898a.
2022-08-08 14:44:10 -07:00
osy 6626058f22 net/vmnet: use availability check at runtime
MAC_OS_X_VERSION_MIN_REQUIRED is set at compile time so this means that when
we target an older macOS version, it disables the newer features. With a
runtime check, we can selectively disable newer API features.
2022-05-17 19:48:48 -07:00
osy 0fbf694119 ui/cocoa: fix compile issues after merge 2022-05-11 16:34:54 -07:00
osy 12d182898a usbredir: avoid queuing hello packet on snapshot restore
When launching QEMU with "-loadvm", usbredir_create_parser() should avoid
setting up the hello packet (just as with "-incoming". On the latest version
of libusbredir, usbredirparser_unserialize() will return error if the parser
is not "pristine."
2022-05-06 21:09:31 -07:00
osy 25dfefc810 hw/arm/virt: revert old behaviour of highmem=off
On < macOS 12.4, a kernel panic is triggered for highmem=on and an error
is shown for highmem=off. We workaround this by inhibiting the error so
older versions of macOS can still use highmem=off.
2022-04-29 10:50:45 -07:00
osy 397bb125e1 Merge tag 'v7.0.0' into utm-edition
v7.0.0 release
2022-04-22 11:38:37 -07:00
osy 355b0824c6 Merge remote-tracking branch 'akihikodaki/macos' into utm-edition 2022-04-22 11:38:17 -07:00
Akihiko Odaki 84641e7ceb coreaudio: Initialize the buffer for device change
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:12:13 +09:00
Akihiko Odaki 1716a3f189 ui/cocoa: Use qemu_add_mouse_change_notifier
This eliminates the polling in cocoa_refresh and implements the
propagation of the mouse mode change from absolute to relative.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:12:08 +09:00
Gustavo Noronha Silva aac64f9286 ui/cocoa: handle mouse grab properly on window being key changes
Being key is similar to being focused on other platforms. When the
window loses focus at the moment it will still keep the mouse grabbed
unless it is using an absolute pointing device like a USB tablet.

That may happen in several ways as Mac OS does not let Qemu handle some
of the events even when it has a grab. Command-Tab will switch applications
if full-grab is off, and even if it is on you can still switch away from
by using 3-finger gestures on the trackpad to change spaces or open
Mission Control, for instance.

That behaviour is not ideal, as even though Qemu still believes it is
getting all the events, Mac OS has effectively released the mouse.
And it is worse with full-grab turned on, as it will still capture
the key events, making you unable to use the keyboard on the Mac OS
environment.

This change makes Qemu properly release the grab when Mac OS effectively
does it. In addition, it properly automatically regrabs the mouse when
the window becomes key and is fullscreen. While it makes sense to wait
for a click on a non-fullscreen window, as the user may just be moving
the window around, for instance, when it's fullscreen there is no point.

Signed-off-by: Gustavo Noronha Silva <[email protected]>
2022-03-25 16:12:02 +09:00
Akihiko Odaki 85af432691 ui/cocoa: Divide ui/cocoa.m 2022-03-25 16:11:56 +09:00
Akihiko Odaki a0167d013f ui/cocoa: Isolate fragments with preprocessor 2022-03-25 16:11:48 +09:00
Akihiko Odaki 3acd8e70ba ui/cocoa: Define types early 2022-03-25 16:11:42 +09:00
Akihiko Odaki e0af80866a Use virgl_renderer_borrow_texture_for_scanout
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:35 +09:00
Akihiko Odaki b3ebe68e23 ui/cocoa: Update cursor
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:28 +09:00
Akihiko Odaki 9e45375602 ui/cocoa: Take refresh rate into account
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:22 +09:00
Akihiko Odaki bdf261c858 Support Virgil 3D renderer on macOS
Virgil 3D renderer will be available with ui/cocoa on macOS.

The OpenGL backend is NSOpenGLContext for core profile, and
EGL (in particular, ANGLE) for ES profile.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:15 +09:00
Akihiko Odaki ad2fe378fe ui/cocoa: Do not scale UI without "Zoom To Fit"
Cocoa scales UI for high-resolution display like Retina, but we do not
need it since we now have our own "Zoom To Fit" work well also for
windows, and the guest is aware of the resolution thanks to UI
information. This change reverts the scaling.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:10 +09:00
Akihiko Odaki 3f620296d8 ui/curses: Do not use console_select
ui/curses is the only user of console_select. Move the implementation
to ui/curses.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:03 +09:00
Akihiko Odaki f2098f2c30 ui/cocoa: Do not use console_select
ui/cocoa needs to update the UI info when switching the console.
The behavior was implemented in cocoa_switch which was used to be called
by console_select. The function was however to switch the DisplaySurface
and overloaded. Have its own implementation of console_select and
update the UI info with it.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:10:57 +09:00
Akihiko Odaki 7dfd20c7e8 ui/vnc: Do not use console_select
console_select is shared by other displays and switching in one of them
triggers switching also in ui/vnc, circumventing key state
reinitialization specific to ui/vnc. Use its internal state to track
the current active console instead.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:10:48 +09:00
Akihiko Odaki 41eb76f5bf ui/vnc: Respect bound console
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:10:40 +09:00
Akihiko Odaki 99ac5e48e4 ui/console: Check console before emitting GL event
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:10:09 +09:00
Akihiko Odaki 67876f074e ui/cocoa: Respect left-command-key option
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:04:32 +09:00
Akihiko Odaki 781a23afc7 audio/mixeng: Do not declare unused variables
The unused variables when FLOAT_MIXENG is defined caused warnings on
Apple clang version 13.1.6 (clang-1316.0.21.2).

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:04:24 +09:00
Akihiko Odaki 1f24abea06 ui/cocoa: Use qemu_input_map_osx_to_qcode
ui/cocoa used to have a conversion table from macOS keycode to QKeyCode.
It is an unnecessary redundancy as ui/input-keymap.c already has such a
table. Worse, I added an incorrect mapping of kVK_JIS_Eisu and
kVK_JIS_Kana with commit 708b72557f.
According to the following documentations, the definitions in
ui/keycodemapdb/keymaps.csv, which ui/input-keymap.c uses, are correct:
https://developer.apple.com/documentation/uikit/uikeyboardhidusage/uikeyboardhidusagekeyboardlang1?language=objc
https://developer.apple.com/documentation/uikit/uikeyboardhidusage/uikeyboardhidusagekeyboardlang2?language=objc
https://docs.microsoft.com/en-us/windows-hardware/design/component-guidelines/keyboard-japan-ime

Use qemu_input_map_osx_to_qcode to eliminate the redundancy and
incorrect mappings.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:04:17 +09:00
Akihiko Odaki de8f1b03d0 block/file-posix: Use O_RDWR for locking on macOS
qemu_lock_fd_test always returns 0 when fd is not open for writing and
exclusive is true on macOS 11.3.1.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:04:11 +09:00
Akihiko Odaki 66553a8213 ui/cocoa: Use NSWindow's ability to resize
This change brings two new features:
- The window will be resizable if "Zoom To Fit" is eanbled
- The window can be made full screen by clicking full screen button
  provided by the platform. (The left-top green button.)

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:04:04 +09:00
Akihiko Odaki 4214699f96 coreaudio: Commit the result of init in the end
init_out_device may only commit some part of the result and leave the
state inconsistent when it encounters an error. Commit the result in
the end of the function so that it commits the result iif it sees no
error.

With this change, handle_voice_change can rely on core->outputDeviceID
to know whether the output device is initialized after calling
init_out_device.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:03:58 +09:00
Akihiko Odaki 401a81844b ui/cocoa: Do not raise keys before QEMU resigns active
ui/cocoa used to raise all keys before it resigns active to prevent a
stuck key problem caused by key up events it does not see while it is
inactive. The problem is solved by checking -[NSEvent modifierFlags] in
commit 6d73bb643a, which is better
because it handles the case that key *down* events are missed while it
is inactive.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:03:53 +09:00
Akihiko Odaki 129127242d virtio-gpu: Respect UI refresh rate for EDID
This change adds a new member, refresh_rate to QemuUIInfo in
include/ui/console.h. It represents the refresh rate of the
physical display backend, and it is more appropriate than
GUI update interval as the refresh rate which the emulated device
reports:
- sdl may set GUI update interval shorter than the refresh rate
  of the physical display to respond to user-generated events.
- sdl and vnc aggressively changes GUI update interval, but
  a guests is typically not designed to respond to frequent
  refresh rate changes, or frequent "display mode" changes in
  general. The frequency of refresh rate changes of the physical
  display backend matches better to the guest's expectation.

QemuUIInfo also has other members representing "display mode",
which makes it suitable for refresh rate representation. It has
a throttling of update notifications, and prevents frequent changes
of the display mode.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:03:47 +09:00
Akihiko Odaki c146fe8095 ui/cocoa: Initialize before setting UID and GID
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:02:50 +09:00
Akihiko Odaki e6441f8683 Merge tag 'patchew/[email protected]' 2022-03-18 18:20:45 +09:00
Vladislav Yaroshchuk 7135bae71b net/vmnet: update hmp-commands.hx
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk c9eb230657 net/vmnet: update qemu-options.hx
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk ee9a9b425f net/vmnet: implement bridged mode (vmnet-bridged)
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk 5286a192c8 net/vmnet: implement host mode (vmnet-host)
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk f854a87eeb net/vmnet: implement shared mode (vmnet-shared)
Interaction with vmnet.framework in different modes
differs only on configuration stage, so we can create
common `send`, `receive`, etc. procedures and reuse them.

Signed-off-by: Phillip Tennen <[email protected]>
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk 1699eb16a7 net/vmnet: add vmnet backends to qapi/net
Create separate netdevs for each vmnet operating mode:
- vmnet-host
- vmnet-shared
- vmnet-bridged

Acked-by: Markus Armbruster <[email protected]>
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk d1792ff228 net/vmnet: add vmnet dependency and customizable option
vmnet.framework dependency is added with 'vmnet' option
to enable or disable it. Default value is 'auto'.

used vmnet features are available since macOS 11.0,
but new backend can be built and work properly with
subset of them on 10.15 too.

Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Paolo Bonzini cd85cb5abe ui/cocoa: run qemu_init in the main thread
Simplify the initialization dance by running qemu_init() in the main
thread before the Cocoa event loop starts.  The cocoa_display_init()
code that is post-applicationDidFinishLaunching: moves to the
application delegate itself, and the secondary thread only runs
the rest of qemu_main(), namely qemu_main_loop() and qemu_cleanup().

This fixes a case where addRemovableDevicesMenuItems() calls
qmp_query_block() while expecting the main thread to still hold
the BQL.  The newly-introduced assertions in the block layer
complain about this.

Signed-off-by: Paolo Bonzini <[email protected]>
Message-Id: <[email protected]>
[PMD: Fixed trivial build failures & rebased]
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
2022-03-17 13:01:51 +00:00
Philippe Mathieu-Daudé c94e174af8 ui/cocoa: Code movement
Pure code movement in preparation for the next commit.

Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
2022-03-17 13:01:51 +00:00
osy 8f1617b581 pc: add option to disable PS/2 mouse/keyboard
On some older software like Windows 7 installer, having both a PS/2
mouse and USB mouse results in only one device working property (which
might be a different device each boot). While the workaround to not use
a USB mouse with such software is valid, it creates an inconsistent
experience if the user wishes to always use a USB mouse.

This introduces a new machine property to inhibit the creation of the
i8042 PS/2 controller.
2022-02-27 12:48:07 -08:00
osy fc43b65e06 rcu: do not register constructor thread if shared library
On iOS 15, the constructor can run on a new thread that is destroyed
after construction is finished in dyld. When this happens the TLS gets
freed and causes use-after-free when QEMU is built in shared library
mode. This moves the rcu_register_thread() call to qemu_init()
2022-02-25 23:57:19 -08:00
osy 6409730ff9 spice-display: reduce race in sending IOSurface
There is a kernel bug detailed in
https://github.com/utmapp/UTM/issues/2743#issuecomment-1047175257
which results in a race whenever IOSurfaceGetID/IOSurfaceLookup is used.
As a result, we need a way to "indicate" to the receiver that the
surface id in the pipe is now stale and should not be used. To do this
we send POLLHUP to poll() by closing the write FD when the surface is
about to be deallocated.

Note this does not fix the race completely as there is still a small
chance that the race happens between the close() and the CFRelease() but
the chance of that is small and the whole FD passing surface ID system
is a hack anyways that should be replaced with a proper set of SPICE
APIs one day...
2022-02-21 18:04:32 -08:00
osy cc24c9b7cb meson: build qemu-img as shared library 2022-01-10 15:35:44 -08:00
Alexander Graf 0d24c5332f HACK: hvf: arm: Always treat SMC as enabled conduit
The Windows 10 and 11 for ARM boot code implicitly assumes that SMC is a valid
SMCCC conduit to call for an OEM SMCCC call.

This patch forces HVF to treat SMC as an always active conduit, even when the
user has configured HVC. That way, the OEM SMCCC call gets handled as an
unimplemented SMCCC function (return -1) rather than an invalid conduit (inject
undefined instruction exception) which crashes Windows.

With this patch applied, I can successfully boot Windows for ARM Insider
Previews.

Signed-off-by: Alexander Graf <[email protected]>
2021-12-30 08:33:01 -08:00
osy 44cfb32e24 Merge tag 'v6.2.0' into utm-edition
v6.2.0 release
2021-12-29 11:44:40 -08:00
osy e73864e11d shaders: support byte swapping of pixels
Some EGL implementations do not support GL_BGRA_EXT so we always use
a surface format of GL_RGBA and then swap the bytes with a fragment
shader.
2021-09-08 20:03:21 -07:00
osy 2b73a7937d virtio-ramfb: break out GL supported device
This follows the same convention as other devices.
2021-09-07 01:36:59 -07:00
osy 753fffe1ea spice-display: support GL_TEXTURE_RECTANGLE_ANGLE
On macOS with CGL rendering backend, IOSurface only supports rectangle
texture targets. On iOS, EAGL, and Metal rendering backends IOSurface
only supports 2D texture targets.
2021-08-25 15:46:30 -07:00
osy e19e3cb9b5 Merge tag 'v6.1.0' into utm-edition
v6.1.0 release
2021-08-25 14:23:36 -07:00
osy 26324b7d94 Merge tag 'v6.1.0-rc4' into utm-edition
v6.1.0-rc4 release
2021-08-23 20:01:14 -07:00
osy 929b3859bd spice-display: send IOSurfaceID through pipe
This is still a hacky workaround to using mach ports but should support
different processes on macOS.
2021-08-08 12:18:33 -07:00
osy fdd3d1d3a0 virtio-ramfb: enable GL if supported 2021-08-08 12:18:33 -07:00
osy 345ec3279b tcti: fix build after latest TCG changes 2021-08-08 12:18:33 -07:00
osy e8f8220618 spice-display: fix crash in destroy texture with IOSurface 2021-08-02 11:27:44 -07:00
osy f275f433af Merge tag 'v6.1.0-rc1' into utm-edition
v6.1.0-rc1 release
2021-08-02 11:26:27 -07:00
osy f384e2c7eb spice-display: initial support for IOSurface rendering
In both surface and scanout mode, we blit the texture to a ANGLE texture
backed pbuffer using IOSurface. This IOSurface can be shared with a
separate process.

What needs to be done:
1) Handing of IOSurfaceRef through mach ports (Unix sockets are not
   supported. This implementation hacks in by passing the pointer through
   a file descriptor but this will fail if client is running in a separate
   process).
2) Cursor handling through QEMU (currently, the SPICE client will handle
   it).
2021-08-01 22:24:02 -07:00
osy dc386f9eb0 spice-display: support ANGLE backend
Add support for creating a pbuffer surface and setup from SPICE.
2021-08-01 22:22:14 -07:00
osy 1adb9ff17d spice-display: make GBM conditional 2021-08-01 22:17:23 -07:00
osy ce01739e6d egl-headless: fix compile without GBM 2021-08-01 22:13:51 -07:00
osy f357b925b3 egl-helpers: update EGL client version to 3.0
Required for Metal ANGLE to work on iOS
2021-08-01 22:13:11 -07:00
Akihiko Odaki edba23a4d4 egl-headless: Allow to test with Mesa on macOS
Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-26 14:38:10 -07:00
osy 3428101c02 configure: disable plugins for shared_lib builds 2021-07-26 14:32:44 -07:00
osy 1e8db1949d file-posix: fix holepunch build on iOS 2021-07-26 14:32:28 -07:00
osy e91d59cbea Merge branch 'utm-edition-v6.0.0' into utm-edition-v6.1.0-rc0 2021-07-26 14:30:35 -07:00
osy eace1c8c9f Merge branch 'virgl-support' into utm-edition-v6.1.0-rc0 2021-07-25 19:11:11 -07:00
Akihiko Odaki c800dbb61e block/file-posix: Use O_RDWR for locking on macOS
qemu_lock_fd_test always returns 0 when fd is not open for writing and
exclusive is true on macOS 11.3.1.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:55:03 +09:00
Akihiko Odaki b3a305701e ui: update keycodemapdb submodule commit
The change of ui/keycodemapdb effective on QEMU is only commit
d21009b1c9f94b740ea66be8e48a1d8ad8124023, which adds mappings for key
codes added in commit d7696ff884.

d21009b1c9f94b740ea66be8e48a1d8ad8124023 Add QEMU QKeyCode "lang1" and "lang2"
320f92c36a80bfafc5d57834592a7be5fd79f104 rust: fix cargo clippy
e62d42f0fd76f7bb8bf78385a83c060e66ff52b0 tests: add rust test
3e25e1ca1772fc3f2039f739f8f920450dc68e50 gen: add --lang rust
9133a0b8022d1fb063a81cc2ba3b627c14ccdfd1 tests: fix argument order

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:54:59 +09:00
Akihiko Odaki 21954ae12a coreaudio: Commit the result of init in the end
init_out_device may only commit some part of the result and leave the
state inconsistent when it encounters an error. Commit the result in
the end of the function so that it commits the result iif it sees no
error.

With this change, handle_voice_change can rely on core->outputDeviceID
to know whether the output device is initialized after calling
init_out_device.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:54:51 +09:00
Akihiko Odaki 61f5befa07 virtio-gpu: Call Virgl only in the main thread
Virgl relies on callbacks provided by the OpenGL display, and such a
display may rely on eglMakeCurrent. eglMakeCurrent will fail if the
given context is current to some other thread. The easiest way to avoid
such a failure is to call the OpenGL display in a single thread. As all
operations except virtio_gpu_virgl_reset happens in the main thread,
this change makes virtio_gpu_virgl_reset happen only in the main thread.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:54:45 +09:00
Gustavo Noronha Silva 45c171c238 ui/cocoa: handle mouse grab properly on window being key changes
Being key is similar to being focused on other platforms. When the
window loses focus at the moment it will still keep the mouse grabbed
unless it is using an absolute pointing device like a USB tablet.

That may happen in several ways as Mac OS does not let Qemu handle some
of the events even when it has a grab. Command-Tab will switch applications
if full-grab is off, and even if it is on you can still switch away from
by using 3-finger gestures on the trackpad to change spaces or open
Mission Control, for instance.

That behaviour is not ideal, as even though Qemu still believes it is
getting all the events, Mac OS has effectively released the mouse.
And it is worse with full-grab turned on, as it will still capture
the key events, making you unable to use the keyboard on the Mac OS
environment.

This change makes Qemu properly release the grab when Mac OS effectively
does it. In addition, it properly automatically regrabs the mouse when
the window becomes key and is fullscreen. While it makes sense to wait
for a click on a non-fullscreen window, as the user may just be moving
the window around, for instance, when it's fullscreen there is no point.

Signed-off-by: Gustavo Noronha Silva <[email protected]>
2021-07-14 14:54:37 +09:00
Phillip Tennen 1b10cab21a net/macos: implement vmnet-based netdev
This patch implements a new netdev device, reachable via -netdev
vmnet-macos, that’s backed by macOS’s vmnet framework.

The vmnet framework provides native bridging support, and its usage in
this patch is intended as a replacement for attempts to use a tap device
via the tuntaposx kernel extension. Notably, the tap/tuntaposx approach
never would have worked in the first place, as QEMU interacts with the
tap device via poll(), and macOS does not support polling device files.

vmnet requires either a special entitlement, granted via a provisioning
profile, or root access. Otherwise attempts to create the virtual
interface will fail with a “generic error” status code. QEMU may not
currently be signed with an entitlement granted in a provisioning
profile, as this would necessitate pre-signed binary build distribution,
rather than source-code distribution. As such, using this netdev
currently requires that qemu be run with root access. I’ve opened a
feedback report with Apple to allow the use of the relevant entitlement
with this use case:
https://openradar.appspot.com/radar?id=5007417364447232

vmnet offers three operating modes, all of which are supported by this
patch via the “mode=host|shared|bridge” option:

* "Host" mode: Allows the vmnet interface to communicate with other
* vmnet
interfaces that are in host mode and also with the native host.
* "Shared" mode: Allows traffic originating from the vmnet interface to
reach the Internet through a NAT. The vmnet interface can also
communicate with the native host.
* "Bridged" mode: Bridges the vmnet interface with a physical network
interface.

Each of these modes also provide some extra configuration that’s
supported by this patch:

* "Bridged" mode: The user may specify the physical interface to bridge
with. Defaults to en0.
* "Host" mode / "Shared" mode: The user may specify the DHCP range and
subnet. Allocated by vmnet if not provided.

vmnet also offers some extra configuration options that are not
supported by this patch:

* Enable isolation from other VMs using vmnet
* Port forwarding rules
* Enabling TCP segmentation offload
* Only applicable in "shared" mode: specifying the NAT IPv6 prefix
* Only available in "host" mode: specifying the IP address for the VM
within an isolated network

Note that this patch requires macOS 10.15 as a minimum, as this is when
bridging support was implemented in vmnet.framework.

Rebased to commit 9aef095419 by Akihiko
Odaki.

Signed-off-by: Phillip Tennen <[email protected]>
Signed-off-by: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
2021-07-14 14:54:30 +09:00
Akihiko Odaki c61c853e1f ui/cocoa: Divide ui/cocoa.m 2021-07-14 14:54:25 +09:00
Akihiko Odaki 8681835e66 ui/cocoa: Isolate fragments with preprocessor 2021-07-14 14:54:19 +09:00
Akihiko Odaki adaef950b5 ui/cocoa: Define types early 2021-07-14 14:54:14 +09:00
Akihiko Odaki a1cbf10708 ui/cocoa: Use qemu_input_map_osx_to_qcode
ui/cocoa used to have a conversion table from macOS keycode to QKeyCode.
It is an unnecessary redundancy as ui/input-keymap.c already has such a
table. Worse, I added an incorrect mapping of kVK_JIS_Eisu and
kVK_JIS_Kana with commit 708b72557f.
According to the following documentations, the definitions in
ui/keycodemapdb/keymaps.csv, which ui/input-keymap.c uses, are correct:
https://developer.apple.com/documentation/uikit/uikeyboardhidusage/uikeyboardhidusagekeyboardlang1?language=objc
https://developer.apple.com/documentation/uikit/uikeyboardhidusage/uikeyboardhidusagekeyboardlang2?language=objc
https://docs.microsoft.com/en-us/windows-hardware/design/component-guidelines/keyboard-japan-ime

Use qemu_input_map_osx_to_qcode to eliminate the redundancy and
incorrect mappings.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:54:08 +09:00
Akihiko Odaki d0c0d66796 ui/cocoa: Do not raise keys before QEMU resigns active
ui/cocoa used to raise all keys before it resigns active to prevent a
stuck key problem caused by key up events it does not see while it is
inactive. The problem is solved by checking -[NSEvent modifierFlags] in
commit 6d73bb643a, which is better
because it handles the case that key *down* events are missed while it
is inactive.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:54:04 +09:00
Akihiko Odaki 920d2875a0 Use virgl_renderer_borrow_texture_for_scanout
virgl_renderer_borrow_texture_for_scanout is a replacement of
virgl_renderer_resource_get_info and performs configurations such as
swizzle and sRGB decode.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:59 +09:00
Akihiko Odaki 5ba17fba6e ui/cocoa: Update cursor
Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:53 +09:00
Akihiko Odaki 51f8c2e5b8 ui/cocoa: Take refresh rate into account
Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:48 +09:00
Akihiko Odaki 3184f37bbe Support Virgil 3D renderer on macOS
Virgil 3D renderer will be available with ui/cocoa on macOS.

The OpenGL backend is NSOpenGLContext for core profile, and
EGL (in particular, ANGLE) for ES profile.

As a notable change, CONFIG_OPENGL_DMABUF is replaced with the
combination of CONFIG_EGL and CONFIG_GBM. In fact, the old
detection of DMA-BUF in configure script was not working
because EGL_MESA_image_dma_buf_export is always defined in
<epoxy/egl.h>. Therefore, the new combination should
behave in the same way.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:43 +09:00
Akihiko Odaki 110dbe7e89 ui/spice: Use HAVE_SPICE_GL for OpenGL checks
Some code in ui/spice used CONFIG_OPENGL for OpenGL conditionals, but
SPICE also depends on CONFIG_GBM and SPICE server whose version is
0.13.1 or later for OpenGL. Always use HAVE_SPICE_GL, which defines the
precise condition.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:29 +09:00
Akihiko Odaki 2565eea22b ui/egl-headless: Remove a check for CONFIG_OPENGL
ui/egl-headless is only built when CONFIG_OPENGL is defined because it
depends on CONFIG_OPENGL without condition. Remove a redundant
conditonal in ui/egl-headless.c

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:17 +09:00
Akihiko Odaki 8c2f5eff66 virtio-gpu: Respect UI refresh rate for EDID
This change adds a new member, refresh_rate to QemuUIInfo in
include/ui/console.h. It represents the refresh rate of the
physical display backend, and it is more appropriate than
GUI update interval as the refresh rate which the emulated device
reports:
- sdl may set GUI update interval shorter than the refresh rate
  of the physical display to respond to user-generated events.
- sdl and vnc aggressively changes GUI update interval, but
  a guests is typically not designed to respond to frequent
  refresh rate changes, or frequent "display mode" changes in
  general. The frequency of refresh rate changes of the physical
  display backend matches better to the guest's expectation.

QemuUIInfo also has other members representing "display mode",
which makes it suitable for refresh rate representation. It has
a throttling of update notifications, and prevents frequent changes
of the display mode.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 12:15:46 +09:00
Akihiko Odaki db430377c0 ui/cocoa: Do not scale UI without "Zoom To Fit"
Cocoa scales UI for high-resolution display like Retina, but we do not
need it since we now have our own "Zoom To Fit" work well also for
windows, and the guest is aware of the resolution thanks to UI
information. This change reverts the scaling.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 12:15:30 +09:00
Akihiko Odaki b2708c4684 ui/cocoa: Use the standard about panel
This provides standard look and feel for the about panel and reduces
code.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 12:15:23 +09:00
Akihiko Odaki 9ea8f7a804 ui/cocoa: Do not perform unsafe cast of argv
Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 12:15:10 +09:00
Akihiko Odaki 6a1e678f5b ui/cocoa: Use NSWindow's ability to resize
This change brings two new features:
- The window will be resizable if "Zoom To Fit" is eanbled
- The window can be made full screen by clicking full screen button
  provided by the platform. (The left-top green button.)

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 12:14:21 +09:00
Akihiko Odaki 902616b2f0 Merge tag 'patchew/[email protected]' 2021-07-14 12:02:33 +09:00
Gustavo Noronha Silva bc73e87997 ui/cocoa: add option to swap Option and Command
On Mac OS X the Option key maps to Alt and Command to Super/Meta. This change
swaps them around so that Alt is the key closer to the space bar and Meta/Super
is between Control and Alt, like on non-Mac keyboards.

It is a cocoa display option, disabled by default.

Acked-by: Markus Armbruster <[email protected]>
Reviewed-by: Akihiko Odaki <[email protected]>
Signed-off-by: Gustavo Noronha Silva <[email protected]>
Message-Id: <[email protected]>
2021-07-13 23:00:52 +00:00
Gustavo Noronha Silva 7292f1fc18 ui/cocoa: capture all keys and combos when mouse is grabbed
Applications such as Gnome may use Alt-Tab and Super-Tab for different
purposes, some use Ctrl-arrows so we want to allow qemu to handle
everything when it captures the mouse/keyboard.

However, Mac OS handles some combos like Command-Tab and Ctrl-arrows
at an earlier part of the event handling chain, not letting qemu see it.

We add a global Event Tap that allows qemu to see all events when the
mouse is grabbed. Note that this requires additional permissions.

See:

https://developer.apple.com/documentation/coregraphics/1454426-cgeventtapcreate?language=objc#discussion
https://support.apple.com/en-in/guide/mac-help/mh32356/mac

Acked-by: Markus Armbruster <[email protected]>
Reviewed-by: Akihiko Odaki <[email protected]>
Signed-off-by: Gustavo Noronha Silva <[email protected]>
Message-Id: <[email protected]>
2021-07-13 23:00:52 +00:00
Yasuo Kuwahara 2ee6330b9e tcg/aarch64: Fix tcg_out_rotl
The last argument of tcg_out_extr() must be in the range 0-31 if ext==0.
Before the fix, when m==0 it becomes 32 and it crashes with an Illegal
instruction on Apple Silicon.  After the fix, it will be 0.  If m is in
the range 1-31, it is the same as before.

Signed-off-by: Yasuo Kuwahara <[email protected]>
Message-Id: <CAHfJ0vSXnmnTLmT0kR=a8ACRdw_UsLYOhStzUzgVEHoH8U-7sA@mail.gmail.com>
Signed-off-by: Richard Henderson <[email protected]>
2021-07-09 13:36:27 -07:00
Alexander Graf a0db5bfa90 hvf: arm: Handle Windows 10 SMC call
Windows 10 calls an SMCCC call via SMC unconditionally on boot. It lives
in the trusted application call number space, but its purpose is unknown.

In our current SMC implementation, we inject a UDEF for unknown SMC calls,
including this one. However, Windows breaks on boot when we do this. Instead,
let's return an error code.

With this patch applied I can successfully boot the current Windows 10
Insider Preview in HVF.

Signed-off-by: Alexander Graf <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:14 +00:00
Alexander Graf 998320a3da arm: Enable Windows 10 trusted SMCCC boot call
Windows 10 calls an SMCCC call via SMC unconditionally on boot. It lives
in the trusted application call number space, but its purpose is unknown.

In our current SMC implementation, we inject a UDEF for unknown SMC calls,
including this one. However, Windows breaks on boot when we do this. Instead,
let's return an error code.

With this and -M virt,virtualization=on I can successfully boot the current
Windows 10 Insider Preview in TCG.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:13 +00:00
Alexander Graf 8137225fde arm: Add Hypervisor.framework build target
Now that we have all logic in place that we need to handle Hypervisor.framework
on Apple Silicon systems, let's add CONFIG_HVF for aarch64 as well so that we
can build it.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]> (x86 only)

Message-Id: <[email protected]>
2021-05-27 12:30:13 +00:00
Alexander Graf 3f09807e7f hvf: arm: Implement PSCI handling
We need to handle PSCI calls. Most of the TCG code works for us,
but we can simplify it to only handle aa64 mode and we need to
handle SUSPEND differently.

This patch takes the TCG code as template and duplicates it in HVF.

To tell the guest that we support PSCI 0.2 now, update the check in
arm_cpu_initfn() as well.

Signed-off-by: Alexander Graf <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:13 +00:00
Alexander Graf 17d38dc6d9 hvf: arm: Implement -cpu host
Now that we have working system register sync, we push more target CPU
properties into the virtual machine. That might be useful in some
situations, but is not the typical case that users want.

So let's add a -cpu host option that allows them to explicitly pass all
CPU capabilities of their host CPU into the guest.

Signed-off-by: Alexander Graf <[email protected]>
Acked-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:13 +00:00
Peter Collingbourne 66c71d88ed arm/hvf: Add a WFI handler
Sleep on WFI until the VTIMER is due but allow ourselves to be woken
up on IPI.

In this implementation IPI is blocked on the CPU thread at startup and
pselect() is used to atomically unblock the signal and begin sleeping.
The signal is sent unconditionally so there's no need to worry about
races between actually sleeping and the "we think we're sleeping"
state. It may lead to an extra wakeup but that's better than missing
it entirely.

Signed-off-by: Peter Collingbourne <[email protected]>
[agraf: Remove unused 'set' variable, always advance PC on WFX trap]
Signed-off-by: Alexander Graf <[email protected]>
Acked-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:12 +00:00
Alexander Graf 30adfa9b1d hvf: Add Apple Silicon support
With Apple Silicon available to the masses, it's a good time to add support
for driving its virtualization extensions from QEMU.

This patch adds all necessary architecture specific code to get basic VMs
working. It's still pretty raw, but definitely functional.

Known limitations:

  - Vtimer acknowledgement is hacky
  - Should implement more sysregs and fault on invalid ones then
  - WFI handling is missing, need to marry it with vtimer

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:12 +00:00
Alexander Graf 3bf12f1f40 hvf: Simplify post reset/init/loadvm hooks
The hooks we have that call us after reset, init and loadvm really all
just want to say "The reference of all register state is in the QEMU
vcpu struct, please push it".

We already have a working pushing mechanism though called cpu->vcpu_dirty,
so we can just reuse that for all of the above, syncing state properly the
next time we actually execute a vCPU.

This fixes PSCI resets on ARM, as they modify CPU state even after the
post init call has completed, but before we execute the vCPU again.

To also make the scheme work for x86, we have to make sure we don't
move stale eflags into our env when the vcpu state is dirty.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:12 +00:00
Alexander Graf 4c82b50085 hvf: Introduce hvf vcpu struct
We will need more than a single field for hvf going forward. To keep
the global vcpu struct uncluttered, let's allocate a special hvf vcpu
struct, similar to how hax does it.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:12 +00:00
Alexander Graf f3b4506f14 hvf: Remove hvf-accel-ops.h
We can move the definition of hvf_vcpu_exec() into our internal
hvf header, obsoleting the need for hvf-accel-ops.h.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:12 +00:00
Alexander Graf 056bdd9a51 hvf: Make synchronize functions static
The hvf accel synchronize functions are only used as input for local
callback functions, so we can make them static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:11 +00:00
Alexander Graf 0bc7389a8e hvf: Use cpu_synchronize_state()
There is no reason to call the hvf specific hvf_cpu_synchronize_state()
when we can just use the generic cpu_synchronize_state() instead. This
allows us to have less dependency on internal function definitions and
allows us to make hvf_cpu_synchronize_state() static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:11 +00:00
Alexander Graf 9517f7e873 hvf: Split out common code on vcpu init and destroy
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch splits the vcpu init and destroy functions into a generic and
an architecture specific portion. This also allows us to move the generic
functions into the generic hvf code, removing exported functions.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:11 +00:00
Alexander Graf 30c2f78449 hvf: Remove use of hv_uvaddr_t and hv_gpaddr_t
The ARM version of Hypervisor.framework no longer defines these two
types, so let's just revert to standard ones.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:11 +00:00
Alexander Graf ea9f45cec5 hvf: Make hvf_set_phys_mem() static
The hvf_set_phys_mem() function is only called within the same file.
Make it static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:10 +00:00
Alexander Graf 82e6e2bdff hvf: Move hvf internal definitions into common header
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves a few internal struct and constant defines over.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:10 +00:00
Alexander Graf ffb51175ba hvf: Move cpu functions into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves CPU and memory operations over. While at it, make sure
the code is consumable on non-i386 systems.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:10 +00:00
Alexander Graf a13fec6c17 hvf: Move vcpu thread functions into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves the vCPU thread loop over.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:10 +00:00
Alexander Graf cf664b3a04 hvf: Move assert_hvf_ok() into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves assert_hvf_ok() and introduces generic build infrastructure.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:09 +00:00
John Arbuckle 5897229105 Implement the Screamer sound chip for the mac99 machine type
This patch enables the playback of audio on a Mac OS 9 or Mac OS X guest.

Signed-off-by: John Arbuckle <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:30:23 -07:00
osy d35954d3c9 tcti: mark gadgets static to reduce symbol size in shared library builds 2021-05-23 20:30:23 -07:00
Kate Temkin 64dcc3969b TCTI: add TCTI TCG backend for acceleration on non-JIT AArch64 2021-05-23 20:30:23 -07:00
Phillip Tennen 06962e1aaa net/macos: implement vmnet-based netdev
This patch implements a new netdev device, reachable via -netdev
vmnet-macos, that’s backed by macOS’s vmnet framework.

The vmnet framework provides native bridging support, and its usage in
this patch is intended as a replacement for attempts to use a tap device
via the tuntaposx kernel extension. Notably, the tap/tuntaposx approach
never would have worked in the first place, as QEMU interacts with the
tap device via poll(), and macOS does not support polling device files.

vmnet requires either a special entitlement, granted via a provisioning
profile, or root access. Otherwise attempts to create the virtual
interface will fail with a “generic error” status code. QEMU may not
currently be signed with an entitlement granted in a provisioning
profile, as this would necessitate pre-signed binary build distribution,
rather than source-code distribution. As such, using this netdev
currently requires that qemu be run with root access. I’ve opened a
feedback report with Apple to allow the use of the relevant entitlement
with this use case:
https://openradar.appspot.com/radar?id=5007417364447232

vmnet offers three operating modes, all of which are supported by this
patch via the “mode=host|shared|bridge” option:

* "Host" mode: Allows the vmnet interface to communicate with other
* vmnet
interfaces that are in host mode and also with the native host.
* "Shared" mode: Allows traffic originating from the vmnet interface to
reach the Internet through a NAT. The vmnet interface can also
communicate with the native host.
* "Bridged" mode: Bridges the vmnet interface with a physical network
interface.

Each of these modes also provide some extra configuration that’s
supported by this patch:

* "Bridged" mode: The user may specify the physical interface to bridge
with. Defaults to en0.
* "Host" mode / "Shared" mode: The user may specify the DHCP range and
subnet. Allocated by vmnet if not provided.

vmnet also offers some extra configuration options that are not
supported by this patch:

* Enable isolation from other VMs using vmnet
* Port forwarding rules
* Enabling TCP segmentation offload
* Only applicable in "shared" mode: specifying the NAT IPv6 prefix
* Only available in "host" mode: specifying the IP address for the VM
within an isolated network

Note that this patch requires macOS 10.15 as a minimum, as this is when
bridging support was implemented in vmnet.framework.

Rebased to commit 571d413b5d by Akihiko
Odaki.

Signed-off-by: Phillip Tennen <[email protected]>
Signed-off-by: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:30:23 -07:00
osy ec151f4659 Merge branch 'hvf-aarch64-patch-v8' into utm-edition-v6.0.0 2021-05-23 20:28:47 -07:00
Alexander Graf 9d9ca24b72 hvf: arm: Handle Windows 10 SMC call
Windows 10 calls an SMCCC call via SMC unconditionally on boot. It lives
in the trusted application call number space, but its purpose is unknown.

In our current SMC implementation, we inject a UDEF for unknown SMC calls,
including this one. However, Windows breaks on boot when we do this. Instead,
let's return an error code.

With this patch applied I can successfully boot the current Windows 10
Insider Preview in HVF.

Signed-off-by: Alexander Graf <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf fe1b754eab arm: Enable Windows 10 trusted SMCCC boot call
Windows 10 calls an SMCCC call via SMC unconditionally on boot. It lives
in the trusted application call number space, but its purpose is unknown.

In our current SMC implementation, we inject a UDEF for unknown SMC calls,
including this one. However, Windows breaks on boot when we do this. Instead,
let's return an error code.

With this and -M virt,virtualization=on I can successfully boot the current
Windows 10 Insider Preview in TCG.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf 6d6e43ebce arm: Add Hypervisor.framework build target
Now that we have all logic in place that we need to handle Hypervisor.framework
on Apple Silicon systems, let's add CONFIG_HVF for aarch64 as well so that we
can build it.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]> (x86 only)

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf f479e7eacd hvf: arm: Implement PSCI handling
We need to handle PSCI calls. Most of the TCG code works for us,
but we can simplify it to only handle aa64 mode and we need to
handle SUSPEND differently.

This patch takes the TCG code as template and duplicates it in HVF.

To tell the guest that we support PSCI 0.2 now, update the check in
arm_cpu_initfn() as well.

Signed-off-by: Alexander Graf <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf dbbbd13bf6 hvf: arm: Implement -cpu host
Now that we have working system register sync, we push more target CPU
properties into the virtual machine. That might be useful in some
situations, but is not the typical case that users want.

So let's add a -cpu host option that allows them to explicitly pass all
CPU capabilities of their host CPU into the guest.

Signed-off-by: Alexander Graf <[email protected]>
Acked-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Peter Collingbourne dc32fd2d89 arm/hvf: Add a WFI handler
Sleep on WFI until the VTIMER is due but allow ourselves to be woken
up on IPI.

In this implementation IPI is blocked on the CPU thread at startup and
pselect() is used to atomically unblock the signal and begin sleeping.
The signal is sent unconditionally so there's no need to worry about
races between actually sleeping and the "we think we're sleeping"
state. It may lead to an extra wakeup but that's better than missing
it entirely.

Signed-off-by: Peter Collingbourne <[email protected]>
[agraf: Remove unused 'set' variable, always advance PC on WFX trap]
Signed-off-by: Alexander Graf <[email protected]>
Acked-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf 3354c800ac hvf: Add Apple Silicon support
With Apple Silicon available to the masses, it's a good time to add support
for driving its virtualization extensions from QEMU.

This patch adds all necessary architecture specific code to get basic VMs
working. It's still pretty raw, but definitely functional.

Known limitations:

  - Vtimer acknowledgement is hacky
  - Should implement more sysregs and fault on invalid ones then
  - WFI handling is missing, need to marry it with vtimer

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf 365294d55a hvf: Simplify post reset/init/loadvm hooks
The hooks we have that call us after reset, init and loadvm really all
just want to say "The reference of all register state is in the QEMU
vcpu struct, please push it".

We already have a working pushing mechanism though called cpu->vcpu_dirty,
so we can just reuse that for all of the above, syncing state properly the
next time we actually execute a vCPU.

This fixes PSCI resets on ARM, as they modify CPU state even after the
post init call has completed, but before we execute the vCPU again.

To also make the scheme work for x86, we have to make sure we don't
move stale eflags into our env when the vcpu state is dirty.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf a6bff5ccc8 hvf: Introduce hvf vcpu struct
We will need more than a single field for hvf going forward. To keep
the global vcpu struct uncluttered, let's allocate a special hvf vcpu
struct, similar to how hax does it.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf c803fc9d7d hvf: Remove hvf-accel-ops.h
We can move the definition of hvf_vcpu_exec() into our internal
hvf header, obsoleting the need for hvf-accel-ops.h.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf 653cc15628 hvf: Make synchronize functions static
The hvf accel synchronize functions are only used as input for local
callback functions, so we can make them static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf 2e77c788d8 hvf: Use cpu_synchronize_state()
There is no reason to call the hvf specific hvf_cpu_synchronize_state()
when we can just use the generic cpu_synchronize_state() instead. This
allows us to have less dependency on internal function definitions and
allows us to make hvf_cpu_synchronize_state() static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf 1534c4fe04 hvf: Split out common code on vcpu init and destroy
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch splits the vcpu init and destroy functions into a generic and
an architecture specific portion. This also allows us to move the generic
functions into the generic hvf code, removing exported functions.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf 3a513c9db4 hvf: Remove use of hv_uvaddr_t and hv_gpaddr_t
The ARM version of Hypervisor.framework no longer defines these two
types, so let's just revert to standard ones.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf e27df17c9c hvf: Make hvf_set_phys_mem() static
The hvf_set_phys_mem() function is only called within the same file.
Make it static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf aa7ebf9a77 hvf: Move hvf internal definitions into common header
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves a few internal struct and constant defines over.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf be54898fd5 hvf: Move cpu functions into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves CPU and memory operations over. While at it, make sure
the code is consumable on non-i386 systems.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf 7a64de81ce hvf: Move vcpu thread functions into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves the vCPU thread loop over.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf 71f21b796f hvf: Move assert_hvf_ok() into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves assert_hvf_ok() and introduces generic build infrastructure.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Kate Temkin 13c9a7c820 TCTI: expand vector support to all ops 2021-05-06 16:58:56 -06:00
Kate Temkin 21ad741c1c TCTI: add initial vector instruction support 2021-05-06 08:53:59 -06:00
Kate Temkin 671b3cefcc TCTI: add remaining scalar ops 2021-05-04 08:02:19 -06:00
Kate Temkin 026956a474 TCTI: minor gadget optimizations 2021-05-04 06:19:41 -06:00
Kate Temkin 919856f02e Merge branch 'with_tcti_modular' into with_tcti 2021-04-30 11:44:01 -06:00
Kate Temkin cd4b5da233 TCTI: optimize I/O operation and helper call speeds 2021-04-30 11:40:17 -06:00
Joelle van Dyne 4e70afa94d coroutine: add libucontext as external library
iOS does not support ucontext natively for aarch64 and the sigaltstack is
also unsupported (even worse, it fails silently, see:
https://openradar.appspot.com/13002712 )

As a workaround we include a library implementation of ucontext and add it
as a build option.
2021-04-29 23:29:35 -07:00
osy 36195a781c tcg: custom APRR implementation 2021-04-29 23:29:35 -07:00
Marc-André Lureau 2541dde936 build-sys: make libslirp a meson subproject
Remove the manual build.

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-04-29 23:29:35 -07:00
Marc-André Lureau ecc067a3ba slirp: update to git master
git cherry-diff:

Commits on bacb71f1c3ed5f40e393afd8be81bedfba13a401 branch that is not on 8f43a99191afb47ca3f3c6972f6306209f367ece branch
+ 1021b0dc38d39f1dc95a296fe3e05a24a087cdc6 disable_dns option
+ 0f94ceec752592e4ac632a24e3c64a97dd09bf4c limit vnameserver_addr to port 53
+ b57bafa852ef16b133907a13678ec69e9531f177 libslirp.h: fix SlirpConfig v3 documentation
+ 1abf18b2b5edb462797629ed47ad4515a195686e Update CHANGELOG
+ ff4ecf9b6c6542b24b4ac6ea178be9d44e159f79 Release v4.3.0
+ 21f1d933050a40d62612c6274c32de60b811d9ea changelog: post-release
+ 376187c4b14c795763d472214812826eebe7e9c2 Release v4.3.1
+ 73336e08902a7e826f7d960453df037380266186 changelog: post-release
+ 5c1c9d43be61571608e9b14615045b67b830daf5 udp, udp6, icmp: handle TTL value
+ 73ed49ab71998d4288e71e954ef6214b70f23d79 icmp, icmp6: Add icmp_forward_error and icmp6_forward_error
+ 7a4840a57ec7dbc37cca1ab96f058a9610b26950 udp, udp6, icmp, icmp6: Enable forwarding errors on Linux
+ e9b2bc19ae652a2907f247e621b2e4773bdd2aab TCPIPHDR_DELTA: Fix potential negative value
+ 39f9a363eec082f04513413046321abd04163148 .gitlab-ci: add a Coverity stage
+ 1b0093b973cfa0dc041522e5d4e6f576b2df642e sosendoob: better document what urgc is used for
+ 5b9ad89ebbb8afa50162c9156fabd5fc56291088 Add G_GNUC_PRINTF to local function slirp_vsnprintf
+ 8a808aa493980e212b4d5f5465330905c8294e59 meson: remove meson-dist script
+ 0b669b5fbe4d3c25a682a67f1059d8633c963b3d meson: support compiling as subproject
+ 9f82a47b81f2864422b82c1e40e51a2ed9c6ac32 Add DNS resolving for iOS
+ c0eac03e8ce1b9a743231f2fe21e7cb579fc9339 Remove the QEMU-special make build-system
+ 1bfd4d9368f9fa2e4f0731e1266bec05bbc83a80 socket: consume empty packets
+ 92413be68914f8cae2f5bad4bf3ab8491dcbc5d7 Release v4.4.0
+ 07e8cfac69766081871ab620d9f16a630543d302 changelog: post-release
+ 4c4e035813313d02b63fdeb920d56fb2fdc0a5b1 Remove some needless (void)casts
+ eee9db9d115d91aa82f33685c4e76d656db92976 fork_exec_child_setup: improve signal handling
+ 216f434a018b3af182a4f31bbe5a00daee170343 Fix unused variables

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-04-29 23:29:35 -07:00
Gerd Hoffmann 819b2c2984 hw/display: add virtio-ramfb device
Like virtio-vga, but using ramfb instead of legacy vga.
Useful for booting from OVMF into Windows ARM which expects a linear FB.
2021-04-29 23:29:35 -07:00
osy 8ed0f7cb4d meson: option to build as shared library
On iOS, we cannot fork() new processes, so the best way to load QEMU into an
app is through a shared library. We add a new configure option
`--enable-shared-lib` that will build the bulk of QEMU into a shared lib.
The usual executables will then link to the library.
2021-04-29 23:29:35 -07:00
Joelle van Dyne d1bf1e28b6 slirp: feature detection for smbd
Replace Windows specific macro with a more generic feature detection
macro. Allows slirp smb feature to be disabled manually as well.
2021-04-29 23:29:35 -07:00
Joelle van DyneandWarner Losh 47cd50d3d2 block: detect DKIOCGETBLOCKCOUNT/SIZE before use
iOS hosts do not have these defined so we fallback to the
default behaviour.

Co-authored-by: Warner Losh <[email protected]>
2021-04-29 23:29:35 -07:00
Joelle van Dyne 324cef19f8 block: check for sys/disk.h
Some BSD platforms do not have this header.
2021-04-29 23:29:35 -07:00
Joelle van Dyne e252078b6e block: feature detection for host block support
On Darwin (iOS), there are no system level APIs for directly accessing
host block devices. We detect this at configure time.
2021-04-29 23:29:35 -07:00
Kate Temkin 69c9fe3f2e TCTI: modularize things more for fast clang 2021-04-29 04:23:23 -06:00
Kate Temkin 6764fe306f TCTI: more modular hacks 2021-04-28 05:37:42 -06:00
Kate Temkin 744075b9ee TCTI: dramatically speed up build & reduce footprint 2021-04-28 03:29:08 +00:00
Kate Temkin c77bed1d5c split gadgets into multiple files 2021-04-27 13:47:14 -06:00
Kate Temkin 1e4d72b004 TCTI: add TCTI TCG backend for acceleration on non-JIT AArch64 2021-04-27 13:21:48 -06:00
Kate Temkin 6c39f9e99b get building for an iOS target, as well 2021-04-27 13:21:47 -06:00
Joelle van Dyne ad73633ab3 coroutine: add libucontext as external library
iOS does not support ucontext natively for aarch64 and the sigaltstack is
also unsupported (even worse, it fails silently, see:
https://openradar.appspot.com/13002712 )

As a workaround we include a library implementation of ucontext and add it
as a build option.
2021-04-27 13:21:20 -06:00
osy a6b59f6dee tcg: custom APRR implementation 2021-04-27 13:21:20 -06:00
Roman Bolshakov 5db66c67b9 util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2
There's a change in mprotect() behaviour [1] in the latest macOS on M1
and it's not yet clear if it's going to be fixed by Apple. For now we
can avoid unsupported mprotect() calls. QEMU and qtests work fine
without it.

1. https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f

Buglink: https://bugs.launchpad.net/qemu/+bug/1914849
Apple-Feedback: FB8994773
Signed-off-by: Roman Bolshakov <[email protected]>
Message-Id: <[email protected]>
2021-04-27 13:21:20 -06:00
Marc-André Lureau c78951da1b build-sys: make libslirp a meson subproject
Remove the manual build.

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-04-27 13:21:20 -06:00
Marc-André Lureau 138287176b slirp: update to git master
git cherry-diff:

Commits on bacb71f1c3ed5f40e393afd8be81bedfba13a401 branch that is not on 8f43a99191afb47ca3f3c6972f6306209f367ece branch
+ 1021b0dc38d39f1dc95a296fe3e05a24a087cdc6 disable_dns option
+ 0f94ceec752592e4ac632a24e3c64a97dd09bf4c limit vnameserver_addr to port 53
+ b57bafa852ef16b133907a13678ec69e9531f177 libslirp.h: fix SlirpConfig v3 documentation
+ 1abf18b2b5edb462797629ed47ad4515a195686e Update CHANGELOG
+ ff4ecf9b6c6542b24b4ac6ea178be9d44e159f79 Release v4.3.0
+ 21f1d933050a40d62612c6274c32de60b811d9ea changelog: post-release
+ 376187c4b14c795763d472214812826eebe7e9c2 Release v4.3.1
+ 73336e08902a7e826f7d960453df037380266186 changelog: post-release
+ 5c1c9d43be61571608e9b14615045b67b830daf5 udp, udp6, icmp: handle TTL value
+ 73ed49ab71998d4288e71e954ef6214b70f23d79 icmp, icmp6: Add icmp_forward_error and icmp6_forward_error
+ 7a4840a57ec7dbc37cca1ab96f058a9610b26950 udp, udp6, icmp, icmp6: Enable forwarding errors on Linux
+ e9b2bc19ae652a2907f247e621b2e4773bdd2aab TCPIPHDR_DELTA: Fix potential negative value
+ 39f9a363eec082f04513413046321abd04163148 .gitlab-ci: add a Coverity stage
+ 1b0093b973cfa0dc041522e5d4e6f576b2df642e sosendoob: better document what urgc is used for
+ 5b9ad89ebbb8afa50162c9156fabd5fc56291088 Add G_GNUC_PRINTF to local function slirp_vsnprintf
+ 8a808aa493980e212b4d5f5465330905c8294e59 meson: remove meson-dist script
+ 0b669b5fbe4d3c25a682a67f1059d8633c963b3d meson: support compiling as subproject
+ 9f82a47b81f2864422b82c1e40e51a2ed9c6ac32 Add DNS resolving for iOS
+ c0eac03e8ce1b9a743231f2fe21e7cb579fc9339 Remove the QEMU-special make build-system
+ 1bfd4d9368f9fa2e4f0731e1266bec05bbc83a80 socket: consume empty packets
+ 92413be68914f8cae2f5bad4bf3ab8491dcbc5d7 Release v4.4.0
+ 07e8cfac69766081871ab620d9f16a630543d302 changelog: post-release
+ 4c4e035813313d02b63fdeb920d56fb2fdc0a5b1 Remove some needless (void)casts
+ eee9db9d115d91aa82f33685c4e76d656db92976 fork_exec_child_setup: improve signal handling
+ 216f434a018b3af182a4f31bbe5a00daee170343 Fix unused variables

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-04-27 13:21:20 -06:00
Gerd Hoffmann 17ebce776d hw/display: add virtio-ramfb device
Like virtio-vga, but using ramfb instead of legacy vga.
Useful for booting from OVMF into Windows ARM which expects a linear FB.
2021-04-27 13:21:20 -06:00
osy e034ab0b4d meson: option to build as shared library
On iOS, we cannot fork() new processes, so the best way to load QEMU into an
app is through a shared library. We add a new configure option
`--enable-shared-lib` that will build the bulk of QEMU into a shared lib.
The usual executables will then link to the library.
2021-04-27 13:21:20 -06:00
Joelle van Dyne d4e9108ef1 slirp: feature detection for smbd
Replace Windows specific macro with a more generic feature detection
macro. Allows slirp smb feature to be disabled manually as well.
2021-04-27 13:21:18 -06:00
Joelle van DyneandWarner Losh 36c2febd7f block: detect DKIOCGETBLOCKCOUNT/SIZE before use
iOS hosts do not have these defined so we fallback to the
default behaviour.

Co-authored-by: Warner Losh <[email protected]>
2021-04-27 13:20:46 -06:00
Joelle van Dyne 1913d4d2a7 block: check for sys/disk.h
Some BSD platforms do not have this header.
2021-04-27 13:20:46 -06:00
Joelle van Dyne 4f59dc2db0 block: feature detection for host block support
On Darwin (iOS), there are no system level APIs for directly accessing
host block devices. We detect this at configure time.
2021-04-27 13:20:46 -06:00
Kate Temkin 4de86e6de1 TCTI: add TCTI TCG backend for acceleration on non-JIT AArch64 2021-04-07 10:34:23 -06:00
Kate Temkin e16a18d2d9 get building for an iOS target, as well 2021-03-27 15:46:31 -06:00
Joelle van Dyne 4373fc4514 coroutine: add libucontext as external library
iOS does not support ucontext natively for aarch64 and the sigaltstack is
also unsupported (even worse, it fails silently, see:
https://openradar.appspot.com/13002712 )

As a workaround we include a library implementation of ucontext and add it
as a build option.
2021-03-08 17:28:49 -08:00
osy 37aa4a1894 tcg: custom APRR implementation 2021-03-08 17:28:49 -08:00
Roman Bolshakov cf8a85ad18 util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2
There's a change in mprotect() behaviour [1] in the latest macOS on M1
and it's not yet clear if it's going to be fixed by Apple. For now we
can avoid unsupported mprotect() calls. QEMU and qtests work fine
without it.

1. https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f

Buglink: https://bugs.launchpad.net/qemu/+bug/1914849
Apple-Feedback: FB8994773
Signed-off-by: Roman Bolshakov <[email protected]>
Message-Id: <[email protected]>
2021-03-08 17:28:49 -08:00
Marc-André Lureau da1d34255c build-sys: make libslirp a meson subproject
Remove the manual build.

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-03-08 17:28:49 -08:00
Marc-André Lureau ff51693eef slirp: update to git master
git cherry-diff:

Commits on bacb71f1c3ed5f40e393afd8be81bedfba13a401 branch that is not on 8f43a99191afb47ca3f3c6972f6306209f367ece branch
+ 1021b0dc38d39f1dc95a296fe3e05a24a087cdc6 disable_dns option
+ 0f94ceec752592e4ac632a24e3c64a97dd09bf4c limit vnameserver_addr to port 53
+ b57bafa852ef16b133907a13678ec69e9531f177 libslirp.h: fix SlirpConfig v3 documentation
+ 1abf18b2b5edb462797629ed47ad4515a195686e Update CHANGELOG
+ ff4ecf9b6c6542b24b4ac6ea178be9d44e159f79 Release v4.3.0
+ 21f1d933050a40d62612c6274c32de60b811d9ea changelog: post-release
+ 376187c4b14c795763d472214812826eebe7e9c2 Release v4.3.1
+ 73336e08902a7e826f7d960453df037380266186 changelog: post-release
+ 5c1c9d43be61571608e9b14615045b67b830daf5 udp, udp6, icmp: handle TTL value
+ 73ed49ab71998d4288e71e954ef6214b70f23d79 icmp, icmp6: Add icmp_forward_error and icmp6_forward_error
+ 7a4840a57ec7dbc37cca1ab96f058a9610b26950 udp, udp6, icmp, icmp6: Enable forwarding errors on Linux
+ e9b2bc19ae652a2907f247e621b2e4773bdd2aab TCPIPHDR_DELTA: Fix potential negative value
+ 39f9a363eec082f04513413046321abd04163148 .gitlab-ci: add a Coverity stage
+ 1b0093b973cfa0dc041522e5d4e6f576b2df642e sosendoob: better document what urgc is used for
+ 5b9ad89ebbb8afa50162c9156fabd5fc56291088 Add G_GNUC_PRINTF to local function slirp_vsnprintf
+ 8a808aa493980e212b4d5f5465330905c8294e59 meson: remove meson-dist script
+ 0b669b5fbe4d3c25a682a67f1059d8633c963b3d meson: support compiling as subproject
+ 9f82a47b81f2864422b82c1e40e51a2ed9c6ac32 Add DNS resolving for iOS
+ c0eac03e8ce1b9a743231f2fe21e7cb579fc9339 Remove the QEMU-special make build-system
+ 1bfd4d9368f9fa2e4f0731e1266bec05bbc83a80 socket: consume empty packets
+ 92413be68914f8cae2f5bad4bf3ab8491dcbc5d7 Release v4.4.0
+ 07e8cfac69766081871ab620d9f16a630543d302 changelog: post-release
+ 4c4e035813313d02b63fdeb920d56fb2fdc0a5b1 Remove some needless (void)casts
+ eee9db9d115d91aa82f33685c4e76d656db92976 fork_exec_child_setup: improve signal handling
+ 216f434a018b3af182a4f31bbe5a00daee170343 Fix unused variables

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-03-08 17:28:49 -08:00
Gerd Hoffmann 4ef61a5fd7 hw/display: add virtio-ramfb device
Like virtio-vga, but using ramfb instead of legacy vga.
Useful for booting from OVMF into Windows ARM which expects a linear FB.
2021-03-08 17:28:49 -08:00
osy bcdcc525e4 meson: option to build as shared library
On iOS, we cannot fork() new processes, so the best way to load QEMU into an
app is through a shared library. We add a new configure option
`--enable-shared-lib` that will build the bulk of QEMU into a shared lib.
The usual executables will then link to the library.
2021-03-08 17:28:49 -08:00
Joelle van Dyne 69819144f1 slirp: feature detection for smbd
Replace Windows specific macro with a more generic feature detection
macro. Allows slirp smb feature to be disabled manually as well.
2021-03-08 16:24:07 -08:00
Joelle van DyneandWarner Losh f314014422 block: detect DKIOCGETBLOCKCOUNT/SIZE before use
iOS hosts do not have these defined so we fallback to the
default behaviour.

Co-authored-by: Warner Losh <[email protected]>
2021-03-07 18:42:43 -08:00
Joelle van Dyne e0a033d9d4 block: check for sys/disk.h
Some BSD platforms do not have this header.
2021-03-07 18:42:20 -08:00
Joelle van Dyne 0272e162b7 block: feature detection for host block support
On Darwin (iOS), there are no system level APIs for directly accessing
host block devices. We detect this at configure time.
2021-03-07 16:52:13 -08:00
104 changed files with 10421 additions and 1183 deletions

No files matched your search

+3
View File
@@ -55,6 +55,9 @@
[submodule "roms/vbootrom"]
path = roms/vbootrom
url = https://gitlab.com/qemu-project/vbootrom.git
[submodule "libucontext"]
path = subprojects/libucontext
url = https://github.com/utmapp/libucontext.git
[submodule "tests/lcitool/libvirt-ci"]
path = tests/lcitool/libvirt-ci
url = https://gitlab.com/libvirt/libvirt-ci.git
+320 -35
View File
@@ -57,14 +57,24 @@
#include "sysemu/hvf_int.h"
#include "sysemu/runstate.h"
#include "qemu/guest-random.h"
#include "hw/boards.h"
#include "exec/memory-remap.h"
#include "exec/ram_addr.h"
HVFState *hvf_state;
#ifdef __aarch64__
#define HV_VM_DEFAULT NULL
/* Memory slots */
#define HVF_MAX_SLOTS 512
#ifdef DEBUG_HVF
#define DPRINTF(fmt, ...) \
do { fprintf(stdout, fmt, ## __VA_ARGS__); } while (0)
#else
#define DPRINTF(fmt, ...) \
do { } while (0)
#endif
/* Memory slots */
pthread_rwlock_t mem_lock = PTHREAD_RWLOCK_INITIALIZER;
hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t size)
{
@@ -85,22 +95,265 @@ struct mac_slot {
uint64_t size;
uint64_t gpa_start;
uint64_t gva;
void *hva;
};
struct mac_slot mac_slots[32];
struct mac_slot mac_slots[HVF_MAX_SLOTS];
static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)
#define ALIGN(x, y) (((x) + (y) - 1) & ~((y) - 1))
void *hvf_gpa2hva(uint64_t gpa, bool *found)
{
struct mac_slot *mslot;
*found = false;
for (uint32_t i = 0; i < HVF_MAX_SLOTS; i++) {
mslot = &mac_slots[i];
if (!mslot->present) {
continue;
}
if (gpa >= mslot->gpa_start &&
gpa < mslot->gpa_start + mslot->size) {
*found = true;
return (void *)((char *)(mslot->hva) + (gpa - mslot->gpa_start));
}
}
return 0;
}
#define min(a, b) ((a) < (b) ? (a) : (b))
int hvf_hva2gpa(void *hva, uint64_t length, int array_size,
uint64_t *gpa, uint64_t *size)
{
struct mac_slot *mslot;
int count = 0;
for (uint32_t i = 0; i < HVF_MAX_SLOTS; i++) {
mslot = &mac_slots[i];
if (!mslot->present) {
continue;
}
uintptr_t hva_start_num = (uintptr_t)mslot->hva;
uintptr_t hva_num = (uintptr_t)hva;
/* Start of this hva region is in this slot. */
if (hva_num >= hva_start_num &&
hva_num < hva_start_num + mslot->size) {
if (count < array_size) {
gpa[count] = mslot->gpa_start + (hva_num - hva_start_num);
size[count] = min(length,
mslot->size - (hva_num - hva_start_num));
}
count++;
/**
* End of this hva region is in this slot.
* Its start is outside of this slot.
*/
} else if (hva_num + length <= hva_start_num + mslot->size &&
hva_num + length > hva_start_num) {
if (count < array_size) {
gpa[count] = mslot->gpa_start;
size[count] = hva_num + length - hva_start_num;
}
count++;
/* This slot belongs to this hva region completely. */
} else if (hva_num + length > hva_start_num + mslot->size &&
hva_num < hva_start_num) {
if (count < array_size) {
gpa[count] = mslot->gpa_start;
size[count] = mslot->size;
}
count++;
}
}
return count;
}
static hvf_slot *hvf_next_free_slot(void)
{
hvf_slot *mem = 0;
int x;
for (x = 0; x < hvf_state->num_slots; ++x) {
mem = &hvf_state->slots[x];
if (!mem->size) {
return mem;
}
}
return mem;
}
static int __hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags);
static int __hvf_set_memory_with_flags_locked(hvf_slot *slot,
hv_memory_flags_t flags);
int hvf_map_safe(void *hva, uint64_t gpa, uint64_t size, uint64_t flags)
{
pthread_rwlock_wrlock(&mem_lock);
DPRINTF("%s: hva: [%p 0x%llx] gpa: [0x%llx 0x%llx]\n", __func__,
hva, (unsigned long long)(uintptr_t)(((char *)hva) + size),
(unsigned long long)gpa,
(unsigned long long)gpa + size);
hvf_slot *mem;
mem = hvf_find_overlap_slot(gpa, size);
if (mem &&
mem->mem == hva &&
mem->start == gpa &&
mem->size == size) {
pthread_rwlock_unlock(&mem_lock);
return HV_SUCCESS;
} else if (mem &&
mem->start == gpa &&
mem->size == size) {
/* unmap existing mapping, but only if it coincides */
mem->size = 0;
__hvf_set_memory_with_flags_locked(mem, 0);
} else if (mem) {
/**
* TODO: Manage and support partially-overlapping user-backed RAM
* mappings. for now, consider it fatal.
*/
pthread_rwlock_unlock(&mem_lock);
error_report("FATAL: tried to map [0x%llx 0x%llx) to %p "
"while it was mapped to [0x%llx 0x%llx), %p",
(unsigned long long)gpa,
(unsigned long long)gpa + size,
hva,
(unsigned long long)mem->start,
(unsigned long long)mem->start + mem->size,
mem->mem);
abort();
}
mem = hvf_next_free_slot();
if (mem->size) {
error_report("no free slots");
abort();
}
mem->mem = (uint8_t *)hva;
mem->start = gpa;
mem->size = size;
int res = __hvf_set_memory_with_flags_locked(mem, (hv_memory_flags_t)flags);
pthread_rwlock_unlock(&mem_lock);
return res;
}
int hvf_unmap_safe(uint64_t gpa, uint64_t size)
{
DPRINTF("%s: gpa: [0x%llx 0x%llx]\n", __func__,
(unsigned long long)gpa,
(unsigned long long)gpa + size);
pthread_rwlock_wrlock(&mem_lock);
hvf_slot *mem;
int res = 0;
mem = hvf_find_overlap_slot(gpa, size);
if (mem &&
(mem->start != gpa ||
mem->size != size)) {
pthread_rwlock_unlock(&mem_lock);
error_report("tried to unmap [0x%llx 0x%llx) but partially overlapping "
"[0x%llx 0x%llx), %p was encountered",
gpa, gpa + size,
mem->start, mem->start + mem->size, mem->mem);
abort();
} else if (mem) {
mem->size = 0;
res = __hvf_set_memory_with_flags_locked(mem, 0);
} else {
/* fall through, allow res to be 0 still if slot was not found. */
}
pthread_rwlock_unlock(&mem_lock);
return res;
}
int hvf_protect_safe(uint64_t gpa, uint64_t size, uint64_t flags)
{
pthread_rwlock_wrlock(&mem_lock);
int res = hv_vm_protect(gpa, size, flags);
pthread_rwlock_unlock(&mem_lock);
return res;
}
int hvf_remap_safe(void *hva, uint64_t gpa, uint64_t size, uint64_t flags)
{
pthread_rwlock_wrlock(&mem_lock);
int res = hv_vm_unmap(gpa, size);
assert_hvf_ok(res);
res = hv_vm_map(hva, gpa, size, flags);
assert_hvf_ok(res);
pthread_rwlock_unlock(&mem_lock);
return res;
}
/**
* API for adding and removing mappings of guest RAM and host addrs.
* Implementation depends on the hypervisor.
*/
static hv_memory_flags_t user_backed_flags_to_hvf_flags(int flags)
{
hv_memory_flags_t hvf_flags = 0;
if (flags & USER_BACKED_RAM_FLAGS_READ) {
hvf_flags |= HV_MEMORY_READ;
}
if (flags & USER_BACKED_RAM_FLAGS_WRITE) {
hvf_flags |= HV_MEMORY_WRITE;
}
if (flags & USER_BACKED_RAM_FLAGS_EXEC) {
hvf_flags |= HV_MEMORY_EXEC;
}
return hvf_flags;
}
static void hvf_user_backed_ram_map(uint64_t gpa,
void *hva,
uint64_t size,
int flags)
{
hvf_map_safe(hva, gpa, size, user_backed_flags_to_hvf_flags(flags));
}
static void hvf_user_backed_ram_unmap(uint64_t gpa, uint64_t size)
{
hvf_unmap_safe(gpa, size);
}
static int __hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)
{
pthread_rwlock_wrlock(&mem_lock);
int res = __hvf_set_memory_with_flags_locked(slot, flags);
pthread_rwlock_unlock(&mem_lock);
return res;
}
static int __hvf_set_memory_with_flags_locked(hvf_slot *slot,
hv_memory_flags_t flags)
{
struct mac_slot *macslot;
hv_return_t ret;
macslot = &mac_slots[slot->slot_id];
if (macslot->present) {
if (macslot->size != slot->size) {
macslot->present = 0;
ret = hv_vm_unmap(macslot->gpa_start, macslot->size);
assert_hvf_ok(ret);
DPRINTF("%s: hv_vm_unmap for gpa [0x%llx 0x%llx]\n", __func__,
(unsigned long long)macslot->gpa_start,
(unsigned long long)(macslot->gpa_start + macslot->size));
int unmapres = hv_vm_unmap(macslot->gpa_start, macslot->size);
assert_hvf_ok(unmapres);
}
}
@@ -111,8 +364,13 @@ static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)
macslot->present = 1;
macslot->gpa_start = slot->start;
macslot->size = slot->size;
ret = hv_vm_map(slot->mem, slot->start, slot->size, flags);
assert_hvf_ok(ret);
macslot->hva = slot->mem;
DPRINTF("%s: hv_vm_map for hva 0x%llx gpa [0x%llx 0x%llx]\n", __func__,
(unsigned long long)(slot->mem),
(unsigned long long)macslot->gpa_start,
(unsigned long long)(macslot->gpa_start + macslot->size));
int mapres = (hv_vm_map(slot->mem, slot->start, slot->size, flags));
assert_hvf_ok(mapres);
return 0;
}
@@ -129,12 +387,15 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
return;
} else if (!memory_region_is_romd(area)) {
/*
* If the memory device is not in romd_mode, then we actually want
* to remove the hvf memory slot so all accesses will trap.
*/
add = false;
* If the memory device is not in romd_mode, then we actually want
* to remove the hvf memory slot so all accesses will trap.
*/
add = false;
}
}
if (memory_region_is_user_backed(area)) {
return;
}
if (!QEMU_IS_ALIGNED(int128_get64(section->size), page_size) ||
!QEMU_IS_ALIGNED(section->offset_within_address_space, page_size)) {
@@ -158,7 +419,7 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
/* Region needs to be reset. set the size to 0 and remap it. */
if (mem) {
mem->size = 0;
if (do_hvf_set_memory(mem, 0)) {
if (__hvf_set_memory(mem, 0)) {
error_report("Failed to reset overlapping slot");
abort();
}
@@ -176,16 +437,10 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
}
/* Now make a new slot. */
int x;
for (x = 0; x < hvf_state->num_slots; ++x) {
mem = &hvf_state->slots[x];
if (!mem->size) {
break;
}
}
mem = hvf_next_free_slot();
if (x == hvf_state->num_slots) {
if (!mem) {
error_report("No free slots");
abort();
}
@@ -193,10 +448,9 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
mem->size = int128_get64(section->size);
mem->mem = memory_region_get_ram_ptr(area) + section->offset_within_region;
mem->start = section->offset_within_address_space;
mem->region = area;
if (do_hvf_set_memory(mem, flags)) {
error_report("Error registering new memory slot");
if (__hvf_set_memory(mem, flags)) {
error_report("error regsitering new memory slot");
abort();
}
}
@@ -319,25 +573,47 @@ bool hvf_allowed;
static int hvf_accel_init(MachineState *ms)
{
int x;
hv_return_t ret;
HVFState *s;
HVFState *s = HVF_STATE(ms->accelerator);
ret = hv_vm_create(HV_VM_DEFAULT);
ret = hvf_arch_vm_create(s);
assert_hvf_ok(ret);
s = g_new0(HVFState, 1);
hvf_state = s;
memory_listener_register(&hvf_memory_listener, &address_space_memory);
qemu_set_user_backed_mapping_funcs(
hvf_user_backed_ram_map,
hvf_user_backed_ram_unmap);
return hvf_arch_init();
}
#if defined(CONFIG_HVF_PRIVATE) && defined(__aarch64__)
static bool hvf_get_tso(Object *obj, Error **errp)
{
HVFState *s = HVF_STATE(obj);
return s->tso_mode;
}
static void hvf_set_tso(Object *obj, bool value, Error **errp)
{
HVFState *s = HVF_STATE(obj);
s->tso_mode = value;
}
#endif
static void hvf_accel_instance_init(Object *obj)
{
int x;
HVFState *s = HVF_STATE(obj);
s->num_slots = ARRAY_SIZE(s->slots);
for (x = 0; x < s->num_slots; ++x) {
s->slots[x].size = 0;
s->slots[x].slot_id = x;
}
hvf_state = s;
memory_listener_register(&hvf_memory_listener, &address_space_memory);
return hvf_arch_init();
}
static void hvf_accel_class_init(ObjectClass *oc, void *data)
@@ -346,12 +622,21 @@ static void hvf_accel_class_init(ObjectClass *oc, void *data)
ac->name = "HVF";
ac->init_machine = hvf_accel_init;
ac->allowed = &hvf_allowed;
#if defined(CONFIG_HVF_PRIVATE) && defined(__aarch64__)
object_class_property_add_bool(oc, "tso",
hvf_get_tso, hvf_set_tso);
object_class_property_set_description(oc, "tso",
"Set on/off to enable/disable total store ordering mode");
#endif
}
static const TypeInfo hvf_accel_type = {
.name = TYPE_HVF_ACCEL,
.parent = TYPE_ACCEL,
.instance_init = hvf_accel_instance_init,
.class_init = hvf_accel_class_init,
.instance_size = sizeof(HVFState),
};
static void hvf_type_init(void)
+1
View File
@@ -26,6 +26,7 @@
#include "disas/disas.h"
#include "exec/exec-all.h"
#include "tcg/tcg.h"
#include "tcg/tcg-apple-jit.h"
#include "qemu/atomic.h"
#include "qemu/rcu.h"
#include "exec/log.h"
+1
View File
@@ -27,6 +27,7 @@
#include "exec/translate-all.h"
#include "sysemu/tcg.h"
#include "tcg/tcg.h"
#include "tcg/tcg-apple-jit.h"
#include "tb-hash.h"
#include "tb-context.h"
#include "internal.h"
+5
View File
@@ -59,6 +59,11 @@ void tcg_cpu_init_cflags(CPUState *cpu, bool parallel)
cflags |= parallel ? CF_PARALLEL : 0;
cflags |= icount_enabled() ? CF_USE_ICOUNT : 0;
#if defined(CONFIG_TCG_THREADED_INTERPRETER)
// GOTO_PTR is too complex to emit a simple gadget for.
// We'll let C handle it, since the overhead is similar.
cflags |= CF_NO_GOTO_PTR;
#endif
cpu->tcg_cflags |= cflags;
}
+1
View File
@@ -24,6 +24,7 @@
#include "disas/disas.h"
#include "exec/exec-all.h"
#include "tcg/tcg.h"
#include "tcg/tcg-apple-jit.h"
#if defined(CONFIG_USER_ONLY)
#include "qemu.h"
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+24 -6
View File
@@ -1403,12 +1403,21 @@ void audio_run(AudioState *s, const char *msg)
#endif
}
void audio_generic_initialize_buffer_in(HWVoiceIn *hw)
{
if (hw->buf_emul) {
g_free(hw->buf_emul);
}
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
}
void audio_generic_run_buffer_in(HWVoiceIn *hw)
{
if (unlikely(!hw->buf_emul)) {
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
audio_generic_initialize_buffer_in(hw);
}
while (hw->pending_emul < hw->size_emul) {
@@ -1442,6 +1451,17 @@ void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size)
hw->pending_emul -= size;
}
void audio_generic_initialize_buffer_out(HWVoiceOut *hw)
{
if (hw->buf_emul) {
g_free(hw->buf_emul);
}
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
}
size_t audio_generic_buffer_get_free(HWVoiceOut *hw)
{
if (hw->buf_emul) {
@@ -1473,9 +1493,7 @@ void audio_generic_run_buffer_out(HWVoiceOut *hw)
void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size)
{
if (unlikely(!hw->buf_emul)) {
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
audio_generic_initialize_buffer_out(hw);
}
*size = MIN(hw->size_emul - hw->pending_emul,
+2
View File
@@ -188,9 +188,11 @@ struct audio_pcm_ops {
void (*volume_in)(HWVoiceIn *hw, Volume *vol);
};
void audio_generic_initialize_buffer_in(HWVoiceIn *hw);
void audio_generic_run_buffer_in(HWVoiceIn *hw);
void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size);
void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size);
void audio_generic_initialize_buffer_out(HWVoiceOut *hw);
void audio_generic_run_buffer_out(HWVoiceOut *hw);
size_t audio_generic_buffer_get_free(HWVoiceOut *hw);
void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size);
+28 -22
View File
@@ -360,7 +360,10 @@ static OSStatus audioDeviceIOProc(
static OSStatus init_out_device(coreaudioVoiceOut *core)
{
OSStatus status;
AudioDeviceID deviceID;
AudioValueRange frameRange;
UInt32 audioDevicePropertyBufferFrameSize;
AudioDeviceIOProcID ioprocid;
AudioStreamBasicDescription streamBasicDescription = {
.mBitsPerChannel = core->hw.info.bits,
@@ -373,20 +376,19 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
.mSampleRate = core->hw.info.freq
};
status = coreaudio_get_voice(&core->outputDeviceID);
status = coreaudio_get_voice(&deviceID);
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr (status,
"Could not get default output Device\n");
return status;
}
if (core->outputDeviceID == kAudioDeviceUnknown) {
if (deviceID == kAudioDeviceUnknown) {
dolog ("Could not initialize playback - Unknown Audiodevice\n");
return status;
}
/* get minimum and maximum buffer frame sizes */
status = coreaudio_get_framesizerange(core->outputDeviceID,
&frameRange);
status = coreaudio_get_framesizerange(deviceID, &frameRange);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
@@ -397,31 +399,31 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
}
if (frameRange.mMinimum > core->frameSizeSetting) {
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
} else if (frameRange.mMaximum < core->frameSizeSetting) {
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum);
} else {
core->audioDevicePropertyBufferFrameSize = core->frameSizeSetting;
audioDevicePropertyBufferFrameSize = core->frameSizeSetting;
}
/* set Buffer Frame Size */
status = coreaudio_set_framesize(core->outputDeviceID,
&core->audioDevicePropertyBufferFrameSize);
status = coreaudio_set_framesize(deviceID,
&audioDevicePropertyBufferFrameSize);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr (status,
"Could not set device buffer frame size %" PRIu32 "\n",
(uint32_t)core->audioDevicePropertyBufferFrameSize);
(uint32_t)audioDevicePropertyBufferFrameSize);
return status;
}
/* get Buffer Frame Size */
status = coreaudio_get_framesize(core->outputDeviceID,
&core->audioDevicePropertyBufferFrameSize);
status = coreaudio_get_framesize(deviceID,
&audioDevicePropertyBufferFrameSize);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
@@ -430,11 +432,9 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
"Could not get device buffer frame size\n");
return status;
}
core->hw.samples = core->bufferCount * core->audioDevicePropertyBufferFrameSize;
/* set Samplerate */
status = coreaudio_set_streamformat(core->outputDeviceID,
&streamBasicDescription);
status = coreaudio_set_streamformat(deviceID, &streamBasicDescription);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
@@ -442,7 +442,6 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
coreaudio_playback_logerr (status,
"Could not set samplerate %lf\n",
streamBasicDescription.mSampleRate);
core->outputDeviceID = kAudioDeviceUnknown;
return status;
}
@@ -456,20 +455,25 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
* Therefore, the specified callback must be designed to avoid a deadlock
* with the callers of AudioObjectGetPropertyData.
*/
core->ioprocid = NULL;
status = AudioDeviceCreateIOProcID(core->outputDeviceID,
ioprocid = NULL;
status = AudioDeviceCreateIOProcID(deviceID,
audioDeviceIOProc,
&core->hw,
&core->ioprocid);
&ioprocid);
if (status == kAudioHardwareBadDeviceError) {
return 0;
}
if (status != kAudioHardwareNoError || core->ioprocid == NULL) {
if (status != kAudioHardwareNoError || ioprocid == NULL) {
coreaudio_playback_logerr (status, "Could not set IOProc\n");
core->outputDeviceID = kAudioDeviceUnknown;
return status;
}
core->outputDeviceID = deviceID;
core->audioDevicePropertyBufferFrameSize = audioDevicePropertyBufferFrameSize;
core->hw.samples = core->bufferCount * core->audioDevicePropertyBufferFrameSize;
audio_generic_initialize_buffer_out(&core->hw);
core->ioprocid = ioprocid;
return 0;
}
@@ -553,7 +557,9 @@ static OSStatus handle_voice_change(
fini_out_device(core);
}
if (!init_out_device(core)) {
init_out_device(core);
if (core->outputDeviceID) {
update_device_playback_state(core);
}
+40 -2
View File
@@ -44,10 +44,10 @@
#if defined(__APPLE__) && (__MACH__)
#include <sys/ioctl.h>
#if defined(HAVE_HOST_BLOCK_DEVICE)
#include <paths.h>
#include <sys/param.h>
#include <sys/mount.h>
#if defined(HAVE_HOST_BLOCK_DEVICE)
#include <paths.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOBSD.h>
#include <IOKit/storage/IOMediaBSDClient.h>
@@ -131,6 +131,14 @@
#define RAW_LOCK_PERM_BASE 100
#define RAW_LOCK_SHARED_BASE 200
/*
* qemu_lock_fd_test always returns 0 when fd is not open for writing and
* exclusive is true on macOS 11.3.1.
*/
#ifdef __APPLE__
#define RAW_LOCK_WRITES
#endif
typedef struct BDRVRawState {
int fd;
bool use_lock;
@@ -273,6 +281,13 @@ static int raw_normalize_devicepath(const char **filename, Error **errp)
}
#endif
#if defined(CONFIG_IOS)
static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
{
return -ENOTSUP; /* not supported on iOS */
}
#else /* CONFIG_IOS */
/*
* Get logical block size via ioctl. On success store it in @sector_size_p.
*/
@@ -306,6 +321,8 @@ static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
return success ? 0 : -errno;
}
#endif
/**
* Get physical block size of @fd.
* On success, store it in @blk_size and return 0.
@@ -674,7 +691,11 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
false);
s->open_flags = open_flags;
#ifdef RAW_LOCK_WRITES
raw_parse_flags(bdrv_flags, &s->open_flags, s->use_lock);
#else
raw_parse_flags(bdrv_flags, &s->open_flags, false);
#endif
s->fd = -1;
fd = qemu_open(filename, s->open_flags, errp);
@@ -1039,6 +1060,11 @@ static int raw_reconfigure_getfd(BlockDriverState *bs, int flags,
bool has_writers = perm &
(BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED | BLK_PERM_RESIZE);
int fcntl_flags = O_APPEND | O_NONBLOCK;
#ifdef RAW_LOCK_WRITES
if (s->use_lock) {
has_writers = true;
}
#endif
#ifdef O_NOATIME
fcntl_flags |= O_NOATIME;
#endif
@@ -1431,12 +1457,24 @@ static bool preadv_present = true;
static ssize_t
qemu_preadv(int fd, const struct iovec *iov, int nr_iov, off_t offset)
{
#ifdef CONFIG_DARWIN /* preadv introduced in macOS 11 */
if (!__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
preadv_present = false;
return -ENOSYS;
} else
#endif
return preadv(fd, iov, nr_iov, offset);
}
static ssize_t
qemu_pwritev(int fd, const struct iovec *iov, int nr_iov, off_t offset)
{
#ifdef CONFIG_DARWIN /* pwritev introduced in macOS 11 */
if (!__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
preadv_present = false;
return -ENOSYS;
} else
#endif
return pwritev(fd, iov, nr_iov, offset);
}
Vendored
+36 -3
View File
@@ -293,6 +293,7 @@ meson=""
ninja=""
bindir="bin"
skip_meson=no
shared_lib="no"
vfio_user_server="disabled"
# The following Meson options are handled manually (still they
@@ -895,6 +896,12 @@ for opt do
;;
--disable-vfio-user-server) vfio_user_server="disabled"
;;
--enable-shared-lib)
shared_lib="yes"
plugins="no"
;;
--disable-shared-lib) shared_lib="no"
;;
# everything else has the same name in configure and meson
--*) meson_option_parse "$opt" "$optarg"
;;
@@ -906,6 +913,10 @@ if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
error_exit "Can't enable plugins on non-TCG builds"
fi
if test "$plugins" = "yes" -a "$shared_lib" = "yes"; then
error_exit "Can't enable plugins on shared library builds"
fi
case $git_submodules_action in
update|validate)
if test ! -e "$source_path/.git"; then
@@ -1030,7 +1041,7 @@ Advanced options (experts only):
--disable-stack-protector disable compiler-provided stack protection
--cpu=CPU Build for host CPU [$cpu]
--with-coroutine=BACKEND coroutine backend. Supported options:
ucontext, sigaltstack, windows
ucontext, libucontext, sigaltstack, windows
--enable-plugins
enable plugins via shared library loading
--disable-containers don't use containers for cross-building
@@ -1621,12 +1632,26 @@ else
error_exit "only the 'windows' coroutine backend is valid for Windows"
fi
;;
libucontext)
;;
*)
error_exit "unknown coroutine backend $coroutine"
;;
esac
fi
case $coroutine in
libucontext)
git_submodules="${git_submodules} subprojects/libucontext"
coroutine_impl=ucontext
libucontext="enabled"
;;
*)
coroutine_impl=$coroutine
libucontext="disabled"
;;
esac
##################################################
# SafeStack
@@ -2391,7 +2416,7 @@ if [ "$bsd" = "yes" ] ; then
echo "CONFIG_BSD=y" >> $config_host_mak
fi
echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
echo "CONFIG_COROUTINE_BACKEND=$coroutine_impl" >> $config_host_mak
if test "$have_asan_iface_fiber" = "yes" ; then
echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
@@ -2405,6 +2430,10 @@ if test "$plugins" = "yes" ; then
echo "CONFIG_PLUGIN=y" >> $config_host_mak
fi
if test "$shared_lib" = "yes" ; then
echo "CONFIG_SHARED_LIBRARY_BUILD=y" >> $config_host_mak
fi
if test -n "$gdb_bin"; then
gdb_version=$($gdb_bin --version | head -n 1)
if version_ge ${gdb_version##* } 9.1; then
@@ -2586,7 +2615,11 @@ if test "$skip_meson" = no; then
if has $sdl2_config; then
echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
fi
echo "strip = [$(meson_quote $strip)]" >> $cross
if test "$shared_lib" = "yes"; then
echo "strip = [$(meson_quote $strip), '-x']" >> $cross
else
echo "strip = [$(meson_quote $strip)]" >> $cross
fi
echo "widl = [$(meson_quote $widl)]" >> $cross
echo "windres = [$(meson_quote $windres)]" >> $cross
echo "windmc = [$(meson_quote $windmc)]" >> $cross
+2 -2
View File
@@ -323,7 +323,7 @@ virgl_cmd_set_scanout(VuGpu *g,
struct virtio_gpu_ctrl_command *cmd)
{
struct virtio_gpu_set_scanout ss;
struct virgl_renderer_resource_info info;
struct virgl_renderer_texture_info info;
int ret;
VUGPU_FILL_CMD(ss);
@@ -338,7 +338,7 @@ virgl_cmd_set_scanout(VuGpu *g,
memset(&info, 0, sizeof(info));
if (ss.resource_id && ss.r.width && ss.r.height) {
ret = virgl_renderer_resource_get_info(ss.resource_id, &info);
ret = virgl_renderer_borrow_texture_for_scanout(ss.resource_id, &info);
if (ret == -1) {
g_critical("%s: illegal resource specified %d\n",
__func__, ss.resource_id);
+2
View File
@@ -151,6 +151,8 @@ static void initialize_debug_host(CPUDebug *s)
#endif
#if defined(CONFIG_TCG_INTERPRETER)
s->info.print_insn = print_insn_tci;
#elif defined(CONFIG_TCG_THREADED_INTERPRETER)
s->info.print_insn = print_insn_tcti;
#elif defined(__i386__)
s->info.mach = bfd_mach_i386_i386;
s->info.cap_arch = CS_ARCH_X86;
+7 -1
View File
@@ -1729,7 +1729,7 @@ static void virt_set_high_memmap(VirtMachineState *vms,
for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) {
region_enabled = virt_get_high_memmap_enabled(vms, i);
region_base = ROUND_UP(base, extended_memmap[i].size);
region_base = ROUND_UP(base, 0x4000);
region_size = extended_memmap[i].size;
vms->memmap[i].base = region_base;
@@ -1779,7 +1779,11 @@ static void virt_set_memmap(VirtMachineState *vms, int pa_bits)
* irrespective of the underlying capabilities of the HW.
*/
if (!vms->highmem) {
#ifdef CONFIG_DARWIN
pa_bits = 36;
#else
pa_bits = 32;
#endif
}
/*
@@ -1804,9 +1808,11 @@ static void virt_set_memmap(VirtMachineState *vms, int pa_bits)
error_report("maxmem/slots too huge");
exit(EXIT_FAILURE);
}
/*
if (base < vms->memmap[VIRT_MEM].base + LEGACY_RAMLIMIT_BYTES) {
base = vms->memmap[VIRT_MEM].base + LEGACY_RAMLIMIT_BYTES;
}
*/
/* We know for sure that at least the memory fits in the PA space */
vms->highest_gpa = memtop - 1;
+3
View File
@@ -47,3 +47,6 @@ config PL041
config CS4231
bool
config SCREAMER
bool
+1
View File
@@ -12,3 +12,4 @@ softmmu_ss.add(when: 'CONFIG_PL041', if_true: files('pl041.c', 'lm4549.c'))
softmmu_ss.add(when: 'CONFIG_SB16', if_true: files('sb16.c'))
softmmu_ss.add(when: 'CONFIG_VT82C686', if_true: files('via-ac97.c'))
softmmu_ss.add(when: 'CONFIG_WM8750', if_true: files('wm8750.c'))
softmmu_ss.add(when: 'CONFIG_SCREAMER', if_true: files('screamer.c'))
+986
View File
@@ -0,0 +1,986 @@
/*
* File: Screamer.c
* Description: Implement the Screamer sound chip used in Apple Macintoshes.
* It works by filling a buffer, then playing the buffer.
*/
#include "qemu/osdep.h"
#include "audio/audio.h"
#include "hw/hw.h"
#include "hw/irq.h"
#include <inttypes.h>
#include "hw/ppc/mac_dbdma.h"
#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
#include "include/hw/audio/screamer.h"
#define DEBUG_SCREAMER 0
#define DPRINTF(fmt, ...) \
do { if (DEBUG_SCREAMER) { printf(fmt , ## __VA_ARGS__); } } while (0)
#define SOUND_CONTROL_REG 0
#define CODEC_CONTROL_REG 1
#define CODEC_STATUS_REG 2
#define CLIP_COUNT_REG 3
#define BYTE_SWAP_REG 4
#define FRAME_COUNT_REG 5
#define AWACS_BUSY 0x01000000
/* Used with AWACS register 1 */
#define RECALIBRATE 0x004
#define LOOPTHRU 0x040
#define SPEAKER_MUTE 0x080
#define HEADPHONE_MUTE 0x200
#define OUTPUT_ZERO 0x400
#define OUTPUT_ONE 0x800
#define PARALLEL_OUTPUT 0xc00
/* Function prototypes */
static uint32_t set_busy_bit(uint32_t value, int bit);
static uint32_t set_part_ready_bit(uint32_t value, int bit_value);
static uint32_t set_revision(uint32_t input_value);
static uint32_t set_manufacturer(uint32_t input_value);
static int get_sampling_rate(ScreamerState *s);
static uint32_t get_frame_count_reg(ScreamerState *s);
static void add_to_speaker_buffer(DBDMA_io *io);
static void dma_request(DBDMA_io *io);
/**************************** Getters *************************/
/* Returns the codec control register's encoded AWACS address */
static uint8_t get_codec_control_address(uint32_t value)
{
uint8_t return_value;
return_value = (value >> 12) & 0x00000fff;
return return_value;
}
static uint32_t get_sound_control_reg(ScreamerState *s)
{
DPRINTF("%s() called - returned 0x%x\n", __func__, s->sound_control);
return s->sound_control;
}
/* The AWACS registers are accessed thru this register */
static uint32_t get_codec_control_reg(ScreamerState *s)
{
int awacs_register = get_codec_control_address(s->codec_control);
uint32_t return_value = s->awacs[awacs_register];
return_value = set_busy_bit(return_value, 0); /* Tell CPU we are ready */
DPRINTF("%s() called - returned 0x%x\tAWACS register: %d\n", __func__,
return_value, awacs_register);
return return_value;
}
/*
* Determines if the readback bit is set.
* It is used by the Codec Control register.
*/
static bool readback_enabled(ScreamerState *s)
{
/* Note: bit zero is the readback enabled bit */
if (s->awacs[7] & 1) {
return true;
} else {
return false;
}
}
static uint32_t get_codec_status_reg(ScreamerState *s)
{
uint32_t return_value;
/* if in readback mode - return AWACS register value */
if (readback_enabled(s)) {
int awacs_register = (s->awacs[7] & 0xe) >> 1;
s->awacs[7] = s->awacs[7] & 0xfffffffe; /* turn off readback mode */
return_value = s->awacs[awacs_register] << 4;
DPRINTF("readback enable bit is set, returning AWACS register %d\t"
"value:0x%x\n", awacs_register, return_value);
return return_value;
}
/* Tell CPU we are ready */
return_value = set_part_ready_bit(s->codec_status, 1);
/* Set Revision to Screamer */
return_value = set_revision(return_value);
/* Set the Manufacturer to Crystal */
return_value = set_manufacturer(return_value);
DPRINTF("%s() called - returned 0x%x\n", __func__, return_value);
return return_value;
}
static uint32_t get_clip_count_reg(ScreamerState *s)
{
DPRINTF("%s() called - returned 0x%x\n", __func__, s->clip_count);
uint32_t return_value;
return_value = s->clip_count;
/* This is reset everytime it is read */
s->clip_count = 0;
return return_value;
}
static uint32_t get_byte_swap_reg(ScreamerState *s)
{
DPRINTF("%s() called - returned 0x%x\n", __func__, s->byte_swap);
/*
* If all you hear is noise, it could be this register reporting the
* wrong value.
*/
return s->byte_swap ? 0 : 1;
}
/*
* Returns the frame (sample) count
*/
static uint32_t get_frame_count_reg(ScreamerState *s)
{
DPRINTF("%s() called - returned 0x%x\n", __func__, s->frame_count);
return s->frame_count;
}
static uint8_t get_left_vol(uint32_t value)
{
return value & 0xf;
}
static uint8_t get_right_vol(uint32_t value)
{
return value & 0x3c0 >> 6;
}
/*
* Returns the sampling rate.
* If the audio is playing back too fast or too slow, this function may be the
* cause.
*/
static int get_sampling_rate(ScreamerState *s)
{
uint32_t screamer_rate = s->sound_control & 0x700;
int return_value;
/* All return values are in Hertz */
switch (screamer_rate) {
case 0x0:
return_value = 44100;
break;
case 0x100:
return_value = 29400;
break;
case 0x200:
return_value = 22050;
break;
case 0x300:
return_value = 17640;
break;
case 0x400:
return_value = 14700;
break;
case 0x500:
return_value = 11025;
break;
case 0x600:
return_value = 8820;
break;
case 0x700:
return_value = 7350;
break;
default:
DPRINTF("get_sampling_rate() unknown value: 0x%x\nDefaulting to"
" 44100 Hz.\n", screamer_rate);
return 44100;
}
DPRINTF("%s() called - returning %dHz\n", __func__, return_value);
return return_value;
}
/**************************** End of getters *************************/
/***************************** Speaker call back *************************/
/* resets the play and buffer position markers */
static void reset_markers(ScreamerState *s)
{
s->spk_play_position = 0;
s->spk_buffer_position = 0;
}
/* Sends the samples to the host for playing */
static void send_samples_to_host(ScreamerState *s, int max_samples)
{
int write_length, requested_length;
requested_length = MIN(max_samples, (s->spk_buffer_position -
s->spk_play_position));
write_length = AUD_write(s->speaker_voice,
&s->spk_buffer[s->spk_play_position],
requested_length);
DPRINTF("requested length: %d\twrite length: %d\t",
requested_length, write_length);
s->spk_play_position += write_length;
DPRINTF("AUD_write %d/%d\n", s->spk_play_position, s->spk_buffer_position);
s->frame_count += write_length;
}
/*
* Called by QEMU's audio system to tell the output backend to send samples
* from the buffer to the host sound system.
* opaque: a pointer to the ScreamerState instance.
* max_samples: the number of samples that can be sent to the hardware buffer.
*/
static void speaker_callback(void *opaque, int max_samples)
{
ScreamerState *s = (ScreamerState *) opaque;
/* if we have more samples to play */
if (s->spk_buffer_position > 0) {
if (s->spk_buffer_position > s->spk_play_position) {
DPRINTF("%s() called - max_samples: %d\n", __func__, max_samples);
send_samples_to_host(s, max_samples);
}
if (s->spk_play_position >= s->spk_buffer_position) {
DPRINTF("done playing buffer\n");
DPRINTF("pp: %d\tbp: %d\n", s->spk_play_position,
s->spk_buffer_position);
if (s->spk_play_position > s->spk_buffer_position) {
DPRINTF("Error detected! - pp > bp\n\a");
}
reset_markers(s);
/* play postponed samples */
if (s->dma_io.len > 0) {
DPRINTF("playing postponed samples\n");
add_to_speaker_buffer(&s->dma_io);
return;
}
}
}
}
/************************* End of speaker call back *************************/
/* Opens the speaker's voice */
static void open_speaker_voice(ScreamerState *s)
{
DPRINTF("%s() called\n", __func__);
/* if voice is already open return from function */
if (s->speaker_voice != NULL) {
DPRINTF("closing speaker voice\n");
AUD_close_out(&s->card, s->speaker_voice);
s->speaker_voice = NULL;
}
struct audsettings audio_settings;
audio_settings.freq = get_sampling_rate(s); /* in hertz */
audio_settings.nchannels = 2; /* stereo output */
audio_settings.fmt = AUDIO_FORMAT_S16; /* signed 16 bit */
audio_settings.endianness = get_byte_swap_reg(s); /* endianness */
s->speaker_voice = AUD_open_out(&s->card, s->speaker_voice, SOUND_CHIP_NAME
" speaker", s, speaker_callback,
&audio_settings);
if (!s->speaker_voice) {
AUD_log(SOUND_CHIP_NAME, "Out voice could not be opened\n");
} else {
AUD_set_active_out(s->speaker_voice, true);
}
}
/******************************* Setters *************************************/
/* Updates QEMU's audio backend settings */
static void set_QEMU_audio_settings(ScreamerState *s)
{
DPRINTF("%s() called\n", __func__);
open_speaker_voice(s);
}
/* Return value: 1 = muted 0 = not muted */
static int is_muted(ScreamerState *s)
{
int mute_state = s->awacs[1] & SPEAKER_MUTE ? 1 : 0;
if (s->awacs[1] & SPEAKER_MUTE) {
DPRINTF("speaker is muted\n");
} else {
DPRINTF("speaker is unmuted\n");
}
if (s->awacs[1] & HEADPHONE_MUTE) {
DPRINTF("headphone is muted\n");
} else {
DPRINTF("headphone is unmuted\n");
}
return mute_state;
}
/* Converts Screamer's volume system to QEMU's system */
static int screamer_to_qemu_volume(int x)
{
return -16 * x + 240;
}
/* Sets QEMU's volume. */
static void set_volume(ScreamerState *s)
{
int should_mute = is_muted(s);
/* Get Screamer volume values */
uint8_t left_vol = get_left_vol(s->awacs[4]);
uint8_t right_vol = get_right_vol(s->awacs[4]);
DPRINTF("set_volume() called - M:%d\tL:%d\tR:%d\n", should_mute, left_vol,
right_vol);
/* Convert Screamer to QEMU volume values */
left_vol = screamer_to_qemu_volume(left_vol);
right_vol = screamer_to_qemu_volume(right_vol);
DPRINTF("QEMU volume: L:%d\tR:%d\n", left_vol, right_vol);
AUD_set_volume_out(s->speaker_voice, should_mute, left_vol, right_vol);
}
/* Sets the sound control register */
static void set_sound_control_reg(ScreamerState *s, uint32_t value)
{
DPRINTF("set_sound_control_reg() called - value: 0x%x\n", value);
s->sound_control = value;
set_QEMU_audio_settings(s);
}
/* Used for input gain only - can be ignored for now. */
static void set_awacs_0_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 0 to 0x%x\n", s->awacs[0]);
s->awacs[0] = new_value;
}
static void set_awacs_1_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 1 to 0x%x\n", new_value);
s->awacs[1] = new_value;
/* If recalibration requested */
if (new_value & RECALIBRATE) {
DPRINTF("Recalibration requested - unimplemented\n");
new_value = new_value ^ RECALIBRATE; /* Turn off recalibrate bit */
}
/* If loop thru set - what does this mean? */
if (new_value & LOOPTHRU) {
DPRINTF("Loopthru enabled - doing nothing\n");
}
/* Set headphone jack mute state */
if (new_value & HEADPHONE_MUTE) {
DPRINTF("Headphone muted\n");
}
else {
DPRINTF("Headphone unmuted\n");
}
if (new_value & SPEAKER_MUTE) {
DPRINTF("Speaker muted\n");
}
else {
DPRINTF("Speaker unmuted\n");
}
if (new_value & OUTPUT_ZERO) {
DPRINTF("output zero set - not sure what this means\n");
}
if (new_value & OUTPUT_ONE) {
DPRINTF("output one set - not sure what this means\n");
}
if (new_value & PARALLEL_OUTPUT) {
DPRINTF("parallel port enabled - but no parallel port here\n");
}
set_volume(s);
}
/* This is used for headphone volume - not needed */
static void set_awacs_2_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 2 to 0x%x\n"
"Ignoring change in headphone volume.\n", s->awacs[2]);
s->awacs[2] = new_value;
}
/* Unknown register purpose */
static void set_awacs_3_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 3 to 0x%x\n"
"This register has an unknown purpose and does not do anything\n",
s->awacs[3]);
s->awacs[3] = new_value;
}
/* Mostly deals with speaker volume */
static void set_awacs_4_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("AWACS register 4 write: 0x%x\n", new_value);
s->awacs[4] = new_value;
set_volume(s);
}
/* This register is about loop thru stuff I don't understand */
static void set_awacs_5_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 5 to 0x%x\n"
"Loop thru update ignored.\n", s->awacs[5]);
s->awacs[5] = new_value;
}
/* Prints the states of the AWACS power register */
static void print_power_reg_values(uint32_t value)
{
if ((value & 0x3) == 0) {
printf("Screamer run state set\n");
}
if ((value & 0x3) == 1) {
printf("Screamer doze state set\n");
}
if ((value & 0x3) == 2) {
printf("Screamer idle state set\n");
}
}
/* Power Magement register */
static void set_awacs_6_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 6 to 0x%x\n"
"Power management update ignored.\n", s->awacs[6]);
if (DEBUG_SCREAMER) {
print_power_reg_values(new_value);
}
s->awacs[6] = new_value;
}
/* Read Back - repeating something that was sent to this chip? */
static void set_awacs_7_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("Settings AWACS register 7 to 0x%x\n", new_value);
s->awacs[7] = new_value;
}
/* Sets the AWACs registers - a.k.a. shadow registers */
static void set_awacs_register(ScreamerState *s, uint32_t value)
{
int the_register = get_codec_control_address(value);
switch (the_register) {
case 0:
set_awacs_0_reg(s, value);
break;
case 1:
set_awacs_1_reg(s, value);
break;
case 2:
set_awacs_2_reg(s, value);
break;
case 3:
set_awacs_3_reg(s, value);
break;
case 4:
set_awacs_4_reg(s, value);
break;
case 5:
set_awacs_5_reg(s, value);
break;
case 6:
set_awacs_6_reg(s, value);
break;
case 7:
set_awacs_7_reg(s, value);
break;
default:
DPRINTF("Unhandled awacs registers %d\n", the_register);
}
}
/* Used to set the AWACS registers */
static void set_codec_control_reg(ScreamerState *s, uint32_t value)
{
DPRINTF("set_codec_control_reg() called - value: 0x%x\n", value);
s->codec_control = value;
set_awacs_register(s, value);
}
static void set_codec_status_reg(ScreamerState *s, uint32_t value)
{
DPRINTF("set_codec_status_reg() called - value: 0x%x\n", value);
s->codec_status = value;
}
static void set_clip_count_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("set_clip_count_reg() called - value: 0x%x\n", new_value);
s->clip_count = new_value;
}
static void set_byte_swap_reg(ScreamerState *s, uint32_t value)
{
DPRINTF("set_byte_swap_reg() called - value: 0x%x\n", value);
s->byte_swap = value;
}
static void set_frame_count_reg(ScreamerState *s, uint32_t new_value)
{
DPRINTF("%s() called - value: 0x%x\n", __func__, new_value);
s->frame_count = new_value;
}
/*
* Sets the busy bit of codec control register.
* It is used to tell the CPU to wait.
* value: the codec control register's value
* bit_value: used to set or disable the busy bit
*/
static uint32_t set_busy_bit(uint32_t value, int bit_value)
{
const int busy_bit = 0x01000000;
uint32_t return_value;
if (bit_value == 1) /* Set this bit */
return_value = (value | busy_bit);
else /* bit_value == 0 Disable this bit */
return_value = (value & ~busy_bit);
return return_value;
}
/*
* Sets the part ready bit of the codec status register
* value: the codec status register's value
* bit_value: used to set or disable the part ready bit
*/
static uint32_t set_part_ready_bit(uint32_t value, int bit_value)
{
const int part_ready_bit = 0x00400000;
uint32_t return_value;
if (bit_value == 1) /* Set this bit */
return_value = (value | part_ready_bit);
else /* bit_value == 0 Disable this bit */
return_value = (value & ~part_ready_bit);
return return_value;
}
/* Sets bits 12 and 13 to 1 to indicate the Screamer revision */
static uint32_t set_revision(uint32_t input_value)
{
uint32_t return_value;
return_value = input_value | 0x3000;
return return_value;
}
/* Sets bit 8 to indicate Crystal as the manufacturer */
static uint32_t set_manufacturer(uint32_t input_value)
{
uint32_t return_value;
return_value = input_value | 0x100;
return return_value;
}
/************************** End of Setters *********************************/
/*************************** DMA functions *********************************/
/*
* Sends audio samples from a microphone or line-in to memory.
* Used for sound input.
* Currently only prevents a deadlock condition with Mac OS 9.
*/
static void screamer_to_dma(DBDMA_io *io)
{
DPRINTF("%s() called\n", __func__);
ScreamerState *s = (ScreamerState *)io->opaque;
DBDMAState *dbs = s->dbdma;
DBDMA_channel *ch = &dbs->channels[0x12];
ch->regs[DBDMA_STATUS] |= DEAD;
ch->regs[DBDMA_STATUS] &= ~ACTIVE;
io->dma_end(io);
return;
}
static void print_dma_info(DBDMA_io *io)
{
#define RUN 0x8000
#define PAUSE 0x4000
#define FLUSH 0x2000
#define WAKE 0x1000
#define DEAD 0x0800
#define ACTIVE 0x0400
#define BT 0x0100
#define DEVSTAT 0x00ff
/*
* RUN and PAUSE are bits under software control only.
* FLUSH and WAKE are set by SW and cleared by hardware.
* DEAD, ACTIVE and BT are only under hardware control.
*/
DBDMA_channel *ch = io->channel;
printf("DMA FLAGS: ");
if (ch->regs[DBDMA_STATUS] & RUN) {
printf("RUN ");
}
if (ch->regs[DBDMA_STATUS] & ACTIVE) {
printf("ACTIVE ");
}
if (ch->regs[DBDMA_STATUS] & PAUSE) {
printf("PAUSE ");
}
if (ch->regs[DBDMA_STATUS] & DEAD) {
printf("DEAD ");
}
if (ch->regs[DBDMA_STATUS] & WAKE) {
printf("WAKE ");
}
if (ch->regs[DBDMA_STATUS] & BT) {
printf("BT ");
}
if (ch->regs[DBDMA_STATUS] & DEVSTAT) {
printf("DEVSTAT ");
}
if (ch->regs[DBDMA_STATUS] & FLUSH) {
printf("FLUSH ");
}
if (ch->io.processing == true) {
printf("processing ");
}
printf("\n");
}
/* Tell the DMA controller we request more samples */
static void dma_request(DBDMA_io *io)
{
DPRINTF("%s() called\n", __func__);
if (DEBUG_SCREAMER) {
print_dma_info(io);
}
io->len = 0;
io->dma_end(io);
}
/* Adds sample data to the buffer */
static void add_to_speaker_buffer(DBDMA_io *io)
{
ScreamerState *s = (ScreamerState *) io->opaque;
if (s->spk_buffer_position + io->len > MAX_BUFFER_SIZE) {
/* postpone calling these samples until the buffer has been emptied */
memcpy(&s->dma_io, io, sizeof(DBDMA_io));
return;
}
dma_memory_read(&address_space_memory, io->addr,
&s->spk_buffer[s->spk_buffer_position], io->len,
MEMTXATTRS_UNSPECIFIED);
s->spk_buffer_position += io->len;
DPRINTF("%s() called - len: %d pos: %d/%d\n", __func__, io->len,
s->spk_buffer_position, MAX_BUFFER_SIZE);
dma_request(io);
}
/*
* Called by the DMA chip to transfer samples from memory to the
* Screamer chip.
* Used for sound output.
*/
static void dma_to_screamer(DBDMA_io *io)
{
add_to_speaker_buffer(io);
}
/*
* This will flush the audio buffer of previous audio - eliminating previous
* audio playback.
*/
static void send_silence_to_speaker(ScreamerState *s)
{
DPRINTF("Silencing audio buffer...\n");
int length = MAX_BUFFER_SIZE;
s->spk_buffer_position = length;
s->spk_play_position = 0;
memset(s->spk_buffer, 0, length);
s->dma_io.len = 0; /* stop any postponed samples from playing */
}
/* This is called after audio stops playing */
static void dma_send_flush(DBDMA_io *io)
{
DPRINTF("dma_send_flush() called\n");
if (DEBUG_SCREAMER) {
print_dma_info(io);
}
ScreamerState *s = (ScreamerState *)io->opaque;
reset_markers(s);
send_silence_to_speaker(s);
if (io->len > 0) {
dma_request(io);
}
}
static void dma_receive_flush(DBDMA_io *io)
{
DPRINTF("dma_receive_flush() called\n");
}
/* Set the functions the DMA system will call */
void screamer_register_dma_functions(ScreamerState *s, void *dbdma,
int send_channel, int receive_channel)
{
DPRINTF("%s() called\n", __func__);
DPRINTF("send channel: %d\treceive channel: %d\n", send_channel,
receive_channel);
s->dbdma = dbdma;
/* Setup the DMA send system */
DBDMA_register_channel(s->dbdma, send_channel, s->dma_send_irq,
dma_to_screamer, dma_send_flush, s);
/* Setup the DMA receive system */
DBDMA_register_channel(s->dbdma, receive_channel, s->dma_receive_irq,
screamer_to_dma, dma_receive_flush, s);
}
/************************* End of DMA functions **************************/
/* Resets this sound chip */
static void screamer_reset(DeviceState *d)
{
DPRINTF("screamer_reset() called\n");
ScreamerState *s = SCREAMER(d);
set_sound_control_reg(s, 0);
set_codec_control_reg(s, 0);
set_codec_status_reg(s, 0);
set_clip_count_reg(s, 0);
set_byte_swap_reg(s, 0);
set_frame_count_reg(s, 0);
int i, num_awacs_regs = 8;
for (i = 0; i < num_awacs_regs; i++) {
s->awacs[i] = 0;
}
set_QEMU_audio_settings(s);
reset_markers(s);
s->dma_io.len = 0;
}
/* Called when the CPU reads the memory addresses assigned to Screamer */
static uint64_t screamer_mmio_read(void *opaque, hwaddr addr, unsigned size)
{
ScreamerState *state = opaque;
uint32_t return_value;
addr = addr >> 4;
switch (addr) {
case SOUND_CONTROL_REG:
return_value = get_sound_control_reg(state);
break;
case CODEC_CONTROL_REG:
return_value = get_codec_control_reg(state);
break;
case CODEC_STATUS_REG:
return_value = get_codec_status_reg(state);
break;
case CLIP_COUNT_REG:
return_value = get_clip_count_reg(state);
break;
case BYTE_SWAP_REG:
return_value = get_byte_swap_reg(state);
break;
case FRAME_COUNT_REG:
return_value = get_frame_count_reg(state);
break;
default:
DPRINTF("Unknown register read - addr:%" HWADDR_PRIx "\tsize:%d\n",
addr, size);
return_value = 12021981; /* Value used for debugging purposes */
}
DPRINTF("screamer_mmio_read() called addr: %" HWADDR_PRIx " size: %d",
addr >> 4, size);
DPRINTF(" returning 0x%x\n", return_value);
return return_value;
}
/* Called when the CPU writes to the memory addresses assigned to Screamer */
static void screamer_mmio_write(void *opaque, hwaddr addr, uint64_t raw_value,
unsigned size)
{
DPRINTF("screamer_mmio_write() called - size: %d\n", size);
ScreamerState *state = opaque;
uint32_t value = raw_value & 0xffffffff;
addr = addr >> 4;
switch (addr) {
case SOUND_CONTROL_REG:
set_sound_control_reg(state, value);
break;
case CODEC_CONTROL_REG:
set_codec_control_reg(state, value);
break;
case CODEC_STATUS_REG:
set_codec_status_reg(state, value);
break;
case CLIP_COUNT_REG:
set_clip_count_reg(state, value);
break;
case BYTE_SWAP_REG:
set_byte_swap_reg(state, value);
break;
case FRAME_COUNT_REG:
set_frame_count_reg(state, value);
break;
default:
DPRINTF("Unknown register write - addr:%" HWADDR_PRIx "\tvalue:%d\n",
addr, value);
}
}
/* Used for memory_region_init_io() for memory mapped I/O */
static const MemoryRegionOps screamer_ops = {
.read = screamer_mmio_read,
.write = screamer_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4,
.max_access_size = 4
}
};
/* Called when the device has become active */
static void screamer_realize(DeviceState *dev, Error **errp)
{
DPRINTF("screamer_realize() called\n");
screamer_reset(dev);
}
/*
* Called when an instance of the Screamer device is created.
* Also called when this HMP command is called: device_add screamer
*/
static void screamer_init(Object *obj)
{
DPRINTF("screamer_init() called\n");
ScreamerState *s = (ScreamerState *)obj;
SysBusDevice *d = SYS_BUS_DEVICE(obj);
const int region_size = 5 * 32;
/* Makes the read and write ops work */
memory_region_init_io(&s->io_memory_region, OBJECT(s),
&screamer_ops, s, SOUND_CHIP_NAME, region_size);
/* Sets the SysBusDevice's memory property */
sysbus_init_mmio(d, &s->io_memory_region);
/* Setup all the interrupt requests */
sysbus_init_irq(d, &s->irq);
sysbus_init_irq(d, &s->dma_send_irq);
sysbus_init_irq(d, &s->dma_receive_irq);
/* Registers Screamer with QEMU's audio system */
AUD_register_card(SOUND_CHIP_NAME, &s->card);
}
/*
* When saving and restoring the state of the VM, this is used to save and
* restore the registers.
*/
static const VMStateDescription vmstate_screamer = {
.name = "Screamer",
.version_id = 1,
.minimum_version_id = 1,
.fields = (VMStateField[]) {
VMSTATE_UINT16_ARRAY(awacs, ScreamerState, 8), /* 8 AWACS registers */
VMSTATE_UINT32(sound_control, ScreamerState),
VMSTATE_UINT32(codec_control, ScreamerState),
VMSTATE_UINT32(codec_status, ScreamerState),
VMSTATE_UINT32(clip_count, ScreamerState),
VMSTATE_UINT32(byte_swap, ScreamerState),
VMSTATE_UINT32(frame_count, ScreamerState),
VMSTATE_END_OF_LIST()
}
};
/*
* Sets the class data. It is like polymorphism and inheritance in object
* oriented languages.
*/
static void screamer_class_init(ObjectClass *class, void *data)
{
DPRINTF("screamer_class_init() called\n");
DeviceClass *dc = DEVICE_CLASS(class);
dc->realize = screamer_realize;
dc->reset = screamer_reset;
dc->desc = "Apple Screamer";
dc->vmsd = &vmstate_screamer;
dc->hotpluggable = false;
}
/* Used for QOM function registration */
static const TypeInfo screamer_info = {
.name = "screamer",
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(ScreamerState),
.instance_init = screamer_init,
.class_init = screamer_class_init,
};
/* QOM registration of above functions for calling */
static void screamer_register_types(void)
{
DPRINTF("screamer_register_types() called\n");
type_register_static(&screamer_info);
}
/* QEMU Object Model (QOM) stuff */
type_init(screamer_register_types)
+41 -9
View File
@@ -63,6 +63,8 @@ softmmu_ss.add(when: 'CONFIG_ARTIST', if_true: files('artist.c'))
softmmu_ss.add(when: [pixman, 'CONFIG_ATI_VGA'], if_true: files('ati.c', 'ati_2d.c', 'ati_dbg.c'))
virgl_found = virgl.found() and opengl.found()
rutabaga_found = rutabaga.found()
if config_all_devices.has_key('CONFIG_VIRTIO_GPU')
virtio_gpu_ss = ss.source_set()
@@ -73,12 +75,37 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU')
virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-user-gpu.c'))
hw_display_modules += {'virtio-gpu': virtio_gpu_ss}
if virgl.found() and opengl.found()
virtio_gpu_gl_ss = ss.source_set()
virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', virgl, opengl],
if_true: [files('virtio-gpu-gl.c', 'virtio-gpu-virgl.c'), pixman, virgl])
hw_display_modules += {'virtio-gpu-gl': virtio_gpu_gl_ss}
virtio_gpu_gl_ss = ss.source_set()
if virgl_found or rutabaga_found
virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU'],
if_true: [files('virtio-gpu-gl.c'), pixman])
endif
if virgl_found
virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU'],
if_true: [files('virtio-gpu-virgl.c'), virgl])
else
virtio_gpu_gl_ss.add([files('virtio-gpu-virgl-stubs.c')])
endif
if rutabaga_found
virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU'],
if_true: [files('virtio-gpu-rutabaga.c'), rutabaga])
else
virtio_gpu_gl_ss.add([files('virtio-gpu-rutabaga-stubs.c')])
endif
hw_display_modules += {'virtio-gpu-gl': virtio_gpu_gl_ss}
endif
if config_all_devices.has_key('CONFIG_FW_CFG_DMA')
virtio_ramfb_ss = ss.source_set()
virtio_ramfb_ss.add(when: 'CONFIG_FW_CFG_DMA', if_true: files('virtio-ramfb.c'))
hw_display_modules += {'virtio-ramfb': virtio_ramfb_ss}
virtio_ramfb_gl_ss = ss.source_set()
virtio_ramfb_gl_ss.add(when: ['CONFIG_FW_CFG_DMA', virgl, opengl],
if_true: files('virtio-ramfb-gl.c'))
hw_display_modules += {'virtio-ramfb-gl': virtio_ramfb_gl_ss}
endif
if config_all_devices.has_key('CONFIG_VIRTIO_PCI')
@@ -89,9 +116,10 @@ if config_all_devices.has_key('CONFIG_VIRTIO_PCI')
if_true: files('vhost-user-gpu-pci.c'))
hw_display_modules += {'virtio-gpu-pci': virtio_gpu_pci_ss}
if virgl.found() and opengl.found()
if virgl_found or rutabaga_found
virtio_gpu_pci_gl_ss = ss.source_set()
virtio_gpu_pci_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PCI', virgl, opengl],
virtio_gpu_pci_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', '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
@@ -108,8 +136,12 @@ if config_all_devices.has_key('CONFIG_VIRTIO_VGA')
hw_display_modules += {'virtio-vga': virtio_vga_ss}
virtio_vga_gl_ss = ss.source_set()
virtio_vga_gl_ss.add(when: ['CONFIG_VIRTIO_VGA', virgl, opengl],
if_true: [files('virtio-vga-gl.c'), pixman])
if virgl_found or rutabaga_found
virtio_vga_gl_ss.add(when: ['CONFIG_VIRTIO_VGA'],
if_true: [files('virtio-vga-gl.c'), pixman])
endif
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}
+5 -1
View File
@@ -206,7 +206,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)) {
@@ -215,6 +216,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;
}
+13 -108
View File
@@ -15,124 +15,29 @@
#include "qemu/iov.h"
#include "qemu/module.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
#include "sysemu/sysemu.h"
#include "hw/virtio/virtio.h"
#include "hw/virtio/virtio-gpu.h"
#include "hw/virtio/virtio-gpu-bswap.h"
#include "hw/virtio/virtio-gpu-pixman.h"
#include "hw/qdev-properties.h"
#include <virglrenderer.h>
static void virtio_gpu_gl_update_cursor_data(VirtIOGPU *g,
struct virtio_gpu_scanout *s,
uint32_t resource_id)
{
uint32_t width, height;
uint32_t pixels, *data;
data = virgl_renderer_get_cursor_data(resource_id, &width, &height);
if (!data) {
return;
}
if (width != s->current_cursor->width ||
height != s->current_cursor->height) {
free(data);
return;
}
pixels = s->current_cursor->width * s->current_cursor->height;
memcpy(s->current_cursor->data, data, pixels * sizeof(uint32_t));
free(data);
}
static void virtio_gpu_gl_flushed(VirtIOGPUBase *b)
{
VirtIOGPU *g = VIRTIO_GPU(b);
virtio_gpu_process_cmdq(g);
}
static void virtio_gpu_gl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIOGPU *g = VIRTIO_GPU(vdev);
VirtIOGPUGL *gl = VIRTIO_GPU_GL(vdev);
struct virtio_gpu_ctrl_command *cmd;
if (!virtio_queue_ready(vq)) {
return;
}
if (!gl->renderer_inited) {
virtio_gpu_virgl_init(g);
gl->renderer_inited = true;
}
if (gl->renderer_reset) {
gl->renderer_reset = false;
virtio_gpu_virgl_reset(g);
}
cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
while (cmd) {
cmd->vq = vq;
cmd->error = 0;
cmd->finished = false;
QTAILQ_INSERT_TAIL(&g->cmdq, cmd, next);
cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
}
virtio_gpu_process_cmdq(g);
virtio_gpu_virgl_fence_poll(g);
}
static void virtio_gpu_gl_reset(VirtIODevice *vdev)
{
VirtIOGPU *g = VIRTIO_GPU(vdev);
VirtIOGPUGL *gl = VIRTIO_GPU_GL(vdev);
virtio_gpu_reset(vdev);
/*
* GL functions must be called with the associated GL context in main
* thread, and when the renderer is unblocked.
*/
if (gl->renderer_inited && !gl->renderer_reset) {
virtio_gpu_virgl_reset_scanout(g);
gl->renderer_reset = true;
}
}
static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
{
VirtIOGPU *g = VIRTIO_GPU(qdev);
VirtIOGPUGL *virtio_gpu = VIRTIO_GPU_GL(qdev);
virtio_gpu->rutabaga = NULL;
virtio_gpu_rutabaga_device_realize(qdev, errp);
#if HOST_BIG_ENDIAN
error_setg(errp, "virgl is not supported on bigendian platforms");
return;
#endif
if (!object_resolve_path_type("", TYPE_VIRTIO_GPU_GL, NULL)) {
error_setg(errp, "at most one %s device is permitted", TYPE_VIRTIO_GPU_GL);
return;
/* Fallback to virgl if rutabaga fails to initialize */
if (!virtio_gpu->rutabaga) {
virtio_gpu_virgl_device_realize(qdev, errp);
}
if (!display_opengl) {
error_setg(errp, "opengl is not available");
return;
}
g->parent_obj.conf.flags |= (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED);
VIRTIO_GPU_BASE(g)->virtio_config.num_capsets =
virtio_gpu_virgl_get_num_capsets(g);
virtio_gpu_device_realize(qdev, errp);
}
static Property virtio_gpu_gl_properties[] = {
DEFINE_PROP_BIT("stats", VirtIOGPU, parent_obj.conf.flags,
VIRTIO_GPU_FLAG_STATS_ENABLED, false),
DEFINE_PROP_STRING("capset_names", VirtIOGPUGL, capset_names),
DEFINE_PROP_STRING("wayland_socket_path", VirtIOGPUGL, wayland_socket_path),
DEFINE_PROP_END_OF_LIST(),
};
@@ -143,13 +48,13 @@ static void virtio_gpu_gl_class_init(ObjectClass *klass, void *data)
VirtIOGPUBaseClass *vbc = VIRTIO_GPU_BASE_CLASS(klass);
VirtIOGPUClass *vgc = VIRTIO_GPU_CLASS(klass);
vbc->gl_flushed = virtio_gpu_gl_flushed;
vgc->handle_ctrl = virtio_gpu_gl_handle_ctrl;
vgc->process_cmd = virtio_gpu_virgl_process_cmd;
vgc->update_cursor_data = virtio_gpu_gl_update_cursor_data;
vbc->gl_flushed = NULL;
vgc->handle_ctrl = NULL;
vgc->process_cmd = NULL;
vgc->update_cursor_data = NULL;
vdc->realize = virtio_gpu_gl_device_realize;
vdc->reset = virtio_gpu_gl_reset;
vdc->reset = NULL;
device_class_set_props(dc, virtio_gpu_gl_properties);
}
+15
View File
@@ -33,6 +33,21 @@ 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_ram_user_backed(&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;
+8
View File
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: GPL-2.0
#include "qemu/osdep.h"
#include "hw/virtio/virtio-gpu.h"
void virtio_gpu_rutabaga_device_realize(DeviceState *qdev, Error **errp)
{
/* nothing (stub) */
}
File diff suppressed because it is too large. Load diff
+8
View File
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: GPL-2.0
#include "qemu/osdep.h"
#include "hw/virtio/virtio-gpu.h"
void virtio_gpu_virgl_device_realize(DeviceState *qdev, Error **errp)
{
/* nothing (stub) */
}
+162 -22
View File
@@ -14,6 +14,8 @@
#include "qemu/osdep.h"
#include "qemu/error-report.h"
#include "qemu/iov.h"
#include "qapi/error.h"
#include "sysemu/sysemu.h"
#include "trace.h"
#include "hw/virtio/virtio.h"
#include "hw/virtio/virtio-gpu.h"
@@ -141,12 +143,39 @@ static void virgl_cmd_resource_flush(VirtIOGPU *g,
}
}
static GLuint virgl_borrow_texture_for_scanout(uint32_t id, bool *y_0_top,
uint32_t *width,
uint32_t *height)
{
struct virgl_renderer_texture_info info;
int ret;
memset(&info, 0, sizeof(info));
ret = virgl_renderer_borrow_texture_for_scanout(id, &info);
if (ret == -1) {
return 0;
}
if (y_0_top) {
*y_0_top = info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP;
}
if (width) {
*width = info.width;
}
if (height) {
*height = info.height;
}
return info.tex_id;
}
static void virgl_cmd_set_scanout(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
struct virtio_gpu_set_scanout ss;
struct virgl_renderer_resource_info info;
int ret;
VIRTIO_GPU_FILL_CMD(ss);
trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id,
@@ -160,24 +189,13 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
}
g->parent_obj.enable = 1;
memset(&info, 0, sizeof(info));
if (ss.resource_id && ss.r.width && ss.r.height) {
ret = virgl_renderer_resource_get_info(ss.resource_id, &info);
if (ret == -1) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: illegal resource specified %d\n",
__func__, ss.resource_id);
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
return;
}
qemu_console_resize(g->parent_obj.scanout[ss.scanout_id].con,
ss.r.width, ss.r.height);
virgl_renderer_force_ctx_0();
dpy_gl_scanout_texture(
g->parent_obj.scanout[ss.scanout_id].con, info.tex_id,
info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP,
info.width, info.height,
g->parent_obj.scanout[ss.scanout_id].con, ss.resource_id,
virgl_borrow_texture_for_scanout,
ss.r.x, ss.r.y, ss.r.width, ss.r.height);
} else {
dpy_gfx_replace_surface(
@@ -399,8 +417,9 @@ static void virgl_cmd_get_capset(VirtIOGPU *g,
g_free(resp);
}
void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
static void
virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
VIRTIO_GPU_FILL_CMD(cmd->cmd_hdr);
@@ -584,12 +603,12 @@ static void virtio_gpu_fence_poll(void *opaque)
}
}
void virtio_gpu_virgl_fence_poll(VirtIOGPU *g)
static void virtio_gpu_virgl_fence_poll(VirtIOGPU *g)
{
virtio_gpu_fence_poll(g);
}
void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)
static void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)
{
int i;
@@ -599,12 +618,12 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)
}
}
void virtio_gpu_virgl_reset(VirtIOGPU *g)
static void virtio_gpu_virglrenderer_reset(VirtIOGPU *g)
{
virgl_renderer_reset();
}
int virtio_gpu_virgl_init(VirtIOGPU *g)
static int virtio_gpu_virgl_init(VirtIOGPU *g)
{
int ret;
@@ -625,7 +644,7 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
return 0;
}
int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g)
static int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g)
{
uint32_t capset2_max_ver, capset2_max_size;
virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_VIRGL2,
@@ -634,3 +653,124 @@ int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g)
return capset2_max_ver ? 2 : 1;
}
static void
virtio_gpu_virgl_update_cursor(VirtIOGPU *g,
struct virtio_gpu_scanout *s,
uint32_t resource_id)
{
uint32_t width, height;
uint32_t pixels, *data;
data = virgl_renderer_get_cursor_data(resource_id, &width, &height);
if (!data) {
return;
}
if (width != s->current_cursor->width ||
height != s->current_cursor->height) {
free(data);
return;
}
pixels = s->current_cursor->width * s->current_cursor->height;
memcpy(s->current_cursor->data, data, pixels * sizeof(uint32_t));
free(data);
}
static void virtio_gpu_virgl_flushed(VirtIOGPUBase *b)
{
VirtIOGPU *g = VIRTIO_GPU(b);
virtio_gpu_process_cmdq(g);
}
static void virtio_gpu_virgl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIOGPU *g = VIRTIO_GPU(vdev);
VirtIOGPUGL *gl = VIRTIO_GPU_GL(vdev);
struct virtio_gpu_ctrl_command *cmd;
if (!virtio_queue_ready(vq)) {
return;
}
if (!gl->renderer_inited) {
virtio_gpu_virgl_init(g);
gl->renderer_inited = true;
}
if (gl->renderer_reset) {
gl->renderer_reset = false;
virtio_gpu_virglrenderer_reset(g);
}
cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
while (cmd) {
cmd->vq = vq;
cmd->error = 0;
cmd->finished = false;
QTAILQ_INSERT_TAIL(&g->cmdq, cmd, next);
cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
}
virtio_gpu_process_cmdq(g);
virtio_gpu_virgl_fence_poll(g);
}
static void virtio_gpu_virgl_reset(VirtIODevice *vdev)
{
VirtIOGPU *g = VIRTIO_GPU(vdev);
VirtIOGPUGL *gl = VIRTIO_GPU_GL(vdev);
virtio_gpu_reset(vdev);
/*
* GL functions must be called with the associated GL context in main
* thread, and when the renderer is unblocked.
*/
if (gl->renderer_inited && !gl->renderer_reset) {
virtio_gpu_virgl_reset_scanout(g);
gl->renderer_reset = true;
}
}
void virtio_gpu_virgl_device_realize(DeviceState *qdev, Error **errp)
{
VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
VirtIOGPUBase *bdev = VIRTIO_GPU_BASE(qdev);
VirtIOGPUBaseClass *vbc = VIRTIO_GPU_BASE_GET_CLASS(bdev);
VirtIOGPU *gpudev = VIRTIO_GPU(qdev);
VirtIOGPUClass *vgc = VIRTIO_GPU_GET_CLASS(gpudev);
vbc->gl_flushed = virtio_gpu_virgl_flushed;
vgc->handle_ctrl = virtio_gpu_virgl_handle_ctrl;
vgc->process_cmd = virtio_gpu_virgl_process_cmd;
vgc->update_cursor_data = virtio_gpu_virgl_update_cursor;
vdc->reset = virtio_gpu_virgl_reset;
#if HOST_BIG_ENDIAN
error_setg(errp, "virgl is not supported on bigendian platforms");
return;
#endif
if (!object_resolve_path_type("", TYPE_VIRTIO_GPU_GL, NULL)) {
error_setg(errp, "at most one %s device is permitted",
TYPE_VIRTIO_GPU_GL);
return;
}
if (!display_opengl) {
error_setg(errp, "opengl is not available");
return;
}
gpudev->parent_obj.conf.flags |= (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED);
VIRTIO_GPU_BASE(gpudev)->virtio_config.num_capsets =
virtio_gpu_virgl_get_num_capsets(gpudev);
virtio_gpu_device_realize(qdev, errp);
}
+7 -10
View File
@@ -33,16 +33,11 @@
#define VIRTIO_GPU_VM_VERSION 1
static struct virtio_gpu_simple_resource*
virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id);
static struct virtio_gpu_simple_resource *
virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t resource_id,
bool require_backing,
const char *caller, uint32_t *error);
static void virtio_gpu_cleanup_mapping(VirtIOGPU *g,
struct virtio_gpu_simple_resource *res);
void virtio_gpu_update_cursor_data(VirtIOGPU *g,
struct virtio_gpu_scanout *s,
uint32_t resource_id)
@@ -115,7 +110,7 @@ static void update_cursor(VirtIOGPU *g, struct virtio_gpu_update_cursor *cursor)
cursor->resource_id ? 1 : 0);
}
static struct virtio_gpu_simple_resource *
struct virtio_gpu_simple_resource *
virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id)
{
struct virtio_gpu_simple_resource *res;
@@ -872,8 +867,8 @@ void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g,
g_free(iov);
}
static void virtio_gpu_cleanup_mapping(VirtIOGPU *g,
struct virtio_gpu_simple_resource *res)
void virtio_gpu_cleanup_mapping(VirtIOGPU *g,
struct virtio_gpu_simple_resource *res)
{
virtio_gpu_cleanup_mapping_iov(g, res->iov, res->iov_cnt);
res->iov = NULL;
@@ -1319,8 +1314,9 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
VirtIOGPU *g = VIRTIO_GPU(qdev);
if (virtio_gpu_blob_enabled(g->parent_obj.conf)) {
if (!virtio_gpu_have_udmabuf()) {
error_setg(errp, "cannot enable blob resources without udmabuf");
if (!virtio_gpu_have_udmabuf() &&
!virtio_gpu_rutabaga_enabled(g->parent_obj.conf)) {
error_setg(errp, "need udmabuf or rutabaga for blob resources");
return;
}
@@ -1425,6 +1421,7 @@ static Property virtio_gpu_properties[] = {
256 * MiB),
DEFINE_PROP_BIT("blob", VirtIOGPU, parent_obj.conf.flags,
VIRTIO_GPU_FLAG_BLOB_ENABLED, false),
DEFINE_PROP_SIZE("hostmem", VirtIOGPU, parent_obj.conf.hostmem, 0),
DEFINE_PROP_END_OF_LIST(),
};
+50
View File
@@ -0,0 +1,50 @@
#include "qemu/osdep.h"
#include "hw/pci/pci.h"
#include "hw/qdev-properties.h"
#include "hw/virtio/virtio-gpu.h"
#include "hw/display/vga.h"
#include "qapi/error.h"
#include "qemu/module.h"
#include "virtio-ramfb.h"
#include "qom/object.h"
#define TYPE_VIRTIO_RAMFB_GL "virtio-ramfb-gl"
typedef struct VirtIORAMFBGL VirtIORAMFBGL;
DECLARE_INSTANCE_CHECKER(VirtIORAMFBGL, VIRTIO_RAMFB_GL,
TYPE_VIRTIO_RAMFB_GL)
struct VirtIORAMFBGL {
VirtIORAMFBBase parent_obj;
VirtIOGPUGL vdev;
};
static void virtio_ramfb_gl_inst_initfn(Object *obj)
{
VirtIORAMFBGL *dev = VIRTIO_RAMFB_GL(obj);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_GPU_GL);
VIRTIO_RAMFB_BASE(dev)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
}
static VirtioPCIDeviceTypeInfo virtio_ramfb_gl_info = {
.generic_name = TYPE_VIRTIO_RAMFB_GL,
.parent = TYPE_VIRTIO_RAMFB_BASE,
.instance_size = sizeof(VirtIORAMFBGL),
.instance_init = virtio_ramfb_gl_inst_initfn,
};
module_obj(TYPE_VIRTIO_RAMFB_GL);
static void virtio_ramfb_register_types(void)
{
if (have_vga) {
virtio_pci_types_register(&virtio_ramfb_gl_info);
}
}
type_init(virtio_ramfb_register_types)
module_dep("hw-display-virtio-ramfb");
+191
View File
@@ -0,0 +1,191 @@
#include "qemu/osdep.h"
#include "sysemu/sysemu.h"
#include "hw/pci/pci.h"
#include "ui/console.h"
#include "hw/qdev-properties.h"
#include "virtio-ramfb.h"
#include "qapi/error.h"
#include "qom/object.h"
static int virtio_ramfb_get_flags(void *opaque)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->get_flags) {
return g->hw_ops->get_flags(g);
} else {
return 0;
}
}
static void virtio_ramfb_invalidate_display(void *opaque)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->enable) {
g->hw_ops->invalidate(g);
}
}
static void virtio_ramfb_text_update(void *opaque, console_ch_t *chardata)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->text_update) {
g->hw_ops->text_update(g, chardata);
}
}
static void virtio_ramfb_update_display(void *opaque)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->enable) {
g->hw_ops->gfx_update(g);
} else {
ramfb_display_update(g->scanout[0].con, vramfb->ramfb);
}
}
static void virtio_ramfb_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->ui_info) {
g->hw_ops->ui_info(g, idx, info);
}
}
static void virtio_ramfb_gl_block(void *opaque, bool block)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->gl_block) {
g->hw_ops->gl_block(g, block);
}
}
static const GraphicHwOps virtio_ramfb_ops = {
.get_flags = virtio_ramfb_get_flags,
.invalidate = virtio_ramfb_invalidate_display,
.gfx_update = virtio_ramfb_update_display,
.text_update = virtio_ramfb_text_update,
.ui_info = virtio_ramfb_ui_info,
.gl_block = virtio_ramfb_gl_block,
};
static const VMStateDescription vmstate_virtio_ramfb = {
.name = "virtio-ramfb",
.version_id = 2,
.minimum_version_id = 2,
.fields = (VMStateField[]) {
/* no pci stuff here, saving the virtio device will handle that */
/* FIXME */
VMSTATE_END_OF_LIST()
}
};
/* RAMFB device wrapper around PCI device around virtio GPU */
static void virtio_ramfb_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
{
VirtIORAMFBBase *vramfb = VIRTIO_RAMFB_BASE(vpci_dev);
VirtIOGPUBase *g = vramfb->vgpu;
int i;
/* init virtio bits */
virtio_pci_force_virtio_1(vpci_dev);
if (!qdev_realize(DEVICE(g), BUS(&vpci_dev->bus), errp)) {
return;
}
/* init ramfb */
vramfb->ramfb = ramfb_setup(errp);
graphic_console_set_hwops(g->scanout[0].con, &virtio_ramfb_ops, vramfb);
for (i = 0; i < g->conf.max_outputs; i++) {
object_property_set_link(OBJECT(g->scanout[i].con), "device",
OBJECT(vpci_dev), &error_abort);
}
}
static void virtio_ramfb_reset(DeviceState *dev)
{
VirtIORAMFBBaseClass *klass = VIRTIO_RAMFB_BASE_GET_CLASS(dev);
/* reset virtio-gpu */
klass->parent_reset(dev);
}
static Property virtio_ramfb_base_properties[] = {
DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
DEFINE_PROP_END_OF_LIST(),
};
static void virtio_ramfb_base_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
VirtIORAMFBBaseClass *v = VIRTIO_RAMFB_BASE_CLASS(klass);
PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
device_class_set_props(dc, virtio_ramfb_base_properties);
dc->vmsd = &vmstate_virtio_ramfb;
dc->hotpluggable = false;
device_class_set_parent_reset(dc, virtio_ramfb_reset,
&v->parent_reset);
k->realize = virtio_ramfb_realize;
pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER;
}
static const TypeInfo virtio_ramfb_base_info = {
.name = TYPE_VIRTIO_RAMFB_BASE,
.parent = TYPE_VIRTIO_PCI,
.instance_size = sizeof(VirtIORAMFBBase),
.class_size = sizeof(VirtIORAMFBBaseClass),
.class_init = virtio_ramfb_base_class_init,
.abstract = true,
};
#define TYPE_VIRTIO_RAMFB "virtio-ramfb"
typedef struct VirtIORAMFB VirtIORAMFB;
DECLARE_INSTANCE_CHECKER(VirtIORAMFB, VIRTIO_RAMFB,
TYPE_VIRTIO_RAMFB)
struct VirtIORAMFB {
VirtIORAMFBBase parent_obj;
VirtIOGPU vdev;
};
static void virtio_ramfb_inst_initfn(Object *obj)
{
VirtIORAMFB *dev = VIRTIO_RAMFB(obj);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_GPU);
VIRTIO_RAMFB_BASE(dev)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
}
static VirtioPCIDeviceTypeInfo virtio_ramfb_info = {
.generic_name = TYPE_VIRTIO_RAMFB,
.parent = TYPE_VIRTIO_RAMFB_BASE,
.instance_size = sizeof(VirtIORAMFB),
.instance_init = virtio_ramfb_inst_initfn,
};
static void virtio_ramfb_register_types(void)
{
type_register_static(&virtio_ramfb_base_info);
virtio_pci_types_register(&virtio_ramfb_info);
}
type_init(virtio_ramfb_register_types)
+28
View File
@@ -0,0 +1,28 @@
#ifndef VIRTIO_RAMFB_H
#define VIRTIO_RAMFB_H
#include "hw/virtio/virtio-gpu-pci.h"
#include "hw/display/ramfb.h"
#include "qom/object.h"
/*
* virtio-ramfb-base: This extends VirtioPCIProxy.
*/
#define TYPE_VIRTIO_RAMFB_BASE "virtio-ramfb-base"
OBJECT_DECLARE_TYPE(VirtIORAMFBBase, VirtIORAMFBBaseClass,
VIRTIO_RAMFB_BASE)
struct VirtIORAMFBBase {
VirtIOPCIProxy parent_obj;
VirtIOGPUBase *vgpu;
RAMFBState *ramfb;
};
struct VirtIORAMFBBaseClass {
VirtioPCIClass parent_class;
DeviceReset parent_reset;
};
#endif /* VIRTIO_RAMFB_H */
+25 -9
View File
@@ -115,17 +115,33 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
pci_register_bar(&vpci_dev->pci_dev, 0,
PCI_BASE_ADDRESS_MEM_PREFETCH, &vga->vram);
/*
* Configure virtio bar and regions
*
* We use bar #2 for the mmio regions, to be compatible with stdvga.
* virtio regions are moved to the end of bar #2, to make room for
* the stdvga mmio registers at the start of bar #2.
*/
vpci_dev->modern_mem_bar_idx = 2;
vpci_dev->msix_bar_idx = 4;
vpci_dev->modern_io_bar_idx = 5;
if (!virtio_gpu_hostmem_enabled(g->conf)) {
/*
* Configure virtio bar and regions
*
* We use bar #2 for the mmio regions, to be compatible with stdvga.
* virtio regions are moved to the end of bar #2, to make room for
* the stdvga mmio registers at the start of bar #2.
*/
vpci_dev->modern_mem_bar_idx = 2;
vpci_dev->msix_bar_idx = 4;
} else {
vpci_dev->msix_bar_idx = 1;
vpci_dev->modern_mem_bar_idx = 2;
memory_region_init_ram_user_backed(&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);
}
if (!(vpci_dev->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)) {
/*
* with page-per-vq=off there is no padding space we can use
+28
View File
@@ -35,6 +35,7 @@
#include "hw/misc/macio/macio.h"
#include "hw/intc/heathrow_pic.h"
#include "trace.h"
#include "include/hw/audio/screamer.h"
#define ESCC_CLOCK 3686400
@@ -101,6 +102,17 @@ static bool macio_common_realize(PCIDevice *d, Error **errp)
sbd = SYS_BUS_DEVICE(&s->dbdma);
memory_region_add_subregion(&s->bar, 0x08000,
sysbus_mmio_get_region(sbd, 0));
if (!qdev_realize(DEVICE(&s->screamer), BUS(&s->macio_bus), errp)) {
return false;
}
/* Add the screamer sound chip */
sbd = SYS_BUS_DEVICE(&s->screamer);
const int offset = 0x14000; /* Offset from base address register (bar) */
const int region_number = 0; /* which memory region to use */
memory_region_add_subregion(&s->bar, offset,
sysbus_mmio_get_region(sbd,
region_number));
qdev_prop_set_uint32(DEVICE(&s->escc), "disabled", 0);
qdev_prop_set_uint32(DEVICE(&s->escc), "frequency", ESCC_CLOCK);
@@ -341,6 +353,19 @@ static void macio_newworld_realize(PCIDevice *d, Error **errp)
memory_region_add_subregion(&s->bar, 0x16000,
sysbus_mmio_get_region(sbd, 0));
}
/* Screamer Sound Chip */
const int gpio_0 = 0;
const int gpio_1 = 1;
const int transmit_channel = 0x10;
const int receive_channel = 0x12;
sbd = SYS_BUS_DEVICE(&s->screamer);
sysbus_connect_irq(sbd, gpio_0, qdev_get_gpio_in(pic_dev,
NEWWORLD_SCREAMER_IRQ));
sysbus_connect_irq(sbd, gpio_1, qdev_get_gpio_in(pic_dev,
NEWWORLD_SCREAMER_DMA_IRQ));
screamer_register_dma_functions(SCREAMER(sbd), &s->dbdma,
transmit_channel, receive_channel);
}
static void macio_newworld_init(Object *obj)
@@ -370,6 +395,9 @@ static void macio_instance_init(Object *obj)
object_initialize_child(obj, "dbdma", &s->dbdma, TYPE_MAC_DBDMA);
object_initialize_child(obj, "escc", &s->escc, TYPE_ESCC);
object_initialize_child(obj, SOUND_CHIP_NAME, &s->screamer,
TYPE_SCREAMER);
}
static const VMStateDescription vmstate_macio_oldworld = {
+1
View File
@@ -115,6 +115,7 @@ config MAC_NEWWORLD
select MAC_PMU
select UNIN_PCI
select FW_CFG_PPC
select SCREAMER
config E500
bool
+2 -1
View File
@@ -1280,7 +1280,8 @@ static void usbredir_create_parser(USBRedirDevice *dev)
}
#endif
if (runstate_check(RUN_STATE_INMIGRATE)) {
if (runstate_check(RUN_STATE_INMIGRATE) ||
runstate_check(RUN_STATE_RESTORE_VM)) {
flags |= usbredirparser_fl_no_hello;
}
usbredirparser_init(dev->parser, VERSION, caps, USB_REDIR_CAPS_SIZE,
+18
View File
@@ -1399,6 +1399,24 @@ static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,
return offset;
}
int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy,
uint8_t bar, uint64_t offset, uint64_t length,
uint8_t id)
{
struct virtio_pci_cap64 cap = {
.cap.cap_len = sizeof cap,
.cap.cfg_type = VIRTIO_PCI_CAP_SHARED_MEMORY_CFG,
};
cap.cap.bar = bar;
cap.cap.length = cpu_to_le32(length);
cap.length_hi = cpu_to_le32(length >> 32);
cap.cap.offset = cpu_to_le32(offset);
cap.offset_hi = cpu_to_le32(offset >> 32);
cap.cap.id = id;
return virtio_pci_add_mem_cap(proxy, &cap.cap);
}
static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr,
unsigned size)
{
+1
View File
@@ -412,6 +412,7 @@ typedef struct disassemble_info {
typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *);
int print_insn_tci(bfd_vma, disassemble_info*);
int print_insn_tcti(bfd_vma, disassemble_info*);
int print_insn_big_mips (bfd_vma, disassemble_info*);
int print_insn_little_mips (bfd_vma, disassemble_info*);
int print_insn_nanomips (bfd_vma, disassemble_info*);
+4
View File
@@ -685,7 +685,11 @@ void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr);
#if defined(CONFIG_TCG_INTERPRETER)
extern __thread uintptr_t tci_tb_ptr;
# define GETPC() tci_tb_ptr
#elif defined(CONFIG_TCG_THREADED_INTERPRETER)
extern __thread uintptr_t tcti_call_return_address;
# define GETPC() tcti_call_return_address
#else
/* Note that this is correct for TCTI also; whose gadget behaves like native code. */
# define GETPC() \
((uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0)))
#endif
+17
View File
@@ -0,0 +1,17 @@
#ifndef EXEC_MEMORY_REMAH_H_INCLUDED
#define EXEC_MEMORY_REMAH_H_INCLUDED
#include <stdint.h>
/*
* API for adding and removing mappings of guest RAM and host addrs.
* Implementation depends on the hypervisor.
*/
#define USER_BACKED_RAM_FLAGS_NONE 0x0
#define USER_BACKED_RAM_FLAGS_READ 0x1
#define USER_BACKED_RAM_FLAGS_WRITE 0x2
#define USER_BACKED_RAM_FLAGS_EXEC 0x4
void qemu_user_backed_ram_map(uint64_t gpa, void* hva, uint64_t size, int flags);
void qemu_user_backed_ram_unmap(uint64_t gpa, uint64_t size);
#endif /* EXEC_MEMORY_REMAH_H_INCLUDED */
+28
View File
@@ -214,6 +214,8 @@ typedef struct IOMMUTLBEvent {
/* RAM is a persistent kind memory */
#define RAM_PMEM (1 << 5)
/* RAM backing is managed by user */
#define RAM_USER_BACKED (1 << 6)
/*
* UFFDIO_WRITEPROTECT is used on this RAMBlock to
@@ -763,6 +765,7 @@ struct MemoryRegion {
bool nonvolatile;
bool rom_device;
bool flush_coalesced_mmio;
bool user_backed;
uint8_t dirty_log_mask;
bool is_iommu;
RAMBlock *ram_block;
@@ -1535,6 +1538,16 @@ void memory_region_init_ram(MemoryRegion *mr,
uint64_t size,
Error **errp);
/**
* memory_region_init_ram_user_backed - Initialize RAM memory region where
* the allocation is dynamically managed by the user.
* Accesses into the region will modify memory directly.
*/
void memory_region_init_ram_user_backed(MemoryRegion *mr,
Object *owner,
const char *name,
uint64_t size);
/**
* memory_region_init_rom: Initialize a ROM memory region.
*
@@ -1622,6 +1635,21 @@ static inline bool memory_region_is_ram(MemoryRegion *mr)
return mr->ram;
}
/**
* memory_region_is_user_backed: check whether a memory region is random access
*
* Returns %true if a memory region's backing
* is user managed. This allows hypervisor to avoid
* directly adding the region on initialization,
* which can be a fatal error.
*
* @mr: the memory region being queried
*/
static inline bool memory_region_is_user_backed(MemoryRegion *mr)
{
return mr->user_backed;
}
/**
* memory_region_is_ram_device: check whether a memory region is a ram device
*
+9
View File
@@ -133,6 +133,15 @@ RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size,
uint64_t length,
void *host),
MemoryRegion *mr, Error **errp);
RAMBlock *qemu_ram_alloc_user_backed(ram_addr_t size, MemoryRegion *mr,
Error **errp);
typedef void (*QemuUserBackedRamMapFunc)(uint64_t gpa, void* hva, uint64_t size, int flags);
typedef void (*QemuUserBackedRamUnmapFunc)(uint64_t gpa, uint64_t size);
void qemu_set_user_backed_mapping_funcs(QemuUserBackedRamMapFunc mapFunc,
QemuUserBackedRamUnmapFunc unmapFunc);
void qemu_ram_free(RAMBlock *block);
int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp);
+42
View File
@@ -0,0 +1,42 @@
/*
* File: screamer.h
* Description: header file to the hw/audio/screamer.c file
*/
#ifndef screamer_h
#define screamer_h
#include <inttypes.h>
#include "audio/audio.h"
#include "hw/ppc/mac_dbdma.h"
#define TYPE_SCREAMER "screamer"
#define SCREAMER(obj) OBJECT_CHECK(ScreamerState, (obj), TYPE_SCREAMER)
#define SOUND_CHIP_NAME "Screamer Sound Chip"
#define MAX_BUFFER_SIZE (128 * 64)
typedef struct ScreamerState {
SysBusDevice parent_obj;
uint16_t awacs[8]; /* Shadow/awacs registers */
uint32_t sound_control;
uint32_t codec_control;
uint32_t codec_status;
uint32_t clip_count;
uint32_t byte_swap;
uint32_t frame_count;
SWVoiceOut *speaker_voice;
DBDMAState *dbdma;
qemu_irq dma_send_irq;
qemu_irq dma_receive_irq;
qemu_irq irq;
QEMUSoundCard card;
MemoryRegion io_memory_region;
uint8_t spk_buffer[MAX_BUFFER_SIZE];
uint16_t spk_buffer_position, spk_play_position;
DBDMA_io dma_io;
} ScreamerState;
void screamer_register_dma_functions(ScreamerState *s, void *dbdma,
int send_channel, int receive_channel);
#endif /* screamer_h */
+5
View File
@@ -36,6 +36,7 @@
#include "hw/nvram/mac_nvram.h"
#include "hw/ppc/mac_dbdma.h"
#include "hw/ppc/openpic.h"
#include "hw/audio/screamer.h"
#include "qom/object.h"
/* Old World IRQs */
@@ -58,6 +59,9 @@
#define NEWWORLD_IDE1_DMA_IRQ 0x3
#define NEWWORLD_EXTING_GPIO1 0x2f
#define NEWWORLD_EXTING_GPIO9 0x37
#define NEWWORLD_SCREAMER_IRQ 0x18
#define NEWWORLD_SCREAMER_DMA_IRQ 0x9
#define NEWWORLD_SCREAMER_RX_IRQ 0xa
/* MacIO virtual bus */
#define TYPE_MACIO_BUS "macio-bus"
@@ -109,6 +113,7 @@ struct MacIOState {
PMUState pmu;
DBDMAState dbdma;
ESCCState escc;
ScreamerState screamer;
uint64_t frequency;
};
+18
View File
@@ -63,10 +63,28 @@ virtio_gpu_create_blob_bswap(struct virtio_gpu_resource_create_blob *cblob)
{
virtio_gpu_ctrl_hdr_bswap(&cblob->hdr);
le32_to_cpus(&cblob->resource_id);
le32_to_cpus(&cblob->blob_mem);
le32_to_cpus(&cblob->blob_flags);
le32_to_cpus(&cblob->nr_entries);
le64_to_cpus(&cblob->blob_id);
le64_to_cpus(&cblob->size);
}
static inline void
virtio_gpu_map_blob_bswap(struct virtio_gpu_resource_map_blob *mblob)
{
virtio_gpu_ctrl_hdr_bswap(&mblob->hdr);
le32_to_cpus(&mblob->resource_id);
le64_to_cpus(&mblob->offset);
}
static inline void
virtio_gpu_unmap_blob_bswap(struct virtio_gpu_resource_unmap_blob *ublob)
{
virtio_gpu_ctrl_hdr_bswap(&ublob->hdr);
le32_to_cpus(&ublob->resource_id);
}
static inline void
virtio_gpu_scanout_blob_bswap(struct virtio_gpu_set_scanout_blob *ssb)
{
+30 -8
View File
@@ -55,6 +55,9 @@ struct virtio_gpu_simple_resource {
int dmabuf_fd;
uint8_t *remapped;
MemoryRegion region;
void *mapped;
QTAILQ_ENTRY(virtio_gpu_simple_resource) next;
};
@@ -90,6 +93,8 @@ enum virtio_gpu_base_conf_flags {
VIRTIO_GPU_FLAG_EDID_ENABLED,
VIRTIO_GPU_FLAG_DMABUF_ENABLED,
VIRTIO_GPU_FLAG_BLOB_ENABLED,
VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED,
VIRTIO_GPU_FLAG_RUTABAGA_ENABLED,
};
#define virtio_gpu_virgl_enabled(_cfg) \
@@ -102,12 +107,19 @@ enum virtio_gpu_base_conf_flags {
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED))
#define virtio_gpu_blob_enabled(_cfg) \
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED))
#define virtio_gpu_rutabaga_enabled(_cfg) \
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_RUTABAGA_ENABLED))
#define virtio_gpu_hostmem_enabled(_cfg) \
(_cfg.hostmem > 0)
#define virtio_gpu_context_init_enabled(_cfg) \
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED))
struct virtio_gpu_base_conf {
uint32_t max_outputs;
uint32_t flags;
uint32_t xres;
uint32_t yres;
uint64_t hostmem;
};
struct virtio_gpu_ctrl_command {
@@ -131,6 +143,8 @@ struct VirtIOGPUBase {
int renderer_blocked;
int enable;
MemoryRegion hostmem;
struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS];
int enabled_output_bitmask;
@@ -206,6 +220,12 @@ struct VirtIOGPUGL {
bool renderer_inited;
bool renderer_reset;
char *capset_names;
char *wayland_socket_path;
uint32_t num_capsets;
void *rutabaga;
AioContext *ctx;
};
struct VhostUserGPU {
@@ -240,6 +260,9 @@ void virtio_gpu_base_fill_display_info(VirtIOGPUBase *g,
struct virtio_gpu_resp_display_info *dpy_info);
/* virtio-gpu.c */
struct virtio_gpu_simple_resource *
virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id);
void virtio_gpu_ctrl_response(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd,
struct virtio_gpu_ctrl_hdr *resp,
@@ -258,6 +281,8 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g,
uint32_t *niov);
void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g,
struct iovec *iov, uint32_t count);
void virtio_gpu_cleanup_mapping(VirtIOGPU *g,
struct virtio_gpu_simple_resource *res);
void virtio_gpu_process_cmdq(VirtIOGPU *g);
void virtio_gpu_device_realize(DeviceState *qdev, Error **errp);
void virtio_gpu_reset(VirtIODevice *vdev);
@@ -276,13 +301,10 @@ int virtio_gpu_update_dmabuf(VirtIOGPU *g,
struct virtio_gpu_framebuffer *fb,
struct virtio_gpu_rect *r);
/* virtio-gpu-3d.c */
void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd);
void virtio_gpu_virgl_fence_poll(VirtIOGPU *g);
void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g);
void virtio_gpu_virgl_reset(VirtIOGPU *g);
int virtio_gpu_virgl_init(VirtIOGPU *g);
int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g);
/* virtio-gpu-virgl.c or virtio-gpu-virgl-stubs.c */
void virtio_gpu_virgl_device_realize(DeviceState *qdev, Error **errp);
/* virtio-gpu-rutabaga.c or virtio-gpu-rutabaga-stubs.c */
void virtio_gpu_rutabaga_device_realize(DeviceState *qdev, Error **errp);
#endif
+4
View File
@@ -264,4 +264,8 @@ unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues);
void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueue *vq,
int n, bool assign,
bool with_irqfd);
int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, uint8_t bar, uint64_t offset,
uint64_t length, uint8_t id);
#endif
+1 -21
View File
@@ -720,30 +720,10 @@ int qemu_msync(void *addr, size_t length, int fd);
*/
size_t qemu_get_host_physmem(void);
/*
* Toggle write/execute on the pages marked MAP_JIT
* for the current thread.
*/
#if defined(MAC_OS_VERSION_11_0) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
static inline void qemu_thread_jit_execute(void)
{
pthread_jit_write_protect_np(true);
}
static inline void qemu_thread_jit_write(void)
{
pthread_jit_write_protect_np(false);
}
#else
static inline void qemu_thread_jit_write(void) {}
static inline void qemu_thread_jit_execute(void) {}
#endif
/**
* Platforms which do not support system() return ENOSYS
*/
#ifndef HAVE_SYSTEM_FUNCTION
#if !defined(HAVE_SYSTEM_FUNCTION) || defined(CONFIG_IOS)
#define system platform_does_not_support_system
static inline int platform_does_not_support_system(const char *command)
{
+9
View File
@@ -28,6 +28,15 @@ extern bool hvf_allowed;
#define hvf_get_supported_cpuid(func, idx, reg) 0
#endif /* !CONFIG_HVF */
void *hvf_gpa2hva(uint64_t gpa, bool *found);
int hvf_hva2gpa(void *hva, uint64_t length, int max,
uint64_t *gpa, uint64_t *size);
int hvf_map_safe(void *hva, uint64_t gpa, uint64_t size, uint64_t flags);
int hvf_unmap_safe(uint64_t gpa, uint64_t size);
int hvf_protect_safe(uint64_t gpa, uint64_t size, uint64_t flags);
int hvf_remap_safe(void *hva, uint64_t gpa, uint64_t size, uint64_t flags);
#endif /* NEED_CPU_H */
#define TYPE_HVF_ACCEL ACCEL_CLASS_NAME("hvf")
+13 -1
View File
@@ -17,6 +17,15 @@
#include <Hypervisor/hv.h>
#endif
#if defined(CONFIG_HVF_PRIVATE) && defined(__aarch64__)
extern hv_return_t _hv_vm_config_set_isa(hv_vm_config_t config, uint32_t isa);
extern hv_return_t _hv_vcpu_get_actlr(hv_vcpu_t vcpu, uint64_t* value);
extern hv_return_t _hv_vcpu_set_actlr(hv_vcpu_t vcpu, uint64_t value);
#define HV_VM_CONFIG_ISA_PRIVATE (3)
#define ACTLR_EL1_TSO_ENABLE_MASK ((1 << 1) | (1 << 9))
#endif
/* hvf_slot flags */
#define HVF_SLOT_LOG (1 << 0)
@@ -26,7 +35,6 @@ typedef struct hvf_slot {
uint8_t *mem;
int slot_id;
uint32_t flags;
MemoryRegion *region;
} hvf_slot;
typedef struct hvf_vcpu_caps {
@@ -45,6 +53,9 @@ struct HVFState {
hvf_vcpu_caps *hvf_caps;
uint64_t vtimer_offset;
#if defined(CONFIG_HVF_PRIVATE) && defined(__aarch64__)
bool tso_mode;
#endif
};
extern HVFState *hvf_state;
@@ -56,6 +67,7 @@ struct hvf_vcpu_state {
};
void assert_hvf_ok(hv_return_t ret);
hv_return_t hvf_arch_vm_create(HVFState *s);
int hvf_arch_init(void);
int hvf_arch_init_vcpu(CPUState *cpu);
void hvf_arch_vcpu_destroy(CPUState *cpu);
+100
View File
@@ -0,0 +1,100 @@
/*
* Apple Silicon functions for JIT handling
*
* Copyright (c) 2020 osy
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TCG_APPLE_JIT_H
#define TCG_APPLE_JIT_H
/*
* APRR handling
* Credits to: https://siguza.github.io/APRR/
* Reversed from /usr/lib/system/libsystem_pthread.dylib
*/
#if defined(__aarch64__) && defined(CONFIG_DARWIN)
#define _COMM_PAGE_START_ADDRESS (0x0000000FFFFFC000ULL) /* In TTBR0 */
#define _COMM_PAGE_APRR_SUPPORT (_COMM_PAGE_START_ADDRESS + 0x10C)
#define _COMM_PAGE_APPR_WRITE_ENABLE (_COMM_PAGE_START_ADDRESS + 0x110)
#define _COMM_PAGE_APRR_WRITE_DISABLE (_COMM_PAGE_START_ADDRESS + 0x118)
static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)
{
/* Access shared kernel page at fixed memory location. */
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
return aprr_support > 0;
}
/* write protect enable = write disable */
static __attribute__((__always_inline__)) void jit_write_protect(int enabled)
{
/* Access shared kernel page at fixed memory location. */
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
if (aprr_support == 0 || aprr_support > 3) {
return;
} else if (aprr_support == 1) {
__asm__ __volatile__ (
"mov x0, %0\n"
"ldr x0, [x0]\n"
"msr S3_4_c15_c2_7, x0\n"
"isb sy\n"
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE
: _COMM_PAGE_APPR_WRITE_ENABLE)
: "memory", "x0"
);
} else {
__asm__ __volatile__ (
"mov x0, %0\n"
"ldr x0, [x0]\n"
"msr S3_6_c15_c1_5, x0\n"
"isb sy\n"
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE
: _COMM_PAGE_APPR_WRITE_ENABLE)
: "memory", "x0"
);
}
}
#else /* defined(__aarch64__) && defined(CONFIG_DARWIN) */
static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)
{
return false;
}
static __attribute__((__always_inline__)) void jit_write_protect(int enabled)
{
}
#endif
static inline void qemu_thread_jit_execute(void)
{
if (jit_write_protect_supported()) {
jit_write_protect(true);
}
}
static inline void qemu_thread_jit_write(void)
{
if (jit_write_protect_supported()) {
jit_write_protect(false);
}
}
#endif /* define TCG_APPLE_JIT_H */
+4
View File
@@ -194,7 +194,11 @@ DEF(insn_start, 0, 0, TLADDR_ARGS * TARGET_INSN_START_WORDS,
TCG_OPF_NOT_PRESENT)
DEF(exit_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
DEF(goto_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
#if defined(CONFIG_TCG_THREADED_INTERPRETER)
DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END | TCG_OPF_NOT_PRESENT)
#else
DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
#endif
DEF(plugin_cb_start, 0, 0, 3, TCG_OPF_NOT_PRESENT)
DEF(plugin_cb_end, 0, 0, 0, TCG_OPF_NOT_PRESENT)
+1 -1
View File
@@ -1158,7 +1158,7 @@ static inline size_t tcg_current_code_size(TCGContext *s)
#define TB_EXIT_IDXMAX 1
#define TB_EXIT_REQUESTED 3
#ifdef CONFIG_TCG_INTERPRETER
#if defined(CONFIG_TCG_INTERPRETER) || defined(CONFIG_TCG_THREADED_INTERPRETER)
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, const void *tb_ptr);
#else
typedef uintptr_t tcg_prologue_fn(CPUArchState *env, const void *tb_ptr);
+10 -11
View File
@@ -93,7 +93,6 @@ bool qemu_mouse_set(int index, Error **errp);
void kbd_put_keysym_console(QemuConsole *s, int keysym);
bool kbd_put_qcode_console(QemuConsole *s, int qcode, bool ctrl);
void kbd_put_string_console(QemuConsole *s, const char *str, int len);
void kbd_put_keysym(int keysym);
/* consoles */
@@ -108,11 +107,13 @@ struct QemuConsoleClass {
#define QEMU_ALLOCATED_FLAG 0x01
#define QEMU_PLACEHOLDER_FLAG 0x02
typedef uint32_t (* DisplayGLTextureBorrower)(uint32_t id, bool *y_0_top,
uint32_t *width,
uint32_t *height);
typedef struct ScanoutTexture {
uint32_t backing_id;
bool backing_y_0_top;
uint32_t backing_width;
uint32_t backing_height;
DisplayGLTextureBorrower backing_borrow;
uint32_t x;
uint32_t y;
uint32_t width;
@@ -127,6 +128,7 @@ typedef struct DisplaySurface {
GLenum glformat;
GLenum gltype;
GLuint texture;
bool glswapped;
#endif
} DisplaySurface;
@@ -247,9 +249,7 @@ typedef struct DisplayChangeListenerOps {
/* required if GL */
void (*dpy_gl_scanout_texture)(DisplayChangeListener *dcl,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h);
/* optional (default to true if has dpy_gl_scanout_dmabuf) */
@@ -352,9 +352,8 @@ bool dpy_gfx_check_format(QemuConsole *con,
pixman_format_code_t format);
void dpy_gl_scanout_disable(QemuConsole *con);
void dpy_gl_scanout_texture(QemuConsole *con,
uint32_t backing_id, bool backing_y_0_top,
uint32_t backing_width, uint32_t backing_height,
void dpy_gl_scanout_texture(QemuConsole *con, uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
void dpy_gl_scanout_dmabuf(QemuConsole *con,
QemuDmaBuf *dmabuf);
@@ -454,6 +453,7 @@ void qemu_console_early_init(void);
void qemu_console_set_display_gl_ctx(QemuConsole *con, DisplayGLCtx *ctx);
QemuConsole *qemu_console_lookup_first_graphic_console(void);
QemuConsole *qemu_console_lookup_by_index(unsigned int index);
QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
@@ -475,7 +475,6 @@ int qemu_console_get_window_id(QemuConsole *con);
/* Set the low-level window id for the console */
void qemu_console_set_window_id(QemuConsole *con, int window_id);
void console_select(unsigned int index);
void qemu_console_resize(QemuConsole *con, int width, int height);
DisplaySurface *qemu_console_surface(QemuConsole *con);
+22 -3
View File
@@ -6,6 +6,9 @@
#ifdef CONFIG_GBM
#include <gbm.h>
#endif
#ifdef CONFIG_ANGLE
#include <EGL/eglext_angle.h>
#endif
#include "ui/console.h"
#include "ui/shader.h"
@@ -17,6 +20,7 @@ typedef struct egl_fb {
int width;
int height;
GLuint texture;
GLenum texture_target;
GLuint framebuffer;
bool delete_texture;
QemuDmaBuf *dmabuf;
@@ -26,15 +30,18 @@ typedef struct egl_fb {
void egl_fb_destroy(egl_fb *fb);
void egl_fb_setup_default(egl_fb *fb, int width, int height);
void egl_fb_setup_for_tex_target(egl_fb *fb, int width, int height,
GLuint texture, GLenum target, bool delete);
void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,
GLuint texture, bool delete);
void egl_fb_setup_new_tex_target(egl_fb *fb, int width, int height, GLenum target);
void egl_fb_setup_new_tex(egl_fb *fb, int width, int height);
void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip);
void egl_fb_read(DisplaySurface *dst, egl_fb *src);
void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip);
void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip, bool swap);
void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
int x, int y, double scale_x, double scale_y);
bool swap, int x, int y, double scale_x, double scale_y);
#ifdef CONFIG_GBM
@@ -53,7 +60,13 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf);
#endif
EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win);
EGLSurface qemu_egl_init_surface(EGLContext ectx, EGLNativeWindowType win);
EGLSurface qemu_egl_init_buffer_surface(EGLContext ectx, EGLenum buftype,
EGLClientBuffer buffer, const EGLint *attrib_list);
bool qemu_egl_destroy_surface(EGLSurface surface);
int qemu_egl_init_dpy_cocoa(DisplayGLMode mode);
int qemu_egl_init_dpy_surfaceless(DisplayGLMode mode);
#if defined(CONFIG_X11) || defined(CONFIG_GBM)
@@ -62,6 +75,12 @@ int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode);
#endif
#if defined(CONFIG_ANGLE)
int qemu_egl_init_dpy_angle(DisplayGLMode mode);
#endif
EGLContext qemu_egl_init_ctx(void);
bool qemu_egl_has_dmabuf(void);
+2 -6
View File
@@ -171,9 +171,7 @@ QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc,
void gd_egl_scanout_disable(DisplayChangeListener *dcl);
void gd_egl_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h);
void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
@@ -207,9 +205,7 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
QemuDmaBuf *dmabuf);
void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h);
void gd_gl_area_scanout_disable(DisplayChangeListener *dcl);
+3 -5
View File
@@ -22,7 +22,7 @@
#endif
#include "ui/kbd-state.h"
#ifdef CONFIG_OPENGL
#if defined(CONFIG_OPENGL)
# include "ui/egl-helpers.h"
#endif
@@ -44,7 +44,7 @@ struct sdl2_console {
int ignore_hotkeys;
SDL_GLContext winctx;
QKbdState *kbd;
#ifdef CONFIG_OPENGL
#if defined(CONFIG_OPENGL)
QemuGLShader *gls;
egl_fb guest_fb;
egl_fb win_fb;
@@ -86,9 +86,7 @@ int sdl2_gl_make_context_current(DisplayGLCtx *dgc,
void sdl2_gl_scanout_disable(DisplayChangeListener *dcl);
void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h);
void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
+1 -1
View File
@@ -5,7 +5,7 @@
typedef struct QemuGLShader QemuGLShader;
void qemu_gl_run_texture_blit(QemuGLShader *gls, bool flip);
void qemu_gl_run_texture_blit(QemuGLShader *gls, bool flip, bool swapped);
QemuGLShader *qemu_gl_init_shader(void);
void qemu_gl_fini_shader(QemuGLShader *gls);
+18 -1
View File
@@ -27,7 +27,12 @@
#include "ui/qemu-pixman.h"
#include "ui/console.h"
#if defined(CONFIG_OPENGL) && defined(CONFIG_GBM)
#if defined(CONFIG_IOSURFACE)
#include <CoreFoundation/CoreFoundation.h>
#include <IOSurface/IOSurfaceRef.h>
#endif
#if defined(CONFIG_OPENGL)
# define HAVE_SPICE_GL 1
# include "ui/egl-helpers.h"
# include "ui/egl-context.h"
@@ -125,8 +130,20 @@ struct SimpleSpiceDisplay {
bool have_scanout;
bool have_surface;
#if defined(CONFIG_GBM)
QemuDmaBuf *guest_dmabuf;
bool guest_dmabuf_refresh;
#endif
#if defined(CONFIG_IOSURFACE)
IOSurfaceRef iosurface;
int surface_send_fd;
#endif
#if defined(CONFIG_ANGLE)
EGLSurface esurface;
egl_fb iosurface_fb;
DisplayGLTextureBorrower backing_borrow;
uint32_t backing_id;
#endif
bool render_cursor;
egl_fb guest_fb;
+161 -8
View File
@@ -30,7 +30,7 @@ if add_languages('cpp', required: false, native: false)
cxx = meson.get_compiler('cpp')
endif
if targetos == 'darwin' and \
add_languages('objc', required: get_option('cocoa'), native: false)
add_languages('objc', required: false, native: false)
all_languages += ['objc']
objc = meson.get_compiler('objc')
endif
@@ -62,6 +62,7 @@ bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin
supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv', 'x86', 'x86_64',
'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64']
tcti_supported_cpus = ['aarch64']
cpu = host_machine.cpu_family()
@@ -292,6 +293,10 @@ add_project_arguments('-iquote', '.',
'-iquote', meson.current_source_dir() / 'include',
language: all_languages)
if targetos == 'darwin'
add_project_link_arguments(['-fvisibility-inlines-hidden', '-Xlinker', '-no_deduplicate'], native: false, language: all_languages)
endif
sparse = find_program('cgcc', required: get_option('sparse'))
if sparse.found()
run_target('sparse',
@@ -378,6 +383,7 @@ socket = []
version_res = []
coref = []
iokit = []
iosurface = not_found
emulator_link_args = []
nvmm =not_found
hvf = not_found
@@ -400,6 +406,7 @@ if targetos == 'windows'
elif targetos == 'darwin'
coref = dependency('appleframeworks', modules: 'CoreFoundation')
iokit = dependency('appleframeworks', modules: 'IOKit', required: false)
iosurface = dependency('appleframeworks', modules: 'IOSurface', required: false)
host_dsosuf = '.dylib'
elif targetos == 'sunos'
socket = [cc.find_library('socket'),
@@ -434,6 +441,7 @@ if get_option('hvf').allowed()
required: get_option('hvf'))
if hvf.found()
accelerators += 'CONFIG_HVF'
config_host_data.set('CONFIG_HVF_PRIVATE', get_option('hvf_private'))
endif
endif
if get_option('hax').allowed()
@@ -448,6 +456,8 @@ if targetos == 'netbsd'
endif
endif
tcti_gadgets = files()
tcg_arch = host_arch
if get_option('tcg').allowed()
if host_arch == 'unknown'
@@ -467,6 +477,89 @@ if get_option('tcg').allowed()
if get_option('tcg_interpreter')
tcg_arch = 'tci'
config_host += { 'CONFIG_TCG_INTERPRETER': 'y' }
elif get_option('tcg_threaded_interpreter')
if cpu not in tcti_supported_cpus
error('Unsupported CPU @0@ for TCTI, try --enable-tcg-interpreter'.format(cpu))
else
warning('TCTI is extremely experimental and incomplete! Things might break!')
tcg_arch = '@0@-tcti'.format(cpu)
endif
config_host += { 'CONFIG_TCG_THREADED_INTERPRETER': 'y' }
# Tell our compiler how to generate our TCTI gadgets.
gadget_generator = 'tcg/@0@/tcti-gadget-gen.py'.format(tcg_arch)
tcti_sources = [
'tcti_gadgets.h',
'tcti_misc_gadgets.c',
'tcti_misc_gadgets.h',
'tcti_setcond_gadgets.c',
'tcti_setcond_gadgets.h',
'tcti_brcond_gadgets.c',
'tcti_brcond_gadgets.h',
'tcti_mov_gadgets.c',
'tcti_mov_gadgets.h',
'tcti_load_signed_gadgets.c',
'tcti_load_signed_gadgets.h',
'tcti_load_unsigned_gadgets.c',
'tcti_load_unsigned_gadgets.h',
'tcti_store_gadgets.c',
'tcti_store_gadgets.h',
'tcti_arithmetic_gadgets.c',
'tcti_arithmetic_gadgets.h',
'tcti_logical_gadgets.c',
'tcti_logical_gadgets.h',
'tcti_extension_gadgets.c',
'tcti_extension_gadgets.h',
'tcti_bitwise_gadgets.c',
'tcti_bitwise_gadgets.h',
'tcti_byteswap_gadgets.c',
'tcti_byteswap_gadgets.h',
'tcti_qemu_ld_aligned_signed_le_gadgets.c',
'tcti_qemu_ld_aligned_signed_le_gadgets.h',
'tcti_qemu_ld_unaligned_signed_le_gadgets.c',
'tcti_qemu_ld_unaligned_signed_le_gadgets.h',
'tcti_qemu_ld_slowpath_signed_le_gadgets.c',
'tcti_qemu_ld_slowpath_signed_le_gadgets.h',
'tcti_qemu_ld_aligned_unsigned_le_gadgets.c',
'tcti_qemu_ld_aligned_unsigned_le_gadgets.h',
'tcti_qemu_ld_unaligned_unsigned_le_gadgets.c',
'tcti_qemu_ld_unaligned_unsigned_le_gadgets.h',
'tcti_qemu_ld_slowpath_unsigned_le_gadgets.c',
'tcti_qemu_ld_slowpath_unsigned_le_gadgets.h',
'tcti_qemu_ld_aligned_be_gadgets.c',
'tcti_qemu_ld_aligned_be_gadgets.h',
'tcti_qemu_ld_unaligned_be_gadgets.c',
'tcti_qemu_ld_unaligned_be_gadgets.h',
'tcti_qemu_ld_slowpath_be_gadgets.c',
'tcti_qemu_ld_slowpath_be_gadgets.h',
'tcti_qemu_st_aligned_le_gadgets.c',
'tcti_qemu_st_aligned_le_gadgets.h',
'tcti_qemu_st_unaligned_le_gadgets.c',
'tcti_qemu_st_unaligned_le_gadgets.h',
'tcti_qemu_st_slowpath_le_gadgets.c',
'tcti_qemu_st_slowpath_le_gadgets.h',
'tcti_qemu_st_aligned_be_gadgets.c',
'tcti_qemu_st_aligned_be_gadgets.h',
'tcti_qemu_st_unaligned_be_gadgets.c',
'tcti_qemu_st_unaligned_be_gadgets.h',
'tcti_qemu_st_slowpath_be_gadgets.c',
'tcti_qemu_st_slowpath_be_gadgets.h',
'tcti_simd_base_gadgets.c',
'tcti_simd_base_gadgets.h',
'tcti_simd_arithmetic_gadgets.c',
'tcti_simd_arithmetic_gadgets.h',
'tcti_simd_logical_gadgets.c',
'tcti_simd_logical_gadgets.h',
'tcti_simd_immediate_gadgets.c',
'tcti_simd_immediate_gadgets.h',
]
tcti_gadgets = custom_target('tcti-gadgets.h',
output: tcti_sources,
input: gadget_generator,
command: [find_program(gadget_generator)],
build_by_default: true,
build_always_stale: false)
elif host_arch == 'x86_64'
tcg_arch = 'i386'
elif host_arch == 'ppc64'
@@ -777,6 +870,13 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu
required: get_option('virglrenderer'),
kwargs: static_kwargs)
endif
rutabaga = not_found
if not get_option('rutabaga_gfx').auto() or have_system or have_vhost_user_gpu
rutabaga = dependency('rutabaga_gfx_ffi',
method: 'pkg-config',
required: get_option('rutabaga_gfx'),
kwargs: static_kwargs)
endif
blkio = not_found
if not get_option('blkio').auto() or have_block
blkio = dependency('blkio',
@@ -1931,6 +2031,7 @@ config_host_data.set('CONFIG_SPICE', spice.found())
config_host_data.set('CONFIG_X11', x11.found())
config_host_data.set('CONFIG_DBUS_DISPLAY', dbus_display)
config_host_data.set('CONFIG_CFI', get_option('cfi'))
config_host_data.set('CONFIG_IOSURFACE', iosurface.found())
config_host_data.set('CONFIG_SELINUX', selinux.found())
config_host_data.set('CONFIG_XEN_BACKEND', xen.found())
config_host_data.set('CONFIG_LIBDW', libdw.found())
@@ -1973,6 +2074,7 @@ config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h'))
config_host_data.set('HAVE_SYS_DISK_H', cc.has_header('sys/disk.h'))
config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h'))
config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h'))
config_host_data.set('CONFIG_ANGLE', cc.has_header('EGL/eglext_angle.h'))
if targetos == 'windows'
config_host_data.set('HAVE_AFUNIX_H', cc.has_header('afunix.h'))
endif
@@ -2813,9 +2915,18 @@ if not fdt.found() and fdt_required.length() > 0
error('fdt not available but required by targets ' + ', '.join(fdt_required))
endif
ucontext = dependency('libucontext', kwargs: static_kwargs, required : false)
if not ucontext.found() and get_option('ucontext').enabled()
libucontext_proj = subproject('libucontext',
default_options: ['default_library=static',
'freestanding=true'])
ucontext = libucontext_proj.get_variable('libucontext_dep')
endif
config_host_data.set('CONFIG_CAPSTONE', capstone.found())
config_host_data.set('CONFIG_FDT', fdt.found())
config_host_data.set('CONFIG_SLIRP', slirp.found())
config_host_data.set('CONFIG_LIBUCONTEXT', ucontext.found())
#####################
# Generated sources #
@@ -3096,7 +3207,7 @@ util_ss.add_all(trace_ss)
util_ss = util_ss.apply(config_all, strict: false)
libqemuutil = static_library('qemuutil',
sources: util_ss.sources() + stub_ss.sources() + genh,
dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman])
dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman, ucontext])
qemuutil = declare_dependency(link_with: libqemuutil,
sources: genh + version_res,
dependencies: [event_loop_base])
@@ -3170,6 +3281,11 @@ if get_option('b_lto')
endif
common_ss.add(pagevary)
specific_ss.add(files('page-vary.c'))
specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('tcg/tci.c'))
# FIXME: This is being used for now for development quickness, but these realy should be
# added to a gadget-specific shared library (tcti_ss).
specific_ss.add(when: 'CONFIG_TCG_THREADED_INTERPRETER', if_true: tcti_gadgets)
subdir('backends')
subdir('disas')
@@ -3511,14 +3627,32 @@ foreach target : target_dirs
arch_srcs += target_specific.sources()
arch_deps += target_specific.dependencies()
lib = static_library('qemu-' + target,
if config_all.has_key('CONFIG_SHARED_LIBRARY_BUILD')
build_lib_args = {
'target_type': 'shared_library',
'install': true,
'dependencies': arch_deps + deps,
'link_language': link_language,
'link_depends': [block_syms, qemu_syms],
'link_args': link_args + cc.get_supported_link_arguments(['-Wl,-U,_qemu_main']),
'gnu_symbol_visibility': 'default'
}
else
build_lib_args = {
'target_type': 'static_library',
'install': false,
'dependencies': arch_deps,
'name_suffix': 'fa'
}
endif
lib = build_target('qemu-' + target,
sources: arch_srcs + genh,
dependencies: arch_deps,
objects: objects,
include_directories: target_inc,
c_args: c_args,
build_by_default: false,
name_suffix: 'fa')
kwargs: build_lib_args)
if target.endswith('-softmmu')
execs = [{
@@ -3552,6 +3686,17 @@ foreach target : target_dirs
'dependencies': []
}]
endif
if config_all.has_key('CONFIG_SHARED_LIBRARY_BUILD')
build_exe_args = {
'link_with': lib,
'link_args': link_args + cc.get_supported_link_arguments(['-Wl,--exclude-libs,ALL'])
}
else
build_exe_args = {
'objects': lib.extract_all_objects(recursive: true),
'link_args': link_args
}
endif
foreach exe: execs
exe_name = exe['name']
if targetos == 'darwin'
@@ -3562,11 +3707,10 @@ foreach target : target_dirs
install: true,
c_args: c_args,
dependencies: arch_deps + deps + exe['dependencies'],
objects: lib.extract_all_objects(recursive: true),
link_language: link_language,
link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []),
link_args: link_args,
win_subsystem: exe['win_subsystem'])
win_subsystem: exe['win_subsystem'],
kwargs: build_exe_args)
if targetos == 'darwin'
icon = 'pc-bios/qemu.rsrc'
@@ -3637,6 +3781,10 @@ if xkbcommon.found()
endif
if have_tools
if config_all.has_key('CONFIG_SHARED_LIBRARY_BUILD')
qemu_img_lib = shared_library('qemu-img', [files('qemu-img.c'), hxdep],
dependencies: [authz, block, crypto, io, qom, qemuutil], install: true)
endif
qemu_img = executable('qemu-img', [files('qemu-img.c'), hxdep],
dependencies: [authz, block, crypto, io, qom, qemuutil], install: true)
qemu_io = executable('qemu-io', files('qemu-io.c'),
@@ -3738,6 +3886,7 @@ endif
summary_info += {'Doc directory': get_option('prefix') / get_option('docdir')}
summary_info += {'Build directory': meson.current_build_dir()}
summary_info += {'Source path': meson.current_source_dir()}
summary_info += {'build shared lib': config_all.has_key('CONFIG_SHARED_LIBRARY_BUILD')}
summary_info += {'GIT submodules': config_host['GIT_SUBMODULES']}
summary(summary_info, bool_yn: true, section: 'Directories')
@@ -3891,6 +4040,8 @@ summary_info += {'TCG support': config_all.has_key('CONFIG_TCG')}
if config_all.has_key('CONFIG_TCG')
if get_option('tcg_interpreter')
summary_info += {'TCG backend': 'TCI (TCG with bytecode interpreter, slow)'}
elif get_option('tcg_threaded_interpreter')
summary_info += {'TCG backend': 'TCTI (TCG with threaded-dispatch bytecode interpreter, experimental and slow; but faster than TCI)'}
else
summary_info += {'TCG backend': 'native (@0@)'.format(cpu)}
endif
@@ -3907,6 +4058,7 @@ summary(summary_info, bool_yn: true, section: 'Targets and accelerators')
# Block layer
summary_info = {}
summary_info += {'libucontext support': ucontext.found()}
summary_info += {'coroutine backend': config_host['CONFIG_COROUTINE_BACKEND']}
summary_info += {'coroutine pool': have_coroutine_pool}
if have_block
@@ -3963,6 +4115,7 @@ summary_info += {'PAM': pam}
summary_info += {'iconv support': iconv}
summary_info += {'curses support': curses}
summary_info += {'virgl support': virgl}
summary_info += {'rutabaga support': rutabaga}
summary_info += {'blkio support': blkio}
summary_info += {'curl support': curl}
summary_info += {'Multipath support': mpathpersist}
+8
View File
@@ -72,6 +72,8 @@ option('whpx', type: 'feature', value: 'auto',
description: 'WHPX acceleration support')
option('hvf', type: 'feature', value: 'auto',
description: 'HVF acceleration support')
option('hvf_private', type: 'boolean', value: 'false',
description: 'HVF private features (entitlements required)')
option('nvmm', type: 'feature', value: 'auto',
description: 'NVMM acceleration support')
option('xen', type: 'feature', value: 'auto',
@@ -82,6 +84,8 @@ option('tcg', type: 'feature', value: 'enabled',
description: 'TCG support')
option('tcg_interpreter', type: 'boolean', value: false,
description: 'TCG with bytecode interpreter (slow)')
option('tcg_threaded_interpreter', type: 'boolean', value: false,
description: 'TCG with threaded-dispatch bytecode interpreter (experimental and slow, but less slow than TCI)')
option('cfi', type: 'boolean', value: false,
description: 'Control-Flow Integrity (CFI)')
option('cfi_debug', type: 'boolean', value: false,
@@ -213,6 +217,8 @@ option('vmnet', type : 'feature', value : 'auto',
description: 'vmnet.framework network backend support')
option('virglrenderer', type : 'feature', value : 'auto',
description: 'virgl rendering support')
option('rutabaga_gfx', type : 'feature', value : 'auto',
description: 'rutabaga_gfx support')
option('png', type : 'feature', value : 'auto',
description: 'PNG support with libpng')
option('vnc', type : 'feature', value : 'auto',
@@ -238,6 +244,8 @@ option('fuse', type: 'feature', value: 'auto',
description: 'FUSE block device export')
option('fuse_lseek', type : 'feature', value : 'auto',
description: 'SEEK_HOLE/SEEK_DATA support for FUSE exports')
option('ucontext', type : 'feature', value : 'disabled',
description: 'libucontext support')
option('trace_backends', type: 'array', value: ['log'],
choices: ['dtrace', 'ftrace', 'log', 'nop', 'simple', 'syslog', 'ust'],
+15 -14
View File
@@ -88,15 +88,16 @@ static bool validate_options(const Netdev *netdev, Error **errp)
return false;
}
#if !defined(MAC_OS_VERSION_11_0) || \
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_11_0
if (options->has_isolated) {
error_setg(errp,
"vmnet-bridged.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
if (__builtin_available(macOS 11, *)) {
// clang requires a true branch
} else {
if (options->has_isolated) {
error_setg(errp,
"vmnet-bridged.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
}
#endif
return true;
}
@@ -115,12 +116,12 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
vmnet_shared_interface_name_key,
options->ifname);
#if defined(MAC_OS_VERSION_11_0) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
#endif
if (__builtin_available(macOS 11, *)) {
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
}
return if_desc;
}
+31 -35
View File
@@ -22,30 +22,28 @@ static bool validate_options(const Netdev *netdev, Error **errp)
{
const NetdevVmnetHostOptions *options = &(netdev->u.vmnet_host);
#if defined(MAC_OS_VERSION_11_0) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
if (__builtin_available(macOS 11, *)) {
QemuUUID net_uuid;
if (options->net_uuid &&
qemu_uuid_parse(options->net_uuid, &net_uuid) < 0) {
error_setg(errp, "Invalid UUID provided in 'net-uuid'");
return false;
}
} else {
if (options->has_isolated) {
error_setg(errp,
"vmnet-host.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
QemuUUID net_uuid;
if (options->net_uuid &&
qemu_uuid_parse(options->net_uuid, &net_uuid) < 0) {
error_setg(errp, "Invalid UUID provided in 'net-uuid'");
return false;
if (options->net_uuid) {
error_setg(errp,
"vmnet-host.net-uuid feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
}
#else
if (options->has_isolated) {
error_setg(errp,
"vmnet-host.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
if (options->net_uuid) {
error_setg(errp,
"vmnet-host.net-uuid feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
#endif
if ((options->start_address ||
options->end_address ||
@@ -71,21 +69,19 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
vmnet_operation_mode_key,
VMNET_HOST_MODE);
#if defined(MAC_OS_VERSION_11_0) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
if (__builtin_available(macOS 11, *)) {
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
QemuUUID net_uuid;
if (options->net_uuid) {
qemu_uuid_parse(options->net_uuid, &net_uuid);
xpc_dictionary_set_uuid(if_desc,
vmnet_network_identifier_key,
net_uuid.data);
QemuUUID net_uuid;
if (options->net_uuid) {
qemu_uuid_parse(options->net_uuid, &net_uuid);
xpc_dictionary_set_uuid(if_desc,
vmnet_network_identifier_key,
net_uuid.data);
}
}
#endif
if (options->start_address) {
xpc_dictionary_set_string(if_desc,
+16 -16
View File
@@ -21,15 +21,16 @@ static bool validate_options(const Netdev *netdev, Error **errp)
{
const NetdevVmnetSharedOptions *options = &(netdev->u.vmnet_shared);
#if !defined(MAC_OS_VERSION_11_0) || \
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_11_0
if (options->has_isolated) {
error_setg(errp,
"vmnet-shared.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
if (__builtin_available(macOS 11, *)) {
// clang requires a true branch
} else {
if (options->has_isolated) {
error_setg(errp,
"vmnet-shared.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
}
#endif
if ((options->start_address ||
options->end_address ||
@@ -76,14 +77,13 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
options->subnet_mask);
}
#if defined(MAC_OS_VERSION_11_0) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
xpc_dictionary_set_bool(
if_desc,
vmnet_enable_isolation_key,
options->isolated
);
#endif
if (__builtin_available(macOS 11, *)) {
xpc_dictionary_set_bool(
if_desc,
vmnet_enable_isolation_key,
options->isolated
);
}
return if_desc;
}
+2 -2
View File
@@ -1384,7 +1384,7 @@
{ 'name': 'gtk', 'if': 'CONFIG_GTK' },
{ 'name': 'sdl', 'if': 'CONFIG_SDL' },
{ 'name': 'egl-headless',
'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } },
'if': 'CONFIG_OPENGL' },
{ 'name': 'curses', 'if': 'CONFIG_CURSES' },
{ 'name': 'cocoa', 'if': 'CONFIG_COCOA' },
{ 'name': 'spice-app', 'if': 'CONFIG_SPICE' },
@@ -1417,7 +1417,7 @@
'cocoa': { 'type': 'DisplayCocoa', 'if': 'CONFIG_COCOA' },
'curses': { 'type': 'DisplayCurses', 'if': 'CONFIG_CURSES' },
'egl-headless': { 'type': 'DisplayEGLHeadless',
'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } },
'if': 'CONFIG_OPENGL' },
'dbus': { 'type': 'DisplayDBus', 'if': 'CONFIG_DBUS_DISPLAY' },
'sdl': { 'type': 'DisplaySDL', 'if': 'CONFIG_SDL' }
}
+14
View File
@@ -29,6 +29,7 @@ meson_options_help() {
printf "%s\n" ' --enable-fuzzing build fuzzing targets'
printf "%s\n" ' --enable-gcov Enable coverage tracking.'
printf "%s\n" ' --enable-gprof QEMU profiling with gprof'
printf "%s\n" ' --enable-hvf-private HVF private features (entitlements required)'
printf "%s\n" ' --enable-lto Use link time optimization'
printf "%s\n" ' --enable-malloc=CHOICE choose memory allocator to use [system] (choices:'
printf "%s\n" ' jemalloc/system/tcmalloc)'
@@ -40,6 +41,9 @@ meson_options_help() {
printf "%s\n" ' getrandom()'
printf "%s\n" ' --enable-strip Strip targets on install'
printf "%s\n" ' --enable-tcg-interpreter TCG with bytecode interpreter (slow)'
printf "%s\n" ' --enable-tcg-threaded-interpreter'
printf "%s\n" ' TCG with threaded-dispatch bytecode interpreter'
printf "%s\n" ' (experimental and slow, but less slow than TCI)'
printf "%s\n" ' --enable-trace-backends=CHOICES'
printf "%s\n" ' Set available tracing backends [log] (choices:'
printf "%s\n" ' dtrace/ftrace/log/nop/simple/syslog/ust)'
@@ -144,6 +148,7 @@ meson_options_help() {
printf "%s\n" ' rbd Ceph block device driver'
printf "%s\n" ' rdma Enable RDMA-based migration'
printf "%s\n" ' replication replication support'
printf "%s\n" ' rutabaga-gfx rutabaga_gfx support'
printf "%s\n" ' sdl SDL user interface'
printf "%s\n" ' sdl-image SDL Image support for icons'
printf "%s\n" ' seccomp seccomp support'
@@ -160,6 +165,7 @@ meson_options_help() {
printf "%s\n" ' tools build support utilities that come with QEMU'
printf "%s\n" ' tpm TPM support'
printf "%s\n" ' u2f U2F emulation support'
printf "%s\n" ' ucontext libucontext support'
printf "%s\n" ' usb-redir libusbredir support'
printf "%s\n" ' vde vde network backend support'
printf "%s\n" ' vdi vdi image format support'
@@ -295,6 +301,8 @@ _meson_option_parse() {
--disable-hexagon-idef-parser) printf "%s" -Dhexagon_idef_parser=false ;;
--enable-hvf) printf "%s" -Dhvf=enabled ;;
--disable-hvf) printf "%s" -Dhvf=disabled ;;
--enable-hvf-private) printf "%s" -Dhvf_private=true ;;
--disable-hvf-private) printf "%s" -Dhvf_private=false ;;
--iasl=*) quote_sh "-Diasl=$2" ;;
--enable-iconv) printf "%s" -Diconv=enabled ;;
--disable-iconv) printf "%s" -Diconv=disabled ;;
@@ -394,6 +402,8 @@ _meson_option_parse() {
--disable-replication) printf "%s" -Dreplication=disabled ;;
--enable-rng-none) printf "%s" -Drng_none=true ;;
--disable-rng-none) printf "%s" -Drng_none=false ;;
--enable-rutabaga-gfx) printf "%s" -Drutabaga_gfx=enabled ;;
--disable-rutabaga-gfx) printf "%s" -Drutabaga_gfx=disabled ;;
--enable-sdl) printf "%s" -Dsdl=enabled ;;
--disable-sdl) printf "%s" -Dsdl=disabled ;;
--enable-sdl-image) printf "%s" -Dsdl_image=enabled ;;
@@ -426,6 +436,8 @@ _meson_option_parse() {
--disable-tcg) printf "%s" -Dtcg=disabled ;;
--enable-tcg-interpreter) printf "%s" -Dtcg_interpreter=true ;;
--disable-tcg-interpreter) printf "%s" -Dtcg_interpreter=false ;;
--enable-tcg-threaded-interpreter) printf "%s" -Dtcg_threaded_interpreter=true ;;
--disable-tcg-threaded-interpreter) printf "%s" -Dtcg_threaded_interpreter=false ;;
--tls-priority=*) quote_sh "-Dtls_priority=$2" ;;
--enable-tools) printf "%s" -Dtools=enabled ;;
--disable-tools) printf "%s" -Dtools=disabled ;;
@@ -435,6 +447,8 @@ _meson_option_parse() {
--with-trace-file=*) quote_sh "-Dtrace_file=$2" ;;
--enable-u2f) printf "%s" -Du2f=enabled ;;
--disable-u2f) printf "%s" -Du2f=disabled ;;
--enable-ucontext) printf "%s" -Ducontext=enabled ;;
--disable-ucontext) printf "%s" -Ducontext=disabled ;;
--enable-usb-redir) printf "%s" -Dusb_redir=enabled ;;
--disable-usb-redir) printf "%s" -Dusb_redir=disabled ;;
--enable-vde) printf "%s" -Dvde=enabled ;;
+17
View File
@@ -1744,6 +1744,23 @@ void memory_region_init_iommu(void *_iommu_mr,
iommu_mr->iommu_notify_flags = IOMMU_NOTIFIER_NONE;
}
void memory_region_init_ram_user_backed(MemoryRegion *mr,
Object *owner,
const char *name,
uint64_t size)
{
DeviceState* owner_dev;
memory_region_init(mr, owner, name, size);
mr->ram = true;
mr->user_backed = true;
mr->terminates = true;
mr->destructor = memory_region_destructor_ram;
mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
mr->ram_block = qemu_ram_alloc_user_backed(size, mr, &error_fatal);
owner_dev = DEVICE(owner);
vmstate_register_ram(mr, owner_dev);
}
static void memory_region_finalize(Object *obj)
{
MemoryRegion *mr = MEMORY_REGION(obj);
+126 -1
View File
@@ -46,6 +46,7 @@
#include "qemu/log.h"
#include "qemu/memalign.h"
#include "exec/memory.h"
#include "exec/memory-remap.h"
#include "exec/ioport.h"
#include "sysemu/dma.h"
#include "sysemu/hostmem.h"
@@ -1789,7 +1790,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
qemu_mutex_lock_ramlist();
new_block->offset = find_ram_offset(new_block->max_length);
if (!new_block->host) {
if (!new_block->host && !(new_block->flags & RAM_USER_BACKED)) {
if (xen_enabled()) {
xen_ram_alloc(new_block->offset, new_block->max_length,
new_block->mr, &err);
@@ -2014,6 +2015,130 @@ RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t maxsz,
RAM_RESIZEABLE, mr, errp);
}
RAMBlock *qemu_ram_alloc_user_backed(ram_addr_t size, MemoryRegion *mr,
Error **errp)
{
RAMBlock *new_block;
Error *local_err = NULL;
size = HOST_PAGE_ALIGN(size);
new_block = (RAMBlock*)g_malloc0(sizeof(*new_block));
new_block->mr = mr;
new_block->used_length = size;
new_block->max_length = size;
new_block->fd = -1;
new_block->page_size = getpagesize();
new_block->host = NULL;
new_block->flags |= RAM_PREALLOC;
new_block->flags |= RAM_USER_BACKED;
ram_block_add(new_block, &local_err);
if (local_err) {
g_free(new_block);
error_propagate(errp, local_err);
return NULL;
}
return new_block;
}
#define TCG_MAX_USER_RAM_SLOTS 1024
struct TcgUserRamSlotInfo {
int used;
MemoryRegion mr;
uint64_t gpa;
};
struct TcgUserRamTable {
struct TcgUserRamSlotInfo slots[TCG_MAX_USER_RAM_SLOTS];
};
static struct TcgUserRamTable* tcg_user_ram_table_get(void) {
static struct TcgUserRamTable* s_table;
if (!s_table) {
struct TcgUserRamTable* table =
(struct TcgUserRamTable*)malloc(sizeof(*table));
memset(table, 0, sizeof(*table));
s_table = table;
}
return s_table;
}
static int tcg_user_ram_slot_infos_first_free_slot() {
struct TcgUserRamTable* table = tcg_user_ram_table_get();
for (int i = 0; i < TCG_MAX_USER_RAM_SLOTS; ++i) {
if (0 == table->slots[i].used) return i;
}
return -1;
}
static void tcg_user_ram_slot_map(
uint64_t gpa, void *hva, uint64_t size, int flags) {
struct TcgUserRamTable* table = tcg_user_ram_table_get();
int slot = tcg_user_ram_slot_infos_first_free_slot();
MemoryRegion* mr = &(table->slots[slot].mr);
if (slot < 0) {
fprintf(stderr, "%s: error: no free slots to "
"map hva %p -> gpa [0x%llx 0x%llx)\n", __func__,
hva, (unsigned long long)gpa, (unsigned long long)gpa + size);
return;
}
memory_region_init_ram_ptr(
mr, 0 /* unattached */, "tcg-user-backed", size, hva);
memory_region_add_subregion(system_memory, gpa, mr);
table->slots[slot].gpa = gpa;
table->slots[slot].used = 1;
}
static void tcg_user_ram_slot_unmap(
uint64_t gpa, uint64_t size) {
struct TcgUserRamTable* table = tcg_user_ram_table_get();
for (int i = 0; i < TCG_MAX_USER_RAM_SLOTS; ++i) {
if (0 == table->slots[i].used) continue;
if (gpa != table->slots[i].gpa) continue;
memory_region_del_subregion(system_memory, &(table->slots[i].mr));
table->slots[i].used = 0;
return;
}
}
static void qemu_user_backed_ram_map_empty(uint64_t gpa, void *hva, uint64_t size, int flags)
{
tcg_user_ram_slot_map(gpa, hva, size, flags);
}
static void qemu_user_backed_ram_unmap_empty(uint64_t gpa, uint64_t size)
{
tcg_user_ram_slot_unmap(gpa, size);
}
static QemuUserBackedRamMapFunc s_user_backed_ram_map = &qemu_user_backed_ram_map_empty;
static QemuUserBackedRamUnmapFunc s_user_backed_ram_unmap = &qemu_user_backed_ram_unmap_empty;
void qemu_set_user_backed_mapping_funcs(QemuUserBackedRamMapFunc mapFunc,
QemuUserBackedRamUnmapFunc unmapFunc)
{
s_user_backed_ram_map = mapFunc;
s_user_backed_ram_unmap = unmapFunc;
}
void qemu_user_backed_ram_map(uint64_t gpa, void *hva, uint64_t size, int flags)
{
s_user_backed_ram_map(gpa, hva, size, flags);
}
void qemu_user_backed_ram_unmap(uint64_t gpa, uint64_t size)
{
s_user_backed_ram_unmap(gpa, size);
}
static void reclaim_ramblock(RAMBlock *block)
{
if (block->flags & RAM_PREALLOC) {
+1
View File
@@ -76,6 +76,7 @@ typedef struct {
static const RunStateTransition runstate_transitions_def[] = {
{ RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
{ RUN_STATE_PRELAUNCH, RUN_STATE_RESTORE_VM },
{ RUN_STATE_DEBUG, RUN_STATE_RUNNING },
{ RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },
+7
View File
@@ -2642,6 +2642,10 @@ void qemu_init(int argc, char **argv)
bool userconfig = true;
FILE *vmstate_dump_file = NULL;
/* in non-library builds this is done in a constructor */
#ifdef CONFIG_SHARED_LIBRARY_BUILD
rcu_register_thread();
#endif
qemu_add_opts(&qemu_drive_opts);
qemu_add_drive_opts(&qemu_legacy_drive_opts);
qemu_add_drive_opts(&qemu_common_drive_opts);
@@ -3157,6 +3161,9 @@ void qemu_init(int argc, char **argv)
add_device_config(DEV_DEBUGCON, optarg);
break;
case QEMU_OPTION_loadvm:
if (!loadvm) {
runstate_set(RUN_STATE_RESTORE_VM);
}
loadvm = optarg;
break;
case QEMU_OPTION_full_screen:
+32 -1
View File
@@ -113,6 +113,8 @@
#define TMR_CTL_IMASK (1 << 1)
#define TMR_CTL_ISTATUS (1 << 2)
static const bool windows_workaround_enabled = true;
static void hvf_wfi(CPUState *cpu);
typedef struct HVFVTimer {
@@ -648,6 +650,18 @@ int hvf_arch_init_vcpu(CPUState *cpu)
&arm_cpu->isar.id_aa64mmfr0);
assert_hvf_ok(ret);
#if defined(CONFIG_HVF_PRIVATE)
/* enable TSO mode */
if (hvf_state->tso_mode) {
uint64_t actlr;
ret = _hv_vcpu_get_actlr(cpu->hvf->fd, &actlr);
assert_hvf_ok(ret);
actlr |= ACTLR_EL1_TSO_ENABLE_MASK;
ret = _hv_vcpu_set_actlr(cpu->hvf->fd, actlr);
assert_hvf_ok(ret);
}
#endif
return 0;
}
@@ -1433,7 +1447,8 @@ int hvf_vcpu_exec(CPUState *cpu)
break;
case EC_AA64_SMC:
cpu_synchronize_state(cpu);
if (arm_cpu->psci_conduit == QEMU_PSCI_CONDUIT_SMC) {
if (windows_workaround_enabled ||
arm_cpu->psci_conduit == QEMU_PSCI_CONDUIT_SMC) {
advance_pc = true;
if (!hvf_handle_psci_call(cpu)) {
@@ -1491,6 +1506,22 @@ static void hvf_vm_state_change(void *opaque, bool running, RunState state)
}
}
hv_return_t hvf_arch_vm_create(HVFState *s)
{
#if defined(CONFIG_HVF_PRIVATE)
hv_return_t ret;
hv_vm_config_t config = hv_vm_config_create();
if (s->tso_mode) {
_hv_vm_config_set_isa(config, HV_VM_CONFIG_ISA_PRIVATE);
}
ret = hv_vm_create(config);
os_release(config);
return ret;
#else
return hv_vm_create(NULL);
#endif
}
int hvf_arch_init(void)
{
hvf_state->vtimer_offset = mach_absolute_time();
+5
View File
@@ -212,6 +212,11 @@ void hvf_kick_vcpu_thread(CPUState *cpu)
cpus_kick_thread(cpu);
}
hv_return_t hvf_arch_vm_create(HVFState *s)
{
return hv_vm_create(HV_VM_DEFAULT);
}
int hvf_arch_init(void)
{
return 0;
File diff suppressed because it is too large. Load diff
+32
View File
@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: MIT */
/*
* TCI target-specific constraint sets.
* Copyright (c) 2021 Linaro
*/
/*
* C_On_Im(...) defines a constraint set with <n> outputs and <m> inputs.
* Each operand should be a sequence of constraint letters as defined by
* tcg-target-con-str.h; the constraint combination is inclusive or.
*/
// Simple register functions.
C_O0_I1(r)
C_O0_I2(r, r)
C_O0_I3(r, r, r)
//C_O0_I4(r, r, r, r)
C_O1_I1(r, r)
C_O1_I2(r, r, r)
//C_O1_I4(r, r, r, r, r)
//C_O2_I1(r, r, r)
//C_O2_I2(r, r, r, r)
//C_O2_I4(r, r, r, r, r, r)
// Vector functions.
C_O1_I1(w, w)
C_O1_I1(w, r)
C_O0_I2(w, r)
C_O1_I1(w, wr)
C_O1_I2(w, w, w)
C_O1_I3(w, w, w, w)
C_O1_I2(w, 0, w)
+20
View File
@@ -0,0 +1,20 @@
/* SPDX-License-Identifier: MIT */
/*
* Define TCI target-specific operand constraints.
* Copyright (c) 2021 Linaro
*/
/*
* Define constraint letters for register sets:
* REGS(letter, register_mask)
*/
REGS('r', TCG_MASK_GP_REGISTERS)
REGS('w', TCG_MASK_VECTOR_REGISTERS)
/*
* Define constraint letters for constants:
* CONST(letter, TCG_CT_CONST_* bit set)
*/
// Simple 64-bit immediates.
CONST('I', 0xFFFFFFFFFFFFFFFF)
File diff suppressed because it is too large. Load diff
+254
View File
@@ -0,0 +1,254 @@
/*
* Tiny Code Generator for QEMU
*
* Copyright (c) 2009, 2011 Stefan Weil
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* This code implements a TCG which does not generate machine code for some
* real target machine but which generates virtual machine code for an
* interpreter. Interpreted pseudo code is slow, but it works on any host.
*
* Some remarks might help in understanding the code:
*
* "target" or "TCG target" is the machine which runs the generated code.
* This is different to the usual meaning in QEMU where "target" is the
* emulated machine. So normally QEMU host is identical to TCG target.
* Here the TCG target is a virtual machine, but this virtual machine must
* use the same word size like the real machine.
* Therefore, we need both 32 and 64 bit virtual machines (interpreter).
*/
#ifndef TCG_TARGET_H
#define TCG_TARGET_H
#if UINTPTR_MAX == UINT32_MAX
# error We only support AArch64 running in 64B mode.
#elif UINTPTR_MAX == UINT64_MAX
# define TCG_TARGET_REG_BITS 64
#else
# error Unknown pointer size for tcti target
#endif
#define TCG_TARGET_INSN_UNIT_SIZE 1
#define TCG_TARGET_TLB_DISPLACEMENT_BITS 32
#define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1)
// We're an interpreted target; even if we're JIT-compiling to our interpreter's
// weird psuedo-native bytecode. We'll indicate that we're intepreted.
#define TCG_TARGET_INTERPRETER 1
//
// Supported optional scalar instructions.
//
// Divs.
#define TCG_TARGET_HAS_div_i32 1
#define TCG_TARGET_HAS_rem_i32 1
#define TCG_TARGET_HAS_div_i64 1
#define TCG_TARGET_HAS_rem_i64 1
// Extends.
#define TCG_TARGET_HAS_ext8s_i32 1
#define TCG_TARGET_HAS_ext16s_i32 1
#define TCG_TARGET_HAS_ext8u_i32 1
#define TCG_TARGET_HAS_ext16u_i32 1
#define TCG_TARGET_HAS_ext8s_i64 1
#define TCG_TARGET_HAS_ext16s_i64 1
#define TCG_TARGET_HAS_ext32s_i64 1
#define TCG_TARGET_HAS_ext8u_i64 1
#define TCG_TARGET_HAS_ext16u_i64 1
#define TCG_TARGET_HAS_ext32u_i64 1
// Register extractions.
#define TCG_TARGET_HAS_extrl_i64_i32 1
#define TCG_TARGET_HAS_extrh_i64_i32 1
// Negations.
#define TCG_TARGET_HAS_neg_i32 1
#define TCG_TARGET_HAS_not_i32 1
#define TCG_TARGET_HAS_neg_i64 1
#define TCG_TARGET_HAS_not_i64 1
// Logicals.
#define TCG_TARGET_HAS_andc_i32 1
#define TCG_TARGET_HAS_orc_i32 1
#define TCG_TARGET_HAS_eqv_i32 1
#define TCG_TARGET_HAS_rot_i32 1
#define TCG_TARGET_HAS_nand_i32 1
#define TCG_TARGET_HAS_nor_i32 1
#define TCG_TARGET_HAS_andc_i64 1
#define TCG_TARGET_HAS_eqv_i64 1
#define TCG_TARGET_HAS_orc_i64 1
#define TCG_TARGET_HAS_rot_i64 1
#define TCG_TARGET_HAS_nor_i64 1
#define TCG_TARGET_HAS_nand_i64 1
// Bitwise operations.
#define TCG_TARGET_HAS_clz_i32 1
#define TCG_TARGET_HAS_ctz_i32 1
#define TCG_TARGET_HAS_clz_i64 1
#define TCG_TARGET_HAS_ctz_i64 1
// Swaps.
#define TCG_TARGET_HAS_bswap16_i32 1
#define TCG_TARGET_HAS_bswap32_i32 1
#define TCG_TARGET_HAS_bswap16_i64 1
#define TCG_TARGET_HAS_bswap32_i64 1
#define TCG_TARGET_HAS_bswap64_i64 1
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
//
// Supported optional vector instructions.
//
#define TCG_TARGET_HAS_v64 1
#define TCG_TARGET_HAS_v128 1
#define TCG_TARGET_HAS_v256 0
#define TCG_TARGET_HAS_andc_vec 1
#define TCG_TARGET_HAS_orc_vec 1
#define TCG_TARGET_HAS_nand_vec 0
#define TCG_TARGET_HAS_nor_vec 0
#define TCG_TARGET_HAS_eqv_vec 0
#define TCG_TARGET_HAS_not_vec 1
#define TCG_TARGET_HAS_neg_vec 1
#define TCG_TARGET_HAS_abs_vec 1
#define TCG_TARGET_HAS_roti_vec 0
#define TCG_TARGET_HAS_rots_vec 0
#define TCG_TARGET_HAS_rotv_vec 0
#define TCG_TARGET_HAS_shi_vec 0
#define TCG_TARGET_HAS_shs_vec 0
#define TCG_TARGET_HAS_shv_vec 1
#define TCG_TARGET_HAS_mul_vec 1
#define TCG_TARGET_HAS_sat_vec 1
#define TCG_TARGET_HAS_minmax_vec 1
#define TCG_TARGET_HAS_bitsel_vec 1
#define TCG_TARGET_HAS_cmpsel_vec 0
//
// Unsupported instructions.
//
// There's no direct instruction with which to count the number of ones,
// so we'll leave this implemented as other instructions.
#define TCG_TARGET_HAS_ctpop_i32 0
#define TCG_TARGET_HAS_ctpop_i64 0
// We don't currently support gadgets with more than three arguments,
// so we can't yet create movcond, deposit, or extract gadgets.
#define TCG_TARGET_HAS_movcond_i32 0
#define TCG_TARGET_HAS_movcond_i64 0
#define TCG_TARGET_HAS_deposit_i32 0
#define TCG_TARGET_HAS_deposit_i64 0
#define TCG_TARGET_HAS_extract_i32 0
#define TCG_TARGET_HAS_sextract_i32 0
#define TCG_TARGET_HAS_extract_i64 0
#define TCG_TARGET_HAS_sextract_i64 0
// This operation exists specifically to allow us to provide differing register
// constraints for 8-bit loads and stores. We don't need to do so, so we'll leave
// this unimplemented, as we gain nothing by it.
#define TCG_TARGET_HAS_qemu_st8_i32 0
// These should always be zero on our 64B platform.
#define TCG_TARGET_HAS_muls2_i64 0
#define TCG_TARGET_HAS_add2_i32 0
#define TCG_TARGET_HAS_sub2_i32 0
#define TCG_TARGET_HAS_mulu2_i32 0
#define TCG_TARGET_HAS_add2_i64 0
#define TCG_TARGET_HAS_sub2_i64 0
#define TCG_TARGET_HAS_mulu2_i64 0
#define TCG_TARGET_HAS_muluh_i64 0
#define TCG_TARGET_HAS_mulsh_i64 0
#define TCG_TARGET_HAS_extract2_i32 0
#define TCG_TARGET_HAS_muls2_i32 0
#define TCG_TARGET_HAS_muluh_i32 0
#define TCG_TARGET_HAS_mulsh_i32 0
#define TCG_TARGET_HAS_extract2_i64 0
//
// Platform metadata.
//
// Number of registers available.
#define TCG_TARGET_NB_REGS 64
// Number of general purpose registers.
#define TCG_TARGET_GP_REGS 16
/* List of registers which are used by TCG. */
typedef enum {
// General purpose registers.
// Note that we name every _host_ register here; but don't
// necessarily use them; that's determined by the allocation order
// and the number of registers setting above. These just give us the ability
// to refer to these by name.
TCG_REG_R0, TCG_REG_R1, TCG_REG_R2, TCG_REG_R3,
TCG_REG_R4, TCG_REG_R5, TCG_REG_R6, TCG_REG_R7,
TCG_REG_R8, TCG_REG_R9, TCG_REG_R10, TCG_REG_R11,
TCG_REG_R12, TCG_REG_R13, TCG_REG_R14, TCG_REG_R15,
TCG_REG_R16, TCG_REG_R17, TCG_REG_R18, TCG_REG_R19,
TCG_REG_R20, TCG_REG_R21, TCG_REG_R22, TCG_REG_R23,
TCG_REG_R24, TCG_REG_R25, TCG_REG_R26, TCG_REG_R27,
TCG_REG_R28, TCG_REG_R29, TCG_REG_R30, TCG_REG_R31,
// Register aliases.
TCG_AREG0 = TCG_REG_R14,
TCG_REG_CALL_STACK = TCG_REG_R15,
// Mask that refers to the GP registers.
TCG_MASK_GP_REGISTERS = 0xFFFFul,
// Vector registers.
TCG_REG_V0 = 32, TCG_REG_V1, TCG_REG_V2, TCG_REG_V3,
TCG_REG_V4, TCG_REG_V5, TCG_REG_V6, TCG_REG_V7,
TCG_REG_V8, TCG_REG_V9, TCG_REG_V10, TCG_REG_V11,
TCG_REG_V12, TCG_REG_V13, TCG_REG_V14, TCG_REG_V15,
TCG_REG_V16, TCG_REG_V17, TCG_REG_V18, TCG_REG_V19,
TCG_REG_V20, TCG_REG_V21, TCG_REG_V22, TCG_REG_V23,
TCG_REG_V24, TCG_REG_V25, TCG_REG_V26, TCG_REG_V27,
TCG_REG_V28, TCG_REG_V29, TCG_REG_V30, TCG_REG_V31,
// Mask that refers to the vector registers.
TCG_MASK_VECTOR_REGISTERS = 0xFFFF000000000000ul,
} TCGReg;
// Specify the shape of the stack our runtime will use.
#define TCG_TARGET_CALL_STACK_OFFSET 0
#define TCG_TARGET_STACK_ALIGN 16
#define TCG_TARGET_CALL_ARG_I32 TCG_CALL_ARG_NORMAL
#define TCG_TARGET_CALL_ARG_I64 TCG_CALL_ARG_NORMAL
#define TCG_TARGET_CALL_ARG_I128 TCG_CALL_ARG_NORMAL
#define TCG_TARGET_CALL_RET_I128 TCG_CALL_RET_NORMAL
// We're interpreted, so we'll use our own code to run TB_EXEC.
#define HAVE_TCG_QEMU_TB_EXEC
// We'll need to enforce memory ordering with barriers.
#define TCG_TARGET_DEFAULT_MO (0)
void tci_disas(uint8_t opc);
#endif /* TCG_TARGET_H */
+14
View File
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 Linaro
*
* This work is licensed under the terms of the GNU GPL, version 2 or
* (at your option) any later version.
*
* See the COPYING file in the top-level directory for details.
*
* Target-specific opcodes for host vector expansion. These will be
* emitted by tcg_expand_vec_op. For those familiar with GCC internals,
* consider these to be UNSPEC with names.
*/
DEF(aa64_sshl_vec, 1, 2, 0, IMPLVEC)
+1163
View File
File diff suppressed because it is too large. Load diff
+7 -4
View File
@@ -545,7 +545,7 @@ static int alloc_code_gen_buffer_anon(size_t size, int prot,
return prot;
}
#ifndef CONFIG_TCG_INTERPRETER
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
#ifdef CONFIG_POSIX
#include "qemu/memfd.h"
@@ -649,7 +649,7 @@ static int alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp)
static int alloc_code_gen_buffer_splitwx(size_t size, Error **errp)
{
#ifndef CONFIG_TCG_INTERPRETER
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
# ifdef CONFIG_DARWIN
return alloc_code_gen_buffer_splitwx_vmremap(size, errp);
# endif
@@ -689,7 +689,10 @@ static int alloc_code_gen_buffer(size_t size, int splitwx, Error **errp)
*/
prot = PROT_NONE;
flags = MAP_PRIVATE | MAP_ANONYMOUS;
#ifdef CONFIG_DARWIN
#if defined(CONFIG_TCG_INTERPRETER) || defined(CONFIG_TCG_THREADED_INTERPRETER)
/* The tcg interpreter does not need execute permission. */
prot = PROT_READ | PROT_WRITE;
#elif defined(CONFIG_DARWIN)
/* Applicable to both iOS and macOS (Apple Silicon). */
if (!splitwx) {
flags |= MAP_JIT;
@@ -795,7 +798,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus)
* Work with the page protections set up with the initial mapping.
*/
need_prot = PAGE_READ | PAGE_WRITE;
#ifndef CONFIG_TCG_INTERPRETER
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
if (tcg_splitwx_diff == 0) {
need_prot |= PAGE_EXEC;
}
+13 -6
View File
@@ -44,6 +44,7 @@
#define NO_CPU_IO_DEFS
#include "exec/exec-all.h"
#include "tcg/tcg-apple-jit.h"
#include "tcg/tcg-op.h"
#if UINTPTR_MAX == UINT32_MAX
@@ -168,7 +169,7 @@ TCGv_env cpu_env = 0;
const void *tcg_code_gen_epilogue;
uintptr_t tcg_splitwx_diff;
#ifndef CONFIG_TCG_INTERPRETER
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
tcg_prologue_fn *tcg_qemu_tb_exec;
#endif
@@ -1044,7 +1045,7 @@ void tcg_prologue_init(TCGContext *s)
s->code_buf = s->code_gen_ptr;
s->data_gen_ptr = NULL;
#ifndef CONFIG_TCG_INTERPRETER
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
tcg_qemu_tb_exec = (tcg_prologue_fn *)tcg_splitwx_to_rx(s->code_ptr);
#endif
@@ -1067,7 +1068,7 @@ void tcg_prologue_init(TCGContext *s)
prologue_size = tcg_current_code_size(s);
perf_report_prologue(s->code_gen_ptr, prologue_size);
#ifndef CONFIG_TCG_INTERPRETER
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(s->code_buf),
(uintptr_t)s->code_buf, prologue_size);
#endif
@@ -1106,7 +1107,7 @@ void tcg_prologue_init(TCGContext *s)
}
#endif
#ifndef CONFIG_TCG_INTERPRETER
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
/*
* Assert that goto_ptr is implemented completely, setting an epilogue.
* For tci, we use NULL as the signal to return from the interpreter,
@@ -1461,13 +1462,19 @@ bool tcg_op_supported(TCGOpcode op)
case INDEX_op_insn_start:
case INDEX_op_exit_tb:
case INDEX_op_goto_tb:
case INDEX_op_goto_ptr:
case INDEX_op_qemu_ld_i32:
case INDEX_op_qemu_st_i32:
case INDEX_op_qemu_ld_i64:
case INDEX_op_qemu_st_i64:
return true;
case INDEX_op_goto_ptr:
#if defined(CONFIG_TCG_THREADED_INTERPRETER)
return false;
#else
return true;
#endif
case INDEX_op_qemu_st8_i32:
return TCG_TARGET_HAS_qemu_st8_i32;
@@ -5154,7 +5161,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, target_ulong pc_start)
return -2;
}
#ifndef CONFIG_TCG_INTERPRETER
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
/* flush instruction cache */
flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(s->code_buf),
(uintptr_t)s->code_buf,
+1049 -530
View File
File diff suppressed because it is too large. Load diff
+3 -2
View File
@@ -56,8 +56,9 @@ void surface_gl_create_texture(QemuGLShader *gls,
switch (surface->format) {
case PIXMAN_BE_b8g8r8x8:
case PIXMAN_BE_b8g8r8a8:
surface->glformat = GL_BGRA_EXT;
surface->glformat = GL_RGBA;
surface->gltype = GL_UNSIGNED_BYTE;
surface->glswapped = true;
break;
case PIXMAN_BE_x8r8g8b8:
case PIXMAN_BE_a8r8g8b8:
@@ -125,7 +126,7 @@ void surface_gl_render_texture(QemuGLShader *gls,
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
qemu_gl_run_texture_blit(gls, false);
qemu_gl_run_texture_blit(gls, false, false);
}
void surface_gl_destroy_texture(QemuGLShader *gls,
+20 -47
View File
@@ -1217,9 +1217,7 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
dcl->ops->dpy_gl_scanout_texture) {
dcl->ops->dpy_gl_scanout_texture(dcl,
con->scanout.texture.backing_id,
con->scanout.texture.backing_y_0_top,
con->scanout.texture.backing_width,
con->scanout.texture.backing_height,
con->scanout.texture.backing_borrow,
con->scanout.texture.x,
con->scanout.texture.y,
con->scanout.texture.width,
@@ -1227,32 +1225,6 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
}
}
void console_select(unsigned int index)
{
DisplayChangeListener *dcl;
QemuConsole *s;
trace_console_select(index);
s = qemu_console_lookup_by_index(index);
if (s) {
DisplayState *ds = s->ds;
active_console = s;
if (ds->have_gfx) {
QLIST_FOREACH(dcl, &ds->listeners, next) {
if (dcl->con != NULL) {
continue;
}
displaychangelistener_display_console(dcl, s, NULL);
}
}
if (ds->have_text) {
dpy_text_resize(s, s->width, s->height);
}
text_console_update_cursor(NULL);
}
}
struct VCChardev {
Chardev parent;
QemuConsole *console;
@@ -1407,11 +1379,6 @@ void kbd_put_string_console(QemuConsole *s, const char *str, int len)
}
}
void kbd_put_keysym(int keysym)
{
kbd_put_keysym_console(active_console, keysym);
}
static void text_console_invalidate(void *opaque)
{
QemuConsole *s = (QemuConsole *) opaque;
@@ -1669,6 +1636,9 @@ void register_displaychangelistener(DisplayChangeListener *dcl)
if (con && dcl->ops->dpy_mouse_set) {
dcl->ops->dpy_mouse_set(dcl, con->cursor_x, con->cursor_y, con->cursor_on);
}
if (dcl->ds->have_text) {
dpy_text_resize(dcl->con, dcl->con->width, dcl->con->height);
}
text_console_update_cursor(NULL);
}
@@ -2001,9 +1971,7 @@ void dpy_gl_scanout_disable(QemuConsole *con)
void dpy_gl_scanout_texture(QemuConsole *con,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t width, uint32_t height)
{
@@ -2012,7 +1980,7 @@ void dpy_gl_scanout_texture(QemuConsole *con,
con->scanout.kind = SCANOUT_TEXTURE;
con->scanout.texture = (ScanoutTexture) {
backing_id, backing_y_0_top, backing_width, backing_height,
backing_id, backing_borrow,
x, y, width, height
};
QLIST_FOREACH(dcl, &s->listeners, next) {
@@ -2020,9 +1988,7 @@ void dpy_gl_scanout_texture(QemuConsole *con,
continue;
}
if (dcl->ops->dpy_gl_scanout_texture) {
dcl->ops->dpy_gl_scanout_texture(dcl, backing_id,
backing_y_0_top,
backing_width, backing_height,
dcl->ops->dpy_gl_scanout_texture(dcl, backing_id, backing_borrow,
x, y, width, height);
}
}
@@ -2225,6 +2191,18 @@ void graphic_console_close(QemuConsole *con)
dpy_gfx_replace_surface(con, surface);
}
QemuConsole *qemu_console_lookup_first_graphic_console(void)
{
QemuConsole *con;
QTAILQ_FOREACH(con, &consoles, next) {
if (con->console_type == GRAPHIC_CONSOLE) {
return con;
}
}
return NULL;
}
QemuConsole *qemu_console_lookup_by_index(unsigned int index)
{
QemuConsole *con;
@@ -2615,12 +2593,7 @@ void qemu_console_resize(QemuConsole *s, int width, int height)
DisplaySurface *qemu_console_surface(QemuConsole *console)
{
switch (console->scanout.kind) {
case SCANOUT_SURFACE:
return console->surface;
default:
return NULL;
}
return console->surface;
}
PixelFormat qemu_default_pixelformat(int bpp)
+26 -20
View File
@@ -98,7 +98,7 @@ static void curses_update(DisplayChangeListener *dcl,
static void curses_calc_pad(void)
{
if (qemu_console_is_fixedsize(NULL)) {
if (qemu_console_is_fixedsize(dcl->con)) {
width = gwidth;
height = gheight;
} else {
@@ -201,7 +201,7 @@ static void curses_cursor_position(DisplayChangeListener *dcl,
curs_set(1);
/* it seems that curs_set(1) must always be called before
* curs_set(2) for the latter to have effect */
if (!qemu_console_is_graphic(NULL)) {
if (!qemu_console_is_graphic(dcl->con)) {
curs_set(2);
}
return;
@@ -274,11 +274,11 @@ static void curses_refresh(DisplayChangeListener *dcl)
clear();
refresh();
curses_calc_pad();
graphic_hw_invalidate(NULL);
graphic_hw_invalidate(dcl->con);
invalidate = 0;
}
graphic_hw_text_update(NULL, screen);
graphic_hw_text_update(dcl->con, screen);
while (1) {
/* while there are any pending key strokes to process */
@@ -318,11 +318,16 @@ static void curses_refresh(DisplayChangeListener *dcl)
/* process keys reserved for qemu */
if (keycode >= QEMU_KEY_CONSOLE0 &&
keycode < QEMU_KEY_CONSOLE0 + 9) {
erase();
wnoutrefresh(stdscr);
console_select(keycode - QEMU_KEY_CONSOLE0);
QemuConsole *con = qemu_console_lookup_by_index(keycode - QEMU_KEY_CONSOLE0);
if (con) {
erase();
wnoutrefresh(stdscr);
unregister_displaychangelistener(dcl);
dcl->con = con;
register_displaychangelistener(dcl);
invalidate = 1;
invalidate = 1;
}
continue;
}
}
@@ -354,45 +359,45 @@ static void curses_refresh(DisplayChangeListener *dcl)
if (keycode == -1)
continue;
if (qemu_console_is_graphic(NULL)) {
if (qemu_console_is_graphic(dcl->con)) {
/* since terminals don't know about key press and release
* events, we need to emit both for each key received */
if (keycode & SHIFT) {
qemu_input_event_send_key_number(NULL, SHIFT_CODE, true);
qemu_input_event_send_key_number(dcl->con, SHIFT_CODE, true);
qemu_input_event_send_key_delay(0);
}
if (keycode & CNTRL) {
qemu_input_event_send_key_number(NULL, CNTRL_CODE, true);
qemu_input_event_send_key_number(dcl->con, CNTRL_CODE, true);
qemu_input_event_send_key_delay(0);
}
if (keycode & ALT) {
qemu_input_event_send_key_number(NULL, ALT_CODE, true);
qemu_input_event_send_key_number(dcl->con, ALT_CODE, true);
qemu_input_event_send_key_delay(0);
}
if (keycode & ALTGR) {
qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, true);
qemu_input_event_send_key_number(dcl->con, GREY | ALT_CODE, true);
qemu_input_event_send_key_delay(0);
}
qemu_input_event_send_key_number(NULL, keycode & KEY_MASK, true);
qemu_input_event_send_key_number(dcl->con, keycode & KEY_MASK, true);
qemu_input_event_send_key_delay(0);
qemu_input_event_send_key_number(NULL, keycode & KEY_MASK, false);
qemu_input_event_send_key_number(dcl->con, keycode & KEY_MASK, false);
qemu_input_event_send_key_delay(0);
if (keycode & ALTGR) {
qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, false);
qemu_input_event_send_key_number(dcl->con, GREY | ALT_CODE, false);
qemu_input_event_send_key_delay(0);
}
if (keycode & ALT) {
qemu_input_event_send_key_number(NULL, ALT_CODE, false);
qemu_input_event_send_key_number(dcl->con, ALT_CODE, false);
qemu_input_event_send_key_delay(0);
}
if (keycode & CNTRL) {
qemu_input_event_send_key_number(NULL, CNTRL_CODE, false);
qemu_input_event_send_key_number(dcl->con, CNTRL_CODE, false);
qemu_input_event_send_key_delay(0);
}
if (keycode & SHIFT) {
qemu_input_event_send_key_number(NULL, SHIFT_CODE, false);
qemu_input_event_send_key_number(dcl->con, SHIFT_CODE, false);
qemu_input_event_send_key_delay(0);
}
} else {
@@ -400,7 +405,7 @@ static void curses_refresh(DisplayChangeListener *dcl)
if (keysym == -1)
keysym = chr;
kbd_put_keysym(keysym);
kbd_put_keysym_console(dcl->con, keysym);
}
}
}
@@ -798,6 +803,7 @@ static void curses_display_init(DisplayState *ds, DisplayOptions *opts)
curses_winch_init();
dcl = g_new0(DisplayChangeListener, 1);
dcl->con = qemu_console_lookup_first_graphic_console();
dcl->ops = &dcl_ops;
register_displaychangelistener(dcl);
+23 -9
View File
@@ -117,13 +117,11 @@ static void dbus_scanout_dmabuf(DisplayChangeListener *dcl,
NULL, NULL, NULL);
}
static void dbus_scanout_texture(DisplayChangeListener *dcl,
uint32_t tex_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
static void dbus_scanout_borrowed_texture(DisplayChangeListener *dcl,
uint32_t tex_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height)
{
QemuDmaBuf dmabuf = {
.width = backing_width,
@@ -145,6 +143,22 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl,
close(dmabuf.fd);
}
static void dbus_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
{
bool backing_y_0_top;
uint32_t backing_width;
uint32_t backing_height;
uint32_t tex_id = backing_borrow(backing_id, &backing_y_0_top,
&backing_width, &backing_height);
dbus_scanout_borrowed_texture(dcl, tex_id, backing_y_0_top,
backing_width, backing_height);
}
static void dbus_cursor_dmabuf(DisplayChangeListener *dcl,
QemuDmaBuf *dmabuf, bool have_hot,
uint32_t hot_x, uint32_t hot_y)
@@ -314,8 +328,8 @@ static void dbus_gl_gfx_switch(DisplayChangeListener *dcl,
int height = surface_height(ddl->ds);
/* TODO: lazy send dmabuf (there are unnecessary sent otherwise) */
dbus_scanout_texture(&ddl->dcl, ddl->ds->texture, false,
width, height, 0, 0, width, height);
dbus_scanout_borrowed_texture(&ddl->dcl, ddl->ds->texture, false,
width, height);
}
}
#endif
+52 -15
View File
@@ -19,6 +19,10 @@ typedef struct egl_dpy {
uint32_t pos_y;
} egl_dpy;
#ifndef CONFIG_GBM
static EGLContext ctx;
#endif
/* ------------------------------------------------------------------ */
static void egl_refresh(DisplayChangeListener *dcl)
@@ -42,8 +46,12 @@ static void egl_gfx_switch(DisplayChangeListener *dcl,
static QEMUGLContext egl_create_context(DisplayGLCtx *dgc,
QEMUGLParams *params)
{
#ifdef CONFIG_GBM
eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
qemu_egl_rn_ctx);
#else
eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
#endif
return qemu_egl_create_context(dgc, params);
}
@@ -55,13 +63,11 @@ static void egl_scanout_disable(DisplayChangeListener *dcl)
egl_fb_destroy(&edpy->blit_fb);
}
static void egl_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
static void egl_scanout_imported_texture(DisplayChangeListener *dcl,
uint32_t backing_texture,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height)
{
egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
@@ -69,7 +75,7 @@ static void egl_scanout_texture(DisplayChangeListener *dcl,
/* source framebuffer */
egl_fb_setup_for_tex(&edpy->guest_fb,
backing_width, backing_height, backing_id, false);
backing_width, backing_height, backing_texture, false);
/* dest framebuffer */
if (edpy->blit_fb.width != backing_width ||
@@ -79,17 +85,32 @@ static void egl_scanout_texture(DisplayChangeListener *dcl,
}
}
static void egl_scanout_dmabuf(DisplayChangeListener *dcl,
QemuDmaBuf *dmabuf)
static void egl_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
{
bool backing_y_0_top;
uint32_t backing_width;
uint32_t backing_height;
GLuint backing_texture = backing_borrow(backing_id, &backing_y_0_top,
&backing_width, &backing_height);
egl_scanout_imported_texture(dcl, backing_texture, backing_y_0_top,
backing_width, backing_height);
}
#ifdef CONFIG_GBM
static void egl_scanout_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf)
{
egl_dmabuf_import_texture(dmabuf);
if (!dmabuf->texture) {
return;
}
egl_scanout_texture(dcl, dmabuf->texture,
false, dmabuf->width, dmabuf->height,
0, 0, dmabuf->width, dmabuf->height);
egl_scanout_imported_texture(dcl, dmabuf->texture,
false, dmabuf->width, dmabuf->height);
}
static void egl_cursor_dmabuf(DisplayChangeListener *dcl,
@@ -124,6 +145,7 @@ static void egl_release_dmabuf(DisplayChangeListener *dcl,
{
egl_dmabuf_release_texture(dmabuf);
}
#endif
static void egl_scanout_flush(DisplayChangeListener *dcl,
uint32_t x, uint32_t y,
@@ -139,9 +161,9 @@ static void egl_scanout_flush(DisplayChangeListener *dcl,
if (edpy->cursor_fb.texture) {
/* have cursor -> render using textures */
egl_texture_blit(edpy->gls, &edpy->blit_fb, &edpy->guest_fb,
!edpy->y_0_top);
!edpy->y_0_top, false);
egl_texture_blend(edpy->gls, &edpy->blit_fb, &edpy->cursor_fb,
!edpy->y_0_top, edpy->pos_x, edpy->pos_y,
false, !edpy->y_0_top, edpy->pos_x, edpy->pos_y,
1.0, 1.0);
} else {
/* no cursor -> use simple framebuffer blit */
@@ -160,10 +182,12 @@ static const DisplayChangeListenerOps egl_ops = {
.dpy_gl_scanout_disable = egl_scanout_disable,
.dpy_gl_scanout_texture = egl_scanout_texture,
#ifdef CONFIG_GBM
.dpy_gl_scanout_dmabuf = egl_scanout_dmabuf,
.dpy_gl_cursor_dmabuf = egl_cursor_dmabuf,
.dpy_gl_cursor_position = egl_cursor_position,
.dpy_gl_release_dmabuf = egl_release_dmabuf,
#endif
.dpy_gl_update = egl_scanout_flush,
};
@@ -197,7 +221,20 @@ static void early_egl_headless_init(DisplayOptions *opts)
mode = opts->gl;
}
#ifdef CONFIG_GBM
egl_init(opts->u.egl_headless.rendernode, mode, &error_fatal);
#else
if (qemu_egl_init_dpy_surfaceless(mode)) {
error_report("egl: display init failed");
exit(1);
}
ctx = qemu_egl_init_ctx();
if (!ctx) {
error_report("egl: egl_init_ctx failed");
exit(1);
}
#endif
}
static void egl_headless_init(DisplayState *ds, DisplayOptions *opts)
+151 -80
View File
@@ -28,7 +28,6 @@ DisplayGLMode qemu_egl_mode;
/* ------------------------------------------------------------------ */
#if defined(CONFIG_X11) || defined(CONFIG_GBM)
static const char *egl_get_error_string(void)
{
EGLint error = eglGetError();
@@ -68,7 +67,6 @@ static const char *egl_get_error_string(void)
return "Unknown EGL error";
}
}
#endif
static void egl_fb_delete_texture(egl_fb *fb)
{
@@ -102,14 +100,15 @@ void egl_fb_setup_default(egl_fb *fb, int width, int height)
fb->framebuffer = 0; /* default framebuffer */
}
void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,
GLuint texture, bool delete)
void egl_fb_setup_for_tex_target(egl_fb *fb, int width, int height,
GLuint texture, GLenum target, bool delete)
{
egl_fb_delete_texture(fb);
fb->width = width;
fb->height = height;
fb->texture = texture;
fb->texture_target = target;
fb->delete_texture = delete;
if (!fb->framebuffer) {
glGenFramebuffers(1, &fb->framebuffer);
@@ -117,19 +116,30 @@ void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,
glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb->framebuffer);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, fb->texture, 0);
fb->texture_target, fb->texture, 0);
}
void egl_fb_setup_new_tex(egl_fb *fb, int width, int height)
void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,
GLuint texture, bool delete)
{
egl_fb_setup_for_tex_target(fb, width, height, texture, GL_TEXTURE_2D, delete);
}
void egl_fb_setup_new_tex_target(egl_fb *fb, int width, int height, GLenum target)
{
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,
glBindTexture(target, texture);
glTexImage2D(target, 0, GL_RGBA, width, height,
0, GL_BGRA, GL_UNSIGNED_BYTE, 0);
egl_fb_setup_for_tex(fb, width, height, texture, true);
egl_fb_setup_for_tex_target(fb, width, height, texture, target, true);
}
void egl_fb_setup_new_tex(egl_fb *fb, int width, int height)
{
egl_fb_setup_new_tex_target(fb, width, height, GL_TEXTURE_2D);
}
void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip)
@@ -171,17 +181,17 @@ void egl_fb_read(DisplaySurface *dst, egl_fb *src)
GL_BGRA, GL_UNSIGNED_BYTE, surface_data(dst));
}
void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip)
void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip, bool swap)
{
glBindFramebuffer(GL_FRAMEBUFFER_EXT, dst->framebuffer);
glViewport(0, 0, dst->width, dst->height);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, src->texture);
qemu_gl_run_texture_blit(gls, flip);
glBindTexture(src->texture_target, src->texture);
qemu_gl_run_texture_blit(gls, flip, swap);
}
void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
int x, int y, double scale_x, double scale_y)
bool swap, int x, int y, double scale_x, double scale_y)
{
glBindFramebuffer(GL_FRAMEBUFFER_EXT, dst->framebuffer);
int w = scale_x * src->width;
@@ -192,10 +202,10 @@ void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
glViewport(x, dst->height - h - y, w, h);
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, src->texture);
glBindTexture(src->texture_target, src->texture);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
qemu_gl_run_texture_blit(gls, flip);
qemu_gl_run_texture_blit(gls, flip, swap);
glDisable(GL_BLEND);
}
@@ -378,7 +388,7 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf)
/* ---------------------------------------------------------------------- */
EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win)
EGLSurface qemu_egl_init_surface(EGLContext ectx, EGLNativeWindowType win)
{
EGLSurface esurface;
EGLBoolean b;
@@ -400,9 +410,104 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win)
return esurface;
}
EGLSurface qemu_egl_init_buffer_surface(EGLContext ectx,
EGLenum buftype,
EGLClientBuffer buffer,
const EGLint *attrib_list)
{
EGLSurface esurface;
EGLBoolean b;
esurface = eglCreatePbufferFromClientBuffer(qemu_egl_display,
buftype,
buffer,
qemu_egl_config,
attrib_list);
if (esurface == EGL_NO_SURFACE) {
error_report("egl: eglCreatePbufferFromClientBuffer failed");
return NULL;
}
b = eglMakeCurrent(qemu_egl_display, esurface, esurface, ectx);
if (b == EGL_FALSE) {
error_report("egl: eglMakeCurrent failed");
qemu_egl_destroy_surface(esurface);
return NULL;
}
return esurface;
}
bool qemu_egl_destroy_surface(EGLSurface surface)
{
return eglDestroySurface(qemu_egl_display, surface);
}
/* ---------------------------------------------------------------------- */
#if defined(CONFIG_X11) || defined(CONFIG_GBM)
static int qemu_egl_init_dpy(EGLDisplay dpy, DisplayGLMode mode)
{
static const EGLint conf_att_core[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 5,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, 0,
EGL_NONE,
};
static const EGLint conf_att_gles[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 5,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, 0,
EGL_NONE,
};
EGLint major, minor;
EGLBoolean b;
EGLint n;
bool gles = (mode == DISPLAYGL_MODE_ES);
qemu_egl_display = dpy;
b = eglInitialize(qemu_egl_display, &major, &minor);
if (b == EGL_FALSE) {
error_report("egl: eglInitialize failed: %s", egl_get_error_string());
return -1;
}
b = eglBindAPI(gles ? EGL_OPENGL_ES_API : EGL_OPENGL_API);
if (b == EGL_FALSE) {
error_report("egl: eglBindAPI failed (%s mode): %s",
gles ? "gles" : "core", egl_get_error_string());
return -1;
}
b = eglChooseConfig(qemu_egl_display,
gles ? conf_att_gles : conf_att_core,
&qemu_egl_config, 1, &n);
if (b == EGL_FALSE || n != 1) {
error_report("egl: eglChooseConfig failed (%s mode): %s",
gles ? "gles" : "core", egl_get_error_string());
return -1;
}
qemu_egl_mode = gles ? DISPLAYGL_MODE_ES : DISPLAYGL_MODE_CORE;
return 0;
}
int qemu_egl_init_dpy_cocoa(DisplayGLMode mode)
{
EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (dpy == EGL_NO_DISPLAY) {
error_report("egl: eglGetDisplay failed");
return -1;
}
return qemu_egl_init_dpy(dpy, mode);
}
/*
* Taken from glamor_egl.h from the Xorg xserver, which is MIT licensed
@@ -432,8 +537,9 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win)
* platform extensions (EGL_KHR_platform_gbm and friends) yet it doesn't seem
* like mesa will be able to advertise these (even though it can do EGL 1.5).
*/
static EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
EGLenum platform)
static int qemu_egl_init_dpy_platform(EGLNativeDisplayType native,
EGLenum platform,
DisplayGLMode mode)
{
EGLDisplay dpy = EGL_NO_DISPLAY;
@@ -446,92 +552,57 @@ static EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
}
}
#if defined(CONFIG_X11) || defined(CONFIG_GBM)
if (dpy == EGL_NO_DISPLAY) {
/* fallback */
dpy = eglGetDisplay(native);
}
return dpy;
#endif
if (dpy == EGL_NO_DISPLAY) {
error_report("egl: eglGetDisplay failed");
return -1;
}
return qemu_egl_init_dpy(dpy, mode);
}
static int qemu_egl_init_dpy(EGLNativeDisplayType dpy,
EGLenum platform,
DisplayGLMode mode)
int qemu_egl_init_dpy_surfaceless(DisplayGLMode mode)
{
static const EGLint conf_att_core[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 5,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, 0,
EGL_NONE,
};
static const EGLint conf_att_gles[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 5,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, 0,
EGL_NONE,
};
EGLint major, minor;
EGLBoolean b;
EGLint n;
bool gles = (mode == DISPLAYGL_MODE_ES);
qemu_egl_display = qemu_egl_get_display(dpy, platform);
if (qemu_egl_display == EGL_NO_DISPLAY) {
error_report("egl: eglGetDisplay failed: %s", egl_get_error_string());
return -1;
}
b = eglInitialize(qemu_egl_display, &major, &minor);
if (b == EGL_FALSE) {
error_report("egl: eglInitialize failed: %s", egl_get_error_string());
return -1;
}
b = eglBindAPI(gles ? EGL_OPENGL_ES_API : EGL_OPENGL_API);
if (b == EGL_FALSE) {
error_report("egl: eglBindAPI failed (%s mode): %s",
gles ? "gles" : "core", egl_get_error_string());
return -1;
}
b = eglChooseConfig(qemu_egl_display,
gles ? conf_att_gles : conf_att_core,
&qemu_egl_config, 1, &n);
if (b == EGL_FALSE || n != 1) {
error_report("egl: eglChooseConfig failed (%s mode): %s",
gles ? "gles" : "core", egl_get_error_string());
return -1;
}
qemu_egl_mode = gles ? DISPLAYGL_MODE_ES : DISPLAYGL_MODE_CORE;
return 0;
return qemu_egl_init_dpy_platform(NULL, EGL_PLATFORM_SURFACELESS_MESA, mode);
}
#if defined(CONFIG_X11) || defined(CONFIG_GBM)
int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy, DisplayGLMode mode)
{
#ifdef EGL_KHR_platform_x11
return qemu_egl_init_dpy(dpy, EGL_PLATFORM_X11_KHR, mode);
return qemu_egl_init_dpy_platform(dpy, EGL_PLATFORM_X11_KHR, mode);
#else
return qemu_egl_init_dpy(dpy, 0, mode);
return qemu_egl_init_dpy_platform(dpy, 0, mode);
#endif
}
int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode)
{
#ifdef EGL_MESA_platform_gbm
return qemu_egl_init_dpy(dpy, EGL_PLATFORM_GBM_MESA, mode);
return qemu_egl_init_dpy_platform(dpy, EGL_PLATFORM_GBM_MESA, mode);
#else
return qemu_egl_init_dpy(dpy, 0, mode);
return qemu_egl_init_dpy_platform(dpy, 0, mode);
#endif
}
#endif
#if defined(CONFIG_ANGLE)
int qemu_egl_init_dpy_angle(DisplayGLMode mode)
{
return qemu_egl_init_dpy_platform(NULL, EGL_PLATFORM_ANGLE_ANGLE, mode);
}
#endif
bool qemu_egl_has_dmabuf(void)
{
if (qemu_egl_display == EGL_NO_DISPLAY) {
+31 -15
View File
@@ -54,7 +54,7 @@ void gd_egl_init(VirtualConsole *vc)
}
vc->gfx.ectx = qemu_egl_init_ctx();
vc->gfx.esurface = qemu_egl_init_surface_x11
vc->gfx.esurface = qemu_egl_init_surface
(vc->gfx.ectx, (EGLNativeWindowType)x11_window);
assert(vc->gfx.esurface);
@@ -219,14 +219,14 @@ void gd_egl_scanout_disable(DisplayChangeListener *dcl)
gtk_egl_set_scanout_mode(vc, false);
}
void gd_egl_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id, bool backing_y_0_top,
uint32_t backing_width, uint32_t backing_height,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
static void gd_egl_scanout_borrowed_texture(VirtualConsole *vc,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
{
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
vc->gfx.x = x;
vc->gfx.y = y;
vc->gfx.w = w;
@@ -241,8 +241,24 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,
backing_id, false);
}
void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
QemuDmaBuf *dmabuf)
void gd_egl_scanout_texture(DisplayChangeListener *dcl, uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
{
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
bool backing_y_0_top;
uint32_t backing_width;
uint32_t backing_height;
GLuint backing_texture = backing_borrow(backing_id, &backing_y_0_top,
&backing_width, &backing_height);
gd_egl_scanout_borrowed_texture(vc, backing_texture, backing_y_0_top,
backing_width, backing_height,
x, y, w, h);
}
void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf)
{
#ifdef CONFIG_GBM
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
@@ -255,9 +271,9 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
return;
}
gd_egl_scanout_texture(dcl, dmabuf->texture,
false, dmabuf->width, dmabuf->height,
0, 0, dmabuf->width, dmabuf->height);
gd_egl_scanout_borrowed_texture(vc, dmabuf->texture,
false, dmabuf->width, dmabuf->height,
0, 0, dmabuf->width, dmabuf->height);
if (dmabuf->allow_fences) {
vc->gfx.guest_fb.dmabuf = dmabuf;
@@ -317,9 +333,9 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl,
egl_fb_setup_default(&vc->gfx.win_fb, ww, wh);
if (vc->gfx.cursor_fb.texture) {
egl_texture_blit(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.guest_fb,
vc->gfx.y0_top);
vc->gfx.y0_top, false);
egl_texture_blend(vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.cursor_fb,
vc->gfx.y0_top,
vc->gfx.y0_top, false,
vc->gfx.cursor_x, vc->gfx.cursor_y,
vc->gfx.scale_x, vc->gfx.scale_y);
} else {
+35 -13
View File
@@ -121,7 +121,12 @@ void gd_gl_area_refresh(DisplayChangeListener *dcl)
{
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
<<<<<<< HEAD
gd_update_monitor_refresh_rate(
vc, vc->window ? vc->window : vc->gfx.drawing_area);
=======
gd_update_monitor_refresh_rate(vc, vc->window ? vc->window : vc->gfx.drawing_area);
>>>>>>> v7.1.0
if (!vc->gfx.gls) {
if (!gtk_widget_get_realized(vc->gfx.drawing_area)) {
@@ -238,16 +243,14 @@ void gd_gl_area_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx)
g_clear_object(&ctx);
}
void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
static void gd_gl_area_scanout_borrowed_texture(VirtualConsole *vc,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
{
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
vc->gfx.x = x;
vc->gfx.y = y;
vc->gfx.w = w;
@@ -256,7 +259,7 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
if (backing_id == 0 || vc->gfx.w == 0 || vc->gfx.h == 0) {
if (vc->gfx.w == 0 || vc->gfx.h == 0) {
gtk_gl_area_set_scanout_mode(vc, false);
return;
}
@@ -266,6 +269,25 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
backing_id, false);
}
void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
{
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
bool backing_y_0_top;
uint32_t backing_width;
uint32_t backing_height;
GLuint backing_texture = backing_borrow(backing_id, &backing_y_0_top,
&backing_width, &backing_height);
gd_gl_area_scanout_borrowed_texture(vc, backing_texture,
backing_y_0_top,
backing_width, backing_height,
x, y, w, h);
}
void gd_gl_area_scanout_disable(DisplayChangeListener *dcl)
{
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
@@ -297,9 +319,9 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
return;
}
gd_gl_area_scanout_texture(dcl, dmabuf->texture,
false, dmabuf->width, dmabuf->height,
0, 0, dmabuf->width, dmabuf->height);
gd_gl_area_scanout_borrowed_texture(vc, dmabuf->texture,
false, dmabuf->width, dmabuf->height,
0, 0, dmabuf->width, dmabuf->height);
if (dmabuf->allow_fences) {
vc->gfx.guest_fb.dmabuf = dmabuf;
+2 -2
View File
@@ -664,7 +664,7 @@ static const DisplayGLCtxOps egl_ctx_ops = {
};
#endif
#endif /* CONFIG_OPENGL */
#endif /* defined(CONFIG_OPENGL) */
/** QEMU Events **/
@@ -2475,6 +2475,6 @@ static void register_gtk(void)
type_init(register_gtk);
#ifdef CONFIG_OPENGL
#if defined(CONFIG_OPENGL)
module_dep("ui-opengl");
#endif
+5 -2
View File
@@ -65,9 +65,9 @@ if opengl.found()
ui_modules += {'opengl' : opengl_ss}
endif
if opengl.found() and gbm.found()
if opengl.found()
egl_headless_ss = ss.source_set()
egl_headless_ss.add(when: [opengl, gbm, pixman],
egl_headless_ss.add(when: [opengl, pixman],
if_true: files('egl-headless.c'))
ui_modules += {'egl-headless' : egl_headless_ss}
endif
@@ -132,6 +132,9 @@ if spice.found()
'spice-input.c',
'spice-display.c'
))
if iosurface.found()
spice_core_ss.add(iosurface)
endif
ui_modules += {'spice-core' : spice_core_ss}
endif
+9 -4
View File
@@ -197,15 +197,20 @@ void sdl2_gl_scanout_disable(DisplayChangeListener *dcl)
void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
{
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
bool backing_y_0_top;
uint32_t backing_width;
uint32_t backing_height;
assert(scon->opengl);
GLuint backing_texture = backing_borrow(backing_id, &backing_y_0_top,
&backing_width, &backing_height);
scon->x = x;
scon->y = y;
scon->w = w;
@@ -216,7 +221,7 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
sdl2_set_scanout_mode(scon, true);
egl_fb_setup_for_tex(&scon->guest_fb, backing_width, backing_height,
backing_id, false);
backing_texture, false);
}
void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
+6 -6
View File
@@ -93,7 +93,7 @@ void sdl2_window_create(struct sdl2_console *scon)
if (scon->hidden) {
flags |= SDL_WINDOW_HIDDEN;
}
#ifdef CONFIG_OPENGL
#if defined(CONFIG_OPENGL)
if (scon->opengl) {
flags |= SDL_WINDOW_OPENGL;
}
@@ -150,7 +150,7 @@ void sdl2_window_resize(struct sdl2_console *scon)
static void sdl2_redraw(struct sdl2_console *scon)
{
if (scon->opengl) {
#ifdef CONFIG_OPENGL
#if defined(CONFIG_OPENGL)
sdl2_gl_redraw(scon);
#endif
} else {
@@ -793,7 +793,7 @@ static const DisplayChangeListenerOps dcl_2d_ops = {
.dpy_cursor_define = sdl_mouse_define,
};
#ifdef CONFIG_OPENGL
#if defined(CONFIG_OPENGL)
static const DisplayChangeListenerOps dcl_gl_ops = {
.dpy_name = "sdl2-gl",
.dpy_gfx_update = sdl2_gl_update,
@@ -827,7 +827,7 @@ static void sdl2_display_early_init(DisplayOptions *o)
{
assert(o->type == DISPLAY_TYPE_SDL);
if (o->has_gl && o->gl) {
#ifdef CONFIG_OPENGL
#if defined(CONFIG_OPENGL)
display_opengl = 1;
#endif
}
@@ -889,7 +889,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
}
sdl2_console[i].idx = i;
sdl2_console[i].opts = o;
#ifdef CONFIG_OPENGL
#if defined(CONFIG_OPENGL)
sdl2_console[i].opengl = display_opengl;
sdl2_console[i].dcl.ops = display_opengl ? &dcl_gl_ops : &dcl_2d_ops;
sdl2_console[i].dgc.ops = display_opengl ? &gl_ctx_ops : NULL;
@@ -958,6 +958,6 @@ static void register_sdl1(void)
type_init(register_sdl1);
#ifdef CONFIG_OPENGL
#if defined(CONFIG_OPENGL)
module_dep("ui-opengl");
#endif
+31 -7
View File
@@ -30,10 +30,13 @@
#include "ui/shader/texture-blit-vert.h"
#include "ui/shader/texture-blit-flip-vert.h"
#include "ui/shader/texture-blit-frag.h"
#include "ui/shader/texture-blit-swap-frag.h"
struct QemuGLShader {
GLint texture_blit_prog;
GLint texture_blit_flip_prog;
GLint texture_blit_swap_prog;
GLint texture_blit_flip_swap_prog;
GLint texture_blit_vao;
};
@@ -69,11 +72,17 @@ static GLuint qemu_gl_init_texture_blit(GLint texture_blit_prog)
return vao;
}
void qemu_gl_run_texture_blit(QemuGLShader *gls, bool flip)
void qemu_gl_run_texture_blit(QemuGLShader *gls, bool flip, bool swapped)
{
glUseProgram(flip
? gls->texture_blit_flip_prog
: gls->texture_blit_prog);
if (flip && swapped) {
glUseProgram(gls->texture_blit_flip_swap_prog);
} else if (flip && !swapped) {
glUseProgram(gls->texture_blit_flip_prog);
} else if (!flip && swapped) {
glUseProgram(gls->texture_blit_swap_prog);
} else { // !flip && !swapped
glUseProgram(gls->texture_blit_prog);
}
glBindVertexArray(gls->texture_blit_vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
@@ -152,12 +161,27 @@ end:
QemuGLShader *qemu_gl_init_shader(void)
{
QemuGLShader *gls = g_new0(QemuGLShader, 1);
const char *header = epoxy_is_desktop_gl() ? "#version 140\n" : "#version 300 es\n";
char vert_src[256];
char frag_src[256];
char *vert_src_body = stpcpy(vert_src, header);
char *frag_src_body = stpcpy(frag_src, header);
strcpy(vert_src_body, texture_blit_vert_src);
strcpy(frag_src_body, texture_blit_frag_src);
gls->texture_blit_prog = qemu_gl_create_compile_link_program
(texture_blit_vert_src, texture_blit_frag_src);
(vert_src, frag_src);
strcpy(vert_src_body, texture_blit_flip_vert_src);
gls->texture_blit_flip_prog = qemu_gl_create_compile_link_program
(texture_blit_flip_vert_src, texture_blit_frag_src);
if (!gls->texture_blit_prog || !gls->texture_blit_flip_prog) {
(vert_src, frag_src);
strcpy(frag_src_body, texture_blit_swap_frag_src);
gls->texture_blit_flip_swap_prog = qemu_gl_create_compile_link_program
(vert_src, frag_src);
strcpy(vert_src_body, texture_blit_vert_src);
gls->texture_blit_swap_prog = qemu_gl_create_compile_link_program
(vert_src, frag_src);
if (!gls->texture_blit_prog || !gls->texture_blit_flip_prog ||
!gls->texture_blit_swap_prog || !gls->texture_blit_flip_swap_prog) {
exit(1);
}
+1
View File
@@ -1,5 +1,6 @@
shaders = [
['texture-blit', 'frag'],
['texture-blit-swap', 'frag'],
['texture-blit', 'vert'],
['texture-blit-flip', 'vert'],
]
-2
View File
@@ -1,5 +1,3 @@
#version 300 es
in vec2 in_position;
out vec2 ex_tex_coord;
+7
View File
@@ -0,0 +1,7 @@
uniform sampler2D image;
in mediump vec2 ex_tex_coord;
out mediump vec4 out_frag_color;
void main(void) {
out_frag_color = texture(image, ex_tex_coord).zyxw;
}
-2
View File
@@ -1,5 +1,3 @@
#version 300 es
uniform sampler2D image;
in mediump vec2 ex_tex_coord;
out mediump vec4 out_frag_color;
-2
View File
@@ -1,5 +1,3 @@
#version 300 es
in vec2 in_position;
out vec2 ex_tex_coord;
+21
View File
@@ -52,6 +52,10 @@ static int spice_have_target_host;
static QemuThread me;
#ifdef CONFIG_ANGLE
extern EGLContext spice_gl_ctx;
#endif
struct SpiceTimer {
QEMUTimer *timer;
};
@@ -842,7 +846,24 @@ static void qemu_spice_init(void)
"incompatible with -spice port/tls-port");
exit(1);
}
#if defined(CONFIG_GBM)
egl_init(qemu_opt_get(opts, "rendernode"), DISPLAYGL_MODE_ON, &error_fatal);
#elif defined(CONFIG_ANGLE)
if (qemu_egl_init_dpy_angle(DISPLAYGL_MODE_ES)) {
error_report("SPICE GL failed to initialize ANGLE display");
exit(1);
}
spice_gl_ctx = qemu_egl_init_ctx();
if (!spice_gl_ctx) {
error_report("egl: egl_init_ctx failed");
exit(1);
}
#else
error_report("No backend to support SPICE GL");
exit(1);
#endif
display_opengl = 1;
spice_opengl = 1;
}
#endif
+258 -15
View File
@@ -25,11 +25,22 @@
#include "qemu/queue.h"
#include "ui/console.h"
#include "trace.h"
#ifdef CONFIG_IOSURFACE
#include <TargetConditionals.h>
#endif
#ifdef CONFIG_ANGLE
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#endif
#include "ui/spice-display.h"
bool spice_opengl;
#ifdef CONFIG_ANGLE
EGLContext spice_gl_ctx;
#endif
int qemu_spice_rect_is_empty(const QXLRect* r)
{
return r->top == r->bottom || r->left == r->right;
@@ -790,6 +801,168 @@ static const DisplayChangeListenerOps display_listener_ops = {
#ifdef HAVE_SPICE_GL
#if defined(CONFIG_IOSURFACE)
static void AddIntegerValue(CFMutableDictionaryRef dictionary, const CFStringRef key, int32_t value)
{
CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value);
CFDictionaryAddValue(dictionary, key, number);
CFRelease(number);
}
static int spice_iosurface_create(SimpleSpiceDisplay *ssd, int width, int height)
{
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(
kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
AddIntegerValue(dict, kIOSurfaceWidth, width);
AddIntegerValue(dict, kIOSurfaceHeight, height);
AddIntegerValue(dict, kIOSurfacePixelFormat, 'BGRA');
AddIntegerValue(dict, kIOSurfaceBytesPerElement, 4);
#if TARGET_OS_OSX
CFDictionaryAddValue(dict, kIOSurfaceIsGlobal, kCFBooleanTrue);
#endif
ssd->iosurface = IOSurfaceCreate(dict);
CFRelease(dict);
if (!ssd->iosurface) {
error_report("spice_iosurface_create: IOSurfaceCreate failed");
return 0;
}
#if defined(CONFIG_ANGLE)
EGLint target = 0;
GLenum tex_target = 0;
if (eglGetConfigAttrib(qemu_egl_display,
qemu_egl_config,
EGL_BIND_TO_TEXTURE_TARGET_ANGLE,
&target) != EGL_TRUE) {
error_report("spice_iosurface_create: eglGetConfigAttrib failed");
goto gl_error;
}
if (target == EGL_TEXTURE_2D) {
tex_target = GL_TEXTURE_2D;
} else if (target == EGL_TEXTURE_RECTANGLE_ANGLE) {
tex_target = GL_TEXTURE_RECTANGLE_ANGLE;
} else {
error_report("spice_iosurface_create: unsupported texture target");
goto gl_error;
}
const EGLint attribs[] = {
EGL_WIDTH, width,
EGL_HEIGHT, height,
EGL_IOSURFACE_PLANE_ANGLE, 0,
EGL_TEXTURE_TARGET, target,
EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, GL_BGRA_EXT,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
EGL_TEXTURE_TYPE_ANGLE, GL_UNSIGNED_BYTE,
EGL_IOSURFACE_USAGE_HINT_ANGLE, EGL_IOSURFACE_WRITE_HINT_ANGLE,
EGL_NONE, EGL_NONE,
};
ssd->esurface = qemu_egl_init_buffer_surface(spice_gl_ctx,
EGL_IOSURFACE_ANGLE,
ssd->iosurface,
attribs);
if (ssd->esurface == NULL) {
goto gl_error;
}
egl_fb_setup_new_tex_target(&ssd->iosurface_fb, width, height, tex_target);
eglBindTexImage(qemu_egl_display, ssd->esurface, EGL_BACK_BUFFER);
return 1;
gl_error:
CFRelease(ssd->iosurface);
ssd->iosurface = NULL;
return 0;
#else
error_report("spice_iosurface_create: ANGLE not found");
return 0;
#endif
}
static void spice_iosurface_destroy(SimpleSpiceDisplay *ssd)
{
if (!ssd->iosurface) {
return;
}
#if defined(CONFIG_ANGLE)
eglMakeCurrent(qemu_egl_display, ssd->esurface, ssd->esurface, spice_gl_ctx);
eglReleaseTexImage(qemu_egl_display, ssd->esurface, EGL_BACK_BUFFER);
egl_fb_destroy(&ssd->iosurface_fb);
qemu_egl_destroy_surface(ssd->esurface);
ssd->esurface = EGL_NO_SURFACE;
#endif
if (ssd->surface_send_fd > -1) {
// this sends POLLHUP and indicates that any unread data is stale
// and should not be used
close(ssd->surface_send_fd);
ssd->surface_send_fd = -1;
}
// FIXME: still a tiny race with the close() above
CFRelease(ssd->iosurface);
ssd->iosurface = NULL;
}
static int spice_iosurface_resize(SimpleSpiceDisplay *ssd, int width, int height)
{
if (ssd->iosurface) {
if (IOSurfaceGetHeight(ssd->iosurface) != width ||
IOSurfaceGetWidth(ssd->iosurface) != height) {
spice_iosurface_destroy(ssd);
return spice_iosurface_create(ssd, width, height);
} else {
return 1;
}
} else {
return spice_iosurface_create(ssd, width, height);
}
}
/* FIXME: use mach ports instead of this hack */
static int spice_iosurface_create_fd(SimpleSpiceDisplay *ssd, int *fourcc)
{
int fds[2];
IOSurfaceID surfaceid;
if (!ssd->iosurface) {
return -1;
}
if (pipe(fds) < 0) {
error_report("spice_iosurface_create_fd: failed to create pipe");
return -1;
}
if (ssd->surface_send_fd > -1) {
close(ssd->surface_send_fd);
}
// we keep the write end of the pipe open for the lifetime of this surface
// when we close it, POLLHUP will be seen by the other side and know that
// the surface ID is stale and should not be used
ssd->surface_send_fd = fds[1];
*fourcc = 'BGRA';
surfaceid = IOSurfaceGetID(ssd->iosurface);
write(ssd->surface_send_fd, &surfaceid, sizeof(surfaceid));
return fds[0];
}
static void spice_iosurface_blit(SimpleSpiceDisplay *ssd, GLuint src_texture, bool flip, bool swap)
{
egl_fb tmp_fb = { .texture = src_texture, .texture_target = GL_TEXTURE_2D };
if (!ssd->iosurface) {
return;
}
#if defined(CONFIG_ANGLE)
eglMakeCurrent(qemu_egl_display, ssd->esurface, ssd->esurface, spice_gl_ctx);
egl_texture_blit(ssd->gls, &ssd->iosurface_fb, &tmp_fb, flip, swap);
#endif
}
#endif
static void qemu_spice_gl_monitor_config(SimpleSpiceDisplay *ssd,
int x, int y, int w, int h)
{
@@ -867,6 +1040,11 @@ static void spice_gl_update(DisplayChangeListener *dcl,
SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
surface_gl_update_texture(ssd->gls, ssd->ds, x, y, w, h);
#if defined(CONFIG_IOSURFACE)
if (!qemu_console_is_gl_blocked(ssd->dcl.con)) {
spice_iosurface_blit(ssd, ssd->ds->texture, true, ssd->ds->glswapped);
}
#endif
ssd->gl_updates++;
}
@@ -874,15 +1052,19 @@ static void spice_gl_switch(DisplayChangeListener *dcl,
struct DisplaySurface *new_surface)
{
SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
EGLint stride, fourcc;
int fd;
EGLint stride = 0, fourcc = 0;
int fd = -1;
int width = 0, height = 0;
if (ssd->ds) {
surface_gl_destroy_texture(ssd->gls, ssd->ds);
}
ssd->ds = new_surface;
width = surface_width(new_surface);
height = surface_height(new_surface);
if (ssd->ds) {
surface_gl_create_texture(ssd->gls, ssd->ds);
#if defined(CONFIG_GBM)
fd = egl_get_fd_for_texture(ssd->ds->texture,
&stride, &fourcc,
NULL);
@@ -890,31 +1072,48 @@ static void spice_gl_switch(DisplayChangeListener *dcl,
surface_gl_destroy_texture(ssd->gls, ssd->ds);
return;
}
#elif defined(CONFIG_IOSURFACE)
if (spice_iosurface_resize(ssd, width, height)) {
fd = spice_iosurface_create_fd(ssd, &fourcc);
if (fd < 0) {
error_report("spice_gl_switch: failed to create fd");
return;
}
} else {
error_report("spice_gl_switch: failed to create IOSurface");
return;
}
#endif
trace_qemu_spice_gl_surface(ssd->qxl.id,
surface_width(ssd->ds),
surface_height(ssd->ds),
width,
height,
fourcc);
/* note: spice server will close the fd */
spice_qxl_gl_scanout(&ssd->qxl, fd,
surface_width(ssd->ds),
surface_height(ssd->ds),
width,
height,
stride, fourcc, false);
ssd->have_surface = true;
ssd->have_scanout = false;
qemu_spice_gl_monitor_config(ssd, 0, 0,
surface_width(ssd->ds),
surface_height(ssd->ds));
width,
height);
}
}
static QEMUGLContext qemu_spice_gl_create_context(DisplayGLCtx *dgc,
QEMUGLParams *params)
{
#if defined(CONFIG_GBM)
eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
qemu_egl_rn_ctx);
#elif defined(CONFIG_ANGLE)
eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
spice_gl_ctx);
#endif
return qemu_egl_create_context(dgc, params);
}
@@ -927,22 +1126,44 @@ static void qemu_spice_gl_scanout_disable(DisplayChangeListener *dcl)
qemu_spice_gl_monitor_config(ssd, 0, 0, 0, 0);
ssd->have_surface = false;
ssd->have_scanout = false;
#if defined(CONFIG_IOSURFACE)
spice_iosurface_destroy(ssd);
#endif
#if defined(CONFIG_ANGLE)
ssd->backing_borrow = NULL;
ssd->backing_id = -1;
#endif
}
static void qemu_spice_gl_scanout_texture(DisplayChangeListener *dcl,
uint32_t tex_id,
bool y_0_top,
uint32_t backing_width,
uint32_t backing_height,
uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h)
{
SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
EGLint stride = 0, fourcc = 0;
int fd = -1;
bool y_0_top;
uint32_t backing_width;
uint32_t backing_height;
GLuint tex_id = backing_borrow(backing_id, &y_0_top,
&backing_width, &backing_height);
assert(tex_id);
#if defined(CONFIG_GBM)
fd = egl_get_fd_for_texture(tex_id, &stride, &fourcc, NULL);
#elif defined(CONFIG_IOSURFACE)
if (spice_iosurface_resize(ssd, backing_width, backing_height)) {
#if defined(CONFIG_ANGLE)
ssd->backing_borrow = backing_borrow;
ssd->backing_id = backing_id;
#endif
fd = spice_iosurface_create_fd(ssd, &fourcc);
} else {
fd = -1;
}
#endif
if (fd < 0) {
fprintf(stderr, "%s: failed to get fd for texture\n", __func__);
return;
@@ -957,6 +1178,7 @@ static void qemu_spice_gl_scanout_texture(DisplayChangeListener *dcl,
ssd->have_scanout = true;
}
#ifdef CONFIG_GBM
static void qemu_spice_gl_scanout_dmabuf(DisplayChangeListener *dcl,
QemuDmaBuf *dmabuf)
{
@@ -1014,21 +1236,25 @@ static void qemu_spice_gl_release_dmabuf(DisplayChangeListener *dcl,
}
egl_dmabuf_release_texture(dmabuf);
}
#endif // CONFIG_GBM
static void qemu_spice_gl_update(DisplayChangeListener *dcl,
uint32_t x, uint32_t y, uint32_t w, uint32_t h)
{
SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
#ifdef CONFIG_GBM
EGLint stride = 0, fourcc = 0;
int fd;
bool render_cursor = false;
#endif
bool y_0_top = false; /* FIXME */
uint64_t cookie;
int fd;
if (!ssd->have_scanout) {
return;
}
#ifdef CONFIG_GBM
if (ssd->cursor_fb.texture) {
render_cursor = true;
}
@@ -1085,11 +1311,17 @@ static void qemu_spice_gl_update(DisplayChangeListener *dcl,
y = ssd->ptr_y;
qemu_mutex_unlock(&ssd->lock);
egl_texture_blit(ssd->gls, &ssd->blit_fb, &ssd->guest_fb,
!y_0_top);
!y_0_top, false);
egl_texture_blend(ssd->gls, &ssd->blit_fb, &ssd->cursor_fb,
!y_0_top, x, y, 1.0, 1.0);
!y_0_top, false, x, y, 1.0, 1.0);
glFlush();
}
#elif defined(CONFIG_ANGLE) && defined(CONFIG_IOSURFACE)
GLuint tex_id = ssd->backing_borrow(ssd->backing_id, &y_0_top,
NULL, NULL);
spice_iosurface_blit(ssd, tex_id, !y_0_top, false);
//TODO: cursor stuff
#endif
trace_qemu_spice_gl_update(ssd->qxl.id, w, h, x, y);
qemu_spice_gl_block(ssd, true);
@@ -1109,10 +1341,12 @@ static const DisplayChangeListenerOps display_listener_gl_ops = {
.dpy_gl_scanout_disable = qemu_spice_gl_scanout_disable,
.dpy_gl_scanout_texture = qemu_spice_gl_scanout_texture,
#ifdef CONFIG_GBM
.dpy_gl_scanout_dmabuf = qemu_spice_gl_scanout_dmabuf,
.dpy_gl_cursor_dmabuf = qemu_spice_gl_cursor_dmabuf,
.dpy_gl_cursor_position = qemu_spice_gl_cursor_position,
.dpy_gl_release_dmabuf = qemu_spice_gl_release_dmabuf,
#endif
.dpy_gl_update = qemu_spice_gl_update,
};
@@ -1149,6 +1383,15 @@ static void qemu_spice_display_init_one(QemuConsole *con)
ssd->gls = qemu_gl_init_shader();
ssd->have_surface = false;
ssd->have_scanout = false;
#if defined(CONFIG_IOSURFACE)
ssd->iosurface = NULL;
ssd->surface_send_fd = -1;
#endif
#if defined(CONFIG_ANGLE)
ssd->esurface = EGL_NO_SURFACE;
ssd->backing_borrow = NULL;
ssd->backing_id = -1;
#endif
}
#endif
ssd->dcl.con = con;
Loaded 100 of 104 files, more files were not shown because too many files have changed in this diff. Show more