mirror of
https://github.com/utmapp/qemu.git
synced 2026-12-01 22:23:23 -10:00
Compare commits
97
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
753fffe1ea | ||
|
|
e19e3cb9b5 | ||
|
|
26324b7d94 | ||
|
|
929b3859bd | ||
|
|
fdd3d1d3a0 | ||
|
|
345ec3279b | ||
|
|
e8f8220618 | ||
|
|
f275f433af | ||
|
|
f384e2c7eb | ||
|
|
dc386f9eb0 | ||
|
|
1adb9ff17d | ||
|
|
ce01739e6d | ||
|
|
f357b925b3 | ||
|
|
edba23a4d4 | ||
|
|
3428101c02 | ||
|
|
1e8db1949d | ||
|
|
e91d59cbea | ||
|
|
eace1c8c9f | ||
|
|
c800dbb61e | ||
|
|
b3a305701e | ||
|
|
21954ae12a | ||
|
|
61f5befa07 | ||
|
|
45c171c238 | ||
|
|
1b10cab21a | ||
|
|
c61c853e1f | ||
|
|
8681835e66 | ||
|
|
adaef950b5 | ||
|
|
a1cbf10708 | ||
|
|
d0c0d66796 | ||
|
|
920d2875a0 | ||
|
|
5ba17fba6e | ||
|
|
51f8c2e5b8 | ||
|
|
3184f37bbe | ||
|
|
110dbe7e89 | ||
|
|
2565eea22b | ||
|
|
8c2f5eff66 | ||
|
|
db430377c0 | ||
|
|
b2708c4684 | ||
|
|
9ea8f7a804 | ||
|
|
6a1e678f5b | ||
|
|
902616b2f0 | ||
|
|
bc73e87997 | ||
|
|
7292f1fc18 | ||
|
|
2ee6330b9e | ||
|
|
a0db5bfa90 | ||
|
|
998320a3da | ||
|
|
8137225fde | ||
|
|
3f09807e7f | ||
|
|
17d38dc6d9 | ||
|
|
66c71d88ed | ||
|
|
30adfa9b1d | ||
|
|
3bf12f1f40 | ||
|
|
4c82b50085 | ||
|
|
f3b4506f14 | ||
|
|
056bdd9a51 | ||
|
|
0bc7389a8e | ||
|
|
9517f7e873 | ||
|
|
30c2f78449 | ||
|
|
ea9f45cec5 | ||
|
|
82e6e2bdff | ||
|
|
ffb51175ba | ||
|
|
a13fec6c17 | ||
|
|
cf664b3a04 | ||
|
|
5897229105 | ||
|
|
d35954d3c9 | ||
|
|
64dcc3969b | ||
|
|
06962e1aaa | ||
|
|
ec151f4659 | ||
|
|
9d9ca24b72 | ||
|
|
fe1b754eab | ||
|
|
6d6e43ebce | ||
|
|
f479e7eacd | ||
|
|
dbbbd13bf6 | ||
|
|
dc32fd2d89 | ||
|
|
3354c800ac | ||
|
|
365294d55a | ||
|
|
a6bff5ccc8 | ||
|
|
c803fc9d7d | ||
|
|
653cc15628 | ||
|
|
2e77c788d8 | ||
|
|
1534c4fe04 | ||
|
|
3a513c9db4 | ||
|
|
e27df17c9c | ||
|
|
aa7ebf9a77 | ||
|
|
be54898fd5 | ||
|
|
7a64de81ce | ||
|
|
71f21b796f | ||
|
|
4e70afa94d | ||
|
|
36195a781c | ||
|
|
2541dde936 | ||
|
|
ecc067a3ba | ||
|
|
819b2c2984 | ||
|
|
8ed0f7cb4d | ||
|
|
d1bf1e28b6 | ||
|
|
47cd50d3d2 | ||
|
|
324cef19f8 | ||
|
|
e252078b6e |
No files matched your search
+6
-3
@@ -49,9 +49,9 @@
|
||||
[submodule "roms/edk2"]
|
||||
path = roms/edk2
|
||||
url = https://gitlab.com/qemu-project/edk2.git
|
||||
[submodule "slirp"]
|
||||
path = slirp
|
||||
url = https://gitlab.com/qemu-project/libslirp.git
|
||||
[submodule "subprojects/libslirp"]
|
||||
path = subprojects/libslirp
|
||||
url = https://git.qemu.org/git/libslirp.git
|
||||
[submodule "roms/opensbi"]
|
||||
path = roms/opensbi
|
||||
url = https://gitlab.com/qemu-project/opensbi.git
|
||||
@@ -64,3 +64,6 @@
|
||||
[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
|
||||
@@ -433,6 +433,11 @@ F: accel/accel-*.c
|
||||
F: accel/Makefile.objs
|
||||
F: accel/stubs/Makefile.objs
|
||||
|
||||
Apple Silicon HVF CPUs
|
||||
M: Alexander Graf <[email protected]>
|
||||
S: Maintained
|
||||
F: target/arm/hvf/
|
||||
|
||||
X86 HVF CPUs
|
||||
M: Cameron Esfahani <[email protected]>
|
||||
M: Roman Bolshakov <[email protected]>
|
||||
|
||||
@@ -60,6 +60,10 @@
|
||||
|
||||
HVFState *hvf_state;
|
||||
|
||||
#ifdef __aarch64__
|
||||
#define HV_VM_DEFAULT NULL
|
||||
#endif
|
||||
|
||||
/* Memory slots */
|
||||
|
||||
hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t size)
|
||||
@@ -365,17 +369,20 @@ static int hvf_init_vcpu(CPUState *cpu)
|
||||
cpu->hvf = g_malloc0(sizeof(*cpu->hvf));
|
||||
|
||||
/* init cpu signals */
|
||||
sigset_t set;
|
||||
struct sigaction sigact;
|
||||
|
||||
memset(&sigact, 0, sizeof(sigact));
|
||||
sigact.sa_handler = dummy_signal;
|
||||
sigaction(SIG_IPI, &sigact, NULL);
|
||||
|
||||
pthread_sigmask(SIG_BLOCK, NULL, &set);
|
||||
sigdelset(&set, SIG_IPI);
|
||||
pthread_sigmask(SIG_BLOCK, NULL, &cpu->hvf->unblock_ipi_mask);
|
||||
sigdelset(&cpu->hvf->unblock_ipi_mask, SIG_IPI);
|
||||
|
||||
#ifdef __aarch64__
|
||||
r = hv_vcpu_create(&cpu->hvf->fd, (hv_vcpu_exit_t **)&cpu->hvf->exit, NULL);
|
||||
#else
|
||||
r = hv_vcpu_create((hv_vcpuid_t *)&cpu->hvf->fd, HV_VCPU_DEFAULT);
|
||||
#endif
|
||||
cpu->vcpu_dirty = 1;
|
||||
assert_hvf_ok(r);
|
||||
|
||||
@@ -446,11 +453,17 @@ static void hvf_start_vcpu_thread(CPUState *cpu)
|
||||
cpu, QEMU_THREAD_JOINABLE);
|
||||
}
|
||||
|
||||
__attribute__((weak)) void hvf_kick_vcpu_thread(CPUState *cpu)
|
||||
{
|
||||
cpus_kick_thread(cpu);
|
||||
}
|
||||
|
||||
static void hvf_accel_ops_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
|
||||
|
||||
ops->create_vcpu_thread = hvf_start_vcpu_thread;
|
||||
ops->kick_vcpu_thread = hvf_kick_vcpu_thread;
|
||||
|
||||
ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset;
|
||||
ops->synchronize_post_init = hvf_cpu_synchronize_post_init;
|
||||
|
||||
@@ -25,6 +25,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/compiler.h"
|
||||
#include "qemu/timer.h"
|
||||
|
||||
@@ -45,6 +45,11 @@ void tcg_cpu_init_cflags(CPUState *cpu, bool parallel)
|
||||
uint32_t cflags = cpu->cluster_index << CF_CLUSTER_SHIFT;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,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__)
|
||||
|
||||
+25
-22
@@ -356,7 +356,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,
|
||||
@@ -369,20 +372,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;
|
||||
}
|
||||
@@ -393,31 +395,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;
|
||||
}
|
||||
@@ -426,11 +428,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;
|
||||
}
|
||||
@@ -438,7 +438,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;
|
||||
}
|
||||
|
||||
@@ -452,20 +451,24 @@ 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;
|
||||
core->ioprocid = ioprocid;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -551,7 +554,7 @@ static OSStatus handle_voice_change(
|
||||
}
|
||||
|
||||
status = init_out_device(core);
|
||||
if (!status) {
|
||||
if (core->outputDeviceID) {
|
||||
update_device_playback_state(core);
|
||||
}
|
||||
|
||||
|
||||
+19
-2
@@ -43,10 +43,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>
|
||||
@@ -134,6 +134,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;
|
||||
@@ -652,7 +660,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);
|
||||
@@ -1018,6 +1030,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
|
||||
|
||||
@@ -347,6 +347,7 @@ tsan="no"
|
||||
fortify_source="$default_feature"
|
||||
strip_opt="yes"
|
||||
tcg_interpreter="false"
|
||||
tcg_threaded_interpreter="false"
|
||||
bigendian="no"
|
||||
mingw32="no"
|
||||
gcov="no"
|
||||
@@ -380,6 +381,7 @@ u2f="auto"
|
||||
libusb="auto"
|
||||
usb_redir="auto"
|
||||
opengl="$default_feature"
|
||||
egl="no"
|
||||
cpuid_h="no"
|
||||
avx2_opt="$default_feature"
|
||||
capstone="auto"
|
||||
@@ -445,6 +447,7 @@ fuse="auto"
|
||||
fuse_lseek="auto"
|
||||
multiprocess="auto"
|
||||
slirp_smbd="$default_feature"
|
||||
shared_lib="false"
|
||||
|
||||
malloc_trim="auto"
|
||||
gio="$default_feature"
|
||||
@@ -1114,6 +1117,10 @@ for opt do
|
||||
;;
|
||||
--enable-tcg-interpreter) tcg_interpreter="true"
|
||||
;;
|
||||
--disable-tcg-tcti) tcg_threaded_interpreter="false"
|
||||
;;
|
||||
--enable-tcg-tcti) tcg_threaded_interpreter="true"
|
||||
;;
|
||||
--disable-cap-ng) cap_ng="disabled"
|
||||
;;
|
||||
--enable-cap-ng) cap_ng="enabled"
|
||||
@@ -1581,6 +1588,12 @@ for opt do
|
||||
;;
|
||||
--disable-slirp-smbd) slirp_smbd=no
|
||||
;;
|
||||
--enable-shared-lib)
|
||||
shared_lib=true
|
||||
plugins="no"
|
||||
;;
|
||||
--disable-shared-lib) shared_lib=false
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: unknown option $opt"
|
||||
echo "Try '$0 --help' for more information"
|
||||
@@ -1594,6 +1607,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" = "true"; 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
|
||||
@@ -1824,7 +1841,7 @@ Advanced options (experts only):
|
||||
--oss-lib path to OSS library
|
||||
--cpu=CPU Build for host CPU [$cpu]
|
||||
--with-coroutine=BACKEND coroutine backend. Supported options:
|
||||
ucontext, sigaltstack, windows
|
||||
ucontext, libucontext, sigaltstack, windows
|
||||
--enable-gcov enable test coverage analysis with gcov
|
||||
--disable-blobs disable installing provided firmware blobs
|
||||
--with-vss-sdk=SDK-path enable Windows VSS support in QEMU Guest Agent
|
||||
@@ -1838,6 +1855,7 @@ Advanced options (experts only):
|
||||
enable plugins via shared library loading
|
||||
--disable-containers don't use containers for cross-building
|
||||
--gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
|
||||
--enable-shared-lib build QEMU as a shared library
|
||||
|
||||
Optional features, enabled with --enable-FEATURE and
|
||||
disabled with --disable-FEATURE, default is enabled if available
|
||||
@@ -3460,18 +3478,7 @@ if $pkg_config gbm; then
|
||||
fi
|
||||
|
||||
if test "$opengl" != "no" ; then
|
||||
epoxy=no
|
||||
if $pkg_config epoxy; then
|
||||
cat > $TMPC << EOF
|
||||
#include <epoxy/egl.h>
|
||||
int main(void) { return 0; }
|
||||
EOF
|
||||
if compile_prog "" "" ; then
|
||||
epoxy=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$epoxy" = "yes" ; then
|
||||
opengl_cflags="$($pkg_config --cflags epoxy)"
|
||||
opengl_libs="$($pkg_config --libs epoxy)"
|
||||
opengl=yes
|
||||
@@ -3485,6 +3492,16 @@ EOF
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$opengl" = "yes"; then
|
||||
cat > $TMPC << EOF
|
||||
#include <epoxy/egl.h>
|
||||
int main(void) { return 0; }
|
||||
EOF
|
||||
if compile_prog "" "" ; then
|
||||
egl=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
##########################################
|
||||
# libnuma probe
|
||||
|
||||
@@ -3761,12 +3778,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
|
||||
|
||||
if test "$coroutine_pool" = ""; then
|
||||
coroutine_pool=yes
|
||||
fi
|
||||
@@ -4238,7 +4269,7 @@ fi
|
||||
case "$slirp" in
|
||||
auto | enabled | internal)
|
||||
# Simpler to always update submodule, even if not needed.
|
||||
git_submodules="${git_submodules} slirp"
|
||||
git_submodules="${git_submodules} subprojects/libslirp"
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -4679,6 +4710,9 @@ if test "$opengl" = "yes" ; then
|
||||
echo "CONFIG_OPENGL=y" >> $config_host_mak
|
||||
echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
|
||||
echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
|
||||
if test "$egl" = "yes" ; then
|
||||
echo "CONFIG_EGL=y" >> $config_host_mak
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$gbm" = "yes" ; then
|
||||
@@ -4705,7 +4739,7 @@ if test "$qom_cast_debug" = "yes" ; then
|
||||
echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
|
||||
fi
|
||||
|
||||
echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
|
||||
echo "CONFIG_COROUTINE_BACKEND=$coroutine_impl" >> $config_host_mak
|
||||
if test "$coroutine_pool" = "yes" ; then
|
||||
echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
|
||||
else
|
||||
@@ -5126,7 +5160,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" = "true"; then
|
||||
echo "strip = [$(meson_quote $strip), '-x']" >> $cross
|
||||
else
|
||||
echo "strip = [$(meson_quote $strip)]" >> $cross
|
||||
fi
|
||||
echo "windres = [$(meson_quote $windres)]" >> $cross
|
||||
if test "$cross_compile" = "yes"; then
|
||||
cross_arg="--cross-file config-meson.cross"
|
||||
@@ -5207,11 +5245,12 @@ if test "$skip_meson" = no; then
|
||||
-Dgnutls=$gnutls -Dnettle=$nettle -Dgcrypt=$gcrypt -Dauth_pam=$auth_pam \
|
||||
-Dzstd=$zstd -Dseccomp=$seccomp -Dvirtfs=$virtfs -Dcap_ng=$cap_ng \
|
||||
-Dattr=$attr -Ddefault_devices=$default_devices -Dvirglrenderer=$virglrenderer \
|
||||
-Ddocs=$docs -Dsphinx_build=$sphinx_build -Dinstall_blobs=$blobs \
|
||||
-Ducontext=$libucontext -Ddocs=$docs -Dsphinx_build=$sphinx_build -Dinstall_blobs=$blobs \
|
||||
-Dvhost_user_blk_server=$vhost_user_blk_server -Dmultiprocess=$multiprocess \
|
||||
-Dfuse=$fuse -Dfuse_lseek=$fuse_lseek -Dguest_agent_msi=$guest_agent_msi -Dbpf=$bpf\
|
||||
$(if test "$default_feature" = no; then echo "-Dauto_features=disabled"; fi) \
|
||||
-Dtcg_interpreter=$tcg_interpreter \
|
||||
-Dtcg_interpreter=$tcg_interpreter -Dtcg_threaded_interpreter=$tcg_threaded_interpreter \
|
||||
-Dshared_lib=$shared_lib \
|
||||
$cross_arg \
|
||||
"$PWD" "$source_path"
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.print_insn = print_insn_i386;
|
||||
|
||||
@@ -50,3 +50,6 @@ config CS4231
|
||||
|
||||
config MARVELL_88W8618
|
||||
bool
|
||||
|
||||
config SCREAMER
|
||||
bool
|
||||
@@ -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'))
|
||||
@@ -0,0 +1,985 @@
|
||||
/*
|
||||
* 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.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);
|
||||
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)
|
||||
@@ -58,6 +58,7 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU')
|
||||
if_true: [files('virtio-gpu-base.c', 'virtio-gpu.c'), pixman])
|
||||
virtio_gpu_ss.add(when: 'CONFIG_LINUX', if_true: files('virtio-gpu-udmabuf.c'))
|
||||
virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-user-gpu.c'))
|
||||
virtio_gpu_ss.add(when: 'CONFIG_FW_CFG_DMA', if_true: files('virtio-ramfb.c'))
|
||||
hw_display_modules += {'virtio-gpu': virtio_gpu_ss}
|
||||
|
||||
virtio_gpu_gl_ss = ss.source_set()
|
||||
|
||||
@@ -249,7 +249,7 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg)
|
||||
}
|
||||
|
||||
con = g->parent_obj.scanout[m->scanout_id].con;
|
||||
if (!console_has_gl(con)) {
|
||||
if (!console_has_gl()) {
|
||||
error_report("console doesn't support GL!");
|
||||
vhost_user_gpu_unblock(g);
|
||||
break;
|
||||
|
||||
@@ -79,6 +79,7 @@ static int virtio_gpu_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
|
||||
|
||||
g->req_state[idx].x = info->xoff;
|
||||
g->req_state[idx].y = info->yoff;
|
||||
g->req_state[idx].refresh_rate = info->refresh_rate;
|
||||
g->req_state[idx].width = info->width;
|
||||
g->req_state[idx].height = info->height;
|
||||
g->req_state[idx].width_mm = info->width_mm;
|
||||
|
||||
@@ -140,12 +140,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 & 1 /* FIXME: 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,
|
||||
@@ -159,24 +186,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 & 1 /* FIXME: 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(
|
||||
|
||||
@@ -217,6 +217,7 @@ virtio_gpu_generate_edid(VirtIOGPU *g, int scanout,
|
||||
.height_mm = b->req_state[scanout].height_mm,
|
||||
.prefx = b->req_state[scanout].width,
|
||||
.prefy = b->req_state[scanout].height,
|
||||
.refresh_rate = b->req_state[scanout].refresh_rate,
|
||||
};
|
||||
|
||||
edid->size = cpu_to_le32(sizeof(edid->edid));
|
||||
@@ -514,7 +515,7 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g,
|
||||
for (i = 0; i < g->parent_obj.conf.max_outputs; i++) {
|
||||
scanout = &g->parent_obj.scanout[i];
|
||||
if (scanout->resource_id == res->resource_id &&
|
||||
console_has_gl(scanout->con)) {
|
||||
console_has_gl()) {
|
||||
dpy_gl_update(scanout->con, 0, 0, scanout->width,
|
||||
scanout->height);
|
||||
return;
|
||||
@@ -626,7 +627,7 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g,
|
||||
g->parent_obj.enable = 1;
|
||||
|
||||
if (res->blob) {
|
||||
if (console_has_gl(scanout->con)) {
|
||||
if (console_has_gl()) {
|
||||
if (!virtio_gpu_update_dmabuf(g, scanout_id, res, fb)) {
|
||||
virtio_gpu_update_scanout(g, scanout_id, res, r);
|
||||
return;
|
||||
@@ -639,7 +640,7 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g,
|
||||
}
|
||||
|
||||
/* create a surface for this scanout */
|
||||
if ((res->blob && !console_has_gl(scanout->con)) ||
|
||||
if ((res->blob && !console_has_gl()) ||
|
||||
!scanout->ds ||
|
||||
surface_data(scanout->ds) != data + fb->offset ||
|
||||
scanout->width != r->width ||
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "hw/pci/pci.h"
|
||||
#include "ui/console.h"
|
||||
#include "hw/qdev-properties.h"
|
||||
#include "hw/virtio/virtio-gpu-pci.h"
|
||||
#include "qapi/error.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;
|
||||
};
|
||||
|
||||
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 int virtio_ramfb_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
|
||||
{
|
||||
VirtIORAMFBBase *vramfb = opaque;
|
||||
VirtIOGPUBase *g = vramfb->vgpu;
|
||||
|
||||
if (g->hw_ops->ui_info) {
|
||||
return g->hw_ops->ui_info(g, idx, info);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
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 void virtio_ramfb_gl_flushed(void *opaque)
|
||||
{
|
||||
VirtIORAMFBBase *vramfb = opaque;
|
||||
VirtIOGPUBase *g = vramfb->vgpu;
|
||||
|
||||
if (g->hw_ops->gl_flushed) {
|
||||
g->hw_ops->gl_flushed(g);
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
.gl_flushed = virtio_ramfb_gl_flushed,
|
||||
};
|
||||
|
||||
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 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;
|
||||
VirtIOGPUGL vdevgl;
|
||||
};
|
||||
|
||||
static void virtio_ramfb_inst_initfn(Object *obj)
|
||||
{
|
||||
VirtIORAMFB *dev = VIRTIO_RAMFB(obj);
|
||||
|
||||
if (display_opengl) {
|
||||
virtio_instance_init_common(obj, &dev->vdevgl, sizeof(dev->vdevgl),
|
||||
TYPE_VIRTIO_GPU_GL);
|
||||
VIRTIO_RAMFB_BASE(dev)->vgpu = VIRTIO_GPU_BASE(&dev->vdevgl);
|
||||
} else {
|
||||
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)
|
||||
+11
-3
@@ -777,16 +777,24 @@ static void xenfb_update(void *opaque)
|
||||
xenfb->up_fullscreen = 0;
|
||||
}
|
||||
|
||||
static void xenfb_update_interval(void *opaque, uint64_t interval)
|
||||
static void xenfb_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
|
||||
{
|
||||
struct XenFB *xenfb = opaque;
|
||||
uint32_t refresh_rate;
|
||||
|
||||
if (xenfb->feature_update) {
|
||||
#ifdef XENFB_TYPE_REFRESH_PERIOD
|
||||
if (xenfb_queue_full(xenfb)) {
|
||||
return;
|
||||
}
|
||||
xenfb_send_refresh_period(xenfb, interval);
|
||||
|
||||
refresh_rate = info->refresh_rate;
|
||||
if (!refresh_rate) {
|
||||
refresh_rate = 75;
|
||||
}
|
||||
|
||||
/* T = 1 / f = 1 [s*Hz] / f = 1000*1000 [ms*mHz] / f */
|
||||
xenfb_send_refresh_period(xenfb, 1000 * 1000 / refresh_rate);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -983,5 +991,5 @@ struct XenDevOps xen_framebuffer_ops = {
|
||||
static const GraphicHwOps xenfb_ops = {
|
||||
.invalidate = xenfb_invalidate,
|
||||
.gfx_update = xenfb_update,
|
||||
.update_interval = xenfb_update_interval,
|
||||
.ui_info = xenfb_ui_info,
|
||||
};
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "hw/misc/macio/macio.h"
|
||||
#include "hw/intc/heathrow_pic.h"
|
||||
#include "trace.h"
|
||||
#include "include/hw/audio/screamer.h"
|
||||
|
||||
/* Note: this code is strongly inspirated from the corresponding code
|
||||
* in PearPC */
|
||||
@@ -104,6 +105,17 @@ static void macio_common_realize(PCIDevice *d, Error **errp)
|
||||
sysbus_dev = SYS_BUS_DEVICE(&s->dbdma);
|
||||
memory_region_add_subregion(&s->bar, 0x08000,
|
||||
sysbus_mmio_get_region(sysbus_dev, 0));
|
||||
if (!qdev_realize(DEVICE(&s->screamer), BUS(&s->macio_bus), errp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Add the screamer sound chip */
|
||||
sysbus_dev = 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(sysbus_dev,
|
||||
region_number));
|
||||
|
||||
qdev_prop_set_uint32(DEVICE(&s->escc), "disabled", 0);
|
||||
qdev_prop_set_uint32(DEVICE(&s->escc), "frequency", ESCC_CLOCK);
|
||||
@@ -364,6 +376,19 @@ static void macio_newworld_realize(PCIDevice *d, Error **errp)
|
||||
memory_region_add_subregion(&s->bar, 0x16000,
|
||||
sysbus_mmio_get_region(sysbus_dev, 0));
|
||||
}
|
||||
|
||||
/* Screamer Sound Chip */
|
||||
const int gpio_0 = 0;
|
||||
const int gpio_1 = 1;
|
||||
const int transmit_channel = 0x10;
|
||||
const int receive_channel = 0x12;
|
||||
sysbus_dev = SYS_BUS_DEVICE(&s->screamer);
|
||||
sysbus_connect_irq(sysbus_dev, gpio_0, qdev_get_gpio_in(pic_dev,
|
||||
NEWWORLD_SCREAMER_IRQ));
|
||||
sysbus_connect_irq(sysbus_dev, gpio_1, qdev_get_gpio_in(pic_dev,
|
||||
NEWWORLD_SCREAMER_DMA_IRQ));
|
||||
screamer_register_dma_functions(SCREAMER(sysbus_dev), &s->dbdma,
|
||||
transmit_channel, receive_channel);
|
||||
}
|
||||
|
||||
static void macio_newworld_init(Object *obj)
|
||||
@@ -393,6 +418,9 @@ static void macio_instance_init(Object *obj)
|
||||
object_initialize_child(OBJECT(s), "dbdma", &s->dbdma, TYPE_MAC_DBDMA);
|
||||
|
||||
object_initialize_child(OBJECT(s), "escc", &s->escc, TYPE_ESCC);
|
||||
|
||||
object_initialize_child(OBJECT(s), SOUND_CHIP_NAME, &s->screamer,
|
||||
TYPE_SCREAMER);
|
||||
}
|
||||
|
||||
static const VMStateDescription vmstate_macio_oldworld = {
|
||||
|
||||
@@ -119,6 +119,7 @@ config MAC_NEWWORLD
|
||||
select MAC_PMU
|
||||
select UNIN_PCI
|
||||
select FW_CFG_PPC
|
||||
select SCREAMER
|
||||
|
||||
config E500
|
||||
bool
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "hw/pci/pci_host.h"
|
||||
#include "hw/pci-host/uninorth.h"
|
||||
#include "qom/object.h"
|
||||
#include "hw/ppc/mac_dbdma.h"
|
||||
#include "audio/audio.h"
|
||||
|
||||
/* SMP is not enabled, for now */
|
||||
#define MAX_CPUS 1
|
||||
@@ -67,6 +69,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
|
||||
|
||||
/* Core99 machine */
|
||||
#define TYPE_CORE99_MACHINE MACHINE_TYPE_NAME("mac99")
|
||||
|
||||
@@ -415,6 +415,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*);
|
||||
|
||||
@@ -588,7 +588,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
|
||||
|
||||
@@ -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 */
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "hw/ppc/mac.h"
|
||||
#include "hw/ppc/mac_dbdma.h"
|
||||
#include "hw/ppc/openpic.h"
|
||||
#include "hw/audio/screamer.h"
|
||||
#include "qom/object.h"
|
||||
|
||||
/* MacIO virtual bus */
|
||||
@@ -88,6 +89,7 @@ struct MacIOState {
|
||||
PMUState pmu;
|
||||
DBDMAState dbdma;
|
||||
ESCCState escc;
|
||||
ScreamerState screamer;
|
||||
uint64_t frequency;
|
||||
};
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ struct virtio_gpu_scanout {
|
||||
struct virtio_gpu_requested_state {
|
||||
uint16_t width_mm, height_mm;
|
||||
uint32_t width, height;
|
||||
uint32_t refresh_rate;
|
||||
int x, y;
|
||||
};
|
||||
|
||||
|
||||
@@ -762,30 +762,6 @@ char *qemu_get_host_name(Error **errp);
|
||||
*/
|
||||
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_MAX_ALLOWED >= MAC_OS_VERSION_11_0
|
||||
static inline void qemu_thread_jit_execute(void)
|
||||
{
|
||||
if (__builtin_available(macOS 11.0, *)) {
|
||||
pthread_jit_write_protect_np(true);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void qemu_thread_jit_write(void)
|
||||
{
|
||||
if (__builtin_available(macOS 11.0, *)) {
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,11 @@
|
||||
#ifndef HVF_INT_H
|
||||
#define HVF_INT_H
|
||||
|
||||
#ifdef __aarch64__
|
||||
#include <Hypervisor/Hypervisor.h>
|
||||
#else
|
||||
#include <Hypervisor/hv.h>
|
||||
#endif
|
||||
|
||||
/* hvf_slot flags */
|
||||
#define HVF_SLOT_LOG (1 << 0)
|
||||
@@ -44,7 +48,10 @@ struct HVFState {
|
||||
extern HVFState *hvf_state;
|
||||
|
||||
struct hvf_vcpu_state {
|
||||
int fd;
|
||||
uint64_t fd;
|
||||
void *exit;
|
||||
bool vtimer_masked;
|
||||
sigset_t unblock_ipi_mask;
|
||||
};
|
||||
|
||||
void assert_hvf_ok(hv_return_t ret);
|
||||
@@ -54,5 +61,6 @@ int hvf_vcpu_exec(CPUState *);
|
||||
hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
|
||||
int hvf_put_registers(CPUState *);
|
||||
int hvf_get_registers(CPUState *);
|
||||
void hvf_kick_vcpu_thread(CPUState *cpu);
|
||||
|
||||
#endif
|
||||
@@ -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 */
|
||||
@@ -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
@@ -1236,7 +1236,7 @@ static inline unsigned get_mmuidx(TCGMemOpIdx oi)
|
||||
#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);
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* QEMU Cocoa CG display driver
|
||||
*
|
||||
* Copyright (c) 2008 Mike Kronenberg
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef UI_COCOA_H
|
||||
#define UI_COCOA_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "ui/clipboard.h"
|
||||
#include "ui/console.h"
|
||||
#include "ui/kbd-state.h"
|
||||
#include "qemu/thread.h"
|
||||
|
||||
//#define DEBUG
|
||||
|
||||
#ifdef DEBUG
|
||||
#define COCOA_DEBUG(...) { (void) fprintf (stdout, __VA_ARGS__); }
|
||||
#else
|
||||
#define COCOA_DEBUG(...) ((void) 0)
|
||||
#endif
|
||||
|
||||
typedef void (^CodeBlock)(void);
|
||||
typedef bool (^BoolCodeBlock)(void);
|
||||
|
||||
typedef struct {
|
||||
DisplayChangeListener dcl;
|
||||
DisplaySurface *surface;
|
||||
QemuMutex draw_mutex;
|
||||
int mouse_x;
|
||||
int mouse_y;
|
||||
int mouse_on;
|
||||
CGImageRef cursor_cgimage;
|
||||
int cursor_show;
|
||||
bool swap_option_command;
|
||||
bool inited;
|
||||
} QEMUScreen;
|
||||
|
||||
typedef struct {
|
||||
QemuClipboardInfo *info;
|
||||
QemuEvent event;
|
||||
} QemuCocoaClipboard;
|
||||
|
||||
@interface QemuCocoaView : NSView
|
||||
{
|
||||
NSTextField *pauseLabel;
|
||||
NSTrackingArea *trackingArea;
|
||||
QEMUScreen *screen;
|
||||
int screen_width;
|
||||
int screen_height;
|
||||
QKbdState *kbd;
|
||||
BOOL isMouseGrabbed;
|
||||
BOOL isAbsoluteEnabled;
|
||||
CFMachPortRef eventsTap;
|
||||
}
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
screen:(QEMUScreen *)given_screen;
|
||||
- (void) frameUpdated;
|
||||
- (NSSize) computeUnzoomedSize;
|
||||
- (NSSize) fixZoomedFullScreenSize:(NSSize)proposedSize;
|
||||
- (void) resizeWindow;
|
||||
- (void) updateUIInfo;
|
||||
- (void) updateScreenWidth:(int)w height:(int)h;
|
||||
- (void) grabMouse;
|
||||
- (void) ungrabMouse;
|
||||
- (void) setFullGrab:(id)sender;
|
||||
- (bool) handleEvent:(NSEvent *)event;
|
||||
- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
|
||||
/* The state surrounding mouse grabbing is potentially confusing.
|
||||
* isAbsoluteEnabled tracks qemu_input_is_absolute() [ie "is the emulated
|
||||
* pointing device an absolute-position one?"], but is only updated on
|
||||
* next refresh.
|
||||
* isMouseGrabbed tracks whether GUI events are directed to the guest;
|
||||
* it controls whether special keys like Cmd get sent to the guest,
|
||||
* and whether we capture the mouse when in non-absolute mode.
|
||||
*/
|
||||
- (BOOL) isMouseGrabbed;
|
||||
- (BOOL) isAbsoluteEnabled;
|
||||
- (void) setNeedsDisplayForCursorX:(int)x
|
||||
y:(int)y
|
||||
width:(int)width
|
||||
height:(int)height
|
||||
screenHeight:(int)screen_height;
|
||||
- (void)displayPause;
|
||||
- (void)removePause;
|
||||
@end
|
||||
|
||||
@interface QemuCocoaAppController : NSObject
|
||||
<NSWindowDelegate, NSApplicationDelegate>
|
||||
{
|
||||
QemuSemaphore *started_sem;
|
||||
NSArray * supportedImageFileTypes;
|
||||
QemuCocoaView *cocoaView;
|
||||
}
|
||||
- (id) initWithStartedSem:(QemuSemaphore *)given_started_sem
|
||||
screen:(QEMUScreen *)screen;
|
||||
- (QemuCocoaView *)cocoaView;
|
||||
@end
|
||||
|
||||
@interface QemuCocoaPasteboardTypeOwner : NSObject<NSPasteboardTypeOwner>
|
||||
{
|
||||
QemuCocoaClipboard *cb;
|
||||
}
|
||||
- (id) initWith:(QemuCocoaClipboard *)aCb;
|
||||
@end
|
||||
|
||||
#endif
|
||||
+36
-40
@@ -128,6 +128,7 @@ typedef struct QemuUIInfo {
|
||||
int yoff;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t refresh_rate;
|
||||
} QemuUIInfo;
|
||||
|
||||
/* cursor data format is 32bit RGBA */
|
||||
@@ -206,41 +207,6 @@ typedef struct DisplayChangeListenerOps {
|
||||
QEMUCursor *cursor);
|
||||
|
||||
/* required if GL */
|
||||
QEMUGLContext (*dpy_gl_ctx_create)(DisplayChangeListener *dcl,
|
||||
QEMUGLParams *params);
|
||||
/* required if GL */
|
||||
void (*dpy_gl_ctx_destroy)(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx);
|
||||
/* required if GL */
|
||||
int (*dpy_gl_ctx_make_current)(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx);
|
||||
|
||||
/* required if GL */
|
||||
void (*dpy_gl_scanout_disable)(DisplayChangeListener *dcl);
|
||||
/* 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,
|
||||
uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h);
|
||||
/* optional (default to true if has dpy_gl_scanout_dmabuf) */
|
||||
bool (*dpy_has_dmabuf)(DisplayChangeListener *dcl);
|
||||
/* optional */
|
||||
void (*dpy_gl_scanout_dmabuf)(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf);
|
||||
/* optional */
|
||||
void (*dpy_gl_cursor_dmabuf)(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf, bool have_hot,
|
||||
uint32_t hot_x, uint32_t hot_y);
|
||||
/* optional */
|
||||
void (*dpy_gl_cursor_position)(DisplayChangeListener *dcl,
|
||||
uint32_t pos_x, uint32_t pos_y);
|
||||
/* optional */
|
||||
void (*dpy_gl_release_dmabuf)(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf);
|
||||
/* required if GL */
|
||||
void (*dpy_gl_update)(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
||||
|
||||
@@ -255,6 +221,36 @@ struct DisplayChangeListener {
|
||||
QLIST_ENTRY(DisplayChangeListener) next;
|
||||
};
|
||||
|
||||
typedef uint32_t (* DisplayGLTextureBorrower)(uint32_t id, bool *y_0_top,
|
||||
uint32_t *width, uint32_t *height);
|
||||
|
||||
typedef struct DisplayGLOps {
|
||||
QEMUGLContext (*dpy_gl_ctx_create)(void *dg, QEMUGLParams *params);
|
||||
void (*dpy_gl_ctx_destroy)(void *dg, QEMUGLContext ctx);
|
||||
int (*dpy_gl_ctx_make_current)(void *dg, QEMUGLContext ctx);
|
||||
|
||||
bool (*dpy_gl_scanout_get_enabled)(void *dg);
|
||||
void (*dpy_gl_scanout_disable)(void *dg);
|
||||
void (*dpy_gl_scanout_texture)(void *dg,
|
||||
uint32_t backing_id,
|
||||
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) */
|
||||
bool (*dpy_has_dmabuf)(void *dg);
|
||||
/* optional */
|
||||
void (*dpy_gl_scanout_dmabuf)(void *dg, QemuDmaBuf *dmabuf);
|
||||
/* optional */
|
||||
void (*dpy_gl_cursor_dmabuf)(void *dg,
|
||||
QemuDmaBuf *dmabuf, bool have_hot,
|
||||
uint32_t hot_x, uint32_t hot_y);
|
||||
/* optional */
|
||||
void (*dpy_gl_cursor_position)(void *dg, uint32_t pos_x, uint32_t pos_y);
|
||||
/* optional */
|
||||
void (*dpy_gl_release_dmabuf)(void *dg, QemuDmaBuf *dmabuf);
|
||||
} DisplayGLOps;
|
||||
|
||||
DisplayState *init_displaystate(void);
|
||||
DisplaySurface *qemu_create_displaysurface_from(int width, int height,
|
||||
pixman_format_code_t format,
|
||||
@@ -277,6 +273,7 @@ static inline int is_placeholder(DisplaySurface *surface)
|
||||
return surface->flags & QEMU_PLACEHOLDER_FLAG;
|
||||
}
|
||||
|
||||
void register_displayglops(const DisplayGLOps *dg_ops);
|
||||
void register_displaychangelistener(DisplayChangeListener *dcl);
|
||||
void update_displaychangelistener(DisplayChangeListener *dcl,
|
||||
uint64_t interval);
|
||||
@@ -300,9 +297,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);
|
||||
@@ -320,7 +316,8 @@ QEMUGLContext dpy_gl_ctx_create(QemuConsole *con,
|
||||
void dpy_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx);
|
||||
int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx);
|
||||
|
||||
bool console_has_gl(QemuConsole *con);
|
||||
void console_set_displayglcontext(QemuConsole *con, void *dg);
|
||||
bool console_has_gl(void);
|
||||
|
||||
static inline int surface_stride(DisplaySurface *s)
|
||||
{
|
||||
@@ -380,7 +377,6 @@ typedef struct GraphicHwOps {
|
||||
void (*gfx_update)(void *opaque);
|
||||
bool gfx_update_async; /* if true, calls graphic_hw_update_done() */
|
||||
void (*text_update)(void *opaque, console_ch_t *text);
|
||||
void (*update_interval)(void *opaque, uint64_t interval);
|
||||
int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info);
|
||||
void (*gl_block)(void *opaque, bool block);
|
||||
void (*gl_flushed)(void *opaque);
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
#include "ui/console.h"
|
||||
#include "ui/egl-helpers.h"
|
||||
|
||||
QEMUGLContext qemu_egl_create_context(DisplayChangeListener *dcl,
|
||||
QEMUGLParams *params);
|
||||
void qemu_egl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx);
|
||||
int qemu_egl_make_context_current(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx);
|
||||
QEMUGLContext qemu_egl_create_context(void *dg, QEMUGLParams *params);
|
||||
void qemu_egl_destroy_context(void *dg, QEMUGLContext ctx);
|
||||
int qemu_egl_make_context_current(void *dg, QEMUGLContext ctx);
|
||||
|
||||
#endif /* EGL_CONTEXT_H */
|
||||
@@ -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,14 +20,18 @@ typedef struct egl_fb {
|
||||
int width;
|
||||
int height;
|
||||
GLuint texture;
|
||||
GLenum texture_target;
|
||||
GLuint framebuffer;
|
||||
bool delete_texture;
|
||||
} 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);
|
||||
@@ -48,7 +55,13 @@ void egl_dmabuf_release_texture(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)
|
||||
|
||||
@@ -57,6 +70,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);
|
||||
|
||||
|
||||
+21
-32
@@ -21,7 +21,7 @@
|
||||
#include "ui/clipboard.h"
|
||||
#include "ui/console.h"
|
||||
#include "ui/kbd-state.h"
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
#include "ui/egl-helpers.h"
|
||||
#include "ui/egl-context.h"
|
||||
#endif
|
||||
@@ -42,7 +42,7 @@ typedef struct VirtualGfxConsole {
|
||||
cairo_surface_t *surface;
|
||||
double scale_x;
|
||||
double scale_y;
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
QemuGLShader *gls;
|
||||
EGLContext ectx;
|
||||
EGLSurface esurface;
|
||||
@@ -155,7 +155,7 @@ extern bool gtk_use_gl_area;
|
||||
|
||||
/* ui/gtk.c */
|
||||
void gd_update_windowsize(VirtualConsole *vc);
|
||||
int gd_monitor_update_interval(GtkWidget *widget);
|
||||
void gd_update_monitor_refresh_rate(VirtualConsole *vc, GtkWidget *widget);
|
||||
|
||||
/* ui/gtk-egl.c */
|
||||
void gd_egl_init(VirtualConsole *vc);
|
||||
@@ -165,30 +165,24 @@ void gd_egl_update(DisplayChangeListener *dcl,
|
||||
void gd_egl_refresh(DisplayChangeListener *dcl);
|
||||
void gd_egl_switch(DisplayChangeListener *dcl,
|
||||
DisplaySurface *surface);
|
||||
QEMUGLContext gd_egl_create_context(DisplayChangeListener *dcl,
|
||||
QEMUGLParams *params);
|
||||
void gd_egl_scanout_disable(DisplayChangeListener *dcl);
|
||||
void gd_egl_scanout_texture(DisplayChangeListener *dcl,
|
||||
QEMUGLContext gd_egl_create_context(void *dg, QEMUGLParams *params);
|
||||
bool gd_egl_scanout_get_enabled(void *dg);
|
||||
void gd_egl_scanout_disable(void *dg);
|
||||
void gd_egl_scanout_texture(void *dg,
|
||||
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,
|
||||
QemuDmaBuf *dmabuf);
|
||||
void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl,
|
||||
void gd_egl_scanout_dmabuf(void *dg, QemuDmaBuf *dmabuf);
|
||||
void gd_egl_cursor_dmabuf(void *dg,
|
||||
QemuDmaBuf *dmabuf, bool have_hot,
|
||||
uint32_t hot_x, uint32_t hot_y);
|
||||
void gd_egl_cursor_position(DisplayChangeListener *dcl,
|
||||
uint32_t pos_x, uint32_t pos_y);
|
||||
void gd_egl_release_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf);
|
||||
void gd_egl_cursor_position(void *dg, uint32_t pos_x, uint32_t pos_y);
|
||||
void gd_egl_release_dmabuf(void *dg, QemuDmaBuf *dmabuf);
|
||||
void gd_egl_scanout_flush(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
||||
void gtk_egl_init(DisplayGLMode mode);
|
||||
int gd_egl_make_current(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx);
|
||||
int gd_egl_make_current(void *dg, QEMUGLContext ctx);
|
||||
|
||||
/* ui/gtk-gl-area.c */
|
||||
void gd_gl_area_init(VirtualConsole *vc);
|
||||
@@ -198,25 +192,20 @@ void gd_gl_area_update(DisplayChangeListener *dcl,
|
||||
void gd_gl_area_refresh(DisplayChangeListener *dcl);
|
||||
void gd_gl_area_switch(DisplayChangeListener *dcl,
|
||||
DisplaySurface *surface);
|
||||
QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
|
||||
QEMUGLParams *params);
|
||||
void gd_gl_area_destroy_context(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx);
|
||||
void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf);
|
||||
void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
|
||||
QEMUGLContext gd_gl_area_create_context(void *dg, QEMUGLParams *params);
|
||||
void gd_gl_area_destroy_context(void *dg, QEMUGLContext ctx);
|
||||
bool gd_gl_area_scanout_get_enabled(void *dg);
|
||||
void gd_gl_area_scanout_dmabuf(void *dg, QemuDmaBuf *dmabuf);
|
||||
void gd_gl_area_scanout_texture(void *dg,
|
||||
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);
|
||||
void gd_gl_area_scanout_disable(void *dg);
|
||||
void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
||||
void gtk_gl_area_init(void);
|
||||
int gd_gl_area_make_current(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx);
|
||||
int gd_gl_area_make_current(void *dg, QEMUGLContext ctx);
|
||||
|
||||
/* gtk-clipboard.c */
|
||||
void gd_clipboard_init(GtkDisplayState *gd);
|
||||
|
||||
+9
-12
@@ -11,7 +11,7 @@
|
||||
#endif
|
||||
|
||||
#include "ui/kbd-state.h"
|
||||
#ifdef CONFIG_OPENGL
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
# include "ui/egl-helpers.h"
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,7 @@ struct sdl2_console {
|
||||
int ignore_hotkeys;
|
||||
SDL_GLContext winctx;
|
||||
QKbdState *kbd;
|
||||
#ifdef CONFIG_OPENGL
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
QemuGLShader *gls;
|
||||
egl_fb guest_fb;
|
||||
egl_fb win_fb;
|
||||
@@ -65,18 +65,15 @@ void sdl2_gl_switch(DisplayChangeListener *dcl,
|
||||
void sdl2_gl_refresh(DisplayChangeListener *dcl);
|
||||
void sdl2_gl_redraw(struct sdl2_console *scon);
|
||||
|
||||
QEMUGLContext sdl2_gl_create_context(DisplayChangeListener *dcl,
|
||||
QEMUGLParams *params);
|
||||
void sdl2_gl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx);
|
||||
int sdl2_gl_make_context_current(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx);
|
||||
QEMUGLContext sdl2_gl_create_context(void *dg, QEMUGLParams *params);
|
||||
void sdl2_gl_destroy_context(void *dg, QEMUGLContext ctx);
|
||||
int sdl2_gl_make_context_current(void *dg, QEMUGLContext ctx);
|
||||
|
||||
void sdl2_gl_scanout_disable(DisplayChangeListener *dcl);
|
||||
void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
|
||||
bool sdl2_gl_scanout_get_enabled(void *dg);
|
||||
void sdl2_gl_scanout_disable(void *dg);
|
||||
void sdl2_gl_scanout_texture(void *dg,
|
||||
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,
|
||||
|
||||
@@ -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) && defined(CONFIG_EGL)
|
||||
# if SPICE_SERVER_VERSION >= 0x000d01 /* release 0.13.1 */
|
||||
# define HAVE_SPICE_GL 1
|
||||
# include "ui/egl-helpers.h"
|
||||
@@ -126,8 +131,19 @@ 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;
|
||||
#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;
|
||||
|
||||
+90
-69
@@ -58,6 +58,7 @@ python = import('python').find_installation()
|
||||
supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
|
||||
supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 'x86_64',
|
||||
'arm', 'aarch64', 'mips', 'mips64', 'sparc', 'sparc64']
|
||||
tcti_supported_cpus = ['aarch64']
|
||||
|
||||
cpu = host_machine.cpu_family()
|
||||
targetos = host_machine.system()
|
||||
@@ -77,6 +78,13 @@ else
|
||||
endif
|
||||
|
||||
accelerator_targets = { 'CONFIG_KVM': kvm_targets }
|
||||
|
||||
if cpu in ['aarch64']
|
||||
accelerator_targets += {
|
||||
'CONFIG_HVF': ['aarch64-softmmu']
|
||||
}
|
||||
endif
|
||||
|
||||
if cpu in ['x86', 'x86_64', 'arm', 'aarch64']
|
||||
# i368 emulator provides xenpv machine type for multiple architectures
|
||||
accelerator_targets += {
|
||||
@@ -177,6 +185,8 @@ socket = []
|
||||
version_res = []
|
||||
coref = []
|
||||
iokit = []
|
||||
vmnet = not_found
|
||||
iosurface = not_found
|
||||
emulator_link_args = []
|
||||
nvmm =not_found
|
||||
hvf = not_found
|
||||
@@ -191,6 +201,8 @@ if targetos == 'windows'
|
||||
elif targetos == 'darwin'
|
||||
coref = dependency('appleframeworks', modules: 'CoreFoundation')
|
||||
iokit = dependency('appleframeworks', modules: 'IOKit', required: false)
|
||||
vmnet = dependency('appleframeworks', modules: 'vmnet', required: false)
|
||||
iosurface = dependency('appleframeworks', modules: 'IOSurface', required: false)
|
||||
elif targetos == 'sunos'
|
||||
socket = [cc.find_library('socket'),
|
||||
cc.find_library('nsl'),
|
||||
@@ -263,6 +275,25 @@ if not get_option('tcg').disabled()
|
||||
endif
|
||||
if get_option('tcg_interpreter')
|
||||
tcg_arch = 'tci'
|
||||
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
|
||||
|
||||
# Tell our compiler how to generate our TCTI gadgets.
|
||||
gadget_generator = 'tcg/@0@/tcti-gadget-gen.py'.format(tcg_arch)
|
||||
tcti_gadgets = custom_target('tcti-gadgets.c.inc',
|
||||
output: 'tcti-gadgets.c.inc',
|
||||
input: gadget_generator,
|
||||
command: [find_program(gadget_generator), '@OUTPUT@'],
|
||||
build_by_default: true,
|
||||
build_always_stale: false)
|
||||
|
||||
genh += tcti_gadgets
|
||||
|
||||
elif config_host['ARCH'] == 'sparc64'
|
||||
tcg_arch = 'sparc'
|
||||
elif config_host['ARCH'] == 's390x'
|
||||
@@ -381,7 +412,8 @@ if not get_option('attr').disabled()
|
||||
endif
|
||||
endif
|
||||
|
||||
cocoa = dependency('appleframeworks', modules: 'Cocoa', required: get_option('cocoa'))
|
||||
cocoa = dependency('appleframeworks', modules: ['Cocoa', 'CoreVideo'],
|
||||
required: get_option('cocoa'))
|
||||
if cocoa.found() and get_option('sdl').enabled()
|
||||
error('Cocoa and SDL cannot be enabled at the same time')
|
||||
endif
|
||||
@@ -1291,6 +1323,8 @@ config_host_data.set('CONFIG_FUSE', fuse.found())
|
||||
config_host_data.set('CONFIG_FUSE_LSEEK', fuse_lseek.found())
|
||||
config_host_data.set('CONFIG_X11', x11.found())
|
||||
config_host_data.set('CONFIG_CFI', get_option('cfi'))
|
||||
config_host_data.set('CONFIG_VMNET', vmnet.found())
|
||||
config_host_data.set('CONFIG_IOSURFACE', iosurface.found())
|
||||
config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version()))
|
||||
config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('.')[0])
|
||||
config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1])
|
||||
@@ -1308,6 +1342,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'))
|
||||
|
||||
# has_function
|
||||
config_host_data.set('CONFIG_ACCEPT4', cc.has_function('accept4'))
|
||||
@@ -1564,6 +1599,8 @@ foreach target : target_dirs
|
||||
config_all += { sym: 'y' }
|
||||
if sym == 'CONFIG_TCG' and tcg_arch == 'tci'
|
||||
config_target += { 'CONFIG_TCG_INTERPRETER': 'y' }
|
||||
elif sym == 'CONFIG_TCG' and tcg_arch.endswith('tcti')
|
||||
config_target += { 'CONFIG_TCG_THREADED_INTERPRETER': 'y' }
|
||||
elif sym == 'CONFIG_XEN' and have_xen_pci_passthrough
|
||||
config_target += { 'CONFIG_XEN_PCI_PASSTHROUGH': 'y' }
|
||||
endif
|
||||
@@ -1807,7 +1844,7 @@ slirp_opt = 'disabled'
|
||||
if have_system
|
||||
slirp_opt = get_option('slirp')
|
||||
if slirp_opt in ['enabled', 'auto', 'system']
|
||||
have_internal = fs.exists(meson.current_source_dir() / 'slirp/meson.build')
|
||||
have_internal = fs.exists(meson.current_source_dir() / 'subprojects/libslirp/meson.build')
|
||||
slirp = dependency('slirp', kwargs: static_kwargs,
|
||||
method: 'pkg-config',
|
||||
required: slirp_opt == 'system' or
|
||||
@@ -1821,66 +1858,9 @@ if have_system
|
||||
endif
|
||||
endif
|
||||
if slirp_opt == 'internal'
|
||||
slirp_deps = []
|
||||
if targetos == 'windows'
|
||||
slirp_deps = cc.find_library('iphlpapi')
|
||||
elif targetos == 'darwin'
|
||||
slirp_deps = cc.find_library('resolv')
|
||||
endif
|
||||
slirp_conf = configuration_data()
|
||||
slirp_conf.set('SLIRP_MAJOR_VERSION', meson.project_version().split('.')[0])
|
||||
slirp_conf.set('SLIRP_MINOR_VERSION', meson.project_version().split('.')[1])
|
||||
slirp_conf.set('SLIRP_MICRO_VERSION', meson.project_version().split('.')[2])
|
||||
slirp_conf.set_quoted('SLIRP_VERSION_STRING', meson.project_version())
|
||||
slirp_cargs = ['-DG_LOG_DOMAIN="Slirp"']
|
||||
slirp_files = [
|
||||
'slirp/src/arp_table.c',
|
||||
'slirp/src/bootp.c',
|
||||
'slirp/src/cksum.c',
|
||||
'slirp/src/dhcpv6.c',
|
||||
'slirp/src/dnssearch.c',
|
||||
'slirp/src/if.c',
|
||||
'slirp/src/ip6_icmp.c',
|
||||
'slirp/src/ip6_input.c',
|
||||
'slirp/src/ip6_output.c',
|
||||
'slirp/src/ip_icmp.c',
|
||||
'slirp/src/ip_input.c',
|
||||
'slirp/src/ip_output.c',
|
||||
'slirp/src/mbuf.c',
|
||||
'slirp/src/misc.c',
|
||||
'slirp/src/ncsi.c',
|
||||
'slirp/src/ndp_table.c',
|
||||
'slirp/src/sbuf.c',
|
||||
'slirp/src/slirp.c',
|
||||
'slirp/src/socket.c',
|
||||
'slirp/src/state.c',
|
||||
'slirp/src/stream.c',
|
||||
'slirp/src/tcp_input.c',
|
||||
'slirp/src/tcp_output.c',
|
||||
'slirp/src/tcp_subr.c',
|
||||
'slirp/src/tcp_timer.c',
|
||||
'slirp/src/tftp.c',
|
||||
'slirp/src/udp.c',
|
||||
'slirp/src/udp6.c',
|
||||
'slirp/src/util.c',
|
||||
'slirp/src/version.c',
|
||||
'slirp/src/vmstate.c',
|
||||
]
|
||||
|
||||
configure_file(
|
||||
input : 'slirp/src/libslirp-version.h.in',
|
||||
output : 'libslirp-version.h',
|
||||
configuration: slirp_conf)
|
||||
|
||||
slirp_inc = include_directories('slirp', 'slirp/src')
|
||||
libslirp = static_library('slirp',
|
||||
build_by_default: false,
|
||||
sources: slirp_files,
|
||||
c_args: slirp_cargs,
|
||||
include_directories: slirp_inc)
|
||||
slirp = declare_dependency(link_with: libslirp,
|
||||
dependencies: slirp_deps,
|
||||
include_directories: slirp_inc)
|
||||
libslirp = subproject('libslirp',
|
||||
default_options: ['default_library=static'])
|
||||
slirp = libslirp.get_variable('libslirp_dep')
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -1943,9 +1923,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 #
|
||||
@@ -2162,6 +2151,7 @@ if have_system or have_user
|
||||
'accel/tcg',
|
||||
'hw/core',
|
||||
'target/arm',
|
||||
'target/arm/hvf',
|
||||
'target/hppa',
|
||||
'target/i386',
|
||||
'target/i386/kvm',
|
||||
@@ -2202,7 +2192,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)
|
||||
|
||||
@@ -2602,14 +2592,31 @@ foreach target : target_dirs
|
||||
arch_srcs += target_specific.sources()
|
||||
arch_deps += target_specific.dependencies()
|
||||
|
||||
lib = static_library('qemu-' + target,
|
||||
if get_option('shared_lib')
|
||||
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'])
|
||||
}
|
||||
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 = [{
|
||||
@@ -2643,6 +2650,17 @@ foreach target : target_dirs
|
||||
'dependencies': []
|
||||
}]
|
||||
endif
|
||||
if get_option('shared_lib')
|
||||
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'
|
||||
@@ -2653,11 +2671,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,
|
||||
gui_app: exe['gui'])
|
||||
gui_app: exe['gui'],
|
||||
kwargs: build_exe_args)
|
||||
|
||||
if targetos == 'darwin'
|
||||
icon = 'pc-bios/qemu.rsrc'
|
||||
@@ -2834,6 +2851,7 @@ endif
|
||||
summary_info += {'Doc directory': get_option('docdir')}
|
||||
summary_info += {'Build directory': meson.current_build_dir()}
|
||||
summary_info += {'Source path': meson.current_source_dir()}
|
||||
summary_info += {'build shared lib': get_option('shared_lib')}
|
||||
summary_info += {'GIT submodules': config_host['GIT_SUBMODULES']}
|
||||
summary(summary_info, bool_yn: true, section: 'Directories')
|
||||
|
||||
@@ -2978,6 +2996,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, experimental and 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
|
||||
@@ -2993,6 +3013,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': config_host['CONFIG_COROUTINE_POOL'] == '1'}
|
||||
if have_block
|
||||
|
||||
@@ -6,6 +6,8 @@ option('qemu_firmwarepath', type : 'string', value : '',
|
||||
description: 'search PATH for firmware files')
|
||||
option('sphinx_build', type : 'string', value : '',
|
||||
description: 'Use specified sphinx-build [$sphinx_build] for building document (default to be empty)')
|
||||
option('shared_lib', type : 'boolean', value : false,
|
||||
description: 'build QEMU as a shared library')
|
||||
|
||||
option('default_devices', type : 'boolean', value : true,
|
||||
description: 'Include a default selection of devices in emulators')
|
||||
@@ -43,6 +45,8 @@ option('tcg', type: 'feature', value: 'auto',
|
||||
description: 'TCG support')
|
||||
option('tcg_interpreter', type: 'boolean', value: false,
|
||||
description: 'TCG with bytecode interpreter (experimental and 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',
|
||||
@@ -138,6 +142,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('vhost_user_blk_server', type: 'feature', value: 'auto',
|
||||
description: 'build vhost-user-blk server')
|
||||
|
||||
@@ -63,4 +63,9 @@ int net_init_vhost_user(const Netdev *netdev, const char *name,
|
||||
|
||||
int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
|
||||
NetClientState *peer, Error **errp);
|
||||
|
||||
#ifdef CONFIG_VMNET
|
||||
int net_init_vmnet_macos(const Netdev *netdev, const char *name,
|
||||
NetClientState *peer, Error **errp);
|
||||
#endif
|
||||
#endif /* QEMU_NET_CLIENTS_H */
|
||||
@@ -37,5 +37,6 @@ endif
|
||||
softmmu_ss.add(when: 'CONFIG_POSIX', if_true: files(tap_posix))
|
||||
softmmu_ss.add(when: 'CONFIG_WIN32', if_true: files('tap-win32.c'))
|
||||
softmmu_ss.add(when: 'CONFIG_VHOST_NET_VDPA', if_true: files('vhost-vdpa.c'))
|
||||
softmmu_ss.add(when: vmnet, if_true: files('vmnet-macos.c'))
|
||||
|
||||
subdir('can')
|
||||
@@ -1001,6 +1001,9 @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
|
||||
#ifdef CONFIG_L2TPV3
|
||||
[NET_CLIENT_DRIVER_L2TPV3] = net_init_l2tpv3,
|
||||
#endif
|
||||
#ifdef CONFIG_VMNET
|
||||
[NET_CLIENT_DRIVER_VMNET_MACOS] = net_init_vmnet_macos,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,447 @@
|
||||
/*
|
||||
* vmnet.framework backed netdev for macOS 10.15+ hosts
|
||||
*
|
||||
* Copyright (c) 2021 Phillip Tennen <[email protected]>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qapi/qapi-types-net.h"
|
||||
#include "net/net.h"
|
||||
/* macOS vmnet framework header */
|
||||
#include <vmnet/vmnet.h>
|
||||
|
||||
typedef struct vmnet_state {
|
||||
NetClientState nc;
|
||||
interface_ref vmnet_iface_ref;
|
||||
/* Switched on after vmnet informs us that the interface has started */
|
||||
bool link_up;
|
||||
/*
|
||||
* If qemu_send_packet_async returns 0, this is switched off until our
|
||||
* delivery callback is invoked
|
||||
*/
|
||||
bool qemu_ready_to_receive;
|
||||
} vmnet_state_t;
|
||||
|
||||
int net_init_vmnet_macos(const Netdev *netdev, const char *name,
|
||||
NetClientState *peer, Error **errp);
|
||||
|
||||
static const char *_vmnet_status_repr(vmnet_return_t status)
|
||||
{
|
||||
switch (status) {
|
||||
case VMNET_SUCCESS:
|
||||
return "success";
|
||||
case VMNET_FAILURE:
|
||||
return "generic failure";
|
||||
case VMNET_MEM_FAILURE:
|
||||
return "out of memory";
|
||||
case VMNET_INVALID_ARGUMENT:
|
||||
return "invalid argument";
|
||||
case VMNET_SETUP_INCOMPLETE:
|
||||
return "setup is incomplete";
|
||||
case VMNET_INVALID_ACCESS:
|
||||
return "insufficient permissions";
|
||||
case VMNET_PACKET_TOO_BIG:
|
||||
return "packet size exceeds MTU";
|
||||
case VMNET_BUFFER_EXHAUSTED:
|
||||
return "kernel buffers temporarily exhausted";
|
||||
case VMNET_TOO_MANY_PACKETS:
|
||||
return "number of packets exceeds system limit";
|
||||
/* This error code was introduced in macOS 11.0 */
|
||||
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
|
||||
case VMNET_SHARING_SERVICE_BUSY:
|
||||
return "sharing service busy";
|
||||
#endif
|
||||
default:
|
||||
return "unknown status code";
|
||||
}
|
||||
}
|
||||
|
||||
static operating_modes_t _vmnet_operating_mode_enum_compat(
|
||||
VmnetOperatingMode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case VMNET_OPERATING_MODE_HOST:
|
||||
return VMNET_HOST_MODE;
|
||||
case VMNET_OPERATING_MODE_SHARED:
|
||||
return VMNET_SHARED_MODE;
|
||||
case VMNET_OPERATING_MODE_BRIDGED:
|
||||
return VMNET_BRIDGED_MODE;
|
||||
default:
|
||||
/* Should never happen as the modes are parsed before we get here */
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
static bool vmnet_can_receive(NetClientState *nc)
|
||||
{
|
||||
vmnet_state_t *s = DO_UPCAST(vmnet_state_t, nc, nc);
|
||||
return s->link_up;
|
||||
}
|
||||
|
||||
static ssize_t vmnet_receive_iov(NetClientState *nc,
|
||||
const struct iovec *iovs,
|
||||
int iovcnt)
|
||||
{
|
||||
vmnet_state_t *s = DO_UPCAST(vmnet_state_t, nc, nc);
|
||||
|
||||
/* Combine the provided iovs into a single vmnet packet */
|
||||
struct vmpktdesc *packet = g_new0(struct vmpktdesc, 1);
|
||||
packet->vm_pkt_iov = g_new0(struct iovec, iovcnt);
|
||||
memcpy(packet->vm_pkt_iov, iovs, sizeof(struct iovec) * iovcnt);
|
||||
packet->vm_pkt_iovcnt = iovcnt;
|
||||
packet->vm_flags = 0;
|
||||
|
||||
/* Figure out the packet size by iterating the iov's */
|
||||
for (int i = 0; i < iovcnt; i++) {
|
||||
const struct iovec *iov = iovs + i;
|
||||
packet->vm_pkt_size += iov->iov_len;
|
||||
}
|
||||
|
||||
/* Finally, write the packet to the vmnet interface */
|
||||
int packet_count = 1;
|
||||
vmnet_return_t result = vmnet_write(s->vmnet_iface_ref, packet,
|
||||
&packet_count);
|
||||
if (result != VMNET_SUCCESS || packet_count != 1) {
|
||||
error_printf("Failed to send packet to host: %s\n",
|
||||
_vmnet_status_repr(result));
|
||||
}
|
||||
ssize_t wrote_bytes = packet->vm_pkt_size;
|
||||
g_free(packet->vm_pkt_iov);
|
||||
g_free(packet);
|
||||
return wrote_bytes;
|
||||
}
|
||||
|
||||
static void vmnet_send_completed(NetClientState *nc, ssize_t len)
|
||||
{
|
||||
vmnet_state_t *vmnet_client_state = DO_UPCAST(vmnet_state_t, nc, nc);
|
||||
/* Ready to receive more packets! */
|
||||
vmnet_client_state->qemu_ready_to_receive = true;
|
||||
}
|
||||
|
||||
static NetClientInfo net_vmnet_macos_info = {
|
||||
.type = NET_CLIENT_DRIVER_VMNET_MACOS,
|
||||
.size = sizeof(vmnet_state_t),
|
||||
.receive_iov = vmnet_receive_iov,
|
||||
.can_receive = vmnet_can_receive,
|
||||
};
|
||||
|
||||
static bool _validate_ifname_is_valid_bridge_target(const char *ifname)
|
||||
{
|
||||
/* Iterate available bridge interfaces, ensure the provided one is valid */
|
||||
xpc_object_t bridge_interfaces = vmnet_copy_shared_interface_list();
|
||||
bool failed_to_match_iface_name = xpc_array_apply(
|
||||
bridge_interfaces,
|
||||
^bool(size_t index, xpc_object_t _Nonnull value) {
|
||||
if (!strcmp(xpc_string_get_string_ptr(value), ifname)) {
|
||||
/* The interface name is valid! Stop iterating */
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (failed_to_match_iface_name) {
|
||||
error_printf("Invalid bridge interface name provided: %s\n", ifname);
|
||||
error_printf("Valid bridge interfaces:\n");
|
||||
xpc_array_apply(
|
||||
vmnet_copy_shared_interface_list(),
|
||||
^bool(size_t index, xpc_object_t _Nonnull value) {
|
||||
error_printf("\t%s\n", xpc_string_get_string_ptr(value));
|
||||
/* Keep iterating */
|
||||
return true;
|
||||
});
|
||||
exit(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static xpc_object_t _construct_vmnet_interface_description(
|
||||
const NetdevVmnetModeOptions *vmnet_opts)
|
||||
{
|
||||
operating_modes_t mode = _vmnet_operating_mode_enum_compat(
|
||||
vmnet_opts->mode);
|
||||
|
||||
/* Validate options */
|
||||
if (mode == VMNET_HOST_MODE || mode == VMNET_SHARED_MODE) {
|
||||
NetdevVmnetModeOptionsHostOrShared mode_opts = vmnet_opts->u.host;
|
||||
/* If one DHCP parameter is configured, all 3 are required */
|
||||
if (mode_opts.has_dhcp_start_address ||
|
||||
mode_opts.has_dhcp_end_address ||
|
||||
mode_opts.has_dhcp_subnet_mask) {
|
||||
if (!(mode_opts.has_dhcp_start_address &&
|
||||
mode_opts.has_dhcp_end_address &&
|
||||
mode_opts.has_dhcp_subnet_mask)) {
|
||||
error_printf("Incomplete DHCP configuration provided\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
} else if (mode == VMNET_BRIDGED_MODE) {
|
||||
/* Nothing to validate */
|
||||
} else {
|
||||
error_printf("Unknown vmnet mode %d\n", mode);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
xpc_object_t interface_desc = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_uint64(
|
||||
interface_desc,
|
||||
vmnet_operation_mode_key,
|
||||
mode
|
||||
);
|
||||
|
||||
if (mode == VMNET_BRIDGED_MODE) {
|
||||
/*
|
||||
* Configure the provided physical interface to act
|
||||
* as a bridge with QEMU
|
||||
*/
|
||||
NetdevVmnetModeOptionsBridged mode_opts = vmnet_opts->u.bridged;
|
||||
/* Bridge with en0 by default */
|
||||
const char *physical_ifname = mode_opts.has_ifname ? mode_opts.ifname :
|
||||
"en0";
|
||||
_validate_ifname_is_valid_bridge_target(physical_ifname);
|
||||
xpc_dictionary_set_string(interface_desc,
|
||||
vmnet_shared_interface_name_key,
|
||||
physical_ifname);
|
||||
} else if (mode == VMNET_HOST_MODE || mode == VMNET_SHARED_MODE) {
|
||||
/* Pass the DHCP configuration to vmnet, if the user provided one */
|
||||
NetdevVmnetModeOptionsHostOrShared mode_opts = vmnet_opts->u.host;
|
||||
if (mode_opts.has_dhcp_start_address) {
|
||||
/* All DHCP arguments are available, as per the checks above */
|
||||
xpc_dictionary_set_string(interface_desc,
|
||||
vmnet_start_address_key,
|
||||
mode_opts.dhcp_start_address);
|
||||
xpc_dictionary_set_string(interface_desc,
|
||||
vmnet_end_address_key,
|
||||
mode_opts.dhcp_end_address);
|
||||
xpc_dictionary_set_string(interface_desc,
|
||||
vmnet_subnet_mask_key,
|
||||
mode_opts.dhcp_subnet_mask);
|
||||
}
|
||||
}
|
||||
|
||||
return interface_desc;
|
||||
}
|
||||
|
||||
int net_init_vmnet_macos(const Netdev *netdev, const char *name,
|
||||
NetClientState *peer, Error **errp)
|
||||
{
|
||||
assert(netdev->type == NET_CLIENT_DRIVER_VMNET_MACOS);
|
||||
|
||||
NetdevVmnetModeOptions *vmnet_opts = netdev->u.vmnet_macos.options;
|
||||
xpc_object_t iface_desc = _construct_vmnet_interface_description(vmnet_opts);
|
||||
|
||||
NetClientState *nc = qemu_new_net_client(&net_vmnet_macos_info, peer,
|
||||
"vmnet", name);
|
||||
vmnet_state_t *vmnet_client_state = DO_UPCAST(vmnet_state_t, nc, nc);
|
||||
|
||||
dispatch_queue_t vmnet_dispatch_queue = dispatch_queue_create(
|
||||
"org.qemu.vmnet.iface_queue",
|
||||
DISPATCH_QUEUE_SERIAL
|
||||
);
|
||||
|
||||
__block vmnet_return_t vmnet_start_status = 0;
|
||||
__block uint64_t vmnet_iface_mtu = 0;
|
||||
__block uint64_t vmnet_max_packet_size = 0;
|
||||
__block const char *vmnet_mac_address = NULL;
|
||||
/*
|
||||
* We can't refer to an array type directly within a block,
|
||||
* so hold a pointer instead.
|
||||
*/
|
||||
uuid_string_t vmnet_iface_uuid = {0};
|
||||
__block uuid_string_t *vmnet_iface_uuid_ptr = &vmnet_iface_uuid;
|
||||
/* These are only provided in VMNET_HOST_MODE and VMNET_SHARED_MODE */
|
||||
bool vmnet_provides_dhcp_info = (
|
||||
vmnet_opts->mode == VMNET_OPERATING_MODE_HOST ||
|
||||
vmnet_opts->mode == VMNET_OPERATING_MODE_SHARED);
|
||||
__block const char *vmnet_subnet_mask = NULL;
|
||||
__block const char *vmnet_dhcp_range_start = NULL;
|
||||
__block const char *vmnet_dhcp_range_end = NULL;
|
||||
|
||||
/* Create the vmnet interface */
|
||||
dispatch_semaphore_t vmnet_iface_sem = dispatch_semaphore_create(0);
|
||||
interface_ref vmnet_iface_ref = vmnet_start_interface(
|
||||
iface_desc,
|
||||
vmnet_dispatch_queue,
|
||||
^(vmnet_return_t status, xpc_object_t _Nullable interface_param) {
|
||||
vmnet_start_status = status;
|
||||
if (vmnet_start_status != VMNET_SUCCESS || !interface_param) {
|
||||
/* Early return if the interface couldn't be started */
|
||||
dispatch_semaphore_signal(vmnet_iface_sem);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the configuration that vmnet provided us.
|
||||
* The provided dictionary is owned by XPC and may be freed
|
||||
* shortly after this block's execution.
|
||||
* So, copy data buffers now.
|
||||
*/
|
||||
vmnet_iface_mtu = xpc_dictionary_get_uint64(
|
||||
interface_param,
|
||||
vmnet_mtu_key
|
||||
);
|
||||
vmnet_max_packet_size = xpc_dictionary_get_uint64(
|
||||
interface_param,
|
||||
vmnet_max_packet_size_key
|
||||
);
|
||||
vmnet_mac_address = strdup(xpc_dictionary_get_string(
|
||||
interface_param,
|
||||
vmnet_mac_address_key
|
||||
));
|
||||
|
||||
const uint8_t *iface_uuid = xpc_dictionary_get_uuid(
|
||||
interface_param,
|
||||
vmnet_interface_id_key
|
||||
);
|
||||
uuid_unparse_upper(iface_uuid, *vmnet_iface_uuid_ptr);
|
||||
|
||||
/* If we're in a mode that provides DHCP info, read it out now */
|
||||
if (vmnet_provides_dhcp_info) {
|
||||
vmnet_dhcp_range_start = strdup(xpc_dictionary_get_string(
|
||||
interface_param,
|
||||
vmnet_start_address_key
|
||||
));
|
||||
vmnet_dhcp_range_end = strdup(xpc_dictionary_get_string(
|
||||
interface_param,
|
||||
vmnet_end_address_key
|
||||
));
|
||||
vmnet_subnet_mask = strdup(xpc_dictionary_get_string(
|
||||
interface_param,
|
||||
vmnet_subnet_mask_key
|
||||
));
|
||||
}
|
||||
dispatch_semaphore_signal(vmnet_iface_sem);
|
||||
});
|
||||
|
||||
/* And block until we receive a response from vmnet */
|
||||
dispatch_semaphore_wait(vmnet_iface_sem, DISPATCH_TIME_FOREVER);
|
||||
|
||||
/* Did we manage to start the interface? */
|
||||
if (vmnet_start_status != VMNET_SUCCESS || !vmnet_iface_ref) {
|
||||
error_printf("Failed to start interface: %s\n",
|
||||
_vmnet_status_repr(vmnet_start_status));
|
||||
if (vmnet_start_status == VMNET_FAILURE) {
|
||||
error_printf("Hint: vmnet requires running with root access\n");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
info_report("Started vmnet interface with configuration:");
|
||||
info_report("MTU: %llu", vmnet_iface_mtu);
|
||||
info_report("Max packet size: %llu", vmnet_max_packet_size);
|
||||
info_report("MAC: %s", vmnet_mac_address);
|
||||
if (vmnet_provides_dhcp_info) {
|
||||
info_report("DHCP IPv4 start: %s", vmnet_dhcp_range_start);
|
||||
info_report("DHCP IPv4 end: %s", vmnet_dhcp_range_end);
|
||||
info_report("IPv4 subnet mask: %s", vmnet_subnet_mask);
|
||||
}
|
||||
info_report("UUID: %s", vmnet_iface_uuid);
|
||||
|
||||
/* The interface is up! Set a block to run when packets are received */
|
||||
vmnet_client_state->vmnet_iface_ref = vmnet_iface_ref;
|
||||
vmnet_return_t event_cb_stat = vmnet_interface_set_event_callback(
|
||||
vmnet_iface_ref,
|
||||
VMNET_INTERFACE_PACKETS_AVAILABLE,
|
||||
vmnet_dispatch_queue,
|
||||
^(interface_event_t event_mask, xpc_object_t _Nonnull event) {
|
||||
if (event_mask != VMNET_INTERFACE_PACKETS_AVAILABLE) {
|
||||
error_printf("Unknown vmnet interface event 0x%08x\n", event_mask);
|
||||
return;
|
||||
}
|
||||
|
||||
/* If we're unable to handle more packets now, drop this packet */
|
||||
if (!vmnet_client_state->qemu_ready_to_receive) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO(Phillip Tennen <[email protected]>): There may be more than
|
||||
* one packet available.
|
||||
* As an optimization, we could read
|
||||
* vmnet_estimated_packets_available_key packets now.
|
||||
*/
|
||||
char *packet_buf = g_malloc0(vmnet_max_packet_size);
|
||||
struct iovec *iov = g_new0(struct iovec, 1);
|
||||
iov->iov_base = packet_buf;
|
||||
iov->iov_len = vmnet_max_packet_size;
|
||||
|
||||
int pktcnt = 1;
|
||||
struct vmpktdesc *v = g_new0(struct vmpktdesc, pktcnt);
|
||||
v->vm_pkt_size = vmnet_max_packet_size;
|
||||
v->vm_pkt_iov = iov;
|
||||
v->vm_pkt_iovcnt = 1;
|
||||
v->vm_flags = 0;
|
||||
|
||||
vmnet_return_t result = vmnet_read(vmnet_iface_ref, v, &pktcnt);
|
||||
if (result != VMNET_SUCCESS) {
|
||||
error_printf("Failed to read packet from host: %s\n",
|
||||
_vmnet_status_repr(result));
|
||||
}
|
||||
|
||||
/* Ensure we read exactly one packet */
|
||||
assert(pktcnt == 1);
|
||||
|
||||
/* Dispatch this block to a global queue instead of the main queue,
|
||||
* which is only created when the program has a Cocoa event loop.
|
||||
* If QEMU is started with -nographic, no Cocoa event loop will be
|
||||
* created and thus the main queue will be unavailable.
|
||||
*/
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,
|
||||
0),
|
||||
^{
|
||||
qemu_mutex_lock_iothread();
|
||||
|
||||
/*
|
||||
* Deliver the packet to the guest
|
||||
* If the delivery succeeded synchronously, this returns the length
|
||||
* of the sent packet.
|
||||
*/
|
||||
if (qemu_send_packet_async(nc, iov->iov_base,
|
||||
v->vm_pkt_size,
|
||||
vmnet_send_completed) == 0) {
|
||||
vmnet_client_state->qemu_ready_to_receive = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* It's safe to free the packet buffers.
|
||||
* Even if delivery needs to wait, qemu_net_queue_append copies
|
||||
* the packet buffer.
|
||||
*/
|
||||
g_free(v);
|
||||
g_free(iov);
|
||||
g_free(packet_buf);
|
||||
|
||||
qemu_mutex_unlock_iothread();
|
||||
});
|
||||
});
|
||||
|
||||
/* Did we manage to set an event callback? */
|
||||
if (event_cb_stat != VMNET_SUCCESS) {
|
||||
error_printf("Failed to set up a callback to receive packets: %s\n",
|
||||
_vmnet_status_repr(vmnet_start_status));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* We're now ready to receive packets */
|
||||
vmnet_client_state->qemu_ready_to_receive = true;
|
||||
vmnet_client_state->link_up = true;
|
||||
|
||||
/* Include DHCP info if we're in a relevant mode */
|
||||
if (vmnet_provides_dhcp_info) {
|
||||
snprintf(nc->info_str, sizeof(nc->info_str),
|
||||
"dhcp_start=%s,dhcp_end=%s,mask=%s",
|
||||
vmnet_dhcp_range_start, vmnet_dhcp_range_end,
|
||||
vmnet_subnet_mask);
|
||||
} else {
|
||||
snprintf(nc->info_str, sizeof(nc->info_str),
|
||||
"mac=%s", vmnet_mac_address);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+118
-2
@@ -452,6 +452,115 @@
|
||||
'*vhostdev': 'str',
|
||||
'*queues': 'int' } }
|
||||
|
||||
##
|
||||
# @VmnetOperatingMode:
|
||||
#
|
||||
# The operating modes in which a vmnet netdev can run
|
||||
# Only available on macOS
|
||||
#
|
||||
# @host: the guest may communicate with the host
|
||||
# and other guest network interfaces
|
||||
#
|
||||
# @shared: the guest may reach the Internet through a NAT,
|
||||
# and may communicate with the host and other guest
|
||||
# network interfaces
|
||||
#
|
||||
# @bridged: the guest's traffic is bridged with a
|
||||
# physical network interface of the host
|
||||
#
|
||||
# Since: 6.0
|
||||
##
|
||||
{ 'enum': 'VmnetOperatingMode',
|
||||
'data': [ 'host', 'shared', 'bridged' ],
|
||||
'if': 'defined(CONFIG_VMNET)' }
|
||||
|
||||
##
|
||||
# @NetdevVmnetModeOptionsBridged:
|
||||
#
|
||||
# Options for the vmnet-macos netdev
|
||||
# that are only available in 'bridged' mode
|
||||
# Only available on macOS
|
||||
#
|
||||
# @ifname: the physical network interface to bridge with
|
||||
# (defaults to en0 if not specified)
|
||||
#
|
||||
# Since: 6.0
|
||||
##
|
||||
{ 'struct': 'NetdevVmnetModeOptionsBridged',
|
||||
'data': { '*ifname': 'str' },
|
||||
'if': 'defined(CONFIG_VMNET)' }
|
||||
|
||||
##
|
||||
# @NetdevVmnetModeOptionsHostOrShared:
|
||||
#
|
||||
# Options for the vmnet-macos netdev
|
||||
# that are only available in 'host' or 'shared' mode
|
||||
# Only available on macOS
|
||||
#
|
||||
# @dhcp-start-address: the gateway address to use for the interface.
|
||||
# The range to dhcp_end_address is placed in the DHCP pool.
|
||||
# (only valid with mode=host|shared)
|
||||
# (must be specified with dhcp-end-address and
|
||||
# dhcp-subnet-mask)
|
||||
# (allocated automatically if unset)
|
||||
#
|
||||
# @dhcp-end-address: the DHCP IPv4 range end address to use for the interface.
|
||||
# (only valid with mode=host|shared)
|
||||
# (must be specified with dhcp-start-address and
|
||||
# dhcp-subnet-mask)
|
||||
# (allocated automatically if unset)
|
||||
#
|
||||
# @dhcp-subnet-mask: the IPv4 subnet mask (string) to use on the interface.
|
||||
# (only valid with mode=host|shared)
|
||||
# (must be specified with dhcp-start-address and
|
||||
# dhcp-end-address)
|
||||
# (allocated automatically if unset)
|
||||
#
|
||||
# Since: 6.0
|
||||
##
|
||||
{ 'struct': 'NetdevVmnetModeOptionsHostOrShared',
|
||||
'data': {
|
||||
'*dhcp-start-address': 'str' ,
|
||||
'*dhcp-end-address': 'str',
|
||||
'*dhcp-subnet-mask': 'str' },
|
||||
'if': 'defined(CONFIG_VMNET)' }
|
||||
|
||||
##
|
||||
# @NetdevVmnetModeOptions:
|
||||
#
|
||||
# Options specific to different operating modes of a vmnet netdev
|
||||
# Only available on macOS
|
||||
#
|
||||
# @mode: the operating mode vmnet should run in
|
||||
#
|
||||
# Since: 6.0
|
||||
##
|
||||
{ 'union': 'NetdevVmnetModeOptions',
|
||||
'base': { 'mode': 'VmnetOperatingMode' },
|
||||
'discriminator': 'mode',
|
||||
'data': {
|
||||
'bridged': 'NetdevVmnetModeOptionsBridged',
|
||||
'host': 'NetdevVmnetModeOptionsHostOrShared',
|
||||
'shared': 'NetdevVmnetModeOptionsHostOrShared' },
|
||||
'if': 'defined(CONFIG_VMNET)' }
|
||||
|
||||
##
|
||||
# @NetdevVmnetOptions:
|
||||
#
|
||||
# vmnet network backend
|
||||
# Only available on macOS
|
||||
#
|
||||
# @options: a structure specifying the mode and mode-specific options
|
||||
# (once QAPI supports a union type as a branch to another union type,
|
||||
# this structure can be changed to a union, and the contents of
|
||||
# NetdevVmnetModeOptions moved here)
|
||||
#
|
||||
# Since: 6.0
|
||||
##
|
||||
{ 'struct': 'NetdevVmnetOptions',
|
||||
'data': {'options': 'NetdevVmnetModeOptions' },
|
||||
'if': 'defined(CONFIG_VMNET)' }
|
||||
|
||||
##
|
||||
# @NetClientDriver:
|
||||
#
|
||||
@@ -460,10 +569,13 @@
|
||||
# Since: 2.7
|
||||
#
|
||||
# @vhost-vdpa since 5.1
|
||||
#
|
||||
# @vmnet-macos since 6.0 (only available on macOS)
|
||||
##
|
||||
{ 'enum': 'NetClientDriver',
|
||||
'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde',
|
||||
'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa' ] }
|
||||
'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa',
|
||||
{ 'name': 'vmnet-macos', 'if': 'defined(CONFIG_VMNET)' } ] }
|
||||
|
||||
##
|
||||
# @Netdev:
|
||||
@@ -477,6 +589,8 @@
|
||||
# Since: 1.2
|
||||
#
|
||||
# 'l2tpv3' - since 2.1
|
||||
#
|
||||
# 'vmnet-macos' since 6.0 (only available on macOS)
|
||||
##
|
||||
{ 'union': 'Netdev',
|
||||
'base': { 'id': 'str', 'type': 'NetClientDriver' },
|
||||
@@ -492,7 +606,9 @@
|
||||
'hubport': 'NetdevHubPortOptions',
|
||||
'netmap': 'NetdevNetmapOptions',
|
||||
'vhost-user': 'NetdevVhostUserOptions',
|
||||
'vhost-vdpa': 'NetdevVhostVDPAOptions' } }
|
||||
'vhost-vdpa': 'NetdevVhostVDPAOptions',
|
||||
'vmnet-macos': { 'type': 'NetdevVmnetOptions',
|
||||
'if': 'defined(CONFIG_VMNET)' } } }
|
||||
|
||||
##
|
||||
# @RxState:
|
||||
|
||||
+23
-1
@@ -1092,6 +1092,27 @@
|
||||
{ 'struct' : 'DisplayCurses',
|
||||
'data' : { '*charset' : 'str' } }
|
||||
|
||||
##
|
||||
# @DisplayCocoa:
|
||||
#
|
||||
# Cocoa display options.
|
||||
#
|
||||
# @full-grab: Capture all key presses, including system combos. This
|
||||
# requires accessibility permissions, since it performs
|
||||
# a global grab on key events. (default: off)
|
||||
# See https://support.apple.com/en-in/guide/mac-help/mh32356/mac
|
||||
#
|
||||
# @swap-option-command: Swap the Option and Command keys so that their key
|
||||
# codes match their position on non-Mac keyboards and
|
||||
# you can use Meta/Super and Alt where you expect them.
|
||||
# (default: off)
|
||||
#
|
||||
# Since: 6.1
|
||||
##
|
||||
{ 'struct' : 'DisplayCocoa',
|
||||
'data' : { '*full-grab' : 'bool',
|
||||
'*swap-option-command' : 'bool' } }
|
||||
|
||||
##
|
||||
# @DisplayType:
|
||||
#
|
||||
@@ -1136,7 +1157,7 @@
|
||||
{ 'name': 'gtk', 'if': 'defined(CONFIG_GTK)' },
|
||||
{ 'name': 'sdl', 'if': 'defined(CONFIG_SDL)' },
|
||||
{ 'name': 'egl-headless',
|
||||
'if': 'defined(CONFIG_OPENGL) && defined(CONFIG_GBM)' },
|
||||
'if': 'defined(CONFIG_OPENGL)' },
|
||||
{ 'name': 'curses', 'if': 'defined(CONFIG_CURSES)' },
|
||||
{ 'name': 'cocoa', 'if': 'defined(CONFIG_COCOA)' },
|
||||
{ 'name': 'spice-app', 'if': 'defined(CONFIG_SPICE)'} ] }
|
||||
@@ -1165,6 +1186,7 @@
|
||||
'discriminator' : 'type',
|
||||
'data' : {
|
||||
'gtk': { 'type': 'DisplayGTK', 'if': 'defined(CONFIG_GTK)' },
|
||||
'cocoa': { 'type': 'DisplayCocoa', 'if': 'defined(CONFIG_COCOA)' },
|
||||
'curses': { 'type': 'DisplayCurses', 'if': 'defined(CONFIG_CURSES)' },
|
||||
'egl-headless': { 'type': 'DisplayEGLHeadless',
|
||||
'if': 'defined(CONFIG_OPENGL) && defined(CONFIG_GBM)' }
|
||||
|
||||
+14
-1
@@ -1846,7 +1846,11 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
|
||||
#if defined(CONFIG_CURSES)
|
||||
"-display curses[,charset=<encoding>]\n"
|
||||
#endif
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#if defined(CONFIG_COCOA)
|
||||
"-display cocoa[,full-grab=on|off]\n"
|
||||
" [,swap-option-command=on|off]\n"
|
||||
#endif
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
"-display egl-headless[,rendernode=<file>]\n"
|
||||
#endif
|
||||
"-display none\n"
|
||||
@@ -2655,6 +2659,15 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
|
||||
#ifdef __linux__
|
||||
"-netdev vhost-vdpa,id=str,vhostdev=/path/to/dev\n"
|
||||
" configure a vhost-vdpa network,Establish a vhost-vdpa netdev\n"
|
||||
#endif
|
||||
#ifdef CONFIG_VMNET
|
||||
"-netdev vmnet-macos,id=str,mode=bridged[,ifname=ifname]\n"
|
||||
" configure a macOS-provided vmnet network in \"physical interface bridge\" mode\n"
|
||||
" the physical interface to bridge with defaults to en0 if unspecified\n"
|
||||
"-netdev vmnet-macos,id=str,mode=host|shared\n"
|
||||
" [,dhcp_start_address=addr,dhcp_end_address=addr,dhcp_subnet_mask=mask]\n"
|
||||
" configure a macOS-provided vmnet network in \"host\" or \"shared\" mode\n"
|
||||
" the DHCP configuration will be set automatically if unspecified\n"
|
||||
#endif
|
||||
"-netdev hubport,id=str,hubid=n[,netdev=nd]\n"
|
||||
" configure a hub port on the hub with ID 'n'\n", QEMU_ARCH_ALL)
|
||||
|
||||
+12
-12
@@ -75,18 +75,18 @@ def process_tests(test, targets, suites):
|
||||
print('run-test-%d: $(.test.deps.%d)' % (i,i))
|
||||
print('\t@$(call .test.run,%d,$(.test.output-format))' % (i,))
|
||||
|
||||
test_suites = test['suite'] or ['default']
|
||||
is_slow = any(s.endswith('-slow') for s in test_suites)
|
||||
for s in test_suites:
|
||||
# The suite name in the introspection info is "PROJECT:SUITE"
|
||||
s = s.split(':')[1]
|
||||
if s.endswith('-slow'):
|
||||
s = s[:-5]
|
||||
if is_slow:
|
||||
suites[s].slow_tests.append(i)
|
||||
else:
|
||||
suites[s].tests.append(i)
|
||||
suites[s].executables.add(executable)
|
||||
#test_suites = test['suite'] or ['default']
|
||||
#is_slow = any(s.endswith('-slow') for s in test_suites)
|
||||
#for s in test_suites:
|
||||
# # The suite name in the introspection info is "PROJECT:SUITE"
|
||||
# s = s.split(':')[1]
|
||||
# if s.endswith('-slow'):
|
||||
# s = s[:-5]
|
||||
# if is_slow:
|
||||
# suites[s].slow_tests.append(i)
|
||||
# else:
|
||||
# suites[s].tests.append(i)
|
||||
# suites[s].executables.add(executable)
|
||||
|
||||
def emit_prolog(suites, prefix):
|
||||
all_tap = ' '.join(('%s-report-%s.tap' % (prefix, k) for k in suites.keys()))
|
||||
|
||||
-1
Submodule slirp deleted from a88d9ace23.
Submodule
+1
Submodule subprojects/libslirp added at cceced0cce.
Submodule
+1
Submodule subprojects/libucontext added at 9b1d8f01a6.
+9
-4
@@ -39,6 +39,7 @@
|
||||
#include "sysemu/tcg.h"
|
||||
#include "sysemu/hw_accel.h"
|
||||
#include "kvm_arm.h"
|
||||
#include "hvf_arm.h"
|
||||
#include "disas/capstone.h"
|
||||
#include "fpu/softfloat.h"
|
||||
|
||||
@@ -1089,8 +1090,8 @@ static void arm_cpu_initfn(Object *obj)
|
||||
cpu->psci_version = 1; /* By default assume PSCI v0.1 */
|
||||
cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
|
||||
|
||||
if (tcg_enabled()) {
|
||||
cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
|
||||
if (tcg_enabled() || hvf_enabled()) {
|
||||
cpu->psci_version = 2; /* TCG and HVF implement PSCI 0.2 */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2032,15 +2033,19 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
|
||||
#endif /* CONFIG_TCG */
|
||||
}
|
||||
|
||||
#ifdef CONFIG_KVM
|
||||
#if defined(CONFIG_KVM) || defined(CONFIG_HVF)
|
||||
static void arm_host_initfn(Object *obj)
|
||||
{
|
||||
ARMCPU *cpu = ARM_CPU(obj);
|
||||
|
||||
#ifdef CONFIG_KVM
|
||||
kvm_arm_set_cpu_features_from_host(cpu);
|
||||
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
|
||||
aarch64_add_sve_properties(obj);
|
||||
}
|
||||
#else
|
||||
hvf_arm_set_cpu_features_from_host(cpu);
|
||||
#endif
|
||||
arm_cpu_post_init(obj);
|
||||
}
|
||||
|
||||
@@ -2100,7 +2105,7 @@ static void arm_cpu_register_types(void)
|
||||
{
|
||||
type_register_static(&arm_cpu_type_info);
|
||||
|
||||
#ifdef CONFIG_KVM
|
||||
#if defined(CONFIG_KVM) || defined(CONFIG_HVF)
|
||||
type_register_static(&host_arm_cpu_type_info);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -3002,6 +3002,8 @@ bool write_cpustate_to_list(ARMCPU *cpu, bool kvm_sync);
|
||||
#define ARM_CPU_TYPE_NAME(name) (name ARM_CPU_TYPE_SUFFIX)
|
||||
#define CPU_RESOLVING_TYPE TYPE_ARM_CPU
|
||||
|
||||
#define TYPE_ARM_HOST_CPU "host-" TYPE_ARM_CPU
|
||||
|
||||
#define cpu_signal_handler cpu_arm_signal_handler
|
||||
#define cpu_list arm_cpu_list
|
||||
|
||||
|
||||
@@ -0,0 +1,962 @@
|
||||
/*
|
||||
* QEMU Hypervisor.framework support for Apple Silicon
|
||||
|
||||
* Copyright 2020 Alexander Graf <agraf@csgraf.de>
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/error-report.h"
|
||||
|
||||
#include "sysemu/runstate.h"
|
||||
#include "sysemu/hvf.h"
|
||||
#include "sysemu/hvf_int.h"
|
||||
#include "sysemu/hw_accel.h"
|
||||
#include "hvf_arm.h"
|
||||
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
#include "exec/address-spaces.h"
|
||||
#include "hw/irq.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "sysemu/cpus.h"
|
||||
#include "arm-powerctl.h"
|
||||
#include "target/arm/cpu.h"
|
||||
#include "target/arm/internals.h"
|
||||
#include "trace/trace-target_arm_hvf.h"
|
||||
|
||||
#define HVF_SYSREG(crn, crm, op0, op1, op2) \
|
||||
ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP, crn, crm, op0, op1, op2)
|
||||
#define PL1_WRITE_MASK 0x4
|
||||
|
||||
#define SYSREG(op0, op1, crn, crm, op2) \
|
||||
((op0 << 20) | (op2 << 17) | (op1 << 14) | (crn << 10) | (crm << 1))
|
||||
#define SYSREG_MASK SYSREG(0x3, 0x7, 0xf, 0xf, 0x7)
|
||||
#define SYSREG_CNTPCT_EL0 SYSREG(3, 3, 14, 0, 1)
|
||||
#define SYSREG_PMCCNTR_EL0 SYSREG(3, 3, 9, 13, 0)
|
||||
|
||||
#define WFX_IS_WFE (1 << 0)
|
||||
|
||||
#define TMR_CTL_ENABLE (1 << 0)
|
||||
#define TMR_CTL_IMASK (1 << 1)
|
||||
#define TMR_CTL_ISTATUS (1 << 2)
|
||||
|
||||
static void hvf_wfi(CPUState *cpu);
|
||||
|
||||
typedef struct ARMHostCPUFeatures {
|
||||
ARMISARegisters isar;
|
||||
uint64_t features;
|
||||
uint64_t midr;
|
||||
uint32_t reset_sctlr;
|
||||
const char *dtb_compatible;
|
||||
} ARMHostCPUFeatures;
|
||||
|
||||
static ARMHostCPUFeatures arm_host_cpu_features;
|
||||
|
||||
struct hvf_reg_match {
|
||||
int reg;
|
||||
uint64_t offset;
|
||||
};
|
||||
|
||||
static const struct hvf_reg_match hvf_reg_match[] = {
|
||||
{ HV_REG_X0, offsetof(CPUARMState, xregs[0]) },
|
||||
{ HV_REG_X1, offsetof(CPUARMState, xregs[1]) },
|
||||
{ HV_REG_X2, offsetof(CPUARMState, xregs[2]) },
|
||||
{ HV_REG_X3, offsetof(CPUARMState, xregs[3]) },
|
||||
{ HV_REG_X4, offsetof(CPUARMState, xregs[4]) },
|
||||
{ HV_REG_X5, offsetof(CPUARMState, xregs[5]) },
|
||||
{ HV_REG_X6, offsetof(CPUARMState, xregs[6]) },
|
||||
{ HV_REG_X7, offsetof(CPUARMState, xregs[7]) },
|
||||
{ HV_REG_X8, offsetof(CPUARMState, xregs[8]) },
|
||||
{ HV_REG_X9, offsetof(CPUARMState, xregs[9]) },
|
||||
{ HV_REG_X10, offsetof(CPUARMState, xregs[10]) },
|
||||
{ HV_REG_X11, offsetof(CPUARMState, xregs[11]) },
|
||||
{ HV_REG_X12, offsetof(CPUARMState, xregs[12]) },
|
||||
{ HV_REG_X13, offsetof(CPUARMState, xregs[13]) },
|
||||
{ HV_REG_X14, offsetof(CPUARMState, xregs[14]) },
|
||||
{ HV_REG_X15, offsetof(CPUARMState, xregs[15]) },
|
||||
{ HV_REG_X16, offsetof(CPUARMState, xregs[16]) },
|
||||
{ HV_REG_X17, offsetof(CPUARMState, xregs[17]) },
|
||||
{ HV_REG_X18, offsetof(CPUARMState, xregs[18]) },
|
||||
{ HV_REG_X19, offsetof(CPUARMState, xregs[19]) },
|
||||
{ HV_REG_X20, offsetof(CPUARMState, xregs[20]) },
|
||||
{ HV_REG_X21, offsetof(CPUARMState, xregs[21]) },
|
||||
{ HV_REG_X22, offsetof(CPUARMState, xregs[22]) },
|
||||
{ HV_REG_X23, offsetof(CPUARMState, xregs[23]) },
|
||||
{ HV_REG_X24, offsetof(CPUARMState, xregs[24]) },
|
||||
{ HV_REG_X25, offsetof(CPUARMState, xregs[25]) },
|
||||
{ HV_REG_X26, offsetof(CPUARMState, xregs[26]) },
|
||||
{ HV_REG_X27, offsetof(CPUARMState, xregs[27]) },
|
||||
{ HV_REG_X28, offsetof(CPUARMState, xregs[28]) },
|
||||
{ HV_REG_X29, offsetof(CPUARMState, xregs[29]) },
|
||||
{ HV_REG_X30, offsetof(CPUARMState, xregs[30]) },
|
||||
{ HV_REG_PC, offsetof(CPUARMState, pc) },
|
||||
};
|
||||
|
||||
static const struct hvf_reg_match hvf_fpreg_match[] = {
|
||||
{ HV_SIMD_FP_REG_Q0, offsetof(CPUARMState, vfp.zregs[0]) },
|
||||
{ HV_SIMD_FP_REG_Q1, offsetof(CPUARMState, vfp.zregs[1]) },
|
||||
{ HV_SIMD_FP_REG_Q2, offsetof(CPUARMState, vfp.zregs[2]) },
|
||||
{ HV_SIMD_FP_REG_Q3, offsetof(CPUARMState, vfp.zregs[3]) },
|
||||
{ HV_SIMD_FP_REG_Q4, offsetof(CPUARMState, vfp.zregs[4]) },
|
||||
{ HV_SIMD_FP_REG_Q5, offsetof(CPUARMState, vfp.zregs[5]) },
|
||||
{ HV_SIMD_FP_REG_Q6, offsetof(CPUARMState, vfp.zregs[6]) },
|
||||
{ HV_SIMD_FP_REG_Q7, offsetof(CPUARMState, vfp.zregs[7]) },
|
||||
{ HV_SIMD_FP_REG_Q8, offsetof(CPUARMState, vfp.zregs[8]) },
|
||||
{ HV_SIMD_FP_REG_Q9, offsetof(CPUARMState, vfp.zregs[9]) },
|
||||
{ HV_SIMD_FP_REG_Q10, offsetof(CPUARMState, vfp.zregs[10]) },
|
||||
{ HV_SIMD_FP_REG_Q11, offsetof(CPUARMState, vfp.zregs[11]) },
|
||||
{ HV_SIMD_FP_REG_Q12, offsetof(CPUARMState, vfp.zregs[12]) },
|
||||
{ HV_SIMD_FP_REG_Q13, offsetof(CPUARMState, vfp.zregs[13]) },
|
||||
{ HV_SIMD_FP_REG_Q14, offsetof(CPUARMState, vfp.zregs[14]) },
|
||||
{ HV_SIMD_FP_REG_Q15, offsetof(CPUARMState, vfp.zregs[15]) },
|
||||
{ HV_SIMD_FP_REG_Q16, offsetof(CPUARMState, vfp.zregs[16]) },
|
||||
{ HV_SIMD_FP_REG_Q17, offsetof(CPUARMState, vfp.zregs[17]) },
|
||||
{ HV_SIMD_FP_REG_Q18, offsetof(CPUARMState, vfp.zregs[18]) },
|
||||
{ HV_SIMD_FP_REG_Q19, offsetof(CPUARMState, vfp.zregs[19]) },
|
||||
{ HV_SIMD_FP_REG_Q20, offsetof(CPUARMState, vfp.zregs[20]) },
|
||||
{ HV_SIMD_FP_REG_Q21, offsetof(CPUARMState, vfp.zregs[21]) },
|
||||
{ HV_SIMD_FP_REG_Q22, offsetof(CPUARMState, vfp.zregs[22]) },
|
||||
{ HV_SIMD_FP_REG_Q23, offsetof(CPUARMState, vfp.zregs[23]) },
|
||||
{ HV_SIMD_FP_REG_Q24, offsetof(CPUARMState, vfp.zregs[24]) },
|
||||
{ HV_SIMD_FP_REG_Q25, offsetof(CPUARMState, vfp.zregs[25]) },
|
||||
{ HV_SIMD_FP_REG_Q26, offsetof(CPUARMState, vfp.zregs[26]) },
|
||||
{ HV_SIMD_FP_REG_Q27, offsetof(CPUARMState, vfp.zregs[27]) },
|
||||
{ HV_SIMD_FP_REG_Q28, offsetof(CPUARMState, vfp.zregs[28]) },
|
||||
{ HV_SIMD_FP_REG_Q29, offsetof(CPUARMState, vfp.zregs[29]) },
|
||||
{ HV_SIMD_FP_REG_Q30, offsetof(CPUARMState, vfp.zregs[30]) },
|
||||
{ HV_SIMD_FP_REG_Q31, offsetof(CPUARMState, vfp.zregs[31]) },
|
||||
};
|
||||
|
||||
struct hvf_sreg_match {
|
||||
int reg;
|
||||
uint32_t key;
|
||||
};
|
||||
|
||||
static const struct hvf_sreg_match hvf_sreg_match[] = {
|
||||
{ HV_SYS_REG_DBGBVR0_EL1, HVF_SYSREG(0, 0, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR0_EL1, HVF_SYSREG(0, 0, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR0_EL1, HVF_SYSREG(0, 0, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR0_EL1, HVF_SYSREG(0, 0, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR1_EL1, HVF_SYSREG(0, 1, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR1_EL1, HVF_SYSREG(0, 1, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR1_EL1, HVF_SYSREG(0, 1, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR1_EL1, HVF_SYSREG(0, 1, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR2_EL1, HVF_SYSREG(0, 2, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR2_EL1, HVF_SYSREG(0, 2, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR2_EL1, HVF_SYSREG(0, 2, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR2_EL1, HVF_SYSREG(0, 2, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR3_EL1, HVF_SYSREG(0, 3, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR3_EL1, HVF_SYSREG(0, 3, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR3_EL1, HVF_SYSREG(0, 3, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR3_EL1, HVF_SYSREG(0, 3, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR4_EL1, HVF_SYSREG(0, 4, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR4_EL1, HVF_SYSREG(0, 4, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR4_EL1, HVF_SYSREG(0, 4, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR4_EL1, HVF_SYSREG(0, 4, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR5_EL1, HVF_SYSREG(0, 5, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR5_EL1, HVF_SYSREG(0, 5, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR5_EL1, HVF_SYSREG(0, 5, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR5_EL1, HVF_SYSREG(0, 5, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR6_EL1, HVF_SYSREG(0, 6, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR6_EL1, HVF_SYSREG(0, 6, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR6_EL1, HVF_SYSREG(0, 6, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR6_EL1, HVF_SYSREG(0, 6, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR7_EL1, HVF_SYSREG(0, 7, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR7_EL1, HVF_SYSREG(0, 7, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR7_EL1, HVF_SYSREG(0, 7, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR7_EL1, HVF_SYSREG(0, 7, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR8_EL1, HVF_SYSREG(0, 8, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR8_EL1, HVF_SYSREG(0, 8, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR8_EL1, HVF_SYSREG(0, 8, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR8_EL1, HVF_SYSREG(0, 8, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR9_EL1, HVF_SYSREG(0, 9, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR9_EL1, HVF_SYSREG(0, 9, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR9_EL1, HVF_SYSREG(0, 9, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR9_EL1, HVF_SYSREG(0, 9, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR10_EL1, HVF_SYSREG(0, 10, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR10_EL1, HVF_SYSREG(0, 10, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR10_EL1, HVF_SYSREG(0, 10, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR10_EL1, HVF_SYSREG(0, 10, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR11_EL1, HVF_SYSREG(0, 11, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR11_EL1, HVF_SYSREG(0, 11, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR11_EL1, HVF_SYSREG(0, 11, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR11_EL1, HVF_SYSREG(0, 11, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR12_EL1, HVF_SYSREG(0, 12, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR12_EL1, HVF_SYSREG(0, 12, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR12_EL1, HVF_SYSREG(0, 12, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR12_EL1, HVF_SYSREG(0, 12, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR13_EL1, HVF_SYSREG(0, 13, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR13_EL1, HVF_SYSREG(0, 13, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR13_EL1, HVF_SYSREG(0, 13, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR13_EL1, HVF_SYSREG(0, 13, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR14_EL1, HVF_SYSREG(0, 14, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR14_EL1, HVF_SYSREG(0, 14, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR14_EL1, HVF_SYSREG(0, 14, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR14_EL1, HVF_SYSREG(0, 14, 14, 0, 7) },
|
||||
|
||||
{ HV_SYS_REG_DBGBVR15_EL1, HVF_SYSREG(0, 15, 14, 0, 4) },
|
||||
{ HV_SYS_REG_DBGBCR15_EL1, HVF_SYSREG(0, 15, 14, 0, 5) },
|
||||
{ HV_SYS_REG_DBGWVR15_EL1, HVF_SYSREG(0, 15, 14, 0, 6) },
|
||||
{ HV_SYS_REG_DBGWCR15_EL1, HVF_SYSREG(0, 15, 14, 0, 7) },
|
||||
|
||||
#ifdef SYNC_NO_RAW_REGS
|
||||
/*
|
||||
* The registers below are manually synced on init because they are
|
||||
* marked as NO_RAW. We still list them to make number space sync easier.
|
||||
*/
|
||||
{ HV_SYS_REG_MDCCINT_EL1, HVF_SYSREG(0, 2, 2, 0, 0) },
|
||||
{ HV_SYS_REG_MIDR_EL1, HVF_SYSREG(0, 0, 3, 0, 0) },
|
||||
{ HV_SYS_REG_MPIDR_EL1, HVF_SYSREG(0, 0, 3, 0, 5) },
|
||||
{ HV_SYS_REG_ID_AA64PFR0_EL1, HVF_SYSREG(0, 4, 3, 0, 0) },
|
||||
#endif
|
||||
{ HV_SYS_REG_ID_AA64PFR1_EL1, HVF_SYSREG(0, 4, 3, 0, 2) },
|
||||
{ HV_SYS_REG_ID_AA64DFR0_EL1, HVF_SYSREG(0, 5, 3, 0, 0) },
|
||||
{ HV_SYS_REG_ID_AA64DFR1_EL1, HVF_SYSREG(0, 5, 3, 0, 1) },
|
||||
{ HV_SYS_REG_ID_AA64ISAR0_EL1, HVF_SYSREG(0, 6, 3, 0, 0) },
|
||||
{ HV_SYS_REG_ID_AA64ISAR1_EL1, HVF_SYSREG(0, 6, 3, 0, 1) },
|
||||
#ifdef SYNC_NO_MMFR0
|
||||
/* We keep the hardware MMFR0 around. HW limits are there anyway */
|
||||
{ HV_SYS_REG_ID_AA64MMFR0_EL1, HVF_SYSREG(0, 7, 3, 0, 0) },
|
||||
#endif
|
||||
{ HV_SYS_REG_ID_AA64MMFR1_EL1, HVF_SYSREG(0, 7, 3, 0, 1) },
|
||||
{ HV_SYS_REG_ID_AA64MMFR2_EL1, HVF_SYSREG(0, 7, 3, 0, 2) },
|
||||
|
||||
{ HV_SYS_REG_MDSCR_EL1, HVF_SYSREG(0, 2, 2, 0, 2) },
|
||||
{ HV_SYS_REG_SCTLR_EL1, HVF_SYSREG(1, 0, 3, 0, 0) },
|
||||
{ HV_SYS_REG_CPACR_EL1, HVF_SYSREG(1, 0, 3, 0, 2) },
|
||||
{ HV_SYS_REG_TTBR0_EL1, HVF_SYSREG(2, 0, 3, 0, 0) },
|
||||
{ HV_SYS_REG_TTBR1_EL1, HVF_SYSREG(2, 0, 3, 0, 1) },
|
||||
{ HV_SYS_REG_TCR_EL1, HVF_SYSREG(2, 0, 3, 0, 2) },
|
||||
|
||||
{ HV_SYS_REG_APIAKEYLO_EL1, HVF_SYSREG(2, 1, 3, 0, 0) },
|
||||
{ HV_SYS_REG_APIAKEYHI_EL1, HVF_SYSREG(2, 1, 3, 0, 1) },
|
||||
{ HV_SYS_REG_APIBKEYLO_EL1, HVF_SYSREG(2, 1, 3, 0, 2) },
|
||||
{ HV_SYS_REG_APIBKEYHI_EL1, HVF_SYSREG(2, 1, 3, 0, 3) },
|
||||
{ HV_SYS_REG_APDAKEYLO_EL1, HVF_SYSREG(2, 2, 3, 0, 0) },
|
||||
{ HV_SYS_REG_APDAKEYHI_EL1, HVF_SYSREG(2, 2, 3, 0, 1) },
|
||||
{ HV_SYS_REG_APDBKEYLO_EL1, HVF_SYSREG(2, 2, 3, 0, 2) },
|
||||
{ HV_SYS_REG_APDBKEYHI_EL1, HVF_SYSREG(2, 2, 3, 0, 3) },
|
||||
{ HV_SYS_REG_APGAKEYLO_EL1, HVF_SYSREG(2, 3, 3, 0, 0) },
|
||||
{ HV_SYS_REG_APGAKEYHI_EL1, HVF_SYSREG(2, 3, 3, 0, 1) },
|
||||
|
||||
{ HV_SYS_REG_SPSR_EL1, HVF_SYSREG(4, 0, 3, 1, 0) },
|
||||
{ HV_SYS_REG_ELR_EL1, HVF_SYSREG(4, 0, 3, 0, 1) },
|
||||
{ HV_SYS_REG_SP_EL0, HVF_SYSREG(4, 1, 3, 0, 0) },
|
||||
{ HV_SYS_REG_AFSR0_EL1, HVF_SYSREG(5, 1, 3, 0, 0) },
|
||||
{ HV_SYS_REG_AFSR1_EL1, HVF_SYSREG(5, 1, 3, 0, 1) },
|
||||
{ HV_SYS_REG_ESR_EL1, HVF_SYSREG(5, 2, 3, 0, 0) },
|
||||
{ HV_SYS_REG_FAR_EL1, HVF_SYSREG(6, 0, 3, 0, 0) },
|
||||
{ HV_SYS_REG_PAR_EL1, HVF_SYSREG(7, 4, 3, 0, 0) },
|
||||
{ HV_SYS_REG_MAIR_EL1, HVF_SYSREG(10, 2, 3, 0, 0) },
|
||||
{ HV_SYS_REG_AMAIR_EL1, HVF_SYSREG(10, 3, 3, 0, 0) },
|
||||
{ HV_SYS_REG_VBAR_EL1, HVF_SYSREG(12, 0, 3, 0, 0) },
|
||||
{ HV_SYS_REG_CONTEXTIDR_EL1, HVF_SYSREG(13, 0, 3, 0, 1) },
|
||||
{ HV_SYS_REG_TPIDR_EL1, HVF_SYSREG(13, 0, 3, 0, 4) },
|
||||
{ HV_SYS_REG_CNTKCTL_EL1, HVF_SYSREG(14, 1, 3, 0, 0) },
|
||||
{ HV_SYS_REG_CSSELR_EL1, HVF_SYSREG(0, 0, 3, 2, 0) },
|
||||
{ HV_SYS_REG_TPIDR_EL0, HVF_SYSREG(13, 0, 3, 3, 2) },
|
||||
{ HV_SYS_REG_TPIDRRO_EL0, HVF_SYSREG(13, 0, 3, 3, 3) },
|
||||
{ HV_SYS_REG_CNTV_CTL_EL0, HVF_SYSREG(14, 3, 3, 3, 1) },
|
||||
{ HV_SYS_REG_CNTV_CVAL_EL0, HVF_SYSREG(14, 3, 3, 3, 2) },
|
||||
{ HV_SYS_REG_SP_EL1, HVF_SYSREG(4, 1, 3, 4, 0) },
|
||||
};
|
||||
|
||||
int hvf_get_registers(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
hv_return_t ret;
|
||||
uint64_t val;
|
||||
hv_simd_fp_uchar16_t fpval;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
|
||||
ret = hv_vcpu_get_reg(cpu->hvf->fd, hvf_reg_match[i].reg, &val);
|
||||
*(uint64_t *)((void *)env + hvf_reg_match[i].offset) = val;
|
||||
assert_hvf_ok(ret);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_fpreg_match); i++) {
|
||||
ret = hv_vcpu_get_simd_fp_reg(cpu->hvf->fd, hvf_fpreg_match[i].reg,
|
||||
&fpval);
|
||||
memcpy((void *)env + hvf_fpreg_match[i].offset, &fpval, sizeof(fpval));
|
||||
assert_hvf_ok(ret);
|
||||
}
|
||||
|
||||
val = 0;
|
||||
ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_FPCR, &val);
|
||||
assert_hvf_ok(ret);
|
||||
vfp_set_fpcr(env, val);
|
||||
|
||||
val = 0;
|
||||
ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_FPSR, &val);
|
||||
assert_hvf_ok(ret);
|
||||
vfp_set_fpsr(env, val);
|
||||
|
||||
ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_CPSR, &val);
|
||||
assert_hvf_ok(ret);
|
||||
pstate_write(env, val);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_sreg_match); i++) {
|
||||
ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, hvf_sreg_match[i].reg, &val);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
arm_cpu->cpreg_values[i] = val;
|
||||
}
|
||||
write_list_to_cpustate(arm_cpu);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hvf_put_registers(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
hv_return_t ret;
|
||||
uint64_t val;
|
||||
hv_simd_fp_uchar16_t fpval;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
|
||||
val = *(uint64_t *)((void *)env + hvf_reg_match[i].offset);
|
||||
ret = hv_vcpu_set_reg(cpu->hvf->fd, hvf_reg_match[i].reg, val);
|
||||
assert_hvf_ok(ret);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_fpreg_match); i++) {
|
||||
memcpy(&fpval, (void *)env + hvf_fpreg_match[i].offset, sizeof(fpval));
|
||||
ret = hv_vcpu_set_simd_fp_reg(cpu->hvf->fd, hvf_fpreg_match[i].reg,
|
||||
fpval);
|
||||
assert_hvf_ok(ret);
|
||||
}
|
||||
|
||||
ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_FPCR, vfp_get_fpcr(env));
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_FPSR, vfp_get_fpsr(env));
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_CPSR, pstate_read(env));
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
write_cpustate_to_list(arm_cpu, false);
|
||||
for (i = 0; i < ARRAY_SIZE(hvf_sreg_match); i++) {
|
||||
val = arm_cpu->cpreg_values[i];
|
||||
ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, hvf_sreg_match[i].reg, val);
|
||||
assert_hvf_ok(ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void flush_cpu_state(CPUState *cpu)
|
||||
{
|
||||
if (cpu->vcpu_dirty) {
|
||||
hvf_put_registers(cpu);
|
||||
cpu->vcpu_dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void hvf_set_reg(CPUState *cpu, int rt, uint64_t val)
|
||||
{
|
||||
hv_return_t r;
|
||||
|
||||
flush_cpu_state(cpu);
|
||||
|
||||
if (rt < 31) {
|
||||
r = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_X0 + rt, val);
|
||||
assert_hvf_ok(r);
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t hvf_get_reg(CPUState *cpu, int rt)
|
||||
{
|
||||
uint64_t val = 0;
|
||||
hv_return_t r;
|
||||
|
||||
flush_cpu_state(cpu);
|
||||
|
||||
if (rt < 31) {
|
||||
r = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_X0 + rt, &val);
|
||||
assert_hvf_ok(r);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static void hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
|
||||
{
|
||||
ARMISARegisters host_isar;
|
||||
const struct isar_regs {
|
||||
int reg;
|
||||
uint64_t *val;
|
||||
} regs[] = {
|
||||
{ HV_SYS_REG_ID_AA64PFR0_EL1, &host_isar.id_aa64pfr0 },
|
||||
{ HV_SYS_REG_ID_AA64PFR1_EL1, &host_isar.id_aa64pfr1 },
|
||||
{ HV_SYS_REG_ID_AA64DFR0_EL1, &host_isar.id_aa64dfr0 },
|
||||
{ HV_SYS_REG_ID_AA64DFR1_EL1, &host_isar.id_aa64dfr1 },
|
||||
{ HV_SYS_REG_ID_AA64ISAR0_EL1, &host_isar.id_aa64isar0 },
|
||||
{ HV_SYS_REG_ID_AA64ISAR1_EL1, &host_isar.id_aa64isar1 },
|
||||
{ HV_SYS_REG_ID_AA64MMFR0_EL1, &host_isar.id_aa64mmfr0 },
|
||||
{ HV_SYS_REG_ID_AA64MMFR1_EL1, &host_isar.id_aa64mmfr1 },
|
||||
{ HV_SYS_REG_ID_AA64MMFR2_EL1, &host_isar.id_aa64mmfr2 },
|
||||
};
|
||||
hv_vcpu_t fd;
|
||||
hv_vcpu_exit_t *exit;
|
||||
int i;
|
||||
|
||||
ahcf->dtb_compatible = "arm,arm-v8";
|
||||
ahcf->features = (1ULL << ARM_FEATURE_V8) |
|
||||
(1ULL << ARM_FEATURE_NEON) |
|
||||
(1ULL << ARM_FEATURE_AARCH64) |
|
||||
(1ULL << ARM_FEATURE_PMU) |
|
||||
(1ULL << ARM_FEATURE_GENERIC_TIMER);
|
||||
|
||||
/* We set up a small vcpu to extract host registers */
|
||||
|
||||
assert_hvf_ok(hv_vcpu_create(&fd, &exit, NULL));
|
||||
for (i = 0; i < ARRAY_SIZE(regs); i++) {
|
||||
assert_hvf_ok(hv_vcpu_get_sys_reg(fd, regs[i].reg, regs[i].val));
|
||||
}
|
||||
assert_hvf_ok(hv_vcpu_get_sys_reg(fd, HV_SYS_REG_MIDR_EL1, &ahcf->midr));
|
||||
assert_hvf_ok(hv_vcpu_destroy(fd));
|
||||
|
||||
ahcf->isar = host_isar;
|
||||
ahcf->reset_sctlr = 0x00c50078;
|
||||
|
||||
/* Make sure we don't advertise AArch32 support for EL0/EL1 */
|
||||
g_assert((host_isar.id_aa64pfr0 & 0xff) == 0x11);
|
||||
}
|
||||
|
||||
void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu)
|
||||
{
|
||||
if (!arm_host_cpu_features.dtb_compatible) {
|
||||
if (!hvf_enabled()) {
|
||||
cpu->host_cpu_probe_failed = true;
|
||||
return;
|
||||
}
|
||||
hvf_arm_get_host_cpu_features(&arm_host_cpu_features);
|
||||
}
|
||||
|
||||
cpu->dtb_compatible = arm_host_cpu_features.dtb_compatible;
|
||||
cpu->isar = arm_host_cpu_features.isar;
|
||||
cpu->env.features = arm_host_cpu_features.features;
|
||||
cpu->midr = arm_host_cpu_features.midr;
|
||||
cpu->reset_sctlr = arm_host_cpu_features.reset_sctlr;
|
||||
}
|
||||
|
||||
void hvf_arch_vcpu_destroy(CPUState *cpu)
|
||||
{
|
||||
}
|
||||
|
||||
int hvf_arch_init_vcpu(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
uint32_t sregs_match_len = ARRAY_SIZE(hvf_sreg_match);
|
||||
uint64_t pfr;
|
||||
hv_return_t ret;
|
||||
int i;
|
||||
|
||||
env->aarch64 = 1;
|
||||
asm volatile("mrs %0, cntfrq_el0" : "=r"(arm_cpu->gt_cntfrq_hz));
|
||||
|
||||
/* Allocate enough space for our sysreg sync */
|
||||
arm_cpu->cpreg_indexes = g_renew(uint64_t, arm_cpu->cpreg_indexes,
|
||||
sregs_match_len);
|
||||
arm_cpu->cpreg_values = g_renew(uint64_t, arm_cpu->cpreg_values,
|
||||
sregs_match_len);
|
||||
arm_cpu->cpreg_vmstate_indexes = g_renew(uint64_t,
|
||||
arm_cpu->cpreg_vmstate_indexes,
|
||||
sregs_match_len);
|
||||
arm_cpu->cpreg_vmstate_values = g_renew(uint64_t,
|
||||
arm_cpu->cpreg_vmstate_values,
|
||||
sregs_match_len);
|
||||
|
||||
memset(arm_cpu->cpreg_values, 0, sregs_match_len * sizeof(uint64_t));
|
||||
arm_cpu->cpreg_array_len = sregs_match_len;
|
||||
arm_cpu->cpreg_vmstate_array_len = sregs_match_len;
|
||||
|
||||
/* Populate cp list for all known sysregs */
|
||||
for (i = 0; i < sregs_match_len; i++) {
|
||||
const ARMCPRegInfo *ri;
|
||||
|
||||
arm_cpu->cpreg_indexes[i] = cpreg_to_kvm_id(hvf_sreg_match[i].key);
|
||||
|
||||
ri = get_arm_cp_reginfo(arm_cpu->cp_regs, hvf_sreg_match[i].key);
|
||||
if (ri) {
|
||||
assert(!(ri->type & ARM_CP_NO_RAW));
|
||||
}
|
||||
}
|
||||
write_cpustate_to_list(arm_cpu, false);
|
||||
|
||||
/* Set CP_NO_RAW system registers on init */
|
||||
ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_MIDR_EL1,
|
||||
arm_cpu->midr);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_MPIDR_EL1,
|
||||
arm_cpu->mp_affinity);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64PFR0_EL1, &pfr);
|
||||
assert_hvf_ok(ret);
|
||||
pfr |= env->gicv3state ? (1 << 24) : 0;
|
||||
ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64PFR0_EL1, pfr);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
/* We're limited to underlying hardware caps, override internal versions */
|
||||
ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64MMFR0_EL1,
|
||||
&arm_cpu->isar.id_aa64mmfr0);
|
||||
assert_hvf_ok(ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hvf_kick_vcpu_thread(CPUState *cpu)
|
||||
{
|
||||
cpus_kick_thread(cpu);
|
||||
hv_vcpus_exit(&cpu->hvf->fd, 1);
|
||||
}
|
||||
|
||||
static void hvf_raise_exception(CPUARMState *env, uint32_t excp,
|
||||
uint32_t syndrome)
|
||||
{
|
||||
unsigned int new_el = 1;
|
||||
unsigned int old_mode = pstate_read(env);
|
||||
unsigned int new_mode = aarch64_pstate_mode(new_el, true);
|
||||
target_ulong addr = env->cp15.vbar_el[new_el];
|
||||
|
||||
env->cp15.esr_el[new_el] = syndrome;
|
||||
aarch64_save_sp(env, arm_current_el(env));
|
||||
env->elr_el[new_el] = env->pc;
|
||||
env->banked_spsr[aarch64_banked_spsr_index(new_el)] = old_mode;
|
||||
pstate_write(env, PSTATE_DAIF | new_mode);
|
||||
aarch64_restore_sp(env, new_el);
|
||||
env->pc = addr;
|
||||
}
|
||||
|
||||
static int hvf_psci_cpu_off(ARMCPU *arm_cpu)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
ret = arm_set_cpu_off(arm_cpu->mp_affinity);
|
||||
assert(ret == QEMU_ARM_POWERCTL_RET_SUCCESS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hvf_handle_psci_call(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
uint64_t param[4] = {
|
||||
env->xregs[0],
|
||||
env->xregs[1],
|
||||
env->xregs[2],
|
||||
env->xregs[3]
|
||||
};
|
||||
uint64_t context_id, mpidr;
|
||||
bool target_aarch64 = true;
|
||||
CPUState *target_cpu_state;
|
||||
ARMCPU *target_cpu;
|
||||
target_ulong entry;
|
||||
int target_el = 1;
|
||||
int32_t ret = 0;
|
||||
|
||||
trace_hvf_psci_call(param[0], param[1], param[2], param[3],
|
||||
arm_cpu->mp_affinity);
|
||||
|
||||
switch (param[0]) {
|
||||
case QEMU_PSCI_0_2_FN_PSCI_VERSION:
|
||||
ret = QEMU_PSCI_0_2_RET_VERSION_0_2;
|
||||
break;
|
||||
case QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE:
|
||||
ret = QEMU_PSCI_0_2_RET_TOS_MIGRATION_NOT_REQUIRED; /* No trusted OS */
|
||||
break;
|
||||
case QEMU_PSCI_0_2_FN_AFFINITY_INFO:
|
||||
case QEMU_PSCI_0_2_FN64_AFFINITY_INFO:
|
||||
mpidr = param[1];
|
||||
|
||||
switch (param[2]) {
|
||||
case 0:
|
||||
target_cpu_state = arm_get_cpu_by_id(mpidr);
|
||||
if (!target_cpu_state) {
|
||||
ret = QEMU_PSCI_RET_INVALID_PARAMS;
|
||||
break;
|
||||
}
|
||||
target_cpu = ARM_CPU(target_cpu_state);
|
||||
|
||||
ret = target_cpu->power_state;
|
||||
break;
|
||||
default:
|
||||
/* Everything above affinity level 0 is always on. */
|
||||
ret = 0;
|
||||
}
|
||||
break;
|
||||
case QEMU_PSCI_0_2_FN_SYSTEM_RESET:
|
||||
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
||||
/* QEMU reset and shutdown are async requests, but PSCI
|
||||
* mandates that we never return from the reset/shutdown
|
||||
* call, so power the CPU off now so it doesn't execute
|
||||
* anything further.
|
||||
*/
|
||||
return hvf_psci_cpu_off(arm_cpu);
|
||||
case QEMU_PSCI_0_2_FN_SYSTEM_OFF:
|
||||
qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
|
||||
return hvf_psci_cpu_off(arm_cpu);
|
||||
case QEMU_PSCI_0_1_FN_CPU_ON:
|
||||
case QEMU_PSCI_0_2_FN_CPU_ON:
|
||||
case QEMU_PSCI_0_2_FN64_CPU_ON:
|
||||
mpidr = param[1];
|
||||
entry = param[2];
|
||||
context_id = param[3];
|
||||
ret = arm_set_cpu_on(mpidr, entry, context_id,
|
||||
target_el, target_aarch64);
|
||||
break;
|
||||
case QEMU_PSCI_0_1_FN_CPU_OFF:
|
||||
case QEMU_PSCI_0_2_FN_CPU_OFF:
|
||||
return hvf_psci_cpu_off(arm_cpu);
|
||||
case QEMU_PSCI_0_1_FN_CPU_SUSPEND:
|
||||
case QEMU_PSCI_0_2_FN_CPU_SUSPEND:
|
||||
case QEMU_PSCI_0_2_FN64_CPU_SUSPEND:
|
||||
/* Affinity levels are not supported in QEMU */
|
||||
if (param[1] & 0xfffe0000) {
|
||||
ret = QEMU_PSCI_RET_INVALID_PARAMS;
|
||||
break;
|
||||
}
|
||||
/* Powerdown is not supported, we always go into WFI */
|
||||
env->xregs[0] = 0;
|
||||
hvf_wfi(cpu);
|
||||
break;
|
||||
case QEMU_PSCI_0_1_FN_MIGRATE:
|
||||
case QEMU_PSCI_0_2_FN_MIGRATE:
|
||||
ret = QEMU_PSCI_RET_NOT_SUPPORTED;
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
env->xregs[0] = ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint64_t hvf_sysreg_read(CPUState *cpu, uint32_t reg)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
uint64_t val = 0;
|
||||
|
||||
switch (reg) {
|
||||
case SYSREG_CNTPCT_EL0:
|
||||
val = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) /
|
||||
gt_cntfrq_period_ns(arm_cpu);
|
||||
break;
|
||||
case SYSREG_PMCCNTR_EL0:
|
||||
val = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
||||
break;
|
||||
default:
|
||||
trace_hvf_unhandled_sysreg_read(reg,
|
||||
(reg >> 20) & 0x3,
|
||||
(reg >> 14) & 0x7,
|
||||
(reg >> 10) & 0xf,
|
||||
(reg >> 1) & 0xf,
|
||||
(reg >> 17) & 0x7);
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static void hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val)
|
||||
{
|
||||
switch (reg) {
|
||||
case SYSREG_CNTPCT_EL0:
|
||||
break;
|
||||
default:
|
||||
trace_hvf_unhandled_sysreg_write(reg,
|
||||
(reg >> 20) & 0x3,
|
||||
(reg >> 14) & 0x7,
|
||||
(reg >> 10) & 0xf,
|
||||
(reg >> 1) & 0xf,
|
||||
(reg >> 17) & 0x7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int hvf_inject_interrupts(CPUState *cpu)
|
||||
{
|
||||
if (cpu->interrupt_request & CPU_INTERRUPT_FIQ) {
|
||||
trace_hvf_inject_fiq();
|
||||
hv_vcpu_set_pending_interrupt(cpu->hvf->fd, HV_INTERRUPT_TYPE_FIQ,
|
||||
true);
|
||||
}
|
||||
|
||||
if (cpu->interrupt_request & CPU_INTERRUPT_HARD) {
|
||||
trace_hvf_inject_irq();
|
||||
hv_vcpu_set_pending_interrupt(cpu->hvf->fd, HV_INTERRUPT_TYPE_IRQ,
|
||||
true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hvf_wait_for_ipi(CPUState *cpu, struct timespec *ts)
|
||||
{
|
||||
/*
|
||||
* Use pselect to sleep so that other threads can IPI us while we're
|
||||
* sleeping.
|
||||
*/
|
||||
qatomic_mb_set(&cpu->thread_kicked, false);
|
||||
qemu_mutex_unlock_iothread();
|
||||
pselect(0, 0, 0, 0, ts, &cpu->hvf->unblock_ipi_mask);
|
||||
qemu_mutex_lock_iothread();
|
||||
}
|
||||
|
||||
static void hvf_wfi(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
hv_return_t r;
|
||||
uint64_t ctl;
|
||||
|
||||
if (cpu->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_FIQ)) {
|
||||
/* Interrupt pending, no need to wait */
|
||||
return;
|
||||
}
|
||||
|
||||
r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CTL_EL0,
|
||||
&ctl);
|
||||
assert_hvf_ok(r);
|
||||
|
||||
if (!(ctl & 1) || (ctl & 2)) {
|
||||
/* Timer disabled or masked, just wait for an IPI. */
|
||||
hvf_wait_for_ipi(cpu, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t cval;
|
||||
r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CVAL_EL0,
|
||||
&cval);
|
||||
assert_hvf_ok(r);
|
||||
|
||||
int64_t ticks_to_sleep = cval - mach_absolute_time();
|
||||
if (ticks_to_sleep < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t seconds = ticks_to_sleep / arm_cpu->gt_cntfrq_hz;
|
||||
uint64_t nanos =
|
||||
(ticks_to_sleep - arm_cpu->gt_cntfrq_hz * seconds) *
|
||||
1000000000 / arm_cpu->gt_cntfrq_hz;
|
||||
|
||||
/*
|
||||
* Don't sleep for less than the time a context switch would take,
|
||||
* so that we can satisfy fast timer requests on the same CPU.
|
||||
* Measurements on M1 show the sweet spot to be ~2ms.
|
||||
*/
|
||||
if (!seconds && nanos < 2000000) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct timespec ts = { seconds, nanos };
|
||||
hvf_wait_for_ipi(cpu, &ts);
|
||||
}
|
||||
|
||||
static void hvf_sync_vtimer(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
hv_return_t r;
|
||||
uint64_t ctl;
|
||||
bool irq_state;
|
||||
|
||||
if (!cpu->hvf->vtimer_masked) {
|
||||
/* We will get notified on vtimer changes by hvf, nothing to do */
|
||||
return;
|
||||
}
|
||||
|
||||
r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CTL_EL0, &ctl);
|
||||
assert_hvf_ok(r);
|
||||
|
||||
irq_state = (ctl & (TMR_CTL_ENABLE | TMR_CTL_IMASK | TMR_CTL_ISTATUS)) ==
|
||||
(TMR_CTL_ENABLE | TMR_CTL_ISTATUS);
|
||||
qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], irq_state);
|
||||
|
||||
if (!irq_state) {
|
||||
/* Timer no longer asserting, we can unmask it */
|
||||
hv_vcpu_set_vtimer_mask(cpu->hvf->fd, false);
|
||||
cpu->hvf->vtimer_masked = false;
|
||||
}
|
||||
}
|
||||
|
||||
int hvf_vcpu_exec(CPUState *cpu)
|
||||
{
|
||||
ARMCPU *arm_cpu = ARM_CPU(cpu);
|
||||
CPUARMState *env = &arm_cpu->env;
|
||||
hv_vcpu_exit_t *hvf_exit = cpu->hvf->exit;
|
||||
hv_return_t r;
|
||||
bool advance_pc = false;
|
||||
|
||||
flush_cpu_state(cpu);
|
||||
|
||||
hvf_sync_vtimer(cpu);
|
||||
|
||||
if (hvf_inject_interrupts(cpu)) {
|
||||
return EXCP_INTERRUPT;
|
||||
}
|
||||
|
||||
if (cpu->halted) {
|
||||
/* On unhalt, we usually have CPU state changes. Prepare for them. */
|
||||
cpu_synchronize_state(cpu);
|
||||
return EXCP_HLT;
|
||||
}
|
||||
|
||||
qemu_mutex_unlock_iothread();
|
||||
assert_hvf_ok(hv_vcpu_run(cpu->hvf->fd));
|
||||
|
||||
/* handle VMEXIT */
|
||||
uint64_t exit_reason = hvf_exit->reason;
|
||||
uint64_t syndrome = hvf_exit->exception.syndrome;
|
||||
uint32_t ec = syn_get_ec(syndrome);
|
||||
|
||||
qemu_mutex_lock_iothread();
|
||||
switch (exit_reason) {
|
||||
case HV_EXIT_REASON_EXCEPTION:
|
||||
/* This is the main one, handle below. */
|
||||
break;
|
||||
case HV_EXIT_REASON_VTIMER_ACTIVATED:
|
||||
qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], 1);
|
||||
cpu->hvf->vtimer_masked = true;
|
||||
return 0;
|
||||
case HV_EXIT_REASON_CANCELED:
|
||||
/* we got kicked, no exit to process */
|
||||
return 0;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
switch (ec) {
|
||||
case EC_DATAABORT: {
|
||||
bool isv = syndrome & ARM_EL_ISV;
|
||||
bool iswrite = (syndrome >> 6) & 1;
|
||||
bool s1ptw = (syndrome >> 7) & 1;
|
||||
uint32_t sas = (syndrome >> 22) & 3;
|
||||
uint32_t len = 1 << sas;
|
||||
uint32_t srt = (syndrome >> 16) & 0x1f;
|
||||
uint64_t val = 0;
|
||||
|
||||
trace_hvf_data_abort(env->pc, hvf_exit->exception.virtual_address,
|
||||
hvf_exit->exception.physical_address, isv,
|
||||
iswrite, s1ptw, len, srt);
|
||||
|
||||
assert(isv);
|
||||
|
||||
if (iswrite) {
|
||||
val = hvf_get_reg(cpu, srt);
|
||||
address_space_write(&address_space_memory,
|
||||
hvf_exit->exception.physical_address,
|
||||
MEMTXATTRS_UNSPECIFIED, &val, len);
|
||||
} else {
|
||||
address_space_read(&address_space_memory,
|
||||
hvf_exit->exception.physical_address,
|
||||
MEMTXATTRS_UNSPECIFIED, &val, len);
|
||||
hvf_set_reg(cpu, srt, val);
|
||||
}
|
||||
|
||||
advance_pc = true;
|
||||
break;
|
||||
}
|
||||
case EC_SYSTEMREGISTERTRAP: {
|
||||
bool isread = (syndrome >> 0) & 1;
|
||||
uint32_t rt = (syndrome >> 5) & 0x1f;
|
||||
uint32_t reg = syndrome & SYSREG_MASK;
|
||||
uint64_t val = 0;
|
||||
|
||||
if (isread) {
|
||||
val = hvf_sysreg_read(cpu, reg);
|
||||
trace_hvf_sysreg_read(reg,
|
||||
(reg >> 20) & 0x3,
|
||||
(reg >> 14) & 0x7,
|
||||
(reg >> 10) & 0xf,
|
||||
(reg >> 1) & 0xf,
|
||||
(reg >> 17) & 0x7,
|
||||
val);
|
||||
hvf_set_reg(cpu, rt, val);
|
||||
} else {
|
||||
val = hvf_get_reg(cpu, rt);
|
||||
trace_hvf_sysreg_write(reg,
|
||||
(reg >> 20) & 0x3,
|
||||
(reg >> 14) & 0x7,
|
||||
(reg >> 10) & 0xf,
|
||||
(reg >> 1) & 0xf,
|
||||
(reg >> 17) & 0x7,
|
||||
val);
|
||||
hvf_sysreg_write(cpu, reg, val);
|
||||
}
|
||||
|
||||
advance_pc = true;
|
||||
break;
|
||||
}
|
||||
case EC_WFX_TRAP:
|
||||
advance_pc = true;
|
||||
if (!(syndrome & WFX_IS_WFE)) {
|
||||
hvf_wfi(cpu);
|
||||
}
|
||||
break;
|
||||
case EC_AA64_HVC:
|
||||
cpu_synchronize_state(cpu);
|
||||
if (hvf_handle_psci_call(cpu)) {
|
||||
trace_hvf_unknown_hvf(env->xregs[0]);
|
||||
hvf_raise_exception(env, EXCP_UDEF, syn_uncategorized());
|
||||
}
|
||||
break;
|
||||
case EC_AA64_SMC:
|
||||
cpu_synchronize_state(cpu);
|
||||
if (!hvf_handle_psci_call(cpu)) {
|
||||
advance_pc = true;
|
||||
} else if (env->xregs[0] == QEMU_SMCCC_TC_WINDOWS10_BOOT) {
|
||||
/* This special SMC is called by Windows 10 on boot. Return error */
|
||||
env->xregs[0] = -1;
|
||||
advance_pc = true;
|
||||
} else {
|
||||
trace_hvf_unknown_smc(env->xregs[0]);
|
||||
hvf_raise_exception(env, EXCP_UDEF, syn_uncategorized());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cpu_synchronize_state(cpu);
|
||||
trace_hvf_exit(syndrome, ec, env->pc);
|
||||
error_report("0x%llx: unhandled exit 0x%llx", env->pc, exit_reason);
|
||||
}
|
||||
|
||||
if (advance_pc) {
|
||||
uint64_t pc;
|
||||
|
||||
flush_cpu_state(cpu);
|
||||
|
||||
r = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_PC, &pc);
|
||||
assert_hvf_ok(r);
|
||||
pc += 4;
|
||||
r = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_PC, pc);
|
||||
assert_hvf_ok(r);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
arm_softmmu_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files(
|
||||
'hvf.c',
|
||||
))
|
||||
@@ -0,0 +1,11 @@
|
||||
hvf_unhandled_sysreg_read(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2) "unhandled sysreg read 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d)"
|
||||
hvf_unhandled_sysreg_write(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2) "unhandled sysreg write 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d)"
|
||||
hvf_inject_fiq(void) "injecting FIQ"
|
||||
hvf_inject_irq(void) "injecting IRQ"
|
||||
hvf_data_abort(uint64_t pc, uint64_t va, uint64_t pa, bool isv, bool iswrite, bool s1ptw, uint32_t len, uint32_t srt) "data abort: [pc=0x%"PRIx64" va=0x%016"PRIx64" pa=0x%016"PRIx64" isv=%d iswrite=%d s1ptw=%d len=%d srt=%d]"
|
||||
hvf_sysreg_read(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2, uint64_t val) "sysreg read 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d) = 0x%016"PRIx64
|
||||
hvf_sysreg_write(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2, uint64_t val) "sysreg write 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d, val=0x%016"PRIx64")"
|
||||
hvf_unknown_hvf(uint64_t x0) "unknown HVC! 0x%016"PRIx64
|
||||
hvf_unknown_smc(uint64_t x0) "unknown SMC! 0x%016"PRIx64
|
||||
hvf_exit(uint64_t syndrome, uint32_t ec, uint64_t pc) "exit: 0x%"PRIx64" [ec=0x%x pc=0x%"PRIx64"]"
|
||||
hvf_psci_call(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3, uint32_t cpuid) "PSCI Call x0=0x%016"PRIx64" x1=0x%016"PRIx64" x2=0x%016"PRIx64" x3=0x%016"PRIx64" cpu=0x%x"
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* QEMU Hypervisor.framework (HVF) support -- ARM specifics
|
||||
*
|
||||
* Copyright (c) 2021 Alexander Graf
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QEMU_HVF_ARM_H
|
||||
#define QEMU_HVF_ARM_H
|
||||
|
||||
#include "qemu/accel.h"
|
||||
#include "cpu.h"
|
||||
|
||||
void hvf_arm_set_cpu_features_from_host(struct ARMCPU *cpu);
|
||||
|
||||
#endif
|
||||
@@ -85,6 +85,8 @@ MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_SUSPEND, PSCI_0_2_FN64_CPU_SUSPEND);
|
||||
MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_ON, PSCI_0_2_FN64_CPU_ON);
|
||||
MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_MIGRATE, PSCI_0_2_FN64_MIGRATE);
|
||||
|
||||
#define QEMU_SMCCC_TC_WINDOWS10_BOOT 0xc3000001
|
||||
|
||||
/* PSCI v0.2 return values used by TCG emulation of PSCI */
|
||||
|
||||
/* No Trusted OS migration to worry about when offlining CPUs */
|
||||
|
||||
@@ -214,8 +214,6 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
|
||||
*/
|
||||
void kvm_arm_destroy_scratch_host_vcpu(int *fdarray);
|
||||
|
||||
#define TYPE_ARM_HOST_CPU "host-" TYPE_ARM_CPU
|
||||
|
||||
/**
|
||||
* ARMHostCPUFeatures: information about the host CPU (identified
|
||||
* by asking the host kernel)
|
||||
|
||||
@@ -60,5 +60,7 @@ arm_softmmu_ss.add(files(
|
||||
'psci.c',
|
||||
))
|
||||
|
||||
subdir('hvf')
|
||||
|
||||
target_arch += {'arm': arm_ss}
|
||||
target_softmmu_arch += {'arm': arm_softmmu_ss}
|
||||
@@ -69,6 +69,7 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type)
|
||||
case QEMU_PSCI_0_2_FN64_CPU_SUSPEND:
|
||||
case QEMU_PSCI_0_1_FN_MIGRATE:
|
||||
case QEMU_PSCI_0_2_FN_MIGRATE:
|
||||
case QEMU_SMCCC_TC_WINDOWS10_BOOT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -194,6 +195,7 @@ void arm_handle_psci_call(ARMCPU *cpu)
|
||||
break;
|
||||
case QEMU_PSCI_0_1_FN_MIGRATE:
|
||||
case QEMU_PSCI_0_2_FN_MIGRATE:
|
||||
case QEMU_SMCCC_TC_WINDOWS10_BOOT:
|
||||
ret = QEMU_PSCI_RET_NOT_SUPPORTED;
|
||||
break;
|
||||
default:
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,21 @@
|
||||
/* 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.
|
||||
*/
|
||||
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, 0, 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)
|
||||
@@ -0,0 +1,11 @@
|
||||
/* 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', MAKE_64BIT_MASK(0, TCG_TARGET_NB_REGS))
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* 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 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
|
||||
|
||||
// Logicals.
|
||||
#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
|
||||
|
||||
#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_andc_i64 1
|
||||
#define TCG_TARGET_HAS_eqv_i64 1
|
||||
#define TCG_TARGET_HAS_orc_i64 1
|
||||
|
||||
// We don't curretly support rotates, since AArch64 lacks ROL.
|
||||
// We'll fix this later.
|
||||
#define TCG_TARGET_HAS_rot_i32 0
|
||||
#define TCG_TARGET_HAS_rot_i64 0
|
||||
|
||||
// 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
|
||||
|
||||
// Specify we'll handle direct jumps.
|
||||
#define TCG_TARGET_HAS_direct_jump 1
|
||||
|
||||
//
|
||||
// Potential TODOs.
|
||||
//
|
||||
|
||||
// TODO: implement DEPOSIT as BFI.
|
||||
#define TCG_TARGET_HAS_deposit_i32 0
|
||||
#define TCG_TARGET_HAS_deposit_i64 0
|
||||
|
||||
// TODO: implement EXTRACT as BFX.
|
||||
#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
|
||||
|
||||
// TODO: it might be worth writing a gadget for this
|
||||
#define TCG_TARGET_HAS_movcond_i32 0
|
||||
#define TCG_TARGET_HAS_movcond_i64 0
|
||||
|
||||
//
|
||||
// Unsupported instructions.
|
||||
//
|
||||
|
||||
// ARMv8 doesn't have instructions for NAND/NOR.
|
||||
#define TCG_TARGET_HAS_nand_i32 0
|
||||
#define TCG_TARGET_HAS_nor_i32 0
|
||||
#define TCG_TARGET_HAS_nor_i64 0
|
||||
#define TCG_TARGET_HAS_nand_i64 0
|
||||
|
||||
// aarch64's CLZ is implemented without a condition, so it
|
||||
#define TCG_TARGET_HAS_clz_i32 0
|
||||
#define TCG_TARGET_HAS_ctz_i32 0
|
||||
#define TCG_TARGET_HAS_ctpop_i32 0
|
||||
#define TCG_TARGET_HAS_clz_i64 0
|
||||
#define TCG_TARGET_HAS_ctz_i64 0
|
||||
#define TCG_TARGET_HAS_ctpop_i64 0
|
||||
|
||||
// We don't have a simple gadget for this, since we're always assuming softmmu.
|
||||
#define TCG_TARGET_HAS_qemu_st8_i32 0
|
||||
|
||||
// No AArch64 equivalent.a
|
||||
#define TCG_TARGET_HAS_extrl_i64_i32 0
|
||||
#define TCG_TARGET_HAS_extrh_i64_i32 0
|
||||
|
||||
#define TCG_TARGET_HAS_extract2_i64 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
|
||||
|
||||
//
|
||||
// Platform metadata.
|
||||
//
|
||||
|
||||
// Number of registers available.
|
||||
// It might make sense to up these, since we can also use x16 -> x25?
|
||||
#define TCG_TARGET_NB_REGS 16
|
||||
|
||||
/* List of registers which are used by TCG. */
|
||||
typedef enum {
|
||||
TCG_REG_R0 = 0,
|
||||
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_AREG0 = TCG_REG_R14,
|
||||
TCG_REG_CALL_STACK = TCG_REG_R15,
|
||||
} TCGReg;
|
||||
|
||||
// Specify the shape of the stack our runtime will use.
|
||||
#define TCG_TARGET_CALL_STACK_OFFSET 0
|
||||
#define TCG_TARGET_STACK_ALIGN 16
|
||||
|
||||
// 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);
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
|
||||
#endif /* TCG_TARGET_H */
|
||||
Executable
+788
@@ -0,0 +1,788 @@
|
||||
#!/usr/bin/env python3
|
||||
""" Gadget-code generator for QEMU TCTI on AArch64.
|
||||
|
||||
Generates a C-code include file containing 'gadgets' for use by TCTI.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import itertools
|
||||
|
||||
# Get a handle on the file we'll be working with, and redirect print to it.
|
||||
if len(sys.argv) > 1:
|
||||
out_file = open(sys.argv[1], "w")
|
||||
|
||||
# Hook our print function, so it always outputs to the relevant file.
|
||||
core_print = print
|
||||
print = lambda *a, **k : core_print(*a, **k, file=out_file)
|
||||
|
||||
# Epilogue code follows at the end of each gadget, and handles continuing execution.
|
||||
EPILOGUE = (
|
||||
# Load our next gadget address from our bytecode stream, advancing it.
|
||||
"ldr x27, [x28], #8",
|
||||
|
||||
# Jump to the next gadget.
|
||||
"br x27"
|
||||
)
|
||||
|
||||
# The number of general-purpose registers we're affording the TCG. This must match
|
||||
# the configuration in the TCTI target.
|
||||
TCG_REGISTER_COUNT = 16
|
||||
TCG_REGISTER_NUMBERS = list(range(TCG_REGISTER_COUNT))
|
||||
|
||||
# Helper that provides each of the AArch64 condition codes of interest.
|
||||
ARCH_CONDITION_CODES = ["eq", "ne", "lt", "ge", "le", "gt", "lo", "hs", "ls", "hi"]
|
||||
|
||||
# We'll create a variety of gadgets that assume the MMU's TLB is stored at certain
|
||||
# offsets into its structure. These should match the offsets in tcg-target.c.in.
|
||||
QEMU_ALLOWED_MMU_OFFSETS = [ 64, 96, 128 ]
|
||||
|
||||
# Statistics.
|
||||
gadgets = 0
|
||||
instructions = 0
|
||||
|
||||
def simple(name, *lines):
|
||||
""" Generates a simple gadget that needs no per-register specialization. """
|
||||
|
||||
global gadgets, instructions
|
||||
|
||||
gadgets += 1
|
||||
|
||||
# Create our C/ASM framing.
|
||||
#print(f"__attribute__((naked)) static void gadget_{name}(void)")
|
||||
print(f"__attribute__((naked)) static void gadget_{name}(void);")
|
||||
print(f"__attribute__((naked)) static void gadget_{name}(void)")
|
||||
print("{")
|
||||
|
||||
# Add the core gadget
|
||||
print("\tasm(")
|
||||
for line in lines + EPILOGUE:
|
||||
print(f"\t\t\"{line} \\n\"")
|
||||
instructions += 1
|
||||
print("\t);")
|
||||
|
||||
# End our framing.
|
||||
print("}\n")
|
||||
|
||||
|
||||
def with_register_substitutions(name, substitutions, *lines, immediate_range=range(0)):
|
||||
""" Generates a collection of gadgtes with register substitutions. """
|
||||
|
||||
def substitutions_for_letter(letter, number, line):
|
||||
""" Helper that transforms Wd => w1, implementing gadget substitutions. """
|
||||
|
||||
# Register substitutions...
|
||||
line = line.replace(f"X{letter}", f"x{number}")
|
||||
line = line.replace(f"W{letter}", f"w{number}")
|
||||
|
||||
# ... immediate substitutions.
|
||||
line = line.replace(f"I{letter}", f"{number}")
|
||||
return line
|
||||
|
||||
|
||||
# Build a list of all the various stages we'll iterate over...
|
||||
immediate_parameters = list(immediate_range)
|
||||
parameters = ([TCG_REGISTER_NUMBERS] * len(substitutions))
|
||||
|
||||
# ... adding immediates, if need be.
|
||||
if immediate_parameters:
|
||||
parameters.append(immediate_parameters)
|
||||
substitutions = substitutions + ['i']
|
||||
|
||||
# Generate a list of register-combinations we'll support.
|
||||
permutations = itertools.product(*parameters)
|
||||
|
||||
# For each permutation...
|
||||
for permutation in permutations:
|
||||
new_lines = lines
|
||||
|
||||
# Replace each placeholder element with its proper value...
|
||||
for index, element in enumerate(permutation):
|
||||
letter = substitutions[index]
|
||||
number = element
|
||||
|
||||
# Create new gadgets for the releavnt line...
|
||||
new_lines = [substitutions_for_letter(letter, number, line) for line in new_lines]
|
||||
|
||||
# ... and emit the gadget.
|
||||
permutation_id = "_arg".join(str(number) for number in permutation)
|
||||
simple(f"{name}_arg{permutation_id}", *new_lines)
|
||||
|
||||
|
||||
def with_dnm(name, *lines):
|
||||
""" Generates a collection of gadgets with substitutions for Xd, Xn, and Xm, and equivalents. """
|
||||
with_register_substitutions(name, ("d", "n", "m"), *lines)
|
||||
|
||||
# Print out an array that contains all of our gadgets, for lookup.
|
||||
print(f"static void* gadget_{name}[{TCG_REGISTER_COUNT}][{TCG_REGISTER_COUNT}][{TCG_REGISTER_COUNT}] = ", end="")
|
||||
print("{")
|
||||
|
||||
# D array
|
||||
for d in TCG_REGISTER_NUMBERS:
|
||||
print("\t{")
|
||||
|
||||
# N array
|
||||
for n in TCG_REGISTER_NUMBERS:
|
||||
print("\t\t{", end="")
|
||||
|
||||
# M array
|
||||
for m in TCG_REGISTER_NUMBERS:
|
||||
print(f"gadget_{name}_arg{d}_arg{n}_arg{m}", end=", ")
|
||||
|
||||
print("},")
|
||||
print("\t},")
|
||||
print("};")
|
||||
|
||||
|
||||
def with_dn_immediate(name, *lines, immediate_range):
|
||||
""" Generates a collection of gadgets with substitutions for Xd, Xn, and Xm, and equivalents. """
|
||||
with_register_substitutions(name, ["d", "n"], *lines, immediate_range=immediate_range)
|
||||
|
||||
# Print out an array that contains all of our gadgets, for lookup.
|
||||
print(f"static void* gadget_{name}[{TCG_REGISTER_COUNT}][{TCG_REGISTER_COUNT}][{len(immediate_range)}] = ", end="")
|
||||
print("{")
|
||||
|
||||
# D array
|
||||
for d in TCG_REGISTER_NUMBERS:
|
||||
print("\t{")
|
||||
|
||||
# N array
|
||||
for n in TCG_REGISTER_NUMBERS:
|
||||
print("\t\t{", end="")
|
||||
|
||||
# M array
|
||||
for i in immediate_range:
|
||||
print(f"gadget_{name}_arg{d}_arg{n}_arg{i}", end=", ")
|
||||
|
||||
print("},")
|
||||
print("\t},")
|
||||
print("};")
|
||||
|
||||
|
||||
def with_pair(name, substitutions, *lines):
|
||||
""" Generates a collection of gadgets with two subtstitutions."""
|
||||
with_register_substitutions(name, substitutions, *lines)
|
||||
|
||||
# Print out an array that contains all of our gadgets, for lookup.
|
||||
print(f"static void* gadget_{name}[{TCG_REGISTER_COUNT}][{TCG_REGISTER_COUNT}] = ", end="")
|
||||
print("{")
|
||||
|
||||
# N array
|
||||
for a in TCG_REGISTER_NUMBERS:
|
||||
print("\t\t{", end="")
|
||||
|
||||
# M array
|
||||
for b in TCG_REGISTER_NUMBERS:
|
||||
print(f"gadget_{name}_arg{a}_arg{b}", end=", ")
|
||||
|
||||
print("},")
|
||||
print("};")
|
||||
|
||||
|
||||
def math_dnm(name, mnemonic):
|
||||
""" Equivalent to `with_dnm`, but creates a _i32 and _i64 variant. For simple math. """
|
||||
with_dnm(f'{name}_i32', f"{mnemonic} Wd, Wn, Wm")
|
||||
with_dnm(f'{name}_i64', f"{mnemonic} Xd, Xn, Xm")
|
||||
|
||||
def math_dn(name, mnemonic):
|
||||
""" Equivalent to `with_dn`, but creates a _i32 and _i64 variant. For simple math. """
|
||||
with_dn(f'{name}_i32', f"{mnemonic} Wd, Wn")
|
||||
with_dn(f'{name}_i64', f"{mnemonic} Xd, Xn")
|
||||
|
||||
|
||||
def with_nm(name, *lines):
|
||||
""" Generates a collection of gadgets with substitutions for Xn, and Xm, and equivalents. """
|
||||
with_pair(name, ('n', 'm',), *lines)
|
||||
|
||||
|
||||
def with_dn(name, *lines):
|
||||
""" Generates a collection of gadgets with substitutions for Xd, and Xn, and equivalents. """
|
||||
with_pair(name, ('d', 'n',), *lines)
|
||||
|
||||
|
||||
def ldst_dn(name, *lines):
|
||||
""" Generates a collection of gadgets with substitutions for Xd, and Xn, and equivalents.
|
||||
|
||||
This variant is optimized for loads and stores, and optimizes common offset cases.
|
||||
"""
|
||||
|
||||
#
|
||||
# Simple case: create our gadgets.
|
||||
#
|
||||
with_dn(name, "ldr x27, [x28], #8", *lines)
|
||||
|
||||
#
|
||||
# Optimization case: create variants of our gadgets with our offsets replaced with common immediates.
|
||||
#
|
||||
immediate_lines_pos = [line.replace("x27", "#Ii") for line in lines]
|
||||
with_dn_immediate(f"{name}_imm", *immediate_lines_pos, immediate_range=range(64))
|
||||
|
||||
immediate_lines_aligned = [line.replace("x27", "#(Ii << 3)") for line in lines]
|
||||
with_dn_immediate(f"{name}_sh8_imm", *immediate_lines_aligned, immediate_range=range(64))
|
||||
|
||||
immediate_lines_neg = [line.replace("x27", "#-Ii") for line in lines]
|
||||
with_dn_immediate(f"{name}_neg_imm", *immediate_lines_neg, immediate_range=range(64))
|
||||
|
||||
|
||||
def with_single(name, substitution, *lines):
|
||||
""" Generates a collection of gadgets with two subtstitutions."""
|
||||
with_register_substitutions(name, (substitution,), *lines)
|
||||
|
||||
# Print out an array that contains all of our gadgets, for lookup.
|
||||
print(f"static void* gadget_{name}[{TCG_REGISTER_COUNT}] = ", end="")
|
||||
print("{")
|
||||
|
||||
for n in TCG_REGISTER_NUMBERS:
|
||||
print(f"gadget_{name}_arg{n}", end=", ")
|
||||
|
||||
print("};")
|
||||
|
||||
|
||||
def with_d_immediate(name, *lines, immediate_range=range(0)):
|
||||
""" Generates a collection of gadgets with two subtstitutions."""
|
||||
with_register_substitutions(name, ['d'], *lines, immediate_range=immediate_range)
|
||||
|
||||
# Print out an array that contains all of our gadgets, for lookup.
|
||||
print(f"static void* gadget_{name}[{TCG_REGISTER_COUNT}][{len(immediate_range)}] = ", end="")
|
||||
print("{")
|
||||
|
||||
# D array
|
||||
for a in TCG_REGISTER_NUMBERS:
|
||||
print("\t\t{", end="")
|
||||
|
||||
# I array
|
||||
for b in immediate_range:
|
||||
print(f"gadget_{name}_arg{a}_arg{b}", end=", ")
|
||||
|
||||
print("},")
|
||||
print("};")
|
||||
|
||||
|
||||
|
||||
def with_d(name, *lines):
|
||||
""" Generates a collection of gadgets with substitutions for Xd. """
|
||||
with_single(name, 'd', *lines)
|
||||
|
||||
|
||||
# Assembly code for saving our machine state before entering the C runtime.
|
||||
C_CALL_PROLOGUE = [
|
||||
# Store our machine state.
|
||||
"str x25, [sp, #-16]!",
|
||||
"stp x14, x15, [sp, #-16]!",
|
||||
"stp x12, x13, [sp, #-16]!",
|
||||
"stp x10, x11, [sp, #-16]!",
|
||||
"stp x8, x9, [sp, #-16]!",
|
||||
"stp x6, x7, [sp, #-16]!",
|
||||
"stp x4, x5, [sp, #-16]!",
|
||||
"stp x2, x3, [sp, #-16]!",
|
||||
"stp x0, x1, [sp, #-16]!",
|
||||
"stp x28, lr, [sp, #-16]!",
|
||||
]
|
||||
|
||||
# Assembly code for restoring our machine state after leaving the C runtime.
|
||||
C_CALL_EPILOGUE = [
|
||||
"ldp x28, lr, [sp], #16",
|
||||
"ldp x0, x1, [sp], #16",
|
||||
"ldp x2, x3, [sp], #16",
|
||||
"ldp x4, x5, [sp], #16",
|
||||
"ldp x6, x7, [sp], #16",
|
||||
"ldp x8, x9, [sp], #16",
|
||||
"ldp x10, x11, [sp], #16",
|
||||
"ldp x12, x13, [sp], #16",
|
||||
"ldp x14, x15, [sp], #16",
|
||||
"ldr x25, [sp], #16",
|
||||
]
|
||||
|
||||
|
||||
def create_tlb_fastpath(is_aligned, is_write, offset, miss_label="0"):
|
||||
""" Creates a set of instructions that perform a soft-MMU TLB lookup.
|
||||
|
||||
This is used for `qemu_ld`/qemu_st` instructions; to emit a prologue that
|
||||
hopefully helps us skip a slow call into the C runtime when a Guest Virtual
|
||||
-> Host Virtual mapping is in the softmmu's TLB.
|
||||
|
||||
This "fast-path" prelude behaves as follows:
|
||||
- If a TLB entry is found for the address stored in Xn, then x27
|
||||
is stored to an "addend" that can be added to the guest virtual addres
|
||||
to get the host virtual address (the address in our local memory space).
|
||||
- If a TLB entry isn't found, it branches to the "miss_label" (by default, 0:),
|
||||
so address lookup can be handled by the fastpath.
|
||||
|
||||
Clobbers x24, and x26; provides output in x27.
|
||||
"""
|
||||
|
||||
fast_path = [
|
||||
# Load env_tlb(env)->f[mmu_idx].{mask,table} into {x26,x27}.
|
||||
f"ldp x26, x27, [x14, #-{offset}]",
|
||||
|
||||
# Extract the TLB index from the address into X26.
|
||||
"and x26, x26, Xn, lsr #7", # Xn = addr regsiter
|
||||
|
||||
# Add the tlb_table pointer, creating the CPUTLBEntry address into X27.
|
||||
"add x27, x27, x26",
|
||||
|
||||
# Load the tlb comparator into X26, and the fast path addend into X27.
|
||||
"ldr x26, [x27, #8]" if is_write else "ldr x26, [x27]",
|
||||
"ldr x27, [x27, #0x18]",
|
||||
|
||||
]
|
||||
|
||||
if is_aligned:
|
||||
fast_path.extend([
|
||||
# Store the page mask part of the address into X24.
|
||||
"and x24, Xn, #0xfffffffffffff000",
|
||||
|
||||
# Compare the masked address with the TLB value.
|
||||
"cmp x26, x24",
|
||||
|
||||
# If we're not equal, this isn't a TLB hit. Jump to our miss handler.
|
||||
f"b.ne {miss_label}f",
|
||||
])
|
||||
else:
|
||||
fast_path.extend([
|
||||
# If we're not aligned, add in our alignment value to ensure we don't
|
||||
# don't straddle the end of a page.
|
||||
"add x24, Xn, #7",
|
||||
|
||||
# Store the page mask part of the address into X24.
|
||||
"and x24, x24, #0xfffffffffffff000",
|
||||
|
||||
# Compare the masked address with the TLB value.
|
||||
"cmp x26, x24",
|
||||
|
||||
# If we're not equal, this isn't a TLB hit. Jump to our miss handler.
|
||||
f"b.ne {miss_label}f",
|
||||
])
|
||||
|
||||
return fast_path
|
||||
|
||||
|
||||
|
||||
def ld_thunk(name, fastpath_32b, fastpath_64b, slowpath_helper, immediate=None, is_aligned=False, force_slowpath=False):
|
||||
""" Creates a thunk into our C runtime for a QEMU ST operation. """
|
||||
|
||||
# Use only offset 0 (no real offset) if we're forcing slowpath;
|
||||
# otherwise, use all of our allowed MMU offsets.
|
||||
offsets = [0] if force_slowpath else QEMU_ALLOWED_MMU_OFFSETS
|
||||
for offset in offsets:
|
||||
for is_32b in (True, False):
|
||||
fastpath = fastpath_32b if is_32b else fastpath_64b
|
||||
|
||||
gadget_name = f"{name}_off{offset}_i32" if is_32b else f"{name}_off{offset}_i64"
|
||||
postscript = () if immediate else ("add x28, x28, #8",)
|
||||
|
||||
# If we have a pure-assembly fast path, start our gadget with it.
|
||||
if fastpath and not force_slowpath:
|
||||
fastpath_ops = [
|
||||
# Create a fastpath that jumps to miss_lable on a TLB miss,
|
||||
# or sets x27 to the TLB addend on a TLB hit.
|
||||
*create_tlb_fastpath(is_aligned=is_aligned, is_write=False, offset=offset),
|
||||
|
||||
# On a hit, we can just perform an appropriate load...
|
||||
*fastpath,
|
||||
|
||||
# Run our patch-up post-script, if we have one.
|
||||
*postscript,
|
||||
|
||||
# ... and then we're done!
|
||||
*EPILOGUE,
|
||||
]
|
||||
# Otherwise, we'll save arguments for our slow path.
|
||||
else:
|
||||
fastpath_ops = []
|
||||
|
||||
#
|
||||
# If we're not taking our fast path, we'll call into our C runtime to take the slow path.
|
||||
#
|
||||
with_dn(gadget_name,
|
||||
*fastpath_ops,
|
||||
|
||||
"0:",
|
||||
"mov x27, Xn",
|
||||
|
||||
# Save our registers in preparation for entering a C call.
|
||||
*C_CALL_PROLOGUE,
|
||||
|
||||
# Per our calling convention:
|
||||
# - Move our architectural environment into x0, from x14.
|
||||
# - Move our target address into x1. [Placed in x27 below.]
|
||||
# - Move our operation info into x2, from an immediate32.
|
||||
# - Move the next bytecode pointer into x3, from x28.
|
||||
"mov x0, x14",
|
||||
"mov x1, x27",
|
||||
f"mov x2, #{immediate}" if (immediate is not None) else "ldr x2, [x28], #8",
|
||||
"mov x3, x28",
|
||||
|
||||
# Perform our actual core code.
|
||||
f"bl _{slowpath_helper}",
|
||||
|
||||
# Temporarily store our result in a register that won't get trashed.
|
||||
"mov x27, x0",
|
||||
|
||||
# Restore our registers after our C call.
|
||||
*C_CALL_EPILOGUE,
|
||||
|
||||
# Finally, call our postscript...
|
||||
*postscript,
|
||||
|
||||
# ... and place our results in the target register.
|
||||
"mov Wd, w27" if is_32b else "mov Xd, x27"
|
||||
)
|
||||
|
||||
|
||||
def st_thunk(name, fastpath_32b, fastpath_64b, slowpath_helper, immediate=None, is_aligned=False, force_slowpath=False):
|
||||
""" Creates a thunk into our C runtime for a QEMU ST operation. """
|
||||
|
||||
# Use only offset 0 (no real offset) if we're forcing slowpath;
|
||||
# otherwise, use all of our allowed MMU offsets.
|
||||
offsets = [0] if force_slowpath else QEMU_ALLOWED_MMU_OFFSETS
|
||||
for offset in offsets:
|
||||
|
||||
for is_32b in (True, False):
|
||||
fastpath = fastpath_32b if is_32b else fastpath_64b
|
||||
|
||||
gadget_name = f"{name}_off{offset}_i32" if is_32b else f"{name}_off{offset}_i64"
|
||||
postscript = () if immediate else ("add x28, x28, #8",)
|
||||
|
||||
# If we have a pure-assembly fast path, start our gadget with it.
|
||||
if fastpath and not force_slowpath:
|
||||
fastpath_ops = [
|
||||
|
||||
# Create a fastpath that jumps to miss_lable on a TLB miss,
|
||||
# or sets x27 to the TLB addend on a TLB hit.
|
||||
*create_tlb_fastpath(is_aligned=is_aligned, is_write=True, offset=offset),
|
||||
|
||||
# On a hit, we can just perform an appropriate load...
|
||||
*fastpath,
|
||||
|
||||
# Run our patch-up post-script, if we have one.
|
||||
*postscript,
|
||||
|
||||
# ... and then we're done!
|
||||
*EPILOGUE,
|
||||
]
|
||||
else:
|
||||
fastpath_ops = []
|
||||
|
||||
|
||||
#
|
||||
# If we're not taking our fast path, we'll call into our C runtime to take the slow path.
|
||||
#
|
||||
with_dn(gadget_name,
|
||||
*fastpath_ops,
|
||||
|
||||
"0:",
|
||||
# Move our arguments into registers that we're not actively using.
|
||||
# This ensures that they won't be trounced by our calling convention
|
||||
# if this is reading values from x0-x4.
|
||||
"mov w27, Wd" if is_32b else "mov x27, Xd",
|
||||
"mov x26, Xn",
|
||||
|
||||
# Save our registers in preparation for entering a C call.
|
||||
*C_CALL_PROLOGUE,
|
||||
|
||||
# Per our calling convention:
|
||||
# - Move our architectural environment into x0, from x14.
|
||||
# - Move our target address into x1. [Moved into x26 above].
|
||||
# - Move our target value into x2. [Moved into x27 above].
|
||||
# - Move our operation info into x3, from an immediate32.
|
||||
# - Move the next bytecode pointer into x4, from x28.
|
||||
"mov x0, x14",
|
||||
"mov x1, x26",
|
||||
"mov x2, x27",
|
||||
f"mov x3, #{immediate}" if (immediate is not None) else "ldr x3, [x28], #8",
|
||||
"mov x4, x28",
|
||||
|
||||
# Perform our actual core code.
|
||||
f"bl _{slowpath_helper}",
|
||||
|
||||
# Restore our registers after our C call.
|
||||
*C_CALL_EPILOGUE,
|
||||
|
||||
# Finally, call our postscript.
|
||||
*postscript
|
||||
)
|
||||
|
||||
|
||||
#
|
||||
# Gadget definitions.
|
||||
#
|
||||
|
||||
print("/* Automatically generated by tcti-gadget-gen.py. Do not edit. */\n")
|
||||
|
||||
# Call a C language helper function by address.
|
||||
simple("call",
|
||||
# Get our C runtime function's location as a pointer-sized immediate...
|
||||
"ldr x27, [x28], #8",
|
||||
|
||||
# Store our TB return address for our helper.
|
||||
"str x28, [x25]",
|
||||
|
||||
# Prepare ourselves to call into our C runtime...
|
||||
*C_CALL_PROLOGUE,
|
||||
|
||||
# ... perform the call itself ...
|
||||
"blr x27",
|
||||
|
||||
# Save the result of our call for later.
|
||||
"mov x27, x0",
|
||||
|
||||
# ... and restore our environment.
|
||||
*C_CALL_EPILOGUE,
|
||||
|
||||
# Restore our return value.
|
||||
"mov x0, x27"
|
||||
)
|
||||
|
||||
# Branch to a given immediate address.
|
||||
simple("br",
|
||||
# Use our immediate argument as our new bytecode-pointer location.
|
||||
"ldr x28, [x28]"
|
||||
)
|
||||
|
||||
# Exit from a translation buffer execution.
|
||||
simple("exit_tb",
|
||||
|
||||
# We have a single immediate argument, which contains our return code.
|
||||
# Place it into x0, as one would a return code.
|
||||
"ldr x0, [x28], #8",
|
||||
|
||||
# And finally, return back to the code that invoked our gadget stream.
|
||||
"ret"
|
||||
)
|
||||
|
||||
|
||||
for condition in ARCH_CONDITION_CODES:
|
||||
|
||||
# Performs a comparison between two operands.
|
||||
with_dnm(f"setcond_i32_{condition}",
|
||||
"subs Wd, Wn, Wm",
|
||||
f"cset Wd, {condition}"
|
||||
)
|
||||
with_dnm(f"setcond_i64_{condition}",
|
||||
"subs Xd, Xn, Xm",
|
||||
f"cset Xd, {condition}"
|
||||
)
|
||||
|
||||
#
|
||||
# NOTE: we use _dnm for the conditional branches, even though we don't
|
||||
# actually do anything different based on the d argument. This gemerates
|
||||
# effectively 16 identical `brcond` gadgets for each condition; which we
|
||||
# use in the backend to spread out the actual branch sources we use.
|
||||
#
|
||||
# This is a slight mercy for the branch predictor, as not every conditional
|
||||
# branch is funneled throught the same address.
|
||||
#
|
||||
|
||||
# Branches iff a given comparison is true.
|
||||
with_dnm(f'brcond_i32_{condition}',
|
||||
|
||||
# Grab our immediate argument.
|
||||
"ldr x27, [x28], #8",
|
||||
|
||||
# Perform our comparison and conditional branch.
|
||||
"subs Wzr, Wn, Wm",
|
||||
f"b{condition} 1f",
|
||||
|
||||
"0:", # not taken
|
||||
# Perform our end-of-instruction epilogue.
|
||||
*EPILOGUE,
|
||||
|
||||
"1:" # taken
|
||||
# Update our bytecode pointer to take the label.
|
||||
"mov x28, x27"
|
||||
)
|
||||
|
||||
# Branches iff a given comparison is true.
|
||||
with_dnm(f'brcond_i64_{condition}',
|
||||
|
||||
# Grab our immediate argument.
|
||||
"ldr x27, [x28], #8",
|
||||
|
||||
# Perform our comparison and conditional branch.
|
||||
"subs Xzr, Xn, Xm",
|
||||
f"b{condition} 1f",
|
||||
|
||||
"0:", # not taken
|
||||
# Perform our end-of-instruction epilogue.
|
||||
*EPILOGUE,
|
||||
|
||||
"1:" # taken
|
||||
# Update our bytecode pointer to take the label.
|
||||
"mov x28, x27"
|
||||
)
|
||||
|
||||
|
||||
# MOV variants.
|
||||
with_dn("mov_i32", "mov Wd, Wn")
|
||||
with_dn("mov_i64", "mov Xd, Xn")
|
||||
with_d("movi_i32", "ldr Wd, [x28], #8")
|
||||
with_d("movi_i64", "ldr Xd, [x28], #8")
|
||||
|
||||
# Create MOV variants that have common constants built in to the gadget.
|
||||
# This optimization helps costly reads from memories for simple operations.
|
||||
with_d_immediate("movi_imm_i32", "mov Wd, #Ii", immediate_range=range(64))
|
||||
with_d_immediate("movi_imm_i64", "mov Xd, #Ii", immediate_range=range(64))
|
||||
|
||||
# LOAD variants.
|
||||
# TODO: should the signed variants have X variants for _i64?
|
||||
ldst_dn("ld8u", "ldrb Wd, [Xn, x27]")
|
||||
ldst_dn("ld8s_i32", "ldrsb Wd, [Xn, x27]")
|
||||
ldst_dn("ld8s_i64", "ldrsb Xd, [Xn, x27]")
|
||||
ldst_dn("ld16u", "ldrh Wd, [Xn, x27]")
|
||||
ldst_dn("ld16s_i32", "ldrsh Wd, [Xn, x27]")
|
||||
ldst_dn("ld16s_i64", "ldrsh Xd, [Xn, x27]")
|
||||
ldst_dn("ld32u", "ldr Wd, [Xn, x27]")
|
||||
ldst_dn("ld32s_i64", "ldrsw Xd, [Xn, x27]")
|
||||
ldst_dn("ld_i64", "ldr Xd, [Xn, x27]")
|
||||
|
||||
# STORE variants.
|
||||
ldst_dn("st8", "strb Wd, [Xn, x27]")
|
||||
ldst_dn("st16", "strh Wd, [Xn, x27]")
|
||||
ldst_dn("st_i32", "str Wd, [Xn, x27]")
|
||||
ldst_dn("st_i64", "str Xd, [Xn, x27]")
|
||||
|
||||
# QEMU LD/ST are handled in our C runtime rather than with simple gadgets,
|
||||
# as they're nontrivial.
|
||||
|
||||
# Trivial arithmetic.
|
||||
math_dnm("add" , "add" )
|
||||
math_dnm("sub" , "sub" )
|
||||
math_dnm("mul" , "mul" )
|
||||
math_dnm("div" , "sdiv")
|
||||
math_dnm("divu", "udiv")
|
||||
|
||||
# Division remainder
|
||||
with_dnm("rem_i32", "sdiv w27, Wn, Wm", "msub Wd, w27, Wm, Wn")
|
||||
with_dnm("rem_i64", "sdiv x27, Xn, Xm", "msub Xd, x27, Xm, Xn")
|
||||
with_dnm("remu_i32", "udiv w27, Wn, Wm", "msub Wd, w27, Wm, Wn")
|
||||
with_dnm("remu_i64", "udiv x27, Xn, Xm", "msub Xd, x27, Xm, Xn")
|
||||
|
||||
# Trivial logical.
|
||||
math_dn( "not", "mvn")
|
||||
math_dn( "neg", "neg")
|
||||
math_dnm("and", "and")
|
||||
math_dnm("andc", "bic")
|
||||
math_dnm("or", "orr")
|
||||
math_dnm("orc", "orn")
|
||||
math_dnm("xor", "eor")
|
||||
math_dnm("eqv", "eon")
|
||||
math_dnm("shl", "lsl")
|
||||
math_dnm("shr", "lsr")
|
||||
math_dnm("sar", "asr")
|
||||
|
||||
# AArch64 lacks a Rotate Left; so we instead rotate right by a negative.
|
||||
# TODO: validate this?
|
||||
#math_dnm("rotr", "ror")
|
||||
#with_dnm("rotl_i32", "neg w27, Wm", "ror Wd, Wn, w27")
|
||||
#with_dnm("rotl_i64", "neg x27, Xm", "ror Xd, Xn, x27")
|
||||
|
||||
# Numeric extension.
|
||||
math_dn("ext8s", "sxtb")
|
||||
with_dn("ext8u", "and Xd, Xn, #0xff")
|
||||
math_dn("ext16s", "sxth")
|
||||
with_dn("ext16u", "and Wd, Wn, #0xffff")
|
||||
with_dn("ext32s_i64", "sxtw Xd, Wn")
|
||||
with_dn("ext32u_i64", "and Xd, Xn, #0xffffffff")
|
||||
|
||||
# Byte swapping.
|
||||
with_dn("bswap16", "rev w27, Wn", "lsr Wd, w27, #16")
|
||||
with_dn("bswap32", "rev Wd, Wn")
|
||||
with_dn("bswap64", "rev Xd, Xn")
|
||||
|
||||
# Memory barriers.
|
||||
simple("mb_all", "dmb ish")
|
||||
simple("mb_st", "dmb ishst")
|
||||
simple("mb_ld", "dmb ishld")
|
||||
|
||||
# Handlers for QEMU_LD, which handles guest <- host loads.
|
||||
for subtype in ('aligned', 'unaligned', 'slowpath'):
|
||||
is_aligned = (subtype == 'aligned')
|
||||
is_slowpath = (subtype == 'slowpath')
|
||||
|
||||
ld_thunk(f"qemu_ld_ub_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_ret_ldub_mmu",
|
||||
fastpath_32b=["ldrb Wd, [Xn, x27]"], fastpath_64b=["ldrb Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_sb_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_ret_ldub_mmu_signed",
|
||||
fastpath_32b=["ldrsb Wd, [Xn, x27]"], fastpath_64b=["ldrsb Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_leuw_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_lduw_mmu",
|
||||
fastpath_32b=["ldrh Wd, [Xn, x27]"], fastpath_64b=["ldrh Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_lesw_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_lduw_mmu_signed",
|
||||
fastpath_32b=["ldrsh Wd, [Xn, x27]"], fastpath_64b=["ldrsh Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_leul_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_ldul_mmu",
|
||||
fastpath_32b=["ldr Wd, [Xn, x27]"], fastpath_64b=["ldr Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_lesl_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_ldul_mmu_signed",
|
||||
fastpath_32b=["ldrsw Xd, [Xn, x27]"], fastpath_64b=["ldrsw Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
ld_thunk(f"qemu_ld_leq_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_ldq_mmu",
|
||||
fastpath_32b=["ldr Xd, [Xn, x27]"], fastpath_64b=["ldr Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
|
||||
# Special variant for the most common mode, as a speedup optimization.
|
||||
ld_thunk(f"qemu_ld_leq_{subtype}_mode3a", is_aligned=is_aligned, slowpath_helper="helper_le_ldq_mmu",
|
||||
fastpath_32b=["ldr Xd, [Xn, x27]"], fastpath_64b=["ldr Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath, immediate=0x3a
|
||||
)
|
||||
|
||||
# For now, leave the rare/big-endian stuff slow-path only.
|
||||
ld_thunk(f"qemu_ld_beuw_{subtype}", None, None, "helper_be_lduw_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
ld_thunk(f"qemu_ld_besw_{subtype}", None, None, "helper_be_lduw_mmu_signed",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
ld_thunk(f"qemu_ld_beul_{subtype}", None, None, "helper_be_ldul_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
ld_thunk(f"qemu_ld_besl_{subtype}", None, None, "helper_be_ldul_mmu_signed",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
ld_thunk(f"qemu_ld_beq_{subtype}", None, None, "helper_be_ldq_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
|
||||
|
||||
# Handlers for QEMU_ST, which handles guest -> host stores.
|
||||
for subtype in ('aligned', 'unaligned', 'slowpath'):
|
||||
is_aligned = (subtype == 'aligned')
|
||||
is_slowpath = (subtype == 'slowpath')
|
||||
|
||||
st_thunk(f"qemu_st_ub_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_ret_stb_mmu",
|
||||
fastpath_32b=["strb Wd, [Xn, x27]"], fastpath_64b=["strb Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
st_thunk(f"qemu_st_leuw_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_stw_mmu",
|
||||
fastpath_32b=["strh Wd, [Xn, x27]"], fastpath_64b=["strh Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
st_thunk(f"qemu_st_leul_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_stl_mmu",
|
||||
fastpath_32b=["str Wd, [Xn, x27]"], fastpath_64b=["str Wd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
st_thunk(f"qemu_st_leq_{subtype}", is_aligned=is_aligned, slowpath_helper="helper_le_stq_mmu",
|
||||
fastpath_32b=["str Xd, [Xn, x27]"], fastpath_64b=["str Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath,
|
||||
)
|
||||
|
||||
# Special optimization for the most common modes.
|
||||
st_thunk(f"qemu_st_leq_{subtype}_mode3a", is_aligned=is_aligned, slowpath_helper="helper_le_stq_mmu",
|
||||
fastpath_32b=["str Xd, [Xn, x27]"], fastpath_64b=["str Xd, [Xn, x27]"],
|
||||
force_slowpath=is_slowpath, immediate=0x3a
|
||||
)
|
||||
|
||||
# For now, leave the rare/big-endian stuff slow-path only.
|
||||
st_thunk(f"qemu_st_beuw_{subtype}", None, None, "helper_be_stw_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
st_thunk(f"qemu_st_beul_{subtype}", None, None, "helper_be_stl_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
st_thunk(f"qemu_st_beq_{subtype}", None, None, "helper_be_stq_mmu",
|
||||
is_aligned=is_aligned, force_slowpath=is_slowpath)
|
||||
|
||||
|
||||
# Statistics.
|
||||
sys.stderr.write(f"\nGenerated {gadgets} gadgets with {instructions} instructions ({instructions * 4} B).\n\n")
|
||||
+7
-4
@@ -611,7 +611,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"
|
||||
|
||||
@@ -735,7 +735,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
|
||||
@@ -775,7 +775,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;
|
||||
@@ -881,7 +884,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;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,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
|
||||
|
||||
@@ -725,7 +726,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
|
||||
|
||||
@@ -747,7 +748,7 @@ void tcg_prologue_init(TCGContext *s)
|
||||
|
||||
prologue_size = tcg_current_code_size(s);
|
||||
|
||||
#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
|
||||
@@ -783,7 +784,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,
|
||||
@@ -1174,13 +1175,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;
|
||||
|
||||
@@ -1468,7 +1475,7 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args)
|
||||
#endif
|
||||
|
||||
#if defined(__sparc__) && !defined(__arch64__) \
|
||||
&& !defined(CONFIG_TCG_INTERPRETER)
|
||||
&& !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
/* We have 64-bit values in one register, but need to pass as two
|
||||
separate parameters. Split them. */
|
||||
int orig_typemask = typemask;
|
||||
@@ -1523,7 +1530,7 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args)
|
||||
pi = 0;
|
||||
if (ret != NULL) {
|
||||
#if defined(__sparc__) && !defined(__arch64__) \
|
||||
&& !defined(CONFIG_TCG_INTERPRETER)
|
||||
&& !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
if ((typemask & 6) == dh_typecode_i64) {
|
||||
/* The 32-bit ABI is going to return the 64-bit value in
|
||||
the %o0/%o1 register pair. Prepare for this by using
|
||||
@@ -1615,7 +1622,7 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args)
|
||||
tcg_debug_assert(pi <= ARRAY_SIZE(op->args));
|
||||
|
||||
#if defined(__sparc__) && !defined(__arch64__) \
|
||||
&& !defined(CONFIG_TCG_INTERPRETER)
|
||||
&& !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
|
||||
/* Free all of the parts we allocated above. */
|
||||
for (i = real_args = 0; i < orig_nargs; ++i) {
|
||||
int argtype = extract32(orig_typemask, (i + 1) * 3, 3);
|
||||
@@ -4371,7 +4378,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
|
||||
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,
|
||||
|
||||
-2063
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,676 @@
|
||||
/*
|
||||
* QEMU Cocoa CG display driver
|
||||
*
|
||||
* Copyright (c) 2008 Mike Kronenberg
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "qemu-common.h"
|
||||
#include "ui/cocoa.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "sysemu/runstate.h"
|
||||
#include "sysemu/cpu-throttle.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qapi-commands-block.h"
|
||||
#include "qapi/qapi-commands-machine.h"
|
||||
#include "qapi/qapi-commands-misc.h"
|
||||
#include "sysemu/blockdev.h"
|
||||
#include "qemu-version.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/module.h"
|
||||
#include "hw/core/cpu.h"
|
||||
|
||||
#ifndef MAC_OS_X_VERSION_10_13
|
||||
#define MAC_OS_X_VERSION_10_13 101300
|
||||
#endif
|
||||
|
||||
/* 10.14 deprecates NSOnState and NSOffState in favor of
|
||||
* NSControlStateValueOn/Off, which were introduced in 10.13.
|
||||
* Define for older versions
|
||||
*/
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_13
|
||||
#define NSControlStateValueOn NSOnState
|
||||
#define NSControlStateValueOff NSOffState
|
||||
#endif
|
||||
|
||||
// Utility function to run specified code block with iothread lock held
|
||||
static void with_iothread_lock(CodeBlock block)
|
||||
{
|
||||
bool locked = qemu_mutex_iothread_locked();
|
||||
if (!locked) {
|
||||
qemu_mutex_lock_iothread();
|
||||
}
|
||||
block();
|
||||
if (!locked) {
|
||||
qemu_mutex_unlock_iothread();
|
||||
}
|
||||
}
|
||||
|
||||
/* Displays an alert dialog box with the specified message */
|
||||
static void QEMU_Alert(NSString *message)
|
||||
{
|
||||
NSAlert *alert;
|
||||
alert = [NSAlert new];
|
||||
[alert setMessageText: message];
|
||||
[alert runModal];
|
||||
}
|
||||
|
||||
/* Handles any errors that happen with a device transaction */
|
||||
static void handleAnyDeviceErrors(Error * err)
|
||||
{
|
||||
if (err) {
|
||||
QEMU_Alert([NSString stringWithCString: error_get_pretty(err)
|
||||
encoding: NSASCIIStringEncoding]);
|
||||
error_free(err);
|
||||
}
|
||||
}
|
||||
|
||||
static void create_initial_menus(void)
|
||||
{
|
||||
// Add menus
|
||||
NSMenu *menu;
|
||||
NSMenuItem *menuItem;
|
||||
|
||||
[NSApp setMainMenu:[[NSMenu alloc] init]];
|
||||
|
||||
// Application menu
|
||||
menu = [[NSMenu alloc] initWithTitle:@""];
|
||||
[menu addItemWithTitle:@"About QEMU" action:@selector(do_about_menu_item:) keyEquivalent:@""]; // About QEMU
|
||||
[menu addItem:[NSMenuItem separatorItem]]; //Separator
|
||||
[menu addItemWithTitle:@"Hide QEMU" action:@selector(hide:) keyEquivalent:@"h"]; //Hide QEMU
|
||||
menuItem = (NSMenuItem *)[menu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; // Hide Others
|
||||
[menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)];
|
||||
[menu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; // Show All
|
||||
[menu addItem:[NSMenuItem separatorItem]]; //Separator
|
||||
[menu addItemWithTitle:@"Quit QEMU" action:@selector(terminate:) keyEquivalent:@"q"];
|
||||
menuItem = [[NSMenuItem alloc] initWithTitle:@"Apple" action:nil keyEquivalent:@""];
|
||||
[menuItem setSubmenu:menu];
|
||||
[[NSApp mainMenu] addItem:menuItem];
|
||||
[NSApp performSelector:@selector(setAppleMenu:) withObject:menu]; // Workaround (this method is private since 10.4+)
|
||||
|
||||
// Machine menu
|
||||
menu = [[NSMenu alloc] initWithTitle: @"Machine"];
|
||||
[menu setAutoenablesItems: NO];
|
||||
[menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Pause" action: @selector(pauseQEMU:) keyEquivalent: @""] autorelease]];
|
||||
menuItem = [[[NSMenuItem alloc] initWithTitle: @"Resume" action: @selector(resumeQEMU:) keyEquivalent: @""] autorelease];
|
||||
[menu addItem: menuItem];
|
||||
[menuItem setEnabled: NO];
|
||||
[menu addItem: [NSMenuItem separatorItem]];
|
||||
[menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Reset" action: @selector(restartQEMU:) keyEquivalent: @""] autorelease]];
|
||||
[menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Power Down" action: @selector(powerDownQEMU:) keyEquivalent: @""] autorelease]];
|
||||
menuItem = [[[NSMenuItem alloc] initWithTitle: @"Machine" action:nil keyEquivalent:@""] autorelease];
|
||||
[menuItem setSubmenu:menu];
|
||||
[[NSApp mainMenu] addItem:menuItem];
|
||||
|
||||
// View menu
|
||||
menu = [[NSMenu alloc] initWithTitle:@"View"];
|
||||
[menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(doToggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen
|
||||
[menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Zoom To Fit" action:@selector(zoomToFit:) keyEquivalent:@""] autorelease]];
|
||||
menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease];
|
||||
[menuItem setSubmenu:menu];
|
||||
[[NSApp mainMenu] addItem:menuItem];
|
||||
|
||||
// Speed menu
|
||||
menu = [[NSMenu alloc] initWithTitle:@"Speed"];
|
||||
|
||||
// Add the rest of the Speed menu items
|
||||
int p, percentage, throttle_pct;
|
||||
for (p = 10; p >= 0; p--)
|
||||
{
|
||||
percentage = p * 10 > 1 ? p * 10 : 1; // prevent a 0% menu item
|
||||
|
||||
menuItem = [[[NSMenuItem alloc]
|
||||
initWithTitle: [NSString stringWithFormat: @"%d%%", percentage] action:@selector(adjustSpeed:) keyEquivalent:@""] autorelease];
|
||||
|
||||
if (percentage == 100) {
|
||||
[menuItem setState: NSControlStateValueOn];
|
||||
}
|
||||
|
||||
/* Calculate the throttle percentage */
|
||||
throttle_pct = -1 * percentage + 100;
|
||||
|
||||
[menuItem setTag: throttle_pct];
|
||||
[menu addItem: menuItem];
|
||||
}
|
||||
menuItem = [[[NSMenuItem alloc] initWithTitle:@"Speed" action:nil keyEquivalent:@""] autorelease];
|
||||
[menuItem setSubmenu:menu];
|
||||
[[NSApp mainMenu] addItem:menuItem];
|
||||
|
||||
// Window menu
|
||||
menu = [[NSMenu alloc] initWithTitle:@"Window"];
|
||||
[menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; // Miniaturize
|
||||
menuItem = [[[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""] autorelease];
|
||||
[menuItem setSubmenu:menu];
|
||||
[[NSApp mainMenu] addItem:menuItem];
|
||||
[NSApp setWindowsMenu:menu];
|
||||
|
||||
// Help menu
|
||||
menu = [[NSMenu alloc] initWithTitle:@"Help"];
|
||||
[menu addItem: [[[NSMenuItem alloc] initWithTitle:@"QEMU Documentation" action:@selector(showQEMUDoc:) keyEquivalent:@"?"] autorelease]]; // QEMU Help
|
||||
menuItem = [[[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""] autorelease];
|
||||
[menuItem setSubmenu:menu];
|
||||
[[NSApp mainMenu] addItem:menuItem];
|
||||
}
|
||||
|
||||
/* Returns a name for a given console */
|
||||
static NSString * getConsoleName(QemuConsole * console)
|
||||
{
|
||||
return [NSString stringWithFormat: @"%s", qemu_console_get_label(console)];
|
||||
}
|
||||
|
||||
/* Add an entry to the View menu for each console */
|
||||
static void add_console_menu_entries(void)
|
||||
{
|
||||
NSMenu *menu;
|
||||
NSMenuItem *menuItem;
|
||||
int index = 0;
|
||||
|
||||
menu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu];
|
||||
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
while (qemu_console_lookup_by_index(index) != NULL) {
|
||||
menuItem = [[[NSMenuItem alloc] initWithTitle: getConsoleName(qemu_console_lookup_by_index(index))
|
||||
action: @selector(displayConsole:) keyEquivalent: @""] autorelease];
|
||||
[menuItem setTag: index];
|
||||
[menu addItem: menuItem];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Make menu items for all removable devices.
|
||||
* Each device is given an 'Eject' and 'Change' menu item.
|
||||
*/
|
||||
static void addRemovableDevicesMenuItems(void)
|
||||
{
|
||||
NSMenu *menu;
|
||||
NSMenuItem *menuItem;
|
||||
BlockInfoList *currentDevice, *pointerToFree;
|
||||
NSString *deviceName;
|
||||
|
||||
currentDevice = qmp_query_block(NULL);
|
||||
pointerToFree = currentDevice;
|
||||
if(currentDevice == NULL) {
|
||||
NSBeep();
|
||||
QEMU_Alert(@"Failed to query for block devices!");
|
||||
return;
|
||||
}
|
||||
|
||||
menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];
|
||||
|
||||
// Add a separator between related groups of menu items
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
// Set the attributes to the "Removable Media" menu item
|
||||
NSString *titleString = @"Removable Media";
|
||||
NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:titleString];
|
||||
NSColor *newColor = [NSColor blackColor];
|
||||
NSFontManager *fontManager = [NSFontManager sharedFontManager];
|
||||
NSFont *font = [fontManager fontWithFamily:@"Helvetica"
|
||||
traits:NSBoldFontMask|NSItalicFontMask
|
||||
weight:0
|
||||
size:14];
|
||||
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, [titleString length])];
|
||||
[attString addAttribute:NSForegroundColorAttributeName value:newColor range:NSMakeRange(0, [titleString length])];
|
||||
[attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt: 1] range:NSMakeRange(0, [titleString length])];
|
||||
|
||||
// Add the "Removable Media" menu item
|
||||
menuItem = [NSMenuItem new];
|
||||
[menuItem setAttributedTitle: attString];
|
||||
[menuItem setEnabled: NO];
|
||||
[menu addItem: menuItem];
|
||||
|
||||
/* Loop through all the block devices in the emulator */
|
||||
while (currentDevice) {
|
||||
deviceName = [[NSString stringWithFormat: @"%s", currentDevice->value->device] retain];
|
||||
|
||||
if(currentDevice->value->removable) {
|
||||
menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Change %s...", currentDevice->value->device]
|
||||
action: @selector(changeDeviceMedia:)
|
||||
keyEquivalent: @""];
|
||||
[menu addItem: menuItem];
|
||||
[menuItem setRepresentedObject: deviceName];
|
||||
[menuItem autorelease];
|
||||
|
||||
menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Eject %s", currentDevice->value->device]
|
||||
action: @selector(ejectDeviceMedia:)
|
||||
keyEquivalent: @""];
|
||||
[menu addItem: menuItem];
|
||||
[menuItem setRepresentedObject: deviceName];
|
||||
[menuItem autorelease];
|
||||
}
|
||||
currentDevice = currentDevice->next;
|
||||
}
|
||||
qapi_free_BlockInfoList(pointerToFree);
|
||||
}
|
||||
|
||||
@implementation QemuCocoaAppController
|
||||
- (id) initWithStartedSem:(QemuSemaphore *)given_started_sem
|
||||
screen:(QEMUScreen *)screen
|
||||
{
|
||||
COCOA_DEBUG("%s\n", __func__);
|
||||
|
||||
self = [super init];
|
||||
if (self) {
|
||||
|
||||
started_sem = given_started_sem;
|
||||
|
||||
create_initial_menus();
|
||||
|
||||
/*
|
||||
* Create the menu entries which depend on QEMU state (for consoles
|
||||
* and removeable devices). These make calls back into QEMU functions,
|
||||
* which is OK because at this point we know that the second thread
|
||||
* holds the iothread lock and is synchronously waiting for us to
|
||||
* finish.
|
||||
*/
|
||||
add_console_menu_entries();
|
||||
addRemovableDevicesMenuItems();
|
||||
|
||||
// create a view and add it to the window
|
||||
cocoaView = [[QemuCocoaView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 640.0, 480.0)
|
||||
screen:screen];
|
||||
if(!cocoaView) {
|
||||
error_report("(cocoa) can't create a view");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// create a window
|
||||
NSWindow *normalWindow = [[NSWindow alloc] initWithContentRect:[cocoaView frame]
|
||||
styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskClosable
|
||||
backing:NSBackingStoreBuffered defer:NO];
|
||||
if(!normalWindow) {
|
||||
error_report("(cocoa) can't create window");
|
||||
exit(1);
|
||||
}
|
||||
[normalWindow setAcceptsMouseMovedEvents:YES];
|
||||
[normalWindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
||||
[normalWindow setTitle:qemu_name ? [NSString stringWithFormat:@"QEMU %s", qemu_name] : @"QEMU"];
|
||||
[normalWindow setContentView:cocoaView];
|
||||
[normalWindow makeKeyAndOrderFront:self];
|
||||
[normalWindow center];
|
||||
[normalWindow setDelegate: self];
|
||||
[normalWindow release];
|
||||
|
||||
// set the supported image file types that can be opened
|
||||
supportedImageFileTypes = [NSArray arrayWithObjects: @"img", @"iso", @"dmg",
|
||||
@"qcow", @"qcow2", @"cloop", @"vmdk", @"cdr",
|
||||
@"toast", nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaAppController: dealloc\n");
|
||||
|
||||
if (cocoaView)
|
||||
[cocoaView release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching: (NSNotification *) note
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaAppController: applicationDidFinishLaunching\n");
|
||||
/* Tell cocoa_display_init to proceed */
|
||||
qemu_sem_post(started_sem);
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)aNotification
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaAppController: applicationWillTerminate\n");
|
||||
|
||||
qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI);
|
||||
|
||||
/*
|
||||
* Sleep here, because returning will cause OSX to kill us
|
||||
* immediately; the QEMU main loop will handle the shutdown
|
||||
* request and terminate the process.
|
||||
*/
|
||||
[NSThread sleepForTimeInterval:INFINITY];
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:
|
||||
(NSApplication *)sender
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaAppController: applicationShouldTerminate\n");
|
||||
return [self verifyQuit];
|
||||
}
|
||||
|
||||
- (void)windowDidChangeScreen:(NSNotification *)notification
|
||||
{
|
||||
[cocoaView updateUIInfo];
|
||||
}
|
||||
|
||||
- (void)windowDidEnterFullScreen:(NSNotification *)notification
|
||||
{
|
||||
[cocoaView grabMouse];
|
||||
}
|
||||
|
||||
- (void)windowDidExitFullScreen:(NSNotification *)notification
|
||||
{
|
||||
[cocoaView resizeWindow];
|
||||
[cocoaView ungrabMouse];
|
||||
}
|
||||
|
||||
- (void)windowDidResize:(NSNotification *)notification
|
||||
{
|
||||
[cocoaView frameUpdated];
|
||||
}
|
||||
|
||||
- (void)windowDidResignKey:(NSNotification *)notification
|
||||
{
|
||||
[cocoaView ungrabMouse];
|
||||
}
|
||||
|
||||
- (void)windowDidBecomeKey:(NSNotification *)notification
|
||||
{
|
||||
/* If we became key and are fullscreen there is no point in waiting for
|
||||
* a click to grab the mouse.
|
||||
*/
|
||||
if (([[cocoaView window] styleMask] & NSWindowStyleMaskFullScreen) != 0) {
|
||||
[cocoaView grabMouse];
|
||||
}
|
||||
}
|
||||
|
||||
/* Called when the user clicks on a window's close button */
|
||||
- (BOOL)windowShouldClose:(id)sender
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaAppController: windowShouldClose\n");
|
||||
[NSApp terminate: sender];
|
||||
/* If the user allows the application to quit then the call to
|
||||
* NSApp terminate will never return. If we get here then the user
|
||||
* cancelled the quit, so we should return NO to not permit the
|
||||
* closing of this window.
|
||||
*/
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSSize) window:(NSWindow *)window willUseFullScreenContentSize:(NSSize)proposedSize
|
||||
{
|
||||
if (([[cocoaView window] styleMask] & NSWindowStyleMaskResizable) == 0) {
|
||||
return [cocoaView computeUnzoomedSize];
|
||||
}
|
||||
|
||||
return [cocoaView fixZoomedFullScreenSize:proposedSize];
|
||||
}
|
||||
|
||||
- (NSApplicationPresentationOptions) window:(NSWindow *)window
|
||||
willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions;
|
||||
|
||||
{
|
||||
return (proposedOptions & ~(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)) |
|
||||
NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
|
||||
}
|
||||
|
||||
/* We abstract the method called by the Enter Fullscreen menu item
|
||||
* because Mac OS 10.7 and higher disables it. This is because of the
|
||||
* menu item's old selector's name toggleFullScreen:
|
||||
*/
|
||||
- (void) doToggleFullScreen:(id)sender
|
||||
{
|
||||
[[cocoaView window] toggleFullScreen:sender];
|
||||
}
|
||||
|
||||
/* Tries to find then open the specified filename */
|
||||
- (void) openDocumentation: (NSString *) filename
|
||||
{
|
||||
/* Where to look for local files */
|
||||
NSString *path_array[] = {@"../share/doc/qemu/", @"../doc/qemu/", @"docs/"};
|
||||
NSString *full_file_path;
|
||||
NSURL *full_file_url;
|
||||
|
||||
/* iterate thru the possible paths until the file is found */
|
||||
int index;
|
||||
for (index = 0; index < ARRAY_SIZE(path_array); index++) {
|
||||
full_file_path = [[NSBundle mainBundle] executablePath];
|
||||
full_file_path = [full_file_path stringByDeletingLastPathComponent];
|
||||
full_file_path = [NSString stringWithFormat: @"%@/%@%@", full_file_path,
|
||||
path_array[index], filename];
|
||||
full_file_url = [NSURL fileURLWithPath: full_file_path
|
||||
isDirectory: false];
|
||||
if ([[NSWorkspace sharedWorkspace] openURL: full_file_url] == YES) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* If none of the paths opened a file */
|
||||
NSBeep();
|
||||
QEMU_Alert(@"Failed to open file");
|
||||
}
|
||||
|
||||
- (void)showQEMUDoc:(id)sender
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaAppController: showQEMUDoc\n");
|
||||
|
||||
[self openDocumentation: @"index.html"];
|
||||
}
|
||||
|
||||
/* Toggles the flag which stretches video to fit host window size */
|
||||
- (void)zoomToFit:(id) sender
|
||||
{
|
||||
if (([[cocoaView window] styleMask] & NSWindowStyleMaskResizable) == 0) {
|
||||
[[cocoaView window] setStyleMask:[[cocoaView window] styleMask] | NSWindowStyleMaskResizable];
|
||||
[sender setState: NSControlStateValueOn];
|
||||
} else {
|
||||
[[cocoaView window] setStyleMask:[[cocoaView window] styleMask] & ~NSWindowStyleMaskResizable];
|
||||
[cocoaView resizeWindow];
|
||||
[sender setState: NSControlStateValueOff];
|
||||
}
|
||||
}
|
||||
|
||||
/* Displays the console on the screen */
|
||||
- (void)displayConsole:(id)sender
|
||||
{
|
||||
with_iothread_lock(^{
|
||||
console_select([sender tag]);
|
||||
});
|
||||
}
|
||||
|
||||
/* Pause the guest */
|
||||
- (void)pauseQEMU:(id)sender
|
||||
{
|
||||
with_iothread_lock(^{
|
||||
qmp_stop(NULL);
|
||||
});
|
||||
[sender setEnabled: NO];
|
||||
[[[sender menu] itemWithTitle: @"Resume"] setEnabled: YES];
|
||||
[cocoaView displayPause];
|
||||
}
|
||||
|
||||
/* Resume running the guest operating system */
|
||||
- (void)resumeQEMU:(id) sender
|
||||
{
|
||||
with_iothread_lock(^{
|
||||
qmp_cont(NULL);
|
||||
});
|
||||
[sender setEnabled: NO];
|
||||
[[[sender menu] itemWithTitle: @"Pause"] setEnabled: YES];
|
||||
[cocoaView removePause];
|
||||
}
|
||||
|
||||
/* Restarts QEMU */
|
||||
- (void)restartQEMU:(id)sender
|
||||
{
|
||||
with_iothread_lock(^{
|
||||
qmp_system_reset(NULL);
|
||||
});
|
||||
}
|
||||
|
||||
/* Powers down QEMU */
|
||||
- (void)powerDownQEMU:(id)sender
|
||||
{
|
||||
with_iothread_lock(^{
|
||||
qmp_system_powerdown(NULL);
|
||||
});
|
||||
}
|
||||
|
||||
/* Ejects the media.
|
||||
* Uses sender's tag to figure out the device to eject.
|
||||
*/
|
||||
- (void)ejectDeviceMedia:(id)sender
|
||||
{
|
||||
NSString * drive;
|
||||
drive = [sender representedObject];
|
||||
if(drive == nil) {
|
||||
NSBeep();
|
||||
QEMU_Alert(@"Failed to find drive to eject!");
|
||||
return;
|
||||
}
|
||||
|
||||
__block Error *err = NULL;
|
||||
with_iothread_lock(^{
|
||||
qmp_eject(true, [drive cStringUsingEncoding: NSASCIIStringEncoding],
|
||||
false, NULL, false, false, &err);
|
||||
});
|
||||
handleAnyDeviceErrors(err);
|
||||
}
|
||||
|
||||
/* Displays a dialog box asking the user to select an image file to load.
|
||||
* Uses sender's represented object value to figure out which drive to use.
|
||||
*/
|
||||
- (void)changeDeviceMedia:(id)sender
|
||||
{
|
||||
/* Find the drive name */
|
||||
NSString * drive;
|
||||
drive = [sender representedObject];
|
||||
if(drive == nil) {
|
||||
NSBeep();
|
||||
QEMU_Alert(@"Could not find drive!");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Display the file open dialog */
|
||||
NSOpenPanel * openPanel;
|
||||
openPanel = [NSOpenPanel openPanel];
|
||||
[openPanel setCanChooseFiles: YES];
|
||||
[openPanel setAllowsMultipleSelection: NO];
|
||||
[openPanel setAllowedFileTypes: supportedImageFileTypes];
|
||||
if([openPanel runModal] == NSModalResponseOK) {
|
||||
NSString * file = [[[openPanel URLs] objectAtIndex: 0] path];
|
||||
if(file == nil) {
|
||||
NSBeep();
|
||||
QEMU_Alert(@"Failed to convert URL to file path!");
|
||||
return;
|
||||
}
|
||||
|
||||
__block Error *err = NULL;
|
||||
with_iothread_lock(^{
|
||||
qmp_blockdev_change_medium(true,
|
||||
[drive cStringUsingEncoding:
|
||||
NSASCIIStringEncoding],
|
||||
false, NULL,
|
||||
[file cStringUsingEncoding:
|
||||
NSASCIIStringEncoding],
|
||||
true, "raw",
|
||||
false, 0,
|
||||
&err);
|
||||
});
|
||||
handleAnyDeviceErrors(err);
|
||||
}
|
||||
}
|
||||
|
||||
/* Verifies if the user really wants to quit */
|
||||
- (BOOL)verifyQuit
|
||||
{
|
||||
NSAlert *alert = [NSAlert new];
|
||||
[alert autorelease];
|
||||
[alert setMessageText: @"Are you sure you want to quit QEMU?"];
|
||||
[alert addButtonWithTitle: @"Cancel"];
|
||||
[alert addButtonWithTitle: @"Quit"];
|
||||
if([alert runModal] == NSAlertSecondButtonReturn) {
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
/* The action method for the About menu item */
|
||||
- (IBAction) do_about_menu_item: (id) sender
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
char *icon_path_c = get_relocated_path(CONFIG_QEMU_ICONDIR "/hicolor/512x512/apps/qemu.png");
|
||||
NSString *icon_path = [NSString stringWithUTF8String:icon_path_c];
|
||||
g_free(icon_path_c);
|
||||
NSImage *icon = [[NSImage alloc] initWithContentsOfFile:icon_path];
|
||||
NSString *version = @"QEMU emulator version " QEMU_FULL_VERSION;
|
||||
NSString *copyright = @QEMU_COPYRIGHT;
|
||||
NSDictionary *options;
|
||||
if (icon) {
|
||||
options = @{
|
||||
NSAboutPanelOptionApplicationIcon : icon,
|
||||
NSAboutPanelOptionApplicationVersion : version,
|
||||
@"Copyright" : copyright,
|
||||
};
|
||||
[icon release];
|
||||
} else {
|
||||
options = @{
|
||||
NSAboutPanelOptionApplicationVersion : version,
|
||||
@"Copyright" : copyright,
|
||||
};
|
||||
}
|
||||
[NSApp orderFrontStandardAboutPanelWithOptions:options];
|
||||
[pool release];
|
||||
}
|
||||
|
||||
/* Used by the Speed menu items */
|
||||
- (void)adjustSpeed:(id)sender
|
||||
{
|
||||
int throttle_pct; /* throttle percentage */
|
||||
NSMenu *menu;
|
||||
|
||||
menu = [sender menu];
|
||||
if (menu != nil)
|
||||
{
|
||||
/* Unselect the currently selected item */
|
||||
for (NSMenuItem *item in [menu itemArray]) {
|
||||
if (item.state == NSControlStateValueOn) {
|
||||
[item setState: NSControlStateValueOff];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check the menu item
|
||||
[sender setState: NSControlStateValueOn];
|
||||
|
||||
// get the throttle percentage
|
||||
throttle_pct = [sender tag];
|
||||
|
||||
with_iothread_lock(^{
|
||||
cpu_throttle_set(throttle_pct);
|
||||
});
|
||||
COCOA_DEBUG("cpu throttling at %d%c\n", cpu_throttle_get_percentage(), '%');
|
||||
}
|
||||
|
||||
- (QemuCocoaView *)cocoaView
|
||||
{
|
||||
return cocoaView;
|
||||
}
|
||||
|
||||
@end
|
||||
+852
@@ -0,0 +1,852 @@
|
||||
/*
|
||||
* QEMU Cocoa CG display driver
|
||||
*
|
||||
* Copyright (c) 2008 Mike Kronenberg
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include <crt_externs.h>
|
||||
|
||||
#include "qemu-common.h"
|
||||
#include "ui/cocoa.h"
|
||||
#include "ui/input.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
|
||||
#ifdef CONFIG_EGL
|
||||
#include "ui/egl-context.h"
|
||||
#endif
|
||||
|
||||
static QEMUScreen screen;
|
||||
static QemuCocoaAppController *appController;
|
||||
|
||||
static int gArgc;
|
||||
static char **gArgv;
|
||||
|
||||
static QemuSemaphore display_init_sem;
|
||||
static QemuSemaphore app_started_sem;
|
||||
|
||||
static NSInteger cbchangecount = -1;
|
||||
static QemuCocoaClipboard qemucb;
|
||||
static QemuCocoaPasteboardTypeOwner *cbowner;
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
|
||||
typedef struct {
|
||||
uint32_t scanout_id;
|
||||
DisplayGLTextureBorrower scanout_borrow;
|
||||
bool surface_dirty;
|
||||
} DisplayGL;
|
||||
|
||||
static DisplayGL *dgs;
|
||||
static QEMUGLContext view_ctx;
|
||||
static QemuGLShader *gls;
|
||||
static GLuint cursor_texture;
|
||||
static int cursor_texture_width;
|
||||
static int cursor_texture_height;
|
||||
|
||||
#ifdef CONFIG_EGL
|
||||
static EGLSurface egl_surface;
|
||||
#endif
|
||||
|
||||
static void cocoa_gl_destroy_context(void *dg, QEMUGLContext ctx);
|
||||
|
||||
#endif
|
||||
|
||||
@interface QemuApplication : NSApplication
|
||||
@end
|
||||
|
||||
@implementation QemuApplication
|
||||
- (void)sendEvent:(NSEvent *)event
|
||||
{
|
||||
COCOA_DEBUG("QemuApplication: sendEvent\n");
|
||||
if (![[appController cocoaView] handleEvent:event]) {
|
||||
[super sendEvent: event];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
static void cocoa_clipboard_notify(Notifier *notifier, void *data);
|
||||
static void cocoa_clipboard_request(QemuClipboardInfo *info,
|
||||
QemuClipboardType type);
|
||||
|
||||
static QemuClipboardPeer cbpeer = {
|
||||
.name = "cocoa",
|
||||
.update = { .notify = cocoa_clipboard_notify },
|
||||
.request = cocoa_clipboard_request
|
||||
};
|
||||
|
||||
static void cocoa_clipboard_notify(Notifier *notifier, void *data)
|
||||
{
|
||||
QemuClipboardInfo *info = data;
|
||||
|
||||
if (info->owner == &cbpeer || info->selection != QEMU_CLIPBOARD_SELECTION_CLIPBOARD) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (info != qemucb.info) {
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
qemu_clipboard_info_unref(qemucb.info);
|
||||
qemucb.info = qemu_clipboard_info_ref(info);
|
||||
cbchangecount = [[NSPasteboard generalPasteboard] declareTypes:@[NSPasteboardTypeString] owner:cbowner];
|
||||
[pool release];
|
||||
}
|
||||
|
||||
qemu_event_set(&qemucb.event);
|
||||
}
|
||||
|
||||
static void cocoa_clipboard_request(QemuClipboardInfo *info,
|
||||
QemuClipboardType type)
|
||||
{
|
||||
NSData *text;
|
||||
|
||||
switch (type) {
|
||||
case QEMU_CLIPBOARD_TYPE_TEXT:
|
||||
text = [[NSPasteboard generalPasteboard] dataForType:NSPasteboardTypeString];
|
||||
if (text) {
|
||||
qemu_clipboard_set_data(&cbpeer, info, type,
|
||||
[text length], [text bytes], true);
|
||||
[text release];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The startup process for the OSX/Cocoa UI is complicated, because
|
||||
* OSX insists that the UI runs on the initial main thread, and so we
|
||||
* need to start a second thread which runs the vl.c qemu_main():
|
||||
*
|
||||
* Initial thread: 2nd thread:
|
||||
* in main():
|
||||
* create qemu-main thread
|
||||
* wait on display_init semaphore
|
||||
* call qemu_main()
|
||||
* ...
|
||||
* in cocoa_display_init():
|
||||
* post the display_init semaphore
|
||||
* wait on app_started semaphore
|
||||
* create application, menus, etc
|
||||
* enter OSX run loop
|
||||
* in applicationDidFinishLaunching:
|
||||
* post app_started semaphore
|
||||
* tell main thread to fullscreen if needed
|
||||
* [...]
|
||||
* run qemu main-loop
|
||||
*
|
||||
* We do this in two stages so that we don't do the creation of the
|
||||
* GUI application menus and so on for command line options like --help
|
||||
* where we want to just print text to stdout and exit immediately.
|
||||
*/
|
||||
|
||||
static void *call_qemu_main(void *opaque)
|
||||
{
|
||||
int status;
|
||||
|
||||
COCOA_DEBUG("Second thread: calling qemu_main()\n");
|
||||
status = qemu_main(gArgc, gArgv, *_NSGetEnviron());
|
||||
COCOA_DEBUG("Second thread: qemu_main() returned, exiting\n");
|
||||
[cbowner release];
|
||||
CGImageRelease(screen.cursor_cgimage);
|
||||
#ifdef CONFIG_OPENGL
|
||||
g_free(dgs);
|
||||
qemu_gl_fini_shader(gls);
|
||||
if (view_ctx) {
|
||||
cocoa_gl_destroy_context(NULL, view_ctx);
|
||||
}
|
||||
if (appController) {
|
||||
[appController release];
|
||||
}
|
||||
#endif
|
||||
exit(status);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
QemuThread thread;
|
||||
|
||||
COCOA_DEBUG("Entered main()\n");
|
||||
gArgc = argc;
|
||||
gArgv = argv;
|
||||
|
||||
qemu_sem_init(&display_init_sem, 0);
|
||||
qemu_sem_init(&app_started_sem, 0);
|
||||
|
||||
qemu_thread_create(&thread, "qemu_main", call_qemu_main,
|
||||
NULL, QEMU_THREAD_DETACHED);
|
||||
|
||||
qemu_mutex_init(&screen.draw_mutex);
|
||||
|
||||
COCOA_DEBUG("Main thread: waiting for display_init_sem\n");
|
||||
qemu_sem_wait(&display_init_sem);
|
||||
COCOA_DEBUG("Main thread: initializing app\n");
|
||||
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// Pull this console process up to being a fully-fledged graphical
|
||||
// app with a menubar and Dock icon
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
|
||||
[QemuApplication sharedApplication];
|
||||
|
||||
// Create an Application controller
|
||||
appController = [[QemuCocoaAppController alloc] initWithStartedSem:&app_started_sem
|
||||
screen:&screen];
|
||||
[NSApp setDelegate:appController];
|
||||
|
||||
// Start the main event loop
|
||||
COCOA_DEBUG("Main thread: entering OSX run loop\n");
|
||||
[NSApp run];
|
||||
COCOA_DEBUG("Main thread: left OSX run loop, exiting\n");
|
||||
|
||||
[pool release];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#pragma mark qemu
|
||||
static void cocoa_update(DisplayChangeListener *dcl,
|
||||
int x, int y, int w, int h)
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
DisplaySurface *updated = screen.surface;
|
||||
|
||||
COCOA_DEBUG("qemu_cocoa: cocoa_update\n");
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
qemu_mutex_lock(&screen.draw_mutex);
|
||||
if (updated != screen.surface) {
|
||||
qemu_mutex_unlock(&screen.draw_mutex);
|
||||
return;
|
||||
}
|
||||
int full_height = surface_height(screen.surface);
|
||||
qemu_mutex_unlock(&screen.draw_mutex);
|
||||
|
||||
CGFloat d = [[appController cocoaView] frame].size.height / full_height;
|
||||
NSRect rect = NSMakeRect(x * d, (full_height - y - h) * d, w * d, h * d);
|
||||
[[appController cocoaView] setNeedsDisplayInRect:rect];
|
||||
});
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
static void cocoa_switch(DisplayChangeListener *dcl,
|
||||
DisplaySurface *new_surface)
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
static bool updating_screen;
|
||||
|
||||
COCOA_DEBUG("qemu_cocoa: cocoa_switch\n");
|
||||
|
||||
[[appController cocoaView] updateUIInfo];
|
||||
|
||||
qemu_mutex_lock(&screen.draw_mutex);
|
||||
screen.surface = new_surface;
|
||||
if (!updating_screen) {
|
||||
updating_screen = true;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
qemu_mutex_lock(&screen.draw_mutex);
|
||||
updating_screen = false;
|
||||
int w = surface_width(screen.surface);
|
||||
int h = surface_height(screen.surface);
|
||||
qemu_mutex_unlock(&screen.draw_mutex);
|
||||
|
||||
[[appController cocoaView] updateScreenWidth:w height:h];
|
||||
});
|
||||
}
|
||||
qemu_mutex_unlock(&screen.draw_mutex);
|
||||
[pool release];
|
||||
}
|
||||
|
||||
static void cocoa_refresh(DisplayChangeListener *dcl)
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
COCOA_DEBUG("qemu_cocoa: cocoa_refresh\n");
|
||||
graphic_hw_update(NULL);
|
||||
|
||||
if (qemu_input_is_absolute()) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (![[appController cocoaView] isAbsoluteEnabled]) {
|
||||
if ([[appController cocoaView] isMouseGrabbed]) {
|
||||
[[appController cocoaView] ungrabMouse];
|
||||
}
|
||||
}
|
||||
[[appController cocoaView] setAbsoluteEnabled:YES];
|
||||
});
|
||||
}
|
||||
|
||||
if (cbchangecount != [[NSPasteboard generalPasteboard] changeCount]) {
|
||||
qemu_clipboard_info_unref(qemucb.info);
|
||||
qemucb.info = qemu_clipboard_info_new(&cbpeer, QEMU_CLIPBOARD_SELECTION_CLIPBOARD);
|
||||
if ([[NSPasteboard generalPasteboard] availableTypeFromArray:@[NSPasteboardTypeString]]) {
|
||||
qemucb.info->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true;
|
||||
}
|
||||
qemu_clipboard_update(qemucb.info);
|
||||
cbchangecount = [[NSPasteboard generalPasteboard] changeCount];
|
||||
qemu_event_set(&qemucb.event);
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
static void cocoa_mouse_set(DisplayChangeListener *dcl, int x, int y, int on)
|
||||
{
|
||||
qemu_mutex_lock(&screen.draw_mutex);
|
||||
int full_height = surface_height(screen.surface);
|
||||
size_t cursor_width = CGImageGetWidth(screen.cursor_cgimage);
|
||||
size_t cursor_height = CGImageGetHeight(screen.cursor_cgimage);
|
||||
int old_x = screen.mouse_x;
|
||||
int old_y = screen.mouse_y;
|
||||
int old_on = screen.mouse_on;
|
||||
screen.mouse_x = x;
|
||||
screen.mouse_y = y;
|
||||
screen.mouse_on = on;
|
||||
qemu_mutex_unlock(&screen.draw_mutex);
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (old_on) {
|
||||
[[appController cocoaView] setNeedsDisplayForCursorX:old_x
|
||||
y:old_y
|
||||
width:cursor_width
|
||||
height:cursor_height
|
||||
screenHeight:full_height];
|
||||
}
|
||||
|
||||
if (on) {
|
||||
[[appController cocoaView] setNeedsDisplayForCursorX:x
|
||||
y:y
|
||||
width:cursor_width
|
||||
height:cursor_height
|
||||
screenHeight:full_height];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void cocoa_cursor_define(DisplayChangeListener *dcl, QEMUCursor *cursor)
|
||||
{
|
||||
int width = cursor->width;
|
||||
int height = cursor->height;
|
||||
|
||||
CGDataProviderRef dataProviderRef = CGDataProviderCreateWithData(
|
||||
NULL,
|
||||
cursor->data,
|
||||
width * height * 4,
|
||||
NULL
|
||||
);
|
||||
|
||||
CGImageRef imageRef = CGImageCreate(
|
||||
width, //width
|
||||
height, //height
|
||||
8, //bitsPerComponent
|
||||
32, //bitsPerPixel
|
||||
width * 4, //bytesPerRow
|
||||
CGColorSpaceCreateWithName(kCGColorSpaceSRGB), //colorspace
|
||||
kCGBitmapByteOrder32Little | kCGImageAlphaFirst, //bitmapInfo
|
||||
dataProviderRef, //provider
|
||||
NULL, //decode
|
||||
0, //interpolate
|
||||
kCGRenderingIntentDefault //intent
|
||||
);
|
||||
|
||||
qemu_mutex_lock(&screen.draw_mutex);
|
||||
int full_height = surface_height(screen.surface);
|
||||
int x = screen.mouse_x;
|
||||
int y = screen.mouse_y;
|
||||
int on = screen.mouse_on;
|
||||
size_t old_width;
|
||||
size_t old_height;
|
||||
if (screen.cursor_cgimage) {
|
||||
old_width = CGImageGetWidth(screen.cursor_cgimage);
|
||||
old_height = CGImageGetHeight(screen.cursor_cgimage);
|
||||
} else {
|
||||
old_width = 0;
|
||||
old_height = 0;
|
||||
}
|
||||
screen.cursor_cgimage = CGImageCreateCopy(imageRef);
|
||||
qemu_mutex_unlock(&screen.draw_mutex);
|
||||
|
||||
CGImageRelease(imageRef);
|
||||
CGDataProviderRelease(dataProviderRef);
|
||||
|
||||
if (on) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
CGFloat d = [[appController cocoaView] frame].size.height / full_height;
|
||||
NSRect rect;
|
||||
|
||||
rect.origin.x = d * x;
|
||||
rect.origin.y = d * (full_height - y - old_height);
|
||||
rect.size.width = d * old_width;
|
||||
rect.size.height = d * old_height;
|
||||
[[appController cocoaView] setNeedsDisplayInRect:rect];
|
||||
|
||||
rect.origin.x = d * x;
|
||||
rect.origin.y = d * (full_height - y - height);
|
||||
rect.size.width = d * width;
|
||||
rect.size.height = d * height;
|
||||
[[appController cocoaView] setNeedsDisplayInRect:rect];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static const DisplayChangeListenerOps dcl_ops = {
|
||||
.dpy_name = "cocoa",
|
||||
.dpy_gfx_update = cocoa_update,
|
||||
.dpy_gfx_switch = cocoa_switch,
|
||||
.dpy_refresh = cocoa_refresh,
|
||||
.dpy_mouse_set = cocoa_mouse_set,
|
||||
.dpy_cursor_define = cocoa_cursor_define,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
|
||||
static void with_view_ctx(CodeBlock block)
|
||||
{
|
||||
#ifdef CONFIG_EGL
|
||||
if (egl_surface) {
|
||||
eglMakeCurrent(qemu_egl_display, egl_surface, egl_surface, view_ctx);
|
||||
block();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[(NSOpenGLContext *)view_ctx lock];
|
||||
[(NSOpenGLContext *)view_ctx makeCurrentContext];
|
||||
block();
|
||||
[(NSOpenGLContext *)view_ctx unlock];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
static NSOpenGLContext *cocoa_gl_create_context_ns(NSOpenGLContext *share_context,
|
||||
int bpp)
|
||||
{
|
||||
NSOpenGLPixelFormatAttribute attributes[] = {
|
||||
NSOpenGLPFAOpenGLProfile,
|
||||
NSOpenGLProfileVersion4_1Core,
|
||||
NSOpenGLPFAColorSize,
|
||||
bpp,
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
0,
|
||||
};
|
||||
NSOpenGLPixelFormat *format;
|
||||
NSOpenGLContext *ctx;
|
||||
|
||||
format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||
ctx = [[NSOpenGLContext alloc] initWithFormat:format shareContext:share_context];
|
||||
[format release];
|
||||
|
||||
[ctx retain];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[ctx setView:[appController cocoaView]];
|
||||
[ctx release];
|
||||
});
|
||||
|
||||
return (QEMUGLContext)ctx;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
static int cocoa_gl_make_context_current(void *dg, QEMUGLContext ctx)
|
||||
{
|
||||
#ifdef CONFIG_EGL
|
||||
if (egl_surface) {
|
||||
EGLSurface surface = ctx == EGL_NO_CONTEXT ? EGL_NO_SURFACE : egl_surface;
|
||||
return eglMakeCurrent(qemu_egl_display, surface, surface, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (ctx) {
|
||||
[(NSOpenGLContext *)ctx makeCurrentContext];
|
||||
} else {
|
||||
[NSOpenGLContext clearCurrentContext];
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QEMUGLContext cocoa_gl_create_context(void *dg, QEMUGLParams *params)
|
||||
{
|
||||
#ifdef CONFIG_EGL
|
||||
if (egl_surface) {
|
||||
eglMakeCurrent(qemu_egl_display, egl_surface, egl_surface, view_ctx);
|
||||
return qemu_egl_create_context(dg, params);
|
||||
}
|
||||
#endif
|
||||
|
||||
int bpp = PIXMAN_FORMAT_BPP(surface_format(screen.surface));
|
||||
return cocoa_gl_create_context_ns(view_ctx, bpp);
|
||||
}
|
||||
|
||||
static void cocoa_gl_destroy_context(void *dg, QEMUGLContext ctx)
|
||||
{
|
||||
#ifdef CONFIG_EGL
|
||||
if (egl_surface) {
|
||||
eglDestroyContext(qemu_egl_display, ctx);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[(NSOpenGLContext *)ctx release];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
static void cocoa_gl_flush()
|
||||
{
|
||||
#ifdef CONFIG_EGL
|
||||
if (egl_surface) {
|
||||
eglSwapBuffers(qemu_egl_display, egl_surface);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[[NSOpenGLContext currentContext] flushBuffer];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[(NSOpenGLContext *)view_ctx update];
|
||||
});
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
static void cocoa_scanout_disable(DisplayGL *dg)
|
||||
{
|
||||
if (!dg->scanout_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
dg->scanout_id = 0;
|
||||
|
||||
if (screen.surface) {
|
||||
surface_gl_destroy_texture(gls, screen.surface);
|
||||
surface_gl_create_texture(gls, screen.surface);
|
||||
}
|
||||
}
|
||||
|
||||
static void cocoa_gl_render_cursor()
|
||||
{
|
||||
if (!screen.mouse_on) {
|
||||
return;
|
||||
}
|
||||
|
||||
QemuCocoaView *cocoaView = [appController cocoaView];
|
||||
NSSize size = [cocoaView convertSizeToBacking:[cocoaView frame].size];
|
||||
int full_height = surface_height(screen.surface);
|
||||
CGFloat d = size.height / full_height;
|
||||
|
||||
glViewport(
|
||||
d * screen.mouse_x,
|
||||
d * (full_height - screen.mouse_y - cursor_texture_height),
|
||||
d * cursor_texture_width,
|
||||
d * cursor_texture_height
|
||||
);
|
||||
glBindTexture(GL_TEXTURE_2D, cursor_texture);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
qemu_gl_run_texture_blit(gls, false);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
static void cocoa_gl_render_surface(DisplayGL *dg)
|
||||
{
|
||||
cocoa_scanout_disable(dg);
|
||||
|
||||
QemuCocoaView *cocoaView = [appController cocoaView];
|
||||
NSSize size = [cocoaView convertSizeToBacking:[cocoaView frame].size];
|
||||
|
||||
surface_gl_setup_viewport(gls, screen.surface, size.width, size.height);
|
||||
glBindTexture(GL_TEXTURE_2D, screen.surface->texture);
|
||||
surface_gl_render_texture(gls, screen.surface);
|
||||
|
||||
cocoa_gl_render_cursor();
|
||||
|
||||
cocoa_gl_flush();
|
||||
}
|
||||
|
||||
static void cocoa_gl_update(DisplayChangeListener *dcl,
|
||||
int x, int y, int w, int h)
|
||||
{
|
||||
with_view_ctx(^{
|
||||
surface_gl_update_texture(gls, screen.surface, x, y, w, h);
|
||||
dgs[qemu_console_get_index(dcl->con)].surface_dirty = true;
|
||||
});
|
||||
}
|
||||
|
||||
static void cocoa_gl_switch(DisplayChangeListener *dcl,
|
||||
DisplaySurface *new_surface)
|
||||
{
|
||||
cocoa_switch(dcl, new_surface);
|
||||
|
||||
with_view_ctx(^{
|
||||
surface_gl_create_texture(gls, new_surface);
|
||||
});
|
||||
}
|
||||
|
||||
static void cocoa_gl_refresh(DisplayChangeListener *dcl)
|
||||
{
|
||||
cocoa_refresh(dcl);
|
||||
|
||||
with_view_ctx(^{
|
||||
DisplayGL *dg = dgs + qemu_console_get_index(dcl->con);
|
||||
|
||||
if (dg->surface_dirty && screen.surface) {
|
||||
dg->surface_dirty = false;
|
||||
cocoa_gl_render_surface(dg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static bool cocoa_gl_scanout_get_enabled(void *dg)
|
||||
{
|
||||
return ((DisplayGL *)dg)->scanout_id != 0;
|
||||
}
|
||||
|
||||
static void cocoa_gl_scanout_disable(void *dg)
|
||||
{
|
||||
with_view_ctx(^{
|
||||
cocoa_scanout_disable((DisplayGL *)dg);
|
||||
});
|
||||
}
|
||||
|
||||
static void cocoa_gl_scanout_texture(void *dg,
|
||||
uint32_t backing_id,
|
||||
DisplayGLTextureBorrower backing_borrow,
|
||||
uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h)
|
||||
{
|
||||
((DisplayGL *)dg)->scanout_id = backing_id;
|
||||
((DisplayGL *)dg)->scanout_borrow = backing_borrow;
|
||||
}
|
||||
|
||||
static void cocoa_gl_scanout_flush(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h)
|
||||
{
|
||||
DisplayGL *dg = dgs + qemu_console_get_index(dcl->con);
|
||||
bool y0_top;
|
||||
|
||||
if (!dg->scanout_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
GLint texture = dg->scanout_borrow(dg->scanout_id, &y0_top, NULL, NULL);
|
||||
if (!texture) {
|
||||
return;
|
||||
}
|
||||
|
||||
with_view_ctx(^{
|
||||
QemuCocoaView *cocoaView = [appController cocoaView];
|
||||
NSSize size = [cocoaView convertSizeToBacking:[cocoaView frame].size];
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
|
||||
glViewport(0, 0, size.width, size.height);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
qemu_gl_run_texture_blit(gls, y0_top);
|
||||
|
||||
cocoa_gl_render_cursor();
|
||||
|
||||
cocoa_gl_flush();
|
||||
});
|
||||
}
|
||||
|
||||
static void cocoa_gl_mouse_set(DisplayChangeListener *dcl, int x, int y, int on)
|
||||
{
|
||||
screen.mouse_x = x;
|
||||
screen.mouse_y = y;
|
||||
screen.mouse_on = on;
|
||||
|
||||
DisplayGL *dg = dgs + qemu_console_get_index(dcl->con);
|
||||
|
||||
if (dg->scanout_id) {
|
||||
cocoa_gl_scanout_flush(dcl, 0, 0, 0, 0);
|
||||
} else {
|
||||
with_view_ctx(^{
|
||||
cocoa_gl_render_surface(dg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void cocoa_gl_cursor_define(DisplayChangeListener *dcl, QEMUCursor *cursor)
|
||||
{
|
||||
cursor_texture_width = cursor->width;
|
||||
cursor_texture_height = cursor->height;
|
||||
|
||||
with_view_ctx(^{
|
||||
glBindTexture(GL_TEXTURE_2D, cursor_texture);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, cursor->width);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,
|
||||
epoxy_is_desktop_gl() ? GL_RGBA : GL_BGRA,
|
||||
cursor->width,
|
||||
cursor->height,
|
||||
0, GL_BGRA, GL_UNSIGNED_BYTE,
|
||||
cursor->data);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
});
|
||||
}
|
||||
|
||||
static const DisplayGLOps dg_ops = {
|
||||
.dpy_gl_ctx_create = cocoa_gl_create_context,
|
||||
.dpy_gl_ctx_destroy = cocoa_gl_destroy_context,
|
||||
.dpy_gl_ctx_make_current = cocoa_gl_make_context_current,
|
||||
.dpy_gl_scanout_get_enabled = cocoa_gl_scanout_get_enabled,
|
||||
.dpy_gl_scanout_disable = cocoa_gl_scanout_disable,
|
||||
.dpy_gl_scanout_texture = cocoa_gl_scanout_texture,
|
||||
};
|
||||
|
||||
static const DisplayChangeListenerOps dcl_gl_ops = {
|
||||
.dpy_name = "cocoa-gl",
|
||||
.dpy_gfx_update = cocoa_gl_update,
|
||||
.dpy_gfx_switch = cocoa_gl_switch,
|
||||
.dpy_gfx_check_format = console_gl_check_format,
|
||||
.dpy_refresh = cocoa_gl_refresh,
|
||||
.dpy_mouse_set = cocoa_gl_mouse_set,
|
||||
.dpy_cursor_define = cocoa_gl_cursor_define,
|
||||
|
||||
.dpy_gl_update = cocoa_gl_scanout_flush,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
static void cocoa_display_early_init(DisplayOptions *o)
|
||||
{
|
||||
assert(o->type == DISPLAY_TYPE_COCOA);
|
||||
if (o->has_gl && o->gl) {
|
||||
display_opengl = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
|
||||
{
|
||||
COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");
|
||||
|
||||
screen.cursor_show = opts->has_show_cursor && opts->show_cursor;
|
||||
screen.swap_option_command = opts->u.cocoa.has_swap_option_command &&
|
||||
opts->u.cocoa.swap_option_command;
|
||||
|
||||
/* Tell main thread to go ahead and create the app and enter the run loop */
|
||||
qemu_sem_post(&display_init_sem);
|
||||
qemu_sem_wait(&app_started_sem);
|
||||
COCOA_DEBUG("cocoa_display_init: app start completed\n");
|
||||
|
||||
/* if fullscreen mode is to be used */
|
||||
if (opts->has_full_screen && opts->full_screen) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[[appController cocoaView] window] toggleFullScreen: nil];
|
||||
});
|
||||
}
|
||||
if (opts->u.cocoa.has_full_grab && opts->u.cocoa.full_grab) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[appController cocoaView] setFullGrab: nil];
|
||||
});
|
||||
}
|
||||
|
||||
if (display_opengl) {
|
||||
#ifdef CONFIG_OPENGL
|
||||
unsigned int console_count = 0;
|
||||
while (qemu_console_lookup_by_index(console_count)) {
|
||||
console_count++;
|
||||
}
|
||||
|
||||
dgs = g_new0(DisplayGL, console_count);
|
||||
|
||||
for (unsigned int index = 0; index < console_count; index++) {
|
||||
QemuConsole *con = qemu_console_lookup_by_index(index);
|
||||
console_set_displayglcontext(con, dgs + index);
|
||||
}
|
||||
|
||||
if (opts->gl == DISPLAYGL_MODE_ES) {
|
||||
#ifdef CONFIG_EGL
|
||||
if (qemu_egl_init_dpy_cocoa(DISPLAYGL_MODE_ES)) {
|
||||
exit(1);
|
||||
}
|
||||
view_ctx = qemu_egl_init_ctx();
|
||||
if (!view_ctx) {
|
||||
exit(1);
|
||||
}
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
CALayer *layer = [[appController cocoaView] layer];
|
||||
egl_surface = qemu_egl_init_surface(view_ctx, layer);
|
||||
});
|
||||
#else
|
||||
error_report("OpenGLES without EGL is not supported - exiting");
|
||||
exit(1);
|
||||
#endif
|
||||
} else {
|
||||
view_ctx = cocoa_gl_create_context_ns(nil, 32);
|
||||
#ifdef CONFIG_EGL
|
||||
egl_surface = EGL_NO_SURFACE;
|
||||
#endif
|
||||
cocoa_gl_make_context_current(NULL, view_ctx);
|
||||
}
|
||||
|
||||
gls = qemu_gl_init_shader();
|
||||
glGenTextures(1, &cursor_texture);
|
||||
|
||||
// register vga output callbacks
|
||||
screen.dcl.ops = &dcl_gl_ops;
|
||||
|
||||
register_displayglops(&dg_ops);
|
||||
#else
|
||||
error_report("OpenGL is not enabled - exiting");
|
||||
exit(1);
|
||||
#endif
|
||||
} else {
|
||||
// register vga output callbacks
|
||||
screen.dcl.ops = &dcl_ops;
|
||||
}
|
||||
|
||||
register_displaychangelistener(&screen.dcl);
|
||||
qatomic_store_release(&screen.inited, true);
|
||||
|
||||
qemu_event_init(&qemucb.event, false);
|
||||
cbowner = [[QemuCocoaPasteboardTypeOwner alloc] initWith:&qemucb];
|
||||
qemu_clipboard_peer_register(&cbpeer);
|
||||
}
|
||||
|
||||
static QemuDisplay qemu_display_cocoa = {
|
||||
.type = DISPLAY_TYPE_COCOA,
|
||||
.early_init = cocoa_display_early_init,
|
||||
.init = cocoa_display_init,
|
||||
};
|
||||
|
||||
static void register_cocoa(void)
|
||||
{
|
||||
qemu_display_register(&qemu_display_cocoa);
|
||||
}
|
||||
|
||||
type_init(register_cocoa);
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
module_dep("ui-opengl");
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* QEMU Cocoa CG display driver
|
||||
*
|
||||
* Copyright (c) 2008 Mike Kronenberg
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "ui/cocoa.h"
|
||||
#include "qemu/main-loop.h"
|
||||
|
||||
@implementation QemuCocoaPasteboardTypeOwner
|
||||
|
||||
- (id)initWith:(QemuCocoaClipboard *)aCb
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaView: initWithFrame\n");
|
||||
|
||||
self = [super init];
|
||||
if (self) {
|
||||
cb = aCb;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)pasteboard:(NSPasteboard *)sender provideDataForType:(NSPasteboardType)type
|
||||
{
|
||||
if (type != NSPasteboardTypeString) {
|
||||
return;
|
||||
}
|
||||
|
||||
qemu_mutex_lock_iothread();
|
||||
|
||||
QemuClipboardInfo *info = qemu_clipboard_info_ref(cb->info);
|
||||
qemu_event_reset(&cb->event);
|
||||
qemu_clipboard_request(info, QEMU_CLIPBOARD_TYPE_TEXT);
|
||||
|
||||
while (info == cb->info &&
|
||||
info->types[QEMU_CLIPBOARD_TYPE_TEXT].available &&
|
||||
info->types[QEMU_CLIPBOARD_TYPE_TEXT].data == NULL) {
|
||||
qemu_mutex_unlock_iothread();
|
||||
qemu_event_wait(&cb->event);
|
||||
qemu_mutex_lock_iothread();
|
||||
}
|
||||
|
||||
if (info == cb->info) {
|
||||
NSData *data = [[NSData alloc] initWithBytes:info->types[QEMU_CLIPBOARD_TYPE_TEXT].data
|
||||
length:info->types[QEMU_CLIPBOARD_TYPE_TEXT].size];
|
||||
[sender setData:data forType:NSPasteboardTypeString];
|
||||
[data release];
|
||||
}
|
||||
|
||||
qemu_clipboard_info_unref(info);
|
||||
|
||||
qemu_mutex_unlock_iothread();
|
||||
}
|
||||
|
||||
@end
|
||||
+921
@@ -0,0 +1,921 @@
|
||||
/*
|
||||
* QEMU Cocoa CG display driver
|
||||
*
|
||||
* Copyright (c) 2008 Mike Kronenberg
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "ui/cocoa.h"
|
||||
#include "ui/input.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
#define cgrect(nsrect) (*(CGRect *)&(nsrect))
|
||||
|
||||
static int cocoa_keycode_to_qemu(int keycode)
|
||||
{
|
||||
if (qemu_input_map_osx_to_qcode_len <= keycode) {
|
||||
error_report("(cocoa) warning unknown keycode 0x%x", keycode);
|
||||
return 0;
|
||||
}
|
||||
return qemu_input_map_osx_to_qcode[keycode];
|
||||
}
|
||||
|
||||
static CGRect compute_cursor_clip_rect(int screen_height,
|
||||
int given_mouse_x, int given_mouse_y,
|
||||
int cursor_width, int cursor_height)
|
||||
{
|
||||
CGRect rect;
|
||||
|
||||
rect.origin.x = MAX(0, -given_mouse_x);
|
||||
rect.origin.y = 0;
|
||||
rect.size.width = MIN(cursor_width, cursor_width + given_mouse_x);
|
||||
rect.size.height = cursor_height - rect.origin.x;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEventRef cgEvent, void *userInfo)
|
||||
{
|
||||
QemuCocoaView *cocoaView = (QemuCocoaView*) userInfo;
|
||||
NSEvent* event = [NSEvent eventWithCGEvent:cgEvent];
|
||||
if ([cocoaView isMouseGrabbed] && [cocoaView handleEvent:event]) {
|
||||
COCOA_DEBUG("Global events tap: qemu handled the event, capturing!\n");
|
||||
return NULL;
|
||||
}
|
||||
COCOA_DEBUG("Global events tap: qemu did not handle the event, letting it through...\n");
|
||||
|
||||
return cgEvent;
|
||||
}
|
||||
|
||||
@implementation QemuCocoaView
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
screen:(QEMUScreen *)given_screen
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaView: initWithFrame\n");
|
||||
|
||||
self = [super initWithFrame:frameRect];
|
||||
if (self) {
|
||||
|
||||
screen = given_screen;
|
||||
screen_width = frameRect.size.width;
|
||||
screen_height = frameRect.size.height;
|
||||
kbd = qkbd_state_init(screen->dcl.con);
|
||||
|
||||
/* Used for displaying pause on the screen */
|
||||
pauseLabel = [NSTextField new];
|
||||
[pauseLabel setBezeled:YES];
|
||||
[pauseLabel setDrawsBackground:YES];
|
||||
[pauseLabel setBackgroundColor: [NSColor whiteColor]];
|
||||
[pauseLabel setEditable:NO];
|
||||
[pauseLabel setSelectable:NO];
|
||||
[pauseLabel setStringValue: @"Paused"];
|
||||
[pauseLabel setFont: [NSFont fontWithName: @"Helvetica" size: 90]];
|
||||
[pauseLabel setTextColor: [NSColor blackColor]];
|
||||
[pauseLabel sizeToFit];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaView: dealloc\n");
|
||||
|
||||
if (pauseLabel) {
|
||||
[pauseLabel release];
|
||||
}
|
||||
|
||||
qkbd_state_free(kbd);
|
||||
|
||||
if (eventsTap) {
|
||||
CFRelease(eventsTap);
|
||||
}
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (BOOL) isOpaque
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) removeTrackingRect
|
||||
{
|
||||
if (trackingArea) {
|
||||
[self removeTrackingArea:trackingArea];
|
||||
[trackingArea release];
|
||||
trackingArea = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) frameUpdated
|
||||
{
|
||||
[self removeTrackingRect];
|
||||
|
||||
if ([self window]) {
|
||||
NSTrackingAreaOptions options = NSTrackingActiveInKeyWindow |
|
||||
NSTrackingMouseEnteredAndExited |
|
||||
NSTrackingMouseMoved;
|
||||
trackingArea = [[NSTrackingArea alloc] initWithRect:[self frame]
|
||||
options:options
|
||||
owner:self
|
||||
userInfo:nil];
|
||||
[self addTrackingArea:trackingArea];
|
||||
[self updateUIInfo];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) viewDidMoveToWindow
|
||||
{
|
||||
[self resizeWindow];
|
||||
[self frameUpdated];
|
||||
}
|
||||
|
||||
- (void) viewWillMoveToWindow:(NSWindow *)newWindow
|
||||
{
|
||||
[self removeTrackingRect];
|
||||
}
|
||||
|
||||
- (void) hideCursor
|
||||
{
|
||||
if (screen->cursor_show) {
|
||||
return;
|
||||
}
|
||||
[NSCursor hide];
|
||||
}
|
||||
|
||||
- (void) unhideCursor
|
||||
{
|
||||
if (screen->cursor_show) {
|
||||
return;
|
||||
}
|
||||
[NSCursor unhide];
|
||||
}
|
||||
|
||||
- (CGRect) convertCursorClipRectToDraw:(CGRect)rect
|
||||
screenHeight:(int)given_screen_height
|
||||
mouseX:(int)mouse_x
|
||||
mouseY:(int)mouse_y
|
||||
{
|
||||
CGFloat d = [self frame].size.height / (CGFloat)given_screen_height;
|
||||
|
||||
rect.origin.x = (rect.origin.x + mouse_x) * d;
|
||||
rect.origin.y = (given_screen_height - rect.origin.y - mouse_y - rect.size.height) * d;
|
||||
rect.size.width *= d;
|
||||
rect.size.height *= d;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
- (void) drawRect:(NSRect) rect
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaView: drawRect\n");
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
if (display_opengl) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// get CoreGraphic context
|
||||
CGContextRef viewContextRef = [[NSGraphicsContext currentContext] CGContext];
|
||||
|
||||
CGContextSetInterpolationQuality (viewContextRef, kCGInterpolationNone);
|
||||
CGContextSetShouldAntialias (viewContextRef, NO);
|
||||
|
||||
qemu_mutex_lock(&screen->draw_mutex);
|
||||
|
||||
// draw screen bitmap directly to Core Graphics context
|
||||
if (!screen->surface) {
|
||||
// Draw request before any guest device has set up a framebuffer:
|
||||
// just draw an opaque black rectangle
|
||||
CGContextSetRGBFillColor(viewContextRef, 0, 0, 0, 1.0);
|
||||
CGContextFillRect(viewContextRef, NSRectToCGRect(rect));
|
||||
} else {
|
||||
int w = surface_width(screen->surface);
|
||||
int h = surface_height(screen->surface);
|
||||
int bitsPerPixel = PIXMAN_FORMAT_BPP(surface_format(screen->surface));
|
||||
int stride = surface_stride(screen->surface);
|
||||
|
||||
CGDataProviderRef dataProviderRef = CGDataProviderCreateWithData(
|
||||
NULL,
|
||||
surface_data(screen->surface),
|
||||
stride * h,
|
||||
NULL
|
||||
);
|
||||
|
||||
CGImageRef imageRef = CGImageCreate(
|
||||
w, //width
|
||||
h, //height
|
||||
DIV_ROUND_UP(bitsPerPixel, 8) * 2, //bitsPerComponent
|
||||
bitsPerPixel, //bitsPerPixel
|
||||
stride, //bytesPerRow
|
||||
CGColorSpaceCreateWithName(kCGColorSpaceSRGB), //colorspace
|
||||
kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst, //bitmapInfo
|
||||
dataProviderRef, //provider
|
||||
NULL, //decode
|
||||
0, //interpolate
|
||||
kCGRenderingIntentDefault //intent
|
||||
);
|
||||
// selective drawing code (draws only dirty rectangles) (OS X >= 10.4)
|
||||
const NSRect *rectList;
|
||||
NSInteger rectCount;
|
||||
int i;
|
||||
CGImageRef clipImageRef;
|
||||
CGRect clipRect;
|
||||
CGFloat d = (CGFloat)h / [self frame].size.height;
|
||||
|
||||
[self getRectsBeingDrawn:&rectList count:&rectCount];
|
||||
for (i = 0; i < rectCount; i++) {
|
||||
clipRect.origin.x = rectList[i].origin.x * d;
|
||||
clipRect.origin.y = (float)h - (rectList[i].origin.y + rectList[i].size.height) * d;
|
||||
clipRect.size.width = rectList[i].size.width * d;
|
||||
clipRect.size.height = rectList[i].size.height * d;
|
||||
clipImageRef = CGImageCreateWithImageInRect(
|
||||
imageRef,
|
||||
clipRect
|
||||
);
|
||||
CGContextDrawImage (viewContextRef, cgrect(rectList[i]), clipImageRef);
|
||||
CGImageRelease (clipImageRef);
|
||||
}
|
||||
CGImageRelease (imageRef);
|
||||
CGDataProviderRelease(dataProviderRef);
|
||||
|
||||
if (screen->mouse_on) {
|
||||
size_t cursor_width = CGImageGetWidth(screen->cursor_cgimage);
|
||||
size_t cursor_height = CGImageGetHeight(screen->cursor_cgimage);
|
||||
clipRect = compute_cursor_clip_rect(h, screen->mouse_x, screen->mouse_y,
|
||||
cursor_width,
|
||||
cursor_height);
|
||||
CGRect drawRect = [self convertCursorClipRectToDraw:clipRect
|
||||
screenHeight:h
|
||||
mouseX:screen->mouse_x
|
||||
mouseY:screen->mouse_y];
|
||||
clipImageRef = CGImageCreateWithImageInRect(
|
||||
screen->cursor_cgimage,
|
||||
clipRect
|
||||
);
|
||||
CGContextDrawImage(viewContextRef, drawRect, clipImageRef);
|
||||
CGImageRelease (clipImageRef);
|
||||
}
|
||||
}
|
||||
|
||||
qemu_mutex_unlock(&screen->draw_mutex);
|
||||
}
|
||||
|
||||
- (NSSize) computeUnzoomedSize
|
||||
{
|
||||
CGFloat width = screen_width / [[self window] backingScaleFactor];
|
||||
CGFloat height = screen_height / [[self window] backingScaleFactor];
|
||||
|
||||
return NSMakeSize(width, height);
|
||||
}
|
||||
|
||||
- (NSSize) fixZoomedFullScreenSize:(NSSize)proposedSize
|
||||
{
|
||||
NSSize size;
|
||||
|
||||
size.width = (CGFloat)screen_width * proposedSize.height;
|
||||
size.height = (CGFloat)screen_height * proposedSize.width;
|
||||
|
||||
if (size.width < size.height) {
|
||||
size.width /= screen_height;
|
||||
size.height = proposedSize.height;
|
||||
} else {
|
||||
size.width = proposedSize.width;
|
||||
size.height /= screen_width;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
- (void) resizeWindow
|
||||
{
|
||||
[[self window] setContentAspectRatio:NSMakeSize(screen_width, screen_height)];
|
||||
|
||||
if (([[self window] styleMask] & NSWindowStyleMaskResizable) == 0) {
|
||||
[[self window] setContentSize:[self computeUnzoomedSize]];
|
||||
[[self window] center];
|
||||
} else if (([[self window] styleMask] & NSWindowStyleMaskFullScreen) != 0) {
|
||||
[[self window] setContentSize:[self fixZoomedFullScreenSize:[[[self window] screen] frame].size]];
|
||||
[[self window] center];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) updateUIInfo
|
||||
{
|
||||
NSSize frameSize;
|
||||
QemuUIInfo info = {};
|
||||
|
||||
if (!qatomic_load_acquire(&screen->inited)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ([self window]) {
|
||||
NSDictionary *description = [[[self window] screen] deviceDescription];
|
||||
CGDirectDisplayID display = [[description objectForKey:@"NSScreenNumber"] unsignedIntValue];
|
||||
NSSize screenSize = [[[self window] screen] frame].size;
|
||||
CGSize screenPhysicalSize = CGDisplayScreenSize(display);
|
||||
CVDisplayLinkRef displayLink;
|
||||
|
||||
if (([[self window] styleMask] & NSWindowStyleMaskFullScreen) == 0) {
|
||||
frameSize = [self frame].size;
|
||||
} else {
|
||||
frameSize = screenSize;
|
||||
}
|
||||
|
||||
if (!CVDisplayLinkCreateWithCGDisplay(display, &displayLink)) {
|
||||
CVTime period = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(displayLink);
|
||||
CVDisplayLinkRelease(displayLink);
|
||||
if (!(period.flags & kCVTimeIsIndefinite)) {
|
||||
update_displaychangelistener(&screen->dcl,
|
||||
1000 * period.timeValue / period.timeScale);
|
||||
info.refresh_rate = (int64_t)1000 * period.timeScale / period.timeValue;
|
||||
}
|
||||
}
|
||||
|
||||
info.width_mm = frameSize.width / screenSize.width * screenPhysicalSize.width;
|
||||
info.height_mm = frameSize.height / screenSize.height * screenPhysicalSize.height;
|
||||
} else {
|
||||
frameSize = [self frame].size;
|
||||
}
|
||||
|
||||
NSSize frameBackingSize = [self convertSizeToBacking:frameSize];
|
||||
|
||||
info.width = frameBackingSize.width;
|
||||
info.height = frameBackingSize.height;
|
||||
|
||||
dpy_set_ui_info(screen->dcl.con, &info);
|
||||
}
|
||||
|
||||
- (void) updateScreenWidth:(int)w height:(int)h
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaView: updateScreenWidth:height:\n");
|
||||
|
||||
if (w != screen_width || h != screen_height) {
|
||||
COCOA_DEBUG("updateScreenWidth:height: new size %d x %d\n", w, h);
|
||||
screen_width = w;
|
||||
screen_height = h;
|
||||
[self resizeWindow];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setFullGrab:(id)sender
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaView: setFullGrab\n");
|
||||
|
||||
CGEventMask mask = CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventFlagsChanged);
|
||||
eventsTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault,
|
||||
mask, handleTapEvent, self);
|
||||
if (!eventsTap) {
|
||||
warn_report("Could not create event tap, system key combos will not be captured.\n");
|
||||
return;
|
||||
} else {
|
||||
COCOA_DEBUG("Global events tap created! Will capture system key combos.\n");
|
||||
}
|
||||
|
||||
CFRunLoopRef runLoop = CFRunLoopGetCurrent();
|
||||
if (!runLoop) {
|
||||
warn_report("Could not obtain current CF RunLoop, system key combos will not be captured.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
CFRunLoopSourceRef tapEventsSrc = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventsTap, 0);
|
||||
if (!tapEventsSrc ) {
|
||||
warn_report("Could not obtain current CF RunLoop, system key combos will not be captured.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
CFRunLoopAddSource(runLoop, tapEventsSrc, kCFRunLoopDefaultMode);
|
||||
CFRelease(tapEventsSrc);
|
||||
}
|
||||
|
||||
- (void) toggleKey: (int)keycode {
|
||||
qkbd_state_key_event(kbd, keycode, !qkbd_state_key_get(kbd, keycode));
|
||||
}
|
||||
|
||||
// Does the work of sending input to the monitor
|
||||
- (void) handleMonitorInput:(NSEvent *)event
|
||||
{
|
||||
int keysym = 0;
|
||||
int control_key = 0;
|
||||
|
||||
// if the control key is down
|
||||
if ([event modifierFlags] & NSEventModifierFlagControl) {
|
||||
control_key = 1;
|
||||
}
|
||||
|
||||
/* translates Macintosh keycodes to QEMU's keysym */
|
||||
|
||||
int without_control_translation[] = {
|
||||
[0 ... 0xff] = 0, // invalid key
|
||||
|
||||
[kVK_UpArrow] = QEMU_KEY_UP,
|
||||
[kVK_DownArrow] = QEMU_KEY_DOWN,
|
||||
[kVK_RightArrow] = QEMU_KEY_RIGHT,
|
||||
[kVK_LeftArrow] = QEMU_KEY_LEFT,
|
||||
[kVK_Home] = QEMU_KEY_HOME,
|
||||
[kVK_End] = QEMU_KEY_END,
|
||||
[kVK_PageUp] = QEMU_KEY_PAGEUP,
|
||||
[kVK_PageDown] = QEMU_KEY_PAGEDOWN,
|
||||
[kVK_ForwardDelete] = QEMU_KEY_DELETE,
|
||||
[kVK_Delete] = QEMU_KEY_BACKSPACE,
|
||||
};
|
||||
|
||||
int with_control_translation[] = {
|
||||
[0 ... 0xff] = 0, // invalid key
|
||||
|
||||
[kVK_UpArrow] = QEMU_KEY_CTRL_UP,
|
||||
[kVK_DownArrow] = QEMU_KEY_CTRL_DOWN,
|
||||
[kVK_RightArrow] = QEMU_KEY_CTRL_RIGHT,
|
||||
[kVK_LeftArrow] = QEMU_KEY_CTRL_LEFT,
|
||||
[kVK_Home] = QEMU_KEY_CTRL_HOME,
|
||||
[kVK_End] = QEMU_KEY_CTRL_END,
|
||||
[kVK_PageUp] = QEMU_KEY_CTRL_PAGEUP,
|
||||
[kVK_PageDown] = QEMU_KEY_CTRL_PAGEDOWN,
|
||||
};
|
||||
|
||||
if (control_key != 0) { /* If the control key is being used */
|
||||
if ([event keyCode] < ARRAY_SIZE(with_control_translation)) {
|
||||
keysym = with_control_translation[[event keyCode]];
|
||||
}
|
||||
} else {
|
||||
if ([event keyCode] < ARRAY_SIZE(without_control_translation)) {
|
||||
keysym = without_control_translation[[event keyCode]];
|
||||
}
|
||||
}
|
||||
|
||||
// if not a key that needs translating
|
||||
if (keysym == 0) {
|
||||
NSString *ks = [event characters];
|
||||
if ([ks length] > 0) {
|
||||
keysym = [ks characterAtIndex:0];
|
||||
}
|
||||
}
|
||||
|
||||
if (keysym) {
|
||||
kbd_put_keysym(keysym);
|
||||
}
|
||||
}
|
||||
|
||||
- (bool) handleEvent:(NSEvent *)event
|
||||
{
|
||||
if(!qatomic_read(&screen->inited)) {
|
||||
/*
|
||||
* Just let OSX have all events that arrive before
|
||||
* applicationDidFinishLaunching.
|
||||
* This avoids a deadlock on the iothread lock, which cocoa_display_init()
|
||||
* will not drop until after the app_started_sem is posted. (In theory
|
||||
* there should not be any such events, but OSX Catalina now emits some.)
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
qemu_mutex_lock_iothread();
|
||||
bool handled = [self handleEventLocked:event];
|
||||
qemu_mutex_unlock_iothread();
|
||||
return handled;
|
||||
}
|
||||
|
||||
- (bool) handleEventLocked:(NSEvent *)event
|
||||
{
|
||||
/* Return true if we handled the event, false if it should be given to OSX */
|
||||
COCOA_DEBUG("QemuCocoaView: handleEvent\n");
|
||||
int keycode = 0;
|
||||
NSUInteger modifiers = [event modifierFlags];
|
||||
|
||||
/*
|
||||
* Check -[NSEvent modifierFlags] here.
|
||||
*
|
||||
* There is a NSEventType for an event notifying the change of
|
||||
* -[NSEvent modifierFlags], NSEventTypeFlagsChanged but these operations
|
||||
* are performed for any events because a modifier state may change while
|
||||
* the application is inactive (i.e. no events fire) and we don't want to
|
||||
* wait for another modifier state change to detect such a change.
|
||||
*
|
||||
* NSEventModifierFlagCapsLock requires a special treatment. The other flags
|
||||
* are handled in similar manners.
|
||||
*
|
||||
* NSEventModifierFlagCapsLock
|
||||
* ---------------------------
|
||||
*
|
||||
* If CapsLock state is changed, "up" and "down" events will be fired in
|
||||
* sequence, effectively updates CapsLock state on the guest.
|
||||
*
|
||||
* The other flags
|
||||
* ---------------
|
||||
*
|
||||
* If a flag is not set, fire "up" events for all keys which correspond to
|
||||
* the flag. Note that "down" events are not fired here because the flags
|
||||
* checked here do not tell what exact keys are down.
|
||||
*
|
||||
* If one of the keys corresponding to a flag is down, we rely on
|
||||
* -[NSEvent keyCode] of an event whose -[NSEvent type] is
|
||||
* NSEventTypeFlagsChanged to know the exact key which is down, which has
|
||||
* the following two downsides:
|
||||
* - It does not work when the application is inactive as described above.
|
||||
* - It malfactions *after* the modifier state is changed while the
|
||||
* application is inactive. It is because -[NSEvent keyCode] does not tell
|
||||
* if the key is up or down, and requires to infer the current state from
|
||||
* the previous state. It is still possible to fix such a malfanction by
|
||||
* completely leaving your hands from the keyboard, which hopefully makes
|
||||
* this implementation usable enough.
|
||||
*/
|
||||
if (!!(modifiers & NSEventModifierFlagCapsLock) !=
|
||||
qkbd_state_modifier_get(kbd, QKBD_MOD_CAPSLOCK)) {
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_CAPS_LOCK, true);
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_CAPS_LOCK, false);
|
||||
}
|
||||
|
||||
if (!(modifiers & NSEventModifierFlagShift)) {
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_SHIFT, false);
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_SHIFT_R, false);
|
||||
}
|
||||
if (!(modifiers & NSEventModifierFlagControl)) {
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_CTRL, false);
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_CTRL_R, false);
|
||||
}
|
||||
if (!(modifiers & NSEventModifierFlagOption)) {
|
||||
if ([self isSwapOptionCommandEnabled]) {
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false);
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false);
|
||||
} else {
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false);
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false);
|
||||
}
|
||||
}
|
||||
if (!(modifiers & NSEventModifierFlagCommand)) {
|
||||
if ([self isSwapOptionCommandEnabled]) {
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false);
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false);
|
||||
} else {
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false);
|
||||
qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false);
|
||||
}
|
||||
}
|
||||
|
||||
switch ([event type]) {
|
||||
case NSEventTypeFlagsChanged:
|
||||
switch ([event keyCode]) {
|
||||
case kVK_Shift:
|
||||
if (!!(modifiers & NSEventModifierFlagShift)) {
|
||||
[self toggleKey:Q_KEY_CODE_SHIFT];
|
||||
}
|
||||
return true;
|
||||
|
||||
case kVK_RightShift:
|
||||
if (!!(modifiers & NSEventModifierFlagShift)) {
|
||||
[self toggleKey:Q_KEY_CODE_SHIFT_R];
|
||||
}
|
||||
return true;
|
||||
|
||||
case kVK_Control:
|
||||
if (!!(modifiers & NSEventModifierFlagControl)) {
|
||||
[self toggleKey:Q_KEY_CODE_CTRL];
|
||||
}
|
||||
return true;
|
||||
|
||||
case kVK_RightControl:
|
||||
if (!!(modifiers & NSEventModifierFlagControl)) {
|
||||
[self toggleKey:Q_KEY_CODE_CTRL_R];
|
||||
}
|
||||
return true;
|
||||
|
||||
case kVK_Option:
|
||||
if (!!(modifiers & NSEventModifierFlagOption)) {
|
||||
if ([self isSwapOptionCommandEnabled]) {
|
||||
[self toggleKey:Q_KEY_CODE_META_L];
|
||||
} else {
|
||||
[self toggleKey:Q_KEY_CODE_ALT];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case kVK_RightOption:
|
||||
if (!!(modifiers & NSEventModifierFlagOption)) {
|
||||
if ([self isSwapOptionCommandEnabled]) {
|
||||
[self toggleKey:Q_KEY_CODE_META_R];
|
||||
} else {
|
||||
[self toggleKey:Q_KEY_CODE_ALT_R];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
/* Don't pass command key changes to guest unless mouse is grabbed */
|
||||
case kVK_Command:
|
||||
if (isMouseGrabbed &&
|
||||
!!(modifiers & NSEventModifierFlagCommand)) {
|
||||
if ([self isSwapOptionCommandEnabled]) {
|
||||
[self toggleKey:Q_KEY_CODE_ALT];
|
||||
} else {
|
||||
[self toggleKey:Q_KEY_CODE_META_L];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case kVK_RightCommand:
|
||||
if (isMouseGrabbed &&
|
||||
!!(modifiers & NSEventModifierFlagCommand)) {
|
||||
if ([self isSwapOptionCommandEnabled]) {
|
||||
[self toggleKey:Q_KEY_CODE_ALT_R];
|
||||
} else {
|
||||
[self toggleKey:Q_KEY_CODE_META_R];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
case NSEventTypeKeyDown:
|
||||
keycode = cocoa_keycode_to_qemu([event keyCode]);
|
||||
|
||||
// forward command key combos to the host UI unless the mouse is grabbed
|
||||
if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifierFlagCommand)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// default
|
||||
|
||||
// handle control + alt Key Combos (ctrl+alt+[1..9,g] is reserved for QEMU)
|
||||
if (([event modifierFlags] & NSEventModifierFlagControl) && ([event modifierFlags] & NSEventModifierFlagOption)) {
|
||||
NSString *keychar = [event charactersIgnoringModifiers];
|
||||
if ([keychar length] == 1) {
|
||||
char key = [keychar characterAtIndex:0];
|
||||
switch (key) {
|
||||
|
||||
// enable graphic console
|
||||
case '1' ... '9':
|
||||
console_select(key - '0' - 1); /* ascii math */
|
||||
return true;
|
||||
|
||||
// release the mouse grab
|
||||
case 'g':
|
||||
[self ungrabMouseLocked];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (qemu_console_is_graphic(NULL)) {
|
||||
qkbd_state_key_event(kbd, keycode, true);
|
||||
} else {
|
||||
[self handleMonitorInput: event];
|
||||
}
|
||||
return true;
|
||||
case NSEventTypeKeyUp:
|
||||
keycode = cocoa_keycode_to_qemu([event keyCode]);
|
||||
|
||||
// don't pass the guest a spurious key-up if we treated this
|
||||
// command-key combo as a host UI action
|
||||
if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifierFlagCommand)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (qemu_console_is_graphic(NULL)) {
|
||||
qkbd_state_key_event(kbd, keycode, false);
|
||||
}
|
||||
return true;
|
||||
case NSEventTypeScrollWheel:
|
||||
/*
|
||||
* Send wheel events to the guest regardless of window focus.
|
||||
* This is in-line with standard Mac OS X UI behaviour.
|
||||
*/
|
||||
|
||||
/*
|
||||
* When deltaY is zero, it means that this scrolling event was
|
||||
* either horizontal, or so fine that it only appears in
|
||||
* scrollingDeltaY. So we drop the event.
|
||||
*/
|
||||
if ([event deltaY] != 0) {
|
||||
/* Determine if this is a scroll up or scroll down event */
|
||||
int buttons = ([event deltaY] > 0) ?
|
||||
INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
|
||||
qemu_input_queue_btn(screen->dcl.con, buttons, true);
|
||||
qemu_input_event_sync();
|
||||
qemu_input_queue_btn(screen->dcl.con, buttons, false);
|
||||
qemu_input_event_sync();
|
||||
}
|
||||
/*
|
||||
* Since deltaY also reports scroll wheel events we prevent mouse
|
||||
* movement code from executing.
|
||||
*/
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) handleMouseEvent:(NSEvent *)event
|
||||
{
|
||||
if (!isMouseGrabbed) {
|
||||
return;
|
||||
}
|
||||
|
||||
qemu_mutex_lock_iothread();
|
||||
|
||||
if (isAbsoluteEnabled) {
|
||||
CGFloat d = (CGFloat)screen_height / [self frame].size.height;
|
||||
NSPoint p = [event locationInWindow];
|
||||
// Note that the origin for Cocoa mouse coords is bottom left, not top left.
|
||||
qemu_input_queue_abs(screen->dcl.con, INPUT_AXIS_X, p.x * d, 0, screen_width);
|
||||
qemu_input_queue_abs(screen->dcl.con, INPUT_AXIS_Y, screen_height - p.y * d, 0, screen_height);
|
||||
} else {
|
||||
CGFloat d = (CGFloat)screen_height / [self convertSizeToBacking:[self frame].size].height;
|
||||
qemu_input_queue_rel(screen->dcl.con, INPUT_AXIS_X, [event deltaX] * d);
|
||||
qemu_input_queue_rel(screen->dcl.con, INPUT_AXIS_Y, [event deltaY] * d);
|
||||
}
|
||||
|
||||
qemu_input_event_sync();
|
||||
|
||||
qemu_mutex_unlock_iothread();
|
||||
}
|
||||
|
||||
- (void) handleMouseEvent:(NSEvent *)event button:(InputButton)button down:(bool)down
|
||||
{
|
||||
if (!isMouseGrabbed) {
|
||||
return;
|
||||
}
|
||||
|
||||
qemu_mutex_lock_iothread();
|
||||
qemu_input_queue_btn(screen->dcl.con, button, down);
|
||||
qemu_mutex_unlock_iothread();
|
||||
|
||||
[self handleMouseEvent:event];
|
||||
}
|
||||
|
||||
- (void) mouseExited:(NSEvent *)event
|
||||
{
|
||||
if (isAbsoluteEnabled && isMouseGrabbed) {
|
||||
[self ungrabMouse];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) mouseEntered:(NSEvent *)event
|
||||
{
|
||||
if (isAbsoluteEnabled && !isMouseGrabbed) {
|
||||
[self grabMouse];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) mouseMoved:(NSEvent *)event
|
||||
{
|
||||
[self handleMouseEvent:event];
|
||||
}
|
||||
|
||||
- (void) mouseDown:(NSEvent *)event
|
||||
{
|
||||
[self handleMouseEvent:event button:INPUT_BUTTON_LEFT down:true];
|
||||
}
|
||||
|
||||
- (void) rightMouseDown:(NSEvent *)event
|
||||
{
|
||||
[self handleMouseEvent:event button:INPUT_BUTTON_RIGHT down:true];
|
||||
}
|
||||
|
||||
- (void) otherMouseDown:(NSEvent *)event
|
||||
{
|
||||
[self handleMouseEvent:event button:INPUT_BUTTON_MIDDLE down:true];
|
||||
}
|
||||
|
||||
- (void) mouseDragged:(NSEvent *)event
|
||||
{
|
||||
[self handleMouseEvent:event];
|
||||
}
|
||||
|
||||
- (void) rightMouseDragged:(NSEvent *)event
|
||||
{
|
||||
[self handleMouseEvent:event];
|
||||
}
|
||||
|
||||
- (void) otherMouseDragged:(NSEvent *)event
|
||||
{
|
||||
[self handleMouseEvent:event];
|
||||
}
|
||||
|
||||
- (void) mouseUp:(NSEvent *)event
|
||||
{
|
||||
if (!isMouseGrabbed) {
|
||||
[self grabMouse];
|
||||
}
|
||||
|
||||
[self handleMouseEvent:event button:INPUT_BUTTON_LEFT down:false];
|
||||
}
|
||||
|
||||
- (void) rightMouseUp:(NSEvent *)event
|
||||
{
|
||||
[self handleMouseEvent:event button:INPUT_BUTTON_RIGHT down:false];
|
||||
}
|
||||
|
||||
- (void) otherMouseUp:(NSEvent *)event
|
||||
{
|
||||
[self handleMouseEvent:event button:INPUT_BUTTON_MIDDLE down:false];
|
||||
}
|
||||
|
||||
- (void) grabMouse
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaView: grabMouse\n");
|
||||
|
||||
if (qemu_name)
|
||||
[[self window] setTitle:[NSString stringWithFormat:@"QEMU %s - (Press ctrl + alt + g to release Mouse)", qemu_name]];
|
||||
else
|
||||
[[self window] setTitle:@"QEMU - (Press ctrl + alt + g to release Mouse)"];
|
||||
[self hideCursor];
|
||||
CGAssociateMouseAndMouseCursorPosition(isAbsoluteEnabled);
|
||||
isMouseGrabbed = TRUE; // while isMouseGrabbed = TRUE, QemuCocoaApp sends all events to [cocoaView handleEvent:]
|
||||
}
|
||||
|
||||
- (void) ungrabMouse
|
||||
{
|
||||
qemu_mutex_lock_iothread();
|
||||
[self ungrabMouseLocked];
|
||||
qemu_mutex_unlock_iothread();
|
||||
}
|
||||
|
||||
- (void) ungrabMouseLocked
|
||||
{
|
||||
COCOA_DEBUG("QemuCocoaView: ungrabMouseLocked\n");
|
||||
|
||||
if (qemu_name)
|
||||
[[self window] setTitle:[NSString stringWithFormat:@"QEMU %s", qemu_name]];
|
||||
else
|
||||
[[self window] setTitle:@"QEMU"];
|
||||
[self unhideCursor];
|
||||
CGAssociateMouseAndMouseCursorPosition(TRUE);
|
||||
isMouseGrabbed = FALSE;
|
||||
[self raiseAllButtonsLocked];
|
||||
}
|
||||
|
||||
- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled {
|
||||
isAbsoluteEnabled = tIsAbsoluteEnabled;
|
||||
if (isMouseGrabbed) {
|
||||
CGAssociateMouseAndMouseCursorPosition(isAbsoluteEnabled);
|
||||
}
|
||||
}
|
||||
- (BOOL) isMouseGrabbed {return isMouseGrabbed;}
|
||||
- (BOOL) isAbsoluteEnabled {return isAbsoluteEnabled;}
|
||||
- (BOOL) isSwapOptionCommandEnabled {return screen->swap_option_command;}
|
||||
|
||||
- (void) raiseAllButtonsLocked
|
||||
{
|
||||
qemu_input_queue_btn(screen->dcl.con, INPUT_BUTTON_LEFT, false);
|
||||
qemu_input_queue_btn(screen->dcl.con, INPUT_BUTTON_RIGHT, false);
|
||||
qemu_input_queue_btn(screen->dcl.con, INPUT_BUTTON_MIDDLE, false);
|
||||
}
|
||||
|
||||
- (void) setNeedsDisplayForCursorX:(int)x
|
||||
y:(int)y
|
||||
width:(int)width
|
||||
height:(int)height
|
||||
screenHeight:(int)given_screen_height
|
||||
{
|
||||
CGRect clip_rect = compute_cursor_clip_rect(given_screen_height, x, y,
|
||||
width, height);
|
||||
CGRect draw_rect = [self convertCursorClipRectToDraw:clip_rect
|
||||
screenHeight:given_screen_height
|
||||
mouseX:x
|
||||
mouseY:y];
|
||||
[self setNeedsDisplayInRect:draw_rect];
|
||||
}
|
||||
|
||||
/* Displays the word pause on the screen */
|
||||
- (void)displayPause
|
||||
{
|
||||
/* Coordinates have to be calculated each time because the window can change its size */
|
||||
int xCoord, yCoord, width, height;
|
||||
xCoord = ([[self window] frame].size.width - [pauseLabel frame].size.width)/2;
|
||||
yCoord = [[self window] frame].size.height - [pauseLabel frame].size.height - ([pauseLabel frame].size.height * .5);
|
||||
width = [pauseLabel frame].size.width;
|
||||
height = [pauseLabel frame].size.height;
|
||||
[pauseLabel setFrame: NSMakeRect(xCoord, yCoord, width, height)];
|
||||
[self addSubview: pauseLabel];
|
||||
}
|
||||
|
||||
/* Removes the word pause from the screen */
|
||||
- (void)removePause
|
||||
{
|
||||
[pauseLabel removeFromSuperview];
|
||||
}
|
||||
@end
|
||||
+79
-63
@@ -127,7 +127,7 @@ struct QemuConsole {
|
||||
DisplayState *ds;
|
||||
DisplaySurface *surface;
|
||||
int dcls;
|
||||
DisplayChangeListener *gl;
|
||||
void *dg;
|
||||
bool gl_block;
|
||||
int window_id;
|
||||
|
||||
@@ -184,6 +184,7 @@ struct DisplayState {
|
||||
QLIST_HEAD(, DisplayChangeListener) listeners;
|
||||
};
|
||||
|
||||
static const DisplayGLOps *display_gl_ops;
|
||||
static DisplayState *display_state;
|
||||
static QemuConsole *active_console;
|
||||
static QTAILQ_HEAD(, QemuConsole) consoles =
|
||||
@@ -203,7 +204,6 @@ static void gui_update(void *opaque)
|
||||
uint64_t dcl_interval;
|
||||
DisplayState *ds = opaque;
|
||||
DisplayChangeListener *dcl;
|
||||
QemuConsole *con;
|
||||
|
||||
ds->refreshing = true;
|
||||
dpy_refresh(ds);
|
||||
@@ -218,11 +218,6 @@ static void gui_update(void *opaque)
|
||||
}
|
||||
if (ds->update_interval != interval) {
|
||||
ds->update_interval = interval;
|
||||
QTAILQ_FOREACH(con, &consoles, next) {
|
||||
if (con->hw_ops->update_interval) {
|
||||
con->hw_ops->update_interval(con->hw, interval);
|
||||
}
|
||||
}
|
||||
trace_console_refresh(interval);
|
||||
}
|
||||
ds->last_update = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
|
||||
@@ -1109,8 +1104,14 @@ void console_select(unsigned int index)
|
||||
}
|
||||
}
|
||||
if (s->surface) {
|
||||
dpy_gfx_update(s, 0, 0, surface_width(s->surface),
|
||||
surface_height(s->surface));
|
||||
int width = surface_width(s->surface);
|
||||
int height = surface_height(s->surface);
|
||||
if (display_gl_ops &&
|
||||
display_gl_ops->dpy_gl_scanout_get_enabled(s->dg)) {
|
||||
dpy_gl_update(s, 0, 0, width, height);
|
||||
} else {
|
||||
dpy_gfx_update(s, 0, 0, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ds->have_text) {
|
||||
@@ -1460,26 +1461,30 @@ void qemu_free_displaysurface(DisplaySurface *surface)
|
||||
g_free(surface);
|
||||
}
|
||||
|
||||
bool console_has_gl(QemuConsole *con)
|
||||
bool console_has_gl(void)
|
||||
{
|
||||
return con->gl != NULL;
|
||||
return display_gl_ops != NULL;
|
||||
}
|
||||
|
||||
static bool displaychangelistener_has_dmabuf(DisplayChangeListener *dcl)
|
||||
void console_set_displayglcontext(QemuConsole *con, void *dg)
|
||||
{
|
||||
if (dcl->ops->dpy_has_dmabuf) {
|
||||
return dcl->ops->dpy_has_dmabuf(dcl);
|
||||
con->dg = dg;
|
||||
}
|
||||
|
||||
static bool console_has_dmabuf(QemuConsole *con)
|
||||
{
|
||||
if (display_gl_ops->dpy_has_dmabuf) {
|
||||
return display_gl_ops->dpy_has_dmabuf(con->dg);
|
||||
}
|
||||
|
||||
if (dcl->ops->dpy_gl_scanout_dmabuf) {
|
||||
if (display_gl_ops->dpy_gl_scanout_dmabuf) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool dpy_compatible_with(QemuConsole *con,
|
||||
DisplayChangeListener *dcl, Error **errp)
|
||||
static bool dpy_compatible_with(QemuConsole *con, Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
int flags;
|
||||
@@ -1487,14 +1492,13 @@ static bool dpy_compatible_with(QemuConsole *con,
|
||||
flags = con->hw_ops->get_flags ? con->hw_ops->get_flags(con->hw) : 0;
|
||||
|
||||
if (flags & GRAPHIC_FLAGS_GL &&
|
||||
!console_has_gl(con)) {
|
||||
!console_has_gl()) {
|
||||
error_setg(errp, "The console requires a GL context.");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if (flags & GRAPHIC_FLAGS_DMABUF &&
|
||||
!displaychangelistener_has_dmabuf(dcl)) {
|
||||
!console_has_dmabuf(con)) {
|
||||
error_setg(errp, "The console requires display DMABUF support.");
|
||||
return false;
|
||||
}
|
||||
@@ -1502,6 +1506,16 @@ static bool dpy_compatible_with(QemuConsole *con,
|
||||
return true;
|
||||
}
|
||||
|
||||
void register_displayglops(const DisplayGLOps *dg_ops)
|
||||
{
|
||||
if (display_gl_ops) {
|
||||
error_report("can't register two opengl operators");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
display_gl_ops = dg_ops;
|
||||
}
|
||||
|
||||
void register_displaychangelistener(DisplayChangeListener *dcl)
|
||||
{
|
||||
static const char nodev[] =
|
||||
@@ -1512,20 +1526,18 @@ void register_displaychangelistener(DisplayChangeListener *dcl)
|
||||
|
||||
assert(!dcl->ds);
|
||||
|
||||
if (dcl->ops->dpy_gl_ctx_create) {
|
||||
/* display has opengl support */
|
||||
assert(dcl->con);
|
||||
if (dcl->con->gl) {
|
||||
fprintf(stderr, "can't register two opengl displays (%s, %s)\n",
|
||||
dcl->ops->dpy_name, dcl->con->gl->ops->dpy_name);
|
||||
if (dcl->con) {
|
||||
if (!dpy_compatible_with(dcl->con, &err)) {
|
||||
error_report_err(err);
|
||||
exit(1);
|
||||
}
|
||||
dcl->con->gl = dcl;
|
||||
}
|
||||
|
||||
if (dcl->con && !dpy_compatible_with(dcl->con, dcl, &err)) {
|
||||
error_report_err(err);
|
||||
exit(1);
|
||||
} else {
|
||||
QTAILQ_FOREACH(con, &consoles, next) {
|
||||
if (!dpy_compatible_with(con, &err)) {
|
||||
error_report_err(err);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trace_displaychangelistener_register(dcl, dcl->ops->dpy_name);
|
||||
@@ -1842,86 +1854,90 @@ bool dpy_cursor_define_supported(QemuConsole *con)
|
||||
QEMUGLContext dpy_gl_ctx_create(QemuConsole *con,
|
||||
struct QEMUGLParams *qparams)
|
||||
{
|
||||
assert(con->gl);
|
||||
return con->gl->ops->dpy_gl_ctx_create(con->gl, qparams);
|
||||
assert(display_gl_ops);
|
||||
return display_gl_ops->dpy_gl_ctx_create(con->dg, qparams);
|
||||
}
|
||||
|
||||
void dpy_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx)
|
||||
{
|
||||
assert(con->gl);
|
||||
con->gl->ops->dpy_gl_ctx_destroy(con->gl, ctx);
|
||||
assert(display_gl_ops);
|
||||
display_gl_ops->dpy_gl_ctx_destroy(con->dg, ctx);
|
||||
}
|
||||
|
||||
int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx)
|
||||
{
|
||||
assert(con->gl);
|
||||
return con->gl->ops->dpy_gl_ctx_make_current(con->gl, ctx);
|
||||
assert(display_gl_ops);
|
||||
return display_gl_ops->dpy_gl_ctx_make_current(con->dg, ctx);
|
||||
}
|
||||
|
||||
void dpy_gl_scanout_disable(QemuConsole *con)
|
||||
{
|
||||
assert(con->gl);
|
||||
con->gl->ops->dpy_gl_scanout_disable(con->gl);
|
||||
assert(display_gl_ops);
|
||||
display_gl_ops->dpy_gl_scanout_disable(con->dg);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
assert(con->gl);
|
||||
con->gl->ops->dpy_gl_scanout_texture(con->gl, backing_id,
|
||||
backing_y_0_top,
|
||||
backing_width, backing_height,
|
||||
x, y, width, height);
|
||||
assert(display_gl_ops);
|
||||
display_gl_ops->dpy_gl_scanout_texture(con->dg, backing_id, backing_borrow,
|
||||
x, y, width, height);
|
||||
}
|
||||
|
||||
void dpy_gl_scanout_dmabuf(QemuConsole *con,
|
||||
QemuDmaBuf *dmabuf)
|
||||
{
|
||||
assert(con->gl);
|
||||
con->gl->ops->dpy_gl_scanout_dmabuf(con->gl, dmabuf);
|
||||
assert(display_gl_ops);
|
||||
display_gl_ops->dpy_gl_scanout_dmabuf(con->dg, dmabuf);
|
||||
}
|
||||
|
||||
void dpy_gl_cursor_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf,
|
||||
bool have_hot, uint32_t hot_x, uint32_t hot_y)
|
||||
{
|
||||
assert(con->gl);
|
||||
assert(display_gl_ops);
|
||||
|
||||
if (con->gl->ops->dpy_gl_cursor_dmabuf) {
|
||||
con->gl->ops->dpy_gl_cursor_dmabuf(con->gl, dmabuf,
|
||||
have_hot, hot_x, hot_y);
|
||||
if (display_gl_ops->dpy_gl_cursor_dmabuf) {
|
||||
display_gl_ops->dpy_gl_cursor_dmabuf(con->dg, dmabuf,
|
||||
have_hot, hot_x, hot_y);
|
||||
}
|
||||
}
|
||||
|
||||
void dpy_gl_cursor_position(QemuConsole *con,
|
||||
uint32_t pos_x, uint32_t pos_y)
|
||||
{
|
||||
assert(con->gl);
|
||||
assert(display_gl_ops);
|
||||
|
||||
if (con->gl->ops->dpy_gl_cursor_position) {
|
||||
con->gl->ops->dpy_gl_cursor_position(con->gl, pos_x, pos_y);
|
||||
if (display_gl_ops->dpy_gl_cursor_position) {
|
||||
display_gl_ops->dpy_gl_cursor_position(con->dg, pos_x, pos_y);
|
||||
}
|
||||
}
|
||||
|
||||
void dpy_gl_release_dmabuf(QemuConsole *con,
|
||||
QemuDmaBuf *dmabuf)
|
||||
{
|
||||
assert(con->gl);
|
||||
assert(display_gl_ops);
|
||||
|
||||
if (con->gl->ops->dpy_gl_release_dmabuf) {
|
||||
con->gl->ops->dpy_gl_release_dmabuf(con->gl, dmabuf);
|
||||
if (display_gl_ops->dpy_gl_release_dmabuf) {
|
||||
display_gl_ops->dpy_gl_release_dmabuf(con->dg, dmabuf);
|
||||
}
|
||||
}
|
||||
|
||||
void dpy_gl_update(QemuConsole *con,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h)
|
||||
{
|
||||
assert(con->gl);
|
||||
con->gl->ops->dpy_gl_update(con->gl, x, y, w, h);
|
||||
DisplayChangeListener *dcl;
|
||||
|
||||
QLIST_FOREACH(dcl, &con->ds->listeners, next) {
|
||||
if (con != (dcl->con ? dcl->con : active_console)) {
|
||||
continue;
|
||||
}
|
||||
if (dcl->ops->dpy_gl_update) {
|
||||
dcl->ops->dpy_gl_update(dcl, x, y, w, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************/
|
||||
@@ -2032,7 +2048,7 @@ void graphic_console_close(QemuConsole *con)
|
||||
object_property_set_link(OBJECT(con), "device", NULL, &error_abort);
|
||||
graphic_console_set_hwops(con, &unused_ops, NULL);
|
||||
|
||||
if (con->gl) {
|
||||
if (display_gl_ops) {
|
||||
dpy_gl_scanout_disable(con);
|
||||
}
|
||||
surface = qemu_create_placeholder_surface(width, height, unplugged);
|
||||
|
||||
+3
-5
@@ -1,8 +1,7 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "ui/egl-context.h"
|
||||
|
||||
QEMUGLContext qemu_egl_create_context(DisplayChangeListener *dcl,
|
||||
QEMUGLParams *params)
|
||||
QEMUGLContext qemu_egl_create_context(void *dg, QEMUGLParams *params)
|
||||
{
|
||||
EGLContext ctx;
|
||||
EGLint ctx_att_core[] = {
|
||||
@@ -24,13 +23,12 @@ QEMUGLContext qemu_egl_create_context(DisplayChangeListener *dcl,
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void qemu_egl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx)
|
||||
void qemu_egl_destroy_context(void *dg, QEMUGLContext ctx)
|
||||
{
|
||||
eglDestroyContext(qemu_egl_display, ctx);
|
||||
}
|
||||
|
||||
int qemu_egl_make_context_current(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx)
|
||||
int qemu_egl_make_context_current(void *dg, QEMUGLContext ctx)
|
||||
{
|
||||
return eglMakeCurrent(qemu_egl_display,
|
||||
EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
|
||||
|
||||
+85
-36
@@ -18,6 +18,10 @@ typedef struct egl_dpy {
|
||||
uint32_t pos_y;
|
||||
} egl_dpy;
|
||||
|
||||
#ifndef CONFIG_GBM
|
||||
static EGLContext ctx;
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static void egl_refresh(DisplayChangeListener *dcl)
|
||||
@@ -38,37 +42,43 @@ static void egl_gfx_switch(DisplayChangeListener *dcl,
|
||||
edpy->ds = new_surface;
|
||||
}
|
||||
|
||||
static QEMUGLContext egl_create_context(DisplayChangeListener *dcl,
|
||||
static QEMUGLContext egl_create_context(void *dg,
|
||||
QEMUGLParams *params)
|
||||
{
|
||||
#ifdef CONFIG_GBM
|
||||
eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||
qemu_egl_rn_ctx);
|
||||
return qemu_egl_create_context(dcl, params);
|
||||
#else
|
||||
eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
|
||||
#endif
|
||||
return qemu_egl_create_context(dg, params);
|
||||
}
|
||||
|
||||
static void egl_scanout_disable(DisplayChangeListener *dcl)
|
||||
static bool egl_scanout_get_enabled(void *dg)
|
||||
{
|
||||
egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
|
||||
return ((egl_dpy *)dg)->guest_fb.texture != 0;
|
||||
}
|
||||
|
||||
static void egl_scanout_disable(void *dg)
|
||||
{
|
||||
egl_dpy *edpy = dg;
|
||||
egl_fb_destroy(&edpy->guest_fb);
|
||||
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(void *dg,
|
||||
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);
|
||||
egl_dpy *edpy = dg;
|
||||
|
||||
edpy->y_0_top = backing_y_0_top;
|
||||
|
||||
/* 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 ||
|
||||
@@ -78,24 +88,41 @@ static void egl_scanout_texture(DisplayChangeListener *dcl,
|
||||
}
|
||||
}
|
||||
|
||||
static void egl_scanout_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf)
|
||||
static void egl_scanout_texture(void *dg,
|
||||
uint32_t backing_id,
|
||||
DisplayGLTextureBorrower backing_borrower,
|
||||
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_borrower(backing_id, &backing_y_0_top,
|
||||
&backing_width, &backing_height);
|
||||
if (backing_texture) {
|
||||
egl_scanout_imported_texture(dg, backing_texture, backing_y_0_top,
|
||||
backing_width, backing_height);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_GBM
|
||||
static void egl_scanout_dmabuf(void *dg, 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(dg, dmabuf->texture,
|
||||
false, dmabuf->width, dmabuf->height);
|
||||
}
|
||||
|
||||
static void egl_cursor_dmabuf(DisplayChangeListener *dcl,
|
||||
static void egl_cursor_dmabuf(void *dg,
|
||||
QemuDmaBuf *dmabuf, bool have_hot,
|
||||
uint32_t hot_x, uint32_t hot_y)
|
||||
{
|
||||
egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
|
||||
egl_dpy *edpy = dg;
|
||||
|
||||
if (dmabuf) {
|
||||
egl_dmabuf_import_texture(dmabuf);
|
||||
@@ -109,20 +136,20 @@ static void egl_cursor_dmabuf(DisplayChangeListener *dcl,
|
||||
}
|
||||
}
|
||||
|
||||
static void egl_cursor_position(DisplayChangeListener *dcl,
|
||||
static void egl_cursor_position(void *dg,
|
||||
uint32_t pos_x, uint32_t pos_y)
|
||||
{
|
||||
egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
|
||||
egl_dpy *edpy = dg;
|
||||
|
||||
edpy->pos_x = pos_x;
|
||||
edpy->pos_y = pos_y;
|
||||
}
|
||||
|
||||
static void egl_release_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf)
|
||||
static void egl_release_dmabuf(void *dg, QemuDmaBuf *dmabuf)
|
||||
{
|
||||
egl_dmabuf_release_texture(dmabuf);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void egl_scanout_flush(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y,
|
||||
@@ -151,22 +178,28 @@ static void egl_scanout_flush(DisplayChangeListener *dcl,
|
||||
dpy_gfx_update(edpy->dcl.con, x, y, w, h);
|
||||
}
|
||||
|
||||
static const DisplayChangeListenerOps egl_ops = {
|
||||
static const DisplayGLOps dg_egl_ops = {
|
||||
.dpy_gl_ctx_create = egl_create_context,
|
||||
.dpy_gl_ctx_destroy = qemu_egl_destroy_context,
|
||||
.dpy_gl_ctx_make_current = qemu_egl_make_context_current,
|
||||
|
||||
.dpy_gl_scanout_get_enabled = egl_scanout_get_enabled,
|
||||
.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
|
||||
};
|
||||
|
||||
static const DisplayChangeListenerOps dcl_egl_ops = {
|
||||
.dpy_name = "egl-headless",
|
||||
.dpy_refresh = egl_refresh,
|
||||
.dpy_gfx_update = egl_gfx_update,
|
||||
.dpy_gfx_switch = egl_gfx_switch,
|
||||
|
||||
.dpy_gl_ctx_create = egl_create_context,
|
||||
.dpy_gl_ctx_destroy = qemu_egl_destroy_context,
|
||||
.dpy_gl_ctx_make_current = qemu_egl_make_context_current,
|
||||
|
||||
.dpy_gl_scanout_disable = egl_scanout_disable,
|
||||
.dpy_gl_scanout_texture = egl_scanout_texture,
|
||||
.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,
|
||||
.dpy_gl_update = egl_scanout_flush,
|
||||
};
|
||||
|
||||
@@ -182,10 +215,25 @@ static void egl_headless_init(DisplayState *ds, DisplayOptions *opts)
|
||||
egl_dpy *edpy;
|
||||
int idx;
|
||||
|
||||
#ifdef CONFIG_GBM
|
||||
if (egl_rendernode_init(opts->u.egl_headless.rendernode, mode) < 0) {
|
||||
error_report("egl: render node init failed");
|
||||
exit(1);
|
||||
}
|
||||
#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
|
||||
|
||||
register_displayglops(&dg_egl_ops);
|
||||
|
||||
for (idx = 0;; idx++) {
|
||||
con = qemu_console_lookup_by_index(idx);
|
||||
@@ -195,8 +243,9 @@ static void egl_headless_init(DisplayState *ds, DisplayOptions *opts)
|
||||
|
||||
edpy = g_new0(egl_dpy, 1);
|
||||
edpy->dcl.con = con;
|
||||
edpy->dcl.ops = &egl_ops;
|
||||
edpy->dcl.ops = &dcl_egl_ops;
|
||||
edpy->gls = qemu_gl_init_shader();
|
||||
console_set_displayglcontext(con, edpy);
|
||||
register_displaychangelistener(&edpy->dcl);
|
||||
}
|
||||
}
|
||||
|
||||
+181
-73
@@ -58,14 +58,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);
|
||||
@@ -73,19 +74,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)
|
||||
@@ -115,7 +127,7 @@ void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, dst->framebuffer);
|
||||
glViewport(0, 0, dst->width, dst->height);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, src->texture);
|
||||
glBindTexture(src->texture_target, src->texture);
|
||||
qemu_gl_run_texture_blit(gls, flip);
|
||||
}
|
||||
|
||||
@@ -131,7 +143,7 @@ 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);
|
||||
@@ -291,7 +303,7 @@ void egl_dmabuf_release_texture(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;
|
||||
@@ -313,9 +325,118 @@ 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");
|
||||
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)
|
||||
{
|
||||
EGLint major, minor;
|
||||
EGLBoolean b;
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
|
||||
b = eglBindAPI(gles ? EGL_OPENGL_ES_API : EGL_OPENGL_API);
|
||||
if (b == EGL_FALSE) {
|
||||
error_report("egl: eglBindAPI failed (%s mode)",
|
||||
gles ? "gles" : "core");
|
||||
return -1;
|
||||
}
|
||||
|
||||
qemu_egl_mode = gles ? DISPLAYGL_MODE_ES : DISPLAYGL_MODE_CORE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qemu_egl_config_dpy()
|
||||
{
|
||||
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,
|
||||
};
|
||||
EGLBoolean b;
|
||||
EGLint n;
|
||||
bool gles = (qemu_egl_mode == DISPLAYGL_MODE_ES);
|
||||
|
||||
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)",
|
||||
gles ? "gles" : "core");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qemu_egl_init_dpy_cocoa(DisplayGLMode mode)
|
||||
{
|
||||
int result;
|
||||
|
||||
EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (dpy == EGL_NO_DISPLAY) {
|
||||
error_report("egl: eglGetDisplay failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = qemu_egl_init_dpy(dpy, mode);
|
||||
if (!result) {
|
||||
result = qemu_egl_config_dpy();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Taken from glamor_egl.h from the Xorg xserver, which is MIT licensed
|
||||
@@ -345,8 +466,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(void *native,
|
||||
EGLenum platform,
|
||||
DisplayGLMode mode)
|
||||
{
|
||||
EGLDisplay dpy = EGL_NO_DISPLAY;
|
||||
|
||||
@@ -359,88 +481,74 @@ 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
|
||||
|
||||
static int qemu_egl_init_dpy(EGLNativeDisplayType dpy,
|
||||
EGLenum platform,
|
||||
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) {
|
||||
if (dpy == EGL_NO_DISPLAY) {
|
||||
error_report("egl: eglGetDisplay failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
b = eglInitialize(qemu_egl_display, &major, &minor);
|
||||
if (b == EGL_FALSE) {
|
||||
error_report("egl: eglInitialize failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
b = eglBindAPI(gles ? EGL_OPENGL_ES_API : EGL_OPENGL_API);
|
||||
if (b == EGL_FALSE) {
|
||||
error_report("egl: eglBindAPI failed (%s mode)",
|
||||
gles ? "gles" : "core");
|
||||
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)",
|
||||
gles ? "gles" : "core");
|
||||
return -1;
|
||||
}
|
||||
|
||||
qemu_egl_mode = gles ? DISPLAYGL_MODE_ES : DISPLAYGL_MODE_CORE;
|
||||
return 0;
|
||||
return qemu_egl_init_dpy(dpy, mode);
|
||||
}
|
||||
|
||||
int qemu_egl_init_dpy_surfaceless(DisplayGLMode mode)
|
||||
{
|
||||
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)
|
||||
{
|
||||
int result;
|
||||
|
||||
#ifdef EGL_KHR_platform_x11
|
||||
return qemu_egl_init_dpy(dpy, EGL_PLATFORM_X11_KHR, mode);
|
||||
result = qemu_egl_init_dpy_platform(dpy, EGL_PLATFORM_X11_KHR, mode);
|
||||
#else
|
||||
return qemu_egl_init_dpy(dpy, 0, mode);
|
||||
result = qemu_egl_init_dpy_platform(dpy, 0, mode);
|
||||
#endif
|
||||
if (!result) {
|
||||
result = qemu_egl_config_dpy();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode)
|
||||
{
|
||||
int result;
|
||||
|
||||
#ifdef EGL_MESA_platform_gbm
|
||||
return qemu_egl_init_dpy(dpy, EGL_PLATFORM_GBM_MESA, mode);
|
||||
result = qemu_egl_init_dpy_platform(dpy, EGL_PLATFORM_GBM_MESA, mode);
|
||||
#else
|
||||
return qemu_egl_init_dpy(dpy, 0, mode);
|
||||
result = qemu_egl_init_dpy_platform(dpy, 0, mode);
|
||||
#endif
|
||||
if (!result) {
|
||||
result = qemu_egl_config_dpy();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ANGLE)
|
||||
|
||||
int qemu_egl_init_dpy_angle(DisplayGLMode mode)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = qemu_egl_init_dpy_platform(NULL, EGL_PLATFORM_ANGLE_ANGLE, mode);
|
||||
if (!result) {
|
||||
result = qemu_egl_config_dpy();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -462,7 +570,7 @@ EGLContext qemu_egl_init_ctx(void)
|
||||
EGL_NONE
|
||||
};
|
||||
static const EGLint ctx_att_gles[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||
EGL_NONE
|
||||
};
|
||||
bool gles = (qemu_egl_mode == DISPLAYGL_MODE_ES);
|
||||
|
||||
+49
-31
@@ -53,7 +53,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);
|
||||
@@ -116,8 +116,8 @@ void gd_egl_refresh(DisplayChangeListener *dcl)
|
||||
{
|
||||
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
||||
|
||||
vc->gfx.dcl.update_interval = gd_monitor_update_interval(
|
||||
vc->window ? vc->window : vc->gfx.drawing_area);
|
||||
gd_update_monitor_refresh_rate(
|
||||
vc, vc->window ? vc->window : vc->gfx.drawing_area);
|
||||
|
||||
if (!vc->gfx.esurface) {
|
||||
gd_egl_init(vc);
|
||||
@@ -164,33 +164,37 @@ void gd_egl_switch(DisplayChangeListener *dcl,
|
||||
}
|
||||
}
|
||||
|
||||
QEMUGLContext gd_egl_create_context(DisplayChangeListener *dcl,
|
||||
QEMUGLParams *params)
|
||||
QEMUGLContext gd_egl_create_context(void *dg, QEMUGLParams *params)
|
||||
{
|
||||
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
||||
VirtualConsole *vc = dg;
|
||||
|
||||
eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
|
||||
vc->gfx.esurface, vc->gfx.ectx);
|
||||
return qemu_egl_create_context(dcl, params);
|
||||
return qemu_egl_create_context(dg, params);
|
||||
}
|
||||
|
||||
void gd_egl_scanout_disable(DisplayChangeListener *dcl)
|
||||
bool gd_egl_scanout_get_enabled(void *dg)
|
||||
{
|
||||
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
||||
return ((VirtualConsole *)dg)->gfx.scanout_mode;
|
||||
}
|
||||
|
||||
void gd_egl_scanout_disable(void *dg)
|
||||
{
|
||||
VirtualConsole *vc = dg;
|
||||
|
||||
vc->gfx.w = 0;
|
||||
vc->gfx.h = 0;
|
||||
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;
|
||||
@@ -205,8 +209,25 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,
|
||||
backing_id, false);
|
||||
}
|
||||
|
||||
void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf)
|
||||
void gd_egl_scanout_texture(void *dg, 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);
|
||||
if (backing_texture) {
|
||||
gd_egl_scanout_borrowed_texture(dg, backing_texture, backing_y_0_top,
|
||||
backing_width, backing_height,
|
||||
x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
void gd_egl_scanout_dmabuf(void *dg, QemuDmaBuf *dmabuf)
|
||||
{
|
||||
#ifdef CONFIG_GBM
|
||||
egl_dmabuf_import_texture(dmabuf);
|
||||
@@ -214,18 +235,18 @@ 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(dg, dmabuf->texture,
|
||||
false, dmabuf->width, dmabuf->height,
|
||||
0, 0, dmabuf->width, dmabuf->height);
|
||||
#endif
|
||||
}
|
||||
|
||||
void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl,
|
||||
void gd_egl_cursor_dmabuf(void *dg,
|
||||
QemuDmaBuf *dmabuf, bool have_hot,
|
||||
uint32_t hot_x, uint32_t hot_y)
|
||||
{
|
||||
#ifdef CONFIG_GBM
|
||||
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
||||
VirtualConsole *vc = dg;
|
||||
|
||||
if (dmabuf) {
|
||||
egl_dmabuf_import_texture(dmabuf);
|
||||
@@ -240,17 +261,15 @@ void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl,
|
||||
#endif
|
||||
}
|
||||
|
||||
void gd_egl_cursor_position(DisplayChangeListener *dcl,
|
||||
uint32_t pos_x, uint32_t pos_y)
|
||||
void gd_egl_cursor_position(void *dg, uint32_t pos_x, uint32_t pos_y)
|
||||
{
|
||||
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
||||
VirtualConsole *vc = dg;
|
||||
|
||||
vc->gfx.cursor_x = pos_x * vc->gfx.scale_x;
|
||||
vc->gfx.cursor_y = pos_y * vc->gfx.scale_y;
|
||||
}
|
||||
|
||||
void gd_egl_release_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf)
|
||||
void gd_egl_release_dmabuf(void *dg, QemuDmaBuf *dmabuf)
|
||||
{
|
||||
#ifdef CONFIG_GBM
|
||||
egl_dmabuf_release_texture(dmabuf);
|
||||
@@ -304,10 +323,9 @@ void gtk_egl_init(DisplayGLMode mode)
|
||||
display_opengl = 1;
|
||||
}
|
||||
|
||||
int gd_egl_make_current(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx)
|
||||
int gd_egl_make_current(void *dg, QEMUGLContext ctx)
|
||||
{
|
||||
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
||||
VirtualConsole *vc = dg;
|
||||
|
||||
return eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
|
||||
vc->gfx.esurface, ctx);
|
||||
|
||||
+41
-23
@@ -139,10 +139,9 @@ void gd_gl_area_switch(DisplayChangeListener *dcl,
|
||||
}
|
||||
}
|
||||
|
||||
QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
|
||||
QEMUGLParams *params)
|
||||
QEMUGLContext gd_gl_area_create_context(void *dg, QEMUGLParams *params)
|
||||
{
|
||||
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
||||
VirtualConsole *vc = dg;
|
||||
GdkWindow *window;
|
||||
GdkGLContext *ctx;
|
||||
GError *err = NULL;
|
||||
@@ -168,21 +167,24 @@ QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void gd_gl_area_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx)
|
||||
void gd_gl_area_destroy_context(void *dg, QEMUGLContext ctx)
|
||||
{
|
||||
/* FIXME */
|
||||
}
|
||||
|
||||
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)
|
||||
bool gd_gl_area_scanout_get_enabled(void *dg)
|
||||
{
|
||||
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
||||
return ((VirtualConsole *)dg)->gfx.scanout_mode;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
vc->gfx.x = x;
|
||||
vc->gfx.y = y;
|
||||
vc->gfx.w = w;
|
||||
@@ -201,11 +203,29 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
|
||||
backing_id, false);
|
||||
}
|
||||
|
||||
void gd_gl_area_scanout_disable(DisplayChangeListener *dcl)
|
||||
void gd_gl_area_scanout_texture(void *dg,
|
||||
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;
|
||||
|
||||
gtk_gl_area_set_scanout_mode(vc, false);
|
||||
GLuint backing_texture = backing_borrow(backing_id, &backing_y_0_top,
|
||||
&backing_width, &backing_height);
|
||||
if (backing_texture) {
|
||||
gd_gl_area_scanout_borrowed_texture(dg, backing_texture,
|
||||
backing_y_0_top,
|
||||
backing_width, backing_height,
|
||||
x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
void gd_gl_area_scanout_disable(void *dg)
|
||||
{
|
||||
gtk_gl_area_set_scanout_mode(dg, false);
|
||||
}
|
||||
|
||||
void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
|
||||
@@ -216,11 +236,10 @@ void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
|
||||
gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
|
||||
}
|
||||
|
||||
void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf)
|
||||
void gd_gl_area_scanout_dmabuf(void *dg, QemuDmaBuf *dmabuf)
|
||||
{
|
||||
#ifdef CONFIG_GBM
|
||||
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
||||
VirtualConsole *vc = dg;
|
||||
|
||||
gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
|
||||
egl_dmabuf_import_texture(dmabuf);
|
||||
@@ -228,9 +247,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(dg, dmabuf->texture,
|
||||
false, dmabuf->width, dmabuf->height,
|
||||
0, 0, dmabuf->width, dmabuf->height);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -239,8 +258,7 @@ void gtk_gl_area_init(void)
|
||||
display_opengl = 1;
|
||||
}
|
||||
|
||||
int gd_gl_area_make_current(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx)
|
||||
int gd_gl_area_make_current(void *dg, QEMUGLContext ctx)
|
||||
{
|
||||
gdk_gl_context_make_current(ctx);
|
||||
return 0;
|
||||
|
||||
@@ -341,7 +341,7 @@ static void gd_update_full_redraw(VirtualConsole *vc)
|
||||
int ww, wh;
|
||||
ww = gdk_window_get_width(gtk_widget_get_window(area));
|
||||
wh = gdk_window_get_height(gtk_widget_get_window(area));
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
if (vc->gfx.gls && gtk_use_gl_area) {
|
||||
gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
|
||||
return;
|
||||
@@ -560,11 +560,11 @@ static const DisplayChangeListenerOps dcl_ops = {
|
||||
};
|
||||
|
||||
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
|
||||
static bool gd_has_dmabuf(DisplayChangeListener *dcl)
|
||||
static bool gd_has_dmabuf(void *dg)
|
||||
{
|
||||
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
|
||||
VirtualConsole *vc = dg;
|
||||
|
||||
if (gtk_use_gl_area && !gtk_widget_get_realized(vc->gfx.drawing_area)) {
|
||||
/* FIXME: Assume it will work, actual check done after realize */
|
||||
@@ -577,6 +577,17 @@ static bool gd_has_dmabuf(DisplayChangeListener *dcl)
|
||||
|
||||
/** DisplayState Callbacks (opengl version) **/
|
||||
|
||||
static const DisplayGLOps dg_gl_area_ops = {
|
||||
.dpy_gl_ctx_create = gd_gl_area_create_context,
|
||||
.dpy_gl_ctx_destroy = gd_gl_area_destroy_context,
|
||||
.dpy_gl_ctx_make_current = gd_gl_area_make_current,
|
||||
.dpy_gl_scanout_get_enabled = gd_gl_area_scanout_get_enabled,
|
||||
.dpy_gl_scanout_texture = gd_gl_area_scanout_texture,
|
||||
.dpy_gl_scanout_disable = gd_gl_area_scanout_disable,
|
||||
.dpy_gl_scanout_dmabuf = gd_gl_area_scanout_dmabuf,
|
||||
.dpy_has_dmabuf = gd_has_dmabuf,
|
||||
};
|
||||
|
||||
static const DisplayChangeListenerOps dcl_gl_area_ops = {
|
||||
.dpy_name = "gtk-egl",
|
||||
.dpy_gfx_update = gd_gl_area_update,
|
||||
@@ -586,14 +597,7 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = {
|
||||
.dpy_mouse_set = gd_mouse_set,
|
||||
.dpy_cursor_define = gd_cursor_define,
|
||||
|
||||
.dpy_gl_ctx_create = gd_gl_area_create_context,
|
||||
.dpy_gl_ctx_destroy = gd_gl_area_destroy_context,
|
||||
.dpy_gl_ctx_make_current = gd_gl_area_make_current,
|
||||
.dpy_gl_scanout_texture = gd_gl_area_scanout_texture,
|
||||
.dpy_gl_scanout_disable = gd_gl_area_scanout_disable,
|
||||
.dpy_gl_update = gd_gl_area_scanout_flush,
|
||||
.dpy_gl_scanout_dmabuf = gd_gl_area_scanout_dmabuf,
|
||||
.dpy_has_dmabuf = gd_has_dmabuf,
|
||||
.dpy_gl_update = gd_gl_area_scanout_flush,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_X11
|
||||
@@ -607,6 +611,10 @@ static const DisplayChangeListenerOps dcl_egl_ops = {
|
||||
.dpy_mouse_set = gd_mouse_set,
|
||||
.dpy_cursor_define = gd_cursor_define,
|
||||
|
||||
.dpy_gl_update = gd_egl_scanout_flush,
|
||||
};
|
||||
|
||||
static const DisplayGLOps dg_egl_ops = {
|
||||
.dpy_gl_ctx_create = gd_egl_create_context,
|
||||
.dpy_gl_ctx_destroy = qemu_egl_destroy_context,
|
||||
.dpy_gl_ctx_make_current = gd_egl_make_current,
|
||||
@@ -616,13 +624,12 @@ static const DisplayChangeListenerOps dcl_egl_ops = {
|
||||
.dpy_gl_cursor_dmabuf = gd_egl_cursor_dmabuf,
|
||||
.dpy_gl_cursor_position = gd_egl_cursor_position,
|
||||
.dpy_gl_release_dmabuf = gd_egl_release_dmabuf,
|
||||
.dpy_gl_update = gd_egl_scanout_flush,
|
||||
.dpy_has_dmabuf = gd_has_dmabuf,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_OPENGL */
|
||||
#endif /* defined(CONFIG_OPENGL) && defined(CONFIG_EGL) */
|
||||
|
||||
/** QEMU Events **/
|
||||
|
||||
@@ -669,17 +676,26 @@ static gboolean gd_window_close(GtkWidget *widget, GdkEvent *event,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void gd_set_ui_info(VirtualConsole *vc, gint width, gint height)
|
||||
static void gd_set_ui_refresh_rate(VirtualConsole *vc, int refresh_rate)
|
||||
{
|
||||
QemuUIInfo info;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
info = *dpy_get_ui_info(vc->gfx.dcl.con);
|
||||
info.refresh_rate = refresh_rate;
|
||||
dpy_set_ui_info(vc->gfx.dcl.con, &info);
|
||||
}
|
||||
|
||||
static void gd_set_ui_size(VirtualConsole *vc, gint width, gint height)
|
||||
{
|
||||
QemuUIInfo info;
|
||||
|
||||
info = *dpy_get_ui_info(vc->gfx.dcl.con);
|
||||
info.width = width;
|
||||
info.height = height;
|
||||
dpy_set_ui_info(vc->gfx.dcl.con, &info);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
|
||||
static gboolean gd_render_event(GtkGLArea *area, GdkGLContext *context,
|
||||
void *opaque)
|
||||
@@ -697,33 +713,32 @@ static void gd_resize_event(GtkGLArea *area,
|
||||
{
|
||||
VirtualConsole *vc = (void *)opaque;
|
||||
|
||||
gd_set_ui_info(vc, width, height);
|
||||
gd_set_ui_size(vc, width, height);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If available, return the update interval of the monitor in ms,
|
||||
* else return 0 (the default update interval).
|
||||
*/
|
||||
int gd_monitor_update_interval(GtkWidget *widget)
|
||||
void gd_update_monitor_refresh_rate(VirtualConsole *vc, GtkWidget *widget)
|
||||
{
|
||||
#ifdef GDK_VERSION_3_22
|
||||
GdkWindow *win = gtk_widget_get_window(widget);
|
||||
int refresh_rate;
|
||||
|
||||
if (win) {
|
||||
GdkDisplay *dpy = gtk_widget_get_display(widget);
|
||||
GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
|
||||
int refresh_rate = gdk_monitor_get_refresh_rate(monitor); /* [mHz] */
|
||||
|
||||
if (refresh_rate) {
|
||||
/* T = 1 / f = 1 [s*Hz] / f = 1000*1000 [ms*mHz] / f */
|
||||
return MIN(1000 * 1000 / refresh_rate,
|
||||
GUI_REFRESH_INTERVAL_DEFAULT);
|
||||
}
|
||||
refresh_rate = gdk_monitor_get_refresh_rate(monitor); /* [mHz] */
|
||||
} else {
|
||||
refresh_rate = 0;
|
||||
}
|
||||
|
||||
gd_set_ui_refresh_rate(vc, refresh_rate);
|
||||
|
||||
/* T = 1 / f = 1 [s*Hz] / f = 1000*1000 [ms*mHz] / f */
|
||||
vc->gfx.dcl.update_interval = refresh_rate ?
|
||||
MIN(1000 * 1000 / refresh_rate, GUI_REFRESH_INTERVAL_DEFAULT) :
|
||||
GUI_REFRESH_INTERVAL_DEFAULT;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
|
||||
@@ -734,7 +749,7 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
|
||||
int ww, wh;
|
||||
int fbw, fbh;
|
||||
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
if (vc->gfx.gls) {
|
||||
if (gtk_use_gl_area) {
|
||||
/* invoke render callback please */
|
||||
@@ -757,8 +772,7 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
vc->gfx.dcl.update_interval =
|
||||
gd_monitor_update_interval(vc->window ? vc->window : s->window);
|
||||
gd_update_monitor_refresh_rate(vc, vc->window ? vc->window : s->window);
|
||||
|
||||
fbw = surface_width(vc->gfx.ds);
|
||||
fbh = surface_height(vc->gfx.ds);
|
||||
@@ -1590,7 +1604,7 @@ static gboolean gd_configure(GtkWidget *widget,
|
||||
{
|
||||
VirtualConsole *vc = opaque;
|
||||
|
||||
gd_set_ui_info(vc, cfg->width, cfg->height);
|
||||
gd_set_ui_size(vc, cfg->width, cfg->height);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -1843,7 +1857,7 @@ static void gd_connect_vc_gfx_signals(VirtualConsole *vc)
|
||||
{
|
||||
g_signal_connect(vc->gfx.drawing_area, "draw",
|
||||
G_CALLBACK(gd_draw_event), vc);
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
if (gtk_use_gl_area) {
|
||||
/* wire up GtkGlArea events */
|
||||
g_signal_connect(vc->gfx.drawing_area, "render",
|
||||
@@ -1957,7 +1971,7 @@ static GtkWidget *gd_create_menu_machine(GtkDisplayState *s)
|
||||
return machine_menu;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
static void gl_area_realize(GtkGLArea *area, VirtualConsole *vc)
|
||||
{
|
||||
gtk_gl_area_make_current(area);
|
||||
@@ -1980,7 +1994,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
|
||||
vc->gfx.scale_x = 1.0;
|
||||
vc->gfx.scale_y = 1.0;
|
||||
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
if (display_opengl) {
|
||||
if (gtk_use_gl_area) {
|
||||
vc->gfx.drawing_area = gtk_gl_area_new();
|
||||
@@ -2035,6 +2049,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
|
||||
vc->gfx.kbd = qkbd_state_init(con);
|
||||
vc->gfx.dcl.con = con;
|
||||
|
||||
console_set_displayglcontext(con, vc);
|
||||
register_displaychangelistener(&vc->gfx.dcl);
|
||||
|
||||
gd_connect_vc_gfx_signals(vc);
|
||||
@@ -2124,6 +2139,18 @@ static GtkWidget *gd_create_menu_view(GtkDisplayState *s)
|
||||
separator = gtk_separator_menu_item_new();
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
|
||||
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
if (display_opengl) {
|
||||
if (gtk_use_gl_area) {
|
||||
register_displayglops(&dg_gl_area_ops);
|
||||
} else {
|
||||
#ifdef CONFIG_X11
|
||||
register_displayglops(&dg_egl_ops);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* gfx */
|
||||
for (vc = 0;; vc++) {
|
||||
con = qemu_console_lookup_by_index(vc);
|
||||
@@ -2308,7 +2335,7 @@ static void early_gtk_display_init(DisplayOptions *opts)
|
||||
|
||||
assert(opts->type == DISPLAY_TYPE_GTK);
|
||||
if (opts->has_gl && opts->gl != DISPLAYGL_MODE_OFF) {
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
#if defined(GDK_WINDOWING_WAYLAND)
|
||||
if (GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default())) {
|
||||
gtk_use_gl_area = true;
|
||||
@@ -2344,6 +2371,6 @@ static void register_gtk(void)
|
||||
|
||||
type_init(register_gtk);
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
module_dep("ui-opengl");
|
||||
#endif
|
||||
+16
-7
@@ -18,7 +18,9 @@ softmmu_ss.add([spice_headers, files('spice-module.c')])
|
||||
softmmu_ss.add(when: spice_protocol, if_true: files('vdagent.c'))
|
||||
|
||||
softmmu_ss.add(when: 'CONFIG_LINUX', if_true: files('input-linux.c'))
|
||||
softmmu_ss.add(when: cocoa, if_true: files('cocoa.m'))
|
||||
softmmu_ss.add(when: cocoa,
|
||||
if_true: files('cocoa/main.m', 'cocoa/pasteboard_type_owner.m',
|
||||
'cocoa/view.m', 'cocoa/app_controller.m'))
|
||||
|
||||
vnc_ss = ss.source_set()
|
||||
vnc_ss.add(files(
|
||||
@@ -51,13 +53,15 @@ if config_host.has_key('CONFIG_OPENGL')
|
||||
opengl_ss = ss.source_set()
|
||||
opengl_ss.add(gbm)
|
||||
opengl_ss.add(when: [opengl, pixman, 'CONFIG_OPENGL'],
|
||||
if_true: files('shader.c', 'console-gl.c', 'egl-helpers.c', 'egl-context.c'))
|
||||
if_true: files('shader.c', 'console-gl.c'))
|
||||
opengl_ss.add(when: [opengl, pixman, 'CONFIG_OPENGL', 'CONFIG_EGL'],
|
||||
if_true: files('egl-helpers.c', 'egl-context.c'))
|
||||
ui_modules += {'opengl' : opengl_ss}
|
||||
endif
|
||||
|
||||
if config_host.has_key('CONFIG_OPENGL') and gbm.found()
|
||||
if config_host.has_key('CONFIG_OPENGL')
|
||||
egl_headless_ss = ss.source_set()
|
||||
egl_headless_ss.add(when: [opengl, gbm, pixman, 'CONFIG_OPENGL'],
|
||||
egl_headless_ss.add(when: [opengl, pixman, 'CONFIG_OPENGL', 'CONFIG_EGL'],
|
||||
if_true: files('egl-headless.c'))
|
||||
ui_modules += {'egl-headless' : egl_headless_ss}
|
||||
endif
|
||||
@@ -68,8 +72,10 @@ if gtk.found()
|
||||
gtk_ss = ss.source_set()
|
||||
gtk_ss.add(gtk, vte, pixman, files('gtk.c', 'gtk-clipboard.c'))
|
||||
gtk_ss.add(when: x11, if_true: files('x_keymap.c'))
|
||||
gtk_ss.add(when: [opengl, 'CONFIG_OPENGL'], if_true: files('gtk-gl-area.c'))
|
||||
gtk_ss.add(when: [x11, opengl, 'CONFIG_OPENGL'], if_true: files('gtk-egl.c'))
|
||||
gtk_ss.add(when: [opengl, 'CONFIG_OPENGL', 'CONFIG_EGL'],
|
||||
if_true: files('gtk-gl-area.c'))
|
||||
gtk_ss.add(when: [x11, opengl, 'CONFIG_OPENGL', 'CONFIG_EGL'],
|
||||
if_true: files('gtk-egl.c'))
|
||||
ui_modules += {'gtk' : gtk_ss}
|
||||
endif
|
||||
|
||||
@@ -82,7 +88,7 @@ if sdl.found()
|
||||
'sdl2-input.c',
|
||||
'sdl2.c',
|
||||
))
|
||||
sdl_ss.add(when: [opengl, 'CONFIG_OPENGL'], if_true: files('sdl2-gl.c'))
|
||||
sdl_ss.add(when: [opengl, 'CONFIG_OPENGL', 'CONFIG_EGL'], if_true: files('sdl2-gl.c'))
|
||||
sdl_ss.add(when: x11, if_true: files('x_keymap.c'))
|
||||
ui_modules += {'sdl' : sdl_ss}
|
||||
endif
|
||||
@@ -94,6 +100,9 @@ if config_host.has_key('CONFIG_SPICE')
|
||||
'spice-input.c',
|
||||
'spice-display.c'
|
||||
))
|
||||
if iosurface.found()
|
||||
spice_core_ss.add(iosurface)
|
||||
endif
|
||||
ui_modules += {'spice-core' : spice_core_ss}
|
||||
endif
|
||||
|
||||
|
||||
+26
-15
@@ -133,10 +133,9 @@ void sdl2_gl_redraw(struct sdl2_console *scon)
|
||||
}
|
||||
}
|
||||
|
||||
QEMUGLContext sdl2_gl_create_context(DisplayChangeListener *dcl,
|
||||
QEMUGLParams *params)
|
||||
QEMUGLContext sdl2_gl_create_context(void *dg, QEMUGLParams *params)
|
||||
{
|
||||
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||
struct sdl2_console *scon = dg;
|
||||
SDL_GLContext ctx;
|
||||
|
||||
assert(scon->opengl);
|
||||
@@ -168,17 +167,16 @@ QEMUGLContext sdl2_gl_create_context(DisplayChangeListener *dcl,
|
||||
return (QEMUGLContext)ctx;
|
||||
}
|
||||
|
||||
void sdl2_gl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx)
|
||||
void sdl2_gl_destroy_context(void *dg, QEMUGLContext ctx)
|
||||
{
|
||||
SDL_GLContext sdlctx = (SDL_GLContext)ctx;
|
||||
|
||||
SDL_GL_DeleteContext(sdlctx);
|
||||
}
|
||||
|
||||
int sdl2_gl_make_context_current(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx)
|
||||
int sdl2_gl_make_context_current(void *dg, QEMUGLContext ctx)
|
||||
{
|
||||
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||
struct sdl2_console *scon = dg;
|
||||
SDL_GLContext sdlctx = (SDL_GLContext)ctx;
|
||||
|
||||
assert(scon->opengl);
|
||||
@@ -186,9 +184,9 @@ int sdl2_gl_make_context_current(DisplayChangeListener *dcl,
|
||||
return SDL_GL_MakeCurrent(scon->real_window, sdlctx);
|
||||
}
|
||||
|
||||
void sdl2_gl_scanout_disable(DisplayChangeListener *dcl)
|
||||
void sdl2_gl_scanout_disable(void *dg)
|
||||
{
|
||||
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||
struct sdl2_console *scon = dg;
|
||||
|
||||
assert(scon->opengl);
|
||||
scon->w = 0;
|
||||
@@ -196,17 +194,30 @@ void sdl2_gl_scanout_disable(DisplayChangeListener *dcl)
|
||||
sdl2_set_scanout_mode(scon, false);
|
||||
}
|
||||
|
||||
void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
|
||||
bool sdl2_gl_scanout_get_enabled(void *dg)
|
||||
{
|
||||
return ((struct sdl2_console *)dg)->scanout_mode;
|
||||
}
|
||||
|
||||
void sdl2_gl_scanout_texture(void *dg,
|
||||
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);
|
||||
struct sdl2_console *scon = dg;
|
||||
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);
|
||||
if (!backing_texture) {
|
||||
return;
|
||||
}
|
||||
|
||||
scon->x = x;
|
||||
scon->y = y;
|
||||
scon->w = w;
|
||||
@@ -217,7 +228,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,
|
||||
|
||||
@@ -85,7 +85,7 @@ void sdl2_window_create(struct sdl2_console *scon)
|
||||
if (scon->hidden) {
|
||||
flags |= SDL_WINDOW_HIDDEN;
|
||||
}
|
||||
#ifdef CONFIG_OPENGL
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
if (scon->opengl) {
|
||||
flags |= SDL_WINDOW_OPENGL;
|
||||
}
|
||||
@@ -129,7 +129,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) && defined(CONFIG_EGL)
|
||||
sdl2_gl_redraw(scon);
|
||||
#endif
|
||||
} else {
|
||||
@@ -768,7 +768,16 @@ static const DisplayChangeListenerOps dcl_2d_ops = {
|
||||
.dpy_cursor_define = sdl_mouse_define,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
static const DisplayGLOps dg_gl_ops = {
|
||||
.dpy_gl_ctx_create = sdl2_gl_create_context,
|
||||
.dpy_gl_ctx_destroy = sdl2_gl_destroy_context,
|
||||
.dpy_gl_ctx_make_current = sdl2_gl_make_context_current,
|
||||
.dpy_gl_scanout_get_enabled = sdl2_gl_scanout_get_enabled,
|
||||
.dpy_gl_scanout_disable = sdl2_gl_scanout_disable,
|
||||
.dpy_gl_scanout_texture = sdl2_gl_scanout_texture,
|
||||
};
|
||||
|
||||
static const DisplayChangeListenerOps dcl_gl_ops = {
|
||||
.dpy_name = "sdl2-gl",
|
||||
.dpy_gfx_update = sdl2_gl_update,
|
||||
@@ -778,11 +787,6 @@ static const DisplayChangeListenerOps dcl_gl_ops = {
|
||||
.dpy_mouse_set = sdl_mouse_warp,
|
||||
.dpy_cursor_define = sdl_mouse_define,
|
||||
|
||||
.dpy_gl_ctx_create = sdl2_gl_create_context,
|
||||
.dpy_gl_ctx_destroy = sdl2_gl_destroy_context,
|
||||
.dpy_gl_ctx_make_current = sdl2_gl_make_context_current,
|
||||
.dpy_gl_scanout_disable = sdl2_gl_scanout_disable,
|
||||
.dpy_gl_scanout_texture = sdl2_gl_scanout_texture,
|
||||
.dpy_gl_update = sdl2_gl_scanout_flush,
|
||||
};
|
||||
#endif
|
||||
@@ -791,7 +795,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) && defined(CONFIG_EGL)
|
||||
display_opengl = 1;
|
||||
#endif
|
||||
}
|
||||
@@ -837,6 +841,12 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
|
||||
|
||||
gui_fullscreen = o->has_full_screen && o->full_screen;
|
||||
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
if (display_opengl) {
|
||||
register_displayglops(&dg_gl_ops);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0;; i++) {
|
||||
QemuConsole *con = qemu_console_lookup_by_index(i);
|
||||
if (!con) {
|
||||
@@ -857,7 +867,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) && defined(CONFIG_EGL)
|
||||
sdl2_console[i].opengl = display_opengl;
|
||||
sdl2_console[i].dcl.ops = display_opengl ? &dcl_gl_ops : &dcl_2d_ops;
|
||||
#else
|
||||
@@ -866,6 +876,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
|
||||
#endif
|
||||
sdl2_console[i].dcl.con = con;
|
||||
sdl2_console[i].kbd = qkbd_state_init(con);
|
||||
console_set_displayglcontext(con, sdl2_console + i);
|
||||
register_displaychangelistener(&sdl2_console[i].dcl);
|
||||
|
||||
#if defined(SDL_VIDEO_DRIVER_WINDOWS) || defined(SDL_VIDEO_DRIVER_X11)
|
||||
@@ -922,6 +933,6 @@ static void register_sdl1(void)
|
||||
|
||||
type_init(register_sdl1);
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_EGL)
|
||||
module_dep("ui-opengl");
|
||||
#endif
|
||||
+10
-2
@@ -150,11 +150,19 @@ static GLuint qemu_gl_create_compile_link_program(const GLchar *vert_src,
|
||||
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);
|
||||
(vert_src, frag_src);
|
||||
if (!gls->texture_blit_prog || !gls->texture_blit_flip_prog) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
|
||||
#version 300 es
|
||||
|
||||
in vec2 in_position;
|
||||
out vec2 ex_tex_coord;
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
|
||||
#version 300 es
|
||||
|
||||
uniform sampler2D image;
|
||||
in mediump vec2 ex_tex_coord;
|
||||
out mediump vec4 out_frag_color;
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
|
||||
#version 300 es
|
||||
|
||||
in vec2 in_position;
|
||||
out vec2 ex_tex_coord;
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
@@ -845,11 +849,27 @@ static void qemu_spice_init(void)
|
||||
"incompatible with -spice port/tls-port");
|
||||
exit(1);
|
||||
}
|
||||
#if defined(CONFIG_GBM)
|
||||
if (egl_rendernode_init(qemu_opt_get(opts, "rendernode"),
|
||||
DISPLAYGL_MODE_ON) != 0) {
|
||||
error_report("Failed to initialize EGL render node for SPICE GL");
|
||||
exit(1);
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
||||
+283
-31
@@ -24,11 +24,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;
|
||||
@@ -788,6 +799,165 @@ 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");
|
||||
return 0;
|
||||
}
|
||||
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");
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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)
|
||||
egl_fb_destroy(&ssd->iosurface_fb);
|
||||
qemu_egl_destroy_surface(ssd->esurface);
|
||||
ssd->esurface = EGL_NO_SURFACE;
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
*fourcc = 'BGRA';
|
||||
surfaceid = IOSurfaceGetID(ssd->iosurface);
|
||||
write(fds[1], &surfaceid, sizeof(surfaceid));
|
||||
close(fds[1]);
|
||||
return fds[0];
|
||||
}
|
||||
|
||||
static void spice_iosurface_blit(SimpleSpiceDisplay *ssd, GLuint src_texture, bool flip)
|
||||
{
|
||||
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);
|
||||
glBindTexture(ssd->iosurface_fb.texture_target, ssd->iosurface_fb.texture);
|
||||
eglBindTexImage(qemu_egl_display, ssd->esurface, EGL_BACK_BUFFER);
|
||||
egl_texture_blit(ssd->gls, &ssd->iosurface_fb, &tmp_fb, flip);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void spice_iosurface_flush(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);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void qemu_spice_gl_monitor_config(SimpleSpiceDisplay *ssd,
|
||||
int x, int y, int w, int h)
|
||||
{
|
||||
@@ -850,6 +1020,9 @@ static void spice_gl_refresh(DisplayChangeListener *dcl)
|
||||
graphic_hw_update(dcl->con);
|
||||
if (ssd->gl_updates && ssd->have_surface) {
|
||||
qemu_spice_gl_block(ssd, true);
|
||||
#if defined(CONFIG_IOSURFACE)
|
||||
spice_iosurface_flush(ssd);
|
||||
#endif
|
||||
glFlush();
|
||||
cookie = (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_GL_DRAW_DONE, 0);
|
||||
spice_qxl_gl_draw_async(&ssd->qxl, 0, 0,
|
||||
@@ -866,6 +1039,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);
|
||||
}
|
||||
#endif
|
||||
ssd->gl_updates++;
|
||||
}
|
||||
|
||||
@@ -873,15 +1051,23 @@ 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) {
|
||||
#if defined(CONFIG_IOSURFACE)
|
||||
// need to release texture from surface before destorying it
|
||||
spice_iosurface_flush(ssd);
|
||||
#endif
|
||||
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);
|
||||
@@ -889,59 +1075,101 @@ 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(DisplayChangeListener *dcl,
|
||||
static QEMUGLContext qemu_spice_gl_create_context(void *dg,
|
||||
QEMUGLParams *params)
|
||||
{
|
||||
#if defined(CONFIG_GBM)
|
||||
eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||
qemu_egl_rn_ctx);
|
||||
return qemu_egl_create_context(dcl, params);
|
||||
#elif defined(CONFIG_ANGLE)
|
||||
eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||
spice_gl_ctx);
|
||||
#endif
|
||||
return qemu_egl_create_context(dg, params);
|
||||
}
|
||||
|
||||
static void qemu_spice_gl_scanout_disable(DisplayChangeListener *dcl)
|
||||
static void qemu_spice_gl_scanout_disable(void *dg)
|
||||
{
|
||||
SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
|
||||
SimpleSpiceDisplay *ssd = dg;
|
||||
|
||||
trace_qemu_spice_gl_scanout_disable(ssd->qxl.id);
|
||||
spice_qxl_gl_scanout(&ssd->qxl, -1, 0, 0, 0, 0, false);
|
||||
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,
|
||||
static void qemu_spice_gl_scanout_texture(void *dg,
|
||||
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);
|
||||
SimpleSpiceDisplay *ssd = dg;
|
||||
EGLint stride = 0, fourcc = 0;
|
||||
int fd = -1;
|
||||
bool y_0_top;
|
||||
uint32_t backing_width;
|
||||
uint32_t backing_height;
|
||||
|
||||
assert(tex_id);
|
||||
GLuint tex_id = backing_borrow(backing_id, &y_0_top,
|
||||
&backing_width, &backing_height);
|
||||
if (!tex_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
#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;
|
||||
@@ -956,10 +1184,10 @@ static void qemu_spice_gl_scanout_texture(DisplayChangeListener *dcl,
|
||||
ssd->have_scanout = true;
|
||||
}
|
||||
|
||||
static void qemu_spice_gl_scanout_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf)
|
||||
#ifdef CONFIG_GBM
|
||||
static void qemu_spice_gl_scanout_dmabuf(void *dg, QemuDmaBuf *dmabuf)
|
||||
{
|
||||
SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
|
||||
SimpleSpiceDisplay *ssd = dg;
|
||||
|
||||
ssd->guest_dmabuf = dmabuf;
|
||||
ssd->guest_dmabuf_refresh = true;
|
||||
@@ -968,11 +1196,11 @@ static void qemu_spice_gl_scanout_dmabuf(DisplayChangeListener *dcl,
|
||||
ssd->have_scanout = true;
|
||||
}
|
||||
|
||||
static void qemu_spice_gl_cursor_dmabuf(DisplayChangeListener *dcl,
|
||||
static void qemu_spice_gl_cursor_dmabuf(void *dg,
|
||||
QemuDmaBuf *dmabuf, bool have_hot,
|
||||
uint32_t hot_x, uint32_t hot_y)
|
||||
{
|
||||
SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
|
||||
SimpleSpiceDisplay *ssd = dg;
|
||||
|
||||
ssd->have_hot = have_hot;
|
||||
ssd->hot_x = hot_x;
|
||||
@@ -991,10 +1219,10 @@ static void qemu_spice_gl_cursor_dmabuf(DisplayChangeListener *dcl,
|
||||
}
|
||||
}
|
||||
|
||||
static void qemu_spice_gl_cursor_position(DisplayChangeListener *dcl,
|
||||
static void qemu_spice_gl_cursor_position(void *dg,
|
||||
uint32_t pos_x, uint32_t pos_y)
|
||||
{
|
||||
SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
|
||||
SimpleSpiceDisplay *ssd = dg;
|
||||
|
||||
qemu_mutex_lock(&ssd->lock);
|
||||
ssd->ptr_x = pos_x;
|
||||
@@ -1002,10 +1230,9 @@ static void qemu_spice_gl_cursor_position(DisplayChangeListener *dcl,
|
||||
qemu_mutex_unlock(&ssd->lock);
|
||||
}
|
||||
|
||||
static void qemu_spice_gl_release_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf)
|
||||
static void qemu_spice_gl_release_dmabuf(void *dg, QemuDmaBuf *dmabuf)
|
||||
{
|
||||
SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
|
||||
SimpleSpiceDisplay *ssd = dg;
|
||||
|
||||
if (ssd->guest_dmabuf == dmabuf) {
|
||||
ssd->guest_dmabuf = NULL;
|
||||
@@ -1013,21 +1240,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;
|
||||
}
|
||||
@@ -1089,6 +1320,13 @@ static void qemu_spice_gl_update(DisplayChangeListener *dcl,
|
||||
!y_0_top, 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);
|
||||
spice_iosurface_flush(ssd);
|
||||
//TODO: cursor stuff
|
||||
#endif
|
||||
|
||||
trace_qemu_spice_gl_update(ssd->qxl.id, w, h, x, y);
|
||||
qemu_spice_gl_block(ssd, true);
|
||||
@@ -1105,18 +1343,22 @@ static const DisplayChangeListenerOps display_listener_gl_ops = {
|
||||
.dpy_refresh = spice_gl_refresh,
|
||||
.dpy_mouse_set = display_mouse_set,
|
||||
.dpy_cursor_define = display_mouse_define,
|
||||
.dpy_gl_update = qemu_spice_gl_update,
|
||||
};
|
||||
|
||||
static const DisplayGLOps display_gl_ops = {
|
||||
.dpy_gl_ctx_create = qemu_spice_gl_create_context,
|
||||
.dpy_gl_ctx_destroy = qemu_egl_destroy_context,
|
||||
.dpy_gl_ctx_make_current = qemu_egl_make_context_current,
|
||||
|
||||
.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,
|
||||
.dpy_gl_update = qemu_spice_gl_update,
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* HAVE_SPICE_GL */
|
||||
@@ -1137,6 +1379,16 @@ 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;
|
||||
#endif
|
||||
#if defined(CONFIG_ANGLE)
|
||||
ssd->esurface = EGL_NO_SURFACE;
|
||||
ssd->backing_borrow = NULL;
|
||||
ssd->backing_id = -1;
|
||||
#endif
|
||||
console_set_displayglcontext(con, ssd);
|
||||
register_displayglops(&display_gl_ops);
|
||||
}
|
||||
#endif
|
||||
ssd->dcl.con = con;
|
||||
|
||||
@@ -23,7 +23,16 @@
|
||||
#undef _FORTIFY_SOURCE
|
||||
#endif
|
||||
#include "qemu/osdep.h"
|
||||
#if defined(CONFIG_LIBUCONTEXT)
|
||||
#include <libucontext/libucontext.h>
|
||||
#define ucontext_t libucontext_ucontext_t
|
||||
#define getcontext libucontext_getcontext
|
||||
#define setcontext libucontext_setcontext
|
||||
#define swapcontext libucontext_swapcontext
|
||||
#define makecontext libucontext_makecontext
|
||||
#else
|
||||
#include <ucontext.h>
|
||||
#endif
|
||||
#include "qemu/coroutine_int.h"
|
||||
|
||||
#ifdef CONFIG_VALGRIND_H
|
||||
|
||||
@@ -39,6 +39,10 @@ extern int madvise(char *, size_t, int);
|
||||
#include "qemu/error-report.h"
|
||||
#include "monitor/monitor.h"
|
||||
|
||||
#ifdef CONFIG_DARWIN
|
||||
#include "tcg/tcg-apple-jit.h"
|
||||
#endif
|
||||
|
||||
static bool fips_enabled = false;
|
||||
|
||||
static const char *hw_version = QEMU_HW_VERSION;
|
||||
|
||||
Reference in new issue
Block a user