Skip to contentSkip to conversation

hw/nvram/eeprom_at24c: Cleanup + FRUID EEPROM init example

PATCH Superseded Peter Delevoryas 3 participants 24 messages Jan 14, 2023 – Jan 17, 2023 Arm/Aspeed machine support

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover hw/nvram/eeprom_at24c: Cleanup + FRUID EEPROM init example

This cleans up some of the code we have creating at24c-eeprom objects in the Aspeed and Nuvoton files, and adds an example of how to initialize a FRUID EEPROM with static data using I2C transfers.

Initially I was going to propose a patch to update the at24c-eeprom realize function to incorporate static data, but then I realized I could just accomplish the same thing using i2c_send in board reset. The patch at the end demonstrates this.

Thanks,
Peter

Peter Delevoryas (6):
hw/nvram/eeprom_at24c: Add header w/ init helper hw/arm/aspeed: Remove local copy of at24c_eeprom_init hw/arm/aspeed: Replace aspeed_eeprom_init with at24c_eeprom_init hw/arm/npcm7xx: Remove local copy of at24c_eeprom_init hw/nvram/eeprom_at24c: Add I2C write helper hw/arm/aspeed: Init fby35 BMC FRUID EEPROM

 hw/arm/aspeed.c                 | 154 +++++++++++++++++++-------------
 hw/arm/npcm7xx_boards.c         |  20 ++---
 hw/nvram/eeprom_at24c.c         |  25 ++++++
 include/hw/nvram/eeprom_at24c.h |  12 +++
 4 files changed, 135 insertions(+), 76 deletions(-)
 create mode 100644 include/hw/nvram/eeprom_at24c.h
Signature · 1 line
2.39.0
#1 lore raw

PATCH 1/6 hw/nvram/eeprom_at24c: Add header w/ init helper

---
 hw/nvram/eeprom_at24c.c         | 10 ++++++++++
 include/hw/nvram/eeprom_at24c.h | 10 ++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 include/hw/nvram/eeprom_at24c.h
hw/nvram/eeprom_at24c.c +10 -0
index 2d4d8b952f38..0c27eae2b354 100644
@@ -12,6 +12,7 @@
 #include "qapi/error.h"
 #include "qemu/module.h"
 #include "hw/i2c/i2c.h"
+#include "hw/nvram/eeprom_at24c.h"
 #include "hw/qdev-properties.h"
 #include "hw/qdev-properties-system.h"
 #include "sysemu/block-backend.h"
@@ -128,6 +129,15 @@ int at24c_eeprom_send(I2CSlave *s, uint8_t data)
     return 0;
 }
 
+void at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size)
+{
+    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", address);
+    DeviceState *dev = DEVICE(i2c_dev);
+
+    qdev_prop_set_uint32(dev, "rom-size", rom_size);
+    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
+}
+
 static void at24c_eeprom_realize(DeviceState *dev, Error **errp)
 {
     EEPROMState *ee = AT24C_EE(dev);
include/hw/nvram/eeprom_at24c.h new file +10 -0
new file mode 100644
index 000000000000..9d9cf212757c
@@ -0,0 +1,10 @@
+/* Copyright (c) Meta Platforms, Inc. and affiliates. */
+
+#ifndef EEPROM_AT24C_H
+#define EEPROM_AT24C_H
+
+#include "hw/i2c/i2c.h"
+
+void at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size);
+
+#endif
Signature · 1 line
2.39.0
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] hw/nvram/eeprom_at24c: Add header w/ init helper

Quoted 1 line · Peter Delevoryas

Please add some short commit log explaining how the helper could be useful.

Thanks,

C.

Quoted 50 lines
---
  hw/nvram/eeprom_at24c.c         | 10 ++++++++++
  include/hw/nvram/eeprom_at24c.h | 10 ++++++++++
  2 files changed, 20 insertions(+)

create mode 100644 include/hw/nvram/eeprom_at24c.h

hw/nvram/eeprom_at24c.c +10 -0
index 2d4d8b952f38..0c27eae2b354 100644
@@ -12,6 +12,7 @@
  #include "qapi/error.h"
  #include "qemu/module.h"
  #include "hw/i2c/i2c.h"
+#include "hw/nvram/eeprom_at24c.h"
  #include "hw/qdev-properties.h"
  #include "hw/qdev-properties-system.h"
  #include "sysemu/block-backend.h"
@@ -128,6 +129,15 @@ int at24c_eeprom_send(I2CSlave *s, uint8_t data)
      return 0;
  }
 
+void at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size)
+{
+    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", address);
+    DeviceState *dev = DEVICE(i2c_dev);
+
+    qdev_prop_set_uint32(dev, "rom-size", rom_size);
+    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
+}
+
  static void at24c_eeprom_realize(DeviceState *dev, Error **errp)
  {
      EEPROMState *ee = AT24C_EE(dev);
include/hw/nvram/eeprom_at24c.h new file +10 -0
new file mode 100644
index 000000000000..9d9cf212757c
@@ -0,0 +1,10 @@
+/* Copyright (c) Meta Platforms, Inc. and affiliates. */
+
+#ifndef EEPROM_AT24C_H
+#define EEPROM_AT24C_H
+
+#include "hw/i2c/i2c.h"
+
+void at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size);
+
+#endif
#3 lore raw

Re: [PATCH 1/6] hw/nvram/eeprom_at24c: Add header w/ init helper

In reply to Peter Delevoryas

hw/nvram/eeprom_at24c.c int at24c_eeprom_send(I2CSlave *s, uint8_t data) · line 134

Quoted 10 lines · Peter Delevoryas
---
  hw/nvram/eeprom_at24c.c         | 10 ++++++++++
  include/hw/nvram/eeprom_at24c.h | 10 ++++++++++
  2 files changed, 20 insertions(+)

create mode 100644 include/hw/nvram/eeprom_at24c.h

hw/nvram/eeprom_at24c.c +3 -0
+void at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size)
+{
+    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", address);

Please use the type definition: TYPE_AT24C_EE.

hw/nvram/eeprom_at24c.c int at24c_eeprom_send(I2CSlave *s, uint8_t data) · line 138

Quoted 4 lines
hw/nvram/eeprom_at24c.c +4 -0
+    DeviceState *dev = DEVICE(i2c_dev);
+
+    qdev_prop_set_uint32(dev, "rom-size", rom_size);
+    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);

Although the allocated object is somehow reachable from the i2c bus object, it would be simpler to deallocate allowing the parent to keep a reference to it. So consider this prototype instead:

I2CSlave *at24c_eeprom_create(I2CBus *bus, uint8_t address,

                                uint32_t rom_size);
Quoted 1 line

+}

#4 lore raw

Re: [PATCH 1/6] hw/nvram/eeprom_at24c: Add header w/ init helper

Quoted 19 lines · Philippe Mathieu-Daudé

hw/nvram/eeprom_at24c.c int at24c_eeprom_send(I2CSlave *s, uint8_t data) · line 134

Quoted 10 lines · Peter Delevoryas
---
  hw/nvram/eeprom_at24c.c         | 10 ++++++++++
  include/hw/nvram/eeprom_at24c.h | 10 ++++++++++
  2 files changed, 20 insertions(+)

create mode 100644 include/hw/nvram/eeprom_at24c.h

