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