timestamp.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
  4. *
  5. * Modified from the coreboot version
  6. */
  7. #include <common.h>
  8. #include <bootstage.h>
  9. #include <asm/arch/timestamp.h>
  10. #include <asm/cb_sysinfo.h>
  11. #include <linux/compiler.h>
  12. static struct timestamp_table *ts_table __section(".data");
  13. void timestamp_init(void)
  14. {
  15. timestamp_add_now(TS_U_BOOT_INITTED);
  16. }
  17. void timestamp_add(enum timestamp_id id, uint64_t ts_time)
  18. {
  19. struct timestamp_entry *tse;
  20. if (!ts_table || (ts_table->num_entries == ts_table->max_entries))
  21. return;
  22. tse = &ts_table->entries[ts_table->num_entries++];
  23. tse->entry_id = id;
  24. tse->entry_stamp = ts_time - ts_table->base_time;
  25. }
  26. void timestamp_add_now(enum timestamp_id id)
  27. {
  28. timestamp_add(id, rdtsc());
  29. }
  30. int timestamp_add_to_bootstage(void)
  31. {
  32. uint i;
  33. if (!ts_table)
  34. return -1;
  35. for (i = 0; i < ts_table->num_entries; i++) {
  36. struct timestamp_entry *tse = &ts_table->entries[i];
  37. const char *name = NULL;
  38. switch (tse->entry_id) {
  39. case TS_START_ROMSTAGE:
  40. name = "start-romstage";
  41. break;
  42. case TS_BEFORE_INITRAM:
  43. name = "before-initram";
  44. break;
  45. case TS_DEVICE_INITIALIZE:
  46. name = "device-initialize";
  47. break;
  48. case TS_DEVICE_DONE:
  49. name = "device-done";
  50. break;
  51. case TS_SELFBOOT_JUMP:
  52. name = "selfboot-jump";
  53. break;
  54. }
  55. if (name) {
  56. bootstage_add_record(0, name, BOOTSTAGEF_ALLOC,
  57. tse->entry_stamp /
  58. get_tbclk_mhz());
  59. }
  60. }
  61. return 0;
  62. }