usbdebug: Initialize the HW once in CAR stages

The EHCI hardware needs to be initialized only once during CAR stages.
Some exception need to be made when a blob messes with the EHCI
hardware. To achieve this add a fixed location in the car.ld linker
script such that the ehci debug information can be shared across CAR
stages.

Currently this means only romstage and bootblock, but verstage can
also be hooked up later on.

Tested on google/peppy: Both the bootblock and the romstage properly
output console.

Change-Id: I78e20a172fd5cc81f366d580f3cce57b9545d7a2
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/30481
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
diff --git a/src/arch/x86/car.ld b/src/arch/x86/car.ld
index 2f0ce50..7b10f43 100644
--- a/src/arch/x86/car.ld
+++ b/src/arch/x86/car.ld
@@ -40,9 +40,9 @@
 	_car_stack_end = .;
 #endif
 	/* The pre-ram cbmem console as well as the timestamp region are fixed
-	 * in size. Therefore place them at the beginning .car.data section
-	 * so that multiple stages (romstage and verstage) have a consistent
-	 * link address of these shared objects. */
+	 * in size. Therefore place them above the car global section so that
+         * multiple stages (romstage and verstage) have a consistent
+         * link address of these shared objects. */
 	PRERAM_CBMEM_CONSOLE(., CONFIG_PRERAM_CBMEM_CONSOLE_SIZE)
 #if IS_ENABLED(CONFIG_PAGING_IN_CACHE_AS_RAM)
 	. = ALIGN(32);
@@ -66,6 +66,9 @@
 	. += 256;
 	_car_drivers_storage_end = .;
 #endif
+	_car_ehci_dbg_info_start = .;
+        . += 64;
+        _car_ehci_dbg_info_end = .;
 	/* _car_global_start and _car_global_end provide symbols to per-stage
 	 * variables that are not shared like the timestamp and the pre-ram
 	 * cbmem console. This is useful for clearing this area on a per-stage
diff --git a/src/arch/x86/include/arch/symbols.h b/src/arch/x86/include/arch/symbols.h
index 704e3bb..9ef6a3b 100644
--- a/src/arch/x86/include/arch/symbols.h
+++ b/src/arch/x86/include/arch/symbols.h
@@ -34,6 +34,8 @@
 extern char _car_stack_end[];
 #define _car_stack_size (_car_stack_end - _car_stack_start)
 
+extern char _car_ehci_dbg_info_start[];
+
 /*
  * The _car_relocatable_data_[start|end] symbols cover CAR data which is
  * relocatable once memory comes online. Variables with CAR_GLOBAL decoration
diff --git a/src/drivers/usb/ehci_debug.c b/src/drivers/usb/ehci_debug.c
index 2020888..4987523 100644
--- a/src/drivers/usb/ehci_debug.c
+++ b/src/drivers/usb/ehci_debug.c
@@ -18,6 +18,7 @@
 #include <console/console.h>
 #include <console/usb.h>
 #include <arch/io.h>
+#include <arch/symbols.h>
 #include <arch/early_variables.h>
 #include <string.h>
 #include <cbmem.h>
@@ -61,6 +62,10 @@
 
 static inline struct ehci_debug_info *dbgp_ehci_info(void)
 {
+	if (IS_ENABLED(CONFIG_USBDEBUG_IN_PRE_RAM)
+	    && (ENV_ROMSTAGE || ENV_BOOTBLOCK || ENV_VERSTAGE))
+		glob_dbg_info_p =
+			(struct ehci_debug_info *)_car_ehci_dbg_info_start;
 	if (car_get_var(glob_dbg_info_p) == NULL)
 		car_set_var(glob_dbg_info_p, &glob_dbg_info);