Skip to contentSkip to conversation

Add PowerNV I2C Controller Model

PATCH Applied Glenn Miles 3 participants 6 messages Oct 16, 2023 – Nov 7, 2023 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v3 cover Add PowerNV I2C Controller Model

Upstreams the PowerNV I2C controller model originally authored by Cédric Le Goater with minor changes by myself to split the actual addition of the model from wiring it up to a power processor model.

This series only attaches the controller to the powernv9 chip model, but is expected to eventually also be attached to the powernv10 chip model.

Cédric Le Goater (2):
ppc/pnv: Add an I2C controller model
ppc/pnv: Connect I2C controller model to powernv9 chip

 hw/ppc/meson.build         |   1 +
 hw/ppc/pnv.c               |  28 ++
 hw/ppc/pnv_i2c.c           | 697 +++++++++++++++++++++++++++++++++++++
 include/hw/ppc/pnv_chip.h  |   8 +
 include/hw/ppc/pnv_i2c.h   |  38 ++
 include/hw/ppc/pnv_xscom.h |   3 +
 6 files changed, 775 insertions(+)
 create mode 100644 hw/ppc/pnv_i2c.c
 create mode 100644 include/hw/ppc/pnv_i2c.h
Signature · 1 line
2.31.1
#1 lore raw

PATCH v3 1/2 ppc/pnv: Add an I2C controller model

From: Cédric Le Goater <[email protected]>

The more recent IBM power processors have an embedded I2C controller that is accessible by software via the XSCOM address space.

Each instance of the I2C controller is capable of controlling multiple I2C buses (one at a time). Prior to beginning a transaction on an I2C bus, the bus must be selected by writing the port number associated with the bus into the PORT_NUM field of the MODE register. Once an I2C bus is selected, the status of the bus can be determined by reading the Status and Extended Status registers.

I2C bus transactions can be started by writing a command to the Command register and reading/writing data from/to the FIFO register.

Not supported :

. 10 bit I2C addresses
. Multimaster
. Slave

[milesg: Split wiring to powernv9 into its own commit]
[milesg: Added more detail to commit message]
[milesg: Added SPDX Licensed Identifier to new files]
[milesg: updated copyright dates]
[milesg: Added use of g_autofree]
[milesg: Added NULL check after pnv_i2c_get_bus]

---

Changes from v2:
-Fixed uninitialized usage of g_autofree -Added NULL checks after calls to pnv_i2c_get_bus

 hw/ppc/meson.build         |   1 +
 hw/ppc/pnv_i2c.c           | 697 +++++++++++++++++++++++++++++++++++++
 include/hw/ppc/pnv_i2c.h   |  38 ++
 include/hw/ppc/pnv_xscom.h |   3 +
 4 files changed, 739 insertions(+)
 create mode 100644 hw/ppc/pnv_i2c.c
 create mode 100644 include/hw/ppc/pnv_i2c.h
