Skip to contentSkip to conversation

generic/starfive: Enable Starfive JH7110 platform preferred cold boot HART implementation

PATCH Superseded Wei Liang Lim 6 participants 14 messages Dec 20, 2022 – Dec 21, 2022

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover generic/starfive: Enable Starfive JH7110 platform preferred cold boot HART implementation

This is patchset to enable Starfive JH7110 platform preferred cold boot HART implementation.
User has the option to specify preferred cold boot HART in the device tree. If unspecified, the existing lottery mechanism will be used.

Anup Patel (2):
lib: sbi: Allow platform to influence cold boot HART selection
platform: generic: Allow platform_override to select cold boot HART

Wei Liang Lim (1):
generic/starfive: Add Starfive JH7110 platform implementation

 include/sbi/sbi_platform.h                   | 20 +++++++
 lib/sbi/sbi_init.c                           |  7 ++-
 platform/generic/Kconfig                     |  4 ++
 platform/generic/configs/defconfig           |  1 +
 platform/generic/include/platform_override.h |  1 +
 platform/generic/platform.c                  |  9 ++++
 platform/generic/starfive/jh7110.c           | 57 ++++++++++++++++++++
 platform/generic/starfive/objects.mk         |  6 +++
 8 files changed, 103 insertions(+), 2 deletions(-)
 create mode 100644 platform/generic/starfive/jh7110.c
 create mode 100644 platform/generic/starfive/objects.mk
Signature · 1 line
2.25.1
#1 lore raw

PATCH v4 1/3 lib: sbi: Allow platform to influence cold boot HART selection

From: Anup Patel <[email protected]>

We add an optional cold_boot_allowed() platform callback which allows platform support to decide which HARTs can do cold boot initialization.

If this platform callback is not available then any HART can do cold boot initialization.

---
 include/sbi/sbi_platform.h | 20 ++++++++++++++++++++
 lib/sbi/sbi_init.c         |  7 +++++--
 2 files changed, 25 insertions(+), 2 deletions(-)
