]>
git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioGpuDxe/Commands.c
3 VirtIo GPU initialization, and commands (primitives) for the GPU device.
5 Copyright (C) 2016, Red Hat, Inc.
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
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.
17 #include <IndustryStandard/VirtioGpu.h>
18 #include <Library/VirtioLib.h>
20 #include "VirtioGpu.h"
23 Configure the VirtIo GPU device that underlies VgpuDev.
25 @param[in,out] VgpuDev The VGPU_DEV object to set up VirtIo messaging for.
26 On input, the caller is responsible for having
27 initialized VgpuDev->VirtIo. On output, VgpuDev->Ring
28 has been initialized, and synchronous VirtIo GPU
29 commands (primitives) can be submitted to the device.
31 @retval EFI_SUCCESS VirtIo GPU configuration successful.
33 @retval EFI_UNSUPPORTED The host-side configuration of the VirtIo GPU is not
34 supported by this driver.
36 @retval Error codes from underlying functions.
40 IN OUT VGPU_DEV
*VgpuDev
49 // Execute virtio-v1.0-cs04, 3.1.1 Driver Requirements: Device
52 // 1. Reset the device.
55 Status
= VgpuDev
->VirtIo
->SetDeviceStatus (VgpuDev
->VirtIo
, NextDevStat
);
56 if (EFI_ERROR (Status
)) {
61 // 2. Set the ACKNOWLEDGE status bit [...]
63 NextDevStat
|= VSTAT_ACK
;
64 Status
= VgpuDev
->VirtIo
->SetDeviceStatus (VgpuDev
->VirtIo
, NextDevStat
);
65 if (EFI_ERROR (Status
)) {
70 // 3. Set the DRIVER status bit [...]
72 NextDevStat
|= VSTAT_DRIVER
;
73 Status
= VgpuDev
->VirtIo
->SetDeviceStatus (VgpuDev
->VirtIo
, NextDevStat
);
74 if (EFI_ERROR (Status
)) {
79 // 4. Read device feature bits...
81 Status
= VgpuDev
->VirtIo
->GetDeviceFeatures (VgpuDev
->VirtIo
, &Features
);
82 if (EFI_ERROR (Status
)) {
85 if ((Features
& VIRTIO_F_VERSION_1
) == 0) {
86 Status
= EFI_UNSUPPORTED
;
90 // We only want the most basic 2D features.
92 Features
&= VIRTIO_F_VERSION_1
;
95 // ... and write the subset of feature bits understood by the [...] driver to
97 // 5. Set the FEATURES_OK status bit.
98 // 6. Re-read device status to ensure the FEATURES_OK bit is still set [...]
100 Status
= Virtio10WriteFeatures (VgpuDev
->VirtIo
, Features
, &NextDevStat
);
101 if (EFI_ERROR (Status
)) {
106 // 7. Perform device-specific setup, including discovery of virtqueues for
109 Status
= VgpuDev
->VirtIo
->SetQueueSel (VgpuDev
->VirtIo
,
110 VIRTIO_GPU_CONTROL_QUEUE
);
111 if (EFI_ERROR (Status
)) {
114 Status
= VgpuDev
->VirtIo
->GetQueueNumMax (VgpuDev
->VirtIo
, &QueueSize
);
115 if (EFI_ERROR (Status
)) {
120 // We implement each VirtIo GPU command that we use with two descriptors:
121 // request, response.
124 Status
= EFI_UNSUPPORTED
;
129 // [...] population of virtqueues [...]
131 Status
= VirtioRingInit (QueueSize
, &VgpuDev
->Ring
);
132 if (EFI_ERROR (Status
)) {
135 Status
= VgpuDev
->VirtIo
->SetQueueAddress (VgpuDev
->VirtIo
, &VgpuDev
->Ring
);
136 if (EFI_ERROR (Status
)) {
141 // 8. Set the DRIVER_OK status bit.
143 NextDevStat
|= VSTAT_DRIVER_OK
;
144 Status
= VgpuDev
->VirtIo
->SetDeviceStatus (VgpuDev
->VirtIo
, NextDevStat
);
145 if (EFI_ERROR (Status
)) {
152 VirtioRingUninit (&VgpuDev
->Ring
);
156 // If any of these steps go irrecoverably wrong, the driver SHOULD set the
157 // FAILED status bit to indicate that it has given up on the device (it can
158 // reset the device later to restart if desired). [...]
160 // VirtIo access failure here should not mask the original error.
162 NextDevStat
|= VSTAT_FAILED
;
163 VgpuDev
->VirtIo
->SetDeviceStatus (VgpuDev
->VirtIo
, NextDevStat
);
169 De-configure the VirtIo GPU device that underlies VgpuDev.
171 @param[in,out] VgpuDev The VGPU_DEV object to tear down VirtIo messaging
172 for. On input, the caller is responsible for having
173 called VirtioGpuInit(). On output, VgpuDev->Ring has
174 been uninitialized; VirtIo GPU commands (primitives)
175 can no longer be submitted to the device.
179 IN OUT VGPU_DEV
*VgpuDev
183 // Resetting the VirtIo device makes it release its resources and forget its
186 VgpuDev
->VirtIo
->SetDeviceStatus (VgpuDev
->VirtIo
, 0);
187 VirtioRingUninit (&VgpuDev
->Ring
);
191 EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the
192 VirtIo device, causing it to release its resources and to forget its
195 This function may only be called (that is, VGPU_DEV.ExitBoot may only be
196 signaled) after VirtioGpuInit() returns and before VirtioGpuUninit() is
199 @param[in] Event Event whose notification function is being invoked.
201 @param[in] Context Pointer to the associated VGPU_DEV object.
213 VgpuDev
->VirtIo
->SetDeviceStatus (VgpuDev
->VirtIo
, 0);