Patch set updated for coreboot: 4c31db2 cbmem: [NOTFORMERGE]  CBMEM_INIT_HOOK() API

Marc Jones (marc.jones@se-eng.com) gerrit at coreboot.org
Sat May 16 02:49:17 CEST 2015


Marc Jones (marc.jones at se-eng.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/7878

-gerrit

commit 4c31db2fa1ed00d0ecfe628b525e6b913435d854
Author: Kyösti Mälkki <kyosti.malkki at gmail.com>
Date:   Wed Jan 7 04:48:43 2015 +0200

    cbmem: [NOTFORMERGE]  CBMEM_INIT_HOOK() API
    
    Squashed two changes from chromium.git.
    
    cbmem: Unify random on-CBMEM-init tasks under common CBMEM_INIT_HOOK() API
    
    There are several use cases for performing a certain task when CBMEM is
    first set up (usually to migrate some data into it that was previously
    kept in BSS/SRAM/hammerspace), and unfortunately we handle each of them
    differently: timestamp migration is called explicitly from
    cbmem_initialize(), certain x86-chipset-specific tasks use the
    CAR_MIGRATION() macro to register a hook, and the CBMEM console is
    migrated through a direct call from romstage (on non-x86 and SandyBridge
    boards).
    
    This patch decouples the CAR_MIGRATION() hook mechanism from
    cache-as-RAM and rechristens it to CBMEM_INIT_HOOK(), which is a clearer
    description of what it really does. All of the above use cases are
    ported to this new, consistent model, allowing us to have one less line
    of boilerplate in non-CAR romstages.
    
    BRANCH=None
    BUG=None
    TEST=Built and booted on Nyan_Blaze and Falco with and without
    CONFIG_CBMEM_CONSOLE. Confirmed that 'cbmem -c' shows the full log after
    boot (and the resume log after S3 resume on Falco). Compiled for Parrot,
    Stout and Lumpy.
    
    Original-Change-Id: I1681b372664f5a1f15c3733cbd32b9b11f55f8ea
    Signed-off-by: Julius Werner <jwerner at chromium.org>
    Reviewed-on: https://chromium-review.googlesource.com/232612
    Reviewed-by: Aaron Durbin <adurbin at chromium.org>
    
    cbmem: Extend hooks to ramstage, fix timestamp synching
    
    Commit 7dd5bbd71 (cbmem: Unify random on-CBMEM-init tasks under common
    CBMEM_INIT_HOOK() API) inadvertently broke ramstage timestamps since
    timestamp_sync() was no longer called there. Oops.
    
    This patch fixes the issue by extending the CBMEM_INIT_HOOK() mechanism
    to the cbmem_initialize() call in ramstage. The macro is split into
    explicit ROMSTAGE_/RAMSTAGE_ versions to make the behavior as clear as
    possible and prevent surprises (although just using a single macro and
    relying on the Makefiles to link an object into all appropriate stages
    would also work).
    
    This allows us to get rid of the explicit cbmemc_reinit() in ramstage
    (which I somehow accounted for in the last patch without realizing that
    timestamps work exactly the same way...), and replace the older and less
    flexible cbmem_arch_init() mechanism.
    
    Also added a size assertion for the pre-RAM CBMEM console to memlayout
    that could prevent a very unlikely buffer overflow I just noticed.
    
    BRANCH=None
    BUG=None
    TEST=Booted on Pinky and Falco, confirmed that ramstage timestamps once
    again show up. Compile-tested for Rambi and Samus.
    
    Original-Change-Id: If907266c3f20dc3d599b5c968ea5b39fe5c00e9c
    Signed-off-by: Julius Werner <jwerner at chromium.org>
    Reviewed-on: https://chromium-review.googlesource.com/233533
    Reviewed-by: Aaron Durbin <adurbin at chromium.org>
    
    Change-Id: I1be89bafacfe85cba63426e2d91f5d8d4caa1800
    Signed-off-by: Kyösti Mälkki <kyosti.malkki at gmail.com>
---
 src/arch/arm/include/arch/early_variables.h    |  1 -
 src/arch/arm64/include/arch/early_variables.h  |  1 -
 src/arch/x86/boot/cbmem.c                      | 22 ----------------------
 src/arch/x86/boot/gdt.c                        |  3 ++-
 src/arch/x86/include/arch/early_variables.h    | 14 +-------------
 src/arch/x86/init/romstage.ld                  |  9 ++++-----
 src/cpu/x86/car.c                              | 18 +++---------------
 src/drivers/usb/ehci_debug.c                   |  2 +-
 src/include/cbmem.h                            | 16 ++++++++++++++++
 src/include/console/cbmem_console.h            |  8 +-------
 src/include/cpu/x86/gdt.h                      |  3 ---
 src/include/timestamp.h                        |  2 --
 src/lib/cbmem_common.c                         | 19 +++++++------------
 src/lib/cbmem_console.c                        |  7 +++----
 src/lib/ramstage.ld                            |  3 +++
 src/lib/rmodule.ld                             |  3 +++
 src/lib/romstage.ld                            |  6 ++++--
 src/lib/timestamp.c                            |  7 ++++---
 src/soc/intel/baytrail/romstage/romstage.c     |  2 +-
 src/soc/intel/broadwell/romstage/power_state.c |  2 +-
 20 files changed, 54 insertions(+), 94 deletions(-)

diff --git a/src/arch/arm/include/arch/early_variables.h b/src/arch/arm/include/arch/early_variables.h
index 97bc0cd..f7266d4 100644
--- a/src/arch/arm/include/arch/early_variables.h
+++ b/src/arch/arm/include/arch/early_variables.h
@@ -22,7 +22,6 @@
 
 #define CAR_GLOBAL
 
-#define CAR_MIGRATE(migrate_fn_)
 static inline void *car_get_var_ptr(void *var) { return var; }
 #define car_get_var(var) (var)
 #define car_sync_var(var) (var)
diff --git a/src/arch/arm64/include/arch/early_variables.h b/src/arch/arm64/include/arch/early_variables.h
index 97bc0cd..f7266d4 100644
--- a/src/arch/arm64/include/arch/early_variables.h
+++ b/src/arch/arm64/include/arch/early_variables.h
@@ -22,7 +22,6 @@
 
 #define CAR_GLOBAL
 
-#define CAR_MIGRATE(migrate_fn_)
 static inline void *car_get_var_ptr(void *var) { return var; }
 #define car_get_var(var) (var)
 #define car_sync_var(var) (var)
diff --git a/src/arch/x86/boot/cbmem.c b/src/arch/x86/boot/cbmem.c
index 762d246..414782a 100644
--- a/src/arch/x86/boot/cbmem.c
+++ b/src/arch/x86/boot/cbmem.c
@@ -20,12 +20,6 @@
 #include <cbmem.h>
 #include <arch/acpi.h>
 
-/* FIXME: Remove after CBMEM_INIT_HOOKS. */
-#include <arch/early_variables.h>
-#include <cpu/x86/gdt.h>
-#include <console/cbmem_console.h>
-#include <timestamp.h>
-
 #if IS_ENABLED(CONFIG_LATE_CBMEM_INIT)
 
 #if !defined(__PRE_RAM__)
@@ -55,22 +49,6 @@ void *cbmem_top(void)
 
 #endif /* LATE_CBMEM_INIT */
 
-void cbmem_run_init_hooks(void)
-{
-	/* Migrate car.global_data. */
-	car_migrate_variables();
-
-#if !defined(__PRE_RAM__)
-	/* Relocate CBMEM console. */
-	cbmemc_reinit();
-
-	/* Relocate timestamps stash. */
-	timestamp_reinit();
-
-	move_gdt();
-#endif
-}
-
 /* Something went wrong, our high memory area got wiped */
 void cbmem_fail_resume(void)
 {
diff --git a/src/arch/x86/boot/gdt.c b/src/arch/x86/boot/gdt.c
index 7b64af7..b4cfbee 100644
--- a/src/arch/x86/boot/gdt.c
+++ b/src/arch/x86/boot/gdt.c
@@ -32,7 +32,7 @@ struct gdtarg {
 /* Copy GDT to new location and reload it.
  * FIXME: We only do this for BSP CPU.
  */
-void move_gdt(void)
+static void move_gdt(void)
 {
 	void *newgdt;
 	u16 num_gdt_bytes = (u32)&gdt_end - (u32)&gdt;
@@ -55,3 +55,4 @@ void move_gdt(void)
 	__asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg));
 	printk(BIOS_DEBUG, "ok\n");
 }
+RAMSTAGE_CBMEM_INIT_HOOK(move_gdt)
diff --git a/src/arch/x86/include/arch/early_variables.h b/src/arch/x86/include/arch/early_variables.h
index c6afceb..afd4344 100644
--- a/src/arch/x86/include/arch/early_variables.h
+++ b/src/arch/x86/include/arch/early_variables.h
@@ -23,18 +23,12 @@
 #if defined(__PRE_RAM__) && IS_ENABLED(CONFIG_CACHE_AS_RAM)
 asm(".section .car.global_data,\"w\", at nobits");
 asm(".previous");
-#ifdef __clang__
 #define CAR_GLOBAL __attribute__((used,section(".car.global_data")))
 #else
 #define CAR_GLOBAL __attribute__((used,section(".car.global_data#")))
 #endif /* __clang__ */
 
-#define CAR_MIGRATE_ATTR __attribute__ ((used,section (".car.migrate")))
-
-/* Call migrate_fn_() when CAR globals are migrated. */
-#define CAR_MIGRATE(migrate_fn_) \
-	static void (* const migrate_fn_ ## _ptr)(void) CAR_MIGRATE_ATTR = \
-	migrate_fn_;
+#if defined(__PRE_RAM__)
 
 /* Get the correct pointer for the CAR global variable. */
 void *car_get_var_ptr(void *var);
@@ -50,17 +44,11 @@ void *car_sync_var_ptr(void *var);
 #define car_set_var(var, val) \
 	do { car_get_var(var) = (val); } while(0)
 
-/* Migrate the CAR variables to memory. */
-void car_migrate_variables(void);
-
 #else
-#define CAR_GLOBAL
-#define CAR_MIGRATE(migrate_fn_)
 static inline void *car_get_var_ptr(void *var) { return var; }
 #define car_get_var(var) (var)
 #define car_sync_var(var) (var)
 #define car_set_var(var, val) do { (var) = (val); } while (0)
-static inline void car_migrate_variables(void) { }
 #endif
 
 #endif
diff --git a/src/arch/x86/init/romstage.ld b/src/arch/x86/init/romstage.ld
index 2ae96ac..40b2132 100644
--- a/src/arch/x86/init/romstage.ld
+++ b/src/arch/x86/init/romstage.ld
@@ -34,15 +34,14 @@ SECTIONS
 		*(.text);
 		*(.text.*);
 		*(.rom.data);
+		. = ALIGN(4);
+		_cbmem_init_hooks = .;
+		KEEP(*(.rodata.cbmem_init_hooks));
+		_ecbmem_init_hooks = .;
 		*(.rodata);
 		*(.rodata.*);
 		*(.rom.data.*);
 		. = ALIGN(16);
-		_car_migrate_start = .;
-		KEEP(*(.car.migrate));
-		LONG(0);
-		_car_migrate_end = .;
-		. = ALIGN(16);
 		_erom = .;
 	}
 
diff --git a/src/cpu/x86/car.c b/src/cpu/x86/car.c
index 342a179..fc4f0d0 100644
--- a/src/cpu/x86/car.c
+++ b/src/cpu/x86/car.c
@@ -136,21 +136,9 @@ static void do_car_migrate_variables(void)
 	car_migrated = ~0;
 }
 
-static void do_car_migrate_hooks(void)
+static void car_migrate_variables(void)
 {
-	car_migration_func_t *migrate_func;
-	/* Call all the migration functions. */
-	migrate_func = &_car_migrate_start;
-	while (*migrate_func != NULL) {
-		(*migrate_func)();
-		migrate_func++;
-	}
-}
-
-void car_migrate_variables(void)
-{
-	if (!IS_ENABLED(PLATFORM_USES_FSP1_0))
+	if (!IS_ENABLED(CONFIG_BROKEN_CAR_MIGRATE) && !IS_ENABLED(PLATFORM_USES_FSP))
 		do_car_migrate_variables();
-
-	do_car_migrate_hooks();
 }
+ROMSTAGE_CBMEM_INIT_HOOK(car_migrate_variables)
diff --git a/src/drivers/usb/ehci_debug.c b/src/drivers/usb/ehci_debug.c
index 16f9164..f91402d 100644
--- a/src/drivers/usb/ehci_debug.c
+++ b/src/drivers/usb/ehci_debug.c
@@ -682,7 +682,7 @@ static void migrate_ehci_debug(void)
 	memcpy(dbg_info_cbmem, dbg_info, sizeof(*dbg_info));
 	car_set_var(glob_dbg_info_p, dbg_info_cbmem);
 }
