From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0610.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe48::610]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BA56720D76485 for ; Wed, 12 Apr 2017 07:55:33 -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=rdvYfDhzF8GCnglj435l41sMxLVlrsJ1g/JRKU5Gf48=; b=Q+oU56WltJ8895j7OvyuY1Kx/O+iRCo4yVrSgbWkSgQcGXV/9s9NH+trwIFk/G0puj+z7BbtcviAgxsh+ztUQfhz1pNDsSdcRtVQvPLCI0XxNOCghxhgODVx6smvMMSA7scjClxXKt/qlj/KET8pmHELLixm2Mmn0TlKYiwCek4= 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 DM5PR12MB1242.namprd12.prod.outlook.com (10.168.237.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1019.17; Wed, 12 Apr 2017 14:55:32 +0000 From: Leo Duran To: CC: Leo Duran , Michael D Kinney , Liming Gao , Brijesh Singh Date: Wed, 12 Apr 2017 09:55:23 -0500 Message-ID: <1492008923-6566-2-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492008923-6566-1-git-send-email-leo.duran@amd.com> References: <1492008923-6566-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR16CA0039.namprd16.prod.outlook.com (10.169.34.49) To DM5PR12MB1242.namprd12.prod.outlook.com (10.168.237.21) X-MS-Office365-Filtering-Correlation-Id: 33dd924b-0a1d-4cea-9a70-08d481b3f82f X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:DM5PR12MB1242; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1242; 3:+v8Hrk+70jTpCGmcphaLQy5Fy3unrFu2TKo+QE3kcKB+Q/VwBHYE69q0sAPeYw5SQUJ4GUE0kdGGhluK81geyzL/cIX1K9Bbch29g/WtkSlx8pZe9oalef3uJ4kHNIQy5RLNrziOs3sfnOCu6Qdcnm395I+DiawTuEUS5XDx6/UYlVYtJAOjPvj1o40Qx8zmQvvUReeZCLk6861W48Qn1tYFsNy+lObubdLDf7LW2sMhqAmH1oJ7hwXltEQ+BC9B40M71AGF5FBR2uBnI1EOgQTB0exumh6L0O31FprauX77+AVNUwW28YdkIzFNoT4wPmpN6XClyVHjSCoIpXU8vkibURf3wDw6qD4dQY4Lm3Q=; 25:m+toZd5TH1U5G0A955ypdHyT3t9OJY4GXreBwu1XaIi4KFPt3JB0tB2w8rtR+zB5Y8W+rucNj57MK6B4x278izgVIqS/bS4OdMZP4skUiAMy2+1qGurIItdr1EEnhAdQFZsGO+ouW3Xv9xRAGiJz129gQxEZQ5ZIzxWpCfKxW9zSnckSzatTO0gWOT8OQig0veSAoe8NRAij5QqQdUXA3Ds1o6KEXfWI0wrS9TtO/x6V/EhxMem+2efp1BGpEufnJQyXno4xSmPWohjMpuoPpehdqxWZEX3dLMzkkpU2AR7agzKiLE8zvwTaEjxweAKLQkd4/CiFk7XcUy6iEYxXcLt2vxdIWsiOpF0O4blI2qizq6K/+qLTkNIYaPbniuCE4njqN+GAe1mdcrpoabMobp+FYMYYxvEkDVtJLkwOpJNkO2UbevMK6f1IEkqolUDGCqL2VGvvh64hgKtBgl02FA== X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1242; 31:FjId88Mbj+xCsTYPVLJPNPLLlb6s7ni5JyiLecWKaWxbXKTLNWNcO3ZdV7FNZFJxQry9v2LEJuDHuOkUVinRTOSTxV6yQ4bGbd0BdBcWY409eYMyEX7k66zkKJfLjNphiiAYzcAC/Uq11hWrQzzaDdOK4MPVLlwzaE5514VA1xiMCX/BNk7OiAX0Brkdg8J3PBmNIAys79wcdQrYQAbjhMQxXzrIAtsRmYcxRWd9oo8=; 20:eiVSc19sLEYHzYrQen28/dLgkv967O8xk+wBfy/vtQt0PIUEJ3YNJt8e+yQS0Jpp+dvWcfKzzAt3qK67i6odoFAr8xM/0gwGNzpW8sU5S5n+YJxxWGKCZsM3uzxKC4spUjCB1pzvjWW6PtY/qn1LEO/ZGA2gQtrvkVrlxFXiDXmmhxex8EQRDhQEfeL7h+24I9zg8f+nQb3VelITph0igxJY9L/ieCIqACtpM2oCdtvN017FHq0bBpImzpcg3gAt/8VTdczEE8BkRBRux5IBlpoK351Xnyx1ULX/Fab7khbDkAiqWgcI3UE4KlfwWS/z2gxgDvQydyA6vEsox92aXudSwvGpcwQV+bKLC3qn1n6tEbHT2L7mSUhqSE7RBVWjOg6xCxBz54c/hfJ62ZXsIHGzmc0V7CD+Wx03t855XQpdMS3rjGoqgyoP1UwXylcgRnfvCpHMxZzvyEBccdSN+pkTQiXP+NsfDJcHCiKdVpO1rR4kjh9JnZESzq4kVYkP 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)(93006095)(93001095)(3002001)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(20161123555025)(20161123564025)(20161123560025)(20161123562025)(6072148); SRVR:DM5PR12MB1242; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1242; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1242; 4:F7knHXqQSWJNZW+radgpYnukIiTmK6GaXvrXmVu0X2XaFAIKUw9l38sWcO0TvXxuH0Ly5Qh1UepiNoT+eikiwBGA8bAE5y+MYvKHhjlI2oICEm24NFRugGPf0i2ohnEMVF46SPzrGMvHnoDD2npjVZCKlsRrD0bHVFOzotO/qd3QJjxNlRJAF6QtrmCRazYDsiWMKVWHkeClgRb3kG58LlSdhVjn3T043SjD4CRqsOXbXwqlXeBfj4zt4iw4ZLkkmlqfTamJNLj0fzl4olLdWgCSgSN16Oerc0dxWgLG5hGWDCsIksu1bKbc9aAnhpusgUU/nUehWaNhgnJ2qZtYEWScOKaKAQ+Z5vUj8T2gAiuBar+ER2w1QHyBn//VW6q1LoBlcyL7FgFGWintSn4qcr1CStSWMTjJocs6sGDlObX5HxSwRj3OyQQf6dGaSLEmZay1RCe+paIagBubexngm+xa745gzynne6XH1XWovOW8fcsu3b4vhun3bulg0kHutooMJnfq1pR/Kq3A6EKO9eyukZMXDPrp0Hqv3zVFNw8m2Qo3yT0Q7FU1E6AN2E1zgDxKw/qWZJ4uNgmTlJ3pr8LalpB0jgWiP+G2RsZC7HCPJB8WQ/uHReGUlDs5SwO4YyWs3a21bnUFvP7Uf21RTMjwOelGFheUAKa8EDeot9M+8tnorqABWhJy2S+YTzu6heiLPB7/6/3c4peZwa5GTRalPwFS91rzzNiq8/JpDXFCvL9Dvs5W+D3D1NCXriQqCXOAQnEuUZ8JrcbzBmK2NYOXbvPkt2eeMIgnDbHSJCP2/DVD3kj+W5CpalL2hrcb X-Forefront-PRVS: 027578BB13 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6029001)(39450400003)(39850400002)(39400400002)(39840400002)(39860400002)(39410400002)(2906002)(5003940100001)(66066001)(6486002)(6666003)(54906002)(4326008)(25786009)(86362001)(48376002)(2351001)(6306002)(76176999)(7736002)(6916009)(50466002)(33646002)(5660300001)(50226002)(189998001)(305945005)(2950100002)(53936002)(966004)(81166006)(53416004)(50986999)(36756003)(8676002)(42186005)(3846002)(53376002)(38730400002)(6116002)(110136004)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1242; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR12MB1242; 23:BrN6a8moclo8tbtICkitj4Yf77SgsaqCWep//1hq6?= =?us-ascii?Q?xK8QDDh2dXRbHVe4Na08nUg6kZ2aErMQkb/o+tmkcDF9ogXxuUvC+dbtm0vH?= =?us-ascii?Q?YCYu01e6qVIwFsgAvRnvXZSN/DvCHJSGBXkhv0Akuzy1JYSpQJxW5DFwzu6K?= =?us-ascii?Q?7T2apdtRR6vsfFAmLU/sN+pm4KypgoNIXTR64lpc0w1AEUugVXBP1ZsFZI2x?= =?us-ascii?Q?uvHNkSnztVVB2gMd5dptUYuQhcJN3GwnJI5UFJT49/4zlBWXesXuzP1FoJNJ?= =?us-ascii?Q?M+x7JQm9iUNvEyxn5tlKe7bA0zSm/Zxqbl0Ll125KOKr/Bbd8c+d7Ahg/84E?= =?us-ascii?Q?JLu72IPuuQmkEgwae+Ykup/iRNbL9Xtvli3aSyfTmAU5fa1kSgTfUfxA+P52?= =?us-ascii?Q?CKUp0YuhFsISLSwENILBynNPaUg8LX9ne51cJsPb9xb5bUTjYQaw4QFylkLB?= =?us-ascii?Q?nd/RzqZKIevh2hUAC/eBDlmSiJjfXiEdwt5g4znoRUyaeFG4m9SczAz/4Wyq?= =?us-ascii?Q?+y0mt7QEKkCbKHE+ee6xaNsHD+7AqkiyX2DzC89R9VaPJeio0790h6wTnFn5?= =?us-ascii?Q?QmOP/irdQzUih41PD50BjvAIcIOjBMTcjPw3X0CfRCrNary40x0xWqMmOTDO?= =?us-ascii?Q?jUNdHPNAs14hZjzD+r06Ng9lv/f9NW4O3X/f8m/wlZ+3OKr1RdngNMXAsGIA?= =?us-ascii?Q?dsYBiYp26Nel3w1vxs+QdqKOp7HWgU0pD1mVB1sVjKv6eTnpj87Mq6oqS26n?= =?us-ascii?Q?WtjR8mW/y7RjXsnVo7cCWtF3o/u31+JK6k/FI6cHceMBClEbkeQAOEAUbofL?= =?us-ascii?Q?WJIlBEmJ6mvG8E1JQZ19yWbx94rqCoIE9aMb8qXC17ETed2ElIcKIKT18woI?= =?us-ascii?Q?yrt/TyRGoNnpbHqUsODqkVzLLJseH3pTTvSZ1+XqkKD4I59K0SDPQjpHdIGI?= =?us-ascii?Q?G4hQ4lJMfqwU+CZZF1L9JgmIHM6ZkWdwX2TpiixIqopm3oBnLc/N+QTR8lpu?= =?us-ascii?Q?Q99w0Grfug+ZfYVBuqZ2IhN9B+rgz/tT0pgaKXMdMHy1gReOv7urBpswgnW/?= =?us-ascii?Q?YDjDygTUtAlWs4BJuidSlrQx06t2awqThqSqrUWVt6TZnolkNqy4Iktdu0s8?= =?us-ascii?Q?QlE2vGBXbFdyaMPdM0LcnB3DT0VJDaF?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1242; 6:7iSxwOhUNyl/Ut7q2/2aEQDagkwagTG63IleTYDeWK+9qVFDpt2YVdksVlyHbmYJgIsQSb6x4CQ1Vj+sjDwE8UnHuh/xEmJySMJUWZWItEB3iVraBrxxy8U0S5CtiRab4s+fdtuQinxAhlcZMIze5p4CLoE6QZMmnY/23NKWcryg8SpcuC0bfwyYHbw+rrjsInCHMq42h517W0p7gPQShwPomDYTrEn86YnDX57mRK/PYKKpQBNuMxcKfmIi855UdLSTfSsFkHQ1uwXaQ7PphEtl6MoKWvKiqpq1naYI5zMXKzuv38ufRtYtNWJlKWdhHnmLGZYIjUxqz7wT1q9Qqr1G2JloSNDGcPR+1ENoFylvwgIxXDBh+BrQtRt3xWLfE2WLVSUBIC2hOLlZ7TUrg1aOyXou5jOlKvf81gvGJ3ExqCZn1c8mhYt+ZSCxIfgble4ebFiT1Rxp3BvepA5BhnsQi4RO43F4h9CTVOySDjk=; 5:1orz5AnsfTlmuQFgFZ7gcktx1V5g9UBBAxobuUaVjoPoEwe/3rXN5wfKPHguQ2PLbWNmDoAWdRSLIWrK2yOs6Z9ShmMj1P12+Yi1fYSyABSrxBwZGszUKX5AWUrzrGNilLJAjubaBYSyxX/qbdlwjDM6pvN28aado6IkWwzCYm4=; 24:GVlCgNT2UQoyC+2GgnLGRima9d5To5+IXyPHPNDaGc8O6xHB2DcyOfXYBuveuDunBNnW+uutkDvAwiJR66+JTN4BTuMnIAlqQvWSFnh4n68= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1242; 7:EDhyyIhEtvKBSanqogO0RTKPHLja/NilNCGR7YuxXYTUWKrK4kCdyTZHjjT9bqIHdirrSUsvQI3jeA8tX6+jzd53VAhGGUUUqtWcwO3g0hoq3AaCTehOBcGSpKraycZVcsaXFY36QnI57QD6p5KrR+5H97XiH1hQS1j7RiF5bh+0idmVCyL4GURfS0c2BzeePbuHDrzIpfIBLjycpTnTvE1Ct5OwmpWKgMUM3UJtdxwJru6FN60DRCbHd8niIvBvWKl9+fccmA28h+u6w1+kCMQIZrTQ7syhT9h1n90sfpCBsaCktF1Mm8zqvENTPTaHonj08HBn7r6MDemL9Th4Xg==; 20:B+ErHem+XAcRZk6DQyVHMJ/8d9TlGQYDtnZly27omrIozU+WUJD06h2p56za0S65XdMTUbMQQyOXsgydrs40rvsQv92JGcj/9V86aMIuCFyA1yyoS45EAOxWxNtKuP9t32udZo1JPFUV5bwYPAk4AIePhgocLsFuF7slIWwqQpJYy2aBc4uWfuev2FC9noLkzybAY3UuSLsJTPvzPw+x4NJTKm2aWtqp90oxwc1bnFVHLFU4IOtZJ28m28Y3cClk X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2017 14:55:32.6328 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1242 Subject: [PATCH v8] 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, 12 Apr 2017 14:55:34 -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 Reviewed-by: Liming Gao --- .../BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf | 59 ++++ .../Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm | 299 +++++++++++++++++++++ .../Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm | 288 ++++++++++++++++++++ MdePkg/MdePkg.dsc | 1 + 4 files changed, 647 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..0eec896 --- /dev/null +++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf @@ -0,0 +1,59 @@ +## @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. +# +# 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..3e80c17 --- /dev/null +++ b/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm @@ -0,0 +1,299 @@ +;------------------------------------------------------------------------------ +; +; 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] + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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] + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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] + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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] + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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] + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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] + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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..26e0166 --- /dev/null +++ b/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm @@ -0,0 +1,288 @@ +;------------------------------------------------------------------------------ +; +; 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 + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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 + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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 + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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 + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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 + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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 + + ; Check if we need to unroll String I/O + call ASM_PFX(SevNoRepIo) + 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..8b69de3 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -134,6 +134,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