From bd9ab06808e956135a961566d0644c404b1ab751 Mon Sep 17 00:00:00 2001
From: Felix Held <felix-coreboot@felixheld.de>
Date: Thu, 8 Dec 2022 19:14:43 +0100
Subject: vc/amd/fsp/morgana/FspmUpd: don't use pointers for usb_phy config

The size of a pointer changes between a 32 and 64 bit coreboot build. In
order to be able to use a 32 bit FSP in a 64 bit coreboot build, change
the pointer in the UPDs to a uint32_t to always have a 32 bit field in
the UPD for this. Also make sure that the address of the lcl_usb_phy
struct is located below the 4GB boundary, so that the truncation to 32
bits won't result in pointing to a different memory location than
intended. In this error case, which I don't expect to happen, print an
error and write 0 to mcfg->usb_phy_ptr so that the FSP will use its
default values.

Signed-off-by: Felix Held <felix-coreboot@felixheld.de>
Change-Id: I1394aa6ef5f401e0c7bdd4861f1e28ae46e56e4f
Reviewed-on: https://review.coreboot.org/c/coreboot/+/70505
Reviewed-by: Fred Reitberger <reitbergerfred@gmail.com>
Reviewed-by: Matt DeVillier <matt.devillier@amd.corp-partner.google.com>
Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
---
 src/soc/amd/morgana/fsp_m_params.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

(limited to 'src/soc/amd')

diff --git a/src/soc/amd/morgana/fsp_m_params.c b/src/soc/amd/morgana/fsp_m_params.c
index 0c51c1afb8..0b4bf2acc0 100644
--- a/src/soc/amd/morgana/fsp_m_params.c
+++ b/src/soc/amd/morgana/fsp_m_params.c
@@ -7,6 +7,7 @@
 #include <amdblocks/ioapic.h>
 #include <amdblocks/memmap.h>
 #include <assert.h>
+#include <console/console.h>
 #include <console/uart.h>
 #include <device/device.h>
 #include <fsp/api.h>
@@ -158,9 +159,15 @@ void platform_fsp_memory_init_params_cb(FSPM_UPD *mupd, uint32_t version)
 		lcl_usb_phy.Version_Major = FSP_USB_STRUCT_MAJOR_VERSION;
 		lcl_usb_phy.Version_Minor = FSP_USB_STRUCT_MINOR_VERSION;
 		lcl_usb_phy.TableLength = sizeof(struct usb_phy_config);
-		mcfg->usb_phy = &lcl_usb_phy;
+		if ((uintptr_t)&lcl_usb_phy <= UINT32_MAX) {
+			mcfg->usb_phy_ptr = (uint32_t)(uintptr_t)&lcl_usb_phy;
+		} else {
+			printk(BIOS_ERR, "USB PHY config struct above 4GB; can't pass USB PHY "
+					 "configuration to 32 bit FSP.\n");
+			mcfg->usb_phy_ptr = 0;
+		}
 	} else {
-		mcfg->usb_phy = NULL;
+		mcfg->usb_phy_ptr = 0;
 	}
 
 	fsp_fill_pcie_ddi_descriptors(mcfg);
-- 
cgit v1.2.3