Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 16 | #include <assert.h> |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 17 | #include <stddef.h> |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 18 | #include <stdint.h> |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 19 | #include <compiler.h> |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 20 | #include <console/console.h> |
| 21 | #include <cbmem.h> |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 22 | #include <symbols.h> |
Aaron Durbin | 2daadf8 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 23 | #include <timer.h> |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 24 | #include <timestamp.h> |
Stefan Reinauer | fd4f413 | 2013-06-19 12:25:44 -0700 | [diff] [blame] | 25 | #include <arch/early_variables.h> |
Aaron Durbin | 2daadf8 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 26 | #include <rules.h> |
Kyösti Mälkki | 5a5c886 | 2014-01-26 14:41:54 +0200 | [diff] [blame] | 27 | #include <smp/node.h> |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 28 | |
Julius Werner | 69d20c4 | 2016-02-08 19:48:11 -0800 | [diff] [blame] | 29 | #define MAX_TIMESTAMPS 84 |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 30 | |
Julius Werner | 85b1aad | 2016-08-19 15:17:42 -0700 | [diff] [blame] | 31 | /* When changing this number, adjust TIMESTAMP() size ASSERT() in memlayout.h */ |
Julius Werner | 69d20c4 | 2016-02-08 19:48:11 -0800 | [diff] [blame] | 32 | #define MAX_BSS_TIMESTAMP_CACHE 16 |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 33 | |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 34 | struct __packed timestamp_cache { |
Aaron Durbin | bd1499d | 2015-07-10 01:51:14 -0500 | [diff] [blame] | 35 | uint32_t cache_state; |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 36 | struct timestamp_table table; |
| 37 | /* The struct timestamp_table has a 0 length array as its last field. |
| 38 | * The following 'entries' array serves as the storage space for the |
Julius Werner | 69d20c4 | 2016-02-08 19:48:11 -0800 | [diff] [blame] | 39 | * cache when allocated in the BSS. */ |
| 40 | struct timestamp_entry entries[MAX_BSS_TIMESTAMP_CACHE]; |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 41 | }; |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 42 | |
Julius Werner | 8c09377 | 2016-02-09 16:09:15 -0800 | [diff] [blame] | 43 | DECLARE_OPTIONAL_REGION(timestamp); |
| 44 | |
| 45 | #if defined(__PRE_RAM__) |
| 46 | #define USE_TIMESTAMP_REGION (_timestamp_size > 0) |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 47 | #else |
| 48 | #define USE_TIMESTAMP_REGION 0 |
| 49 | #endif |
| 50 | |
| 51 | /* The cache location will sit in BSS when in ramstage. */ |
| 52 | #define TIMESTAMP_CACHE_IN_BSS ENV_RAMSTAGE |
| 53 | |
Furquan Shaikh | e85de02 | 2016-08-02 11:19:53 -0700 | [diff] [blame] | 54 | #define HAS_CBMEM (ENV_ROMSTAGE || ENV_RAMSTAGE || ENV_POSTCAR) |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 55 | |
| 56 | /* Storage of cache entries during ramstage prior to cbmem coming online. */ |
| 57 | static struct timestamp_cache timestamp_cache; |
| 58 | |
| 59 | enum { |
| 60 | TIMESTAMP_CACHE_UNINITIALIZED = 0, |
| 61 | TIMESTAMP_CACHE_INITIALIZED, |
| 62 | TIMESTAMP_CACHE_NOT_NEEDED, |
| 63 | }; |
| 64 | |
| 65 | static void timestamp_cache_init(struct timestamp_cache *ts_cache, |
| 66 | uint64_t base) |
| 67 | { |
| 68 | ts_cache->table.num_entries = 0; |
Julius Werner | 69d20c4 | 2016-02-08 19:48:11 -0800 | [diff] [blame] | 69 | ts_cache->table.max_entries = MAX_BSS_TIMESTAMP_CACHE; |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 70 | ts_cache->table.base_time = base; |
| 71 | ts_cache->cache_state = TIMESTAMP_CACHE_INITIALIZED; |
Julius Werner | 69d20c4 | 2016-02-08 19:48:11 -0800 | [diff] [blame] | 72 | |
| 73 | if (USE_TIMESTAMP_REGION) |
| 74 | ts_cache->table.max_entries = (_timestamp_size - |
| 75 | offsetof(struct timestamp_cache, entries)) |
| 76 | / sizeof(struct timestamp_entry); |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static struct timestamp_cache *timestamp_cache_get(void) |
| 80 | { |
| 81 | struct timestamp_cache *ts_cache = NULL; |
| 82 | |
| 83 | if (TIMESTAMP_CACHE_IN_BSS) { |
| 84 | ts_cache = ×tamp_cache; |
| 85 | } else if (USE_TIMESTAMP_REGION) { |
| 86 | if (_timestamp_size < sizeof(*ts_cache)) |
| 87 | BUG(); |
| 88 | ts_cache = car_get_var_ptr((void *)_timestamp); |
| 89 | } |
| 90 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 91 | return ts_cache; |
| 92 | } |
| 93 | |
| 94 | static struct timestamp_table *timestamp_alloc_cbmem_table(void) |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 95 | { |
Lee Leahy | b2d834a | 2017-03-08 16:52:22 -0800 | [diff] [blame] | 96 | struct timestamp_table *tst; |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 97 | |
| 98 | tst = cbmem_add(CBMEM_ID_TIMESTAMP, |
| 99 | sizeof(struct timestamp_table) + |
| 100 | MAX_TIMESTAMPS * sizeof(struct timestamp_entry)); |
| 101 | |
Kyösti Mälkki | e034417 | 2015-05-26 06:23:02 +0300 | [diff] [blame] | 102 | if (!tst) |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 103 | return NULL; |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 104 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 105 | tst->base_time = 0; |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 106 | tst->max_entries = MAX_TIMESTAMPS; |
| 107 | tst->num_entries = 0; |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 108 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 109 | return tst; |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Aaron Durbin | 2daadf8 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 112 | /* Determine if one should proceed into timestamp code. This is for protecting |
| 113 | * systems that have multiple processors running in romstage -- namely AMD |
| 114 | * based x86 platforms. */ |
| 115 | static int timestamp_should_run(void) |
| 116 | { |
| 117 | /* Only check boot_cpu() in other stages than ramstage on x86. */ |
| 118 | if ((!ENV_RAMSTAGE && IS_ENABLED(CONFIG_ARCH_X86)) && !boot_cpu()) |
| 119 | return 0; |
| 120 | |
| 121 | return 1; |
| 122 | } |
| 123 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 124 | static struct timestamp_table *timestamp_table_get(void) |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 125 | { |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 126 | MAYBE_STATIC struct timestamp_table *ts_table = NULL; |
| 127 | struct timestamp_cache *ts_cache; |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 128 | |
Aaron Durbin | 2daadf8 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 129 | if (!timestamp_should_run()) |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 130 | return NULL; |
Kyösti Mälkki | f56ff90 | 2013-09-08 13:10:28 +0300 | [diff] [blame] | 131 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 132 | if (ts_table != NULL) |
| 133 | return ts_table; |
| 134 | |
| 135 | ts_cache = timestamp_cache_get(); |
| 136 | |
| 137 | if (ts_cache == NULL) { |
| 138 | if (HAS_CBMEM) |
| 139 | ts_table = cbmem_find(CBMEM_ID_TIMESTAMP); |
| 140 | return ts_table; |
| 141 | } |
| 142 | |
| 143 | /* Cache is required. */ |
| 144 | if (ts_cache->cache_state != TIMESTAMP_CACHE_NOT_NEEDED) |
| 145 | return &ts_cache->table; |
| 146 | |
| 147 | /* Cache shouldn't be used but there's no backing store. */ |
| 148 | if (!HAS_CBMEM) |
| 149 | return NULL; |
| 150 | |
| 151 | ts_table = cbmem_find(CBMEM_ID_TIMESTAMP); |
| 152 | |
| 153 | return ts_table; |
| 154 | } |
| 155 | |
| 156 | static void timestamp_add_table_entry(struct timestamp_table *ts_table, |
| 157 | enum timestamp_id id, uint64_t ts_time) |
| 158 | { |
| 159 | struct timestamp_entry *tse; |
| 160 | |
Ben Gardner | f5fd4c9 | 2015-11-20 13:25:25 -0600 | [diff] [blame] | 161 | if (ts_table->num_entries >= ts_table->max_entries) |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 162 | return; |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 163 | |
| 164 | tse = &ts_table->entries[ts_table->num_entries++]; |
| 165 | tse->entry_id = id; |
Stefan Reinauer | 3a6550d | 2013-08-01 13:31:44 -0700 | [diff] [blame] | 166 | tse->entry_stamp = ts_time - ts_table->base_time; |
Ben Gardner | f5fd4c9 | 2015-11-20 13:25:25 -0600 | [diff] [blame] | 167 | |
| 168 | if (ts_table->num_entries == ts_table->max_entries) |
| 169 | printk(BIOS_ERR, "ERROR: Timestamp table full\n"); |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 172 | void timestamp_add(enum timestamp_id id, uint64_t ts_time) |
| 173 | { |
| 174 | struct timestamp_table *ts_table; |
| 175 | |
| 176 | ts_table = timestamp_table_get(); |
| 177 | |
| 178 | if (!ts_table) { |
| 179 | printk(BIOS_ERR, "ERROR: No timestamp table found\n"); |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | timestamp_add_table_entry(ts_table, id, ts_time); |
| 184 | } |
| 185 | |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 186 | void timestamp_add_now(enum timestamp_id id) |
| 187 | { |
Stefan Reinauer | 3a6550d | 2013-08-01 13:31:44 -0700 | [diff] [blame] | 188 | timestamp_add(id, timestamp_get()); |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 189 | } |
Stefan Reinauer | 4221a19 | 2012-10-15 15:23:20 -0700 | [diff] [blame] | 190 | |
Stefan Reinauer | 3a6550d | 2013-08-01 13:31:44 -0700 | [diff] [blame] | 191 | void timestamp_init(uint64_t base) |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 192 | { |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 193 | struct timestamp_cache *ts_cache; |
| 194 | |
Aaron Durbin | 2daadf8 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 195 | if (!timestamp_should_run()) |
Kyösti Mälkki | f56ff90 | 2013-09-08 13:10:28 +0300 | [diff] [blame] | 196 | return; |
| 197 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 198 | ts_cache = timestamp_cache_get(); |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 199 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 200 | if (!ts_cache) { |
| 201 | printk(BIOS_ERR, "ERROR: No timestamp cache to init\n"); |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 202 | return; |
| 203 | } |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 204 | |
Aaron Durbin | bd1499d | 2015-07-10 01:51:14 -0500 | [diff] [blame] | 205 | /* In the EARLY_CBMEM_INIT case timestamps could have already been |
| 206 | * recovered. In those circumstances honor the cache which sits in BSS |
| 207 | * as it has already been initialized. */ |
Aaron Durbin | 2a983bd | 2015-07-11 13:36:01 -0500 | [diff] [blame] | 208 | if (ENV_RAMSTAGE && IS_ENABLED(CONFIG_EARLY_CBMEM_INIT) && |
Aaron Durbin | bd1499d | 2015-07-10 01:51:14 -0500 | [diff] [blame] | 209 | ts_cache->cache_state != TIMESTAMP_CACHE_UNINITIALIZED) |
| 210 | return; |
| 211 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 212 | timestamp_cache_init(ts_cache, base); |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 213 | } |
| 214 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 215 | static void timestamp_sync_cache_to_cbmem(int is_recovery) |
Kyösti Mälkki | b766b1c | 2013-09-07 17:26:08 +0300 | [diff] [blame] | 216 | { |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 217 | uint32_t i; |
| 218 | struct timestamp_cache *ts_cache; |
| 219 | struct timestamp_table *ts_cache_table; |
| 220 | struct timestamp_table *ts_cbmem_table = NULL; |
| 221 | |
Aaron Durbin | 2daadf8 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 222 | if (!timestamp_should_run()) |
Kyösti Mälkki | f56ff90 | 2013-09-08 13:10:28 +0300 | [diff] [blame] | 223 | return; |
| 224 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 225 | ts_cache = timestamp_cache_get(); |
| 226 | |
| 227 | /* No timestamp cache found */ |
| 228 | if (ts_cache == NULL) { |
| 229 | printk(BIOS_ERR, "ERROR: No timestamp cache found\n"); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | ts_cache_table = &ts_cache->table; |
| 234 | |
| 235 | /* cbmem is being recovered. */ |
| 236 | if (is_recovery) { |
| 237 | /* x86 resume path expects timestamps to be reset. */ |
| 238 | if (IS_ENABLED(CONFIG_ARCH_ROMSTAGE_X86_32) && ENV_ROMSTAGE) |
| 239 | ts_cbmem_table = timestamp_alloc_cbmem_table(); |
| 240 | else { |
| 241 | /* Find existing table in cbmem. */ |
| 242 | ts_cbmem_table = cbmem_find(CBMEM_ID_TIMESTAMP); |
| 243 | /* No existing timestamp table. */ |
| 244 | if (ts_cbmem_table == NULL) |
| 245 | ts_cbmem_table = timestamp_alloc_cbmem_table(); |
| 246 | } |
| 247 | } else |
| 248 | /* First time sync. Add new table. */ |
| 249 | ts_cbmem_table = timestamp_alloc_cbmem_table(); |
| 250 | |
| 251 | if (ts_cbmem_table == NULL) { |
| 252 | printk(BIOS_ERR, "ERROR: No timestamp table allocated\n"); |
| 253 | return; |
| 254 | } |
| 255 | |
| 256 | /* |
| 257 | * There's no need to worry about the base_time fields being out of |
Julius Werner | 8c09377 | 2016-02-09 16:09:15 -0800 | [diff] [blame] | 258 | * sync because only the following configurations are used/supported: |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 259 | * |
Julius Werner | 8c09377 | 2016-02-09 16:09:15 -0800 | [diff] [blame] | 260 | * 1. Timestamps get initialized before ramstage, which implies |
| 261 | * CONFIG_EARLY_CBMEM_INIT and CBMEM initialization in romstage. |
| 262 | * This requires the board to define a TIMESTAMP() region in its |
| 263 | * memlayout.ld (default on x86). The base_time from timestamp_init() |
| 264 | * (usually called from bootblock.c on most non-x86 boards) persists |
| 265 | * in that region until it gets synced to CBMEM in romstage. |
| 266 | * In ramstage, the BSS cache's base_time will be 0 until the second |
| 267 | * sync, which will adjust the timestamps in there to the correct |
| 268 | * base_time (from CBMEM) with the timestamp_add_table_entry() below. |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 269 | * |
Julius Werner | 8c09377 | 2016-02-09 16:09:15 -0800 | [diff] [blame] | 270 | * 2. Timestamps only get initialized in ramstage *and* |
| 271 | * CONFIG_LATE_CBMEM_INIT is set. main() will call timestamp_init() |
| 272 | * very early (before any timestamps get logged) to set a base_time |
| 273 | * in the BSS cache, which will later get synced over to CBMEM. |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 274 | * |
Julius Werner | 8c09377 | 2016-02-09 16:09:15 -0800 | [diff] [blame] | 275 | * If you try to initialize timestamps before ramstage but don't define |
| 276 | * a TIMESTAMP region, all operations will fail (safely), and coreboot |
| 277 | * will behave as if timestamps only get initialized in ramstage. |
| 278 | * |
| 279 | * If CONFIG_EARLY_CBMEM_INIT is set but timestamps only get |
| 280 | * initialized in ramstage, the base_time from timestamp_init() will |
| 281 | * get ignored and all timestamps will be 0-based. |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 282 | */ |
| 283 | for (i = 0; i < ts_cache_table->num_entries; i++) { |
| 284 | struct timestamp_entry *tse = &ts_cache_table->entries[i]; |
| 285 | timestamp_add_table_entry(ts_cbmem_table, tse->entry_id, |
| 286 | tse->entry_stamp); |
| 287 | } |
| 288 | |
| 289 | /* Freshly added cbmem table has base_time 0. Inherit cache base_time */ |
| 290 | if (ts_cbmem_table->base_time == 0) |
| 291 | ts_cbmem_table->base_time = ts_cache_table->base_time; |
| 292 | |
Aaron Durbin | c49014e | 2015-08-30 21:19:55 -0500 | [diff] [blame] | 293 | /* Seed the timestamp tick frequency in ramstage. */ |
| 294 | if (ENV_RAMSTAGE) |
| 295 | ts_cbmem_table->tick_freq_mhz = timestamp_tick_freq_mhz(); |
| 296 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 297 | /* Cache no longer required. */ |
| 298 | ts_cache_table->num_entries = 0; |
| 299 | ts_cache->cache_state = TIMESTAMP_CACHE_NOT_NEEDED; |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 300 | } |
Kyösti Mälkki | cbf5bdf | 2013-09-10 00:07:21 +0300 | [diff] [blame] | 301 | |
Kyösti Mälkki | 806ea08b | 2017-07-15 20:42:20 +0300 | [diff] [blame^] | 302 | void timestamp_rescale_table(uint16_t N, uint16_t M) |
| 303 | { |
| 304 | uint32_t i; |
| 305 | struct timestamp_table *ts_table; |
| 306 | |
| 307 | if (!timestamp_should_run()) |
| 308 | return; |
| 309 | |
| 310 | if (N == 0 || M == 0) |
| 311 | return; |
| 312 | |
| 313 | ts_table = timestamp_table_get(); |
| 314 | |
| 315 | /* No timestamp table found */ |
| 316 | if (ts_table == NULL) { |
| 317 | printk(BIOS_ERR, "ERROR: No timestamp table found\n"); |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | ts_table->base_time /= M; |
| 322 | ts_table->base_time *= N; |
| 323 | for (i = 0; i < ts_table->num_entries; i++) { |
| 324 | struct timestamp_entry *tse = &ts_table->entries[i]; |
| 325 | tse->entry_stamp /= M; |
| 326 | tse->entry_stamp *= N; |
| 327 | } |
| 328 | } |
| 329 | |
Aaron Durbin | 1936f6c | 2015-07-03 17:04:21 -0500 | [diff] [blame] | 330 | ROMSTAGE_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem) |
| 331 | RAMSTAGE_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem) |
Aaron Durbin | 9e80e27 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 332 | |
| 333 | /* Provide default timestamp implementation using monotonic timer. */ |
| 334 | uint64_t __attribute__((weak)) timestamp_get(void) |
| 335 | { |
| 336 | struct mono_time t1, t2; |
| 337 | |
Aaron Durbin | 7aafe53 | 2015-05-07 11:32:30 -0500 | [diff] [blame] | 338 | if (!IS_ENABLED(CONFIG_HAVE_MONOTONIC_TIMER)) |
| 339 | return 0; |
| 340 | |
Aaron Durbin | 9e80e27 | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 341 | mono_time_set_usecs(&t1, 0); |
| 342 | timer_monotonic_get(&t2); |
| 343 | |
| 344 | return mono_time_diff_microseconds(&t1, &t2); |
| 345 | } |
Aaron Durbin | c49014e | 2015-08-30 21:19:55 -0500 | [diff] [blame] | 346 | |
| 347 | /* Like timestamp_get() above this matches up with microsecond granularity. */ |
| 348 | int __attribute__((weak)) timestamp_tick_freq_mhz(void) |
| 349 | { |
| 350 | return 1; |
| 351 | } |