From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: eric.dong@intel.com) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by groups.io with SMTP; Wed, 10 Jul 2019 19:22:08 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2019 19:22:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,476,1557212400"; d="scan'208";a="193251761" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga002.fm.intel.com with ESMTP; 10 Jul 2019 19:22:06 -0700 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 10 Jul 2019 19:22:06 -0700 Received: from shsmsx107.ccr.corp.intel.com (10.239.4.96) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 10 Jul 2019 19:22:06 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.3]) by SHSMSX107.ccr.corp.intel.com ([169.254.9.162]) with mapi id 14.03.0439.000; Thu, 11 Jul 2019 10:22:03 +0800 From: "Dong, Eric" To: "Gao, Zhichao" , "devel@edk2.groups.io" CC: Sean Brogan , "Ni, Ray" , Laszlo Ersek , "Gao, Liming" , Michael Turner , Bret Barkelew Subject: Re: [PATCH V2 2/4] UefiCpuPkg/CpuDxe: Implement Cpu2 protocol Thread-Topic: [PATCH V2 2/4] UefiCpuPkg/CpuDxe: Implement Cpu2 protocol Thread-Index: AQHVNjH1iYXC3K035Uqlr1tKSh1h+6bEsi1g Date: Thu, 11 Jul 2019 02:22:03 +0000 Message-ID: References: <20190709083956.13024-1-zhichao.gao@intel.com> <20190709083956.13024-3-zhichao.gao@intel.com> In-Reply-To: <20190709083956.13024-3-zhichao.gao@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: eric.dong@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Zhizhao, The new add files don't have copyright info, is it ok? Thanks, Eric > -----Original Message----- > From: Gao, Zhichao > Sent: Tuesday, July 9, 2019 4:40 PM > To: devel@edk2.groups.io > Cc: Sean Brogan ; Dong, Eric > ; Ni, Ray ; Laszlo Ersek > ; Gao, Liming ; Michael Turner > ; Bret Barkelew > > Subject: [PATCH V2 2/4] UefiCpuPkg/CpuDxe: Implement Cpu2 protocol >=20 > From: Sean Brogan >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1400 >=20 > Implement Cp2 protocol: it has one interface to enable the interrupt and = put > cpu to sleep and wait for an interrupt. >=20 > Cc: Eric Dong > Cc: Ray Ni > Cc: Laszlo Ersek > Cc: Liming Gao > Cc: Sean Brogan > Cc: Michael Turner > Cc: Bret Barkelew > Signed-off-by: Zhichao Gao > --- > UefiCpuPkg/CpuDxe/CpuDxe.c | 38 +++++++++++++++++++ > UefiCpuPkg/CpuDxe/CpuDxe.h | 25 ++++++++++++ > UefiCpuPkg/CpuDxe/CpuDxe.inf | 3 ++ > .../CpuDxe/Ia32/EnableInterruptsAndSleep.c | 24 ++++++++++++ > .../CpuDxe/X64/EnableInterruptsAndSleep.nasm | 31 +++++++++++++++ > 5 files changed, 121 insertions(+) > create mode 100644 UefiCpuPkg/CpuDxe/Ia32/EnableInterruptsAndSleep.c > create mode 100644 > UefiCpuPkg/CpuDxe/X64/EnableInterruptsAndSleep.nasm >=20 > diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c > index 7d7270e10b..2eeffcf426 100644 > --- a/UefiCpuPkg/CpuDxe/CpuDxe.c > +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c > @@ -18,6 +18,7 @@ > // > BOOLEAN InterruptState =3D FALSE; > EFI_HANDLE mCpuHandle =3D NULL; > +EFI_HANDLE mCpu2Handle =3D NULL; > BOOLEAN mIsFlushingGCD; > BOOLEAN mIsAllocatingPageTable =3D FALSE; > UINT64 mValidMtrrAddressMask; > @@ -96,6 +97,10 @@ EFI_CPU_ARCH_PROTOCOL gCpu =3D { > 4 // DmaBufferAlignment > }; >=20 > +EDKII_CPU2_PROTOCOL gCpu2 =3D { > + CpuEnableAndWaitForInterrupt > +}; > + > // > // CPU Arch Protocol Functions > // > @@ -499,6 +504,28 @@ CpuSetMemoryAttributes ( > return AssignMemoryPageAttributes (NULL, BaseAddress, Length, > MemoryAttributes, NULL); } >=20 > +// > +// CPU2 Protocol Functions > +// > +/** > + This function enables CPU interrupts and then waits for an interrupt t= o > arrive. > + > + @param This The EFI_CPU2_PROTOCOL instance. > + > + @retval EFI_SUCCESS Interrupts are enabled on the processor. > + @retval EFI_DEVICE_ERROR Interrupts could not be enabled on the > processor. > + > +**/ > +EFI_STATUS > +CpuEnableAndWaitForInterrupt ( > + IN EDKII_CPU2_PROTOCOL *This > + ) > +{ > + EnableInterruptsAndSleep (); > + > + return EFI_SUCCESS; > +} > + > /** > Initializes the valid bits mask and valid address mask for MTRRs. >=20 > @@ -1211,6 +1238,17 @@ InitializeCpu ( > ); > ASSERT_EFI_ERROR (Status); >=20 > + // > + // Install CPU2 Protocol > + // > + Status =3D gBS->InstallMultipleProtocolInterfaces ( > + &mCpu2Handle, > + &gEdkiiCpu2ProtocolGuid, > + &gCpu2, > + NULL > + ); > + ASSERT_EFI_ERROR (Status); > + > InitializeMpSupport (); >=20 > return Status; > diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/CpuDxe/CpuDxe.h > index b029be430b..c1398830ba 100644 > --- a/UefiCpuPkg/CpuDxe/CpuDxe.h > +++ b/UefiCpuPkg/CpuDxe/CpuDxe.h > @@ -12,6 +12,7 @@ > #include >=20 > #include > +#include > #include > #include >=20 > @@ -305,6 +306,30 @@ PageFaultExceptionHandler ( > IN EFI_SYSTEM_CONTEXT SystemContext > ); >=20 > +/** > + This function enables CPU interrupts and then waits for an interrupt t= o > arrive. > + > + @param This The EFI_CPU2_PROTOCOL instance. > + > + @retval EFI_SUCCESS Interrupts are enabled on the processor. > + @retval EFI_DEVICE_ERROR Interrupts could not be enabled on the > processor. > + > +**/ > +EFI_STATUS > +CpuEnableAndWaitForInterrupt ( > + IN EDKII_CPU2_PROTOCOL *This > + ); > + > +/** > + Enables CPU interrupts and then waits for an interrupt to arrive. > + > +**/ > +VOID > +EFIAPI > +EnableInterruptsAndSleep ( > + VOID > + ); > + > extern BOOLEAN mIsAllocatingPageTable; > extern UINTN mNumberOfProcessors; >=20 > diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf > b/UefiCpuPkg/CpuDxe/CpuDxe.inf index 57381dbc85..334ddb142f 100644 > --- a/UefiCpuPkg/CpuDxe/CpuDxe.inf > +++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf > @@ -54,14 +54,17 @@ >=20 > [Sources.IA32] > Ia32/CpuAsm.nasm > + Ia32/EnableInterruptsAndSleep.c >=20 > [Sources.X64] > X64/CpuAsm.nasm > + X64/EnableInterruptsAndSleep.nasm >=20 > [Protocols] > gEfiCpuArchProtocolGuid ## PRODUCES > gEfiMpServiceProtocolGuid ## PRODUCES > gEfiSmmBase2ProtocolGuid ## SOMETIMES_CONSUMES > + gEdkiiCpu2ProtocolGuid ## PRODUCES >=20 > [Guids] > gIdleLoopEventGuid ## CONSUMES ##= Event > diff --git a/UefiCpuPkg/CpuDxe/Ia32/EnableInterruptsAndSleep.c > b/UefiCpuPkg/CpuDxe/Ia32/EnableInterruptsAndSleep.c > new file mode 100644 > index 0000000000..dda76139ab > --- /dev/null > +++ b/UefiCpuPkg/CpuDxe/Ia32/EnableInterruptsAndSleep.c > @@ -0,0 +1,24 @@ > +/** @file > + EnableInterruptsAndSleep function > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > + > + > +/** > + Enables CPU interrupts and then sleep. > + > +**/ > +VOID > +EFIAPI > +EnableInterruptsAndSleep ( > + VOID > + ) > +{ > + _asm { > + sti > + hlt > + } > +} > diff --git a/UefiCpuPkg/CpuDxe/X64/EnableInterruptsAndSleep.nasm > b/UefiCpuPkg/CpuDxe/X64/EnableInterruptsAndSleep.nasm > new file mode 100644 > index 0000000000..2d93ecb4bb > --- /dev/null > +++ b/UefiCpuPkg/CpuDxe/X64/EnableInterruptsAndSleep.nasm > @@ -0,0 +1,31 @@ > +;---------------------------------------------------------------------- > +-------- > +; > +; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: > +; > +; EnableInterruptsAndSleep.nasm > +; > +; Abstract: > +; > +; EnableInterruptsAndSleep function > +; > +; Notes: > +; > +;---------------------------------------------------------------------- > +-------- > + > + DEFAULT REL > + SECTION .text > + > +;---------------------------------------------------------------------- > +-------- > +; VOID > +; EFIAPI > +; EnableInterruptsAndSleep ( > +; VOID > +; ); > +;---------------------------------------------------------------------- > +-------- global ASM_PFX(EnableInterruptsAndSleep) > +ASM_PFX(EnableInterruptsAndSleep): > + sti > + hlt > + ret > -- > 2.21.0.windows.1