2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
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.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
21 #include <console/console.h>
23 #include <timestamp.h>
25 #define MAX_TIMESTAMPS 30
28 static struct timestamp_table* ts_table;
31 static uint64_t tsc_to_uint64(tsc_t tstamp)
33 return (((uint64_t)tstamp.hi) << 32) + tstamp.lo;
36 void timestamp_init(tsc_t base)
38 struct timestamp_table* tst;
40 tst = cbmem_add(CBMEM_ID_TIMESTAMP,
41 sizeof(struct timestamp_table) +
42 MAX_TIMESTAMPS * sizeof(struct timestamp_entry));
45 printk(BIOS_ERR, "ERROR: failed to allocate timstamp table\n");
49 tst->base_time = tsc_to_uint64(base);
50 tst->max_entries = MAX_TIMESTAMPS;
54 void timestamp_add(enum timestamp_id id, tsc_t ts_time)
56 struct timestamp_entry *tse;
58 struct timestamp_table *ts_table = cbmem_find(CBMEM_ID_TIMESTAMP);
61 ts_table = cbmem_find(CBMEM_ID_TIMESTAMP);
63 if (!ts_table || (ts_table->num_entries == ts_table->max_entries))
66 tse = &ts_table->entries[ts_table->num_entries++];
68 tse->entry_stamp = tsc_to_uint64(ts_time) - ts_table->base_time;
71 void timestamp_add_now(enum timestamp_id id)
73 timestamp_add(id, rdtsc());