hw/ppc/meson.build +1 -0
index 7c2c52434a..87b756a701 100644
@@ -43,6 +43,7 @@ ppc_ss.add(when: 'CONFIG_POWERNV', if_true: files(
   'pnv.c',
   'pnv_xscom.c',
   'pnv_core.c',
+  'pnv_i2c.c',
   'pnv_lpc.c',
   'pnv_psi.c',
   'pnv_occ.c',
hw/ppc/pnv_i2c.c new file +697 -0

697 lines not on this page · raw message

include/hw/ppc/pnv_i2c.h new file +38 -0
new file mode 100644
index 0000000000..1a37730f1e
@@ -0,0 +1,38 @@
+/*
+ * QEMU PowerPC PowerNV Processor I2C model
+ *
+ * Copyright (c) 2019-2023, IBM Corporation.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef PPC_PNV_I2C_H
+#define PPC_PNV_I2C_H
+
+#include "hw/ppc/pnv.h"
+#include "hw/i2c/i2c.h"
+#include "qemu/fifo8.h"
+
+#define TYPE_PNV_I2C "pnv-i2c"
+#define PNV_I2C(obj) OBJECT_CHECK(PnvI2C, (obj), TYPE_PNV_I2C)
+
+#define PNV_I2C_REGS 0x20
+
+typedef struct PnvI2C {
+    DeviceState parent;
+
+    struct PnvChip *chip;
+
+    qemu_irq psi_irq;
+
+    uint64_t regs[PNV_I2C_REGS];
+    uint32_t engine;
+    uint32_t num_busses;
+    I2CBus **busses;
+
+    MemoryRegion xscom_regs;
+
+    Fifo8 fifo;
+} PnvI2C;
+
+#endif /* PPC_PNV_I2C_H */
include/hw/ppc/pnv_xscom.h +3 -0
index 9bc6463547..0c8b873c4c 100644
@@ -90,6 +90,9 @@ struct PnvXScomInterfaceClass {
     ((uint64_t)(((core) & 0x1C) + 0x40) << 22)
 #define PNV9_XSCOM_EQ_SIZE        0x100000
 
+#define PNV9_XSCOM_I2CM_BASE      0xa0000
+#define PNV9_XSCOM_I2CM_SIZE      0x1000
+
 #define PNV9_XSCOM_OCC_BASE       PNV_XSCOM_OCC_BASE
 #define PNV9_XSCOM_OCC_SIZE       0x8000
 
Signature · 1 line
2.31.1
#2 lore raw

PATCH v3 2/2 ppc/pnv: Connect I2C controller model to powernv9 chip

In reply to Glenn Miles

From: Cédric Le Goater <[email protected]>

Wires up three I2C controller instances to the powernv9 chip XSCOM address space.

Each controller instance is wired up to a single I2C bus of its own. No other I2C devices are connected to the buses at this time.

[milesg: Split wiring from addition of model itself]
[milesg: Added new commit message]
[milesg: Moved hardcoded attributes into PnvChipClass]
[milesg: Removed TODO comment for I2C]

---

Changes from v2:
-Removed TODO comment for I2C

 hw/ppc/pnv.c              | 28 ++++++++++++++++++++++++++++
 include/hw/ppc/pnv_chip.h |  8 ++++++++
 2 files changed, 36 insertions(+)
hw/ppc/pnv.c +28 -0
index eb54f93986..e0b3478325 100644
@@ -1438,6 +1438,10 @@ static void pnv_chip_power9_instance_init(Object *obj)
         object_initialize_child(obj, "pec[*]", &chip9->pecs[i],
                                 TYPE_PNV_PHB4_PEC);
     }
+
+    for (i = 0; i < pcc->i2c_num_engines; i++) {
+        object_initialize_child(obj, "i2c[*]", &chip9->i2c[i], TYPE_PNV_I2C);
+    }
 }
 
 static void pnv_chip_quad_realize_one(PnvChip *chip, PnvQuad *eq,
@@ -1510,6 +1514,7 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp)
     PnvChip *chip = PNV_CHIP(dev);
     Pnv9Psi *psi9 = &chip9->psi;
     Error *local_err = NULL;
+    int i;
 
     /* XSCOM bridge is first */
     pnv_xscom_realize(chip, PNV9_XSCOM_SIZE, &local_err);
@@ -1613,6 +1618,27 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp)
         error_propagate(errp, local_err);
         return;
     }
+
+    /*
+     * I2C
+     */
+    for (i = 0; i < pcc->i2c_num_engines; i++) {
+        Object *obj =  OBJECT(&chip9->i2c[i]);
+
+        object_property_set_int(obj, "engine", i + 1, &error_fatal);
+        object_property_set_int(obj, "num-busses", pcc->i2c_num_ports,
+                                &error_fatal);
+        object_property_set_link(obj, "chip", OBJECT(chip), &error_abort);
+        if (!qdev_realize(DEVICE(obj), NULL, errp)) {
+            return;
+        }
+        pnv_xscom_add_subregion(chip, PNV9_XSCOM_I2CM_BASE +
+                               chip9->i2c[i].engine * PNV9_XSCOM_I2CM_SIZE,
+                                &chip9->i2c[i].xscom_regs);
+        qdev_connect_gpio_out(DEVICE(&chip9->i2c[i]), 0,
+                              qdev_get_gpio_in(DEVICE(&chip9->psi),
+                                               PSIHB9_IRQ_SBE_I2C));
+    }
 }
 
 static uint32_t pnv_chip_power9_xscom_pcba(PnvChip *chip, uint64_t addr)
@@ -1640,6 +1666,8 @@ static void pnv_chip_power9_class_init(ObjectClass *klass, void *data)
     k->xscom_pcba = pnv_chip_power9_xscom_pcba;
     dc->desc = "PowerNV Chip POWER9";
     k->num_pecs = PNV9_CHIP_MAX_PEC;
+    k->i2c_num_engines = PNV9_CHIP_MAX_I2C;
+    k->i2c_num_ports = PNV9_CHIP_MAX_I2C_PORTS;
 
     device_class_set_parent_realize(dc, pnv_chip_power9_realize,
                                     &k->parent_realize);
include/hw/ppc/pnv_chip.h +8 -0
index 53e1d921d7..90cfbad1a5 100644
@@ -9,6 +9,7 @@
 #include "hw/ppc/pnv_psi.h"
 #include "hw/ppc/pnv_sbe.h"
 #include "hw/ppc/pnv_xive.h"
