blob: 06c99acb3ce49b08a9898e5f57dfee755a32a84c [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vadim Bendebury6f72d692011-09-21 16:12:39 -07002
3#ifndef __TIMESTAMP_H__
4#define __TIMESTAMP_H__
5
Aaron Durbindc9f5cd2015-09-08 13:34:43 -05006#include <commonlib/timestamp_serialized.h>
Vadim Bendebury6f72d692011-09-21 16:12:39 -07007
Julius Wernercd49cce2019-03-05 16:53:33 -08008#if CONFIG(COLLECT_TIMESTAMPS)
Aaron Durbin1936f6c2015-07-03 17:04:21 -05009/*
Kyösti Mälkki3dd23a52019-08-22 15:06:50 +030010 * timestamp_init() needs to be called once in *one* of the ENV_ROMSTAGE_OR_BEFORE
11 * stages (bootblock, romstage, verstage, etc). It's up to the chipset/arch
12 * to make the call in the earliest stage, otherwise some timestamps will be lost.
13 * For x86 ENV_ROMSTAGE call must be made before CAR is torn down.
Aaron Durbin1936f6c2015-07-03 17:04:21 -050014 */
Stefan Reinauer3a6550d2013-08-01 13:31:44 -070015void timestamp_init(uint64_t base);
Aaron Durbin1936f6c2015-07-03 17:04:21 -050016/*
Kyösti Mälkki8b936892019-09-12 13:45:15 +030017 * Add a new timestamp. For ENV_ROMSTAGE_OR_BEFORE, this timestamp will be stored
18 * inside REGION(timestamp) before cbmem comes online. For later stages, timestamps
19 * added before cbmem_[recovery|initialize] calls will be lost.
Aaron Durbin1936f6c2015-07-03 17:04:21 -050020 */
Stefan Reinauer3a6550d2013-08-01 13:31:44 -070021void timestamp_add(enum timestamp_id id, uint64_t ts_time);
Aaron Durbin1936f6c2015-07-03 17:04:21 -050022/* Calls timestamp_add with current timestamp. */
Vadim Bendebury6f72d692011-09-21 16:12:39 -070023void timestamp_add_now(enum timestamp_id id);
Kyösti Mälkki806ea08b2017-07-15 20:42:20 +030024
25/* Apply a factor of N/M to all timestamps recorded so far. */
26void timestamp_rescale_table(uint16_t N, uint16_t M);
27
Werner Zeh35cceb82017-09-12 07:42:54 +020028/*
29 * Get the time since boot scaled in microseconds. Therefore use the base time
30 * of the timestamps to get the initial value which is subtracted from
31 * current timestamp at call time. This will provide a more reliable value even
32 * if the TSC is not reset on soft reset or warm start.
33 */
34uint32_t get_us_since_boot(void);
35
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070036#else
37#define timestamp_init(base)
38#define timestamp_add(id, time)
39#define timestamp_add_now(id)
Kyösti Mälkki806ea08b2017-07-15 20:42:20 +030040#define timestamp_rescale_table(N, M)
Werner Zeh35cceb82017-09-12 07:42:54 +020041#define get_us_since_boot() 0
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070042#endif
Vadim Bendebury6f72d692011-09-21 16:12:39 -070043
Philipp Deppenwiese86fd8842017-10-24 15:08:49 +020044/**
45 * Workaround for guard combination above.
Philipp Deppenwiese86fd8842017-10-24 15:08:49 +020046 */
Julius Wernercd49cce2019-03-05 16:53:33 -080047#if CONFIG(COLLECT_TIMESTAMPS)
Stefan Reinauer3a6550d2013-08-01 13:31:44 -070048/* Implemented by the architecture code */
49uint64_t timestamp_get(void);
Philipp Deppenwiese86fd8842017-10-24 15:08:49 +020050#else
51#define timestamp_get() 0
52#endif
53
Stefan Reinauer3a6550d2013-08-01 13:31:44 -070054uint64_t get_initial_timestamp(void);
Aaron Durbinc49014e2015-08-30 21:19:55 -050055/* Returns timestamp tick frequency in MHz. */
56int timestamp_tick_freq_mhz(void);
Stefan Reinauer3a6550d2013-08-01 13:31:44 -070057
Vadim Bendebury6f72d692011-09-21 16:12:39 -070058#endif