Skip to contentSkip to conversation

hw/arm: Add NPCM8XX support

PATCH In review Hao Wu 2 participants 25 messages Apr 5, 2022 – Apr 21, 2022 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Hao Wu

author
#0 lore raw

cover hw/arm: Add NPCM8XX support

NPCM8XX BMCs are the successors of the NPCM7XX BMCs. They feature quad-core ARM Cortex A35 that supports both 32 bits and 64 bits operations. This patch set aims to support basic functionalities of the NPCM7XX BMCs. The patch set includes:

1. We derive most devices from the 7XX models and
made some modifications.
2. We have constructed a minimum vBootROM similar to the 7XX one at
https://github.com/google/vbootrom/tree/master/npcm8xx
and included it in the patch set.
3. We added a new NPCM8XX SOC and an evaluation
board machine npcm845-evb.

The OpenBMC for NPCM845 evaluation board can be found at:
https://github.com/Nuvoton-Israel/openbmc/tree/npcm-v2.10/meta-evb/meta-evb-nuvoton/meta-evb-npcm845

The patch set can boot the evaluation board image built from the source above to login prompt.

Hao Wu (11):
docs/system/arm: Add Description for NPCM8XX SoC hw/ssi: Make flash size a property in NPCM7XX FIU hw/misc: Support NPCM8XX GCR module
hw/misc: Support NPCM8XX CLK Module Registers
hw/misc: Store DRAM size in NPCM8XX GCR Module
hw/intc: Add a property to allow GIC to reset into non secure mode hw/misc: Support 8-bytes memop in NPCM GCR module hw/net: Add NPCM8XX PCS Module
pc-bios: Add NPCM8xx Bootrom
hw/arm: Add NPCM8XX SoC
hw/arm: Add NPCM845 Evaluation board

 MAINTAINERS                                   |   9 +-
 configs/devices/aarch64-softmmu/default.mak   |   1 +
 docs/system/arm/nuvoton.rst                   |  20 +-
 hw/arm/Kconfig                                |  11 +
 hw/arm/meson.build                            |   1 +
 hw/arm/npcm7xx.c                              |   6 +
 hw/arm/npcm8xx.c                              | 806 ++++++++++++++++++
 hw/arm/npcm8xx_boards.c                       | 257 ++++++
 hw/intc/arm_gic_common.c                      |   2 +
 hw/misc/meson.build                           |   4 +-
 hw/misc/npcm7xx_gcr.c                         | 269 ------
 hw/misc/{npcm7xx_clk.c => npcm_clk.c}         | 238 ++++--
 hw/misc/npcm_gcr.c                            | 492 +++++++++++
 hw/misc/trace-events                          |  12 +-
 hw/net/meson.build                            |   1 +
 hw/net/npcm_pcs.c                             | 409 +++++++++
 hw/net/trace-events                           |   4 +
 hw/ssi/npcm7xx_fiu.c                          |   6 +-
 include/hw/arm/npcm7xx.h                      |   8 +-
 include/hw/arm/npcm8xx.h                      | 126 +++
 include/hw/misc/{npcm7xx_clk.h => npcm_clk.h} |  43 +-
 include/hw/misc/{npcm7xx_gcr.h => npcm_gcr.h} |  30 +-
 include/hw/net/npcm_pcs.h                     |  42 +
 include/hw/ssi/npcm7xx_fiu.h                  |   1 +
 pc-bios/npcm8xx_bootrom.bin                   | Bin 0 -> 608 bytes
 25 files changed, 2428 insertions(+), 370 deletions(-)
 create mode 100644 hw/arm/npcm8xx.c
 create mode 100644 hw/arm/npcm8xx_boards.c
 delete mode 100644 hw/misc/npcm7xx_gcr.c
 rename hw/misc/{npcm7xx_clk.c => npcm_clk.c} (81%)
 create mode 100644 hw/misc/npcm_gcr.c
 create mode 100644 hw/net/npcm_pcs.c
 create mode 100644 include/hw/arm/npcm8xx.h
 rename include/hw/misc/{npcm7xx_clk.h => npcm_clk.h} (83%)
 rename include/hw/misc/{npcm7xx_gcr.h => npcm_gcr.h} (55%)
 create mode 100644 include/hw/net/npcm_pcs.h
 create mode 100644 pc-bios/npcm8xx_bootrom.bin
Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
author
#1 lore raw

PATCH 1/11 docs/system/arm: Add Description for NPCM8XX SoC

NPCM8XX SoC is the successor of the NPCM7XX. It features quad-core Cortex-A35 (Armv8, 64-bit) CPUs and some additional peripherals.

---
 docs/system/arm/nuvoton.rst | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
docs/system/arm/nuvoton.rst +15 -5
index ef2792076a..bead17fa7e 100644
@@ -1,12 +1,13 @@
 Nuvoton iBMC boards (``*-bmc``, ``npcm750-evb``, ``quanta-gsj``)
 ================================================================
 
-The `Nuvoton iBMC`_ chips (NPCM7xx) are a family of ARM-based SoCs that are
+The `Nuvoton iBMC`_ chips are a family of ARM-based SoCs that are
 designed to be used as Baseboard Management Controllers (BMCs) in various
-servers. They all feature one or two ARM Cortex-A9 CPU cores, as well as an
-assortment of peripherals targeted for either Enterprise or Data Center /
-Hyperscale applications. The former is a superset of the latter, so NPCM750 has
-all the peripherals of NPCM730 and more.
+servers. Currently there are two families: NPCM7XX series and
+NPCM8XX series. NPCM7XX series feature one or two ARM Cortex-A9 CPU cores,
+while NPCM8XX feature 4 ARM Cortex-A35 CPU cores. Both series contain a
+different assortment of peripherals targeted for either Enterprise or Data
+Center / Hyperscale applications.
 
 .. _Nuvoton iBMC: https://www.nuvoton.com/products/cloud-computing/ibmc/
 
@@ -27,6 +28,8 @@ There are also two more SoCs, NPCM710 and NPCM705, which are single-core
 variants of NPCM750 and NPCM730, respectively. These are currently not
 supported by QEMU.
 
+The NPCM8xx SoC is the successor of the NPCM7xx SoC.
+
 Supported devices
 -----------------
 
@@ -61,6 +64,8 @@ Missing devices
    * System Wake-up Control (SWC)
    * Shared memory (SHM)
    * eSPI slave interface
+   * Block-tranfer interface (8XX only)
+   * Virtual UART (8XX only)
 
  * Ethernet controller (GMAC)
  * USB device (USBD)
@@ -76,6 +81,11 @@ Missing devices
  * Video capture
  * Encoding compression engine
  * Security features
+ * I3C buses (8XX only)
+ * Temperator sensor interface (8XX only)
+ * Virtual UART (8XX only)
+ * Flash monitor (8XX only)
+ * JTAG master (8XX only)
 
 Boot options
 ------------
Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
author
#2 lore raw

PATCH 2/11 hw/ssi: Make flash size a property in NPCM7XX FIU

In reply to Hao Wu

This allows different FIUs to have different flash sizes, useful in NPCM8XX which has multiple different sized FIU modules.

---
 hw/arm/npcm7xx.c             | 6 ++++++
 hw/ssi/npcm7xx_fiu.c         | 6 ++----
 include/hw/ssi/npcm7xx_fiu.h | 1 +
 3 files changed, 9 insertions(+), 4 deletions(-)