hw/nvram/eeprom_at24c.c +3 -0
+void at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size)
+{
+    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", address);

Please use the type definition: TYPE_AT24C_EE.

hw/nvram/eeprom_at24c.c int at24c_eeprom_send(I2CSlave *s, uint8_t data) · line 138

Quoted 4 lines
hw/nvram/eeprom_at24c.c +4 -0
+    DeviceState *dev = DEVICE(i2c_dev);
+
+    qdev_prop_set_uint32(dev, "rom-size", rom_size);
+    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
Quoted 7 lines

Although the allocated object is somehow reachable from the i2c bus object, it would be simpler to deallocate allowing the parent to keep a reference to it. So consider this prototype instead:

I2CSlave *at24c_eeprom_create(I2CBus *bus, uint8_t address,

                                uint32_t rom_size);

Oh ok, yeah that sounds good. In this case, if I let the parent keep a reference, maybe I shouldn't use i2c_slave_realize_and_unref, and just use qdev_realize/etc (to avoid the unref?). I'll try just returning the pointer from the function to start with though.

Quoted 1 line
Quoted 1 line

+}

#5 lore raw

PATCH 2/6 hw/arm/aspeed: Remove local copy of at24c_eeprom_init

In reply to Peter Delevoryas
---
 hw/arm/aspeed.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
hw/arm/aspeed.c +1 -9
index 55f114ef729f..1f9799d4321e 100644
@@ -17,6 +17,7 @@
 #include "hw/i2c/i2c_mux_pca954x.h"
 #include "hw/i2c/smbus_eeprom.h"
 #include "hw/misc/pca9552.h"
+#include "hw/nvram/eeprom_at24c.h"
 #include "hw/sensor/tmp105.h"
 #include "hw/misc/led.h"
 #include "hw/qdev-properties.h"
@@ -429,15 +430,6 @@ static void aspeed_machine_init(MachineState *machine)
     arm_load_kernel(ARM_CPU(first_cpu), machine, &aspeed_board_binfo);
 }
 
-static void at24c_eeprom_init(I2CBus *bus, uint8_t addr, uint32_t rsize)
-{
-    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
-    DeviceState *dev = DEVICE(i2c_dev);
-
-    qdev_prop_set_uint32(dev, "rom-size", rsize);
-    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
-}
-
 static void palmetto_bmc_i2c_init(AspeedMachineState *bmc)
 {
     AspeedSoCState *soc = &bmc->soc;
Signature · 1 line
2.39.0
Reviewed-by on v1 2/6
#6 lore raw

Re: [PATCH 2/6] hw/arm/aspeed: Remove local copy of at24c_eeprom_init

Quoted 1 line · Peter Delevoryas

Thanks,

C.

Quoted 32 lines
---
  hw/arm/aspeed.c | 10 +---------
  1 file changed, 1 insertion(+), 9 deletions(-)
hw/arm/aspeed.c +1 -9
index 55f114ef729f..1f9799d4321e 100644
@@ -17,6 +17,7 @@
  #include "hw/i2c/i2c_mux_pca954x.h"
  #include "hw/i2c/smbus_eeprom.h"
  #include "hw/misc/pca9552.h"
+#include "hw/nvram/eeprom_at24c.h"
  #include "hw/sensor/tmp105.h"
  #include "hw/misc/led.h"
  #include "hw/qdev-properties.h"
@@ -429,15 +430,6 @@ static void aspeed_machine_init(MachineState *machine)
      arm_load_kernel(ARM_CPU(first_cpu), machine, &aspeed_board_binfo);
  }
 
-static void at24c_eeprom_init(I2CBus *bus, uint8_t addr, uint32_t rsize)
-{
-    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
-    DeviceState *dev = DEVICE(i2c_dev);
-
-    qdev_prop_set_uint32(dev, "rom-size", rsize);
-    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
-}
-
  static void palmetto_bmc_i2c_init(AspeedMachineState *bmc)
  {
      AspeedSoCState *soc = &bmc->soc;
Reviewed-by on v1 2/6
#7 lore raw

Re: [PATCH 2/6] hw/arm/aspeed: Remove local copy of at24c_eeprom_init

In reply to Peter Delevoryas

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

Quoted 13 lines · Peter Delevoryas
---
  hw/arm/aspeed.c | 10 +---------
  1 file changed, 1 insertion(+), 9 deletions(-)
hw/arm/aspeed.c +0 -8
-static void at24c_eeprom_init(I2CBus *bus, uint8_t addr, uint32_t rsize)
-{
-    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
-    DeviceState *dev = DEVICE(i2c_dev);
-
-    qdev_prop_set_uint32(dev, "rom-size", rsize);
-    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
-}

Why not squash in previous commit as 'extract helper' change?

Anyhow,

#8 lore raw

Re: [PATCH 2/6] hw/arm/aspeed: Remove local copy of at24c_eeprom_init

Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Peter Delevoryas
---
  hw/arm/aspeed.c | 10 +---------
  1 file changed, 1 insertion(+), 9 deletions(-)
Quoted 10 lines

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

Quoted 8 lines
hw/arm/aspeed.c +0 -8
-static void at24c_eeprom_init(I2CBus *bus, uint8_t addr, uint32_t rsize)
-{
-    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
-    DeviceState *dev = DEVICE(i2c_dev);
-
-    qdev_prop_set_uint32(dev, "rom-size", rsize);
-    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
-}

Why not squash in previous commit as 'extract helper' change?

+1, I'll squash this.

Quoted 5 lines

Anyhow,

#9 lore raw

PATCH 3/6 hw/arm/aspeed: Replace aspeed_eeprom_init with at24c_eeprom_init

In reply to Peter Delevoryas
---
 hw/arm/aspeed.c | 95 ++++++++++++++++++++++---------------------------
 1 file changed, 43 insertions(+), 52 deletions(-)
hw/arm/aspeed.c +43 -52
index 1f9799d4321e..c929c61d582a 100644
@@ -660,15 +660,6 @@ static void g220a_bmc_i2c_init(AspeedMachineState *bmc)
                           eeprom_buf);
 }
 
-static void aspeed_eeprom_init(I2CBus *bus, uint8_t addr, uint32_t rsize)
-{
-    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
-    DeviceState *dev = DEVICE(i2c_dev);
-
-    qdev_prop_set_uint32(dev, "rom-size", rsize);
-    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
-}
-
 static void fp5280g2_bmc_i2c_init(AspeedMachineState *bmc)
 {
     AspeedSoCState *soc = &bmc->soc;
@@ -701,7 +692,7 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
     AspeedSoCState *soc = &bmc->soc;
     I2CSlave *i2c_mux;
 
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 0), 0x51, 32 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 0), 0x51, 32 * KiB);
 
     create_pca9552(soc, 3, 0x61);
 
@@ -714,9 +705,9 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
                      0x4a);
     i2c_mux = i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 4),
                                       "pca9546", 0x70);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 2), 0x52, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 2), 0x52, 64 * KiB);
     create_pca9552(soc, 4, 0x60);
 
     i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 5), TYPE_TMP105,
@@ -727,8 +718,8 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
     create_pca9552(soc, 5, 0x61);
     i2c_mux = i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 5),
                                       "pca9546", 0x70);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
 
     i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 6), TYPE_TMP105,
                      0x48);
@@ -738,10 +729,10 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
                      0x4b);
     i2c_mux = i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 6),
                                       "pca9546", 0x70);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 2), 0x50, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 3), 0x51, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 2), 0x50, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 3), 0x51, 64 * KiB);
 
     create_pca9552(soc, 7, 0x30);
     create_pca9552(soc, 7, 0x31);
