\r
#include "XenBusDxe.h"\r
\r
+#include "XenHypercall.h"\r
+#include "GrantTable.h"\r
+#include "XenStore.h"\r
+\r
\r
///\r
/// Driver Binding Protocol instance\r
@retval EFI_SUCCESS The device was started.\r
@retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
+ @retval EFI_UNSUPPORTED Something is missing on the system that\r
+ prevent to start the edvice.\r
@retval Others The driver failded to start the device.\r
\r
**/\r
{\r
EFI_STATUS Status;\r
XENBUS_DEVICE *Dev;\r
+ EFI_PCI_IO_PROTOCOL *PciIo;\r
+ EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BarDesc;\r
+ UINT64 MmioAddr;\r
+\r
+ Status = gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiPciIoProtocolGuid,\r
+ (VOID **) &PciIo,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
\r
Dev = AllocateZeroPool (sizeof (*Dev));\r
Dev->Signature = XENBUS_DEVICE_SIGNATURE;\r
Dev->This = This;\r
Dev->ControllerHandle = ControllerHandle;\r
+ Dev->PciIo = PciIo;\r
\r
EfiAcquireLock (&mMyDeviceLock);\r
if (mMyDevice != NULL) {\r
mMyDevice = Dev;\r
EfiReleaseLock (&mMyDeviceLock);\r
\r
+ //\r
+ // The BAR1 of this PCI device is used for shared memory and is supposed to\r
+ // look like MMIO. The address space of the BAR1 will be used to map the\r
+ // Grant Table.\r
+ //\r
+ Status = PciIo->GetBarAttributes (PciIo, PCI_BAR_IDX1, NULL, (VOID**) &BarDesc);\r
+ ASSERT_EFI_ERROR (Status);\r
+ ASSERT (BarDesc->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM);\r
+\r
+ /* Get a Memory address for mapping the Grant Table. */\r
+ DEBUG ((EFI_D_INFO, "XenBus: BAR at %LX\n", BarDesc->AddrRangeMin));\r
+ MmioAddr = BarDesc->AddrRangeMin;\r
+ FreePool (BarDesc);\r
+\r
+ Status = XenHyperpageInit (Dev);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "XenBus: Unable to retrieve the hyperpage.\n"));\r
+ Status = EFI_UNSUPPORTED;\r
+ goto ErrorAllocated;\r
+ }\r
+\r
+ Status = XenGetSharedInfoPage (Dev);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "XenBus: Unable to get the shared info page.\n"));\r
+ Status = EFI_UNSUPPORTED;\r
+ goto ErrorAllocated;\r
+ }\r
+\r
+ XenGrantTableInit (Dev, MmioAddr);\r
+\r
+ Status = XenStoreInit (Dev);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK,\r
NotifyExitBoot,\r
(VOID*) Dev,\r
\r
ErrorAllocated:\r
FreePool (Dev);\r
+ gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid,\r
+ This->DriverBindingHandle, ControllerHandle);\r
return Status;\r
}\r
\r
XENBUS_DEVICE *Dev = mMyDevice;\r
\r
gBS->CloseEvent (Dev->ExitBootEvent);\r
+ XenStoreDeinit (Dev);\r
+ XenGrantTableDeinit (Dev);\r
+\r
+ gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid,\r
+ This->DriverBindingHandle, ControllerHandle);\r
\r
mMyDevice = NULL;\r
FreePool (Dev);\r