2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
6 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/timestamp.h>
11 #include <asm/arch/sysinfo.h>
12 #include <linux/compiler.h>
14 struct timestamp_entry {
19 struct timestamp_table {
23 struct timestamp_entry entries[0]; /* Variable number of entries */
26 static struct timestamp_table *ts_table __attribute__((section(".data")));
28 void timestamp_init(void)
30 #ifdef CONFIG_SYS_X86_TSC_TIMER
34 ts_table = lib_sysinfo.tstamp_table;
35 #ifdef CONFIG_SYS_X86_TSC_TIMER
37 * If coreboot is built with CONFIG_COLLECT_TIMESTAMPS, use the value
38 * of base_time in coreboot's timestamp table as our timer base,
39 * otherwise TSC counter value will be used.
41 * Sometimes even coreboot is built with CONFIG_COLLECT_TIMESTAMPS,
42 * the value of base_time in the timestamp table is still zero, so
43 * we must exclude this case too (this is currently seen on booting
46 if (ts_table && ts_table->base_time)
47 base_time = ts_table->base_time;
50 timer_set_base(base_time);
52 timestamp_add_now(TS_U_BOOT_INITTED);
55 void timestamp_add(enum timestamp_id id, uint64_t ts_time)
57 struct timestamp_entry *tse;
59 if (!ts_table || (ts_table->num_entries == ts_table->max_entries))
62 tse = &ts_table->entries[ts_table->num_entries++];
64 tse->entry_stamp = ts_time - ts_table->base_time;
67 void timestamp_add_now(enum timestamp_id id)
69 timestamp_add(id, rdtsc());
72 int timestamp_add_to_bootstage(void)
79 for (i = 0; i < ts_table->num_entries; i++) {
80 struct timestamp_entry *tse = &ts_table->entries[i];
81 const char *name = NULL;
83 switch (tse->entry_id) {
84 case TS_START_ROMSTAGE:
85 name = "start-romstage";
87 case TS_BEFORE_INITRAM:
88 name = "before-initram";
90 case TS_DEVICE_INITIALIZE:
91 name = "device-initialize";
96 case TS_SELFBOOT_JUMP:
97 name = "selfboot-jump";
101 bootstage_add_record(0, name, BOOTSTAGEF_ALLOC,