@@ -754,15 +745,15 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 7), TYPE_TMP105,
                      0x48);
     i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 7), "max31785", 0x52);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 7), 0x50, 64 * KiB);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 7), 0x51, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 7), 0x50, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 7), 0x51, 64 * KiB);
 
     i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 8), TYPE_TMP105,
                      0x48);
     i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 8), TYPE_TMP105,
                      0x4a);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 8), 0x50, 64 * KiB);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 8), 0x51, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 8), 0x50, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 8), 0x51, 64 * KiB);
     create_pca9552(soc, 8, 0x60);
     create_pca9552(soc, 8, 0x61);
     /* Bus 8: ucd90320@11 */
@@ -771,11 +762,11 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
 
     i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 9), "tmp423", 0x4c);
     i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 9), "tmp423", 0x4d);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 9), 0x50, 128 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 9), 0x50, 128 * KiB);
 
     i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 10), "tmp423", 0x4c);
     i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 10), "tmp423", 0x4d);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 10), 0x50, 128 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 10), 0x50, 128 * KiB);
 
     i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 11), TYPE_TMP105,
                      0x48);
@@ -783,18 +774,18 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
                      0x49);
     i2c_mux = i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 11),
                                       "pca9546", 0x70);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
     create_pca9552(soc, 11, 0x60);
 
 
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 13), 0x50, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 13), 0x50, 64 * KiB);
     create_pca9552(soc, 13, 0x60);
 
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 14), 0x50, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 14), 0x50, 64 * KiB);
     create_pca9552(soc, 14, 0x60);
 
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 15), 0x50, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 15), 0x50, 64 * KiB);
     create_pca9552(soc, 15, 0x60);
 }
 
@@ -838,45 +829,45 @@ static void fuji_bmc_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(i2c[17], TYPE_LM75, 0x4c);
     i2c_slave_create_simple(i2c[17], TYPE_LM75, 0x4d);
 
-    aspeed_eeprom_init(i2c[19], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[20], 0x50, 2 * KiB);
-    aspeed_eeprom_init(i2c[22], 0x52, 2 * KiB);
+    at24c_eeprom_init(i2c[19], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[20], 0x50, 2 * KiB);
+    at24c_eeprom_init(i2c[22], 0x52, 2 * KiB);
 
     i2c_slave_create_simple(i2c[3], TYPE_LM75, 0x48);
     i2c_slave_create_simple(i2c[3], TYPE_LM75, 0x49);
     i2c_slave_create_simple(i2c[3], TYPE_LM75, 0x4a);
     i2c_slave_create_simple(i2c[3], TYPE_TMP422, 0x4c);
 
-    aspeed_eeprom_init(i2c[8], 0x51, 64 * KiB);
+    at24c_eeprom_init(i2c[8], 0x51, 64 * KiB);
     i2c_slave_create_simple(i2c[8], TYPE_LM75, 0x4a);
 
     i2c_slave_create_simple(i2c[50], TYPE_LM75, 0x4c);
-    aspeed_eeprom_init(i2c[50], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[50], 0x52, 64 * KiB);
     i2c_slave_create_simple(i2c[51], TYPE_TMP75, 0x48);
     i2c_slave_create_simple(i2c[52], TYPE_TMP75, 0x49);
 
     i2c_slave_create_simple(i2c[59], TYPE_TMP75, 0x48);
     i2c_slave_create_simple(i2c[60], TYPE_TMP75, 0x49);
 
-    aspeed_eeprom_init(i2c[65], 0x53, 64 * KiB);
+    at24c_eeprom_init(i2c[65], 0x53, 64 * KiB);
     i2c_slave_create_simple(i2c[66], TYPE_TMP75, 0x49);
     i2c_slave_create_simple(i2c[66], TYPE_TMP75, 0x48);
-    aspeed_eeprom_init(i2c[68], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[69], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[70], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[71], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[68], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[69], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[70], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[71], 0x52, 64 * KiB);
 
-    aspeed_eeprom_init(i2c[73], 0x53, 64 * KiB);
+    at24c_eeprom_init(i2c[73], 0x53, 64 * KiB);
     i2c_slave_create_simple(i2c[74], TYPE_TMP75, 0x49);
     i2c_slave_create_simple(i2c[74], TYPE_TMP75, 0x48);
-    aspeed_eeprom_init(i2c[76], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[77], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[78], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[79], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[28], 0x50, 2 * KiB);
+    at24c_eeprom_init(i2c[76], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[77], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[78], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[79], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[28], 0x50, 2 * KiB);
 
     for (int i = 0; i < 8; i++) {
-        aspeed_eeprom_init(i2c[81 + i * 8], 0x56, 64 * KiB);
+        at24c_eeprom_init(i2c[81 + i * 8], 0x56, 64 * KiB);
         i2c_slave_create_simple(i2c[82 + i * 8], TYPE_TMP75, 0x48);
         i2c_slave_create_simple(i2c[83 + i * 8], TYPE_TMP75, 0x4b);
         i2c_slave_create_simple(i2c[84 + i * 8], TYPE_TMP75, 0x4a);
@@ -947,11 +938,11 @@ static void fby35_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(i2c[12], TYPE_LM75, 0x4e);
     i2c_slave_create_simple(i2c[12], TYPE_LM75, 0x4f);
 
-    aspeed_eeprom_init(i2c[4], 0x51, 128 * KiB);
-    aspeed_eeprom_init(i2c[6], 0x51, 128 * KiB);
-    aspeed_eeprom_init(i2c[8], 0x50, 32 * KiB);
-    aspeed_eeprom_init(i2c[11], 0x51, 128 * KiB);
-    aspeed_eeprom_init(i2c[11], 0x54, 128 * KiB);
+    at24c_eeprom_init(i2c[4], 0x51, 128 * KiB);
+    at24c_eeprom_init(i2c[6], 0x51, 128 * KiB);
+    at24c_eeprom_init(i2c[8], 0x50, 32 * KiB);
+    at24c_eeprom_init(i2c[11], 0x51, 128 * KiB);
+    at24c_eeprom_init(i2c[11], 0x54, 128 * KiB);
 
     /*
      * TODO: There is a multi-master i2c connection to an AST1030 MiniBMC on
Signature · 1 line
2.39.0
Reviewed-by on v1 3/6
#10 lore raw

Re: [PATCH 3/6] hw/arm/aspeed: Replace aspeed_eeprom_init with at24c_eeprom_init

Quoted 1 line · Peter Delevoryas

Thanks,

C.

Quoted 210 lines
---
  hw/arm/aspeed.c | 95 ++++++++++++++++++++++---------------------------
  1 file changed, 43 insertions(+), 52 deletions(-)
hw/arm/aspeed.c +43 -52
index 1f9799d4321e..c929c61d582a 100644
@@ -660,15 +660,6 @@ static void g220a_bmc_i2c_init(AspeedMachineState *bmc)
                            eeprom_buf);
  }
 
-static void aspeed_eeprom_init(I2CBus *bus, uint8_t addr, uint32_t rsize)
-{
-    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
-    DeviceState *dev = DEVICE(i2c_dev);
-
-    qdev_prop_set_uint32(dev, "rom-size", rsize);
-    i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
-}
-
  static void fp5280g2_bmc_i2c_init(AspeedMachineState *bmc)
  {
      AspeedSoCState *soc = &bmc->soc;
@@ -701,7 +692,7 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
      AspeedSoCState *soc = &bmc->soc;
      I2CSlave *i2c_mux;
 
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 0), 0x51, 32 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 0), 0x51, 32 * KiB);
 
      create_pca9552(soc, 3, 0x61);
 
@@ -714,9 +705,9 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
                       0x4a);
      i2c_mux = i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 4),
                                        "pca9546", 0x70);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 2), 0x52, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 2), 0x52, 64 * KiB);
      create_pca9552(soc, 4, 0x60);
 
      i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 5), TYPE_TMP105,
@@ -727,8 +718,8 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
      create_pca9552(soc, 5, 0x61);
      i2c_mux = i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 5),
                                        "pca9546", 0x70);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
 
      i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 6), TYPE_TMP105,
                       0x48);
@@ -738,10 +729,10 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
                       0x4b);
      i2c_mux = i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 6),
                                        "pca9546", 0x70);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 2), 0x50, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 3), 0x51, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 2), 0x50, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 3), 0x51, 64 * KiB);
 
      create_pca9552(soc, 7, 0x30);
      create_pca9552(soc, 7, 0x31);
@@ -754,15 +745,15 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
      i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 7), TYPE_TMP105,
                       0x48);
      i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 7), "max31785", 0x52);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 7), 0x50, 64 * KiB);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 7), 0x51, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 7), 0x50, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 7), 0x51, 64 * KiB);
 
      i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 8), TYPE_TMP105,
                       0x48);
      i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 8), TYPE_TMP105,
                       0x4a);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 8), 0x50, 64 * KiB);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 8), 0x51, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 8), 0x50, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 8), 0x51, 64 * KiB);
      create_pca9552(soc, 8, 0x60);
      create_pca9552(soc, 8, 0x61);
      /* Bus 8: ucd90320@11 */
@@ -771,11 +762,11 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
 
      i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 9), "tmp423", 0x4c);
      i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 9), "tmp423", 0x4d);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 9), 0x50, 128 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 9), 0x50, 128 * KiB);
 
      i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 10), "tmp423", 0x4c);
      i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 10), "tmp423", 0x4d);
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 10), 0x50, 128 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 10), 0x50, 128 * KiB);
 
      i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 11), TYPE_TMP105,
                       0x48);
