Skip to content

Commit

Permalink
Ovmf/Xen: move XenBusDxe to abstract XENIO_PROTOCOL
Browse files Browse the repository at this point in the history
While Xen on Intel uses a virtual PCI device to communicate the
base address of the grant table, the ARM implementation uses a DT
node, which is fundamentally incompatible with the way XenBusDxe is
implemented, i.e., as a UEFI Driver Model implementation for a PCI
device.

Contributed-under: TianoCore Contribution Agreement 1.0
Acked-by: Laszlo Ersek <[email protected]>
Reviewed-by: Anthony PERARD <[email protected]>
Signed-off-by: Ard Biesheuvel <[email protected]>
Signed-off-by: Laszlo Ersek <[email protected]>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16973 6f19259b-4bc3-4df7-8a09-765794883524
  • Loading branch information
Ard Biesheuvel authored and lersek committed Feb 28, 2015
1 parent f2162d3 commit d9fdfd8
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 58 deletions.
1 change: 1 addition & 0 deletions OvmfPkg/OvmfPkgIa32.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
OvmfPkg/XenBusDxe/XenBusDxe.inf
OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf {
Expand Down
1 change: 1 addition & 0 deletions OvmfPkg/OvmfPkgIa32.fdf
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
INF OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
INF OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
INF OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
INF OvmfPkg/XenBusDxe/XenBusDxe.inf
INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf

Expand Down
1 change: 1 addition & 0 deletions OvmfPkg/OvmfPkgIa32X64.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
OvmfPkg/XenBusDxe/XenBusDxe.inf
OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf {
Expand Down
1 change: 1 addition & 0 deletions OvmfPkg/OvmfPkgIa32X64.fdf
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
INF OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
INF OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
INF OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
INF OvmfPkg/XenBusDxe/XenBusDxe.inf
INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf

Expand Down
1 change: 1 addition & 0 deletions OvmfPkg/OvmfPkgX64.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf
OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
OvmfPkg/XenBusDxe/XenBusDxe.inf
OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf {
Expand Down
1 change: 1 addition & 0 deletions OvmfPkg/OvmfPkgX64.fdf
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf
INF OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
INF OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
INF OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
INF OvmfPkg/XenBusDxe/XenBusDxe.inf
INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf

Expand Down
2 changes: 1 addition & 1 deletion OvmfPkg/XenBusDxe/ComponentName.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ XenBusDxeComponentNameGetControllerName (
Status = EfiTestManagedDevice (
ControllerHandle,
gXenBusDxeDriverBinding.DriverBindingHandle,
&gEfiPciIoProtocolGuid
&gXenIoProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
Expand Down
5 changes: 2 additions & 3 deletions OvmfPkg/XenBusDxe/GrantTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ XenGrantTableEndAccess (

VOID
XenGrantTableInit (
IN XENBUS_DEVICE *Dev,
IN UINT64 MmioAddr
IN XENBUS_DEVICE *Dev
)
{
xen_add_to_physmap_t Parameters;
Expand All @@ -155,7 +154,7 @@ XenGrantTableInit (
XenGrantTablePutFreeEntry ((grant_ref_t)Index);
}

GrantTable = (VOID*)(UINTN) MmioAddr;
GrantTable = (VOID*)(UINTN) Dev->XenIo->GrantTableAddress;
for (Index = 0; Index < NR_GRANT_FRAMES; Index++) {
Parameters.domid = DOMID_SELF;
Parameters.idx = Index;
Expand Down
3 changes: 1 addition & 2 deletions OvmfPkg/XenBusDxe/GrantTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
**/
VOID
XenGrantTableInit (
IN XENBUS_DEVICE *Dev,
IN UINT64 MmioAddr
IN XENBUS_DEVICE *Dev
);

/**
Expand Down
6 changes: 3 additions & 3 deletions OvmfPkg/XenBusDxe/XenBus.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ XenBusAddDevice (
XENBUS_PRIVATE_DATA *Private;
EFI_STATUS Status;
XENBUS_DEVICE_PATH *TempXenBusPath;
VOID *ChildPciIo;
VOID *ChildXenIo;

AsciiSPrint (DevicePath, sizeof (DevicePath),
"device/%a/%a", Type, Id);
Expand Down Expand Up @@ -208,8 +208,8 @@ XenBusAddDevice (
}

Status = gBS->OpenProtocol (Dev->ControllerHandle,
&gEfiPciIoProtocolGuid,
&ChildPciIo, Dev->This->DriverBindingHandle,
&gXenIoProtocolGuid,
&ChildXenIo, Dev->This->DriverBindingHandle,
Private->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER);
if (EFI_ERROR (Status)) {
Expand Down
55 changes: 13 additions & 42 deletions OvmfPkg/XenBusDxe/XenBusDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
**/

#include <IndustryStandard/Pci.h>
#include <IndustryStandard/Acpi.h>
#include <Library/DebugLib.h>
#include <Library/XenHypercallLib.h>

Expand Down Expand Up @@ -233,34 +231,22 @@ XenBusDxeDriverBindingSupported (
)
{
EFI_STATUS Status;
EFI_PCI_IO_PROTOCOL *PciIo;
PCI_TYPE00 Pci;
XENIO_PROTOCOL *XenIo;

Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiPciIoProtocolGuid,
(VOID **)&PciIo,
&gXenIoProtocolGuid,
(VOID **)&XenIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);

if (EFI_ERROR (Status)) {
return Status;
}

Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0,
sizeof Pci / sizeof (UINT32), &Pci);

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;
}
}

gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid,
gBS->CloseProtocol (ControllerHandle, &gXenIoProtocolGuid,
This->DriverBindingHandle, ControllerHandle);

return Status;
Expand Down Expand Up @@ -326,19 +312,18 @@ XenBusDxeDriverBindingStart (
{
EFI_STATUS Status;
XENBUS_DEVICE *Dev;
EFI_PCI_IO_PROTOCOL *PciIo;
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BarDesc;
UINT64 MmioAddr;
XENIO_PROTOCOL *XenIo;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;

Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiPciIoProtocolGuid,
(VOID **) &PciIo,
&gXenIoProtocolGuid,
(VOID**)&XenIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);

if (EFI_ERROR (Status)) {
return Status;
}
Expand All @@ -360,7 +345,7 @@ XenBusDxeDriverBindingStart (
Dev->Signature = XENBUS_DEVICE_SIGNATURE;
Dev->This = This;
Dev->ControllerHandle = ControllerHandle;
Dev->PciIo = PciIo;
Dev->XenIo = XenIo;
Dev->DevicePath = DevicePath;
InitializeListHead (&Dev->ChildList);

Expand All @@ -376,28 +361,14 @@ XenBusDxeDriverBindingStart (
mMyDevice = Dev;
EfiReleaseLock (&mMyDeviceLock);

//
// The BAR1 of this PCI device is used for shared memory and is supposed to
// look like MMIO. The address space of the BAR1 will be used to map the
// Grant Table.
//
Status = PciIo->GetBarAttributes (PciIo, PCI_BAR_IDX1, NULL, (VOID**) &BarDesc);
ASSERT_EFI_ERROR (Status);
ASSERT (BarDesc->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM);

/* Get a Memory address for mapping the Grant Table. */
DEBUG ((EFI_D_INFO, "XenBus: BAR at %LX\n", BarDesc->AddrRangeMin));
MmioAddr = BarDesc->AddrRangeMin;
FreePool (BarDesc);

Status = XenGetSharedInfoPage (Dev);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "XenBus: Unable to get the shared info page.\n"));
Status = EFI_UNSUPPORTED;
goto ErrorAllocated;
}

XenGrantTableInit (Dev, MmioAddr);
XenGrantTableInit (Dev);

Status = XenStoreInit (Dev);
ASSERT_EFI_ERROR (Status);
Expand All @@ -417,7 +388,7 @@ XenBusDxeDriverBindingStart (
gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid,
This->DriverBindingHandle, ControllerHandle);
ErrorOpenningProtocol:
gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid,
gBS->CloseProtocol (ControllerHandle, &gXenIoProtocolGuid,
This->DriverBindingHandle, ControllerHandle);
return Status;
}
Expand Down Expand Up @@ -507,7 +478,7 @@ XenBusDxeDriverBindingStop (

gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid,
This->DriverBindingHandle, ControllerHandle);
gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid,
gBS->CloseProtocol (ControllerHandle, &gXenIoProtocolGuid,
This->DriverBindingHandle, ControllerHandle);

mMyDevice = NULL;
Expand Down
8 changes: 2 additions & 6 deletions OvmfPkg/XenBusDxe/XenBusDxe.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
//
// Consumed Protocols
//
#include <Protocol/PciIo.h>
#include <Protocol/XenIo.h>


//
Expand Down Expand Up @@ -73,10 +73,6 @@ extern EFI_COMPONENT_NAME_PROTOCOL gXenBusDxeComponentName;
//
#include <IndustryStandard/Xen/xen.h>

#define PCI_VENDOR_ID_XEN 0x5853
#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001


typedef struct _XENBUS_DEVICE_PATH XENBUS_DEVICE_PATH;
typedef struct _XENBUS_DEVICE XENBUS_DEVICE;

Expand All @@ -86,7 +82,7 @@ struct _XENBUS_DEVICE {
UINT32 Signature;
EFI_DRIVER_BINDING_PROTOCOL *This;
EFI_HANDLE ControllerHandle;
EFI_PCI_IO_PROTOCOL *PciIo;
XENIO_PROTOCOL *XenIo;
EFI_EVENT ExitBootEvent;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
LIST_ENTRY ChildList;
Expand Down
2 changes: 1 addition & 1 deletion OvmfPkg/XenBusDxe/XenBusDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@

[Protocols]
gEfiDriverBindingProtocolGuid
gEfiPciIoProtocolGuid
gEfiComponentName2ProtocolGuid
gEfiComponentNameProtocolGuid
gXenBusProtocolGuid
gXenIoProtocolGuid

0 comments on commit d9fdfd8

Please sign in to comment.