+#include "hw/ppc/pnv_i2c.h"
 #include "hw/sysbus.h"
 
 OBJECT_DECLARE_TYPE(PnvChip, PnvChipClass,
@@ -86,6 +87,10 @@ struct Pnv9Chip {
 
 #define PNV9_CHIP_MAX_PEC 3
     PnvPhb4PecState pecs[PNV9_CHIP_MAX_PEC];
+
+#define PNV9_CHIP_MAX_I2C 3
+#define PNV9_CHIP_MAX_I2C_PORTS 1
+    PnvI2C      i2c[PNV9_CHIP_MAX_I2C];
 };
 
 /*
@@ -130,6 +135,9 @@ struct PnvChipClass {
     uint32_t     num_pecs;
     uint32_t     num_phbs;
 
+    uint32_t     i2c_num_engines;
+    uint32_t     i2c_num_ports;
+
     DeviceRealize parent_realize;
 
     uint32_t (*core_pir)(PnvChip *chip, uint32_t core_id);
Signature · 1 line
2.31.1
Reviewed-by on the v3 series
#3 lore raw
In reply to Glenn Miles
Quoted 5 lines · Glenn Miles

Upstreams the PowerNV I2C controller model originally authored by Cédric Le Goater with minor changes by myself to split the actual addition of the model from wiring it up to a power processor model.

Quoted 7 lines

This series only attaches the controller to the powernv9 chip model, but is expected to eventually also be attached to the powernv10 chip model.

Cédric Le Goater (2):
ppc/pnv: Add an I2C controller model
ppc/pnv: Connect I2C controller model to powernv9 chip

Thanks for taking care of upstreaming Glenn. Waiting for the P10 part now !

C.

Quoted 11 lines
  hw/ppc/meson.build         |   1 +
  hw/ppc/pnv.c               |  28 ++
  hw/ppc/pnv_i2c.c           | 697 +++++++++++++++++++++++++++++++++++++
  include/hw/ppc/pnv_chip.h  |   8 +
  include/hw/ppc/pnv_i2c.h   |  38 ++
  include/hw/ppc/pnv_xscom.h |   3 +
  6 files changed, 775 insertions(+)

create mode 100644 hw/ppc/pnv_i2c.c
create mode 100644 include/hw/ppc/pnv_i2c.h

#4 lore raw
Quoted 14 lines · Cédric Le Goater
Quoted 5 lines · Glenn Miles

Upstreams the PowerNV I2C controller model originally authored by Cédric Le Goater with minor changes by myself to split the actual addition of the model from wiring it up to a power processor model.

Quoted 7 lines

This series only attaches the controller to the powernv9 chip model, but is expected to eventually also be attached to the powernv10 chip model.

Cédric Le Goater (2):
ppc/pnv: Add an I2C controller model
ppc/pnv: Connect I2C controller model to powernv9 chip

Quoted 6 lines

Thanks for taking care of upstreaming Glenn. Waiting for the P10 part now !

C.

No problem! Thanks for all of your help as well.

Glenn

Quoted 13 lines
Quoted 13 lines

  hw/ppc/meson.build         |   1 +
  hw/ppc/pnv.c               |  28 ++
  hw/ppc/pnv_i2c.c           | 697
+++++++++++++++++++++++++++++++++++++
  include/hw/ppc/pnv_chip.h  |   8 +
  include/hw/ppc/pnv_i2c.h   |  38 ++
  include/hw/ppc/pnv_xscom.h |   3 +
  6 files changed, 775 insertions(+)

create mode 100644 hw/ppc/pnv_i2c.c
create mode 100644 include/hw/ppc/pnv_i2c.h

#5 lore raw
In reply to Glenn Miles

Queued in gitlab.com/danielhb/qemu/tree/ppc-next. Thanks,

Daniel

Quoted 23 lines · Glenn Miles

Upstreams the PowerNV I2C controller model originally authored by Cédric Le Goater with minor changes by myself to split the actual addition of the model from wiring it up to a power processor model.

This series only attaches the controller to the powernv9 chip model, but is expected to eventually also be attached to the powernv10 chip model.

Cédric Le Goater (2):
ppc/pnv: Add an I2C controller model
ppc/pnv: Connect I2C controller model to powernv9 chip

  hw/ppc/meson.build         |   1 +
  hw/ppc/pnv.c               |  28 ++
  hw/ppc/pnv_i2c.c           | 697 +++++++++++++++++++++++++++++++++++++
  include/hw/ppc/pnv_chip.h  |   8 +
  include/hw/ppc/pnv_i2c.h   |  38 ++
  include/hw/ppc/pnv_xscom.h |   3 +
  6 files changed, 775 insertions(+)

create mode 100644 hw/ppc/pnv_i2c.c
create mode 100644 include/hw/ppc/pnv_i2c.h