Copyright (C) 2016, Red Hat, Inc.\r
Copyright (c) 2017, AMD Inc, All rights reserved.<BR>\r
\r
- This program and the accompanying materials are licensed and made available\r
- under the terms and conditions of the BSD License which accompanies this\r
- distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
- WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
//\r
// We only want the most basic 2D features.\r
//\r
- Features &= VIRTIO_F_VERSION_1;\r
+ Features &= VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM;\r
\r
//\r
// ... and write the subset of feature bits understood by the [...] driver to\r
VirtioRingUninit (VgpuDev->VirtIo, &VgpuDev->Ring);\r
}\r
\r
+/**\r
+ Allocate, zero and map memory, for bus master common buffer operation, to be\r
+ attached as backing store to a host-side VirtIo GPU resource.\r
+\r
+ @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r
+ device.\r
+\r
+ @param[in] NumberOfPages The number of whole pages to allocate and map.\r
+\r
+ @param[out] HostAddress The system memory address of the allocated area.\r
+\r
+ @param[out] DeviceAddress The bus master device address of the allocated\r
+ area. The VirtIo GPU device may be programmed to\r
+ access the allocated area through DeviceAddress;\r
+ DeviceAddress is to be passed to the\r
+ VirtioGpuResourceAttachBacking() function, as the\r
+ BackingStoreDeviceAddress parameter.\r
+\r
+ @param[out] Mapping A resulting token to pass to\r
+ VirtioGpuUnmapAndFreeBackingStore().\r
+\r
+ @retval EFI_SUCCESS The requested number of pages has been allocated, zeroed\r
+ and mapped.\r
+\r
+ @return Status codes propagated from\r
+ VgpuDev->VirtIo->AllocateSharedPages() and\r
+ VirtioMapAllBytesInSharedBuffer().\r
+**/\r
+EFI_STATUS\r
+VirtioGpuAllocateZeroAndMapBackingStore (\r
+ IN VGPU_DEV *VgpuDev,\r
+ IN UINTN NumberOfPages,\r
+ OUT VOID **HostAddress,\r
+ OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
+ OUT VOID **Mapping\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ VOID *NewHostAddress;\r
+\r
+ Status = VgpuDev->VirtIo->AllocateSharedPages (\r
+ VgpuDev->VirtIo,\r
+ NumberOfPages,\r
+ &NewHostAddress\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Avoid exposing stale data to the device even temporarily: zero the area\r
+ // before mapping it.\r
+ //\r
+ ZeroMem (NewHostAddress, EFI_PAGES_TO_SIZE (NumberOfPages));\r
+\r
+ Status = VirtioMapAllBytesInSharedBuffer (\r
+ VgpuDev->VirtIo, // VirtIo\r
+ VirtioOperationBusMasterCommonBuffer, // Operation\r
+ NewHostAddress, // HostAddress\r
+ EFI_PAGES_TO_SIZE (NumberOfPages), // NumberOfBytes\r
+ DeviceAddress, // DeviceAddress\r
+ Mapping // Mapping\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto FreeSharedPages;\r
+ }\r
+\r
+ *HostAddress = NewHostAddress;\r
+ return EFI_SUCCESS;\r
+\r
+FreeSharedPages:\r
+ VgpuDev->VirtIo->FreeSharedPages (\r
+ VgpuDev->VirtIo,\r
+ NumberOfPages,\r
+ NewHostAddress\r
+ );\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Unmap and free memory originally allocated and mapped with\r
+ VirtioGpuAllocateZeroAndMapBackingStore().\r
+\r
+ If the memory allocated and mapped with\r
+ VirtioGpuAllocateZeroAndMapBackingStore() was attached to a host-side VirtIo\r
+ GPU resource with VirtioGpuResourceAttachBacking(), then the caller is\r
+ responsible for detaching the backing store from the same resource, with\r
+ VirtioGpuResourceDetachBacking(), before calling this function.\r
+\r
+ @param[in] VgpuDev The VGPU_DEV object that represents the VirtIo GPU\r
+ device.\r
+\r
+ @param[in] NumberOfPages The NumberOfPages parameter originally passed to\r
+ VirtioGpuAllocateZeroAndMapBackingStore().\r
+\r
+ @param[in] HostAddress The HostAddress value originally output by\r
+ VirtioGpuAllocateZeroAndMapBackingStore().\r
+\r
+ @param[in] Mapping The token that was originally output by\r
+ VirtioGpuAllocateZeroAndMapBackingStore().\r
+**/\r
+VOID\r
+VirtioGpuUnmapAndFreeBackingStore (\r
+ IN VGPU_DEV *VgpuDev,\r
+ IN UINTN NumberOfPages,\r
+ IN VOID *HostAddress,\r
+ IN VOID *Mapping\r
+ )\r
+{\r
+ VgpuDev->VirtIo->UnmapSharedBuffer (\r
+ VgpuDev->VirtIo,\r
+ Mapping\r
+ );\r
+ VgpuDev->VirtIo->FreeSharedPages (\r
+ VgpuDev->VirtIo,\r
+ NumberOfPages,\r
+ HostAddress\r
+ );\r
+}\r
+\r
/**\r
EFI_EVENT_NOTIFY function for the VGPU_DEV.ExitBoot event. It resets the\r
VirtIo device, causing it to release its resources and to forget its\r
{\r
VGPU_DEV *VgpuDev;\r
\r
+ DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __FUNCTION__, Context));\r
VgpuDev = Context;\r
VgpuDev->VirtIo->SetDeviceStatus (VgpuDev->VirtIo, 0);\r
- VgpuDev->VirtIo->UnmapSharedBuffer (VgpuDev->VirtIo, VgpuDev->RingMap);\r
}\r
\r
/**\r