include/sbi/sbi_platform.h +20 -0
index 722f27a..566eee3 100644
@@ -65,6 +65,9 @@ enum sbi_platform_features {
 
 /** Platform functions */
 struct sbi_platform_operations {
+	/* Check if specified HART is allowed to do cold boot */
+	bool (*cold_boot_allowed)(u32 hartid);
+
 	/* Platform nascent initialization */
 	int (*nascent_init)(void);
 
@@ -356,6 +359,23 @@ static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat,
 	return FALSE;
 }
 
+/**
+ * Check whether given HART is allowed to do cold boot
+ *
+ * @param plat pointer to struct sbi_platform
+ * @param hartid HART ID
+ *
+ * @return TRUE if HART is allowed to do cold boot and FALSE otherwise
+ */
+static inline bool sbi_platform_cold_boot_allowed(
+					const struct sbi_platform *plat,
+					u32 hartid)
+{
+	if (plat && sbi_platform_ops(plat)->cold_boot_allowed)
+		return sbi_platform_ops(plat)->cold_boot_allowed(hartid);
+	return TRUE;
+}
+
 /**
  * Nascent (very early) initialization for current HART
  *
lib/sbi/sbi_init.c +5 -2
index a8500e5..d4902d9 100644
@@ -498,8 +498,11 @@ void __noreturn sbi_init(struct sbi_scratch *scratch)
 	 * HARTs which satisfy above condition.
 	 */
 
-	if (next_mode_supported && atomic_xchg(&coldboot_lottery, 1) == 0)
-		coldboot = TRUE;
+	if (sbi_platform_cold_boot_allowed(plat, hartid)) {
+		if (next_mode_supported &&
+		    atomic_xchg(&coldboot_lottery, 1) == 0)
+			coldboot = TRUE;
+	}
 
 	/*
 	 * Do platform specific nascent (very early) initialization so
Signature · 1 line
2.25.1
#2 lore raw

PATCH v4 1/3 lib: sbi: Allow platform to influence cold boot HART selection

? 2022-12-20???? 11:41 +0800?Wei Liang Lim???

Quoted 9 lines

From: Anup Patel <[email protected]>

We add an optional cold_boot_allowed() platform callback which allows platform support to decide which HARTs can do cold boot initialization.

If this platform callback is not available then any HART can do cold boot initialization.

Quoted 65 lines

---
?include/sbi/sbi_platform.h | 20 ++++++++++++++++++++ ?lib/sbi/sbi_init.c???????? |? 7 +++++--
?2 files changed, 25 insertions(+), 2 deletions(-)

include/sbi/sbi_platform.h +0 -0
index 722f27a..566eee3 100644
@@ -65,6 +65,9 @@ enum sbi_platform_features {

?
?/** Platform functions */
?struct sbi_platform_operations {
+???????/* Check if specified HART is allowed to do cold boot */ +???????bool (*cold_boot_allowed)(u32 hartid);
+
????????/* Platform nascent initialization */ ????????int (*nascent_init)(void);
?

include/sbi/sbi_platform.h +0 -0
@@ -356,6 +359,23 @@ static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat,
 ????????return FALSE;
 ?}

?

include/sbi/sbi_platform.h +17 -0
+/**
+ * Check whether given HART is allowed to do cold boot
+ *
+ * @param plat pointer to struct sbi_platform
+ * @param hartid HART ID
+ *
+ * @return TRUE if HART is allowed to do cold boot and FALSE otherwise
+ */
+static inline bool sbi_platform_cold_boot_allowed(
+???????????????????????????????????????const struct sbi_platform *plat,
+???????????????????????????????????????u32 hartid)
+{
+???????if (plat && sbi_platform_ops(plat)->cold_boot_allowed)
+???????????????return sbi_platform_ops(plat)->cold_boot_allowed(hartid);
+???????return TRUE;
+}
+

?/**
? * Nascent (very early) initialization for current HART ? *

lib/sbi/sbi_init.c +0 -0
index a8500e5..d4902d9 100644
@@ -498,8 +498,11 @@ void __noreturn sbi_init(struct sbi_scratch *scratch)

???????? * HARTs which satisfy above condition.
???????? */
?
-???????if (next_mode_supported && atomic_xchg(&coldboot_lottery, 1) == 0) -???????????????coldboot = TRUE;
+???????if (sbi_platform_cold_boot_allowed(plat, hartid)) { +???????????????if (next_mode_supported &&
+?????????????????? atomic_xchg(&coldboot_lottery, 1) == 0) +???????????????????????coldboot = TRUE;
+???????}
?
????????/*
???????? * Do platform specific nascent (very early) initialization so

Signature · 1 line
2.25.1
#3 lore raw

PATCH v4 1/3 lib: sbi: Allow platform to influence cold boot HART selection

In reply to Wei Liang Lim
Quoted 30 lines · Wei Liang Lim

From: Anup Patel <[email protected]>

We add an optional cold_boot_allowed() platform callback which allows platform support to decide which HARTs can do cold boot initialization.

If this platform callback is not available then any HART can do cold boot initialization.

---
 include/sbi/sbi_platform.h | 20 ++++++++++++++++++++
 lib/sbi/sbi_init.c         |  7 +++++--
 2 files changed, 25 insertions(+), 2 deletions(-)
include/sbi/sbi_platform.h +3 -0
index 722f27a..566eee3 100644
@@ -65,6 +65,9 @@ enum sbi_platform_features {
 
 /** Platform functions */
 struct sbi_platform_operations {
+       /* Check if specified HART is allowed to do cold boot */
+       bool (*cold_boot_allowed)(u32 hartid);
+
        /* Platform nascent initialization */
        int (*nascent_init)(void);
 

include/sbi/sbi_platform.h static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat, · line 368

Quoted 10 lines
include/sbi/sbi_platform.h +7 -0
@@ -356,6 +359,23 @@ static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat,
        return FALSE;
 }
 
+/**
+ * Check whether given HART is allowed to do cold boot
+ *
+ * @param plat pointer to struct sbi_platform
+ * @param hartid HART ID
+ *
+ * @return TRUE if HART is allowed to do cold boot and FALSE otherwise

s/TRUE/true/g
s/FALSE/false/g

Quoted 32 lines
include/sbi/sbi_platform.h +10 -0
+ */
+static inline bool sbi_platform_cold_boot_allowed(
+                                       const struct sbi_platform *plat,
+                                       u32 hartid)
+{
+       if (plat && sbi_platform_ops(plat)->cold_boot_allowed)
+               return sbi_platform_ops(plat)->cold_boot_allowed(hartid);
+       return TRUE;
+}
+
 /**
  * Nascent (very early) initialization for current HART
  *
lib/sbi/sbi_init.c +5 -3
index a8500e5..d4902d9 100644
@@ -498,8 +498,11 @@ void __noreturn sbi_init(struct sbi_scratch *scratch)
         * HARTs which satisfy above condition.
         */
 
-       if (next_mode_supported && atomic_xchg(&coldboot_lottery, 1) == 0)
-               coldboot = TRUE;
+       if (sbi_platform_cold_boot_allowed(plat, hartid)) {
+               if (next_mode_supported &&
+                   atomic_xchg(&coldboot_lottery, 1) == 0)
+                       coldboot = TRUE;
+       }
 
        /*
         * Do platform specific nascent (very early) initialization so
--
Quoted 1 line

2.25.1

Otherwise,

#4 lore raw

PATCH v4 2/3 platform: generic: Allow platform_override to select cold boot HART

In reply to Wei Liang Lim

From: Anup Patel <[email protected]>

We add a generic platform override callback to allow platform specific selection of cold boot HART.

---
 platform/generic/include/platform_override.h | 1 +
 platform/generic/platform.c                  | 9 +++++++++
 2 files changed, 10 insertions(+)
platform/generic/include/platform_override.h +1 -0
index 7f1558d..21354e9 100644
@@ -18,6 +18,7 @@ struct platform_override {
 	const struct fdt_match *match_table;
 	u64 (*features)(const struct fdt_match *match);
 	u64 (*tlbr_flush_limit)(const struct fdt_match *match);
+	bool (*cold_boot_allowed)(u32 hartid, const struct fdt_match *match);
 	int (*early_init)(bool cold_boot, const struct fdt_match *match);
 	int (*final_init)(bool cold_boot, const struct fdt_match *match);
 	void (*early_exit)(const struct fdt_match *match);
platform/generic/platform.c +9 -0
index bfe15f0..16aa4f3 100644
@@ -122,6 +122,14 @@ fail:
 		wfi();
 }
 
+static bool generic_cold_boot_allowed(u32 hartid)
+{
+	if (generic_plat && generic_plat->cold_boot_allowed)
+		return generic_plat->cold_boot_allowed(
+						hartid, generic_plat_match);
+	return TRUE;
+}
+
 static int generic_nascent_init(void)
 {
 	if (platform_has_mlevel_imsic)
@@ -261,6 +269,7 @@ static int generic_console_init(void)
 }
 
 const struct sbi_platform_operations platform_ops = {
+	.cold_boot_allowed	= generic_cold_boot_allowed,
 	.nascent_init		= generic_nascent_init,
 	.early_init		= generic_early_init,
 	.final_init		= generic_final_init,
Signature · 1 line
2.25.1
#5 lore raw

PATCH v4 2/3 platform: generic: Allow platform_override to select cold boot HART

? 2022-12-20???? 11:41 +0800?Wei Liang Lim???

Quoted 6 lines

From: Anup Patel <[email protected]>

We add a generic platform override callback to allow platform specific selection of cold boot HART.

Quoted 48 lines

---
?platform/generic/include/platform_override.h | 1 + ?platform/generic/platform.c????????????????? | 9 +++++++++ ?2 files changed, 10 insertions(+)

platform/generic/include/platform_override.h +1 -0
index 7f1558d..21354e9 100644
@@ -18,6 +18,7 @@ struct platform_override {
 ????????const struct fdt_match *match_table;
 ????????u64 (*features)(const struct fdt_match *match);
 ????????u64 (*tlbr_flush_limit)(const struct fdt_match *match);
+???????bool (*cold_boot_allowed)(u32 hartid, const struct fdt_match *match);
 ????????int (*early_init)(bool cold_boot, const struct fdt_match *match);
 ????????int (*final_init)(bool cold_boot, const struct fdt_match *match);
 ????????void (*early_exit)(const struct fdt_match *match);
platform/generic/platform.c +0 -0
index bfe15f0..16aa4f3 100644
@@ -122,6 +122,14 @@ fail:
 ????????????????wfi();
 ?}

?

platform/generic/platform.c +8 -0
+static bool generic_cold_boot_allowed(u32 hartid)
+{
+???????if (generic_plat && generic_plat->cold_boot_allowed)
+???????????????return generic_plat->cold_boot_allowed(
+???????????????????????????????????????????????hartid, generic_plat_match);
+???????return TRUE;
+}
+

?static int generic_nascent_init(void)
?{
????????if (platform_has_mlevel_imsic)

platform/generic/platform.c +0 -0
@@ -261,6 +269,7 @@ static int generic_console_init(void)
 ?}

?
?const struct sbi_platform_operations platform_ops = { +???????.cold_boot_allowed??????= generic_cold_boot_allowed, ????????.nascent_init???????????= generic_nascent_init, ????????.early_init?????????????= generic_early_init, ????????.final_init?????????????= generic_final_init,

Signature · 1 line
2.25.1
#6 lore raw

PATCH v4 2/3 platform: generic: Allow platform_override to select cold boot HART

In reply to Wei Liang Lim
Quoted 29 lines · Wei Liang Lim

From: Anup Patel <[email protected]>

We add a generic platform override callback to allow platform specific selection of cold boot HART.

---
 platform/generic/include/platform_override.h | 1 +
 platform/generic/platform.c                  | 9 +++++++++
 2 files changed, 10 insertions(+)
platform/generic/include/platform_override.h +1 -0
index 7f1558d..21354e9 100644
@@ -18,6 +18,7 @@ struct platform_override {
        const struct fdt_match *match_table;
        u64 (*features)(const struct fdt_match *match);
        u64 (*tlbr_flush_limit)(const struct fdt_match *match);
+       bool (*cold_boot_allowed)(u32 hartid, const struct fdt_match *match);
        int (*early_init)(bool cold_boot, const struct fdt_match *match);
        int (*final_init)(bool cold_boot, const struct fdt_match *match);
        void (*early_exit)(const struct fdt_match *match);
platform/generic/platform.c +0 -0
index bfe15f0..16aa4f3 100644

platform/generic/platform.c fail: · line 130

Quoted 9 lines
platform/generic/platform.c +6 -0
@@ -122,6 +122,14 @@ fail:
                wfi();
 }
 
+static bool generic_cold_boot_allowed(u32 hartid)
+{
+       if (generic_plat && generic_plat->cold_boot_allowed)
+               return generic_plat->cold_boot_allowed(
+                                               hartid, generic_plat_match);
+       return TRUE;

s/TRUE/true

Quoted 14 lines
platform/generic/platform.c +3 -1
+}
+
 static int generic_nascent_init(void)
 {
        if (platform_has_mlevel_imsic)
@@ -261,6 +269,7 @@ static int generic_console_init(void)
 }
 
 const struct sbi_platform_operations platform_ops = {
+       .cold_boot_allowed      = generic_cold_boot_allowed,
        .nascent_init           = generic_nascent_init,
        .early_init             = generic_early_init,
        .final_init             = generic_final_init,
--
Quoted 2 lines

2.25.1

Otherwise,

#7 lore raw

PATCH v4 3/3 generic/starfive: Add Starfive JH7110 platform implementation

In reply to Wei Liang Lim

Add Starfive JH7110 platform implementation

---
 platform/generic/Kconfig             |  4 ++
 platform/generic/configs/defconfig   |  1 +
 platform/generic/starfive/jh7110.c   | 57 ++++++++++++++++++++++++++++
 platform/generic/starfive/objects.mk |  6 +++
 4 files changed, 68 insertions(+)
 create mode 100644 platform/generic/starfive/jh7110.c
 create mode 100644 platform/generic/starfive/objects.mk
platform/generic/Kconfig +4 -0
index 62c7a2d..47c10e5 100644
@@ -45,4 +45,8 @@ config PLATFORM_SIFIVE_FU740
 	depends on FDT_RESET && FDT_I2C
 	default n
 
+config PLATFORM_STARFIVE_JH7110
+	bool "StarFive JH7110 support"
+	default n
+
 endif
platform/generic/configs/defconfig +1 -0
index 47fca95..4b0842e 100644
@@ -3,6 +3,7 @@ CONFIG_PLATFORM_ANDES_AE350=y
 CONFIG_PLATFORM_RENESAS_RZFIVE=y
 CONFIG_PLATFORM_SIFIVE_FU540=y
 CONFIG_PLATFORM_SIFIVE_FU740=y
+CONFIG_PLATFORM_STARFIVE_JH7110=y
 CONFIG_FDT_GPIO=y
 CONFIG_FDT_GPIO_SIFIVE=y
 CONFIG_FDT_I2C=y
platform/generic/starfive/jh7110.c new file +57 -0

57 lines not on this page · raw message

platform/generic/starfive/objects.mk new file +6 -0
new file mode 100644
index 0000000..0b900fb
@@ -0,0 +1,6 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+carray-platform_override_modules-$(CONFIG_PLATFORM_STARFIVE_JH7110) += starfive_jh7110
+platform-objs-$(CONFIG_PLATFORM_STARFIVE_JH7110) += starfive/jh7110.o
Signature · 1 line
2.25.1
#8 lore raw

PATCH v4 3/3 generic/starfive: Add Starfive JH7110 platform implementation

? 2022-12-20???? 11:41 +0800?Wei Liang Lim???

Quoted 49 lines

Add Starfive JH7110 platform implementation

---

?platform/generic/Kconfig???????????? |? 4 ++
?platform/generic/configs/defconfig?? |? 1 +
?platform/generic/starfive/jh7110.c?? | 57 ++++++++++++++++++++++++++++
?platform/generic/starfive/objects.mk |? 6 +++

?4 files changed, 68 insertions(+)
?create mode 100644 platform/generic/starfive/jh7110.c ?create mode 100644 platform/generic/starfive/objects.mk

platform/generic/Kconfig +0 -0
index 62c7a2d..47c10e5 100644
@@ -45,4 +45,8 @@ config PLATFORM_SIFIVE_FU740

????????depends on FDT_RESET && FDT_I2C
????????default n
?

platform/generic/Kconfig +4 -0
+config PLATFORM_STARFIVE_JH7110
+???????bool "StarFive JH7110 support"
+???????default n
+

?endif

platform/generic/configs/defconfig +0 -0
index 47fca95..4b0842e 100644
@@ -3,6 +3,7 @@ CONFIG_PLATFORM_ANDES_AE350=y

?CONFIG_PLATFORM_RENESAS_RZFIVE=y
?CONFIG_PLATFORM_SIFIVE_FU540=y
?CONFIG_PLATFORM_SIFIVE_FU740=y
+CONFIG_PLATFORM_STARFIVE_JH7110=y
?CONFIG_FDT_GPIO=y
?CONFIG_FDT_GPIO_SIFIVE=y
?CONFIG_FDT_I2C=y

platform/generic/starfive/jh7110.c new file +4 -0
new file mode 100644
index 0000000..5d3ab6f
@@ -0,0 +1,57 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 StarFive

platform/generic/starfive/jh7110.c line 14

Quoted 10 lines
platform/generic/starfive/jh7110.c new file +10 -0
+ *
+ * Authors:
+ *?? Wei Liang Lim <[email protected]>
+ */
+
+#include <libfdt.h>
+#include <platform_override.h>
+#include <sbi_utils/fdt/fdt_helper.h>
+
+static bool hart_cold_booted = FALSE;

hart_cold_booted is not necessary, because coldboot_lottery will be 1 after the first boot, which will guarantee that the second init_coldboot will not be executed

Quoted 10 lines
platform/generic/starfive/jh7110.c new file +10 -0
+
+static bool starfive_jh7110_cold_boot_allowed(u32 hartid,
+????????????????????????????????? const struct fdt_match *match)
+{
+???????const fdt32_t *val;
+???????int len, coff;
+
+???????if (hart_cold_booted)
+???????????????return FALSE;
+

platform/generic/starfive/jh7110.c line 34

Quoted 10 lines
platform/generic/starfive/jh7110.c new file +10 -0
+???????void *fdt = fdt_get_address();
+
+???????coff = fdt_path_offset(fdt, "/chosen");
+???????if (-1 < coff) {
+???????????????val = fdt_getprop(fdt, coff, "boot-hart", &len);
+???????????????if (val && len) {
+???????????????????????u32 selected_hartid = (u32) fdt32_to_cpu(*val);
+???????????????????????return (selected_hartid == hartid);
+???????????????}
+???????}

You can define selected_hartid as a static variable with an initial value of -1, and get it from fdt when the initial value is -1. In this way, there is no need to analyze fdt every time.

Regards,
Xiang W

Quoted 40 lines
platform/generic/starfive/jh7110.c new file +23 -0
+
+???????return TRUE;
+}
+
 
+static int starfive_jh7110_early_init(bool cold_boot,
+????????????????????????????????? const struct fdt_match *match)
+{
+???????if (cold_boot)
+???????????????hart_cold_booted = TRUE;
+
+???????return 0;
+}
+
+static const struct fdt_match starfive_jh7110_match[] = {
+???????{ .compatible = "starfive,jh7110" },
+???????{ },
+};
+
+const struct platform_override starfive_jh7110 = {
+???????.match_table = starfive_jh7110_match,
+???????.early_init = starfive_jh7110_early_init,
+???????.cold_boot_allowed = starfive_jh7110_cold_boot_allowed,
+};
platform/generic/starfive/objects.mk new file +6 -0
new file mode 100644
index 0000000..0b900fb
@@ -0,0 +1,6 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+carray-platform_override_modules-$(CONFIG_PLATFORM_STARFIVE_JH7110) += starfive_jh7110
+platform-objs-$(CONFIG_PLATFORM_STARFIVE_JH7110) += starfive/jh7110.o
Signature · 1 line
2.25.1
#9 lore raw

PATCH v4 3/3 generic/starfive: Add Starfive JH7110 platform implementation

In reply to Wei Liang Lim
Quoted 61 lines · Wei Liang Lim

Add Starfive JH7110 platform implementation

---
 platform/generic/Kconfig             |  4 ++
 platform/generic/configs/defconfig   |  1 +
 platform/generic/starfive/jh7110.c   | 57 ++++++++++++++++++++++++++++
 platform/generic/starfive/objects.mk |  6 +++
 4 files changed, 68 insertions(+)
 create mode 100644 platform/generic/starfive/jh7110.c
 create mode 100644 platform/generic/starfive/objects.mk
platform/generic/Kconfig +4 -0
index 62c7a2d..47c10e5 100644
@@ -45,4 +45,8 @@ config PLATFORM_SIFIVE_FU740
        depends on FDT_RESET && FDT_I2C
        default n
 
+config PLATFORM_STARFIVE_JH7110
+       bool "StarFive JH7110 support"
+       default n
+
 endif
platform/generic/configs/defconfig +1 -0
index 47fca95..4b0842e 100644
@@ -3,6 +3,7 @@ CONFIG_PLATFORM_ANDES_AE350=y
 CONFIG_PLATFORM_RENESAS_RZFIVE=y
 CONFIG_PLATFORM_SIFIVE_FU540=y
 CONFIG_PLATFORM_SIFIVE_FU740=y
+CONFIG_PLATFORM_STARFIVE_JH7110=y
 CONFIG_FDT_GPIO=y
 CONFIG_FDT_GPIO_SIFIVE=y
 CONFIG_FDT_I2C=y
platform/generic/starfive/jh7110.c new file +15 -0
new file mode 100644
index 0000000..5d3ab6f
@@ -0,0 +1,57 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 StarFive
+ *
+ * Authors:
+ *   Wei Liang Lim <[email protected]>
+ */
+
+#include <libfdt.h>
+#include <platform_override.h>
+#include <sbi_utils/fdt/fdt_helper.h>
+
+static bool hart_cold_booted = FALSE;
+

platform/generic/starfive/jh7110.c line 25

Quoted 10 lines
platform/generic/starfive/jh7110.c new file +10 -0
+static bool starfive_jh7110_cold_boot_allowed(u32 hartid,
+                                  const struct fdt_match *match)
+{
+       const fdt32_t *val;
+       int len, coff;
+
+       if (hart_cold_booted)
+               return FALSE;
+
+       void *fdt = fdt_get_address();

starfive_jh7110_cold_boot_allowed() will be called at runtime during CPU hotplug or CPU non-retentive suspend so don't access FDT in this function because it might have been corrupted/over-written by S-mode software.

You can save data from FDT in starfive_jh7110_early_init() when cold_boot == TRUE.

Regards,
Anup

Quoted 47 lines
platform/generic/starfive/jh7110.c new file +32 -0
+
+       coff = fdt_path_offset(fdt, "/chosen");
+       if (-1 < coff) {
+               val = fdt_getprop(fdt, coff, "boot-hart", &len);
+               if (val && len) {
+                       u32 selected_hartid = (u32) fdt32_to_cpu(*val);
+                       return (selected_hartid == hartid);
+               }
+       }
+
+       return TRUE;
+}
+
+static int starfive_jh7110_early_init(bool cold_boot,
+                                  const struct fdt_match *match)
+{
+       if (cold_boot)
+               hart_cold_booted = TRUE;
+
+       return 0;
+}
+
+static const struct fdt_match starfive_jh7110_match[] = {
+       { .compatible = "starfive,jh7110" },
+       { },
+};
+
+const struct platform_override starfive_jh7110 = {
+       .match_table = starfive_jh7110_match,
+       .early_init = starfive_jh7110_early_init,
+       .cold_boot_allowed = starfive_jh7110_cold_boot_allowed,
+};
platform/generic/starfive/objects.mk new file +6 -1
new file mode 100644
index 0000000..0b900fb
@@ -0,0 +1,6 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+carray-platform_override_modules-$(CONFIG_PLATFORM_STARFIVE_JH7110) += starfive_jh7110
+platform-objs-$(CONFIG_PLATFORM_STARFIVE_JH7110) += starfive/jh7110.o
--

2.25.1

#10 lore raw

PATCH v4 3/3 generic/starfive: Add Starfive JH7110 platform implementation

Quoted 91 lines

-----Original Message-----
From: Anup Patel <[email protected]>
Sent: Tuesday, December 20, 2022 7:05 PM
To: WeiLiang Lim <[email protected]>
Cc: opensbi at lists.infradead.org; Cheehong Ang <[email protected]>; JunLiang Tan <[email protected]>
Subject: Re: [PATCH v4 3/3] generic/starfive: Add Starfive JH7110 platform implementation

Quoted 34 lines · Wei Liang Lim

Add Starfive JH7110 platform implementation

---
 platform/generic/Kconfig             |  4 ++
 platform/generic/configs/defconfig   |  1 +
 platform/generic/starfive/jh7110.c   | 57 ++++++++++++++++++++++++++++
 platform/generic/starfive/objects.mk |  6 +++
 4 files changed, 68 insertions(+)
 create mode 100644 platform/generic/starfive/jh7110.c
 create mode 100644 platform/generic/starfive/objects.mk
platform/generic/Kconfig index renamed from platform/generic/Kconfig +0 -0

62c7a2d..47c10e5 100644

platform/generic/Kconfig +4 -0
@@ -45,4 +45,8 @@ config PLATFORM_SIFIVE_FU740
        depends on FDT_RESET && FDT_I2C
        default n
 
+config PLATFORM_STARFIVE_JH7110
+       bool "StarFive JH7110 support"
+       default n
+
 endif
platform/generic/configs/defconfig +0 -0
index 47fca95..4b0842e 100644
@@ -3,6 +3,7 @@ CONFIG_PLATFORM_ANDES_AE350=y
Quoted 1 line

CONFIG_PLATFORM_RENESAS_RZFIVE=y

CONFIG_PLATFORM_SIFIVE_FU540=y

Quoted 26 lines

CONFIG_PLATFORM_SIFIVE_FU740=y

platform/generic/configs/defconfig +1 -0
+CONFIG_PLATFORM_STARFIVE_JH7110=y
 CONFIG_FDT_GPIO=y
 CONFIG_FDT_GPIO_SIFIVE=y
 CONFIG_FDT_I2C=y
platform/generic/starfive/jh7110.c new file +14 -0
new file mode 100644
index 0000000..5d3ab6f
@@ -0,0 +1,57 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 StarFive
+ *
+ * Authors:
+ *   Wei Liang Lim <[email protected]>
+ */
+
+#include <libfdt.h>
+#include <platform_override.h>
+#include <sbi_utils/fdt/fdt_helper.h>
+
+static bool hart_cold_booted = FALSE;

platform/generic/starfive/jh7110.c line 24

Quoted 10 lines
platform/generic/starfive/jh7110.c new file +10 -0
+
+static bool starfive_jh7110_cold_boot_allowed(u32 hartid,
+                                  const struct fdt_match *match) {
+       const fdt32_t *val;
+       int len, coff;
+
+       if (hart_cold_booted)
+               return FALSE;
+
+       void *fdt = fdt_get_address();

starfive_jh7110_cold_boot_allowed() will be called at runtime during CPU hotplug or CPU non-retentive suspend so don't access FDT in this function because it might have been corrupted/over-written by S-mode software.

Quoted 3 lines

You can save data from FDT in starfive_jh7110_early_init() when cold_boot == TRUE.

The problem is early_init() is called from init_coldboot() and init_warm_startup() which is right after cold_boot_allowed(). Therefore, we have to access the FDT here, this is why we add a 'hart_cold_booted' boolean to ensure the FDT will not be accessed again once the FDT is read in cold boot path for the first time.
This is to avoid the issue you mentioned above. The code here already ensure the FDT will not be accessed again when the cold_boot_allowed() function is called during HSM SBI calls. This is the reason in the beginning of the cold_boot_allowed() function, we check whether the 'hart_cold_booted' is set to TRUE which mean the FDT should not be accessed again.

Quoted 52 lines

Regards,
Anup

Quoted 38 lines
platform/generic/starfive/jh7110.c new file +31 -0
+
+       coff = fdt_path_offset(fdt, "/chosen");
+       if (-1 < coff) {
+               val = fdt_getprop(fdt, coff, "boot-hart", &len);
+               if (val && len) {
+                       u32 selected_hartid = (u32) fdt32_to_cpu(*val);
+                       return (selected_hartid == hartid);
+               }
+       }
+
+       return TRUE;
+}
+
+static int starfive_jh7110_early_init(bool cold_boot,
+                                  const struct fdt_match *match) {
+       if (cold_boot)
+               hart_cold_booted = TRUE;
+
+       return 0;
+}
+
+static const struct fdt_match starfive_jh7110_match[] = {
+       { .compatible = "starfive,jh7110" },
+       { },
+};
+
+const struct platform_override starfive_jh7110 = {
+       .match_table = starfive_jh7110_match,
+       .early_init = starfive_jh7110_early_init,
+       .cold_boot_allowed = starfive_jh7110_cold_boot_allowed,
+};
platform/generic/starfive/objects.mk new file +0 -0
new file mode 100644
index 0000000..0b900fb

platform/generic/starfive/objects.mk line 4

Quoted 4 lines
platform/generic/starfive/objects.mk new file +4 -0
@@ -0,0 +1,6 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause #
+
+carray-platform_override_modules-

$(CONFIG_PLATFORM_STARFIVE_JH7110)

platform/generic/starfive/objects.mk line 6

Quoted 2 lines
platform/generic/starfive/objects.mk new file +2 -0
++= starfive_jh7110
+platform-objs-$(CONFIG_PLATFORM_STARFIVE_JH7110) +=

starfive/jh7110.o

Quoted 3 lines

--
2.25.1

#11 lore raw

PATCH v4 3/3 generic/starfive: Add Starfive JH7110 platform implementation

Quoted 92 lines · Cheehong Ang
Quoted 92 lines

-----Original Message-----
From: Anup Patel <[email protected]>
Sent: Tuesday, December 20, 2022 7:05 PM
To: WeiLiang Lim <[email protected]>
Cc: opensbi at lists.infradead.org; Cheehong Ang <[email protected]>; JunLiang Tan <[email protected]>
Subject: Re: [PATCH v4 3/3] generic/starfive: Add Starfive JH7110 platform implementation

Quoted 34 lines · Wei Liang Lim

Add Starfive JH7110 platform implementation

---
 platform/generic/Kconfig             |  4 ++
 platform/generic/configs/defconfig   |  1 +
 platform/generic/starfive/jh7110.c   | 57 ++++++++++++++++++++++++++++
 platform/generic/starfive/objects.mk |  6 +++
 4 files changed, 68 insertions(+)
 create mode 100644 platform/generic/starfive/jh7110.c
 create mode 100644 platform/generic/starfive/objects.mk
platform/generic/Kconfig index renamed from platform/generic/Kconfig +0 -0

62c7a2d..47c10e5 100644

platform/generic/Kconfig +4 -0
@@ -45,4 +45,8 @@ config PLATFORM_SIFIVE_FU740
        depends on FDT_RESET && FDT_I2C
        default n
 
+config PLATFORM_STARFIVE_JH7110
+       bool "StarFive JH7110 support"
+       default n
+
 endif
platform/generic/configs/defconfig +0 -0
index 47fca95..4b0842e 100644
@@ -3,6 +3,7 @@ CONFIG_PLATFORM_ANDES_AE350=y
Quoted 1 line

CONFIG_PLATFORM_RENESAS_RZFIVE=y

CONFIG_PLATFORM_SIFIVE_FU540=y

Quoted 26 lines

CONFIG_PLATFORM_SIFIVE_FU740=y

platform/generic/configs/defconfig +1 -0
+CONFIG_PLATFORM_STARFIVE_JH7110=y
 CONFIG_FDT_GPIO=y
 CONFIG_FDT_GPIO_SIFIVE=y
 CONFIG_FDT_I2C=y
platform/generic/starfive/jh7110.c new file +14 -0
new file mode 100644
index 0000000..5d3ab6f
@@ -0,0 +1,57 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 StarFive
+ *
+ * Authors:
+ *   Wei Liang Lim <[email protected]>
+ */
+
+#include <libfdt.h>
+#include <platform_override.h>
+#include <sbi_utils/fdt/fdt_helper.h>
+
+static bool hart_cold_booted = FALSE;

platform/generic/starfive/jh7110.c line 24

Quoted 10 lines
platform/generic/starfive/jh7110.c new file +10 -0
+
+static bool starfive_jh7110_cold_boot_allowed(u32 hartid,
+                                  const struct fdt_match *match) {
+       const fdt32_t *val;
+       int len, coff;
+
+       if (hart_cold_booted)
+               return FALSE;
+
+       void *fdt = fdt_get_address();

starfive_jh7110_cold_boot_allowed() will be called at runtime during CPU hotplug or CPU non-retentive suspend so don't access FDT in this function because it might have been corrupted/over-written by S-mode software.

Quoted 8 lines
Quoted 3 lines

You can save data from FDT in starfive_jh7110_early_init() when cold_boot == TRUE.

The problem is early_init() is called from init_coldboot() and init_warm_startup() which is right after cold_boot_allowed(). Therefore, we have to access the FDT here, this is why we add a 'hart_cold_booted' boolean to ensure the FDT will not be accessed again once the FDT is read in cold boot path for the first time.
This is to avoid the issue you mentioned above. The code here already ensure the FDT will not be accessed again when the cold_boot_allowed() function is called during HSM SBI calls. This is the reason in the beginning of the cold_boot_allowed() function, we check whether the 'hart_cold_booted' is set to TRUE which mean the FDT should not be accessed again.

I see but there is another way to do this.

You do the following as a separate PATCH before this PATCH:
1) Add "void (*fw_init)(void *fdt, const struct fdt_match *match)" in "struct platform_override"
2) Update fw_platform_init() to call generic_plat->fw_init() right after fw_platform_lookup_special() call.

