From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0605.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe48::605]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AD56321939313 for ; Tue, 4 Apr 2017 07:11:29 -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=Ry5NmKN77WqOgu/rQuBVmqc4acxj2yVw7/sm2VGL1tU=; b=G+BuBbxZmldkJYLnX7Lg6T6aipRN7cgswMpNxJx2xycdrcUtPilncw6mBd+T5i2YMIzE+PxPxqOh/llxjmJkko8p2zYbQ6ztwfXdvOjS2imQSbBvNSWXn7tS+ADUGyEEJc1mvhfPBFKiAQ5BxPyPCmEJBMhhSgilk62qJcUBJDE= Authentication-Results: ml01.01.org; dkim=none (message not signed) header.d=none;ml01.01.org; dmarc=none action=none header.from=amd.com; Received: from leduran-Precision-WorkStation-T5400.amd.com (165.204.77.1) by CY4PR12MB1240.namprd12.prod.outlook.com (10.168.167.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1005.10; Tue, 4 Apr 2017 14:11:28 +0000 From: Leo Duran To: CC: Leo Duran , Michael D Kinney , Liming Gao , Brijesh Singh Date: Tue, 4 Apr 2017 09:11:18 -0500 Message-ID: <1491315078-3648-2-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491315078-3648-1-git-send-email-leo.duran@amd.com> References: <1491315078-3648-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR10CA0009.namprd10.prod.outlook.com (10.172.48.19) To CY4PR12MB1240.namprd12.prod.outlook.com (10.168.167.15) X-MS-Office365-Filtering-Correlation-Id: 49a56e3b-56ba-4c46-e3c1-08d47b647cc9 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:CY4PR12MB1240; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1240; 3:esBJWqQ5BWziWDQHRMJfxcG2FcqnLOnBIJb6tK4+59sdLw7wnt8jiZtNaYXbVw/Hs00ZKFoZyPnE5ULwMf6nUsG5uEJsnzXoc0CMmdVV3pxNptDxXEKfxfHUxqXyHEXZMlX0NYherww3zdJGJLiQ16NUBdkOLBK9t2kP0ejVUK3HfdefgTWjSJgzy8TZ+mMcHwszYng3ZNcYti36NtNilMLUsBKAmlKtDm8ozJMGvDXD/vPNS0PFBci3XKVeOt6XqbsZ8g0r/nXPM+4JkSuc3CJeDxMLf0C3wivFFoaIjEk9DU1MY4XbSfZBkroCzEXEGN3fIAdDTDfUImFVgzI3GuBBGXycgAMqeXlXDCIH43s=; 25:jCPpPSXdr/1PdYuL6bn958SSEW5YEPBj6+wxU/JcuM9m056FAIC1zv1Td3GJB5u6hLxw3fLmZtsvP9c3xmX+TRdE2Awt0awBFvyGYkvoRX9MrwKamX4bpbDQ/03wU6Dj311Q4E8AmIrVQwVqjw4Uc95zF8narTpiJZzzvWpvuMP0ZQ8qopJ84MMkv4i8iEVjaWbrG3D+ryTOLwTq6l18twPxdkvDEhvWt/qYomBMFIThzhfjWI9tLcvMJob6lzWB0fTj1CENoaALa+V2DmBVp+QlHJ+mhHOvdK9ZLvtnE0gNq98Bzh4fRSAZHdRtVxOVPxD0qItB1jSHUCeCXVi+mjYXM4zzL0jAyD6KPDCwtYzR7U8B/UOXbOtxbscQAW4INZsuu4LFGnrbApLEIfeGwwVfTldlR4IFdl9ka3RZVdvZIaj/vI+c17GD9iNKqT0k1DAKV7uZBCaPRC7wzUheaQ== X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1240; 31:JFggwKaFGqvXA8hqoOdxuueo62U82VQGUfg6u4Yk/v3gDvBwHdU99/ygrEzlF966ptO+WN71u23K+q5SeE2F3M+Xs01yZU4oayFwQhrpYE3p2KG0npHf8Hkpiqaho0PRVh434wXjlU9kgU11eTAAaJxre10AavgmohGan3Gmp6d0Bwb5Jj7JrpvGqaAkRUu7yrOvZq6Ejo2B4MQl+0I0wRMNrV790XvWXxMHfwx5oUm3ZrtcHSo8bTM0pQeXNQpU; 20:lRRZthV5grgTY5NXyH4EHhYHw/FXtOkl/K+2JL7Zso5HWwwe6CGPGR8vpe8wodecfiTQEZEYflz7vBIz1Du5ybBO8G1DFKKcTc3D3VjgptEur6yviL7TM4yYFB69Z0APdU8EBdhlipjo2epFdEq1FQ5JaNfmZn9R0EkVCvv6DEIb16qaVOeG9zahAY3wHyotHsYl5JhqN8m+/sJvtwnXHFpu/NVxk51E/dscEjgl5LKFr7H3s2C8NL8+zLRvwqUG3OJw3m+iC+5JIHX3UAadKUszGGgwe3Z99j3mwadKzBffiG2trUmXH8kq9T2jx8baps4ctmgDudlYim962+xOtXkakptf9wDGC0KfDYQXTc7V2LeB0YDJc79VPqyRL7JF22R2ZR40ABFtreFjwGlZE7fWzU1EzyWFXrZmaoaXGMNgb1BOQQnQQqla/6p4iPeWt9cmxmhc7B76rWAHHGTgAwdsxuj9kD0eE3JrfRi7uPaRAKRDki7Ix5bHP5C4f9ii X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(20161123564025)(20161123562025)(6072148); SRVR:CY4PR12MB1240; BCL:0; PCL:0; RULEID:; SRVR:CY4PR12MB1240; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1240; 4:SjDAn5Ocxs2zurDcpauFbKqnFrqmSDUkzXqkXI9spzA51oYC9YfGgJW+0x96crpJ0t6eicFjjDWoZJ8BEAUz8NxvJkABf9kazxPiteCLHvE3pU8YrNPbxl+rZgIgQjnC4hPpPprH8FICTG1KQabfucI1WyABzI2zQZ5Wzwmch1zgeawCa0/KlidINzTeQyTOJ42bTpcUqrBzZF3lIfdddEowHdzc/v40bMQMKGtB7qdtBJoQqq48OBMoHZt5fY43afUfkarlEqcDtIC8Gt+4CGiZIUrzgaayR4FIQrCT8i5q8vMTl0g9I618+T6eyp6+pXAFWENgtlx6e9YeEpp4I0VKXaQuKUifQZFAeunD4bzYcZZTbNoRddDQyW4d6nKRgWrpepT4e/aFozDXkFwITCibBNqqA/6QyFmVX562a4kT+5GEJX/Jg4aBapQ3SfWIe7+LKlVXeyhVlBnDEsSGffjhj9DwJhRDGHS292BKY+wXCmLRtWHJepBfwpByiKLKjA2XAlA1g/mW/vlKHKXT4FjK9eKzxdI+5c07x2vd0BpBFe/C0IIBQscV2AQtUmYC+j7p8u9H7nhwSy+fdXrcdZmG8TLmllRGJci5MFRAGSlgoj9WZGTqFuMVr0h77quzUfZ465UHvdAV3jpUBHgjT2WKBmqFlzV4/5aGcMQwCebeUWUugco27yg5A1O1xHc0NQaUHoXsA/Mo3VwrbsYJYP+h0ZuvLgme9n0YGe+wPXxpC9kGWaFqIgoUNh1OSqYesD5gnRFzcTJDOI1MDZxH2ooKXh2ipdKR64WDwzIAuhzu8ToOjNS1846KaX6FWILw X-Forefront-PRVS: 0267E514F9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39850400002)(39410400002)(39860400002)(39400400002)(39450400003)(39840400002)(2906002)(50226002)(6666003)(305945005)(50986999)(33646002)(42186005)(7736002)(2351001)(6916009)(50466002)(81166006)(8676002)(2950100002)(86362001)(53416004)(6116002)(3846002)(5003940100001)(53936002)(6486002)(53376002)(66066001)(966004)(38730400002)(47776003)(36756003)(189998001)(6306002)(54906002)(5660300001)(25786009)(4326008)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1240; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR12MB1240; 23:Ru8lR9l6AmE9MMQlDoa5p6zjBp+AxqU6r7/AgGCl1?= =?us-ascii?Q?vtV8a+qbog20Pe3DW0B0iJDMScFv8Dmj3N4GmeeeNsaCDexheWk+/yCEfIN3?= =?us-ascii?Q?Phwqb4cita+EdXa0PfmFIAzvAeuPRcqWqBUA6ZmcF7iC9pqONxjXaLZzvlvL?= =?us-ascii?Q?/Ve6HJ+/kzlhTC3yy6ewF9NbkInnHlD3ZVxp/X24QvqrKWcn/KWbLIax8qLh?= =?us-ascii?Q?TcdRl5x5NBP/nUHtrgmt05W/7pL5qcJkRhutVhp5Tb9S3r0D0tzv2T17EcnG?= =?us-ascii?Q?YJBODwI0plIW6wbXjsFopLRm7iV7+Ed+gD1SHf1djzaKKo086uexX3ZuGmqS?= =?us-ascii?Q?q2HTiAAUw12MqRxWZbdXTODI8DGivp4nKUcoLIEzZ83qOxRmrrab1U90ffvo?= =?us-ascii?Q?1cQx5GBzBhHOeHTujTLWvd7gqdBQWQ0fwIZPrHdBlJcmszm35zvzsRSkyiEc?= =?us-ascii?Q?kUIg+U6Gc6VmeHL/MVS08Q0LhfVUwMwlwc4qdrcf5WIXaZt3D9XdIok2v8Xj?= =?us-ascii?Q?oCWsL9Kk5xCs7PkQD1ifGIinpJSFXW46JTN1SR7syoPEmycJp+C4Ff63/xX+?= =?us-ascii?Q?gMr0du6xbjHTlcYfihDoHYNW3XWBf6lXOD5UNrf929fgzp5F+BFJ83N9HZOF?= =?us-ascii?Q?f/vBin7ioA8zAxGYucT/D9crJDIVvxrxSgHVP9zSyb+TWzKC4pJ8oWXmNjtI?= =?us-ascii?Q?Aw97v883dhltx7emSMZX9cDLwcEh/a98d7jQTe8rhzCJX0RCZ8JrPP5g6O8O?= =?us-ascii?Q?A1cvlvmlpnYoSZK4h04H/UMSGPoKHT0oe0QHt/c/3qytA3VZp0O7gr2G8PIR?= =?us-ascii?Q?V6wsK/G8Nxq0iIbRQHknVMRANrhE+zjtAjmCQ5bjgYqMbkFOIgh3Wu4WHswT?= =?us-ascii?Q?Aa8/Vn/MKWlumr2LO0MpXdspNdAAVZo1ADHsNw7ZPOvxpPGyMrf92HNpXikI?= =?us-ascii?Q?apwt6kbbt/IBIdWp2JR1k0j0bHiCTg/kNaWuWulLQy1vU9Wjg9JV8Vq1Oi3s?= =?us-ascii?Q?LBlVy7Kt8ygvqlxlmwIRYCbqW9g5TWfOBfFXCOVae1CsTxANxQpwAG4MnMue?= =?us-ascii?Q?kmS02NWb/4jW64dWt4hAuGkExph?= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1240; 6:JukHaCIS3XcUXnbz6maZ5MHIt4H65W5vIvdQsoooh2WV1UxAQnd7S5v6XAYarfWVGv7hG1eROD+T4uuMYnBCh+OgPX55TxCSRnCB+bnY5U782bTS+/vANIJ6iotTSByT8m0pLO3oTNPTLNVE6LWUNpdyGGqlgApvGSfVQdoNldvC4nfCSfneKMg1M/my35P1nGaL3svzbzVsNlmrYJqkI+BNOdl5RrC2N4wH9WiY/9ZgO/Va5LSsM4J0tW3zChRxgO91Gx7jNGf3gfNSaGIOnDElxmH+YdB7b15ijKMNl7g3s3Puf5dC73emD1T09lJ+L1QXSy+ISG/96zBYhLXWM/PRJOS+iXd1Gc5Ul5sSehBU0q33wAiysy1fHUbIh6WlQSJ2r1gRWCPXXkCO62gknLTr0JqpJBdL2I2cPxS6azU=; 5:JrEqCIVX8MIHH4g2+T8e1RMZvPsdLBNzcDXjp2lqXvTxt7FK/cUUyfkX+IVoMoJ2bkGJTOuendxiITlnLP57x29RQ8F0TSy/NAkQuzc7QySRX4BmlXUn1P7dId0Ul0zPF4WrD1okEeFsutWMt+4H4Q==; 24:0RMYuEh0UOJtw68ghqw0JDMmsbRXns7CtkeC2zfG7y8zYEvzd1ClulCFy/+qvR6ZWBgvtFBg2kuwGlQ0q1j1MyF1iS+a3qe4w+RO3XuGY6E= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1240; 7:DLtrK+xsycDiqNFYXdMgm1nQETLJsRepbXq+dJBraQf3gkyIQcUWhiWJB/1h901X+spRtZZTY7iteV2j5EebhGfv4c0fsCd0EkQmz1ggOUxQr9KWxxinvuwO8TwouFPvBfk3VyjrePMSSroUMk/GCVma8ZUrmER6rcIzVlMESFph2kFHmqFmwgdKONY5GjLbnCCxQicpwb6FyZvMtXtbeS9ML4FAlitu6Ee4AY3EqgBFUSJlILH/0pnGHb+vXtinBv5AdcAXwQxiSvkOS+AsyRmHmpxe+FzAorcl6F/CttnjoqbnKfoOZ3lLa+badgyUMSJewDteItv8hOAXxVJ8FQ==; 20:gY2nsnwLL5Sihe3V1kkcpkB29jJz2E5w4Jt51qFk+YgVwhDu7AthB/PwPXPj+U3hVTiwFjhR2l24v/vRHa71qTMuwMEFMxipWFFrJKBBJ2GTFVgJt8Lc6Co9t6ZnqgTAGMsRU18exE7xtpg5iJuiq11tiYcj2GAXpT3vIh3gjwH1UHiufIDrFJBS1sJqo3YYD6tmhlK8mRoOZfMMkCQDv7nVRpsDduRFraBg7ZTr1kvAklUobS1nUC3hWOaLcDjs X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2017 14:11:28.1420 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1240 Subject: [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: Tue, 04 Apr 2017 14:11:29 -0000 Content-Type: text/plain 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 translated 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 = 0x00010005 + BASE_NAME = BaseIoLibIntrinsicSev + MODULE_UNI_FILE = BaseIoLibIntrinsic.uni + FILE_GUID = 93742f95-6e71-4581-b600-8e1da443f95a + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = IoLib + + +# +# VALID_ARCHITECTURES = 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 == 0 && SevEnabled == 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 == 0 && SevEnabled == 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