Misc changes for 2017-01-27
Subsystems (5)
The following changes since commit 3879284d6517dc22529395bdb259f4183b589127:
Merge remote-tracking branch 'remotes/berrange/tags/pull-qio-2017-01-23-2' into staging (2017-01-23 15:59:09 +0000)
are available in the git repository at:
git://github.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to 0a24326232f7c7f8c5ab9080784312d05d496e47:
memory: don't sign-extend 32-bit writes (2017-01-26 15:29:49 +0100)
----------------------------------------------------------------
* SCSI max_transfer support for scsi-generic (Eric)
* x86 SMI broadcast (Laszlo)
* Character device QOMification (Marc-André)
* Record/replay improvements (Pavel)
* iscsi fixes (Peter L.)
* "info mtree -f" command (Peter Xu)
* TSC clock rate reporting (Phil)
* DEVICE_CATEGORY_CPU (Thomas)
* Memory sign-extension fix (Ladi)
----------------------------------------------------------------
Eric Farman (3):
hw/scsi: Fix debug message of cdb structure in scsi-generic
block: Fix target variable of BLKSECTGET ioctl
block: get max_transfer limit for char (scsi-generic) devices
Ladi Prosek (1):
memory: don't sign-extend 32-bit writes
Laszlo Ersek (3):
hw/isa/lpc_ich9: add SMI feature negotiation via fw_cfg hw/isa/lpc_ich9: add broadcast SMI feature hw/isa/lpc_ich9: negotiate SMI broadcast on pc-q35-2.9+ machine types
Marc-André Lureau (20):
tests: fix linking test-char on win32
qemu-options: stdio is available on win32
char: add qemu_chr_fe_add_watch() Returns description
doc: fix spelling
char: use a const CharDriver
char: use a static array for backends
char: move callbacks in CharDriver
char: fold single-user functions in caller
char: introduce generic qemu_chr_get_kind()
char: use a feature bit for replay
char: allocate CharDriverState as a single object
bt: use qemu_chr_alloc()
char: rename CharDriverState Chardev
char: rename TCPChardev and NetChardev
spice-char: improve error reporting
char: use error_report()
gtk: overwrite the console.c char driver
baum: use a common prefix for chr callbacks
vc: use a common prefix for chr callbacks
chardev: qom-ify
Pavel Dovgalyuk (7):
icount: update instruction counter on apic patching
replay: improve interrupt handling
replay: don't use rtc clock on loadvm phase
savevm: add public save_vmstate function
replay: save/load initial state
replay: exception replay fix
apic: save apic_delivered flag
Peter Lieven (2):
block/iscsi: avoid data corruption with cache=writeback block/iscsi: statically link qemu_iscsi_opts
Peter Xu (2):
memory: tune mtree_print_mr() to dump mr type
memory: hmp: add "-f" for "info mtree"
Phil Dennis-Jordan (2):
x86-KVM: Supply TSC and APIC clock rates to guest like VMWare
pc: Enable vmware-cpuid-freq CPU option for 2.9+ machine types
Thomas Huth (1):
Introduce DEVICE_CATEGORY_CPU for CPU devices
MAINTAINERS | 1 + backends/baum.c | 102 +- backends/msmouse.c | 77 +- backends/rng-egd.c | 4 +- backends/testdev.c | 53 +- block/Makefile.objs | 1 + block/file-posix.c | 19 +- block/iscsi-opts.c | 69 ++ block/iscsi.c | 8 +- cpu-exec.c | 2 +- docs/replay.txt | 16 + exec.c | 2 +- gdbstub.c | 45 +- hmp-commands-info.hx | 6 +- hw/arm/fsl-imx25.c | 2 +- hw/arm/fsl-imx31.c | 2 +- hw/arm/fsl-imx6.c | 2 +- hw/arm/nseries.c | 2 +- hw/arm/omap2.c | 2 +- hw/arm/pxa2xx.c | 2 +- hw/arm/virt.c | 2 +- hw/bt/hci-csr.c | 64 +- hw/char/escc.c | 2 +- hw/char/exynos4210_uart.c | 2 +- hw/char/imx_serial.c | 2 +- hw/char/mcf_uart.c | 4 +- hw/char/omap_uart.c | 6 +- hw/char/parallel.c | 2 +- hw/char/serial-isa.c | 2 +- hw/char/serial.c | 4 +- hw/char/sh_serial.c | 2 +- hw/char/spapr_vty.c | 2 +- hw/char/virtio-console.c | 2 +- hw/core/qdev-properties-system.c | 4 +- hw/cpu/core.c | 8 + hw/display/milkymist-tmu2.c | 2 +- hw/display/sm501.c | 2 +- hw/i386/kvmvapic.c | 6 + hw/intc/apic_common.c | 33 + hw/isa/isa-bus.c | 2 +- hw/isa/lpc_ich9.c | 91 +- hw/isa/pc87312.c | 2 +- hw/lm32/lm32.h | 4 +- hw/lm32/milkymist-hw.h | 2 +- hw/mips/mips_malta.c | 4 +- hw/misc/ivshmem.c | 2 +- hw/misc/milkymist-pfpu.c | 2 +- hw/scsi/scsi-generic.c | 5 +- hw/timer/mc146818rtc.c | 15 +- hw/usb/ccid-card-passthru.c | 2 +- hw/usb/dev-serial.c | 6 +- hw/usb/redirect.c | 4 +- include/block/block.h | 1 + include/exec/memory.h | 2 +- include/hw/arm/exynos4210.h | 2 +- include/hw/arm/omap.h | 6 +- include/hw/bt.h | 4 +- include/hw/char/cadence_uart.h | 2 +- include/hw/char/escc.h | 2 +- include/hw/char/pl011.h | 4 +- include/hw/char/serial.h | 4 +- include/hw/char/xilinx_uartlite.h | 2 +- include/hw/cris/etraxfs.h | 2 +- include/hw/devices.h | 2 +- include/hw/i386/apic_internal.h | 2 + include/hw/i386/ich9.h | 13 + include/hw/i386/pc.h | 12 +- include/hw/m68k/mcf.h | 4 +- include/hw/ppc/spapr_vio.h | 2 +- include/hw/qdev-core.h | 1 + include/hw/qdev-properties.h | 2 +- include/hw/sh4/sh.h | 2 +- include/hw/sparc/grlib.h | 2 +- include/hw/xen/xen.h | 2 +- include/monitor/monitor.h | 2 +- include/qemu/typedefs.h | 2 +- include/sysemu/char.h | 155 +-- include/sysemu/replay.h | 13 +- include/sysemu/sysemu.h | 5 +- include/ui/console.h | 2 + include/ui/gtk.h | 2 +- include/ui/qemu-spice.h | 2 +- memory.c | 89 +- migration/savevm.c | 33 +- monitor.c | 10 +- net/colo-compare.c | 4 +- net/filter-mirror.c | 4 +- net/slirp.c | 2 +- net/vhost-user.c | 10 +- qdev-monitor.c | 1 + qemu-char.c | 1914 ++++++++++++++++++++----------------- qemu-options.hx | 12 +- qmp.c | 2 +- qom/cpu.c | 1 + qtest.c | 2 +- replay/replay-char.c | 8 +- replay/replay-snapshot.c | 17 + replay/replay.c | 5 + spice-qemu-char.c | 231 +++-- stubs/monitor.c | 2 +- stubs/replay.c | 4 +- target/i386/cpu.c | 1 + target/i386/cpu.h | 4 + target/i386/kvm.c | 36 +- target/i386/seg_helper.c | 1 + tests/Makefile.include | 2 +- tests/test-char.c | 10 +- tests/vhost-user-test.c | 4 +- translate-all.c | 2 + ui/console.c | 111 ++- ui/gtk.c | 86 +- vl.c | 59 +- xen-common-stub.c | 2 +- xen-common.c | 4 +- 114 files changed, 2192 insertions(+), 1448 deletions(-) create mode 100644 block/iscsi-opts.c
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 01/41] icount: update instruction counter on apic patching
From: Pavel Dovgalyuk <[email protected]>
kvmvapic patches the code when some instructions are executed. E.g. mov 0xff, 0xfffe0080 is interpreted as push 0xff/call ... This patching is also followed by some side effects (changing apic and guest memory state). Therefore deterministic execution should take this operation into account. This patch decreases icount when original mov instruction is trying to execute. Therefore patching becomes deterministic and can be replayed correctly.
Message-Id: <20170124071702.4572.17294.stgit@PASHA-ISP>
--- hw/i386/kvmvapic.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/i386/kvmvapic.c +6 -0
@@ -413,6 +413,12 @@ static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)if (!kvm_enabled ()) {cpu_get_tb_cpu_state (env, ¤t_pc, ¤t_cs_base, ¤t_flags); +/* Account this instruction, because we will exit the tb. +This is the first instruction in the block. Therefore +there is no need in restoring CPU state. */ +if (use_icount) { + --cs->icount_decr.u16.low; + } }pause_all_vcpus ();
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 02/41] replay: improve interrupt handling
In reply to Paolo BonziniFrom: Pavel Dovgalyuk <[email protected]>
This patch improves interrupt handling in record/replay mode.
Now "interrupt" event is saved only when cc->cpu_exec_interrupt returns true. This patch also adds missing return to cpu_exec_interrupt function.
Message-Id: <20170124071708.4572.64023.stgit@PASHA-ISP>
--- cpu-exec.c | 2 +- target/i386/seg_helper.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
cpu-exec.c +1 -1
@@ -508,8 +508,8 @@ static inline void cpu_handle_interrupt(CPUState *cpu,True when it is, and we should restart on a new TB, and via longjmp via cpu_loop_exit. */ else { -replay_interrupt ();if (cc->cpu_exec_interrupt (cpu, interrupt_request)) { +replay_interrupt (); *last_tb =NULL ; }/* The target hook may have updated the 'cpu->interrupt_request';
target/i386/seg_helper.c +1 -0
@@ -1331,6 +1331,7 @@ bool x86_cpu_exec_interrupt(CPUState *cs, int interrupt_request)#endif if (interrupt_request &CPU_INTERRUPT_SIPI ) {do_cpu_sipi (cpu); + ret = true; }else if (env->hflags2 &HF2_GIF_MASK ) {if ((interrupt_request &CPU_INTERRUPT_SMI ) && !(env->hflags &HF_SMM_MASK )) {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 03/41] replay: don't use rtc clock on loadvm phase
In reply to Paolo BonziniFrom: Pavel Dovgalyuk <[email protected]>
This patch disables the update of the periodic timer of mc146818rtc in record/replay mode. State of this timer is saved and therefore does not need to be updated in record/replay mode.
Read of RTC breaks the replay because all rtc reads have to be the same as in record mode.
Message-Id: <20170124071730.4572.41874.stgit@PASHA-ISP>
--- hw/timer/mc146818rtc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
hw/timer/mc146818rtc.c +11 -4
@@ -27,6 +27,7 @@#include "hw/hw.h" #include "qemu/timer.h" #include "sysemu/sysemu.h" +#include "sysemu/replay.h" #include "hw/timer/mc146818rtc.h" #include "qapi/visitor.h" #include "qapi-event.h"
@@ -734,10 +735,16 @@ static int rtc_post_load(void *opaque, int version_id)check_update_timer (s); } -uint64_t now =qemu_clock_get_ns (rtc_clock); -if (now < s->next_periodic_time || - now > (s->next_periodic_time +get_max_clock_jump ())) { -periodic_timer_update (s,qemu_clock_get_ns (rtc_clock)); +/* The periodic timer is deterministic in record/replay mode, +* so there is no need to update it after loading the vmstate. +* Reading RTC here would misalign record and replay. +*/ +if (replay_mode ==REPLAY_MODE_NONE ) { +uint64_t now =qemu_clock_get_ns (rtc_clock); +if (now < s->next_periodic_time || + now > (s->next_periodic_time +get_max_clock_jump ())) { +periodic_timer_update (s,qemu_clock_get_ns (rtc_clock)); + } }#ifdef TARGET_I386
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 04/41] savevm: add public save_vmstate function
In reply to Paolo BonziniFrom: Pavel Dovgalyuk <[email protected]>
This patch introduces save_vmstate function to allow saving and loading vmstates from the replay module.
Message-Id: <20170124071741.4572.13714.stgit@PASHA-ISP>
--- include/sysemu/sysemu.h | 1 + migration/savevm.c | 33 ++++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-)
include/sysemu/sysemu.h +1 -0
@@ -74,6 +74,7 @@ void qemu_add_machine_init_done_notifier(Notifier *notify);void qemu_remove_machine_init_done_notifier (Notifier *notify);void hmp_savevm (Monitor *mon,const QDict *qdict); +int save_vmstate (Monitor *mon,const char *name);int load_vmstate (const char *name);void hmp_delvm (Monitor *mon,const QDict *qdict);void hmp_info_snapshots (Monitor *mon,const QDict *qdict);
migration/savevm.c +22 -11
@@ -2039,38 +2039,40 @@ int qemu_loadvm_state(QEMUFile *f)return ret; } -void hmp_savevm (Monitor *mon,const QDict *qdict) +int save_vmstate (Monitor *mon,const char *name) {BlockDriverState *bs, *bs1;QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1; -int ret; +int ret =-1 ;QEMUFile *f;int saved_vm_running;uint64_t vm_state_size;qemu_timeval tv;struct tm tm; -const char *name =qdict_get_try_str (qdict,"name" );Error *local_err =NULL ;AioContext *aio_context;if (!bdrv_all_can_snapshot (&bs)) {monitor_printf (mon,"Device '%s' is writable but does not " "support snapshots.\n" ,bdrv_get_device_name (bs)); -return ; +return ret; }/* Delete old snapshots of the same name */ -if (name &&bdrv_all_delete_snapshot (name, &bs1, &local_err) <0 ) { -error_reportf_err (local_err, -"Error while deleting snapshot on device '%s': " , -bdrv_get_device_name (bs1)); -return ; +if (name) { + ret =bdrv_all_delete_snapshot (name, &bs1, &local_err); +if (ret <0 ) { +error_reportf_err (local_err, +"Error while deleting snapshot on device '%s': " , +bdrv_get_device_name (bs1)); +return ret; + } } bs =bdrv_all_find_vmstate_bs ();if (bs ==NULL ) {monitor_printf (mon,"No block device can accept snapshots\n" ); -return ; +return ret; } aio_context =bdrv_get_aio_context (bs);
@@ -2079,7 +2081,7 @@ void hmp_savevm(Monitor *mon, const QDict *qdict) ret =global_state_store ();if (ret) {monitor_printf (mon,"Error saving global state\n" ); -return ; +return ret; }vm_stop (RUN_STATE_SAVE_VM );
@@ -2125,13 +2127,22 @@ void hmp_savevm(Monitor *mon, const QDict *qdict)if (ret <0 ) {monitor_printf (mon,"Error while creating snapshot on '%s'\n" ,bdrv_get_device_name (bs)); + goto the_end; } + ret =0 ; + the_end:aio_context_release (aio_context);if (saved_vm_running) {vm_start (); } +return ret; +} + +void hmp_savevm (Monitor *mon,const QDict *qdict) +{ +save_vmstate (mon,qdict_get_try_str (qdict,"name" )); }void qmp_xen_save_devices_state (const char *filename,Error **errp)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 05/41] replay: save/load initial state
In reply to Paolo BonziniFrom: Pavel Dovgalyuk <[email protected]>
This patch implements initial vmstate creation or loading at the start of record/replay. It is needed for rewinding the execution in the replay mode.
v4 changes:
- snapshots are not created by default anymore
v3 changes:
- added rrsnapshot option
Message-Id: <20170124071746.4572.61449.stgit@PASHA-ISP>
--- docs/replay.txt | 16 ++++++++++++++++ include/sysemu/replay.h | 9 +++++++++ qemu-options.hx | 8 ++++++-- replay/replay-snapshot.c | 17 +++++++++++++++++ replay/replay.c | 5 +++++ vl.c | 7 ++++++- 6 files changed, 59 insertions(+), 3 deletions(-)
docs/replay.txt +16 -0
@@ -196,6 +196,22 @@ is recorded to the log. In replay phase the queue is matched with events read from the log. Therefore block devices requests are processed deterministically. +Snapshotting +------------ + +New VM snapshots may be created in replay mode. They can be used later +to recover the desired VM state. All VM states created in replay mode +are associated with the moment of time in the replay scenario. +After recovering the VM state replay will start from that position. + +Default starting snapshot name may be specified with icount field +rrsnapshot as follows: + -icount shift=7,rr=record,rrfile=replay.bin,rrsnapshot=snapshot_name + +This snapshot is created at start of recording and restored at start +of replaying. It also can be loaded while replaying to roll back +the execution. + Network devices ---------------
include/sysemu/replay.h +9 -0
@@ -43,6 +43,9 @@ typedef struct ReplayNetState ReplayNetState;extern ReplayMode replay_mode; +/* Name of the initial VM snapshot */ +extern char *replay_snapshot; +/* Replay process control functions */ /*! Enables recording or saving event log with specified parameters */
@@ -149,4 +152,10 @@ void replay_unregister_net(ReplayNetState *rns);void replay_net_packet_event (ReplayNetState *rns,unsigned flags,const struct iovec *iov,int iovcnt); +/* VM state operations */ + +/*! Called at the start of execution. +Loads or saves initial vmstate depending on execution mode. */ +void replay_vmstate_init (void ); +#endif
qemu-options.hx +6 -2
@@ -3401,12 +3401,12 @@ re-inject them. ETEXI DEF("icount", HAS_ARG, QEMU_OPTION_icount, \ - "-icount [shift=N|auto][,align=on|off][,sleep=on|off,rr=record|replay,rrfile=<filename>]\n" \ + "-icount [shift=N|auto][,align=on|off][,sleep=on|off,rr=record|replay,rrfile=<filename>,rrsnapshot=<snapshot>]\n" \ " enable virtual instruction counter with 2^N clock ticks per\n" \ " instruction, enable aligning the host and virtual clocks\n" \ " or disable real time cpu sleeping\n", QEMU_ARCH_ALL) STEXI -@item -icount [shift=@var{N}|auto][,rr=record|replay,rrfile=@var{filename}] +@item -icount [shift=@var{N}|auto][,rr=record|replay,rrfile=@var{filename},rrsnapshot=@var{snapshot}] @findex -icount Enable virtual instruction counter. The virtual cpu will execute one instruction every 2^@var{N} ns of virtual time. If @code{auto} is specified
@@ -3439,6 +3439,10 @@ when the shift value is high (how high depends on the host machine). When @option{rr} option is specified deterministic record/replay is enabled. Replay log is written into @var{filename} file in record mode and read from this file in replay mode. + +Option rrsnapshot is used to create new vm snapshot named @var{snapshot} +at the start of execution recording. In replay mode this option is used +to load the initial VM state. ETEXI DEF("watchdog", HAS_ARG, QEMU_OPTION_watchdog, \
replay/replay-snapshot.c +17 -0
@@ -59,3 +59,20 @@ void replay_vmstate_register(void) {vmstate_register (NULL ,0 , &vmstate_replay, &replay_state); } + +void replay_vmstate_init (void ) +{ +if (replay_snapshot) { +if (replay_mode ==REPLAY_MODE_RECORD ) { +if (save_vmstate (cur_mon, replay_snapshot) !=0 ) { +error_report ("Could not create snapshot for icount record" ); +exit (1 ); + } + }else if (replay_mode ==REPLAY_MODE_PLAY ) { +if (load_vmstate (replay_snapshot) !=0 ) { +error_report ("Could not load snapshot for icount replay" ); +exit (1 ); + } + } + } +}
replay/replay.c +5 -0
@@ -26,6 +26,7 @@#define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t))ReplayMode replay_mode =REPLAY_MODE_NONE ; +char *replay_snapshot;/* Name of replay file */ static char *replay_filename;
@@ -292,6 +293,7 @@ void replay_configure(QemuOpts *opts)exit (1 ); } + replay_snapshot =g_strdup (qemu_opt_get (opts,"rrsnapshot" ));replay_vmstate_register ();replay_enable (fname, mode);
@@ -346,6 +348,9 @@ void replay_finish(void) replay_filename =NULL ; } +g_free (replay_snapshot); + replay_snapshot =NULL ; +replay_finish_events ();replay_mutex_destroy (); }
vl.c +6 -1
@@ -464,6 +464,9 @@ static QemuOptsList qemu_icount_opts = { }, { .name = "rrfile", .type = QEMU_OPT_STRING, + }, { + .name = "rrsnapshot", + .type = QEMU_OPT_STRING, }, {/* end of list */ } },
@@ -4619,7 +4622,9 @@ int main(int argc, char **argv, char **envp)replay_checkpoint (CHECKPOINT_RESET );qemu_system_reset (VMRESET_SILENT );register_global_state (); -if (loadvm) { +if (replay_mode !=REPLAY_MODE_NONE ) { +replay_vmstate_init (); + }else if (loadvm) {if (load_vmstate (loadvm) <0 ) { autostart =0 ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 06/41] replay: exception replay fix
In reply to Paolo BonziniFrom: Pavel Dovgalyuk <[email protected]>
This patch fixes replaying the exception when TB cache is full. It breaks cpu loop execution through setting exception_index to process such queued work as TB flush.
v8: moved setting of exeption_index to tb_gen_code
Message-Id: <20170126123418.5412.33815.stgit@PASHA-ISP>
--- translate-all.c | 2 ++ 1 file changed, 2 insertions(+)
translate-all.c +2 -0
@@ -1290,6 +1290,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu,/* flush must be done */ tb_flush (cpu);mmap_unlock (); +/* Make the execution loop process the flush as soon as possible. */ + cpu->exception_index =EXCP_INTERRUPT ;cpu_loop_exit (cpu); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 07/41] apic: save apic_delivered flag
In reply to Paolo BonziniFrom: Pavel Dovgalyuk <[email protected]>
This patch implements saving/restoring of static apic_delivered variable.
v8: saving static variable only for one of the APICs
Message-Id: <20170126123429.5412.94368.stgit@PASHA-ISP>
--- hw/intc/apic_common.c | 33 +++++++++++++++++++++++++++++++++ include/hw/i386/apic_internal.h | 2 ++ 2 files changed, 35 insertions(+)
hw/intc/apic_common.c +33 -0
@@ -385,6 +385,25 @@ static bool apic_common_sipi_needed(void *opaque)return s->wait_for_sipi !=0 ; } +static bool apic_irq_delivered_needed (void *opaque) +{ +APICCommonState *s =APIC_COMMON (opaque); +return s->cpu ==X86_CPU (first_cpu) && apic_irq_delivered !=0 ; +} + +static void apic_irq_delivered_pre_save (void *opaque) +{ +APICCommonState *s =APIC_COMMON (opaque); + s->apic_irq_delivered = apic_irq_delivered; +} + +static int apic_irq_delivered_post_load (void *opaque,int version_id) +{ +APICCommonState *s =APIC_COMMON (opaque); + apic_irq_delivered = s->apic_irq_delivered; +return 0 ; +} +static const VMStateDescription vmstate_apic_common_sipi = { .name ="apic_sipi" , .version_id =1 ,
@@ -397,6 +416,19 @@ static const VMStateDescription vmstate_apic_common_sipi = { } }; +static const VMStateDescription vmstate_apic_irq_delivered = { + .name ="apic_irq_delivered" , + .version_id =1 , + .minimum_version_id =1 , + .needed = apic_irq_delivered_needed, + .pre_save = apic_irq_delivered_pre_save, + .post_load = apic_irq_delivered_post_load, + .fields = (VMStateField []) { +VMSTATE_INT32 (apic_irq_delivered, APICCommonState), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_apic_common = { .name ="apic" , .version_id =3 ,
@@ -431,6 +463,7 @@ static const VMStateDescription vmstate_apic_common = { }, .subsections = (const VMStateDescription*[]) { &vmstate_apic_common_sipi, + &vmstate_apic_irq_delivered,NULL } };
include/hw/i386/apic_internal.h +2 -0
@@ -189,6 +189,8 @@ struct APICCommonState {DeviceState *vapic;hwaddr vapic_paddr;/* note: persistence via kvmvapic */ bool legacy_instance_id; + +int apic_irq_delivered;/* for saving static variable */ }; typedef struct VAPICState {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 09/41] memory: hmp: add "-f" for "info mtree"
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
Adding one more option "-f" for "info mtree" to dump the flat views of all the address spaces.
This will be useful to debug the memory rendering logic, also it'll be much easier with it to know what memory region is handling what address range.
Message-Id: <[email protected]>
--- hmp-commands-info.hx | 6 +++--- include/exec/memory.h | 2 +- memory.c | 41 ++++++++++++++++++++++++++++++++++++++++- monitor.c | 4 +++- 4 files changed, 47 insertions(+), 6 deletions(-)
hmp-commands-info.hx +3 -3
@@ -249,9 +249,9 @@ ETEXI { .name = "mtree", - .args_type = "", - .params = "", - .help = "show memory tree", + .args_type = "flatview:-f", + .params = "[-f]", + .help = "show memory tree (-f: dump flat view for address spaces)", .cmd = hmp_info_mtree, },
include/exec/memory.h +1 -1
@@ -1250,7 +1250,7 @@ void memory_global_dirty_log_start(void);*/ void memory_global_dirty_log_stop (void ); -void mtree_info (fprintf_function mon_printf,void *f); +void mtree_info (fprintf_function mon_printf,void *f,bool flatview);/** * memory_region_dispatch_read: perform a read directly to the specified
memory.c +40 -1
52 lines not on this page · raw message
monitor.c +3 -1
@@ -1529,7 +1529,9 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict)static void hmp_info_mtree (Monitor *mon,const QDict *qdict) { -mtree_info ((fprintf_function )monitor_printf, mon); +bool flatview =qdict_get_try_bool (qdict,"flatview" , false); + +mtree_info ((fprintf_function )monitor_printf, mon, flatview); }static void hmp_info_numa (Monitor *mon,const QDict *qdict)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 08/41] memory: tune mtree_print_mr() to dump mr type
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
We were dumping RW bits for each memory region, that might be confusing. It'll make more sense to dump the memory region type directly rather than the RW bits since that's how the bits are derived.
Meanwhile, with some slight cleanup in the function.
Message-Id: <[email protected]>
--- memory.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-)
memory.c +27 -21
@@ -2450,6 +2450,21 @@ void address_space_destroy(AddressSpace *as)call_rcu (as, do_address_space_destroy, rcu); } +static const char *memory_region_type (MemoryRegion *mr) +{ +if (memory_region_is_ram_device (mr)) { +return "ramd" ; + }else if (memory_region_is_romd (mr)) { +return "romd" ; + }else if (memory_region_is_rom (mr)) { +return "rom" ; + }else if (memory_region_is_ram (mr)) { +return "ram" ; + }else { +return "i/o" ; + } +} +typedef struct MemoryRegionList MemoryRegionList ;struct MemoryRegionList {
@@ -2459,6 +2474,10 @@ struct MemoryRegionList { typedef QTAILQ_HEAD(queue, MemoryRegionList) MemoryRegionListHead; +#define MR_SIZE (size) (int128_nz(size) ? (hwaddr)int128_get64( \ + int128_sub((size), int128_one())) : 0) +#define MTREE_INDENT " " + static void mtree_print_mr(fprintf_function mon_printf, void *f, const MemoryRegion *mr, unsigned int level, hwaddr base,
@@ -2474,7 +2493,7 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f, }for (i =0 ; i < level; i++) { -mon_printf (f," " ); +mon_printf (f,MTREE_INDENT ); }if (mr->alias) {
@@ -2494,37 +2513,24 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f,QTAILQ_INSERT_TAIL (alias_print_queue, ml, queue); }mon_printf (f, TARGET_FMT_plx"-" TARGET_FMT_plx -" (prio %d, %c%c): alias %s @%s " TARGET_FMT_plx +" (prio %d, %s): alias %s @%s " TARGET_FMT_plx"-" TARGET_FMT_plx"%s\n" , base + mr->addr, - base + mr->addr - + (int128_nz (mr->size) ? - (hwaddr )int128_get64 (int128_sub (mr->size, -int128_one ())) :0 ), + base + mr->addr +MR_SIZE (mr->size), mr->priority, - mr->romd_mode ?'R' :'-' , - !mr->readonly && !(mr->rom_device && mr->romd_mode) ?'W' - :'-' , +memory_region_type ((MemoryRegion *)mr),memory_region_name (mr),memory_region_name (mr->alias), mr->alias_offset, - mr->alias_offset - + (int128_nz (mr->size) ? - (hwaddr )int128_get64 (int128_sub (mr->size, -int128_one ())) :0 ), + mr->alias_offset +MR_SIZE (mr->size), mr->enabled ?"" :" [disabled]" ); }else {mon_printf (f, - TARGET_FMT_plx"-" TARGET_FMT_plx" (prio %d, %c%c): %s%s\n" , + TARGET_FMT_plx"-" TARGET_FMT_plx" (prio %d, %s): %s%s\n" , base + mr->addr, - base + mr->addr - + (int128_nz (mr->size) ? - (hwaddr )int128_get64 (int128_sub (mr->size, -int128_one ())) :0 ), + base + mr->addr +MR_SIZE (mr->size), mr->priority, - mr->romd_mode ?'R' :'-' , - !mr->readonly && !(mr->rom_device && mr->romd_mode) ?'W' - :'-' , +memory_region_type ((MemoryRegion *)mr),memory_region_name (mr), mr->enabled ?"" :" [disabled]" ); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 10/41] hw/isa/lpc_ich9: add SMI feature negotiation via fw_cfg
In reply to Paolo BonziniFrom: Laszlo Ersek <[email protected]>
Introduce the following fw_cfg files:
- "etc/smi/supported-features": a little endian uint64_t feature bitmap, presenting the features known by the host to the guest. Read-only for the guest.
The content of this file will be determined via bit-granularity ICH9-LPC device properties, to be introduced later. For now, the bitmask is left zeroed. The bits will be set from machine type compat properties and on the QEMU command line, hence this file is not migrated.
- "etc/smi/requested-features": a little endian uint64_t feature bitmap, representing the features the guest would like to request. Read-write for the guest.
The guest can freely (re)write this file, it has no direct consequence. Initial value is zero. A nonzero value causes the SMI-related fw_cfg files and fields that are under guest influence to be migrated.
- "etc/smi/features-ok": contains a uint8_t value, and it is read-only for the guest. When the guest selects the associated fw_cfg key, the guest features are validated against the host features. In case of error, the negotiation doesn't proceed, and the "features-ok" file remains zero. In case of success, the "features-ok" file becomes (uint8_t)1, and the negotiated features are locked down internally (to which no further changes are possible until reset).
The initial value is zero. A nonzero value causes the SMI-related fw_cfg files and fields that are under guest influence to be migrated.
The C-language fields backing the "supported-features" and "requested-features" files are uint8_t arrays. This is because they carry guest-side representation (our choice is little endian), while VMSTATE_UINT64() assumes / implies host-side endianness for any uint64_t fields. If we migrate a guest between hosts with different endiannesses (which is possible with TCG), then the host-side value is preserved, and the host-side representation is translated. This would be visible to the guest through fw_cfg, unless we used plain byte arrays. So we do.
Message-Id: <[email protected]>
--- hw/isa/lpc_ich9.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/i386/ich9.h | 10 +++++++ 2 files changed, 89 insertions(+)
hw/isa/lpc_ich9.c +79 -0
@@ -48,6 +48,8 @@#include "exec/address-spaces.h" #include "sysemu/sysemu.h" #include "qom/cpu.h" +#include "hw/nvram/fw_cfg.h" +#include "qemu/cutils.h" /*****************************************************************************/ /* ICH9 LPC PCI to ISA bridge */
@@ -360,13 +362,62 @@ static void ich9_set_sci(void *opaque, int irq_num, int level) } } +static void smi_features_ok_callback (void *opaque) +{ +ICH9LPCState *lpc = opaque; +uint64_t guest_features; + +if (lpc->smi_features_ok) { +/* negotiation already complete, features locked */ +return ; + } + +memcpy (&guest_features, lpc->smi_guest_features_le,sizeof guest_features); +le64_to_cpus (&guest_features); +if (guest_features & ~lpc->smi_host_features) { +/* guest requests invalid features, leave @features_ok at zero */ +return ; + } + +/* valid feature subset requested, lock it down, report success */ + lpc->smi_negotiated_features = guest_features; + lpc->smi_features_ok =1 ; +} +void ich9_lpc_pm_init (PCIDevice *lpc_pci,bool smm_enabled) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (lpc_pci);qemu_irq sci_irq; +FWCfgState *fw_cfg =fw_cfg_find (); sci_irq =qemu_allocate_irq (ich9_set_sci, lpc,0 );ich9_pm_init (lpc_pci, &lpc->pm, smm_enabled, sci_irq); + +if (lpc->smi_host_features && fw_cfg) { +uint64_t host_features_le; + + host_features_le =cpu_to_le64 (lpc->smi_host_features); +memcpy (lpc->smi_host_features_le, &host_features_le, +sizeof host_features_le); +fw_cfg_add_file (fw_cfg,"etc/smi/supported-features" , + lpc->smi_host_features_le, +sizeof lpc->smi_host_features_le); + +/* The other two guest-visible fields are cleared on device reset, we +* just link them into fw_cfg here. +*/ +fw_cfg_add_file_callback (fw_cfg,"etc/smi/requested-features" , +NULL ,NULL , + lpc->smi_guest_features_le, +sizeof lpc->smi_guest_features_le, + false); +fw_cfg_add_file_callback (fw_cfg,"etc/smi/features-ok" , + smi_features_ok_callback, lpc, + &lpc->smi_features_ok, +sizeof lpc->smi_features_ok, + true); + } +ich9_lpc_reset (&lpc->d.qdev); }
@@ -507,6 +558,10 @@ static void ich9_lpc_reset(DeviceState *qdev) lpc->sci_level =0 ; lpc->rst_cnt =0 ; + +memset (lpc->smi_guest_features_le,0 ,sizeof lpc->smi_guest_features_le); + lpc->smi_features_ok =0 ; + lpc->smi_negotiated_features =0 ; }/* root complex register block is mapped into memory space */
@@ -668,6 +723,29 @@ static const VMStateDescription vmstate_ich9_rst_cnt = { } }; +static bool ich9_smi_feat_needed (void *opaque) +{ +ICH9LPCState *lpc = opaque; + +return !buffer_is_zero (lpc->smi_guest_features_le, +sizeof lpc->smi_guest_features_le) || + lpc->smi_features_ok; +} + +static const VMStateDescription vmstate_ich9_smi_feat = { + .name ="ICH9LPC/smi_feat" , + .version_id =1 , + .minimum_version_id =1 , + .needed = ich9_smi_feat_needed, + .fields = (VMStateField []) { +VMSTATE_UINT8_ARRAY (smi_guest_features_le, ICH9LPCState, +sizeof (uint64_t )), +VMSTATE_UINT8 (smi_features_ok, ICH9LPCState), +VMSTATE_UINT64 (smi_negotiated_features, ICH9LPCState), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_ich9_lpc = { .name ="ICH9LPC" , .version_id =1 ,
@@ -683,6 +761,7 @@ static const VMStateDescription vmstate_ich9_lpc = { }, .subsections = (const VMStateDescription*[]) { &vmstate_ich9_rst_cnt, + &vmstate_ich9_smi_feat,NULL } };
include/hw/i386/ich9.h +10 -0
@@ -64,6 +64,16 @@ typedef struct ICH9LPCState {uint8_t rst_cnt;MemoryRegion rst_cnt_mem; +/* SMI feature negotiation via fw_cfg */ +uint64_t smi_host_features;/* guest-invisible, host endian */ +uint8_t smi_host_features_le[8 ];/* guest-visible, read-only, little +* endian uint64_t */ +uint8_t smi_guest_features_le[8 ];/* guest-visible, read-write, little +* endian uint64_t */ +uint8_t smi_features_ok;/* guest-visible, read-only; selecting it +* triggers feature lockdown */ +uint64_t smi_negotiated_features;/* guest-invisible, host endian */ +/* isa bus */ ISABus *isa_bus;MemoryRegion rcrb_mem;/* root complex register block */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 11/41] hw/isa/lpc_ich9: add broadcast SMI feature
In reply to Paolo BonziniFrom: Laszlo Ersek <[email protected]>
The generic edk2 SMM infrastructure prefers EFI_SMM_CONTROL2_PROTOCOL.Trigger() to inject an SMI on each processor. If Trigger() only brings the current processor into SMM, then edk2 handles it in the following ways:
(1) If Trigger() is executed by the BSP (which is guaranteed before ExitBootServices(), but is not necessarily true at runtime), then:
(a) If edk2 has been configured for "traditional" SMM synchronization, then the BSP sends directed SMIs to the APs with APIC delivery, bringing them into SMM individually. Then the BSP runs the SMI handler / dispatcher.
(b) If edk2 has been configured for "relaxed" SMM synchronization, then the APs that are not already in SMM are not brought in, and the BSP runs the SMI handler / dispatcher.
(2) If Trigger() is executed by an AP (which is possible after ExitBootServices(), and can be forced e.g. by "taskset -c 1 efibootmgr"), then the AP in question brings in the BSP with a directed SMI, and the BSP runs the SMI handler / dispatcher.
The smaller problem with (1a) and (2) is that the BSP and AP synchronization is slow. For example, the "taskset -c 1 efibootmgr" command from (2) can take more than 3 seconds to complete, because efibootmgr accesses non-volatile UEFI variables intensively.
The larger problem is that QEMU's current behavior diverges from the behavior usually seen on physical hardware, and that keeps exposing obscure corner cases, race conditions and other instabilities in edk2, which generally expects / prefers a software SMI to affect all CPUs at once.
Therefore introduce the "broadcast SMI" feature that causes QEMU to inject the SMI on all VCPUs.
While the original posting of this patch
<http://lists.nongnu.org/archive/html/qemu-devel/2015-10/msg05658.html>
only intended to speed up (2), based on our recent "stress testing" of SMM this patch actually provides functional improvements.
Message-Id: <[email protected]>
--- hw/isa/lpc_ich9.c | 10 +++++++++- include/hw/i386/ich9.h | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-)
hw/isa/lpc_ich9.c +9 -1
@@ -437,7 +437,15 @@ static void ich9_apm_ctrl_changed(uint32_t val, void *arg)/* SMI_EN = PMBASE + 30. SMI control and enable register */ if (lpc->pm.smi_en &ICH9_PMIO_SMI_EN_APMC_EN ) { -cpu_interrupt (current_cpu,CPU_INTERRUPT_SMI ); +if (lpc->smi_negotiated_features & + (UINT64_C (1 ) <<ICH9_LPC_SMI_F_BROADCAST_BIT )) { +CPUState *cs; +CPU_FOREACH (cs) { +cpu_interrupt (cs,CPU_INTERRUPT_SMI ); + } + }else { +cpu_interrupt (current_cpu,CPU_INTERRUPT_SMI ); + } } }
include/hw/i386/ich9.h +3 -0
@@ -250,4 +250,7 @@ Object *ich9_lpc_find(void);#define ICH9_SMB_HST_D1 0x06#define ICH9_SMB_HOST_BLOCK_DB 0x07 +/* bit positions used in fw_cfg SMI feature negotiation */ +#define ICH9_LPC_SMI_F_BROADCAST_BIT 0 +#endif /* HW_ICH9_H */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 12/41] hw/isa/lpc_ich9: negotiate SMI broadcast on pc-q35-2.9+ machine types
In reply to Paolo BonziniFrom: Laszlo Ersek <[email protected]>
Message-Id: <[email protected]>
--- hw/isa/lpc_ich9.c | 2 ++ include/hw/i386/pc.h | 6 ++++++ 2 files changed, 8 insertions(+)
hw/isa/lpc_ich9.c +2 -0
@@ -776,6 +776,8 @@ static const VMStateDescription vmstate_ich9_lpc = {static Property ich9_lpc_properties[] = {DEFINE_PROP_BOOL ("noreboot" , ICH9LPCState, pin_strap.spkr_hi, true), +DEFINE_PROP_BIT64 ("x-smi-broadcast" , ICH9LPCState, smi_host_features, +ICH9_LPC_SMI_F_BROADCAST_BIT , true),DEFINE_PROP_END_OF_LIST (), };
include/hw/i386/pc.h +6 -0
@@ -381,6 +381,12 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); .property = "x-mach-use-reliable-get-clock",\ .value = "off",\ },\ + {\ + .driver = "ICH9-LPC",\ + .property = "x-smi-broadcast",\ + .value = "off",\ + },\ +#define PC_COMPAT_2_7 \ HW_COMPAT_2_7 \
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 13/41] block/iscsi: avoid data corruption with cache=writeback
In reply to Paolo BonziniFrom: Peter Lieven <[email protected]>
nb_cls_shrunk in iscsi_allocmap_update can become -1 if the request starts and ends within the same cluster. This results in passing -1 to bitmap_set and bitmap_clear and they don't handle negative values properly. In the end this leads to data corruption.
Message-Id: <[email protected]>
--- block/iscsi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
block/iscsi.c +6 -2
@@ -499,14 +499,18 @@ iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sector_num,if (allocated) {bitmap_set (iscsilun->allocmap, cl_num_expanded, nb_cls_expanded); }else { -bitmap_clear (iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk); +if (nb_cls_shrunk >0 ) { +bitmap_clear (iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk); + } }if (iscsilun->allocmap_valid ==NULL ) {return ; }if (valid) { -bitmap_set (iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk); +if (nb_cls_shrunk >0 ) { +bitmap_set (iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk); + } }else {bitmap_clear (iscsilun->allocmap_valid, cl_num_expanded, nb_cls_expanded);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 14/41] Introduce DEVICE_CATEGORY_CPU for CPU devices
In reply to Paolo BonziniFrom: Thomas Huth <[email protected]>
Now that CPUs show up in the help text of "-device ?", we should group them into an appropriate category.
Message-Id: <[email protected]>
--- hw/cpu/core.c | 8 ++++++++ include/hw/qdev-core.h | 1 + qdev-monitor.c | 1 + qom/cpu.c | 1 + 4 files changed, 11 insertions(+)
hw/cpu/core.c +8 -0
@@ -72,10 +72,18 @@ static void cpu_core_instance_init(Object *obj) core->nr_threads = smp_threads; } +static void cpu_core_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + +set_bit (DEVICE_CATEGORY_CPU , dc->categories); +} +static const TypeInfo cpu_core_type_info = { .name =TYPE_CPU_CORE , .parent =TYPE_DEVICE , .abstract = true, + .class_init = cpu_core_class_init, .instance_size =sizeof (CPUCore), .instance_init = cpu_core_instance_init, };
include/hw/qdev-core.h +1 -0
@@ -26,6 +26,7 @@ typedef enum DeviceCategory {DEVICE_CATEGORY_DISPLAY ,DEVICE_CATEGORY_SOUND ,DEVICE_CATEGORY_MISC , +DEVICE_CATEGORY_CPU , DEVICE_CATEGORY_MAX } DeviceCategory;
qdev-monitor.c +1 -0
@@ -136,6 +136,7 @@ static void qdev_print_devinfos(bool show_no_user) [DEVICE_CATEGORY_DISPLAY] = "Display", [DEVICE_CATEGORY_SOUND] = "Sound", [DEVICE_CATEGORY_MISC] = "Misc", + [DEVICE_CATEGORY_CPU] = "CPU", [DEVICE_CATEGORY_MAX ] ="Uncategorized" , }; GSList *list, *elt;
qom/cpu.c +1 -0
@@ -415,6 +415,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->cpu_exec_enter = cpu_common_noop; k->cpu_exec_exit = cpu_common_noop; k->cpu_exec_interrupt = cpu_common_exec_interrupt; +set_bit (DEVICE_CATEGORY_CPU , dc->categories); dc->realize = cpu_common_realizefn; dc->unrealize = cpu_common_unrealizefn;/*
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 15/41] hw/scsi: Fix debug message of cdb structure in scsi-generic
In reply to Paolo BonziniFrom: Eric Farman <[email protected]>
When running with debug enabled, the scsi-generic cdb that is dumped skips byte 0 of the command, which is the opcode. This makes identifying which command is being issued/completed a little difficult. Example:
0x00 0x00 0x01 0x00 0x00
scsi-generic: scsi_read_data 0x0
scsi-generic: Data ready tag=0x0 len=164
scsi-generic: scsi_read_data 0x0
scsi-generic: Command complete 0x0x10a42c60 tag=0x0 status=0
Improve this by adding a message prior to the loop, similar to what exists for scsi-disk. Clean up a few other messages to be more explicit of what is being represented. Example:
scsi-generic: Command: data=0x12 0x00 0x00 0x01 0x00 0x00
scsi-generic: scsi_read_data tag=0x0
scsi-generic: Data ready tag=0x0 len=164
scsi-generic: scsi_read_data tag=0x0
scsi-generic: Command complete 0x0x10a452d0 tag=0x0 status=0
Message-Id: <[email protected]>
--- hw/scsi/scsi-generic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/scsi/scsi-generic.c +3 -2
@@ -246,7 +246,7 @@ static void scsi_read_data(SCSIRequest *req)SCSIDevice *s = r->req.dev;int ret; -DPRINTF ("scsi_read_data 0x%x\n" , req->tag); +DPRINTF ("scsi_read_data tag=0x%x\n" , req->tag);/* The request is used as the AIO opaque value, so add a ref. */ scsi_req_ref (&r->req);
@@ -294,7 +294,7 @@ static void scsi_write_data(SCSIRequest *req)SCSIDevice *s = r->req.dev;int ret; -DPRINTF ("scsi_write_data 0x%x\n" , req->tag); +DPRINTF ("scsi_write_data tag=0x%x\n" , req->tag);if (r->len ==0 ) { r->len = r->buflen;scsi_req_data (&r->req, r->len);
@@ -329,6 +329,7 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *cmd)int ret;#ifdef DEBUG_SCSI +DPRINTF ("Command: data=0x%02x" , cmd[0 ]); {int i;for (i =1 ; i < r->req.cmd.len; i++) {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 17/41] block: get max_transfer limit for char (scsi-generic) devices
In reply to Paolo BonziniFrom: Eric Farman <[email protected]>
We can get the maximum number of bytes for a single I/O transfer from the BLKSECTGET ioctl, but we only perform this for block devices. scsi-generic devices are represented as character devices, and so do not issue this today. Update this, so that virtio-scsi devices using the scsi-generic interface can return the same data.
Message-Id: <[email protected]>
--- block/file-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/file-posix.c +1 -1
@@ -674,7 +674,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)struct stat st;if (!fstat (s->fd, &st)) { -if (S_ISBLK (st.st_mode)) { +if (S_ISBLK (st.st_mode) ||S_ISCHR (st.st_mode)) {int ret =hdev_get_max_transfer_length (bs, s->fd);if (ret >0 && ret <=BDRV_REQUEST_MAX_BYTES ) { bs->bl.max_transfer =pow2floor (ret);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 18/41] x86-KVM: Supply TSC and APIC clock rates to guest like VMWare
In reply to Paolo BonziniFrom: Phil Dennis-Jordan <[email protected]>
This fixes timekeeping of x86-64 Darwin/OS X/macOS guests when using KVM.
Darwin/OS X/macOS for x86-64 uses the TSC for timekeeping; it normally calibrates this by querying various clock frequency scaling MSRs. Details depend on the exact CPU model detected. The local APIC timer frequency is extracted from (EFI) firmware.
This is problematic in the presence of virtualisation, as the MSRs in question are typically not handled by the hypervisor. VMWare (Fusion) advertises TSC and APIC frequency via a custom 0x40000010 CPUID leaf, in the eax and ebx registers respectively. This is documented at https://lwn.net/Articles/301888/ among other places.
Darwin/OS X/macOS looks for the generic 0x40000000 hypervisor leaf, and if this indicates via eax that leaf 0x40000010 might be available, that is in turn queried for the two frequencies.
This adds a CPU option "vmware-cpuid-freq" to enable the same behaviour when running Qemu with KVM acceleration, if the KVM TSC frequency can be determined, and it is stable. (invtsc or user-specified) The virtualised APIC bus cycle is hardcoded to 1GHz in KVM, so ebx of the CPUID leaf is also hardcoded to this value.
Message-Id: <[email protected]>
--- target/i386/cpu.c | 1 + target/i386/cpu.h | 4 ++++ target/i386/kvm.c | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 6 deletions(-)
target/i386/cpu.c +1 -0
@@ -3677,6 +3677,7 @@ static Property x86_cpu_properties[] = {DEFINE_PROP_BOOL ("cpuid-0xb" ,X86CPU , enable_cpuid_0xb, true),DEFINE_PROP_BOOL ("lmce" ,X86CPU , enable_lmce, false),DEFINE_PROP_BOOL ("l3-cache" ,X86CPU , enable_l3_cache, true), +DEFINE_PROP_BOOL ("vmware-cpuid-freq" ,X86CPU , vmware_cpuid_freq, false), DEFINE_PROP_END_OF_LIST() };
target/i386/cpu.h +4 -0
@@ -1213,6 +1213,10 @@ struct X86CPU {bool host_features;uint32_t apic_id; +/* Enables publishing of TSC increment and Local APIC bus frequencies to +* the guest OS in CPUID page 0x40000010, the same way that VMWare does. */ +bool vmware_cpuid_freq; +/* if true the CPUID code directly forward host cache leaves to the guest */ bool cache_info_passthrough;
target/i386/kvm.c +30 -6
@@ -974,12 +974,6 @@ int kvm_arch_init_vcpu(CPUState *cs) vmstate_x86_cpu.unmigratable =1 ; } - cpuid_data.cpuid.padding =0 ; - r =kvm_vcpu_ioctl (cs,KVM_SET_CPUID2 , &cpuid_data); -if (r) { -return r; - } - r =kvm_arch_set_tsc_khz (cs);if (r <0 ) {return r;
@@ -999,6 +993,36 @@ int kvm_arch_init_vcpu(CPUState *cs) } } +if (cpu->vmware_cpuid_freq +/* Guests depend on 0x40000000 to detect this feature, so only expose +* it if KVM exposes leaf 0x40000000. (Conflicts with Hyper-V) */ + && cpu->expose_kvm + && kvm_base ==KVM_CPUID_SIGNATURE +/* TSC clock must be stable and known for this feature. */ + && ((env->features[FEAT_8000_0007_EDX ] &CPUID_APM_INVTSC ) + || env->user_tsc_khz !=0 ) + && env->tsc_khz !=0 ) { + + c = &cpuid_data.entries[cpuid_i++]; + c->function =KVM_CPUID_SIGNATURE |0x10 ; + c->eax = env->tsc_khz; +/* LAPIC resolution of 1ns (freq: 1GHz) is hardcoded in KVM's +* APIC_BUS_CYCLE_NS */ + c->ebx =1000000 ; + c->ecx = c->edx =0 ; + + c =cpuid_find_entry (&cpuid_data.cpuid, kvm_base,0 ); + c->eax =MAX (c->eax,KVM_CPUID_SIGNATURE |0x10 ); + } + + cpuid_data.cpuid.nent = cpuid_i; + + cpuid_data.cpuid.padding =0 ; + r =kvm_vcpu_ioctl (cs,KVM_SET_CPUID2 , &cpuid_data); +if (r) { +return r; + } +if (has_xsave) { env->kvm_xsave_buf =qemu_memalign (4096 ,sizeof (struct kvm_xsave )); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 16/41] block: Fix target variable of BLKSECTGET ioctl
In reply to Paolo BonziniFrom: Eric Farman <[email protected]>
Commit 6f6071745bd0 ("raw-posix: Fetch max sectors for host block device") introduced a routine to call the kernel BLKSECTGET ioctl, which stores the result back to user space. However, the size of the data returned depends on the routine handling the ioctl. The (compat_)blkdev_ioctl returns a short, while sg_ioctl returns an int. Thus, on big-endian systems, we can find ourselves accidentally shifting the result to a much larger value. (On s390x, a short is 16 bits while an int is 32 bits.)
Also, the two ioctl handlers return values in different scales (block returns sectors, while sg returns bytes), so some tweaking of the outputs is required such that hdev_get_max_transfer_length returns a value in a consistent set of units.
Message-Id: <[email protected]>
--- block/file-posix.c | 17 ++++++++++------- include/block/block.h | 1 + 2 files changed, 11 insertions(+), 7 deletions(-)
block/file-posix.c +10 -7
@@ -651,12 +651,15 @@ static void raw_reopen_abort(BDRVReopenState *state) state->opaque =NULL ; } -static int hdev_get_max_transfer_length (int fd) +static int hdev_get_max_transfer_length (BlockDriverState *bs,int fd) {#ifdef BLKSECTGET -int max_sectors =0 ; -if (ioctl (fd,BLKSECTGET , &max_sectors) ==0 ) { -return max_sectors; +int max_bytes =0 ; +short max_sectors =0 ; +if (bs->sg &&ioctl (fd,BLKSECTGET , &max_bytes) ==0 ) { +return max_bytes; + }else if (!bs->sg &&ioctl (fd,BLKSECTGET , &max_sectors) ==0 ) { +return max_sectors <<BDRV_SECTOR_BITS ; }else {return -errno; }
@@ -672,9 +675,9 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)if (!fstat (s->fd, &st)) {if (S_ISBLK (st.st_mode)) { -int ret =hdev_get_max_transfer_length (s->fd); -if (ret >0 && ret <=BDRV_REQUEST_MAX_SECTORS ) { - bs->bl.max_transfer =pow2floor (ret <<BDRV_SECTOR_BITS ); +int ret =hdev_get_max_transfer_length (bs, s->fd); +if (ret >0 && ret <=BDRV_REQUEST_MAX_BYTES ) { + bs->bl.max_transfer =pow2floor (ret); } } }
include/block/block.h +1 -0
@@ -116,6 +116,7 @@ typedef struct HDGeometry {#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ INT_MAX >> BDRV_SECTOR_BITS) +#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS)/* * Allocation status flags
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 19/41] pc: Enable vmware-cpuid-freq CPU option for 2.9+ machine types
In reply to Paolo BonziniFrom: Phil Dennis-Jordan <[email protected]>
Message-Id: <[email protected]>
--- include/hw/i386/pc.h | 6 +++++- target/i386/cpu.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-)
include/hw/i386/pc.h +5 -1
@@ -386,7 +386,11 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); .property = "x-smi-broadcast",\ .value = "off",\ },\ - + {\ + .driver = TYPE_X86_CPU,\ + .property = "vmware-cpuid-freq",\ + .value = "off",\ + },#define PC_COMPAT_2_7 \ HW_COMPAT_2_7 \
target/i386/cpu.c +1 -1
@@ -3677,7 +3677,7 @@ static Property x86_cpu_properties[] = {DEFINE_PROP_BOOL ("cpuid-0xb" ,X86CPU , enable_cpuid_0xb, true),DEFINE_PROP_BOOL ("lmce" ,X86CPU , enable_lmce, false),DEFINE_PROP_BOOL ("l3-cache" ,X86CPU , enable_l3_cache, true), -DEFINE_PROP_BOOL ("vmware-cpuid-freq" ,X86CPU , vmware_cpuid_freq, false), +DEFINE_PROP_BOOL ("vmware-cpuid-freq" ,X86CPU , vmware_cpuid_freq, true), DEFINE_PROP_END_OF_LIST() };
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 20/41] block/iscsi: statically link qemu_iscsi_opts
In reply to Paolo BonziniFrom: Peter Lieven <[email protected]>
commit f57b4b5f moved qemu_iscsi_opts into vl.c. This made them invisible for qemu-img, qemu-nbd etc.
Message-Id: <[email protected]>
--- MAINTAINERS | 1 + block/Makefile.objs | 1 + block/iscsi-opts.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 40 ------------------------------- 4 files changed, 71 insertions(+), 40 deletions(-) create mode 100644 block/iscsi-opts.c
MAINTAINERS +1 -0
@@ -1626,6 +1626,7 @@ M: Peter Lieven <[email protected]> L: [email protected] S: Supported F: block/iscsi.c +F: block/iscsi-opts.c NFS M: Jeff Cody <[email protected]>
block/Makefile.objs +1 -0
@@ -14,6 +14,7 @@ block-obj-y += throttle-groups.o block-obj-y += nbd.o nbd-client.o sheepdog.o block-obj-$(CONFIG_LIBISCSI) += iscsi.o +block-obj-$(if $(CONFIG_LIBISCSI),y,n) += iscsi-opts.o block-obj-$(CONFIG_LIBNFS) += nfs.o block-obj-$(CONFIG_CURL) += curl.o block-obj-$(CONFIG_RBD) += rbd.o
block/iscsi-opts.c new file +69 -0
69 lines not on this page · raw message
vl.c +0 -40
@@ -514,43 +514,6 @@ static QemuOptsList qemu_fw_cfg_opts = { }, }; -#ifdef CONFIG_LIBISCSI -static QemuOptsList qemu_iscsi_opts = { - .name ="iscsi" , - .head =QTAILQ_HEAD_INITIALIZER (qemu_iscsi_opts.head), - .desc = { - { - .name ="user" , - .type =QEMU_OPT_STRING , - .help ="username for CHAP authentication to target" , - },{ - .name ="password" , - .type =QEMU_OPT_STRING , - .help ="password for CHAP authentication to target" , - },{ - .name ="password-secret" , - .type =QEMU_OPT_STRING , - .help ="ID of the secret providing password for CHAP " -"authentication to target" , - },{ - .name ="header-digest" , - .type =QEMU_OPT_STRING , - .help ="HeaderDigest setting. " -"{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}" , - },{ - .name ="initiator-name" , - .type =QEMU_OPT_STRING , - .help ="Initiator iqn name to use when connecting" , - },{ - .name ="timeout" , - .type =QEMU_OPT_NUMBER , - .help ="Request timeout in seconds (default 0 = no timeout)" , - }, - {/* end of list */ } - }, -}; -#endif -/** * Get machine options *
@@ -3032,9 +2995,6 @@ int main(int argc, char **argv, char **envp)qemu_add_opts (&qemu_icount_opts);qemu_add_opts (&qemu_semihosting_config_opts);qemu_add_opts (&qemu_fw_cfg_opts); -#ifdef CONFIG_LIBISCSI -qemu_add_opts (&qemu_iscsi_opts); -#endif module_call_init (MODULE_INIT_OPTS );runstate_init ();
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 23/41] char: add qemu_chr_fe_add_watch() Returns description
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
--- include/sysemu/char.h | 2 ++ 1 file changed, 2 insertions(+)
include/sysemu/char.h +2 -0
@@ -258,6 +258,8 @@ void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...)* @cond the condition to poll for * @func the function to call when the condition happens * @user_data the opaque pointer to pass to @func +* +* Returns: the source tag */ guint qemu_chr_fe_add_watch (CharBackend *be,GIOCondition cond,GIOFunc func,void *user_data);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 24/41] doc: fix spelling
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
I am pretty sure that's the word Fabrice Bellard intended to write.
--- qemu-options.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-options.hx +1 -1
@@ -3016,7 +3016,7 @@ udp::4555@@:4556} to QEMU. Another approach is to use a patched version of netcat which can listen to a TCP port and send and receive characters via udp. If you have a patched version of netcat which activates telnet remote echo and single char transfer, then you can -use the following options to step up a netcat redirector to allow +use the following options to set up a netcat redirector to allow telnet on port 5555 to access the QEMU port. @table @code @item QEMU Options:
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 21/41] tests: fix linking test-char on win32
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
test.char.exe fails to link:
qemu-char.o: In function `win_chr_free':/home/elmarco/src/qemu/qemu-char.c:2149: undefined reference to qemu_del_polling_cb' /home/elmarco/src/qemu/qemu-char.c:2151: undefined reference to qemu_del_polling_cb' qemu-char.o: In function `win_stdio_thread':/home/elmarco/src/qemu/qemu-char.c:2568: undefined reference to qemu_del_wait_object' qemu-char.o: In function qemu_chr_open_stdio':/home/elmarco/src/qemu/qemu-char.c:2661: undefined reference to qemu_add_wait_object' /home/elmarco/src/qemu/qemu-char.c:2646: undefined reference to qemu_add_wait_object'
...
It needs main-loop.o symbols, among others. Linking with $(test-block-obj-y) brings what's necessary. We could try to eventually strip to the minimum if needed.
--- tests/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/Makefile.include +1 -1
@@ -510,7 +510,7 @@ tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y) tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y) tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y) -tests/test-char$(EXESUF): tests/test-char.o qemu-char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-io-obj-y) +tests/test-char$(EXESUF): tests/test-char.o qemu-char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-block-obj-y) tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y) tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y) tests/test-throttle$(EXESUF): tests/test-throttle.o $(test-block-obj-y)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 22/41] qemu-options: stdio is available on win32
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Available since commit db418a0a7ef5887ea0f3d167584e6f500bb0c4c5 (October 2011, qemu 1.0)
--- qemu-options.hx | 2 -- 1 file changed, 2 deletions(-)
qemu-options.hx +0 -2
@@ -2431,8 +2431,6 @@ Connect to standard input and standard output of the QEMU process. exiting QEMU with the key sequence @key{Control-c}. This option is enabled by default, use @option{signal=off} to disable it. -@option{stdio} is not available on Windows hosts. - @item -chardev braille ,id=@var{id} Connect to a local BrlAPI server. @option{braille} does not take any options.
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 26/41] char: use a static array for backends
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Number and kinds of backends is known at compile-time, use a fixed-sized static array to simplify iterations & lookups.
--- qemu-char.c | 68 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 34 deletions(-)
qemu-char.c +34 -34
@@ -4101,21 +4101,20 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, } } -static GSList *backends; +static const CharDriver *backends[CHARDEV_BACKEND_KIND__MAX ];void register_char_driver (const CharDriver *driver) { -/* casting away const */ - backends =g_slist_append (backends, (void *)driver); + backends[driver->kind] = driver; }CharDriverState *qemu_chr_new_from_opts (QemuOpts *opts,Error **errp) {Error *local_err =NULL ; -CharDriver *cd; +const CharDriver *cd =NULL ;CharDriverState *chr; -GSList *i; +int i;ChardevReturn *ret =NULL ;ChardevBackend *backend;const char *name =qemu_opt_get (opts,"backend" );
@@ -4130,11 +4129,13 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,if (is_help_option (name)) {fprintf (stderr,"Available chardev backend types:\n" ); -for (i = backends; i; i = i->next) { - cd = i->data; -fprintf (stderr,"%s\n" , ChardevBackendKind_lookup[cd->kind]); -if (cd->alias) { -fprintf (stderr,"%s\n" , cd->alias); +for (i =0 ; i <ARRAY_SIZE (backends); i++) { + cd = backends[i]; +if (cd) { +fprintf (stderr,"%s\n" , ChardevBackendKind_lookup[cd->kind]); +if (cd->alias) { +fprintf (stderr,"%s\n" , cd->alias); + } } }exit (0 );
@@ -4145,15 +4146,17 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, goto err; } -for (i = backends; i; i = i->next) { - cd = i->data; - +for (i =0 ; i <ARRAY_SIZE (backends); i++) { + cd = backends[i]; +if (!cd) { +continue ; + }if (g_strcmp0 (ChardevBackendKind_lookup[cd->kind], name) ==0 ||g_strcmp0 (cd->alias, name) ==0 ) {break ; } } -if (i ==NULL ) { +if (i ==ARRAY_SIZE (backends)) {error_setg (errp,"chardev: backend \"%s\" not found" , name); goto err; }
@@ -4370,11 +4373,15 @@ qmp_prepend_backend(ChardevBackendInfoList *list, const char *name)ChardevBackendInfoList *qmp_query_chardev_backends (Error **errp) {ChardevBackendInfoList *backend_list =NULL ; -CharDriver *c; -GSList *i; +const CharDriver *c; +int i; + +for (i =0 ; i <ARRAY_SIZE (backends); i++) { + c = backends[i]; +if (!c) { +continue ; + } -for (i = backends; i; i = i->next) { - c = i->data; backend_list =qmp_prepend_backend (backend_list, ChardevBackendKind_lookup[c->kind]);if (c->alias) {
@@ -4835,9 +4842,8 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, {ChardevReturn *ret =g_new0 (ChardevReturn,1 );CharDriverState *chr =NULL ; +const CharDriver *cd;Error *local_err =NULL ; -GSList *i; -CharDriver *cd;bool be_opened = true; chr =qemu_chr_find (id);
@@ -4846,22 +4852,16 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, goto out_error; } -for (i = backends; i; i = i->next) { - cd = i->data; - -if (cd->kind == backend->type) { - chr = cd->create (id, backend, ret, &be_opened, &local_err); -if (local_err) { -error_propagate (errp, local_err); - goto out_error; - } -break ; - } + cd = (int )backend->type >=0 && backend->type <ARRAY_SIZE (backends) ? + backends[backend->type] :NULL ; +if (cd ==NULL ) { +error_setg (errp,"chardev backend not available" ); + goto out_error; } -if (chr ==NULL ) { -assert (!i); -error_setg (errp,"chardev backend not available" ); + chr = cd->create (id, backend, ret, &be_opened, &local_err); +if (local_err) { +error_propagate (errp, local_err); goto out_error; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 25/41] char: use a const CharDriver
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
No need to allocate & copy fields, let's use static const struct instead.
Add an alias field to the CharDriver structure to cover the cases where we previously registered a driver twice under two names.
--- backends/baum.c | 8 ++- backends/msmouse.c | 7 ++- backends/testdev.c | 7 ++- include/sysemu/char.h | 20 +++--- qemu-char.c | 169 +++++++++++++++++++++++++++++++------------------- spice-qemu-char.c | 16 +++-- ui/console.c | 10 ++- 7 files changed, 151 insertions(+), 86 deletions(-)
backends/baum.c +6 -2
@@ -671,8 +671,12 @@ fail_handle:static void register_types (void ) { -register_char_driver ("braille" ,CHARDEV_BACKEND_KIND_BRAILLE ,NULL , - chr_baum_init); +static const CharDriver driver = { + .kind =CHARDEV_BACKEND_KIND_BRAILLE , + .create = chr_baum_init, + }; + +register_char_driver (&driver); }type_init (register_types);
backends/msmouse.c +5 -2
@@ -179,8 +179,11 @@ static CharDriverState *qemu_chr_open_msmouse(const char *id,static void register_types (void ) { -register_char_driver ("msmouse" ,CHARDEV_BACKEND_KIND_MSMOUSE ,NULL , - qemu_chr_open_msmouse); +static const CharDriver driver = { + .kind =CHARDEV_BACKEND_KIND_MSMOUSE , + .create = qemu_chr_open_msmouse, + }; +register_char_driver (&driver); }type_init (register_types);
backends/testdev.c +5 -2
@@ -130,8 +130,11 @@ static CharDriverState *chr_testdev_init(const char *id,static void register_types (void ) { -register_char_driver ("testdev" ,CHARDEV_BACKEND_KIND_TESTDEV ,NULL , - chr_testdev_init); +static const CharDriver driver = { + .kind =CHARDEV_BACKEND_KIND_TESTDEV , + .create = chr_testdev_init, + }; +register_char_driver (&driver); }type_init (register_types);
include/sysemu/char.h +11 -9
@@ -475,15 +475,17 @@ void qemu_chr_set_feature(CharDriverState *chr, CharDriverFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); -typedef void CharDriverParse (QemuOpts *opts,ChardevBackend *backend, -Error **errp); -typedef CharDriverState *CharDriverCreate (const char *id, -ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp); - -void register_char_driver (const char *name,ChardevBackendKind kind, -CharDriverParse *parse,CharDriverCreate *create); +typedef struct CharDriver { +ChardevBackendKind kind; +const char *alias; +void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); +CharDriverState *(*create)(const char *id, +ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp); +}CharDriver ; + +void register_char_driver (const CharDriver *driver);extern int term_escape_char;
qemu-char.c +105 -64
232 lines not on this page · raw message
spice-qemu-char.c +12 -4
@@ -389,10 +389,18 @@ static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,static void register_types (void ) { -register_char_driver ("spicevmc" ,CHARDEV_BACKEND_KIND_SPICEVMC , - qemu_chr_parse_spice_vmc, qemu_chr_open_spice_vmc); -register_char_driver ("spiceport" ,CHARDEV_BACKEND_KIND_SPICEPORT , - qemu_chr_parse_spice_port, qemu_chr_open_spice_port); +static const CharDriver vmc_driver = { + .kind =CHARDEV_BACKEND_KIND_SPICEVMC , + .parse = qemu_chr_parse_spice_vmc, + .create = qemu_chr_open_spice_vmc, + }; +static const CharDriver port_driver = { + .kind =CHARDEV_BACKEND_KIND_SPICEPORT , + .parse = qemu_chr_parse_spice_port, + .create = qemu_chr_open_spice_port, + }; +register_char_driver (&vmc_driver); +register_char_driver (&port_driver); }type_init (register_types);
ui/console.c +7 -3
@@ -2191,12 +2191,16 @@ static const TypeInfo qemu_console_info = { .class_size = sizeof(QemuConsoleClass), }; -static void register_types (void ) { +static const CharDriver vc_driver = { + .kind =CHARDEV_BACKEND_KIND_VC , + .parse = qemu_chr_parse_vc, + .create = vc_init, + }; +type_register_static (&qemu_console_info); -register_char_driver ("vc" ,CHARDEV_BACKEND_KIND_VC , qemu_chr_parse_vc, - vc_init); +register_char_driver (&vc_driver); }type_init (register_types);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 28/41] char: fold single-user functions in caller
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
This shortens the code a bit.
--- qemu-char.c | 95 +++++++++++++++++++------------------------------------------ 1 file changed, 29 insertions(+), 66 deletions(-)
qemu-char.c +29 -66
@@ -1891,22 +1891,6 @@ static void qemu_chr_free_tty(CharDriverState *chr) {fd_chr_free (chr); } - -static CharDriverState *qemu_chr_open_tty_fd (const CharDriver *driver, -int fd, -ChardevCommon *backend, -bool *be_opened, -Error **errp) -{ -CharDriverState *chr; - -tty_serial_init (fd,115200 ,'N' ,8 ,1 ); - chr =qemu_chr_open_fd (driver, fd, fd, backend, errp); -if (!chr) { -return NULL ; - } -return chr; -}#endif /* __linux__ || __sun__ */ #if defined(__linux__)
@@ -2327,29 +2311,6 @@ static int win_chr_poll(void *opaque)return 0 ; } -static CharDriverState *qemu_chr_open_win_path (const CharDriver *driver, -const char *filename, -ChardevCommon *backend, -Error **errp) -{ -CharDriverState *chr; -WinCharState *s; - - chr =qemu_chr_alloc (driver, backend, errp); -if (!chr) { -return NULL ; - } - s =g_new0 (WinCharState,1 ); - chr->opaque = s; - -if (win_chr_init (chr, filename, errp) <0 ) { -g_free (s); -qemu_chr_free_common (chr); -return NULL ; - } -return chr; -} -static int win_chr_pipe_poll (void *opaque) {CharDriverState *chr = opaque;
@@ -2806,30 +2767,6 @@ static void udp_chr_free(CharDriverState *chr)qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); } -static CharDriverState *qemu_chr_open_udp (const CharDriver *driver, -QIOChannelSocket *sioc, -ChardevCommon *backend, -bool *be_opened, -Error **errp) -{ -CharDriverState *chr =NULL ; -NetCharDriver *s =NULL ; - - chr =qemu_chr_alloc (driver, backend, errp); -if (!chr) { -return NULL ; - } - s =g_new0 (NetCharDriver,1 ); - - s->ioc =QIO_CHANNEL (sioc); - s->bufcnt =0 ; - s->bufptr =0 ; - chr->opaque = s; -/* be isn't opened until we get a connection */ - *be_opened = false; -return chr; -} -/***********************************************************/ /* TCP Net console */
@@ -4614,8 +4551,23 @@ static CharDriverState *qmp_chardev_open_serial(const CharDriver *driver, {ChardevHostdev *serial = backend->u.serial.data;ChardevCommon *common =qapi_ChardevHostdev_base (serial); +CharDriverState *chr; +WinCharState *s; + + chr =qemu_chr_alloc (driver, common, errp); +if (!chr) { +return NULL ; + } -return qemu_chr_open_win_path (driver, serial->device, common, errp); + s =g_new0 (WinCharState,1 ); + chr->opaque = s; +if (win_chr_init (chr, serial->device, errp) <0 ) { +g_free (s); +qemu_chr_free_common (chr); +return NULL ; + } + +return chr; }#else /* WIN32 */
@@ -4684,8 +4636,9 @@ static CharDriverState *qmp_chardev_open_serial(const CharDriver *driver, return NULL; }qemu_set_nonblock (fd); +tty_serial_init (fd,115200 ,'N' ,8 ,1 ); -return qemu_chr_open_tty_fd (driver, fd, common, be_opened, errp); +return qemu_chr_open_fd (driver, fd, fd, common, errp); }#endif
@@ -4941,6 +4894,7 @@ static CharDriverState *qmp_chardev_open_udp(const CharDriver *driver,QIOChannelSocket *sioc =qio_channel_socket_new ();char *name;CharDriverState *chr; +NetCharDriver *s; if (qio_channel_socket_dgram_sync(sioc, udp->local, udp->remote,
@@ -4949,12 +4903,21 @@ static CharDriverState *qmp_chardev_open_udp(const CharDriver *driver,return NULL ; } - chr =qemu_chr_open_udp (driver, sioc, common, be_opened, errp); + chr =qemu_chr_alloc (driver, common, errp); +if (!chr) { +return NULL ; + } name =g_strdup_printf ("chardev-udp-%s" , chr->label);qio_channel_set_name (QIO_CHANNEL (sioc), name);g_free (name); + s =g_new0 (NetCharDriver,1 ); + s->ioc =QIO_CHANNEL (sioc); + chr->opaque = s; +/* be isn't opened until we get a connection */ + *be_opened = false; +return chr; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 29/41] char: introduce generic qemu_chr_get_kind()
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
This allows to remove the "is_mux" field from CharDriverState.
--- include/sysemu/char.h | 15 +++++++++++++-- monitor.c | 2 +- qemu-char.c | 21 ++++++++++----------- 3 files changed, 24 insertions(+), 14 deletions(-)
include/sysemu/char.h +13 -2
@@ -96,7 +96,6 @@ struct CharDriverState {char *filename;int logfd;int be_open; -int is_mux;guint fd_in_tag;bool replay;DECLARE_BITMAP (features,QEMU_CHAR_FEATURE_LAST );
@@ -455,7 +454,19 @@ void qemu_chr_be_generic_open(CharDriverState *s);void qemu_chr_fe_accept_input (CharBackend *be);int qemu_chr_add_client (CharDriverState *s,int fd);CharDriverState *qemu_chr_find (const char *name); -bool chr_is_ringbuf (const CharDriverState *chr); + +/** +* @qemu_chr_get_kind: +* +* Returns the kind of char backend, or -1 if unspecified. +*/ +ChardevBackendKind qemu_chr_get_kind (const CharDriverState *chr); + +static inline bool qemu_chr_is_ringbuf (const CharDriverState *chr) +{ +return qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_RINGBUF || +qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_MEMORY ; +}bool qemu_chr_has_feature (CharDriverState *chr,CharDriverFeature feature);
monitor.c +1 -1
@@ -3196,7 +3196,7 @@ static void ringbuf_completion(ReadLineState *rs, const char *str)if (!strncmp (chr_info->label, str, len)) {CharDriverState *chr =qemu_chr_find (chr_info->label); -if (chr &&chr_is_ringbuf (chr)) { +if (chr &&qemu_chr_is_ringbuf (chr)) {readline_add_completion (rs, chr_info->label); } }
qemu-char.c +10 -11
@@ -781,7 +781,7 @@ static void muxes_realize_done(Notifier *notifier, void *unused)CharDriverState *chr; QTAILQ_FOREACH(chr, &chardevs, next) { -if (chr->is_mux) { +if (qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = chr->opaque;int i;
@@ -888,7 +888,6 @@ static CharDriverState *qemu_chr_open_mux(const CharDriver *driver,* set of muxes */ *be_opened = muxes_realized; - chr->is_mux =1 ;if (!qemu_chr_fe_init (&d->chr, drv, errp)) {qemu_chr_free (chr);return NULL ;
@@ -906,7 +905,7 @@ bool qemu_chr_fe_init(CharBackend *b, CharDriverState *s, Error **errp) {int tag =0 ; -if (s->is_mux) { +if (qemu_chr_get_kind (s) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = s->opaque;if (d->mux_cnt >=MAX_MUX ) {
@@ -933,7 +932,7 @@ unavailable:static bool qemu_chr_is_busy (CharDriverState *s) { -if (s->is_mux) { +if (qemu_chr_get_kind (s) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = s->opaque;return d->mux_cnt >=0 ; }else {
@@ -950,7 +949,7 @@ void qemu_chr_fe_deinit(CharBackend *b)if (b->chr->be == b) { b->chr->be =NULL ; } -if (b->chr->is_mux) { +if (qemu_chr_get_kind (b->chr) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = b->chr->opaque; d->backends[b->tag] =NULL ; }
@@ -1001,7 +1000,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b, } } -if (s->is_mux) { +if (qemu_chr_get_kind (s) ==CHARDEV_BACKEND_KIND_MUX ) {mux_chr_set_handlers (s, context); } }
@@ -1012,7 +1011,7 @@ void qemu_chr_fe_take_focus(CharBackend *b)return ; } -if (b->chr->is_mux) { +if (qemu_chr_get_kind (b->chr) ==CHARDEV_BACKEND_KIND_MUX ) {mux_set_focus (b->chr, b->tag); } }
@@ -3559,9 +3558,9 @@ fail:return NULL ; } -bool chr_is_ringbuf (const CharDriverState *chr) +ChardevBackendKind qemu_chr_get_kind (const CharDriverState *chr) { -return chr->driver->chr_write == ringbuf_chr_write; +return chr->driver->kind; } void qmp_ringbuf_write(const char *device, const char *data,
@@ -3579,7 +3578,7 @@ void qmp_ringbuf_write(const char *device, const char *data,return ; } -if (!chr_is_ringbuf (chr)) { +if (!qemu_chr_is_ringbuf (chr)) {error_setg (errp,"%s is not a ringbuf device" , device);return ; }
@@ -3623,7 +3622,7 @@ char *qmp_ringbuf_read(const char *device, int64_t size,return NULL ; } -if (!chr_is_ringbuf (chr)) { +if (!qemu_chr_is_ringbuf (chr)) {error_setg (errp,"%s is not a ringbuf device" , device);return NULL ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 30/41] char: use a feature bit for replay
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Use a feature flag rather than a structure field for "replay".
--- include/sysemu/char.h | 3 ++- qemu-char.c | 33 ++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-)
include/sysemu/char.h +2 -1
@@ -69,6 +69,8 @@ typedef enum {/* Whether it is possible to send/recv file descriptors * over the data channel */ QEMU_CHAR_FEATURE_FD_PASS , +/* Whether replay or record mode is enabled */ +QEMU_CHAR_FEATURE_REPLAY ,QEMU_CHAR_FEATURE_LAST , } CharDriverFeature;
@@ -97,7 +99,6 @@ struct CharDriverState {int logfd;int be_open;guint fd_in_tag; -bool replay;DECLARE_BITMAP (features,QEMU_CHAR_FEATURE_LAST );QTAILQ_ENTRY (CharDriverState) next; };
qemu-char.c +20 -13
@@ -277,6 +277,11 @@ static int qemu_chr_fe_write_buffer(CharDriverState *s, const uint8_t *buf, intreturn res; } +static bool qemu_chr_replay (CharDriverState *chr) +{ +return qemu_chr_has_feature (chr,QEMU_CHAR_FEATURE_REPLAY ); +} +int qemu_chr_fe_write (CharBackend *be,const uint8_t *buf,int len) {CharDriverState *s = be->chr;
@@ -286,7 +291,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)return 0 ; } -if (s->replay && replay_mode ==REPLAY_MODE_PLAY ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_PLAY ) {int offset;replay_char_write_event_load (&ret, &offset);assert (offset <= len);
@@ -303,7 +308,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)qemu_mutex_unlock (&s->chr_write_lock); -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_write_event_save (ret, ret <0 ?0 : ret); }
@@ -315,7 +320,7 @@ static int qemu_chr_write_all(CharDriverState *s, const uint8_t *buf, int len)int offset;int res; -if (s->replay && replay_mode ==REPLAY_MODE_PLAY ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_PLAY ) {replay_char_write_event_load (&res, &offset);assert (offset <= len);qemu_chr_fe_write_buffer (s, buf, offset, &offset);
@@ -324,7 +329,7 @@ static int qemu_chr_write_all(CharDriverState *s, const uint8_t *buf, int len) res =qemu_chr_fe_write_buffer (s, buf, len, &offset); -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_write_event_save (res, offset); }
@@ -355,7 +360,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)return 0 ; } -if (s->replay && replay_mode ==REPLAY_MODE_PLAY ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_PLAY ) {return replay_char_read_all_load (buf); }
@@ -372,7 +377,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) }if (res <0 ) { -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_read_all_save_error (res); }return res;
@@ -385,7 +390,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) } } -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_read_all_save_buf (buf, offset); }return offset;
@@ -396,7 +401,7 @@ int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg)CharDriverState *s = be->chr;int res; -if (!s || !s->driver->chr_ioctl || s->replay) { +if (!s || !s->driver->chr_ioctl ||qemu_chr_replay (s)) { res = -ENOTSUP ; }else { res = s->driver->chr_ioctl (s, cmd, arg);
@@ -427,7 +432,7 @@ void qemu_chr_be_write_impl(CharDriverState *s, uint8_t *buf, int len)void qemu_chr_be_write (CharDriverState *s,uint8_t *buf,int len) { -if (s->replay) { +if (qemu_chr_replay (s)) {if (replay_mode ==REPLAY_MODE_PLAY ) {return ; }
@@ -442,7 +447,7 @@ int qemu_chr_fe_get_msgfd(CharBackend *be)CharDriverState *s = be->chr;int fd;int res = (qemu_chr_fe_get_msgfds (be, &fd,1 ) ==1 ) ? fd :-1 ; -if (s && s->replay) { +if (s &&qemu_chr_replay (s)) {fprintf (stderr,"Replay: get msgfd is not supported for serial devices yet\n" );exit (1 );
@@ -4249,8 +4254,10 @@ CharDriverState *qemu_chr_new(const char *label, const char *filename)CharDriverState *chr; chr =qemu_chr_new_noreplay (label, filename);if (chr) { - chr->replay = replay_mode !=REPLAY_MODE_NONE ; -if (chr->replay && chr->driver->chr_ioctl) { +if (replay_mode !=REPLAY_MODE_NONE ) { +qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_REPLAY ); + } +if (qemu_chr_replay (chr) && chr->driver->chr_ioctl) {fprintf (stderr,"Replay: ioctl is not supported for serial devices yet\n" ); }
@@ -4997,7 +5004,7 @@ void qmp_chardev_remove(const char *id, Error **errp)error_setg (errp,"Chardev '%s' is busy" , id);return ; } -if (chr->replay) { +if (qemu_chr_replay (chr)) {error_setg (errp,"Chardev '%s' cannot be unplugged in record/replay mode" , id);return ;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 32/41] bt: use qemu_chr_alloc()
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Use common allocator for CharDriverState.
Rename the now untouched parent field.
The casts added are temporary, they are replaced with QOM type-safe macros in a later patch in this series.
--- hw/bt/hci-csr.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
hw/bt/hci-csr.c +13 -6
@@ -26,9 +26,10 @@#include "hw/irq.h" #include "sysemu/bt.h" #include "hw/bt.h" +#include "qapi/error.h" struct csrhci_s { -CharDriverState chr; +CharDriverState parent;int enable;qemu_irq *pins;int pin_state;
@@ -78,7 +79,8 @@ enum {static inline void csrhci_fifo_wake (struct csrhci_s *s) { -CharBackend *be = s->chr.be; +CharDriverState *chr = (CharDriverState *)s; +CharBackend *be = chr->be;if (!s->enable || !s->out_len)return ;
@@ -468,10 +470,15 @@ CharDriverState *uart_hci_init(void) .chr_write = csrhci_write, .chr_ioctl = csrhci_ioctl, }; -struct csrhci_s *s = (struct csrhci_s *) -g_malloc0 (sizeof (struct csrhci_s )); +Error *err =NULL ; +ChardevCommon common = {0 , }; +CharDriverState *chr =qemu_chr_alloc (&hci_driver, &common, &err); +struct csrhci_s *s = (struct csrhci_s *)chr; - s->chr.driver = &hci_driver; +if (err) { +error_report_err (err); +return NULL ; + } s->hci =qemu_next_hci (); s->hci->opaque = s;
@@ -482,5 +489,5 @@ CharDriverState *uart_hci_init(void) s->pins =qemu_allocate_irqs (csrhci_pins, s, __csrhci_pins);csrhci_reset (s); -return &s->chr; +return chr; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 27/41] char: move callbacks in CharDriver
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
This makes the code more declarative, and avoids duplicating the information on all instances.
--- backends/baum.c | 11 +- backends/msmouse.c | 11 +- backends/testdev.c | 8 +- gdbstub.c | 7 +- hw/bt/hci-csr.c | 8 +- include/sysemu/char.h | 46 ++--- qemu-char.c | 479 ++++++++++++++++++++++++++++++-------------------- spice-qemu-char.c | 32 ++-- ui/console.c | 28 +-- ui/gtk.c | 11 +- 10 files changed, 381 insertions(+), 260 deletions(-)
backends/baum.c +6 -5
@@ -622,7 +622,8 @@ static void baum_free(struct CharDriverState *chr)g_free (baum); } -static CharDriverState *chr_baum_init(const char *id, +static CharDriverState *chr_baum_init(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -633,7 +634,7 @@ static CharDriverState *chr_baum_init(const char *id,CharDriverState *chr;brlapi_handle_t *handle; - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (driver, common, errp);if (!chr) {return NULL ; }
@@ -641,9 +642,6 @@ static CharDriverState *chr_baum_init(const char *id, baum->chr = chr; chr->opaque = baum; - chr->chr_write = baum_write; - chr->chr_accept_input = baum_accept_input; - chr->chr_free = baum_free; handle =g_malloc0 (brlapi_getHandleSize ()); baum->brlapi = handle;
@@ -674,6 +672,9 @@ static void register_types(void)static const CharDriver driver = { .kind =CHARDEV_BACKEND_KIND_BRAILLE , .create = chr_baum_init, + .chr_write = baum_write, + .chr_accept_input = baum_accept_input, + .chr_free = baum_free, };register_char_driver (&driver);
backends/msmouse.c +6 -5
@@ -148,7 +148,8 @@ static QemuInputHandler msmouse_handler = { .sync = msmouse_input_sync, }; -static CharDriverState *qemu_chr_open_msmouse(const char *id, +static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -158,13 +159,10 @@ static CharDriverState *qemu_chr_open_msmouse(const char *id,MouseState *mouse;CharDriverState *chr; - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (driver, common, errp);if (!chr) {return NULL ; } - chr->chr_write = msmouse_chr_write; - chr->chr_free = msmouse_chr_free; - chr->chr_accept_input = msmouse_chr_accept_input; *be_opened = false; mouse =g_new0 (MouseState,1 );
@@ -182,6 +180,9 @@ static void register_types(void)static const CharDriver driver = { .kind =CHARDEV_BACKEND_KIND_MSMOUSE , .create = qemu_chr_open_msmouse, + .chr_write = msmouse_chr_write, + .chr_accept_input = msmouse_chr_accept_input, + .chr_free = msmouse_chr_free, };register_char_driver (&driver); }
backends/testdev.c +5 -3
@@ -109,7 +109,8 @@ static void testdev_free(struct CharDriverState *chr)g_free (testdev); } -static CharDriverState *chr_testdev_init(const char *id, +static CharDriverState *chr_testdev_init(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -121,9 +122,8 @@ static CharDriverState *chr_testdev_init(const char *id, testdev =g_new0 (TestdevCharState,1 ); testdev->chr = chr =g_new0 (CharDriverState,1 ); + chr->driver = driver; chr->opaque = testdev; - chr->chr_write = testdev_write; - chr->chr_free = testdev_free;return chr; }
@@ -133,6 +133,8 @@ static void register_types(void)static const CharDriver driver = { .kind =CHARDEV_BACKEND_KIND_TESTDEV , .create = chr_testdev_init, + .chr_write = testdev_write, + .chr_free = testdev_free, };register_char_driver (&driver); }
gdbstub.c +5 -2
@@ -1731,6 +1731,10 @@ int gdbserver_start(const char *device)CharDriverState *chr =NULL ;CharDriverState *mon_chr;ChardevCommon common = {0 }; +static const CharDriver driver = { + .kind =-1 , + .chr_write = gdb_monitor_write, + };if (!device)return -1 ;
@@ -1763,8 +1767,7 @@ int gdbserver_start(const char *device)qemu_add_vm_change_state_handler (gdb_vm_state_change,NULL );/* Initialize a monitor terminal for gdb */ - mon_chr =qemu_chr_alloc (&common, &error_abort); - mon_chr->chr_write = gdb_monitor_write; + mon_chr =qemu_chr_alloc (&driver, &common, &error_abort);monitor_init (mon_chr,0 ); }else {if (qemu_chr_fe_get_driver (&s->chr)) {
hw/bt/hci-csr.c +6 -2
@@ -462,12 +462,16 @@ qemu_irq *csrhci_pins_get(CharDriverState *chr)CharDriverState *uart_hci_init (void ) { +static const CharDriver hci_driver = { + .kind =-1 , + .chr_write = csrhci_write, + .chr_ioctl = csrhci_ioctl, + };struct csrhci_s *s = (struct csrhci_s *)g_malloc0 (sizeof (struct csrhci_s )); s->chr.opaque = s; - s->chr.chr_write = csrhci_write; - s->chr.chr_ioctl = csrhci_ioctl; + s->chr.driver = &hci_driver; s->hci =qemu_next_hci (); s->hci->opaque = s;
include/sysemu/char.h +26 -20
72 lines not on this page · raw message
qemu-char.c +284 -195
1,027 lines not on this page · raw message
spice-qemu-char.c +19 -13
@@ -260,16 +260,15 @@ static void spice_chr_accept_input(struct CharDriverState *chr)spice_server_char_device_wakeup (&s->sin); } -static CharDriverState *chr_open (const char *subtype, -void (*set_fe_open)(struct CharDriverState *, -int ), +static CharDriverState *chr_open (const CharDriver *driver, +const char *subtype,ChardevCommon *backend,Error **errp) {CharDriverState *chr;SpiceCharDriver *s; - chr =qemu_chr_alloc (backend, errp); + chr =qemu_chr_alloc (driver, backend, errp);if (!chr) {return NULL ; }
@@ -278,18 +277,14 @@ static CharDriverState *chr_open(const char *subtype, s->active = false; s->sin.subtype =g_strdup (subtype); chr->opaque = s; - chr->chr_write = spice_chr_write; - chr->chr_add_watch = spice_chr_add_watch; - chr->chr_free = spice_chr_free; - chr->chr_set_fe_open = set_fe_open; - chr->chr_accept_input = spice_chr_accept_input;QLIST_INSERT_HEAD (&spice_chars, s, next);return chr; } -static CharDriverState *qemu_chr_open_spice_vmc(const char *id, +static CharDriverState *qemu_chr_open_spice_vmc(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -312,11 +307,12 @@ static CharDriverState *qemu_chr_open_spice_vmc(const char *id, } *be_opened = false; -return chr_open (type, spice_vmc_set_fe_open, common, errp); +return chr_open (driver, type, common, errp); }#if SPICE_SERVER_VERSION >=0x000c02 -static CharDriverState *qemu_chr_open_spice_port(const char *id, +static CharDriverState *qemu_chr_open_spice_port(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -333,7 +329,7 @@ static CharDriverState *qemu_chr_open_spice_port(const char *id,return NULL ; } - chr =chr_open ("port" , spice_port_set_fe_open, common, errp); + chr =chr_open (driver,"port" , common, errp);if (!chr) {return NULL ; }
@@ -393,11 +389,21 @@ static void register_types(void) .kind = CHARDEV_BACKEND_KIND_SPICEVMC, .parse = qemu_chr_parse_spice_vmc, .create = qemu_chr_open_spice_vmc, + .chr_write = spice_chr_write, + .chr_add_watch = spice_chr_add_watch, + .chr_set_fe_open = spice_vmc_set_fe_open, + .chr_accept_input = spice_chr_accept_input, + .chr_free = spice_chr_free, };static const CharDriver port_driver = { .kind =CHARDEV_BACKEND_KIND_SPICEPORT , .parse = qemu_chr_parse_spice_port, .create = qemu_chr_open_spice_port, + .chr_write = spice_chr_write, + .chr_add_watch = spice_chr_add_watch, + .chr_set_fe_open = spice_port_set_fe_open, + .chr_accept_input = spice_chr_accept_input, + .chr_free = spice_chr_free, };register_char_driver (&vmc_driver);register_char_driver (&port_driver);
ui/console.c +17 -11
@@ -1051,6 +1051,10 @@ static int console_puts(CharDriverState *chr, const uint8_t *buf, int len)QemuConsole *s = chr->opaque;int i; +if (!s->ds) { +return 0 ; + } + s->update_x0 = s->width *FONT_WIDTH ; s->update_y0 = s->height *FONT_HEIGHT ; s->update_x1 =0 ;
@@ -2000,8 +2004,6 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds) s = chr->opaque; - chr->chr_write = console_puts; - s->out_fifo.buf = s->out_fifo_buf; s->out_fifo.buf_size =sizeof (s->out_fifo_buf); s->kbd_timer =timer_new_ms (QEMU_CLOCK_REALTIME , kbd_send_chars, s);
@@ -2048,6 +2050,8 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds)qemu_chr_be_generic_open (chr); } +static const CharDriver vc_driver; +static CharDriverState *text_console_init (ChardevVC *vc,Error **errp) {ChardevCommon *common =qapi_ChardevVC_base (vc);
@@ -2056,7 +2060,7 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp)unsigned width =0 ;unsigned height =0 ; - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (&vc_driver, common, errp);if (!chr) {return NULL ; }
@@ -2089,7 +2093,6 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) s->chr = chr; chr->opaque = s; - chr->chr_set_echo = text_console_set_echo;if (display_state) {text_console_do_init (chr, display_state);
@@ -2099,7 +2102,8 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp)static VcHandler *vc_handler = text_console_init; -static CharDriverState *vc_init (const char *id,ChardevBackend *backend, +static CharDriverState *vc_init (const CharDriver *driver, +const char *id,ChardevBackend *backend,ChardevReturn *ret,bool *be_opened,Error **errp) {
@@ -2191,14 +2195,16 @@ static const TypeInfo qemu_console_info = { .class_size = sizeof(QemuConsoleClass), }; +static const CharDriver vc_driver = { + .kind =CHARDEV_BACKEND_KIND_VC , + .parse = qemu_chr_parse_vc, + .create = vc_init, + .chr_write = console_puts, + .chr_set_echo = text_console_set_echo, +}; +static void register_types (void ) { -static const CharDriver vc_driver = { - .kind =CHARDEV_BACKEND_KIND_VC , - .parse = qemu_chr_parse_vc, - .create = vc_init, - }; -type_register_static (&qemu_console_info);register_char_driver (&vc_driver); }
ui/gtk.c +7 -4
@@ -1703,6 +1703,12 @@ static CharDriverState *vcs[MAX_VCS];static CharDriverState *gd_vc_handler (ChardevVC *vc,Error **errp) { +static const CharDriver gd_vc_driver = { + .kind =CHARDEV_BACKEND_KIND_VC , + .chr_write = gd_vc_chr_write, + .chr_set_echo = gd_vc_chr_set_echo, + }; +ChardevCommon *common =qapi_ChardevVC_base (vc);CharDriverState *chr;
@@ -1711,14 +1717,11 @@ static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp)return NULL ; } - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (&gd_vc_driver, common, errp);if (!chr) {return NULL ; } - chr->chr_write = gd_vc_chr_write; - chr->chr_set_echo = gd_vc_chr_set_echo; -/* Temporary, until gd_vc_vte_init runs. */ chr->opaque =g_new0 (VirtualConsole,1 );
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 35/41] spice-char: improve error reporting
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Set errp to report errors up to the right monitor.
Use error_append_hint() to give hints about parameters on !qmp monitors, instead of a direct fprintf() call.
--- spice-qemu-char.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-)
spice-qemu-char.c +10 -20
@@ -2,6 +2,7 @@#include "trace.h" #include "ui/qemu-spice.h" #include "sysemu/char.h" +#include "qemu/error-report.h" #include <spice.h> #include <spice/protocol.h>
@@ -239,23 +240,6 @@ static void spice_port_set_fe_open(struct Chardev *chr, int fe_open)#endif } -static void print_allowed_subtypes (void ) -{ -const char ** psubtype; -int i; - -fprintf (stderr,"allowed names: " ); -for (i=0 , psubtype =spice_server_char_device_recognized_subtypes (); - *psubtype !=NULL ; ++psubtype, ++i) { -if (i ==0 ) { -fprintf (stderr,"%s" , *psubtype); - }else { -fprintf (stderr,", %s" , *psubtype); - } - } -fprintf (stderr,"\n" ); -} -static void spice_chr_accept_input (struct Chardev *chr) {SpiceChardev *s = (SpiceChardev *)chr;
@@ -302,8 +286,14 @@ static Chardev *qemu_chr_open_spice_vmc(const CharDriver *driver, } }if (*psubtype ==NULL ) { -fprintf (stderr,"spice-qemu-char: unsupported type: %s\n" , type); -print_allowed_subtypes (); +char *subtypes =g_strjoinv (", " , + (gchar **)spice_server_char_device_recognized_subtypes ()); + +error_setg (errp,"unsupported type name: %s" , type); +error_append_hint (errp,"allowed spice char type names: %s\n" , + subtypes); + +g_free (subtypes);return NULL ; }
@@ -326,7 +316,7 @@ static Chardev *qemu_chr_open_spice_port(const CharDriver *driver,SpiceChardev *s;if (name ==NULL ) { -fprintf (stderr,"spice-qemu-char: missing name parameter\n" ); +error_setg (errp,"missing name parameter" );return NULL ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 38/41] baum: use a common prefix for chr callbacks
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
--- backends/baum.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
backends/baum.c +8 -8
@@ -253,7 +253,7 @@ static int baum_deferred_init(BaumChardev *baum) }/* The serial port can receive more of our data */ -static void baum_accept_input (struct Chardev *chr) +static void baum_chr_accept_input (struct Chardev *chr) {BaumChardev *baum = (BaumChardev *)chr;int room, first;
@@ -470,7 +470,7 @@ static int baum_eat_packet(BaumChardev *baum, const uint8_t *buf, int len) }/* The other end is writing some data. Store it and try to interpret */ -static int baum_write (Chardev *chr,const uint8_t *buf,int len) +static int baum_chr_write (Chardev *chr,const uint8_t *buf,int len) {BaumChardev *baum = (BaumChardev *)chr;int tocopy, cur, eaten, orig_len = len;
@@ -613,7 +613,7 @@ static void baum_chr_read(void *opaque) } } -static void baum_free (struct Chardev *chr) +static void baum_chr_free (struct Chardev *chr) {BaumChardev *baum = (BaumChardev *)chr;
@@ -624,7 +624,7 @@ static void baum_free(struct Chardev *chr) } } -static Chardev *chr_baum_init(const CharDriver *driver, +static Chardev *baum_chr_init(const CharDriver *driver, const char *id, ChardevBackend *backend, ChardevReturn *ret,
@@ -670,10 +670,10 @@ static void register_types(void)static const CharDriver driver = { .instance_size =sizeof (BaumChardev), .kind =CHARDEV_BACKEND_KIND_BRAILLE , - .create = chr_baum_init, - .chr_write = baum_write, - .chr_accept_input = baum_accept_input, - .chr_free = baum_free, + .create = baum_chr_init, + .chr_write = baum_chr_write, + .chr_accept_input = baum_chr_accept_input, + .chr_free = baum_chr_free, };register_char_driver (&driver);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 34/41] char: rename TCPChardev and NetChardev
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Rename the types to follow the name of the chardev kind.
- socket: TCPChardev -> SocketChardev
- udp: NetChardev -> UdpChardev
--- qemu-char.c | 74 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 37 deletions(-)
qemu-char.c +37 -37
@@ -2691,12 +2691,12 @@ typedef struct {int bufcnt;int bufptr;int max_size; -} NetChardev; +} UdpChardev;/* Called with chr_write_lock held. */ static int udp_chr_write (Chardev *chr,const uint8_t *buf,int len) { -NetChardev *s = (NetChardev *)chr; +UdpChardev *s = (UdpChardev *)chr;return qio_channel_write ( s->ioc, (const char *)buf, len,NULL );
@@ -2705,7 +2705,7 @@ static int udp_chr_write(Chardev *chr, const uint8_t *buf, int len)static int udp_chr_read_poll (void *opaque) {Chardev *chr = opaque; -NetChardev *s = opaque; +UdpChardev *s = opaque; s->max_size =qemu_chr_be_can_write (chr);
@@ -2723,7 +2723,7 @@ static int udp_chr_read_poll(void *opaque)static gboolean udp_chr_read (QIOChannel *chan,GIOCondition cond,void *opaque) {Chardev *chr = opaque; -NetChardev *s = opaque; +UdpChardev *s = opaque;ssize_t ret;if (s->max_size ==0 ) {
@@ -2750,7 +2750,7 @@ static gboolean udp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)static void udp_chr_update_read_handler (Chardev *chr,GMainContext *context) { -NetChardev *s = (NetChardev *)chr; +UdpChardev *s = (UdpChardev *)chr;remove_fd_in_watch (chr);if (s->ioc) {
@@ -2763,7 +2763,7 @@ static void udp_chr_update_read_handler(Chardev *chr,static void udp_chr_free (Chardev *chr) { -NetChardev *s = (NetChardev *)chr; +UdpChardev *s = (UdpChardev *)chr;remove_fd_in_watch (chr);if (s->ioc) {
@@ -2799,13 +2799,13 @@ typedef struct {guint reconnect_timer;int64_t reconnect_time;bool connect_err_reported; -} TCPChardev; +} SocketChardev;static gboolean socket_reconnect_timeout (gpointer opaque);static void qemu_chr_socket_restart_timer (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;char *name;assert (s->connected ==0 );
@@ -2819,7 +2819,7 @@ static void qemu_chr_socket_restart_timer(Chardev *chr)static void check_report_connect_error (Chardev *chr,Error *err) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (!s->connect_err_reported) { error_report("Unable to connect character device %s: %s",
@@ -2836,7 +2836,7 @@ static gboolean tcp_chr_accept(QIOChannel *chan,/* Called with chr_write_lock held. */ static int tcp_chr_write (Chardev *chr,const uint8_t *buf,int len) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (s->connected) { int ret = io_channel_send_full(s->ioc, buf, len,
@@ -2860,7 +2860,7 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len)static int tcp_chr_read_poll (void *opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;if (!s->connected)return 0 ; s->max_size =qemu_chr_be_can_write (chr);
@@ -2870,7 +2870,7 @@ static int tcp_chr_read_poll(void *opaque)#define IAC 255#define IAC_BREAK 243static void tcp_chr_process_IAC_bytes (Chardev *chr, -TCPChardev *s, +SocketChardev *s,uint8_t *buf,int *size) {/* Handle any telnet client's basic IAC options to satisfy char by
@@ -2919,7 +2919,7 @@ static void tcp_chr_process_IAC_bytes(Chardev *chr,static int tcp_get_msgfds (Chardev *chr,int *fds,int num) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;int to_copy = (s->read_msgfds_num < num) ? s->read_msgfds_num : num;
@@ -2945,7 +2945,7 @@ static int tcp_get_msgfds(Chardev *chr, int *fds, int num)static int tcp_set_msgfds (Chardev *chr,int *fds,int num) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;/* clear old pending fd array */ g_free (s->write_msgfds);
@@ -2970,7 +2970,7 @@ static int tcp_set_msgfds(Chardev *chr, int *fds, int num)static ssize_t tcp_chr_recv (Chardev *chr,char *buf,size_t len) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;struct iovec iov = { .iov_base = buf, .iov_len = len };int ret;size_t i;
@@ -3027,13 +3027,13 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, size_t len)static GSource *tcp_chr_add_watch (Chardev *chr,GIOCondition cond) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;return qio_channel_create_watch (s->ioc, cond); }static void tcp_chr_free_connection (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;int i;if (!s->connected) {
@@ -3062,7 +3062,7 @@ static void tcp_chr_free_connection(Chardev *chr)static void tcp_chr_disconnect (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (!s->connected) {return ;
@@ -3085,7 +3085,7 @@ static void tcp_chr_disconnect(Chardev *chr)static gboolean tcp_chr_read (QIOChannel *chan,GIOCondition cond,void *opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;uint8_t buf[READ_BUF_LEN ];int len, size;
@@ -3111,7 +3111,7 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)static int tcp_chr_sync_read (Chardev *chr,const uint8_t *buf,int len) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;int size;if (!s->connected) {
@@ -3130,7 +3130,7 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)static void tcp_chr_connect (void *opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;g_free (chr->filename); chr->filename = sockaddr_to_str(
@@ -3151,7 +3151,7 @@ static void tcp_chr_connect(void *opaque)static void tcp_chr_update_read_handler (Chardev *chr,GMainContext *context) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (!s->connected) {return ;
@@ -3202,7 +3202,7 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc,static void tcp_chr_telnet_init (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;TCPCharDriverTelnetInit *init =g_new0 (TCPCharDriverTelnetInit,1 );size_t n =0 ;
@@ -3237,7 +3237,7 @@ static void tcp_chr_tls_handshake(QIOTask *task, gpointer user_data) {Chardev *chr = user_data; -TCPChardev *s = user_data; +SocketChardev *s = user_data;if (qio_task_propagate_error (task,NULL )) {tcp_chr_disconnect (chr);
@@ -3253,7 +3253,7 @@ static void tcp_chr_tls_handshake(QIOTask *task,static void tcp_chr_tls_init (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;QIOChannelTLS *tioc;Error *err =NULL ;gchar *name;
@@ -3292,7 +3292,7 @@ static void tcp_chr_tls_init(Chardev *chr)static void tcp_chr_set_client_ioc_name (Chardev *chr,QIOChannelSocket *sioc) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;char *name; name = g_strdup_printf("chardev-tcp-%s-%s", s->is_listen ? "server" : "client",
@@ -3304,7 +3304,7 @@ static void tcp_chr_set_client_ioc_name(Chardev *chr,static int tcp_chr_new_client (Chardev *chr,QIOChannelSocket *sioc) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (s->ioc !=NULL ) {return -1 ;
@@ -3376,7 +3376,7 @@ static gboolean tcp_chr_accept(QIOChannel *channel,static int tcp_chr_wait_connected (Chardev *chr,Error **errp) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;QIOChannelSocket *sioc;/* It can't wait on s->connected, since it is set asynchronously
@@ -3424,7 +3424,7 @@ int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp)static void tcp_chr_free (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;tcp_chr_free_connection (chr);
@@ -3452,7 +3452,7 @@ static void qemu_chr_socket_connected(QIOTask *task, void *opaque) {QIOChannelSocket *sioc =QIO_CHANNEL_SOCKET (qio_task_get_source (task));Chardev *chr = opaque; -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;Error *err =NULL ;if (qio_task_propagate_error (task, &err)) {
@@ -4733,7 +4733,7 @@ static const CharDriver serial_driver = {static gboolean socket_reconnect_timeout (gpointer opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;QIOChannelSocket *sioc; s->reconnect_timer =0 ;
@@ -4759,7 +4759,7 @@ static Chardev *qmp_chardev_open_socket(const CharDriver *driver, Error **errp) {Chardev *chr; -TCPChardev *s; +SocketChardev *s;ChardevSocket *sock = backend->u.socket.data;SocketAddress *addr = sock->addr;bool do_nodelay = sock->has_nodelay ? sock->nodelay : false;
@@ -4774,7 +4774,7 @@ static Chardev *qmp_chardev_open_socket(const CharDriver *driver,if (!chr) {return NULL ; } - s = (TCPChardev *)chr; + s = (SocketChardev *)chr; s->is_unix = addr->type ==SOCKET_ADDRESS_KIND_UNIX ; s->is_listen = is_listen;
@@ -4881,7 +4881,7 @@ static Chardev *qmp_chardev_open_socket(const CharDriver *driver, }static const CharDriver socket_driver = { - .instance_size =sizeof (TCPChardev), + .instance_size =sizeof (SocketChardev), .kind =CHARDEV_BACKEND_KIND_SOCKET , .parse = qemu_chr_parse_socket, .create = qmp_chardev_open_socket,
@@ -4909,7 +4909,7 @@ static Chardev *qmp_chardev_open_udp(const CharDriver *driver,QIOChannelSocket *sioc =qio_channel_socket_new ();char *name;Chardev *chr; -NetChardev *s; +UdpChardev *s; if (qio_channel_socket_dgram_sync(sioc, udp->local, udp->remote,
@@ -4927,7 +4927,7 @@ static Chardev *qmp_chardev_open_udp(const CharDriver *driver,qio_channel_set_name (QIO_CHANNEL (sioc), name);g_free (name); - s = (NetChardev *)chr; + s = (UdpChardev *)chr; s->ioc =QIO_CHANNEL (sioc);/* be isn't opened until we get a connection */ *be_opened = false;
@@ -4936,7 +4936,7 @@ static Chardev *qmp_chardev_open_udp(const CharDriver *driver, }static const CharDriver udp_driver = { - .instance_size =sizeof (NetChardev), + .instance_size =sizeof (UdpChardev), .kind =CHARDEV_BACKEND_KIND_UDP , .parse = qemu_chr_parse_udp, .create = qmp_chardev_open_udp,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 37/41] gtk: overwrite the console.c char driver
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Instead of registering a vc handler to allocate the Gtk VC Chardev, overwrite the console.c char driver.
A later patch, when switching to QOM, will register a default console vc QOM class if none has been registered before.
--- include/sysemu/char.h | 4 +--- ui/console.c | 24 +++++++----------------- ui/gtk.c | 30 +++++++++++++++++++++--------- 3 files changed, 29 insertions(+), 29 deletions(-)
include/sysemu/char.h +1 -3
@@ -507,9 +507,7 @@ void register_char_driver(const CharDriver *driver);extern int term_escape_char; -/* console.c */ -typedef Chardev *(VcHandler )(ChardevVC *vc,Error **errp); -void register_vc_handler (VcHandler *handler); +void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend,Error **errp);#endif
ui/console.c +7 -17
@@ -2058,8 +2058,12 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds)static const CharDriver vc_driver; -static Chardev *text_console_init (ChardevVC *vc,Error **errp) +static Chardev *vc_init (const CharDriver *driver, +const char *id,ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp) { +ChardevVC *vc = backend->u.vc.data;ChardevCommon *common =qapi_ChardevVC_base (vc);Chardev *chr;VCChardev *drv;
@@ -2105,26 +2109,13 @@ static Chardev *text_console_init(ChardevVC *vc, Error **errp)if (display_state) {text_console_do_init (chr, display_state); } -return chr; -} -static VcHandler *vc_handler = text_console_init; - -static Chardev *vc_init (const CharDriver *driver, -const char *id,ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp) -{/* console/chardev init sometimes completes elsewhere in a 2nd * stage, so defer OPENED events until they are fully initialized */ *be_opened = false; -return vc_handler (backend->u.vc.data, errp); -} -void register_vc_handler (VcHandler *handler) -{ - vc_handler = handler; +return chr; }void qemu_console_resize (QemuConsole *s,int width,int height)
@@ -2162,8 +2153,7 @@ PixelFormat qemu_default_pixelformat(int bpp)return pf; } -static void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend, -Error **errp) +void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend,Error **errp) {int val;ChardevVC *vc;
ui/gtk.c +21 -9
@@ -1712,16 +1712,14 @@ static void gd_vc_chr_set_echo(Chardev *chr, bool echo)static int nb_vcs;static Chardev *vcs[MAX_VCS ]; +static const CharDriver gd_vc_driver; -static Chardev *gd_vc_handler (ChardevVC *vc,Error **errp) +static Chardev *vc_init (const CharDriver *driver, +const char *id,ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp) { -static const CharDriver gd_vc_driver = { - .instance_size =sizeof (VCChardev), - .kind =CHARDEV_BACKEND_KIND_VC , - .chr_write = gd_vc_chr_write, - .chr_set_echo = gd_vc_chr_set_echo, - }; - +ChardevVC *vc = backend->u.vc.data;ChardevCommon *common =qapi_ChardevVC_base (vc);Chardev *chr;
@@ -1737,9 +1735,22 @@ static Chardev *gd_vc_handler(ChardevVC *vc, Error **errp) vcs[nb_vcs++] = chr; +/* console/chardev init sometimes completes elsewhere in a 2nd +* stage, so defer OPENED events until they are fully initialized +*/ + *be_opened = false; +return chr; } +static const CharDriver gd_vc_driver = { + .instance_size =sizeof (VCChardev), + .kind =CHARDEV_BACKEND_KIND_VC , + .parse = qemu_chr_parse_vc, .create = vc_init, + .chr_write = gd_vc_chr_write, + .chr_set_echo = gd_vc_chr_set_echo, +}; +static gboolean gd_vc_in (VteTerminal *terminal,gchar *text,guint size,gpointer user_data) {
@@ -2336,6 +2347,7 @@ void early_gtk_display_init(int opengl) }#if defined(CONFIG_VTE ) -register_vc_handler (gd_vc_handler); +/* overwrite the console.c vc driver */ +register_char_driver (&gd_vc_driver);#endif }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 31/41] char: allocate CharDriverState as a single object
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Use a single allocation for CharDriverState, this avoids extra allocations & pointers, and is a step towards more object-oriented CharDriver.
Gtk console is a bit peculiar, gd_vc_chr_set_echo() used to have a temporary VirtualConsole to save the echo bit. Instead now, we consider whether vcd->console is set or not, and restore the echo bit saved in VCDriverState when calling gd_vc_vte_init().
The casts added are temporary, they are replaced with QOM type-safe macros in a later patch in this series.
--- backends/baum.c | 23 ++--- backends/msmouse.c | 16 +-- backends/testdev.c | 22 ++-- gdbstub.c | 1 + hw/bt/hci-csr.c | 10 +- include/sysemu/char.h | 2 +- qemu-char.c | 280 ++++++++++++++++++++++++++------------------------ spice-qemu-char.c | 39 +++---- ui/console.c | 21 ++-- ui/gtk.c | 30 ++++-- 10 files changed, 230 insertions(+), 214 deletions(-)
backends/baum.c +10 -13
@@ -85,7 +85,7 @@#define BUF_SIZE 256 typedef struct { - CharDriverState *chr; + CharDriverState parent; brlapi_handle_t *brlapi; int brlapi_fd;
@@ -255,7 +255,7 @@ static int baum_deferred_init(BaumDriverState *baum)/* The serial port can receive more of our data */ static void baum_accept_input (struct CharDriverState *chr) { -BaumDriverState *baum = chr->opaque; +BaumDriverState *baum = (BaumDriverState *)chr;int room, first;if (!baum->out_buf_used)
@@ -281,22 +281,23 @@ static void baum_accept_input(struct CharDriverState *chr)/* We want to send a packet */ static void baum_write_packet (BaumDriverState *baum,const uint8_t *buf,int len) { +CharDriverState *chr = (CharDriverState *)baum;uint8_t io_buf[1 +2 * len], *cur = io_buf;int room; *cur++ =ESC ;while (len--)if ((*cur++ = *buf++) ==ESC ) *cur++ =ESC ; - room =qemu_chr_be_can_write (baum->chr); + room =qemu_chr_be_can_write (chr); len = cur - io_buf;if (len <= room) {/* Fits */ -qemu_chr_be_write (baum->chr, io_buf, len); +qemu_chr_be_write (chr, io_buf, len); }else {int first;uint8_t out;/* Can't fit all, send what can be, and store the rest. */ -qemu_chr_be_write (baum->chr, io_buf, room); +qemu_chr_be_write (chr, io_buf, room); len -= room; cur = io_buf + room;if (len >BUF_SIZE - baum->out_buf_used) {
@@ -471,7 +472,7 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)/* The other end is writing some data. Store it and try to interpret */ static int baum_write (CharDriverState *chr,const uint8_t *buf,int len) { -BaumDriverState *baum = chr->opaque; +BaumDriverState *baum = (BaumDriverState *)chr;int tocopy, cur, eaten, orig_len = len;if (!len)
@@ -612,14 +613,13 @@ static void baum_chr_read(void *opaque)static void baum_free (struct CharDriverState *chr) { -BaumDriverState *baum = chr->opaque; +BaumDriverState *baum = (BaumDriverState *)chr;timer_free (baum->cellCount_timer);if (baum->brlapi) {brlapi__closeConnection (baum->brlapi);g_free (baum->brlapi); } -g_free (baum); } static CharDriverState *chr_baum_init(const CharDriver *driver,
@@ -638,10 +638,7 @@ static CharDriverState *chr_baum_init(const CharDriver *driver,if (!chr) {return NULL ; } - baum =g_malloc0 (sizeof (BaumDriverState)); - baum->chr = chr; - - chr->opaque = baum; + baum = (BaumDriverState *)chr; handle =g_malloc0 (brlapi_getHandleSize ()); baum->brlapi = handle;
@@ -663,13 +660,13 @@ static CharDriverState *chr_baum_init(const CharDriver *driver, fail_handle:g_free (handle);g_free (chr); -g_free (baum);return NULL ; }static void register_types (void ) {static const CharDriver driver = { + .instance_size =sizeof (BaumDriverState), .kind =CHARDEV_BACKEND_KIND_BRAILLE , .create = chr_baum_init, .chr_write = baum_write,
backends/msmouse.c +8 -8
@@ -31,7 +31,8 @@#define MSMOUSE_HI2 (n) (((n) & 0xc0) >> 6) typedef struct { - CharDriverState *chr; + CharDriverState parent; + QemuInputHandlerState *hs; int axis[INPUT_AXIS__MAX]; bool btns[INPUT_BUTTON__MAX];
@@ -42,7 +43,7 @@ typedef struct {static void msmouse_chr_accept_input (CharDriverState *chr) { -MouseState *mouse = chr->opaque; +MouseState *mouse = (MouseState *)chr;int len; len =qemu_chr_be_can_write (chr);
@@ -122,9 +123,10 @@ static void msmouse_input_event(DeviceState *dev, QemuConsole *src,static void msmouse_input_sync (DeviceState *dev) {MouseState *mouse = (MouseState *)dev; +CharDriverState *chr = (CharDriverState *)dev;msmouse_queue_event (mouse); -msmouse_chr_accept_input (mouse->chr); +msmouse_chr_accept_input (chr); }static int msmouse_chr_write (struct CharDriverState *s,const uint8_t *buf,int len)
@@ -135,10 +137,9 @@ static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, intstatic void msmouse_chr_free (struct CharDriverState *chr) { -MouseState *mouse = chr->opaque; +MouseState *mouse = (MouseState *)chr;qemu_input_handler_unregister (mouse->hs); -g_free (mouse); }static QemuInputHandler msmouse_handler = {
@@ -165,12 +166,10 @@ static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver, } *be_opened = false; - mouse =g_new0 (MouseState,1 ); + mouse = (MouseState *)chr; mouse->hs =qemu_input_handler_register ((DeviceState *)mouse, &msmouse_handler); - mouse->chr = chr; - chr->opaque = mouse;return chr; }
@@ -178,6 +177,7 @@ static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver,static void register_types (void ) {static const CharDriver driver = { + .instance_size =sizeof (MouseState), .kind =CHARDEV_BACKEND_KIND_MSMOUSE , .create = qemu_chr_open_msmouse, .chr_write = msmouse_chr_write,
backends/testdev.c +6 -16
@@ -30,7 +30,8 @@#define BUF_SIZE 32typedef struct { -CharDriverState *chr; +CharDriverState parent; +uint8_t in_buf[32 ];int in_buf_used; }TestdevCharState ;
@@ -79,7 +80,7 @@ static int testdev_eat_packet(TestdevCharState *testdev)/* The other end is writing some data. Store it and try to interpret */ static int testdev_write (CharDriverState *chr,const uint8_t *buf,int len) { -TestdevCharState *testdev = chr->opaque; +TestdevCharState *testdev = (TestdevCharState *)chr;int tocopy, eaten, orig_len = len;while (len) {
@@ -102,13 +103,6 @@ static int testdev_write(CharDriverState *chr, const uint8_t *buf, int len)return orig_len; } -static void testdev_free (struct CharDriverState *chr) -{ -TestdevCharState *testdev = chr->opaque; - -g_free (testdev); -} - static CharDriverState *chr_testdev_init(const CharDriver *driver, const char *id, ChardevBackend *backend,
@@ -116,14 +110,10 @@ static CharDriverState *chr_testdev_init(const CharDriver *driver,bool *be_opened, Error **errp) { - TestdevCharState *testdev; -CharDriverState *chr; - - testdev =g_new0 (TestdevCharState,1 ); - testdev->chr = chr =g_new0 (CharDriverState,1 ); + TestdevCharState *testdev = g_new0(TestdevCharState, 1);; +CharDriverState *chr = (CharDriverState *)testdev; chr->driver = driver; - chr->opaque = testdev;return chr; }
@@ -131,10 +121,10 @@ static CharDriverState *chr_testdev_init(const CharDriver *driver,static void register_types (void ) {static const CharDriver driver = { + .instance_size =sizeof (TestdevCharState), .kind =CHARDEV_BACKEND_KIND_TESTDEV , .create = chr_testdev_init, .chr_write = testdev_write, - .chr_free = testdev_free, };register_char_driver (&driver); }
gdbstub.c +1 -0
@@ -1732,6 +1732,7 @@ int gdbserver_start(const char *device)CharDriverState *mon_chr;ChardevCommon common = {0 };static const CharDriver driver = { + .instance_size =sizeof (CharDriverState), .kind =-1 , .chr_write = gdb_monitor_write, };
hw/bt/hci-csr.c +5 -5
@@ -28,11 +28,11 @@#include "hw/bt.h" struct csrhci_s { +CharDriverState chr;int enable;qemu_irq *pins;int pin_state;int modem_state; -CharDriverState chr;#define FIFO_LEN 4096int out_start;int out_len;
@@ -314,7 +314,7 @@ static void csrhci_ready_for_next_inpkt(struct csrhci_s *s)static int csrhci_write (struct CharDriverState *chr,const uint8_t *buf,int len) { -struct csrhci_s *s = (struct csrhci_s *) chr->opaque; +struct csrhci_s *s = (struct csrhci_s *)chr;int total =0 ;if (!s->enable)
@@ -387,7 +387,7 @@ static void csrhci_out_hci_packet_acl(void *opaque,static int csrhci_ioctl (struct CharDriverState *chr,int cmd,void *arg) {QEMUSerialSetParams *ssp; -struct csrhci_s *s = (struct csrhci_s *) chr->opaque; +struct csrhci_s *s = (struct csrhci_s *) chr;int prev_state = s->modem_state;switch (cmd) {
@@ -455,7 +455,7 @@ static void csrhci_pins(void *opaque, int line, int level)qemu_irq *csrhci_pins_get (CharDriverState *chr) { -struct csrhci_s *s = (struct csrhci_s *) chr->opaque; +struct csrhci_s *s = (struct csrhci_s *) chr;return s->pins; }
@@ -463,6 +463,7 @@ qemu_irq *csrhci_pins_get(CharDriverState *chr)CharDriverState *uart_hci_init (void ) {static const CharDriver hci_driver = { + .instance_size =sizeof (struct csrhci_s ), .kind =-1 , .chr_write = csrhci_write, .chr_ioctl = csrhci_ioctl,
@@ -470,7 +471,6 @@ CharDriverState *uart_hci_init(void)struct csrhci_s *s = (struct csrhci_s *)g_malloc0 (sizeof (struct csrhci_s )); - s->chr.opaque = s; s->chr.driver = &hci_driver; s->hci =qemu_next_hci ();
include/sysemu/char.h +1 -1
@@ -93,7 +93,6 @@ struct CharDriverState {const CharDriver *driver;QemuMutex chr_write_lock;CharBackend *be; -void *opaque;char *label;char *filename;int logfd;
@@ -484,6 +483,7 @@ struct CharDriver { ChardevBackend *backend, ChardevReturn *ret, bool *be_opened, Error **errp); +size_t instance_size;int (*chr_write)(struct CharDriverState *s,const uint8_t *buf,int len); int (*chr_sync_read)(struct CharDriverState *s,
qemu-char.c +144 -136
1,101 lines not on this page · raw message
spice-qemu-char.c +21 -18
@@ -7,7 +7,8 @@ typedef struct SpiceCharDriver { - CharDriverState* chr; + CharDriverState parent; + SpiceCharDeviceInstance sin; bool active; bool blocked;
@@ -27,17 +28,18 @@ static QLIST_HEAD(, SpiceCharDriver) spice_chars =static int vmc_write (SpiceCharDeviceInstance *sin,const uint8_t *buf,int len) {SpiceCharDriver *scd =container_of (sin, SpiceCharDriver, sin); +CharDriverState *chr = (CharDriverState *)scd;ssize_t out =0 ;ssize_t last_out;uint8_t * p = (uint8_t *)buf;while (len >0 ) { -int can_write =qemu_chr_be_can_write (scd->chr); +int can_write =qemu_chr_be_can_write (chr); last_out =MIN (len, can_write);if (last_out <=0 ) {break ; } -qemu_chr_be_write (scd->chr, p, last_out); +qemu_chr_be_write (chr, p, last_out); out += last_out; len -= last_out; p += last_out;
@@ -70,6 +72,7 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)static void vmc_event (SpiceCharDeviceInstance *sin,uint8_t event) {SpiceCharDriver *scd =container_of (sin, SpiceCharDriver, sin); +CharDriverState *chr = (CharDriverState *)scd;int chr_event;switch (event) {
@@ -81,20 +84,21 @@ static void vmc_event(SpiceCharDeviceInstance *sin, uint8_t event) }trace_spice_vmc_event (chr_event); -qemu_chr_be_event (scd->chr, chr_event); +qemu_chr_be_event (chr, chr_event); }#endif static void vmc_state (SpiceCharDeviceInstance *sin,int connected) {SpiceCharDriver *scd =container_of (sin, SpiceCharDriver, sin); +CharDriverState *chr = (CharDriverState *)scd; -if ((scd->chr->be_open && connected) || - (!scd->chr->be_open && !connected)) { +if ((chr->be_open && connected) || + (!chr->be_open && !connected)) {return ; } -qemu_chr_be_event (scd->chr, +qemu_chr_be_event (chr, connected ?CHR_EVENT_OPENED :CHR_EVENT_CLOSED ); }
@@ -168,7 +172,7 @@ static GSourceFuncs SpiceCharSourceFuncs = {static GSource *spice_chr_add_watch (CharDriverState *chr,GIOCondition cond) { -SpiceCharDriver *scd = chr->opaque; +SpiceCharDriver *scd = (SpiceCharDriver *)chr;SpiceCharSource *src;assert (cond &G_IO_OUT );
@@ -182,7 +186,7 @@ static GSource *spice_chr_add_watch(CharDriverState *chr, GIOCondition cond)static int spice_chr_write (CharDriverState *chr,const uint8_t *buf,int len) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;int read_bytes;assert (s->datalen ==0 );
@@ -201,7 +205,7 @@ static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)static void spice_chr_free (struct CharDriverState *chr) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;vmc_unregister_interface (s);QLIST_REMOVE (s, next);
@@ -210,12 +214,11 @@ static void spice_chr_free(struct CharDriverState *chr)#if SPICE_SERVER_VERSION >=0x000c02 g_free ((char *)s->sin.portname);#endif -g_free (s); }static void spice_vmc_set_fe_open (struct CharDriverState *chr,int fe_open) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;if (fe_open) {vmc_register_interface (s); }else {
@@ -226,7 +229,7 @@ static void spice_vmc_set_fe_open(struct CharDriverState *chr, int fe_open)static void spice_port_set_fe_open (struct CharDriverState *chr,int fe_open) {#if SPICE_SERVER_VERSION >=0x000c02 -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;if (fe_open) {spice_server_port_event (&s->sin,SPICE_PORT_EVENT_OPENED );
@@ -255,7 +258,7 @@ static void print_allowed_subtypes(void)static void spice_chr_accept_input (struct CharDriverState *chr) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;spice_server_char_device_wakeup (&s->sin); }
@@ -272,11 +275,9 @@ static CharDriverState *chr_open(const CharDriver *driver,if (!chr) {return NULL ; } - s =g_malloc0 (sizeof (SpiceCharDriver)); - s->chr = chr; + s = (SpiceCharDriver *)chr; s->active = false; s->sin.subtype =g_strdup (subtype); - chr->opaque = s;QLIST_INSERT_HEAD (&spice_chars, s, next);
@@ -334,7 +335,7 @@ static CharDriverState *qemu_chr_open_spice_port(const CharDriver *driver,return NULL ; } *be_opened = false; - s = chr->opaque; + s = (SpiceCharDriver *)chr; s->sin.portname =g_strdup (name);return chr;
@@ -386,6 +387,7 @@ static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,static void register_types (void ) {static const CharDriver vmc_driver = { + .instance_size =sizeof (SpiceCharDriver), .kind =CHARDEV_BACKEND_KIND_SPICEVMC , .parse = qemu_chr_parse_spice_vmc, .create = qemu_chr_open_spice_vmc,
@@ -396,6 +398,7 @@ static void register_types(void) .chr_free = spice_chr_free, };static const CharDriver port_driver = { + .instance_size =sizeof (SpiceCharDriver), .kind =CHARDEV_BACKEND_KIND_SPICEPORT , .parse = qemu_chr_parse_spice_port, .create = qemu_chr_open_spice_port,
ui/console.c +15 -6
@@ -1046,9 +1046,15 @@ void console_select(unsigned int index) } } +typedef struct VCDriverState { +CharDriverState parent; +QemuConsole *console; +}VCDriverState ; +static int console_puts (CharDriverState *chr,const uint8_t *buf,int len) { -QemuConsole *s = chr->opaque; +VCDriverState *drv = (VCDriverState *)chr; +QemuConsole *s = drv->console;int i;if (!s->ds) {
@@ -1958,7 +1964,8 @@ int qemu_console_get_height(QemuConsole *con, int fallback)static void text_console_set_echo (CharDriverState *chr,bool echo) { -QemuConsole *s = chr->opaque; +VCDriverState *drv = (VCDriverState *)chr; +QemuConsole *s = drv->console; s->echo = echo; }
@@ -1998,12 +2005,11 @@ static const GraphicHwOps text_console_ops = {static void text_console_do_init (CharDriverState *chr,DisplayState *ds) { -QemuConsole *s; +VCDriverState *drv = (VCDriverState *)chr; +QemuConsole *s = drv->console;int g_width =80 *FONT_WIDTH ;int g_height =24 *FONT_HEIGHT ; - s = chr->opaque; - s->out_fifo.buf = s->out_fifo_buf; s->out_fifo.buf_size =sizeof (s->out_fifo_buf); s->kbd_timer =timer_new_ms (QEMU_CLOCK_REALTIME , kbd_send_chars, s);
@@ -2056,6 +2062,7 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) {ChardevCommon *common =qapi_ChardevVC_base (vc);CharDriverState *chr; +VCDriverState *drv;QemuConsole *s;unsigned width =0 ;unsigned height =0 ;
@@ -2092,7 +2099,8 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) } s->chr = chr; - chr->opaque = s; + drv = (VCDriverState *)chr; + drv->console = s;if (display_state) {text_console_do_init (chr, display_state);
@@ -2196,6 +2204,7 @@ static const TypeInfo qemu_console_info = { };static const CharDriver vc_driver = { + .instance_size =sizeof (VCDriverState), .kind =CHARDEV_BACKEND_KIND_VC , .parse = qemu_chr_parse_vc, .create = vc_init,
ui/gtk.c +19 -11
@@ -181,6 +181,12 @@ struct GtkDisplayState {bool ignore_keys; }; +typedef struct VCDriverState { +CharDriverState parent; +VirtualConsole *console; +bool echo; +}VCDriverState ; +static void gd_grab_pointer (VirtualConsole *vc,const char *reason);static void gd_ungrab_pointer (GtkDisplayState *s);static void gd_grab_keyboard (VirtualConsole *vc,const char *reason);
@@ -1685,7 +1691,8 @@ static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)static int gd_vc_chr_write (CharDriverState *chr,const uint8_t *buf,int len) { -VirtualConsole *vc = chr->opaque; +VCDriverState *vcd = (VCDriverState *)chr; +VirtualConsole *vc = vcd->console;vte_terminal_feed (VTE_TERMINAL (vc->vte.terminal), (const char *)buf, len);return len;
@@ -1693,9 +1700,14 @@ static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)static void gd_vc_chr_set_echo (CharDriverState *chr,bool echo) { -VirtualConsole *vc = chr->opaque; +VCDriverState *vcd = (VCDriverState *)chr; +VirtualConsole *vc = vcd->console; - vc->vte.echo = echo; +if (vc) { + vc->vte.echo = echo; + }else { + vcd->echo = echo; + } }static int nb_vcs;
@@ -1704,6 +1716,7 @@ static CharDriverState *vcs[MAX_VCS];static CharDriverState *gd_vc_handler (ChardevVC *vc,Error **errp) {static const CharDriver gd_vc_driver = { + .instance_size =sizeof (VCDriverState), .kind =CHARDEV_BACKEND_KIND_VC , .chr_write = gd_vc_chr_write, .chr_set_echo = gd_vc_chr_set_echo,
@@ -1722,9 +1735,6 @@ static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp)return NULL ; } -/* Temporary, until gd_vc_vte_init runs. */ - chr->opaque =g_new0 (VirtualConsole,1 ); - vcs[nb_vcs++] = chr;return chr;
@@ -1765,14 +1775,12 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,GtkWidget *box;GtkWidget *scrollbar;GtkAdjustment *vadjustment; -VirtualConsole *tmp_vc = chr->opaque; +VCDriverState *vcd = (VCDriverState *)chr; vc->s = s; - vc->vte.echo = tmp_vc->vte.echo; - + vc->vte.echo = vcd->echo; vc->vte.chr = chr; - chr->opaque = vc; -g_free (tmp_vc); + vcd->console = vc;snprintf (buffer,sizeof (buffer),"vc%d" , idx); vc->label = g_strdup_printf("%s", vc->vte.chr->label
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 39/41] vc: use a common prefix for chr callbacks
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
vc_chr_write() is more appropriate than _puts() since no newline is appended, even though it's not used only as a callback.
Keep "qemu_chr_parse" prefix, most chardev parse functions use this prefix atm.
--- ui/console.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
ui/console.c +12 -12
@@ -1051,7 +1051,7 @@ typedef struct VCChardev {QemuConsole *console; } VCChardev; -static int console_puts (Chardev *chr,const uint8_t *buf,int len) +static int vc_chr_write (Chardev *chr,const uint8_t *buf,int len) {VCChardev *drv = (VCChardev *)chr;QemuConsole *s = drv->console;
@@ -1139,13 +1139,13 @@ void kbd_put_keysym_console(QemuConsole *s, int keysym) *q++ ='[' ; *q++ = keysym &0xff ; }else if (s->echo && (keysym =='\r' || keysym =='\n' )) { -console_puts (s->chr, (const uint8_t *)"\r" ,1 ); +vc_chr_write (s->chr, (const uint8_t *)"\r" ,1 ); *q++ ='\n' ; }else { *q++ = keysym; }if (s->echo) { -console_puts (s->chr, buf, q - buf); +vc_chr_write (s->chr, buf, q - buf); } be = s->chr->be;if (be && be->chr_read) {
@@ -1962,7 +1962,7 @@ int qemu_console_get_height(QemuConsole *con, int fallback)return con ?surface_height (con->surface) : fallback; } -static void text_console_set_echo (Chardev *chr,bool echo) +static void vc_chr_set_echo (Chardev *chr,bool echo) {VCChardev *drv = (VCChardev *)chr;QemuConsole *s = drv->console;
@@ -2049,7 +2049,7 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds) s->t_attrib.bgcol =QEMU_COLOR_BLUE ; len =snprintf (msg,sizeof (msg),"%s console\r\n" , chr->label); -console_puts (chr, (uint8_t *)msg, len); +vc_chr_write (chr, (uint8_t *)msg, len); s->t_attrib = s->t_attrib_default; }
@@ -2058,10 +2058,10 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds)static const CharDriver vc_driver; -static Chardev *vc_init (const CharDriver *driver, -const char *id,ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp) +static Chardev *vc_chr_init (const CharDriver *driver, +const char *id,ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp) {ChardevVC *vc = backend->u.vc.data;ChardevCommon *common =qapi_ChardevVC_base (vc);
@@ -2197,9 +2197,9 @@ static const CharDriver vc_driver = { .instance_size = sizeof(VCChardev), .kind = CHARDEV_BACKEND_KIND_VC, .parse = qemu_chr_parse_vc, - .create = vc_init, - .chr_write = console_puts, - .chr_set_echo = text_console_set_echo, + .create = vc_chr_init, + .chr_write = vc_chr_write, + .chr_set_echo = vc_chr_set_echo, };static void register_types (void )
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 36/41] char: use error_report()
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Prefer error_report() over fprintf(stderr..)
--- qemu-char.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
qemu-char.c +14 -11
@@ -451,8 +451,8 @@ int qemu_chr_fe_get_msgfd(CharBackend *be)int fd;int res = (qemu_chr_fe_get_msgfds (be, &fd,1 ) ==1 ) ? fd :-1 ;if (s &&qemu_chr_replay (s)) { -fprintf (stderr, -"Replay: get msgfd is not supported for serial devices yet\n" ); +error_report ("Replay: get msgfd is not supported " +"for serial devices yet" );exit (1 ); }return res;
@@ -1680,8 +1680,8 @@ static Chardev *qemu_chr_open_pty(const CharDriver *driver, ret->pty =g_strdup (pty_name); ret->has_pty = true; -fprintf (stderr,"char device redirected to %s (label %s)\n" , - pty_name, id); +error_report ("char device redirected to %s (label %s)" , + pty_name, id); s = (PtyChardev *)chr; s->ioc =QIO_CHANNEL (qio_channel_file_new_fd (master_fd));
@@ -3383,8 +3383,8 @@ static int tcp_chr_wait_connected(Chardev *chr, Error **errp)* in TLS and telnet cases, only wait for an accepted socket */ while (!s->ioc) {if (s->is_listen) { -fprintf (stderr,"QEMU waiting for connection on: %s\n" , - chr->filename); +error_report ("QEMU waiting for connection on: %s" , + chr->filename);qio_channel_set_blocking (QIO_CHANNEL (s->listen_ioc), true,NULL );tcp_chr_accept (QIO_CHANNEL (s->listen_ioc),G_IO_IN , chr);qio_channel_set_blocking (QIO_CHANNEL (s->listen_ioc), false,NULL );
@@ -4146,16 +4146,19 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, }if (is_help_option (name)) { -fprintf (stderr,"Available chardev backend types:\n" ); +GString *str =g_string_new ("" );for (i =0 ; i <ARRAY_SIZE (backends); i++) { cd = backends[i];if (cd) { -fprintf (stderr,"%s\n" , ChardevBackendKind_lookup[cd->kind]); +g_string_append_printf (str,"\n%s" , ChardevBackendKind_lookup[cd->kind]);if (cd->alias) { -fprintf (stderr,"%s\n" , cd->alias); +g_string_append_printf (str,"\n%s" , cd->alias); } } } + +error_report ("Available chardev backend types: %s" , str->str); +g_string_free (str, true);exit (0 ); }
@@ -4267,8 +4270,8 @@ Chardev *qemu_chr_new(const char *label, const char *filename)qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_REPLAY ); }if (qemu_chr_replay (chr) && chr->driver->chr_ioctl) { -fprintf (stderr, -"Replay: ioctl is not supported for serial devices yet\n" ); +error_report ("Replay: ioctl is not supported " +"for serial devices yet" ); }replay_register_char_driver (chr); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 41/41] memory: don't sign-extend 32-bit writes
In reply to Paolo BonziniFrom: Ladi Prosek <[email protected]>
ldl_p has a signed return type so assigning it to uint64_t implicitly sign-extends the value. This results in devices with min_access_size = 8 seeing unexpected values passed to their write handlers.
Example: guest performs a 32-bit write of 0x80000000 to an mmio region and the handler receives 0xFFFFFFFF80000000 in its value argument.
Message-Id: <[email protected]>
--- exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
exec.c +1 -1
@@ -2630,7 +2630,7 @@ static MemTxResult address_space_write_continue(AddressSpace *as, hwaddr addr,break ;case 4 :/* 32 bit write access */ - val =ldl_p (buf); + val = (uint32_t )ldl_p (buf); result |=memory_region_dispatch_write (mr, addr1, val,4 , attrs);break ;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 33/41] char: rename CharDriverState Chardev
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Pick a uniform chardev type name.
--- backends/baum.c | 56 +-- backends/msmouse.c | 42 +- backends/rng-egd.c | 4 +- backends/testdev.c | 28 +- gdbstub.c | 12 +- hw/arm/fsl-imx25.c | 2 +- hw/arm/fsl-imx31.c | 2 +- hw/arm/fsl-imx6.c | 2 +- hw/arm/nseries.c | 2 +- hw/arm/omap2.c | 2 +- hw/arm/pxa2xx.c | 2 +- hw/arm/virt.c | 2 +- hw/bt/hci-csr.c | 14 +- hw/char/escc.c | 2 +- hw/char/exynos4210_uart.c | 2 +- hw/char/imx_serial.c | 2 +- hw/char/mcf_uart.c | 4 +- hw/char/omap_uart.c | 6 +- hw/char/parallel.c | 2 +- hw/char/serial-isa.c | 2 +- hw/char/serial.c | 4 +- hw/char/sh_serial.c | 2 +- hw/char/spapr_vty.c | 2 +- hw/char/virtio-console.c | 2 +- hw/core/qdev-properties-system.c | 4 +- hw/display/milkymist-tmu2.c | 2 +- hw/display/sm501.c | 2 +- hw/isa/isa-bus.c | 2 +- hw/isa/pc87312.c | 2 +- hw/lm32/lm32.h | 4 +- hw/lm32/milkymist-hw.h | 2 +- hw/mips/mips_malta.c | 4 +- hw/misc/ivshmem.c | 2 +- hw/misc/milkymist-pfpu.c | 2 +- hw/usb/ccid-card-passthru.c | 2 +- hw/usb/dev-serial.c | 6 +- hw/usb/redirect.c | 4 +- include/hw/arm/exynos4210.h | 2 +- include/hw/arm/omap.h | 6 +- include/hw/bt.h | 4 +- include/hw/char/cadence_uart.h | 2 +- include/hw/char/escc.h | 2 +- include/hw/char/pl011.h | 4 +- include/hw/char/serial.h | 4 +- include/hw/char/xilinx_uartlite.h | 2 +- include/hw/cris/etraxfs.h | 2 +- include/hw/devices.h | 2 +- include/hw/i386/pc.h | 2 +- include/hw/m68k/mcf.h | 4 +- include/hw/ppc/spapr_vio.h | 2 +- include/hw/qdev-properties.h | 2 +- include/hw/sh4/sh.h | 2 +- include/hw/sparc/grlib.h | 2 +- include/hw/xen/xen.h | 2 +- include/monitor/monitor.h | 2 +- include/qemu/typedefs.h | 2 +- include/sysemu/char.h | 94 ++--- include/sysemu/replay.h | 4 +- include/sysemu/sysemu.h | 4 +- include/ui/gtk.h | 2 +- include/ui/qemu-spice.h | 2 +- monitor.c | 4 +- net/colo-compare.c | 4 +- net/filter-mirror.c | 4 +- net/slirp.c | 2 +- net/vhost-user.c | 10 +- qemu-char.c | 839 +++++++++++++++++++------------------- qmp.c | 2 +- qtest.c | 2 +- replay/replay-char.c | 8 +- spice-qemu-char.c | 80 ++-- stubs/monitor.c | 2 +- stubs/replay.c | 4 +- tests/test-char.c | 10 +- tests/vhost-user-test.c | 4 +- ui/console.c | 40 +- ui/gtk.c | 26 +- vl.c | 10 +- xen-common-stub.c | 2 +- xen-common.c | 4 +- 80 files changed, 727 insertions(+), 724 deletions(-)
backends/baum.c +29 -27
@@ -85,7 +85,7 @@#define BUF_SIZE 256 typedef struct { - CharDriverState parent; + Chardev parent; brlapi_handle_t *brlapi; int brlapi_fd;
@@ -98,7 +98,7 @@ typedef struct {uint8_t out_buf_used, out_buf_ptr;QEMUTimer *cellCount_timer; -} BaumDriverState; +} BaumChardev;/* Let's assume NABCC by default */ enum way {
@@ -223,7 +223,7 @@ static const uint8_t nabcc_translation[2][256] = { };/* The guest OS has started discussing with us, finish initializing BrlAPI */ -static int baum_deferred_init (BaumDriverState *baum) +static int baum_deferred_init (BaumChardev *baum) {int tty =BRLAPI_TTY_DEFAULT ;QemuConsole *con;
@@ -253,9 +253,9 @@ static int baum_deferred_init(BaumDriverState *baum) }/* The serial port can receive more of our data */ -static void baum_accept_input (struct CharDriverState *chr) +static void baum_accept_input (struct Chardev *chr) { -BaumDriverState *baum = (BaumDriverState *)chr; +BaumChardev *baum = (BaumChardev *)chr;int room, first;if (!baum->out_buf_used)
@@ -279,9 +279,9 @@ static void baum_accept_input(struct CharDriverState *chr) }/* We want to send a packet */ -static void baum_write_packet (BaumDriverState *baum,const uint8_t *buf,int len) +static void baum_write_packet (BaumChardev *baum,const uint8_t *buf,int len) { -CharDriverState *chr = (CharDriverState *)baum; +Chardev *chr = (Chardev *)baum;uint8_t io_buf[1 +2 * len], *cur = io_buf;int room; *cur++ =ESC ;
@@ -322,14 +322,14 @@ static void baum_write_packet(BaumDriverState *baum, const uint8_t *buf, int len/* Called when the other end seems to have a wrong idea of our display size */ static void baum_cellCount_timer_cb (void *opaque) { -BaumDriverState *baum = opaque; +BaumChardev *baum = opaque;uint8_t cell_count[] = { BAUM_RSP_CellCount, baum->x * baum->y };DPRINTF ("Timeout waiting for DisplayData, sending cell count\n" );baum_write_packet (baum, cell_count,sizeof (cell_count)); }/* Try to interpret a whole incoming packet */ -static int baum_eat_packet (BaumDriverState *baum,const uint8_t *buf,int len) +static int baum_eat_packet (BaumChardev *baum,const uint8_t *buf,int len) {const uint8_t *cur = buf;uint8_t req =0 ;
@@ -470,9 +470,9 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len) }/* The other end is writing some data. Store it and try to interpret */ -static int baum_write (CharDriverState *chr,const uint8_t *buf,int len) +static int baum_write (Chardev *chr,const uint8_t *buf,int len) { -BaumDriverState *baum = (BaumDriverState *)chr; +BaumChardev *baum = (BaumChardev *)chr;int tocopy, cur, eaten, orig_len = len;if (!len)
@@ -511,14 +511,16 @@ static int baum_write(CharDriverState *chr, const uint8_t *buf, int len) }/* Send the key code to the other end */ -static void baum_send_key (BaumDriverState *baum,uint8_t type,uint8_t value) { +static void baum_send_key (BaumChardev *baum,uint8_t type,uint8_t value) +{uint8_t packet[] = { type, value };DPRINTF ("writing key %x %x\n" , type, value);baum_write_packet (baum, packet,sizeof (packet)); } -static void baum_send_key2 (BaumDriverState *baum,uint8_t type,uint8_t value, -uint8_t value2) { +static void baum_send_key2 (BaumChardev *baum,uint8_t type,uint8_t value, +uint8_t value2) +{uint8_t packet[] = { type, value, value2 };DPRINTF ("writing key %x %x\n" , type, value);baum_write_packet (baum, packet,sizeof (packet));
@@ -527,7 +529,7 @@ static void baum_send_key2(BaumDriverState *baum, uint8_t type, uint8_t value,/* We got some data on the BrlAPI socket */ static void baum_chr_read (void *opaque) { -BaumDriverState *baum = opaque; +BaumChardev *baum = opaque;brlapi_keyCode_t code;int ret;if (!baum->brlapi)
@@ -611,9 +613,9 @@ static void baum_chr_read(void *opaque) } } -static void baum_free (struct CharDriverState *chr) +static void baum_free (struct Chardev *chr) { -BaumDriverState *baum = (BaumDriverState *)chr; +BaumChardev *baum = (BaumChardev *)chr;timer_free (baum->cellCount_timer);if (baum->brlapi) {
@@ -622,23 +624,23 @@ static void baum_free(struct CharDriverState *chr) } } -static CharDriverState *chr_baum_init (const CharDriver *driver, -const char *id, -ChardevBackend *backend, -ChardevReturn *ret, -bool *be_opened, -Error **errp) +static Chardev *chr_baum_init (const CharDriver *driver, +const char *id, +ChardevBackend *backend, +ChardevReturn *ret, +bool *be_opened, +Error **errp) {ChardevCommon *common = backend->u.braille.data; -BaumDriverState *baum; -CharDriverState *chr; +BaumChardev *baum; +Chardev *chr;brlapi_handle_t *handle; chr =qemu_chr_alloc (driver, common, errp);if (!chr) {return NULL ; } - baum = (BaumDriverState *)chr; + baum = (BaumChardev *)chr; handle =g_malloc0 (brlapi_getHandleSize ()); baum->brlapi = handle;
@@ -666,7 +668,7 @@ fail_handle:static void register_types (void ) {static const CharDriver driver = { - .instance_size =sizeof (BaumDriverState), + .instance_size =sizeof (BaumChardev), .kind =CHARDEV_BACKEND_KIND_BRAILLE , .create = chr_baum_init, .chr_write = baum_write,
backends/msmouse.c +21 -21
105 lines not on this page · raw message
backends/rng-egd.c +2 -2
@@ -86,7 +86,7 @@ static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size)static void rng_egd_opened (RngBackend *b,Error **errp) {RngEgd *s =RNG_EGD (b); -CharDriverState *chr; +Chardev *chr;if (s->chr_name ==NULL ) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
@@ -125,7 +125,7 @@ static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)static char *rng_egd_get_chardev (Object *obj,Error **errp) {RngEgd *s =RNG_EGD (obj); -CharDriverState *chr =qemu_chr_fe_get_driver (&s->chr); +Chardev *chr =qemu_chr_fe_get_driver (&s->chr);if (chr && chr->label) {return g_strdup (chr->label);
backends/testdev.c +14 -14
@@ -30,14 +30,14 @@#define BUF_SIZE 32typedef struct { -CharDriverState parent; +Chardev parent;uint8_t in_buf[32 ];int in_buf_used; -}TestdevCharState ; +}TestdevChardev ;/* Try to interpret a whole incoming packet */ -static int testdev_eat_packet (TestdevCharState *testdev) +static int testdev_eat_packet (TestdevChardev *testdev) {const uint8_t *cur = testdev->in_buf;int len = testdev->in_buf_used;
@@ -78,9 +78,9 @@ static int testdev_eat_packet(TestdevCharState *testdev) }/* The other end is writing some data. Store it and try to interpret */ -static int testdev_write (CharDriverState *chr,const uint8_t *buf,int len) +static int testdev_write (Chardev *chr,const uint8_t *buf,int len) { -TestdevCharState *testdev = (TestdevCharState *)chr; +TestdevChardev *testdev = (TestdevChardev *)chr;int tocopy, eaten, orig_len = len;while (len) {
@@ -103,15 +103,15 @@ static int testdev_write(CharDriverState *chr, const uint8_t *buf, int len)return orig_len; } -static CharDriverState *chr_testdev_init (const CharDriver *driver, -const char *id, -ChardevBackend *backend, -ChardevReturn *ret, -bool *be_opened, -Error **errp) +static Chardev *chr_testdev_init (const CharDriver *driver, +const char *id, +ChardevBackend *backend, +ChardevReturn *ret, +bool *be_opened, +Error **errp) { -TestdevCharState *testdev =g_new0 (TestdevCharState,1 );; -CharDriverState *chr = (CharDriverState *)testdev; +TestdevChardev *testdev =g_new0 (TestdevChardev,1 );; +Chardev *chr = (Chardev *)testdev; chr->driver = driver;
@@ -121,7 +121,7 @@ static CharDriverState *chr_testdev_init(const CharDriver *driver,static void register_types (void ) {static const CharDriver driver = { - .instance_size =sizeof (TestdevCharState), + .instance_size =sizeof (TestdevChardev), .kind =CHARDEV_BACKEND_KIND_TESTDEV , .create = chr_testdev_init, .chr_write = testdev_write,
gdbstub.c +6 -6
@@ -304,7 +304,7 @@ typedef struct GDBState {int running_state;#else CharBackend chr; -CharDriverState *mon_chr; +Chardev *mon_chr;#endif char syscall_buf[256 ];gdb_syscall_complete_cb current_syscall_cb;
@@ -1472,7 +1472,7 @@ void gdb_exit(CPUArchState *env, int code)GDBState *s;char buf[4 ];#ifndef CONFIG_USER_ONLY -CharDriverState *chr; +Chardev *chr;#endif s = gdbserver_state;
@@ -1697,7 +1697,7 @@ static void gdb_monitor_output(GDBState *s, const char *msg, int len)put_packet (s, buf); } -static int gdb_monitor_write (CharDriverState *chr,const uint8_t *buf,int len) +static int gdb_monitor_write (Chardev *chr,const uint8_t *buf,int len) {const char *p = (const char *)buf;int max_sz;
@@ -1728,11 +1728,11 @@ int gdbserver_start(const char *device) {GDBState *s;char gdbstub_device_name[128 ]; -CharDriverState *chr =NULL ; -CharDriverState *mon_chr; +Chardev *chr =NULL ; +Chardev *mon_chr;ChardevCommon common = {0 };static const CharDriver driver = { - .instance_size =sizeof (CharDriverState), + .instance_size =sizeof (Chardev), .kind =-1 , .chr_write = gdb_monitor_write, };
hw/arm/fsl-imx25.c +1 -1
@@ -118,7 +118,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp) };if (i <MAX_SERIAL_PORTS ) { -CharDriverState *chr; +Chardev *chr; chr = serial_hds[i];
hw/arm/fsl-imx31.c +1 -1
@@ -107,7 +107,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp) };if (i <MAX_SERIAL_PORTS ) { -CharDriverState *chr; +Chardev *chr; chr = serial_hds[i];
hw/arm/fsl-imx6.c +1 -1
@@ -187,7 +187,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp) };if (i <MAX_SERIAL_PORTS ) { -CharDriverState *chr; +Chardev *chr; chr = serial_hds[i];
hw/arm/nseries.c +1 -1
@@ -786,7 +786,7 @@ static void n8x0_cbus_setup(struct n800_s *s)static void n8x0_uart_setup (struct n800_s *s) { -CharDriverState *radio =uart_hci_init (); +Chardev *radio =uart_hci_init ();qdev_connect_gpio_out (s->mpu->gpio,N8X0_BT_RESET_GPIO ,csrhci_pins_get (radio)[csrhci_pin_reset]);
hw/arm/omap2.c +1 -1
@@ -792,7 +792,7 @@ static const MemoryRegionOps omap_sti_fifo_ops = {static struct omap_sti_s *omap_sti_init (struct omap_target_agent_s *ta,MemoryRegion *sysmem,hwaddr channel_base,qemu_irq irq,omap_clk clk, -CharDriverState *chr) +Chardev *chr) { struct omap_sti_s *s = g_new0(struct omap_sti_s, 1);
hw/arm/pxa2xx.c +1 -1
@@ -2024,7 +2024,7 @@ static PXA2xxFIrState *pxa2xx_fir_init(MemoryRegion *sysmem,hwaddr base, qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma, - CharDriverState *chr) + Chardev *chr) { DeviceState *dev;SysBusDevice *sbd;
hw/arm/virt.c +1 -1
@@ -613,7 +613,7 @@ static void create_gic(VirtMachineState *vms, qemu_irq *pic) }static void create_uart (const VirtMachineState *vms,qemu_irq *pic,int uart, -MemoryRegion *mem,CharDriverState *chr) +MemoryRegion *mem,Chardev *chr) {char *nodename;hwaddr base = vms->memmap[uart].base;
hw/bt/hci-csr.c +7 -7
@@ -29,7 +29,7 @@#include "qapi/error.h" struct csrhci_s { -CharDriverState parent; +Chardev parent;int enable;qemu_irq *pins;int pin_state;
@@ -79,7 +79,7 @@ enum {static inline void csrhci_fifo_wake (struct csrhci_s *s) { -CharDriverState *chr = (CharDriverState *)s; +Chardev *chr = (Chardev *)s;CharBackend *be = chr->be;if (!s->enable || !s->out_len)
@@ -313,7 +313,7 @@ static void csrhci_ready_for_next_inpkt(struct csrhci_s *s) s->in_hdr =INT_MAX ; } -static int csrhci_write (struct CharDriverState *chr, +static int csrhci_write (struct Chardev *chr,const uint8_t *buf,int len) {struct csrhci_s *s = (struct csrhci_s *)chr;
@@ -386,7 +386,7 @@ static void csrhci_out_hci_packet_acl(void *opaque,csrhci_fifo_wake (s); } -static int csrhci_ioctl (struct CharDriverState *chr,int cmd,void *arg) +static int csrhci_ioctl (struct Chardev *chr,int cmd,void *arg) {QEMUSerialSetParams *ssp;struct csrhci_s *s = (struct csrhci_s *) chr;
@@ -455,14 +455,14 @@ static void csrhci_pins(void *opaque, int line, int level) } } -qemu_irq *csrhci_pins_get (CharDriverState *chr) +qemu_irq *csrhci_pins_get (Chardev *chr) {struct csrhci_s *s = (struct csrhci_s *) chr;return s->pins; } -CharDriverState *uart_hci_init (void ) +Chardev *uart_hci_init (void ) {static const CharDriver hci_driver = { .instance_size =sizeof (struct csrhci_s ),
@@ -472,7 +472,7 @@ CharDriverState *uart_hci_init(void) };Error *err =NULL ;ChardevCommon common = {0 , }; -CharDriverState *chr =qemu_chr_alloc (&hci_driver, &common, &err); +Chardev *chr =qemu_chr_alloc (&hci_driver, &common, &err);struct csrhci_s *s = (struct csrhci_s *)chr;if (err) {
hw/char/escc.c +1 -1
@@ -689,7 +689,7 @@ static const VMStateDescription vmstate_escc = { };MemoryRegion *escc_init (hwaddr base,qemu_irq irqA,qemu_irq irqB, -CharDriverState *chrA,CharDriverState *chrB, +Chardev *chrA,Chardev *chrB,int clock,int it_shift) {DeviceState *dev;
hw/char/exynos4210_uart.c +1 -1
@@ -586,7 +586,7 @@ static const VMStateDescription vmstate_exynos4210_uart = {DeviceState *exynos4210_uart_create (hwaddr addr,int fifo_size,int channel, -CharDriverState *chr, +Chardev *chr,qemu_irq irq) {DeviceState *dev;
hw/char/imx_serial.c +1 -1
@@ -170,7 +170,7 @@ static void imx_serial_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) {IMXSerialState *s = (IMXSerialState *)opaque; -CharDriverState *chr =qemu_chr_fe_get_driver (&s->chr); +Chardev *chr =qemu_chr_fe_get_driver (&s->chr);unsigned char ch; DPRINTF("write(offset=0x%" HWADDR_PRIx ", value = 0x%x) to %s\n",
hw/char/mcf_uart.c +2 -2
@@ -275,7 +275,7 @@ static void mcf_uart_receive(void *opaque, const uint8_t *buf, int size)mcf_uart_push_byte (s, buf[0 ]); } -void *mcf_uart_init (qemu_irq irq,CharDriverState *chr) +void *mcf_uart_init (qemu_irq irq,Chardev *chr) {mcf_uart_state *s;
@@ -300,7 +300,7 @@ static const MemoryRegionOps mcf_uart_ops = {void mcf_uart_mm_init (MemoryRegion *sysmem,hwaddr base,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {mcf_uart_state *s;
hw/char/omap_uart.c +3 -3
@@ -54,7 +54,7 @@ void omap_uart_reset(struct omap_uart_s *s)struct omap_uart_s *omap_uart_init (hwaddr base,qemu_irq irq,omap_clk fclk,omap_clk iclk,qemu_irq txdma,qemu_irq rxdma, -const char *label,CharDriverState *chr) +const char *label,Chardev *chr) { struct omap_uart_s *s = g_new0(struct omap_uart_s, 1);
@@ -163,7 +163,7 @@ struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,struct omap_target_agent_s *ta, qemu_irq irq, omap_clk fclk, omap_clk iclk, qemu_irq txdma, qemu_irq rxdma, - const char *label, CharDriverState *chr) + const char *label, Chardev *chr) { hwaddr base = omap_l4_attach(ta, 0, NULL); struct omap_uart_s *s = omap_uart_init(base, irq,
@@ -178,7 +178,7 @@ struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,return s; } -void omap_uart_attach (struct omap_uart_s *s,CharDriverState *chr) +void omap_uart_attach (struct omap_uart_s *s,Chardev *chr) {/* TODO: Should reuse or destroy current s->serial */ s->serial = serial_mm_init(get_system_memory(), s->base, 2, s->irq,
hw/char/parallel.c +1 -1
@@ -603,7 +603,7 @@ static const MemoryRegionOps parallel_mm_ops = {/* If fd is zero, it means that the parallel device uses the console */ bool parallel_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {ParallelState *s;
hw/char/serial-isa.c +1 -1
@@ -121,7 +121,7 @@ static void serial_register_types(void)type_init (serial_register_types) -static void serial_isa_init(ISABus *bus, int index, CharDriverState *chr) +static void serial_isa_init(ISABus *bus, int index, Chardev *chr) {DeviceState *dev;ISADevice *isadev;
hw/char/serial.c +2 -2
@@ -937,7 +937,7 @@ const MemoryRegionOps serial_io_ops = { };SerialState *serial_init (int base,qemu_irq irq,int baudbase, -CharDriverState *chr,MemoryRegion *system_io) +Chardev *chr,MemoryRegion *system_io) {SerialState *s;
@@ -993,7 +993,7 @@ static const MemoryRegionOps serial_mm_ops[3] = {SerialState *serial_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq,int baudbase, -CharDriverState *chr,enum device_endian end) +Chardev *chr,enum device_endian end) {SerialState *s;
hw/char/sh_serial.c +1 -1
@@ -356,7 +356,7 @@ static const MemoryRegionOps sh_serial_ops = { void sh_serial_init(MemoryRegion *sysmem, hwaddr base, int feat, - uint32_t freq, CharDriverState *chr, + uint32_t freq, Chardev *chr, qemu_irq eri_source, qemu_irq rxi_source, qemu_irq txi_source,
hw/char/spapr_vty.c +1 -1
@@ -141,7 +141,7 @@ static target_ulong h_get_term_char(PowerPCCPU *cpu, sPAPRMachineState *spapr,return H_SUCCESS ; } -void spapr_vty_create (VIOsPAPRBus *bus,CharDriverState *chardev) +void spapr_vty_create (VIOsPAPRBus *bus,Chardev *chardev) {DeviceState *dev;
hw/char/virtio-console.c +1 -1
@@ -168,7 +168,7 @@ static void virtconsole_realize(DeviceState *dev, Error **errp)VirtIOSerialPort *port =VIRTIO_SERIAL_PORT (dev);VirtConsole *vcon =VIRTIO_CONSOLE (dev);VirtIOSerialPortClass *k =VIRTIO_SERIAL_PORT_GET_CLASS (dev); -CharDriverState *chr =qemu_chr_fe_get_driver (&vcon->chr); +Chardev *chr =qemu_chr_fe_get_driver (&vcon->chr);if (port->id ==0 && !k->is_console) { error_setg(errp, "Port number 0 on virtio-serial devices reserved "
hw/core/qdev-properties-system.c +2 -2
@@ -179,7 +179,7 @@ static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,Error *local_err =NULL ;Property *prop = opaque;CharBackend *be =qdev_get_prop_ptr (dev, prop); -CharDriverState *s; +Chardev *s;char *str;if (dev->realized) {
@@ -411,7 +411,7 @@ void qdev_prop_set_drive(DeviceState *dev, const char *name, }void qdev_prop_set_chr (DeviceState *dev,const char *name, -CharDriverState *value) +Chardev *value) {assert (!value || value->label); object_property_set_str(OBJECT(dev),
hw/display/milkymist-tmu2.c +1 -1
@@ -85,7 +85,7 @@ struct MilkymistTMU2State {SysBusDevice parent_obj;MemoryRegion regs_region; -CharDriverState *chr; +Chardev *chr;qemu_irq irq;uint32_t regs[R_MAX ];
hw/display/sm501.c +1 -1
@@ -1392,7 +1392,7 @@ static const GraphicHwOps sm501_ops = { };void sm501_init (MemoryRegion *address_space_mem,uint32_t base, -uint32_t local_mem_bytes,qemu_irq irq,CharDriverState *chr) +uint32_t local_mem_bytes,qemu_irq irq,Chardev *chr) {SM501State * s;DeviceState *dev;
hw/isa/isa-bus.c +1 -1
@@ -287,7 +287,7 @@ MemoryRegion *isa_address_space_io(ISADevice *dev)type_init (isabus_register_types) -static void parallel_init(ISABus *bus, int index, CharDriverState *chr) +static void parallel_init(ISABus *bus, int index, Chardev *chr) {DeviceState *dev;ISADevice *isadev;
hw/isa/pc87312.c +1 -1
@@ -268,7 +268,7 @@ static void pc87312_realize(DeviceState *dev, Error **errp)DeviceState *d;ISADevice *isa;ISABus *bus; -CharDriverState *chr; +Chardev *chr;DriveInfo *drive;char name[5 ];int i;
hw/lm32/lm32.h +2 -2
@@ -16,7 +16,7 @@ static inline DeviceState *lm32_pic_init(qemu_irq cpu_irq)return dev; } -static inline DeviceState *lm32_juart_init (CharDriverState *chr) +static inline DeviceState *lm32_juart_init (Chardev *chr) {DeviceState *dev;
@@ -29,7 +29,7 @@ static inline DeviceState *lm32_juart_init(CharDriverState *chr)static inline DeviceState *lm32_uart_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
hw/lm32/milkymist-hw.h +1 -1
@@ -6,7 +6,7 @@static inline DeviceState *milkymist_uart_create (hwaddr base,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;
hw/mips/mips_malta.c +2 -2
@@ -551,10 +551,10 @@ static void malta_fgpa_display_event(void *opaque, int event) }static MaltaFPGAState *malta_fpga_init (MemoryRegion *address_space, -hwaddr base,qemu_irq uart_irq,CharDriverState *uart_chr) +hwaddr base,qemu_irq uart_irq,Chardev *uart_chr) {MaltaFPGAState *s; -CharDriverState *chr; +Chardev *chr; s = (MaltaFPGAState *)g_malloc0 (sizeof (MaltaFPGAState));
hw/misc/ivshmem.c +1 -1
@@ -868,7 +868,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp) s->ivshmem_bar2 =host_memory_backend_get_memory (s->hostmem, &error_abort); }else { -CharDriverState *chr =qemu_chr_fe_get_driver (&s->server_chr); +Chardev *chr =qemu_chr_fe_get_driver (&s->server_chr);assert (chr); IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n",
hw/misc/milkymist-pfpu.c +1 -1
@@ -125,7 +125,7 @@ struct MilkymistPFPUState {SysBusDevice parent_obj;MemoryRegion regs_region; -CharDriverState *chr; +Chardev *chr;qemu_irq irq;uint32_t regs[R_MAX ];
hw/usb/ccid-card-passthru.c +1 -1
@@ -264,7 +264,7 @@ static void ccid_card_vscard_handle_message(PassthruState *card,static void ccid_card_vscard_drop_connection (PassthruState *card) { -CharDriverState *chr =qemu_chr_fe_get_driver (&card->cs); +Chardev *chr =qemu_chr_fe_get_driver (&card->cs);qemu_chr_fe_deinit (&card->cs);qemu_chr_delete (chr);
hw/usb/dev-serial.c +3 -3
@@ -483,7 +483,7 @@ static void usb_serial_realize(USBDevice *dev, Error **errp) {USBSerialState *s =USB_SERIAL_DEV (dev);Error *local_err =NULL ; -CharDriverState *chr =qemu_chr_fe_get_driver (&s->cs); +Chardev *chr =qemu_chr_fe_get_driver (&s->cs);usb_desc_create_serial (dev);usb_desc_init (dev);
@@ -512,7 +512,7 @@ static void usb_serial_realize(USBDevice *dev, Error **errp)static USBDevice *usb_serial_init (USBBus *bus,const char *filename) {USBDevice *dev; -CharDriverState *cdrv; +Chardev *cdrv;uint32_t vendorid =0 , productid =0 ;char label[32 ];static int index;
@@ -564,7 +564,7 @@ static USBDevice *usb_serial_init(USBBus *bus, const char *filename)static USBDevice *usb_braille_init (USBBus *bus,const char *unused) {USBDevice *dev; -CharDriverState *cdrv; +Chardev *cdrv; cdrv =qemu_chr_new ("braille" ,"braille" );if (!cdrv)
hw/usb/redirect.c +2 -2
@@ -284,7 +284,7 @@ static gboolean usbredir_write_unblocked(GIOChannel *chan, GIOCondition cond,static int usbredir_write (void *priv,uint8_t *data,int count) {USBRedirDevice *dev = priv; -CharDriverState *chr =qemu_chr_fe_get_driver (&dev->cs); +Chardev *chr =qemu_chr_fe_get_driver (&dev->cs);int r;if (!chr->be_open) {
@@ -1430,7 +1430,7 @@ static void usbredir_cleanup_device_queues(USBRedirDevice *dev)static void usbredir_handle_destroy (USBDevice *udev) {USBRedirDevice *dev =USB_REDIRECT (udev); -CharDriverState *chr =qemu_chr_fe_get_driver (&dev->cs); +Chardev *chr =qemu_chr_fe_get_driver (&dev->cs);qemu_chr_fe_deinit (&dev->cs);qemu_chr_delete (chr);
include/hw/arm/exynos4210.h +1 -1
@@ -131,7 +131,7 @@ void exynos4210_combiner_get_gpioin(Exynos4210Irq *irqs, DeviceState *dev,DeviceState *exynos4210_uart_create (hwaddr addr,int fifo_size,int channel, -CharDriverState *chr, +Chardev *chr,qemu_irq irq);#endif /* EXYNOS4210_H */
include/hw/arm/omap.h +3 -3
@@ -664,14 +664,14 @@ struct omap_uart_s;struct omap_uart_s *omap_uart_init (hwaddr base,qemu_irq irq,omap_clk fclk,omap_clk iclk,qemu_irq txdma,qemu_irq rxdma, -const char *label,CharDriverState *chr); +const char *label,Chardev *chr);struct omap_uart_s *omap2_uart_init (MemoryRegion *sysmem,struct omap_target_agent_s *ta,qemu_irq irq,omap_clk fclk,omap_clk iclk,qemu_irq txdma,qemu_irq rxdma, -const char *label,CharDriverState *chr); +const char *label,Chardev *chr);void omap_uart_reset (struct omap_uart_s *s); -void omap_uart_attach (struct omap_uart_s *s,CharDriverState *chr); +void omap_uart_attach (struct omap_uart_s *s,Chardev *chr);struct omap_mpuio_s ;qemu_irq *omap_mpuio_in_get (struct omap_mpuio_s *s);
include/hw/bt.h +2 -2
@@ -127,8 +127,8 @@ enum { csrhci_pin_wakeup, __csrhci_pins, }; -qemu_irq *csrhci_pins_get (CharDriverState *chr); -CharDriverState *uart_hci_init (void ); +qemu_irq *csrhci_pins_get (Chardev *chr); +Chardev *uart_hci_init (void );/* bt-l2cap.c */ struct bt_l2cap_device_s ;
include/hw/char/cadence_uart.h +1 -1
@@ -51,7 +51,7 @@ typedef struct {static inline DeviceState *cadence_uart_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/char/escc.h +1 -1
@@ -5,7 +5,7 @@#define TYPE_ESCC "escc"#define ESCC_SIZE 4MemoryRegion *escc_init (hwaddr base,qemu_irq irqA,qemu_irq irqB, -CharDriverState *chrA,CharDriverState *chrB, +Chardev *chrA,Chardev *chrB,int clock,int it_shift); void slavio_serial_ms_kbd_init(hwaddr base, qemu_irq irq,
include/hw/char/pl011.h +2 -2
@@ -17,7 +17,7 @@static inline DeviceState *pl011_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
@@ -34,7 +34,7 @@ static inline DeviceState *pl011_create(hwaddr addr,static inline DeviceState *pl011_luminary_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/char/serial.h +2 -2
@@ -88,11 +88,11 @@ void serial_set_frequency(SerialState *s, uint32_t frequency);/* legacy pre qom */ SerialState *serial_init (int base,qemu_irq irq,int baudbase, -CharDriverState *chr,MemoryRegion *system_io); +Chardev *chr,MemoryRegion *system_io);SerialState *serial_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq,int baudbase, -CharDriverState *chr,enum device_endian end); +Chardev *chr,enum device_endian end);/* serial-isa.c */ #define TYPE_ISA_SERIAL "isa-serial"
include/hw/char/xilinx_uartlite.h +1 -1
@@ -17,7 +17,7 @@static inline DeviceState *xilinx_uartlite_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/cris/etraxfs.h +1 -1
@@ -48,7 +48,7 @@ etraxfs_eth_init(NICInfo *nd, hwaddr base, int phyaddr,static inline DeviceState *etraxfs_ser_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/devices.h +1 -1
@@ -65,6 +65,6 @@ qemu_irq tc6393xb_l3v_get(TC6393xbState *s);/* sm501.c */ void sm501_init (struct MemoryRegion *address_space_mem,uint32_t base,uint32_t local_mem_bytes,qemu_irq irq, -CharDriverState *chr); +Chardev *chr);#endif
include/hw/i386/pc.h +1 -1
@@ -181,7 +181,7 @@ void parallel_hds_isa_init(ISABus *bus, int n);bool parallel_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq, -CharDriverState *chr); +Chardev *chr);/* i8259.c */
include/hw/m68k/mcf.h +2 -2
@@ -11,10 +11,10 @@ uint64_t mcf_uart_read(void *opaque, hwaddr addr, unsigned size);void mcf_uart_write (void *opaque,hwaddr addr,uint64_t val,unsigned size); -void *mcf_uart_init (qemu_irq irq,CharDriverState *chr); +void *mcf_uart_init (qemu_irq irq,Chardev *chr);void mcf_uart_mm_init (struct MemoryRegion *sysmem,hwaddr base, -qemu_irq irq,CharDriverState *chr); +qemu_irq irq,Chardev *chr);/* mcf_intc.c */ qemu_irq *mcf_intc_init(struct MemoryRegion *sysmem,
include/hw/ppc/spapr_vio.h +1 -1
@@ -127,7 +127,7 @@ int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq);VIOsPAPRDevice *vty_lookup (sPAPRMachineState *spapr,target_ulong reg);void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,int len); -void spapr_vty_create (VIOsPAPRBus *bus,CharDriverState *chardev); +void spapr_vty_create (VIOsPAPRBus *bus,Chardev *chardev);void spapr_vlan_create (VIOsPAPRBus *bus,NICInfo *nd);void spapr_vscsi_create (VIOsPAPRBus *bus);
include/hw/qdev-properties.h +1 -1
@@ -184,7 +184,7 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);void qdev_prop_set_int32 (DeviceState *dev,const char *name,int32_t value);void qdev_prop_set_uint64 (DeviceState *dev,const char *name,uint64_t value);void qdev_prop_set_string (DeviceState *dev,const char *name,const char *value); -void qdev_prop_set_chr (DeviceState *dev,const char *name,CharDriverState *value); +void qdev_prop_set_chr (DeviceState *dev,const char *name,Chardev *value);void qdev_prop_set_netdev (DeviceState *dev,const char *name,NetClientState *value);void qdev_prop_set_drive (DeviceState *dev,const char *name,BlockBackend *value,Error **errp);
include/hw/sh4/sh.h +1 -1
@@ -42,7 +42,7 @@ void tmu012_init(struct MemoryRegion *sysmem, hwaddr base,#define SH_SERIAL_FEAT_SCIF (1 << 0) void sh_serial_init(MemoryRegion *sysmem, hwaddr base, int feat, - uint32_t freq, CharDriverState *chr, + uint32_t freq, Chardev *chr, qemu_irq eri_source, qemu_irq rxi_source, qemu_irq txi_source,
include/hw/sparc/grlib.h +1 -1
@@ -100,7 +100,7 @@ DeviceState *grlib_gptimer_create(hwaddr base,static inline DeviceState *grlib_apbuart_create (hwaddr base, -CharDriverState *serial, +Chardev *serial,qemu_irq irq) {DeviceState *dev;
include/hw/xen/xen.h +1 -1
@@ -37,7 +37,7 @@ int xen_is_pirq_msi(uint32_t msi_data);qemu_irq *xen_interrupt_controller_init (void ); -void xenstore_store_pv_console_info (int i,struct CharDriverState *chr); +void xenstore_store_pv_console_info (int i,struct Chardev *chr);void xen_hvm_init (PCMachineState *pcms,MemoryRegion **ram_memory);
include/monitor/monitor.h +1 -1
@@ -16,7 +16,7 @@ extern Monitor *cur_mon;bool monitor_cur_is_qmp (void ); -void monitor_init (CharDriverState *chr,int flags); +void monitor_init (Chardev *chr,int flags);void monitor_cleanup (void );int monitor_suspend (Monitor *mon);
include/qemu/typedefs.h +1 -1
@@ -17,7 +17,7 @@ typedef struct BlockBackendRootState BlockBackendRootState;typedef struct BlockDriverState BlockDriverState ;typedef struct BusClass BusClass ;typedef struct BusState BusState ; -typedef struct CharDriverState CharDriverState ; +typedef struct Chardev Chardev ;typedef struct CompatProperty CompatProperty ;typedef struct CPUAddressSpace CPUAddressSpace ;typedef struct CPUState CPUState ;
include/sysemu/char.h +47 -47
223 lines not on this page · raw message
include/sysemu/replay.h +2 -2
@@ -128,9 +128,9 @@ uint64_t blkreplay_next_id(void);/* Character device */ /*! Registers char driver to save it's events */ -void replay_register_char_driver (struct CharDriverState *chr); +void replay_register_char_driver (struct Chardev *chr);/*! Saves write to char device event to the log */ -void replay_chr_be_write (struct CharDriverState *s,uint8_t *buf,int len); +void replay_chr_be_write (struct Chardev *s,uint8_t *buf,int len);/*! Writes char write return value to the replay log. */ void replay_char_write_event_save (int res,int offset);/*! Reads char write return value from the replay log. */
include/sysemu/sysemu.h +2 -2
@@ -190,13 +190,13 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);#define MAX_SERIAL_PORTS 4 -extern CharDriverState *serial_hds[MAX_SERIAL_PORTS ]; +extern Chardev *serial_hds[MAX_SERIAL_PORTS ];/* parallel ports */ #define MAX_PARALLEL_PORTS 3 -extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS ]; +extern Chardev *parallel_hds[MAX_PARALLEL_PORTS ];void hmp_usb_add (Monitor *mon,const QDict *qdict);void hmp_usb_del (Monitor *mon,const QDict *qdict);
include/ui/gtk.h +1 -1
@@ -64,7 +64,7 @@ typedef struct VirtualVteConsole {GtkWidget *box;GtkWidget *scrollbar;GtkWidget *terminal; -CharDriverState *chr; +Chardev *chr; bool echo; } VirtualVteConsole;#endif
include/ui/qemu-spice.h +1 -1
@@ -51,7 +51,7 @@ int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,#if SPICE_SERVER_VERSION >=0x000c02 void qemu_spice_register_ports (void );#else -static inline CharDriverState *qemu_chr_open_spice_port (const char *name) +static inline Chardev *qemu_chr_open_spice_port (const char *name) {return NULL ; }#endif
monitor.c +2 -2
@@ -3195,7 +3195,7 @@ static void ringbuf_completion(ReadLineState *rs, const char *str)ChardevInfo *chr_info = list->value;if (!strncmp (chr_info->label, str, len)) { -CharDriverState *chr =qemu_chr_find (chr_info->label); +Chardev *chr =qemu_chr_find (chr_info->label);if (chr &&qemu_chr_is_ringbuf (chr)) {readline_add_completion (rs, chr_info->label); }
@@ -3985,7 +3985,7 @@ static void __attribute__((constructor)) monitor_lock_init(void)qemu_mutex_init (&monitor_lock); } -void monitor_init (CharDriverState *chr,int flags) +void monitor_init (Chardev *chr,int flags) {static int is_first_init =1 ;Monitor *mon;
net/colo-compare.c +2 -2
@@ -564,7 +564,7 @@ static void compare_sec_rs_finalize(SocketReadState *sec_rs)* Return 0 is success. * Return 1 is failed. */ -static int find_and_check_chardev (CharDriverState **chr, +static int find_and_check_chardev (Chardev **chr,char *chr_name,Error **errp) {
@@ -611,7 +611,7 @@ static void check_old_packet_regular(void *opaque)static void colo_compare_complete (UserCreatable *uc,Error **errp) {CompareState *s =COLO_COMPARE (uc); -CharDriverState *chr; +Chardev *chr;char thread_name[64 ];static int compare_id;
net/filter-mirror.c +2 -2
@@ -191,7 +191,7 @@ static void filter_redirector_cleanup(NetFilterState *nf)static void filter_mirror_setup (NetFilterState *nf,Error **errp) {MirrorState *s =FILTER_MIRROR (nf); -CharDriverState *chr; +Chardev *chr;if (!s->outdev) { error_setg(errp, "filter mirror needs 'outdev' "
@@ -220,7 +220,7 @@ static void redirector_rs_finalize(SocketReadState *rs)static void filter_redirector_setup (NetFilterState *nf,Error **errp) {MirrorState *s =FILTER_REDIRECTOR (nf); -CharDriverState *chr; +Chardev *chr;if (!s->indev && !s->outdev) { error_setg(errp, "filter redirector needs 'indev' or "
net/slirp.c +1 -1
@@ -748,7 +748,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, } }else {Error *err =NULL ; -CharDriverState *chr =qemu_chr_new (buf, p); +Chardev *chr =qemu_chr_new (buf, p);if (!chr) {error_report ("could not open guest forwarding device '%s'" , buf);
net/vhost-user.c +5 -5
@@ -195,7 +195,7 @@ static void net_vhost_user_event(void *opaque, int event)const char *name = opaque;NetClientState *ncs[MAX_QUEUE_NUM ];VhostUserState *s; -CharDriverState *chr; +Chardev *chr;Error *err =NULL ;int queues;
@@ -232,7 +232,7 @@ static void net_vhost_user_event(void *opaque, int event) }static int net_vhost_user_init (NetClientState *peer,const char *device, -const char *name,CharDriverState *chr, +const char *name,Chardev *chr,int queues) {Error *err =NULL ;
@@ -274,10 +274,10 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,return 0 ; } -static CharDriverState *net_vhost_claim_chardev ( +static Chardev *net_vhost_claim_chardev (const NetdevVhostUserOptions *opts,Error **errp) { -CharDriverState *chr =qemu_chr_find (opts->chardev); +Chardev *chr =qemu_chr_find (opts->chardev);if (chr ==NULL ) {error_setg (errp,"chardev \"%s\" not found" , opts->chardev);
@@ -324,7 +324,7 @@ int net_init_vhost_user(const Netdev *netdev, const char *name, {int queues;const NetdevVhostUserOptions *vhost_user_opts; -CharDriverState *chr; +Chardev *chr;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_USER ); vhost_user_opts = &netdev->u.vhost_user;
qemu-char.c +420 -419
1,715 lines not on this page · raw message
spice-qemu-char.c +40 -40
80 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.3.1
Part of the diff is not shown here. View the raw message.
[Qemu-devel] [PULL 40/41] chardev: qom-ify
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Turn Chardev into Object.
qemu_chr_alloc() is replaced by the qemu_chardev_new() constructor. It will call qemu_char_open() to open/intialize the chardev with the ChardevCommon *backend settings.
The CharDriver::create() callback is turned into a ChardevClass::open() which is called from the newly introduced qemu_chardev_open().
"chardev-gdb" and "chardev-hci" are internal chardev and aren't creatable directly with -chardev. Use a new internal flag to disable them. We may want to use TYPE_USER_CREATABLE interface instead, or perhaps allow -chardev usage.
Although in general we keep typename and macros private, unless the type is being used by some other file, in this patch, all types and common helper macros for qemu-char.c are in char.h. This is to help transition now (some types must be declared early, while some aren't shared) and when splitting in several units. This is to be improved later.
--- backends/baum.c | 66 +-- backends/msmouse.c | 57 ++- backends/testdev.c | 34 +- gdbstub.c | 39 +- hw/bt/hci-csr.c | 55 +- include/sysemu/char.h | 107 ++-- include/ui/console.h | 2 + monitor.c | 2 +- qemu-char.c | 1327 ++++++++++++++++++++++++++----------------------- spice-qemu-char.c | 142 +++--- ui/console.c | 62 ++- ui/gtk.c | 51 +- vl.c | 2 + 13 files changed, 1073 insertions(+), 873 deletions(-)
backends/baum.c +33 -33
@@ -100,6 +100,9 @@ typedef struct {QEMUTimer *cellCount_timer; } BaumChardev; +#define TYPE_CHARDEV_BRAILLE "chardev-braille" +#define BAUM_CHARDEV (obj) OBJECT_CHECK(BaumChardev, (obj), TYPE_CHARDEV_BRAILLE) +/* Let's assume NABCC by default */ enum way {DOTS2ASCII ,
@@ -255,7 +258,7 @@ static int baum_deferred_init(BaumChardev *baum)/* The serial port can receive more of our data */ static void baum_chr_accept_input (struct Chardev *chr) { -BaumChardev *baum = (BaumChardev *)chr; +BaumChardev *baum =BAUM_CHARDEV (chr);int room, first;if (!baum->out_buf_used)
@@ -281,7 +284,7 @@ static void baum_chr_accept_input(struct Chardev *chr)/* We want to send a packet */ static void baum_write_packet (BaumChardev *baum,const uint8_t *buf,int len) { -Chardev *chr = (Chardev *)baum; +Chardev *chr =CHARDEV (baum);uint8_t io_buf[1 +2 * len], *cur = io_buf;int room; *cur++ =ESC ;
@@ -322,7 +325,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)/* Called when the other end seems to have a wrong idea of our display size */ static void baum_cellCount_timer_cb (void *opaque) { -BaumChardev *baum = opaque; +BaumChardev *baum =BAUM_CHARDEV (opaque);uint8_t cell_count[] = { BAUM_RSP_CellCount, baum->x * baum->y };DPRINTF ("Timeout waiting for DisplayData, sending cell count\n" );baum_write_packet (baum, cell_count,sizeof (cell_count));
@@ -472,7 +475,7 @@ static int baum_eat_packet(BaumChardev *baum, const uint8_t *buf, int len)/* The other end is writing some data. Store it and try to interpret */ static int baum_chr_write (Chardev *chr,const uint8_t *buf,int len) { -BaumChardev *baum = (BaumChardev *)chr; +BaumChardev *baum =BAUM_CHARDEV (chr);int tocopy, cur, eaten, orig_len = len;if (!len)
@@ -529,7 +532,7 @@ static void baum_send_key2(BaumChardev *baum, uint8_t type, uint8_t value,/* We got some data on the BrlAPI socket */ static void baum_chr_read (void *opaque) { -BaumChardev *baum = opaque; +BaumChardev *baum =BAUM_CHARDEV (opaque);brlapi_keyCode_t code;int ret;if (!baum->brlapi)
@@ -613,9 +616,9 @@ static void baum_chr_read(void *opaque) } } -static void baum_chr_free (struct Chardev *chr) +static void baum_chr_free (Chardev *chr) { -BaumChardev *baum = (BaumChardev *)chr; +BaumChardev *baum =BAUM_CHARDEV (chr);timer_free (baum->cellCount_timer);if (baum->brlapi) {
@@ -624,24 +627,14 @@ static void baum_chr_free(struct Chardev *chr) } } -static Chardev *baum_chr_init (const CharDriver *driver, -const char *id, -ChardevBackend *backend, -ChardevReturn *ret, -bool *be_opened, -Error **errp) +static void baum_chr_open (Chardev *chr, +ChardevBackend *backend, +bool *be_opened, +Error **errp) { -ChardevCommon *common = backend->u.braille.data; -BaumChardev *baum; -Chardev *chr; +BaumChardev *baum =BAUM_CHARDEV (chr);brlapi_handle_t *handle; - chr =qemu_chr_alloc (driver, common, errp); -if (!chr) { -return NULL ; - } - baum = (BaumChardev *)chr; - handle =g_malloc0 (brlapi_getHandleSize ()); baum->brlapi = handle;
@@ -649,34 +642,41 @@ static Chardev *baum_chr_init(const CharDriver *driver,if (baum->brlapi_fd ==-1 ) {error_setg (errp,"brlapi__openConnection: %s" ,brlapi_strerror (brlapi_error_location ())); - goto fail_handle; +g_free (handle); +return ; } baum->deferred_init =0 ; baum->cellCount_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , baum_cellCount_timer_cb, baum);qemu_set_fd_handler (baum->brlapi_fd, baum_chr_read,NULL , baum); +} -return chr; +static void char_braille_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); -fail_handle: -g_free (handle); -g_free (chr); -return NULL ; + cc->open = baum_chr_open; + cc->chr_write = baum_chr_write; + cc->chr_accept_input = baum_chr_accept_input; + cc->chr_free = baum_chr_free; } +static const TypeInfo char_braille_type_info = { + .name =TYPE_CHARDEV_BRAILLE , + .parent =TYPE_CHARDEV , + .instance_size =sizeof (BaumChardev), + .class_init = char_braille_class_init, +}; +static void register_types (void ) {static const CharDriver driver = { - .instance_size =sizeof (BaumChardev), .kind =CHARDEV_BACKEND_KIND_BRAILLE , - .create = baum_chr_init, - .chr_write = baum_chr_write, - .chr_accept_input = baum_chr_accept_input, - .chr_free = baum_chr_free, };register_char_driver (&driver); +type_register_static (&char_braille_type_info); }type_init (register_types);
backends/msmouse.c +31 -26
104 lines not on this page · raw message
backends/testdev.c +18 -16
@@ -36,6 +36,10 @@ typedef struct {int in_buf_used; } TestdevChardev; +#define TYPE_CHARDEV_TESTDEV "chardev-testdev" +#define TESTDEV_CHARDEV (obj) \ + OBJECT_CHECK(TestdevChardev, (obj), TYPE_CHARDEV_TESTDEV) +/* Try to interpret a whole incoming packet */ static int testdev_eat_packet (TestdevChardev *testdev) {
@@ -78,9 +82,9 @@ static int testdev_eat_packet(TestdevChardev *testdev) }/* The other end is writing some data. Store it and try to interpret */ -static int testdev_write (Chardev *chr,const uint8_t *buf,int len) +static int testdev_chr_write (Chardev *chr,const uint8_t *buf,int len) { -TestdevChardev *testdev = (TestdevChardev *)chr; +TestdevChardev *testdev =TESTDEV_CHARDEV (chr);int tocopy, eaten, orig_len = len;while (len) {
@@ -103,30 +107,28 @@ static int testdev_write(Chardev *chr, const uint8_t *buf, int len)return orig_len; } -static Chardev *chr_testdev_init (const CharDriver *driver, -const char *id, -ChardevBackend *backend, -ChardevReturn *ret, -bool *be_opened, -Error **errp) +static void char_testdev_class_init (ObjectClass *oc,void *data) { -TestdevChardev *testdev =g_new0 (TestdevChardev,1 );; -Chardev *chr = (Chardev *)testdev; - - chr->driver = driver; +ChardevClass *cc =CHARDEV_CLASS (oc); -return chr; + cc->chr_write = testdev_chr_write; } +static const TypeInfo char_testdev_type_info = { + .name =TYPE_CHARDEV_TESTDEV , + .parent =TYPE_CHARDEV , + .instance_size =sizeof (TestdevChardev), + .class_init = char_testdev_class_init, +}; +static void register_types (void ) {static const CharDriver driver = { - .instance_size =sizeof (TestdevChardev), .kind =CHARDEV_BACKEND_KIND_TESTDEV , - .create = chr_testdev_init, - .chr_write = testdev_write, }; +register_char_driver (&driver); +type_register_static (&char_testdev_type_info); }type_init (register_types);
gdbstub.c +32 -7
@@ -1724,18 +1724,35 @@ static void gdb_sigterm_handler(int signal) }#endif +static void gdb_monitor_open (Chardev *chr,ChardevBackend *backend, +bool *be_opened,Error **errp) +{ + *be_opened = false; +} + +static void char_gdb_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->internal = true; + cc->open = gdb_monitor_open; + cc->chr_write = gdb_monitor_write; +} + +#define TYPE_CHARDEV_GDB "chardev-gdb" + +static const TypeInfo char_gdb_type_info = { + .name =TYPE_CHARDEV_GDB , + .parent =TYPE_CHARDEV , + .class_init = char_gdb_class_init, +}; +int gdbserver_start (const char *device) {GDBState *s;char gdbstub_device_name[128 ];Chardev *chr =NULL ;Chardev *mon_chr; -ChardevCommon common = {0 }; -static const CharDriver driver = { - .instance_size =sizeof (Chardev), - .kind =-1 , - .chr_write = gdb_monitor_write, - };if (!device)return -1 ;
@@ -1768,7 +1785,8 @@ int gdbserver_start(const char *device)qemu_add_vm_change_state_handler (gdb_vm_state_change,NULL );/* Initialize a monitor terminal for gdb */ - mon_chr =qemu_chr_alloc (&driver, &common, &error_abort); + mon_chr =qemu_chardev_new (NULL ,TYPE_CHARDEV_GDB , +NULL , &error_abort);monitor_init (mon_chr,0 ); }else {if (qemu_chr_fe_get_driver (&s->chr)) {
@@ -1791,4 +1809,11 @@ int gdbserver_start(const char *device) return 0; } + +static void register_types (void ) +{ +type_register_static (&char_gdb_type_info); +} + +type_init (register_types);#endif
hw/bt/hci-csr.c +38 -17
73 lines not on this page · raw message
include/sysemu/char.h +58 -49
143 lines not on this page · raw message
include/ui/console.h +2 -0
@@ -383,6 +383,8 @@ void graphic_hw_invalidate(QemuConsole *con);void graphic_hw_text_update (QemuConsole *con,console_ch_t *chardata);void graphic_hw_gl_block (QemuConsole *con,bool block); +void qemu_console_early_init (void ); +QemuConsole *qemu_console_lookup_by_index (unsigned int index);QemuConsole *qemu_console_lookup_by_device (DeviceState *dev,uint32_t head); QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
monitor.c +1 -1
@@ -3196,7 +3196,7 @@ static void ringbuf_completion(ReadLineState *rs, const char *str)if (!strncmp (chr_info->label, str, len)) {Chardev *chr =qemu_chr_find (chr_info->label); -if (chr &&qemu_chr_is_ringbuf (chr)) { +if (chr &&CHARDEV_IS_RINGBUF (chr)) {readline_add_completion (rs, chr_info->label); } }
qemu-char.c +712 -615
2,399 lines not on this page · raw message
spice-qemu-char.c +81 -61
142 lines not on this page · raw message
ui/console.c +37 -25
62 lines not on this page · raw message
ui/gtk.c +28 -23
51 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.3.1
Part of the diff is not shown here. View the raw message.
Quoted 4 lines · Paolo Bonzini
The following changes since commit
3879284d6517dc22529395bdb259f4183b589127:Merge remote-tracking branch 'remotes/berrange/tags/pull-qio-2017-01-23-2' into staging (2017-01-23 15:59:09 +0000)
Quoted 9 lines
are available in the git repository at:
git://github.com/bonzini/qemu.gittags/for-upstreamfor you to fetch changes up to
0a24326232f7c7f8c5ab9080784312d05d496e47:memory: don't sign-extend 32-bit writes (2017-01-26 15:29:49 +0100)
Conflict in target/i386/kvm.c which I didn't quite feel confident of resolving, though I suspect it's mostly trivial. Can you rebase, please?
thanks
-- PMM