]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioGpuDxe/VirtioGpu.h
OvmfPkg/VirtioGpuDxe: provide functions for sending VirtIo GPU commands
[mirror_edk2.git] / OvmfPkg / VirtioGpuDxe / VirtioGpu.h
1 /** @file
2
3 Internal type and macro definitions for the Virtio GPU hybrid driver.
4
5 Copyright (C) 2016, Red Hat, Inc.
6
7 This program and the accompanying materials are licensed and made available
8 under the terms and conditions of the BSD License which accompanies this
9 distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
13 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #ifndef _VIRTIO_GPU_DXE_H_
18 #define _VIRTIO_GPU_DXE_H_
19
20 #include <IndustryStandard/VirtioGpu.h>
21 #include <Library/DebugLib.h>
22 #include <Library/UefiLib.h>
23 #include <Protocol/VirtioDevice.h>
24
25 //
26 // Forward declaration of VGPU_GOP.
27 //
28 typedef struct VGPU_GOP_STRUCT VGPU_GOP;
29
30 //
31 // The abstraction that directly corresponds to a Virtio GPU device.
32 //
33 // This structure will be installed on the handle that has the VirtIo Device
34 // Protocol interface, with GUID gEfiCallerIdGuid. A similar trick is employed
35 // in TerminalDxe, and it is necessary so that we can look up VGPU_DEV just
36 // from the VirtIo Device Protocol handle in the Component Name 2 Protocol
37 // implementation.
38 //
39 typedef struct {
40 //
41 // VirtIo represents access to the Virtio GPU device. Never NULL.
42 //
43 VIRTIO_DEVICE_PROTOCOL *VirtIo;
44
45 //
46 // BusName carries a customized name for
47 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table
48 // form because it can theoretically support several languages. Never NULL.
49 //
50 EFI_UNICODE_STRING_TABLE *BusName;
51
52 //
53 // VirtIo ring used for VirtIo communication.
54 //
55 VRING Ring;
56
57 //
58 // Event to be signaled at ExitBootServices().
59 //
60 EFI_EVENT ExitBoot;
61
62 //
63 // Common running counter for all VirtIo GPU requests that ask for fencing.
64 //
65 UINT64 FenceId;
66
67 //
68 // The Child field references the GOP wrapper structure. If this pointer is
69 // NULL, then the hybrid driver has bound (i.e., started) the
70 // VIRTIO_DEVICE_PROTOCOL controller without producing the child GOP
71 // controller (that is, after Start() was called with RemainingDevicePath
72 // pointing to and End of Device Path node). Child can be created and
73 // destroyed, even repeatedly, independently of VGPU_DEV.
74 //
75 // In practice, this field represents the single head (scanout) that we
76 // support.
77 //
78 VGPU_GOP *Child;
79 } VGPU_DEV;
80
81 //
82 // The Graphics Output Protocol wrapper structure.
83 //
84 #define VGPU_GOP_SIG SIGNATURE_64 ('V', 'G', 'P', 'U', '_', 'G', 'O', 'P')
85
86 struct VGPU_GOP_STRUCT {
87 UINT64 Signature;
88
89 //
90 // ParentBus points to the parent VGPU_DEV object. Never NULL.
91 //
92 VGPU_DEV *ParentBus;
93
94 //
95 // GopName carries a customized name for
96 // EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName(). It is expressed in table
97 // form because it can theoretically support several languages. Never NULL.
98 //
99 EFI_UNICODE_STRING_TABLE *GopName;
100
101 //
102 // GopHandle is the UEFI child handle that carries the device path ending
103 // with the ACPI ADR node, and the Graphics Output Protocol. Never NULL.
104 //
105 EFI_HANDLE GopHandle;
106
107 //
108 // The GopDevicePath field is the device path installed on GopHandle,
109 // ending with an ACPI ADR node. Never NULL.
110 //
111 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
112
113 //
114 // The Gop field is installed on the child handle as Graphics Output Protocol
115 // interface.
116 //
117 // For now it is just a placeholder.
118 //
119 UINT8 Gop;
120 };
121
122 //
123 // VirtIo GPU initialization, and commands (primitives) for the GPU device.
124 //
125 /**
126 Configure the VirtIo GPU device that underlies VgpuDev.
127
128 @param[in,out] VgpuDev The VGPU_DEV object to set up VirtIo messaging for.
129 On input, the caller is responsible for having
130 initialized VgpuDev->VirtIo. On output, VgpuDev->Ring
131 has been initialized, and synchronous VirtIo GPU
132 commands (primitives) can be submitted to the device.
133
134 @retval EFI_SUCCESS VirtIo GPU configuration successful.
135
136 @retval EFI_UNSUPPORTED The host-side configuration of the VirtIo GPU is not
137 supported by this driver.
138
139 @retval Error codes from underlying functions.
140 **/
141 EFI_STATUS
142 VirtioGpuInit (
143 IN OUT VGPU_DEV *VgpuDev
144 );
145
146 /**
147 De-configure the VirtIo GPU device that underlies VgpuDev.
148
149 @param[in,out] VgpuDev The VGPU_DEV object to tear down VirtIo messaging
150 for. On input, the caller is responsible for having
151 called VirtioGpuInit(). On output, VgpuDev->Ring has
152 been uninitialized; VirtIo GPU commands (primitives)
153 can no longer be submitted to the device.
154 **/
155 VOID
156 VirtioGpuUninit (
157 IN OUT VGPU_DEV *VgpuDev
158 );
159
160 /**
161 EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the
162 VirtIo device, causing it to release its resources and to forget its
163 configuration.
164
165 This function may only be called (that is, VGPU_DEV.ExitBoot may only be
166 signaled) after VirtioGpuInit() returns and before VirtioGpuUninit() is
167 called.
168
169 @param[in] Event Event whose notification function is being invoked.
170
171 @param[in] Context Pointer to the associated VGPU_DEV object.
172 **/
173 VOID
174 EFIAPI
175 VirtioGpuExitBoot (
176 IN EFI_EVENT Event,
177 IN VOID *Context
178 );
179
180 /**
181 The following functions send requests to the VirtIo GPU device model, await
182 the answer from the host, and return a status. They share the following
183 interface details:
184
185 @param[in,out] VgpuDev The VGPU_DEV object that represents the VirtIo GPU
186 device. The caller is responsible to have
187 successfully invoked VirtioGpuInit() on VgpuDev
188 previously, while VirtioGpuUninit() must not have
189 been called on VgpuDev.
190
191 @retval EFI_INVALID_PARAMETER Invalid command-specific parameters were
192 detected by this driver.
193
194 @retval EFI_SUCCESS Operation successful.
195
196 @retval EFI_DEVICE_ERROR The host rejected the request. The host error
197 code has been logged on the EFI_D_ERROR level.
198
199 @return Codes for unexpected errors in VirtIo
200 messaging.
201
202 For the command-specific parameters, please consult the GPU Device section of
203 the VirtIo 1.0 specification (see references in
204 "OvmfPkg/Include/IndustryStandard/VirtioGpu.h").
205 **/
206 EFI_STATUS
207 VirtioGpuResourceCreate2d (
208 IN OUT VGPU_DEV *VgpuDev,
209 IN UINT32 ResourceId,
210 IN VIRTIO_GPU_FORMATS Format,
211 IN UINT32 Width,
212 IN UINT32 Height
213 );
214
215 EFI_STATUS
216 VirtioGpuResourceUnref (
217 IN OUT VGPU_DEV *VgpuDev,
218 IN UINT32 ResourceId
219 );
220
221 EFI_STATUS
222 VirtioGpuResourceAttachBacking (
223 IN OUT VGPU_DEV *VgpuDev,
224 IN UINT32 ResourceId,
225 IN VOID *FirstBackingPage,
226 IN UINTN NumberOfPages
227 );
228
229 EFI_STATUS
230 VirtioGpuResourceDetachBacking (
231 IN OUT VGPU_DEV *VgpuDev,
232 IN UINT32 ResourceId
233 );
234
235 EFI_STATUS
236 VirtioGpuSetScanout (
237 IN OUT VGPU_DEV *VgpuDev,
238 IN UINT32 X,
239 IN UINT32 Y,
240 IN UINT32 Width,
241 IN UINT32 Height,
242 IN UINT32 ScanoutId,
243 IN UINT32 ResourceId
244 );
245
246 EFI_STATUS
247 VirtioGpuTransferToHost2d (
248 IN OUT VGPU_DEV *VgpuDev,
249 IN UINT32 X,
250 IN UINT32 Y,
251 IN UINT32 Width,
252 IN UINT32 Height,
253 IN UINT64 Offset,
254 IN UINT32 ResourceId
255 );
256
257 EFI_STATUS
258 VirtioGpuResourceFlush (
259 IN OUT VGPU_DEV *VgpuDev,
260 IN UINT32 X,
261 IN UINT32 Y,
262 IN UINT32 Width,
263 IN UINT32 Height,
264 IN UINT32 ResourceId
265 );
266
267 #endif // _VIRTIO_GPU_DXE_H_