summaryrefslogtreecommitdiff
path: root/OvmfPkg/Library
diff options
context:
space:
mode:
authorLeif Lindholm <leif.lindholm@linaro.org>2014-01-24 17:18:26 +0000
committerLeif Lindholm <leif.lindholm@linaro.org>2014-01-24 17:18:26 +0000
commite1e57aa891deef00276b26a4569802a5cd13ce92 (patch)
tree9061825c6c9f5c8bed33d5b2087101ce38f23fdf /OvmfPkg/Library
parent18110e987bb049e24ade0fb63b5577def8f99114 (diff)
parent04d965c0713468e055ef328f9f49903bc5944e54 (diff)
Merging uefi-next/linaro-release into masterHEADlinaro-uefi-2014.01master
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Diffstat (limited to 'OvmfPkg/Library')
-rw-r--r--OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c60
-rw-r--r--OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf7
-rw-r--r--OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiDxe.c92
-rw-r--r--OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c81
-rw-r--r--OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf54
-rw-r--r--OvmfPkg/Library/VirtioLib/VirtioLib.c16
-rw-r--r--OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c428
-rw-r--r--OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h294
-rw-r--r--OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c614
-rw-r--r--OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf85
10 files changed, 967 insertions, 764 deletions
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
index 7e5ea00bf..3c5963f31 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
@@ -1,6 +1,7 @@
/** @file
Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
+ Copyright (C) 2013, Red Hat, Inc.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -21,8 +22,6 @@
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
-STATIC BOOLEAN mQemuFwCfgSupported = FALSE;
-
/**
Reads an 8-bit I/O port fifo into a block of memory.
@@ -78,24 +77,6 @@ IoWriteFifo8 (
/**
- Returns a boolean indicating if the firmware configuration interface
- is available or not.
-
- @retval TRUE The interface is available
- @retval FALSE The interface is not available
-
-**/
-BOOLEAN
-EFIAPI
-QemuFwCfgIsAvailable (
- VOID
- )
-{
- return mQemuFwCfgSupported;
-}
-
-
-/**
Selects a firmware configuration item for reading.
Following this call, any data read from this item will start from
@@ -151,7 +132,7 @@ QemuFwCfgReadBytes (
IN VOID *Buffer
)
{
- if (mQemuFwCfgSupported) {
+ if (InternalQemuFwCfgIsAvailable ()) {
InternalQemuFwCfgReadBytes (Size, Buffer);
} else {
ZeroMem (Buffer, Size);
@@ -176,7 +157,7 @@ QemuFwCfgWriteBytes (
IN VOID *Buffer
)
{
- if (mQemuFwCfgSupported) {
+ if (InternalQemuFwCfgIsAvailable ()) {
IoWriteFifo8 (0x511, Size, Buffer);
}
}
@@ -262,39 +243,6 @@ QemuFwCfgRead64 (
}
-RETURN_STATUS
-EFIAPI
-QemuFwCfgInitialize (
- VOID
- )
-{
- UINT32 Signature;
- UINT32 Revision;
-
- //
- // Enable the access routines while probing to see if it is supported.
- //
- mQemuFwCfgSupported = TRUE;
-
- QemuFwCfgSelectItem (QemuFwCfgItemSignature);
- Signature = QemuFwCfgRead32 ();
- DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));
- QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
- Revision = QemuFwCfgRead32 ();
- DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));
- if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
- (Revision < 1)
- ) {
- DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));
- mQemuFwCfgSupported = FALSE;
- return RETURN_SUCCESS;
- }
-
- DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));
- return RETURN_SUCCESS;
-}
-
-
/**
Find the configuration item corresponding to the firmware configuration file.
@@ -319,7 +267,7 @@ QemuFwCfgFindFile (
UINT32 Count;
UINT32 Idx;
- if (!mQemuFwCfgSupported) {
+ if (!InternalQemuFwCfgIsAvailable ()) {
return RETURN_UNSUPPORTED;
}
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf
index a5446f0b9..071737ede 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf
@@ -1,5 +1,8 @@
## @file
#
+# Stateful, implicitly initialized fw_cfg library.
+#
+# Copyright (C) 2013, Red Hat, Inc.
# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
@@ -18,7 +21,7 @@
FILE_GUID = fdd53716-31e1-4acc-9007-8bd5d877c96f
MODULE_TYPE = BASE
VERSION_STRING = 1.0
- LIBRARY_CLASS = QemuFwCfgLib
+ LIBRARY_CLASS = QemuFwCfgLib|PEIM DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER
CONSTRUCTOR = QemuFwCfgInitialize
@@ -30,6 +33,7 @@
[Sources]
QemuFwCfgLib.c
+ QemuFwCfgPeiDxe.c
[Sources.IA32]
Ia32/IoLibExAsm.asm
@@ -49,5 +53,4 @@
DebugLib
IoLib
MemoryAllocationLib
- UefiBootServicesTableLib
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiDxe.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiDxe.c
new file mode 100644
index 000000000..f693cff29
--- /dev/null
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiDxe.c
@@ -0,0 +1,92 @@
+/** @file
+
+ Stateful and implicitly initialized fw_cfg library implementation.
+
+ Copyright (C) 2013, Red Hat, Inc.
+ Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/QemuFwCfgLib.h>
+
+STATIC BOOLEAN mQemuFwCfgSupported = FALSE;
+
+
+/**
+ Returns a boolean indicating if the firmware configuration interface
+ is available or not.
+
+ This function may change fw_cfg state.
+
+ @retval TRUE The interface is available
+ @retval FALSE The interface is not available
+
+**/
+BOOLEAN
+EFIAPI
+QemuFwCfgIsAvailable (
+ VOID
+ )
+{
+ return InternalQemuFwCfgIsAvailable ();
+}
+
+
+RETURN_STATUS
+EFIAPI
+QemuFwCfgInitialize (
+ VOID
+ )
+{
+ UINT32 Signature;
+ UINT32 Revision;
+
+ //
+ // Enable the access routines while probing to see if it is supported.
+ //
+ mQemuFwCfgSupported = TRUE;
+
+ QemuFwCfgSelectItem (QemuFwCfgItemSignature);
+ Signature = QemuFwCfgRead32 ();
+ DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));
+ QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
+ Revision = QemuFwCfgRead32 ();
+ DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));
+ if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
+ (Revision < 1)
+ ) {
+ DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));
+ mQemuFwCfgSupported = FALSE;
+ return RETURN_SUCCESS;
+ }
+
+ DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));
+ return RETURN_SUCCESS;
+}
+
+
+/**
+ Returns a boolean indicating if the firmware configuration interface is
+ available for library-internal purposes.
+
+ This function never changes fw_cfg state.
+
+ @retval TRUE The interface is available internally.
+ @retval FALSE The interface is not available internally.
+**/
+BOOLEAN
+EFIAPI
+InternalQemuFwCfgIsAvailable (
+ VOID
+ )
+{
+ return mQemuFwCfgSupported;
+}
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c
new file mode 100644
index 000000000..88c32ce89
--- /dev/null
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c
@@ -0,0 +1,81 @@
+/** @file
+
+ Stateless fw_cfg library implementation.
+
+ Clients must call QemuFwCfgIsAvailable() first.
+
+ Copyright (C) 2013, Red Hat, Inc.
+ Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/QemuFwCfgLib.h>
+
+
+/**
+ Returns a boolean indicating if the firmware configuration interface
+ is available or not.
+
+ This function may change fw_cfg state.
+
+ @retval TRUE The interface is available
+ @retval FALSE The interface is not available
+
+**/
+BOOLEAN
+EFIAPI
+QemuFwCfgIsAvailable (
+ VOID
+ )
+{
+ UINT32 Signature;
+ UINT32 Revision;
+
+ QemuFwCfgSelectItem (QemuFwCfgItemSignature);
+ Signature = QemuFwCfgRead32 ();
+ DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));
+ QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
+ Revision = QemuFwCfgRead32 ();
+ DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));
+ if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
+ (Revision < 1)
+ ) {
+ DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));
+ return FALSE;
+ }
+
+ DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));
+ return TRUE;
+}
+
+
+/**
+ Returns a boolean indicating if the firmware configuration interface is
+ available for library-internal purposes.
+
+ This function never changes fw_cfg state.
+
+ @retval TRUE The interface is available internally.
+ @retval FALSE The interface is not available internally.
+**/
+BOOLEAN
+EFIAPI
+InternalQemuFwCfgIsAvailable (
+ VOID
+ )
+{
+ //
+ // We always return TRUE, because the consumer of this library ought to have
+ // called QemuFwCfgIsAvailable before making other calls which would hit this
+ // path.
+ //
+ return TRUE;
+}
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf
new file mode 100644
index 000000000..71beacbaf
--- /dev/null
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf
@@ -0,0 +1,54 @@
+## @file
+#
+# Stateless fw_cfg library that must be queried before use.
+#
+# Copyright (C) 2013, Red Hat, Inc.
+# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = QemuFwCfgSecLib
+ FILE_GUID = 60a910e5-7443-413d-9a30-97e57497cd1b
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = QemuFwCfgLib|SEC
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ QemuFwCfgLib.c
+ QemuFwCfgSec.c
+
+[Sources.IA32]
+ Ia32/IoLibExAsm.asm
+ Ia32/IoLibExAsm.S
+
+[Sources.X64]
+ X64/IoLibExAsm.asm
+ X64/IoLibExAsm.S
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ IoLib
+ MemoryAllocationLib
+
diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.c b/OvmfPkg/Library/VirtioLib/VirtioLib.c
index 1550318d8..54cf225c9 100644
--- a/OvmfPkg/Library/VirtioLib/VirtioLib.c
+++ b/OvmfPkg/Library/VirtioLib/VirtioLib.c
@@ -3,7 +3,7 @@
Utility functions used by virtio device drivers.
Copyright (C) 2012, Red Hat, Inc.
- Portion of Copyright (C) 2013, ARM Ltd.
+ Portion of Copyright (C) 2013, ARM Ltd.
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
@@ -239,7 +239,7 @@ VirtioAppendDesc (
Notify the host about the descriptor chain just built, and wait until the
host processes it.
- @param[in] VirtIo The target virtio device to notify.
+ @param[in] VirtIo The target virtio device to notify.
@param[in] VirtQueueId Identifies the queue for the target device.
@@ -250,7 +250,7 @@ VirtioAppendDesc (
of the descriptor chain.
- @return Error code from VirtioWriteDevice() if it fails.
+ @return Error code from VirtIo->SetQueueNotify() if it fails.
@retval EFI_SUCCESS Otherwise, the host processed all descriptors.
@@ -258,10 +258,10 @@ VirtioAppendDesc (
EFI_STATUS
EFIAPI
VirtioFlush (
- IN VIRTIO_DEVICE_PROTOCOL *VirtIo,
- IN UINT16 VirtQueueId,
- IN OUT VRING *Ring,
- IN DESC_INDICES *Indices
+ IN VIRTIO_DEVICE_PROTOCOL *VirtIo,
+ IN UINT16 VirtQueueId,
+ IN OUT VRING *Ring,
+ IN DESC_INDICES *Indices
)
{
UINT16 NextAvailIdx;
@@ -290,7 +290,7 @@ VirtioFlush (
// OK.
//
MemoryFence();
- Status = VirtIo->SetQueueNotify (VirtIo, VirtQueueId);
+ Status = VirtIo->SetQueueNotify (VirtIo, VirtQueueId);
if (EFI_ERROR (Status)) {
return Status;
}
diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
index f763db5fb..4af9dd0ac 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
@@ -1,204 +1,224 @@
-/** @file
-
- This driver produces Virtio Device Protocol instances for Virtio Mmio devices.
-
- Copyright (C) 2013, ARM Ltd.
-
- This program and the accompanying materials are licensed and made available
- under the terms and conditions of the BSD License which accompanies this
- distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
-
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
- WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-
-#include "VirtioMmioDevice.h"
-
-static VIRTIO_DEVICE_PROTOCOL mMmioDeviceProtocolTemplate = {
- 0, // Revision
- 0, // SubSystemDeviceId
- VirtioMmioGetDeviceFeatures, // GetDeviceFeatures
- VirtioMmioSetGuestFeatures, // SetGuestFeatures
- VirtioMmioGetQueueAddress, // GetQueueAddress
- VirtioMmioSetQueueAddress, // SetQueueAddress
- VirtioMmioSetQueueSel, // SetQueueSel
- VirtioMmioSetQueueNotify, // SetQueueNotify
- VirtioMmioSetQueueAlignment, // SetQueueAlign
- VirtioMmioSetPageSize, // SetPageSize
- VirtioMmioGetQueueSize, // GetQueueNumMax
- VirtioMmioSetQueueSize, // SetQueueNum
- VirtioMmioGetDeviceStatus, // GetDeviceStatus
- VirtioMmioSetDeviceStatus, // SetDeviceStatus
- VirtioMmioDeviceWrite, // WriteDevice
- VirtioMmioDeviceRead // ReadDevice
-};
-
-/**
-
- Initialize the VirtIo MMIO Device
-
- @param[in] BaseAddress Base Address of the VirtIo MMIO Device
-
- @param[in, out] Device The driver instance to configure.
-
- @retval EFI_SUCCESS Setup complete.
-
- @retval EFI_UNSUPPORTED The driver is not a VirtIo MMIO device.
-
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-VirtioMmioInit (
- IN PHYSICAL_ADDRESS BaseAddress,
- IN OUT VIRTIO_MMIO_DEVICE *Device
- )
-{
- UINT32 MagicValue;
- UINT32 VendorId;
- UINT32 Version;
-
- // Initialize VirtIo Mmio Device
- CopyMem (&Device->VirtioDevice, &mMmioDeviceProtocolTemplate,
- sizeof (VIRTIO_DEVICE_PROTOCOL));
- Device->BaseAddress = BaseAddress;
- Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (0, 9, 5);
- Device->VirtioDevice.SubSystemDeviceId =
- MmioRead32 (BaseAddress + VIRTIO_MMIO_OFFSET_DEVICE_ID);
-
- // Double-check MMIO-specific values
- MagicValue = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_MAGIC);
- if (MagicValue != VIRTIO_MMIO_MAGIC) {
- return EFI_UNSUPPORTED;
- }
-
- Version = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_VERSION);
- if (Version != 1) {
- return EFI_UNSUPPORTED;
- }
-
- // Double-check MMIO-specific values
- VendorId = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_VENDOR_ID);
- if (VendorId != VIRTIO_VENDOR_ID) {
- // The ARM Base and Foundation Models do not report a valid VirtIo VendorId.
- // They return a value of 0x0 for the VendorId.
- DEBUG((EFI_D_WARN, "VirtioMmioInit: Warning: The VendorId (0x%X) does not "
- "match the VirtIo VendorId (0x%X).\n",
- VendorId, VIRTIO_VENDOR_ID));
- //return EFI_UNSUPPORTED;
- }
-
- return EFI_SUCCESS;
-}
-
-
-/**
-
- Uninitialize the internals of a virtio-mmio device that has been successfully
- set up with VirtioMmioInit().
-
- @param[in, out] Device The device to clean up.
-
-**/
-
-STATIC
-VOID
-EFIAPI
-VirtioMmioUninit (
- IN VIRTIO_MMIO_DEVICE *Device
- )
-{
- // Note: This function mirrors VirtioMmioInit() that does not allocate any
- // resources - there's nothing to free here.
-}
-
-EFI_STATUS
-VirtioMmioInstallDevice (
- IN PHYSICAL_ADDRESS BaseAddress,
- IN EFI_HANDLE Handle
- )
-{
- EFI_STATUS Status;
- VIRTIO_MMIO_DEVICE *VirtIo;
-
- if (!BaseAddress) {
- return EFI_INVALID_PARAMETER;
- }
- if (Handle == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- // Allocate VIRTIO_MMIO_DEVICE
- VirtIo = AllocateZeroPool (sizeof (VIRTIO_MMIO_DEVICE));
- if (VirtIo == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- VirtIo->Signature = VIRTIO_MMIO_DEVICE_SIGNATURE;
-
- Status = VirtioMmioInit (BaseAddress, VirtIo);
- if (EFI_ERROR (Status)) {
- goto FreeVirtioMem;
- }
-
- // Install VIRTIO_DEVICE_PROTOCOL to Handle
- Status = gBS->InstallProtocolInterface (&Handle,
- &gVirtioDeviceProtocolGuid, EFI_NATIVE_INTERFACE,
- &VirtIo->VirtioDevice);
- if (EFI_ERROR (Status)) {
- goto UninitVirtio;
- }
-
- return EFI_SUCCESS;
-
-UninitVirtio:
- VirtioMmioUninit (VirtIo);
-
-FreeVirtioMem:
- FreePool (VirtIo);
- return Status;
-}
-
-EFI_STATUS
-VirtioMmioUninstallDevice (
- IN EFI_HANDLE DeviceHandle
- )
-{
- VIRTIO_DEVICE_PROTOCOL *VirtioDevice;
- VIRTIO_MMIO_DEVICE *MmioDevice;
- EFI_STATUS Status;
-
- Status = gBS->OpenProtocol (
- DeviceHandle, // candidate device
- &gVirtioDeviceProtocolGuid, // retrieve the VirtIo iface
- (VOID **)&VirtioDevice, // target pointer
- DeviceHandle, // requestor driver identity
- DeviceHandle, // requesting lookup for dev.
- EFI_OPEN_PROTOCOL_GET_PROTOCOL // lookup only, no ref. added
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- // Get the MMIO device from the VirtIo Device instance
- MmioDevice = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (VirtioDevice);
-
- // Uninstall the protocol interface
- Status = gBS->UninstallProtocolInterface (DeviceHandle,
- &gVirtioDeviceProtocolGuid, &MmioDevice->VirtioDevice
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- // Uninitialize the VirtIo Device
- VirtioMmioUninit (MmioDevice);
-
- return EFI_SUCCESS;
-}
+/** @file
+
+ This driver produces Virtio Device Protocol instances for Virtio Mmio devices.
+
+ Copyright (C) 2013, ARM Ltd.
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include "VirtioMmioDevice.h"
+
+static VIRTIO_DEVICE_PROTOCOL mMmioDeviceProtocolTemplate = {
+ 0, // Revision
+ 0, // SubSystemDeviceId
+ VirtioMmioGetDeviceFeatures, // GetDeviceFeatures
+ VirtioMmioSetGuestFeatures, // SetGuestFeatures
+ VirtioMmioGetQueueAddress, // GetQueueAddress
+ VirtioMmioSetQueueAddress, // SetQueueAddress
+ VirtioMmioSetQueueSel, // SetQueueSel
+ VirtioMmioSetQueueNotify, // SetQueueNotify
+ VirtioMmioSetQueueAlignment, // SetQueueAlign
+ VirtioMmioSetPageSize, // SetPageSize
+ VirtioMmioGetQueueSize, // GetQueueNumMax
+ VirtioMmioSetQueueSize, // SetQueueNum
+ VirtioMmioGetDeviceStatus, // GetDeviceStatus
+ VirtioMmioSetDeviceStatus, // SetDeviceStatus
+ VirtioMmioDeviceWrite, // WriteDevice
+ VirtioMmioDeviceRead // ReadDevice
+};
+
+/**
+
+ Initialize the VirtIo MMIO Device
+
+ @param[in] BaseAddress Base Address of the VirtIo MMIO Device
+
+ @param[in, out] Device The driver instance to configure.
+
+ @retval EFI_SUCCESS Setup complete.
+
+ @retval EFI_UNSUPPORTED The driver is not a VirtIo MMIO device.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+VirtioMmioInit (
+ IN PHYSICAL_ADDRESS BaseAddress,
+ IN OUT VIRTIO_MMIO_DEVICE *Device
+ )
+{
+ UINT32 MagicValue;
+ UINT32 VendorId;
+ UINT32 Version;
+
+ //
+ // Initialize VirtIo Mmio Device
+ //
+ CopyMem (&Device->VirtioDevice, &mMmioDeviceProtocolTemplate,
+ sizeof (VIRTIO_DEVICE_PROTOCOL));
+ Device->BaseAddress = BaseAddress;
+ Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (0, 9, 5);
+ Device->VirtioDevice.SubSystemDeviceId =
+ MmioRead32 (BaseAddress + VIRTIO_MMIO_OFFSET_DEVICE_ID);
+
+ //
+ // Double-check MMIO-specific values
+ //
+ MagicValue = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_MAGIC);
+ if (MagicValue != VIRTIO_MMIO_MAGIC) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Version = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_VERSION);
+ if (Version != 1) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Double-check MMIO-specific values
+ //
+ VendorId = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_VENDOR_ID);
+ if (VendorId != VIRTIO_VENDOR_ID) {
+ //
+ // The ARM Base and Foundation Models do not report a valid VirtIo VendorId.
+ // They return a value of 0x0 for the VendorId.
+ //
+ DEBUG((EFI_D_WARN, "VirtioMmioInit: Warning: The VendorId (0x%X) does not "
+ "match the VirtIo VendorId (0x%X).\n",
+ VendorId, VIRTIO_VENDOR_ID));
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+/**
+
+ Uninitialize the internals of a virtio-mmio device that has been successfully
+ set up with VirtioMmioInit().
+
+ @param[in, out] Device The device to clean up.
+
+**/
+
+STATIC
+VOID
+EFIAPI
+VirtioMmioUninit (
+ IN VIRTIO_MMIO_DEVICE *Device
+ )
+{
+ //
+ // Note: This function mirrors VirtioMmioInit() that does not allocate any
+ // resources - there's nothing to free here.
+ //
+}
+
+EFI_STATUS
+VirtioMmioInstallDevice (
+ IN PHYSICAL_ADDRESS BaseAddress,
+ IN EFI_HANDLE Handle
+ )
+{
+ EFI_STATUS Status;
+ VIRTIO_MMIO_DEVICE *VirtIo;
+
+ if (!BaseAddress) {
+ return EFI_INVALID_PARAMETER;
+ }
+ if (Handle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Allocate VIRTIO_MMIO_DEVICE
+ //
+ VirtIo = AllocateZeroPool (sizeof (VIRTIO_MMIO_DEVICE));
+ if (VirtIo == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ VirtIo->Signature = VIRTIO_MMIO_DEVICE_SIGNATURE;
+
+ Status = VirtioMmioInit (BaseAddress, VirtIo);
+ if (EFI_ERROR (Status)) {
+ goto FreeVirtioMem;
+ }
+
+ //
+ // Install VIRTIO_DEVICE_PROTOCOL to Handle
+ //
+ Status = gBS->InstallProtocolInterface (&Handle,
+ &gVirtioDeviceProtocolGuid, EFI_NATIVE_INTERFACE,
+ &VirtIo->VirtioDevice);
+ if (EFI_ERROR (Status)) {
+ goto UninitVirtio;
+ }
+
+ return EFI_SUCCESS;
+
+UninitVirtio:
+ VirtioMmioUninit (VirtIo);
+
+FreeVirtioMem:
+ FreePool (VirtIo);
+ return Status;
+}
+
+EFI_STATUS
+VirtioMmioUninstallDevice (
+ IN EFI_HANDLE DeviceHandle
+ )
+{
+ VIRTIO_DEVICE_PROTOCOL *VirtioDevice;
+ VIRTIO_MMIO_DEVICE *MmioDevice;
+ EFI_STATUS Status;
+
+ Status = gBS->OpenProtocol (
+ DeviceHandle, // candidate device
+ &gVirtioDeviceProtocolGuid, // retrieve the VirtIo iface
+ (VOID **)&VirtioDevice, // target pointer
+ DeviceHandle, // requestor driver identity
+ DeviceHandle, // requesting lookup for dev.
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL // lookup only, no ref. added
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Get the MMIO device from the VirtIo Device instance
+ //
+ MmioDevice = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (VirtioDevice);
+
+ //
+ // Uninstall the protocol interface
+ //
+ Status = gBS->UninstallProtocolInterface (DeviceHandle,
+ &gVirtioDeviceProtocolGuid, &MmioDevice->VirtioDevice
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Uninitialize the VirtIo Device
+ //
+ VirtioMmioUninit (MmioDevice);
+ FreePool (MmioDevice);
+
+ return EFI_SUCCESS;
+}
diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
index 188d873ae..3e4e5606c 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
@@ -1,147 +1,147 @@
-/** @file
-
- Internal definitions for the VirtIo MMIO Device driver
-
- Copyright (C) 2013, ARM Ltd
-
- This program and the accompanying materials are licensed and made available
- under the terms and conditions of the BSD License which accompanies this
- distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
-
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
- WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#ifndef _VIRTIO_MMIO_DEVICE_INTERNAL_H_
-#define _VIRTIO_MMIO_DEVICE_INTERNAL_H_
-
-#include <Protocol/VirtioDevice.h>
-
-#include <IndustryStandard/Virtio.h>
-
-#include <Library/DebugLib.h>
-#include <Library/IoLib.h>
-#include <Library/UefiLib.h>
-#include <Library/VirtioMmioDeviceLib.h>
-
-#define VIRTIO_MMIO_DEVICE_SIGNATURE SIGNATURE_32 ('V', 'M', 'I', 'O')
-
-typedef struct {
- UINT32 Signature;
- VIRTIO_DEVICE_PROTOCOL VirtioDevice;
- PHYSICAL_ADDRESS BaseAddress;
-} VIRTIO_MMIO_DEVICE;
-
-#define VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE(Device) \
- CR (Device, VIRTIO_MMIO_DEVICE, VirtioDevice, VIRTIO_MMIO_DEVICE_SIGNATURE)
-
-#define VIRTIO_CFG_WRITE(Device, Offset, Val) \
- (MmioWrite32 (Device->BaseAddress + (Offset), Val))
-#define VIRTIO_CFG_READ(Device, Offset) \
- (MmioRead32 (Device->BaseAddress + (Offset)))
-
-EFI_STATUS
-EFIAPI
-VirtioMmioDeviceRead (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINTN FieldOFfset,
- IN UINTN FieldSize,
- IN UINTN BufferSize,
- OUT VOID* Buffer
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioDeviceWrite (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINT64 Value
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioGetDeviceFeatures (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT32 *DeviceFeatures
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioGetQueueAddress (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT32 *QueueAddress
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioGetQueueSize (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT16 *QueueNumMax
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioGetDeviceStatus (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT8 *DeviceStatus
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetQueueSize (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 QueueSize
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetDeviceStatus (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT8 DeviceStatus
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetQueueNotify (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 QueueNotify
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetQueueSel (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 Sel
- );
-
-EFI_STATUS
-VirtioMmioSetQueueAddress (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Address
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetQueueAlignment (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Alignment
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetPageSize (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 PageSize
- );
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetGuestFeatures (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Features
- );
-
-#endif // _VIRTIO_MMIO_DEVICE_INTERNAL_H_
+/** @file
+
+ Internal definitions for the VirtIo MMIO Device driver
+
+ Copyright (C) 2013, ARM Ltd
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _VIRTIO_MMIO_DEVICE_INTERNAL_H_
+#define _VIRTIO_MMIO_DEVICE_INTERNAL_H_
+
+#include <Protocol/VirtioDevice.h>
+
+#include <IndustryStandard/Virtio.h>
+
+#include <Library/DebugLib.h>
+#include <Library/IoLib.h>
+#include <Library/UefiLib.h>
+#include <Library/VirtioMmioDeviceLib.h>
+
+#define VIRTIO_MMIO_DEVICE_SIGNATURE SIGNATURE_32 ('V', 'M', 'I', 'O')
+
+typedef struct {
+ UINT32 Signature;
+ VIRTIO_DEVICE_PROTOCOL VirtioDevice;
+ PHYSICAL_ADDRESS BaseAddress;
+} VIRTIO_MMIO_DEVICE;
+
+#define VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE(Device) \
+ CR (Device, VIRTIO_MMIO_DEVICE, VirtioDevice, VIRTIO_MMIO_DEVICE_SIGNATURE)
+
+#define VIRTIO_CFG_WRITE(Device, Offset, Val) \
+ (MmioWrite32 (Device->BaseAddress + (Offset), Val))
+#define VIRTIO_CFG_READ(Device, Offset) \
+ (MmioRead32 (Device->BaseAddress + (Offset)))
+
+EFI_STATUS
+EFIAPI
+VirtioMmioDeviceRead (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINTN FieldOFfset,
+ IN UINTN FieldSize,
+ IN UINTN BufferSize,
+ OUT VOID* Buffer
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioDeviceWrite (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINT64 Value
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioGetDeviceFeatures (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT32 *DeviceFeatures
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioGetQueueAddress (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT32 *QueueAddress
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioGetQueueSize (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT16 *QueueNumMax
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioGetDeviceStatus (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT8 *DeviceStatus
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetQueueSize (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 QueueSize
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetDeviceStatus (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT8 DeviceStatus
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetQueueNotify (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 QueueNotify
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetQueueSel (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 Sel
+ );
+
+EFI_STATUS
+VirtioMmioSetQueueAddress (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 Address
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetQueueAlignment (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 Alignment
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetPageSize (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 PageSize
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetGuestFeatures (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 Features
+ );
+
+#endif // _VIRTIO_MMIO_DEVICE_INTERNAL_H_
diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
index fa76f8ffc..3950c07f7 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
@@ -1,304 +1,310 @@
-/** @file
-
- This driver produces Virtio Device Protocol instances for Virtio MMIO devices.
-
- Copyright (C) 2012, Red Hat, Inc.
- Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
- Copyright (C) 2013, ARM Ltd.
-
- This program and the accompanying materials are licensed and made available
- under the terms and conditions of the BSD License which accompanies this
- distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
-
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
- WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "VirtioMmioDevice.h"
-
-EFI_STATUS
-EFIAPI
-VirtioMmioGetDeviceFeatures (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT32 *DeviceFeatures
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- if (DeviceFeatures == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- *DeviceFeatures = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioGetQueueAddress (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT32 *QueueAddress
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- if (QueueAddress == NULL) {
-
- }
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- *QueueAddress = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioGetQueueSize (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT16 *QueueNumMax
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- if (QueueNumMax == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- *QueueNumMax = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM_MAX) & 0xFFFF;
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioGetDeviceStatus (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT8 *DeviceStatus
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- if (DeviceStatus == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- *DeviceStatus = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_STATUS) & 0xFF;
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetQueueSize (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 QueueSize
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM, QueueSize);
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetDeviceStatus (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT8 DeviceStatus
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_STATUS, DeviceStatus);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetQueueNotify (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 QueueNotify
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NOTIFY, QueueNotify);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetQueueAlignment (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Alignment
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_ALIGN, Alignment);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetPageSize (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 PageSize
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- ASSERT (PageSize == EFI_PAGE_SIZE);
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_PAGE_SIZE, PageSize);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetQueueSel (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 Sel
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_SEL, Sel);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-VirtioMmioSetQueueAddress (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Address
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN, Address);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioSetGuestFeatures (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Features
- )
-{
- VIRTIO_MMIO_DEVICE *Device;
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES, Features);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioDeviceWrite (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINT64 Value
- )
-{
- UINTN DstBaseAddress;
- VIRTIO_MMIO_DEVICE *Device;
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- // Double-check fieldsize
- if (FieldSize > 8) {
- return EFI_INVALID_PARAMETER;
- }
-
- if ((FieldSize != 1) && (FieldSize != 2) &&
- (FieldSize != 4) && (FieldSize != 8)) {
- return EFI_INVALID_PARAMETER;
- }
-
- // Compute base address
- DstBaseAddress = Device->BaseAddress +
- VIRTIO_DEVICE_SPECIFIC_CONFIGURATION_OFFSET_MMIO + FieldOffset;
-
- //
- // The device-specific memory area of Virtio-MMIO can only be written in
- // byte accesses. This is not currently in the Virtio spec.
- //
- MmioWriteBuffer8 (DstBaseAddress, FieldSize, (UINT8*)&Value);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioMmioDeviceRead (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINTN BufferSize,
- OUT VOID *Buffer
- )
-{
- UINTN SrcBaseAddress;
- VIRTIO_MMIO_DEVICE *Device;
-
- Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- // Parameter validation
- ASSERT (FieldSize == BufferSize);
-
- // Double-check fieldsize
- if (FieldSize > 8) {
- return EFI_INVALID_PARAMETER;
- }
-
- if ((FieldSize != 1) && (FieldSize != 2) &&
- (FieldSize != 4) && (FieldSize != 8)) {
- return EFI_INVALID_PARAMETER;
- }
-
- // Compute base address
- SrcBaseAddress = Device->BaseAddress +
- VIRTIO_DEVICE_SPECIFIC_CONFIGURATION_OFFSET_MMIO + FieldOffset;
-
- //
- // The device-specific memory area of Virtio-MMIO can only be read in
- // byte reads. This is not currently in the Virtio spec.
- //
- MmioReadBuffer8 (SrcBaseAddress, BufferSize, Buffer);
-
- return EFI_SUCCESS;
-}
+/** @file
+
+ This driver produces Virtio Device Protocol instances for Virtio MMIO devices.
+
+ Copyright (C) 2012, Red Hat, Inc.
+ Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (C) 2013, ARM Ltd.
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "VirtioMmioDevice.h"
+
+EFI_STATUS
+EFIAPI
+VirtioMmioGetDeviceFeatures (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT32 *DeviceFeatures
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ if (DeviceFeatures == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ *DeviceFeatures = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioGetQueueAddress (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT32 *QueueAddress
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ if (QueueAddress == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ *QueueAddress = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioGetQueueSize (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT16 *QueueNumMax
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ if (QueueNumMax == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ *QueueNumMax = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM_MAX) & 0xFFFF;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioGetDeviceStatus (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT8 *DeviceStatus
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ if (DeviceStatus == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ *DeviceStatus = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_STATUS) & 0xFF;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetQueueSize (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 QueueSize
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NUM, QueueSize);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetDeviceStatus (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT8 DeviceStatus
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_STATUS, DeviceStatus);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetQueueNotify (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 QueueNotify
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_NOTIFY, QueueNotify);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetQueueAlignment (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 Alignment
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_ALIGN, Alignment);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetPageSize (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 PageSize
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ if (PageSize != EFI_PAGE_SIZE) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_PAGE_SIZE, PageSize);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetQueueSel (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 Sel
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_SEL, Sel);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+VirtioMmioSetQueueAddress (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 Address
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN, Address);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioSetGuestFeatures (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 Features
+ )
+{
+ VIRTIO_MMIO_DEVICE *Device;
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES, Features);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioDeviceWrite (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINT64 Value
+ )
+{
+ UINTN DstBaseAddress;
+ VIRTIO_MMIO_DEVICE *Device;
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ //
+ // Double-check fieldsize
+ //
+ if ((FieldSize != 1) && (FieldSize != 2) &&
+ (FieldSize != 4) && (FieldSize != 8)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Compute base address
+ //
+ DstBaseAddress = Device->BaseAddress +
+ VIRTIO_DEVICE_SPECIFIC_CONFIGURATION_OFFSET_MMIO + FieldOffset;
+
+ //
+ // The device-specific memory area of Virtio-MMIO can only be written in
+ // byte accesses. This is not currently in the Virtio spec.
+ //
+ MmioWriteBuffer8 (DstBaseAddress, FieldSize, (UINT8*)&Value);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioMmioDeviceRead (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ )
+{
+ UINTN SrcBaseAddress;
+ VIRTIO_MMIO_DEVICE *Device;
+
+ Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ //
+ // Parameter validation
+ //
+ ASSERT (FieldSize == BufferSize);
+
+ //
+ // Double-check fieldsize
+ //
+ if ((FieldSize != 1) && (FieldSize != 2) &&
+ (FieldSize != 4) && (FieldSize != 8)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Compute base address
+ //
+ SrcBaseAddress = Device->BaseAddress +
+ VIRTIO_DEVICE_SPECIFIC_CONFIGURATION_OFFSET_MMIO + FieldOffset;
+
+ //
+ // The device-specific memory area of Virtio-MMIO can only be read in
+ // byte reads. This is not currently in the Virtio spec.
+ //
+ MmioReadBuffer8 (SrcBaseAddress, BufferSize, Buffer);
+
+ return EFI_SUCCESS;
+}
diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf
index 0758375aa..2e266a9d4 100644
--- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf
+++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf
@@ -1,43 +1,42 @@
-## @file
-# This driver produces the VirtIo Device Protocol instances for VirtIo Mmio
-# Device
-#
-# Copyright (C) 2013, ARM Ltd
-#
-# This program and the accompanying materials are licensed and made available
-# under the terms and conditions of the BSD License which accompanies this
-# distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
-# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-##
-
-[Defines]
- INF_VERSION = 0x00010006
- BASE_NAME = VirtioMmioDeviceLib
- FILE_GUID = 3b6ed966-b5d1-46a8-965b-867ff22d9c89
- MODULE_TYPE = UEFI_DRIVER
- VERSION_STRING = 1.0
- LIBRARY_CLASS = VirtioMmioDeviceLib
-
-[Sources]
- VirtioMmioDevice.c
- VirtioMmioDeviceFunctions.c
-
-[Packages]
- MdePkg/MdePkg.dec
- OvmfPkg/OvmfPkg.dec
-
-[LibraryClasses]
- BaseMemoryLib
- DebugLib
- IoLib
- MemoryAllocationLib
- UefiBootServicesTableLib
- UefiDriverEntryPoint
- UefiLib
-
-[Protocols]
- gVirtioDeviceProtocolGuid ## PRODUCES
+## @file
+# This driver produces the VirtIo Device Protocol instances for VirtIo Mmio
+# Device
+#
+# Copyright (C) 2013, ARM Ltd
+#
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = VirtioMmioDeviceLib
+ FILE_GUID = 3b6ed966-b5d1-46a8-965b-867ff22d9c89
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = VirtioMmioDeviceLib
+
+[Sources]
+ VirtioMmioDevice.c
+ VirtioMmioDeviceFunctions.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+ BaseMemoryLib
+ DebugLib
+ IoLib
+ MemoryAllocationLib
+ UefiBootServicesTableLib
+ UefiLib
+
+[Protocols]
+ gVirtioDeviceProtocolGuid ## PRODUCES