Skip to contentSkip to conversation

aspeed: misc fixes and enhancements (SMC)

PATCH In review Cédric Le Goater 3 participants 30 messages Sep 21, 2018 – Nov 28, 2018 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

v2 cover aspeed: misc fixes and enhancements (SMC)

Hello,

This series adds a couple of cleanups and two main features to the SMC controller of the Aspeed machines :

- a 'execute-in-place' property to boot directly from a memory region alias of the FMC flash module using MMIO execution. This is not activated by default because boot time needs to be improved on recent firmwares. It also breaks migration compatibility.

- support for DMA to access the flash modules. Our primary need is the checksum calculation which is used to evaluate the best clock settings for reads.

Thanks,

C.

Changes since v1:

- fixed #ifdef leading underscore
- changed the name of the property from 'mmio-exec' to 'execute-in-place'
- improved changelogs
- introduced a DMA address space for the SMC controller

Cédric Le Goater (11):
aspeed/timer: fix compile breakage with clang 3.4.2 hw/arm/aspeed: change the FMC flash model of the AST2500 evb hw/arm/aspeed: Add an Aspeed machine class
hw/arm/aspeed: add a 'execute-in-place' property to boot directly from

    CE0

aspeed/smc: fix some alignment issues
aspeed/smc: fix default read value
aspeed/smc: add a 'sdram_base' and 'max-ram-size' properties aspeed/smc: add support for DMAs
aspeed/smc: add DMA calibration settings aspeed/smc: inject errors in DMA checksum aspeed/smc: Add dummy data register

 include/hw/arm/aspeed.h         |  48 +++++
 include/hw/ssi/aspeed_smc.h     |   6 +
 include/hw/timer/aspeed_timer.h |   3 +-
 hw/arm/aspeed.c                 | 256 ++++++++++--------------
 hw/arm/aspeed_soc.c             |  28 ++-
 hw/ssi/aspeed_smc.c             | 341 ++++++++++++++++++++++++++++++--
 hw/timer/aspeed_timer.c         |   1 -
 7 files changed, 509 insertions(+), 174 deletions(-)
 create mode 100644 include/hw/arm/aspeed.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/11 aspeed/timer: fix compile breakage with clang 3.4.2

In file included from /home/thuth/devel/qemu/hw/timer/aspeed_timer.c:16:
/home/thuth/devel/qemu/include/hw/misc/aspeed_scu.h:37:3: error:
redefinition of typedef 'AspeedSCUState' is a C11 feature
[-Werror,-Wtypedef-redefinition]
} AspeedSCUState;
^
/home/thuth/devel/qemu/include/hw/timer/aspeed_timer.h:27:31: note:
previous definition is here
typedef struct AspeedSCUState AspeedSCUState;

---
 include/hw/timer/aspeed_timer.h | 3 +--
 hw/timer/aspeed_timer.c         | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)
include/hw/timer/aspeed_timer.h +1 -2
index 040a08873432..1fb949e16710 100644
@@ -23,8 +23,7 @@
 #define ASPEED_TIMER_H
 
 #include "qemu/timer.h"
-
-typedef struct AspeedSCUState AspeedSCUState;
+#include "hw/misc/aspeed_scu.h"
 
 #define ASPEED_TIMER(obj) \
     OBJECT_CHECK(AspeedTimerCtrlState, (obj), TYPE_ASPEED_TIMER);
hw/timer/aspeed_timer.c +0 -1
index 5e3f51b66b43..54b400b94aa9 100644
@@ -13,7 +13,6 @@
 #include "qapi/error.h"
 #include "hw/sysbus.h"
 #include "hw/timer/aspeed_timer.h"
-#include "hw/misc/aspeed_scu.h"
 #include "qemu-common.h"
 #include "qemu/bitops.h"
 #include "qemu/timer.h"
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/11 hw/arm/aspeed: change the FMC flash model of the AST2500 evb

In reply to Cédric Le Goater

The AST2500 evb is shipped with a W25Q256 which has a non volatile bit to make the chip operate in 4 Byte address mode at power up. This should be an interesting feature to model as it will exercise a bit more the SMC controllers and MMIO execution at boot time.

---
 hw/arm/aspeed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/aspeed.c +1 -1
