1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2011 The ChromiumOS Authors.  All rights reserved.
4  *
5  * Modified from the coreboot version
6  */
7 
8 #include <bootstage.h>
9 #include <errno.h>
10 #include <asm/arch/timestamp.h>
11 #include <asm/cb_sysinfo.h>
12 #include <asm/u-boot-x86.h>
13 #include <linux/compiler.h>
14 
timestamp_init(void)15 void timestamp_init(void)
16 {
17 	timestamp_add_now(TS_U_BOOT_INITTED);
18 }
19 
timestamp_add(enum timestamp_id id,uint64_t ts_time)20 void timestamp_add(enum timestamp_id id, uint64_t ts_time)
21 {
22 	const struct sysinfo_t *info = cb_get_sysinfo();
23 	struct timestamp_table *ts_table = info->tstamp_table;
24 	struct timestamp_entry *tse;
25 
26 	if (!ts_table || (ts_table->num_entries == ts_table->max_entries))
27 		return;
28 
29 	tse = &ts_table->entries[ts_table->num_entries++];
30 	tse->entry_id = id;
31 	tse->entry_stamp = ts_time - ts_table->base_time;
32 }
33 
timestamp_add_now(enum timestamp_id id)34 void timestamp_add_now(enum timestamp_id id)
35 {
36 	timestamp_add(id, rdtsc());
37 }
38 
timestamp_add_to_bootstage(void)39 int timestamp_add_to_bootstage(void)
40 {
41 	const struct sysinfo_t *info = cb_get_sysinfo();
42 	const struct timestamp_table *ts_table = info->tstamp_table;
43 	uint i;
44 
45 	if (!ts_table)
46 		return -ENOENT;
47 
48 	for (i = 0; i < ts_table->num_entries; i++) {
49 		const struct timestamp_entry *tse = &ts_table->entries[i];
50 		const char *name = NULL;
51 
52 		switch (tse->entry_id) {
53 		case TS_START_ROMSTAGE:
54 			name = "start-romstage";
55 			break;
56 		case TS_BEFORE_INITRAM:
57 			name = "before-initram";
58 			break;
59 		case TS_DEVICE_INITIALIZE:
60 			name = "device-initialize";
61 			break;
62 		case TS_DEVICE_DONE:
63 			name = "device-done";
64 			break;
65 		case TS_SELFBOOT_JUMP:
66 			name = "selfboot-jump";
67 			break;
68 		}
69 		if (name) {
70 			bootstage_add_record(0, name, BOOTSTAGEF_ALLOC,
71 					     tse->entry_stamp /
72 							get_tbclk_mhz());
73 		}
74 	}
75 
76 	return 0;
77 }
78