Patchwork [v2,03/30] net/pcnet-pci: QOM Upcast Sweep

login
register
mail settings
Submitter Peter Crosthwaite
Date June 24, 2013, 6:52 a.m.
Message ID <9c7472accbd24d1720a257a63109897a96dfed55.1372055322.git.peter.crosthwaite@xilinx.com>
Download mbox | patch
Permalink /patch/253660/
State New
Headers show

Comments

Peter Crosthwaite - June 24, 2013, 6:52 a.m.
From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct -> style upcasting.

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
---

 hw/net/pcnet-pci.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
Andreas Färber - June 30, 2013, 7:34 a.m.
Am 24.06.2013 08:52, schrieb peter.crosthwaite@xilinx.com:
> From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> 
> Define and use standard QOM cast macro. Remove usages of DO_UPCAST
> and direct -> style upcasting.
> 
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> ---
> 
>  hw/net/pcnet-pci.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/net/pcnet-pci.c b/hw/net/pcnet-pci.c
> index 9df2b87..b1afbf4 100644
> --- a/hw/net/pcnet-pci.c
> +++ b/hw/net/pcnet-pci.c
> @@ -43,6 +43,10 @@
>  //#define PCNET_DEBUG_TMD
>  //#define PCNET_DEBUG_MATCH
>  
> +#define TYPE_PCI_PC_NET "pcnet"

I'm wondering whether we should rename this PCNET rather than PC_NET,
but I'm queuing it as is. Thanks,

Andreas