hw/arm/npcm7xx.c +6 -0
index d85cc02765..9946b94120 100644
@@ -274,17 +274,21 @@ static const struct {
     hwaddr regs_addr;
     int cs_count;
     const hwaddr *flash_addr;
+    size_t flash_size;
 } npcm7xx_fiu[] = {
     {
         .name = "fiu0",
         .regs_addr = 0xfb000000,
         .cs_count = ARRAY_SIZE(npcm7xx_fiu0_flash_addr),
         .flash_addr = npcm7xx_fiu0_flash_addr,
+        .flash_size = 128 * MiB,
+
     }, {
         .name = "fiu3",
         .regs_addr = 0xc0000000,
         .cs_count = ARRAY_SIZE(npcm7xx_fiu3_flash_addr),
         .flash_addr = npcm7xx_fiu3_flash_addr,
+        .flash_size = 128 * MiB,
     },
 };
 
@@ -686,6 +690,8 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
 
         object_property_set_int(OBJECT(sbd), "cs-count",
                                 npcm7xx_fiu[i].cs_count, &error_abort);
+        object_property_set_int(OBJECT(sbd), "flash-size",
+                                npcm7xx_fiu[i].flash_size, &error_abort);
         sysbus_realize(sbd, &error_abort);
 
         sysbus_mmio_map(sbd, 0, npcm7xx_fiu[i].regs_addr);
hw/ssi/npcm7xx_fiu.c +2 -4
index 4eedb2927e..ea490f1332 100644
@@ -28,9 +28,6 @@
 
 #include "trace.h"
 
-/* Up to 128 MiB of flash may be accessed directly as memory. */
-#define NPCM7XX_FIU_FLASH_WINDOW_SIZE (128 * MiB)
-
 /* Each module has 4 KiB of register space. Only a fraction of it is used. */
 #define NPCM7XX_FIU_CTRL_REGS_SIZE (4 * KiB)
 
@@ -525,7 +522,7 @@ static void npcm7xx_fiu_realize(DeviceState *dev, Error **errp)
         flash->fiu = s;
         memory_region_init_io(&flash->direct_access, OBJECT(s),
                               &npcm7xx_fiu_flash_ops, &s->flash[i], "flash",
-                              NPCM7XX_FIU_FLASH_WINDOW_SIZE);
+                              s->flash_size);
         sysbus_init_mmio(sbd, &flash->direct_access);
     }
 }
