hw/usb: Cleanups around QOM style
cover hw/usb: Cleanups around QOM style
- Use QOM's OBJECT_DECLARE*TYPE() to declare typedef / macros
- Use QOM cast macros instead of container_of()
Philippe Mathieu-Daudé (9):
hw/usb/dev-smartcard-reader: Avoid forward-declaring CCIDBus hw/usb/hcd-ohci: Use OHCIState type definition hw/usb/hcd-ohci-pci: Use QOM type-safe cast conversion macro hw/usb/hcd-uhci: Declare QOM macros using OBJECT_DECLARE_TYPE() hw/usb/hcd-uhci: Replace container_of() by UHCI_GET_CLASS() QOM macro hw/usb/hcd-xhci-nec: Declare QOM macros for NEC_XHCI hw/usb/hcd-xhci-nec: Replace container_of() by NEC_XHCI() QOM cast
macro
hw/usb/u2f: Declare QOM macros using OBJECT_DECLARE_TYPE() hw/usb/u2f-passthru: Use QOM type-safe cast conversion macros
hw/usb/dev-smartcard-reader.c | 7 +++---- hw/usb/hcd-ohci-pci.c | 4 ++-- hw/usb/hcd-ohci.c | 2 +- hw/usb/hcd-ohci.h | 10 ++++++---- hw/usb/hcd-uhci.c | 7 ++----- hw/usb/hcd-uhci.h | 2 +- hw/usb/hcd-xhci-nec.c | 8 +++++--- hw/usb/u2f-passthru.c | 7 ++++--- hw/usb/u2f.h | 16 +++++----------- 9 files changed, 29 insertions(+), 34 deletions(-)
Signature · 1 line
2.38.1
PATCH 1/9 hw/usb/dev-smartcard-reader: Avoid forward-declaring CCIDBus
To avoid forward-declaring CCIDBus, declare CCID_BUS QOM definitions before its use in the USBCCIDState structure.
--- hw/usb/dev-smartcard-reader.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
hw/usb/dev-smartcard-reader.c +3 -4
@@ -278,7 +278,9 @@ typedef struct BulkIn {struct CCIDBus {BusState qbus; }; -typedef struct CCIDBus CCIDBus ; + +#define TYPE_CCID_BUS "ccid-bus" +OBJECT_DECLARE_SIMPLE_TYPE (CCIDBus,CCID_BUS )/* * powered - defaults to true, changed by PowerOn/PowerOff messages
@@ -1174,9 +1176,6 @@ static Property ccid_props[] = { DEFINE_PROP_END_OF_LIST(), }; -#define TYPE_CCID_BUS "ccid-bus" -OBJECT_DECLARE_SIMPLE_TYPE(CCIDBus, CCID_BUS) -static const TypeInfo ccid_bus_info = { .name =TYPE_CCID_BUS , .parent =TYPE_BUS ,
Signature · 1 line
2.38.1
Re: [PATCH 1/9] hw/usb/dev-smartcard-reader: Avoid forward-declaring CCIDBus
Quoted 7 lines · Philippe Mathieu-Daudé
To avoid forward-declaring CCIDBus, declare
CCID_BUSQOM definitions before its use in the USBCCIDState structure.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/usb/dev-smartcard-reader.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
r~
PATCH 2/9 hw/usb/hcd-ohci: Use OHCIState type definition
In reply to Philippe Mathieu-DaudéForward-define the type first, then use it for the ohci_die() handler.
--- hw/usb/hcd-ohci.c | 2 +- hw/usb/hcd-ohci.h | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-)
hw/usb/hcd-ohci.c +1 -1
@@ -1827,7 +1827,7 @@ static USBBusOps ohci_bus_ops = {void usb_ohci_init (OHCIState *ohci,DeviceState *dev,uint32_t num_ports,dma_addr_t localmem_base,char *masterbus,uint32_t firstport,AddressSpace *as, -void (*ohci_die_fn)(struct OHCIState *),Error **errp) +void (*ohci_die_fn)(OHCIState *),Error **errp) {Error *err =NULL ;int i;
hw/usb/hcd-ohci.h +6 -4
@@ -33,7 +33,9 @@ typedef struct OHCIPort {uint32_t ctrl; } OHCIPort; -typedef struct OHCIState { +typedef struct OHCIState OHCIState ; + +struct OHCIState {USBBus bus;qemu_irq irq;MemoryRegion mem;
@@ -89,8 +91,8 @@ typedef struct OHCIState {uint32_t async_td;bool async_complete; -void (*ohci_die)(struct OHCIState *ohci); -} OHCIState; +void (*ohci_die)(OHCIState *ohci); +};#define TYPE_SYSBUS_OHCI "sysbus-ohci"OBJECT_DECLARE_SIMPLE_TYPE (OHCISysBusState,SYSBUS_OHCI )
@@ -112,7 +114,7 @@ extern const VMStateDescription vmstate_ohci_state;void usb_ohci_init (OHCIState *ohci,DeviceState *dev,uint32_t num_ports,dma_addr_t localmem_base,char *masterbus,uint32_t firstport,AddressSpace *as, -void (*ohci_die_fn)(struct OHCIState *),Error **errp); +void (*ohci_die_fn)(OHCIState *),Error **errp);void ohci_bus_stop (OHCIState *ohci);void ohci_stop_endpoints (OHCIState *ohci);void ohci_hard_reset (OHCIState *ohci);
Signature · 1 line
2.38.1
Re: [PATCH 2/9] hw/usb/hcd-ohci: Use OHCIState type definition
Quoted 7 lines · Philippe Mathieu-Daudé
Forward-define the type first, then use it for the
ohci_die()handler.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/usb/hcd-ohci.c | 2 +- hw/usb/hcd-ohci.h | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-)
r~
PATCH 3/9 hw/usb/hcd-ohci-pci: Use QOM type-safe cast conversion macro
In reply to Philippe Mathieu-DaudéUse the PCI_DEVICE() QOM cast macros to avoid accessing internal fields.
--- hw/usb/hcd-ohci-pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/usb/hcd-ohci-pci.c +2 -2
@@ -52,11 +52,11 @@ struct OHCIPCIState {static void ohci_pci_die (struct OHCIState *ohci) {OHCIPCIState *dev =container_of (ohci, OHCIPCIState, state); +PCIDevice *pdev =PCI_DEVICE (dev);ohci_sysbus_die (ohci); -pci_set_word (dev->parent_obj.config +PCI_STATUS , -PCI_STATUS_DETECTED_PARITY ); +pci_set_word (pdev->config +PCI_STATUS ,PCI_STATUS_DETECTED_PARITY ); }static void usb_ohci_realize_pci (PCIDevice *dev,Error **errp)
Signature · 1 line
2.38.1
PATCH 4/9 hw/usb/hcd-uhci: Declare QOM macros using OBJECT_DECLARE_TYPE()
In reply to Philippe Mathieu-DaudéThe automatic conversion done during commit a489d1951c ("Use OBJECT_DECLARE_TYPE when possible") missed this model because the typedefs are in a different file unit (hcd-uhci.c) than where the DECLARE_INSTANCE_CHECKER() is (hcd-uhci.h). Manually convert to OBJECT_DECLARE_TYPE().
--- hw/usb/hcd-uhci.c | 2 -- hw/usb/hcd-uhci.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-)
hw/usb/hcd-uhci.c +0 -2
@@ -60,9 +60,7 @@ enum { TD_RESULT_ASYNC_CONT, }; -typedef struct UHCIState UHCIState ;typedef struct UHCIAsync UHCIAsync ; -typedef struct UHCIPCIDeviceClass UHCIPCIDeviceClass ;struct UHCIPCIDeviceClass {PCIDeviceClass parent_class;
hw/usb/hcd-uhci.h +1 -1
@@ -75,7 +75,7 @@ typedef struct UHCIState { } UHCIState;#define TYPE_UHCI "pci-uhci-usb" -DECLARE_INSTANCE_CHECKER(UHCIState, UHCI, TYPE_UHCI) +OBJECT_DECLARE_TYPE(UHCIState, UHCIPCIDeviceClass, UHCI) typedef struct UHCIInfo { const char *name;
Signature · 1 line
2.38.1
Re: [PATCH 4/9] hw/usb/hcd-uhci: Declare QOM macros using OBJECT_DECLARE_TYPE()
Quoted 11 lines · Philippe Mathieu-Daudé
The automatic conversion done during commit
a489d1951c("UseOBJECT_DECLARE_TYPEwhen possible") missed this model because the typedefs are in a different file unit (hcd-uhci.c) than where theDECLARE_INSTANCE_CHECKER()is (hcd-uhci.h). Manually convert toOBJECT_DECLARE_TYPE().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/usb/hcd-uhci.c | 2 -- hw/usb/hcd-uhci.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-)
r~
PATCH 5/9 hw/usb/hcd-uhci: Replace container_of() by UHCI_GET_CLASS() QOM macro
In reply to Philippe Mathieu-DaudéBy using the QOM UHCI_GET_CLASS() cast macro we don't to use the intermediate PCIDeviceClass variable.
--- hw/usb/hcd-uhci.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/usb/hcd-uhci.c +2 -3
@@ -1159,8 +1159,7 @@ static USBBusOps uhci_bus_ops = {void usb_uhci_common_realize (PCIDevice *dev,Error **errp) {Error *err =NULL ; -PCIDeviceClass *pc =PCI_DEVICE_GET_CLASS (dev); -UHCIPCIDeviceClass *u =container_of (pc, UHCIPCIDeviceClass, parent_class); +UHCIPCIDeviceClass *u =UHCI_GET_CLASS (dev);UHCIState *s =UHCI (dev);uint8_t *pci_conf = s->dev.config;int i;
@@ -1267,7 +1266,7 @@ void uhci_data_class_init(ObjectClass *klass, void *data) {PCIDeviceClass *k =PCI_DEVICE_CLASS (klass);DeviceClass *dc =DEVICE_CLASS (klass); -UHCIPCIDeviceClass *u =container_of (k, UHCIPCIDeviceClass, parent_class); +UHCIPCIDeviceClass *u =UHCI_CLASS (klass);UHCIInfo *info = data; k->realize = info->realize ? info->realize : usb_uhci_common_realize;
Signature · 1 line
2.38.1
Re: [PATCH 5/9] hw/usb/hcd-uhci: Replace container_of() by UHCI_GET_CLASS() QOM macro
Quoted 7 lines · Philippe Mathieu-Daudé
By using the QOM
UHCI_GET_CLASS()cast macro we don't to use the intermediate PCIDeviceClass variable.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/usb/hcd-uhci.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
r~
PATCH 6/9 hw/usb/hcd-xhci-nec: Declare QOM macros for NEC_XHCI
In reply to Philippe Mathieu-DaudéNEC_XHCI is a QOM object type. Declare its macros / typedefs using OBJECT_DECLARE_SIMPLE_TYPE().
--- hw/usb/hcd-xhci-nec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/usb/hcd-xhci-nec.c +4 -2
@@ -27,14 +27,16 @@#include "hcd-xhci-pci.h" -typedef struct XHCINecState { +OBJECT_DECLARE_SIMPLE_TYPE(XHCINecState, NEC_XHCI) + +struct XHCINecState {/*< private >*/ XHCIPciState parent_obj;/*< public >*/ uint32_t flags;uint32_t intrs;uint32_t slots; -}XHCINecState ; +};static Property nec_xhci_properties[] = {DEFINE_PROP_ON_OFF_AUTO ("msi" , XHCIPciState, msi,ON_OFF_AUTO_AUTO ),
Signature · 1 line
2.38.1
Re: [PATCH 6/9] hw/usb/hcd-xhci-nec: Declare QOM macros for NEC_XHCI
Quoted 7 lines · Philippe Mathieu-Daudé
NEC_XHCIis a QOM object type. Declare its macros / typedefs usingOBJECT_DECLARE_SIMPLE_TYPE().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/usb/hcd-xhci-nec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
r~
PATCH 7/9 hw/usb/hcd-xhci-nec: Replace container_of() by NEC_XHCI() QOM cast macro
In reply to Philippe Mathieu-Daudé--- hw/usb/hcd-xhci-nec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/hcd-xhci-nec.c +1 -1
@@ -53,7 +53,7 @@ static Property nec_xhci_properties[] = {static void nec_xhci_instance_init (Object *obj) {XHCIPciState *pci =XHCI_PCI (obj); -XHCINecState *nec =container_of (pci, XHCINecState, parent_obj); +XHCINecState *nec =NEC_XHCI (obj); pci->xhci.flags = nec->flags; pci->xhci.numintrs = nec->intrs;
Signature · 1 line
2.38.1
Re: [PATCH 7/9] hw/usb/hcd-xhci-nec: Replace container_of() by NEC_XHCI() QOM cast macro
Quoted 4 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/usb/hcd-xhci-nec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
PATCH 8/9 hw/usb/u2f: Declare QOM macros using OBJECT_DECLARE_TYPE()
In reply to Philippe Mathieu-Daudéhw/usb/u2f.h was added by commit 80e267f1d1 ("hw/usb: Add U2F key base class"), almost the same time of the automatic conversion done by commit c821774a3b ("Use OBJECT_DECLARE_TYPE where posible"). Manually convert to OBJECT_DECLARE_TYPE().
--- hw/usb/u2f.h | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
hw/usb/u2f.h +5 -11
@@ -31,22 +31,16 @@#define U2FHID_PACKET_SIZE 64#define U2FHID_PENDING_IN_NUM 32 -typedef struct U2FKeyState U2FKeyState ;typedef struct U2FKeyInfo U2FKeyInfo ;#define TYPE_U2F_KEY "u2f-key" -#define U2F_KEY (obj) \ - OBJECT_CHECK(U2FKeyState, (obj), TYPE_U2F_KEY) -#define U2F_KEY_CLASS (klass) \ - OBJECT_CLASS_CHECK(U2FKeyClass, (klass), TYPE_U2F_KEY) -#define U2F_KEY_GET_CLASS (obj) \ - OBJECT_GET_CLASS(U2FKeyClass, (obj), TYPE_U2F_KEY) +OBJECT_DECLARE_TYPE (U2FKeyState, U2FKeyClass,U2F_KEY )/* * Callbacks to be used by the U2F key base device (i.e. hw/u2f.c) * to interact with its variants (i.e. hw/u2f-*.c) */ -typedef struct U2FKeyClass { +struct U2FKeyClass {/*< private >*/ USBDeviceClass parent_class;
@@ -55,12 +49,12 @@ typedef struct U2FKeyClass { const uint8_t packet[U2FHID_PACKET_SIZE]);void (*realize)(U2FKeyState *key,Error **errp);void (*unrealize)(U2FKeyState *key); -} U2FKeyClass; +};/* * State of the U2F key base device (i.e. hw/u2f.c) */ -typedef struct U2FKeyState { +struct U2FKeyState {USBDevice dev;USBEndpoint *ep;uint8_t idle;
@@ -70,7 +64,7 @@ typedef struct U2FKeyState {uint8_t pending_in_start;uint8_t pending_in_end;uint8_t pending_in_num; -} U2FKeyState; +};/* * API to be used by the U2F key device variants (i.e. hw/u2f-*.c)
Signature · 1 line
2.38.1
Re: [PATCH 8/9] hw/usb/u2f: Declare QOM macros using OBJECT_DECLARE_TYPE()
Quoted 9 lines · Philippe Mathieu-Daudé
hw/usb/u2f.hwas added by commit80e267f1d1("hw/usb: Add U2F key base class"), almost the same time of the automatic conversion done by commitc821774a3b("UseOBJECT_DECLARE_TYPEwhere posible"). Manually convert toOBJECT_DECLARE_TYPE().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/usb/u2f.h | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
r~
PATCH 9/9 hw/usb/u2f-passthru: Use QOM type-safe cast conversion macros
In reply to Philippe Mathieu-DaudéUse the QOM cast macros to avoid accessing internal fields.
--- hw/usb/u2f-passthru.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/usb/u2f-passthru.c +4 -3
@@ -299,7 +299,7 @@ static void u2f_passthru_recv_from_host(U2FPassthruState *key,if (transaction->resp_size >= transaction->resp_bcnt) {u2f_transaction_close (key, cid); } -u2f_send_to_guest (&key->base, packet); +u2f_send_to_guest (U2F_KEY (key), packet); }static void u2f_passthru_read (void *opaque)
@@ -316,9 +316,10 @@ static void u2f_passthru_read(void *opaque) ret =read (key->hidraw_fd, packet,sizeof (packet));if (ret <0 ) { +USBDevice *udev =USB_DEVICE (key);/* Detach */ -if (base->dev.attached) { -usb_device_detach (&base->dev); +if (udev->attached) { +usb_device_detach (udev);u2f_passthru_reset (key); }return ;
Signature · 1 line
2.38.1