-CAR_MIGRATE(migrate_ehci_debug);
+ROMSTAGE_CBMEM_INIT_HOOK(migrate_ehci_debug);
 #endif
 
 int dbgp_ep_is_active(struct dbgp_pipe *pipe)
diff --git a/src/include/cbmem.h b/src/include/cbmem.h
index 08c1d64..9033952 100644
--- a/src/include/cbmem.h
+++ b/src/include/cbmem.h
@@ -206,6 +206,7 @@ void *cbmem_add(u32 id, u64 size);
 /* Find a cbmem entry of a given id. These return NULL on failure. */
 void *cbmem_find(u32 id);
 
+typedef void (* const cbmem_init_hook_t)(void);
 void cbmem_run_init_hooks(void);
 void cbmem_fail_resume(void);
 
@@ -216,6 +217,21 @@ void cbmem_add_bootmem(void);
 void cbmem_list(void);
 #endif /* __PRE_RAM__ */
 
+#ifndef __PRE_RAM__
+#define ROMSTAGE_CBMEM_INIT_HOOK(init_fn_) static cbmem_init_hook_t \
+        init_fn_ ## _unused_ __attribute__((unused)) = init_fn_;
+#define RAMSTAGE_CBMEM_INIT_HOOK(init_fn_) \
+       static cbmem_init_hook_t init_fn_ ## _ptr_ __attribute__((used, \
+       section(".rodata.cbmem_init_hooks"))) = init_fn_;
+#else /* __PRE_RAM__ */
+#define ROMSTAGE_CBMEM_INIT_HOOK(init_fn_) \
+       static cbmem_init_hook_t init_fn_ ## _ptr_ __attribute__((used, \
+       section(".rodata.cbmem_init_hooks"))) = init_fn_;
+#define RAMSTAGE_CBMEM_INIT_HOOK(init_fn_) static cbmem_init_hook_t \
+       init_fn_ ## _unused_ __attribute__((unused)) = init_fn_;
+#endif /* !__PRE_RAM__ */
+
+
 /* These are for compatibility with old boards only. Any new chipset and board
  * must implement cbmem_top() for both romstage and ramstage to support
  * early features like COLLECT_TIMESTAMPS and CBMEM_CONSOLE.
diff --git a/src/include/console/cbmem_console.h b/src/include/console/cbmem_console.h
index 8f7fcb2..90fe447 100644
--- a/src/include/console/cbmem_console.h
+++ b/src/include/console/cbmem_console.h
@@ -13,7 +13,7 @@
  * 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
+ * along with this program; if not, write to the Free src/include/console/cbmem_console.hSoftware
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
  */
 #ifndef _CONSOLE_CBMEM_CONSOLE_H_
