From patchwork Fri Jan 23 15:03:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 43664 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 13B3C218DB for ; Fri, 23 Jan 2015 15:04:35 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id r20sf1695871wiv.2 for ; Fri, 23 Jan 2015 07:04:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=i7QlCUIg3wSpthDbCFE/kqUK4yN2MjkQczKh1OXNYjc=; b=e50f1vAP8Guu/Wyol0md5GSUzW2VGv7hSOR+BkY3PhSvYcWjX+a2gNywGSDSgm2IcN RLoynFitCS3fGPOftpPmjsahpR3XBZEArNlX+ZLfQhpo49o3fSzmdyNB//Jrcns5/bYl O3Ix7+l1isHyTsLQkACL20UR3r4nYLk2obH2M3IKwA9+5Ks0khriMH3TH9d6GyC7tZsM /RXVFXbxvlfgzpRqdZMqD1q2yY03gZKMLH3uZG+2ba5qLE7oiEyqFDtYOjfnIpfLBtFU FNvWghVPrZD9ZcolynyJTcLZJu4vPWMzPLsphqzrPcREBK/4c2jLKCgKND6i8yNJPLE4 rC3A== X-Gm-Message-State: ALoCoQlAQfV+juJKU3cPCLylriJpJOeZ/IA6e0U/spjpo+xLOH3wL6jy4MzB3AkKncGKoLnaGX4p X-Received: by 10.112.9.199 with SMTP id c7mr1072115lbb.7.1422025474298; Fri, 23 Jan 2015 07:04:34 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.10 with SMTP id lc10ls304312lac.22.gmail; Fri, 23 Jan 2015 07:04:34 -0800 (PST) X-Received: by 10.112.144.136 with SMTP id sm8mr7806536lbb.95.1422025474066; Fri, 23 Jan 2015 07:04:34 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id ln11si1549373lac.114.2015.01.23.07.04.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jan 2015 07:04:34 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id l4so7442414lbv.13 for ; Fri, 23 Jan 2015 07:04:34 -0800 (PST) X-Received: by 10.112.44.230 with SMTP id h6mr7744788lbm.98.1422025473942; Fri, 23 Jan 2015 07:04:33 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp283208lbb; Fri, 23 Jan 2015 07:04:32 -0800 (PST) X-Received: by 10.107.47.29 with SMTP id j29mr4111224ioo.18.1422025470358; Fri, 23 Jan 2015 07:04:30 -0800 (PST) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id 86si1297443ios.59.2015.01.23.07.04.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 23 Jan 2015 07:04:30 -0800 (PST) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YEfmY-0007OE-0R; Fri, 23 Jan 2015 15:04:22 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YEfmW-0007O4-Jv for edk2-devel@lists.sourceforge.net; Fri, 23 Jan 2015 15:04:20 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.47 as permitted sender) client-ip=74.125.82.47; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wg0-f47.google.com; Received: from mail-wg0-f47.google.com ([74.125.82.47]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1YEfmU-0004Ta-OD for edk2-devel@lists.sourceforge.net; Fri, 23 Jan 2015 15:04:20 +0000 Received: by mail-wg0-f47.google.com with SMTP id n12so7993675wgh.6 for ; Fri, 23 Jan 2015 07:04:12 -0800 (PST) X-Received: by 10.194.200.1 with SMTP id jo1mr15384933wjc.64.1422025452739; Fri, 23 Jan 2015 07:04:12 -0800 (PST) Received: from ards-macbook-pro.local ([197.129.136.117]) by mx.google.com with ESMTPSA id pl1sm2176036wic.16.2015.01.23.07.04.05 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Jan 2015 07:04:07 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, lersek@redhat.com, olivier.martin@arm.com, roy.franz@linaro.org, leif.lindholm@linaro.org, stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, anthony.perard@citrix.com, christoffer.dall@linaro.org, xen-devel@lists.xen.org, ilias.biris@linaro.org Date: Fri, 23 Jan 2015 15:03:03 +0000 Message-Id: <1422025390-8036-15-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1422025390-8036-1-git-send-email-ard.biesheuvel@linaro.org> References: <1422025390-8036-1-git-send-email-ard.biesheuvel@linaro.org> X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1YEfmU-0004Ta-OD Subject: [edk2] [PATCH v1 14/21] Ovmf/Xen: allow non-PCI usage of XenBusDxe X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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. To allow the non-PCI implementations to use this driver anyway, this patch introduces an abstract XENIO_PROTOCOL protocol, which contains just the grant table base address. The Intel implementation is adapted to allocate such a protocol on the fly based on the PCI config space metadata, so it operates as before. Other users can invoke the driver by installing a XENIO_PROTOCOL instance on a handle, and invoking ConnectController() Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- OvmfPkg/Include/Protocol/XenIo.h | 48 ++++++++++ OvmfPkg/OvmfPkg.dec | 1 + OvmfPkg/XenBusDxe/ComponentName.c | 2 +- OvmfPkg/XenBusDxe/GrantTable.c | 5 +- OvmfPkg/XenBusDxe/GrantTable.h | 3 +- OvmfPkg/XenBusDxe/XenBus.c | 6 +- OvmfPkg/XenBusDxe/XenBusDxe.c | 190 ++++++++++++++++++++++++++++++++------ OvmfPkg/XenBusDxe/XenBusDxe.h | 2 + OvmfPkg/XenBusDxe/XenBusDxe.inf | 1 + 9 files changed, 220 insertions(+), 38 deletions(-) create mode 100644 OvmfPkg/Include/Protocol/XenIo.h diff --git a/OvmfPkg/Include/Protocol/XenIo.h b/OvmfPkg/Include/Protocol/XenIo.h new file mode 100644 index 000000000000..510391f3b3e8 --- /dev/null +++ b/OvmfPkg/Include/Protocol/XenIo.h @@ -0,0 +1,48 @@ +/** @file + XenIo protocol to abstract arch specific details + + The Xen implementations for the Intel and ARM archictures differ in the way + the base address of the grant table is communicated to the guest. The former + uses a virtual PCI device, while the latter uses a device tree node. + In order to allow the XenBusDxe UEFI driver to be reused for the non-PCI + Xen implementation, this abstract protocol can be installed on a handle + with the appropriate base address. + + Copyright (C) 2014, 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. + +**/ + +#ifndef __PROTOCOL_XENIO_H__ +#define __PROTOCOL_XENIO_H__ + +#include + +#define XENIO_PROTOCOL_GUID \ + {0x6efac84f, 0x0ab0, 0x4747, {0x81, 0xbe, 0x85, 0x55, 0x62, 0x59, 0x04, 0x49}} + +/// +/// Forward declaration +/// +typedef struct _XENIO_PROTOCOL XENIO_PROTOCOL; + +/// +/// Protocol structure +/// +struct _XENIO_PROTOCOL { + // + // Protocol data fields + // + EFI_PHYSICAL_ADDRESS GrantTableAddress; +}; + +extern EFI_GUID gXenIoProtocolGuid; + +#endif diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 30a9fb1e9b42..3711fa922311 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -58,6 +58,7 @@ gVirtioDeviceProtocolGuid = {0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}} gBlockMmioProtocolGuid = {0x6b558ce3, 0x69e5, 0x4c67, {0xa6, 0x34, 0xf7, 0xfe, 0x72, 0xad, 0xbe, 0x84}} gXenBusProtocolGuid = {0x3d3ca290, 0xb9a5, 0x11e3, {0xb7, 0x5d, 0xb8, 0xac, 0x6f, 0x7d, 0x65, 0xe6}} + gXenIoProtocolGuid = {0x6efac84f, 0x0ab0, 0x4747, {0x81, 0xbe, 0x85, 0x55, 0x62, 0x59, 0x04, 0x49}} [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase|0x0|UINT32|0 diff --git a/OvmfPkg/XenBusDxe/ComponentName.c b/OvmfPkg/XenBusDxe/ComponentName.c index 4530509e65dc..3f2dd406c77d 100644 --- a/OvmfPkg/XenBusDxe/ComponentName.c +++ b/OvmfPkg/XenBusDxe/ComponentName.c @@ -155,7 +155,7 @@ XenBusDxeComponentNameGetControllerName ( Status = EfiTestManagedDevice ( ControllerHandle, gXenBusDxeDriverBinding.DriverBindingHandle, - &gEfiPciIoProtocolGuid + &gXenIoProtocolGuid ); if (EFI_ERROR (Status)) { return Status; diff --git a/OvmfPkg/XenBusDxe/GrantTable.c b/OvmfPkg/XenBusDxe/GrantTable.c index 52ff045a74db..e825c7c76fa5 100644 --- a/OvmfPkg/XenBusDxe/GrantTable.c +++ b/OvmfPkg/XenBusDxe/GrantTable.c @@ -139,8 +139,7 @@ XenGrantTableEndAccess ( VOID XenGrantTableInit ( - IN XENBUS_DEVICE *Dev, - IN UINT64 MmioAddr + IN XENBUS_DEVICE *Dev ) { xen_add_to_physmap_t Parameters; @@ -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; diff --git a/OvmfPkg/XenBusDxe/GrantTable.h b/OvmfPkg/XenBusDxe/GrantTable.h index 5772c56662df..194275ba7ed5 100644 --- a/OvmfPkg/XenBusDxe/GrantTable.h +++ b/OvmfPkg/XenBusDxe/GrantTable.h @@ -29,8 +29,7 @@ **/ VOID XenGrantTableInit ( - IN XENBUS_DEVICE *Dev, - IN UINT64 MmioAddr + IN XENBUS_DEVICE *Dev ); /** diff --git a/OvmfPkg/XenBusDxe/XenBus.c b/OvmfPkg/XenBusDxe/XenBus.c index f69c27dd184a..ee9526c33252 100644 --- a/OvmfPkg/XenBusDxe/XenBus.c +++ b/OvmfPkg/XenBusDxe/XenBus.c @@ -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); @@ -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)) { diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.c b/OvmfPkg/XenBusDxe/XenBusDxe.c index cc334c086c1f..efa9bb0ccd23 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.c +++ b/OvmfPkg/XenBusDxe/XenBusDxe.c @@ -234,8 +234,29 @@ XenBusDxeDriverBindingSupported ( { EFI_STATUS Status; EFI_PCI_IO_PROTOCOL *PciIo; + XENIO_PROTOCOL *XenIo; PCI_TYPE00 Pci; + // + // If the ControllerHandle supports the XENIO_PROTOCOL, we can use + // it directly without having to bother with the PCI representation. + // + Status = gBS->OpenProtocol ( + ControllerHandle, + &gXenIoProtocolGuid, + (VOID **)&XenIo, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + + gBS->CloseProtocol (ControllerHandle, &gXenIoProtocolGuid, + This->DriverBindingHandle, ControllerHandle); + + if (!EFI_ERROR (Status) || Status == EFI_ALREADY_STARTED) { + return Status; + } + Status = gBS->OpenProtocol ( ControllerHandle, &gEfiPciIoProtocolGuid, @@ -280,6 +301,137 @@ NotifyExitBoot ( } /** + Opens the XENIO_PROTOCOL on ControllerHandle. + + If the protocol is not available, but the EFI_PCI_IO_PROTOCOL is, create + the XENIO_PROTOCOL protocol instance on the fly based on the PCI metadata + and install it on Handle. + + @param ControllerHandle The controller handle + @param DriverBindingHandle The driver binding handle + @param XenIo The XENIO_PROTOCOL return value + @param PciIo The EFI_PCI_IO_PROTOCOL return value, or NULL if + the XENIO_PROTOCOL already existed on Handle +**/ +STATIC +EFI_STATUS +OpenOrInstallXenIoProtocolOnHandle ( + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE DriverBindingHandle, + OUT XENIO_PROTOCOL **XenIo, + OUT EFI_PCI_IO_PROTOCOL **PciIo + ) +{ + EFI_STATUS Status; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BarDesc; + + // + // We support both EFI_PCI_IO_PROTOCOL and XENIO_PROTOCOL, the former only + // if the vendor and product IDs match up (as verified in .Supported()). + // The latter has precedence, and we install it on the fly if it is not + // supported. + // + *PciIo = NULL; + Status = gBS->OpenProtocol ( + ControllerHandle, + &gXenIoProtocolGuid, + (VOID**)XenIo, + DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (EFI_ERROR (Status)) { + // + // This handle does not support XENIO_PROTOCOL yet, which implies that it + // does support the EFI_PCI_IO_PROTOCOL, or we wouldn't have been invoked. + // Get the grant table base address from the PCI config space, and allocate + // and install the XENIO_PROTOCOL instance on the fly. + // + Status = gBS->OpenProtocol ( + ControllerHandle, + &gEfiPciIoProtocolGuid, + (VOID**)PciIo, + DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + ASSERT_EFI_ERROR (Status); + + *XenIo = AllocateZeroPool (sizeof(XENIO_PROTOCOL)); + ASSERT (*XenIo != NULL); + + // + // 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)); + (*XenIo)->GrantTableAddress = BarDesc->AddrRangeMin; + FreePool (BarDesc); + + // + // Now install the XENIO_PROTOCOL protocol instance on Handle. + // This should only fail in extraordinary cases, as we have already + // established that the protocol does not exist yet on the handle. + // + Status = gBS->InstallProtocolInterface (ControllerHandle, + &gXenIoProtocolGuid, EFI_NATIVE_INTERFACE, *XenIo); + ASSERT_EFI_ERROR (Status); + + Status = gBS->OpenProtocol ( + ControllerHandle, + &gXenIoProtocolGuid, + (VOID**)XenIo, + DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (EFI_ERROR (Status)) { + gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid, + DriverBindingHandle, ControllerHandle); + } + } + return Status; +} + +/** + Close or uninstall the XENIO_PROTOCOL instance on ControllerHandle + + Close the XENIO_PROTOCOL protocol instance on ControllerHandle, and + in case PciIo != NULL, uninstall and deallocate it as well. + + @param ControllerHandle The controller handle + @param DriverBindingHandle The driver binding handle + @param XenIo The XENIO_PROTOCOL protocol instance + @param PciIo The EFI_PCI_IO_PROTOCOL protocol instance, or NULL + if the XENIO_PROTOCOL already existed on + ControllerHandle +**/ +STATIC +VOID +CloseOrUninstallXenIoProtocolOnHandle ( + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE DriverBindingHandle, + IN XENIO_PROTOCOL *XenIo, + IN EFI_PCI_IO_PROTOCOL *PciIo + ) +{ + gBS->CloseProtocol (ControllerHandle, &gXenIoProtocolGuid, + DriverBindingHandle, ControllerHandle); + if (PciIo != NULL) { + gBS->UninstallProtocolInterface (ControllerHandle, &gXenIoProtocolGuid, XenIo); + FreePool (XenIo); + gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid, + DriverBindingHandle, ControllerHandle); + } +} + +/** Starts a bus controller. The Start() function is designed to be invoked from the EFI boot service ConnectController(). @@ -326,19 +478,12 @@ XenBusDxeDriverBindingStart ( { EFI_STATUS Status; XENBUS_DEVICE *Dev; + XENIO_PROTOCOL *XenIo; EFI_PCI_IO_PROTOCOL *PciIo; - EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BarDesc; - UINT64 MmioAddr; EFI_DEVICE_PATH_PROTOCOL *DevicePath; - Status = gBS->OpenProtocol ( - ControllerHandle, - &gEfiPciIoProtocolGuid, - (VOID **) &PciIo, - This->DriverBindingHandle, - ControllerHandle, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); + Status = OpenOrInstallXenIoProtocolOnHandle (ControllerHandle, + This->DriverBindingHandle, &XenIo, &PciIo); if (EFI_ERROR (Status)) { return Status; } @@ -361,6 +506,7 @@ XenBusDxeDriverBindingStart ( Dev->This = This; Dev->ControllerHandle = ControllerHandle; Dev->PciIo = PciIo; + Dev->XenIo = XenIo; Dev->DevicePath = DevicePath; InitializeListHead (&Dev->ChildList); @@ -376,20 +522,6 @@ 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")); @@ -397,7 +529,7 @@ XenBusDxeDriverBindingStart ( goto ErrorAllocated; } - XenGrantTableInit (Dev, MmioAddr); + XenGrantTableInit (Dev); Status = XenStoreInit (Dev); ASSERT_EFI_ERROR (Status); @@ -417,8 +549,8 @@ ErrorAllocated: gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid, This->DriverBindingHandle, ControllerHandle); ErrorOpenningProtocol: - gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid, - This->DriverBindingHandle, ControllerHandle); + CloseOrUninstallXenIoProtocolOnHandle (ControllerHandle, + This->DriverBindingHandle, XenIo, PciIo); return Status; } @@ -507,8 +639,8 @@ XenBusDxeDriverBindingStop ( gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid, This->DriverBindingHandle, ControllerHandle); - gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid, - This->DriverBindingHandle, ControllerHandle); + CloseOrUninstallXenIoProtocolOnHandle (ControllerHandle, + This->DriverBindingHandle, Dev->XenIo, Dev->PciIo); mMyDevice = NULL; FreePool (Dev); diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.h b/OvmfPkg/XenBusDxe/XenBusDxe.h index 9b7219906a69..596e5f04a03b 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.h +++ b/OvmfPkg/XenBusDxe/XenBusDxe.h @@ -40,6 +40,7 @@ // Consumed Protocols // #include +#include // @@ -87,6 +88,7 @@ struct _XENBUS_DEVICE { 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; diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.inf b/OvmfPkg/XenBusDxe/XenBusDxe.inf index 714607dbd6f8..8294997e20db 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.inf +++ b/OvmfPkg/XenBusDxe/XenBusDxe.inf @@ -71,4 +71,5 @@ gEfiComponentName2ProtocolGuid gEfiComponentNameProtocolGuid gXenBusProtocolGuid + gXenIoProtocolGuid