]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioGpuDxe/VirtioGpu.h
OvmfPkg/BaseMemEncryptSevLib: skip the pre-validated system RAM
[mirror_edk2.git] / OvmfPkg / VirtioGpuDxe / VirtioGpu.h
CommitLineData
a2a4fa66
LE
1/** @file\r
2\r
3 Internal type and macro definitions for the Virtio GPU hybrid driver.\r
4\r
5 Copyright (C) 2016, Red Hat, Inc.\r
6\r
b26f0cf9 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a2a4fa66
LE
8\r
9**/\r
10\r
11#ifndef _VIRTIO_GPU_DXE_H_\r
12#define _VIRTIO_GPU_DXE_H_\r
13\r
a66ea3b5 14#include <IndustryStandard/VirtioGpu.h>\r
5c8f091b 15#include <Library/BaseMemoryLib.h>\r
a2a4fa66
LE
16#include <Library/DebugLib.h>\r
17#include <Library/UefiLib.h>\r
8731debe 18#include <Protocol/GraphicsOutput.h>\r
a2a4fa66
LE
19#include <Protocol/VirtioDevice.h>\r
20\r
21//\r
22// Forward declaration of VGPU_GOP.\r
23//\r
24typedef struct VGPU_GOP_STRUCT VGPU_GOP;\r
25\r
26//\r
27// The abstraction that directly corresponds to a Virtio GPU device.\r
28//\r
29// This structure will be installed on the handle that has the VirtIo Device\r
30// Protocol interface, with GUID gEfiCallerIdGuid. A similar trick is employed\r
31// in TerminalDxe, and it is necessary so that we can look up VGPU_DEV just\r
32// from the VirtIo Device Protocol handle in the Component Name 2 Protocol\r
33// implementation.\r
34//\r
35typedef struct {\r
36 //\r
37 // VirtIo represents access to the Virtio GPU device. Never NULL.\r
38 //\r
ac0a286f 39 VIRTIO_DEVICE_PROTOCOL *VirtIo;\r
a2a4fa66
LE
40\r
41 //\r
42 // BusName carries a customized name for\r
43 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table\r
44 // form because it can theoretically support several languages. Never NULL.\r
45 //\r
ac0a286f 46 EFI_UNICODE_STRING_TABLE *BusName;\r
a2a4fa66 47\r
c5f235bb
LE
48 //\r
49 // VirtIo ring used for VirtIo communication.\r
50 //\r
ac0a286f 51 VRING Ring;\r
c5f235bb 52\r
9bc5026c
LE
53 //\r
54 // Token associated with Ring's mapping for bus master common buffer\r
55 // operation, from VirtioRingMap().\r
56 //\r
ac0a286f 57 VOID *RingMap;\r
9bc5026c 58\r
c5f235bb
LE
59 //\r
60 // Event to be signaled at ExitBootServices().\r
61 //\r
ac0a286f 62 EFI_EVENT ExitBoot;\r
c5f235bb 63\r
a66ea3b5
LE
64 //\r
65 // Common running counter for all VirtIo GPU requests that ask for fencing.\r
66 //\r
ac0a286f 67 UINT64 FenceId;\r
a66ea3b5 68\r
a2a4fa66
LE
69 //\r
70 // The Child field references the GOP wrapper structure. If this pointer is\r
71 // NULL, then the hybrid driver has bound (i.e., started) the\r
72 // VIRTIO_DEVICE_PROTOCOL controller without producing the child GOP\r
73 // controller (that is, after Start() was called with RemainingDevicePath\r
74 // pointing to and End of Device Path node). Child can be created and\r
75 // destroyed, even repeatedly, independently of VGPU_DEV.\r
76 //\r
77 // In practice, this field represents the single head (scanout) that we\r
78 // support.\r
79 //\r
ac0a286f 80 VGPU_GOP *Child;\r
a2a4fa66
LE
81} VGPU_DEV;\r
82\r
83//\r
84// The Graphics Output Protocol wrapper structure.\r
85//\r
ac0a286f 86#define VGPU_GOP_SIG SIGNATURE_64 ('V', 'G', 'P', 'U', '_', 'G', 'O', 'P')\r
a2a4fa66
LE
87\r
88struct VGPU_GOP_STRUCT {\r
ac0a286f 89 UINT64 Signature;\r
a2a4fa66
LE
90\r
91 //\r
92 // ParentBus points to the parent VGPU_DEV object. Never NULL.\r
93 //\r
ac0a286f 94 VGPU_DEV *ParentBus;\r
a2a4fa66
LE
95\r
96 //\r
97 // GopName carries a customized name for\r
98 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table\r
99 // form because it can theoretically support several languages. Never NULL.\r
100 //\r
ac0a286f 101 EFI_UNICODE_STRING_TABLE *GopName;\r
a2a4fa66
LE
102\r
103 //\r
104 // GopHandle is the UEFI child handle that carries the device path ending\r
105 // with the ACPI ADR node, and the Graphics Output Protocol. Never NULL.\r
106 //\r
ac0a286f 107 EFI_HANDLE GopHandle;\r
a2a4fa66
LE
108\r
109 //\r
110 // The GopDevicePath field is the device path installed on GopHandle,\r
111 // ending with an ACPI ADR node. Never NULL.\r
112 //\r
ac0a286f 113 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;\r
a2a4fa66
LE
114\r
115 //\r
116 // The Gop field is installed on the child handle as Graphics Output Protocol\r
117 // interface.\r
118 //\r
ac0a286f 119 EFI_GRAPHICS_OUTPUT_PROTOCOL Gop;\r
8731debe
LE
120\r
121 //\r
122 // Referenced by Gop.Mode, GopMode provides a summary about the supported\r
123 // graphics modes, and the current mode.\r
124 //\r
ac0a286f 125 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE GopMode;\r
8731debe
LE
126\r
127 //\r
128 // Referenced by GopMode.Info, GopModeInfo provides detailed information\r
129 // about the current mode.\r
130 //\r
ac0a286f 131 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION GopModeInfo;\r
8731debe
LE
132\r
133 //\r
134 // Identifier of the 2D host resource that is in use by this head (scanout)\r
135 // of the VirtIo GPU device. Zero until the first successful -- internal --\r
136 // Gop.SetMode() call, never zero afterwards.\r
137 //\r
ac0a286f 138 UINT32 ResourceId;\r
8731debe 139\r
a2a4fa66 140 //\r
8731debe
LE
141 // A number of whole pages providing the backing store for the 2D host\r
142 // resource identified by ResourceId above. NULL until the first successful\r
143 // -- internal -- Gop.SetMode() call, never NULL afterwards.\r
144 //\r
ac0a286f
MK
145 UINT32 *BackingStore;\r
146 UINTN NumberOfPages;\r
f10ae923
LE
147\r
148 //\r
149 // Token associated with BackingStore's mapping for bus master common\r
150 // buffer operation. BackingStoreMap is valid if, and only if,\r
151 // BackingStore is non-NULL.\r
152 //\r
ac0a286f 153 VOID *BackingStoreMap;\r
a2a4fa66
LE
154};\r
155\r
c5f235bb
LE
156//\r
157// VirtIo GPU initialization, and commands (primitives) for the GPU device.\r
158//\r
ac0a286f 159\r
c5f235bb
LE
160/**\r
161 Configure the VirtIo GPU device that underlies VgpuDev.\r
162\r
163 @param[in,out] VgpuDev The VGPU_DEV object to set up VirtIo messaging for.\r
164 On input, the caller is responsible for having\r
165 initialized VgpuDev->VirtIo. On output, VgpuDev->Ring\r
166 has been initialized, and synchronous VirtIo GPU\r
167 commands (primitives) can be submitted to the device.\r
168\r
169 @retval EFI_SUCCESS VirtIo GPU configuration successful.\r
170\r
171 @retval EFI_UNSUPPORTED The host-side configuration of the VirtIo GPU is not\r
172 supported by this driver.\r
173\r
174 @retval Error codes from underlying functions.\r
175**/\r
176EFI_STATUS\r
177VirtioGpuInit (\r
ac0a286f 178 IN OUT VGPU_DEV *VgpuDev\r
c5f235bb
LE
179 );\r
180\r
181/**\r
182 De-configure the VirtIo GPU device that underlies VgpuDev.\r
183\r
184 @param[in,out] VgpuDev The VGPU_DEV object to tear down VirtIo messaging\r
185 for. On input, the caller is responsible for having\r
186 called VirtioGpuInit(). On output, VgpuDev->Ring has\r
187 been uninitialized; VirtIo GPU commands (primitives)\r
188 can no longer be submitted to the device.\r
189**/\r
190VOID\r
191VirtioGpuUninit (\r
ac0a286f 192 IN OUT VGPU_DEV *VgpuDev\r
c5f235bb
LE
193 );\r
194\r
5c8f091b
LE
195/**\r
196 Allocate, zero and map memory, for bus master common buffer operation, to be\r
197 attached as backing store to a host-side VirtIo GPU resource.\r
198\r
199 @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r
200 device.\r
201\r
202 @param[in] NumberOfPages The number of whole pages to allocate and map.\r
203\r
204 @param[out] HostAddress The system memory address of the allocated area.\r
205\r
206 @param[out] DeviceAddress The bus master device address of the allocated\r
207 area. The VirtIo GPU device may be programmed to\r
208 access the allocated area through DeviceAddress;\r
209 DeviceAddress is to be passed to the\r
210 VirtioGpuResourceAttachBacking() function, as the\r
211 BackingStoreDeviceAddress parameter.\r
212\r
213 @param[out] Mapping A resulting token to pass to\r
214 VirtioGpuUnmapAndFreeBackingStore().\r
215\r
216 @retval EFI_SUCCESS The requested number of pages has been allocated, zeroed\r
217 and mapped.\r
218\r
219 @return Status codes propagated from\r
220 VgpuDev->VirtIo->AllocateSharedPages() and\r
221 VirtioMapAllBytesInSharedBuffer().\r
222**/\r
223EFI_STATUS\r
224VirtioGpuAllocateZeroAndMapBackingStore (\r
ac0a286f
MK
225 IN VGPU_DEV *VgpuDev,\r
226 IN UINTN NumberOfPages,\r
227 OUT VOID **HostAddress,\r
228 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
229 OUT VOID **Mapping\r
5c8f091b
LE
230 );\r
231\r
232/**\r
233 Unmap and free memory originally allocated and mapped with\r
234 VirtioGpuAllocateZeroAndMapBackingStore().\r
235\r
236 If the memory allocated and mapped with\r
237 VirtioGpuAllocateZeroAndMapBackingStore() was attached to a host-side VirtIo\r
238 GPU resource with VirtioGpuResourceAttachBacking(), then the caller is\r
239 responsible for detaching the backing store from the same resource, with\r
240 VirtioGpuResourceDetachBacking(), before calling this function.\r
241\r
242 @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r
243 device.\r
244\r
245 @param[in] NumberOfPages The NumberOfPages parameter originally passed to\r
246 VirtioGpuAllocateZeroAndMapBackingStore().\r
247\r
248 @param[in] HostAddress The HostAddress value originally output by\r
249 VirtioGpuAllocateZeroAndMapBackingStore().\r
250\r
251 @param[in] Mapping The token that was originally output by\r
252 VirtioGpuAllocateZeroAndMapBackingStore().\r
253**/\r
254VOID\r
255VirtioGpuUnmapAndFreeBackingStore (\r
ac0a286f
MK
256 IN VGPU_DEV *VgpuDev,\r
257 IN UINTN NumberOfPages,\r
258 IN VOID *HostAddress,\r
259 IN VOID *Mapping\r
5c8f091b
LE
260 );\r
261\r
c5f235bb
LE
262/**\r
263 EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the\r
264 VirtIo device, causing it to release its resources and to forget its\r
265 configuration.\r
266\r
267 This function may only be called (that is, VGPU_DEV.ExitBoot may only be\r
268 signaled) after VirtioGpuInit() returns and before VirtioGpuUninit() is\r
269 called.\r
270\r
271 @param[in] Event Event whose notification function is being invoked.\r
272\r
273 @param[in] Context Pointer to the associated VGPU_DEV object.\r
274**/\r
275VOID\r
276EFIAPI\r
277VirtioGpuExitBoot (\r
ac0a286f
MK
278 IN EFI_EVENT Event,\r
279 IN VOID *Context\r
c5f235bb
LE
280 );\r
281\r
a66ea3b5
LE
282/**\r
283 The following functions send requests to the VirtIo GPU device model, await\r
284 the answer from the host, and return a status. They share the following\r
285 interface details:\r
286\r
287 @param[in,out] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r
288 device. The caller is responsible to have\r
289 successfully invoked VirtioGpuInit() on VgpuDev\r
290 previously, while VirtioGpuUninit() must not have\r
291 been called on VgpuDev.\r
292\r
293 @retval EFI_INVALID_PARAMETER Invalid command-specific parameters were\r
294 detected by this driver.\r
295\r
296 @retval EFI_SUCCESS Operation successful.\r
297\r
298 @retval EFI_DEVICE_ERROR The host rejected the request. The host error\r
70d5086c 299 code has been logged on the DEBUG_ERROR level.\r
a66ea3b5
LE
300\r
301 @return Codes for unexpected errors in VirtIo\r
302 messaging.\r
303\r
304 For the command-specific parameters, please consult the GPU Device section of\r
305 the VirtIo 1.0 specification (see references in\r
306 "OvmfPkg/Include/IndustryStandard/VirtioGpu.h").\r
307**/\r
308EFI_STATUS\r
309VirtioGpuResourceCreate2d (\r
ac0a286f
MK
310 IN OUT VGPU_DEV *VgpuDev,\r
311 IN UINT32 ResourceId,\r
312 IN VIRTIO_GPU_FORMATS Format,\r
313 IN UINT32 Width,\r
314 IN UINT32 Height\r
a66ea3b5
LE
315 );\r
316\r
317EFI_STATUS\r
318VirtioGpuResourceUnref (\r
ac0a286f
MK
319 IN OUT VGPU_DEV *VgpuDev,\r
320 IN UINT32 ResourceId\r
a66ea3b5
LE
321 );\r
322\r
323EFI_STATUS\r
324VirtioGpuResourceAttachBacking (\r
ac0a286f
MK
325 IN OUT VGPU_DEV *VgpuDev,\r
326 IN UINT32 ResourceId,\r
327 IN EFI_PHYSICAL_ADDRESS BackingStoreDeviceAddress,\r
328 IN UINTN NumberOfPages\r
a66ea3b5
LE
329 );\r
330\r
331EFI_STATUS\r
332VirtioGpuResourceDetachBacking (\r
ac0a286f
MK
333 IN OUT VGPU_DEV *VgpuDev,\r
334 IN UINT32 ResourceId\r
a66ea3b5
LE
335 );\r
336\r
337EFI_STATUS\r
338VirtioGpuSetScanout (\r
ac0a286f
MK
339 IN OUT VGPU_DEV *VgpuDev,\r
340 IN UINT32 X,\r
341 IN UINT32 Y,\r
342 IN UINT32 Width,\r
343 IN UINT32 Height,\r
344 IN UINT32 ScanoutId,\r
345 IN UINT32 ResourceId\r
a66ea3b5
LE
346 );\r
347\r
348EFI_STATUS\r
349VirtioGpuTransferToHost2d (\r
ac0a286f
MK
350 IN OUT VGPU_DEV *VgpuDev,\r
351 IN UINT32 X,\r
352 IN UINT32 Y,\r
353 IN UINT32 Width,\r
354 IN UINT32 Height,\r
355 IN UINT64 Offset,\r
356 IN UINT32 ResourceId\r
a66ea3b5
LE
357 );\r
358\r
359EFI_STATUS\r
360VirtioGpuResourceFlush (\r
ac0a286f
MK
361 IN OUT VGPU_DEV *VgpuDev,\r
362 IN UINT32 X,\r
363 IN UINT32 Y,\r
364 IN UINT32 Width,\r
365 IN UINT32 Height,\r
366 IN UINT32 ResourceId\r
a66ea3b5
LE
367 );\r
368\r
8731debe
LE
369/**\r
370 Release guest-side and host-side resources that are related to an initialized\r
371 VGPU_GOP.Gop.\r
372\r
373 param[in,out] VgpuGop The VGPU_GOP object to release resources for.\r
374\r
375 On input, the caller is responsible for having called\r
376 VgpuGop->Gop.SetMode() at least once successfully.\r
377 (This is equivalent to the requirement that\r
378 VgpuGop->BackingStore be non-NULL. It is also\r
379 equivalent to the requirement that VgpuGop->ResourceId\r
380 be nonzero.)\r
381\r
382 On output, resources will be released, and\r
383 VgpuGop->BackingStore and VgpuGop->ResourceId will be\r
384 nulled.\r
385\r
386 param[in] DisableHead Whether this head (scanout) currently references the\r
387 resource identified by VgpuGop->ResourceId. Only pass\r
388 FALSE when VgpuGop->Gop.SetMode() calls this function\r
389 while switching between modes, and set it to TRUE\r
390 every other time.\r
391**/\r
392VOID\r
393ReleaseGopResources (\r
ac0a286f
MK
394 IN OUT VGPU_GOP *VgpuGop,\r
395 IN BOOLEAN DisableHead\r
8731debe
LE
396 );\r
397\r
398//\r
399// Template for initializing VGPU_GOP.Gop.\r
400//\r
ac0a286f 401extern CONST EFI_GRAPHICS_OUTPUT_PROTOCOL mGopTemplate;\r
8731debe 402\r
a2a4fa66 403#endif // _VIRTIO_GPU_DXE_H_\r