From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.40]) by mx.groups.io with SMTP id smtpd.web12.9705.1597325059201168820 for ; Thu, 13 Aug 2020 06:24:19 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=jqBqI8Pb; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.220.40, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b4v/Me57HDlOZduP7cKSgDRme7f4Usw/pqTDfWktLSo9HSeZZwTYaQTFnqfd7o2q5lJx4ytPoPffQf+6V0BZ8MOkqqZHS93PHcqRKbGy0OC1MHbChuN69wV3e7mcaBBhSncwhlFw2qSHJ6vGoDAmaeMWjuFlSoOQbsQrzinL/Fi4aJhPHsHZ5qAoxztmMM1A4MFj1UPCdc8VOiYkUEUusH7Z2leVmwCmD8loUz/pdRBRmiCKZEQI7cWKd4q25Nbqy0YAHWNn7mbyAdDgBobP/eYaQuPybCHE2Fc37tSLEZ9QUrsNGPaW9hZUWvy0nqUvyfTn9dvm4SS4MIbMKG1fHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VT1rPisC80mHx5Aymm6SdA0zAOXbubqUR6sDermqotw=; b=lncwwASTygkMDfPRWoCYTEE7YGWQJeF5D+5Pd6ZjT6YChJYPuQ7HjybK3ZMg0vxVqWqqSAAPMm9pl58xzpntlf6akjO0/iqO2pKdDuRbwlHPQq+gkLilAoduRSYw7sKc+6khHaFLQlzU/VtFvqgdF59gYBO/E2bgiy0kRqe1+qNlRv48sEG/AHYXV380rO1PatpR/wobdAR/tEq96E9MTbhlOBf5oLpmD3mvXm0Gy6kHoneji88pATsO2S+yOF1vLv0tPO+NTFtz289BzSQJ17dR200Y5CkhPzoYTgIHj0ekt6NtO3LFXf7ibyAyHsuWjwglMZ4u64wFFYYiJFBuEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VT1rPisC80mHx5Aymm6SdA0zAOXbubqUR6sDermqotw=; b=jqBqI8PbUQlWc14emoZg2tRAumALYHekYcNl9BPDD/g25wnrgZsulMEqU+Sm2GtWcZUoV67HIFrV0wC3ZY/Piw6Vi9TGwPmUObXd8AFoJaXiYFnUmzyexdg7VvN13l09yrJX1KlJyeGnb2czOVsgFoMhy6Nk6XtMAV9F6vglzUQ= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR1201MB0026.namprd12.prod.outlook.com (2603:10b6:4:52::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.20; Thu, 13 Aug 2020 13:24:17 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3261.025; Thu, 13 Aug 2020 13:24:17 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [PATCH v15 04/46] MdePkg: Add a structure definition for the GHCB Date: Thu, 13 Aug 2020 08:22:51 -0500 Message-ID: <4e65c0f7d9482f747070f129ac192e6b34b40ea2.1597325013.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR16CA0030.namprd16.prod.outlook.com (2603:10b6:4:15::16) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR16CA0030.namprd16.prod.outlook.com (2603:10b6:4:15::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.16 via Frontend Transport; Thu, 13 Aug 2020 13:24:16 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f339a3f9-a318-4903-95bf-08d83f8c2e15 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0026: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0Q6DwNpZZvRuI6oSEu9ixilEOQSIbe2V6gdOZOd7FmReggK6eXKLy6v5o8x7EqY6E2V/w6y4wTZCCVZZiuiACZCBuCgg/pjr7HX5eRgB8xOLdsycfl0AvlQzcWrerjXRoYjNBrfkAcj8fuGBqneiTQ4aBIB4AWhkpL8CDYl7819k1Mfjj3RXluQ/jL/VchMjPnGnufPNl9gQ2lTvNEtIrLzmai6paGU/g7QQV+wQvdw6/ol5obkGzxjBKbdbf5eUfDXO07VYdNIWamt8CqqM21mR1i3Mdodma6l552WS1sol6JpNmfsYjOk2Uh+4rWGArGGK8TYtaIW+d6TCDN6BwEoAH2XurTtzh4QJ/K9Vh8ggMjWwDknOKWcACePFPm4lfVi+9X8QEtMDxPFHOGok+LFzLQupWK8TKyh6i/DoHlfZKbqcrPkibAAAX3on5+i6UKfNfO2hdxCx6q+0QSq21A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(376002)(136003)(346002)(396003)(366004)(39860400002)(316002)(8936002)(5660300002)(83380400001)(54906003)(8676002)(6486002)(2906002)(6666004)(6916009)(956004)(2616005)(4326008)(66476007)(26005)(52116002)(7696005)(66556008)(16526019)(36756003)(966005)(478600001)(66946007)(86362001)(186003)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: PYfUE5DlYwhBF/gLA3VUh+NMItMJOErhGrT424kz7Sb/FAdbGuhE1+lp8b0eJmFFz/6zABwPfa8gx1trGF1Mqkkec1rXQIjVbLIZecomegk1IgBKomnntvwEIuutodtBRasTMAeg1t6hsDAbLqSSu7Ubk2IsRQd0aC+F1cQa+hR81lB57ruh4ih5/9hmr8jpZE796QGlgG/smzX9JsddqDnmJGeOTj5VMLHM9dJtVWxJlAxYV/4hwKvl+YQCGO3GYbq2CaG/C7bgcbdIKvbAMUp0j+jdOI4AZKLAJB07BCUHdb6GalZsCEy8hocsJkLvso4u0fZlUs7IdNz+nRdpLrPq3V6O0jqzu9PwPS/q89ygOXVDaKRlBDsyFC5yTYSNCauWo4LzGB64LO3MWkSwZPhFBQ/wi3qK2JDokjXiSY6DD7divD4vmRqNXvc0OOpybkUeOjH93b/D8c1X9w+Sc5OEIfOQevB2vjkZz9vwqGduYteLmOCOqBq0fVAQwO+/Axh8QC7ccLMjQHaHCYA2LnXSGIqA6GGRmzwafz/O9UwE3MXD5YCNFsfDKf2Ep3NUTVnj6C4NjUbHzI5UWZSmBlMpdLdV5BaT/U0tHcA0jp4+T+tTAE1qGOZd/Ud/XR0fDNGnwJBphp+JZXcPbhsRJw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f339a3f9-a318-4903-95bf-08d83f8c2e15 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2020 13:24:17.6222 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: u5NF43AygjF7Tgkchp0WwhwrE/wOrMZAVUjpPnqmCrvmXmfjQotiUq9Y2hrn0UfpJPN+RwaG09jUfo8G3d/1XA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0026 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 The GHCB is used by an SEV-ES guest for communicating between the guest and the hypervisor. Create the GHCB definition as defined by the GHCB protocol definition. Cc: Michael D Kinney Cc: Liming Gao Reviewed-by: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Include/Register/Amd/Ghcb.h | 166 ++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/MdePkg/Include/Register/Amd/Ghcb.h b/MdePkg/Include/Register/A= md/Ghcb.h new file mode 100644 index 000000000000..54a80da0f6d7 --- /dev/null +++ b/MdePkg/Include/Register/Amd/Ghcb.h @@ -0,0 +1,166 @@ +/** @file + Guest-Hypervisor Communication Block (GHCB) Definition. + + Provides data types allowing an SEV-ES guest to interact with the hyperv= isor + using the GHCB protocol. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Specification Reference: + SEV-ES Guest-Hypervisor Communication Block Standardization + +**/ + +#ifndef __GHCB_H__ +#define __GHCB_H__ + +#include +#include +#include + +#define UD_EXCEPTION 6 +#define GP_EXCEPTION 13 +#define VC_EXCEPTION 29 + +#define GHCB_VERSION_MIN 1 +#define GHCB_VERSION_MAX 1 + +#define GHCB_STANDARD_USAGE 0 + +// +// SVM Exit Codes +// +#define SVM_EXIT_DR7_READ 0x27ULL +#define SVM_EXIT_DR7_WRITE 0x37ULL +#define SVM_EXIT_RDTSC 0x6EULL +#define SVM_EXIT_RDPMC 0x6FULL +#define SVM_EXIT_CPUID 0x72ULL +#define SVM_EXIT_INVD 0x76ULL +#define SVM_EXIT_IOIO_PROT 0x7BULL +#define SVM_EXIT_MSR 0x7CULL +#define SVM_EXIT_VMMCALL 0x81ULL +#define SVM_EXIT_RDTSCP 0x87ULL +#define SVM_EXIT_WBINVD 0x89ULL +#define SVM_EXIT_MONITOR 0x8AULL +#define SVM_EXIT_MWAIT 0x8BULL +#define SVM_EXIT_NPF 0x400ULL + +// +// VMG Special Exit Codes +// +#define SVM_EXIT_MMIO_READ 0x80000001ULL +#define SVM_EXIT_MMIO_WRITE 0x80000002ULL +#define SVM_EXIT_NMI_COMPLETE 0x80000003ULL +#define SVM_EXIT_AP_RESET_HOLD 0x80000004ULL +#define SVM_EXIT_AP_JUMP_TABLE 0x80000005ULL +#define SVM_EXIT_UNSUPPORTED 0x8000FFFFULL + +// +// IOIO Exit Information +// +#define IOIO_TYPE_STR BIT2 +#define IOIO_TYPE_IN 1 +#define IOIO_TYPE_INS (IOIO_TYPE_IN | IOIO_TYPE_STR) +#define IOIO_TYPE_OUT 0 +#define IOIO_TYPE_OUTS (IOIO_TYPE_OUT | IOIO_TYPE_STR) + +#define IOIO_REP BIT3 + +#define IOIO_ADDR_64 BIT9 +#define IOIO_ADDR_32 BIT8 +#define IOIO_ADDR_16 BIT7 + +#define IOIO_DATA_32 BIT6 +#define IOIO_DATA_16 BIT5 +#define IOIO_DATA_8 BIT4 +#define IOIO_DATA_MASK (BIT6 | BIT5 | BIT4) +#define IOIO_DATA_OFFSET 4 +#define IOIO_DATA_BYTES(x) (((x) & IOIO_DATA_MASK) >> IOIO_DATA_OFFSET) + +#define IOIO_SEG_ES 0 +#define IOIO_SEG_DS (BIT11 | BIT10) + + +typedef enum { + GhcbCpl =3D 25, + GhcbRflags =3D 46, + GhcbRip, + GhcbRsp =3D 59, + GhcbRax =3D 63, + GhcbRcx =3D 97, + GhcbRdx, + GhcbRbx, + GhcbRbp =3D 101, + GhcbRsi, + GhcbRdi, + GhcbR8, + GhcbR9, + GhcbR10, + GhcbR11, + GhcbR12, + GhcbR13, + GhcbR14, + GhcbR15, + GhcbXCr0 =3D 125, +} GHCB_REGISTER; + +typedef PACKED struct { + UINT8 Reserved1[203]; + UINT8 Cpl; + UINT8 Reserved2[148]; + UINT64 Dr7; + UINT8 Reserved3[144]; + UINT64 Rax; + UINT8 Reserved4[264]; + UINT64 Rcx; + UINT64 Rdx; + UINT64 Rbx; + UINT8 Reserved5[112]; + UINT64 SwExitCode; + UINT64 SwExitInfo1; + UINT64 SwExitInfo2; + UINT64 SwScratch; + UINT8 Reserved6[56]; + UINT64 XCr0; + UINT8 ValidBitmap[16]; + UINT64 X87StateGpa; + UINT8 Reserved7[1016]; +} GHCB_SAVE_AREA; + +typedef PACKED struct { + GHCB_SAVE_AREA SaveArea; + UINT8 SharedBuffer[2032]; + UINT8 Reserved1[10]; + UINT16 ProtocolVersion; + UINT32 GhcbUsage; +} GHCB; + +typedef union { + struct { + UINT32 Lower32Bits; + UINT32 Upper32Bits; + } Elements; + + UINT64 Uint64; +} GHCB_EXIT_INFO; + +typedef union { + struct { + UINT32 Vector:8; + UINT32 Type:3; + UINT32 ErrorCodeValid:1; + UINT32 Rsvd:19; + UINT32 Valid:1; + UINT32 ErrorCode; + } Elements; + + UINT64 Uint64; +} GHCB_EVENT_INJECTION; + +#define GHCB_EVENT_INJECTION_TYPE_INT 0 +#define GHCB_EVENT_INJECTION_TYPE_NMI 2 +#define GHCB_EVENT_INJECTION_TYPE_EXCEPTION 3 +#define GHCB_EVENT_INJECTION_TYPE_SOFT_INT 4 + +#endif --=20 2.28.0