Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 3 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 4 | #include <assert.h> |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 5 | #include <stddef.h> |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 6 | #include <stdint.h> |
| 7 | #include <console/console.h> |
| 8 | #include <cbmem.h> |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 9 | #include <symbols.h> |
Aaron Durbin | 2daadf8 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 10 | #include <timer.h> |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 11 | #include <timestamp.h> |
Kyösti Mälkki | 5a5c886 | 2014-01-26 14:41:54 +0200 | [diff] [blame] | 12 | #include <smp/node.h> |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 13 | |
Raul E Rangel | b3e0220 | 2018-05-11 11:08:08 -0600 | [diff] [blame] | 14 | #define MAX_TIMESTAMPS 192 |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 15 | |
Julius Werner | 8c09377 | 2016-02-09 16:09:15 -0800 | [diff] [blame] | 16 | DECLARE_OPTIONAL_REGION(timestamp); |
| 17 | |
Kyösti Mälkki | 8b93689 | 2019-09-12 13:45:15 +0300 | [diff] [blame] | 18 | /* This points to the active timestamp_table and can change within a stage |
Kyösti Mälkki | 3dd23a5 | 2019-08-22 15:06:50 +0300 | [diff] [blame] | 19 | as CBMEM comes available. */ |
Arthur Heymans | 1a71163 | 2019-11-20 20:38:29 +0100 | [diff] [blame] | 20 | static struct timestamp_table *glob_ts_table; |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 21 | |
Kyösti Mälkki | 3c559e7 | 2019-09-07 13:25:47 +0300 | [diff] [blame] | 22 | static void timestamp_cache_init(struct timestamp_table *ts_cache, |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 23 | uint64_t base) |
| 24 | { |
Kyösti Mälkki | 3c559e7 | 2019-09-07 13:25:47 +0300 | [diff] [blame] | 25 | ts_cache->num_entries = 0; |
Kyösti Mälkki | 3c559e7 | 2019-09-07 13:25:47 +0300 | [diff] [blame] | 26 | ts_cache->base_time = base; |
Kyösti Mälkki | 8b93689 | 2019-09-12 13:45:15 +0300 | [diff] [blame] | 27 | ts_cache->max_entries = (REGION_SIZE(timestamp) - |
| 28 | offsetof(struct timestamp_table, entries)) |
| 29 | / sizeof(struct timestamp_entry); |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 30 | } |
| 31 | |
Kyösti Mälkki | 3c559e7 | 2019-09-07 13:25:47 +0300 | [diff] [blame] | 32 | static struct timestamp_table *timestamp_cache_get(void) |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 33 | { |
Kyösti Mälkki | 3c559e7 | 2019-09-07 13:25:47 +0300 | [diff] [blame] | 34 | struct timestamp_table *ts_cache = NULL; |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 35 | |
Kyösti Mälkki | 8b93689 | 2019-09-12 13:45:15 +0300 | [diff] [blame] | 36 | if (!ENV_ROMSTAGE_OR_BEFORE) |
| 37 | return NULL; |
| 38 | |
| 39 | if (REGION_SIZE(timestamp) < sizeof(*ts_cache)) { |
| 40 | BUG(); |
| 41 | } else { |
Kyösti Mälkki | 3dd23a5 | 2019-08-22 15:06:50 +0300 | [diff] [blame] | 42 | ts_cache = (void *)_timestamp; |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 45 | return ts_cache; |
| 46 | } |
| 47 | |
| 48 | static struct timestamp_table *timestamp_alloc_cbmem_table(void) |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 49 | { |
Lee Leahy | b2d834a | 2017-03-08 16:52:22 -0800 | [diff] [blame] | 50 | struct timestamp_table *tst; |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 51 | |
| 52 | tst = cbmem_add(CBMEM_ID_TIMESTAMP, |
| 53 | sizeof(struct timestamp_table) + |
| 54 | MAX_TIMESTAMPS * sizeof(struct timestamp_entry)); |
| 55 | |
Kyösti Mälkki | e034417 | 2015-05-26 06:23:02 +0300 | [diff] [blame] | 56 | if (!tst) |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 57 | return NULL; |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 58 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 59 | tst->base_time = 0; |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 60 | tst->max_entries = MAX_TIMESTAMPS; |
| 61 | tst->num_entries = 0; |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 62 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 63 | return tst; |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Aaron Durbin | 2daadf8 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 66 | /* Determine if one should proceed into timestamp code. This is for protecting |
| 67 | * systems that have multiple processors running in romstage -- namely AMD |
| 68 | * based x86 platforms. */ |
| 69 | static int timestamp_should_run(void) |
| 70 | { |
Subrata Banik | 42c44c2 | 2019-05-15 20:27:04 +0530 | [diff] [blame] | 71 | /* |
| 72 | * Only check boot_cpu() in other stages than |
| 73 | * ENV_PAYLOAD_LOADER on x86. |
| 74 | */ |
| 75 | if ((!ENV_PAYLOAD_LOADER && CONFIG(ARCH_X86)) && !boot_cpu()) |
Aaron Durbin | 2daadf8 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 76 | return 0; |
| 77 | |
| 78 | return 1; |
| 79 | } |
| 80 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 81 | static struct timestamp_table *timestamp_table_get(void) |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 82 | { |
Arthur Heymans | 1a71163 | 2019-11-20 20:38:29 +0100 | [diff] [blame] | 83 | if (glob_ts_table) |
| 84 | return glob_ts_table; |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 85 | |
Arthur Heymans | 1a71163 | 2019-11-20 20:38:29 +0100 | [diff] [blame] | 86 | glob_ts_table = timestamp_cache_get(); |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 87 | |
Arthur Heymans | 1a71163 | 2019-11-20 20:38:29 +0100 | [diff] [blame] | 88 | return glob_ts_table; |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 89 | } |
| 90 | |
Kyösti Mälkki | 3dd23a5 | 2019-08-22 15:06:50 +0300 | [diff] [blame] | 91 | static void timestamp_table_set(struct timestamp_table *ts) |
| 92 | { |
Arthur Heymans | 1a71163 | 2019-11-20 20:38:29 +0100 | [diff] [blame] | 93 | glob_ts_table = ts; |
Kyösti Mälkki | 3dd23a5 | 2019-08-22 15:06:50 +0300 | [diff] [blame] | 94 | } |
| 95 | |
Martin Roth | b22bbe2 | 2018-03-07 15:32:16 -0700 | [diff] [blame] | 96 | static const char *timestamp_name(enum timestamp_id id) |
| 97 | { |
| 98 | int i; |
| 99 | |
| 100 | for (i = 0; i < ARRAY_SIZE(timestamp_ids); i++) { |
| 101 | if (timestamp_ids[i].id == id) |
| 102 | return timestamp_ids[i].name; |
| 103 | } |
| 104 | |
| 105 | return "Unknown timestamp ID"; |
| 106 | } |
| 107 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 108 | static void timestamp_add_table_entry(struct timestamp_table *ts_table, |
| 109 | enum timestamp_id id, uint64_t ts_time) |
| 110 | { |
| 111 | struct timestamp_entry *tse; |
| 112 | |
Ben Gardner | f5fd4c9 | 2015-11-20 13:25:25 -0600 | [diff] [blame] | 113 | if (ts_table->num_entries >= ts_table->max_entries) |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 114 | return; |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 115 | |
| 116 | tse = &ts_table->entries[ts_table->num_entries++]; |
| 117 | tse->entry_id = id; |
Kyösti Mälkki | d548edd | 2020-01-09 08:41:46 +0200 | [diff] [blame] | 118 | tse->entry_stamp = ts_time; |
Ben Gardner | f5fd4c9 | 2015-11-20 13:25:25 -0600 | [diff] [blame] | 119 | |
| 120 | if (ts_table->num_entries == ts_table->max_entries) |
| 121 | printk(BIOS_ERR, "ERROR: Timestamp table full\n"); |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 124 | void timestamp_add(enum timestamp_id id, uint64_t ts_time) |
| 125 | { |
| 126 | struct timestamp_table *ts_table; |
| 127 | |
Kyösti Mälkki | 187e4c4 | 2019-02-20 17:38:45 +0200 | [diff] [blame] | 128 | if (!timestamp_should_run()) |
| 129 | return; |
| 130 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 131 | ts_table = timestamp_table_get(); |
| 132 | |
| 133 | if (!ts_table) { |
| 134 | printk(BIOS_ERR, "ERROR: No timestamp table found\n"); |
| 135 | return; |
| 136 | } |
| 137 | |
Kyösti Mälkki | d548edd | 2020-01-09 08:41:46 +0200 | [diff] [blame] | 138 | ts_time -= ts_table->base_time; |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 139 | timestamp_add_table_entry(ts_table, id, ts_time); |
Kyösti Mälkki | 8b93cb7 | 2020-01-09 08:41:46 +0200 | [diff] [blame] | 140 | |
| 141 | if (CONFIG(TIMESTAMPS_ON_CONSOLE)) |
| 142 | printk(BIOS_INFO, "Timestamp - %s: %llu\n", timestamp_name(id), ts_time); |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 143 | } |
| 144 | |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 145 | void timestamp_add_now(enum timestamp_id id) |
| 146 | { |
Stefan Reinauer | 3a6550d | 2013-08-01 13:31:44 -0700 | [diff] [blame] | 147 | timestamp_add(id, timestamp_get()); |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 148 | } |
Stefan Reinauer | 4221a19 | 2012-10-15 15:23:20 -0700 | [diff] [blame] | 149 | |
Stefan Reinauer | 3a6550d | 2013-08-01 13:31:44 -0700 | [diff] [blame] | 150 | void timestamp_init(uint64_t base) |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 151 | { |
Kyösti Mälkki | 3c559e7 | 2019-09-07 13:25:47 +0300 | [diff] [blame] | 152 | struct timestamp_table *ts_cache; |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 153 | |
Kyösti Mälkki | 3dd23a5 | 2019-08-22 15:06:50 +0300 | [diff] [blame] | 154 | assert(ENV_ROMSTAGE_OR_BEFORE); |
| 155 | |
Aaron Durbin | 2daadf8 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 156 | if (!timestamp_should_run()) |
Kyösti Mälkki | f56ff90 | 2013-09-08 13:10:28 +0300 | [diff] [blame] | 157 | return; |
| 158 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 159 | ts_cache = timestamp_cache_get(); |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 160 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 161 | if (!ts_cache) { |
| 162 | printk(BIOS_ERR, "ERROR: No timestamp cache to init\n"); |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 163 | return; |
| 164 | } |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 165 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 166 | timestamp_cache_init(ts_cache, base); |
Kyösti Mälkki | 3c559e7 | 2019-09-07 13:25:47 +0300 | [diff] [blame] | 167 | timestamp_table_set(ts_cache); |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 168 | } |
| 169 | |
Kyösti Mälkki | 72e634f | 2019-09-05 18:16:25 +0300 | [diff] [blame] | 170 | static void timestamp_sync_cache_to_cbmem(struct timestamp_table *ts_cbmem_table) |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 171 | { |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 172 | uint32_t i; |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 173 | struct timestamp_table *ts_cache_table; |
Kyösti Mälkki | 3dd23a5 | 2019-08-22 15:06:50 +0300 | [diff] [blame] | 174 | |
| 175 | ts_cache_table = timestamp_table_get(); |
| 176 | if (!ts_cache_table) { |
Kyösti Mälkki | 72e634f | 2019-09-05 18:16:25 +0300 | [diff] [blame] | 177 | printk(BIOS_ERR, "ERROR: No timestamp cache found\n"); |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 178 | return; |
| 179 | } |
| 180 | |
| 181 | /* |
| 182 | * There's no need to worry about the base_time fields being out of |
Kyösti Mälkki | 513a1a8 | 2018-06-03 12:29:50 +0300 | [diff] [blame] | 183 | * sync because only the following configuration is used/supported: |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 184 | * |
Kyösti Mälkki | 513a1a8 | 2018-06-03 12:29:50 +0300 | [diff] [blame] | 185 | * Timestamps get initialized before ramstage, which implies |
| 186 | * CBMEM initialization in romstage. |
Julius Werner | 8c09377 | 2016-02-09 16:09:15 -0800 | [diff] [blame] | 187 | * This requires the board to define a TIMESTAMP() region in its |
| 188 | * memlayout.ld (default on x86). The base_time from timestamp_init() |
| 189 | * (usually called from bootblock.c on most non-x86 boards) persists |
| 190 | * in that region until it gets synced to CBMEM in romstage. |
| 191 | * In ramstage, the BSS cache's base_time will be 0 until the second |
| 192 | * sync, which will adjust the timestamps in there to the correct |
| 193 | * base_time (from CBMEM) with the timestamp_add_table_entry() below. |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 194 | * |
Julius Werner | 8c09377 | 2016-02-09 16:09:15 -0800 | [diff] [blame] | 195 | * If you try to initialize timestamps before ramstage but don't define |
| 196 | * a TIMESTAMP region, all operations will fail (safely), and coreboot |
Kyösti Mälkki | d548edd | 2020-01-09 08:41:46 +0200 | [diff] [blame] | 197 | * will behave as if timestamps collection was disabled. |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 198 | */ |
Kyösti Mälkki | 3dd23a5 | 2019-08-22 15:06:50 +0300 | [diff] [blame] | 199 | |
Kyösti Mälkki | d548edd | 2020-01-09 08:41:46 +0200 | [diff] [blame] | 200 | /* Inherit cache base_time. */ |
| 201 | ts_cbmem_table->base_time = ts_cache_table->base_time; |
| 202 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 203 | for (i = 0; i < ts_cache_table->num_entries; i++) { |
| 204 | struct timestamp_entry *tse = &ts_cache_table->entries[i]; |
| 205 | timestamp_add_table_entry(ts_cbmem_table, tse->entry_id, |
| 206 | tse->entry_stamp); |
| 207 | } |
| 208 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 209 | /* Cache no longer required. */ |
| 210 | ts_cache_table->num_entries = 0; |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 211 | } |
Kyösti Mälkki | cbf5bdf | 2013-09-10 00:07:21 +0300 | [diff] [blame] | 212 | |
Kyösti Mälkki | 72e634f | 2019-09-05 18:16:25 +0300 | [diff] [blame] | 213 | static void timestamp_reinit(int is_recovery) |
| 214 | { |
| 215 | struct timestamp_table *ts_cbmem_table; |
| 216 | |
| 217 | if (!timestamp_should_run()) |
| 218 | return; |
| 219 | |
Kyösti Mälkki | b6b13c9 | 2019-09-12 12:58:50 +0300 | [diff] [blame] | 220 | /* First time into romstage we make a clean new table. For platforms that travel |
| 221 | through this path on resume, ARCH_X86 S3, timestamps are also reset. */ |
| 222 | if (ENV_ROMSTAGE) { |
Kyösti Mälkki | 72e634f | 2019-09-05 18:16:25 +0300 | [diff] [blame] | 223 | ts_cbmem_table = timestamp_alloc_cbmem_table(); |
Kyösti Mälkki | b6b13c9 | 2019-09-12 12:58:50 +0300 | [diff] [blame] | 224 | } else { |
| 225 | /* Find existing table in cbmem. */ |
| 226 | ts_cbmem_table = cbmem_find(CBMEM_ID_TIMESTAMP); |
| 227 | } |
Kyösti Mälkki | 72e634f | 2019-09-05 18:16:25 +0300 | [diff] [blame] | 228 | |
| 229 | if (ts_cbmem_table == NULL) { |
| 230 | printk(BIOS_ERR, "ERROR: No timestamp table allocated\n"); |
| 231 | timestamp_table_set(NULL); |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | if (ENV_ROMSTAGE) |
| 236 | timestamp_sync_cache_to_cbmem(ts_cbmem_table); |
| 237 | |
| 238 | /* Seed the timestamp tick frequency in ENV_PAYLOAD_LOADER. */ |
| 239 | if (ENV_PAYLOAD_LOADER) |
| 240 | ts_cbmem_table->tick_freq_mhz = timestamp_tick_freq_mhz(); |
| 241 | |
| 242 | timestamp_table_set(ts_cbmem_table); |
| 243 | } |
| 244 | |
Kyösti Mälkki | 806ea08b | 2017-07-15 20:42:20 +0300 | [diff] [blame] | 245 | void timestamp_rescale_table(uint16_t N, uint16_t M) |
| 246 | { |
| 247 | uint32_t i; |
| 248 | struct timestamp_table *ts_table; |
| 249 | |
| 250 | if (!timestamp_should_run()) |
| 251 | return; |
| 252 | |
| 253 | if (N == 0 || M == 0) |
| 254 | return; |
| 255 | |
| 256 | ts_table = timestamp_table_get(); |
| 257 | |
| 258 | /* No timestamp table found */ |
| 259 | if (ts_table == NULL) { |
| 260 | printk(BIOS_ERR, "ERROR: No timestamp table found\n"); |
| 261 | return; |
| 262 | } |
| 263 | |
| 264 | ts_table->base_time /= M; |
| 265 | ts_table->base_time *= N; |
| 266 | for (i = 0; i < ts_table->num_entries; i++) { |
| 267 | struct timestamp_entry *tse = &ts_table->entries[i]; |
| 268 | tse->entry_stamp /= M; |
| 269 | tse->entry_stamp *= N; |
| 270 | } |
| 271 | } |
| 272 | |
Werner Zeh | 35cceb8 | 2017-09-12 07:42:54 +0200 | [diff] [blame] | 273 | /* |
| 274 | * Get the time in microseconds since boot (or more precise: since timestamp |
| 275 | * table was initialized). |
| 276 | */ |
| 277 | uint32_t get_us_since_boot(void) |
| 278 | { |
| 279 | struct timestamp_table *ts = timestamp_table_get(); |
| 280 | |
| 281 | if (ts == NULL || ts->tick_freq_mhz == 0) |
| 282 | return 0; |
| 283 | return (timestamp_get() - ts->base_time) / ts->tick_freq_mhz; |
| 284 | } |
| 285 | |
Kyösti Mälkki | 72e634f | 2019-09-05 18:16:25 +0300 | [diff] [blame] | 286 | ROMSTAGE_CBMEM_INIT_HOOK(timestamp_reinit) |
| 287 | POSTCAR_CBMEM_INIT_HOOK(timestamp_reinit) |
| 288 | RAMSTAGE_CBMEM_INIT_HOOK(timestamp_reinit) |
Aaron Durbin | 9e80e27 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 289 | |
| 290 | /* Provide default timestamp implementation using monotonic timer. */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 291 | uint64_t __weak timestamp_get(void) |
Aaron Durbin | 9e80e27 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 292 | { |
| 293 | struct mono_time t1, t2; |
| 294 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 295 | if (!CONFIG(HAVE_MONOTONIC_TIMER)) |
Aaron Durbin | 7aafe53 | 2015-05-07 11:32:30 -0500 | [diff] [blame] | 296 | return 0; |
| 297 | |
Aaron Durbin | 9e80e27 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 298 | mono_time_set_usecs(&t1, 0); |
| 299 | timer_monotonic_get(&t2); |
| 300 | |
| 301 | return mono_time_diff_microseconds(&t1, &t2); |
| 302 | } |
Aaron Durbin | c49014e | 2015-08-30 21:19:55 -0500 | [diff] [blame] | 303 | |
| 304 | /* Like timestamp_get() above this matches up with microsecond granularity. */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 305 | int __weak timestamp_tick_freq_mhz(void) |
Aaron Durbin | c49014e | 2015-08-30 21:19:55 -0500 | [diff] [blame] | 306 | { |
| 307 | return 1; |
| 308 | } |