Re: [PATCH 1/4] conf: add loader type 'none'

2023-04-11 Thread Gerd Hoffmann
  Hi,

> The second approach is the one described in the Ubuntu wiki[3], and
> also requires passing two files to QEMU, except this time they come
> from the opensbi and u-boot-qemu packages respectively. The usage
> looks like
> 
>   -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf
>   -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf
> 
> I think in this case the first file is a minimal build of OpenSBI
> that likely just initializes enough hardware before handing control
> to an arbitrary payload - in this case, u-boot.

Yes.  These days opensbi seems to be loaded by default, so the first
line is not needed.  In fact I'm running a guest here, on fedora 37 +
virt-preview with just this ...

  
hvm

/home/kraxel/projects/u-boot/build-qemu-riscv64-smode/u-boot.bin

  

... and it works fine.

There is also this variant ...

  


  

... to boot edk2 firmware.  Note this is a single image carrying both
code and vars.  Also note 'index=1', which I think is needed because the
(default) opensbi is loaded to the pflash device with 'index=0'.

This doesn't boot the distro due to grub2 not having full riscv64 efi
support (yet).

take care,
  Gerd



Re: [PATCH] hw/misc/sga: Remove the deprecated "sga" device

2023-02-10 Thread Gerd Hoffmann
On Thu, Feb 09, 2023 at 05:15:40PM +0100, Thomas Huth wrote:
> It's been deprecated since QEMU v6.2, so it should be OK to
> finally remove this now.
> 
> Signed-off-by: Thomas Huth 

Acked-by: Gerd Hoffmann 



[PATCH v2] docs: add firmware feature flags

2022-09-30 Thread Gerd Hoffmann
Add new firmware feature flags for the recently added confidential
computing operating modes by amd and intel.

While being at it also fix the path to the amd sev documentation.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Kashyap Chamarthy 
---
 docs/interop/firmware.json | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/docs/interop/firmware.json b/docs/interop/firmware.json
index 4e049b1c7ca0..56814f02b3c0 100644
--- a/docs/interop/firmware.json
+++ b/docs/interop/firmware.json
@@ -113,13 +113,22 @@
 #   Virtualization, as specified in the AMD64 Architecture
 #   Programmer's Manual. QEMU command line options related to
 #   this feature are documented in
-#   "docs/amd-memory-encryption.txt".
+#   "docs/system/i386/amd-memory-encryption.rst".
 #
 # @amd-sev-es: The firmware supports running under AMD Secure Encrypted
 #  Virtualization - Encrypted State, as specified in the AMD64
 #  Architecture Programmer's Manual. QEMU command line options
 #  related to this feature are documented in
-#  "docs/amd-memory-encryption.txt".
+#  "docs/system/i386/amd-memory-encryption.rst".
+#
+# @amd-sev-snp: The firmware supports running under AMD Secure Encrypted
+#   Virtualization - Secure Nested Paging, as specified in the
+#   AMD64 Architecture Programmer's Manual. QEMU command line
+#   options related to this feature are documented in
+#   "docs/system/i386/amd-memory-encryption.rst".
+#
+# @intel-tdx: The firmware supports running under Intel Trust Domain
+# Extensions (TDX).
 #
 # @enrolled-keys: The variable store (NVRAM) template associated with
 # the firmware binary has the UEFI Secure Boot
@@ -185,9 +194,11 @@
 # Since: 3.0
 ##
 { 'enum' : 'FirmwareFeature',
-  'data' : [ 'acpi-s3', 'acpi-s4', 'amd-sev', 'amd-sev-es', 'enrolled-keys',
- 'requires-smm', 'secure-boot', 'verbose-dynamic',
- 'verbose-static' ] }
+  'data' : [ 'acpi-s3', 'acpi-s4',
+ 'amd-sev', 'amd-sev-es', 'amd-sev-snp',
+ 'intel-tdx',
+ 'enrolled-keys', 'requires-smm', 'secure-boot',
+ 'verbose-dynamic', 'verbose-static' ] }
 
 ##
 # @FirmwareFlashFile:
-- 
2.37.3



[PATCH] docs: add firmware feature flags

2022-09-30 Thread Gerd Hoffmann
Add new firmware feature flags for the recently added confidential
computing operating modes by amd and intel.

Signed-off-by: Gerd Hoffmann 
---
 docs/interop/firmware.json | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/docs/interop/firmware.json b/docs/interop/firmware.json
index 4e049b1c7ca0..657082b78b83 100644
--- a/docs/interop/firmware.json
+++ b/docs/interop/firmware.json
@@ -121,6 +121,15 @@
 #  related to this feature are documented in
 #  "docs/amd-memory-encryption.txt".
 #
+# @amd-sev-snp: The firmware supports running under AMD Secure Encrypted
+#   Virtualization - Secure Nested Paging, as specified in the
+#   AMD64 Architecture Programmer's Manual. QEMU command line
+#   options related to this feature are documented in
+#   "docs/amd-memory-encryption.txt".
+#
+# @intel-tdx: The firmware supports running under Intel Trust Domain
+# Extensions (TDX).
+#
 # @enrolled-keys: The variable store (NVRAM) template associated with
 # the firmware binary has the UEFI Secure Boot
 # operational mode turned on, with certificates
@@ -185,9 +194,11 @@
 # Since: 3.0
 ##
 { 'enum' : 'FirmwareFeature',
-  'data' : [ 'acpi-s3', 'acpi-s4', 'amd-sev', 'amd-sev-es', 'enrolled-keys',
- 'requires-smm', 'secure-boot', 'verbose-dynamic',
- 'verbose-static' ] }
+  'data' : [ 'acpi-s3', 'acpi-s4',
+ 'amd-sev', 'amd-sev-es', 'amd-sev-snp',
+ 'intel-tdx',
+ 'enrolled-keys', 'requires-smm', 'secure-boot',
+ 'verbose-dynamic', 'verbose-static' ] }
 
 ##
 # @FirmwareFlashFile:
-- 
2.37.3



Re: [PATCH] RFC: char: deprecate usage of bidirectional pipe

2022-08-16 Thread Gerd Hoffmann
On Tue, Jul 26, 2022 at 09:44:25AM +0100, Daniel P. Berrangé wrote:
> On Tue, Jul 26, 2022 at 12:32:32PM +0400, marcandre.lur...@redhat.com wrote:
> > From: Marc-André Lureau 
> > 
> > As Ed Swierk explained back in 2006:
> > https://lists.nongnu.org/archive/html/qemu-devel/2006-12/msg00160.html
> > 
> > "When qemu writes into the pipe, it immediately reads back what it just
> > wrote and treats it as a monitor command, endlessly breathing its own
> > exhaust."
> > 
> > This is similarly confusing when using the chardev with a serial device,
> > as reported in https://bugzilla.redhat.com/show_bug.cgi?id=2106975.
> > 
> > It seems we have kept the support for bidirectional pipes for historical
> > reasons and odd systems, however it's not documented in qemu -chardev
> > options. I suggest to stop supporting it, for portability reasons.
> 
> Hmm, I always assumed that in this scenario the pipe was operating
> in output-only mode. Obviously not the case with the code as it
> exists, but perhaps this would be useful ?  eg its good as a serial
> console logging mechanism at least.

Well, using ${file}.in and ${file}.out has the advantage that it works
fine with all qemu versions.  So adding a warning suggesting to use that
makes sense to me, especially as 7.1 fix.

When looking at longer-term improvements it is probably better to add
support for explicit in/out pipe names, i.e. input= and output=
parameters as suggested later in the thread.  Avoids needing to know
qemu internals (pipe naming convention) and allows to make the input
pipe optional for the logging use case.  That probably is something we
don't want rush into 7.1 though ...

take care,
  Gerd



Re: [libvirt PATCH 00/28] Improve firmware autoselection

2022-06-27 Thread Gerd Hoffmann
On Thu, Jun 23, 2022 at 06:14:12PM +0200, Andrea Bolognani wrote:
> The main motivation behind this series was making it as simple as
> possible ("one click") to enable Secure Boot for a VM.

Heads up, and sort-of follow-up to the recent secure boot and smm (x86)
and tz (arm) discussion.

We'll most likely get a new secure boot variant soon.  This will not
require smm, but it will also not support persistent variables.  The
underlying idea is to simply re-initialize the variable store from
known-good ROM on each boot to compensate for the varstore not being
protected against the guest OS tampering with it.

Which of course implies some drawbacks:  The guest can't add keys (via
mokutil) for example, and turning off secure boot in firmware setup
wouldn't work either.  There are enough use cases (like just booting
cloud images in secure boot mode) where this doesn't matter, so I
consider this useful nevertheless, but maybe a separate feature flag
like 'stateless-secure-boot' makes sense for that.

Not sure yet how to package that up, best is probably as stateless image
because that'll reduce the chances of getting it wrong, i.e. something
like this:

{
"description": "OVMF with secure boot, no persistent vars",
"interface-types": [
"uefi"
],
"mapping": {
"device": "flash",
"mode": "stateless",
"executable": {
"filename": "/usr/share/edk2/ovmf/OVMF.secboot.fd",
"format": "raw"
}
},
"targets": [
{
"architecture": "x86_64",
"machines": [
"pc-i440fx-*"
"pc-q35-*"
]
}
],
"features": [
"secure-boot",
"enrolled-keys",
]
}

The idea idea should work for aarch64 too and remove the trustzone support
requirement.

take care,
  Gerd



Re: Some questions regarding firmware handling in the qemu driver

2022-06-14 Thread Gerd Hoffmann
  Hi,
 
> libvirt requires the firmware to support SMM to enable secure boot. But is
> SMM a strict requirement for secure boot? IIUC, lack of SMM makes the
> securely booted stack less secure since it is easier to tamper with it, but
> it does not prevent securely booting the components.

Well, 'less secure' is an *ahem* interesting way to frame it.  It's not
secure at all.  The guest OS can go ahead modify uefi variables in flash
directly, and the firmware can't stop it.

It's possible to use a build without SMM support for niche use cases,
for example for test setups verifying the secure boot certificate
checking, where broken security isn't much of a problem.

That actually was useful before x86 got SMM support, now there is little
reason to do that.

take care,
  Gerd



Re: Some questions regarding firmware handling in the qemu driver

2022-06-14 Thread Gerd Hoffmann
  Hi,

> I think we need an ARM expert to explain the rules about SecureBoot
> on aarch64. Given SMM doesn't exist outside x86, it may be fine to
> just enable secureboot unconditionally on aarch64 and have it be
> genuinely secure. I simply don't know enough in this respect.

Unlikely.  The firmware needs some way to store state (i.e. uefi
variables) somewhere where the guest OS can't tamper with it.

On x86 SMM mode provides that.  Flash can be configured to be writable
in SMM mode only, so the guest OS can't change things directly but has
to route all update requests through the firmware.

The arm architecture has a concept called TrustZone which can as far I
know can provide simliar guarantees.  Checking upstream edk2 git log
finds me this... 

  commit 6b46d77243e02d23ce922803998e01277fe9f399
  Author: Supreeth Venkatesh 
  Date:   Fri Jul 13 23:05:27 2018 +0800

StandaloneMmPkg/Core: Implementation of Standalone MM Core Module.

Management Mode (MM) is a generic term used to describe a secure
execution environment provided by the CPU and related silicon that is
entered when the CPU detects a MMI. For x86 systems, this can be
implemented with System Management Mode (SMM). For ARM systems, this can
be implemented with TrustZone (TZ).
[ ... snip ... ]

... but not much beyond that.  So I don't think edk2 has support
implemented, and I'm also not sure where we stand with qemu.

I suspect it'll be quite a bit of work to get everything going.

take care,
  Gerd



Re: Some questions regarding firmware handling in the qemu driver

2022-06-14 Thread Gerd Hoffmann
  Hi,

> Having said that I find Fedora does still buld shim 15.4 for
> aarch64. We only exclude 32-bit, and I think RHEL does the
> same.  Whether anyone's tested SecureBoot on aarch64 in
> Fedora/RHEL though, I'm not so sure.

Well, at least the fedora shim builds are not signed with anything,
and grub doesn't look much better:

$ pesigcheck -v -i grubaa64.efi 
[ ... ]
Signature has impossible time constraint: 1639158862 <= 1373397163
Peer's Certificate has expired.
[ ... ]
$ date --date @1373397163
Tue Jul  9 21:12:43 CEST 2013
 

I think we can take that as clear indication that nobody ever tested
secure boot with fedora on aarch64 ;)

take care,
  Gerd



Re: [PATCH v2 2/3] ui: Switch "-display sdl" to use the QAPI parser

2022-05-19 Thread Gerd Hoffmann
  Hi,

> Hmm, ok ... but maybe I should call the new enum HotKeyMod instead of
> GrabMod to make it more obvious that it is something different?

Looks good to me.

take care,
  Gerd



Re: [PATCH v2 2/3] ui: Switch "-display sdl" to use the QAPI parser

2022-05-19 Thread Gerd Hoffmann
  Hi,

> Oh well, I just noticed that we already have a GrabToggleKeys enum in
> qapi/common.json ... I wonder whether I should try to use that instead? It
> seems to be used in a slightly different context, though, if I get that
> right ...?

qemu/ui/input-linux.c

Those switch the input routing between host and guest, and they act on
their own (i.e. by default both control keys without anything else).

For SDL it defines the modifiers to press in addition to the hotkeys
(i.e. ctrl + shift + 'G' for grab release, IIRC there a are more, 'F'
for fullscreen?).

So I don't think it makes sense to merge them.

take care,
  Gerd



Re: [PATCH v2] docs: expand firmware descriptor to allow flash without NVRAM

2022-02-01 Thread Gerd Hoffmann
On Mon, Jan 31, 2022 at 04:21:36PM +0100, Kashyap Chamarthy wrote:
> On Mon, Jan 31, 2022 at 02:36:46PM +, Daniel P. Berrangé wrote:
> > On Mon, Jan 31, 2022 at 03:00:33PM +0100, Kashyap Chamarthy wrote:
> > > On Mon, Jan 31, 2022 at 12:55:09PM +, Daniel P. Berrangé wrote:
> 
> [...]
> 
> > > I briefly wondered if in this "combined" mode whether the no. of
> > > duplicate copies can ever fill up the storage.  I doubt that, as the
> > > combined size of _VARS + _CODE is just about 2MB.  So it only starts
> > > mattering if you're running tens of thousands of guests.
> > 
> > When guest root / data disk sizes are measured in 100's of MB, or
> > GBs, I struggle to get worried about even a 16 MB OVMF  blob being
> > copied per guest.
> 
> Heh, fair enough.

Main advantage of the split is that it is much easier to update the
firmware code without smashing the guest vars, not so much the disk
space requirements.

take care,
  Gerd



Re: [libvirt PATCH 0/2] qemu: support the SeaBIOS/EDK2 debug console

2022-01-25 Thread Gerd Hoffmann
  Hi,

> > On balance I felt  was/is the winner. Essentially every
> > impl of  can be said to be a general purpose data
> > channel for passing arbitrary bytes. We choose to explicitly
> > distinguish  from  based on the intended use
> > case of the thing.
> 
> This interpretation directly contradicts our documentation,
> specifically
> 
>   https://libvirt.org/formatdomain.html#console
> 
> The console element is used to represent interactive serial
> consoles.

Yep.  Something where it make sense to run a getty on.
Which surely isn't the case for isa-debugcon ...

take care,
  Gerd



[PULL 07/10] ui/console: replace kbd_timer with chr_accept_input callback

2021-11-02 Thread Gerd Hoffmann
From: Volker Rümelin 

There's a ChardevClass chr_accept_input() callback function that
can replace the write retry timer.

Reviewed-by: Marc-André Lureau 
Signed-off-by: Volker Rümelin 
Message-Id: <20210916192239.18742-2-vr_q...@t-online.de>
Signed-off-by: Gerd Hoffmann 
---
 ui/console.c | 28 +---
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index d2433c0636d0..dda1e6861d6a 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -116,7 +116,6 @@ struct QemuConsole {
 Chardev *chr;
 /* fifo for key pressed */
 Fifo8 out_fifo;
-QEMUTimer *kbd_timer;
 CoQueue dump_queue;
 
 QTAILQ_ENTRY(QemuConsole) next;
@@ -1106,30 +1105,21 @@ static int vc_chr_write(Chardev *chr, const uint8_t 
*buf, int len)
 return len;
 }
 
-static void kbd_send_chars(void *opaque)
+static void kbd_send_chars(QemuConsole *s)
 {
-QemuConsole *s = opaque;
 uint32_t len, avail;
 
 len = qemu_chr_be_can_write(s->chr);
 avail = fifo8_num_used(>out_fifo);
-if (len > avail) {
-len = avail;
-}
-while (len > 0) {
+while (len > 0 && avail > 0) {
 const uint8_t *buf;
 uint32_t size;
 
-buf = fifo8_pop_buf(>out_fifo, len, );
+buf = fifo8_pop_buf(>out_fifo, MIN(len, avail), );
 qemu_chr_be_write(s->chr, (uint8_t *)buf, size);
-len -= size;
+len = qemu_chr_be_can_write(s->chr);
 avail -= size;
 }
-/* characters are pending: we send them a bit later (XXX:
-   horrible, should change char device API) */
-if (avail > 0) {
-timer_mod(s->kbd_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1);
-}
 }
 
 /* called when an ascii key is pressed */
@@ -2141,6 +2131,14 @@ int qemu_console_get_height(QemuConsole *con, int 
fallback)
 return con ? surface_height(con->surface) : fallback;
 }
 
+static void vc_chr_accept_input(Chardev *chr)
+{
+VCChardev *drv = VC_CHARDEV(chr);
+QemuConsole *s = drv->console;
+
+kbd_send_chars(s);
+}
+
 static void vc_chr_set_echo(Chardev *chr, bool echo)
 {
 VCChardev *drv = VC_CHARDEV(chr);
@@ -2189,7 +2187,6 @@ static void text_console_do_init(Chardev *chr, 
DisplayState *ds)
 int g_height = 24 * FONT_HEIGHT;
 
 fifo8_create(>out_fifo, 16);
-s->kbd_timer = timer_new_ms(QEMU_CLOCK_REALTIME, kbd_send_chars, s);
 s->ds = ds;
 
 s->y_displayed = 0;
@@ -2439,6 +2436,7 @@ static void char_vc_class_init(ObjectClass *oc, void 
*data)
 cc->parse = qemu_chr_parse_vc;
 cc->open = vc_chr_open;
 cc->chr_write = vc_chr_write;
+cc->chr_accept_input = vc_chr_accept_input;
 cc->chr_set_echo = vc_chr_set_echo;
 }
 
-- 
2.31.1



[PULL 05/10] ui/gtk: skip any extra draw of same guest scanout blob res

2021-11-02 Thread Gerd Hoffmann
From: Dongwon Kim 

Any extra draw call for the same blob resource representing guest scanout
before the previous drawing is not finished can break synchronous draw
sequence. To prevent this, drawing is now done only once for each draw
submission (when draw_submitted == true).

v2:
 - removed mutex
 - updated commit msg

Cc: Gerd Hoffmann 
Cc: Vivek Kasireddy 
Signed-off-by: Dongwon Kim 
Message-Id: <20210924225105.24930-1-dongwon@intel.com>
Signed-off-by: Gerd Hoffmann 
---
 include/ui/console.h|  1 +
 hw/display/virtio-gpu-udmabuf.c |  2 +-
 ui/gtk-egl.c| 40 ++-
 ui/gtk-gl-area.c| 49 -
 4 files changed, 59 insertions(+), 33 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 244664d727a4..b6bedc5f4152 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -171,6 +171,7 @@ typedef struct QemuDmaBuf {
 void  *sync;
 int   fence_fd;
 bool  allow_fences;
+bool  draw_submitted;
 } QemuDmaBuf;
 
 typedef struct DisplayState DisplayState;
diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabuf.c
index c6f7f587847f..60ea7f8f4972 100644
--- a/hw/display/virtio-gpu-udmabuf.c
+++ b/hw/display/virtio-gpu-udmabuf.c
@@ -186,7 +186,7 @@ static VGPUDMABuf
 dmabuf->buf.fourcc = qemu_pixman_to_drm_format(fb->format);
 dmabuf->buf.fd = res->dmabuf_fd;
 dmabuf->buf.allow_fences = true;
-
+dmabuf->buf.draw_submitted = false;
 dmabuf->scanout_id = scanout_id;
 QTAILQ_INSERT_HEAD(>dmabuf.bufs, dmabuf, next);
 
diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index 72ce5e1f8f41..e912b200755a 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -63,6 +63,9 @@ void gd_egl_init(VirtualConsole *vc)
 void gd_egl_draw(VirtualConsole *vc)
 {
 GdkWindow *window;
+#ifdef CONFIG_GBM
+QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
+#endif
 int ww, wh;
 
 if (!vc->gfx.gls) {
@@ -74,10 +77,31 @@ void gd_egl_draw(VirtualConsole *vc)
 wh = gdk_window_get_height(window);
 
 if (vc->gfx.scanout_mode) {
+#ifdef CONFIG_GBM
+if (dmabuf) {
+if (!dmabuf->draw_submitted) {
+return;
+} else {
+dmabuf->draw_submitted = false;
+}
+}
+#endif
 gd_egl_scanout_flush(>gfx.dcl, 0, 0, vc->gfx.w, vc->gfx.h);
 
 vc->gfx.scale_x = (double)ww / vc->gfx.w;
 vc->gfx.scale_y = (double)wh / vc->gfx.h;
+
+glFlush();
+#ifdef CONFIG_GBM
+if (dmabuf) {
+egl_dmabuf_create_fence(dmabuf);
+if (dmabuf->fence_fd > 0) {
+qemu_set_fd_handler(dmabuf->fence_fd, gd_hw_gl_flushed, NULL, 
vc);
+return;
+}
+graphic_hw_gl_block(vc->gfx.dcl.con, false);
+}
+#endif
 } else {
 if (!vc->gfx.ds) {
 return;
@@ -92,21 +116,10 @@ void gd_egl_draw(VirtualConsole *vc)
 
 vc->gfx.scale_x = (double)ww / surface_width(vc->gfx.ds);
 vc->gfx.scale_y = (double)wh / surface_height(vc->gfx.ds);
-}
-
-glFlush();
-#ifdef CONFIG_GBM
-if (vc->gfx.guest_fb.dmabuf) {
-QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
 
-egl_dmabuf_create_fence(dmabuf);
-if (dmabuf->fence_fd > 0) {
-qemu_set_fd_handler(dmabuf->fence_fd, gd_hw_gl_flushed, NULL, vc);
-return;
-}
-graphic_hw_gl_block(vc->gfx.dcl.con, false);
+glFlush();
 }
-#endif
+
 graphic_hw_gl_flushed(vc->gfx.dcl.con);
 }
 
@@ -317,6 +330,7 @@ void gd_egl_flush(DisplayChangeListener *dcl,
 
 if (vc->gfx.guest_fb.dmabuf) {
 graphic_hw_gl_block(vc->gfx.dcl.con, true);
+vc->gfx.guest_fb.dmabuf->draw_submitted = true;
 gtk_widget_queue_draw_area(area, x, y, w, h);
 return;
 }
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index afcb29f65823..461da7712f4f 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -38,6 +38,9 @@ static void gtk_gl_area_set_scanout_mode(VirtualConsole *vc, 
bool scanout)
 
 void gd_gl_area_draw(VirtualConsole *vc)
 {
+#ifdef CONFIG_GBM
+QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
+#endif
 int ww, wh, y1, y2;
 
 if (!vc->gfx.gls) {
@@ -53,6 +56,16 @@ void gd_gl_area_draw(VirtualConsole *vc)
 return;
 }
 
+#ifdef CONFIG_GBM
+if (dmabuf) {
+if (!dmabuf->draw_submitted) {
+return;
+} else {
+dmabuf->draw_submitted = false;
+}
+}
+#endif
+
 glBindFramebuffer(GL_READ_FRAMEBUFFER, vc->gfx.guest_fb.framebuffer);
 /* GtkGLArea sets GL_DRAW_FRAMEBUFFER for us */
 
@@ -62,6 +75,22 @@ void gd_gl_area_draw(VirtualConsole *vc)
 glBlitFramebuffer(0, y1, vc->gfx.w, 

[PULL 10/10] usb-storage: tag usb_msd_csw as packed struct

2021-11-02 Thread Gerd Hoffmann
Without this the struct has the wrong size: sizeof() evaluates
to 16 instead of 13.  In most cases the bug is hidden by the
fact that guests submits a buffer which is exactly 13 bytes
long, so the padding added by the compiler is simply ignored.

But sometimes guests submit a larger buffer and expect a short
transfer, which does not work properly with the wrong struct
size.

Cc: vintagepc...@protonmail.com
Signed-off-by: Gerd Hoffmann 
Fixes: a917d384ac0 ("SCSI TCQ support.")
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20210906045523.1259629-1-kra...@redhat.com>
---
 include/hw/usb/msd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/hw/usb/msd.h b/include/hw/usb/msd.h
index 7538c54569bf..54e9f38bda46 100644
--- a/include/hw/usb/msd.h
+++ b/include/hw/usb/msd.h
@@ -17,7 +17,7 @@ enum USBMSDMode {
 USB_MSDM_CSW /* Command Status.  */
 };
 
-struct usb_msd_csw {
+struct QEMU_PACKED usb_msd_csw {
 uint32_t sig;
 uint32_t tag;
 uint32_t residue;
-- 
2.31.1



[PULL 09/10] hw/misc: deprecate the 'sga' device

2021-11-02 Thread Gerd Hoffmann
From: Daniel P. Berrangé 

This is obsolete since SeaBIOS 1.11.0 introduced native support for
sending messages to the serial console. The new support can be
activated using -machine graphics=off on x86 targets.

Signed-off-by: Daniel P. Berrangé 
Reviewed-by: Gerd Hoffmann 
Message-Id: <20210909123219.862652-1-berra...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 hw/misc/sga.c |  2 ++
 docs/about/deprecated.rst | 10 ++
 2 files changed, 12 insertions(+)

diff --git a/hw/misc/sga.c b/hw/misc/sga.c
index 4dbe6d78f9e5..1d04672b013b 100644
--- a/hw/misc/sga.c
+++ b/hw/misc/sga.c
@@ -30,6 +30,7 @@
 #include "hw/loader.h"
 #include "qemu/module.h"
 #include "qom/object.h"
+#include "qemu/error-report.h"
 
 #define SGABIOS_FILENAME "sgabios.bin"
 
@@ -42,6 +43,7 @@ struct ISASGAState {
 
 static void sga_realizefn(DeviceState *dev, Error **errp)
 {
+warn_report("-device sga is deprecated, use -machine graphics=off");
 rom_add_vga(SGABIOS_FILENAME);
 }
 
diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst
index be19317470a1..25b7ec8d92d9 100644
--- a/docs/about/deprecated.rst
+++ b/docs/about/deprecated.rst
@@ -313,6 +313,16 @@ full SCSI support.  Use virtio-scsi instead when SCSI 
passthrough is required.
 Note this also applies to ``-device virtio-blk-pci,scsi=on|off``, which is an
 alias.
 
+``-device sga`` (since 6.2)
+^^^
+
+The ``sga`` device loads an option ROM for x86 targets which enables
+SeaBIOS to send messages to the serial console. SeaBIOS 1.11.0 onwards
+contains native support for this feature and thus use of the option
+ROM approach is obsolete. The native SeaBIOS support can be activated
+by using ``-machine graphics=off``.
+
+
 Block device options
 
 
-- 
2.31.1



[PULL 04/10] ui/gtk: Update the refresh rate for gl-area too

2021-11-02 Thread Gerd Hoffmann
From: Nikola Pavlica 

This is a bugfix that stretches all the way back to January 2020,
where I initially introduced this problem and potential solutions.

A quick recap of the issue: QEMU did not sync up with the monitors
refresh rate causing the VM to render frames that were NOT displayed
to the user. That "fix" allowed QEMU to obtain the screen refreshrate
information from the system using GDK API's and was for GTK only.

Well, I'm back with the same issue again. But this time on Wayland.

And I did NOT realize there was YET another screen refresh rate
function, this time for Wayland specifically. Thankfully the fix was
simple and without much hassle.

Thanks,
Nikola

PS: It seems that my patch has gone missing from the mailing list,
hence I'm sending it again. Sorry for any inconveniences.

Signed-off-by: Nikola Pavlica 
Message-Id: <20211024143110.704296-1-pavlica.nik...@gmail.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/gtk-gl-area.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index b23523748e7f..afcb29f65823 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -112,6 +112,9 @@ void gd_gl_area_refresh(DisplayChangeListener *dcl)
 {
 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
 
+vc->gfx.dcl.update_interval = gd_monitor_update_interval(
+vc->window ? vc->window : vc->gfx.drawing_area);
+
 if (!vc->gfx.gls) {
 if (!gtk_widget_get_realized(vc->gfx.drawing_area)) {
 return;
-- 
2.31.1



[PULL 08/10] ui/console: remove chardev frontend connected test

2021-11-02 Thread Gerd Hoffmann
From: Volker Rümelin 

The test if the chardev frontend is connected in
kbd_put_keysym_console() is redundant, because the call
to qemu_chr_be_can_write() in kbd_send_chars() tests
the connected condition again.

Remove the redundant test whether the chardev frontend
is connected.

Reviewed-by: Marc-André Lureau 
Signed-off-by: Volker Rümelin 
Message-Id: <20210916192239.18742-3-vr_q...@t-online.de>
Signed-off-by: Gerd Hoffmann 
---
 ui/console.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index dda1e6861d6a..29a3e3f0f51c 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -28,10 +28,11 @@
 #include "qapi/error.h"
 #include "qapi/qapi-commands-ui.h"
 #include "qemu/fifo8.h"
+#include "qemu/main-loop.h"
 #include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/timer.h"
-#include "chardev/char-fe.h"
+#include "chardev/char.h"
 #include "trace.h"
 #include "exec/memory.h"
 #include "io/channel-file.h"
@@ -1126,7 +1127,6 @@ static void kbd_send_chars(QemuConsole *s)
 void kbd_put_keysym_console(QemuConsole *s, int keysym)
 {
 uint8_t buf[16], *q;
-CharBackend *be;
 int c;
 uint32_t num_free;
 
@@ -1170,12 +1170,9 @@ void kbd_put_keysym_console(QemuConsole *s, int keysym)
 if (s->echo) {
 vc_chr_write(s->chr, buf, q - buf);
 }
-be = s->chr->be;
-if (be && be->chr_read) {
-num_free = fifo8_num_free(>out_fifo);
-fifo8_push_all(>out_fifo, buf, MIN(num_free, q - buf));
-kbd_send_chars(s);
-}
+num_free = fifo8_num_free(>out_fifo);
+fifo8_push_all(>out_fifo, buf, MIN(num_free, q - buf));
+kbd_send_chars(s);
 break;
 }
 }
-- 
2.31.1



[PULL 03/10] microvm: add device tree support.

2021-11-02 Thread Gerd Hoffmann
Allows edk2 detect virtio-mmio devices and pcie ecam.
See comment in hw/i386/microvm-dt.c for more details.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Sergio Lopez 
Message-Id: <20211014193617.2475578-1-kra...@redhat.com>
---
 hw/i386/microvm-dt.h   |   8 +
 include/hw/i386/microvm.h  |   4 +
 hw/i386/microvm-dt.c   | 341 +
 hw/i386/microvm.c  |   2 +
 .gitlab-ci.d/buildtest.yml |   1 -
 configs/targets/i386-softmmu.mak   |   1 +
 configs/targets/x86_64-softmmu.mak |   1 +
 hw/i386/meson.build|   2 +-
 8 files changed, 358 insertions(+), 2 deletions(-)
 create mode 100644 hw/i386/microvm-dt.h
 create mode 100644 hw/i386/microvm-dt.c

diff --git a/hw/i386/microvm-dt.h b/hw/i386/microvm-dt.h
new file mode 100644
index ..77c79cbdd9fb
--- /dev/null
+++ b/hw/i386/microvm-dt.h
@@ -0,0 +1,8 @@
+#ifndef HW_I386_MICROVM_DT_H
+#define HW_I386_MICROVM_DT_H
+
+#include "hw/i386/microvm.h"
+
+void dt_setup_microvm(MicrovmMachineState *mms);
+
+#endif
diff --git a/include/hw/i386/microvm.h b/include/hw/i386/microvm.h
index f25f8374413f..4d9c732d4b2b 100644
--- a/include/hw/i386/microvm.h
+++ b/include/hw/i386/microvm.h
@@ -104,6 +104,10 @@ struct MicrovmMachineState {
 Notifier machine_done;
 Notifier powerdown_req;
 struct GPEXConfig gpex;
+
+/* device tree */
+void *fdt;
+uint32_t ioapic_phandle[2];
 };
 
 #define TYPE_MICROVM_MACHINE   MACHINE_TYPE_NAME("microvm")
diff --git a/hw/i386/microvm-dt.c b/hw/i386/microvm-dt.c
new file mode 100644
index ..875ba9196394
--- /dev/null
+++ b/hw/i386/microvm-dt.c
@@ -0,0 +1,341 @@
+/*
+ * microvm device tree support
+ *
+ * This generates an device tree for microvm and exports it via fw_cfg
+ * as "etc/fdt" to the firmware (edk2 specifically).
+ *
+ * The use case is to allow edk2 find the pcie ecam and the virtio
+ * devices, without adding an ACPI parser, reusing the fdt parser
+ * which is needed anyway for the arm platform.
+ *
+ * Note 1: The device tree is incomplete. CPUs and memory is missing
+ * for example, those can be detected using other fw_cfg files.
+ * Also pci ecam irq routing is not there, edk2 doesn't use
+ * interrupts.
+ *
+ * Note 2: This is for firmware only. OSes should use the more
+ * complete ACPI tables for hardware discovery.
+ *
+ * --
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "qemu/osdep.h"
+#include "qemu/cutils.h"
+#include "sysemu/device_tree.h"
+#include "hw/char/serial.h"
+#include "hw/i386/fw_cfg.h"
+#include "hw/rtc/mc146818rtc.h"
+#include "hw/sysbus.h"
+#include "hw/virtio/virtio-mmio.h"
+#include "hw/usb/xhci.h"
+
+#include "microvm-dt.h"
+
+static bool debug;
+
+static void dt_add_microvm_irq(MicrovmMachineState *mms,
+   const char *nodename, uint32_t irq)
+{
+int index = 0;
+
+if (irq >= IO_APIC_SECONDARY_IRQBASE) {
+irq -= IO_APIC_SECONDARY_IRQBASE;
+index++;
+}
+
+qemu_fdt_setprop_cell(mms->fdt, nodename, "interrupt-parent",
+  mms->ioapic_phandle[index]);
+qemu_fdt_setprop_cells(mms->fdt, nodename, "interrupts", irq, 0);
+}
+
+static void dt_add_virtio(MicrovmMachineState *mms, VirtIOMMIOProxy *mmio)
+{
+SysBusDevice *dev = SYS_BUS_DEVICE(mmio);
+VirtioBusState *mmio_virtio_bus = >bus;
+BusState *mmio_bus = _virtio_bus->parent_obj;
+char *nodename;
+
+if (QTAILQ_EMPTY(_bus->children)) {
+return;
+}
+
+hwaddr base = dev->mmio[0].addr;
+hwaddr size = 512;
+unsigned index = (base - VIRTIO_MMIO_BASE) / size;
+uint32_t irq = mms->virtio_irq_base + index;
+
+nodename = g_strdup_printf("/virtio_mmio@%" PRIx64, base);
+qemu_fdt_add_subnode(mms->fdt, nodename);
+qemu_fdt_setprop_string(mms->fdt, nodename, "compatible", "virtio,mmio");
+qemu_fdt_setprop_sized_cells(mms->fdt, nodename, "reg", 2, base, 2, size);
+qemu_fdt_setprop(mms->fdt, nodename, "dma-coherent", NULL, 0);
+dt_add_microvm_irq(mms, nodename,

[PULL 01/10] MAINTAINERS: Add myself as a reviewer for SDL audio

2021-11-02 Thread Gerd Hoffmann
From: Thomas Huth 

I've got some experience with the SDL library, so I can help
reviewing patches here.

Signed-off-by: Thomas Huth 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20211030062106.46024-1-h...@tuxfamily.org>
Signed-off-by: Gerd Hoffmann 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 310a9512ea18..99618e6d9906 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2315,6 +2315,7 @@ F: audio/paaudio.c
 
 SDL Audio backend
 M: Gerd Hoffmann 
+R: Thomas Huth 
 S: Odd Fixes
 F: audio/sdlaudio.c
 
-- 
2.31.1



[PULL 06/10] ui/console: replace QEMUFIFO with Fifo8

2021-11-02 Thread Gerd Hoffmann
From: Volker Rümelin 

One of the two FIFO implementations QEMUFIFO and Fifo8 is
redundant. Replace QEMUFIFO with Fifo8.

Signed-off-by: Volker Rümelin 
Reviewed-by: Marc-André Lureau 
Message-Id: <20210916192239.18742-1-vr_q...@t-online.de>
Signed-off-by: Gerd Hoffmann 
---
 ui/console.c | 86 
 1 file changed, 20 insertions(+), 66 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index eabbbc951c5f..d2433c0636d0 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -27,6 +27,7 @@
 #include "hw/qdev-core.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-ui.h"
+#include "qemu/fifo8.h"
 #include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/timer.h"
@@ -62,57 +63,6 @@ enum TTYState {
 TTY_STATE_CSI,
 };
 
-typedef struct QEMUFIFO {
-uint8_t *buf;
-int buf_size;
-int count, wptr, rptr;
-} QEMUFIFO;
-
-static int qemu_fifo_write(QEMUFIFO *f, const uint8_t *buf, int len1)
-{
-int l, len;
-
-l = f->buf_size - f->count;
-if (len1 > l)
-len1 = l;
-len = len1;
-while (len > 0) {
-l = f->buf_size - f->wptr;
-if (l > len)
-l = len;
-memcpy(f->buf + f->wptr, buf, l);
-f->wptr += l;
-if (f->wptr >= f->buf_size)
-f->wptr = 0;
-buf += l;
-len -= l;
-}
-f->count += len1;
-return len1;
-}
-
-static int qemu_fifo_read(QEMUFIFO *f, uint8_t *buf, int len1)
-{
-int l, len;
-
-if (len1 > f->count)
-len1 = f->count;
-len = len1;
-while (len > 0) {
-l = f->buf_size - f->rptr;
-if (l > len)
-l = len;
-memcpy(buf, f->buf + f->rptr, l);
-f->rptr += l;
-if (f->rptr >= f->buf_size)
-f->rptr = 0;
-buf += l;
-len -= l;
-}
-f->count -= len1;
-return len1;
-}
-
 typedef enum {
 GRAPHIC_CONSOLE,
 TEXT_CONSOLE,
@@ -165,8 +115,7 @@ struct QemuConsole {
 
 Chardev *chr;
 /* fifo for key pressed */
-QEMUFIFO out_fifo;
-uint8_t out_fifo_buf[16];
+Fifo8 out_fifo;
 QEMUTimer *kbd_timer;
 CoQueue dump_queue;
 
@@ -1160,21 +1109,25 @@ static int vc_chr_write(Chardev *chr, const uint8_t 
*buf, int len)
 static void kbd_send_chars(void *opaque)
 {
 QemuConsole *s = opaque;
-int len;
-uint8_t buf[16];
+uint32_t len, avail;
 
 len = qemu_chr_be_can_write(s->chr);
-if (len > s->out_fifo.count)
-len = s->out_fifo.count;
-if (len > 0) {
-if (len > sizeof(buf))
-len = sizeof(buf);
-qemu_fifo_read(>out_fifo, buf, len);
-qemu_chr_be_write(s->chr, buf, len);
+avail = fifo8_num_used(>out_fifo);
+if (len > avail) {
+len = avail;
+}
+while (len > 0) {
+const uint8_t *buf;
+uint32_t size;
+
+buf = fifo8_pop_buf(>out_fifo, len, );
+qemu_chr_be_write(s->chr, (uint8_t *)buf, size);
+len -= size;
+avail -= size;
 }
 /* characters are pending: we send them a bit later (XXX:
horrible, should change char device API) */
-if (s->out_fifo.count > 0) {
+if (avail > 0) {
 timer_mod(s->kbd_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1);
 }
 }
@@ -1185,6 +1138,7 @@ void kbd_put_keysym_console(QemuConsole *s, int keysym)
 uint8_t buf[16], *q;
 CharBackend *be;
 int c;
+uint32_t num_free;
 
 if (!s || (s->console_type == GRAPHIC_CONSOLE))
 return;
@@ -1228,7 +1182,8 @@ void kbd_put_keysym_console(QemuConsole *s, int keysym)
 }
 be = s->chr->be;
 if (be && be->chr_read) {
-qemu_fifo_write(>out_fifo, buf, q - buf);
+num_free = fifo8_num_free(>out_fifo);
+fifo8_push_all(>out_fifo, buf, MIN(num_free, q - buf));
 kbd_send_chars(s);
 }
 break;
@@ -2233,8 +2188,7 @@ static void text_console_do_init(Chardev *chr, 
DisplayState *ds)
 int g_width = 80 * FONT_WIDTH;
 int g_height = 24 * FONT_HEIGHT;
 
-s->out_fifo.buf = s->out_fifo_buf;
-s->out_fifo.buf_size = sizeof(s->out_fifo_buf);
+fifo8_create(>out_fifo, 16);
 s->kbd_timer = timer_new_ms(QEMU_CLOCK_REALTIME, kbd_send_chars, s);
 s->ds = ds;
 
-- 
2.31.1



[PULL 00/10] Misc 20211102 patches

2021-11-02 Thread Gerd Hoffmann
The following changes since commit 8cb41fda78c7ebde0dd248c6afe1d336efb0de50:

  Merge remote-tracking branch 'remotes/philmd/tags/machine-20211101' into 
staging (2021-11-02 05:53:45 -0400)

are available in the Git repository at:

  git://git.kraxel.org/qemu tags/misc-20211102-pull-request

for you to fetch changes up to 58d7d4c7869cb3addb0714aa7b6bd88f2b6b7edf:

  usb-storage: tag usb_msd_csw as packed struct (2021-11-02 17:24:18 +0100)


MAINTAINERS: audio updates
microvm: device tree support
console: chardev fixes
misc: deprecate sga
usb: fix struct usb_msd_csw



Christian Schoenebeck (1):
  MAINTAINERS: add myself as partial audio reviewer

Daniel P. Berrangé (1):
  hw/misc: deprecate the 'sga' device

Dongwon Kim (1):
  ui/gtk: skip any extra draw of same guest scanout blob res

Gerd Hoffmann (2):
  microvm: add device tree support.
  usb-storage: tag usb_msd_csw as packed struct

Nikola Pavlica (1):
  ui/gtk: Update the refresh rate for gl-area too

Thomas Huth (1):
  MAINTAINERS: Add myself as a reviewer for SDL audio

Volker Rümelin (3):
  ui/console: replace QEMUFIFO with Fifo8
  ui/console: replace kbd_timer with chr_accept_input callback
  ui/console: remove chardev frontend connected test

 hw/i386/microvm-dt.h   |   8 +
 include/hw/i386/microvm.h  |   4 +
 include/hw/usb/msd.h   |   2 +-
 include/ui/console.h   |   1 +
 hw/display/virtio-gpu-udmabuf.c|   2 +-
 hw/i386/microvm-dt.c   | 341 +
 hw/i386/microvm.c  |   2 +
 hw/misc/sga.c  |   2 +
 ui/console.c   | 109 +++--
 ui/gtk-egl.c   |  40 ++--
 ui/gtk-gl-area.c   |  52 +++--
 .gitlab-ci.d/buildtest.yml |   1 -
 MAINTAINERS|   4 +
 configs/targets/i386-softmmu.mak   |   1 +
 configs/targets/x86_64-softmmu.mak |   1 +
 docs/about/deprecated.rst  |  10 +
 hw/i386/meson.build|   2 +-
 17 files changed, 466 insertions(+), 116 deletions(-)
 create mode 100644 hw/i386/microvm-dt.h
 create mode 100644 hw/i386/microvm-dt.c

-- 
2.31.1




[PULL 02/10] MAINTAINERS: add myself as partial audio reviewer

2021-11-02 Thread Gerd Hoffmann
From: Christian Schoenebeck 

Volunteering as reviewer for some of the audio backends; namely
ALSA, CoreAudio and JACK.

Signed-off-by: Christian Schoenebeck 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: 
Signed-off-by: Gerd Hoffmann 
---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 99618e6d9906..9ddba68701b5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2285,11 +2285,13 @@ F: qapi/audio.json
 
 ALSA Audio backend
 M: Gerd Hoffmann 
+R: Christian Schoenebeck 
 S: Odd Fixes
 F: audio/alsaaudio.c
 
 Core Audio framework backend
 M: Gerd Hoffmann 
+R: Christian Schoenebeck 
 S: Odd Fixes
 F: audio/coreaudio.c
 
@@ -2300,6 +2302,7 @@ F: audio/dsound*
 
 JACK Audio Connection Kit backend
 M: Gerd Hoffmann 
+R: Christian Schoenebeck 
 S: Odd Fixes
 F: audio/jackaudio.c
 
-- 
2.31.1



Re: [PATCH] hw/misc: deprecate the 'sga' device

2021-09-09 Thread Gerd Hoffmann
On Thu, Sep 09, 2021 at 01:32:19PM +0100, Daniel P. Berrangé wrote:
> This is obsolete since SeaBIOS 1.11.0 introduced native support for
> sending messages to the serial console. The new support can be
> activated using -machine graphics=off on x86 targets.
> 
> Signed-off-by: Daniel P. Berrangé 

Reviewed-by: Gerd Hoffmann 



Re: [PULL 37/48] usb: build usb-host as module

2021-07-23 Thread Gerd Hoffmann
> > +if config_host.has_key('CONFIG_USB_LIBUSB')
> 
> The problem is in this condition as it's evaluated as false. When I
> replace it with libusb.found(), everything works as it used to.

Correct fix, paolo has a pending pull request containing it.

> Unfortunately I don't know what the real goa behind using
> CONFIG_USB_LIBUSB here was to see whether my approach is good.

Used to be the correct approach before libusb detection was
switched from configure to meson.

take care,
  Gerd



Re: [PATCH v2] ui: Make the DisplayType enum entries conditional

2021-06-23 Thread Gerd Hoffmann
On Tue, Jun 15, 2021 at 11:04:39AM +0200, Thomas Huth wrote:
> Libvirt's "domcapabilities" command has a way to state whether certain
> graphic frontends are available in QEMU or not. Originally, libvirt
> looked at the "--help" output of the QEMU binary to determine whether
> SDL was available or not (by looking for the "-sdl" parameter in the
> help text), but since libvirt stopped doing this analysis of the help
> text, the detection of SDL is currently broken, see:
> 
>  https://bugzilla.redhat.com/show_bug.cgi?id=1790902
> 
> QEMU should provide a way via the QMP interface instead. A simple way,
> without introducing additional commands, is to make the DisplayType
> enum entries conditional, so that the enum only contains the entries if
> the corresponding CONFIG_xxx switches have been set. This of course
> only gives an indication which possibilities have been enabled during
> compile-time of QEMU (and does not take into account whether modules
> are later available or not for example - for this we'd need a separate
> command), but anyway, this should already be good enough for the above
> bug ticket, and it's a good idea anyway to make the QMP interface
> conditional here, so let's simply do it.
> 
> Signed-off-by: Thomas Huth 

Added to ui queue.

thanks,
  Gerd



Re: [RFC QEMU PATCH] ui: Make the DisplayType enum entries conditional

2021-06-09 Thread Gerd Hoffmann
  Hi,

> > The #if CONFIG_SDL approach will not work because qemu will continue to
> > report sdl as supported even when the sdl module is not installed any
> > more.
> 
> I guess we'd need a separate QMP command to fix that, which tries to load
> the modules first when being called? Something similar to what is being done
> in qemu_display_help() ?

That would work, yes.

> That's certainly doable, too, just a little bit more complex...

Alternative idea: turn QemuDisplay into an ObjectClass, then it'll be
visible in qom introspection.  Likewise a bit more complex ...

> do we want that?  Or is the quick-n-easy way via the schema good
> enough for most use cases?

Would be better than nothing, but I'd prefer something which works
properly with modular qemu ...

> (I'm not that familiar with "virsh domcapabilities" ... is there any
> real usage for the  section or is this rather cosmetical?)

Management apps can use that info to avoid building unsupported
configurations.  Also you'll get a nice "$foo is not supported" error
from libvirt instead of libvirt dumping qemu stderr ;)

take care,
  Gerd



Re: [RFC QEMU PATCH] ui: Make the DisplayType enum entries conditional

2021-06-09 Thread Gerd Hoffmann
On Wed, Jun 09, 2021 at 12:29:58PM +0100, Daniel P. Berrangé wrote:
> On Wed, Jun 09, 2021 at 01:24:05PM +0200, Gerd Hoffmann wrote:
> > On Wed, Jun 09, 2021 at 12:02:40PM +0200, Thomas Huth wrote:
> > > Libvirt's "domcapabilities" command has a way to state whether
> > > certain graphic frontends are available in QEMU or not. Originally,
> > > libvirt looked at the "--help" output of the QEMU binary to determine
> > > whether SDL was available or not (by looking for the "-sdl" parameter
> > > in the help text), but since libvirt stopped doing this analysis of
> > > the help text, the detection of SDL is currently broken, see:
> > > 
> > >  https://bugzilla.redhat.com/show_bug.cgi?id=1790902
> > > 
> > > QEMU should provide a way via the QMP interface instead. The simplest
> > > way, without introducing additional commands, is to make the DisplayType
> > > enum entries conditional, so that the enum only contains the entries if
> > > the corresponding CONFIG_xxx switches have been set.
> > 
> > Hmm, that'll break for the "dnf remove qemu-ui-sdl" case ...
> 
> Note tht libvirt invalidates its cache of QEMU capabilities when it
> sees the /usr/lib64/qemu directory timestamp change. So it ought to
> pick up changes caused by installing/removing QEMU modules, and apply
> this to future queries for domcapabilities, or when starting future
> QEMU guests.

That'll work fine for modules implementing qom objects / devices,
because the list of available objects changes accordingly and libvirt
can see that.

The #if CONFIG_SDL approach will not work because qemu will continue to
report sdl as supported even when the sdl module is not installed any
more.

take care,
  Gerd



Re: [RFC QEMU PATCH] ui: Make the DisplayType enum entries conditional

2021-06-09 Thread Gerd Hoffmann
On Wed, Jun 09, 2021 at 12:02:40PM +0200, Thomas Huth wrote:
> Libvirt's "domcapabilities" command has a way to state whether
> certain graphic frontends are available in QEMU or not. Originally,
> libvirt looked at the "--help" output of the QEMU binary to determine
> whether SDL was available or not (by looking for the "-sdl" parameter
> in the help text), but since libvirt stopped doing this analysis of
> the help text, the detection of SDL is currently broken, see:
> 
>  https://bugzilla.redhat.com/show_bug.cgi?id=1790902
> 
> QEMU should provide a way via the QMP interface instead. The simplest
> way, without introducing additional commands, is to make the DisplayType
> enum entries conditional, so that the enum only contains the entries if
> the corresponding CONFIG_xxx switches have been set.

Hmm, that'll break for the "dnf remove qemu-ui-sdl" case ...

take care,
  Gerd



[PULL 09/11] ui: honour the actual guest display dimensions without rounding

2021-03-15 Thread Gerd Hoffmann
From: Daniel P. Berrangé 

A long time ago the VNC server code had some memory corruption
fixes done in:

  commit bea60dd7679364493a0d7f5b54316c767cf894ef
  Author: Peter Lieven 
  Date:   Mon Jun 30 10:57:51 2014 +0200

ui/vnc: fix potential memory corruption issues

One of the implications of the fix was that the VNC server would have a
thin black bad down the right hand side if the guest desktop width was
not a multiple of 16. In practice this was a non-issue since the VNC
server was always honouring a guest specified resolution and guests
essentially always pick from a small set of sane resolutions likely in
real world hardware.

We recently introduced support for the extended desktop resize extension
and as a result the VNC client has ability to specify an arbitrary
desktop size and the guest OS may well honour it exactly. As a result we
no longer have any guarantee that the width will be a multiple of 16,
and so when resizing the desktop we have a 93% chance of getting the
black bar on the right hand size.

The VNC server maintains three different desktop dimensions

 1. The guest surface
 2. The server surface
 3. The client desktop

The requirement for the width to be a multiple of 16 only applies to
item 2, the server surface, for the purpose of doing dirty bitmap
tracking.

Normally we will set the client desktop size to always match the server
surface size, but that's not a strict requirement. In order to cope with
clients that don't support the desktop size encoding, we already allow
for the client desktop to be a different size that the server surface.

Thus we can trivially eliminate the black bar, but setting the client
desktop size to be the un-rounded server surface size - the so called
"true width".

Signed-off-by: Daniel P. Berrangé 
Reviewed-by: Marc-André Lureau 
Message-Id: <20210311182957.486939-5-berra...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/vnc.h|  1 +
 ui/vnc.c| 23 +++
 ui/trace-events |  2 ++
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/ui/vnc.h b/ui/vnc.h
index 116463d5f099..d4f3e1555809 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -164,6 +164,7 @@ struct VncDisplay
 
 struct VncSurface guest;   /* guest visible surface (aka ds->surface) */
 pixman_image_t *server;/* vnc server surface */
+int true_width; /* server surface width before rounding up */
 
 const char *id;
 QTAILQ_ENTRY(VncDisplay) next;
diff --git a/ui/vnc.c b/ui/vnc.c
index 8c9890b3cdc4..9c004a11f495 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -608,6 +608,11 @@ static int vnc_width(VncDisplay *vd)
VNC_DIRTY_PIXELS_PER_BIT));
 }
 
+static int vnc_true_width(VncDisplay *vd)
+{
+return MIN(VNC_MAX_WIDTH, surface_width(vd->ds));
+}
+
 static int vnc_height(VncDisplay *vd)
 {
 return MIN(VNC_MAX_HEIGHT, surface_height(vd->ds));
@@ -691,16 +696,16 @@ static void vnc_desktop_resize(VncState *vs)
 !vnc_has_feature(vs, VNC_FEATURE_RESIZE_EXT))) {
 return;
 }
-if (vs->client_width == pixman_image_get_width(vs->vd->server) &&
+if (vs->client_width == vs->vd->true_width &&
 vs->client_height == pixman_image_get_height(vs->vd->server)) {
 return;
 }
 
-assert(pixman_image_get_width(vs->vd->server) < 65536 &&
-   pixman_image_get_width(vs->vd->server) >= 0);
+assert(vs->vd->true_width < 65536 &&
+   vs->vd->true_width >= 0);
 assert(pixman_image_get_height(vs->vd->server) < 65536 &&
pixman_image_get_height(vs->vd->server) >= 0);
-vs->client_width = pixman_image_get_width(vs->vd->server);
+vs->client_width = vs->vd->true_width;
 vs->client_height = pixman_image_get_height(vs->vd->server);
 
 if (vnc_has_feature(vs, VNC_FEATURE_RESIZE_EXT)) {
@@ -774,6 +779,7 @@ static void vnc_update_server_surface(VncDisplay *vd)
 
 width = vnc_width(vd);
 height = vnc_height(vd);
+vd->true_width = vnc_true_width(vd);
 vd->server = pixman_image_create_bits(VNC_SERVER_FB_FORMAT,
   width, height,
   NULL, 0);
@@ -809,13 +815,22 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl,
 vd->guest.fb = pixman_image_ref(surface->image);
 vd->guest.format = surface->format;
 
+
 if (pageflip) {
+trace_vnc_server_dpy_pageflip(vd,
+  surface_width(surface),
+  surface_height(surface),
+  surface_format(surface));
 vnc_set_area_dirty(vd->guest.dirty, vd, 0, 0,
surface_width(surface),
surface_heigh

[PULL 07/11] ui: avoid sending framebuffer updates outside client desktop bounds

2021-03-15 Thread Gerd Hoffmann
From: Daniel P. Berrangé 

We plan framebuffer update rects based on the VNC server surface. If the
client doesn't support desktop resize, then the client bounds may differ
from the server surface bounds. VNC clients may become upset if we then
send an update message outside the bounds of the client desktop.

This takes the approach of clamping the rectangles from the worker
thread immediately before sending them. This may sometimes results in
sending a framebuffer update message with zero rectangles.

Signed-off-by: Daniel P. Berrangé 
Reviewed-by: Marc-André Lureau 
Message-Id: <20210311182957.486939-3-berra...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/vnc-jobs.c   | 44 
 ui/trace-events |  5 +
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c
index dbbfbefe5619..4562bf89288e 100644
--- a/ui/vnc-jobs.c
+++ b/ui/vnc-jobs.c
@@ -32,6 +32,7 @@
 #include "qemu/sockets.h"
 #include "qemu/main-loop.h"
 #include "block/aio.h"
+#include "trace.h"
 
 /*
  * Locking:
@@ -94,6 +95,8 @@ int vnc_job_add_rect(VncJob *job, int x, int y, int w, int h)
 {
 VncRectEntry *entry = g_new0(VncRectEntry, 1);
 
+trace_vnc_job_add_rect(job->vs, job, x, y, w, h);
+
 entry->rect.x = x;
 entry->rect.y = y;
 entry->rect.w = w;
@@ -190,6 +193,8 @@ static void vnc_async_encoding_start(VncState *orig, 
VncState *local)
 local->zlib = orig->zlib;
 local->hextile = orig->hextile;
 local->zrle = orig->zrle;
+local->client_width = orig->client_width;
+local->client_height = orig->client_height;
 }
 
 static void vnc_async_encoding_end(VncState *orig, VncState *local)
@@ -202,6 +207,34 @@ static void vnc_async_encoding_end(VncState *orig, 
VncState *local)
 orig->lossy_rect = local->lossy_rect;
 }
 
+static bool vnc_worker_clamp_rect(VncState *vs, VncJob *job, VncRect *rect)
+{
+trace_vnc_job_clamp_rect(vs, job, rect->x, rect->y, rect->w, rect->h);
+
+if (rect->x >= vs->client_width) {
+goto discard;
+}
+rect->w = MIN(vs->client_width - rect->x, rect->w);
+if (rect->w == 0) {
+goto discard;
+}
+
+if (rect->y >= vs->client_height) {
+goto discard;
+}
+rect->h = MIN(vs->client_height - rect->y, rect->h);
+if (rect->h == 0) {
+goto discard;
+}
+
+trace_vnc_job_clamped_rect(vs, job, rect->x, rect->y, rect->w, rect->h);
+return true;
+
+ discard:
+trace_vnc_job_discard_rect(vs, job, rect->x, rect->y, rect->w, rect->h);
+return false;
+}
+
 static int vnc_worker_thread_loop(VncJobQueue *queue)
 {
 VncJob *job;
@@ -260,14 +293,17 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
 goto disconnected;
 }
 
-n = vnc_send_framebuffer_update(, entry->rect.x, entry->rect.y,
-entry->rect.w, entry->rect.h);
+if (vnc_worker_clamp_rect(, job, >rect)) {
+n = vnc_send_framebuffer_update(, entry->rect.x, entry->rect.y,
+entry->rect.w, entry->rect.h);
 
-if (n >= 0) {
-n_rectangles += n;
+if (n >= 0) {
+n_rectangles += n;
+}
 }
 g_free(entry);
 }
+trace_vnc_job_nrects(, job, n_rectangles);
 vnc_unlock_display(job->vs->vd);
 
 /* Put n_rectangles at the beginning of the message */
diff --git a/ui/trace-events b/ui/trace-events
index bd8f8a9d186a..3838ae2d849a 100644
--- a/ui/trace-events
+++ b/ui/trace-events
@@ -59,6 +59,11 @@ vnc_client_throttle_audio(void *state, void *ioc, size_t 
offset) "VNC client thr
 vnc_client_unthrottle_forced(void *state, void *ioc) "VNC client unthrottle 
forced offset state=%p ioc=%p"
 vnc_client_unthrottle_incremental(void *state, void *ioc, size_t offset) "VNC 
client unthrottle incremental state=%p ioc=%p offset=%zu"
 vnc_client_output_limit(void *state, void *ioc, size_t offset, size_t 
threshold) "VNC client output limit state=%p ioc=%p offset=%zu threshold=%zu"
+vnc_job_add_rect(void *state, void *job, int x, int y, int w, int h) "VNC add 
rect state=%p job=%p offset=%d,%d size=%dx%d"
+vnc_job_discard_rect(void *state, void *job, int x, int y, int w, int h) "VNC 
job discard rect state=%p job=%p offset=%d,%d size=%dx%d"
+vnc_job_clamp_rect(void *state, void *job, int x, int y, int w, int h) "VNC 
job clamp rect state=%p job=%p offset=%d,%d size=%dx%d"
+vnc_job_clamped_rect(void *state, void *job, int x, int y, int w, int h) "VNC 
job clamp rect state=%p job=%p offset=%d,%d size=%dx%d"
+vnc_job_nrects(void *state, void *job, int nrects) "VNC job state=%p job=%p 
nrec

[PULL 08/11] ui: use client width/height in WMVi message

2021-03-15 Thread Gerd Hoffmann
From: Daniel P. Berrangé 

The WMVi message is supposed to provide the same width/height
information as the regular desktop resize and extended desktop
resize messages. There can be times where the client width and
height are different from the pixman surface dimensions.

Signed-off-by: Daniel P. Berrangé 
Reviewed-by: Marc-André Lureau 
Message-Id: <20210311182957.486939-4-berra...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/vnc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 7291429c04cf..8c9890b3cdc4 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2319,8 +2319,8 @@ static void vnc_colordepth(VncState *vs)
 vnc_write_u8(vs, 0);
 vnc_write_u16(vs, 1); /* number of rects */
 vnc_framebuffer_update(vs, 0, 0,
-   pixman_image_get_width(vs->vd->server),
-   pixman_image_get_height(vs->vd->server),
+   vs->client_width,
+   vs->client_height,
VNC_ENCODING_WMVi);
 pixel_format_message(vs);
 vnc_unlock_output(vs);
-- 
2.29.2



[PULL 06/11] ui: add more trace points for VNC client/server messages

2021-03-15 Thread Gerd Hoffmann
From: Daniel P. Berrangé 

This adds trace points for desktop size and audio related messages.

Signed-off-by: Daniel P. Berrangé 
Reviewed-by: Marc-André Lureau 
Message-Id: <20210311182957.486939-2-berra...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/vnc.c| 21 +++--
 ui/trace-events |  9 +
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index e8e3426a65c4..7291429c04cf 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -659,6 +659,9 @@ void vnc_framebuffer_update(VncState *vs, int x, int y, int 
w, int h,
 
 static void vnc_desktop_resize_ext(VncState *vs, int reject_reason)
 {
+trace_vnc_msg_server_ext_desktop_resize(
+vs, vs->ioc, vs->client_width, vs->client_height, reject_reason);
+
 vnc_lock_output(vs);
 vnc_write_u8(vs, VNC_MSG_SERVER_FRAMEBUFFER_UPDATE);
 vnc_write_u8(vs, 0);
@@ -705,6 +708,9 @@ static void vnc_desktop_resize(VncState *vs)
 return;
 }
 
+trace_vnc_msg_server_desktop_resize(
+vs, vs->ioc, vs->client_width, vs->client_height);
+
 vnc_lock_output(vs);
 vnc_write_u8(vs, VNC_MSG_SERVER_FRAMEBUFFER_UPDATE);
 vnc_write_u8(vs, 0);
@@ -1182,6 +1188,7 @@ static void audio_capture_notify(void *opaque, 
audcnotification_e cmd)
 assert(vs->magic == VNC_MAGIC);
 switch (cmd) {
 case AUD_CNOTIFY_DISABLE:
+trace_vnc_msg_server_audio_end(vs, vs->ioc);
 vnc_lock_output(vs);
 vnc_write_u8(vs, VNC_MSG_SERVER_QEMU);
 vnc_write_u8(vs, VNC_MSG_SERVER_QEMU_AUDIO);
@@ -1191,6 +1198,7 @@ static void audio_capture_notify(void *opaque, 
audcnotification_e cmd)
 break;
 
 case AUD_CNOTIFY_ENABLE:
+trace_vnc_msg_server_audio_begin(vs, vs->ioc);
 vnc_lock_output(vs);
 vnc_write_u8(vs, VNC_MSG_SERVER_QEMU);
 vnc_write_u8(vs, VNC_MSG_SERVER_QEMU_AUDIO);
@@ -1210,6 +1218,7 @@ static void audio_capture(void *opaque, const void *buf, 
int size)
 VncState *vs = opaque;
 
 assert(vs->magic == VNC_MAGIC);
+trace_vnc_msg_server_audio_data(vs, vs->ioc, buf, size);
 vnc_lock_output(vs);
 if (vs->output.offset < vs->throttle_output_offset) {
 vnc_write_u8(vs, VNC_MSG_SERVER_QEMU);
@@ -2454,9 +2463,11 @@ static int protocol_client_msg(VncState *vs, uint8_t 
*data, size_t len)
 
 switch (read_u16 (data, 2)) {
 case VNC_MSG_CLIENT_QEMU_AUDIO_ENABLE:
+trace_vnc_msg_client_audio_enable(vs, vs->ioc);
 audio_add(vs);
 break;
 case VNC_MSG_CLIENT_QEMU_AUDIO_DISABLE:
+trace_vnc_msg_client_audio_disable(vs, vs->ioc);
 audio_del(vs);
 break;
 case VNC_MSG_CLIENT_QEMU_AUDIO_SET_FORMAT:
@@ -2492,6 +2503,8 @@ static int protocol_client_msg(VncState *vs, uint8_t 
*data, size_t len)
 break;
 }
 vs->as.freq = freq;
+trace_vnc_msg_client_audio_format(
+vs, vs->ioc, vs->as.fmt, vs->as.nchannels, vs->as.freq);
 break;
 default:
 VNC_DEBUG("Invalid audio message %d\n", read_u8(data, 4));
@@ -2510,6 +2523,7 @@ static int protocol_client_msg(VncState *vs, uint8_t 
*data, size_t len)
 {
 size_t size;
 uint8_t screens;
+int w, h;
 
 if (len < 8) {
 return 8;
@@ -2520,12 +2534,15 @@ static int protocol_client_msg(VncState *vs, uint8_t 
*data, size_t len)
 if (len < size) {
 return size;
 }
+w = read_u16(data, 2);
+h = read_u16(data, 4);
 
+trace_vnc_msg_client_set_desktop_size(vs, vs->ioc, w, h, screens);
 if (dpy_ui_info_supported(vs->vd->dcl.con)) {
 QemuUIInfo info;
 memset(, 0, sizeof(info));
-info.width = read_u16(data, 2);
-info.height = read_u16(data, 4);
+info.width = w;
+info.height = h;
 dpy_set_ui_info(vs->vd->dcl.con, );
 vnc_desktop_resize_ext(vs, 4 /* Request forwarded */);
 } else {
diff --git a/ui/trace-events b/ui/trace-events
index 0ffcdb4408a6..bd8f8a9d186a 100644
--- a/ui/trace-events
+++ b/ui/trace-events
@@ -37,6 +37,15 @@ vnc_key_event_ext(bool down, int sym, int keycode, const 
char *name) "down %d, s
 vnc_key_event_map(bool down, int sym, int keycode, const char *name) "down %d, 
sym 0x%x -> keycode 0x%x [%s]"
 vnc_key_sync_numlock(bool on) "%d"
 vnc_key_sync_capslock(bool on) "%d"
+vnc_msg_server_audio_begin(void *state, void *ioc) "VNC server msg audio begin 
state=%p ioc=%p"
+vnc_msg_server_audio_end(void *state, void *ioc) "VNC server msg audio end 
state=%p ioc=%p"
+vnc_msg_server_audio_data(void *state, void *ioc, const void *buf, size_t len) 

[PULL 02/11] ui: introduce "password-secret" option for SPICE server

2021-03-15 Thread Gerd Hoffmann
From: Daniel P. Berrangé 

Currently when using SPICE the "password" option provides the password
in plain text on the command line. This is insecure as it is visible
to all processes on the host. As an alternative, the password can be
provided separately via the monitor.

This introduces a "password-secret" option which lets the password be
provided up front.

  $QEMU --object secret,id=vncsec0,file=passwd.txt \
--spice port=5901,password-secret=vncsec0

Signed-off-by: Daniel P. Berrangé 
Message-Id: <2021034343.439820-3-berra...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/spice-core.c | 30 --
 qemu-options.hx |  9 +++--
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/ui/spice-core.c b/ui/spice-core.c
index cadec766fe3a..b9d8aced91df 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -34,6 +34,7 @@
 #include "qapi/qapi-events-ui.h"
 #include "qemu/notify.h"
 #include "qemu/option.h"
+#include "crypto/secret_common.h"
 #include "migration/misc.h"
 #include "hw/pci/pci_bus.h"
 #include "ui/spice-display.h"
@@ -415,6 +416,9 @@ static QemuOptsList qemu_spice_opts = {
 },{
 .name = "password",
 .type = QEMU_OPT_STRING,
+},{
+.name = "password-secret",
+.type = QEMU_OPT_STRING,
 },{
 .name = "disable-ticketing",
 .type = QEMU_OPT_BOOL,
@@ -636,7 +640,9 @@ void qemu_spice_display_init_done(void)
 static void qemu_spice_init(void)
 {
 QemuOpts *opts = QTAILQ_FIRST(_spice_opts.head);
-const char *password, *str, *x509_dir, *addr,
+char *password = NULL;
+const char *passwordSecret;
+const char *str, *x509_dir, *addr,
 *x509_key_password = NULL,
 *x509_dh_file = NULL,
 *tls_ciphers = NULL;
@@ -663,7 +669,26 @@ static void qemu_spice_init(void)
 error_report("spice tls-port is out of range");
 exit(1);
 }
-password = qemu_opt_get(opts, "password");
+passwordSecret = qemu_opt_get(opts, "password-secret");
+if (passwordSecret) {
+Error *local_err = NULL;
+if (qemu_opt_get(opts, "password")) {
+error_report("'password' option is mutually exclusive with "
+ "'password-secret'");
+exit(1);
+}
+password = qcrypto_secret_lookup_as_utf8(passwordSecret,
+ _err);
+if (!password) {
+error_report_err(local_err);
+exit(1);
+}
+} else {
+str = qemu_opt_get(opts, "password");
+if (str) {
+password = g_strdup(str);
+}
+}
 
 if (tls_port) {
 x509_dir = qemu_opt_get(opts, "x509-dir");
@@ -809,6 +834,7 @@ static void qemu_spice_init(void)
 g_free(x509_key_file);
 g_free(x509_cert_file);
 g_free(x509_cacert_file);
+g_free(password);
 
 #ifdef HAVE_SPICE_GL
 if (qemu_opt_get_bool(opts, "gl", 0)) {
diff --git a/qemu-options.hx b/qemu-options.hx
index 357fc4596ecc..a98f8e84a29d 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1899,7 +1899,8 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice,
 "   [,tls-ciphers=]\n"
 "   [,tls-channel=[main|display|cursor|inputs|record|playback]]\n"
 "   
[,plaintext-channel=[main|display|cursor|inputs|record|playback]]\n"
-"   [,sasl=on|off][,password=][,disable-ticketing=on|off]\n"
+"   [,sasl=on|off][,disable-ticketing=on|off]\n"
+"   [,password=][,password-secret=]\n"
 "   [,image-compression=[auto_glz|auto_lz|quic|glz|lz|off]]\n"
 "   [,jpeg-wan-compression=[auto|never|always]]\n"
 "   [,zlib-glz-wan-compression=[auto|never|always]]\n"
@@ -1924,9 +1925,13 @@ SRST
 ``ipv4=on|off``; \ ``ipv6=on|off``; \ ``unix=on|off``
 Force using the specified IP version.
 
-``password=``
+``password=``
 Set the password you need to authenticate.
 
+``password-secret=``
+Set the ID of the ``secret`` object containing the password
+you need to authenticate.
+
 ``sasl=on|off``
 Require that the client use SASL to authenticate with the spice.
 The exact choice of authentication method used is controlled
-- 
2.29.2



[PULL 11/11] ui/cocoa: Comment about modifier key input quirks

2021-03-15 Thread Gerd Hoffmann
From: Akihiko Odaki 

Based-on: <20210310042348.21931-1-akihiko.od...@gmail.com>
Signed-off-by: Akihiko Odaki 
Message-Id: <20210312133212.3131-1-akihiko.od...@gmail.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/cocoa.m | 38 +-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 9da0e884b712..37e1fb52eb4d 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -690,7 +690,43 @@ QemuCocoaView *cocoaView;
 NSPoint p = [self screenLocationOfEvent:event];
 NSUInteger modifiers = [event modifierFlags];
 
-// emulate caps lock keydown and keyup
+/*
+ * Check -[NSEvent modifierFlags] here.
+ *
+ * There is a NSEventType for an event notifying the change of
+ * -[NSEvent modifierFlags], NSEventTypeFlagsChanged but these operations
+ * are performed for any events because a modifier state may change while
+ * the application is inactive (i.e. no events fire) and we don't want to
+ * wait for another modifier state change to detect such a change.
+ *
+ * NSEventModifierFlagCapsLock requires a special treatment. The other 
flags
+ * are handled in similar manners.
+ *
+ * NSEventModifierFlagCapsLock
+ * ---
+ *
+ * If CapsLock state is changed, "up" and "down" events will be fired in
+ * sequence, effectively updates CapsLock state on the guest.
+ *
+ * The other flags
+ * ---
+ *
+ * If a flag is not set, fire "up" events for all keys which correspond to
+ * the flag. Note that "down" events are not fired here because the flags
+ * checked here do not tell what exact keys are down.
+ *
+ * If one of the keys corresponding to a flag is down, we rely on
+ * -[NSEvent keyCode] of an event whose -[NSEvent type] is
+ * NSEventTypeFlagsChanged to know the exact key which is down, which has
+ * the following two downsides:
+ * - It does not work when the application is inactive as described above.
+ * - It malfactions *after* the modifier state is changed while the
+ *   application is inactive. It is because -[NSEvent keyCode] does not 
tell
+ *   if the key is up or down, and requires to infer the current state from
+ *   the previous state. It is still possible to fix such a malfanction by
+ *   completely leaving your hands from the keyboard, which hopefully makes
+ *   this implementation usable enough.
+ */
 if (!!(modifiers & NSEventModifierFlagCapsLock) !=
 qkbd_state_modifier_get(kbd, QKBD_MOD_CAPSLOCK)) {
 qkbd_state_key_event(kbd, Q_KEY_CODE_CAPS_LOCK, true);
-- 
2.29.2



[PULL 10/11] ui: fold qemu_alloc_display in only caller

2021-03-15 Thread Gerd Hoffmann
From: Marc-André Lureau 

A minor code simplification.

Signed-off-by: Marc-André Lureau 
Message-Id: <20210312100108.2706195-2-marcandre.lur...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/console.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index c2fdf975b6b3..2de5f4105b59 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1386,26 +1386,18 @@ static QemuConsole *new_console(DisplayState *ds, 
console_type_t console_type,
 return s;
 }
 
-static void qemu_alloc_display(DisplaySurface *surface, int width, int height)
+DisplaySurface *qemu_create_displaysurface(int width, int height)
 {
-qemu_pixman_image_unref(surface->image);
-surface->image = NULL;
+DisplaySurface *surface = g_new0(DisplaySurface, 1);
 
+trace_displaysurface_create(surface, width, height);
 surface->format = PIXMAN_x8r8g8b8;
 surface->image = pixman_image_create_bits(surface->format,
   width, height,
   NULL, width * 4);
 assert(surface->image != NULL);
-
 surface->flags = QEMU_ALLOCATED_FLAG;
-}
 
-DisplaySurface *qemu_create_displaysurface(int width, int height)
-{
-DisplaySurface *surface = g_new0(DisplaySurface, 1);
-
-trace_displaysurface_create(surface, width, height);
-qemu_alloc_display(surface, width, height);
 return surface;
 }
 
-- 
2.29.2



[PULL 03/11] ui: deprecate "password" option for SPICE server

2021-03-15 Thread Gerd Hoffmann
From: Daniel P. Berrangé 

With the new "password-secret" option, there is no reason to use the old
inecure "password" option with -spice, so it can be deprecated.

Signed-off-by: Daniel P. Berrangé 
Message-Id: <2021034343.439820-4-berra...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/spice-core.c| 2 ++
 docs/system/deprecated.rst | 8 
 qemu-options.hx| 4 
 3 files changed, 14 insertions(+)

diff --git a/ui/spice-core.c b/ui/spice-core.c
index b9d8aced91df..272d19b0c152 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -686,6 +686,8 @@ static void qemu_spice_init(void)
 } else {
 str = qemu_opt_get(opts, "password");
 if (str) {
+warn_report("'password' option is deprecated and insecure, "
+"use 'password-secret' instead");
 password = g_strdup(str);
 }
 }
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 5e3a31c12361..8cba672a7b4a 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -174,6 +174,14 @@ Input parameters that take a size value should only use a 
size suffix
 the value is hexadecimal.  That is, '0x20M' is deprecated, and should
 be written either as '32M' or as '0x200'.
 
+``-spice password=string`` (since 6.0)
+''
+
+This option is insecure because the SPICE password remains visible in
+the process listing. This is replaced by the new ``password-secret``
+option which lets the password be securely provided on the command
+line using a ``secret`` object instance.
+
 QEMU Machine Protocol (QMP) commands
 
 
diff --git a/qemu-options.hx b/qemu-options.hx
index a98f8e84a29d..4da3f4f48c03 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1928,6 +1928,10 @@ SRST
 ``password=``
 Set the password you need to authenticate.
 
+This option is deprecated and insecure because it leaves the
+password visible in the process listing. Use ``password-secret``
+instead.
+
 ``password-secret=``
 Set the ID of the ``secret`` object containing the password
 you need to authenticate.
-- 
2.29.2



[PULL 05/11] ui/cocoa: Do not exit immediately after shutdown

2021-03-15 Thread Gerd Hoffmann
From: Akihiko Odaki 

ui/cocoa used to call exit immediately after calling
qemu_system_shutdown_request, which prevents QEMU from actually
perfoming system shutdown. Just sleep forever, and wait QEMU to call
exit and kill the Cocoa thread.

Signed-off-by: Akihiko Odaki 
Message-Id: <20210219111652.20623-1-akihiko.od...@gmail.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/cocoa.m | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index a7848ae0a30e..9da0e884b712 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1115,7 +1115,13 @@ QemuCocoaView *cocoaView;
 COCOA_DEBUG("QemuCocoaAppController: applicationWillTerminate\n");
 
 qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI);
-exit(0);
+
+/*
+ * Sleep here, because returning will cause OSX to kill us
+ * immediately; the QEMU main loop will handle the shutdown
+ * request and terminate the process.
+ */
+[NSThread sleepForTimeInterval:INFINITY];
 }
 
 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication 
*)theApplication
-- 
2.29.2



[PULL 00/11] Ui 20210316 patches

2021-03-15 Thread Gerd Hoffmann
The following changes since commit 6157b0e19721aadb4c7fdcfe57b2924af6144b14:

  Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-6.0-pull-=
request' into staging (2021-03-14 17:47:49 +)

are available in the Git repository at:

  git://git.kraxel.org/qemu tags/ui-20210316-pull-request

for you to fetch changes up to ad7f2f8ee9fbded410fbf77158b0065f8e2f08e3:

  ui/cocoa: Comment about modifier key input quirks (2021-03-16 06:36:45 +010=
0)


vnc+spice: password-secret option.
bugfixes for cocoa, vnc, opengl.



Akihiko Odaki (3):
  opengl: Do not convert format with glTexImage2D on OpenGL ES
  ui/cocoa: Do not exit immediately after shutdown
  ui/cocoa: Comment about modifier key input quirks

Daniel P. Berrang=C3=A9 (7):
  ui: introduce "password-secret" option for VNC servers
  ui: introduce "password-secret" option for SPICE server
  ui: deprecate "password" option for SPICE server
  ui: add more trace points for VNC client/server messages
  ui: avoid sending framebuffer updates outside client desktop bounds
  ui: use client width/height in WMVi message
  ui: honour the actual guest display dimensions without rounding

Marc-Andr=C3=A9 Lureau (1):
  ui: fold qemu_alloc_display in only caller

 ui/vnc.h   |  1 +
 ui/console-gl.c| 19 +++---
 ui/console.c   | 14 ++--
 ui/spice-core.c| 32 +++--
 ui/vnc-jobs.c  | 44 ---
 ui/vnc.c   | 71 +-
 docs/system/deprecated.rst |  8 +
 qemu-options.hx| 18 --
 ui/cocoa.m | 46 ++--
 ui/trace-events| 16 +
 10 files changed, 234 insertions(+), 35 deletions(-)

--=20
2.29.2




[PULL 01/11] ui: introduce "password-secret" option for VNC servers

2021-03-15 Thread Gerd Hoffmann
From: Daniel P. Berrangé 

Currently when using VNC the "password" flag turns on password based
authentication. The actual password has to be provided separately via
the monitor.

This introduces a "password-secret" option which lets the password be
provided up front.

  $QEMU --object secret,id=vncsec0,file=passwd.txt \
--vnc localhost:0,password-secret=vncsec0

Signed-off-by: Daniel P. Berrangé 
Message-Id: <2021034343.439820-2-berra...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/vnc.c| 23 ++-
 qemu-options.hx |  5 +
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 310abc937812..e8e3426a65c4 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -48,6 +48,7 @@
 #include "crypto/tlscredsanon.h"
 #include "crypto/tlscredsx509.h"
 #include "crypto/random.h"
+#include "crypto/secret_common.h"
 #include "qom/object_interfaces.h"
 #include "qemu/cutils.h"
 #include "qemu/help_option.h"
@@ -3459,6 +3460,9 @@ static QemuOptsList qemu_vnc_opts = {
 },{
 .name = "password",
 .type = QEMU_OPT_BOOL,
+},{
+.name = "password-secret",
+.type = QEMU_OPT_STRING,
 },{
 .name = "reverse",
 .type = QEMU_OPT_BOOL,
@@ -3931,6 +3935,7 @@ void vnc_display_open(const char *id, Error **errp)
 int lock_key_sync = 1;
 int key_delay_ms;
 const char *audiodev;
+const char *passwordSecret;
 
 if (!vd) {
 error_setg(errp, "VNC display not active");
@@ -3948,7 +3953,23 @@ void vnc_display_open(const char *id, Error **errp)
 goto fail;
 }
 
-password = qemu_opt_get_bool(opts, "password", false);
+
+passwordSecret = qemu_opt_get(opts, "password-secret");
+if (passwordSecret) {
+if (qemu_opt_get(opts, "password")) {
+error_setg(errp,
+   "'password' flag is redundant with 'password-secret'");
+goto fail;
+}
+vd->password = qcrypto_secret_lookup_as_utf8(passwordSecret,
+ errp);
+if (!vd->password) {
+goto fail;
+}
+password = true;
+} else {
+password = qemu_opt_get_bool(opts, "password", false);
+}
 if (password) {
 if (fips_get_state()) {
 error_setg(errp,
diff --git a/qemu-options.hx b/qemu-options.hx
index 622d3bfa5a7d..357fc4596ecc 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2165,6 +2165,11 @@ SRST
 time to allow  password to expire immediately or never
 expire.
 
+``password-secret=``
+Require that password based authentication is used for client
+connections, using the password provided by the ``secret``
+object identified by ``secret-id``.
+
 ``tls-creds=ID``
 Provides the ID of a set of TLS credentials to use to secure the
 VNC server. They will apply to both the normal VNC server socket
-- 
2.29.2



[PULL 04/11] opengl: Do not convert format with glTexImage2D on OpenGL ES

2021-03-15 Thread Gerd Hoffmann
From: Akihiko Odaki 

OpenGL ES does not support conversion from the given data format
to the internal format with glTexImage2D.

Use the given data format as the internal format, and ignore
the given alpha channels with GL_TEXTURE_SWIZZLE_A in case the
format contains alpha channels.

Signed-off-by: Akihiko Odaki 
Message-Id: <20210219094803.90860-1-akihiko.od...@gmail.com>
Signed-off-by: Gerd Hoffmann 
---
 ui/console-gl.c | 19 ++-
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/ui/console-gl.c b/ui/console-gl.c
index 0a6478161fed..7c9894a51d99 100644
--- a/ui/console-gl.c
+++ b/ui/console-gl.c
@@ -73,11 +73,20 @@ void surface_gl_create_texture(QemuGLShader *gls,
 glBindTexture(GL_TEXTURE_2D, surface->texture);
 glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT,
   surface_stride(surface) / surface_bytes_per_pixel(surface));
-glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
- surface_width(surface),
- surface_height(surface),
- 0, surface->glformat, surface->gltype,
- surface_data(surface));
+if (epoxy_is_desktop_gl()) {
+glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
+ surface_width(surface),
+ surface_height(surface),
+ 0, surface->glformat, surface->gltype,
+ surface_data(surface));
+} else {
+glTexImage2D(GL_TEXTURE_2D, 0, surface->glformat,
+ surface_width(surface),
+ surface_height(surface),
+ 0, surface->glformat, surface->gltype,
+ surface_data(surface));
+glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ONE);
+}
 
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-- 
2.29.2



[PULL 11/13] usb/storage move usb-storage device to separate source file

2021-03-15 Thread Gerd Hoffmann
Pure code motion, no functional change.

Signed-off-by: Gerd Hoffmann 
Message-Id: <20210312090425.772900-4-kra...@redhat.com>
---
 hw/usb/dev-storage-classic.c | 156 +++
 hw/usb/dev-storage.c | 135 --
 hw/usb/meson.build   |   1 +
 3 files changed, 157 insertions(+), 135 deletions(-)
 create mode 100644 hw/usb/dev-storage-classic.c

diff --git a/hw/usb/dev-storage-classic.c b/hw/usb/dev-storage-classic.c
new file mode 100644
index ..00cb34b22f02
--- /dev/null
+++ b/hw/usb/dev-storage-classic.c
@@ -0,0 +1,156 @@
+/*
+ * USB Mass Storage Device emulation
+ *
+ * Copyright (c) 2006 CodeSourcery.
+ * Written by Paul Brook
+ *
+ * This code is licensed under the LGPL.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/typedefs.h"
+#include "qapi/error.h"
+#include "qapi/visitor.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
+#include "hw/usb/msd.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/block-backend.h"
+
+static const struct SCSIBusInfo usb_msd_scsi_info_storage = {
+.tcq = false,
+.max_target = 0,
+.max_lun = 0,
+
+.transfer_data = usb_msd_transfer_data,
+.complete = usb_msd_command_complete,
+.cancel = usb_msd_request_cancelled,
+.load_request = usb_msd_load_request,
+};
+
+static void usb_msd_storage_realize(USBDevice *dev, Error **errp)
+{
+MSDState *s = USB_STORAGE_DEV(dev);
+BlockBackend *blk = s->conf.blk;
+SCSIDevice *scsi_dev;
+
+if (!blk) {
+error_setg(errp, "drive property not set");
+return;
+}
+
+if (!blkconf_blocksizes(>conf, errp)) {
+return;
+}
+
+if (!blkconf_apply_backend_options(>conf, !blk_supports_write_perm(blk),
+   true, errp)) {
+return;
+}
+
+/*
+ * Hack alert: this pretends to be a block device, but it's really
+ * a SCSI bus that can serve only a single device, which it
+ * creates automatically.  But first it needs to detach from its
+ * blockdev, or else scsi_bus_legacy_add_drive() dies when it
+ * attaches again. We also need to take another reference so that
+ * blk_detach_dev() doesn't free blk while we still need it.
+ *
+ * The hack is probably a bad idea.
+ */
+blk_ref(blk);
+blk_detach_dev(blk, DEVICE(s));
+s->conf.blk = NULL;
+
+usb_desc_create_serial(dev);
+usb_desc_init(dev);
+scsi_bus_new(>bus, sizeof(s->bus), DEVICE(dev),
+ _msd_scsi_info_storage, NULL);
+scsi_dev = scsi_bus_legacy_add_drive(>bus, blk, 0, !!s->removable,
+ s->conf.bootindex, s->conf.share_rw,
+ s->conf.rerror, s->conf.werror,
+ dev->serial,
+ errp);
+blk_unref(blk);
+if (!scsi_dev) {
+return;
+}
+usb_msd_handle_reset(dev);
+s->scsi_dev = scsi_dev;
+}
+
+static Property msd_properties[] = {
+DEFINE_BLOCK_PROPERTIES(MSDState, conf),
+DEFINE_BLOCK_ERROR_PROPERTIES(MSDState, conf),
+DEFINE_PROP_BOOL("removable", MSDState, removable, false),
+DEFINE_PROP_BOOL("commandlog", MSDState, commandlog, false),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void usb_msd_class_storage_initfn(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+uc->realize = usb_msd_storage_realize;
+device_class_set_props(dc, msd_properties);
+}
+
+static void usb_msd_get_bootindex(Object *obj, Visitor *v, const char *name,
+  void *opaque, Error **errp)
+{
+USBDevice *dev = USB_DEVICE(obj);
+MSDState *s = USB_STORAGE_DEV(dev);
+
+visit_type_int32(v, name, >conf.bootindex, errp);
+}
+
+static void usb_msd_set_bootindex(Object *obj, Visitor *v, const char *name,
+  void *opaque, Error **errp)
+{
+USBDevice *dev = USB_DEVICE(obj);
+MSDState *s = USB_STORAGE_DEV(dev);
+int32_t boot_index;
+Error *local_err = NULL;
+
+if (!visit_type_int32(v, name, _index, errp)) {
+return;
+}
+/* check whether bootindex is present in fw_boot_order list  */
+check_boot_index(boot_index, _err);
+if (local_err) {
+goto out;
+}
+/* change bootindex to a new one */
+s->conf.bootindex = boot_index;
+
+if (s->scsi_dev) {
+object_property_set_int(OBJECT(s->scsi_dev), "bootindex", boot_index,
+_abort);
+}
+
+out:
+error_propagate(errp, local_err);
+}
+
+static void usb_msd_instance_init(Object *obj)
+{
+object_property_add(obj, "bootindex", "int32",
+

[PULL 05/13] usb: Document the missing -usbdevice options

2021-03-15 Thread Gerd Hoffmann
From: Thomas Huth 

There are some more -usbdevice options that have never been mentioned
in the documentation. Now that we removed -usbdevice from the list
of deprecated features again, we should document them properly.

While we're at it, also sort them alphabetically.

Signed-off-by: Thomas Huth 
Message-Id: <20210310173323.1422754-5-th...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 qemu-options.hx | 35 +--
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 622d3bfa5a7d..fe83ea09b25e 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1705,7 +1705,7 @@ ERST
 
 DEFHEADING()
 
-DEFHEADING(USB options:)
+DEFHEADING(USB convenience options:)
 
 DEF("usb", 0, QEMU_OPTION_usb,
 "-usbenable on-board USB host controller (if not enabled by 
default)\n",
@@ -1723,9 +1723,31 @@ DEF("usbdevice", HAS_ARG, QEMU_OPTION_usbdevice,
 QEMU_ARCH_ALL)
 SRST
 ``-usbdevice devname``
-Add the USB device devname. Note that this option is deprecated,
-please use ``-device usb-...`` instead. See the chapter about
+Add the USB device devname, and enable an on-board USB controller
+if possible and necessary (just like it can be done via
+``-machine usb=on``). Note that this option is mainly intended for
+the user's convenience only. More fine-grained control can be
+achieved by selecting a USB host controller (if necessary) and the
+desired USB device via the ``-device`` option instead. For example,
+instead of using ``-usbdevice mouse`` it is possible to use
+``-device qemu-xhci -device usb-mouse`` to connect the USB mouse
+to a USB 3.0 controller instead (at least on machines that support
+PCI and do not have an USB controller enabled by default yet).
+For more details, see the chapter about
 :ref:`Connecting USB devices` in the System Emulation Users Guide.
+Possible devices for devname are:
+
+``braille``
+Braille device. This will use BrlAPI to display the braille
+output on a real or fake device (i.e. it also creates a
+corresponding ``braille`` chardev automatically beside the
+``usb-braille`` USB device).
+
+``ccid``
+Smartcard reader device
+
+``keyboard``
+Standard USB keyboard. Will override the PS/2 keyboard (if present).
 
 ``mouse``
 Virtual Mouse. This will override the PS/2 mouse emulation when
@@ -1737,9 +1759,10 @@ SRST
 position without having to grab the mouse. Also overrides the
 PS/2 mouse emulation when activated.
 
-``braille``
-Braille device. This will use BrlAPI to display the braille
-output on a real or fake device.
+``wacom-tablet``
+Wacom PenPartner USB tablet.
+
+
 ERST
 
 DEFHEADING()
-- 
2.29.2



[PULL 10/13] usb/storage: move usb-bot device to separate source file

2021-03-15 Thread Gerd Hoffmann
Pure code motion, no functional change.

Signed-off-by: Gerd Hoffmann 
Message-Id: <20210312090425.772900-3-kra...@redhat.com>
---
 hw/usb/dev-storage-bot.c | 63 
 hw/usb/dev-storage.c | 42 ---
 hw/usb/meson.build   |  1 +
 3 files changed, 64 insertions(+), 42 deletions(-)
 create mode 100644 hw/usb/dev-storage-bot.c

diff --git a/hw/usb/dev-storage-bot.c b/hw/usb/dev-storage-bot.c
new file mode 100644
index ..6aad026d1133
--- /dev/null
+++ b/hw/usb/dev-storage-bot.c
@@ -0,0 +1,63 @@
+/*
+ * USB Mass Storage Device emulation
+ *
+ * Copyright (c) 2006 CodeSourcery.
+ * Written by Paul Brook
+ *
+ * This code is licensed under the LGPL.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/typedefs.h"
+#include "qapi/error.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
+#include "hw/usb/msd.h"
+
+static const struct SCSIBusInfo usb_msd_scsi_info_bot = {
+.tcq = false,
+.max_target = 0,
+.max_lun = 15,
+
+.transfer_data = usb_msd_transfer_data,
+.complete = usb_msd_command_complete,
+.cancel = usb_msd_request_cancelled,
+.load_request = usb_msd_load_request,
+};
+
+static void usb_msd_bot_realize(USBDevice *dev, Error **errp)
+{
+MSDState *s = USB_STORAGE_DEV(dev);
+DeviceState *d = DEVICE(dev);
+
+usb_desc_create_serial(dev);
+usb_desc_init(dev);
+if (d->hotplugged) {
+s->dev.auto_attach = 0;
+}
+
+scsi_bus_new(>bus, sizeof(s->bus), DEVICE(dev),
+ _msd_scsi_info_bot, NULL);
+usb_msd_handle_reset(dev);
+}
+
+static void usb_msd_class_bot_initfn(ObjectClass *klass, void *data)
+{
+USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+uc->realize = usb_msd_bot_realize;
+uc->attached_settable = true;
+}
+
+static const TypeInfo bot_info = {
+.name  = "usb-bot",
+.parent= TYPE_USB_STORAGE,
+.class_init= usb_msd_class_bot_initfn,
+};
+
+static void register_types(void)
+{
+type_register_static(_info);
+}
+
+type_init(register_types)
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 027e29dda3f5..3e613ecc886b 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -551,17 +551,6 @@ static const struct SCSIBusInfo usb_msd_scsi_info_storage 
= {
 .load_request = usb_msd_load_request,
 };
 
-static const struct SCSIBusInfo usb_msd_scsi_info_bot = {
-.tcq = false,
-.max_target = 0,
-.max_lun = 15,
-
-.transfer_data = usb_msd_transfer_data,
-.complete = usb_msd_command_complete,
-.cancel = usb_msd_request_cancelled,
-.load_request = usb_msd_load_request,
-};
-
 static void usb_msd_storage_realize(USBDevice *dev, Error **errp)
 {
 MSDState *s = USB_STORAGE_DEV(dev);
@@ -613,22 +602,6 @@ static void usb_msd_storage_realize(USBDevice *dev, Error 
**errp)
 s->scsi_dev = scsi_dev;
 }
 
-static void usb_msd_bot_realize(USBDevice *dev, Error **errp)
-{
-MSDState *s = USB_STORAGE_DEV(dev);
-DeviceState *d = DEVICE(dev);
-
-usb_desc_create_serial(dev);
-usb_desc_init(dev);
-if (d->hotplugged) {
-s->dev.auto_attach = 0;
-}
-
-scsi_bus_new(>bus, sizeof(s->bus), DEVICE(dev),
- _msd_scsi_info_bot, NULL);
-usb_msd_handle_reset(dev);
-}
-
 static const VMStateDescription vmstate_usb_msd = {
 .name = "usb-storage",
 .version_id = 1,
@@ -734,14 +707,6 @@ static void usb_msd_instance_init(Object *obj)
 object_property_set_int(obj, "bootindex", -1, NULL);
 }
 
-static void usb_msd_class_bot_initfn(ObjectClass *klass, void *data)
-{
-USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
-
-uc->realize = usb_msd_bot_realize;
-uc->attached_settable = true;
-}
-
 static const TypeInfo msd_info = {
 .name  = "usb-storage",
 .parent= TYPE_USB_STORAGE,
@@ -749,17 +714,10 @@ static const TypeInfo msd_info = {
 .instance_init = usb_msd_instance_init,
 };
 
-static const TypeInfo bot_info = {
-.name  = "usb-bot",
-.parent= TYPE_USB_STORAGE,
-.class_init= usb_msd_class_bot_initfn,
-};
-
 static void usb_msd_register_types(void)
 {
 type_register_static(_storage_dev_type_info);
 type_register_static(_info);
-type_register_static(_info);
 }
 
 type_init(usb_msd_register_types)
diff --git a/hw/usb/meson.build b/hw/usb/meson.build
index 6e3159798e93..518cd1fbbbea 100644
--- a/hw/usb/meson.build
+++ b/hw/usb/meson.build
@@ -41,6 +41,7 @@ softmmu_ss.add(when: 'CONFIG_USB', if_true: 
files('dev-hub.c'))
 softmmu_ss.add(when: 'CONFIG_USB', if_true: files('dev-hid.c'))
 softmmu_ss.add(when: 'CONFIG_USB_TABLET_WACOM', if_true: files('dev-wacom.c'))
 softmmu_ss.add(when: 'CONFIG_USB_STORAGE_BOT', if_true: files('dev-storage.c'))
+softmmu_ss.add(when: 'CONFIG_USB_STORAGE_BOT', if_true: 
files('dev-

[PULL 12/13] usb/storage: add kconfig symbols

2021-03-15 Thread Gerd Hoffmann
Add new kconfig symbols so usb-storage and usb-bot can
be enabled or disabled individually at build time.

Signed-off-by: Gerd Hoffmann 
Message-Id: <20210312090425.772900-5-kra...@redhat.com>
---
 hw/usb/Kconfig | 13 -
 hw/usb/meson.build |  4 ++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/hw/usb/Kconfig b/hw/usb/Kconfig
index 40093d7ea6bf..53f8283ffdc1 100644
--- a/hw/usb/Kconfig
+++ b/hw/usb/Kconfig
@@ -66,11 +66,22 @@ config USB_TABLET_WACOM
 default y
 depends on USB
 
+config USB_STORAGE_CORE
+bool
+depends on USB
+select SCSI
+
+config USB_STORAGE_CLASSIC
+bool
+default y
+depends on USB
+select USB_STORAGE_CORE
+
 config USB_STORAGE_BOT
 bool
 default y
 depends on USB
-select SCSI
+select USB_STORAGE_CORE
 
 config USB_STORAGE_UAS
 bool
diff --git a/hw/usb/meson.build b/hw/usb/meson.build
index 9e4da68e3b6c..fb7a74e73ae8 100644
--- a/hw/usb/meson.build
+++ b/hw/usb/meson.build
@@ -40,9 +40,9 @@ specific_ss.add(when: 'CONFIG_XLNX_USB_SUBSYS', if_true: 
files('xlnx-usb-subsyst
 softmmu_ss.add(when: 'CONFIG_USB', if_true: files('dev-hub.c'))
 softmmu_ss.add(when: 'CONFIG_USB', if_true: files('dev-hid.c'))
 softmmu_ss.add(when: 'CONFIG_USB_TABLET_WACOM', if_true: files('dev-wacom.c'))
-softmmu_ss.add(when: 'CONFIG_USB_STORAGE_BOT', if_true: files('dev-storage.c'))
+softmmu_ss.add(when: 'CONFIG_USB_STORAGE_CORE', if_true: 
files('dev-storage.c'))
 softmmu_ss.add(when: 'CONFIG_USB_STORAGE_BOT', if_true: 
files('dev-storage-bot.c'))
-softmmu_ss.add(when: 'CONFIG_USB_STORAGE_BOT', if_true: 
files('dev-storage-classic.c'))
+softmmu_ss.add(when: 'CONFIG_USB_STORAGE_CLASSIC', if_true: 
files('dev-storage-classic.c'))
 softmmu_ss.add(when: 'CONFIG_USB_STORAGE_UAS', if_true: files('dev-uas.c'))
 softmmu_ss.add(when: 'CONFIG_USB_AUDIO', if_true: files('dev-audio.c'))
 softmmu_ss.add(when: 'CONFIG_USB_SERIAL', if_true: files('dev-serial.c'))
-- 
2.29.2



[PULL 09/13] usb/storage: move declarations to usb/msd.h header

2021-03-15 Thread Gerd Hoffmann
In preparation for splitting the usb-storage.c file move
declarations to the new usb/msd.h header file.

Signed-off-by: Gerd Hoffmann 
Message-Id: <20210312090425.772900-2-kra...@redhat.com>
---
 include/hw/usb/msd.h | 54 
 hw/usb/dev-storage.c | 48 +--
 2 files changed, 60 insertions(+), 42 deletions(-)
 create mode 100644 include/hw/usb/msd.h

diff --git a/include/hw/usb/msd.h b/include/hw/usb/msd.h
new file mode 100644
index ..7538c54569bf
--- /dev/null
+++ b/include/hw/usb/msd.h
@@ -0,0 +1,54 @@
+/*
+ * USB Mass Storage Device emulation
+ *
+ * Copyright (c) 2006 CodeSourcery.
+ * Written by Paul Brook
+ *
+ * This code is licensed under the LGPL.
+ */
+
+#include "hw/usb.h"
+#include "hw/scsi/scsi.h"
+
+enum USBMSDMode {
+USB_MSDM_CBW, /* Command Block.  */
+USB_MSDM_DATAOUT, /* Transfer data to device.  */
+USB_MSDM_DATAIN, /* Transfer data from device.  */
+USB_MSDM_CSW /* Command Status.  */
+};
+
+struct usb_msd_csw {
+uint32_t sig;
+uint32_t tag;
+uint32_t residue;
+uint8_t status;
+};
+
+struct MSDState {
+USBDevice dev;
+enum USBMSDMode mode;
+uint32_t scsi_off;
+uint32_t scsi_len;
+uint32_t data_len;
+struct usb_msd_csw csw;
+SCSIRequest *req;
+SCSIBus bus;
+/* For async completion.  */
+USBPacket *packet;
+/* usb-storage only */
+BlockConf conf;
+bool removable;
+bool commandlog;
+SCSIDevice *scsi_dev;
+};
+
+typedef struct MSDState MSDState;
+#define TYPE_USB_STORAGE "usb-storage-dev"
+DECLARE_INSTANCE_CHECKER(MSDState, USB_STORAGE_DEV,
+ TYPE_USB_STORAGE)
+
+void usb_msd_transfer_data(SCSIRequest *req, uint32_t len);
+void usb_msd_command_complete(SCSIRequest *req, size_t resid);
+void usb_msd_request_cancelled(SCSIRequest *req);
+void *usb_msd_load_request(QEMUFile *f, SCSIRequest *req);
+void usb_msd_handle_reset(USBDevice *dev);
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index a5f76fc00120..027e29dda3f5 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -14,6 +14,7 @@
 #include "qemu/option.h"
 #include "qemu/config-file.h"
 #include "hw/usb.h"
+#include "hw/usb/msd.h"
 #include "desc.h"
 #include "hw/qdev-properties.h"
 #include "hw/scsi/scsi.h"
@@ -29,43 +30,6 @@
 #define MassStorageReset  0xff
 #define GetMaxLun 0xfe
 
-enum USBMSDMode {
-USB_MSDM_CBW, /* Command Block.  */
-USB_MSDM_DATAOUT, /* Transfer data to device.  */
-USB_MSDM_DATAIN, /* Transfer data from device.  */
-USB_MSDM_CSW /* Command Status.  */
-};
-
-struct usb_msd_csw {
-uint32_t sig;
-uint32_t tag;
-uint32_t residue;
-uint8_t status;
-};
-
-struct MSDState {
-USBDevice dev;
-enum USBMSDMode mode;
-uint32_t scsi_off;
-uint32_t scsi_len;
-uint32_t data_len;
-struct usb_msd_csw csw;
-SCSIRequest *req;
-SCSIBus bus;
-/* For async completion.  */
-USBPacket *packet;
-/* usb-storage only */
-BlockConf conf;
-bool removable;
-bool commandlog;
-SCSIDevice *scsi_dev;
-};
-typedef struct MSDState MSDState;
-
-#define TYPE_USB_STORAGE "usb-storage-dev"
-DECLARE_INSTANCE_CHECKER(MSDState, USB_STORAGE_DEV,
- TYPE_USB_STORAGE)
-
 struct usb_msd_cbw {
 uint32_t sig;
 uint32_t tag;
@@ -259,7 +223,7 @@ static void usb_msd_packet_complete(MSDState *s)
 usb_packet_complete(>dev, p);
 }
 
-static void usb_msd_transfer_data(SCSIRequest *req, uint32_t len)
+void usb_msd_transfer_data(SCSIRequest *req, uint32_t len)
 {
 MSDState *s = DO_UPCAST(MSDState, dev.qdev, req->bus->qbus.parent);
 USBPacket *p = s->packet;
@@ -277,7 +241,7 @@ static void usb_msd_transfer_data(SCSIRequest *req, 
uint32_t len)
 }
 }
 
-static void usb_msd_command_complete(SCSIRequest *req, size_t resid)
+void usb_msd_command_complete(SCSIRequest *req, size_t resid)
 {
 MSDState *s = DO_UPCAST(MSDState, dev.qdev, req->bus->qbus.parent);
 USBPacket *p = s->packet;
@@ -320,7 +284,7 @@ static void usb_msd_command_complete(SCSIRequest *req, 
size_t resid)
 s->req = NULL;
 }
 
-static void usb_msd_request_cancelled(SCSIRequest *req)
+void usb_msd_request_cancelled(SCSIRequest *req)
 {
 MSDState *s = DO_UPCAST(MSDState, dev.qdev, req->bus->qbus.parent);
 
@@ -337,7 +301,7 @@ static void usb_msd_request_cancelled(SCSIRequest *req)
 }
 }
 
-static void usb_msd_handle_reset(USBDevice *dev)
+void usb_msd_handle_reset(USBDevice *dev)
 {
 MSDState *s = (MSDState *)dev;
 
@@ -565,7 +529,7 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket 
*p)
 }
 }
 
-static void *usb_msd_load_request(QEMUFile *f, SCSIRequest *req)
+void *usb_msd_load_request(QEMUFile *f, SCSIRequest *req)
 {
 MSDState *s = DO_UPCAST(MSDState, dev.qdev, req->bus->qbus.parent);
 
-- 
2.29.2



[PULL 13/13] usb/storage: clear csw on reset

2021-03-15 Thread Gerd Hoffmann
Stale data in csw (specifically residue) can confuse the state machine
and allows the guest trigger an assert().  So clear csw on reset to
avoid this happening in case the guest resets the device in the middle
of a request.

Buglink: https://bugs.launchpad.net/qemu/+bug/1523811
Signed-off-by: Gerd Hoffmann 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20210312094954.796799-1-kra...@redhat.com>
---
 hw/usb/dev-storage.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 7b587ad051ff..dca62d544fe9 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -313,6 +313,7 @@ void usb_msd_handle_reset(USBDevice *dev)
 usb_msd_packet_complete(s);
 }
 
+memset(>csw, 0, sizeof(s->csw));
 s->mode = USB_MSDM_CBW;
 }
 
-- 
2.29.2



[PULL 06/13] hw/southbridge: Add missing Kconfig dependency VT82C686 on USB_UHCI

2021-03-15 Thread Gerd Hoffmann
From: Philippe Mathieu-Daudé 

The VT82C686 south bridge provides a USB UHCI bus via a PCI function.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: BALATON Zoltan 
Message-Id: <20210309190802.830969-2-f4...@amsat.org>
Signed-off-by: Gerd Hoffmann 
---
 hw/isa/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/isa/Kconfig b/hw/isa/Kconfig
index c7f07854f7e7..2691eae2f0c6 100644
--- a/hw/isa/Kconfig
+++ b/hw/isa/Kconfig
@@ -47,6 +47,7 @@ config VT82C686
 select ACPI_SMBUS
 select SERIAL_ISA
 select FDC
+select USB_UHCI
 
 config SMC37C669
 bool
-- 
2.29.2



[PULL 07/13] hw/usb/hcd-uhci: Expose generic prototypes to local header

2021-03-15 Thread Gerd Hoffmann
From: Philippe Mathieu-Daudé 

Extract generic UHCI prototypes into a new "hcd-uhci.h" local
header so we can reuse them in other units.

Signed-off-by: Philippe Mathieu-Daudé 
Message-Id: <20210309190802.830969-3-f4...@amsat.org>
Signed-off-by: Gerd Hoffmann 
---
 hw/usb/hcd-uhci.h | 93 +++
 hw/usb/hcd-uhci.c | 60 ++
 2 files changed, 96 insertions(+), 57 deletions(-)
 create mode 100644 hw/usb/hcd-uhci.h

diff --git a/hw/usb/hcd-uhci.h b/hw/usb/hcd-uhci.h
new file mode 100644
index ..e61d8fcb1921
--- /dev/null
+++ b/hw/usb/hcd-uhci.h
@@ -0,0 +1,93 @@
+/*
+ * USB UHCI controller emulation
+ *
+ * Copyright (c) 2005 Fabrice Bellard
+ *
+ * Copyright (c) 2008 Max Krasnyansky
+ * Magor rewrite of the UHCI data structures parser and frame processor
+ * Support for fully async operation and multiple outstanding transactions
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef HW_USB_HCD_UHCI_H
+#define HW_USB_HCD_UHCI_H
+
+#include "exec/memory.h"
+#include "qemu/timer.h"
+#include "hw/pci/pci.h"
+#include "hw/usb.h"
+
+typedef struct UHCIQueue UHCIQueue;
+
+#define NB_PORTS 2
+
+typedef struct UHCIPort {
+USBPort port;
+uint16_t ctrl;
+} UHCIPort;
+
+typedef struct UHCIState {
+PCIDevice dev;
+MemoryRegion io_bar;
+USBBus bus; /* Note unused when we're a companion controller */
+uint16_t cmd; /* cmd register */
+uint16_t status;
+uint16_t intr; /* interrupt enable register */
+uint16_t frnum; /* frame number */
+uint32_t fl_base_addr; /* frame list base address */
+uint8_t sof_timing;
+uint8_t status2; /* bit 0 and 1 are used to generate UHCI_STS_USBINT */
+int64_t expire_time;
+QEMUTimer *frame_timer;
+QEMUBH *bh;
+uint32_t frame_bytes;
+uint32_t frame_bandwidth;
+bool completions_only;
+UHCIPort ports[NB_PORTS];
+
+/* Interrupts that should be raised at the end of the current frame.  */
+uint32_t pending_int_mask;
+
+/* Active packets */
+QTAILQ_HEAD(, UHCIQueue) queues;
+uint8_t num_ports_vmstate;
+
+/* Properties */
+char *masterbus;
+uint32_t firstport;
+uint32_t maxframes;
+} UHCIState;
+
+#define TYPE_UHCI "pci-uhci-usb"
+DECLARE_INSTANCE_CHECKER(UHCIState, UHCI, TYPE_UHCI)
+
+typedef struct UHCIInfo {
+const char *name;
+uint16_t   vendor_id;
+uint16_t   device_id;
+uint8_trevision;
+uint8_tirq_pin;
+void   (*realize)(PCIDevice *dev, Error **errp);
+bool   unplug;
+} UHCIInfo;
+
+void uhci_data_class_init(ObjectClass *klass, void *data);
+void usb_uhci_common_realize(PCIDevice *dev, Error **errp);
+
+#endif
diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index 5969eb86b31b..d6338c33d863 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -40,6 +40,7 @@
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
 #include "qom/object.h"
+#include "hcd-uhci.h"
 
 #define FRAME_TIMER_FREQ 1000
 
@@ -50,8 +51,6 @@
 
 #define MAX_FRAMES_PER_TICK(QH_VALID / 2)
 
-#define NB_PORTS 2
-
 enum {
 TD_RESULT_STOP_FRAME = 10,
 TD_RESULT_COMPLETE,
@@ -62,20 +61,8 @@ enum {
 
 typedef struct UHCIState UHCIState;
 typedef struct UHCIAsync UHCIAsync;
-typedef struct UHCIQueue UHCIQueue;
-typedef struct UHCIInfo UHCIInfo;
 typedef struct UHCIPCIDeviceClass UHCIPCIDeviceClass;
 
-struct UHCIInfo {
-const char *name;
-uint16_t   vendor_id;
-uint16_t   device_id;
-uint8_trevision;
-uint8_tirq_pin;
-void   (*realize)(PCIDevice *dev, Error **errp);
-bool   unplug;
-};
-
 struct UHCIPCIDeviceClass {
 PCIDeviceClass parent_class;
 UHCIInfo   info;
@@ -107,43 +94,6 @@ struct UHCIQueue {
 int8_tvalid;
 };
 
-typedef struct UHCIPort {
-USBP

[PULL 04/13] usb: Un-deprecate -usbdevice (except for -usbdevice audio which gets removed)

2021-03-15 Thread Gerd Hoffmann
From: Thomas Huth 

When trying to remove the -usbdevice option, there were complaints that
"-usbdevice braille" is still a very useful shortcut for some people.
Thus we never remove this option. Since it's not such a big burden to
keep it around, and it's also convenient in the sense that you don't
have to worry to enable a host controller explicitly with this option,
we should remove it from he deprecation list again.

However, there is one exception: "-usbdevice audio" should go away, since
audio devices without "audiodev=..." parameter are also on the deprecation
list and you cannot use "-usbdevice audio" with "audiodev".

Signed-off-by: Thomas Huth 
Message-Id: <20210310173323.1422754-4-th...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 hw/usb/dev-audio.c   | 1 -
 softmmu/vl.c | 2 --
 docs/system/deprecated.rst   | 9 -
 docs/system/removed-features.rst | 8 
 4 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
index e1486f81e06b..f5cb2467929a 100644
--- a/hw/usb/dev-audio.c
+++ b/hw/usb/dev-audio.c
@@ -1024,7 +1024,6 @@ static const TypeInfo usb_audio_info = {
 static void usb_audio_register_types(void)
 {
 type_register_static(_audio_info);
-usb_legacy_register(TYPE_USB_AUDIO, "audio", NULL);
 }
 
 type_init(usb_audio_register_types)
diff --git a/softmmu/vl.c b/softmmu/vl.c
index b7673b96134d..a750dae6b1ef 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3180,8 +3180,6 @@ void qemu_init(int argc, char **argv, char **envp)
 qemu_opts_parse_noisily(olist, "usb=on", false);
 break;
 case QEMU_OPTION_usbdevice:
-error_report("'-usbdevice' is deprecated, please use "
- "'-device usb-...' instead");
 olist = qemu_find_opts("machine");
 qemu_opts_parse_noisily(olist, "usb=on", false);
 add_device_config(DEV_USB, optarg);
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 5e3a31c12361..62a64a8c41e1 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -21,15 +21,6 @@ deprecated.
 System emulator command line arguments
 --
 
-``-usbdevice`` (since 2.10.0)
-'
-
-The ``-usbdevice DEV`` argument is now a synonym for setting
-the ``-device usb-DEV`` argument instead. The deprecated syntax
-would automatically enable USB support on the machine type.
-If using the new syntax, USB support must be explicitly
-enabled via the ``-machine usb=on`` argument.
-
 ``-drive file=json:{...{'driver':'file'}}`` (since 3.0)
 '''
 
diff --git a/docs/system/removed-features.rst b/docs/system/removed-features.rst
index 83148dcfda6a..82e7fcc51715 100644
--- a/docs/system/removed-features.rst
+++ b/docs/system/removed-features.rst
@@ -38,6 +38,14 @@ or ``-display default,show-cursor=on`` instead.
 QEMU 5.0 introduced an alternative syntax to specify the size of the 
translation
 block cache, ``-accel tcg,tb-size=``.
 
+``-usbdevice audio`` (removed in 6.0)
+'
+
+This option lacked the possibility to specify an audio backend device.
+Use ``-device usb-audio`` now instead (and specify a corresponding USB
+host controller or ``-usb`` if necessary).
+
+
 QEMU Machine Protocol (QMP) commands
 
 
-- 
2.29.2



[PULL 01/13] hw/usb/bus: Remove the "full-path" property

2021-03-15 Thread Gerd Hoffmann
From: Thomas Huth 

This property was only required for the pc-1.0 and earlier machine
types. Since these have been removed now, we can delete the property
as well.

Signed-off-by: Thomas Huth 
Message-Id: <20210302120152.118042-1-th...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 include/hw/usb.h | 1 -
 hw/usb/bus.c | 7 +--
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/include/hw/usb.h b/include/hw/usb.h
index abfbfc5284c2..9f42394efaea 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -216,7 +216,6 @@ struct USBEndpoint {
 };
 
 enum USBDeviceFlags {
-USB_DEV_FLAG_FULL_PATH,
 USB_DEV_FLAG_IS_HOST,
 USB_DEV_FLAG_MSOS_DESC_ENABLE,
 USB_DEV_FLAG_MSOS_DESC_IN_USE,
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 064f94e9c3cc..df7411fea8e4 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -19,8 +19,6 @@ static void usb_qdev_unrealize(DeviceState *qdev);
 static Property usb_props[] = {
 DEFINE_PROP_STRING("port", USBDevice, port_path),
 DEFINE_PROP_STRING("serial", USBDevice, serial),
-DEFINE_PROP_BIT("full-path", USBDevice, flags,
-USB_DEV_FLAG_FULL_PATH, true),
 DEFINE_PROP_BIT("msos-desc", USBDevice, flags,
 USB_DEV_FLAG_MSOS_DESC_ENABLE, true),
 DEFINE_PROP_STRING("pcap", USBDevice, pcap_filename),
@@ -596,11 +594,8 @@ static char *usb_get_dev_path(DeviceState *qdev)
 {
 USBDevice *dev = USB_DEVICE(qdev);
 DeviceState *hcd = qdev->parent_bus->parent;
-char *id = NULL;
+char *id = qdev_get_dev_path(hcd);
 
-if (dev->flags & (1 << USB_DEV_FLAG_FULL_PATH)) {
-id = qdev_get_dev_path(hcd);
-}
 if (id) {
 char *ret = g_strdup_printf("%s/%s", id, dev->port->path);
 g_free(id);
-- 
2.29.2



[PULL 03/13] usb: remove '-usbdevice u2f-key'

2021-03-15 Thread Gerd Hoffmann
From: Paolo Bonzini 

It never worked.

Signed-off-by: Paolo Bonzini 
Cc: Gerd Hoffmann 
Signed-off-by: Thomas Huth 
Message-Id: <20210310173323.1422754-3-th...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 hw/usb/u2f.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/hw/usb/u2f.c b/hw/usb/u2f.c
index bc09191f063e..56001249a449 100644
--- a/hw/usb/u2f.c
+++ b/hw/usb/u2f.c
@@ -346,7 +346,6 @@ static const TypeInfo u2f_key_info = {
 static void u2f_key_register_types(void)
 {
 type_register_static(_key_info);
-usb_legacy_register(TYPE_U2F_KEY, "u2f-key", NULL);
 }
 
 type_init(u2f_key_register_types)
-- 
2.29.2



[PULL 08/13] hw/usb: Extract VT82C686 UHCI PCI function into a new unit

2021-03-15 Thread Gerd Hoffmann
From: Philippe Mathieu-Daudé 

Extract the VT82C686 PCI UHCI function into a new unit so
it is only build when the VT82C686 south bridge is selected.

Signed-off-by: Philippe Mathieu-Daudé 
Message-Id: <20210309190802.830969-4-f4...@amsat.org>
Signed-off-by: Gerd Hoffmann 
---
 hw/usb/hcd-uhci.c  | 23 
 hw/usb/vt82c686-uhci-pci.c | 43 ++
 MAINTAINERS|  1 +
 hw/usb/meson.build |  1 +
 4 files changed, 45 insertions(+), 23 deletions(-)
 create mode 100644 hw/usb/vt82c686-uhci-pci.c

diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index d6338c33d863..0cb02a643214 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -1207,21 +1207,6 @@ void usb_uhci_common_realize(PCIDevice *dev, Error 
**errp)
 pci_register_bar(>dev, 4, PCI_BASE_ADDRESS_SPACE_IO, >io_bar);
 }
 
-static void usb_uhci_vt82c686b_realize(PCIDevice *dev, Error **errp)
-{
-UHCIState *s = UHCI(dev);
-uint8_t *pci_conf = s->dev.config;
-
-/* USB misc control 1/2 */
-pci_set_long(pci_conf + 0x40,0x1000);
-/* PM capability */
-pci_set_long(pci_conf + 0x80,0x00020001);
-/* USB legacy support  */
-pci_set_long(pci_conf + 0xc0,0x2000);
-
-usb_uhci_common_realize(dev, errp);
-}
-
 static void usb_uhci_exit(PCIDevice *dev)
 {
 UHCIState *s = UHCI(dev);
@@ -1318,14 +1303,6 @@ static UHCIInfo uhci_info[] = {
 .revision  = 0x01,
 .irq_pin   = 3,
 .unplug= true,
-},{
-.name  = "vt82c686b-usb-uhci",
-.vendor_id = PCI_VENDOR_ID_VIA,
-.device_id = PCI_DEVICE_ID_VIA_UHCI,
-.revision  = 0x01,
-.irq_pin   = 3,
-.realize   = usb_uhci_vt82c686b_realize,
-.unplug= true,
 },{
 .name  = "ich9-usb-uhci1", /* 00:1d.0 */
 .vendor_id = PCI_VENDOR_ID_INTEL,
diff --git a/hw/usb/vt82c686-uhci-pci.c b/hw/usb/vt82c686-uhci-pci.c
new file mode 100644
index ..b109c2160335
--- /dev/null
+++ b/hw/usb/vt82c686-uhci-pci.c
@@ -0,0 +1,43 @@
+#include "qemu/osdep.h"
+#include "hcd-uhci.h"
+
+static void usb_uhci_vt82c686b_realize(PCIDevice *dev, Error **errp)
+{
+UHCIState *s = UHCI(dev);
+uint8_t *pci_conf = s->dev.config;
+
+/* USB misc control 1/2 */
+pci_set_long(pci_conf + 0x40, 0x1000);
+/* PM capability */
+pci_set_long(pci_conf + 0x80, 0x00020001);
+/* USB legacy support  */
+pci_set_long(pci_conf + 0xc0, 0x2000);
+
+usb_uhci_common_realize(dev, errp);
+}
+
+static UHCIInfo uhci_info[] = {
+{
+.name  = "vt82c686b-usb-uhci",
+.vendor_id = PCI_VENDOR_ID_VIA,
+.device_id = PCI_DEVICE_ID_VIA_UHCI,
+.revision  = 0x01,
+.irq_pin   = 3,
+.realize   = usb_uhci_vt82c686b_realize,
+.unplug= true,
+}
+};
+
+static const TypeInfo vt82c686b_usb_uhci_type_info = {
+.parent = TYPE_UHCI,
+.name   = "vt82c686b-usb-uhci",
+.class_init = uhci_data_class_init,
+.class_data = uhci_info,
+};
+
+static void vt82c686b_usb_uhci_register_types(void)
+{
+type_register_static(_usb_uhci_type_info);
+}
+
+type_init(vt82c686b_usb_uhci_register_types)
diff --git a/MAINTAINERS b/MAINTAINERS
index 5ca3c9f851f9..b6ab3d25a751 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1180,6 +1180,7 @@ S: Odd Fixes
 F: hw/mips/fuloong2e.c
 F: hw/isa/vt82c686.c
 F: hw/pci-host/bonito.c
+F: hw/usb/vt82c686-uhci-pci.c
 F: include/hw/isa/vt82c686.h
 
 Loongson-3 virtual platforms
diff --git a/hw/usb/meson.build b/hw/usb/meson.build
index 653192cff6fa..6e3159798e93 100644
--- a/hw/usb/meson.build
+++ b/hw/usb/meson.build
@@ -32,6 +32,7 @@ softmmu_ss.add(when: 'CONFIG_USB_DWC3', if_true: 
files('hcd-dwc3.c'))
 softmmu_ss.add(when: 'CONFIG_TUSB6010', if_true: files('tusb6010.c'))
 softmmu_ss.add(when: 'CONFIG_IMX', if_true: files('chipidea.c'))
 softmmu_ss.add(when: 'CONFIG_IMX_USBPHY', if_true: files('imx-usb-phy.c'))
+softmmu_ss.add(when: 'CONFIG_VT82C686', if_true: files('vt82c686-uhci-pci.c'))
 specific_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: 
files('xlnx-versal-usb2-ctrl-regs.c'))
 specific_ss.add(when: 'CONFIG_XLNX_USB_SUBSYS', if_true: 
files('xlnx-usb-subsystem.c'))
 
-- 
2.29.2



[PULL 02/13] usb: remove support for -usbdevice parameters

2021-03-15 Thread Gerd Hoffmann
From: Paolo Bonzini 

No device needs them anymore and in fact they're undocumented.
Remove the code.  The only change in behavior is that "-usbdevice
braille:hello" now reports an error, which is a bugfix.

Signed-off-by: Paolo Bonzini 
Cc: Gerd Hoffmann 
Signed-off-by: Thomas Huth 
Message-Id: <20210310173323.1422754-2-th...@redhat.com>
Signed-off-by: Gerd Hoffmann 
---
 include/hw/usb.h|  2 +-
 hw/usb/bus.c| 32 +++-
 hw/usb/dev-serial.c |  2 +-
 3 files changed, 9 insertions(+), 27 deletions(-)

diff --git a/include/hw/usb.h b/include/hw/usb.h
index 9f42394efaea..436e07b30404 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -499,7 +499,7 @@ void usb_bus_new(USBBus *bus, size_t bus_size,
 void usb_bus_release(USBBus *bus);
 USBBus *usb_bus_find(int busnr);
 void usb_legacy_register(const char *typename, const char *usbdevice_name,
- USBDevice *(*usbdevice_init)(const char *params));
+ USBDevice *(*usbdevice_init)(void));
 USBDevice *usb_new(const char *name);
 bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, Error **errp);
 USBDevice *usb_create_simple(USBBus *bus, const char *name);
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index df7411fea8e4..07083349f51b 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -310,13 +310,13 @@ typedef struct LegacyUSBFactory
 {
 const char *name;
 const char *usbdevice_name;
-USBDevice *(*usbdevice_init)(const char *params);
+USBDevice *(*usbdevice_init)(void);
 } LegacyUSBFactory;
 
 static GSList *legacy_usb_factory;
 
 void usb_legacy_register(const char *typename, const char *usbdevice_name,
- USBDevice *(*usbdevice_init)(const char *params))
+ USBDevice *(*usbdevice_init)(void))
 {
 if (usbdevice_name) {
 LegacyUSBFactory *f = g_malloc0(sizeof(*f));
@@ -658,27 +658,17 @@ void hmp_info_usb(Monitor *mon, const QDict *qdict)
 }
 
 /* handle legacy -usbdevice cmd line option */
-USBDevice *usbdevice_create(const char *cmdline)
+USBDevice *usbdevice_create(const char *driver)
 {
 USBBus *bus = usb_bus_find(-1 /* any */);
 LegacyUSBFactory *f = NULL;
 Error *err = NULL;
 GSList *i;
-char driver[32];
-const char *params;
-int len;
 USBDevice *dev;
 
-params = strchr(cmdline,':');
-if (params) {
-params++;
-len = params - cmdline;
-if (len > sizeof(driver))
-len = sizeof(driver);
-pstrcpy(driver, len, cmdline);
-} else {
-params = "";
-pstrcpy(driver, sizeof(driver), cmdline);
+if (strchr(driver, ':')) {
+error_report("usbdevice parameters are not supported anymore");
+return NULL;
 }
 
 for (i = legacy_usb_factory; i; i = i->next) {
@@ -702,15 +692,7 @@ USBDevice *usbdevice_create(const char *cmdline)
 return NULL;
 }
 
-if (f->usbdevice_init) {
-dev = f->usbdevice_init(params);
-} else {
-if (*params) {
-error_report("usbdevice %s accepts no params", driver);
-return NULL;
-}
-dev = usb_new(f->name);
-}
+dev = f->usbdevice_init ? f->usbdevice_init() : usb_new(f->name);
 if (!dev) {
 error_report("Failed to create USB device '%s'", f->name);
 return NULL;
diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
index b58c4eb90822..63047d79cfd1 100644
--- a/hw/usb/dev-serial.c
+++ b/hw/usb/dev-serial.c
@@ -614,7 +614,7 @@ static void usb_serial_realize(USBDevice *dev, Error **errp)
 s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
 }
 
-static USBDevice *usb_braille_init(const char *unused)
+static USBDevice *usb_braille_init(void)
 {
 USBDevice *dev;
 Chardev *cdrv;
-- 
2.29.2



[PULL 00/13] Usb 20210315 patches

2021-03-15 Thread Gerd Hoffmann
The following changes since commit 6157b0e19721aadb4c7fdcfe57b2924af6144b14:

  Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-6.0-pull-=
request' into staging (2021-03-14 17:47:49 +)

are available in the Git repository at:

  git://git.kraxel.org/qemu tags/usb-20210315-pull-request

for you to fetch changes up to 39912c14da07a2dbc73854addcfa0a42596340ac:

  usb/storage: clear csw on reset (2021-03-15 17:01:17 +0100)


usb: -usbdevice cleanup and un-deprecation.
usb: split usb-storage.
usb: misc fixes and cleanups.



Gerd Hoffmann (5):
  usb/storage: move declarations to usb/msd.h header
  usb/storage: move usb-bot device to separate source file
  usb/storage move usb-storage device to separate source file
  usb/storage: add kconfig symbols
  usb/storage: clear csw on reset

Paolo Bonzini (2):
  usb: remove support for -usbdevice parameters
  usb: remove '-usbdevice u2f-key'

Philippe Mathieu-Daud=C3=A9 (3):
  hw/southbridge: Add missing Kconfig dependency VT82C686 on USB_UHCI
  hw/usb/hcd-uhci: Expose generic prototypes to local header
  hw/usb: Extract VT82C686 UHCI PCI function into a new unit

Thomas Huth (3):
  hw/usb/bus: Remove the "full-path" property
  usb: Un-deprecate -usbdevice (except for -usbdevice audio which gets
removed)
  usb: Document the missing -usbdevice options

 hw/usb/hcd-uhci.h|  93 +
 include/hw/usb.h |   3 +-
 include/hw/usb/msd.h |  54 
 hw/usb/bus.c |  39 ++
 hw/usb/dev-audio.c   |   1 -
 hw/usb/dev-serial.c  |   2 +-
 hw/usb/dev-storage-bot.c |  63 +
 hw/usb/dev-storage-classic.c | 156 +
 hw/usb/dev-storage.c | 226 +--
 hw/usb/hcd-uhci.c|  83 +---
 hw/usb/u2f.c |   1 -
 hw/usb/vt82c686-uhci-pci.c   |  43 ++
 softmmu/vl.c |   2 -
 MAINTAINERS  |   1 +
 docs/system/deprecated.rst   |   9 --
 docs/system/removed-features.rst |   8 ++
 hw/isa/Kconfig   |   1 +
 hw/usb/Kconfig   |  13 +-
 hw/usb/meson.build   |   5 +-
 qemu-options.hx  |  35 -
 20 files changed, 484 insertions(+), 354 deletions(-)
 create mode 100644 hw/usb/hcd-uhci.h
 create mode 100644 include/hw/usb/msd.h
 create mode 100644 hw/usb/dev-storage-bot.c
 create mode 100644 hw/usb/dev-storage-classic.c
 create mode 100644 hw/usb/vt82c686-uhci-pci.c

--=20
2.29.2




Re: [PATCH v2 0/3] ui: add support for 'secret' object to provide VNC/SPICE passwords

2021-03-11 Thread Gerd Hoffmann
On Thu, Mar 11, 2021 at 11:43:40AM +, Daniel P. Berrangé wrote:
> This fixes a long standing limitation of the VNC/SPICE code which was
> unable to securely accept passswords on the CLI, instead requiring use
> of separate monitor commands after startup.
> 
> In v2:
> 
>  - Dropped patch removing ACL commands, as it will move to a bigger
>deprecation cleanup series
>  - Rebased and resolved conflicts

Added to UI queue.

thanks,
  Gerd



Re: [PATCH 0/4] ui: add support for 'secret' object to provide VNC/SPICE passwords

2021-03-11 Thread Gerd Hoffmann
On Thu, Mar 11, 2021 at 10:37:45AM +, Daniel P. Berrangé wrote:
> Ping

Looks good but doesn't apply cleanly, can you rebase?

(current ui queue is gitlab.com/kraxel/qemu queue/ui, there are no
spice/vnc changes queued so it probably doesn't make a difference
compared to latest master)

take care,
  Gerd



Re: [PATCH 4/4] hw/usb/bus: Remove the "full-path" property

2021-02-05 Thread Gerd Hoffmann
On Thu, Feb 04, 2021 at 04:51:39PM +0100, Thomas Huth wrote:
> On 04/02/2021 09.36, Gerd Hoffmann wrote:
> >Hi,
> > 
> > >   enum USBDeviceFlags {
> > > -USB_DEV_FLAG_FULL_PATH,
> > > +USB_DEV_FLAG_FULL_PATH, /* unused since QEMU v6.0 */
> > 
> > Why not just drop it?  Any remaining users?
> 
> I didn't want to change the values of the other members of the enum ...

This should be purely internal to qemu hw/usb and not some kind of abi,
so changing the values shouldn't break anything ...

take care,
  Gerd



Re: [PATCH 4/4] hw/usb/bus: Remove the "full-path" property

2021-02-04 Thread Gerd Hoffmann
  Hi,

>  enum USBDeviceFlags {
> -USB_DEV_FLAG_FULL_PATH,
> +USB_DEV_FLAG_FULL_PATH, /* unused since QEMU v6.0 */

Why not just drop it?  Any remaining users?

take care,
  Gerd



Re: [PATCH 00/18] qapi/qom: QAPIfy object-add

2020-12-02 Thread Gerd Hoffmann
  Hi,

> It would be much nicer to do the wrapper the other way round, i.e.
> setting properties before the device is realized would update a
> configuration struct and realize would then call .create() with that
> struct. To me, this sounds much harder, though also a more useful state.

Well, in some places we already have separate config structs.  We have
NICConf for example, which is typically used like this:

struct USBNetState {
   USBDevice dev;
   [ ... ]
   NICConf conf;
   [ ... ]
};

and

static Property net_properties[] = {
DEFINE_NIC_PROPERTIES(USBNetState, conf),
DEFINE_PROP_END_OF_LIST(),
};

So I think we could:

  (1) move *all* properties into structs.
  (2) generate those structs from qapi schemas.
  (3) generate Property lists (or functions with
  object_class_property_add_*() calls) from qapi
  schema.

We could then convert devices one-by-one without breaking anything
or needing two code paths essentially doing the same thing in two
different ways.

take care,
  Gerd



Re: [PATCH 1/1] QEMU: support USB cdrom devices

2020-09-08 Thread Gerd Hoffmann
  Hi,

> >> Also "info usb" just shows a single device. I just copied these lines
> >> from a normal libvirt SCSI setup with two cdroms.
> > 
> > That is normal, it actually is only one usb device after all ;)
> 
> I was referring to the posted usb-bot example, where "your" docs
> (/docs/usb-storage.txt) says it supports multiple LUNs, so I was
> wondering, how these would be exposed on the USB bus.

You can't see that on the USB bus.  usb-bot/usb-storage is a scsi host
adapter, with some limitations (only one target, 15 luns max and luns
can't be sparse).  You just have to set the LUN in the scsi commands to
address the device you want.

> All fine. I've spent my time on this. I just want to fix my LibreOffice
> Windows Arm64 cross-build and need an install to debug my obviously
> existing errors, but the current Windows installer ISOs even break
> somewhere in the initial ramdisk setup in QEMU and the older versions
> have timeouts, if current uup-based images are even correctly generated
> on Linux, which I have no way to verify.

FYI; You can simply copy all the files from the iso to a (virtual) usb
stick and use that to boot the windows installer.

take care,
  Gerd



Re: [PATCH 1/1] QEMU: support USB cdrom devices

2020-09-07 Thread Gerd Hoffmann
  Hi,

> -device nec-usb-xhci,id=xhci \
> -device usb-bot,id=scsi0,bus=xhci.0 \
> -device
> scsi-cd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,device_id=drive-scsi0-0-0-0,drive=libvirt-1-format,id=scsi0-0-0-0,bootindex=1
> \
> -device
> scsi-cd,bus=scsi0.0,channel=0,scsi-id=0,lun=1,device_id=drive-scsi0-0-0-1,drive=libvirt-1-format,id=scsi0-0-0-1
> \
> 
> which starts, but gives me a "Synchronous Exception" from the TianoCore
> firmware, which I often saw with PCI enumeration problems.

Hmm, firmware bug?  Does seabios work?

> Also "info usb" just shows a single device. I just copied these lines
> from a normal libvirt SCSI setup with two cdroms.

That is normal, it actually is only one usb device after all ;)

> But compared to my small patch with the usb-storage based USB CDROM,
> this looks like a much larger change and a lot of work implement.

Yes.

As far I know libvirt wants move away from the old syntax and shift to
use -blockdev more, not the other way around.

> 1. doing this transparently with a controller per device, just like the
> usb-storage controller does internally (ok - it's just a scsi-cd there),
> even if the usb-bot supports multiple LUNs. Guess multiple LUNs would
> act like an USB hub?

usb-storage simply doesn't support multiple LUNs, so when going that
route you can completely ignore the multiple LUN case.

> 2. invalidating the cdrom with USB addresses configurations and exposing
> the controller in the XML. This seems easier from the libvirt code POV,
> like:
> 
> 
>   
> 

Yep, that is the other obvious approach.

> So I still would like to see my much simpler solution merged.

See above, but I'm not a libvirt maintainer so that's not for me to
judge.  I'm just pointing out that this can be fixed without switching
back to the old -drive syntax.

take care,
  Gerd



Re: [PATCH 1/1] QEMU: support USB cdrom devices

2020-09-07 Thread Gerd Hoffmann
> USB disks. The main problem is, that -blockdev mechanism relies
> on the device type to handle the media type, like ide-cd and
> ide-hd. But there is just usb-storage.

You can use -device usb-bot + -device scsi-cd ...

take care,
  Gerd



Re: Various issues when using multiple graphic outputs

2020-09-04 Thread Gerd Hoffmann
  Hi,

> Well my initial target before I realized that it seemed to affect all
> combinations in different ways was to get a mediated device to work well.
> So If the answer is "just use only one" then I need to find a way to convince
> libvirt to -not- re-add a graphics device when the mdev of the vgpu is
> present.

model='none'.

HTH,
  Gerd



Re: Various issues when using multiple graphic outputs

2020-09-04 Thread Gerd Hoffmann
On Fri, Sep 04, 2020 at 12:05:08PM +0200, Christian Ehrhardt wrote:
> Hi,
> I've had continuous issues with this and wanted to reach out
> if that is a common issue everyone has or just me lacking a little
> detail on my setup.

> - QXL with multiple heads
>   - works fine (so multi display in general seems fine for the
> involved components)

Yep.

> - VGA + QXL, QXL + Virtio, Virtio + QXL:
>   - Guest only detects primary display
>   - Can't convince X in the guest to use the second device as well
>   - lspci lists both devices just fine
>   - dmesg shows the kernel is initializing them, e.g. drm for virtio

As far I know xorg can't really deal with multiple display devices.
So typically you have a single device with multiple connectors, so
you can hook up multiple monitors.

In the virtual world qxl and virtio support multiple heads, so pick
one of these two and enable as many heads as you need.  Also make sure
spice-agent is active in the guest, otherwise operating the mouse is a
PITA.

Dunno how things are with wayland.

> - 2*QXL
>   - X has issues to initialize on user login
>   - no error in the log, just hung

The windows guest driver doesn't support qxl devices with multiple
outputs and expects one qxl device per head instead.  So use this
one for windows guests.

HTH,
  Gerd



Re: [PATCH 2/4] conf: allow to map sound device to host device

2020-07-22 Thread Gerd Hoffmann
  Hi,

> IIUC, QEMU can expose multiple sound devices to the guest too.
> 
> I think this means that we can have a M:N relationship between
> a sound device, and an audio backend, not just 1:1.

It's 1:N.  Sound devices have a single backend, but a backends can
service multiple sound devices.

> Assuming I'm right about the M:N relationship, I assume that
> of multiple cards all do playback concurrently, something
> will have todo mixing of the streams ?

In general it is a good idea to go with 1:1 if possible.  With
pulseaudio this works fine.  You'll have two streams to pulseaudio
then, pulseaudio does the mixing, and you'll see both streams in
mixer apps.

OSS devices tend to not like being opened multiple times, so you
have to go with 1:N if you want multiple sound devices.  qemu mixes
the playback streams then.  Not fully sure what happens with
recording, probably all sound devices see the very same stream.

take care,
  Gerd



Re: [PATCH 2/2] x86/cpu: Handle GUEST_MAXPHYADDR < HOST_MAXPHYADDR for hosts that don't support it

2020-07-09 Thread Gerd Hoffmann
  Hi,

> > (CCing libvir-list, and people who were included in the OVMF
> > thread[1])
> > 
> > [1] 
> > https://lore.kernel.org/qemu-devel/99779e9c-f05f-501b-b4be-ff719f140...@canonical.com/

> > Also, it's important that we work with libvirt and management
> > software to ensure they have appropriate APIs to choose what to
> > do when a cluster has hosts with different MAXPHYADDR.
> 
> There's been so many complex discussions that it is hard to have any
> understanding of what we should be doing going forward. There's enough
> problems wrt phys bits, that I think we would benefit from a doc that
> outlines the big picture expectation for how to handle this in the
> virt stack.

Well, the fundamental issue is not that hard actually.  We have three
cases:

(1) GUEST_MAXPHYADDR == HOST_MAXPHYADDR

Everything is fine ;)

(2) GUEST_MAXPHYADDR < HOST_MAXPHYADDR

Mostly fine.  Some edge cases, like different page fault errors for
addresses above GUEST_MAXPHYADDR and below HOST_MAXPHYADDR.  Which I
think Mohammed fixed in the kernel recently.

(3) GUEST_MAXPHYADDR > HOST_MAXPHYADDR

Broken.  If the guest uses addresses above HOST_MAXPHYADDR everything
goes south.

The (2) case isn't much of a problem.  We only need to figure whenever
we want qemu allow this unconditionally (current state) or only in case
the kernel fixes are present (state with this patch applied if I read it
correctly).

The (3) case is the reason why guest firmware never ever uses
GUEST_MAXPHYADDR and goes with very conservative heuristics instead,
which in turn leads to the consequences discussed at length in the
OVMF thread linked above.

Ideally we would simply outlaw (3), but it's hard for backward
compatibility reasons.  Second best solution is a flag somewhere
(msr, cpuid, ...) telling the guest firmware "you can use
GUEST_MAXPHYADDR, we guarantee it is <= HOST_MAXPHYADDR".

> As mentioned in the thread quoted above, using host_phys_bits is a
> obvious thing to do when the user requested "-cpu host".
> 
> The harder issue is how to handle other CPU models. I had suggested
> we should try associating a phys bits value with them, which would
> probably involve creating Client/Server variants for all our CPU
> models which don't currently have it. I still think that's worth
> exploring as a strategy and with versioned CPU models we should
> be ok wrt back compatibility with that approach.

Yep, better defaults for GUEST_MAXPHYADDR would be good too, but that
is a separate (although related) discussion.

take care,
  Gerd



[PULL 16/20] audio: create pcspk device early

2020-07-06 Thread Gerd Hoffmann
Create the pcspk device early, so it exists at
machine type initialization time.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-17-kra...@redhat.com
---
 include/hw/i386/pc.h | 1 +
 hw/i386/pc.c | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index d7690bf4290f..a802e699749a 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -33,6 +33,7 @@ struct PCMachineState {
 PCIBus *bus;
 I2CBus *smbus;
 PFlashCFI01 *flash[2];
+ISADevice *pcspk;
 
 /* Configuration options: */
 uint64_t max_ram_below_4g;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 4fc1b7048b28..88785f9dcc70 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1219,7 +1219,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
 /* connect PIT to output control line of the HPET */
 qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(DEVICE(pit), 0));
 }
-pcspk_init(isa_new(TYPE_PC_SPEAKER), isa_bus, pit);
+pcspk_init(pcms->pcspk, isa_bus, pit);
 }
 
 i8257_dma_init(isa_bus, 0);
@@ -1891,6 +1891,7 @@ static void pc_machine_initfn(Object *obj)
 pcms->pit_enabled = true;
 
 pc_system_flash_create(pcms);
+pcms->pcspk = isa_new(TYPE_PC_SPEAKER);
 }
 
 static void pc_machine_reset(MachineState *machine)
-- 
2.18.4



[PULL 11/20] pc_basic_device_init: pass PCMachineState

2020-07-06 Thread Gerd Hoffmann
Need access to pcms for pcspk initialization.
Just preparation, no functional change.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-12-kra...@redhat.com
---
 include/hw/i386/pc.h | 3 ++-
 hw/i386/pc.c | 3 ++-
 hw/i386/pc_piix.c| 2 +-
 hw/i386/pc_q35.c | 2 +-
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index dce1273c7dad..3a601dbe71da 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -160,7 +160,8 @@ void pc_memory_init(PCMachineState *pcms,
 MemoryRegion **ram_memory);
 uint64_t pc_pci_hole64_start(void);
 DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus);
-void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
+void pc_basic_device_init(struct PCMachineState *pcms,
+  ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
   bool no_vmport,
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 4af9679d039b..d89e577f6fa1 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1155,7 +1155,8 @@ static void pc_superio_init(ISABus *isa_bus, bool 
create_fdctrl, bool no_vmport)
 g_free(a20_line);
 }
 
-void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
+void pc_basic_device_init(struct PCMachineState *pcms,
+  ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
   bool no_vmport,
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 1d832b2878b1..a3b416507286 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -235,7 +235,7 @@ static void pc_init1(MachineState *machine,
 }
 
 /* init basic PC hardware */
-pc_basic_device_init(isa_bus, x86ms->gsi, _state, true,
+pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, true,
  (pcms->vmport != ON_OFF_AUTO_ON), pcms->pit_enabled,
  0x4);
 
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 047ea8db28ea..b16e22c6cccd 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -275,7 +275,7 @@ static void pc_q35_init(MachineState *machine)
 }
 
 /* init basic PC hardware */
-pc_basic_device_init(isa_bus, x86ms->gsi, _state, !mc->no_floppy,
+pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, !mc->no_floppy,
  (pcms->vmport != ON_OFF_AUTO_ON), pcms->pit_enabled,
  0xff0104);
 
-- 
2.18.4



[PULL 10/20] audio: deprecate -soundhw hda

2020-07-06 Thread Gerd Hoffmann
Add deprecation message to the audio init function.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-11-kra...@redhat.com
---
 hw/audio/intel-hda.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index f673b8317a84..f6cea49686d7 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -25,6 +25,7 @@
 #include "qemu/bitops.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
+#include "qemu/error-report.h"
 #include "hw/audio/soundhw.h"
 #include "intel-hda.h"
 #include "migration/vmstate.h"
@@ -1307,6 +1308,8 @@ static int intel_hda_and_codec_init(PCIBus *bus)
 BusState *hdabus;
 DeviceState *codec;
 
+warn_report("'-soundhw hda' is deprecated, "
+"please use '-device intel-hda -device hda-duplex' instead");
 controller = DEVICE(pci_create_simple(bus, -1, "intel-hda"));
 hdabus = QLIST_FIRST(>child_bus);
 codec = qdev_new("hda-duplex");
-- 
2.18.4



[PULL 12/20] pc_basic_device_init: drop has_pit arg

2020-07-06 Thread Gerd Hoffmann
Now that we pass pcms anyway, we don't need the has_pit arg any more.
No functional change.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-13-kra...@redhat.com
---
 include/hw/i386/pc.h | 1 -
 hw/i386/pc.c | 3 +--
 hw/i386/pc_piix.c| 2 +-
 hw/i386/pc_q35.c | 2 +-
 4 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 3a601dbe71da..bd447e380b5e 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -165,7 +165,6 @@ void pc_basic_device_init(struct PCMachineState *pcms,
   ISADevice **rtc_state,
   bool create_fdctrl,
   bool no_vmport,
-  bool has_pit,
   uint32_t hpet_irqs);
 void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd);
 void pc_cmos_init(PCMachineState *pcms,
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d89e577f6fa1..9f5153b6f24d 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1160,7 +1160,6 @@ void pc_basic_device_init(struct PCMachineState *pcms,
   ISADevice **rtc_state,
   bool create_fdctrl,
   bool no_vmport,
-  bool has_pit,
   uint32_t hpet_irqs)
 {
 int i;
@@ -1211,7 +1210,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
 
 qemu_register_boot_set(pc_boot_set, *rtc_state);
 
-if (!xen_enabled() && has_pit) {
+if (!xen_enabled() && pcms->pit_enabled) {
 if (kvm_pit_in_kernel()) {
 pit = kvm_pit_init(isa_bus, 0x40);
 } else {
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index a3b416507286..6c1612d0ca45 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -236,7 +236,7 @@ static void pc_init1(MachineState *machine,
 
 /* init basic PC hardware */
 pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, true,
- (pcms->vmport != ON_OFF_AUTO_ON), pcms->pit_enabled,
+ (pcms->vmport != ON_OFF_AUTO_ON),
  0x4);
 
 pc_nic_init(pcmc, isa_bus, pci_bus);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index b16e22c6cccd..6faf4458549a 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -276,7 +276,7 @@ static void pc_q35_init(MachineState *machine)
 
 /* init basic PC hardware */
 pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, !mc->no_floppy,
- (pcms->vmport != ON_OFF_AUTO_ON), pcms->pit_enabled,
+ (pcms->vmport != ON_OFF_AUTO_ON),
  0xff0104);
 
 /* connect pm stuff to lpc */
-- 
2.18.4



[PULL 07/20] audio: deprecate -soundhw cs4231a

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-8-kra...@redhat.com
---
 hw/audio/cs4231a.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c
index ffdbb58d6a11..59705a8d4701 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -683,12 +683,6 @@ static void cs4231a_realizefn (DeviceState *dev, Error 
**errp)
 AUD_register_card ("cs4231a", >card);
 }
 
-static int cs4231a_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_CS4231A);
-return 0;
-}
-
 static Property cs4231a_properties[] = {
 DEFINE_AUDIO_PROPERTIES(CSState, card),
 DEFINE_PROP_UINT32 ("iobase",  CSState, port, 0x534),
@@ -720,7 +714,7 @@ static const TypeInfo cs4231a_info = {
 static void cs4231a_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("cs4231a", "CS4231A", cs4231a_init);
+deprecated_register_soundhw("cs4231a", "CS4231A", 1, TYPE_CS4231A);
 }
 
 type_init (cs4231a_register_types)
-- 
2.18.4



[PULL 18/20] audio: add soundhw deprecation notice

2020-07-06 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-19-kra...@redhat.com
---
 docs/system/deprecated.rst | 9 +
 1 file changed, 9 insertions(+)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 47f84be8e09f..58a9aeb85153 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -82,6 +82,15 @@ should specify an ``audiodev=`` property.  Additionally, 
when using
 vnc, you should specify an ``audiodev=`` propery if you plan to
 transmit audio through the VNC protocol.
 
+Creating sound card devices using ``-soundhw`` (since 5.1)
+''
+
+Sound card devices should be created using ``-device`` instead.  The
+names are the same for most devices.  The exceptions are ``hda`` which
+needs two devices (``-device intel-hda -device hda-duplex``) and
+``pcspk`` which can be activated using ``-machine
+pcspk-audiodev=``.
+
 ``-mon ...,control=readline,pretty=on|off`` (since 4.1)
 '''
 
-- 
2.18.4



[PULL 17/20] audio: deprecate -soundhw pcspk

2020-07-06 Thread Gerd Hoffmann
Add deprecation message to the audio init function.

Factor out audio initialization and call that from
both audio init and realize, so setting the audiodev
property is enough to properly initialize pcspk.

Add a property alias to the machine type to set the
audio device, so pcspk can be initialized using:
"-machine pcspk-audiodev="

Using "-global isa-pcspk.audiodev=" works too but
is not recommended.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-18-kra...@redhat.com
---
 hw/audio/pcspk.c | 24 +---
 hw/i386/pc.c |  2 ++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index c37a3878612e..4c7e339ac2b5 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -28,6 +28,7 @@
 #include "audio/audio.h"
 #include "qemu/module.h"
 #include "qemu/timer.h"
+#include "qemu/error-report.h"
 #include "hw/timer/i8254.h"
 #include "migration/vmstate.h"
 #include "hw/audio/pcspk.h"
@@ -112,11 +113,15 @@ static void pcspk_callback(void *opaque, int free)
 }
 }
 
-static int pcspk_audio_init(ISABus *bus)
+static int pcspk_audio_init(PCSpkState *s)
 {
-PCSpkState *s = pcspk_state;
 struct audsettings as = {PCSPK_SAMPLE_RATE, 1, AUDIO_FORMAT_U8, 0};
 
+if (s->voice) {
+/* already initialized */
+return 0;
+}
+
 AUD_register_card(s_spk, >card);
 
 s->voice = AUD_open_out(>card, s->voice, s_spk, s, pcspk_callback, );
@@ -185,6 +190,10 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
 
 isa_register_ioport(isadev, >ioport, s->iobase);
 
+if (s->card.state) {
+pcspk_audio_init(s);
+}
+
 pcspk_state = s;
 }
 
@@ -236,9 +245,18 @@ static const TypeInfo pcspk_info = {
 .class_init = pcspk_class_initfn,
 };
 
+static int pcspk_audio_init_soundhw(ISABus *bus)
+{
+PCSpkState *s = pcspk_state;
+
+warn_report("'-soundhw pcspk' is deprecated, "
+"please set a backend using '-machine pcspk-audiodev=' 
instead");
+return pcspk_audio_init(s);
+}
+
 static void pcspk_register(void)
 {
 type_register_static(_info);
-isa_register_soundhw("pcspk", "PC speaker", pcspk_audio_init);
+isa_register_soundhw("pcspk", "PC speaker", pcspk_audio_init_soundhw);
 }
 type_init(pcspk_register)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 88785f9dcc70..c45e7bfd864b 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1892,6 +1892,8 @@ static void pc_machine_initfn(Object *obj)
 
 pc_system_flash_create(pcms);
 pcms->pcspk = isa_new(TYPE_PC_SPEAKER);
+object_property_add_alias(OBJECT(pcms), "pcspk-audiodev",
+  OBJECT(pcms->pcspk), "audiodev");
 }
 
 static void pc_machine_reset(MachineState *machine)
-- 
2.18.4



[PULL 19/20] pcspk: update docs/system/target-i386-desc.rst.inc

2020-07-06 Thread Gerd Hoffmann
Add PC speaker with config hints.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-20-kra...@redhat.com
---
 docs/system/target-i386-desc.rst.inc | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/docs/system/target-i386-desc.rst.inc 
b/docs/system/target-i386-desc.rst.inc
index 47a169e0ae2a..7d1fffacbea3 100644
--- a/docs/system/target-i386-desc.rst.inc
+++ b/docs/system/target-i386-desc.rst.inc
@@ -31,6 +31,8 @@ The QEMU PC System emulator simulates the following 
peripherals:
 
 -  CS4231A compatible sound card
 
+-  PC speaker
+
 -  PCI UHCI, OHCI, EHCI or XHCI USB controller and a virtual USB-1.1
hub.
 
@@ -49,7 +51,7 @@ must be told to not have parallel ports to have working GUS.
 
 .. parsed-literal::
 
-   |qemu_system_x86| dos.img -soundhw gus -parallel none
+   |qemu_system_x86| dos.img -device gus -parallel none
 
 Alternatively:
 
@@ -60,3 +62,12 @@ Alternatively:
 Or some other unclaimed IRQ.
 
 CS4231A is the chip used in Windows Sound System and GUSMAX products
+
+The PC speaker audio device can be configured using the pcspk-audiodev
+machine property, i.e.
+
+.. parsed-literal::
+
+   |qemu_system_x86| some.img \
+   -audiodev ,id= \
+   -machine pcspk-audiodev=
-- 
2.18.4



[PULL 20/20] audio: set default value for pcspk.iobase property

2020-07-06 Thread Gerd Hoffmann
Allows dropping the explicit qdev_prop_set_uint32 call in pcspk_init.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-21-kra...@redhat.com
---
 include/hw/audio/pcspk.h | 6 +-
 hw/audio/pcspk.c | 2 +-
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/include/hw/audio/pcspk.h b/include/hw/audio/pcspk.h
index 8b485602675f..06cba00b8376 100644
--- a/include/hw/audio/pcspk.h
+++ b/include/hw/audio/pcspk.h
@@ -33,11 +33,7 @@
 
 static inline void pcspk_init(ISADevice *isadev, ISABus *bus, ISADevice *pit)
 {
-DeviceState *dev;
-
-dev = DEVICE(isadev);
-qdev_prop_set_uint32(dev, "iobase", 0x61);
-object_property_set_link(OBJECT(dev), OBJECT(pit), "pit", NULL);
+object_property_set_link(OBJECT(isadev), OBJECT(pit), "pit", NULL);
 isa_realize_and_unref(isadev, bus, _fatal);
 }
 
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 4c7e339ac2b5..ea539e7605a8 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -219,7 +219,7 @@ static const VMStateDescription vmstate_spk = {
 
 static Property pcspk_properties[] = {
 DEFINE_AUDIO_PROPERTIES(PCSpkState, card),
-DEFINE_PROP_UINT32("iobase", PCSpkState, iobase,  -1),
+DEFINE_PROP_UINT32("iobase", PCSpkState, iobase,  0x61),
 DEFINE_PROP_BOOL("migrate", PCSpkState, migrate,  true),
 DEFINE_PROP_END_OF_LIST(),
 };
-- 
2.18.4



[PULL 14/20] softmmu: initialize spice and audio earlier

2020-07-06 Thread Gerd Hoffmann
audiodev must be initialized before machine_set_property
so the machine can have audiodev property aliases.

spice must initialize before audiodev because the default
audiodev is spice only in case spice is actually enabled.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-15-kra...@redhat.com
---
 softmmu/vl.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 3e15ee243572..8ee91219060a 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -4131,12 +4131,17 @@ void qemu_init(int argc, char **argv, char **envp)
   fsdev_init_func, NULL, _fatal);
 #endif
 
+/* spice needs the timers to be initialized by this point */
+/* spice must initialize before audio as it changes the default auiodev */
+qemu_spice_init();
+
 /*
- * Note: we need to create block backends before
+ * Note: we need to create audio and block backends before
  * machine_set_property(), so machine properties can refer to
  * them.
  */
 configure_blockdev(_queue, machine_class, snapshot);
+audio_init_audiodevs();
 
 machine_opts = qemu_get_machine_opts();
 qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
@@ -4230,9 +4235,6 @@ void qemu_init(int argc, char **argv, char **envp)
 semihosting_arg_fallback(kernel_filename, kernel_cmdline);
 }
 
-/* spice needs the timers to be initialized by this point */
-qemu_spice_init();
-
 cpu_ticks_init();
 
 if (default_net) {
@@ -4342,8 +4344,6 @@ void qemu_init(int argc, char **argv, char **envp)
 create_default_memdev(current_machine, mem_path);
 }
 
-audio_init_audiodevs();
-
 /* from here on runstate is RUN_STATE_PRELAUNCH */
 machine_run_board_init(current_machine);
 
-- 
2.18.4



[PULL 13/20] pc_basic_device_init: drop no_vmport arg

2020-07-06 Thread Gerd Hoffmann
Now that we pass pcms anyway, we don't need the no_vmport arg any more.
No functional change.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-14-kra...@redhat.com
---
 include/hw/i386/pc.h | 1 -
 hw/i386/pc.c | 3 +--
 hw/i386/pc_piix.c| 1 -
 hw/i386/pc_q35.c | 1 -
 4 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index bd447e380b5e..d7690bf4290f 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -164,7 +164,6 @@ void pc_basic_device_init(struct PCMachineState *pcms,
   ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
-  bool no_vmport,
   uint32_t hpet_irqs);
 void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd);
 void pc_cmos_init(PCMachineState *pcms,
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 9f5153b6f24d..407c782b5d42 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1159,7 +1159,6 @@ void pc_basic_device_init(struct PCMachineState *pcms,
   ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
-  bool no_vmport,
   uint32_t hpet_irqs)
 {
 int i;
@@ -1226,7 +1225,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
 i8257_dma_init(isa_bus, 0);
 
 /* Super I/O */
-pc_superio_init(isa_bus, create_fdctrl, no_vmport);
+pc_superio_init(isa_bus, create_fdctrl, pcms->vmport != ON_OFF_AUTO_ON);
 }
 
 void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus)
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 6c1612d0ca45..1ef3f39c55a5 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -236,7 +236,6 @@ static void pc_init1(MachineState *machine,
 
 /* init basic PC hardware */
 pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, true,
- (pcms->vmport != ON_OFF_AUTO_ON),
  0x4);
 
 pc_nic_init(pcmc, isa_bus, pci_bus);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 6faf4458549a..5f8f21b84093 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -276,7 +276,6 @@ static void pc_q35_init(MachineState *machine)
 
 /* init basic PC hardware */
 pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, !mc->no_floppy,
- (pcms->vmport != ON_OFF_AUTO_ON),
  0xff0104);
 
 /* connect pm stuff to lpc */
-- 
2.18.4



[PULL 15/20] audio: rework pcspk_init()

2020-07-06 Thread Gerd Hoffmann
Instead of creating and returning the pc speaker accept it as argument.
That allows to rework the initialization workflow in followup patches.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-16-kra...@redhat.com
---
 include/hw/audio/pcspk.h | 6 +-
 hw/i386/pc.c | 2 +-
 hw/isa/i82378.c  | 2 +-
 hw/mips/jazz.c   | 2 +-
 4 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/include/hw/audio/pcspk.h b/include/hw/audio/pcspk.h
index 7e7f5f49dcb0..8b485602675f 100644
--- a/include/hw/audio/pcspk.h
+++ b/include/hw/audio/pcspk.h
@@ -31,18 +31,14 @@
 
 #define TYPE_PC_SPEAKER "isa-pcspk"
 
-static inline ISADevice *pcspk_init(ISABus *bus, ISADevice *pit)
+static inline void pcspk_init(ISADevice *isadev, ISABus *bus, ISADevice *pit)
 {
 DeviceState *dev;
-ISADevice *isadev;
 
-isadev = isa_new(TYPE_PC_SPEAKER);
 dev = DEVICE(isadev);
 qdev_prop_set_uint32(dev, "iobase", 0x61);
 object_property_set_link(OBJECT(dev), OBJECT(pit), "pit", NULL);
 isa_realize_and_unref(isadev, bus, _fatal);
-
-return isadev;
 }
 
 #endif /* HW_PCSPK_H */
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 407c782b5d42..4fc1b7048b28 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1219,7 +1219,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
 /* connect PIT to output control line of the HPET */
 qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(DEVICE(pit), 0));
 }
-pcspk_init(isa_bus, pit);
+pcspk_init(isa_new(TYPE_PC_SPEAKER), isa_bus, pit);
 }
 
 i8257_dma_init(isa_bus, 0);
diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c
index d9e6c7fa0096..75a2da288157 100644
--- a/hw/isa/i82378.c
+++ b/hw/isa/i82378.c
@@ -102,7 +102,7 @@ static void i82378_realize(PCIDevice *pci, Error **errp)
 pit = i8254_pit_init(isabus, 0x40, 0, NULL);
 
 /* speaker */
-pcspk_init(isabus, pit);
+pcspk_init(isa_new(TYPE_PC_SPEAKER), isabus, pit);
 
 /* 2 82C37 (dma) */
 isa_create_simple(isabus, "i82374");
diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c
index c3b0da60ccc1..0002bff69590 100644
--- a/hw/mips/jazz.c
+++ b/hw/mips/jazz.c
@@ -250,7 +250,7 @@ static void mips_jazz_init(MachineState *machine,
 isa_bus_irqs(isa_bus, i8259);
 i8257_dma_init(isa_bus, 0);
 pit = i8254_pit_init(isa_bus, 0x40, 0, NULL);
-pcspk_init(isa_bus, pit);
+pcspk_init(isa_new(TYPE_PC_SPEAKER), isa_bus, pit);
 
 /* Video card */
 switch (jazz_model) {
-- 
2.18.4



[PULL 08/20] audio: deprecate -soundhw gus

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-9-kra...@redhat.com
---
 hw/audio/gus.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index c8df2bde6b32..7e4a8cadad6f 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -286,12 +286,6 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
 AUD_set_active_out (s->voice, 1);
 }
 
-static int GUS_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_GUS);
-return 0;
-}
-
 static Property gus_properties[] = {
 DEFINE_AUDIO_PROPERTIES(GUSState, card),
 DEFINE_PROP_UINT32 ("freq",GUSState, freq,44100),
@@ -322,7 +316,7 @@ static const TypeInfo gus_info = {
 static void gus_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("gus", "Gravis Ultrasound GF1", GUS_init);
+deprecated_register_soundhw("gus", "Gravis Ultrasound GF1", 1, TYPE_GUS);
 }
 
 type_init (gus_register_types)
-- 
2.18.4



[PULL 09/20] audio: deprecate -soundhw sb16

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-10-kra...@redhat.com
---
 hw/audio/sb16.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c
index df6f755a37f8..2d9e50f99b5d 100644
--- a/hw/audio/sb16.c
+++ b/hw/audio/sb16.c
@@ -1415,12 +1415,6 @@ static void sb16_realizefn (DeviceState *dev, Error 
**errp)
 AUD_register_card ("sb16", >card);
 }
 
-static int SB16_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_SB16);
-return 0;
-}
-
 static Property sb16_properties[] = {
 DEFINE_AUDIO_PROPERTIES(SB16State, card),
 DEFINE_PROP_UINT32 ("version", SB16State, ver,  0x0405), /* 4.5 */
@@ -1453,7 +1447,8 @@ static const TypeInfo sb16_info = {
 static void sb16_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("sb16", "Creative Sound Blaster 16", SB16_init);
+deprecated_register_soundhw("sb16", "Creative Sound Blaster 16",
+1, TYPE_SB16);
 }
 
 type_init (sb16_register_types)
-- 
2.18.4



[PULL 04/20] audio: deprecate -soundhw ac97

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().  Remove the now obsolete init
function.  Add an alias so both ac97 and AC97 are working with -device.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-5-kra...@redhat.com
---
 hw/audio/ac97.c | 9 ++---
 qdev-monitor.c  | 1 +
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index 8a9b9924c495..38522cf0ba44 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -1393,12 +1393,6 @@ static void ac97_exit(PCIDevice *dev)
 AUD_remove_card(>card);
 }
 
-static int ac97_init (PCIBus *bus)
-{
-pci_create_simple(bus, -1, TYPE_AC97);
-return 0;
-}
-
 static Property ac97_properties[] = {
 DEFINE_AUDIO_PROPERTIES(AC97LinkState, card),
 DEFINE_PROP_END_OF_LIST (),
@@ -1436,7 +1430,8 @@ static const TypeInfo ac97_info = {
 static void ac97_register_types (void)
 {
 type_register_static (_info);
-pci_register_soundhw("ac97", "Intel 82801AA AC97 Audio", ac97_init);
+deprecated_register_soundhw("ac97", "Intel 82801AA AC97 Audio",
+0, TYPE_AC97);
 }
 
 type_init (ac97_register_types)
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 22da107484c5..105d9792ecdf 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -53,6 +53,7 @@ typedef struct QDevAlias
 
 /* Please keep this table sorted by typename. */
 static const QDevAlias qdev_alias_table[] = {
+{ "AC97", "ac97" }, /* -soundhw name */
 { "e1000", "e1000-82540em" },
 { "ich9-ahci", "ahci" },
 { "lsi53c895a", "lsi" },
-- 
2.18.4



[PULL 02/20] stubs: add pci_create_simple

2020-07-06 Thread Gerd Hoffmann
Needed for -soundhw cleanup.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
Message-id: 20200702132525.6849-3-kra...@redhat.com
---
 stubs/pci-bus.c | 7 +++
 stubs/Makefile.objs | 1 +
 2 files changed, 8 insertions(+)
 create mode 100644 stubs/pci-bus.c

diff --git a/stubs/pci-bus.c b/stubs/pci-bus.c
new file mode 100644
index ..a8932fa93250
--- /dev/null
+++ b/stubs/pci-bus.c
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+
+PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
+{
+g_assert_not_reached();
+}
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index ff0411d21f22..918e46bdc1ca 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -13,6 +13,7 @@ stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 stub-obj-$(CONFIG_LINUX_IO_URING) += io_uring.o
 stub-obj-y += monitor-core.o
 stub-obj-y += notify-event.o
+stub-obj-y += pci-bus.o
 stub-obj-y += qmp_memory_device.o
 stub-obj-y += qtest.o
 stub-obj-y += ramfb.o
-- 
2.18.4



[PULL 03/20] audio: add deprecated_register_soundhw

2020-07-06 Thread Gerd Hoffmann
Add helper function for -soundhw deprecation.  It can replace the
simple init functions which just call {isa,pci}_create_simple()
with a hardcoded type.  It also prints a deprecation message.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-4-kra...@redhat.com
---
 include/hw/audio/soundhw.h |  2 ++
 hw/audio/soundhw.c | 24 +++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/include/hw/audio/soundhw.h b/include/hw/audio/soundhw.h
index c8eef8241846..f09a297854af 100644
--- a/include/hw/audio/soundhw.h
+++ b/include/hw/audio/soundhw.h
@@ -6,6 +6,8 @@ void isa_register_soundhw(const char *name, const char *descr,
 
 void pci_register_soundhw(const char *name, const char *descr,
   int (*init_pci)(PCIBus *bus));
+void deprecated_register_soundhw(const char *name, const char *descr,
+ int isa, const char *typename);
 
 void soundhw_init(void);
 void select_soundhw(const char *optarg);
diff --git a/hw/audio/soundhw.c b/hw/audio/soundhw.c
index c750473c8f0c..173b674ff53a 100644
--- a/hw/audio/soundhw.c
+++ b/hw/audio/soundhw.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
+#include "qemu/option.h"
 #include "qemu/help_option.h"
 #include "qemu/error-report.h"
 #include "qom/object.h"
@@ -32,6 +33,7 @@
 struct soundhw {
 const char *name;
 const char *descr;
+const char *typename;
 int enabled;
 int isa;
 union {
@@ -65,6 +67,17 @@ void pci_register_soundhw(const char *name, const char 
*descr,
 soundhw_count++;
 }
 
+void deprecated_register_soundhw(const char *name, const char *descr,
+ int isa, const char *typename)
+{
+assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
+soundhw[soundhw_count].name = name;
+soundhw[soundhw_count].descr = descr;
+soundhw[soundhw_count].isa = isa;
+soundhw[soundhw_count].typename = typename;
+soundhw_count++;
+}
+
 void select_soundhw(const char *optarg)
 {
 struct soundhw *c;
@@ -136,7 +149,16 @@ void soundhw_init(void)
 
 for (c = soundhw; c->name; ++c) {
 if (c->enabled) {
-if (c->isa) {
+if (c->typename) {
+warn_report("'-soundhw %s' is deprecated, "
+"please use '-device %s' instead",
+c->name, c->typename);
+if (c->isa) {
+isa_create_simple(isa_bus, c->typename);
+} else {
+pci_create_simple(pci_bus, -1, c->typename);
+}
+} else if (c->isa) {
 if (!isa_bus) {
 error_report("ISA bus not available for %s", c->name);
 exit(1);
-- 
2.18.4



[PULL 00/20] Audio 20200706 patches

2020-07-06 Thread Gerd Hoffmann
The following changes since commit eb6490f544388dd24c0d054a96dd304bc7284450:

  Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20200703' 
into staging (2020-07-04 16:08:41 +0100)

are available in the Git repository at:

  git://git.kraxel.org/qemu tags/audio-20200706-pull-request

for you to fetch changes up to 2336172d9b396b4fa4483712f5560a563c25352f:

  audio: set default value for pcspk.iobase property (2020-07-06 17:01:11 +0200)


audio: deprecate -soundhw



Gerd Hoffmann (20):
  stubs: add isa_create_simple
  stubs: add pci_create_simple
  audio: add deprecated_register_soundhw
  audio: deprecate -soundhw ac97
  audio: deprecate -soundhw es1370
  audio: deprecate -soundhw adlib
  audio: deprecate -soundhw cs4231a
  audio: deprecate -soundhw gus
  audio: deprecate -soundhw sb16
  audio: deprecate -soundhw hda
  pc_basic_device_init: pass PCMachineState
  pc_basic_device_init: drop has_pit arg
  pc_basic_device_init: drop no_vmport arg
  softmmu: initialize spice and audio earlier
  audio: rework pcspk_init()
  audio: create pcspk device early
  audio: deprecate -soundhw pcspk
  audio: add soundhw deprecation notice
  pcspk: update docs/system/target-i386-desc.rst.inc
  audio: set default value for pcspk.iobase property

 include/hw/audio/pcspk.h | 12 ++--
 include/hw/audio/soundhw.h   |  2 ++
 include/hw/i386/pc.h |  6 +++---
 hw/audio/ac97.c  |  9 ++---
 hw/audio/adlib.c |  8 +---
 hw/audio/cs4231a.c   |  8 +---
 hw/audio/es1370.c|  9 ++---
 hw/audio/gus.c   |  8 +---
 hw/audio/intel-hda.c |  3 +++
 hw/audio/pcspk.c | 26 ++
 hw/audio/sb16.c  |  9 ++---
 hw/audio/soundhw.c   | 24 +++-
 hw/i386/pc.c | 14 --
 hw/i386/pc_piix.c|  3 +--
 hw/i386/pc_q35.c |  3 +--
 hw/isa/i82378.c  |  2 +-
 hw/mips/jazz.c   |  2 +-
 qdev-monitor.c   |  2 ++
 softmmu/vl.c | 12 ++--
 stubs/isa-bus.c  |  7 +++
 stubs/pci-bus.c  |  7 +++
 docs/system/deprecated.rst   |  9 +
 docs/system/target-i386-desc.rst.inc | 13 -
 stubs/Makefile.objs  |  2 ++
 24 files changed, 121 insertions(+), 79 deletions(-)
 create mode 100644 stubs/isa-bus.c
 create mode 100644 stubs/pci-bus.c

-- 
2.18.4



[PULL 01/20] stubs: add isa_create_simple

2020-07-06 Thread Gerd Hoffmann
Needed for -soundhw cleanup.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
Message-id: 20200702132525.6849-2-kra...@redhat.com
---
 stubs/isa-bus.c | 7 +++
 stubs/Makefile.objs | 1 +
 2 files changed, 8 insertions(+)
 create mode 100644 stubs/isa-bus.c

diff --git a/stubs/isa-bus.c b/stubs/isa-bus.c
new file mode 100644
index ..522f448997d4
--- /dev/null
+++ b/stubs/isa-bus.c
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "hw/isa/isa.h"
+
+ISADevice *isa_create_simple(ISABus *bus, const char *name)
+{
+g_assert_not_reached();
+}
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index f32b9e47a3d8..ff0411d21f22 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -8,6 +8,7 @@ stub-obj-y += fdset.o
 stub-obj-y += gdbstub.o
 stub-obj-y += iothread-lock.o
 stub-obj-y += is-daemonized.o
+stub-obj-y += isa-bus.o
 stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 stub-obj-$(CONFIG_LINUX_IO_URING) += io_uring.o
 stub-obj-y += monitor-core.o
-- 
2.18.4



[PULL 06/20] audio: deprecate -soundhw adlib

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-7-kra...@redhat.com
---
 hw/audio/adlib.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index 7c3b67dcfb8c..65dff5b6fca4 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -319,16 +319,10 @@ static const TypeInfo adlib_info = {
 .class_init= adlib_class_initfn,
 };
 
-static int Adlib_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_ADLIB);
-return 0;
-}
-
 static void adlib_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("adlib", ADLIB_DESC, Adlib_init);
+deprecated_register_soundhw("adlib", ADLIB_DESC, 1, TYPE_ADLIB);
 }
 
 type_init (adlib_register_types)
-- 
2.18.4



[PULL 05/20] audio: deprecate -soundhw es1370

2020-07-06 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().  Remove the now obsolete init
function.  Add an alias so both es1370 and ES1370 are working with
-device.

Signed-off-by: Gerd Hoffmann 
Message-id: 20200702132525.6849-6-kra...@redhat.com
---
 hw/audio/es1370.c | 9 ++---
 qdev-monitor.c| 1 +
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index 5f8a83ff5624..4255463a49ff 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -884,12 +884,6 @@ static void es1370_exit(PCIDevice *dev)
 AUD_remove_card(>card);
 }
 
-static int es1370_init (PCIBus *bus)
-{
-pci_create_simple (bus, -1, TYPE_ES1370);
-return 0;
-}
-
 static Property es1370_properties[] = {
 DEFINE_AUDIO_PROPERTIES(ES1370State, card),
 DEFINE_PROP_END_OF_LIST(),
@@ -928,7 +922,8 @@ static const TypeInfo es1370_info = {
 static void es1370_register_types (void)
 {
 type_register_static (_info);
-pci_register_soundhw("es1370", "ENSONIQ AudioPCI ES1370", es1370_init);
+deprecated_register_soundhw("es1370", "ENSONIQ AudioPCI ES1370",
+0, TYPE_ES1370);
 }
 
 type_init (es1370_register_types)
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 105d9792ecdf..e3083fae394b 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -55,6 +55,7 @@ typedef struct QDevAlias
 static const QDevAlias qdev_alias_table[] = {
 { "AC97", "ac97" }, /* -soundhw name */
 { "e1000", "e1000-82540em" },
+{ "ES1370", "es1370" }, /* -soundhw name */
 { "ich9-ahci", "ahci" },
 { "lsi53c895a", "lsi" },
 { "virtio-9p-ccw", "virtio-9p", QEMU_ARCH_S390X },
-- 
2.18.4



[PATCH v5 02/20] stubs: add pci_create_simple

2020-07-02 Thread Gerd Hoffmann
Needed for -soundhw cleanup.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
---
 stubs/pci-bus.c | 7 +++
 stubs/Makefile.objs | 1 +
 2 files changed, 8 insertions(+)
 create mode 100644 stubs/pci-bus.c

diff --git a/stubs/pci-bus.c b/stubs/pci-bus.c
new file mode 100644
index ..a8932fa93250
--- /dev/null
+++ b/stubs/pci-bus.c
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+
+PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
+{
+g_assert_not_reached();
+}
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index ff0411d21f22..918e46bdc1ca 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -13,6 +13,7 @@ stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 stub-obj-$(CONFIG_LINUX_IO_URING) += io_uring.o
 stub-obj-y += monitor-core.o
 stub-obj-y += notify-event.o
+stub-obj-y += pci-bus.o
 stub-obj-y += qmp_memory_device.o
 stub-obj-y += qtest.o
 stub-obj-y += ramfb.o
-- 
2.18.4



[PATCH v5 09/20] audio: deprecate -soundhw sb16

2020-07-02 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/sb16.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c
index df6f755a37f8..2d9e50f99b5d 100644
--- a/hw/audio/sb16.c
+++ b/hw/audio/sb16.c
@@ -1415,12 +1415,6 @@ static void sb16_realizefn (DeviceState *dev, Error 
**errp)
 AUD_register_card ("sb16", >card);
 }
 
-static int SB16_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_SB16);
-return 0;
-}
-
 static Property sb16_properties[] = {
 DEFINE_AUDIO_PROPERTIES(SB16State, card),
 DEFINE_PROP_UINT32 ("version", SB16State, ver,  0x0405), /* 4.5 */
@@ -1453,7 +1447,8 @@ static const TypeInfo sb16_info = {
 static void sb16_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("sb16", "Creative Sound Blaster 16", SB16_init);
+deprecated_register_soundhw("sb16", "Creative Sound Blaster 16",
+1, TYPE_SB16);
 }
 
 type_init (sb16_register_types)
-- 
2.18.4



[PATCH v5 05/20] audio: deprecate -soundhw es1370

2020-07-02 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().  Remove the now obsolete init
function.  Add an alias so both es1370 and ES1370 are working with
-device.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/es1370.c | 9 ++---
 qdev-monitor.c| 1 +
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index 5f8a83ff5624..4255463a49ff 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -884,12 +884,6 @@ static void es1370_exit(PCIDevice *dev)
 AUD_remove_card(>card);
 }
 
-static int es1370_init (PCIBus *bus)
-{
-pci_create_simple (bus, -1, TYPE_ES1370);
-return 0;
-}
-
 static Property es1370_properties[] = {
 DEFINE_AUDIO_PROPERTIES(ES1370State, card),
 DEFINE_PROP_END_OF_LIST(),
@@ -928,7 +922,8 @@ static const TypeInfo es1370_info = {
 static void es1370_register_types (void)
 {
 type_register_static (_info);
-pci_register_soundhw("es1370", "ENSONIQ AudioPCI ES1370", es1370_init);
+deprecated_register_soundhw("es1370", "ENSONIQ AudioPCI ES1370",
+0, TYPE_ES1370);
 }
 
 type_init (es1370_register_types)
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 105d9792ecdf..e3083fae394b 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -55,6 +55,7 @@ typedef struct QDevAlias
 static const QDevAlias qdev_alias_table[] = {
 { "AC97", "ac97" }, /* -soundhw name */
 { "e1000", "e1000-82540em" },
+{ "ES1370", "es1370" }, /* -soundhw name */
 { "ich9-ahci", "ahci" },
 { "lsi53c895a", "lsi" },
 { "virtio-9p-ccw", "virtio-9p", QEMU_ARCH_S390X },
-- 
2.18.4



[PATCH v5 19/20] pcspk: update docs/system/target-i386-desc.rst.inc

2020-07-02 Thread Gerd Hoffmann
Add PC speaker with config hints.

Signed-off-by: Gerd Hoffmann 
---
 docs/system/target-i386-desc.rst.inc | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/docs/system/target-i386-desc.rst.inc 
b/docs/system/target-i386-desc.rst.inc
index 47a169e0ae2a..7d1fffacbea3 100644
--- a/docs/system/target-i386-desc.rst.inc
+++ b/docs/system/target-i386-desc.rst.inc
@@ -31,6 +31,8 @@ The QEMU PC System emulator simulates the following 
peripherals:
 
 -  CS4231A compatible sound card
 
+-  PC speaker
+
 -  PCI UHCI, OHCI, EHCI or XHCI USB controller and a virtual USB-1.1
hub.
 
@@ -49,7 +51,7 @@ must be told to not have parallel ports to have working GUS.
 
 .. parsed-literal::
 
-   |qemu_system_x86| dos.img -soundhw gus -parallel none
+   |qemu_system_x86| dos.img -device gus -parallel none
 
 Alternatively:
 
@@ -60,3 +62,12 @@ Alternatively:
 Or some other unclaimed IRQ.
 
 CS4231A is the chip used in Windows Sound System and GUSMAX products
+
+The PC speaker audio device can be configured using the pcspk-audiodev
+machine property, i.e.
+
+.. parsed-literal::
+
+   |qemu_system_x86| some.img \
+   -audiodev ,id= \
+   -machine pcspk-audiodev=
-- 
2.18.4



[PATCH v5 20/20] audio: set default value for pcspk.iobase property

2020-07-02 Thread Gerd Hoffmann
Allows dropping the explicit qdev_prop_set_uint32 call in pcspk_init.

Signed-off-by: Gerd Hoffmann 
---
 include/hw/audio/pcspk.h | 6 +-
 hw/audio/pcspk.c | 2 +-
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/include/hw/audio/pcspk.h b/include/hw/audio/pcspk.h
index 8b485602675f..06cba00b8376 100644
--- a/include/hw/audio/pcspk.h
+++ b/include/hw/audio/pcspk.h
@@ -33,11 +33,7 @@
 
 static inline void pcspk_init(ISADevice *isadev, ISABus *bus, ISADevice *pit)
 {
-DeviceState *dev;
-
-dev = DEVICE(isadev);
-qdev_prop_set_uint32(dev, "iobase", 0x61);
-object_property_set_link(OBJECT(dev), OBJECT(pit), "pit", NULL);
+object_property_set_link(OBJECT(isadev), OBJECT(pit), "pit", NULL);
 isa_realize_and_unref(isadev, bus, _fatal);
 }
 
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 4c7e339ac2b5..ea539e7605a8 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -219,7 +219,7 @@ static const VMStateDescription vmstate_spk = {
 
 static Property pcspk_properties[] = {
 DEFINE_AUDIO_PROPERTIES(PCSpkState, card),
-DEFINE_PROP_UINT32("iobase", PCSpkState, iobase,  -1),
+DEFINE_PROP_UINT32("iobase", PCSpkState, iobase,  0x61),
 DEFINE_PROP_BOOL("migrate", PCSpkState, migrate,  true),
 DEFINE_PROP_END_OF_LIST(),
 };
-- 
2.18.4



[PATCH v5 10/20] audio: deprecate -soundhw hda

2020-07-02 Thread Gerd Hoffmann
Add deprecation message to the audio init function.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/intel-hda.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index f673b8317a84..f6cea49686d7 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -25,6 +25,7 @@
 #include "qemu/bitops.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
+#include "qemu/error-report.h"
 #include "hw/audio/soundhw.h"
 #include "intel-hda.h"
 #include "migration/vmstate.h"
@@ -1307,6 +1308,8 @@ static int intel_hda_and_codec_init(PCIBus *bus)
 BusState *hdabus;
 DeviceState *codec;
 
+warn_report("'-soundhw hda' is deprecated, "
+"please use '-device intel-hda -device hda-duplex' instead");
 controller = DEVICE(pci_create_simple(bus, -1, "intel-hda"));
 hdabus = QLIST_FIRST(>child_bus);
 codec = qdev_new("hda-duplex");
-- 
2.18.4



[PATCH v5 01/20] stubs: add isa_create_simple

2020-07-02 Thread Gerd Hoffmann
Needed for -soundhw cleanup.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
---
 stubs/isa-bus.c | 7 +++
 stubs/Makefile.objs | 1 +
 2 files changed, 8 insertions(+)
 create mode 100644 stubs/isa-bus.c

diff --git a/stubs/isa-bus.c b/stubs/isa-bus.c
new file mode 100644
index ..522f448997d4
--- /dev/null
+++ b/stubs/isa-bus.c
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "hw/isa/isa.h"
+
+ISADevice *isa_create_simple(ISABus *bus, const char *name)
+{
+g_assert_not_reached();
+}
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index f32b9e47a3d8..ff0411d21f22 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -8,6 +8,7 @@ stub-obj-y += fdset.o
 stub-obj-y += gdbstub.o
 stub-obj-y += iothread-lock.o
 stub-obj-y += is-daemonized.o
+stub-obj-y += isa-bus.o
 stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 stub-obj-$(CONFIG_LINUX_IO_URING) += io_uring.o
 stub-obj-y += monitor-core.o
-- 
2.18.4



[PATCH v5 17/20] audio: deprecate -soundhw pcspk

2020-07-02 Thread Gerd Hoffmann
Add deprecation message to the audio init function.

Factor out audio initialization and call that from
both audio init and realize, so setting the audiodev
property is enough to properly initialize pcspk.

Add a property alias to the machine type to set the
audio device, so pcspk can be initialized using:
"-machine pcspk-audiodev="

Using "-global isa-pcspk.audiodev=" works too but
is not recommended.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/pcspk.c | 24 +---
 hw/i386/pc.c |  2 ++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index c37a3878612e..4c7e339ac2b5 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -28,6 +28,7 @@
 #include "audio/audio.h"
 #include "qemu/module.h"
 #include "qemu/timer.h"
+#include "qemu/error-report.h"
 #include "hw/timer/i8254.h"
 #include "migration/vmstate.h"
 #include "hw/audio/pcspk.h"
@@ -112,11 +113,15 @@ static void pcspk_callback(void *opaque, int free)
 }
 }
 
-static int pcspk_audio_init(ISABus *bus)
+static int pcspk_audio_init(PCSpkState *s)
 {
-PCSpkState *s = pcspk_state;
 struct audsettings as = {PCSPK_SAMPLE_RATE, 1, AUDIO_FORMAT_U8, 0};
 
+if (s->voice) {
+/* already initialized */
+return 0;
+}
+
 AUD_register_card(s_spk, >card);
 
 s->voice = AUD_open_out(>card, s->voice, s_spk, s, pcspk_callback, );
@@ -185,6 +190,10 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
 
 isa_register_ioport(isadev, >ioport, s->iobase);
 
+if (s->card.state) {
+pcspk_audio_init(s);
+}
+
 pcspk_state = s;
 }
 
@@ -236,9 +245,18 @@ static const TypeInfo pcspk_info = {
 .class_init = pcspk_class_initfn,
 };
 
+static int pcspk_audio_init_soundhw(ISABus *bus)
+{
+PCSpkState *s = pcspk_state;
+
+warn_report("'-soundhw pcspk' is deprecated, "
+"please set a backend using '-machine pcspk-audiodev=' 
instead");
+return pcspk_audio_init(s);
+}
+
 static void pcspk_register(void)
 {
 type_register_static(_info);
-isa_register_soundhw("pcspk", "PC speaker", pcspk_audio_init);
+isa_register_soundhw("pcspk", "PC speaker", pcspk_audio_init_soundhw);
 }
 type_init(pcspk_register)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 88785f9dcc70..c45e7bfd864b 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1892,6 +1892,8 @@ static void pc_machine_initfn(Object *obj)
 
 pc_system_flash_create(pcms);
 pcms->pcspk = isa_new(TYPE_PC_SPEAKER);
+object_property_add_alias(OBJECT(pcms), "pcspk-audiodev",
+  OBJECT(pcms->pcspk), "audiodev");
 }
 
 static void pc_machine_reset(MachineState *machine)
-- 
2.18.4



[PATCH v5 13/20] pc_basic_device_init: drop no_vmport arg

2020-07-02 Thread Gerd Hoffmann
Now that we pass pcms anyway, we don't need the no_vmport arg any more.
No functional change.

Signed-off-by: Gerd Hoffmann 
---
 include/hw/i386/pc.h | 1 -
 hw/i386/pc.c | 3 +--
 hw/i386/pc_piix.c| 1 -
 hw/i386/pc_q35.c | 1 -
 4 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index bd447e380b5e..d7690bf4290f 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -164,7 +164,6 @@ void pc_basic_device_init(struct PCMachineState *pcms,
   ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
-  bool no_vmport,
   uint32_t hpet_irqs);
 void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd);
 void pc_cmos_init(PCMachineState *pcms,
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 9f5153b6f24d..407c782b5d42 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1159,7 +1159,6 @@ void pc_basic_device_init(struct PCMachineState *pcms,
   ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
-  bool no_vmport,
   uint32_t hpet_irqs)
 {
 int i;
@@ -1226,7 +1225,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
 i8257_dma_init(isa_bus, 0);
 
 /* Super I/O */
-pc_superio_init(isa_bus, create_fdctrl, no_vmport);
+pc_superio_init(isa_bus, create_fdctrl, pcms->vmport != ON_OFF_AUTO_ON);
 }
 
 void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus)
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 6c1612d0ca45..1ef3f39c55a5 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -236,7 +236,6 @@ static void pc_init1(MachineState *machine,
 
 /* init basic PC hardware */
 pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, true,
- (pcms->vmport != ON_OFF_AUTO_ON),
  0x4);
 
 pc_nic_init(pcmc, isa_bus, pci_bus);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 6faf4458549a..5f8f21b84093 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -276,7 +276,6 @@ static void pc_q35_init(MachineState *machine)
 
 /* init basic PC hardware */
 pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, !mc->no_floppy,
- (pcms->vmport != ON_OFF_AUTO_ON),
  0xff0104);
 
 /* connect pm stuff to lpc */
-- 
2.18.4



[PATCH v5 15/20] audio: rework pcspk_init()

2020-07-02 Thread Gerd Hoffmann
Instead of creating and returning the pc speaker accept it as argument.
That allows to rework the initialization workflow in followup patches.

Signed-off-by: Gerd Hoffmann 
---
 include/hw/audio/pcspk.h | 6 +-
 hw/i386/pc.c | 2 +-
 hw/isa/i82378.c  | 2 +-
 hw/mips/jazz.c   | 2 +-
 4 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/include/hw/audio/pcspk.h b/include/hw/audio/pcspk.h
index 7e7f5f49dcb0..8b485602675f 100644
--- a/include/hw/audio/pcspk.h
+++ b/include/hw/audio/pcspk.h
@@ -31,18 +31,14 @@
 
 #define TYPE_PC_SPEAKER "isa-pcspk"
 
-static inline ISADevice *pcspk_init(ISABus *bus, ISADevice *pit)
+static inline void pcspk_init(ISADevice *isadev, ISABus *bus, ISADevice *pit)
 {
 DeviceState *dev;
-ISADevice *isadev;
 
-isadev = isa_new(TYPE_PC_SPEAKER);
 dev = DEVICE(isadev);
 qdev_prop_set_uint32(dev, "iobase", 0x61);
 object_property_set_link(OBJECT(dev), OBJECT(pit), "pit", NULL);
 isa_realize_and_unref(isadev, bus, _fatal);
-
-return isadev;
 }
 
 #endif /* HW_PCSPK_H */
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 407c782b5d42..4fc1b7048b28 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1219,7 +1219,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
 /* connect PIT to output control line of the HPET */
 qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(DEVICE(pit), 0));
 }
-pcspk_init(isa_bus, pit);
+pcspk_init(isa_new(TYPE_PC_SPEAKER), isa_bus, pit);
 }
 
 i8257_dma_init(isa_bus, 0);
diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c
index d9e6c7fa0096..75a2da288157 100644
--- a/hw/isa/i82378.c
+++ b/hw/isa/i82378.c
@@ -102,7 +102,7 @@ static void i82378_realize(PCIDevice *pci, Error **errp)
 pit = i8254_pit_init(isabus, 0x40, 0, NULL);
 
 /* speaker */
-pcspk_init(isabus, pit);
+pcspk_init(isa_new(TYPE_PC_SPEAKER), isabus, pit);
 
 /* 2 82C37 (dma) */
 isa_create_simple(isabus, "i82374");
diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c
index c3b0da60ccc1..0002bff69590 100644
--- a/hw/mips/jazz.c
+++ b/hw/mips/jazz.c
@@ -250,7 +250,7 @@ static void mips_jazz_init(MachineState *machine,
 isa_bus_irqs(isa_bus, i8259);
 i8257_dma_init(isa_bus, 0);
 pit = i8254_pit_init(isa_bus, 0x40, 0, NULL);
-pcspk_init(isa_bus, pit);
+pcspk_init(isa_new(TYPE_PC_SPEAKER), isa_bus, pit);
 
 /* Video card */
 switch (jazz_model) {
-- 
2.18.4



[PATCH v5 00/20] audio: deprecate -soundhw

2020-07-02 Thread Gerd Hoffmann
v2:
 - use g_assert_not_reached() for stubs.
 - add deprecation notice.

v3:
 - rebase to latest master.
 - adapt to armbru's device initialization changes.

v4:
 - reorder patches, drop temporary -global setup,
   go straight to -machine pcspk-audiodev= instead.
 - update error messages and documentation accordingly.

v5:
 - spell fixes (Eric).
 - fix mips build error.

Gerd Hoffmann (20):
  stubs: add isa_create_simple
  stubs: add pci_create_simple
  audio: add deprecated_register_soundhw
  audio: deprecate -soundhw ac97
  audio: deprecate -soundhw es1370
  audio: deprecate -soundhw adlib
  audio: deprecate -soundhw cs4231a
  audio: deprecate -soundhw gus
  audio: deprecate -soundhw sb16
  audio: deprecate -soundhw hda
  pc_basic_device_init: pass PCMachineState
  pc_basic_device_init: drop has_pit arg
  pc_basic_device_init: drop no_vmport arg
  softmmu: initialize spice and audio earlier
  audio: rework pcspk_init()
  audio: create pcspk device early
  audio: deprecate -soundhw pcspk
  audio: add soundhw deprecation notice
  pcspk: update docs/system/target-i386-desc.rst.inc
  audio: set default value for pcspk.iobase property

 include/hw/audio/pcspk.h | 12 ++--
 include/hw/audio/soundhw.h   |  2 ++
 include/hw/i386/pc.h |  6 +++---
 hw/audio/ac97.c  |  9 ++---
 hw/audio/adlib.c |  8 +---
 hw/audio/cs4231a.c   |  8 +---
 hw/audio/es1370.c|  9 ++---
 hw/audio/gus.c   |  8 +---
 hw/audio/intel-hda.c |  3 +++
 hw/audio/pcspk.c | 26 ++
 hw/audio/sb16.c  |  9 ++---
 hw/audio/soundhw.c   | 24 +++-
 hw/i386/pc.c | 14 --
 hw/i386/pc_piix.c|  3 +--
 hw/i386/pc_q35.c |  3 +--
 hw/isa/i82378.c  |  2 +-
 hw/mips/jazz.c   |  2 +-
 qdev-monitor.c   |  2 ++
 softmmu/vl.c | 12 ++--
 stubs/isa-bus.c  |  7 +++
 stubs/pci-bus.c  |  7 +++
 docs/system/deprecated.rst   |  9 +
 docs/system/target-i386-desc.rst.inc | 13 -
 stubs/Makefile.objs  |  2 ++
 24 files changed, 121 insertions(+), 79 deletions(-)
 create mode 100644 stubs/isa-bus.c
 create mode 100644 stubs/pci-bus.c

-- 
2.18.4



  1   2   3   4   5   >