summaryrefslogtreecommitdiff
path: root/OvmfPkg
diff options
context:
space:
mode:
Diffstat (limited to 'OvmfPkg')
-rw-r--r--OvmfPkg/Include/IndustryStandard/E820.h46
-rw-r--r--OvmfPkg/Include/IndustryStandard/VirtioBlk.h40
-rw-r--r--OvmfPkg/Include/IndustryStandard/VirtioNet.h12
-rw-r--r--OvmfPkg/Include/IndustryStandard/VirtioScsi.h26
-rw-r--r--OvmfPkg/Include/Library/QemuFwCfgLib.h21
-rw-r--r--OvmfPkg/Include/Library/VirtioLib.h16
-rw-r--r--OvmfPkg/Include/Library/VirtioMmioDeviceLib.h131
-rw-r--r--OvmfPkg/Include/Protocol/VirtioDevice.h758
-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
-rw-r--r--OvmfPkg/OvmfPkg.dec2
-rw-r--r--OvmfPkg/OvmfPkgIa32.dsc9
-rw-r--r--OvmfPkg/OvmfPkgIa32.fdf2
-rw-r--r--OvmfPkg/OvmfPkgIa32X64.dsc9
-rw-r--r--OvmfPkg/OvmfPkgIa32X64.fdf2
-rw-r--r--OvmfPkg/OvmfPkgX64.dsc9
-rw-r--r--OvmfPkg/OvmfPkgX64.fdf2
-rw-r--r--OvmfPkg/PlatformPei/MemDetect.c49
-rw-r--r--OvmfPkg/PlatformPei/Platform.c95
-rw-r--r--OvmfPkg/PlatformPei/Platform.h18
-rw-r--r--OvmfPkg/PlatformPei/PlatformPei.inf1
-rw-r--r--OvmfPkg/PlatformPei/Xen.c42
-rw-r--r--OvmfPkg/PlatformPei/Xen.h45
-rw-r--r--OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c2
-rw-r--r--OvmfPkg/QemuVideoDxe/Driver.c33
-rw-r--r--OvmfPkg/README22
-rw-r--r--OvmfPkg/VirtioBlkDxe/VirtioBlk.c214
-rw-r--r--OvmfPkg/VirtioBlkDxe/VirtioBlk.h24
-rw-r--r--OvmfPkg/VirtioBlkDxe/VirtioBlk.inf4
-rw-r--r--OvmfPkg/VirtioNetDxe/ComponentName.c6
-rw-r--r--OvmfPkg/VirtioNetDxe/DriverBinding.c121
-rw-r--r--OvmfPkg/VirtioNetDxe/Events.c2
-rw-r--r--OvmfPkg/VirtioNetDxe/SnpGetStatus.c2
-rw-r--r--OvmfPkg/VirtioNetDxe/SnpInitialize.c68
-rw-r--r--OvmfPkg/VirtioNetDxe/SnpReceive.c10
-rw-r--r--OvmfPkg/VirtioNetDxe/SnpShutdown.c2
-rw-r--r--OvmfPkg/VirtioNetDxe/SnpTransmit.c12
-rw-r--r--OvmfPkg/VirtioNetDxe/VirtioNet.h24
-rw-r--r--OvmfPkg/VirtioNetDxe/VirtioNet.inf2
-rw-r--r--OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.c1347
-rw-r--r--OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h332
-rw-r--r--OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf86
-rw-r--r--OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c568
-rw-r--r--OvmfPkg/VirtioScsiDxe/VirtioScsi.c143
-rw-r--r--OvmfPkg/VirtioScsiDxe/VirtioScsi.h22
-rw-r--r--OvmfPkg/VirtioScsiDxe/VirtioScsi.inf2
-rwxr-xr-xOvmfPkg/create-release.py151
55 files changed, 3427 insertions, 2838 deletions
diff --git a/OvmfPkg/Include/IndustryStandard/E820.h b/OvmfPkg/Include/IndustryStandard/E820.h
new file mode 100644
index 000000000..aeafd89f2
--- /dev/null
+++ b/OvmfPkg/Include/IndustryStandard/E820.h
@@ -0,0 +1,46 @@
+/** @file
+
+Copyright (c) 2013, Citrix Systems UK Ltd.
+Copyright (c) 2006 - 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.
+
+**/
+
+
+#ifndef __E820_H__
+#define __E820_H__
+
+#pragma pack(1)
+
+typedef enum {
+ EfiAcpiAddressRangeMemory = 1,
+ EfiAcpiAddressRangeReserved = 2,
+ EfiAcpiAddressRangeACPI = 3,
+ EfiAcpiAddressRangeNVS = 4
+} EFI_ACPI_MEMORY_TYPE;
+
+typedef struct {
+ UINT64 BaseAddr;
+ UINT64 Length;
+ EFI_ACPI_MEMORY_TYPE Type;
+} EFI_E820_ENTRY64;
+
+typedef struct {
+ UINT32 BassAddrLow;
+ UINT32 BaseAddrHigh;
+ UINT32 LengthLow;
+ UINT32 LengthHigh;
+ EFI_ACPI_MEMORY_TYPE Type;
+} EFI_E820_ENTRY;
+
+#pragma pack()
+
+#endif /* __E820_H__ */
diff --git a/OvmfPkg/Include/IndustryStandard/VirtioBlk.h b/OvmfPkg/Include/IndustryStandard/VirtioBlk.h
index 55f6548ed..2ce528a12 100644
--- a/OvmfPkg/Include/IndustryStandard/VirtioBlk.h
+++ b/OvmfPkg/Include/IndustryStandard/VirtioBlk.h
@@ -26,30 +26,40 @@
//
#pragma pack(1)
typedef struct {
- UINT64 Capacity;
- UINT32 SizeMax;
- UINT32 SegMax;
- UINT16 Cylinders;
- UINT8 Heads;
- UINT8 Sectors;
- UINT32 BlkSize;
-} VIRTIO_BLK_CONFIG;
+ UINT8 PhysicalBlockExp; // # of logical blocks per physical block (log2)
+ UINT8 AlignmentOffset; // offset of first aligned logical block
+ UINT16 MinIoSize; // suggested minimum I/O size in blocks
+ UINT32 OptIoSize; // optimal (suggested maximum) I/O size in blocks
+} VIRTIO_BLK_TOPOLOGY;
+
+typedef struct {
+ UINT64 Capacity;
+ UINT32 SizeMax;
+ UINT32 SegMax;
+ UINT16 Cylinders;
+ UINT8 Heads;
+ UINT8 Sectors;
+ UINT32 BlkSize;
+ VIRTIO_BLK_TOPOLOGY Topology;
+} VIRTIO_BLK_CONFIG;
#pragma pack()
-#define OFFSET_OF_VBLK(Field) OFFSET_OF (VIRTIO_BLK_CONFIG, Field)
-#define SIZE_OF_VBLK(Field) (sizeof ((VIRTIO_BLK_CONFIG *) 0)->Field)
+#define OFFSET_OF_VBLK(Field) OFFSET_OF (VIRTIO_BLK_CONFIG, Field)
+#define SIZE_OF_VBLK(Field) (sizeof ((VIRTIO_BLK_CONFIG *) 0)->Field)
#define VIRTIO_BLK_F_BARRIER BIT0
#define VIRTIO_BLK_F_SIZE_MAX BIT1
#define VIRTIO_BLK_F_SEG_MAX BIT2
#define VIRTIO_BLK_F_GEOMETRY BIT4
#define VIRTIO_BLK_F_RO BIT5
-#define VIRTIO_BLK_F_BLK_SIZE BIT6 // treated as "logical block size" in
- // practice; actual host side implementation
- // negotiates "optimal" block size
- // separately
+#define VIRTIO_BLK_F_BLK_SIZE BIT6 // treated as "logical block size" in
+ // practice; actual host side
+ // implementation negotiates "optimal"
+ // block size separately, via
+ // VIRTIO_BLK_F_TOPOLOGY
#define VIRTIO_BLK_F_SCSI BIT7
-#define VIRTIO_BLK_F_FLUSH BIT9 // identical to "write cache enabled"
+#define VIRTIO_BLK_F_FLUSH BIT9 // identical to "write cache enabled"
+#define VIRTIO_BLK_F_TOPOLOGY BIT10 // information on optimal I/O alignment
//
// We keep the status byte separate from the rest of the virtio-blk request
diff --git a/OvmfPkg/Include/IndustryStandard/VirtioNet.h b/OvmfPkg/Include/IndustryStandard/VirtioNet.h
index 90d9702cb..34bf15a58 100644
--- a/OvmfPkg/Include/IndustryStandard/VirtioNet.h
+++ b/OvmfPkg/Include/IndustryStandard/VirtioNet.h
@@ -24,13 +24,13 @@
//
#pragma pack(1)
typedef struct {
- UINT8 Mac[6];
- UINT16 LinkStatus;
-} VIRTIO_NET_CONFIG;
+ UINT8 Mac[6];
+ UINT16 LinkStatus;
+} VIRTIO_NET_CONFIG;
#pragma pack()
-#define OFFSET_OF_VNET(Field) OFFSET_OF (VIRTIO_NET_CONFIG, Field)
-#define SIZE_OF_VNET(Field) (sizeof ((VIRTIO_NET_CONFIG *) 0)->Field)
+#define OFFSET_OF_VNET(Field) OFFSET_OF (VIRTIO_NET_CONFIG, Field)
+#define SIZE_OF_VNET(Field) (sizeof ((VIRTIO_NET_CONFIG *) 0)->Field)
//
// Queue Identifiers
@@ -89,7 +89,7 @@ typedef struct {
#define VIRTIO_NET_HDR_GSO_ECN BIT7
//
-// Link Status Bits in VIRTIO_NET_CONFIG.LinkStatus
+// Link Status Bits in VIRTIO_NET_CONFIG.LinkStatus
//
#define VIRTIO_NET_S_LINK_UP BIT0
#define VIRTIO_NET_S_ANNOUNCE BIT1
diff --git a/OvmfPkg/Include/IndustryStandard/VirtioScsi.h b/OvmfPkg/Include/IndustryStandard/VirtioScsi.h
index 884e4d642..0c9b52090 100644
--- a/OvmfPkg/Include/IndustryStandard/VirtioScsi.h
+++ b/OvmfPkg/Include/IndustryStandard/VirtioScsi.h
@@ -26,21 +26,21 @@
//
#pragma pack(1)
typedef struct {
- UINT32 NumQueues;
- UINT32 SegMax;
- UINT32 MaxSectors;
- UINT32 CmdPerLun;
- UINT32 EventInfoSize;
- UINT32 SenseSize;
- UINT32 CdbSize;
- UINT16 MaxChannel;
- UINT16 MaxTarget;
- UINT32 MaxLun;
-} VIRTIO_SCSI_CONFIG;
+ UINT32 NumQueues;
+ UINT32 SegMax;
+ UINT32 MaxSectors;
+ UINT32 CmdPerLun;
+ UINT32 EventInfoSize;
+ UINT32 SenseSize;
+ UINT32 CdbSize;
+ UINT16 MaxChannel;
+ UINT16 MaxTarget;
+ UINT32 MaxLun;
+} VIRTIO_SCSI_CONFIG;
#pragma pack()
-#define OFFSET_OF_VSCSI(Field) OFFSET_OF (VIRTIO_SCSI_CONFIG, Field)
-#define SIZE_OF_VSCSI(Field) (sizeof ((VIRTIO_SCSI_CONFIG *) 0)->Field)
+#define OFFSET_OF_VSCSI(Field) OFFSET_OF (VIRTIO_SCSI_CONFIG, Field)
+#define SIZE_OF_VSCSI(Field) (sizeof ((VIRTIO_SCSI_CONFIG *) 0)->Field)
#define VIRTIO_SCSI_F_INOUT BIT0
#define VIRTIO_SCSI_F_HOTPLUG BIT1
diff --git a/OvmfPkg/Include/Library/QemuFwCfgLib.h b/OvmfPkg/Include/Library/QemuFwCfgLib.h
index 9d023777c..2519fc297 100644
--- a/OvmfPkg/Include/Library/QemuFwCfgLib.h
+++ b/OvmfPkg/Include/Library/QemuFwCfgLib.h
@@ -2,6 +2,8 @@
QEMU/KVM Firmware Configuration access
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
which accompanies this distribution. The full text of the license may be found at
@@ -56,6 +58,8 @@ typedef enum {
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
@@ -193,5 +197,22 @@ QemuFwCfgFindFile (
OUT FIRMWARE_CONFIG_ITEM *Item,
OUT UINTN *Size
);
+
+
+/**
+ 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
+ );
+
#endif
diff --git a/OvmfPkg/Include/Library/VirtioLib.h b/OvmfPkg/Include/Library/VirtioLib.h
index e61a5090e..36527a523 100644
--- a/OvmfPkg/Include/Library/VirtioLib.h
+++ b/OvmfPkg/Include/Library/VirtioLib.h
@@ -17,8 +17,8 @@
#ifndef _VIRTIO_LIB_H_
#define _VIRTIO_LIB_H_
-#include <Protocol/VirtioDevice.h>
-
+#include <Protocol/VirtioDevice.h>
+
#include <IndustryStandard/Virtio.h>
@@ -157,7 +157,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.
@@ -168,7 +168,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.
@@ -176,10 +176,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
);
#endif // _VIRTIO_LIB_H_
diff --git a/OvmfPkg/Include/Library/VirtioMmioDeviceLib.h b/OvmfPkg/Include/Library/VirtioMmioDeviceLib.h
index 73e5a9e8d..3f63a650b 100644
--- a/OvmfPkg/Include/Library/VirtioMmioDeviceLib.h
+++ b/OvmfPkg/Include/Library/VirtioMmioDeviceLib.h
@@ -1,65 +1,66 @@
-/** @file
-
- Definitions for the VirtIo MMIO Device Library
-
- 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_LIB_H_
-#define _VIRTIO_MMIO_DEVICE_LIB_H_
-
-/**
-
- Initialize VirtIo Device and Install VIRTIO_DEVICE_PROTOCOL protocol
-
- @param[in] BaseAddress Base Address of the VirtIo MMIO Device
-
- @param[in] Handle Handle of the device the driver should be attached to.
-
- @retval EFI_SUCCESS The VirtIo Device has been installed
- successfully.
-
- @retval EFI_OUT_OF_RESOURCES The function failed too allocate memory require
- by the Virtio MMIO device initialization.
-
- @retval EFI_UNSUPPORTED BaseAddress does not point to a VirtIo MMIO
- device.
-
- @return Status code returned by InstallProtocolInterface
- Boot Service function.
-
-**/
-EFI_STATUS
-VirtioMmioInstallDevice (
- IN PHYSICAL_ADDRESS BaseAddress,
- IN EFI_HANDLE Handle
- );
-
-/**
-
- Uninstall the VirtIo Device
-
- @param[in] Handle Handle of the device where the VirtIo Device protocol
- should have been installed.
-
- @retval EFI_SUCCESS The device has been un-initialized successfully.
-
- @return Status code returned by UninstallProtocolInterface
- Boot Service function.
-
-**/
-EFI_STATUS
-VirtioMmioUninstallDevice (
- IN EFI_HANDLE Handle
- );
-
-#endif // _VIRTIO_MMIO_DEVICE_LIB_H_
+/** @file
+
+ Definitions for the VirtIo MMIO Device Library
+
+ 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_LIB_H_
+#define _VIRTIO_MMIO_DEVICE_LIB_H_
+
+/**
+
+ Initialize VirtIo Device and Install VIRTIO_DEVICE_PROTOCOL protocol
+
+ @param[in] BaseAddress Base Address of the VirtIo MMIO Device
+
+ @param[in] Handle Handle of the device the driver should be attached
+ to.
+
+ @retval EFI_SUCCESS The VirtIo Device has been installed
+ successfully.
+
+ @retval EFI_OUT_OF_RESOURCES The function failed to allocate memory required
+ by the Virtio MMIO device initialization.
+
+ @retval EFI_UNSUPPORTED BaseAddress does not point to a VirtIo MMIO
+ device.
+
+ @return Status code returned by InstallProtocolInterface
+ Boot Service function.
+
+**/
+EFI_STATUS
+VirtioMmioInstallDevice (
+ IN PHYSICAL_ADDRESS BaseAddress,
+ IN EFI_HANDLE Handle
+ );
+
+/**
+
+ Uninstall the VirtIo Device
+
+ @param[in] Handle Handle of the device where the VirtIo Device protocol
+ should have been installed.
+
+ @retval EFI_SUCCESS The device has been un-initialized successfully.
+
+ @return Status code returned by UninstallProtocolInterface
+ Boot Service function.
+
+**/
+EFI_STATUS
+VirtioMmioUninstallDevice (
+ IN EFI_HANDLE Handle
+ );
+
+#endif // _VIRTIO_MMIO_DEVICE_LIB_H_
diff --git a/OvmfPkg/Include/Protocol/VirtioDevice.h b/OvmfPkg/Include/Protocol/VirtioDevice.h
index cecac0541..48fca2e14 100644
--- a/OvmfPkg/Include/Protocol/VirtioDevice.h
+++ b/OvmfPkg/Include/Protocol/VirtioDevice.h
@@ -1,376 +1,382 @@
-/** @file
- Virtio Device
-
- Copyright (c) 2013, ARM Ltd. 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.
-
-**/
-
-#ifndef __VIRTIO_DEVICE_H__
-#define __VIRTIO_DEVICE_H__
-
-// VirtIo Specification Revision: Major[31:24].Minor[23:16].Revision[15:0
-#define VIRTIO_SPEC_REVISION(major,minor,revision) \
- ((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF))
-
-#define VIRTIO_DEVICE_PROTOCOL_GUID { \
- 0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a }\
- }
-
-typedef struct _VIRTIO_DEVICE_PROTOCOL VIRTIO_DEVICE_PROTOCOL;
-
-/**
-
- Read a word from the device-specific I/O region of the Virtio Header.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[in] FieldOffset Source offset.
-
- @param[in] FieldSize Source field size in bytes, must be in {1, 2, 4, 8}.
-
- @param[in] BufferSize Number of bytes available in the target buffer. Must
- equal FieldSize.
-
- @param[out] Buffer Target buffer.
-
- @retval EFI_SUCCESS The data was read successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and read size.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources.
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
-
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_DEVICE_READ) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINTN BufferSize,
- OUT VOID *Buffer
- );
-
-/**
-
- Write a word to the device-specific I/O region of the Virtio Header.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[in] FieldOffset Destination offset.
-
- @param[in] FieldSize Destination field size in bytes,
- must be in {1, 2, 4, 8}.
-
- @param[out] Value Value to write.
-
- @retval EFI_SUCCESS The data was written successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and write size.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources.
- @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
-
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_DEVICE_WRITE) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINT64 Value
- );
-
-/**
- Read the device features field from the Virtio Header.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[out] DeviceFeatures The 32-bit device features field.
-
- @retval EFI_SUCCESS The data was read successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and read size.
- @retval EFI_INVALID_PARAMETER DeviceFeatures is NULL
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_GET_DEVICE_FEATURES) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT32 *DeviceFeatures
- );
-
-/**
- Write the guest features field in the Virtio Header.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[in] Features The 32-bit guest guest features field
-
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_SET_GUEST_FEATURES) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINT32 Features
- );
-
-/**
- Read the queue address field from the Virtio Header.
-
- QueueAddress is the address of the virtqueue divided by 4096.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[out] QueueAddress The 32-bit queue address field.
-
- @retval EFI_SUCCESS The data was read successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and read size.
- @retval EFI_INVALID_PARAMETER QueueAddress is NULL
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_GET_QUEUE_ADDRESS) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT32 *QueueAddress
- );
-
-/**
- Write the queue address field in the Virtio Header.
-
- The parameter Address must be the base address of the virtqueue divided
- by 4096.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[in] Address The 32-bit Queue Address field
-
- @retval EFI_SUCCESS The data was written successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and write size.
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_SET_QUEUE_ADDRESS) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINT32 Address
- );
-
-/**
-
- Write the queue select field in the Virtio Header.
-
- Writing to the queue select field sets the index of the queue to which
- operations such as SetQueueAlign and GetQueueNumMax apply.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[in] Index The index of the queue to select
-
- @retval EFI_SUCCESS The data was written successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and write size.
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_SET_QUEUE_SEL) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINT16 Index
- );
-
-/**
-
- Write the queue notify field in the Virtio Header.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[in] Address The 32-bit Queue Notify field
-
- @retval EFI_SUCCESS The data was written successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and write size.
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_SET_QUEUE_NOTIFY) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINT16 Index
- );
-
-/**
- Write the queue alignment field in the Virtio Header.
-
- The queue to which the alignment applies is selected by the Queue Select
- field.
-
- Note: This operation is not implemented by the VirtIo over PCI. The PCI
- implementation of this protocol returns EFI_SUCCESS.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[in] Alignment The alignment boundary of the Used Ring in bytes.
- Must be a power of 2.
-
- @retval EFI_SUCCESS The data was written successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and write size.
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_SET_QUEUE_ALIGN) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINT32 Alignment
- );
-
-/**
- Write the guest page size.
-
- Note: This operation is not implemented by the VirtIo over PCI. The PCI
- implementation of this protocol returns EFI_SUCCESS.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[in] PageSize Size of the Guest page in bytes.
- Must be a power of 2.
-
- @retval EFI_SUCCESS The data was written successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and write size.
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_SET_PAGE_SIZE) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINT32 PageSize
- );
-
-/**
-
- Get the size of the virtqueue selected by the queue select field.
-
- See Virtio spec Section 2.3
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[out] QueueNumMax The size of the virtqueue in bytes.
- Always a power of 2.
-
- @retval EFI_SUCCESS The data was read successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and read size.
- @retval EFI_INVALID_PARAMETER QueueNumMax is NULL
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_GET_QUEUE_NUM_MAX) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT16 *QueueNumMax
- );
-
-/**
-
- Write to the QueueNum field in the Virtio Header.
-
- This function only applies to Virtio-MMIO and may be a stub for other
- implementations. See Virtio Spec appendix X.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[in] QueueSize The number of elements in the queue.
-
- @retval EFI_SUCCESS The data was written successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and write size.
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_SET_QUEUE_NUM) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINT16 QueueSize
- );
-
-/**
-
- Get the DeviceStatus field from the Virtio Header.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[out] DeviceStatus The 8-bit value for the Device status field
-
- @retval EFI_SUCCESS The data was read successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and read size.
- @retval EFI_INVALID_PARAMETER DeviceStatus is NULL
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_GET_DEVICE_STATUS) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT8 *DeviceStatus
- );
-
-/**
-
- Write the DeviceStatus field in the Virtio Header.
-
- @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
-
- @param[in] DeviceStatus The 8-bit value for the Device status field
-
- @retval EFI_SUCCESS The data was written successfully.
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and write size.
-**/
-typedef
-EFI_STATUS
-(EFIAPI *VIRTIO_SET_DEVICE_STATUS) (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINT8 DeviceStatus
- );
-
-
-///
-/// This protocol provides an abstraction over the VirtIo transport layer
-///
-struct _VIRTIO_DEVICE_PROTOCOL {
- /// VirtIo Specification Revision encoded with VIRTIO_SPEC_REVISION()
- UINT32 Revision;
- /// From the Virtio Spec
- INT32 SubSystemDeviceId;
-
- VIRTIO_GET_DEVICE_FEATURES GetDeviceFeatures;
- VIRTIO_SET_GUEST_FEATURES SetGuestFeatures;
-
- VIRTIO_GET_QUEUE_ADDRESS GetQueueAddress;
- VIRTIO_SET_QUEUE_ADDRESS SetQueueAddress;
-
- VIRTIO_SET_QUEUE_SEL SetQueueSel;
-
- VIRTIO_SET_QUEUE_NOTIFY SetQueueNotify;
-
- VIRTIO_SET_QUEUE_ALIGN SetQueueAlign;
- VIRTIO_SET_PAGE_SIZE SetPageSize;
-
- VIRTIO_GET_QUEUE_NUM_MAX GetQueueNumMax;
- VIRTIO_SET_QUEUE_NUM SetQueueNum;
-
- VIRTIO_GET_DEVICE_STATUS GetDeviceStatus;
- VIRTIO_SET_DEVICE_STATUS SetDeviceStatus;
-
- // Functions to read/write Device Specific headers
- VIRTIO_DEVICE_WRITE WriteDevice;
- VIRTIO_DEVICE_READ ReadDevice;
-};
-
-extern EFI_GUID gVirtioDeviceProtocolGuid;
-
-#endif
+/** @file
+ Virtio Device
+
+ DISCLAIMER: the VIRTIO_DEVICE_PROTOCOL introduced here is a work in progress,
+ and should not be used outside of the EDK II tree.
+
+ Copyright (c) 2013, ARM Ltd. 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.
+
+**/
+
+#ifndef __VIRTIO_DEVICE_H__
+#define __VIRTIO_DEVICE_H__
+
+// VirtIo Specification Revision: Major[31:24].Minor[23:16].Revision[15:0
+#define VIRTIO_SPEC_REVISION(major,minor,revision) \
+ ((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF))
+
+#define VIRTIO_DEVICE_PROTOCOL_GUID { \
+ 0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a }\
+ }
+
+typedef struct _VIRTIO_DEVICE_PROTOCOL VIRTIO_DEVICE_PROTOCOL;
+
+/**
+
+ Read a word from the device-specific I/O region of the Virtio Header.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[in] FieldOffset Source offset.
+
+ @param[in] FieldSize Source field size in bytes, must be in {1, 2, 4, 8}.
+
+ @param[in] BufferSize Number of bytes available in the target buffer. Must
+ equal FieldSize.
+
+ @param[out] Buffer Target buffer.
+
+ @retval EFI_SUCCESS The data was read successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and read size.
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
+ lack of resources.
+ @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_DEVICE_READ) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ );
+
+/**
+
+ Write a word to the device-specific I/O region of the Virtio Header.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[in] FieldOffset Destination offset.
+
+ @param[in] FieldSize Destination field size in bytes,
+ must be in {1, 2, 4, 8}.
+
+ @param[out] Value Value to write.
+
+ @retval EFI_SUCCESS The data was written successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and write size.
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
+ lack of resources.
+ @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_DEVICE_WRITE) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINT64 Value
+ );
+
+/**
+ Read the device features field from the Virtio Header.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[out] DeviceFeatures The 32-bit device features field.
+
+ @retval EFI_SUCCESS The data was read successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and read size.
+ @retval EFI_INVALID_PARAMETER DeviceFeatures is NULL
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_GET_DEVICE_FEATURES) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT32 *DeviceFeatures
+ );
+
+/**
+ Write the guest features field in the Virtio Header.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[in] Features The 32-bit guest guest features field
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_SET_GUEST_FEATURES) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINT32 Features
+ );
+
+/**
+ Read the queue address field from the Virtio Header.
+
+ QueueAddress is the address of the virtqueue divided by 4096.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[out] QueueAddress The 32-bit queue address field.
+
+ @retval EFI_SUCCESS The data was read successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and read size.
+ @retval EFI_INVALID_PARAMETER QueueAddress is NULL
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_GET_QUEUE_ADDRESS) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT32 *QueueAddress
+ );
+
+/**
+ Write the queue address field in the Virtio Header.
+
+ The parameter Address must be the base address of the virtqueue divided
+ by 4096.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[in] Address The 32-bit Queue Address field
+
+ @retval EFI_SUCCESS The data was written successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and write size.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_SET_QUEUE_ADDRESS) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINT32 Address
+ );
+
+/**
+
+ Write the queue select field in the Virtio Header.
+
+ Writing to the queue select field sets the index of the queue to which
+ operations such as SetQueueAlign and GetQueueNumMax apply.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[in] Index The index of the queue to select
+
+ @retval EFI_SUCCESS The data was written successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and write size.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_SET_QUEUE_SEL) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINT16 Index
+ );
+
+/**
+
+ Write the queue notify field in the Virtio Header.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[in] Address The 32-bit Queue Notify field
+
+ @retval EFI_SUCCESS The data was written successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and write size.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_SET_QUEUE_NOTIFY) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINT16 Index
+ );
+
+/**
+ Write the queue alignment field in the Virtio Header.
+
+ The queue to which the alignment applies is selected by the Queue Select
+ field.
+
+ Note: This operation is not implemented by the VirtIo over PCI. The PCI
+ implementation of this protocol returns EFI_SUCCESS.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[in] Alignment The alignment boundary of the Used Ring in bytes.
+ Must be a power of 2.
+
+ @retval EFI_SUCCESS The data was written successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and write size.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_SET_QUEUE_ALIGN) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINT32 Alignment
+ );
+
+/**
+ Write the guest page size.
+
+ Note: This operation is not implemented by the VirtIo over PCI. The PCI
+ implementation of this protocol returns EFI_SUCCESS.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[in] PageSize Size of the Guest page in bytes.
+ Must be a power of 2.
+
+ @retval EFI_SUCCESS The data was written successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and write size.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_SET_PAGE_SIZE) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINT32 PageSize
+ );
+
+/**
+
+ Get the size of the virtqueue selected by the queue select field.
+
+ See Virtio spec Section 2.3
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[out] QueueNumMax The size of the virtqueue in bytes.
+ Always a power of 2.
+
+ @retval EFI_SUCCESS The data was read successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and read size.
+ @retval EFI_INVALID_PARAMETER QueueNumMax is NULL
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_GET_QUEUE_NUM_MAX) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT16 *QueueNumMax
+ );
+
+/**
+
+ Write to the QueueNum field in the Virtio Header.
+
+ This function only applies to Virtio-MMIO and may be a stub for other
+ implementations. See Virtio Spec appendix X.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[in] QueueSize The number of elements in the queue.
+
+ @retval EFI_SUCCESS The data was written successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and write size.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_SET_QUEUE_NUM) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINT16 QueueSize
+ );
+
+/**
+
+ Get the DeviceStatus field from the Virtio Header.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[out] DeviceStatus The 8-bit value for the Device status field
+
+ @retval EFI_SUCCESS The data was read successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and read size.
+ @retval EFI_INVALID_PARAMETER DeviceStatus is NULL
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_GET_DEVICE_STATUS) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT8 *DeviceStatus
+ );
+
+/**
+
+ Write the DeviceStatus field in the Virtio Header.
+
+ @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL
+
+ @param[in] DeviceStatus The 8-bit value for the Device status field
+
+ @retval EFI_SUCCESS The data was written successfully.
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and write size.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *VIRTIO_SET_DEVICE_STATUS) (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINT8 DeviceStatus
+ );
+
+
+///
+/// This protocol provides an abstraction over the VirtIo transport layer
+///
+/// DISCLAIMER: this protocol is a work in progress, and should not be used
+/// outside of the EDK II tree.
+///
+struct _VIRTIO_DEVICE_PROTOCOL {
+ /// VirtIo Specification Revision encoded with VIRTIO_SPEC_REVISION()
+ UINT32 Revision;
+ /// From the Virtio Spec
+ INT32 SubSystemDeviceId;
+
+ VIRTIO_GET_DEVICE_FEATURES GetDeviceFeatures;
+ VIRTIO_SET_GUEST_FEATURES SetGuestFeatures;
+
+ VIRTIO_GET_QUEUE_ADDRESS GetQueueAddress;
+ VIRTIO_SET_QUEUE_ADDRESS SetQueueAddress;
+
+ VIRTIO_SET_QUEUE_SEL SetQueueSel;
+
+ VIRTIO_SET_QUEUE_NOTIFY SetQueueNotify;
+
+ VIRTIO_SET_QUEUE_ALIGN SetQueueAlign;
+ VIRTIO_SET_PAGE_SIZE SetPageSize;
+
+ VIRTIO_GET_QUEUE_NUM_MAX GetQueueNumMax;
+ VIRTIO_SET_QUEUE_NUM SetQueueNum;
+
+ VIRTIO_GET_DEVICE_STATUS GetDeviceStatus;
+ VIRTIO_SET_DEVICE_STATUS SetDeviceStatus;
+
+ // Functions to read/write Device Specific headers
+ VIRTIO_DEVICE_WRITE WriteDevice;
+ VIRTIO_DEVICE_READ ReadDevice;
+};
+
+extern EFI_GUID gVirtioDeviceProtocolGuid;
+
+#endif
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
diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 3d4e7bcd9..9d7fedf4d 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -44,7 +44,7 @@
gEfiXenInfoGuid = {0xd3b46f3b, 0xd441, 0x1244, {0x9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}}
[Protocols]
- gVirtioDeviceProtocolGuid = {0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}}
+ gVirtioDeviceProtocolGuid = {0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}}
gBlockMmioProtocolGuid = {0x6b558ce3, 0x69e5, 0x4c67, {0xa6, 0x34, 0xf7, 0xfe, 0x72, 0xad, 0xbe, 0x84}}
[PcdsFixedAtBuild]
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 860a73e96..c7c90fb3d 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -127,6 +127,7 @@
!endif
[LibraryClasses.common.SEC]
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf
!ifdef $(DEBUG_ON_SERIAL_PORT)
DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
!else
@@ -322,6 +323,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|FALSE
################################################################################
@@ -386,7 +388,10 @@
UefiCpuPkg/CpuDxe/CpuDxe.inf
PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
PcAtChipsetPkg/PciHostBridgeDxe/PciHostBridgeDxe.inf
- MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
+ MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {
+ <LibraryClasses>
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
+ }
PcAtChipsetPkg/KbcResetDxe/Reset.inf
MdeModulePkg/Universal/Metronome/Metronome.inf {
<LibraryClasses>
@@ -407,7 +412,7 @@
}
OvmfPkg/BlockMmioToBlockIoDxe/BlockIo.inf
- OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
+ OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
index af3890c0e..c6e186f26 100644
--- a/OvmfPkg/OvmfPkgIa32.fdf
+++ b/OvmfPkg/OvmfPkgIa32.fdf
@@ -266,7 +266,7 @@ INF MdeModulePkg/Universal/Metronome/Metronome.inf
INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
INF OvmfPkg/BlockMmioToBlockIoDxe/BlockIo.inf
-INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
+INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
INF OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 829341ca8..b8c569a14 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -132,6 +132,7 @@
!endif
[LibraryClasses.common.SEC]
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf
!ifdef $(DEBUG_ON_SERIAL_PORT)
DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
!else
@@ -328,6 +329,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|FALSE
################################################################################
@@ -393,7 +395,10 @@
UefiCpuPkg/CpuDxe/CpuDxe.inf
PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
PcAtChipsetPkg/PciHostBridgeDxe/PciHostBridgeDxe.inf
- MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
+ MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {
+ <LibraryClasses>
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
+ }
PcAtChipsetPkg/KbcResetDxe/Reset.inf
MdeModulePkg/Universal/Metronome/Metronome.inf {
<LibraryClasses>
@@ -414,7 +419,7 @@
}
OvmfPkg/BlockMmioToBlockIoDxe/BlockIo.inf
- OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
+ OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf
index 9aa47740b..615451dbe 100644
--- a/OvmfPkg/OvmfPkgIa32X64.fdf
+++ b/OvmfPkg/OvmfPkgIa32X64.fdf
@@ -266,7 +266,7 @@ INF MdeModulePkg/Universal/Metronome/Metronome.inf
INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
INF OvmfPkg/BlockMmioToBlockIoDxe/BlockIo.inf
-INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
+INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
INF OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 96067f3e3..7b1fa5217 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -132,6 +132,7 @@
!endif
[LibraryClasses.common.SEC]
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf
!ifdef $(DEBUG_ON_SERIAL_PORT)
DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
!else
@@ -327,6 +328,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|FALSE
################################################################################
@@ -391,7 +393,10 @@
UefiCpuPkg/CpuDxe/CpuDxe.inf
PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
PcAtChipsetPkg/PciHostBridgeDxe/PciHostBridgeDxe.inf
- MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
+ MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {
+ <LibraryClasses>
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
+ }
PcAtChipsetPkg/KbcResetDxe/Reset.inf
MdeModulePkg/Universal/Metronome/Metronome.inf {
<LibraryClasses>
@@ -412,7 +417,7 @@
}
OvmfPkg/BlockMmioToBlockIoDxe/BlockIo.inf
- OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
+ OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index d7221950b..911fe0898 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -266,7 +266,7 @@ INF MdeModulePkg/Universal/Metronome/Metronome.inf
INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
INF OvmfPkg/BlockMmioToBlockIoDxe/BlockIo.inf
-INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
+INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
INF OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index 9f6ca1942..a1de76268 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -83,30 +83,23 @@ GetSystemMemorySizeAbove4gb (
return LShiftU64 (Size, 16);
}
-
/**
- Peform Memory Detection
+ Publish PEI core memory
@return EFI_SUCCESS The PEIM initialized successfully.
**/
-EFI_PHYSICAL_ADDRESS
-MemDetect (
+EFI_STATUS
+PublishPeiMemory (
+ VOID
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS MemoryBase;
UINT64 MemorySize;
UINT64 LowerMemorySize;
- UINT64 UpperMemorySize;
- DEBUG ((EFI_D_ERROR, "MemDetect called\n"));
-
- //
- // Determine total memory size available
- //
LowerMemorySize = GetSystemMemorySizeBelow4gb ();
- UpperMemorySize = GetSystemMemorySizeAbove4gb ();
//
// Determine the range of memory to use during PEI
@@ -124,14 +117,40 @@ MemDetect (
Status = PublishSystemMemory(MemoryBase, MemorySize);
ASSERT_EFI_ERROR (Status);
+ return Status;
+}
+
+
+/**
+ Peform Memory Detection
+
+ @return Top of memory
+
+**/
+EFI_PHYSICAL_ADDRESS
+MemDetect (
+ )
+{
+ UINT64 LowerMemorySize;
+ UINT64 UpperMemorySize;
+
+ DEBUG ((EFI_D_ERROR, "MemDetect called\n"));
+
+ //
+ // Determine total memory size available
+ //
+ LowerMemorySize = GetSystemMemorySizeBelow4gb ();
+ UpperMemorySize = GetSystemMemorySizeAbove4gb ();
+
+ PublishPeiMemory ();
+
//
// Create memory HOBs
//
- AddMemoryBaseSizeHob (MemoryBase, MemorySize);
- AddMemoryRangeHob (BASE_1MB, MemoryBase);
+ AddMemoryRangeHob (BASE_1MB, LowerMemorySize);
AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);
- MtrrSetMemoryAttribute (BASE_1MB, MemoryBase + MemorySize - BASE_1MB, CacheWriteBack);
+ MtrrSetMemoryAttribute (BASE_1MB, LowerMemorySize - BASE_1MB, CacheWriteBack);
MtrrSetMemoryAttribute (0, BASE_512KB + BASE_128KB, CacheWriteBack);
@@ -141,6 +160,6 @@ MemDetect (
MtrrSetMemoryAttribute (BASE_4GB, UpperMemorySize, CacheWriteBack);
}
- return MemoryBase + MemorySize;
+ return LowerMemorySize;
}
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index fb56e999e..7363702be 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -34,6 +34,10 @@
#include <Guid/MemoryTypeInformation.h>
#include <Ppi/MasterBootMode.h>
#include <IndustryStandard/Pci22.h>
+#include <Guid/XenInfo.h>
+#include <IndustryStandard/E820.h>
+#include <Library/ResourcePublicationLib.h>
+#include <Library/MtrrLib.h>
#include "Platform.h"
#include "Cmos.h"
@@ -163,6 +167,74 @@ AddUntestedMemoryRangeHob (
AddUntestedMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
}
+VOID
+XenMemMapInitialization (
+ VOID
+ )
+{
+ EFI_E820_ENTRY64 *E820Map;
+ UINT32 E820EntriesCount;
+ EFI_STATUS Status;
+
+ DEBUG ((EFI_D_INFO, "Using memory map provided by Xen\n"));
+
+ //
+ // Create Memory Type Information HOB
+ //
+ BuildGuidDataHob (
+ &gEfiMemoryTypeInformationGuid,
+ mDefaultMemoryTypeInformation,
+ sizeof(mDefaultMemoryTypeInformation)
+ );
+
+ //
+ // Add PCI IO Port space available for PCI resource allocations.
+ //
+ BuildResourceDescriptorHob (
+ EFI_RESOURCE_IO,
+ EFI_RESOURCE_ATTRIBUTE_PRESENT |
+ EFI_RESOURCE_ATTRIBUTE_INITIALIZED,
+ 0xC000,
+ 0x4000
+ );
+
+ //
+ // Video memory + Legacy BIOS region
+ //
+ AddIoMemoryRangeHob (0x0A0000, BASE_1MB);
+
+ //
+ // Parse RAM in E820 map
+ //
+ Status = XenGetE820Map(&E820Map, &E820EntriesCount);
+
+ ASSERT_EFI_ERROR (Status);
+
+ if (E820EntriesCount > 0) {
+ EFI_E820_ENTRY64 *Entry;
+ UINT32 Loop;
+
+ for (Loop = 0; Loop < E820EntriesCount; Loop++) {
+ Entry = E820Map + Loop;
+
+ //
+ // Only care about RAM
+ //
+ if (Entry->Type != EfiAcpiAddressRangeMemory) {
+ continue;
+ }
+
+ if (Entry->BaseAddr >= BASE_4GB) {
+ AddUntestedMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);
+ } else {
+ AddMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);
+ }
+
+ MtrrSetMemoryAttribute (Entry->BaseAddr, Entry->Length, CacheWriteBack);
+ }
+ }
+}
+
VOID
MemMapInitialization (
@@ -338,20 +410,37 @@ InitializePlatform (
)
{
EFI_PHYSICAL_ADDRESS TopOfMemory;
+ UINT32 XenLeaf;
+
+ TopOfMemory = 0;
DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));
DebugDumpCmos ();
- TopOfMemory = MemDetect ();
+ XenLeaf = XenDetect ();
+
+ if (XenLeaf != 0) {
+ PublishPeiMemory ();
+ PcdSetBool (PcdPciDisableBusEnumeration, TRUE);
+ } else {
+ TopOfMemory = MemDetect ();
+ }
- InitializeXen ();
+ if (XenLeaf != 0) {
+ DEBUG ((EFI_D_INFO, "Xen was detected\n"));
+ InitializeXen (XenLeaf);
+ }
ReserveEmuVariableNvStore ();
PeiFvInitialization ();
- MemMapInitialization (TopOfMemory);
+ if (XenLeaf != 0) {
+ XenMemMapInitialization ();
+ } else {
+ MemMapInitialization (TopOfMemory);
+ }
MiscInitialization ();
diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index 383e6a436..5378b9d8e 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -15,6 +15,8 @@
#ifndef _PLATFORM_PEI_H_INCLUDED_
#define _PLATFORM_PEI_H_INCLUDED_
+#include <IndustryStandard/E820.h>
+
VOID
AddIoMemoryBaseSizeHob (
EFI_PHYSICAL_ADDRESS MemoryBase,
@@ -57,6 +59,11 @@ AddUntestedMemoryRangeHob (
EFI_PHYSICAL_ADDRESS MemoryLimit
);
+EFI_STATUS
+PublishPeiMemory (
+ VOID
+ );
+
EFI_PHYSICAL_ADDRESS
MemDetect (
VOID
@@ -69,7 +76,18 @@ PeiFvInitialization (
EFI_STATUS
InitializeXen (
+ UINT32 XenLeaf
+ );
+
+UINT32
+XenDetect (
VOID
);
+EFI_STATUS
+XenGetE820Map (
+ EFI_E820_ENTRY64 **Entries,
+ UINT32 *Count
+ );
+
#endif // _PLATFORM_PEI_H_INCLUDED_
diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf
index 3d5cbbbc2..7fe9d471c 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -65,6 +65,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration
gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress
[Ppis]
diff --git a/OvmfPkg/PlatformPei/Xen.c b/OvmfPkg/PlatformPei/Xen.c
index a720b91b9..8e5d79e8b 100644
--- a/OvmfPkg/PlatformPei/Xen.c
+++ b/OvmfPkg/PlatformPei/Xen.c
@@ -1,7 +1,7 @@
/**@file
Xen Platform PEI support
- Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>
This program and the accompanying materials
@@ -29,9 +29,37 @@
#include <Guid/XenInfo.h>
#include "Platform.h"
+#include "Xen.h"
EFI_XEN_INFO mXenInfo;
+/**
+ Returns E820 map provided by Xen
+
+ @param Entries Pointer to E820 map
+ @param Count Number of entries
+
+ @return EFI_STATUS
+**/
+EFI_STATUS
+XenGetE820Map (
+ EFI_E820_ENTRY64 **Entries,
+ UINT32 *Count
+ )
+{
+ EFI_XEN_OVMF_INFO *Info =
+ (EFI_XEN_OVMF_INFO *)(UINTN) OVMF_INFO_PHYSICAL_ADDRESS;
+
+ if (AsciiStrCmp ((CHAR8 *) Info->Signature, "XenHVMOVMF")) {
+ return EFI_NOT_FOUND;
+ }
+
+ ASSERT (Info->E820 < MAX_ADDRESS);
+ *Entries = (EFI_E820_ENTRY64 *)(UINTN) Info->E820;
+ *Count = Info->E820EntriesCount;
+
+ return EFI_SUCCESS;
+}
/**
Connects to the Hypervisor.
@@ -119,19 +147,9 @@ XenDetect (
**/
EFI_STATUS
InitializeXen (
- VOID
+ UINT32 XenLeaf
)
{
- UINT32 XenLeaf;
-
- XenLeaf = XenDetect ();
-
- if (XenLeaf == 0) {
- return EFI_NOT_FOUND;
- }
-
- DEBUG ((EFI_D_INFO, "Xen was detected\n"));
-
XenConnect (XenLeaf);
//
diff --git a/OvmfPkg/PlatformPei/Xen.h b/OvmfPkg/PlatformPei/Xen.h
new file mode 100644
index 000000000..2a8a32be6
--- /dev/null
+++ b/OvmfPkg/PlatformPei/Xen.h
@@ -0,0 +1,45 @@
+/** @file
+ Ovmf info structure passed by Xen
+
+Copyright (c) 2013, Citrix Systems UK Ltd.<BR>
+
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that 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 __XEN_H__
+#define __XEN_H__
+
+#include <PiPei.h>
+
+// Physical address of OVMF info
+#define OVMF_INFO_PHYSICAL_ADDRESS 0x00001000
+
+// This structure must match the definition on Xen side
+#pragma pack(1)
+typedef struct {
+ CHAR8 Signature[14]; // XenHVMOVMF\0
+ UINT8 Length; // Length of this structure
+ UINT8 Checksum; // Set such that the sum over bytes 0..length == 0
+ //
+ // Physical address of an array of TablesCount elements.
+ //
+ // Each element contains the physical address of a BIOS table.
+ //
+ EFI_PHYSICAL_ADDRESS Tables;
+ UINT32 TablesCount;
+ //
+ // Physical address of the E820 table, contains E820EntriesCount entries.
+ //
+ EFI_PHYSICAL_ADDRESS E820;
+ UINT32 E820EntriesCount;
+} EFI_XEN_OVMF_INFO;
+#pragma pack()
+
+#endif /* __XEN_H__ */
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
index a3fe7d874..f9c6f5c55 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
@@ -208,7 +208,7 @@ QemuFlashWrite (
// Restore flash to read mode
//
if (*NumBytes > 0) {
- *Ptr = READ_ARRAY_CMD;
+ *(Ptr - 1) = READ_ARRAY_CMD;
}
return EFI_SUCCESS;
diff --git a/OvmfPkg/QemuVideoDxe/Driver.c b/OvmfPkg/QemuVideoDxe/Driver.c
index 53718e1ae..b253ec734 100644
--- a/OvmfPkg/QemuVideoDxe/Driver.c
+++ b/OvmfPkg/QemuVideoDxe/Driver.c
@@ -209,6 +209,7 @@ QemuVideoControllerDriverStart (
PCI_TYPE00 Pci;
QEMU_VIDEO_CARD *Card;
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *MmioDesc;
+ EFI_PCI_IO_PROTOCOL *ChildPciIo;
PciAttributesSaved = FALSE;
//
@@ -419,6 +420,22 @@ QemuVideoControllerDriverStart (
&Private->GraphicsOutput,
NULL
);
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
+
+ Status = gBS->OpenProtocol (
+ Controller,
+ &gEfiPciIoProtocolGuid,
+ (VOID **) &ChildPciIo,
+ This->DriverBindingHandle,
+ Private->Handle,
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
}
Error:
@@ -440,7 +457,14 @@ Error:
// Close the PCI I/O Protocol
//
gBS->CloseProtocol (
- Private->Handle,
+ Controller,
+ &gEfiPciIoProtocolGuid,
+ This->DriverBindingHandle,
+ Controller
+ );
+
+ gBS->CloseProtocol (
+ Controller,
&gEfiPciIoProtocolGuid,
This->DriverBindingHandle,
Private->Handle
@@ -533,6 +557,13 @@ QemuVideoControllerDriverStop (
Controller
);
+ gBS->CloseProtocol (
+ Controller,
+ &gEfiPciIoProtocolGuid,
+ This->DriverBindingHandle,
+ Private->Handle
+ );
+
//
// Free our instance data
//
diff --git a/OvmfPkg/README b/OvmfPkg/README
index f2c2fc799..be798063a 100644
--- a/OvmfPkg/README
+++ b/OvmfPkg/README
@@ -9,8 +9,6 @@ http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=OVMF
=== STATUS ===
-Current status: Alpha
-
Current capabilities:
* IA32 and X64 architectures
* QEMU (0.10.0 or later)
@@ -22,7 +20,6 @@ Current capabilities:
=== FUTURE PLANS ===
-* Stabilize UEFI Linux boot
* Test/Stabilize UEFI Self-Certification Tests (SCT) results
=== BUILDING OVMF ===
@@ -60,12 +57,23 @@ http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=How_to_build_OVM
=== RUNNING OVMF on QEMU ===
-* QEMU 0.9.1 or later is required.
-* Either copy, rename or symlink OVMF.FD => bios.bin
+* QEMU 0.12.2 or later is required.
* Be sure to use qemu-system-x86_64, if you are using and X64 firmware.
(qemu-system-x86_64 works for the IA32 firmware as well, of course.)
-* Use the QEMU -L parameter to specify the directory where the bios.bin
- file is located.
+* Use OVMF for QEMU firmware (3 options available)
+ - Option 1: QEMU 1.6 or newer; Use QEMU -pflash parameter
+ * QEMU/OVMF will use emulated flash, and fully support UEFI variables
+ * Run qemu with: -pflash path/to/OVMF.fd
+ - Option 2: Use QEMU -bios parameter
+ * Note that UEFI variables will be partially emulated, and non-volatile
+ variables may lose their contents after a reboot
+ * Run qemu with: -bios path/to/OVMF.fd
+ - Option 3: Use QEMU -L parameter
+ * Note that UEFI variables will be partially emulated, and non-volatile
+ variables may lose their contents after a reboot
+ * Either copy, rename or symlink OVMF.fd => bios.bin
+ * Use the QEMU -L parameter to specify the directory where the bios.bin
+ file is located.
* The EFI shell is built into OVMF builds at this time, so it should
run automatically if a UEFI boot application is not found on the
removable media.
diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
index 08edf23fc..35fc88e35 100644
--- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
+++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
@@ -36,14 +36,14 @@
/**
Convenience macros to read and write region 0 IO space elements of the
- virtio-blk device, for configuration purposes.
+ virtio-blk device, for configuration purposes.
The following macros make it possible to specify only the "core parameters"
for such accesses and to derive the rest. By the time VIRTIO_CFG_WRITE()
returns, the transaction will have been completed.
- @param[in] Dev Pointer to the VBLK_DEV structure whose VirtIo space
- we're accessing. Dev->VirtIo must be valid.
+ @param[in] Dev Pointer to the VBLK_DEV structure whose VirtIo space
+ we're accessing. Dev->VirtIo must be valid.
@param[in] Field A field name from VBLK_HDR, identifying the virtio-blk
configuration item to access.
@@ -56,23 +56,24 @@
one of UINT8, UINT16, UINT32, UINT64.
- @return Status code returned by Virtio->WriteDevice() / Virtio->ReadDevice().
+ @return Status code returned by Virtio->WriteDevice() /
+ Virtio->ReadDevice().
**/
-#define VIRTIO_CFG_WRITE(Dev, Field, Value) ((Dev)->VirtIo->WriteDevice ( \
- (Dev)->VirtIo, \
- OFFSET_OF_VBLK (Field), \
- SIZE_OF_VBLK (Field), \
- (Value) \
+#define VIRTIO_CFG_WRITE(Dev, Field, Value) ((Dev)->VirtIo->WriteDevice ( \
+ (Dev)->VirtIo, \
+ OFFSET_OF_VBLK (Field), \
+ SIZE_OF_VBLK (Field), \
+ (Value) \
))
-#define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice ( \
- (Dev)->VirtIo, \
- OFFSET_OF_VBLK (Field), \
- SIZE_OF_VBLK (Field), \
- sizeof *(Pointer), \
- (Pointer) \
+#define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice ( \
+ (Dev)->VirtIo, \
+ OFFSET_OF_VBLK (Field), \
+ SIZE_OF_VBLK (Field), \
+ sizeof *(Pointer), \
+ (Pointer) \
))
@@ -228,7 +229,7 @@ VerifyReadWriteRequest (
@retval EFI_SUCCESS Transfer complete.
- @retval EFI_DEVICE_ERROR Failed to notify host side via VirtIo write, or
+ @retval EFI_DEVICE_ERROR Failed to notify host side via VirtIo write, or
unable to parse host response, or host response
is not VIRTIO_BLK_S_OK.
@@ -323,7 +324,7 @@ SynchronousRequest (
//
// virtio-blk's only virtqueue is #0, called "requestq" (see Appendix D).
//
- if (VirtioFlush (Dev->VirtIo, 0, &Dev->Ring, &Indices) == EFI_SUCCESS &&
+ if (VirtioFlush (Dev->VirtIo, 0, &Dev->Ring, &Indices) == EFI_SUCCESS &&
HostStatus == VIRTIO_BLK_S_OK) {
return EFI_SUCCESS;
}
@@ -510,11 +511,11 @@ VirtioBlkFlushBlocks (
@retval EFI_SUCCESS The driver supports the device being probed.
- @retval EFI_UNSUPPORTED Based on virtio-blk discovery, we do not support
+ @retval EFI_UNSUPPORTED Based on virtio-blk discovery, we do not support
the device.
@return Error codes from the OpenProtocol() boot service or
- the VirtIo protocol.
+ the VirtIo protocol.
**/
@@ -527,36 +528,36 @@ VirtioBlkDriverBindingSupported (
)
{
EFI_STATUS Status;
- VIRTIO_DEVICE_PROTOCOL *VirtIo;
+ VIRTIO_DEVICE_PROTOCOL *VirtIo;
//
- // Attempt to open the device with the VirtIo set of interfaces. On success,
- // the protocol is "instantiated" for the VirtIo device. Covers duplicate open
- // attempts (EFI_ALREADY_STARTED).
+ // Attempt to open the device with the VirtIo set of interfaces. On success,
+ // the protocol is "instantiated" for the VirtIo device. Covers duplicate
+ // open attempts (EFI_ALREADY_STARTED).
//
Status = gBS->OpenProtocol (
DeviceHandle, // candidate device
- &gVirtioDeviceProtocolGuid, // for generic VirtIo access
- (VOID **)&VirtIo, // handle to instantiate
+ &gVirtioDeviceProtocolGuid, // for generic VirtIo access
+ (VOID **)&VirtIo, // handle to instantiate
This->DriverBindingHandle, // requestor driver identity
DeviceHandle, // ControllerHandle, according to
// the UEFI Driver Model
- EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive VirtIo access to
+ EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive VirtIo access to
// the device; to be released
);
if (EFI_ERROR (Status)) {
return Status;
}
- if (VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_BLOCK_DEVICE) {
- Status = EFI_UNSUPPORTED;
+ if (VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_BLOCK_DEVICE) {
+ Status = EFI_UNSUPPORTED;
}
//
- // We needed VirtIo access only transitorily, to see whether we support the
+ // We needed VirtIo access only transitorily, to see whether we support the
// device or not.
//
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
return Status;
}
@@ -568,8 +569,8 @@ VirtioBlkDriverBindingSupported (
device.
@param[in out] Dev The driver instance to configure. The caller is
- responsible for Dev->VirtIo's validity (ie. working IO
- access to the underlying virtio-blk device).
+ responsible for Dev->VirtIo's validity (ie. working IO
+ access to the underlying virtio-blk device).
@retval EFI_SUCCESS Setup complete.
@@ -594,46 +595,53 @@ VirtioBlkInit (
UINT32 Features;
UINT64 NumSectors;
UINT32 BlockSize;
+ UINT8 PhysicalBlockExp;
+ UINT8 AlignmentOffset;
+ UINT32 OptIoSize;
UINT16 QueueSize;
+ PhysicalBlockExp = 0;
+ AlignmentOffset = 0;
+ OptIoSize = 0;
+
//
// Execute virtio-0.9.5, 2.2.1 Device Initialization Sequence.
//
NextDevStat = 0; // step 1 -- reset device
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto Failed;
}
NextDevStat |= VSTAT_ACK; // step 2 -- acknowledge device presence
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto Failed;
}
NextDevStat |= VSTAT_DRIVER; // step 3 -- we know how to drive it
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ if (EFI_ERROR (Status)) {
+ goto Failed;
+ }
+
+ //
+ // Set Page Size - MMIO VirtIo Specific
+ //
+ Status = Dev->VirtIo->SetPageSize (Dev->VirtIo, EFI_PAGE_SIZE);
if (EFI_ERROR (Status)) {
goto Failed;
}
//
- // Set Page Size - MMIO VirtIo Specific
- //
- Status = Dev->VirtIo->SetPageSize (Dev->VirtIo, EFI_PAGE_SIZE);
- if (EFI_ERROR (Status)) {
- goto ReleaseQueue;
- }
-
- //
// step 4a -- retrieve and validate features
//
- Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);
+ Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);
if (EFI_ERROR (Status)) {
goto Failed;
}
-
- Status = VIRTIO_CFG_READ (Dev, Capacity, &NumSectors);
+
+ Status = VIRTIO_CFG_READ (Dev, Capacity, &NumSectors);
if (EFI_ERROR (Status)) {
goto Failed;
}
@@ -643,7 +651,7 @@ VirtioBlkInit (
}
if (Features & VIRTIO_BLK_F_BLK_SIZE) {
- Status = VIRTIO_CFG_READ (Dev, BlkSize, &BlockSize);
+ Status = VIRTIO_CFG_READ (Dev, BlkSize, &BlockSize);
if (EFI_ERROR (Status)) {
goto Failed;
}
@@ -661,14 +669,36 @@ VirtioBlkInit (
BlockSize = 512;
}
+ if (Features & VIRTIO_BLK_F_TOPOLOGY) {
+ Status = VIRTIO_CFG_READ (Dev, Topology.PhysicalBlockExp,
+ &PhysicalBlockExp);
+ if (EFI_ERROR (Status)) {
+ goto Failed;
+ }
+ if (PhysicalBlockExp >= 32) {
+ Status = EFI_UNSUPPORTED;
+ goto Failed;
+ }
+
+ Status = VIRTIO_CFG_READ (Dev, Topology.AlignmentOffset, &AlignmentOffset);
+ if (EFI_ERROR (Status)) {
+ goto Failed;
+ }
+
+ Status = VIRTIO_CFG_READ (Dev, Topology.OptIoSize, &OptIoSize);
+ if (EFI_ERROR (Status)) {
+ goto Failed;
+ }
+ }
+
//
// step 4b -- allocate virtqueue
//
- Status = Dev->VirtIo->SetQueueSel (Dev->VirtIo, 0);
+ Status = Dev->VirtIo->SetQueueSel (Dev->VirtIo, 0);
if (EFI_ERROR (Status)) {
goto Failed;
}
- Status = Dev->VirtIo->GetQueueNumMax (Dev->VirtIo, &QueueSize);
+ Status = Dev->VirtIo->GetQueueNumMax (Dev->VirtIo, &QueueSize);
if (EFI_ERROR (Status)) {
goto Failed;
}
@@ -683,31 +713,36 @@ VirtioBlkInit (
}
//
- // Additional steps for MMIO: align the queue appropriately, and set the size
- Dev->VirtIo->SetQueueNum (Dev->VirtIo, QueueSize);
- Status = Dev->VirtIo->SetQueueAlign (Dev->VirtIo, EFI_PAGE_SIZE);
- if (EFI_ERROR (Status)) {
- goto ReleaseQueue;
- }
-
- //
- // step 4c -- Report GPFN (guest-physical frame number) of queue. If anything
- // fails from here on, we must release the ring resources.
+ // Additional steps for MMIO: align the queue appropriately, and set the
+ // size. If anything fails from here on, we must release the ring resources.
//
- Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
- (UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
+ Status = Dev->VirtIo->SetQueueNum (Dev->VirtIo, QueueSize);
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
-
+ Status = Dev->VirtIo->SetQueueAlign (Dev->VirtIo, EFI_PAGE_SIZE);
+ if (EFI_ERROR (Status)) {
+ goto ReleaseQueue;
+ }
+
+ //
+ // step 4c -- Report GPFN (guest-physical frame number) of queue.
+ //
+ Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
+ (UINT32) ((UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT));
+ if (EFI_ERROR (Status)) {
+ goto ReleaseQueue;
+ }
+
+
//
// step 5 -- Report understood features. There are no virtio-blk specific
// features to negotiate in virtio-0.9.5, plus we do not want any of the
// device-independent (known or unknown) VIRTIO_F_* capabilities (see
// Appendix B).
//
- Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, 0);
+ Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, 0);
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
@@ -716,15 +751,14 @@ VirtioBlkInit (
// step 6 -- initialization complete
//
NextDevStat |= VSTAT_DRIVER_OK;
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
//
- // Populate the exported interface's attributes; see UEFI spec v2.3.1 +
- // Errata C, 12.8 EFI Block I/O Protocol. We stick to the lowest possible
- // EFI_BLOCK_IO_PROTOCOL revision for now.
+ // Populate the exported interface's attributes; see UEFI spec v2.4, 12.9 EFI
+ // Block I/O Protocol.
//
Dev->BlockIo.Revision = 0;
Dev->BlockIo.Media = &Dev->BlockIoMedia;
@@ -742,6 +776,24 @@ VirtioBlkInit (
Dev->BlockIoMedia.IoAlign = 0;
Dev->BlockIoMedia.LastBlock = DivU64x32 (NumSectors,
BlockSize / 512) - 1;
+
+ DEBUG ((DEBUG_INFO, "%a: LbaSize=0x%x[B] NumBlocks=0x%Lx[Lba]\n",
+ __FUNCTION__, Dev->BlockIoMedia.BlockSize,
+ Dev->BlockIoMedia.LastBlock + 1));
+
+ if (Features & VIRTIO_BLK_F_TOPOLOGY) {
+ Dev->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION3;
+
+ Dev->BlockIoMedia.LowestAlignedLba = AlignmentOffset;
+ Dev->BlockIoMedia.LogicalBlocksPerPhysicalBlock = 1u << PhysicalBlockExp;
+ Dev->BlockIoMedia.OptimalTransferLengthGranularity = OptIoSize;
+
+ DEBUG ((DEBUG_INFO, "%a: FirstAligned=0x%Lx[Lba] PhysBlkSize=0x%x[Lba]\n",
+ __FUNCTION__, Dev->BlockIoMedia.LowestAlignedLba,
+ Dev->BlockIoMedia.LogicalBlocksPerPhysicalBlock));
+ DEBUG ((DEBUG_INFO, "%a: OptimalTransferLengthGranularity=0x%x[Lba]\n",
+ __FUNCTION__, Dev->BlockIoMedia.OptimalTransferLengthGranularity));
+ }
return EFI_SUCCESS;
ReleaseQueue:
@@ -750,10 +802,10 @@ ReleaseQueue:
Failed:
//
// Notify the host about our failure to setup: virtio-0.9.5, 2.2.2.1 Device
- // Status. VirtIo access failure here should not mask the original error.
+ // Status. VirtIo access failure here should not mask the original error.
//
NextDevStat |= VSTAT_FAILED;
- Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
return Status; // reached only via Failed above
}
@@ -780,7 +832,7 @@ VirtioBlkUninit (
// VIRTIO_CFG_WRITE() returns, the host will have learned to stay away from
// the old comms area.
//
- Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
+ Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
VirtioRingUninit (&Dev->Ring);
@@ -807,13 +859,13 @@ VirtioBlkUninit (
@retval EFI_SUCCESS Driver instance has been created and
- initialized for the virtio-blk device, it
+ initialized for the virtio-blk device, it
is now accessibla via EFI_BLOCK_IO_PROTOCOL.
@retval EFI_OUT_OF_RESOURCES Memory allocation failed.
@return Error codes from the OpenProtocol() boot
- service, the VirtIo protocol, VirtioBlkInit(),
+ service, the VirtIo protocol, VirtioBlkInit(),
or the InstallProtocolInterface() boot service.
**/
@@ -834,23 +886,19 @@ VirtioBlkDriverBindingStart (
return EFI_OUT_OF_RESOURCES;
}
- Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
- (VOID **)&Dev->VirtIo, This->DriverBindingHandle,
+ Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ (VOID **)&Dev->VirtIo, This->DriverBindingHandle,
DeviceHandle, EFI_OPEN_PROTOCOL_BY_DRIVER);
if (EFI_ERROR (Status)) {
goto FreeVirtioBlk;
}
- if (Dev->VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_BLOCK_DEVICE) {
- return EFI_UNSUPPORTED;
- }
-
//
- // VirtIo access granted, configure virtio-blk device.
+ // VirtIo access granted, configure virtio-blk device.
//
Status = VirtioBlkInit (Dev);
if (EFI_ERROR (Status)) {
- goto CloseVirtIo;
+ goto CloseVirtIo;
}
//
@@ -869,8 +917,8 @@ VirtioBlkDriverBindingStart (
UninitDev:
VirtioBlkUninit (Dev);
-CloseVirtIo:
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+CloseVirtIo:
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
FreeVirtioBlk:
@@ -941,7 +989,7 @@ VirtioBlkDriverBindingStop (
VirtioBlkUninit (Dev);
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
FreePool (Dev);
diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.h b/OvmfPkg/VirtioBlkDxe/VirtioBlk.h
index 43dd5064d..789caf9a3 100644
--- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.h
+++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.h
@@ -33,13 +33,13 @@ typedef struct {
// at various call depths. The table to the right should make it easier to
// track them.
//
- // field init function init dpth
- // --------------------- ------------------ ---------
- UINT32 Signature; // DriverBindingStart 0
- VIRTIO_DEVICE_PROTOCOL *VirtIo; // DriverBindingStart 0
- VRING Ring; // VirtioRingInit 2
- EFI_BLOCK_IO_PROTOCOL BlockIo; // VirtioBlkInit 1
- EFI_BLOCK_IO_MEDIA BlockIoMedia; // VirtioBlkInit 1
+ // field init function init dpth
+ // --------------------- ------------------ ---------
+ UINT32 Signature; // DriverBindingStart 0
+ VIRTIO_DEVICE_PROTOCOL *VirtIo; // DriverBindingStart 0
+ VRING Ring; // VirtioRingInit 2
+ EFI_BLOCK_IO_PROTOCOL BlockIo; // VirtioBlkInit 1
+ EFI_BLOCK_IO_MEDIA BlockIoMedia; // VirtioBlkInit 1
} VBLK_DEV;
#define VIRTIO_BLK_FROM_BLOCK_IO(BlockIoPointer) \
@@ -75,10 +75,10 @@ typedef struct {
@retval EFI_SUCCESS The driver supports the device being probed.
- @retval EFI_UNSUPPORTED Based on virtio-blk discovery, we do not support
+ @retval EFI_UNSUPPORTED Based on virtio-blk discovery, we do not support
the device.
- @return Error codes from the OpenProtocol() boot service.
+ @return Error codes from the OpenProtocol() boot service.
**/
@@ -109,14 +109,14 @@ VirtioBlkDriverBindingSupported (
@retval EFI_SUCCESS Driver instance has been created and
- initialized for the virtio-blk device, it
+ initialized for the virtio-blk device, it
is now accessibla via EFI_BLOCK_IO_PROTOCOL.
@retval EFI_OUT_OF_RESOURCES Memory allocation failed.
@return Error codes from the OpenProtocol() boot
- service, VirtioBlkInit(), or the
- InstallProtocolInterface() boot service.
+ service, VirtioBlkInit(), or the
+ InstallProtocolInterface() boot service.
**/
diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.inf b/OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
index 86266b26c..d5975b74e 100644
--- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
+++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
@@ -38,5 +38,5 @@
VirtioLib
[Protocols]
- gEfiBlockIoProtocolGuid ## BY_START
- gVirtioDeviceProtocolGuid ## TO_START
+ gEfiBlockIoProtocolGuid ## BY_START
+ gVirtioDeviceProtocolGuid ## TO_START
diff --git a/OvmfPkg/VirtioNetDxe/ComponentName.c b/OvmfPkg/VirtioNetDxe/ComponentName.c
index 1a43448fd..2c96adbcb 100644
--- a/OvmfPkg/VirtioNetDxe/ComponentName.c
+++ b/OvmfPkg/VirtioNetDxe/ComponentName.c
@@ -139,20 +139,20 @@ VirtioNetGetControllerName (
}
//
- // confirm that the device is managed by this driver, using the VirtIo
+ // confirm that the device is managed by this driver, using the VirtIo
// Protocol
//
Status = EfiTestManagedDevice (
ControllerHandle,
gVirtioNetDriverBinding.DriverBindingHandle,
- &gVirtioDeviceProtocolGuid
+ &gVirtioDeviceProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
}
//
- // we don't give different names to the bus (= parent) handle and the
+ // we don't give different names to the bus (= parent) handle and the
// child (= MAC) handle
//
return LookupUnicodeString2 (
diff --git a/OvmfPkg/VirtioNetDxe/DriverBinding.c b/OvmfPkg/VirtioNetDxe/DriverBinding.c
index f92a447f0..93995c635 100644
--- a/OvmfPkg/VirtioNetDxe/DriverBinding.c
+++ b/OvmfPkg/VirtioNetDxe/DriverBinding.c
@@ -49,8 +49,7 @@
unused.
@retval EFI_UNSUPPORTED The host doesn't supply a MAC address.
- @return Status codes from Dev->VirtIo->Io.Read(),
- VIRTIO_CFG_READ() and VIRTIO_CFG_WRITE().
+ @return Status codes from VirtIo protocol members.
@retval EFI_SUCCESS Configuration values retrieved.
*/
STATIC
@@ -66,6 +65,7 @@ VirtioNetGetFeatures (
EFI_STATUS Status;
UINT8 NextDevStat;
UINT32 Features;
+ UINTN MacIdx;
UINT16 LinkStatus;
//
@@ -73,19 +73,19 @@ VirtioNetGetFeatures (
// Initialization Sequence), but don't complete setting it up.
//
NextDevStat = 0; // step 1 -- reset device
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
return Status;
}
NextDevStat |= VSTAT_ACK; // step 2 -- acknowledge device presence
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto YieldDevice;
}
NextDevStat |= VSTAT_DRIVER; // step 3 -- we know how to drive it
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto YieldDevice;
}
@@ -93,7 +93,7 @@ VirtioNetGetFeatures (
//
// step 4a -- retrieve and validate features
//
- Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);
+ Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);
if (EFI_ERROR (Status)) {
goto YieldDevice;
}
@@ -105,15 +105,16 @@ VirtioNetGetFeatures (
Status = EFI_UNSUPPORTED;
goto YieldDevice;
}
- Status = Dev->VirtIo->ReadDevice (Dev->VirtIo,
- OFFSET_OF_VNET (Mac), // Offset
- sizeof(UINT8), // FieldSize
- SIZE_OF_VNET (Mac), // BufferSize
- MacAddress // Buffer
- );
-
- if (EFI_ERROR (Status)) {
- goto YieldDevice;
+ for (MacIdx = 0; MacIdx < SIZE_OF_VNET (Mac); ++MacIdx) {
+ Status = Dev->VirtIo->ReadDevice (Dev->VirtIo,
+ OFFSET_OF_VNET (Mac) + MacIdx, // Offset
+ 1, // FieldSize
+ 1, // BufferSize
+ &MacAddress->Addr[MacIdx] // Buffer
+ );
+ if (EFI_ERROR (Status)) {
+ goto YieldDevice;
+ }
}
//
@@ -124,7 +125,7 @@ VirtioNetGetFeatures (
}
else {
*MediaPresentSupported = TRUE;
- Status = VIRTIO_CFG_READ (Dev, LinkStatus, &LinkStatus);
+ Status = VIRTIO_CFG_READ (Dev, LinkStatus, &LinkStatus);
if (EFI_ERROR (Status)) {
goto YieldDevice;
}
@@ -132,7 +133,7 @@ VirtioNetGetFeatures (
}
YieldDevice:
- Dev->VirtIo->SetDeviceStatus (Dev->VirtIo,
+ Dev->VirtIo->SetDeviceStatus (Dev->VirtIo,
EFI_ERROR (Status) ? VSTAT_FAILED : 0);
return Status;
@@ -205,9 +206,9 @@ VirtioNetSnpPopulate (
Dev->Snp.Mode = &Dev->Snm;
Dev->Snm.State = EfiSimpleNetworkStopped;
- Dev->Snm.HwAddressSize = SIZE_OF_VNET (Mac);
- Dev->Snm.MediaHeaderSize = SIZE_OF_VNET (Mac) + // dst MAC
- SIZE_OF_VNET (Mac) + // src MAC
+ Dev->Snm.HwAddressSize = SIZE_OF_VNET (Mac);
+ Dev->Snm.MediaHeaderSize = SIZE_OF_VNET (Mac) + // dst MAC
+ SIZE_OF_VNET (Mac) + // src MAC
2; // Ethertype
Dev->Snm.MaxPacketSize = 1500;
Dev->Snm.NvRamSize = 0;
@@ -220,7 +221,7 @@ VirtioNetSnpPopulate (
Dev->Snm.MacAddressChangeable = FALSE;
Dev->Snm.MultipleTxSupported = TRUE;
- ASSERT (SIZE_OF_VNET (Mac) <= sizeof (EFI_MAC_ADDRESS));
+ ASSERT (SIZE_OF_VNET (Mac) <= sizeof (EFI_MAC_ADDRESS));
Status = VirtioNetGetFeatures (Dev, &Dev->Snm.CurrentAddress,
&Dev->Snm.MediaPresentSupported, &Dev->Snm.MediaPresent);
@@ -228,8 +229,8 @@ VirtioNetSnpPopulate (
goto CloseWaitForPacket;
}
CopyMem (&Dev->Snm.PermanentAddress, &Dev->Snm.CurrentAddress,
- SIZE_OF_VNET (Mac));
- SetMem (&Dev->Snm.BroadcastAddress, SIZE_OF_VNET (Mac), 0xFF);
+ SIZE_OF_VNET (Mac));
+ SetMem (&Dev->Snm.BroadcastAddress, SIZE_OF_VNET (Mac), 0xFF);
//
// VirtioNetExitBoot() is queued by ExitBootServices(); its purpose is to
@@ -346,36 +347,36 @@ VirtioNetDriverBindingSupported (
)
{
EFI_STATUS Status;
- VIRTIO_DEVICE_PROTOCOL *VirtIo;
-
- //
- // Attempt to open the device with the VirtIo set of interfaces. On success,
- // the protocol is "instantiated" for the VirtIo device. Covers duplicate open
- // attempts (EFI_ALREADY_STARTED).
- //
- Status = gBS->OpenProtocol (
- DeviceHandle, // candidate device
- &gVirtioDeviceProtocolGuid, // for generic VirtIo access
- (VOID **)&VirtIo, // handle to instantiate
- This->DriverBindingHandle, // requestor driver identity
- DeviceHandle, // ControllerHandle, according to
- // the UEFI Driver Model
- EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive VirtIo access to
- // the device; to be released
- );
+ VIRTIO_DEVICE_PROTOCOL *VirtIo;
+
+ //
+ // Attempt to open the device with the VirtIo set of interfaces. On success,
+ // the protocol is "instantiated" for the VirtIo device. Covers duplicate open
+ // attempts (EFI_ALREADY_STARTED).
+ //
+ Status = gBS->OpenProtocol (
+ DeviceHandle, // candidate device
+ &gVirtioDeviceProtocolGuid, // for generic VirtIo access
+ (VOID **)&VirtIo, // handle to instantiate
+ This->DriverBindingHandle, // requestor driver identity
+ DeviceHandle, // ControllerHandle, according to
+ // the UEFI Driver Model
+ EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive VirtIo access to
+ // the device; to be released
+ );
if (EFI_ERROR (Status)) {
return Status;
}
- if (VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_NETWORK_CARD) {
- Status = EFI_UNSUPPORTED;
- }
+ if (VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_NETWORK_CARD) {
+ Status = EFI_UNSUPPORTED;
+ }
//
- // We needed VirtIo access only transitorily, to see whether we support the
- // device or not.
+ // We needed VirtIo access only transitorily, to see whether we support the
+ // device or not.
//
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
return Status;
}
@@ -441,7 +442,7 @@ VirtioNetDriverBindingStart (
VNET_DEV *Dev;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
MAC_ADDR_DEVICE_PATH MacNode;
- VOID *ChildVirtIo;
+ VOID *ChildVirtIo;
//
// allocate space for the driver instance
@@ -452,28 +453,24 @@ VirtioNetDriverBindingStart (
}
Dev->Signature = VNET_SIG;
- Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
- (VOID **)&Dev->VirtIo, This->DriverBindingHandle,
+ Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ (VOID **)&Dev->VirtIo, This->DriverBindingHandle,
DeviceHandle, EFI_OPEN_PROTOCOL_BY_DRIVER);
if (EFI_ERROR (Status)) {
goto FreeVirtioNet;
}
- if (Dev->VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_NETWORK_CARD) {
- return EFI_UNSUPPORTED;
- }
-
//
// now we can run a basic one-shot virtio-net initialization required to
// retrieve the MAC address
//
Status = VirtioNetSnpPopulate (Dev);
if (EFI_ERROR (Status)) {
- goto CloseVirtIo;
+ goto CloseVirtIo;
}
//
- // get the device path of the virtio-net device -- one-shot open
+ // get the device path of the virtio-net device -- one-shot open
//
Status = gBS->OpenProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid,
(VOID **)&DevicePath, This->DriverBindingHandle,
@@ -511,11 +508,11 @@ VirtioNetDriverBindingStart (
}
//
- // make a note that we keep this device open with VirtIo for the sake of this
+ // make a note that we keep this device open with VirtIo for the sake of this
// child
//
- Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
- &ChildVirtIo, This->DriverBindingHandle,
+ Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ &ChildVirtIo, This->DriverBindingHandle,
Dev->MacHandle, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER);
if (EFI_ERROR (Status)) {
goto UninstallMultiple;
@@ -535,8 +532,8 @@ FreeMacDevicePath:
Evacuate:
VirtioNetSnpEvacuate (Dev);
-CloseVirtIo:
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+CloseVirtIo:
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
FreeVirtioNet:
@@ -621,7 +618,7 @@ VirtioNetDriverBindingStop (
Status = EFI_DEVICE_ERROR;
}
else {
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, Dev->MacHandle);
gBS->UninstallMultipleProtocolInterfaces (Dev->MacHandle,
&gEfiDevicePathProtocolGuid, Dev->MacDevicePath,
@@ -639,7 +636,7 @@ VirtioNetDriverBindingStop (
//
// release remaining resources, tied directly to the parent handle
//
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
return EFI_SUCCESS;
diff --git a/OvmfPkg/VirtioNetDxe/Events.c b/OvmfPkg/VirtioNetDxe/Events.c
index 4889580f3..5be1af6ff 100644
--- a/OvmfPkg/VirtioNetDxe/Events.c
+++ b/OvmfPkg/VirtioNetDxe/Events.c
@@ -86,6 +86,6 @@ VirtioNetExitBoot (
Dev = Context;
if (Dev->Snm.State == EfiSimpleNetworkInitialized) {
- Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
+ Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
}
}
diff --git a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c b/OvmfPkg/VirtioNetDxe/SnpGetStatus.c
index b92011561..4393d243a 100644
--- a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c
+++ b/OvmfPkg/VirtioNetDxe/SnpGetStatus.c
@@ -90,7 +90,7 @@ VirtioNetGetStatus (
if (Dev->Snm.MediaPresentSupported) {
UINT16 LinkStatus;
- Status = VIRTIO_CFG_READ (Dev, LinkStatus, &LinkStatus);
+ Status = VIRTIO_CFG_READ (Dev, LinkStatus, &LinkStatus);
if (EFI_ERROR (Status)) {
goto Exit;
}
diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
index 4352ab96b..223030af9 100644
--- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c
+++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
@@ -57,15 +57,15 @@ VirtioNetInitRing (
//
// step 4b -- allocate selected queue
//
- Status = Dev->VirtIo->SetQueueSel (Dev->VirtIo, Selector);
+ Status = Dev->VirtIo->SetQueueSel (Dev->VirtIo, Selector);
if (EFI_ERROR (Status)) {
return Status;
}
- Status = Dev->VirtIo->GetQueueNumMax (Dev->VirtIo, &QueueSize);
+ Status = Dev->VirtIo->GetQueueNumMax (Dev->VirtIo, &QueueSize);
if (EFI_ERROR (Status)) {
return Status;
}
-
+
//
// For each packet (RX and TX alike), we need two descriptors:
// one for the virtio-net request header, and another one for the data
@@ -79,13 +79,33 @@ VirtioNetInitRing (
}
//
+ // Additional steps for MMIO: align the queue appropriately, and set the
+ // size. If anything fails from here on, we must release the ring resources.
+ //
+ Status = Dev->VirtIo->SetQueueNum (Dev->VirtIo, QueueSize);
+ if (EFI_ERROR (Status)) {
+ goto ReleaseQueue;
+ }
+
+ Status = Dev->VirtIo->SetQueueAlign (Dev->VirtIo, EFI_PAGE_SIZE);
+ if (EFI_ERROR (Status)) {
+ goto ReleaseQueue;
+ }
+
+ //
// step 4c -- report GPFN (guest-physical frame number) of queue
//
- Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
- (UINTN) Ring->Base >> EFI_PAGE_SHIFT);
+ Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
+ (UINT32) ((UINTN) Ring->Base >> EFI_PAGE_SHIFT));
if (EFI_ERROR (Status)) {
- VirtioRingUninit (Ring);
+ goto ReleaseQueue;
}
+
+ return EFI_SUCCESS;
+
+ReleaseQueue:
+ VirtioRingUninit (Ring);
+
return Status;
}
@@ -288,9 +308,9 @@ VirtioNetInitRx (
// virtio-0.9.5, 2.4.1.4 Notifying the Device
//
MemoryFence ();
- Status = Dev->VirtIo->SetQueueNotify (Dev->VirtIo, VIRTIO_NET_Q_RX);
+ Status = Dev->VirtIo->SetQueueNotify (Dev->VirtIo, VIRTIO_NET_Q_RX);
if (EFI_ERROR (Status)) {
- Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
+ Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
FreePool (Dev->RxBuf);
}
@@ -366,34 +386,34 @@ VirtioNetInitialize (
// virtio-0.9.5 spec, 2.2.1 Device Initialization Sequence.
//
NextDevStat = VSTAT_ACK; // step 2 -- acknowledge device presence
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto InitFailed;
}
NextDevStat |= VSTAT_DRIVER; // step 3 -- we know how to drive it
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ if (EFI_ERROR (Status)) {
+ goto DeviceFailed;
+ }
+
+ //
+ // Set Page Size - MMIO VirtIo Specific
+ //
+ Status = Dev->VirtIo->SetPageSize (Dev->VirtIo, EFI_PAGE_SIZE);
if (EFI_ERROR (Status)) {
goto DeviceFailed;
}
//
- // Set Page Size - MMIO VirtIo Specific
- //
- Status = Dev->VirtIo->SetPageSize (Dev->VirtIo, EFI_PAGE_SIZE);
- if (EFI_ERROR (Status)) {
- goto ReleaseTxRing;
- }
-
- //
// step 4a -- retrieve features. Note that we're past validating required
// features in VirtioNetGetFeatures().
//
- Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);
+ Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);
if (EFI_ERROR (Status)) {
goto DeviceFailed;
}
-
+
ASSERT (Features & VIRTIO_NET_F_MAC);
ASSERT (Dev->Snm.MediaPresentSupported ==
!!(Features & VIRTIO_NET_F_STATUS));
@@ -415,7 +435,7 @@ VirtioNetInitialize (
// step 5 -- keep only the features we want
//
Features &= VIRTIO_NET_F_MAC | VIRTIO_NET_F_STATUS;
- Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features);
+ Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features);
if (EFI_ERROR (Status)) {
goto ReleaseTxRing;
}
@@ -424,7 +444,7 @@ VirtioNetInitialize (
// step 6 -- virtio-net initialization complete
//
NextDevStat |= VSTAT_DRIVER_OK;
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto ReleaseTxRing;
}
@@ -450,7 +470,7 @@ ReleaseTxAux:
VirtioNetShutdownTx (Dev);
AbortDevice:
- Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
+ Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
ReleaseTxRing:
VirtioRingUninit (&Dev->TxRing);
@@ -462,7 +482,7 @@ DeviceFailed:
//
// restore device status invariant for the EfiSimpleNetworkStarted state
//
- Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
+ Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
InitFailed:
gBS->RestoreTPL (OldTpl);
diff --git a/OvmfPkg/VirtioNetDxe/SnpReceive.c b/OvmfPkg/VirtioNetDxe/SnpReceive.c
index ce87978f1..99abd7ebe 100644
--- a/OvmfPkg/VirtioNetDxe/SnpReceive.c
+++ b/OvmfPkg/VirtioNetDxe/SnpReceive.c
@@ -147,14 +147,14 @@ VirtioNetReceive (
CopyMem (Buffer, RxPtr, RxLen);
if (DestAddr != NULL) {
- CopyMem (DestAddr, RxPtr, SIZE_OF_VNET (Mac));
+ CopyMem (DestAddr, RxPtr, SIZE_OF_VNET (Mac));
}
- RxPtr += SIZE_OF_VNET (Mac);
+ RxPtr += SIZE_OF_VNET (Mac);
if (SrcAddr != NULL) {
- CopyMem (SrcAddr, RxPtr, SIZE_OF_VNET (Mac));
+ CopyMem (SrcAddr, RxPtr, SIZE_OF_VNET (Mac));
}
- RxPtr += SIZE_OF_VNET (Mac);
+ RxPtr += SIZE_OF_VNET (Mac);
if (Protocol != NULL) {
*Protocol = (UINT16) ((RxPtr[0] << 8) | RxPtr[1]);
@@ -177,7 +177,7 @@ RecycleDesc:
*Dev->RxRing.Avail.Idx = AvailIdx;
MemoryFence ();
- NotifyStatus = Dev->VirtIo->SetQueueNotify (Dev->VirtIo, VIRTIO_NET_Q_RX);
+ NotifyStatus = Dev->VirtIo->SetQueueNotify (Dev->VirtIo, VIRTIO_NET_Q_RX);
if (!EFI_ERROR (Status)) { // earlier error takes precedence
Status = NotifyStatus;
}
diff --git a/OvmfPkg/VirtioNetDxe/SnpShutdown.c b/OvmfPkg/VirtioNetDxe/SnpShutdown.c
index c05a22f65..01409c0ce 100644
--- a/OvmfPkg/VirtioNetDxe/SnpShutdown.c
+++ b/OvmfPkg/VirtioNetDxe/SnpShutdown.c
@@ -63,7 +63,7 @@ VirtioNetShutdown (
break;
}
- Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
+ Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
VirtioNetShutdownRx (Dev);
VirtioNetShutdownTx (Dev);
VirtioRingUninit (&Dev->TxRing);
diff --git a/OvmfPkg/VirtioNetDxe/SnpTransmit.c b/OvmfPkg/VirtioNetDxe/SnpTransmit.c
index b2a364b96..7ca40d5d0 100644
--- a/OvmfPkg/VirtioNetDxe/SnpTransmit.c
+++ b/OvmfPkg/VirtioNetDxe/SnpTransmit.c
@@ -127,15 +127,15 @@ VirtioNetTransmit (
goto Exit;
}
Ptr = Buffer;
- ASSERT (SIZE_OF_VNET (Mac) <= sizeof (EFI_MAC_ADDRESS));
+ ASSERT (SIZE_OF_VNET (Mac) <= sizeof (EFI_MAC_ADDRESS));
- CopyMem (Ptr, DestAddr, SIZE_OF_VNET (Mac));
- Ptr += SIZE_OF_VNET (Mac);
+ CopyMem (Ptr, DestAddr, SIZE_OF_VNET (Mac));
+ Ptr += SIZE_OF_VNET (Mac);
CopyMem (Ptr,
(SrcAddr == NULL) ? &Dev->Snm.CurrentAddress : SrcAddr,
- SIZE_OF_VNET (Mac));
- Ptr += SIZE_OF_VNET (Mac);
+ SIZE_OF_VNET (Mac));
+ Ptr += SIZE_OF_VNET (Mac);
*Ptr++ = (UINT8) (*Protocol >> 8);
*Ptr++ = (UINT8) *Protocol;
@@ -161,7 +161,7 @@ VirtioNetTransmit (
*Dev->TxRing.Avail.Idx = AvailIdx;
MemoryFence ();
- Status = Dev->VirtIo->SetQueueNotify (Dev->VirtIo, VIRTIO_NET_Q_TX);
+ Status = Dev->VirtIo->SetQueueNotify (Dev->VirtIo, VIRTIO_NET_Q_TX);
Exit:
gBS->RestoreTPL (OldTpl);
diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/VirtioNet.h
index a0e0b4337..2d3f3d87e 100644
--- a/OvmfPkg/VirtioNetDxe/VirtioNet.h
+++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h
@@ -74,7 +74,7 @@ typedef struct {
// field init function
// ------------------ ------------------------------
UINT32 Signature; // VirtioNetDriverBindingStart
- VIRTIO_DEVICE_PROTOCOL *VirtIo; // VirtioNetDriverBindingStart
+ VIRTIO_DEVICE_PROTOCOL *VirtIo; // VirtioNetDriverBindingStart
EFI_SIMPLE_NETWORK_PROTOCOL Snp; // VirtioNetSnpPopulate
EFI_SIMPLE_NETWORK_MODE Snm; // VirtioNetSnpPopulate
EFI_EVENT ExitBoot; // VirtioNetSnpPopulate
@@ -107,19 +107,19 @@ typedef struct {
#define VIRTIO_NET_FROM_SNP(SnpPointer) \
CR (SnpPointer, VNET_DEV, Snp, VNET_SIG)
-#define VIRTIO_CFG_WRITE(Dev, Field, Value) ((Dev)->VirtIo->WriteDevice ( \
- (Dev)->VirtIo, \
- OFFSET_OF_VNET (Field), \
- SIZE_OF_VNET (Field), \
- (Value) \
+#define VIRTIO_CFG_WRITE(Dev, Field, Value) ((Dev)->VirtIo->WriteDevice ( \
+ (Dev)->VirtIo, \
+ OFFSET_OF_VNET (Field), \
+ SIZE_OF_VNET (Field), \
+ (Value) \
))
-#define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice ( \
- (Dev)->VirtIo, \
- OFFSET_OF_VNET (Field), \
- SIZE_OF_VNET (Field), \
- sizeof *(Pointer), \
- (Pointer) \
+#define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice ( \
+ (Dev)->VirtIo, \
+ OFFSET_OF_VNET (Field), \
+ SIZE_OF_VNET (Field), \
+ sizeof *(Pointer), \
+ (Pointer) \
))
//
diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.inf b/OvmfPkg/VirtioNetDxe/VirtioNet.inf
index dea01f3b9..a855ad4ac 100644
--- a/OvmfPkg/VirtioNetDxe/VirtioNet.inf
+++ b/OvmfPkg/VirtioNetDxe/VirtioNet.inf
@@ -57,4 +57,4 @@
[Protocols]
gEfiSimpleNetworkProtocolGuid ## BY_START
gEfiDevicePathProtocolGuid ## BY_START
- gVirtioDeviceProtocolGuid ## TO_START
+ gVirtioDeviceProtocolGuid ## TO_START
diff --git a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.c b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.c
index b120d5f2c..2647bd391 100644
--- a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.c
+++ b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.c
@@ -1,667 +1,680 @@
-/** @file
-
- This driver produces Virtio Device Protocol instances for Virtio PCI 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 <IndustryStandard/Pci.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-
-#include "VirtioPciDevice.h"
-
-STATIC VIRTIO_DEVICE_PROTOCOL mDeviceProtocolTemplate = {
- 0, // Revision
- 0, // SubSystemDeviceId
- VirtioPciGetDeviceFeatures, // GetDeviceFeatures
- VirtioPciSetGuestFeatures, // SetGuestFeatures
- VirtioPciGetQueueAddress, // GetQueueAddress
- VirtioPciSetQueueAddress, // SetQueueAddress
- VirtioPciSetQueueSel, // SetQueueSel
- VirtioPciSetQueueNotify, // SetQueueNotify
- VirtioPciSetQueueAlignment, // SetQueueAlignment
- VirtioPciSetPageSize, // SetPageSize
- VirtioPciGetQueueSize, // GetQueueNumMax
- VirtioPciSetQueueSize, // SetQueueNum
- VirtioPciGetDeviceStatus, // GetDeviceStatus
- VirtioPciSetDeviceStatus, // SetDeviceStatus
- VirtioPciDeviceWrite, // WriteDevice
- VirtioPciDeviceRead // ReadDevice
-};
-
-/**
-
- Read a word from Region 0 of the device specified by PciIo.
-
- Region 0 must be an iomem region. This is an internal function for the PCI
- implementation of the protocol.
-
- @param[in] Dev Virtio PCI device.
-
- @param[in] FieldOffset Source offset.
-
- @param[in] FieldSize Source field size, must be in { 1, 2, 4, 8 }.
-
- @param[in] BufferSize Number of bytes available in the target buffer. Must
- equal FieldSize.
-
- @param[out] Buffer Target buffer.
-
-
- @return Status code returned by PciIo->Io.Read().
-
-**/
-EFI_STATUS
-EFIAPI
-VirtioPciIoRead (
- IN VIRTIO_PCI_DEVICE *Dev,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINTN BufferSize,
- OUT VOID *Buffer
- )
-{
- UINTN Count;
- EFI_PCI_IO_PROTOCOL_WIDTH Width;
- EFI_PCI_IO_PROTOCOL *PciIo;
-
- // The BufferSize must be a multiple of FieldSize
- ASSERT ((BufferSize % FieldSize) == 0);
-
- PciIo = Dev->PciIo;
- Count = BufferSize / FieldSize;
-
- switch (FieldSize) {
- case 1:
- Width = EfiPciIoWidthUint8;
- break;
-
- case 2:
- Width = EfiPciIoWidthUint16;
- break;
-
- case 8:
- // The 64bit PCI I/O is broken down into two 32bit reads to prevent
- // any alignment or width issues.
- // The UEFI spec says under EFI_PCI_IO_PROTOCOL.Io.Write():
- //
- // The I/O operations are carried out exactly as requested. The caller
- // is responsible for any alignment and I/O width issues which the
- // bus, device, platform, or type of I/O might require. For example on
- // some platforms, width requests of EfiPciIoWidthUint64 do not work
- Count = Count * 2;
- // fall through
-
- case 4:
- Width = EfiPciIoWidthUint32;
- break;
-
- default:
- ASSERT (FALSE);
- return EFI_INVALID_PARAMETER;
- }
-
- return PciIo->Io.Read (
- PciIo,
- Width,
- PCI_BAR_IDX0,
- FieldOffset,
- Count,
- Buffer
- );
-}
-
-/**
-
- Write a word into Region 0 of the device specified by PciIo.
-
- Region 0 must be an iomem region. This is an internal function for the PCI
- implementation of the protocol.
-
- @param[in] Dev Virtio PCI device.
-
- @param[in] FieldOffset Destination offset.
-
- @param[in] FieldSize Destination field size, must be in { 1, 2, 4, 8 }.
-
- @param[in] Value Little endian value to write, converted to UINT64.
- The least significant FieldSize bytes will be used.
-
-
- @return Status code returned by PciIo->Io.Write().
-
-**/
-EFI_STATUS
-EFIAPI
-VirtioPciIoWrite (
- IN VIRTIO_PCI_DEVICE *Dev,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINT64 Value
- )
-{
- UINTN Count;
- EFI_PCI_IO_PROTOCOL_WIDTH Width;
- EFI_PCI_IO_PROTOCOL *PciIo;
-
- PciIo = Dev->PciIo;
- Count = 1;
-
- switch (FieldSize) {
- case 1:
- Width = EfiPciIoWidthUint8;
- break;
-
- case 2:
- Width = EfiPciIoWidthUint16;
- break;
-
- case 8:
- // The 64bit PCI I/O is broken down into two 32bit writes to prevent
- // any alignment or width issues.
- // The UEFI spec says under EFI_PCI_IO_PROTOCOL.Io.Write():
- //
- // The I/O operations are carried out exactly as requested. The caller
- // is responsible for any alignment and I/O width issues which the
- // bus, device, platform, or type of I/O might require. For example on
- // some platforms, width requests of EfiPciIoWidthUint64 do not work
- Count = Count * 2;
- // fall through
-
- case 4:
- Width = EfiPciIoWidthUint32;
- break;
-
- default:
- ASSERT (FALSE);
- return EFI_INVALID_PARAMETER;
- }
-
- return PciIo->Io.Write (
- PciIo,
- Width,
- PCI_BAR_IDX0,
- FieldOffset,
- Count,
- &Value
- );
-}
-
-/**
-
- Device probe function for this driver.
-
- The DXE core calls this function for any given device in order to see if the
- driver can drive the device.
-
- @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
- incorporating this driver (independently of
- any device).
-
- @param[in] DeviceHandle The device to probe.
-
- @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.
-
-
- @retval EFI_SUCCESS The driver supports the device being probed.
-
- @retval EFI_UNSUPPORTED Based on virtio-pci discovery, we do not support
- the device.
-
- @return Error codes from the OpenProtocol() boot service or
- the PciIo protocol.
-
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-VirtioPciDeviceBindingSupported (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE DeviceHandle,
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
- )
-{
- EFI_STATUS Status;
- EFI_PCI_IO_PROTOCOL *PciIo;
- PCI_TYPE00 Pci;
-
- //
- // Attempt to open the device with the PciIo set of interfaces. On success,
- // the protocol is "instantiated" for the PCI device. Covers duplicate open
- // attempts (EFI_ALREADY_STARTED).
- //
- Status = gBS->OpenProtocol (
- DeviceHandle, // candidate device
- &gEfiPciIoProtocolGuid, // for generic PCI access
- (VOID **)&PciIo, // handle to instantiate
- This->DriverBindingHandle, // requestor driver identity
- DeviceHandle, // ControllerHandle, according to
- // the UEFI Driver Model
- EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive PciIo access to
- // the device; to be released
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Read entire PCI configuration header for more extensive check ahead.
- //
- Status = PciIo->Pci.Read (
- PciIo, // (protocol, device)
- // handle
- EfiPciIoWidthUint32, // access width & copy
- // mode
- 0, // Offset
- sizeof Pci / sizeof (UINT32), // Count
- &Pci // target buffer
- );
-
- if (Status == EFI_SUCCESS) {
- //
- // virtio-0.9.5, 2.1 PCI Discovery
- //
- if ((Pci.Hdr.VendorId == VIRTIO_VENDOR_ID) &&
- (Pci.Hdr.DeviceId >= 0x1000) &&
- (Pci.Hdr.DeviceId <= 0x103F) &&
- (Pci.Hdr.RevisionID == 0x00)) {
- Status = EFI_SUCCESS;
- } else {
- Status = EFI_UNSUPPORTED;
- }
- }
-
- //
- // We needed PCI IO access only transitorily, to see whether we support the
- // device or not.
- //
- gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
- This->DriverBindingHandle, DeviceHandle);
-
- return Status;
-}
-
-/**
-
- Initialize the VirtIo PCI Device
-
- @param[in, out] Dev The driver instance to configure. The caller is
- responsible for Device->PciIo's validity (ie. working IO
- access to the underlying virtio-pci device).
-
- @retval EFI_SUCCESS Setup complete.
-
- @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
- provided address offset and read size.
-
- @return Error codes from PciIo->Pci.Read().
-
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-VirtioPciInit (
- IN OUT VIRTIO_PCI_DEVICE *Device
- )
-{
- EFI_STATUS Status;
- EFI_PCI_IO_PROTOCOL *PciIo;
- PCI_TYPE00 Pci;
-
- ASSERT (Device != NULL);
- PciIo = Device->PciIo;
- ASSERT (PciIo != NULL);
- ASSERT (PciIo->Pci.Read != NULL);
-
- Status = PciIo->Pci.Read (
- PciIo, // (protocol, device)
- // handle
- EfiPciIoWidthUint32, // access width & copy
- // mode
- 0, // Offset
- sizeof (Pci) / sizeof (UINT32), // Count
- &Pci // target buffer
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- // Copy protocol template
- CopyMem (&Device->VirtioDevice, &mDeviceProtocolTemplate,
- sizeof (VIRTIO_DEVICE_PROTOCOL));
-
- // Initialize the protocol interface attributes
- Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (0, 9, 5);
- Device->VirtioDevice.SubSystemDeviceId = Pci.Device.SubsystemID;
-
- // Note: We don't support the MSI-X capability. If we did,
- // the offset would become 24 after enabling MSI-X.
- Device->DeviceSpecificConfigurationOffset =
- VIRTIO_DEVICE_SPECIFIC_CONFIGURATION_OFFSET_PCI;
-
- return EFI_SUCCESS;
-}
-
-/**
-
- Uninitialize the internals of a virtio-pci device that has been successfully
- set up with VirtioPciInit().
-
- @param[in, out] Dev The device to clean up.
-
-**/
-
-STATIC
-VOID
-EFIAPI
-VirtioPciUninit (
- IN OUT VIRTIO_PCI_DEVICE *Device
- )
-{
- // Note: This function mirrors VirtioPciInit() that does not allocate any
- // resources - there's nothing to free here.
-}
-
-/**
-
- After we've pronounced support for a specific device in
- DriverBindingSupported(), we start managing said device (passed in by the
- Driver Exeuction Environment) with the following service.
-
- See DriverBindingSupported() for specification references.
-
- @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
- incorporating this driver (independently of
- any device).
-
- @param[in] DeviceHandle The supported device to drive.
-
- @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.
-
-
- @retval EFI_SUCCESS Driver instance has been created and
- initialized for the virtio-pci device, it
- is now accessible via VIRTIO_DEVICE_PROTOCOL.
-
- @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
-
- @return Error codes from the OpenProtocol() boot
- service, the PciIo protocol, VirtioPciInit(),
- or the InstallProtocolInterface() boot service.
-
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-VirtioPciDeviceBindingStart (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE DeviceHandle,
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
- )
-{
- VIRTIO_PCI_DEVICE *Device;
- EFI_STATUS Status;
-
- Device = (VIRTIO_PCI_DEVICE *) AllocateZeroPool (sizeof *Device);
- if (Device == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- Status = gBS->OpenProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
- (VOID **)&Device->PciIo, This->DriverBindingHandle,
- DeviceHandle, EFI_OPEN_PROTOCOL_BY_DRIVER);
- if (EFI_ERROR (Status)) {
- goto FreeVirtioPci;
- }
-
- //
- // We must retain and ultimately restore the original PCI attributes of the
- // device. See Driver Writer's Guide for UEFI 2.3.1 v1.01, 18.3 PCI drivers /
- // 18.3.2 Start() and Stop().
- //
- // The third parameter ("Attributes", input) is ignored by the Get operation.
- // The fourth parameter ("Result", output) is ignored by the Enable and Set
- // operations.
- //
- // For virtio-pci we only need IO space access.
- //
- Status = Device->PciIo->Attributes (Device->PciIo,
- EfiPciIoAttributeOperationGet, 0, &Device->OriginalPciAttributes);
- if (EFI_ERROR (Status)) {
- goto ClosePciIo;
- }
-
- Status = Device->PciIo->Attributes (Device->PciIo,
- EfiPciIoAttributeOperationEnable,
- EFI_PCI_IO_ATTRIBUTE_IO, NULL);
- if (EFI_ERROR (Status)) {
- goto ClosePciIo;
- }
-
- //
- // PCI IO access granted, configure protocol instance
- //
-
- Status = VirtioPciInit (Device);
- if (EFI_ERROR (Status)) {
- goto RestorePciAttributes;
- }
-
- //
- // Setup complete, attempt to export the driver instance's VirtioDevice
- // interface.
- //
- Device->Signature = VIRTIO_PCI_DEVICE_SIGNATURE;
- Status = gBS->InstallProtocolInterface (&DeviceHandle,
- &gVirtioDeviceProtocolGuid, EFI_NATIVE_INTERFACE,
- &Device->VirtioDevice);
- if (EFI_ERROR (Status)) {
- goto UninitDev;
- }
-
- return EFI_SUCCESS;
-
-UninitDev:
- VirtioPciUninit (Device);
-
-RestorePciAttributes:
- Device->PciIo->Attributes (Device->PciIo, EfiPciIoAttributeOperationSet,
- Device->OriginalPciAttributes, NULL);
-
-ClosePciIo:
- gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
- This->DriverBindingHandle, DeviceHandle);
-
-FreeVirtioPci:
- FreePool (Device);
-
- return Status;
-}
-
-/**
-
- Stop driving the Virtio PCI device
-
- @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
- incorporating this driver (independently of any
- device).
-
- @param[in] DeviceHandle Stop driving this device.
-
- @param[in] NumberOfChildren Since this function belongs to a device driver
- only (as opposed to a bus driver), the caller
- environment sets NumberOfChildren to zero, and
- we ignore it.
-
- @param[in] ChildHandleBuffer Ignored (corresponding to NumberOfChildren).
-
- @retval EFI_SUCCESS Driver instance has been stopped and the PCI
- configuration attributes have been restored.
-
- @return Error codes from the OpenProtocol() or
- CloseProtocol(), UninstallProtocolInterface()
- boot services.
-
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-VirtioPciDeviceBindingStop (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE DeviceHandle,
- IN UINTN NumberOfChildren,
- IN EFI_HANDLE *ChildHandleBuffer
- )
-{
- EFI_STATUS Status;
- VIRTIO_DEVICE_PROTOCOL *VirtioDevice;
- VIRTIO_PCI_DEVICE *Device;
-
- Status = gBS->OpenProtocol (
- DeviceHandle, // candidate device
- &gVirtioDeviceProtocolGuid, // retrieve the VirtIo iface
- (VOID **)&VirtioDevice, // target pointer
- This->DriverBindingHandle, // requestor driver identity
- DeviceHandle, // requesting lookup for dev.
- EFI_OPEN_PROTOCOL_GET_PROTOCOL // lookup only, no ref. added
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- Device = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (VirtioDevice);
-
- //
- // Handle Stop() requests for in-use driver instances gracefully.
- //
- Status = gBS->UninstallProtocolInterface (DeviceHandle,
- &gVirtioDeviceProtocolGuid, &Device->VirtioDevice);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- VirtioPciUninit (Device);
-
- Device->PciIo->Attributes (Device->PciIo, EfiPciIoAttributeOperationSet,
- Device->OriginalPciAttributes, NULL);
-
- Status = gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
- This->DriverBindingHandle, DeviceHandle);
-
- FreePool (Device);
-
- return Status;
-}
-
-
-//
-// The static object that groups the Supported() (ie. probe), Start() and
-// Stop() functions of the driver together. Refer to UEFI Spec 2.3.1 + Errata
-// C, 10.1 EFI Driver Binding Protocol.
-//
-STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding = {
- &VirtioPciDeviceBindingSupported,
- &VirtioPciDeviceBindingStart,
- &VirtioPciDeviceBindingStop,
- 0x10, // Version, must be in [0x10 .. 0xFFFFFFEF] for IHV-developed drivers
- NULL, // ImageHandle, to be overwritten by
- // EfiLibInstallDriverBindingComponentName2() in VirtioPciEntryPoint()
- NULL // DriverBindingHandle, ditto
-};
-
-
-//
-// The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and
-// EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name
-// in English, for display on standard console devices. This is recommended for
-// UEFI drivers that follow the UEFI Driver Model. Refer to the Driver Writer's
-// Guide for UEFI 2.3.1 v1.01, 11 UEFI Driver and Controller Names.
-//
-STATIC
-EFI_UNICODE_STRING_TABLE mDriverNameTable[] = {
- { "eng;en", L"Virtio PCI Driver" },
- { NULL, NULL }
-};
-
-STATIC
-EFI_COMPONENT_NAME_PROTOCOL gComponentName;
-
-EFI_STATUS
-EFIAPI
-VirtioPciGetDriverName (
- IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN CHAR8 *Language,
- OUT CHAR16 **DriverName
- )
-{
- return LookupUnicodeString2 (
- Language,
- This->SupportedLanguages,
- mDriverNameTable,
- DriverName,
- (BOOLEAN)(This == &gComponentName) // Iso639Language
- );
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciGetDeviceName (
- IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN EFI_HANDLE DeviceHandle,
- IN EFI_HANDLE ChildHandle,
- IN CHAR8 *Language,
- OUT CHAR16 **ControllerName
- )
-{
- return EFI_UNSUPPORTED;
-}
-
-STATIC
-EFI_COMPONENT_NAME_PROTOCOL gComponentName = {
- &VirtioPciGetDriverName,
- &VirtioPciGetDeviceName,
- "eng" // SupportedLanguages, ISO 639-2 language codes
-};
-
-STATIC
-EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = {
- (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) &VirtioPciGetDriverName,
- (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &VirtioPciGetDeviceName,
- "en" // SupportedLanguages, RFC 4646 language codes
-};
-
-
-//
-// Entry point of this driver.
-//
-EFI_STATUS
-EFIAPI
-VirtioPciDeviceEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
-{
- return EfiLibInstallDriverBindingComponentName2 (
- ImageHandle,
- SystemTable,
- &gDriverBinding,
- ImageHandle,
- &gComponentName,
- &gComponentName2
- );
-}
+/** @file
+
+ This driver produces Virtio Device Protocol instances for Virtio PCI 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 <IndustryStandard/Pci.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include "VirtioPciDevice.h"
+
+STATIC VIRTIO_DEVICE_PROTOCOL mDeviceProtocolTemplate = {
+ 0, // Revision
+ 0, // SubSystemDeviceId
+ VirtioPciGetDeviceFeatures, // GetDeviceFeatures
+ VirtioPciSetGuestFeatures, // SetGuestFeatures
+ VirtioPciGetQueueAddress, // GetQueueAddress
+ VirtioPciSetQueueAddress, // SetQueueAddress
+ VirtioPciSetQueueSel, // SetQueueSel
+ VirtioPciSetQueueNotify, // SetQueueNotify
+ VirtioPciSetQueueAlignment, // SetQueueAlignment
+ VirtioPciSetPageSize, // SetPageSize
+ VirtioPciGetQueueSize, // GetQueueNumMax
+ VirtioPciSetQueueSize, // SetQueueNum
+ VirtioPciGetDeviceStatus, // GetDeviceStatus
+ VirtioPciSetDeviceStatus, // SetDeviceStatus
+ VirtioPciDeviceWrite, // WriteDevice
+ VirtioPciDeviceRead // ReadDevice
+};
+
+/**
+
+ Read a word from Region 0 of the device specified by PciIo.
+
+ Region 0 must be an iomem region. This is an internal function for the PCI
+ implementation of the protocol.
+
+ @param[in] Dev Virtio PCI device.
+
+ @param[in] FieldOffset Source offset.
+
+ @param[in] FieldSize Source field size, must be in { 1, 2, 4, 8 }.
+
+ @param[in] BufferSize Number of bytes available in the target buffer. Must
+ equal FieldSize.
+
+ @param[out] Buffer Target buffer.
+
+
+ @return Status code returned by PciIo->Io.Read().
+
+**/
+EFI_STATUS
+EFIAPI
+VirtioPciIoRead (
+ IN VIRTIO_PCI_DEVICE *Dev,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ )
+{
+ UINTN Count;
+ EFI_PCI_IO_PROTOCOL_WIDTH Width;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+
+ ASSERT (FieldSize == BufferSize);
+
+ PciIo = Dev->PciIo;
+ Count = 1;
+
+ switch (FieldSize) {
+ case 1:
+ Width = EfiPciIoWidthUint8;
+ break;
+
+ case 2:
+ Width = EfiPciIoWidthUint16;
+ break;
+
+ case 8:
+ //
+ // The 64bit PCI I/O is broken down into two 32bit reads to prevent
+ // any alignment or width issues.
+ // The UEFI spec says under EFI_PCI_IO_PROTOCOL.Io.Write():
+ //
+ // The I/O operations are carried out exactly as requested. The caller
+ // is responsible for any alignment and I/O width issues which the
+ // bus, device, platform, or type of I/O might require. For example on
+ // some platforms, width requests of EfiPciIoWidthUint64 do not work.
+ //
+ Count = 2;
+
+ //
+ // fall through
+ //
+ case 4:
+ Width = EfiPciIoWidthUint32;
+ break;
+
+ default:
+ ASSERT (FALSE);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return PciIo->Io.Read (
+ PciIo,
+ Width,
+ PCI_BAR_IDX0,
+ FieldOffset,
+ Count,
+ Buffer
+ );
+}
+
+/**
+
+ Write a word into Region 0 of the device specified by PciIo.
+
+ Region 0 must be an iomem region. This is an internal function for the PCI
+ implementation of the protocol.
+
+ @param[in] Dev Virtio PCI device.
+
+ @param[in] FieldOffset Destination offset.
+
+ @param[in] FieldSize Destination field size, must be in { 1, 2, 4, 8 }.
+
+ @param[in] Value Little endian value to write, converted to UINT64.
+ The least significant FieldSize bytes will be used.
+
+
+ @return Status code returned by PciIo->Io.Write().
+
+**/
+EFI_STATUS
+EFIAPI
+VirtioPciIoWrite (
+ IN VIRTIO_PCI_DEVICE *Dev,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINT64 Value
+ )
+{
+ UINTN Count;
+ EFI_PCI_IO_PROTOCOL_WIDTH Width;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+
+ PciIo = Dev->PciIo;
+ Count = 1;
+
+ switch (FieldSize) {
+ case 1:
+ Width = EfiPciIoWidthUint8;
+ break;
+
+ case 2:
+ Width = EfiPciIoWidthUint16;
+ break;
+
+ case 8:
+ //
+ // The 64bit PCI I/O is broken down into two 32bit writes to prevent
+ // any alignment or width issues.
+ // The UEFI spec says under EFI_PCI_IO_PROTOCOL.Io.Write():
+ //
+ // The I/O operations are carried out exactly as requested. The caller
+ // is responsible for any alignment and I/O width issues which the
+ // bus, device, platform, or type of I/O might require. For example on
+ // some platforms, width requests of EfiPciIoWidthUint64 do not work
+ //
+ Count = Count * 2;
+
+ //
+ // fall through
+ //
+ case 4:
+ Width = EfiPciIoWidthUint32;
+ break;
+
+ default:
+ ASSERT (FALSE);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return PciIo->Io.Write (
+ PciIo,
+ Width,
+ PCI_BAR_IDX0,
+ FieldOffset,
+ Count,
+ &Value
+ );
+}
+
+/**
+
+ Device probe function for this driver.
+
+ The DXE core calls this function for any given device in order to see if the
+ driver can drive the device.
+
+ @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
+ incorporating this driver (independently of
+ any device).
+
+ @param[in] DeviceHandle The device to probe.
+
+ @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.
+
+
+ @retval EFI_SUCCESS The driver supports the device being probed.
+
+ @retval EFI_UNSUPPORTED Based on virtio-pci discovery, we do not support
+ the device.
+
+ @return Error codes from the OpenProtocol() boot service or
+ the PciIo protocol.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+VirtioPciDeviceBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE DeviceHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+{
+ EFI_STATUS Status;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+ PCI_TYPE00 Pci;
+
+ //
+ // Attempt to open the device with the PciIo set of interfaces. On success,
+ // the protocol is "instantiated" for the PCI device. Covers duplicate open
+ // attempts (EFI_ALREADY_STARTED).
+ //
+ Status = gBS->OpenProtocol (
+ DeviceHandle, // candidate device
+ &gEfiPciIoProtocolGuid, // for generic PCI access
+ (VOID **)&PciIo, // handle to instantiate
+ This->DriverBindingHandle, // requestor driver identity
+ DeviceHandle, // ControllerHandle, according to
+ // the UEFI Driver Model
+ EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive PciIo access to
+ // the device; to be released
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Read entire PCI configuration header for more extensive check ahead.
+ //
+ Status = PciIo->Pci.Read (
+ PciIo, // (protocol, device)
+ // handle
+ EfiPciIoWidthUint32, // access width & copy
+ // mode
+ 0, // Offset
+ sizeof Pci / sizeof (UINT32), // Count
+ &Pci // target buffer
+ );
+
+ if (Status == EFI_SUCCESS) {
+ //
+ // virtio-0.9.5, 2.1 PCI Discovery
+ //
+ if ((Pci.Hdr.VendorId == VIRTIO_VENDOR_ID) &&
+ (Pci.Hdr.DeviceId >= 0x1000) &&
+ (Pci.Hdr.DeviceId <= 0x103F) &&
+ (Pci.Hdr.RevisionID == 0x00)) {
+ Status = EFI_SUCCESS;
+ } else {
+ Status = EFI_UNSUPPORTED;
+ }
+ }
+
+ //
+ // We needed PCI IO access only transitorily, to see whether we support the
+ // device or not.
+ //
+ gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
+ This->DriverBindingHandle, DeviceHandle);
+
+ return Status;
+}
+
+/**
+
+ Initialize the VirtIo PCI Device
+
+ @param[in, out] Dev The driver instance to configure. The caller is
+ responsible for Device->PciIo's validity (ie. working IO
+ access to the underlying virtio-pci device).
+
+ @retval EFI_SUCCESS Setup complete.
+
+ @retval EFI_UNSUPPORTED The underlying IO device doesn't support the
+ provided address offset and read size.
+
+ @return Error codes from PciIo->Pci.Read().
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+VirtioPciInit (
+ IN OUT VIRTIO_PCI_DEVICE *Device
+ )
+{
+ EFI_STATUS Status;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+ PCI_TYPE00 Pci;
+
+ ASSERT (Device != NULL);
+ PciIo = Device->PciIo;
+ ASSERT (PciIo != NULL);
+ ASSERT (PciIo->Pci.Read != NULL);
+
+ Status = PciIo->Pci.Read (
+ PciIo, // (protocol, device)
+ // handle
+ EfiPciIoWidthUint32, // access width & copy
+ // mode
+ 0, // Offset
+ sizeof (Pci) / sizeof (UINT32), // Count
+ &Pci // target buffer
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Copy protocol template
+ //
+ CopyMem (&Device->VirtioDevice, &mDeviceProtocolTemplate,
+ sizeof (VIRTIO_DEVICE_PROTOCOL));
+
+ //
+ // Initialize the protocol interface attributes
+ //
+ Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (0, 9, 5);
+ Device->VirtioDevice.SubSystemDeviceId = Pci.Device.SubsystemID;
+
+ //
+ // Note: We don't support the MSI-X capability. If we did,
+ // the offset would become 24 after enabling MSI-X.
+ //
+ Device->DeviceSpecificConfigurationOffset =
+ VIRTIO_DEVICE_SPECIFIC_CONFIGURATION_OFFSET_PCI;
+
+ return EFI_SUCCESS;
+}
+
+/**
+
+ Uninitialize the internals of a virtio-pci device that has been successfully
+ set up with VirtioPciInit().
+
+ @param[in, out] Dev The device to clean up.
+
+**/
+
+STATIC
+VOID
+EFIAPI
+VirtioPciUninit (
+ IN OUT VIRTIO_PCI_DEVICE *Device
+ )
+{
+ // Note: This function mirrors VirtioPciInit() that does not allocate any
+ // resources - there's nothing to free here.
+}
+
+/**
+
+ After we've pronounced support for a specific device in
+ DriverBindingSupported(), we start managing said device (passed in by the
+ Driver Exeuction Environment) with the following service.
+
+ See DriverBindingSupported() for specification references.
+
+ @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
+ incorporating this driver (independently of
+ any device).
+
+ @param[in] DeviceHandle The supported device to drive.
+
+ @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.
+
+
+ @retval EFI_SUCCESS Driver instance has been created and
+ initialized for the virtio-pci device, it
+ is now accessible via VIRTIO_DEVICE_PROTOCOL.
+
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+
+ @return Error codes from the OpenProtocol() boot
+ service, the PciIo protocol, VirtioPciInit(),
+ or the InstallProtocolInterface() boot service.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+VirtioPciDeviceBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE DeviceHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+{
+ VIRTIO_PCI_DEVICE *Device;
+ EFI_STATUS Status;
+
+ Device = (VIRTIO_PCI_DEVICE *) AllocateZeroPool (sizeof *Device);
+ if (Device == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = gBS->OpenProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
+ (VOID **)&Device->PciIo, This->DriverBindingHandle,
+ DeviceHandle, EFI_OPEN_PROTOCOL_BY_DRIVER);
+ if (EFI_ERROR (Status)) {
+ goto FreeVirtioPci;
+ }
+
+ //
+ // We must retain and ultimately restore the original PCI attributes of the
+ // device. See Driver Writer's Guide for UEFI 2.3.1 v1.01, 18.3 PCI drivers /
+ // 18.3.2 Start() and Stop().
+ //
+ // The third parameter ("Attributes", input) is ignored by the Get operation.
+ // The fourth parameter ("Result", output) is ignored by the Enable and Set
+ // operations.
+ //
+ // For virtio-pci we only need IO space access.
+ //
+ Status = Device->PciIo->Attributes (Device->PciIo,
+ EfiPciIoAttributeOperationGet, 0, &Device->OriginalPciAttributes);
+ if (EFI_ERROR (Status)) {
+ goto ClosePciIo;
+ }
+
+ Status = Device->PciIo->Attributes (Device->PciIo,
+ EfiPciIoAttributeOperationEnable,
+ EFI_PCI_IO_ATTRIBUTE_IO, NULL);
+ if (EFI_ERROR (Status)) {
+ goto ClosePciIo;
+ }
+
+ //
+ // PCI IO access granted, configure protocol instance
+ //
+
+ Status = VirtioPciInit (Device);
+ if (EFI_ERROR (Status)) {
+ goto RestorePciAttributes;
+ }
+
+ //
+ // Setup complete, attempt to export the driver instance's VirtioDevice
+ // interface.
+ //
+ Device->Signature = VIRTIO_PCI_DEVICE_SIGNATURE;
+ Status = gBS->InstallProtocolInterface (&DeviceHandle,
+ &gVirtioDeviceProtocolGuid, EFI_NATIVE_INTERFACE,
+ &Device->VirtioDevice);
+ if (EFI_ERROR (Status)) {
+ goto UninitDev;
+ }
+
+ return EFI_SUCCESS;
+
+UninitDev:
+ VirtioPciUninit (Device);
+
+RestorePciAttributes:
+ Device->PciIo->Attributes (Device->PciIo, EfiPciIoAttributeOperationSet,
+ Device->OriginalPciAttributes, NULL);
+
+ClosePciIo:
+ gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
+ This->DriverBindingHandle, DeviceHandle);
+
+FreeVirtioPci:
+ FreePool (Device);
+
+ return Status;
+}
+
+/**
+
+ Stop driving the Virtio PCI device
+
+ @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
+ incorporating this driver (independently of any
+ device).
+
+ @param[in] DeviceHandle Stop driving this device.
+
+ @param[in] NumberOfChildren Since this function belongs to a device driver
+ only (as opposed to a bus driver), the caller
+ environment sets NumberOfChildren to zero, and
+ we ignore it.
+
+ @param[in] ChildHandleBuffer Ignored (corresponding to NumberOfChildren).
+
+ @retval EFI_SUCCESS Driver instance has been stopped and the PCI
+ configuration attributes have been restored.
+
+ @return Error codes from the OpenProtocol() or
+ CloseProtocol(), UninstallProtocolInterface()
+ boot services.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+VirtioPciDeviceBindingStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE DeviceHandle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
+ )
+{
+ EFI_STATUS Status;
+ VIRTIO_DEVICE_PROTOCOL *VirtioDevice;
+ VIRTIO_PCI_DEVICE *Device;
+
+ Status = gBS->OpenProtocol (
+ DeviceHandle, // candidate device
+ &gVirtioDeviceProtocolGuid, // retrieve the VirtIo iface
+ (VOID **)&VirtioDevice, // target pointer
+ This->DriverBindingHandle, // requestor driver identity
+ DeviceHandle, // requesting lookup for dev.
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL // lookup only, no ref. added
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Device = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (VirtioDevice);
+
+ //
+ // Handle Stop() requests for in-use driver instances gracefully.
+ //
+ Status = gBS->UninstallProtocolInterface (DeviceHandle,
+ &gVirtioDeviceProtocolGuid, &Device->VirtioDevice);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ VirtioPciUninit (Device);
+
+ Device->PciIo->Attributes (Device->PciIo, EfiPciIoAttributeOperationSet,
+ Device->OriginalPciAttributes, NULL);
+
+ Status = gBS->CloseProtocol (DeviceHandle, &gEfiPciIoProtocolGuid,
+ This->DriverBindingHandle, DeviceHandle);
+
+ FreePool (Device);
+
+ return Status;
+}
+
+
+//
+// The static object that groups the Supported() (ie. probe), Start() and
+// Stop() functions of the driver together. Refer to UEFI Spec 2.3.1 + Errata
+// C, 10.1 EFI Driver Binding Protocol.
+//
+STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding = {
+ &VirtioPciDeviceBindingSupported,
+ &VirtioPciDeviceBindingStart,
+ &VirtioPciDeviceBindingStop,
+ 0x10, // Version, must be in [0x10 .. 0xFFFFFFEF] for IHV-developed drivers
+ NULL, // ImageHandle, to be overwritten by
+ // EfiLibInstallDriverBindingComponentName2() in VirtioPciEntryPoint()
+ NULL // DriverBindingHandle, ditto
+};
+
+
+//
+// The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and
+// EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name
+// in English, for display on standard console devices. This is recommended for
+// UEFI drivers that follow the UEFI Driver Model. Refer to the Driver Writer's
+// Guide for UEFI 2.3.1 v1.01, 11 UEFI Driver and Controller Names.
+//
+STATIC
+EFI_UNICODE_STRING_TABLE mDriverNameTable[] = {
+ { "eng;en", L"Virtio PCI Driver" },
+ { NULL, NULL }
+};
+
+STATIC
+EFI_COMPONENT_NAME_PROTOCOL gComponentName;
+
+EFI_STATUS
+EFIAPI
+VirtioPciGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+{
+ return LookupUnicodeString2 (
+ Language,
+ This->SupportedLanguages,
+ mDriverNameTable,
+ DriverName,
+ (BOOLEAN)(This == &gComponentName) // Iso639Language
+ );
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciGetDeviceName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE DeviceHandle,
+ IN EFI_HANDLE ChildHandle,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_COMPONENT_NAME_PROTOCOL gComponentName = {
+ &VirtioPciGetDriverName,
+ &VirtioPciGetDeviceName,
+ "eng" // SupportedLanguages, ISO 639-2 language codes
+};
+
+STATIC
+EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = {
+ (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) &VirtioPciGetDriverName,
+ (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &VirtioPciGetDeviceName,
+ "en" // SupportedLanguages, RFC 4646 language codes
+};
+
+
+//
+// Entry point of this driver.
+//
+EFI_STATUS
+EFIAPI
+VirtioPciDeviceEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return EfiLibInstallDriverBindingComponentName2 (
+ ImageHandle,
+ SystemTable,
+ &gDriverBinding,
+ ImageHandle,
+ &gComponentName,
+ &gComponentName2
+ );
+}
diff --git a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h
index bbad164f6..6311ae849 100644
--- a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h
+++ b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h
@@ -1,166 +1,166 @@
-/** @file
-
- Internal definitions for the VirtIo PCI 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_PCI_DEVICE_DXE_H_
-#define _VIRTIO_PCI_DEVICE_DXE_H_
-
-#include <Protocol/ComponentName.h>
-#include <Protocol/DriverBinding.h>
-#include <Protocol/PciIo.h>
-#include <Protocol/VirtioDevice.h>
-
-#include <IndustryStandard/Virtio.h>
-
-#define VIRTIO_PCI_DEVICE_SIGNATURE SIGNATURE_32 ('V', 'P', 'C', 'I')
-
-typedef struct {
- UINT32 Signature;
- VIRTIO_DEVICE_PROTOCOL VirtioDevice;
- EFI_PCI_IO_PROTOCOL *PciIo;
- UINT64 OriginalPciAttributes;
- UINT32 DeviceSpecificConfigurationOffset;
-} VIRTIO_PCI_DEVICE;
-
-#define VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE(Device) \
- CR (Device, VIRTIO_PCI_DEVICE, VirtioDevice, VIRTIO_PCI_DEVICE_SIGNATURE)
-
-
-EFI_STATUS
-EFIAPI
-VirtioPciIoRead (
- IN VIRTIO_PCI_DEVICE *Dev,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINTN BufferSize,
- OUT VOID *Buffer
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciIoWrite (
- IN VIRTIO_PCI_DEVICE *Dev,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINT64 Value
- );
-
-/********************************************
- * PCI Functions for VIRTIO_DEVICE_PROTOCOL
- *******************************************/
-EFI_STATUS
-EFIAPI
-VirtioPciDeviceRead (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINTN BufferSize,
- OUT VOID *Buffer
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciDeviceWrite (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINT64 Value
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciGetDeviceFeatures (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT32 *DeviceFeatures
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciGetQueueAddress (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT32 *QueueAddress
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciGetQueueSize (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT16 *QueueNumMax
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetQueueAlignment (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Alignment
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetPageSize (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 PageSize
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciGetDeviceStatus (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT8 *DeviceStatus
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetGuestFeatures (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINT32 Features
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetQueueAddress (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Address
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetQueueSel (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 Sel
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetQueueNotify (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 Index
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetQueueSize (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 Size
- );
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetDeviceStatus (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT8 DeviceStatus
- );
-
-#endif // _VIRTIO_PCI_DEVICE_DXE_H_
+/** @file
+
+ Internal definitions for the VirtIo PCI 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_PCI_DEVICE_DXE_H_
+#define _VIRTIO_PCI_DEVICE_DXE_H_
+
+#include <Protocol/ComponentName.h>
+#include <Protocol/DriverBinding.h>
+#include <Protocol/PciIo.h>
+#include <Protocol/VirtioDevice.h>
+
+#include <IndustryStandard/Virtio.h>
+
+#define VIRTIO_PCI_DEVICE_SIGNATURE SIGNATURE_32 ('V', 'P', 'C', 'I')
+
+typedef struct {
+ UINT32 Signature;
+ VIRTIO_DEVICE_PROTOCOL VirtioDevice;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+ UINT64 OriginalPciAttributes;
+ UINT32 DeviceSpecificConfigurationOffset;
+} VIRTIO_PCI_DEVICE;
+
+#define VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE(Device) \
+ CR (Device, VIRTIO_PCI_DEVICE, VirtioDevice, VIRTIO_PCI_DEVICE_SIGNATURE)
+
+
+EFI_STATUS
+EFIAPI
+VirtioPciIoRead (
+ IN VIRTIO_PCI_DEVICE *Dev,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciIoWrite (
+ IN VIRTIO_PCI_DEVICE *Dev,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINT64 Value
+ );
+
+/********************************************
+ * PCI Functions for VIRTIO_DEVICE_PROTOCOL
+ *******************************************/
+EFI_STATUS
+EFIAPI
+VirtioPciDeviceRead (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciDeviceWrite (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINT64 Value
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciGetDeviceFeatures (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT32 *DeviceFeatures
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciGetQueueAddress (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT32 *QueueAddress
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciGetQueueSize (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT16 *QueueNumMax
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetQueueAlignment (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 Alignment
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetPageSize (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 PageSize
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciGetDeviceStatus (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT8 *DeviceStatus
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetGuestFeatures (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINT32 Features
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetQueueAddress (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 Address
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetQueueSel (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 Sel
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetQueueNotify (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 Index
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetQueueSize (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 Size
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetDeviceStatus (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT8 DeviceStatus
+ );
+
+#endif // _VIRTIO_PCI_DEVICE_DXE_H_
diff --git a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
index 90a5dbc2b..4b5d1a493 100644
--- a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
+++ b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
@@ -1,43 +1,43 @@
-## @file
-# This driver produces the VirtIo Device Protocol instances for VirtIo PCI
-# 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 = VirtioPciDeviceDxe
- FILE_GUID = 83dd3b39-7caf-4fac-a542-e050b767e3a7
- MODULE_TYPE = UEFI_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = VirtioPciDeviceEntryPoint
-
-[Sources]
- VirtioPciDevice.c
- VirtioPciFunctions.c
-
-[Packages]
- MdePkg/MdePkg.dec
- OvmfPkg/OvmfPkg.dec
-
-[LibraryClasses]
- BaseMemoryLib
- DebugLib
- MemoryAllocationLib
- UefiBootServicesTableLib
- UefiDriverEntryPoint
- UefiLib
-
-[Protocols]
- gEfiPciIoProtocolGuid ## TO_START
- gVirtioDeviceProtocolGuid ## BY_START
+## @file
+# This driver produces the VirtIo Device Protocol instances for VirtIo PCI
+# 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 = VirtioPciDeviceDxe
+ FILE_GUID = 83dd3b39-7caf-4fac-a542-e050b767e3a7
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = VirtioPciDeviceEntryPoint
+
+[Sources]
+ VirtioPciDevice.c
+ VirtioPciFunctions.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+ BaseMemoryLib
+ DebugLib
+ MemoryAllocationLib
+ UefiBootServicesTableLib
+ UefiDriverEntryPoint
+ UefiLib
+
+[Protocols]
+ gEfiPciIoProtocolGuid ## TO_START
+ gVirtioDeviceProtocolGuid ## BY_START
diff --git a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c
index e9e48b945..9c40fd94a 100644
--- a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c
+++ b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c
@@ -1,285 +1,283 @@
-/** @file
-
- This driver produces Virtio Device Protocol instances for Virtio PCI 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 <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-#include "VirtioPciDevice.h"
-
-/**
-
- Read a word from Region 0 of the device specified by PciIo.
-
- The function implements the ReadDevice protocol member of
- VIRTIO_DEVICE_PROTOCOL.
-
- @param[in] PciIo Source PCI device.
-
- @param[in] FieldOffset Source offset.
-
- @param[in] FieldSize Source field size, must be in { 1, 2, 4, 8 }.
-
- @param[in] BufferSize Number of bytes available in the target buffer. Must
- equal FieldSize.
-
- @param[out] Buffer Target buffer.
-
-
- @return Status code returned by PciIo->Io.Read().
-
-**/
-EFI_STATUS
-EFIAPI
-VirtioPciDeviceRead (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINTN BufferSize,
- OUT VOID *Buffer
- )
-{
- VIRTIO_PCI_DEVICE *Dev;
-
- Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VirtioPciIoRead (Dev,
- Dev->DeviceSpecificConfigurationOffset + FieldOffset,
- FieldSize, BufferSize, Buffer);
-}
-
-/**
-
- Write a word into Region 0 of the device specified by VirtIo Device protocol.
-
- @param[in] This VirtIo Device protocol.
-
- @param[in] FieldOffset Destination offset.
-
- @param[in] FieldSize Destination field size, must be in { 1, 2, 4, 8 }.
-
- @param[in] Value Little endian value to write, converted to UINT64.
- The least significant FieldSize bytes will be used.
-
-
- @return Status code returned by PciIo->Io.Write().
-
-**/
-EFI_STATUS
-EFIAPI
-VirtioPciDeviceWrite (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINTN FieldOffset,
- IN UINTN FieldSize,
- IN UINT64 Value
- )
-{
- VIRTIO_PCI_DEVICE *Dev;
-
- Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VirtioPciIoWrite (Dev,
- Dev->DeviceSpecificConfigurationOffset + FieldOffset, FieldSize, Value);
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciGetDeviceFeatures (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT32 *DeviceFeatures
- )
-{
- VIRTIO_PCI_DEVICE *Dev;
-
- if (DeviceFeatures == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_DEVICE_FEATURES, sizeof (UINT32),
- sizeof (UINT32), DeviceFeatures);
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciGetQueueAddress (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT32 *QueueAddress
- )
-{
- VIRTIO_PCI_DEVICE *Dev;
-
- if (QueueAddress == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_QUEUE_ADDRESS, sizeof (UINT32),
- sizeof (UINT32), QueueAddress);
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciGetQueueSize (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT16 *QueueNumMax
- )
-{
- VIRTIO_PCI_DEVICE *Dev;
-
- if (QueueNumMax == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_QUEUE_SIZE, sizeof (UINT16),
- sizeof (UINT16), QueueNumMax);
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciGetDeviceStatus (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- OUT UINT8 *DeviceStatus
- )
-{
- VIRTIO_PCI_DEVICE *Dev;
-
- if (DeviceStatus == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_QUEUE_DEVICE_STATUS,
- sizeof (UINT8), sizeof (UINT8), DeviceStatus);
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetGuestFeatures (
- IN VIRTIO_DEVICE_PROTOCOL *This,
- IN UINT32 Features
- )
-{
- VIRTIO_PCI_DEVICE *Dev;
-
- Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_GUEST_FEATURES,
- sizeof (UINT32), Features);
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetQueueAddress (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Address
- )
-{
- VIRTIO_PCI_DEVICE *Dev;
-
- Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_QUEUE_ADDRESS, sizeof (UINT32),
- Address);
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetQueueSel (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 Sel
- )
-{
- VIRTIO_PCI_DEVICE *Dev;
-
- Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_QUEUE_SELECT, sizeof (UINT16),
- Sel);
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetQueueAlignment (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 Alignment
- )
-{
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetPageSize (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT32 PageSize
- )
-{
- ASSERT (PageSize == EFI_PAGE_SIZE);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetQueueNotify (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 Index
- )
-{
- VIRTIO_PCI_DEVICE *Dev;
-
- Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_QUEUE_NOTIFY, sizeof (UINT16),
- Index);
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetQueueSize (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT16 Size
- )
-{
- //
- // This function is only applicable in Virtio-MMIO.
- // (The QueueSize field is read-only in Virtio proper (PCI))
- //
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EFIAPI
-VirtioPciSetDeviceStatus (
- VIRTIO_DEVICE_PROTOCOL *This,
- UINT8 DeviceStatus
- )
-{
- VIRTIO_PCI_DEVICE *Dev;
-
- Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
-
- return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_QUEUE_DEVICE_STATUS,
- sizeof (UINT8), DeviceStatus);
-}
+/** @file
+
+ This driver produces Virtio Device Protocol instances for Virtio PCI 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 <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+#include "VirtioPciDevice.h"
+
+/**
+
+ Read a word from Region 0 of the device specified by VirtIo Device protocol.
+
+ The function implements the ReadDevice protocol member of
+ VIRTIO_DEVICE_PROTOCOL.
+
+ @param[in] This VirtIo Device protocol.
+
+ @param[in] FieldOffset Source offset.
+
+ @param[in] FieldSize Source field size, must be in { 1, 2, 4, 8 }.
+
+ @param[in] BufferSize Number of bytes available in the target buffer. Must
+ equal FieldSize.
+
+ @param[out] Buffer Target buffer.
+
+
+ @return Status code returned by PciIo->Io.Read().
+
+**/
+EFI_STATUS
+EFIAPI
+VirtioPciDeviceRead (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ )
+{
+ VIRTIO_PCI_DEVICE *Dev;
+
+ Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ return VirtioPciIoRead (Dev,
+ Dev->DeviceSpecificConfigurationOffset + FieldOffset,
+ FieldSize, BufferSize, Buffer);
+}
+
+/**
+
+ Write a word into Region 0 of the device specified by VirtIo Device protocol.
+
+ @param[in] This VirtIo Device protocol.
+
+ @param[in] FieldOffset Destination offset.
+
+ @param[in] FieldSize Destination field size, must be in { 1, 2, 4, 8 }.
+
+ @param[in] Value Little endian value to write, converted to UINT64.
+ The least significant FieldSize bytes will be used.
+
+
+ @return Status code returned by PciIo->Io.Write().
+
+**/
+EFI_STATUS
+EFIAPI
+VirtioPciDeviceWrite (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINTN FieldOffset,
+ IN UINTN FieldSize,
+ IN UINT64 Value
+ )
+{
+ VIRTIO_PCI_DEVICE *Dev;
+
+ Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ return VirtioPciIoWrite (Dev,
+ Dev->DeviceSpecificConfigurationOffset + FieldOffset, FieldSize, Value);
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciGetDeviceFeatures (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT32 *DeviceFeatures
+ )
+{
+ VIRTIO_PCI_DEVICE *Dev;
+
+ if (DeviceFeatures == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ return VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_DEVICE_FEATURES, sizeof (UINT32),
+ sizeof (UINT32), DeviceFeatures);
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciGetQueueAddress (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT32 *QueueAddress
+ )
+{
+ VIRTIO_PCI_DEVICE *Dev;
+
+ if (QueueAddress == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ return VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_QUEUE_ADDRESS, sizeof (UINT32),
+ sizeof (UINT32), QueueAddress);
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciGetQueueSize (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT16 *QueueNumMax
+ )
+{
+ VIRTIO_PCI_DEVICE *Dev;
+
+ if (QueueNumMax == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ return VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_QUEUE_SIZE, sizeof (UINT16),
+ sizeof (UINT16), QueueNumMax);
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciGetDeviceStatus (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ OUT UINT8 *DeviceStatus
+ )
+{
+ VIRTIO_PCI_DEVICE *Dev;
+
+ if (DeviceStatus == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ return VirtioPciIoRead (Dev, VIRTIO_PCI_OFFSET_QUEUE_DEVICE_STATUS,
+ sizeof (UINT8), sizeof (UINT8), DeviceStatus);
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetGuestFeatures (
+ IN VIRTIO_DEVICE_PROTOCOL *This,
+ IN UINT32 Features
+ )
+{
+ VIRTIO_PCI_DEVICE *Dev;
+
+ Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_GUEST_FEATURES,
+ sizeof (UINT32), Features);
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetQueueAddress (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 Address
+ )
+{
+ VIRTIO_PCI_DEVICE *Dev;
+
+ Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_QUEUE_ADDRESS, sizeof (UINT32),
+ Address);
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetQueueSel (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 Sel
+ )
+{
+ VIRTIO_PCI_DEVICE *Dev;
+
+ Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_QUEUE_SELECT, sizeof (UINT16),
+ Sel);
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetQueueAlignment (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 Alignment
+ )
+{
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetPageSize (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT32 PageSize
+ )
+{
+ return (PageSize == EFI_PAGE_SIZE) ? EFI_SUCCESS : EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetQueueNotify (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 Index
+ )
+{
+ VIRTIO_PCI_DEVICE *Dev;
+
+ Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_QUEUE_NOTIFY, sizeof (UINT16),
+ Index);
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetQueueSize (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT16 Size
+ )
+{
+ //
+ // This function is only applicable in Virtio-MMIO.
+ // (The QueueSize field is read-only in Virtio proper (PCI))
+ //
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtioPciSetDeviceStatus (
+ VIRTIO_DEVICE_PROTOCOL *This,
+ UINT8 DeviceStatus
+ )
+{
+ VIRTIO_PCI_DEVICE *Dev;
+
+ Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This);
+
+ return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_QUEUE_DEVICE_STATUS,
+ sizeof (UINT8), DeviceStatus);
+}
diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
index 3b6c3ade8..e6154cd22 100644
--- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
+++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
@@ -50,14 +50,14 @@
/**
- Convenience macros to read and write region 0 IO space elements of the
- virtio-scsi VirtIo device, for configuration purposes.
+ Convenience macros to read and write configuration elements of the
+ virtio-scsi VirtIo device.
The following macros make it possible to specify only the "core parameters"
for such accesses and to derive the rest. By the time VIRTIO_CFG_WRITE()
returns, the transaction will have been completed.
- @param[in] Dev Pointer to the VirtIo Device Protocol
+ @param[in] Dev Pointer to the VSCSI_DEV structure.
@param[in] Field A field name from VSCSI_HDR, identifying the virtio-scsi
configuration item to access.
@@ -70,23 +70,23 @@
one of UINT8, UINT16, UINT32, UINT64.
- @return Status codes returned by Virtio->WriteDevice() / Virtio->ReadDevice().
+ @return Status codes returned by Virtio->WriteDevice() / Virtio->ReadDevice().
**/
-#define VIRTIO_CFG_WRITE(Dev, Field, Value) ((Dev)->VirtIo->WriteDevice ( \
- (Dev)->VirtIo, \
- OFFSET_OF_VSCSI (Field), \
- SIZE_OF_VSCSI (Field), \
- (Value) \
+#define VIRTIO_CFG_WRITE(Dev, Field, Value) ((Dev)->VirtIo->WriteDevice ( \
+ (Dev)->VirtIo, \
+ OFFSET_OF_VSCSI (Field), \
+ SIZE_OF_VSCSI (Field), \
+ (Value) \
))
-#define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice ( \
- (Dev)->VirtIo, \
- OFFSET_OF_VSCSI (Field), \
- SIZE_OF_VSCSI (Field), \
- sizeof *(Pointer), \
- (Pointer) \
+#define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice ( \
+ (Dev)->VirtIo, \
+ OFFSET_OF_VSCSI (Field), \
+ SIZE_OF_VSCSI (Field), \
+ sizeof *(Pointer), \
+ (Pointer) \
))
@@ -469,7 +469,7 @@ VirtioScsiPassThru (
// EFI_NOT_READY would save us the effort, but it would also suggest that the
// caller retry.
//
- if (VirtioFlush (Dev->VirtIo, VIRTIO_SCSI_REQUEST_QUEUE, &Dev->Ring,
+ if (VirtioFlush (Dev->VirtIo, VIRTIO_SCSI_REQUEST_QUEUE, &Dev->Ring,
&Indices) != EFI_SUCCESS) {
Packet->InTransferLength = 0;
Packet->OutTransferLength = 0;
@@ -716,41 +716,41 @@ VirtioScsiInit (
// Execute virtio-0.9.5, 2.2.1 Device Initialization Sequence.
//
NextDevStat = 0; // step 1 -- reset device
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto Failed;
}
NextDevStat |= VSTAT_ACK; // step 2 -- acknowledge device presence
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto Failed;
}
NextDevStat |= VSTAT_DRIVER; // step 3 -- we know how to drive it
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ if (EFI_ERROR (Status)) {
+ goto Failed;
+ }
+
+ //
+ // Set Page Size - MMIO VirtIo Specific
+ //
+ Status = Dev->VirtIo->SetPageSize (Dev->VirtIo, EFI_PAGE_SIZE);
if (EFI_ERROR (Status)) {
goto Failed;
}
//
- // Set Page Size - MMIO VirtIo Specific
- //
- Status = Dev->VirtIo->SetPageSize (Dev->VirtIo, EFI_PAGE_SIZE);
- if (EFI_ERROR (Status)) {
- goto ReleaseQueue;
- }
-
- //
// step 4a -- retrieve and validate features
//
- Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);
+ Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);
if (EFI_ERROR (Status)) {
goto Failed;
}
Dev->InOutSupported = !!(Features & VIRTIO_SCSI_F_INOUT);
- Status = VIRTIO_CFG_READ (Dev, MaxChannel, &MaxChannel);
+ Status = VIRTIO_CFG_READ (Dev, MaxChannel, &MaxChannel);
if (EFI_ERROR (Status)) {
goto Failed;
}
@@ -762,7 +762,7 @@ VirtioScsiInit (
goto Failed;
}
- Status = VIRTIO_CFG_READ (Dev, NumQueues, &NumQueues);
+ Status = VIRTIO_CFG_READ (Dev, NumQueues, &NumQueues);
if (EFI_ERROR (Status)) {
goto Failed;
}
@@ -771,7 +771,7 @@ VirtioScsiInit (
goto Failed;
}
- Status = VIRTIO_CFG_READ (Dev, MaxTarget, &Dev->MaxTarget);
+ Status = VIRTIO_CFG_READ (Dev, MaxTarget, &Dev->MaxTarget);
if (EFI_ERROR (Status)) {
goto Failed;
}
@@ -779,7 +779,7 @@ VirtioScsiInit (
Dev->MaxTarget = PcdGet16 (PcdVirtioScsiMaxTargetLimit);
}
- Status = VIRTIO_CFG_READ (Dev, MaxLun, &Dev->MaxLun);
+ Status = VIRTIO_CFG_READ (Dev, MaxLun, &Dev->MaxLun);
if (EFI_ERROR (Status)) {
goto Failed;
}
@@ -787,7 +787,7 @@ VirtioScsiInit (
Dev->MaxLun = PcdGet32 (PcdVirtioScsiMaxLunLimit);
}
- Status = VIRTIO_CFG_READ (Dev, MaxSectors, &Dev->MaxSectors);
+ Status = VIRTIO_CFG_READ (Dev, MaxSectors, &Dev->MaxSectors);
if (EFI_ERROR (Status)) {
goto Failed;
}
@@ -803,11 +803,11 @@ VirtioScsiInit (
//
// step 4b -- allocate request virtqueue
//
- Status = Dev->VirtIo->SetQueueSel (Dev->VirtIo, VIRTIO_SCSI_REQUEST_QUEUE);
+ Status = Dev->VirtIo->SetQueueSel (Dev->VirtIo, VIRTIO_SCSI_REQUEST_QUEUE);
if (EFI_ERROR (Status)) {
goto Failed;
}
- Status = Dev->VirtIo->GetQueueNumMax (Dev->VirtIo, &QueueSize);
+ Status = Dev->VirtIo->GetQueueNumMax (Dev->VirtIo, &QueueSize);
if (EFI_ERROR (Status)) {
goto Failed;
}
@@ -825,11 +825,24 @@ VirtioScsiInit (
}
//
- // step 4c -- Report GPFN (guest-physical frame number) of queue. If anything
- // fails from here on, we must release the ring resources.
+ // Additional steps for MMIO: align the queue appropriately, and set the
+ // size. If anything fails from here on, we must release the ring resources.
//
- Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
- (UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
+ Status = Dev->VirtIo->SetQueueNum (Dev->VirtIo, QueueSize);
+ if (EFI_ERROR (Status)) {
+ goto ReleaseQueue;
+ }
+
+ Status = Dev->VirtIo->SetQueueAlign (Dev->VirtIo, EFI_PAGE_SIZE);
+ if (EFI_ERROR (Status)) {
+ goto ReleaseQueue;
+ }
+
+ //
+ // step 4c -- Report GPFN (guest-physical frame number) of queue.
+ //
+ Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
+ (UINT32) ((UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT));
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
@@ -839,8 +852,8 @@ VirtioScsiInit (
// the known (or unknown) VIRTIO_SCSI_F_* or VIRTIO_F_* capabilities (see
// virtio-0.9.5, Appendices B and I), except bidirectional transfers.
//
- Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo,
- Features & VIRTIO_SCSI_F_INOUT);
+ Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo,
+ Features & VIRTIO_SCSI_F_INOUT);
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
@@ -849,11 +862,11 @@ VirtioScsiInit (
// We expect these maximum sizes from the host. Since they are
// guest-negotiable, ask for them rather than just checking them.
//
- Status = VIRTIO_CFG_WRITE (Dev, CdbSize, VIRTIO_SCSI_CDB_SIZE);
+ Status = VIRTIO_CFG_WRITE (Dev, CdbSize, VIRTIO_SCSI_CDB_SIZE);
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
- Status = VIRTIO_CFG_WRITE (Dev, SenseSize, VIRTIO_SCSI_SENSE_SIZE);
+ Status = VIRTIO_CFG_WRITE (Dev, SenseSize, VIRTIO_SCSI_SENSE_SIZE);
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
@@ -862,7 +875,7 @@ VirtioScsiInit (
// step 6 -- initialization complete
//
NextDevStat |= VSTAT_DRIVER_OK;
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto ReleaseQueue;
}
@@ -906,10 +919,10 @@ ReleaseQueue:
Failed:
//
// Notify the host about our failure to setup: virtio-0.9.5, 2.2.2.1 Device
- // Status. VirtIo access failure here should not mask the original error.
+ // Status. VirtIo access failure here should not mask the original error.
//
NextDevStat |= VSTAT_FAILED;
- Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
Dev->InOutSupported = FALSE;
Dev->MaxTarget = 0;
@@ -933,7 +946,7 @@ VirtioScsiUninit (
// VIRTIO_CFG_WRITE() returns, the host will have learned to stay away from
// the old comms area.
//
- Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
+ Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
Dev->InOutSupported = FALSE;
Dev->MaxTarget = 0;
@@ -970,37 +983,37 @@ VirtioScsiDriverBindingSupported (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
- EFI_STATUS Status;
- VIRTIO_DEVICE_PROTOCOL *VirtIo;
+ EFI_STATUS Status;
+ VIRTIO_DEVICE_PROTOCOL *VirtIo;
//
- // Attempt to open the device with the VirtIo set of interfaces. On success,
- // the protocol is "instantiated" for the VirtIo device. Covers duplicate open
+ // Attempt to open the device with the VirtIo set of interfaces. On success,
+ // the protocol is "instantiated" for the VirtIo device. Covers duplicate open
// attempts (EFI_ALREADY_STARTED).
//
Status = gBS->OpenProtocol (
DeviceHandle, // candidate device
- &gVirtioDeviceProtocolGuid, // for generic VirtIo access
- (VOID **)&VirtIo, // handle to instantiate
+ &gVirtioDeviceProtocolGuid, // for generic VirtIo access
+ (VOID **)&VirtIo, // handle to instantiate
This->DriverBindingHandle, // requestor driver identity
DeviceHandle, // ControllerHandle, according to
// the UEFI Driver Model
- EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive VirtIo access to
+ EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive VirtIo access to
// the device; to be released
);
if (EFI_ERROR (Status)) {
return Status;
}
- if (VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_SCSI_HOST) {
- Status = EFI_UNSUPPORTED;
+ if (VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_SCSI_HOST) {
+ Status = EFI_UNSUPPORTED;
}
//
- // We needed VirtIo access only transitorily, to see whether we support the
+ // We needed VirtIo access only transitorily, to see whether we support the
// device or not.
//
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
return Status;
}
@@ -1022,19 +1035,19 @@ VirtioScsiDriverBindingStart (
return EFI_OUT_OF_RESOURCES;
}
- Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
- (VOID **)&Dev->VirtIo, This->DriverBindingHandle,
+ Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ (VOID **)&Dev->VirtIo, This->DriverBindingHandle,
DeviceHandle, EFI_OPEN_PROTOCOL_BY_DRIVER);
if (EFI_ERROR (Status)) {
goto FreeVirtioScsi;
}
//
- // VirtIo access granted, configure virtio-scsi device.
+ // VirtIo access granted, configure virtio-scsi device.
//
Status = VirtioScsiInit (Dev);
if (EFI_ERROR (Status)) {
- goto CloseVirtIo;
+ goto CloseVirtIo;
}
//
@@ -1054,8 +1067,8 @@ VirtioScsiDriverBindingStart (
UninitDev:
VirtioScsiUninit (Dev);
-CloseVirtIo:
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+CloseVirtIo:
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
FreeVirtioScsi:
@@ -1103,7 +1116,7 @@ VirtioScsiDriverBindingStop (
VirtioScsiUninit (Dev);
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
FreePool (Dev);
diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.h b/OvmfPkg/VirtioScsiDxe/VirtioScsi.h
index 42d8ed765..0d3181d14 100644
--- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.h
+++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.h
@@ -48,17 +48,17 @@ typedef struct {
// at various call depths. The table to the right should make it easier to
// track them.
//
- // field init function init depth
- // ---------------- ------------------ ----------
- UINT32 Signature; // DriverBindingStart 0
- VIRTIO_DEVICE_PROTOCOL *VirtIo; // DriverBindingStart 0
- BOOLEAN InOutSupported; // VirtioScsiInit 1
- UINT16 MaxTarget; // VirtioScsiInit 1
- UINT32 MaxLun; // VirtioScsiInit 1
- UINT32 MaxSectors; // VirtioScsiInit 1
- VRING Ring; // VirtioRingInit 2
- EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; // VirtioScsiInit 1
- EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode; // VirtioScsiInit 1
+ // field init function init depth
+ // ---------------- ------------------ ----------
+ UINT32 Signature; // DriverBindingStart 0
+ VIRTIO_DEVICE_PROTOCOL *VirtIo; // DriverBindingStart 0
+ BOOLEAN InOutSupported; // VirtioScsiInit 1
+ UINT16 MaxTarget; // VirtioScsiInit 1
+ UINT32 MaxLun; // VirtioScsiInit 1
+ UINT32 MaxSectors; // VirtioScsiInit 1
+ VRING Ring; // VirtioRingInit 2
+ EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; // VirtioScsiInit 1
+ EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode; // VirtioScsiInit 1
} VSCSI_DEV;
#define VIRTIO_SCSI_FROM_PASS_THRU(PassThruPointer) \
diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.inf b/OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
index e98780db8..755811239 100644
--- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
+++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
@@ -40,7 +40,7 @@
[Protocols]
gEfiExtScsiPassThruProtocolGuid ## BY_START
- gVirtioDeviceProtocolGuid ## TO_START
+ gVirtioDeviceProtocolGuid ## TO_START
[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdVirtioScsiMaxTargetLimit ## CONSUMES
diff --git a/OvmfPkg/create-release.py b/OvmfPkg/create-release.py
index 6a6017a9f..a15d2473c 100755
--- a/OvmfPkg/create-release.py
+++ b/OvmfPkg/create-release.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
-# Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2010 - 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
@@ -11,8 +11,6 @@
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
-release_type = 'alpha'
-
import os
import re
import StringIO
@@ -33,11 +31,6 @@ if not os.path.exists(os.path.join('OvmfPkg', 'OvmfPkgX64.dsc')):
print "OvmfPkg/OvmfPkgX64.dsc doesn't exist"
sys.exit(-1)
-if 'TOOLCHAIN' in os.environ:
- TOOLCHAIN = os.environ['TOOLCHAIN']
-else:
- TOOLCHAIN = 'GCC44'
-
def run_and_capture_output(args, checkExitCode = True):
p = subprocess.Popen(args=args, stdout=subprocess.PIPE)
stdout = p.stdout.read()
@@ -46,12 +39,37 @@ def run_and_capture_output(args, checkExitCode = True):
assert ret_code == 0
return stdout
-def git_svn_info():
+gcc_version = run_and_capture_output(args=('gcc', '--version'))
+gcc_re = re.compile(r'\s*\S+\s+\([^\)]+?\)\s+(\d+(?:\.\d+)*)(?:\s+.*)?')
+mo = gcc_re.match(gcc_version)
+if not mo:
+ print "Unable to find GCC version"
+ sys.exit(-1)
+gcc_version = map(lambda n: int(n), mo.group(1).split('.'))
+
+if 'TOOLCHAIN' in os.environ:
+ TOOLCHAIN = os.environ['TOOLCHAIN']
+else:
+ assert(gcc_version[0] == 4)
+ minor = max(4, min(7, gcc_version[1]))
+ TOOLCHAIN = 'GCC4' + str(minor)
+
+def git_based_version():
dir = os.getcwd()
- os.chdir('OvmfPkg')
- stdout = run_and_capture_output(args=('git', 'svn', 'info'))
+ if not os.path.exists('.git'):
+ os.chdir('OvmfPkg')
+ stdout = run_and_capture_output(args=('git', 'log',
+ '-n', '1',
+ '--abbrev-commit'))
+ regex = re.compile(r'^\s*git-svn-id:\s+\S+@(\d+)\s+[0-9a-f\-]+$',
+ re.MULTILINE)
+ mo = regex.search(stdout)
+ if mo:
+ version = 'r' + mo.group(1)
+ else:
+ version = stdout.split(None, 3)[1]
os.chdir(dir)
- return stdout
+ return version
def svn_info():
dir = os.getcwd()
@@ -60,18 +78,18 @@ def svn_info():
os.chdir(dir)
return stdout
-def get_svn_info_output():
- if os.path.exists(os.path.join('OvmfPkg', '.svn')):
- return svn_info()
- else:
- return git_svn_info()
+def svn_based_version():
+ buf = svn_info()
+ revision_re = re.compile('^Revision\:\s*([\da-f]+)$', re.MULTILINE)
+ mo = revision_re.search(buf)
+ assert(mo is not None)
+ return 'r' + mo.group(1)
def get_revision():
- buf = get_svn_info_output()
- revision_re = re.compile('^Revision\:\s*(\d+)$', re.MULTILINE)
- mo = revision_re.search(buf)
- if mo is not None:
- return int(mo.group(1))
+ if os.path.exists(os.path.join('OvmfPkg', '.svn')):
+ return svn_based_version()
+ else:
+ return git_based_version()
revision = get_revision()
@@ -84,8 +102,7 @@ def gen_build_info():
machine = run_and_capture_output(args=('uname', '-m')).strip()
- gcc_version = run_and_capture_output(args=('gcc', '--version'))
- gcc_version = gcc_version.split('\n')[0].split()[-1]
+ gcc_version_str = '.'.join(map(lambda v: str(v), gcc_version))
ld_version = run_and_capture_output(args=('ld', '--version'))
ld_version = ld_version.split('\n')[0].split()[-1]
@@ -95,13 +112,19 @@ def gen_build_info():
iasl_version = iasl_version.split(' version ')[1].strip()
sb = StringIO.StringIO()
- print >> sb, 'edk2: ', 'r%d' % revision
- print >> sb, 'compiler: GCC', gcc_version
+ print >> sb, 'edk2: ', revision
+ print >> sb, 'compiler: GCC', gcc_version_str, '(' + TOOLCHAIN + ')'
print >> sb, 'binutils:', ld_version
print >> sb, 'iasl: ', iasl_version
print >> sb, 'system: ', distro, machine.replace('_', '-')
return to_dos_text(sb.getvalue())
+def read_file(filename):
+ f = open(filename)
+ d = f.read()
+ f.close()
+ return d
+
LICENSE = to_dos_text(
'''This OVMF binary release is built from source code licensed under
the BSD open source license. The BSD license is documented at
@@ -116,76 +139,22 @@ and a copy is shown below (following the normal BSD license).
=== BSD license: START ===
-Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
-* Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-* Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-* Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
+''')
+
+LICENSE += read_file(os.path.join('MdePkg', 'License.txt'))
+LICENSE += to_dos_text(
+'''
=== BSD license: END ===
=== FAT filesystem driver license: START ===
-Copyright (c) 2004, Intel Corporation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
-* Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-* Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-* Neither the name of Intel nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
-Additional terms:
-In addition to the forgoing, redistribution and use of the code is
-conditioned upon the FAT 32 File System Driver and all derivative
-works thereof being used for and designed only to read and/or write
-to a file system that is directly managed by an Extensible Firmware
-Interface (EFI) implementation or by an emulator of an EFI
-implementation.
+''')
+
+LICENSE += read_file(os.path.join('FatBinPkg', 'License.txt'))
+LICENSE += to_dos_text(
+'''
=== FAT filesystem driver license: END ===
''')
@@ -210,7 +179,7 @@ def build(arch):
def create_zip(arch):
global build_info
- filename = 'OVMF-%s-r%d-%s.zip' % (arch, revision, release_type)
+ filename = 'OVMF-%s-%s.zip' % (arch, revision)
print 'Creating', filename, '...',
sys.stdout.flush()
if os.path.exists(filename):