From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web09.12126.1647966123876858586 for ; Tue, 22 Mar 2022 09:22:04 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=sTLs02Dm; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (unknown [47.202.59.224]) by linux.microsoft.com (Postfix) with ESMTPSA id 7936520B4783; Tue, 22 Mar 2022 09:22:02 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7936520B4783 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1647966123; bh=gIlnJz0LokDVT5vHQNzwx9kF30SbtZvfgCpccXN7+9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sTLs02Dmv6IO1X13dqvsYGzJK8DkgiH1FfENurWSltn/Npxlj8YjgjiOWehRSeqsL ab+qGDA4kKmnLVlNNWbapQJCX/DtxoxNaLsN9zbQRHF1WlM9E5qMaCfxakXRE/gMQZ 2CLJYGk9vQ3bGuYPq3+zUjTCd4wzhhlxNz5THR4g= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Andrew Fish , Kang Gao , Michael D Kinney , Michael Kubacki , Leif Lindholm , Benjamin You , Liu Yun , Ankit Sinha , Nate DeSimone Subject: [PATCH v1 23/41] PrmPkg/HardwareAccessModuleConfigLib: Add initial library Date: Tue, 22 Mar 2022 12:19:29 -0400 Message-Id: <20220322161947.9319-24-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220322161947.9319-1-mikuback@linux.microsoft.com> References: <20220322161947.9319-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki Adds a PRM module configuration library for PrmSampleHardwareAccessModule that demonstrates marking a runtime MMIO range. In the case of this sample module, the range used is for HPET. Cc: Andrew Fish Cc: Kang Gao Cc: Michael D Kinney Cc: Michael Kubacki Cc: Leif Lindholm Cc: Benjamin You Cc: Liu Yun Cc: Ankit Sinha Cc: Nate DeSimone Signed-off-by: Michael Kubacki --- PrmPkg/Samples/PrmSampleHardwareAccessModule/Library/DxeHardwareAccessMo= duleConfigLib/DxeHardwareAccessModuleConfigLib.c | 104 ++++++++++++++++= ++++ PrmPkg/Samples/PrmSampleHardwareAccessModule/PrmSampleHardwareAccessModu= le.c | 2 - PrmPkg/PrmPkg.dsc = | 1 + PrmPkg/Samples/PrmSampleHardwareAccessModule/Hpet.h = | 3 + PrmPkg/Samples/PrmSampleHardwareAccessModule/Library/DxeHardwareAccessMo= duleConfigLib/DxeHardwareAccessModuleConfigLib.inf | 39 ++++++++ 5 files changed, 147 insertions(+), 2 deletions(-) diff --git a/PrmPkg/Samples/PrmSampleHardwareAccessModule/Library/DxeHard= wareAccessModuleConfigLib/DxeHardwareAccessModuleConfigLib.c b/PrmPkg/Sam= ples/PrmSampleHardwareAccessModule/Library/DxeHardwareAccessModuleConfigL= ib/DxeHardwareAccessModuleConfigLib.c new file mode 100644 index 000000000000..c00ab9ffbbe3 --- /dev/null +++ b/PrmPkg/Samples/PrmSampleHardwareAccessModule/Library/DxeHardwareAcc= essModuleConfigLib/DxeHardwareAccessModuleConfigLib.c @@ -0,0 +1,104 @@ +/** @file + + The boot services environment configuration library for the Hardware A= ccess Sample PRM module. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include + +STATIC EFI_HANDLE mPrmConfigProtocolHandle; + +// {0ef93ed7-14ae-425b-928f-b85a6213b57e} +STATIC CONST EFI_GUID mPrmModuleGuid =3D {0x0ef93ed7, 0x14ae, 0x425b, {0= x92, 0x8f, 0xb8, 0x5a, 0x62, 0x13, 0xb5, 0x7e}}; + +/** + Constructor of the PRM configuration library. + + @param[in] ImageHandle The image handle of the driver. + @param[in] SystemTable The EFI System Table pointer. + + @retval EFI_SUCCESS The shell command handlers were installe= d successfully. + @retval EFI_UNSUPPORTED The shell level required was not found. +**/ +EFI_STATUS +EFIAPI +HardwareAccessModuleConfigLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges; + PRM_CONFIG_PROTOCOL *PrmConfigProtocol; + + RuntimeMmioRanges =3D NULL; + PrmConfigProtocol =3D NULL; + + /* + In this sample PRM module, the protocol describing this sample modul= e's resources is simply + installed in the constructor. + + However, if some data is not available until later, this constructor= could register a callback + on the dependency for the data to be available (e.g. ability to comm= unicate with some device) + and then install the protocol. The requirement is that the protocol = is installed before end of DXE. + */ + + // Runtime MMIO Ranges structure + + // Since this sample module only uses 1 runtime MMIO range, it can use= the PRM_RUNTIME_MMIO_RANGES + // type directly without extending the size of the data buffer for add= itional MMIO ranges. + RuntimeMmioRanges =3D AllocateRuntimeZeroPool (sizeof (*RuntimeMmioRan= ges)); + ASSERT (RuntimeMmioRanges !=3D NULL); + if (RuntimeMmioRanges =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Done; + } + + // Allocate the PRM Configuration protocol structure for this PRM modu= le + PrmConfigProtocol =3D AllocateZeroPool (sizeof (*PrmConfigProtocol)); + ASSERT (PrmConfigProtocol !=3D NULL); + if (PrmConfigProtocol =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Done; + } + CopyGuid (&PrmConfigProtocol->ModuleContextBuffers.ModuleGuid, &mPrmMo= duleGuid); + + // Populate the Runtime MMIO Ranges structure + RuntimeMmioRanges->Count =3D 1; + RuntimeMmioRanges->Range[0].PhysicalBaseAddress =3D HPET_BASE_ADDRESS; + RuntimeMmioRanges->Range[0].Length =3D HPET_RANGE_LENGTH; + + PrmConfigProtocol->ModuleContextBuffers.RuntimeMmioRanges =3D RuntimeM= mioRanges; + + // + // Install the PRM Configuration Protocol for this module. This indica= tes the configuration + // library has completed resource initialization for the PRM module. + // + Status =3D gBS->InstallProtocolInterface ( + &mPrmConfigProtocolHandle, + &gPrmConfigProtocolGuid, + EFI_NATIVE_INTERFACE, + (VOID *) PrmConfigProtocol + ); + +Done: + if (EFI_ERROR (Status)) { + if (RuntimeMmioRanges !=3D NULL) { + FreePool (RuntimeMmioRanges); + } + if (PrmConfigProtocol !=3D NULL) { + FreePool (PrmConfigProtocol); + } + } + + return Status; +} diff --git a/PrmPkg/Samples/PrmSampleHardwareAccessModule/PrmSampleHardwa= reAccessModule.c b/PrmPkg/Samples/PrmSampleHardwareAccessModule/PrmSample= HardwareAccessModule.c index 32e04c5e8592..35da1fcf5f17 100644 --- a/PrmPkg/Samples/PrmSampleHardwareAccessModule/PrmSampleHardwareAcces= sModule.c +++ b/PrmPkg/Samples/PrmSampleHardwareAccessModule/PrmSampleHardwareAcces= sModule.c @@ -42,8 +42,6 @@ // {8a0efdde-78d0-45f0-aea0-c28245c7e1db} #define MMIO_PRINT_HPET_PRM_HANDLER_GUID {0x8a0efdde, 0x78d0, 0x45f0, {0= xae, 0xa0, 0xc2, 0x82, 0x45, 0xc7, 0xe1, 0xdb}} =20 -#define HPET_BASE_ADDRESS 0xFED00000 - // // BEGIN: MtrrLib internal library globals and function prototypes here = for testing // diff --git a/PrmPkg/PrmPkg.dsc b/PrmPkg/PrmPkg.dsc index 2409378926b9..19b996eb3a02 100644 --- a/PrmPkg/PrmPkg.dsc +++ b/PrmPkg/PrmPkg.dsc @@ -79,6 +79,7 @@ [Components] NULL|$(PLATFORM_PACKAGE)/Samples/PrmSampleAcpiParameterBufferModul= e/Library/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferMod= uleConfigLib.inf NULL|$(PLATFORM_PACKAGE)/Samples/PrmSampleContextBufferModule/Libr= ary/DxeContextBufferModuleConfigLib/DxeContextBufferModuleConfigLib.inf + NULL|$(PLATFORM_PACKAGE)/Samples/PrmSampleHardwareAccessModule/Lib= rary/DxeHardwareAccessModuleConfigLib/DxeHardwareAccessModuleConfigLib.in= f } =20 # diff --git a/PrmPkg/Samples/PrmSampleHardwareAccessModule/Hpet.h b/PrmPkg= /Samples/PrmSampleHardwareAccessModule/Hpet.h index c7eb0cbfa747..a4f8758516c0 100644 --- a/PrmPkg/Samples/PrmSampleHardwareAccessModule/Hpet.h +++ b/PrmPkg/Samples/PrmSampleHardwareAccessModule/Hpet.h @@ -15,6 +15,9 @@ #ifndef HPET_REGISTER_H_ #define HPET_REGISTER_H_ =20 +#define HPET_BASE_ADDRESS 0xFED00000 +#define HPET_RANGE_LENGTH 0x1000 + /// /// HPET General Register Offsets /// diff --git a/PrmPkg/Samples/PrmSampleHardwareAccessModule/Library/DxeHard= wareAccessModuleConfigLib/DxeHardwareAccessModuleConfigLib.inf b/PrmPkg/S= amples/PrmSampleHardwareAccessModule/Library/DxeHardwareAccessModuleConfi= gLib/DxeHardwareAccessModuleConfigLib.inf new file mode 100644 index 000000000000..1a50480dd2c5 --- /dev/null +++ b/PrmPkg/Samples/PrmSampleHardwareAccessModule/Library/DxeHardwareAcc= essModuleConfigLib/DxeHardwareAccessModuleConfigLib.inf @@ -0,0 +1,39 @@ +## @file +# Sample PRM Configuration Library Instance +# +# The PRM configuration library instance is responsible for initializin= g and setting the corresponding +# PRM module's configuration in the boot environment. +# +# Copyright (c) Microsoft Corporation +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxeHardwareAccessModuleConfigLib + FILE_GUID =3D 88AA72FE-AE5A-435F-A267-E24D526C666C + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D NULL |DXE_DRIVER + CONSTRUCTOR =3D HardwareAccessModuleConfigLibConstructor + +[Sources] + DxeHardwareAccessModuleConfigLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + PrmPkg/PrmPkg.dec + +[Protocols] + gPrmConfigProtocolGuid + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + UefiBootServicesTableLib + UefiDriverEntryPoint --=20 2.28.0.windows.1