From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 6E597AC1562 for ; Mon, 20 May 2024 13:50:11 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=K7kpP1mAi2tVCWbTnOy9wnQba4kLnjOQKHgTRKbQ6N8=; c=relaxed/simple; d=groups.io; h=Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20240206; t=1716213010; v=1; b=4kwZLlBkyPQ7TtUNzqxVsmshULPjYGZPPUa0iVJMrSKHmuYqBBpipXijnLAAKgBZCYZs17XU cqRsXLYnjZryo1kJ1gVbTvjSY2RdkaYqg4OwlKKk8V2MZIP+0GySzMyhmUDJKQV8fPOI9Wzvkoc /3AxVYR0IvW90ZnHm2zy0MdSeQ8T/LihE8gAVVJQvxxB7D8ujzmBrClHug2jB+hpNP1eaTHQrG2 A/rF1rZmmVMnt8TbpaA2EwaWVei4BPrq7Vu9V6o6YwljqZ/Mw9CkTQtPTZXQbZe2Pjc/C0IuADP 37WgVoPzEhK/8lKHKmFBoyffV8yeCOyivn5pHLWnW2Qfw== X-Received: by 127.0.0.2 with SMTP id sxdHYY7687511xnJk93VQtfh; Mon, 20 May 2024 06:50:10 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.54]) by mx.groups.io with SMTP id smtpd.web11.61470.1716213004091276120 for ; Mon, 20 May 2024 06:50:04 -0700 X-Received: from BL1PR13CA0203.namprd13.prod.outlook.com (2603:10b6:208:2be::28) by DM6PR12MB4075.namprd12.prod.outlook.com (2603:10b6:5:21d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.35; Mon, 20 May 2024 13:50:00 +0000 X-Received: from BL02EPF0001A101.namprd05.prod.outlook.com (2603:10b6:208:2be:cafe::f) by BL1PR13CA0203.outlook.office365.com (2603:10b6:208:2be::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.16 via Frontend Transport; Mon, 20 May 2024 13:49:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C X-Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A101.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Mon, 20 May 2024 13:49:58 +0000 X-Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 20 May 2024 08:49:57 -0500 X-Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 20 May 2024 08:49:57 -0500 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Mon, 20 May 2024 08:49:55 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Abner Chang , Paul Grimes Subject: [edk2-devel] [edk2-platforms RESEND v2 3/5] AmdMinBoardPkg: Implement BoardInitLib for PEI phase Date: Mon, 20 May 2024 19:19:47 +0530 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A101:EE_|DM6PR12MB4075:EE_ X-MS-Office365-Filtering-Correlation-Id: 0fde3494-a2e2-4202-bd41-08dc78d3bcd0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?vK7N3XabFOtjsrU95kQJmsgBFyqFakR5WgLt8bPvg8oiuCtViQwolFSrfQ45?= =?us-ascii?Q?V2MJJ8L1xRDwwx1pGL736uWjSySqpe+5JyF11FXjfLmoqd1PhO+YqSSPKkbg?= =?us-ascii?Q?nqFb6obm5P2ov2TBM2KT4NrfOP8OD1CaURo8H571agTq0rILn7mi0MHy5nMH?= =?us-ascii?Q?ZuJ7JrzZL96hwGXcfKl343kGe7+5nO3HfGXbgkqd/bfcFg0rgAIf4gxx70dR?= =?us-ascii?Q?Vod8vTh7KbtEbEW8Rk594jiQhPDjJx25eN5EGPRqmQfyIpW1F/TU15oZxkXb?= =?us-ascii?Q?wPKm2MQrjY/sIXVBCaZRpF1Yn2VTN5pH1bZh40WuqCCogHkBUCEg0FClRoEy?= =?us-ascii?Q?sfQQC/7pmjehwkk7k5a8yMC3QjNZ0gFIDPmkzyJW5xO90V4FakImP1OwvBFv?= =?us-ascii?Q?FfJE9BeKtDlFbGC87zCTSBd9aCewNyViOTaOmjlD0c42YXspRBc/albVQsVk?= =?us-ascii?Q?mznVyZ2WjUCN5FT0LZETNBbPCAiS3zig25VShkJtyM/XrMxkon12tzH4tKv3?= =?us-ascii?Q?6z7pHI2LF2vrnkjgxklaQX4q4H58MWH5t5YuO+6cPu8fLQatIm19JslSmMX3?= =?us-ascii?Q?G6Vtts/W/mVocEHlmatK/ZTdWmpTuUQyfoLI6AGReNYcndGxocy7cBLZbhWK?= =?us-ascii?Q?QNe1qKx/0POMiG6iL69mfZkeWB7E0gBEbaodoly8FvfBoeEer6rAmdxcBdpF?= =?us-ascii?Q?Xf+4uHFlN1pOXWOYrWZNnT5qiSZv6xT4h2h/9sMSv4yG4+opDU70Eq4Y4hrc?= =?us-ascii?Q?EnHbBdsJBn2RKFsVeGfA3vi/QRntu+MpLuN4e8dy9TeuhgHgSODCp6hpFrRn?= =?us-ascii?Q?pjnpdOTmBwA5yQgsH0uhLESKaz/X3R8NUywgC2Lu2HOjuZ3/JPWRLpqB83Fn?= =?us-ascii?Q?lQBJtvO/ReHoBbbvKKa+FbyWuFLjRlE7D9pRcBmPMTkf9269uEJJOd9z+Sit?= =?us-ascii?Q?kA2ewlKpbHEAEEmBYVChahH8IvjaZOrYdk9HQKSkQ8Ewe5kNI5g4W36RaS/v?= =?us-ascii?Q?MVM37sCLhhe2m2GUzoVpydYM4I1q9AD6RRu5nL9X9ujuYrLxBcIbLz51Imje?= =?us-ascii?Q?h/j0sH6mK9zsk8X4zgcT1ggSEqOVPIF02GMTf7jpeO7TSkLV0j4GWrn1u1VB?= =?us-ascii?Q?cbSKHSZIgoo+zShXLSNui8PPbbeGAiy7oB+ArZU5ZaugK3nVwlC7iqZOYUEf?= =?us-ascii?Q?Uq1s43dKohSIdPPROkkSMVxeEzzNDAQNLwVqctiquLomXoeMYfEsBlu6Z6pM?= =?us-ascii?Q?Cb9+KSZl30pQEdVmZk6cArjXGCNXZCBaI7nl6Bkx6hL0kKWdvfXMIskKcwTR?= =?us-ascii?Q?omEl4MCCaITsdsiHRgiJcfYULZ3/NuatkM4VYbEpzL4/YtsAqezzoywG9ZwF?= =?us-ascii?Q?mWWRrRs=3D?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2024 13:49:58.0528 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0fde3494-a2e2-4202-bd41-08dc78d3bcd0 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A101.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4075 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Mon, 20 May 2024 06:50:04 -0700 Resent-From: AbdulLateef.Attar@amd.com Reply-To: devel@edk2.groups.io,AbdulLateef.Attar@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Dne6tnZb0sebzXlglhXmPXcdx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=4kwZLlBk; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io PeiBoardInitPreMemLib library provides board-specific initialization functions for the PEI phase. Cc: Abner Chang Cc: Paul Grimes Signed-off-by: Abdul Lateef Attar --- .../AMD/AmdMinBoardPkg/AmdMinBoardPkg.dec | 8 + .../AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc | 5 + .../PeiBoardInitPreMemLib/AmdMemoryInfoHob.h | 50 ++++ .../PeiBoardInitPreMemLib.c | 229 ++++++++++++++++++ .../PeiBoardInitPreMemLib.inf | 45 ++++ .../PeiBoardInitPreMemLib/PeiMemoryInit.c | 198 +++++++++++++++ .../PeiBoardInitPreMemLib/PeiMemoryInit.h | 50 ++++ 7 files changed, 585 insertions(+) create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemL= ib/AmdMemoryInfoHob.h create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemL= ib/PeiBoardInitPreMemLib.c create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemL= ib/PeiBoardInitPreMemLib.inf create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemL= ib/PeiMemoryInit.c create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemL= ib/PeiMemoryInit.h diff --git a/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dec b/Platform/AMD/= AmdMinBoardPkg/AmdMinBoardPkg.dec index 03d1d77c34..98768af210 100644 --- a/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dec +++ b/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dec @@ -19,6 +19,10 @@ =20 [Guids] gAmdMinBoardPkgTokenSpaceGuid =3D {0xd4d23d79, 0x73bf, 0x460a, {0xa1, 0= xc7, 0x85, 0xa3, 0xca, 0x71, 0xb9, 0x4c}} + gAmdMemoryInfoHobGuid =3D { 0x1bce3d14, 0xa5fe, 0x4a0b, { 0x9a,= 0x8d, 0x69, 0xca, 0x5d, 0x98, 0x38, 0xd3}} + +[Ppis] + gAmdMemoryInfoHobPpiGuid =3D { 0xba16e587, 0x1d66, 0x41b7, { 0x9b,= 0x52, 0xca, 0x4f, 0x2c, 0xad, 0x0d, 0xc8}} =20 [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] # @@ -41,3 +45,7 @@ gAmdMinBoardPkgTokenSpaceGuid.PcdAmdFlashFvAdvancedSecuritySize |0x00= 000000|UINT32|0x10000008 gAmdMinBoardPkgTokenSpaceGuid.PcdAmdFlashFvAdvancedSecurityOffset |0x00= 000000|UINT32|0x10000009 =20 + # SMRAM size + # Holds the SMRAM area size, which is reserved for SMRAM operation + # default value 128MB + gAmdMinBoardPkgTokenSpaceGuid.PcdAmdSmramAreaSize |0x08= 000000|UINT64|0x20000100 diff --git a/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc b/Platform/AMD/= AmdMinBoardPkg/AmdMinBoardPkg.dsc index be33089a45..7e356a2a67 100644 --- a/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc +++ b/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc @@ -22,6 +22,9 @@ MinPlatformPkg/MinPlatformPkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 +[PcdsDynamicDefault] + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseSize|0x10000000 + [LibraryClasses] SpcrDeviceLib|AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.inf ReportFvLib|AmdMinBoardPkg/Library/PeiReportFvLib/PeiReportFvLib.inf @@ -38,6 +41,7 @@ =20 [LibraryClasses.common.PEIM] SetCacheMtrrLib|AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.i= nf + BoardInitLib|AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiBoardInitPr= eMemLib.inf =20 [Components] AmdMinBoardPkg/Library/SpcrDeviceLib/SpcrDeviceLib.inf @@ -45,6 +49,7 @@ [Components.IA32] AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.inf AmdMinBoardPkg/Library/PeiReportFvLib/PeiReportFvLib.inf + AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiBoardInitPreMemLib.inf =20 [Components.X64] AmdMinBoardPkg/PciHotPlug/PciHotPlugInit.inf diff --git a/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/AmdM= emoryInfoHob.h b/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/= AmdMemoryInfoHob.h new file mode 100644 index 0000000000..b596b3bdf3 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/AmdMemoryIn= foHob.h @@ -0,0 +1,50 @@ +/** @file + Defines AMD memory info hob. + + Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserv= ed. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef AMD_MEMORY_INFO_HOB_H_ +#define AMD_MEMORY_INFO_HOB_H_ + +#pragma pack (push, 1) + +/// Memory descriptor structure for each memory range +typedef struct { + UINT64 Base; ///< Base address of memory ra= ng + UINT64 Size; ///< Size of memory rang + UINT32 Attribute; ///< Attribute of memory rang + UINT32 Reserved; ///< For alignment purpose +} AMD_MEMORY_RANGE_DESCRIPTOR; + +/// Memory info HOB structure +typedef struct { + UINT32 Version; ///< Version of HO= B structure + BOOLEAN Reserved1; + UINT16 Reserved2; + BOOLEAN Reserved3; + UINT8 Reserved4; + BOOLEAN Reserved5; + UINT32 Reserved6; + UINT32 Reserved7; + UINT32 NumberOfDescriptor; ///< Number of mem= ory range descriptor + AMD_MEMORY_RANGE_DESCRIPTOR Ranges[1]; ///< Memory ranges= array +} AMD_MEMORY_INFO_HOB; + +#pragma pack (pop) + +/// Memory attribute in the memory range descriptor =3D AVAILABLE +#define AMD_MEMORY_ATTRIBUTE_AVAILABLE 0x1 + +/// Memory attribute in the memory range descriptor =3D UMA +#define AMD_MEMORY_ATTRIBUTE_UMA 0x2 + +/// Memory attribute in the memory range descriptor =3D MMIO +#define AMD_MEMORY_ATTRIBUTE_MMIO 0x3 + +/// Memory attribute in the memory range descriptor =3D RESERVED +#define AMD_MEMORY_ATTRIBUTE_RESERVED 0x4 + +#endif diff --git a/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiB= oardInitPreMemLib.c b/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMe= mLib/PeiBoardInitPreMemLib.c new file mode 100644 index 0000000000..af96969471 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiBoardIni= tPreMemLib.c @@ -0,0 +1,229 @@ +/** @file + BoardInitLib library implementation for pre-mem PEI phase. + +Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include "PeiMemoryInit.h" + +EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList =3D { + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH | EFI_PEI_PPI_DESCRIPTOR_TERMINA= TE_LIST), + &gAmdMemoryInfoHobPpiGuid, + EndofAmdMemoryInfoHobPpiGuidCallBack +}; + +/** + Get Pcie base address from MSR and set PcdPciExpressBaseSize + + @retval EFI_SUCCESS PcdPciExpressBaseSize value set successfully. +**/ +EFI_STATUS +EFIAPI +SetPcieBaseSize ( + VOID + ) +{ + EFI_STATUS Status; + UINT64 PcieBaseSize; + UINT8 BusRange; + + Status =3D EFI_SUCCESS; + + // Gather the value of PcdPciExpressBaseSize from MSR + BusRange =3D RShiftU64 (AsmReadMsr64 (0xC0010058), 2) & 0xF; + PcieBaseSize =3D MultU64x64 (LShiftU64 (1, BusRange), SIZE_1MB); + PcdSet64S (PcdPciExpressBaseSize, (UINT64)PcieBaseSize); + return Status; +} + +/** + This board service detects the board type. + + @retval EFI_SUCCESS The board was detected successfully. + @retval EFI_NOT_FOUND The board could not be detected. +**/ +EFI_STATUS +EFIAPI +BoardDetect ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + This board service initializes board-specific debug devices. + + @retval EFI_SUCCESS Board-specific debug initialization was successful= . + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardDebugInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + This board service detects the boot mode. + + @retval EFI_BOOT_MODE The boot mode. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_BOOT_MODE +EFIAPI +BoardBootModeDetect ( + VOID + ) +{ + return BOOT_WITH_FULL_CONFIGURATION; +} + +/** + A hook for board-specific initialization prior to memory initialization. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitBeforeMemoryInit ( + VOID + ) +{ + EFI_STATUS Status; + + Status =3D PeiServicesNotifyPpi (&mNotifyList); + ASSERT_EFI_ERROR (Status); + Status =3D SetPcieBaseSize (); + ASSERT_EFI_ERROR (Status); + return (Status); +} + +/** + A hook for board-specific initialization after memory initialization. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitAfterMemoryInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific initialization prior to disabling temporary RA= M. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitBeforeTempRamExit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific initialization after disabling temporary RAM. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitAfterTempRamExit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific initialization prior to silicon initialization= . + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitBeforeSiliconInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific initialization after silicon initialization. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitAfterSiliconInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific initialization after PCI enumeration. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitAfterPciEnumeration ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific functionality for the ReadyToBoot event. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitReadyToBoot ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + A hook for board-specific functionality for the ExitBootServices event. + + @retval EFI_SUCCESS The board initialization was successful. + @retval EFI_NOT_READY The board has not been detected yet. +**/ +EFI_STATUS +EFIAPI +BoardInitEndOfFirmware ( + VOID + ) +{ + return EFI_SUCCESS; +} diff --git a/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiB= oardInitPreMemLib.inf b/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPre= MemLib/PeiBoardInitPreMemLib.inf new file mode 100644 index 0000000000..9f3cfd47c4 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiBoardIni= tPreMemLib.inf @@ -0,0 +1,45 @@ +## @file +# Board Init Library for AMD Platforms. +# +# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserv= ed +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D PeiBoardInitPreMemLib + FILE_GUID =3D A394D6BE-4433-4564-8FEB-2C90DD9ECE5B + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D BoardInitLib + +[LibraryClasses] + BaseLib + DebugLib + HobLib + PcdLib + +[Packages] + AmdMinBoardPkg/AmdMinBoardPkg.dec + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[Sources] + AmdMemoryInfoHob.h + PeiMemoryInit.h + PeiBoardInitPreMemLib.c + PeiMemoryInit.c + +[Guids] + gAmdMemoryInfoHobGuid + gEfiSmmSmramMemoryGuid + +[Ppis] + gAmdMemoryInfoHobPpiGuid ## CON= SUMES + gPeiPlatformMemorySizePpiGuid ## CON= SUMES + +[Pcd] + gAmdMinBoardPkgTokenSpaceGuid.PcdAmdSmramAreaSize + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseSize ## CON= SUMES diff --git a/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiM= emoryInit.c b/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/Pei= MemoryInit.c new file mode 100644 index 0000000000..03f08214e2 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiMemoryIn= it.c @@ -0,0 +1,198 @@ +/** @file + +Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "PeiMemoryInit.h" +#include "AmdMemoryInfoHob.h" + +/** + A Callback routine only AmdMemoryInfoHob is ready. + + @param[in] PeiServices General purpose services available to ever= y PEIM. + @param[in] NotifyDescriptor The descriptor for the notification event. + @param[in] Ppi The context of the notification. + + @retval EFI_SUCCESS Platform Pre Memory initialization is successful. + EFI_STATUS Various failure from underlying routine calls. +**/ +EFI_STATUS +EFIAPI +EndofAmdMemoryInfoHobPpiGuidCallBack ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +{ + PEI_PLATFORM_MEMORY_SIZE_PPI *PlatformMemorySizePpi; + EFI_STATUS Status; + UINT64 MemorySize; + AMD_MEMORY_INFO_HOB *AmdMemoryInfoHob; + AMD_MEMORY_RANGE_DESCRIPTOR *AmdMemoryInfoRange; + EFI_HOB_GUID_TYPE *GuidHob; + EFI_PEI_HOB_POINTERS Hob; + UINTN Index; + EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; + EFI_PHYSICAL_ADDRESS SmramBaseAddress; + UINT8 SmramRanges; + UINTN DataSize; + + SmramBaseAddress =3D 0; + SmramRanges =3D 0; + + // Locate AMD_MEMORY_INFO_HOB Guided HOB and retrieve data + AmdMemoryInfoHob =3D NULL; + GuidHob =3D GetFirstGuidHob (&gAmdMemoryInfoHobGuid); + if (GuidHob !=3D NULL) { + AmdMemoryInfoHob =3D GET_GUID_HOB_DATA (GuidHob); + } + + if (AmdMemoryInfoHob =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "Error: Could not locate AMD_MEMORY_INFO_HOB.\n")= ); + return EFI_OUT_OF_RESOURCES; + } + + DEBUG ((DEBUG_INFO, "AMD_MEMORY_INFO_HOB at 0x%X\n", AmdMemoryInfoHob)); + DEBUG ((DEBUG_INFO, " Version: 0x%X\n", AmdMemoryInfoHob->Version)); + DEBUG ((DEBUG_INFO, " NumberOfDescriptor: 0x%X\n", AmdMemoryInfoHob->Nu= mberOfDescriptor)); + + // + // Build Descriptors + // + DEBUG ((DEBUG_INFO, "\nAMD HOB Descriptors:")); + for (Index =3D 0; Index < AmdMemoryInfoHob->NumberOfDescriptor; Index++)= { + AmdMemoryInfoRange =3D (AMD_MEMORY_RANGE_DESCRIPTOR *)&(AmdMemoryInfoH= ob->Ranges[Index]); + + DEBUG ((DEBUG_INFO, "\n Index: %d\n", Index)); + DEBUG ((DEBUG_INFO, " Base: 0x%lX\n", AmdMemoryInfoRange->Base)); + DEBUG ((DEBUG_INFO, " Size: 0x%lX\n", AmdMemoryInfoRange->Size)); + DEBUG ((DEBUG_INFO, " Attribute: 0x%X\n", AmdMemoryInfoRange->Attrib= ute)); + + switch (AmdMemoryInfoRange->Attribute) { + case AMD_MEMORY_ATTRIBUTE_AVAILABLE: + if (AmdMemoryInfoRange->Base < SIZE_4GB) { + SmramRanges =3D 1u; + // Set SMRAM base at heighest range below 4GB + SmramBaseAddress =3D AmdMemoryInfoRange->Base + AmdMemoryInfoRan= ge->Size - FixedPcdGet32 (PcdAmdSmramAreaSize); + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_RESERVED, + (EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE | EFI_RESOURCE_AT= TRIBUTE_UNCACHEABLE), + SmramBaseAddress, + FixedPcdGet32 (PcdAmdSmramAreaSize) + ); + DEBUG (( + DEBUG_INFO, + "SMRAM RESERVED_MEMORY: Base =3D 0x%lX, Size =3D 0x%lX\n", + SmramBaseAddress, + FixedPcdGet32 (PcdAmdSmramAreaSize) + )); + + AmdMemoryInfoRange->Size -=3D FixedPcdGet32 (PcdAmdSmramAreaSize= ); + } + + if (AmdMemoryInfoRange->Size) { + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + SYSTEM_MEMORY_ATTRIBUTES, + AmdMemoryInfoRange->Base, + AmdMemoryInfoRange->Size + ); + + DEBUG (( + DEBUG_INFO, + "SYSTEM_MEMORY: Base =3D 0x%lX, Size =3D 0x%lX\n", + AmdMemoryInfoRange->Base, + AmdMemoryInfoRange->Size + )); + } + + break; + + case AMD_MEMORY_ATTRIBUTE_MMIO: + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_MAPPED_IO, + MEMORY_MAPPED_IO_ATTRIBUTES, + AmdMemoryInfoRange->Base, + AmdMemoryInfoRange->Size + ); + + DEBUG (( + DEBUG_INFO, + "MMIO: Base =3D 0x%lX, Size =3D 0x%lX\n", + AmdMemoryInfoRange->Base, + AmdMemoryInfoRange->Size + )); + break; + + case AMD_MEMORY_ATTRIBUTE_RESERVED: + case AMD_MEMORY_ATTRIBUTE_UMA: + default: + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_RESERVED, + 0, + AmdMemoryInfoRange->Base, + AmdMemoryInfoRange->Size + ); + + DEBUG (( + DEBUG_INFO, + "RESERVED_MEMORY: Base =3D 0x%lX, Size =3D 0x%lX\n", + AmdMemoryInfoRange->Base, + AmdMemoryInfoRange->Size + )); + break; + } + } + + ASSERT (SmramRanges > 0); + DataSize =3D sizeof (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK); + DataSize +=3D ((SmramRanges - 1) * sizeof (EFI_SMRAM_DESCRIPTOR)); + + Hob.Raw =3D BuildGuidHob ( + &gEfiSmmSmramMemoryGuid, + DataSize + ); + ASSERT (Hob.Raw); + + SmramHobDescriptorBlock =3D (EFI_SMRAM_HOB_= DESCRIPTOR_BLOCK *)(Hob.Raw); + SmramHobDescriptorBlock->NumberOfSmmReservedRegions =3D SmramRanges; + SmramHobDescriptorBlock->Descriptor[0].PhysicalStart =3D SmramBaseAddres= s; + SmramHobDescriptorBlock->Descriptor[0].CpuStart =3D SmramBaseAddres= s; + SmramHobDescriptorBlock->Descriptor[0].PhysicalSize =3D FixedPcdGet32 (= PcdAmdSmramAreaSize); + SmramHobDescriptorBlock->Descriptor[0].RegionState =3D EFI_SMRAM_CLOSE= D | EFI_CACHEABLE; + + Status =3D PeiServicesLocatePpi ( + &gPeiPlatformMemorySizePpiGuid, + 0, + NULL, + (VOID **)&PlatformMemorySizePpi + ); + ASSERT_EFI_ERROR (Status); + + Status =3D PlatformMemorySizePpi->GetPlatformMemorySize ( + PeiServices, + PlatformMemorySizePpi, + &MemorySize + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Error(%r) in getting Platform Memory size.\n", + __func__, + Status + )); + return Status; + } + + DEBUG (( + DEBUG_INFO, + "Installing PeiMemory, BaseAddress =3D 0x%x, Size =3D 0x%x\n", + 0, + MemorySize + )); + Status =3D PeiServicesInstallPeiMemory (0, MemorySize); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiM= emoryInit.h b/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/Pei= MemoryInit.h new file mode 100644 index 0000000000..726db25543 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/PeiBoardInitPreMemLib/PeiMemoryIn= it.h @@ -0,0 +1,50 @@ +/** @file + This file contains definitions required for memory initialization in PEI= phase. + + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef PEI_MEMORY_INIT_PEI_H_ +#define PEI_MEMORY_INIT_PEI_H_ + +#include +#include +#include +#include +#include +#include +#include + +#define SYSTEM_MEMORY_ATTRIBUTES ( \ + EFI_RESOURCE_ATTRIBUTE_PRESENT | \ + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \ + EFI_RESOURCE_ATTRIBUTE_TESTED | \ + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | \ + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | \ + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | \ + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE \ + ) + +#define MEMORY_MAPPED_IO_ATTRIBUTES ( \ + EFI_RESOURCE_ATTRIBUTE_PRESENT | \ + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \ + EFI_RESOURCE_ATTRIBUTE_TESTED | \ + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE \ + ) + +/** + A Callback routine only AmdMemoryInfoHob is ready. + + @retval EFI_SUCCESS Platform Pre Memory initialization is successfull. + EFI_STATUS Various failure from underlying routine calls. +**/ +EFI_STATUS +EFIAPI +EndofAmdMemoryInfoHobPpiGuidCallBack ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ); + +#endif // PEI_MEMORY_INIT_PEI_H_ --=20 2.34.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119082): https://edk2.groups.io/g/devel/message/119082 Mute This Topic: https://groups.io/mt/106203334/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-