@@ -783,18 +774,18 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
                       0x49);
      i2c_mux = i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 11),
                                        "pca9546", 0x70);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
-    aspeed_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
+    at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
      create_pca9552(soc, 11, 0x60);
 
 
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 13), 0x50, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 13), 0x50, 64 * KiB);
      create_pca9552(soc, 13, 0x60);
 
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 14), 0x50, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 14), 0x50, 64 * KiB);
      create_pca9552(soc, 14, 0x60);
 
-    aspeed_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 15), 0x50, 64 * KiB);
+    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 15), 0x50, 64 * KiB);
      create_pca9552(soc, 15, 0x60);
  }
 
@@ -838,45 +829,45 @@ static void fuji_bmc_i2c_init(AspeedMachineState *bmc)
      i2c_slave_create_simple(i2c[17], TYPE_LM75, 0x4c);
      i2c_slave_create_simple(i2c[17], TYPE_LM75, 0x4d);
 
-    aspeed_eeprom_init(i2c[19], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[20], 0x50, 2 * KiB);
-    aspeed_eeprom_init(i2c[22], 0x52, 2 * KiB);
+    at24c_eeprom_init(i2c[19], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[20], 0x50, 2 * KiB);
+    at24c_eeprom_init(i2c[22], 0x52, 2 * KiB);
 
      i2c_slave_create_simple(i2c[3], TYPE_LM75, 0x48);
      i2c_slave_create_simple(i2c[3], TYPE_LM75, 0x49);
      i2c_slave_create_simple(i2c[3], TYPE_LM75, 0x4a);
      i2c_slave_create_simple(i2c[3], TYPE_TMP422, 0x4c);
 
-    aspeed_eeprom_init(i2c[8], 0x51, 64 * KiB);
+    at24c_eeprom_init(i2c[8], 0x51, 64 * KiB);
      i2c_slave_create_simple(i2c[8], TYPE_LM75, 0x4a);
 
      i2c_slave_create_simple(i2c[50], TYPE_LM75, 0x4c);
-    aspeed_eeprom_init(i2c[50], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[50], 0x52, 64 * KiB);
      i2c_slave_create_simple(i2c[51], TYPE_TMP75, 0x48);
      i2c_slave_create_simple(i2c[52], TYPE_TMP75, 0x49);
 
      i2c_slave_create_simple(i2c[59], TYPE_TMP75, 0x48);
      i2c_slave_create_simple(i2c[60], TYPE_TMP75, 0x49);
 
-    aspeed_eeprom_init(i2c[65], 0x53, 64 * KiB);
+    at24c_eeprom_init(i2c[65], 0x53, 64 * KiB);
      i2c_slave_create_simple(i2c[66], TYPE_TMP75, 0x49);
      i2c_slave_create_simple(i2c[66], TYPE_TMP75, 0x48);
-    aspeed_eeprom_init(i2c[68], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[69], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[70], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[71], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[68], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[69], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[70], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[71], 0x52, 64 * KiB);
 
-    aspeed_eeprom_init(i2c[73], 0x53, 64 * KiB);
+    at24c_eeprom_init(i2c[73], 0x53, 64 * KiB);
      i2c_slave_create_simple(i2c[74], TYPE_TMP75, 0x49);
      i2c_slave_create_simple(i2c[74], TYPE_TMP75, 0x48);
