VirtioGpu.h 14 KB

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