Your current patch can simply implement fw_init() callback which will parse the chosen boot-hart-id. You will not need hart_cold_booted boolean with this approach.

Regards,
Anup

Quoted 53 lines
Quoted 53 lines

Regards,
Anup

Quoted 38 lines
platform/generic/starfive/jh7110.c new file +31 -0
+
+       coff = fdt_path_offset(fdt, "/chosen");
+       if (-1 < coff) {
+               val = fdt_getprop(fdt, coff, "boot-hart", &len);
+               if (val && len) {
+                       u32 selected_hartid = (u32) fdt32_to_cpu(*val);
+                       return (selected_hartid == hartid);
+               }
+       }
+
+       return TRUE;
+}
+
+static int starfive_jh7110_early_init(bool cold_boot,
+                                  const struct fdt_match *match) {
+       if (cold_boot)
+               hart_cold_booted = TRUE;
+
+       return 0;
+}
+
+static const struct fdt_match starfive_jh7110_match[] = {
+       { .compatible = "starfive,jh7110" },
+       { },
+};
+
+const struct platform_override starfive_jh7110 = {
+       .match_table = starfive_jh7110_match,
+       .early_init = starfive_jh7110_early_init,
+       .cold_boot_allowed = starfive_jh7110_cold_boot_allowed,
+};
platform/generic/starfive/objects.mk new file +0 -0
new file mode 100644
index 0000000..0b900fb

