Compare commits
128 Commits
v2.8.1
...
pull-ui-20
Author | SHA1 | Date | |
---|---|---|---|
|
e934644126 | ||
|
f27ff81070 | ||
|
97efe4f961 | ||
|
c952b71582 | ||
|
6250dff39a | ||
|
d825367172 | ||
|
f29b3431f6 | ||
|
b3cb21b9b5 | ||
|
a8ffb372a2 | ||
|
3d4da9d6f3 | ||
|
e92fbc753d | ||
|
9c904a7581 | ||
|
12597061b3 | ||
|
5e5db49953 | ||
|
82a4118694 | ||
|
a7c8215e3b | ||
|
684e508c23 | ||
|
aff8fd18f1 | ||
|
23425cc2b7 | ||
|
9ef9d40261 | ||
|
0d9d86fb4d | ||
|
ee68697551 | ||
|
0062ea0fd6 | ||
|
4a1cba3802 | ||
|
f6a51c84cd | ||
|
721671ade7 | ||
|
0891ee1112 | ||
|
a37c07022b | ||
|
ba0d10378c | ||
|
04b88c84a1 | ||
|
5c3df1f096 | ||
|
6cc9906b4c | ||
|
baecbde6d7 | ||
|
1211d81b17 | ||
|
d5ebc8272b | ||
|
f2b58c4375 | ||
|
88da0b0301 | ||
|
bcb8998fac | ||
|
ea83441cc4 | ||
|
583f21f8b9 | ||
|
204f01b309 | ||
|
33243031da | ||
|
b8e23926c5 | ||
|
dbe2b65566 | ||
|
2b5e217067 | ||
|
0194cf31cf | ||
|
367790cce8 | ||
|
72d2e4b6a4 | ||
|
7b542eb96d | ||
|
14f944063a | ||
|
fb5543d820 | ||
|
0ccb9c1d81 | ||
|
8be95defd6 | ||
|
817af1c72d | ||
|
f84aab269d | ||
|
8a1e52b69d | ||
|
0f72559fbc | ||
|
91db4642f8 | ||
|
9e41bade85 | ||
|
8e953a658f | ||
|
26d5df9578 | ||
|
0584d3c33f | ||
|
c491e1521f | ||
|
bd407a21a9 | ||
|
6efbac908f | ||
|
74af4eec29 | ||
|
ef17f83661 | ||
|
6a0e947b12 | ||
|
bd673bd8ab | ||
|
4c3386f421 | ||
|
2d105bd6b5 | ||
|
e03192fd62 | ||
|
e353aac51b | ||
|
0bfa02595a | ||
|
e971fa0422 | ||
|
c9b61d9aa1 | ||
|
92204403ef | ||
|
0a97c40f8e | ||
|
416d72b97b | ||
|
0f1944735b | ||
|
2494c9f640 | ||
|
450aaae863 | ||
|
e5fdf663cf | ||
|
e45d4ef6e3 | ||
|
65839b56b9 | ||
|
a470b33259 | ||
|
c76904ef2f | ||
|
6c7c3c21f9 | ||
|
c52ab08aee | ||
|
6053a86fe7 | ||
|
bc20403598 | ||
|
166dbda7e1 | ||
|
8929fc3a55 | ||
|
96a3d39277 | ||
|
e3592bc9d8 | ||
|
feddd2fd91 | ||
|
272f042877 | ||
|
be232eb076 | ||
|
638cbd452d | ||
|
722f8d9099 | ||
|
11717bc93a | ||
|
45241cf9d7 | ||
|
8caa05d889 | ||
|
e7a9f35321 | ||
|
c17a18ef30 | ||
|
a273f4cedf | ||
|
5ffb350541 | ||
|
eb7a20a361 | ||
|
1f4e496e1f | ||
|
715c31ec8e | ||
|
0ce265ffef | ||
|
2651efe7f5 | ||
|
225adf16d2 | ||
|
4fd460bf25 | ||
|
f4d7674722 | ||
|
e11680524a | ||
|
5ce9cfe737 | ||
|
12a4f2162a | ||
|
1f923c70bd | ||
|
d1e8e8ecc3 | ||
|
ffb7bf452a | ||
|
d4c64800bb | ||
|
9443598d7e | ||
|
893dcdbfa9 | ||
|
fcf5ef2ab5 | ||
|
82ecffa8c0 | ||
|
9b7621bca2 | ||
|
abd7f08b23 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -82,10 +82,6 @@
|
||||
*.d
|
||||
!/scripts/qemu-guest-agent/fsfreeze-hook.d
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
*.pc
|
||||
.libs
|
||||
.sdk
|
||||
*.gcda
|
||||
*.gcno
|
||||
|
18
HACKING
18
HACKING
@@ -1,10 +1,28 @@
|
||||
1. Preprocessor
|
||||
|
||||
1.1. Variadic macros
|
||||
|
||||
For variadic macros, stick with this C99-like syntax:
|
||||
|
||||
#define DPRINTF(fmt, ...) \
|
||||
do { printf("IRQ: " fmt, ## __VA_ARGS__); } while (0)
|
||||
|
||||
1.2. Include directives
|
||||
|
||||
Order include directives as follows:
|
||||
|
||||
#include "qemu/osdep.h" /* Always first... */
|
||||
#include <...> /* then system headers... */
|
||||
#include "..." /* and finally QEMU headers. */
|
||||
|
||||
The "qemu/osdep.h" header contains preprocessor macros that affect the behavior
|
||||
of core system headers like <stdint.h>. It must be the first include so that
|
||||
core system headers included by external libraries get the preprocessor macros
|
||||
that QEMU depends on.
|
||||
|
||||
Do not include "qemu/osdep.h" from header files since the .c file will have
|
||||
already included it.
|
||||
|
||||
2. C types
|
||||
|
||||
It should be common sense to use the right type, but we have collected
|
||||
|
48
MAINTAINERS
48
MAINTAINERS
@@ -106,7 +106,7 @@ F: include/fpu/
|
||||
Alpha
|
||||
M: Richard Henderson <rth@twiddle.net>
|
||||
S: Maintained
|
||||
F: target-alpha/
|
||||
F: target/alpha/
|
||||
F: hw/alpha/
|
||||
F: tests/tcg/alpha/
|
||||
F: disas/alpha.c
|
||||
@@ -115,7 +115,7 @@ ARM
|
||||
M: Peter Maydell <peter.maydell@linaro.org>
|
||||
L: qemu-arm@nongnu.org
|
||||
S: Maintained
|
||||
F: target-arm/
|
||||
F: target/arm/
|
||||
F: hw/arm/
|
||||
F: hw/cpu/a*mpcore.c
|
||||
F: include/hw/cpu/a*mpcore.h
|
||||
@@ -126,7 +126,7 @@ F: disas/libvixl/
|
||||
CRIS
|
||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
||||
S: Maintained
|
||||
F: target-cris/
|
||||
F: target/cris/
|
||||
F: hw/cris/
|
||||
F: include/hw/cris/
|
||||
F: tests/tcg/cris/
|
||||
@@ -135,7 +135,7 @@ F: disas/cris.c
|
||||
LM32
|
||||
M: Michael Walle <michael@walle.cc>
|
||||
S: Maintained
|
||||
F: target-lm32/
|
||||
F: target/lm32/
|
||||
F: disas/lm32.c
|
||||
F: hw/lm32/
|
||||
F: hw/*/lm32_*
|
||||
@@ -147,13 +147,13 @@ F: tests/tcg/lm32/
|
||||
M68K
|
||||
M: Laurent Vivier <laurent@vivier.eu>
|
||||
S: Maintained
|
||||
F: target-m68k/
|
||||
F: target/m68k/
|
||||
F: disas/m68k.c
|
||||
|
||||
MicroBlaze
|
||||
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
|
||||
S: Maintained
|
||||
F: target-microblaze/
|
||||
F: target/microblaze/
|
||||
F: hw/microblaze/
|
||||
F: disas/microblaze.c
|
||||
|
||||
@@ -161,7 +161,7 @@ MIPS
|
||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
||||
M: Yongbok Kim <yongbok.kim@imgtec.com>
|
||||
S: Maintained
|
||||
F: target-mips/
|
||||
F: target/mips/
|
||||
F: hw/mips/
|
||||
F: hw/misc/mips_*
|
||||
F: hw/intc/mips_gic.c
|
||||
@@ -176,7 +176,7 @@ F: disas/mips.c
|
||||
Moxie
|
||||
M: Anthony Green <green@moxielogic.com>
|
||||
S: Maintained
|
||||
F: target-moxie/
|
||||
F: target/moxie/
|
||||
F: disas/moxie.c
|
||||
F: hw/moxie/
|
||||
F: default-configs/moxie-softmmu.mak
|
||||
@@ -184,7 +184,7 @@ F: default-configs/moxie-softmmu.mak
|
||||
OpenRISC
|
||||
M: Jia Liu <proljc@gmail.com>
|
||||
S: Maintained
|
||||
F: target-openrisc/
|
||||
F: target/openrisc/
|
||||
F: hw/openrisc/
|
||||
F: tests/tcg/openrisc/
|
||||
|
||||
@@ -193,7 +193,7 @@ M: David Gibson <david@gibson.dropbear.id.au>
|
||||
M: Alexander Graf <agraf@suse.de>
|
||||
L: qemu-ppc@nongnu.org
|
||||
S: Maintained
|
||||
F: target-ppc/
|
||||
F: target/ppc/
|
||||
F: hw/ppc/
|
||||
F: include/hw/ppc/
|
||||
F: disas/ppc.c
|
||||
@@ -202,14 +202,14 @@ S390
|
||||
M: Richard Henderson <rth@twiddle.net>
|
||||
M: Alexander Graf <agraf@suse.de>
|
||||
S: Maintained
|
||||
F: target-s390x/
|
||||
F: target/s390x/
|
||||
F: hw/s390x/
|
||||
F: disas/s390.c
|
||||
|
||||
SH4
|
||||
M: Aurelien Jarno <aurelien@aurel32.net>
|
||||
S: Odd Fixes
|
||||
F: target-sh4/
|
||||
F: target/sh4/
|
||||
F: hw/sh4/
|
||||
F: disas/sh4.c
|
||||
F: include/hw/sh4/
|
||||
@@ -218,7 +218,7 @@ SPARC
|
||||
M: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
|
||||
M: Artyom Tarasenko <atar4qemu@gmail.com>
|
||||
S: Maintained
|
||||
F: target-sparc/
|
||||
F: target/sparc/
|
||||
F: hw/sparc/
|
||||
F: hw/sparc64/
|
||||
F: disas/sparc.c
|
||||
@@ -226,7 +226,7 @@ F: disas/sparc.c
|
||||
UniCore32
|
||||
M: Guan Xuetao <gxt@mprc.pku.edu.cn>
|
||||
S: Maintained
|
||||
F: target-unicore32/
|
||||
F: target/unicore32/
|
||||
F: hw/unicore32/
|
||||
F: include/hw/unicore32/
|
||||
|
||||
@@ -235,7 +235,7 @@ M: Paolo Bonzini <pbonzini@redhat.com>
|
||||
M: Richard Henderson <rth@twiddle.net>
|
||||
M: Eduardo Habkost <ehabkost@redhat.com>
|
||||
S: Maintained
|
||||
F: target-i386/
|
||||
F: target/i386/
|
||||
F: hw/i386/
|
||||
F: disas/i386.c
|
||||
|
||||
@@ -243,14 +243,14 @@ Xtensa
|
||||
M: Max Filippov <jcmvbkbc@gmail.com>
|
||||
W: http://wiki.osll.spb.ru/doku.php?id=etc:users:jcmvbkbc:qemu-target-xtensa
|
||||
S: Maintained
|
||||
F: target-xtensa/
|
||||
F: target/xtensa/
|
||||
F: hw/xtensa/
|
||||
F: tests/tcg/xtensa/
|
||||
|
||||
TriCore
|
||||
M: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
|
||||
S: Maintained
|
||||
F: target-tricore/
|
||||
F: target/tricore/
|
||||
F: hw/tricore/
|
||||
F: include/hw/tricore/
|
||||
|
||||
@@ -269,26 +269,26 @@ ARM
|
||||
M: Peter Maydell <peter.maydell@linaro.org>
|
||||
L: qemu-arm@nongnu.org
|
||||
S: Maintained
|
||||
F: target-arm/kvm.c
|
||||
F: target/arm/kvm.c
|
||||
|
||||
MIPS
|
||||
M: James Hogan <james.hogan@imgtec.com>
|
||||
S: Maintained
|
||||
F: target-mips/kvm.c
|
||||
F: target/mips/kvm.c
|
||||
|
||||
PPC
|
||||
M: Alexander Graf <agraf@suse.de>
|
||||
S: Maintained
|
||||
F: target-ppc/kvm.c
|
||||
F: target/ppc/kvm.c
|
||||
|
||||
S390
|
||||
M: Christian Borntraeger <borntraeger@de.ibm.com>
|
||||
M: Cornelia Huck <cornelia.huck@de.ibm.com>
|
||||
M: Alexander Graf <agraf@suse.de>
|
||||
S: Maintained
|
||||
F: target-s390x/kvm.c
|
||||
F: target-s390x/ioinst.[ch]
|
||||
F: target-s390x/machine.c
|
||||
F: target/s390x/kvm.c
|
||||
F: target/s390x/ioinst.[ch]
|
||||
F: target/s390x/machine.c
|
||||
F: hw/intc/s390_flic.c
|
||||
F: hw/intc/s390_flic_kvm.c
|
||||
F: include/hw/s390x/s390_flic.h
|
||||
@@ -301,7 +301,7 @@ M: Paolo Bonzini <pbonzini@redhat.com>
|
||||
M: Marcelo Tosatti <mtosatti@redhat.com>
|
||||
L: kvm@vger.kernel.org
|
||||
S: Supported
|
||||
F: target-i386/kvm.c
|
||||
F: target/i386/kvm.c
|
||||
|
||||
Guest CPU Cores (Xen):
|
||||
----------------------
|
||||
|
9
Makefile
9
Makefile
@@ -231,12 +231,10 @@ ALL_SUBDIRS=$(TARGET_DIRS) $(patsubst %,pc-bios/%, $(ROMS))
|
||||
|
||||
recurse-all: $(SUBDIR_RULES) $(ROMSUBDIR_RULES)
|
||||
|
||||
$(BUILD_DIR)/version.o: $(SRC_PATH)/version.rc config-host.h | $(BUILD_DIR)/version.lo
|
||||
$(BUILD_DIR)/version.o: $(SRC_PATH)/version.rc config-host.h
|
||||
$(call quiet-command,$(WINDRES) -I$(BUILD_DIR) -o $@ $<,"RC","version.o")
|
||||
$(BUILD_DIR)/version.lo: $(SRC_PATH)/version.rc config-host.h
|
||||
$(call quiet-command,$(WINDRES) -I$(BUILD_DIR) -o $@ $<,"RC","version.lo")
|
||||
|
||||
Makefile: $(version-obj-y) $(version-lobj-y)
|
||||
Makefile: $(version-obj-y)
|
||||
|
||||
######################################################################
|
||||
# Build libraries
|
||||
@@ -358,10 +356,9 @@ clean:
|
||||
rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
|
||||
rm -f qemu-options.def
|
||||
rm -f *.msi
|
||||
find . \( -name '*.l[oa]' -o -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name '*.[oda]' \) -type f -exec rm {} +
|
||||
find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name '*.[oda]' \) -type f -exec rm {} +
|
||||
rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
|
||||
rm -f fsdev/*.pod
|
||||
rm -rf .libs */.libs
|
||||
rm -f qemu-img-cmds.h
|
||||
rm -f ui/shader/*-vert.h ui/shader/*-frag.h
|
||||
@# May not be present in GENERATED_HEADERS
|
||||
|
@@ -97,7 +97,6 @@ common-obj-y += disas/
|
||||
######################################################################
|
||||
# Resource file for Windows executables
|
||||
version-obj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.o
|
||||
version-lobj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.lo
|
||||
|
||||
######################################################################
|
||||
# tracing
|
||||
@@ -155,11 +154,11 @@ trace-events-y += hw/alpha/trace-events
|
||||
trace-events-y += ui/trace-events
|
||||
trace-events-y += audio/trace-events
|
||||
trace-events-y += net/trace-events
|
||||
trace-events-y += target-arm/trace-events
|
||||
trace-events-y += target-i386/trace-events
|
||||
trace-events-y += target-sparc/trace-events
|
||||
trace-events-y += target-s390x/trace-events
|
||||
trace-events-y += target-ppc/trace-events
|
||||
trace-events-y += target/arm/trace-events
|
||||
trace-events-y += target/i386/trace-events
|
||||
trace-events-y += target/sparc/trace-events
|
||||
trace-events-y += target/s390x/trace-events
|
||||
trace-events-y += target/ppc/trace-events
|
||||
trace-events-y += qom/trace-events
|
||||
trace-events-y += linux-user/trace-events
|
||||
trace-events-y += qapi/trace-events
|
||||
|
@@ -11,7 +11,7 @@ $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
|
||||
ifdef CONFIG_LINUX
|
||||
QEMU_CFLAGS += -I../linux-headers
|
||||
endif
|
||||
QEMU_CFLAGS += -I.. -I$(SRC_PATH)/target-$(TARGET_BASE_ARCH) -DNEED_CPU_H
|
||||
QEMU_CFLAGS += -I.. -I$(SRC_PATH)/target/$(TARGET_BASE_ARCH) -DNEED_CPU_H
|
||||
|
||||
QEMU_CFLAGS+=-I$(SRC_PATH)/include
|
||||
|
||||
@@ -76,6 +76,7 @@ $(QEMU_PROG)-simpletrace.stp: $(BUILD_DIR)/trace-events-all
|
||||
else
|
||||
stap:
|
||||
endif
|
||||
.PHONY: stap
|
||||
|
||||
all: $(PROGS) stap
|
||||
|
||||
@@ -92,7 +93,7 @@ obj-$(CONFIG_TCG_INTERPRETER) += tci.o
|
||||
obj-y += tcg/tcg-common.o
|
||||
obj-$(CONFIG_TCG_INTERPRETER) += disas/tci.o
|
||||
obj-y += fpu/softfloat.o
|
||||
obj-y += target-$(TARGET_BASE_ARCH)/
|
||||
obj-y += target/$(TARGET_BASE_ARCH)/
|
||||
obj-y += disas.o
|
||||
obj-y += tcg-runtime.o
|
||||
obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o
|
||||
|
262
aio-posix.c
262
aio-posix.c
@@ -18,6 +18,8 @@
|
||||
#include "block/block.h"
|
||||
#include "qemu/queue.h"
|
||||
#include "qemu/sockets.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "trace.h"
|
||||
#ifdef CONFIG_EPOLL_CREATE1
|
||||
#include <sys/epoll.h>
|
||||
#endif
|
||||
@@ -27,6 +29,9 @@ struct AioHandler
|
||||
GPollFD pfd;
|
||||
IOHandler *io_read;
|
||||
IOHandler *io_write;
|
||||
AioPollFn *io_poll;
|
||||
IOHandler *io_poll_begin;
|
||||
IOHandler *io_poll_end;
|
||||
int deleted;
|
||||
void *opaque;
|
||||
bool is_external;
|
||||
@@ -200,6 +205,7 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
bool is_external,
|
||||
IOHandler *io_read,
|
||||
IOHandler *io_write,
|
||||
AioPollFn *io_poll,
|
||||
void *opaque)
|
||||
{
|
||||
AioHandler *node;
|
||||
@@ -209,7 +215,7 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
node = find_aio_handler(ctx, fd);
|
||||
|
||||
/* Are we deleting the fd handler? */
|
||||
if (!io_read && !io_write) {
|
||||
if (!io_read && !io_write && !io_poll) {
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -228,6 +234,10 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
QLIST_REMOVE(node, node);
|
||||
deleted = true;
|
||||
}
|
||||
|
||||
if (!node->io_poll) {
|
||||
ctx->poll_disable_cnt--;
|
||||
}
|
||||
} else {
|
||||
if (node == NULL) {
|
||||
/* Alloc and insert if it's not already there */
|
||||
@@ -237,10 +247,16 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
|
||||
g_source_add_poll(&ctx->source, &node->pfd);
|
||||
is_new = true;
|
||||
|
||||
ctx->poll_disable_cnt += !io_poll;
|
||||
} else {
|
||||
ctx->poll_disable_cnt += !io_poll - !node->io_poll;
|
||||
}
|
||||
|
||||
/* Update handler with latest information */
|
||||
node->io_read = io_read;
|
||||
node->io_write = io_write;
|
||||
node->io_poll = io_poll;
|
||||
node->opaque = opaque;
|
||||
node->is_external = is_external;
|
||||
|
||||
@@ -250,22 +266,83 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
|
||||
aio_epoll_update(ctx, node, is_new);
|
||||
aio_notify(ctx);
|
||||
|
||||
if (deleted) {
|
||||
g_free(node);
|
||||
}
|
||||
}
|
||||
|
||||
void aio_set_fd_poll(AioContext *ctx, int fd,
|
||||
IOHandler *io_poll_begin,
|
||||
IOHandler *io_poll_end)
|
||||
{
|
||||
AioHandler *node = find_aio_handler(ctx, fd);
|
||||
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
node->io_poll_begin = io_poll_begin;
|
||||
node->io_poll_end = io_poll_end;
|
||||
}
|
||||
|
||||
void aio_set_event_notifier(AioContext *ctx,
|
||||
EventNotifier *notifier,
|
||||
bool is_external,
|
||||
EventNotifierHandler *io_read)
|
||||
EventNotifierHandler *io_read,
|
||||
AioPollFn *io_poll)
|
||||
{
|
||||
aio_set_fd_handler(ctx, event_notifier_get_fd(notifier),
|
||||
is_external, (IOHandler *)io_read, NULL, notifier);
|
||||
aio_set_fd_handler(ctx, event_notifier_get_fd(notifier), is_external,
|
||||
(IOHandler *)io_read, NULL, io_poll, notifier);
|
||||
}
|
||||
|
||||
void aio_set_event_notifier_poll(AioContext *ctx,
|
||||
EventNotifier *notifier,
|
||||
EventNotifierHandler *io_poll_begin,
|
||||
EventNotifierHandler *io_poll_end)
|
||||
{
|
||||
aio_set_fd_poll(ctx, event_notifier_get_fd(notifier),
|
||||
(IOHandler *)io_poll_begin,
|
||||
(IOHandler *)io_poll_end);
|
||||
}
|
||||
|
||||
static void poll_set_started(AioContext *ctx, bool started)
|
||||
{
|
||||
AioHandler *node;
|
||||
|
||||
if (started == ctx->poll_started) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->poll_started = started;
|
||||
|
||||
ctx->walking_handlers++;
|
||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
||||
IOHandler *fn;
|
||||
|
||||
if (node->deleted) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (started) {
|
||||
fn = node->io_poll_begin;
|
||||
} else {
|
||||
fn = node->io_poll_end;
|
||||
}
|
||||
|
||||
if (fn) {
|
||||
fn(node->opaque);
|
||||
}
|
||||
}
|
||||
ctx->walking_handlers--;
|
||||
}
|
||||
|
||||
|
||||
bool aio_prepare(AioContext *ctx)
|
||||
{
|
||||
/* Poll mode cannot be used with glib's event loop, disable it. */
|
||||
poll_set_started(ctx, false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -290,9 +367,13 @@ bool aio_pending(AioContext *ctx)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool aio_dispatch(AioContext *ctx)
|
||||
/*
|
||||
* Note that dispatch_fds == false has the side-effect of post-poning the
|
||||
* freeing of deleted handlers.
|
||||
*/
|
||||
bool aio_dispatch(AioContext *ctx, bool dispatch_fds)
|
||||
{
|
||||
AioHandler *node;
|
||||
AioHandler *node = NULL;
|
||||
bool progress = false;
|
||||
|
||||
/*
|
||||
@@ -308,7 +389,9 @@ bool aio_dispatch(AioContext *ctx)
|
||||
* We have to walk very carefully in case aio_set_fd_handler is
|
||||
* called while we're walking.
|
||||
*/
|
||||
if (dispatch_fds) {
|
||||
node = QLIST_FIRST(&ctx->aio_handlers);
|
||||
}
|
||||
while (node) {
|
||||
AioHandler *tmp;
|
||||
int revents;
|
||||
@@ -400,12 +483,100 @@ static void add_pollfd(AioHandler *node)
|
||||
npfd++;
|
||||
}
|
||||
|
||||
static bool run_poll_handlers_once(AioContext *ctx)
|
||||
{
|
||||
bool progress = false;
|
||||
AioHandler *node;
|
||||
|
||||
QLIST_FOREACH(node, &ctx->aio_handlers, node) {
|
||||
if (!node->deleted && node->io_poll &&
|
||||
node->io_poll(node->opaque)) {
|
||||
progress = true;
|
||||
}
|
||||
|
||||
/* Caller handles freeing deleted nodes. Don't do it here. */
|
||||
}
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
/* run_poll_handlers:
|
||||
* @ctx: the AioContext
|
||||
* @max_ns: maximum time to poll for, in nanoseconds
|
||||
*
|
||||
* Polls for a given time.
|
||||
*
|
||||
* Note that ctx->notify_me must be non-zero so this function can detect
|
||||
* aio_notify().
|
||||
*
|
||||
* Note that the caller must have incremented ctx->walking_handlers.
|
||||
*
|
||||
* Returns: true if progress was made, false otherwise
|
||||
*/
|
||||
static bool run_poll_handlers(AioContext *ctx, int64_t max_ns)
|
||||
{
|
||||
bool progress;
|
||||
int64_t end_time;
|
||||
|
||||
assert(ctx->notify_me);
|
||||
assert(ctx->walking_handlers > 0);
|
||||
assert(ctx->poll_disable_cnt == 0);
|
||||
|
||||
trace_run_poll_handlers_begin(ctx, max_ns);
|
||||
|
||||
end_time = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + max_ns;
|
||||
|
||||
do {
|
||||
progress = run_poll_handlers_once(ctx);
|
||||
} while (!progress && qemu_clock_get_ns(QEMU_CLOCK_REALTIME) < end_time);
|
||||
|
||||
trace_run_poll_handlers_end(ctx, progress);
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
/* try_poll_mode:
|
||||
* @ctx: the AioContext
|
||||
* @blocking: busy polling is only attempted when blocking is true
|
||||
*
|
||||
* ctx->notify_me must be non-zero so this function can detect aio_notify().
|
||||
*
|
||||
* Note that the caller must have incremented ctx->walking_handlers.
|
||||
*
|
||||
* Returns: true if progress was made, false otherwise
|
||||
*/
|
||||
static bool try_poll_mode(AioContext *ctx, bool blocking)
|
||||
{
|
||||
if (blocking && ctx->poll_max_ns && ctx->poll_disable_cnt == 0) {
|
||||
/* See qemu_soonest_timeout() uint64_t hack */
|
||||
int64_t max_ns = MIN((uint64_t)aio_compute_timeout(ctx),
|
||||
(uint64_t)ctx->poll_ns);
|
||||
|
||||
if (max_ns) {
|
||||
poll_set_started(ctx, true);
|
||||
|
||||
if (run_poll_handlers(ctx, max_ns)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
poll_set_started(ctx, false);
|
||||
|
||||
/* Even if we don't run busy polling, try polling once in case it can make
|
||||
* progress and the caller will be able to avoid ppoll(2)/epoll_wait(2).
|
||||
*/
|
||||
return run_poll_handlers_once(ctx);
|
||||
}
|
||||
|
||||
bool aio_poll(AioContext *ctx, bool blocking)
|
||||
{
|
||||
AioHandler *node;
|
||||
int i, ret;
|
||||
int i;
|
||||
int ret = 0;
|
||||
bool progress;
|
||||
int64_t timeout;
|
||||
int64_t start = 0;
|
||||
|
||||
aio_context_acquire(ctx);
|
||||
progress = false;
|
||||
@@ -423,6 +594,13 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
|
||||
ctx->walking_handlers++;
|
||||
|
||||
if (ctx->poll_max_ns) {
|
||||
start = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
|
||||
}
|
||||
|
||||
if (try_poll_mode(ctx, blocking)) {
|
||||
progress = true;
|
||||
} else {
|
||||
assert(npfd == 0);
|
||||
|
||||
/* fill pollfds */
|
||||
@@ -453,11 +631,54 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
} else {
|
||||
ret = qemu_poll_ns(pollfds, npfd, timeout);
|
||||
}
|
||||
if (timeout) {
|
||||
aio_context_acquire(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
if (blocking) {
|
||||
atomic_sub(&ctx->notify_me, 2);
|
||||
}
|
||||
if (timeout) {
|
||||
aio_context_acquire(ctx);
|
||||
|
||||
/* Adjust polling time */
|
||||
if (ctx->poll_max_ns) {
|
||||
int64_t block_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start;
|
||||
|
||||
if (block_ns <= ctx->poll_ns) {
|
||||
/* This is the sweet spot, no adjustment needed */
|
||||
} else if (block_ns > ctx->poll_max_ns) {
|
||||
/* We'd have to poll for too long, poll less */
|
||||
int64_t old = ctx->poll_ns;
|
||||
|
||||
if (ctx->poll_shrink) {
|
||||
ctx->poll_ns /= ctx->poll_shrink;
|
||||
} else {
|
||||
ctx->poll_ns = 0;
|
||||
}
|
||||
|
||||
trace_poll_shrink(ctx, old, ctx->poll_ns);
|
||||
} else if (ctx->poll_ns < ctx->poll_max_ns &&
|
||||
block_ns < ctx->poll_max_ns) {
|
||||
/* There is room to grow, poll longer */
|
||||
int64_t old = ctx->poll_ns;
|
||||
int64_t grow = ctx->poll_grow;
|
||||
|
||||
if (grow == 0) {
|
||||
grow = 2;
|
||||
}
|
||||
|
||||
if (ctx->poll_ns) {
|
||||
ctx->poll_ns *= grow;
|
||||
} else {
|
||||
ctx->poll_ns = 4000; /* start polling at 4 microseconds */
|
||||
}
|
||||
|
||||
if (ctx->poll_ns > ctx->poll_max_ns) {
|
||||
ctx->poll_ns = ctx->poll_max_ns;
|
||||
}
|
||||
|
||||
trace_poll_grow(ctx, old, ctx->poll_ns);
|
||||
}
|
||||
}
|
||||
|
||||
aio_notify_accept(ctx);
|
||||
@@ -473,7 +694,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
ctx->walking_handlers--;
|
||||
|
||||
/* Run dispatch even if there were no readable fds to run timers */
|
||||
if (aio_dispatch(ctx)) {
|
||||
if (aio_dispatch(ctx, ret > 0)) {
|
||||
progress = true;
|
||||
}
|
||||
|
||||
@@ -484,6 +705,13 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
|
||||
void aio_context_setup(AioContext *ctx)
|
||||
{
|
||||
/* TODO remove this in final patch submission */
|
||||
if (getenv("QEMU_AIO_POLL_MAX_NS")) {
|
||||
fprintf(stderr, "The QEMU_AIO_POLL_MAX_NS environment variable has "
|
||||
"been replaced with -object iothread,poll-max-ns=NUM\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EPOLL_CREATE1
|
||||
assert(!ctx->epollfd);
|
||||
ctx->epollfd = epoll_create1(EPOLL_CLOEXEC);
|
||||
@@ -495,3 +723,17 @@ void aio_context_setup(AioContext *ctx)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,
|
||||
int64_t grow, int64_t shrink, Error **errp)
|
||||
{
|
||||
/* No thread synchronization here, it doesn't matter if an incorrect value
|
||||
* is used once.
|
||||
*/
|
||||
ctx->poll_max_ns = max_ns;
|
||||
ctx->poll_ns = 0;
|
||||
ctx->poll_grow = grow;
|
||||
ctx->poll_shrink = shrink;
|
||||
|
||||
aio_notify(ctx);
|
||||
}
|
||||
|
30
aio-win32.c
30
aio-win32.c
@@ -20,6 +20,7 @@
|
||||
#include "block/block.h"
|
||||
#include "qemu/queue.h"
|
||||
#include "qemu/sockets.h"
|
||||
#include "qapi/error.h"
|
||||
|
||||
struct AioHandler {
|
||||
EventNotifier *e;
|
||||
@@ -38,6 +39,7 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
bool is_external,
|
||||
IOHandler *io_read,
|
||||
IOHandler *io_write,
|
||||
AioPollFn *io_poll,
|
||||
void *opaque)
|
||||
{
|
||||
/* fd is a SOCKET in our case */
|
||||
@@ -100,10 +102,18 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
aio_notify(ctx);
|
||||
}
|
||||
|
||||
void aio_set_fd_poll(AioContext *ctx, int fd,
|
||||
IOHandler *io_poll_begin,
|
||||
IOHandler *io_poll_end)
|
||||
{
|
||||
/* Not implemented */
|
||||
}
|
||||
|
||||
void aio_set_event_notifier(AioContext *ctx,
|
||||
EventNotifier *e,
|
||||
bool is_external,
|
||||
EventNotifierHandler *io_notify)
|
||||
EventNotifierHandler *io_notify,
|
||||
AioPollFn *io_poll)
|
||||
{
|
||||
AioHandler *node;
|
||||
|
||||
@@ -150,6 +160,14 @@ void aio_set_event_notifier(AioContext *ctx,
|
||||
aio_notify(ctx);
|
||||
}
|
||||
|
||||
void aio_set_event_notifier_poll(AioContext *ctx,
|
||||
EventNotifier *notifier,
|
||||
EventNotifierHandler *io_poll_begin,
|
||||
EventNotifierHandler *io_poll_end)
|
||||
{
|
||||
/* Not implemented */
|
||||
}
|
||||
|
||||
bool aio_prepare(AioContext *ctx)
|
||||
{
|
||||
static struct timeval tv0;
|
||||
@@ -271,12 +289,14 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event)
|
||||
return progress;
|
||||
}
|
||||
|
||||
bool aio_dispatch(AioContext *ctx)
|
||||
bool aio_dispatch(AioContext *ctx, bool dispatch_fds)
|
||||
{
|
||||
bool progress;
|
||||
|
||||
progress = aio_bh_poll(ctx);
|
||||
if (dispatch_fds) {
|
||||
progress |= aio_dispatch_handlers(ctx, INVALID_HANDLE_VALUE);
|
||||
}
|
||||
progress |= timerlistgroup_run_timers(&ctx->tlg);
|
||||
return progress;
|
||||
}
|
||||
@@ -374,3 +394,9 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
void aio_context_setup(AioContext *ctx)
|
||||
{
|
||||
}
|
||||
|
||||
void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,
|
||||
int64_t grow, int64_t shrink, Error **errp)
|
||||
{
|
||||
error_setg(errp, "AioContext polling is not implemented on Windows");
|
||||
}
|
||||
|
21
async.c
21
async.c
@@ -251,7 +251,7 @@ aio_ctx_dispatch(GSource *source,
|
||||
AioContext *ctx = (AioContext *) source;
|
||||
|
||||
assert(callback == NULL);
|
||||
aio_dispatch(ctx);
|
||||
aio_dispatch(ctx, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ aio_ctx_finalize(GSource *source)
|
||||
}
|
||||
qemu_mutex_unlock(&ctx->bh_lock);
|
||||
|
||||
aio_set_event_notifier(ctx, &ctx->notifier, false, NULL);
|
||||
aio_set_event_notifier(ctx, &ctx->notifier, false, NULL, NULL);
|
||||
event_notifier_cleanup(&ctx->notifier);
|
||||
qemu_rec_mutex_destroy(&ctx->lock);
|
||||
qemu_mutex_destroy(&ctx->bh_lock);
|
||||
@@ -349,6 +349,15 @@ static void event_notifier_dummy_cb(EventNotifier *e)
|
||||
{
|
||||
}
|
||||
|
||||
/* Returns true if aio_notify() was called (e.g. a BH was scheduled) */
|
||||
static bool event_notifier_poll(void *opaque)
|
||||
{
|
||||
EventNotifier *e = opaque;
|
||||
AioContext *ctx = container_of(e, AioContext, notifier);
|
||||
|
||||
return atomic_read(&ctx->notified);
|
||||
}
|
||||
|
||||
AioContext *aio_context_new(Error **errp)
|
||||
{
|
||||
int ret;
|
||||
@@ -366,7 +375,8 @@ AioContext *aio_context_new(Error **errp)
|
||||
aio_set_event_notifier(ctx, &ctx->notifier,
|
||||
false,
|
||||
(EventNotifierHandler *)
|
||||
event_notifier_dummy_cb);
|
||||
event_notifier_dummy_cb,
|
||||
event_notifier_poll);
|
||||
#ifdef CONFIG_LINUX_AIO
|
||||
ctx->linux_aio = NULL;
|
||||
#endif
|
||||
@@ -375,6 +385,11 @@ AioContext *aio_context_new(Error **errp)
|
||||
qemu_rec_mutex_init(&ctx->lock);
|
||||
timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx);
|
||||
|
||||
ctx->poll_ns = 0;
|
||||
ctx->poll_max_ns = 0;
|
||||
ctx->poll_grow = 0;
|
||||
ctx->poll_shrink = 0;
|
||||
|
||||
return ctx;
|
||||
fail:
|
||||
g_source_destroy(&ctx->source);
|
||||
|
@@ -27,12 +27,10 @@
|
||||
#include "sysemu/char.h"
|
||||
#include "qemu/timer.h"
|
||||
#include "hw/usb.h"
|
||||
#include "ui/console.h"
|
||||
#include <brlapi.h>
|
||||
#include <brlapi_constants.h>
|
||||
#include <brlapi_keycodes.h>
|
||||
#ifdef CONFIG_SDL
|
||||
#include <SDL_syswm.h>
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define DPRINTF(fmt, ...) \
|
||||
@@ -227,12 +225,8 @@ static const uint8_t nabcc_translation[2][256] = {
|
||||
/* The guest OS has started discussing with us, finish initializing BrlAPI */
|
||||
static int baum_deferred_init(BaumDriverState *baum)
|
||||
{
|
||||
#if defined(CONFIG_SDL)
|
||||
#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
|
||||
SDL_SysWMinfo info;
|
||||
#endif
|
||||
#endif
|
||||
int tty;
|
||||
int tty = BRLAPI_TTY_DEFAULT;
|
||||
QemuConsole *con;
|
||||
|
||||
if (baum->deferred_init) {
|
||||
return 1;
|
||||
@@ -243,21 +237,12 @@ static int baum_deferred_init(BaumDriverState *baum)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_SDL)
|
||||
#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
|
||||
memset(&info, 0, sizeof(info));
|
||||
SDL_VERSION(&info.version);
|
||||
if (SDL_GetWMInfo(&info)) {
|
||||
tty = info.info.x11.wmwindow;
|
||||
} else {
|
||||
#endif
|
||||
#endif
|
||||
con = qemu_console_lookup_by_index(0);
|
||||
if (con && qemu_console_is_graphic(con)) {
|
||||
tty = qemu_console_get_window_id(con);
|
||||
if (tty == -1)
|
||||
tty = BRLAPI_TTY_DEFAULT;
|
||||
#if defined(CONFIG_SDL)
|
||||
#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (brlapi__enterTtyMode(baum->brlapi, tty, NULL) == -1) {
|
||||
brlapi_perror("baum: brlapi__enterTtyMode");
|
||||
|
@@ -192,19 +192,19 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
|
||||
switch (action) {
|
||||
case CURL_POLL_IN:
|
||||
aio_set_fd_handler(s->aio_context, fd, false,
|
||||
curl_multi_read, NULL, state);
|
||||
curl_multi_read, NULL, NULL, state);
|
||||
break;
|
||||
case CURL_POLL_OUT:
|
||||
aio_set_fd_handler(s->aio_context, fd, false,
|
||||
NULL, curl_multi_do, state);
|
||||
NULL, curl_multi_do, NULL, state);
|
||||
break;
|
||||
case CURL_POLL_INOUT:
|
||||
aio_set_fd_handler(s->aio_context, fd, false,
|
||||
curl_multi_read, curl_multi_do, state);
|
||||
curl_multi_read, curl_multi_do, NULL, state);
|
||||
break;
|
||||
case CURL_POLL_REMOVE:
|
||||
aio_set_fd_handler(s->aio_context, fd, false,
|
||||
NULL, NULL, NULL);
|
||||
NULL, NULL, NULL, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -362,6 +362,7 @@ iscsi_set_events(IscsiLun *iscsilun)
|
||||
false,
|
||||
(ev & POLLIN) ? iscsi_process_read : NULL,
|
||||
(ev & POLLOUT) ? iscsi_process_write : NULL,
|
||||
NULL,
|
||||
iscsilun);
|
||||
iscsilun->events = ev;
|
||||
}
|
||||
@@ -498,18 +499,14 @@ iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sector_num,
|
||||
if (allocated) {
|
||||
bitmap_set(iscsilun->allocmap, cl_num_expanded, nb_cls_expanded);
|
||||
} else {
|
||||
if (nb_cls_shrunk > 0) {
|
||||
bitmap_clear(iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk);
|
||||
}
|
||||
}
|
||||
|
||||
if (iscsilun->allocmap_valid == NULL) {
|
||||
return;
|
||||
}
|
||||
if (valid) {
|
||||
if (nb_cls_shrunk > 0) {
|
||||
bitmap_set(iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk);
|
||||
}
|
||||
} else {
|
||||
bitmap_clear(iscsilun->allocmap_valid, cl_num_expanded,
|
||||
nb_cls_expanded);
|
||||
@@ -1530,7 +1527,7 @@ static void iscsi_detach_aio_context(BlockDriverState *bs)
|
||||
IscsiLun *iscsilun = bs->opaque;
|
||||
|
||||
aio_set_fd_handler(iscsilun->aio_context, iscsi_get_fd(iscsilun->iscsi),
|
||||
false, NULL, NULL, NULL);
|
||||
false, NULL, NULL, NULL, NULL);
|
||||
iscsilun->events = 0;
|
||||
|
||||
if (iscsilun->nop_timer) {
|
||||
|
@@ -255,6 +255,20 @@ static void qemu_laio_completion_cb(EventNotifier *e)
|
||||
}
|
||||
}
|
||||
|
||||
static bool qemu_laio_poll_cb(void *opaque)
|
||||
{
|
||||
EventNotifier *e = opaque;
|
||||
LinuxAioState *s = container_of(e, LinuxAioState, e);
|
||||
struct io_event *events;
|
||||
|
||||
if (!io_getevents_peek(s->ctx, &events)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
qemu_laio_process_completions_and_submit(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void laio_cancel(BlockAIOCB *blockacb)
|
||||
{
|
||||
struct qemu_laiocb *laiocb = (struct qemu_laiocb *)blockacb;
|
||||
@@ -439,7 +453,7 @@ BlockAIOCB *laio_submit(BlockDriverState *bs, LinuxAioState *s, int fd,
|
||||
|
||||
void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context)
|
||||
{
|
||||
aio_set_event_notifier(old_context, &s->e, false, NULL);
|
||||
aio_set_event_notifier(old_context, &s->e, false, NULL, NULL);
|
||||
qemu_bh_delete(s->completion_bh);
|
||||
}
|
||||
|
||||
@@ -448,7 +462,8 @@ void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context)
|
||||
s->aio_context = new_context;
|
||||
s->completion_bh = aio_bh_new(new_context, qemu_laio_completion_bh, s);
|
||||
aio_set_event_notifier(new_context, &s->e, false,
|
||||
qemu_laio_completion_cb);
|
||||
qemu_laio_completion_cb,
|
||||
qemu_laio_poll_cb);
|
||||
}
|
||||
|
||||
LinuxAioState *laio_init(void)
|
||||
|
@@ -145,7 +145,7 @@ static int nbd_co_send_request(BlockDriverState *bs,
|
||||
aio_context = bdrv_get_aio_context(bs);
|
||||
|
||||
aio_set_fd_handler(aio_context, s->sioc->fd, false,
|
||||
nbd_reply_ready, nbd_restart_write, bs);
|
||||
nbd_reply_ready, nbd_restart_write, NULL, bs);
|
||||
if (qiov) {
|
||||
qio_channel_set_cork(s->ioc, true);
|
||||
rc = nbd_send_request(s->ioc, request);
|
||||
@@ -161,7 +161,7 @@ static int nbd_co_send_request(BlockDriverState *bs,
|
||||
rc = nbd_send_request(s->ioc, request);
|
||||
}
|
||||
aio_set_fd_handler(aio_context, s->sioc->fd, false,
|
||||
nbd_reply_ready, NULL, bs);
|
||||
nbd_reply_ready, NULL, NULL, bs);
|
||||
s->send_coroutine = NULL;
|
||||
qemu_co_mutex_unlock(&s->send_mutex);
|
||||
return rc;
|
||||
@@ -366,14 +366,14 @@ void nbd_client_detach_aio_context(BlockDriverState *bs)
|
||||
{
|
||||
aio_set_fd_handler(bdrv_get_aio_context(bs),
|
||||
nbd_get_client_session(bs)->sioc->fd,
|
||||
false, NULL, NULL, NULL);
|
||||
false, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void nbd_client_attach_aio_context(BlockDriverState *bs,
|
||||
AioContext *new_context)
|
||||
{
|
||||
aio_set_fd_handler(new_context, nbd_get_client_session(bs)->sioc->fd,
|
||||
false, nbd_reply_ready, NULL, bs);
|
||||
false, nbd_reply_ready, NULL, NULL, bs);
|
||||
}
|
||||
|
||||
void nbd_client_close(BlockDriverState *bs)
|
||||
|
50
block/nfs.c
50
block/nfs.c
@@ -108,13 +108,12 @@ static int nfs_parse_uri(const char *filename, QDict *options, Error **errp)
|
||||
qdict_put(options, "path", qstring_from_str(uri->path));
|
||||
|
||||
for (i = 0; i < qp->n; i++) {
|
||||
unsigned long long val;
|
||||
if (!qp->p[i].value) {
|
||||
error_setg(errp, "Value for NFS parameter expected: %s",
|
||||
qp->p[i].name);
|
||||
goto out;
|
||||
}
|
||||
if (parse_uint_full(qp->p[i].value, &val, 0)) {
|
||||
if (parse_uint_full(qp->p[i].value, NULL, 0)) {
|
||||
error_setg(errp, "Illegal value for NFS parameter: %s",
|
||||
qp->p[i].name);
|
||||
goto out;
|
||||
@@ -198,7 +197,8 @@ static void nfs_set_events(NFSClient *client)
|
||||
aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context),
|
||||
false,
|
||||
(ev & POLLIN) ? nfs_process_read : NULL,
|
||||
(ev & POLLOUT) ? nfs_process_write : NULL, client);
|
||||
(ev & POLLOUT) ? nfs_process_write : NULL,
|
||||
NULL, client);
|
||||
|
||||
}
|
||||
client->events = ev;
|
||||
@@ -358,27 +358,27 @@ static QemuOptsList runtime_opts = {
|
||||
.help = "Path of the image on the host",
|
||||
},
|
||||
{
|
||||
.name = "user",
|
||||
.name = "uid",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "UID value to use when talking to the server",
|
||||
},
|
||||
{
|
||||
.name = "group",
|
||||
.name = "gid",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "GID value to use when talking to the server",
|
||||
},
|
||||
{
|
||||
.name = "tcp-syn-count",
|
||||
.name = "tcp-syncnt",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "Number of SYNs to send during the session establish",
|
||||
},
|
||||
{
|
||||
.name = "readahead-size",
|
||||
.name = "readahead",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "Set the readahead size in bytes",
|
||||
},
|
||||
{
|
||||
.name = "page-cache-size",
|
||||
.name = "pagecache",
|
||||
.type = QEMU_OPT_NUMBER,
|
||||
.help = "Set the pagecache size in bytes",
|
||||
},
|
||||
@@ -396,7 +396,7 @@ static void nfs_detach_aio_context(BlockDriverState *bs)
|
||||
NFSClient *client = bs->opaque;
|
||||
|
||||
aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context),
|
||||
false, NULL, NULL, NULL);
|
||||
false, NULL, NULL, NULL, NULL);
|
||||
client->events = 0;
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ static void nfs_client_close(NFSClient *client)
|
||||
nfs_close(client->context, client->fh);
|
||||
}
|
||||
aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context),
|
||||
false, NULL, NULL, NULL);
|
||||
false, NULL, NULL, NULL, NULL);
|
||||
nfs_destroy_context(client->context);
|
||||
}
|
||||
memset(client, 0, sizeof(NFSClient));
|
||||
@@ -507,29 +507,29 @@ static int64_t nfs_client_open(NFSClient *client, QDict *options,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (qemu_opt_get(opts, "user")) {
|
||||
client->uid = qemu_opt_get_number(opts, "user", 0);
|
||||
if (qemu_opt_get(opts, "uid")) {
|
||||
client->uid = qemu_opt_get_number(opts, "uid", 0);
|
||||
nfs_set_uid(client->context, client->uid);
|
||||
}
|
||||
|
||||
if (qemu_opt_get(opts, "group")) {
|
||||
client->gid = qemu_opt_get_number(opts, "group", 0);
|
||||
if (qemu_opt_get(opts, "gid")) {
|
||||
client->gid = qemu_opt_get_number(opts, "gid", 0);
|
||||
nfs_set_gid(client->context, client->gid);
|
||||
}
|
||||
|
||||
if (qemu_opt_get(opts, "tcp-syn-count")) {
|
||||
client->tcp_syncnt = qemu_opt_get_number(opts, "tcp-syn-count", 0);
|
||||
if (qemu_opt_get(opts, "tcp-syncnt")) {
|
||||
client->tcp_syncnt = qemu_opt_get_number(opts, "tcp-syncnt", 0);
|
||||
nfs_set_tcp_syncnt(client->context, client->tcp_syncnt);
|
||||
}
|
||||
|
||||
#ifdef LIBNFS_FEATURE_READAHEAD
|
||||
if (qemu_opt_get(opts, "readahead-size")) {
|
||||
if (qemu_opt_get(opts, "readahead")) {
|
||||
if (open_flags & BDRV_O_NOCACHE) {
|
||||
error_setg(errp, "Cannot enable NFS readahead "
|
||||
"if cache.direct = on");
|
||||
goto fail;
|
||||
}
|
||||
client->readahead = qemu_opt_get_number(opts, "readahead-size", 0);
|
||||
client->readahead = qemu_opt_get_number(opts, "readahead", 0);
|
||||
if (client->readahead > QEMU_NFS_MAX_READAHEAD_SIZE) {
|
||||
error_report("NFS Warning: Truncating NFS readahead "
|
||||
"size to %d", QEMU_NFS_MAX_READAHEAD_SIZE);
|
||||
@@ -544,13 +544,13 @@ static int64_t nfs_client_open(NFSClient *client, QDict *options,
|
||||
#endif
|
||||
|
||||
#ifdef LIBNFS_FEATURE_PAGECACHE
|
||||
if (qemu_opt_get(opts, "page-cache-size")) {
|
||||
if (qemu_opt_get(opts, "pagecache")) {
|
||||
if (open_flags & BDRV_O_NOCACHE) {
|
||||
error_setg(errp, "Cannot enable NFS pagecache "
|
||||
"if cache.direct = on");
|
||||
goto fail;
|
||||
}
|
||||
client->pagecache = qemu_opt_get_number(opts, "page-cache-size", 0);
|
||||
client->pagecache = qemu_opt_get_number(opts, "pagecache", 0);
|
||||
if (client->pagecache > QEMU_NFS_MAX_PAGECACHE_SIZE) {
|
||||
error_report("NFS Warning: Truncating NFS pagecache "
|
||||
"size to %d pages", QEMU_NFS_MAX_PAGECACHE_SIZE);
|
||||
@@ -803,21 +803,21 @@ static void nfs_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||
qdict_put(opts, "path", qstring_from_str(client->path));
|
||||
|
||||
if (client->uid) {
|
||||
qdict_put(opts, "user", qint_from_int(client->uid));
|
||||
qdict_put(opts, "uid", qint_from_int(client->uid));
|
||||
}
|
||||
if (client->gid) {
|
||||
qdict_put(opts, "group", qint_from_int(client->gid));
|
||||
qdict_put(opts, "gid", qint_from_int(client->gid));
|
||||
}
|
||||
if (client->tcp_syncnt) {
|
||||
qdict_put(opts, "tcp-syn-cnt",
|
||||
qdict_put(opts, "tcp-syncnt",
|
||||
qint_from_int(client->tcp_syncnt));
|
||||
}
|
||||
if (client->readahead) {
|
||||
qdict_put(opts, "readahead-size",
|
||||
qdict_put(opts, "readahead",
|
||||
qint_from_int(client->readahead));
|
||||
}
|
||||
if (client->pagecache) {
|
||||
qdict_put(opts, "page-cache-size",
|
||||
qdict_put(opts, "pagecache",
|
||||
qint_from_int(client->pagecache));
|
||||
}
|
||||
if (client->debug) {
|
||||
|
@@ -664,7 +664,7 @@ static coroutine_fn void do_co_req(void *opaque)
|
||||
|
||||
co = qemu_coroutine_self();
|
||||
aio_set_fd_handler(srco->aio_context, sockfd, false,
|
||||
NULL, restart_co_req, co);
|
||||
NULL, restart_co_req, NULL, co);
|
||||
|
||||
ret = send_co_req(sockfd, hdr, data, wlen);
|
||||
if (ret < 0) {
|
||||
@@ -672,7 +672,7 @@ static coroutine_fn void do_co_req(void *opaque)
|
||||
}
|
||||
|
||||
aio_set_fd_handler(srco->aio_context, sockfd, false,
|
||||
restart_co_req, NULL, co);
|
||||
restart_co_req, NULL, NULL, co);
|
||||
|
||||
ret = qemu_co_recv(sockfd, hdr, sizeof(*hdr));
|
||||
if (ret != sizeof(*hdr)) {
|
||||
@@ -698,7 +698,7 @@ out:
|
||||
/* there is at most one request for this sockfd, so it is safe to
|
||||
* set each handler to NULL. */
|
||||
aio_set_fd_handler(srco->aio_context, sockfd, false,
|
||||
NULL, NULL, NULL);
|
||||
NULL, NULL, NULL, NULL);
|
||||
|
||||
srco->ret = ret;
|
||||
srco->finished = true;
|
||||
@@ -760,7 +760,7 @@ static coroutine_fn void reconnect_to_sdog(void *opaque)
|
||||
AIOReq *aio_req, *next;
|
||||
|
||||
aio_set_fd_handler(s->aio_context, s->fd, false, NULL,
|
||||
NULL, NULL);
|
||||
NULL, NULL, NULL);
|
||||
close(s->fd);
|
||||
s->fd = -1;
|
||||
|
||||
@@ -964,7 +964,7 @@ static int get_sheep_fd(BDRVSheepdogState *s, Error **errp)
|
||||
}
|
||||
|
||||
aio_set_fd_handler(s->aio_context, fd, false,
|
||||
co_read_response, NULL, s);
|
||||
co_read_response, NULL, NULL, s);
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -1226,7 +1226,7 @@ static void coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req,
|
||||
qemu_co_mutex_lock(&s->lock);
|
||||
s->co_send = qemu_coroutine_self();
|
||||
aio_set_fd_handler(s->aio_context, s->fd, false,
|
||||
co_read_response, co_write_request, s);
|
||||
co_read_response, co_write_request, NULL, s);
|
||||
socket_set_cork(s->fd, 1);
|
||||
|
||||
/* send a header */
|
||||
@@ -1245,7 +1245,7 @@ static void coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req,
|
||||
out:
|
||||
socket_set_cork(s->fd, 0);
|
||||
aio_set_fd_handler(s->aio_context, s->fd, false,
|
||||
co_read_response, NULL, s);
|
||||
co_read_response, NULL, NULL, s);
|
||||
s->co_send = NULL;
|
||||
qemu_co_mutex_unlock(&s->lock);
|
||||
}
|
||||
@@ -1396,7 +1396,7 @@ static void sd_detach_aio_context(BlockDriverState *bs)
|
||||
BDRVSheepdogState *s = bs->opaque;
|
||||
|
||||
aio_set_fd_handler(s->aio_context, s->fd, false, NULL,
|
||||
NULL, NULL);
|
||||
NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static void sd_attach_aio_context(BlockDriverState *bs,
|
||||
@@ -1406,7 +1406,7 @@ static void sd_attach_aio_context(BlockDriverState *bs,
|
||||
|
||||
s->aio_context = new_context;
|
||||
aio_set_fd_handler(new_context, s->fd, false,
|
||||
co_read_response, NULL, s);
|
||||
co_read_response, NULL, NULL, s);
|
||||
}
|
||||
|
||||
/* TODO Convert to fine grained options */
|
||||
@@ -1520,7 +1520,7 @@ static int sd_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
return 0;
|
||||
out:
|
||||
aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd,
|
||||
false, NULL, NULL, NULL);
|
||||
false, NULL, NULL, NULL, NULL);
|
||||
if (s->fd >= 0) {
|
||||
closesocket(s->fd);
|
||||
}
|
||||
@@ -1559,7 +1559,7 @@ static void sd_reopen_commit(BDRVReopenState *state)
|
||||
|
||||
if (s->fd) {
|
||||
aio_set_fd_handler(s->aio_context, s->fd, false,
|
||||
NULL, NULL, NULL);
|
||||
NULL, NULL, NULL, NULL);
|
||||
closesocket(s->fd);
|
||||
}
|
||||
|
||||
@@ -1583,7 +1583,7 @@ static void sd_reopen_abort(BDRVReopenState *state)
|
||||
|
||||
if (re_s->fd) {
|
||||
aio_set_fd_handler(s->aio_context, re_s->fd, false,
|
||||
NULL, NULL, NULL);
|
||||
NULL, NULL, NULL, NULL);
|
||||
closesocket(re_s->fd);
|
||||
}
|
||||
|
||||
@@ -1972,7 +1972,7 @@ static void sd_close(BlockDriverState *bs)
|
||||
}
|
||||
|
||||
aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd,
|
||||
false, NULL, NULL, NULL);
|
||||
false, NULL, NULL, NULL, NULL);
|
||||
closesocket(s->fd);
|
||||
g_free(s->host_spec);
|
||||
}
|
||||
|
@@ -911,7 +911,7 @@ static coroutine_fn void set_fd_handler(BDRVSSHState *s, BlockDriverState *bs)
|
||||
rd_handler, wr_handler);
|
||||
|
||||
aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock,
|
||||
false, rd_handler, wr_handler, co);
|
||||
false, rd_handler, wr_handler, NULL, co);
|
||||
}
|
||||
|
||||
static coroutine_fn void clear_fd_handler(BDRVSSHState *s,
|
||||
@@ -919,7 +919,7 @@ static coroutine_fn void clear_fd_handler(BDRVSSHState *s,
|
||||
{
|
||||
DPRINTF("s->sock=%d", s->sock);
|
||||
aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock,
|
||||
false, NULL, NULL, NULL);
|
||||
false, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/* A non-blocking call returned EAGAIN, so yield, ensuring the
|
||||
|
@@ -1354,8 +1354,8 @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,
|
||||
goto out;
|
||||
}
|
||||
|
||||
data->lba = cpu_to_le64(offset >> BDRV_SECTOR_BITS);
|
||||
data->size = cpu_to_le32(buf_len);
|
||||
data->lba = offset >> BDRV_SECTOR_BITS;
|
||||
data->size = buf_len;
|
||||
|
||||
n_bytes = buf_len + sizeof(VmdkGrainMarker);
|
||||
iov = (struct iovec) {
|
||||
|
@@ -175,7 +175,7 @@ int win32_aio_attach(QEMUWin32AIOState *aio, HANDLE hfile)
|
||||
void win32_aio_detach_aio_context(QEMUWin32AIOState *aio,
|
||||
AioContext *old_context)
|
||||
{
|
||||
aio_set_event_notifier(old_context, &aio->e, false, NULL);
|
||||
aio_set_event_notifier(old_context, &aio->e, false, NULL, NULL);
|
||||
aio->is_aio_context_attached = false;
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ void win32_aio_attach_aio_context(QEMUWin32AIOState *aio,
|
||||
{
|
||||
aio->is_aio_context_attached = true;
|
||||
aio_set_event_notifier(new_context, &aio->e, false,
|
||||
win32_aio_completion_cb);
|
||||
win32_aio_completion_cb, NULL);
|
||||
}
|
||||
|
||||
QEMUWin32AIOState *win32_aio_init(void)
|
||||
|
19
configure
vendored
19
configure
vendored
@@ -28,8 +28,6 @@ TMPB="qemu-conf"
|
||||
TMPC="${TMPDIR1}/${TMPB}.c"
|
||||
TMPO="${TMPDIR1}/${TMPB}.o"
|
||||
TMPCXX="${TMPDIR1}/${TMPB}.cxx"
|
||||
TMPL="${TMPDIR1}/${TMPB}.lo"
|
||||
TMPA="${TMPDIR1}/lib${TMPB}.la"
|
||||
TMPE="${TMPDIR1}/${TMPB}.exe"
|
||||
TMPMO="${TMPDIR1}/${TMPB}.mo"
|
||||
|
||||
@@ -313,6 +311,7 @@ gnutls_rnd=""
|
||||
nettle=""
|
||||
nettle_kdf="no"
|
||||
gcrypt=""
|
||||
gcrypt_hmac="no"
|
||||
gcrypt_kdf="no"
|
||||
vte=""
|
||||
virglrenderer=""
|
||||
@@ -2417,6 +2416,19 @@ EOF
|
||||
if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
|
||||
gcrypt_kdf=yes
|
||||
fi
|
||||
|
||||
cat > $TMPC << EOF
|
||||
#include <gcrypt.h>
|
||||
int main(void) {
|
||||
gcry_mac_hd_t handle;
|
||||
gcry_mac_open(&handle, GCRY_MAC_HMAC_MD5,
|
||||
GCRY_MAC_FLAG_SECURE, NULL);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
|
||||
gcrypt_hmac=yes
|
||||
fi
|
||||
else
|
||||
if test "$gcrypt" = "yes"; then
|
||||
feature_not_found "gcrypt" "Install gcrypt devel"
|
||||
@@ -5387,6 +5399,9 @@ if test "$gnutls_rnd" = "yes" ; then
|
||||
fi
|
||||
if test "$gcrypt" = "yes" ; then
|
||||
echo "CONFIG_GCRYPT=y" >> $config_host_mak
|
||||
if test "$gcrypt_hmac" = "yes" ; then
|
||||
echo "CONFIG_GCRYPT_HMAC=y" >> $config_host_mak
|
||||
fi
|
||||
if test "$gcrypt_kdf" = "yes" ; then
|
||||
echo "CONFIG_GCRYPT_KDF=y" >> $config_host_mak
|
||||
fi
|
||||
|
@@ -491,7 +491,7 @@ static inline void cpu_handle_interrupt(CPUState *cpu,
|
||||
X86CPU *x86_cpu = X86_CPU(cpu);
|
||||
CPUArchState *env = &x86_cpu->env;
|
||||
replay_interrupt();
|
||||
cpu_svm_check_intercept_param(env, SVM_EXIT_INIT, 0, 0);
|
||||
cpu_svm_check_intercept_param(env, SVM_EXIT_INIT, 0);
|
||||
do_cpu_init(x86_cpu);
|
||||
cpu->exception_index = EXCP_HALTED;
|
||||
cpu_loop_exit(cpu);
|
||||
@@ -542,7 +542,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
|
||||
|
||||
trace_exec_tb(tb, tb->pc);
|
||||
ret = cpu_tb_exec(cpu, tb);
|
||||
tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK);
|
||||
*last_tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK);
|
||||
*tb_exit = ret & TB_EXIT_MASK;
|
||||
switch (*tb_exit) {
|
||||
case TB_EXIT_REQUESTED:
|
||||
@@ -566,7 +566,6 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
|
||||
abort();
|
||||
#else
|
||||
int insns_left = cpu->icount_decr.u32;
|
||||
*last_tb = NULL;
|
||||
if (cpu->icount_extra && insns_left >= 0) {
|
||||
/* Refill decrementer and continue execution. */
|
||||
cpu->icount_extra += insns_left;
|
||||
@@ -576,17 +575,17 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
|
||||
} else {
|
||||
if (insns_left > 0) {
|
||||
/* Execute remaining instructions. */
|
||||
cpu_exec_nocache(cpu, insns_left, tb, false);
|
||||
cpu_exec_nocache(cpu, insns_left, *last_tb, false);
|
||||
align_clocks(sc, cpu);
|
||||
}
|
||||
cpu->exception_index = EXCP_INTERRUPT;
|
||||
*last_tb = NULL;
|
||||
cpu_loop_exit(cpu);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
default:
|
||||
*last_tb = tb;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,10 @@ crypto-obj-y += hash.o
|
||||
crypto-obj-$(CONFIG_NETTLE) += hash-nettle.o
|
||||
crypto-obj-$(if $(CONFIG_NETTLE),n,$(CONFIG_GCRYPT)) += hash-gcrypt.o
|
||||
crypto-obj-$(if $(CONFIG_NETTLE),n,$(if $(CONFIG_GCRYPT),n,y)) += hash-glib.o
|
||||
crypto-obj-y += hmac.o
|
||||
crypto-obj-$(CONFIG_NETTLE) += hmac-nettle.o
|
||||
crypto-obj-$(CONFIG_GCRYPT_HMAC) += hmac-gcrypt.o
|
||||
crypto-obj-$(if $(CONFIG_NETTLE),n,$(if $(CONFIG_GCRYPT_HMAC),n,y)) += hmac-glib.o
|
||||
crypto-obj-y += aes.o
|
||||
crypto-obj-y += desrfb.o
|
||||
crypto-obj-y += cipher.o
|
||||
|
@@ -29,6 +29,7 @@ bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg,
|
||||
{
|
||||
switch (alg) {
|
||||
case QCRYPTO_CIPHER_ALG_DES_RFB:
|
||||
case QCRYPTO_CIPHER_ALG_3DES:
|
||||
case QCRYPTO_CIPHER_ALG_AES_128:
|
||||
case QCRYPTO_CIPHER_ALG_AES_192:
|
||||
case QCRYPTO_CIPHER_ALG_AES_256:
|
||||
@@ -99,6 +100,10 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
|
||||
gcryalg = GCRY_CIPHER_DES;
|
||||
break;
|
||||
|
||||
case QCRYPTO_CIPHER_ALG_3DES:
|
||||
gcryalg = GCRY_CIPHER_3DES;
|
||||
break;
|
||||
|
||||
case QCRYPTO_CIPHER_ALG_AES_128:
|
||||
gcryalg = GCRY_CIPHER_AES128;
|
||||
break;
|
||||
@@ -200,6 +205,7 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
|
||||
case QCRYPTO_CIPHER_ALG_TWOFISH_256:
|
||||
ctx->blocksize = 16;
|
||||
break;
|
||||
case QCRYPTO_CIPHER_ALG_3DES:
|
||||
case QCRYPTO_CIPHER_ALG_CAST5_128:
|
||||
ctx->blocksize = 8;
|
||||
break;
|
||||
|
@@ -78,6 +78,18 @@ static void des_decrypt_native(cipher_ctx_t ctx, cipher_length_t length,
|
||||
des_decrypt(ctx, length, dst, src);
|
||||
}
|
||||
|
||||
static void des3_encrypt_native(cipher_ctx_t ctx, cipher_length_t length,
|
||||
uint8_t *dst, const uint8_t *src)
|
||||
{
|
||||
des3_encrypt(ctx, length, dst, src);
|
||||
}
|
||||
|
||||
static void des3_decrypt_native(cipher_ctx_t ctx, cipher_length_t length,
|
||||
uint8_t *dst, const uint8_t *src)
|
||||
{
|
||||
des3_decrypt(ctx, length, dst, src);
|
||||
}
|
||||
|
||||
static void cast128_encrypt_native(cipher_ctx_t ctx, cipher_length_t length,
|
||||
uint8_t *dst, const uint8_t *src)
|
||||
{
|
||||
@@ -140,6 +152,18 @@ static void des_decrypt_wrapper(const void *ctx, size_t length,
|
||||
des_decrypt(ctx, length, dst, src);
|
||||
}
|
||||
|
||||
static void des3_encrypt_wrapper(const void *ctx, size_t length,
|
||||
uint8_t *dst, const uint8_t *src)
|
||||
{
|
||||
des3_encrypt(ctx, length, dst, src);
|
||||
}
|
||||
|
||||
static void des3_decrypt_wrapper(const void *ctx, size_t length,
|
||||
uint8_t *dst, const uint8_t *src)
|
||||
{
|
||||
des3_decrypt(ctx, length, dst, src);
|
||||
}
|
||||
|
||||
static void cast128_encrypt_wrapper(const void *ctx, size_t length,
|
||||
uint8_t *dst, const uint8_t *src)
|
||||
{
|
||||
@@ -197,6 +221,7 @@ bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg,
|
||||
{
|
||||
switch (alg) {
|
||||
case QCRYPTO_CIPHER_ALG_DES_RFB:
|
||||
case QCRYPTO_CIPHER_ALG_3DES:
|
||||
case QCRYPTO_CIPHER_ALG_AES_128:
|
||||
case QCRYPTO_CIPHER_ALG_AES_192:
|
||||
case QCRYPTO_CIPHER_ALG_AES_256:
|
||||
@@ -254,6 +279,7 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
|
||||
cipher->mode = mode;
|
||||
|
||||
ctx = g_new0(QCryptoCipherNettle, 1);
|
||||
cipher->opaque = ctx;
|
||||
|
||||
switch (alg) {
|
||||
case QCRYPTO_CIPHER_ALG_DES_RFB:
|
||||
@@ -270,6 +296,18 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
|
||||
ctx->blocksize = DES_BLOCK_SIZE;
|
||||
break;
|
||||
|
||||
case QCRYPTO_CIPHER_ALG_3DES:
|
||||
ctx->ctx = g_new0(struct des3_ctx, 1);
|
||||
des3_set_key(ctx->ctx, key);
|
||||
|
||||
ctx->alg_encrypt_native = des3_encrypt_native;
|
||||
ctx->alg_decrypt_native = des3_decrypt_native;
|
||||
ctx->alg_encrypt_wrapper = des3_encrypt_wrapper;
|
||||
ctx->alg_decrypt_wrapper = des3_decrypt_wrapper;
|
||||
|
||||
ctx->blocksize = DES3_BLOCK_SIZE;
|
||||
break;
|
||||
|
||||
case QCRYPTO_CIPHER_ALG_AES_128:
|
||||
case QCRYPTO_CIPHER_ALG_AES_192:
|
||||
case QCRYPTO_CIPHER_ALG_AES_256:
|
||||
@@ -384,13 +422,11 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
|
||||
}
|
||||
|
||||
ctx->iv = g_new0(uint8_t, ctx->blocksize);
|
||||
cipher->opaque = ctx;
|
||||
|
||||
return cipher;
|
||||
|
||||
error:
|
||||
g_free(cipher);
|
||||
g_free(ctx);
|
||||
qcrypto_cipher_free(cipher);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@@ -28,6 +28,7 @@ static size_t alg_key_len[QCRYPTO_CIPHER_ALG__MAX] = {
|
||||
[QCRYPTO_CIPHER_ALG_AES_192] = 24,
|
||||
[QCRYPTO_CIPHER_ALG_AES_256] = 32,
|
||||
[QCRYPTO_CIPHER_ALG_DES_RFB] = 8,
|
||||
[QCRYPTO_CIPHER_ALG_3DES] = 24,
|
||||
[QCRYPTO_CIPHER_ALG_CAST5_128] = 16,
|
||||
[QCRYPTO_CIPHER_ALG_SERPENT_128] = 16,
|
||||
[QCRYPTO_CIPHER_ALG_SERPENT_192] = 24,
|
||||
@@ -42,6 +43,7 @@ static size_t alg_block_len[QCRYPTO_CIPHER_ALG__MAX] = {
|
||||
[QCRYPTO_CIPHER_ALG_AES_192] = 16,
|
||||
[QCRYPTO_CIPHER_ALG_AES_256] = 16,
|
||||
[QCRYPTO_CIPHER_ALG_DES_RFB] = 8,
|
||||
[QCRYPTO_CIPHER_ALG_3DES] = 8,
|
||||
[QCRYPTO_CIPHER_ALG_CAST5_128] = 8,
|
||||
[QCRYPTO_CIPHER_ALG_SERPENT_128] = 16,
|
||||
[QCRYPTO_CIPHER_ALG_SERPENT_192] = 16,
|
||||
@@ -107,8 +109,9 @@ qcrypto_cipher_validate_key_length(QCryptoCipherAlgorithm alg,
|
||||
}
|
||||
|
||||
if (mode == QCRYPTO_CIPHER_MODE_XTS) {
|
||||
if (alg == QCRYPTO_CIPHER_ALG_DES_RFB) {
|
||||
error_setg(errp, "XTS mode not compatible with DES-RFB");
|
||||
if (alg == QCRYPTO_CIPHER_ALG_DES_RFB
|
||||
|| alg == QCRYPTO_CIPHER_ALG_3DES) {
|
||||
error_setg(errp, "XTS mode not compatible with DES-RFB/3DES");
|
||||
return false;
|
||||
}
|
||||
if (nkey % 2) {
|
||||
|
152
crypto/hmac-gcrypt.c
Normal file
152
crypto/hmac-gcrypt.c
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* QEMU Crypto hmac algorithms (based on libgcrypt)
|
||||
*
|
||||
* Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
|
||||
*
|
||||
* Authors:
|
||||
* Longpeng(Mike) <longpeng2@huawei.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or
|
||||
* (at your option) any later version. See the COPYING file in the
|
||||
* top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qapi/error.h"
|
||||
#include "crypto/hmac.h"
|
||||
#include <gcrypt.h>
|
||||
|
||||
static int qcrypto_hmac_alg_map[QCRYPTO_HASH_ALG__MAX] = {
|
||||
[QCRYPTO_HASH_ALG_MD5] = GCRY_MAC_HMAC_MD5,
|
||||
[QCRYPTO_HASH_ALG_SHA1] = GCRY_MAC_HMAC_SHA1,
|
||||
[QCRYPTO_HASH_ALG_SHA224] = GCRY_MAC_HMAC_SHA224,
|
||||
[QCRYPTO_HASH_ALG_SHA256] = GCRY_MAC_HMAC_SHA256,
|
||||
[QCRYPTO_HASH_ALG_SHA384] = GCRY_MAC_HMAC_SHA384,
|
||||
[QCRYPTO_HASH_ALG_SHA512] = GCRY_MAC_HMAC_SHA512,
|
||||
[QCRYPTO_HASH_ALG_RIPEMD160] = GCRY_MAC_HMAC_RMD160,
|
||||
};
|
||||
|
||||
typedef struct QCryptoHmacGcrypt QCryptoHmacGcrypt;
|
||||
struct QCryptoHmacGcrypt {
|
||||
gcry_mac_hd_t handle;
|
||||
};
|
||||
|
||||
bool qcrypto_hmac_supports(QCryptoHashAlgorithm alg)
|
||||
{
|
||||
if (alg < G_N_ELEMENTS(qcrypto_hmac_alg_map) &&
|
||||
qcrypto_hmac_alg_map[alg] != GCRY_MAC_NONE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg,
|
||||
const uint8_t *key, size_t nkey,
|
||||
Error **errp)
|
||||
{
|
||||
QCryptoHmac *hmac;
|
||||
QCryptoHmacGcrypt *ctx;
|
||||
gcry_error_t err;
|
||||
|
||||
if (!qcrypto_hmac_supports(alg)) {
|
||||
error_setg(errp, "Unsupported hmac algorithm %s",
|
||||
QCryptoHashAlgorithm_lookup[alg]);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hmac = g_new0(QCryptoHmac, 1);
|
||||
hmac->alg = alg;
|
||||
|
||||
ctx = g_new0(QCryptoHmacGcrypt, 1);
|
||||
|
||||
err = gcry_mac_open(&ctx->handle, qcrypto_hmac_alg_map[alg],
|
||||
GCRY_MAC_FLAG_SECURE, NULL);
|
||||
if (err != 0) {
|
||||
error_setg(errp, "Cannot initialize hmac: %s",
|
||||
gcry_strerror(err));
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = gcry_mac_setkey(ctx->handle, (const void *)key, nkey);
|
||||
if (err != 0) {
|
||||
error_setg(errp, "Cannot set key: %s",
|
||||
gcry_strerror(err));
|
||||
goto error;
|
||||
}
|
||||
|
||||
hmac->opaque = ctx;
|
||||
return hmac;
|
||||
|
||||
error:
|
||||
g_free(ctx);
|
||||
g_free(hmac);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void qcrypto_hmac_free(QCryptoHmac *hmac)
|
||||
{
|
||||
QCryptoHmacGcrypt *ctx;
|
||||
|
||||
if (!hmac) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx = hmac->opaque;
|
||||
gcry_mac_close(ctx->handle);
|
||||
|
||||
g_free(ctx);
|
||||
g_free(hmac);
|
||||
}
|
||||
|
||||
int qcrypto_hmac_bytesv(QCryptoHmac *hmac,
|
||||
const struct iovec *iov,
|
||||
size_t niov,
|
||||
uint8_t **result,
|
||||
size_t *resultlen,
|
||||
Error **errp)
|
||||
{
|
||||
QCryptoHmacGcrypt *ctx;
|
||||
gcry_error_t err;
|
||||
uint32_t ret;
|
||||
int i;
|
||||
|
||||
ctx = hmac->opaque;
|
||||
|
||||
for (i = 0; i < niov; i++) {
|
||||
gcry_mac_write(ctx->handle, iov[i].iov_base, iov[i].iov_len);
|
||||
}
|
||||
|
||||
ret = gcry_mac_get_algo_maclen(qcrypto_hmac_alg_map[hmac->alg]);
|
||||
if (ret <= 0) {
|
||||
error_setg(errp, "Unable to get hmac length: %s",
|
||||
gcry_strerror(ret));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*resultlen == 0) {
|
||||
*resultlen = ret;
|
||||
*result = g_new0(uint8_t, *resultlen);
|
||||
} else if (*resultlen != ret) {
|
||||
error_setg(errp, "Result buffer size %zu is smaller than hmac %d",
|
||||
*resultlen, ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = gcry_mac_read(ctx->handle, *result, resultlen);
|
||||
if (err != 0) {
|
||||
error_setg(errp, "Cannot get result: %s",
|
||||
gcry_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = gcry_mac_reset(ctx->handle);
|
||||
if (err != 0) {
|
||||
error_setg(errp, "Cannot reset hmac context: %s",
|
||||
gcry_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
166
crypto/hmac-glib.c
Normal file
166
crypto/hmac-glib.c
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* QEMU Crypto hmac algorithms (based on glib)
|
||||
*
|
||||
* Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
|
||||
*
|
||||
* Authors:
|
||||
* Longpeng(Mike) <longpeng2@huawei.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or
|
||||
* (at your option) any later version. See the COPYING file in the
|
||||
* top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qapi/error.h"
|
||||
#include "crypto/hmac.h"
|
||||
|
||||
/* Support for HMAC Algos has been added in GLib 2.30 */
|
||||
#if GLIB_CHECK_VERSION(2, 30, 0)
|
||||
|
||||
static int qcrypto_hmac_alg_map[QCRYPTO_HASH_ALG__MAX] = {
|
||||
[QCRYPTO_HASH_ALG_MD5] = G_CHECKSUM_MD5,
|
||||
[QCRYPTO_HASH_ALG_SHA1] = G_CHECKSUM_SHA1,
|
||||
[QCRYPTO_HASH_ALG_SHA256] = G_CHECKSUM_SHA256,
|
||||
/* Support for HMAC SHA-512 in GLib 2.42 */
|
||||
#if GLIB_CHECK_VERSION(2, 42, 0)
|
||||
[QCRYPTO_HASH_ALG_SHA512] = G_CHECKSUM_SHA512,
|
||||
#else
|
||||
[QCRYPTO_HASH_ALG_SHA512] = -1,
|
||||
#endif
|
||||
[QCRYPTO_HASH_ALG_SHA224] = -1,
|
||||
[QCRYPTO_HASH_ALG_SHA384] = -1,
|
||||
[QCRYPTO_HASH_ALG_RIPEMD160] = -1,
|
||||
};
|
||||
|
||||
typedef struct QCryptoHmacGlib QCryptoHmacGlib;
|
||||
struct QCryptoHmacGlib {
|
||||
GHmac *ghmac;
|
||||
};
|
||||
|
||||
bool qcrypto_hmac_supports(QCryptoHashAlgorithm alg)
|
||||
{
|
||||
if (alg < G_N_ELEMENTS(qcrypto_hmac_alg_map) &&
|
||||
qcrypto_hmac_alg_map[alg] != -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg,
|
||||
const uint8_t *key, size_t nkey,
|
||||
Error **errp)
|
||||
{
|
||||
QCryptoHmac *hmac;
|
||||
QCryptoHmacGlib *ctx;
|
||||
|
||||
if (!qcrypto_hmac_supports(alg)) {
|
||||
error_setg(errp, "Unsupported hmac algorithm %s",
|
||||
QCryptoHashAlgorithm_lookup[alg]);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hmac = g_new0(QCryptoHmac, 1);
|
||||
hmac->alg = alg;
|
||||
|
||||
ctx = g_new0(QCryptoHmacGlib, 1);
|
||||
|
||||
ctx->ghmac = g_hmac_new(qcrypto_hmac_alg_map[alg],
|
||||
(const uint8_t *)key, nkey);
|
||||
if (!ctx->ghmac) {
|
||||
error_setg(errp, "Cannot initialize hmac and set key");
|
||||
goto error;
|
||||
}
|
||||
|
||||
hmac->opaque = ctx;
|
||||
return hmac;
|
||||
|
||||
error:
|
||||
g_free(ctx);
|
||||
g_free(hmac);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void qcrypto_hmac_free(QCryptoHmac *hmac)
|
||||
{
|
||||
QCryptoHmacGlib *ctx;
|
||||
|
||||
if (!hmac) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx = hmac->opaque;
|
||||
g_hmac_unref(ctx->ghmac);
|
||||
|
||||
g_free(ctx);
|
||||
g_free(hmac);
|
||||
}
|
||||
|
||||
int qcrypto_hmac_bytesv(QCryptoHmac *hmac,
|
||||
const struct iovec *iov,
|
||||
size_t niov,
|
||||
uint8_t **result,
|
||||
size_t *resultlen,
|
||||
Error **errp)
|
||||
{
|
||||
QCryptoHmacGlib *ctx;
|
||||
int i, ret;
|
||||
|
||||
ctx = hmac->opaque;
|
||||
|
||||
for (i = 0; i < niov; i++) {
|
||||
g_hmac_update(ctx->ghmac, iov[i].iov_base, iov[i].iov_len);
|
||||
}
|
||||
|
||||
ret = g_checksum_type_get_length(qcrypto_hmac_alg_map[hmac->alg]);
|
||||
if (ret < 0) {
|
||||
error_setg(errp, "Unable to get hmac length");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*resultlen == 0) {
|
||||
*resultlen = ret;
|
||||
*result = g_new0(uint8_t, *resultlen);
|
||||
} else if (*resultlen != ret) {
|
||||
error_setg(errp, "Result buffer size %zu is smaller than hmac %d",
|
||||
*resultlen, ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_hmac_get_digest(ctx->ghmac, *result, resultlen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
bool qcrypto_hmac_supports(QCryptoHashAlgorithm alg)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg,
|
||||
const uint8_t *key, size_t nkey,
|
||||
Error **errp)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void qcrypto_hmac_free(QCryptoHmac *hmac)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int qcrypto_hmac_bytesv(QCryptoHmac *hmac,
|
||||
const struct iovec *iov,
|
||||
size_t niov,
|
||||
uint8_t **result,
|
||||
size_t *resultlen,
|
||||
Error **errp)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
175
crypto/hmac-nettle.c
Normal file
175
crypto/hmac-nettle.c
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* QEMU Crypto hmac algorithms (based on nettle)
|
||||
*
|
||||
* Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
|
||||
*
|
||||
* Authors:
|
||||
* Longpeng(Mike) <longpeng2@huawei.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or
|
||||
* (at your option) any later version. See the COPYING file in the
|
||||
* top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qapi/error.h"
|
||||
#include "crypto/hmac.h"
|
||||
#include <nettle/hmac.h>
|
||||
|
||||
typedef void (*qcrypto_nettle_hmac_setkey)(void *ctx,
|
||||
size_t key_length, const uint8_t *key);
|
||||
|
||||
typedef void (*qcrypto_nettle_hmac_update)(void *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
typedef void (*qcrypto_nettle_hmac_digest)(void *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
typedef struct QCryptoHmacNettle QCryptoHmacNettle;
|
||||
struct QCryptoHmacNettle {
|
||||
union qcrypto_nettle_hmac_ctx {
|
||||
struct hmac_md5_ctx md5_ctx;
|
||||
struct hmac_sha1_ctx sha1_ctx;
|
||||
struct hmac_sha256_ctx sha256_ctx; /* equals hmac_sha224_ctx */
|
||||
struct hmac_sha512_ctx sha512_ctx; /* equals hmac_sha384_ctx */
|
||||
struct hmac_ripemd160_ctx ripemd160_ctx;
|
||||
} u;
|
||||
};
|
||||
|
||||
struct qcrypto_nettle_hmac_alg {
|
||||
qcrypto_nettle_hmac_setkey setkey;
|
||||
qcrypto_nettle_hmac_update update;
|
||||
qcrypto_nettle_hmac_digest digest;
|
||||
size_t len;
|
||||
} qcrypto_hmac_alg_map[QCRYPTO_HASH_ALG__MAX] = {
|
||||
[QCRYPTO_HASH_ALG_MD5] = {
|
||||
.setkey = (qcrypto_nettle_hmac_setkey)hmac_md5_set_key,
|
||||
.update = (qcrypto_nettle_hmac_update)hmac_md5_update,
|
||||
.digest = (qcrypto_nettle_hmac_digest)hmac_md5_digest,
|
||||
.len = MD5_DIGEST_SIZE,
|
||||
},
|
||||
[QCRYPTO_HASH_ALG_SHA1] = {
|
||||
.setkey = (qcrypto_nettle_hmac_setkey)hmac_sha1_set_key,
|
||||
.update = (qcrypto_nettle_hmac_update)hmac_sha1_update,
|
||||
.digest = (qcrypto_nettle_hmac_digest)hmac_sha1_digest,
|
||||
.len = SHA1_DIGEST_SIZE,
|
||||
},
|
||||
[QCRYPTO_HASH_ALG_SHA224] = {
|
||||
.setkey = (qcrypto_nettle_hmac_setkey)hmac_sha224_set_key,
|
||||
.update = (qcrypto_nettle_hmac_update)hmac_sha224_update,
|
||||
.digest = (qcrypto_nettle_hmac_digest)hmac_sha224_digest,
|
||||
.len = SHA224_DIGEST_SIZE,
|
||||
},
|
||||
[QCRYPTO_HASH_ALG_SHA256] = {
|
||||
.setkey = (qcrypto_nettle_hmac_setkey)hmac_sha256_set_key,
|
||||
.update = (qcrypto_nettle_hmac_update)hmac_sha256_update,
|
||||
.digest = (qcrypto_nettle_hmac_digest)hmac_sha256_digest,
|
||||
.len = SHA256_DIGEST_SIZE,
|
||||
},
|
||||
[QCRYPTO_HASH_ALG_SHA384] = {
|
||||
.setkey = (qcrypto_nettle_hmac_setkey)hmac_sha384_set_key,
|
||||
.update = (qcrypto_nettle_hmac_update)hmac_sha384_update,
|
||||
.digest = (qcrypto_nettle_hmac_digest)hmac_sha384_digest,
|
||||
.len = SHA384_DIGEST_SIZE,
|
||||
},
|
||||
[QCRYPTO_HASH_ALG_SHA512] = {
|
||||
.setkey = (qcrypto_nettle_hmac_setkey)hmac_sha512_set_key,
|
||||
.update = (qcrypto_nettle_hmac_update)hmac_sha512_update,
|
||||
.digest = (qcrypto_nettle_hmac_digest)hmac_sha512_digest,
|
||||
.len = SHA512_DIGEST_SIZE,
|
||||
},
|
||||
[QCRYPTO_HASH_ALG_RIPEMD160] = {
|
||||
.setkey = (qcrypto_nettle_hmac_setkey)hmac_ripemd160_set_key,
|
||||
.update = (qcrypto_nettle_hmac_update)hmac_ripemd160_update,
|
||||
.digest = (qcrypto_nettle_hmac_digest)hmac_ripemd160_digest,
|
||||
.len = RIPEMD160_DIGEST_SIZE,
|
||||
},
|
||||
};
|
||||
|
||||
bool qcrypto_hmac_supports(QCryptoHashAlgorithm alg)
|
||||
{
|
||||
if (alg < G_N_ELEMENTS(qcrypto_hmac_alg_map) &&
|
||||
qcrypto_hmac_alg_map[alg].setkey != NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg,
|
||||
const uint8_t *key, size_t nkey,
|
||||
Error **errp)
|
||||
{
|
||||
QCryptoHmac *hmac;
|
||||
QCryptoHmacNettle *ctx;
|
||||
|
||||
if (!qcrypto_hmac_supports(alg)) {
|
||||
error_setg(errp, "Unsupported hmac algorithm %s",
|
||||
QCryptoHashAlgorithm_lookup[alg]);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hmac = g_new0(QCryptoHmac, 1);
|
||||
hmac->alg = alg;
|
||||
|
||||
ctx = g_new0(QCryptoHmacNettle, 1);
|
||||
|
||||
qcrypto_hmac_alg_map[alg].setkey(&ctx->u, nkey, key);
|
||||
|
||||
hmac->opaque = ctx;
|
||||
|
||||
return hmac;
|
||||
}
|
||||
|
||||
void qcrypto_hmac_free(QCryptoHmac *hmac)
|
||||
{
|
||||
QCryptoHmacNettle *ctx;
|
||||
|
||||
if (!hmac) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx = hmac->opaque;
|
||||
|
||||
g_free(ctx);
|
||||
g_free(hmac);
|
||||
}
|
||||
|
||||
int qcrypto_hmac_bytesv(QCryptoHmac *hmac,
|
||||
const struct iovec *iov,
|
||||
size_t niov,
|
||||
uint8_t **result,
|
||||
size_t *resultlen,
|
||||
Error **errp)
|
||||
{
|
||||
QCryptoHmacNettle *ctx;
|
||||
int i;
|
||||
|
||||
ctx = (QCryptoHmacNettle *)hmac->opaque;
|
||||
|
||||
for (i = 0; i < niov; ++i) {
|
||||
size_t len = iov[i].iov_len;
|
||||
uint8_t *base = iov[i].iov_base;
|
||||
while (len) {
|
||||
size_t shortlen = MIN(len, UINT_MAX);
|
||||
qcrypto_hmac_alg_map[hmac->alg].update(&ctx->u, len, base);
|
||||
len -= shortlen;
|
||||
base += len;
|
||||
}
|
||||
}
|
||||
|
||||
if (*resultlen == 0) {
|
||||
*resultlen = qcrypto_hmac_alg_map[hmac->alg].len;
|
||||
*result = g_new0(uint8_t, *resultlen);
|
||||
} else if (*resultlen != qcrypto_hmac_alg_map[hmac->alg].len) {
|
||||
error_setg(errp,
|
||||
"Result buffer size %zu is smaller than hash %zu",
|
||||
*resultlen, qcrypto_hmac_alg_map[hmac->alg].len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
qcrypto_hmac_alg_map[hmac->alg].digest(&ctx->u, *resultlen, *result);
|
||||
|
||||
return 0;
|
||||
}
|
72
crypto/hmac.c
Normal file
72
crypto/hmac.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* QEMU Crypto hmac algorithms
|
||||
*
|
||||
* Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or
|
||||
* (at your option) any later version. See the COPYING file in the
|
||||
* top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qapi/error.h"
|
||||
#include "crypto/hmac.h"
|
||||
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
|
||||
int qcrypto_hmac_bytes(QCryptoHmac *hmac,
|
||||
const char *buf,
|
||||
size_t len,
|
||||
uint8_t **result,
|
||||
size_t *resultlen,
|
||||
Error **errp)
|
||||
{
|
||||
struct iovec iov = {
|
||||
.iov_base = (char *)buf,
|
||||
.iov_len = len
|
||||
};
|
||||
|
||||
return qcrypto_hmac_bytesv(hmac, &iov, 1, result, resultlen, errp);
|
||||
}
|
||||
|
||||
int qcrypto_hmac_digestv(QCryptoHmac *hmac,
|
||||
const struct iovec *iov,
|
||||
size_t niov,
|
||||
char **digest,
|
||||
Error **errp)
|
||||
{
|
||||
uint8_t *result = NULL;
|
||||
size_t resultlen = 0;
|
||||
size_t i;
|
||||
|
||||
if (qcrypto_hmac_bytesv(hmac, iov, niov, &result, &resultlen, errp) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*digest = g_new0(char, (resultlen * 2) + 1);
|
||||
|
||||
for (i = 0 ; i < resultlen ; i++) {
|
||||
(*digest)[(i * 2)] = hex[(result[i] >> 4) & 0xf];
|
||||
(*digest)[(i * 2) + 1] = hex[result[i] & 0xf];
|
||||
}
|
||||
|
||||
(*digest)[resultlen * 2] = '\0';
|
||||
|
||||
g_free(result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qcrypto_hmac_digest(QCryptoHmac *hmac,
|
||||
const char *buf,
|
||||
size_t len,
|
||||
char **digest,
|
||||
Error **errp)
|
||||
{
|
||||
struct iovec iov = {
|
||||
.iov_base = (char *)buf,
|
||||
.iov_len = len
|
||||
};
|
||||
|
||||
return qcrypto_hmac_digestv(hmac, &iov, 1, digest, errp);
|
||||
}
|
166
crypto/hmac.h
Normal file
166
crypto/hmac.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* QEMU Crypto hmac algorithms
|
||||
*
|
||||
* Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or
|
||||
* (at your option) any later version. See the COPYING file in the
|
||||
* top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QCRYPTO_HMAC_H
|
||||
#define QCRYPTO_HMAC_H
|
||||
|
||||
#include "qapi-types.h"
|
||||
|
||||
typedef struct QCryptoHmac QCryptoHmac;
|
||||
struct QCryptoHmac {
|
||||
QCryptoHashAlgorithm alg;
|
||||
void *opaque;
|
||||
};
|
||||
|
||||
/**
|
||||
* qcrypto_hmac_supports:
|
||||
* @alg: the hmac algorithm
|
||||
*
|
||||
* Determine if @alg hmac algorithm is supported by
|
||||
* the current configured build
|
||||
*
|
||||
* Returns:
|
||||
* true if the algorithm is supported, false otherwise
|
||||
*/
|
||||
bool qcrypto_hmac_supports(QCryptoHashAlgorithm alg);
|
||||
|
||||
/**
|
||||
* qcrypto_hmac_new:
|
||||
* @alg: the hmac algorithm
|
||||
* @key: the key bytes
|
||||
* @nkey: the length of @key
|
||||
* @errp: pointer to a NULL-initialized error object
|
||||
*
|
||||
* Creates a new hmac object with the algorithm @alg
|
||||
*
|
||||
* The @key parameter provides the bytes representing
|
||||
* the secret key to use. The @nkey parameter specifies
|
||||
* the length of @key in bytes
|
||||
*
|
||||
* Note: must use qcrypto_hmac_free() to release the
|
||||
* returned hmac object when no longer required
|
||||
*
|
||||
* Returns:
|
||||
* a new hmac object, or NULL on error
|
||||
*/
|
||||
QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg,
|
||||
const uint8_t *key, size_t nkey,
|
||||
Error **errp);
|
||||
|
||||
/**
|
||||
* qcrypto_hmac_free:
|
||||
* @hmac: the hmac object
|
||||
*
|
||||
* Release the memory associated with @hmac that was
|
||||
* previously allocated by qcrypto_hmac_new()
|
||||
*/
|
||||
void qcrypto_hmac_free(QCryptoHmac *hmac);
|
||||
|
||||
/**
|
||||
* qcrypto_hmac_bytesv:
|
||||
* @hmac: the hmac object
|
||||
* @iov: the array of memory regions to hmac
|
||||
* @niov: the length of @iov
|
||||
* @result: pointer to hold output hmac
|
||||
* @resultlen: pointer to hold length of @result
|
||||
* @errp: pointer to a NULL-initialized error object
|
||||
*
|
||||
* Computes the hmac across all the memory regions
|
||||
* present in @iov. The @result pointer will be
|
||||
* filled with raw bytes representing the computed
|
||||
* hmac, which will have length @resultlen. The
|
||||
* memory pointer in @result must be released
|
||||
* with a call to g_free() when no longer required.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success, -1 on error
|
||||
*/
|
||||
int qcrypto_hmac_bytesv(QCryptoHmac *hmac,
|
||||
const struct iovec *iov,
|
||||
size_t niov,
|
||||
uint8_t **result,
|
||||
size_t *resultlen,
|
||||
Error **errp);
|
||||
|
||||
/**
|
||||
* qcrypto_hmac_bytes:
|
||||
* @hmac: the hmac object
|
||||
* @buf: the memory region to hmac
|
||||
* @len: the length of @buf
|
||||
* @result: pointer to hold output hmac
|
||||
* @resultlen: pointer to hold length of @result
|
||||
* @errp: pointer to a NULL-initialized error object
|
||||
*
|
||||
* Computes the hmac across all the memory region
|
||||
* @buf of length @len. The @result pointer will be
|
||||
* filled with raw bytes representing the computed
|
||||
* hmac, which will have length @resultlen. The
|
||||
* memory pointer in @result must be released
|
||||
* with a call to g_free() when no longer required.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success, -1 on error
|
||||
*/
|
||||
int qcrypto_hmac_bytes(QCryptoHmac *hmac,
|
||||
const char *buf,
|
||||
size_t len,
|
||||
uint8_t **result,
|
||||
size_t *resultlen,
|
||||
Error **errp);
|
||||
|
||||
/**
|
||||
* qcrypto_hmac_digestv:
|
||||
* @hmac: the hmac object
|
||||
* @iov: the array of memory regions to hmac
|
||||
* @niov: the length of @iov
|
||||
* @digest: pointer to hold output hmac
|
||||
* @errp: pointer to a NULL-initialized error object
|
||||
*
|
||||
* Computes the hmac across all the memory regions
|
||||
* present in @iov. The @digest pointer will be
|
||||
* filled with the printable hex digest of the computed
|
||||
* hmac, which will be terminated by '\0'. The
|
||||
* memory pointer in @digest must be released
|
||||
* with a call to g_free() when no longer required.
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success, -1 on error
|
||||
*/
|
||||
int qcrypto_hmac_digestv(QCryptoHmac *hmac,
|
||||
const struct iovec *iov,
|
||||
size_t niov,
|
||||
char **digest,
|
||||
Error **errp);
|
||||
|
||||
/**
|
||||
* qcrypto_hmac_digest:
|
||||
* @hmac: the hmac object
|
||||
* @buf: the memory region to hmac
|
||||
* @len: the length of @buf
|
||||
* @digest: pointer to hold output hmac
|
||||
* @errp: pointer to a NULL-initialized error object
|
||||
*
|
||||
* Computes the hmac across all the memory region
|
||||
* @buf of length @len. The @digest pointer will be
|
||||
* filled with the printable hex digest of the computed
|
||||
* hmac, which will be terminated by '\0'. The
|
||||
* memory pointer in @digest must be released
|
||||
* with a call to g_free() when no longer required.
|
||||
*
|
||||
* Returns: 0 on success, -1 on error
|
||||
*/
|
||||
int qcrypto_hmac_digest(QCryptoHmac *hmac,
|
||||
const char *buf,
|
||||
size_t len,
|
||||
char **digest,
|
||||
Error **errp);
|
||||
|
||||
#endif
|
@@ -21,9 +21,7 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "disas/bfd.h"
|
||||
//#include "sysdep.h"
|
||||
#include "target-cris/opcode-cris.h"
|
||||
//#include "libiberty.h"
|
||||
#include "target/cris/opcode-cris.h"
|
||||
|
||||
#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
|
||||
|
||||
|
@@ -4698,10 +4698,6 @@ get_field (const unsigned char *data, enum floatformat_byteorders order,
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/* Convert from FMT to a double.
|
||||
FROM is the address of the extended float.
|
||||
Store the double in *TO. */
|
||||
@@ -4733,7 +4729,7 @@ floatformat_to_double (const struct floatformat *fmt,
|
||||
nan = 0;
|
||||
while (mant_bits_left > 0)
|
||||
{
|
||||
mant_bits = min (mant_bits_left, 32);
|
||||
mant_bits = MIN(mant_bits_left, 32);
|
||||
|
||||
if (get_field (ufrom, fmt->byteorder, fmt->totalsize,
|
||||
mant_off, mant_bits) != 0)
|
||||
@@ -4793,7 +4789,7 @@ floatformat_to_double (const struct floatformat *fmt,
|
||||
|
||||
while (mant_bits_left > 0)
|
||||
{
|
||||
mant_bits = min (mant_bits_left, 32);
|
||||
mant_bits = MIN(mant_bits_left, 32);
|
||||
|
||||
mant = get_field (ufrom, fmt->byteorder, fmt->totalsize,
|
||||
mant_off, mant_bits);
|
||||
|
694
exec.c
694
exec.c
@@ -2927,7 +2927,6 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_
|
||||
if (!memory_access_is_direct(mr, is_write)) {
|
||||
l = memory_access_size(mr, l, addr);
|
||||
if (!memory_region_access_valid(mr, xlat, l, is_write)) {
|
||||
rcu_read_unlock();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2939,6 +2938,31 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_
|
||||
return true;
|
||||
}
|
||||
|
||||
static hwaddr
|
||||
address_space_extend_translation(AddressSpace *as, hwaddr addr, hwaddr target_len,
|
||||
MemoryRegion *mr, hwaddr base, hwaddr len,
|
||||
bool is_write)
|
||||
{
|
||||
hwaddr done = 0;
|
||||
hwaddr xlat;
|
||||
MemoryRegion *this_mr;
|
||||
|
||||
for (;;) {
|
||||
target_len -= len;
|
||||
addr += len;
|
||||
done += len;
|
||||
if (target_len == 0) {
|
||||
return done;
|
||||
}
|
||||
|
||||
len = target_len;
|
||||
this_mr = address_space_translate(as, addr, &xlat, &len, is_write);
|
||||
if (this_mr != mr || xlat != base + done) {
|
||||
return done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Map a physical memory region into a host virtual address.
|
||||
* May map a subset of the requested range, given by and returned in *plen.
|
||||
* May return NULL if resources needed to perform the mapping are exhausted.
|
||||
@@ -2952,9 +2976,8 @@ void *address_space_map(AddressSpace *as,
|
||||
bool is_write)
|
||||
{
|
||||
hwaddr len = *plen;
|
||||
hwaddr done = 0;
|
||||
hwaddr l, xlat, base;
|
||||
MemoryRegion *mr, *this_mr;
|
||||
hwaddr l, xlat;
|
||||
MemoryRegion *mr;
|
||||
void *ptr;
|
||||
|
||||
if (len == 0) {
|
||||
@@ -2988,26 +3011,10 @@ void *address_space_map(AddressSpace *as,
|
||||
return bounce.buffer;
|
||||
}
|
||||
|
||||
base = xlat;
|
||||
|
||||
for (;;) {
|
||||
len -= l;
|
||||
addr += l;
|
||||
done += l;
|
||||
if (len == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
l = len;
|
||||
this_mr = address_space_translate(as, addr, &xlat, &l, is_write);
|
||||
if (this_mr != mr || xlat != base + done) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
memory_region_ref(mr);
|
||||
*plen = done;
|
||||
ptr = qemu_ram_ptr_length(mr->ram_block, base, plen);
|
||||
*plen = address_space_extend_translation(as, addr, len, mr, xlat, l, is_write);
|
||||
ptr = qemu_ram_ptr_length(mr->ram_block, xlat, plen);
|
||||
rcu_read_unlock();
|
||||
|
||||
return ptr;
|
||||
@@ -3059,597 +3066,92 @@ void cpu_physical_memory_unmap(void *buffer, hwaddr len,
|
||||
return address_space_unmap(&address_space_memory, buffer, len, is_write, access_len);
|
||||
}
|
||||
|
||||
/* warning: addr must be aligned */
|
||||
static inline uint32_t address_space_ldl_internal(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs,
|
||||
MemTxResult *result,
|
||||
enum device_endian endian)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
uint64_t val;
|
||||
MemoryRegion *mr;
|
||||
hwaddr l = 4;
|
||||
hwaddr addr1;
|
||||
MemTxResult r;
|
||||
bool release_lock = false;
|
||||
#define ARG1_DECL AddressSpace *as
|
||||
#define ARG1 as
|
||||
#define SUFFIX
|
||||
#define TRANSLATE(...) address_space_translate(as, __VA_ARGS__)
|
||||
#define IS_DIRECT(mr, is_write) memory_access_is_direct(mr, is_write)
|
||||
#define MAP_RAM(mr, ofs) qemu_map_ram_ptr((mr)->ram_block, ofs)
|
||||
#define INVALIDATE(mr, ofs, len) invalidate_and_set_dirty(mr, ofs, len)
|
||||
#define RCU_READ_LOCK(...) rcu_read_lock()
|
||||
#define RCU_READ_UNLOCK(...) rcu_read_unlock()
|
||||
#include "memory_ldst.inc.c"
|
||||
|
||||
rcu_read_lock();
|
||||
mr = address_space_translate(as, addr, &addr1, &l, false);
|
||||
if (l < 4 || !memory_access_is_direct(mr, false)) {
|
||||
release_lock |= prepare_mmio_access(mr);
|
||||
|
||||
/* I/O case */
|
||||
r = memory_region_dispatch_read(mr, addr1, &val, 4, attrs);
|
||||
#if defined(TARGET_WORDS_BIGENDIAN)
|
||||
if (endian == DEVICE_LITTLE_ENDIAN) {
|
||||
val = bswap32(val);
|
||||
}
|
||||
#else
|
||||
if (endian == DEVICE_BIG_ENDIAN) {
|
||||
val = bswap32(val);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
/* RAM case */
|
||||
ptr = qemu_map_ram_ptr(mr->ram_block, addr1);
|
||||
switch (endian) {
|
||||
case DEVICE_LITTLE_ENDIAN:
|
||||
val = ldl_le_p(ptr);
|
||||
break;
|
||||
case DEVICE_BIG_ENDIAN:
|
||||
val = ldl_be_p(ptr);
|
||||
break;
|
||||
default:
|
||||
val = ldl_p(ptr);
|
||||
break;
|
||||
}
|
||||
r = MEMTX_OK;
|
||||
}
|
||||
if (result) {
|
||||
*result = r;
|
||||
}
|
||||
if (release_lock) {
|
||||
qemu_mutex_unlock_iothread();
|
||||
}
|
||||
rcu_read_unlock();
|
||||
return val;
|
||||
}
|
||||
|
||||
uint32_t address_space_ldl(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
return address_space_ldl_internal(as, addr, attrs, result,
|
||||
DEVICE_NATIVE_ENDIAN);
|
||||
}
|
||||
|
||||
uint32_t address_space_ldl_le(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
return address_space_ldl_internal(as, addr, attrs, result,
|
||||
DEVICE_LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
uint32_t address_space_ldl_be(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
return address_space_ldl_internal(as, addr, attrs, result,
|
||||
DEVICE_BIG_ENDIAN);
|
||||
}
|
||||
|
||||
uint32_t ldl_phys(AddressSpace *as, hwaddr addr)
|
||||
{
|
||||
return address_space_ldl(as, addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
uint32_t ldl_le_phys(AddressSpace *as, hwaddr addr)
|
||||
{
|
||||
return address_space_ldl_le(as, addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
uint32_t ldl_be_phys(AddressSpace *as, hwaddr addr)
|
||||
{
|
||||
return address_space_ldl_be(as, addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
/* warning: addr must be aligned */
|
||||
static inline uint64_t address_space_ldq_internal(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs,
|
||||
MemTxResult *result,
|
||||
enum device_endian endian)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
uint64_t val;
|
||||
MemoryRegion *mr;
|
||||
hwaddr l = 8;
|
||||
hwaddr addr1;
|
||||
MemTxResult r;
|
||||
bool release_lock = false;
|
||||
|
||||
rcu_read_lock();
|
||||
mr = address_space_translate(as, addr, &addr1, &l,
|
||||
false);
|
||||
if (l < 8 || !memory_access_is_direct(mr, false)) {
|
||||
release_lock |= prepare_mmio_access(mr);
|
||||
|
||||
/* I/O case */
|
||||
r = memory_region_dispatch_read(mr, addr1, &val, 8, attrs);
|
||||
#if defined(TARGET_WORDS_BIGENDIAN)
|
||||
if (endian == DEVICE_LITTLE_ENDIAN) {
|
||||
val = bswap64(val);
|
||||
}
|
||||
#else
|
||||
if (endian == DEVICE_BIG_ENDIAN) {
|
||||
val = bswap64(val);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
/* RAM case */
|
||||
ptr = qemu_map_ram_ptr(mr->ram_block, addr1);
|
||||
switch (endian) {
|
||||
case DEVICE_LITTLE_ENDIAN:
|
||||
val = ldq_le_p(ptr);
|
||||
break;
|
||||
case DEVICE_BIG_ENDIAN:
|
||||
val = ldq_be_p(ptr);
|
||||
break;
|
||||
default:
|
||||
val = ldq_p(ptr);
|
||||
break;
|
||||
}
|
||||
r = MEMTX_OK;
|
||||
}
|
||||
if (result) {
|
||||
*result = r;
|
||||
}
|
||||
if (release_lock) {
|
||||
qemu_mutex_unlock_iothread();
|
||||
}
|
||||
rcu_read_unlock();
|
||||
return val;
|
||||
}
|
||||
|
||||
uint64_t address_space_ldq(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
return address_space_ldq_internal(as, addr, attrs, result,
|
||||
DEVICE_NATIVE_ENDIAN);
|
||||
}
|
||||
|
||||
uint64_t address_space_ldq_le(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
return address_space_ldq_internal(as, addr, attrs, result,
|
||||
DEVICE_LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
uint64_t address_space_ldq_be(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
return address_space_ldq_internal(as, addr, attrs, result,
|
||||
DEVICE_BIG_ENDIAN);
|
||||
}
|
||||
|
||||
uint64_t ldq_phys(AddressSpace *as, hwaddr addr)
|
||||
{
|
||||
return address_space_ldq(as, addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
uint64_t ldq_le_phys(AddressSpace *as, hwaddr addr)
|
||||
{
|
||||
return address_space_ldq_le(as, addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
uint64_t ldq_be_phys(AddressSpace *as, hwaddr addr)
|
||||
{
|
||||
return address_space_ldq_be(as, addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
/* XXX: optimize */
|
||||
uint32_t address_space_ldub(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
uint8_t val;
|
||||
MemTxResult r;
|
||||
|
||||
r = address_space_rw(as, addr, attrs, &val, 1, 0);
|
||||
if (result) {
|
||||
*result = r;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
uint32_t ldub_phys(AddressSpace *as, hwaddr addr)
|
||||
{
|
||||
return address_space_ldub(as, addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
/* warning: addr must be aligned */
|
||||
static inline uint32_t address_space_lduw_internal(AddressSpace *as,
|
||||
int64_t address_space_cache_init(MemoryRegionCache *cache,
|
||||
AddressSpace *as,
|
||||
hwaddr addr,
|
||||
MemTxAttrs attrs,
|
||||
MemTxResult *result,
|
||||
enum device_endian endian)
|
||||
hwaddr len,
|
||||
bool is_write)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
uint64_t val;
|
||||
hwaddr l, xlat;
|
||||
MemoryRegion *mr;
|
||||
hwaddr l = 2;
|
||||
hwaddr addr1;
|
||||
MemTxResult r;
|
||||
bool release_lock = false;
|
||||
void *ptr;
|
||||
|
||||
rcu_read_lock();
|
||||
mr = address_space_translate(as, addr, &addr1, &l,
|
||||
false);
|
||||
if (l < 2 || !memory_access_is_direct(mr, false)) {
|
||||
release_lock |= prepare_mmio_access(mr);
|
||||
assert(len > 0);
|
||||
|
||||
/* I/O case */
|
||||
r = memory_region_dispatch_read(mr, addr1, &val, 2, attrs);
|
||||
#if defined(TARGET_WORDS_BIGENDIAN)
|
||||
if (endian == DEVICE_LITTLE_ENDIAN) {
|
||||
val = bswap16(val);
|
||||
}
|
||||
#else
|
||||
if (endian == DEVICE_BIG_ENDIAN) {
|
||||
val = bswap16(val);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
/* RAM case */
|
||||
ptr = qemu_map_ram_ptr(mr->ram_block, addr1);
|
||||
switch (endian) {
|
||||
case DEVICE_LITTLE_ENDIAN:
|
||||
val = lduw_le_p(ptr);
|
||||
break;
|
||||
case DEVICE_BIG_ENDIAN:
|
||||
val = lduw_be_p(ptr);
|
||||
break;
|
||||
default:
|
||||
val = lduw_p(ptr);
|
||||
break;
|
||||
}
|
||||
r = MEMTX_OK;
|
||||
}
|
||||
if (result) {
|
||||
*result = r;
|
||||
}
|
||||
if (release_lock) {
|
||||
qemu_mutex_unlock_iothread();
|
||||
}
|
||||
rcu_read_unlock();
|
||||
return val;
|
||||
l = len;
|
||||
mr = address_space_translate(as, addr, &xlat, &l, is_write);
|
||||
if (!memory_access_is_direct(mr, is_write)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
uint32_t address_space_lduw(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
l = address_space_extend_translation(as, addr, len, mr, xlat, l, is_write);
|
||||
ptr = qemu_ram_ptr_length(mr->ram_block, xlat, &l);
|
||||
|
||||
cache->xlat = xlat;
|
||||
cache->is_write = is_write;
|
||||
cache->mr = mr;
|
||||
cache->ptr = ptr;
|
||||
cache->len = l;
|
||||
memory_region_ref(cache->mr);
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
void address_space_cache_invalidate(MemoryRegionCache *cache,
|
||||
hwaddr addr,
|
||||
hwaddr access_len)
|
||||
{
|
||||
return address_space_lduw_internal(as, addr, attrs, result,
|
||||
DEVICE_NATIVE_ENDIAN);
|
||||
assert(cache->is_write);
|
||||
invalidate_and_set_dirty(cache->mr, addr + cache->xlat, access_len);
|
||||
}
|
||||
|
||||
uint32_t address_space_lduw_le(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
void address_space_cache_destroy(MemoryRegionCache *cache)
|
||||
{
|
||||
return address_space_lduw_internal(as, addr, attrs, result,
|
||||
DEVICE_LITTLE_ENDIAN);
|
||||
if (!cache->mr) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t address_space_lduw_be(AddressSpace *as, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
if (xen_enabled()) {
|
||||
xen_invalidate_map_cache_entry(cache->ptr);
|
||||
}
|
||||
memory_region_unref(cache->mr);
|
||||
}
|
||||
|
||||
/* Called from RCU critical section. This function has the same
|
||||
* semantics as address_space_translate, but it only works on a
|
||||
* predefined range of a MemoryRegion that was mapped with
|
||||
* address_space_cache_init.
|
||||
*/
|
||||
static inline MemoryRegion *address_space_translate_cached(
|
||||
MemoryRegionCache *cache, hwaddr addr, hwaddr *xlat,
|
||||
hwaddr *plen, bool is_write)
|
||||
{
|
||||
return address_space_lduw_internal(as, addr, attrs, result,
|
||||
DEVICE_BIG_ENDIAN);
|
||||
assert(addr < cache->len && *plen <= cache->len - addr);
|
||||
*xlat = addr + cache->xlat;
|
||||
return cache->mr;
|
||||
}
|
||||
|
||||
uint32_t lduw_phys(AddressSpace *as, hwaddr addr)
|
||||
{
|
||||
return address_space_lduw(as, addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
uint32_t lduw_le_phys(AddressSpace *as, hwaddr addr)
|
||||
{
|
||||
return address_space_lduw_le(as, addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
uint32_t lduw_be_phys(AddressSpace *as, hwaddr addr)
|
||||
{
|
||||
return address_space_lduw_be(as, addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
/* warning: addr must be aligned. The ram page is not masked as dirty
|
||||
and the code inside is not invalidated. It is useful if the dirty
|
||||
bits are used to track modified PTEs */
|
||||
void address_space_stl_notdirty(AddressSpace *as, hwaddr addr, uint32_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
MemoryRegion *mr;
|
||||
hwaddr l = 4;
|
||||
hwaddr addr1;
|
||||
MemTxResult r;
|
||||
uint8_t dirty_log_mask;
|
||||
bool release_lock = false;
|
||||
|
||||
rcu_read_lock();
|
||||
mr = address_space_translate(as, addr, &addr1, &l,
|
||||
true);
|
||||
if (l < 4 || !memory_access_is_direct(mr, true)) {
|
||||
release_lock |= prepare_mmio_access(mr);
|
||||
|
||||
r = memory_region_dispatch_write(mr, addr1, val, 4, attrs);
|
||||
} else {
|
||||
ptr = qemu_map_ram_ptr(mr->ram_block, addr1);
|
||||
stl_p(ptr, val);
|
||||
|
||||
dirty_log_mask = memory_region_get_dirty_log_mask(mr);
|
||||
dirty_log_mask &= ~(1 << DIRTY_MEMORY_CODE);
|
||||
cpu_physical_memory_set_dirty_range(memory_region_get_ram_addr(mr) + addr,
|
||||
4, dirty_log_mask);
|
||||
r = MEMTX_OK;
|
||||
}
|
||||
if (result) {
|
||||
*result = r;
|
||||
}
|
||||
if (release_lock) {
|
||||
qemu_mutex_unlock_iothread();
|
||||
}
|
||||
rcu_read_unlock();
|
||||
}
|
||||
|
||||
void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val)
|
||||
{
|
||||
address_space_stl_notdirty(as, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
/* warning: addr must be aligned */
|
||||
static inline void address_space_stl_internal(AddressSpace *as,
|
||||
hwaddr addr, uint32_t val,
|
||||
MemTxAttrs attrs,
|
||||
MemTxResult *result,
|
||||
enum device_endian endian)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
MemoryRegion *mr;
|
||||
hwaddr l = 4;
|
||||
hwaddr addr1;
|
||||
MemTxResult r;
|
||||
bool release_lock = false;
|
||||
|
||||
rcu_read_lock();
|
||||
mr = address_space_translate(as, addr, &addr1, &l,
|
||||
true);
|
||||
if (l < 4 || !memory_access_is_direct(mr, true)) {
|
||||
release_lock |= prepare_mmio_access(mr);
|
||||
|
||||
#if defined(TARGET_WORDS_BIGENDIAN)
|
||||
if (endian == DEVICE_LITTLE_ENDIAN) {
|
||||
val = bswap32(val);
|
||||
}
|
||||
#else
|
||||
if (endian == DEVICE_BIG_ENDIAN) {
|
||||
val = bswap32(val);
|
||||
}
|
||||
#endif
|
||||
r = memory_region_dispatch_write(mr, addr1, val, 4, attrs);
|
||||
} else {
|
||||
/* RAM case */
|
||||
ptr = qemu_map_ram_ptr(mr->ram_block, addr1);
|
||||
switch (endian) {
|
||||
case DEVICE_LITTLE_ENDIAN:
|
||||
stl_le_p(ptr, val);
|
||||
break;
|
||||
case DEVICE_BIG_ENDIAN:
|
||||
stl_be_p(ptr, val);
|
||||
break;
|
||||
default:
|
||||
stl_p(ptr, val);
|
||||
break;
|
||||
}
|
||||
invalidate_and_set_dirty(mr, addr1, 4);
|
||||
r = MEMTX_OK;
|
||||
}
|
||||
if (result) {
|
||||
*result = r;
|
||||
}
|
||||
if (release_lock) {
|
||||
qemu_mutex_unlock_iothread();
|
||||
}
|
||||
rcu_read_unlock();
|
||||
}
|
||||
|
||||
void address_space_stl(AddressSpace *as, hwaddr addr, uint32_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
address_space_stl_internal(as, addr, val, attrs, result,
|
||||
DEVICE_NATIVE_ENDIAN);
|
||||
}
|
||||
|
||||
void address_space_stl_le(AddressSpace *as, hwaddr addr, uint32_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
address_space_stl_internal(as, addr, val, attrs, result,
|
||||
DEVICE_LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
void address_space_stl_be(AddressSpace *as, hwaddr addr, uint32_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
address_space_stl_internal(as, addr, val, attrs, result,
|
||||
DEVICE_BIG_ENDIAN);
|
||||
}
|
||||
|
||||
void stl_phys(AddressSpace *as, hwaddr addr, uint32_t val)
|
||||
{
|
||||
address_space_stl(as, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
void stl_le_phys(AddressSpace *as, hwaddr addr, uint32_t val)
|
||||
{
|
||||
address_space_stl_le(as, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
void stl_be_phys(AddressSpace *as, hwaddr addr, uint32_t val)
|
||||
{
|
||||
address_space_stl_be(as, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
/* XXX: optimize */
|
||||
void address_space_stb(AddressSpace *as, hwaddr addr, uint32_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
uint8_t v = val;
|
||||
MemTxResult r;
|
||||
|
||||
r = address_space_rw(as, addr, attrs, &v, 1, 1);
|
||||
if (result) {
|
||||
*result = r;
|
||||
}
|
||||
}
|
||||
|
||||
void stb_phys(AddressSpace *as, hwaddr addr, uint32_t val)
|
||||
{
|
||||
address_space_stb(as, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
/* warning: addr must be aligned */
|
||||
static inline void address_space_stw_internal(AddressSpace *as,
|
||||
hwaddr addr, uint32_t val,
|
||||
MemTxAttrs attrs,
|
||||
MemTxResult *result,
|
||||
enum device_endian endian)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
MemoryRegion *mr;
|
||||
hwaddr l = 2;
|
||||
hwaddr addr1;
|
||||
MemTxResult r;
|
||||
bool release_lock = false;
|
||||
|
||||
rcu_read_lock();
|
||||
mr = address_space_translate(as, addr, &addr1, &l, true);
|
||||
if (l < 2 || !memory_access_is_direct(mr, true)) {
|
||||
release_lock |= prepare_mmio_access(mr);
|
||||
|
||||
#if defined(TARGET_WORDS_BIGENDIAN)
|
||||
if (endian == DEVICE_LITTLE_ENDIAN) {
|
||||
val = bswap16(val);
|
||||
}
|
||||
#else
|
||||
if (endian == DEVICE_BIG_ENDIAN) {
|
||||
val = bswap16(val);
|
||||
}
|
||||
#endif
|
||||
r = memory_region_dispatch_write(mr, addr1, val, 2, attrs);
|
||||
} else {
|
||||
/* RAM case */
|
||||
ptr = qemu_map_ram_ptr(mr->ram_block, addr1);
|
||||
switch (endian) {
|
||||
case DEVICE_LITTLE_ENDIAN:
|
||||
stw_le_p(ptr, val);
|
||||
break;
|
||||
case DEVICE_BIG_ENDIAN:
|
||||
stw_be_p(ptr, val);
|
||||
break;
|
||||
default:
|
||||
stw_p(ptr, val);
|
||||
break;
|
||||
}
|
||||
invalidate_and_set_dirty(mr, addr1, 2);
|
||||
r = MEMTX_OK;
|
||||
}
|
||||
if (result) {
|
||||
*result = r;
|
||||
}
|
||||
if (release_lock) {
|
||||
qemu_mutex_unlock_iothread();
|
||||
}
|
||||
rcu_read_unlock();
|
||||
}
|
||||
|
||||
void address_space_stw(AddressSpace *as, hwaddr addr, uint32_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
address_space_stw_internal(as, addr, val, attrs, result,
|
||||
DEVICE_NATIVE_ENDIAN);
|
||||
}
|
||||
|
||||
void address_space_stw_le(AddressSpace *as, hwaddr addr, uint32_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
address_space_stw_internal(as, addr, val, attrs, result,
|
||||
DEVICE_LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
void address_space_stw_be(AddressSpace *as, hwaddr addr, uint32_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
address_space_stw_internal(as, addr, val, attrs, result,
|
||||
DEVICE_BIG_ENDIAN);
|
||||
}
|
||||
|
||||
void stw_phys(AddressSpace *as, hwaddr addr, uint32_t val)
|
||||
{
|
||||
address_space_stw(as, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
void stw_le_phys(AddressSpace *as, hwaddr addr, uint32_t val)
|
||||
{
|
||||
address_space_stw_le(as, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
void stw_be_phys(AddressSpace *as, hwaddr addr, uint32_t val)
|
||||
{
|
||||
address_space_stw_be(as, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
/* XXX: optimize */
|
||||
void address_space_stq(AddressSpace *as, hwaddr addr, uint64_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
MemTxResult r;
|
||||
val = tswap64(val);
|
||||
r = address_space_rw(as, addr, attrs, (void *) &val, 8, 1);
|
||||
if (result) {
|
||||
*result = r;
|
||||
}
|
||||
}
|
||||
|
||||
void address_space_stq_le(AddressSpace *as, hwaddr addr, uint64_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
MemTxResult r;
|
||||
val = cpu_to_le64(val);
|
||||
r = address_space_rw(as, addr, attrs, (void *) &val, 8, 1);
|
||||
if (result) {
|
||||
*result = r;
|
||||
}
|
||||
}
|
||||
void address_space_stq_be(AddressSpace *as, hwaddr addr, uint64_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
MemTxResult r;
|
||||
val = cpu_to_be64(val);
|
||||
r = address_space_rw(as, addr, attrs, (void *) &val, 8, 1);
|
||||
if (result) {
|
||||
*result = r;
|
||||
}
|
||||
}
|
||||
|
||||
void stq_phys(AddressSpace *as, hwaddr addr, uint64_t val)
|
||||
{
|
||||
address_space_stq(as, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
void stq_le_phys(AddressSpace *as, hwaddr addr, uint64_t val)
|
||||
{
|
||||
address_space_stq_le(as, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
void stq_be_phys(AddressSpace *as, hwaddr addr, uint64_t val)
|
||||
{
|
||||
address_space_stq_be(as, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
#define ARG1_DECL MemoryRegionCache *cache
|
||||
#define ARG1 cache
|
||||
#define SUFFIX _cached
|
||||
#define TRANSLATE(...) address_space_translate_cached(cache, __VA_ARGS__)
|
||||
#define IS_DIRECT(mr, is_write) true
|
||||
#define MAP_RAM(mr, ofs) (cache->ptr + (ofs - cache->xlat))
|
||||
#define INVALIDATE(mr, ofs, len) ((void)0)
|
||||
#define RCU_READ_LOCK() ((void)0)
|
||||
#define RCU_READ_UNLOCK() ((void)0)
|
||||
#include "memory_ldst.inc.c"
|
||||
|
||||
/* virtual memory access for debug (includes writing to ROM) */
|
||||
int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
|
||||
|
6
hmp.c
6
hmp.c
@@ -1551,7 +1551,6 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
Error *err = NULL;
|
||||
BlockIOThrottle throttle = {
|
||||
.has_device = true,
|
||||
.device = (char *) qdict_get_str(qdict, "device"),
|
||||
.bps = qdict_get_int(qdict, "bps"),
|
||||
.bps_rd = qdict_get_int(qdict, "bps_rd"),
|
||||
@@ -1809,6 +1808,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
Error *err = NULL;
|
||||
QemuOpts *opts;
|
||||
Visitor *v;
|
||||
Object *obj = NULL;
|
||||
|
||||
opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
|
||||
@@ -1817,7 +1817,9 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
|
||||
return;
|
||||
}
|
||||
|
||||
obj = user_creatable_add_opts(opts, &err);
|
||||
v = opts_visitor_new(opts);
|
||||
obj = user_creatable_add(qdict, v, &err);
|
||||
visit_free(v);
|
||||
qemu_opts_del(opts);
|
||||
|
||||
if (err) {
|
||||
|
1017
hw/9pfs/9p-local.c
1017
hw/9pfs/9p-local.c
File diff suppressed because it is too large
Load Diff
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* 9p local backend utilities
|
||||
*
|
||||
* Copyright IBM, Corp. 2017
|
||||
*
|
||||
* Authors:
|
||||
* Greg Kurz <groug@kaod.org>
|
||||
*
|
||||
* 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_9P_LOCAL_H
|
||||
#define QEMU_9P_LOCAL_H
|
||||
|
||||
int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags,
|
||||
mode_t mode);
|
||||
int local_opendir_nofollow(FsContext *fs_ctx, const char *path);
|
||||
|
||||
#endif
|
@@ -25,7 +25,13 @@
|
||||
static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path,
|
||||
const char *name, void *value, size_t size)
|
||||
{
|
||||
return local_getxattr_nofollow(ctx, path, MAP_ACL_ACCESS, value, size);
|
||||
char *buffer;
|
||||
ssize_t ret;
|
||||
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lgetxattr(buffer, MAP_ACL_ACCESS, value, size);
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
|
||||
@@ -50,16 +56,23 @@ static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
|
||||
static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
|
||||
void *value, size_t size, int flags)
|
||||
{
|
||||
return local_setxattr_nofollow(ctx, path, MAP_ACL_ACCESS, value, size,
|
||||
flags);
|
||||
char *buffer;
|
||||
int ret;
|
||||
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lsetxattr(buffer, MAP_ACL_ACCESS, value, size, flags);
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mp_pacl_removexattr(FsContext *ctx,
|
||||
const char *path, const char *name)
|
||||
{
|
||||
int ret;
|
||||
char *buffer;
|
||||
|
||||
ret = local_removexattr_nofollow(ctx, path, MAP_ACL_ACCESS);
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lremovexattr(buffer, MAP_ACL_ACCESS);
|
||||
if (ret == -1 && errno == ENODATA) {
|
||||
/*
|
||||
* We don't get ENODATA error when trying to remove a
|
||||
@@ -69,13 +82,20 @@ static int mp_pacl_removexattr(FsContext *ctx,
|
||||
errno = 0;
|
||||
ret = 0;
|
||||
}
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
|
||||
const char *name, void *value, size_t size)
|
||||
{
|
||||
return local_getxattr_nofollow(ctx, path, MAP_ACL_DEFAULT, value, size);
|
||||
char *buffer;
|
||||
ssize_t ret;
|
||||
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lgetxattr(buffer, MAP_ACL_DEFAULT, value, size);
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
|
||||
@@ -100,16 +120,23 @@ static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
|
||||
static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
|
||||
void *value, size_t size, int flags)
|
||||
{
|
||||
return local_setxattr_nofollow(ctx, path, MAP_ACL_DEFAULT, value, size,
|
||||
flags);
|
||||
char *buffer;
|
||||
int ret;
|
||||
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lsetxattr(buffer, MAP_ACL_DEFAULT, value, size, flags);
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mp_dacl_removexattr(FsContext *ctx,
|
||||
const char *path, const char *name)
|
||||
{
|
||||
int ret;
|
||||
char *buffer;
|
||||
|
||||
ret = local_removexattr_nofollow(ctx, path, MAP_ACL_DEFAULT);
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lremovexattr(buffer, MAP_ACL_DEFAULT);
|
||||
if (ret == -1 && errno == ENODATA) {
|
||||
/*
|
||||
* We don't get ENODATA error when trying to remove a
|
||||
@@ -119,6 +146,7 @@ static int mp_dacl_removexattr(FsContext *ctx,
|
||||
errno = 0;
|
||||
ret = 0;
|
||||
}
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 9p utilities
|
||||
*
|
||||
* Copyright IBM, Corp. 2017
|
||||
*
|
||||
* Authors:
|
||||
* Greg Kurz <groug@kaod.org>
|
||||
*
|
||||
* 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/xattr.h"
|
||||
#include "9p-util.h"
|
||||
|
||||
int relative_openat_nofollow(int dirfd, const char *path, int flags,
|
||||
mode_t mode)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = dup(dirfd);
|
||||
if (fd == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (*path) {
|
||||
const char *c;
|
||||
int next_fd;
|
||||
char *head;
|
||||
|
||||
/* Only relative paths without consecutive slashes */
|
||||
assert(path[0] != '/');
|
||||
|
||||
head = g_strdup(path);
|
||||
c = strchr(path, '/');
|
||||
if (c) {
|
||||
head[c - path] = 0;
|
||||
next_fd = openat_dir(fd, head);
|
||||
} else {
|
||||
next_fd = openat_file(fd, head, flags, mode);
|
||||
}
|
||||
g_free(head);
|
||||
if (next_fd == -1) {
|
||||
close_preserve_errno(fd);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
fd = next_fd;
|
||||
|
||||
if (!c) {
|
||||
break;
|
||||
}
|
||||
path = c + 1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
ssize_t fgetxattrat_nofollow(int dirfd, const char *filename, const char *name,
|
||||
void *value, size_t size)
|
||||
{
|
||||
char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
|
||||
int ret;
|
||||
|
||||
ret = lgetxattr(proc_path, name, value, size);
|
||||
g_free(proc_path);
|
||||
return ret;
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 9p utilities
|
||||
*
|
||||
* Copyright IBM, Corp. 2017
|
||||
*
|
||||
* Authors:
|
||||
* Greg Kurz <groug@kaod.org>
|
||||
*
|
||||
* 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_9P_UTIL_H
|
||||
#define QEMU_9P_UTIL_H
|
||||
|
||||
static inline void close_preserve_errno(int fd)
|
||||
{
|
||||
int serrno = errno;
|
||||
close(fd);
|
||||
errno = serrno;
|
||||
}
|
||||
|
||||
static inline int openat_dir(int dirfd, const char *name)
|
||||
{
|
||||
#ifdef O_PATH
|
||||
#define OPENAT_DIR_O_PATH O_PATH
|
||||
#else
|
||||
#define OPENAT_DIR_O_PATH 0
|
||||
#endif
|
||||
return openat(dirfd, name,
|
||||
O_DIRECTORY | O_RDONLY | O_NOFOLLOW | OPENAT_DIR_O_PATH);
|
||||
}
|
||||
|
||||
static inline int openat_file(int dirfd, const char *name, int flags,
|
||||
mode_t mode)
|
||||
{
|
||||
int fd, serrno, ret;
|
||||
|
||||
fd = openat(dirfd, name, flags | O_NOFOLLOW | O_NOCTTY | O_NONBLOCK,
|
||||
mode);
|
||||
if (fd == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
serrno = errno;
|
||||
/* O_NONBLOCK was only needed to open the file. Let's drop it. */
|
||||
ret = fcntl(fd, F_SETFL, flags);
|
||||
assert(!ret);
|
||||
errno = serrno;
|
||||
return fd;
|
||||
}
|
||||
|
||||
int relative_openat_nofollow(int dirfd, const char *path, int flags,
|
||||
mode_t mode);
|
||||
ssize_t fgetxattrat_nofollow(int dirfd, const char *path, const char *name,
|
||||
void *value, size_t size);
|
||||
int fsetxattrat_nofollow(int dirfd, const char *path, const char *name,
|
||||
void *value, size_t size, int flags);
|
||||
|
||||
#endif
|
@@ -20,6 +20,9 @@
|
||||
static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
|
||||
const char *name, void *value, size_t size)
|
||||
{
|
||||
char *buffer;
|
||||
ssize_t ret;
|
||||
|
||||
if (strncmp(name, "user.virtfs.", 12) == 0) {
|
||||
/*
|
||||
* Don't allow fetch of user.virtfs namesapce
|
||||
@@ -28,7 +31,10 @@ static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
|
||||
errno = ENOATTR;
|
||||
return -1;
|
||||
}
|
||||
return local_getxattr_nofollow(ctx, path, name, value, size);
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lgetxattr(buffer, name, value, size);
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
|
||||
@@ -67,6 +73,9 @@ static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
|
||||
static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
|
||||
void *value, size_t size, int flags)
|
||||
{
|
||||
char *buffer;
|
||||
int ret;
|
||||
|
||||
if (strncmp(name, "user.virtfs.", 12) == 0) {
|
||||
/*
|
||||
* Don't allow fetch of user.virtfs namesapce
|
||||
@@ -75,12 +84,18 @@ static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
return local_setxattr_nofollow(ctx, path, name, value, size, flags);
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lsetxattr(buffer, name, value, size, flags);
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mp_user_removexattr(FsContext *ctx,
|
||||
const char *path, const char *name)
|
||||
{
|
||||
char *buffer;
|
||||
int ret;
|
||||
|
||||
if (strncmp(name, "user.virtfs.", 12) == 0) {
|
||||
/*
|
||||
* Don't allow fetch of user.virtfs namesapce
|
||||
@@ -89,7 +104,10 @@ static int mp_user_removexattr(FsContext *ctx,
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
return local_removexattr_nofollow(ctx, path, name);
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lremovexattr(buffer, name);
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
XattrOperations mapped_user_xattr = {
|
||||
|
@@ -15,8 +15,6 @@
|
||||
#include "9p.h"
|
||||
#include "fsdev/file-op-9p.h"
|
||||
#include "9p-xattr.h"
|
||||
#include "9p-util.h"
|
||||
#include "9p-local.h"
|
||||
|
||||
|
||||
static XattrOperations *get_xattr_operations(XattrOperations **h,
|
||||
@@ -60,16 +58,6 @@ ssize_t pt_listxattr(FsContext *ctx, const char *path,
|
||||
return name_size;
|
||||
}
|
||||
|
||||
static ssize_t flistxattrat_nofollow(int dirfd, const char *filename,
|
||||
char *list, size_t size)
|
||||
{
|
||||
char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
|
||||
int ret;
|
||||
|
||||
ret = llistxattr(proc_path, list, size);
|
||||
g_free(proc_path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the list and pass to each layer to find out whether
|
||||
@@ -79,37 +67,24 @@ ssize_t v9fs_list_xattr(FsContext *ctx, const char *path,
|
||||
void *value, size_t vsize)
|
||||
{
|
||||
ssize_t size = 0;
|
||||
char *buffer;
|
||||
void *ovalue = value;
|
||||
XattrOperations *xops;
|
||||
char *orig_value, *orig_value_start;
|
||||
ssize_t xattr_len, parsed_len = 0, attr_len;
|
||||
char *dirpath, *name;
|
||||
int dirfd;
|
||||
|
||||
/* Get the actual len */
|
||||
dirpath = g_path_get_dirname(path);
|
||||
dirfd = local_opendir_nofollow(ctx, dirpath);
|
||||
g_free(dirpath);
|
||||
if (dirfd == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = g_path_get_basename(path);
|
||||
xattr_len = flistxattrat_nofollow(dirfd, name, value, 0);
|
||||
buffer = rpath(ctx, path);
|
||||
xattr_len = llistxattr(buffer, value, 0);
|
||||
if (xattr_len <= 0) {
|
||||
g_free(name);
|
||||
close_preserve_errno(dirfd);
|
||||
g_free(buffer);
|
||||
return xattr_len;
|
||||
}
|
||||
|
||||
/* Now fetch the xattr and find the actual size */
|
||||
orig_value = g_malloc(xattr_len);
|
||||
xattr_len = flistxattrat_nofollow(dirfd, name, orig_value, xattr_len);
|
||||
g_free(name);
|
||||
close_preserve_errno(dirfd);
|
||||
if (xattr_len < 0) {
|
||||
return -1;
|
||||
}
|
||||
xattr_len = llistxattr(buffer, orig_value, xattr_len);
|
||||
g_free(buffer);
|
||||
|
||||
/* store the orig pointer */
|
||||
orig_value_start = orig_value;
|
||||
@@ -168,135 +143,6 @@ int v9fs_remove_xattr(FsContext *ctx,
|
||||
|
||||
}
|
||||
|
||||
ssize_t local_getxattr_nofollow(FsContext *ctx, const char *path,
|
||||
const char *name, void *value, size_t size)
|
||||
{
|
||||
char *dirpath = g_path_get_dirname(path);
|
||||
char *filename = g_path_get_basename(path);
|
||||
int dirfd;
|
||||
ssize_t ret = -1;
|
||||
|
||||
dirfd = local_opendir_nofollow(ctx, dirpath);
|
||||
if (dirfd == -1) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = fgetxattrat_nofollow(dirfd, filename, name, value, size);
|
||||
close_preserve_errno(dirfd);
|
||||
out:
|
||||
g_free(dirpath);
|
||||
g_free(filename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t pt_getxattr(FsContext *ctx, const char *path, const char *name,
|
||||
void *value, size_t size)
|
||||
{
|
||||
return local_getxattr_nofollow(ctx, path, name, value, size);
|
||||
}
|
||||
|
||||
int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,
|
||||
void *value, size_t size, int flags)
|
||||
{
|
||||
char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
|
||||
int ret;
|
||||
|
||||
ret = lsetxattr(proc_path, name, value, size, flags);
|
||||
g_free(proc_path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t local_setxattr_nofollow(FsContext *ctx, const char *path,
|
||||
const char *name, void *value, size_t size,
|
||||
int flags)
|
||||
{
|
||||
char *dirpath = g_path_get_dirname(path);
|
||||
char *filename = g_path_get_basename(path);
|
||||
int dirfd;
|
||||
ssize_t ret = -1;
|
||||
|
||||
dirfd = local_opendir_nofollow(ctx, dirpath);
|
||||
if (dirfd == -1) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = fsetxattrat_nofollow(dirfd, filename, name, value, size, flags);
|
||||
close_preserve_errno(dirfd);
|
||||
out:
|
||||
g_free(dirpath);
|
||||
g_free(filename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pt_setxattr(FsContext *ctx, const char *path, const char *name, void *value,
|
||||
size_t size, int flags)
|
||||
{
|
||||
return local_setxattr_nofollow(ctx, path, name, value, size, flags);
|
||||
}
|
||||
|
||||
static ssize_t fremovexattrat_nofollow(int dirfd, const char *filename,
|
||||
const char *name)
|
||||
{
|
||||
char *proc_path = g_strdup_printf("/proc/self/fd/%d/%s", dirfd, filename);
|
||||
int ret;
|
||||
|
||||
ret = lremovexattr(proc_path, name);
|
||||
g_free(proc_path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t local_removexattr_nofollow(FsContext *ctx, const char *path,
|
||||
const char *name)
|
||||
{
|
||||
char *dirpath = g_path_get_dirname(path);
|
||||
char *filename = g_path_get_basename(path);
|
||||
int dirfd;
|
||||
ssize_t ret = -1;
|
||||
|
||||
dirfd = local_opendir_nofollow(ctx, dirpath);
|
||||
if (dirfd == -1) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = fremovexattrat_nofollow(dirfd, filename, name);
|
||||
close_preserve_errno(dirfd);
|
||||
out:
|
||||
g_free(dirpath);
|
||||
g_free(filename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pt_removexattr(FsContext *ctx, const char *path, const char *name)
|
||||
{
|
||||
return local_removexattr_nofollow(ctx, path, name);
|
||||
}
|
||||
|
||||
ssize_t notsup_getxattr(FsContext *ctx, const char *path, const char *name,
|
||||
void *value, size_t size)
|
||||
{
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int notsup_setxattr(FsContext *ctx, const char *path, const char *name,
|
||||
void *value, size_t size, int flags)
|
||||
{
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t notsup_listxattr(FsContext *ctx, const char *path, char *name,
|
||||
void *value, size_t size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int notsup_removexattr(FsContext *ctx, const char *path, const char *name)
|
||||
{
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
XattrOperations *mapped_xattr_ops[] = {
|
||||
&mapped_user_xattr,
|
||||
&mapped_pacl_xattr,
|
||||
|
@@ -29,13 +29,6 @@ typedef struct xattr_operations
|
||||
const char *path, const char *name);
|
||||
} XattrOperations;
|
||||
|
||||
ssize_t local_getxattr_nofollow(FsContext *ctx, const char *path,
|
||||
const char *name, void *value, size_t size);
|
||||
ssize_t local_setxattr_nofollow(FsContext *ctx, const char *path,
|
||||
const char *name, void *value, size_t size,
|
||||
int flags);
|
||||
ssize_t local_removexattr_nofollow(FsContext *ctx, const char *path,
|
||||
const char *name);
|
||||
|
||||
extern XattrOperations mapped_user_xattr;
|
||||
extern XattrOperations passthrough_user_xattr;
|
||||
@@ -56,21 +49,73 @@ ssize_t v9fs_list_xattr(FsContext *ctx, const char *path, void *value,
|
||||
int v9fs_set_xattr(FsContext *ctx, const char *path, const char *name,
|
||||
void *value, size_t size, int flags);
|
||||
int v9fs_remove_xattr(FsContext *ctx, const char *path, const char *name);
|
||||
|
||||
ssize_t pt_listxattr(FsContext *ctx, const char *path, char *name, void *value,
|
||||
size_t size);
|
||||
ssize_t pt_getxattr(FsContext *ctx, const char *path, const char *name,
|
||||
void *value, size_t size);
|
||||
int pt_setxattr(FsContext *ctx, const char *path, const char *name, void *value,
|
||||
size_t size, int flags);
|
||||
int pt_removexattr(FsContext *ctx, const char *path, const char *name);
|
||||
|
||||
ssize_t notsup_getxattr(FsContext *ctx, const char *path, const char *name,
|
||||
void *value, size_t size);
|
||||
int notsup_setxattr(FsContext *ctx, const char *path, const char *name,
|
||||
void *value, size_t size, int flags);
|
||||
ssize_t notsup_listxattr(FsContext *ctx, const char *path, char *name,
|
||||
void *value, size_t size);
|
||||
int notsup_removexattr(FsContext *ctx, const char *path, const char *name);
|
||||
static inline ssize_t pt_getxattr(FsContext *ctx, const char *path,
|
||||
const char *name, void *value, size_t size)
|
||||
{
|
||||
char *buffer;
|
||||
ssize_t ret;
|
||||
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lgetxattr(buffer, name, value, size);
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline int pt_setxattr(FsContext *ctx, const char *path,
|
||||
const char *name, void *value,
|
||||
size_t size, int flags)
|
||||
{
|
||||
char *buffer;
|
||||
int ret;
|
||||
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lsetxattr(buffer, name, value, size, flags);
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline int pt_removexattr(FsContext *ctx,
|
||||
const char *path, const char *name)
|
||||
{
|
||||
char *buffer;
|
||||
int ret;
|
||||
|
||||
buffer = rpath(ctx, path);
|
||||
ret = lremovexattr(path, name);
|
||||
g_free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline ssize_t notsup_getxattr(FsContext *ctx, const char *path,
|
||||
const char *name, void *value,
|
||||
size_t size)
|
||||
{
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int notsup_setxattr(FsContext *ctx, const char *path,
|
||||
const char *name, void *value,
|
||||
size_t size, int flags)
|
||||
{
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline ssize_t notsup_listxattr(FsContext *ctx, const char *path,
|
||||
char *name, void *value, size_t size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int notsup_removexattr(FsContext *ctx,
|
||||
const char *path, const char *name)
|
||||
{
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
84
hw/9pfs/9p.c
84
hw/9pfs/9p.c
@@ -47,7 +47,7 @@ ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = virtio_pdu_vmarshal(pdu, offset, fmt, ap);
|
||||
ret = pdu->s->transport->pdu_vmarshal(pdu, offset, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
@@ -59,7 +59,7 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = virtio_pdu_vunmarshal(pdu, offset, fmt, ap);
|
||||
ret = pdu->s->transport->pdu_vunmarshal(pdu, offset, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
@@ -67,7 +67,7 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
|
||||
|
||||
static void pdu_push_and_notify(V9fsPDU *pdu)
|
||||
{
|
||||
virtio_9p_push_and_notify(pdu);
|
||||
pdu->s->transport->push_and_notify(pdu);
|
||||
}
|
||||
|
||||
static int omode_to_uflags(int8_t mode)
|
||||
@@ -1633,14 +1633,43 @@ out_nofid:
|
||||
pdu_complete(pdu, err);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a QEMUIOVector for a sub-region of PDU iovecs
|
||||
*
|
||||
* @qiov: uninitialized QEMUIOVector
|
||||
* @skip: number of bytes to skip from beginning of PDU
|
||||
* @size: number of bytes to include
|
||||
* @is_write: true - write, false - read
|
||||
*
|
||||
* The resulting QEMUIOVector has heap-allocated iovecs and must be cleaned up
|
||||
* with qemu_iovec_destroy().
|
||||
*/
|
||||
static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu,
|
||||
size_t skip, size_t size,
|
||||
bool is_write)
|
||||
{
|
||||
QEMUIOVector elem;
|
||||
struct iovec *iov;
|
||||
unsigned int niov;
|
||||
|
||||
if (is_write) {
|
||||
pdu->s->transport->init_out_iov_from_pdu(pdu, &iov, &niov);
|
||||
} else {
|
||||
pdu->s->transport->init_in_iov_from_pdu(pdu, &iov, &niov, size);
|
||||
}
|
||||
|
||||
qemu_iovec_init_external(&elem, iov, niov);
|
||||
qemu_iovec_init(qiov, niov);
|
||||
qemu_iovec_concat(qiov, &elem, skip, size);
|
||||
}
|
||||
|
||||
static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
|
||||
uint64_t off, uint32_t max_count)
|
||||
{
|
||||
ssize_t err;
|
||||
size_t offset = 7;
|
||||
uint64_t read_count;
|
||||
V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
|
||||
VirtQueueElement *elem = v->elems[pdu->idx];
|
||||
QEMUIOVector qiov_full;
|
||||
|
||||
if (fidp->fs.xattr.len < off) {
|
||||
read_count = 0;
|
||||
@@ -1656,9 +1685,11 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
|
||||
}
|
||||
offset += err;
|
||||
|
||||
err = v9fs_pack(elem->in_sg, elem->in_num, offset,
|
||||
v9fs_init_qiov_from_pdu(&qiov_full, pdu, 0, read_count, false);
|
||||
err = v9fs_pack(qiov_full.iov, qiov_full.niov, offset,
|
||||
((char *)fidp->fs.xattr.value) + off,
|
||||
read_count);
|
||||
qemu_iovec_destroy(&qiov_full);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
@@ -1732,32 +1763,6 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu,
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a QEMUIOVector for a sub-region of PDU iovecs
|
||||
*
|
||||
* @qiov: uninitialized QEMUIOVector
|
||||
* @skip: number of bytes to skip from beginning of PDU
|
||||
* @size: number of bytes to include
|
||||
* @is_write: true - write, false - read
|
||||
*
|
||||
* The resulting QEMUIOVector has heap-allocated iovecs and must be cleaned up
|
||||
* with qemu_iovec_destroy().
|
||||
*/
|
||||
static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu,
|
||||
size_t skip, size_t size,
|
||||
bool is_write)
|
||||
{
|
||||
QEMUIOVector elem;
|
||||
struct iovec *iov;
|
||||
unsigned int niov;
|
||||
|
||||
virtio_init_iov_from_pdu(pdu, &iov, &niov, is_write);
|
||||
|
||||
qemu_iovec_init_external(&elem, iov, niov);
|
||||
qemu_iovec_init(qiov, niov);
|
||||
qemu_iovec_concat(qiov, &elem, skip, size);
|
||||
}
|
||||
|
||||
static void coroutine_fn v9fs_read(void *opaque)
|
||||
{
|
||||
int32_t fid;
|
||||
@@ -2337,7 +2342,7 @@ static void v9fs_flush(void *opaque)
|
||||
ssize_t err;
|
||||
int16_t tag;
|
||||
size_t offset = 7;
|
||||
V9fsPDU *cancel_pdu = NULL;
|
||||
V9fsPDU *cancel_pdu;
|
||||
V9fsPDU *pdu = opaque;
|
||||
V9fsState *s = pdu->s;
|
||||
|
||||
@@ -2348,15 +2353,11 @@ static void v9fs_flush(void *opaque)
|
||||
}
|
||||
trace_v9fs_flush(pdu->tag, pdu->id, tag);
|
||||
|
||||
if (pdu->tag == tag) {
|
||||
error_report("Warning: the guest sent a self-referencing 9P flush request");
|
||||
} else {
|
||||
QLIST_FOREACH(cancel_pdu, &s->active_list, next) {
|
||||
if (cancel_pdu->tag == tag) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cancel_pdu) {
|
||||
cancel_pdu->cancelled = 1;
|
||||
/*
|
||||
@@ -3444,7 +3445,6 @@ void pdu_submit(V9fsPDU *pdu)
|
||||
/* Returns 0 on success, 1 on failure. */
|
||||
int v9fs_device_realize_common(V9fsState *s, Error **errp)
|
||||
{
|
||||
V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
|
||||
int i, len;
|
||||
struct stat stat;
|
||||
FsDriverEntry *fse;
|
||||
@@ -3454,10 +3454,10 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp)
|
||||
/* initialize pdu allocator */
|
||||
QLIST_INIT(&s->free_list);
|
||||
QLIST_INIT(&s->active_list);
|
||||
for (i = 0; i < MAX_REQ; i++) {
|
||||
QLIST_INSERT_HEAD(&s->free_list, &v->pdus[i], next);
|
||||
v->pdus[i].s = s;
|
||||
v->pdus[i].idx = i;
|
||||
for (i = 0; i < (MAX_REQ - 1); i++) {
|
||||
QLIST_INSERT_HEAD(&s->free_list, &s->pdus[i], next);
|
||||
s->pdus[i].s = s;
|
||||
s->pdus[i].idx = i;
|
||||
}
|
||||
|
||||
v9fs_path_init(&path);
|
||||
|
26
hw/9pfs/9p.h
26
hw/9pfs/9p.h
@@ -99,8 +99,8 @@ enum p9_proto_version {
|
||||
V9FS_PROTO_2000L = 0x02,
|
||||
};
|
||||
|
||||
#define P9_NOTAG (u16)(~0)
|
||||
#define P9_NOFID (u32)(~0)
|
||||
#define P9_NOTAG UINT16_MAX
|
||||
#define P9_NOFID UINT32_MAX
|
||||
#define P9_MAXWELEM 16
|
||||
|
||||
#define FID_REFERENCED 0x1
|
||||
@@ -229,6 +229,8 @@ typedef struct V9fsState
|
||||
char *tag;
|
||||
enum p9_proto_version proto_version;
|
||||
int32_t msize;
|
||||
V9fsPDU pdus[MAX_REQ];
|
||||
const struct V9fsTransport *transport;
|
||||
/*
|
||||
* lock ensuring atomic path update
|
||||
* on rename.
|
||||
@@ -342,4 +344,24 @@ void pdu_free(V9fsPDU *pdu);
|
||||
void pdu_submit(V9fsPDU *pdu);
|
||||
void v9fs_reset(V9fsState *s);
|
||||
|
||||
struct V9fsTransport {
|
||||
ssize_t (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt,
|
||||
va_list ap);
|
||||
ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt,
|
||||
va_list ap);
|
||||
void (*init_in_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov,
|
||||
unsigned int *pniov, size_t size);
|
||||
void (*init_out_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov,
|
||||
unsigned int *pniov);
|
||||
void (*push_and_notify)(V9fsPDU *pdu);
|
||||
};
|
||||
|
||||
static inline int v9fs_register_transport(V9fsState *s,
|
||||
const struct V9fsTransport *t)
|
||||
{
|
||||
assert(!s->transport);
|
||||
s->transport = t;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,4 +1,4 @@
|
||||
common-obj-y = 9p.o 9p-util.o
|
||||
common-obj-y = 9p.o
|
||||
common-obj-y += 9p-local.o 9p-xattr.o
|
||||
common-obj-y += 9p-xattr-user.o 9p-posix-acl.o
|
||||
common-obj-y += coth.o cofs.o codir.o cofile.o
|
||||
|
@@ -20,7 +20,9 @@
|
||||
#include "hw/virtio/virtio-access.h"
|
||||
#include "qemu/iov.h"
|
||||
|
||||
void virtio_9p_push_and_notify(V9fsPDU *pdu)
|
||||
static const struct V9fsTransport virtio_9p_transport;
|
||||
|
||||
static void virtio_9p_push_and_notify(V9fsPDU *pdu)
|
||||
{
|
||||
V9fsState *s = pdu->s;
|
||||
V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
|
||||
@@ -126,6 +128,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
|
||||
v->config_size = sizeof(struct virtio_9p_config) + strlen(s->fsconf.tag);
|
||||
virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P, v->config_size);
|
||||
v->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
|
||||
v9fs_register_transport(s, &virtio_9p_transport);
|
||||
|
||||
out:
|
||||
return;
|
||||
@@ -148,7 +151,7 @@ static void virtio_9p_reset(VirtIODevice *vdev)
|
||||
v9fs_reset(&v->state);
|
||||
}
|
||||
|
||||
ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
|
||||
static ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
V9fsState *s = pdu->s;
|
||||
@@ -158,7 +161,7 @@ ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
|
||||
return v9fs_iov_vmarshal(elem->in_sg, elem->in_num, offset, 1, fmt, ap);
|
||||
}
|
||||
|
||||
ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
|
||||
static ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
V9fsState *s = pdu->s;
|
||||
@@ -168,22 +171,37 @@ ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
|
||||
return v9fs_iov_vunmarshal(elem->out_sg, elem->out_num, offset, 1, fmt, ap);
|
||||
}
|
||||
|
||||
void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
|
||||
unsigned int *pniov, bool is_write)
|
||||
/* The size parameter is used by other transports. Do not drop it. */
|
||||
static void virtio_init_in_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
|
||||
unsigned int *pniov, size_t size)
|
||||
{
|
||||
V9fsState *s = pdu->s;
|
||||
V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
|
||||
VirtQueueElement *elem = v->elems[pdu->idx];
|
||||
|
||||
if (is_write) {
|
||||
*piov = elem->out_sg;
|
||||
*pniov = elem->out_num;
|
||||
} else {
|
||||
*piov = elem->in_sg;
|
||||
*pniov = elem->in_num;
|
||||
}
|
||||
|
||||
static void virtio_init_out_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
|
||||
unsigned int *pniov)
|
||||
{
|
||||
V9fsState *s = pdu->s;
|
||||
V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
|
||||
VirtQueueElement *elem = v->elems[pdu->idx];
|
||||
|
||||
*piov = elem->out_sg;
|
||||
*pniov = elem->out_num;
|
||||
}
|
||||
|
||||
static const struct V9fsTransport virtio_9p_transport = {
|
||||
.pdu_vmarshal = virtio_pdu_vmarshal,
|
||||
.pdu_vunmarshal = virtio_pdu_vunmarshal,
|
||||
.init_in_iov_from_pdu = virtio_init_in_iov_from_pdu,
|
||||
.init_out_iov_from_pdu = virtio_init_out_iov_from_pdu,
|
||||
.push_and_notify = virtio_9p_push_and_notify,
|
||||
};
|
||||
|
||||
/* virtio-9p device */
|
||||
|
||||
static const VMStateDescription vmstate_virtio_9p = {
|
||||
|
@@ -10,20 +10,10 @@ typedef struct V9fsVirtioState
|
||||
VirtIODevice parent_obj;
|
||||
VirtQueue *vq;
|
||||
size_t config_size;
|
||||
V9fsPDU pdus[MAX_REQ];
|
||||
VirtQueueElement *elems[MAX_REQ];
|
||||
V9fsState state;
|
||||
} V9fsVirtioState;
|
||||
|
||||
void virtio_9p_push_and_notify(V9fsPDU *pdu);
|
||||
|
||||
ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
|
||||
const char *fmt, va_list ap);
|
||||
ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
|
||||
const char *fmt, va_list ap);
|
||||
void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
|
||||
unsigned int *pniov, bool is_write);
|
||||
|
||||
#define TYPE_VIRTIO_9P "virtio-9p-device"
|
||||
#define VIRTIO_9P(obj) \
|
||||
OBJECT_CHECK(V9fsVirtioState, (obj), TYPE_VIRTIO_9P)
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#ifndef HW_ALPHA_SYS_H
|
||||
#define HW_ALPHA_SYS_H
|
||||
|
||||
#include "target-alpha/cpu-qom.h"
|
||||
#include "target/alpha/cpu-qom.h"
|
||||
#include "hw/pci/pci.h"
|
||||
#include "hw/pci/pci_host.h"
|
||||
#include "hw/ide.h"
|
||||
|
@@ -34,13 +34,18 @@ typedef struct AspeedBoardState {
|
||||
typedef struct AspeedBoardConfig {
|
||||
const char *soc_name;
|
||||
uint32_t hw_strap1;
|
||||
const char *fmc_model;
|
||||
const char *spi_model;
|
||||
uint32_t num_cs;
|
||||
} AspeedBoardConfig;
|
||||
|
||||
enum {
|
||||
PALMETTO_BMC,
|
||||
AST2500_EVB,
|
||||
ROMULUS_BMC,
|
||||
};
|
||||
|
||||
/* Palmetto hardware value: 0x120CE416 */
|
||||
#define PALMETTO_BMC_HW_STRAP1 ( \
|
||||
SCU_AST2400_HW_STRAP_DRAM_SIZE(DRAM_SIZE_256MB) | \
|
||||
SCU_AST2400_HW_STRAP_DRAM_CONFIG(2 /* DDR3 with CL=6, CWL=5 */) | \
|
||||
@@ -54,6 +59,7 @@ enum {
|
||||
SCU_HW_STRAP_VGA_SIZE_SET(VGA_16M_DRAM) | \
|
||||
SCU_AST2400_HW_STRAP_BOOT_MODE(AST2400_SPI_BOOT))
|
||||
|
||||
/* AST2500 evb hardware value: 0xF100C2E6 */
|
||||
#define AST2500_EVB_HW_STRAP1 (( \
|
||||
AST2500_HW_STRAP1_DEFAULTS | \
|
||||
SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE | \
|
||||
@@ -64,9 +70,38 @@ enum {
|
||||
SCU_HW_STRAP_MAC0_RGMII) & \
|
||||
~SCU_HW_STRAP_2ND_BOOT_WDT)
|
||||
|
||||
/* Romulus hardware value: 0xF10AD206 */
|
||||
#define ROMULUS_BMC_HW_STRAP1 ( \
|
||||
AST2500_HW_STRAP1_DEFAULTS | \
|
||||
SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE | \
|
||||
SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE | \
|
||||
SCU_AST2500_HW_STRAP_UART_DEBUG | \
|
||||
SCU_AST2500_HW_STRAP_DDR4_ENABLE | \
|
||||
SCU_AST2500_HW_STRAP_ACPI_ENABLE | \
|
||||
SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER))
|
||||
|
||||
static const AspeedBoardConfig aspeed_boards[] = {
|
||||
[PALMETTO_BMC] = { "ast2400-a0", PALMETTO_BMC_HW_STRAP1 },
|
||||
[AST2500_EVB] = { "ast2500-a1", AST2500_EVB_HW_STRAP1 },
|
||||
[PALMETTO_BMC] = {
|
||||
.soc_name = "ast2400-a1",
|
||||
.hw_strap1 = PALMETTO_BMC_HW_STRAP1,
|
||||
.fmc_model = "n25q256a",
|
||||
.spi_model = "mx25l25635e",
|
||||
.num_cs = 1,
|
||||
},
|
||||
[AST2500_EVB] = {
|
||||
.soc_name = "ast2500-a1",
|
||||
.hw_strap1 = AST2500_EVB_HW_STRAP1,
|
||||
.fmc_model = "n25q256a",
|
||||
.spi_model = "mx25l25635e",
|
||||
.num_cs = 1,
|
||||
},
|
||||
[ROMULUS_BMC] = {
|
||||
.soc_name = "ast2500-a1",
|
||||
.hw_strap1 = ROMULUS_BMC_HW_STRAP1,
|
||||
.fmc_model = "n25q256a",
|
||||
.spi_model = "mx66l1g45g",
|
||||
.num_cs = 2,
|
||||
},
|
||||
};
|
||||
|
||||
static void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype,
|
||||
@@ -112,6 +147,8 @@ static void aspeed_board_init(MachineState *machine,
|
||||
&error_abort);
|
||||
object_property_set_int(OBJECT(&bmc->soc), cfg->hw_strap1, "hw-strap1",
|
||||
&error_abort);
|
||||
object_property_set_int(OBJECT(&bmc->soc), cfg->num_cs, "num-cs",
|
||||
&error_abort);
|
||||
object_property_set_bool(OBJECT(&bmc->soc), true, "realized",
|
||||
&error_abort);
|
||||
|
||||
@@ -128,8 +165,8 @@ static void aspeed_board_init(MachineState *machine,
|
||||
object_property_add_const_link(OBJECT(&bmc->soc), "ram", OBJECT(&bmc->ram),
|
||||
&error_abort);
|
||||
|
||||
aspeed_board_init_flashes(&bmc->soc.fmc, "n25q256a", &error_abort);
|
||||
aspeed_board_init_flashes(&bmc->soc.spi[0], "mx25l25635e", &error_abort);
|
||||
aspeed_board_init_flashes(&bmc->soc.fmc, cfg->fmc_model, &error_abort);
|
||||
aspeed_board_init_flashes(&bmc->soc.spi[0], cfg->spi_model, &error_abort);
|
||||
|
||||
aspeed_board_binfo.kernel_filename = machine->kernel_filename;
|
||||
aspeed_board_binfo.initrd_filename = machine->initrd_filename;
|
||||
@@ -188,10 +225,35 @@ static const TypeInfo ast2500_evb_type = {
|
||||
.class_init = ast2500_evb_class_init,
|
||||
};
|
||||
|
||||
static void romulus_bmc_init(MachineState *machine)
|
||||
{
|
||||
aspeed_board_init(machine, &aspeed_boards[ROMULUS_BMC]);
|
||||
}
|
||||
|
||||
static void romulus_bmc_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
MachineClass *mc = MACHINE_CLASS(oc);
|
||||
|
||||
mc->desc = "OpenPOWER Romulus BMC (ARM1176)";
|
||||
mc->init = romulus_bmc_init;
|
||||
mc->max_cpus = 1;
|
||||
mc->no_sdcard = 1;
|
||||
mc->no_floppy = 1;
|
||||
mc->no_cdrom = 1;
|
||||
mc->no_parallel = 1;
|
||||
}
|
||||
|
||||
static const TypeInfo romulus_bmc_type = {
|
||||
.name = MACHINE_TYPE_NAME("romulus-bmc"),
|
||||
.parent = TYPE_MACHINE,
|
||||
.class_init = romulus_bmc_class_init,
|
||||
};
|
||||
|
||||
static void aspeed_machine_init(void)
|
||||
{
|
||||
type_register_static(&palmetto_bmc_type);
|
||||
type_register_static(&ast2500_evb_type);
|
||||
type_register_static(&romulus_bmc_type);
|
||||
}
|
||||
|
||||
type_init(aspeed_machine_init)
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#define ASPEED_SOC_VIC_BASE 0x1E6C0000
|
||||
#define ASPEED_SOC_SDMC_BASE 0x1E6E0000
|
||||
#define ASPEED_SOC_SCU_BASE 0x1E6E2000
|
||||
#define ASPEED_SOC_SRAM_BASE 0x1E720000
|
||||
#define ASPEED_SOC_TIMER_BASE 0x1E782000
|
||||
#define ASPEED_SOC_I2C_BASE 0x1E78A000
|
||||
|
||||
@@ -47,15 +48,47 @@ static const char *aspeed_soc_ast2500_typenames[] = {
|
||||
"aspeed.smc.ast2500-spi1", "aspeed.smc.ast2500-spi2" };
|
||||
|
||||
static const AspeedSoCInfo aspeed_socs[] = {
|
||||
{ "ast2400-a0", "arm926", AST2400_A0_SILICON_REV, AST2400_SDRAM_BASE,
|
||||
1, aspeed_soc_ast2400_spi_bases,
|
||||
"aspeed.smc.fmc", aspeed_soc_ast2400_typenames },
|
||||
{ "ast2400", "arm926", AST2400_A0_SILICON_REV, AST2400_SDRAM_BASE,
|
||||
1, aspeed_soc_ast2400_spi_bases,
|
||||
"aspeed.smc.fmc", aspeed_soc_ast2400_typenames },
|
||||
{ "ast2500-a1", "arm1176", AST2500_A1_SILICON_REV, AST2500_SDRAM_BASE,
|
||||
2, aspeed_soc_ast2500_spi_bases,
|
||||
"aspeed.smc.ast2500-fmc", aspeed_soc_ast2500_typenames },
|
||||
{
|
||||
.name = "ast2400-a0",
|
||||
.cpu_model = "arm926",
|
||||
.silicon_rev = AST2400_A0_SILICON_REV,
|
||||
.sdram_base = AST2400_SDRAM_BASE,
|
||||
.sram_size = 0x8000,
|
||||
.spis_num = 1,
|
||||
.spi_bases = aspeed_soc_ast2400_spi_bases,
|
||||
.fmc_typename = "aspeed.smc.fmc",
|
||||
.spi_typename = aspeed_soc_ast2400_typenames,
|
||||
}, {
|
||||
.name = "ast2400-a1",
|
||||
.cpu_model = "arm926",
|
||||
.silicon_rev = AST2400_A1_SILICON_REV,
|
||||
.sdram_base = AST2400_SDRAM_BASE,
|
||||
.sram_size = 0x8000,
|
||||
.spis_num = 1,
|
||||
.spi_bases = aspeed_soc_ast2400_spi_bases,
|
||||
.fmc_typename = "aspeed.smc.fmc",
|
||||
.spi_typename = aspeed_soc_ast2400_typenames,
|
||||
}, {
|
||||
.name = "ast2400",
|
||||
.cpu_model = "arm926",
|
||||
.silicon_rev = AST2400_A0_SILICON_REV,
|
||||
.sdram_base = AST2400_SDRAM_BASE,
|
||||
.sram_size = 0x8000,
|
||||
.spis_num = 1,
|
||||
.spi_bases = aspeed_soc_ast2400_spi_bases,
|
||||
.fmc_typename = "aspeed.smc.fmc",
|
||||
.spi_typename = aspeed_soc_ast2400_typenames,
|
||||
}, {
|
||||
.name = "ast2500-a1",
|
||||
.cpu_model = "arm1176",
|
||||
.silicon_rev = AST2500_A1_SILICON_REV,
|
||||
.sdram_base = AST2500_SDRAM_BASE,
|
||||
.sram_size = 0x9000,
|
||||
.spis_num = 2,
|
||||
.spi_bases = aspeed_soc_ast2500_spi_bases,
|
||||
.fmc_typename = "aspeed.smc.ast2500-fmc",
|
||||
.spi_typename = aspeed_soc_ast2500_typenames,
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -87,9 +120,13 @@ static void aspeed_soc_init(Object *obj)
|
||||
{
|
||||
AspeedSoCState *s = ASPEED_SOC(obj);
|
||||
AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
|
||||
char *cpu_typename;
|
||||
int i;
|
||||
|
||||
s->cpu = cpu_arm_init(sc->info->cpu_model);
|
||||
cpu_typename = g_strdup_printf("%s-" TYPE_ARM_CPU, sc->info->cpu_model);
|
||||
object_initialize(&s->cpu, sizeof(s->cpu), cpu_typename);
|
||||
object_property_add_child(obj, "cpu", OBJECT(&s->cpu), NULL);
|
||||
g_free(cpu_typename);
|
||||
|
||||
object_initialize(&s->vic, sizeof(s->vic), TYPE_ASPEED_VIC);
|
||||
object_property_add_child(obj, "vic", OBJECT(&s->vic), NULL);
|
||||
@@ -116,11 +153,13 @@ static void aspeed_soc_init(Object *obj)
|
||||
object_initialize(&s->fmc, sizeof(s->fmc), sc->info->fmc_typename);
|
||||
object_property_add_child(obj, "fmc", OBJECT(&s->fmc), NULL);
|
||||
qdev_set_parent_bus(DEVICE(&s->fmc), sysbus_get_default());
|
||||
object_property_add_alias(obj, "num-cs", OBJECT(&s->fmc), "num-cs",
|
||||
&error_abort);
|
||||
|
||||
for (i = 0; i < sc->info->spis_num; i++) {
|
||||
object_initialize(&s->spi[i], sizeof(s->spi[i]),
|
||||
sc->info->spi_typename[i]);
|
||||
object_property_add_child(obj, "spi", OBJECT(&s->spi[i]), NULL);
|
||||
object_property_add_child(obj, "spi[*]", OBJECT(&s->spi[i]), NULL);
|
||||
qdev_set_parent_bus(DEVICE(&s->spi[i]), sysbus_get_default());
|
||||
}
|
||||
|
||||
@@ -146,6 +185,24 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
|
||||
memory_region_add_subregion_overlap(get_system_memory(),
|
||||
ASPEED_SOC_IOMEM_BASE, &s->iomem, -1);
|
||||
|
||||
/* CPU */
|
||||
object_property_set_bool(OBJECT(&s->cpu), true, "realized", &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
return;
|
||||
}
|
||||
|
||||
/* SRAM */
|
||||
memory_region_init_ram(&s->sram, OBJECT(dev), "aspeed.sram",
|
||||
sc->info->sram_size, &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
return;
|
||||
}
|
||||
vmstate_register_ram_global(&s->sram);
|
||||
memory_region_add_subregion(get_system_memory(), ASPEED_SOC_SRAM_BASE,
|
||||
&s->sram);
|
||||
|
||||
/* VIC */
|
||||
object_property_set_bool(OBJECT(&s->vic), true, "realized", &err);
|
||||
if (err) {
|
||||
@@ -154,9 +211,9 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
|
||||
}
|
||||
sysbus_mmio_map(SYS_BUS_DEVICE(&s->vic), 0, ASPEED_SOC_VIC_BASE);
|
||||
sysbus_connect_irq(SYS_BUS_DEVICE(&s->vic), 0,
|
||||
qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_IRQ));
|
||||
qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_IRQ));
|
||||
sysbus_connect_irq(SYS_BUS_DEVICE(&s->vic), 1,
|
||||
qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_FIQ));
|
||||
qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_FIQ));
|
||||
|
||||
/* Timer */
|
||||
object_property_set_bool(OBJECT(&s->timerctrl), true, "realized", &err);
|
||||
@@ -195,10 +252,8 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
|
||||
sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c), 0,
|
||||
qdev_get_gpio_in(DEVICE(&s->vic), 12));
|
||||
|
||||
/* FMC */
|
||||
object_property_set_int(OBJECT(&s->fmc), 1, "num-cs", &err);
|
||||
object_property_set_bool(OBJECT(&s->fmc), true, "realized", &local_err);
|
||||
error_propagate(&err, local_err);
|
||||
/* FMC, The number of CS is set at the board level */
|
||||
object_property_set_bool(OBJECT(&s->fmc), true, "realized", &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
return;
|
||||
@@ -240,12 +295,6 @@ static void aspeed_soc_class_init(ObjectClass *oc, void *data)
|
||||
|
||||
sc->info = (AspeedSoCInfo *) data;
|
||||
dc->realize = aspeed_soc_realize;
|
||||
|
||||
/*
|
||||
* Reason: creates an ARM CPU, thus use after free(), see
|
||||
* arm_cpu_class_init()
|
||||
*/
|
||||
dc->cannot_destroy_with_object_finalize_yet = true;
|
||||
}
|
||||
|
||||
static const TypeInfo aspeed_soc_type_info = {
|
||||
|
@@ -1449,17 +1449,10 @@ static const VMStateDescription vmstate_pxa2xx_i2c = {
|
||||
}
|
||||
};
|
||||
|
||||
static int pxa2xx_i2c_slave_init(I2CSlave *i2c)
|
||||
{
|
||||
/* Nothing to do. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pxa2xx_i2c_slave_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
|
||||
|
||||
k->init = pxa2xx_i2c_slave_init;
|
||||
k->event = pxa2xx_i2c_event;
|
||||
k->recv = pxa2xx_i2c_rx;
|
||||
k->send = pxa2xx_i2c_tx;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#define STRONGARM_H
|
||||
|
||||
#include "exec/memory.h"
|
||||
#include "target-arm/cpu-qom.h"
|
||||
#include "target/arm/cpu-qom.h"
|
||||
|
||||
#define SA_CS0 0x00000000
|
||||
#define SA_CS1 0x08000000
|
||||
|
@@ -202,12 +202,6 @@ static int tosa_dac_recv(I2CSlave *s)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int tosa_dac_init(I2CSlave *i2c)
|
||||
{
|
||||
/* Nothing to do. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void tosa_tg_init(PXA2xxState *cpu)
|
||||
{
|
||||
I2CBus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
|
||||
@@ -275,7 +269,6 @@ static void tosa_dac_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
|
||||
|
||||
k->init = tosa_dac_init;
|
||||
k->event = tosa_dac_event;
|
||||
k->recv = tosa_dac_recv;
|
||||
k->send = tosa_dac_send;
|
||||
|
@@ -33,7 +33,7 @@
|
||||
#include "qemu/bitmap.h"
|
||||
#include "trace.h"
|
||||
#include "qom/cpu.h"
|
||||
#include "target-arm/cpu.h"
|
||||
#include "target/arm/cpu.h"
|
||||
#include "hw/acpi/acpi-defs.h"
|
||||
#include "hw/acpi/acpi.h"
|
||||
#include "hw/nvram/fw_cfg.h"
|
||||
|
@@ -1525,7 +1525,7 @@ static void machvirt_machine_init(void)
|
||||
}
|
||||
type_init(machvirt_machine_init);
|
||||
|
||||
static void virt_2_8_instance_init(Object *obj)
|
||||
static void virt_2_9_instance_init(Object *obj)
|
||||
{
|
||||
VirtMachineState *vms = VIRT_MACHINE(obj);
|
||||
|
||||
@@ -1558,10 +1558,25 @@ static void virt_2_8_instance_init(Object *obj)
|
||||
"Valid values are 2, 3 and host", NULL);
|
||||
}
|
||||
|
||||
static void virt_machine_2_8_options(MachineClass *mc)
|
||||
static void virt_machine_2_9_options(MachineClass *mc)
|
||||
{
|
||||
}
|
||||
DEFINE_VIRT_MACHINE_AS_LATEST(2, 8)
|
||||
DEFINE_VIRT_MACHINE_AS_LATEST(2, 9)
|
||||
|
||||
#define VIRT_COMPAT_2_8 \
|
||||
HW_COMPAT_2_8
|
||||
|
||||
static void virt_2_8_instance_init(Object *obj)
|
||||
{
|
||||
virt_2_9_instance_init(obj);
|
||||
}
|
||||
|
||||
static void virt_machine_2_8_options(MachineClass *mc)
|
||||
{
|
||||
virt_machine_2_9_options(mc);
|
||||
SET_MACHINE_COMPAT(mc, VIRT_COMPAT_2_8);
|
||||
}
|
||||
DEFINE_VIRT_MACHINE(2, 8)
|
||||
|
||||
#define VIRT_COMPAT_2_7 \
|
||||
HW_COMPAT_2_7
|
||||
|
@@ -263,12 +263,6 @@ static int aer915_recv(I2CSlave *slave)
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int aer915_init(I2CSlave *i2c)
|
||||
{
|
||||
/* Nothing to do. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static VMStateDescription vmstate_aer915_state = {
|
||||
.name = "aer915",
|
||||
.version_id = 1,
|
||||
@@ -285,7 +279,6 @@ static void aer915_class_init(ObjectClass *klass, void *data)
|
||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
|
||||
|
||||
k->init = aer915_init;
|
||||
k->event = aer915_event;
|
||||
k->recv = aer915_recv;
|
||||
k->send = aer915_send;
|
||||
|
@@ -203,6 +203,7 @@ static const FlashPartInfo known_devices[] = {
|
||||
{ INFO("mx25l25655e", 0xc22619, 0, 64 << 10, 512, 0) },
|
||||
{ INFO("mx66u51235f", 0xc2253a, 0, 64 << 10, 1024, ER_4K | ER_32K) },
|
||||
{ INFO("mx66u1g45g", 0xc2253b, 0, 64 << 10, 2048, ER_4K | ER_32K) },
|
||||
{ INFO("mx66l1g45g", 0xc2201b, 0, 64 << 10, 2048, ER_4K | ER_32K) },
|
||||
|
||||
/* Micron */
|
||||
{ INFO("n25q032a11", 0x20bb16, 0, 64 << 10, 64, ER_4K) },
|
||||
|
@@ -707,6 +707,19 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
|
||||
int num_devices;
|
||||
Error *local_err = NULL;
|
||||
|
||||
if (pfl->sector_len == 0) {
|
||||
error_setg(errp, "attribute \"sector-length\" not specified or zero.");
|
||||
return;
|
||||
}
|
||||
if (pfl->nb_blocs == 0) {
|
||||
error_setg(errp, "attribute \"num-blocks\" not specified or zero.");
|
||||
return;
|
||||
}
|
||||
if (pfl->name == NULL) {
|
||||
error_setg(errp, "attribute \"name\" not specified.");
|
||||
return;
|
||||
}
|
||||
|
||||
total_len = pfl->sector_len * pfl->nb_blocs;
|
||||
|
||||
/* These are only used to expose the parameters of each device
|
||||
|
@@ -600,6 +600,19 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
|
||||
int ret;
|
||||
Error *local_err = NULL;
|
||||
|
||||
if (pfl->sector_len == 0) {
|
||||
error_setg(errp, "attribute \"sector-length\" not specified or zero.");
|
||||
return;
|
||||
}
|
||||
if (pfl->nb_blocs == 0) {
|
||||
error_setg(errp, "attribute \"num-blocks\" not specified or zero.");
|
||||
return;
|
||||
}
|
||||
if (pfl->name == NULL) {
|
||||
error_setg(errp, "attribute \"name\" not specified.");
|
||||
return;
|
||||
}
|
||||
|
||||
chip_len = pfl->sector_len * pfl->nb_blocs;
|
||||
/* XXX: to be fixed */
|
||||
#if 0
|
||||
|
@@ -588,6 +588,9 @@ void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq)
|
||||
|
||||
blk_io_plug(s->blk);
|
||||
|
||||
do {
|
||||
virtio_queue_set_notification(vq, 0);
|
||||
|
||||
while ((req = virtio_blk_get_request(s, vq))) {
|
||||
if (virtio_blk_handle_request(req, &mrb)) {
|
||||
virtqueue_detach_element(req->vq, &req->elem, 0);
|
||||
@@ -596,6 +599,9 @@ void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq)
|
||||
}
|
||||
}
|
||||
|
||||
virtio_queue_set_notification(vq, 1);
|
||||
} while (!virtio_queue_empty(vq));
|
||||
|
||||
if (mrb.num_reqs) {
|
||||
virtio_blk_submit_multireq(s->blk, &mrb);
|
||||
}
|
||||
|
@@ -138,10 +138,11 @@ static void fifo_trigger_update(void *opaque)
|
||||
{
|
||||
CadenceUARTState *s = opaque;
|
||||
|
||||
if (s->r[R_RTOR]) {
|
||||
s->r[R_CISR] |= UART_INTR_TIMEOUT;
|
||||
|
||||
uart_update_status(s);
|
||||
}
|
||||
}
|
||||
|
||||
static void uart_rx_reset(CadenceUARTState *s)
|
||||
{
|
||||
@@ -502,6 +503,13 @@ static int cadence_uart_post_load(void *opaque, int version_id)
|
||||
{
|
||||
CadenceUARTState *s = opaque;
|
||||
|
||||
/* Ensure these two aren't invalid numbers */
|
||||
if (s->r[R_BRGR] < 1 || s->r[R_BRGR] & ~0xFFFF ||
|
||||
s->r[R_BDIV] <= 3 || s->r[R_BDIV] & ~0xFF) {
|
||||
/* Value is invalid, abort */
|
||||
return 1;
|
||||
}
|
||||
|
||||
uart_parameters_setup(s);
|
||||
uart_update_status(s);
|
||||
return 0;
|
||||
|
@@ -554,31 +554,11 @@ static void machine_class_finalize(ObjectClass *klass, void *data)
|
||||
g_free(mc->name);
|
||||
}
|
||||
|
||||
static void register_compat_prop(const char *driver,
|
||||
const char *property,
|
||||
const char *value)
|
||||
{
|
||||
GlobalProperty *p = g_new0(GlobalProperty, 1);
|
||||
/* Machine compat_props must never cause errors: */
|
||||
p->errp = &error_abort;
|
||||
p->driver = driver;
|
||||
p->property = property;
|
||||
p->value = value;
|
||||
qdev_prop_register_global(p);
|
||||
}
|
||||
|
||||
static void machine_register_compat_for_subclass(ObjectClass *oc, void *opaque)
|
||||
{
|
||||
GlobalProperty *p = opaque;
|
||||
register_compat_prop(object_class_get_name(oc), p->property, p->value);
|
||||
}
|
||||
|
||||
void machine_register_compat_props(MachineState *machine)
|
||||
{
|
||||
MachineClass *mc = MACHINE_GET_CLASS(machine);
|
||||
int i;
|
||||
GlobalProperty *p;
|
||||
ObjectClass *oc;
|
||||
|
||||
if (!mc->compat_props) {
|
||||
return;
|
||||
@@ -586,22 +566,9 @@ void machine_register_compat_props(MachineState *machine)
|
||||
|
||||
for (i = 0; i < mc->compat_props->len; i++) {
|
||||
p = g_array_index(mc->compat_props, GlobalProperty *, i);
|
||||
oc = object_class_by_name(p->driver);
|
||||
if (oc && object_class_is_abstract(oc)) {
|
||||
/* temporary hack to make sure we do not override
|
||||
* globals set explicitly on -global: if an abstract class
|
||||
* is on compat_props, register globals for all its
|
||||
* non-abstract subtypes instead.
|
||||
*
|
||||
* This doesn't solve the problem for cases where
|
||||
* a non-abstract typename mentioned on compat_props
|
||||
* has subclasses, like spapr-pci-host-bridge.
|
||||
*/
|
||||
object_class_foreach(machine_register_compat_for_subclass,
|
||||
p->driver, false, p);
|
||||
} else {
|
||||
register_compat_prop(p->driver, p->property, p->value);
|
||||
}
|
||||
/* Machine compat_props must never cause errors: */
|
||||
p->errp = &error_abort;
|
||||
qdev_prop_register_global(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -177,12 +177,11 @@
|
||||
|
||||
struct CirrusVGAState;
|
||||
typedef void (*cirrus_bitblt_rop_t) (struct CirrusVGAState *s,
|
||||
uint32_t dstaddr, uint32_t srcaddr,
|
||||
uint8_t * dst, const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
int bltwidth, int bltheight);
|
||||
typedef void (*cirrus_fill_t)(struct CirrusVGAState *s,
|
||||
uint32_t dstaddr, int dst_pitch,
|
||||
int width, int height);
|
||||
uint8_t *dst, int dst_pitch, int width, int height);
|
||||
|
||||
typedef struct CirrusVGAState {
|
||||
VGACommonState vga;
|
||||
@@ -278,9 +277,10 @@ static bool blit_region_is_unsafe(struct CirrusVGAState *s,
|
||||
}
|
||||
if (pitch < 0) {
|
||||
int64_t min = addr
|
||||
+ ((int64_t)s->cirrus_blt_height - 1) * pitch
|
||||
- s->cirrus_blt_width;
|
||||
if (min < -1 || addr >= s->vga.vram_size) {
|
||||
+ ((int64_t)s->cirrus_blt_height-1) * pitch;
|
||||
int32_t max = addr
|
||||
+ s->cirrus_blt_width;
|
||||
if (min < 0 || max > s->vga.vram_size) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
@@ -294,7 +294,7 @@ static bool blit_region_is_unsafe(struct CirrusVGAState *s,
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool blit_is_unsafe(struct CirrusVGAState *s, bool dst_only)
|
||||
static bool blit_is_unsafe(struct CirrusVGAState *s)
|
||||
{
|
||||
/* should be the case, see cirrus_bitblt_start */
|
||||
assert(s->cirrus_blt_width > 0);
|
||||
@@ -305,14 +305,11 @@ static bool blit_is_unsafe(struct CirrusVGAState *s, bool dst_only)
|
||||
}
|
||||
|
||||
if (blit_region_is_unsafe(s, s->cirrus_blt_dstpitch,
|
||||
s->cirrus_blt_dstaddr)) {
|
||||
s->cirrus_blt_dstaddr & s->cirrus_addr_mask)) {
|
||||
return true;
|
||||
}
|
||||
if (dst_only) {
|
||||
return false;
|
||||
}
|
||||
if (blit_region_is_unsafe(s, s->cirrus_blt_srcpitch,
|
||||
s->cirrus_blt_srcaddr)) {
|
||||
s->cirrus_blt_srcaddr & s->cirrus_addr_mask)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -320,57 +317,18 @@ static bool blit_is_unsafe(struct CirrusVGAState *s, bool dst_only)
|
||||
}
|
||||
|
||||
static void cirrus_bitblt_rop_nop(CirrusVGAState *s,
|
||||
uint32_t dstaddr, uint32_t srcaddr,
|
||||
uint8_t *dst,const uint8_t *src,
|
||||
int dstpitch,int srcpitch,
|
||||
int bltwidth,int bltheight)
|
||||
{
|
||||
}
|
||||
|
||||
static void cirrus_bitblt_fill_nop(CirrusVGAState *s,
|
||||
uint32_t dstaddr,
|
||||
uint8_t *dst,
|
||||
int dstpitch, int bltwidth,int bltheight)
|
||||
{
|
||||
}
|
||||
|
||||
static inline uint8_t cirrus_src(CirrusVGAState *s, uint32_t srcaddr)
|
||||
{
|
||||
if (s->cirrus_srccounter) {
|
||||
/* cputovideo */
|
||||
return s->cirrus_bltbuf[srcaddr & (CIRRUS_BLTBUFSIZE - 1)];
|
||||
} else {
|
||||
/* videotovideo */
|
||||
return s->vga.vram_ptr[srcaddr & s->cirrus_addr_mask];
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint16_t cirrus_src16(CirrusVGAState *s, uint32_t srcaddr)
|
||||
{
|
||||
uint16_t *src;
|
||||
|
||||
if (s->cirrus_srccounter) {
|
||||
/* cputovideo */
|
||||
src = (void *)&s->cirrus_bltbuf[srcaddr & (CIRRUS_BLTBUFSIZE - 1) & ~1];
|
||||
} else {
|
||||
/* videotovideo */
|
||||
src = (void *)&s->vga.vram_ptr[srcaddr & s->cirrus_addr_mask & ~1];
|
||||
}
|
||||
return *src;
|
||||
}
|
||||
|
||||
static inline uint32_t cirrus_src32(CirrusVGAState *s, uint32_t srcaddr)
|
||||
{
|
||||
uint32_t *src;
|
||||
|
||||
if (s->cirrus_srccounter) {
|
||||
/* cputovideo */
|
||||
src = (void *)&s->cirrus_bltbuf[srcaddr & (CIRRUS_BLTBUFSIZE - 1) & ~3];
|
||||
} else {
|
||||
/* videotovideo */
|
||||
src = (void *)&s->vga.vram_ptr[srcaddr & s->cirrus_addr_mask & ~3];
|
||||
}
|
||||
return *src;
|
||||
}
|
||||
|
||||
#define ROP_NAME 0
|
||||
#define ROP_FN(d, s) 0
|
||||
#include "cirrus_vga_rop.h"
|
||||
@@ -700,51 +658,25 @@ static void cirrus_invalidate_region(CirrusVGAState * s, int off_begin,
|
||||
int off_cur;
|
||||
int off_cur_end;
|
||||
|
||||
if (off_pitch < 0) {
|
||||
off_begin -= bytesperline - 1;
|
||||
}
|
||||
|
||||
for (y = 0; y < lines; y++) {
|
||||
off_cur = off_begin;
|
||||
off_cur_end = ((off_cur + bytesperline - 1) & s->cirrus_addr_mask) + 1;
|
||||
assert(off_cur_end >= off_cur);
|
||||
off_cur_end = (off_cur + bytesperline) & s->cirrus_addr_mask;
|
||||
memory_region_set_dirty(&s->vga.vram, off_cur, off_cur_end - off_cur);
|
||||
off_begin += off_pitch;
|
||||
}
|
||||
}
|
||||
|
||||
static int cirrus_bitblt_common_patterncopy(CirrusVGAState *s)
|
||||
static int cirrus_bitblt_common_patterncopy(CirrusVGAState * s,
|
||||
const uint8_t * src)
|
||||
{
|
||||
uint32_t patternsize;
|
||||
bool videosrc = !s->cirrus_srccounter;
|
||||
uint8_t *dst;
|
||||
|
||||
if (videosrc) {
|
||||
switch (s->vga.get_bpp(&s->vga)) {
|
||||
case 8:
|
||||
patternsize = 64;
|
||||
break;
|
||||
case 15:
|
||||
case 16:
|
||||
patternsize = 128;
|
||||
break;
|
||||
case 24:
|
||||
case 32:
|
||||
default:
|
||||
patternsize = 256;
|
||||
break;
|
||||
}
|
||||
s->cirrus_blt_srcaddr &= ~(patternsize - 1);
|
||||
if (s->cirrus_blt_srcaddr + patternsize > s->vga.vram_size) {
|
||||
dst = s->vga.vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask);
|
||||
|
||||
if (blit_is_unsafe(s))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (blit_is_unsafe(s, true)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
(*s->cirrus_rop) (s, s->cirrus_blt_dstaddr,
|
||||
videosrc ? s->cirrus_blt_srcaddr : 0,
|
||||
(*s->cirrus_rop) (s, dst, src,
|
||||
s->cirrus_blt_dstpitch, 0,
|
||||
s->cirrus_blt_width, s->cirrus_blt_height);
|
||||
cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
|
||||
@@ -759,11 +691,11 @@ static int cirrus_bitblt_solidfill(CirrusVGAState *s, int blt_rop)
|
||||
{
|
||||
cirrus_fill_t rop_func;
|
||||
|
||||
if (blit_is_unsafe(s, true)) {
|
||||
if (blit_is_unsafe(s)) {
|
||||
return 0;
|
||||
}
|
||||
rop_func = cirrus_fill[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
|
||||
rop_func(s, s->cirrus_blt_dstaddr,
|
||||
rop_func(s, s->vga.vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask),
|
||||
s->cirrus_blt_dstpitch,
|
||||
s->cirrus_blt_width, s->cirrus_blt_height);
|
||||
cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
|
||||
@@ -781,7 +713,9 @@ static int cirrus_bitblt_solidfill(CirrusVGAState *s, int blt_rop)
|
||||
|
||||
static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState * s)
|
||||
{
|
||||
return cirrus_bitblt_common_patterncopy(s);
|
||||
return cirrus_bitblt_common_patterncopy(s,
|
||||
s->vga.vram_ptr + ((s->cirrus_blt_srcaddr & ~7) &
|
||||
s->cirrus_addr_mask));
|
||||
}
|
||||
|
||||
static int cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
|
||||
@@ -830,13 +764,21 @@ static int cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
|
||||
}
|
||||
}
|
||||
|
||||
(*s->cirrus_rop) (s, s->cirrus_blt_dstaddr,
|
||||
s->cirrus_blt_srcaddr,
|
||||
/* we have to flush all pending changes so that the copy
|
||||
is generated at the appropriate moment in time */
|
||||
if (notify)
|
||||
graphic_hw_update(s->vga.con);
|
||||
|
||||
(*s->cirrus_rop) (s, s->vga.vram_ptr +
|
||||
(s->cirrus_blt_dstaddr & s->cirrus_addr_mask),
|
||||
s->vga.vram_ptr +
|
||||
(s->cirrus_blt_srcaddr & s->cirrus_addr_mask),
|
||||
s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch,
|
||||
s->cirrus_blt_width, s->cirrus_blt_height);
|
||||
|
||||
if (notify) {
|
||||
dpy_gfx_update(s->vga.con, dx, dy,
|
||||
qemu_console_copy(s->vga.con,
|
||||
sx, sy, dx, dy,
|
||||
s->cirrus_blt_width / depth,
|
||||
s->cirrus_blt_height);
|
||||
}
|
||||
@@ -853,7 +795,7 @@ static int cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
|
||||
|
||||
static int cirrus_bitblt_videotovideo_copy(CirrusVGAState * s)
|
||||
{
|
||||
if (blit_is_unsafe(s, false))
|
||||
if (blit_is_unsafe(s))
|
||||
return 0;
|
||||
|
||||
return cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->vga.start_addr,
|
||||
@@ -874,15 +816,16 @@ static void cirrus_bitblt_cputovideo_next(CirrusVGAState * s)
|
||||
|
||||
if (s->cirrus_srccounter > 0) {
|
||||
if (s->cirrus_blt_mode & CIRRUS_BLTMODE_PATTERNCOPY) {
|
||||
cirrus_bitblt_common_patterncopy(s);
|
||||
cirrus_bitblt_common_patterncopy(s, s->cirrus_bltbuf);
|
||||
the_end:
|
||||
s->cirrus_srccounter = 0;
|
||||
cirrus_bitblt_reset(s);
|
||||
} else {
|
||||
/* at least one scan line */
|
||||
do {
|
||||
(*s->cirrus_rop)(s, s->cirrus_blt_dstaddr,
|
||||
0, 0, 0, s->cirrus_blt_width, 1);
|
||||
(*s->cirrus_rop)(s, s->vga.vram_ptr +
|
||||
(s->cirrus_blt_dstaddr & s->cirrus_addr_mask),
|
||||
s->cirrus_bltbuf, 0, 0, s->cirrus_blt_width, 1);
|
||||
cirrus_invalidate_region(s, s->cirrus_blt_dstaddr, 0,
|
||||
s->cirrus_blt_width, 1);
|
||||
s->cirrus_blt_dstaddr += s->cirrus_blt_dstpitch;
|
||||
@@ -928,10 +871,6 @@ static int cirrus_bitblt_cputovideo(CirrusVGAState * s)
|
||||
{
|
||||
int w;
|
||||
|
||||
if (blit_is_unsafe(s, true)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
s->cirrus_blt_mode &= ~CIRRUS_BLTMODE_MEMSYSSRC;
|
||||
s->cirrus_srcptr = &s->cirrus_bltbuf[0];
|
||||
s->cirrus_srcptr_end = &s->cirrus_bltbuf[0];
|
||||
@@ -957,10 +896,6 @@ static int cirrus_bitblt_cputovideo(CirrusVGAState * s)
|
||||
}
|
||||
s->cirrus_srccounter = s->cirrus_blt_srcpitch * s->cirrus_blt_height;
|
||||
}
|
||||
|
||||
/* the blit_is_unsafe call above should catch this */
|
||||
assert(s->cirrus_blt_srcpitch <= CIRRUS_BLTBUFSIZE);
|
||||
|
||||
s->cirrus_srcptr = s->cirrus_bltbuf;
|
||||
s->cirrus_srcptr_end = s->cirrus_bltbuf + s->cirrus_blt_srcpitch;
|
||||
cirrus_update_memory_access(s);
|
||||
@@ -1008,9 +943,6 @@ static void cirrus_bitblt_start(CirrusVGAState * s)
|
||||
s->cirrus_blt_modeext = s->vga.gr[0x33];
|
||||
blt_rop = s->vga.gr[0x32];
|
||||
|
||||
s->cirrus_blt_dstaddr &= s->cirrus_addr_mask;
|
||||
s->cirrus_blt_srcaddr &= s->cirrus_addr_mask;
|
||||
|
||||
#ifdef DEBUG_BITBLT
|
||||
printf("rop=0x%02x mode=0x%02x modeext=0x%02x w=%d h=%d dpitch=%d spitch=%d daddr=0x%08x saddr=0x%08x writemask=0x%02x\n",
|
||||
blt_rop,
|
||||
|
@@ -22,63 +22,29 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
static inline void glue(rop_8_, ROP_NAME)(CirrusVGAState *s,
|
||||
uint32_t dstaddr, uint8_t src)
|
||||
static inline void glue(rop_8_,ROP_NAME)(uint8_t *dst, uint8_t src)
|
||||
{
|
||||
uint8_t *dst = &s->vga.vram_ptr[dstaddr & s->cirrus_addr_mask];
|
||||
*dst = ROP_FN(*dst, src);
|
||||
}
|
||||
|
||||
static inline void glue(rop_tr_8_, ROP_NAME)(CirrusVGAState *s,
|
||||
uint32_t dstaddr, uint8_t src,
|
||||
uint8_t transp)
|
||||
static inline void glue(rop_16_,ROP_NAME)(uint16_t *dst, uint16_t src)
|
||||
{
|
||||
uint8_t *dst = &s->vga.vram_ptr[dstaddr & s->cirrus_addr_mask];
|
||||
uint8_t pixel = ROP_FN(*dst, src);
|
||||
if (pixel != transp) {
|
||||
*dst = pixel;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void glue(rop_16_, ROP_NAME)(CirrusVGAState *s,
|
||||
uint32_t dstaddr, uint16_t src)
|
||||
{
|
||||
uint16_t *dst = (uint16_t *)
|
||||
(&s->vga.vram_ptr[dstaddr & s->cirrus_addr_mask & ~1]);
|
||||
*dst = ROP_FN(*dst, src);
|
||||
}
|
||||
|
||||
static inline void glue(rop_tr_16_, ROP_NAME)(CirrusVGAState *s,
|
||||
uint32_t dstaddr, uint16_t src,
|
||||
uint16_t transp)
|
||||
static inline void glue(rop_32_,ROP_NAME)(uint32_t *dst, uint32_t src)
|
||||
{
|
||||
uint16_t *dst = (uint16_t *)
|
||||
(&s->vga.vram_ptr[dstaddr & s->cirrus_addr_mask & ~1]);
|
||||
uint16_t pixel = ROP_FN(*dst, src);
|
||||
if (pixel != transp) {
|
||||
*dst = pixel;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void glue(rop_32_, ROP_NAME)(CirrusVGAState *s,
|
||||
uint32_t dstaddr, uint32_t src)
|
||||
{
|
||||
uint32_t *dst = (uint32_t *)
|
||||
(&s->vga.vram_ptr[dstaddr & s->cirrus_addr_mask & ~3]);
|
||||
*dst = ROP_FN(*dst, src);
|
||||
}
|
||||
|
||||
#define ROP_OP(st, d, s) glue(rop_8_, ROP_NAME)(st, d, s)
|
||||
#define ROP_OP_TR(st, d, s, t) glue(rop_tr_8_, ROP_NAME)(st, d, s, t)
|
||||
#define ROP_OP_16(st, d, s) glue(rop_16_, ROP_NAME)(st, d, s)
|
||||
#define ROP_OP_TR_16(st, d, s, t) glue(rop_tr_16_, ROP_NAME)(st, d, s, t)
|
||||
#define ROP_OP_32(st, d, s) glue(rop_32_, ROP_NAME)(st, d, s)
|
||||
#define ROP_OP(d, s) glue(rop_8_,ROP_NAME)(d, s)
|
||||
#define ROP_OP_16(d, s) glue(rop_16_,ROP_NAME)(d, s)
|
||||
#define ROP_OP_32(d, s) glue(rop_32_,ROP_NAME)(d, s)
|
||||
#undef ROP_FN
|
||||
|
||||
static void
|
||||
glue(cirrus_bitblt_rop_fwd_, ROP_NAME)(CirrusVGAState *s,
|
||||
uint32_t dstaddr,
|
||||
uint32_t srcaddr,
|
||||
uint8_t *dst,const uint8_t *src,
|
||||
int dstpitch,int srcpitch,
|
||||
int bltwidth,int bltheight)
|
||||
{
|
||||
@@ -92,19 +58,18 @@ glue(cirrus_bitblt_rop_fwd_, ROP_NAME)(CirrusVGAState *s,
|
||||
|
||||
for (y = 0; y < bltheight; y++) {
|
||||
for (x = 0; x < bltwidth; x++) {
|
||||
ROP_OP(s, dstaddr, cirrus_src(s, srcaddr));
|
||||
dstaddr++;
|
||||
srcaddr++;
|
||||
ROP_OP(dst, *src);
|
||||
dst++;
|
||||
src++;
|
||||
}
|
||||
dstaddr += dstpitch;
|
||||
srcaddr += srcpitch;
|
||||
dst += dstpitch;
|
||||
src += srcpitch;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
glue(cirrus_bitblt_rop_bkwd_, ROP_NAME)(CirrusVGAState *s,
|
||||
uint32_t dstaddr,
|
||||
uint32_t srcaddr,
|
||||
uint8_t *dst,const uint8_t *src,
|
||||
int dstpitch,int srcpitch,
|
||||
int bltwidth,int bltheight)
|
||||
{
|
||||
@@ -113,118 +78,114 @@ glue(cirrus_bitblt_rop_bkwd_, ROP_NAME)(CirrusVGAState *s,
|
||||
srcpitch += bltwidth;
|
||||
for (y = 0; y < bltheight; y++) {
|
||||
for (x = 0; x < bltwidth; x++) {
|
||||
ROP_OP(s, dstaddr, cirrus_src(s, srcaddr));
|
||||
dstaddr--;
|
||||
srcaddr--;
|
||||
ROP_OP(dst, *src);
|
||||
dst--;
|
||||
src--;
|
||||
}
|
||||
dstaddr += dstpitch;
|
||||
srcaddr += srcpitch;
|
||||
dst += dstpitch;
|
||||
src += srcpitch;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
glue(glue(cirrus_bitblt_rop_fwd_transp_, ROP_NAME),_8)(CirrusVGAState *s,
|
||||
uint32_t dstaddr,
|
||||
uint32_t srcaddr,
|
||||
int dstpitch,
|
||||
int srcpitch,
|
||||
int bltwidth,
|
||||
int bltheight)
|
||||
uint8_t *dst,const uint8_t *src,
|
||||
int dstpitch,int srcpitch,
|
||||
int bltwidth,int bltheight)
|
||||
{
|
||||
int x,y;
|
||||
uint8_t transp = s->vga.gr[0x34];
|
||||
uint8_t p;
|
||||
dstpitch -= bltwidth;
|
||||
srcpitch -= bltwidth;
|
||||
|
||||
if (bltheight > 1 && (dstpitch < 0 || srcpitch < 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (y = 0; y < bltheight; y++) {
|
||||
for (x = 0; x < bltwidth; x++) {
|
||||
ROP_OP_TR(s, dstaddr, cirrus_src(s, srcaddr), transp);
|
||||
dstaddr++;
|
||||
srcaddr++;
|
||||
p = *dst;
|
||||
ROP_OP(&p, *src);
|
||||
if (p != s->vga.gr[0x34]) *dst = p;
|
||||
dst++;
|
||||
src++;
|
||||
}
|
||||
dstaddr += dstpitch;
|
||||
srcaddr += srcpitch;
|
||||
dst += dstpitch;
|
||||
src += srcpitch;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
glue(glue(cirrus_bitblt_rop_bkwd_transp_, ROP_NAME),_8)(CirrusVGAState *s,
|
||||
uint32_t dstaddr,
|
||||
uint32_t srcaddr,
|
||||
int dstpitch,
|
||||
int srcpitch,
|
||||
int bltwidth,
|
||||
int bltheight)
|
||||
uint8_t *dst,const uint8_t *src,
|
||||
int dstpitch,int srcpitch,
|
||||
int bltwidth,int bltheight)
|
||||
{
|
||||
int x,y;
|
||||
uint8_t transp = s->vga.gr[0x34];
|
||||
uint8_t p;
|
||||
dstpitch += bltwidth;
|
||||
srcpitch += bltwidth;
|
||||
for (y = 0; y < bltheight; y++) {
|
||||
for (x = 0; x < bltwidth; x++) {
|
||||
ROP_OP_TR(s, dstaddr, cirrus_src(s, srcaddr), transp);
|
||||
dstaddr--;
|
||||
srcaddr--;
|
||||
p = *dst;
|
||||
ROP_OP(&p, *src);
|
||||
if (p != s->vga.gr[0x34]) *dst = p;
|
||||
dst--;
|
||||
src--;
|
||||
}
|
||||
dstaddr += dstpitch;
|
||||
srcaddr += srcpitch;
|
||||
dst += dstpitch;
|
||||
src += srcpitch;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
glue(glue(cirrus_bitblt_rop_fwd_transp_, ROP_NAME),_16)(CirrusVGAState *s,
|
||||
uint32_t dstaddr,
|
||||
uint32_t srcaddr,
|
||||
int dstpitch,
|
||||
int srcpitch,
|
||||
int bltwidth,
|
||||
int bltheight)
|
||||
uint8_t *dst,const uint8_t *src,
|
||||
int dstpitch,int srcpitch,
|
||||
int bltwidth,int bltheight)
|
||||
{
|
||||
int x,y;
|
||||
uint16_t transp = s->vga.gr[0x34] | (uint16_t)s->vga.gr[0x35] << 8;
|
||||
uint8_t p1, p2;
|
||||
dstpitch -= bltwidth;
|
||||
srcpitch -= bltwidth;
|
||||
|
||||
if (bltheight > 1 && (dstpitch < 0 || srcpitch < 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (y = 0; y < bltheight; y++) {
|
||||
for (x = 0; x < bltwidth; x+=2) {
|
||||
ROP_OP_TR_16(s, dstaddr, cirrus_src16(s, srcaddr), transp);
|
||||
dstaddr += 2;
|
||||
srcaddr += 2;
|
||||
p1 = *dst;
|
||||
p2 = *(dst+1);
|
||||
ROP_OP(&p1, *src);
|
||||
ROP_OP(&p2, *(src + 1));
|
||||
if ((p1 != s->vga.gr[0x34]) || (p2 != s->vga.gr[0x35])) {
|
||||
*dst = p1;
|
||||
*(dst+1) = p2;
|
||||
}
|
||||
dstaddr += dstpitch;
|
||||
srcaddr += srcpitch;
|
||||
dst+=2;
|
||||
src+=2;
|
||||
}
|
||||
dst += dstpitch;
|
||||
src += srcpitch;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
glue(glue(cirrus_bitblt_rop_bkwd_transp_, ROP_NAME),_16)(CirrusVGAState *s,
|
||||
uint32_t dstaddr,
|
||||
uint32_t srcaddr,
|
||||
int dstpitch,
|
||||
int srcpitch,
|
||||
int bltwidth,
|
||||
int bltheight)
|
||||
uint8_t *dst,const uint8_t *src,
|
||||
int dstpitch,int srcpitch,
|
||||
int bltwidth,int bltheight)
|
||||
{
|
||||
int x,y;
|
||||
uint16_t transp = s->vga.gr[0x34] | (uint16_t)s->vga.gr[0x35] << 8;
|
||||
uint8_t p1, p2;
|
||||
dstpitch += bltwidth;
|
||||
srcpitch += bltwidth;
|
||||
for (y = 0; y < bltheight; y++) {
|
||||
for (x = 0; x < bltwidth; x+=2) {
|
||||
ROP_OP_TR_16(s, dstaddr - 1, cirrus_src16(s, srcaddr - 1), transp);
|
||||
dstaddr -= 2;
|
||||
srcaddr -= 2;
|
||||
p1 = *(dst-1);
|
||||
p2 = *dst;
|
||||
ROP_OP(&p1, *(src - 1));
|
||||
ROP_OP(&p2, *src);
|
||||
if ((p1 != s->vga.gr[0x34]) || (p2 != s->vga.gr[0x35])) {
|
||||
*(dst-1) = p1;
|
||||
*dst = p2;
|
||||
}
|
||||
dstaddr += dstpitch;
|
||||
srcaddr += srcpitch;
|
||||
dst-=2;
|
||||
src-=2;
|
||||
}
|
||||
dst += dstpitch;
|
||||
src += srcpitch;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -23,32 +23,30 @@
|
||||
*/
|
||||
|
||||
#if DEPTH == 8
|
||||
#define PUTPIXEL(s, a, c) ROP_OP(s, a, c)
|
||||
#define PUTPIXEL() ROP_OP(&d[0], col)
|
||||
#elif DEPTH == 16
|
||||
#define PUTPIXEL(s, a, c) ROP_OP_16(s, a, c)
|
||||
#define PUTPIXEL() ROP_OP_16((uint16_t *)&d[0], col)
|
||||
#elif DEPTH == 24
|
||||
#define PUTPIXEL(s, a, c) do { \
|
||||
ROP_OP(s, a, c); \
|
||||
ROP_OP(s, a + 1, (col >> 8)); \
|
||||
ROP_OP(s, a + 2, (col >> 16)); \
|
||||
} while (0)
|
||||
#define PUTPIXEL() ROP_OP(&d[0], col); \
|
||||
ROP_OP(&d[1], (col >> 8)); \
|
||||
ROP_OP(&d[2], (col >> 16))
|
||||
#elif DEPTH == 32
|
||||
#define PUTPIXEL(s, a, c) ROP_OP_32(s, a, c)
|
||||
#define PUTPIXEL() ROP_OP_32(((uint32_t *)&d[0]), col)
|
||||
#else
|
||||
#error unsupported DEPTH
|
||||
#endif
|
||||
|
||||
static void
|
||||
glue(glue(glue(cirrus_patternfill_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState *s, uint32_t dstaddr,
|
||||
uint32_t srcaddr,
|
||||
(CirrusVGAState * s, uint8_t * dst,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
int bltwidth, int bltheight)
|
||||
{
|
||||
uint32_t addr;
|
||||
uint8_t *d;
|
||||
int x, y, pattern_y, pattern_pitch, pattern_x;
|
||||
unsigned int col;
|
||||
uint32_t src1addr;
|
||||
const uint8_t *src1;
|
||||
#if DEPTH == 24
|
||||
int skipleft = s->vga.gr[0x2f] & 0x1f;
|
||||
#else
|
||||
@@ -65,44 +63,42 @@ glue(glue(glue(cirrus_patternfill_, ROP_NAME), _),DEPTH)
|
||||
pattern_y = s->cirrus_blt_srcaddr & 7;
|
||||
for(y = 0; y < bltheight; y++) {
|
||||
pattern_x = skipleft;
|
||||
addr = dstaddr + skipleft;
|
||||
src1addr = srcaddr + pattern_y * pattern_pitch;
|
||||
d = dst + skipleft;
|
||||
src1 = src + pattern_y * pattern_pitch;
|
||||
for (x = skipleft; x < bltwidth; x += (DEPTH / 8)) {
|
||||
#if DEPTH == 8
|
||||
col = cirrus_src(s, src1addr + pattern_x);
|
||||
col = src1[pattern_x];
|
||||
pattern_x = (pattern_x + 1) & 7;
|
||||
#elif DEPTH == 16
|
||||
col = cirrus_src16(s, src1addr + pattern_x);
|
||||
col = ((uint16_t *)(src1 + pattern_x))[0];
|
||||
pattern_x = (pattern_x + 2) & 15;
|
||||
#elif DEPTH == 24
|
||||
{
|
||||
uint32_t src2addr = src1addr + pattern_x * 3;
|
||||
col = cirrus_src(s, src2addr) |
|
||||
(cirrus_src(s, src2addr + 1) << 8) |
|
||||
(cirrus_src(s, src2addr + 2) << 16);
|
||||
const uint8_t *src2 = src1 + pattern_x * 3;
|
||||
col = src2[0] | (src2[1] << 8) | (src2[2] << 16);
|
||||
pattern_x = (pattern_x + 1) & 7;
|
||||
}
|
||||
#else
|
||||
col = cirrus_src32(s, src1addr + pattern_x);
|
||||
col = ((uint32_t *)(src1 + pattern_x))[0];
|
||||
pattern_x = (pattern_x + 4) & 31;
|
||||
#endif
|
||||
PUTPIXEL(s, addr, col);
|
||||
addr += (DEPTH / 8);
|
||||
PUTPIXEL();
|
||||
d += (DEPTH / 8);
|
||||
}
|
||||
pattern_y = (pattern_y + 1) & 7;
|
||||
dstaddr += dstpitch;
|
||||
dst += dstpitch;
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTE: srcpitch is ignored */
|
||||
static void
|
||||
glue(glue(glue(cirrus_colorexpand_transp_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState *s, uint32_t dstaddr,
|
||||
uint32_t srcaddr,
|
||||
(CirrusVGAState * s, uint8_t * dst,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
int bltwidth, int bltheight)
|
||||
{
|
||||
uint32_t addr;
|
||||
uint8_t *d;
|
||||
int x, y;
|
||||
unsigned bits, bits_xor;
|
||||
unsigned int col;
|
||||
@@ -126,33 +122,33 @@ glue(glue(glue(cirrus_colorexpand_transp_, ROP_NAME), _),DEPTH)
|
||||
|
||||
for(y = 0; y < bltheight; y++) {
|
||||
bitmask = 0x80 >> srcskipleft;
|
||||
bits = cirrus_src(s, srcaddr++) ^ bits_xor;
|
||||
addr = dstaddr + dstskipleft;
|
||||
bits = *src++ ^ bits_xor;
|
||||
d = dst + dstskipleft;
|
||||
for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
|
||||
if ((bitmask & 0xff) == 0) {
|
||||
bitmask = 0x80;
|
||||
bits = cirrus_src(s, srcaddr++) ^ bits_xor;
|
||||
bits = *src++ ^ bits_xor;
|
||||
}
|
||||
index = (bits & bitmask);
|
||||
if (index) {
|
||||
PUTPIXEL(s, addr, col);
|
||||
PUTPIXEL();
|
||||
}
|
||||
addr += (DEPTH / 8);
|
||||
d += (DEPTH / 8);
|
||||
bitmask >>= 1;
|
||||
}
|
||||
dstaddr += dstpitch;
|
||||
dst += dstpitch;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
glue(glue(glue(cirrus_colorexpand_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState *s, uint32_t dstaddr,
|
||||
uint32_t srcaddr,
|
||||
(CirrusVGAState * s, uint8_t * dst,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
int bltwidth, int bltheight)
|
||||
{
|
||||
uint32_t colors[2];
|
||||
uint32_t addr;
|
||||
uint8_t *d;
|
||||
int x, y;
|
||||
unsigned bits;
|
||||
unsigned int col;
|
||||
@@ -164,30 +160,30 @@ glue(glue(glue(cirrus_colorexpand_, ROP_NAME), _),DEPTH)
|
||||
colors[1] = s->cirrus_blt_fgcol;
|
||||
for(y = 0; y < bltheight; y++) {
|
||||
bitmask = 0x80 >> srcskipleft;
|
||||
bits = cirrus_src(s, srcaddr++);
|
||||
addr = dstaddr + dstskipleft;
|
||||
bits = *src++;
|
||||
d = dst + dstskipleft;
|
||||
for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
|
||||
if ((bitmask & 0xff) == 0) {
|
||||
bitmask = 0x80;
|
||||
bits = cirrus_src(s, srcaddr++);
|
||||
bits = *src++;
|
||||
}
|
||||
col = colors[!!(bits & bitmask)];
|
||||
PUTPIXEL(s, addr, col);
|
||||
addr += (DEPTH / 8);
|
||||
PUTPIXEL();
|
||||
d += (DEPTH / 8);
|
||||
bitmask >>= 1;
|
||||
}
|
||||
dstaddr += dstpitch;
|
||||
dst += dstpitch;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState *s, uint32_t dstaddr,
|
||||
uint32_t srcaddr,
|
||||
(CirrusVGAState * s, uint8_t * dst,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
int bltwidth, int bltheight)
|
||||
{
|
||||
uint32_t addr;
|
||||
uint8_t *d;
|
||||
int x, y, bitpos, pattern_y;
|
||||
unsigned int bits, bits_xor;
|
||||
unsigned int col;
|
||||
@@ -209,30 +205,30 @@ glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)
|
||||
pattern_y = s->cirrus_blt_srcaddr & 7;
|
||||
|
||||
for(y = 0; y < bltheight; y++) {
|
||||
bits = cirrus_src(s, srcaddr + pattern_y) ^ bits_xor;
|
||||
bits = src[pattern_y] ^ bits_xor;
|
||||
bitpos = 7 - srcskipleft;
|
||||
addr = dstaddr + dstskipleft;
|
||||
d = dst + dstskipleft;
|
||||
for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
|
||||
if ((bits >> bitpos) & 1) {
|
||||
PUTPIXEL(s, addr, col);
|
||||
PUTPIXEL();
|
||||
}
|
||||
addr += (DEPTH / 8);
|
||||
d += (DEPTH / 8);
|
||||
bitpos = (bitpos - 1) & 7;
|
||||
}
|
||||
pattern_y = (pattern_y + 1) & 7;
|
||||
dstaddr += dstpitch;
|
||||
dst += dstpitch;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
glue(glue(glue(cirrus_colorexpand_pattern_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState *s, uint32_t dstaddr,
|
||||
uint32_t srcaddr,
|
||||
(CirrusVGAState * s, uint8_t * dst,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
int bltwidth, int bltheight)
|
||||
{
|
||||
uint32_t colors[2];
|
||||
uint32_t addr;
|
||||
uint8_t *d;
|
||||
int x, y, bitpos, pattern_y;
|
||||
unsigned int bits;
|
||||
unsigned int col;
|
||||
@@ -244,39 +240,40 @@ glue(glue(glue(cirrus_colorexpand_pattern_, ROP_NAME), _),DEPTH)
|
||||
pattern_y = s->cirrus_blt_srcaddr & 7;
|
||||
|
||||
for(y = 0; y < bltheight; y++) {
|
||||
bits = cirrus_src(s, srcaddr + pattern_y);
|
||||
bits = src[pattern_y];
|
||||
bitpos = 7 - srcskipleft;
|
||||
addr = dstaddr + dstskipleft;
|
||||
d = dst + dstskipleft;
|
||||
for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
|
||||
col = colors[(bits >> bitpos) & 1];
|
||||
PUTPIXEL(s, addr, col);
|
||||
addr += (DEPTH / 8);
|
||||
PUTPIXEL();
|
||||
d += (DEPTH / 8);
|
||||
bitpos = (bitpos - 1) & 7;
|
||||
}
|
||||
pattern_y = (pattern_y + 1) & 7;
|
||||
dstaddr += dstpitch;
|
||||
dst += dstpitch;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
glue(glue(glue(cirrus_fill_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState *s,
|
||||
uint32_t dstaddr, int dst_pitch,
|
||||
uint8_t *dst, int dst_pitch,
|
||||
int width, int height)
|
||||
{
|
||||
uint32_t addr;
|
||||
uint8_t *d, *d1;
|
||||
uint32_t col;
|
||||
int x, y;
|
||||
|
||||
col = s->cirrus_blt_fgcol;
|
||||
|
||||
d1 = dst;
|
||||
for(y = 0; y < height; y++) {
|
||||
addr = dstaddr;
|
||||
d = d1;
|
||||
for(x = 0; x < width; x += (DEPTH / 8)) {
|
||||
PUTPIXEL(s, addr, col);
|
||||
addr += (DEPTH / 8);
|
||||
PUTPIXEL();
|
||||
d += (DEPTH / 8);
|
||||
}
|
||||
dstaddr += dst_pitch;
|
||||
d1 += dst_pitch;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -291,8 +291,11 @@ static void virgl_resource_attach_backing(VirtIOGPU *g,
|
||||
return;
|
||||
}
|
||||
|
||||
virgl_renderer_resource_attach_iov(att_rb.resource_id,
|
||||
ret = virgl_renderer_resource_attach_iov(att_rb.resource_id,
|
||||
res_iovs, att_rb.nr_entries);
|
||||
|
||||
if (ret != 0)
|
||||
virtio_gpu_cleanup_mapping_iov(res_iovs, att_rb.nr_entries);
|
||||
}
|
||||
|
||||
static void virgl_resource_detach_backing(VirtIOGPU *g,
|
||||
@@ -371,8 +374,12 @@ static void virgl_cmd_get_capset(VirtIOGPU *g,
|
||||
|
||||
virgl_renderer_get_cap_set(gc.capset_id, &max_ver,
|
||||
&max_size);
|
||||
resp = g_malloc(sizeof(*resp) + max_size);
|
||||
if (!max_size) {
|
||||
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
|
||||
return;
|
||||
}
|
||||
|
||||
resp = g_malloc(sizeof(*resp) + max_size);
|
||||
resp->hdr.type = VIRTIO_GPU_RESP_OK_CAPSET;
|
||||
virgl_renderer_fill_caps(gc.capset_id,
|
||||
gc.capset_version,
|
||||
|
@@ -28,6 +28,8 @@
|
||||
static struct virtio_gpu_simple_resource*
|
||||
virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id);
|
||||
|
||||
static void virtio_gpu_cleanup_mapping(struct virtio_gpu_simple_resource *res);
|
||||
|
||||
#ifdef CONFIG_VIRGL
|
||||
#include <virglrenderer.h>
|
||||
#define VIRGL(_g, _virgl, _simple, ...) \
|
||||
@@ -338,10 +340,14 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g,
|
||||
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
|
||||
return;
|
||||
}
|
||||
|
||||
res->hostmem = PIXMAN_FORMAT_BPP(pformat) * c2d.width * c2d.height;
|
||||
if (res->hostmem + g->hostmem < g->conf.max_hostmem) {
|
||||
res->image = pixman_image_create_bits(pformat,
|
||||
c2d.width,
|
||||
c2d.height,
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
if (!res->image) {
|
||||
qemu_log_mask(LOG_GUEST_ERROR,
|
||||
@@ -353,13 +359,16 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g,
|
||||
}
|
||||
|
||||
QTAILQ_INSERT_HEAD(&g->reslist, res, next);
|
||||
g->hostmem += res->hostmem;
|
||||
}
|
||||
|
||||
static void virtio_gpu_resource_destroy(VirtIOGPU *g,
|
||||
struct virtio_gpu_simple_resource *res)
|
||||
{
|
||||
pixman_image_unref(res->image);
|
||||
virtio_gpu_cleanup_mapping(res);
|
||||
QTAILQ_REMOVE(&g->reslist, res, next);
|
||||
g->hostmem -= res->hostmem;
|
||||
g_free(res);
|
||||
}
|
||||
|
||||
@@ -705,6 +714,11 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g,
|
||||
return;
|
||||
}
|
||||
|
||||
if (res->iov) {
|
||||
cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
|
||||
return;
|
||||
}
|
||||
|
||||
ret = virtio_gpu_create_mapping_iov(&ab, cmd, &res->addrs, &res->iov);
|
||||
if (ret != 0) {
|
||||
cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
|
||||
@@ -1241,6 +1255,8 @@ static const VMStateDescription vmstate_virtio_gpu = {
|
||||
|
||||
static Property virtio_gpu_properties[] = {
|
||||
DEFINE_PROP_UINT32("max_outputs", VirtIOGPU, conf.max_outputs, 1),
|
||||
DEFINE_PROP_SIZE("max_hostmem", VirtIOGPU, conf.max_hostmem,
|
||||
256 * 1024 * 1024),
|
||||
#ifdef CONFIG_VIRGL
|
||||
DEFINE_PROP_BIT("virgl", VirtIOGPU, conf.flags,
|
||||
VIRTIO_GPU_FLAG_VIRGL_ENABLED, true),
|
||||
|
@@ -260,9 +260,13 @@ static int i2c_slave_qdev_init(DeviceState *dev)
|
||||
I2CSlave *s = I2C_SLAVE(dev);
|
||||
I2CSlaveClass *sc = I2C_SLAVE_GET_CLASS(s);
|
||||
|
||||
if (sc->init) {
|
||||
return sc->init(s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr)
|
||||
{
|
||||
DeviceState *dev;
|
||||
|
@@ -29,7 +29,7 @@
|
||||
#include "hw/pci/pci.h"
|
||||
#include "qom/cpu.h"
|
||||
#include "hw/i386/pc.h"
|
||||
#include "target-i386/cpu.h"
|
||||
#include "target/i386/cpu.h"
|
||||
#include "hw/timer/hpet.h"
|
||||
#include "hw/acpi/acpi-defs.h"
|
||||
#include "hw/acpi/acpi.h"
|
||||
|
@@ -15,7 +15,7 @@
|
||||
#include "hw/i386/apic_internal.h"
|
||||
#include "hw/pci/msi.h"
|
||||
#include "sysemu/kvm.h"
|
||||
#include "target-i386/kvm_i386.h"
|
||||
#include "target/i386/kvm_i386.h"
|
||||
|
||||
static inline void kvm_apic_set_reg(struct kvm_lapic_state *kapic,
|
||||
int reg_id, uint32_t val)
|
||||
|
@@ -36,6 +36,13 @@ typedef struct KVMClockState {
|
||||
|
||||
uint64_t clock;
|
||||
bool clock_valid;
|
||||
|
||||
/* whether machine type supports reliable KVM_GET_CLOCK */
|
||||
bool mach_use_reliable_get_clock;
|
||||
|
||||
/* whether the 'clock' value was obtained in a host with
|
||||
* reliable KVM_GET_CLOCK */
|
||||
bool clock_is_reliable;
|
||||
} KVMClockState;
|
||||
|
||||
struct pvclock_vcpu_time_info {
|
||||
@@ -81,6 +88,60 @@ static uint64_t kvmclock_current_nsec(KVMClockState *s)
|
||||
return nsec + time.system_time;
|
||||
}
|
||||
|
||||
static void kvm_update_clock(KVMClockState *s)
|
||||
{
|
||||
struct kvm_clock_data data;
|
||||
int ret;
|
||||
|
||||
ret = kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, &data);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "KVM_GET_CLOCK failed: %s\n", strerror(ret));
|
||||
abort();
|
||||
}
|
||||
s->clock = data.clock;
|
||||
|
||||
/* If kvm_has_adjust_clock_stable() is false, KVM_GET_CLOCK returns
|
||||
* essentially CLOCK_MONOTONIC plus a guest-specific adjustment. This
|
||||
* can drift from the TSC-based value that is computed by the guest,
|
||||
* so we need to go through kvmclock_current_nsec(). If
|
||||
* kvm_has_adjust_clock_stable() is true, and the flags contain
|
||||
* KVM_CLOCK_TSC_STABLE, then KVM_GET_CLOCK returns a TSC-based value
|
||||
* and kvmclock_current_nsec() is not necessary.
|
||||
*
|
||||
* Here, however, we need not check KVM_CLOCK_TSC_STABLE. This is because:
|
||||
*
|
||||
* - if the host has disabled the kvmclock master clock, the guest already
|
||||
* has protection against time going backwards. This "safety net" is only
|
||||
* absent when kvmclock is stable;
|
||||
*
|
||||
* - therefore, we can replace a check like
|
||||
*
|
||||
* if last KVM_GET_CLOCK was not reliable then
|
||||
* read from memory
|
||||
*
|
||||
* with
|
||||
*
|
||||
* if last KVM_GET_CLOCK was not reliable && masterclock is enabled
|
||||
* read from memory
|
||||
*
|
||||
* However:
|
||||
*
|
||||
* - if kvm_has_adjust_clock_stable() returns false, the left side is
|
||||
* always true (KVM_GET_CLOCK is never reliable), and the right side is
|
||||
* unknown (because we don't have data.flags). We must assume it's true
|
||||
* and read from memory.
|
||||
*
|
||||
* - if kvm_has_adjust_clock_stable() returns true, the result of the &&
|
||||
* is always false (masterclock is enabled iff KVM_GET_CLOCK is reliable)
|
||||
*
|
||||
* So we can just use this instead:
|
||||
*
|
||||
* if !kvm_has_adjust_clock_stable() then
|
||||
* read from memory
|
||||
*/
|
||||
s->clock_is_reliable = kvm_has_adjust_clock_stable();
|
||||
}
|
||||
|
||||
static void kvmclock_vm_state_change(void *opaque, int running,
|
||||
RunState state)
|
||||
{
|
||||
@@ -91,15 +152,21 @@ static void kvmclock_vm_state_change(void *opaque, int running,
|
||||
|
||||
if (running) {
|
||||
struct kvm_clock_data data = {};
|
||||
uint64_t time_at_migration = kvmclock_current_nsec(s);
|
||||
|
||||
/*
|
||||
* If the host where s->clock was read did not support reliable
|
||||
* KVM_GET_CLOCK, read kvmclock value from memory.
|
||||
*/
|
||||
if (!s->clock_is_reliable) {
|
||||
uint64_t pvclock_via_mem = kvmclock_current_nsec(s);
|
||||
/* We can't rely on the saved clock value, just discard it */
|
||||
if (pvclock_via_mem) {
|
||||
s->clock = pvclock_via_mem;
|
||||
}
|
||||
}
|
||||
|
||||
s->clock_valid = false;
|
||||
|
||||
/* We can't rely on the migrated clock value, just discard it */
|
||||
if (time_at_migration) {
|
||||
s->clock = time_at_migration;
|
||||
}
|
||||
|
||||
data.clock = s->clock;
|
||||
ret = kvm_vm_ioctl(kvm_state, KVM_SET_CLOCK, &data);
|
||||
if (ret < 0) {
|
||||
@@ -120,8 +187,6 @@ static void kvmclock_vm_state_change(void *opaque, int running,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
struct kvm_clock_data data;
|
||||
int ret;
|
||||
|
||||
if (s->clock_valid) {
|
||||
return;
|
||||
@@ -129,13 +194,7 @@ static void kvmclock_vm_state_change(void *opaque, int running,
|
||||
|
||||
kvm_synchronize_all_tsc();
|
||||
|
||||
ret = kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, &data);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "KVM_GET_CLOCK failed: %s\n", strerror(ret));
|
||||
abort();
|
||||
}
|
||||
s->clock = data.clock;
|
||||
|
||||
kvm_update_clock(s);
|
||||
/*
|
||||
* If the VM is stopped, declare the clock state valid to
|
||||
* avoid re-reading it on next vmsave (which would return
|
||||
@@ -149,25 +208,78 @@ static void kvmclock_realize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
KVMClockState *s = KVM_CLOCK(dev);
|
||||
|
||||
kvm_update_clock(s);
|
||||
|
||||
qemu_add_vm_change_state_handler(kvmclock_vm_state_change, s);
|
||||
}
|
||||
|
||||
static bool kvmclock_clock_is_reliable_needed(void *opaque)
|
||||
{
|
||||
KVMClockState *s = opaque;
|
||||
|
||||
return s->mach_use_reliable_get_clock;
|
||||
}
|
||||
|
||||
static const VMStateDescription kvmclock_reliable_get_clock = {
|
||||
.name = "kvmclock/clock_is_reliable",
|
||||
.version_id = 1,
|
||||
.minimum_version_id = 1,
|
||||
.needed = kvmclock_clock_is_reliable_needed,
|
||||
.fields = (VMStateField[]) {
|
||||
VMSTATE_BOOL(clock_is_reliable, KVMClockState),
|
||||
VMSTATE_END_OF_LIST()
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* When migrating, read the clock just before migration,
|
||||
* so that the guest clock counts during the events
|
||||
* between:
|
||||
*
|
||||
* * vm_stop()
|
||||
* *
|
||||
* * pre_save()
|
||||
*
|
||||
* This reduces kvmclock difference on migration from 5s
|
||||
* to 0.1s (when max_downtime == 5s), because sending the
|
||||
* final pages of memory (which happens between vm_stop()
|
||||
* and pre_save()) takes max_downtime.
|
||||
*/
|
||||
static void kvmclock_pre_save(void *opaque)
|
||||
{
|
||||
KVMClockState *s = opaque;
|
||||
|
||||
kvm_update_clock(s);
|
||||
}
|
||||
|
||||
static const VMStateDescription kvmclock_vmsd = {
|
||||
.name = "kvmclock",
|
||||
.version_id = 1,
|
||||
.minimum_version_id = 1,
|
||||
.pre_save = kvmclock_pre_save,
|
||||
.fields = (VMStateField[]) {
|
||||
VMSTATE_UINT64(clock, KVMClockState),
|
||||
VMSTATE_END_OF_LIST()
|
||||
},
|
||||
.subsections = (const VMStateDescription * []) {
|
||||
&kvmclock_reliable_get_clock,
|
||||
NULL
|
||||
}
|
||||
};
|
||||
|
||||
static Property kvmclock_properties[] = {
|
||||
DEFINE_PROP_BOOL("x-mach-use-reliable-get-clock", KVMClockState,
|
||||
mach_use_reliable_get_clock, true),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
};
|
||||
|
||||
static void kvmclock_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||
|
||||
dc->realize = kvmclock_realize;
|
||||
dc->vmsd = &kvmclock_vmsd;
|
||||
dc->props = kvmclock_properties;
|
||||
}
|
||||
|
||||
static const TypeInfo kvmclock_info = {
|
||||
|
@@ -109,7 +109,7 @@ static uint32_t mb_add_cmdline(MultibootState *s, const char *cmdline)
|
||||
hwaddr p = s->offset_cmdlines;
|
||||
char *b = (char *)s->mb_buf + p;
|
||||
|
||||
get_opt_value(b, strlen(cmdline) + 1, cmdline);
|
||||
memcpy(b, cmdline, strlen(cmdline) + 1);
|
||||
s->offset_cmdlines += strlen(b) + 1;
|
||||
return s->mb_buf_phys + p;
|
||||
}
|
||||
@@ -287,7 +287,8 @@ int load_multiboot(FWCfgState *fw_cfg,
|
||||
mbs.offset_bootloader = mbs.offset_cmdlines + cmdline_len;
|
||||
|
||||
if (initrd_filename) {
|
||||
char *next_initrd, not_last;
|
||||
const char *next_initrd;
|
||||
char not_last, tmpbuf[strlen(initrd_filename) + 1];
|
||||
|
||||
mbs.offset_mods = mbs.mb_buf_size;
|
||||
|
||||
@@ -296,25 +297,24 @@ int load_multiboot(FWCfgState *fw_cfg,
|
||||
int mb_mod_length;
|
||||
uint32_t offs = mbs.mb_buf_size;
|
||||
|
||||
next_initrd = (char *)get_opt_value(NULL, 0, initrd_filename);
|
||||
next_initrd = get_opt_value(tmpbuf, sizeof(tmpbuf), initrd_filename);
|
||||
not_last = *next_initrd;
|
||||
*next_initrd = '\0';
|
||||
/* if a space comes after the module filename, treat everything
|
||||
after that as parameters */
|
||||
hwaddr c = mb_add_cmdline(&mbs, initrd_filename);
|
||||
if ((next_space = strchr(initrd_filename, ' ')))
|
||||
hwaddr c = mb_add_cmdline(&mbs, tmpbuf);
|
||||
if ((next_space = strchr(tmpbuf, ' ')))
|
||||
*next_space = '\0';
|
||||
mb_debug("multiboot loading module: %s\n", initrd_filename);
|
||||
mb_mod_length = get_image_size(initrd_filename);
|
||||
mb_debug("multiboot loading module: %s\n", tmpbuf);
|
||||
mb_mod_length = get_image_size(tmpbuf);
|
||||
if (mb_mod_length < 0) {
|
||||
fprintf(stderr, "Failed to open file '%s'\n", initrd_filename);
|
||||
fprintf(stderr, "Failed to open file '%s'\n", tmpbuf);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mbs.mb_buf_size = TARGET_PAGE_ALIGN(mb_mod_length + mbs.mb_buf_size);
|
||||
mbs.mb_buf = g_realloc(mbs.mb_buf, mbs.mb_buf_size);
|
||||
|
||||
load_image(initrd_filename, (unsigned char *)mbs.mb_buf + offs);
|
||||
load_image(tmpbuf, (unsigned char *)mbs.mb_buf + offs);
|
||||
mb_add_mod(&mbs, mbs.mb_buf_phys + offs,
|
||||
mbs.mb_buf_phys + offs + mb_mod_length, c);
|
||||
|
||||
|
68
hw/i386/pc.c
68
hw/i386/pc.c
@@ -400,12 +400,12 @@ static void pc_cmos_init_late(void *opaque)
|
||||
int i, trans;
|
||||
|
||||
val = 0;
|
||||
if (ide_get_geometry(arg->idebus[0], 0,
|
||||
if (arg->idebus[0] && ide_get_geometry(arg->idebus[0], 0,
|
||||
&cylinders, &heads, §ors) >= 0) {
|
||||
cmos_init_hd(s, 0x19, 0x1b, cylinders, heads, sectors);
|
||||
val |= 0xf0;
|
||||
}
|
||||
if (ide_get_geometry(arg->idebus[0], 1,
|
||||
if (arg->idebus[0] && ide_get_geometry(arg->idebus[0], 1,
|
||||
&cylinders, &heads, §ors) >= 0) {
|
||||
cmos_init_hd(s, 0x1a, 0x24, cylinders, heads, sectors);
|
||||
val |= 0x0f;
|
||||
@@ -418,7 +418,8 @@ static void pc_cmos_init_late(void *opaque)
|
||||
geometry. It is always such that: 1 <= sects <= 63, 1
|
||||
<= heads <= 16, 1 <= cylinders <= 16383. The BIOS
|
||||
geometry can be different if a translation is done. */
|
||||
if (ide_get_geometry(arg->idebus[i / 2], i % 2,
|
||||
if (arg->idebus[i / 2] &&
|
||||
ide_get_geometry(arg->idebus[i / 2], i % 2,
|
||||
&cylinders, &heads, §ors) >= 0) {
|
||||
trans = ide_get_bios_chs_trans(arg->idebus[i / 2], i % 2) - 1;
|
||||
assert((trans & ~3) == 0);
|
||||
@@ -1535,6 +1536,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
|
||||
ISADevice **rtc_state,
|
||||
bool create_fdctrl,
|
||||
bool no_vmport,
|
||||
bool has_pit,
|
||||
uint32_t hpet_irqs)
|
||||
{
|
||||
int i;
|
||||
@@ -1588,7 +1590,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
|
||||
|
||||
qemu_register_boot_set(pc_boot_set, *rtc_state);
|
||||
|
||||
if (!xen_enabled()) {
|
||||
if (!xen_enabled() && has_pit) {
|
||||
if (kvm_pit_in_kernel()) {
|
||||
pit = kvm_pit_init(isa_bus, 0x40);
|
||||
} else {
|
||||
@@ -1818,10 +1820,8 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
|
||||
|
||||
/* increment the number of CPUs */
|
||||
pcms->boot_cpus++;
|
||||
if (pcms->rtc) {
|
||||
if (dev->hotplugged) {
|
||||
rtc_set_cpus_count(pcms->rtc, pcms->boot_cpus);
|
||||
}
|
||||
if (pcms->fw_cfg) {
|
||||
fw_cfg_modify_i16(pcms->fw_cfg, FW_CFG_NB_CPUS, pcms->boot_cpus);
|
||||
}
|
||||
|
||||
@@ -2160,6 +2160,48 @@ static void pc_machine_set_nvdimm(Object *obj, bool value, Error **errp)
|
||||
pcms->acpi_nvdimm_state.is_enabled = value;
|
||||
}
|
||||
|
||||
static bool pc_machine_get_smbus(Object *obj, Error **errp)
|
||||
{
|
||||
PCMachineState *pcms = PC_MACHINE(obj);
|
||||
|
||||
return pcms->smbus;
|
||||
}
|
||||
|
||||
static void pc_machine_set_smbus(Object *obj, bool value, Error **errp)
|
||||
{
|
||||
PCMachineState *pcms = PC_MACHINE(obj);
|
||||
|
||||
pcms->smbus = value;
|
||||
}
|
||||
|
||||
static bool pc_machine_get_sata(Object *obj, Error **errp)
|
||||
{
|
||||
PCMachineState *pcms = PC_MACHINE(obj);
|
||||
|
||||
return pcms->sata;
|
||||
}
|
||||
|
||||
static void pc_machine_set_sata(Object *obj, bool value, Error **errp)
|
||||
{
|
||||
PCMachineState *pcms = PC_MACHINE(obj);
|
||||
|
||||
pcms->sata = value;
|
||||
}
|
||||
|
||||
static bool pc_machine_get_pit(Object *obj, Error **errp)
|
||||
{
|
||||
PCMachineState *pcms = PC_MACHINE(obj);
|
||||
|
||||
return pcms->pit;
|
||||
}
|
||||
|
||||
static void pc_machine_set_pit(Object *obj, bool value, Error **errp)
|
||||
{
|
||||
PCMachineState *pcms = PC_MACHINE(obj);
|
||||
|
||||
pcms->pit = value;
|
||||
}
|
||||
|
||||
static void pc_machine_initfn(Object *obj)
|
||||
{
|
||||
PCMachineState *pcms = PC_MACHINE(obj);
|
||||
@@ -2171,6 +2213,9 @@ static void pc_machine_initfn(Object *obj)
|
||||
pcms->acpi_nvdimm_state.is_enabled = false;
|
||||
/* acpi build is enabled by default if machine supports it */
|
||||
pcms->acpi_build_enabled = PC_MACHINE_GET_CLASS(pcms)->has_acpi_build;
|
||||
pcms->smbus = true;
|
||||
pcms->sata = true;
|
||||
pcms->pit = true;
|
||||
}
|
||||
|
||||
static void pc_machine_reset(void)
|
||||
@@ -2331,6 +2376,15 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
|
||||
|
||||
object_class_property_add_bool(oc, PC_MACHINE_NVDIMM,
|
||||
pc_machine_get_nvdimm, pc_machine_set_nvdimm, &error_abort);
|
||||
|
||||
object_class_property_add_bool(oc, PC_MACHINE_SMBUS,
|
||||
pc_machine_get_smbus, pc_machine_set_smbus, &error_abort);
|
||||
|
||||
object_class_property_add_bool(oc, PC_MACHINE_SATA,
|
||||
pc_machine_get_sata, pc_machine_set_sata, &error_abort);
|
||||
|
||||
object_class_property_add_bool(oc, PC_MACHINE_PIT,
|
||||
pc_machine_get_pit, pc_machine_set_pit, &error_abort);
|
||||
}
|
||||
|
||||
static const TypeInfo pc_machine_info = {
|
||||
|
@@ -235,7 +235,7 @@ static void pc_init1(MachineState *machine,
|
||||
|
||||
/* init basic PC hardware */
|
||||
pc_basic_device_init(isa_bus, pcms->gsi, &rtc_state, true,
|
||||
(pcms->vmport != ON_OFF_AUTO_ON), 0x4);
|
||||
(pcms->vmport != ON_OFF_AUTO_ON), pcms->pit, 0x4);
|
||||
|
||||
pc_nic_init(isa_bus, pci_bus);
|
||||
|
||||
|
@@ -227,11 +227,13 @@ static void pc_q35_init(MachineState *machine)
|
||||
|
||||
/* init basic PC hardware */
|
||||
pc_basic_device_init(isa_bus, pcms->gsi, &rtc_state, !mc->no_floppy,
|
||||
(pcms->vmport != ON_OFF_AUTO_ON), 0xff0104);
|
||||
(pcms->vmport != ON_OFF_AUTO_ON), pcms->pit,
|
||||
0xff0104);
|
||||
|
||||
/* connect pm stuff to lpc */
|
||||
ich9_lpc_pm_init(lpc, pc_machine_is_smm_enabled(pcms));
|
||||
|
||||
if (pcms->sata) {
|
||||
/* ahci and SATA device, for q35 1 ahci controller is built-in */
|
||||
ahci = pci_create_simple_multifunction(host_bus,
|
||||
PCI_DEVFN(ICH9_SATA1_DEV,
|
||||
@@ -242,17 +244,22 @@ static void pc_q35_init(MachineState *machine)
|
||||
g_assert(MAX_SATA_PORTS == ICH_AHCI(ahci)->ahci.ports);
|
||||
ide_drive_get(hd, ICH_AHCI(ahci)->ahci.ports);
|
||||
ahci_ide_create_devs(ahci, hd);
|
||||
} else {
|
||||
idebus[0] = idebus[1] = NULL;
|
||||
}
|
||||
|
||||
if (machine_usb(machine)) {
|
||||
/* Should we create 6 UHCI according to ich9 spec? */
|
||||
ehci_create_ich9_with_companions(host_bus, 0x1d);
|
||||
}
|
||||
|
||||
if (pcms->smbus) {
|
||||
/* TODO: Populate SPD eeprom data. */
|
||||
smbus_eeprom_init(ich9_smb_init(host_bus,
|
||||
PCI_DEVFN(ICH9_SMB_DEV, ICH9_SMB_FUNC),
|
||||
0xb100),
|
||||
8, NULL, 0);
|
||||
}
|
||||
|
||||
pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
|
||||
|
||||
|
@@ -488,7 +488,7 @@ static void ahci_reg_init(AHCIState *s)
|
||||
s->control_regs.cap = (s->ports - 1) |
|
||||
(AHCI_NUM_COMMAND_SLOTS << 8) |
|
||||
(AHCI_SUPPORTED_SPEED_GEN1 << AHCI_SUPPORTED_SPEED) |
|
||||
HOST_CAP_NCQ | HOST_CAP_AHCI | HOST_CAP_64;
|
||||
HOST_CAP_NCQ | HOST_CAP_AHCI;
|
||||
|
||||
s->control_regs.impl = (1 << s->ports) - 1;
|
||||
|
||||
|
@@ -252,6 +252,9 @@ static const uint16_t qcode_to_keycode_set1[Q_KEY_CODE__MAX] = {
|
||||
[Q_KEY_CODE_ASTERISK] = 0x37,
|
||||
[Q_KEY_CODE_LESS] = 0x56,
|
||||
[Q_KEY_CODE_RO] = 0x73,
|
||||
[Q_KEY_CODE_HIRAGANA] = 0x70,
|
||||
[Q_KEY_CODE_HENKAN] = 0x79,
|
||||
[Q_KEY_CODE_YEN] = 0x7d,
|
||||
[Q_KEY_CODE_KP_COMMA] = 0x7e,
|
||||
};
|
||||
|
||||
@@ -394,6 +397,9 @@ static const uint16_t qcode_to_keycode_set2[Q_KEY_CODE__MAX] = {
|
||||
[Q_KEY_CODE_LESS] = 0x61,
|
||||
[Q_KEY_CODE_SYSRQ] = 0x7f,
|
||||
[Q_KEY_CODE_RO] = 0x51,
|
||||
[Q_KEY_CODE_HIRAGANA] = 0x13,
|
||||
[Q_KEY_CODE_HENKAN] = 0x64,
|
||||
[Q_KEY_CODE_YEN] = 0x6a,
|
||||
[Q_KEY_CODE_KP_COMMA] = 0x6d,
|
||||
};
|
||||
|
||||
@@ -504,6 +510,10 @@ static const uint16_t qcode_to_keycode_set3[Q_KEY_CODE__MAX] = {
|
||||
[Q_KEY_CODE_COMMA] = 0x41,
|
||||
[Q_KEY_CODE_DOT] = 0x49,
|
||||
[Q_KEY_CODE_SLASH] = 0x4a,
|
||||
|
||||
[Q_KEY_CODE_HIRAGANA] = 0x87,
|
||||
[Q_KEY_CODE_HENKAN] = 0x86,
|
||||
[Q_KEY_CODE_YEN] = 0x5d,
|
||||
};
|
||||
|
||||
static uint8_t translate_table[256] = {
|
||||
|
@@ -250,8 +250,6 @@ static void apic_reset_common(DeviceState *dev)
|
||||
s->apicbase = APIC_DEFAULT_ADDRESS | bsp | MSR_IA32_APICBASE_ENABLE;
|
||||
s->id = s->initial_apic_id;
|
||||
|
||||
apic_reset_irq_delivered();
|
||||
|
||||
s->vapic_paddr = 0;
|
||||
info->vapic_base_update(s);
|
||||
|
||||
|
@@ -54,6 +54,7 @@ static uint32_t gicd_int_pending(GICv3State *s, int irq)
|
||||
* + the PENDING latch is set OR it is level triggered and the input is 1
|
||||
* + its ENABLE bit is set
|
||||
* + the GICD enable bit for its group is set
|
||||
* + its ACTIVE bit is not set (otherwise it would be Active+Pending)
|
||||
* Conveniently we can bulk-calculate this with bitwise operations.
|
||||
*/
|
||||
uint32_t pend, grpmask;
|
||||
@@ -63,9 +64,11 @@ static uint32_t gicd_int_pending(GICv3State *s, int irq)
|
||||
uint32_t group = *gic_bmp_ptr32(s->group, irq);
|
||||
uint32_t grpmod = *gic_bmp_ptr32(s->grpmod, irq);
|
||||
uint32_t enable = *gic_bmp_ptr32(s->enabled, irq);
|
||||
uint32_t active = *gic_bmp_ptr32(s->active, irq);
|
||||
|
||||
pend = pending | (~edge_trigger & level);
|
||||
pend &= enable;
|
||||
pend &= ~active;
|
||||
|
||||
if (s->gicd_ctlr & GICD_CTLR_DS) {
|
||||
grpmod = 0;
|
||||
@@ -96,12 +99,14 @@ static uint32_t gicr_int_pending(GICv3CPUState *cs)
|
||||
* + the PENDING latch is set OR it is level triggered and the input is 1
|
||||
* + its ENABLE bit is set
|
||||
* + the GICD enable bit for its group is set
|
||||
* + its ACTIVE bit is not set (otherwise it would be Active+Pending)
|
||||
* Conveniently we can bulk-calculate this with bitwise operations.
|
||||
*/
|
||||
uint32_t pend, grpmask, grpmod;
|
||||
|
||||
pend = cs->gicr_ipendr0 | (~cs->edge_trigger & cs->level);
|
||||
pend &= cs->gicr_ienabler0;
|
||||
pend &= ~cs->gicr_iactiver0;
|
||||
|
||||
if (cs->gic->gicd_ctlr & GICD_CTLR_DS) {
|
||||
grpmod = 0;
|
||||
|
@@ -204,7 +204,8 @@ static void arm_gicv3_common_realize(DeviceState *dev, Error **errp)
|
||||
/* The CPU mp-affinity property is in MPIDR register format; squash
|
||||
* the affinity bytes into 32 bits as the GICR_TYPER has them.
|
||||
*/
|
||||
cpu_affid = (cpu_affid & 0xFF00000000ULL >> 8) | (cpu_affid & 0xFFFFFF);
|
||||
cpu_affid = ((cpu_affid & 0xFF00000000ULL) >> 8) |
|
||||
(cpu_affid & 0xFFFFFF);
|
||||
s->cpu[i].gicr_typer = (cpu_affid << 32) |
|
||||
(1 << 24) |
|
||||
(i << 8) |
|
||||
|
@@ -1118,35 +1118,35 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
|
||||
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 3,
|
||||
.type = ARM_CP_IO | ARM_CP_NO_RAW,
|
||||
.access = PL1_RW, .accessfn = gicv3_fiq_access,
|
||||
.fieldoffset = offsetof(GICv3CPUState, icc_bpr[GICV3_G0]),
|
||||
.readfn = icc_bpr_read,
|
||||
.writefn = icc_bpr_write,
|
||||
},
|
||||
{ .name = "ICC_AP0R0_EL1", .state = ARM_CP_STATE_BOTH,
|
||||
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 4,
|
||||
.type = ARM_CP_IO | ARM_CP_NO_RAW,
|
||||
.access = PL1_RW, .accessfn = gicv3_fiq_access,
|
||||
.fieldoffset = offsetof(GICv3CPUState, icc_apr[GICV3_G0][0]),
|
||||
.readfn = icc_ap_read,
|
||||
.writefn = icc_ap_write,
|
||||
},
|
||||
{ .name = "ICC_AP0R1_EL1", .state = ARM_CP_STATE_BOTH,
|
||||
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 5,
|
||||
.type = ARM_CP_IO | ARM_CP_NO_RAW,
|
||||
.access = PL1_RW, .accessfn = gicv3_fiq_access,
|
||||
.fieldoffset = offsetof(GICv3CPUState, icc_apr[GICV3_G0][1]),
|
||||
.readfn = icc_ap_read,
|
||||
.writefn = icc_ap_write,
|
||||
},
|
||||
{ .name = "ICC_AP0R2_EL1", .state = ARM_CP_STATE_BOTH,
|
||||
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 6,
|
||||
.type = ARM_CP_IO | ARM_CP_NO_RAW,
|
||||
.access = PL1_RW, .accessfn = gicv3_fiq_access,
|
||||
.fieldoffset = offsetof(GICv3CPUState, icc_apr[GICV3_G0][2]),
|
||||
.readfn = icc_ap_read,
|
||||
.writefn = icc_ap_write,
|
||||
},
|
||||
{ .name = "ICC_AP0R3_EL1", .state = ARM_CP_STATE_BOTH,
|
||||
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 7,
|
||||
.type = ARM_CP_IO | ARM_CP_NO_RAW,
|
||||
.access = PL1_RW, .accessfn = gicv3_fiq_access,
|
||||
.fieldoffset = offsetof(GICv3CPUState, icc_apr[GICV3_G0][3]),
|
||||
.readfn = icc_ap_read,
|
||||
.writefn = icc_ap_write,
|
||||
},
|
||||
/* All the ICC_AP1R*_EL1 registers are banked */
|
||||
@@ -1275,7 +1275,7 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
|
||||
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 6,
|
||||
.type = ARM_CP_IO | ARM_CP_NO_RAW,
|
||||
.access = PL1_RW, .accessfn = gicv3_fiq_access,
|
||||
.fieldoffset = offsetof(GICv3CPUState, icc_igrpen[GICV3_G0]),
|
||||
.readfn = icc_igrpen_read,
|
||||
.writefn = icc_igrpen_write,
|
||||
},
|
||||
/* This register is banked */
|
||||
@@ -1299,7 +1299,6 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
|
||||
.opc0 = 3, .opc1 = 6, .crn = 12, .crm = 12, .opc2 = 4,
|
||||
.type = ARM_CP_IO | ARM_CP_NO_RAW,
|
||||
.access = PL3_RW,
|
||||
.fieldoffset = offsetof(GICv3CPUState, icc_ctlr_el3),
|
||||
.readfn = icc_ctlr_el3_read,
|
||||
.writefn = icc_ctlr_el3_write,
|
||||
},
|
||||
|
@@ -30,7 +30,7 @@
|
||||
#include "hw/i386/ioapic_internal.h"
|
||||
#include "include/hw/pci/msi.h"
|
||||
#include "sysemu/kvm.h"
|
||||
#include "target-i386/cpu.h"
|
||||
#include "target/i386/cpu.h"
|
||||
#include "hw/i386/apic-msidef.h"
|
||||
#include "hw/i386/x86-iommu.h"
|
||||
|
||||
@@ -426,11 +426,6 @@ static void ioapic_class_init(ObjectClass *klass, void *data)
|
||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||
|
||||
k->realize = ioapic_realize;
|
||||
/*
|
||||
* If APIC is in kernel, we need to update the kernel cache after
|
||||
* migration, otherwise first 24 gsi routes will be invalid.
|
||||
*/
|
||||
k->post_load = ioapic_update_kvm_routes;
|
||||
dc->reset = ioapic_reset_common;
|
||||
dc->props = ioapic_properties;
|
||||
}
|
||||
|
@@ -86,7 +86,7 @@
|
||||
#define BMC_DEV_ID TO_REG(0x1A4)
|
||||
|
||||
#define PROT_KEY_UNLOCK 0x1688A8A8
|
||||
#define SCU_IO_REGION_SIZE 0x20000
|
||||
#define SCU_IO_REGION_SIZE 0x1000
|
||||
|
||||
static const uint32_t ast2400_a0_resets[ASPEED_SCU_NR_REGS] = {
|
||||
[SYS_RST_CTRL] = 0xFFCFFEDCU,
|
||||
@@ -231,6 +231,7 @@ static void aspeed_scu_reset(DeviceState *dev)
|
||||
|
||||
switch (s->silicon_rev) {
|
||||
case AST2400_A0_SILICON_REV:
|
||||
case AST2400_A1_SILICON_REV:
|
||||
reset = ast2400_a0_resets;
|
||||
break;
|
||||
case AST2500_A0_SILICON_REV:
|
||||
@@ -249,6 +250,7 @@ static void aspeed_scu_reset(DeviceState *dev)
|
||||
|
||||
static uint32_t aspeed_silicon_revs[] = {
|
||||
AST2400_A0_SILICON_REV,
|
||||
AST2400_A1_SILICON_REV,
|
||||
AST2500_A0_SILICON_REV,
|
||||
AST2500_A1_SILICON_REV,
|
||||
};
|
||||
|
@@ -119,6 +119,7 @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data,
|
||||
/* Make sure readonly bits are kept */
|
||||
switch (s->silicon_rev) {
|
||||
case AST2400_A0_SILICON_REV:
|
||||
case AST2400_A1_SILICON_REV:
|
||||
data &= ~ASPEED_SDMC_READONLY_MASK;
|
||||
break;
|
||||
case AST2500_A0_SILICON_REV:
|
||||
@@ -193,6 +194,7 @@ static void aspeed_sdmc_reset(DeviceState *dev)
|
||||
/* Set ram size bit and defaults values */
|
||||
switch (s->silicon_rev) {
|
||||
case AST2400_A0_SILICON_REV:
|
||||
case AST2400_A1_SILICON_REV:
|
||||
s->regs[R_CONF] |=
|
||||
ASPEED_SDMC_VGA_COMPAT |
|
||||
ASPEED_SDMC_DRAM_SIZE(s->ram_bits);
|
||||
@@ -224,6 +226,7 @@ static void aspeed_sdmc_realize(DeviceState *dev, Error **errp)
|
||||
|
||||
switch (s->silicon_rev) {
|
||||
case AST2400_A0_SILICON_REV:
|
||||
case AST2400_A1_SILICON_REV:
|
||||
s->ram_bits = ast2400_rambits(s);
|
||||
break;
|
||||
case AST2500_A0_SILICON_REV:
|
||||
|
@@ -17,7 +17,7 @@
|
||||
#include "hw/qdev.h"
|
||||
#include "hw/isa/isa.h"
|
||||
#include "sysemu/kvm.h"
|
||||
#include "target-i386/hyperv.h"
|
||||
#include "target/i386/hyperv.h"
|
||||
#include "kvm_i386.h"
|
||||
|
||||
#define HV_TEST_DEV_MAX_SINT_ROUTES 64
|
||||
|
@@ -306,7 +306,7 @@ e1000e_init_msix(E1000EState *s)
|
||||
static void
|
||||
e1000e_cleanup_msix(E1000EState *s)
|
||||
{
|
||||
if (msix_present(PCI_DEVICE(s))) {
|
||||
if (msix_enabled(PCI_DEVICE(s))) {
|
||||
e1000e_unuse_msix_vectors(s, E1000E_MSIX_VEC_NUM);
|
||||
msix_uninit(PCI_DEVICE(s), &s->msix, &s->msix);
|
||||
}
|
||||
|
@@ -23,13 +23,13 @@
|
||||
|
||||
struct NetRxPkt {
|
||||
struct virtio_net_hdr virt_hdr;
|
||||
uint8_t ehdr_buf[sizeof(struct eth_header) + sizeof(struct vlan_header)];
|
||||
uint8_t ehdr_buf[sizeof(struct eth_header)];
|
||||
struct iovec *vec;
|
||||
uint16_t vec_len_total;
|
||||
uint16_t vec_len;
|
||||
uint32_t tot_len;
|
||||
uint16_t tci;
|
||||
size_t ehdr_buf_len;
|
||||
bool vlan_stripped;
|
||||
bool has_virt_hdr;
|
||||
eth_pkt_types_e packet_type;
|
||||
|
||||
@@ -88,16 +88,17 @@ net_rx_pkt_pull_data(struct NetRxPkt *pkt,
|
||||
const struct iovec *iov, int iovcnt,
|
||||
size_t ploff)
|
||||
{
|
||||
if (pkt->ehdr_buf_len) {
|
||||
if (pkt->vlan_stripped) {
|
||||
net_rx_pkt_iovec_realloc(pkt, iovcnt + 1);
|
||||
|
||||
pkt->vec[0].iov_base = pkt->ehdr_buf;
|
||||
pkt->vec[0].iov_len = pkt->ehdr_buf_len;
|
||||
pkt->vec[0].iov_len = sizeof(pkt->ehdr_buf);
|
||||
|
||||
pkt->tot_len =
|
||||
iov_size(iov, iovcnt) - ploff + sizeof(struct eth_header);
|
||||
|
||||
pkt->tot_len = iov_size(iov, iovcnt) - ploff + pkt->ehdr_buf_len;
|
||||
pkt->vec_len = iov_copy(pkt->vec + 1, pkt->vec_len_total - 1,
|
||||
iov, iovcnt, ploff,
|
||||
pkt->tot_len - pkt->ehdr_buf_len) + 1;
|
||||
iov, iovcnt, ploff, pkt->tot_len);
|
||||
} else {
|
||||
net_rx_pkt_iovec_realloc(pkt, iovcnt);
|
||||
|
||||
@@ -122,12 +123,11 @@ void net_rx_pkt_attach_iovec(struct NetRxPkt *pkt,
|
||||
uint16_t tci = 0;
|
||||
uint16_t ploff = iovoff;
|
||||
assert(pkt);
|
||||
pkt->vlan_stripped = false;
|
||||
|
||||
if (strip_vlan) {
|
||||
pkt->ehdr_buf_len = eth_strip_vlan(iov, iovcnt, iovoff, pkt->ehdr_buf,
|
||||
pkt->vlan_stripped = eth_strip_vlan(iov, iovcnt, iovoff, pkt->ehdr_buf,
|
||||
&ploff, &tci);
|
||||
} else {
|
||||
pkt->ehdr_buf_len = 0;
|
||||
}
|
||||
|
||||
pkt->tci = tci;
|
||||
@@ -143,13 +143,12 @@ void net_rx_pkt_attach_iovec_ex(struct NetRxPkt *pkt,
|
||||
uint16_t tci = 0;
|
||||
uint16_t ploff = iovoff;
|
||||
assert(pkt);
|
||||
pkt->vlan_stripped = false;
|
||||
|
||||
if (strip_vlan) {
|
||||
pkt->ehdr_buf_len = eth_strip_vlan_ex(iov, iovcnt, iovoff, vet,
|
||||
pkt->vlan_stripped = eth_strip_vlan_ex(iov, iovcnt, iovoff, vet,
|
||||
pkt->ehdr_buf,
|
||||
&ploff, &tci);
|
||||
} else {
|
||||
pkt->ehdr_buf_len = 0;
|
||||
}
|
||||
|
||||
pkt->tci = tci;
|
||||
@@ -163,8 +162,8 @@ void net_rx_pkt_dump(struct NetRxPkt *pkt)
|
||||
NetRxPkt *pkt = (NetRxPkt *)pkt;
|
||||
assert(pkt);
|
||||
|
||||
printf("RX PKT: tot_len: %d, ehdr_buf_len: %lu, vlan_tag: %d\n",
|
||||
pkt->tot_len, pkt->ehdr_buf_len, pkt->tci);
|
||||
printf("RX PKT: tot_len: %d, vlan_stripped: %d, vlan_tag: %d\n",
|
||||
pkt->tot_len, pkt->vlan_stripped, pkt->tci);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -427,7 +426,7 @@ bool net_rx_pkt_is_vlan_stripped(struct NetRxPkt *pkt)
|
||||
{
|
||||
assert(pkt);
|
||||
|
||||
return pkt->ehdr_buf_len ? true : false;
|
||||
return pkt->vlan_stripped;
|
||||
}
|
||||
|
||||
bool net_rx_pkt_has_virt_hdr(struct NetRxPkt *pkt)
|
||||
|
@@ -982,8 +982,8 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
|
||||
pci_get_function_0(pci_dev)) {
|
||||
error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
|
||||
" new func %s cannot be exposed to guest.",
|
||||
PCI_SLOT(pci_get_function_0(pci_dev)->devfn),
|
||||
pci_get_function_0(pci_dev)->name,
|
||||
PCI_SLOT(devfn),
|
||||
bus->devices[PCI_DEVFN(PCI_SLOT(devfn), 0)]->name,
|
||||
name);
|
||||
|
||||
return NULL;
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qapi/error.h"
|
||||
#include "target-ppc/cpu.h"
|
||||
#include "target/ppc/cpu.h"
|
||||
|
||||
#include "hw/ppc/fdt.h"
|
||||
|
||||
|
@@ -22,7 +22,7 @@
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "sysemu/numa.h"
|
||||
#include "hw/hw.h"
|
||||
#include "target-ppc/cpu.h"
|
||||
#include "target/ppc/cpu.h"
|
||||
#include "qemu/log.h"
|
||||
#include "hw/ppc/fdt.h"
|
||||
#include "hw/ppc/ppc.h"
|
||||
|
@@ -20,7 +20,7 @@
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/log.h"
|
||||
#include "target-ppc/cpu.h"
|
||||
#include "target/ppc/cpu.h"
|
||||
#include "hw/ppc/ppc.h"
|
||||
#include "hw/ppc/pnv.h"
|
||||
#include "hw/ppc/pnv_core.h"
|
||||
|
@@ -19,7 +19,7 @@
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "target-ppc/cpu.h"
|
||||
#include "target/ppc/cpu.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/log.h"
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#include "hw/hw.h"
|
||||
#include "qemu/log.h"
|
||||
#include "sysemu/kvm.h"
|
||||
#include "target-ppc/cpu.h"
|
||||
#include "target/ppc/cpu.h"
|
||||
#include "hw/sysbus.h"
|
||||
|
||||
#include "hw/ppc/fdt.h"
|
||||
|
@@ -8,14 +8,14 @@
|
||||
*/
|
||||
#include "hw/cpu/core.h"
|
||||
#include "hw/ppc/spapr_cpu_core.h"
|
||||
#include "target-ppc/cpu.h"
|
||||
#include "target/ppc/cpu.h"
|
||||
#include "hw/ppc/spapr.h"
|
||||
#include "hw/boards.h"
|
||||
#include "qapi/error.h"
|
||||
#include "sysemu/cpus.h"
|
||||
#include "target-ppc/kvm_ppc.h"
|
||||
#include "target/ppc/kvm_ppc.h"
|
||||
#include "hw/ppc/ppc.h"
|
||||
#include "target-ppc/mmu-hash64.h"
|
||||
#include "target/ppc/mmu-hash64.h"
|
||||
#include "sysemu/numa.h"
|
||||
|
||||
static void spapr_cpu_reset(void *opaque)
|
||||
|
@@ -250,5 +250,5 @@ int spapr_ovec_populate_dt(void *fdt, int fdt_offset,
|
||||
}
|
||||
}
|
||||
|
||||
return fdt_setprop(fdt, fdt_offset, name, vec, vec_len + 1);
|
||||
return fdt_setprop(fdt, fdt_offset, name, vec, vec_len);
|
||||
}
|
||||
|
@@ -1672,27 +1672,12 @@ void subch_device_save(SubchDev *s, QEMUFile *f)
|
||||
|
||||
int subch_device_load(SubchDev *s, QEMUFile *f)
|
||||
{
|
||||
SubchDev *old_s;
|
||||
uint16_t old_schid = s->schid;
|
||||
int i;
|
||||
|
||||
s->cssid = qemu_get_byte(f);
|
||||
s->ssid = qemu_get_byte(f);
|
||||
s->schid = qemu_get_be16(f);
|
||||
s->devno = qemu_get_be16(f);
|
||||
/* Re-assign subch. */
|
||||
if (old_schid != s->schid) {
|
||||
old_s = channel_subsys.css[s->cssid]->sch_set[s->ssid]->sch[old_schid];
|
||||
/*
|
||||
* (old_s != s) means that some other device has its correct
|
||||
* subchannel already assigned (in load).
|
||||
*/
|
||||
if (old_s == s) {
|
||||
css_subch_assign(s->cssid, s->ssid, old_schid, s->devno, NULL);
|
||||
}
|
||||
/* It's OK to re-assign without a prior de-assign. */
|
||||
css_subch_assign(s->cssid, s->ssid, s->schid, s->devno, s);
|
||||
}
|
||||
s->thinint_active = qemu_get_byte(f);
|
||||
/* SCHIB */
|
||||
/* PMCW */
|
||||
|
@@ -204,8 +204,8 @@ void s390_machine_reset(void)
|
||||
{
|
||||
S390CPU *ipl_cpu = S390_CPU(qemu_get_cpu(0));
|
||||
|
||||
s390_cmma_reset();
|
||||
qemu_devices_reset();
|
||||
s390_cmma_reset();
|
||||
s390_crypto_reset();
|
||||
|
||||
/* all cpus are stopped - configure and start the ipl cpu only */
|
||||
|
@@ -756,7 +756,7 @@ static void mptsas_fetch_request(MPTSASState *s)
|
||||
|
||||
/* Read the message header from the guest first. */
|
||||
addr = s->host_mfa_high_addr | MPTSAS_FIFO_GET(s, request_post);
|
||||
pci_dma_read(pci, addr, req, sizeof(*hdr));
|
||||
pci_dma_read(pci, addr, req, sizeof(hdr));
|
||||
|
||||
if (hdr->Function < ARRAY_SIZE(mpi_request_sizes) &&
|
||||
mpi_request_sizes[hdr->Function]) {
|
||||
@@ -766,8 +766,8 @@ static void mptsas_fetch_request(MPTSASState *s)
|
||||
*/
|
||||
size = mpi_request_sizes[hdr->Function];
|
||||
assert(size <= MPTSAS_MAX_REQUEST_SIZE);
|
||||
pci_dma_read(pci, addr + sizeof(*hdr), &req[sizeof(*hdr)],
|
||||
size - sizeof(*hdr));
|
||||
pci_dma_read(pci, addr + sizeof(hdr), &req[sizeof(hdr)],
|
||||
size - sizeof(hdr));
|
||||
}
|
||||
|
||||
if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST) {
|
||||
|
@@ -2157,6 +2157,13 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)
|
||||
DPRINTF("Write %s(sector %" PRId64 ", count %u)\n",
|
||||
(command & 0xe) == 0xe ? "And Verify " : "",
|
||||
r->req.cmd.lba, len);
|
||||
case VERIFY_10:
|
||||
case VERIFY_12:
|
||||
case VERIFY_16:
|
||||
/* We get here only for BYTCHK == 0x01 and only for scsi-block.
|
||||
* As far as DMA is concerned, we can treat it the same as a write;
|
||||
* scsi_block_do_sgio will send VERIFY commands.
|
||||
*/
|
||||
if (r->req.cmd.buf[1] & 0xe0) {
|
||||
goto illegal_request;
|
||||
}
|
||||
@@ -2694,7 +2701,7 @@ static bool scsi_block_is_passthrough(SCSIDiskState *s, uint8_t *buf)
|
||||
* for the number of logical blocks specified in the length
|
||||
* field). For other modes, do not use scatter/gather operation.
|
||||
*/
|
||||
if ((buf[1] & 6) == 2) {
|
||||
if ((buf[1] & 6) != 2) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@@ -2712,7 +2719,7 @@ static bool scsi_block_is_passthrough(SCSIDiskState *s, uint8_t *buf)
|
||||
case WRITE_VERIFY_16:
|
||||
/* MMC writing cannot be done via DMA helpers, because it sometimes
|
||||
* involves writing beyond the maximum LBA or to negative LBA (lead-in).
|
||||
* We might use scsi_disk_dma_reqops as long as no writing commands are
|
||||
* We might use scsi_block_dma_reqops as long as no writing commands are
|
||||
* seen, but performance usually isn't paramount on optical media. So,
|
||||
* just make scsi-block operate the same as scsi-generic for them.
|
||||
*/
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user