Utility functions used by virtio device drivers.\r
\r
Copyright (C) 2012, Red Hat, Inc.\r
+ Portion of Copyright (C) 2013, ARM Ltd.\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
\r
**/\r
\r
-#include <IndustryStandard/Pci22.h>\r
#include <Library/BaseLib.h>\r
#include <Library/BaseMemoryLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/VirtioLib.h>\r
\r
\r
-/**\r
-\r
- Write a word into Region 0 of the device specified by PciIo.\r
-\r
- Region 0 must be an iomem region. This is an internal function for the\r
- driver-specific VIRTIO_CFG_WRITE() macros.\r
-\r
- @param[in] PciIo Target PCI device.\r
-\r
- @param[in] FieldOffset Destination offset.\r
-\r
- @param[in] FieldSize Destination field size, must be in { 1, 2, 4, 8 }.\r
-\r
- @param[in] Value Little endian value to write, converted to UINT64.\r
- The least significant FieldSize bytes will be used.\r
-\r
-\r
- @return Status code returned by PciIo->Io.Write().\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VirtioWrite (\r
- IN EFI_PCI_IO_PROTOCOL *PciIo,\r
- IN UINTN FieldOffset,\r
- IN UINTN FieldSize,\r
- IN UINT64 Value\r
- )\r
-{\r
- UINTN Count;\r
- EFI_PCI_IO_PROTOCOL_WIDTH Width;\r
-\r
- Count = 1;\r
- switch (FieldSize) {\r
- case 1:\r
- Width = EfiPciIoWidthUint8;\r
- break;\r
-\r
- case 2:\r
- Width = EfiPciIoWidthUint16;\r
- break;\r
-\r
- case 8:\r
- Count = 2;\r
- // fall through\r
-\r
- case 4:\r
- Width = EfiPciIoWidthUint32;\r
- break;\r
-\r
- default:\r
- ASSERT (FALSE);\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return PciIo->Io.Write (\r
- PciIo,\r
- Width,\r
- PCI_BAR_IDX0,\r
- FieldOffset,\r
- Count,\r
- &Value\r
- );\r
-}\r
-\r
-\r
-/**\r
-\r
- Read a word from Region 0 of the device specified by PciIo.\r
-\r
- Region 0 must be an iomem region. This is an internal function for the\r
- driver-specific VIRTIO_CFG_READ() macros.\r
-\r
- @param[in] PciIo Source PCI device.\r
-\r
- @param[in] FieldOffset Source offset.\r
-\r
- @param[in] FieldSize Source field size, must be in { 1, 2, 4, 8 }.\r
-\r
- @param[in] BufferSize Number of bytes available in the target buffer. Must\r
- equal FieldSize.\r
-\r
- @param[out] Buffer Target buffer.\r
-\r
-\r
- @return Status code returned by PciIo->Io.Read().\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VirtioRead (\r
- IN EFI_PCI_IO_PROTOCOL *PciIo,\r
- IN UINTN FieldOffset,\r
- IN UINTN FieldSize,\r
- IN UINTN BufferSize,\r
- OUT VOID *Buffer\r
- )\r
-{\r
- UINTN Count;\r
- EFI_PCI_IO_PROTOCOL_WIDTH Width;\r
-\r
- ASSERT (FieldSize == BufferSize);\r
-\r
- Count = 1;\r
- switch (FieldSize) {\r
- case 1:\r
- Width = EfiPciIoWidthUint8;\r
- break;\r
-\r
- case 2:\r
- Width = EfiPciIoWidthUint16;\r
- break;\r
-\r
- case 8:\r
- Count = 2;\r
- // fall through\r
-\r
- case 4:\r
- Width = EfiPciIoWidthUint32;\r
- break;\r
-\r
- default:\r
- ASSERT (FALSE);\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return PciIo->Io.Read (\r
- PciIo,\r
- Width,\r
- PCI_BAR_IDX0,\r
- FieldOffset,\r
- Count,\r
- Buffer\r
- );\r
-}\r
-\r
-\r
/**\r
\r
Configure a virtio ring.\r
Notify the host about the descriptor chain just built, and wait until the\r
host processes it.\r
\r
- @param[in] PciIo The target virtio PCI device to notify.\r
+ @param[in] VirtIo The target virtio device to notify.\r
\r
@param[in] VirtQueueId Identifies the queue for the target device.\r
\r
of the descriptor chain.\r
\r
\r
- @return Error code from VirtioWrite() if it fails.\r
+ @return Error code from VirtIo->SetQueueNotify() if it fails.\r
\r
@retval EFI_SUCCESS Otherwise, the host processed all descriptors.\r
\r
EFI_STATUS\r
EFIAPI\r
VirtioFlush (\r
- IN EFI_PCI_IO_PROTOCOL *PciIo,\r
- IN UINT16 VirtQueueId,\r
- IN OUT VRING *Ring,\r
- IN DESC_INDICES *Indices\r
+ IN VIRTIO_DEVICE_PROTOCOL *VirtIo,\r
+ IN UINT16 VirtQueueId,\r
+ IN OUT VRING *Ring,\r
+ IN DESC_INDICES *Indices\r
)\r
{\r
UINT16 NextAvailIdx;\r
// OK.\r
//\r
MemoryFence();\r
- Status = VirtioWrite (\r
- PciIo,\r
- OFFSET_OF (VIRTIO_HDR, VhdrQueueNotify),\r
- sizeof (UINT16),\r
- VirtQueueId\r
- );\r
+ Status = VirtIo->SetQueueNotify (VirtIo, VirtQueueId);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
MemoryFence();\r
}\r
\r
+ MemoryFence();\r
return EFI_SUCCESS;\r
}\r