platform/generic/starfive/objects.mk line 4

Quoted 4 lines
platform/generic/starfive/objects.mk new file +4 -0
@@ -0,0 +1,6 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause #
+
+carray-platform_override_modules-

$(CONFIG_PLATFORM_STARFIVE_JH7110)

platform/generic/starfive/objects.mk line 6

Quoted 2 lines
platform/generic/starfive/objects.mk new file +2 -0
++= starfive_jh7110
+platform-objs-$(CONFIG_PLATFORM_STARFIVE_JH7110) +=

starfive/jh7110.o

Quoted 3 lines

--
2.25.1

#12 lore raw

PATCH v4 3/3 generic/starfive: Add Starfive JH7110 platform implementation

Quoted 128 lines

-----Original Message-----
From: Anup Patel <[email protected]>
Sent: Tuesday, December 20, 2022 8:04 PM
To: Cheehong Ang <[email protected]>
Cc: WeiLiang Lim <[email protected]>;
opensbi at lists.infradead.org; JunLiang Tan <[email protected]>
Subject: Re: [PATCH v4 3/3] generic/starfive: Add Starfive JH7110 platform implementation

Quoted 18 lines · Cheehong Ang
Quoted 18 lines

-----Original Message-----
From: Anup Patel <[email protected]>
Sent: Tuesday, December 20, 2022 7:05 PM
To: WeiLiang Lim <[email protected]>
Cc: opensbi at lists.infradead.org; Cheehong Ang <[email protected]>; JunLiang Tan <[email protected]>
Subject: Re: [PATCH v4 3/3] generic/starfive: Add Starfive JH7110 platform implementation