@@ -25,12 +25,6 @@
 void cbmemc_init(void);
 void cbmemc_tx_byte(unsigned char data);
 
-#if CONFIG_CONSOLE_CBMEM
-void cbmemc_reinit(void);
-#else
-static inline void cbmemc_reinit(void) {}
-#endif
-
 #define __CBMEM_CONSOLE_ENABLE__	CONFIG_CONSOLE_CBMEM && \
 	(ENV_RAMSTAGE || (IS_ENABLED(CONFIG_EARLY_CBMEM_INIT) && \
 	(ENV_ROMSTAGE || (ENV_BOOTBLOCK && CONFIG_BOOTBLOCK_CONSOLE))))
diff --git a/src/include/cpu/x86/gdt.h b/src/include/cpu/x86/gdt.h
index 260b158..43a80fe 100644
--- a/src/include/cpu/x86/gdt.h
+++ b/src/include/cpu/x86/gdt.h
@@ -28,7 +28,4 @@ extern char _secondary_gdt_addr[];
 extern char _secondary_start[];
 extern char _secondary_start_end[];
 
-/* Defined in src/arch/x86/boot/gdt.c */
-void move_gdt(void);
-
 #endif /* CPU_X86_GDT */
diff --git a/src/include/timestamp.h b/src/include/timestamp.h
index a6bfced..d57ee32 100644
--- a/src/include/timestamp.h
+++ b/src/include/timestamp.h
@@ -92,12 +92,10 @@ enum timestamp_id {
 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_reinit(void);
 #else
 #define timestamp_init(base)
 #define timestamp_add(id, time)
 #define timestamp_add_now(id)
-#define timestamp_reinit()
 #endif
 
 /* Implemented by the architecture code */
diff --git a/src/lib/cbmem_common.c b/src/lib/cbmem_common.c
index 6d581c4..51ffa9d 100644
--- a/src/lib/cbmem_common.c
+++ b/src/lib/cbmem_common.c
@@ -24,26 +24,21 @@
 #include <arch/acpi.h>
 #endif
 
-/* FIXME: Remove after CBMEM_INIT_HOOKS. */
-#include <console/cbmem_console.h>
-#include <timestamp.h>
+extern cbmem_init_hook_t _cbmem_init_hooks;
+extern cbmem_init_hook_t _ecbmem_init_hooks;
 
-
-/* FIXME: Replace with CBMEM_INIT_HOOKS API. */
-#if !IS_ENABLED(CONFIG_ARCH_X86)
 void cbmem_run_init_hooks(void)
 {
-	/* Relocate CBMEM console. */
-	cbmemc_reinit();
-
-	/* Relocate timestamps stash. */
-	timestamp_reinit();
+	cbmem_init_hook_t *init_hook_ptr = &_cbmem_init_hooks;
+	while (init_hook_ptr != &_ecbmem_init_hooks) {
+		(*init_hook_ptr)();
+		init_hook_ptr++;
+	}
 }
 
 void __attribute__((weak)) cbmem_fail_resume(void)
 {
 }
-#endif
 
 #if ENV_RAMSTAGE && !IS_ENABLED(CONFIG_EARLY_CBMEM_INIT)
 static void init_cbmem_post_device(void *unused)
diff --git a/src/lib/cbmem_console.c b/src/lib/cbmem_console.c
index 9d292bf..f803f99 100644
--- a/src/lib/cbmem_console.c
+++ b/src/lib/cbmem_console.c
@@ -208,7 +208,7 @@ static void copy_console_buffer(struct cbmem_console *old_cons_p,
 	new_cons_p->buffer_cursor = cursor;
 }
 
-void cbmemc_reinit(void)
+static void cbmemc_reinit(void)
 {
 	struct cbmem_console *cbm_cons_p;
 	const size_t size = CONFIG_CONSOLE_CBMEM_BUFFER_SIZE;
@@ -236,6 +236,8 @@ void cbmemc_reinit(void)
 
 	init_console_ptr(cbm_cons_p, size, flags);
 }
+ROMSTAGE_CBMEM_INIT_HOOK(cbmemc_reinit)
+RAMSTAGE_CBMEM_INIT_HOOK(cbmemc_reinit)
 
 #if IS_ENABLED(CONFIG_CONSOLE_CBMEM_DUMP_TO_UART)
 void cbmem_dump_console(void)
@@ -252,6 +254,3 @@ void cbmem_dump_console(void)
 		uart_tx_byte(0, cbm_cons_p->buffer_body[cursor]);
 }
 #endif
