From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.89]) by mx.groups.io with SMTP id smtpd.web11.1746.1596134695473364706 for ; Thu, 30 Jul 2020 11:44:55 -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=JQ1x2RAk; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.236.89, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h2QUAvLCvzdcuP70OpdJURneTrmjGe67owOq6C4c6v2IRmVCTCyTfMJsjBSwWEf1tVcyX2o9mkPZE/H3PHyiPYc0qqQlFhs/IJvy3B00g31uoRITgtk4mLV+wS3b3q1VC2ebkca7Tv8uChSuyGTg/WmHXrDBTNn0YlOe13ZXC2bMA4haLZF6VG1ctlKtuOO8ZP+fCssPNLt+J26TnHYNkJTItsEkAzVc6znrfrVZZ6pHzZKzYWbz2Er8joOthj8K2/yYpHe++jziC8qELFiLxRWTHPkOxIojLJultk31Sh2PtfMmIJdqgGtHm+hbh4ELL2Og1DeVwZ0rZBQGED8Rqg== 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=V5LkREfg+5IrgurId/tA6M1V5UREbXv/xVwYHjnhOWUwkyebnc0sCIkT/Eg392sw7mWAMV9mwz/dw4us7yltC3aXUtrK2+cCAVozrJnyi2HOnw6Cyf9AImDEiyDE9DoapgJRFETksVovc/q+aecSypS9SHBLCp7887wgRjrvkJ2s5FjqhEDpyDJi3ab/Dm3X1tPIrdGxJAWV7sJSH0qXUzTrSTxrXUNpN333PmmZ8hcCB0EOSLVv0sjq6xX4I+oItdK8DmfR2XU7//AxcQHhGZ0BnKXk3hYrqOr4/k3EqW+xoor3JogmJYvKND//tJVo/NAAmpam9EvEJR21qugFRw== 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=JQ1x2RAkXxUWbHGWPaxcSAQNLU21jsqcSZGT+ODRkWEytmuo8cfvQn1F9ik2UyZOdGL9FxyZhwcMW9+1M3FBk7k4/h0S0N+l++uvu/xDtHb+DUej5MJ2QG1onqwl5Zi58857hby7p6PlB1fi7Rpo1t6nrm8m43ws711P0KOY4p4= 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:44:52 +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.3239.020; Thu, 30 Jul 2020 18:44:52 +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 v13 04/46] MdePkg: Add a structure definition for the GHCB Date: Thu, 30 Jul 2020 13:43:16 -0500 Message-ID: <1868f4d686ffaf8edf633d5902c050f50e714153.1596134638.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0038.namprd05.prod.outlook.com (2603:10b6:803:41::15) 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 SN4PR0501CA0038.namprd05.prod.outlook.com (2603:10b6:803:41::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.9 via Frontend Transport; Thu, 30 Jul 2020 18:44:51 +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: a7602788-0d47-4423-89fa-08d834b8a529 X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: BUoJqhIY6hdfmm840wQpdQfRCWT8y0NiImQ4GU+Dn+vlGgsCWZQXuFDuxtO0+6MSZoMxVeMK7vnBevMNFEWvpQPupvqgUJ1NIUVt+6rFdyolF2w7HZwEWDbmw3QfA58hJzQ65KaltqQZU/C7a2KDC9XhDJcEJdjk7o3/DkXi4q4a8VtmzhxJ+WYwslh3sKRhjgOCyVyIB2yt/kdkpT1dBk5n3HcrcwAas/I1SFvp/EKO8ZSLaz3jFTq+4JBQkIJljKsOrJvIM7GGJfSLcid9eeOwsXWFipN6MSzRMw+TFCDwdswHt3bVNQJodxLI9c9P7ZN09mrzPGBDgYyzVZAGZMryswR1PXrZMeIRWkXfkaVvwPe2kb360IqmFjvdp6LrUWYHUkh0yupXBpka5Dm5NzcekVTl2TjnDWpKfnCT8C9J1ZAeHShdW+Ol1Lu6k9TjrxIsYBd1OvEafD59cGE24Q== 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)(366004)(346002)(376002)(136003)(396003)(39860400002)(2616005)(5660300002)(36756003)(966005)(316002)(52116002)(6916009)(6486002)(86362001)(7696005)(956004)(83380400001)(54906003)(8936002)(6666004)(2906002)(186003)(16526019)(8676002)(66946007)(26005)(66556008)(66476007)(478600001)(4326008)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: +eoE+OdU2JWH+0vgMGcWrHbyAXqzcuZexnLbIW5CP987OXt+evG4upub/kzdMTv+u3REX9C9qZvscZ1ntwUM6LwHGDg4js5XZbjBluPDMuqEHTbkMl6CP0mSEw2Nl8NWjyfc1w1hHr5Tr/GtgphEJOxoOt+spZzEjplDDVANT5qwgvSMoHSHz9Yf3r+aYVHAkmfGLhmnWGpuCPteW7MnnoghxF3mDtA79nwehfTkSslhemS1bHYGWGsOJG8N8r7HNneWjAVXwXdQ4AtjWXKwtDoA8wLy3D7Rg6GT9ZcG/g8b69woQlvPFUIkCFmAjLdiVOhJUXSnqAjeSWRXX5iqinoEbqxm0O5OsR7fDLkPiANjt5GdCvtNkZeAkkKyF+vTO8ZCa+kF+YVLMSGZ67oQHjgyEfIYgcd9xQtcagYEItZJbvAOeB2DVQBnpNRE1j7zSOG+QlYzhCw9IDjWxUYb8E8euI6/+IL8+xk4XagWW4Y= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a7602788-0d47-4423-89fa-08d834b8a529 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:44:52.6363 (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: WPQQJSNOt2S4rDwava4r555pBKgoLqG+Q+PK2irdjrEedzzKPWjKd6HWTbNU1hNGPeEQiG0WejiRl8Pikklypw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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