diff --git a/src/arch/armv7/Makefile.inc b/src/arch/armv7/Makefile.inc index cc22cd5b7d..f688743a15 100644 --- a/src/arch/armv7/Makefile.inc +++ b/src/arch/armv7/Makefile.inc @@ -192,6 +192,9 @@ romstage-y += memmove.S ramstage-y += memmove.S bootblock-y += memmove.S +romstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c +ramstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c + $(obj)/arch/armv7/coreboot_table.ramstage.o : $(OPTION_TABLE_H) romstage-srcs += $(objgenerated)/crt0.s diff --git a/src/arch/armv7/timestamp.c b/src/arch/armv7/timestamp.c new file mode 100644 index 0000000000..07a209c6cd --- /dev/null +++ b/src/arch/armv7/timestamp.c @@ -0,0 +1,29 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2013 Google Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA + */ + +#include +#include + +uint64_t timestamp_get(void) +{ + struct mono_time timestamp; + timer_monotonic_get(×tamp); + return (uint64_t)timestamp.microseconds; +} + diff --git a/src/arch/x86/lib/Makefile.inc b/src/arch/x86/lib/Makefile.inc index 8588c7686e..2844b75b87 100644 --- a/src/arch/x86/lib/Makefile.inc +++ b/src/arch/x86/lib/Makefile.inc @@ -11,6 +11,7 @@ ramstage-y += ebda.c ramstage-y += rom_media.c ramstage-$(CONFIG_COOP_MULTITASKING) += thread.c ramstage-$(CONFIG_COOP_MULTITASKING) += thread_switch.S +ramstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c romstage-$(CONFIG_EARLY_CONSOLE) += romstage_console.c romstage-y += cbfs_and_run.c @@ -18,6 +19,7 @@ romstage-y += memset.c romstage-y += memcpy.c romstage-y += memmove.c romstage-y += rom_media.c +romstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c smm-y += memset.c smm-y += memcpy.c diff --git a/src/arch/x86/lib/timestamp.c b/src/arch/x86/lib/timestamp.c new file mode 100644 index 0000000000..02582a5c3b --- /dev/null +++ b/src/arch/x86/lib/timestamp.c @@ -0,0 +1,27 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2013 Google Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA + */ + +#include +#include + +uint64_t timestamp_get(void) +{ + return rdtscll(); +} + diff --git a/src/cpu/intel/haswell/romstage.c b/src/cpu/intel/haswell/romstage.c index 5c381c092d..686631cefa 100644 --- a/src/cpu/intel/haswell/romstage.c +++ b/src/cpu/intel/haswell/romstage.c @@ -201,17 +201,16 @@ void romstage_common(const struct romstage_params *params) struct romstage_handoff *handoff; #if CONFIG_COLLECT_TIMESTAMPS - tsc_t start_romstage_time; - tsc_t before_dram_time; - tsc_t after_dram_time; - tsc_t base_time = { - .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc), - .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) - }; + uint64_t start_romstage_time; + uint64_t before_dram_time; + uint64_t after_dram_time; + uint64_t base_time = + (uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 || + pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc); #endif #if CONFIG_COLLECT_TIMESTAMPS - start_romstage_time = rdtsc(); + start_romstage_time = timestamp_get(); #endif if (params->bist == 0) @@ -253,7 +252,7 @@ void romstage_common(const struct romstage_params *params) post_code(0x3a); params->pei_data->boot_mode = boot_mode; #if CONFIG_COLLECT_TIMESTAMPS - before_dram_time = rdtsc(); + before_dram_time = timestamp_get(); #endif report_platform_info(); @@ -264,7 +263,7 @@ void romstage_common(const struct romstage_params *params) sdram_initialize(params->pei_data); #if CONFIG_COLLECT_TIMESTAMPS - after_dram_time = rdtsc(); + after_dram_time = timestamp_get(); #endif post_code(0x3b); diff --git a/src/include/timestamp.h b/src/include/timestamp.h index 9dd0d0f521..a4cfc6ab17 100644 --- a/src/include/timestamp.h +++ b/src/include/timestamp.h @@ -1,7 +1,7 @@ /* * This file is part of the coreboot project. * - * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. + * Copyright 2011 Google Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +20,8 @@ #ifndef __TIMESTAMP_H__ #define __TIMESTAMP_H__ +#include + struct timestamp_entry { uint32_t entry_id; uint64_t entry_stamp; @@ -55,12 +57,13 @@ enum timestamp_id { }; #if CONFIG_COLLECT_TIMESTAMPS -#include -void timestamp_init(tsc_t base); -void timestamp_add(enum timestamp_id id, tsc_t ts_time); +void timestamp_init(uint64_t base); +void timestamp_add(enum timestamp_id id, uint64_t ts_time); void timestamp_add_now(enum timestamp_id id); void timestamp_stash(enum timestamp_id id); void timestamp_sync(void); +/* Implemented by the architecture code */ +uint64_t timestamp_get(void); #else #define timestamp_init(base) #define timestamp_add(id, time) diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c index 15b200d42e..4643bdd084 100644 --- a/src/lib/timestamp.c +++ b/src/lib/timestamp.c @@ -1,7 +1,7 @@ /* * This file is part of the coreboot project. * - * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. + * Copyright 2011 Google Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,22 +22,14 @@ #include #include #ifndef __PRE_RAM__ -/* For CAR_GLOBAL... This should move out of x86 specific code */ #include + +static struct timestamp_table* ts_table; #endif #define MAX_TIMESTAMPS 30 -#ifndef __PRE_RAM__ -static struct timestamp_table* ts_table; -#endif - -static uint64_t tsc_to_uint64(tsc_t tstamp) -{ - return (((uint64_t)tstamp.hi) << 32) + tstamp.lo; -} - -void timestamp_init(tsc_t base) +void timestamp_init(uint64_t base) { struct timestamp_table* tst; @@ -50,12 +42,12 @@ void timestamp_init(tsc_t base) return; } - tst->base_time = tsc_to_uint64(base); + tst->base_time = base; tst->max_entries = MAX_TIMESTAMPS; tst->num_entries = 0; } -void timestamp_add(enum timestamp_id id, tsc_t ts_time) +void timestamp_add(enum timestamp_id id, uint64_t ts_time) { struct timestamp_entry *tse; #ifdef __PRE_RAM__ @@ -69,12 +61,12 @@ void timestamp_add(enum timestamp_id id, tsc_t ts_time) tse = &ts_table->entries[ts_table->num_entries++]; tse->entry_id = id; - tse->entry_stamp = tsc_to_uint64(ts_time) - ts_table->base_time; + tse->entry_stamp = ts_time - ts_table->base_time; } void timestamp_add_now(enum timestamp_id id) { - timestamp_add(id, rdtsc()); + timestamp_add(id, timestamp_get()); } #ifndef __PRE_RAM__ @@ -82,7 +74,7 @@ void timestamp_add_now(enum timestamp_id id) #define MAX_TIMESTAMP_CACHE 8 struct timestamp_cache { enum timestamp_id id; - tsc_t time; + uint64_t time; } timestamp_cache[MAX_TIMESTAMP_CACHE] CAR_GLOBAL; static int timestamp_entries CAR_GLOBAL = 0; @@ -102,7 +94,7 @@ void timestamp_stash(enum timestamp_id id) return; } timestamp_cache[timestamp_entries].id = id; - timestamp_cache[timestamp_entries].time = rdtsc(); + timestamp_cache[timestamp_entries].time = timestamp_get(); timestamp_entries++; } diff --git a/src/mainboard/google/butterfly/romstage.c b/src/mainboard/google/butterfly/romstage.c index 8127726dc9..b659b8a7e4 100644 --- a/src/mainboard/google/butterfly/romstage.c +++ b/src/mainboard/google/butterfly/romstage.c @@ -119,13 +119,12 @@ void main(unsigned long bist) u16 pm1_sts; #if CONFIG_COLLECT_TIMESTAMPS - tsc_t start_romstage_time; - tsc_t before_dram_time; - tsc_t after_dram_time; - tsc_t base_time = { - .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc), - .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) - }; + uint64_t start_romstage_time; + uint64_t before_dram_time; + uint64_t after_dram_time; + uint64_t base_time = + (uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 || + pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc); #endif struct pei_data pei_data = { pei_version: PEI_VERSION, @@ -175,7 +174,7 @@ void main(unsigned long bist) }; #if CONFIG_COLLECT_TIMESTAMPS - start_romstage_time = rdtsc(); + start_romstage_time = timestamp_get(); #endif if (bist == 0) @@ -242,12 +241,12 @@ void main(unsigned long bist) post_code(0x3a); pei_data.boot_mode = boot_mode; #if CONFIG_COLLECT_TIMESTAMPS - before_dram_time = rdtsc(); + before_dram_time = timestamp_get(); #endif sdram_initialize(&pei_data); #if CONFIG_COLLECT_TIMESTAMPS - after_dram_time = rdtsc(); + after_dram_time = timestamp_get(); #endif post_code(0x3c); diff --git a/src/mainboard/google/link/romstage.c b/src/mainboard/google/link/romstage.c index f20a7226ab..2f53df93bf 100644 --- a/src/mainboard/google/link/romstage.c +++ b/src/mainboard/google/link/romstage.c @@ -155,13 +155,12 @@ void main(unsigned long bist) u16 pm1_sts; #if CONFIG_COLLECT_TIMESTAMPS - tsc_t start_romstage_time; - tsc_t before_dram_time; - tsc_t after_dram_time; - tsc_t base_time = { - .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc), - .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) - }; + uint64_t start_romstage_time; + uint64_t before_dram_time; + uint64_t after_dram_time; + uint64_t base_time = + (uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 || + pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc); #endif struct pei_data pei_data = { pei_version: PEI_VERSION, @@ -210,7 +209,7 @@ void main(unsigned long bist) }; #if CONFIG_COLLECT_TIMESTAMPS - start_romstage_time = rdtsc(); + start_romstage_time = timestamp_get(); #endif if (bist == 0) @@ -284,12 +283,12 @@ void main(unsigned long bist) post_code(0x3a); pei_data.boot_mode = boot_mode; #if CONFIG_COLLECT_TIMESTAMPS - before_dram_time = rdtsc(); + before_dram_time = timestamp_get(); #endif sdram_initialize(&pei_data); #if CONFIG_COLLECT_TIMESTAMPS - after_dram_time = rdtsc(); + after_dram_time = timestamp_get(); #endif post_code(0x3c); diff --git a/src/mainboard/google/parrot/romstage.c b/src/mainboard/google/parrot/romstage.c index 9968226f81..82675017d7 100644 --- a/src/mainboard/google/parrot/romstage.c +++ b/src/mainboard/google/parrot/romstage.c @@ -120,13 +120,12 @@ void main(unsigned long bist) u16 pm1_sts; #if CONFIG_COLLECT_TIMESTAMPS - tsc_t start_romstage_time; - tsc_t before_dram_time; - tsc_t after_dram_time; - tsc_t base_time = { - .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc), - .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) - }; + uint64_t start_romstage_time; + uint64_t before_dram_time; + uint64_t after_dram_time; + uint64_t base_time = + (uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 || + pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc); #endif struct pei_data pei_data = { pei_version: PEI_VERSION, @@ -175,7 +174,7 @@ void main(unsigned long bist) }; #if CONFIG_COLLECT_TIMESTAMPS - start_romstage_time = rdtsc(); + start_romstage_time = timestamp_get(); #endif if (bist == 0) @@ -242,12 +241,12 @@ void main(unsigned long bist) post_code(0x3a); pei_data.boot_mode = boot_mode; #if CONFIG_COLLECT_TIMESTAMPS - before_dram_time = rdtsc(); + before_dram_time = timestamp_get(); #endif sdram_initialize(&pei_data); #if CONFIG_COLLECT_TIMESTAMPS - after_dram_time = rdtsc(); + after_dram_time = timestamp_get(); #endif post_code(0x3c); diff --git a/src/mainboard/google/stout/romstage.c b/src/mainboard/google/stout/romstage.c index 14820ddc65..b7c41aa7da 100644 --- a/src/mainboard/google/stout/romstage.c +++ b/src/mainboard/google/stout/romstage.c @@ -159,13 +159,12 @@ void main(unsigned long bist) u16 pm1_sts; #if CONFIG_COLLECT_TIMESTAMPS - tsc_t start_romstage_time; - tsc_t before_dram_time; - tsc_t after_dram_time; - tsc_t base_time = { - .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc), - .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) - }; + uint64_t start_romstage_time; + uint64_t before_dram_time; + uint64_t after_dram_time; + uint64_t base_time = + (uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 || + pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc); #endif struct pei_data pei_data = { pei_version: PEI_VERSION, @@ -219,7 +218,7 @@ void main(unsigned long bist) }; #if CONFIG_COLLECT_TIMESTAMPS - start_romstage_time = rdtsc(); + start_romstage_time = timestamp_get(); #endif if (bist == 0) @@ -291,12 +290,12 @@ void main(unsigned long bist) post_code(0x3a); pei_data.boot_mode = boot_mode; #if CONFIG_COLLECT_TIMESTAMPS - before_dram_time = rdtsc(); + before_dram_time = timestamp_get(); #endif sdram_initialize(&pei_data); #if CONFIG_COLLECT_TIMESTAMPS - after_dram_time = rdtsc(); + after_dram_time = timestamp_get(); #endif post_code(0x3b); /* Perform some initialization that must run before stage2 */ diff --git a/src/mainboard/intel/emeraldlake2/romstage.c b/src/mainboard/intel/emeraldlake2/romstage.c index 88bcced67c..7f97ff77cb 100644 --- a/src/mainboard/intel/emeraldlake2/romstage.c +++ b/src/mainboard/intel/emeraldlake2/romstage.c @@ -171,13 +171,12 @@ void main(unsigned long bist) u16 pm1_sts; #if CONFIG_COLLECT_TIMESTAMPS - tsc_t start_romstage_time; - tsc_t before_dram_time; - tsc_t after_dram_time; - tsc_t base_time = { - .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc), - .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) - }; + uint64_t start_romstage_time; + uint64_t before_dram_time; + uint64_t after_dram_time; + uint64_t base_time = + (uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 || + pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc); #endif struct pei_data pei_data = { pei_version: PEI_VERSION, @@ -224,7 +223,7 @@ void main(unsigned long bist) }; #if CONFIG_COLLECT_TIMESTAMPS - start_romstage_time = rdtsc(); + start_romstage_time = timestamp_get(); #endif if (bist == 0) @@ -290,12 +289,12 @@ void main(unsigned long bist) post_code(0x3a); pei_data.boot_mode = boot_mode; #if CONFIG_COLLECT_TIMESTAMPS - before_dram_time = rdtsc(); + before_dram_time = timestamp_get(); #endif sdram_initialize(&pei_data); #if CONFIG_COLLECT_TIMESTAMPS - after_dram_time = rdtsc(); + after_dram_time = timestamp_get(); #endif post_code(0x3b); /* Perform some initialization that must run before stage2 */ diff --git a/src/mainboard/samsung/lumpy/romstage.c b/src/mainboard/samsung/lumpy/romstage.c index b941021f9e..316a6d65d3 100644 --- a/src/mainboard/samsung/lumpy/romstage.c +++ b/src/mainboard/samsung/lumpy/romstage.c @@ -138,13 +138,12 @@ void main(unsigned long bist) u16 pm1_sts; #if CONFIG_COLLECT_TIMESTAMPS - tsc_t start_romstage_time; - tsc_t before_dram_time; - tsc_t after_dram_time; - tsc_t base_time = { - .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc), - .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) - }; + uint64_t start_romstage_time; + uint64_t before_dram_time; + uint64_t after_dram_time; + uint64_t base_time = + (uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 || + pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc); #endif struct pei_data pei_data = { @@ -197,7 +196,7 @@ void main(unsigned long bist) #if CONFIG_COLLECT_TIMESTAMPS - start_romstage_time = rdtsc(); + start_romstage_time = timestamp_get(); #endif if (bist == 0) @@ -312,12 +311,12 @@ void main(unsigned long bist) post_code(0x39); pei_data.boot_mode = boot_mode; #if CONFIG_COLLECT_TIMESTAMPS - before_dram_time = rdtsc(); + before_dram_time = timestamp_get(); #endif sdram_initialize(&pei_data); #if CONFIG_COLLECT_TIMESTAMPS - after_dram_time = rdtsc(); + after_dram_time = timestamp_get(); #endif post_code(0x3a); /* Perform some initialization that must run before stage2 */ diff --git a/src/mainboard/samsung/stumpy/romstage.c b/src/mainboard/samsung/stumpy/romstage.c index dda3ab5301..59b835fbc9 100644 --- a/src/mainboard/samsung/stumpy/romstage.c +++ b/src/mainboard/samsung/stumpy/romstage.c @@ -174,13 +174,12 @@ void main(unsigned long bist) u16 pm1_sts; #if CONFIG_COLLECT_TIMESTAMPS - tsc_t start_romstage_time; - tsc_t before_dram_time; - tsc_t after_dram_time; - tsc_t base_time = { - .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc), - .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) - }; + uint64_t start_romstage_time; + uint64_t before_dram_time; + uint64_t after_dram_time; + uint64_t base_time = + (uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 || + pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc); #endif struct pei_data pei_data = { mchbar: DEFAULT_MCHBAR, @@ -225,7 +224,7 @@ void main(unsigned long bist) }; #if CONFIG_COLLECT_TIMESTAMPS - start_romstage_time = rdtsc(); + start_romstage_time = timestamp_get(); #endif if (bist == 0) @@ -317,12 +316,12 @@ void main(unsigned long bist) post_code(0x39); pei_data.boot_mode = boot_mode; #if CONFIG_COLLECT_TIMESTAMPS - before_dram_time = rdtsc(); + before_dram_time = timestamp_get(); #endif sdram_initialize(&pei_data); #if CONFIG_COLLECT_TIMESTAMPS - after_dram_time = rdtsc(); + after_dram_time = timestamp_get(); #endif post_code(0x3a); /* Perform some initialization that must run before stage2 */