timestamp.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/arch/sysinfo.h>
  11. #include <linux/compiler.h>
  12. struct timestamp_entry {
  13. uint32_t entry_id;
  14. uint64_t entry_stamp;
  15. } __packed;
  16. struct timestamp_table {
  17. uint64_t base_time;
  18. uint32_t max_entries;
  19. uint32_t num_entries;
  20. struct timestamp_entry entries[0]; /* Variable number of entries */
  21. } __packed;
  22. static struct timestamp_table *ts_table __attribute__((section(".data")));
  23. void timestamp_init(void)
  24. {
  25. timestamp_add_now(TS_U_BOOT_INITTED);
  26. }
  27. void timestamp_add(enum timestamp_id id, uint64_t ts_time)
  28. {
  29. struct timestamp_entry *tse;
  30. if (!ts_table || (ts_table->num_entries == ts_table->max_entries))
  31. return;
  32. tse = &ts_table->entries[ts_table->num_entries++];
  33. tse->entry_id = id;
  34. tse->entry_stamp = ts_time - ts_table->base_time;
  35. }
  36. void timestamp_add_now(enum timestamp_id id)
  37. {
  38. timestamp_add(id, rdtsc());
  39. }
  40. int timestamp_add_to_bootstage(void)
  41. {
  42. uint i;
  43. if (!ts_table)
  44. return -1;
  45. for (i = 0; i < ts_table->num_entries; i++) {
  46. struct timestamp_entry *tse = &ts_table->entries[i];
  47. const char *name = NULL;
  48. switch (tse->entry_id) {
  49. case TS_START_ROMSTAGE:
  50. name = "start-romstage";
  51. break;
  52. case TS_BEFORE_INITRAM:
  53. name = "before-initram";
  54. break;
  55. case TS_DEVICE_INITIALIZE:
  56. name = "device-initialize";
  57. break;
  58. case TS_DEVICE_DONE:
  59. name = "device-done";
  60. break;
  61. case TS_SELFBOOT_JUMP:
  62. name = "selfboot-jump";
  63. break;
  64. }
  65. if (name) {
  66. bootstage_add_record(0, name, BOOTSTAGEF_ALLOC,
  67. tse->entry_stamp /
  68. get_tbclk_mhz());
  69. }
  70. }
  71. return 0;
  72. }