timestamp.c 1.7 KB

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