From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.46]) by mx.groups.io with SMTP id smtpd.web11.58055.1595863630931071631 for ; Mon, 27 Jul 2020 08:27:11 -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=ZO6rhbDs; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.92.46, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LZLhamOdf2mMikqW1qhApUxV4PCfRTiWGSUePG63YUmIoePHALM9CqGPNONS73hQLcd9K4opIyWVBJE0WE3hBFIP0it7A1xIlsNLa2MJacxy8VAHtez4k8T4WChW8DxkDkwsp4hw3oie/aZM2VvBw3LPf/5y2H9g+DJUNfVZmp1V/DmpWn1lqeGCZiKL2W3EO83UVTuQldS2JZs0DDx6wcz5T7RFo5EegWbLvoprSZ7bQ+wZewRjpd/BAU2KEUPcOAnB6lKT+6EuJYbuZo1bIRG/XgHMh2g9t6E+nKWAbx3uw1Rbb7NgRUixpYg8GeDdEXpmtaLyXD8Lfipb+1QahA== 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=iew4PMVeW0MaIhXeGFQATcsDlTic15oSkh5/B0/sO1Hryrn0+BVlfH9B5seoAGdWZm5UAPbDMgv0M2I/l1ubnorKAu0h5t3uxbEhide8PE/lXKldf0Kd/k3qFio594NQxLzdouJpi2lZiwXWeg/fcrg3p15hMfdtnDXi406BtCDX0ABN+hU+ATaiZAsffFPhNaK9GMADd8igNllsXkbiDwWeSF6XzGEl5hFmq1qA0hhCl/ZHpdcmNi1byd7FSy5uS9zZBc0rPh5H9L0rn4yHjt50YvRsDQiikU9K1CDRI5awbdiUgW5rwzAGuzv/qJiBlzploINNRvKgZyL+0KS1yA== 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=ZO6rhbDsX82mwSp/iVSzPGuzyB0ABE2845DRjK+qkow0992W3h/bh1V6GMfRRAYiW1/2d9nFdmgNIQsiSiMhcSOy7Hbg94iQdY5dpxCq46zDxcmMUMzObbp1TezTwwN7MAO4kJ3ewnwTMi5menkhy2m3WFBEMWdqsGesVJ35Db8= 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 DM5PR12MB1641.namprd12.prod.outlook.com (2603:10b6:4:10::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Mon, 27 Jul 2020 15:27:09 +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.3216.031; Mon, 27 Jul 2020 15:27:09 +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 v12 04/46] MdePkg: Add a structure definition for the GHCB Date: Mon, 27 Jul 2020 10:25:45 -0500 Message-ID: <92473075ba8e28c21050f80577d70e761de74b40.1595863587.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN4PR0601CA0013.namprd06.prod.outlook.com (2603:10b6:803:2f::23) 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 SN4PR0601CA0013.namprd06.prod.outlook.com (2603:10b6:803:2f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:27:08 +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: 13ea6558-e9de-426c-a3b3-08d8324186d8 X-MS-TrafficTypeDiagnostic: DM5PR12MB1641: 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: Y0bdGdgYdV8AOrQeCuDlOduP4y9LOEO5j5DMhc/RHYjy8lHgcr/mRYj26Bb3pQEl7+/Tgzt0jKQ77vFZKFFMAqK99x2n6lIT/ZKqWfu/eQvZVPgOybgpeE1o0nBRvx2zSxgzfumksafJz2RtQT4ffbAxnicWPmBH3WcOlNf2/22VsGalXpPaL03PyI2JZHxjfQksfFJbHSs4bY3U8K2LK7G6Opu/lTnaGL55HRB/w7VUrACIYKCkdMfKFqjt7hAPIEBNTuaAhuzeY6ygStPA+8q0E1CH0EAi9MLGO4FomQ5WTEYSr3G4+5qZQW9P9MpHFiWeNHR3IQuXdBSs0Y7C02JX6aZaoAEiBjBiiDoYXktzzjN/lqULxci1mD4f07MM7TQ/77DCIcU/l9UbRIvX3IzdReKzBJ7cTc0JmJpQKNpMhFobHWaZzpc8jmpSERx9ZAdJxDjj7a6MolWC8Znjjw== 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)(136003)(376002)(366004)(39860400002)(396003)(346002)(2906002)(83380400001)(16526019)(2616005)(956004)(26005)(8936002)(186003)(8676002)(4326008)(52116002)(7696005)(5660300002)(66476007)(6486002)(66556008)(6666004)(478600001)(966005)(54906003)(6916009)(66946007)(36756003)(316002)(86362001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: LanmS4BR5ljoTFUsPAh9ZV6tI/suvBR317pTQRQQDXGmPmVWFKDvrBF7RtjDwKNZZjjdbZOVDnfSFsQkFikt66zPv9bbeAfDeOU3vaKjgTPfpca5k29d3ukwd29paSPlfBJ4d0JdAoxBU3mlV+yigu/z8s3tH2AYeHaXa7VGjlqjZKPQcmp9nm3v/uGlucQtiWYd3lx/s8W7kTgwcTZjYgbkAiJGhcLBXs+IHMd+e0J7RPFe2MCCUR1UVilu+HQBWc6lHzBoNdwuCcO7q6T9wzrrattJgJ9Ria9pTjSJzl9vaVZEZ4diwRAHo1dawyypcryj8w7i7Bj49Mz8v4hEe+iVvXRufrzi8/vstzMJARXLEdoVRCB/4KFXFoP6lkP2XUdHDUlE/h5cbsgBXJitNEAe1Iuv4EllLMbcN/NPORNA+PPUZgIQuop5nnLel9XFJHGsEppDRGFaE0SJp62X1qQzefPWuCa854G5wnbq9yI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13ea6558-e9de-426c-a3b3-08d8324186d8 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:27:09.0982 (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: lPPVAgQydVcIlsbHSHik/ttaOKqgwvy+He67lNiWn1tc61Hl+CNVllyTog1hXyWpRfmVJD6jyO8jNLMvcGyXLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1641 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