]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Register/Amd/Ghcb.h
MdePkg: Add a structure definition for the GHCB
[mirror_edk2.git] / MdePkg / Include / Register / Amd / Ghcb.h
CommitLineData
1c0eb915
TL
1/** @file\r
2 Guest-Hypervisor Communication Block (GHCB) Definition.\r
3\r
4 Provides data types allowing an SEV-ES guest to interact with the hypervisor\r
5 using the GHCB protocol.\r
6\r
7 Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>\r
8 SPDX-License-Identifier: BSD-2-Clause-Patent\r
9\r
10 @par Specification Reference:\r
11 SEV-ES Guest-Hypervisor Communication Block Standardization\r
12\r
13**/\r
14\r
15#ifndef __GHCB_H__\r
16#define __GHCB_H__\r
17\r
18#include <Base.h>\r
19#include <Library/BaseLib.h>\r
20#include <Library/DebugLib.h>\r
21\r
22#define UD_EXCEPTION 6\r
23#define GP_EXCEPTION 13\r
24#define VC_EXCEPTION 29\r
25\r
26#define GHCB_VERSION_MIN 1\r
27#define GHCB_VERSION_MAX 1\r
28\r
29#define GHCB_STANDARD_USAGE 0\r
30\r
31//\r
32// SVM Exit Codes\r
33//\r
34#define SVM_EXIT_DR7_READ 0x27ULL\r
35#define SVM_EXIT_DR7_WRITE 0x37ULL\r
36#define SVM_EXIT_RDTSC 0x6EULL\r
37#define SVM_EXIT_RDPMC 0x6FULL\r
38#define SVM_EXIT_CPUID 0x72ULL\r
39#define SVM_EXIT_INVD 0x76ULL\r
40#define SVM_EXIT_IOIO_PROT 0x7BULL\r
41#define SVM_EXIT_MSR 0x7CULL\r
42#define SVM_EXIT_VMMCALL 0x81ULL\r
43#define SVM_EXIT_RDTSCP 0x87ULL\r
44#define SVM_EXIT_WBINVD 0x89ULL\r
45#define SVM_EXIT_MONITOR 0x8AULL\r
46#define SVM_EXIT_MWAIT 0x8BULL\r
47#define SVM_EXIT_NPF 0x400ULL\r
48\r
49//\r
50// VMG Special Exit Codes\r
51//\r
52#define SVM_EXIT_MMIO_READ 0x80000001ULL\r
53#define SVM_EXIT_MMIO_WRITE 0x80000002ULL\r
54#define SVM_EXIT_NMI_COMPLETE 0x80000003ULL\r
55#define SVM_EXIT_AP_RESET_HOLD 0x80000004ULL\r
56#define SVM_EXIT_AP_JUMP_TABLE 0x80000005ULL\r
57#define SVM_EXIT_UNSUPPORTED 0x8000FFFFULL\r
58\r
59//\r
60// IOIO Exit Information\r
61//\r
62#define IOIO_TYPE_STR BIT2\r
63#define IOIO_TYPE_IN 1\r
64#define IOIO_TYPE_INS (IOIO_TYPE_IN | IOIO_TYPE_STR)\r
65#define IOIO_TYPE_OUT 0\r
66#define IOIO_TYPE_OUTS (IOIO_TYPE_OUT | IOIO_TYPE_STR)\r
67\r
68#define IOIO_REP BIT3\r
69\r
70#define IOIO_ADDR_64 BIT9\r
71#define IOIO_ADDR_32 BIT8\r
72#define IOIO_ADDR_16 BIT7\r
73\r
74#define IOIO_DATA_32 BIT6\r
75#define IOIO_DATA_16 BIT5\r
76#define IOIO_DATA_8 BIT4\r
77#define IOIO_DATA_MASK (BIT6 | BIT5 | BIT4)\r
78#define IOIO_DATA_OFFSET 4\r
79#define IOIO_DATA_BYTES(x) (((x) & IOIO_DATA_MASK) >> IOIO_DATA_OFFSET)\r
80\r
81#define IOIO_SEG_ES 0\r
82#define IOIO_SEG_DS (BIT11 | BIT10)\r
83\r
84\r
85typedef enum {\r
86 GhcbCpl = 25,\r
87 GhcbRflags = 46,\r
88 GhcbRip,\r
89 GhcbRsp = 59,\r
90 GhcbRax = 63,\r
91 GhcbRcx = 97,\r
92 GhcbRdx,\r
93 GhcbRbx,\r
94 GhcbRbp = 101,\r
95 GhcbRsi,\r
96 GhcbRdi,\r
97 GhcbR8,\r
98 GhcbR9,\r
99 GhcbR10,\r
100 GhcbR11,\r
101 GhcbR12,\r
102 GhcbR13,\r
103 GhcbR14,\r
104 GhcbR15,\r
105 GhcbXCr0 = 125,\r
106} GHCB_REGISTER;\r
107\r
108typedef PACKED struct {\r
109 UINT8 Reserved1[203];\r
110 UINT8 Cpl;\r
111 UINT8 Reserved2[148];\r
112 UINT64 Dr7;\r
113 UINT8 Reserved3[144];\r
114 UINT64 Rax;\r
115 UINT8 Reserved4[264];\r
116 UINT64 Rcx;\r
117 UINT64 Rdx;\r
118 UINT64 Rbx;\r
119 UINT8 Reserved5[112];\r
120 UINT64 SwExitCode;\r
121 UINT64 SwExitInfo1;\r
122 UINT64 SwExitInfo2;\r
123 UINT64 SwScratch;\r
124 UINT8 Reserved6[56];\r
125 UINT64 XCr0;\r
126 UINT8 ValidBitmap[16];\r
127 UINT64 X87StateGpa;\r
128 UINT8 Reserved7[1016];\r
129} GHCB_SAVE_AREA;\r
130\r
131typedef PACKED struct {\r
132 GHCB_SAVE_AREA SaveArea;\r
133 UINT8 SharedBuffer[2032];\r
134 UINT8 Reserved1[10];\r
135 UINT16 ProtocolVersion;\r
136 UINT32 GhcbUsage;\r
137} GHCB;\r
138\r
139typedef union {\r
140 struct {\r
141 UINT32 Lower32Bits;\r
142 UINT32 Upper32Bits;\r
143 } Elements;\r
144\r
145 UINT64 Uint64;\r
146} GHCB_EXIT_INFO;\r
147\r
148typedef union {\r
149 struct {\r
150 UINT32 Vector:8;\r
151 UINT32 Type:3;\r
152 UINT32 ErrorCodeValid:1;\r
153 UINT32 Rsvd:19;\r
154 UINT32 Valid:1;\r
155 UINT32 ErrorCode;\r
156 } Elements;\r
157\r
158 UINT64 Uint64;\r
159} GHCB_EVENT_INJECTION;\r
160\r
161#define GHCB_EVENT_INJECTION_TYPE_INT 0\r
162#define GHCB_EVENT_INJECTION_TYPE_NMI 2\r
163#define GHCB_EVENT_INJECTION_TYPE_EXCEPTION 3\r
164#define GHCB_EVENT_INJECTION_TYPE_SOFT_INT 4\r
165\r
166#endif\r