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 <common.h>
9 #include <bootstage.h>
10 #include <asm/arch/timestamp.h>
11 #include <asm/cb_sysinfo.h>
12 #include <linux/compiler.h>
13 
14 static struct timestamp_table *ts_table  __section(".data");
15 
timestamp_init(void)16 void timestamp_init(void)
17 {
18 	timestamp_add_now(TS_U_BOOT_INITTED);
19 }
20 
timestamp_add(enum timestamp_id id,uint64_t ts_time)21 void timestamp_add(enum timestamp_id id, uint64_t ts_time)
22 {
23 	struct timestamp_entry *tse;
24 
25 	if (!ts_table || (ts_table->num_entries == ts_table->max_entries))
26 		return;
27 
28 	tse = &ts_table->entries[ts_table->num_entries++];
29 	tse->entry_id = id;
30 	tse->entry_stamp = ts_time - ts_table->base_time;
31 }
32 
timestamp_add_now(enum timestamp_id id)33 void timestamp_add_now(enum timestamp_id id)
34 {
35 	timestamp_add(id, rdtsc());
36 }
37 
timestamp_add_to_bootstage(void)38 int timestamp_add_to_bootstage(void)
39 {
40 	uint i;
41 
42 	if (!ts_table)
43 		return -1;
44 
45 	for (i = 0; i < ts_table->num_entries; i++) {
46 		struct timestamp_entry *tse = &ts_table->entries[i];
47 		const char *name = NULL;
48 
49 		switch (tse->entry_id) {
50 		case TS_START_ROMSTAGE:
51 			name = "start-romstage";
52 			break;
53 		case TS_BEFORE_INITRAM:
54 			name = "before-initram";
55 			break;
56 		case TS_DEVICE_INITIALIZE:
57 			name = "device-initialize";
58 			break;
59 		case TS_DEVICE_DONE:
60 			name = "device-done";
61 			break;
62 		case TS_SELFBOOT_JUMP:
63 			name = "selfboot-jump";
64 			break;
65 		}
66 		if (name) {
67 			bootstage_add_record(0, name, BOOTSTAGEF_ALLOC,
68 					     tse->entry_stamp /
69 							get_tbclk_mhz());
70 		}
71 	}
72 
73 	return 0;
74 }
75