From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0607.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe4a::607]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 146FB20080923 for ; Wed, 5 Apr 2017 06:20:14 -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=yOJglyZ8nAFIiQDCek6WKtzIbINEork2a1llzZNnA4w=; b=BjHPsLBL7RCxXZN441pHZXunhwQ3aqYgGZqbC8CdpEziLKLt+ACPCYdiZ64E947E38L43DLydQCAfvitW4AHp2LtcVohJcmNrG206Ht4aX9Hue3PnECpw1OnheSgPYGuBZBGTTa6PQEAdCul89uLQC3XZ2zPOX3mecPKuG7Chw8= 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 MWHPR12MB1246.namprd12.prod.outlook.com (10.169.204.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1019.17; Wed, 5 Apr 2017 13:20:12 +0000 From: Leo Duran To: CC: Leo Duran , Michael D Kinney , Liming Gao , Brijesh Singh Date: Wed, 5 Apr 2017 08:19:57 -0500 Message-ID: <1491398397-21176-2-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491398397-21176-1-git-send-email-leo.duran@amd.com> References: <1491398397-21176-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CY4PR19CA0047.namprd19.prod.outlook.com (10.172.173.161) To MWHPR12MB1246.namprd12.prod.outlook.com (10.169.204.150) X-MS-Office365-Filtering-Correlation-Id: 8a248128-ec70-4f51-104e-08d47c267ddc X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:MWHPR12MB1246; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1246; 3:Ga6oUxnupSoP8TbhtnZPHIPBZg7D74aXDEY7XFI6LxICqLGHRJHemJx5aU4c7ZfaJ2oE68ntCo/VxVjRG43kbTmcmJHIZigQ3YYBq5VKnxqNb7mi+a5j0HOUa0EpNmrWLIoL21mwtCgexNKTSLLGPElgjVzlCasFfMzk3gdasz/q1xqvJy7fl6nysMND4jDgBvNbf3ENhxIAcEQ8YqXd/4zsKR02UBLg4Ra2YXl4bCljpiE78vcitRykKoueYNcDIVBJORndUfqxaIwx6LbqDVqjzejnxH3T9X8DmjDmn+uzR3CzBV1SYQq6AoXg6Kdq+waCkWBvzFGKG61F8N0wkTLNuewgo3LcZr6AZ3kITyc=; 25:Q3/xM/4xzhhhn2Prp5vxm2HzPty80G0k9hUYunl+urevDN9N5CIEr5EYfsq5SF3RPqdTw1UdDUYbgPeoUIA9+SJoEW6LcnaOE+/twA7j0ouhk0y38rMb2Q0bSDoKXbET2AuXYy9W5Xy2xCjH5iVda/fEibhUaZlSECjyHM6H4lc4tLFjVVxld1I1kRj05rCJocnx+xudxpu1L2PpaTNlWzxxYb9GDkt5p95ZzETQKcZ9Dh/49sRZmkwgMwTH6+bnjtUE/bFZ0tviNknqA6r37LSBiaRdRy9qAQaGQtqo08JEKsybtjsQZS3HBSOgMY4xMOTcoITGt5SWsiaA7GxrJ4XV5L2/ou7SPLecg6NKjuFgt3AH2vDMISbTHh6c+qM8NJH50ggbRiKH7WL/SsW3JdNTeosSmw3Qxrmn50qWPkwNK0hhc+/PuukEf9wIshV3SyqsTxge2dkPfik9+1mbbQ== X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1246; 31:uVR0abKkUldmAh9dRQywTIobrsnBbrAh1llEGDSYdQLKVrUFbbHynKXPGp7XJdxQIzGWruCq8siWvu1QjiQ4Rofd1nDs4lWNk0wzRuxrqz5QVwFnQYnPtM/GI1196H9xZhFWN3CQm4p+7toUXs0gavR3EPeK0gYlbGuYqrLG6eqKbJcfK3bS8+6UGAuu05Jf3e/l5CQb7HnvB/0682SwAeQdHQTbjZR0P7MSZud0smE=; 20:u/XcbWUMA7khMRwYCZOHajeSZGJ41Ls1cqmh777So4lZTIoWa8/lrclJ1x8zqkP4QI0lBvEnc2A6eYYXmYPyZED460lHIsd2Xe6N2Tp8UuvyszHTutJnL86PbPr6lXH9S4c4J/URZA75WTMgCYaaVw2ka1aMaFp7PhwE87ZF4NjyqV2/dc7x/qPBtElc3ofAlLc1mIpftnDERx6Gw9/k0425/tD5hOvo0Ee0JcdjdsbCEXPgoFfyBDhraJy2aanE00vW2hx6Aj1oZvdcswpV+lxAmpR7mIoFPYjZHhpODj5umWqBfyob9lmShz54rL+h9ndALhT+lwvCvD3LguU3f0oTjRpfozO4lvag6DMOm/vrnflOxzX40s6mCr40Yc0ec17L9G394KAySXD/d3uyWCDH1k9Pp6gV1ZYg9+RUDBxvS+51gDLNkV78PB457N8DDnXwwTyHcHtmndZyZJVQ/RPtEjzckzEM9l7bH72Ff2YZ1pzD4Av3fNrYOdWOV5go 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)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123562025)(20161123555025)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(6072148); SRVR:MWHPR12MB1246; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1246; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1246; 4:O2XOiCjd3atJy96DhNmneI+CGUfN4rhFLbRDp7jJe824t7lvH048lai/C8zWe6YqFQZ9pBhghCzRFZgYlZFqi38WTFY3O6XtQKXdGsT3cfgQn8IJrQKwo6M54AX7k/zxtQpCFVjb1xt0gLw2rlF0HBuCA9YTFkofZ2+FrlTJxHeKplcz0XhWO3hZ6A27Xtpyof7jBZfCHOdIEDG0x4ojz0xdo/P2MNyfc7+fvBEotafOJVFlfyNWwtPRJlbOkAkZ/L4MWEhjmaYjyDCgKB7r3dW05apHOwxnC5sxeqAxQM8AkSN4HWAaML2XeEVy+XCDZ2pYZQnist/1EyqbT4AUNf9uU605nb7j64E/vp8Bo1aYNzl3z3YpJOuBN1XZFuvWkWTbZxFDB9dFIAYwTey6YFW+40LPQqAUR62HAmilohqvpQV0ifYQq1G0gG8VJOlPtsrfh2M3qIArprqCob3zPKSZwaOCtIE4wcl3iovEM68tAJ1x9D0fHHVnPO+PlnRszH2Xp+5aTvLsNfetjtT5RC92dzPHNMFnY1OgFdEGRgF+hRNszqhSNfOp+2mULWf60JmsBOATCDRhAz3p24+kmR/XWcytFg2OXIOqb1Mk+itDII1ZPfQ4cehQhWXHP8l2NVXSNMNBH+XuoRh80+GC/gh/THuiGszvGq2tSkSxIulEAGFvQg3DskhQqW6KVMi1O1ezfzDOYXmIfi9c8/QIXOTdMb4WDTI/WO9zbn9/ZZMrL4QZHjYB6HEWZON5kfx73qre9tsJnbEVibbiS/RIz/SB/sfFsekA+6u3TcrZLfx2WZXehaclPueMuYDUcaxL X-Forefront-PRVS: 0268246AE7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6029001)(6009001)(39410400002)(39450400003)(39840400002)(39850400002)(39860400002)(39400400002)(53416004)(7736002)(42186005)(36756003)(38730400002)(53376002)(8676002)(110136004)(81166006)(48376002)(6486002)(50466002)(4326008)(53936002)(966004)(50226002)(25786009)(86362001)(33646002)(47776003)(66066001)(54906002)(2351001)(6306002)(3846002)(6116002)(5003940100001)(6916009)(305945005)(189998001)(50986999)(2950100002)(76176999)(6666003)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1246; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR12MB1246; 23:XsLqvCLzsbIDk/MEk4WBa02UD+NaXH1j39eqB4EzL?= =?us-ascii?Q?MLbOSjpSO/G2nFoulZvagM6U4w8TItNVjx67Uje5z1MEpnBgE7f5kDHXr0qc?= =?us-ascii?Q?PYlRLvP6ox657uf0HR0oM8jdW/+5v9cBBeo0Zma6WzfIJDO2m8G5Kf8yFTTS?= =?us-ascii?Q?mouzy9CU411+OFMySPKfGxKtxu/6TKw7a8NMl8H3oE258LlXcP1CQgD8wjFl?= =?us-ascii?Q?76rMKa/K5k6J0pglonI48C+RvCXXGVhAOVzQqAVNaic5lO4TGSyvrXq/CZsW?= =?us-ascii?Q?oXecZg68QM/G2tRzSeGbpbQa9eWNX/6dxZAcTbhDQ0MD1ivj6OfvsQPQU3vN?= =?us-ascii?Q?KULNjoMWeUAUDiCJRUp8KnXIrsMdzpmvCxJCKaW5aiTFBWQoqya5dVRw6jzQ?= =?us-ascii?Q?RwYINHufYhmiPSOcbluBW1cNEzNHrsQZh5xXHl1aVHjCLDnUh30SXDaTk2MX?= =?us-ascii?Q?t4v1kGgtvaBUHkhvtRiPMjhCaCw9bz5WTLu8zc9WhQ0mfCUvd6TcM8AuxkOz?= =?us-ascii?Q?BATRx1zDWFRnc+1Rbk7+ZnwUlZXNbR6JDJSDoQwd/QsEuQ4B0jF5M8MEEqgG?= =?us-ascii?Q?x8YJC56Z4owLOu33okl2sQtXA+MaORE7esgr8IUGyV00X6lmB4APLH8GiEjz?= =?us-ascii?Q?B0Q+g/KdC2SK7LwyPKXdIPlWHopud0hwggnx1nW8paO995n9lqLbfIxc1DXl?= =?us-ascii?Q?fUyPrH8Pnoj5MgdNax9n+s1c/Y/DzYotWkGdHqpJmll5I6I9u6+HEGA2l/vw?= =?us-ascii?Q?zIQ/KewCi63dq6tRMm6jUIZ8cC2vcV3hvn7t6C1GMsmNYD7VwVwa+hEL4vcb?= =?us-ascii?Q?EoolSfMMTEqfSwdgAzG2iRrEToEunfwJsYNzGNlxtBtVQZpLgT9XZsIiukUy?= =?us-ascii?Q?Hahjt3XCynd8nHnkpaKuG9B0cPlbBUH9Asj9fNy62gqRz0bapojzLnjZPsCc?= =?us-ascii?Q?DTM7p+F4erfIPO9beHOXpJ6nnH9ZoDQzxGoSr5SIRuPSW+LJimBe0ZM6SOkl?= =?us-ascii?Q?Dyle1RCDyIIWCnbpvx23u+fJ3bJFunBrhZLQB5Zy4tIw0A1TbOMnIy11xLVI?= =?us-ascii?Q?/lTOFm1IOT2LHCrGgvSOZK1NQ+cfJERqEPx9rRerrmaJBSD7q/NOveQnzTCG?= =?us-ascii?Q?8wLoWe5IRo=3D?= X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1246; 6:0284X86TKJzit9LD5H7LZ54CP8N03yW4iBHe6dFP2S41Vv6OLPUI518c7TxdsN+/2duSOaDYPQqu8YhKdGRBL5I8/tlXzMibataBKYPB/kwPm0AjYW1z2Qmu0CAXO3Pt7eUKmc3zp4c4ssM6m9HB8i3mtnMregz6tv7mEF6uxiST3kDcyjgmb/yWEAQmeal9gbcbnYmpC6wr1ciTJ99PC7QsAAYAKiScZ1ZspuJ+5dXsRj6QdRfzKloZ+g1DS0b2qzA0sjgfnKWE55NOk4ZRg7wSrppNFZSgHOzuBo7PbTk8QlzQYhWykDaZNyomLPhBj51NnqyvQlHCUmlyLvCNLvBeuglC+Qbr4JbV704n069fTXHO+VAsK3ewElmElUWcdHS1VjCvjHSzs6/b3PYi3GLFX9osvHG1TcW9zuKc7AA=; 5:uAsMQ6ROcv+p4pPYHaMM1DC15JzSDBFgpzTFRannMkN7ZMC5vl9F0tLq5eWpqPmgsHqnnAxqVB8VquFDvuk00c5190DFAzkw9AqEdFg1i3ka5iz3ca9MciBZMeDYBGSsPAkSuf5dgn2AVD8TURikaw==; 24:Ie1ebr7EvpHoTcUvh+YLqpyVyX2qL0Qx4hwV0arCK4C8wsqaIHHcEWP096Eakl1x0/zYK6xgFZZW7ROOeKVkySiFlTSLVs48FvQdxm2m9e0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1246; 7:7KG3BDHrULTHb3IQNkTbqMERk5fNIK9FAdCOMoM9uit6J9IDAFHpF2lXasD9Uc9ejyHGOVJSTDeTmKTN2qGcmSA3BsFBQEEQH7FSkmeDRyb93KrwnzOfHa073vuYON3adq3QBT1xveblJaqMxCJjP9WDccZd2YxcVxVJWwf+LeweIazrlvuZNbjXURNAcSWjNoO0noY0BGwDEaY8f0EsN2leMeRfwPXe2Hm9G3InNWsUILH8DtmaJS3cqxOHHJIJYGzizwzFtoDDiwMXMhQD52HQ9CJBOO/iG9wPdWTnJXgU0FHkVoQDQxZVZYZS0yNyZ6pUoFnuXcaH2qqL5n0dlQ==; 20:kFV1ZGU4YDpKheEw2MQPRfb7aw36MB+Cr/dQ+Cb2bZlaJ8ZNvOD3BndM4teEw5CEpsv4YP4tntzUscC+QM0IN0fQim94imktnK0YBkr9P9tTHBLG6bYiDQQPYoxN2wMjBbHbFu1kEXcLleUyap1WwY0L7R7r7TfoThN9YnvPqbr2tnVPj0MJx1hITKOV5QJoklE69HaSwY5myzA1IWa2LOyAj2X0VgAIRN1gOJG4qhXEkW5eoVnpN8QDZMqHBCOl X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2017 13:20:12.4705 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1246 Subject: [PATCH v5] 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:20:14 -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 --- .../Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm | 293 +++++++++++++++++++++ .../Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm | 282 ++++++++++++++++++++ MdePkg/MdePkg.dsc | 2 + 3 files changed, 577 insertions(+) create mode 100644 MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm create mode 100644 MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm 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