index bb9590f1aed1..f2d64e45511a 100644
@@ -105,7 +105,7 @@ static const AspeedBoardConfig aspeed_boards[] = {
     [AST2500_EVB]  = {
         .soc_name  = "ast2500-a1",
         .hw_strap1 = AST2500_EVB_HW_STRAP1,
-        .fmc_model = "n25q256a",
+        .fmc_model = "w25q256",
         .spi_model = "mx25l25635e",
         .num_cs    = 1,
         .i2c_init  = ast2500_evb_i2c_init,
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 3/11 hw/arm/aspeed: Add an Aspeed machine class

In reply to Cédric Le Goater

The code looks better, it removes duplicated lines and it will ease the introduction of common properties for the Aspeed machines.

---
 include/hw/arm/aspeed.h |  46 +++++++++
 hw/arm/aspeed.c         | 212 +++++++++++++---------------------------
 2 files changed, 116 insertions(+), 142 deletions(-)
 create mode 100644 include/hw/arm/aspeed.h
include/hw/arm/aspeed.h new file +46 -0
new file mode 100644
index 000000000000..325c091d09e4
@@ -0,0 +1,46 @@
+/*
+ * Aspeed Machines
+ *
+ * Copyright 2018 IBM Corp.
+ *
+ * This code is licensed under the GPL version 2 or later.  See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef ARM_ASPEED_H
+#define ARM_ASPEED_H
+
+#include "hw/boards.h"
+
+typedef struct AspeedBoardState AspeedBoardState;
+
+typedef struct AspeedBoardConfig {
+    const char *name;
+    const char *desc;
+    const char *soc_name;
+    uint32_t hw_strap1;
+    const char *fmc_model;
+    const char *spi_model;
+    uint32_t num_cs;
+    void (*i2c_init)(AspeedBoardState *bmc);
+} AspeedBoardConfig;
+
+#define TYPE_ASPEED_MACHINE       MACHINE_TYPE_NAME("aspeed")
+#define ASPEED_MACHINE(obj) \
+    OBJECT_CHECK(AspeedMachine, (obj), TYPE_ASPEED_MACHINE)
+
+typedef struct AspeedMachine {
+    MachineState parent_obj;
+} AspeedMachine;
+
+#define ASPEED_MACHINE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(AspeedMachineClass, (klass), TYPE_ASPEED_MACHINE)
+#define ASPEED_MACHINE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(AspeedMachineClass, (obj), TYPE_ASPEED_MACHINE)
+
+typedef struct AspeedMachineClass {
+    MachineClass parent_obj;
+    const AspeedBoardConfig *board;
+} AspeedMachineClass;
+
+
+#endif
hw/arm/aspeed.c +70 -142

270 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v2 03/11] hw/arm/aspeed: Add an Aspeed machine class

Quoted 21 lines · Cédric Le Goater

The code looks better, it removes duplicated lines and it will ease the introduction of common properties for the Aspeed machines.

---
 include/hw/arm/aspeed.h |  46 +++++++++
 hw/arm/aspeed.c         | 212 +++++++++++++---------------------------
 2 files changed, 116 insertions(+), 142 deletions(-)
 create mode 100644 include/hw/arm/aspeed.h
include/hw/arm/aspeed.h new file +4 -0
new file mode 100644
index 000000000000..325c091d09e4
@@ -0,0 +1,46 @@
+/*
+ * Aspeed Machines
+ *
+ * Copyright 2018 IBM Corp.

include/hw/arm/aspeed.h line 14

Quoted 10 lines
include/hw/arm/aspeed.h new file +10 -0
+ *
+ * This code is licensed under the GPL version 2 or later.  See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef ARM_ASPEED_H
+#define ARM_ASPEED_H
+
+#include "hw/boards.h"
+
+typedef struct AspeedBoardState AspeedBoardState;

Hi Cédric,

this patch breaks compiling with clang v3.4.2 here:

CC aarch64-softmmu/hw/arm/aspeed.o
hw/arm/aspeed.c:36:3: error: redefinition of typedef 'AspeedBoardState' is a C11
feature [-Werror,-Wtypedef-redefinition]
} AspeedBoardState;
^
include/hw/arm/aspeed.h:14:33: note: previous definition is here

typedef struct AspeedBoardState AspeedBoardState;
                                ^

1 error generated.
make[1]: *** [hw/arm/aspeed.o] Error 1
make: *** [subdir-aarch64-softmmu] Error 2

Seems like it can be fixed like this:

hw/arm/aspeed.c +2 -2
@@ -29,11 +29,11 @@ static struct arm_boot_info aspeed_board_binfo = {
     .nb_cpus = 1,
 };
 
-typedef struct AspeedBoardState {
+struct AspeedBoardState {
     AspeedSoCState soc;
     MemoryRegion ram;
     MemoryRegion max_ram;
-} AspeedBoardState;
+};
 

... does that look OK for you, too?

Quoted 21 lines
include/hw/arm/aspeed.h new file +21 -0
+typedef struct AspeedBoardConfig {
+    const char *name;
+    const char *desc;
+    const char *soc_name;
+    uint32_t hw_strap1;
+    const char *fmc_model;
+    const char *spi_model;
+    uint32_t num_cs;
+    void (*i2c_init)(AspeedBoardState *bmc);
+} AspeedBoardConfig;
+
+#define TYPE_ASPEED_MACHINE       MACHINE_TYPE_NAME("aspeed")
+#define ASPEED_MACHINE(obj) \
+    OBJECT_CHECK(AspeedMachine, (obj), TYPE_ASPEED_MACHINE)
+
+typedef struct AspeedMachine {
+    MachineState parent_obj;
+} AspeedMachine;
+
+#define ASPEED_MACHINE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(AspeedMachineClass, (klass), TYPE_ASPEED_MACHINE)

include/hw/arm/aspeed.h line 45

Quoted 10 lines
include/hw/arm/aspeed.h new file +10 -0
+#define ASPEED_MACHINE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(AspeedMachineClass, (obj), TYPE_ASPEED_MACHINE)
+
+typedef struct AspeedMachineClass {
+    MachineClass parent_obj;
+    const AspeedBoardConfig *board;
+} AspeedMachineClass;
+
+
+#endif

Thomas

#5 lore raw

PATCH v2 4/11 hw/arm/aspeed: add a 'execute-in-place' property to boot directly from CE0

In reply to Cédric Le Goater

The overhead for the OpenBMC firmware images using the a custom U-Boot is around 2 seconds, which is fine, but with a U-Boot from mainline, it takes an extra 50 seconds or so to reach Linux. A quick survey on the number of reads performed on the flash memory region gives the following figures :

OpenBMC U-Boot 922478 (~ 3.5 MBytes)
Mainline U-Boot 20569977 (~ 80 MBytes)

QEMU must be trashing the TCG TBs and reloading text very often. Some addresses are read more than 250.000 times. Until we find a solution to improve boot time, execution from MMIO is not activated by default.

Setting this option also breaks migration compatibility.

---
 include/hw/arm/aspeed.h |  2 ++
 hw/arm/aspeed.c         | 44 ++++++++++++++++++++++++++++++++++++-----
 2 files changed, 41 insertions(+), 5 deletions(-)
include/hw/arm/aspeed.h +2 -0
index 325c091d09e4..b67f633ddbd1 100644
@@ -30,6 +30,8 @@ typedef struct AspeedBoardConfig {
 
 typedef struct AspeedMachine {
     MachineState parent_obj;
+
+    bool mmio_exec;
 } AspeedMachine;
 
 #define ASPEED_MACHINE_CLASS(klass) \
hw/arm/aspeed.c +39 -5

68 lines not on this page · raw message

Signature · 1 line
2.17.1
Reviewed-by on v2 4/11
#6 lore raw

Re: [Qemu-arm] [PATCH v2 04/11] hw/arm/aspeed: add a 'execute-in-place' property to boot directly from CE0

Quoted 9 lines · Cédric Le Goater

The overhead for the OpenBMC firmware images using the a custom U-Boot is around 2 seconds, which is fine, but with a U-Boot from mainline, it takes an extra 50 seconds or so to reach Linux. A quick survey on the number of reads performed on the flash memory region gives the following figures :

OpenBMC U-Boot 922478 (~ 3.5 MBytes)
Mainline U-Boot 20569977 (~ 80 MBytes)

Quoted 7 lines

QEMU must be trashing the TCG TBs and reloading text very often. Some addresses are read more than 250.000 times. Until we find a solution to improve boot time, execution from MMIO is not activated by default.

Setting this option also breaks migration compatibility.

thanks
-- PMM

#7 lore raw

Re: [Qemu-arm] [PATCH v2 04/11] hw/arm/aspeed: add a 'execute-in-place' property to boot directly from CE0

Quoted 14 lines · Peter Maydell
Quoted 13 lines · Cédric Le Goater

The overhead for the OpenBMC firmware images using the a custom U-Boot is around 2 seconds, which is fine, but with a U-Boot from mainline, it takes an extra 50 seconds or so to reach Linux. A quick survey on the number of reads performed on the flash memory region gives the following figures :

OpenBMC U-Boot 922478 (~ 3.5 MBytes)
Mainline U-Boot 20569977 (~ 80 MBytes)

QEMU must be trashing the TCG TBs and reloading text very often. Some addresses are read more than 250.000 times. Until we find a solution to improve boot time, execution from MMIO is not activated by default.

Quoted 5 lines
Quoted 3 lines

Setting this option also breaks migration compatibility.

The DRAM training in mainline u-boot is also significantly slower on real HW. I haven't spotted the exact area but the code is jumping back and forth. This patch should help tracking the culprit.

Thanks,

C.

#8 lore raw

PATCH v2 5/11 aspeed/smc: fix some alignment issues

In reply to Cédric Le Goater
---
 hw/ssi/aspeed_smc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/ssi/aspeed_smc.c +4 -4
index b29bfd3124a9..1270842dcf0c 100644
@@ -388,8 +388,8 @@ static uint64_t aspeed_smc_flash_default_read(void *opaque, hwaddr addr,
 static void aspeed_smc_flash_default_write(void *opaque, hwaddr addr,
                                            uint64_t data, unsigned size)
 {
-   qemu_log_mask(LOG_GUEST_ERROR, "%s: To 0x%" HWADDR_PRIx " of size %u: 0x%"
-                 PRIx64 "\n", __func__, addr, size, data);
+    qemu_log_mask(LOG_GUEST_ERROR, "%s: To 0x%" HWADDR_PRIx " of size %u: 0x%"
+                  PRIx64 "\n", __func__, addr, size, data);
 }
 
 static const MemoryRegionOps aspeed_smc_flash_default_ops = {
@@ -529,7 +529,7 @@ static void aspeed_smc_flash_setup(AspeedSMCFlash *fl, uint32_t addr)
      */
     if (aspeed_smc_flash_mode(fl) == CTRL_FREADMODE) {
         for (i = 0; i < aspeed_smc_flash_dummies(fl); i++) {
-                ssi_transfer(fl->controller->spi, 0xFF);
+            ssi_transfer(fl->controller->spi, 0xFF);
         }
     }
 }
@@ -567,7 +567,7 @@ static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)
 }
 
 static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