-    aspeed_eeprom_init(i2c[76], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[77], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[78], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[79], 0x52, 64 * KiB);
-    aspeed_eeprom_init(i2c[28], 0x50, 2 * KiB);
+    at24c_eeprom_init(i2c[76], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[77], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[78], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[79], 0x52, 64 * KiB);
+    at24c_eeprom_init(i2c[28], 0x50, 2 * KiB);
 
      for (int i = 0; i < 8; i++) {
-        aspeed_eeprom_init(i2c[81 + i * 8], 0x56, 64 * KiB);
+        at24c_eeprom_init(i2c[81 + i * 8], 0x56, 64 * KiB);
          i2c_slave_create_simple(i2c[82 + i * 8], TYPE_TMP75, 0x48);
          i2c_slave_create_simple(i2c[83 + i * 8], TYPE_TMP75, 0x4b);
          i2c_slave_create_simple(i2c[84 + i * 8], TYPE_TMP75, 0x4a);
@@ -947,11 +938,11 @@ static void fby35_i2c_init(AspeedMachineState *bmc)
      i2c_slave_create_simple(i2c[12], TYPE_LM75, 0x4e);
      i2c_slave_create_simple(i2c[12], TYPE_LM75, 0x4f);
 
-    aspeed_eeprom_init(i2c[4], 0x51, 128 * KiB);
-    aspeed_eeprom_init(i2c[6], 0x51, 128 * KiB);
-    aspeed_eeprom_init(i2c[8], 0x50, 32 * KiB);
-    aspeed_eeprom_init(i2c[11], 0x51, 128 * KiB);
-    aspeed_eeprom_init(i2c[11], 0x54, 128 * KiB);
+    at24c_eeprom_init(i2c[4], 0x51, 128 * KiB);
+    at24c_eeprom_init(i2c[6], 0x51, 128 * KiB);
+    at24c_eeprom_init(i2c[8], 0x50, 32 * KiB);
+    at24c_eeprom_init(i2c[11], 0x51, 128 * KiB);
+    at24c_eeprom_init(i2c[11], 0x54, 128 * KiB);
 
      /*
       * TODO: There is a multi-master i2c connection to an AST1030 MiniBMC on
#12 lore raw

PATCH 4/6 hw/arm/npcm7xx: Remove local copy of at24c_eeprom_init

In reply to Peter Delevoryas
---
 hw/arm/npcm7xx_boards.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
hw/arm/npcm7xx_boards.c +5 -15
index 6bc6f5d2fe29..9b31207a06e9 100644
@@ -21,6 +21,7 @@
 #include "hw/i2c/i2c_mux_pca954x.h"
 #include "hw/i2c/smbus_eeprom.h"
 #include "hw/loader.h"
+#include "hw/nvram/eeprom_at24c.h"
 #include "hw/qdev-core.h"
 #include "hw/qdev-properties.h"
 #include "qapi/error.h"
@@ -140,17 +141,6 @@ static I2CBus *npcm7xx_i2c_get_bus(NPCM7xxState *soc, uint32_t num)
     return I2C_BUS(qdev_get_child_bus(DEVICE(&soc->smbus[num]), "i2c-bus"));
 }
 
-static void at24c_eeprom_init(NPCM7xxState *soc, int bus, uint8_t addr,
-                              uint32_t rsize)
-{
-    I2CBus *i2c_bus = npcm7xx_i2c_get_bus(soc, bus);
-    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
-    DeviceState *dev = DEVICE(i2c_dev);
-
-    qdev_prop_set_uint32(dev, "rom-size", rsize);
-    i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort);
-}
-
 static void npcm7xx_init_pwm_splitter(NPCM7xxMachine *machine,
                                       NPCM7xxState *soc, const int *fan_counts)
 {
@@ -253,8 +243,8 @@ static void quanta_gsj_i2c_init(NPCM7xxState *soc)
     i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 3), "tmp105", 0x5c);
     i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), "tmp105", 0x5c);
 
-    at24c_eeprom_init(soc, 9, 0x55, 8192);
-    at24c_eeprom_init(soc, 10, 0x55, 8192);
+    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 9), 0x55, 8192);
+    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 10), 0x55, 8192);
 
     /*
      * i2c-11:
@@ -360,7 +350,7 @@ static void kudo_bmc_i2c_init(NPCM7xxState *soc)
 
     i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), TYPE_PCA9548, 0x77);
 
-    at24c_eeprom_init(soc, 4, 0x50, 8192); /* mbfru */
+    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 4), 0x50, 8192); /* mbfru */
 
     i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 13),
                                       TYPE_PCA9548, 0x77);
@@ -371,7 +361,7 @@ static void kudo_bmc_i2c_init(NPCM7xxState *soc)
     i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 4), "tmp105", 0x48);
     i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 5), "tmp105", 0x49);
 
-    at24c_eeprom_init(soc, 14, 0x55, 8192); /* bmcfru */
+    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 14), 0x55, 8192); /* bmcfru */
 
     /* TODO: Add remaining i2c devices. */
 }
Signature · 1 line
2.39.0
Reviewed-by on v1 4/6
#13 lore raw

Re: [PATCH 4/6] hw/arm/npcm7xx: Remove local copy of at24c_eeprom_init

Quoted 1 line · Peter Delevoryas

Thanks,

C.

Quoted 63 lines
---
  hw/arm/npcm7xx_boards.c | 20 +++++---------------
  1 file changed, 5 insertions(+), 15 deletions(-)
hw/arm/npcm7xx_boards.c +5 -15
index 6bc6f5d2fe29..9b31207a06e9 100644
@@ -21,6 +21,7 @@
  #include "hw/i2c/i2c_mux_pca954x.h"
  #include "hw/i2c/smbus_eeprom.h"
  #include "hw/loader.h"
+#include "hw/nvram/eeprom_at24c.h"
  #include "hw/qdev-core.h"
  #include "hw/qdev-properties.h"
  #include "qapi/error.h"
@@ -140,17 +141,6 @@ static I2CBus *npcm7xx_i2c_get_bus(NPCM7xxState *soc, uint32_t num)
      return I2C_BUS(qdev_get_child_bus(DEVICE(&soc->smbus[num]), "i2c-bus"));
  }
 
-static void at24c_eeprom_init(NPCM7xxState *soc, int bus, uint8_t addr,
-                              uint32_t rsize)
-{
-    I2CBus *i2c_bus = npcm7xx_i2c_get_bus(soc, bus);
-    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
-    DeviceState *dev = DEVICE(i2c_dev);
-
-    qdev_prop_set_uint32(dev, "rom-size", rsize);
-    i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort);
-}
-
  static void npcm7xx_init_pwm_splitter(NPCM7xxMachine *machine,
                                        NPCM7xxState *soc, const int *fan_counts)
  {
@@ -253,8 +243,8 @@ static void quanta_gsj_i2c_init(NPCM7xxState *soc)
      i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 3), "tmp105", 0x5c);
      i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), "tmp105", 0x5c);
 
-    at24c_eeprom_init(soc, 9, 0x55, 8192);
-    at24c_eeprom_init(soc, 10, 0x55, 8192);
+    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 9), 0x55, 8192);
+    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 10), 0x55, 8192);
 
      /*
       * i2c-11:
@@ -360,7 +350,7 @@ static void kudo_bmc_i2c_init(NPCM7xxState *soc)
 
      i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), TYPE_PCA9548, 0x77);
 
-    at24c_eeprom_init(soc, 4, 0x50, 8192); /* mbfru */
+    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 4), 0x50, 8192); /* mbfru */
 
      i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 13),
                                        TYPE_PCA9548, 0x77);
@@ -371,7 +361,7 @@ static void kudo_bmc_i2c_init(NPCM7xxState *soc)
      i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 4), "tmp105", 0x48);
      i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 5), "tmp105", 0x49);
 
-    at24c_eeprom_init(soc, 14, 0x55, 8192); /* bmcfru */
+    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 14), 0x55, 8192); /* bmcfru */
 
      /* TODO: Add remaining i2c devices. */
  }
#15 lore raw

PATCH 5/6 hw/nvram/eeprom_at24c: Add I2C write helper

In reply to Peter Delevoryas
---
 hw/nvram/eeprom_at24c.c         | 15 +++++++++++++++
 include/hw/nvram/eeprom_at24c.h |  2 ++
 2 files changed, 17 insertions(+)
hw/nvram/eeprom_at24c.c +15 -0
index 0c27eae2b354..69565a420c28 100644
@@ -10,6 +10,7 @@
 #include "qemu/osdep.h"
 
 #include "qapi/error.h"
+#include "qemu/bitops.h"
 #include "qemu/module.h"
 #include "hw/i2c/i2c.h"
 #include "hw/nvram/eeprom_at24c.h"
@@ -138,6 +139,20 @@ void at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size)
     i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort);
 }
 
+void at24c_eeprom_write(I2CBus *bus, uint8_t address, uint16_t offset,
+                        const uint8_t *buf, uint32_t len)
+{
+    int i;
+
+    i2c_start_send(bus, address);
+    i2c_send(bus, extract16(offset, 8, 8));
+    i2c_send(bus, extract16(offset, 0, 8));
+    for (i = 0; i < len; i++) {
+        i2c_send(bus, buf[i]);
+    }
+    i2c_end_transfer(bus);
+}
+
 static void at24c_eeprom_realize(DeviceState *dev, Error **errp)
 {
     EEPROMState *ee = AT24C_EE(dev);
include/hw/nvram/eeprom_at24c.h +2 -0
index 9d9cf212757c..bbca73a07ad1 100644
@@ -6,5 +6,7 @@
 #include "hw/i2c/i2c.h"
 
 void at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size);
