diff options
301 files changed, 7273 insertions, 5314 deletions
diff --git a/.mailmap b/.mailmap new file mode 100644 index 0000000000..9797802aaa --- /dev/null +++ b/.mailmap @@ -0,0 +1,16 @@ +# This mailmap just translates the weird addresses from the original import into git +# into proper addresses so that they are counted properly in git shortlog output. +# +Andrzej Zaborowski <balrogg@gmail.com> balrog <balrog@c046a42c-6fe2-441c-8c8c-71466251a162> +Anthony Liguori <aliguori@us.ibm.com> aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> +Aurelien Jarno <aurelien@aurel32.net> aurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162> +Blue Swirl <blauwirbel@gmail.com> blueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162> +Edgar E. Iglesias <edgar.iglesias@gmail.com> edgar_igl <edgar_igl@c046a42c-6fe2-441c-8c8c-71466251a162> +Fabrice Bellard <fabrice@bellard.org> bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> +Jocelyn Mayer <l_indien@magic.fr> j_mayer <j_mayer@c046a42c-6fe2-441c-8c8c-71466251a162> +Paul Brook <paul@codesourcery.com> pbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162> +Thiemo Seufer <ths@networkno.de> ths <ths@c046a42c-6fe2-441c-8c8c-71466251a162> +malc <av1474@comtv.ru> malc <malc@c046a42c-6fe2-441c-8c8c-71466251a162> +# There is also a: +# (no author) <(no author)@c046a42c-6fe2-441c-8c8c-71466251a162> +# for the cvs2svn initialization commit e63c3dc74bf. @@ -78,7 +78,7 @@ version 0.10.2: - fix savevm/loadvm (Anthony Liguori) - live migration: fix dirty tracking windows (Glauber Costa) - - live migration: improve error propogation (Glauber Costa) + - live migration: improve error propagation (Glauber Costa) - qcow2: fix image creation for > ~2TB images (Chris Wright) - hotplug: fix error handling for if= parameter (Eduardo Habkost) - qcow2: fix data corruption (Nolan Leake) @@ -386,7 +386,7 @@ version 0.5.3: - support of CD-ROM change - multiple network interface support - initial x86-64 host support (Gwenole Beauchesne) - - lret to outer priviledge fix (OS/2 install fix) + - lret to outer privilege fix (OS/2 install fix) - task switch fixes (SkyOS boot) - VM save/restore commands - new timer API @@ -77,11 +77,13 @@ avoided. Use of the malloc/free/realloc/calloc/valloc/memalign/posix_memalign APIs is not allowed in the QEMU codebase. Instead of these routines, -use the replacement g_malloc/g_malloc0/g_realloc/g_free or -qemu_vmalloc/qemu_memalign/qemu_vfree APIs. +use the GLib memory allocation routines g_malloc/g_malloc0/g_new/ +g_new0/g_realloc/g_free or QEMU's qemu_vmalloc/qemu_memalign/qemu_vfree +APIs. -Please note that NULL check for the g_malloc result is redundant and -that g_malloc() call with zero size is not allowed. +Please note that g_malloc will exit on allocation failure, so there +is no need to test for failure (as you would have to with malloc). +Calling g_malloc with a zero size is valid and will return NULL. Memory allocated by qemu_vmalloc or qemu_memalign must be freed with qemu_vfree, since breaking this will cause problems on Win32 and user @@ -6,9 +6,7 @@ The following points clarify the QEMU license: GNU General Public License. Hence each source file contains its own licensing information. -In particular, the QEMU virtual CPU core library (libqemu.a) is -released under the GNU Lesser General Public License. Many hardware -device emulation sources are released under the BSD license. +Many hardware device emulation sources are released under the BSD license. 3) The Tiny Code Generator (TCG) is released under the BSD license (see license headers in files). diff --git a/MAINTAINERS b/MAINTAINERS index 7ee301e787..e22bfa1a30 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20,7 +20,7 @@ Descriptions of section entries: Supported: Someone is actually paid to look after this. Maintained: Someone actually looks after it. Odd Fixes: It has a maintainer but they don't have time to do - much other than throw the odd patch in. See below.. + much other than throw the odd patch in. See below. Orphan: No current maintainer [but maybe you could take the role as you write your new code]. Obsolete: Old code. Something tagged obsolete generally means @@ -485,6 +485,11 @@ S: Maintained F: trace/ T: git://repo.or.cz/qemu/stefanha.git tracing +Checkpatch +M: Blue Swirl <blauwirbel@gmail.com> +S: Odd Fixes +F: scripts/checkpatch.pl + Usermode Emulation ------------------ BSD user @@ -554,3 +559,8 @@ SPARC target M: Blue Swirl <blauwirbel@gmail.com> S: Maintained F: tcg/sparc/ + +TCI target +M: Stefan Weil <sw@weilnetz.de> +S: Maintained +F: tcg/tci @@ -168,8 +168,8 @@ check-qjson: check-qjson.o $(qobject-obj-y) $(tools-obj-y) test-coroutine: test-coroutine.o qemu-timer-common.o async.o $(coroutine-obj-y) $(tools-obj-y) $(qapi-obj-y): $(GENERATED_HEADERS) -qapi-dir := qapi-generated -test-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir) +qapi-dir := $(BUILD_DIR)/qapi-generated +test-qmp-input-visitor.o test-qmp-output-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir) qemu-ga$(EXESUF): LIBS = $(LIBS_QGA) $(qapi-dir)/test-qapi-types.c $(qapi-dir)/test-qapi-types.h :\ @@ -202,8 +202,11 @@ qmp-commands.h qmp-marshal.c :\ $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -m -o "." < $<, " GEN $@") -test-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) -test-visitor: test-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o +test-qmp-output-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) +test-qmp-output-visitor: test-qmp-output-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o + +test-qmp-input-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) +test-qmp-input-visitor: test-qmp-input-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o test-qmp-commands.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h test-qmp-marshal.c test-qmp-commands.h) $(qapi-obj-y) test-qmp-commands: test-qmp-commands.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o $(qapi-dir)/test-qmp-marshal.o module.o diff --git a/Makefile.objs b/Makefile.objs index d7a65393b3..f753d838ff 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -68,10 +68,9 @@ endif fsdev-obj-$(CONFIG_VIRTFS) += $(addprefix fsdev/, $(fsdev-nested-y)) ###################################################################### -# libqemu_common.a: Target independent part of system emulation. The -# long term path is to suppress *all* target specific code in case of -# system emulation, i.e. a single QEMU executable should support all -# CPUs and machines. +# Target independent part of system emulation. The long term path is to +# suppress *all* target specific code in case of system emulation, i.e. a +# single QEMU executable should support all CPUs and machines. common-obj-y = $(block-obj-y) blockdev.o common-obj-y += $(net-obj-y) @@ -279,7 +278,7 @@ hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o hw-obj-$(CONFIG_ESP) += esp.o hw-obj-y += dma-helpers.o sysbus.o isa-bus.o -hw-obj-y += qdev-addr.o +hw-obj-y += qdev-addr.o container.o # VGA hw-obj-$(CONFIG_VGA_PCI) += vga-pci.o @@ -310,8 +309,8 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y) 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-local.o virtio-9p-xattr.o 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o -9pfs-nested-$(CONFIG_VIRTFS) += coxattr.o virtio-9p-handle.o -9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-synth.o +9pfs-nested-$(CONFIG_VIRTFS) += coxattr.o virtio-9p-synth.o +9pfs-nested-$(CONFIG_OPEN_BY_HANDLE) += virtio-9p-handle.o hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y)) $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS) diff --git a/Makefile.target b/Makefile.target index a111521dbf..3261383fd3 100644 --- a/Makefile.target +++ b/Makefile.target @@ -92,14 +92,6 @@ tci-dis.o: QEMU_CFLAGS += -I$(SRC_PATH)/tcg -I$(SRC_PATH)/tcg/tci $(libobj-y): $(GENERATED_HEADERS) -# libqemu - -translate.o: translate.c cpu.h - -translate-all.o: translate-all.c cpu.h - -tcg/tcg.o: cpu.h - # HELPER_CFLAGS is used for all the code compiled with static register # variables op_helper.o ldst_helper.o user-exec.o: QEMU_CFLAGS += $(HELPER_CFLAGS) @@ -344,6 +336,7 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o +obj-arm-y += arm_mptimer.o obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o obj-arm-y += pl061.o obj-arm-y += arm-semi.o @@ -361,9 +354,6 @@ obj-arm-y += mst_fpga.o mainstone.o obj-arm-y += z2.o obj-arm-y += musicpal.o bitbang_i2c.o marvell_88w8618_audio.o obj-arm-y += framebuffer.o -obj-arm-y += syborg.o syborg_fb.o syborg_interrupt.o syborg_keyboard.o -obj-arm-y += syborg_serial.o syborg_timer.o syborg_pointer.o syborg_rtc.o -obj-arm-y += syborg_virtio.o obj-arm-y += vexpress.o obj-arm-y += strongarm.o obj-arm-y += collie.o diff --git a/QMP/qmp b/QMP/qmp new file mode 100755 index 0000000000..1db3c7ffeb --- /dev/null +++ b/QMP/qmp @@ -0,0 +1,126 @@ +#!/usr/bin/python +# +# QMP command line tool +# +# Copyright IBM, Corp. 2011 +# +# Authors: +# Anthony Liguori <aliguori@us.ibm.com> +# +# This work is licensed under the terms of the GNU GPLv2 or later. +# See the COPYING file in the top-level directory. + +import sys, os +from qmp import QEMUMonitorProtocol + +def print_response(rsp, prefix=[]): + if type(rsp) == list: + i = 0 + for item in rsp: + if prefix == []: + prefix = ['item'] + print_response(item, prefix[:-1] + ['%s[%d]' % (prefix[-1], i)]) + i += 1 + elif type(rsp) == dict: + for key in rsp.keys(): + print_response(rsp[key], prefix + [key]) + else: + if len(prefix): + print '%s: %s' % ('.'.join(prefix), rsp) + else: + print '%s' % (rsp) + +def main(args): + path = None + + # Use QMP_PATH if it's set + if os.environ.has_key('QMP_PATH'): + path = os.environ['QMP_PATH'] + + while len(args): + arg = args[0] + + if arg.startswith('--'): + arg = arg[2:] + if arg.find('=') == -1: + value = True + else: + arg, value = arg.split('=', 1) + + if arg in ['path']: + if type(value) == str: + path = value + elif arg in ['help']: + os.execlp('man', 'man', 'qmp') + else: + print 'Unknown argument "%s"' % arg + + args = args[1:] + else: + break + + if not path: + print "QMP path isn't set, use --path=qmp-monitor-address or set QMP_PATH" + return 1 + + if len(args): + command, args = args[0], args[1:] + else: + print 'No command found' + print 'Usage: "qmp [--path=qmp-monitor-address] qmp-cmd arguments"' + return 1 + + if command in ['help']: + os.execlp('man', 'man', 'qmp') + + srv = QEMUMonitorProtocol(path) + srv.connect() + + def do_command(srv, cmd, **kwds): + rsp = srv.cmd(cmd, kwds) + if rsp.has_key('error'): + raise Exception(rsp['error']['desc']) + return rsp['return'] + + commands = map(lambda x: x['name'], do_command(srv, 'query-commands')) + + srv.close() + + if command not in commands: + fullcmd = 'qmp-%s' % command + try: + os.environ['QMP_PATH'] = path + os.execvp(fullcmd, [fullcmd] + args) + except OSError, (errno, msg): + if errno == 2: + print 'Command "%s" not found.' % (fullcmd) + return 1 + raise + return 0 + + srv = QEMUMonitorProtocol(path) + srv.connect() + + arguments = {} + for arg in args: + if not arg.startswith('--'): + print 'Unknown argument "%s"' % arg + return 1 + + arg = arg[2:] + if arg.find('=') == -1: + value = True + else: + arg, value = arg.split('=', 1) + + if arg in ['help']: + os.execlp('man', 'man', 'qmp-%s' % command) + return 1 + + arguments[arg] = value + + rsp = do_command(srv, command, **arguments) + print_response(rsp) + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt index 0ce5d4efe2..af586ec855 100644 --- a/QMP/qmp-events.txt +++ b/QMP/qmp-events.txt @@ -126,7 +126,7 @@ the authentication ID is not provided. VNC_DISCONNECTED ---------------- -Emitted when the conection is closed. +Emitted when the connection is closed. Data: @@ -1,3 +1,3 @@ -Read the documentation in qemu-doc.html. +Read the documentation in qemu-doc.html or on http://wiki.qemu.org -Fabrice Bellard. +- QEMU team @@ -1 +1 @@ -0.15.93 +1.0.50 @@ -1624,7 +1624,7 @@ arm_decode_shift (long given, fprintf_function func, void *stream, } /* Print one coprocessor instruction on INFO->STREAM. - Return true if the instuction matched, false if this is not a + Return true if the instruction matched, false if this is not a recognised coprocessor instruction. */ static bfd_boolean @@ -2214,7 +2214,7 @@ print_arm_address (bfd_vma pc, struct disassemble_info *info, long given) } /* Print one neon instruction on INFO->STREAM. - Return true if the instuction matched, false if this is not a + Return true if the instruction matched, false if this is not a recognised neon instruction. */ static bfd_boolean @@ -3927,7 +3927,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info) n = last_mapping_sym - 1; /* No mapping symbol found at this address. Look backwards - for a preceeding one. */ + for a preceding one. */ for (; n >= 0; n--) { if (get_sym_code_type (info, n, &type)) diff --git a/audio/audio.c b/audio/audio.c index 50d0d7183f..5fff6de966 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -1665,7 +1665,7 @@ static void audio_pp_nb_voices (const char *typ, int nb) printf ("Theoretically supports many %s voices\n", typ); break; default: - printf ("Theoretically supports upto %d %s voices\n", nb, typ); + printf ("Theoretically supports up to %d %s voices\n", nb, typ); break; } @@ -100,31 +100,19 @@ BalloonInfo *qmp_query_balloon(Error **errp) return info; } -/** - * do_balloon(): Request VM to change its memory allocation - */ -int do_balloon(Monitor *mon, const QDict *params, - MonitorCompletion cb, void *opaque) +void qmp_balloon(int64_t value, Error **errp) { - int64_t target; - int ret; - if (kvm_enabled() && !kvm_has_sync_mmu()) { - qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); - return -1; + error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); + return; } - target = qdict_get_int(params, "value"); - if (target <= 0) { + if (value <= 0) { qerror_report(QERR_INVALID_PARAMETER_VALUE, "target", "a size"); - return -1; + return; } - ret = qemu_balloon(target); - if (ret == 0) { - qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); - return -1; + + if (qemu_balloon(value) == 0) { + error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon"); } - - cb(opaque, NULL); - return 0; } @@ -24,7 +24,4 @@ int qemu_add_balloon_handler(QEMUBalloonEvent *event_func, QEMUBalloonStatus *stat_func, void *opaque); void qemu_remove_balloon_handler(void *opaque); -int do_balloon(Monitor *mon, const QDict *params, - MonitorCompletion cb, void *opaque); - #endif diff --git a/block-migration.c b/block-migration.c index 5f10486416..2b7edbc3d7 100644 --- a/block-migration.c +++ b/block-migration.c @@ -251,22 +251,12 @@ static int mig_save_device_bulk(Monitor *mon, QEMUFile *f, blk->aiocb = bdrv_aio_readv(bs, cur_sector, &blk->qiov, nr_sectors, blk_mig_read_cb, blk); - if (!blk->aiocb) { - goto error; - } block_mig_state.submitted++; bdrv_reset_dirty(bs, cur_sector, nr_sectors); bmds->cur_sector = cur_sector + nr_sectors; return (bmds->cur_sector >= total_sectors); - -error: - monitor_printf(mon, "Error reading sector %" PRId64 "\n", cur_sector); - qemu_file_set_error(f, -EIO); - g_free(blk->buf); - g_free(blk); - return 0; } static void set_dirty_tracking(int enable) @@ -387,7 +377,7 @@ static int mig_save_device_dirty(Monitor *mon, QEMUFile *f, for (sector = bmds->cur_dirty; sector < bmds->total_sectors;) { if (bmds_aio_inflight(bmds, sector)) { - qemu_aio_flush(); + bdrv_drain_all(); } if (bdrv_get_dirty(bmds->bs, sector)) { @@ -413,9 +403,6 @@ static int mig_save_device_dirty(Monitor *mon, QEMUFile *f, blk->aiocb = bdrv_aio_readv(bmds->bs, sector, &blk->qiov, nr_sectors, blk_mig_read_cb, blk); - if (!blk->aiocb) { - goto error; - } block_mig_state.submitted++; bmds_set_aio_inflight(bmds, sector, nr_sectors, 1); } else { @@ -30,6 +30,7 @@ #include "qjson.h" #include "qemu-coroutine.h" #include "qmp-commands.h" +#include "qemu-timer.h" #ifdef CONFIG_BSD #include <sys/types.h> @@ -73,6 +74,13 @@ static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs, bool is_write); static void coroutine_fn bdrv_co_do_rw(void *opaque); +static bool bdrv_exceed_bps_limits(BlockDriverState *bs, int nb_sectors, + bool is_write, double elapsed_time, uint64_t *wait); +static bool bdrv_exceed_iops_limits(BlockDriverState *bs, bool is_write, + double elapsed_time, uint64_t *wait); +static bool bdrv_exceed_io_limits(BlockDriverState *bs, int nb_sectors, + bool is_write, int64_t *wait); + static QTAILQ_HEAD(, BlockDriverState) bdrv_states = QTAILQ_HEAD_INITIALIZER(bdrv_states); @@ -105,6 +113,79 @@ int is_windows_drive(const char *filename) } #endif +/* throttling disk I/O limits */ +void bdrv_io_limits_disable(BlockDriverState *bs) +{ + bs->io_limits_enabled = false; + + while (qemu_co_queue_next(&bs->throttled_reqs)); + + if (bs->block_timer) { + qemu_del_timer(bs->block_timer); + qemu_free_timer(bs->block_timer); + bs->block_timer = NULL; + } + + bs->slice_start = 0; + bs->slice_end = 0; + bs->slice_time = 0; + memset(&bs->io_base, 0, sizeof(bs->io_base)); +} + +static void bdrv_block_timer(void *opaque) +{ + BlockDriverState *bs = opaque; + + qemu_co_queue_next(&bs->throttled_reqs); +} + +void bdrv_io_limits_enable(BlockDriverState *bs) +{ + qemu_co_queue_init(&bs->throttled_reqs); + bs->block_timer = qemu_new_timer_ns(vm_clock, bdrv_block_timer, bs); + bs->slice_time = 5 * BLOCK_IO_SLICE_TIME; + bs->slice_start = qemu_get_clock_ns(vm_clock); + bs->slice_end = bs->slice_start + bs->slice_time; + memset(&bs->io_base, 0, sizeof(bs->io_base)); + bs->io_limits_enabled = true; +} + +bool bdrv_io_limits_enabled(BlockDriverState *bs) +{ + BlockIOLimit *io_limits = &bs->io_limits; + return io_limits->bps[BLOCK_IO_LIMIT_READ] + || io_limits->bps[BLOCK_IO_LIMIT_WRITE] + || io_limits->bps[BLOCK_IO_LIMIT_TOTAL] + || io_limits->iops[BLOCK_IO_LIMIT_READ] + || io_limits->iops[BLOCK_IO_LIMIT_WRITE] + || io_limits->iops[BLOCK_IO_LIMIT_TOTAL]; +} + +static void bdrv_io_limits_intercept(BlockDriverState *bs, + bool is_write, int nb_sectors) +{ + int64_t wait_time = -1; + + if (!qemu_co_queue_empty(&bs->throttled_reqs)) { + qemu_co_queue_wait(&bs->throttled_reqs); + } + + /* In fact, we hope to keep each request's timing, in FIFO mode. The next + * throttled requests will not be dequeued until the current request is + * allowed to be serviced. So if the current request still exceeds the + * limits, it will be inserted to the head. All requests followed it will + * be still in throttled_reqs queue. + */ + + while (bdrv_exceed_io_limits(bs, nb_sectors, is_write, &wait_time)) { + qemu_mod_timer(bs->block_timer, + wait_time + qemu_get_clock_ns(vm_clock)); + qemu_co_queue_wait_insert_head(&bs->throttled_reqs); + } + + qemu_co_queue_next(&bs->throttled_reqs); +} + /* check if the path starts with "<protocol>:" */ static int path_has_protocol(const char *path) { @@ -457,6 +538,22 @@ int bdrv_parse_cache_flags(const char *mode, int *flags) return 0; } +/** + * The copy-on-read flag is actually a reference count so multiple users may + * use the feature without worrying about clobbering its previous state. + * Copy-on-read stays enabled until all users have called to disable it. + */ +void bdrv_enable_copy_on_read(BlockDriverState *bs) +{ + bs->copy_on_read++; +} + +void bdrv_disable_copy_on_read(BlockDriverState *bs) +{ + assert(bs->copy_on_read > 0); + bs->copy_on_read--; +} + /* * Common part for opening disk images and files */ @@ -478,6 +575,11 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, bs->growable = 0; bs->buffer_alignment = 512; + assert(bs->copy_on_read == 0); /* bdrv_new() and bdrv_close() make it so */ + if ((flags & BDRV_O_RDWR) && (flags & BDRV_O_COPY_ON_READ)) { + bdrv_enable_copy_on_read(bs); + } + pstrcpy(bs->filename, sizeof(bs->filename), filename); bs->backing_file[0] = '\0'; @@ -687,6 +789,11 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, bdrv_dev_change_media_cb(bs, true); } + /* throttling disk I/O limits */ + if (bs->io_limits_enabled) { + bdrv_io_limits_enable(bs); + } + return 0; unlink_and_fail: @@ -715,6 +822,7 @@ void bdrv_close(BlockDriverState *bs) #endif bs->opaque = NULL; bs->drv = NULL; + bs->copy_on_read = 0; if (bs->file != NULL) { bdrv_close(bs->file); @@ -722,6 +830,11 @@ void bdrv_close(BlockDriverState *bs) bdrv_dev_change_media_cb(bs, false); } + + /*throttling disk I/O limits*/ + if (bs->io_limits_enabled) { + bdrv_io_limits_disable(bs); + } } void bdrv_close_all(void) @@ -733,6 +846,25 @@ void bdrv_close_all(void) } } +/* + * Wait for pending requests to complete across all BlockDriverStates + * + * This function does not flush data to disk, use bdrv_flush_all() for that + * after calling this function. + */ +void bdrv_drain_all(void) +{ + BlockDriverState *bs; + + qemu_aio_flush(); + + /* If requests are still pending there is a bug somewhere */ + QTAILQ_FOREACH(bs, &bdrv_states, list) { + assert(QLIST_EMPTY(&bs->tracked_requests)); + assert(qemu_co_queue_empty(&bs->throttled_reqs)); + } +} + /* make a BlockDriverState anonymous by removing from bdrv_state list. Also, NULL terminate the device_name to prevent double remove */ void bdrv_make_anon(BlockDriverState *bs) @@ -922,7 +1054,7 @@ int bdrv_commit(BlockDriverState *bs) buf = g_malloc(COMMIT_BUF_SECTORS * BDRV_SECTOR_SIZE); for (sector = 0; sector < total_sectors; sector += n) { - if (drv->bdrv_is_allocated(bs, sector, COMMIT_BUF_SECTORS, &n)) { + if (bdrv_is_allocated(bs, sector, COMMIT_BUF_SECTORS, &n)) { if (bdrv_read(bs, sector, buf, n) != 0) { ret = -EIO; @@ -980,6 +1112,118 @@ void bdrv_commit_all(void) } } +struct BdrvTrackedRequest { + BlockDriverState *bs; + int64_t sector_num; + int nb_sectors; + bool is_write; + QLIST_ENTRY(BdrvTrackedRequest) list; + Coroutine *co; /* owner, used for deadlock detection */ + CoQueue wait_queue; /* coroutines blocked on this request */ +}; + +/** + * Remove an active request from the tracked requests list + * + * This function should be called when a tracked request is completing. + */ +static void tracked_request_end(BdrvTrackedRequest *req) +{ + QLIST_REMOVE(req, list); + qemu_co_queue_restart_all(&req->wait_queue); +} + +/** + * Add an active request to the tracked requests list + */ +static void tracked_request_begin(BdrvTrackedRequest *req, + BlockDriverState *bs, + int64_t sector_num, + int nb_sectors, bool is_write) +{ + *req = (BdrvTrackedRequest){ + .bs = bs, + .sector_num = sector_num, + .nb_sectors = nb_sectors, + .is_write = is_write, + .co = qemu_coroutine_self(), + }; + + qemu_co_queue_init(&req->wait_queue); + + QLIST_INSERT_HEAD(&bs->tracked_requests, req, list); +} + +/** + * Round a region to cluster boundaries + */ +static void round_to_clusters(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, + int64_t *cluster_sector_num, + int *cluster_nb_sectors) +{ + BlockDriverInfo bdi; + + if (bdrv_get_info(bs, &bdi) < 0 || bdi.cluster_size == 0) { + *cluster_sector_num = sector_num; + *cluster_nb_sectors = nb_sectors; + } else { + int64_t c = bdi.cluster_size / BDRV_SECTOR_SIZE; + *cluster_sector_num = QEMU_ALIGN_DOWN(sector_num, c); + *cluster_nb_sectors = QEMU_ALIGN_UP(sector_num - *cluster_sector_num + + nb_sectors, c); + } +} + +static bool tracked_request_overlaps(BdrvTrackedRequest *req, + int64_t sector_num, int nb_sectors) { + /* aaaa bbbb */ + if (sector_num >= req->sector_num + req->nb_sectors) { + return false; + } + /* bbbb aaaa */ + if (req->sector_num >= sector_num + nb_sectors) { + return false; + } + return true; +} + +static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs, + int64_t sector_num, int nb_sectors) +{ + BdrvTrackedRequest *req; + int64_t cluster_sector_num; + int cluster_nb_sectors; + bool retry; + + /* If we touch the same cluster it counts as an overlap. This guarantees + * that allocating writes will be serialized and not race with each other + * for the same cluster. For example, in copy-on-read it ensures that the + * CoR read and write operations are atomic and guest writes cannot + * interleave between them. + */ + round_to_clusters(bs, sector_num, nb_sectors, + &cluster_sector_num, &cluster_nb_sectors); + + do { + retry = false; + QLIST_FOREACH(req, &bs->tracked_requests, list) { + if (tracked_request_overlaps(req, cluster_sector_num, + cluster_nb_sectors)) { + /* Hitting this means there was a reentrant request, for + * example, a block driver issuing nested requests. This must + * never happen since it means deadlock. + */ + assert(qemu_coroutine_self() != req->co); + + qemu_co_queue_wait(&req->wait_queue); + retry = true; + break; + } + } + } while (retry); +} + /* * Return values: * 0 - success @@ -1252,6 +1496,61 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset, return 0; } +static int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) +{ + /* Perform I/O through a temporary buffer so that users who scribble over + * their read buffer while the operation is in progress do not end up + * modifying the image file. This is critical for zero-copy guest I/O + * where anything might happen inside guest memory. + */ + void *bounce_buffer; + + struct iovec iov; + QEMUIOVector bounce_qiov; + int64_t cluster_sector_num; + int cluster_nb_sectors; + size_t skip_bytes; + int ret; + + /* Cover entire cluster so no additional backing file I/O is required when + * allocating cluster in the image file. + */ + round_to_clusters(bs, sector_num, nb_sectors, + &cluster_sector_num, &cluster_nb_sectors); + + trace_bdrv_co_copy_on_readv(bs, sector_num, nb_sectors, + cluster_sector_num, cluster_nb_sectors); + + iov.iov_len = cluster_nb_sectors * BDRV_SECTOR_SIZE; + iov.iov_base = bounce_buffer = qemu_blockalign(bs, iov.iov_len); + qemu_iovec_init_external(&bounce_qiov, &iov, 1); + + ret = bs->drv->bdrv_co_readv(bs, cluster_sector_num, cluster_nb_sectors, + &bounce_qiov); + if (ret < 0) { + goto err; + } + + ret = bs->drv->bdrv_co_writev(bs, cluster_sector_num, cluster_nb_sectors, + &bounce_qiov); + if (ret < 0) { + /* It might be okay to ignore write errors for guest requests. If this + * is a deliberate copy-on-read then we don't want to ignore the error. + * Simply report it in all cases. + */ + goto err; + } + + skip_bytes = (sector_num - cluster_sector_num) * BDRV_SECTOR_SIZE; + qemu_iovec_from_buffer(qiov, bounce_buffer + skip_bytes, + nb_sectors * BDRV_SECTOR_SIZE); + +err: + qemu_vfree(bounce_buffer); + return ret; +} + /* * Handle a read request in coroutine context */ @@ -1259,6 +1558,8 @@ static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BlockDriver *drv = bs->drv; + BdrvTrackedRequest req; + int ret; if (!drv) { return -ENOMEDIUM; @@ -1267,7 +1568,36 @@ static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs, return -EIO; } - return drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov); + /* throttling disk read I/O */ + if (bs->io_limits_enabled) { + bdrv_io_limits_intercept(bs, false, nb_sectors); + } + + if (bs->copy_on_read) { + wait_for_overlapping_requests(bs, sector_num, nb_sectors); + } + + tracked_request_begin(&req, bs, sector_num, nb_sectors, false); + + if (bs->copy_on_read) { + int pnum; + + ret = bdrv_co_is_allocated(bs, sector_num, nb_sectors, &pnum); + if (ret < 0) { + goto out; + } + + if (!ret || pnum != nb_sectors) { + ret = bdrv_co_copy_on_readv(bs, sector_num, nb_sectors, qiov); + goto out; + } + } + + ret = drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov); + +out: + tracked_request_end(&req); + return ret; } int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, @@ -1285,6 +1615,7 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BlockDriver *drv = bs->drv; + BdrvTrackedRequest req; int ret; if (!bs->drv) { @@ -1297,6 +1628,17 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs, return -EIO; } + /* throttling disk write I/O */ + if (bs->io_limits_enabled) { + bdrv_io_limits_intercept(bs, true, nb_sectors); + } + + if (bs->copy_on_read) { + wait_for_overlapping_requests(bs, sector_num, nb_sectors); + } + + tracked_request_begin(&req, bs, sector_num, nb_sectors, true); + ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov); if (bs->dirty_bitmap) { @@ -1307,6 +1649,8 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs, bs->wr_highest_sector = sector_num + nb_sectors - 1; } + tracked_request_end(&req); + return ret; } @@ -1526,6 +1870,14 @@ void bdrv_get_geometry_hint(BlockDriverState *bs, *psecs = bs->secs; } +/* throttling disk io limits */ +void bdrv_set_io_limits(BlockDriverState *bs, + BlockIOLimit *io_limits) +{ + bs->io_limits = *io_limits; + bs->io_limits_enabled = bdrv_io_limits_enabled(bs); +} + /* Recognize floppy formats */ typedef struct FDFormat { FDriveType drive; @@ -1778,31 +2130,87 @@ int bdrv_has_zero_init(BlockDriverState *bs) return 1; } +typedef struct BdrvCoIsAllocatedData { + BlockDriverState *bs; + int64_t sector_num; + int nb_sectors; + int *pnum; + int ret; + bool done; +} BdrvCoIsAllocatedData; + /* * Returns true iff the specified sector is present in the disk image. Drivers * not implementing the functionality are assumed to not support backing files, * hence all their sectors are reported as allocated. * + * If 'sector_num' is beyond the end of the disk image the return value is 0 + * and 'pnum' is set to 0. + * * 'pnum' is set to the number of sectors (including and immediately following * the specified sector) that are known to be in the same * allocated/unallocated state. * - * 'nb_sectors' is the max value 'pnum' should be set to. + * 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors goes + * beyond the end of the disk image it will be clamped. */ -int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, - int *pnum) +int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, int *pnum) { int64_t n; - if (!bs->drv->bdrv_is_allocated) { - if (sector_num >= bs->total_sectors) { - *pnum = 0; - return 0; - } - n = bs->total_sectors - sector_num; - *pnum = (n < nb_sectors) ? (n) : (nb_sectors); + + if (sector_num >= bs->total_sectors) { + *pnum = 0; + return 0; + } + + n = bs->total_sectors - sector_num; + if (n < nb_sectors) { + nb_sectors = n; + } + + if (!bs->drv->bdrv_co_is_allocated) { + *pnum = nb_sectors; return 1; } - return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum); + + return bs->drv->bdrv_co_is_allocated(bs, sector_num, nb_sectors, pnum); +} + +/* Coroutine wrapper for bdrv_is_allocated() */ +static void coroutine_fn bdrv_is_allocated_co_entry(void *opaque) +{ + BdrvCoIsAllocatedData *data = opaque; + BlockDriverState *bs = data->bs; + + data->ret = bdrv_co_is_allocated(bs, data->sector_num, data->nb_sectors, + data->pnum); + data->done = true; +} + +/* + * Synchronous wrapper around bdrv_co_is_allocated(). + * + * See bdrv_co_is_allocated() for details. + */ +int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, + int *pnum) +{ + Coroutine *co; + BdrvCoIsAllocatedData data = { + .bs = bs, + .sector_num = sector_num, + .nb_sectors = nb_sectors, + .pnum = pnum, + .done = false, + }; + + co = qemu_coroutine_create(bdrv_is_allocated_co_entry); + qemu_coroutine_enter(co, &data); + while (!data.done) { + qemu_aio_wait(); + } + return data.ret; } void bdrv_mon_event(const BlockDriverState *bdrv, @@ -1869,6 +2277,21 @@ BlockInfoList *qmp_query_block(Error **errp) info->value->inserted->has_backing_file = true; info->value->inserted->backing_file = g_strdup(bs->backing_file); } + + if (bs->io_limits_enabled) { + info->value->inserted->bps = + bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL]; + info->value->inserted->bps_rd = + bs->io_limits.bps[BLOCK_IO_LIMIT_READ]; + info->value->inserted->bps_wr = + bs->io_limits.bps[BLOCK_IO_LIMIT_WRITE]; + info->value->inserted->iops = + bs->io_limits.iops[BLOCK_IO_LIMIT_TOTAL]; + info->value->inserted->iops_rd = + bs->io_limits.iops[BLOCK_IO_LIMIT_READ]; + info->value->inserted->iops_wr = + bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE]; + } } /* XXX: waiting for the qapi to support GSList */ @@ -2389,7 +2812,6 @@ static int multiwrite_merge(BlockDriverState *bs, BlockRequest *reqs, */ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs) { - BlockDriverAIOCB *acb; MultiwriteCB *mcb; int i; @@ -2420,66 +2842,185 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs) trace_bdrv_aio_multiwrite(mcb, mcb->num_callbacks, num_reqs); - /* - * Run the aio requests. As soon as one request can't be submitted - * successfully, fail all requests that are not yet submitted (we must - * return failure for all requests anyway) - * - * num_requests cannot be set to the right value immediately: If - * bdrv_aio_writev fails for some request, num_requests would be too high - * and therefore multiwrite_cb() would never recognize the multiwrite - * request as completed. We also cannot use the loop variable i to set it - * when the first request fails because the callback may already have been - * called for previously submitted requests. Thus, num_requests must be - * incremented for each request that is submitted. - * - * The problem that callbacks may be called early also means that we need - * to take care that num_requests doesn't become 0 before all requests are - * submitted - multiwrite_cb() would consider the multiwrite request - * completed. A dummy request that is "completed" by a manual call to - * multiwrite_cb() takes care of this. - */ - mcb->num_requests = 1; - - // Run the aio requests + /* Run the aio requests. */ + mcb->num_requests = num_reqs; for (i = 0; i < num_reqs; i++) { - mcb->num_requests++; - acb = bdrv_aio_writev(bs, reqs[i].sector, reqs[i].qiov, + bdrv_aio_writev(bs, reqs[i].sector, reqs[i].qiov, reqs[i].nb_sectors, multiwrite_cb, mcb); + } - if (acb == NULL) { - // We can only fail the whole thing if no request has been - // submitted yet. Otherwise we'll wait for the submitted AIOs to - // complete and report the error in the callback. - if (i == 0) { - trace_bdrv_aio_multiwrite_earlyfail(mcb); - goto fail; - } else { - trace_bdrv_aio_multiwrite_latefail(mcb, i); - multiwrite_cb(mcb, -EIO); - break; - } + return 0; +} + +void bdrv_aio_cancel(BlockDriverAIOCB *acb) +{ + acb->pool->cancel(acb); +} + +/* block I/O throttling */ +static bool bdrv_exceed_bps_limits(BlockDriverState *bs, int nb_sectors, + bool is_write, double elapsed_time, uint64_t *wait) +{ + uint64_t bps_limit = 0; + double bytes_limit, bytes_base, bytes_res; + double slice_time, wait_time; + + if (bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL]) { + bps_limit = bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL]; + } else if (bs->io_limits.bps[is_write]) { + bps_limit = bs->io_limits.bps[is_write]; + } else { + if (wait) { + *wait = 0; } + + return false; } - /* Complete the dummy request */ - multiwrite_cb(mcb, 0); + slice_time = bs->slice_end - bs->slice_start; + slice_time /= (NANOSECONDS_PER_SECOND); + bytes_limit = bps_limit * slice_time; + bytes_base = bs->nr_bytes[is_write] - bs->io_base.bytes[is_write]; + if (bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL]) { + bytes_base += bs->nr_bytes[!is_write] - bs->io_base.bytes[!is_write]; + } - return 0; + /* bytes_base: the bytes of data which have been read/written; and + * it is obtained from the history statistic info. + * bytes_res: the remaining bytes of data which need to be read/written. + * (bytes_base + bytes_res) / bps_limit: used to calcuate + * the total time for completing reading/writting all data. + */ + bytes_res = (unsigned) nb_sectors * BDRV_SECTOR_SIZE; -fail: - for (i = 0; i < mcb->num_callbacks; i++) { - reqs[i].error = -EIO; + if (bytes_base + bytes_res <= bytes_limit) { + if (wait) { + *wait = 0; + } + + return false; } - g_free(mcb); - return -1; + + /* Calc approx time to dispatch */ + wait_time = (bytes_base + bytes_res) / bps_limit - elapsed_time; + + /* When the I/O rate at runtime exceeds the limits, + * bs->slice_end need to be extended in order that the current statistic + * info can be kept until the timer fire, so it is increased and tuned + * based on the result of experiment. + */ + bs->slice_time = wait_time * BLOCK_IO_SLICE_TIME * 10; + bs->slice_end += bs->slice_time - 3 * BLOCK_IO_SLICE_TIME; + if (wait) { + *wait = wait_time * BLOCK_IO_SLICE_TIME * 10; + } + + return true; } -void bdrv_aio_cancel(BlockDriverAIOCB *acb) +static bool bdrv_exceed_iops_limits(BlockDriverState *bs, bool is_write, + double elapsed_time, uint64_t *wait) { - acb->pool->cancel(acb); + uint64_t iops_limit = 0; + double ios_limit, ios_base; + double slice_time, wait_time; + + if (bs->io_limits.iops[BLOCK_IO_LIMIT_TOTAL]) { + iops_limit = bs->io_limits.iops[BLOCK_IO_LIMIT_TOTAL]; + } else if (bs->io_limits.iops[is_write]) { + iops_limit = bs->io_limits.iops[is_write]; + } else { + if (wait) { + *wait = 0; + } + + return false; + } + + slice_time = bs->slice_end - bs->slice_start; + slice_time /= (NANOSECONDS_PER_SECOND); + ios_limit = iops_limit * slice_time; + ios_base = bs->nr_ops[is_write] - bs->io_base.ios[is_write]; + if (bs->io_limits.iops[BLOCK_IO_LIMIT_TOTAL]) { + ios_base += bs->nr_ops[!is_write] - bs->io_base.ios[!is_write]; + } + + if (ios_base + 1 <= ios_limit) { + if (wait) { + *wait = 0; + } + + return false; + } + + /* Calc approx time to dispatch */ + wait_time = (ios_base + 1) / iops_limit; + if (wait_time > elapsed_time) { + wait_time = wait_time - elapsed_time; + } else { + wait_time = 0; + } + + bs->slice_time = wait_time * BLOCK_IO_SLICE_TIME * 10; + bs->slice_end += bs->slice_time - 3 * BLOCK_IO_SLICE_TIME; + if (wait) { + *wait = wait_time * BLOCK_IO_SLICE_TIME * 10; + } + + return true; } +static bool bdrv_exceed_io_limits(BlockDriverState *bs, int nb_sectors, + bool is_write, int64_t *wait) +{ + int64_t now, max_wait; + uint64_t bps_wait = 0, iops_wait = 0; + double elapsed_time; + int bps_ret, iops_ret; + + now = qemu_get_clock_ns(vm_clock); + if ((bs->slice_start < now) + && (bs->slice_end > now)) { + bs->slice_end = now + bs->slice_time; + } else { + bs->slice_time = 5 * BLOCK_IO_SLICE_TIME; + bs->slice_start = now; + bs->slice_end = now + bs->slice_time; + + bs->io_base.bytes[is_write] = bs->nr_bytes[is_write]; + bs->io_base.bytes[!is_write] = bs->nr_bytes[!is_write]; + + bs->io_base.ios[is_write] = bs->nr_ops[is_write]; + bs->io_base.ios[!is_write] = bs->nr_ops[!is_write]; + } + + elapsed_time = now - bs->slice_start; + elapsed_time /= (NANOSECONDS_PER_SECOND); + + bps_ret = bdrv_exceed_bps_limits(bs, nb_sectors, + is_write, elapsed_time, &bps_wait); + iops_ret = bdrv_exceed_iops_limits(bs, is_write, + elapsed_time, &iops_wait); + if (bps_ret || iops_ret) { + max_wait = bps_wait > iops_wait ? bps_wait : iops_wait; + if (wait) { + *wait = max_wait; + } + + now = qemu_get_clock_ns(vm_clock); + if (bs->slice_end < now + max_wait) { + bs->slice_end = now + max_wait; + } + + return true; + } + + if (wait) { + *wait = 0; + } + + return false; +} /**************************************************************/ /* async block device emulation */ @@ -2536,9 +3077,7 @@ static BlockDriverAIOCB *bdrv_aio_rw_vector(BlockDriverState *bs, acb->is_write = is_write; acb->qiov = qiov; acb->bounce = qemu_blockalign(bs, qiov->size); - - if (!acb->bh) - acb->bh = qemu_bh_new(bdrv_aio_bh_cb, acb); + acb->bh = qemu_bh_new(bdrv_aio_bh_cb, acb); if (is_write) { qemu_iovec_to_buffer(acb->qiov, acb->bounce); @@ -21,8 +21,8 @@ typedef struct QEMUSnapshotInfo { char id_str[128]; /* unique snapshot id */ /* the following fields are informative. They are not needed for the consistency of the snapshot */ - char name[256]; /* user choosen name */ - uint32_t vm_state_size; /* VM state info size */ + char name[256]; /* user chosen name */ + uint64_t vm_state_size; /* VM state info size */ uint32_t date_sec; /* UTC date of the snapshot */ uint32_t date_nsec; uint64_t vm_clock_nsec; /* VM clock relative to boot */ @@ -70,6 +70,7 @@ typedef struct BlockDevOps { #define BDRV_O_NATIVE_AIO 0x0080 /* use native AIO instead of the thread pool */ #define BDRV_O_NO_BACKING 0x0100 /* don't open the backing file */ #define BDRV_O_NO_FLUSH 0x0200 /* disable flushing on this disk */ +#define BDRV_O_COPY_ON_READ 0x0400 /* copy read backing sectors into image */ #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH) @@ -98,6 +99,11 @@ void bdrv_info(Monitor *mon, QObject **ret_data); void bdrv_stats_print(Monitor *mon, const QObject *data); void bdrv_info_stats(Monitor *mon, QObject **ret_data); +/* disk I/O throttling */ +void bdrv_io_limits_enable(BlockDriverState *bs); +void bdrv_io_limits_disable(BlockDriverState *bs); +bool bdrv_io_limits_enabled(BlockDriverState *bs); + void bdrv_init(void); void bdrv_init_with_whitelist(void); BlockDriver *bdrv_find_protocol(const char *filename); @@ -138,6 +144,8 @@ int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); +int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, int *pnum); int bdrv_truncate(BlockDriverState *bs, int64_t offset); int64_t bdrv_getlength(BlockDriverState *bs); int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); @@ -206,6 +214,7 @@ int bdrv_flush(BlockDriverState *bs); int coroutine_fn bdrv_co_flush(BlockDriverState *bs); void bdrv_flush_all(void); void bdrv_close_all(void); +void bdrv_drain_all(void); int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); @@ -305,6 +314,9 @@ void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors); int64_t bdrv_get_dirty_count(BlockDriverState *bs); +void bdrv_enable_copy_on_read(BlockDriverState *bs); +void bdrv_disable_copy_on_read(BlockDriverState *bs); + void bdrv_set_in_use(BlockDriverState *bs, int in_use); int bdrv_in_use(BlockDriverState *bs); diff --git a/block/blkverify.c b/block/blkverify.c index 483f3b3cfe..4ca8584b88 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -310,14 +310,10 @@ static BlockDriverAIOCB *blkverify_aio_readv(BlockDriverState *bs, qemu_iovec_init(&acb->raw_qiov, acb->qiov->niov); blkverify_iovec_clone(&acb->raw_qiov, qiov, acb->buf); - if (!bdrv_aio_readv(s->test_file, sector_num, qiov, nb_sectors, - blkverify_aio_cb, acb)) { - blkverify_aio_cb(acb, -EIO); - } - if (!bdrv_aio_readv(bs->file, sector_num, &acb->raw_qiov, nb_sectors, - blkverify_aio_cb, acb)) { - blkverify_aio_cb(acb, -EIO); - } + bdrv_aio_readv(s->test_file, sector_num, qiov, nb_sectors, + blkverify_aio_cb, acb); + bdrv_aio_readv(bs->file, sector_num, &acb->raw_qiov, nb_sectors, + blkverify_aio_cb, acb); return &acb->common; } @@ -329,14 +325,10 @@ static BlockDriverAIOCB *blkverify_aio_writev(BlockDriverState *bs, BlkverifyAIOCB *acb = blkverify_aio_get(bs, true, sector_num, qiov, nb_sectors, cb, opaque); - if (!bdrv_aio_writev(s->test_file, sector_num, qiov, nb_sectors, - blkverify_aio_cb, acb)) { - blkverify_aio_cb(acb, -EIO); - } - if (!bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, - blkverify_aio_cb, acb)) { - blkverify_aio_cb(acb, -EIO); - } + bdrv_aio_writev(s->test_file, sector_num, qiov, nb_sectors, + blkverify_aio_cb, acb); + bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, + blkverify_aio_cb, acb); return &acb->common; } diff --git a/block/cow.c b/block/cow.c index 089d395c40..bb5927c6aa 100644 --- a/block/cow.c +++ b/block/cow.c @@ -64,15 +64,26 @@ static int cow_open(BlockDriverState *bs, int flags) struct cow_header_v2 cow_header; int bitmap_size; int64_t size; + int ret; /* see if it is a cow image */ - if (bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header)) != - sizeof(cow_header)) { + ret = bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header)); + if (ret < 0) { + goto fail; + } + + if (be32_to_cpu(cow_header.magic) != COW_MAGIC) { + ret = -EINVAL; goto fail; } - if (be32_to_cpu(cow_header.magic) != COW_MAGIC || - be32_to_cpu(cow_header.version) != COW_VERSION) { + if (be32_to_cpu(cow_header.version) != COW_VERSION) { + char version[64]; + snprintf(version, sizeof(version), + "COW version %d", cow_header.version); + qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, + bs->device_name, "cow", version); + ret = -ENOTSUP; goto fail; } @@ -88,11 +99,11 @@ static int cow_open(BlockDriverState *bs, int flags) qemu_co_mutex_init(&s->lock); return 0; fail: - return -1; + return ret; } /* - * XXX(hch): right now these functions are extremly ineffcient. + * XXX(hch): right now these functions are extremely ineffcient. * We should just read the whole bitmap we'll need in one go instead. */ static inline int cow_set_bit(BlockDriverState *bs, int64_t bitnum) @@ -132,8 +143,8 @@ static inline int is_bit_set(BlockDriverState *bs, int64_t bitnum) /* Return true if first block has been changed (ie. current version is * in COW file). Set the number of continuous blocks for which that * is true. */ -static int cow_is_allocated(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *num_same) +static int coroutine_fn cow_co_is_allocated(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, int *num_same) { int changed; @@ -171,28 +182,30 @@ static int cow_update_bitmap(BlockDriverState *bs, int64_t sector_num, return error; } -static int cow_read(BlockDriverState *bs, int64_t sector_num, - uint8_t *buf, int nb_sectors) +static int coroutine_fn cow_read(BlockDriverState *bs, int64_t sector_num, + uint8_t *buf, int nb_sectors) { BDRVCowState *s = bs->opaque; int ret, n; while (nb_sectors > 0) { - if (cow_is_allocated(bs, sector_num, nb_sectors, &n)) { + if (bdrv_co_is_allocated(bs, sector_num, nb_sectors, &n)) { ret = bdrv_pread(bs->file, s->cow_sectors_offset + sector_num * 512, buf, n * 512); - if (ret != n * 512) - return -1; + if (ret < 0) { + return ret; + } } else { if (bs->backing_hd) { /* read from the base image */ ret = bdrv_read(bs->backing_hd, sector_num, buf, n); - if (ret < 0) - return -1; + if (ret < 0) { + return ret; + } } else { - memset(buf, 0, n * 512); - } + memset(buf, 0, n * 512); + } } nb_sectors -= n; sector_num += n; @@ -220,8 +233,9 @@ static int cow_write(BlockDriverState *bs, int64_t sector_num, ret = bdrv_pwrite(bs->file, s->cow_sectors_offset + sector_num * 512, buf, nb_sectors * 512); - if (ret != nb_sectors * 512) - return -1; + if (ret < 0) { + return ret; + } return cow_update_bitmap(bs, sector_num, nb_sectors); } @@ -243,12 +257,12 @@ static void cow_close(BlockDriverState *bs) static int cow_create(const char *filename, QEMUOptionParameter *options) { - int fd, cow_fd; struct cow_header_v2 cow_header; struct stat st; int64_t image_sectors = 0; const char *image_filename = NULL; int ret; + BlockDriverState *cow_bs; /* Read out options */ while (options && options->name) { @@ -260,10 +274,16 @@ static int cow_create(const char *filename, QEMUOptionParameter *options) options++; } - cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - 0644); - if (cow_fd < 0) - return -errno; + ret = bdrv_create_file(filename, options); + if (ret < 0) { + return ret; + } + + ret = bdrv_file_open(&cow_bs, filename, BDRV_O_RDWR); + if (ret < 0) { + return ret; + } + memset(&cow_header, 0, sizeof(cow_header)); cow_header.magic = cpu_to_be32(COW_MAGIC); cow_header.version = cpu_to_be32(COW_VERSION); @@ -271,16 +291,9 @@ static int cow_create(const char *filename, QEMUOptionParameter *options) /* Note: if no file, we put a dummy mtime */ cow_header.mtime = cpu_to_be32(0); - fd = open(image_filename, O_RDONLY | O_BINARY); - if (fd < 0) { - close(cow_fd); + if (stat(image_filename, &st) != 0) { goto mtime_fail; } - if (fstat(fd, &st) != 0) { - close(fd); - goto mtime_fail; - } - close(fd); cow_header.mtime = cpu_to_be32(st.st_mtime); mtime_fail: pstrcpy(cow_header.backing_file, sizeof(cow_header.backing_file), @@ -288,21 +301,20 @@ static int cow_create(const char *filename, QEMUOptionParameter *options) } cow_header.sectorsize = cpu_to_be32(512); cow_header.size = cpu_to_be64(image_sectors * 512); - ret = qemu_write_full(cow_fd, &cow_header, sizeof(cow_header)); - if (ret != sizeof(cow_header)) { - ret = -errno; + ret = bdrv_pwrite(cow_bs, 0, &cow_header, sizeof(cow_header)); + if (ret < 0) { goto exit; } /* resize to include at least all the bitmap */ - ret = ftruncate(cow_fd, sizeof(cow_header) + ((image_sectors + 7) >> 3)); - if (ret) { - ret = -errno; + ret = bdrv_truncate(cow_bs, + sizeof(cow_header) + ((image_sectors + 7) >> 3)); + if (ret < 0) { goto exit; } exit: - close(cow_fd); + bdrv_delete(cow_bs); return ret; } @@ -337,7 +349,7 @@ static BlockDriver bdrv_cow = { .bdrv_read = cow_co_read, .bdrv_write = cow_co_write, .bdrv_co_flush_to_disk = cow_co_flush, - .bdrv_is_allocated = cow_is_allocated, + .bdrv_co_is_allocated = cow_co_is_allocated, .create_options = cow_create_options, }; diff --git a/block/curl.c b/block/curl.c index 4209ac88ce..e9102e3e20 100644 --- a/block/curl.c +++ b/block/curl.c @@ -509,10 +509,6 @@ static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs, acb = qemu_aio_get(&curl_aio_pool, bs, cb, opaque); - if (!acb) { - return NULL; - } - acb->qiov = qiov; acb->sector_num = sector_num; acb->nb_sectors = nb_sectors; diff --git a/block/nbd.c b/block/nbd.c index 882b2dc84a..95212dac64 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -189,7 +189,7 @@ static int nbd_read(BlockDriverState *bs, int64_t sector_num, request.type = NBD_CMD_READ; request.handle = (uint64_t)(intptr_t)bs; - request.from = sector_num * 512;; + request.from = sector_num * 512; request.len = nb_sectors * 512; if (nbd_send_request(s->sock, &request) == -1) @@ -219,7 +219,7 @@ static int nbd_write(BlockDriverState *bs, int64_t sector_num, request.type = NBD_CMD_WRITE; request.handle = (uint64_t)(intptr_t)bs; - request.from = sector_num * 512;; + request.from = sector_num * 512; request.len = nb_sectors * 512; if (nbd_send_request(s->sock, &request) == -1) diff --git a/block/qcow.c b/block/qcow.c index adecee06c9..b16955d764 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -26,6 +26,7 @@ #include "module.h" #include <zlib.h> #include "aes.h" +#include "migration.h" /**************************************************************/ /* QEMU COW block driver with compression and encryption support */ @@ -74,6 +75,7 @@ typedef struct BDRVQcowState { AES_KEY aes_encrypt_key; AES_KEY aes_decrypt_key; CoMutex lock; + Error *migration_blocker; } BDRVQcowState; static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset); @@ -160,6 +162,12 @@ static int qcow_open(BlockDriverState *bs, int flags) bs->backing_file[len] = '\0'; } + /* Disable migration when qcow images are used */ + error_set(&s->migration_blocker, + QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, + "qcow", bs->device_name, "live migration"); + migrate_add_blocker(s->migration_blocker); + qemu_co_mutex_init(&s->lock); return 0; @@ -360,14 +368,16 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, return cluster_offset; } -static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *pnum) +static int coroutine_fn qcow_co_is_allocated(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, int *pnum) { BDRVQcowState *s = bs->opaque; int index_in_cluster, n; uint64_t cluster_offset; + qemu_co_mutex_lock(&s->lock); cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0); + qemu_co_mutex_unlock(&s->lock); index_in_cluster = sector_num & (s->cluster_sectors - 1); n = s->cluster_sectors - index_in_cluster; if (n > nb_sectors) @@ -425,7 +435,7 @@ static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) return 0; } -static int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, +static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BDRVQcowState *s = bs->opaque; @@ -523,7 +533,7 @@ fail: goto done; } -static int qcow_co_writev(BlockDriverState *bs, int64_t sector_num, +static coroutine_fn int qcow_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BDRVQcowState *s = bs->opaque; @@ -604,10 +614,14 @@ static int qcow_co_writev(BlockDriverState *bs, int64_t sector_num, static void qcow_close(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; + g_free(s->l1_table); g_free(s->l2_cache); g_free(s->cluster_cache); g_free(s->cluster_data); + + migrate_del_blocker(s->migration_blocker); + error_free(s->migration_blocker); } static int qcow_create(const char *filename, QEMUOptionParameter *options) @@ -832,7 +846,7 @@ static BlockDriver bdrv_qcow = { .bdrv_co_readv = qcow_co_readv, .bdrv_co_writev = qcow_co_writev, .bdrv_co_flush_to_disk = qcow_co_flush, - .bdrv_is_allocated = qcow_is_allocated, + .bdrv_co_is_allocated = qcow_co_is_allocated, .bdrv_set_key = qcow_set_key, .bdrv_make_empty = qcow_make_empty, diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index f4e049fa90..07a2e936fd 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -289,89 +289,62 @@ void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num, } } - -static int qcow2_read(BlockDriverState *bs, int64_t sector_num, - uint8_t *buf, int nb_sectors) +static int coroutine_fn copy_sectors(BlockDriverState *bs, + uint64_t start_sect, + uint64_t cluster_offset, + int n_start, int n_end) { BDRVQcowState *s = bs->opaque; - int ret, index_in_cluster, n, n1; - uint64_t cluster_offset; - struct iovec iov; QEMUIOVector qiov; + struct iovec iov; + int n, ret; - while (nb_sectors > 0) { - n = nb_sectors; - - ret = qcow2_get_cluster_offset(bs, sector_num << 9, &n, - &cluster_offset); - if (ret < 0) { - return ret; - } - - index_in_cluster = sector_num & (s->cluster_sectors - 1); - if (!cluster_offset) { - if (bs->backing_hd) { - /* read from the base image */ - iov.iov_base = buf; - iov.iov_len = n * 512; - qemu_iovec_init_external(&qiov, &iov, 1); - - n1 = qcow2_backing_read1(bs->backing_hd, &qiov, sector_num, n); - if (n1 > 0) { - BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING); - ret = bdrv_read(bs->backing_hd, sector_num, buf, n1); - if (ret < 0) - return -1; - } - } else { - memset(buf, 0, 512 * n); - } - } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) { - if (qcow2_decompress_cluster(bs, cluster_offset) < 0) - return -1; - memcpy(buf, s->cluster_cache + index_in_cluster * 512, 512 * n); - } else { - BLKDBG_EVENT(bs->file, BLKDBG_READ); - ret = bdrv_pread(bs->file, cluster_offset + index_in_cluster * 512, buf, n * 512); - if (ret != n * 512) - return -1; - if (s->crypt_method) { - qcow2_encrypt_sectors(s, sector_num, buf, buf, n, 0, - &s->aes_decrypt_key); - } - } - nb_sectors -= n; - sector_num += n; - buf += n * 512; + /* + * If this is the last cluster and it is only partially used, we must only + * copy until the end of the image, or bdrv_check_request will fail for the + * bdrv_read/write calls below. + */ + if (start_sect + n_end > bs->total_sectors) { + n_end = bs->total_sectors - start_sect; } - return 0; -} - -static int copy_sectors(BlockDriverState *bs, uint64_t start_sect, - uint64_t cluster_offset, int n_start, int n_end) -{ - BDRVQcowState *s = bs->opaque; - int n, ret; n = n_end - n_start; - if (n <= 0) + if (n <= 0) { return 0; + } + + iov.iov_len = n * BDRV_SECTOR_SIZE; + iov.iov_base = qemu_blockalign(bs, iov.iov_len); + + qemu_iovec_init_external(&qiov, &iov, 1); + BLKDBG_EVENT(bs->file, BLKDBG_COW_READ); - ret = qcow2_read(bs, start_sect + n_start, s->cluster_data, n); - if (ret < 0) - return ret; + + /* Call .bdrv_co_readv() directly instead of using the public block-layer + * interface. This avoids double I/O throttling and request tracking, + * which can lead to deadlock when block layer copy-on-read is enabled. + */ + ret = bs->drv->bdrv_co_readv(bs, start_sect + n_start, n, &qiov); + if (ret < 0) { + goto out; + } + if (s->crypt_method) { qcow2_encrypt_sectors(s, start_sect + n_start, - s->cluster_data, - s->cluster_data, n, 1, + iov.iov_base, iov.iov_base, n, 1, &s->aes_encrypt_key); } + BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE); - ret = bdrv_write(bs->file, (cluster_offset >> 9) + n_start, - s->cluster_data, n); - if (ret < 0) - return ret; - return 0; + ret = bdrv_co_writev(bs->file, (cluster_offset >> 9) + n_start, n, &qiov); + if (ret < 0) { + goto out; + } + + ret = 0; +out: + qemu_vfree(iov.iov_base); + return ret; } @@ -620,7 +593,9 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m) start_sect = (m->offset & ~(s->cluster_size - 1)) >> 9; if (m->n_start) { cow = true; + qemu_co_mutex_unlock(&s->lock); ret = copy_sectors(bs, start_sect, cluster_offset, 0, m->n_start); + qemu_co_mutex_lock(&s->lock); if (ret < 0) goto err; } @@ -628,8 +603,10 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m) if (m->nb_available & (s->cluster_sectors - 1)) { uint64_t end = m->nb_available & ~(uint64_t)(s->cluster_sectors - 1); cow = true; + qemu_co_mutex_unlock(&s->lock); ret = copy_sectors(bs, start_sect + end, cluster_offset + (end << 9), m->nb_available - end, s->cluster_sectors); + qemu_co_mutex_lock(&s->lock); if (ret < 0) goto err; } diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 9605367777..2db2ede3d1 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -700,6 +700,10 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, l2_table = NULL; l1_table = NULL; l1_size2 = l1_size * sizeof(uint64_t); + + /* WARNING: qcow2_snapshot_goto relies on this function not using the + * l1_table_offset when it is the current s->l1_table_offset! Be careful + * when changing this! */ if (l1_table_offset != s->l1_table_offset) { if (l1_size2 != 0) { l1_table = g_malloc0(align_offset(l1_size2, 512)); @@ -819,7 +823,8 @@ fail: qcow2_cache_set_writethrough(bs, s->refcount_block_cache, old_refcount_writethrough); - if (l1_modified) { + /* Update L1 only if it isn't deleted anyway (addend = -1) */ + if (addend >= 0 && l1_modified) { for(i = 0; i < l1_size; i++) cpu_to_be64s(&l1_table[i]); if (bdrv_pwrite_sync(bs->file, l1_table_offset, l1_table, diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index bdc33ba94c..7d3fde5a8a 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -46,6 +46,10 @@ typedef struct QEMU_PACKED QCowSnapshotHeader { /* name follows */ } QCowSnapshotHeader; +typedef struct QEMU_PACKED QCowSnapshotExtraData { + uint64_t vm_state_size_large; +} QCowSnapshotExtraData; + void qcow2_free_snapshots(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; @@ -64,10 +68,12 @@ int qcow2_read_snapshots(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; QCowSnapshotHeader h; + QCowSnapshotExtraData extra; QCowSnapshot *sn; int i, id_str_size, name_size; int64_t offset; uint32_t extra_data_size; + int ret; if (!s->nb_snapshots) { s->snapshots = NULL; @@ -77,10 +83,15 @@ int qcow2_read_snapshots(BlockDriverState *bs) offset = s->snapshots_offset; s->snapshots = g_malloc0(s->nb_snapshots * sizeof(QCowSnapshot)); + for(i = 0; i < s->nb_snapshots; i++) { + /* Read statically sized part of the snapshot header */ offset = align_offset(offset, 8); - if (bdrv_pread(bs->file, offset, &h, sizeof(h)) != sizeof(h)) + ret = bdrv_pread(bs->file, offset, &h, sizeof(h)); + if (ret < 0) { goto fail; + } + offset += sizeof(h); sn = s->snapshots + i; sn->l1_table_offset = be64_to_cpu(h.l1_table_offset); @@ -94,25 +105,43 @@ int qcow2_read_snapshots(BlockDriverState *bs) id_str_size = be16_to_cpu(h.id_str_size); name_size = be16_to_cpu(h.name_size); + /* Read extra data */ + ret = bdrv_pread(bs->file, offset, &extra, + MIN(sizeof(extra), extra_data_size)); + if (ret < 0) { + goto fail; + } offset += extra_data_size; + if (extra_data_size >= 8) { + sn->vm_state_size = be64_to_cpu(extra.vm_state_size_large); + } + + /* Read snapshot ID */ sn->id_str = g_malloc(id_str_size + 1); - if (bdrv_pread(bs->file, offset, sn->id_str, id_str_size) != id_str_size) + ret = bdrv_pread(bs->file, offset, sn->id_str, id_str_size); + if (ret < 0) { goto fail; + } offset += id_str_size; sn->id_str[id_str_size] = '\0'; + /* Read snapshot name */ sn->name = g_malloc(name_size + 1); - if (bdrv_pread(bs->file, offset, sn->name, name_size) != name_size) + ret = bdrv_pread(bs->file, offset, sn->name, name_size); + if (ret < 0) { goto fail; + } offset += name_size; sn->name[name_size] = '\0'; } + s->snapshots_size = offset - s->snapshots_offset; return 0; - fail: + +fail: qcow2_free_snapshots(bs); - return -1; + return ret; } /* add at the end of the file a new list of snapshots */ @@ -121,10 +150,14 @@ static int qcow2_write_snapshots(BlockDriverState *bs) BDRVQcowState *s = bs->opaque; QCowSnapshot *sn; QCowSnapshotHeader h; + QCowSnapshotExtraData extra; int i, name_size, id_str_size, snapshots_size; - uint64_t data64; - uint32_t data32; + struct { + uint32_t nb_snapshots; + uint64_t snapshots_offset; + } QEMU_PACKED header_data; int64_t offset, snapshots_offset; + int ret; /* compute the size of the snapshots */ offset = 0; @@ -132,11 +165,13 @@ static int qcow2_write_snapshots(BlockDriverState *bs) sn = s->snapshots + i; offset = align_offset(offset, 8); offset += sizeof(h); + offset += sizeof(extra); offset += strlen(sn->id_str); offset += strlen(sn->name); } snapshots_size = offset; + /* Allocate space for the new snapshot list */ snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size); bdrv_flush(bs->file); offset = snapshots_offset; @@ -144,49 +179,85 @@ static int qcow2_write_snapshots(BlockDriverState *bs) return offset; } + /* Write all snapshots to the new list */ for(i = 0; i < s->nb_snapshots; i++) { sn = s->snapshots + i; memset(&h, 0, sizeof(h)); h.l1_table_offset = cpu_to_be64(sn->l1_table_offset); h.l1_size = cpu_to_be32(sn->l1_size); - h.vm_state_size = cpu_to_be32(sn->vm_state_size); + /* If it doesn't fit in 32 bit, older implementations should treat it + * as a disk-only snapshot rather than truncate the VM state */ + if (sn->vm_state_size <= 0xffffffff) { + h.vm_state_size = cpu_to_be32(sn->vm_state_size); + } h.date_sec = cpu_to_be32(sn->date_sec); h.date_nsec = cpu_to_be32(sn->date_nsec); h.vm_clock_nsec = cpu_to_be64(sn->vm_clock_nsec); + h.extra_data_size = cpu_to_be32(sizeof(extra)); + + memset(&extra, 0, sizeof(extra)); + extra.vm_state_size_large = cpu_to_be64(sn->vm_state_size); id_str_size = strlen(sn->id_str); name_size = strlen(sn->name); h.id_str_size = cpu_to_be16(id_str_size); h.name_size = cpu_to_be16(name_size); offset = align_offset(offset, 8); - if (bdrv_pwrite_sync(bs->file, offset, &h, sizeof(h)) < 0) + + ret = bdrv_pwrite(bs->file, offset, &h, sizeof(h)); + if (ret < 0) { goto fail; + } offset += sizeof(h); - if (bdrv_pwrite_sync(bs->file, offset, sn->id_str, id_str_size) < 0) + + ret = bdrv_pwrite(bs->file, offset, &extra, sizeof(extra)); + if (ret < 0) { goto fail; + } + offset += sizeof(extra); + + ret = bdrv_pwrite(bs->file, offset, sn->id_str, id_str_size); + if (ret < 0) { + goto fail; + } offset += id_str_size; - if (bdrv_pwrite_sync(bs->file, offset, sn->name, name_size) < 0) + + ret = bdrv_pwrite(bs->file, offset, sn->name, name_size); + if (ret < 0) { goto fail; + } offset += name_size; } - /* update the various header fields */ - data64 = cpu_to_be64(snapshots_offset); - if (bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, snapshots_offset), - &data64, sizeof(data64)) < 0) + /* + * Update the header to point to the new snapshot table. This requires the + * new table and its refcounts to be stable on disk. + */ + ret = bdrv_flush(bs); + if (ret < 0) { goto fail; - data32 = cpu_to_be32(s->nb_snapshots); - if (bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), - &data32, sizeof(data32)) < 0) + } + + QEMU_BUILD_BUG_ON(offsetof(QCowHeader, snapshots_offset) != + offsetof(QCowHeader, nb_snapshots) + sizeof(header_data.nb_snapshots)); + + header_data.nb_snapshots = cpu_to_be32(s->nb_snapshots); + header_data.snapshots_offset = cpu_to_be64(snapshots_offset); + + ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), + &header_data, sizeof(header_data)); + if (ret < 0) { goto fail; + } /* free the old snapshot table */ qcow2_free_clusters(bs, s->snapshots_offset, s->snapshots_size); s->snapshots_offset = snapshots_offset; s->snapshots_size = snapshots_size; return 0; - fail: - return -1; + +fail: + return ret; } static void find_new_snapshot_id(BlockDriverState *bs, @@ -236,72 +307,92 @@ static int find_snapshot_by_id_or_name(BlockDriverState *bs, const char *name) int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) { BDRVQcowState *s = bs->opaque; - QCowSnapshot *snapshots1, sn1, *sn = &sn1; + QCowSnapshot *new_snapshot_list = NULL; + QCowSnapshot *old_snapshot_list = NULL; + QCowSnapshot sn1, *sn = &sn1; int i, ret; uint64_t *l1_table = NULL; int64_t l1_table_offset; memset(sn, 0, sizeof(*sn)); + /* Generate an ID if it wasn't passed */ if (sn_info->id_str[0] == '\0') { - /* compute a new id */ find_new_snapshot_id(bs, sn_info->id_str, sizeof(sn_info->id_str)); } - /* check that the ID is unique */ - if (find_snapshot_by_id(bs, sn_info->id_str) >= 0) + /* Check that the ID is unique */ + if (find_snapshot_by_id(bs, sn_info->id_str) >= 0) { return -ENOENT; + } + /* Populate sn with passed data */ sn->id_str = g_strdup(sn_info->id_str); - if (!sn->id_str) - goto fail; sn->name = g_strdup(sn_info->name); - if (!sn->name) - goto fail; + sn->vm_state_size = sn_info->vm_state_size; sn->date_sec = sn_info->date_sec; sn->date_nsec = sn_info->date_nsec; sn->vm_clock_nsec = sn_info->vm_clock_nsec; - ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1); - if (ret < 0) - goto fail; - - /* create the L1 table of the snapshot */ + /* Allocate the L1 table of the snapshot and copy the current one there. */ l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t)); if (l1_table_offset < 0) { + ret = l1_table_offset; goto fail; } - bdrv_flush(bs->file); sn->l1_table_offset = l1_table_offset; sn->l1_size = s->l1_size; - if (s->l1_size != 0) { - l1_table = g_malloc(s->l1_size * sizeof(uint64_t)); - } else { - l1_table = NULL; - } - + l1_table = g_malloc(s->l1_size * sizeof(uint64_t)); for(i = 0; i < s->l1_size; i++) { l1_table[i] = cpu_to_be64(s->l1_table[i]); } - if (bdrv_pwrite_sync(bs->file, sn->l1_table_offset, - l1_table, s->l1_size * sizeof(uint64_t)) < 0) + + ret = bdrv_pwrite(bs->file, sn->l1_table_offset, l1_table, + s->l1_size * sizeof(uint64_t)); + if (ret < 0) { goto fail; + } + g_free(l1_table); l1_table = NULL; - snapshots1 = g_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot)); + /* + * Increase the refcounts of all clusters and make sure everything is + * stable on disk before updating the snapshot table to contain a pointer + * to the new L1 table. + */ + ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1); + if (ret < 0) { + goto fail; + } + + ret = bdrv_flush(bs); + if (ret < 0) { + goto fail; + } + + /* Append the new snapshot to the snapshot list */ + new_snapshot_list = g_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot)); if (s->snapshots) { - memcpy(snapshots1, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot)); - g_free(s->snapshots); + memcpy(new_snapshot_list, s->snapshots, + s->nb_snapshots * sizeof(QCowSnapshot)); + old_snapshot_list = s->snapshots; } - s->snapshots = snapshots1; + s->snapshots = new_snapshot_list; s->snapshots[s->nb_snapshots++] = *sn; - if (qcow2_write_snapshots(bs) < 0) + ret = qcow2_write_snapshots(bs); + if (ret < 0) { + g_free(s->snapshots); + s->snapshots = old_snapshot_list; goto fail; + } + + g_free(old_snapshot_list); + #ifdef DEBUG_ALLOC { BdrvCheckResult result = {0}; @@ -309,10 +400,13 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) } #endif return 0; - fail: + +fail: + g_free(sn->id_str); g_free(sn->name); g_free(l1_table); - return -1; + + return ret; } /* copy the snapshot 'snapshot_name' into the current disk image */ @@ -322,38 +416,92 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) QCowSnapshot *sn; int i, snapshot_index; int cur_l1_bytes, sn_l1_bytes; + int ret; + uint64_t *sn_l1_table = NULL; + /* Search the snapshot */ snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id); - if (snapshot_index < 0) + if (snapshot_index < 0) { return -ENOENT; + } sn = &s->snapshots[snapshot_index]; - if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, -1) < 0) - goto fail; - - if (qcow2_grow_l1_table(bs, sn->l1_size, true) < 0) + /* + * Make sure that the current L1 table is big enough to contain the whole + * L1 table of the snapshot. If the snapshot L1 table is smaller, the + * current one must be padded with zeros. + */ + ret = qcow2_grow_l1_table(bs, sn->l1_size, true); + if (ret < 0) { goto fail; + } cur_l1_bytes = s->l1_size * sizeof(uint64_t); sn_l1_bytes = sn->l1_size * sizeof(uint64_t); - if (cur_l1_bytes > sn_l1_bytes) { - memset(s->l1_table + sn->l1_size, 0, cur_l1_bytes - sn_l1_bytes); + /* + * Copy the snapshot L1 table to the current L1 table. + * + * Before overwriting the old current L1 table on disk, make sure to + * increase all refcounts for the clusters referenced by the new one. + * Decrease the refcount referenced by the old one only when the L1 + * table is overwritten. + */ + sn_l1_table = g_malloc0(cur_l1_bytes); + + ret = bdrv_pread(bs->file, sn->l1_table_offset, sn_l1_table, sn_l1_bytes); + if (ret < 0) { + goto fail; } - /* copy the snapshot l1 table to the current l1 table */ - if (bdrv_pread(bs->file, sn->l1_table_offset, - s->l1_table, sn_l1_bytes) < 0) + ret = qcow2_update_snapshot_refcount(bs, sn->l1_table_offset, + sn->l1_size, 1); + if (ret < 0) { goto fail; - if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, - s->l1_table, cur_l1_bytes) < 0) + } + + ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset, sn_l1_table, + cur_l1_bytes); + if (ret < 0) { goto fail; + } + + /* + * Decrease refcount of clusters of current L1 table. + * + * At this point, the in-memory s->l1_table points to the old L1 table, + * whereas on disk we already have the new one. + * + * qcow2_update_snapshot_refcount special cases the current L1 table to use + * the in-memory data instead of really using the offset to load a new one, + * which is why this works. + */ + ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, + s->l1_size, -1); + + /* + * Now update the in-memory L1 table to be in sync with the on-disk one. We + * need to do this even if updating refcounts failed. + */ for(i = 0;i < s->l1_size; i++) { - be64_to_cpus(&s->l1_table[i]); + s->l1_table[i] = be64_to_cpu(sn_l1_table[i]); } - if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1) < 0) + if (ret < 0) { + goto fail; + } + + g_free(sn_l1_table); + sn_l1_table = NULL; + + /* + * Update QCOW_OFLAG_COPIED in the active L1 table (it may have changed + * when we decreased the refcount of the old snapshot. + */ + ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0); + if (ret < 0) { goto fail; + } #ifdef DEBUG_ALLOC { @@ -362,39 +510,59 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) } #endif return 0; - fail: - return -EIO; + +fail: + g_free(sn_l1_table); + return ret; } int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id) { BDRVQcowState *s = bs->opaque; - QCowSnapshot *sn; + QCowSnapshot sn; int snapshot_index, ret; + /* Search the snapshot */ snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id); - if (snapshot_index < 0) + if (snapshot_index < 0) { return -ENOENT; - sn = &s->snapshots[snapshot_index]; + } + sn = s->snapshots[snapshot_index]; - ret = qcow2_update_snapshot_refcount(bs, sn->l1_table_offset, sn->l1_size, -1); - if (ret < 0) + /* Remove it from the snapshot list */ + memmove(s->snapshots + snapshot_index, + s->snapshots + snapshot_index + 1, + (s->nb_snapshots - snapshot_index - 1) * sizeof(sn)); + s->nb_snapshots--; + ret = qcow2_write_snapshots(bs); + if (ret < 0) { return ret; - /* must update the copied flag on the current cluster offsets */ - ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0); - if (ret < 0) + } + + /* + * The snapshot is now unused, clean up. If we fail after this point, we + * won't recover but just leak clusters. + */ + g_free(sn.id_str); + g_free(sn.name); + + /* + * Now decrease the refcounts of clusters referenced by the snapshot and + * free the L1 table. + */ + ret = qcow2_update_snapshot_refcount(bs, sn.l1_table_offset, + sn.l1_size, -1); + if (ret < 0) { return ret; - qcow2_free_clusters(bs, sn->l1_table_offset, sn->l1_size * sizeof(uint64_t)); + } + qcow2_free_clusters(bs, sn.l1_table_offset, sn.l1_size * sizeof(uint64_t)); - g_free(sn->id_str); - g_free(sn->name); - memmove(sn, sn + 1, (s->nb_snapshots - snapshot_index - 1) * sizeof(*sn)); - s->nb_snapshots--; - ret = qcow2_write_snapshots(bs); + /* must update the copied flag on the current cluster offsets */ + ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0); if (ret < 0) { - /* XXX: restore snapshot if error ? */ return ret; } + #ifdef DEBUG_ALLOC { BdrvCheckResult result = {0}; @@ -435,32 +603,42 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name) { - int i, snapshot_index, l1_size2; + int i, snapshot_index; BDRVQcowState *s = bs->opaque; QCowSnapshot *sn; + uint64_t *new_l1_table; + int new_l1_bytes; + int ret; + assert(bs->read_only); + + /* Search the snapshot */ snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_name); if (snapshot_index < 0) { return -ENOENT; } - sn = &s->snapshots[snapshot_index]; - s->l1_size = sn->l1_size; - l1_size2 = s->l1_size * sizeof(uint64_t); - if (s->l1_table != NULL) { - g_free(s->l1_table); - } - s->l1_table_offset = sn->l1_table_offset; - s->l1_table = g_malloc0(align_offset(l1_size2, 512)); + /* Allocate and read in the snapshot's L1 table */ + new_l1_bytes = s->l1_size * sizeof(uint64_t); + new_l1_table = g_malloc0(align_offset(new_l1_bytes, 512)); - if (bdrv_pread(bs->file, sn->l1_table_offset, - s->l1_table, l1_size2) != l1_size2) { - return -1; + ret = bdrv_pread(bs->file, sn->l1_table_offset, new_l1_table, new_l1_bytes); + if (ret < 0) { + g_free(new_l1_table); + return ret; } + /* Switch the L1 table */ + g_free(s->l1_table); + + s->l1_size = sn->l1_size; + s->l1_table_offset = sn->l1_table_offset; + s->l1_table = new_l1_table; + for(i = 0;i < s->l1_size; i++) { be64_to_cpus(&s->l1_table[i]); } + return 0; } diff --git a/block/qcow2.c b/block/qcow2.c index d7805ce943..aa32e8d01a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -92,7 +92,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, if (offset > s->cluster_size) printf("qcow2_read_extension: suspicious offset %lu\n", offset); - printf("attemting to read extended header in offset %lu\n", offset); + printf("attempting to read extended header in offset %lu\n", offset); #endif if (bdrv_pread(bs->file, offset, &ext, sizeof(ext)) != sizeof(ext)) { @@ -273,8 +273,9 @@ static int qcow2_open(BlockDriverState *bs, int flags) } bs->backing_file[len] = '\0'; } - if (qcow2_read_snapshots(bs) < 0) { - ret = -EINVAL; + + ret = qcow2_read_snapshots(bs); + if (ret < 0) { goto fail; } @@ -343,16 +344,19 @@ static int qcow2_set_key(BlockDriverState *bs, const char *key) return 0; } -static int qcow2_is_allocated(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *pnum) +static int coroutine_fn qcow2_co_is_allocated(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, int *pnum) { + BDRVQcowState *s = bs->opaque; uint64_t cluster_offset; int ret; *pnum = nb_sectors; - /* FIXME We can get errors here, but the bdrv_is_allocated interface can't - * pass them on today */ + /* FIXME We can get errors here, but the bdrv_co_is_allocated interface + * can't pass them on today */ + qemu_co_mutex_lock(&s->lock); ret = qcow2_get_cluster_offset(bs, sector_num << 9, pnum, &cluster_offset); + qemu_co_mutex_unlock(&s->lock); if (ret < 0) { *pnum = 0; } @@ -377,7 +381,7 @@ int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov, return n1; } -static int qcow2_co_readv(BlockDriverState *bs, int64_t sector_num, +static coroutine_fn int qcow2_co_readv(BlockDriverState *bs, int64_t sector_num, int remaining_sectors, QEMUIOVector *qiov) { BDRVQcowState *s = bs->opaque; @@ -512,12 +516,12 @@ static void run_dependent_requests(BDRVQcowState *s, QCowL2Meta *m) /* Restart all dependent requests */ if (!qemu_co_queue_empty(&m->dependent_requests)) { qemu_co_mutex_unlock(&s->lock); - while(qemu_co_queue_next(&m->dependent_requests)); + qemu_co_queue_restart_all(&m->dependent_requests); qemu_co_mutex_lock(&s->lock); } } -static int qcow2_co_writev(BlockDriverState *bs, +static coroutine_fn int qcow2_co_writev(BlockDriverState *bs, int64_t sector_num, int remaining_sectors, QEMUIOVector *qiov) @@ -631,6 +635,7 @@ static void qcow2_close(BlockDriverState *bs) g_free(s->cluster_cache); qemu_vfree(s->cluster_data); qcow2_refcount_close(bs); + qcow2_free_snapshots(bs); } static void qcow2_invalidate_cache(BlockDriverState *bs) @@ -821,7 +826,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, int flags, size_t cluster_size, int prealloc, QEMUOptionParameter *options) { - /* Calulate cluster_bits */ + /* Calculate cluster_bits */ int cluster_bits; cluster_bits = ffs(cluster_size) - 1; if (cluster_bits < MIN_CLUSTER_BITS || cluster_bits > MAX_CLUSTER_BITS || @@ -1137,7 +1142,7 @@ fail: return ret; } -static int qcow2_co_flush_to_os(BlockDriverState *bs) +static coroutine_fn int qcow2_co_flush_to_os(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; int ret; @@ -1159,7 +1164,7 @@ static int qcow2_co_flush_to_os(BlockDriverState *bs) return 0; } -static int qcow2_co_flush_to_disk(BlockDriverState *bs) +static coroutine_fn int qcow2_co_flush_to_disk(BlockDriverState *bs) { return bdrv_co_flush(bs->file); } @@ -1276,7 +1281,7 @@ static BlockDriver bdrv_qcow2 = { .bdrv_open = qcow2_open, .bdrv_close = qcow2_close, .bdrv_create = qcow2_create, - .bdrv_is_allocated = qcow2_is_allocated, + .bdrv_co_is_allocated = qcow2_co_is_allocated, .bdrv_set_key = qcow2_set_key, .bdrv_make_empty = qcow2_make_empty, diff --git a/block/qcow2.h b/block/qcow2.h index 4e44eea5ef..99e45361f5 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -78,7 +78,7 @@ typedef struct QCowSnapshot { uint32_t l1_size; char *id_str; char *name; - uint32_t vm_state_size; + uint64_t vm_state_size; uint32_t date_sec; uint32_t date_nsec; uint64_t vm_clock_nsec; diff --git a/block/qed-table.c b/block/qed-table.c index f31f9ff069..ce07b05549 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -29,7 +29,7 @@ static void qed_read_table_cb(void *opaque, int ret) { QEDReadTableCB *read_table_cb = opaque; QEDTable *table = read_table_cb->table; - int noffsets = read_table_cb->iov.iov_len / sizeof(uint64_t); + int noffsets = read_table_cb->qiov.size / sizeof(uint64_t); int i; /* Handle I/O error */ @@ -54,7 +54,6 @@ static void qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *table, QEDReadTableCB *read_table_cb = gencb_alloc(sizeof(*read_table_cb), cb, opaque); QEMUIOVector *qiov = &read_table_cb->qiov; - BlockDriverAIOCB *aiocb; trace_qed_read_table(s, offset, table); @@ -64,12 +63,9 @@ static void qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *table, read_table_cb->iov.iov_len = s->header.cluster_size * s->header.table_size, qemu_iovec_init_external(qiov, &read_table_cb->iov, 1); - aiocb = bdrv_aio_readv(s->bs->file, offset / BDRV_SECTOR_SIZE, qiov, - read_table_cb->iov.iov_len / BDRV_SECTOR_SIZE, - qed_read_table_cb, read_table_cb); - if (!aiocb) { - qed_read_table_cb(read_table_cb, -EIO); - } + bdrv_aio_readv(s->bs->file, offset / BDRV_SECTOR_SIZE, qiov, + qiov->size / BDRV_SECTOR_SIZE, + qed_read_table_cb, read_table_cb); } typedef struct { @@ -127,7 +123,6 @@ static void qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table, BlockDriverCompletionFunc *cb, void *opaque) { QEDWriteTableCB *write_table_cb; - BlockDriverAIOCB *aiocb; unsigned int sector_mask = BDRV_SECTOR_SIZE / sizeof(uint64_t) - 1; unsigned int start, end, i; size_t len_bytes; @@ -158,13 +153,10 @@ static void qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table, /* Adjust for offset into table */ offset += start * sizeof(uint64_t); - aiocb = bdrv_aio_writev(s->bs->file, offset / BDRV_SECTOR_SIZE, - &write_table_cb->qiov, - write_table_cb->iov.iov_len / BDRV_SECTOR_SIZE, - qed_write_table_cb, write_table_cb); - if (!aiocb) { - qed_write_table_cb(write_table_cb, -EIO); - } + bdrv_aio_writev(s->bs->file, offset / BDRV_SECTOR_SIZE, + &write_table_cb->qiov, + write_table_cb->qiov.size / BDRV_SECTOR_SIZE, + qed_write_table_cb, write_table_cb); } /** diff --git a/block/qed.c b/block/qed.c index 7e22e77b9d..8da3ebe9d4 100644 --- a/block/qed.c +++ b/block/qed.c @@ -123,7 +123,6 @@ static void qed_write_header_read_cb(void *opaque, int ret) { QEDWriteHeaderCB *write_header_cb = opaque; BDRVQEDState *s = write_header_cb->s; - BlockDriverAIOCB *acb; if (ret) { qed_write_header_cb(write_header_cb, ret); @@ -133,12 +132,9 @@ static void qed_write_header_read_cb(void *opaque, int ret) /* Update header */ qed_header_cpu_to_le(&s->header, (QEDHeader *)write_header_cb->buf); - acb = bdrv_aio_writev(s->bs->file, 0, &write_header_cb->qiov, - write_header_cb->nsectors, qed_write_header_cb, - write_header_cb); - if (!acb) { - qed_write_header_cb(write_header_cb, -EIO); - } + bdrv_aio_writev(s->bs->file, 0, &write_header_cb->qiov, + write_header_cb->nsectors, qed_write_header_cb, + write_header_cb); } /** @@ -156,7 +152,6 @@ static void qed_write_header(BDRVQEDState *s, BlockDriverCompletionFunc cb, * them, and write back. */ - BlockDriverAIOCB *acb; int nsectors = (sizeof(QEDHeader) + BDRV_SECTOR_SIZE - 1) / BDRV_SECTOR_SIZE; size_t len = nsectors * BDRV_SECTOR_SIZE; @@ -170,11 +165,8 @@ static void qed_write_header(BDRVQEDState *s, BlockDriverCompletionFunc cb, write_header_cb->iov.iov_len = len; qemu_iovec_init_external(&write_header_cb->qiov, &write_header_cb->iov, 1); - acb = bdrv_aio_readv(s->bs->file, 0, &write_header_cb->qiov, nsectors, - qed_write_header_read_cb, write_header_cb); - if (!acb) { - qed_write_header_cb(write_header_cb, -EIO); - } + bdrv_aio_readv(s->bs->file, 0, &write_header_cb->qiov, nsectors, + qed_write_header_read_cb, write_header_cb); } static uint64_t qed_max_image_size(uint32_t cluster_size, uint32_t table_size) @@ -661,6 +653,7 @@ static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options) } typedef struct { + Coroutine *co; int is_allocated; int *pnum; } QEDIsAllocatedCB; @@ -670,10 +663,14 @@ static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, size_t l QEDIsAllocatedCB *cb = opaque; *cb->pnum = len / BDRV_SECTOR_SIZE; cb->is_allocated = (ret == QED_CLUSTER_FOUND || ret == QED_CLUSTER_ZERO); + if (cb->co) { + qemu_coroutine_enter(cb->co, NULL); + } } -static int bdrv_qed_is_allocated(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *pnum) +static int coroutine_fn bdrv_qed_co_is_allocated(BlockDriverState *bs, + int64_t sector_num, + int nb_sectors, int *pnum) { BDRVQEDState *s = bs->opaque; uint64_t pos = (uint64_t)sector_num * BDRV_SECTOR_SIZE; @@ -686,8 +683,10 @@ static int bdrv_qed_is_allocated(BlockDriverState *bs, int64_t sector_num, qed_find_cluster(s, &request, pos, len, qed_is_allocated_cb, &cb); + /* Now sleep if the callback wasn't invoked immediately */ while (cb.is_allocated == -1) { - qemu_aio_wait(); + cb.co = qemu_coroutine_self(); + qemu_coroutine_yield(); } qed_unref_l2_cache_entry(request.l2_table); @@ -721,7 +720,6 @@ static void qed_read_backing_file(BDRVQEDState *s, uint64_t pos, QEMUIOVector *qiov, BlockDriverCompletionFunc *cb, void *opaque) { - BlockDriverAIOCB *aiocb; uint64_t backing_length = 0; size_t size; @@ -753,11 +751,8 @@ static void qed_read_backing_file(BDRVQEDState *s, uint64_t pos, size = MIN((uint64_t)backing_length - pos, qiov->size); BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING); - aiocb = bdrv_aio_readv(s->bs->backing_hd, pos / BDRV_SECTOR_SIZE, - qiov, size / BDRV_SECTOR_SIZE, cb, opaque); - if (!aiocb) { - cb(opaque, -EIO); - } + bdrv_aio_readv(s->bs->backing_hd, pos / BDRV_SECTOR_SIZE, + qiov, size / BDRV_SECTOR_SIZE, cb, opaque); } typedef struct { @@ -779,7 +774,6 @@ static void qed_copy_from_backing_file_write(void *opaque, int ret) { CopyFromBackingFileCB *copy_cb = opaque; BDRVQEDState *s = copy_cb->s; - BlockDriverAIOCB *aiocb; if (ret) { qed_copy_from_backing_file_cb(copy_cb, ret); @@ -787,13 +781,9 @@ static void qed_copy_from_backing_file_write(void *opaque, int ret) } BLKDBG_EVENT(s->bs->file, BLKDBG_COW_WRITE); - aiocb = bdrv_aio_writev(s->bs->file, copy_cb->offset / BDRV_SECTOR_SIZE, - ©_cb->qiov, - copy_cb->qiov.size / BDRV_SECTOR_SIZE, - qed_copy_from_backing_file_cb, copy_cb); - if (!aiocb) { - qed_copy_from_backing_file_cb(copy_cb, -EIO); - } + bdrv_aio_writev(s->bs->file, copy_cb->offset / BDRV_SECTOR_SIZE, + ©_cb->qiov, copy_cb->qiov.size / BDRV_SECTOR_SIZE, + qed_copy_from_backing_file_cb, copy_cb); } /** @@ -1015,7 +1005,6 @@ static void qed_aio_write_main(void *opaque, int ret) uint64_t offset = acb->cur_cluster + qed_offset_into_cluster(s, acb->cur_pos); BlockDriverCompletionFunc *next_fn; - BlockDriverAIOCB *file_acb; trace_qed_aio_write_main(s, acb, ret, offset, acb->cur_qiov.size); @@ -1035,13 +1024,9 @@ static void qed_aio_write_main(void *opaque, int ret) } BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO); - file_acb = bdrv_aio_writev(s->bs->file, offset / BDRV_SECTOR_SIZE, - &acb->cur_qiov, - acb->cur_qiov.size / BDRV_SECTOR_SIZE, - next_fn, acb); - if (!file_acb) { - qed_aio_complete(acb, -EIO); - } + bdrv_aio_writev(s->bs->file, offset / BDRV_SECTOR_SIZE, + &acb->cur_qiov, acb->cur_qiov.size / BDRV_SECTOR_SIZE, + next_fn, acb); } /** @@ -1208,7 +1193,6 @@ static void qed_aio_read_data(void *opaque, int ret, QEDAIOCB *acb = opaque; BDRVQEDState *s = acb_to_s(acb); BlockDriverState *bs = acb->common.bs; - BlockDriverAIOCB *file_acb; /* Adjust offset into cluster */ offset += qed_offset_into_cluster(s, acb->cur_pos); @@ -1233,14 +1217,9 @@ static void qed_aio_read_data(void *opaque, int ret, } BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - file_acb = bdrv_aio_readv(bs->file, offset / BDRV_SECTOR_SIZE, - &acb->cur_qiov, - acb->cur_qiov.size / BDRV_SECTOR_SIZE, - qed_aio_next_io, acb); - if (!file_acb) { - ret = -EIO; - goto err; - } + bdrv_aio_readv(bs->file, offset / BDRV_SECTOR_SIZE, + &acb->cur_qiov, acb->cur_qiov.size / BDRV_SECTOR_SIZE, + qed_aio_next_io, acb); return; err: @@ -1485,7 +1464,7 @@ static BlockDriver bdrv_qed = { .bdrv_open = bdrv_qed_open, .bdrv_close = bdrv_qed_close, .bdrv_create = bdrv_qed_create, - .bdrv_is_allocated = bdrv_qed_is_allocated, + .bdrv_co_is_allocated = bdrv_qed_co_is_allocated, .bdrv_make_empty = bdrv_qed_make_empty, .bdrv_aio_readv = bdrv_qed_aio_readv, .bdrv_aio_writev = bdrv_qed_aio_writev, diff --git a/block/raw-posix.c b/block/raw-posix.c index a3de373586..2ee5d690e9 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1153,7 +1153,7 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, int flags) if (ret) return ret; - /* make sure the door isnt locked at this time */ + /* make sure the door isn't locked at this time */ ioctl(s->fd, CDIOCALLOW); return 0; } @@ -1184,7 +1184,7 @@ static int cdrom_reopen(BlockDriverState *bs) } s->fd = fd; - /* make sure the door isnt locked at this time */ + /* make sure the door isn't locked at this time */ ioctl(s->fd, CDIOCALLOW); return 0; } diff --git a/block/rbd.c b/block/rbd.c index 9088c52d24..7a2384c8f9 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -632,9 +632,6 @@ static BlockDriverAIOCB *rbd_aio_rw_vector(BlockDriverState *bs, BDRVRBDState *s = bs->opaque; acb = qemu_aio_get(&rbd_aio_pool, bs, cb, opaque); - if (!acb) { - return NULL; - } acb->write = write; acb->qiov = qiov; acb->bounce = qemu_blockalign(bs, qiov->size); @@ -808,7 +805,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs, } while (snap_count == -ERANGE); if (snap_count <= 0) { - return snap_count; + goto done; } sn_tab = g_malloc0(snap_count * sizeof(QEMUSnapshotInfo)); @@ -827,6 +824,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs, } rbd_snap_list_end(snaps); + done: *psn_tab = sn_tab; return snap_count; } diff --git a/block/sheepdog.c b/block/sheepdog.c index 9f8060960f..aa9707f2ae 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1116,6 +1116,7 @@ static int coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req, /* send a header */ ret = do_write(s->fd, &hdr, sizeof(hdr)); if (ret) { + qemu_co_mutex_unlock(&s->lock); error_report("failed to send a req, %s", strerror(errno)); return -EIO; } @@ -1123,6 +1124,7 @@ static int coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req, if (wlen) { ret = do_writev(s->fd, iov, wlen, aio_req->iov_offset); if (ret) { + qemu_co_mutex_unlock(&s->lock); error_report("failed to send a data, %s", strerror(errno)); return -EIO; } @@ -1713,7 +1715,7 @@ out: return 1; } -static int sd_co_writev(BlockDriverState *bs, int64_t sector_num, +static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { SheepdogAIOCB *acb; @@ -1742,7 +1744,7 @@ static int sd_co_writev(BlockDriverState *bs, int64_t sector_num, return acb->ret; } -static int sd_co_readv(BlockDriverState *bs, int64_t sector_num, +static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { SheepdogAIOCB *acb; diff --git a/block/vdi.c b/block/vdi.c index 684a4a87b6..31cdfabdea 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -52,6 +52,7 @@ #include "qemu-common.h" #include "block_int.h" #include "module.h" +#include "migration.h" #if defined(CONFIG_UUID) #include <uuid/uuid.h> @@ -203,6 +204,8 @@ typedef struct { uint32_t bmap_sector; /* VDI header (converted to host endianness). */ VdiHeader header; + + Error *migration_blocker; } BDRVVdiState; /* Change UUID from little endian (IPRT = VirtualBox format) to big endian @@ -454,6 +457,12 @@ static int vdi_open(BlockDriverState *bs, int flags) goto fail_free_bmap; } + /* Disable migration when vdi images are used */ + error_set(&s->migration_blocker, + QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, + "vdi", bs->device_name, "live migration"); + migrate_add_blocker(s->migration_blocker); + return 0; fail_free_bmap: @@ -463,8 +472,8 @@ static int vdi_open(BlockDriverState *bs, int flags) return -1; } -static int vdi_is_allocated(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *pnum) +static int coroutine_fn vdi_co_is_allocated(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, int *pnum) { /* TODO: Check for too large sector_num (in bdrv_is_allocated or here). */ BDRVVdiState *s = (BDRVVdiState *)bs->opaque; @@ -506,28 +515,26 @@ static VdiAIOCB *vdi_aio_setup(BlockDriverState *bs, int64_t sector_num, bs, sector_num, qiov, nb_sectors, cb, opaque, is_write); acb = qemu_aio_get(&vdi_aio_pool, bs, cb, opaque); - if (acb) { - acb->hd_aiocb = NULL; - acb->sector_num = sector_num; - acb->qiov = qiov; - acb->is_write = is_write; - - if (qiov->niov > 1) { - acb->buf = qemu_blockalign(bs, qiov->size); - acb->orig_buf = acb->buf; - if (is_write) { - qemu_iovec_to_buffer(qiov, acb->buf); - } - } else { - acb->buf = (uint8_t *)qiov->iov->iov_base; + acb->hd_aiocb = NULL; + acb->sector_num = sector_num; + acb->qiov = qiov; + acb->is_write = is_write; + + if (qiov->niov > 1) { + acb->buf = qemu_blockalign(bs, qiov->size); + acb->orig_buf = acb->buf; + if (is_write) { + qemu_iovec_to_buffer(qiov, acb->buf); } - acb->nb_sectors = nb_sectors; - acb->n_sectors = 0; - acb->bmap_first = VDI_UNALLOCATED; - acb->bmap_last = VDI_UNALLOCATED; - acb->block_buffer = NULL; - acb->header_modified = 0; - } + } else { + acb->buf = (uint8_t *)qiov->iov->iov_base; + } + acb->nb_sectors = nb_sectors; + acb->n_sectors = 0; + acb->bmap_first = VDI_UNALLOCATED; + acb->bmap_last = VDI_UNALLOCATED; + acb->block_buffer = NULL; + acb->header_modified = 0; return acb; } @@ -624,10 +631,6 @@ static void vdi_aio_read_cb(void *opaque, int ret) qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); acb->hd_aiocb = bdrv_aio_readv(bs->file, offset, &acb->hd_qiov, n_sectors, vdi_aio_read_cb, acb); - if (acb->hd_aiocb == NULL) { - ret = -EIO; - goto done; - } } return; done: @@ -648,10 +651,6 @@ static BlockDriverAIOCB *vdi_aio_readv(BlockDriverState *bs, logout("\n"); acb = vdi_aio_setup(bs, sector_num, qiov, nb_sectors, cb, opaque, 0); - if (!acb) { - return NULL; - } - ret = vdi_schedule_bh(vdi_aio_rw_bh, acb); if (ret < 0) { if (acb->qiov->niov > 1) { @@ -699,10 +698,6 @@ static void vdi_aio_write_cb(void *opaque, int ret) qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); acb->hd_aiocb = bdrv_aio_writev(bs->file, 0, &acb->hd_qiov, 1, vdi_aio_write_cb, acb); - if (acb->hd_aiocb == NULL) { - ret = -EIO; - goto done; - } return; } else if (VDI_IS_ALLOCATED(acb->bmap_first)) { /* One or more new blocks were allocated. */ @@ -729,10 +724,6 @@ static void vdi_aio_write_cb(void *opaque, int ret) n_sectors, bmap_first); acb->hd_aiocb = bdrv_aio_writev(bs->file, offset, &acb->hd_qiov, n_sectors, vdi_aio_write_cb, acb); - if (acb->hd_aiocb == NULL) { - ret = -EIO; - goto done; - } return; } ret = 0; @@ -780,10 +771,6 @@ static void vdi_aio_write_cb(void *opaque, int ret) acb->hd_aiocb = bdrv_aio_writev(bs->file, offset, &acb->hd_qiov, s->block_sectors, vdi_aio_write_cb, acb); - if (acb->hd_aiocb == NULL) { - ret = -EIO; - goto done; - } } else { uint64_t offset = s->header.offset_data / SECTOR_SIZE + (uint64_t)bmap_entry * s->block_sectors + @@ -793,10 +780,6 @@ static void vdi_aio_write_cb(void *opaque, int ret) qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); acb->hd_aiocb = bdrv_aio_writev(bs->file, offset, &acb->hd_qiov, n_sectors, vdi_aio_write_cb, acb); - if (acb->hd_aiocb == NULL) { - ret = -EIO; - goto done; - } } return; @@ -818,10 +801,6 @@ static BlockDriverAIOCB *vdi_aio_writev(BlockDriverState *bs, logout("\n"); acb = vdi_aio_setup(bs, sector_num, qiov, nb_sectors, cb, opaque, 1); - if (!acb) { - return NULL; - } - ret = vdi_schedule_bh(vdi_aio_rw_bh, acb); if (ret < 0) { if (acb->qiov->niov > 1) { @@ -939,6 +918,12 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options) static void vdi_close(BlockDriverState *bs) { + BDRVVdiState *s = bs->opaque; + + g_free(s->bmap); + + migrate_del_blocker(s->migration_blocker); + error_free(s->migration_blocker); } static coroutine_fn int vdi_co_flush(BlockDriverState *bs) @@ -981,7 +966,7 @@ static BlockDriver bdrv_vdi = { .bdrv_close = vdi_close, .bdrv_create = vdi_create, .bdrv_co_flush_to_disk = vdi_co_flush, - .bdrv_is_allocated = vdi_is_allocated, + .bdrv_co_is_allocated = vdi_co_is_allocated, .bdrv_make_empty = vdi_make_empty, .bdrv_aio_readv = vdi_aio_readv, diff --git a/block/vmdk.c b/block/vmdk.c index 96f7d5d90f..5623ac10cd 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -26,6 +26,7 @@ #include "qemu-common.h" #include "block_int.h" #include "module.h" +#include "migration.h" #include <zlib.h> #define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D') @@ -97,6 +98,7 @@ typedef struct BDRVVmdkState { int num_extents; /* Extent array with num_extents entries, ascend ordered by address */ VmdkExtent *extents; + Error *migration_blocker; } BDRVVmdkState; typedef struct VmdkMetaData { @@ -659,7 +661,14 @@ static int vmdk_open(BlockDriverState *bs, int flags) } s->parent_cid = vmdk_read_cid(bs, 1); qemu_co_mutex_init(&s->lock); - return ret; + + /* Disable migration when VMDK images are used */ + error_set(&s->migration_blocker, + QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, + "vmdk", bs->device_name, "live migration"); + migrate_add_blocker(s->migration_blocker); + + return 0; fail: vmdk_free_extents(bs); @@ -852,8 +861,8 @@ static VmdkExtent *find_extent(BDRVVmdkState *s, return NULL; } -static int vmdk_is_allocated(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *pnum) +static int coroutine_fn vmdk_co_is_allocated(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, int *pnum) { BDRVVmdkState *s = bs->opaque; int64_t index_in_cluster, n, ret; @@ -864,8 +873,10 @@ static int vmdk_is_allocated(BlockDriverState *bs, int64_t sector_num, if (!extent) { return 0; } + qemu_co_mutex_lock(&s->lock); ret = get_cluster_offset(bs, extent, NULL, sector_num * 512, 0, &offset); + qemu_co_mutex_unlock(&s->lock); /* get_cluster_offset returning 0 means success */ ret = !ret; @@ -1504,7 +1515,12 @@ exit: static void vmdk_close(BlockDriverState *bs) { + BDRVVmdkState *s = bs->opaque; + vmdk_free_extents(bs); + + migrate_del_blocker(s->migration_blocker); + error_free(s->migration_blocker); } static coroutine_fn int vmdk_co_flush(BlockDriverState *bs) @@ -1582,7 +1598,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_close = vmdk_close, .bdrv_create = vmdk_create, .bdrv_co_flush_to_disk = vmdk_co_flush, - .bdrv_is_allocated = vmdk_is_allocated, + .bdrv_co_is_allocated = vmdk_co_is_allocated, .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size, .create_options = vmdk_create_options, diff --git a/block/vpc.c b/block/vpc.c index 39a324705d..89a5ee2668 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -25,6 +25,7 @@ #include "qemu-common.h" #include "block_int.h" #include "module.h" +#include "migration.h" /**************************************************************/ @@ -128,6 +129,8 @@ typedef struct BDRVVPCState { uint64_t last_bitmap; #endif + + Error *migration_blocker; } BDRVVPCState; static uint32_t vpc_checksum(uint8_t* buf, size_t size) @@ -228,6 +231,13 @@ static int vpc_open(BlockDriverState *bs, int flags) #endif qemu_co_mutex_init(&s->lock); + + /* Disable migration when VHD images are used */ + error_set(&s->migration_blocker, + QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, + "vpc", bs->device_name, "live migration"); + migrate_add_blocker(s->migration_blocker); + return 0; fail: return err; @@ -352,8 +362,11 @@ static int64_t alloc_block(BlockDriverState* bs, int64_t sector_num) // Initialize the block's bitmap memset(bitmap, 0xff, s->bitmap_size); - bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap, + ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap, s->bitmap_size); + if (ret < 0) { + return ret; + } // Write new footer (the old one will be overwritten) s->free_data_block_offset += s->block_size + s->bitmap_size; @@ -651,6 +664,9 @@ static void vpc_close(BlockDriverState *bs) #ifdef CACHE g_free(s->pageentry_u8); #endif + + migrate_del_blocker(s->migration_blocker); + error_free(s->migration_blocker); } static QEMUOptionParameter vpc_create_options[] = { diff --git a/block/vvfat.c b/block/vvfat.c index 131680f6f4..eeffc4a4a8 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -27,6 +27,7 @@ #include "qemu-common.h" #include "block_int.h" #include "module.h" +#include "migration.h" #ifndef S_IWGRP #define S_IWGRP 0 @@ -350,6 +351,8 @@ typedef struct BDRVVVFATState { array_t commits; const char* path; int downcase_short_names; + + Error *migration_blocker; } BDRVVVFATState; /* take the sector position spos and convert it to Cylinder/Head/Sector position @@ -1073,6 +1076,15 @@ DLOG(if (stderr == NULL) { // assert(is_consistent(s)); qemu_co_mutex_init(&s->lock); + + /* Disable migration when vvfat is used rw */ + if (s->qcow) { + error_set(&s->migration_blocker, + QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, + "vvfat (rw)", bs->device_name, "live migration"); + migrate_add_blocker(s->migration_blocker); + } + return 0; } @@ -2746,7 +2758,7 @@ static coroutine_fn int vvfat_co_write(BlockDriverState *bs, int64_t sector_num, return ret; } -static int vvfat_is_allocated(BlockDriverState *bs, +static int coroutine_fn vvfat_co_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int* n) { BDRVVVFATState* s = bs->opaque; @@ -2829,6 +2841,11 @@ static void vvfat_close(BlockDriverState *bs) array_free(&(s->directory)); array_free(&(s->mapping)); g_free(s->cluster_buffer); + + if (s->qcow) { + migrate_del_blocker(s->migration_blocker); + error_free(s->migration_blocker); + } } static BlockDriver bdrv_vvfat = { @@ -2838,7 +2855,7 @@ static BlockDriver bdrv_vvfat = { .bdrv_read = vvfat_co_read, .bdrv_write = vvfat_co_write, .bdrv_close = vvfat_close, - .bdrv_is_allocated = vvfat_is_allocated, + .bdrv_co_is_allocated = vvfat_co_is_allocated, .protocol_name = "fat", }; diff --git a/block_int.h b/block_int.h index 77c0187c3d..311bd2a6fa 100644 --- a/block_int.h +++ b/block_int.h @@ -34,6 +34,13 @@ #define BLOCK_FLAG_ENCRYPT 1 #define BLOCK_FLAG_COMPAT6 4 +#define BLOCK_IO_LIMIT_READ 0 +#define BLOCK_IO_LIMIT_WRITE 1 +#define BLOCK_IO_LIMIT_TOTAL 2 + +#define BLOCK_IO_SLICE_TIME 100000000 +#define NANOSECONDS_PER_SECOND 1000000000.0 + #define BLOCK_OPT_SIZE "size" #define BLOCK_OPT_ENCRYPT "encryption" #define BLOCK_OPT_COMPAT6 "compat6" @@ -44,12 +51,24 @@ #define BLOCK_OPT_PREALLOC "preallocation" #define BLOCK_OPT_SUBFMT "subformat" +typedef struct BdrvTrackedRequest BdrvTrackedRequest; + typedef struct AIOPool { void (*cancel)(BlockDriverAIOCB *acb); int aiocb_size; BlockDriverAIOCB *free_aiocb; } AIOPool; +typedef struct BlockIOLimit { + int64_t bps[3]; + int64_t iops[3]; +} BlockIOLimit; + +typedef struct BlockIOBaseValue { + uint64_t bytes[2]; + uint64_t ios[2]; +} BlockIOBaseValue; + struct BlockDriver { const char *format_name; int instance_size; @@ -63,8 +82,6 @@ struct BlockDriver { const uint8_t *buf, int nb_sectors); void (*bdrv_close)(BlockDriverState *bs); int (*bdrv_create)(const char *filename, QEMUOptionParameter *options); - int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *pnum); int (*bdrv_set_key)(BlockDriverState *bs, const char *key); int (*bdrv_make_empty)(BlockDriverState *bs); /* aio */ @@ -86,6 +103,8 @@ struct BlockDriver { int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs, int64_t sector_num, int nb_sectors); + int coroutine_fn (*bdrv_co_is_allocated)(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, int *pnum); /* * Invalidate any cached meta-data. @@ -179,6 +198,8 @@ struct BlockDriverState { int encrypted; /* if true, the media is encrypted */ int valid_key; /* if true, a valid encryption key has been set */ int sg; /* if true, the device is a /dev/sg* */ + int copy_on_read; /* if true, copy read backing sectors into image + note this is a reference count */ BlockDriver *drv; /* NULL means no media */ void *opaque; @@ -201,6 +222,16 @@ struct BlockDriverState { void *sync_aiocb; + /* the time for latest disk I/O */ + int64_t slice_time; + int64_t slice_start; + int64_t slice_end; + BlockIOLimit io_limits; + BlockIOBaseValue io_base; + CoQueue throttled_reqs; + QEMUTimer *block_timer; + bool io_limits_enabled; + /* I/O stats (display with "info blockstats"). */ uint64_t nr_bytes[BDRV_MAX_IOTYPE]; uint64_t nr_ops[BDRV_MAX_IOTYPE]; @@ -228,6 +259,8 @@ struct BlockDriverState { int in_use; /* users other than guest access, eg. block migration */ QTAILQ_ENTRY(BlockDriverState) list; void *private; + + QLIST_HEAD(, BdrvTrackedRequest) tracked_requests; }; struct BlockDriverAIOCB { @@ -244,6 +277,9 @@ void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque); void qemu_aio_release(void *p); +void bdrv_set_io_limits(BlockDriverState *bs, + BlockIOLimit *io_limits); + #ifdef _WIN32 int is_windows_drive(const char *filename); #endif diff --git a/blockdev.c b/blockdev.c index 222818690d..c832782d03 100644 --- a/blockdev.c +++ b/blockdev.c @@ -15,6 +15,7 @@ #include "qemu-config.h" #include "sysemu.h" #include "block_int.h" +#include "qmp-commands.h" static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives); @@ -216,6 +217,26 @@ static int parse_block_error_action(const char *buf, int is_read) } } +static bool do_check_io_limits(BlockIOLimit *io_limits) +{ + bool bps_flag; + bool iops_flag; + + assert(io_limits); + + bps_flag = (io_limits->bps[BLOCK_IO_LIMIT_TOTAL] != 0) + && ((io_limits->bps[BLOCK_IO_LIMIT_READ] != 0) + || (io_limits->bps[BLOCK_IO_LIMIT_WRITE] != 0)); + iops_flag = (io_limits->iops[BLOCK_IO_LIMIT_TOTAL] != 0) + && ((io_limits->iops[BLOCK_IO_LIMIT_READ] != 0) + || (io_limits->iops[BLOCK_IO_LIMIT_WRITE] != 0)); + if (bps_flag || iops_flag) { + return false; + } + + return true; +} + DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) { const char *buf; @@ -235,7 +256,9 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) int on_read_error, on_write_error; const char *devaddr; DriveInfo *dinfo; + BlockIOLimit io_limits; int snapshot = 0; + bool copy_on_read; int ret; translation = BIOS_ATA_TRANSLATION_AUTO; @@ -252,6 +275,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) snapshot = qemu_opt_get_bool(opts, "snapshot", 0); ro = qemu_opt_get_bool(opts, "readonly", 0); + copy_on_read = qemu_opt_get_bool(opts, "copy-on-read", false); file = qemu_opt_get(opts, "file"); serial = qemu_opt_get(opts, "serial"); @@ -353,6 +377,26 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) } } + /* disk I/O throttling */ + io_limits.bps[BLOCK_IO_LIMIT_TOTAL] = + qemu_opt_get_number(opts, "bps", 0); + io_limits.bps[BLOCK_IO_LIMIT_READ] = + qemu_opt_get_number(opts, "bps_rd", 0); + io_limits.bps[BLOCK_IO_LIMIT_WRITE] = + qemu_opt_get_number(opts, "bps_wr", 0); + io_limits.iops[BLOCK_IO_LIMIT_TOTAL] = + qemu_opt_get_number(opts, "iops", 0); + io_limits.iops[BLOCK_IO_LIMIT_READ] = + qemu_opt_get_number(opts, "iops_rd", 0); + io_limits.iops[BLOCK_IO_LIMIT_WRITE] = + qemu_opt_get_number(opts, "iops_wr", 0); + + if (!do_check_io_limits(&io_limits)) { + error_report("bps(iops) and bps_rd/bps_wr(iops_rd/iops_wr) " + "cannot be used at the same time"); + return NULL; + } + on_write_error = BLOCK_ERR_STOP_ENOSPC; if ((buf = qemu_opt_get(opts, "werror")) != NULL) { if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO && type != IF_NONE) { @@ -460,6 +504,9 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) bdrv_set_on_error(dinfo->bdrv, on_read_error, on_write_error); + /* disk I/O throttling */ + bdrv_set_io_limits(dinfo->bdrv, &io_limits); + switch(type) { case IF_IDE: case IF_SCSI: @@ -502,6 +549,10 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) bdrv_flags |= (BDRV_O_SNAPSHOT|BDRV_O_CACHE_WB|BDRV_O_NO_FLUSH); } + if (copy_on_read) { + bdrv_flags |= BDRV_O_COPY_ON_READ; + } + if (media == MEDIA_CDROM) { /* CDROM is fine for any interface, don't check. */ ro = 1; @@ -550,28 +601,20 @@ void do_commit(Monitor *mon, const QDict *qdict) } } -int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data) +void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, + bool has_format, const char *format, + Error **errp) { - const char *device = qdict_get_str(qdict, "device"); - const char *filename = qdict_get_try_str(qdict, "snapshot-file"); - const char *format = qdict_get_try_str(qdict, "format"); BlockDriverState *bs; BlockDriver *drv, *old_drv, *proto_drv; int ret = 0; int flags; char old_filename[1024]; - if (!filename) { - qerror_report(QERR_MISSING_PARAMETER, "snapshot-file"); - ret = -1; - goto out; - } - bs = bdrv_find(device); if (!bs) { - qerror_report(QERR_DEVICE_NOT_FOUND, device); - ret = -1; - goto out; + error_set(errp, QERR_DEVICE_NOT_FOUND, device); + return; } pstrcpy(old_filename, sizeof(old_filename), bs->filename); @@ -579,35 +622,34 @@ int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data) old_drv = bs->drv; flags = bs->open_flags; - if (!format) { + if (!has_format) { format = "qcow2"; } drv = bdrv_find_format(format); if (!drv) { - qerror_report(QERR_INVALID_BLOCK_FORMAT, format); - ret = -1; - goto out; + error_set(errp, QERR_INVALID_BLOCK_FORMAT, format); + return; } - proto_drv = bdrv_find_protocol(filename); + proto_drv = bdrv_find_protocol(snapshot_file); if (!proto_drv) { - qerror_report(QERR_INVALID_BLOCK_FORMAT, format); - ret = -1; - goto out; + error_set(errp, QERR_INVALID_BLOCK_FORMAT, format); + return; } - ret = bdrv_img_create(filename, format, bs->filename, + ret = bdrv_img_create(snapshot_file, format, bs->filename, bs->drv->format_name, NULL, -1, flags); if (ret) { - goto out; + error_set(errp, QERR_UNDEFINED_ERROR); + return; } - qemu_aio_flush(); + bdrv_drain_all(); bdrv_flush(bs); bdrv_close(bs); - ret = bdrv_open(bs, filename, flags, drv); + ret = bdrv_open(bs, snapshot_file, flags, drv); /* * If reopening the image file we just created fails, fall back * and try to re-open the original image. If that fails too, we @@ -616,17 +658,11 @@ int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data) if (ret != 0) { ret = bdrv_open(bs, old_filename, flags, old_drv); if (ret != 0) { - qerror_report(QERR_OPEN_FILE_FAILED, old_filename); + error_set(errp, QERR_OPEN_FILE_FAILED, old_filename); } else { - qerror_report(QERR_OPEN_FILE_FAILED, filename); + error_set(errp, QERR_OPEN_FILE_FAILED, snapshot_file); } } -out: - if (ret) { - ret = -1; - } - - return ret; } static int eject_device(Monitor *mon, BlockDriverState *bs, int force) @@ -660,28 +696,25 @@ int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data) return eject_device(mon, bs, force); } -int do_block_set_passwd(Monitor *mon, const QDict *qdict, - QObject **ret_data) +void qmp_block_passwd(const char *device, const char *password, Error **errp) { BlockDriverState *bs; int err; - bs = bdrv_find(qdict_get_str(qdict, "device")); + bs = bdrv_find(device); if (!bs) { - qerror_report(QERR_DEVICE_NOT_FOUND, qdict_get_str(qdict, "device")); - return -1; + error_set(errp, QERR_DEVICE_NOT_FOUND, device); + return; } - err = bdrv_set_key(bs, qdict_get_str(qdict, "password")); + err = bdrv_set_key(bs, password); if (err == -EINVAL) { - qerror_report(QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs)); - return -1; + error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs)); + return; } else if (err < 0) { - qerror_report(QERR_INVALID_PASSWORD); - return -1; + error_set(errp, QERR_INVALID_PASSWORD); + return; } - - return 0; } int do_change_block(Monitor *mon, const char *device, @@ -715,6 +748,65 @@ int do_change_block(Monitor *mon, const char *device, return monitor_read_bdrv_key_start(mon, bs, NULL, NULL); } +/* throttling disk I/O limits */ +int do_block_set_io_throttle(Monitor *mon, + const QDict *qdict, QObject **ret_data) +{ + BlockIOLimit io_limits; + const char *devname = qdict_get_str(qdict, "device"); + BlockDriverState *bs; + + io_limits.bps[BLOCK_IO_LIMIT_TOTAL] + = qdict_get_try_int(qdict, "bps", -1); + io_limits.bps[BLOCK_IO_LIMIT_READ] + = qdict_get_try_int(qdict, "bps_rd", -1); + io_limits.bps[BLOCK_IO_LIMIT_WRITE] + = qdict_get_try_int(qdict, "bps_wr", -1); + io_limits.iops[BLOCK_IO_LIMIT_TOTAL] + = qdict_get_try_int(qdict, "iops", -1); + io_limits.iops[BLOCK_IO_LIMIT_READ] + = qdict_get_try_int(qdict, "iops_rd", -1); + io_limits.iops[BLOCK_IO_LIMIT_WRITE] + = qdict_get_try_int(qdict, "iops_wr", -1); + + bs = bdrv_find(devname); + if (!bs) { + qerror_report(QERR_DEVICE_NOT_FOUND, devname); + return -1; + } + + if ((io_limits.bps[BLOCK_IO_LIMIT_TOTAL] == -1) + || (io_limits.bps[BLOCK_IO_LIMIT_READ] == -1) + || (io_limits.bps[BLOCK_IO_LIMIT_WRITE] == -1) + || (io_limits.iops[BLOCK_IO_LIMIT_TOTAL] == -1) + || (io_limits.iops[BLOCK_IO_LIMIT_READ] == -1) + || (io_limits.iops[BLOCK_IO_LIMIT_WRITE] == -1)) { + qerror_report(QERR_MISSING_PARAMETER, + "bps/bps_rd/bps_wr/iops/iops_rd/iops_wr"); + return -1; + } + + if (!do_check_io_limits(&io_limits)) { + qerror_report(QERR_INVALID_PARAMETER_COMBINATION); + return -1; + } + + bs->io_limits = io_limits; + bs->slice_time = BLOCK_IO_SLICE_TIME; + + if (!bs->io_limits_enabled && bdrv_io_limits_enabled(bs)) { + bdrv_io_limits_enable(bs); + } else if (bs->io_limits_enabled && !bdrv_io_limits_enabled(bs)) { + bdrv_io_limits_disable(bs); + } else { + if (bs->block_timer) { + qemu_mod_timer(bs->block_timer, qemu_get_clock_ns(vm_clock)); + } + } + + return 0; +} + int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *id = qdict_get_str(qdict, "id"); @@ -731,7 +823,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) } /* quiesce block driver; prevent further io */ - qemu_aio_flush(); + bdrv_drain_all(); bdrv_flush(bs); bdrv_close(bs); @@ -754,27 +846,23 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) * existing QERR_ macro mess is cleaned up. A good example for better * error reports can be found in the qemu-img resize code. */ -int do_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data) +void qmp_block_resize(const char *device, int64_t size, Error **errp) { - const char *device = qdict_get_str(qdict, "device"); - int64_t size = qdict_get_int(qdict, "size"); BlockDriverState *bs; bs = bdrv_find(device); if (!bs) { - qerror_report(QERR_DEVICE_NOT_FOUND, device); - return -1; + error_set(errp, QERR_DEVICE_NOT_FOUND, device); + return; } if (size < 0) { - qerror_report(QERR_UNDEFINED_ERROR); - return -1; + error_set(errp, QERR_UNDEFINED_ERROR); + return; } if (bdrv_truncate(bs, size)) { - qerror_report(QERR_UNDEFINED_ERROR); - return -1; + error_set(errp, QERR_UNDEFINED_ERROR); + return; } - - return 0; } diff --git a/blockdev.h b/blockdev.h index 3587786a64..f1b639660d 100644 --- a/blockdev.h +++ b/blockdev.h @@ -59,11 +59,9 @@ DriveInfo *add_init_drive(const char *opts); void do_commit(Monitor *mon, const QDict *qdict); int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data); -int do_block_set_passwd(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_change_block(Monitor *mon, const char *device, const char *filename, const char *fmt); int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data); -int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data); -int do_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data); - +int do_block_set_io_throttle(Monitor *mon, + const QDict *qdict, QObject **ret_data); #endif diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 6d9bb6fb4e..2abc7136e0 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -196,7 +196,7 @@ int loader_exec(const char * filename, char ** argv, char ** envp, /* Something went wrong, return the inode and free the argument pages*/ for (i=0 ; i<MAX_ARG_PAGES ; i++) { - free(bprm.page[i]); + g_free(bprm.page[i]); } return(retval); } diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 1ef1f972fc..12888840a4 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -641,8 +641,7 @@ static abi_ulong copy_elf_strings(int argc,char ** argv, void **page, offset = p % TARGET_PAGE_SIZE; pag = (char *)page[p/TARGET_PAGE_SIZE]; if (!pag) { - pag = (char *)malloc(TARGET_PAGE_SIZE); - memset(pag, 0, TARGET_PAGE_SIZE); + pag = g_try_malloc0(TARGET_PAGE_SIZE); page[p/TARGET_PAGE_SIZE] = pag; if (!pag) return 0; @@ -696,7 +695,7 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm, info->rss++; /* FIXME - check return value of memcpy_to_target() for failure */ memcpy_to_target(stack_base, bprm->page[i], TARGET_PAGE_SIZE); - free(bprm->page[i]); + g_free(bprm->page[i]); } stack_base += TARGET_PAGE_SIZE; } diff --git a/bsd-user/x86_64/syscall.h b/bsd-user/x86_64/syscall.h index 5f71b7cdcf..630514a930 100644 --- a/bsd-user/x86_64/syscall.h +++ b/bsd-user/x86_64/syscall.h @@ -8,7 +8,7 @@ struct target_pt_regs { abi_ulong r12; abi_ulong rbp; abi_ulong rbx; -/* arguments: non interrupts/non tracing syscalls only save upto here*/ +/* arguments: non interrupts/non tracing syscalls only save up to here */ abi_ulong r11; abi_ulong r10; abi_ulong r9; @@ -20,6 +20,11 @@ TMPE="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.exe" trap "rm -f $TMPC $TMPO $TMPE" EXIT INT QUIT TERM rm -f config.log +# Print a helpful header at the top of config.log +echo "# QEMU configure log $(date)" >> config.log +echo "# produced by $0 $*" >> config.log +echo "#" >> config.log + compile_object() { echo $cc $QEMU_CFLAGS -c -o $TMPO $TMPC >> config.log $cc $QEMU_CFLAGS -c -o $TMPO $TMPC >> config.log 2>&1 @@ -249,7 +254,7 @@ source_path=`cd "$source_path"; pwd` check_define() { cat > $TMPC <<EOF #if !defined($1) -#error Not defined +#error $1 not defined #endif int main(void) { return 0; } EOF @@ -287,10 +292,8 @@ elif check_define __s390__ ; then else cpu="s390" fi -elif check_define __ARMEB__ ; then - cpu="armv4b" -elif check_define __ARMEL__ ; then - cpu="armv4l" +elif check_define __arm__ ; then + cpu="arm" elif check_define __hppa__ ; then cpu="hppa" else @@ -307,11 +310,8 @@ case "$cpu" in x86_64|amd64) cpu="x86_64" ;; - armv*b) - cpu="armv4b" - ;; - armv*l) - cpu="armv4l" + armv*b|armv*l|arm) + cpu="arm" ;; hppa|parisc|parisc64) cpu="hppa" @@ -569,6 +569,14 @@ for opt do ;; --sysconfdir=*) sysconfdir="$optarg" ;; + --sbindir=*|--libexecdir=*|--sharedstatedir=*|--localstatedir=*|\ + --oldincludedir=*|--datarootdir=*|--infodir=*|--localedir=*|\ + --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*) + # These switches are silently ignored, for compatibility with + # autoconf-generated configure scripts. This allows QEMU's + # configure to be used by RPM and similar macros that set + # lots of directory switches by default. + ;; --disable-sdl) sdl="no" ;; --enable-sdl) sdl="yes" @@ -759,8 +767,6 @@ for opt do ;; --enable-opengl) opengl="yes" ;; - --*dir) - ;; --disable-rbd) rbd="no" ;; --enable-rbd) rbd="yes" @@ -1076,7 +1082,7 @@ fi # check that the C compiler works. cat > $TMPC <<EOF -int main(void) {} +int main(void) { return 0; } EOF if compile_object ; then @@ -1110,7 +1116,7 @@ fi if test "$pie" = ""; then case "$cpu-$targetos" in - i386-Linux|x86_64-Linux) + i386-Linux|x86_64-Linux|i386-OpenBSD|x86_64-OpenBSD) ;; *) pie="no" @@ -1120,7 +1126,17 @@ fi if test "$pie" != "no" ; then cat > $TMPC << EOF -int main(void) { return 0; } + +#ifdef __linux__ +# define THREAD __thread +#else +# define THREAD +#endif + +static THREAD int tls_var; + +int main(void) { return tls_var; } + EOF if compile_prog "-fPIE -DPIE" "-pie"; then QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS" @@ -1227,7 +1243,13 @@ else # if cross compiling, cannot launch a program, so make a static guess case "$cpu" in - armv4b|hppa|m68k|mips|mips64|ppc|ppc64|s390|s390x|sparc|sparc64) + arm) + # ARM can be either way; ask the compiler which one we are + if check_define __ARMEB__; then + bigendian=yes + fi + ;; + hppa|m68k|mips|mips64|ppc|ppc64|s390|s390x|sparc|sparc64) bigendian=yes ;; esac @@ -1252,11 +1274,11 @@ if test "$nptl" != "no" ; then cat > $TMPC <<EOF #include <sched.h> #include <linux/futex.h> -void foo() -{ +int main(void) { #if !defined(CLONE_SETTLS) || !defined(FUTEX_WAIT) #error bork #endif + return 0; } EOF @@ -1295,10 +1317,30 @@ fi if test "$xen" != "no" ; then xen_libs="-lxenstore -lxenctrl -lxenguest" - # Xen unstable + # First we test whether Xen headers and libraries are available. + # If no, we are done and there is no Xen support. + # If yes, more tests are run to detect the Xen version. + + # Xen (any) cat > $TMPC <<EOF #include <xenctrl.h> #include <xs.h> +int main(void) { + return 0; +} +EOF + if ! compile_prog "" "$xen_libs" ; then + # Xen not found + if test "$xen" = "yes" ; then + feature_not_found "xen" + fi + xen=no + + # Xen unstable + elif ( + cat > $TMPC <<EOF +#include <xenctrl.h> +#include <xs.h> #include <stdint.h> #include <xen/hvm/hvm_info_table.h> #if !defined(HVM_MAX_VCPUS) @@ -1314,7 +1356,8 @@ int main(void) { return 0; } EOF - if compile_prog "" "$xen_libs" ; then + compile_prog "" "$xen_libs" + ) ; then xen_ctrl_version=410 xen=yes @@ -1385,10 +1428,10 @@ EOF xen_ctrl_version=330 xen=yes - # Xen not found or unsupported + # Xen version unsupported else if test "$xen" = "yes" ; then - feature_not_found "xen" + feature_not_found "xen (unsupported version)" fi xen=no fi @@ -1506,9 +1549,6 @@ EOF if compile_prog "$sdl_cflags" "$sdl_libs" ; then sdl_libs="$sdl_libs -lX11" fi - if test "$mingw32" = "yes" ; then - sdl_libs="`echo $sdl_libs | sed s/-mwindows//g` -mconsole" - fi libs_softmmu="$sdl_libs $libs_softmmu" fi @@ -1651,6 +1691,7 @@ fi # xfsctl() probe, used for raw-posix if test "$xfs" != "no" ; then cat > $TMPC << EOF +#include <stddef.h> /* NULL */ #include <xfs/xfs.h> int main(void) { @@ -1822,7 +1863,11 @@ if test "$curses" != "no" ; then #ifdef __OpenBSD__ #define resize_term resizeterm #endif -int main(void) { resize_term(0, 0); return curses_version(); } +int main(void) { + const char *s = curses_version(); + resize_term(0, 0); + return s != 0; +} EOF for curses_lib in $curses_list; do if compile_prog "" "$curses_lib" ; then @@ -1928,7 +1973,12 @@ PTHREADLIBS_LIST="-pthread -lpthread -lpthreadGC2" pthread=no cat > $TMPC << EOF #include <pthread.h> -int main(void) { pthread_create(0,0,0,0); return 0; } +static void *f(void *p) { return NULL; } +int main(void) { + pthread_t thread; + pthread_create(&thread, 0, f, 0); + return 0; +} EOF if compile_prog "" "" ; then pthread=yes @@ -2032,7 +2082,7 @@ cat > $TMPC <<EOF #include <sys/types.h> #include <sys/uio.h> #include <unistd.h> -int main(void) { struct iovec iov; return 0; } +int main(void) { return sizeof(struct iovec); } EOF iovec=no if compile_prog "" "" ; then @@ -2045,7 +2095,7 @@ cat > $TMPC <<EOF #include <sys/types.h> #include <sys/uio.h> #include <unistd.h> -int main(void) { preadv; } +int main(void) { return preadv == preadv; } EOF preadv=no if compile_prog "" "" ; then @@ -2078,7 +2128,7 @@ if test "$opengl" != "no" ; then #include <X11/Xlib.h> #include <GL/gl.h> #include <GL/glx.h> -int main(void) { GL_VERSION; return 0; } +int main(void) { return GL_VERSION != 0; } EOF if compile_prog "" "-lGL" ; then opengl=yes @@ -2209,7 +2259,7 @@ cat > $TMPC << EOF int main(void) { - int len, fd; + int len, fd = 0; len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, SPLICE_F_NONBLOCK); splice(STDIN_FILENO, NULL, fd, NULL, len, SPLICE_F_MOVE); return 0; @@ -2223,7 +2273,6 @@ fi # signalfd probe signalfd="no" cat > $TMPC << EOF -#define _GNU_SOURCE #include <unistd.h> #include <sys/syscall.h> #include <signal.h> @@ -2241,8 +2290,7 @@ cat > $TMPC << EOF int main(void) { - int efd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); - return 0; + return eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); } EOF if compile_prog "" "" ; then @@ -2342,8 +2390,7 @@ int main(void) * warning but not an error, and will proceed to fail the * qemu compile where we compile with -Werror.) */ - epoll_create1; - return 0; + return epoll_create1 == epoll_create1; } EOF if compile_prog "$ARCH_CFLAGS" "" ; then @@ -2422,7 +2469,7 @@ fi cat > $TMPC <<EOF #include <signal.h> #include <time.h> -int main(void) { clockid_t id; return clock_gettime(id, NULL); } +int main(void) { return clock_gettime(CLOCK_REALTIME, NULL); } EOF if compile_prog "" "" ; then @@ -2632,7 +2679,7 @@ ucontext_coroutine=no if test "$darwin" != "yes"; then cat > $TMPC << EOF #include <ucontext.h> -int main(void) { makecontext(0, 0, 0); } +int main(void) { makecontext(0, 0, 0); return 0; } EOF if compile_prog "" "" ; then ucontext_coroutine=yes @@ -2645,7 +2692,7 @@ fi open_by_hande_at=no cat > $TMPC << EOF #include <fcntl.h> -int main(void) { struct file_handle fh; open_by_handle_at(0, &fh, 0); } +int main(void) { struct file_handle fh; return open_by_handle_at(0, &fh, 0); } EOF if compile_prog "" "" ; then open_by_handle_at=yes @@ -2658,6 +2705,7 @@ linux_magic_h=no cat > $TMPC << EOF #include <linux/magic.h> int main(void) { + return 0; } EOF if compile_prog "" "" ; then @@ -2726,8 +2774,9 @@ if test "$softmmu" = yes ; then fi if [ "$check_utests" = "yes" ]; then checks="check-qint check-qstring check-qdict check-qlist" - checks="check-qfloat check-qjson test-coroutine $checks" + checks="check-qfloat check-qjson $checks" fi + test_progs="$checks test-coroutine test-qmp-output-visitor test-qmp-input-visitor" fi fi @@ -2855,12 +2904,9 @@ echo "docdir=$docdir" >> $config_host_mak echo "confdir=$confdir" >> $config_host_mak case "$cpu" in - i386|x86_64|alpha|cris|hppa|ia64|lm32|m68k|microblaze|mips|mips64|ppc|ppc64|s390|s390x|sparc|sparc64|unicore32) + i386|x86_64|alpha|arm|cris|hppa|ia64|lm32|m68k|microblaze|mips|mips64|ppc|ppc64|s390|s390x|sparc|sparc64|unicore32) ARCH=$cpu ;; - armv4b|armv4l) - ARCH=arm - ;; *) if test "$tcg_interpreter" = "yes" ; then echo "Unsupported CPU = $cpu, will use TCG with TCI (experimental)" @@ -3216,7 +3262,7 @@ if test "$trace_default" = "yes"; then fi echo "TOOLS=$tools" >> $config_host_mak -echo "CHECKS=$checks" >> $config_host_mak +echo "CHECKS=$test_progs" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak echo "INSTALL=$install" >> $config_host_mak @@ -3267,6 +3313,22 @@ for d in libdis libdis-user; do echo > $d/config.mak done +# use included Linux headers +if test "$linux" = "yes" ; then + mkdir -p linux-headers + case "$cpu" in + i386|x86_64) + symlink $source_path/linux-headers/asm-x86 linux-headers/asm + ;; + ppcemb|ppc|ppc64) + symlink $source_path/linux-headers/asm-powerpc linux-headers/asm + ;; + s390x) + symlink $source_path/linux-headers/asm-s390 linux-headers/asm + ;; + esac +fi + for target in $target_list; do target_dir="$target" config_target_mak=$target_dir/config-target.mak @@ -3592,6 +3654,10 @@ else fi includes="-I\$(SRC_PATH)/tcg $includes" +if test "$linux" = "yes" ; then + includes="-I\$(SRC_PATH)/linux-headers $includes" +fi + if test "$target_user_only" = "yes" ; then libdis_config_mak=libdis-user/config.mak else @@ -3723,23 +3789,6 @@ if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then esac fi -# use included Linux headers -if test "$linux" = "yes" ; then - includes="-I\$(SRC_PATH)/linux-headers $includes" - mkdir -p linux-headers - case "$cpu" in - i386|x86_64) - symlink $source_path/linux-headers/asm-x86 linux-headers/asm - ;; - ppcemb|ppc|ppc64) - symlink $source_path/linux-headers/asm-powerpc linux-headers/asm - ;; - s390x) - symlink $source_path/linux-headers/asm-s390 linux-headers/asm - ;; - esac -fi - echo "LDFLAGS+=$ldflags" >> $config_target_mak echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak echo "QEMU_INCLUDES+=$includes" >> $config_target_mak @@ -1009,16 +1009,17 @@ static void console_putchar(TextConsole *s, int ch) console_clear_xy(s, x, y); } } - break; + break; } + break; case 'K': switch (s->esc_params[0]) { case 0: - /* clear to eol */ - for(x = s->x; x < s->width; x++) { + /* clear to eol */ + for(x = s->x; x < s->width; x++) { console_clear_xy(s, x, s->y); - } - break; + } + break; case 1: /* clear from beginning of line */ for (x = 0; x <= s->x; x++) { @@ -1030,12 +1031,12 @@ static void console_putchar(TextConsole *s, int ch) for(x = 0; x < s->width; x++) { console_clear_xy(s, x, s->y); } - break; - } + break; + } break; case 'm': - console_handle_escape(s); - break; + console_handle_escape(s); + break; case 'n': /* report cursor position */ /* TODO: send ESC[row;colR */ @@ -1687,6 +1688,7 @@ PixelFormat qemu_default_pixelformat(int bpp) pf.rbits = 8; pf.gbits = 8; pf.bbits = 8; + break; case 32: pf.rmask = 0x00FF0000; pf.gmask = 0x0000FF00; @@ -74,8 +74,6 @@ struct MouseTransformInfo { int a[7]; }; -void do_info_mice_print(Monitor *mon, const QObject *data); -void do_info_mice(Monitor *mon, QObject **ret_data); void do_mouse_set(Monitor *mon, const QDict *qdict); /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx diff --git a/coroutine-ucontext.c b/coroutine-ucontext.c index 2b8d3e9c12..3d01075b06 100644 --- a/coroutine-ucontext.c +++ b/coroutine-ucontext.c @@ -35,6 +35,10 @@ enum { POOL_MAX_SIZE = 64, }; +/** Free list to speed up creation */ +static QLIST_HEAD(, Coroutine) pool = QLIST_HEAD_INITIALIZER(pool); +static unsigned int pool_size; + typedef struct { Coroutine base; void *stack; @@ -48,10 +52,6 @@ typedef struct { /** Currently executing coroutine */ Coroutine *current; - /** Free list to speed up creation */ - QLIST_HEAD(, Coroutine) pool; - unsigned int pool_size; - /** The default coroutine */ CoroutineUContext leader; } CoroutineThreadState; @@ -75,7 +75,6 @@ static CoroutineThreadState *coroutine_get_thread_state(void) if (!s) { s = g_malloc0(sizeof(*s)); s->current = &s->leader.base; - QLIST_INIT(&s->pool); pthread_setspecific(thread_state_key, s); } return s; @@ -84,14 +83,19 @@ static CoroutineThreadState *coroutine_get_thread_state(void) static void qemu_coroutine_thread_cleanup(void *opaque) { CoroutineThreadState *s = opaque; + + g_free(s); +} + +static void __attribute__((destructor)) coroutine_cleanup(void) +{ Coroutine *co; Coroutine *tmp; - QLIST_FOREACH_SAFE(co, &s->pool, pool_next, tmp) { + QLIST_FOREACH_SAFE(co, &pool, pool_next, tmp) { g_free(DO_UPCAST(CoroutineUContext, base, co)->stack); g_free(co); } - g_free(s); } static void __attribute__((constructor)) coroutine_init(void) @@ -169,13 +173,12 @@ static Coroutine *coroutine_new(void) Coroutine *qemu_coroutine_new(void) { - CoroutineThreadState *s = coroutine_get_thread_state(); Coroutine *co; - co = QLIST_FIRST(&s->pool); + co = QLIST_FIRST(&pool); if (co) { QLIST_REMOVE(co, pool_next); - s->pool_size--; + pool_size--; } else { co = coroutine_new(); } @@ -184,13 +187,12 @@ Coroutine *qemu_coroutine_new(void) void qemu_coroutine_delete(Coroutine *co_) { - CoroutineThreadState *s = coroutine_get_thread_state(); CoroutineUContext *co = DO_UPCAST(CoroutineUContext, base, co_); - if (s->pool_size < POOL_MAX_SIZE) { - QLIST_INSERT_HEAD(&s->pool, &co->base, pool_next); + if (pool_size < POOL_MAX_SIZE) { + QLIST_INSERT_HEAD(&pool, &co->base, pool_next); co->base.caller = NULL; - s->pool_size++; + pool_size++; return; } @@ -336,7 +336,7 @@ void QEMU_NORETURN cpu_abort(CPUState *env, const char *fmt, ...) GCC_FMT_ATTR(2, 3); extern CPUState *first_cpu; DECLARE_TLS(CPUState *,cpu_single_env); -#define cpu_single_env get_tls(cpu_single_env) +#define cpu_single_env tls_var(cpu_single_env) /* Flags for use in ENV->INTERRUPT_PENDING. @@ -368,7 +368,7 @@ DECLARE_TLS(CPUState *,cpu_single_env); #define CPU_INTERRUPT_TGT_EXT_4 0x1000 /* Several target-specific internal interrupts. These differ from the - preceeding target-specific interrupts in that they are intended to + preceding target-specific interrupts in that they are intended to originate from within the cpu itself, typically in response to some instruction being executed. These, therefore, are not masked while single-stepping within the debugger. */ diff --git a/cpu-common.h b/cpu-common.h index c9878ba474..48f4c01a3f 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -1,7 +1,7 @@ #ifndef CPU_COMMON_H #define CPU_COMMON_H 1 -/* CPU interfaces that are target indpendent. */ +/* CPU interfaces that are target independent. */ #ifdef TARGET_PHYS_ADDR_BITS #include "targphys.h" @@ -172,6 +172,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr, #define IO_MEM_ROM (1 << IO_MEM_SHIFT) /* hardcoded offset */ #define IO_MEM_UNASSIGNED (2 << IO_MEM_SHIFT) #define IO_MEM_NOTDIRTY (3 << IO_MEM_SHIFT) +#define IO_MEM_SUBPAGE_RAM (4 << IO_MEM_SHIFT) /* Acts like a ROM when read and like a device when written. */ #define IO_MEM_ROMD (1) diff --git a/cpu-defs.h b/cpu-defs.h index db48a7afef..57a709b679 100644 --- a/cpu-defs.h +++ b/cpu-defs.h @@ -153,6 +153,14 @@ typedef struct CPUWatchpoint { QTAILQ_ENTRY(CPUWatchpoint) entry; } CPUWatchpoint; +#ifdef _WIN32 +#define CPU_COMMON_THREAD \ + void *hThread; + +#else +#define CPU_COMMON_THREAD +#endif + #define CPU_TEMP_BUF_NLONGS 128 #define CPU_COMMON \ struct TranslationBlock *current_tb; /* currently executing TB */ \ @@ -211,6 +219,7 @@ typedef struct CPUWatchpoint { uint32_t stop; /* Stop request */ \ uint32_t stopped; /* Artificially stopped */ \ struct QemuThread *thread; \ + CPU_COMMON_THREAD \ struct QemuCond *halt_cond; \ int thread_kicked; \ struct qemu_work_item *queued_work_first, *queued_work_last; \ @@ -89,7 +89,7 @@ TimersState timers_state; int64_t cpu_get_icount(void) { int64_t icount; - CPUState *env = cpu_single_env;; + CPUState *env = cpu_single_env; icount = qemu_icount; if (env) { @@ -281,7 +281,7 @@ void qemu_clock_warp(QEMUClock *clock) * (related to the time left until the next event) has passed. This * rt_clock timer will do this. This avoids that the warps are too * visible externally---for example, you will not be sending network - * packets continously instead of every 100ms. + * packets continuously instead of every 100ms. */ qemu_mod_timer(icount_warp_timer, vm_clock_warp_start + deadline); } else { @@ -396,7 +396,7 @@ static void do_vm_stop(RunState state) pause_all_vcpus(); runstate_set(state); vm_state_notify(0, state); - qemu_aio_flush(); + bdrv_drain_all(); bdrv_flush_all(); monitor_protocol_event(QEVENT_STOP, NULL); } @@ -793,9 +793,9 @@ static void qemu_cpu_kick_thread(CPUState *env) } #else /* _WIN32 */ if (!qemu_cpu_is_self(env)) { - SuspendThread(env->thread->thread); + SuspendThread(env->hThread); cpu_signal(0); - ResumeThread(env->thread->thread); + ResumeThread(env->hThread); } #endif } @@ -910,7 +910,11 @@ static void qemu_tcg_init_vcpu(void *_env) env->halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); tcg_halt_cond = env->halt_cond; - qemu_thread_create(env->thread, qemu_tcg_cpu_thread_fn, env); + qemu_thread_create(env->thread, qemu_tcg_cpu_thread_fn, env, + QEMU_THREAD_JOINABLE); +#ifdef _WIN32 + env->hThread = qemu_thread_get_handle(env->thread); +#endif while (env->created == 0) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); } @@ -926,7 +930,8 @@ static void qemu_kvm_start_vcpu(CPUState *env) env->thread = g_malloc0(sizeof(QemuThread)); env->halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); - qemu_thread_create(env->thread, qemu_kvm_cpu_thread_fn, env); + qemu_thread_create(env->thread, qemu_kvm_cpu_thread_fn, env, + QEMU_THREAD_JOINABLE); while (env->created == 0) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); } @@ -1136,3 +1141,93 @@ CpuInfoList *qmp_query_cpus(Error **errp) return head; } + +void qmp_memsave(int64_t addr, int64_t size, const char *filename, + bool has_cpu, int64_t cpu_index, Error **errp) +{ + FILE *f; + uint32_t l; + CPUState *env; + uint8_t buf[1024]; + + if (!has_cpu) { + cpu_index = 0; + } + + for (env = first_cpu; env; env = env->next_cpu) { + if (cpu_index == env->cpu_index) { + break; + } + } + + if (env == NULL) { + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", + "a CPU number"); + return; + } + + f = fopen(filename, "wb"); + if (!f) { + error_set(errp, QERR_OPEN_FILE_FAILED, filename); + return; + } + + while (size != 0) { + l = sizeof(buf); + if (l > size) + l = size; + cpu_memory_rw_debug(env, addr, buf, l, 0); + if (fwrite(buf, 1, l, f) != l) { + error_set(errp, QERR_IO_ERROR); + goto exit; + } + addr += l; + size -= l; + } + +exit: + fclose(f); +} + +void qmp_pmemsave(int64_t addr, int64_t size, const char *filename, + Error **errp) +{ + FILE *f; + uint32_t l; + uint8_t buf[1024]; + + f = fopen(filename, "wb"); + if (!f) { + error_set(errp, QERR_OPEN_FILE_FAILED, filename); + return; + } + + while (size != 0) { + l = sizeof(buf); + if (l > size) + l = size; + cpu_physical_memory_rw(addr, buf, l, 0); + if (fwrite(buf, 1, l, f) != l) { + error_set(errp, QERR_IO_ERROR); + goto exit; + } + addr += l; + size -= l; + } + +exit: + fclose(f); +} + +void qmp_inject_nmi(Error **errp) +{ +#if defined(TARGET_I386) + CPUState *env; + + for (env = first_cpu; env != NULL; env = env->next_cpu) { + cpu_interrupt(env, CPU_INTERRUPT_NMI); + } +#else + error_set(errp, QERR_UNSUPPORTED); +#endif +} @@ -217,7 +217,10 @@ void qemu_iovec_destroy(QEMUIOVector *qiov) { assert(qiov->nalloc != -1); + qemu_iovec_reset(qiov); g_free(qiov->iov); + qiov->nalloc = 0; + qiov->iov = NULL; } void qemu_iovec_reset(QEMUIOVector *qiov) @@ -315,19 +318,34 @@ int fcntl_setfl(int fd, int flag) } #endif +static int64_t suffix_mul(char suffix, int64_t unit) +{ + switch (qemu_toupper(suffix)) { + case STRTOSZ_DEFSUFFIX_B: + return 1; + case STRTOSZ_DEFSUFFIX_KB: + return unit; + case STRTOSZ_DEFSUFFIX_MB: + return unit * unit; + case STRTOSZ_DEFSUFFIX_GB: + return unit * unit * unit; + case STRTOSZ_DEFSUFFIX_TB: + return unit * unit * unit * unit; + } + return -1; +} + /* * Convert string to bytes, allowing either B/b for bytes, K/k for KB, - * M/m for MB, G/g for GB or T/t for TB. Default without any postfix - * is MB. End pointer will be returned in *end, if not NULL. A valid - * value must be terminated by whitespace, ',' or '\0'. Return -1 on - * error. + * M/m for MB, G/g for GB or T/t for TB. End pointer will be returned + * in *end, if not NULL. Return -1 on error. */ int64_t strtosz_suffix_unit(const char *nptr, char **end, const char default_suffix, int64_t unit) { int64_t retval = -1; char *endptr; - unsigned char c, d; + unsigned char c; int mul_required = 0; double val, mul, integral, fraction; @@ -340,59 +358,17 @@ int64_t strtosz_suffix_unit(const char *nptr, char **end, if (fraction != 0) { mul_required = 1; } - /* - * Any whitespace character is fine for terminating the number, - * in addition we accept ',' to handle strings where the size is - * part of a multi token argument. - */ c = *endptr; - d = c; - if (qemu_isspace(c) || c == '\0' || c == ',') { - c = 0; - if (default_suffix) { - d = default_suffix; - } else { - d = c; - } + mul = suffix_mul(c, unit); + if (mul >= 0) { + endptr++; + } else { + mul = suffix_mul(default_suffix, unit); + assert(mul >= 0); } - switch (qemu_toupper(d)) { - case STRTOSZ_DEFSUFFIX_B: - mul = 1; - if (mul_required) { - goto fail; - } - break; - case STRTOSZ_DEFSUFFIX_KB: - mul = unit; - break; - case 0: - if (mul_required) { - goto fail; - } - case STRTOSZ_DEFSUFFIX_MB: - mul = unit * unit; - break; - case STRTOSZ_DEFSUFFIX_GB: - mul = unit * unit * unit; - break; - case STRTOSZ_DEFSUFFIX_TB: - mul = unit * unit * unit * unit; - break; - default: + if (mul == 1 && mul_required) { goto fail; } - /* - * If not terminated by whitespace, ',', or \0, increment endptr - * to point to next character, then check that we are terminated - * by an appropriate separating character, ie. whitespace, ',', or - * \0. If not, we are seeing trailing garbage, thus fail. - */ - if (c != 0) { - endptr++; - if (!qemu_isspace(*endptr) && *endptr != ',' && *endptr != 0) { - goto fail; - } - } if ((val * mul >= INT64_MAX) || val < 0) { goto fail; } diff --git a/darwin-user/machload.c b/darwin-user/machload.c index 0aa828298b..26dd293686 100644 --- a/darwin-user/machload.c +++ b/darwin-user/machload.c @@ -460,7 +460,7 @@ int load_object(const char *filename, struct target_pt_regs * regs, void ** mh) int mach_hdr_pos = 0; struct mach_header mach_hdr; - /* for symbol lookup whith -d flag. */ + /* for symbol lookup with -d flag. */ struct symtab_command * symtabcmd = 0; struct nlist_extended *symtab, *sym; struct nlist *symtab_std, *syment; @@ -645,7 +645,7 @@ int load_object(const char *filename, struct target_pt_regs * regs, void ** mh) case LC_PREBIND_CKSUM: case LC_SUB_LIBRARY: break; - default: fprintf(stderr, "warning: unkown command 0x%x in '%s'\n", lc->cmd, filename); + default: fprintf(stderr, "warning: unknown command 0x%x in '%s'\n", lc->cmd, filename); } lc = (struct load_command*)((int)(lc)+(lc->cmdsize)); } @@ -809,7 +809,7 @@ unsigned long setup_arg_pages(void * mh, char ** argv, char ** env) page_set_flags((int)env[i], (int)(env[i]+strlen(env[i])), PROT_READ | PAGE_VALID); } - /* Add on the stack the interp_prefix choosen if so */ + /* Add on the stack the interp_prefix chosen if so */ if(interp_prefix[0]) { char *dyld_root; diff --git a/darwin-user/main.c b/darwin-user/main.c index c0f14f8260..9b57c20815 100644 --- a/darwin-user/main.c +++ b/darwin-user/main.c @@ -394,7 +394,7 @@ void cpu_loop(CPUPPCState *env) queue_signal(info.si_signo, &info); break; case POWERPC_EXCP_PIT: /* Programmable interval timer IRQ */ - cpu_abort(env, "Programable interval timer interrupt " + cpu_abort(env, "Programmable interval timer interrupt " "while in user mode. Aborting\n"); break; case POWERPC_EXCP_IO: /* IO error exception */ diff --git a/darwin-user/signal.c b/darwin-user/signal.c index c530227f1c..317ef92168 100644 --- a/darwin-user/signal.c +++ b/darwin-user/signal.c @@ -270,8 +270,7 @@ int do_sigaction(int sig, const struct sigaction *act, host_sig = target_to_host_signal(sig); if (host_sig != SIGSEGV && host_sig != SIGBUS) { #if defined(DEBUG_SIGNAL) - fprintf(stderr, "sigaction handler going to call sigaction\n", - act->sa_handler, act->sa_flags, act->sa_mask); + fprintf(stderr, "sigaction handler going to call sigaction\n"); #endif sigfillset(&act1.sa_mask); diff --git a/darwin-user/syscall.c b/darwin-user/syscall.c index f3cc1f83a6..8a168830e9 100644 --- a/darwin-user/syscall.c +++ b/darwin-user/syscall.c @@ -755,7 +755,7 @@ struct attrbuf_header { static inline void byteswap_attrbuf(struct attrbuf_header *attrbuf, struct attrlist *attrlist) { - DPRINTF("attrBuf.lenght %lx\n", attrbuf->length); + DPRINTF("attrBuf.length %lx\n", attrbuf->length); } static inline void byteswap_statfs(struct statfs *s) diff --git a/dma-helpers.c b/dma-helpers.c index bdcd38cd27..f08cdb5454 100644 --- a/dma-helpers.c +++ b/dma-helpers.c @@ -9,6 +9,7 @@ #include "dma.h" #include "block_int.h" +#include "trace.h" void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint) { @@ -83,6 +84,8 @@ static void dma_bdrv_unmap(DMAAIOCB *dbs) static void dma_complete(DMAAIOCB *dbs, int ret) { + trace_dma_complete(dbs, ret, dbs->common.cb); + dma_bdrv_unmap(dbs); if (dbs->common.cb) { dbs->common.cb(dbs->common.opaque, ret); @@ -106,6 +109,8 @@ static void dma_bdrv_cb(void *opaque, int ret) target_phys_addr_t cur_addr, cur_len; void *mem; + trace_dma_bdrv_cb(dbs, ret); + dbs->acb = NULL; dbs->sector_num += dbs->iov.size / 512; dma_bdrv_unmap(dbs); @@ -130,21 +135,22 @@ static void dma_bdrv_cb(void *opaque, int ret) } if (dbs->iov.size == 0) { + trace_dma_map_wait(dbs); cpu_register_map_client(dbs, continue_after_map_failure); return; } dbs->acb = dbs->io_func(dbs->bs, dbs->sector_num, &dbs->iov, dbs->iov.size / 512, dma_bdrv_cb, dbs); - if (!dbs->acb) { - dma_complete(dbs, -EIO); - } + assert(dbs->acb); } static void dma_aio_cancel(BlockDriverAIOCB *acb) { DMAAIOCB *dbs = container_of(acb, DMAAIOCB, common); + trace_dma_aio_cancel(dbs); + if (dbs->acb) { BlockDriverAIOCB *acb = dbs->acb; dbs->acb = NULL; @@ -168,6 +174,8 @@ BlockDriverAIOCB *dma_bdrv_io( { DMAAIOCB *dbs = qemu_aio_get(&dma_aio_pool, bs, cb, opaque); + trace_dma_bdrv_io(dbs, bs, sector_num, to_dev); + dbs->acb = NULL; dbs->bs = bs; dbs->sg = sg; diff --git a/docs/memory.txt b/docs/memory.txt index 3fc1683d88..5bbee8e85d 100644 --- a/docs/memory.txt +++ b/docs/memory.txt @@ -7,7 +7,7 @@ machine. It attempts to allow modelling of: - ordinary RAM - memory-mapped I/O (MMIO) - memory controllers that can dynamically reroute physical memory regions - to different destinations + to different destinations The memory model provides support for @@ -121,7 +121,7 @@ pci (0-2^32-1) ram: ram@0x00000000-0xffffffff -The is a (simplified) PC memory map. The 4GB RAM block is mapped into the +This is a (simplified) PC memory map. The 4GB RAM block is mapped into the system address space via two aliases: "lomem" is a 1:1 mapping of the first 3.5GB; "himem" maps the last 0.5GB at address 4GB. This leaves 0.5GB for the so-called PCI hole, that allows a 32-bit PCI bus to exist in a system with @@ -164,7 +164,7 @@ various constraints can be supplied to control how these callbacks are called: - .impl.min_access_size, .impl.max_access_size define the access sizes (in bytes) supported by the *implementation*; other access sizes will be emulated using the ones available. For example a 4-byte write will be - emulated using four 1-byte write, if .impl.max_access_size = 1. + emulated using four 1-byte writes, if .impl.max_access_size = 1. - .impl.valid specifies that the *implementation* only supports unaligned accesses; unaligned accesses will be emulated by two aligned accesses. - .old_portio and .old_mmio can be used to ease porting from code using diff --git a/docs/specs/qcow2.txt b/docs/specs/qcow2.txt index e792953c8f..b6adcaddb7 100644 --- a/docs/specs/qcow2.txt +++ b/docs/specs/qcow2.txt @@ -253,7 +253,13 @@ Snapshot table entry: 36 - 39: Size of extra data in the table entry (used for future extensions of the format) - variable: Extra data for future extensions. Must be ignored. + variable: Extra data for future extensions. Unknown fields must be + ignored. Currently defined are (offset relative to snapshot + table entry): + + Byte 40 - 47: Size of the VM state in bytes. 0 if no VM + state is saved. If this field is present, + the 32-bit value in bytes 32-35 is ignored. variable: Unique ID string for the snapshot (not null terminated) diff --git a/docs/writing-qmp-commands.txt b/docs/writing-qmp-commands.txt new file mode 100644 index 0000000000..0472fc3914 --- /dev/null +++ b/docs/writing-qmp-commands.txt @@ -0,0 +1,642 @@ += How to write QMP commands using the QAPI framework = + +This document is a step-by-step guide on how to write new QMP commands using +the QAPI framework. It also shows how to implement new style HMP commands. + +This document doesn't discuss QMP protocol level details, nor does it dive +into the QAPI framework implementation. + +For an in-depth introduction to the QAPI framework, please refer to +docs/qapi-code-gen.txt. For documentation about the QMP protocol, please +check the files in QMP/. + +== Overview == + +Generally speaking, the following steps should be taken in order to write a +new QMP command. + +1. Write the command's and type(s) specification in the QAPI schema file + (qapi-schema.json in the root source directory) + +2. Write the QMP command itself, which is a regular C function. Preferably, + the command should be exported by some QEMU subsystem. But it can also be + added to the qmp.c file + +3. At this point the command can be tested under the QMP protocol + +4. Write the HMP command equivalent. This is not required and should only be + done if it does make sense to have the functionality in HMP. The HMP command + is implemented in terms of the QMP command + +The following sections will demonstrate each of the steps above. We will start +very simple and get more complex as we progress. + +=== Testing === + +For all the examples in the next sections, the test setup is the same and is +shown here. + +First, QEMU should be started as: + +# /path/to/your/source/qemu [...] \ + -chardev socket,id=qmp,port=4444,host=localhost,server \ + -mon chardev=qmp,mode=control,pretty=on + +Then, in a different terminal: + +$ telnet localhost 4444 +Trying 127.0.0.1... +Connected to localhost. +Escape character is '^]'. +{ + "QMP": { + "version": { + "qemu": { + "micro": 50, + "minor": 15, + "major": 0 + }, + "package": "" + }, + "capabilities": [ + ] + } +} + +The above output is the QMP server saying you're connected. The server is +actually in capabilities negotiation mode. To enter in command mode type: + +{ "execute": "qmp_capabilities" } + +Then the server should respond: + +{ + "return": { + } +} + +Which is QMP's way of saying "the latest command executed OK and didn't return +any data". Now you're ready to enter the QMP example commands as explained in +the following sections. + +== Writing a command that doesn't return data == + +That's the most simple QMP command that can be written. Usually, this kind of +command carries some meaningful action in QEMU but here it will just print +"Hello, world" to the standard output. + +Our command will be called "hello-world". It takes no arguments, nor does it +return any data. + +The first step is to add the following line to the bottom of the +qapi-schema.json file: + +{ 'command': 'hello-world' } + +The "command" keyword defines a new QMP command. It's an JSON object. All +schema entries are JSON objects. The line above will instruct the QAPI to +generate any prototypes and the necessary code to marshal and unmarshal +protocol data. + +The next step is to write the "hello-world" implementation. As explained +earlier, it's preferable for commands to live in QEMU subsystems. But +"hello-world" doesn't pertain to any, so we put its implementation in qmp.c: + +void qmp_hello_world(Error **errp) +{ + printf("Hello, world!\n"); +} + +There are a few things to be noticed: + +1. QMP command implementation functions must be prefixed with "qmp_" +2. qmp_hello_world() returns void, this is in accordance with the fact that the + command doesn't return any data +3. It takes an "Error **" argument. This is required. Later we will see how to + return errors and take additional arguments. The Error argument should not + be touched if the command doesn't return errors +4. We won't add the function's prototype. That's automatically done by the QAPI +5. Printing to the terminal is discouraged for QMP commands, we do it here + because it's the easiest way to demonstrate a QMP command + +Now a little hack is needed. As we're still using the old QMP server we need +to add the new command to its internal dispatch table. This step won't be +required in the near future. Open the qmp-commands.hx file and add the +following in the botton: + + { + .name = "hello-world", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_hello_world, + }, + +You're done. Now build qemu, run it as suggested in the "Testing" section, +and then type the following QMP command: + +{ "execute": "hello-world" } + +Then check the terminal running qemu and look for the "Hello, world" string. If +you don't see it then something went wrong. + +=== Arguments === + +Let's add an argument called "message" to our "hello-world" command. The new +argument will contain the string to be printed to stdout. It's an optional +argument, if it's not present we print our default "Hello, World" string. + +The first change we have to do is to modify the command specification in the +schema file to the following: + +{ 'command': 'hello-world', 'data': { '*message': 'str' } } + +Notice the new 'data' member in the schema. It's an JSON object whose each +element is an argument to the command in question. Also notice the asterisk, +it's used to mark the argument optional (that means that you shouldn't use it +for mandatory arguments). Finally, 'str' is the argument's type, which +stands for "string". The QAPI also supports integers, booleans, enumerations +and user defined types. + +Now, let's update our C implementation in qmp.c: + +void qmp_hello_world(bool has_message, const char *message, Error **errp) +{ + if (has_message) { + printf("%s\n", message); + } else { + printf("Hello, world\n"); + } +} + +There are two important details to be noticed: + +1. All optional arguments are accompanied by a 'has_' boolean, which is set + if the optional argument is present or false otherwise +2. The C implementation signature must follow the schema's argument ordering, + which is defined by the "data" member + +The last step is to update the qmp-commands.hx file: + + { + .name = "hello-world", + .args_type = "message:s?", + .mhandler.cmd_new = qmp_marshal_input_hello_world, + }, + +Notice that the "args_type" member got our "message" argument. The character +"s" stands for "string" and "?" means it's optional. This too must be ordered +according to the C implementation and schema file. You can look for more +examples in the qmp-commands.hx file if you need to define more arguments. + +Again, this step won't be required in the future. + +Time to test our new version of the "hello-world" command. Build qemu, run it as +described in the "Testing" section and then send two commands: + +{ "execute": "hello-world" } +{ + "return": { + } +} + +{ "execute": "hello-world", "arguments": { "message": "We love qemu" } } +{ + "return": { + } +} + +You should see "Hello, world" and "we love qemu" in the terminal running qemu, +if you don't see these strings, then something went wrong. + +=== Errors === + +QMP commands should use the error interface exported by the error.h header +file. The basic function used to set an error is the error_set() one. + +Let's say we don't accept the string "message" to contain the word "love". If +it does contain it, we want the "hello-world" command to the return the +InvalidParameter error. + +Only one change is required, and it's in the C implementation: + +void qmp_hello_world(bool has_message, const char *message, Error **errp) +{ + if (has_message) { + if (strstr(message, "love")) { + error_set(errp, QERR_INVALID_PARAMETER, "message"); + return; + } + printf("%s\n", message); + } else { + printf("Hello, world\n"); + } +} + +Let's test it. Build qemu, run it as defined in the "Testing" section, and +then issue the following command: + +{ "execute": "hello-world", "arguments": { "message": "we love qemu" } } + +The QMP server's response should be: + +{ + "error": { + "class": "InvalidParameter", + "desc": "Invalid parameter 'message'", + "data": { + "name": "message" + } + } +} + +Which is the InvalidParameter error. + +When you have to return an error but you're unsure what error to return or +which arguments an error takes, you should look at the qerror.h file. Note +that you might be required to add new errors if needed. + +FIXME: describe better the error API and how to add new errors. + +=== Command Documentation === + +There's only one step missing to make "hello-world"'s implementation complete, +and that's its documentation in the schema file. + +This is very important. No QMP command will be accepted in QEMU without proper +documentation. + +There are many examples of such documentation in the schema file already, but +here goes "hello-world"'s new entry for the qapi-schema.json file: + +## +# @hello-world +# +# Print a client provided string to the standard output stream. +# +# @message: #optional string to be printed +# +# Returns: Nothing on success. +# If @message contains "love", InvalidParameter +# +# Notes: if @message is not provided, the "Hello, world" string will +# be printed instead +# +# Since: <next qemu stable release, eg. 1.0> +## +{ 'command': 'hello-world', 'data': { '*message': 'str' } } + +Please, note that the "Returns" clause is optional if a command doesn't return +any data nor any errors. + +=== Implementing the HMP command === + +Now that the QMP command is in place, we can also make it available in the human +monitor (HMP). + +With the introduction of the QAPI, HMP commands make QMP calls. Most of the +time HMP commands are simple wrappers. All HMP commands implementation exist in +the hmp.c file. + +Here's the implementation of the "hello-world" HMP command: + +void hmp_hello_world(Monitor *mon, const QDict *qdict) +{ + const char *message = qdict_get_try_str(qdict, "message"); + Error *errp = NULL; + + qmp_hello_world(!!message, message, &errp); + if (error_is_set(&errp)) { + monitor_printf(mon, "%s\n", error_get_pretty(errp)); + error_free(errp); + return; + } +} + +Also, you have to add the function's prototype to the hmp.h file. + +There are three important points to be noticed: + +1. The "mon" and "qdict" arguments are mandatory for all HMP functions. The + former is the monitor object. The latter is how the monitor passes + arguments entered by the user to the command implementation +2. hmp_hello_world() performs error checking. In this example we just print + the error description to the user, but we could do more, like taking + different actions depending on the error qmp_hello_world() returns +3. The "errp" variable must be initialized to NULL before performing the + QMP call + +There's one last step to actually make the command available to monitor users, +we should add it to the hmp-commands.hx file: + + { + .name = "hello-world", + .args_type = "message:s?", + .params = "hello-world [message]", + .help = "Print message to the standard output", + .mhandler.cmd = hmp_hello_world, + }, + +STEXI +@item hello_world @var{message} +@findex hello_world +Print message to the standard output +ETEXI + +To test this you have to open a user monitor and issue the "hello-world" +command. It might be instructive to check the command's documentation with +HMP's "help" command. + +Please, check the "-monitor" command-line option to know how to open a user +monitor. + +== Writing a command that returns data == + +A QMP command is capable of returning any data the QAPI supports like integers, +strings, booleans, enumerations and user defined types. + +In this section we will focus on user defined types. Please, check the QAPI +documentation for information about the other types. + +=== User Defined Types === + +For this example we will write the query-alarm-clock command, which returns +information about QEMU's timer alarm. For more information about it, please +check the "-clock" command-line option. + +We want to return two pieces of information. The first one is the alarm clock's +name. The second one is when the next alarm will fire. The former information is +returned as a string, the latter is an integer in nanoseconds (which is not +very useful in practice, as the timer has probably already fired when the +information reaches the client). + +The best way to return that data is to create a new QAPI type, as shown below: + +## +# @QemuAlarmClock +# +# QEMU alarm clock information. +# +# @clock-name: The alarm clock method's name. +# +# @next-deadline: #optional The time (in nanoseconds) the next alarm will fire. +# +# Since: 1.0 +## +{ 'type': 'QemuAlarmClock', + 'data': { 'clock-name': 'str', '*next-deadline': 'int' } } + +The "type" keyword defines a new QAPI type. Its "data" member contains the +type's members. In this example our members are the "clock-name" and the +"next-deadline" one, which is optional. + +Now let's define the query-alarm-clock command: + +## +# @query-alarm-clock +# +# Return information about QEMU's alarm clock. +# +# Returns a @QemuAlarmClock instance describing the alarm clock method +# being currently used by QEMU (this is usually set by the '-clock' +# command-line option). +# +# Since: 1.0 +## +{ 'command': 'query-alarm-clock', 'returns': 'QemuAlarmClock' } + +Notice the "returns" keyword. As its name suggests, it's used to define the +data returned by a command. + +It's time to implement the qmp_query_alarm_clock() function, you can put it +in the qemu-timer.c file: + +QemuAlarmClock *qmp_query_alarm_clock(Error **errp) +{ + QemuAlarmClock *clock; + int64_t deadline; + + clock = g_malloc0(sizeof(*clock)); + + deadline = qemu_next_alarm_deadline(); + if (deadline > 0) { + clock->has_next_deadline = true; + clock->next_deadline = deadline; + } + clock->clock_name = g_strdup(alarm_timer->name); + + return clock; +} + +There are a number of things to be noticed: + +1. The QemuAlarmClock type is automatically generated by the QAPI framework, + its members correspond to the type's specification in the schema file +2. As specified in the schema file, the function returns a QemuAlarmClock + instance and takes no arguments (besides the "errp" one, which is mandatory + for all QMP functions) +3. The "clock" variable (which will point to our QAPI type instance) is + allocated by the regular g_malloc0() function. Note that we chose to + initialize the memory to zero. This is recomended for all QAPI types, as + it helps avoiding bad surprises (specially with booleans) +4. Remember that "next_deadline" is optional? All optional members have a + 'has_TYPE_NAME' member that should be properly set by the implementation, + as shown above +5. Even static strings, such as "alarm_timer->name", should be dynamically + allocated by the implementation. This is so because the QAPI also generates + a function to free its types and it cannot distinguish between dynamically + or statically allocated strings +6. You have to include the "qmp-commands.h" header file in qemu-timer.c, + otherwise qemu won't build + +The last step is to add the correspoding entry in the qmp-commands.hx file: + + { + .name = "query-alarm-clock", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_alarm_clock, + }, + +Time to test the new command. Build qemu, run it as described in the "Testing" +section and try this: + +{ "execute": "query-alarm-clock" } +{ + "return": { + "next-deadline": 2368219, + "clock-name": "dynticks" + } +} + +==== The HMP command ==== + +Here's the HMP counterpart of the query-alarm-clock command: + +void hmp_info_alarm_clock(Monitor *mon) +{ + QemuAlarmClock *clock; + Error *errp = NULL; + + clock = qmp_query_alarm_clock(&errp); + if (error_is_set(&errp)) { + monitor_printf(mon, "Could not query alarm clock information\n"); + error_free(errp); + return; + } + + monitor_printf(mon, "Alarm clock method in use: '%s'\n", clock->clock_name); + if (clock->has_next_deadline) { + monitor_printf(mon, "Next alarm will fire in %" PRId64 " nanoseconds\n", + clock->next_deadline); + } + + qapi_free_QemuAlarmClock(clock); +} + +It's important to notice that hmp_info_alarm_clock() calls +qapi_free_QemuAlarmClock() to free the data returned by qmp_query_alarm_clock(). +For user defined types, the QAPI will generate a qapi_free_QAPI_TYPE_NAME() +function and that's what you have to use to free the types you define and +qapi_free_QAPI_TYPE_NAMEList() for list types (explained in the next section). +If the QMP call returns a string, then you should g_free() to free it. + +Also note that hmp_info_alarm_clock() performs error handling. That's not +strictly required if you're sure the QMP function doesn't return errors, but +it's good practice to always check for errors. + +Another important detail is that HMP's "info" commands don't go into the +hmp-commands.hx. Instead, they go into the info_cmds[] table, which is defined +in the monitor.c file. The entry for the "info alarmclock" follows: + + { + .name = "alarmclock", + .args_type = "", + .params = "", + .help = "show information about the alarm clock", + .mhandler.info = hmp_info_alarm_clock, + }, + +To test this, run qemu and type "info alarmclock" in the user monitor. + +=== Returning Lists === + +For this example, we're going to return all available methods for the timer +alarm, which is pretty much what the command-line option "-clock ?" does, +except that we're also going to inform which method is in use. + +This first step is to define a new type: + +## +# @TimerAlarmMethod +# +# Timer alarm method information. +# +# @method-name: The method's name. +# +# @current: true if this alarm method is currently in use, false otherwise +# +# Since: 1.0 +## +{ 'type': 'TimerAlarmMethod', + 'data': { 'method-name': 'str', 'current': 'bool' } } + +The command will be called "query-alarm-methods", here is its schema +specification: + +## +# @query-alarm-methods +# +# Returns information about available alarm methods. +# +# Returns: a list of @TimerAlarmMethod for each method +# +# Since: 1.0 +## +{ 'command': 'query-alarm-methods', 'returns': ['TimerAlarmMethod'] } + +Notice the syntax for returning lists "'returns': ['TimerAlarmMethod']", this +should be read as "returns a list of TimerAlarmMethod instances". + +The C implementation follows: + +TimerAlarmMethodList *qmp_query_alarm_methods(Error **errp) +{ + TimerAlarmMethodList *method_list = NULL; + const struct qemu_alarm_timer *p; + bool current = true; + + for (p = alarm_timers; p->name; p++) { + TimerAlarmMethodList *info = g_malloc0(sizeof(*info)); + info->value = g_malloc0(sizeof(*info->value)); + info->value->method_name = g_strdup(p->name); + info->value->current = current; + + current = false; + + info->next = method_list; + method_list = info; + } + + return method_list; +} + +The most important difference from the previous examples is the +TimerAlarmMethodList type, which is automatically generated by the QAPI from +the TimerAlarmMethod type. + +Each list node is represented by a TimerAlarmMethodList instance. We have to +allocate it, and that's done inside the for loop: the "info" pointer points to +an allocated node. We also have to allocate the node's contents, which is +stored in its "value" member. In our example, the "value" member is a pointer +to an TimerAlarmMethod instance. + +Notice that the "current" variable is used as "true" only in the first +interation of the loop. That's because the alarm timer method in use is the +first element of the alarm_timers array. Also notice that QAPI lists are handled +by hand and we return the head of the list. + +To test this you have to add the corresponding qmp-commands.hx entry: + + { + .name = "query-alarm-methods", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_alarm_methods, + }, + +Now Build qemu, run it as explained in the "Testing" section and try our new +command: + +{ "execute": "query-alarm-methods" } +{ + "return": [ + { + "current": false, + "method-name": "unix" + }, + { + "current": true, + "method-name": "dynticks" + } + ] +} + +The HMP counterpart is a bit more complex than previous examples because it +has to traverse the list, it's shown below for reference: + +void hmp_info_alarm_methods(Monitor *mon) +{ + TimerAlarmMethodList *method_list, *method; + Error *errp = NULL; + + method_list = qmp_query_alarm_methods(&errp); + if (error_is_set(&errp)) { + monitor_printf(mon, "Could not query alarm methods\n"); + error_free(errp); + return; + } + + for (method = method_list; method; method = method->next) { + monitor_printf(mon, "%c %s\n", method->value->current ? '*' : ' ', + method->value->method_name); + } + + qapi_free_TimerAlarmMethodList(method_list); +} diff --git a/exec-memory.h b/exec-memory.h index 334219fe23..1cd92eec71 100644 --- a/exec-memory.h +++ b/exec-memory.h @@ -1,5 +1,5 @@ /* - * Internal memory managment interfaces + * Internal memory management interfaces * * Copyright 2011 Red Hat, Inc. and/or its affiliates * @@ -418,6 +418,7 @@ static PhysPageDesc *phys_page_find_alloc(target_phys_addr_t index, int alloc) pd = *lp; if (pd == NULL) { int i; + int first_index = index & ~(L2_SIZE - 1); if (!alloc) { return NULL; @@ -427,7 +428,7 @@ static PhysPageDesc *phys_page_find_alloc(target_phys_addr_t index, int alloc) for (i = 0; i < L2_SIZE; i++) { pd[i].phys_offset = IO_MEM_UNASSIGNED; - pd[i].region_offset = (index + i) << TARGET_PAGE_BITS; + pd[i].region_offset = (first_index + i) << TARGET_PAGE_BITS; } } @@ -497,9 +498,7 @@ static void code_gen_alloc(unsigned long tb_size) if (code_gen_buffer_size > (512 * 1024 * 1024)) code_gen_buffer_size = (512 * 1024 * 1024); #elif defined(__arm__) - /* Map the buffer below 32M, so we can use direct calls and branches */ - flags |= MAP_FIXED; - start = (void *) 0x01000000UL; + /* Keep the buffer no bigger than 16GB to branch between blocks */ if (code_gen_buffer_size > 16 * 1024 * 1024) code_gen_buffer_size = 16 * 1024 * 1024; #elif defined(__s390x__) @@ -1603,8 +1602,10 @@ void cpu_set_log(int log_flags) static char logfile_buf[4096]; setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf)); } -#elif !defined(_WIN32) - /* Win32 doesn't support line-buffering and requires size >= 2 */ +#elif defined(_WIN32) + /* Win32 doesn't support line-buffering, so use unbuffered output. */ + setvbuf(logfile, NULL, _IONBF, 0); +#else setvbuf(logfile, NULL, _IOLBF, 0); #endif log_append = 1; @@ -3570,6 +3571,63 @@ static CPUWriteMemoryFunc * const subpage_write[] = { &subpage_writel, }; +static uint32_t subpage_ram_readb(void *opaque, target_phys_addr_t addr) +{ + ram_addr_t raddr = addr; + void *ptr = qemu_get_ram_ptr(raddr); + return ldub_p(ptr); +} + +static void subpage_ram_writeb(void *opaque, target_phys_addr_t addr, + uint32_t value) +{ + ram_addr_t raddr = addr; + void *ptr = qemu_get_ram_ptr(raddr); + stb_p(ptr, value); +} + +static uint32_t subpage_ram_readw(void *opaque, target_phys_addr_t addr) +{ + ram_addr_t raddr = addr; + void *ptr = qemu_get_ram_ptr(raddr); + return lduw_p(ptr); +} + +static void subpage_ram_writew(void *opaque, target_phys_addr_t addr, + uint32_t value) +{ + ram_addr_t raddr = addr; + void *ptr = qemu_get_ram_ptr(raddr); + stw_p(ptr, value); +} + +static uint32_t subpage_ram_readl(void *opaque, target_phys_addr_t addr) +{ + ram_addr_t raddr = addr; + void *ptr = qemu_get_ram_ptr(raddr); + return ldl_p(ptr); +} + +static void subpage_ram_writel(void *opaque, target_phys_addr_t addr, + uint32_t value) +{ + ram_addr_t raddr = addr; + void *ptr = qemu_get_ram_ptr(raddr); + stl_p(ptr, value); +} + +static CPUReadMemoryFunc * const subpage_ram_read[] = { + &subpage_ram_readb, + &subpage_ram_readw, + &subpage_ram_readl, +}; + +static CPUWriteMemoryFunc * const subpage_ram_write[] = { + &subpage_ram_writeb, + &subpage_ram_writew, + &subpage_ram_writel, +}; + static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end, ram_addr_t memory, ram_addr_t region_offset) { @@ -3583,8 +3641,9 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end, printf("%s: %p start %08x end %08x idx %08x eidx %08x mem %ld\n", __func__, mmio, start, end, idx, eidx, memory); #endif - if ((memory & ~TARGET_PAGE_MASK) == IO_MEM_RAM) - memory = IO_MEM_UNASSIGNED; + if ((memory & ~TARGET_PAGE_MASK) == IO_MEM_RAM) { + memory = IO_MEM_SUBPAGE_RAM; + } memory = (memory >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); for (; idx <= eidx; idx++) { mmio->sub_io_index[idx] = memory; @@ -3817,6 +3876,9 @@ static void io_mem_init(void) cpu_register_io_memory_fixed(IO_MEM_NOTDIRTY, error_mem_read, notdirty_mem_write, NULL, DEVICE_NATIVE_ENDIAN); + cpu_register_io_memory_fixed(IO_MEM_SUBPAGE_RAM, subpage_ram_read, + subpage_ram_write, NULL, + DEVICE_NATIVE_ENDIAN); for (i=0; i<5; i++) io_mem_used[i] = 1; diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index 1928da2525..a85ecd30b0 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -112,10 +112,10 @@ typedef struct FileOperations ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *, const struct iovec *, int, off_t); int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *); - int (*fstat)(FsContext *, V9fsFidOpenState *, struct stat *); + int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *); int (*rename)(FsContext *, const char *, const char *); int (*truncate)(FsContext *, V9fsPath *, off_t); - int (*fsync)(FsContext *, V9fsFidOpenState *, int); + int (*fsync)(FsContext *, int, V9fsFidOpenState *, int); int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf); ssize_t (*lgetxattr)(FsContext *, V9fsPath *, const char *, void *, size_t); diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index 7fd2aa7793..6684f7ea90 100644 --- a/fsdev/qemu-fsdev.c +++ b/fsdev/qemu-fsdev.c @@ -23,7 +23,9 @@ static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries = static FsDriverTable FsDrivers[] = { { .name = "local", .ops = &local_ops}, +#ifdef CONFIG_OPEN_BY_HANDLE { .name = "handle", .ops = &handle_ops}, +#endif { .name = "synth", .ops = &synth_ops}, }; @@ -2678,7 +2678,7 @@ gdb_handlesig (CPUState *env, int sig) } else if (n == 0 || errno != EAGAIN) { - /* XXX: Connection closed. Should probably wait for annother + /* XXX: Connection closed. Should probably wait for another connection before continuing. */ return sig; } diff --git a/hmp-commands.hx b/hmp-commands.hx index 089c1ac23d..14838b7fae 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -57,8 +57,7 @@ ETEXI .args_type = "device:B,size:o", .params = "device size", .help = "resize a block image", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_resize, + .mhandler.cmd = hmp_block_resize, }, STEXI @@ -304,8 +303,7 @@ ETEXI .args_type = "", .params = "", .help = "resume emulation", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_cont, + .mhandler.cmd = hmp_cont, }, STEXI @@ -689,8 +687,7 @@ ETEXI .args_type = "val:l,size:i,filename:s", .params = "addr size file", .help = "save to disk virtual memory dump starting at 'addr' of size 'size'", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_memory_save, + .mhandler.cmd = hmp_memsave, }, STEXI @@ -704,8 +701,7 @@ ETEXI .args_type = "val:l,size:i,filename:s", .params = "addr size file", .help = "save to disk physical memory dump starting at 'addr' of size 'size'", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_physical_memory_save, + .mhandler.cmd = hmp_pmemsave, }, STEXI @@ -739,8 +735,7 @@ ETEXI .args_type = "", .params = "", .help = "inject an NMI on all guest's CPUs", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_inject_nmi, + .mhandler.cmd = hmp_inject_nmi, }, #endif STEXI @@ -776,8 +771,7 @@ ETEXI .args_type = "", .params = "", .help = "cancel the current VM migration", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate_cancel, + .mhandler.cmd = hmp_migrate_cancel, }, STEXI @@ -792,8 +786,7 @@ ETEXI .params = "value", .help = "set maximum speed (in bytes) for migrations. " "Defaults to MB if no size suffix is specified, ie. B/K/M/G/T", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate_set_speed, + .mhandler.cmd = hmp_migrate_set_speed, }, STEXI @@ -807,8 +800,7 @@ ETEXI .args_type = "value:T", .params = "value", .help = "set maximum tolerated downtime (in seconds) for migrations", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate_set_downtime, + .mhandler.cmd = hmp_migrate_set_downtime, }, STEXI @@ -845,7 +837,7 @@ ETEXI "If format is specified, the snapshot file will\n\t\t\t" "be created in that format. Otherwise the\n\t\t\t" "snapshot will be internal! (currently unsupported)", - .mhandler.cmd_new = do_snapshot_blkdev, + .mhandler.cmd = hmp_snapshot_blkdev, }, STEXI @@ -860,9 +852,10 @@ ETEXI .args_type = "pci_addr:s,opts:s", .params = "[[<domain>:]<bus>:]<slot>\n" "[file=file][,if=type][,bus=n]\n" - "[,unit=m][,media=d][index=i]\n" + "[,unit=m][,media=d][,index=i]\n" "[,cyls=c,heads=h,secs=s[,trans=t]]\n" - "[snapshot=on|off][,cache=on|off]", + "[,snapshot=on|off][,cache=on|off]\n" + "[,readonly=on|off][,copy-on-read=on|off]", .help = "add drive to PCI storage controller", .mhandler.cmd = drive_hot_add, }, @@ -922,7 +915,7 @@ ETEXI "<tlb header> = 32bit x 4\n\t\t\t" "<tlb header prefix> = 32bit x 4", .user_print = pcie_aer_inject_error_print, - .mhandler.cmd_new = do_pcie_aer_inejct_error, + .mhandler.cmd_new = do_pcie_aer_inject_error, }, STEXI @@ -1025,9 +1018,7 @@ ETEXI .args_type = "value:M", .params = "target", .help = "request VM to change its memory allocation (in MB)", - .user_print = monitor_user_noop, - .mhandler.cmd_async = do_balloon, - .flags = MONITOR_CMD_ASYNC, + .mhandler.cmd = hmp_balloon, }, STEXI @@ -1041,8 +1032,7 @@ ETEXI .args_type = "name:s,up:b", .params = "name on|off", .help = "change the link status of a network adapter", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_set_link, + .mhandler.cmd = hmp_set_link, }, STEXI @@ -1202,8 +1192,22 @@ ETEXI .args_type = "device:B,password:s", .params = "block_passwd device password", .help = "set the password of encrypted block devices", + .mhandler.cmd = hmp_block_passwd, + }, + +STEXI +@item block_set_io_throttle @var{device} @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +@findex block_set_io_throttle +Change I/O throttle limits for a block drive to @var{bps} @var{bps_rd} @var{bps_wr} @var{iops} @var{iops_rd} @var{iops_wr} +ETEXI + + { + .name = "block_set_io_throttle", + .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", + .params = "device bps bps_rd bps_wr iops iops_rd iops_wr", + .help = "change I/O throttle limits for a block drive", .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_set_passwd, + .mhandler.cmd_new = do_block_set_io_throttle, }, STEXI @@ -14,6 +14,14 @@ #include "hmp.h" #include "qmp-commands.h" +static void hmp_handle_error(Monitor *mon, Error **errp) +{ + if (error_is_set(errp)) { + monitor_printf(mon, "%s\n", error_get_pretty(*errp)); + error_free(*errp); + } +} + void hmp_info_name(Monitor *mon) { NameInfo *info; @@ -216,6 +224,16 @@ void hmp_info_block(Monitor *mon) info->value->inserted->ro, info->value->inserted->drv, info->value->inserted->encrypted); + + monitor_printf(mon, " bps=%" PRId64 " bps_rd=%" PRId64 + " bps_wr=%" PRId64 " iops=%" PRId64 + " iops_rd=%" PRId64 " iops_wr=%" PRId64, + info->value->inserted->bps, + info->value->inserted->bps_rd, + info->value->inserted->bps_wr, + info->value->inserted->iops, + info->value->inserted->iops_rd, + info->value->inserted->iops_wr); } else { monitor_printf(mon, " [not inserted]"); } @@ -521,3 +539,143 @@ void hmp_cpu(Monitor *mon, const QDict *qdict) monitor_printf(mon, "invalid CPU index\n"); } } + +void hmp_memsave(Monitor *mon, const QDict *qdict) +{ + uint32_t size = qdict_get_int(qdict, "size"); + const char *filename = qdict_get_str(qdict, "filename"); + uint64_t addr = qdict_get_int(qdict, "val"); + Error *errp = NULL; + + qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp); + hmp_handle_error(mon, &errp); +} + +void hmp_pmemsave(Monitor *mon, const QDict *qdict) +{ + uint32_t size = qdict_get_int(qdict, "size"); + const char *filename = qdict_get_str(qdict, "filename"); + uint64_t addr = qdict_get_int(qdict, "val"); + Error *errp = NULL; + + qmp_pmemsave(addr, size, filename, &errp); + hmp_handle_error(mon, &errp); +} + +static void hmp_cont_cb(void *opaque, int err) +{ + Monitor *mon = opaque; + + if (!err) { + hmp_cont(mon, NULL); + } +} + +void hmp_cont(Monitor *mon, const QDict *qdict) +{ + Error *errp = NULL; + + qmp_cont(&errp); + if (error_is_set(&errp)) { + if (error_is_type(errp, QERR_DEVICE_ENCRYPTED)) { + const char *device; + + /* The device is encrypted. Ask the user for the password + and retry */ + + device = error_get_field(errp, "device"); + assert(device != NULL); + + monitor_read_block_device_key(mon, device, hmp_cont_cb, mon); + error_free(errp); + return; + } + hmp_handle_error(mon, &errp); + } +} + +void hmp_inject_nmi(Monitor *mon, const QDict *qdict) +{ + Error *errp = NULL; + + qmp_inject_nmi(&errp); + hmp_handle_error(mon, &errp); +} + +void hmp_set_link(Monitor *mon, const QDict *qdict) +{ + const char *name = qdict_get_str(qdict, "name"); + int up = qdict_get_bool(qdict, "up"); + Error *errp = NULL; + + qmp_set_link(name, up, &errp); + hmp_handle_error(mon, &errp); +} + +void hmp_block_passwd(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + const char *password = qdict_get_str(qdict, "password"); + Error *errp = NULL; + + qmp_block_passwd(device, password, &errp); + hmp_handle_error(mon, &errp); +} + +void hmp_balloon(Monitor *mon, const QDict *qdict) +{ + int64_t value = qdict_get_int(qdict, "value"); + Error *errp = NULL; + + qmp_balloon(value, &errp); + if (error_is_set(&errp)) { + monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp)); + error_free(errp); + } +} + +void hmp_block_resize(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + int64_t size = qdict_get_int(qdict, "size"); + Error *errp = NULL; + + qmp_block_resize(device, size, &errp); + hmp_handle_error(mon, &errp); +} + +void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + const char *filename = qdict_get_try_str(qdict, "snapshot-file"); + const char *format = qdict_get_try_str(qdict, "format"); + Error *errp = NULL; + + if (!filename) { + /* In the future, if 'snapshot-file' is not specified, the snapshot + will be taken internally. Today it's actually required. */ + error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file"); + hmp_handle_error(mon, &errp); + return; + } + + qmp_blockdev_snapshot_sync(device, filename, !!format, format, &errp); + hmp_handle_error(mon, &errp); +} + +void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) +{ + qmp_migrate_cancel(NULL); +} + +void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) +{ + double value = qdict_get_double(qdict, "value"); + qmp_migrate_set_downtime(value, NULL); +} + +void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) +{ + int64_t value = qdict_get_int(qdict, "value"); + qmp_migrate_set_speed(value, NULL); +} @@ -37,5 +37,17 @@ void hmp_stop(Monitor *mon, const QDict *qdict); void hmp_system_reset(Monitor *mon, const QDict *qdict); void hmp_system_powerdown(Monitor *mon, const QDict *qdict); void hmp_cpu(Monitor *mon, const QDict *qdict); +void hmp_memsave(Monitor *mon, const QDict *qdict); +void hmp_pmemsave(Monitor *mon, const QDict *qdict); +void hmp_cont(Monitor *mon, const QDict *qdict); +void hmp_inject_nmi(Monitor *mon, const QDict *qdict); +void hmp_set_link(Monitor *mon, const QDict *qdict); +void hmp_block_passwd(Monitor *mon, const QDict *qdict); +void hmp_balloon(Monitor *mon, const QDict *qdict); +void hmp_block_resize(Monitor *mon, const QDict *qdict); +void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict); +void hmp_migrate_cancel(Monitor *mon, const QDict *qdict); +void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict); +void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict); #endif diff --git a/hppa-dis.c b/hppa-dis.c index 435da73553..420a7d22d0 100644 --- a/hppa-dis.c +++ b/hppa-dis.c @@ -564,7 +564,7 @@ If not, see <http://www.gnu.org/licenses/>. */ */ /* There are two kinds of delay slot nullification: normal which is - * controled by the nullification bit, and conditional, which depends + * controlled by the nullification bit, and conditional, which depends * on the direction of the branch and its success or failure. * * NONE is unfortunately #defined in the hiux system include files. diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c index 9b6d47d91d..3d188284ba 100644 --- a/hw/9pfs/codir.c +++ b/hw/9pfs/codir.c @@ -90,7 +90,7 @@ int v9fs_co_mkdir(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, V9fsState *s = pdu->s; if (v9fs_request_cancelled(pdu)) { - return -EINTR;; + return -EINTR; } cred_init(&cred); cred.fc_mode = mode; @@ -124,7 +124,7 @@ int v9fs_co_opendir(V9fsPDU *pdu, V9fsFidState *fidp) V9fsState *s = pdu->s; if (v9fs_request_cancelled(pdu)) { - return -EINTR;; + return -EINTR; } v9fs_path_read_lock(s); v9fs_co_run_in_worker( @@ -152,7 +152,7 @@ int v9fs_co_closedir(V9fsPDU *pdu, V9fsFidOpenState *fs) V9fsState *s = pdu->s; if (v9fs_request_cancelled(pdu)) { - return -EINTR;; + return -EINTR; } v9fs_co_run_in_worker( { diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c index 586b0382f6..b15838c1e6 100644 --- a/hw/9pfs/cofile.c +++ b/hw/9pfs/cofile.c @@ -71,7 +71,7 @@ int v9fs_co_fstat(V9fsPDU *pdu, V9fsFidState *fidp, struct stat *stbuf) } v9fs_co_run_in_worker( { - err = s->ops->fstat(&s->ctx, &fidp->fs, stbuf); + err = s->ops->fstat(&s->ctx, fidp->fid_type, &fidp->fs, stbuf); if (err < 0) { err = -errno; } @@ -192,7 +192,7 @@ int v9fs_co_fsync(V9fsPDU *pdu, V9fsFidState *fidp, int datasync) } v9fs_co_run_in_worker( { - err = s->ops->fsync(&s->ctx, &fidp->fs, datasync); + err = s->ops->fsync(&s->ctx, fidp->fid_type, &fidp->fs, datasync); if (err < 0) { err = -errno; } diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h index c4b74b0221..c31c96578b 100644 --- a/hw/9pfs/virtio-9p-coth.h +++ b/hw/9pfs/virtio-9p-coth.h @@ -44,7 +44,7 @@ typedef struct V9fsThPool { qemu_coroutine_self()); \ qemu_bh_schedule(co_bh); \ /* \ - * yeild in qemu thread and re-enter back \ + * yield in qemu thread and re-enter back \ * in glib worker thread \ */ \ qemu_coroutine_yield(); \ diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index bba4c54762..cd343e1d81 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -33,13 +33,15 @@ static V9fsState *to_virtio_9p(VirtIODevice *vdev) static void virtio_9p_get_config(VirtIODevice *vdev, uint8_t *config) { + int len; struct virtio_9p_config *cfg; V9fsState *s = to_virtio_9p(vdev); - cfg = g_malloc0(sizeof(struct virtio_9p_config) + - s->tag_len); - stw_raw(&cfg->tag_len, s->tag_len); - memcpy(cfg->tag, s->tag, s->tag_len); + len = strlen(s->tag); + cfg = g_malloc0(sizeof(struct virtio_9p_config) + len); + stw_raw(&cfg->tag_len, len); + /* We don't copy the terminating null to config space */ + memcpy(cfg->tag, s->tag, len); memcpy(config, cfg, s->config_size); g_free(cfg); } @@ -96,20 +98,18 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) } len = strlen(conf->tag); - if (len > MAX_TAG_LEN) { + if (len > MAX_TAG_LEN - 1) { fprintf(stderr, "mount tag '%s' (%d bytes) is longer than " - "maximum (%d bytes)", conf->tag, len, MAX_TAG_LEN); + "maximum (%d bytes)", conf->tag, len, MAX_TAG_LEN - 1); exit(1); } - /* s->tag is non-NULL terminated string */ - s->tag = g_malloc(len); - memcpy(s->tag, conf->tag, len); - s->tag_len = len; + + s->tag = strdup(conf->tag); s->ctx.uid = -1; s->ops = fse->ops; s->vdev.get_features = virtio_9p_get_features; - s->config_size = sizeof(struct virtio_9p_config) + s->tag_len; + s->config_size = sizeof(struct virtio_9p_config) + len; s->vdev.get_config = virtio_9p_get_config; s->fid_list = NULL; qemu_co_rwlock_init(&s->rename_lock); @@ -176,7 +176,8 @@ static PCIDeviceInfo virtio_9p_info = { DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag), DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id), DEFINE_PROP_END_OF_LIST(), - } + }, + .qdev.reset = virtio_pci_reset, }; static void virtio_9p_register_devices(void) diff --git a/hw/9pfs/virtio-9p-handle.c b/hw/9pfs/virtio-9p-handle.c index 7644ae5ab9..b556e39702 100644 --- a/hw/9pfs/virtio-9p-handle.c +++ b/hw/9pfs/virtio-9p-handle.c @@ -45,7 +45,6 @@ struct handle_data { int handle_bytes; }; -#ifdef CONFIG_OPEN_BY_HANDLE static inline int name_to_handle(int dirfd, const char *name, struct file_handle *fh, int *mnt_id, int flags) { @@ -56,43 +55,11 @@ static inline int open_by_handle(int mountfd, const char *fh, int flags) { return open_by_handle_at(mountfd, (struct file_handle *)fh, flags); } -#else - -struct rpl_file_handle { - unsigned int handle_bytes; - int handle_type; - unsigned char handle[0]; -}; -#define file_handle rpl_file_handle - -#ifndef AT_REMOVEDIR -#define AT_REMOVEDIR 0x200 -#endif -#ifndef AT_EMPTY_PATH -#define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */ -#endif -#ifndef O_PATH -#define O_PATH 010000000 -#endif - -static inline int name_to_handle(int dirfd, const char *name, - struct file_handle *fh, int *mnt_id, int flags) -{ - errno = ENOSYS; - return -1; -} - -static inline int open_by_handle(int mountfd, const char *fh, int flags) -{ - errno = ENOSYS; - return -1; -} -#endif static int handle_update_file_cred(int dirfd, const char *name, FsCred *credp) { int fd, ret; - fd = openat(dirfd, name, O_NONBLOCK | O_NOFOLLOW);; + fd = openat(dirfd, name, O_NONBLOCK | O_NOFOLLOW); if (fd < 0) { return fd; } @@ -288,10 +255,17 @@ static int handle_mkdir(FsContext *fs_ctx, V9fsPath *dir_path, return ret; } -static int handle_fstat(FsContext *fs_ctx, V9fsFidOpenState *fs, - struct stat *stbuf) +static int handle_fstat(FsContext *fs_ctx, int fid_type, + V9fsFidOpenState *fs, struct stat *stbuf) { - return fstat(fs->fd, stbuf); + int fd; + + if (fid_type == P9_FID_DIR) { + fd = dirfd(fs->dir); + } else { + fd = fs->fd; + } + return fstat(fd, stbuf); } static int handle_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name, @@ -428,12 +402,21 @@ static int handle_remove(FsContext *ctx, const char *path) return -1; } -static int handle_fsync(FsContext *ctx, V9fsFidOpenState *fs, int datasync) +static int handle_fsync(FsContext *ctx, int fid_type, + V9fsFidOpenState *fs, int datasync) { + int fd; + + if (fid_type == P9_FID_DIR) { + fd = dirfd(fs->dir); + } else { + fd = fs->fd; + } + if (datasync) { - return qemu_fdatasync(fs->fd); + return qemu_fdatasync(fd); } else { - return fsync(fs->fd); + return fsync(fd); } } @@ -537,7 +520,7 @@ static int handle_name_to_path(FsContext *ctx, V9fsPath *dir_path, } fh = g_malloc(sizeof(struct file_handle) + data->handle_bytes); fh->handle_bytes = data->handle_bytes; - /* add a "./" at the begining of the path */ + /* add a "./" at the beginning of the path */ snprintf(buffer, PATH_MAX, "./%s", name); /* flag = 0 imply don't follow symlink */ ret = name_to_handle(dirfd, buffer, fh, &mnt_id, 0); diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c index 7f1c0894de..371a94dfff 100644 --- a/hw/9pfs/virtio-9p-local.c +++ b/hw/9pfs/virtio-9p-local.c @@ -366,11 +366,18 @@ out: return err; } -static int local_fstat(FsContext *fs_ctx, +static int local_fstat(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs, struct stat *stbuf) { - int err; - err = fstat(fs->fd, stbuf); + int err, fd; + + if (fid_type == P9_FID_DIR) { + fd = dirfd(fs->dir); + } else { + fd = fs->fd; + } + + err = fstat(fd, stbuf); if (err) { return err; } @@ -381,19 +388,19 @@ static int local_fstat(FsContext *fs_ctx, mode_t tmp_mode; dev_t tmp_dev; - if (fgetxattr(fs->fd, "user.virtfs.uid", + if (fgetxattr(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) { stbuf->st_uid = tmp_uid; } - if (fgetxattr(fs->fd, "user.virtfs.gid", + if (fgetxattr(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) { stbuf->st_gid = tmp_gid; } - if (fgetxattr(fs->fd, "user.virtfs.mode", + if (fgetxattr(fd, "user.virtfs.mode", &tmp_mode, sizeof(mode_t)) > 0) { stbuf->st_mode = tmp_mode; } - if (fgetxattr(fs->fd, "user.virtfs.rdev", + if (fgetxattr(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) { stbuf->st_rdev = tmp_dev; } @@ -583,8 +590,7 @@ static int local_utimensat(FsContext *s, V9fsPath *fs_path, char buffer[PATH_MAX]; char *path = fs_path->data; - return qemu_utimensat(AT_FDCWD, rpath(s, path, buffer), buf, - AT_SYMLINK_NOFOLLOW); + return qemu_utimens(rpath(s, path, buffer), buf); } static int local_remove(FsContext *ctx, const char *path) @@ -593,12 +599,21 @@ static int local_remove(FsContext *ctx, const char *path) return remove(rpath(ctx, path, buffer)); } -static int local_fsync(FsContext *ctx, V9fsFidOpenState *fs, int datasync) +static int local_fsync(FsContext *ctx, int fid_type, + V9fsFidOpenState *fs, int datasync) { + int fd; + + if (fid_type == P9_FID_DIR) { + fd = dirfd(fs->dir); + } else { + fd = fs->fd; + } + if (datasync) { - return qemu_fdatasync(fs->fd); + return qemu_fdatasync(fd); } else { - return fsync(fs->fd); + return fsync(fd); } } @@ -694,6 +709,7 @@ static int local_ioc_getversion(FsContext *ctx, V9fsPath *path, mode_t st_mode, uint64_t *st_gen) { int err; +#ifdef FS_IOC_GETVERSION V9fsFidOpenState fid_open; /* @@ -709,15 +725,22 @@ static int local_ioc_getversion(FsContext *ctx, V9fsPath *path, } err = ioctl(fid_open.fd, FS_IOC_GETVERSION, st_gen); local_close(ctx, &fid_open); +#else + err = -ENOTTY; +#endif return err; } static int local_init(FsContext *ctx) { - int err; + int err = 0; struct statfs stbuf; ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT; +#ifdef FS_IOC_GETVERSION + /* + * use ioc_getversion only if the iocl is definied + */ err = statfs(ctx->fs_root, &stbuf); if (!err) { switch (stbuf.f_type) { @@ -729,6 +752,7 @@ static int local_init(FsContext *ctx) break; } } +#endif return err; } diff --git a/hw/9pfs/virtio-9p-synth.c b/hw/9pfs/virtio-9p-synth.c index f573616363..92e0b09d38 100644 --- a/hw/9pfs/virtio-9p-synth.c +++ b/hw/9pfs/virtio-9p-synth.c @@ -166,7 +166,7 @@ static int v9fs_synth_lstat(FsContext *fs_ctx, return 0; } -static int v9fs_synth_fstat(FsContext *fs_ctx, +static int v9fs_synth_fstat(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs, struct stat *stbuf) { V9fsSynthOpenState *synth_open = fs->private; @@ -414,7 +414,8 @@ static int v9fs_synth_remove(FsContext *ctx, const char *path) return -1; } -static int v9fs_synth_fsync(FsContext *ctx, V9fsFidOpenState *fs, int datasync) +static int v9fs_synth_fsync(FsContext *ctx, int fid_type, + V9fsFidOpenState *fs, int datasync) { errno = ENOSYS; return 0; diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index 1b2fc5dfb6..36a862f1f1 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -23,6 +23,7 @@ #include "virtio-9p-xattr.h" #include "virtio-9p-coth.h" #include "trace.h" +#include "migration.h" int open_fd_hw; int total_open_fd; @@ -373,6 +374,19 @@ static void put_fid(V9fsPDU *pdu, V9fsFidState *fidp) * Don't free the fid if it is in reclaim list */ if (!fidp->ref && fidp->clunked) { + if (fidp->fid == pdu->s->root_fid) { + /* + * if the clunked fid is root fid then we + * have unmounted the fs on the client side. + * delete the migration blocker. Ideally, this + * should be hooked to transport close notification + */ + if (pdu->s->migration_blocker) { + migrate_del_blocker(pdu->s->migration_blocker); + error_free(pdu->s->migration_blocker); + pdu->s->migration_blocker = NULL; + } + } free_fid(pdu, fidp); } } @@ -509,6 +523,30 @@ static int v9fs_mark_fids_unreclaim(V9fsPDU *pdu, V9fsPath *path) return 0; } +static void virtfs_reset(V9fsPDU *pdu) +{ + V9fsState *s = pdu->s; + V9fsFidState *fidp = NULL; + + /* Free all fids */ + while (s->fid_list) { + fidp = s->fid_list; + s->fid_list = fidp->next; + + if (fidp->ref) { + fidp->clunked = 1; + } else { + free_fid(pdu, fidp); + } + } + if (fidp) { + /* One or more unclunked fids found... */ + error_report("9pfs:%s: One or more uncluncked fids " + "found during reset", __func__); + } + return; +} + #define P9_QID_TYPE_DIR 0x80 #define P9_QID_TYPE_SYMLINK 0x02 @@ -1182,6 +1220,8 @@ static void v9fs_version(void *opaque) pdu_unmarshal(pdu, offset, "ds", &s->msize, &version); trace_v9fs_version(pdu->tag, pdu->id, s->msize, version.data); + virtfs_reset(pdu); + if (!strcmp(version.data, "9P2000.u")) { s->proto_version = V9FS_PROTO_2000U; } else if (!strcmp(version.data, "9P2000.L")) { @@ -1235,6 +1275,11 @@ static void v9fs_attach(void *opaque) err = offset; trace_v9fs_attach_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path); + s->root_fid = fid; + /* disable migration */ + error_set(&s->migration_blocker, QERR_VIRTFS_FEATURE_BLOCKS_MIGRATION, + s->ctx.fs_root, s->tag); + migrate_add_blocker(s->migration_blocker); out: put_fid(pdu, fidp); out_nofid: @@ -1447,7 +1492,7 @@ static void v9fs_walk(void *opaque) int32_t fid, newfid; V9fsString *wnames = NULL; V9fsFidState *fidp; - V9fsFidState *newfidp = NULL;; + V9fsFidState *newfidp = NULL; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; @@ -2353,7 +2398,7 @@ static void v9fs_link(void *opaque) V9fsState *s = pdu->s; int32_t dfid, oldfid; V9fsFidState *dfidp, *oldfidp; - V9fsString name;; + V9fsString name; size_t offset = 7; int err = 0; diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h index 7f883563d6..8b612da529 100644 --- a/hw/9pfs/virtio-9p.h +++ b/hw/9pfs/virtio-9p.h @@ -246,8 +246,7 @@ typedef struct V9fsState V9fsFidState *fid_list; FileOperations *ops; FsContext ctx; - uint16_t tag_len; - uint8_t *tag; + char *tag; size_t config_size; enum p9_proto_version proto_version; int32_t msize; @@ -256,6 +255,8 @@ typedef struct V9fsState * on rename. */ CoRwlock rename_lock; + int32_t root_fid; + Error *migration_blocker; } V9fsState; typedef struct V9fsStatState { diff --git a/hw/a9mpcore.c b/hw/a9mpcore.c index 6f108f4ce2..cd2985f421 100644 --- a/hw/a9mpcore.c +++ b/hw/a9mpcore.c @@ -2,28 +2,197 @@ * Cortex-A9MPCore internal peripheral emulation. * * Copyright (c) 2009 CodeSourcery. - * Written by Paul Brook + * Copyright (c) 2011 Linaro Limited. + * Written by Paul Brook, Peter Maydell. * * This code is licensed under the GPL. */ -/* 64 external IRQ lines. */ +#include "sysbus.h" + +/* Configuration for arm_gic.c: + * number of external IRQ lines, max number of CPUs, how to ID current CPU + */ #define GIC_NIRQ 96 -#include "mpcore.c" +#define NCPU 4 + +static inline int +gic_get_current_cpu(void) +{ + return cpu_single_env->cpu_index; +} + +#include "arm_gic.c" + +/* A9MP private memory region. */ + +typedef struct a9mp_priv_state { + gic_state gic; + uint32_t scu_control; + uint32_t old_timer_status[8]; + uint32_t num_cpu; + qemu_irq *timer_irq; + MemoryRegion scu_iomem; + MemoryRegion ptimer_iomem; + MemoryRegion container; + DeviceState *mptimer; +} a9mp_priv_state; + +static uint64_t a9_scu_read(void *opaque, target_phys_addr_t offset, + unsigned size) +{ + a9mp_priv_state *s = (a9mp_priv_state *)opaque; + switch (offset) { + case 0x00: /* Control */ + return s->scu_control; + case 0x04: /* Configuration */ + return (((1 << s->num_cpu) - 1) << 4) | (s->num_cpu - 1); + case 0x08: /* CPU Power Status */ + return 0; + case 0x0c: /* Invalidate All Registers In Secure State */ + return 0; + case 0x40: /* Filtering Start Address Register */ + case 0x44: /* Filtering End Address Register */ + /* RAZ/WI, like an implementation with only one AXI master */ + return 0; + case 0x50: /* SCU Access Control Register */ + case 0x54: /* SCU Non-secure Access Control Register */ + /* unimplemented, fall through */ + default: + return 0; + } +} + +static void a9_scu_write(void *opaque, target_phys_addr_t offset, + uint64_t value, unsigned size) +{ + a9mp_priv_state *s = (a9mp_priv_state *)opaque; + switch (offset) { + case 0x00: /* Control */ + s->scu_control = value & 1; + break; + case 0x4: /* Configuration: RO */ + break; + case 0x0c: /* Invalidate All Registers In Secure State */ + /* no-op as we do not implement caches */ + break; + case 0x40: /* Filtering Start Address Register */ + case 0x44: /* Filtering End Address Register */ + /* RAZ/WI, like an implementation with only one AXI master */ + break; + case 0x8: /* CPU Power Status */ + case 0x50: /* SCU Access Control Register */ + case 0x54: /* SCU Non-secure Access Control Register */ + /* unimplemented, fall through */ + default: + break; + } +} + +static const MemoryRegionOps a9_scu_ops = { + .read = a9_scu_read, + .write = a9_scu_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void a9mpcore_timer_irq_handler(void *opaque, int irq, int level) +{ + a9mp_priv_state *s = (a9mp_priv_state *)opaque; + if (level && !s->old_timer_status[irq]) { + gic_set_pending_private(&s->gic, irq >> 1, 29 + (irq & 1)); + } + s->old_timer_status[irq] = level; +} + +static void a9mp_priv_reset(DeviceState *dev) +{ + a9mp_priv_state *s = FROM_SYSBUSGIC(a9mp_priv_state, sysbus_from_qdev(dev)); + int i; + s->scu_control = 0; + for (i = 0; i < ARRAY_SIZE(s->old_timer_status); i++) { + s->old_timer_status[i] = 0; + } +} + +static int a9mp_priv_init(SysBusDevice *dev) +{ + a9mp_priv_state *s = FROM_SYSBUSGIC(a9mp_priv_state, dev); + SysBusDevice *busdev; + int i; + + if (s->num_cpu > NCPU) { + hw_error("a9mp_priv_init: num-cpu may not be more than %d\n", NCPU); + } + + gic_init(&s->gic, s->num_cpu); + + s->mptimer = qdev_create(NULL, "arm_mptimer"); + qdev_prop_set_uint32(s->mptimer, "num-cpu", s->num_cpu); + qdev_init_nofail(s->mptimer); + busdev = sysbus_from_qdev(s->mptimer); + + /* Memory map (addresses are offsets from PERIPHBASE): + * 0x0000-0x00ff -- Snoop Control Unit + * 0x0100-0x01ff -- GIC CPU interface + * 0x0200-0x02ff -- Global Timer + * 0x0300-0x05ff -- nothing + * 0x0600-0x06ff -- private timers and watchdogs + * 0x0700-0x0fff -- nothing + * 0x1000-0x1fff -- GIC Distributor + * + * We should implement the global timer but don't currently do so. + */ + memory_region_init(&s->container, "a9mp-priv-container", 0x2000); + memory_region_init_io(&s->scu_iomem, &a9_scu_ops, s, "a9mp-scu", 0x100); + memory_region_add_subregion(&s->container, 0, &s->scu_iomem); + /* GIC CPU interface */ + memory_region_add_subregion(&s->container, 0x100, &s->gic.cpuiomem[0]); + /* Note that the A9 exposes only the "timer/watchdog for this core" + * memory region, not the "timer/watchdog for core X" ones 11MPcore has. + */ + memory_region_add_subregion(&s->container, 0x600, + sysbus_mmio_get_region(busdev, 0)); + memory_region_add_subregion(&s->container, 0x620, + sysbus_mmio_get_region(busdev, 1)); + memory_region_add_subregion(&s->container, 0x1000, &s->gic.iomem); + + sysbus_init_mmio(dev, &s->container); + + /* Wire up the interrupt from each watchdog and timer. */ + s->timer_irq = qemu_allocate_irqs(a9mpcore_timer_irq_handler, + s, (s->num_cpu + 1) * 2); + for (i = 0; i < s->num_cpu * 2; i++) { + sysbus_connect_irq(busdev, i, s->timer_irq[i]); + } + return 0; +} + +static const VMStateDescription vmstate_a9mp_priv = { + .name = "a9mpcore_priv", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32(scu_control, a9mp_priv_state), + VMSTATE_UINT32_ARRAY(old_timer_status, a9mp_priv_state, 8), + VMSTATE_END_OF_LIST() + } +}; -static SysBusDeviceInfo mpcore_priv_info = { - .init = mpcore_priv_init, +static SysBusDeviceInfo a9mp_priv_info = { + .init = a9mp_priv_init, .qdev.name = "a9mpcore_priv", - .qdev.size = sizeof(mpcore_priv_state), + .qdev.size = sizeof(a9mp_priv_state), + .qdev.vmsd = &vmstate_a9mp_priv, + .qdev.reset = a9mp_priv_reset, .qdev.props = (Property[]) { - DEFINE_PROP_UINT32("num-cpu", mpcore_priv_state, num_cpu, 1), + DEFINE_PROP_UINT32("num-cpu", a9mp_priv_state, num_cpu, 1), DEFINE_PROP_END_OF_LIST(), } }; -static void a9mpcore_register_devices(void) +static void a9mp_register_devices(void) { - sysbus_register_withprop(&mpcore_priv_info); + sysbus_register_withprop(&a9mp_priv_info); } -device_init(a9mpcore_register_devices) +device_init(a9mp_register_devices) @@ -304,7 +304,7 @@ void acpi_pm_tmr_calc_overflow_time(ACPIPMTimer *tmr) uint32_t acpi_pm_tmr_get(ACPIPMTimer *tmr) { - uint32_t d = acpi_pm_tmr_get_clock();; + uint32_t d = acpi_pm_tmr_get_clock(); return d & 0xffffff; } diff --git a/hw/alpha_dp264.c b/hw/alpha_dp264.c index fcc20e973d..598b830e92 100644 --- a/hw/alpha_dp264.c +++ b/hw/alpha_dp264.c @@ -2,7 +2,7 @@ * QEMU Alpha DP264/CLIPPER hardware system emulator. * * Choose CLIPPER IRQ mappings over, say, DP264, MONET, or WEBBRICK - * variants because CLIPPER doesn't have an SMC669 SuperIO controler + * variants because CLIPPER doesn't have an SMC669 SuperIO controller * that we need to emulate as well. */ diff --git a/hw/arm11mpcore.c b/hw/arm11mpcore.c index 32ecf98309..bc0457e58b 100644 --- a/hw/arm11mpcore.c +++ b/hw/arm11mpcore.c @@ -7,11 +7,139 @@ * This code is licensed under the GPL. */ +#include "sysbus.h" +#include "qemu-timer.h" + /* ??? The MPCore TRM says the on-chip controller has 224 external IRQ lines (+ 32 internal). However my test chip only exposes/reports 32. More importantly Linux falls over if more than 32 are present! */ #define GIC_NIRQ 64 -#include "mpcore.c" + +#define NCPU 4 + +static inline int +gic_get_current_cpu(void) +{ + return cpu_single_env->cpu_index; +} + +#include "arm_gic.c" + +/* MPCore private memory region. */ + +typedef struct mpcore_priv_state { + gic_state gic; + uint32_t scu_control; + int iomemtype; + uint32_t old_timer_status[8]; + uint32_t num_cpu; + qemu_irq *timer_irq; + MemoryRegion iomem; + MemoryRegion container; + DeviceState *mptimer; +} mpcore_priv_state; + +/* Per-CPU private memory mapped IO. */ + +static uint64_t mpcore_scu_read(void *opaque, target_phys_addr_t offset, + unsigned size) +{ + mpcore_priv_state *s = (mpcore_priv_state *)opaque; + int id; + offset &= 0xff; + /* SCU */ + switch (offset) { + case 0x00: /* Control. */ + return s->scu_control; + case 0x04: /* Configuration. */ + id = ((1 << s->num_cpu) - 1) << 4; + return id | (s->num_cpu - 1); + case 0x08: /* CPU status. */ + return 0; + case 0x0c: /* Invalidate all. */ + return 0; + default: + hw_error("mpcore_priv_read: Bad offset %x\n", (int)offset); + } +} + +static void mpcore_scu_write(void *opaque, target_phys_addr_t offset, + uint64_t value, unsigned size) +{ + mpcore_priv_state *s = (mpcore_priv_state *)opaque; + offset &= 0xff; + /* SCU */ + switch (offset) { + case 0: /* Control register. */ + s->scu_control = value & 1; + break; + case 0x0c: /* Invalidate all. */ + /* This is a no-op as cache is not emulated. */ + break; + default: + hw_error("mpcore_priv_read: Bad offset %x\n", (int)offset); + } +} + +static const MemoryRegionOps mpcore_scu_ops = { + .read = mpcore_scu_read, + .write = mpcore_scu_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void mpcore_timer_irq_handler(void *opaque, int irq, int level) +{ + mpcore_priv_state *s = (mpcore_priv_state *)opaque; + if (level && !s->old_timer_status[irq]) { + gic_set_pending_private(&s->gic, irq >> 1, 29 + (irq & 1)); + } + s->old_timer_status[irq] = level; +} + +static void mpcore_priv_map_setup(mpcore_priv_state *s) +{ + int i; + SysBusDevice *busdev = sysbus_from_qdev(s->mptimer); + memory_region_init(&s->container, "mpcode-priv-container", 0x2000); + memory_region_init_io(&s->iomem, &mpcore_scu_ops, s, "mpcore-scu", 0x100); + memory_region_add_subregion(&s->container, 0, &s->iomem); + /* GIC CPU interfaces: "current CPU" at 0x100, then specific CPUs + * at 0x200, 0x300... + */ + for (i = 0; i < (s->num_cpu + 1); i++) { + target_phys_addr_t offset = 0x100 + (i * 0x100); + memory_region_add_subregion(&s->container, offset, &s->gic.cpuiomem[i]); + } + /* Add the regions for timer and watchdog for "current CPU" and + * for each specific CPU. + */ + s->timer_irq = qemu_allocate_irqs(mpcore_timer_irq_handler, + s, (s->num_cpu + 1) * 2); + for (i = 0; i < (s->num_cpu + 1) * 2; i++) { + /* Timers at 0x600, 0x700, ...; watchdogs at 0x620, 0x720, ... */ + target_phys_addr_t offset = 0x600 + (i >> 1) * 0x100 + (i & 1) * 0x20; + memory_region_add_subregion(&s->container, offset, + sysbus_mmio_get_region(busdev, i)); + } + memory_region_add_subregion(&s->container, 0x1000, &s->gic.iomem); + /* Wire up the interrupt from each watchdog and timer. */ + for (i = 0; i < s->num_cpu * 2; i++) { + sysbus_connect_irq(busdev, i, s->timer_irq[i]); + } +} + +static int mpcore_priv_init(SysBusDevice *dev) +{ + mpcore_priv_state *s = FROM_SYSBUSGIC(mpcore_priv_state, dev); + + gic_init(&s->gic, s->num_cpu); + s->mptimer = qdev_create(NULL, "arm_mptimer"); + qdev_prop_set_uint32(s->mptimer, "num-cpu", s->num_cpu); + qdev_init_nofail(s->mptimer); + mpcore_priv_map_setup(s); + sysbus_init_mmio(dev, &s->container); + return 0; +} /* Dummy PIC to route IRQ lines. The baseboard has 4 independent IRQ controllers. The output of these, plus some of the raw input lines diff --git a/hw/arm_gic.c b/hw/arm_gic.c index f3f35164d0..9b521195a5 100644 --- a/hw/arm_gic.c +++ b/hw/arm_gic.c @@ -103,7 +103,14 @@ typedef struct gic_state int num_cpu; #endif - MemoryRegion iomem; + MemoryRegion iomem; /* Distributor */ +#ifndef NVIC + /* This is just so we can have an opaque pointer which identifies + * both this GIC and which CPU interface we should be accessing. + */ + struct gic_state *backref[NCPU]; + MemoryRegion cpuiomem[NCPU+1]; /* CPU interfaces */ +#endif } gic_state; /* TODO: Many places that call this routine could be optimized. */ @@ -215,17 +222,26 @@ static void gic_complete_irq(gic_state * s, int cpu, int irq) int update = 0; int cm = 1 << cpu; DPRINTF("EOI %d\n", irq); + if (irq >= GIC_NIRQ) { + /* This handles two cases: + * 1. If software writes the ID of a spurious interrupt [ie 1023] + * to the GICC_EOIR, the GIC ignores that write. + * 2. If software writes the number of a non-existent interrupt + * this must be a subcase of "value written does not match the last + * valid interrupt value read from the Interrupt Acknowledge + * register" and so this is UNPREDICTABLE. We choose to ignore it. + */ + return; + } if (s->running_irq[cpu] == 1023) return; /* No active IRQ. */ - if (irq != 1023) { - /* Mark level triggered interrupts as pending if they are still - raised. */ - if (!GIC_TEST_TRIGGER(irq) && GIC_TEST_ENABLED(irq, cm) - && GIC_TEST_LEVEL(irq, cm) && (GIC_TARGET(irq) & cm) != 0) { - DPRINTF("Set %d pending mask %x\n", irq, cm); - GIC_SET_PENDING(irq, cm); - update = 1; - } + /* Mark level triggered interrupts as pending if they are still + raised. */ + if (!GIC_TEST_TRIGGER(irq) && GIC_TEST_ENABLED(irq, cm) + && GIC_TEST_LEVEL(irq, cm) && (GIC_TARGET(irq) & cm) != 0) { + DPRINTF("Set %d pending mask %x\n", irq, cm); + GIC_SET_PENDING(irq, cm); + update = 1; } if (irq != s->running_irq[cpu]) { /* Complete an IRQ that is not currently running. */ @@ -593,7 +609,7 @@ static uint32_t gic_cpu_read(gic_state *s, int cpu, int offset) return 0; case 0x0c: /* Acknowledge */ return gic_acknowledge_irq(s, cpu); - case 0x14: /* Runing Priority */ + case 0x14: /* Running Priority */ return s->running_priority[cpu]; case 0x18: /* Highest Pending Interrupt */ return s->current_pending[cpu]; @@ -624,6 +640,54 @@ static void gic_cpu_write(gic_state *s, int cpu, int offset, uint32_t value) } gic_update(s); } + +/* Wrappers to read/write the GIC CPU interface for the current CPU */ +static uint64_t gic_thiscpu_read(void *opaque, target_phys_addr_t addr, + unsigned size) +{ + gic_state *s = (gic_state *)opaque; + return gic_cpu_read(s, gic_get_current_cpu(), addr & 0xff); +} + +static void gic_thiscpu_write(void *opaque, target_phys_addr_t addr, + uint64_t value, unsigned size) +{ + gic_state *s = (gic_state *)opaque; + gic_cpu_write(s, gic_get_current_cpu(), addr & 0xff, value); +} + +/* Wrappers to read/write the GIC CPU interface for a specific CPU. + * These just decode the opaque pointer into gic_state* + cpu id. + */ +static uint64_t gic_do_cpu_read(void *opaque, target_phys_addr_t addr, + unsigned size) +{ + gic_state **backref = (gic_state **)opaque; + gic_state *s = *backref; + int id = (backref - s->backref); + return gic_cpu_read(s, id, addr & 0xff); +} + +static void gic_do_cpu_write(void *opaque, target_phys_addr_t addr, + uint64_t value, unsigned size) +{ + gic_state **backref = (gic_state **)opaque; + gic_state *s = *backref; + int id = (backref - s->backref); + gic_cpu_write(s, id, addr & 0xff, value); +} + +static const MemoryRegionOps gic_thiscpu_ops = { + .read = gic_thiscpu_read, + .write = gic_thiscpu_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static const MemoryRegionOps gic_cpu_ops = { + .read = gic_do_cpu_read, + .write = gic_do_cpu_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; #endif static void gic_reset(gic_state *s) @@ -743,6 +807,24 @@ static void gic_init(gic_state *s) sysbus_init_irq(&s->busdev, &s->parent_irq[i]); } memory_region_init_io(&s->iomem, &gic_dist_ops, s, "gic_dist", 0x1000); +#ifndef NVIC + /* Memory regions for the CPU interfaces (NVIC doesn't have these): + * a region for "CPU interface for this core", then a region for + * "CPU interface for core 0", "for core 1", ... + * NB that the memory region size of 0x100 applies for the 11MPCore + * and also cores following the GIC v1 spec (ie A9). + * GIC v2 defines a larger memory region (0x1000) so this will need + * to be extended when we implement A15. + */ + memory_region_init_io(&s->cpuiomem[0], &gic_thiscpu_ops, s, + "gic_cpu", 0x100); + for (i = 0; i < NUM_CPU(s); i++) { + s->backref[i] = s; + memory_region_init_io(&s->cpuiomem[i+1], &gic_cpu_ops, &s->backref[i], + "gic_cpu", 0x100); + } +#endif + gic_reset(s); register_savevm(NULL, "arm_gic", -1, 2, gic_save, gic_load, s); } diff --git a/hw/arm_mptimer.c b/hw/arm_mptimer.c new file mode 100644 index 0000000000..455a0aa55a --- /dev/null +++ b/hw/arm_mptimer.c @@ -0,0 +1,332 @@ +/* + * Private peripheral timer/watchdog blocks for ARM 11MPCore and A9MP + * + * Copyright (c) 2006-2007 CodeSourcery. + * Copyright (c) 2011 Linaro Limited + * Written by Paul Brook, Peter Maydell + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "sysbus.h" +#include "qemu-timer.h" + +/* This device implements the per-cpu private timer and watchdog block + * which is used in both the ARM11MPCore and Cortex-A9MP. + */ + +#define MAX_CPUS 4 + +/* State of a single timer or watchdog block */ +typedef struct { + uint32_t count; + uint32_t load; + uint32_t control; + uint32_t status; + int64_t tick; + QEMUTimer *timer; + qemu_irq irq; + MemoryRegion iomem; +} timerblock; + +typedef struct { + SysBusDevice busdev; + uint32_t num_cpu; + timerblock timerblock[MAX_CPUS * 2]; + MemoryRegion iomem[2]; +} arm_mptimer_state; + +static inline int get_current_cpu(arm_mptimer_state *s) +{ + if (cpu_single_env->cpu_index >= s->num_cpu) { + hw_error("arm_mptimer: num-cpu %d but this cpu is %d!\n", + s->num_cpu, cpu_single_env->cpu_index); + } + return cpu_single_env->cpu_index; +} + +static inline void timerblock_update_irq(timerblock *tb) +{ + qemu_set_irq(tb->irq, tb->status); +} + +/* Return conversion factor from mpcore timer ticks to qemu timer ticks. */ +static inline uint32_t timerblock_scale(timerblock *tb) +{ + return (((tb->control >> 8) & 0xff) + 1) * 10; +} + +static void timerblock_reload(timerblock *tb, int restart) +{ + if (tb->count == 0) { + return; + } + if (restart) { + tb->tick = qemu_get_clock_ns(vm_clock); + } + tb->tick += (int64_t)tb->count * timerblock_scale(tb); + qemu_mod_timer(tb->timer, tb->tick); +} + +static void timerblock_tick(void *opaque) +{ + timerblock *tb = (timerblock *)opaque; + tb->status = 1; + if (tb->control & 2) { + tb->count = tb->load; + timerblock_reload(tb, 0); + } else { + tb->count = 0; + } + timerblock_update_irq(tb); +} + +static uint64_t timerblock_read(void *opaque, target_phys_addr_t addr, + unsigned size) +{ + timerblock *tb = (timerblock *)opaque; + int64_t val; + addr &= 0x1f; + switch (addr) { + case 0: /* Load */ + return tb->load; + case 4: /* Counter. */ + if (((tb->control & 1) == 0) || (tb->count == 0)) { + return 0; + } + /* Slow and ugly, but hopefully won't happen too often. */ + val = tb->tick - qemu_get_clock_ns(vm_clock); + val /= timerblock_scale(tb); + if (val < 0) { + val = 0; + } + return val; + case 8: /* Control. */ + return tb->control; + case 12: /* Interrupt status. */ + return tb->status; + default: + return 0; + } +} + +static void timerblock_write(void *opaque, target_phys_addr_t addr, + uint64_t value, unsigned size) +{ + timerblock *tb = (timerblock *)opaque; + int64_t old; + addr &= 0x1f; + switch (addr) { + case 0: /* Load */ + tb->load = value; + /* Fall through. */ + case 4: /* Counter. */ + if ((tb->control & 1) && tb->count) { + /* Cancel the previous timer. */ + qemu_del_timer(tb->timer); + } + tb->count = value; + if (tb->control & 1) { + timerblock_reload(tb, 1); + } + break; + case 8: /* Control. */ + old = tb->control; + tb->control = value; + if (((old & 1) == 0) && (value & 1)) { + if (tb->count == 0 && (tb->control & 2)) { + tb->count = tb->load; + } + timerblock_reload(tb, 1); + } + break; + case 12: /* Interrupt status. */ + tb->status &= ~value; + timerblock_update_irq(tb); + break; + } +} + +/* Wrapper functions to implement the "read timer/watchdog for + * the current CPU" memory regions. + */ +static uint64_t arm_thistimer_read(void *opaque, target_phys_addr_t addr, + unsigned size) +{ + arm_mptimer_state *s = (arm_mptimer_state *)opaque; + int id = get_current_cpu(s); + return timerblock_read(&s->timerblock[id * 2], addr, size); +} + +static void arm_thistimer_write(void *opaque, target_phys_addr_t addr, + uint64_t value, unsigned size) +{ + arm_mptimer_state *s = (arm_mptimer_state *)opaque; + int id = get_current_cpu(s); + timerblock_write(&s->timerblock[id * 2], addr, value, size); +} + +static uint64_t arm_thiswdog_read(void *opaque, target_phys_addr_t addr, + unsigned size) +{ + arm_mptimer_state *s = (arm_mptimer_state *)opaque; + int id = get_current_cpu(s); + return timerblock_read(&s->timerblock[id * 2 + 1], addr, size); +} + +static void arm_thiswdog_write(void *opaque, target_phys_addr_t addr, + uint64_t value, unsigned size) +{ + arm_mptimer_state *s = (arm_mptimer_state *)opaque; + int id = get_current_cpu(s); + timerblock_write(&s->timerblock[id * 2 + 1], addr, value, size); +} + +static const MemoryRegionOps arm_thistimer_ops = { + .read = arm_thistimer_read, + .write = arm_thistimer_write, + .valid = { + .min_access_size = 4, + .max_access_size = 4, + }, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static const MemoryRegionOps arm_thiswdog_ops = { + .read = arm_thiswdog_read, + .write = arm_thiswdog_write, + .valid = { + .min_access_size = 4, + .max_access_size = 4, + }, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static const MemoryRegionOps timerblock_ops = { + .read = timerblock_read, + .write = timerblock_write, + .valid = { + .min_access_size = 4, + .max_access_size = 4, + }, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void timerblock_reset(timerblock *tb) +{ + tb->count = 0; + tb->load = 0; + tb->control = 0; + tb->status = 0; + tb->tick = 0; +} + +static void arm_mptimer_reset(DeviceState *dev) +{ + arm_mptimer_state *s = + FROM_SYSBUS(arm_mptimer_state, sysbus_from_qdev(dev)); + int i; + /* We reset every timer in the array, not just the ones we're using, + * because vmsave will look at every array element. + */ + for (i = 0; i < ARRAY_SIZE(s->timerblock); i++) { + timerblock_reset(&s->timerblock[i]); + } +} + +static int arm_mptimer_init(SysBusDevice *dev) +{ + arm_mptimer_state *s = FROM_SYSBUS(arm_mptimer_state, dev); + int i; + if (s->num_cpu < 1 || s->num_cpu > MAX_CPUS) { + hw_error("%s: num-cpu must be between 1 and %d\n", __func__, MAX_CPUS); + } + /* We implement one timer and one watchdog block per CPU, and + * expose multiple MMIO regions: + * * region 0 is "timer for this core" + * * region 1 is "watchdog for this core" + * * region 2 is "timer for core 0" + * * region 3 is "watchdog for core 0" + * * region 4 is "timer for core 1" + * * region 5 is "watchdog for core 1" + * and so on. + * The outgoing interrupt lines are + * * timer for core 0 + * * watchdog for core 0 + * * timer for core 1 + * * watchdog for core 1 + * and so on. + */ + memory_region_init_io(&s->iomem[0], &arm_thistimer_ops, s, + "arm_mptimer_timer", 0x20); + sysbus_init_mmio(dev, &s->iomem[0]); + memory_region_init_io(&s->iomem[1], &arm_thiswdog_ops, s, + "arm_mptimer_wdog", 0x20); + sysbus_init_mmio(dev, &s->iomem[1]); + for (i = 0; i < (s->num_cpu * 2); i++) { + timerblock *tb = &s->timerblock[i]; + tb->timer = qemu_new_timer_ns(vm_clock, timerblock_tick, tb); + sysbus_init_irq(dev, &tb->irq); + memory_region_init_io(&tb->iomem, &timerblock_ops, tb, + "arm_mptimer_timerblock", 0x20); + sysbus_init_mmio(dev, &tb->iomem); + } + + return 0; +} + +static const VMStateDescription vmstate_timerblock = { + .name = "arm_mptimer_timerblock", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32(count, timerblock), + VMSTATE_UINT32(load, timerblock), + VMSTATE_UINT32(control, timerblock), + VMSTATE_UINT32(status, timerblock), + VMSTATE_INT64(tick, timerblock), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_arm_mptimer = { + .name = "arm_mptimer", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_STRUCT_ARRAY(timerblock, arm_mptimer_state, (MAX_CPUS * 2), + 1, vmstate_timerblock, timerblock), + VMSTATE_END_OF_LIST() + } +}; + +static SysBusDeviceInfo arm_mptimer_info = { + .init = arm_mptimer_init, + .qdev.name = "arm_mptimer", + .qdev.size = sizeof(arm_mptimer_state), + .qdev.vmsd = &vmstate_arm_mptimer, + .qdev.reset = arm_mptimer_reset, + .qdev.no_user = 1, + .qdev.props = (Property[]) { + DEFINE_PROP_UINT32("num-cpu", arm_mptimer_state, num_cpu, 0), + DEFINE_PROP_END_OF_LIST() + } +}; + +static void arm_mptimer_register_devices(void) +{ + sysbus_register_withprop(&arm_mptimer_info); +} + +device_init(arm_mptimer_register_devices) diff --git a/hw/arm_timer.c b/hw/arm_timer.c index 8f442d7878..0a5b9d2cd3 100644 --- a/hw/arm_timer.c +++ b/hw/arm_timer.c @@ -61,7 +61,7 @@ static uint32_t arm_timer_read(void *opaque, target_phys_addr_t offset) return 0; return s->int_level; default: - hw_error("arm_timer_read: Bad offset %x\n", (int)offset); + hw_error("%s: Bad offset %x\n", __func__, (int)offset); return 0; } } @@ -128,7 +128,7 @@ static void arm_timer_write(void *opaque, target_phys_addr_t offset, arm_timer_recalibrate(s, 0); break; default: - hw_error("arm_timer_write: Bad offset %x\n", (int)offset); + hw_error("%s: Bad offset %x\n", __func__, (int)offset); } arm_timer_update(s); } @@ -170,9 +170,9 @@ static arm_timer_state *arm_timer_init(uint32_t freq) } /* ARM PrimeCell SP804 dual timer module. - Docs for this device don't seem to be publicly available. This - implementation is based on guesswork, the linux kernel sources and the - Integrator/CP timer modules. */ + * Docs at + * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0271d/index.html +*/ typedef struct { SysBusDevice busdev; @@ -182,6 +182,13 @@ typedef struct { qemu_irq irq; } sp804_state; +static const uint8_t sp804_ids[] = { + /* Timer ID */ + 0x04, 0x18, 0x14, 0, + /* PrimeCell ID */ + 0xd, 0xf0, 0x05, 0xb1 +}; + /* Merge the IRQs from the two component devices. */ static void sp804_set_irq(void *opaque, int irq, int level) { @@ -196,12 +203,27 @@ static uint64_t sp804_read(void *opaque, target_phys_addr_t offset, { sp804_state *s = (sp804_state *)opaque; - /* ??? Don't know the PrimeCell ID for this device. */ if (offset < 0x20) { return arm_timer_read(s->timer[0], offset); - } else { + } + if (offset < 0x40) { return arm_timer_read(s->timer[1], offset - 0x20); } + + /* TimerPeriphID */ + if (offset >= 0xfe0 && offset <= 0xffc) { + return sp804_ids[(offset - 0xfe0) >> 2]; + } + + switch (offset) { + /* Integration Test control registers, which we won't support */ + case 0xf00: /* TimerITCR */ + case 0xf04: /* TimerITOP (strictly write only but..) */ + return 0; + } + + hw_error("%s: Bad offset %x\n", __func__, (int)offset); + return 0; } static void sp804_write(void *opaque, target_phys_addr_t offset, @@ -211,9 +233,16 @@ static void sp804_write(void *opaque, target_phys_addr_t offset, if (offset < 0x20) { arm_timer_write(s->timer[0], offset, value); - } else { + return; + } + + if (offset < 0x40) { arm_timer_write(s->timer[1], offset - 0x20, value); + return; } + + /* Technically we could be writing to the Test Registers, but not likely */ + hw_error("%s: Bad offset %x\n", __func__, (int)offset); } static const MemoryRegionOps sp804_ops = { @@ -270,7 +299,7 @@ static uint64_t icp_pit_read(void *opaque, target_phys_addr_t offset, /* ??? Don't know the PrimeCell ID for this device. */ n = offset >> 8; if (n > 2) { - hw_error("sp804_read: Bad timer %d\n", n); + hw_error("%s: Bad timer %d\n", __func__, n); } return arm_timer_read(s->timer[n], offset & 0xff); @@ -284,7 +313,7 @@ static void icp_pit_write(void *opaque, target_phys_addr_t offset, n = offset >> 8; if (n > 2) { - hw_error("sp804_write: Bad timer %d\n", n); + hw_error("%s: Bad timer %d\n", __func__, n); } arm_timer_write(s->timer[n], offset & 0xff, value); diff --git a/hw/bt-hci-csr.c b/hw/bt-hci-csr.c index 0dcf897421..772b677ba1 100644 --- a/hw/bt-hci-csr.c +++ b/hw/bt-hci-csr.c @@ -222,7 +222,7 @@ static void csrhci_in_packet(struct csrhci_s *s, uint8_t *pkt) rpkt = csrhci_out_packet_csr(s, H4_NEG_PKT, 10); - *rpkt ++ = 0x20; /* Operational settings negotation Ok */ + *rpkt ++ = 0x20; /* Operational settings negotiation Ok */ memcpy(rpkt, pkt, 7); rpkt += 7; *rpkt ++ = 0xff; *rpkt = 0xff; diff --git a/hw/ccid-card-emulated.c b/hw/ccid-card-emulated.c index 092301b541..2d2ebce852 100644 --- a/hw/ccid-card-emulated.c +++ b/hw/ccid-card-emulated.c @@ -120,6 +120,7 @@ struct EmulatedState { uint8_t atr_length; QSIMPLEQ_HEAD(event_list, EmulEvent) event_list; QemuMutex event_list_mutex; + QemuThread event_thread_id; VReader *reader; QSIMPLEQ_HEAD(guest_apdu_list, EmulEvent) guest_apdu_list; QemuMutex vreader_mutex; /* and guest_apdu_list mutex */ @@ -127,8 +128,7 @@ struct EmulatedState { QemuCond handle_apdu_cond; int pipe[2]; int quit_apdu_thread; - QemuMutex apdu_thread_quit_mutex; - QemuCond apdu_thread_quit_cond; + QemuThread apdu_thread_id; }; static void emulated_apdu_from_guest(CCIDCardState *base, @@ -271,9 +271,6 @@ static void *handle_apdu_thread(void* arg) } qemu_mutex_unlock(&card->vreader_mutex); } - qemu_mutex_lock(&card->apdu_thread_quit_mutex); - qemu_cond_signal(&card->apdu_thread_quit_cond); - qemu_mutex_unlock(&card->apdu_thread_quit_mutex); return NULL; } @@ -489,7 +486,6 @@ static uint32_t parse_enumeration(char *str, static int emulated_initfn(CCIDCardState *base) { EmulatedState *card = DO_UPCAST(EmulatedState, base, base); - QemuThread thread_id; VCardEmulError ret; EnumTable *ptable; @@ -541,8 +537,10 @@ static int emulated_initfn(CCIDCardState *base) printf("%s: failed to initialize vcard\n", EMULATED_DEV_NAME); return -1; } - qemu_thread_create(&thread_id, event_thread, card); - qemu_thread_create(&thread_id, handle_apdu_thread, card); + qemu_thread_create(&card->event_thread_id, event_thread, card, + QEMU_THREAD_JOINABLE); + qemu_thread_create(&card->apdu_thread_id, handle_apdu_thread, card, + QEMU_THREAD_JOINABLE); return 0; } @@ -552,15 +550,14 @@ static int emulated_exitfn(CCIDCardState *base) VEvent *vevent = vevent_new(VEVENT_LAST, NULL, NULL); vevent_queue_vevent(vevent); /* stop vevent thread */ - qemu_mutex_lock(&card->apdu_thread_quit_mutex); + qemu_thread_join(&card->event_thread_id); + card->quit_apdu_thread = 1; /* stop handle_apdu thread */ qemu_cond_signal(&card->handle_apdu_cond); - qemu_cond_wait(&card->apdu_thread_quit_cond, - &card->apdu_thread_quit_mutex); - /* handle_apdu thread stopped, can destroy all of it's mutexes */ + qemu_thread_join(&card->apdu_thread_id); + + /* threads exited, can destroy all condvars/mutexes */ qemu_cond_destroy(&card->handle_apdu_cond); - qemu_cond_destroy(&card->apdu_thread_quit_cond); - qemu_mutex_destroy(&card->apdu_thread_quit_mutex); qemu_mutex_destroy(&card->handle_apdu_mutex); qemu_mutex_destroy(&card->vreader_mutex); qemu_mutex_destroy(&card->event_list_mutex); diff --git a/hw/ccid-card-passthru.c b/hw/ccid-card-passthru.c index 2cbc81b9f4..9f51c6cb05 100644 --- a/hw/ccid-card-passthru.c +++ b/hw/ccid-card-passthru.c @@ -150,6 +150,7 @@ static void ccid_card_vscard_handle_message(PassthruState *card, error_report("ATR size exceeds spec, ignoring"); ccid_card_vscard_send_error(card, scr_msg_header->reader_id, VSC_GENERAL_ERROR); + break; } memcpy(card->atr, data, scr_msg_header->length); card->atr_length = scr_msg_header->length; diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c index 9f7fea19e1..f7b1d3d785 100644 --- a/hw/cirrus_vga.c +++ b/hw/cirrus_vga.c @@ -783,7 +783,7 @@ static void cirrus_bitblt_cputovideo_next(CirrusVGAState * s) s->cirrus_srccounter -= s->cirrus_blt_srcpitch; if (s->cirrus_srccounter <= 0) goto the_end; - /* more bytes than needed can be transfered because of + /* more bytes than needed can be transferred because of word alignment, so we keep them for the next line */ /* XXX: keep alignment to speed up transfer */ end_ptr = s->cirrus_bltbuf + s->cirrus_blt_srcpitch; @@ -2883,7 +2883,7 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci, * ***************************************/ -void isa_cirrus_vga_init(MemoryRegion *system_memory) +DeviceState *isa_cirrus_vga_init(MemoryRegion *system_memory) { CirrusVGAState *s; @@ -2897,6 +2897,8 @@ void isa_cirrus_vga_init(MemoryRegion *system_memory) vmstate_register(NULL, 0, &vmstate_cirrus_vga, s); rom_add_vga(VGABIOS_CIRRUS_FILENAME); /* XXX ISA-LFB support */ + /* FIXME not qdev yet */ + return NULL; } /*************************************** @@ -2939,9 +2941,9 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev) return 0; } -void pci_cirrus_vga_init(PCIBus *bus) +DeviceState *pci_cirrus_vga_init(PCIBus *bus) { - pci_create_simple(bus, -1, "cirrus-vga"); + return &pci_create_simple(bus, -1, "cirrus-vga")->qdev; } static PCIDeviceInfo cirrus_vga_info = { diff --git a/hw/container.c b/hw/container.c new file mode 100644 index 0000000000..9cbf3992c4 --- /dev/null +++ b/hw/container.c @@ -0,0 +1,20 @@ +#include "sysbus.h" + +static int container_initfn(SysBusDevice *dev) +{ + return 0; +} + +static SysBusDeviceInfo container_info = { + .init = container_initfn, + .qdev.name = "container", + .qdev.size = sizeof(SysBusDevice), + .qdev.no_user = 1, +}; + +static void container_init(void) +{ + sysbus_register_withprop(&container_info); +} + +device_init(container_init); diff --git a/hw/dp8393x.c b/hw/dp8393x.c index 54f5864b43..017d0742ae 100644 --- a/hw/dp8393x.c +++ b/hw/dp8393x.c @@ -516,7 +516,7 @@ static void write_register(dp8393xState *s, int reg, uint16_t val) switch (reg) { /* Command register */ case SONIC_CR: - do_command(s, val);; + do_command(s, val); break; /* Prevent write to read-only registers */ case SONIC_CAP2: diff --git a/hw/ds1225y.c b/hw/ds1225y.c index 59d224edfe..7aa0832266 100644 --- a/hw/ds1225y.c +++ b/hw/ds1225y.c @@ -1,7 +1,7 @@ /* * QEMU NVRAM emulation for DS1225Y chip * - * Copyright (c) 2007-2008 Hervé Poussineau + * Copyright (c) 2007-2008 Hervé Poussineau * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/hw/e1000.c b/hw/e1000.c index 986ed9cf79..a29c944df4 100644 --- a/hw/e1000.c +++ b/hw/e1000.c @@ -507,7 +507,7 @@ txdesc_writeback(E1000State *s, dma_addr_t base, struct e1000_tx_desc *dp) ~(E1000_TXD_STAT_EC | E1000_TXD_STAT_LC | E1000_TXD_STAT_TU); dp->upper.data = cpu_to_le32(txd_upper); pci_dma_write(&s->dev, base + ((char *)&dp->upper - (char *)dp), - (void *)&dp->upper, sizeof(dp->upper)); + &dp->upper, sizeof(dp->upper)); return E1000_ICR_TXDW; } @@ -534,7 +534,7 @@ start_xmit(E1000State *s) while (s->mac_reg[TDH] != s->mac_reg[TDT]) { base = tx_desc_base(s) + sizeof(struct e1000_tx_desc) * s->mac_reg[TDH]; - pci_dma_read(&s->dev, base, (void *)&desc, sizeof(desc)); + pci_dma_read(&s->dev, base, &desc, sizeof(desc)); DBGOUT(TX, "index %d: %p : %x %x\n", s->mac_reg[TDH], (void *)(intptr_t)desc.buffer_addr, desc.lower.data, @@ -714,7 +714,7 @@ e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size) desc_size = s->rxbuf_size; } base = rx_desc_base(s) + sizeof(desc) * s->mac_reg[RDH]; - pci_dma_read(&s->dev, base, (void *)&desc, sizeof(desc)); + pci_dma_read(&s->dev, base, &desc, sizeof(desc)); desc.special = vlan_special; desc.status |= (vlan_status | E1000_RXD_STAT_DD); if (desc.buffer_addr) { @@ -724,8 +724,7 @@ e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size) copy_size = s->rxbuf_size; } pci_dma_write(&s->dev, le64_to_cpu(desc.buffer_addr), - (void *)(buf + desc_offset + vlan_offset), - copy_size); + buf + desc_offset + vlan_offset, copy_size); } desc_offset += desc_size; desc.length = cpu_to_le16(desc_size); @@ -739,7 +738,7 @@ e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size) } else { // as per intel docs; skip descriptors with null buf addr DBGOUT(RX, "Null RX descriptor!!\n"); } - pci_dma_write(&s->dev, base, (void *)&desc, sizeof(desc)); + pci_dma_write(&s->dev, base, &desc, sizeof(desc)); if (++s->mac_reg[RDH] * sizeof(desc) >= s->mac_reg[RDLEN]) s->mac_reg[RDH] = 0; diff --git a/hw/e1000_hw.h b/hw/e1000_hw.h index 2e341ac27e..9e29af8c82 100644 --- a/hw/e1000_hw.h +++ b/hw/e1000_hw.h @@ -295,7 +295,7 @@ #define E1000_KUMCTRLSTA 0x00034 /* MAC-PHY interface - RW */ #define E1000_MDPHYA 0x0003C /* PHY address - RW */ -#define E1000_MANC2H 0x05860 /* Managment Control To Host - RW */ +#define E1000_MANC2H 0x05860 /* Management Control To Host - RW */ #define E1000_SW_FW_SYNC 0x05B5C /* Software-Firmware Synchronization - RW */ #define E1000_GCR 0x05B00 /* PCI-Ex Control */ diff --git a/hw/eepro100.c b/hw/eepro100.c index 7d59e7136d..6a162f607f 100644 --- a/hw/eepro100.c +++ b/hw/eepro100.c @@ -258,7 +258,7 @@ typedef struct { /* Data in mem is always in the byte order of the controller (le). * It must be dword aligned to allow direct access to 32 bit values. */ - uint8_t mem[PCI_MEM_SIZE] __attribute__((aligned(8)));; + uint8_t mem[PCI_MEM_SIZE] __attribute__((aligned(8))); /* Configuration bytes. */ uint8_t configuration[22]; @@ -713,8 +713,7 @@ static void dump_statistics(EEPRO100State * s) * values which really matter. * Number of data should check configuration!!! */ - pci_dma_write(&s->dev, s->statsaddr, - (uint8_t *) &s->statistics, s->stats_size); + pci_dma_write(&s->dev, s->statsaddr, &s->statistics, s->stats_size); stl_le_pci_dma(&s->dev, s->statsaddr + 0, s->statistics.tx_good_frames); stl_le_pci_dma(&s->dev, s->statsaddr + 36, @@ -732,7 +731,7 @@ static void dump_statistics(EEPRO100State * s) static void read_cb(EEPRO100State *s) { - pci_dma_read(&s->dev, s->cb_address, (uint8_t *) &s->tx, sizeof(s->tx)); + pci_dma_read(&s->dev, s->cb_address, &s->tx, sizeof(s->tx)); s->tx.status = le16_to_cpu(s->tx.status); s->tx.command = le16_to_cpu(s->tx.command); s->tx.link = le32_to_cpu(s->tx.link); @@ -976,7 +975,15 @@ static void eepro100_cu_command(EEPRO100State * s, uint8_t val) case CU_STATSADDR: /* Load dump counters address. */ s->statsaddr = e100_read_reg4(s, SCBPointer); - TRACE(OTHER, logout("val=0x%02x (status address)\n", val)); + TRACE(OTHER, logout("val=0x%02x (dump counters address)\n", val)); + if (s->statsaddr & 3) { + /* Memory must be Dword aligned. */ + logout("unaligned dump counters address\n"); + /* Handling of misaligned addresses is undefined. + * Here we align the address by ignoring the lower bits. */ + /* TODO: Test unaligned dump counter address on real hardware. */ + s->statsaddr &= ~3; + } break; case CU_SHOWSTATS: /* Dump statistical counters. */ @@ -1707,7 +1714,7 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size /* !!! */ eepro100_rx_t rx; pci_dma_read(&s->dev, s->ru_base + s->ru_offset, - (uint8_t *) &rx, sizeof(eepro100_rx_t)); + &rx, sizeof(eepro100_rx_t)); uint16_t rfd_command = le16_to_cpu(rx.command); uint16_t rfd_size = le16_to_cpu(rx.size); diff --git a/hw/es1370.c b/hw/es1370.c index c5c16b0484..6a3ba55f6f 100644 --- a/hw/es1370.c +++ b/hw/es1370.c @@ -788,7 +788,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, int cnt = d->frame_cnt >> 16; int size = d->frame_cnt & 0xffff; int left = ((size - cnt + 1) << 2) + d->leftover; - int transfered = 0; + int transferred = 0; int temp = audio_MIN (max, audio_MIN (left, csc_bytes)); int index = d - &s->chan[0]; @@ -807,7 +807,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, temp -= acquired; addr += acquired; - transfered += acquired; + transferred += acquired; } } else { @@ -823,11 +823,11 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, break; temp -= copied; addr += copied; - transfered += copied; + transferred += copied; } } - if (csc_bytes == transfered) { + if (csc_bytes == transferred) { *irq = 1; d->scount = sc | (sc << 16); ldebug ("sc = %d, rate = %f\n", @@ -836,10 +836,10 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, } else { *irq = 0; - d->scount = sc | (((csc_bytes - transfered - 1) >> d->shift) << 16); + d->scount = sc | (((csc_bytes - transferred - 1) >> d->shift) << 16); } - cnt += (transfered + d->leftover) >> 2; + cnt += (transferred + d->leftover) >> 2; if (s->sctl & loop_sel) { /* Bah, how stupid is that having a 0 represent true value? @@ -853,7 +853,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, d->frame_cnt |= cnt << 16; } - d->leftover = (transfered + d->leftover) & 3; + d->leftover = (transferred + d->leftover) & 3; } static void es1370_run_channel (ES1370State *s, size_t chan, int free_or_avail) diff --git a/hw/etraxfs_dma.c b/hw/etraxfs_dma.c index 02d01836ce..d2bd584bc5 100644 --- a/hw/etraxfs_dma.c +++ b/hw/etraxfs_dma.c @@ -180,7 +180,7 @@ struct fs_dma_channel struct dma_descr_context current_c; struct dma_descr_data current_d; - /* Controll registers. */ + /* Control registers. */ uint32_t regs[DMA_REG_MAX]; }; diff --git a/hw/etraxfs_pic.c b/hw/etraxfs_pic.c index 72cbdb8c89..993d6a8885 100644 --- a/hw/etraxfs_pic.c +++ b/hw/etraxfs_pic.c @@ -53,7 +53,7 @@ static void pic_update(struct etrax_pic *fs) fs->regs[R_R_MASKED_VECT] = fs->regs[R_R_VECT] & fs->regs[R_RW_MASK]; - /* The ETRAX interrupt controller signals interrupts to teh core + /* The ETRAX interrupt controller signals interrupts to the core through an interrupt request wire and an irq vector bus. If multiple interrupts are simultaneously active it chooses vector 0x30 and lets the sw choose the priorities. */ @@ -2,7 +2,7 @@ * QEMU Floppy disk emulator (Intel 82078) * * Copyright (c) 2003, 2007 Jocelyn Mayer - * Copyright (c) 2008 Hervé Poussineau + * Copyright (c) 2008 Hervé Poussineau * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/hw/fmopl.c b/hw/fmopl.c index 5ad52ab7d2..734d2f4aae 100644 --- a/hw/fmopl.c +++ b/hw/fmopl.c @@ -362,8 +362,8 @@ INLINE UINT32 OPL_CALC_SLOT( OPL_SLOT *SLOT ) return SLOT->TLL+ENV_CURVE[SLOT->evc>>ENV_BITS]+(SLOT->ams ? ams : 0); } -/* set algorythm connection */ -static void set_algorythm( OPL_CH *CH) +/* set algorithm connection */ +static void set_algorithm( OPL_CH *CH) { INT32 *carrier = &outd[0]; CH->connect1 = CH->CON ? carrier : &feedback2; @@ -498,7 +498,7 @@ INLINE void OPL_CALC_CH( OPL_CH *CH ) } } -/* ---------- calcrate rythm block ---------- */ +/* ---------- calcrate rhythm block ---------- */ #define WHITE_NOISE_db 6.0 INLINE void OPL_CALC_RH( OPL_CH *CH ) { @@ -715,7 +715,7 @@ static void OPLCloseTable( void ) free(VIB_TABLE); } -/* CSM Key Controll */ +/* CSM Key Control */ INLINE void CSMKeyControll(OPL_CH *CH) { OPL_SLOT *slot1 = &CH->SLOT[SLOT1]; @@ -762,7 +762,7 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v) switch(r&0xe0) { - case 0x00: /* 00-1f:controll */ + case 0x00: /* 00-1f:control */ switch(r&0x1f) { case 0x01: @@ -826,7 +826,7 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v) LOG(LOG_WAR,("OPL:write unmapped KEYBOARD port\n")); } return; - case 0x07: /* DELTA-T controll : START,REC,MEMDATA,REPT,SPOFF,x,x,RST */ + case 0x07: /* DELTA-T control : START,REC,MEMDATA,REPT,SPOFF,x,x,RST */ if(OPL->type&OPL_TYPE_ADPCM) YM_DELTAT_ADPCM_Write(OPL->deltat,r-0x07,v); return; @@ -895,14 +895,14 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v) case 0xbd: /* amsep,vibdep,r,bd,sd,tom,tc,hh */ { - UINT8 rkey = OPL->rythm^v; + UINT8 rkey = OPL->rhythm^v; OPL->ams_table = &AMS_TABLE[v&0x80 ? AMS_ENT : 0]; OPL->vib_table = &VIB_TABLE[v&0x40 ? VIB_ENT : 0]; - OPL->rythm = v&0x3f; - if(OPL->rythm&0x20) + OPL->rhythm = v&0x3f; + if(OPL->rhythm&0x20) { #if 0 - usrintf_showmessage("OPL Rythm mode select"); + usrintf_showmessage("OPL Rhythm mode select"); #endif /* BD key on/off */ if(rkey&0x10) @@ -995,7 +995,7 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v) int feedback = (v>>1)&7; CH->FB = feedback ? (8+1) - feedback : 0; CH->CON = v&1; - set_algorythm(CH); + set_algorithm(CH); } return; case 0xe0: /* wave type */ @@ -1049,7 +1049,7 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length) OPLSAMPLE *buf = buffer; UINT32 amsCnt = OPL->amsCnt; UINT32 vibCnt = OPL->vibCnt; - UINT8 rythm = OPL->rythm&0x20; + UINT8 rhythm = OPL->rhythm&0x20; OPL_CH *CH,*R_CH; if( (void *)OPL != cur_chip ){ @@ -1057,7 +1057,7 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length) /* channel pointers */ S_CH = OPL->P_CH; E_CH = &S_CH[9]; - /* rythm slot */ + /* rhythm slot */ SLOT7_1 = &S_CH[7].SLOT[SLOT1]; SLOT7_2 = &S_CH[7].SLOT[SLOT2]; SLOT8_1 = &S_CH[8].SLOT[SLOT1]; @@ -1068,7 +1068,7 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length) ams_table = OPL->ams_table; vib_table = OPL->vib_table; } - R_CH = rythm ? &S_CH[6] : E_CH; + R_CH = rhythm ? &S_CH[6] : E_CH; for( i=0; i < length ; i++ ) { /* channel A channel B channel C */ @@ -1080,7 +1080,7 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length) for(CH=S_CH ; CH < R_CH ; CH++) OPL_CALC_CH(CH); /* Rythn part */ - if(rythm) + if(rhythm) OPL_CALC_RH(S_CH); /* limit check */ data = Limit( outd[0] , OPL_MAXOUT, OPL_MINOUT ); @@ -1110,7 +1110,7 @@ void Y8950UpdateOne(FM_OPL *OPL, INT16 *buffer, int length) OPLSAMPLE *buf = buffer; UINT32 amsCnt = OPL->amsCnt; UINT32 vibCnt = OPL->vibCnt; - UINT8 rythm = OPL->rythm&0x20; + UINT8 rhythm = OPL->rhythm&0x20; OPL_CH *CH,*R_CH; YM_DELTAT *DELTAT = OPL->deltat; @@ -1122,7 +1122,7 @@ void Y8950UpdateOne(FM_OPL *OPL, INT16 *buffer, int length) /* channel pointers */ S_CH = OPL->P_CH; E_CH = &S_CH[9]; - /* rythm slot */ + /* rhythm slot */ SLOT7_1 = &S_CH[7].SLOT[SLOT1]; SLOT7_2 = &S_CH[7].SLOT[SLOT2]; SLOT8_1 = &S_CH[8].SLOT[SLOT1]; @@ -1133,7 +1133,7 @@ void Y8950UpdateOne(FM_OPL *OPL, INT16 *buffer, int length) ams_table = OPL->ams_table; vib_table = OPL->vib_table; } - R_CH = rythm ? &S_CH[6] : E_CH; + R_CH = rhythm ? &S_CH[6] : E_CH; for( i=0; i < length ; i++ ) { /* channel A channel B channel C */ @@ -1148,7 +1148,7 @@ void Y8950UpdateOne(FM_OPL *OPL, INT16 *buffer, int length) for(CH=S_CH ; CH < R_CH ; CH++) OPL_CALC_CH(CH); /* Rythn part */ - if(rythm) + if(rhythm) OPL_CALC_RH(S_CH); /* limit check */ data = Limit( outd[0] , OPL_MAXOUT, OPL_MINOUT ); @@ -1380,7 +1380,7 @@ int OPLTimerOver(FM_OPL *OPL,int c) else { /* Timer A */ OPL_STATUS_SET(OPL,0x40); - /* CSM mode key,TL controll */ + /* CSM mode key,TL control */ if( OPL->mode & 0x80 ) { /* CSM mode total level latch and auto key on */ int ch; diff --git a/hw/fmopl.h b/hw/fmopl.h index a01ff902c7..24ba5f4802 100644 --- a/hw/fmopl.h +++ b/hw/fmopl.h @@ -110,8 +110,8 @@ typedef struct fm_opl_f { /* FM channel slots */ OPL_CH *P_CH; /* pointer of CH */ int max_ch; /* maximum channel */ - /* Rythm sention */ - UINT8 rythm; /* Rythm mode , key flag */ + /* Rhythm sention */ + UINT8 rhythm; /* Rhythm mode , key flag */ #if BUILD_Y8950 /* Delta-T ADPCM unit (Y8950) */ YM_DELTAT *deltat; /* DELTA-T ADPCM */ diff --git a/hw/gusemu.h b/hw/gusemu.h index 50937678e9..331bb6fec0 100644 --- a/hw/gusemu.h +++ b/hw/gusemu.h @@ -27,7 +27,7 @@ /* data types (need to be adjusted if neither a VC6 nor a C99 compatible compiler is used) */ -#if defined _WIN32 && defined _MSC_VER /* doesnt support other win32 compilers yet, do it yourself... */ +#if defined _WIN32 && defined _MSC_VER /* doesn't support other win32 compilers yet, do it yourself... */ typedef unsigned char GUSbyte; typedef unsigned short GUSword; typedef unsigned int GUSdword; @@ -83,7 +83,7 @@ void gus_dma_transferdata(GUSEmuState *state, char *dma_addr, unsigned int count /* it is possible to break down a single transfer into multiple ones, but take care that: */ /* -dma_count is actually count-1 */ /* -before and during a transfer, DREQ is set and TC cleared */ -/* -when calling gus_dma_transferdata(), TC is only set true for call transfering the last byte */ +/* -when calling gus_dma_transferdata(), TC is only set true for call transferring the last byte */ /* -after the last transfer, DREQ is cleared and TC is set */ /* ** GF1 mixer emulation functions: */ diff --git a/hw/gusemu_hal.c b/hw/gusemu_hal.c index c6f9537483..6096690735 100644 --- a/hw/gusemu_hal.c +++ b/hw/gusemu_hal.c @@ -502,7 +502,7 @@ void gus_dma_transferdata(GUSEmuState * state, char *dma_addr, unsigned int coun /* this function gets called by the callback function as soon as a DMA transfer is about to start * dma_addr is a translated address within accessible memory, not the physical one, * count is (real dma count register)+1 - * note that the amount of bytes transfered is fully determined by values in the DMA registers + * note that the amount of bytes transferred is fully determined by values in the DMA registers * do not forget to update DMA states after transferring the entire block: * DREQ cleared & TC asserted after the _whole_ transfer */ @@ -517,7 +517,7 @@ void gus_dma_transferdata(GUSEmuState * state, char *dma_addr, unsigned int coun int offset = (GUSregw(GUS42DMAStart) << 4) + (GUSregb(GUS50DMAHigh) & 0xf); if (state->gusdma >= 4) offset = (offset & 0xc0000) + (2 * (offset & 0x1fff0)); /* 16 bit address translation */ - destaddr = (char *) state->himemaddr + offset; /* wavetable RAM adress */ + destaddr = (char *) state->himemaddr + offset; /* wavetable RAM address */ } GUSregw(GUS42DMAStart) += (GUSword) (count >> 4); /* ToDo: add 16bit GUS page limit? */ @@ -27,7 +27,13 @@ typedef int (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf, typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf, int64_t pos, int size); -/* Close a file and return an error code */ +/* Close a file + * + * Return negative error number on error, 0 or positive value on success. + * + * The meaning of return value on success depends on the specific back-end being + * used. + */ typedef int (QEMUFileCloseFunc)(void *opaque); /* Called to determine if the file has exceeded it's bandwidth allocation. The diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c index 8af1cfdd7e..0adb27b799 100644 --- a/hw/ide/atapi.c +++ b/hw/ide/atapi.c @@ -352,14 +352,8 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret) s->bus->dma->aiocb = bdrv_aio_readv(s->bs, (int64_t)s->lba << 2, &s->bus->dma->qiov, n * 4, ide_atapi_cmd_read_dma_cb, s); - if (!s->bus->dma->aiocb) { - /* Note: media not present is the most likely case */ - ide_atapi_cmd_error(s, NOT_READY, - ASC_MEDIUM_NOT_PRESENT); - goto eot; - } - return; + eot: bdrv_acct_done(s->bs, &s->acct); s->bus->dma->ops->add_status(s->bus->dma, BM_STATUS_INT); diff --git a/hw/ide/core.c b/hw/ide/core.c index 93a1a689c4..56b219b504 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -493,7 +493,7 @@ void ide_sector_read(IDEState *s) } } -static void dma_buf_commit(IDEState *s, int is_write) +static void dma_buf_commit(IDEState *s) { qemu_sglist_destroy(&s->sg); } @@ -532,7 +532,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int op) bdrv_iostatus_set_err(s->bs, error); } else { if (op & BM_STATUS_DMA_RETRY) { - dma_buf_commit(s, 0); + dma_buf_commit(s); ide_dma_error(s); } else { ide_rw_error(s); @@ -549,7 +549,6 @@ void ide_dma_cb(void *opaque, int ret) int n; int64_t sector_num; -handle_rw_error: if (ret < 0) { int op = BM_STATUS_DMA_RETRY; @@ -566,7 +565,7 @@ handle_rw_error: n = s->io_buffer_size >> 9; sector_num = ide_get_sector(s); if (n > 0) { - dma_buf_commit(s, ide_cmd_is_read(s)); + dma_buf_commit(s); sector_num += n; ide_set_sector(s, sector_num); s->nsector -= n; @@ -608,11 +607,6 @@ handle_rw_error: ide_issue_trim, ide_dma_cb, s, true); break; } - - if (!s->bus->dma->aiocb) { - ret = -1; - goto handle_rw_error; - } return; eot: @@ -718,18 +712,13 @@ static void ide_flush_cb(void *opaque, int ret) void ide_flush_cache(IDEState *s) { - BlockDriverAIOCB *acb; - if (s->bs == NULL) { ide_flush_cb(s, 0); return; } bdrv_acct_start(s->bs, &s->acct, 0, BDRV_ACCT_FLUSH); - acb = bdrv_aio_flush(s->bs, ide_flush_cb, s); - if (acb == NULL) { - ide_flush_cb(s, -EIO); - } + bdrv_aio_flush(s->bs, ide_flush_cb, s); } static void ide_cfata_metadata_inquiry(IDEState *s) @@ -1000,7 +989,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) printf("ide: CMD=%02x\n", val); #endif s = idebus_active_if(bus); - /* ignore commands to non existant slave */ + /* ignore commands to non existent slave */ if (s != bus->ifs && !s->bs) return; diff --git a/hw/ide/macio.c b/hw/ide/macio.c index 70b33422d2..abbc41b59e 100644 --- a/hw/ide/macio.c +++ b/hw/ide/macio.c @@ -84,13 +84,6 @@ static void pmac_ide_atapi_transfer_cb(void *opaque, int ret) m->aiocb = dma_bdrv_read(s->bs, &s->sg, (int64_t)(s->lba << 2) + (s->io_buffer_index >> 9), pmac_ide_atapi_transfer_cb, io); - if (!m->aiocb) { - qemu_sglist_destroy(&s->sg); - /* Note: media not present is the most likely case */ - ide_atapi_cmd_error(s, NOT_READY, - ASC_MEDIUM_NOT_PRESENT); - goto done; - } return; done: @@ -159,10 +152,8 @@ static void pmac_ide_transfer_cb(void *opaque, int ret) ide_issue_trim, pmac_ide_transfer_cb, s, true); break; } - - if (!m->aiocb) - pmac_ide_transfer_cb(io, -1); return; + done: if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) { bdrv_acct_done(s->bs, &s->acct); @@ -200,8 +191,9 @@ static void pmac_ide_flush(DBDMA_io *io) { MACIOIDEState *m = io->opaque; - if (m->aiocb) - qemu_aio_flush(); + if (m->aiocb) { + bdrv_drain_all(); + } } /* PowerMac IDE memory IO */ diff --git a/hw/ide/pci.c b/hw/ide/pci.c index 49b823df79..cb3de6537b 100644 --- a/hw/ide/pci.c +++ b/hw/ide/pci.c @@ -71,7 +71,7 @@ static int bmdma_prepare_buf(IDEDMA *dma, int is_write) if (bm->cur_prd_last || (bm->cur_addr - bm->addr) >= BMDMA_PAGE_SIZE) return s->io_buffer_size != 0; - pci_dma_read(&bm->pci_dev->dev, bm->cur_addr, (uint8_t *)&prd, 8); + pci_dma_read(&bm->pci_dev->dev, bm->cur_addr, &prd, 8); bm->cur_addr += 8; prd.addr = le32_to_cpu(prd.addr); prd.size = le32_to_cpu(prd.size); @@ -113,7 +113,7 @@ static int bmdma_rw_buf(IDEDMA *dma, int is_write) if (bm->cur_prd_last || (bm->cur_addr - bm->addr) >= BMDMA_PAGE_SIZE) return 0; - pci_dma_read(&bm->pci_dev->dev, bm->cur_addr, (uint8_t *)&prd, 8); + pci_dma_read(&bm->pci_dev->dev, bm->cur_addr, &prd, 8); bm->cur_addr += 8; prd.addr = le32_to_cpu(prd.addr); prd.size = le32_to_cpu(prd.size); @@ -309,7 +309,7 @@ void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val) * aio operation with preadv/pwritev. */ if (bm->bus->dma->aiocb) { - qemu_aio_flush(); + bdrv_drain_all(); assert(bm->bus->dma->aiocb == NULL); assert((bm->status & BM_STATUS_DMAING) == 0); } diff --git a/hw/ide/via.c b/hw/ide/via.c index 098f150bb2..a57134c12a 100644 --- a/hw/ide/via.c +++ b/hw/ide/via.c @@ -172,7 +172,7 @@ static void vt82c686b_init_ports(PCIIDEState *d) { /* via ide func */ static int vt82c686b_ide_initfn(PCIDevice *dev) { - PCIIDEState *d = DO_UPCAST(PCIIDEState, dev, dev);; + PCIIDEState *d = DO_UPCAST(PCIIDEState, dev, dev); uint8_t *pci_conf = d->dev.config; pci_config_set_prog_interface(pci_conf, 0x8a); /* legacy ATA mode */ diff --git a/hw/jazz_led.c b/hw/jazz_led.c index 6fab334253..f8a218252c 100644 --- a/hw/jazz_led.c +++ b/hw/jazz_led.c @@ -1,7 +1,7 @@ /* * QEMU JAZZ LED emulator. * - * Copyright (c) 2007 Hervé Poussineau + * Copyright (c) 2007 Hervé Poussineau * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/hw/lan9118.c b/hw/lan9118.c index ee8b2eab06..7e64c5dee3 100644 --- a/hw/lan9118.c +++ b/hw/lan9118.c @@ -697,7 +697,7 @@ static uint32_t do_phy_read(lan9118_state *s, int reg) return 0x0007; case 3: /* ID2 */ return 0xc0d1; - case 4: /* Auto-neg advertisment */ + case 4: /* Auto-neg advertisement */ return s->phy_advertise; case 5: /* Auto-neg Link Partner Ability */ return 0x0f71; @@ -731,7 +731,7 @@ static void do_phy_write(lan9118_state *s, int reg, uint32_t val) s->phy_status |= 0x0020; } break; - case 4: /* Auto-neg advertisment */ + case 4: /* Auto-neg advertisement */ s->phy_advertise = (val & 0x2d7f) | 0x80; break; /* TODO 17, 18, 27, 31 */ diff --git a/hw/lm4549.c b/hw/lm4549.c index 4d5b83125f..80b3ec4a5d 100644 --- a/hw/lm4549.c +++ b/hw/lm4549.c @@ -4,7 +4,7 @@ * Copyright (c) 2011 * Written by Mathieu Sonet - www.elasticsheep.com * - * This code is licenced under the GPL. + * This code is licensed under the GPL. * * ***************************************************************** * diff --git a/hw/lm4549.h b/hw/lm4549.h index 70d0ac1750..5948780e00 100644 --- a/hw/lm4549.h +++ b/hw/lm4549.h @@ -4,7 +4,7 @@ * Copyright (c) 2011 * Written by Mathieu Sonet - www.elasticsheep.com * - * This code is licenced under the GPL. + * This code is licensed under the GPL. * * ***************************************************************** */ diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c index fcc27d726f..0d3a1016df 100644 --- a/hw/lsi53c895a.c +++ b/hw/lsi53c895a.c @@ -392,7 +392,7 @@ static inline uint32_t read_dword(LSIState *s, uint32_t addr) { uint32_t buf; - pci_dma_read(&s->dev, addr, (uint8_t *)&buf, 4); + pci_dma_read(&s->dev, addr, &buf, 4); return cpu_to_le32(buf); } @@ -1079,7 +1079,7 @@ again: /* 32-bit Table indirect */ offset = sxt24(addr); - pci_dma_read(&s->dev, s->dsa + offset, (uint8_t *)buf, 8); + pci_dma_read(&s->dev, s->dsa + offset, buf, 8); /* byte count is stored in bits 0:23 only */ s->dbc = cpu_to_le32(buf[0]) & 0xffffff; s->rbc = s->dbc; diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c index 2aaca2ff41..0c23cb0dba 100644 --- a/hw/mc146818rtc.c +++ b/hw/mc146818rtc.c @@ -614,6 +614,29 @@ static const MemoryRegionOps cmos_ops = { .old_portio = cmos_portio }; +// FIXME add int32 visitor +static void visit_type_int32(Visitor *v, int *value, const char *name, Error **errp) +{ + int64_t val = *value; + visit_type_int(v, &val, name, errp); +} + +static void rtc_get_date(DeviceState *dev, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + ISADevice *isa = DO_UPCAST(ISADevice, qdev, dev); + RTCState *s = DO_UPCAST(RTCState, dev, isa); + + visit_start_struct(v, NULL, "struct tm", name, 0, errp); + visit_type_int32(v, &s->current_tm.tm_year, "tm_year", errp); + visit_type_int32(v, &s->current_tm.tm_mon, "tm_mon", errp); + visit_type_int32(v, &s->current_tm.tm_mday, "tm_mday", errp); + visit_type_int32(v, &s->current_tm.tm_hour, "tm_hour", errp); + visit_type_int32(v, &s->current_tm.tm_min, "tm_min", errp); + visit_type_int32(v, &s->current_tm.tm_sec, "tm_sec", errp); + visit_end_struct(v, errp); +} + static int rtc_initfn(ISADevice *dev) { RTCState *s = DO_UPCAST(RTCState, dev, dev); @@ -647,6 +670,10 @@ static int rtc_initfn(ISADevice *dev) qdev_set_legacy_instance_id(&dev->qdev, base, 2); qemu_register_reset(rtc_reset, s); + + qdev_property_add(&s->dev.qdev, "date", "struct tm", + rtc_get_date, NULL, NULL, s, NULL); + return 0; } diff --git a/hw/mips_malta.c b/hw/mips_malta.c index bb49749569..e7dfbd6632 100644 --- a/hw/mips_malta.c +++ b/hw/mips_malta.c @@ -911,6 +911,7 @@ void mips_malta_init (ram_addr_t ram_size, uint32_t *end = addr + bios_size; while (addr < end) { bswap32s(addr); + addr++; } } #endif diff --git a/hw/mpcore.c b/hw/mpcore.c deleted file mode 100644 index 4357d12217..0000000000 --- a/hw/mpcore.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * ARM MPCore internal peripheral emulation (common code). - * - * Copyright (c) 2006-2007 CodeSourcery. - * Written by Paul Brook - * - * This code is licensed under the GPL. - */ - -#include "sysbus.h" -#include "qemu-timer.h" - -#define NCPU 4 - -static inline int -gic_get_current_cpu(void) -{ - return cpu_single_env->cpu_index; -} - -#include "arm_gic.c" - -/* MPCore private memory region. */ - -typedef struct { - uint32_t count; - uint32_t load; - uint32_t control; - uint32_t status; - uint32_t old_status; - int64_t tick; - QEMUTimer *timer; - struct mpcore_priv_state *mpcore; - int id; /* Encodes both timer/watchdog and CPU. */ -} mpcore_timer_state; - -typedef struct mpcore_priv_state { - gic_state gic; - uint32_t scu_control; - int iomemtype; - mpcore_timer_state timer[8]; - uint32_t num_cpu; - MemoryRegion iomem; - MemoryRegion container; -} mpcore_priv_state; - -/* Per-CPU Timers. */ - -static inline void mpcore_timer_update_irq(mpcore_timer_state *s) -{ - if (s->status & ~s->old_status) { - gic_set_pending_private(&s->mpcore->gic, s->id >> 1, 29 + (s->id & 1)); - } - s->old_status = s->status; -} - -/* Return conversion factor from mpcore timer ticks to qemu timer ticks. */ -static inline uint32_t mpcore_timer_scale(mpcore_timer_state *s) -{ - return (((s->control >> 8) & 0xff) + 1) * 10; -} - -static void mpcore_timer_reload(mpcore_timer_state *s, int restart) -{ - if (s->count == 0) - return; - if (restart) - s->tick = qemu_get_clock_ns(vm_clock); - s->tick += (int64_t)s->count * mpcore_timer_scale(s); - qemu_mod_timer(s->timer, s->tick); -} - -static void mpcore_timer_tick(void *opaque) -{ - mpcore_timer_state *s = (mpcore_timer_state *)opaque; - s->status = 1; - if (s->control & 2) { - s->count = s->load; - mpcore_timer_reload(s, 0); - } else { - s->count = 0; - } - mpcore_timer_update_irq(s); -} - -static uint32_t mpcore_timer_read(mpcore_timer_state *s, int offset) -{ - int64_t val; - switch (offset) { - case 0: /* Load */ - return s->load; - /* Fall through. */ - case 4: /* Counter. */ - if (((s->control & 1) == 0) || (s->count == 0)) - return 0; - /* Slow and ugly, but hopefully won't happen too often. */ - val = s->tick - qemu_get_clock_ns(vm_clock); - val /= mpcore_timer_scale(s); - if (val < 0) - val = 0; - return val; - case 8: /* Control. */ - return s->control; - case 12: /* Interrupt status. */ - return s->status; - default: - return 0; - } -} - -static void mpcore_timer_write(mpcore_timer_state *s, int offset, - uint32_t value) -{ - int64_t old; - switch (offset) { - case 0: /* Load */ - s->load = value; - /* Fall through. */ - case 4: /* Counter. */ - if ((s->control & 1) && s->count) { - /* Cancel the previous timer. */ - qemu_del_timer(s->timer); - } - s->count = value; - if (s->control & 1) { - mpcore_timer_reload(s, 1); - } - break; - case 8: /* Control. */ - old = s->control; - s->control = value; - if (((old & 1) == 0) && (value & 1)) { - if (s->count == 0 && (s->control & 2)) - s->count = s->load; - mpcore_timer_reload(s, 1); - } - break; - case 12: /* Interrupt status. */ - s->status &= ~value; - mpcore_timer_update_irq(s); - break; - } -} - -static void mpcore_timer_init(mpcore_priv_state *mpcore, - mpcore_timer_state *s, int id) -{ - s->id = id; - s->mpcore = mpcore; - s->timer = qemu_new_timer_ns(vm_clock, mpcore_timer_tick, s); -} - - -/* Per-CPU private memory mapped IO. */ - -static uint64_t mpcore_priv_read(void *opaque, target_phys_addr_t offset, - unsigned size) -{ - mpcore_priv_state *s = (mpcore_priv_state *)opaque; - int id; - offset &= 0xfff; - if (offset < 0x100) { - /* SCU */ - switch (offset) { - case 0x00: /* Control. */ - return s->scu_control; - case 0x04: /* Configuration. */ - id = ((1 << s->num_cpu) - 1) << 4; - return id | (s->num_cpu - 1); - case 0x08: /* CPU status. */ - return 0; - case 0x0c: /* Invalidate all. */ - return 0; - default: - goto bad_reg; - } - } else if (offset < 0x600) { - /* Interrupt controller. */ - if (offset < 0x200) { - id = gic_get_current_cpu(); - } else { - id = (offset - 0x200) >> 8; - if (id >= s->num_cpu) { - return 0; - } - } - return gic_cpu_read(&s->gic, id, offset & 0xff); - } else if (offset < 0xb00) { - /* Timers. */ - if (offset < 0x700) { - id = gic_get_current_cpu(); - } else { - id = (offset - 0x700) >> 8; - if (id >= s->num_cpu) { - return 0; - } - } - id <<= 1; - if (offset & 0x20) - id++; - return mpcore_timer_read(&s->timer[id], offset & 0xf); - } -bad_reg: - hw_error("mpcore_priv_read: Bad offset %x\n", (int)offset); - return 0; -} - -static void mpcore_priv_write(void *opaque, target_phys_addr_t offset, - uint64_t value, unsigned size) -{ - mpcore_priv_state *s = (mpcore_priv_state *)opaque; - int id; - offset &= 0xfff; - if (offset < 0x100) { - /* SCU */ - switch (offset) { - case 0: /* Control register. */ - s->scu_control = value & 1; - break; - case 0x0c: /* Invalidate all. */ - /* This is a no-op as cache is not emulated. */ - break; - default: - goto bad_reg; - } - } else if (offset < 0x600) { - /* Interrupt controller. */ - if (offset < 0x200) { - id = gic_get_current_cpu(); - } else { - id = (offset - 0x200) >> 8; - } - if (id < s->num_cpu) { - gic_cpu_write(&s->gic, id, offset & 0xff, value); - } - } else if (offset < 0xb00) { - /* Timers. */ - if (offset < 0x700) { - id = gic_get_current_cpu(); - } else { - id = (offset - 0x700) >> 8; - } - if (id < s->num_cpu) { - id <<= 1; - if (offset & 0x20) - id++; - mpcore_timer_write(&s->timer[id], offset & 0xf, value); - } - return; - } - return; -bad_reg: - hw_error("mpcore_priv_read: Bad offset %x\n", (int)offset); -} - -static const MemoryRegionOps mpcore_priv_ops = { - .read = mpcore_priv_read, - .write = mpcore_priv_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static void mpcore_priv_map_setup(mpcore_priv_state *s) -{ - memory_region_init(&s->container, "mpcode-priv-container", 0x2000); - memory_region_init_io(&s->iomem, &mpcore_priv_ops, s, "mpcode-priv", - 0x1000); - memory_region_add_subregion(&s->container, 0, &s->iomem); - memory_region_add_subregion(&s->container, 0x1000, &s->gic.iomem); -} - -static int mpcore_priv_init(SysBusDevice *dev) -{ - mpcore_priv_state *s = FROM_SYSBUSGIC(mpcore_priv_state, dev); - int i; - - gic_init(&s->gic, s->num_cpu); - mpcore_priv_map_setup(s); - sysbus_init_mmio(dev, &s->container); - for (i = 0; i < s->num_cpu * 2; i++) { - mpcore_timer_init(s, &s->timer[i], i); - } - return 0; -} diff --git a/hw/omap2.c b/hw/omap2.c index 91577ae128..c09c04a50f 100644 --- a/hw/omap2.c +++ b/hw/omap2.c @@ -1616,7 +1616,7 @@ static void omap_prcm_write(void *opaque, target_phys_addr_t addr, case 0x500: /* CM_CLKEN_PLL */ if (value & 0xffffff30) fprintf(stderr, "%s: write 0s in CM_CLKEN_PLL for " - "future compatiblity\n", __FUNCTION__); + "future compatibility\n", __FUNCTION__); if ((s->clken[9] ^ value) & 0xcc) { s->clken[9] &= ~0xcc; s->clken[9] |= value & 0xcc; @@ -1635,7 +1635,7 @@ static void omap_prcm_write(void *opaque, target_phys_addr_t addr, case 0x540: /* CM_CLKSEL1_PLL */ if (value & 0xfc4000d7) fprintf(stderr, "%s: write 0s in CM_CLKSEL1_PLL for " - "future compatiblity\n", __FUNCTION__); + "future compatibility\n", __FUNCTION__); if ((s->clksel[5] ^ value) & 0x003fff00) { s->clksel[5] = value & 0x03bfff28; omap_prcm_dpll_update(s); @@ -1647,7 +1647,7 @@ static void omap_prcm_write(void *opaque, target_phys_addr_t addr, case 0x544: /* CM_CLKSEL2_PLL */ if (value & ~3) fprintf(stderr, "%s: write 0s in CM_CLKSEL2_PLL[31:2] for " - "future compatiblity\n", __FUNCTION__); + "future compatibility\n", __FUNCTION__); if (s->clksel[6] != (value & 3)) { s->clksel[6] = value & 3; omap_prcm_dpll_update(s); @@ -983,7 +983,7 @@ void pc_memory_init(MemoryRegion *system_memory, linux_boot = (kernel_filename != NULL); /* Allocate RAM. We allocate it as a single memory region and use - * aliases to address portions of it, mostly for backwards compatiblity + * aliases to address portions of it, mostly for backwards compatibility * with older qemus that used qemu_ram_alloc(). */ ram = g_malloc(sizeof(*ram)); @@ -1069,38 +1069,44 @@ qemu_irq *pc_allocate_cpu_irq(void) return qemu_allocate_irqs(pic_irq_request, NULL, 1); } -void pc_vga_init(PCIBus *pci_bus) +DeviceState *pc_vga_init(PCIBus *pci_bus) { + DeviceState *dev = NULL; + if (cirrus_vga_enabled) { if (pci_bus) { - pci_cirrus_vga_init(pci_bus); + dev = pci_cirrus_vga_init(pci_bus); } else { - isa_cirrus_vga_init(get_system_memory()); + dev = isa_cirrus_vga_init(get_system_memory()); } } else if (vmsvga_enabled) { if (pci_bus) { - if (!pci_vmsvga_init(pci_bus)) { + dev = pci_vmsvga_init(pci_bus); + if (!dev) { fprintf(stderr, "Warning: vmware_vga not available," " using standard VGA instead\n"); - pci_vga_init(pci_bus); + dev = pci_vga_init(pci_bus); } } else { fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__); } #ifdef CONFIG_SPICE } else if (qxl_enabled) { - if (pci_bus) - pci_create_simple(pci_bus, -1, "qxl-vga"); - else + if (pci_bus) { + dev = &pci_create_simple(pci_bus, -1, "qxl-vga")->qdev; + } else { fprintf(stderr, "%s: qxl: no PCI bus\n", __FUNCTION__); + } #endif } else if (std_vga_enabled) { if (pci_bus) { - pci_vga_init(pci_bus); + dev = pci_vga_init(pci_bus); } else { - isa_vga_init(); + dev = isa_vga_init(); } } + + return dev; } static void cpu_request_exit(void *opaque, int irq, int level) @@ -140,7 +140,7 @@ void pc_memory_init(MemoryRegion *system_memory, MemoryRegion *rom_memory, MemoryRegion **ram_memory); qemu_irq *pc_allocate_cpu_irq(void); -void pc_vga_init(PCIBus *pci_bus); +DeviceState *pc_vga_init(PCIBus *pci_bus); void pc_basic_device_init(qemu_irq *gsi, ISADevice **rtc_state, ISADevice **floppy, @@ -205,27 +205,27 @@ enum vga_retrace_method { extern enum vga_retrace_method vga_retrace_method; -static inline int isa_vga_init(void) +static inline DeviceState *isa_vga_init(void) { ISADevice *dev; dev = isa_try_create("isa-vga"); if (!dev) { fprintf(stderr, "Warning: isa-vga not available\n"); - return 0; + return NULL; } qdev_init_nofail(&dev->qdev); - return 1; + return &dev->qdev; } -int pci_vga_init(PCIBus *bus); +DeviceState *pci_vga_init(PCIBus *bus); int isa_vga_mm_init(target_phys_addr_t vram_base, target_phys_addr_t ctrl_base, int it_shift, MemoryRegion *address_space); /* cirrus_vga.c */ -void pci_cirrus_vga_init(PCIBus *bus); -void isa_cirrus_vga_init(MemoryRegion *address_space); +DeviceState *pci_cirrus_vga_init(PCIBus *bus); +DeviceState *isa_cirrus_vga_init(MemoryRegion *address_space); /* ne2000.c */ static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd) diff --git a/hw/pc_piix.c b/hw/pc_piix.c index 970f43c99c..b9bb09d1e0 100644 --- a/hw/pc_piix.c +++ b/hw/pc_piix.c @@ -99,6 +99,7 @@ static void pc_init1(MemoryRegion *system_memory, MemoryRegion *ram_memory; MemoryRegion *pci_memory; MemoryRegion *rom_memory; + DeviceState *dev; pc_cpus_init(cpu_model); @@ -168,7 +169,10 @@ static void pc_init1(MemoryRegion *system_memory, pc_register_ferr_irq(gsi[13]); - pc_vga_init(pci_enabled? pci_bus: NULL); + dev = pc_vga_init(pci_enabled? pci_bus: NULL); + if (dev) { + qdev_property_add_child(qdev_get_root(), "vga", dev, NULL); + } if (xen_enabled()) { pci_create_simple(pci_bus, -1, "xen-platform"); @@ -205,6 +209,17 @@ static void pc_init1(MemoryRegion *system_memory, } } + /* FIXME there's some major spaghetti here. Somehow we create the devices + * on the PIIX before we actually create it. We create the PIIX3 deep in + * the recess of the i440fx creation too and then lose the DeviceState. + * + * For now, let's "fix" this by making judicious use of paths. This is not + * generally the right way to do this. + */ + + qdev_property_add_child(qdev_resolve_path("/i440fx/piix3", NULL), + "rtc", (DeviceState *)rtc_state, NULL); + audio_init(gsi, pci_enabled ? pci_bus : NULL); pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device, @@ -306,6 +321,14 @@ static QEMUMachine pc_machine_v1_0 = { .is_default = 1, }; +static QEMUMachine pc_machine_v0_15 = { + .name = "pc-0.15", + .desc = "Standard PC", + .init = pc_init_pci, + .max_cpus = 255, + .is_default = 1, +}; + static QEMUMachine pc_machine_v0_14 = { .name = "pc-0.14", .desc = "Standard PC", @@ -320,6 +343,22 @@ static QEMUMachine pc_machine_v0_14 = { .driver = "qxl-vga", .property = "revision", .value = stringify(2), + },{ + .driver = "virtio-blk-pci", + .property = "event_idx", + .value = "off", + },{ + .driver = "virtio-serial-pci", + .property = "event_idx", + .value = "off", + },{ + .driver = "virtio-net-pci", + .property = "event_idx", + .value = "off", + },{ + .driver = "virtio-balloon-pci", + .property = "event_idx", + .value = "off", }, { /* end of list */ } }, @@ -360,6 +399,10 @@ static QEMUMachine pc_machine_v0_13 = { .property = "event_idx", .value = "off", },{ + .driver = "virtio-balloon-pci", + .property = "event_idx", + .value = "off", + },{ .driver = "AC97", .property = "use_broken_id", .value = stringify(1), @@ -407,6 +450,10 @@ static QEMUMachine pc_machine_v0_12 = { .property = "event_idx", .value = "off", },{ + .driver = "virtio-balloon-pci", + .property = "event_idx", + .value = "off", + },{ .driver = "AC97", .property = "use_broken_id", .value = stringify(1), @@ -462,6 +509,10 @@ static QEMUMachine pc_machine_v0_11 = { .property = "event_idx", .value = "off", },{ + .driver = "virtio-balloon-pci", + .property = "event_idx", + .value = "off", + },{ .driver = "AC97", .property = "use_broken_id", .value = stringify(1), @@ -529,6 +580,10 @@ static QEMUMachine pc_machine_v0_10 = { .property = "event_idx", .value = "off", },{ + .driver = "virtio-balloon-pci", + .property = "event_idx", + .value = "off", + },{ .driver = "AC97", .property = "use_broken_id", .value = stringify(1), @@ -557,6 +612,7 @@ static QEMUMachine xenfv_machine = { static void pc_machine_init(void) { qemu_register_machine(&pc_machine_v1_0); + qemu_register_machine(&pc_machine_v0_15); qemu_register_machine(&pc_machine_v0_14); qemu_register_machine(&pc_machine_v0_13); qemu_register_machine(&pc_machine_v0_12); diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index b59be2a599..12f61fea6e 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -91,7 +91,8 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter, */ dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1); dinfo->bus = scsibus->busnr; - scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit, false); + scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit, + false, -1); if (!scsidev) { return -1; } diff --git a/hw/pci-stub.c b/hw/pci-stub.c index 636171c16f..134c4484b6 100644 --- a/hw/pci-stub.c +++ b/hw/pci-stub.c @@ -34,7 +34,7 @@ static void pci_error_message(Monitor *mon) monitor_printf(mon, "PCI devices not supported\n"); } -int do_pcie_aer_inejct_error(Monitor *mon, +int do_pcie_aer_inject_error(Monitor *mon, const QDict *qdict, QObject **ret_data) { pci_error_message(mon); diff --git a/hw/pcie_aer.c b/hw/pcie_aer.c index 62c06eafd6..3b6981c7b7 100644 --- a/hw/pcie_aer.c +++ b/hw/pcie_aer.c @@ -826,7 +826,7 @@ typedef struct PCIEAERErrorName { } PCIEAERErrorName; /* - * AER error name -> value convertion table + * AER error name -> value conversion table * This naming scheme is same to linux aer-injection tool. */ static const struct PCIEAERErrorName pcie_aer_error_list[] = { @@ -951,7 +951,7 @@ static int pcie_aer_parse_error_string(const char *error_name, return -EINVAL; } -int do_pcie_aer_inejct_error(Monitor *mon, +int do_pcie_aer_inject_error(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *id = qdict_get_str(qdict, "id"); diff --git a/hw/piix_pci.c b/hw/piix_pci.c index ac3d8980e8..43c85aa3d8 100644 --- a/hw/piix_pci.c +++ b/hw/piix_pci.c @@ -278,6 +278,7 @@ static PCIBus *i440fx_common_init(const char *device_name, address_space_io, 0); s->bus = b; qdev_init_nofail(dev); + qdev_property_add_child(qdev_get_root(), "i440fx", dev, NULL); d = pci_create_simple(b, 0, device_name); *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d); @@ -316,6 +317,7 @@ static PCIBus *i440fx_common_init(const char *device_name, pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3, PIIX_NUM_PIRQS); } + qdev_property_add_child(dev, "piix3", &piix3->dev.qdev, NULL); piix3->pic = pic; (*pi440fx_state)->piix3 = piix3; diff --git a/hw/pl041.c b/hw/pl041.c index d8e55d1ef2..4585ccf9c0 100644 --- a/hw/pl041.c +++ b/hw/pl041.c @@ -4,7 +4,7 @@ * Copyright (c) 2011 * Written by Mathieu Sonet - www.elasticsheep.com * - * This code is licenced under the GPL. + * This code is licensed under the GPL. * * ***************************************************************** * diff --git a/hw/pl041.h b/hw/pl041.h index 1f224326e5..427ab6d6f8 100644 --- a/hw/pl041.h +++ b/hw/pl041.h @@ -4,7 +4,7 @@ * Copyright (c) 2011 * Written by Mathieu Sonet - www.elasticsheep.com * - * This code is licenced under the GPL. + * This code is licensed under the GPL. * * ***************************************************************** */ diff --git a/hw/pl041.hx b/hw/pl041.hx index e972996725..dd7188cbcb 100644 --- a/hw/pl041.hx +++ b/hw/pl041.hx @@ -4,7 +4,7 @@ * Copyright (c) 2011 * Written by Mathieu Sonet - www.elasticsheep.com * - * This code is licenced under the GPL. + * This code is licensed under the GPL. * * ***************************************************************** */ diff --git a/hw/pl110.c b/hw/pl110.c index 7aef8a4e25..cc1eb6d986 100644 --- a/hw/pl110.c +++ b/hw/pl110.c @@ -358,7 +358,7 @@ static void pl110_write(void *opaque, target_phys_addr_t offset, int n; /* For simplicity invalidate the display whenever a control register - is writen to. */ + is written to. */ s->invalidate = 1; if (offset >= 0x200 && offset < 0x400) { /* Pallette. */ diff --git a/hw/pl181.c b/hw/pl181.c index 46855f69de..d05bc191be 100644 --- a/hw/pl181.c +++ b/hw/pl181.c @@ -311,9 +311,9 @@ static uint64_t pl181_read(void *opaque, target_phys_addr_t offset, case 0x48: /* FifoCnt */ /* The documentation is somewhat vague about exactly what FifoCnt does. On real hardware it appears to be when decrememnted - when a word is transfered between the FIFO and the serial + when a word is transferred between the FIFO and the serial data engine. DataCnt is decremented after each byte is - transfered between the serial engine and the card. + transferred between the serial engine and the card. We don't emulate this level of detail, so both can be the same. */ tmp = (s->datacnt + 3) >> 2; if (s->linux_hack) { @@ -1153,7 +1153,7 @@ void PPC_debug_write (void *opaque, uint32_t addr, uint32_t val) /* NVRAM helpers */ static inline uint32_t nvram_read (nvram_t *nvram, uint32_t addr) { - return (*nvram->read_fn)(nvram->opaque, addr);; + return (*nvram->read_fn)(nvram->opaque, addr); } static inline void nvram_write (nvram_t *nvram, uint32_t addr, uint32_t val) @@ -83,6 +83,7 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name) static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info) { DeviceState *dev; + Property *prop; assert(bus->info == info->bus_info); dev = g_malloc0(info->size); @@ -98,7 +99,19 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info) qdev_hot_added = true; } dev->instance_id_alias = -1; + QTAILQ_INIT(&dev->properties); dev->state = DEV_STATE_CREATED; + + for (prop = dev->info->props; prop && prop->name; prop++) { + qdev_property_add_legacy(dev, prop, NULL); + } + + for (prop = dev->info->bus_info->props; prop && prop->name; prop++) { + qdev_property_add_legacy(dev, prop, NULL); + } + + qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL); + return dev; } @@ -216,6 +229,32 @@ int qdev_device_help(QemuOpts *opts) return 1; } +static DeviceState *qdev_get_peripheral(void) +{ + static DeviceState *dev; + + if (dev == NULL) { + dev = qdev_create(NULL, "container"); + qdev_property_add_child(qdev_get_root(), "peripheral", dev, NULL); + qdev_init_nofail(dev); + } + + return dev; +} + +static DeviceState *qdev_get_peripheral_anon(void) +{ + static DeviceState *dev; + + if (dev == NULL) { + dev = qdev_create(NULL, "container"); + qdev_property_add_child(qdev_get_root(), "peripheral-anon", dev, NULL); + qdev_init_nofail(dev); + } + + return dev; +} + DeviceState *qdev_device_add(QemuOpts *opts) { const char *driver, *path, *id; @@ -267,7 +306,14 @@ DeviceState *qdev_device_add(QemuOpts *opts) id = qemu_opts_id(opts); if (id) { qdev->id = id; - } + qdev_property_add_child(qdev_get_peripheral(), qdev->id, qdev, NULL); + } else { + static int anon_count; + gchar *name = g_strdup_printf("device[%d]", anon_count++); + qdev_property_add_child(qdev_get_peripheral_anon(), name, + qdev, NULL); + g_free(name); + } if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) { qdev_free(qdev); return NULL; @@ -323,6 +369,11 @@ int qdev_unplug(DeviceState *dev) } assert(dev->info->unplug != NULL); + if (dev->ref != 0) { + qerror_report(QERR_DEVICE_IN_USE, dev->id?:""); + return -1; + } + qdev_hot_removed = true; return dev->info->unplug(dev); @@ -390,12 +441,31 @@ void qdev_init_nofail(DeviceState *dev) } } +static void qdev_property_del_all(DeviceState *dev) +{ + while (!QTAILQ_EMPTY(&dev->properties)) { + DeviceProperty *prop = QTAILQ_FIRST(&dev->properties); + + QTAILQ_REMOVE(&dev->properties, prop, node); + + if (prop->release) { + prop->release(dev, prop->name, prop->opaque); + } + + g_free(prop->name); + g_free(prop->type); + g_free(prop); + } +} + /* Unlink device from bus and free the structure. */ void qdev_free(DeviceState *dev) { BusState *bus; Property *prop; + qdev_property_del_all(dev); + if (dev->state == DEV_STATE_INITIALIZED) { while (dev->num_child_bus) { bus = QLIST_FIRST(&dev->child_bus); @@ -962,3 +1032,486 @@ char* qdev_get_fw_dev_path(DeviceState *dev) return strdup(path); } + +char *qdev_get_type(DeviceState *dev, Error **errp) +{ + return g_strdup(dev->info->name); +} + +void qdev_ref(DeviceState *dev) +{ + dev->ref++; +} + +void qdev_unref(DeviceState *dev) +{ + g_assert(dev->ref > 0); + dev->ref--; +} + +void qdev_property_add(DeviceState *dev, const char *name, const char *type, + DevicePropertyAccessor *get, DevicePropertyAccessor *set, + DevicePropertyRelease *release, + void *opaque, Error **errp) +{ + DeviceProperty *prop = g_malloc0(sizeof(*prop)); + + prop->name = g_strdup(name); + prop->type = g_strdup(type); + + prop->get = get; + prop->set = set; + prop->release = release; + prop->opaque = opaque; + + QTAILQ_INSERT_TAIL(&dev->properties, prop, node); +} + +static DeviceProperty *qdev_property_find(DeviceState *dev, const char *name) +{ + DeviceProperty *prop; + + QTAILQ_FOREACH(prop, &dev->properties, node) { + if (strcmp(prop->name, name) == 0) { + return prop; + } + } + + return NULL; +} + +void qdev_property_get(DeviceState *dev, Visitor *v, const char *name, + Error **errp) +{ + DeviceProperty *prop = qdev_property_find(dev, name); + + if (prop == NULL) { + error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name); + return; + } + + if (!prop->get) { + error_set(errp, QERR_PERMISSION_DENIED); + } else { + prop->get(dev, v, prop->opaque, name, errp); + } +} + +void qdev_property_set(DeviceState *dev, Visitor *v, const char *name, + Error **errp) +{ + DeviceProperty *prop = qdev_property_find(dev, name); + + if (prop == NULL) { + error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name); + return; + } + + if (!prop->set) { + error_set(errp, QERR_PERMISSION_DENIED); + } else { + prop->set(dev, prop->opaque, v, name, errp); + } +} + +const char *qdev_property_get_type(DeviceState *dev, const char *name, Error **errp) +{ + DeviceProperty *prop = qdev_property_find(dev, name); + + if (prop == NULL) { + error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name); + return NULL; + } + + return prop->type; +} + +/** + * Legacy property handling + */ + +static void qdev_get_legacy_property(DeviceState *dev, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + Property *prop = opaque; + + if (prop->info->print) { + char buffer[1024]; + char *ptr = buffer; + + prop->info->print(dev, prop, buffer, sizeof(buffer)); + visit_type_str(v, &ptr, name, errp); + } else { + error_set(errp, QERR_PERMISSION_DENIED); + } +} + +static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + Property *prop = opaque; + + if (dev->state != DEV_STATE_CREATED) { + error_set(errp, QERR_PERMISSION_DENIED); + return; + } + + if (prop->info->parse) { + Error *local_err = NULL; + char *ptr = NULL; + + visit_type_str(v, &ptr, name, &local_err); + if (!local_err) { + int ret; + ret = prop->info->parse(dev, prop, ptr); + if (ret != 0) { + error_set(errp, QERR_INVALID_PARAMETER_VALUE, + name, prop->info->name); + } + g_free(ptr); + } else { + error_propagate(errp, local_err); + } + } else { + error_set(errp, QERR_PERMISSION_DENIED); + } +} + +/** + * @qdev_add_legacy_property - adds a legacy property + * + * Do not use this is new code! Properties added through this interface will + * be given types in the "legacy<>" type namespace. + * + * Legacy properties are always processed as strings. The format of the string + * depends on the property type. + */ +void qdev_property_add_legacy(DeviceState *dev, Property *prop, + Error **errp) +{ + gchar *type; + + type = g_strdup_printf("legacy<%s>", prop->info->name); + + qdev_property_add(dev, prop->name, type, + qdev_get_legacy_property, + qdev_set_legacy_property, + NULL, + prop, errp); + + g_free(type); +} + +DeviceState *qdev_get_root(void) +{ + static DeviceState *qdev_root; + + if (!qdev_root) { + qdev_root = qdev_create(NULL, "container"); + qdev_init_nofail(qdev_root); + } + + return qdev_root; +} + +static void qdev_get_child_property(DeviceState *dev, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + DeviceState *child = opaque; + gchar *path; + + path = qdev_get_canonical_path(child); + visit_type_str(v, &path, name, errp); + g_free(path); +} + +void qdev_property_add_child(DeviceState *dev, const char *name, + DeviceState *child, Error **errp) +{ + gchar *type; + + type = g_strdup_printf("child<%s>", child->info->name); + + qdev_property_add(dev, name, type, qdev_get_child_property, + NULL, NULL, child, errp); + + qdev_ref(child); + g_assert(child->parent == NULL); + child->parent = dev; + + g_free(type); +} + +static void qdev_get_link_property(DeviceState *dev, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + DeviceState **child = opaque; + gchar *path; + + if (*child) { + path = qdev_get_canonical_path(*child); + visit_type_str(v, &path, name, errp); + g_free(path); + } else { + path = (gchar *)""; + visit_type_str(v, &path, name, errp); + } +} + +static void qdev_set_link_property(DeviceState *dev, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + DeviceState **child = opaque; + bool ambiguous = false; + const char *type; + char *path; + + type = qdev_property_get_type(dev, name, NULL); + + visit_type_str(v, &path, name, errp); + + if (*child) { + qdev_unref(*child); + } + + if (strcmp(path, "") != 0) { + DeviceState *target; + + target = qdev_resolve_path(path, &ambiguous); + if (target) { + gchar *target_type; + + target_type = g_strdup_printf("link<%s>", target->info->name); + if (strcmp(target_type, type) == 0) { + *child = target; + qdev_ref(target); + } else { + error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, type); + } + + g_free(target_type); + } else { + error_set(errp, QERR_DEVICE_NOT_FOUND, path); + } + } else { + *child = NULL; + } + + g_free(path); +} + +void qdev_property_add_link(DeviceState *dev, const char *name, + const char *type, DeviceState **child, + Error **errp) +{ + gchar *full_type; + + full_type = g_strdup_printf("link<%s>", type); + + qdev_property_add(dev, name, full_type, + qdev_get_link_property, + qdev_set_link_property, + NULL, child, errp); + + g_free(full_type); +} + +gchar *qdev_get_canonical_path(DeviceState *dev) +{ + DeviceState *root = qdev_get_root(); + char *newpath = NULL, *path = NULL; + + while (dev != root) { + DeviceProperty *prop = NULL; + + g_assert(dev->parent != NULL); + + QTAILQ_FOREACH(prop, &dev->parent->properties, node) { + if (!strstart(prop->type, "child<", NULL)) { + continue; + } + + if (prop->opaque == dev) { + if (path) { + newpath = g_strdup_printf("%s/%s", prop->name, path); + g_free(path); + path = newpath; + } else { + path = g_strdup(prop->name); + } + break; + } + } + + g_assert(prop != NULL); + + dev = dev->parent; + } + + newpath = g_strdup_printf("/%s", path); + g_free(path); + + return newpath; +} + +static DeviceState *qdev_resolve_abs_path(DeviceState *parent, + gchar **parts, + int index) +{ + DeviceProperty *prop; + DeviceState *child; + + if (parts[index] == NULL) { + return parent; + } + + if (strcmp(parts[index], "") == 0) { + return qdev_resolve_abs_path(parent, parts, index + 1); + } + + prop = qdev_property_find(parent, parts[index]); + if (prop == NULL) { + return NULL; + } + + child = NULL; + if (strstart(prop->type, "link<", NULL)) { + DeviceState **pchild = prop->opaque; + if (*pchild) { + child = *pchild; + } + } else if (strstart(prop->type, "child<", NULL)) { + child = prop->opaque; + } + + if (!child) { + return NULL; + } + + return qdev_resolve_abs_path(child, parts, index + 1); +} + +static DeviceState *qdev_resolve_partial_path(DeviceState *parent, + gchar **parts, + bool *ambiguous) +{ + DeviceState *dev; + DeviceProperty *prop; + + dev = qdev_resolve_abs_path(parent, parts, 0); + + QTAILQ_FOREACH(prop, &parent->properties, node) { + DeviceState *found; + + if (!strstart(prop->type, "child<", NULL)) { + continue; + } + + found = qdev_resolve_partial_path(prop->opaque, parts, ambiguous); + if (found) { + if (dev) { + if (ambiguous) { + *ambiguous = true; + } + return NULL; + } + dev = found; + } + + if (ambiguous && *ambiguous) { + return NULL; + } + } + + return dev; +} + +DeviceState *qdev_resolve_path(const char *path, bool *ambiguous) +{ + bool partial_path = true; + DeviceState *dev; + gchar **parts; + + parts = g_strsplit(path, "/", 0); + if (parts == NULL || parts[0] == NULL) { + g_strfreev(parts); + return qdev_get_root(); + } + + if (strcmp(parts[0], "") == 0) { + partial_path = false; + } + + if (partial_path) { + if (ambiguous) { + *ambiguous = false; + } + dev = qdev_resolve_partial_path(qdev_get_root(), parts, ambiguous); + } else { + dev = qdev_resolve_abs_path(qdev_get_root(), parts, 1); + } + + g_strfreev(parts); + + return dev; +} + +typedef struct StringProperty +{ + char *(*get)(DeviceState *, Error **); + void (*set)(DeviceState *, const char *, Error **); +} StringProperty; + +static void qdev_property_get_str(DeviceState *dev, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + StringProperty *prop = opaque; + char *value; + + value = prop->get(dev, errp); + if (value) { + visit_type_str(v, &value, name, errp); + g_free(value); + } +} + +static void qdev_property_set_str(DeviceState *dev, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + StringProperty *prop = opaque; + char *value; + Error *local_err = NULL; + + visit_type_str(v, &value, name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + prop->set(dev, value, errp); + g_free(value); +} + +static void qdev_property_release_str(DeviceState *dev, const char *name, + void *opaque) +{ + StringProperty *prop = opaque; + g_free(prop); +} + +void qdev_property_add_str(DeviceState *dev, const char *name, + char *(*get)(DeviceState *, Error **), + void (*set)(DeviceState *, const char *, Error **), + Error **errp) +{ + StringProperty *prop = g_malloc0(sizeof(*prop)); + + prop->get = get; + prop->set = set; + + qdev_property_add(dev, name, "string", + get ? qdev_property_get_str : NULL, + set ? qdev_property_set_str : NULL, + qdev_property_release_str, + prop, errp); +} @@ -5,6 +5,7 @@ #include "qemu-queue.h" #include "qemu-char.h" #include "qemu-option.h" +#include "qapi/qapi-visit-core.h" typedef struct Property Property; @@ -27,6 +28,44 @@ enum { DEV_NVECTORS_UNSPECIFIED = -1, }; +/** + * @DevicePropertyAccessor - called when trying to get/set a property + * + * @dev the device that owns the property + * @v the visitor that contains the property data + * @opaque the device property opaque + * @name the name of the property + * @errp a pointer to an Error that is filled if getting/setting fails. + */ +typedef void (DevicePropertyAccessor)(DeviceState *dev, + Visitor *v, + void *opaque, + const char *name, + Error **errp); + +/** + * @DevicePropertyRelease - called when a property is removed from a device + * + * @dev the device that owns the property + * @name the name of the property + * @opaque the opaque registered with the property + */ +typedef void (DevicePropertyRelease)(DeviceState *dev, + const char *name, + void *opaque); + +typedef struct DeviceProperty +{ + gchar *name; + gchar *type; + DevicePropertyAccessor *get; + DevicePropertyAccessor *set; + DevicePropertyRelease *release; + void *opaque; + + QTAILQ_ENTRY(DeviceProperty) node; +} DeviceProperty; + /* This structure should not be accessed directly. We declare it here so that it can be embedded in individual device state structures. */ struct DeviceState { @@ -45,6 +84,18 @@ struct DeviceState { QTAILQ_ENTRY(DeviceState) sibling; int instance_id_alias; int alias_required_for_version; + + /** + * This tracks the number of references between devices. See @qdev_ref for + * more information. + */ + uint32_t ref; + + QTAILQ_HEAD(, DeviceProperty) properties; + + /* Do not, under any circumstance, use this parent link below anywhere + * outside of qdev.c. You have been warned. */ + DeviceState *parent; }; typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent); @@ -329,4 +380,234 @@ char *qdev_get_fw_dev_path(DeviceState *dev); /* This is a nasty hack to allow passing a NULL bus to qdev_create. */ extern struct BusInfo system_bus_info; +/** + * @qdev_ref + * + * Increase the reference count of a device. A device cannot be freed as long + * as its reference count is greater than zero. + * + * @dev - the device + */ +void qdev_ref(DeviceState *dev); + +/** + * @qdef_unref + * + * Decrease the reference count of a device. A device cannot be freed as long + * as its reference count is greater than zero. + * + * @dev - the device + */ +void qdev_unref(DeviceState *dev); + +/** + * @qdev_property_add - add a new property to a device + * + * @dev - the device to add a property to + * + * @name - the name of the property. This can contain any character except for + * a forward slash. In general, you should use hyphens '-' instead of + * underscores '_' when naming properties. + * + * @type - the type name of the property. This namespace is pretty loosely + * defined. Sub namespaces are constructed by using a prefix and then + * to angle brackets. For instance, the type 'virtio-net-pci' in the + * 'link' namespace would be 'link<virtio-net-pci>'. + * + * @get - the getter to be called to read a property. If this is NULL, then + * the property cannot be read. + * + * @set - the setter to be called to write a property. If this is NULL, + * then the property cannot be written. + * + * @release - called when the property is removed from the device. This is + * meant to allow a property to free its opaque upon device + * destruction. This may be NULL. + * + * @opaque - an opaque pointer to pass to the callbacks for the property + * + * @errp - returns an error if this function fails + */ +void qdev_property_add(DeviceState *dev, const char *name, const char *type, + DevicePropertyAccessor *get, DevicePropertyAccessor *set, + DevicePropertyRelease *release, + void *opaque, Error **errp); + +/** + * @qdev_property_get - reads a property from a device + * + * @dev - the device + * + * @v - the visitor that will receive the property value. This should be an + * Output visitor and the data will be written with @name as the name. + * + * @name - the name of the property + * + * @errp - returns an error if this function fails + */ +void qdev_property_get(DeviceState *dev, Visitor *v, const char *name, + Error **errp); + +/** + * @qdev_property_set - writes a property to a device + * + * @dev - the device + * + * @v - the visitor that will be used to write the property value. This should + * be an Input visitor and the data will be first read with @name as the + * name and then written as the property value. + * + * @name - the name of the property + * + * @errp - returns an error if this function fails + */ +void qdev_property_set(DeviceState *dev, Visitor *v, const char *name, + Error **errp); + +/** + * @qdev_property_get_type - returns the type of a property + * + * @dev - the device + * + * @name - the name of the property + * + * @errp - returns an error if this function fails + * + * Returns: + * The type name of the property. + */ +const char *qdev_property_get_type(DeviceState *dev, const char *name, + Error **errp); + +/** + * @qdev_property_add_legacy - add a legacy @Property to a device + * + * DO NOT USE THIS IN NEW CODE! + */ +void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp); + +/** + * @qdev_get_root - returns the root device of the composition tree + * + * Returns: + * The root of the composition tree. + */ +DeviceState *qdev_get_root(void); + +/** + * @qdev_get_canonical_path - returns the canonical path for a device. This + * is the path within the composition tree starting from the root. + * + * Returns: + * The canonical path in the composition tree. + */ +gchar *qdev_get_canonical_path(DeviceState *dev); + +/** + * @qdev_resolve_path - resolves a path returning a device + * + * There are two types of supported paths--absolute paths and partial paths. + * + * Absolute paths are derived from the root device and can follow child<> or + * link<> properties. Since they can follow link<> properties, they can be + * arbitrarily long. Absolute paths look like absolute filenames and are + * prefixed with a leading slash. + * + * Partial paths look like relative filenames. They do not begin with a + * prefix. The matching rules for partial paths are subtle but designed to make + * specifying devices easy. At each level of the composition tree, the partial + * path is matched as an absolute path. The first match is not returned. At + * least two matches are searched for. A successful result is only returned if + * only one match is founded. If more than one match is found, a flag is + * return to indicate that the match was ambiguous. + * + * @path - the path to resolve + * + * @ambiguous - returns true if the path resolution failed because of an + * ambiguous match + * + * Returns: + * The matched device or NULL on path lookup failure. + */ +DeviceState *qdev_resolve_path(const char *path, bool *ambiguous); + +/** + * @qdev_property_add_child - Add a child property to a device + * + * Child properties form the composition tree. All devices need to be a child + * of another device. Devices can only be a child of one device. + * + * There is no way for a child to determine what its parent is. It is not + * a bidirectional relationship. This is by design. + * + * @dev - the device to add a property to + * + * @name - the name of the property + * + * @child - the child device + * + * @errp - if an error occurs, a pointer to an area to store the area + */ +void qdev_property_add_child(DeviceState *dev, const char *name, + DeviceState *child, Error **errp); + +/** + * @qdev_property_add_link - Add a link property to a device + * + * Links establish relationships between devices. Links are unidirectional + * although two links can be combined to form a bidirectional relationship + * between devices. + * + * Links form the graph in the device model. + * + * @dev - the device to add a property to + * + * @name - the name of the property + * + * @type - the qdev type of the link + * + * @child - a pointer to where the link device reference is stored + * + * @errp - if an error occurs, a pointer to an area to store the area + */ +void qdev_property_add_link(DeviceState *dev, const char *name, + const char *type, DeviceState **child, + Error **errp); + +/** + * @qdev_property_add_str + * + * Add a string property using getters/setters. This function will add a + * property of type 'string'. + * + * @dev - the device to add a property to + * + * @name - the name of the property + * + * @get - the getter or NULL if the property is write-only. This function must + * return a string to be freed by @g_free(). + * + * @set - the setter or NULL if the property is read-only + * + * @errp - if an error occurs, a pointer to an area to store the error + */ +void qdev_property_add_str(DeviceState *dev, const char *name, + char *(*get)(DeviceState *, Error **), + void (*set)(DeviceState *, const char *, Error **), + Error **errp); + +/** + * @qdev_get_type + * + * Returns the string representation of the type of this object. + * + * @dev - the device + * + * @errp - if an error occurs, a pointer to an area to store the error + * + * Returns: a string representing the type. This must be freed by the caller + * with g_free(). + */ +char *qdev_get_type(DeviceState *dev, Error **errp); + #endif diff --git a/hw/qxl-render.c b/hw/qxl-render.c index 2c51ba9806..133d09324c 100644 --- a/hw/qxl-render.c +++ b/hw/qxl-render.c @@ -157,7 +157,7 @@ static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor) { QEMUCursor *c; uint8_t *image, *mask; - int size; + size_t size; c = cursor_alloc(cursor->header.width, cursor->header.height); c->hot_x = cursor->header.hot_spot_x; diff --git a/hw/realview_gic.c b/hw/realview_gic.c index 479f939553..8c4d509ee7 100644 --- a/hw/realview_gic.c +++ b/hw/realview_gic.c @@ -23,36 +23,13 @@ gic_get_current_cpu(void) typedef struct { gic_state gic; - MemoryRegion iomem; MemoryRegion container; } RealViewGICState; -static uint64_t realview_gic_cpu_read(void *opaque, target_phys_addr_t offset, - unsigned size) -{ - gic_state *s = (gic_state *)opaque; - return gic_cpu_read(s, gic_get_current_cpu(), offset); -} - -static void realview_gic_cpu_write(void *opaque, target_phys_addr_t offset, - uint64_t value, unsigned size) -{ - gic_state *s = (gic_state *)opaque; - gic_cpu_write(s, gic_get_current_cpu(), offset, value); -} - -static const MemoryRegionOps realview_gic_cpu_ops = { - .read = realview_gic_cpu_read, - .write = realview_gic_cpu_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - static void realview_gic_map_setup(RealViewGICState *s) { memory_region_init(&s->container, "realview-gic-container", 0x2000); - memory_region_init_io(&s->iomem, &realview_gic_cpu_ops, &s->gic, - "realview-gic", 0x1000); - memory_region_add_subregion(&s->container, 0, &s->iomem); + memory_region_add_subregion(&s->container, 0, &s->gic.cpuiomem[0]); memory_region_add_subregion(&s->container, 0x1000, &s->gic.iomem); } diff --git a/hw/rtl8139.c b/hw/rtl8139.c index 4c379932e3..0ae9f5774b 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -991,13 +991,13 @@ static ssize_t rtl8139_do_receive(VLANClientState *nc, const uint8_t *buf, size_ uint32_t val, rxdw0,rxdw1,rxbufLO,rxbufHI; - pci_dma_read(&s->dev, cplus_rx_ring_desc, (uint8_t *)&val, 4); + pci_dma_read(&s->dev, cplus_rx_ring_desc, &val, 4); rxdw0 = le32_to_cpu(val); - pci_dma_read(&s->dev, cplus_rx_ring_desc+4, (uint8_t *)&val, 4); + pci_dma_read(&s->dev, cplus_rx_ring_desc+4, &val, 4); rxdw1 = le32_to_cpu(val); - pci_dma_read(&s->dev, cplus_rx_ring_desc+8, (uint8_t *)&val, 4); + pci_dma_read(&s->dev, cplus_rx_ring_desc+8, &val, 4); rxbufLO = le32_to_cpu(val); - pci_dma_read(&s->dev, cplus_rx_ring_desc+12, (uint8_t *)&val, 4); + pci_dma_read(&s->dev, cplus_rx_ring_desc+12, &val, 4); rxbufHI = le32_to_cpu(val); DPRINTF("+++ C+ mode RX descriptor %d %08x %08x %08x %08x\n", @@ -1971,7 +1971,7 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s) cplus_tx_ring_desc += 16 * descriptor; DPRINTF("+++ C+ mode reading TX descriptor %d from host memory at " - "%08x0x%08x = 0x"DMA_ADDR_FMT"\n", descriptor, s->TxAddr[1], + "%08x %08x = 0x"DMA_ADDR_FMT"\n", descriptor, s->TxAddr[1], s->TxAddr[0], cplus_tx_ring_desc); uint32_t val, txdw0,txdw1,txbufLO,txbufHI; @@ -2662,7 +2662,7 @@ static void rtl8139_IntrStatus_write(RTL8139State *s, uint32_t val) * Computing if we miss an interrupt here is not that correct but * considered that we should have had already an interrupt * and probably emulated is slower is better to assume this resetting was - * done before testing on previous rtl8139_update_irq lead to IRQ loosing + * done before testing on previous rtl8139_update_irq lead to IRQ losing */ rtl8139_set_next_tctr_time(s, qemu_get_clock_ns(vm_clock)); rtl8139_update_irq(s); @@ -2713,8 +2713,6 @@ static void rtl8139_io_writeb(void *opaque, uint8_t addr, uint32_t val) { RTL8139State *s = opaque; - addr &= 0xff; - switch (addr) { case MAC0 ... MAC0+5: @@ -2800,8 +2798,6 @@ static void rtl8139_io_writew(void *opaque, uint8_t addr, uint32_t val) { RTL8139State *s = opaque; - addr &= 0xfe; - switch (addr) { case IntrMask: @@ -2900,8 +2896,6 @@ static void rtl8139_io_writel(void *opaque, uint8_t addr, uint32_t val) { RTL8139State *s = opaque; - addr &= 0xfc; - switch (addr) { case RxMissed: @@ -2969,8 +2963,6 @@ static uint32_t rtl8139_io_readb(void *opaque, uint8_t addr) RTL8139State *s = opaque; int ret; - addr &= 0xff; - switch (addr) { case MAC0 ... MAC0+5: @@ -3043,8 +3035,6 @@ static uint32_t rtl8139_io_readw(void *opaque, uint8_t addr) RTL8139State *s = opaque; uint32_t ret; - addr &= 0xfe; /* mask lower bit */ - switch (addr) { case IntrMask: @@ -3120,8 +3110,6 @@ static uint32_t rtl8139_io_readl(void *opaque, uint8_t addr) RTL8139State *s = opaque; uint32_t ret; - addr &= 0xfc; /* also mask low 2 bits */ - switch (addr) { case RxMissed: diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c index 0ce6406b6d..c4b9a99e6e 100644 --- a/hw/s390-virtio-bus.c +++ b/hw/s390-virtio-bus.c @@ -254,10 +254,7 @@ void s390_virtio_device_update_status(VirtIOS390Device *dev) /* Update guest supported feature bitmap */ features = bswap32(ldl_be_phys(dev->feat_offs)); - if (vdev->set_features) { - vdev->set_features(vdev, features); - } - vdev->guest_features = features; + virtio_set_features(vdev, features); } VirtIOS390Device *s390_virtio_bus_console(VirtIOS390Bus *bus) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 3a2a7bb72c..64e709ee9f 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -162,7 +162,7 @@ void scsi_qdev_register(SCSIDeviceInfo *info) /* handle legacy '-drive if=scsi,...' cmd line args */ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, - int unit, bool removable) + int unit, bool removable, int bootindex) { const char *driver; DeviceState *dev; @@ -170,6 +170,9 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk"; dev = qdev_create(&bus->qbus, driver); qdev_prop_set_uint32(dev, "scsi-id", unit); + if (bootindex >= 0) { + qdev_prop_set_int32(dev, "bootindex", bootindex); + } if (qdev_prop_exists(dev, "removable")) { qdev_prop_set_bit(dev, "removable", removable); } @@ -195,7 +198,7 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus) continue; } qemu_opts_loc_restore(dinfo->opts); - if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false)) { + if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1)) { res = -1; break; } @@ -1367,8 +1370,8 @@ static char *scsibus_get_fw_dev_path(DeviceState *dev) SCSIDevice *d = DO_UPCAST(SCSIDevice, qdev, dev); char path[100]; - snprintf(path, sizeof(path), "%s@%d,%d,%d", qdev_fw_name(dev), - d->channel, d->id, d->lun); + snprintf(path, sizeof(path), "channel@%x/%s@%x,%x", d->channel, + qdev_fw_name(dev), d->id, d->lun); return strdup(path); } diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 673948c51f..505accdde5 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -217,9 +217,6 @@ static void scsi_read_data(SCSIRequest *req) bdrv_acct_start(s->qdev.conf.bs, &r->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ); r->req.aiocb = bdrv_aio_readv(s->qdev.conf.bs, r->sector, &r->qiov, n, scsi_read_complete, r); - if (r->req.aiocb == NULL) { - scsi_read_complete(r, -EIO); - } } /* @@ -327,9 +324,6 @@ static void scsi_write_data(SCSIRequest *req) bdrv_acct_start(s->qdev.conf.bs, &r->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_WRITE); r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, r->sector, &r->qiov, n, scsi_write_complete, r); - if (r->req.aiocb == NULL) { - scsi_write_complete(r, -ENOMEM); - } } else { /* Called for the first time. Ask the driver to send us more data. */ scsi_write_complete(r, 0); @@ -1332,9 +1326,6 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) scsi_req_ref(&r->req); bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BDRV_ACCT_FLUSH); r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_flush_complete, r); - if (r->req.aiocb == NULL) { - scsi_flush_complete(r, -EIO); - } return 0; case READ_6: case READ_10: diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c index 9594cc1276..6f7d3db775 100644 --- a/hw/scsi-generic.c +++ b/hw/scsi-generic.c @@ -152,10 +152,6 @@ static int execute_command(BlockDriverState *bdrv, r->io_header.flags |= SG_FLAG_DIRECT_IO; r->req.aiocb = bdrv_aio_ioctl(bdrv, SG_IO, &r->io_header, complete, r); - if (r->req.aiocb == NULL) { - BADF("execute_command: read failed !\n"); - return -ENOMEM; - } return 0; } @@ -413,6 +409,10 @@ static int scsi_generic_initfn(SCSIDevice *s) /* define device state */ s->type = scsiid.scsi_type; DPRINTF("device type %d\n", s->type); + if (s->type == TYPE_DISK || s->type == TYPE_ROM) { + add_boot_device_path(s->conf.bootindex, &s->qdev, NULL); + } + switch (s->type) { case TYPE_TAPE: s->blocksize = get_stream_blocksize(s->conf.bs); @@ -459,6 +459,7 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun, static SCSIDeviceInfo scsi_generic_info = { .qdev.name = "scsi-generic", + .qdev.fw_name = "disk", .qdev.desc = "pass through generic scsi device (/dev/sg*)", .qdev.size = sizeof(SCSIDevice), .qdev.reset = scsi_generic_reset, @@ -128,7 +128,7 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) } SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, - int unit, bool removable); + int unit, bool removable, int bootindex); int scsi_bus_legacy_handle_cmdline(SCSIBus *bus); /* diff --git a/hw/sh7750_regs.h b/hw/sh7750_regs.h index 6ec13ab6fe..534aa48403 100644 --- a/hw/sh7750_regs.h +++ b/hw/sh7750_regs.h @@ -157,7 +157,7 @@ * Exeption-related registers */ -/* Immediate data for TRAPA instuction - TRA */ +/* Immediate data for TRAPA instruction - TRA */ #define SH7750_TRA_REGOFS 0x000020 /* offset */ #define SH7750_TRA SH7750_P4_REG32(SH7750_TRA_REGOFS) #define SH7750_TRA_A7 SH7750_A7_REG32(SH7750_TRA_REGOFS) diff --git a/hw/smc91c111.c b/hw/smc91c111.c index 9a3eddf25d..82b8811459 100644 --- a/hw/smc91c111.c +++ b/hw/smc91c111.c @@ -429,7 +429,7 @@ static void smc91c111_writeb(void *opaque, target_phys_addr_t offset, smc91c111_update(s); return; } - break;; + break; case 3: switch (offset) { diff --git a/hw/spapr.h b/hw/spapr.h index df88f6abad..d624841362 100644 --- a/hw/spapr.h +++ b/hw/spapr.h @@ -141,7 +141,7 @@ typedef struct sPAPREnvironment { #define H_DABRX_KERNEL (1ULL<<(63-62)) #define H_DABRX_USER (1ULL<<(63-63)) -/* Each control block has to be on a 4K bondary */ +/* Each control block has to be on a 4K boundary */ #define H_CB_ALIGNMENT 4096 /* pSeries hypervisor opcodes */ diff --git a/hw/spapr_pci.c b/hw/spapr_pci.c index 7162588543..9b6a032cce 100644 --- a/hw/spapr_pci.c +++ b/hw/spapr_pci.c @@ -454,7 +454,7 @@ int spapr_populate_pci_devices(sPAPRPHBState *phb, reg[0].size = 0; n = 0; - for (i = 0; i < PCI_NUM_REGIONS; ++i) { + for (i = 0; i < ARRAY_SIZE(bars); ++i) { if (0 == dev->io_regions[i].size) { continue; } diff --git a/hw/ssd0303.c b/hw/ssd0303.c index 401fdf592a..bcad7bf922 100644 --- a/hw/ssd0303.c +++ b/hw/ssd0303.c @@ -123,7 +123,7 @@ static int ssd0303_send(i2c_slave *i2c, uint8_t data) case 0xa7: /* Inverse on. */ s->inverse = 1; break; - case 0xa8: /* Set multipled ratio (Ignored). */ + case 0xa8: /* Set multiplied ratio (Ignored). */ s->cmd_state = SSD0303_CMD_SKIP1; break; case 0xad: /* DC-DC power control. */ diff --git a/hw/stellaris.c b/hw/stellaris.c index ce62a98158..7a73074982 100644 --- a/hw/stellaris.c +++ b/hw/stellaris.c @@ -621,6 +621,7 @@ static void ssys_reset(void *opaque) s->rcgc[0] = 1; s->scgc[0] = 1; s->dcgc[0] = 1; + ssys_calculate_system_clock(s); } static int stellaris_sys_post_load(void *opaque, int version_id) diff --git a/hw/syborg.c b/hw/syborg.c deleted file mode 100644 index 248de54c4e..0000000000 --- a/hw/syborg.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Syborg (Symbian Virtual Platform) reference board - * - * Copyright (c) 2009 CodeSourcery - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "sysbus.h" -#include "boards.h" -#include "arm-misc.h" -#include "net.h" -#include "exec-memory.h" - -static struct arm_boot_info syborg_binfo; - -static void syborg_init(ram_addr_t ram_size, - const char *boot_device, - const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename, const char *cpu_model) -{ - CPUState *env; - MemoryRegion *sysmem = get_system_memory(); - MemoryRegion *ram = g_new(MemoryRegion, 1); - qemu_irq *cpu_pic; - qemu_irq pic[64]; - DeviceState *dev; - int i; - - if (!cpu_model) - cpu_model = "cortex-a8"; - env = cpu_init(cpu_model); - if (!env) { - fprintf(stderr, "Unable to find CPU definition\n"); - exit(1); - } - - /* RAM at address zero. */ - memory_region_init_ram(ram, NULL, "syborg.ram", ram_size); - memory_region_add_subregion(sysmem, 0, ram); - - cpu_pic = arm_pic_init_cpu(env); - dev = sysbus_create_simple("syborg,interrupt", 0xC0000000, - cpu_pic[ARM_PIC_CPU_IRQ]); - for (i = 0; i < 64; i++) { - pic[i] = qdev_get_gpio_in(dev, i); - } - - sysbus_create_simple("syborg,rtc", 0xC0001000, NULL); - - dev = qdev_create(NULL, "syborg,timer"); - qdev_prop_set_uint32(dev, "frequency", 1000000); - qdev_init_nofail(dev); - sysbus_mmio_map(sysbus_from_qdev(dev), 0, 0xC0002000); - sysbus_connect_irq(sysbus_from_qdev(dev), 0, pic[1]); - - sysbus_create_simple("syborg,keyboard", 0xC0003000, pic[2]); - sysbus_create_simple("syborg,pointer", 0xC0004000, pic[3]); - sysbus_create_simple("syborg,framebuffer", 0xC0005000, pic[4]); - sysbus_create_simple("syborg,serial", 0xC0006000, pic[5]); - sysbus_create_simple("syborg,serial", 0xC0007000, pic[6]); - sysbus_create_simple("syborg,serial", 0xC0008000, pic[7]); - sysbus_create_simple("syborg,serial", 0xC0009000, pic[8]); - - if (nd_table[0].vlan || nd_table[0].netdev) { - DeviceState *dev; - SysBusDevice *s; - - qemu_check_nic_model(&nd_table[0], "virtio"); - dev = qdev_create(NULL, "syborg,virtio-net"); - qdev_set_nic_properties(dev, &nd_table[0]); - qdev_init_nofail(dev); - s = sysbus_from_qdev(dev); - sysbus_mmio_map(s, 0, 0xc000c000); - sysbus_connect_irq(s, 0, pic[9]); - } - - syborg_binfo.ram_size = ram_size; - syborg_binfo.kernel_filename = kernel_filename; - syborg_binfo.kernel_cmdline = kernel_cmdline; - syborg_binfo.initrd_filename = initrd_filename; - syborg_binfo.board_id = 0; - arm_load_kernel(env, &syborg_binfo); -} - -static QEMUMachine syborg_machine = { - .name = "syborg", - .desc = "Syborg (Symbian Virtual Platform)", - .init = syborg_init, -}; - -static void syborg_machine_init(void) -{ - qemu_register_machine(&syborg_machine); -} - -machine_init(syborg_machine_init); diff --git a/hw/syborg.h b/hw/syborg.h deleted file mode 100644 index b82ce4a502..0000000000 --- a/hw/syborg.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _SYBORG_H -#define _SYBORG_H - -#define SYBORG_ID_PLATFORM 0xc51d1000 -#define SYBORG_ID_INT 0xc51d0000 -#define SYBORG_ID_SERIAL 0xc51d0001 -#define SYBORG_ID_KEYBOARD 0xc51d0002 -#define SYBORG_ID_TIMER 0xc51d0003 -#define SYBORG_ID_RTC 0xc51d0004 -#define SYBORG_ID_MOUSE 0xc51d0005 -#define SYBORG_ID_TOUCHSCREEN 0xc51d0006 -#define SYBORG_ID_FRAMEBUFFER 0xc51d0007 -#define SYBORG_ID_HOSTFS 0xc51d0008 -#define SYBORG_ID_SNAPSHOT 0xc51d0009 -#define SYBORG_ID_VIRTIO 0xc51d000a -#define SYBORG_ID_NAND 0xc51d000b - -#endif diff --git a/hw/syborg_fb.c b/hw/syborg_fb.c deleted file mode 100644 index b87d7e6d10..0000000000 --- a/hw/syborg_fb.c +++ /dev/null @@ -1,554 +0,0 @@ -/* - * Syborg Framebuffer - * - * Copyright (c) 2009 CodeSourcery - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "sysbus.h" -#include "console.h" -#include "syborg.h" -#include "framebuffer.h" - -//#define DEBUG_SYBORG_FB - -#ifdef DEBUG_SYBORG_FB -#define DPRINTF(fmt, ...) \ -do { printf("syborg_fb: " fmt , ## __VA_ARGS__); } while (0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_fb: error: " fmt , ## __VA_ARGS__); \ - exit(1);} while (0) -#else -#define DPRINTF(fmt, ...) do {} while(0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_fb: error: " fmt , ## __VA_ARGS__);} while (0) -#endif - -enum { - FB_ID = 0, - FB_BASE = 1, - FB_HEIGHT = 2, - FB_WIDTH = 3, - FB_ORIENTATION = 4, - FB_BLANK = 5, - FB_INT_MASK = 6, - FB_INTERRUPT_CAUSE = 7, - FB_BPP = 8, - FB_COLOR_ORDER = 9, - FB_BYTE_ORDER = 10, - FB_PIXEL_ORDER = 11, - FB_ROW_PITCH = 12, - FB_ENABLED = 13, - FB_PALETTE_START = 0x400 >> 2, - FB_PALETTE_END = FB_PALETTE_START+256-1, -}; - -#define FB_INT_VSYNC (1U << 0) -#define FB_INT_BASE_UPDATE_DONE (1U << 1) - -typedef struct { - SysBusDevice busdev; - MemoryRegion iomem; - DisplayState *ds; - /*QEMUConsole *console;*/ - uint32_t need_update : 1; - uint32_t need_int : 1; - uint32_t enabled : 1; - uint32_t int_status; - uint32_t int_enable; - qemu_irq irq; - - uint32_t base; - uint32_t pitch; - uint32_t rows; - uint32_t cols; - int blank; - int bpp; - int rgb; /* 0 = BGR, 1 = RGB */ - int endian; /* 0 = Little, 1 = Big */ - uint32_t raw_palette[256]; - uint32_t palette[256]; -} SyborgFBState; - -enum { - BPP_SRC_1, - BPP_SRC_2, - BPP_SRC_4, - BPP_SRC_8, - BPP_SRC_16, - BPP_SRC_32, - /* TODO: Implement these. */ - BPP_SRC_15 = -1, - BPP_SRC_24 = -2 -}; - -#include "pixel_ops.h" - -#define BITS 8 -#include "pl110_template.h" -#define BITS 15 -#include "pl110_template.h" -#define BITS 16 -#include "pl110_template.h" -#define BITS 24 -#include "pl110_template.h" -#define BITS 32 -#include "pl110_template.h" - -/* Update interrupts. */ -static void syborg_fb_update(SyborgFBState *s) -{ - if ((s->int_status & s->int_enable) != 0) { - DPRINTF("Raise IRQ\n"); - qemu_irq_raise(s->irq); - } else { - DPRINTF("Lower IRQ\n"); - qemu_irq_lower(s->irq); - } -} - -static int syborg_fb_enabled(const SyborgFBState *s) -{ - return s->enabled; -} - -static void syborg_fb_update_palette(SyborgFBState *s) -{ - int n, i; - uint32_t raw; - unsigned int r, g, b; - - switch (s->bpp) { - case BPP_SRC_1: n = 2; break; - case BPP_SRC_2: n = 4; break; - case BPP_SRC_4: n = 16; break; - case BPP_SRC_8: n = 256; break; - default: return; - } - - for (i = 0; i < n; i++) { - raw = s->raw_palette[i]; - r = (raw >> 16) & 0xff; - g = (raw >> 8) & 0xff; - b = raw & 0xff; - switch (ds_get_bits_per_pixel(s->ds)) { - case 8: - s->palette[i] = rgb_to_pixel8(r, g, b); - break; - case 15: - s->palette[i] = rgb_to_pixel15(r, g, b); - break; - case 16: - s->palette[i] = rgb_to_pixel16(r, g, b); - break; - case 24: - case 32: - s->palette[i] = rgb_to_pixel32(r, g, b); - break; - default: - abort(); - } - } - -} - -static void syborg_fb_update_display(void *opaque) -{ - SyborgFBState *s = (SyborgFBState *)opaque; - drawfn* fntable; - drawfn fn; - int dest_width; - int src_width; - int bpp_offset; - int first; - int last; - - if (!syborg_fb_enabled(s)) - return; - - switch (ds_get_bits_per_pixel(s->ds)) { - case 0: - return; - case 8: - fntable = pl110_draw_fn_8; - dest_width = 1; - break; - case 15: - fntable = pl110_draw_fn_15; - dest_width = 2; - break; - case 16: - fntable = pl110_draw_fn_16; - dest_width = 2; - break; - case 24: - fntable = pl110_draw_fn_24; - dest_width = 3; - break; - case 32: - fntable = pl110_draw_fn_32; - dest_width = 4; - break; - default: - fprintf(stderr, "syborg_fb: Bad color depth\n"); - exit(1); - } - - if (s->need_int) { - s->int_status |= FB_INT_BASE_UPDATE_DONE; - syborg_fb_update(s); - s->need_int = 0; - } - - if (s->rgb) { - bpp_offset = 24; - } else { - bpp_offset = 0; - } - if (s->endian) { - bpp_offset += 8; - } - /* Our bpp constants mostly match the PL110/PL111 but - * not for the 16 bit case - */ - switch (s->bpp) { - case BPP_SRC_16: - bpp_offset += 6; - break; - default: - bpp_offset += s->bpp; - } - fn = fntable[bpp_offset]; - - if (s->pitch) { - src_width = s->pitch; - } else { - src_width = s->cols; - switch (s->bpp) { - case BPP_SRC_1: - src_width >>= 3; - break; - case BPP_SRC_2: - src_width >>= 2; - break; - case BPP_SRC_4: - src_width >>= 1; - break; - case BPP_SRC_8: - break; - case BPP_SRC_15: - case BPP_SRC_16: - src_width <<= 1; - break; - case BPP_SRC_24: - src_width *= 3; - break; - case BPP_SRC_32: - src_width <<= 2; - break; - } - } - dest_width *= s->cols; - first = 0; - /* TODO: Implement blanking. */ - if (!s->blank) { - if (s->need_update && s->bpp <= BPP_SRC_8) { - syborg_fb_update_palette(s); - } - framebuffer_update_display(s->ds, - s->base, s->cols, s->rows, - src_width, dest_width, 0, - s->need_update, - fn, s->palette, - &first, &last); - if (first >= 0) { - dpy_update(s->ds, 0, first, s->cols, last - first + 1); - } - - s->int_status |= FB_INT_VSYNC; - syborg_fb_update(s); - } - - s->need_update = 0; -} - -static void syborg_fb_invalidate_display(void * opaque) -{ - SyborgFBState *s = (SyborgFBState *)opaque; - s->need_update = 1; -} - -static uint64_t syborg_fb_read(void *opaque, target_phys_addr_t offset, - unsigned size) -{ - SyborgFBState *s = opaque; - - DPRINTF("read reg %d\n", (int)offset); - offset &= 0xfff; - switch (offset >> 2) { - case FB_ID: - return SYBORG_ID_FRAMEBUFFER; - - case FB_BASE: - return s->base; - - case FB_HEIGHT: - return s->rows; - - case FB_WIDTH: - return s->cols; - - case FB_ORIENTATION: - return 0; - - case FB_BLANK: - return s->blank; - - case FB_INT_MASK: - return s->int_enable; - - case FB_INTERRUPT_CAUSE: - return s->int_status; - - case FB_BPP: - switch (s->bpp) { - case BPP_SRC_1: return 1; - case BPP_SRC_2: return 2; - case BPP_SRC_4: return 4; - case BPP_SRC_8: return 8; - case BPP_SRC_15: return 15; - case BPP_SRC_16: return 16; - case BPP_SRC_24: return 24; - case BPP_SRC_32: return 32; - default: return 0; - } - - case FB_COLOR_ORDER: - return s->rgb; - - case FB_BYTE_ORDER: - return s->endian; - - case FB_PIXEL_ORDER: - return 0; - - case FB_ROW_PITCH: - return s->pitch; - - case FB_ENABLED: - return s->enabled; - - default: - if ((offset >> 2) >= FB_PALETTE_START - && (offset >> 2) <= FB_PALETTE_END) { - return s->raw_palette[(offset >> 2) - FB_PALETTE_START]; - } else { - cpu_abort (cpu_single_env, "syborg_fb_read: Bad offset %x\n", - (int)offset); - } - return 0; - } -} - -static void syborg_fb_write(void *opaque, target_phys_addr_t offset, - uint64_t val, unsigned size) -{ - SyborgFBState *s = opaque; - - DPRINTF("write reg %d = %d\n", (int)offset, val); - s->need_update = 1; - offset &= 0xfff; - switch (offset >> 2) { - case FB_BASE: - s->base = val; - s->need_int = 1; - s->need_update = 1; - syborg_fb_update(s); - break; - - case FB_HEIGHT: - s->rows = val; - break; - - case FB_WIDTH: - s->cols = val; - break; - - case FB_ORIENTATION: - /* TODO: Implement rotation. */ - break; - - case FB_BLANK: - s->blank = val & 1; - break; - - case FB_INT_MASK: - s->int_enable = val; - syborg_fb_update(s); - break; - - case FB_INTERRUPT_CAUSE: - s->int_status &= ~val; - syborg_fb_update(s); - break; - - case FB_BPP: - switch (val) { - case 1: val = BPP_SRC_1; break; - case 2: val = BPP_SRC_2; break; - case 4: val = BPP_SRC_4; break; - case 8: val = BPP_SRC_8; break; - /* case 15: val = BPP_SRC_15; break; */ - case 16: val = BPP_SRC_16; break; - /* case 24: val = BPP_SRC_24; break; */ - case 32: val = BPP_SRC_32; break; - default: val = s->bpp; break; - } - s->bpp = val; - break; - - case FB_COLOR_ORDER: - s->rgb = (val != 0); - break; - - case FB_BYTE_ORDER: - s->endian = (val != 0); - break; - - case FB_PIXEL_ORDER: - /* TODO: Implement this. */ - break; - - case FB_ROW_PITCH: - s->pitch = val; - break; - - case FB_ENABLED: - s->enabled = val; - break; - - default: - if ((offset >> 2) >= FB_PALETTE_START - && (offset >> 2) <= FB_PALETTE_END) { - s->raw_palette[(offset >> 2) - FB_PALETTE_START] = val; - } else { - cpu_abort (cpu_single_env, "syborg_fb_write: Bad offset %x\n", - (int)offset); - } - break; - } -} - -static const MemoryRegionOps syborg_fb_ops = { - .read = syborg_fb_read, - .write = syborg_fb_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static void syborg_fb_save(QEMUFile *f, void *opaque) -{ - SyborgFBState *s = opaque; - int i; - - qemu_put_be32(f, s->need_int); - qemu_put_be32(f, s->int_status); - qemu_put_be32(f, s->int_enable); - qemu_put_be32(f, s->enabled); - qemu_put_be32(f, s->base); - qemu_put_be32(f, s->pitch); - qemu_put_be32(f, s->rows); - qemu_put_be32(f, s->cols); - qemu_put_be32(f, s->bpp); - qemu_put_be32(f, s->rgb); - for (i = 0; i < 256; i++) { - qemu_put_be32(f, s->raw_palette[i]); - } -} - -static int syborg_fb_load(QEMUFile *f, void *opaque, int version_id) -{ - SyborgFBState *s = opaque; - int i; - - if (version_id != 1) - return -EINVAL; - - s->need_int = qemu_get_be32(f); - s->int_status = qemu_get_be32(f); - s->int_enable = qemu_get_be32(f); - s->enabled = qemu_get_be32(f); - s->base = qemu_get_be32(f); - s->pitch = qemu_get_be32(f); - s->rows = qemu_get_be32(f); - s->cols = qemu_get_be32(f); - s->bpp = qemu_get_be32(f); - s->rgb = qemu_get_be32(f); - for (i = 0; i < 256; i++) { - s->raw_palette[i] = qemu_get_be32(f); - } - s->need_update = 1; - - return 0; -} - -static int syborg_fb_init(SysBusDevice *dev) -{ - SyborgFBState *s = FROM_SYSBUS(SyborgFBState, dev); - - sysbus_init_irq(dev, &s->irq); - memory_region_init_io(&s->iomem, &syborg_fb_ops, s, - "framebuffer", 0x1000); - sysbus_init_mmio(dev, &s->iomem); - - s->ds = graphic_console_init(syborg_fb_update_display, - syborg_fb_invalidate_display, - NULL, NULL, s); - - if (s->cols != 0 && s->rows != 0) { - qemu_console_resize(s->ds, s->cols, s->rows); - } - - if (!s->cols) - s->cols = ds_get_width(s->ds); - if (!s->rows) - s->rows = ds_get_height(s->ds); - - register_savevm(&dev->qdev, "syborg_framebuffer", -1, 1, - syborg_fb_save, syborg_fb_load, s); - return 0; -} - -static SysBusDeviceInfo syborg_fb_info = { - .init = syborg_fb_init, - .qdev.name = "syborg,framebuffer", - .qdev.size = sizeof(SyborgFBState), - .qdev.props = (Property[]) { - DEFINE_PROP_UINT32("width", SyborgFBState, cols, 0), - DEFINE_PROP_UINT32("height", SyborgFBState, rows, 0), - DEFINE_PROP_END_OF_LIST(), - } -}; - -static void syborg_fb_register_devices(void) -{ - sysbus_register_withprop(&syborg_fb_info); -} - -device_init(syborg_fb_register_devices) diff --git a/hw/syborg_interrupt.c b/hw/syborg_interrupt.c deleted file mode 100644 index 93e81c8660..0000000000 --- a/hw/syborg_interrupt.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Syborg interrupt controller. - * - * Copyright (c) 2008 CodeSourcery - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "sysbus.h" -#include "syborg.h" - -//#define DEBUG_SYBORG_INT - -#ifdef DEBUG_SYBORG_INT -#define DPRINTF(fmt, ...) \ -do { printf("syborg_int: " fmt , ## __VA_ARGS__); } while (0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_int: error: " fmt , ## __VA_ARGS__); \ - exit(1);} while (0) -#else -#define DPRINTF(fmt, ...) do {} while(0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_int: error: " fmt , ## __VA_ARGS__);} while (0) -#endif -enum { - INT_ID = 0, - INT_STATUS = 1, /* number of pending interrupts */ - INT_CURRENT = 2, /* next interrupt to be serviced */ - INT_DISABLE_ALL = 3, - INT_DISABLE = 4, - INT_ENABLE = 5, - INT_TOTAL = 6 -}; - -typedef struct { - unsigned level:1; - unsigned enabled:1; -} syborg_int_flags; - -typedef struct { - SysBusDevice busdev; - MemoryRegion iomem; - int pending_count; - uint32_t num_irqs; - syborg_int_flags *flags; - qemu_irq parent_irq; -} SyborgIntState; - -static void syborg_int_update(SyborgIntState *s) -{ - DPRINTF("pending %d\n", s->pending_count); - qemu_set_irq(s->parent_irq, s->pending_count > 0); -} - -static void syborg_int_set_irq(void *opaque, int irq, int level) -{ - SyborgIntState *s = (SyborgIntState *)opaque; - - if (s->flags[irq].level == level) - return; - - s->flags[irq].level = level; - if (s->flags[irq].enabled) { - if (level) - s->pending_count++; - else - s->pending_count--; - syborg_int_update(s); - } -} - -static uint64_t syborg_int_read(void *opaque, target_phys_addr_t offset, - unsigned size) -{ - SyborgIntState *s = (SyborgIntState *)opaque; - int i; - - offset &= 0xfff; - switch (offset >> 2) { - case INT_ID: - return SYBORG_ID_INT; - case INT_STATUS: - DPRINTF("read status=%d\n", s->pending_count); - return s->pending_count; - - case INT_CURRENT: - for (i = 0; i < s->num_irqs; i++) { - if (s->flags[i].level & s->flags[i].enabled) { - DPRINTF("read current=%d\n", i); - return i; - } - } - DPRINTF("read current=none\n"); - return 0xffffffffu; - - default: - cpu_abort(cpu_single_env, "syborg_int_read: Bad offset %x\n", - (int)offset); - return 0; - } -} - -static void syborg_int_write(void *opaque, target_phys_addr_t offset, - uint64_t value, unsigned size) -{ - SyborgIntState *s = (SyborgIntState *)opaque; - int i; - offset &= 0xfff; - - DPRINTF("syborg_int_write offset=%d val=%d\n", (int)offset, (int)value); - switch (offset >> 2) { - case INT_DISABLE_ALL: - s->pending_count = 0; - for (i = 0; i < s->num_irqs; i++) - s->flags[i].enabled = 0; - break; - - case INT_DISABLE: - if (value >= s->num_irqs) - break; - if (s->flags[value].enabled) { - if (s->flags[value].enabled) - s->pending_count--; - s->flags[value].enabled = 0; - } - break; - - case INT_ENABLE: - if (value >= s->num_irqs) - break; - if (!(s->flags[value].enabled)) { - if(s->flags[value].level) - s->pending_count++; - s->flags[value].enabled = 1; - } - break; - - default: - cpu_abort(cpu_single_env, "syborg_int_write: Bad offset %x\n", - (int)offset); - return; - } - syborg_int_update(s); -} - -static const MemoryRegionOps syborg_int_ops = { - .read = syborg_int_read, - .write = syborg_int_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static void syborg_int_save(QEMUFile *f, void *opaque) -{ - SyborgIntState *s = (SyborgIntState *)opaque; - int i; - - qemu_put_be32(f, s->num_irqs); - qemu_put_be32(f, s->pending_count); - for (i = 0; i < s->num_irqs; i++) { - qemu_put_be32(f, s->flags[i].enabled - | ((unsigned)s->flags[i].level << 1)); - } -} - -static int syborg_int_load(QEMUFile *f, void *opaque, int version_id) -{ - SyborgIntState *s = (SyborgIntState *)opaque; - uint32_t val; - int i; - - if (version_id != 1) - return -EINVAL; - - val = qemu_get_be32(f); - if (val != s->num_irqs) - return -EINVAL; - s->pending_count = qemu_get_be32(f); - for (i = 0; i < s->num_irqs; i++) { - val = qemu_get_be32(f); - s->flags[i].enabled = val & 1; - s->flags[i].level = (val >> 1) & 1; - } - return 0; -} - -static int syborg_int_init(SysBusDevice *dev) -{ - SyborgIntState *s = FROM_SYSBUS(SyborgIntState, dev); - - sysbus_init_irq(dev, &s->parent_irq); - qdev_init_gpio_in(&dev->qdev, syborg_int_set_irq, s->num_irqs); - memory_region_init_io(&s->iomem, &syborg_int_ops, s, - "interrupt", 0x1000); - sysbus_init_mmio(dev, &s->iomem); - s->flags = g_malloc0(s->num_irqs * sizeof(syborg_int_flags)); - - register_savevm(&dev->qdev, "syborg_int", -1, 1, syborg_int_save, - syborg_int_load, s); - return 0; -} - -static SysBusDeviceInfo syborg_int_info = { - .init = syborg_int_init, - .qdev.name = "syborg,interrupt", - .qdev.size = sizeof(SyborgIntState), - .qdev.props = (Property[]) { - DEFINE_PROP_UINT32("num-interrupts", SyborgIntState, num_irqs, 64), - DEFINE_PROP_END_OF_LIST(), - } -}; - -static void syborg_interrupt_register_devices(void) -{ - sysbus_register_withprop(&syborg_int_info); -} - -device_init(syborg_interrupt_register_devices) diff --git a/hw/syborg_keyboard.c b/hw/syborg_keyboard.c deleted file mode 100644 index 942a7dc800..0000000000 --- a/hw/syborg_keyboard.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Syborg keyboard controller. - * - * Copyright (c) 2008 CodeSourcery - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "sysbus.h" -#include "console.h" -#include "syborg.h" - -//#define DEBUG_SYBORG_KEYBOARD - -#ifdef DEBUG_SYBORG_KEYBOARD -#define DPRINTF(fmt, ...) \ -do { printf("syborg_keyboard: " fmt , ##args); } while (0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_keyboard: error: " fmt , ## __VA_ARGS__); \ - exit(1);} while (0) -#else -#define DPRINTF(fmt, ...) do {} while(0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_keyboard: error: " fmt , ## __VA_ARGS__); \ -} while (0) -#endif - -enum { - KBD_ID = 0, - KBD_DATA = 1, - KBD_FIFO_COUNT = 2, - KBD_INT_ENABLE = 3, - KBD_FIFO_SIZE = 4 -}; - -typedef struct { - SysBusDevice busdev; - MemoryRegion iomem; - uint32_t int_enabled; - int extension_bit; - uint32_t fifo_size; - uint32_t *key_fifo; - uint32_t read_pos, read_count; - qemu_irq irq; -} SyborgKeyboardState; - -static void syborg_keyboard_update(SyborgKeyboardState *s) -{ - int level = s->read_count && s->int_enabled; - DPRINTF("Update IRQ %d\n", level); - qemu_set_irq(s->irq, level); -} - -static uint64_t syborg_keyboard_read(void *opaque, target_phys_addr_t offset, - unsigned size) -{ - SyborgKeyboardState *s = (SyborgKeyboardState *)opaque; - int c; - - DPRINTF("reg read %d\n", (int)offset); - offset &= 0xfff; - switch (offset >> 2) { - case KBD_ID: - return SYBORG_ID_KEYBOARD; - case KBD_FIFO_COUNT: - return s->read_count; - case KBD_DATA: - if (s->read_count == 0) { - c = -1; - DPRINTF("FIFO underflow\n"); - } else { - c = s->key_fifo[s->read_pos]; - DPRINTF("FIFO read 0x%x\n", c); - s->read_count--; - s->read_pos++; - if (s->read_pos == s->fifo_size) - s->read_pos = 0; - } - syborg_keyboard_update(s); - return c; - case KBD_INT_ENABLE: - return s->int_enabled; - case KBD_FIFO_SIZE: - return s->fifo_size; - default: - cpu_abort(cpu_single_env, "syborg_keyboard_read: Bad offset %x\n", - (int)offset); - return 0; - } -} - -static void syborg_keyboard_write(void *opaque, target_phys_addr_t offset, - uint64_t value, unsigned size) -{ - SyborgKeyboardState *s = (SyborgKeyboardState *)opaque; - - DPRINTF("reg write %d\n", (int)offset); - offset &= 0xfff; - switch (offset >> 2) { - case KBD_INT_ENABLE: - s->int_enabled = value; - syborg_keyboard_update(s); - break; - default: - cpu_abort(cpu_single_env, "syborg_keyboard_write: Bad offset %x\n", - (int)offset); - } -} - -static const MemoryRegionOps syborg_keyboard_ops = { - .read = syborg_keyboard_read, - .write = syborg_keyboard_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static void syborg_keyboard_event(void *opaque, int keycode) -{ - SyborgKeyboardState *s = (SyborgKeyboardState *)opaque; - int slot; - uint32_t val; - - /* Strip off 0xe0 prefixes and reconstruct the full scancode. */ - if (keycode == 0xe0 && !s->extension_bit) { - DPRINTF("Extension bit\n"); - s->extension_bit = 0x80; - return; - } - val = (keycode & 0x7f) | s->extension_bit; - if (keycode & 0x80) - val |= 0x80000000u; - s->extension_bit = 0; - - DPRINTF("FIFO push 0x%x\n", val); - slot = s->read_pos + s->read_count; - if (slot >= s->fifo_size) - slot -= s->fifo_size; - - if (s->read_count < s->fifo_size) { - s->read_count++; - s->key_fifo[slot] = val; - } else { - fprintf(stderr, "syborg_keyboard error! FIFO overflow\n"); - } - - syborg_keyboard_update(s); -} - -static const VMStateDescription vmstate_syborg_keyboard = { - .name = "syborg_keyboard", - .version_id = 1, - .minimum_version_id = 1, - .minimum_version_id_old = 1, - .fields = (VMStateField[]) { - VMSTATE_UINT32_EQUAL(fifo_size, SyborgKeyboardState), - VMSTATE_UINT32(int_enabled, SyborgKeyboardState), - VMSTATE_UINT32(read_pos, SyborgKeyboardState), - VMSTATE_UINT32(read_count, SyborgKeyboardState), - VMSTATE_VARRAY_UINT32(key_fifo, SyborgKeyboardState, fifo_size, 1, - vmstate_info_uint32, uint32), - VMSTATE_END_OF_LIST() - } -}; - -static int syborg_keyboard_init(SysBusDevice *dev) -{ - SyborgKeyboardState *s = FROM_SYSBUS(SyborgKeyboardState, dev); - - sysbus_init_irq(dev, &s->irq); - memory_region_init_io(&s->iomem, &syborg_keyboard_ops, s, - "keyboard", 0x1000); - sysbus_init_mmio(dev, &s->iomem); - if (s->fifo_size <= 0) { - fprintf(stderr, "syborg_keyboard: fifo too small\n"); - s->fifo_size = 16; - } - s->key_fifo = g_malloc0(s->fifo_size * sizeof(s->key_fifo[0])); - - qemu_add_kbd_event_handler(syborg_keyboard_event, s); - - vmstate_register(&dev->qdev, -1, &vmstate_syborg_keyboard, s); - return 0; -} - -static SysBusDeviceInfo syborg_keyboard_info = { - .init = syborg_keyboard_init, - .qdev.name = "syborg,keyboard", - .qdev.size = sizeof(SyborgKeyboardState), - .qdev.props = (Property[]) { - DEFINE_PROP_UINT32("fifo-size", SyborgKeyboardState, fifo_size, 16), - DEFINE_PROP_END_OF_LIST(), - } -}; - -static void syborg_keyboard_register_devices(void) -{ - sysbus_register_withprop(&syborg_keyboard_info); -} - -device_init(syborg_keyboard_register_devices) diff --git a/hw/syborg_pointer.c b/hw/syborg_pointer.c deleted file mode 100644 index bb75fa42c8..0000000000 --- a/hw/syborg_pointer.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Syborg pointing device (mouse/touchscreen) - * - * Copyright (c) 2008 CodeSourcery - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "sysbus.h" -#include "console.h" -#include "syborg.h" - -enum { - POINTER_ID = 0, - POINTER_LATCH = 1, - POINTER_FIFO_COUNT = 2, - POINTER_X = 3, - POINTER_Y = 4, - POINTER_Z = 5, - POINTER_BUTTONS = 6, - POINTER_INT_ENABLE = 7, - POINTER_FIFO_SIZE = 8 -}; - -typedef struct { - int x, y, z, pointer_buttons; -} event_data; - -typedef struct { - SysBusDevice busdev; - MemoryRegion iomem; - int int_enabled; - uint32_t fifo_size; - event_data *event_fifo; - int read_pos, read_count; - qemu_irq irq; - uint32_t absolute; -} SyborgPointerState; - -static void syborg_pointer_update(SyborgPointerState *s) -{ - qemu_set_irq(s->irq, s->read_count && s->int_enabled); -} - -static uint64_t syborg_pointer_read(void *opaque, target_phys_addr_t offset, - unsigned size) -{ - SyborgPointerState *s = (SyborgPointerState *)opaque; - - offset &= 0xfff; - switch (offset >> 2) { - case POINTER_ID: - return s->absolute ? SYBORG_ID_TOUCHSCREEN : SYBORG_ID_MOUSE; - case POINTER_FIFO_COUNT: - return s->read_count; - case POINTER_X: - return s->event_fifo[s->read_pos].x; - case POINTER_Y: - return s->event_fifo[s->read_pos].y; - case POINTER_Z: - return s->event_fifo[s->read_pos].z; - case POINTER_BUTTONS: - return s->event_fifo[s->read_pos].pointer_buttons; - case POINTER_INT_ENABLE: - return s->int_enabled; - case POINTER_FIFO_SIZE: - return s->fifo_size; - default: - cpu_abort(cpu_single_env, "syborg_pointer_read: Bad offset %x\n", - (int)offset); - return 0; - } -} - -static void syborg_pointer_write(void *opaque, target_phys_addr_t offset, - uint64_t value, unsigned size) -{ - SyborgPointerState *s = (SyborgPointerState *)opaque; - - offset &= 0xfff; - switch (offset >> 2) { - case POINTER_LATCH: - if (s->read_count > 0) { - s->read_count--; - if (++s->read_pos == s->fifo_size) - s->read_pos = 0; - } - break; - case POINTER_INT_ENABLE: - s->int_enabled = value; - break; - default: - cpu_abort(cpu_single_env, "syborg_pointer_write: Bad offset %x\n", - (int)offset); - } - syborg_pointer_update(s); -} - -static const MemoryRegionOps syborg_pointer_ops = { - .read = syborg_pointer_read, - .write = syborg_pointer_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static void syborg_pointer_event(void *opaque, int dx, int dy, int dz, - int buttons_state) -{ - SyborgPointerState *s = (SyborgPointerState *)opaque; - int slot = s->read_pos + s->read_count; - - /* This first FIFO entry is used to store current register state. */ - if (s->read_count < s->fifo_size - 1) { - s->read_count++; - slot++; - } - - if (slot >= s->fifo_size) - slot -= s->fifo_size; - - if (s->read_count == s->fifo_size && !s->absolute) { - /* Merge existing entries. */ - s->event_fifo[slot].x += dx; - s->event_fifo[slot].y += dy; - s->event_fifo[slot].z += dz; - } else { - s->event_fifo[slot].x = dx; - s->event_fifo[slot].y = dy; - s->event_fifo[slot].z = dz; - } - s->event_fifo[slot].pointer_buttons = buttons_state; - - syborg_pointer_update(s); -} - -static const VMStateDescription vmstate_event_data = { - .name = "dbma_channel", - .version_id = 0, - .minimum_version_id = 0, - .minimum_version_id_old = 0, - .fields = (VMStateField[]) { - VMSTATE_INT32(x, event_data), - VMSTATE_INT32(y, event_data), - VMSTATE_INT32(z, event_data), - VMSTATE_INT32(pointer_buttons, event_data), - VMSTATE_END_OF_LIST() - } -}; - -static const VMStateDescription vmstate_syborg_pointer = { - .name = "syborg_pointer", - .version_id = 1, - .minimum_version_id = 1, - .minimum_version_id_old = 1, - .fields = (VMStateField[]) { - VMSTATE_UINT32_EQUAL(fifo_size, SyborgPointerState), - VMSTATE_UINT32_EQUAL(absolute, SyborgPointerState), - VMSTATE_INT32(int_enabled, SyborgPointerState), - VMSTATE_INT32(read_pos, SyborgPointerState), - VMSTATE_INT32(read_count, SyborgPointerState), - VMSTATE_STRUCT_VARRAY_UINT32(event_fifo, SyborgPointerState, fifo_size, - 1, vmstate_event_data, event_data), - VMSTATE_END_OF_LIST() - } -}; - -static int syborg_pointer_init(SysBusDevice *dev) -{ - SyborgPointerState *s = FROM_SYSBUS(SyborgPointerState, dev); - - sysbus_init_irq(dev, &s->irq); - memory_region_init_io(&s->iomem, &syborg_pointer_ops, s, - "pointer", 0x1000); - sysbus_init_mmio(dev, &s->iomem); - - if (s->fifo_size <= 0) { - fprintf(stderr, "syborg_pointer: fifo too small\n"); - s->fifo_size = 16; - } - s->event_fifo = g_malloc0(s->fifo_size * sizeof(s->event_fifo[0])); - - qemu_add_mouse_event_handler(syborg_pointer_event, s, s->absolute, - "Syborg Pointer"); - - vmstate_register(&dev->qdev, -1, &vmstate_syborg_pointer, s); - return 0; -} - -static SysBusDeviceInfo syborg_pointer_info = { - .init = syborg_pointer_init, - .qdev.name = "syborg,pointer", - .qdev.size = sizeof(SyborgPointerState), - .qdev.props = (Property[]) { - DEFINE_PROP_UINT32("fifo-size", SyborgPointerState, fifo_size, 16), - DEFINE_PROP_UINT32("absolute", SyborgPointerState, absolute, 1), - DEFINE_PROP_END_OF_LIST(), - } -}; - -static void syborg_pointer_register_devices(void) -{ - sysbus_register_withprop(&syborg_pointer_info); -} - -device_init(syborg_pointer_register_devices) diff --git a/hw/syborg_rtc.c b/hw/syborg_rtc.c deleted file mode 100644 index b5f34798b6..0000000000 --- a/hw/syborg_rtc.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Syborg RTC - * - * Copyright (c) 2008 CodeSourcery - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "sysbus.h" -#include "qemu-timer.h" -#include "syborg.h" - -enum { - RTC_ID = 0, - RTC_LATCH = 1, - RTC_DATA_LOW = 2, - RTC_DATA_HIGH = 3 -}; - -typedef struct { - SysBusDevice busdev; - MemoryRegion iomem; - int64_t offset; - int64_t data; - qemu_irq irq; -} SyborgRTCState; - -static uint64_t syborg_rtc_read(void *opaque, target_phys_addr_t offset, - unsigned size) -{ - SyborgRTCState *s = (SyborgRTCState *)opaque; - offset &= 0xfff; - switch (offset >> 2) { - case RTC_ID: - return SYBORG_ID_RTC; - case RTC_DATA_LOW: - return (uint32_t)s->data; - case RTC_DATA_HIGH: - return (uint32_t)(s->data >> 32); - default: - cpu_abort(cpu_single_env, "syborg_rtc_read: Bad offset %x\n", - (int)offset); - return 0; - } -} - -static void syborg_rtc_write(void *opaque, target_phys_addr_t offset, - uint64_t value, unsigned size) -{ - SyborgRTCState *s = (SyborgRTCState *)opaque; - uint64_t now; - - offset &= 0xfff; - switch (offset >> 2) { - case RTC_LATCH: - now = qemu_get_clock_ns(vm_clock); - if (value >= 4) { - s->offset = s->data - now; - } else { - s->data = now + s->offset; - while (value) { - s->data /= 1000; - value--; - } - } - break; - case RTC_DATA_LOW: - s->data = (s->data & ~(uint64_t)0xffffffffu) | value; - break; - case RTC_DATA_HIGH: - s->data = (s->data & 0xffffffffu) | ((uint64_t)value << 32); - break; - default: - cpu_abort(cpu_single_env, "syborg_rtc_write: Bad offset %x\n", - (int)offset); - break; - } -} - -static const MemoryRegionOps syborg_rtc_ops = { - .read = syborg_rtc_read, - .write = syborg_rtc_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static const VMStateDescription vmstate_syborg_rtc = { - .name = "syborg_keyboard", - .version_id = 1, - .minimum_version_id = 1, - .minimum_version_id_old = 1, - .fields = (VMStateField[]) { - VMSTATE_INT64(offset, SyborgRTCState), - VMSTATE_INT64(data, SyborgRTCState), - VMSTATE_END_OF_LIST() - } -}; - -static int syborg_rtc_init(SysBusDevice *dev) -{ - SyborgRTCState *s = FROM_SYSBUS(SyborgRTCState, dev); - struct tm tm; - - memory_region_init_io(&s->iomem, &syborg_rtc_ops, s, "rtc", 0x1000); - sysbus_init_mmio(dev, &s->iomem); - - qemu_get_timedate(&tm, 0); - s->offset = (uint64_t)mktime(&tm) * 1000000000; - - vmstate_register(&dev->qdev, -1, &vmstate_syborg_rtc, s); - return 0; -} - -static void syborg_rtc_register_devices(void) -{ - sysbus_register_dev("syborg,rtc", sizeof(SyborgRTCState), syborg_rtc_init); -} - -device_init(syborg_rtc_register_devices) diff --git a/hw/syborg_serial.c b/hw/syborg_serial.c deleted file mode 100644 index 6f339fa7a6..0000000000 --- a/hw/syborg_serial.c +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Syborg serial port - * - * Copyright (c) 2008 CodeSourcery - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "sysbus.h" -#include "qemu-char.h" -#include "syborg.h" - -//#define DEBUG_SYBORG_SERIAL - -#ifdef DEBUG_SYBORG_SERIAL -#define DPRINTF(fmt, ...) \ -do { printf("syborg_serial: " fmt , ##args); } while (0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_serial: error: " fmt , ## __VA_ARGS__); \ - exit(1);} while (0) -#else -#define DPRINTF(fmt, ...) do {} while(0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_serial: error: " fmt , ## __VA_ARGS__);} while (0) -#endif - -enum { - SERIAL_ID = 0, - SERIAL_DATA = 1, - SERIAL_FIFO_COUNT = 2, - SERIAL_INT_ENABLE = 3, - SERIAL_DMA_TX_ADDR = 4, - SERIAL_DMA_TX_COUNT = 5, /* triggers dma */ - SERIAL_DMA_RX_ADDR = 6, - SERIAL_DMA_RX_COUNT = 7, /* triggers dma */ - SERIAL_FIFO_SIZE = 8 -}; - -#define SERIAL_INT_FIFO (1u << 0) -#define SERIAL_INT_DMA_TX (1u << 1) -#define SERIAL_INT_DMA_RX (1u << 2) - -typedef struct { - SysBusDevice busdev; - MemoryRegion iomem; - uint32_t int_enable; - uint32_t fifo_size; - uint32_t *read_fifo; - int read_pos; - int read_count; - CharDriverState *chr; - qemu_irq irq; - uint32_t dma_tx_ptr; - uint32_t dma_rx_ptr; - uint32_t dma_rx_size; -} SyborgSerialState; - -static void syborg_serial_update(SyborgSerialState *s) -{ - int level; - level = 0; - if ((s->int_enable & SERIAL_INT_FIFO) && s->read_count) - level = 1; - if (s->int_enable & SERIAL_INT_DMA_TX) - level = 1; - if ((s->int_enable & SERIAL_INT_DMA_RX) && s->dma_rx_size == 0) - level = 1; - - qemu_set_irq(s->irq, level); -} - -static uint32_t fifo_pop(SyborgSerialState *s) -{ - const uint32_t c = s->read_fifo[s->read_pos]; - s->read_count--; - s->read_pos++; - if (s->read_pos == s->fifo_size) - s->read_pos = 0; - - DPRINTF("FIFO pop %x (%d)\n", c, s->read_count); - return c; -} - -static void fifo_push(SyborgSerialState *s, uint32_t new_value) -{ - int slot; - - DPRINTF("FIFO push %x (%d)\n", new_value, s->read_count); - slot = s->read_pos + s->read_count; - if (slot >= s->fifo_size) - slot -= s->fifo_size; - s->read_fifo[slot] = new_value; - s->read_count++; -} - -static void do_dma_tx(SyborgSerialState *s, uint32_t count) -{ - unsigned char ch; - - if (count == 0) - return; - - if (s->chr != NULL) { - /* optimize later. Now, 1 byte per iteration */ - while (count--) { - cpu_physical_memory_read(s->dma_tx_ptr, &ch, 1); - qemu_chr_fe_write(s->chr, &ch, 1); - s->dma_tx_ptr++; - } - } else { - s->dma_tx_ptr += count; - } - /* QEMU char backends do not have a nonblocking mode, so we transmit all - the data immediately and the interrupt status will be unchanged. */ -} - -/* Initiate RX DMA, and transfer data from the FIFO. */ -static void dma_rx_start(SyborgSerialState *s, uint32_t len) -{ - uint32_t dest; - unsigned char ch; - - dest = s->dma_rx_ptr; - if (s->read_count < len) { - s->dma_rx_size = len - s->read_count; - len = s->read_count; - } else { - s->dma_rx_size = 0; - } - - while (len--) { - ch = fifo_pop(s); - cpu_physical_memory_write(dest, &ch, 1); - dest++; - } - s->dma_rx_ptr = dest; - syborg_serial_update(s); -} - -static uint64_t syborg_serial_read(void *opaque, target_phys_addr_t offset, - unsigned size) -{ - SyborgSerialState *s = (SyborgSerialState *)opaque; - uint32_t c; - - offset &= 0xfff; - DPRINTF("read 0x%x\n", (int)offset); - switch(offset >> 2) { - case SERIAL_ID: - return SYBORG_ID_SERIAL; - case SERIAL_DATA: - if (s->read_count > 0) - c = fifo_pop(s); - else - c = -1; - syborg_serial_update(s); - return c; - case SERIAL_FIFO_COUNT: - return s->read_count; - case SERIAL_INT_ENABLE: - return s->int_enable; - case SERIAL_DMA_TX_ADDR: - return s->dma_tx_ptr; - case SERIAL_DMA_TX_COUNT: - return 0; - case SERIAL_DMA_RX_ADDR: - return s->dma_rx_ptr; - case SERIAL_DMA_RX_COUNT: - return s->dma_rx_size; - case SERIAL_FIFO_SIZE: - return s->fifo_size; - - default: - cpu_abort(cpu_single_env, "syborg_serial_read: Bad offset %x\n", - (int)offset); - return 0; - } -} - -static void syborg_serial_write(void *opaque, target_phys_addr_t offset, - uint64_t value, unsigned size) -{ - SyborgSerialState *s = (SyborgSerialState *)opaque; - unsigned char ch; - - offset &= 0xfff; - DPRINTF("Write 0x%x=0x%x\n", (int)offset, value); - switch (offset >> 2) { - case SERIAL_DATA: - ch = value; - if (s->chr) - qemu_chr_fe_write(s->chr, &ch, 1); - break; - case SERIAL_INT_ENABLE: - s->int_enable = value; - syborg_serial_update(s); - break; - case SERIAL_DMA_TX_ADDR: - s->dma_tx_ptr = value; - break; - case SERIAL_DMA_TX_COUNT: - do_dma_tx(s, value); - break; - case SERIAL_DMA_RX_ADDR: - /* For safety, writes to this register cancel any pending DMA. */ - s->dma_rx_size = 0; - s->dma_rx_ptr = value; - break; - case SERIAL_DMA_RX_COUNT: - dma_rx_start(s, value); - break; - default: - cpu_abort(cpu_single_env, "syborg_serial_write: Bad offset %x\n", - (int)offset); - break; - } -} - -static int syborg_serial_can_receive(void *opaque) -{ - SyborgSerialState *s = (SyborgSerialState *)opaque; - - if (s->dma_rx_size) - return s->dma_rx_size; - return s->fifo_size - s->read_count; -} - -static void syborg_serial_receive(void *opaque, const uint8_t *buf, int size) -{ - SyborgSerialState *s = (SyborgSerialState *)opaque; - - if (s->dma_rx_size) { - /* Place it in the DMA buffer. */ - cpu_physical_memory_write(s->dma_rx_ptr, buf, size); - s->dma_rx_size -= size; - s->dma_rx_ptr += size; - } else { - while (size--) - fifo_push(s, *buf); - } - - syborg_serial_update(s); -} - -static void syborg_serial_event(void *opaque, int event) -{ - /* TODO: Report BREAK events? */ -} - -static const MemoryRegionOps syborg_serial_ops = { - .read = syborg_serial_read, - .write = syborg_serial_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static const VMStateDescription vmstate_syborg_serial = { - .name = "syborg_serial", - .version_id = 1, - .minimum_version_id = 1, - .minimum_version_id_old = 1, - .fields = (VMStateField[]) { - VMSTATE_UINT32_EQUAL(fifo_size, SyborgSerialState), - VMSTATE_UINT32(int_enable, SyborgSerialState), - VMSTATE_INT32(read_pos, SyborgSerialState), - VMSTATE_INT32(read_count, SyborgSerialState), - VMSTATE_UINT32(dma_tx_ptr, SyborgSerialState), - VMSTATE_UINT32(dma_rx_ptr, SyborgSerialState), - VMSTATE_UINT32(dma_rx_size, SyborgSerialState), - VMSTATE_VARRAY_UINT32(read_fifo, SyborgSerialState, fifo_size, 1, - vmstate_info_uint32, uint32), - VMSTATE_END_OF_LIST() - } -}; - -static int syborg_serial_init(SysBusDevice *dev) -{ - SyborgSerialState *s = FROM_SYSBUS(SyborgSerialState, dev); - - sysbus_init_irq(dev, &s->irq); - memory_region_init_io(&s->iomem, &syborg_serial_ops, s, - "serial", 0x1000); - sysbus_init_mmio(dev, &s->iomem); - s->chr = qdev_init_chardev(&dev->qdev); - if (s->chr) { - qemu_chr_add_handlers(s->chr, syborg_serial_can_receive, - syborg_serial_receive, syborg_serial_event, s); - } - if (s->fifo_size <= 0) { - fprintf(stderr, "syborg_serial: fifo too small\n"); - s->fifo_size = 16; - } - s->read_fifo = g_malloc0(s->fifo_size * sizeof(s->read_fifo[0])); - - return 0; -} - -static SysBusDeviceInfo syborg_serial_info = { - .init = syborg_serial_init, - .qdev.name = "syborg,serial", - .qdev.size = sizeof(SyborgSerialState), - .qdev.vmsd = &vmstate_syborg_serial, - .qdev.props = (Property[]) { - DEFINE_PROP_UINT32("fifo-size", SyborgSerialState, fifo_size, 16), - DEFINE_PROP_END_OF_LIST(), - } -}; - -static void syborg_serial_register_devices(void) -{ - sysbus_register_withprop(&syborg_serial_info); -} - -device_init(syborg_serial_register_devices) diff --git a/hw/syborg_timer.c b/hw/syborg_timer.c deleted file mode 100644 index 1498f01a62..0000000000 --- a/hw/syborg_timer.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Syborg Interval Timer. - * - * Copyright (c) 2008 CodeSourcery - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "sysbus.h" -#include "qemu-timer.h" -#include "syborg.h" - -//#define DEBUG_SYBORG_TIMER - -#ifdef DEBUG_SYBORG_TIMER -#define DPRINTF(fmt, ...) \ -do { printf("syborg_timer: " fmt , ##args); } while (0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_timer: error: " fmt , ## __VA_ARGS__); \ - exit(1);} while (0) -#else -#define DPRINTF(fmt, ...) do {} while(0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_timer: error: " fmt , ## __VA_ARGS__);} while (0) -#endif - -enum { - TIMER_ID = 0, - TIMER_RUNNING = 1, - TIMER_ONESHOT = 2, - TIMER_LIMIT = 3, - TIMER_VALUE = 4, - TIMER_INT_ENABLE = 5, - TIMER_INT_STATUS = 6, - TIMER_FREQ = 7 -}; - -typedef struct { - SysBusDevice busdev; - MemoryRegion iomem; - ptimer_state *timer; - int running; - int oneshot; - uint32_t limit; - uint32_t freq; - uint32_t int_level; - uint32_t int_enabled; - qemu_irq irq; -} SyborgTimerState; - -static void syborg_timer_update(SyborgTimerState *s) -{ - /* Update interrupt. */ - if (s->int_level && s->int_enabled) { - qemu_irq_raise(s->irq); - } else { - qemu_irq_lower(s->irq); - } -} - -static void syborg_timer_tick(void *opaque) -{ - SyborgTimerState *s = (SyborgTimerState *)opaque; - //DPRINTF("Timer Tick\n"); - s->int_level = 1; - if (s->oneshot) - s->running = 0; - syborg_timer_update(s); -} - -static uint64_t syborg_timer_read(void *opaque, target_phys_addr_t offset, - unsigned size) -{ - SyborgTimerState *s = (SyborgTimerState *)opaque; - - DPRINTF("Reg read %d\n", (int)offset); - offset &= 0xfff; - switch (offset >> 2) { - case TIMER_ID: - return SYBORG_ID_TIMER; - case TIMER_RUNNING: - return s->running; - case TIMER_ONESHOT: - return s->oneshot; - case TIMER_LIMIT: - return s->limit; - case TIMER_VALUE: - return ptimer_get_count(s->timer); - case TIMER_INT_ENABLE: - return s->int_enabled; - case TIMER_INT_STATUS: - return s->int_level; - case TIMER_FREQ: - return s->freq; - default: - cpu_abort(cpu_single_env, "syborg_timer_read: Bad offset %x\n", - (int)offset); - return 0; - } -} - -static void syborg_timer_write(void *opaque, target_phys_addr_t offset, - uint64_t value, unsigned size) -{ - SyborgTimerState *s = (SyborgTimerState *)opaque; - - DPRINTF("Reg write %d\n", (int)offset); - offset &= 0xfff; - switch (offset >> 2) { - case TIMER_RUNNING: - if (value == s->running) - break; - s->running = value; - if (value) { - ptimer_run(s->timer, s->oneshot); - } else { - ptimer_stop(s->timer); - } - break; - case TIMER_ONESHOT: - if (s->running) { - ptimer_stop(s->timer); - } - s->oneshot = value; - if (s->running) { - ptimer_run(s->timer, s->oneshot); - } - break; - case TIMER_LIMIT: - s->limit = value; - ptimer_set_limit(s->timer, value, 1); - break; - case TIMER_VALUE: - ptimer_set_count(s->timer, value); - break; - case TIMER_INT_ENABLE: - s->int_enabled = value; - syborg_timer_update(s); - break; - case TIMER_INT_STATUS: - s->int_level &= ~value; - syborg_timer_update(s); - break; - default: - cpu_abort(cpu_single_env, "syborg_timer_write: Bad offset %x\n", - (int)offset); - break; - } -} - -static const MemoryRegionOps syborg_timer_ops = { - .read = syborg_timer_read, - .write = syborg_timer_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static const VMStateDescription vmstate_syborg_timer = { - .name = "syborg_timer", - .version_id = 1, - .minimum_version_id = 1, - .minimum_version_id_old = 1, - .fields = (VMStateField[]) { - VMSTATE_INT32(running, SyborgTimerState), - VMSTATE_INT32(oneshot, SyborgTimerState), - VMSTATE_UINT32(limit, SyborgTimerState), - VMSTATE_UINT32(int_level, SyborgTimerState), - VMSTATE_UINT32(int_enabled, SyborgTimerState), - VMSTATE_PTIMER(timer, SyborgTimerState), - VMSTATE_END_OF_LIST() - } -}; - -static int syborg_timer_init(SysBusDevice *dev) -{ - SyborgTimerState *s = FROM_SYSBUS(SyborgTimerState, dev); - QEMUBH *bh; - - if (s->freq == 0) { - fprintf(stderr, "syborg_timer: Zero/unset frequency\n"); - exit(1); - } - sysbus_init_irq(dev, &s->irq); - memory_region_init_io(&s->iomem, &syborg_timer_ops, s, "timer", 0x1000); - sysbus_init_mmio(dev, &s->iomem); - - bh = qemu_bh_new(syborg_timer_tick, s); - s->timer = ptimer_init(bh); - ptimer_set_freq(s->timer, s->freq); - vmstate_register(&dev->qdev, -1, &vmstate_syborg_timer, s); - return 0; -} - -static SysBusDeviceInfo syborg_timer_info = { - .init = syborg_timer_init, - .qdev.name = "syborg,timer", - .qdev.size = sizeof(SyborgTimerState), - .qdev.props = (Property[]) { - DEFINE_PROP_UINT32("frequency",SyborgTimerState, freq, 0), - DEFINE_PROP_END_OF_LIST(), - } -}; - -static void syborg_timer_register_devices(void) -{ - sysbus_register_withprop(&syborg_timer_info); -} - -device_init(syborg_timer_register_devices) diff --git a/hw/syborg_virtio.c b/hw/syborg_virtio.c deleted file mode 100644 index 3bb10b5c70..0000000000 --- a/hw/syborg_virtio.c +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Virtio Syborg bindings - * - * Copyright (c) 2009 CodeSourcery - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "syborg.h" -#include "sysbus.h" -#include "virtio.h" -#include "virtio-net.h" - -//#define DEBUG_SYBORG_VIRTIO - -#ifdef DEBUG_SYBORG_VIRTIO -#define DPRINTF(fmt, ...) \ -do { printf("syborg_virtio: " fmt , ## __VA_ARGS__); } while (0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_virtio: error: " fmt , ## __VA_ARGS__); \ - exit(1);} while (0) -#else -#define DPRINTF(fmt, ...) do {} while(0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "syborg_virtio: error: " fmt , ## __VA_ARGS__);} while (0) -#endif - -enum { - SYBORG_VIRTIO_ID = 0, - SYBORG_VIRTIO_DEVTYPE = 1, - SYBORG_VIRTIO_HOST_FEATURES = 2, - SYBORG_VIRTIO_GUEST_FEATURES = 3, - SYBORG_VIRTIO_QUEUE_BASE = 4, - SYBORG_VIRTIO_QUEUE_NUM = 5, - SYBORG_VIRTIO_QUEUE_SEL = 6, - SYBORG_VIRTIO_QUEUE_NOTIFY = 7, - SYBORG_VIRTIO_STATUS = 8, - SYBORG_VIRTIO_INT_ENABLE = 9, - SYBORG_VIRTIO_INT_STATUS = 10 -}; - -#define SYBORG_VIRTIO_CONFIG 0x100 - -/* Device independent interface. */ - -typedef struct { - SysBusDevice busdev; - VirtIODevice *vdev; - MemoryRegion iomem; - qemu_irq irq; - uint32_t int_enable; - uint32_t id; - NICConf nic; - uint32_t host_features; - virtio_net_conf net; -} SyborgVirtIOProxy; - -static uint32_t syborg_virtio_readl(void *opaque, target_phys_addr_t offset) -{ - SyborgVirtIOProxy *s = opaque; - VirtIODevice *vdev = s->vdev; - uint32_t ret; - - DPRINTF("readl 0x%x\n", (int)offset); - if (offset >= SYBORG_VIRTIO_CONFIG) { - return virtio_config_readl(vdev, offset - SYBORG_VIRTIO_CONFIG); - } - switch(offset >> 2) { - case SYBORG_VIRTIO_ID: - ret = SYBORG_ID_VIRTIO; - break; - case SYBORG_VIRTIO_DEVTYPE: - ret = s->id; - break; - case SYBORG_VIRTIO_HOST_FEATURES: - ret = s->host_features; - break; - case SYBORG_VIRTIO_GUEST_FEATURES: - ret = vdev->guest_features; - break; - case SYBORG_VIRTIO_QUEUE_BASE: - ret = virtio_queue_get_addr(vdev, vdev->queue_sel); - break; - case SYBORG_VIRTIO_QUEUE_NUM: - ret = virtio_queue_get_num(vdev, vdev->queue_sel); - break; - case SYBORG_VIRTIO_QUEUE_SEL: - ret = vdev->queue_sel; - break; - case SYBORG_VIRTIO_STATUS: - ret = vdev->status; - break; - case SYBORG_VIRTIO_INT_ENABLE: - ret = s->int_enable; - break; - case SYBORG_VIRTIO_INT_STATUS: - ret = vdev->isr; - break; - default: - BADF("Bad read offset 0x%x\n", (int)offset); - return 0; - } - return ret; -} - -static void syborg_virtio_writel(void *opaque, target_phys_addr_t offset, - uint32_t value) -{ - SyborgVirtIOProxy *s = opaque; - VirtIODevice *vdev = s->vdev; - - DPRINTF("writel 0x%x = 0x%x\n", (int)offset, value); - if (offset >= SYBORG_VIRTIO_CONFIG) { - return virtio_config_writel(vdev, offset - SYBORG_VIRTIO_CONFIG, - value); - } - switch (offset >> 2) { - case SYBORG_VIRTIO_GUEST_FEATURES: - if (vdev->set_features) - vdev->set_features(vdev, value); - vdev->guest_features = value; - break; - case SYBORG_VIRTIO_QUEUE_BASE: - if (value == 0) - virtio_reset(vdev); - else - virtio_queue_set_addr(vdev, vdev->queue_sel, value); - break; - case SYBORG_VIRTIO_QUEUE_SEL: - if (value < VIRTIO_PCI_QUEUE_MAX) - vdev->queue_sel = value; - break; - case SYBORG_VIRTIO_QUEUE_NOTIFY: - if (value < VIRTIO_PCI_QUEUE_MAX) { - virtio_queue_notify(vdev, value); - } - break; - case SYBORG_VIRTIO_STATUS: - virtio_set_status(vdev, value & 0xFF); - if (vdev->status == 0) - virtio_reset(vdev); - break; - case SYBORG_VIRTIO_INT_ENABLE: - s->int_enable = value; - virtio_update_irq(vdev); - break; - case SYBORG_VIRTIO_INT_STATUS: - vdev->isr &= ~value; - virtio_update_irq(vdev); - break; - default: - BADF("Bad write offset 0x%x\n", (int)offset); - break; - } -} - -static uint32_t syborg_virtio_readw(void *opaque, target_phys_addr_t offset) -{ - SyborgVirtIOProxy *s = opaque; - VirtIODevice *vdev = s->vdev; - - DPRINTF("readw 0x%x\n", (int)offset); - if (offset >= SYBORG_VIRTIO_CONFIG) { - return virtio_config_readw(vdev, offset - SYBORG_VIRTIO_CONFIG); - } - BADF("Bad halfword read offset 0x%x\n", (int)offset); - return -1; -} - -static void syborg_virtio_writew(void *opaque, target_phys_addr_t offset, - uint32_t value) -{ - SyborgVirtIOProxy *s = opaque; - VirtIODevice *vdev = s->vdev; - - DPRINTF("writew 0x%x = 0x%x\n", (int)offset, value); - if (offset >= SYBORG_VIRTIO_CONFIG) { - return virtio_config_writew(vdev, offset - SYBORG_VIRTIO_CONFIG, - value); - } - BADF("Bad halfword write offset 0x%x\n", (int)offset); -} - -static uint32_t syborg_virtio_readb(void *opaque, target_phys_addr_t offset) -{ - SyborgVirtIOProxy *s = opaque; - VirtIODevice *vdev = s->vdev; - - DPRINTF("readb 0x%x\n", (int)offset); - if (offset >= SYBORG_VIRTIO_CONFIG) { - return virtio_config_readb(vdev, offset - SYBORG_VIRTIO_CONFIG); - } - BADF("Bad byte read offset 0x%x\n", (int)offset); - return -1; -} - -static void syborg_virtio_writeb(void *opaque, target_phys_addr_t offset, - uint32_t value) -{ - SyborgVirtIOProxy *s = opaque; - VirtIODevice *vdev = s->vdev; - - DPRINTF("writeb 0x%x = 0x%x\n", (int)offset, value); - if (offset >= SYBORG_VIRTIO_CONFIG) { - return virtio_config_writeb(vdev, offset - SYBORG_VIRTIO_CONFIG, - value); - } - BADF("Bad byte write offset 0x%x\n", (int)offset); -} - -static const MemoryRegionOps syborg_virtio_ops = { - .old_mmio = { - .read = { syborg_virtio_readb, syborg_virtio_readw, syborg_virtio_readl }, - .write = { syborg_virtio_writeb, syborg_virtio_writew, syborg_virtio_writel }, - }, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static void syborg_virtio_update_irq(void *opaque, uint16_t vector) -{ - SyborgVirtIOProxy *proxy = opaque; - int level; - - level = proxy->int_enable & proxy->vdev->isr; - DPRINTF("IRQ %d\n", level); - qemu_set_irq(proxy->irq, level != 0); -} - -static unsigned syborg_virtio_get_features(void *opaque) -{ - SyborgVirtIOProxy *proxy = opaque; - return proxy->host_features; -} - -static VirtIOBindings syborg_virtio_bindings = { - .notify = syborg_virtio_update_irq, - .get_features = syborg_virtio_get_features, -}; - -static int syborg_virtio_init(SyborgVirtIOProxy *proxy, VirtIODevice *vdev) -{ - proxy->vdev = vdev; - - /* Don't support multiple vectors */ - proxy->vdev->nvectors = 0; - sysbus_init_irq(&proxy->busdev, &proxy->irq); - memory_region_init_io(&proxy->iomem, &syborg_virtio_ops, proxy, - "virtio", 0x1000); - sysbus_init_mmio(&proxy->busdev, &proxy->iomem); - - proxy->id = ((uint32_t)0x1af4 << 16) | vdev->device_id; - - qemu_register_reset(virtio_reset, vdev); - - virtio_bind_device(vdev, &syborg_virtio_bindings, proxy); - proxy->host_features |= (0x1 << VIRTIO_F_NOTIFY_ON_EMPTY); - proxy->host_features = vdev->get_features(vdev, proxy->host_features); - return 0; -} - -/* Device specific bindings. */ - -static int syborg_virtio_net_init(SysBusDevice *dev) -{ - VirtIODevice *vdev; - SyborgVirtIOProxy *proxy = FROM_SYSBUS(SyborgVirtIOProxy, dev); - - vdev = virtio_net_init(&dev->qdev, &proxy->nic, &proxy->net); - return syborg_virtio_init(proxy, vdev); -} - -static SysBusDeviceInfo syborg_virtio_net_info = { - .init = syborg_virtio_net_init, - .qdev.name = "syborg,virtio-net", - .qdev.size = sizeof(SyborgVirtIOProxy), - .qdev.props = (Property[]) { - DEFINE_NIC_PROPERTIES(SyborgVirtIOProxy, nic), - DEFINE_VIRTIO_NET_FEATURES(SyborgVirtIOProxy, host_features), - DEFINE_PROP_UINT32("x-txtimer", SyborgVirtIOProxy, - net.txtimer, TX_TIMER_INTERVAL), - DEFINE_PROP_INT32("x-txburst", SyborgVirtIOProxy, - net.txburst, TX_BURST), - DEFINE_PROP_STRING("tx", SyborgVirtIOProxy, net.tx), - DEFINE_PROP_END_OF_LIST(), - } -}; - -static void syborg_virtio_register_devices(void) -{ - sysbus_register_withprop(&syborg_virtio_net_info); -} - -device_init(syborg_virtio_register_devices) diff --git a/hw/tc6393xb_template.h b/hw/tc6393xb_template.h index 1ccf6e8dfe..4cbbad5dae 100644 --- a/hw/tc6393xb_template.h +++ b/hw/tc6393xb_template.h @@ -5,7 +5,7 @@ * * FB support code. Based on G364 fb emulator * - * Copyright (c) 2007 Hervé Poussineau + * Copyright (c) 2007 Hervé Poussineau * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as diff --git a/hw/usb-bt.c b/hw/usb-bt.c index 529fa3355d..f30eec1ea2 100644 --- a/hw/usb-bt.c +++ b/hw/usb-bt.c @@ -528,6 +528,9 @@ USBDevice *usb_bt_init(HCIInfo *hci) if (!hci) return NULL; dev = usb_create_simple(NULL /* FIXME */, "usb-bt-dongle"); + if (!dev) { + return NULL; + } s = DO_UPCAST(struct USBBtState, dev, dev); s->dev.opaque = s; diff --git a/hw/usb-bus.c b/hw/usb-bus.c index 93f640d370..8203390929 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -9,6 +9,7 @@ static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); static char *usb_get_dev_path(DeviceState *dev); static char *usb_get_fw_dev_path(DeviceState *qdev); +static int usb_qdev_exit(DeviceState *qdev); static struct BusInfo usb_bus_info = { .name = "USB", @@ -75,13 +76,22 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base) dev->auto_attach = 1; QLIST_INIT(&dev->strings); rc = usb_claim_port(dev); - if (rc == 0) { - rc = dev->info->init(dev); + if (rc != 0) { + return rc; } - if (rc == 0 && dev->auto_attach) { + rc = dev->info->init(dev); + if (rc != 0) { + usb_release_port(dev); + return rc; + } + if (dev->auto_attach) { rc = usb_device_attach(dev); + if (rc != 0) { + usb_qdev_exit(qdev); + return rc; + } } - return rc; + return 0; } static int usb_qdev_exit(DeviceState *qdev) @@ -139,10 +149,17 @@ USBDevice *usb_create(USBBus *bus, const char *name) USBDevice *usb_create_simple(USBBus *bus, const char *name) { USBDevice *dev = usb_create(bus, name); + int rc; + if (!dev) { - hw_error("Failed to create USB device '%s'\n", name); + error_report("Failed to create USB device '%s'\n", name); + return NULL; + } + rc = qdev_init(&dev->qdev); + if (rc < 0) { + error_report("Failed to initialize USB device '%s'\n", name); + return NULL; } - qdev_init_nofail(&dev->qdev); return dev; } diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c index 3eea94d09e..7c926c0d47 100644 --- a/hw/usb-ehci.c +++ b/hw/usb-ehci.c @@ -437,37 +437,39 @@ struct EHCIState { } while(0) static const char *ehci_state_names[] = { - [ EST_INACTIVE ] = "INACTIVE", - [ EST_ACTIVE ] = "ACTIVE", - [ EST_EXECUTING ] = "EXECUTING", - [ EST_SLEEPING ] = "SLEEPING", - [ EST_WAITLISTHEAD ] = "WAITLISTHEAD", - [ EST_FETCHENTRY ] = "FETCH ENTRY", - [ EST_FETCHQH ] = "FETCH QH", - [ EST_FETCHITD ] = "FETCH ITD", - [ EST_ADVANCEQUEUE ] = "ADVANCEQUEUE", - [ EST_FETCHQTD ] = "FETCH QTD", - [ EST_EXECUTE ] = "EXECUTE", - [ EST_WRITEBACK ] = "WRITEBACK", - [ EST_HORIZONTALQH ] = "HORIZONTALQH", + [EST_INACTIVE] = "INACTIVE", + [EST_ACTIVE] = "ACTIVE", + [EST_EXECUTING] = "EXECUTING", + [EST_SLEEPING] = "SLEEPING", + [EST_WAITLISTHEAD] = "WAITLISTHEAD", + [EST_FETCHENTRY] = "FETCH ENTRY", + [EST_FETCHQH] = "FETCH QH", + [EST_FETCHITD] = "FETCH ITD", + [EST_ADVANCEQUEUE] = "ADVANCEQUEUE", + [EST_FETCHQTD] = "FETCH QTD", + [EST_EXECUTE] = "EXECUTE", + [EST_WRITEBACK] = "WRITEBACK", + [EST_HORIZONTALQH] = "HORIZONTALQH", }; static const char *ehci_mmio_names[] = { - [ CAPLENGTH ] = "CAPLENGTH", - [ HCIVERSION ] = "HCIVERSION", - [ HCSPARAMS ] = "HCSPARAMS", - [ HCCPARAMS ] = "HCCPARAMS", - [ USBCMD ] = "USBCMD", - [ USBSTS ] = "USBSTS", - [ USBINTR ] = "USBINTR", - [ FRINDEX ] = "FRINDEX", - [ PERIODICLISTBASE ] = "P-LIST BASE", - [ ASYNCLISTADDR ] = "A-LIST ADDR", - [ PORTSC_BEGIN ] = "PORTSC #0", - [ PORTSC_BEGIN + 4] = "PORTSC #1", - [ PORTSC_BEGIN + 8] = "PORTSC #2", - [ PORTSC_BEGIN + 12] = "PORTSC #3", - [ CONFIGFLAG ] = "CONFIGFLAG", + [CAPLENGTH] = "CAPLENGTH", + [HCIVERSION] = "HCIVERSION", + [HCSPARAMS] = "HCSPARAMS", + [HCCPARAMS] = "HCCPARAMS", + [USBCMD] = "USBCMD", + [USBSTS] = "USBSTS", + [USBINTR] = "USBINTR", + [FRINDEX] = "FRINDEX", + [PERIODICLISTBASE] = "P-LIST BASE", + [ASYNCLISTADDR] = "A-LIST ADDR", + [PORTSC_BEGIN] = "PORTSC #0", + [PORTSC_BEGIN + 4] = "PORTSC #1", + [PORTSC_BEGIN + 8] = "PORTSC #2", + [PORTSC_BEGIN + 12] = "PORTSC #3", + [PORTSC_BEGIN + 16] = "PORTSC #4", + [PORTSC_BEGIN + 20] = "PORTSC #5", + [CONFIGFLAG] = "CONFIGFLAG", }; static const char *nr2str(const char **n, size_t len, uint32_t nr) @@ -1107,7 +1109,7 @@ static inline int get_dwords(EHCIState *ehci, uint32_t addr, int i; for(i = 0; i < num; i++, buf++, addr += sizeof(*buf)) { - pci_dma_read(&ehci->dev, addr, (uint8_t *)buf, sizeof(*buf)); + pci_dma_read(&ehci->dev, addr, buf, sizeof(*buf)); *buf = le32_to_cpu(*buf); } @@ -1122,7 +1124,7 @@ static inline int put_dwords(EHCIState *ehci, uint32_t addr, for(i = 0; i < num; i++, buf++, addr += sizeof(*buf)) { uint32_t tmp = cpu_to_le32(*buf); - pci_dma_write(&ehci->dev, addr, (uint8_t *)&tmp, sizeof(tmp)); + pci_dma_write(&ehci->dev, addr, &tmp, sizeof(tmp)); } return 1; @@ -2155,7 +2157,7 @@ static void ehci_advance_periodic_state(EHCIState *ehci) } list |= ((ehci->frindex & 0x1ff8) >> 1); - pci_dma_read(&ehci->dev, list, (uint8_t *) &entry, sizeof entry); + pci_dma_read(&ehci->dev, list, &entry, sizeof entry); entry = le32_to_cpu(entry); DPRINTF("PERIODIC state adv fr=%d. [%08X] -> %08X\n", diff --git a/hw/usb-hub.c b/hw/usb-hub.c index 3eb0f1aa0a..e1959372e7 100644 --- a/hw/usb-hub.c +++ b/hw/usb-hub.c @@ -171,6 +171,8 @@ static void usb_hub_detach(USBPort *port1) USBHubState *s = port1->opaque; USBHubPort *port = &s->ports[port1->index]; + usb_wakeup(&s->dev); + /* Let upstream know the device on this port is gone */ s->dev.port->ops->child_detach(s->dev.port, port1->dev); @@ -220,7 +222,22 @@ static void usb_hub_complete(USBPort *port, USBPacket *packet) static void usb_hub_handle_reset(USBDevice *dev) { - /* XXX: do it */ + USBHubState *s = DO_UPCAST(USBHubState, dev, dev); + USBHubPort *port; + int i; + + for (i = 0; i < NUM_PORTS; i++) { + port = s->ports + i; + port->wPortStatus = PORT_STAT_POWER; + port->wPortChange = 0; + if (port->port.dev && port->port.dev->attached) { + port->wPortStatus |= PORT_STAT_CONNECTION; + port->wPortChange |= PORT_STAT_C_CONNECTION; + if (port->port.dev->speed == USB_SPEED_LOW) { + port->wPortStatus |= PORT_STAT_LOW_SPEED; + } + } + } } static int usb_hub_handle_control(USBDevice *dev, USBPacket *p, @@ -495,9 +512,8 @@ static int usb_hub_initfn(USBDevice *dev) &port->port, s, i, &usb_hub_port_ops, USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL); usb_port_location(&port->port, dev->port, i+1); - port->wPortStatus = PORT_STAT_POWER; - port->wPortChange = 0; } + usb_hub_handle_reset(dev); return 0; } diff --git a/hw/usb-msd.c b/hw/usb-msd.c index 68e3756783..4c06950125 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -546,7 +546,8 @@ static int usb_msd_initfn(USBDevice *dev) usb_desc_init(dev); scsi_bus_new(&s->bus, &s->dev.qdev, &usb_msd_scsi_info); - s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable); + s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable, + s->conf.bootindex); if (!s->scsi_dev) { return -1; } @@ -562,7 +563,6 @@ static int usb_msd_initfn(USBDevice *dev) } } - add_boot_device_path(s->conf.bootindex, &dev->qdev, "/disk@0,0"); return 0; } diff --git a/hw/usb-net.c b/hw/usb-net.c index a8b7c8dd76..f91fa32334 100644 --- a/hw/usb-net.c +++ b/hw/usb-net.c @@ -1268,8 +1268,9 @@ static ssize_t usbnet_receive(VLANClientState *nc, const uint8_t *buf, size_t si if (is_rndis(s)) { msg = (struct rndis_packet_msg_type *) s->in_buf; - if (!s->rndis_state == RNDIS_DATA_INITIALIZED) + if (s->rndis_state != RNDIS_DATA_INITIALIZED) { return -1; + } if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf)) return -1; @@ -1302,7 +1303,7 @@ static int usbnet_can_receive(VLANClientState *nc) { USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque; - if (is_rndis(s) && !s->rndis_state == RNDIS_DATA_INITIALIZED) { + if (is_rndis(s) && s->rndis_state != RNDIS_DATA_INITIALIZED) { return 1; } diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c index f9e3ea5bfc..f8912e2b0b 100644 --- a/hw/usb-uhci.c +++ b/hw/usb-uhci.c @@ -876,7 +876,7 @@ static void uhci_async_complete(USBPort *port, USBPacket *packet) uint32_t link = async->td; uint32_t int_mask = 0, val; - pci_dma_read(&s->dev, link & ~0xf, (uint8_t *) &td, sizeof(td)); + pci_dma_read(&s->dev, link & ~0xf, &td, sizeof(td)); le32_to_cpus(&td.link); le32_to_cpus(&td.ctrl); le32_to_cpus(&td.token); @@ -888,8 +888,7 @@ static void uhci_async_complete(USBPort *port, USBPacket *packet) /* update the status bits of the TD */ val = cpu_to_le32(td.ctrl); - pci_dma_write(&s->dev, (link & ~0xf) + 4, - (const uint8_t *)&val, sizeof(val)); + pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val)); uhci_async_free(s, async); } else { async->done = 1; @@ -952,7 +951,7 @@ static void uhci_process_frame(UHCIState *s) DPRINTF("uhci: processing frame %d addr 0x%x\n" , s->frnum, frame_addr); - pci_dma_read(&s->dev, frame_addr, (uint8_t *)&link, 4); + pci_dma_read(&s->dev, frame_addr, &link, 4); le32_to_cpus(&link); int_mask = 0; @@ -976,7 +975,7 @@ static void uhci_process_frame(UHCIState *s) break; } - pci_dma_read(&s->dev, link & ~0xf, (uint8_t *) &qh, sizeof(qh)); + pci_dma_read(&s->dev, link & ~0xf, &qh, sizeof(qh)); le32_to_cpus(&qh.link); le32_to_cpus(&qh.el_link); @@ -996,7 +995,7 @@ static void uhci_process_frame(UHCIState *s) } /* TD */ - pci_dma_read(&s->dev, link & ~0xf, (uint8_t *) &td, sizeof(td)); + pci_dma_read(&s->dev, link & ~0xf, &td, sizeof(td)); le32_to_cpus(&td.link); le32_to_cpus(&td.ctrl); le32_to_cpus(&td.token); @@ -1010,8 +1009,7 @@ static void uhci_process_frame(UHCIState *s) if (old_td_ctrl != td.ctrl) { /* update the status bits of the TD */ val = cpu_to_le32(td.ctrl); - pci_dma_write(&s->dev, (link & ~0xf) + 4, - (const uint8_t *)&val, sizeof(val)); + pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val)); } if (ret < 0) { @@ -1039,8 +1037,7 @@ static void uhci_process_frame(UHCIState *s) /* update QH element link */ qh.el_link = link; val = cpu_to_le32(qh.el_link); - pci_dma_write(&s->dev, (curr_qh & ~0xf) + 4, - (const uint8_t *)&val, sizeof(val)); + pci_dma_write(&s->dev, (curr_qh & ~0xf) + 4, &val, sizeof(val)); if (!depth_first(link)) { /* done with this QH */ diff --git a/hw/vga-pci.c b/hw/vga-pci.c index 14bfadbfcf..a75dbf3974 100644 --- a/hw/vga-pci.c +++ b/hw/vga-pci.c @@ -70,10 +70,9 @@ static int pci_vga_initfn(PCIDevice *dev) return 0; } -int pci_vga_init(PCIBus *bus) +DeviceState *pci_vga_init(PCIBus *bus) { - pci_create_simple(bus, -1, "VGA"); - return 0; + return &pci_create_simple(bus, -1, "VGA")->qdev; } static PCIDeviceInfo vga_info = { diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 19e89e71ee..ef27421d46 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -288,19 +288,13 @@ static void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb) static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb) { - BlockDriverAIOCB *acb; - bdrv_acct_start(req->dev->bs, &req->acct, 0, BDRV_ACCT_FLUSH); /* * Make sure all outstanding writes are posted to the backing device. */ virtio_submit_multiwrite(req->dev->bs, mrb); - - acb = bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req); - if (!acb) { - virtio_blk_flush_complete(req, -EIO); - } + bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req); } static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb) @@ -340,7 +334,6 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb) static void virtio_blk_handle_read(VirtIOBlockReq *req) { - BlockDriverAIOCB *acb; uint64_t sector; sector = ldq_p(&req->out->sector); @@ -355,13 +348,9 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req) virtio_blk_rw_complete(req, -EIO); return; } - - acb = bdrv_aio_readv(req->dev->bs, sector, &req->qiov, - req->qiov.size / BDRV_SECTOR_SIZE, - virtio_blk_rw_complete, req); - if (!acb) { - virtio_blk_rw_complete(req, -EIO); - } + bdrv_aio_readv(req->dev->bs, sector, &req->qiov, + req->qiov.size / BDRV_SECTOR_SIZE, + virtio_blk_rw_complete, req); } static void virtio_blk_handle_request(VirtIOBlockReq *req, @@ -474,7 +463,7 @@ static void virtio_blk_reset(VirtIODevice *vdev) * This should cancel pending requests, but can't do nicely until there * are per-device request lists. */ - qemu_aio_flush(); + bdrv_drain_all(); } /* coalesce internal state, copy to pci i/o region 0 @@ -485,6 +474,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) struct virtio_blk_config blkcfg; uint64_t capacity; int cylinders, heads, secs; + int blk_size = s->conf->logical_block_size; bdrv_get_geometry(s->bs, &capacity); bdrv_get_geometry_hint(s->bs, &cylinders, &heads, &secs); @@ -492,14 +482,14 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) stq_raw(&blkcfg.capacity, capacity); stl_raw(&blkcfg.seg_max, 128 - 2); stw_raw(&blkcfg.cylinders, cylinders); + stl_raw(&blkcfg.blk_size, blk_size); + stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blk_size); + stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size); blkcfg.heads = heads; blkcfg.sectors = secs & ~s->sector_mask; - blkcfg.blk_size = s->conf->logical_block_size; blkcfg.size_max = 0; blkcfg.physical_block_exp = get_physical_block_exp(s->conf); blkcfg.alignment_offset = 0; - blkcfg.min_io_size = s->conf->min_io_size / blkcfg.blk_size; - blkcfg.opt_io_size = s->conf->opt_io_size / blkcfg.blk_size; memcpy(config, &blkcfg, sizeof(struct virtio_blk_config)); } diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index ca5923c495..77b75bcd9a 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -266,7 +266,7 @@ static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy) proxy->ioeventfd_started = false; } -static void virtio_pci_reset(DeviceState *d) +void virtio_pci_reset(DeviceState *d) { VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev); virtio_pci_stop_ioeventfd(proxy); @@ -285,14 +285,9 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) case VIRTIO_PCI_GUEST_FEATURES: /* Guest does not negotiate properly? We have to assume nothing. */ if (val & (1 << VIRTIO_F_BAD_FEATURE)) { - if (vdev->bad_features) - val = proxy->host_features & vdev->bad_features(vdev); - else - val = 0; + val = vdev->bad_features ? vdev->bad_features(vdev) : 0; } - if (vdev->set_features) - vdev->set_features(vdev, val); - vdev->guest_features = val; + virtio_set_features(vdev, val); break; case VIRTIO_PCI_QUEUE_PFN: pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT; @@ -632,9 +627,10 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev) if (proxy->class_code) { pci_config_set_class(config, proxy->class_code); } - pci_set_word(config + 0x2c, pci_get_word(config + PCI_VENDOR_ID)); - pci_set_word(config + 0x2e, vdev->device_id); - config[0x3d] = 1; + pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID, + pci_get_word(config + PCI_VENDOR_ID)); + pci_set_word(config + PCI_SUBSYSTEM_ID, vdev->device_id); + config[PCI_INTERRUPT_PIN] = 1; memory_region_init(&proxy->msix_bar, "virtio-msix", 4096); if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h index f8404de92b..344c22b68f 100644 --- a/hw/virtio-pci.h +++ b/hw/virtio-pci.h @@ -45,6 +45,7 @@ typedef struct { } VirtIOPCIProxy; void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev); +void virtio_pci_reset(DeviceState *d); /* Virtio ABI version, if we increment this, we break the guest driver. */ #define VIRTIO_PCI_ABI_VERSION 0 diff --git a/hw/virtio.c b/hw/virtio.c index 7011b5b398..81ecc40b31 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -763,12 +763,25 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f) } } +int virtio_set_features(VirtIODevice *vdev, uint32_t val) +{ + uint32_t supported_features = + vdev->binding->get_features(vdev->binding_opaque); + bool bad = (val & ~supported_features) != 0; + + val &= supported_features; + if (vdev->set_features) { + vdev->set_features(vdev, val); + } + vdev->guest_features = val; + return bad ? -1 : 0; +} + int virtio_load(VirtIODevice *vdev, QEMUFile *f) { int num, i, ret; uint32_t features; - uint32_t supported_features = - vdev->binding->get_features(vdev->binding_opaque); + uint32_t supported_features; if (vdev->binding->load_config) { ret = vdev->binding->load_config(vdev->binding_opaque, f); @@ -780,14 +793,13 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f) qemu_get_8s(f, &vdev->isr); qemu_get_be16s(f, &vdev->queue_sel); qemu_get_be32s(f, &features); - if (features & ~supported_features) { + + if (virtio_set_features(vdev, features) < 0) { + supported_features = vdev->binding->get_features(vdev->binding_opaque); error_report("Features 0x%x unsupported. Allowed features: 0x%x", features, supported_features); return -1; } - if (vdev->set_features) - vdev->set_features(vdev, features); - vdev->guest_features = features; vdev->config_len = qemu_get_be32(f); qemu_get_buffer(f, vdev->config, vdev->config_len); diff --git a/hw/virtio.h b/hw/virtio.h index 2d18209fb2..25f55647b4 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -185,6 +185,7 @@ void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector); void virtio_set_status(VirtIODevice *vdev, uint8_t val); void virtio_reset(void *opaque); void virtio_update_irq(VirtIODevice *vdev); +int virtio_set_features(VirtIODevice *vdev, uint32_t val); void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding, void *opaque); diff --git a/hw/vmport.c b/hw/vmport.c index b5c6fa19cd..0a3dbc5ef5 100644 --- a/hw/vmport.c +++ b/hw/vmport.c @@ -1,7 +1,7 @@ /* * QEMU VMPort emulation * - * Copyright (C) 2007 Hervé Poussineau + * Copyright (C) 2007 Hervé Poussineau * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/hw/vmware_vga.h b/hw/vmware_vga.h index 5132573a56..db11cbfac8 100644 --- a/hw/vmware_vga.h +++ b/hw/vmware_vga.h @@ -4,15 +4,15 @@ #include "qemu-common.h" /* vmware_vga.c */ -static inline bool pci_vmsvga_init(PCIBus *bus) +static inline DeviceState *pci_vmsvga_init(PCIBus *bus) { PCIDevice *dev; dev = pci_try_create(bus, -1, "vmware-svga"); if (!dev || qdev_init(&dev->qdev) < 0) { - return false; + return NULL; } else { - return true; + return &dev->qdev; } } diff --git a/hw/wdt_ib700.c b/hw/wdt_ib700.c index 81f22d0261..ba1d92d615 100644 --- a/hw/wdt_ib700.c +++ b/hw/wdt_ib700.c @@ -42,7 +42,7 @@ typedef struct IB700state { /* This is the timer. We use a global here because the watchdog * code ensures there is only one watchdog (it is located at a fixed, - * unchangable IO port, so there could only ever be one anyway). + * unchangeable IO port, so there could only ever be one anyway). */ /* A write to this register enables the timer. */ diff --git a/hw/xen_disk.c b/hw/xen_disk.c index 286bbac54a..192e81746f 100644 --- a/hw/xen_disk.c +++ b/hw/xen_disk.c @@ -49,7 +49,6 @@ static int syncwrite = 0; static int batch_maps = 0; static int max_requests = 32; -static int use_aio = 1; /* ------------------------------------------------------------- */ @@ -314,76 +313,6 @@ static int ioreq_map(struct ioreq *ioreq) return 0; } -static int ioreq_runio_qemu_sync(struct ioreq *ioreq) -{ - struct XenBlkDev *blkdev = ioreq->blkdev; - int i, rc; - off_t pos; - - if (ioreq->req.nr_segments && ioreq_map(ioreq) == -1) { - goto err_no_map; - } - if (ioreq->presync) { - bdrv_flush(blkdev->bs); - } - - switch (ioreq->req.operation) { - case BLKIF_OP_READ: - pos = ioreq->start; - for (i = 0; i < ioreq->v.niov; i++) { - rc = bdrv_read(blkdev->bs, pos / BLOCK_SIZE, - ioreq->v.iov[i].iov_base, - ioreq->v.iov[i].iov_len / BLOCK_SIZE); - if (rc != 0) { - xen_be_printf(&blkdev->xendev, 0, "rd I/O error (%p, len %zd)\n", - ioreq->v.iov[i].iov_base, - ioreq->v.iov[i].iov_len); - goto err; - } - pos += ioreq->v.iov[i].iov_len; - } - break; - case BLKIF_OP_WRITE: - case BLKIF_OP_WRITE_BARRIER: - if (!ioreq->req.nr_segments) { - break; - } - pos = ioreq->start; - for (i = 0; i < ioreq->v.niov; i++) { - rc = bdrv_write(blkdev->bs, pos / BLOCK_SIZE, - ioreq->v.iov[i].iov_base, - ioreq->v.iov[i].iov_len / BLOCK_SIZE); - if (rc != 0) { - xen_be_printf(&blkdev->xendev, 0, "wr I/O error (%p, len %zd)\n", - ioreq->v.iov[i].iov_base, - ioreq->v.iov[i].iov_len); - goto err; - } - pos += ioreq->v.iov[i].iov_len; - } - break; - default: - /* unknown operation (shouldn't happen -- parse catches this) */ - goto err; - } - - if (ioreq->postsync) { - bdrv_flush(blkdev->bs); - } - ioreq->status = BLKIF_RSP_OKAY; - - ioreq_unmap(ioreq); - ioreq_finish(ioreq); - return 0; - -err: - ioreq_unmap(ioreq); -err_no_map: - ioreq_finish(ioreq); - ioreq->status = BLKIF_RSP_ERROR; - return -1; -} - static void qemu_aio_complete(void *opaque, int ret) { struct ioreq *ioreq = opaque; @@ -554,9 +483,7 @@ static void blk_handle_requests(struct XenBlkDev *blkdev) rp = blkdev->rings.common.sring->req_prod; xen_rmb(); /* Ensure we see queued requests up to 'rp'. */ - if (use_aio) { - blk_send_response_all(blkdev); - } + blk_send_response_all(blkdev); while (rc != rp) { /* pull request from ring */ if (RING_REQUEST_CONS_OVERFLOW(&blkdev->rings.common, rc)) { @@ -579,16 +506,7 @@ static void blk_handle_requests(struct XenBlkDev *blkdev) continue; } - if (use_aio) { - /* run i/o in aio mode */ - ioreq_runio_qemu_aio(ioreq); - } else { - /* run i/o in sync mode */ - ioreq_runio_qemu_sync(ioreq); - } - } - if (!use_aio) { - blk_send_response_all(blkdev); + ioreq_runio_qemu_aio(ioreq); } if (blkdev->more_work && blkdev->requests_inflight < max_requests) { diff --git a/hw/xen_platform.c b/hw/xen_platform.c index 5e792f56f6..e62eaef7d1 100644 --- a/hw/xen_platform.c +++ b/hw/xen_platform.c @@ -120,7 +120,7 @@ static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t v devices, and bit 2 the non-primary-master IDE devices. */ if (val & UNPLUG_ALL_IDE_DISKS) { DPRINTF("unplug disks\n"); - qemu_aio_flush(); + bdrv_drain_all(); bdrv_flush_all(); pci_unplug_disks(s->pci_dev.bus); } @@ -977,7 +977,8 @@ int kvm_cpu_exec(CPUState *env) ret = EXCP_INTERRUPT; break; } - DPRINTF("kvm run failed %s\n", strerror(-run_ret)); + fprintf(stderr, "error: kvm run failed %s\n", + strerror(-run_ret)); abort(); } diff --git a/libcacard/card_7816.c b/libcacard/card_7816.c index 6fe27d5631..8d06326da6 100644 --- a/libcacard/card_7816.c +++ b/libcacard/card_7816.c @@ -125,7 +125,7 @@ vcard_response_new_bytes(VCard *card, unsigned char *buf, int len, int Le, } /* - * get a new Reponse buffer that only has a status. + * get a new Response buffer that only has a status. */ static VCardResponse * vcard_response_new_status(vcard_7816_status_t status) @@ -239,7 +239,7 @@ vcard_apdu_set_class(VCardAPDU *apdu) { } /* - * set the Le and Lc fiels according to table 5 of the + * set the Le and Lc fields according to table 5 of the * 7816-4 part 4 spec */ static vcard_7816_status_t diff --git a/libcacard/card_7816.h b/libcacard/card_7816.h index 2bb2a0d8aa..4a01993d2d 100644 --- a/libcacard/card_7816.h +++ b/libcacard/card_7816.h @@ -23,7 +23,7 @@ VCardResponse *vcard_response_new_bytes(VCard *card, unsigned char *buf, /* response from just status bytes */ VCardResponse *vcard_response_new_status_bytes(unsigned char sw1, unsigned char sw2); -/* response from just status: NOTE this cannot fail, it will alwyas return a +/* response from just status: NOTE this cannot fail, it will always return a * valid response, if it can't allocate memory, the response will be * VCARD7816_STATUS_EXC_ERROR_MEMORY_FAILURE */ VCardResponse *vcard_make_response(vcard_7816_status_t status); diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c index 397485c753..bdc3c79462 100644 --- a/libcacard/vcard_emul_nss.c +++ b/libcacard/vcard_emul_nss.c @@ -1250,7 +1250,7 @@ vcard_emul_usage(void) " {card_type_to_emulate} What card interface to present to the guest\n" " {param_for_card} Card interface specific parameters\n" " {slot_name} NSS slot that contains the certs\n" -" {vreader_name} Virutal reader name to present to the guest\n" +" {vreader_name} Virtual reader name to present to the guest\n" " {certN} Nickname of the certificate n on the virtual card\n" "\n" "These parameters come as a single string separated by blanks or newlines." diff --git a/libcacard/vscard_common.h b/libcacard/vscard_common.h index 609ae98bcf..08f68e4dd2 100644 --- a/libcacard/vscard_common.h +++ b/libcacard/vscard_common.h @@ -44,7 +44,7 @@ * to the existing messages, addition of fields. * * The major digit is for a breaking change of protocol, presumably - * something that cannot be accomodated with the existing protocol. + * something that cannot be accommodated with the existing protocol. */ #define VSCARD_VERSION MAKE_VERSION(0, 0, 2) diff --git a/linux-aio.c b/linux-aio.c index 1c635ef12d..d2fc2e7d02 100644 --- a/linux-aio.c +++ b/linux-aio.c @@ -166,8 +166,6 @@ BlockDriverAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd, off_t offset = sector_num * 512; laiocb = qemu_aio_get(&laio_pool, bs, cb, opaque); - if (!laiocb) - return NULL; laiocb->nbytes = nb_sectors * 512; laiocb->ctx = s; laiocb->ret = -EINPROGRESS; diff --git a/linux-user/arm/nwfpe/fpopcode.h b/linux-user/arm/nwfpe/fpopcode.h index e7d100941c..1b1137f3c8 100644 --- a/linux-user/arm/nwfpe/fpopcode.h +++ b/linux-user/arm/nwfpe/fpopcode.h @@ -75,11 +75,11 @@ TABLE 1 +-------------------------+---+---+---------+---------+ | Precision | u | v | FPSR.EP | length | +-------------------------+---+---+---------+---------+ -| Single | 0 ü 0 | x | 1 words | -| Double | 1 ü 1 | x | 2 words | -| Extended | 1 ü 1 | x | 3 words | -| Packed decimal | 1 ü 1 | 0 | 3 words | -| Expanded packed decimal | 1 ü 1 | 1 | 4 words | +| Single | 0 | 0 | x | 1 words | +| Double | 1 | 1 | x | 2 words | +| Extended | 1 | 1 | x | 3 words | +| Packed decimal | 1 | 1 | 0 | 3 words | +| Expanded packed decimal | 1 | 1 | 1 | 4 words | +-------------------------+---+---+---------+---------+ Note: x = don't care */ @@ -89,10 +89,10 @@ TABLE 2 +---+---+---------------------------------+ | w | x | Number of registers to transfer | +---+---+---------------------------------+ -| 0 ü 1 | 1 | -| 1 ü 0 | 2 | -| 1 ü 1 | 3 | -| 0 ü 0 | 4 | +| 0 | 1 | 1 | +| 1 | 0 | 2 | +| 1 | 1 | 3 | +| 0 | 0 | 4 | +---+---+---------------------------------+ */ @@ -153,10 +153,10 @@ TABLE 5 +-------------------------+---+---+ | Rounding Precision | e | f | +-------------------------+---+---+ -| IEEE Single precision | 0 ü 0 | -| IEEE Double precision | 0 ü 1 | -| IEEE Extended precision | 1 ü 0 | -| undefined (trap) | 1 ü 1 | +| IEEE Single precision | 0 | 0 | +| IEEE Double precision | 0 | 1 | +| IEEE Extended precision | 1 | 0 | +| undefined (trap) | 1 | 1 | +-------------------------+---+---+ */ @@ -165,10 +165,10 @@ TABLE 5 +---------------------------------+---+---+ | Rounding Mode | g | h | +---------------------------------+---+---+ -| Round to nearest (default) | 0 ü 0 | -| Round toward plus infinity | 0 ü 1 | -| Round toward negative infinity | 1 ü 0 | -| Round toward zero | 1 ü 1 | +| Round to nearest (default) | 0 | 0 | +| Round toward plus infinity | 0 | 1 | +| Round toward negative infinity | 1 | 0 | +| Round toward zero | 1 | 1 | +---------------------------------+---+---+ */ diff --git a/linux-user/cpu-uname.c b/linux-user/cpu-uname.c index 23afedeb9b..ddc37be4f9 100644 --- a/linux-user/cpu-uname.c +++ b/linux-user/cpu-uname.c @@ -1,7 +1,7 @@ /* * cpu to uname machine name map * - * Copyright (c) 2009 Loïc Minier + * Copyright (c) 2009 Loïc Minier * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 4635bb2e5d..ea61d0d169 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2339,7 +2339,7 @@ static void fill_auxv_note(struct memelfnote *note, const TaskState *ts) * strictly necessary but we do it here for sake of completeness. */ - /* find out lenght of the vector, AT_NULL is terminator */ + /* find out length of the vector, AT_NULL is terminator */ i = len = 0; do { get_user_ual(val, auxv); diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 1062da3852..be794960cc 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -575,7 +575,7 @@ static int load_flat_file(struct linux_binprm * bprm, * help simplify all this mumbo jumbo * * We've got two different sections of relocation entries. - * The first is the GOT which resides at the begining of the data segment + * The first is the GOT which resides at the beginning of the data segment * and is terminated with a -1. This one can be relocated in place. * The second is the extra relocation entries tacked after the image's * data segment. These require a little more processing as the entry is diff --git a/linux-user/main.c b/linux-user/main.c index d1bbc577e5..64d2208a08 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -1638,7 +1638,7 @@ void cpu_loop(CPUPPCState *env) queue_signal(env, info.si_signo, &info); break; case POWERPC_EXCP_PIT: /* Programmable interval timer IRQ */ - cpu_abort(env, "Programable interval timer interrupt " + cpu_abort(env, "Programmable interval timer interrupt " "while in user mode. Aborting\n"); break; case POWERPC_EXCP_IO: /* IO error exception */ @@ -2434,7 +2434,7 @@ void cpu_loop (CPUState *env) if (env->iflags & D_FLAG) { env->sregs[SR_ESR] |= 1 << 12; env->sregs[SR_PC] -= 4; - /* FIXME: if branch was immed, replay the imm aswell. */ + /* FIXME: if branch was immed, replay the imm as well. */ } env->iflags &= ~(IMM_FLAG | D_FLAG); diff --git a/linux-user/signal.c b/linux-user/signal.c index 78e3380702..ded12caa18 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -80,7 +80,7 @@ static uint8_t host_to_target_signal_table[_NSIG] = { [SIGSYS] = TARGET_SIGSYS, /* next signals stay the same */ /* Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with - host libpthread signals. This assumes noone actually uses SIGRTMAX :-/ + host libpthread signals. This assumes no one actually uses SIGRTMAX :-/ To fix this properly we need to do manual signal delivery multiplexed over a single host signal. */ [__SIGRTMIN] = __SIGRTMAX, diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f227097801..2bf9e7ec44 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2377,7 +2377,7 @@ static inline abi_long host_to_target_semid_ds(abi_ulong target_addr, if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) return -TARGET_EFAULT; if (host_to_target_ipc_perm(target_addr,&(host_sd->sem_perm))) - return -TARGET_EFAULT;; + return -TARGET_EFAULT; target_sd->sem_nsems = tswapal(host_sd->sem_nsems); target_sd->sem_otime = tswapal(host_sd->sem_otime); target_sd->sem_ctime = tswapal(host_sd->sem_ctime); @@ -7521,8 +7521,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #endif cmd = target_to_host_fcntl_cmd(arg2); - if (cmd == -TARGET_EINVAL) - return cmd; + if (cmd == -TARGET_EINVAL) { + ret = cmd; + break; + } switch(arg2) { case TARGET_F_GETLK64: diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 9dd1b8e4cf..2857805e16 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -1,7 +1,7 @@ /* common syscall defines for all architectures */ /* Note: although the syscall numbers change between architectures, - most of them stay the same, so we handle it by puting ifdefs if + most of them stay the same, so we handle it by putting ifdefs if necessary */ #include "syscall_nr.h" @@ -669,7 +669,7 @@ typedef struct target_siginfo { * SIGBUS si_codes */ #define TARGET_BUS_ADRALN (1) /* invalid address alignment */ -#define TARGET_BUS_ADRERR (2) /* non-existant physical address */ +#define TARGET_BUS_ADRERR (2) /* non-existent physical address */ #define TARGET_BUS_OBJERR (3) /* object specific hardware error */ /* @@ -868,7 +868,7 @@ struct target_pollfd { #define TARGET_CDROM_GET_MCN 0x5311 /* Obtain the "Universal Product Code" if available (struct cdrom_mcn) */ #define TARGET_CDROM_GET_UPC TARGET_CDROM_GET_MCN /* This one is depricated, - but here anyway for compatability */ + but here anyway for compatibility */ #define TARGET_CDROMRESET 0x5312 /* hard-reset the drive */ #define TARGET_CDROMVOLREAD 0x5313 /* Get the drive's volume setting (struct cdrom_volctrl) */ diff --git a/linux-user/x86_64/syscall.h b/linux-user/x86_64/syscall.h index 2a8d696bf2..81314cfae6 100644 --- a/linux-user/x86_64/syscall.h +++ b/linux-user/x86_64/syscall.h @@ -8,7 +8,7 @@ struct target_pt_regs { abi_ulong r12; abi_ulong rbp; abi_ulong rbx; -/* arguments: non interrupts/non tracing syscalls only save upto here*/ +/* arguments: non interrupts/non tracing syscalls only save up to here */ abi_ulong r11; abi_ulong r10; abi_ulong r9; diff --git a/m68k-dis.c b/m68k-dis.c index 04f837a31d..2b155de51c 100644 --- a/m68k-dis.c +++ b/m68k-dis.c @@ -3518,7 +3518,7 @@ const struct m68k_opcode m68k_opcodes[] = /* NOTE: The mcf5200 family programmer's reference manual does not indicate the byte form of the movea instruction is invalid (as it - is on 68000 family cpus). However, experiments on the 5202 yeild + is on 68000 family cpus). However, experiments on the 5202 yield unexpected results. The value is copied, but it is not sign extended (as is done with movea.w) and the top three bytes in the address register are not disturbed. I don't know if this is the intended diff --git a/main-loop.h b/main-loop.h index 8a716b133f..876092dd15 100644 --- a/main-loop.h +++ b/main-loop.h @@ -111,7 +111,7 @@ typedef int PollingFunc(void *opaque); * qemu_add_wait_object. * * Polling callbacks really have nothing Windows specific in them, but - * as they are a hack and are currenly not necessary under POSIX systems, + * as they are a hack and are currently not necessary under POSIX systems, * they are only available when QEMU is running under Windows. * * @func: The function that does the polling, and returns 1 to force @@ -150,7 +150,7 @@ struct MemoryRegionPortio { /** * memory_region_init: Initialize a memory region * - * The region typically acts as a container for other memory regions. Us + * The region typically acts as a container for other memory regions. Use * memory_region_add_subregion() to add subregions. * * @mr: the #MemoryRegion to be initialized @@ -163,7 +163,7 @@ void memory_region_init(MemoryRegion *mr, /** * memory_region_init_io: Initialize an I/O memory region. * - * Accesses into the region will be cause the callbacks in @ops to be called. + * Accesses into the region will cause the callbacks in @ops to be called. * if @size is nonzero, subregions will be clipped to @size. * * @mr: the #MemoryRegion to be initialized. @@ -181,7 +181,7 @@ void memory_region_init_io(MemoryRegion *mr, /** * memory_region_init_ram: Initialize RAM memory region. Accesses into the - * region will be modify memory directly. + * region will modify memory directly. * * @mr: the #MemoryRegion to be initialized. * @dev: a device associated with the region; may be %NULL. @@ -197,7 +197,7 @@ void memory_region_init_ram(MemoryRegion *mr, /** * memory_region_init_ram: Initialize RAM memory region from a user-provided. - * pointer. Accesses into the region will be modify + * pointer. Accesses into the region will modify * memory directly. * * @mr: the #MemoryRegion to be initialized. @@ -251,7 +251,7 @@ void memory_region_init_rom_device(MemoryRegion *mr, uint64_t size); /** - * memory_region_destroy: Destroy a memory region and relaim all resources. + * memory_region_destroy: Destroy a memory region and reclaim all resources. * * @mr: the region to be destroyed. May not currently be a subregion * (see memory_region_add_subregion()) or referenced in an alias @@ -418,7 +418,7 @@ void memory_region_clear_coalescing(MemoryRegion *mr); * * Marks a word in an IO region (initialized with memory_region_init_io()) * as a trigger for an eventfd event. The I/O callback will not be called. - * The caller must be prepared to handle failure (hat is, take the required + * The caller must be prepared to handle failure (that is, take the required * action if the callback _is_ called). * * @mr: the memory region being updated. @@ -436,10 +436,10 @@ void memory_region_add_eventfd(MemoryRegion *mr, int fd); /** - * memory_region_del_eventfd: Cancel and eventfd. + * memory_region_del_eventfd: Cancel an eventfd. * - * Cancels an eventfd trigger request by a previous memory_region_add_eventfd() - * call. + * Cancels an eventfd trigger requested by a previous + * memory_region_add_eventfd() call. * * @mr: the memory region being updated. * @addr: the address within @mr that is to be monitored @@ -455,9 +455,9 @@ void memory_region_del_eventfd(MemoryRegion *mr, uint64_t data, int fd); /** - * memory_region_add_subregion: Add a sub-region to a container. + * memory_region_add_subregion: Add a subregion to a container. * - * Adds a sub-region at @offset. The sub-region may not overlap with other + * Adds a subregion at @offset. The subregion may not overlap with other * subregions (except for those explicitly marked as overlapping). A region * may only be added once as a subregion (unless removed with * memory_region_del_subregion()); use memory_region_init_alias() if you @@ -472,9 +472,9 @@ void memory_region_add_subregion(MemoryRegion *mr, target_phys_addr_t offset, MemoryRegion *subregion); /** - * memory_region_add_subregion: Add a sub-region to a container, with overlap. + * memory_region_add_subregion: Add a subregion to a container, with overlap. * - * Adds a sub-region at @offset. The sub-region may overlap with other + * Adds a subregion at @offset. The subregion may overlap with other * subregions. Conflicts are resolved by having a higher @priority hide a * lower @priority. Subregions without priority are taken as @priority 0. * A region may only be added once as a subregion (unless removed with @@ -502,7 +502,6 @@ void memory_region_add_subregion_overlap(MemoryRegion *mr, void memory_region_del_subregion(MemoryRegion *mr, MemoryRegion *subregion); - /* * memory_region_set_enabled: dynamically enable or disable a region * @@ -541,11 +540,17 @@ void memory_region_set_address(MemoryRegion *mr, target_phys_addr_t addr); void memory_region_set_alias_offset(MemoryRegion *mr, target_phys_addr_t offset); -/* Start a transaction; changes will be accumulated and made visible only - * when the transaction ends. +/** + * memory_region_transaction_begin: Start a transaction. + * + * During a transaction, changes will be accumulated and made visible + * only when the transaction ends (is commited). */ void memory_region_transaction_begin(void); -/* Commit a transaction and make changes visible to the guest. + +/** + * memory_region_transaction_commit: Commit a transaction and make changes + * visible to the guest. */ void memory_region_transaction_commit(void); diff --git a/migration-exec.c b/migration-exec.c index b7b1055e88..e14552ec01 100644 --- a/migration-exec.c +++ b/migration-exec.c @@ -50,12 +50,9 @@ static int exec_close(MigrationState *s) ret = qemu_fclose(s->opaque); s->opaque = NULL; s->fd = -1; - if (ret != -1 && - WIFEXITED(ret) - && WEXITSTATUS(ret) == 0) { - ret = 0; - } else { - ret = -1; + if (ret >= 0 && !(WIFEXITED(ret) && WEXITSTATUS(ret) == 0)) { + /* close succeeded, but non-zero exit code: */ + ret = -EIO; /* fake errno value */ } } return ret; diff --git a/migration-tcp.c b/migration-tcp.c index 5aa742c34b..cf6a9b83d6 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -40,12 +40,15 @@ static int socket_write(MigrationState *s, const void * buf, size_t size) static int tcp_close(MigrationState *s) { + int r = 0; DPRINTF("tcp_close\n"); if (s->fd != -1) { - close(s->fd); + if (close(s->fd) < 0) { + r = -errno; + } s->fd = -1; } - return 0; + return r; } static void tcp_wait_for_connect(void *opaque) diff --git a/migration-unix.c b/migration-unix.c index 8596353d7d..dfcf2033c6 100644 --- a/migration-unix.c +++ b/migration-unix.c @@ -40,12 +40,15 @@ static int unix_write(MigrationState *s, const void * buf, size_t size) static int unix_close(MigrationState *s) { + int r = 0; DPRINTF("unix_close\n"); if (s->fd != -1) { - close(s->fd); + if (close(s->fd) < 0) { + r = -errno; + } s->fd = -1; } - return 0; + return r; } static void unix_wait_for_connect(void *opaque) diff --git a/migration.c b/migration.c index 8280d7189a..412fdfe5bf 100644 --- a/migration.c +++ b/migration.c @@ -174,9 +174,7 @@ static int migrate_fd_cleanup(MigrationState *s) if (s->file) { DPRINTF("closing file\n"); - if (qemu_fclose(s->file) != 0) { - ret = -1; - } + ret = qemu_fclose(s->file); s->file = NULL; } else { if (s->mon) { @@ -468,37 +466,27 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) return 0; } -int do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data) +void qmp_migrate_cancel(Error **errp) { migrate_fd_cancel(migrate_get_current()); - return 0; } -int do_migrate_set_speed(Monitor *mon, const QDict *qdict, QObject **ret_data) +void qmp_migrate_set_speed(int64_t value, Error **errp) { - int64_t d; MigrationState *s; - d = qdict_get_int(qdict, "value"); - if (d < 0) { - d = 0; + if (value < 0) { + value = 0; } s = migrate_get_current(); - s->bandwidth_limit = d; + s->bandwidth_limit = value; qemu_file_set_rate_limit(s->file, s->bandwidth_limit); - - return 0; } -int do_migrate_set_downtime(Monitor *mon, const QDict *qdict, - QObject **ret_data) +void qmp_migrate_set_downtime(double value, Error **errp) { - double d; - - d = qdict_get_double(qdict, "value") * 1e9; - d = MAX(0, MIN(UINT64_MAX, d)); - max_downtime = (uint64_t)d; - - return 0; + value *= 1e9; + value = MAX(0, MIN(UINT64_MAX, value)); + max_downtime = (uint64_t)value; } diff --git a/migration.h b/migration.h index 0682179bde..372b066b48 100644 --- a/migration.h +++ b/migration.h @@ -42,15 +42,8 @@ int qemu_start_incoming_migration(const char *uri); int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data); -int do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data); - -int do_migrate_set_speed(Monitor *mon, const QDict *qdict, QObject **ret_data); - uint64_t migrate_max_downtime(void); -int do_migrate_set_downtime(Monitor *mon, const QDict *qdict, - QObject **ret_data); - void do_info_migrate_print(Monitor *mon, const QObject *data); void do_info_migrate(Monitor *mon, QObject **ret_data); @@ -88,8 +81,6 @@ uint64_t ram_bytes_total(void); int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque); int ram_load(QEMUFile *f, void *opaque, int version_id); -extern int incoming_expected; - /** * @migrate_add_blocker - prevent migration from proceeding * @@ -513,10 +513,10 @@ static int do_qmp_capabilities(Monitor *mon, const QDict *params, static void handle_user_command(Monitor *mon, const char *cmdline); -static int do_hmp_passthrough(Monitor *mon, const QDict *params, - QObject **ret_data) +char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index, + int64_t cpu_index, Error **errp) { - int ret = 0; + char *output = NULL; Monitor *old_mon, hmp; CharDriverState mchar; @@ -527,25 +527,30 @@ static int do_hmp_passthrough(Monitor *mon, const QDict *params, old_mon = cur_mon; cur_mon = &hmp; - if (qdict_haskey(params, "cpu-index")) { - ret = monitor_set_cpu(qdict_get_int(params, "cpu-index")); + if (has_cpu_index) { + int ret = monitor_set_cpu(cpu_index); if (ret < 0) { cur_mon = old_mon; - qerror_report(QERR_INVALID_PARAMETER_VALUE, "cpu-index", "a CPU number"); + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", + "a CPU number"); goto out; } } - handle_user_command(&hmp, qdict_get_str(params, "command-line")); + handle_user_command(&hmp, command_line); cur_mon = old_mon; if (qemu_chr_mem_osize(hmp.chr) > 0) { - *ret_data = QOBJECT(qemu_chr_mem_to_qs(hmp.chr)); + QString *str = qemu_chr_mem_to_qs(hmp.chr); + output = g_strdup(qstring_get_str(str)); + QDECREF(str); + } else { + output = g_strdup(""); } out: qemu_chr_close_mem(hmp.chr); - return ret; + return output; } static int compare_cmd(const char *name, const char *list) @@ -1073,65 +1078,6 @@ static void do_singlestep(Monitor *mon, const QDict *qdict) } } -static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs); - -struct bdrv_iterate_context { - Monitor *mon; - int err; -}; - -static void iostatus_bdrv_it(void *opaque, BlockDriverState *bs) -{ - bdrv_iostatus_reset(bs); -} - -/** - * do_cont(): Resume emulation. - */ -static int do_cont(Monitor *mon, const QDict *qdict, QObject **ret_data) -{ - struct bdrv_iterate_context context = { mon, 0 }; - - if (runstate_check(RUN_STATE_INMIGRATE)) { - qerror_report(QERR_MIGRATION_EXPECTED); - return -1; - } else if (runstate_check(RUN_STATE_INTERNAL_ERROR) || - runstate_check(RUN_STATE_SHUTDOWN)) { - qerror_report(QERR_RESET_REQUIRED); - return -1; - } - - bdrv_iterate(iostatus_bdrv_it, NULL); - bdrv_iterate(encrypted_bdrv_it, &context); - /* only resume the vm if all keys are set and valid */ - if (!context.err) { - vm_start(); - return 0; - } else { - return -1; - } -} - -static void bdrv_key_cb(void *opaque, int err) -{ - Monitor *mon = opaque; - - /* another key was set successfully, retry to continue */ - if (!err) - do_cont(mon, NULL, NULL); -} - -static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs) -{ - struct bdrv_iterate_context *context = opaque; - - if (!context->err && bdrv_key_required(bs)) { - context->err = -EBUSY; - monitor_read_bdrv_key_start(context->mon, bs, bdrv_key_cb, - context->mon); - } -} - static void do_gdbserver(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_try_str(qdict, "device"); @@ -1370,81 +1316,6 @@ static void do_print(Monitor *mon, const QDict *qdict) monitor_printf(mon, "\n"); } -static int do_memory_save(Monitor *mon, const QDict *qdict, QObject **ret_data) -{ - FILE *f; - uint32_t size = qdict_get_int(qdict, "size"); - const char *filename = qdict_get_str(qdict, "filename"); - target_long addr = qdict_get_int(qdict, "val"); - uint32_t l; - CPUState *env; - uint8_t buf[1024]; - int ret = -1; - - env = mon_get_cpu(); - - f = fopen(filename, "wb"); - if (!f) { - qerror_report(QERR_OPEN_FILE_FAILED, filename); - return -1; - } - while (size != 0) { - l = sizeof(buf); - if (l > size) - l = size; - cpu_memory_rw_debug(env, addr, buf, l, 0); - if (fwrite(buf, 1, l, f) != l) { - monitor_printf(mon, "fwrite() error in do_memory_save\n"); - goto exit; - } - addr += l; - size -= l; - } - - ret = 0; - -exit: - fclose(f); - return ret; -} - -static int do_physical_memory_save(Monitor *mon, const QDict *qdict, - QObject **ret_data) -{ - FILE *f; - uint32_t l; - uint8_t buf[1024]; - uint32_t size = qdict_get_int(qdict, "size"); - const char *filename = qdict_get_str(qdict, "filename"); - target_phys_addr_t addr = qdict_get_int(qdict, "val"); - int ret = -1; - - f = fopen(filename, "wb"); - if (!f) { - qerror_report(QERR_OPEN_FILE_FAILED, filename); - return -1; - } - while (size != 0) { - l = sizeof(buf); - if (l > size) - l = size; - cpu_physical_memory_read(addr, buf, l); - if (fwrite(buf, 1, l, f) != l) { - monitor_printf(mon, "fwrite() error in do_physical_memory_save\n"); - goto exit; - } - fflush(f); - addr += l; - size -= l; - } - - ret = 0; - -exit: - fclose(f); - return ret; -} - static void do_sum(Monitor *mon, const QDict *qdict) { uint32_t addr; @@ -1796,16 +1667,6 @@ static void do_boot_set(Monitor *mon, const QDict *qdict) } } -/** - * do_system_powerdown(): Issue a machine powerdown - */ -static int do_system_powerdown(Monitor *mon, const QDict *qdict, - QObject **ret_data) -{ - qemu_system_powerdown_request(); - return 0; -} - #if defined(TARGET_I386) static void print_pte(Monitor *mon, target_phys_addr_t addr, target_phys_addr_t pte, @@ -2348,25 +2209,6 @@ static void do_wav_capture(Monitor *mon, const QDict *qdict) } #endif -#if defined(TARGET_I386) -static int do_inject_nmi(Monitor *mon, const QDict *qdict, QObject **ret_data) -{ - CPUState *env; - - for (env = first_cpu; env != NULL; env = env->next_cpu) { - cpu_interrupt(env, CPU_INTERRUPT_NMI); - } - - return 0; -} -#else -static int do_inject_nmi(Monitor *mon, const QDict *qdict, QObject **ret_data) -{ - qerror_report(QERR_UNSUPPORTED); - return -1; -} -#endif - static qemu_acl *find_acl(Monitor *mon, const char *name) { qemu_acl *acl = qemu_acl_find(name); @@ -4943,3 +4785,18 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, return err; } + +int monitor_read_block_device_key(Monitor *mon, const char *device, + BlockDriverCompletionFunc *completion_cb, + void *opaque) +{ + BlockDriverState *bs; + + bs = bdrv_find(device); + if (!bs) { + monitor_printf(mon, "Device not found %s\n", device); + return -1; + } + + return monitor_read_bdrv_key_start(mon, bs, completion_cb, opaque); +} @@ -49,6 +49,9 @@ void monitor_resume(Monitor *mon); int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, BlockDriverCompletionFunc *completion_cb, void *opaque); +int monitor_read_block_device_key(Monitor *mon, const char *device, + BlockDriverCompletionFunc *completion_cb, + void *opaque); int monitor_get_fd(Monitor *mon, const char *fdname); @@ -64,4 +67,8 @@ typedef void (MonitorCompletion)(void *opaque, QObject *ret_data); void monitor_set_error(Monitor *mon, QError *qerror); +int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret); + +int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret); + #endif /* !MONITOR_H */ @@ -203,7 +203,7 @@ int nbd_negotiate(int csock, off_t size, uint32_t flags) return -1; } - TRACE("Negotation succeeded."); + TRACE("Negotiation succeeded."); return 0; } @@ -215,7 +215,7 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags, uint64_t magic, s; uint16_t tmp; - TRACE("Receiving negotation."); + TRACE("Receiving negotiation."); if (read_sync(csock, buf, 8) != 8) { LOG("read failed"); @@ -34,6 +34,7 @@ #include "monitor.h" #include "qemu-common.h" #include "qemu_socket.h" +#include "qmp-commands.h" #include "hw/qdev.h" #include "iov.h" @@ -1258,12 +1259,10 @@ void do_info_network(Monitor *mon) } } -int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data) +void qmp_set_link(const char *name, bool up, Error **errp) { VLANState *vlan; VLANClientState *vc = NULL; - const char *name = qdict_get_str(qdict, "name"); - int up = qdict_get_bool(qdict, "up"); QTAILQ_FOREACH(vlan, &vlans, next) { QTAILQ_FOREACH(vc, &vlan->clients, next) { @@ -1280,8 +1279,8 @@ int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data) done: if (!vc) { - qerror_report(QERR_DEVICE_NOT_FOUND, name); - return -1; + error_set(errp, QERR_DEVICE_NOT_FOUND, name); + return; } vc->link_down = !up; @@ -1300,7 +1299,6 @@ done: if (vc->peer && vc->peer->info->link_status_changed) { vc->peer->info->link_status_changed(vc->peer); } - return 0; } void net_cleanup(void) @@ -122,7 +122,6 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models, const char *default_model); void do_info_network(Monitor *mon); -int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data); /* NIC info */ diff --git a/net/slirp.c b/net/slirp.c index c6cda5dcb2..18e07ba609 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -305,7 +305,7 @@ void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict) { struct in_addr host_addr = { .s_addr = INADDR_ANY }; int host_port; - char buf[256] = ""; + char buf[256]; const char *src_str, *p; SlirpState *s; int is_udp = 0; @@ -325,11 +325,10 @@ void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict) return; } - if (!src_str || !src_str[0]) - goto fail_syntax; - p = src_str; - get_str_sep(buf, sizeof(buf), &p, ':'); + if (!p || get_str_sep(buf, sizeof(buf), &p, ':') < 0) { + goto fail_syntax; + } if (!strcmp(buf, "tcp") || buf[0] == '\0') { is_udp = 0; @@ -352,7 +351,7 @@ void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict) host_addr, host_port); monitor_printf(mon, "host forwarding rule for %s %s\n", src_str, - err ? "removed" : "not found"); + err ? "not found" : "removed"); return; fail_syntax: diff --git a/net/socket.c b/net/socket.c index e9ef12877f..aaf9be48e2 100644 --- a/net/socket.c +++ b/net/socket.c @@ -161,10 +161,11 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, struct in_addr #endif if (!IN_MULTICAST(ntohl(mcastaddr->sin_addr.s_addr))) { - fprintf(stderr, "qemu: error: specified mcastaddr \"%s\" (0x%08x) does not contain a multicast address\n", - inet_ntoa(mcastaddr->sin_addr), + fprintf(stderr, "qemu: error: specified mcastaddr \"%s\" (0x%08x) " + "does not contain a multicast address\n", + inet_ntoa(mcastaddr->sin_addr), (int)ntohl(mcastaddr->sin_addr.s_addr)); - return -1; + return -1; } fd = qemu_socket(PF_INET, SOCK_DGRAM, 0); @@ -177,8 +178,8 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, struct in_addr ret=setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&val, sizeof(val)); if (ret < 0) { - perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)"); - goto fail; + perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)"); + goto fail; } ret = bind(fd, (struct sockaddr *)mcastaddr, sizeof(*mcastaddr)); @@ -198,8 +199,8 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, struct in_addr ret = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char *)&imr, sizeof(struct ip_mreq)); if (ret < 0) { - perror("setsockopt(IP_ADD_MEMBERSHIP)"); - goto fail; + perror("setsockopt(IP_ADD_MEMBERSHIP)"); + goto fail; } /* Force mcast msgs to loopback (eg. several QEMUs in same host */ @@ -207,8 +208,8 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, struct in_addr ret=setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const char *)&loop, sizeof(loop)); if (ret < 0) { - perror("setsockopt(SOL_IP, IP_MULTICAST_LOOP)"); - goto fail; + perror("setsockopt(SOL_IP, IP_MULTICAST_LOOP)"); + goto fail; } /* If a bind address is given, only send packets from that address */ @@ -260,37 +261,37 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, */ if (is_connected) { - if (getsockname(fd, (struct sockaddr *) &saddr, &saddr_len) == 0) { - /* must be bound */ - if (saddr.sin_addr.s_addr==0) { - fprintf(stderr, "qemu: error: init_dgram: fd=%d unbound, cannot setup multicast dst addr\n", - fd); - return NULL; - } - /* clone dgram socket */ - newfd = net_socket_mcast_create(&saddr, NULL); - if (newfd < 0) { - /* error already reported by net_socket_mcast_create() */ - close(fd); - return NULL; - } - /* clone newfd to fd, close newfd */ - dup2(newfd, fd); - close(newfd); - - } else { - fprintf(stderr, "qemu: error: init_dgram: fd=%d failed getsockname(): %s\n", - fd, strerror(errno)); - return NULL; - } + if (getsockname(fd, (struct sockaddr *) &saddr, &saddr_len) == 0) { + /* must be bound */ + if (saddr.sin_addr.s_addr == 0) { + fprintf(stderr, "qemu: error: init_dgram: fd=%d unbound, " + "cannot setup multicast dst addr\n", fd); + goto err; + } + /* clone dgram socket */ + newfd = net_socket_mcast_create(&saddr, NULL); + if (newfd < 0) { + /* error already reported by net_socket_mcast_create() */ + goto err; + } + /* clone newfd to fd, close newfd */ + dup2(newfd, fd); + close(newfd); + + } else { + fprintf(stderr, + "qemu: error: init_dgram: fd=%d failed getsockname(): %s\n", + fd, strerror(errno)); + goto err; + } } nc = qemu_new_net_client(&net_dgram_socket_info, vlan, NULL, model, name); snprintf(nc->info_str, sizeof(nc->info_str), - "socket: fd=%d (%s mcast=%s:%d)", - fd, is_connected ? "cloned" : "", - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); + "socket: fd=%d (%s mcast=%s:%d)", + fd, is_connected ? "cloned" : "", + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); s = DO_UPCAST(NetSocketState, nc, nc); @@ -302,6 +303,10 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, if (is_connected) s->dgram_dst=saddr; return s; + +err: + closesocket(fd); + return NULL; } static void net_socket_connect(void *opaque) @@ -349,8 +354,10 @@ static NetSocketState *net_socket_fd_init(VLANState *vlan, if(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&so_type, (socklen_t *)&optlen)< 0) { - fprintf(stderr, "qemu: error: getsockopt(SO_TYPE) for fd=%d failed\n", fd); - return NULL; + fprintf(stderr, "qemu: error: getsockopt(SO_TYPE) for fd=%d failed\n", + fd); + closesocket(fd); + return NULL; } switch(so_type) { case SOCK_DGRAM: @@ -383,9 +390,7 @@ static void net_socket_accept(void *opaque) } } s1 = net_socket_fd_init(s->vlan, s->model, s->name, fd, 1); - if (!s1) { - closesocket(fd); - } else { + if (s1) { snprintf(s1->nc.info_str, sizeof(s1->nc.info_str), "socket: connection from %s:%d", inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); @@ -409,6 +414,7 @@ static int net_socket_listen_init(VLANState *vlan, fd = qemu_socket(PF_INET, SOCK_STREAM, 0); if (fd < 0) { perror("socket"); + g_free(s); return -1; } socket_set_nonblock(fd); @@ -420,11 +426,13 @@ static int net_socket_listen_init(VLANState *vlan, ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)); if (ret < 0) { perror("bind"); + g_free(s); return -1; } ret = listen(fd, 0); if (ret < 0) { perror("listen"); + g_free(s); return -1; } s->vlan = vlan; @@ -509,7 +517,7 @@ static int net_socket_mcast_init(VLANState *vlan, fd = net_socket_mcast_create(&saddr, param_localaddr); if (fd < 0) - return -1; + return -1; s = net_socket_fd_init(vlan, model, name, fd, 0); if (!s) @@ -546,7 +554,6 @@ int net_init_socket(QemuOpts *opts, } if (!net_socket_fd_init(vlan, "socket", name, fd, 1)) { - close(fd); return -1; } } else if (qemu_opt_get(opts, "listen")) { diff --git a/net/tap-solaris.c b/net/tap-solaris.c index c216d28267..cf764634ef 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -65,7 +65,7 @@ static int tap_alloc(char *dev, size_t dev_size) static int arp_fd = 0; int ip_muxid, arp_muxid; struct strioctl strioc_if, strioc_ppa; - int link_type = I_PLINK;; + int link_type = I_PLINK; struct lifreq ifr; char actual_name[32] = ""; @@ -346,15 +346,10 @@ static TAPState *net_tap_fd_init(VLANState *vlan, static int launch_script(const char *setup_script, const char *ifname, int fd) { - sigset_t oldmask, mask; int pid, status; char *args[3]; char **parg; - sigemptyset(&mask); - sigaddset(&mask, SIGCHLD); - sigprocmask(SIG_BLOCK, &mask, &oldmask); - /* try to launch network script */ pid = fork(); if (pid == 0) { @@ -378,7 +373,6 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) while (waitpid(pid, &status, 0) != pid) { /* loop */ } - sigprocmask(SIG_SETMASK, &oldmask, NULL); if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { return 0; diff --git a/os-win32.c b/os-win32.c index 8ad5fa1fc3..8523d8d0c4 100644 --- a/os-win32.c +++ b/os-win32.c @@ -44,6 +44,13 @@ int setenv(const char *name, const char *value, int overwrite) char *string = g_malloc(length); snprintf(string, length, "%s=%s", name, value); result = putenv(string); + + /* Windows takes a copy and does not continue to use our string. + * Therefore it can be safely freed on this platform. POSIX code + * typically has to leak the string because according to the spec it + * becomes part of the environment. + */ + g_free(string); } return result; } diff --git a/oslib-posix.c b/oslib-posix.c index 6f297626c7..ce755496b5 100644 --- a/oslib-posix.c +++ b/oslib-posix.c @@ -162,8 +162,7 @@ int qemu_pipe(int pipefd[2]) return ret; } -int qemu_utimensat(int dirfd, const char *path, const struct timespec *times, - int flags) +int qemu_utimens(const char *path, const struct timespec *times) { struct timeval tv[2], tv_now; struct stat st; @@ -171,7 +170,7 @@ int qemu_utimensat(int dirfd, const char *path, const struct timespec *times, #ifdef CONFIG_UTIMENSAT int ret; - ret = utimensat(dirfd, path, times, flags); + ret = utimensat(AT_FDCWD, path, times, AT_SYMLINK_NOFOLLOW); if (ret != -1 || errno != ENOSYS) { return ret; } diff --git a/pc-bios/keymaps/is b/pc-bios/keymaps/is index 21dc1fd3ca..935ac1da7a 100644 --- a/pc-bios/keymaps/is +++ b/pc-bios/keymaps/is @@ -1,4 +1,4 @@ -# 2004-03-16 Halldór Guðmundsson and Morten Lange +# 2004-03-16 Halldór Guðmundsson and Morten Lange # Keyboard definition file for the Icelandic keyboard # to be used in rdesktop 1.3.x ( See rdesktop.org) # generated from XKB map de, and changed manually diff --git a/pc-bios/ohw.diff b/pc-bios/ohw.diff index 4fb542274d..c6b6623f2f 100644 --- a/pc-bios/ohw.diff +++ b/pc-bios/ohw.diff @@ -1065,7 +1065,7 @@ diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' -- + tab, 4 * sizeof(uint32_t)); + } +#if 0 - /* escc is usefull to get MacOS X debug messages */ + /* escc is useful to get MacOS X debug messages */ { OF_regprop_t regs[8]; @@ -2645,85 +2843,12 @@ diff --git a/pc-bios/optionrom/multiboot.S b/pc-bios/optionrom/multiboot.S index cc5ca1b7d1..f08222a3c6 100644 --- a/pc-bios/optionrom/multiboot.S +++ b/pc-bios/optionrom/multiboot.S @@ -50,7 +50,7 @@ run_multiboot: shr $0x4, %ecx mov %cx, %gs - /* now push the indirect jump decriptor there */ + /* now push the indirect jump descriptor there */ mov (prot_jump), %ebx add %eax, %ebx movl %ebx, %gs:GS_PROT_JUMP diff --git a/posix-aio-compat.c b/posix-aio-compat.c index 0c0035cb18..cccb673d2e 100644 --- a/posix-aio-compat.c +++ b/posix-aio-compat.c @@ -128,8 +128,8 @@ static ssize_t handle_aiocb_ioctl(struct qemu_paiocb *aiocb) return -errno; /* - * This looks weird, but the aio code only consideres a request - * successful if it has written the number full number of bytes. + * This looks weird, but the aio code only considers a request + * successful if it has written the full number of bytes. * * Now we overload aio_nbytes as aio_ioctl_cmd for the ioctl command, * so in fact we return the ioctl command here to make posix_aio_read() @@ -611,8 +611,6 @@ BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd, struct qemu_paiocb *acb; acb = qemu_aio_get(&raw_aio_pool, bs, cb, opaque); - if (!acb) - return NULL; acb->aio_type = type; acb->aio_fildes = fd; @@ -638,8 +636,6 @@ BlockDriverAIOCB *paio_ioctl(BlockDriverState *bs, int fd, struct qemu_paiocb *acb; acb = qemu_aio_get(&raw_aio_pool, bs, cb, opaque); - if (!acb) - return NULL; acb->aio_type = QEMU_AIO_IOCTL; acb->aio_fildes = fd; acb->aio_offset = 0; diff --git a/qapi-schema-guest.json b/qapi-schema-guest.json index fde5971e87..5f8a18d4d8 100644 --- a/qapi-schema-guest.json +++ b/qapi-schema-guest.json @@ -13,7 +13,7 @@ # partially-delivered JSON text in such a way that this response # can be obtained. # -# Such clients should also preceed this command +# Such clients should also precede this command # with a 0xFF byte to make such the guest agent flushes any # partially read JSON data from a previous session. # @@ -43,7 +43,11 @@ # # Since: 0.15.0 ## -{ 'type': 'GuestAgentInfo', 'data': {'version': 'str'} } +{ 'type': 'GuestAgentCommandInfo', + 'data': { 'name': 'str', 'enabled': 'bool' } } +{ 'type': 'GuestAgentInfo', + 'data': { 'version': 'str', + 'supported_commands': ['GuestAgentCommandInfo'] } } { 'command': 'guest-info', 'returns': 'GuestAgentInfo' } diff --git a/qapi-schema-test.json b/qapi-schema-test.json index 3acedad7ee..2b38919001 100644 --- a/qapi-schema-test.json +++ b/qapi-schema-test.json @@ -16,6 +16,12 @@ 'dict': { 'userdef': 'UserDefOne', 'string': 'str' }, '*dict2': { 'userdef': 'UserDefOne', 'string': 'str' } } } } +{ 'type': 'UserDefNested', + 'data': { 'string0': 'str', + 'dict1': { 'string1': 'str', + 'dict2': { 'userdef1': 'UserDefOne', 'string2': 'str' }, + '*dict3': { 'userdef2': 'UserDefOne', 'string3': 'str' } } } } + # testing commands { 'command': 'user_def_cmd', 'data': {} } { 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} } diff --git a/qapi-schema.json b/qapi-schema.json index cb1ba776df..44cf764ec3 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -370,13 +370,27 @@ # # @encrypted: true if the backing device is encrypted # +# @bps: total throughput limit in bytes per second is specified +# +# @bps_rd: read throughput limit in bytes per second is specified +# +# @bps_wr: write throughput limit in bytes per second is specified +# +# @iops: total I/O operations per second is specified +# +# @iops_rd: read I/O operations per second is specified +# +# @iops_wr: write I/O operations per second is specified +# # Since: 0.14.0 # # Notes: This interface is only found in @BlockInfo. ## { 'type': 'BlockDeviceInfo', 'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str', - '*backing_file': 'str', 'encrypted': 'bool' } } + '*backing_file': 'str', 'encrypted': 'bool', + 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', + 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int'} } ## # @BlockDeviceIoStatus: @@ -887,3 +901,377 @@ # Notes: Do not use this command. ## { 'command': 'cpu', 'data': {'index': 'int'} } + +## +# @memsave: +# +# Save a portion of guest memory to a file. +# +# @val: the virtual address of the guest to start from +# +# @size: the size of memory region to save +# +# @filename: the file to save the memory to as binary data +# +# @cpu-index: #optional the index of the virtual CPU to use for translating the +# virtual address (defaults to CPU 0) +# +# Returns: Nothing on success +# If @cpu is not a valid VCPU, InvalidParameterValue +# If @filename cannot be opened, OpenFileFailed +# If an I/O error occurs while writing the file, IOError +# +# Since: 0.14.0 +# +# Notes: Errors were not reliably returned until 1.1 +## +{ 'command': 'memsave', + 'data': {'val': 'int', 'size': 'int', 'filename': 'str', '*cpu-index': 'int'} } + +## +# @pmemsave: +# +# Save a portion of guest physical memory to a file. +# +# @val: the physical address of the guest to start from +# +# @size: the size of memory region to save +# +# @filename: the file to save the memory to as binary data +# +# Returns: Nothing on success +# If @filename cannot be opened, OpenFileFailed +# If an I/O error occurs while writing the file, IOError +# +# Since: 0.14.0 +# +# Notes: Errors were not reliably returned until 1.1 +## +{ 'command': 'pmemsave', + 'data': {'val': 'int', 'size': 'int', 'filename': 'str'} } + +## +# @cont: +# +# Resume guest VCPU execution. +# +# Since: 0.14.0 +# +# Returns: If successful, nothing +# If the QEMU is waiting for an incoming migration, MigrationExpected +# If QEMU was started with an encrypted block device and a key has +# not yet been set, DeviceEncrypted. +# +# Notes: This command will succeed if the guest is currently running. +## +{ 'command': 'cont' } + +## +# @inject-nmi: +# +# Injects an Non-Maskable Interrupt into all guest's VCPUs. +# +# Returns: If successful, nothing +# If the Virtual Machine doesn't support NMI injection, Unsupported +# +# Since: 0.14.0 +# +# Notes: Only x86 Virtual Machines support this command. +## +{ 'command': 'inject-nmi' } + +## +# @set_link: +# +# Sets the link status of a virtual network adapter. +# +# @name: the device name of the virtual network adapter +# +# @up: true to set the link status to be up +# +# Returns: Nothing on success +# If @name is not a valid network device, DeviceNotFound +# +# Since: 0.14.0 +# +# Notes: Not all network adapters support setting link status. This command +# will succeed even if the network adapter does not support link status +# notification. +## +{ 'command': 'set_link', 'data': {'name': 'str', 'up': 'bool'} } + +## +# @block_passwd: +# +# This command sets the password of a block device that has not been open +# with a password and requires one. +# +# The two cases where this can happen are a block device is created through +# QEMU's initial command line or a block device is changed through the legacy +# @change interface. +# +# In the event that the block device is created through the initial command +# line, the VM will start in the stopped state regardless of whether '-S' is +# used. The intention is for a management tool to query the block devices to +# determine which ones are encrypted, set the passwords with this command, and +# then start the guest with the @cont command. +# +# @device: the name of the device to set the password on +# +# @password: the password to use for the device +# +# Returns: nothing on success +# If @device is not a valid block device, DeviceNotFound +# If @device is not encrypted, DeviceNotEncrypted +# If @password is not valid for this device, InvalidPassword +# +# Notes: Not all block formats support encryption and some that do are not +# able to validate that a password is correct. Disk corruption may +# occur if an invalid password is specified. +# +# Since: 0.14.0 +## +{ 'command': 'block_passwd', 'data': {'device': 'str', 'password': 'str'} } + +## +# @balloon: +# +# Request the balloon driver to change its balloon size. +# +# @value: the target size of the balloon in bytes +# +# Returns: Nothing on success +# If the balloon driver is enabled but not functional because the KVM +# kernel module cannot support it, KvmMissingCap +# If no balloon device is present, DeviceNotActive +# +# Notes: This command just issues a request to the guest. When it returns, +# the balloon size may not have changed. A guest can change the balloon +# size independent of this command. +# +# Since: 0.14.0 +## +{ 'command': 'balloon', 'data': {'value': 'int'} } + +## +# @block_resize +# +# Resize a block image while a guest is running. +# +# @device: the name of the device to get the image resized +# +# @size: new image size in bytes +# +# Returns: nothing on success +# If @device is not a valid block device, DeviceNotFound +# +# Notes: This command returns UndefinedError in a number of error conditions. +# +# Since: 0.14.0 +## +{ 'command': 'block_resize', 'data': { 'device': 'str', 'size': 'int' }} + +## +# @blockdev-snapshot-sync +# +# Generates a synchronous snapshot of a block device. +# +# @device: the name of the device to generate the snapshot from. +# +# @snapshot-file: the target of the new image. If the file exists, or if it +# is a device, the snapshot will be created in the existing +# file/device. If does not exist, a new file will be created. +# +# @format: #optional the format of the snapshot image, default is 'qcow2'. +# +# Returns: nothing on success +# If @device is not a valid block device, DeviceNotFound +# If @snapshot-file can't be opened, OpenFileFailed +# If @format is invalid, InvalidBlockFormat +# +# Notes: One of the last steps taken by this command is to close the current +# image being used by @device and open the @snapshot-file one. If that +# fails, the command will try to reopen the original image file. If +# that also fails OpenFileFailed will be returned and the guest may get +# unexpected errors. +# +# Since 0.14.0 +## +{ 'command': 'blockdev-snapshot-sync', + 'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str' } } + +## +# @human-monitor-command: +# +# Execute a command on the human monitor and return the output. +# +# @command-line: the command to execute in the human monitor +# +# @cpu-index: #optional The CPU to use for commands that require an implicit CPU +# +# Returns: the output of the command as a string +# +# Since: 0.14.0 +# +# Notes: This command only exists as a stop-gap. It's use is highly +# discouraged. The semantics of this command are not guaranteed. +# +# Known limitations: +# +# o This command is stateless, this means that commands that depend +# on state information (such as getfd) might not work +# +# o Commands that prompt the user for data (eg. 'cont' when the block +# device is encrypted) don't currently work +## +{ 'command': 'human-monitor-command', + 'data': {'command-line': 'str', '*cpu-index': 'int'}, + 'returns': 'str' } + +## +# @migrate_cancel +# +# Cancel the current executing migration process. +# +# Returns: nothing on success +# +# Notes: This command succeeds even if there is no migration process running. +# +# Since: 0.14.0 +## +{ 'command': 'migrate_cancel' } + +## +# @migrate_set_downtime +# +# Set maximum tolerated downtime for migration. +# +# @value: maximum downtime in seconds +# +# Returns: nothing on success +# +# Since: 0.14.0 +## +{ 'command': 'migrate_set_downtime', 'data': {'value': 'number'} } + +## +# @migrate_set_speed +# +# Set maximum speed for migration. +# +# @value: maximum speed in bytes. +# +# Returns: nothing on success +# +# Notes: A value lesser than zero will be automatically round up to zero. +# +# Since: 0.14.0 +## +{ 'command': 'migrate_set_speed', 'data': {'value': 'int'} } + +## +# @DevicePropertyInfo: +# +# @name: the name of the property +# +# @type: the type of the property. This will typically come in one of four +# forms: +# +# 1) A primitive type such as 'u8', 'u16', 'bool', 'str', or 'double'. +# These types are mapped to the appropriate JSON type. +# +# 2) A legacy type in the form 'legacy<subtype>' where subtype is the +# legacy qdev typename. These types are always treated as strings. +# +# 3) A child type in the form 'child<subtype>' where subtype is a qdev +# device type name. Child properties create the composition tree. +# +# 4) A link type in the form 'link<subtype>' where subtype is a qdev +# device type name. Link properties form the device model graph. +# +# Since: 1.1 +# +# Notes: This type is experimental. Its syntax may change in future releases. +## +{ 'type': 'DevicePropertyInfo', + 'data': { 'name': 'str', 'type': 'str' } } + +## +# @qom-list: +# +# This command will list any properties of a device given a path in the device +# model. +# +# @path: the path within the device model. See @qom-get for a description of +# this parameter. +# +# Returns: a list of @DevicePropertyInfo that describe the properties of the +# device. +# +# Since: 1.1 +# +# Notes: This command is experimental. It's syntax may change in future +# releases. +## +{ 'command': 'qom-list', + 'data': { 'path': 'str' }, + 'returns': [ 'DevicePropertyInfo' ] } + +## +# @qom-get: +# +# This command will get a property from a device model path and return the +# value. +# +# @path: The path within the device model. There are two forms of supported +# paths--absolute and partial paths. +# +# Absolute paths are derived from the root device and can follow child<> +# or link<> properties. Since they can follow link<> properties, they +# can be arbitrarily long. Absolute paths look like absolute filenames +# and are prefixed with a leading slash. +# +# Partial paths look like relative filenames. They do not begin +# with a prefix. The matching rules for partial paths are subtle but +# designed to make specifying devices easy. At each level of the +# composition tree, the partial path is matched as an absolute path. +# The first match is not returned. At least two matches are searched +# for. A successful result is only returned if only one match is +# found. If more than one match is found, a flag is return to +# indicate that the match was ambiguous. +# +# @property: The property name to read +# +# Returns: The property value. The type depends on the property type. legacy<> +# properties are returned as #str. child<> and link<> properties are +# returns as #str pathnames. All integer property types (u8, u16, etc) +# are returned as #int. +# +# Since: 1.1 +# +# Notes: This command is experimental and may change syntax in future releases. +## +{ 'command': 'qom-get', + 'data': { 'path': 'str', 'property': 'str' }, + 'returns': 'visitor', + 'gen': 'no' } + +## +# @qom-set: +# +# This command will set a property from a device model path. +# +# @path: see @qom-get for a description of this parameter +# +# @property: the property name to set +# +# @value: a value who's type is appropriate for the property type. See @qom-get +# for a description of type mapping. +# +# Since: 1.1 +# +# Notes: This command is experimental and may change syntax in future releases. +## +{ 'command': 'qom-set', + 'data': { 'path': 'str', 'property': 'str', 'value': 'visitor' }, + 'gen': 'no' } diff --git a/qapi/qmp-core.h b/qapi/qmp-core.h index f1c26e4b2e..3bb3acb589 100644 --- a/qapi/qmp-core.h +++ b/qapi/qmp-core.h @@ -31,11 +31,15 @@ typedef struct QmpCommand QmpCommandType type; QmpCommandFunc *fn; QTAILQ_ENTRY(QmpCommand) node; + bool enabled; } QmpCommand; void qmp_register_command(const char *name, QmpCommandFunc *fn); QmpCommand *qmp_find_command(const char *name); QObject *qmp_dispatch(QObject *request); +void qmp_disable_command(const char *name); +bool qmp_command_is_enabled(const char *name); +char **qmp_get_command_list(void); #endif diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 558469325c..43f640a95e 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -79,6 +79,10 @@ static QObject *do_qmp_dispatch(QObject *request, Error **errp) error_set(errp, QERR_COMMAND_NOT_FOUND, command); return NULL; } + if (!cmd->enabled) { + error_set(errp, QERR_COMMAND_DISABLED, command); + return NULL; + } if (!qdict_haskey(dict, "arguments")) { args = qdict_new(); diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c index 5ff99cff14..25c89ad098 100644 --- a/qapi/qmp-registry.c +++ b/qapi/qmp-registry.c @@ -14,7 +14,7 @@ #include "qapi/qmp-core.h" -static QTAILQ_HEAD(, QmpCommand) qmp_commands = +static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands = QTAILQ_HEAD_INITIALIZER(qmp_commands); void qmp_register_command(const char *name, QmpCommandFunc *fn) @@ -24,17 +24,63 @@ void qmp_register_command(const char *name, QmpCommandFunc *fn) cmd->name = name; cmd->type = QCT_NORMAL; cmd->fn = fn; + cmd->enabled = true; QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node); } QmpCommand *qmp_find_command(const char *name) { - QmpCommand *i; + QmpCommand *cmd; - QTAILQ_FOREACH(i, &qmp_commands, node) { - if (strcmp(i->name, name) == 0) { - return i; + QTAILQ_FOREACH(cmd, &qmp_commands, node) { + if (strcmp(cmd->name, name) == 0) { + return cmd; } } return NULL; } + +void qmp_disable_command(const char *name) +{ + QmpCommand *cmd; + + QTAILQ_FOREACH(cmd, &qmp_commands, node) { + if (strcmp(cmd->name, name) == 0) { + cmd->enabled = false; + return; + } + } +} + +bool qmp_command_is_enabled(const char *name) +{ + QmpCommand *cmd; + + QTAILQ_FOREACH(cmd, &qmp_commands, node) { + if (strcmp(cmd->name, name) == 0) { + return cmd->enabled; + } + } + + return false; +} + +char **qmp_get_command_list(void) +{ + QmpCommand *cmd; + int count = 1; + char **list_head, **list; + + QTAILQ_FOREACH(cmd, &qmp_commands, node) { + count++; + } + + list_head = list = g_malloc0(count * sizeof(char *)); + + QTAILQ_FOREACH(cmd, &qmp_commands, node) { + *list = strdup(cmd->name); + list++; + } + + return list_head; +} diff --git a/qemu-char.c b/qemu-char.c index b562bf88a7..27abcb9186 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -106,7 +106,7 @@ static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs = QTAILQ_HEAD_INITIALIZER(chardevs); -static void qemu_chr_event(CharDriverState *s, int event) +void qemu_chr_be_event(CharDriverState *s, int event) { /* Keep track if the char device is open */ switch (event) { @@ -126,7 +126,7 @@ static void qemu_chr_event(CharDriverState *s, int event) static void qemu_chr_generic_open_bh(void *opaque) { CharDriverState *s = opaque; - qemu_chr_event(s, CHR_EVENT_OPENED); + qemu_chr_be_event(s, CHR_EVENT_OPENED); qemu_bh_delete(s->bh); s->bh = NULL; } @@ -359,7 +359,7 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch) bdrv_commit_all(); break; case 'b': - qemu_chr_event(chr, CHR_EVENT_BREAK); + qemu_chr_be_event(chr, CHR_EVENT_BREAK); break; case 'c': /* Switch to the next registered device */ @@ -580,7 +580,7 @@ static void fd_chr_read(void *opaque) if (size == 0) { /* FD has been closed. Remove it from the active list. */ qemu_set_fd_handler2(s->fd_in, NULL, NULL, NULL, NULL); - qemu_chr_event(chr, CHR_EVENT_CLOSED); + qemu_chr_be_event(chr, CHR_EVENT_CLOSED); return; } if (size > 0) { @@ -613,7 +613,7 @@ static void fd_chr_close(struct CharDriverState *chr) } g_free(s); - qemu_chr_event(chr, CHR_EVENT_CLOSED); + qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } /* open a character device to a unix fd */ @@ -715,7 +715,7 @@ static void stdio_read(void *opaque) if (size == 0) { /* stdin has been closed. Remove it from the active list. */ qemu_set_fd_handler2(0, NULL, NULL, NULL, NULL); - qemu_chr_event(chr, CHR_EVENT_CLOSED); + qemu_chr_be_event(chr, CHR_EVENT_CLOSED); return; } if (size > 0) { @@ -977,7 +977,7 @@ static void pty_chr_close(struct CharDriverState *chr) qemu_del_timer(s->timer); qemu_free_timer(s->timer); g_free(s); - qemu_chr_event(chr, CHR_EVENT_CLOSED); + qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } static int qemu_chr_open_pty(QemuOpts *opts, CharDriverState **_chr) @@ -1355,7 +1355,7 @@ static void pp_close(CharDriverState *chr) ioctl(fd, PPRELEASE); close(fd); g_free(drv); - qemu_chr_event(chr, CHR_EVENT_CLOSED); + qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } static int qemu_chr_open_pp(QemuOpts *opts, CharDriverState **_chr) @@ -1500,7 +1500,7 @@ static void win_chr_close(CharDriverState *chr) else qemu_del_polling_cb(win_chr_poll, chr); - qemu_chr_event(chr, CHR_EVENT_CLOSED); + qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } static int win_chr_init(CharDriverState *chr, const char *filename) @@ -2108,7 +2108,7 @@ static void udp_chr_close(CharDriverState *chr) closesocket(s->fd); } g_free(s); - qemu_chr_event(chr, CHR_EVENT_CLOSED); + qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } static int qemu_chr_open_udp(QemuOpts *opts, CharDriverState **_chr) @@ -2213,7 +2213,7 @@ static void tcp_chr_process_IAC_bytes(CharDriverState *chr, } else { if ((unsigned char)buf[i] == IAC_BREAK && s->do_telnetopt == 2) { /* Handle IAC break commands by sending a serial break */ - qemu_chr_event(chr, CHR_EVENT_BREAK); + qemu_chr_be_event(chr, CHR_EVENT_BREAK); s->do_telnetopt++; } s->do_telnetopt++; @@ -2321,7 +2321,7 @@ static void tcp_chr_read(void *opaque) qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); closesocket(s->fd); s->fd = -1; - qemu_chr_event(chr, CHR_EVENT_CLOSED); + qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } else if (size > 0) { if (s->do_telnetopt) tcp_chr_process_IAC_bytes(chr, s, buf, &size); @@ -2433,7 +2433,7 @@ static void tcp_chr_close(CharDriverState *chr) closesocket(s->listen_fd); } g_free(s); - qemu_chr_event(chr, CHR_EVENT_CLOSED); + qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } static int qemu_chr_open_socket(QemuOpts *opts, CharDriverState **_chr) diff --git a/qemu-char.h b/qemu-char.h index 7efcf99f53..8ca1e2d54e 100644 --- a/qemu-char.h +++ b/qemu-char.h @@ -212,6 +212,16 @@ int qemu_chr_be_can_write(CharDriverState *s); */ void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len); + +/** + * @qemu_chr_be_event: + * + * Send an event from the back end to the front end. + * + * @event the event to send + */ +void qemu_chr_be_event(CharDriverState *s, int event); + void qemu_chr_add_handlers(CharDriverState *s, IOCanReadHandler *fd_can_read, IOReadHandler *fd_read, diff --git a/qemu-common.h b/qemu-common.h index 2ce47aa12d..44870fe523 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -341,6 +341,12 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) return res.ll; } +/* Round number down to multiple */ +#define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m)) + +/* Round number up to multiple */ +#define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m)) + #include "module.h" #endif diff --git a/qemu-config.c b/qemu-config.c index 597d7e10b1..18f30204a1 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -85,6 +85,34 @@ static QemuOptsList qemu_drive_opts = { .name = "readonly", .type = QEMU_OPT_BOOL, .help = "open drive file as read-only", + },{ + .name = "iops", + .type = QEMU_OPT_NUMBER, + .help = "limit total I/O operations per second", + },{ + .name = "iops_rd", + .type = QEMU_OPT_NUMBER, + .help = "limit read operations per second", + },{ + .name = "iops_wr", + .type = QEMU_OPT_NUMBER, + .help = "limit write operations per second", + },{ + .name = "bps", + .type = QEMU_OPT_NUMBER, + .help = "limit total bytes per second", + },{ + .name = "bps_rd", + .type = QEMU_OPT_NUMBER, + .help = "limit read bytes per second", + },{ + .name = "bps_wr", + .type = QEMU_OPT_NUMBER, + .help = "limit write bytes per second", + },{ + .name = "copy-on-read", + .type = QEMU_OPT_BOOL, + .help = "copy read data from backing file into image file", }, { /* end of list */ } }, diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c index 6b58160058..26ad76bf50 100644 --- a/qemu-coroutine-lock.c +++ b/qemu-coroutine-lock.c @@ -61,6 +61,14 @@ void coroutine_fn qemu_co_queue_wait(CoQueue *queue) assert(qemu_in_coroutine()); } +void coroutine_fn qemu_co_queue_wait_insert_head(CoQueue *queue) +{ + Coroutine *self = qemu_coroutine_self(); + QTAILQ_INSERT_HEAD(&queue->entries, self, co_queue_next); + qemu_coroutine_yield(); + assert(qemu_in_coroutine()); +} + bool qemu_co_queue_next(CoQueue *queue) { Coroutine *next; @@ -76,6 +84,13 @@ bool qemu_co_queue_next(CoQueue *queue) return (next != NULL); } +void qemu_co_queue_restart_all(CoQueue *queue) +{ + while (qemu_co_queue_next(queue)) { + /* Do nothing */ + } +} + bool qemu_co_queue_empty(CoQueue *queue) { return (QTAILQ_FIRST(&queue->entries) == NULL); @@ -136,13 +151,7 @@ void qemu_co_rwlock_unlock(CoRwlock *lock) assert(qemu_in_coroutine()); if (lock->writer) { lock->writer = false; - while (!qemu_co_queue_empty(&lock->queue)) { - /* - * Wakeup every body. This will include some - * writers too. - */ - qemu_co_queue_next(&lock->queue); - } + qemu_co_queue_restart_all(&lock->queue); } else { lock->reader--; assert(lock->reader >= 0); diff --git a/qemu-coroutine.h b/qemu-coroutine.h index b8fc4f4332..8a55fe125e 100644 --- a/qemu-coroutine.h +++ b/qemu-coroutine.h @@ -118,6 +118,12 @@ void qemu_co_queue_init(CoQueue *queue); void coroutine_fn qemu_co_queue_wait(CoQueue *queue); /** + * Adds the current coroutine to the head of the CoQueue and transfers control to the + * caller of the coroutine. + */ +void coroutine_fn qemu_co_queue_wait_insert_head(CoQueue *queue); + +/** * Restarts the next coroutine in the CoQueue and removes it from the queue. * * Returns true if a coroutine was restarted, false if the queue is empty. @@ -125,6 +131,11 @@ void coroutine_fn qemu_co_queue_wait(CoQueue *queue); bool qemu_co_queue_next(CoQueue *queue); /** + * Restarts all coroutines in the CoQueue and leaves the queue empty. + */ +void qemu_co_queue_restart_all(CoQueue *queue); + +/** * Checks if the CoQueue is empty. */ bool qemu_co_queue_empty(CoQueue *queue); diff --git a/qemu-doc.texi b/qemu-doc.texi index 9c3cb62ee3..11f4166995 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -107,7 +107,6 @@ For system emulation, the following hardware targets are supported: @item MusicPal (MV88W8618 ARM processor) @item Gumstix "Connex" and "Verdex" motherboards (PXA255/270). @item Siemens SX1 smartphone (OMAP310 processor) -@item Syborg SVP base model (ARM Cortex-A8). @item AXIS-Devboard88 (CRISv32 ETRAX-FS). @item Petalogix Spartan 3aDSP1800 MMU ref design (MicroBlaze). @item Avnet LX60/LX110/LX200 boards (Xtensa) @@ -2079,28 +2078,6 @@ Secure Digital card connected to OMAP MMC/SD host Three on-chip UARTs @end itemize -The "Syborg" Symbian Virtual Platform base model includes the following -elements: - -@itemize @minus -@item -ARM Cortex-A8 CPU -@item -Interrupt controller -@item -Timer -@item -Real Time Clock -@item -Keyboard -@item -Framebuffer -@item -Touchscreen -@item -UARTs -@end itemize - A Linux 2.6 test image is available on the QEMU web site. More information is available in the QEMU mailing-list archive. diff --git a/qemu-error.c b/qemu-error.c index 4b20d283a2..7cd5ffe1e9 100644 --- a/qemu-error.c +++ b/qemu-error.c @@ -157,6 +157,11 @@ void error_set_progname(const char *argv0) progname = p ? p + 1 : argv0; } +const char *error_get_progname(void) +{ + return progname; +} + /* * Print current location to current monitor if we have one, else to stderr. */ diff --git a/qemu-error.h b/qemu-error.h index 4d5c53700e..93d74b4a30 100644 --- a/qemu-error.h +++ b/qemu-error.h @@ -36,5 +36,6 @@ void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void error_print_loc(void); void error_set_progname(const char *argv0); void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); +const char *error_get_progname(void); #endif @@ -27,6 +27,7 @@ #include "signal.h" #include "qerror.h" #include "error_int.h" +#include "qapi/qmp-core.h" #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0" #define QGA_PIDFILE_DEFAULT "/var/run/qemu-ga.pid" @@ -91,6 +92,8 @@ static void usage(const char *cmd) " -v, --verbose log extra debugging information\n" " -V, --version print version information and exit\n" " -d, --daemonize become a daemon\n" +" -b, --blacklist comma-seperated list of RPCs to disable (no spaces, \"?\"" +" to list available RPCs)\n" " -h, --help display this help and exit\n" "\n" "Report bugs to <mdroth@linux.vnet.ibm.com>\n" @@ -548,7 +551,7 @@ static void init_guest_agent(GAState *s) int main(int argc, char **argv) { - const char *sopt = "hVvdm:p:l:f:"; + const char *sopt = "hVvdm:p:l:f:b:"; const char *method = NULL, *path = NULL, *pidfile = QGA_PIDFILE_DEFAULT; const struct option lopt[] = { { "help", 0, NULL, 'h' }, @@ -559,13 +562,16 @@ int main(int argc, char **argv) { "method", 0, NULL, 'm' }, { "path", 0, NULL, 'p' }, { "daemonize", 0, NULL, 'd' }, + { "blacklist", 0, NULL, 'b' }, { NULL, 0, NULL, 0 } }; - int opt_ind = 0, ch, daemonize = 0; + int opt_ind = 0, ch, daemonize = 0, i, j, len; GLogLevelFlags log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL; FILE *log_file = stderr; GAState *s; + module_call_init(MODULE_INIT_QAPI); + while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { switch (ch) { case 'm': @@ -595,6 +601,32 @@ int main(int argc, char **argv) case 'd': daemonize = 1; break; + case 'b': { + char **list_head, **list; + if (*optarg == '?') { + list_head = list = qmp_get_command_list(); + while (*list != NULL) { + printf("%s\n", *list); + g_free(*list); + list++; + } + g_free(list_head); + return 0; + } + for (j = 0, i = 0, len = strlen(optarg); i < len; i++) { + if (optarg[i] == ',') { + optarg[i] = 0; + qmp_disable_command(&optarg[j]); + g_debug("disabling command: %s", &optarg[j]); + j = i + 1; + } + } + if (j < i) { + qmp_disable_command(&optarg[j]); + g_debug("disabling command: %s", &optarg[j]); + } + break; + } case 'h': usage(argv[0]); return 0; @@ -624,7 +656,6 @@ int main(int argc, char **argv) ga_command_state_init_all(s->command_state); ga_state = s; - module_call_init(MODULE_INIT_QAPI); init_guest_agent(ga_state); register_signal_handlers(); diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 4be00a5edd..49dce7c928 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -24,13 +24,13 @@ ETEXI DEF("commit", img_commit, "commit [-f fmt] [-t cache] filename") STEXI -@item commit [-f @var{fmt}] @var{filename} +@item commit [-f @var{fmt}] [-t @var{cache}] @var{filename} ETEXI DEF("convert", img_convert, "convert [-c] [-p] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename") STEXI -@item convert [-c] [-p] [-f @var{fmt}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [-c] [-p] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} ETEXI DEF("info", img_info, @@ -48,7 +48,7 @@ ETEXI DEF("rebase", img_rebase, "rebase [-f fmt] [-t cache] [-p] [-u] -b backing_file [-F backing_fmt] filename") STEXI -@item rebase [-f @var{fmt}] [-p] [-u] -b @var{backing_file} [-F @var{backing_fmt}] @var{filename} +@item rebase [-f @var{fmt}] [-t @var{cache}] [-p] [-u] -b @var{backing_file} [-F @var{backing_fmt}] @var{filename} ETEXI DEF("resize", img_resize, diff --git a/qemu-img.c b/qemu-img.c index 86127f0b11..01cc0d35ad 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -332,8 +332,9 @@ static int img_create(int argc, char **argv) /* Get image size, if specified */ if (optind < argc) { int64_t sval; - sval = strtosz_suffix(argv[optind++], NULL, STRTOSZ_DEFSUFFIX_B); - if (sval < 0) { + char *end; + sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B); + if (sval < 0 || *end) { error_report("Invalid image size specified! You may use k, M, G or " "T suffixes for "); error_report("kilobytes, megabytes, gigabytes and terabytes."); @@ -710,8 +711,9 @@ static int img_convert(int argc, char **argv) case 'S': { int64_t sval; - sval = strtosz_suffix(optarg, NULL, STRTOSZ_DEFSUFFIX_B); - if (sval < 0) { + char *end; + sval = strtosz_suffix(optarg, &end, STRTOSZ_DEFSUFFIX_B); + if (sval < 0 || *end) { error_report("Invalid minimum zero buffer size for sparse output specified"); return 1; } @@ -1418,6 +1420,8 @@ static int img_rebase(int argc, char **argv) */ if (!unsafe) { uint64_t num_sectors; + uint64_t old_backing_num_sectors; + uint64_t new_backing_num_sectors; uint64_t sector; int n; uint8_t * buf_old; @@ -1428,6 +1432,8 @@ static int img_rebase(int argc, char **argv) buf_new = qemu_blockalign(bs, IO_BUF_SIZE); bdrv_get_geometry(bs, &num_sectors); + bdrv_get_geometry(bs_old_backing, &old_backing_num_sectors); + bdrv_get_geometry(bs_new_backing, &new_backing_num_sectors); local_progress = (float)100 / (num_sectors / MIN(num_sectors, IO_BUF_SIZE / 512)); @@ -1446,16 +1452,36 @@ static int img_rebase(int argc, char **argv) continue; } - /* Read old and new backing file */ - ret = bdrv_read(bs_old_backing, sector, buf_old, n); - if (ret < 0) { - error_report("error while reading from old backing file"); - goto out; + /* + * Read old and new backing file and take into consideration that + * backing files may be smaller than the COW image. + */ + if (sector >= old_backing_num_sectors) { + memset(buf_old, 0, n * BDRV_SECTOR_SIZE); + } else { + if (sector + n > old_backing_num_sectors) { + n = old_backing_num_sectors - sector; + } + + ret = bdrv_read(bs_old_backing, sector, buf_old, n); + if (ret < 0) { + error_report("error while reading from old backing file"); + goto out; + } } - ret = bdrv_read(bs_new_backing, sector, buf_new, n); - if (ret < 0) { - error_report("error while reading from new backing file"); - goto out; + + if (sector >= new_backing_num_sectors) { + memset(buf_new, 0, n * BDRV_SECTOR_SIZE); + } else { + if (sector + n > new_backing_num_sectors) { + n = new_backing_num_sectors - sector; + } + + ret = bdrv_read(bs_new_backing, sector, buf_new, n); + if (ret < 0) { + error_report("error while reading from new backing file"); + goto out; + } } /* If they differ, we need to write to the COW file */ diff --git a/qemu-img.texi b/qemu-img.texi index 70fa321dff..b2ca3a542c 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -45,6 +45,10 @@ indicates the consecutive number of bytes that must contain only zeros for qemu-img to create a sparse image during conversion. This value is rounded down to the nearest 512 bytes. You may use the common size suffixes like @code{k} for kilobytes. +@item -t @var{cache} +specifies the cache mode that should be used with the (destination) file. See +the documentation of the emulator's @code{-drive cache=...} option for allowed +values. @end table Parameters to snapshot subcommand: @@ -87,11 +91,11 @@ this case. @var{backing_file} will never be modified unless you use the The size can also be specified using the @var{size} option with @code{-o}, it doesn't need to be specified separately in this case. -@item commit [-f @var{fmt}] @var{filename} +@item commit [-f @var{fmt}] [-t @var{cache}] @var{filename} Commit the changes recorded in @var{filename} in its base image. -@item convert [-c] [-p] [-f @var{fmt}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [-c] [-p] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} Convert the disk image @var{filename} or a snapshot @var{snapshot_name} to disk image @var{output_filename} using format @var{output_fmt}. It can be optionally compressed (@code{-c} @@ -121,7 +125,7 @@ they are displayed too. List, apply, create or delete snapshots in image @var{filename}. -@item rebase [-f @var{fmt}] [-p] [-u] -b @var{backing_file} [-F @var{backing_fmt}] @var{filename} +@item rebase [-f @var{fmt}] [-t @var{cache}] [-p] [-u] -b @var{backing_file} [-F @var{backing_fmt}] @var{filename} Changes the backing file of an image. Only the formats @code{qcow2} and @code{qed} support changing the backing file. @@ -244,14 +244,10 @@ static void aio_rw_done(void *opaque, int ret) static int do_aio_readv(QEMUIOVector *qiov, int64_t offset, int *total) { - BlockDriverAIOCB *acb; int async_ret = NOT_DONE; - acb = bdrv_aio_readv(bs, offset >> 9, qiov, qiov->size >> 9, - aio_rw_done, &async_ret); - if (!acb) { - return -EIO; - } + bdrv_aio_readv(bs, offset >> 9, qiov, qiov->size >> 9, + aio_rw_done, &async_ret); while (async_ret == NOT_DONE) { qemu_aio_wait(); } @@ -262,15 +258,10 @@ static int do_aio_readv(QEMUIOVector *qiov, int64_t offset, int *total) static int do_aio_writev(QEMUIOVector *qiov, int64_t offset, int *total) { - BlockDriverAIOCB *acb; int async_ret = NOT_DONE; - acb = bdrv_aio_writev(bs, offset >> 9, qiov, qiov->size >> 9, - aio_rw_done, &async_ret); - if (!acb) { - return -EIO; - } - + bdrv_aio_writev(bs, offset >> 9, qiov, qiov->size >> 9, + aio_rw_done, &async_ret); while (async_ret == NOT_DONE) { qemu_aio_wait(); } @@ -445,7 +436,7 @@ static int read_f(int argc, char **argv) } if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) { - printf("pattern verfication range exceeds end of read data\n"); + printf("pattern verification range exceeds end of read data\n"); return 0; } @@ -1151,7 +1142,6 @@ static int aio_read_f(int argc, char **argv) { int nr_iov, c; struct aio_ctx *ctx = calloc(1, sizeof(struct aio_ctx)); - BlockDriverAIOCB *acb; while ((c = getopt(argc, argv, "CP:qv")) != EOF) { switch (c) { @@ -1206,14 +1196,8 @@ static int aio_read_f(int argc, char **argv) } gettimeofday(&ctx->t1, NULL); - acb = bdrv_aio_readv(bs, ctx->offset >> 9, &ctx->qiov, - ctx->qiov.size >> 9, aio_read_done, ctx); - if (!acb) { - free(ctx->buf); - free(ctx); - return -EIO; - } - + bdrv_aio_readv(bs, ctx->offset >> 9, &ctx->qiov, + ctx->qiov.size >> 9, aio_read_done, ctx); return 0; } @@ -1254,7 +1238,6 @@ static int aio_write_f(int argc, char **argv) int nr_iov, c; int pattern = 0xcd; struct aio_ctx *ctx = calloc(1, sizeof(struct aio_ctx)); - BlockDriverAIOCB *acb; while ((c = getopt(argc, argv, "CqP:")) != EOF) { switch (c) { @@ -1305,14 +1288,8 @@ static int aio_write_f(int argc, char **argv) } gettimeofday(&ctx->t1, NULL); - acb = bdrv_aio_writev(bs, ctx->offset >> 9, &ctx->qiov, - ctx->qiov.size >> 9, aio_write_done, ctx); - if (!acb) { - free(ctx->buf); - free(ctx); - return -EIO; - } - + bdrv_aio_writev(bs, ctx->offset >> 9, &ctx->qiov, + ctx->qiov.size >> 9, aio_write_done, ctx); return 0; } @@ -1853,9 +1830,9 @@ int main(int argc, char **argv) command_loop(); /* - * Make sure all outstanding requests get flushed the program exits. + * Make sure all outstanding requests complete before the program exits. */ - qemu_aio_flush(); + bdrv_drain_all(); if (bs) { bdrv_delete(bs); diff --git a/qemu-option.c b/qemu-option.c index f97a758a95..6b23c31235 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -480,7 +480,7 @@ void print_option_parameters(QEMUOptionParameter *list) printf("%s=%" PRId64 " ", list->name, list->value.n); break; default: - printf("%s=(unkown type) ", list->name); + printf("%s=(unknown type) ", list->name); break; } list++; diff --git a/qemu-options.hx b/qemu-options.hx index 681eaf198e..087a3b9376 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -135,7 +135,8 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive, " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n" " [,cache=writethrough|writeback|none|directsync|unsafe][,format=f]\n" " [,serial=s][,addr=A][,id=name][,aio=threads|native]\n" - " [,readonly=on|off]\n" + " [,readonly=on|off][,copy-on-read=on|off]\n" + " [[,bps=b]|[[,bps_rd=r][,bps_wr=w]]][[,iops=i]|[[,iops_rd=r][,iops_wr=w]]\n" " use 'file' as a drive image\n", QEMU_ARCH_ALL) STEXI @item -drive @var{option}[,@var{option}[,@var{option}[,...]]] @@ -186,6 +187,9 @@ host disk is full; report the error to the guest otherwise). The default setting is @option{werror=enospc} and @option{rerror=report}. @item readonly Open drive @option{file} as read-only. Guest write attempts will fail. +@item copy-on-read=@var{copy-on-read} +@var{copy-on-read} is "on" or "off" and enables whether to copy read backing +file sectors into the image file. @end table By default, writethrough caching is used for all block device. This means that @@ -213,10 +217,14 @@ qcow2. If performance is more important than correctness, In case you don't care about data integrity over host failures, use cache=unsafe. This option tells qemu that it never needs to write any data to the disk but can instead keeps things in cache. If anything goes wrong, -like your host losing power, the disk storage getting disconnected accidently, +like your host losing power, the disk storage getting disconnected accidentally, etc. you're image will most probably be rendered unusable. When using the @option{-snapshot} option, unsafe caching is always used. +Copy-on-read avoids accessing the same backing file sectors repeatedly and is +useful when the backing file is over a slow network. By default copy-on-read +is off. + Instead of @option{-cdrom} you can use: @example qemu -drive file=file,index=2,media=cdrom diff --git a/qemu-os-posix.h b/qemu-os-posix.h index 920499d836..8e1149d964 100644 --- a/qemu-os-posix.h +++ b/qemu-os-posix.h @@ -44,7 +44,6 @@ typedef struct timeval qemu_timeval; #endif #endif typedef struct timespec qemu_timespec; -int qemu_utimensat(int dirfd, const char *path, const qemu_timespec *times, - int flags); +int qemu_utimens(const char *path, const qemu_timespec *times); #endif diff --git a/qemu-tech.texi b/qemu-tech.texi index 62afe45dc2..5676fb7afd 100644 --- a/qemu-tech.texi +++ b/qemu-tech.texi @@ -96,10 +96,6 @@ Alpha and S390 hosts, but TCG (see below) doesn't support those yet. @item Precise exceptions support. -@item The virtual CPU is a library (@code{libqemu}) which can be used -in other projects (look at @file{qemu/tests/qruncom.c} to have an -example of user mode @code{libqemu} usage). - @item Floating point library supporting both full software emulation and native host FPU instructions. @@ -685,7 +681,6 @@ are available. They are used for regression testing. @menu * test-i386:: * linux-test:: -* qruncom.c:: @end menu @node test-i386 @@ -711,11 +706,6 @@ This program tests various Linux system calls. It is used to verify that the system call parameters are correctly converted between target and host CPUs. -@node qruncom.c -@section @file{qruncom.c} - -Example of usage of @code{libqemu} to emulate a user mode i386 CPU. - @node Index @chapter Index @printindex cp diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c index ac3c0c9d14..9e1b5fbdaa 100644 --- a/qemu-thread-posix.c +++ b/qemu-thread-posix.c @@ -117,20 +117,33 @@ void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) void qemu_thread_create(QemuThread *thread, void *(*start_routine)(void*), - void *arg) + void *arg, int mode) { + sigset_t set, oldset; int err; + pthread_attr_t attr; - /* Leave signal handling to the iothread. */ - sigset_t set, oldset; + err = pthread_attr_init(&attr); + if (err) { + error_exit(err, __func__); + } + if (mode == QEMU_THREAD_DETACHED) { + err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + if (err) { + error_exit(err, __func__); + } + } + /* Leave signal handling to the iothread. */ sigfillset(&set); pthread_sigmask(SIG_SETMASK, &set, &oldset); - err = pthread_create(&thread->thread, NULL, start_routine, arg); + err = pthread_create(&thread->thread, &attr, start_routine, arg); if (err) error_exit(err, __func__); pthread_sigmask(SIG_SETMASK, &oldset, NULL); + + pthread_attr_destroy(&attr); } void qemu_thread_get_self(QemuThread *thread) @@ -147,3 +160,15 @@ void qemu_thread_exit(void *retval) { pthread_exit(retval); } + +void *qemu_thread_join(QemuThread *thread) +{ + int err; + void *ret; + + err = pthread_join(thread->thread, &ret); + if (err) { + error_exit(err, __func__); + } + return ret; +} diff --git a/qemu-thread-win32.c b/qemu-thread-win32.c index db8e744729..fe9b931863 100644 --- a/qemu-thread-win32.c +++ b/qemu-thread-win32.c @@ -193,41 +193,74 @@ void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) } struct QemuThreadData { - QemuThread *thread; - void *(*start_routine)(void *); - void *arg; + /* Passed to win32_start_routine. */ + void *(*start_routine)(void *); + void *arg; + short mode; + + /* Only used for joinable threads. */ + bool exited; + void *ret; + CRITICAL_SECTION cs; }; static int qemu_thread_tls_index = TLS_OUT_OF_INDEXES; static unsigned __stdcall win32_start_routine(void *arg) { - struct QemuThreadData data = *(struct QemuThreadData *) arg; - QemuThread *thread = data.thread; - - free(arg); - TlsSetValue(qemu_thread_tls_index, thread); - - /* - * Use DuplicateHandle instead of assigning thread->thread in the - * creating thread to avoid races. It's simpler this way than with - * synchronization. - */ - DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), - GetCurrentProcess(), &thread->thread, - 0, FALSE, DUPLICATE_SAME_ACCESS); - - qemu_thread_exit(data.start_routine(data.arg)); + QemuThreadData *data = (QemuThreadData *) arg; + void *(*start_routine)(void *) = data->start_routine; + void *thread_arg = data->arg; + + if (data->mode == QEMU_THREAD_DETACHED) { + g_free(data); + data = NULL; + } else { + InitializeCriticalSection(&data->cs); + } + TlsSetValue(qemu_thread_tls_index, data); + qemu_thread_exit(start_routine(thread_arg)); abort(); } void qemu_thread_exit(void *arg) { - QemuThread *thread = TlsGetValue(qemu_thread_tls_index); - thread->ret = arg; - CloseHandle(thread->thread); - thread->thread = NULL; - ExitThread(0); + QemuThreadData *data = TlsGetValue(qemu_thread_tls_index); + if (data) { + data->ret = arg; + EnterCriticalSection(&data->cs); + data->exited = true; + LeaveCriticalSection(&data->cs); + } + _endthreadex(0); +} + +void *qemu_thread_join(QemuThread *thread) +{ + QemuThreadData *data; + void *ret; + HANDLE handle; + + data = thread->data; + if (!data) { + return NULL; + } + /* + * Because multiple copies of the QemuThread can exist via + * qemu_thread_get_self, we need to store a value that cannot + * leak there. The simplest, non racy way is to store the TID, + * discard the handle that _beginthreadex gives back, and + * get another copy of the handle here. + */ + handle = qemu_thread_get_handle(thread); + if (handle) { + WaitForSingleObject(handle, INFINITE); + CloseHandle(handle); + } + ret = data->ret; + DeleteCriticalSection(&data->cs); + g_free(data); + return ret; } static inline void qemu_thread_init(void) @@ -243,39 +276,56 @@ static inline void qemu_thread_init(void) void qemu_thread_create(QemuThread *thread, void *(*start_routine)(void *), - void *arg) + void *arg, int mode) { HANDLE hThread; struct QemuThreadData *data; qemu_thread_init(); data = g_malloc(sizeof *data); - data->thread = thread; data->start_routine = start_routine; data->arg = arg; + data->mode = mode; + data->exited = false; hThread = (HANDLE) _beginthreadex(NULL, 0, win32_start_routine, - data, 0, NULL); + data, 0, &thread->tid); if (!hThread) { error_exit(GetLastError(), __func__); } CloseHandle(hThread); + thread->data = (mode == QEMU_THREAD_DETACHED) ? NULL : data; } void qemu_thread_get_self(QemuThread *thread) { - if (!thread->thread) { - /* In the main thread of the process. Initialize the QemuThread - pointer in TLS, and use the dummy GetCurrentThread handle as - the identifier for qemu_thread_is_self. */ - qemu_thread_init(); - TlsSetValue(qemu_thread_tls_index, thread); - thread->thread = GetCurrentThread(); + qemu_thread_init(); + thread->data = TlsGetValue(qemu_thread_tls_index); + thread->tid = GetCurrentThreadId(); +} + +HANDLE qemu_thread_get_handle(QemuThread *thread) +{ + QemuThreadData *data; + HANDLE handle; + + data = thread->data; + if (!data) { + return NULL; + } + + EnterCriticalSection(&data->cs); + if (!data->exited) { + handle = OpenThread(SYNCHRONIZE | THREAD_SUSPEND_RESUME, FALSE, + thread->tid); + } else { + handle = NULL; } + LeaveCriticalSection(&data->cs); + return handle; } int qemu_thread_is_self(QemuThread *thread) { - QemuThread *this_thread = TlsGetValue(qemu_thread_tls_index); - return this_thread->thread == thread->thread; + return GetCurrentThreadId() == thread->tid; } diff --git a/qemu-thread-win32.h b/qemu-thread-win32.h index 878f86a910..b9d1be8478 100644 --- a/qemu-thread-win32.h +++ b/qemu-thread-win32.h @@ -13,9 +13,13 @@ struct QemuCond { HANDLE continue_event; }; +typedef struct QemuThreadData QemuThreadData; struct QemuThread { - HANDLE thread; - void *ret; + QemuThreadData *data; + unsigned tid; }; +/* Only valid for joinable threads. */ +HANDLE qemu_thread_get_handle(QemuThread *thread); + #endif diff --git a/qemu-thread.h b/qemu-thread.h index e008b60028..a78a8f2524 100644 --- a/qemu-thread.h +++ b/qemu-thread.h @@ -13,6 +13,9 @@ typedef struct QemuThread QemuThread; #include "qemu-thread-posix.h" #endif +#define QEMU_THREAD_JOINABLE 0 +#define QEMU_THREAD_DETACHED 1 + void qemu_mutex_init(QemuMutex *mutex); void qemu_mutex_destroy(QemuMutex *mutex); void qemu_mutex_lock(QemuMutex *mutex); @@ -35,8 +38,9 @@ void qemu_cond_broadcast(QemuCond *cond); void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex); void qemu_thread_create(QemuThread *thread, - void *(*start_routine)(void*), - void *arg); + void *(*start_routine)(void *), + void *arg, int mode); +void *qemu_thread_join(QemuThread *thread); void qemu_thread_get_self(QemuThread *thread); int qemu_thread_is_self(QemuThread *thread); void qemu_thread_exit(void *retval); diff --git a/qemu-tls.h b/qemu-tls.h index 5b70f10f8f..b92ea9d7da 100644 --- a/qemu-tls.h +++ b/qemu-tls.h @@ -41,12 +41,12 @@ #ifdef __linux__ #define DECLARE_TLS(type, x) extern DEFINE_TLS(type, x) #define DEFINE_TLS(type, x) __thread __typeof__(type) tls__##x -#define get_tls(x) tls__##x +#define tls_var(x) tls__##x #else /* Dummy implementations which define plain global variables */ #define DECLARE_TLS(type, x) extern DEFINE_TLS(type, x) #define DEFINE_TLS(type, x) __typeof__(type) tls__##x -#define get_tls(x) tls__##x +#define tls_var(x) tls__##x #endif #endif @@ -65,6 +65,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "The command %(name) has not been found", }, { + .error_fmt = QERR_COMMAND_DISABLED, + .desc = "The command %(name) has been disabled for this instance", + }, + { .error_fmt = QERR_DEVICE_ENCRYPTED, .desc = "Device '%(device)' is encrypted", }, @@ -149,6 +153,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Password incorrect", }, { + .error_fmt = QERR_IO_ERROR, + .desc = "An IO error has occurred", + }, + { .error_fmt = QERR_JSON_PARSING, .desc = "Invalid JSON syntax", }, @@ -178,6 +186,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Could not open '%(filename)'", }, { + .error_fmt = QERR_PERMISSION_DENIED, + .desc = "Insufficient permission to perform this operation", + }, + { .error_fmt = QERR_PROPERTY_NOT_FOUND, .desc = "Property '%(device).%(property)' not found", }, @@ -223,7 +235,7 @@ static const QErrorStringTable qerror_table[] = { }, { .error_fmt = QERR_UNDEFINED_ERROR, - .desc = "An undefined error has ocurred", + .desc = "An undefined error has occurred", }, { .error_fmt = QERR_UNSUPPORTED, @@ -235,6 +247,11 @@ static const QErrorStringTable qerror_table[] = { "supported by this qemu version: %(feature)", }, { + .error_fmt = QERR_VIRTFS_FEATURE_BLOCKS_MIGRATION, + .desc = "Migration is disabled when VirtFS export path '%(path)' " + "is mounted in the guest using mount_tag '%(tag)'", + }, + { .error_fmt = QERR_VNC_SERVER_FAILED, .desc = "Could not start VNC server on %(target)", }, @@ -246,6 +263,10 @@ static const QErrorStringTable qerror_table[] = { .error_fmt = QERR_QGA_COMMAND_FAILED, .desc = "Guest agent command failed, error was '%(message)'", }, + { + .error_fmt = QERR_INVALID_PARAMETER_COMBINATION, + .desc = "Invalid parameter combination", + }, {} }; @@ -66,6 +66,9 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_COMMAND_NOT_FOUND \ "{ 'class': 'CommandNotFound', 'data': { 'name': %s } }" +#define QERR_COMMAND_DISABLED \ + "{ 'class': 'CommandDisabled', 'data': { 'name': %s } }" + #define QERR_DEVICE_ENCRYPTED \ "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }" @@ -126,6 +129,9 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_INVALID_PASSWORD \ "{ 'class': 'InvalidPassword', 'data': {} }" +#define QERR_IO_ERROR \ + "{ 'class': 'IOError', 'data': {} }" + #define QERR_JSON_PARSING \ "{ 'class': 'JSONParsing', 'data': {} }" @@ -150,6 +156,9 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_OPEN_FILE_FAILED \ "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }" +#define QERR_PERMISSION_DENIED \ + "{ 'class': 'PermissionDenied', 'data': {} }" + #define QERR_PROPERTY_NOT_FOUND \ "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }" @@ -192,6 +201,9 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_UNKNOWN_BLOCK_FORMAT_FEATURE \ "{ 'class': 'UnknownBlockFormatFeature', 'data': { 'device': %s, 'format': %s, 'feature': %s } }" +#define QERR_VIRTFS_FEATURE_BLOCKS_MIGRATION \ + "{ 'class': 'VirtFSFeatureBlocksMigration', 'data': { 'path': %s, 'tag': %s } }" + #define QERR_VNC_SERVER_FAILED \ "{ 'class': 'VNCServerFailed', 'data': { 'target': %s } }" @@ -204,4 +216,7 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_QGA_COMMAND_FAILED \ "{ 'class': 'QgaCommandFailed', 'data': { 'message': %s } }" +#define QERR_INVALID_PARAMETER_COMBINATION \ + "{ 'class': 'InvalidParameterCombination', 'data': {} }" + #endif /* QERROR_H */ diff --git a/qga/guest-agent-commands.c b/qga/guest-agent-commands.c index 6da9904819..a09c8ca230 100644 --- a/qga/guest-agent-commands.c +++ b/qga/guest-agent-commands.c @@ -57,9 +57,33 @@ void qmp_guest_ping(Error **err) struct GuestAgentInfo *qmp_guest_info(Error **err) { GuestAgentInfo *info = g_malloc0(sizeof(GuestAgentInfo)); + GuestAgentCommandInfo *cmd_info; + GuestAgentCommandInfoList *cmd_info_list; + char **cmd_list_head, **cmd_list; info->version = g_strdup(QGA_VERSION); + cmd_list_head = cmd_list = qmp_get_command_list(); + if (*cmd_list_head == NULL) { + goto out; + } + + while (*cmd_list) { + cmd_info = g_malloc0(sizeof(GuestAgentCommandInfo)); + cmd_info->name = strdup(*cmd_list); + cmd_info->enabled = qmp_command_is_enabled(cmd_info->name); + + cmd_info_list = g_malloc0(sizeof(GuestAgentCommandInfoList)); + cmd_info_list->value = cmd_info; + cmd_info_list->next = info->supported_commands; + info->supported_commands = cmd_info_list; + + g_free(*cmd_list); + cmd_list++; + } + +out: + g_free(cmd_list_head); return info; } diff --git a/qmp-commands.hx b/qmp-commands.hx index 97975a5207..7e3f4b9a59 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -199,10 +199,7 @@ EQMP { .name = "cont", .args_type = "", - .params = "", - .help = "resume emulation", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_cont, + .mhandler.cmd_new = qmp_marshal_input_cont, }, SQMP @@ -244,10 +241,7 @@ EQMP { .name = "system_powerdown", .args_type = "", - .params = "", - .help = "send system power down event", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_system_powerdown, + .mhandler.cmd_new = qmp_marshal_input_system_powerdown, }, SQMP @@ -355,11 +349,8 @@ EQMP { .name = "memsave", - .args_type = "val:l,size:i,filename:s", - .params = "addr size file", - .help = "save to disk virtual memory dump starting at 'addr' of size 'size'", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_memory_save, + .args_type = "val:l,size:i,filename:s,cpu:i?", + .mhandler.cmd_new = qmp_marshal_input_memsave, }, SQMP @@ -373,6 +364,7 @@ Arguments: - "val": the starting address (json-int) - "size": the memory size, in bytes (json-int) - "filename": file path (json-string) +- "cpu": virtual CPU index (json-int, optional) Example: @@ -382,17 +374,12 @@ Example: "filename": "/tmp/virtual-mem-dump" } } <- { "return": {} } -Note: Depends on the current CPU. - EQMP { .name = "pmemsave", .args_type = "val:l,size:i,filename:s", - .params = "addr size file", - .help = "save to disk physical memory dump starting at 'addr' of size 'size'", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_physical_memory_save, + .mhandler.cmd_new = qmp_marshal_input_pmemsave, }, SQMP @@ -420,10 +407,7 @@ EQMP { .name = "inject-nmi", .args_type = "", - .params = "", - .help = "", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_inject_nmi, + .mhandler.cmd_new = qmp_marshal_input_inject_nmi, }, SQMP @@ -487,10 +471,7 @@ EQMP { .name = "migrate_cancel", .args_type = "", - .params = "", - .help = "cancel the current VM migration", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate_cancel, + .mhandler.cmd_new = qmp_marshal_input_migrate_cancel, }, SQMP @@ -511,10 +492,7 @@ EQMP { .name = "migrate_set_speed", .args_type = "value:o", - .params = "value", - .help = "set maximum speed (in bytes) for migrations", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate_set_speed, + .mhandler.cmd_new = qmp_marshal_input_migrate_set_speed, }, SQMP @@ -537,10 +515,7 @@ EQMP { .name = "migrate_set_downtime", .args_type = "value:T", - .params = "value", - .help = "set maximum tolerated downtime (in seconds) for migrations", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_migrate_set_downtime, + .mhandler.cmd_new = qmp_marshal_input_migrate_set_downtime, }, SQMP @@ -658,10 +633,7 @@ EQMP { .name = "block_resize", .args_type = "device:B,size:o", - .params = "device size", - .help = "resize a block image", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_resize, + .mhandler.cmd_new = qmp_marshal_input_block_resize, }, SQMP @@ -684,10 +656,8 @@ EQMP { .name = "blockdev-snapshot-sync", - .args_type = "device:B,snapshot-file:s?,format:s?", - .params = "device [new-image-file] [format]", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_snapshot_blkdev, + .args_type = "device:B,snapshot-file:s,format:s?", + .mhandler.cmd_new = qmp_marshal_input_blockdev_snapshot_sync, }, SQMP @@ -719,11 +689,7 @@ EQMP { .name = "balloon", .args_type = "value:M", - .params = "target", - .help = "request VM to change its memory allocation (in MB)", - .user_print = monitor_user_noop, - .mhandler.cmd_async = do_balloon, - .flags = MONITOR_CMD_ASYNC, + .mhandler.cmd_new = qmp_marshal_input_balloon, }, SQMP @@ -746,10 +712,7 @@ EQMP { .name = "set_link", .args_type = "name:s,up:b", - .params = "name on|off", - .help = "change the link status of a network adapter", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_set_link, + .mhandler.cmd_new = qmp_marshal_input_set_link, }, SQMP @@ -825,10 +788,7 @@ EQMP { .name = "block_passwd", .args_type = "device:B,password:s", - .params = "block_passwd device password", - .help = "set the password of encrypted block devices", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_set_passwd, + .mhandler.cmd_new = qmp_marshal_input_block_passwd, }, SQMP @@ -851,6 +811,44 @@ Example: EQMP { + .name = "block_set_io_throttle", + .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", + .params = "device bps bps_rd bps_wr iops iops_rd iops_wr", + .help = "change I/O throttle limits for a block drive", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_block_set_io_throttle, + }, + +SQMP +block_set_io_throttle +------------ + +Change I/O throttle limits for a block drive. + +Arguments: + +- "device": device name (json-string) +- "bps": total throughput limit in bytes per second(json-int) +- "bps_rd": read throughput limit in bytes per second(json-int) +- "bps_wr": read throughput limit in bytes per second(json-int) +- "iops": total I/O operations per second(json-int) +- "iops_rd": read I/O operations per second(json-int) +- "iops_wr": write I/O operations per second(json-int) + +Example: + +-> { "execute": "block_set_io_throttle", "arguments": { "device": "virtio0", + "bps": "1000000", + "bps_rd": "0", + "bps_wr": "0", + "iops": "0", + "iops_rd": "0", + "iops_wr": "0" } } +<- { "return": {} } + +EQMP + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", .params = "protocol password action-if-connected", @@ -963,10 +961,7 @@ EQMP { .name = "human-monitor-command", .args_type = "command-line:s,cpu-index:i?", - .params = "", - .help = "", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_hmp_passthrough, + .mhandler.cmd_new = qmp_marshal_input_human_monitor_command, }, SQMP @@ -1152,6 +1147,13 @@ Each json-object contain the following: "tftp", "vdi", "vmdk", "vpc", "vvfat" - "backing_file": backing file name (json-string, optional) - "encrypted": true if encrypted, false otherwise (json-bool) + - "bps": limit total bytes per second (json-int) + - "bps_rd": limit read bytes per second (json-int) + - "bps_wr": limit write bytes per second (json-int) + - "iops": limit total I/O operations per second (json-int) + - "iops_rd": limit read operations per second (json-int) + - "iops_wr": limit write operations per second (json-int) + - "io-status": I/O operation status, only present if the device supports it and the VM is configured to stop on errors. It's always reset to "ok" when the "cont" command is issued (json_string, optional) @@ -1171,7 +1173,13 @@ Example: "ro":false, "drv":"qcow2", "encrypted":false, - "file":"disks/test.img" + "file":"disks/test.img", + "bps":1000000, + "bps_rd":0, + "bps_wr":0, + "iops":1000000, + "iops_rd":0, + "iops_wr":0, }, "type":"unknown" }, @@ -2001,3 +2009,21 @@ EQMP .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_balloon, }, + + { + .name = "qom-list", + .args_type = "path:s", + .mhandler.cmd_new = qmp_marshal_input_qom_list, + }, + + { + .name = "qom-set", + .args_type = "path:s,property:s,opts:O", + .mhandler.cmd_new = qmp_qom_set, + }, + + { + .name = "qom-get", + .args_type = "path:s,property:s", + .mhandler.cmd_new = qmp_qom_get, + }, @@ -16,6 +16,9 @@ #include "qmp-commands.h" #include "kvm.h" #include "arch_init.h" +#include "hw/qdev.h" +#include "qapi/qmp-input-visitor.h" +#include "qapi/qmp-output-visitor.h" NameInfo *qmp_query_name(Error **errp) { @@ -117,3 +120,130 @@ SpiceInfo *qmp_query_spice(Error **errp) return NULL; }; #endif + +static void iostatus_bdrv_it(void *opaque, BlockDriverState *bs) +{ + bdrv_iostatus_reset(bs); +} + +static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs) +{ + Error **err = opaque; + + if (!error_is_set(err) && bdrv_key_required(bs)) { + error_set(err, QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs)); + } +} + +void qmp_cont(Error **errp) +{ + Error *local_err = NULL; + + if (runstate_check(RUN_STATE_INMIGRATE)) { + error_set(errp, QERR_MIGRATION_EXPECTED); + return; + } else if (runstate_check(RUN_STATE_INTERNAL_ERROR) || + runstate_check(RUN_STATE_SHUTDOWN)) { + error_set(errp, QERR_RESET_REQUIRED); + return; + } + + bdrv_iterate(iostatus_bdrv_it, NULL); + bdrv_iterate(encrypted_bdrv_it, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + vm_start(); +} + +DevicePropertyInfoList *qmp_qom_list(const char *path, Error **errp) +{ + DeviceState *dev; + bool ambiguous = false; + DevicePropertyInfoList *props = NULL; + DeviceProperty *prop; + + dev = qdev_resolve_path(path, &ambiguous); + if (dev == NULL) { + error_set(errp, QERR_DEVICE_NOT_FOUND, path); + return NULL; + } + + QTAILQ_FOREACH(prop, &dev->properties, node) { + DevicePropertyInfoList *entry = g_malloc0(sizeof(*entry)); + + entry->value = g_malloc0(sizeof(DevicePropertyInfo)); + entry->next = props; + props = entry; + + entry->value->name = g_strdup(prop->name); + entry->value->type = g_strdup(prop->type); + } + + return props; +} + +/* FIXME: teach qapi about how to pass through Visitors */ +int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret) +{ + const char *path = qdict_get_str(qdict, "path"); + const char *property = qdict_get_str(qdict, "property"); + QObject *value = qdict_get(qdict, "value"); + Error *local_err = NULL; + QmpInputVisitor *mi; + DeviceState *dev; + + dev = qdev_resolve_path(path, NULL); + if (!dev) { + error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); + goto out; + } + + mi = qmp_input_visitor_new(value); + qdev_property_set(dev, qmp_input_get_visitor(mi), property, &local_err); + + qmp_input_visitor_cleanup(mi); + +out: + if (local_err) { + qerror_report_err(local_err); + error_free(local_err); + return -1; + } + + return 0; +} + +int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret) +{ + const char *path = qdict_get_str(qdict, "path"); + const char *property = qdict_get_str(qdict, "property"); + Error *local_err = NULL; + QmpOutputVisitor *mo; + DeviceState *dev; + + dev = qdev_resolve_path(path, NULL); + if (!dev) { + error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); + goto out; + } + + mo = qmp_output_visitor_new(); + qdev_property_get(dev, qmp_output_get_visitor(mo), property, &local_err); + if (!local_err) { + *ret = qmp_output_get_qobject(mo); + } + + qmp_output_visitor_cleanup(mo); + +out: + if (local_err) { + qerror_report_err(local_err); + error_free(local_err); + return -1; + } + + return 0; +} @@ -235,6 +235,9 @@ static int stdio_pclose(void *opaque) QEMUFileStdio *s = opaque; int ret; ret = pclose(s->stdio_file); + if (ret == -1) { + ret = -errno; + } g_free(s); return ret; } @@ -242,9 +245,12 @@ static int stdio_pclose(void *opaque) static int stdio_fclose(void *opaque) { QEMUFileStdio *s = opaque; - fclose(s->stdio_file); + int ret = 0; + if (fclose(s->stdio_file) == EOF) { + ret = -errno; + } g_free(s); - return 0; + return ret; } QEMUFile *qemu_popen(FILE *stdio_file, const char *mode) @@ -436,6 +442,22 @@ void qemu_file_set_error(QEMUFile *f, int ret) f->last_error = ret; } +/** Sets last_error conditionally + * + * Sets last_error only if ret is negative _and_ no error + * was set before. + */ +static void qemu_file_set_if_error(QEMUFile *f, int ret) +{ + if (ret < 0 && !f->last_error) { + qemu_file_set_error(f, ret); + } +} + +/** Flushes QEMUFile buffer + * + * In case of error, last_error is set. + */ void qemu_fflush(QEMUFile *f) { if (!f->put_buffer) @@ -448,7 +470,7 @@ void qemu_fflush(QEMUFile *f) if (len > 0) f->buf_offset += f->buf_index; else - f->last_error = -EINVAL; + qemu_file_set_error(f, -EINVAL); f->buf_index = 0; } } @@ -479,15 +501,44 @@ static void qemu_fill_buffer(QEMUFile *f) } else if (len == 0) { f->last_error = -EIO; } else if (len != -EAGAIN) - f->last_error = len; + qemu_file_set_error(f, len); } -int qemu_fclose(QEMUFile *f) +/** Calls close function and set last_error if needed + * + * Internal function. qemu_fflush() must be called before this. + * + * Returns f->close() return value, or 0 if close function is not set. + */ +static int qemu_close(QEMUFile *f) { int ret = 0; - qemu_fflush(f); - if (f->close) + if (f->close) { ret = f->close(f->opaque); + qemu_file_set_if_error(f, ret); + } + return ret; +} + +/** Closes the file + * + * Returns negative error value if any error happened on previous operations or + * while closing the file. Returns 0 or positive number on success. + * + * The meaning of return value on success depends on the specific backend + * being used. + */ +int qemu_fclose(QEMUFile *f) +{ + int ret; + qemu_fflush(f); + ret = qemu_close(f); + /* If any error was spotted before closing, we should report it + * instead of the close() return value. + */ + if (f->last_error) { + ret = f->last_error; + } g_free(f); return ret; } @@ -1552,7 +1603,7 @@ int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable, } /* - * this funtion has three return values: + * this function has three return values: * negative: there was one error, and we have -errno. * 0 : We haven't finished, caller have to go again * 1 : We have finished, we can go to complete phase @@ -1951,7 +2002,7 @@ void do_savevm(Monitor *mon, const QDict *qdict) int ret; QEMUFile *f; int saved_vm_running; - uint32_t vm_state_size; + uint64_t vm_state_size; #ifdef _WIN32 struct _timeb tb; struct tm *ptm; @@ -2104,7 +2155,7 @@ int load_vmstate(const char *name) } /* Flush all IO requests so they don't interfere with the new state. */ - qemu_aio_flush(); + bdrv_drain_all(); bs = NULL; while ((bs = bdrv_next(bs))) { diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 7a71324f6a..8850a5f436 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -859,7 +859,7 @@ sub annotate_values { $av_preprocessor = 0; } - } elsif ($cur =~ /^(\(\s*$Type\s*)\)/) { + } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') { print "CAST($1)\n" if ($dbg_values > 1); push(@av_paren_type, $type); $type = 'C'; @@ -1901,13 +1901,13 @@ sub process { # printk should use KERN_* levels. Note that follow on printk's on the # same line do not need a level, so we use the current block context # to try and find and validate the current printk. In summary the current -# printk includes all preceeding printk's which have no newline on the end. +# printk includes all preceding printk's which have no newline on the end. # we assume the first bad printk is the one to report. if ($line =~ /\bprintk\((?!KERN_)\s*"/) { my $ok = 0; for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) { #print "CHECK<$lines[$ln - 1]\n"; - # we have a preceeding printk if it ends + # we have a preceding printk if it ends # with "\n" ignore it, else it is to blame if ($lines[$ln - 1] =~ m{\bprintk\(}) { if ($rawlines[$ln - 1] !~ m{\\n"}) { @@ -1999,7 +1999,7 @@ sub process { for (my $n = 0; $n < $#elements; $n += 2) { $off += length($elements[$n]); - # Pick up the preceeding and succeeding characters. + # Pick up the preceding and succeeding characters. my $ca = substr($opline, 0, $off); my $cc = ''; if (length($opline) >= ($off + length($elements[$n + 1]))) { diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index f7def16662..54d1f5d659 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -405,6 +405,7 @@ except os.error, e: exprs = parse_schema(sys.stdin) commands = filter(lambda expr: expr.has_key('command'), exprs) +commands = filter(lambda expr: not expr.has_key('gen'), commands) if dispatch_type == "sync": fdecl = open(h_file, 'w') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index f64d84c39e..267cb49b13 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -238,6 +238,7 @@ fdecl.write(mcgen(''' guard=guardname(h_file))) exprs = parse_schema(sys.stdin) +exprs = filter(lambda expr: not expr.has_key('gen'), exprs) for expr in exprs: ret = "\n" diff --git a/scripts/qapi.py b/scripts/qapi.py index 52999763ee..6e05469e6d 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -200,6 +200,7 @@ def basename(filename): return filename.split("/")[-1] def guardname(filename): - if filename.startswith('./'): - filename = filename[2:] - return filename.replace("/", "_").replace("-", "_").split(".")[0].upper() + '_H' + guard = basename(filename).rsplit(".", 1)[0] + for substr in [".", " ", "-"]: + guard = guard.replace(substr, "_") + return guard.upper() + '_H' diff --git a/spice-qemu-char.c b/spice-qemu-char.c index ac522022cc..7e8eaa9fd8 100644 --- a/spice-qemu-char.c +++ b/spice-qemu-char.c @@ -69,11 +69,40 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len) return bytes; } +static void vmc_state(SpiceCharDeviceInstance *sin, int connected) +{ + SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin); + +#if SPICE_SERVER_VERSION < 0x000901 + /* + * spice-server calls the state callback for the agent channel when the + * spice client connects / disconnects. Given that not the client but + * the server is doing the parsing of the messages this is wrong as the + * server is still listening. Worse, this causes the parser in the server + * to go out of sync, so we ignore state calls for subtype vdagent + * spicevmc chardevs. For the full story see: + * http://lists.freedesktop.org/archives/spice-devel/2011-July/004837.html + */ + if (strcmp(sin->subtype, "vdagent") == 0) { + return; + } +#endif + + if ((scd->chr->opened && connected) || + (!scd->chr->opened && !connected)) { + return; + } + + qemu_chr_be_event(scd->chr, + connected ? CHR_EVENT_OPENED : CHR_EVENT_CLOSED); +} + static SpiceCharDeviceInterface vmc_interface = { .base.type = SPICE_INTERFACE_CHAR_DEVICE, .base.description = "spice virtual channel char device", .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR, .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR, + .state = vmc_state, .write = vmc_write, .read = vmc_read, }; @@ -197,7 +226,12 @@ int qemu_chr_open_spice(QemuOpts *opts, CharDriverState **_chr) chr->chr_guest_open = spice_chr_guest_open; chr->chr_guest_close = spice_chr_guest_close; - qemu_chr_generic_open(chr); +#if SPICE_SERVER_VERSION < 0x000901 + /* See comment in vmc_state() */ + if (strcmp(subtype, "vdagent") == 0) { + qemu_chr_generic_open(chr); + } +#endif *_chr = chr; return 0; @@ -148,7 +148,7 @@ void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict); /* pcie aer error injection */ void pcie_aer_inject_error_print(Monitor *mon, const QObject *data); -int do_pcie_aer_inejct_error(Monitor *mon, +int do_pcie_aer_inject_error(Monitor *mon, const QDict *qdict, QObject **ret_data); /* serial ports */ diff --git a/target-alpha/STATUS b/target-alpha/STATUS index 353d543c4a..742e370b90 100644 --- a/target-alpha/STATUS +++ b/target-alpha/STATUS @@ -18,7 +18,7 @@ Linux user mode emulation status: a few programs start to run. Most crash at a certain point, dereferencing a NULL pointer. It seems that the UNIQUE register is not initialized properly. It may appear that old executables, not relying on TLS support, run but -this is to be prooved... +this is to be proved... Full system emulation status: * Alpha PALCode emulation is in a very early stage and is not sufficient diff --git a/target-arm/helper.c b/target-arm/helper.c index 97af4d0bba..65f4fbf98e 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -53,7 +53,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id) env->cp15.c0_cpuid = id; switch (id) { case ARM_CPUID_ARM926: - set_feature(env, ARM_FEATURE_V4T); set_feature(env, ARM_FEATURE_V5); set_feature(env, ARM_FEATURE_VFP); env->vfp.xregs[ARM_VFP_FPSID] = 0x41011090; @@ -61,14 +60,12 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id) env->cp15.c1_sys = 0x00090078; break; case ARM_CPUID_ARM946: - set_feature(env, ARM_FEATURE_V4T); set_feature(env, ARM_FEATURE_V5); set_feature(env, ARM_FEATURE_MPU); env->cp15.c0_cachetype = 0x0f004006; env->cp15.c1_sys = 0x00000078; break; case ARM_CPUID_ARM1026: - set_feature(env, ARM_FEATURE_V4T); set_feature(env, ARM_FEATURE_V5); set_feature(env, ARM_FEATURE_VFP); set_feature(env, ARM_FEATURE_AUXCR); @@ -85,11 +82,8 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id) * older core than plain "arm1136". In particular this does not * have the v6K features. */ - set_feature(env, ARM_FEATURE_V4T); - set_feature(env, ARM_FEATURE_V5); set_feature(env, ARM_FEATURE_V6); set_feature(env, ARM_FEATURE_VFP); - set_feature(env, ARM_FEATURE_AUXCR); /* These ID register values are correct for 1136 but may be wrong * for 1136_r2 (in particular r0p2 does not actually implement most * of the ID registers). @@ -103,12 +97,8 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id) env->cp15.c1_sys = 0x00050078; break; case ARM_CPUID_ARM1176: - set_feature(env, ARM_FEATURE_V4T); - set_feature(env, ARM_FEATURE_V5); - set_feature(env, ARM_FEATURE_V6); set_feature(env, ARM_FEATURE_V6K); set_feature(env, ARM_FEATURE_VFP); - set_feature(env, ARM_FEATURE_AUXCR); set_feature(env, ARM_FEATURE_VAPA); env->vfp.xregs[ARM_VFP_FPSID] = 0x410120b5; env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111; @@ -119,12 +109,8 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id) env->cp15.c1_sys = 0x00050078; break; case ARM_CPUID_ARM11MPCORE: - set_feature(env, ARM_FEATURE_V4T); - set_feature(env, ARM_FEATURE_V5); - set_feature(env, ARM_FEATURE_V6); set_feature(env, ARM_FEATURE_V6K); set_feature(env, ARM_FEATURE_VFP); - set_feature(env, ARM_FEATURE_AUXCR); set_feature(env, ARM_FEATURE_VAPA); env->vfp.xregs[ARM_VFP_FPSID] = 0x410120b4; env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111; @@ -134,14 +120,7 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id) env->cp15.c0_cachetype = 0x1dd20d2; break; case ARM_CPUID_CORTEXA8: - set_feature(env, ARM_FEATURE_V4T); - set_feature(env, ARM_FEATURE_V5); - set_feature(env, ARM_FEATURE_V6); - set_feature(env, ARM_FEATURE_V6K); set_feature(env, ARM_FEATURE_V7); - set_feature(env, ARM_FEATURE_AUXCR); - set_feature(env, ARM_FEATURE_THUMB2); - set_feature(env, ARM_FEATURE_VFP); set_feature(env, ARM_FEATURE_VFP3); set_feature(env, ARM_FEATURE_NEON); set_feature(env, ARM_FEATURE_THUMB2EE); @@ -158,14 +137,7 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id) env->cp15.c1_sys = 0x00c50078; break; case ARM_CPUID_CORTEXA9: - set_feature(env, ARM_FEATURE_V4T); - set_feature(env, ARM_FEATURE_V5); - set_feature(env, ARM_FEATURE_V6); - set_feature(env, ARM_FEATURE_V6K); set_feature(env, ARM_FEATURE_V7); - set_feature(env, ARM_FEATURE_AUXCR); - set_feature(env, ARM_FEATURE_THUMB2); - set_feature(env, ARM_FEATURE_VFP); set_feature(env, ARM_FEATURE_VFP3); set_feature(env, ARM_FEATURE_VFP_FP16); set_feature(env, ARM_FEATURE_NEON); @@ -187,23 +159,11 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id) env->cp15.c1_sys = 0x00c50078; break; case ARM_CPUID_CORTEXM3: - set_feature(env, ARM_FEATURE_V4T); - set_feature(env, ARM_FEATURE_V5); - set_feature(env, ARM_FEATURE_V6); - set_feature(env, ARM_FEATURE_THUMB2); set_feature(env, ARM_FEATURE_V7); set_feature(env, ARM_FEATURE_M); - set_feature(env, ARM_FEATURE_THUMB_DIV); break; case ARM_CPUID_ANY: /* For userspace emulation. */ - set_feature(env, ARM_FEATURE_V4T); - set_feature(env, ARM_FEATURE_V5); - set_feature(env, ARM_FEATURE_V6); - set_feature(env, ARM_FEATURE_V6K); set_feature(env, ARM_FEATURE_V7); - set_feature(env, ARM_FEATURE_THUMB2); - set_feature(env, ARM_FEATURE_VFP); - set_feature(env, ARM_FEATURE_VFP3); set_feature(env, ARM_FEATURE_VFP4); set_feature(env, ARM_FEATURE_VFP_FP16); set_feature(env, ARM_FEATURE_NEON); @@ -226,7 +186,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id) case ARM_CPUID_PXA260: case ARM_CPUID_PXA261: case ARM_CPUID_PXA262: - set_feature(env, ARM_FEATURE_V4T); set_feature(env, ARM_FEATURE_V5); set_feature(env, ARM_FEATURE_XSCALE); /* JTAG_ID is ((id << 28) | 0x09265013) */ @@ -239,7 +198,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id) case ARM_CPUID_PXA270_B1: case ARM_CPUID_PXA270_C0: case ARM_CPUID_PXA270_C5: - set_feature(env, ARM_FEATURE_V4T); set_feature(env, ARM_FEATURE_V5); set_feature(env, ARM_FEATURE_XSCALE); /* JTAG_ID is ((id << 28) | 0x09265013) */ @@ -261,10 +219,37 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id) /* Some features automatically imply others: */ if (arm_feature(env, ARM_FEATURE_V7)) { set_feature(env, ARM_FEATURE_VAPA); + set_feature(env, ARM_FEATURE_THUMB2); + if (!arm_feature(env, ARM_FEATURE_M)) { + set_feature(env, ARM_FEATURE_V6K); + } else { + set_feature(env, ARM_FEATURE_V6); + } + } + if (arm_feature(env, ARM_FEATURE_V6K)) { + set_feature(env, ARM_FEATURE_V6); + } + if (arm_feature(env, ARM_FEATURE_V6)) { + set_feature(env, ARM_FEATURE_V5); + if (!arm_feature(env, ARM_FEATURE_M)) { + set_feature(env, ARM_FEATURE_AUXCR); + } + } + if (arm_feature(env, ARM_FEATURE_V5)) { + set_feature(env, ARM_FEATURE_V4T); + } + if (arm_feature(env, ARM_FEATURE_M)) { + set_feature(env, ARM_FEATURE_THUMB_DIV); } if (arm_feature(env, ARM_FEATURE_ARM_DIV)) { set_feature(env, ARM_FEATURE_THUMB_DIV); } + if (arm_feature(env, ARM_FEATURE_VFP4)) { + set_feature(env, ARM_FEATURE_VFP3); + } + if (arm_feature(env, ARM_FEATURE_VFP3)) { + set_feature(env, ARM_FEATURE_VFP); + } } void cpu_reset(CPUARMState *env) @@ -390,7 +375,7 @@ CPUARMState *cpu_arm_init(const char *cpu_model) return NULL; env = g_malloc0(sizeof(CPUARMState)); cpu_exec_init(env); - if (!inited) { + if (tcg_enabled() && !inited) { inited = 1; arm_translate_init(); } @@ -951,13 +936,14 @@ void do_interrupt(CPUARMState *env) /* Check section/page access permissions. Returns the page protection flags, or zero if the access is not permitted. */ -static inline int check_ap(CPUState *env, int ap, int domain, int access_type, - int is_user) +static inline int check_ap(CPUState *env, int ap, int domain_prot, + int access_type, int is_user) { int prot_ro; - if (domain == 3) + if (domain_prot == 3) { return PAGE_READ | PAGE_WRITE; + } if (access_type == 1) prot_ro = 0; @@ -1023,6 +1009,7 @@ static int get_phys_addr_v5(CPUState *env, uint32_t address, int access_type, int type; int ap; int domain; + int domain_prot; uint32_t phys_addr; /* Pagetable walk. */ @@ -1030,13 +1017,14 @@ static int get_phys_addr_v5(CPUState *env, uint32_t address, int access_type, table = get_level1_table_address(env, address); desc = ldl_phys(table); type = (desc & 3); - domain = (env->cp15.c3 >> ((desc >> 4) & 0x1e)) & 3; + domain = (desc >> 5) & 0x0f; + domain_prot = (env->cp15.c3 >> (domain * 2)) & 3; if (type == 0) { /* Section translation fault. */ code = 5; goto do_fault; } - if (domain == 0 || domain == 2) { + if (domain_prot == 0 || domain_prot == 2) { if (type == 2) code = 9; /* Section domain fault. */ else @@ -1094,7 +1082,7 @@ static int get_phys_addr_v5(CPUState *env, uint32_t address, int access_type, } code = 15; } - *prot = check_ap(env, ap, domain, access_type, is_user); + *prot = check_ap(env, ap, domain_prot, access_type, is_user); if (!*prot) { /* Access permission fault. */ goto do_fault; @@ -1117,6 +1105,7 @@ static int get_phys_addr_v6(CPUState *env, uint32_t address, int access_type, int type; int ap; int domain; + int domain_prot; uint32_t phys_addr; /* Pagetable walk. */ @@ -1134,10 +1123,10 @@ static int get_phys_addr_v6(CPUState *env, uint32_t address, int access_type, domain = 0; } else { /* Section or page. */ - domain = (desc >> 4) & 0x1e; + domain = (desc >> 5) & 0x0f; } - domain = (env->cp15.c3 >> domain) & 3; - if (domain == 0 || domain == 2) { + domain_prot = (env->cp15.c3 >> (domain * 2)) & 3; + if (domain_prot == 0 || domain_prot == 2) { if (type == 2) code = 9; /* Section domain fault. */ else @@ -1182,7 +1171,7 @@ static int get_phys_addr_v6(CPUState *env, uint32_t address, int access_type, } code = 15; } - if (domain == 3) { + if (domain_prot == 3) { *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; } else { if (xn && access_type == 2) @@ -1194,7 +1183,7 @@ static int get_phys_addr_v6(CPUState *env, uint32_t address, int access_type, code = (code == 15) ? 6 : 3; goto do_fault; } - *prot = check_ap(env, ap, domain, access_type, is_user); + *prot = check_ap(env, ap, domain_prot, access_type, is_user); if (!*prot) { /* Access permission fault. */ goto do_fault; diff --git a/target-arm/translate.c b/target-arm/translate.c index 0f35b60946..f91553a48a 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -9025,14 +9025,16 @@ static int disas_thumb2_insn(CPUState *env, DisasContext *s, uint16_t insn_hw1) goto illegal_op; } if (rn == 15) { - /* UNPREDICTABLE or unallocated hint */ + /* UNPREDICTABLE, unallocated hint or + * PLD/PLDW/PLI (literal) + */ return 0; } if (op1 & 1) { - return 0; /* PLD* or unallocated hint */ + return 0; /* PLD/PLDW/PLI or unallocated hint */ } if ((op2 == 0) || ((op2 & 0x3c) == 0x30)) { - return 0; /* PLD* or unallocated hint */ + return 0; /* PLD/PLDW/PLI or unallocated hint */ } /* UNDEF space, or an UNPREDICTABLE */ return 1; diff --git a/target-cris/cpu.h b/target-cris/cpu.h index 8ae0ce3ef3..453afbb66e 100644 --- a/target-cris/cpu.h +++ b/target-cris/cpu.h @@ -67,6 +67,8 @@ #define Q_FLAG 0x80000000 #define M_FLAG 0x40000000 #define PFIX_FLAG 0x800 /* CRISv10 Only. */ +#define F_FLAG_V10 0x400 +#define P_FLAG_V10 0x200 #define S_FLAG 0x200 #define R_FLAG 0x100 #define P_FLAG 0x80 diff --git a/target-cris/helper.c b/target-cris/helper.c index 75f0035e6e..5bc6d810cb 100644 --- a/target-cris/helper.c +++ b/target-cris/helper.c @@ -157,6 +157,7 @@ static void do_interruptv10(CPUState *env) /* Now that we are in kernel mode, load the handlers address. */ env->pc = ldl_code(env->pregs[PR_EBP] + ex_vec * 4); env->locked_irq = 1; + env->pregs[PR_CCS] |= F_FLAG_V10; /* set F. */ qemu_log_mask(CPU_LOG_INT, "%s isr=%x vec=%x ccs=%x pid=%d erp=%x\n", __func__, env->pc, ex_vec, diff --git a/target-cris/translate_v10.c b/target-cris/translate_v10.c index 637ac2084a..95053b64fb 100644 --- a/target-cris/translate_v10.c +++ b/target-cris/translate_v10.c @@ -62,6 +62,65 @@ static inline void cris_illegal_insn(DisasContext *dc) t_gen_raise_exception(EXCP_BREAK); } +static void gen_store_v10_conditional(DisasContext *dc, TCGv addr, TCGv val, + unsigned int size, int mem_index) +{ + int l1 = gen_new_label(); + TCGv taddr = tcg_temp_local_new(); + TCGv tval = tcg_temp_local_new(); + TCGv t1 = tcg_temp_local_new(); + dc->postinc = 0; + cris_evaluate_flags(dc); + + tcg_gen_mov_tl(taddr, addr); + tcg_gen_mov_tl(tval, val); + + /* Store only if F flag isn't set */ + tcg_gen_andi_tl(t1, cpu_PR[PR_CCS], F_FLAG_V10); + tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1); + if (size == 1) { + tcg_gen_qemu_st8(tval, taddr, mem_index); + } else if (size == 2) { + tcg_gen_qemu_st16(tval, taddr, mem_index); + } else { + tcg_gen_qemu_st32(tval, taddr, mem_index); + } + gen_set_label(l1); + tcg_gen_shri_tl(t1, t1, 1); /* shift F to P position */ + tcg_gen_or_tl(cpu_PR[PR_CCS], cpu_PR[PR_CCS], t1); /*P=F*/ + tcg_temp_free(t1); + tcg_temp_free(tval); + tcg_temp_free(taddr); +} + +static void gen_store_v10(DisasContext *dc, TCGv addr, TCGv val, + unsigned int size) +{ + int mem_index = cpu_mmu_index(dc->env); + + /* If we get a fault on a delayslot we must keep the jmp state in + the cpu-state to be able to re-execute the jmp. */ + if (dc->delayed_branch == 1) { + cris_store_direct_jmp(dc); + } + + /* Conditional writes. We only support the kind were X is known + at translation time. */ + if (dc->flagx_known && dc->flags_x) { + gen_store_v10_conditional(dc, addr, val, size, mem_index); + return; + } + + if (size == 1) { + tcg_gen_qemu_st8(val, addr, mem_index); + } else if (size == 2) { + tcg_gen_qemu_st16(val, addr, mem_index); + } else { + tcg_gen_qemu_st32(val, addr, mem_index); + } +} + + /* Prefix flag and register are used to handle the more complex addressing modes. */ static void cris_set_prefix(DisasContext *dc) @@ -313,7 +372,8 @@ static unsigned int dec10_setclrf(DisasContext *dc) if (set) { tcg_gen_ori_tl(cpu_PR[PR_CCS], cpu_PR[PR_CCS], flags); } else { - tcg_gen_andi_tl(cpu_PR[PR_CCS], cpu_PR[PR_CCS], ~flags); + tcg_gen_andi_tl(cpu_PR[PR_CCS], cpu_PR[PR_CCS], + ~(flags|F_FLAG_V10|P_FLAG_V10)); } dc->flags_uptodate = 1; @@ -723,7 +783,7 @@ static unsigned int dec10_ind_move_r_m(DisasContext *dc, unsigned int size) LOG_DIS("move.%d $r%d, [$r%d]\n", dc->size, dc->src, dc->dst); addr = tcg_temp_new(); crisv10_prepare_memaddr(dc, addr, size); - gen_store(dc, addr, cpu_R[dc->dst], size); + gen_store_v10(dc, addr, cpu_R[dc->dst], size); insn_len += crisv10_post_memaddr(dc, size); return insn_len; @@ -767,10 +827,10 @@ static unsigned int dec10_ind_move_pr_m(DisasContext *dc) t0 = tcg_temp_new(); cris_evaluate_flags(dc); tcg_gen_andi_tl(t0, cpu_PR[PR_CCS], ~PFIX_FLAG); - gen_store(dc, addr, t0, size); + gen_store_v10(dc, addr, t0, size); tcg_temp_free(t0); } else { - gen_store(dc, addr, cpu_PR[dc->dst], size); + gen_store_v10(dc, addr, cpu_PR[dc->dst], size); } t0 = tcg_temp_new(); insn_len += crisv10_post_memaddr(dc, size); @@ -793,9 +853,9 @@ static void dec10_movem_r_m(DisasContext *dc) tcg_gen_mov_tl(t0, addr); for (i = dc->dst; i >= 0; i--) { if ((pfix && dc->mode == CRISV10_MODE_AUTOINC) && dc->src == i) { - gen_store(dc, addr, t0, 4); + gen_store_v10(dc, addr, t0, 4); } else { - gen_store(dc, addr, cpu_R[i], 4); + gen_store_v10(dc, addr, cpu_R[i], 4); } tcg_gen_addi_tl(addr, addr, 4); } diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c index 21e589675c..0b3af9060c 100644 --- a/target-i386/cpuid.c +++ b/target-i386/cpuid.c @@ -107,14 +107,33 @@ void host_cpuid(uint32_t function, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { #if defined(CONFIG_KVM) + uint32_t vec[4]; + +#ifdef __x86_64__ + asm volatile("cpuid" + : "=a"(vec[0]), "=b"(vec[1]), + "=c"(vec[2]), "=d"(vec[3]) + : "0"(function), "c"(count) : "cc"); +#else + asm volatile("pusha \n\t" + "cpuid \n\t" + "mov %%eax, 0(%2) \n\t" + "mov %%ebx, 4(%2) \n\t" + "mov %%ecx, 8(%2) \n\t" + "mov %%edx, 12(%2) \n\t" + "popa" + : : "a"(function), "c"(count), "S"(vec) + : "memory", "cc"); +#endif + if (eax) - *eax = kvm_arch_get_supported_cpuid(kvm_state, function, count, R_EAX); + *eax = vec[0]; if (ebx) - *ebx = kvm_arch_get_supported_cpuid(kvm_state, function, count, R_EBX); + *ebx = vec[1]; if (ecx) - *ecx = kvm_arch_get_supported_cpuid(kvm_state, function, count, R_ECX); + *ecx = vec[2]; if (edx) - *edx = kvm_arch_get_supported_cpuid(kvm_state, function, count, R_EDX); + *edx = vec[3]; #endif } @@ -692,7 +711,7 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) tsc_freq = strtosz_suffix_unit(val, &err, STRTOSZ_DEFSUFFIX_B, 1000); - if (!*val || *err) { + if (tsc_freq < 0 || *err) { fprintf(stderr, "bad numerical value %s\n", val); goto error; } diff --git a/target-i386/translate.c b/target-i386/translate.c index 1ef8d16ac7..8321bf39a5 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -4870,20 +4870,23 @@ static target_ulong disas_insn(DisasContext *s, target_ulong pc_start) tcg_gen_sub_tl(t2, cpu_regs[R_EAX], t0); gen_extu(ot, t2); tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, label1); + label2 = gen_new_label(); if (mod == 3) { - label2 = gen_new_label(); gen_op_mov_reg_v(ot, R_EAX, t0); tcg_gen_br(label2); gen_set_label(label1); gen_op_mov_reg_v(ot, rm, t1); - gen_set_label(label2); } else { - tcg_gen_mov_tl(t1, t0); + /* perform no-op store cycle like physical cpu; must be + before changing accumulator to ensure idempotency if + the store faults and the instruction is restarted */ + gen_op_st_v(ot + s->mem_index, t0, a0); gen_op_mov_reg_v(ot, R_EAX, t0); + tcg_gen_br(label2); gen_set_label(label1); - /* always store */ gen_op_st_v(ot + s->mem_index, t1, a0); } + gen_set_label(label2); tcg_gen_mov_tl(cpu_cc_src, t0); tcg_gen_mov_tl(cpu_cc_dst, t2); s->cc_op = CC_OP_SUBB + ot; diff --git a/target-microblaze/cpu.h b/target-microblaze/cpu.h index 35302863cb..1a307e312d 100644 --- a/target-microblaze/cpu.h +++ b/target-microblaze/cpu.h @@ -243,7 +243,7 @@ typedef struct CPUMBState { #define DRTE_FLAG (1 << 17) #define DRTB_FLAG (1 << 18) #define D_FLAG (1 << 19) /* Bit in ESR. */ -/* TB dependant CPUState. */ +/* TB dependent CPUState. */ #define IFLAGS_TB_MASK (D_FLAG | IMM_FLAG | DRTI_FLAG | DRTE_FLAG | DRTB_FLAG) uint32_t iflags; diff --git a/target-microblaze/translate.c b/target-microblaze/translate.c index 366fd3e607..d7f513d34d 100644 --- a/target-microblaze/translate.c +++ b/target-microblaze/translate.c @@ -120,7 +120,7 @@ static inline int sign_extend(unsigned int val, unsigned int width) static inline void t_sync_flags(DisasContext *dc) { - /* Synch the tb dependant flags between translator and runtime. */ + /* Synch the tb dependent flags between translator and runtime. */ if (dc->tb_flags != dc->synced_flags) { tcg_gen_movi_tl(env_iflags, dc->tb_flags); dc->synced_flags = dc->tb_flags; @@ -1122,7 +1122,7 @@ static void dec_store(DisasContext *dc) if ((dc->env->pvr.regs[2] & PVR2_UNALIGNED_EXC_MASK) && size > 1) { tcg_gen_movi_tl(cpu_SR[SR_PC], dc->pc); /* FIXME: if the alignment is wrong, we should restore the value - * in memory. One possible way to acheive this is to probe + * in memory. One possible way to achieve this is to probe * the MMU prior to the memaccess, thay way we could put * the alignment checks in between the probe and the mem * access. diff --git a/target-mips/cpu.h b/target-mips/cpu.h index 79e25583ff..71cb4e8b02 100644 --- a/target-mips/cpu.h +++ b/target-mips/cpu.h @@ -678,7 +678,7 @@ static inline int mips_vpe_active(CPUState *env) if (!(env->mvp->CP0_MVPControl & (1 << CP0MVPCo_EVP))) { active = 0; } - /* Check that the VPE is actived. */ + /* Check that the VPE is activated. */ if (!(env->CP0_VPEConf0 & (1 << CP0VPEC0_VPA))) { active = 0; } diff --git a/target-mips/helper.c b/target-mips/helper.c index 1c58e0cc21..722561695c 100644 --- a/target-mips/helper.c +++ b/target-mips/helper.c @@ -497,7 +497,7 @@ void do_interrupt (CPUState *env) } } else { /* For VEIC mode, the external interrupt controller feeds the - vector throught the CP0Cause IP lines. */ + vector through the CP0Cause IP lines. */ vector = pending; } offset = 0x200 + vector * spacing; diff --git a/target-mips/machine.c b/target-mips/machine.c index be72b36de6..a506ee0b24 100644 --- a/target-mips/machine.c +++ b/target-mips/machine.c @@ -302,7 +302,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) for (i = 0; i < MIPS_FPU_MAX; i++) load_fpu(f, &env->fpus[i]); - /* XXX: ensure compatiblity for halted bit ? */ + /* XXX: ensure compatibility for halted bit ? */ tlb_flush(env, 1); return 0; } diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h index e84108c49a..2d67d1f4b8 100644 --- a/target-ppc/cpu.h +++ b/target-ppc/cpu.h @@ -1004,7 +1004,7 @@ struct CPUPPCState { int error_code; uint32_t pending_interrupts; #if !defined(CONFIG_USER_ONLY) - /* This is the IRQ controller, which is implementation dependant + /* This is the IRQ controller, which is implementation dependent * and only relevant when emulating a complete machine. */ uint32_t irq_input_state; @@ -1024,7 +1024,7 @@ struct CPUPPCState { /* Those resources are used only in Qemu core */ target_ulong hflags; /* hflags is a MSR & HFLAGS_MASK */ - target_ulong hflags_nmsr; /* specific hflags, not comming from MSR */ + target_ulong hflags_nmsr; /* specific hflags, not coming from MSR */ int mmu_idx; /* precomputed MMU index to speed up mem accesses */ /* Power management */ diff --git a/target-ppc/mfrom_table_gen.c b/target-ppc/mfrom_table_gen.c index 4c06aa4e5e..a140ded47a 100644 --- a/target-ppc/mfrom_table_gen.c +++ b/target-ppc/mfrom_table_gen.c @@ -11,7 +11,7 @@ int main (void) printf("static const uint8_t mfrom_ROM_table[602] =\n{\n "); for (i = 0; i < 602; i++) { - /* Extremly decomposed: + /* Extremely decomposed: * -T0 / 256 * T0 = 256 * log10(10 + 1.0) + 0.5 */ diff --git a/target-ppc/op_helper.c b/target-ppc/op_helper.c index 134b0c6587..6339c9559f 100644 --- a/target-ppc/op_helper.c +++ b/target-ppc/op_helper.c @@ -1795,7 +1795,7 @@ void helper_rfsvc (void) /* 602 specific instructions */ /* mfrom is the most crazy instruction ever seen, imho ! */ /* Real implementation uses a ROM table. Do the same */ -/* Extremly decomposed: +/* Extremely decomposed: * -arg / 256 * return 256 * log10(10 + 1.0) + 0.5 */ @@ -3070,7 +3070,7 @@ static inline uint32_t word_reverse(uint32_t val) (byte_reverse(val >> 8) << 16) | (byte_reverse(val) << 24); } -#define MASKBITS 16 // Random value - to be fixed (implementation dependant) +#define MASKBITS 16 // Random value - to be fixed (implementation dependent) target_ulong helper_brinc (target_ulong arg1, target_ulong arg2) { uint32_t a, b, d, mask; diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 202c098ee0..b8893b3027 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -513,15 +513,15 @@ enum cc_op { CC_OP_ADD_64, /* overflow on add (64bit) */ CC_OP_ADDU_64, /* overflow on unsigned add (64bit) */ - CC_OP_SUB_64, /* overflow on substraction (64bit) */ - CC_OP_SUBU_64, /* overflow on unsigned substraction (64bit) */ + CC_OP_SUB_64, /* overflow on subtraction (64bit) */ + CC_OP_SUBU_64, /* overflow on unsigned subtraction (64bit) */ CC_OP_ABS_64, /* sign eval on abs (64bit) */ CC_OP_NABS_64, /* sign eval on nabs (64bit) */ CC_OP_ADD_32, /* overflow on add (32bit) */ CC_OP_ADDU_32, /* overflow on unsigned add (32bit) */ - CC_OP_SUB_32, /* overflow on substraction (32bit) */ - CC_OP_SUBU_32, /* overflow on unsigned substraction (32bit) */ + CC_OP_SUB_32, /* overflow on subtraction (32bit) */ + CC_OP_SUBU_32, /* overflow on unsigned subtraction (32bit) */ CC_OP_ABS_32, /* sign eval on abs (64bit) */ CC_OP_NABS_32, /* sign eval on nabs (64bit) */ diff --git a/target-s390x/op_helper.c b/target-s390x/op_helper.c index 137bae74a0..b8a1a8a54f 100644 --- a/target-s390x/op_helper.c +++ b/target-s390x/op_helper.c @@ -1336,7 +1336,7 @@ void HELPER(meeb)(uint32_t f1, uint32_t val) uint32_t HELPER(cebr)(uint32_t f1, uint32_t f2) { float32 v1 = env->fregs[f1].l.upper; - float32 v2 = env->fregs[f2].l.upper;; + float32 v2 = env->fregs[f2].l.upper; HELPER_LOG("%s: comparing 0x%d from f%d and 0x%d\n", __FUNCTION__, v1, f1, v2); return set_cc_f32(v1, v2); @@ -1346,7 +1346,7 @@ uint32_t HELPER(cebr)(uint32_t f1, uint32_t f2) uint32_t HELPER(cdbr)(uint32_t f1, uint32_t f2) { float64 v1 = env->fregs[f1].d; - float64 v2 = env->fregs[f2].d;; + float64 v2 = env->fregs[f2].d; HELPER_LOG("%s: comparing 0x%ld from f%d and 0x%ld\n", __FUNCTION__, v1, f1, v2); return set_cc_f64(v1, v2); diff --git a/target-sh4/helper.c b/target-sh4/helper.c index f4dda48dd1..006d1a9db8 100644 --- a/target-sh4/helper.c +++ b/target-sh4/helper.c @@ -817,7 +817,7 @@ int cpu_sh4_is_cached(CPUSH4State * env, target_ulong addr) /* * TODO : Evaluate CCR and check if the cache is on or off. * Now CCR is not in CPUSH4State, but in SH7750State. - * When you move the ccr inot CPUSH4State, the code will be + * When you move the ccr into CPUSH4State, the code will be * as follows. */ #if 0 diff --git a/target-sparc/TODO b/target-sparc/TODO index c87459f50c..b8c727e858 100644 --- a/target-sparc/TODO +++ b/target-sparc/TODO @@ -15,7 +15,7 @@ CPU common: - NPC/PC static optimisations (use JUMP_TB when possible)? (Is this obsolete?) - Synthetic instructions - - MMU model dependant on CPU model + - MMU model dependent on CPU model - Select ASI helper at translation time (on V9 only if known) - KQemu/KVM support for VM only - Hardware breakpoint/watchpoint support diff --git a/target-xtensa/helper.c b/target-xtensa/helper.c index fc85815a63..2a0cb1a562 100644 --- a/target-xtensa/helper.c +++ b/target-xtensa/helper.c @@ -273,7 +273,7 @@ static void reset_tlb_mmu_ways56(CPUState *env, entry[6][ei].vaddr = ei << 29; entry[6][ei].paddr = ei << 29; entry[6][ei].asid = 1; - entry[6][ei].attr = 2; + entry[6][ei].attr = 3; } } } diff --git a/target-xtensa/overlay_tool.h b/target-xtensa/overlay_tool.h index 9cef27d03e..df19cc96ea 100644 --- a/target-xtensa/overlay_tool.h +++ b/target-xtensa/overlay_tool.h @@ -256,7 +256,7 @@ .way_size = { \ (refill_way_size), (refill_way_size), \ (refill_way_size), (refill_way_size), \ - 4, 2, 2, 1, 1, 1, \ + 4, (way56) ? 4 : 2, (way56) ? 8 : 2, 1, 1, 1, \ }, \ .varway56 = (way56), \ .nrefillentries = (refill_way_size) * 4, \ diff --git a/tcg/arm/tcg-target.c b/tcg/arm/tcg-target.c index e05a64f75c..1d327984e0 100644 --- a/tcg/arm/tcg-target.c +++ b/tcg/arm/tcg-target.c @@ -842,6 +842,12 @@ static inline void tcg_out_st8(TCGContext *s, int cond, tcg_out_st8_12(s, cond, rd, rn, offset); } +/* The _goto case is normally between TBs within the same code buffer, + * and with the code buffer limited to 16GB we shouldn't need the long + * case. + * + * .... except to the prologue that is in its own buffer. + */ static inline void tcg_out_goto(TCGContext *s, int cond, uint32_t addr) { int32_t val; @@ -855,22 +861,20 @@ static inline void tcg_out_goto(TCGContext *s, int cond, uint32_t addr) if (val - 8 < 0x01fffffd && val - 8 > -0x01fffffd) tcg_out_b(s, cond, val); else { -#if 1 - tcg_abort(); -#else if (cond == COND_AL) { tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4); - tcg_out32(s, addr); /* XXX: This is l->u.value, can we use it? */ + tcg_out32(s, addr); } else { tcg_out_movi32(s, cond, TCG_REG_R8, val - 8); tcg_out_dat_reg(s, cond, ARITH_ADD, TCG_REG_PC, TCG_REG_PC, TCG_REG_R8, SHIFT_IMM_LSL(0)); } -#endif } } +/* The call case is mostly used for helpers - so it's not unreasonable + * for them to be beyond branch range */ static inline void tcg_out_call(TCGContext *s, uint32_t addr) { int32_t val; @@ -887,20 +891,9 @@ static inline void tcg_out_call(TCGContext *s, uint32_t addr) tcg_out_bl(s, COND_AL, val); } } else { -#if 1 - tcg_abort(); -#else - if (cond == COND_AL) { - tcg_out_dat_imm(s, cond, ARITH_ADD, TCG_REG_R14, TCG_REG_PC, 4); - tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4); - tcg_out32(s, addr); /* XXX: This is l->u.value, can we use it? */ - } else { - tcg_out_movi32(s, cond, TCG_REG_R9, addr); - tcg_out_dat_reg(s, cond, ARITH_MOV, TCG_REG_R14, 0, - TCG_REG_PC, SHIFT_IMM_LSL(0)); - tcg_out_bx(s, cond, TCG_REG_R9); - } -#endif + tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R14, TCG_REG_PC, 4); + tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4); + tcg_out32(s, addr); } } diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h index 7756e7b03c..adbb036905 100644 --- a/tcg/i386/tcg-target.h +++ b/tcg/i386/tcg-target.h @@ -23,11 +23,6 @@ */ #define TCG_TARGET_I386 1 -#if defined(__x86_64__) -# define TCG_TARGET_REG_BITS 64 -#else -# define TCG_TARGET_REG_BITS 32 -#endif //#define TCG_TARGET_WORDS_BIGENDIAN #if TCG_TARGET_REG_BITS == 64 diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index 82e04e7f30..169d3b2b0d 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -389,7 +389,7 @@ static inline void tcg_gen_helperN(void *func, int flags, int sizemask, TCGArg ret, int nargs, TCGArg *args) { TCGv_ptr fn; - fn = tcg_const_ptr((tcg_target_long)func); + fn = tcg_const_ptr(func); tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret, nargs, args); tcg_temp_free_ptr(fn); @@ -405,7 +405,7 @@ static inline void tcg_gen_helper32(void *func, int sizemask, TCGv_i32 ret, { TCGv_ptr fn; TCGArg args[2]; - fn = tcg_const_ptr((tcg_target_long)func); + fn = tcg_const_ptr(func); args[0] = GET_TCGV_I32(a); args[1] = GET_TCGV_I32(b); tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE, sizemask, @@ -418,7 +418,7 @@ static inline void tcg_gen_helper64(void *func, int sizemask, TCGv_i64 ret, { TCGv_ptr fn; TCGArg args[2]; - fn = tcg_const_ptr((tcg_target_long)func); + fn = tcg_const_ptr(func); args[0] = GET_TCGV_I64(a); args[1] = GET_TCGV_I64(b); tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE, sizemask, @@ -1555,7 +1555,7 @@ static void temp_save(TCGContext *s, int temp, TCGRegSet allocated_regs) } } -/* save globals to their cannonical location and assume they can be +/* save globals to their canonical location and assume they can be modified be the following code. 'allocated_regs' is used in case a temporary registers needs to be allocated to store a constant. */ static void save_globals(TCGContext *s, TCGRegSet allocated_regs) @@ -178,7 +178,7 @@ typedef tcg_target_ulong TCGArg; /* Define a type and accessor macros for variables. Using a struct is nice because it gives some level of type safely. Ideally the compiler be able to see through all this. However in practice this is not true, - expecially on targets with braindamaged ABIs (e.g. i386). + especially on targets with braindamaged ABIs (e.g. i386). We use plain int by default to avoid this runtime overhead. Users of tcg_gen_* don't need to know about any of this, and should treat TCGv as an opaque type. @@ -544,7 +544,7 @@ void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs); #define TCGV_NAT_TO_PTR(n) MAKE_TCGV_PTR(GET_TCGV_I32(n)) #define TCGV_PTR_TO_NAT(n) MAKE_TCGV_I32(GET_TCGV_PTR(n)) -#define tcg_const_ptr(V) TCGV_NAT_TO_PTR(tcg_const_i32(V)) +#define tcg_const_ptr(V) TCGV_NAT_TO_PTR(tcg_const_i32((tcg_target_long)(V))) #define tcg_global_reg_new_ptr(R, N) \ TCGV_NAT_TO_PTR(tcg_global_reg_new_i32((R), (N))) #define tcg_global_mem_new_ptr(R, O, N) \ @@ -555,7 +555,7 @@ void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs); #define TCGV_NAT_TO_PTR(n) MAKE_TCGV_PTR(GET_TCGV_I64(n)) #define TCGV_PTR_TO_NAT(n) MAKE_TCGV_I64(GET_TCGV_PTR(n)) -#define tcg_const_ptr(V) TCGV_NAT_TO_PTR(tcg_const_i64(V)) +#define tcg_const_ptr(V) TCGV_NAT_TO_PTR(tcg_const_i64((tcg_target_long)(V))) #define tcg_global_reg_new_ptr(R, N) \ TCGV_NAT_TO_PTR(tcg_global_reg_new_i64((R), (N))) #define tcg_global_mem_new_ptr(R, O, N) \ diff --git a/tcg/tci/tcg-target.c b/tcg/tci/tcg-target.c index 942910e14b..fc0880cec5 100644 --- a/tcg/tci/tcg-target.c +++ b/tcg/tci/tcg-target.c @@ -373,10 +373,6 @@ static const char *const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { }; #endif -static void flush_icache_range(unsigned long start, unsigned long stop) -{ -} - static void patch_reloc(uint8_t *code_ptr, int type, tcg_target_long value, tcg_target_long addend) { diff --git a/tcg/tci/tcg-target.h b/tcg/tci/tcg-target.h index cb5858c9cb..03e0fd1a7f 100644 --- a/tcg/tci/tcg-target.h +++ b/tcg/tci/tcg-target.h @@ -157,4 +157,8 @@ void tci_disas(uint8_t opc); unsigned long tcg_qemu_tb_exec(CPUState *env, uint8_t *tb_ptr); #define tcg_qemu_tb_exec tcg_qemu_tb_exec +static inline void flush_icache_range(unsigned long start, unsigned long stop) +{ +} + #endif /* TCG_TARGET_H */ diff --git a/test-qmp-input-visitor.c b/test-qmp-input-visitor.c new file mode 100644 index 0000000000..1f3ab031f7 --- /dev/null +++ b/test-qmp-input-visitor.c @@ -0,0 +1,270 @@ +/* + * QMP Input Visitor unit-tests. + * + * Copyright (C) 2011 Red Hat Inc. + * + * Authors: + * Luiz Capitulino <lcapitulino@redhat.com> + * + * 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 <glib.h> +#include <stdarg.h> + +#include "qapi/qmp-input-visitor.h" +#include "test-qapi-types.h" +#include "test-qapi-visit.h" +#include "qemu-objects.h" + +typedef struct TestInputVisitorData { + QObject *obj; + QmpInputVisitor *qiv; +} TestInputVisitorData; + +static void visitor_input_teardown(TestInputVisitorData *data, + const void *unused) +{ + qobject_decref(data->obj); + data->obj = NULL; + + if (data->qiv) { + qmp_input_visitor_cleanup(data->qiv); + data->qiv = NULL; + } +} + +/* This is provided instead of a test setup function so that the JSON + string used by the tests are kept in the test functions (and not + int main()) */ +static Visitor *visitor_input_test_init(TestInputVisitorData *data, + const char *json_string, ...) +{ + Visitor *v; + va_list ap; + + va_start(ap, json_string); + data->obj = qobject_from_jsonv(json_string, &ap); + va_end(ap); + + g_assert(data->obj != NULL); + + data->qiv = qmp_input_visitor_new(data->obj); + g_assert(data->qiv != NULL); + + v = qmp_input_get_visitor(data->qiv); + g_assert(v != NULL); + + return v; +} + +static void test_visitor_in_int(TestInputVisitorData *data, + const void *unused) +{ + int64_t res = 0, value = -42; + Error *errp = NULL; + Visitor *v; + + v = visitor_input_test_init(data, "%d", value); + + visit_type_int(v, &res, NULL, &errp); + g_assert(!error_is_set(&errp)); + g_assert_cmpint(res, ==, value); +} + +static void test_visitor_in_bool(TestInputVisitorData *data, + const void *unused) +{ + Error *errp = NULL; + bool res = false; + Visitor *v; + + v = visitor_input_test_init(data, "true"); + + visit_type_bool(v, &res, NULL, &errp); + g_assert(!error_is_set(&errp)); + g_assert_cmpint(res, ==, true); +} + +static void test_visitor_in_number(TestInputVisitorData *data, + const void *unused) +{ + double res = 0, value = 3.14; + Error *errp = NULL; + Visitor *v; + + v = visitor_input_test_init(data, "%f", value); + + visit_type_number(v, &res, NULL, &errp); + g_assert(!error_is_set(&errp)); + g_assert_cmpfloat(res, ==, value); +} + +static void test_visitor_in_string(TestInputVisitorData *data, + const void *unused) +{ + char *res = NULL, *value = (char *) "Q E M U"; + Error *errp = NULL; + Visitor *v; + + v = visitor_input_test_init(data, "%s", value); + + visit_type_str(v, &res, NULL, &errp); + g_assert(!error_is_set(&errp)); + g_assert_cmpstr(res, ==, value); + + g_free(res); +} + +static void test_visitor_in_enum(TestInputVisitorData *data, + const void *unused) +{ + Error *errp = NULL; + Visitor *v; + EnumOne i; + + for (i = 0; EnumOne_lookup[i]; i++) { + EnumOne res = -1; + + v = visitor_input_test_init(data, "%s", EnumOne_lookup[i]); + + visit_type_EnumOne(v, &res, NULL, &errp); + g_assert(!error_is_set(&errp)); + g_assert_cmpint(i, ==, res); + + visitor_input_teardown(data, NULL); + } + + data->obj = NULL; + data->qiv = NULL; +} + +typedef struct TestStruct +{ + int64_t integer; + bool boolean; + char *string; +} TestStruct; + +static void visit_type_TestStruct(Visitor *v, TestStruct **obj, + const char *name, Error **errp) +{ + visit_start_struct(v, (void **)obj, "TestStruct", name, sizeof(TestStruct), + errp); + + visit_type_int(v, &(*obj)->integer, "integer", errp); + visit_type_bool(v, &(*obj)->boolean, "boolean", errp); + visit_type_str(v, &(*obj)->string, "string", errp); + + visit_end_struct(v, errp); +} + +static void test_visitor_in_struct(TestInputVisitorData *data, + const void *unused) +{ + TestStruct *p = NULL; + Error *errp = NULL; + Visitor *v; + + v = visitor_input_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }"); + + visit_type_TestStruct(v, &p, NULL, &errp); + g_assert(!error_is_set(&errp)); + g_assert_cmpint(p->integer, ==, -42); + g_assert(p->boolean == true); + g_assert_cmpstr(p->string, ==, "foo"); + + g_free(p->string); + g_free(p); +} + +static void check_and_free_str(char *str, const char *cmp) +{ + g_assert_cmpstr(str, ==, cmp); + g_free(str); +} + +static void test_visitor_in_struct_nested(TestInputVisitorData *data, + const void *unused) +{ + UserDefNested *udp = NULL; + Error *errp = NULL; + Visitor *v; + + v = visitor_input_test_init(data, "{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string' }, 'string2': 'string2'}}}"); + + visit_type_UserDefNested(v, &udp, NULL, &errp); + g_assert(!error_is_set(&errp)); + + check_and_free_str(udp->string0, "string0"); + check_and_free_str(udp->dict1.string1, "string1"); + g_assert_cmpint(udp->dict1.dict2.userdef1->integer, ==, 42); + check_and_free_str(udp->dict1.dict2.userdef1->string, "string"); + check_and_free_str(udp->dict1.dict2.string2, "string2"); + g_assert(udp->dict1.has_dict3 == false); + + g_free(udp->dict1.dict2.userdef1); + g_free(udp); +} + +static void test_visitor_in_list(TestInputVisitorData *data, + const void *unused) +{ + UserDefOneList *item, *head = NULL; + Error *errp = NULL; + Visitor *v; + int i; + + v = visitor_input_test_init(data, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44 } ]"); + + visit_type_UserDefOneList(v, &head, NULL, &errp); + g_assert(!error_is_set(&errp)); + g_assert(head != NULL); + + for (i = 0, item = head; item; item = item->next, i++) { + char string[12]; + + snprintf(string, sizeof(string), "string%d", i); + g_assert_cmpstr(item->value->string, ==, string); + g_assert_cmpint(item->value->integer, ==, 42 + i); + } + + qapi_free_UserDefOneList(head); +} + +static void input_visitor_test_add(const char *testpath, + TestInputVisitorData *data, + void (*test_func)(TestInputVisitorData *data, const void *user_data)) +{ + g_test_add(testpath, TestInputVisitorData, data, NULL, test_func, + visitor_input_teardown); +} + +int main(int argc, char **argv) +{ + TestInputVisitorData in_visitor_data; + + g_test_init(&argc, &argv, NULL); + + input_visitor_test_add("/visitor/input/int", + &in_visitor_data, test_visitor_in_int); + input_visitor_test_add("/visitor/input/bool", + &in_visitor_data, test_visitor_in_bool); + input_visitor_test_add("/visitor/input/number", + &in_visitor_data, test_visitor_in_number); + input_visitor_test_add("/visitor/input/string", + &in_visitor_data, test_visitor_in_string); + input_visitor_test_add("/visitor/input/enum", + &in_visitor_data, test_visitor_in_enum); + input_visitor_test_add("/visitor/input/struct", + &in_visitor_data, test_visitor_in_struct); + input_visitor_test_add("/visitor/input/struct-nested", + &in_visitor_data, test_visitor_in_struct_nested); + input_visitor_test_add("/visitor/input/list", + &in_visitor_data, test_visitor_in_list); + + g_test_run(); + + return 0; +} diff --git a/test-qmp-output-visitor.c b/test-qmp-output-visitor.c new file mode 100644 index 0000000000..c94c208125 --- /dev/null +++ b/test-qmp-output-visitor.c @@ -0,0 +1,423 @@ +/* + * QMP Output Visitor unit-tests. + * + * Copyright (C) 2011 Red Hat Inc. + * + * Authors: + * Luiz Capitulino <lcapitulino@redhat.com> + * + * 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 <glib.h> + +#include "qapi/qmp-output-visitor.h" +#include "test-qapi-types.h" +#include "test-qapi-visit.h" +#include "qemu-objects.h" + +typedef struct TestOutputVisitorData { + QmpOutputVisitor *qov; + Visitor *ov; +} TestOutputVisitorData; + +static void visitor_output_setup(TestOutputVisitorData *data, + const void *unused) +{ + data->qov = qmp_output_visitor_new(); + g_assert(data->qov != NULL); + + data->ov = qmp_output_get_visitor(data->qov); + g_assert(data->ov != NULL); +} + +static void visitor_output_teardown(TestOutputVisitorData *data, + const void *unused) +{ + qmp_output_visitor_cleanup(data->qov); + data->qov = NULL; + data->ov = NULL; +} + +static void test_visitor_out_int(TestOutputVisitorData *data, + const void *unused) +{ + int64_t value = -42; + Error *errp = NULL; + QObject *obj; + + visit_type_int(data->ov, &value, NULL, &errp); + g_assert(error_is_set(&errp) == 0); + + obj = qmp_output_get_qobject(data->qov); + g_assert(obj != NULL); + g_assert(qobject_type(obj) == QTYPE_QINT); + g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, value); + + qobject_decref(obj); +} + +static void test_visitor_out_bool(TestOutputVisitorData *data, + const void *unused) +{ + Error *errp = NULL; + bool value = true; + QObject *obj; + + visit_type_bool(data->ov, &value, NULL, &errp); + g_assert(error_is_set(&errp) == 0); + + obj = qmp_output_get_qobject(data->qov); + g_assert(obj != NULL); + g_assert(qobject_type(obj) == QTYPE_QBOOL); + g_assert(qbool_get_int(qobject_to_qbool(obj)) == value); + + qobject_decref(obj); +} + +static void test_visitor_out_number(TestOutputVisitorData *data, + const void *unused) +{ + double value = 3.14; + Error *errp = NULL; + QObject *obj; + + visit_type_number(data->ov, &value, NULL, &errp); + g_assert(error_is_set(&errp) == 0); + + obj = qmp_output_get_qobject(data->qov); + g_assert(obj != NULL); + g_assert(qobject_type(obj) == QTYPE_QFLOAT); + g_assert(qfloat_get_double(qobject_to_qfloat(obj)) == value); + + qobject_decref(obj); +} + +static void test_visitor_out_string(TestOutputVisitorData *data, + const void *unused) +{ + char *string = (char *) "Q E M U"; + Error *errp = NULL; + QObject *obj; + + visit_type_str(data->ov, &string, NULL, &errp); + g_assert(error_is_set(&errp) == 0); + + obj = qmp_output_get_qobject(data->qov); + g_assert(obj != NULL); + g_assert(qobject_type(obj) == QTYPE_QSTRING); + g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, string); + + qobject_decref(obj); +} + +static void test_visitor_out_no_string(TestOutputVisitorData *data, + const void *unused) +{ + char *string = NULL; + Error *errp = NULL; + QObject *obj; + + /* A null string should return "" */ + visit_type_str(data->ov, &string, NULL, &errp); + g_assert(error_is_set(&errp) == 0); + + obj = qmp_output_get_qobject(data->qov); + g_assert(obj != NULL); + g_assert(qobject_type(obj) == QTYPE_QSTRING); + g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, ""); + + qobject_decref(obj); +} + +static void test_visitor_out_enum(TestOutputVisitorData *data, + const void *unused) +{ + Error *errp = NULL; + QObject *obj; + EnumOne i; + + for (i = 0; i < ENUM_ONE_MAX; i++) { + visit_type_EnumOne(data->ov, &i, "unused", &errp); + g_assert(!error_is_set(&errp)); + + obj = qmp_output_get_qobject(data->qov); + g_assert(obj != NULL); + g_assert(qobject_type(obj) == QTYPE_QSTRING); + g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, + EnumOne_lookup[i]); + qobject_decref(obj); + } +} + +static void test_visitor_out_enum_errors(TestOutputVisitorData *data, + const void *unused) +{ + EnumOne i, bad_values[] = { ENUM_ONE_MAX, -1 }; + Error *errp; + + for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) { + errp = NULL; + visit_type_EnumOne(data->ov, &bad_values[i], "unused", &errp); + g_assert(error_is_set(&errp) == true); + error_free(errp); + } +} + +typedef struct TestStruct +{ + int64_t integer; + bool boolean; + char *string; +} TestStruct; + +static void visit_type_TestStruct(Visitor *v, TestStruct **obj, + const char *name, Error **errp) +{ + visit_start_struct(v, (void **)obj, "TestStruct", name, sizeof(TestStruct), + errp); + + visit_type_int(v, &(*obj)->integer, "integer", errp); + visit_type_bool(v, &(*obj)->boolean, "boolean", errp); + visit_type_str(v, &(*obj)->string, "string", errp); + + visit_end_struct(v, errp); +} + +static void test_visitor_out_struct(TestOutputVisitorData *data, + const void *unused) +{ + TestStruct test_struct = { .integer = 42, + .boolean = false, + .string = (char *) "foo"}; + TestStruct *p = &test_struct; + Error *errp = NULL; + QObject *obj; + QDict *qdict; + + visit_type_TestStruct(data->ov, &p, NULL, &errp); + g_assert(!error_is_set(&errp)); + + obj = qmp_output_get_qobject(data->qov); + g_assert(obj != NULL); + g_assert(qobject_type(obj) == QTYPE_QDICT); + + qdict = qobject_to_qdict(obj); + g_assert_cmpint(qdict_size(qdict), ==, 3); + g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42); + g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, 0); + g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "foo"); + + QDECREF(qdict); +} + +static void test_visitor_out_struct_nested(TestOutputVisitorData *data, + const void *unused) +{ + int64_t value = 42; + Error *errp = NULL; + UserDefNested *ud2; + QObject *obj; + QDict *qdict, *dict1, *dict2, *dict3, *userdef; + const char *string = "user def string"; + const char *strings[] = { "fourty two", "fourty three", "fourty four", + "fourty five" }; + + ud2 = g_malloc0(sizeof(*ud2)); + ud2->string0 = g_strdup(strings[0]); + + ud2->dict1.string1 = g_strdup(strings[1]); + ud2->dict1.dict2.userdef1 = g_malloc0(sizeof(UserDefOne)); + ud2->dict1.dict2.userdef1->string = g_strdup(string); + ud2->dict1.dict2.userdef1->integer = value; + ud2->dict1.dict2.string2 = g_strdup(strings[2]); + + ud2->dict1.has_dict3 = true; + ud2->dict1.dict3.userdef2 = g_malloc0(sizeof(UserDefOne)); + ud2->dict1.dict3.userdef2->string = g_strdup(string); + ud2->dict1.dict3.userdef2->integer = value; + ud2->dict1.dict3.string3 = g_strdup(strings[3]); + + visit_type_UserDefNested(data->ov, &ud2, "unused", &errp); + g_assert(!error_is_set(&errp)); + + obj = qmp_output_get_qobject(data->qov); + g_assert(obj != NULL); + g_assert(qobject_type(obj) == QTYPE_QDICT); + + qdict = qobject_to_qdict(obj); + g_assert_cmpint(qdict_size(qdict), ==, 2); + g_assert_cmpstr(qdict_get_str(qdict, "string0"), ==, strings[0]); + + dict1 = qdict_get_qdict(qdict, "dict1"); + g_assert_cmpint(qdict_size(dict1), ==, 3); + g_assert_cmpstr(qdict_get_str(dict1, "string1"), ==, strings[1]); + + dict2 = qdict_get_qdict(dict1, "dict2"); + g_assert_cmpint(qdict_size(dict2), ==, 2); + g_assert_cmpstr(qdict_get_str(dict2, "string2"), ==, strings[2]); + userdef = qdict_get_qdict(dict2, "userdef1"); + g_assert_cmpint(qdict_size(userdef), ==, 2); + g_assert_cmpint(qdict_get_int(userdef, "integer"), ==, value); + g_assert_cmpstr(qdict_get_str(userdef, "string"), ==, string); + + dict3 = qdict_get_qdict(dict1, "dict3"); + g_assert_cmpint(qdict_size(dict3), ==, 2); + g_assert_cmpstr(qdict_get_str(dict3, "string3"), ==, strings[3]); + userdef = qdict_get_qdict(dict3, "userdef2"); + g_assert_cmpint(qdict_size(userdef), ==, 2); + g_assert_cmpint(qdict_get_int(userdef, "integer"), ==, value); + g_assert_cmpstr(qdict_get_str(userdef, "string"), ==, string); + + QDECREF(qdict); + qapi_free_UserDefNested(ud2); +} + +typedef struct TestStructList +{ + TestStruct *value; + struct TestStructList *next; +} TestStructList; + +static void visit_type_TestStructList(Visitor *v, TestStructList **obj, + const char *name, Error **errp) +{ + GenericList *i, **head = (GenericList **)obj; + + visit_start_list(v, name, errp); + + for (*head = i = visit_next_list(v, head, errp); i; i = visit_next_list(v, &i, errp)) { + TestStructList *native_i = (TestStructList *)i; + visit_type_TestStruct(v, &native_i->value, NULL, errp); + } + + visit_end_list(v, errp); +} + +static void test_visitor_out_list(TestOutputVisitorData *data, + const void *unused) +{ + char *value_str = (char *) "list value"; + TestStructList *p, *head = NULL; + const int max_items = 10; + bool value_bool = true; + int value_int = 10; + Error *errp = NULL; + QListEntry *entry; + QObject *obj; + QList *qlist; + int i; + + for (i = 0; i < max_items; i++) { + p = g_malloc0(sizeof(*p)); + p->value = g_malloc0(sizeof(*p->value)); + p->value->integer = value_int; + p->value->boolean = value_bool; + p->value->string = value_str; + + p->next = head; + head = p; + } + + visit_type_TestStructList(data->ov, &head, NULL, &errp); + g_assert(!error_is_set(&errp)); + + obj = qmp_output_get_qobject(data->qov); + g_assert(obj != NULL); + g_assert(qobject_type(obj) == QTYPE_QLIST); + + qlist = qobject_to_qlist(obj); + g_assert(!qlist_empty(qlist)); + + i = 0; + QLIST_FOREACH_ENTRY(qlist, entry) { + QDict *qdict; + + g_assert(qobject_type(entry->value) == QTYPE_QDICT); + qdict = qobject_to_qdict(entry->value); + g_assert_cmpint(qdict_size(qdict), ==, 3); + g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, value_int); + g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, value_bool); + g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, value_str); + i++; + } + g_assert_cmpint(i, ==, max_items); + + QDECREF(qlist); + + for (p = head; p;) { + TestStructList *tmp = p->next; + g_free(p->value); + g_free(p); + p = tmp; + } +} + +static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data, + const void *unused) +{ + UserDefNestedList *p, *head = NULL; + const char string[] = "foo bar"; + int i, max_count = 1024; + + for (i = 0; i < max_count; i++) { + p = g_malloc0(sizeof(*p)); + p->value = g_malloc0(sizeof(*p->value)); + + p->value->string0 = g_strdup(string); + p->value->dict1.string1 = g_strdup(string); + p->value->dict1.dict2.userdef1 = g_malloc0(sizeof(UserDefOne)); + p->value->dict1.dict2.userdef1->string = g_strdup(string); + p->value->dict1.dict2.userdef1->integer = 42; + p->value->dict1.dict2.string2 = g_strdup(string); + p->value->dict1.has_dict3 = false; + + p->next = head; + head = p; + } + + qapi_free_UserDefNestedList(head); +} + +static void output_visitor_test_add(const char *testpath, + TestOutputVisitorData *data, + void (*test_func)(TestOutputVisitorData *data, const void *user_data)) +{ + g_test_add(testpath, TestOutputVisitorData, data, visitor_output_setup, + test_func, visitor_output_teardown); +} + +int main(int argc, char **argv) +{ + TestOutputVisitorData out_visitor_data; + + g_test_init(&argc, &argv, NULL); + + output_visitor_test_add("/visitor/output/int", + &out_visitor_data, test_visitor_out_int); + output_visitor_test_add("/visitor/output/bool", + &out_visitor_data, test_visitor_out_bool); + output_visitor_test_add("/visitor/output/number", + &out_visitor_data, test_visitor_out_number); + output_visitor_test_add("/visitor/output/string", + &out_visitor_data, test_visitor_out_string); + output_visitor_test_add("/visitor/output/no-string", + &out_visitor_data, test_visitor_out_no_string); + output_visitor_test_add("/visitor/output/enum", + &out_visitor_data, test_visitor_out_enum); + output_visitor_test_add("/visitor/output/enum-errors", + &out_visitor_data, test_visitor_out_enum_errors); + output_visitor_test_add("/visitor/output/struct", + &out_visitor_data, test_visitor_out_struct); + output_visitor_test_add("/visitor/output/struct-nested", + &out_visitor_data, test_visitor_out_struct_nested); + output_visitor_test_add("/visitor/output/list", + &out_visitor_data, test_visitor_out_list); + output_visitor_test_add("/visitor/output/list-qapi-free", + &out_visitor_data, test_visitor_out_list_qapi_free); + + g_test_run(); + + return 0; +} diff --git a/test-visitor.c b/test-visitor.c deleted file mode 100644 index 847ce14ea1..0000000000 --- a/test-visitor.c +++ /dev/null @@ -1,338 +0,0 @@ -#include <glib.h> -#include "qapi/qmp-output-visitor.h" -#include "qapi/qmp-input-visitor.h" -#include "test-qapi-types.h" -#include "test-qapi-visit.h" -#include "qemu-objects.h" - -typedef struct TestStruct -{ - int64_t x; - int64_t y; -} TestStruct; - -typedef struct TestStructList -{ - TestStruct *value; - struct TestStructList *next; -} TestStructList; - -static void visit_type_TestStruct(Visitor *v, TestStruct **obj, const char *name, Error **errp) -{ - visit_start_struct(v, (void **)obj, "TestStruct", name, sizeof(TestStruct), errp); - visit_type_int(v, &(*obj)->x, "x", errp); - visit_type_int(v, &(*obj)->y, "y", errp); - visit_end_struct(v, errp); -} - -static void visit_type_TestStructList(Visitor *m, TestStructList ** obj, const char *name, Error **errp) -{ - GenericList *i, **head = (GenericList **)obj; - - visit_start_list(m, name, errp); - - for (*head = i = visit_next_list(m, head, errp); i; i = visit_next_list(m, &i, errp)) { - TestStructList *native_i = (TestStructList *)i; - visit_type_TestStruct(m, &native_i->value, NULL, errp); - } - - visit_end_list(m, errp); -} - -/* test core visitor methods */ -static void test_visitor_core(void) -{ - QmpOutputVisitor *mo; - QmpInputVisitor *mi; - Visitor *v; - TestStruct ts = { 42, 82 }; - TestStruct *pts = &ts; - TestStructList *lts = NULL; - Error *err = NULL; - QObject *obj; - QList *qlist; - QDict *qdict; - QString *str; - int64_t value = 0; - - mo = qmp_output_visitor_new(); - v = qmp_output_get_visitor(mo); - - visit_type_TestStruct(v, &pts, NULL, &err); - - obj = qmp_output_get_qobject(mo); - - str = qobject_to_json(obj); - - printf("%s\n", qstring_get_str(str)); - - QDECREF(str); - - obj = QOBJECT(qint_from_int(0x42)); - - mi = qmp_input_visitor_new(obj); - v = qmp_input_get_visitor(mi); - - visit_type_int(v, &value, NULL, &err); - if (err) { - g_error("%s", error_get_pretty(err)); - } - - g_assert(value == 0x42); - - qobject_decref(obj); - - obj = qobject_from_json("{'x': 42, 'y': 84}"); - mi = qmp_input_visitor_new(obj); - v = qmp_input_get_visitor(mi); - - pts = NULL; - - visit_type_TestStruct(v, &pts, NULL, &err); - if (err) { - g_error("%s", error_get_pretty(err)); - } - - g_assert(pts != NULL); - g_assert(pts->x == 42); - g_assert(pts->y == 84); - - qobject_decref(obj); - g_free(pts); - - /* test list input visitor */ - obj = qobject_from_json("[{'x': 42, 'y': 84}, {'x': 12, 'y': 24}]"); - mi = qmp_input_visitor_new(obj); - v = qmp_input_get_visitor(mi); - - visit_type_TestStructList(v, <s, NULL, &err); - if (err) { - g_error("%s", error_get_pretty(err)); - } - - g_assert(lts != NULL); - g_assert(lts->value->x == 42); - g_assert(lts->value->y == 84); - - g_assert(lts->next != NULL); - g_assert(lts->next->value->x == 12); - g_assert(lts->next->value->y == 24); - g_assert(lts->next->next == NULL); - - qobject_decref(obj); - - /* test list output visitor */ - mo = qmp_output_visitor_new(); - v = qmp_output_get_visitor(mo); - visit_type_TestStructList(v, <s, NULL, &err); - if (err) { - g_error("%s", error_get_pretty(err)); - } - obj = qmp_output_get_qobject(mo); - g_print("obj: %s\n", qstring_get_str(qobject_to_json(obj))); - - qlist = qobject_to_qlist(obj); - assert(qlist); - obj = qlist_pop(qlist); - qdict = qobject_to_qdict(obj); - assert(qdict); - assert(qdict_get_int(qdict, "x") == 42); - assert(qdict_get_int(qdict, "y") == 84); - qobject_decref(obj); - - obj = qlist_pop(qlist); - qdict = qobject_to_qdict(obj); - assert(qdict); - assert(qdict_get_int(qdict, "x") == 12); - assert(qdict_get_int(qdict, "y") == 24); - qobject_decref(obj); - - qmp_output_visitor_cleanup(mo); - QDECREF(qlist); -} - -/* test deep nesting with refs to other user-defined types */ -static void test_nested_structs(void) -{ - QmpOutputVisitor *mo; - QmpInputVisitor *mi; - Visitor *v; - UserDefOne ud1; - UserDefOne *ud1_p = &ud1, *ud1c_p = NULL; - UserDefTwo ud2; - UserDefTwo *ud2_p = &ud2, *ud2c_p = NULL; - Error *err = NULL; - QObject *obj; - QString *str; - - ud1.integer = 42; - ud1.string = strdup("fourty two"); - - /* sanity check */ - mo = qmp_output_visitor_new(); - v = qmp_output_get_visitor(mo); - visit_type_UserDefOne(v, &ud1_p, "o_O", &err); - if (err) { - g_error("%s", error_get_pretty(err)); - } - obj = qmp_output_get_qobject(mo); - g_assert(obj); - qobject_decref(obj); - - ud2.string = strdup("fourty three"); - ud2.dict.string = strdup("fourty four"); - ud2.dict.dict.userdef = ud1_p; - ud2.dict.dict.string = strdup("fourty five"); - ud2.dict.has_dict2 = true; - ud2.dict.dict2.userdef = ud1_p; - ud2.dict.dict2.string = strdup("fourty six"); - - /* c type -> qobject */ - mo = qmp_output_visitor_new(); - v = qmp_output_get_visitor(mo); - visit_type_UserDefTwo(v, &ud2_p, "unused", &err); - if (err) { - g_error("%s", error_get_pretty(err)); - } - obj = qmp_output_get_qobject(mo); - g_assert(obj); - str = qobject_to_json_pretty(obj); - g_print("%s\n", qstring_get_str(str)); - QDECREF(str); - - /* qobject -> c type, should match original struct */ - mi = qmp_input_visitor_new(obj); - v = qmp_input_get_visitor(mi); - visit_type_UserDefTwo(v, &ud2c_p, NULL, &err); - if (err) { - g_error("%s", error_get_pretty(err)); - } - - g_assert(!g_strcmp0(ud2c_p->string, ud2.string)); - g_assert(!g_strcmp0(ud2c_p->dict.string, ud2.dict.string)); - - ud1c_p = ud2c_p->dict.dict.userdef; - g_assert(ud1c_p->integer == ud1_p->integer); - g_assert(!g_strcmp0(ud1c_p->string, ud1_p->string)); - - g_assert(!g_strcmp0(ud2c_p->dict.dict.string, ud2.dict.dict.string)); - - ud1c_p = ud2c_p->dict.dict2.userdef; - g_assert(ud1c_p->integer == ud1_p->integer); - g_assert(!g_strcmp0(ud1c_p->string, ud1_p->string)); - - g_assert(!g_strcmp0(ud2c_p->dict.dict2.string, ud2.dict.dict2.string)); - g_free(ud1.string); - g_free(ud2.string); - g_free(ud2.dict.string); - g_free(ud2.dict.dict.string); - g_free(ud2.dict.dict2.string); - - qapi_free_UserDefTwo(ud2c_p); - - qobject_decref(obj); -} - -/* test enum values */ -static void test_enums(void) -{ - QmpOutputVisitor *mo; - QmpInputVisitor *mi; - Visitor *v; - EnumOne enum1 = ENUM_ONE_VALUE2, enum1_cpy = ENUM_ONE_VALUE1; - Error *err = NULL; - QObject *obj; - QString *str; - - /* C type -> QObject */ - mo = qmp_output_visitor_new(); - v = qmp_output_get_visitor(mo); - visit_type_EnumOne(v, &enum1, "unused", &err); - if (err) { - g_error("%s", error_get_pretty(err)); - } - obj = qmp_output_get_qobject(mo); - g_assert(obj); - str = qobject_to_json_pretty(obj); - g_print("%s\n", qstring_get_str(str)); - QDECREF(str); - g_assert(g_strcmp0(qstring_get_str(qobject_to_qstring(obj)), "value2") == 0); - - /* QObject -> C type */ - mi = qmp_input_visitor_new(obj); - v = qmp_input_get_visitor(mi); - visit_type_EnumOne(v, &enum1_cpy, "unused", &err); - if (err) { - g_error("%s", error_get_pretty(err)); - } - g_debug("enum1_cpy, enum1: %d, %d", enum1_cpy, enum1); - g_assert(enum1_cpy == enum1); - - qobject_decref(obj); -} - -/* test enum values nested in schema-defined structs */ -static void test_nested_enums(void) -{ - QmpOutputVisitor *mo; - QmpInputVisitor *mi; - Visitor *v; - NestedEnumsOne *nested_enums, *nested_enums_cpy = NULL; - Error *err = NULL; - QObject *obj; - QString *str; - - nested_enums = g_malloc0(sizeof(NestedEnumsOne)); - nested_enums->enum1 = ENUM_ONE_VALUE1; - nested_enums->enum2 = ENUM_ONE_VALUE2; - nested_enums->enum3 = ENUM_ONE_VALUE3; - nested_enums->enum4 = ENUM_ONE_VALUE3; - nested_enums->has_enum2 = false; - nested_enums->has_enum4 = true; - - /* C type -> QObject */ - mo = qmp_output_visitor_new(); - v = qmp_output_get_visitor(mo); - visit_type_NestedEnumsOne(v, &nested_enums, NULL, &err); - if (err) { - g_error("%s", error_get_pretty(err)); - } - obj = qmp_output_get_qobject(mo); - g_assert(obj); - str = qobject_to_json_pretty(obj); - g_print("%s\n", qstring_get_str(str)); - QDECREF(str); - - /* QObject -> C type */ - mi = qmp_input_visitor_new(obj); - v = qmp_input_get_visitor(mi); - visit_type_NestedEnumsOne(v, &nested_enums_cpy, NULL, &err); - if (err) { - g_error("%s", error_get_pretty(err)); - } - g_assert(nested_enums_cpy); - g_assert(nested_enums_cpy->enum1 == nested_enums->enum1); - g_assert(nested_enums_cpy->enum3 == nested_enums->enum3); - g_assert(nested_enums_cpy->enum4 == nested_enums->enum4); - g_assert(nested_enums_cpy->has_enum2 == false); - g_assert(nested_enums_cpy->has_enum4 == true); - - qmp_output_visitor_cleanup(mo); - qmp_input_visitor_cleanup(mi); - qapi_free_NestedEnumsOne(nested_enums); - qapi_free_NestedEnumsOne(nested_enums_cpy); -} - -int main(int argc, char **argv) -{ - g_test_init(&argc, &argv, NULL); - - g_test_add_func("/0.15/visitor_core", test_visitor_core); - g_test_add_func("/0.15/nested_structs", test_nested_structs); - g_test_add_func("/0.15/enums", test_enums); - g_test_add_func("/0.15/nested_enums", test_nested_enums); - - g_test_run(); - - return 0; -} diff --git a/tests/Makefile b/tests/Makefile index 430e0c1776..15e36a208c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -115,12 +115,6 @@ speed: sha1 sha1-i386 time ./sha1 time $(QEMU) ./sha1-i386 -# broken test -# NOTE: -fomit-frame-pointer is currently needed : this is a bug in libqemu -qruncom: qruncom.c ../ioport-user.c ../i386-user/libqemu.a - $(CC) $(CFLAGS) -fomit-frame-pointer $(LDFLAGS) -I../target-i386 -I.. -I../i386-user -I../fpu \ - -o $@ $(filter %.c, $^) -L../i386-user -lqemu -lm - # arm test hello-arm: hello-arm.o arm-linux-ld -o $@ $< diff --git a/tests/cris/check_glibc_kernelversion.c b/tests/cris/check_glibc_kernelversion.c index fcbc7b07f6..07448722c0 100644 --- a/tests/cris/check_glibc_kernelversion.c +++ b/tests/cris/check_glibc_kernelversion.c @@ -70,7 +70,7 @@ \ /* Now we can test with the required version. */ \ if (version < __LINUX_KERNEL_VERSION) \ - /* Not sufficent. */ \ + /* Not sufficient. */ \ FATAL ("FATAL: kernel too old\n"); \ \ _dl_osversion = version; \ diff --git a/tests/cris/check_moveq.c b/tests/cris/check_moveq.c index 9f71194ac3..80f2dff6ab 100644 --- a/tests/cris/check_moveq.c +++ b/tests/cris/check_moveq.c @@ -20,7 +20,7 @@ int main(void) if (t != 10) err(); - /* make sure moveq doesnt clobber the zflag. */ + /* make sure moveq doesn't clobber the zflag. */ cris_tst_cc_init(); asm volatile ("setf vnc\n"); asm volatile ("clearf z\n"); @@ -29,7 +29,7 @@ int main(void) if (t != 0) err(); - /* make sure moveq doesnt clobber the nflag. + /* make sure moveq doesn't clobber the nflag. Also check large immediates */ cris_tst_cc_init(); asm volatile ("setf zvc\n"); diff --git a/tests/qruncom.c b/tests/qruncom.c deleted file mode 100644 index 2e93aafb87..0000000000 --- a/tests/qruncom.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Example of use of user mode libqemu: launch a basic .com DOS - * executable - */ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <inttypes.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/mman.h> -#include <signal.h> -#include <malloc.h> - -#include "cpu.h" - -//#define SIGTEST - -int cpu_get_pic_interrupt(CPUState *env) -{ - return -1; -} - -uint64_t cpu_get_tsc(CPUState *env) -{ - return 0; -} - -static void set_gate(void *ptr, unsigned int type, unsigned int dpl, - unsigned long addr, unsigned int sel) -{ - unsigned int e1, e2; - e1 = (addr & 0xffff) | (sel << 16); - e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); - stl((uint8_t *)ptr, e1); - stl((uint8_t *)ptr + 4, e2); -} - -uint64_t idt_table[256]; - -/* only dpl matters as we do only user space emulation */ -static void set_idt(int n, unsigned int dpl) -{ - set_gate(idt_table + n, 0, dpl, 0, 0); -} - -void g_free(void *ptr) -{ - free(ptr); -} - -void *g_malloc(size_t size) -{ - return malloc(size); -} - -void *g_malloc0(size_t size) -{ - void *ptr; - ptr = g_malloc(size); - if (!ptr) - return NULL; - memset(ptr, 0, size); - return ptr; -} - -void *qemu_vmalloc(size_t size) -{ - return memalign(4096, size); -} - -void qemu_vfree(void *ptr) -{ - free(ptr); -} - -void qemu_printf(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); -} - -/* XXX: this is a bug in helper2.c */ -int errno; - -/**********************************************/ - -#define COM_BASE_ADDR 0x10100 - -static void usage(void) -{ - printf("qruncom version 0.1 (c) 2003 Fabrice Bellard\n" - "usage: qruncom file.com\n" - "user mode libqemu demo: run simple .com DOS executables\n"); - exit(1); -} - -static inline uint8_t *seg_to_linear(unsigned int seg, unsigned int reg) -{ - return (uint8_t *)((seg << 4) + (reg & 0xffff)); -} - -static inline void pushw(CPUState *env, int val) -{ - env->regs[R_ESP] = (env->regs[R_ESP] & ~0xffff) | ((env->regs[R_ESP] - 2) & 0xffff); - *(uint16_t *)seg_to_linear(env->segs[R_SS].selector, env->regs[R_ESP]) = val; -} - -static void host_segv_handler(int host_signum, siginfo_t *info, - void *puc) -{ - if (cpu_signal_handler(host_signum, info, puc)) { - return; - } - abort(); -} - -int main(int argc, char **argv) -{ - uint8_t *vm86_mem; - const char *filename; - int fd, ret, seg; - CPUState *env; - - if (argc != 2) - usage(); - filename = argv[1]; - - vm86_mem = mmap((void *)0x00000000, 0x110000, - PROT_WRITE | PROT_READ | PROT_EXEC, - MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); - if (vm86_mem == MAP_FAILED) { - perror("mmap"); - exit(1); - } - - /* load the MSDOS .com executable */ - fd = open(filename, O_RDONLY); - if (fd < 0) { - perror(filename); - exit(1); - } - ret = read(fd, vm86_mem + COM_BASE_ADDR, 65536 - 256); - if (ret < 0) { - perror("read"); - exit(1); - } - close(fd); - - /* install exception handler for CPU emulator */ - { - struct sigaction act; - - sigfillset(&act.sa_mask); - act.sa_flags = SA_SIGINFO; - // act.sa_flags |= SA_ONSTACK; - - act.sa_sigaction = host_segv_handler; - sigaction(SIGSEGV, &act, NULL); - sigaction(SIGBUS, &act, NULL); - } - - // cpu_set_log(CPU_LOG_TB_IN_ASM | CPU_LOG_TB_OUT_ASM | CPU_LOG_EXEC); - - env = cpu_init("qemu32"); - - cpu_x86_set_cpl(env, 3); - - env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; - /* NOTE: hflags duplicates some of the virtual CPU state */ - env->hflags |= HF_PE_MASK | VM_MASK; - - /* flags setup : we activate the IRQs by default as in user - mode. We also activate the VM86 flag to run DOS code */ - env->eflags |= IF_MASK | VM_MASK; - - /* init basic registers */ - env->eip = 0x100; - env->regs[R_ESP] = 0xfffe; - seg = (COM_BASE_ADDR - 0x100) >> 4; - - cpu_x86_load_seg_cache(env, R_CS, seg, - (seg << 4), 0xffff, 0); - cpu_x86_load_seg_cache(env, R_SS, seg, - (seg << 4), 0xffff, 0); - cpu_x86_load_seg_cache(env, R_DS, seg, - (seg << 4), 0xffff, 0); - cpu_x86_load_seg_cache(env, R_ES, seg, - (seg << 4), 0xffff, 0); - cpu_x86_load_seg_cache(env, R_FS, seg, - (seg << 4), 0xffff, 0); - cpu_x86_load_seg_cache(env, R_GS, seg, - (seg << 4), 0xffff, 0); - - /* exception support */ - env->idt.base = (unsigned long)idt_table; - env->idt.limit = sizeof(idt_table) - 1; - set_idt(0, 0); - set_idt(1, 0); - set_idt(2, 0); - set_idt(3, 3); - set_idt(4, 3); - set_idt(5, 3); - set_idt(6, 0); - set_idt(7, 0); - set_idt(8, 0); - set_idt(9, 0); - set_idt(10, 0); - set_idt(11, 0); - set_idt(12, 0); - set_idt(13, 0); - set_idt(14, 0); - set_idt(15, 0); - set_idt(16, 0); - set_idt(17, 0); - set_idt(18, 0); - set_idt(19, 0); - - /* put return code */ - *seg_to_linear(env->segs[R_CS].selector, 0) = 0xb4; /* mov ah, $0 */ - *seg_to_linear(env->segs[R_CS].selector, 1) = 0x00; - *seg_to_linear(env->segs[R_CS].selector, 2) = 0xcd; /* int $0x21 */ - *seg_to_linear(env->segs[R_CS].selector, 3) = 0x21; - pushw(env, 0x0000); - - /* the value of these registers seem to be assumed by pi_10.com */ - env->regs[R_ESI] = 0x100; - env->regs[R_ECX] = 0xff; - env->regs[R_EBP] = 0x0900; - env->regs[R_EDI] = 0xfffe; - - /* inform the emulator of the mmaped memory */ - page_set_flags(0x00000000, 0x110000, - PAGE_WRITE | PAGE_READ | PAGE_EXEC | PAGE_VALID); - - for(;;) { - ret = cpu_x86_exec(env); - switch(ret) { - case EXCP0D_GPF: - { - int int_num, ah; - int_num = *(uint8_t *)(env->segs[R_CS].base + env->eip + 1); - if (int_num != 0x21) - goto unknown_int; - ah = (env->regs[R_EAX] >> 8) & 0xff; - switch(ah) { - case 0x00: /* exit */ - exit(0); - case 0x02: /* write char */ - { - uint8_t c = env->regs[R_EDX]; - write(1, &c, 1); - } - break; - case 0x09: /* write string */ - { - uint8_t c; - for(;;) { - c = *seg_to_linear(env->segs[R_DS].selector, env->regs[R_EAX]); - if (c == '$') - break; - write(1, &c, 1); - } - env->regs[R_EAX] = (env->regs[R_EAX] & ~0xff) | '$'; - } - break; - default: - unknown_int: - fprintf(stderr, "unsupported int 0x%02x\n", int_num); - cpu_dump_state(env, stderr, fprintf, 0); - // exit(1); - } - env->eip += 2; - } - break; - default: - fprintf(stderr, "unhandled cpu_exec return code (0x%x)\n", ret); - cpu_dump_state(env, stderr, fprintf, 0); - exit(1); - } - } -} diff --git a/trace-events b/trace-events index 962caca598..514849aed8 100644 --- a/trace-events +++ b/trace-events @@ -59,8 +59,6 @@ virtio_console_chr_event(unsigned int port, int event) "port %u, event %d" bdrv_open_common(void *bs, const char *filename, int flags, const char *format_name) "bs %p filename \"%s\" flags %#x format_name \"%s\"" multiwrite_cb(void *mcb, int ret) "mcb %p ret %d" bdrv_aio_multiwrite(void *mcb, int num_callbacks, int num_reqs) "mcb %p num_callbacks %d num_reqs %d" -bdrv_aio_multiwrite_earlyfail(void *mcb) "mcb %p" -bdrv_aio_multiwrite_latefail(void *mcb, int i) "mcb %p i %d" bdrv_aio_discard(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p" bdrv_aio_flush(void *bs, void *opaque) "bs %p opaque %p" bdrv_aio_readv(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p" @@ -69,6 +67,7 @@ bdrv_lock_medium(void *bs, bool locked) "bs %p locked %d" bdrv_co_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" bdrv_co_writev(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" bdrv_co_io_em(void *bs, int64_t sector_num, int nb_sectors, int is_write, void *acb) "bs %p sector_num %"PRId64" nb_sectors %d is_write %d acb %p" +bdrv_co_copy_on_readv(void *bs, int64_t sector_num, int nb_sectors, int64_t cluster_sector_num, int cluster_nb_sectors) "bs %p sector_num %"PRId64" nb_sectors %d cluster_sector_num %"PRId64" cluster_nb_sectors %d" # hw/virtio-blk.c virtio_blk_req_complete(void *req, int status) "req %p status %d" @@ -631,3 +630,10 @@ win_helper_no_switch_pstate(uint32_t new_pstate_regs) "change_pstate: regs new=% win_helper_wrpil(uint32_t psrpil, uint32_t new_pil) "old=%x new=%x" win_helper_done(uint32_t tl) "tl=%d" win_helper_retry(uint32_t tl) "tl=%d" + +# dma-helpers.c +dma_bdrv_io(void *dbs, void *bs, int64_t sector_num, bool to_dev) "dbs=%p bs=%p sector_num=%" PRId64 " to_dev=%d" +dma_aio_cancel(void *dbs) "dbs=%p" +dma_complete(void *dbs, int ret, void *cb) "dbs=%p ret=%d cb=%p" +dma_bdrv_cb(void *dbs, int ret) "dbs=%p ret=%d" +dma_map_wait(void *dbs) "dbs=%p" diff --git a/ui/vnc-enc-zywrle-template.c b/ui/vnc-enc-zywrle-template.c index 4cde6e4362..561f7bfabb 100644 --- a/ui/vnc-enc-zywrle-template.c +++ b/ui/vnc-enc-zywrle-template.c @@ -9,7 +9,7 @@ * * * THE 'ZYWRLE' VNC CODEC SOURCE CODE IS (C) COPYRIGHT 2006 * * BY Hitachi Systems & Services, Ltd. * - * (Noriaki Yamazaki, Research & Developement Center) * + * (Noriaki Yamazaki, Research & Development Center) * * * * * ******************************************************************** diff --git a/ui/vnc-enc-zywrle.h b/ui/vnc-enc-zywrle.h index ac5d27a449..1ff40b1f40 100644 --- a/ui/vnc-enc-zywrle.h +++ b/ui/vnc-enc-zywrle.h @@ -8,7 +8,7 @@ * * * THE 'ZYWRLE' VNC CODEC SOURCE CODE IS (C) COPYRIGHT 2006 * * BY Hitachi Systems & Services, Ltd. * - * (Noriaki Yamazaki, Research & Developement Center) * + * (Noriaki Yamazaki, Research & Development Center) * * * * * ******************************************************************** diff --git a/ui/vnc-jobs-async.c b/ui/vnc-jobs-async.c index de5ea6b5d8..9b3016c129 100644 --- a/ui/vnc-jobs-async.c +++ b/ui/vnc-jobs-async.c @@ -318,7 +318,7 @@ void vnc_start_worker_thread(void) return ; q = vnc_queue_init(); - qemu_thread_create(&q->thread, vnc_worker_thread, q); + qemu_thread_create(&q->thread, vnc_worker_thread, q, QEMU_THREAD_DETACHED); queue = q; /* Set global queue */ } @@ -1732,7 +1732,7 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings) /* * Start from the end because the encodings are sent in order of preference. - * This way the prefered encoding (first encoding defined in the array) + * This way the preferred encoding (first encoding defined in the array) * will be set at the end of the loop. */ for (i = n_encodings - 1; i >= 0; i--) { @@ -2117,7 +2117,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) /* Compare expected vs actual challenge response */ if (memcmp(response, data, VNC_AUTH_CHALLENGE_SIZE) != 0) { - VNC_DEBUG("Client challenge reponse did not match\n"); + VNC_DEBUG("Client challenge response did not match\n"); goto reject; } else { VNC_DEBUG("Accepting VNC challenge response\n"); @@ -2183,7 +2183,7 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len) #ifdef CONFIG_VNC_TLS case VNC_AUTH_VENCRYPT: - VNC_DEBUG("Accept VeNCrypt auth\n");; + VNC_DEBUG("Accept VeNCrypt auth\n"); start_auth_vencrypt(vs); break; #endif /* CONFIG_VNC_TLS */ diff --git a/usb-linux.c b/usb-linux.c index d4426ea730..ab4c6930ca 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -148,6 +148,25 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_file, const char *device_name); static int usb_linux_update_endp_table(USBHostDevice *s); +static int usb_host_do_reset(USBHostDevice *dev) +{ + struct timeval s, e; + uint32_t usecs; + int ret; + + gettimeofday(&s, NULL); + ret = ioctl(dev->fd, USBDEVFS_RESET); + gettimeofday(&e, NULL); + usecs = (e.tv_sec - s.tv_sec) * 1000000; + usecs += e.tv_usec - s.tv_usec; + if (usecs > 1000000) { + /* more than a second, something is fishy, broken usb device? */ + fprintf(stderr, "husb: device %d:%d reset took %d.%06d seconds\n", + dev->bus_num, dev->addr, usecs / 1000000, usecs % 1000000); + } + return ret; +} + static struct endp_data *get_endp(USBHostDevice *s, int pid, int ep) { struct endp_data *eps = pid == USB_TOKEN_IN ? s->ep_in : s->ep_out; @@ -606,7 +625,7 @@ static void usb_host_handle_reset(USBDevice *dev) trace_usb_host_reset(s->bus_num, s->addr); - ioctl(s->fd, USBDEVFS_RESET); + usb_host_do_reset(s);; usb_host_claim_interfaces(s, 0); usb_linux_update_endp_table(s); @@ -1370,7 +1389,7 @@ static int usb_host_close(USBHostDevice *dev) if (dev->dev.attached) { usb_device_detach(&dev->dev); } - ioctl(dev->fd, USBDEVFS_RESET); + usb_host_do_reset(dev); close(dev->fd); dev->fd = -1; return 0; @@ -1381,7 +1400,7 @@ static void usb_host_exit_notifier(struct Notifier *n, void *data) USBHostDevice *s = container_of(n, USBHostDevice, exit); if (s->fd != -1) { - ioctl(s->fd, USBDEVFS_RESET); + usb_host_do_reset(s);; } } diff --git a/usb-redir.c b/usb-redir.c index c74b1560bf..a36f2a7cda 100644 --- a/usb-redir.c +++ b/usb-redir.c @@ -225,6 +225,10 @@ static int usbredir_write(void *priv, uint8_t *data, int count) { USBRedirDevice *dev = priv; + if (!dev->cs->opened) { + return 0; + } + return qemu_chr_fe_write(dev->cs, data, count); } @@ -538,9 +542,9 @@ static int usbredir_handle_data(USBDevice *udev, USBPacket *p) case USB_ENDPOINT_XFER_ISOC: return usbredir_handle_iso_data(dev, p, ep); case USB_ENDPOINT_XFER_BULK: - return usbredir_handle_bulk_data(dev, p, ep);; + return usbredir_handle_bulk_data(dev, p, ep); case USB_ENDPOINT_XFER_INT: - return usbredir_handle_interrupt_data(dev, p, ep);; + return usbredir_handle_interrupt_data(dev, p, ep); default: ERROR("handle_data ep %02X has unknown type %d\n", ep, dev->endpoint[EP2I(ep)].type); @@ -814,6 +818,8 @@ static int usbredir_initfn(USBDevice *udev) /* We'll do the attach once we receive the speed from the usb-host */ udev->auto_attach = 0; + /* Let the backend know we are ready */ + qemu_chr_fe_open(dev->cs); qemu_chr_add_handlers(dev->cs, usbredir_chardev_can_read, usbredir_chardev_read, usbredir_chardev_event, dev); @@ -837,6 +843,7 @@ static void usbredir_handle_destroy(USBDevice *udev) { USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev); + qemu_chr_fe_close(dev->cs); qemu_chr_delete(dev->cs); /* Note must be done after qemu_chr_close, as that causes a close event */ qemu_bh_delete(dev->open_close_bh); @@ -878,6 +885,11 @@ static void usbredir_device_connect(void *priv, { USBRedirDevice *dev = priv; + if (qemu_timer_pending(dev->attach_timer) || dev->dev.attached) { + ERROR("Received device connect while already connected\n"); + return; + } + switch (device_connect->speed) { case usb_redir_speed_low: DPRINTF("attaching low speed device\n"); @@ -906,19 +918,26 @@ static void usbredir_device_connect(void *priv, static void usbredir_device_disconnect(void *priv) { USBRedirDevice *dev = priv; + int i; /* Stop any pending attaches */ qemu_del_timer(dev->attach_timer); if (dev->dev.attached) { usb_device_detach(&dev->dev); - usbredir_cleanup_device_queues(dev); /* * Delay next usb device attach to give the guest a chance to see * see the detach / attach in case of quick close / open succession */ dev->next_attach_time = qemu_get_clock_ms(vm_clock) + 200; } + + /* Reset state so that the next dev connected starts with a clean slate */ + usbredir_cleanup_device_queues(dev); + memset(dev->endpoint, 0, sizeof(dev->endpoint)); + for (i = 0; i < MAX_ENDPOINTS; i++) { + QTAILQ_INIT(&dev->endpoint[i].bufpq); + } } static void usbredir_interface_info(void *priv, @@ -1010,6 +1029,10 @@ static void usbredir_iso_stream_status(void *priv, uint32_t id, DPRINTF("iso status %d ep %02X id %u\n", iso_stream_status->status, ep, id); + if (!dev->dev.attached) { + return; + } + dev->endpoint[EP2I(ep)].iso_error = iso_stream_status->status; if (iso_stream_status->status == usb_redir_stall) { DPRINTF("iso stream stopped by peer ep %02X\n", ep); @@ -1027,6 +1050,10 @@ static void usbredir_interrupt_receiving_status(void *priv, uint32_t id, DPRINTF("interrupt recv status %d ep %02X id %u\n", interrupt_receiving_status->status, ep, id); + if (!dev->dev.attached) { + return; + } + dev->endpoint[EP2I(ep)].interrupt_error = interrupt_receiving_status->status; if (interrupt_receiving_status->status == usb_redir_stall) { @@ -820,7 +820,7 @@ static void validate_bootdevices(char *devices) /* Allowed boot devices are: * a-b: floppy disk drives * c-f: IDE disk drives - * g-m: machine implementation dependant drives + * g-m: machine implementation dependent drives * n-p: network devices * It's up to each machine implementation to check if the given boot * devices match the actual hardware implementation and firmware @@ -953,8 +953,8 @@ static void numa_add(const char *optarg) node_mem[nodenr] = 0; } else { int64_t sval; - sval = strtosz(option, NULL); - if (sval < 0) { + sval = strtosz(option, &endptr); + if (sval < 0 || *endptr) { fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg); exit(1); } @@ -1513,7 +1513,7 @@ static void help(int exitcode) "ctrl-alt toggle mouse and keyboard grab\n" "\n" "When using -nographic, press 'ctrl-a h' to get some help.\n", - "qemu", + error_get_progname(), options_help); exit(exitcode); } @@ -2535,9 +2535,10 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_m: { int64_t value; + char *end; - value = strtosz(optarg, NULL); - if (value < 0) { + value = strtosz(optarg, &end); + if (value < 0 || *end) { fprintf(stderr, "qemu: invalid ram size: %s\n", optarg); exit(1); } diff --git a/xen-mapcache.c b/xen-mapcache.c index 7bcb86e4f8..9fecc64e97 100644 --- a/xen-mapcache.c +++ b/xen-mapcache.c @@ -351,7 +351,7 @@ void xen_invalidate_map_cache(void) MapCacheRev *reventry; /* Flush pending AIO before destroying the mapcache */ - qemu_aio_flush(); + bdrv_drain_all(); QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { DPRINTF("There should be no locked mappings at this time, " |