diff mbox series

[v2,1/3] hw/arm/sbsa-ref: Do not open-code ahci_ide_create_devs()

Message ID 20240225171637.4709-2-philmd@linaro.org
State Superseded
Headers show
Series hw/ide: Make "ide_internal.h" really internal | expand

Commit Message

Philippe Mathieu-Daudé Feb. 25, 2024, 5:16 p.m. UTC
Use ahci_ide_create_devs() instead of open-coding it.
Not accessing AHCIDevice internals anymore allows to
remove "hw/ide/ahci_internal.h" (which isn't really a
public header).

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/arm/sbsa-ref.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

Comments

Philippe Mathieu-Daudé Feb. 25, 2024, 5:21 p.m. UTC | #1
On 25/2/24 18:16, Philippe Mathieu-Daudé wrote:
> Use ahci_ide_create_devs() instead of open-coding it.
> Not accessing AHCIDevice internals anymore allows to
> remove "hw/ide/ahci_internal.h" (which isn't really a
> public header).
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/arm/sbsa-ref.c | 9 +--------
>   1 file changed, 1 insertion(+), 8 deletions(-)
> 
> diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
> index 5d3a574664..995c7be23e 100644
> --- a/hw/arm/sbsa-ref.c
> +++ b/hw/arm/sbsa-ref.c
> @@ -37,7 +37,6 @@
>   #include "hw/block/flash.h"
>   #include "hw/boards.h"
>   #include "hw/ide/internal.h"
> -#include "hw/ide/ahci_internal.h"
>   #include "hw/ide/ahci-sysbus.h"
>   #include "hw/intc/arm_gicv3_common.h"
>   #include "hw/intc/arm_gicv3_its_common.h"
> @@ -572,7 +571,6 @@ static void create_ahci(const SBSAMachineState *sms)
>       DriveInfo *hd[NUM_SATA_PORTS];
>       SysbusAHCIState *sysahci;
>       AHCIState *ahci;
> -    int i;
>   
>       dev = qdev_new("sysbus-ahci");
>       qdev_prop_set_uint32(dev, "num-ports", NUM_SATA_PORTS);
> @@ -583,12 +581,7 @@ static void create_ahci(const SBSAMachineState *sms)
>       sysahci = SYSBUS_AHCI(dev);
>       ahci = &sysahci->ahci;

Bah, we can even remove that 'ahci' variable.

>       ide_drive_get(hd, ARRAY_SIZE(hd));
> -    for (i = 0; i < ahci->ports; i++) {
> -        if (hd[i] == NULL) {
> -            continue;
> -        }
> -        ide_bus_create_drive(&ahci->dev[i].port, 0, hd[i]);
> -    }
> +    ahci_ide_create_devs(ahci, hd);
>   }

-- >8 --
@@ -571,8 +570,6 @@ static void create_ahci(const SBSAMachineState *sms)
      DeviceState *dev;
      DriveInfo *hd[NUM_SATA_PORTS];
      SysbusAHCIState *sysahci;
-    AHCIState *ahci;
-    int i;

      dev = qdev_new("sysbus-ahci");
      qdev_prop_set_uint32(dev, "num-ports", NUM_SATA_PORTS);
@@ -581,14 +578,8 @@ static void create_ahci(const SBSAMachineState *sms)
      sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, 
qdev_get_gpio_in(sms->gic, irq));

      sysahci = SYSBUS_AHCI(dev);
-    ahci = &sysahci->ahci;
      ide_drive_get(hd, ARRAY_SIZE(hd));
-    for (i = 0; i < ahci->ports; i++) {
-        if (hd[i] == NULL) {
-            continue;
-        }
-        ide_bus_create_drive(&ahci->dev[i].port, 0, hd[i]);
-    }
+    ahci_ide_create_devs(&sysahci->ahci, hd);
  }
---
Thomas Huth Feb. 26, 2024, 6:18 a.m. UTC | #2
On 25/02/2024 18.21, Philippe Mathieu-Daudé wrote:
> On 25/2/24 18:16, Philippe Mathieu-Daudé wrote:
>> Use ahci_ide_create_devs() instead of open-coding it.
>> Not accessing AHCIDevice internals anymore allows to
>> remove "hw/ide/ahci_internal.h" (which isn't really a
>> public header).
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   hw/arm/sbsa-ref.c | 9 +--------
>>   1 file changed, 1 insertion(+), 8 deletions(-)
>>
>> diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
>> index 5d3a574664..995c7be23e 100644
>> --- a/hw/arm/sbsa-ref.c
>> +++ b/hw/arm/sbsa-ref.c
>> @@ -37,7 +37,6 @@
>>   #include "hw/block/flash.h"
>>   #include "hw/boards.h"
>>   #include "hw/ide/internal.h"
>> -#include "hw/ide/ahci_internal.h"
>>   #include "hw/ide/ahci-sysbus.h"
>>   #include "hw/intc/arm_gicv3_common.h"
>>   #include "hw/intc/arm_gicv3_its_common.h"
>> @@ -572,7 +571,6 @@ static void create_ahci(const SBSAMachineState *sms)
>>       DriveInfo *hd[NUM_SATA_PORTS];
>>       SysbusAHCIState *sysahci;
>>       AHCIState *ahci;
>> -    int i;
>>       dev = qdev_new("sysbus-ahci");
>>       qdev_prop_set_uint32(dev, "num-ports", NUM_SATA_PORTS);
>> @@ -583,12 +581,7 @@ static void create_ahci(const SBSAMachineState *sms)
>>       sysahci = SYSBUS_AHCI(dev);
>>       ahci = &sysahci->ahci;
> 
> Bah, we can even remove that 'ahci' variable.
> 
>>       ide_drive_get(hd, ARRAY_SIZE(hd));
>> -    for (i = 0; i < ahci->ports; i++) {
>> -        if (hd[i] == NULL) {
>> -            continue;
>> -        }
>> -        ide_bus_create_drive(&ahci->dev[i].port, 0, hd[i]);
>> -    }
>> +    ahci_ide_create_devs(ahci, hd);
>>   }
> 
> -- >8 --
> @@ -571,8 +570,6 @@ static void create_ahci(const SBSAMachineState *sms)
>       DeviceState *dev;
>       DriveInfo *hd[NUM_SATA_PORTS];
>       SysbusAHCIState *sysahci;
> -    AHCIState *ahci;
> -    int i;
> 
>       dev = qdev_new("sysbus-ahci");
>       qdev_prop_set_uint32(dev, "num-ports", NUM_SATA_PORTS);
> @@ -581,14 +578,8 @@ static void create_ahci(const SBSAMachineState *sms)
>       sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, qdev_get_gpio_in(sms->gic, 
> irq));
> 
>       sysahci = SYSBUS_AHCI(dev);
> -    ahci = &sysahci->ahci;
>       ide_drive_get(hd, ARRAY_SIZE(hd));
> -    for (i = 0; i < ahci->ports; i++) {
> -        if (hd[i] == NULL) {
> -            continue;
> -        }
> -        ide_bus_create_drive(&ahci->dev[i].port, 0, hd[i]);
> -    }
> +    ahci_ide_create_devs(&sysahci->ahci, hd);
>   }

Reviewed-by: Thomas Huth <thuth@redhat.com>
diff mbox series

Patch

diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
index 5d3a574664..995c7be23e 100644
--- a/hw/arm/sbsa-ref.c
+++ b/hw/arm/sbsa-ref.c
@@ -37,7 +37,6 @@ 
 #include "hw/block/flash.h"
 #include "hw/boards.h"
 #include "hw/ide/internal.h"
-#include "hw/ide/ahci_internal.h"
 #include "hw/ide/ahci-sysbus.h"
 #include "hw/intc/arm_gicv3_common.h"
 #include "hw/intc/arm_gicv3_its_common.h"
@@ -572,7 +571,6 @@  static void create_ahci(const SBSAMachineState *sms)
     DriveInfo *hd[NUM_SATA_PORTS];
     SysbusAHCIState *sysahci;
     AHCIState *ahci;
-    int i;
 
     dev = qdev_new("sysbus-ahci");
     qdev_prop_set_uint32(dev, "num-ports", NUM_SATA_PORTS);
@@ -583,12 +581,7 @@  static void create_ahci(const SBSAMachineState *sms)
     sysahci = SYSBUS_AHCI(dev);
     ahci = &sysahci->ahci;
     ide_drive_get(hd, ARRAY_SIZE(hd));
-    for (i = 0; i < ahci->ports; i++) {
-        if (hd[i] == NULL) {
-            continue;
-        }
-        ide_bus_create_drive(&ahci->dev[i].port, 0, hd[i]);
-    }
+    ahci_ide_create_devs(ahci, hd);
 }
 
 static void create_xhci(const SBSAMachineState *sms)