From patchwork Thu Dec 8 15:33:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 9466599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 49BBD6071E for ; Thu, 8 Dec 2016 15:48:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B1A2285B1 for ; Thu, 8 Dec 2016 15:48:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E9AF285AC; Thu, 8 Dec 2016 15:48:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F119D285AC for ; Thu, 8 Dec 2016 15:48:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cF0ts-0001Zc-7y; Thu, 08 Dec 2016 15:46:24 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cF0tq-0001Z1-QB for xen-devel@lists.xenproject.org; Thu, 08 Dec 2016 15:46:22 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id C8/51-30093-E4089485; Thu, 08 Dec 2016 15:46:22 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRWlGSWpSXmKPExsXitHSDva5vg2e Ewb0Dchbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aD862sBRfDKyasf8vawLjDuYuRg0NCwF/i xCXbLkZODjYBA4kV068ygtgiAvYSsz/2sYPYzAJ6EucWLWQFsYUFQiQO3XnIDGKzCKhI3Jx7m wXE5hWwk7h24QpYvYSAvMTC80eYQGxOoPjxzZ/ZQGwhAVuJxzd/M0LYahI3Fi6D6hWUODnzCQ vELgmJgy9eME9g5J2FJDULSWoBI9MqRvXi1KKy1CJdc72kosz0jJLcxMwcXUMDM73c1OLixPT UnMSkYr3k/NxNjMDAYQCCHYwzL/sfYpTkYFIS5d01wT1CiC8pP6UyI7E4I76oNCe1+BCjBgeH QN+a1RcYpVjy8vNSlSR4FWo8I4QEi1LTUyvSMnOAoQ1TKsHBoyTCm1INlOYtLkjMLc5Mh0idY rTkuPRm4VMmjkO3lgDJBRNWPmUSApsnJc4rBDJPAKQhozQPbhws/i4xykoJ8zICHSvEU5BalJ tZgir/ilGcg1FJmDcCZApPZl4J3NZXQAcxAR0074Y7yEEliQgpqQZG7ff3X73+vPLfl5TLJuz rYqNaLdzj7LnWXJe+y7Dx80Mmo7WRDp9knAOcpoo2z98bpBDtJnm3LFug2WYfd4+jy16PlWmZ zBsnFDVwht2piPJK+5r5zLDqzd8PP6Rt0j4y7S2a+FWHL3rCn9pmraXbXj5JsbFcfSi5Zu9b1 9kFFSKFJ5r3bXBSYinOSDTUYi4qTgQAW4Yy6roCAAA= X-Env-Sender: prvs=143a4c3ea=anthony.perard@citrix.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1481211979!24281163!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 33641 invoked from network); 8 Dec 2016 15:46:21 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 8 Dec 2016 15:46:21 -0000 X-IronPort-AV: E=Sophos;i="5.33,320,1477958400"; d="scan'208";a="402567039" From: Anthony PERARD To: , Date: Thu, 8 Dec 2016 15:33:39 +0000 Message-ID: <20161208153340.2285-14-anthony.perard@citrix.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161208153340.2285-1-anthony.perard@citrix.com> References: <20161208153340.2285-1-anthony.perard@citrix.com> MIME-Version: 1.0 Cc: Anthony PERARD Subject: [Xen-devel] [PATCH RFC 13/14] OvmfPkg: Introduce XenIoPvhDxe to initialize Grant Tables X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This "device" use XenIoMmioLib to reserve some space to be use by grant tables. It's use 0xfc000000, which might not be a good choice... There is probably a better way that using a device for this. --- OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c | 263 ++++++++++++++++++++++++++++++++++++ OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf | 45 ++++++ OvmfPkg/XenOvmf.dsc | 2 + OvmfPkg/XenOvmf.fdf | 1 + 4 files changed, 311 insertions(+) create mode 100644 OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c create mode 100644 OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf diff --git a/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c b/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c new file mode 100644 index 0000000..12e076f --- /dev/null +++ b/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c @@ -0,0 +1,263 @@ +/** @file + + XXX + + XXX + + 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 +#include +#include +#include +#include +#include + +/* #include */ +STATIC BOOLEAN mXenIoInitialized = FALSE; + +/** + + 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 The driver does not support the device being probed. + + @return Error codes from the OpenProtocol() boot service or + the PciIo protocol. + +**/ +#if 1 +STATIC +EFI_STATUS +EFIAPI +XenIoPvhDeviceBindingSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE DeviceHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath + ) +{ + + // XXX check if running Xen PVH + // + + if (mXenIoInitialized) { + return EFI_ALREADY_STARTED; + } + + DEBUG((EFI_D_INFO, "%a %d\n", __FUNCTION__, __LINE__)); + return EFI_SUCCESS; +} +#endif + +/** + + After we've pronounced support for a specific device in + DriverBindingSupported(), we start managing said device (passed in by the + Driver Execution 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 The device was started. + + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + + @return Error codes from the OpenProtocol() boot + service, the PciIo protocol or the + InstallProtocolInterface() boot service. + +**/ +STATIC +EFI_STATUS +EFIAPI +XenIoPvhDeviceBindingStart ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE DeviceHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle = NULL; + + /* Status = XenIoMmioInstall(&Handle, (UINTN)AllocateReservedPages(4)); */ + Status = XenIoMmioInstall(&Handle, (UINTN)0xfc000000); + + if (!EFI_ERROR (Status)) { + mXenIoInitialized = TRUE; + return EFI_SUCCESS; + } + + return Status; +} + +#if 1 +/** + + Stop driving the XenIo 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 +XenIoPvhDeviceBindingStop ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE DeviceHandle, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer + ) +{ + /* return XenIoMmioUninstall(Handle); */ + return EFI_SUCCESS; +} + + +// +// 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 = { + &XenIoPvhDeviceBindingSupported, + &XenIoPvhDeviceBindingStart, + &XenIoPvhDeviceBindingStop, + 0x10, // Version, must be in [0x10 .. 0xFFFFFFEF] for IHV-developed drivers + NULL, // ImageHandle, to be overwritten by + // EfiLibInstallDriverBindingComponentName2() in XenIoPvhDeviceEntryPoint() + 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"XenIo PVH Driver" }, + { NULL, NULL } +}; + +STATIC +EFI_COMPONENT_NAME_PROTOCOL gComponentName; + +EFI_STATUS +EFIAPI +XenIoPvhGetDriverName ( + 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 +XenIoPvhGetDeviceName ( + 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 = { + &XenIoPvhGetDriverName, + &XenIoPvhGetDeviceName, + "eng" // SupportedLanguages, ISO 639-2 language codes +}; + +STATIC +EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = { + (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) &XenIoPvhGetDriverName, + (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &XenIoPvhGetDeviceName, + "en" // SupportedLanguages, RFC 4646 language codes +}; + +#endif + +// +// Entry point of this driver. +// +EFI_STATUS +EFIAPI +XenIoPvhDeviceEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + /* DEBUG((EFI_D_ERROR, "%a %d\n", __FUNCTION__, __LINE__)); */ + /* return XenIoPvhDeviceBindingStart(ImageHandle); */ + + return EfiLibInstallDriverBindingComponentName2 ( + ImageHandle, + SystemTable, + &gDriverBinding, + ImageHandle, + &gComponentName, + &gComponentName2 + ); +} diff --git a/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf b/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf new file mode 100644 index 0000000..dbdfd6e --- /dev/null +++ b/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf @@ -0,0 +1,45 @@ +## @file +# XXX +# +# Copyright (C) XXX +# +# 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 = XenIoPvhDxe + FILE_GUID = 7a567cc4-0e75-4d7a-a305-c3db109b53ad + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = XenIoPvhDeviceEntryPoint + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[Sources] + XenIoPvhDxe.c + +[LibraryClasses] + UefiDriverEntryPoint + UefiBootServicesTableLib + MemoryAllocationLib + BaseMemoryLib + BaseLib + UefiLib + DebugLib + XenIoMmioLib + +[Protocols] + gEfiDriverBindingProtocolGuid + gEfiComponentName2ProtocolGuid + gEfiComponentNameProtocolGuid + gXenIoProtocolGuid diff --git a/OvmfPkg/XenOvmf.dsc b/OvmfPkg/XenOvmf.dsc index 8bce996..a7a884e 100644 --- a/OvmfPkg/XenOvmf.dsc +++ b/OvmfPkg/XenOvmf.dsc @@ -168,6 +168,7 @@ SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf + XenIoMmioLib|OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf [LibraryClasses.common] !if $(SECURE_BOOT_ENABLE) == TRUE @@ -587,6 +588,7 @@ !endif } OvmfPkg/BlockMmioToBlockIoDxe/BlockIo.inf + OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf OvmfPkg/XenBusDxe/XenBusDxe.inf OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf diff --git a/OvmfPkg/XenOvmf.fdf b/OvmfPkg/XenOvmf.fdf index a40d186..a500ab6 100644 --- a/OvmfPkg/XenOvmf.fdf +++ b/OvmfPkg/XenOvmf.fdf @@ -220,6 +220,7 @@ INF MdeModulePkg/Universal/Metronome/Metronome.inf INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf INF OvmfPkg/BlockMmioToBlockIoDxe/BlockIo.inf +INF OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf INF OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf INF OvmfPkg/XenBusDxe/XenBusDxe.inf INF OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf