From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0621.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe44::621]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E00F22041FBC3 for ; Thu, 6 Apr 2017 07:22:43 -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=6W30LSdi6EEIxOvg9HOERufX2EKbcuPb+th8TAPZSrk=; b=oNEM5Wcht77bDpfi89xREl2srHlOUYC74okI0OtbYjqrYc1X2m78NsOg+4b4LqqpCg5PZlxI0sjNCTcTf4i9zJVlrLXWW3JHW3b7I+SylS4Car/btbIhLwRB35BYQ6EJdINYOK9WY1euJw2nW2PJA6SyP0cod1cMkXRqKpFQJH4= 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 DM5PR12MB1244.namprd12.prod.outlook.com (10.168.237.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1005.10; Thu, 6 Apr 2017 14:22:31 +0000 From: Leo Duran To: CC: Leo Duran , Michael D Kinney , Liming Gao , Brijesh Singh Date: Thu, 6 Apr 2017 09:22:22 -0500 Message-ID: <1491488542-3811-2-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491488542-3811-1-git-send-email-leo.duran@amd.com> References: <1491488542-3811-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR07CA0014.namprd07.prod.outlook.com (10.172.94.24) To DM5PR12MB1244.namprd12.prod.outlook.com (10.168.237.135) X-MS-Office365-Filtering-Correlation-Id: 3198758d-9b6e-4b66-1b21-08d47cf862d8 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:DM5PR12MB1244; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1244; 3:IZ4GDP5F8GY3NMpAu1jg722aZKT+3XyVjTwV25z3/RLh3DvStKdJnGpVSUSINwp3uKfPt+52CosbsCKueniVEIUGOA3RrkDc+O6vtTXXuHRVgkDBkeodA8Wr7UOzPANz2IO1aYeZs12TOJ4WgkCptUV0vgwK09Sm+eJV3zLrszEqUvfaPlaVm37RSOHFMT0ct2gLnJHbQIFP5CNO17gJM2cGna4P6G34wEP+aakTYno4Zi8AAgu0rb2cRVv8HreOF0j+zQtVWnQJnVZUdWE384iQncnLd/mh+2V3hvymFS4pwK90J0VKhVdOpKrR9mZU5eEKfLtK9KNDmgXCy54zVsrWG+sodN/n5pBQl1B6Av0=; 25:HMruVTsNHUEx/yVVYFDdPaTcH+NYQURndPvQC1ocnRinNC7pRxODBQT4UKpMEPr7qKqL+c7DluNkSL5NaN7JMqA2fc5y8c5Efl5i9D1egL1dmSLm/yJUoAUkPR3MThIeGolUMVuaj3EUZUtvAWGORHp9/nFin+uLK9ZsC2akb933FeW3fvv+6cOy7GnwChc2gWjOZE+z4wwn1oB+WnZKENNjPctpHRHL94NKsiHQPtNgaTzNB0EM2CBslHnuBdpAzH8tXebo2iYzPtZFIIxERjKp2J2Sh2QCysHK7qI1BVlSDmtqaxlVEDOB8TvDBH5Efh1LyCSFKMHgc3WKH119ZBLe1KjS5LHKphP4HL1oGbmj5liUbJ8JtFSorJpvksRCDPb4SP3v0UVRUZ3SpEGqMNa6lyv+sk4EFZG/zHa/HapUy6hqJ1eCo/V4Foq4+K6Cmzkp/1w8suEM+Ng7eSfbqg== X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1244; 31:sjcrOhPG2FqZt90MCGc/fmswcnd1q6fjQIeDT/Y74XR/EXQ9xHgiu6ph0KDto5ZvTzUzefK7oigUor+e6chEIWA1aBszYFUWtwDbtDImF2ZCnPzuUtzu35LP8v/jgE5ubjXDWBYmdAJ3wXv140F+HNvQ03uRH4o6UA9t0HQu7UKhGOx7lMQh2aGLD5Pn8w3YBooIW97uDM62RoZAPcu7TOxco/lbJyvuH8pJllpQanQ=; 20:T84Z6MFyaACx+/9I3cAyAqG4Uj4JpRIP6Bex3WVqXiKKGx8nIO/IYHNUnMqFwqpGwQ3smDXKfJDbzgIpfpPNT53A/HP4wY/KWxDy/K2XnKgB3R4OY36ciiUfz6w1pWXd4dmRa27b+5iayfC9rSHH7ikOHB6X0qkQvrFaQKIgZJ+WQ7/9zLJBGYc4ujFUvod6CGl/7/zo6VRq1EgYVfa1dBb9QHHL3t2f+AEJmrO/Lrs3+2s2Q0njpVmGcY3qUZTFyScjb5oFdAmhIpb3mRpFAgeGXxqtqYdqazVdpcluVcqF6crheYmdq+adfNhJGcVUGFd11HTKKQKAK+c41ONH2FqDapCQ4dPNG8v4QQYrqMmEnh7O6IFBnxb6AFxV55er8HeBwYkpTdlDj8DM95Z9bUsX+Ggg2DViyP8RkUi5SzA2wHNSa+Zv6XgAilkjuG6xNaMgOqMN2yz4jEAqxTzeMKh/2vsFg6u/B6DRgCo6Kb/XjqOH7yinWXbmDwV1WCrR 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)(20161123564025)(20161123560025)(20161123555025)(20161123562025)(6072148); SRVR:DM5PR12MB1244; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1244; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1244; 4:BX/AkEnfDnjLxPmXp0UnYIqmsa+rU4ocnVa8SnSewlWiaHvTvVfZEZuZlYVMx16I52S9FU+tmeRy+9fV3/Ugeye85woRwUen7wYOxzLx17ubG01TdSeCQIUza14BtyVjyXDYK96PuVL4BlbhqOnAGroyPbru6wuBgIOce8en5Ky+sjrtvDG1D58nHzGyHYVi1HihDSMC3O5OXYC30zO83YxFpjGrtXscIEWSzG0ATSl7KiknLuOHSDrgjV6d0POCUi4o93rw6xF4O7Er2zTYtq5Ks+/oT+2i1I3/UWdx7eBONcwncv2zJNMYoFd5MEcMj9Rkj1RSQBCYWblBOXNYEik3vDGJiVfVdagvnCkgYixhn7oPK2qYWDlzbxbVRa6Hh1N/RW+FMLwVtMiOHAUCr2oc4YP7QRTPROOVYoz7FEQIHK4N17k7Yv5PDUJ60jxYqY9/7Qk2ew5SNq9Rmn9/x4CI3y15Af4x4mPJ53J8xQ2KieVd9ahM0Hd4PN0v31iQQ8xoTtd8JvfIUClxR2/6flFvq5IAdBzM6e7xk7VtS9s6WzY4hJtXZKrn1hln6BLxRAggbLu6fwoIWF9AeMzoWBnBW8L1ppw9CTVn8ycFqs35tb/AmDzDYoe/At/UOzaoPWGsKqOHz7jKRijuSxke3DJorterVthBFVHrRozRXJsbGByMmbgnIiCRnMGaRkVojZlr1wZbGf2QhY0szuv/PSZh2yh/fYrcQR6XpN3T/QAyzLndAy4qR/g5sXqykBStis+y/1CnEePx4qNUI23tbpbtfJJTPc+87NqlASYKCWgr5AHN7RXUHQMOTorpa8qZ X-Forefront-PRVS: 02698DF457 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6029001)(6009001)(39840400002)(39410400002)(39400400002)(39850400002)(39450400003)(39860400002)(2950100002)(6916009)(76176999)(5660300001)(5003940100001)(81166006)(6666003)(53376002)(36756003)(50986999)(8676002)(966004)(6486002)(305945005)(54906002)(38730400002)(110136004)(50226002)(53936002)(6306002)(7736002)(4326008)(66066001)(25786009)(47776003)(42186005)(53416004)(2906002)(48376002)(86362001)(3846002)(6116002)(189998001)(33646002)(2351001)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1244; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR12MB1244; 23:7O+RPLy4fIzLCMHu0iktpVmBeiLxlnMUrL9Qf6sOu?= =?us-ascii?Q?LGuvtSQzOPTvNVzqOgP9qiC1ao3eVTYKwrYONjB+00nuECWN7p0nSuFqwBws?= =?us-ascii?Q?Nn7r9rxK3Pdv6Ui13WuraDerZdeppff8NJuKRq8u8x/JfUtSTZFnMMrplo4n?= =?us-ascii?Q?BoS0TLlP6mDLkCuGbPDVSj6XbJAN+QKQ6ZfoXmEnh3veCq809t3wlIz0fcKL?= =?us-ascii?Q?SGbvEHy+wLgZXxarGfZXGoFt1F30D9Y9TXK50CK3cey5HKN3zzLMowB9gkJT?= =?us-ascii?Q?jFLxR3cOX3twIWwk9u4rC6AyuLja0p1AXSRsQJ+zPxJAZpiTyBS7q8tMZOoj?= =?us-ascii?Q?Jl2e+5asfYmdZBRteUmvdeEJ/l0NdvFpjBE7ddRotBodf4/RNQLmFynxGh70?= =?us-ascii?Q?iwAVsnTG32EAMS24CEHAE8VkMGKVTaJmv3vbTgHVqan9gW5gpGjP7cfqRIMt?= =?us-ascii?Q?hygp2wAE2x4s/wAaeONLBcFoRZficrDOwDXzJtcbRA2A2oZOTWaqeHWhsPub?= =?us-ascii?Q?sx9ZRlAPPmph5oZGRP+bZ3RZQcj5moVPTK3owIOa9k3alJdqyqDBiWHZ8XE2?= =?us-ascii?Q?6wQKPUw63gKrTSgCHXaIBzFEydif23tZE8gQLa5lQ6WFGlVVUICm0hMoAJgJ?= =?us-ascii?Q?OvfztHco6VOC+cWpsfgKvuGzTw+GZlBzwXGD537+hrEteoNT36bUcbAQ91vo?= =?us-ascii?Q?v0DTFaDwAeUEgiMReNt+tjehSlzz1+rUPMyJFd0XsD9W2q/jYHH1Vo/pCOgm?= =?us-ascii?Q?c0pZZgzxDjYjLBa0Z1Q64dWG4pfL+FRGcerqiUeBJ5bvfqKim+WF1eYDiRnK?= =?us-ascii?Q?dnp17XT5yx/frG1OR4CQI+EKQoqvqSOIFx9fiPyn+x8SFZy2eb7TEYv6jeGQ?= =?us-ascii?Q?PsS64xN5//X6kup0sgF/QAUP7vHMttc1el2pYxqw/hASWV4DSWXItMjSD2C8?= =?us-ascii?Q?IiZ89kVpbnl25/TBhSUIMhCH1PnyKLc/n8pHFr8qR6Cmn1KHYRukSQEXwr2A?= =?us-ascii?Q?PdX0LSSk93nBMNVftwCJRjzJPS6rLvn4Rj30zckVhNf5uiSRs2jIxtkTahgC?= =?us-ascii?Q?zgiBEC8rtRkCzbGh0QpNgi/9LSHxDiauFAIwt/IyRvjzUPS3boUFKMLNq4X4?= =?us-ascii?Q?V92rfRiLlN4IEfIitiC2thUkluOqmXm?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1244; 6:umqrtM/6kXF/b3SGcE+fJ+X58kKuOb6ZXIPOOlF4TTYWroJCLJmF8g0nEpYdiTZWi0lhL+VCMaFjZeXxE+d8lowW1xLyxnXVqaVZUvycvPCEC0xKeO6lgUDfIW8w+c/CxGiWqSmHW00D+iTTWUygkFrI5dC3dBFAc67hd8P4CMxCkwAl9pcTo57pkjIjXOgrozUDD0jGEXXYjoK9+MX/VY2YgYghZjDCnKeRPI4tSbYayMkQMybL5RX4IhNtguPoMDxLvKCH1sGaM/tIdQA30D9/YSwDlCProaY3MFUXjUelpfdSHnnZW7qdaG7/Wymrc0lD9rniv6UFf16CUinYZMQnaHo0eKjcN50UaRS3fMZCCSgPbBScCtpUTI2c0ybCe11nDjGw181W0YVdcS2h0kiviBUfx3mnYGltph6PiCs=; 5:yRkV9a9Lvl7wN4IITNg8ONlq27cbtZEZBFkycRebqRccVoWMKw1tqn3snvWLUYmEFZhsLSPgF9RSNhXcX9ZBeckSaWC+9ZFIjr1Il1EgpxFHo3Nkx4a4jehV/wb7WQdU3tP7oK/UgS+AmKf06b2BUE+5yW9ActzkRY4VHbwFFfM=; 24:S71TmGYmxpKaVThZFDg/7jt3Mc5013S4RJFSP5e1DbNAC+ODsgRE9HWtC8jJyhwDmgClRVZRzGRlP8m3KoBSg8DFIBdct6V1c0biqj+z/0E= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1244; 7:dLw9TG73vtLvFlLVLcJ9h48TBQwVLZWLQHJImcY+Q57ZTdDUyrw/ZCpCUPB+qZChs6PoINDcdcbS5o0LWJtgCRsSajNKF3l2I7L/Lqr/efK7wI9mrNYj/tOVboW4dZQ9iLhLVphLT/o+CPNlGM9NUT6ouQe+gW1YsiB6n48PEeVn/+volSN0GyhMjNXSn6bcV6x24fA8tLyH20Wn0uTMyd1/OvpO8naPWbfTbLnOaMbQbSBlyYdczdckP30fkdz3uSRMj6+Vs3qfHV+TA0t+D4pqyEZL3CjeBzBA2yvNQZLqcKGbSQUt6AMbxNeGZLN0iE99CFb05jBRjajmIIqC9Q==; 20:Zq2ud/VpUKAxUtjTUZVtXrN/XjBtFPk+5RpFfigb3A/IwRb2ImvS/kwa1F7vw9q+lJs8pJM9GpWHGMHUTZfUioe0HgxVg3uYkRGh25LzpCnzVe2Yzhxpjl4ABmSGK3J7nAFFtYkMUMOhFx2drRfB2nuYtjm64KMiTbDRqH8LPfK0ma2TR8yY6lLiqctIhBbCWQ8rVIl9iwPHuK8g+oEo9/uNszLGjjrDMGHu4iDkm6AhEl7pcmjLYbY14kQBH8by X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2017 14:22:31.8552 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1244 Subject: [PATCH v6] 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: Thu, 06 Apr 2017 14:22:44 -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 | 59 +++++ .../Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm | 293 +++++++++++++++++++++ .../Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm | 282 ++++++++++++++++++++ 3 files changed, 634 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..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 + -- 2.7.4