From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.72]) by mx.groups.io with SMTP id smtpd.web11.4201.1596829216664183947 for ; Fri, 07 Aug 2020 12:40:16 -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=s11Z/F39; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.93.72, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GuQDytbLwFwJcHth3wuvrkHglfGy4yJxtpG/iXAjldTkB60u93a3Eh7YPzPipeh5ZmApEac4TS5twf581N0uxQDl5LrSvuRZ46yB8MCwYzGmMymAQOblzAe8gWFTfcYJYaHDYMaoP/lLRCTxCMNPWwvFHdpxUhvbVHdCSu4jBkBFSroDF1SJSVtNrshmLHWy8cEkfjUNFStUhr1m/5403gDFju3y+IWvLJLLxxHYr4iGObUmdFHfZr8bKQCQLb9SXoj4dQ+ImxStH7nGaMaljA/7iNGjqj3rA9oSe3JSw2EQaClk6K/u2+ise0UATHsK0OYxMyYzgmsiATT8NjhUww== 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=YYkVB64VTGSzUnAsN8IQEH1S+2akt7TobPcbdBPWZn8=; b=IK1T4VIz/+nGftHbRKMRyYoL2Or8ONgL6MTtBzjmUpTNZfKXik0bL9/CMO2HVb2MeA571AEYlCVrnw70bxQJbjyAod6FCsFv6mLkAy9Wh5DVIZ6V15Uw0kPA+bVLD5zxx9nKP/OAVOSClKZhR+E35NjMa4EYEAiItMq3wboTpN4emfsYaEXKyque3idL/gEjM/4xHmjBoo7/Xmj7FKfPzSkJYPpGhlY7YwW5oFQqhN/C8bGKisC7VyeQ6KxHBTAaD0ctG8G3OMlwlrQwE9STA7UOYU4TOX1hykwe8RXjBANZXRbBx61o5a3i43GPzmPPGr2iaIky73PvWyRayRXoMA== 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=YYkVB64VTGSzUnAsN8IQEH1S+2akt7TobPcbdBPWZn8=; b=s11Z/F39LikuOo0XNLdRZ8/6XV6u8kSwP65FYXl2ZTOKlwl0cMcQulYen9GByOqHAQjp25be06rN2QCVGbBNU1VimFIjVJ2+Yssjw7n0cwwbH2XQBa6T6c4613O0oaRqZ+AgwZr8tPX4DU6SZGyFNKiB5OmWBOk7z+ejzN3cdP0= 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 CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:40:15 +0000 Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:40:15 +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 v14 04/46] MdePkg: Add a structure definition for the GHCB Date: Fri, 7 Aug 2020 14:38:49 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0067.namprd02.prod.outlook.com (2603:10b6:803:20::29) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) 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 SN4PR0201CA0067.namprd02.prod.outlook.com (2603:10b6:803:20::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:40:14 +0000 X-Mailer: git-send-email 2.27.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e3a19cb0-7a31-4fdf-bcc0-08d83b09b4f5 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: MSyTf65YVVu5OKaRjsEFSLB4IZ3/ESuPn/DdWfzeKLhM6nfxZB3oL6kWYBJQR9r1TH2ZNJOWOiFE5AIBtOCfPS1bLyAe6pWTqZJQWNz6Gl+wj2DXoaFlroZ1tyxrpAFcinvSNWiTXG13PSkdIRFg3xXLdywz3Zjl1BJoF1xZ9U9CUOJmrBpKoDrwDV5aaDB4vxieLUi06NZyQUJSFLiQHRzFmHSqpAGxnICVayCSQ3pk5obnqg8b8t2sqJGXAYmdu7IsNrVmaLOhhEFbyjyRrRggqGN4JXPwjB2qlRla7U8um1ui+brhXqYqrihFXcM6Gj834dgomQSKnSNpsE6tm5Yxoda4lGF/LgwAd3+vAGe4JBamez8DuTaawNqMfbKGhzzqhYRkTnNrqwlmvs9kyLGxn1mubhJAMbbpZQS2FD7YsTEjwktO4xMiFw7OwosaxpLbN3ZdlHN2hdtKV8Caaw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(396003)(136003)(39860400002)(346002)(366004)(376002)(52116002)(7696005)(6486002)(8676002)(83380400001)(186003)(2616005)(16526019)(26005)(36756003)(2906002)(8936002)(956004)(6916009)(4326008)(86362001)(6666004)(54906003)(478600001)(5660300002)(316002)(966005)(66556008)(66476007)(66946007)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: juW+f21rLI6x7QJTpRyeVj0wIllp6gAd+5LaVtmUnhMnIOK3uSyfSCZHBYrpvf7FkoNGnxNLWuLAB2ALcEeFYfOebOtE0JLhoZuF9bEcibsM3xiPkBnygFNbBtqhsMfqYkZ0947eXpaShy6QFtbYbV2OnuVLGyO5+ysIfw9KXYnjaQ7+LobITFqp2UswCAw3npY5D1GfqnEJpDF4oLIQ4uwAKIYi6JRx2Yn/8FWlhlU7pMiZyOvDzxHGIj1cSN3pzX5kqNg7nV+5ExhakI9nUIsP0dkzd8LMf4bfND7R/SLa1FI9WVlXLVwRJHfP8emnc6Y7tk8McMQu1rj76giONaAs2gBZBda53TDCHB1iaB+f1aS/ICR/wwYNUgwkVScAZXwibyRGYESrcXOcCCzdGrxTMaRAf1ZPHNsIthzsX2gBwMCQ34KGN27aFJqtWYsilvqxfzgTE7VaLNnynI8CcFpZwbIZX0YiGa+8UCzi0Edtmfe11h6rYTKxwEHoSANceiH+n5WAL47FGO9CZxq9z7OUY0pvmnRwtadpnZbINp/2AlnP04VPT0spoYDv5YdMuGFfUSYwG4jMwUzBsjEzV8xQpDn6nSt1i07UcTJ3F+twtaDTLJz4pp178YS7hKRWMxGIXqqQz/WvfFs1xIelYw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3a19cb0-7a31-4fdf-bcc0-08d83b09b4f5 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:40:15.1222 (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: HxoDi7g/glLwiih64fuZIQsZmY4S05w+yQEqRB5q7eKxEDfISl4CPp8AR4cH8f8SJTR+S8fSW8J9Qe1PLuTBvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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(+) create mode 100644 MdePkg/Include/Register/Amd/Ghcb.h 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.27.0