[PATCH v3 1/9] usb: inline device creation functions

Paolo Bonzini posted 9 patches 9 months, 2 weeks ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Thomas Huth <thuth@redhat.com>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Beraldo Leal <bleal@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Huacai Chen <chenhuacai@kernel.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Gerd Hoffmann <kraxel@redhat.com>, Aurelien Jarno <aurelien@aurel32.net>
[PATCH v3 1/9] usb: inline device creation functions
Posted by Paolo Bonzini 9 months, 2 weeks ago
Allow boards to use the device creation functions even if USB itself
is not available; of course the functions will fail inexorably, but
this can be okay if the calls are conditional on the existence of
some USB host controller device.  This is for example the case for
hw/mips/loongson3_virt.c.

Acked-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/hw/usb.h | 27 ++++++++++++++++++++++++---
 hw/usb/bus.c     | 23 -----------------------
 2 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/include/hw/usb.h b/include/hw/usb.h
index 32c23a5ca2a..cfeead28403 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -30,6 +30,7 @@
 #include "qemu/iov.h"
 #include "qemu/queue.h"
 #include "qom/object.h"
+#include "qapi/error.h"
 
 /* Constants related to the USB / PCI interaction */
 #define USB_SBRN    0x60 /* Serial Bus Release Number Register */
@@ -500,9 +501,6 @@ 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)(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);
 USBDevice *usbdevice_create(const char *cmdline);
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
                        USBPortOps *ops, int speedmask);
@@ -582,4 +580,27 @@ void usb_pcap_init(FILE *fp);
 void usb_pcap_ctrl(USBPacket *p, bool setup);
 void usb_pcap_data(USBPacket *p, bool setup);
 
+static inline USBDevice *usb_new(const char *name)
+{
+    return USB_DEVICE(qdev_new(name));
+}
+
+static inline USBDevice *usb_try_new(const char *name)
+{
+    return USB_DEVICE(qdev_try_new(name));
+}
+
+static inline bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, Error **errp)
+{
+    return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp);
+}
+
+static inline USBDevice *usb_create_simple(USBBus *bus, const char *name)
+{
+    USBDevice *dev = usb_new(name);
+
+    usb_realize_and_unref(dev, bus, &error_abort);
+    return dev;
+}
+
 #endif
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 59c39945ddd..76fda41b7ec 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -329,29 +329,6 @@ void usb_legacy_register(const char *typename, const char *usbdevice_name,
     }
 }
 
-USBDevice *usb_new(const char *name)
-{
-    return USB_DEVICE(qdev_new(name));
-}
-
-static USBDevice *usb_try_new(const char *name)
-{
-    return USB_DEVICE(qdev_try_new(name));
-}
-
-bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, Error **errp)
-{
-    return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp);
-}
-
-USBDevice *usb_create_simple(USBBus *bus, const char *name)
-{
-    USBDevice *dev = usb_new(name);
-
-    usb_realize_and_unref(dev, bus, &error_abort);
-    return dev;
-}
-
 static void usb_fill_port(USBPort *port, void *opaque, int index,
                           USBPortOps *ops, int speedmask)
 {
-- 
2.43.0
Re: [PATCH v3 1/9] usb: inline device creation functions
Posted by Philippe Mathieu-Daudé 9 months, 1 week ago
On 13/2/24 16:49, Paolo Bonzini wrote:
> Allow boards to use the device creation functions even if USB itself
> is not available; of course the functions will fail inexorably, but
> this can be okay if the calls are conditional on the existence of
> some USB host controller device.  This is for example the case for
> hw/mips/loongson3_virt.c.
> 
> Acked-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   include/hw/usb.h | 27 ++++++++++++++++++++++++---
>   hw/usb/bus.c     | 23 -----------------------
>   2 files changed, 24 insertions(+), 26 deletions(-)

See alternatives:
https://lore.kernel.org/qemu-devel/20240216110313.17039-10-philmd@linaro.org/
https://lore.kernel.org/qemu-devel/20240216110313.17039-11-philmd@linaro.org/
Re: [PATCH v3 1/9] usb: inline device creation functions
Posted by Paolo Bonzini 9 months, 1 week ago
On Fri, Feb 16, 2024 at 12:14 PM Philippe Mathieu-Daudé
<philmd@linaro.org> wrote:
>
> On 13/2/24 16:49, Paolo Bonzini wrote:
> > Allow boards to use the device creation functions even if USB itself
> > is not available; of course the functions will fail inexorably, but
> > this can be okay if the calls are conditional on the existence of
> > some USB host controller device.  This is for example the case for
> > hw/mips/loongson3_virt.c.
> >
> > Acked-by: Richard Henderson <richard.henderson@linaro.org>
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > ---
> >   include/hw/usb.h | 27 ++++++++++++++++++++++++---
> >   hw/usb/bus.c     | 23 -----------------------
> >   2 files changed, 24 insertions(+), 26 deletions(-)
>
> See alternatives:
> https://lore.kernel.org/qemu-devel/20240216110313.17039-10-philmd@linaro.org/
> https://lore.kernel.org/qemu-devel/20240216110313.17039-11-philmd@linaro.org/

That doesn't include usb_create_simple(), which is the one that
matters the most here.

Paolo