diff options
50 files changed, 272 insertions, 239 deletions
diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c index 6315b2d746..3652a7b5fa 100644 --- a/audio/alsaaudio.c +++ b/audio/alsaaudio.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "qemu/osdep.h" #include <alsa/asoundlib.h> #include "qemu-common.h" #include "qemu/main-loop.h" diff --git a/audio/audio.c b/audio/audio.c index a0fc8b31ae..e84153293c 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "audio.h" #include "monitor/monitor.h" diff --git a/audio/audio_pt_int.c b/audio/audio_pt_int.c index 9a9c306a9c..21ff9c5803 100644 --- a/audio/audio_pt_int.c +++ b/audio/audio_pt_int.c @@ -1,3 +1,4 @@ +#include "qemu/osdep.h" #include "qemu-common.h" #include "audio.h" diff --git a/audio/audio_win_int.c b/audio/audio_win_int.c index e1324056a4..6900008d0c 100644 --- a/audio/audio_win_int.c +++ b/audio/audio_win_int.c @@ -1,5 +1,6 @@ /* public domain */ +#include "qemu/osdep.h" #include "qemu-common.h" #define AUDIO_CAP "win-int" diff --git a/audio/coreaudio.c b/audio/coreaudio.c index 7150604c53..d4ad224590 100644 --- a/audio/coreaudio.c +++ b/audio/coreaudio.c @@ -22,8 +22,8 @@ * THE SOFTWARE. */ +#include "qemu/osdep.h" #include <CoreAudio/CoreAudio.h> -#include <string.h> /* strerror */ #include <pthread.h> /* pthread_X */ #include "qemu-common.h" diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c index e9472c105c..516846eb80 100644 --- a/audio/dsoundaudio.c +++ b/audio/dsoundaudio.c @@ -26,6 +26,7 @@ * SEAL 1.07 by Carlos 'pel' Hasan was used as documentation */ +#include "qemu/osdep.h" #include "qemu-common.h" #include "audio.h" diff --git a/audio/mixeng.c b/audio/mixeng.c index 0e4976f271..981b97a964 100644 --- a/audio/mixeng.c +++ b/audio/mixeng.c @@ -22,6 +22,7 @@ * 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 "audio.h" diff --git a/audio/noaudio.c b/audio/noaudio.c index 50db1f344b..09588b9cd0 100644 --- a/audio/noaudio.c +++ b/audio/noaudio.c @@ -21,6 +21,7 @@ * 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 "audio.h" #include "qemu/timer.h" diff --git a/audio/ossaudio.c b/audio/ossaudio.c index 7dbe3332d8..349e9dd53d 100644 --- a/audio/ossaudio.c +++ b/audio/ossaudio.c @@ -21,9 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include <stdlib.h> +#include "qemu/osdep.h" #include <sys/mman.h> -#include <sys/types.h> #include <sys/ioctl.h> #include <sys/soundcard.h> #include "qemu-common.h" diff --git a/audio/paaudio.c b/audio/paaudio.c index fea607166f..57678e72e1 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -1,4 +1,5 @@ /* public domain */ +#include "qemu/osdep.h" #include "qemu-common.h" #include "audio.h" diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c index 1140f2ea0a..db69fe1416 100644 --- a/audio/sdlaudio.c +++ b/audio/sdlaudio.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "qemu/osdep.h" #include <SDL.h> #include <SDL_thread.h> #include "qemu-common.h" diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c index 42ae4a45f7..297fd416ed 100644 --- a/audio/spiceaudio.c +++ b/audio/spiceaudio.c @@ -17,6 +17,7 @@ * along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "qemu/error-report.h" #include "qemu/timer.h" diff --git a/audio/wavaudio.c b/audio/wavaudio.c index c586020c59..343b1a10b9 100644 --- a/audio/wavaudio.c +++ b/audio/wavaudio.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "qemu/timer.h" #include "audio.h" diff --git a/audio/wavcapture.c b/audio/wavcapture.c index 86e905627a..8bfb9e7654 100644 --- a/audio/wavcapture.c +++ b/audio/wavcapture.c @@ -1,3 +1,4 @@ +#include "qemu/osdep.h" #include "hw/hw.h" #include "monitor/monitor.h" #include "qemu/error-report.h" diff --git a/crypto/hash.c b/crypto/hash.c index 33324b6d06..4a8c0caea1 100644 --- a/crypto/hash.c +++ b/crypto/hash.c @@ -24,12 +24,8 @@ #ifdef CONFIG_GNUTLS_HASH #include <gnutls/gnutls.h> #include <gnutls/crypto.h> +#endif -static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALG__MAX] = { - [QCRYPTO_HASH_ALG_MD5] = GNUTLS_DIG_MD5, - [QCRYPTO_HASH_ALG_SHA1] = GNUTLS_DIG_SHA1, - [QCRYPTO_HASH_ALG_SHA256] = GNUTLS_DIG_SHA256, -}; static size_t qcrypto_hash_alg_size[QCRYPTO_HASH_ALG__MAX] = { [QCRYPTO_HASH_ALG_MD5] = 16, @@ -37,14 +33,6 @@ static size_t qcrypto_hash_alg_size[QCRYPTO_HASH_ALG__MAX] = { [QCRYPTO_HASH_ALG_SHA256] = 32, }; -gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg) -{ - if (alg < G_N_ELEMENTS(qcrypto_hash_alg_map)) { - return true; - } - return false; -} - size_t qcrypto_hash_digest_len(QCryptoHashAlgorithm alg) { if (alg >= G_N_ELEMENTS(qcrypto_hash_alg_size)) { @@ -54,6 +42,22 @@ size_t qcrypto_hash_digest_len(QCryptoHashAlgorithm alg) } +#ifdef CONFIG_GNUTLS_HASH +static int qcrypto_hash_alg_map[QCRYPTO_HASH_ALG__MAX] = { + [QCRYPTO_HASH_ALG_MD5] = GNUTLS_DIG_MD5, + [QCRYPTO_HASH_ALG_SHA1] = GNUTLS_DIG_SHA1, + [QCRYPTO_HASH_ALG_SHA256] = GNUTLS_DIG_SHA256, +}; + +gboolean qcrypto_hash_supports(QCryptoHashAlgorithm alg) +{ + if (alg < G_N_ELEMENTS(qcrypto_hash_alg_map)) { + return true; + } + return false; +} + + int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, const struct iovec *iov, size_t niov, diff --git a/crypto/secret.c b/crypto/secret.c index 90592c0a3e..be736f2cd5 100644 --- a/crypto/secret.c +++ b/crypto/secret.c @@ -353,38 +353,6 @@ qcrypto_secret_complete(UserCreatable *uc, Error **errp) static void -qcrypto_secret_init(Object *obj) -{ - object_property_add_bool(obj, "loaded", - qcrypto_secret_prop_get_loaded, - qcrypto_secret_prop_set_loaded, - NULL); - object_property_add_enum(obj, "format", - "QCryptoSecretFormat", - QCryptoSecretFormat_lookup, - qcrypto_secret_prop_get_format, - qcrypto_secret_prop_set_format, - NULL); - object_property_add_str(obj, "data", - qcrypto_secret_prop_get_data, - qcrypto_secret_prop_set_data, - NULL); - object_property_add_str(obj, "file", - qcrypto_secret_prop_get_file, - qcrypto_secret_prop_set_file, - NULL); - object_property_add_str(obj, "keyid", - qcrypto_secret_prop_get_keyid, - qcrypto_secret_prop_set_keyid, - NULL); - object_property_add_str(obj, "iv", - qcrypto_secret_prop_get_iv, - qcrypto_secret_prop_set_iv, - NULL); -} - - -static void qcrypto_secret_finalize(Object *obj) { QCryptoSecret *secret = QCRYPTO_SECRET(obj); @@ -402,6 +370,33 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data) UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc); ucc->complete = qcrypto_secret_complete; + + object_class_property_add_bool(oc, "loaded", + qcrypto_secret_prop_get_loaded, + qcrypto_secret_prop_set_loaded, + NULL); + object_class_property_add_enum(oc, "format", + "QCryptoSecretFormat", + QCryptoSecretFormat_lookup, + qcrypto_secret_prop_get_format, + qcrypto_secret_prop_set_format, + NULL); + object_class_property_add_str(oc, "data", + qcrypto_secret_prop_get_data, + qcrypto_secret_prop_set_data, + NULL); + object_class_property_add_str(oc, "file", + qcrypto_secret_prop_get_file, + qcrypto_secret_prop_set_file, + NULL); + object_class_property_add_str(oc, "keyid", + qcrypto_secret_prop_get_keyid, + qcrypto_secret_prop_set_keyid, + NULL); + object_class_property_add_str(oc, "iv", + qcrypto_secret_prop_get_iv, + qcrypto_secret_prop_set_iv, + NULL); } @@ -493,7 +488,6 @@ static const TypeInfo qcrypto_secret_info = { .parent = TYPE_OBJECT, .name = TYPE_QCRYPTO_SECRET, .instance_size = sizeof(QCryptoSecret), - .instance_init = qcrypto_secret_init, .instance_finalize = qcrypto_secret_finalize, .class_size = sizeof(QCryptoSecretClass), .class_init = qcrypto_secret_class_init, diff --git a/crypto/tlscreds.c b/crypto/tlscreds.c index 38bb671198..fc99589c22 100644 --- a/crypto/tlscreds.c +++ b/crypto/tlscreds.c @@ -199,26 +199,31 @@ qcrypto_tls_creds_prop_get_endpoint(Object *obj, static void +qcrypto_tls_creds_class_init(ObjectClass *oc, void *data) +{ + object_class_property_add_bool(oc, "verify-peer", + qcrypto_tls_creds_prop_get_verify, + qcrypto_tls_creds_prop_set_verify, + NULL); + object_class_property_add_str(oc, "dir", + qcrypto_tls_creds_prop_get_dir, + qcrypto_tls_creds_prop_set_dir, + NULL); + object_class_property_add_enum(oc, "endpoint", + "QCryptoTLSCredsEndpoint", + QCryptoTLSCredsEndpoint_lookup, + qcrypto_tls_creds_prop_get_endpoint, + qcrypto_tls_creds_prop_set_endpoint, + NULL); +} + + +static void qcrypto_tls_creds_init(Object *obj) { QCryptoTLSCreds *creds = QCRYPTO_TLS_CREDS(obj); creds->verifyPeer = true; - - object_property_add_bool(obj, "verify-peer", - qcrypto_tls_creds_prop_get_verify, - qcrypto_tls_creds_prop_set_verify, - NULL); - object_property_add_str(obj, "dir", - qcrypto_tls_creds_prop_get_dir, - qcrypto_tls_creds_prop_set_dir, - NULL); - object_property_add_enum(obj, "endpoint", - "QCryptoTLSCredsEndpoint", - QCryptoTLSCredsEndpoint_lookup, - qcrypto_tls_creds_prop_get_endpoint, - qcrypto_tls_creds_prop_set_endpoint, - NULL); } @@ -237,6 +242,7 @@ static const TypeInfo qcrypto_tls_creds_info = { .instance_size = sizeof(QCryptoTLSCreds), .instance_init = qcrypto_tls_creds_init, .instance_finalize = qcrypto_tls_creds_finalize, + .class_init = qcrypto_tls_creds_class_init, .class_size = sizeof(QCryptoTLSCredsClass), .abstract = true, }; diff --git a/crypto/tlscredsanon.c b/crypto/tlscredsanon.c index 55e2047b76..f36a793d16 100644 --- a/crypto/tlscredsanon.c +++ b/crypto/tlscredsanon.c @@ -172,16 +172,6 @@ qcrypto_tls_creds_anon_complete(UserCreatable *uc, Error **errp) static void -qcrypto_tls_creds_anon_init(Object *obj) -{ - object_property_add_bool(obj, "loaded", - qcrypto_tls_creds_anon_prop_get_loaded, - qcrypto_tls_creds_anon_prop_set_loaded, - NULL); -} - - -static void qcrypto_tls_creds_anon_finalize(Object *obj) { QCryptoTLSCredsAnon *creds = QCRYPTO_TLS_CREDS_ANON(obj); @@ -196,6 +186,11 @@ qcrypto_tls_creds_anon_class_init(ObjectClass *oc, void *data) UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc); ucc->complete = qcrypto_tls_creds_anon_complete; + + object_class_property_add_bool(oc, "loaded", + qcrypto_tls_creds_anon_prop_get_loaded, + qcrypto_tls_creds_anon_prop_set_loaded, + NULL); } @@ -203,7 +198,6 @@ static const TypeInfo qcrypto_tls_creds_anon_info = { .parent = TYPE_QCRYPTO_TLS_CREDS, .name = TYPE_QCRYPTO_TLS_CREDS_ANON, .instance_size = sizeof(QCryptoTLSCredsAnon), - .instance_init = qcrypto_tls_creds_anon_init, .instance_finalize = qcrypto_tls_creds_anon_finalize, .class_size = sizeof(QCryptoTLSCredsAnonClass), .class_init = qcrypto_tls_creds_anon_class_init, diff --git a/crypto/tlscredsx509.c b/crypto/tlscredsx509.c index 8664b825bf..99130433fd 100644 --- a/crypto/tlscredsx509.c +++ b/crypto/tlscredsx509.c @@ -804,19 +804,6 @@ qcrypto_tls_creds_x509_init(Object *obj) QCryptoTLSCredsX509 *creds = QCRYPTO_TLS_CREDS_X509(obj); creds->sanityCheck = true; - - object_property_add_bool(obj, "loaded", - qcrypto_tls_creds_x509_prop_get_loaded, - qcrypto_tls_creds_x509_prop_set_loaded, - NULL); - object_property_add_bool(obj, "sanity-check", - qcrypto_tls_creds_x509_prop_get_sanity, - qcrypto_tls_creds_x509_prop_set_sanity, - NULL); - object_property_add_str(obj, "passwordid", - qcrypto_tls_creds_x509_prop_get_passwordid, - qcrypto_tls_creds_x509_prop_set_passwordid, - NULL); } @@ -836,6 +823,19 @@ qcrypto_tls_creds_x509_class_init(ObjectClass *oc, void *data) UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc); ucc->complete = qcrypto_tls_creds_x509_complete; + + object_class_property_add_bool(oc, "loaded", + qcrypto_tls_creds_x509_prop_get_loaded, + qcrypto_tls_creds_x509_prop_set_loaded, + NULL); + object_class_property_add_bool(oc, "sanity-check", + qcrypto_tls_creds_x509_prop_get_sanity, + qcrypto_tls_creds_x509_prop_set_sanity, + NULL); + object_class_property_add_str(oc, "passwordid", + qcrypto_tls_creds_x509_prop_get_passwordid, + qcrypto_tls_creds_x509_prop_set_passwordid, + NULL); } diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c index b17383555e..cbd959e0bd 100644 --- a/hw/audio/ac97.c +++ b/hw/audio/ac97.c @@ -17,6 +17,7 @@ * GNU GPL, version 2 or (at your option) any later version. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/audio/audio.h" #include "audio/audio.h" diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c index 334935f8d9..1270b19cc6 100644 --- a/hw/audio/adlib.c +++ b/hw/audio/adlib.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/audio/audio.h" #include "audio/audio.h" diff --git a/hw/audio/cs4231.c b/hw/audio/cs4231.c index 6325a8cea7..caf97c1692 100644 --- a/hw/audio/cs4231.c +++ b/hw/audio/cs4231.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ +#include "qemu/osdep.h" #include "hw/sysbus.h" #include "trace.h" diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c index f96f561c7f..b0c7c93e21 100644 --- a/hw/audio/cs4231a.c +++ b/hw/audio/cs4231a.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/audio/audio.h" #include "audio/audio.h" diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c index 592578b142..96acbc6e2f 100644 --- a/hw/audio/es1370.c +++ b/hw/audio/es1370.c @@ -26,6 +26,7 @@ /* #define VERBOSE_ES1370 */ #define SILENT_ES1370 +#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/audio/audio.h" #include "audio/audio.h" diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c index 81c0c1be20..731110fe86 100644 --- a/hw/audio/fmopl.c +++ b/hw/audio/fmopl.c @@ -32,10 +32,7 @@ #define HAS_YM3812 1 -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> +#include "qemu/osdep.h" #include <math.h> //#include "driver.h" /* use M.A.M.E. */ #include "fmopl.h" diff --git a/hw/audio/gus.c b/hw/audio/gus.c index e0c8a4ee1e..47c0fcfb4c 100644 --- a/hw/audio/gus.c +++ b/hw/audio/gus.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/audio/audio.h" #include "audio/audio.h" diff --git a/hw/audio/gusemu_hal.c b/hw/audio/gusemu_hal.c index 6096690735..973d6b9f4f 100644 --- a/hw/audio/gusemu_hal.c +++ b/hw/audio/gusemu_hal.c @@ -26,6 +26,7 @@ * TODO: check mixer: see 7.20 of sdk for panning pos (applies to all gus models?)? */ +#include "qemu/osdep.h" #include "gustate.h" #include "gusemu.h" diff --git a/hw/audio/gusemu_mixer.c b/hw/audio/gusemu_mixer.c index 6d8d9ced11..701e8fb0ed 100644 --- a/hw/audio/gusemu_mixer.c +++ b/hw/audio/gusemu_mixer.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ +#include "qemu/osdep.h" #include "gusemu.h" #include "gustate.h" diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c index 3c03ff5668..52d4640e60 100644 --- a/hw/audio/hda-codec.c +++ b/hw/audio/hda-codec.c @@ -17,6 +17,7 @@ * along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/pci/pci.h" #include "intel-hda.h" diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c index 433463e9c5..d372d4ab98 100644 --- a/hw/audio/intel-hda.c +++ b/hw/audio/intel-hda.c @@ -17,6 +17,7 @@ * along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/pci/pci.h" #include "hw/pci/msi.h" diff --git a/hw/audio/lm4549.c b/hw/audio/lm4549.c index 380ef603bd..a46f2301af 100644 --- a/hw/audio/lm4549.c +++ b/hw/audio/lm4549.c @@ -13,6 +13,7 @@ * It supports only one playback voice and no record voice. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "audio/audio.h" #include "lm4549.h" @@ -33,7 +34,6 @@ do { printf("lm4549: " fmt , ## __VA_ARGS__); } while (0) #endif #if defined(LM4549_DUMP_DAC_INPUT) -#include <stdio.h> static FILE *fp_dac_input; #endif diff --git a/hw/audio/marvell_88w8618.c b/hw/audio/marvell_88w8618.c index 86992677e3..a6ca1806be 100644 --- a/hw/audio/marvell_88w8618.c +++ b/hw/audio/marvell_88w8618.c @@ -9,6 +9,7 @@ * Contributions after 2012-01-13 are licensed under the terms of the * GNU GPL, version 2 or (at your option) any later version. */ +#include "qemu/osdep.h" #include "hw/sysbus.h" #include "hw/hw.h" #include "hw/i2c/i2c.h" diff --git a/hw/audio/milkymist-ac97.c b/hw/audio/milkymist-ac97.c index 28f55e8535..6a3b53674e 100644 --- a/hw/audio/milkymist-ac97.c +++ b/hw/audio/milkymist-ac97.c @@ -21,6 +21,7 @@ * http://www.milkymist.org/socdoc/ac97.pdf */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/sysbus.h" #include "trace.h" diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c index 5266fb5457..f9afc8edad 100644 --- a/hw/audio/pcspk.c +++ b/hw/audio/pcspk.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/i386/pc.h" #include "hw/isa/isa.h" diff --git a/hw/audio/pl041.c b/hw/audio/pl041.c index 19982f2477..4717bc9b9c 100644 --- a/hw/audio/pl041.c +++ b/hw/audio/pl041.c @@ -20,6 +20,7 @@ * */ +#include "qemu/osdep.h" #include "hw/sysbus.h" #include "pl041.h" diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c index 995435f240..3b2dcfdad9 100644 --- a/hw/audio/sb16.c +++ b/hw/audio/sb16.c @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/audio/audio.h" #include "audio/audio.h" diff --git a/hw/audio/wm8750.c b/hw/audio/wm8750.c index b50b331402..0c6500e96a 100644 --- a/hw/audio/wm8750.c +++ b/hw/audio/wm8750.c @@ -7,6 +7,7 @@ * This file is licensed under GNU GPL. */ +#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/i2c/i2c.h" #include "audio/audio.h" diff --git a/hw/block/nvme.c b/hw/block/nvme.c index a5fedb2906..c68b62521a 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -916,45 +916,13 @@ static void nvme_class_init(ObjectClass *oc, void *data) dc->vmsd = &nvme_vmstate; } -static void nvme_get_bootindex(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - NvmeCtrl *s = NVME(obj); - - visit_type_int32(v, &s->conf.bootindex, name, errp); -} - -static void nvme_set_bootindex(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void nvme_instance_init(Object *obj) { NvmeCtrl *s = NVME(obj); - int32_t boot_index; - Error *local_err = NULL; - - visit_type_int32(v, &boot_index, name, &local_err); - if (local_err) { - goto out; - } - /* check whether bootindex is present in fw_boot_order list */ - check_boot_index(boot_index, &local_err); - if (local_err) { - goto out; - } - /* change bootindex to a new one */ - s->conf.bootindex = boot_index; -out: - if (local_err) { - error_propagate(errp, local_err); - } -} - -static void nvme_instance_init(Object *obj) -{ - object_property_add(obj, "bootindex", "int32", - nvme_get_bootindex, - nvme_set_bootindex, NULL, NULL, NULL); - object_property_set_int(obj, -1, "bootindex", NULL); + device_add_bootindex_property(obj, &s->conf.bootindex, + "bootindex", "/namespace@1,0", + DEVICE(obj), &error_abort); } static const TypeInfo nvme_info = { diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index d5c89aeca1..48b7a34a8f 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -263,15 +263,6 @@ static const MemoryRegionOps ivshmem_mmio_ops = { }, }; -static void ivshmem_receive(void *opaque, const uint8_t *buf, int size) -{ - IVShmemState *s = opaque; - - IVSHMEM_DPRINTF("ivshmem_receive 0x%02x size: %d\n", *buf, size); - - ivshmem_IntrStatus_write(s, *buf); -} - static int ivshmem_can_receive(void * opaque) { return sizeof(int64_t); @@ -282,15 +273,24 @@ static void ivshmem_event(void *opaque, int event) IVSHMEM_DPRINTF("ivshmem_event %d\n", event); } -static void fake_irqfd(void *opaque, const uint8_t *buf, int size) { - +static void ivshmem_vector_notify(void *opaque) +{ MSIVector *entry = opaque; PCIDevice *pdev = entry->pdev; IVShmemState *s = IVSHMEM(pdev); int vector = entry - s->msi_vectors; + EventNotifier *n = &s->peers[s->vm_id].eventfds[vector]; + + if (!event_notifier_test_and_clear(n)) { + return; + } IVSHMEM_DPRINTF("interrupt on vector %p %d\n", pdev, vector); - msix_notify(pdev, vector); + if (ivshmem_has_feature(s, IVSHMEM_MSI)) { + msix_notify(pdev, vector); + } else { + ivshmem_IntrStatus_write(s, 1); + } } static int ivshmem_vector_unmask(PCIDevice *dev, unsigned vector, @@ -350,38 +350,16 @@ static void ivshmem_vector_poll(PCIDevice *dev, } } -static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *n, - int vector) +static void watch_vector_notifier(IVShmemState *s, EventNotifier *n, + int vector) { - /* create a event character device based on the passed eventfd */ - IVShmemState *s = opaque; - PCIDevice *pdev = PCI_DEVICE(s); int eventfd = event_notifier_get_fd(n); - CharDriverState *chr; - - s->msi_vectors[vector].pdev = pdev; - - chr = qemu_chr_open_eventfd(eventfd); - - if (chr == NULL) { - error_report("creating chardriver for eventfd %d failed", eventfd); - return NULL; - } - qemu_chr_fe_claim_no_fail(chr); /* if MSI is supported we need multiple interrupts */ - if (ivshmem_has_feature(s, IVSHMEM_MSI)) { - s->msi_vectors[vector].pdev = PCI_DEVICE(s); - - qemu_chr_add_handlers(chr, ivshmem_can_receive, fake_irqfd, - ivshmem_event, &s->msi_vectors[vector]); - } else { - qemu_chr_add_handlers(chr, ivshmem_can_receive, ivshmem_receive, - ivshmem_event, s); - } - - return chr; + s->msi_vectors[vector].pdev = PCI_DEVICE(s); + qemu_set_fd_handler(eventfd, ivshmem_vector_notify, + NULL, &s->msi_vectors[vector]); } static int check_shm_size(IVShmemState *s, int fd, Error **errp) @@ -591,7 +569,7 @@ static void setup_interrupt(IVShmemState *s, int vector) if (!with_irqfd) { IVSHMEM_DPRINTF("with eventfd"); - s->eventfd_chr[vector] = create_eventfd_chr_device(s, n, vector); + watch_vector_notifier(s, n, vector); } else if (msix_enabled(pdev)) { IVSHMEM_DPRINTF("with irqfd"); if (ivshmem_add_kvm_msi_virq(s, vector) < 0) { @@ -772,18 +750,20 @@ static void ivshmem_reset(DeviceState *d) ivshmem_use_msix(s); } -static int ivshmem_setup_msi(IVShmemState * s) +static int ivshmem_setup_interrupts(IVShmemState *s) { - if (msix_init_exclusive_bar(PCI_DEVICE(s), s->vectors, 1)) { - return -1; - } + /* allocate QEMU callback data for receiving interrupts */ + s->msi_vectors = g_malloc0(s->vectors * sizeof(MSIVector)); - IVSHMEM_DPRINTF("msix initialized (%d vectors)\n", s->vectors); + if (ivshmem_has_feature(s, IVSHMEM_MSI)) { + if (msix_init_exclusive_bar(PCI_DEVICE(s), s->vectors, 1)) { + return -1; + } - /* allocate QEMU char devices for receiving interrupts */ - s->msi_vectors = g_malloc0(s->vectors * sizeof(MSIVector)); + IVSHMEM_DPRINTF("msix initialized (%d vectors)\n", s->vectors); + ivshmem_use_msix(s); + } - ivshmem_use_msix(s); return 0; } @@ -950,9 +930,8 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp) IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n", s->server_chr->filename); - if (ivshmem_has_feature(s, IVSHMEM_MSI) && - ivshmem_setup_msi(s)) { - error_setg(errp, "msix initialization failed"); + if (ivshmem_setup_interrupts(s) < 0) { + error_setg(errp, "failed to initialize interrupts"); return; } diff --git a/include/crypto/cipher.h b/include/crypto/cipher.h index a812803df1..f90ac79567 100644 --- a/include/crypto/cipher.h +++ b/include/crypto/cipher.h @@ -138,7 +138,7 @@ size_t qcrypto_cipher_get_iv_len(QCryptoCipherAlgorithm alg, * @mode: the cipher usage mode * @key: the private key bytes * @nkey: the length of @key - * @errp: pointer to an uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Creates a new cipher object for encrypting/decrypting * data with the algorithm @alg in the usage mode @mode. @@ -174,7 +174,7 @@ void qcrypto_cipher_free(QCryptoCipher *cipher); * @in: buffer holding the plain text input data * @out: buffer to fill with the cipher text output data * @len: the length of @in and @out buffers - * @errp: pointer to an uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Encrypts the plain text stored in @in, filling * @out with the resulting ciphered text. Both the @@ -196,7 +196,7 @@ int qcrypto_cipher_encrypt(QCryptoCipher *cipher, * @in: buffer holding the cipher text input data * @out: buffer to fill with the plain text output data * @len: the length of @in and @out buffers - * @errp: pointer to an uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Decrypts the cipher text stored in @in, filling * @out with the resulting plain text. Both the @@ -216,7 +216,7 @@ int qcrypto_cipher_decrypt(QCryptoCipher *cipher, * @cipher: the cipher object * @iv: the initialization vector bytes * @niv: the length of @iv - * @errpr: pointer to an uninitialized error object + * @errpr: pointer to a NULL-initialized error object * * If the @cipher object is setup to use a mode that requires * initialization vectors, this sets the initialization vector diff --git a/include/crypto/hash.h b/include/crypto/hash.h index 41822c0a4e..5e8d9a1372 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h @@ -55,7 +55,7 @@ size_t qcrypto_hash_digest_len(QCryptoHashAlgorithm alg); * @niov: the length of @iov * @result: pointer to hold output hash * @resultlen: pointer to hold length of @result - * @errp: pointer to uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Computes the hash across all the memory regions * present in @iov. The @result pointer will be @@ -80,7 +80,7 @@ int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, * @len: the length of @buf * @result: pointer to hold output hash * @resultlen: pointer to hold length of @result - * @errp: pointer to uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Computes the hash across all the memory region * @buf of length @len. The @result pointer will be @@ -104,7 +104,7 @@ int qcrypto_hash_bytes(QCryptoHashAlgorithm alg, * @iov: the array of memory regions to hash * @niov: the length of @iov * @digest: pointer to hold output hash - * @errp: pointer to uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Computes the hash across all the memory regions * present in @iov. The @digest pointer will be @@ -127,7 +127,7 @@ int qcrypto_hash_digestv(QCryptoHashAlgorithm alg, * @buf: the memory region to hash * @len: the length of @buf * @digest: pointer to hold output hash - * @errp: pointer to uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Computes the hash across all the memory region * @buf of length @len. The @digest pointer will be @@ -150,7 +150,7 @@ int qcrypto_hash_digest(QCryptoHashAlgorithm alg, * @iov: the array of memory regions to hash * @niov: the length of @iov * @base64: pointer to hold output hash - * @errp: pointer to uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Computes the hash across all the memory regions * present in @iov. The @base64 pointer will be @@ -173,7 +173,7 @@ int qcrypto_hash_base64v(QCryptoHashAlgorithm alg, * @buf: the memory region to hash * @len: the length of @buf * @base64: pointer to hold output hash - * @errp: pointer to uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Computes the hash across all the memory region * @buf of length @len. The @base64 pointer will be diff --git a/include/crypto/tlssession.h b/include/crypto/tlssession.h index d356a8dc17..c1bad9e4f0 100644 --- a/include/crypto/tlssession.h +++ b/include/crypto/tlssession.h @@ -114,7 +114,7 @@ typedef struct QCryptoTLSSession QCryptoTLSSession; * @hostname: optional hostname to validate * @aclname: optional ACL to validate peer credentials against * @endpoint: role of the TLS session, client or server - * @errp: pointer to an uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Create a new TLS session object that will be used to * negotiate a TLS session over an arbitrary data channel. @@ -163,7 +163,7 @@ void qcrypto_tls_session_free(QCryptoTLSSession *sess); /** * qcrypto_tls_session_check_credentials: * @sess: the TLS session object - * @errp: pointer to an uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Validate the peer's credentials after a successful * TLS handshake. It is an error to call this before @@ -249,7 +249,7 @@ ssize_t qcrypto_tls_session_read(QCryptoTLSSession *sess, /** * qcrypto_tls_session_handshake: * @sess: the TLS session object - * @errp: pointer to an uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Start, or continue, a TLS handshake sequence. If * the underlying data channel is non-blocking, then @@ -292,7 +292,7 @@ qcrypto_tls_session_get_handshake_status(QCryptoTLSSession *sess); /** * qcrypto_tls_session_get_key_size: * @sess: the TLS session object - * @errp: pointer to an uninitialized error object + * @errp: pointer to a NULL-initialized error object * * Check the size of the data channel encryption key * diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 598dd2bf49..e035d1cbda 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -360,9 +360,6 @@ void register_char_driver(const char *name, ChardevBackendKind kind, CharDriverState *(*create)(const char *id, ChardevBackend *backend, ChardevReturn *ret, Error **errp)); -/* add an eventfd to the qemu devices that are polled */ -CharDriverState *qemu_chr_open_eventfd(int eventfd); - extern int term_escape_char; CharDriverState *qemu_char_get_next_serial(void); diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h index b7ac38f198..3f0b57bb16 100644 --- a/include/ui/sdl2.h +++ b/include/ui/sdl2.h @@ -19,6 +19,7 @@ struct sdl2_console { int hidden; int opengl; int updates; + int idle_counter; SDL_GLContext winctx; #ifdef CONFIG_OPENGL ConsoleGLState *gls; diff --git a/qemu-char.c b/qemu-char.c index ca53e8c376..1605b30c33 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2838,19 +2838,6 @@ static int tcp_chr_sync_read(CharDriverState *chr, const uint8_t *buf, int len) return size; } -#ifndef _WIN32 -CharDriverState *qemu_chr_open_eventfd(int eventfd) -{ - CharDriverState *chr = qemu_chr_open_fd(eventfd, eventfd, NULL, NULL); - - if (chr) { - chr->avail_connections = 1; - } - - return chr; -} -#endif - static void tcp_chr_connect(void *opaque) { CharDriverState *chr = opaque; diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c index 03c7b962a3..705fece717 100644 --- a/tests/ivshmem-test.c +++ b/tests/ivshmem-test.c @@ -34,12 +34,10 @@ static void save_fn(QPCIDevice *dev, int devfn, void *data) *pdev = dev; } -static QPCIDevice *get_device(void) +static QPCIDevice *get_device(QPCIBus *pcibus) { QPCIDevice *dev; - QPCIBus *pcibus; - pcibus = qpci_init_pc(); dev = NULL; qpci_device_foreach(pcibus, 0x1af4, 0x1110, save_fn, &dev); g_assert(dev != NULL); @@ -50,6 +48,7 @@ static QPCIDevice *get_device(void) typedef struct _IVState { QTestState *qtest; void *reg_base, *mem_base; + QPCIBus *pcibus; QPCIDevice *dev; } IVState; @@ -100,13 +99,20 @@ static inline void out_reg(IVState *s, enum Reg reg, unsigned v) global_qtest = qtest; } +static void cleanup_vm(IVState *s) +{ + g_free(s->dev); + qpci_free_pc(s->pcibus); + qtest_quit(s->qtest); +} + static void setup_vm_cmd(IVState *s, const char *cmd, bool msix) { uint64_t barsize; s->qtest = qtest_start(cmd); - - s->dev = get_device(); + s->pcibus = qpci_init_pc(); + s->dev = get_device(s->pcibus); /* FIXME: other bar order fails, mappings changes */ s->mem_base = qpci_iomap(s->dev, 2, &barsize); @@ -173,7 +179,7 @@ static void test_ivshmem_single(void) g_assert_cmpuint(data[i], ==, i); } - qtest_quit(s->qtest); + cleanup_vm(s); } static void test_ivshmem_pair(void) @@ -218,8 +224,8 @@ static void test_ivshmem_pair(void) g_assert_cmpuint(data[i], ==, 0x44); } - qtest_quit(s1->qtest); - qtest_quit(s2->qtest); + cleanup_vm(s1); + cleanup_vm(s2); g_free(data); } @@ -271,18 +277,18 @@ static void *server_thread(void *data) return NULL; } -static void setup_vm_with_server(IVState *s, int nvectors) +static void setup_vm_with_server(IVState *s, int nvectors, bool msi) { char *cmd = g_strdup_printf("-chardev socket,id=chr0,path=%s,nowait " - "-device ivshmem,size=1M,chardev=chr0,vectors=%d", - tmpserver, nvectors); + "-device ivshmem,size=1M,chardev=chr0,vectors=%d,msi=%s", + tmpserver, nvectors, msi ? "true" : "false"); - setup_vm_cmd(s, cmd, true); + setup_vm_cmd(s, cmd, msi); g_free(cmd); } -static void test_ivshmem_server(void) +static void test_ivshmem_server(bool msi) { IVState state1, state2, *s1, *s2; ServerThread thread; @@ -300,9 +306,9 @@ static void test_ivshmem_server(void) ret = ivshmem_server_start(&server); g_assert_cmpint(ret, ==, 0); - setup_vm_with_server(&state1, nvectors); + setup_vm_with_server(&state1, nvectors, msi); s1 = &state1; - setup_vm_with_server(&state2, nvectors); + setup_vm_with_server(&state2, nvectors, msi); s2 = &state2; g_assert_cmpuint(in_reg(s1, IVPOSITION), ==, 0xffffffff); @@ -332,32 +338,42 @@ static void test_ivshmem_server(void) g_assert_cmpuint(vm1, !=, vm2); global_qtest = s1->qtest; - ret = qpci_msix_table_size(s1->dev); - g_assert_cmpuint(ret, ==, nvectors); + if (msi) { + ret = qpci_msix_table_size(s1->dev); + g_assert_cmpuint(ret, ==, nvectors); + } /* ping vm2 -> vm1 */ - ret = qpci_msix_pending(s1->dev, 0); - g_assert_cmpuint(ret, ==, 0); + if (msi) { + ret = qpci_msix_pending(s1->dev, 0); + g_assert_cmpuint(ret, ==, 0); + } else { + out_reg(s1, INTRSTATUS, 0); + } out_reg(s2, DOORBELL, vm1 << 16); do { g_usleep(10000); - ret = qpci_msix_pending(s1->dev, 0); + ret = msi ? qpci_msix_pending(s1->dev, 0) : in_reg(s1, INTRSTATUS); } while (ret == 0 && g_get_monotonic_time() < end_time); g_assert_cmpuint(ret, !=, 0); /* ping vm1 -> vm2 */ global_qtest = s2->qtest; - ret = qpci_msix_pending(s2->dev, 0); - g_assert_cmpuint(ret, ==, 0); + if (msi) { + ret = qpci_msix_pending(s2->dev, 0); + g_assert_cmpuint(ret, ==, 0); + } else { + out_reg(s2, INTRSTATUS, 0); + } out_reg(s1, DOORBELL, vm2 << 16); do { g_usleep(10000); - ret = qpci_msix_pending(s2->dev, 0); + ret = msi ? qpci_msix_pending(s2->dev, 0) : in_reg(s2, INTRSTATUS); } while (ret == 0 && g_get_monotonic_time() < end_time); g_assert_cmpuint(ret, !=, 0); - qtest_quit(s2->qtest); - qtest_quit(s1->qtest); + cleanup_vm(s2); + cleanup_vm(s1); if (qemu_write_full(thread.pipe[1], "q", 1) != 1) { g_error("qemu_write_full: %s", g_strerror(errno)); @@ -370,6 +386,16 @@ static void test_ivshmem_server(void) close(thread.pipe[0]); } +static void test_ivshmem_server_msi(void) +{ + test_ivshmem_server(true); +} + +static void test_ivshmem_server_irq(void) +{ + test_ivshmem_server(false); +} + #define PCI_SLOT_HP 0x06 static void test_ivshmem_hotplug(void) @@ -395,7 +421,7 @@ static void test_ivshmem_memdev(void) setup_vm_cmd(&state, "-object memory-backend-ram,size=1M,id=mb1" " -device ivshmem,x-memdev=mb1", false); - qtest_quit(state.qtest); + cleanup_vm(&state); } static void cleanup(void) @@ -483,7 +509,8 @@ int main(int argc, char **argv) qtest_add_func("/ivshmem/memdev", test_ivshmem_memdev); if (g_test_slow()) { qtest_add_func("/ivshmem/pair", test_ivshmem_pair); - qtest_add_func("/ivshmem/server", test_ivshmem_server); + qtest_add_func("/ivshmem/server-msi", test_ivshmem_server_msi); + qtest_add_func("/ivshmem/server-irq", test_ivshmem_server_irq); } ret = g_test_run(); diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c index 4e630c250a..80b1a2117d 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -34,11 +34,13 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, if (vendor_id != -1 && qpci_config_readw(dev, PCI_VENDOR_ID) != vendor_id) { + g_free(dev); continue; } if (device_id != -1 && qpci_config_readw(dev, PCI_DEVICE_ID) != device_id) { + g_free(dev); continue; } @@ -1598,11 +1598,16 @@ static void gd_vc_chr_set_echo(CharDriverState *chr, bool echo) static int nb_vcs; static CharDriverState *vcs[MAX_VCS]; -static CharDriverState *gd_vc_handler(ChardevVC *unused, Error **errp) +static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp) { + ChardevCommon *common = qapi_ChardevVC_base(vc); CharDriverState *chr; - chr = g_malloc0(sizeof(*chr)); + chr = qemu_chr_alloc(common, errp); + if (!chr) { + return NULL; + } + chr->chr_write = gd_vc_chr_write; chr->chr_set_echo = gd_vc_chr_set_echo; @@ -60,6 +60,11 @@ static SDL_Cursor *guest_sprite = NULL; static SDL_PixelFormat host_format; static int scaling_active = 0; static Notifier mouse_mode_notifier; +static int idle_counter; + +#define SDL_REFRESH_INTERVAL_BUSY 10 +#define SDL_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \ + / SDL_REFRESH_INTERVAL_BUSY + 1) #if 0 #define DEBUG_SDL @@ -802,6 +807,7 @@ static void handle_activation(SDL_Event *ev) static void sdl_refresh(DisplayChangeListener *dcl) { SDL_Event ev1, *ev = &ev1; + int idle = 1; if (last_vm_running != runstate_is_running()) { last_vm_running = runstate_is_running(); @@ -817,9 +823,11 @@ static void sdl_refresh(DisplayChangeListener *dcl) sdl_update(dcl, 0, 0, real_screen->w, real_screen->h); break; case SDL_KEYDOWN: + idle = 0; handle_keydown(ev); break; case SDL_KEYUP: + idle = 0; handle_keyup(ev); break; case SDL_QUIT: @@ -829,10 +837,12 @@ static void sdl_refresh(DisplayChangeListener *dcl) } break; case SDL_MOUSEMOTION: + idle = 0; handle_mousemotion(ev); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: + idle = 0; handle_mousebutton(ev); break; case SDL_ACTIVEEVENT: @@ -847,6 +857,18 @@ static void sdl_refresh(DisplayChangeListener *dcl) break; } } + + if (idle) { + if (idle_counter < SDL_MAX_IDLE_COUNT) { + idle_counter++; + if (idle_counter >= SDL_MAX_IDLE_COUNT) { + dcl->update_interval = GUI_REFRESH_INTERVAL_DEFAULT; + } + } + } else { + idle_counter = 0; + dcl->update_interval = SDL_REFRESH_INTERVAL_BUSY; + } } static void sdl_mouse_warp(DisplayChangeListener *dcl, @@ -49,6 +49,10 @@ static int guest_x, guest_y; static SDL_Cursor *guest_sprite; static Notifier mouse_mode_notifier; +#define SDL2_REFRESH_INTERVAL_BUSY 10 +#define SDL2_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \ + / SDL2_REFRESH_INTERVAL_BUSY + 1) + static void sdl_update_caption(struct sdl2_console *scon); static struct sdl2_console *get_scon_from_window(uint32_t window_id) @@ -578,6 +582,7 @@ static void handle_windowevent(SDL_Event *ev) void sdl2_poll_events(struct sdl2_console *scon) { SDL_Event ev1, *ev = &ev1; + int idle = 1; if (scon->last_vm_running != runstate_is_running()) { scon->last_vm_running = runstate_is_running(); @@ -587,12 +592,15 @@ void sdl2_poll_events(struct sdl2_console *scon) while (SDL_PollEvent(ev)) { switch (ev->type) { case SDL_KEYDOWN: + idle = 0; handle_keydown(ev); break; case SDL_KEYUP: + idle = 0; handle_keyup(ev); break; case SDL_TEXTINPUT: + idle = 0; handle_textinput(ev); break; case SDL_QUIT: @@ -602,13 +610,16 @@ void sdl2_poll_events(struct sdl2_console *scon) } break; case SDL_MOUSEMOTION: + idle = 0; handle_mousemotion(ev); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: + idle = 0; handle_mousebutton(ev); break; case SDL_MOUSEWHEEL: + idle = 0; handle_mousewheel(ev); break; case SDL_WINDOWEVENT: @@ -618,6 +629,18 @@ void sdl2_poll_events(struct sdl2_console *scon) break; } } + + if (idle) { + if (scon->idle_counter < SDL2_MAX_IDLE_COUNT) { + scon->idle_counter++; + if (scon->idle_counter >= SDL2_MAX_IDLE_COUNT) { + scon->dcl.update_interval = GUI_REFRESH_INTERVAL_DEFAULT; + } + } + } else { + scon->idle_counter = 0; + scon->dcl.update_interval = SDL2_REFRESH_INTERVAL_BUSY; + } } static void sdl_mouse_warp(DisplayChangeListener *dcl, |