Quoted 3 lines · Wei Liang Lim

Add Starfive JH7110 platform implementation

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
---
 platform/generic/Kconfig             |  4 ++
 platform/generic/configs/defconfig   |  1 +
 platform/generic/starfive/jh7110.c   | 57

++++++++++++++++++++++++++++

Quoted 59 lines
Quoted 59 lines
Quoted 25 lines
 platform/generic/starfive/objects.mk |  6 +++
 4 files changed, 68 insertions(+)  create mode 100644
platform/generic/starfive/jh7110.c
 create mode 100644 platform/generic/starfive/objects.mk
platform/generic/Kconfig +0 -0

index
62c7a2d..47c10e5 100644

platform/generic/Kconfig +4 -0
@@ -45,4 +45,8 @@ config PLATFORM_SIFIVE_FU740
        depends on FDT_RESET && FDT_I2C
        default n
 
+config PLATFORM_STARFIVE_JH7110
+       bool "StarFive JH7110 support"
+       default n
+
 endif
platform/generic/configs/defconfig +0 -0
index 47fca95..4b0842e 100644
@@ -3,6 +3,7 @@ CONFIG_PLATFORM_ANDES_AE350=y
Quoted 1 line

CONFIG_PLATFORM_RENESAS_RZFIVE=y

CONFIG_PLATFORM_SIFIVE_FU540=y