+void at24c_eeprom_write(I2CBus *bus, uint8_t address, uint16_t offset,
+                        const uint8_t *buf, uint32_t len);
 
 #endif
Signature · 1 line
2.39.0
#16 lore raw

PATCH 6/6 hw/arm/aspeed: Init fby35 BMC FRUID EEPROM

In reply to Peter Delevoryas
---
 hw/arm/aspeed.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
hw/arm/aspeed.c +49 -0
index c929c61d582a..4ac8ff11a835 100644
@@ -922,6 +922,52 @@ static void bletchley_bmc_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(i2c[12], TYPE_PCA9552, 0x67);
 }
 
+static const uint8_t fby35_bmc_fruid[] = {
+    0x01, 0x00, 0x00, 0x01, 0x0d, 0x00, 0x00, 0xf1, 0x01, 0x0c, 0x00, 0x36,
+    0xe6, 0xd0, 0xc6, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xd2, 0x42, 0x4d,
+    0x43, 0x20, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x20, 0x4d, 0x6f,
+    0x64, 0x75, 0x6c, 0x65, 0xcd, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xce, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc3, 0x31, 0x2e,
+    0x30, 0xc9, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xd2,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc1, 0x39, 0x01, 0x0c, 0x00, 0xc6,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xd2, 0x59, 0x6f, 0x73, 0x65, 0x6d,
+    0x69, 0x74, 0x65, 0x20, 0x56, 0x33, 0x2e, 0x35, 0x20, 0x45, 0x56, 0x54,
+    0x32, 0xce, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0xc4, 0x45, 0x56, 0x54, 0x32, 0xcd, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc7,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc3, 0x31, 0x2e, 0x30, 0xc9,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc8, 0x43, 0x6f,
+    0x6e, 0x66, 0x69, 0x67, 0x20, 0x41, 0xc1, 0x45, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+};
+
 static void fby35_i2c_init(AspeedMachineState *bmc)
 {
     AspeedSoCState *soc = &bmc->soc;
@@ -1363,6 +1409,9 @@ static void fby35_reset(MachineState *state, ShutdownCause reason)
     object_property_set_bool(OBJECT(gpio), "gpioB3", false, &error_fatal);
     object_property_set_bool(OBJECT(gpio), "gpioB4", false, &error_fatal);
     object_property_set_bool(OBJECT(gpio), "gpioB5", false, &error_fatal);
+
+    at24c_eeprom_write(aspeed_i2c_get_bus(&bmc->soc.i2c, 11),
+                       0x54, 0, fby35_bmc_fruid, sizeof(fby35_bmc_fruid));
 }
 
 static void aspeed_machine_fby35_class_init(ObjectClass *oc, void *data)
Signature · 1 line
2.39.0
#17 lore raw

Re: [PATCH 6/6] hw/arm/aspeed: Init fby35 BMC FRUID EEPROM

Quoted 14 lines · Peter Delevoryas
---
  hw/arm/aspeed.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 49 insertions(+)
hw/arm/aspeed.c +1 -0
index c929c61d582a..4ac8ff11a835 100644
@@ -922,6 +922,52 @@ static void bletchley_bmc_i2c_init(AspeedMachineState *bmc)
      i2c_slave_create_simple(i2c[12], TYPE_PCA9552, 0x67);
  }
 
+static const uint8_t fby35_bmc_fruid[] = {

[...]

hw/arm/aspeed.c static void fby35_reset(MachineState *state, ShutdownCause reason) · line 1414

Quoted 12 lines
hw/arm/aspeed.c +5 -0
+};
+
  static void fby35_i2c_init(AspeedMachineState *bmc)
  {
      AspeedSoCState *soc = &bmc->soc;
@@ -1363,6 +1409,9 @@ static void fby35_reset(MachineState *state, ShutdownCause reason)
      object_property_set_bool(OBJECT(gpio), "gpioB3", false, &error_fatal);
      object_property_set_bool(OBJECT(gpio), "gpioB4", false, &error_fatal);
      object_property_set_bool(OBJECT(gpio), "gpioB5", false, &error_fatal);
+
+    at24c_eeprom_write(aspeed_i2c_get_bus(&bmc->soc.i2c, 11),
+                       0x54, 0, fby35_bmc_fruid, sizeof(fby35_bmc_fruid));

Why transfer the prom content on the i2c bus at each reset?

In particular this looks wrong if the prom is initialized with a 'drive' block backend (using -global).

Quoted 1 line
hw/arm/aspeed.c +0 -0
  }
#18 lore raw

Re: [PATCH 6/6] hw/arm/aspeed: Init fby35 BMC FRUID EEPROM

Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Peter Delevoryas
---
  hw/arm/aspeed.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 49 insertions(+)
hw/arm/aspeed.c +1 -0
index c929c61d582a..4ac8ff11a835 100644
@@ -922,6 +922,52 @@ static void bletchley_bmc_i2c_init(AspeedMachineState *bmc)
      i2c_slave_create_simple(i2c[12], TYPE_PCA9552, 0x67);
  }
+static const uint8_t fby35_bmc_fruid[] = {

[...]

hw/arm/aspeed.c static void fby35_reset(MachineState *state, ShutdownCause reason) · line 1414

Quoted 12 lines
hw/arm/aspeed.c +5 -0
+};
+
  static void fby35_i2c_init(AspeedMachineState *bmc)
  {
      AspeedSoCState *soc = &bmc->soc;
@@ -1363,6 +1409,9 @@ static void fby35_reset(MachineState *state, ShutdownCause reason)
      object_property_set_bool(OBJECT(gpio), "gpioB3", false, &error_fatal);
      object_property_set_bool(OBJECT(gpio), "gpioB4", false, &error_fatal);
      object_property_set_bool(OBJECT(gpio), "gpioB5", false, &error_fatal);
+
+    at24c_eeprom_write(aspeed_i2c_get_bus(&bmc->soc.i2c, 11),
+                       0x54, 0, fby35_bmc_fruid, sizeof(fby35_bmc_fruid));

Why transfer the prom content on the i2c bus at each reset?

Quoted 2 lines

In particular this looks wrong if the prom is initialized with a 'drive' block backend (using -global).

Yeah, it looks like this might not be the right way to model it. I'm going to try Cedric's suggestions.

Quoted 4 lines
Quoted 2 lines
hw/arm/aspeed.c +0 -0
  }
#19 lore raw

Re: [PATCH 6/6] hw/arm/aspeed: Init fby35 BMC FRUID EEPROM

Quoted 32 lines · Peter Delevoryas
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Peter Delevoryas
---
   hw/arm/aspeed.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
   1 file changed, 49 insertions(+)
hw/arm/aspeed.c +1 -0
index c929c61d582a..4ac8ff11a835 100644
@@ -922,6 +922,52 @@ static void bletchley_bmc_i2c_init(AspeedMachineState *bmc)
       i2c_slave_create_simple(i2c[12], TYPE_PCA9552, 0x67);
   }
