From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.110]) by mx.groups.io with SMTP id smtpd.web11.5266.1635932365780450575 for ; Wed, 03 Nov 2021 02:39:26 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=U/7+SzcQ; spf=pass (domain: os.amperecomputing.com, ip: 40.107.237.110, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JlNvnneVyAsYUi3N4dNQsLu3UOjlkFna6IIY/dwjcs3bXC+BS/W5wl0KFX7/lQZPcyHCfOQydufcMCob9cidayaUtFZlTOUHroUplk/MUkOIgmeGvsUp3nJjGqRc2QUouq3lkkh4Fmz5fY6BcreLEZLGLwkwr+suOcjoU/mFanNv0Xffu1xBD8ngSV1ml5GnX0KB2MrppFRx5oNKrnLW4kqPqGaGq/uCn1k1MAYHDmcM5PgaRb32fXqLHnefQ4ZPkmGU0h2VeAuP19olj5PwV4lYKm6hQ5FBSktlfW963VcvqEnx2Ubw2Z5CqLNzCkrgP64uSlM+reP8gQh5eKyoKg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zLRv30PXM/GRnFyBM9ZooVXCF3PY0CSF7g7SH60dfJE=; b=Mvo+FJ6RvNQcQthjOtd386U/zN7YMZ88rWRtc1p92tdLmrNmNlDhxPSdjEvCxVU7RP5WWh5f0c0dyK80zQ4DwhWuo4em2c1x4FyjwcgqKW/EbeITxXao+HcBzGieqRmGsN3ej4ojBxBkPd/mHqdoOy/sodjhSO3Dhao4XZsPxS5lR/tPQxL4i2fw8ogyEE3dIHETkNtqUaWj//JxhpzqqPbXu1C6a0iSsVVeHvT2GYZZOibu392b3CnFMPPLq/dF9elc558ByBsZr3mkIP8vcOav2yFzTOGdv/TX2Dsq7COoF05v0yWpD6SklOHYvWqsAaApImsCvK37+MpSYxAYUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zLRv30PXM/GRnFyBM9ZooVXCF3PY0CSF7g7SH60dfJE=; b=U/7+SzcQSdRHp6XnCyUHVFsy/6U309w/E5uvZEDH0nprqglxkow70B+Hpfei0lKvqBrShShK9fxCtGwSvDRfOsDO2ozRnLn6gUWv3NSsBpjkMFIc+UGTSwwiF7NQhwrLZT+Ss+oVAYQvsu22vd5IvASjzZVTcv1aMcYSkXv/dn4= Authentication-Results: nuviainc.com; dkim=none (message not signed) header.d=none;nuviainc.com; dmarc=none action=none header.from=os.amperecomputing.com; Received: from PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) by PH0PR01MB7333.prod.exchangelabs.com (2603:10b6:510:dd::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11; Wed, 3 Nov 2021 09:39:22 +0000 Received: from PH0PR01MB7287.prod.exchangelabs.com ([fe80::254c:9533:7f35:aee]) by PH0PR01MB7287.prod.exchangelabs.com ([fe80::254c:9533:7f35:aee%5]) with mapi id 15.20.4669.011; Wed, 3 Nov 2021 09:39:21 +0000 Message-ID: <1c2b84fe-4477-699e-687a-f4cc51d38b89@os.amperecomputing.com> Date: Wed, 3 Nov 2021 16:32:51 +0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [edk2-platforms][PATCH v4 02/31] AmpereAltraPkg: Add FlashLib library instance To: Leif Lindholm Cc: devel@edk2.groups.io, patches@amperecomputing.com, vunguyen@os.amperecomputing.com, Thang Nguyen , Chuong Tran , Phong Vo , Michael D Kinney , Ard Biesheuvel , Nate DeSimone References: <20211022061809.31087-1-nhi@os.amperecomputing.com> <20211022061809.31087-3-nhi@os.amperecomputing.com> <20211026112511.ah35wl6mw7dzyz25@leviathan> From: "Nhi Pham" In-Reply-To: <20211026112511.ah35wl6mw7dzyz25@leviathan> X-ClientProxiedBy: HKAPR03CA0015.apcprd03.prod.outlook.com (2603:1096:203:c8::20) To PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 Received: from [192.168.1.3] (113.188.173.157) by HKAPR03CA0015.apcprd03.prod.outlook.com (2603:1096:203:c8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.4 via Frontend Transport; Wed, 3 Nov 2021 09:39:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f904f45f-0a54-4177-3114-08d99eadcfe1 X-MS-TrafficTypeDiagnostic: PH0PR01MB7333: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YY2H8j465lthfYX8SYzkUtW2uW7tPZiam6dFc3M+f/elPeNtgFnvN5tf50IzhDhJ3MltmhFpqnKI4tecZkMjU8PH4NR0ghA0FPGQxuXeTFcxV59xSqBgj+ZNuj78xZv+VPy79AXDRqse3TNIPwq4WJ6NjUyPxtLWfdTEqhAXIKPYrfBgPyt2BsNxs2mLyPBKcTZC38JcWvaUjEJvBfzDnVgrivng4JpZR9RzOsrmJ6UICl0qpZ0E3sbSH97Y7oFshAG91MVrfMiVUHK8+13J50em2u4u6ZDWcCLalsidA5WmIjBYLRKIwDgsjLlF0YsHd9l9bJBeb7lCZMkB8nHieyu9SQ7m0mIC5T04ExyvSu2J9VFMOX3vzcj8Tt7W85w+dJ9bj39HsHOH3XkakzNDVw88FOO1ghUeFbaDFN/PB/RLdIHhHByap/v7kJB+33DQ1pLSOkjM/h3rl52Sdj0PQU+idGkhWI7E83dTvDPr6Z+dfwH5105EcyVzVVO7kkvCqOynRNcnzwHLI9byf0a405B8C0YO4SbdjyfUjrZHN3eB6ie2uV8Fj4DigGtR1Jp0EEnDpAur+AxZ21Frs55Dpmd3n/FalsUos7nGRBIPFq4BLqX7+dbt0/Y1wnOSY9mqDlpLH77o2PqpGiNFELC7MKvuImDmpt4YepHp2Yzw8RHi+3p1O7CLN99lxQH2GN5QGHYDbxNfX5oTuO9TXZ4tGhA1pZjsdYWhNcWtsF0l/ko/kfiTQuIqGAIfti3TszifOag14fQP22vvBe2kLq8KFgDjeI2zwgYQmCHizviusR0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR01MB7287.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(6666004)(30864003)(38350700002)(66946007)(2906002)(2616005)(86362001)(38100700002)(52116002)(6486002)(53546011)(16576012)(186003)(54906003)(8676002)(5660300002)(508600001)(316002)(31696002)(83380400001)(66476007)(31686004)(66556008)(26005)(6916009)(19627235002)(4326008)(956004)(8936002)(9186005)(45980500001)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?aC9Ua252YTdhNkJKS1Jyc1U2R2ZPU1BUNnB2TU9na3BhUVh4M1JUdDE4NXlU?= =?utf-8?B?NElqcnIxc1p6VGtNWW5CVExEdHpzVW9ETmhjNis3WkY5TkdtRklkNkQyMkM3?= =?utf-8?B?OEFDTHRzT05CYWxDNkVQRW9jbnFVc253bGJ0RnltaFU2ZFh6bHNZZ01TMU5m?= =?utf-8?B?TzUzb2ZLZ3VVUjhGWXhvQmNVOFRZdi9tZjdVY2RZS01MdHQxSFMvS2tNKzkv?= =?utf-8?B?NmlYUy9lTVZKb1RuNzZnVVFqbkdrclZuMlhJQ2xBTVFvcVgrNlpzOHZXSW9S?= =?utf-8?B?aFRCY2J3cnM5UnlCRGRmYUwydU9qRWNxL0pRKy9qQ1Zsb2dQUHp0ZVpsNFNn?= =?utf-8?B?MEJpOXFmM2lZY2Y0QzlKdHRNOGM0d0Q3dHVXcGZtKzczRmtQNmpEWVJsZDVB?= =?utf-8?B?NjJXaEMwKzdNL1l0N3dIa1d5RDlOYTJDV20yNHF3aXAvMkJiL0VDUGx0V3FP?= =?utf-8?B?NlY4Y25DTUxFTUhOTkp1SEF6RjJKOUVpZFVUcWJoQTJnWVcxRUQ4dVl0R2ZC?= =?utf-8?B?RTF5aTltelpKaEM4cjdBQkQzRnhiY2VHUG16SmxRMUphY1hVSGZhWTY3OWZU?= =?utf-8?B?NnZva25PTUU0ZjZPR2xRUGs5OVZ1aDhPMEExa0czcGhHM05NdGFpUnF4bjFC?= =?utf-8?B?Mk5tWk9BeWMrSGhsL292MUVtVVd3ZnRvQXBwam9SVjNRUnV5eXdlL3luR05I?= =?utf-8?B?V3BjQ3NBTmFVdnpIUDgrWjB3dmNxcnllUmt2RWt4MERwY2ZEekIySXhhbCtR?= =?utf-8?B?YWc5d01EcCtDR2t1SXZBVEd3ZDJOOXNQclNCOEtOeTlFRm8xTjJuUFdPUFZu?= =?utf-8?B?WXR4QXVGMUpUK0NuVThKQjMwemYwUkNnd2lPcStPdndRVVVSS2Y3eHZLaE04?= =?utf-8?B?NFU1ekJSQkVIQ3dQQkt2c3hSc2NWQ2dweE5QWmVkS3p3SFkwczZGMzZnNkl3?= =?utf-8?B?K2F5QkRLWFh3cXVFMlpzcWlRdDBNbUZLdWpwQ0VQVS9MTk01Ty9iNXR2cDBI?= =?utf-8?B?cVBiZDQwTVdWS0l1RURhMGNYb0pNSXE0T3JjdG50Ym9QNVZGSVRLNVNhZElI?= =?utf-8?B?NWJvd0t3cytIV0lJcmt4dnlDTkZpc0Q4S2VoYnlHd0FreXRpcVpkb2FMUzd4?= =?utf-8?B?N2d3aTNBKzg3NFJlV3VnM3h1SzFwMVZDa24vaW5GcmpIMStnWDI0cmRzUHZv?= =?utf-8?B?KzBqUHB5NUJ6RituenBVZ2tUT2hndzNjMDZxdHN5Z29lcjRleE1CRjQzS3Ro?= =?utf-8?B?MkNyNFdxeVlYay9ZaGQwTWRTbWpickl2YjlFNUlabVByZThaT05jck5mdFBO?= =?utf-8?B?Q05teFRSY0h0enVvWko1YjExYzdSZnhBeWVlVU50YnErV21HVHpMRkZqZ0dG?= =?utf-8?B?MzlmcUpJbHBOalBvT3BsUVZybXZSZGRKRjllaXNmT29zeVZwNGdCVDN5QThk?= =?utf-8?B?V2dMbzFpWmNXOWlkOG5mRVVwSDFsdzlIUGdQKzN2Rmh2NmJ4b0w3NHF4RUZs?= =?utf-8?B?REIzQ2ZOMHdiRURQUy9uNE9IWHRiRWZwSThUU1JUWER0VVl0ZmtzenNwU2oz?= =?utf-8?B?TEJaeitENHlsekxqTS9QTEoxODdPdDBtNzVQNUhEVzljM1J4SkZ0L2swaktl?= =?utf-8?B?ZDRpd3F1dmNHQ1piQ0NBZm5XaDFNRng0QnZOT1RLbFdRU3ZObFBXV1VnMkFN?= =?utf-8?B?c0F1UHBCRk52Q0E2VlZXVXh1MUwwOEhDZ3ptMUFwck1ENVZLQSt2eEZLNUtB?= =?utf-8?B?TmNDc1ZkdUVZOHdpZkdDODlsK0VNaDV2THB4OXVCY2xqNndIR1BORHQxZStu?= =?utf-8?B?WDVDTndNcjN6YmVZOEpwcUhqUWx2OGtKb3J4VlpVS2lmNmZaenkwdmljMUN1?= =?utf-8?B?MU9kazM2Uy9QeVhGeDdBM0hjcS9hTkQrMTUzSlB4U1ZjZkt1OVd5bC9qSDJW?= =?utf-8?B?eU93VFBCZVRucWxDajZCMC9yS3RLeDFKcXVxNDZCeDlsZWh4VXExY2s5QWh5?= =?utf-8?B?Rm1DQmxyQmtWUWNHTW05YUl4VnZLaTRvWG5lS05xa25QZFhYTm5vMHlqYWUr?= =?utf-8?B?TEVnZG5WdGtVb29ZdFhuelltOGZkNEYvNWRpZmVodTZhaVlURHRSTnE1RHZZ?= =?utf-8?B?enZpOEV2Z0I0b3RPcFFHRmk1MWxydnVBWnZQUFRRQVdDTXJZM1pFc3FBdkty?= =?utf-8?B?WDBYdmdIcjRRTzdoUGlsT3NMaVFHZkU2b0ZDcnA3dUkyeFYwVm5lSldka3pr?= =?utf-8?Q?dQuWUo8feM8BEvSqBl9cX9Mt9AIHtoQ6vCFilIO8RM=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: f904f45f-0a54-4177-3114-08d99eadcfe1 X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB7287.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2021 09:39:21.0021 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VkuUeWBIIJOLbT0p+n9N7IXjGy/qyUyod+doh0avzBBjIVMrUVjzPQYQD2LJWynyj5kmgrdidm9SZc8waf8Ox7UxzzHPUT1nFsa8KRIQPig= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR01MB7333 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 26/10/2021 18:25, Leif Lindholm wrote: > On Fri, Oct 22, 2021 at 13:17:40 +0700, Nhi Pham wrote: >> From: Vu Nguyen >> >> Provides functions to access the NVRAM, NVRAM2 and FailSafe region on the >> Flash over MM communication. >> >> Cc: Thang Nguyen >> Cc: Chuong Tran >> Cc: Phong Vo >> Cc: Leif Lindholm >> Cc: Michael D Kinney >> Cc: Ard Biesheuvel >> Cc: Nate DeSimone >> >> Signed-off-by: Nhi Pham >> --- >> Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec | 3 + >> Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc | 2 + >> Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLib.inf | 35 ++ >> Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/RuntimeFlashLib.inf | 37 ++ >> Silicon/Ampere/AmpereAltraPkg/Include/Library/FlashLib.h | 118 +++++++ >> Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLibCommon.h | 88 +++++ >> Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLib.c | 86 +++++ >> Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLibCommon.c | 372 ++++++++++++++++++++ >> Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/RuntimeFlashLib.c | 141 ++++++++ >> 9 files changed, 882 insertions(+) >> >> diff --git a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec >> index 0813fc9b4b69..ac778674266d 100644 >> --- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec >> +++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec >> @@ -34,6 +34,9 @@ [LibraryClasses] >> ## @libraryclass Defines a set of methods to generate random numbers by using Hardware RNG. >> TrngLib|Silicon/Ampere/AmpereAltraPkg/Include/Library/TrngLib.h >> >> + ## @libraryclass Defines a set of methods to access flash memory. >> + FlashLib|Silicon/Ampere/AmpereAltraPkg/Include/Library/FlashLib.h >> + >> [Guids] >> ## NVParam MM GUID >> gNVParamMmGuid = { 0xE4AC5024, 0x29BE, 0x4ADC, { 0x93, 0x36, 0x87, 0xB5, 0xA0, 0x76, 0x23, 0x2D } } >> diff --git a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc >> index 3b33be6280ce..69a6caa56752 100644 >> --- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc >> +++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc >> @@ -84,6 +84,7 @@ [LibraryClasses.common] >> AmpereCpuLib|Silicon/Ampere/AmpereAltraPkg/Library/AmpereCpuLib/AmpereCpuLib.inf >> TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf >> MmCommunicationLib|Silicon/Ampere/AmpereAltraPkg/Library/MmCommunicationLib/MmCommunicationLib.inf >> + FlashLib|Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLib.inf >> >> # >> # ARM PL011 UART Driver >> @@ -252,6 +253,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] >> ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf >> NVParamLib|Silicon/Ampere/AmpereAltraPkg/Library/NVParamLib/RuntimeNVParamLib.inf >> AmpereCpuLib|Silicon/Ampere/AmpereAltraPkg/Library/AmpereCpuLib/RuntimeAmpereCpuLib.inf >> + FlashLib|Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/RuntimeFlashLib.inf >> >> [LibraryClasses.ARM,LibraryClasses.AARCH64] >> # >> diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLib.inf b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLib.inf >> new file mode 100644 >> index 000000000000..896d8fd965c8 >> --- /dev/null >> +++ b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLib.inf >> @@ -0,0 +1,35 @@ >> +## @file >> +# >> +# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
>> +# >> +# SPDX-License-Identifier: BSD-2-Clause-Patent >> +# >> +## >> + >> +[Defines] >> + INF_VERSION = 0x0001001B >> + BASE_NAME = FlashLib >> + FILE_GUID = 9E9D093D-6484-45AE-BA49-0745AA0BB481 >> + MODULE_TYPE = BASE >> + VERSION_STRING = 0.1 >> + LIBRARY_CLASS = FlashLib >> + CONSTRUCTOR = FlashLibConstructor >> + >> +[Sources.common] >> + FlashLib.c >> + FlashLibCommon.c >> + >> +[Packages] >> + ArmPkg/ArmPkg.dec >> + ArmPlatformPkg/ArmPlatformPkg.dec >> + MdePkg/MdePkg.dec >> + Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec >> + >> +[LibraryClasses] >> + BaseMemoryLib >> + DebugLib >> + MemoryAllocationLib >> + MmCommunicationLib >> + >> +[Guids] >> + gSpiNorMmGuid >> diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/RuntimeFlashLib.inf b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/RuntimeFlashLib.inf >> new file mode 100644 >> index 000000000000..e729e29cf450 >> --- /dev/null >> +++ b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/RuntimeFlashLib.inf >> @@ -0,0 +1,37 @@ >> +## @file >> +# >> +# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
>> +# >> +# SPDX-License-Identifier: BSD-2-Clause-Patent >> +# >> +## >> + >> +[Defines] >> + INF_VERSION = 0x0001001B >> + BASE_NAME = RuntimeFlashLib >> + FILE_GUID = 0FDF1187-A2DA-4876-8B1F-6D1E928AA319 >> + MODULE_TYPE = DXE_RUNTIME_DRIVER >> + VERSION_STRING = 0.1 >> + LIBRARY_CLASS = FlashLib >> + CONSTRUCTOR = FlashLibConstructor >> + >> +[Sources.common] >> + FlashLibCommon.c >> + RuntimeFlashLib.c >> + >> +[Packages] >> + ArmPkg/ArmPkg.dec >> + ArmPlatformPkg/ArmPlatformPkg.dec >> + MdePkg/MdePkg.dec >> + Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec >> + >> +[LibraryClasses] >> + BaseMemoryLib >> + DebugLib >> + MemoryAllocationLib >> + >> +[Guids] >> + gSpiNorMmGuid >> + >> +[Protocols] >> + gEfiMmCommunication2ProtocolGuid >> diff --git a/Silicon/Ampere/AmpereAltraPkg/Include/Library/FlashLib.h b/Silicon/Ampere/AmpereAltraPkg/Include/Library/FlashLib.h >> new file mode 100644 >> index 000000000000..ce50602f9934 >> --- /dev/null >> +++ b/Silicon/Ampere/AmpereAltraPkg/Include/Library/FlashLib.h >> @@ -0,0 +1,118 @@ >> +/** @file >> + >> + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
>> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> +**/ >> + >> +#ifndef FLASH_LIB_H_ >> +#define FLASH_LIB_H_ >> + >> +/** >> + Get the information about the Flash region to store the FailSafe status. >> + >> + @param[out] FailSafeBase Base address of the FailSafe space. >> + @param[out] FailSafeSize Total size of the FailSafe space. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER FailSafeBase or FailSafeSize is NULL. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashGetFailSafeInfo ( >> + OUT UINTN *FailSafeBase, >> + OUT UINT32 *FailSafeSize >> + ); >> + >> +/** >> + Get the information about the Flash region to store the NVRAM variables. >> + >> + @param[out] NvRamBase Base address of the NVRAM space. >> + @param[out] NvRamSize Total size of the NVRAM space. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER NvRamBase or NvRamSize is NULL. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashGetNvRamInfo ( >> + OUT UINTN *NvRamBase, >> + OUT UINT32 *NvRamSize >> + ); >> + >> +/** >> + Get the information about the second Flash region to store the NVRAM variables. >> + >> + @param[out] NvRam2Base Base address of the NVRAM space. >> + @param[out] NvRam2Size Total size of the NVRAM space. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER NvRam2Base or NvRam2Size is NULL. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashGetNvRam2Info ( >> + OUT UINTN *NvRam2Base, >> + OUT UINT32 *NvRam2Size >> + ); >> + >> +/** >> + Erase a region of the Flash. >> + >> + @param[in] ByteAddress Start address of the region. >> + @param[in] Length Number of bytes to erase. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER Length is Zero. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashEraseCommand ( >> + IN UINTN ByteAddress, >> + IN UINT32 Length >> + ); >> + >> +/** >> + Write data buffer to the Flash. >> + >> + @param[in] ByteAddress Start address of the region. >> + @param[in] Buffer Pointer to the data buffer. >> + @param[in] Length Number of bytes to write. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER Buffer is NULL or Length is Zero. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashWriteCommand ( >> + IN UINTN ByteAddress, >> + IN VOID *Buffer, >> + IN UINT32 Length >> + ); >> + >> +/** >> + Read data from the Flash into Buffer. >> + >> + @param[in] ByteAddress Start address of the region. >> + @param[out] Buffer Pointer to the data buffer. >> + @param[in] Length Number of bytes to read. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER Buffer is NULL or Length is Zero. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashReadCommand ( >> + IN UINTN ByteAddress, >> + OUT VOID *Buffer, >> + IN UINT32 Length >> + ); >> + >> +#endif /* FLASH_LIB_H_ */ >> diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLibCommon.h b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLibCommon.h >> new file mode 100644 >> index 000000000000..36ef9b8ca25d >> --- /dev/null >> +++ b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLibCommon.h >> @@ -0,0 +1,88 @@ >> +/** @file >> + >> + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
>> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> +**/ >> + >> +#ifndef FLASH_LIB_COMMON_H_ >> +#define FLASH_LIB_COMMON_H_ >> + >> +#define EFI_MM_MAX_TMP_BUF_SIZE 0x1000 >> +#define EFI_MM_MAX_PAYLOAD_SIZE 0x50 >> + >> +#define MM_SPINOR_FUNC_GET_INFO 0x00 >> +#define MM_SPINOR_FUNC_READ 0x01 >> +#define MM_SPINOR_FUNC_WRITE 0x02 >> +#define MM_SPINOR_FUNC_ERASE 0x03 >> +#define MM_SPINOR_FUNC_GET_NVRAM_INFO 0x04 >> +#define MM_SPINOR_FUNC_GET_NVRAM2_INFO 0x05 >> +#define MM_SPINOR_FUNC_GET_FAILSAFE_INFO 0x06 >> + >> +#define MM_SPINOR_RES_SUCCESS 0xAABBCC00 >> +#define MM_SPINOR_RES_FAIL 0xAABBCCFF >> + >> +#pragma pack(1) >> + >> +typedef struct { >> + // >> + // Allows for disambiguation of the message format. >> + // >> + EFI_GUID HeaderGuid; >> + >> + // >> + // Describes the size of Data (in bytes) and does not include the size of the header. >> + // >> + UINTN MessageLength; >> + >> + // >> + // Designates an array of bytes that is MessageLength in size. >> + // >> + UINT8 Data[EFI_MM_MAX_PAYLOAD_SIZE]; >> +} EFI_MM_COMMUNICATE_REQUEST; >> + >> +typedef struct { >> + UINT64 Status; >> + UINT64 DeviceBase; >> + UINT64 PageSize; >> + UINT64 SectorSize; >> + UINT64 DeviceSize; >> +} EFI_MM_COMMUNICATE_SPINOR_RESPONSE; >> + >> +typedef struct { >> + UINT64 Status; >> + UINT64 FailSafeBase; >> + UINT64 FailSafeSize; >> +} EFI_MM_COMMUNICATE_FAILSAFE_INFO_RESPONSE; >> + >> +typedef struct { >> + UINT64 Status; >> + UINT64 NvRamBase; >> + UINT64 NvRamSize; >> +} EFI_MM_COMMUNICATE_NVRAM_INFO_RESPONSE; >> + >> +#pragma pack() >> + >> +/** >> + Provides an interface to access the Flash services via MM interface. >> + >> + @param[in] Request Pointer to the request buffer >> + @param[in] RequestDataSize Size of the request buffer. >> + @param[out] Response Pointer to the response buffer >> + @param[in] ResponseDataSize Size of the response buffer. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER An invalid data parameter or an invalid >> + combination of data parameters. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +FlashMmCommunicate ( >> + IN VOID *Request, >> + IN UINT32 RequestDataSize, >> + OUT VOID *Response, >> + IN UINT32 ResponseDataSize >> + ); >> + >> +#endif /* FLASH_LIB_COMMON_H_ */ >> diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLib.c b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLib.c >> new file mode 100644 >> index 000000000000..e844a5c73f6c >> --- /dev/null >> +++ b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLib.c >> @@ -0,0 +1,86 @@ >> +/** @file >> + >> + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
>> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> +**/ >> + >> +#include >> + >> +#include >> +#include >> +#include >> +#include >> + >> +#include "FlashLibCommon.h" >> + >> +extern UINT8 *mTempBufferPhysical; >> +extern UINT8 *mTempBufferVirtual; > Could you move these declarations to FlashLibCommon.h? > I *am* a little bit concerned about globally visible symbols having > such generic names. Add FlashLib to name? Thanks, I will rename to `gFlashLib*`. Nhi > >> + >> +/** >> + Constructor function of the FlashLib >> + >> + @retval EFI_SUCCESS The constructor executes successfully. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashLibConstructor ( >> + VOID >> + ) >> +{ >> + mTempBufferPhysical = AllocateZeroPool (EFI_MM_MAX_TMP_BUF_SIZE); >> + mTempBufferVirtual = mTempBufferPhysical; >> + ASSERT (mTempBufferPhysical != NULL); >> + >> + return EFI_SUCCESS; >> +} >> + >> +/** >> + Provides an interface to access the Flash services via MM interface. >> + >> + @param[in] Request Pointer to the request buffer >> + @param[in] RequestDataSize Size of the request buffer. >> + @param[out] Response Pointer to the response buffer >> + @param[in] ResponseDataSize Size of the response buffer. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER An invalid data parameter or an invalid >> + combination of data parameters. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +FlashMmCommunicate ( >> + IN VOID *Request, >> + IN UINT32 RequestDataSize, >> + OUT VOID *Response, >> + IN UINT32 ResponseDataSize >> + ) >> +{ >> + EFI_MM_COMMUNICATE_REQUEST CommBuffer; >> + EFI_STATUS Status; >> + >> + if (Request == NULL || RequestDataSize == 0 >> + || RequestDataSize > EFI_MM_MAX_PAYLOAD_SIZE >> + || (ResponseDataSize == 0 && Response == NULL)) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + CopyGuid (&CommBuffer.HeaderGuid, &gSpiNorMmGuid); >> + CommBuffer.MessageLength = RequestDataSize; >> + CopyMem (CommBuffer.Data, Request, RequestDataSize); >> + >> + Status = MmCommunicationCommunicate ( >> + &CommBuffer, >> + NULL >> + ); >> + if (EFI_ERROR (Status)) { >> + return Status; >> + } >> + >> + if (ResponseDataSize > 0) { >> + CopyMem (Response, CommBuffer.Data, ResponseDataSize); >> + } >> + >> + return EFI_SUCCESS; >> +} >> diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLibCommon.c b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLibCommon.c >> new file mode 100644 >> index 000000000000..08aab4ba9f0c >> --- /dev/null >> +++ b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLibCommon.c >> @@ -0,0 +1,372 @@ >> +/** @file >> + >> + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
>> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> +**/ >> + >> +#include >> + >> +#include >> +#include >> +#include >> +#include >> + >> +#include "FlashLibCommon.h" >> + >> +BOOLEAN mIsEfiRuntime = FALSE; >> +UINT8 *mTempBufferPhysical; >> +UINT8 *mTempBufferVirtual; > (Very generic globally visible symbol names.) > >> + >> +/** >> + Convert Virtual Address to Physical Address at Runtime. >> + >> + @param[in] VirtualPtr Virtual Address Pointer. >> + @param[in] Size Total bytes of the buffer. >> + >> + @retval Pointer to the physical address of the converted buffer. >> +**/ >> +STATIC >> +UINT8 * >> +ConvertToPhysicalBuffer ( >> + IN UINT8 *VirtualPtr, >> + IN UINT32 Size >> + ) >> +{ >> + if (mIsEfiRuntime) { >> + ASSERT (VirtualPtr != NULL); >> + CopyMem (mTempBufferVirtual, VirtualPtr, Size); >> + return mTempBufferPhysical; >> + } >> + >> + return VirtualPtr; >> +} >> + >> +/** >> + Get the information about the Flash region to store the FailSafe status. >> + >> + @param[out] FailSafeBase Base address of the FailSafe space. >> + @param[out] FailSafeSize Total size of the FailSafe space. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER FailSafeBase or FailSafeSize is NULL. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashGetFailSafeInfo ( >> + OUT UINTN *FailSafeBase, >> + OUT UINT32 *FailSafeSize >> + ) >> +{ >> + EFI_MM_COMMUNICATE_FAILSAFE_INFO_RESPONSE FailSafeInfo; >> + EFI_STATUS Status; >> + UINT64 MmData[5]; >> + >> + if (FailSafeBase == NULL || FailSafeSize == NULL ) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + MmData[0] = MM_SPINOR_FUNC_GET_FAILSAFE_INFO; >> + >> + Status = FlashMmCommunicate ( >> + MmData, >> + sizeof (MmData), >> + &FailSafeInfo, >> + sizeof (FailSafeInfo) >> + ); >> + if (EFI_ERROR (Status)) { >> + return Status; >> + } >> + >> + if (FailSafeInfo.Status == MM_SPINOR_RES_SUCCESS) { >> + *FailSafeBase = FailSafeInfo.FailSafeBase; >> + *FailSafeSize = FailSafeInfo.FailSafeSize; >> + >> + DEBUG (( >> + DEBUG_INFO, >> + "%a: FailSafe Base 0x%llx, Size 0x%lx\n", >> + __FUNCTION__, >> + *FailSafeBase, >> + *FailSafeSize >> + )); >> + } >> + >> + return EFI_SUCCESS; >> +} >> + >> +/** >> + Get the information about the Flash region to store the NVRAM variables. >> + >> + @param[out] NvRamBase Base address of the NVRAM space. >> + @param[out] NvRamSize Total size of the NVRAM space. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER NvRamBase or NvRamSize is NULL. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashGetNvRamInfo ( >> + OUT UINTN *NvRamBase, >> + OUT UINT32 *NvRamSize >> + ) >> +{ >> + EFI_MM_COMMUNICATE_NVRAM_INFO_RESPONSE NvRamInfo; >> + EFI_STATUS Status; >> + UINT64 MmData[5]; >> + >> + if (NvRamBase == NULL || NvRamSize == NULL) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + MmData[0] = MM_SPINOR_FUNC_GET_NVRAM_INFO; >> + >> + Status = FlashMmCommunicate ( >> + MmData, >> + sizeof (MmData), >> + &NvRamInfo, >> + sizeof (NvRamInfo) >> + ); >> + if (EFI_ERROR (Status)) { >> + return Status; >> + } >> + >> + if (NvRamInfo.Status == MM_SPINOR_RES_SUCCESS) { >> + *NvRamBase = NvRamInfo.NvRamBase; >> + *NvRamSize = NvRamInfo.NvRamSize; >> + DEBUG (( >> + DEBUG_INFO, >> + "%a: NVRAM Base 0x%llx, Size 0x%lx\n", >> + __FUNCTION__, >> + *NvRamBase, >> + *NvRamSize >> + )); >> + } >> + >> + return EFI_SUCCESS; >> +} >> + >> +/** >> + Get the information about the second Flash region to store the NVRAM variables. >> + >> + @param[out] NvRam2Base Base address of the NVRAM space. >> + @param[out] NvRam2Size Total size of the NVRAM space. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER NvRam2Base or NvRam2Size is NULL. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashGetNvRam2Info ( >> + OUT UINTN *NvRam2Base, >> + OUT UINT32 *NvRam2Size >> + ) >> +{ >> + EFI_MM_COMMUNICATE_NVRAM_INFO_RESPONSE NvRam2Info; >> + EFI_STATUS Status; >> + UINT64 MmData[5]; >> + >> + if (NvRam2Base == NULL || NvRam2Size == NULL) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + MmData[0] = MM_SPINOR_FUNC_GET_NVRAM2_INFO; >> + >> + Status = FlashMmCommunicate ( >> + MmData, >> + sizeof (MmData), >> + &NvRam2Info, >> + sizeof (NvRam2Info) >> + ); >> + if (EFI_ERROR (Status)) { >> + return Status; >> + } >> + >> + if (NvRam2Info.Status == MM_SPINOR_RES_SUCCESS) { >> + *NvRam2Base = NvRam2Info.NvRamBase; >> + *NvRam2Size = NvRam2Info.NvRamSize; >> + DEBUG (( >> + DEBUG_INFO, >> + "%a: NVRAM2 Base 0x%llx, Size 0x%lx\n", >> + __FUNCTION__, >> + *NvRam2Base, >> + *NvRam2Size >> + )); >> + } >> + >> + return EFI_SUCCESS; >> +} >> + >> +/** >> + Erase a region of the Flash. >> + >> + @param[in] ByteAddress Start address of the region. >> + @param[in] Length Number of bytes to erase. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER Length is Zero. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashEraseCommand ( >> + IN UINTN ByteAddress, >> + IN UINT32 Length >> + ) >> +{ >> + EFI_MM_COMMUNICATE_SPINOR_RESPONSE MmSpiNorRes; >> + EFI_STATUS Status; >> + UINT64 MmData[5]; >> + >> + if (Length == 0) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + MmData[0] = MM_SPINOR_FUNC_ERASE; >> + MmData[1] = ByteAddress; >> + MmData[2] = Length; >> + >> + Status = FlashMmCommunicate ( >> + MmData, >> + sizeof (MmData), >> + &MmSpiNorRes, >> + sizeof (MmSpiNorRes) >> + ); >> + if (EFI_ERROR (Status)) { >> + return Status; >> + } >> + >> + if (MmSpiNorRes.Status != MM_SPINOR_RES_SUCCESS) { >> + DEBUG ((DEBUG_ERROR, "%a: Device error %llx\n", __FUNCTION__, MmSpiNorRes.Status)); >> + return EFI_DEVICE_ERROR; >> + } >> + >> + return EFI_SUCCESS; >> +} >> + >> +/** >> + Write data buffer to the Flash. >> + >> + @param[in] ByteAddress Start address of the region. >> + @param[in] Buffer Pointer to the data buffer. >> + @param[in] Length Number of bytes to write. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER Buffer is NULL or Length is Zero. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashWriteCommand ( >> + IN UINTN ByteAddress, >> + IN VOID *Buffer, >> + IN UINT32 Length >> + ) >> +{ >> + EFI_MM_COMMUNICATE_SPINOR_RESPONSE MmSpiNorRes; >> + EFI_STATUS Status; >> + UINT64 MmData[5]; >> + UINTN Remain, NumWrite; >> + UINTN Count = 0; >> + >> + if (Buffer == NULL || Length == 0) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + Remain = Length; >> + while (Remain > 0) { >> + NumWrite = (Remain > EFI_MM_MAX_TMP_BUF_SIZE) ? EFI_MM_MAX_TMP_BUF_SIZE : Remain; >> + >> + MmData[0] = MM_SPINOR_FUNC_WRITE; >> + MmData[1] = ByteAddress + Count; >> + MmData[2] = NumWrite; >> + MmData[3] = (UINT64)ConvertToPhysicalBuffer (Buffer + Count, NumWrite); >> + >> + Status = FlashMmCommunicate ( >> + MmData, >> + sizeof (MmData), >> + &MmSpiNorRes, >> + sizeof (MmSpiNorRes) >> + ); >> + if (EFI_ERROR (Status)) { >> + return Status; >> + } >> + >> + if (MmSpiNorRes.Status != MM_SPINOR_RES_SUCCESS) { >> + DEBUG ((DEBUG_ERROR, "%a: Device error 0x%llx\n", __FUNCTION__, MmSpiNorRes.Status)); >> + return EFI_DEVICE_ERROR; >> + } >> + >> + Remain -= NumWrite; >> + Count += NumWrite; >> + } >> + >> + return EFI_SUCCESS; >> +} >> + >> +/** >> + Read data from the Flash into Buffer. >> + >> + @param[in] ByteAddress Start address of the region. >> + @param[out] Buffer Pointer to the data buffer. >> + @param[in] Length Number of bytes to read. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER Buffer is NULL or Length is Zero. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashReadCommand ( >> + IN UINTN ByteAddress, >> + OUT VOID *Buffer, >> + IN UINT32 Length >> + ) >> +{ >> + EFI_MM_COMMUNICATE_SPINOR_RESPONSE MmSpiNorRes; >> + EFI_STATUS Status; >> + UINT64 MmData[5]; >> + UINTN Remain, NumRead; >> + UINTN Count = 0; >> + >> + if (Buffer == NULL || Length == 0) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + Remain = Length; >> + while (Remain > 0) { >> + NumRead = (Remain > EFI_MM_MAX_TMP_BUF_SIZE) ? EFI_MM_MAX_TMP_BUF_SIZE : Remain; >> + >> + MmData[0] = MM_SPINOR_FUNC_READ; >> + MmData[1] = ByteAddress + Count; >> + MmData[2] = NumRead; >> + MmData[3] = (UINT64)mTempBufferPhysical; // Read data into the temp buffer with specified virtual address >> + >> + Status = FlashMmCommunicate ( >> + MmData, >> + sizeof (MmData), >> + &MmSpiNorRes, >> + sizeof (MmSpiNorRes) >> + ); >> + if (EFI_ERROR (Status)) { >> + return Status; >> + } >> + >> + if (MmSpiNorRes.Status != MM_SPINOR_RES_SUCCESS) { >> + DEBUG ((DEBUG_ERROR, "%a: Device error %llx\n", __FUNCTION__, MmSpiNorRes.Status)); >> + return EFI_DEVICE_ERROR; >> + } >> + >> + // >> + // Get data from the virtual address of the temp buffer. >> + // >> + CopyMem ((VOID *)(Buffer + Count), (VOID *)mTempBufferVirtual, NumRead); >> + Remain -= NumRead; >> + Count += NumRead; >> + } >> + >> + return EFI_SUCCESS; >> +} >> diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/RuntimeFlashLib.c b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/RuntimeFlashLib.c >> new file mode 100644 >> index 000000000000..edea47313501 >> --- /dev/null >> +++ b/Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/RuntimeFlashLib.c >> @@ -0,0 +1,141 @@ >> +/** @file >> + >> + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
>> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> +**/ >> + >> +#include >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#include "FlashLibCommon.h" >> + >> +extern BOOLEAN mIsEfiRuntime; >> +extern UINT8 *mTempBufferPhysical; >> +extern UINT8 *mTempBufferVirtual; > (Have prototypes in FlashLibCommon.h, include "FlashLib" in globally > visible symbol names.) > > / > Leif > >> + >> +STATIC EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunicationProtocol = NULL; >> + >> +/** >> + This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE >> + event. It converts a pointer to a new virtual address. >> + >> + @param[in] Event Event whose notification function is being invoked. >> + @param[in] Context Pointer to the notification function's context >> +**/ >> +VOID >> +EFIAPI >> +FlashLibAddressChangeEvent ( >> + IN EFI_EVENT Event, >> + IN VOID *Context >> + ) >> +{ >> + gRT->ConvertPointer (0x0, (VOID **)&mTempBufferVirtual); >> + gRT->ConvertPointer (0x0, (VOID **)&mMmCommunicationProtocol); >> + >> + mIsEfiRuntime = TRUE; >> +} >> + >> +/** >> + Constructor function of the RuntimeFlashLib. >> + >> + @param[in] ImageHandle The image handle. >> + @param[in] SystemTable The system table. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +EFIAPI >> +FlashLibConstructor ( >> + IN EFI_HANDLE ImageHandle, >> + IN EFI_SYSTEM_TABLE *SystemTable >> + ) >> +{ >> + EFI_EVENT VirtualAddressChangeEvent = NULL; >> + EFI_STATUS Status; >> + >> + mTempBufferPhysical = AllocateRuntimeZeroPool (EFI_MM_MAX_TMP_BUF_SIZE); >> + mTempBufferVirtual = mTempBufferPhysical; >> + ASSERT (mTempBufferPhysical != NULL); >> + >> + Status = gBS->LocateProtocol ( >> + &gEfiMmCommunication2ProtocolGuid, >> + NULL, >> + (VOID **)&mMmCommunicationProtocol >> + ); >> + ASSERT_EFI_ERROR (Status); >> + >> + Status = gBS->CreateEvent ( >> + EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE, >> + TPL_CALLBACK, >> + FlashLibAddressChangeEvent, >> + NULL, >> + &VirtualAddressChangeEvent >> + ); >> + ASSERT_EFI_ERROR (Status); >> + >> + return Status; >> +} >> + >> +/** >> + Provides an interface to access the Flash services via MM interface. >> + >> + @param[in] Request Pointer to the request buffer >> + @param[in] RequestDataSize Size of the request buffer. >> + @param[out] Response Pointer to the response buffer >> + @param[in] ResponseDataSize Size of the response buffer. >> + >> + @retval EFI_SUCCESS Operation succeeded. >> + @retval EFI_INVALID_PARAMETER An invalid data parameter or an invalid >> + combination of data parameters. >> + @retval Others An error has occurred. >> +**/ >> +EFI_STATUS >> +FlashMmCommunicate ( >> + IN VOID *Request, >> + IN UINT32 RequestDataSize, >> + OUT VOID *Response, >> + IN UINT32 ResponseDataSize >> + ) >> +{ >> + EFI_MM_COMMUNICATE_REQUEST CommBuffer; >> + EFI_STATUS Status; >> + >> + if (Request == NULL || RequestDataSize == 0 >> + || RequestDataSize > EFI_MM_MAX_PAYLOAD_SIZE >> + || (ResponseDataSize == 0 && Response == NULL)) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + CopyGuid (&CommBuffer.HeaderGuid, &gSpiNorMmGuid); >> + CommBuffer.MessageLength = RequestDataSize; >> + CopyMem (CommBuffer.Data, Request, RequestDataSize); >> + >> + if (mMmCommunicationProtocol == NULL) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + Status = mMmCommunicationProtocol->Communicate ( >> + mMmCommunicationProtocol, >> + &CommBuffer, >> + &CommBuffer, >> + NULL >> + ); >> + if (EFI_ERROR (Status)) { >> + return Status; >> + } >> + >> + if (ResponseDataSize > 0) { >> + CopyMem (Response, CommBuffer.Data, ResponseDataSize); >> + } >> + >> + return EFI_SUCCESS; >> +} >> -- >> 2.17.1 >>