Quoted 32 lines

CONFIG_PLATFORM_SIFIVE_FU740=y

platform/generic/configs/defconfig +1 -0
+CONFIG_PLATFORM_STARFIVE_JH7110=y
 CONFIG_FDT_GPIO=y
 CONFIG_FDT_GPIO_SIFIVE=y
 CONFIG_FDT_I2C=y
platform/generic/starfive/jh7110.c new file +20 -0
new file mode 100644
index 0000000..5d3ab6f
@@ -0,0 +1,57 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 StarFive
+ *
+ * Authors:
+ *   Wei Liang Lim <[email protected]>
+ */
+
+#include <libfdt.h>
+#include <platform_override.h>
+#include <sbi_utils/fdt/fdt_helper.h>
+
+static bool hart_cold_booted = FALSE;
+
+static bool starfive_jh7110_cold_boot_allowed(u32 hartid,
+                                  const struct fdt_match *match) {
+       const fdt32_t *val;
+       int len, coff;
+
Quoted 8 lines
Quoted 8 lines

platform/generic/starfive/jh7110.c line 25

Quoted 4 lines
platform/generic/starfive/jh7110.c new file +4 -0
+       if (hart_cold_booted)
+               return FALSE;
+
+       void *fdt = fdt_get_address();

starfive_jh7110_cold_boot_allowed() will be called at runtime during CPU hotplug or CPU non-retentive suspend so don't access FDT in this function because it might have been corrupted/over-written by S-mode

software.

Quoted 6 lines
Quoted 4 lines

You can save data from FDT in starfive_jh7110_early_init() when cold_boot == TRUE.

The problem is early_init() is called from init_coldboot() and init_warm_startup() which is right after cold_boot_allowed(). Therefore, we

have to access the FDT here, this is why we add a 'hart_cold_booted' boolean to ensure the FDT will not be accessed again once the FDT is read in cold boot path for the first time.

Quoted 3 lines

This is to avoid the issue you mentioned above. The code here already ensure the FDT will not be accessed again when the cold_boot_allowed() function is called during HSM SBI calls. This is the reason in the beginning of

the cold_boot_allowed() function, we check whether the 'hart_cold_booted' is set to TRUE which mean the FDT should not be accessed again.

I see but there is another way to do this.

You do the following as a separate PATCH before this PATCH:
1) Add "void (*fw_init)(void *fdt, const struct fdt_match *match)" in "struct platform_override"
2) Update fw_platform_init() to call generic_plat->fw_init() right after fw_platform_lookup_special() call.

