Declarations of utility functions used by virtio device drivers.\r
\r
Copyright (C) 2012-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
- 1.1 Virtqueues,\r
- 2.3 Virtqueue Configuration.\r
\r
+ @param[in] VirtIo The virtio device which will use the ring.\r
+\r
@param[in] The number of descriptors to allocate for the\r
virtio ring, as requested by the host.\r
\r
@param[out] Ring The virtio ring to set up.\r
\r
- @retval EFI_OUT_OF_RESOURCES AllocatePages() failed to allocate contiguous\r
- pages for the requested QueueSize. Fields of\r
- Ring have indeterminate value.\r
+ @return Status codes propagated from\r
+ VirtIo->AllocateSharedPages().\r
\r
@retval EFI_SUCCESS Allocation and setup successful. Ring->Base\r
(and nothing else) is responsible for\r
EFI_STATUS\r
EFIAPI\r
VirtioRingInit (\r
- IN UINT16 QueueSize,\r
- OUT VRING *Ring\r
+ IN VIRTIO_DEVICE_PROTOCOL *VirtIo,\r
+ IN UINT16 QueueSize,\r
+ OUT VRING *Ring\r
);\r
\r
\r
+/**\r
+\r
+ Map the ring buffer so that it can be accessed equally by both guest\r
+ and hypervisor.\r
+\r
+ @param[in] VirtIo The virtio device instance.\r
+\r
+ @param[in] Ring The virtio ring to map.\r
+\r
+ @param[out] RingBaseShift A resulting translation offset, to be\r
+ passed to VirtIo->SetQueueAddress().\r
+\r
+ @param[out] Mapping A resulting token to pass to\r
+ VirtIo->UnmapSharedBuffer().\r
+\r
+ @return Status code from VirtIo->MapSharedBuffer()\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioRingMap (\r
+ IN VIRTIO_DEVICE_PROTOCOL *VirtIo,\r
+ IN VRING *Ring,\r
+ OUT UINT64 *RingBaseShift,\r
+ OUT VOID **Mapping\r
+ );\r
+\r
/**\r
\r
Tear down the internal resources of a configured virtio ring.\r
invoking this function: the VSTAT_DRIVER_OK bit must be clear in\r
VhdrDeviceStatus.\r
\r
- @param[out] Ring The virtio ring to clean up.\r
+ @param[in] VirtIo The virtio device which was using the ring.\r
+\r
+ @param[out] Ring The virtio ring to clean up.\r
\r
**/\r
VOID\r
EFIAPI\r
VirtioRingUninit (\r
- IN OUT VRING *Ring\r
+ IN VIRTIO_DEVICE_PROTOCOL *VirtIo,\r
+ IN OUT VRING *Ring\r
);\r
\r
\r
The caller is responsible for initializing *Indices with VirtioPrepare()\r
first.\r
\r
- @param[in,out] Ring The virtio ring to append the buffer to, as a\r
- descriptor.\r
+ @param[in,out] Ring The virtio ring to append the buffer to,\r
+ as a descriptor.\r
\r
- @param[in] BufferPhysAddr (Guest pseudo-physical) start address of the\r
- transmit / receive buffer.\r
+ @param[in] BufferDeviceAddress (Bus master device) start address of the\r
+ transmit / receive buffer.\r
\r
- @param[in] BufferSize Number of bytes to transmit or receive.\r
+ @param[in] BufferSize Number of bytes to transmit or receive.\r
\r
- @param[in] Flags A bitmask of VRING_DESC_F_* flags. The caller\r
- computes this mask dependent on further buffers to\r
- append and transfer direction.\r
- VRING_DESC_F_INDIRECT is unsupported. The\r
- VRING_DESC.Next field is always set, but the host\r
- only interprets it dependent on VRING_DESC_F_NEXT.\r
+ @param[in] Flags A bitmask of VRING_DESC_F_* flags. The\r
+ caller computes this mask dependent on\r
+ further buffers to append and transfer\r
+ direction. VRING_DESC_F_INDIRECT is\r
+ unsupported. The VRING_DESC.Next field is\r
+ always set, but the host only interprets\r
+ it dependent on VRING_DESC_F_NEXT.\r
\r
- @param[in,out] Indices Indices->HeadDescIdx is not accessed.\r
- On input, Indices->NextDescIdx identifies the next\r
- descriptor to carry the buffer. On output,\r
- Indices->NextDescIdx is incremented by one, modulo\r
- 2^16.\r
+ @param[in,out] Indices Indices->HeadDescIdx is not accessed.\r
+ On input, Indices->NextDescIdx identifies\r
+ the next descriptor to carry the buffer.\r
+ On output, Indices->NextDescIdx is\r
+ incremented by one, modulo 2^16.\r
\r
**/\r
VOID\r
EFIAPI\r
VirtioAppendDesc (\r
IN OUT VRING *Ring,\r
- IN UINTN BufferPhysAddr,\r
+ IN UINT64 BufferDeviceAddress,\r
IN UINT32 BufferSize,\r
IN UINT16 Flags,\r
IN OUT DESC_INDICES *Indices\r
IN OUT UINT8 *DeviceStatus\r
);\r
\r
+/**\r
+ Provides the virtio device address required to access system memory from a\r
+ DMA bus master.\r
+\r
+ The interface follows the same usage pattern as defined in UEFI spec 2.6\r
+ (Section 13.2 PCI Root Bridge I/O Protocol)\r
+\r
+ The VirtioMapAllBytesInSharedBuffer() is similar to VIRTIO_MAP_SHARED\r
+ with exception that NumberOfBytes is IN-only parameter. The function\r
+ maps all the bytes specified in NumberOfBytes param in one consecutive\r
+ range.\r
+\r
+ @param[in] VirtIo The virtio device for which the mapping is\r
+ requested.\r
+\r
+ @param[in] Operation Indicates if the bus master is going to\r
+ read or write to system memory.\r
+\r
+ @param[in] HostAddress The system memory address to map to shared\r
+ buffer address.\r
+\r
+ @param[in] NumberOfBytes Number of bytes to map.\r
+\r
+ @param[out] DeviceAddress The resulting shared map address for the\r
+ bus master to access the hosts HostAddress.\r
+\r
+ @param[out] Mapping A resulting token to pass to\r
+ VIRTIO_UNMAP_SHARED.\r
+\r
+\r
+ @retval EFI_SUCCESS The NumberOfBytes is succesfully mapped.\r
+ @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a\r
+ common buffer.\r
+ @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to\r
+ a lack of resources. This includes the case\r
+ when NumberOfBytes bytes cannot be mapped\r
+ in one consecutive range.\r
+ @retval EFI_DEVICE_ERROR The system hardware could not map the\r
+ requested address.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioMapAllBytesInSharedBuffer (\r
+ IN VIRTIO_DEVICE_PROTOCOL *VirtIo,\r
+ IN VIRTIO_MAP_OPERATION Operation,\r
+ IN VOID *HostAddress,\r
+ IN UINTN NumberOfBytes,\r
+ OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
+ OUT VOID **Mapping\r
+ );\r
#endif // _VIRTIO_LIB_H_\r