From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0624.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe42::624]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7D2D92008091A for ; Wed, 5 Apr 2017 06:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=wFMn/zTXG/30MxciuEAQw95G0oH4f8nO8vJmaW8e11k=; b=j1PphVcLj7/sSge5aB5mXEdcDzbkHI5OXN+A8Fp/wos7X5cu+EmpwoXHhZWxYP0MQsKEGr47P8LtM6syqSkgIp9qRc09UlvWXNIwfJPo/Gn4YFJpQqusZQNx/ZcPVgwKIPD5AFLVijt1BEv1OiCScL/fgZSJWis6F2W2+SOYUns= Received: from DM5PR12MB1243.namprd12.prod.outlook.com (10.168.237.22) by CY4PR1201MB0134.namprd12.prod.outlook.com (10.172.78.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1005.10; Wed, 5 Apr 2017 13:12:34 +0000 Received: from DM5PR12MB1243.namprd12.prod.outlook.com ([10.168.237.22]) by DM5PR12MB1243.namprd12.prod.outlook.com ([10.168.237.22]) with mapi id 15.01.1005.020; Wed, 5 Apr 2017 13:12:32 +0000 From: "Duran, Leo" To: "'Gao, Liming'" , "edk2-devel@ml01.01.org" CC: "Kinney, Michael D" , "Singh, Brijesh" Thread-Topic: [edk2] [PATCH v4] MdePkg: BaseIoLibIntrinsic (IoLib class) library Thread-Index: AQHSrU1aud5LRa6IlUGB/QODB0QF7KG1QA0AgADCn4CAAL8UAA== Date: Wed, 5 Apr 2017 13:12:32 +0000 Message-ID: References: <1491315078-3648-1-git-send-email-leo.duran@amd.com> <1491315078-3648-2-git-send-email-leo.duran@amd.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14D7171DD@shsmsx102.ccr.corp.intel.com> In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14D7171DD@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=amd.com; x-originating-ip: [165.204.77.1] x-microsoft-exchange-diagnostics: 1; CY4PR1201MB0134; 7:NBCTBvBVdmHwgKE468EAr/XxGi3ipOkBoPrX9h/Z4y69XRdYPILaOb/qF3fLSfr2r8lAwRyPLo1c5B47p927c3GyhQ4r4nH5roCJBJ6IhrKtMtkQgDIGhrOudCXU8pmtUop5BsqsHILBpuVAgULraoS3Pg7Tw/IGIiYrs/+mXo9BiXlUooO3dw1R8Qgpz+avNDUEj9id+3tOZKlOePkCaakxDDDLD7sa8j/aq2fRZpXu+qwUSTLk30T35GYpMYcwBsJsQATQaaRyWGm+IngZdPftIH+Dh1Lv/vtq8TlJdsHboi32W41oRxg5V7QOGbQfiAlhm9sbKk+o1ZYTiUolKg==; 20:PiumeZbAg7XFVAdQpcugUQY3uHH3rdXFpqIqrTLZJsrzZcyBmuTIVYBX1oiZUvXDBZvkTa7V1DLbXpMLeeBMouMP/NpikXTC5wmfdKTnzm1PeAZUskyb/JXDKbhCIzffNHJQVmaujcU32oKiIi9imEQCoqMnsZluXJZiuvLrbhlyaKIw/rTw42+Xfp28yQi1p/xYWf+VAeXbP2PopHMAD2uFYo+Hc80idQQJ5tFnCYgPb6bZtIc5cXkenEkDbMF2 x-forefront-antispam-report: SFV:SKI; SCL:-1SFV:NSPM; SFS:(10009020)(6009001)(6029001)(39840400002)(39400400002)(39410400002)(39850400002)(39450400003)(39860400002)(377454003)(13464003)(102836003)(3846002)(33656002)(6116002)(2950100002)(229853002)(2900100001)(54356999)(66066001)(189998001)(81166006)(1720100001)(86362001)(122556002)(76176999)(8676002)(8936002)(305945005)(966004)(50986999)(74316002)(99286003)(4326008)(9686003)(7696004)(55016002)(6246003)(3660700001)(3280700002)(6506006)(7736002)(53546009)(6436002)(77096006)(53936002)(54906002)(53376002)(2501003)(53946003)(25786009)(6306002)(38730400002)(559001)(579004)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1201MB0134; H:DM5PR12MB1243.namprd12.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; x-ms-office365-filtering-correlation-id: 833ded65-c24f-4010-bdd0-08d47c256b94 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081); SRVR:CY4PR1201MB0134; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(767451399110)(162533806227266)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(6055026)(6041248)(20161123564025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(20161123562025)(6072148); SRVR:CY4PR1201MB0134; BCL:0; PCL:0; RULEID:; SRVR:CY4PR1201MB0134; x-forefront-prvs: 0268246AE7 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Apr 2017 13:12:32.4575 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0134 Subject: Re: [PATCH v4] MdePkg: BaseIoLibIntrinsic (IoLib class) library X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Apr 2017 13:12:35 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Liming, Yes, agreed... I'll push a v5. Leo. > -----Original Message----- > From: Gao, Liming [mailto:liming.gao@intel.com] > Sent: Tuesday, April 04, 2017 8:48 PM > To: Duran, Leo ; edk2-devel@ml01.01.org > Cc: Kinney, Michael D ; Singh, Brijesh > > Subject: RE: [edk2] [PATCH v4] MdePkg: BaseIoLibIntrinsic (IoLib class) l= ibrary >=20 > Leo: > I just find one minor issue. Could you help update the comments in new > module INF file? >=20 > > +# Instance of I/O Library using compiler intrinsics. > > +# > > +# I/O Library that uses compiler intrinsics to perform IN and OUT > > +instructions # for IA-32 and x64. On IPF, I/O port requests are tran= slated > into MMIO requests. > > +# MMIO requests are forwarded directly to memory. For EBC, I/O port > > +requests # ASSERT(). >=20 > Thanks > Liming > > -----Original Message----- > > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > > Leo Duran > > Sent: Tuesday, April 4, 2017 10:11 PM > > To: edk2-devel@ml01.01.org > > Cc: Kinney, Michael D ; Brijesh Singh > > ; Leo Duran ; Gao, Liming > > > > Subject: [edk2] [PATCH v4] MdePkg: BaseIoLibIntrinsic (IoLib class) > > library > > > > This patch adds an SEV-specific .INF and corresponding assembly files, > > to unroll REP INSx/OUTSx on IoRead/WriteFifo#() routines when the SEV > > feature is enabled under a hypervisor environment. > > > > The new .INF only supports the IA32 and X64 architectures. > > > > Cc: Michael D Kinney > > Cc: Liming Gao > > Contributed-under: TianoCore Contribution Agreement 1.0 > > Signed-off-by: Brijesh Singh > > Signed-off-by: Leo Duran > > --- > > .../BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf | 61 +++++ > > .../Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm | 293 > > +++++++++++++++++++++ > .../Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm | 282 > ++++++++++++++++++++ > > MdePkg/MdePkg.dsc | 2 + > > 4 files changed, 638 insertions(+) > > create mode 100644 > > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf > > create mode 100644 > > MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm > > create mode 100644 > > MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm > > > > diff --git > > a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf > > b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf > > new file mode 100644 > > index 0000000..4544f23 > > --- /dev/null > > +++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf > > @@ -0,0 +1,61 @@ > > +## @file > > +# Instance of I/O Library using compiler intrinsics. > > +# > > +# I/O Library that uses compiler intrinsics to perform IN and OUT > > +instructions # for IA-32 and x64. On IPF, I/O port requests are tran= slated > into MMIO requests. > > +# MMIO requests are forwarded directly to memory. For EBC, I/O port > > +requests # ASSERT(). > > +# > > +# Copyright (c) 2007 - 2015, Intel Corporation. All rights > > +reserved.
# Portions copyright (c) 2008 - 2009, Apple Inc. All > > +rights reserved.
# Copyright (c) 2017, AMD Incorporated. All > > +rights reserved.
# # This program and the accompanying materials > > +# are licensed and made available under the terms and conditions of > > +the BSD License # which accompanies this distribution. The full text > > +of the license may be found at # http://opensource.org/licenses/bsd- > license.php. > > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, > EITHER EXPRESS OR IMPLIED. > > +# > > +## > > + > > +[Defines] > > + INF_VERSION =3D 0x00010005 > > + BASE_NAME =3D BaseIoLibIntrinsicSev > > + MODULE_UNI_FILE =3D BaseIoLibIntrinsic.uni > > + FILE_GUID =3D 93742f95-6e71-4581-b600-8e1da443f= 95a > > + MODULE_TYPE =3D BASE > > + VERSION_STRING =3D 1.0 > > + LIBRARY_CLASS =3D IoLib > > + > > + > > +# > > +# VALID_ARCHITECTURES =3D IA32 X64 > > +# > > + > > +[Sources] > > + IoLibMmioBuffer.c > > + BaseIoLibIntrinsicInternal.h > > + IoHighLevel.c > > + > > +[Sources.IA32] > > + IoLibGcc.c | GCC > > + IoLibMsc.c | MSFT > > + IoLibIcc.c | INTEL > > + IoLib.c > > + Ia32/IoFifoSev.nasm > > + > > +[Sources.X64] > > + IoLibGcc.c | GCC > > + IoLibMsc.c | MSFT > > + IoLibIcc.c | INTEL > > + IoLib.c > > + X64/IoFifoSev.nasm > > + > > +[Packages] > > + MdePkg/MdePkg.dec > > + > > +[LibraryClasses] > > + DebugLib > > + BaseLib > > + > > diff --git a/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm > > b/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm > > new file mode 100644 > > index 0000000..9adb972 > > --- /dev/null > > +++ b/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm > > @@ -0,0 +1,293 @@ > > +;-------------------------------------------------------------------- > > +---------- > > +; > > +; Copyright (c) 2006 - 2012, Intel Corporation. All rights > > +reserved.
; Copyright (c) 2017, AMD Incorporated. All rights > > +reserved.
; ; This program and the accompanying materials are > > +licensed and made available ; under the terms and conditions of the > > +BSD License which accompanies this ; distribution. The full text of > > +the license may be found at ; > > +http://opensource.org/licenses/bsd-license.php. > > +; > > +; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > +BASIS, ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, > EITHER EXPRESS OR IMPLIED. > > +; > > +;-------------------------------------------------------------------- > > +---------- > > + > > + SECTION .text > > + > > +;-------------------------------------------------------------------- > > +---------- ; Check whether we need to unroll the String I/O under SEV > > +guest ; > > +; Return // eax (1 - unroll, 0 - no unroll) > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(SevNoRepIo) > > +ASM_PFX(SevNoRepIo): > > + > > + ; CPUID clobbers ebx, ecx and edx > > + push ebx > > + push ecx > > + push edx > > + > > + ; Check if we are running under hypervisor ; CPUID(1).ECX Bit 31 > > + mov eax, 1 > > + cpuid > > + bt ecx, 31 > > + jnc @UseRepIo > > + > > + ; Check if we have Memory encryption CPUID leaf > > + mov eax, 0x80000000 > > + cpuid > > + cmp eax, 0x8000001f > > + jl @UseRepIo > > + > > + ; Check for memory encryption feature: > > + ; CPUID Fn8000_001F[EAX] - Bit 1 > > + ; > > + mov eax, 0x8000001f > > + cpuid > > + bt eax, 1 > > + jnc @UseRepIo > > + > > + ; Check if memory encryption is enabled ; MSR_0xC0010131 - Bit 0 > > + (SEV enabled) ; MSR_0xC0010131 - Bit 1 (SEV-ES enabled) > > + mov ecx, 0xc0010131 > > + rdmsr > > + > > + ; Check for (SevEsEnabled =3D=3D 0 && SevEnabled =3D=3D 1) > > + and eax, 3 > > + cmp eax, 1 > > + je @SevNoRepIo_Done > > + > > +@UseRepIo: > > + xor eax, eax > > + > > +@SevNoRepIo_Done: > > + pop edx > > + pop ecx > > + pop ebx > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoReadFifo8 ( > > +; IN UINTN Port, > > +; IN UINTN Size, > > +; OUT VOID *Buffer > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoReadFifo8) > > +ASM_PFX(IoReadFifo8): > > + push edi > > + mov dx, [esp + 8] > > + mov ecx, [esp + 12] > > + mov edi, [esp + 16] > > + > > + call SevNoRepIo ; Check if we need to unroll the rep > > + test eax, eax > > + jnz @IoReadFifo8_NoRep > > + > > + cld > > + rep insb > > + jmp @IoReadFifo8_Done > > + > > +@IoReadFifo8_NoRep: > > + jecxz @IoReadFifo8_Done > > + > > +@IoReadFifo8_Loop: > > + in al, dx > > + mov byte [edi], al > > + inc edi > > + loop @IoReadFifo8_Loop > > + > > +@IoReadFifo8_Done: > > + pop edi > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoReadFifo16 ( > > +; IN UINTN Port, > > +; IN UINTN Size, > > +; OUT VOID *Buffer > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoReadFifo16) > > +ASM_PFX(IoReadFifo16): > > + push edi > > + mov dx, [esp + 8] > > + mov ecx, [esp + 12] > > + mov edi, [esp + 16] > > + > > + call SevNoRepIo ; Check if we need to unroll the rep > > + test eax, eax > > + jnz @IoReadFifo16_NoRep > > + > > + cld > > + rep insw > > + jmp @IoReadFifo16_Done > > + > > +@IoReadFifo16_NoRep: > > + jecxz @IoReadFifo16_Done > > + > > +@IoReadFifo16_Loop: > > + in ax, dx > > + mov word [edi], ax > > + add edi, 2 > > + loop @IoReadFifo16_Loop > > + > > +@IoReadFifo16_Done: > > + pop edi > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoReadFifo32 ( > > +; IN UINTN Port, > > +; IN UINTN Size, > > +; OUT VOID *Buffer > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoReadFifo32) > > +ASM_PFX(IoReadFifo32): > > + push edi > > + mov dx, [esp + 8] > > + mov ecx, [esp + 12] > > + mov edi, [esp + 16] > > + > > + call SevNoRepIo ; Check if we need to unroll the rep > > + test eax, eax > > + jnz @IoReadFifo32_NoRep > > + > > + cld > > + rep insd > > + jmp @IoReadFifo32_Done > > + > > +@IoReadFifo32_NoRep: > > + jecxz @IoReadFifo32_Done > > + > > +@IoReadFifo32_Loop: > > + in eax, dx > > + mov dword [edi], eax > > + add edi, 4 > > + loop @IoReadFifo32_Loop > > + > > +@IoReadFifo32_Done: > > + pop edi > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoWriteFifo8 ( > > +; IN UINTN Port, > > +; IN UINTN Size, > > +; IN VOID *Buffer > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoWriteFifo8) > > +ASM_PFX(IoWriteFifo8): > > + push esi > > + mov dx, [esp + 8] > > + mov ecx, [esp + 12] > > + mov esi, [esp + 16] > > + > > + call SevNoRepIo ; Check if we need to unroll String I/O > > + test eax, eax > > + jnz @IoWriteFifo8_NoRep > > + > > + cld > > + rep outsb > > + jmp @IoWriteFifo8_Done > > + > > +@IoWriteFifo8_NoRep: > > + jecxz @IoWriteFifo8_Done > > + > > +@IoWriteFifo8_Loop: > > + mov byte [esi], al > > + out dx, al > > + inc esi > > + loop @IoWriteFifo8_Loop > > + > > +@IoWriteFifo8_Done: > > + pop esi > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoWriteFifo16 ( > > +; IN UINTN Port, > > +; IN UINTN Size, > > +; IN VOID *Buffer > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoWriteFifo16) > > +ASM_PFX(IoWriteFifo16): > > + push esi > > + mov dx, [esp + 8] > > + mov ecx, [esp + 12] > > + mov esi, [esp + 16] > > + > > + call SevNoRepIo ; Check if we need to unroll String I/O > > + test eax, eax > > + jnz @IoWriteFifo16_NoRep > > + > > + cld > > + rep outsw > > + jmp @IoWriteFifo16_Done > > + > > +@IoWriteFifo16_NoRep: > > + jecxz @IoWriteFifo16_Done > > + > > +@IoWriteFifo16_Loop: > > + mov word [esi], ax > > + out dx, ax > > + add esi, 2 > > + loop @IoWriteFifo16_Loop > > + > > +@IoWriteFifo16_Done: > > + pop esi > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoWriteFifo32 ( > > +; IN UINTN Port, > > +; IN UINTN Size, > > +; IN VOID *Buffer > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoWriteFifo32) > > +ASM_PFX(IoWriteFifo32): > > + push esi > > + mov dx, [esp + 8] > > + mov ecx, [esp + 12] > > + mov esi, [esp + 16] > > + > > + call SevNoRepIo ; Check if we need to unroll String I/O > > + test eax, eax > > + jnz @IoWriteFifo32_NoRep > > + > > + cld > > + rep outsd > > + jmp @IoWriteFifo32_Done > > + > > +@IoWriteFifo32_NoRep: > > + jecxz @IoWriteFifo32_Done > > + > > +@IoWriteFifo32_Loop: > > + mov dword [esi], eax > > + out dx, eax > > + add esi, 4 > > + loop @IoWriteFifo32_Loop > > + > > +@IoWriteFifo32_Done: > > + pop esi > > + ret > > + > > diff --git a/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm > > b/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm > > new file mode 100644 > > index 0000000..20e3e64 > > --- /dev/null > > +++ b/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm > > @@ -0,0 +1,282 @@ > > +;-------------------------------------------------------------------- > > +---------- > > +; > > +; Copyright (c) 2006 - 2012, Intel Corporation. All rights > > +reserved.
; Copyright (c) 2017, AMD Incorporated. All rights > > +reserved.
; ; This program and the accompanying materials are > > +licensed and made available ; under the terms and conditions of the > > +BSD License which accompanies this ; distribution. The full text of > > +the license may be found at ; > > +http://opensource.org/licenses/bsd-license.php. > > +; > > +; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > +BASIS, ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, > EITHER EXPRESS OR IMPLIED. > > +; > > +;-------------------------------------------------------------------- > > +---------- > > + > > + DEFAULT REL > > + SECTION .text > > + > > +;-------------------------------------------------------------------- > > +---------- ; Check whether we need to unroll the String I/O in SEV > > +guest ; > > +; Return // eax (1 - unroll, 0 - no unroll) > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(SevNoRepIo) > > +ASM_PFX(SevNoRepIo): > > + > > + ; CPUID clobbers ebx, ecx and edx > > + push rbx > > + push rcx > > + push rdx > > + > > + ; Check if we are runing under hypervisor ; CPUID(1).ECX Bit 31 > > + mov eax, 1 > > + cpuid > > + bt ecx, 31 > > + jnc @UseRepIo > > + > > + ; Check if we have Memory encryption CPUID leaf > > + mov eax, 0x80000000 > > + cpuid > > + cmp eax, 0x8000001f > > + jl @UseRepIo > > + > > + ; Check for memory encryption feature: > > + ; CPUID Fn8000_001F[EAX] - Bit 1 > > + ; > > + mov eax, 0x8000001f > > + cpuid > > + bt eax, 1 > > + jnc @UseRepIo > > + > > + ; Check if memory encryption is enabled ; MSR_0xC0010131 - Bit 0 > > + (SEV enabled) ; MSR_0xC0010131 - Bit 1 (SEV-ES enabled) > > + mov ecx, 0xc0010131 > > + rdmsr > > + > > + ; Check for (SevEsEnabled =3D=3D 0 && SevEnabled =3D=3D 1) > > + and eax, 3 > > + cmp eax, 1 > > + je @SevNoRepIo_Done > > + > > +@UseRepIo: > > + xor eax, eax > > + > > +@SevNoRepIo_Done: > > + pop rdx > > + pop rcx > > + pop rbx > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoReadFifo8 ( > > +; IN UINTN Port, // rcx > > +; IN UINTN Size, // rdx > > +; OUT VOID *Buffer // r8 > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoReadFifo8) > > +ASM_PFX(IoReadFifo8): > > + xchg rcx, rdx > > + xchg rdi, r8 ; rdi: buffer address; r8: save rdi > > + > > + call SevNoRepIo ; Check if we need to unroll String I/= O > > + test eax, eax > > + jnz @IoReadFifo8_NoRep > > + > > + cld > > + rep insb > > + jmp @IoReadFifo8_Done > > + > > +@IoReadFifo8_NoRep: > > + jrcxz @IoReadFifo8_Done > > + > > +@IoReadFifo8_Loop: > > + in al, dx > > + mov byte [rdi], al > > + inc rdi > > + loop @IoReadFifo8_Loop > > + > > +@IoReadFifo8_Done: > > + mov rdi, r8 ; restore rdi > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoReadFifo16 ( > > +; IN UINTN Port, // rcx > > +; IN UINTN Size, // rdx > > +; OUT VOID *Buffer // r8 > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoReadFifo16) > > +ASM_PFX(IoReadFifo16): > > + xchg rcx, rdx > > + xchg rdi, r8 ; rdi: buffer address; r8: save rdi > > + > > + call SevNoRepIo ; Check if we need to unroll String I/= O > > + test eax, eax > > + jnz @IoReadFifo16_NoRep > > + > > + cld > > + rep insw > > + jmp @IoReadFifo16_Done > > + > > +@IoReadFifo16_NoRep: > > + jrcxz @IoReadFifo16_Done > > + > > +@IoReadFifo16_Loop: > > + in ax, dx > > + mov word [rdi], ax > > + add rdi, 2 > > + loop @IoReadFifo16_Loop > > + > > +@IoReadFifo16_Done: > > + mov rdi, r8 ; restore rdi > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoReadFifo32 ( > > +; IN UINTN Port, // rcx > > +; IN UINTN Size, // rdx > > +; OUT VOID *Buffer // r8 > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoReadFifo32) > > +ASM_PFX(IoReadFifo32): > > + xchg rcx, rdx > > + xchg rdi, r8 ; rdi: buffer address; r8: save rdi > > + > > + call SevNoRepIo ; Check if we need to unroll String I/O > > + test eax, eax > > + jnz @IoReadFifo32_NoRep > > + > > + cld > > + rep insd > > + jmp @IoReadFifo32_Done > > + > > +@IoReadFifo32_NoRep: > > + jrcxz @IoReadFifo32_Done > > + > > +@IoReadFifo32_Loop: > > + in eax, dx > > + mov dword [rdi], eax > > + add rdi, 4 > > + loop @IoReadFifo32_Loop > > + > > +@IoReadFifo32_Done: > > + mov rdi, r8 ; restore rdi > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoWriteFifo8 ( > > +; IN UINTN Port, // rcx > > +; IN UINTN Size, // rdx > > +; IN VOID *Buffer // r8 > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoWriteFifo8) > > +ASM_PFX(IoWriteFifo8): > > + xchg rcx, rdx > > + xchg rsi, r8 ; rsi: buffer address; r8: save rsi > > + > > + call SevNoRepIo ; Check if we need to unroll String I/O > > + test eax, eax > > + jnz @IoWriteFifo8_NoRep > > + > > + cld > > + rep outsb > > + jmp @IoWriteFifo8_Done > > + > > +@IoWriteFifo8_NoRep: > > + jrcxz @IoWriteFifo8_Done > > + > > +@IoWriteFifo8_Loop: > > + mov byte [rsi], al > > + out dx, al > > + inc rsi > > + loop @IoWriteFifo8_Loop > > + > > +@IoWriteFifo8_Done: > > + mov rsi, r8 ; restore rsi > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoWriteFifo16 ( > > +; IN UINTN Port, // rcx > > +; IN UINTN Size, // rdx > > +; IN VOID *Buffer // r8 > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoWriteFifo16) > > +ASM_PFX(IoWriteFifo16): > > + xchg rcx, rdx > > + xchg rsi, r8 ; rsi: buffer address; r8: save rsi > > + > > + call SevNoRepIo ; Check if we need to unroll String I/O > > + test eax, eax > > + jnz @IoWriteFifo16_NoRep > > + > > + cld > > + rep outsw > > + jmp @IoWriteFifo16_Done > > + > > +@IoWriteFifo16_NoRep: > > + jrcxz @IoWriteFifo16_Done > > + > > +@IoWriteFifo16_Loop: > > + mov word [rsi], ax > > + out dx, ax > > + add rsi, 2 > > + loop @IoWriteFifo16_Loop > > + > > +@IoWriteFifo16_Done: > > + mov rsi, r8 ; restore rsi > > + ret > > + > > +;-------------------------------------------------------------------- > > +---------- > > +; VOID > > +; EFIAPI > > +; IoWriteFifo32 ( > > +; IN UINTN Port, // rcx > > +; IN UINTN Size, // rdx > > +; IN VOID *Buffer // r8 > > +; ); > > +;-------------------------------------------------------------------- > > +---------- > > +global ASM_PFX(IoWriteFifo32) > > +ASM_PFX(IoWriteFifo32): > > + xchg rcx, rdx > > + xchg rsi, r8 ; rsi: buffer address; r8: save rsi > > + > > + call SevNoRepIo ; Check if we need to unroll String I/O > > + test eax, eax > > + jnz @IoWriteFifo32_NoRep > > + > > + cld > > + rep outsd > > + jmp @IoWriteFifo32_Done > > + > > +@IoWriteFifo32_NoRep: > > + jrcxz @IoWriteFifo32_Done > > + > > +@IoWriteFifo32_Loop: > > + mov dword [rsi], eax > > + out dx, eax > > + add rsi, 4 > > + loop @IoWriteFifo32_Loop > > + > > +@IoWriteFifo32_Done: > > + mov rsi, r8 ; restore rsi > > + ret > > + > > diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index > > 2144979..56fb4cf 100644 > > --- a/MdePkg/MdePkg.dsc > > +++ b/MdePkg/MdePkg.dsc > > @@ -3,6 +3,7 @@ > > # > > # Copyright (c) 2007 - 2017, Intel Corporation. All rights > > reserved.
# Portions copyright (c) 2008 - 2009, Apple Inc. All > > rights reserved.
> > +# Copyright (c) 2017, AMD Incorporated. All rights reserved.
> > # > > # This program and the accompanying materials > > # are licensed and made available under the terms and conditions of= the > BSD License > > @@ -134,6 +135,7 @@ > > > > [Components.IA32, Components.X64] > > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf > > + MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf > > MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf > > MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf > > MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf > > -- > > 2.7.4 > > > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel