timestamps: Use stash before CBMEM is usable

Change-Id: I9e927abdb1d7d9c233de5620a9a65b419e803ebf
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: http://review.coreboot.org/3909
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Aaron Durbin <adurbin@google.com>
This commit is contained in:
Kyösti Mälkki 2013-09-07 17:26:08 +03:00
parent e28bd4ade6
commit b766b1c76a
3 changed files with 52 additions and 27 deletions

View File

@ -59,14 +59,12 @@ enum timestamp_id {
void timestamp_init(tsc_t base);
void timestamp_add(enum timestamp_id id, tsc_t ts_time);
void timestamp_add_now(enum timestamp_id id);
void timestamp_stash(enum timestamp_id id);
void timestamp_sync(void);
tsc_t get_initial_timestamp(void);
#else
#define timestamp_init(base)
#define timestamp_add(id, time)
#define timestamp_add_now(id)
#define timestamp_stash(id)
#define timestamp_sync()
#endif

View File

@ -126,7 +126,7 @@ static boot_state_t bs_pre_device(void *arg)
static boot_state_t bs_dev_init_chips(void *arg)
{
timestamp_stash(TS_DEVICE_ENUMERATE);
timestamp_add_now(TS_DEVICE_ENUMERATE);
/* Initialize chips early, they might disable unused devices. */
dev_initialize_chips();
@ -145,7 +145,7 @@ static boot_state_t bs_dev_enumerate(void *arg)
static boot_state_t bs_dev_resources(void *arg)
{
timestamp_stash(TS_DEVICE_CONFIGURE);
timestamp_add_now(TS_DEVICE_CONFIGURE);
/* Now compute and assign the bus resources. */
dev_configure();
post_code(POST_DEVICE_CONFIGURATION_COMPLETE);
@ -155,7 +155,7 @@ static boot_state_t bs_dev_resources(void *arg)
static boot_state_t bs_dev_enable(void *arg)
{
timestamp_stash(TS_DEVICE_ENABLE);
timestamp_add_now(TS_DEVICE_ENABLE);
/* Now actually enable devices on the bus */
dev_enable();
post_code(POST_DEVICES_ENABLED);
@ -165,7 +165,7 @@ static boot_state_t bs_dev_enable(void *arg)
static boot_state_t bs_dev_init(void *arg)
{
timestamp_stash(TS_DEVICE_INITIALIZE);
timestamp_add_now(TS_DEVICE_INITIALIZE);
/* And of course initialize devices on the bus */
dev_initialize();
post_code(POST_DEVICES_INITIALIZED);
@ -175,7 +175,7 @@ static boot_state_t bs_dev_init(void *arg)
static boot_state_t bs_post_device(void *arg)
{
timestamp_stash(TS_DEVICE_DONE);
timestamp_add_now(TS_DEVICE_DONE);
timestamp_sync();
@ -446,7 +446,10 @@ static void boot_state_schedule_static_entries(void)
void main(void)
{
timestamp_stash(TS_START_RAMSTAGE);
/* Record current time, try to locate timestamps in CBMEM. */
timestamp_init(rdtsc());
timestamp_add_now(TS_START_RAMSTAGE);
post_code(POST_ENTRY_RAMSTAGE);
/* console_init() MUST PRECEDE ALL printk()! */

View File

@ -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