diff mbox series

[v2,03/19] hw/char/serial-pci-multi: Introduce PCI_MULTISERIAL QOM abstract parent

Message ID 20230213070820.76881-4-philmd@linaro.org
State Superseded
Headers show
Series hw: Use QOM macros and remove DO_UPCAST() uses | expand

Commit Message

Philippe Mathieu-Daudé Feb. 13, 2023, 7:08 a.m. UTC
Introduce PCI_MULTISERIAL ("pci-serial"), QOM abstract parent of
"pci-serial-2x" and "pci-serial-4x".

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/char/serial-pci-multi.c | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

Comments

Philippe Mathieu-Daudé Feb. 13, 2023, 7:51 a.m. UTC | #1
On 13/2/23 08:08, Philippe Mathieu-Daudé wrote:
> Introduce PCI_MULTISERIAL ("pci-serial"), QOM abstract parent of
> "pci-serial-2x" and "pci-serial-4x".
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/char/serial-pci-multi.c | 35 ++++++++++++++++++++---------------
>   1 file changed, 20 insertions(+), 15 deletions(-)
> 
> diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c
> index 54768d3d53..faeb0a9476 100644
> --- a/hw/char/serial-pci-multi.c
> +++ b/hw/char/serial-pci-multi.c
> @@ -38,8 +38,15 @@
>   
>   #define PCI_SERIAL_MAX_PORTS 4
>   
> -typedef struct PCIMultiSerialState {
> +#define TYPE_PCI_MULTISERIAL  "pci-serial"

Ouch, copy/paste mistake, this should be "pci-serial-multi".

> +
> +OBJECT_DECLARE_SIMPLE_TYPE(PCIMultiSerialState, PCI_MULTISERIAL)
> +
> +struct PCIMultiSerialState {
> +    /*< private >*/
>       PCIDevice    dev;
> +    /*< public >*/
> +
>       MemoryRegion iobar;
>       uint32_t     ports;
>       char         *name[PCI_SERIAL_MAX_PORTS];
> @@ -47,7 +54,7 @@ typedef struct PCIMultiSerialState {
>       uint32_t     level[PCI_SERIAL_MAX_PORTS];
>       qemu_irq     *irqs;
>       uint8_t      prog_if;
> -} PCIMultiSerialState;
> +};
>   
>   static void multi_serial_pci_exit(PCIDevice *dev)
>   {
> @@ -191,25 +198,23 @@ static void multi_serial_init(Object *o)
>   
>   static const TypeInfo multi_serial_pci_types[] = {
>       {
> -        .name          = "pci-serial-2x",
> -        .parent        = TYPE_PCI_DEVICE,
> -        .instance_size = sizeof(PCIMultiSerialState),
> -        .instance_init = multi_serial_init,
> -        .class_init    = multi_2x_serial_pci_class_initfn,
> -        .interfaces = (InterfaceInfo[]) {
> +        .name           = TYPE_PCI_MULTISERIAL,
> +        .parent         = TYPE_PCI_DEVICE,
> +        .instance_size  = sizeof(PCIMultiSerialState),
> +        .instance_init  = multi_serial_init,
> +        .abstract       = true,
> +        .interfaces     = (InterfaceInfo[]) {
>               { INTERFACE_CONVENTIONAL_PCI_DEVICE },
>               { },
>           },
> +    }, {
> +        .name          = "pci-serial-2x",
> +        .parent        = TYPE_PCI_MULTISERIAL,
> +        .class_init    = multi_2x_serial_pci_class_initfn,
>       }, {
>           .name          = "pci-serial-4x",
> -        .parent        = TYPE_PCI_DEVICE,
> -        .instance_size = sizeof(PCIMultiSerialState),
> -        .instance_init = multi_serial_init,
> +        .parent        = TYPE_PCI_MULTISERIAL,
>           .class_init    = multi_4x_serial_pci_class_initfn,
> -        .interfaces = (InterfaceInfo[]) {
> -            { INTERFACE_CONVENTIONAL_PCI_DEVICE },
> -            { },
> -        },
>       }
>   };
>
diff mbox series

Patch

diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c
index 54768d3d53..faeb0a9476 100644
--- a/hw/char/serial-pci-multi.c
+++ b/hw/char/serial-pci-multi.c
@@ -38,8 +38,15 @@ 
 
 #define PCI_SERIAL_MAX_PORTS 4
 
-typedef struct PCIMultiSerialState {
+#define TYPE_PCI_MULTISERIAL  "pci-serial"
+
+OBJECT_DECLARE_SIMPLE_TYPE(PCIMultiSerialState, PCI_MULTISERIAL)
+
+struct PCIMultiSerialState {
+    /*< private >*/
     PCIDevice    dev;
+    /*< public >*/
+
     MemoryRegion iobar;
     uint32_t     ports;
     char         *name[PCI_SERIAL_MAX_PORTS];
@@ -47,7 +54,7 @@  typedef struct PCIMultiSerialState {
     uint32_t     level[PCI_SERIAL_MAX_PORTS];
     qemu_irq     *irqs;
     uint8_t      prog_if;
-} PCIMultiSerialState;
+};
 
 static void multi_serial_pci_exit(PCIDevice *dev)
 {
@@ -191,25 +198,23 @@  static void multi_serial_init(Object *o)
 
 static const TypeInfo multi_serial_pci_types[] = {
     {
-        .name          = "pci-serial-2x",
-        .parent        = TYPE_PCI_DEVICE,
-        .instance_size = sizeof(PCIMultiSerialState),
-        .instance_init = multi_serial_init,
-        .class_init    = multi_2x_serial_pci_class_initfn,
-        .interfaces = (InterfaceInfo[]) {
+        .name           = TYPE_PCI_MULTISERIAL,
+        .parent         = TYPE_PCI_DEVICE,
+        .instance_size  = sizeof(PCIMultiSerialState),
+        .instance_init  = multi_serial_init,
+        .abstract       = true,
+        .interfaces     = (InterfaceInfo[]) {
             { INTERFACE_CONVENTIONAL_PCI_DEVICE },
             { },
         },
+    }, {
+        .name          = "pci-serial-2x",
+        .parent        = TYPE_PCI_MULTISERIAL,
+        .class_init    = multi_2x_serial_pci_class_initfn,
     }, {
         .name          = "pci-serial-4x",
-        .parent        = TYPE_PCI_DEVICE,
-        .instance_size = sizeof(PCIMultiSerialState),
-        .instance_init = multi_serial_init,
+        .parent        = TYPE_PCI_MULTISERIAL,
         .class_init    = multi_4x_serial_pci_class_initfn,
-        .interfaces = (InterfaceInfo[]) {
-            { INTERFACE_CONVENTIONAL_PCI_DEVICE },
-            { },
-        },
     }
 };