timestamp.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * This file is part of the coreboot project.
  3. *
  4. * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
  18. */
  19. #include <common.h>
  20. #include <asm/arch/timestamp.h>
  21. #include <asm/arch/sysinfo.h>
  22. #include <linux/compiler.h>
  23. struct timestamp_entry {
  24. uint32_t entry_id;
  25. uint64_t entry_stamp;
  26. } __packed;
  27. struct timestamp_table {
  28. uint64_t base_time;
  29. uint32_t max_entries;
  30. uint32_t num_entries;
  31. struct timestamp_entry entries[0]; /* Variable number of entries */
  32. } __packed;
  33. static struct timestamp_table *ts_table __attribute__((section(".data")));
  34. void timestamp_init(void)
  35. {
  36. ts_table = lib_sysinfo.tstamp_table;
  37. #ifdef CONFIG_SYS_X86_TSC_TIMER
  38. timer_set_base(ts_table->base_time);
  39. #endif
  40. timestamp_add_now(TS_U_BOOT_INITTED);
  41. }
  42. void timestamp_add(enum timestamp_id id, uint64_t ts_time)
  43. {
  44. struct timestamp_entry *tse;
  45. if (!ts_table || (ts_table->num_entries == ts_table->max_entries))
  46. return;
  47. tse = &ts_table->entries[ts_table->num_entries++];
  48. tse->entry_id = id;
  49. tse->entry_stamp = ts_time - ts_table->base_time;
  50. }
  51. void timestamp_add_now(enum timestamp_id id)
  52. {
  53. timestamp_add(id, rdtsc());
  54. }
  55. int timestamp_add_to_bootstage(void)
  56. {
  57. uint i;
  58. if (!ts_table)
  59. return -1;
  60. for (i = 0; i < ts_table->num_entries; i++) {
  61. struct timestamp_entry *tse = &ts_table->entries[i];
  62. const char *name = NULL;
  63. switch (tse->entry_id) {
  64. case TS_START_ROMSTAGE:
  65. name = "start-romstage";
  66. break;
  67. case TS_BEFORE_INITRAM:
  68. name = "before-initram";
  69. break;
  70. case TS_DEVICE_INITIALIZE:
  71. name = "device-initialize";
  72. break;
  73. case TS_DEVICE_DONE:
  74. name = "device-done";
  75. break;
  76. case TS_SELFBOOT_JUMP:
  77. name = "selfboot-jump";
  78. break;
  79. }
  80. if (name) {
  81. bootstage_add_record(0, name, BOOTSTAGEF_ALLOC,
  82. tse->entry_stamp /
  83. get_tbclk_mhz());
  84. }
  85. }
  86. return 0;
  87. }