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