-
-/* Call cbmemc_reinit() at CAR migration time. */
-CAR_MIGRATE(cbmemc_reinit)
diff --git a/src/lib/ramstage.ld b/src/lib/ramstage.ld
index f12653e..585a3a0 100644
--- a/src/lib/ramstage.ld
+++ b/src/lib/ramstage.ld
@@ -68,6 +68,9 @@
 	LONG(0);
 	LONG(0);
 	_bs_init_end = .;
+	_cbmem_init_hooks = .;
+	KEEP(*(.rodata.cbmem_init_hooks));
+	_ecbmem_init_hooks = .;
 
 	*(.rodata)
 	*(.rodata.*)
diff --git a/src/lib/rmodule.ld b/src/lib/rmodule.ld
index 70a2d3d..0e9c880 100644
--- a/src/lib/rmodule.ld
+++ b/src/lib/rmodule.ld
@@ -55,6 +55,9 @@ SECTIONS
 		LONG(0);
 		LONG(0);
 		_bs_init_end = .;
+		_cbmem_init_hooks = .;
+		KEEP(*(.rodata.cbmem_init_hooks));
+		_ecbmem_init_hooks = .;
 
 		. = ALIGN(8);
 
diff --git a/src/lib/romstage.ld b/src/lib/romstage.ld
index 1e80962..bbad333 100644
--- a/src/lib/romstage.ld
+++ b/src/lib/romstage.ld
@@ -29,12 +29,14 @@
 } : to_load
 
 .data . : {
+	. = ALIGN(8);
+	_cbmem_init_hooks = .;
+	KEEP(*(.rodata.cbmem_init_hooks));
+	_ecbmem_init_hooks = .;
 	*(.rodata);
 	*(.rodata.*);
 	*(.data);
 	*(.data.*);
-	_preram_cbmem_console = DEFINED(_preram_cbmem_console) ? _preram_cbmem_console : 0;
-	_epreram_cbmem_console = DEFINED(_epreram_cbmem_console) ? _epreram_cbmem_console : 0;
 	. = ALIGN(8);
 }
 
diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c
index 4b5f4d4..d700091 100644
--- a/src/lib/timestamp.c
+++ b/src/lib/timestamp.c
@@ -157,7 +157,7 @@ void timestamp_init(uint64_t base)
 #endif
 }
 
-void timestamp_reinit(void)
+static void timestamp_reinit(void)
 {
 	if (!timestamp_should_run())
 		return;
@@ -172,8 +172,9 @@ void timestamp_reinit(void)
 		timestamp_do_sync();
 }
 
-/* Call timestamp_reinit at CAR migration time. */
-CAR_MIGRATE(timestamp_reinit)
+/* Call timestamp_reinit CBMEM init hooks. */
+ROMSTAGE_CBMEM_INIT_HOOK(timestamp_reinit)
+RAMSTAGE_CBMEM_INIT_HOOK(timestamp_reinit)
 
 /* Provide default timestamp implementation using monotonic timer. */
 uint64_t  __attribute__((weak)) timestamp_get(void)
diff --git a/src/soc/intel/baytrail/romstage/romstage.c b/src/soc/intel/baytrail/romstage/romstage.c
index 9c8bbc4..921b139 100644
--- a/src/soc/intel/baytrail/romstage/romstage.c
+++ b/src/soc/intel/baytrail/romstage/romstage.c
@@ -157,7 +157,7 @@ static void migrate_power_state(void)
 	}
 	memcpy(ps_cbmem, ps_car, sizeof(*ps_cbmem));
 }
-CAR_MIGRATE(migrate_power_state);
+ROMSTAGE_CBMEM_INIT_HOOK(migrate_power_state)
 
 static struct chipset_power_state *fill_power_state(void)
 {
diff --git a/src/soc/intel/broadwell/romstage/power_state.c b/src/soc/intel/broadwell/romstage/power_state.c
index bdb3da9..097a076 100644
--- a/src/soc/intel/broadwell/romstage/power_state.c
+++ b/src/soc/intel/broadwell/romstage/power_state.c
@@ -50,7 +50,7 @@ static void migrate_power_state(void)
 	}
 	memcpy(ps_cbmem, ps_car, sizeof(*ps_cbmem));
 }
-CAR_MIGRATE(migrate_power_state);
+ROMSTAGE_CBMEM_INIT_HOOK(migrate_power_state)
 
 /* Return 0, 3, or 5 to indicate the previous sleep state. */
 static int prev_sleep_state(struct chipset_power_state *ps)



More information about the coreboot-gerrit mailing list