Prepare for making XenBusDxe suitable for use with non-PCI devices
(such as the DT node exposed by Xen on ARM) by introducing a separate
DXE driver that binds to the Xen virtual PCI device and exposes the
abstract XENIO_PROTOCOL for XenBusDxe to bind against.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
---
OvmfPkg/XenIoPciDxe/XenIoPciDxe.c | 367
OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf | 45 +
2 files changed, 412 insertions(+)
create mode 100644 OvmfPkg/XenIoPciDxe/XenIoPciDxe.c
create mode 100644 OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
diff --git a/OvmfPkg/XenIoPciDxe/XenIoPciDxe.c
b/OvmfPkg/XenIoPciDxe/XenIoPciDxe.c
new file mode 100644
index ..c205cf74db34
--- /dev/null
+++ b/OvmfPkg/XenIoPciDxe/XenIoPciDxe.c
@@ -0,0 +1,367 @@
+/** @file
+
+ Driver for the virtual Xen PCI device
+
+ Copyright (C) 2012, Red Hat, Inc.
+ Copyright (c) 2012, Intel Corporation. All rights reserved.BR
+ Copyright (C) 2013, ARM Ltd.
+ Copyright (C) 2015, Linaro 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/Acpi.h
+#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 Protocol/PciIo.h
+#include Protocol/XenIo.h
+
+#define PCI_VENDOR_ID_XEN0x5853
+#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001
+
+/**
+
+ 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] ThisThe 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 The driver does not support the device being probed.
+
+ @return Error codes from the OpenProtocol() boot service or
+ the PciIo protocol.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+XenIoPciDeviceBindingSupported (
+ 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) {
+if ((Pci.Hdr.VendorId == PCI_VENDOR_ID_XEN)
+(Pci.Hdr.DeviceId == PCI_DEVICE_ID_XEN_PLATFORM)) {
+ 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,
+