From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.77]) by mx.groups.io with SMTP id smtpd.web12.6985.1589434268553470675 for ; Wed, 13 May 2020 22:31:09 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nxp1.onmicrosoft.com header.s=selector2-nxp1-onmicrosoft-com header.b=AHuhxmLN; spf=pass (domain: oss.nxp.com, ip: 40.107.20.77, mailfrom: pankaj.bansal@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ia2Km+CxJdwjhM2sQiuol17bWm8fJTzXvX0cRKBwTNKrYYvY9tsuFZw1S/jO+4QpV51/ftxxdPYRK3ybEATsx++pfYlmMJM6NCQLXBUGeAa65n0hXGeNSWF2UL8v5ZqgQJPEkd+x+7YqpfjfDtI4Uuvt8IUDFxua1LTHFjEBW5Mb3xZOlS7Iok+hkqfc2+B6M3QNzsxqNmThUSTqelFB/njrm3gy4UCiBh1Cj60j9eBKO1/piBZKX5FV8r+GIAAcJf+rQwBo8zSQXPZ0DQY/w6FJV9h0+HPQ9ciWWSJDy6N1ZIc7LBs6nmBHqFbsMg0czZHU59SvYsEqn0Z3uNq9BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UbZnUeLYSfKsYaIFbU17MJDgTrUOVPIfh2WJdqvsuGo=; b=NyaHTdqwNG0gsqPW1wkabVFgVPdF9ccv1Xi8zw8Z4FnCFL1Ldt3qYiAEAIGPnj3unALftsbIN1o3HVZly0QQJT1Fw1DSPjV5dM2ALTX/aq6mMfKatRNLGiDDPvcGtzEcScOFM/GkRPFajyKQdi5Fv4kg1Q94nuLybiTRSuW1zoBaZg4wlmq1sYUUpPrcz06e01wFBCCnOyVlmXPl0JAUSIOzY609KPFicjyr12HP6AcnqXjB3HRljxVpser8TV7I8E2WUg9Myh76SxEFXE6U/yrybdzzWjo/pBsNkQhS6AxD1e5wnCiqaXh5EkbQdfR9NNqJAXCaZRli2rRpPTP3Dw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UbZnUeLYSfKsYaIFbU17MJDgTrUOVPIfh2WJdqvsuGo=; b=AHuhxmLNtD2vS7BMcBMRGiUOTlthXsp43dBhYGmvnPEykE815Sy3JZLhlE5NU8Ihyq1N/z2IQdIdKBwSoTvJ2HOrjc9FfUrdQObfhnJk8gNi/eUjDde09sodPorL4Paanvlhc9666k86swgnltlOCHzL7h2LmSa9xMiRiv34TlM= Authentication-Results: nuviainc.com; dkim=none (message not signed) header.d=none;nuviainc.com; dmarc=none action=none header.from=oss.nxp.com; Received: from VI1PR04MB5933.eurprd04.prod.outlook.com (2603:10a6:803:ec::16) by VI1PR04MB4381.eurprd04.prod.outlook.com (2603:10a6:803:6d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.24; Thu, 14 May 2020 05:31:06 +0000 Received: from VI1PR04MB5933.eurprd04.prod.outlook.com ([fe80::45c4:8846:5327:9513]) by VI1PR04MB5933.eurprd04.prod.outlook.com ([fe80::45c4:8846:5327:9513%7]) with mapi id 15.20.2979.033; Thu, 14 May 2020 05:31:06 +0000 From: "Pankaj Bansal" To: Leif Lindholm , Meenakshi Aggarwal , Michael D Kinney , devel@edk2.groups.io, Varun Sethi , Samer El-Haj-Mahmoud , Jon Nettleton , Ard Biesheuvel Subject: [PATCH edk2-platforms v5 12/24] Silicon/NXP: Move RAM retrieval from SocLib Date: Fri, 15 May 2020 10:59:52 +0530 Message-ID: <20200515052952.20914-2-pankaj.bansal@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200515052952.20914-1-pankaj.bansal@oss.nxp.com> References: <20200515052952.20914-1-pankaj.bansal@oss.nxp.com> X-ClientProxiedBy: SG2PR03CA0085.apcprd03.prod.outlook.com (2603:1096:4:7c::13) To VI1PR04MB5933.eurprd04.prod.outlook.com (2603:10a6:803:ec::16) Return-Path: pankaj.bansal@oss.nxp.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from uefi-workstation.ap.freescale.net (92.120.0.69) by SG2PR03CA0085.apcprd03.prod.outlook.com (2603:1096:4:7c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.10 via Frontend Transport; Thu, 14 May 2020 05:31:03 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [92.120.0.69] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 557b3521-f2cb-4d18-720c-08d7f7c7ffe6 X-MS-TrafficTypeDiagnostic: VI1PR04MB4381: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-Forefront-PRVS: 040359335D X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6YG/hwJk3fuuf3I6GWaOnPobVEnR3nyGBkXy91FYvWs4Ek5Y9Bj0y/i29s0JbC71bMI2MKUgE493VWosIN9vi3dVeavl7QSq2/xhKbtv9XbMKcWUChqhVjuse9fjnqnsDhpVgohvVJ+FfAfHlgFmhH7r80PYQVyKgBiKVDHhPqT5pNwvzzxaXVKFtwCH3QIEqcDmeoiyjhJdPHybvGhfGSlr68/Vfsuy6i0EkX2skFZouoH9z8A4S/Pv7QcwGU2s00CGu2SmPAkWI9bdEyeWB+lcTddfA+yukTqRfPl01nD/HMRWttRjrRTGWJNIMSMn1qOnRIg8fU+vbsuWHhD+s+flBz7C1cMx/PFRFyGhfckZ/927qBfggvW8fKnEAqLrSX+yKvXAS7VFzpWeJ7pUyLPSNLwD/ePiiDpeoRaHK6It1OATewCRlj+TDpyhspfC X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5933.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(366004)(396003)(136003)(346002)(376002)(39860400002)(6506007)(6666004)(8676002)(52116002)(316002)(44832011)(478600001)(186003)(6512007)(16526019)(19627235002)(5660300002)(66476007)(66556008)(1076003)(66946007)(8936002)(956004)(110136005)(86362001)(2906002)(2616005)(6486002)(30864003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: oJmRmRQvCQyx6H7lDWu2p6FfuN/f/vfhNASYNkVZe+tt17RUtUkMAxGUcFsZAEODHEymLtFMlh/bUCcdWD5Rz5Gm/uM/RsKzi78tT25M3ROsjMIJd93+U93dESPJspEKLnpHeXcmK75/9VyW8/tyTzqRaOKH3ac3WZleWYxvvBfPZuwY/cRptC/Hkzlprk+IscxX6yBd8C47we251JGS3PgFL0GAjpuwZkwWzpsyHGdwvCUUH2dR2CO3dw4aaKd4z3H6k4aGgGQMk0YDf2t8mcX7KTjX+mH1FTx27HtwFGwPZi121JvUlCUrHXslugHx3yBxpiweLy2mlU6LWn9/SxfuCpIFDJCPSGLyGChAnQxoLPaSdNvNEaUJpAz82V26KBgREb962Q0iN+WPsCx/PDTy1dFPDcTxPjQqssxmokXpIUR+Bt2VlhQCQrVk2kYbHutsuM3nLgUnmoBL5iDLe4Wetd92rH4t8W4mvreJdts= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 557b3521-f2cb-4d18-720c-08d7f7c7ffe6 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 05:31:06.3527 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Mf0MfYfb+N4NHJoHtH2Vw1IKzJrrapgkynpjLmnggqFlFM2b5agvx2BCGlJcVzv6Zrdoo1q4/Ra3GYrOisFWxw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4381 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Pankaj Bansal RAM retrieval using SMC commands is common to all Layerscape SOCs. Therefore, move it to common MemoryInit Pei Lib. Signed-off-by: Pankaj Bansal --- Notes: V5: - Add SMC_DRAM_TOTAL_DRAM_ARG1 to denote the x1 argument to pass to SMC call to retrieve the total DRAM size - cast away the return from GetDramRegionsInfo using (VOID)GetDramRegio= nsInfo - remove unused variable Status from MemoryPeim. =20 V4: - fixed line adds white space error in MemoryInitPeiLib.h - Added SMC_OK and SMC_UOK Macros to denote the return values from SMC calls - Added explanation for SMC_DRAM_BANK_INFO and DRAM_REGION_INFO in MemoryInitPeiLib.h - Modified GetDramSize to check for return value of SMC call against SMC_OK. Also added comments when returning 0 from this function - Modified GetDramRegionsInfo for loop and return values as per Leif's suggestion. Also added DEBUG_ERROR in case of return BUFFER_TOO_SMALL= . - Added SMC_OK in GetDramRegionsInfo - Check for GetDramRegionsInfo return value in MemoryPeim - regios -> regions =20 V3: - sort headers alphabetically - Moved DRAM region retrieval and Total DRAM size retrieval to separate functions - Fixed MemoryPeim function description - Modified check on FoundSystemMem =3D TRUE to check the RAM region aga= inst MemoryPeim function input arguments UefiMemoryBase and UefiMemorySize - (!DramRegions[Index].Size) =3D> (DramRegions[Index].Size =3D=3D 0) - (FoundSystemMem) =3D> (FoundSystemMem =3D=3D TRUE) - Added explanation for starting for loop from the last DRAM region Silicon/NXP/Library/MemoryInitPei/MemoryInitPeiLib.inf | 7 +- Silicon/NXP/Library/SocLib/LS1043aSocLib.inf | 1 - Silicon/NXP/Include/DramInfo.h | 38 ---- Silicon/NXP/Library/MemoryInitPei/MemoryInitPeiLib.h | 40 ++++ Silicon/NXP/Library/MemoryInitPei/MemoryInitPeiLib.c | 203 +++++++++++++= +++---- Silicon/NXP/Library/SocLib/Chassis.c | 67 ------- 6 files changed, 211 insertions(+), 145 deletions(-) diff --git a/Silicon/NXP/Library/MemoryInitPei/MemoryInitPeiLib.inf b/Silic= on/NXP/Library/MemoryInitPei/MemoryInitPeiLib.inf index a5bd39415def..ad2371115b17 100644 --- a/Silicon/NXP/Library/MemoryInitPei/MemoryInitPeiLib.inf +++ b/Silicon/NXP/Library/MemoryInitPei/MemoryInitPeiLib.inf @@ -18,7 +18,6 @@ [Sources] MemoryInitPeiLib.c =20 - [Packages] ArmPkg/ArmPkg.dec ArmPlatformPkg/ArmPlatformPkg.dec @@ -30,6 +29,7 @@ [LibraryClasses] ArmMmuLib ArmPlatformLib + ArmSmcLib DebugLib HobLib PcdLib @@ -40,6 +40,11 @@ [FeaturePcd] gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob =20 +[FixedPcd] + gArmTokenSpaceGuid.PcdFdBaseAddress + gArmTokenSpaceGuid.PcdFdSize + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize + [Pcd] gArmTokenSpaceGuid.PcdSystemMemoryBase gArmTokenSpaceGuid.PcdSystemMemorySize diff --git a/Silicon/NXP/Library/SocLib/LS1043aSocLib.inf b/Silicon/NXP/Lib= rary/SocLib/LS1043aSocLib.inf index b7c7fc78cc8f..99d89498e0e2 100644 --- a/Silicon/NXP/Library/SocLib/LS1043aSocLib.inf +++ b/Silicon/NXP/Library/SocLib/LS1043aSocLib.inf @@ -20,7 +20,6 @@ Silicon/NXP/NxpQoriqLs.dec =20 [LibraryClasses] - ArmSmcLib BaseLib DebugLib IoAccessLib diff --git a/Silicon/NXP/Include/DramInfo.h b/Silicon/NXP/Include/DramInfo.= h deleted file mode 100644 index a934aaeff1f5..000000000000 --- a/Silicon/NXP/Include/DramInfo.h +++ /dev/null @@ -1,38 +0,0 @@ -/** @file -* Header defining the structure for Dram Information -* -* Copyright 2019 NXP -* -* SPDX-License-Identifier: BSD-2-Clause-Patent -* -**/ - -#ifndef DRAM_INFO_H_ -#define DRAM_INFO_H_ - -#include - -#define SMC_DRAM_BANK_INFO (0xC200FF12) - -typedef struct { - UINTN BaseAddress; - UINTN Size; -} DRAM_REGION_INFO; - -typedef struct { - UINT32 NumOfDrams; - UINT32 Reserved; - DRAM_REGION_INFO DramRegion[3]; -} DRAM_INFO; - -EFI_STATUS -GetDramBankInfo ( - IN OUT DRAM_INFO *DramInfo - ); - -VOID -UpdateDpaaDram ( - IN OUT DRAM_INFO *DramInfo - ); - -#endif /* DRAM_INFO_H_ */ diff --git a/Silicon/NXP/Library/MemoryInitPei/MemoryInitPeiLib.h b/Silicon= /NXP/Library/MemoryInitPei/MemoryInitPeiLib.h new file mode 100644 index 000000000000..520277d45c95 --- /dev/null +++ b/Silicon/NXP/Library/MemoryInitPei/MemoryInitPeiLib.h @@ -0,0 +1,40 @@ +/** @file +* +* Copyright 2020 NXP +* +* SPDX-License-Identifier: BSD-2-Clause-Patent +* +**/ + +#ifndef MEMORY_INIT_PEI_LIB_H_ +#define MEMORY_INIT_PEI_LIB_H_ + +#include + +// Specifies the Maximum regions onto which DDR memory can be mapped in +// a Platform +#define MAX_DRAM_REGIONS 3 + +// Unique SMC call to retrieve the total DDR RAM size installed in system +// and the SOC memory map regions to which DDR RAM is mapped +// This SMC call works in this way: +// x1 =3D -1 : return x0: SMC_OK, x1: total DDR Ram size +// x1 >=3D number of DRAM regions to which DDR RAM is mapped : return x0: = SMC_UNK +// 0 <=3D x1 < number of DRAM regions to which DDR RAM is mapped : return +// x0: SMC_OK, x1: Base address of DRAM region, +// x2: Size of DRAM region +#define SMC_DRAM_BANK_INFO (0xC200FF12) + +#define SMC_DRAM_TOTAL_DRAM_ARG1 (-1) + +// Return values from SMC calls. return values are always in x0 +#define SMC_OK (0) +#define SMC_UNK (-1) + +// Regions in SOC memory map to which DDR RAM is mapped. +typedef struct { + UINTN BaseAddress; + UINTN Size; +} DRAM_REGION_INFO; + +#endif // MEMORY_INIT_PEI_LIB_H_ diff --git a/Silicon/NXP/Library/MemoryInitPei/MemoryInitPeiLib.c b/Silicon= /NXP/Library/MemoryInitPei/MemoryInitPeiLib.c index 3ea773678667..e4fdc403f121 100644 --- a/Silicon/NXP/Library/MemoryInitPei/MemoryInitPeiLib.c +++ b/Silicon/NXP/Library/MemoryInitPei/MemoryInitPeiLib.c @@ -12,13 +12,15 @@ =20 #include #include +#include #include #include #include #include #include =20 -#include +#include "MemoryInitPeiLib.h" + =20 VOID BuildMemoryTypeInformationHob ( @@ -44,22 +46,88 @@ InitMmu ( } } =20 -/*++ +STATIC +UINTN +GetDramSize ( + IN VOID + ) +{ + ARM_SMC_ARGS ArmSmcArgs; =20 -Routine Description: + ArmSmcArgs.Arg0 =3D SMC_DRAM_BANK_INFO; + ArmSmcArgs.Arg1 =3D SMC_DRAM_TOTAL_DRAM_ARG1; =20 + ArmCallSmc (&ArmSmcArgs); =20 + if (ArmSmcArgs.Arg0 =3D=3D SMC_OK) { + return ArmSmcArgs.Arg1; + } =20 -Arguments: + // return 0 means no DDR found. + return 0; +} =20 - FileHandle - Handle of the file being invoked. - PeiServices - Describes the list of possible PEI Services. +STATIC +EFI_STATUS +GetDramRegionsInfo ( + OUT DRAM_REGION_INFO *DramRegions, + IN UINT32 NumRegions + ) +{ + ARM_SMC_ARGS ArmSmcArgs; + UINT32 Index; + UINTN RemainingDramSize; + UINTN BaseAddress; + UINTN Size; =20 -Returns: + RemainingDramSize =3D GetDramSize (); + DEBUG ((DEBUG_INFO, "DRAM Total Size 0x%lx \n", RemainingDramSize)); =20 - Status - EFI_SUCCESS if the boot mode could be set + // Ensure Total Dram Size is valid + ASSERT (RemainingDramSize !=3D 0); =20 ---*/ + for (Index =3D 0; Index < NumRegions; Index++) { + ArmSmcArgs.Arg0 =3D SMC_DRAM_BANK_INFO; + ArmSmcArgs.Arg1 =3D Index; + + ArmCallSmc (&ArmSmcArgs); + + if (ArmSmcArgs.Arg0 =3D=3D SMC_OK) { + BaseAddress =3D ArmSmcArgs.Arg1; + Size =3D ArmSmcArgs.Arg2; + ASSERT (BaseAddress && Size); + + DramRegions[Index].BaseAddress =3D BaseAddress; + DramRegions[Index].Size =3D Size; + RemainingDramSize -=3D Size; + + DEBUG ((DEBUG_INFO, "DRAM Region[%d]: start 0x%lx, size 0x%lx\n", + Index, BaseAddress, Size)); + + if (RemainingDramSize =3D=3D 0) { + return EFI_SUCCESS; + } + } else { + break; + } + } + + DEBUG ((DEBUG_ERROR, "RemainingDramSize =3D %u !! Ensure that all DDR re= gions " + "have been accounted for\n", RemainingDramSize)); + + return EFI_BUFFER_TOO_SMALL; +} + +/** + Get the installed RAM information. + Initialize MMU and Memory HOBs (Resource Descriptor HOBs) + + @param[in] UefiMemoryBase Base address of region used by UEFI in + permanent memory + @param[in] UefiMemorySize Size of the region used by UEFI in permanent = memory + + @return EFI_SUCCESS Successfuly Initialize MMU and Memory HOBs. +**/ EFI_STATUS EFIAPI MemoryPeim ( @@ -67,11 +135,16 @@ MemoryPeim ( IN UINT64 UefiMemorySize ) { - ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; - EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; - EFI_PEI_HOB_POINTERS NextHob; - BOOLEAN Found; - DRAM_INFO DramInfo; + ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; + INT32 Index; + UINTN BaseAddress; + UINTN Size; + UINTN Top; + DRAM_REGION_INFO DramRegions[MAX_DRAM_REGIONS]; + EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; + UINTN FdBase; + UINTN FdTop; + BOOLEAN FoundSystemMem; =20 // Get Virtual Memory Map from the Platform Library ArmPlatformGetVirtualMemoryMap (&MemoryTable); @@ -94,40 +167,94 @@ MemoryPeim ( EFI_RESOURCE_ATTRIBUTE_TESTED ); =20 - if (GetDramBankInfo (&DramInfo)) { - DEBUG ((DEBUG_ERROR, "Failed to get DRAM information, exiting...\n")); - return EFI_UNSUPPORTED; - } + FoundSystemMem =3D FALSE; + ZeroMem (DramRegions, sizeof (DramRegions)); =20 - while (DramInfo.NumOfDrams--) { - // - // Check if the resource for the main system memory has been declared - // - Found =3D FALSE; - NextHob.Raw =3D GetHobList (); - while ((NextHob.Raw =3D GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, = NextHob.Raw)) !=3D NULL) { - if ((NextHob.ResourceDescriptor->ResourceType =3D=3D EFI_RESOURCE_SY= STEM_MEMORY) && - (DramInfo.DramRegion[DramInfo.NumOfDrams].BaseAddress >=3D NextH= ob.ResourceDescriptor->PhysicalStart) && - (NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDes= criptor->ResourceLength <=3D - DramInfo.DramRegion[DramInfo.NumOfDrams].BaseAddress + DramInfo= .DramRegion[DramInfo.NumOfDrams].Size)) - { - Found =3D TRUE; - break; - } - NextHob.Raw =3D GET_NEXT_HOB (NextHob); + (VOID)GetDramRegionsInfo (DramRegions, ARRAY_SIZE (DramRegions)); + + FdBase =3D (UINTN)FixedPcdGet64 (PcdFdBaseAddress); + FdTop =3D FdBase + (UINTN)FixedPcdGet32 (PcdFdSize); + + // Declare memory regions to system + // The DRAM region info is sorted based on the RAM address is SOC memory= map. + // i.e. DramRegions[0] is at lower address, as compared to DramRegions[1= ]. + // The goal to start from last region is to find the topmost RAM region = that + // can contain UEFI DXE region i.e. PcdSystemMemoryUefiRegionSize. + // If UEFI were to allocate any reserved or runtime region, it would be + // allocated from topmost RAM region. + // This ensures that maximum amount of lower RAM (32 bit addresses) are = left + // for OS to allocate to devices that can only work with 32bit physical + // addresses. E.g. legacy devices that need to DMA to 32bit addresses. + for (Index =3D MAX_DRAM_REGIONS - 1; Index >=3D 0; Index--) { + if (DramRegions[Index].Size =3D=3D 0) { + continue; } =20 - if (!Found) { - // Reserved the memory space occupied by the firmware volume + BaseAddress =3D DramRegions[Index].BaseAddress; + Top =3D DramRegions[Index].BaseAddress + DramRegions[Index].Size; + + // EDK2 does not have the concept of boot firmware copied into DRAM. + // To avoid the DXE core to overwrite this area we must create a memor= y + // allocation HOB for the region, but this only works if we split off = the + // underlying resource descriptor as well. + if (FdBase >=3D BaseAddress && FdTop <=3D Top) { + // Update Size + Size =3D FdBase - BaseAddress; + if (Size) { + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + ResourceAttributes, + BaseAddress, + Size + ); + } + // create the System Memory HOB for the firmware BuildResourceDescriptorHob ( EFI_RESOURCE_SYSTEM_MEMORY, ResourceAttributes, - DramInfo.DramRegion[DramInfo.NumOfDrams].BaseAddress, - DramInfo.DramRegion[DramInfo.NumOfDrams].Size + FdBase, + PcdGet32 (PcdFdSize) ); + // Create the System Memory HOB for the remaining region (top of the= FD)s + Size =3D Top - FdTop; + if (Size) { + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + ResourceAttributes, + FdTop, + Size + ); + }; + // Mark the memory covering the Firmware Device as boot services dat= a + BuildMemoryAllocationHob (FixedPcdGet64 (PcdFdBaseAddress), + FixedPcdGet32 (PcdFdSize), + EfiBootServicesData); + } else { + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + ResourceAttributes, + DramRegions[Index].BaseAddress, + DramRegions[Index].Size + ); + } + + if (FoundSystemMem =3D=3D TRUE) { + continue; + } + + Size =3D DramRegions[Index].Size; + + if (FdBase >=3D BaseAddress && FdTop <=3D Top) { + Size -=3D (UINTN)FixedPcdGet32 (PcdFdSize); + } + + if ((UefiMemoryBase >=3D BaseAddress) && (Size >=3D UefiMemorySize)) { + FoundSystemMem =3D TRUE; } } =20 + ASSERT (FoundSystemMem =3D=3D TRUE); + // Build Memory Allocation Hob InitMmu (MemoryTable); =20 diff --git a/Silicon/NXP/Library/SocLib/Chassis.c b/Silicon/NXP/Library/Soc= Lib/Chassis.c index 847331a63152..1ef99e8de25f 100644 --- a/Silicon/NXP/Library/SocLib/Chassis.c +++ b/Silicon/NXP/Library/SocLib/Chassis.c @@ -22,7 +22,6 @@ #include #include =20 -#include #include "NxpChassis.h" =20 UINT32 @@ -75,69 +74,3 @@ SmmuInit ( MmioWrite32 ((UINTN)SMMU_REG_NSCR0, Value); } =20 -UINTN -GetDramSize ( - IN VOID - ) -{ - ARM_SMC_ARGS ArmSmcArgs; - - ArmSmcArgs.Arg0 =3D SMC_DRAM_BANK_INFO; - ArmSmcArgs.Arg1 =3D -1; - - ArmCallSmc (&ArmSmcArgs); - - if (ArmSmcArgs.Arg0) { - return 0; - } else { - return ArmSmcArgs.Arg1; - } -} - -EFI_STATUS -GetDramBankInfo ( - IN OUT DRAM_INFO *DramInfo - ) -{ - ARM_SMC_ARGS ArmSmcArgs; - UINT32 I; - UINTN DramSize; - - DramSize =3D GetDramSize (); - DEBUG ((DEBUG_INFO, "DRAM Total Size 0x%lx \n", DramSize)); - - // Ensure DramSize has been set - ASSERT (DramSize !=3D 0); - - I =3D 0; - - do { - ArmSmcArgs.Arg0 =3D SMC_DRAM_BANK_INFO; - ArmSmcArgs.Arg1 =3D I; - - ArmCallSmc (&ArmSmcArgs); - if (ArmSmcArgs.Arg0) { - if (I > 0) { - break; - } else { - ASSERT (ArmSmcArgs.Arg0 =3D=3D 0); - } - } - - DramInfo->DramRegion[I].BaseAddress =3D ArmSmcArgs.Arg1; - DramInfo->DramRegion[I].Size =3D ArmSmcArgs.Arg2; - - DramSize -=3D DramInfo->DramRegion[I].Size; - - DEBUG ((DEBUG_INFO, "bank[%d]: start 0x%lx, size 0x%lx\n", - I, DramInfo->DramRegion[I].BaseAddress, DramInfo->DramRegion[I].Size= )); - - I++; - } while (DramSize); - - DramInfo->NumOfDrams =3D I; - - DEBUG ((DEBUG_INFO, "Number Of DRAM in system %d \n", DramInfo->NumOfDra= ms)); - - return EFI_SUCCESS; -} --=20 2.17.1