Skip to content

Commit

Permalink
usb: inline device creation functions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bonzini committed Feb 16, 2024
1 parent 99d0dcd commit 726c609
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
23 changes: 0 additions & 23 deletions hw/usb/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
27 changes: 24 additions & 3 deletions include/hw/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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

0 comments on commit 726c609

Please sign in to comment.