-                           unsigned size)
+                                   unsigned size)
 {
     AspeedSMCFlash *fl = opaque;
     AspeedSMCState *s = fl->controller;
Signature · 1 line
2.17.1
#9 lore raw

PATCH v2 6/11 aspeed/smc: fix default read value

In reply to Cédric Le Goater

0xFFFFFFFF should be returned for non implemented registers.

Also, the model should expose one control register per possible CS even if there is no flash device attached. When testing the validity of the register number in the read operation, replace 's->num_cs' by 'ctrl->max_slaves' which represents the maximum number of flash devices a controller can handle.

---
 hw/ssi/aspeed_smc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ssi/aspeed_smc.c +2 -2
index 1270842dcf0c..6045ca11b969 100644
@@ -665,12 +665,12 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
         addr == s->r_ce_ctrl ||
         addr == R_INTR_CTRL ||
         (addr >= R_SEG_ADDR0 && addr < R_SEG_ADDR0 + s->ctrl->max_slaves) ||
-        (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->num_cs)) {
+        (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->ctrl->max_slaves)) {
         return s->regs[addr];
     } else {
         qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
                       __func__, addr);
-        return 0;
+        return -1;
     }
 }
 
Signature · 1 line
2.17.1
#10 lore raw

Re: [Qemu-devel] [PATCH v2 06/11] aspeed/smc: fix default read value

Quoted 3 lines · Cédric Le Goater

0xFFFFFFFF should be returned for non implemented registers.

Also,

Use of "Also" in a commit message often indicates that it would be better to split the commit. The two changes here don't seem to me to have much to do with each other.

Quoted 16 lines

the model should expose one control register per possible CS even if there is no flash device attached. When testing the validity of the register number in the read operation, replace 's->num_cs' by 'ctrl->max_slaves' which represents the maximum number of flash devices a controller can handle.

---
 hw/ssi/aspeed_smc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ssi/aspeed_smc.c +0 -0
index 1270842dcf0c..6045ca11b969 100644

hw/ssi/aspeed_smc.c static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) · line 668

Quoted 5 lines
hw/ssi/aspeed_smc.c +1 -1
@@ -665,12 +665,12 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
         addr == s->r_ce_ctrl ||
         addr == R_INTR_CTRL ||
         (addr >= R_SEG_ADDR0 && addr < R_SEG_ADDR0 + s->ctrl->max_slaves) ||
-        (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->num_cs)) {
+        (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->ctrl->max_slaves)) {

The commit message mentions changing the upper bound on the address check here and also the unimplemented-register return value, but this change also seems to be changing the lower bound in the check ?

hw/ssi/aspeed_smc.c static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) · line 674

Quoted 7 lines
hw/ssi/aspeed_smc.c +1 -1
         return s->regs[addr];
     } else {
         qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
                       __func__, addr);
-        return 0;
+        return -1;
     }

thanks
-- PMM

#11 lore raw

Re: [Qemu-arm] [PATCH v2 06/11] aspeed/smc: fix default read value

Quoted 8 lines · Peter Maydell
Quoted 3 lines · Cédric Le Goater

0xFFFFFFFF should be returned for non implemented registers.

Also,

Use of "Also" in a commit message often indicates that it would be better to split the commit. The two changes here don't seem to me to have much to do with each other.

They do in the symptom which is to expose the correct register values. But I won't argue and next version will introduce two patches :)

Thanks,

C.

Quoted 38 lines
Quoted 16 lines

the model should expose one control register per possible CS even if there is no flash device attached. When testing the validity of the register number in the read operation, replace 's->num_cs' by 'ctrl->max_slaves' which represents the maximum number of flash devices a controller can handle.

---
 hw/ssi/aspeed_smc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ssi/aspeed_smc.c +0 -0
index 1270842dcf0c..6045ca11b969 100644

hw/ssi/aspeed_smc.c static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) · line 668

Quoted 5 lines
hw/ssi/aspeed_smc.c +1 -1
@@ -665,12 +665,12 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
         addr == s->r_ce_ctrl ||
         addr == R_INTR_CTRL ||
         (addr >= R_SEG_ADDR0 && addr < R_SEG_ADDR0 + s->ctrl->max_slaves) ||
-        (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->num_cs)) {
+        (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->ctrl->max_slaves)) {

The commit message mentions changing the upper bound on the address check here and also the unimplemented-register return value, but this change also seems to be changing the lower bound in the check ?

hw/ssi/aspeed_smc.c static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) · line 674

Quoted 7 lines
hw/ssi/aspeed_smc.c +1 -1
         return s->regs[addr];
     } else {
         qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
                       __func__, addr);
-        return 0;
+        return -1;
     }

thanks
-- PMM

#12 lore raw

PATCH v2 7/11 aspeed/smc: add a 'sdram_base' and 'max-ram-size' properties

In reply to Cédric Le Goater

The setting of the DRAM address of the DMA transaction depends on the DRAM base address and the maximum DRAM size of the SoC. Let's add a couple of properties to give this information to the SMC controller model.

Also, move the SDRAM Memory controller realization before the other controllers which need it.

---
 include/hw/ssi/aspeed_smc.h |  4 ++++
 hw/arm/aspeed_soc.c         | 28 +++++++++++++++++++---------
 hw/ssi/aspeed_smc.c         |  2 ++
 3 files changed, 25 insertions(+), 9 deletions(-)
include/hw/ssi/aspeed_smc.h +4 -0
index 1f557313fa93..d7090bb5e9b7 100644
@@ -97,6 +97,10 @@ typedef struct AspeedSMCState {
     uint8_t r_timings;
     uint8_t conf_enable_w0;
 
+    /* for DMA support */
+    uint64_t sdram_base;
+    uint64_t max_ram_size;
+
     AspeedSMCFlash *flashes;
 } AspeedSMCState;
 
hw/arm/aspeed_soc.c +19 -9
index 2cbacb4430bb..bbc05d172fe1 100644
@@ -209,6 +209,14 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
     }
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->scu), 0, ASPEED_SOC_SCU_BASE);
 
+    /* SDMC - SDRAM Memory Controller */
+    object_property_set_bool(OBJECT(&s->sdmc), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, ASPEED_SOC_SDMC_BASE);
+
     /* VIC */
     object_property_set_bool(OBJECT(&s->vic), true, "realized", &err);
     if (err) {
@@ -252,7 +260,17 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
                        qdev_get_gpio_in(DEVICE(&s->vic), 12));
 
     /* FMC, The number of CS is set at the board level */
-    object_property_set_bool(OBJECT(&s->fmc), true, "realized", &err);
+    object_property_set_int(OBJECT(&s->fmc), sc->info->sdram_base, "sdram-base",
+                            &err);
+    object_property_set_int(OBJECT(&s->fmc), s->sdmc.max_ram_size,
+                            "max-ram-size", &local_err);
+    error_propagate(&err, local_err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    object_property_set_bool(OBJECT(&s->fmc), true, "realized", &local_err);
+    error_propagate(&err, local_err);
     if (err) {
         error_propagate(errp, err);
         return;
@@ -278,14 +296,6 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
                         s->spi[i].ctrl->flash_window_base);
     }
 
-    /* SDMC - SDRAM Memory Controller */
-    object_property_set_bool(OBJECT(&s->sdmc), true, "realized", &err);
-    if (err) {
-        error_propagate(errp, err);
-        return;
-    }
-    sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, ASPEED_SOC_SDMC_BASE);
-
     /* Watch dog */
     for (i = 0; i < sc->info->wdts_num; i++) {
         object_property_set_bool(OBJECT(&s->wdt[i]), true, "realized", &err);
hw/ssi/aspeed_smc.c +2 -0
index 6045ca11b969..500de6d16d09 100644
@@ -800,6 +800,8 @@ static const VMStateDescription vmstate_aspeed_smc = {
 
 static Property aspeed_smc_properties[] = {
     DEFINE_PROP_UINT32("num-cs", AspeedSMCState, num_cs, 1),
+    DEFINE_PROP_UINT64("sdram-base", AspeedSMCState, sdram_base, 0),
+    DEFINE_PROP_UINT64("max-ram-size", AspeedSMCState, max_ram_size, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.17.1
#13 lore raw

Re: [Qemu-arm] [PATCH v2 07/11] aspeed/smc: add a 'sdram_base' and 'max-ram-size' properties

Quoted 7 lines · Cédric Le Goater

The setting of the DRAM address of the DMA transaction depends on the DRAM base address and the maximum DRAM size of the SoC. Let's add a couple of properties to give this information to the SMC controller model.

Also, move the SDRAM Memory controller realization before the other controllers which need it.

There's that "Also" again :-)

Quoted 48 lines
---
 include/hw/ssi/aspeed_smc.h |  4 ++++
 hw/arm/aspeed_soc.c         | 28 +++++++++++++++++++---------
 hw/ssi/aspeed_smc.c         |  2 ++
 3 files changed, 25 insertions(+), 9 deletions(-)
include/hw/ssi/aspeed_smc.h +4 -0
index 1f557313fa93..d7090bb5e9b7 100644
@@ -97,6 +97,10 @@ typedef struct AspeedSMCState {
     uint8_t r_timings;
     uint8_t conf_enable_w0;
 
+    /* for DMA support */
+    uint64_t sdram_base;
+    uint64_t max_ram_size;
+
     AspeedSMCFlash *flashes;
 } AspeedSMCState;
 
hw/arm/aspeed_soc.c +9 -1
index 2cbacb4430bb..bbc05d172fe1 100644
@@ -209,6 +209,14 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
     }
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->scu), 0, ASPEED_SOC_SCU_BASE);
 
+    /* SDMC - SDRAM Memory Controller */
+    object_property_set_bool(OBJECT(&s->sdmc), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, ASPEED_SOC_SDMC_BASE);
+
     /* VIC */
     object_property_set_bool(OBJECT(&s->vic), true, "realized", &err);
     if (err) {
@@ -252,7 +260,17 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
                        qdev_get_gpio_in(DEVICE(&s->vic), 12));
 
     /* FMC, The number of CS is set at the board level */
-    object_property_set_bool(OBJECT(&s->fmc), true, "realized", &err);
+    object_property_set_int(OBJECT(&s->fmc), sc->info->sdram_base, "sdram-base",

hw/arm/aspeed_soc.c static void aspeed_soc_realize(DeviceState *dev, Error **errp) · line 273

Quoted 10 lines
hw/arm/aspeed_soc.c +10 -0
+                            &err);
+    object_property_set_int(OBJECT(&s->fmc), s->sdmc.max_ram_size,
+                            "max-ram-size", &local_err);
+    error_propagate(&err, local_err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    object_property_set_bool(OBJECT(&s->fmc), true, "realized", &local_err);
+    error_propagate(&err, local_err);

I don't understand why we have several different variations on "do this thing, and if it fails then propagate the error to caller" here. I was expecting all these things to be in the form

       some_thing(..., &err);
       if (err) {
           error_propagate(errp, err);
           return;
       }

Is there a reason you need to involve the 'local_err' variable in some cases ?

Quoted 23 lines
hw/arm/aspeed_soc.c +0 -8
     if (err) {
         error_propagate(errp, err);
         return;
@@ -278,14 +296,6 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
                         s->spi[i].ctrl->flash_window_base);
     }
 
-    /* SDMC - SDRAM Memory Controller */
-    object_property_set_bool(OBJECT(&s->sdmc), true, "realized", &err);
-    if (err) {
-        error_propagate(errp, err);
-        return;
-    }
-    sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, ASPEED_SOC_SDMC_BASE);
-
     /* Watch dog */
     for (i = 0; i < sc->info->wdts_num; i++) {
         object_property_set_bool(OBJECT(&s->wdt[i]), true, "realized", &err);
hw/ssi/aspeed_smc.c +0 -0
index 6045ca11b969..500de6d16d09 100644

hw/ssi/aspeed_smc.c static const VMStateDescription vmstate_aspeed_smc = { · line 806

Quoted 7 lines
hw/ssi/aspeed_smc.c +2 -0
@@ -800,6 +800,8 @@ static const VMStateDescription vmstate_aspeed_smc = {
 
 static Property aspeed_smc_properties[] = {
     DEFINE_PROP_UINT32("num-cs", AspeedSMCState, num_cs, 1),
+    DEFINE_PROP_UINT64("sdram-base", AspeedSMCState, sdram_base, 0),
+    DEFINE_PROP_UINT64("max-ram-size", AspeedSMCState, max_ram_size, 0),
     DEFINE_PROP_END_OF_LIST(),
 };

thanks
-- PMM

#14 lore raw

Re: [Qemu-arm] [PATCH v2 07/11] aspeed/smc: add a 'sdram_base' and 'max-ram-size' properties

Quoted 10 lines · Peter Maydell
Quoted 7 lines · Cédric Le Goater

The setting of the DRAM address of the DMA transaction depends on the DRAM base address and the maximum DRAM size of the SoC. Let's add a couple of properties to give this information to the SMC controller model.

Also, move the SDRAM Memory controller realization before the other controllers which need it.

There's that "Also" again :-)

Arg. It seemed convenient at the time. OK OK, I will split :)

Quoted 62 lines
Quoted 47 lines
---
 include/hw/ssi/aspeed_smc.h |  4 ++++
 hw/arm/aspeed_soc.c         | 28 +++++++++++++++++++---------
 hw/ssi/aspeed_smc.c         |  2 ++
 3 files changed, 25 insertions(+), 9 deletions(-)
include/hw/ssi/aspeed_smc.h +4 -0
index 1f557313fa93..d7090bb5e9b7 100644
@@ -97,6 +97,10 @@ typedef struct AspeedSMCState {
     uint8_t r_timings;
     uint8_t conf_enable_w0;
 
+    /* for DMA support */
+    uint64_t sdram_base;
+    uint64_t max_ram_size;
+
     AspeedSMCFlash *flashes;
 } AspeedSMCState;
 
hw/arm/aspeed_soc.c +9 -1
index 2cbacb4430bb..bbc05d172fe1 100644
@@ -209,6 +209,14 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
     }
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->scu), 0, ASPEED_SOC_SCU_BASE);
 
+    /* SDMC - SDRAM Memory Controller */
+    object_property_set_bool(OBJECT(&s->sdmc), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, ASPEED_SOC_SDMC_BASE);
+
     /* VIC */
     object_property_set_bool(OBJECT(&s->vic), true, "realized", &err);
     if (err) {
@@ -252,7 +260,17 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
                        qdev_get_gpio_in(DEVICE(&s->vic), 12));
 
     /* FMC, The number of CS is set at the board level */
-    object_property_set_bool(OBJECT(&s->fmc), true, "realized", &err);
+    object_property_set_int(OBJECT(&s->fmc), sc->info->sdram_base, "sdram-base",

hw/arm/aspeed_soc.c static void aspeed_soc_realize(DeviceState *dev, Error **errp) · line 273

Quoted 10 lines
hw/arm/aspeed_soc.c +10 -0
+                            &err);
+    object_property_set_int(OBJECT(&s->fmc), s->sdmc.max_ram_size,
+                            "max-ram-size", &local_err);
+    error_propagate(&err, local_err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    object_property_set_bool(OBJECT(&s->fmc), true, "realized", &local_err);
+    error_propagate(&err, local_err);

I don't understand why we have several different variations on "do this thing, and if it fails then propagate the error to caller" here. I was expecting all these things to be in the form

Quoted 8 lines
       some_thing(..., &err);
       if (err) {
           error_propagate(errp, err);
           return;
       }

Is there a reason you need to involve the 'local_err' variable in some cases ?

I tried to reuse the accumulation pattern :

      Error *err = NULL, *local_err = NULL;
      foo(arg, &err);
      bar(arg, &local_err);
      error_propagate(&err, local_err);
      if (err) {
          handle the error...
      }

but I am doing it wrong. Another reason to split the patch.

Thanks,

C.

Quoted 34 lines
Quoted 23 lines
hw/arm/aspeed_soc.c +0 -8
     if (err) {
         error_propagate(errp, err);
         return;
@@ -278,14 +296,6 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
                         s->spi[i].ctrl->flash_window_base);
     }
 
