blob: ec2364f0a876fec125177f58862387e3f09abd0c [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>
Elyes HAOUAS5817c562020-07-12 09:03:22 +02007#include <stdint.h>
Vadim Bendebury6f72d692011-09-21 16:12:39 -07008
Julius Wernercd49cce2019-03-05 16:53:33 -08009#if CONFIG(COLLECT_TIMESTAMPS)
Aaron Durbin1936f6c2015-07-03 17:04:21 -050010/*
Kyösti Mälkki3dd23a52019-08-22 15:06:50 +030011 * timestamp_init() needs to be called once in *one* of the ENV_ROMSTAGE_OR_BEFORE
12 * stages (bootblock, romstage, verstage, etc). It's up to the chipset/arch
13 * to make the call in the earliest stage, otherwise some timestamps will be lost.
Arthur Heymansa2bc2542021-05-29 08:10:49 +020014 * For x86 ENV_BOOTBLOCK / ENV_SEPARATE_ROMSTAGE call must be made before CAR is torn down.
Aaron Durbin1936f6c2015-07-03 17:04:21 -050015 */
Stefan Reinauer3a6550d2013-08-01 13:31:44 -070016void timestamp_init(uint64_t base);
Aaron Durbin1936f6c2015-07-03 17:04:21 -050017/*
Kyösti Mälkki8b936892019-09-12 13:45:15 +030018 * Add a new timestamp. For ENV_ROMSTAGE_OR_BEFORE, this timestamp will be stored
19 * inside REGION(timestamp) before cbmem comes online. For later stages, timestamps
20 * added before cbmem_[recovery|initialize] calls will be lost.
Aaron Durbin1936f6c2015-07-03 17:04:21 -050021 */
Bora Guvendikbf73c492021-11-22 16:03:39 -080022void timestamp_add(enum timestamp_id id, int64_t ts_time);
Aaron Durbin1936f6c2015-07-03 17:04:21 -050023/* Calls timestamp_add with current timestamp. */
Vadim Bendebury6f72d692011-09-21 16:12:39 -070024void timestamp_add_now(enum timestamp_id id);
Kyösti Mälkki806ea08b2017-07-15 20:42:20 +030025
26/* Apply a factor of N/M to all timestamps recorded so far. */
27void timestamp_rescale_table(uint16_t N, uint16_t M);
28
Werner Zeh35cceb82017-09-12 07:42:54 +020029/*
30 * Get the time since boot scaled in microseconds. Therefore use the base time
31 * of the timestamps to get the initial value which is subtracted from
32 * current timestamp at call time. This will provide a more reliable value even
33 * if the TSC is not reset on soft reset or warm start.
34 */
35uint32_t get_us_since_boot(void);
36
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070037#else
38#define timestamp_init(base)
39#define timestamp_add(id, time)
40#define timestamp_add_now(id)
Kyösti Mälkki806ea08b2017-07-15 20:42:20 +030041#define timestamp_rescale_table(N, M)
Werner Zeh35cceb82017-09-12 07:42:54 +020042#define get_us_since_boot() 0
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070043#endif
Vadim Bendebury6f72d692011-09-21 16:12:39 -070044
Philipp Deppenwiese86fd8842017-10-24 15:08:49 +020045/**
46 * Workaround for guard combination above.
Philipp Deppenwiese86fd8842017-10-24 15:08:49 +020047 */
Julius Wernercd49cce2019-03-05 16:53:33 -080048#if CONFIG(COLLECT_TIMESTAMPS)
Stefan Reinauer3a6550d2013-08-01 13:31:44 -070049/* Implemented by the architecture code */
50uint64_t timestamp_get(void);
Philipp Deppenwiese86fd8842017-10-24 15:08:49 +020051#else
52#define timestamp_get() 0
53#endif
54
Stefan Reinauer3a6550d2013-08-01 13:31:44 -070055uint64_t get_initial_timestamp(void);
Aaron Durbinc49014e2015-08-30 21:19:55 -050056/* Returns timestamp tick frequency in MHz. */
57int timestamp_tick_freq_mhz(void);
Stefan Reinauer3a6550d2013-08-01 13:31:44 -070058
Vadim Bendebury6f72d692011-09-21 16:12:39 -070059#endif