Quoted 3 lines

Your current patch can simply implement fw_init() callback which will parse the chosen boot-hart-id. You will not need hart_cold_booted boolean with this approach.

Thanks. Will do. This shall also resolved Xiang's comment in other thread that the FDT is read multiple times when multiple harts call cold_boot_allowed(). I believe the fw_platform_init() in fw_base.S is only called once from initial boot hart. I don't think fdt_get_address() can be called in fw_platform_init() as the scratch area is not initialized yet. But I think we can still get the FDT location from one of the arguments passed to fw_platform_init().

Quoted 57 lines

Regards,
Anup

Quoted 53 lines
Quoted 53 lines

Regards,
Anup

Quoted 38 lines
platform/generic/starfive/jh7110.c new file +31 -0
+
+       coff = fdt_path_offset(fdt, "/chosen");
+       if (-1 < coff) {
+               val = fdt_getprop(fdt, coff, "boot-hart", &len);
+               if (val && len) {
+                       u32 selected_hartid = (u32) fdt32_to_cpu(*val);
+                       return (selected_hartid == hartid);
+               }
+       }
+
+       return TRUE;
+}
+
+static int starfive_jh7110_early_init(bool cold_boot,
+                                  const struct fdt_match *match) {
+       if (cold_boot)
+               hart_cold_booted = TRUE;
+
+       return 0;
+}
+
+static const struct fdt_match starfive_jh7110_match[] = {
+       { .compatible = "starfive,jh7110" },
+       { },
+};
+
+const struct platform_override starfive_jh7110 = {
+       .match_table = starfive_jh7110_match,
+       .early_init = starfive_jh7110_early_init,
+       .cold_boot_allowed = starfive_jh7110_cold_boot_allowed,
+};
platform/generic/starfive/objects.mk new file +0 -0
new file mode 100644
index 0000000..0b900fb

platform/generic/starfive/objects.mk line 4

Quoted 4 lines
platform/generic/starfive/objects.mk new file +4 -0
@@ -0,0 +1,6 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause #
+
+carray-platform_override_modules-

$(CONFIG_PLATFORM_STARFIVE_JH7110)

platform/generic/starfive/objects.mk line 6

Quoted 2 lines
platform/generic/starfive/objects.mk new file +2 -0
++= starfive_jh7110
+platform-objs-$(CONFIG_PLATFORM_STARFIVE_JH7110) +=

starfive/jh7110.o

Quoted 3 lines

--
2.25.1

#13 lore raw

PATCH v4 3/3 generic/starfive: Add Starfive JH7110 platform implementation

Quoted 129 lines · Cheehong Ang
Quoted 129 lines

-----Original Message-----
From: Anup Patel <[email protected]>
Sent: Tuesday, December 20, 2022 8:04 PM
To: Cheehong Ang <[email protected]>
Cc: WeiLiang Lim <[email protected]>;
opensbi at lists.infradead.org; JunLiang Tan <[email protected]>
Subject: Re: [PATCH v4 3/3] generic/starfive: Add Starfive JH7110 platform implementation

Quoted 18 lines · Cheehong Ang
Quoted 18 lines

