summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJianjun Wang <jianjun.wang@mediatek.com>2022-03-22 15:26:52 +0800
committerPaul Fagerburg <pfagerburg@chromium.org>2022-03-29 15:41:30 +0000
commit41faa22c532def4093a65366764d12298c6a10d3 (patch)
treebab1e19cde50a07e1e04f1b81e52b30979f54b15
parent3a6ab474e0dbb92916d09fe3a8a7321cbe1511bf (diff)
soc/mediatek: Add early_init for passing data across stages
Add support for "early_init_data" region, which can be used to store data initialized in an early stage (such as bootblock), and retrieve it in later stages (such as ramstage). TEST=Build pass and boot up to kernel successfully via SSD on Dojo board, here is the SSD information in boot log: == NVME IDENTIFY CONTROLLER DATA == PCI VID : 0x15b7 PCI SSVID : 0x15b7 SN : 21517J440114 MN : WDC PC SN530 SDBPTPZ-256G-1006 RAB : 0x4 AERL : 0x7 SQES : 0x66 CQES : 0x44 NN : 0x1 Identified NVMe model WDC PC SN530 SDBPTPZ-256G-1006 BUG=b:178565024 BRANCH=cherry Signed-off-by: Jianjun Wang <jianjun.wang@mediatek.com> Change-Id: I01f91b7fe2cbe4f73b5c616bb7aae778dee27d9a Reviewed-on: https://review.coreboot.org/c/coreboot/+/63019 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Yu-Ping Wu <yupingso@google.com>
-rw-r--r--src/soc/mediatek/common/early_init.c52
-rw-r--r--src/soc/mediatek/common/include/soc/early_init.h26
2 files changed, 78 insertions, 0 deletions
diff --git a/src/soc/mediatek/common/early_init.c b/src/soc/mediatek/common/early_init.c
new file mode 100644
index 0000000000..329663c8c3
--- /dev/null
+++ b/src/soc/mediatek/common/early_init.c
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <assert.h>
+#include <soc/early_init.h>
+#include <stdlib.h>
+#include <string.h>
+
+static struct early_init_data *find_early_init(void)
+{
+ assert(sizeof(struct early_init_data) <= REGION_SIZE(early_init_data));
+ return (struct early_init_data *)_early_init_data;
+}
+
+void early_init_clear(void)
+{
+ struct early_init_data *data = find_early_init();
+
+ if (!data)
+ return;
+
+ memset(data, 0, sizeof(*data));
+}
+
+void early_init_save_time(enum early_init_type init_type)
+{
+ struct early_init_data *data = find_early_init();
+
+ if (!data)
+ return;
+
+ timer_monotonic_get(&data->init_time[init_type]);
+}
+
+uint64_t early_init_get_elapsed_time_us(enum early_init_type init_type)
+{
+ struct early_init_data *data = find_early_init();
+ struct mono_time cur_time;
+
+ if (!data)
+ return 0;
+
+ memset(&cur_time, 0, sizeof(cur_time));
+
+ /* If early init data was never saved */
+ if (!memcmp(&data->init_time[init_type], &cur_time, sizeof(cur_time)))
+ return 0;
+
+ timer_monotonic_get(&cur_time);
+
+ return mono_time_diff_microseconds(&data->init_time[init_type],
+ &cur_time);
+}
diff --git a/src/soc/mediatek/common/include/soc/early_init.h b/src/soc/mediatek/common/include/soc/early_init.h
new file mode 100644
index 0000000000..2811b0d69a
--- /dev/null
+++ b/src/soc/mediatek/common/include/soc/early_init.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef SOC_MEDIATEK_EARLY_INIT_H
+#define SOC_MEDIATEK_EARLY_INIT_H
+
+#include <soc/symbols.h>
+#include <stdint.h>
+#include <symbols.h>
+#include <timer.h>
+
+DECLARE_REGION(early_init_data);
+
+enum early_init_type {
+ EARLY_INIT_PCIE,
+ EARLY_INIT_MAX,
+};
+
+struct early_init_data {
+ struct mono_time init_time[EARLY_INIT_MAX];
+};
+
+void early_init_clear(void);
+void early_init_save_time(enum early_init_type init_type);
+uint64_t early_init_get_elapsed_time_us(enum early_init_type init_type);
+
+#endif /* SOC_MEDIATEK_EARLY_INIT_H */