From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x22f.google.com (mail-wm0-x22f.google.com [IPv6:2a00:1450:400c:c09::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 898B681D3D for ; Thu, 3 Nov 2016 04:41:50 -0700 (PDT) Received: by mail-wm0-x22f.google.com with SMTP id a197so199235401wmd.0 for ; Thu, 03 Nov 2016 04:41:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=N0ATEisBjEhOv1OL/2/tzuNRuP7jtOiz7WZE0J9WS0Q=; b=kKDocdWYfHMyIezmYAkc7DzoKi5VxXXIl9nSNbopiCkpW1Xh8RcN7zOzVXVB02JVrs /QjvYs9BX3q3i5KO0SJbeemI7S5lkPqyOTsJyknbvcdlqUlhxeeqStX4sBJ6HLpCbHRH /tTjKJL+AY6KcB/cPLVommynje+FY8BkWdzSc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=N0ATEisBjEhOv1OL/2/tzuNRuP7jtOiz7WZE0J9WS0Q=; b=KMFRqix6sSXz6hlIQUceOEKwWhOJHSeq1uPb/A3AyDO9oM2Y2lT3Fj25g1t4/rnScs Pt6b3kxN8Szr8Ui6e1mZWERqP8FDvq1KCTJnvHvgGsy1rf6zvk+ZMXfOVmaWjvVFV29C f7YL0vlCUvOD/TNrWo3m53pi+xLhde92Is/skA+FbeViX0pJbI50/888BBAqBGjxrJv+ w8Ba05hakbKL3Bouk531s5KfzsqmYZRBBO5nX4fiyeRK+xNeLxF1YSjBJLb9qpKoTu3u P/xoyzXDtTa0Cjj5SFVYikVKYExyDQKtbnb34kXhkMZlXY9tY1XRqMC8ce/CNdEF8fqR +MMQ== X-Gm-Message-State: ABUngvdauZr4dYsnnGsl58qEqM4JX/rpA8GLQf5TZeetuCZARwgF//h5eDzxBE6yCUGdHyZi X-Received: by 10.28.48.203 with SMTP id w194mr8450729wmw.115.1478173310893; Thu, 03 Nov 2016 04:41:50 -0700 (PDT) Received: from localhost.localdomain ([105.151.153.127]) by smtp.gmail.com with ESMTPSA id za1sm8108371wjb.8.2016.11.03.04.41.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Nov 2016 04:41:50 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, michael.d.kinney@intel.com, afish@apple.com Cc: mw@semihalf.com, feng.tian@intel.com, star.zeng@intel.com, Ard Biesheuvel Date: Thu, 3 Nov 2016 11:41:39 +0000 Message-Id: <1478173302-22349-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478173302-22349-1-git-send-email-ard.biesheuvel@linaro.org> References: <1478173302-22349-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [PATCH v2 2/5] MdeModule: introduce helper library to register non-discoverable devices X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Nov 2016 11:41:51 -0000 Non-discoverable devices need to be registered explicitly by the platform. Introduce a helper library that takes care of this. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Include/Library/NonDiscoverableDeviceRegistrationLib.h | 47 ++++++++ MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.c | 119 ++++++++++++++++++++ MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.inf | 34 ++++++ MdeModulePkg/MdeModulePkg.dec | 4 + MdeModulePkg/MdeModulePkg.dsc | 2 + 5 files changed, 206 insertions(+) diff --git a/MdeModulePkg/Include/Library/NonDiscoverableDeviceRegistrationLib.h b/MdeModulePkg/Include/Library/NonDiscoverableDeviceRegistrationLib.h new file mode 100644 index 000000000000..5803f1c71b69 --- /dev/null +++ b/MdeModulePkg/Include/Library/NonDiscoverableDeviceRegistrationLib.h @@ -0,0 +1,47 @@ +/** @file + Copyright (c) 2016, Linaro, Ltd. All rights reserved.
+ + 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 __NON_DISCOVERABLE_DEVICE_REGISTRATION_LIB_H__ +#define __NON_DISCOVERABLE_DEVICE_REGISTRATION_LIB_H__ + +#include + +/** + Register a non-discoverable device + + @param[in] BaseAddress The MMIO base address of the non-discoverable + device + @param[in] DeviceType The type of non-discoverable device + @param[in] DmaType Whether the device is DMA coherent + @param[in] InitFunc Initialization routine to be invoked when the + device is enabled + @param[in,out] Handle The handle onto which to install the + non-discoverable device protocol. + If Handle is NULL or *Handle is NULL, a new + handle will be allocated. + + @retval EFI_SUCCESS The registration succeeded. + @retval Other The registration failed. + +**/ +EFI_STATUS +EFIAPI +RegisterNonDiscoverableDevice ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN NON_DISCOVERABLE_DEVICE_TYPE DeviceType, + IN NON_DISCOVERABLE_DEVICE_DMA_TYPE DmaType, + IN NON_DISCOVERABLE_DEVICE_INIT InitFunc, + IN OUT EFI_HANDLE *Handle OPTIONAL + ); + +#endif diff --git a/MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.c b/MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.c new file mode 100644 index 000000000000..c42226a0629a --- /dev/null +++ b/MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.c @@ -0,0 +1,119 @@ +/** @file + Copyright (c) 2016, Linaro, Ltd. All rights reserved.
+ + 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 + +#include +#include + +#pragma pack (1) +typedef struct { + VENDOR_DEVICE_PATH Vendor; + UINT64 BaseAddress; + EFI_DEVICE_PATH_PROTOCOL End; +} NON_DISCOVERABLE_DEVICE_PATH; + +#pragma pack () + +/** + Register a non-discoverable device + + @param[in] BaseAddress The MMIO base address of the platform device + @param[in] DeviceType The type of platform device + @param[in] DmaType Whether the device is DMA coherent + @param[in] InitFunc Initialization routine to be invoked when the + device is enabled + @param[in,out] Handle The handle onto which to install the platform + PCI I/O protocol has been installed. + If Handle is NULL or *Handle is NULL, a new + handle will be allocated. + + @retval EFI_SUCCESS The registration succeeded. + @retval other The registration failed. + +**/ +EFI_STATUS +EFIAPI +RegisterNonDiscoverableDevice ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN NON_DISCOVERABLE_DEVICE_TYPE Type, + IN NON_DISCOVERABLE_DEVICE_DMA_TYPE DmaType, + IN NON_DISCOVERABLE_DEVICE_INIT InitFunc, + IN OUT EFI_HANDLE *Handle + ) +{ + NON_DISCOVERABLE_DEVICE *Device; + NON_DISCOVERABLE_DEVICE_PATH *DevicePath; + EFI_HANDLE LocalHandle; + EFI_STATUS Status; + + if (Type >= NonDiscoverableDeviceTypeMax || + DmaType >= NonDiscoverableDeviceDmaTypeMax) { + return EFI_INVALID_PARAMETER; + } + + if (Handle == NULL) { + Handle = &LocalHandle; + LocalHandle = NULL; + } + + Device = (NON_DISCOVERABLE_DEVICE *)AllocateZeroPool (sizeof *Device); + if (Device == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Device->BaseAddress = BaseAddress; + Device->Type = Type; + Device->DmaType = DmaType; + Device->Initialize = InitFunc; + + DevicePath = (NON_DISCOVERABLE_DEVICE_PATH *)CreateDeviceNode ( + HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, + sizeof (*DevicePath)); + if (DevicePath == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto FreeDevice; + } + + CopyGuid (&DevicePath->Vendor.Guid, &gNonDiscoverableDeviceProtocolGuid); + DevicePath->BaseAddress = BaseAddress; + + SetDevicePathNodeLength (&DevicePath->Vendor, + sizeof (*DevicePath) - sizeof (DevicePath->End)); + SetDevicePathEndNode (&DevicePath->End); + + Status = gBS->InstallMultipleProtocolInterfaces (Handle, + &gNonDiscoverableDeviceProtocolGuid, Device, + &gEfiDevicePathProtocolGuid, DevicePath, + NULL); + if (EFI_ERROR (Status)) { + goto FreeDevicePath; + } + return EFI_SUCCESS; + +FreeDevicePath: + FreePool (DevicePath); + +FreeDevice: + FreePool (Device); + + return Status; +} diff --git a/MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.inf b/MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.inf new file mode 100644 index 000000000000..cf7792e2847c --- /dev/null +++ b/MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.inf @@ -0,0 +1,34 @@ +# @file +# Copyright (c) 2016, Linaro, Ltd. All rights reserved.
+# +# 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 = 0x00010019 + BASE_NAME = NonDiscoverableDeviceRegistrationLib + FILE_GUID = 8802ae41-8184-49cb-8aec-62627cd7ceb4 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = NonDiscoverableDeviceRegistrationLib + +[Sources] + NonDiscoverableDeviceRegistrationLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + DebugLib + DevicePathLib + UefiBootServicesTableLib + +[Protocols] + gNonDiscoverableDeviceProtocolGuid diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 84b489d3fdb7..86685bb8b367 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -157,6 +157,10 @@ [LibraryClasses] ## FrameBufferBltLib|Include/Library/FrameBufferBltLib.h + ## @libraryclass Provides a service to register non-discoverable device + ## + NonDiscoverableDeviceRegistrationLib|Include/Library/NonDiscoverableDeviceRegistrationLib.h + [Guids] ## MdeModule package token space guid # Include/Guid/MdeModulePkgTokenSpace.h diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 757d52dbede4..43421d610ede 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -102,6 +102,7 @@ [LibraryClasses] AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf + NonDiscoverableDeviceRegistrationLib|MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.inf [LibraryClasses.EBC.PEIM] IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf @@ -317,6 +318,7 @@ [Components] MdeModulePkg/Library/PeiIpmiLibIpmiPpi/PeiIpmiLibIpmiPpi.inf MdeModulePkg/Library/SmmIpmiLibSmmIpmiProtocol/SmmIpmiLibSmmIpmiProtocol.inf MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf + MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.inf MdeModulePkg/Universal/BdsDxe/BdsDxe.inf MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf -- 2.7.4