+static const uint8_t fby35_bmc_fruid[] = {

[...]

hw/arm/aspeed.c static void fby35_reset(MachineState *state, ShutdownCause reason) · line 1414

Quoted 12 lines
hw/arm/aspeed.c +5 -0
+};
+
   static void fby35_i2c_init(AspeedMachineState *bmc)
   {
       AspeedSoCState *soc = &bmc->soc;
@@ -1363,6 +1409,9 @@ static void fby35_reset(MachineState *state, ShutdownCause reason)
       object_property_set_bool(OBJECT(gpio), "gpioB3", false, &error_fatal);
       object_property_set_bool(OBJECT(gpio), "gpioB4", false, &error_fatal);
       object_property_set_bool(OBJECT(gpio), "gpioB5", false, &error_fatal);
+
+    at24c_eeprom_write(aspeed_i2c_get_bus(&bmc->soc.i2c, 11),
+                       0x54, 0, fby35_bmc_fruid, sizeof(fby35_bmc_fruid));

Why transfer the prom content on the i2c bus at each reset?

Quoted 5 lines
Quoted 2 lines

In particular this looks wrong if the prom is initialized with a 'drive' block backend (using -global).

Yeah, it looks like this might not be the right way to model it. I'm going to try Cedric's suggestions.

OK, but watch out this is a PROM, not a ROM, meaning it is legitimate for a guest to reprogram it, and expect the reprogrammed content after reset.

Shouldn't we put the 'fill default content if no -drive provided' option in the device's realize() handler, to avoid overwriting content possibly updated by guest before reset?

#20 lore raw

Re: [PATCH 6/6] hw/arm/aspeed: Init fby35 BMC FRUID EEPROM

Quoted 36 lines · Philippe Mathieu-Daudé
Quoted 35 lines · Peter Delevoryas
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Peter Delevoryas
---
   hw/arm/aspeed.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
   1 file changed, 49 insertions(+)
hw/arm/aspeed.c +1 -0
index c929c61d582a..4ac8ff11a835 100644
@@ -922,6 +922,52 @@ static void bletchley_bmc_i2c_init(AspeedMachineState *bmc)
       i2c_slave_create_simple(i2c[12], TYPE_PCA9552, 0x67);
   }
+static const uint8_t fby35_bmc_fruid[] = {

[...]

hw/arm/aspeed.c static void fby35_reset(MachineState *state, ShutdownCause reason) · line 1414

Quoted 12 lines
hw/arm/aspeed.c +5 -0
+};
+
   static void fby35_i2c_init(AspeedMachineState *bmc)
   {
       AspeedSoCState *soc = &bmc->soc;
@@ -1363,6 +1409,9 @@ static void fby35_reset(MachineState *state, ShutdownCause reason)
       object_property_set_bool(OBJECT(gpio), "gpioB3", false, &error_fatal);
       object_property_set_bool(OBJECT(gpio), "gpioB4", false, &error_fatal);
       object_property_set_bool(OBJECT(gpio), "gpioB5", false, &error_fatal);
+
+    at24c_eeprom_write(aspeed_i2c_get_bus(&bmc->soc.i2c, 11),
+                       0x54, 0, fby35_bmc_fruid, sizeof(fby35_bmc_fruid));

Why transfer the prom content on the i2c bus at each reset?

In particular this looks wrong if the prom is initialized with a 'drive' block backend (using -global).

Quoted 6 lines
Quoted 2 lines

Yeah, it looks like this might not be the right way to model it. I'm going to try Cedric's suggestions.

OK, but watch out this is a PROM, not a ROM, meaning it is legitimate for a guest to reprogram it, and expect the reprogrammed content after reset.

+1

Quoted 4 lines

Shouldn't we put the 'fill default content if no -drive provided' option in the device's realize() handler, to avoid overwriting content possibly updated by guest before reset?

+1, yeah I think you're right, if somebody is providing a -drive option, we should allow that to override everything else (default zero initialization, init ROM initialization, etc).

Because, if they're providing a -drive, they shouldn't need to provide an initial value, they can just initialize the file with the data they want.

#21 lore raw

Re: [PATCH 6/6] hw/arm/aspeed: Init fby35 BMC FRUID EEPROM

In reply to Peter Delevoryas
Quoted 48 lines · Peter Delevoryas
---
  hw/arm/aspeed.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 49 insertions(+)
hw/arm/aspeed.c +35 -0
index c929c61d582a..4ac8ff11a835 100644
@@ -922,6 +922,52 @@ static void bletchley_bmc_i2c_init(AspeedMachineState *bmc)
      i2c_slave_create_simple(i2c[12], TYPE_PCA9552, 0x67);
  }
 
+static const uint8_t fby35_bmc_fruid[] = {
+    0x01, 0x00, 0x00, 0x01, 0x0d, 0x00, 0x00, 0xf1, 0x01, 0x0c, 0x00, 0x36,
+    0xe6, 0xd0, 0xc6, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xd2, 0x42, 0x4d,
+    0x43, 0x20, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x20, 0x4d, 0x6f,
+    0x64, 0x75, 0x6c, 0x65, 0xcd, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xce, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc3, 0x31, 0x2e,
+    0x30, 0xc9, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xd2,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc1, 0x39, 0x01, 0x0c, 0x00, 0xc6,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xd2, 0x59, 0x6f, 0x73, 0x65, 0x6d,
+    0x69, 0x74, 0x65, 0x20, 0x56, 0x33, 0x2e, 0x35, 0x20, 0x45, 0x56, 0x54,
+    0x32, 0xce, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0xc4, 0x45, 0x56, 0x54, 0x32, 0xcd, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc7,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc3, 0x31, 0x2e, 0x30, 0xc9,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc8, 0x43, 0x6f,
+    0x6e, 0x66, 0x69, 0x67, 0x20, 0x41, 0xc1, 0x45, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

hw/arm/aspeed.c static void bletchley_bmc_i2c_init(AspeedMachineState *bmc) · line 969

Quoted 10 lines
hw/arm/aspeed.c +10 -0
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+};

I would introduce a new aspeed_eeprom.c file for these definitions because each machine could have its own set of eeproms and aspeed.c is already big enough.

hw/arm/aspeed.c static void fby35_reset(MachineState *state, ShutdownCause reason) · line 1415

Quoted 11 lines
hw/arm/aspeed.c +3 -0
  static void fby35_i2c_init(AspeedMachineState *bmc)
  {
      AspeedSoCState *soc = &bmc->soc;
@@ -1363,6 +1409,9 @@ static void fby35_reset(MachineState *state, ShutdownCause reason)
      object_property_set_bool(OBJECT(gpio), "gpioB3", false, &error_fatal);
      object_property_set_bool(OBJECT(gpio), "gpioB4", false, &error_fatal);
      object_property_set_bool(OBJECT(gpio), "gpioB5", false, &error_fatal);
+
+    at24c_eeprom_write(aspeed_i2c_get_bus(&bmc->soc.i2c, 11),
+                       0x54, 0, fby35_bmc_fruid, sizeof(fby35_bmc_fruid));
  }

That's one way to model the default reset values of the eeprom, we would loose any writes though.

I think we should have a reset_data buffer instead, which would be used at realize time to set the initial data, if there are no drive backend, and at reset if !writable. Something like smbus_eeprom_init_one() does without a proper property API.

We would need some new interface to set a property for a constant buffer of uint<>_t values. I don't know how complex that would be. It could be useful to other models to define the init state of registers.