-----Original Message-----
From: Anup Patel <[email protected]>
Sent: Tuesday, December 20, 2022 7:05 PM
To: WeiLiang Lim <[email protected]>
Cc: opensbi at lists.infradead.org; Cheehong Ang <[email protected]>; JunLiang Tan <[email protected]>
Subject: Re: [PATCH v4 3/3] generic/starfive: Add Starfive JH7110 platform implementation

Quoted 3 lines · Wei Liang Lim

Add Starfive JH7110 platform implementation

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
---
 platform/generic/Kconfig             |  4 ++
 platform/generic/configs/defconfig   |  1 +
 platform/generic/starfive/jh7110.c   | 57

++++++++++++++++++++++++++++

Quoted 59 lines
Quoted 59 lines
Quoted 25 lines
 platform/generic/starfive/objects.mk |  6 +++
 4 files changed, 68 insertions(+)  create mode 100644
platform/generic/starfive/jh7110.c
 create mode 100644 platform/generic/starfive/objects.mk
platform/generic/Kconfig +0 -0

index
62c7a2d..47c10e5 100644

platform/generic/Kconfig +4 -0
@@ -45,4 +45,8 @@ config PLATFORM_SIFIVE_FU740
        depends on FDT_RESET && FDT_I2C
        default n
 
+config PLATFORM_STARFIVE_JH7110
+       bool "StarFive JH7110 support"
+       default n
+
 endif
platform/generic/configs/defconfig +0 -0
index 47fca95..4b0842e 100644
@@ -3,6 +3,7 @@ CONFIG_PLATFORM_ANDES_AE350=y
Quoted 1 line

CONFIG_PLATFORM_RENESAS_RZFIVE=y

CONFIG_PLATFORM_SIFIVE_FU540=y

Quoted 32 lines

CONFIG_PLATFORM_SIFIVE_FU740=y

platform/generic/configs/defconfig +1 -0
+CONFIG_PLATFORM_STARFIVE_JH7110=y
 CONFIG_FDT_GPIO=y
 CONFIG_FDT_GPIO_SIFIVE=y
 CONFIG_FDT_I2C=y
platform/generic/starfive/jh7110.c new file +20 -0
new file mode 100644
index 0000000..5d3ab6f
@@ -0,0 +1,57 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 StarFive
+ *
+ * Authors:
+ *   Wei Liang Lim <[email protected]>
+ */
+
+#include <libfdt.h>
+#include <platform_override.h>
+#include <sbi_utils/fdt/fdt_helper.h>
+
+static bool hart_cold_booted = FALSE;
+
+static bool starfive_jh7110_cold_boot_allowed(u32 hartid,
+                                  const struct fdt_match *match) {
+       const fdt32_t *val;
+       int len, coff;
+
Quoted 8 lines
Quoted 8 lines

platform/generic/starfive/jh7110.c line 25

Quoted 4 lines
platform/generic/starfive/jh7110.c new file +4 -0
+       if (hart_cold_booted)
+               return FALSE;
+
+       void *fdt = fdt_get_address();

starfive_jh7110_cold_boot_allowed() will be called at runtime during CPU hotplug or CPU non-retentive suspend so don't access FDT in this function because it might have been corrupted/over-written by S-mode

software.

Quoted 6 lines
Quoted 4 lines

You can save data from FDT in starfive_jh7110_early_init() when cold_boot == TRUE.

The problem is early_init() is called from init_coldboot() and init_warm_startup() which is right after cold_boot_allowed(). Therefore, we

have to access the FDT here, this is why we add a 'hart_cold_booted' boolean to ensure the FDT will not be accessed again once the FDT is read in cold boot path for the first time.

Quoted 3 lines

This is to avoid the issue you mentioned above. The code here already ensure the FDT will not be accessed again when the cold_boot_allowed() function is called during HSM SBI calls. This is the reason in the beginning of

the cold_boot_allowed() function, we check whether the 'hart_cold_booted' is set to TRUE which mean the FDT should not be accessed again.

I see but there is another way to do this.

You do the following as a separate PATCH before this PATCH:
1) Add "void (*fw_init)(void *fdt, const struct fdt_match *match)" in "struct platform_override"
2) Update fw_platform_init() to call generic_plat->fw_init() right after fw_platform_lookup_special() call.

Quoted 7 lines
Quoted 3 lines

Your current patch can simply implement fw_init() callback which will parse the chosen boot-hart-id. You will not need hart_cold_booted boolean with this approach.

Thanks. Will do. This shall also resolved Xiang's comment in other thread that the FDT is read multiple times when multiple harts call cold_boot_allowed(). I believe the fw_platform_init() in fw_base.S is only called once from initial boot hart. I don't think fdt_get_address() can be called in fw_platform_init() as the scratch area is not initialized yet. But I think we can still get the FDT location from one of the arguments passed to fw_platform_init().

Yes, fw_base.S ensures that only one HART calls fw_platform_init().

Regards,
Anup

Quoted 61 lines
Quoted 57 lines

Regards,
Anup

Quoted 53 lines
Quoted 53 lines

Regards,
Anup

Quoted 38 lines
platform/generic/starfive/jh7110.c new file +31 -0
+
+       coff = fdt_path_offset(fdt, "/chosen");
+       if (-1 < coff) {
+               val = fdt_getprop(fdt, coff, "boot-hart", &len);
+               if (val && len) {
+                       u32 selected_hartid = (u32) fdt32_to_cpu(*val);
+                       return (selected_hartid == hartid);
+               }
+       }
+
+       return TRUE;
+}
+
+static int starfive_jh7110_early_init(bool cold_boot,
+                                  const struct fdt_match *match) {
+       if (cold_boot)
+               hart_cold_booted = TRUE;
+
+       return 0;
+}
+
+static const struct fdt_match starfive_jh7110_match[] = {
+       { .compatible = "starfive,jh7110" },
+       { },
+};
+
+const struct platform_override starfive_jh7110 = {
+       .match_table = starfive_jh7110_match,
+       .early_init = starfive_jh7110_early_init,
+       .cold_boot_allowed = starfive_jh7110_cold_boot_allowed,
+};
platform/generic/starfive/objects.mk new file +0 -0
new file mode 100644
index 0000000..0b900fb

platform/generic/starfive/objects.mk line 4

Quoted 4 lines
platform/generic/starfive/objects.mk new file +4 -0
@@ -0,0 +1,6 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause #
+
+carray-platform_override_modules-

$(CONFIG_PLATFORM_STARFIVE_JH7110)

platform/generic/starfive/objects.mk line 6

Quoted 2 lines
platform/generic/starfive/objects.mk new file +2 -0
++= starfive_jh7110
+platform-objs-$(CONFIG_PLATFORM_STARFIVE_JH7110) +=

starfive/jh7110.o

Quoted 3 lines

--
2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi