summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2019-09-05 18:16:25 +0300
committerKyösti Mälkki <kyosti.malkki@gmail.com>2019-09-12 10:17:33 +0000
commit72e634fa73834987e5ec1a2b368af01bc59cab71 (patch)
tree180f508be83900e0cd43491ba77c564a983727ec /src
parent8dda419b3cb55b47970ed3dcd9f942910ace43ff (diff)
timestamps: Refactor CBMEM hook
Separate timestamp_sync_cache_to_cbmem() as it is only used with ENV_ROMSTAGE. Change-Id: Ibe18a5ecf09b2b87d8ee3e828728ad6a8a262206 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/35280 Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src')
-rw-r--r--src/lib/timestamp.c82
1 files changed, 44 insertions, 38 deletions
diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c
index bb5c114493..4983885195 100644
--- a/src/lib/timestamp.c
+++ b/src/lib/timestamp.c
@@ -214,46 +214,14 @@ void timestamp_init(uint64_t base)
timestamp_table_set(&ts_cache->table);
}
-static void timestamp_sync_cache_to_cbmem(int is_recovery)
+static void timestamp_sync_cache_to_cbmem(struct timestamp_table *ts_cbmem_table)
{
uint32_t i;
struct timestamp_table *ts_cache_table;
- struct timestamp_table *ts_cbmem_table;
-
- if (!timestamp_should_run())
- return;
-
- /* cbmem is being recovered. */
- if (is_recovery) {
- /* x86 resume path expects timestamps to be reset. */
- if (CONFIG(ARCH_ROMSTAGE_X86_32) && ENV_ROMSTAGE)
- ts_cbmem_table = timestamp_alloc_cbmem_table();
- else {
- /* Find existing table in cbmem. */
- ts_cbmem_table = cbmem_find(CBMEM_ID_TIMESTAMP);
- /* No existing timestamp table. */
- if (ts_cbmem_table == NULL)
- ts_cbmem_table = timestamp_alloc_cbmem_table();
- }
- } else
- /* First time sync. Add new table. */
- ts_cbmem_table = timestamp_alloc_cbmem_table();
-
- if (ts_cbmem_table == NULL) {
- printk(BIOS_ERR, "ERROR: No timestamp table allocated\n");
- timestamp_table_set(NULL);
- return;
- }
-
- /* Seed the timestamp tick frequency in ENV_PAYLOAD_LOADER. */
- if (ENV_PAYLOAD_LOADER)
- ts_cbmem_table->tick_freq_mhz = timestamp_tick_freq_mhz();
ts_cache_table = timestamp_table_get();
if (!ts_cache_table) {
- if (ENV_ROMSTAGE)
- printk(BIOS_ERR, "ERROR: No timestamp cache found\n");
- timestamp_table_set(ts_cbmem_table);
+ printk(BIOS_ERR, "ERROR: No timestamp cache found\n");
return;
}
@@ -290,10 +258,48 @@ static void timestamp_sync_cache_to_cbmem(int is_recovery)
ts_cbmem_table->base_time = ts_cache_table->base_time;
/* Cache no longer required. */
- timestamp_table_set(ts_cbmem_table);
ts_cache_table->num_entries = 0;
}
+static void timestamp_reinit(int is_recovery)
+{
+ struct timestamp_table *ts_cbmem_table;
+
+ if (!timestamp_should_run())
+ return;
+
+ /* cbmem is being recovered. */
+ if (is_recovery) {
+ /* x86 resume path expects timestamps to be reset. */
+ if (CONFIG(ARCH_ROMSTAGE_X86_32) && ENV_ROMSTAGE)
+ ts_cbmem_table = timestamp_alloc_cbmem_table();
+ else {
+ /* Find existing table in cbmem. */
+ ts_cbmem_table = cbmem_find(CBMEM_ID_TIMESTAMP);
+ /* No existing timestamp table. */
+ if (ts_cbmem_table == NULL)
+ ts_cbmem_table = timestamp_alloc_cbmem_table();
+ }
+ } else
+ /* First time sync. Add new table. */
+ ts_cbmem_table = timestamp_alloc_cbmem_table();
+
+ if (ts_cbmem_table == NULL) {
+ printk(BIOS_ERR, "ERROR: No timestamp table allocated\n");
+ timestamp_table_set(NULL);
+ return;
+ }
+
+ if (ENV_ROMSTAGE)
+ timestamp_sync_cache_to_cbmem(ts_cbmem_table);
+
+ /* Seed the timestamp tick frequency in ENV_PAYLOAD_LOADER. */
+ if (ENV_PAYLOAD_LOADER)
+ ts_cbmem_table->tick_freq_mhz = timestamp_tick_freq_mhz();
+
+ timestamp_table_set(ts_cbmem_table);
+}
+
void timestamp_rescale_table(uint16_t N, uint16_t M)
{
uint32_t i;
@@ -335,9 +341,9 @@ uint32_t get_us_since_boot(void)
return (timestamp_get() - ts->base_time) / ts->tick_freq_mhz;
}
-ROMSTAGE_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem)
-POSTCAR_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem)
-RAMSTAGE_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem)
+ROMSTAGE_CBMEM_INIT_HOOK(timestamp_reinit)
+POSTCAR_CBMEM_INIT_HOOK(timestamp_reinit)
+RAMSTAGE_CBMEM_INIT_HOOK(timestamp_reinit)
/* Provide default timestamp implementation using monotonic timer. */
uint64_t __weak timestamp_get(void)