Thanks,

C.

Quoted 1 line
hw/arm/aspeed.c +0 -0
  static void aspeed_machine_fby35_class_init(ObjectClass *oc, void *data)
#22 lore raw

Re: [PATCH 6/6] hw/arm/aspeed: Init fby35 BMC FRUID EEPROM

Quoted 55 lines · Cédric Le Goater
Quoted 54 lines · Peter Delevoryas
---
  hw/arm/aspeed.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 49 insertions(+)
hw/arm/aspeed.c +42 -0
index c929c61d582a..4ac8ff11a835 100644
@@ -922,6 +922,52 @@ static void bletchley_bmc_i2c_init(AspeedMachineState *bmc)
      i2c_slave_create_simple(i2c[12], TYPE_PCA9552, 0x67);
  }
+static const uint8_t fby35_bmc_fruid[] = {
+    0x01, 0x00, 0x00, 0x01, 0x0d, 0x00, 0x00, 0xf1, 0x01, 0x0c, 0x00, 0x36,
+    0xe6, 0xd0, 0xc6, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xd2, 0x42, 0x4d,
+    0x43, 0x20, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x20, 0x4d, 0x6f,
+    0x64, 0x75, 0x6c, 0x65, 0xcd, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xce, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc3, 0x31, 0x2e,
+    0x30, 0xc9, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xd2,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc1, 0x39, 0x01, 0x0c, 0x00, 0xc6,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xd2, 0x59, 0x6f, 0x73, 0x65, 0x6d,
+    0x69, 0x74, 0x65, 0x20, 0x56, 0x33, 0x2e, 0x35, 0x20, 0x45, 0x56, 0x54,
+    0x32, 0xce, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0xc4, 0x45, 0x56, 0x54, 0x32, 0xcd, 0x58, 0x58,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc7,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc3, 0x31, 0x2e, 0x30, 0xc9,
+    0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0xc8, 0x43, 0x6f,
+    0x6e, 0x66, 0x69, 0x67, 0x20, 0x41, 0xc1, 0x45, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
Quoted 8 lines

hw/arm/aspeed.c static void bletchley_bmc_i2c_init(AspeedMachineState *bmc) · line 969

Quoted 3 lines
hw/arm/aspeed.c +3 -0
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+};

I would introduce a new aspeed_eeprom.c file for these definitions because each machine could have its own set of eeproms and aspeed.c is already big enough.

+1

Quoted 16 lines

hw/arm/aspeed.c static void fby35_reset(MachineState *state, ShutdownCause reason) · line 1415

Quoted 12 lines
hw/arm/aspeed.c +3 -0
  static void fby35_i2c_init(AspeedMachineState *bmc)
  {
      AspeedSoCState *soc = &bmc->soc;
@@ -1363,6 +1409,9 @@ static void fby35_reset(MachineState *state, ShutdownCause reason)
      object_property_set_bool(OBJECT(gpio), "gpioB3", false, &error_fatal);
      object_property_set_bool(OBJECT(gpio), "gpioB4", false, &error_fatal);
      object_property_set_bool(OBJECT(gpio), "gpioB5", false, &error_fatal);
+
+    at24c_eeprom_write(aspeed_i2c_get_bus(&bmc->soc.i2c, 11),
+                       0x54, 0, fby35_bmc_fruid, sizeof(fby35_bmc_fruid));
  }

That's one way to model the default reset values of the eeprom, we would loose any writes though.

Quoted 4 lines

I think we should have a reset_data buffer instead, which would be used at realize time to set the initial data, if there are no drive backend, and at reset if !writable. Something like smbus_eeprom_init_one() does without a proper property API.

I actually did it this way downstream[1], but I thought it would be controversial without using properties, and I wasn't sure how to model it with properties.

[1] https://github.com/facebook/openbmc/blob/b98f10b7967ebce1f97e14a9a5d4c14f9f7d4c55/common/recipes-devtools/qemu/qemu/0014-hw-nvram-at24c-Add-static-memory-init-option.patch

Quoted 4 lines

We would need some new interface to set a property for a constant buffer of uint<>_t values. I don't know how complex that would be. It could be useful to other models to define the init state of registers.

Would DEFINE_PROP_ARRAY not work? Won't the properties be constant after qdev_realize()?

Or if that's not preferable, DEFINE_PROP_LINK (uint8_t *reset_data) + DEFINE_PROP_UINT32 (reset_data_size)?

Otherwise, if the property stuff is too uncertain, I'd be happy just adding an adhoc API through the helper like smbus_eeprom_init_one does.

Quoted 7 lines

Thanks,

C.

Quoted 1 line
hw/arm/aspeed.c +0 -0
  static void aspeed_machine_fby35_class_init(ObjectClass *oc, void *data)
#23 lore raw
In reply to Peter Delevoryas
Quoted 8 lines · Peter Delevoryas

This cleans up some of the code we have creating at24c-eeprom objects in the Aspeed and Nuvoton files, and adds an example of how to initialize a FRUID EEPROM with static data using I2C transfers.

Initially I was going to propose a patch to update the at24c-eeprom realize function to incorporate static data, but then I realized I could just accomplish the same thing using i2c_send in board reset. The patch at the end demonstrates this.

1. I messed up Joel's email on this thread, sorry about that.
2. I forgot to post the output of the test I used to verify this:

qemu-system-aarch64 -machine fby35-bmc -nographic -mtdblock flash-fby35
...

root@bmc-oob:~# fruid-util bmc
FRU Information           : BMC
---------------           : ------------------
Board Mfg Date            : Mon Jan 10 21:42:00 2022
Board Mfg                 : XXXXXX
Board Product             : BMC Storage Module
Board Serial              : XXXXXXXXXXXXX
Board Part Number         : XXXXXXXXXXXXXX
Board FRU ID              : 1.0
Board Custom Data 1       : XXXXXXXXX
Board Custom Data 2       : XXXXXXXXXXXXXXXXXX
Product Manufacturer      : XXXXXX
Product Name              : Yosemite V3.5 EVT2
Product Part Number       : XXXXXXXXXXXXXX
Product Version           : EVT2
Product Serial            : XXXXXXXXXXXXX
Product Asset Tag         : XXXXXXX
Product FRU ID            : 1.0
Product Custom Data 1     : XXXXXXXXX
Product Custom Data 2     : Config A

A reference flash-fby35 image can be found here:

https://github.com/facebook/openbmc/releases/download/openbmc-e2294ff5d31d/fby35.mtd

Quoted 23 lines

Thanks,
Peter

Peter Delevoryas (6):
hw/nvram/eeprom_at24c: Add header w/ init helper hw/arm/aspeed: Remove local copy of at24c_eeprom_init hw/arm/aspeed: Replace aspeed_eeprom_init with at24c_eeprom_init hw/arm/npcm7xx: Remove local copy of at24c_eeprom_init hw/nvram/eeprom_at24c: Add I2C write helper hw/arm/aspeed: Init fby35 BMC FRUID EEPROM

 hw/arm/aspeed.c                 | 154 +++++++++++++++++++-------------
 hw/arm/npcm7xx_boards.c         |  20 ++---
 hw/nvram/eeprom_at24c.c         |  25 ++++++
 include/hw/nvram/eeprom_at24c.h |  12 +++
 4 files changed, 135 insertions(+), 76 deletions(-)
 create mode 100644 include/hw/nvram/eeprom_at24c.h
Signature · 1 line
2.39.0