Skip to contentSkip to conversation

hw/arm/aspeed: Add /machine/labels container

PATCH In review Cédric Le Goater 3 participants 7 messages Sep 4 – Sep 9 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

cover hw/arm/aspeed: Add /machine/labels container

Hello,

Patch 1 adds a DT-style /machine/labels container where board code registers link properties pointing to well-known devices. Tests can then resolve a device with a single qom-get instead of walking the bus hierarchy.

Patch 2 uses it to test the ADC128D818 on the Anacapa machine through the kernel hwmon interface.

Thanks,

C.

Cédric Le Goater (1):
hw/arm: Add /machine/labels container for Aspeed machines

Emmanuel Blot (1):
test/functional: anacapa: test ADC128D818

 include/hw/arm/aspeed.h                     | 12 +++++
 hw/arm/aspeed.c                             | 10 +++++
 hw/arm/aspeed_ast2600_anacapa.c             | 11 +++--
 tests/functional/arm/test_aspeed_anacapa.py | 50 +++++++++++++++++++++
 4 files changed, 79 insertions(+), 4 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/2 hw/arm: Add /machine/labels container for Aspeed machines

Add a DT-style alias container /machine/labels where board code registers link<> properties pointing to well-known devices. Tests can then resolve a device with a single QMP call (qom-get /machine/labels/<name>) instead of walking the bus hierarchy.

---
 include/hw/arm/aspeed.h | 12 ++++++++++++
 hw/arm/aspeed.c         | 10 ++++++++++
 2 files changed, 22 insertions(+)
include/hw/arm/aspeed.h +12 -0
index 245d02e5f757..0b8b40262767 100644
@@ -128,4 +128,16 @@ void aspeed_machine_ast2600_class_emmc_init(ObjectClass *oc);
  */
 void aspeed_connect_serial_hds_to_uarts(AspeedMachineState *bmc);
 
+/*
+ * aspeed_machine_add_label:
+ * @bmc: pointer to the #AspeedMachineState.
+ * @label: the label name for the device.
+ * @target: the device object to register.
+ *
+ * Register a well-known device under /machine/labels/<label> as a
+ * read-only link.  Aborts on duplicate label names.
+ */
+void aspeed_machine_add_label(AspeedMachineState *bmc, const char *label,
+                              Object *target);
+
 #endif
hw/arm/aspeed.c +10 -0
index 1f8d5d3e132d..79b8d55d66da 100644
@@ -127,6 +127,14 @@ void aspeed_connect_serial_hds_to_uarts(AspeedMachineState *bmc)
     }
 }
 
+void aspeed_machine_add_label(AspeedMachineState *bmc, const char *label,
+                              Object *target)
+{
+    Object *labels = object_resolve_path_component(OBJECT(bmc), "labels");
+
+    object_property_add_const_link(labels, label, target);
+}
+
 static void aspeed_machine_init(MachineState *machine)
 {
     AspeedMachineState *bmc = ASPEED_MACHINE(machine);
@@ -137,6 +145,8 @@ static void aspeed_machine_init(MachineState *machine)
     DriveInfo *emmc0 = NULL;
     bool boot_emmc;
 
+    object_property_add_new_container(OBJECT(machine), "labels");
+
     bmc->soc = ASPEED_SOC(object_new(amc->soc_name));
     object_property_add_child(OBJECT(machine), "soc", OBJECT(bmc->soc));
     object_unref(OBJECT(bmc->soc));
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH 1/2] hw/arm: Add /machine/labels container for Aspeed machines

Quoted 52 lines · Cédric Le Goater

Add a DT-style alias container /machine/labels where board code registers link<> properties pointing to well-known devices. Tests can then resolve a device with a single QMP call (qom-get /machine/labels/<name>) instead of walking the bus hierarchy.

---
  include/hw/arm/aspeed.h | 12 ++++++++++++
  hw/arm/aspeed.c         | 10 ++++++++++
  2 files changed, 22 insertions(+)
include/hw/arm/aspeed.h +12 -0
index 245d02e5f757..0b8b40262767 100644
@@ -128,4 +128,16 @@ void aspeed_machine_ast2600_class_emmc_init(ObjectClass *oc);
   */
  void aspeed_connect_serial_hds_to_uarts(AspeedMachineState *bmc);
 
+/*
+ * aspeed_machine_add_label:
+ * @bmc: pointer to the #AspeedMachineState.
+ * @label: the label name for the device.
+ * @target: the device object to register.
+ *
+ * Register a well-known device under /machine/labels/<label> as a
+ * read-only link.  Aborts on duplicate label names.
+ */
+void aspeed_machine_add_label(AspeedMachineState *bmc, const char *label,
+                              Object *target);
+
  #endif
hw/arm/aspeed.c +8 -0
index 1f8d5d3e132d..79b8d55d66da 100644
@@ -127,6 +127,14 @@ void aspeed_connect_serial_hds_to_uarts(AspeedMachineState *bmc)
      }
  }
 
+void aspeed_machine_add_label(AspeedMachineState *bmc, const char *label,
+                              Object *target)
+{
+    Object *labels = object_resolve_path_component(OBJECT(bmc), "labels");
+
+    object_property_add_const_link(labels, label, target);
+}
+
  static void aspeed_machine_init(MachineState *machine)
  {
      AspeedMachineState *bmc = ASPEED_MACHINE(machine);

hw/arm/aspeed.c static void aspeed_machine_init(MachineState *machine) · line 152

Quoted 8 lines
hw/arm/aspeed.c +2 -0
@@ -137,6 +145,8 @@ static void aspeed_machine_init(MachineState *machine)
      DriveInfo *emmc0 = NULL;
      bool boot_emmc;
 
+    object_property_add_new_container(OBJECT(machine), "labels");
+
      bmc->soc = ASPEED_SOC(object_new(amc->soc_name));
      object_property_add_child(OBJECT(machine), "soc", OBJECT(bmc->soc));
      object_unref(OBJECT(bmc->soc));

Thanks for the proposal, Cédric! A few comments from me below:

1) Is there any reason it should be called labels as opposed to aliases? The aliases name as used in Open Firmware feels more intuitive to me.

2) If there is agreement in this approach, is there any reason why we shouldn't create /machine/labels (or equivalent) for all QOM trees? I certainly think it would be a useful addition going forward.

3) Is there any reason why we need to provide the machine object directly to the aspeed_machine_add_label() function? If possible I think it makes sense to avoid the direct machine reference, in case the underlying implementation changes i.e.

  void machine_add_alias(const char *alias, Object *target)
  {
     Object *aliases = object_resolve_path("/machine/aliases",  NULL);
     object_property_add_const_link(aliases, alias, target);

}

Even better perhaps we should also generate an error if the alias already exists to ensure they are always unique i.e.

  bool machine_add_alias(const char *alias, Object *target,
                         Error **errp)
  {
     Object *aliases = object_resolve_path("/machine/aliases",  NULL);
     if (object_resolve_path_component(aliases, alias)) {
         error_setg(errp, "machine alias '%s' already exists");
         return false;
     }

     return (object_property_add_const_link(aliases, alias, target) !=
             NULL);

}

4) Should we create a page in the documentation explaining which devices/objects should be included in the alias list, which ones are added automatically, and what naming conventions should be used for devices e.g. serial0, net0 for a network device etc.?

5) What should happen to aliases for devices that are hot-plugged/hot-unplugged?

ATB,

Mark.

#3 lore raw

Re: [PATCH 1/2] hw/arm: Add /machine/labels container for Aspeed machines

Hello,

Quoted 62 lines · Mark Cave-Ayland
Quoted 50 lines · Cédric Le Goater

Add a DT-style alias container /machine/labels where board code registers link<> properties pointing to well-known devices. Tests can then resolve a device with a single QMP call (qom-get /machine/labels/<name>) instead of walking the bus hierarchy.

---
  include/hw/arm/aspeed.h | 12 ++++++++++++
  hw/arm/aspeed.c         | 10 ++++++++++

  2 files changed, 22 insertions(+)
include/hw/arm/aspeed.h +12 -0
index 245d02e5f757..0b8b40262767 100644
@@ -128,4 +128,16 @@ void aspeed_machine_ast2600_class_emmc_init(ObjectClass *oc);
    */
   void aspeed_connect_serial_hds_to_uarts(AspeedMachineState *bmc);
+/*
+ * aspeed_machine_add_label:
+ * @bmc: pointer to the #AspeedMachineState.
+ * @label: the label name for the device.
+ * @target: the device object to register.
+ *
+ * Register a well-known device under /machine/labels/<label> as a
+ * read-only link.  Aborts on duplicate label names.
+ */
+void aspeed_machine_add_label(AspeedMachineState *bmc, const char *label,
+                              Object *target);
+
   #endif
hw/arm/aspeed.c +8 -0
index 1f8d5d3e132d..79b8d55d66da 100644
@@ -127,6 +127,14 @@ void aspeed_connect_serial_hds_to_uarts(AspeedMachineState *bmc)
       }
   }
+void aspeed_machine_add_label(AspeedMachineState *bmc, const char *label,
+                              Object *target)
+{
+    Object *labels = object_resolve_path_component(OBJECT(bmc), "labels");
+
+    object_property_add_const_link(labels, label, target);
+}
+
   static void aspeed_machine_init(MachineState *machine)
   {
       AspeedMachineState *bmc = ASPEED_MACHINE(machine);

hw/arm/aspeed.c static void aspeed_machine_init(MachineState *machine) · line 151

Quoted 7 lines
hw/arm/aspeed.c +2 -0
@@ -137,6 +145,8 @@ static void aspeed_machine_init(MachineState *machine)
       DriveInfo *emmc0 = NULL;
       bool boot_emmc;
+    object_property_add_new_container(OBJECT(machine), "labels");
+
       bmc->soc = ASPEED_SOC(object_new(amc->soc_name));
       object_property_add_child(OBJECT(machine), "soc", OBJECT(bmc->soc));
       object_unref(OBJECT(bmc->soc));

Thanks for the proposal, Cédric! A few comments from me below:

Quoted 1 line

1) Is there any reason it should be called labels as opposed to aliases?

none

Quoted 1 line

The aliases name as used in Open Firmware feels more intuitive to me.

yes. It it just a name. aliases is fine for me unless it introduces some confusion with object_property_add_alias().

Quoted 2 lines

2) If there is agreement in this approach, is there any reason why we shouldn't create /machine/labels (or equivalent) for all QOM trees? I certainly think it would be a useful addition going forward.

It is a trivial addition. We would need more maintainers to Ack the concept though.

Quoted 2 lines

3) Is there any reason why we need to provide the machine object directly to the aspeed_machine_add_label() function?

Only because it was selfishly introduced as a Aspeed machine helper !

Quoted 9 lines

If possible I think it makes sense to avoid the direct machine reference, in case the underlying implementation changes i.e.

  void machine_add_alias(const char *alias, Object *target) {
     Object *aliases = object_resolve_path("/machine/aliases",  NULL);

     object_property_add_const_link(aliases, alias, target); }

ok.

Quoted 8 lines

Even better perhaps we should also generate an error if the alias already exists to ensure they are always unique i.e.

  bool machine_add_alias(const char *alias, Object *target, Error **errp)
  {
     Object *aliases = object_resolve_path("/machine/aliases",  NULL);

Quoted 4 lines

     if (object_resolve_path_component(aliases, alias)) { error_setg(errp, "machine alias '%s' already exists"); return false;
     }

I don't think this is useful since object_property_add_const_link() should abort in case of duplicate, which would be a modeling error anyhow.

Quoted 7 lines

     return (object_property_add_const_link(aliases, alias, target) != NULL);
  }

4) Should we create a page in the documentation explaining which devices/objects should be included in the alias list,

Any device in the QOM tree could have an alias. Why would you want to limit the possible aliases? a part from dynamic ones.

Quoted 1 line

which ones are added automatically,

That's dangerous. I would say none.

Quoted 1 line

and what naming conventions should be used for devices e.g. serial0, net0 for a network device etc.?

I would leave the choice to the person in charge of the SoC or the machine.

Quoted 1 line

5) What should happen to aliases for devices that are hot-plugged/hot-unplugged?

IMO, aliases are intended for devices "soldered" on the board, created by the machine. Devices created via the command line or QMP/HMP are excluded.

Thanks,

C.

#4 lore raw

Re: [PATCH 1/2] hw/arm: Add /machine/labels container for Aspeed machines

Quoted 72 lines · Cédric Le Goater

Hello,

Quoted 69 lines · Mark Cave-Ayland
Quoted 62 lines · Cédric Le Goater

Add a DT-style alias container /machine/labels where board code registers link<> properties pointing to well-known devices. Tests can then resolve a device with a single QMP call (qom-get /machine/labels/<name>) instead of walking the bus hierarchy.

---
  include/hw/arm/aspeed.h | 12 ++++++++++++
  hw/arm/aspeed.c         | 10 ++++++++++

  2 files changed, 22 insertions(+)
include/hw/arm/aspeed.h +12 -0
index 245d02e5f757..0b8b40262767 100644
@@ -128,4 +128,16 @@ void 
 aspeed_machine_ast2600_class_emmc_init(ObjectClass *oc);
    */
   void aspeed_connect_serial_hds_to_uarts(AspeedMachineState *bmc);
+/*
+ * aspeed_machine_add_label:
+ * @bmc: pointer to the #AspeedMachineState.
+ * @label: the label name for the device.
+ * @target: the device object to register.
+ *
+ * Register a well-known device under /machine/labels/<label> as a
+ * read-only link.  Aborts on duplicate label names.
+ */
+void aspeed_machine_add_label(AspeedMachineState *bmc, const char 
 *label,
+                              Object *target);
+

  #endif