-    /* SDMC - SDRAM Memory Controller */
-    object_property_set_bool(OBJECT(&s->sdmc), true, "realized", &err);
-    if (err) {
-        error_propagate(errp, err);
-        return;
-    }
-    sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, ASPEED_SOC_SDMC_BASE);
-
     /* Watch dog */
     for (i = 0; i < sc->info->wdts_num; i++) {
         object_property_set_bool(OBJECT(&s->wdt[i]), true, "realized", &err);
hw/ssi/aspeed_smc.c +0 -0
index 6045ca11b969..500de6d16d09 100644

hw/ssi/aspeed_smc.c static const VMStateDescription vmstate_aspeed_smc = { · line 806

Quoted 7 lines
hw/ssi/aspeed_smc.c +2 -0
@@ -800,6 +800,8 @@ static const VMStateDescription vmstate_aspeed_smc = {
 
 static Property aspeed_smc_properties[] = {
     DEFINE_PROP_UINT32("num-cs", AspeedSMCState, num_cs, 1),
+    DEFINE_PROP_UINT64("sdram-base", AspeedSMCState, sdram_base, 0),
+    DEFINE_PROP_UINT64("max-ram-size", AspeedSMCState, max_ram_size, 0),
     DEFINE_PROP_END_OF_LIST(),
 };

thanks
-- PMM

#15 lore raw

PATCH v2 8/11 aspeed/smc: add support for DMAs

In reply to Cédric Le Goater

The FMC controller on the Aspeed SoCs support DMA to access the flash modules. It can operate in a normal mode, to copy to or from the flash module mapping window, or in a checksum calculation mode, to evaluate the best clock settings for reads.

The model introduces a custom address space for DMAs populated with the required regions : an alias region on the AHB window for the flash devices and another alias on the SDRAM.

Our primary need is to support the checksum calculation mode and the model only implements synchronous DMA accesses. Something to improve in the future.

---
 include/hw/ssi/aspeed_smc.h |   2 +
 hw/ssi/aspeed_smc.c         | 227 +++++++++++++++++++++++++++++++++++-
 2 files changed, 223 insertions(+), 6 deletions(-)
include/hw/ssi/aspeed_smc.h +2 -0
index d7090bb5e9b7..b8b2dfbec280 100644
@@ -100,6 +100,8 @@ typedef struct AspeedSMCState {
     /* for DMA support */
     uint64_t sdram_base;
     uint64_t max_ram_size;
+    MemoryRegion dma_mr;
+    AddressSpace dma_as;
 
     AspeedSMCFlash *flashes;
 } AspeedSMCState;
hw/ssi/aspeed_smc.c +221 -6

294 lines not on this page · raw message

Signature · 1 line
2.17.1
#16 lore raw

Re: [Qemu-arm] [PATCH v2 08/11] aspeed/smc: add support for DMAs

Quoted 21 lines · Cédric Le Goater

The FMC controller on the Aspeed SoCs support DMA to access the flash modules. It can operate in a normal mode, to copy to or from the flash module mapping window, or in a checksum calculation mode, to evaluate the best clock settings for reads.

The model introduces a custom address space for DMAs populated with the required regions : an alias region on the AHB window for the flash devices and another alias on the SDRAM.

Our primary need is to support the checksum calculation mode and the model only implements synchronous DMA accesses. Something to improve in the future.

hw/ssi/aspeed_smc.c +5 -0
+static void aspeed_smc_dma_rw(AspeedSMCState *s)
+{
+    MemTxResult result;
+    uint32_t data;
+

hw/ssi/aspeed_smc.c static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) · line 745

Quoted 10 lines
hw/ssi/aspeed_smc.c +10 -0
+    while (s->regs[R_DMA_LEN]) {
+        if (s->regs[R_DMA_CTRL] & DMA_CTRL_WRITE) {
+            result = address_space_read(&s->dma_as, s->regs[R_DMA_DRAM_ADDR],
+                                        MEMTXATTRS_UNSPECIFIED,
+                                        (uint8_t *)&data, 4);
+            if (result != MEMTX_OK) {
+                qemu_log_mask(LOG_GUEST_ERROR, "%s: DRAM read failed @%08x\n",
+                              __func__, s->regs[R_DMA_DRAM_ADDR]);
+                return;
+            }

Does the device really not report DMA read/write failures via a status register bit or similar ?

hw/ssi/aspeed_smc.c static const MemoryRegionOps aspeed_smc_ops = { · line 906

Quoted 13 lines
hw/ssi/aspeed_smc.c +13 -0
+
+/*
+ * Populate our custom address space for DMAs with only the regions we
+ * need : the AHB window for the flash devices and the SDRAM.
+ */
+static void aspeed_smc_dma_setup(AspeedSMCState *s)
+{
+    char name[32];
+    MemoryRegion *sysmem = get_system_memory();
+    MemoryRegion *flash_alias = g_new(MemoryRegion, 1);
+    MemoryRegion *sdram_alias = g_new(MemoryRegion, 1);
+
+    snprintf(name, sizeof(name), "%s-dma", s->ctrl->name);

I would suggest using g_strdup_printf()/g_free(), since it's not immediately obvious here that s->ctrl->name is guaranteed to fit into the fixed-size array.

hw/ssi/aspeed_smc.c static const MemoryRegionOps aspeed_smc_ops = { · line 919

Quoted 13 lines
hw/ssi/aspeed_smc.c +13 -0
+    memory_region_init(&s->dma_mr, OBJECT(s), name,
+                       s->sdram_base + s->max_ram_size);
+    address_space_init(&s->dma_as, &s->dma_mr, name);
+
+    snprintf(name, sizeof(name), "%s.flash", s->ctrl->name);
+    memory_region_init_alias(flash_alias, OBJECT(s), name, &s->mmio_flash,
+                             0, s->ctrl->flash_window_size);
+    memory_region_add_subregion(&s->dma_mr, s->ctrl->flash_window_base,
+                                flash_alias);
+
+    memory_region_init_alias(sdram_alias, OBJECT(s), "ram", sysmem,
+                             s->sdram_base, s->max_ram_size);
+    memory_region_add_subregion(&s->dma_mr, s->sdram_base, sdram_alias);

Rather than having the DMA device directly grab the system_memory MR like this, it's better to have the device have a MemoryRegion property, which the SoC sets with whatever the DMA device should be able to see.

Otherwise, patch looks good, though I don't know enough about the device/SoC to review those details.

thanks
-- PMM

#17 lore raw

Re: [Qemu-arm] [PATCH v2 08/11] aspeed/smc: add support for DMAs

Quoted 27 lines · Peter Maydell
Quoted 26 lines · Cédric Le Goater

The FMC controller on the Aspeed SoCs support DMA to access the flash modules. It can operate in a normal mode, to copy to or from the flash module mapping window, or in a checksum calculation mode, to evaluate the best clock settings for reads.

The model introduces a custom address space for DMAs populated with the required regions : an alias region on the AHB window for the flash devices and another alias on the SDRAM.

Our primary need is to support the checksum calculation mode and the model only implements synchronous DMA accesses. Something to improve in the future.

hw/ssi/aspeed_smc.c +10 -0
+static void aspeed_smc_dma_rw(AspeedSMCState *s)
+{
+    MemTxResult result;
+    uint32_t data;
+
+    while (s->regs[R_DMA_LEN]) {
+        if (s->regs[R_DMA_CTRL] & DMA_CTRL_WRITE) {
+            result = address_space_read(&s->dma_as, s->regs[R_DMA_DRAM_ADDR],
+                                        MEMTXATTRS_UNSPECIFIED,
+                                        (uint8_t *)&data, 4);
Quoted 8 lines

hw/ssi/aspeed_smc.c static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) · line 745

Quoted 5 lines
hw/ssi/aspeed_smc.c +5 -0
+            if (result != MEMTX_OK) {
+                qemu_log_mask(LOG_GUEST_ERROR, "%s: DRAM read failed @%08x\n",
+                              __func__, s->regs[R_DMA_DRAM_ADDR]);
+                return;
+            }

Does the device really not report DMA read/write failures via a status register bit or similar ?

The Interrupt Control and Status Register (FM0C8) has a DMA Status BIT(11) to indicate that a DMA transfer is in progress or not. Nothing for errors.

There are a SPI command abort status BIT(10) and a SPI Write Address Protected status BIT(11) but these are for the command and address filters.

Quoted 9 lines
Quoted 9 lines
hw/ssi/aspeed_smc.c +9 -0
+
+/*
+ * Populate our custom address space for DMAs with only the regions we
+ * need : the AHB window for the flash devices and the SDRAM.
+ */
+static void aspeed_smc_dma_setup(AspeedSMCState *s)
+{
+    char name[32];
+    MemoryRegion *sysmem = get_system_memory();
Quoted 8 lines

hw/ssi/aspeed_smc.c static const MemoryRegionOps aspeed_smc_ops = { · line 906

Quoted 4 lines
hw/ssi/aspeed_smc.c +4 -0
+    MemoryRegion *flash_alias = g_new(MemoryRegion, 1);
+    MemoryRegion *sdram_alias = g_new(MemoryRegion, 1);
+
+    snprintf(name, sizeof(name), "%s-dma", s->ctrl->name);

I would suggest using g_strdup_printf()/g_free(), since it's not immediately obvious here that s->ctrl->name is guaranteed to fit into the fixed-size array.

yes. sure.

Quoted 10 lines
Quoted 10 lines
hw/ssi/aspeed_smc.c +10 -0
+    memory_region_init(&s->dma_mr, OBJECT(s), name,
+                       s->sdram_base + s->max_ram_size);
+    address_space_init(&s->dma_as, &s->dma_mr, name);
+
+    snprintf(name, sizeof(name), "%s.flash", s->ctrl->name);
+    memory_region_init_alias(flash_alias, OBJECT(s), name, &s->mmio_flash,
+                             0, s->ctrl->flash_window_size);
+    memory_region_add_subregion(&s->dma_mr, s->ctrl->flash_window_base,
+                                flash_alias);
+
Quoted 8 lines

hw/ssi/aspeed_smc.c static const MemoryRegionOps aspeed_smc_ops = { · line 919

Quoted 3 lines
hw/ssi/aspeed_smc.c +3 -0
+    memory_region_init_alias(sdram_alias, OBJECT(s), "ram", sysmem,
+                             s->sdram_base, s->max_ram_size);
+    memory_region_add_subregion(&s->dma_mr, s->sdram_base, sdram_alias);

Rather than having the DMA device directly grab the system_memory MR like this, it's better to have the device have a MemoryRegion property, which the SoC sets with whatever the DMA device should be able to see.

ok. I see, but it seems I have a chicken & egg problem.

The MemoryRegion I would liked to grab is the bmc->ram one in aspeed.c but it is initialized after the SoC is. I don't know how to lazy bind this region in the Aspeed SMC model using the Aspeed SoC model as a proxy to pass the region property through a link or/and alias.

If I could find a way, the model would be much cleaner.

Quoted 2 lines

Otherwise, patch looks good, though I don't know enough about the device/SoC to review those details.

For the moment the only use of these registers is in the Aspeed custom u-boot of the SDK :

or in the rewrite I proposed in mainline :

Thanks,

C.

#18 lore raw

Re: [Qemu-arm] [PATCH v2 08/11] aspeed/smc: add support for DMAs

With the links,

[ ... ]

Quoted 5 lines
Quoted 2 lines

Otherwise, patch looks good, though I don't know enough about the device/SoC to review those details.

For the moment the only use of these registers is in the Aspeed custom u-boot of the SDK :

https://github.com/openbmc/u-boot/blob/v2016.07-aspeed-openbmc/arch/arm/mach-aspeed/platform_g5.S#L2314

Quoted 1 line

or in the rewrite I proposed in mainline :

http://patchwork.ozlabs.org/patch/972868/

C.

#19 lore raw

Re: [Qemu-arm] [PATCH v2 08/11] aspeed/smc: add support for DMAs

In reply to Cédric Le Goater
Quoted 6 lines · Cédric Le Goater
Quoted 4 lines · Peter Maydell

Rather than having the DMA device directly grab the system_memory MR like this, it's better to have the device have a MemoryRegion property, which the SoC sets with whatever the DMA device should be able to see.

Quoted 8 lines

ok. I see, but it seems I have a chicken & egg problem.

The MemoryRegion I would liked to grab is the bmc->ram one in aspeed.c but it is initialized after the SoC is. I don't know how to lazy bind this region in the Aspeed SMC model using the Aspeed SoC model as a proxy to pass the region property through a link or/and alias.

If I could find a way, the model would be much cleaner.

Usually what you want to pass is not the RAM region directly but some container object (which contains the RAM region among other things). This is often a container that you're passing to the SoC anyway so it can put its devices in it.

(The direct answer to your chicken-and-egg problem is that you can create a container before creating the SoC, pass that to the SoC, then create the RAM afterwards and put it in the container after. But that feels a bit like a workaround for a less than ideal structure, somehow.)

thanks
-- PMM

#20 lore raw

Re: [Qemu-arm] [PATCH v2 08/11] aspeed/smc: add support for DMAs

Quoted 21 lines · Peter Maydell
Quoted 6 lines · Cédric Le Goater
Quoted 4 lines · Peter Maydell

Rather than having the DMA device directly grab the system_memory MR like this, it's better to have the device have a MemoryRegion property, which the SoC sets with whatever the DMA device should be able to see.

Quoted 8 lines

ok. I see, but it seems I have a chicken & egg problem.

The MemoryRegion I would liked to grab is the bmc->ram one in aspeed.c but it is initialized after the SoC is. I don't know how to lazy bind this region in the Aspeed SMC model using the Aspeed SoC model as a proxy to pass the region property through a link or/and alias.

If I could find a way, the model would be much cleaner.

Usually what you want to pass is not the RAM region directly but some container object (which contains the RAM region among other things). This is often a container that you're passing to the SoC anyway so it can put its devices in it.

Quoted 5 lines

(The direct answer to your chicken-and-egg problem is that you can create a container before creating the SoC, pass that to the SoC, then create the RAM afterwards and put it in the container after. But that feels a bit like a workaround for a less than ideal structure, somehow.)

couldn't we just initialize the RAM under the SoC ? We don't need it at the machine level AFAICT, nor does the raspi model I think.

What is the rational behind putting the RAM region in a state structure at the machine level ?

Thanks,

C.

#21 lore raw

PATCH v2 9/11 aspeed/smc: add DMA calibration settings

In reply to Cédric Le Goater

When doing calibration, the SPI clock rate in the CE0 Control Register and the read delay cycles in the Read Timing Compensation Register are set using bit[11:4] of the DMA Control Register.

---
 hw/ssi/aspeed_smc.c | 64 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)
hw/ssi/aspeed_smc.c +63 -1
index 625c29ba4ad2..db89c54dfc9f 100644
@@ -74,6 +74,10 @@
 #define   CTRL_CMD_MASK            0xff
 #define   CTRL_DUMMY_HIGH_SHIFT    14
 #define   CTRL_AST2400_SPI_4BYTE   (1 << 13)
+#define CE_CTRL_CLOCK_FREQ_SHIFT   8
+#define CE_CTRL_CLOCK_FREQ_MASK    0xf
+#define CE_CTRL_CLOCK_FREQ(div)                                         \
+    (((div) & CE_CTRL_CLOCK_FREQ_MASK) << CE_CTRL_CLOCK_FREQ_SHIFT)
 #define   CTRL_DUMMY_LOW_SHIFT     6 /* 2 bits [7:6] */
 #define   CTRL_CE_STOP_ACTIVE      (1 << 2)
 #define   CTRL_CMD_MODE_MASK       0x3
@@ -109,7 +113,7 @@
 #define   DMA_CTRL_DELAY_SHIFT  8
 #define   DMA_CTRL_FREQ_MASK    0xf
 #define   DMA_CTRL_FREQ_SHIFT   4
-#define   DMA_CTRL_MODE         (1 << 3)
+#define   DMA_CTRL_CALIB        (1 << 3)
 #define   DMA_CTRL_CKSUM        (1 << 2)
 #define   DMA_CTRL_WRITE        (1 << 1)
 #define   DMA_CTRL_ENABLE       (1 << 0)
@@ -693,6 +697,60 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
     }
 }
 
+static uint8_t aspeed_smc_hclk_divisor(uint8_t hclk_mask)
+{
+    /* HCLK/1 .. HCLK/16 */
+    const uint8_t hclk_divisors[] = {
+        15, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 0
+    };
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(hclk_divisors); i++) {
+        if (hclk_mask == hclk_divisors[i]) {
+            return i + 1;
+        }
+    }
+
+    qemu_log_mask(LOG_GUEST_ERROR, "invalid HCLK mask %x", hclk_mask);
+    return 0;
+}
+
+/*
+ * When doing calibration, the SPI clock rate in the CE0 Control
+ * Register and the read delay cycles in the Read Timing Compensation
+ * Register are set using bit[11:4] of the DMA Control Register.
+ */
+static void aspeed_smc_dma_calibration(AspeedSMCState *s)
+{
+    uint8_t delay =
+        (s->regs[R_DMA_CTRL] >> DMA_CTRL_DELAY_SHIFT) & DMA_CTRL_DELAY_MASK;
+    uint8_t hclk_mask =
+        (s->regs[R_DMA_CTRL] >> DMA_CTRL_FREQ_SHIFT) & DMA_CTRL_FREQ_MASK;
+    uint8_t hclk_div = aspeed_smc_hclk_divisor(hclk_mask);
+    uint32_t hclk_shift = (hclk_div - 1) << 2;
+    uint8_t cs;
+
+    /*
+     * The Read Timing Compensation Register values apply to all CS on
+     * the SPI bus and only HCLK/1 - HCLK/5 can have tunable delays
+     */
+    if (hclk_div && hclk_div < 6) {
+        s->regs[s->r_timings] &= ~(0xf << hclk_shift);
+        s->regs[s->r_timings] |= delay << hclk_shift;
+    }
+
+    /*
+     * TODO: compute the CS from the DMA address and the segment
+     * registers. This is not really a problem for now because the
+     * Timing Register values apply to all CS and software uses CS0 to
+     * do calibration.
+     */
+    cs = 0;
+    s->regs[s->r_ctrl0 + cs] &=
+        ~(CE_CTRL_CLOCK_FREQ_MASK << CE_CTRL_CLOCK_FREQ_SHIFT);
+    s->regs[s->r_ctrl0 + cs] |= CE_CTRL_CLOCK_FREQ(hclk_div);
+}
+
 /*
  * Accumulate the result of the reads to provide a checksum that will
  * be used to validate the read timing settings.
@@ -708,6 +766,10 @@ static void aspeed_smc_dma_checksum(AspeedSMCState *s)
         return;
     }
 
+    if (s->regs[R_DMA_CTRL] & DMA_CTRL_CALIB) {
+        aspeed_smc_dma_calibration(s);
+    }
+
     while (s->regs[R_DMA_LEN]) {
         result = address_space_read(&s->dma_as, s->regs[R_DMA_FLASH_ADDR],
                                     MEMTXATTRS_UNSPECIFIED,
Signature · 1 line
2.17.1
#22 lore raw

PATCH v2 10/11 aspeed/smc: inject errors in DMA checksum

In reply to Cédric Le Goater

Emulate read errors in the DMA Checksum Register for high frequencies and optimistic settings of the Read Timing Compensation Register. This will help in tuning the SPI timing calibration algorithm.

The values below are those to expect from the first flash device of the FMC controller of a palmetto-bmc machine.

---
 hw/ssi/aspeed_smc.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
hw/ssi/aspeed_smc.c +29 -0
index db89c54dfc9f..01c3fd7b2666 100644
@@ -751,6 +751,30 @@ static void aspeed_smc_dma_calibration(AspeedSMCState *s)
     s->regs[s->r_ctrl0 + cs] |= CE_CTRL_CLOCK_FREQ(hclk_div);
 }
 
+static bool aspeed_smc_inject_read_failure(AspeedSMCState *s)
+{
+    uint8_t delay =
+        (s->regs[R_DMA_CTRL] >> DMA_CTRL_DELAY_SHIFT) & DMA_CTRL_DELAY_MASK;
+    uint8_t hclk_mask =
+        (s->regs[R_DMA_CTRL] >> DMA_CTRL_FREQ_SHIFT) & DMA_CTRL_FREQ_MASK;
+
+    /*
+     * Typical values of a palmetto-bmc machine.
+     */
+    switch (aspeed_smc_hclk_divisor(hclk_mask)) {
+    case 4 ... 16:
+        return false;
+    case 3: /* at least one HCLK cycle delay */
+        return (delay & 0x7) < 1;
+    case 2: /* at least two HCLK cycle delay */
+        return (delay & 0x7) < 2;
+    case 1: /* (> 100MHz) is above the max freq of the controller */
+        return true;
+    default:
+        g_assert_not_reached();
+    }
+}
+
 /*
  * Accumulate the result of the reads to provide a checksum that will
  * be used to validate the read timing settings.
@@ -788,6 +812,11 @@ static void aspeed_smc_dma_checksum(AspeedSMCState *s)
         s->regs[R_DMA_FLASH_ADDR] += 4;
         s->regs[R_DMA_LEN] -= 4;
     }
+
+    if (aspeed_smc_inject_read_failure(s)) {
+        s->regs[R_DMA_CHECKSUM] = 0xbadc0de;
+    }
+
 }
 
 static void aspeed_smc_dma_rw(AspeedSMCState *s)
Signature · 1 line
2.17.1
#23 lore raw

PATCH v2 11/11 aspeed/smc: Add dummy data register

In reply to Cédric Le Goater

The SMC controllers have a register containing the byte that will be used as dummy output. It can be modified by software.

---
 hw/ssi/aspeed_smc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/ssi/aspeed_smc.c +6 -3
index 01c3fd7b2666..55ceffe100d3 100644
@@ -104,8 +104,8 @@
 /* Misc Control Register #1 */
 #define R_MISC_CTRL1      (0x50 / 4)
 
-/* Misc Control Register #2 */
-#define R_MISC_CTRL2      (0x54 / 4)
+/* SPI dummy cycle data */
+#define R_DUMMY_DATA      (0x54 / 4)
 
 /* DMA Control/Status Register */
 #define R_DMA_CTRL        (0x80 / 4)
@@ -550,7 +550,7 @@ static void aspeed_smc_flash_setup(AspeedSMCFlash *fl, uint32_t addr)
      */
     if (aspeed_smc_flash_mode(fl) == CTRL_FREADMODE) {
         for (i = 0; i < aspeed_smc_flash_dummies(fl); i++) {
-            ssi_transfer(fl->controller->spi, 0xFF);
+            ssi_transfer(fl->controller->spi, s->regs[R_DUMMY_DATA] & 0xff);
         }
     }
 }
@@ -682,6 +682,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
         addr == s->r_timings ||
         addr == s->r_ce_ctrl ||
         addr == R_INTR_CTRL ||
+        addr == R_DUMMY_DATA ||
         (s->ctrl->has_dma && addr == R_DMA_CTRL) ||
         (s->ctrl->has_dma && addr == R_DMA_FLASH_ADDR) ||
         (s->ctrl->has_dma && addr == R_DMA_DRAM_ADDR) ||
@@ -957,6 +958,8 @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
         }
     } else if (addr == R_INTR_CTRL) {
         s->regs[addr] = value;
+    } else if (addr == R_DUMMY_DATA) {
+        s->regs[addr] = value & 0xff ;
     } else if (s->ctrl->has_dma && addr == R_DMA_CTRL) {
         aspeed_smc_dma_ctrl(s, value);
     } else if (s->ctrl->has_dma && addr == R_DMA_DRAM_ADDR) {
Signature · 1 line
2.17.1
#24 lore raw
In reply to Cédric Le Goater
Quoted 5 lines · Cédric Le Goater

Hello,

This series adds a couple of cleanups and two main features to the SMC controller of the Aspeed machines :

Quoted 8 lines

- a 'execute-in-place' property to boot directly from a memory region alias of the FMC flash module using MMIO execution. This is not activated by default because boot time needs to be improved on recent firmwares. It also breaks migration compatibility.

- support for DMA to access the flash modules. Our primary need is the checksum calculation which is used to evaluate the best clock settings for reads.

I've picked out the easy parts of this series and added them to target-arm.next:

Quoted 4 lines

aspeed/timer: fix compile breakage with clang 3.4.2 hw/arm/aspeed: change the FMC flash model of the AST2500 evb hw/arm/aspeed: Add an Aspeed machine class aspeed/smc: fix some alignment issues

and left the rest for the moment (I've still got this series on my to-review list).

In particular I wanted to get the compile fix into the pullreq I'm doing today.

thanks
-- PMM

#25 lore raw
Quoted 18 lines · Peter Maydell
Quoted 5 lines · Cédric Le Goater

Hello,

This series adds a couple of cleanups and two main features to the SMC controller of the Aspeed machines :

Quoted 8 lines

- a 'execute-in-place' property to boot directly from a memory region alias of the FMC flash module using MMIO execution. This is not activated by default because boot time needs to be improved on recent firmwares. It also breaks migration compatibility.

- support for DMA to access the flash modules. Our primary need is the checksum calculation which is used to evaluate the best clock settings for reads.

I've picked out the easy parts of this series and added them to target-arm.next:

Quoted 7 lines
Quoted 4 lines

aspeed/timer: fix compile breakage with clang 3.4.2 hw/arm/aspeed: change the FMC flash model of the AST2500 evb hw/arm/aspeed: Add an Aspeed machine class aspeed/smc: fix some alignment issues

and left the rest for the moment (I've still got this series on my to-review list).

PS: review from people familiar with the SoC would also be helpful.

thanks
-- PMM

#26 lore raw
Quoted 24 lines · Peter Maydell
Quoted 23 lines · Peter Maydell
Quoted 5 lines · Cédric Le Goater

Hello,

This series adds a couple of cleanups and two main features to the SMC controller of the Aspeed machines :

Quoted 8 lines

- a 'execute-in-place' property to boot directly from a memory region alias of the FMC flash module using MMIO execution. This is not activated by default because boot time needs to be improved on recent firmwares. It also breaks migration compatibility.

- support for DMA to access the flash modules. Our primary need is the checksum calculation which is used to evaluate the best clock settings for reads.

I've picked out the easy parts of this series and added them to target-arm.next:

Quoted 4 lines

aspeed/timer: fix compile breakage with clang 3.4.2 hw/arm/aspeed: change the FMC flash model of the AST2500 evb hw/arm/aspeed: Add an Aspeed machine class aspeed/smc: fix some alignment issues

Quoted 4 lines
Quoted 2 lines

and left the rest for the moment (I've still got this series on my to-review list).

PS: review from people familiar with the SoC would also be helpful.

Joel has reviewed the u-boot patches. May be, he can chime in ?

Thanks,

C.

#27 lore raw
In reply to Peter Maydell
Quoted 18 lines · Peter Maydell
Quoted 5 lines · Cédric Le Goater

Hello,

This series adds a couple of cleanups and two main features to the SMC controller of the Aspeed machines :

Quoted 8 lines

- a 'execute-in-place' property to boot directly from a memory region alias of the FMC flash module using MMIO execution. This is not activated by default because boot time needs to be improved on recent firmwares. It also breaks migration compatibility.

- support for DMA to access the flash modules. Our primary need is the checksum calculation which is used to evaluate the best clock settings for reads.

I've picked out the easy parts of this series and added them to target-arm.next:

Quoted 7 lines
Quoted 4 lines

aspeed/timer: fix compile breakage with clang 3.4.2 hw/arm/aspeed: change the FMC flash model of the AST2500 evb hw/arm/aspeed: Add an Aspeed machine class aspeed/smc: fix some alignment issues

and left the rest for the moment (I've still got this series on my to-review list).

I will wait for your comments on the DMA part before resending.

Thanks,

C.

#28 lore raw
Quoted 24 lines · Cédric Le Goater
Quoted 23 lines · Peter Maydell
Quoted 5 lines · Cédric Le Goater

Hello,

This series adds a couple of cleanups and two main features to the SMC controller of the Aspeed machines :

Quoted 8 lines

- a 'execute-in-place' property to boot directly from a memory region alias of the FMC flash module using MMIO execution. This is not activated by default because boot time needs to be improved on recent firmwares. It also breaks migration compatibility.

- support for DMA to access the flash modules. Our primary need is the checksum calculation which is used to evaluate the best clock settings for reads.

I've picked out the easy parts of this series and added them to target-arm.next:

Quoted 4 lines

aspeed/timer: fix compile breakage with clang 3.4.2 hw/arm/aspeed: change the FMC flash model of the AST2500 evb hw/arm/aspeed: Add an Aspeed machine class aspeed/smc: fix some alignment issues

Quoted 4 lines
Quoted 2 lines

and left the rest for the moment (I've still got this series on my to-review list).

I will wait for your comments on the DMA part before resending.

I've now commented on that patch. I think I'm done with review on this version, unless there's something specific you want more input on ?

thanks
-- PMM

#29 lore raw
Quoted 25 lines · Peter Maydell
Quoted 24 lines · Cédric Le Goater
Quoted 23 lines · Peter Maydell
Quoted 5 lines · Cédric Le Goater

Hello,

This series adds a couple of cleanups and two main features to the SMC controller of the Aspeed machines :

Quoted 8 lines

- a 'execute-in-place' property to boot directly from a memory region alias of the FMC flash module using MMIO execution. This is not activated by default because boot time needs to be improved on recent firmwares. It also breaks migration compatibility.

- support for DMA to access the flash modules. Our primary need is the checksum calculation which is used to evaluate the best clock settings for reads.

I've picked out the easy parts of this series and added them to target-arm.next:

Quoted 4 lines

aspeed/timer: fix compile breakage with clang 3.4.2 hw/arm/aspeed: change the FMC flash model of the AST2500 evb hw/arm/aspeed: Add an Aspeed machine class aspeed/smc: fix some alignment issues

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

and left the rest for the moment (I've still got this series on my to-review list).

I will wait for your comments on the DMA part before resending.

I've now commented on that patch. I think I'm done with review on this version, unless there's something specific you want more input on ?

No, a part from the chicken & egg problem on the RAM memory region may be if you have some idea. I will dig in before re-sending anyhow.

Thanks,

C.