@@ -543,6 +540,7 @@ static const VMStateDescription vmstate_npcm7xx_fiu = {
 
 static Property npcm7xx_fiu_properties[] = {
     DEFINE_PROP_INT32("cs-count", NPCM7xxFIUState, cs_count, 0),
+    DEFINE_PROP_SIZE("flash-size", NPCM7xxFIUState, flash_size, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
include/hw/ssi/npcm7xx_fiu.h +1 -0
index a3a1704289..1785ea16f4 100644
@@ -60,6 +60,7 @@ struct NPCM7xxFIUState {
     int32_t cs_count;
     int32_t active_cs;
     qemu_irq *cs_lines;
+    size_t flash_size;
     NPCM7xxFIUFlash *flash;
 
     SSIBus *spi;
Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
#3 lore raw

Re: [PATCH for-7.1 02/11] hw/ssi: Make flash size a property in NPCM7XX FIU

Quoted 13 lines · Hao Wu

This allows different FIUs to have different flash sizes, useful in NPCM8XX which has multiple different sized FIU modules.

---
 hw/arm/npcm7xx.c             | 6 ++++++
 hw/ssi/npcm7xx_fiu.c         | 6 ++----
 include/hw/ssi/npcm7xx_fiu.h | 1 +
 3 files changed, 9 insertions(+), 4 deletions(-)

hw/ssi/npcm7xx_fiu.c static void npcm7xx_fiu_realize(DeviceState *dev, Error **errp) · line 526

Quoted 6 lines
hw/ssi/npcm7xx_fiu.c +1 -1
@@ -525,7 +522,7 @@ static void npcm7xx_fiu_realize(DeviceState *dev, Error **errp)
         flash->fiu = s;
         memory_region_init_io(&flash->direct_access, OBJECT(s),
                               &npcm7xx_fiu_flash_ops, &s->flash[i], "flash",
-                              NPCM7XX_FIU_FLASH_WINDOW_SIZE);
+                              s->flash_size);
         sysbus_init_mmio(sbd, &flash->direct_access);

Creating a zero-sized memory region if the user forgets to set the flash-size property is going to be a bit confusing, so I think it would be better to have at least a basic sanity check of the property in realize.

Otherwise looks good.

thanks
-- PMM

author
#4 lore raw

PATCH 3/11 hw/misc: Support NPCM8XX GCR module

In reply to Hao Wu

NPCM8XX has a different set of global control registers than 7XX. This patch supports that.

---
 MAINTAINERS                                   |   9 +-
 hw/misc/meson.build                           |   2 +-
 hw/misc/npcm7xx_gcr.c                         | 269 ------------
 hw/misc/npcm_gcr.c                            | 413 ++++++++++++++++++
 hw/misc/trace-events                          |   6 +-
 include/hw/arm/npcm7xx.h                      |   4 +-
 include/hw/misc/{npcm7xx_gcr.h => npcm_gcr.h} |  29 +-
 7 files changed, 445 insertions(+), 287 deletions(-)
 delete mode 100644 hw/misc/npcm7xx_gcr.c
 create mode 100644 hw/misc/npcm_gcr.c
 rename include/hw/misc/{npcm7xx_gcr.h => npcm_gcr.h} (56%)
MAINTAINERS +5 -4
index 4ad2451e03..c31ed09527 100644
@@ -791,14 +791,15 @@ F: hw/net/mv88w8618_eth.c
 F: include/hw/net/mv88w8618_eth.h
 F: docs/system/arm/musicpal.rst
 
-Nuvoton NPCM7xx
+Nuvoton NPCM
 M: Havard Skinnemoen <[email protected]>
 M: Tyrone Ting <[email protected]>
+M: Hao Wu <[email protected]>
 L: [email protected]
 S: Supported
-F: hw/*/npcm7xx*
-F: include/hw/*/npcm7xx*
-F: tests/qtest/npcm7xx*
+F: hw/*/npcm*
+F: include/hw/*/npcm*
+F: tests/qtest/npcm*
 F: pc-bios/npcm7xx_bootrom.bin
 F: roms/vbootrom
 F: docs/system/arm/nuvoton.rst
hw/misc/meson.build +1 -1
index 6fb69612e0..13f8fee5b6 100644
@@ -61,7 +61,7 @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files(
 softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c'))
 softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files(
   'npcm7xx_clk.c',
-  'npcm7xx_gcr.c',
+  'npcm_gcr.c',
   'npcm7xx_mft.c',
   'npcm7xx_pwm.c',
   'npcm7xx_rng.c',
hw/misc/npcm7xx_gcr.c deleted +0 -269

269 lines not on this page · raw message

hw/misc/npcm_gcr.c new file +413 -0

413 lines not on this page · raw message

hw/misc/trace-events +3 -3
index 4e0c7973a4..3f9f0fcce0 100644
@@ -102,9 +102,9 @@ mos6522_read(uint64_t addr, const char *name, unsigned val) "reg=0x%"PRIx64 " [%
 npcm7xx_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
 npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
 
-# npcm7xx_gcr.c
-npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
-npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
+# npcm_gcr.c
+npcm_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
+npcm_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
 
 # npcm7xx_mft.c
 npcm7xx_mft_read(const char *name, uint64_t offset, uint16_t value) "%s: offset: 0x%04" PRIx64 " value: 0x%04" PRIx16
include/hw/arm/npcm7xx.h +2 -2
index ce593235d9..b0f50ff5c5 100644
@@ -24,7 +24,7 @@
 #include "hw/i2c/npcm7xx_smbus.h"
 #include "hw/mem/npcm7xx_mc.h"
 #include "hw/misc/npcm7xx_clk.h"
-#include "hw/misc/npcm7xx_gcr.h"
+#include "hw/misc/npcm_gcr.h"
 #include "hw/misc/npcm7xx_mft.h"
 #include "hw/misc/npcm7xx_pwm.h"
 #include "hw/misc/npcm7xx_rng.h"
@@ -88,7 +88,7 @@ typedef struct NPCM7xxState {
     MemoryRegion        ram3;
     MemoryRegion        *dram;
 
-    NPCM7xxGCRState     gcr;
+    NPCMGCRState        gcr;
     NPCM7xxCLKState     clk;
     NPCM7xxTimerCtrlState tim[3];
     NPCM7xxADCState     adc;
include/hw/misc/npcm_gcr.h renamed from include/hw/misc/npcm7xx_gcr.h +21 -8
similarity index 56%
rename from include/hw/misc/npcm7xx_gcr.h
rename to include/hw/misc/npcm_gcr.h
index 13109d9d32..ac3d781c2e 100644
@@ -1,5 +1,5 @@
 /*
- * Nuvoton NPCM7xx System Global Control Registers.
+ * Nuvoton NPCM7xx/NPCM8xx System Global Control Registers.
  *
  * Copyright 2020 Google LLC
  *
@@ -18,26 +18,39 @@
 
 #include "exec/memory.h"
 #include "hw/sysbus.h"
+#include "qom/object.h"
+
+#define NPCM7XX_GCR_NR_REGS (0x148 / sizeof(uint32_t))
+#define NPCM8XX_GCR_NR_REGS (0xf80 / sizeof(uint32_t))
 
 /*
- * Number of registers in our device state structure. Don't change this without
- * incrementing the version_id in the vmstate.
+ * Number of maximum registers in NPCM device state structure. Don't change
+ * this without incrementing the version_id in the vmstate.
  */
-#define NPCM7XX_GCR_NR_REGS (0x148 / sizeof(uint32_t))
+#define NPCM_GCR_MAX_NR_REGS NPCM8XX_GCR_NR_REGS
 
-typedef struct NPCM7xxGCRState {
+typedef struct NPCMGCRState {
     SysBusDevice parent;
 
     MemoryRegion iomem;
 
-    uint32_t regs[NPCM7XX_GCR_NR_REGS];
+    uint32_t regs[NPCM_GCR_MAX_NR_REGS];
 
     uint32_t reset_pwron;
     uint32_t reset_mdlr;
     uint32_t reset_intcr3;
-} NPCM7xxGCRState;
+} NPCMGCRState;
+
+typedef struct NPCMGCRClass {
+    SysBusDeviceClass parent;
+
+    size_t nr_regs;
+    const uint32_t *cold_reset_values;
+} NPCMGCRClass;
 
+#define TYPE_NPCM_GCR "npcm-gcr"
+OBJECT_DECLARE_TYPE(NPCMGCRState, NPCMGCRClass, NPCM_GCR)
 #define TYPE_NPCM7XX_GCR "npcm7xx-gcr"
-#define NPCM7XX_GCR(obj) OBJECT_CHECK(NPCM7xxGCRState, (obj), TYPE_NPCM7XX_GCR)
+#define TYPE_NPCM8XX_GCR "npcm8xx-gcr"
 
 #endif /* NPCM7XX_GCR_H */
Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
#5 lore raw

Re: [PATCH for-7.1 03/11] hw/misc: Support NPCM8XX GCR module

hw/misc/npcm_gcr.c

Quoted 23 lines · Hao Wu

NPCM8XX has a different set of global control registers than 7XX. This patch supports that.

---

hw/misc/npcm7xx_gcr.c deleted +0 -0
deleted file mode 100644
index eace9e1967..0000000000
@@ -1,269 +0,0 @@
hw/misc/npcm_gcr.c new file +0 -0
new file mode 100644
index 0000000000..2349949599
@@ -0,0 +1,413 @@

I'm not reviewing a patch that implements this as "delete 250 lines of the old file and add 400 lines of new file" when they're clearly very similar. Please split this up in a way that makes the changes visible and reviewable (probably this is one patch doing "rename file" and then one or more patches making the code less 7xx specific and then a patch adding the 8xx type).

thanks
-- PMM

author
#6 lore raw

PATCH 4/11 hw/misc: Support NPCM8XX CLK Module Registers

In reply to Hao Wu

NPCM8XX adds a few new registers and have a different set of reset values to the CLK modules. This patch supports them.

This patch doesn't support the new clock values generated by these registers. Currently no modules use these new clock values so they are not necessary at this point.
Implementation of these clocks might be required when implementing these modules.

---
 hw/misc/meson.build                           |   2 +-
 hw/misc/{npcm7xx_clk.c => npcm_clk.c}         | 238 ++++++++++++++----
 hw/misc/trace-events                          |   6 +-
 include/hw/arm/npcm7xx.h                      |   4 +-
 include/hw/misc/{npcm7xx_clk.h => npcm_clk.h} |  43 ++--
 5 files changed, 219 insertions(+), 74 deletions(-)
 rename hw/misc/{npcm7xx_clk.c => npcm_clk.c} (81%)
 rename include/hw/misc/{npcm7xx_clk.h => npcm_clk.h} (83%)
hw/misc/meson.build +1 -1
index 13f8fee5b6..b4e9d3f857 100644
@@ -60,7 +60,7 @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files(
 ))
 softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c'))
 softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files(
-  'npcm7xx_clk.c',
+  'npcm_clk.c',
   'npcm_gcr.c',
   'npcm7xx_mft.c',
   'npcm7xx_pwm.c',
hw/misc/npcm_clk.c renamed from hw/misc/npcm7xx_clk.c +184 -54

431 lines not on this page · raw message

hw/misc/trace-events +3 -3
index 3f9f0fcce0..02650acfff 100644
@@ -98,9 +98,9 @@ mos6522_set_sr_int(void) "set sr_int"
 mos6522_write(uint64_t addr, const char *name, uint64_t val) "reg=0x%"PRIx64 " [%s] val=0x%"PRIx64
 mos6522_read(uint64_t addr, const char *name, unsigned val) "reg=0x%"PRIx64 " [%s] val=0x%x"
 
-# npcm7xx_clk.c
-npcm7xx_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
-npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
+# npcm_clk.c
+npcm_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
+npcm_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
 
 # npcm_gcr.c
 npcm_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
include/hw/arm/npcm7xx.h +2 -2
index b0f50ff5c5..073a388b0f 100644
@@ -23,7 +23,7 @@
 #include "hw/gpio/npcm7xx_gpio.h"
 #include "hw/i2c/npcm7xx_smbus.h"
 #include "hw/mem/npcm7xx_mc.h"
-#include "hw/misc/npcm7xx_clk.h"
+#include "hw/misc/npcm_clk.h"
 #include "hw/misc/npcm_gcr.h"
 #include "hw/misc/npcm7xx_mft.h"
 #include "hw/misc/npcm7xx_pwm.h"
@@ -89,7 +89,7 @@ typedef struct NPCM7xxState {
     MemoryRegion        *dram;
 
     NPCMGCRState        gcr;
-    NPCM7xxCLKState     clk;
+    NPCMCLKState        clk;
     NPCM7xxTimerCtrlState tim[3];
     NPCM7xxADCState     adc;
     NPCM7xxPWMState     pwm[NPCM7XX_NR_PWM_MODULES];
include/hw/misc/npcm_clk.h renamed from include/hw/misc/npcm7xx_clk.h +29 -14

104 lines not on this page · raw message

Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
#7 lore raw

Re: [PATCH for-7.1 04/11] hw/misc: Support NPCM8XX CLK Module Registers

Quoted 4 lines · Hao Wu

NPCM8XX adds a few new registers and have a different set of reset values to the CLK modules. This patch supports them.

Quoted 8 lines

This patch doesn't support the new clock values generated by these registers. Currently no modules use these new clock values so they are not necessary at this point.
Implementation of these clocks might be required when implementing these modules.

Can you split this one up as well, please ? In particular keep the purely-mechanical changes (eg renaming structs) separate from actually-interesting ones.

thanks
-- PMM

author
#8 lore raw

PATCH 5/11 hw/misc: Store DRAM size in NPCM8XX GCR Module

In reply to Hao Wu

NPCM8XX boot block stores the DRAM size in SCRPAD_B register in GCR module. Since we don't simulate a detailed memory controller, we need to store this information directly similar to the NPCM7XX's INCTR3 register.

---
 hw/misc/npcm_gcr.c         | 33 ++++++++++++++++++++++++++++++---
 include/hw/misc/npcm_gcr.h |  1 +
 2 files changed, 31 insertions(+), 3 deletions(-)
hw/misc/npcm_gcr.c +30 -3
index 2349949599..14c298602a 100644
@@ -267,7 +267,7 @@ static const struct MemoryRegionOps npcm_gcr_ops = {
     },
 };
 
-static void npcm_gcr_enter_reset(Object *obj, ResetType type)
+static void npcm7xx_gcr_enter_reset(Object *obj, ResetType type)
 {
     NPCMGCRState *s = NPCM_GCR(obj);
     NPCMGCRClass *c = NPCM_GCR_GET_CLASS(obj);
@@ -283,6 +283,23 @@ static void npcm_gcr_enter_reset(Object *obj, ResetType type)
     }
 }
 
+static void npcm8xx_gcr_enter_reset(Object *obj, ResetType type)
+{
+    NPCMGCRState *s = NPCM_GCR(obj);
+    NPCMGCRClass *c = NPCM_GCR_GET_CLASS(obj);
+
+    switch (type) {
+    case RESET_TYPE_COLD:
+        memcpy(s->regs, c->cold_reset_values, c->nr_regs * sizeof(uint32_t));
+        /* These 3 registers are at the same location in both 7xx and 8xx. */
+        s->regs[NPCM8XX_GCR_PWRON] = s->reset_pwron;
+        s->regs[NPCM8XX_GCR_MDLR] = s->reset_mdlr;
+        s->regs[NPCM8XX_GCR_INTCR3] = s->reset_intcr3;
+        s->regs[NPCM8XX_GCR_SCRPAD_B] = s->reset_scrpad_b;
+        break;
+    }
+}
+
 static void npcm_gcr_realize(DeviceState *dev, Error **errp)
 {
     ERRP_GUARD();
@@ -326,6 +343,14 @@ static void npcm_gcr_realize(DeviceState *dev, Error **errp)
      * https://github.com/Nuvoton-Israel/u-boot/blob/2aef993bd2aafeb5408dbaad0f3ce099ee40c4aa/board/nuvoton/poleg/poleg.c#L244
      */
     s->reset_intcr3 |= ctz64(dram_size / NPCM7XX_GCR_MIN_DRAM_SIZE) << 8;
+
+    /*
+     * The boot block starting from 0.0.6 for NPCM8xx SoCs stores the DRAM size
+     * in the SCRPAD2 registers. We need to set this field correctly since
+     * the initialization is skipped as we mentioned above.
+     * https://github.com/Nuvoton-Israel/u-boot/blob/npcm8mnx-v2019.01_tmp/board/nuvoton/arbel/arbel.c#L737
+     */
+    s->reset_scrpad_b = dram_size;
 }
 
 static void npcm_gcr_init(Object *obj)
@@ -355,12 +380,10 @@ static Property npcm_gcr_properties[] = {
 
 static void npcm_gcr_class_init(ObjectClass *klass, void *data)
 {
-    ResettableClass *rc = RESETTABLE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->realize = npcm_gcr_realize;
     dc->vmsd = &vmstate_npcm_gcr;
-    rc->phases.enter = npcm_gcr_enter_reset;
 
     device_class_set_props(dc, npcm_gcr_properties);
 }
@@ -369,24 +392,28 @@ static void npcm7xx_gcr_class_init(ObjectClass *klass, void *data)
 {
     NPCMGCRClass *c = NPCM_GCR_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     QEMU_BUILD_BUG_ON(NPCM7XX_GCR_REGS_END > NPCM_GCR_MAX_NR_REGS);
     QEMU_BUILD_BUG_ON(NPCM7XX_GCR_REGS_END != NPCM7XX_GCR_NR_REGS);
     dc->desc = "NPCM7xx System Global Control Registers";
     c->nr_regs = NPCM7XX_GCR_NR_REGS;
     c->cold_reset_values = npcm7xx_cold_reset_values;
+    rc->phases.enter = npcm7xx_gcr_enter_reset;
 }
 
 static void npcm8xx_gcr_class_init(ObjectClass *klass, void *data)
 {
     NPCMGCRClass *c = NPCM_GCR_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     QEMU_BUILD_BUG_ON(NPCM8XX_GCR_REGS_END > NPCM_GCR_MAX_NR_REGS);
     QEMU_BUILD_BUG_ON(NPCM8XX_GCR_REGS_END != NPCM8XX_GCR_NR_REGS);
     dc->desc = "NPCM8xx System Global Control Registers";
     c->nr_regs = NPCM8XX_GCR_NR_REGS;
     c->cold_reset_values = npcm8xx_cold_reset_values;
+    rc->phases.enter = npcm8xx_gcr_enter_reset;
 }
 
 static const TypeInfo npcm_gcr_info[] = {
include/hw/misc/npcm_gcr.h +1 -0
index ac3d781c2e..bd69199d51 100644
@@ -39,6 +39,7 @@ typedef struct NPCMGCRState {
     uint32_t reset_pwron;
     uint32_t reset_mdlr;
     uint32_t reset_intcr3;
+    uint32_t reset_scrpad_b;
 } NPCMGCRState;
 
 typedef struct NPCMGCRClass {
Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
Reviewed-by on v1 5/11
#9 lore raw

Re: [PATCH for-7.1 05/11] hw/misc: Store DRAM size in NPCM8XX GCR Module

Quoted 9 lines · Hao Wu

NPCM8XX boot block stores the DRAM size in SCRPAD_B register in GCR module. Since we don't simulate a detailed memory controller, we need to store this information directly similar to the NPCM7XX's INCTR3 register.

---

thanks
-- PMM

author
#10 lore raw

PATCH 6/11 hw/intc: Add a property to allow GIC to reset into non secure mode

In reply to Hao Wu

This property allows certain boards like NPCM8xx to boot the kernel directly into non-secure mode. This is necessary since we do not support secure boot features for NPCM8xx now.

---
 hw/intc/arm_gic_common.c | 2 ++
 1 file changed, 2 insertions(+)
hw/intc/arm_gic_common.c +2 -0
index 7b44d5625b..7ddc5cfbd0 100644
@@ -358,6 +358,8 @@ static Property arm_gic_common_properties[] = {
     /* True if the GIC should implement the virtualization extensions */
     DEFINE_PROP_BOOL("has-virtualization-extensions", GICState, virt_extn, 0),
     DEFINE_PROP_UINT32("num-priority-bits", GICState, n_prio_bits, 8),
+    /* True if we want to directly booting a kernel into NonSecure */
+    DEFINE_PROP_BOOL("irq-reset-nonsecure", GICState, irq_reset_nonsecure, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
#11 lore raw

Re: [PATCH for-7.1 06/11] hw/intc: Add a property to allow GIC to reset into non secure mode

Quoted 16 lines · Hao Wu

This property allows certain boards like NPCM8xx to boot the kernel directly into non-secure mode. This is necessary since we do not support secure boot features for NPCM8xx now.

---
 hw/intc/arm_gic_common.c | 2 ++
 1 file changed, 2 insertions(+)
hw/intc/arm_gic_common.c +0 -0
index 7b44d5625b..7ddc5cfbd0 100644

hw/intc/arm_gic_common.c static Property arm_gic_common_properties[] = { · line 364

Quoted 7 lines
hw/intc/arm_gic_common.c +2 -0
@@ -358,6 +358,8 @@ static Property arm_gic_common_properties[] = {
     /* True if the GIC should implement the virtualization extensions */
     DEFINE_PROP_BOOL("has-virtualization-extensions", GICState, virt_extn, 0),
     DEFINE_PROP_UINT32("num-priority-bits", GICState, n_prio_bits, 8),
+    /* True if we want to directly booting a kernel into NonSecure */
+    DEFINE_PROP_BOOL("irq-reset-nonsecure", GICState, irq_reset_nonsecure, 0),
     DEFINE_PROP_END_OF_LIST(),
 };

This isn't how this is supposed to work. Non-firmware (ie Linux kernel boots) that have to emulate firmware init arrange to get the irq_reset_nonsecure flag set because the GIC implements the TYPE_ARM_LINUX_BOOT_IF and the boot.c code calls the callback for every device that implements that interface. For firmware boots, the firmware has to set up the GIC the way it wants.

thanks
-- PMM

author
#12 lore raw

PATCH 7/11 hw/misc: Support 8-bytes memop in NPCM GCR module

In reply to Hao Wu

The NPCM8xx GCR device can be accessed with 64-bit memory operations. This patch supports that.

---
 hw/misc/npcm_gcr.c   | 98 +++++++++++++++++++++++++++++++++-----------
 hw/misc/trace-events |  4 +-
 2 files changed, 77 insertions(+), 25 deletions(-)
hw/misc/npcm_gcr.c +75 -23
index 14c298602a..aa81db23d7 100644
@@ -201,6 +201,7 @@ static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size)
     uint32_t reg = offset / sizeof(uint32_t);
     NPCMGCRState *s = opaque;
     NPCMGCRClass *c = NPCM_GCR_GET_CLASS(s);
+    uint64_t value;
 
     if (reg >= c->nr_regs) {
         qemu_log_mask(LOG_GUEST_ERROR,
@@ -209,9 +210,23 @@ static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size)
         return 0;
     }
 
-    trace_npcm_gcr_read(offset, s->regs[reg]);
+    switch (size) {
+    case 4:
+        value = s->regs[reg];
+        break;
+
+    case 8:
+        value = s->regs[reg] + (((uint64_t)s->regs[reg + 1]) << 32);
+        break;
+
+    default:
+        g_assert_not_reached();
+    }
 
-    return s->regs[reg];
+    if (s->regs[reg] != 0) {
+        trace_npcm_gcr_read(offset, value);
+    }
+    return value;
 }
 
 static void npcm_gcr_write(void *opaque, hwaddr offset,
@@ -222,7 +237,7 @@ static void npcm_gcr_write(void *opaque, hwaddr offset,
     NPCMGCRClass *c = NPCM_GCR_GET_CLASS(s);
     uint32_t value = v;
 
-    trace_npcm_gcr_write(offset, value);
+    trace_npcm_gcr_write(offset, v);
 
     if (reg >= c->nr_regs) {
         qemu_log_mask(LOG_GUEST_ERROR,
@@ -231,29 +246,65 @@ static void npcm_gcr_write(void *opaque, hwaddr offset,
         return;
     }
 
-    switch (reg) {
-    case NPCM7XX_GCR_PDID:
-    case NPCM7XX_GCR_PWRON:
-    case NPCM7XX_GCR_INTSR:
-        qemu_log_mask(LOG_GUEST_ERROR,
-                      "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
-                      __func__, offset);
-        return;
-
-    case NPCM7XX_GCR_RESSR:
-    case NPCM7XX_GCR_CP2BST:
-        /* Write 1 to clear */
-        value = s->regs[reg] & ~value;
+    switch (size) {
+    case 4:
+        switch (reg) {
+        case NPCM7XX_GCR_PDID:
+        case NPCM7XX_GCR_PWRON:
+        case NPCM7XX_GCR_INTSR:
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
+                          __func__, offset);
+            return;
+
+        case NPCM7XX_GCR_RESSR:
+        case NPCM7XX_GCR_CP2BST:
+            /* Write 1 to clear */
+            value = s->regs[reg] & ~value;
+            break;
+
+        case NPCM7XX_GCR_RLOCKR1:
+        case NPCM7XX_GCR_MDLR:
+            /* Write 1 to set */
+            value |= s->regs[reg];
+            break;
+        };
+        s->regs[reg] = value;
         break;
 
-    case NPCM7XX_GCR_RLOCKR1:
-    case NPCM7XX_GCR_MDLR:
-        /* Write 1 to set */
-        value |= s->regs[reg];
+    case 8:
+        s->regs[reg] = value;
+        s->regs[reg + 1] = v >> 32;
         break;
-    };
 
-    s->regs[reg] = value;
+    default:
+        g_assert_not_reached();
+    }
+}
+
+static bool npcm_gcr_check_mem_op(void *opaque, hwaddr offset,
+                                  unsigned size, bool is_write,
+                                  MemTxAttrs attrs)
+{
+    NPCMGCRClass *c = NPCM_GCR_GET_CLASS(opaque);
+
+    if (offset >= c->nr_regs * sizeof(uint32_t)) {
+        return false;
+    }
+
+    switch (size) {
+    case 4:
+        return true;
+    case 8:
+        if (offset >= NPCM8XX_GCR_SCRPAD_00 * sizeof(uint32_t) &&
+            offset < (NPCM8XX_GCR_NR_REGS - 1) * sizeof(uint32_t)) {
+            return true;
+        } else {
+            return false;
+        }
+    default:
+        return false;
+    }
 }
 
 static const struct MemoryRegionOps npcm_gcr_ops = {
@@ -262,7 +313,8 @@ static const struct MemoryRegionOps npcm_gcr_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
     .valid      = {
         .min_access_size        = 4,
-        .max_access_size        = 4,
+        .max_access_size        = 8,
+        .accepts                = npcm_gcr_check_mem_op,
         .unaligned              = false,
     },
 };
hw/misc/trace-events +2 -2
index 02650acfff..2ffec963e7 100644
@@ -103,8 +103,8 @@ npcm_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value:
 npcm_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
 
 # npcm_gcr.c
-npcm_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
-npcm_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
+npcm_gcr_read(uint64_t offset, uint64_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx64
+npcm_gcr_write(uint64_t offset, uint64_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx64
 
 # npcm7xx_mft.c
 npcm7xx_mft_read(const char *name, uint64_t offset, uint16_t value) "%s: offset: 0x%04" PRIx64 " value: 0x%04" PRIx16
Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
#13 lore raw

Re: [PATCH for-7.1 07/11] hw/misc: Support 8-bytes memop in NPCM GCR module

Quoted 33 lines · Hao Wu

The NPCM8xx GCR device can be accessed with 64-bit memory operations. This patch supports that.

---
 hw/misc/npcm_gcr.c   | 98 +++++++++++++++++++++++++++++++++-----------
 hw/misc/trace-events |  4 +-
 2 files changed, 77 insertions(+), 25 deletions(-)
hw/misc/npcm_gcr.c +6 -1
index 14c298602a..aa81db23d7 100644
@@ -201,6 +201,7 @@ static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size)
     uint32_t reg = offset / sizeof(uint32_t);
     NPCMGCRState *s = opaque;
     NPCMGCRClass *c = NPCM_GCR_GET_CLASS(s);
+    uint64_t value;
 
     if (reg >= c->nr_regs) {
         qemu_log_mask(LOG_GUEST_ERROR,
@@ -209,9 +210,23 @@ static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size)
         return 0;
     }
 
-    trace_npcm_gcr_read(offset, s->regs[reg]);
+    switch (size) {
+    case 4:
+        value = s->regs[reg];
+        break;
+

hw/misc/npcm_gcr.c static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size) · line 226

Quoted 10 lines
hw/misc/npcm_gcr.c +8 -1
+    case 8:
+        value = s->regs[reg] + (((uint64_t)s->regs[reg + 1]) << 32);
+        break;
+
+    default:
+        g_assert_not_reached();
+    }
 
-    return s->regs[reg];
+    if (s->regs[reg] != 0) {

Why are we now only tracing the read if it's not 0 ?

hw/misc/npcm_gcr.c static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size) · line 230

Quoted 4 lines
hw/misc/npcm_gcr.c +3 -0
+        trace_npcm_gcr_read(offset, value);
+    }
+    return value;
 }

-- PMM

author
#14 lore raw

PATCH 8/11 hw/net: Add NPCM8XX PCS Module

In reply to Hao Wu

The PCS exists in NPCM8XX's GMAC1 and is used to control the SGMII PHY. This implementation contains all the default registers and the soft reset feature that are required to load the Linux kernel driver. Further features have not been implemented yet.

---
 hw/net/meson.build        |   1 +
 hw/net/npcm_pcs.c         | 409 ++++++++++++++++++++++++++++++++++++++
 hw/net/trace-events       |   4 +
 include/hw/net/npcm_pcs.h |  42 ++++
 4 files changed, 456 insertions(+)
 create mode 100644 hw/net/npcm_pcs.c
 create mode 100644 include/hw/net/npcm_pcs.h
hw/net/meson.build +1 -0
index 685b75badb..4cba3e66db 100644
@@ -37,6 +37,7 @@ softmmu_ss.add(when: 'CONFIG_SUNHME', if_true: files('sunhme.c'))
 softmmu_ss.add(when: 'CONFIG_FTGMAC100', if_true: files('ftgmac100.c'))
 softmmu_ss.add(when: 'CONFIG_SUNGEM', if_true: files('sungem.c'))
 softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_emc.c'))
+softmmu_ss.add(when: 'CONFIG_NPCM8XX', if_true: files('npcm_pcs.c'))
 
 softmmu_ss.add(when: 'CONFIG_ETRAXFS', if_true: files('etraxfs_eth.c'))
 softmmu_ss.add(when: 'CONFIG_COLDFIRE', if_true: files('mcf_fec.c'))
hw/net/npcm_pcs.c new file +409 -0

409 lines not on this page · raw message

hw/net/trace-events +4 -0
index 4c0ec3fda1..2bb8af4d7b 100644
@@ -438,6 +438,10 @@ npcm7xx_emc_rx_done(uint32_t crxdsa) "RX done, CRXDSA=0x%x"
 npcm7xx_emc_reg_read(int emc_num, uint32_t result, const char *name, int regno) "emc%d: 0x%x = reg[%s/%d]"
 npcm7xx_emc_reg_write(int emc_num, const char *name, int regno, uint32_t value) "emc%d: reg[%s/%d] = 0x%x"
 
+# npcm_pcs.c
+npcm_pcs_reg_read(const char *name, uint16_t indirect_access_baes, uint64_t offset, uint16_t value) "%s: IND: 0x%02" PRIx16 " offset: 0x%04" PRIx64 " value: 0x%04" PRIx16
+npcm_pcs_reg_write(const char *name, uint16_t indirect_access_baes, uint64_t offset, uint16_t value) "%s: IND: 0x%02" PRIx16 " offset: 0x%04" PRIx64 " value: 0x%04" PRIx16
+
 # dp8398x.c
 dp8393x_raise_irq(int isr) "raise irq, isr is 0x%04x"
 dp8393x_lower_irq(void) "lower irq"
include/hw/net/npcm_pcs.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
#15 lore raw

Re: [PATCH for-7.1 08/11] hw/net: Add NPCM8XX PCS Module

Quoted 9 lines · Hao Wu

The PCS exists in NPCM8XX's GMAC1 and is used to control the SGMII PHY. This implementation contains all the default registers and the soft reset feature that are required to load the Linux kernel driver. Further features have not been implemented yet.

hw/net/npcm_pcs.c line 156

Quoted 8 lines
hw/net/npcm_pcs.c new file +8 -0
+static uint16_t npcm_pcs_read_sr_ctl(NPCMPCSState *s, hwaddr offset)
+{
+    hwaddr regno = offset / sizeof(uint16_t);
+
+    if (regno >= NPCM_PCS_NR_SR_CTLS) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: SR_CTL read offset 0x%04" HWADDR_PRIx
+                      " is out of range.",

qemu_log_mask strings need to have a trailing "\n" (here and below)

Quoted 18 lines
hw/net/npcm_pcs.c new file +18 -0
+static uint64_t npcm_pcs_read(void *opaque, hwaddr offset, unsigned size)
+{
+    NPCMPCSState *s = opaque;
+    uint16_t v = 0;
+
+    if (offset == NPCM_PCS_IND_AC_BA) {
+        v = s->indirect_access_base;
+    } else {
+        switch (s->indirect_access_base) {
+        case NPCM_PCS_IND_SR_CTL:
+            v = npcm_pcs_read_sr_ctl(s, offset);
+            break;
+
+        case NPCM_PCS_IND_SR_MII:
+            v = npcm_pcs_read_sr_mii(s, offset);
+            break;
+
+        case NPCM_PCS_IND_SR_TIM:

hw/net/npcm_pcs.c line 301

Quoted 10 lines
hw/net/npcm_pcs.c new file +10 -0
+            v = npcm_pcs_read_sr_tim(s, offset);
+            break;
+
+        case NPCM_PCS_IND_VR_MII:
+            v = npcm_pcs_read_vr_mii(s, offset);
+            break;
+
+        default:
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "%s: Read with invalid indirect address base: 0x%02"

Why are you specifying a width of 2 here? The valid values are definitely larger than 2 digits wide, so presumably invalid values probably are as well...

Quoted 5 lines
hw/net/npcm_pcs.c new file +5 -0
+                          PRIx16 "\n", DEVICE(s)->canonical_path,
+                          s->indirect_access_base);
+        }
+    }
+

hw/net/npcm_pcs.c line 394

Quoted 10 lines
hw/net/npcm_pcs.c new file +9 -0
+    trace_npcm_pcs_reg_read(DEVICE(s)->canonical_path, s->indirect_access_base,
+                            offset, v);
+    return v;
+}
 
+static void npcm_pcs_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);

Not sure this is the right category -- this doesn't seem to be a network device in the usual sense.

hw/net/trace-events npcm7xx_emc_rx_done(uint32_t crxdsa) "RX done, CRXDSA=0x%x" · line 443

Quoted 3 lines
hw/net/trace-events +3 -0
+# npcm_pcs.c
+npcm_pcs_reg_read(const char *name, uint16_t indirect_access_baes, uint64_t offset, uint16_t value) "%s: IND: 0x%02" PRIx16 " offset: 0x%04" PRIx64 " value: 0x%04" PRIx16
+npcm_pcs_reg_write(const char *name, uint16_t indirect_access_baes, uint64_t offset, uint16_t value) "%s: IND: 0x%02" PRIx16 " offset: 0x%04" PRIx64 " value: 0x%04" PRIx16

Typo : should be "_base" I assume.

Quoted 40 lines
hw/net/trace-events +1 -0
+
 # dp8398x.c
 dp8393x_raise_irq(int isr) "raise irq, isr is 0x%04x"
 dp8393x_lower_irq(void) "lower irq"
include/hw/net/npcm_pcs.h new file +30 -0
new file mode 100644
index 0000000000..bd4f71bf3c
@@ -0,0 +1,42 @@
+/*
+ * Nuvoton NPCM8xx PCS Module
+ *
+ * Copyright 2022 Google LLC
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef NPCM_PCS_H
+#define NPCM_PCS_H
+
+#include "hw/sysbus.h"
+
+#define NPCM_PCS_NR_SR_CTLS     (0x12 / sizeof(uint16_t))
+#define NPCM_PCS_NR_SR_MIIS     (0x20 / sizeof(uint16_t))
+#define NPCM_PCS_NR_SR_TIMS     (0x22 / sizeof(uint16_t))
+#define NPCM_PCS_NR_VR_MIIS     (0x1c6 / sizeof(uint16_t))
+
+typedef struct NPCMPCSState {
+    SysBusDevice parent;
+
+    MemoryRegion iomem;

include/hw/net/npcm_pcs.h line 40

Quoted 10 lines
include/hw/net/npcm_pcs.h new file +10 -0
+
+    uint16_t indirect_access_base;
+    uint16_t sr_ctl[NPCM_PCS_NR_SR_CTLS];
+    uint16_t sr_mii[NPCM_PCS_NR_SR_MIIS];
+    uint16_t sr_tim[NPCM_PCS_NR_SR_TIMS];
+    uint16_t vr_mii[NPCM_PCS_NR_VR_MIIS];
+} NPCMPCSState;
+
+#define TYPE_NPCM_PCS "npcm-pcs"
+OBJECT_DECLARE_SIMPLE_TYPE(NPCMPCSState, NPCM_PCS)

OBJECT_DECLARE_SIMPLE_TYPE does the 'typedef' for you, so you don't need to do that in your struct definition if you're using that macro.

thanks
-- PMM

author
#16 lore raw

PATCH 9/11 pc-bios: Add NPCM8xx Bootrom

In reply to Hao Wu

The bootrom is a minimal bootrom that can be used to bring up an NPCM845 Linux kernel. Its source code can be found at github.com/google/vbootrom/tree/master/npcm8xx

---
 pc-bios/npcm8xx_bootrom.bin | Bin 0 -> 608 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 pc-bios/npcm8xx_bootrom.bin
pc-bios/npcm8xx_bootrom.bin new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..6370d6475635c4d445d2b927311edcd591949c82
GIT binary patch
Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
#17 lore raw

Re: [PATCH for-7.1 09/11] pc-bios: Add NPCM8xx Bootrom

pc-bios/npcm8xx_bootrom.bin

Quoted 24 lines · Hao Wu

The bootrom is a minimal bootrom that can be used to bring up an NPCM845 Linux kernel. Its source code can be found at github.com/google/vbootrom/tree/master/npcm8xx

---
 pc-bios/npcm8xx_bootrom.bin | Bin 0 -> 608 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 pc-bios/npcm8xx_bootrom.bin
pc-bios/npcm8xx_bootrom.bin new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..6370d6475635c4d445d2b927311edcd591949c82
GIT binary patch

You can't just dump a sourceless binary into pc-bios/. Check out the commit that added the npcm7xx bootrom blob for what else you need: that's commit d1cb5eda67a0a6.

In particular you need to document it in the README file, and have runes in the Makefile to rebuild the blob from source (and running the Makefile should be how the blob in the commit was created!). You'll probably also want a preceding commit to bump the vbootrom submodule commit and provide a fresh npcm7xx_bootrom blob from whatever commit you choose to bump the submodule to.

thanks
-- PMM

author
#18 lore raw

PATCH 10/11 hw/arm: Add NPCM8XX SoC

In reply to Hao Wu

The file contains a basic NPCM8XX SOC file. It's forked from the NPCM7XX SOC with some changes.

---
 configs/devices/aarch64-softmmu/default.mak |   1 +
 hw/arm/Kconfig                              |  11 +
 hw/arm/meson.build                          |   1 +
 hw/arm/npcm8xx.c                            | 806 ++++++++++++++++++++
 include/hw/arm/npcm8xx.h                    | 106 +++
 5 files changed, 925 insertions(+)
 create mode 100644 hw/arm/npcm8xx.c
 create mode 100644 include/hw/arm/npcm8xx.h
configs/devices/aarch64-softmmu/default.mak +1 -0
index cf43ac8da1..1c3cf6dda1 100644
@@ -6,3 +6,4 @@ include ../arm-softmmu/default.mak
 CONFIG_XLNX_ZYNQMP_ARM=y
 CONFIG_XLNX_VERSAL=y
 CONFIG_SBSA_REF=y
+CONFIG_NPCM8XX=y
hw/arm/Kconfig +11 -0
index 97f3b38019..ed5d37ba01 100644
@@ -408,6 +408,17 @@ config NPCM7XX
     select UNIMP
     select PCA954X
 
+config NPCM8XX
+    bool
+    select ARM_GIC
+    select SMBUS
+    select PL310  # cache controller
+    select NPCM7XX
+    select SERIAL
+    select SSI
+    select UNIMP
+
+
 config FSL_IMX25
     bool
     imply I2C_DEVICES
hw/arm/meson.build +1 -0
index 721a8eb8be..cf824241c5 100644
@@ -14,6 +14,7 @@ arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c'))
 arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
 arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c'))
 arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c', 'npcm7xx_boards.c'))
+arm_ss.add(when: 'CONFIG_NPCM8XX', if_true: files('npcm8xx.c'))
 arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c'))
 arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
 arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c'))
hw/arm/npcm8xx.c new file +806 -0

806 lines not on this page · raw message

include/hw/arm/npcm8xx.h new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
author
#19 lore raw

PATCH 11/11 hw/arm: Add NPCM845 Evaluation board

In reply to Hao Wu
---
 hw/arm/meson.build       |   2 +-
 hw/arm/npcm8xx_boards.c  | 257 +++++++++++++++++++++++++++++++++++++++
 include/hw/arm/npcm8xx.h |  20 +++
 3 files changed, 278 insertions(+), 1 deletion(-)
 create mode 100644 hw/arm/npcm8xx_boards.c
hw/arm/meson.build +1 -1
index cf824241c5..e813cd72fa 100644
@@ -14,7 +14,7 @@ arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c'))
 arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
 arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c'))
 arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c', 'npcm7xx_boards.c'))
-arm_ss.add(when: 'CONFIG_NPCM8XX', if_true: files('npcm8xx.c'))
+arm_ss.add(when: 'CONFIG_NPCM8XX', if_true: files('npcm8xx.c', 'npcm8xx_boards.c'))
 arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c'))
 arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
 arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c'))
hw/arm/npcm8xx_boards.c new file +257 -0

257 lines not on this page · raw message

include/hw/arm/npcm8xx.h +20 -0
index a474c7991b..771bfae377 100644
@@ -51,6 +51,26 @@
 
 #define NPCM8XX_NR_PWM_MODULES 3
 
+typedef struct NPCM8xxMachine {
+    MachineState        parent;
+    /*
+     * PWM fan splitter. each splitter connects to one PWM output and
+     * multiple MFT inputs.
+     */
+    SplitIRQ            fan_splitter[NPCM8XX_NR_PWM_MODULES *
+                                     NPCM7XX_PWM_PER_MODULE];
+} NPCM8xxMachine;
+
+
+typedef struct NPCM8xxMachineClass {
+    MachineClass        parent;
+
+    const char          *soc_type;
+} NPCM8xxMachineClass;
+
+#define TYPE_NPCM8XX_MACHINE MACHINE_TYPE_NAME("npcm8xx")
+OBJECT_DECLARE_TYPE(NPCM8xxMachine, NPCM8xxMachineClass, NPCM8XX_MACHINE)
+
 typedef struct NPCM8xxState {
     DeviceState         parent;
 
Signature · 1 line
2.35.1.1094.g7c7d902a7c-goog
#20 lore raw

Re: [PATCH for-7.1 11/11] hw/arm: Add NPCM845 Evaluation board

Quoted 29 lines · Hao Wu
---
 hw/arm/meson.build       |   2 +-
 hw/arm/npcm8xx_boards.c  | 257 +++++++++++++++++++++++++++++++++++++++
 include/hw/arm/npcm8xx.h |  20 +++
 3 files changed, 278 insertions(+), 1 deletion(-)
 create mode 100644 hw/arm/npcm8xx_boards.c
hw/arm/npcm8xx_boards.c new file +16 -0
@@ -0,0 +1,257 @@
+/*
+ * Machine definitions for boards featuring an NPCM8xx SoC.
+ *
+ * Copyright 2022 Google LLC
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+

hw/arm/npcm8xx_boards.c line 26

Quoted 10 lines
hw/arm/npcm8xx_boards.c new file +10 -0
+#include "qemu/osdep.h"
+
+#include "chardev/char.h"
+#include "hw/arm/npcm8xx.h"
+#include "hw/core/cpu.h"
+#include "hw/loader.h"
+#include "hw/qdev-core.h"
+#include "hw/qdev-properties.h"
+#include "qapi/error.h"
+#include "qemu-common.h"

Don't include qemu-common.h unless you really need it (if you rebase on current head-of-git you almost certainly don't, as it now contains only a very few things, most of its previous contents having been split into more specific header files). There are some patches in flight which rename/delete it entirely, so if you don't #include it you'll avoid a conflict when they land.

thanks
-- PMM

#21 lore raw
In reply to Hao Wu
Quoted 4 lines · Hao Wu

NPCM8XX BMCs are the successors of the NPCM7XX BMCs. They feature quad-core ARM Cortex A35 that supports both 32 bits and 64 bits operations.

Here and in the documentation patch you say "Cortex-A35", but the patch implementing the new SoC creates Cortex-A53 CPUs. Which is correct ?

thanks
-- PMM

author
#22 lore raw

Thanks for all the comments you gave! I'll go over and address them recently.

For this question, The actual CPU should be cortex A35. However, I don't see them supported in QEMU. If I inserted CPU with "cortex-a35" QEMU will complain:
qemu-system-aarch64: missing object type 'cortex-a35-arm-cpu'

What should I do here?

Quoted 13 lines · Peter Maydell
Quoted 4 lines · Hao Wu

NPCM8XX BMCs are the successors of the NPCM7XX BMCs. They feature quad-core ARM Cortex A35 that supports both 32 bits and 64 bits operations.

Here and in the documentation patch you say "Cortex-A35", but the patch implementing the new SoC creates Cortex-A53 CPUs. Which is correct ?

thanks
-- PMM

#23 lore raw
Quoted 8 lines · Hao Wu

Thanks for all the comments you gave! I'll go over and address them recently.

For this question, The actual CPU should be cortex A35. However, I don't see them supported in QEMU. If I inserted CPU with "cortex-a35" QEMU will complain:
qemu-system-aarch64: missing object type 'cortex-a35-arm-cpu'

What should I do here?

You need to implement the new CPU type first... This means adding something to target/arm/cpu64.c which will look similar to the existing CPU handling. You need to watch out for:
* getting all the ID register values right (check the TRM for the CPU)
* implementing whatever the right impdef system registers are
* checking whether QEMU is still missing support for any of the architectural features that the A35 implements (what QEMU supports is listed in docs/system/arm/emulation.rst)

It's typically not much code but quite a lot of cross-checking against the TRM for the CPU that we're not missing pieces... Since you can add the A35 as a supported CPU type for the 'virt' board you can do A35 support as a separate patchset that doesn't depend on the npmc8xx work.

https://patchew.org/QEMU/[email protected]/[email protected]/
is an example of how to add a new CPU (in that case the A76), at the end of a large patchset from RTH that's still going through code review.

-- PMM

author
#24 lore raw

Thanks!

I can add the new CPU type to virt in a separate patch set. It might take a while before I send out
that patch set.

Since this patch set will be dependent on that I won't send out a v2 on this patch set until that finishes.

Quoted 36 lines · Peter Maydell
Quoted 2 lines · Hao Wu

Thanks for all the comments you gave! I'll go over and address them

recently.

Quoted 2 lines

For this question, The actual CPU should be cortex A35. However, I don't

see

Quoted 1 line

them supported in QEMU. If I inserted CPU with "cortex-a35" QEMU will

complain:

Quoted 3 lines

qemu-system-aarch64: missing object type 'cortex-a35-arm-cpu'

What should I do here?

You need to implement the new CPU type first... This means adding something to target/arm/cpu64.c which will look similar to the existing CPU handling. You need to watch out for:
* getting all the ID register values right (check the TRM for the CPU)
* implementing whatever the right impdef system registers are
* checking whether QEMU is still missing support for any of the architectural features that the A35 implements (what QEMU supports is listed in docs/system/arm/emulation.rst)

It's typically not much code but quite a lot of cross-checking against the TRM for the CPU that we're not missing pieces... Since you can add the A35 as a supported CPU type for the 'virt' board you can do A35 support as a separate patchset that doesn't depend on the npmc8xx work.

https://patchew.org/QEMU/[email protected]/[email protected]/
is an example of how to add a new CPU (in that case the A76), at the end of a large patchset from RTH that's still going through code review.

-- PMM