hw/arm/aspeed.c +8 -0
index 1f8d5d3e132d..79b8d55d66da 100644
@@ -127,6 +127,14 @@ void 
 aspeed_connect_serial_hds_to_uarts(AspeedMachineState *bmc)
       }
   }
+void aspeed_machine_add_label(AspeedMachineState *bmc, const char 
 *label,
+                              Object *target)
+{
+    Object *labels = object_resolve_path_component(OBJECT(bmc), 
 "labels");
+
+    object_property_add_const_link(labels, label, target);
+}
+
   static void aspeed_machine_init(MachineState *machine)

  {
      AspeedMachineState *bmc = ASPEED_MACHINE(machine);

hw/arm/aspeed.c +2 -0
@@ -137,6 +145,8 @@ static void aspeed_machine_init(MachineState 
 *machine)
       DriveInfo *emmc0 = NULL;
       bool boot_emmc;
+    object_property_add_new_container(OBJECT(machine), "labels");
+
       bmc->soc = ASPEED_SOC(object_new(amc->soc_name));

      object_property_add_child(OBJECT(machine), "soc", OBJECT(bmc-

Quoted 2 lines
Quoted 1 line

soc));

      object_unref(OBJECT(bmc->soc));

Thanks for the proposal, Cédric! A few comments from me below:

Quoted 8 lines
Quoted 1 line

1) Is there any reason it should be called labels as opposed to aliases?

none

Quoted 1 line

The aliases name as used in Open Firmware feels more intuitive to me.

yes. It it just a name. aliases is fine for me unless it introduces some confusion with object_property_add_alias().

Hmmm good point. It seems an obvious distinction here, although maybe others would find it confusing? I'd be interested to hear other opinions here.

Quoted 4 lines
Quoted 1 line

2) If there is agreement in this approach, is there any reason why we shouldn't create /machine/labels (or equivalent) for all QOM trees? I certainly think it would be a useful addition going forward.

It is a trivial addition. We would need more maintainers to Ack the concept though.

Agreed.

Quoted 3 lines
Quoted 1 line

3) Is there any reason why we need to provide the machine object directly to the aspeed_machine_add_label() function?

Only because it was selfishly introduced as a Aspeed machine helper !

:)

Quoted 19 lines
Quoted 9 lines

 If possible I think it makes sense to avoid the direct machine reference, in case the underlying implementation changes i.e.

   void machine_add_alias(const char *alias, Object *target) {
      Object *aliases = object_resolve_path("/machine/aliases",  NULL);

      object_property_add_const_link(aliases, alias, target); }

ok.

Quoted 8 lines

Even better perhaps we should also generate an error if the alias already exists to ensure they are always unique i.e.

   bool machine_add_alias(const char *alias, Object *target, Error **errp)
   {
      Object *aliases = object_resolve_path("/machine/aliases",  NULL);

Quoted 8 lines
Quoted 4 lines

      if (object_resolve_path_component(aliases, alias)) { error_setg(errp, "machine alias '%s' already exists"); return false;
      }

I don't think this is useful since object_property_add_const_link() should abort in case of duplicate, which would be a modeling error anyhow.

Okay I didn't realise that - in that case it will already prevent duplicate aliases from being added.

Quoted 9 lines
Quoted 6 lines

      return (object_property_add_const_link(aliases, alias, target) != NULL);
   }

4) Should we create a page in the documentation explaining which devices/objects should be included in the alias list,

Any device in the QOM tree could have an alias. Why would you want to limit the possible aliases? a part from dynamic ones.

I was thinking in terms of automatically populating some entries e.g. for PCI buses, but from below I see this is not considered a good idea :)

When you say any *device* above, are you thinking of a specific restriction to devices, since I can see this would be useful for some buses too?

Quoted 3 lines
Quoted 1 line

which ones are added automatically,

That's dangerous. I would say none.

Fair enough. Should we enforce some basic rules e.g. all lower-case, no spaces, mandatory index suffix to try and keep things a bit consistent? (basically as they would appear in Open Firmware). Perhaps these should be enforced programmatically?

Quoted 4 lines
Quoted 1 line

and what naming conventions should be used for devices e.g. serial0, net0 for a network device etc.?

I would leave the choice to the person in charge of the SoC or the machine.

Okay.

Quoted 4 lines
Quoted 1 line

5) What should happen to aliases for devices that are hot-plugged/hot- unplugged?

