1 | /** @file
|
---|
2 | VMware SVGA 3 Video Controller Driver
|
---|
3 |
|
---|
4 | Copyright (c) 2023 - 2024, Oracle and/or its affiliates.<BR>
|
---|
5 | Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | //
|
---|
11 | // VMware SVGA 3 Video Controller Driver
|
---|
12 | //
|
---|
13 |
|
---|
14 | #ifndef _VMWSVGA3_H_
|
---|
15 | #define _VMWSVGA3_H_
|
---|
16 |
|
---|
17 | #include <Uefi.h>
|
---|
18 | #include <Protocol/GraphicsOutput.h>
|
---|
19 | #include <Protocol/PciIo.h>
|
---|
20 | #include <Protocol/DriverSupportedEfiVersion.h>
|
---|
21 | #include <Protocol/DevicePath.h>
|
---|
22 |
|
---|
23 | #include <Library/DebugLib.h>
|
---|
24 | #include <Library/UefiDriverEntryPoint.h>
|
---|
25 | #include <Library/UefiLib.h>
|
---|
26 | #include <Library/PcdLib.h>
|
---|
27 | #include <Library/MemoryAllocationLib.h>
|
---|
28 | #include <Library/UefiBootServicesTableLib.h>
|
---|
29 | #include <Library/BaseMemoryLib.h>
|
---|
30 | #include <Library/DevicePathLib.h>
|
---|
31 | #include <Library/TimerLib.h>
|
---|
32 | #include <Library/FrameBufferBltLib.h>
|
---|
33 |
|
---|
34 | #include <IndustryStandard/Pci.h>
|
---|
35 | #include <IndustryStandard/Acpi.h>
|
---|
36 |
|
---|
37 | //
|
---|
38 | // VMware SVGA 3 Video PCI Configuration Header values
|
---|
39 | //
|
---|
40 | #define PCI_VENDOR_ID_VMWARE 0x15ad
|
---|
41 | #define PCI_DEVICE_ID_VMWARE_SVGA3 0x0406
|
---|
42 |
|
---|
43 | //
|
---|
44 | // Used commands
|
---|
45 | //
|
---|
46 | #define VMWSVGA3_CMD_UPDATE 1
|
---|
47 |
|
---|
48 | //
|
---|
49 | // Command buffer context definitions
|
---|
50 | //
|
---|
51 | #define VMWSVGA3_CB_CTX_DEVICE 0x3f
|
---|
52 | #define VMWSVGA3_CB_CTX_0 0
|
---|
53 |
|
---|
54 | //
|
---|
55 | // Command buffer status definitions
|
---|
56 | //
|
---|
57 | #define VMWSVGA3_CB_STATUS_NONE 0
|
---|
58 | #define VMWSVGA3_CB_STATUS_COMPLETED 1
|
---|
59 |
|
---|
60 | //
|
---|
61 | // Command buffer flags
|
---|
62 | //
|
---|
63 | #define VMWSVGA3_CB_FLAG_NONE 0
|
---|
64 | #define VMWSVGA3_CB_FLAG_NO_IRQ (1 << 0)
|
---|
65 |
|
---|
66 | //
|
---|
67 | // Device context commands
|
---|
68 | //
|
---|
69 | #define VMWSVGA3_CMD_DC_START_STOP_CTX 1
|
---|
70 |
|
---|
71 | //
|
---|
72 | // Command buffer header
|
---|
73 | //
|
---|
74 | typedef struct
|
---|
75 | {
|
---|
76 | volatile UINT32 Status; // Modified by device
|
---|
77 | volatile UINT32 ErrorOffset; // Modified by device
|
---|
78 | UINT64 Id;
|
---|
79 | UINT32 Flags;
|
---|
80 | UINT32 Length;
|
---|
81 | UINT64 PhysicalAddress;
|
---|
82 | UINT32 Offset;
|
---|
83 | UINT32 DxContext; // Valid if DX_CONTEXT flag set, must be zero otherwise
|
---|
84 | UINT32 Reserved[6];
|
---|
85 | } VMWSVGA3_CB_HDR;
|
---|
86 |
|
---|
87 | //
|
---|
88 | // Update command definition
|
---|
89 | //
|
---|
90 | typedef struct {
|
---|
91 | UINT32 CmdId;
|
---|
92 | UINT32 x;
|
---|
93 | UINT32 y;
|
---|
94 | UINT32 Width;
|
---|
95 | UINT32 Height;
|
---|
96 | } VMWSVGA3_CTX_CMD_UPDATE;
|
---|
97 |
|
---|
98 | //
|
---|
99 | // Start/Stop context command definition
|
---|
100 | //
|
---|
101 | typedef struct {
|
---|
102 | UINT32 CmdId;
|
---|
103 | UINT32 Enable;
|
---|
104 | UINT32 Context;
|
---|
105 | } VMWSVGA3_DC_CMD_START_STOP_CTX;
|
---|
106 |
|
---|
107 | //
|
---|
108 | // VMware SVGA 3 Video Private Data Structure
|
---|
109 | //
|
---|
110 | #define VMWSVGA3_VIDEO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('V', 'M', 'W', '3')
|
---|
111 |
|
---|
112 |
|
---|
113 | typedef struct {
|
---|
114 | UINT64 Signature;
|
---|
115 | EFI_HANDLE Handle;
|
---|
116 | EFI_PCI_IO_PROTOCOL *PciIo;
|
---|
117 | UINT64 OriginalPciAttributes;
|
---|
118 | EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
|
---|
119 | EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
|
---|
120 |
|
---|
121 | FRAME_BUFFER_CONFIGURE *FrameBufferBltConfigure;
|
---|
122 | UINTN FrameBufferBltConfigureSize;
|
---|
123 | UINT8 FrameBufferVramBarIndex;
|
---|
124 |
|
---|
125 | VMWSVGA3_CB_HDR *CmdBufHdr;
|
---|
126 | VOID *CmdBuf;
|
---|
127 |
|
---|
128 | EFI_PHYSICAL_ADDRESS PhysicalAddressCmdBufHdr;
|
---|
129 | EFI_PHYSICAL_ADDRESS PhysicalAddressCmdBuf;
|
---|
130 |
|
---|
131 | VOID *CmdBufMapping;
|
---|
132 | } VMWSVGA3_VIDEO_PRIVATE_DATA;
|
---|
133 |
|
---|
134 | #define VMWSVGA3_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
|
---|
135 | CR(a, VMWSVGA3_VIDEO_PRIVATE_DATA, GraphicsOutput, VMWSVGA3_VIDEO_PRIVATE_DATA_SIGNATURE)
|
---|
136 |
|
---|
137 | //
|
---|
138 | // Global Variables
|
---|
139 | //
|
---|
140 | extern UINT8 AttributeController[];
|
---|
141 | extern UINT8 GraphicsController[];
|
---|
142 | extern EFI_DRIVER_BINDING_PROTOCOL gVmwSvga3VideoDriverBinding;
|
---|
143 | extern EFI_COMPONENT_NAME_PROTOCOL gVmwSvga3VideoComponentName;
|
---|
144 | extern EFI_COMPONENT_NAME2_PROTOCOL gVmwSvga3VideoComponentName2;
|
---|
145 |
|
---|
146 | //
|
---|
147 | // PCI BARs defined by SVGA3
|
---|
148 | //
|
---|
149 | #define VMWSVGA3_MMIO_BAR 0
|
---|
150 | #define VMWSVGA3_VRAM_BAR 2
|
---|
151 |
|
---|
152 | //
|
---|
153 | // MMIO Registers defined by SVGA3
|
---|
154 | //
|
---|
155 | #define VMWSVGA3_REG_ID 0
|
---|
156 | # define VMWSVGA3_REG_ID_SVGA3 0x90000003
|
---|
157 | #define VMWSVGA3_REG_ENABLE 4
|
---|
158 | #define VMWSVGA3_REG_WIDTH 8
|
---|
159 | #define VMWSVGA3_REG_HEIGHT 12
|
---|
160 | #define VMWSVGA3_REG_DEPTH 24
|
---|
161 | #define VMWSVGA3_REG_BITS_PER_PIXEL 28
|
---|
162 | #define VMWSVGA3_REG_CONFIG_DONE 80
|
---|
163 | #define VMWSVGA3_REG_IRQMASK 132
|
---|
164 | #define VMWSVGA3_REG_TRACES 180
|
---|
165 | #define VMWSVGA3_REG_COMMAND_LOW 192
|
---|
166 | #define VMWSVGA3_REG_COMMAND_HIGH 196
|
---|
167 | #define VMWSVGA3_REG_IRQ_STATUS 328
|
---|
168 |
|
---|
169 | //
|
---|
170 | // Graphics Output Hardware abstraction internal worker functions
|
---|
171 | //
|
---|
172 | EFI_STATUS
|
---|
173 | VmwSvga3VideoGraphicsOutputConstructor (
|
---|
174 | VMWSVGA3_VIDEO_PRIVATE_DATA *Private
|
---|
175 | );
|
---|
176 |
|
---|
177 | EFI_STATUS
|
---|
178 | VmwSvga3VideoGraphicsOutputDestructor (
|
---|
179 | VMWSVGA3_VIDEO_PRIVATE_DATA *Private
|
---|
180 | );
|
---|
181 |
|
---|
182 | //
|
---|
183 | // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
|
---|
184 | //
|
---|
185 |
|
---|
186 | /**
|
---|
187 | TODO: Add function description
|
---|
188 |
|
---|
189 | @param This TODO: add argument description
|
---|
190 | @param Controller TODO: add argument description
|
---|
191 | @param RemainingDevicePath TODO: add argument description
|
---|
192 |
|
---|
193 | TODO: add return values
|
---|
194 |
|
---|
195 | **/
|
---|
196 | EFI_STATUS
|
---|
197 | EFIAPI
|
---|
198 | VmwSvga3VideoControllerDriverSupported (
|
---|
199 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
200 | IN EFI_HANDLE Controller,
|
---|
201 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
---|
202 | );
|
---|
203 |
|
---|
204 | /**
|
---|
205 | TODO: Add function description
|
---|
206 |
|
---|
207 | @param This TODO: add argument description
|
---|
208 | @param Controller TODO: add argument description
|
---|
209 | @param RemainingDevicePath TODO: add argument description
|
---|
210 |
|
---|
211 | TODO: add return values
|
---|
212 |
|
---|
213 | **/
|
---|
214 | EFI_STATUS
|
---|
215 | EFIAPI
|
---|
216 | VmwSvga3VideoControllerDriverStart (
|
---|
217 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
218 | IN EFI_HANDLE Controller,
|
---|
219 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
---|
220 | );
|
---|
221 |
|
---|
222 | /**
|
---|
223 | TODO: Add function description
|
---|
224 |
|
---|
225 | @param This TODO: add argument description
|
---|
226 | @param Controller TODO: add argument description
|
---|
227 | @param NumberOfChildren TODO: add argument description
|
---|
228 | @param ChildHandleBuffer TODO: add argument description
|
---|
229 |
|
---|
230 | TODO: add return values
|
---|
231 |
|
---|
232 | **/
|
---|
233 | EFI_STATUS
|
---|
234 | EFIAPI
|
---|
235 | VmwSvga3VideoControllerDriverStop (
|
---|
236 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
237 | IN EFI_HANDLE Controller,
|
---|
238 | IN UINTN NumberOfChildren,
|
---|
239 | IN EFI_HANDLE *ChildHandleBuffer
|
---|
240 | );
|
---|
241 |
|
---|
242 | //
|
---|
243 | // EFI Component Name Functions
|
---|
244 | //
|
---|
245 |
|
---|
246 | /**
|
---|
247 | Retrieves a Unicode string that is the user readable name of the driver.
|
---|
248 |
|
---|
249 | This function retrieves the user readable name of a driver in the form of a
|
---|
250 | Unicode string. If the driver specified by This has a user readable name in
|
---|
251 | the language specified by Language, then a pointer to the driver name is
|
---|
252 | returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
|
---|
253 | by This does not support the language specified by Language,
|
---|
254 | then EFI_UNSUPPORTED is returned.
|
---|
255 |
|
---|
256 | @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
|
---|
257 | EFI_COMPONENT_NAME_PROTOCOL instance.
|
---|
258 |
|
---|
259 | @param Language[in] A pointer to a Null-terminated ASCII string
|
---|
260 | array indicating the language. This is the
|
---|
261 | language of the driver name that the caller is
|
---|
262 | requesting, and it must match one of the
|
---|
263 | languages specified in SupportedLanguages. The
|
---|
264 | number of languages supported by a driver is up
|
---|
265 | to the driver writer. Language is specified
|
---|
266 | in RFC 4646 or ISO 639-2 language code format.
|
---|
267 |
|
---|
268 | @param DriverName[out] A pointer to the Unicode string to return.
|
---|
269 | This Unicode string is the name of the
|
---|
270 | driver specified by This in the language
|
---|
271 | specified by Language.
|
---|
272 |
|
---|
273 | @retval EFI_SUCCESS The Unicode string for the Driver specified by
|
---|
274 | This and the language specified by Language was
|
---|
275 | returned in DriverName.
|
---|
276 |
|
---|
277 | @retval EFI_INVALID_PARAMETER Language is NULL.
|
---|
278 |
|
---|
279 | @retval EFI_INVALID_PARAMETER DriverName is NULL.
|
---|
280 |
|
---|
281 | @retval EFI_UNSUPPORTED The driver specified by This does not support
|
---|
282 | the language specified by Language.
|
---|
283 |
|
---|
284 | **/
|
---|
285 | EFI_STATUS
|
---|
286 | EFIAPI
|
---|
287 | VmwSvga3VideoComponentNameGetDriverName (
|
---|
288 | IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
---|
289 | IN CHAR8 *Language,
|
---|
290 | OUT CHAR16 **DriverName
|
---|
291 | );
|
---|
292 |
|
---|
293 | /**
|
---|
294 | Retrieves a Unicode string that is the user readable name of the controller
|
---|
295 | that is being managed by a driver.
|
---|
296 |
|
---|
297 | This function retrieves the user readable name of the controller specified by
|
---|
298 | ControllerHandle and ChildHandle in the form of a Unicode string. If the
|
---|
299 | driver specified by This has a user readable name in the language specified by
|
---|
300 | Language, then a pointer to the controller name is returned in ControllerName,
|
---|
301 | and EFI_SUCCESS is returned. If the driver specified by This is not currently
|
---|
302 | managing the controller specified by ControllerHandle and ChildHandle,
|
---|
303 | then EFI_UNSUPPORTED is returned. If the driver specified by This does not
|
---|
304 | support the language specified by Language, then EFI_UNSUPPORTED is returned.
|
---|
305 |
|
---|
306 | @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
|
---|
307 | EFI_COMPONENT_NAME_PROTOCOL instance.
|
---|
308 |
|
---|
309 | @param ControllerHandle[in] The handle of a controller that the driver
|
---|
310 | specified by This is managing. This handle
|
---|
311 | specifies the controller whose name is to be
|
---|
312 | returned.
|
---|
313 |
|
---|
314 | @param ChildHandle[in] The handle of the child controller to retrieve
|
---|
315 | the name of. This is an optional parameter that
|
---|
316 | may be NULL. It will be NULL for device
|
---|
317 | drivers. It will also be NULL for a bus drivers
|
---|
318 | that wish to retrieve the name of the bus
|
---|
319 | controller. It will not be NULL for a bus
|
---|
320 | driver that wishes to retrieve the name of a
|
---|
321 | child controller.
|
---|
322 |
|
---|
323 | @param Language[in] A pointer to a Null-terminated ASCII string
|
---|
324 | array indicating the language. This is the
|
---|
325 | language of the driver name that the caller is
|
---|
326 | requesting, and it must match one of the
|
---|
327 | languages specified in SupportedLanguages. The
|
---|
328 | number of languages supported by a driver is up
|
---|
329 | to the driver writer. Language is specified in
|
---|
330 | RFC 4646 or ISO 639-2 language code format.
|
---|
331 |
|
---|
332 | @param ControllerName[out] A pointer to the Unicode string to return.
|
---|
333 | This Unicode string is the name of the
|
---|
334 | controller specified by ControllerHandle and
|
---|
335 | ChildHandle in the language specified by
|
---|
336 | Language from the point of view of the driver
|
---|
337 | specified by This.
|
---|
338 |
|
---|
339 | @retval EFI_SUCCESS The Unicode string for the user readable name in
|
---|
340 | the language specified by Language for the
|
---|
341 | driver specified by This was returned in
|
---|
342 | DriverName.
|
---|
343 |
|
---|
344 | @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
|
---|
345 |
|
---|
346 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
|
---|
347 | EFI_HANDLE.
|
---|
348 |
|
---|
349 | @retval EFI_INVALID_PARAMETER Language is NULL.
|
---|
350 |
|
---|
351 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.
|
---|
352 |
|
---|
353 | @retval EFI_UNSUPPORTED The driver specified by This is not currently
|
---|
354 | managing the controller specified by
|
---|
355 | ControllerHandle and ChildHandle.
|
---|
356 |
|
---|
357 | @retval EFI_UNSUPPORTED The driver specified by This does not support
|
---|
358 | the language specified by Language.
|
---|
359 |
|
---|
360 | **/
|
---|
361 | EFI_STATUS
|
---|
362 | EFIAPI
|
---|
363 | VmwSvga3VideoComponentNameGetControllerName (
|
---|
364 | IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
---|
365 | IN EFI_HANDLE ControllerHandle,
|
---|
366 | IN EFI_HANDLE ChildHandle OPTIONAL,
|
---|
367 | IN CHAR8 *Language,
|
---|
368 | OUT CHAR16 **ControllerName
|
---|
369 | );
|
---|
370 |
|
---|
371 | //
|
---|
372 | // Local Function Prototypes
|
---|
373 | //
|
---|
374 | EFI_STATUS
|
---|
375 | VmwSvga3VideoModeSetup (
|
---|
376 | VMWSVGA3_VIDEO_PRIVATE_DATA *Private
|
---|
377 | );
|
---|
378 |
|
---|
379 | UINT32
|
---|
380 | VmwSvga3ReadReg (
|
---|
381 | IN VMWSVGA3_VIDEO_PRIVATE_DATA *VmwSvga3,
|
---|
382 | IN UINT32 Offset
|
---|
383 | );
|
---|
384 |
|
---|
385 | VOID
|
---|
386 | VmwSvga3WriteReg (
|
---|
387 | IN VMWSVGA3_VIDEO_PRIVATE_DATA *VmwSvga3,
|
---|
388 | IN UINT32 Offset,
|
---|
389 | IN UINT32 Data
|
---|
390 | );
|
---|
391 |
|
---|
392 | EFI_STATUS
|
---|
393 | VmwSvga3DeviceInit (
|
---|
394 | IN VMWSVGA3_VIDEO_PRIVATE_DATA *This
|
---|
395 | );
|
---|
396 |
|
---|
397 | EFI_STATUS
|
---|
398 | VmwSvga3DeviceUninit (
|
---|
399 | IN VMWSVGA3_VIDEO_PRIVATE_DATA *This
|
---|
400 | );
|
---|
401 |
|
---|
402 | EFI_STATUS
|
---|
403 | VmwSvga3CmdBufProcess (
|
---|
404 | IN VMWSVGA3_VIDEO_PRIVATE_DATA *This,
|
---|
405 | IN UINTN NumberOfBytes,
|
---|
406 | IN UINT32 Context
|
---|
407 | );
|
---|
408 |
|
---|
409 | #endif
|
---|