> +
> +#define PCI_PC_NET(obj) \
> +     OBJECT_CHECK(PCIPCNetState, (obj), TYPE_PCI_PC_NET)
>  
>  typedef struct {
>      PCIDevice pci_dev;
> @@ -273,7 +277,7 @@ static void pci_pcnet_cleanup(NetClientState *nc)
>  
>  static void pci_pcnet_uninit(PCIDevice *dev)
>  {
> -    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, dev);
> +    PCIPCNetState *d = PCI_PC_NET(dev);
>  
>      memory_region_destroy(&d->state.mmio);
>      memory_region_destroy(&d->io_bar);
> @@ -293,7 +297,7 @@ static NetClientInfo net_pci_pcnet_info = {
>  
>  static int pci_pcnet_init(PCIDevice *pci_dev)
>  {
> -    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev);
> +    PCIPCNetState *d = PCI_PC_NET(pci_dev);
>      PCNetState *s = &d->state;
>      uint8_t *pci_conf;
>  
> @@ -329,12 +333,12 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
>      s->phys_mem_write = pci_physical_memory_write;
>      s->dma_opaque = pci_dev;
>  
> -    return pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info);
> +    return pcnet_common_init(DEVICE(pci_dev), s, &net_pci_pcnet_info);
>  }
>  
>  static void pci_reset(DeviceState *dev)
>  {
> -    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev.qdev, dev);
> +    PCIPCNetState *d = PCI_PC_NET(dev);
>  
>      pcnet_h_reset(&d->state);
>  }
> @@ -362,7 +366,7 @@ static void pcnet_class_init(ObjectClass *klass, void *data)
>  }
>  
>  static const TypeInfo pcnet_info = {
> -    .name          = "pcnet",
> +    .name          = TYPE_PCI_PC_NET,
>      .parent        = TYPE_PCI_DEVICE,
>      .instance_size = sizeof(PCIPCNetState),
>      .class_init    = pcnet_class_init,
>
Andreas Färber - July 22, 2013, 5:17 p.m.
Am 30.06.2013 09:34, schrieb Andreas Färber:
> Am 24.06.2013 08:52, schrieb peter.crosthwaite@xilinx.com:
>> From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>>
>> Define and use standard QOM cast macro. Remove usages of DO_UPCAST
>> and direct -> style upcasting.
>>
>> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>> ---
>>
>>  hw/net/pcnet-pci.c | 14 +++++++++-----
>>  1 file changed, 9 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/net/pcnet-pci.c b/hw/net/pcnet-pci.c
>> index 9df2b87..b1afbf4 100644
>> --- a/hw/net/pcnet-pci.c
>> +++ b/hw/net/pcnet-pci.c
>> @@ -43,6 +43,10 @@
>>  //#define PCNET_DEBUG_TMD
>>  //#define PCNET_DEBUG_MATCH
>>  
>> +#define TYPE_PCI_PC_NET "pcnet"
> 
> I'm wondering whether we should rename this PCNET rather than PC_NET,
> but I'm queuing it as is. Thanks,

In light of the MP_TIMER vs. MPTIMER discussion elsewhere I'm changing
both patches, i.e. TYPE_PCI_PCNET and PCI_PCNET() here, in line with
pcnet_ prefix.

Andreas

>> +
>> +#define PCI_PC_NET(obj) \
>> +     OBJECT_CHECK(PCIPCNetState, (obj), TYPE_PCI_PC_NET)
>>  
>>  typedef struct {
>>      PCIDevice pci_dev;
>> @@ -273,7 +277,7 @@ static void pci_pcnet_cleanup(NetClientState *nc)
>>  
>>  static void pci_pcnet_uninit(PCIDevice *dev)
>>  {
>> -    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, dev);
>> +    PCIPCNetState *d = PCI_PC_NET(dev);
>>  
>>      memory_region_destroy(&d->state.mmio);
>>      memory_region_destroy(&d->io_bar);
>> @@ -293,7 +297,7 @@ static NetClientInfo net_pci_pcnet_info = {
>>  
>>  static int pci_pcnet_init(PCIDevice *pci_dev)
>>  {
>> -    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev);
>> +    PCIPCNetState *d = PCI_PC_NET(pci_dev);
>>      PCNetState *s = &d->state;
>>      uint8_t *pci_conf;
>>  
>> @@ -329,12 +333,12 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
>>      s->phys_mem_write = pci_physical_memory_write;
>>      s->dma_opaque = pci_dev;
>>  
>> -    return pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info);
>> +    return pcnet_common_init(DEVICE(pci_dev), s, &net_pci_pcnet_info);
>>  }
>>  
>>  static void pci_reset(DeviceState *dev)
>>  {
>> -    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev.qdev, dev);
>> +    PCIPCNetState *d = PCI_PC_NET(dev);
>>  
>>      pcnet_h_reset(&d->state);
>>  }
>> @@ -362,7 +366,7 @@ static void pcnet_class_init(ObjectClass *klass, void *data)
>>  }
>>  
>>  static const TypeInfo pcnet_info = {
>> -    .name          = "pcnet",
>> +    .name          = TYPE_PCI_PC_NET,
>>      .parent        = TYPE_PCI_DEVICE,
>>      .instance_size = sizeof(PCIPCNetState),
>>      .class_init    = pcnet_class_init,
>>
> 
>

Patch

diff --git a/hw/net/pcnet-pci.c b/hw/net/pcnet-pci.c
index 9df2b87..b1afbf4 100644
--- a/hw/net/pcnet-pci.c
+++ b/hw/net/pcnet-pci.c
@@ -43,6 +43,10 @@ 
 //#define PCNET_DEBUG_TMD
 //#define PCNET_DEBUG_MATCH
 
+#define TYPE_PCI_PC_NET "pcnet"
+
+#define PCI_PC_NET(obj) \
+     OBJECT_CHECK(PCIPCNetState, (obj), TYPE_PCI_PC_NET)
 
 typedef struct {
     PCIDevice pci_dev;
@@ -273,7 +277,7 @@  static void pci_pcnet_cleanup(NetClientState *nc)
 
 static void pci_pcnet_uninit(PCIDevice *dev)
 {
-    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, dev);
+    PCIPCNetState *d = PCI_PC_NET(dev);
 
     memory_region_destroy(&d->state.mmio);
     memory_region_destroy(&d->io_bar);
@@ -293,7 +297,7 @@  static NetClientInfo net_pci_pcnet_info = {
 
 static int pci_pcnet_init(PCIDevice *pci_dev)
 {
-    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev);
+    PCIPCNetState *d = PCI_PC_NET(pci_dev);
     PCNetState *s = &d->state;
     uint8_t *pci_conf;
 
@@ -329,12 +333,12 @@  static int pci_pcnet_init(PCIDevice *pci_dev)
     s->phys_mem_write = pci_physical_memory_write;
     s->dma_opaque = pci_dev;
 
-    return pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info);
+    return pcnet_common_init(DEVICE(pci_dev), s, &net_pci_pcnet_info);
 }
 
 static void pci_reset(DeviceState *dev)
 {
-    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev.qdev, dev);
+    PCIPCNetState *d = PCI_PC_NET(dev);
 
     pcnet_h_reset(&d->state);
 }
@@ -362,7 +366,7 @@  static void pcnet_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo pcnet_info = {
-    .name          = "pcnet",
+    .name          = TYPE_PCI_PC_NET,
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(PCIPCNetState),
     .class_init    = pcnet_class_init,