IMO, aliases are intended for devices "soldered" on the board, created by the machine. Devices created via the command line or QMP/HMP are excluded.

Makes sense, but I thought I'd ask just in case the inevitable question comes up so at least it is documented somewhere ;)

ATB,

Mark.

#5 lore raw

Re: [PATCH 1/2] hw/arm: Add /machine/labels container for Aspeed machines

Quoted 4 lines
Quoted 2 lines

Any device in the QOM tree could have an alias. Why would you want to limit the possible aliases? a part from dynamic ones.

I was thinking in terms of automatically populating some entries e.g. for PCI buses, but from below I see this is not considered a good idea :)

Ah. I imagine that once the container is available, the machine, the SoC, buses, devices could populate it however they see fit.

Quoted 1 line

When you say any *device* above, are you thinking of a specific restriction to devices, since I can see this would be useful for some buses too?

The const link should apply to any QOM object I think. Give it a try :)

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

which ones are added automatically,

That's dangerous. I would say none.

Fair enough. Should we enforce some basic rules e.g. all lower-case, no spaces, mandatory index suffix to try and keep things a bit consistent? (basically as they would appear in Open Firmware).

I don't think QEMU necessarily needs to follow the naming convention of Open Firmware specification. A PPC or ARM machine could make sure the names are compatible though or would you like the machine_add_alias() helper to implement some dt fixup ?

Quoted 1 line

Perhaps these should be enforced programmatically?

Well, if it is a key requirement for a machine, perhaps it can be implemented at the machine level. What do you have in mind ?

Cheers,

C.

#6 lore raw

PATCH 2/2 test/functional: anacapa: test ADC128D818

In reply to Cédric Le Goater

From: Emmanuel Blot <[email protected]>

Verify the ADC128D818 on the Anacapa R-PDB (i2c8 mux channel 0): two channels are driven with distinct voltages and each is checked to be reported back independently through the kernel hwmon interface, and the channel 0 limit registers are validated.

[ clg: - adjusted on upstream
- added /machine/labels support ]

---
 hw/arm/aspeed_ast2600_anacapa.c             | 11 +++--
 tests/functional/arm/test_aspeed_anacapa.py | 50 +++++++++++++++++++++
 2 files changed, 57 insertions(+), 4 deletions(-)
hw/arm/aspeed_ast2600_anacapa.c +7 -4
index 65d6b0faa2de..0b8d9cc822ca 100644
@@ -221,14 +221,15 @@ static const uint8_t hpm_brd_id_eeprom[] = {
 };
 static const size_t hpm_brd_id_eeprom_len = sizeof(hpm_brd_id_eeprom);
 
-static void anacapa_add_adc128d818(I2CBus *bus, uint8_t addr,
+static void anacapa_add_adc128d818(AspeedMachineState *bmc,
+                                   I2CBus *bus, uint8_t addr,
                                    const char *description)
 {
     DeviceState *dev = DEVICE(i2c_slave_new(TYPE_ADC128D818, addr));
     g_autofree char *childname = g_strdup_printf("0x%02x", addr);
 
     qdev_prop_set_string(dev, "description", description);
-    object_property_add_child(OBJECT(bus), childname, OBJECT(dev));
+    aspeed_machine_add_label(bmc, description, OBJECT(dev));
     i2c_slave_realize_and_unref(I2C_SLAVE(dev), bus, &error_fatal);
 }
 
@@ -271,7 +272,8 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
 
     /* i2c8mux ch0 */
     /* adc128d818@1f - R-PDB ADC (mode 1: 8 voltage channels) */
-    anacapa_add_adc128d818(pca954x_i2c_get_bus(i2c_mux, 0), 0x1f, "i2c8:0:1f");
+    anacapa_add_adc128d818(bmc, pca954x_i2c_get_bus(i2c_mux, 0),
+                           0x1f, "i2c8:0:1f");
     /* pca9555@22 */
     i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 0),
                             TYPE_PCA9552, 0x22);
@@ -333,7 +335,8 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
 
     /* i2c13mux ch3 */
     /* adc128d818@1f - MB ADC (mode 1: 8 voltage channels) */
-    anacapa_add_adc128d818(pca954x_i2c_get_bus(i2c_mux, 3), 0x1f, "i2c13:3:1f");
+    anacapa_add_adc128d818(bmc, pca954x_i2c_get_bus(i2c_mux, 3),
+                           0x1f, "i2c13:3:1f");
 
     /* i2c13mux ch4 */
     /* eeprom@51 */
tests/functional/arm/test_aspeed_anacapa.py +50 -0

71 lines not on this page · raw message

Signature · 1 line
2.55.0