diff mbox

[4/6] fw_cfg: move fw_cfg_init1() into the fw_cfg_*_realize() functions

Message ID 1497097821-32754-5-git-send-email-mark.cave-ayland@ilande.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Mark Cave-Ayland June 10, 2017, 12:30 p.m. UTC
And rename to fw_cfg_common_realize() which better describes its role.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nvram/fw_cfg.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Igor Mammedov June 12, 2017, 12:03 p.m. UTC | #1
On Sat, 10 Jun 2017 13:30:19 +0100
Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> wrote:

> And rename to fw_cfg_common_realize() which better describes its role.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nvram/fw_cfg.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
> index f7b78a9..87b4392 100644
> --- a/hw/nvram/fw_cfg.c
> +++ b/hw/nvram/fw_cfg.c
> @@ -910,7 +910,7 @@ static void fw_cfg_machine_ready(struct Notifier *n, void *data)
>  
>  
>  
> -static void fw_cfg_init1(DeviceState *dev)
> +static void fw_cfg_common_realize(DeviceState *dev)
>  {
>      FWCfgState *s = FW_CFG(dev);
>      MachineState *machine = MACHINE(qdev_get_machine());
> @@ -951,7 +951,6 @@ FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
>          qdev_prop_set_bit(dev, "dma_enabled", false);
>      }
>  
> -    fw_cfg_init1(dev);
>      qdev_init_nofail(dev);
>  
>      s = FW_CFG(dev);
> @@ -985,7 +984,6 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
>          qdev_prop_set_bit(dev, "dma_enabled", false);
>      }
>  
> -    fw_cfg_init1(dev);
>      qdev_init_nofail(dev);
>  
>      sbd = SYS_BUS_DEVICE(dev);
> @@ -1085,6 +1083,8 @@ static void fw_cfg_io_realize(DeviceState *dev, Error **errp)
>          return;
>      }
>  
> +    fw_cfg_common_realize(dev);
For QOM objects it's done with inheritance, see 9f318f8f7e6 for example.

i.e. define in parent TYPE_FW_CFG.realize and call it from children.
You also can dedup fw_cfg_mem_realize/fw_cfg_mem_realize and
move common code into new fw_cfg_realize()
diff mbox

Patch

diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index f7b78a9..87b4392 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -910,7 +910,7 @@  static void fw_cfg_machine_ready(struct Notifier *n, void *data)
 
 
 
-static void fw_cfg_init1(DeviceState *dev)
+static void fw_cfg_common_realize(DeviceState *dev)
 {
     FWCfgState *s = FW_CFG(dev);
     MachineState *machine = MACHINE(qdev_get_machine());
@@ -951,7 +951,6 @@  FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
         qdev_prop_set_bit(dev, "dma_enabled", false);
     }
 
-    fw_cfg_init1(dev);
     qdev_init_nofail(dev);
 
     s = FW_CFG(dev);
@@ -985,7 +984,6 @@  FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
         qdev_prop_set_bit(dev, "dma_enabled", false);
     }
 
-    fw_cfg_init1(dev);
     qdev_init_nofail(dev);
 
     sbd = SYS_BUS_DEVICE(dev);
@@ -1085,6 +1083,8 @@  static void fw_cfg_io_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    fw_cfg_common_realize(dev);
+
     /* when using port i/o, the 8-bit data register ALWAYS overlaps
      * with half of the 16-bit control register. Hence, the total size
      * of the i/o region used is FW_CFG_CTL_SIZE */
@@ -1138,6 +1138,8 @@  static void fw_cfg_mem_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    fw_cfg_common_realize(dev);
+
     memory_region_init_io(&s->ctl_iomem, OBJECT(s), &fw_cfg_ctl_mem_ops,
                           FW_CFG(s), "fwcfg.ctl", FW_CFG_CTL_SIZE);
     sysbus_init_mmio(sbd, &s->ctl_iomem);