summaryrefslogtreecommitdiff
path: root/src/lib/timestamp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/timestamp.c')
-rw-r--r--src/lib/timestamp.c62
1 files changed, 43 insertions, 19 deletions
diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c
index 3f8a7bd621..7e2f7011e6 100644
--- a/src/lib/timestamp.c
+++ b/src/lib/timestamp.c
@@ -17,27 +17,26 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*/
+#include <stddef.h>
#include <stdint.h>
#include <console/console.h>
#include <cbmem.h>
#include <timestamp.h>
-#ifndef __PRE_RAM__
-/* For CAR_GLOBAL... This should move out of x86 specific code */
#include <cpu/x86/car.h>
-#endif
#define MAX_TIMESTAMPS 30
-#ifndef __PRE_RAM__
-static struct timestamp_table* ts_table;
-#endif
+static struct timestamp_table* ts_table CAR_GLOBAL = NULL;
+static tsc_t ts_basetime CAR_GLOBAL = { .lo = 0, .hi =0 };
+
+static void timestamp_stash(enum timestamp_id id, tsc_t ts_time);
static uint64_t tsc_to_uint64(tsc_t tstamp)
{
return (((uint64_t)tstamp.hi) << 32) + tstamp.lo;
}
-void timestamp_init(tsc_t base)
+static void timestamp_real_init(tsc_t base)
{
struct timestamp_table* tst;
@@ -53,18 +52,19 @@ void timestamp_init(tsc_t base)
tst->base_time = tsc_to_uint64(base);
tst->max_entries = MAX_TIMESTAMPS;
tst->num_entries = 0;
+
+ ts_table = tst;
}
void timestamp_add(enum timestamp_id id, tsc_t ts_time)
{
struct timestamp_entry *tse;
-#ifdef __PRE_RAM__
- struct timestamp_table *ts_table = cbmem_find(CBMEM_ID_TIMESTAMP);
-#else
- if (!ts_table)
- ts_table = cbmem_find(CBMEM_ID_TIMESTAMP);
-#endif
- if (!ts_table || (ts_table->num_entries == ts_table->max_entries))
+
+ if (!ts_table) {
+ timestamp_stash(id, ts_time);
+ return;
+ }
+ if (ts_table->num_entries == ts_table->max_entries)
return;
tse = &ts_table->entries[ts_table->num_entries++];
@@ -77,8 +77,6 @@ void timestamp_add_now(enum timestamp_id id)
timestamp_add(id, rdtsc());
}
-#ifndef __PRE_RAM__
-
#define MAX_TIMESTAMP_CACHE 8
struct timestamp_cache {
enum timestamp_id id;
@@ -95,18 +93,18 @@ static int timestamp_entries CAR_GLOBAL = 0;
* ram stage main()
*/
-void timestamp_stash(enum timestamp_id id)
+static void timestamp_stash(enum timestamp_id id, tsc_t ts_time)
{
if (timestamp_entries >= MAX_TIMESTAMP_CACHE) {
printk(BIOS_ERR, "ERROR: failed to add timestamp to cache\n");
return;
}
timestamp_cache[timestamp_entries].id = id;
- timestamp_cache[timestamp_entries].time = rdtsc();
+ timestamp_cache[timestamp_entries].time = ts_time;
timestamp_entries++;
}
-void timestamp_sync(void)
+static void timestamp_do_sync(void)
{
int i;
for (i = 0; i < timestamp_entries; i++)
@@ -114,4 +112,30 @@ void timestamp_sync(void)
timestamp_entries = 0;
}
+void timestamp_init(tsc_t base)
+{
+#ifndef __PRE_RAM__
+ struct timestamp_table* tst;
+
+ /* Locate and use an already existing table. */
+ tst = cbmem_find(CBMEM_ID_TIMESTAMP);
+ if (tst) {
+ ts_table = tst;
+ return;
+ }
+#endif
+
+ timestamp_real_init(base);
+ if (ts_table)
+ timestamp_do_sync();
+ else
+ ts_basetime = base;
+}
+
+#ifndef __PRE_RAM__
+void timestamp_sync(void)
+{
+ if (!ts_table)
+ timestamp_init(ts_basetime);
+}
#endif