From patchwork Mon Oct 31 18:13:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 80251 Delivered-To: patch@linaro.org Received: by 10.80.142.83 with SMTP id 19csp270714edx; Mon, 31 Oct 2016 11:13:23 -0700 (PDT) X-Received: by 10.98.71.215 with SMTP id p84mr51529839pfi.59.1477937602882; Mon, 31 Oct 2016 11:13:22 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id xt1si19924648pac.122.2016.10.31.11.13.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Oct 2016 11:13:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id F010B81D14; Mon, 31 Oct 2016 11:13:20 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x230.google.com (mail-wm0-x230.google.com [IPv6:2a00:1450:400c:c09::230]) (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 E5C7C81D1A for ; Mon, 31 Oct 2016 11:13:18 -0700 (PDT) Received: by mail-wm0-x230.google.com with SMTP id a197so35897958wmd.0 for ; Mon, 31 Oct 2016 11:13:20 -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=tzY17Drr8qKpXmZUMjOWsxO28fAIRLphZNDmSKKyg8I=; b=DtuSnkt2mYuBW92PGZCfjRELKgEEETOzjGdea1FU1Orrc4c4NYL+iDevs14j7qQWcp GExy4L4eipWJB01yrwaoK1yTVMj4vxx0sDX4SqeocONXThjvPbtXTuwFyAF+TSXp040E LGUmvkoma7e/lahfYtgdcnuIeAAtZpfu9WwYk= 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=tzY17Drr8qKpXmZUMjOWsxO28fAIRLphZNDmSKKyg8I=; b=YapT/N4cJQzt+ufkTwLtXEe6dHWw/0Ex/ZRiLnq0dziuTAQlFWP7TOZojiMX9VwYrz Hgz188wNECos7wvjR01SRfxw28flvD/6EhKoAr01LfP/Baa06iP5w1LWzsiLt8/MC+KI zNSpu68VeUzv7yXHHAomEoaOfYlnH8PoP0T51+JdhFi89bIEf7ocN7ZVzoyBIzknAVLE AaBtp4QAmyqRoSOo6hDXvdRI7jfcNRBYueC0D2vBPRf4Bduc0z6MueB5Pgmo+kQfLa1M +D1FmlxiOdmHjoSGZxfGXw1LznoQayuhEF78V5Zm4Soo0kIJcSPLZ8hcw76v13uQt0fp TV0g== X-Gm-Message-State: ABUngve50Fl5pIbUnrFfd+TBB9GvXUuRlw9R2oGmIPhl/xwcd3Rn/o+SZoajx3jC52jZ3XeK X-Received: by 10.28.173.4 with SMTP id w4mr1314358wme.70.1477937598573; Mon, 31 Oct 2016 11:13:18 -0700 (PDT) Received: from localhost.localdomain ([105.151.153.127]) by smtp.gmail.com with ESMTPSA id 132sm26054809wmn.16.2016.10.31.11.13.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 31 Oct 2016 11:13:17 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Date: Mon, 31 Oct 2016 18:13:07 +0000 Message-Id: <1477937590-10361-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477937590-10361-1-git-send-email-ard.biesheuvel@linaro.org> References: <1477937590-10361-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 2/5] EmbeddedPkg: introduce platform PCI I/O registration library 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: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" This introduces the PlatformPciIoDeviceRegistrationLib library class and a default implementation to help platforms expose platform devices that may be driven by a PCI driver. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- EmbeddedPkg/EmbeddedPkg.dec | 1 + EmbeddedPkg/EmbeddedPkg.dsc | 2 + EmbeddedPkg/Include/Library/PlatformPciIoDeviceRegistrationLib.h | 46 ++++++++ EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.c | 115 ++++++++++++++++++++ EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.inf | 34 ++++++ 5 files changed, 198 insertions(+) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec index 84a6f4d01077..226036858880 100644 --- a/EmbeddedPkg/EmbeddedPkg.dec +++ b/EmbeddedPkg/EmbeddedPkg.dec @@ -44,6 +44,7 @@ [LibraryClasses.common] EblNetworkLib|Include/Library/EblNetworkLib.h GdbSerialLib|Include/Library/GdbSerialLib.h DebugAgentTimerLib|Include/Library/DebugAgentTimerLib.h + PlatformPciIoDeviceRegistrationLib|Include/Library/PlatformPciIoDeviceRegistrationLib.h [Guids.common] diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc index eb7af800f0b2..d47c836379c9 100644 --- a/EmbeddedPkg/EmbeddedPkg.dsc +++ b/EmbeddedPkg/EmbeddedPkg.dsc @@ -290,5 +290,7 @@ [Components.common] EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf + EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.inf + [Components.IA32, Components.X64, Components.IPF, Components.ARM] EmbeddedPkg/GdbStub/GdbStub.inf diff --git a/EmbeddedPkg/Include/Library/PlatformPciIoDeviceRegistrationLib.h b/EmbeddedPkg/Include/Library/PlatformPciIoDeviceRegistrationLib.h new file mode 100644 index 000000000000..07f163abc701 --- /dev/null +++ b/EmbeddedPkg/Include/Library/PlatformPciIoDeviceRegistrationLib.h @@ -0,0 +1,46 @@ +/** @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 __PLATFORM_PCI_IO_DEVICE_REGISTRATION_LIB_H__ +#define __PLATFORM_PCI_IO_DEVICE_REGISTRATION_LIB_H__ + +#include + +/** + Register a platform device for PCI I/O protocol emulation + + @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 +PlatformPciIoRegisterDevice ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN PLATFORM_PCI_IO_DEVICE_TYPE DeviceType, + IN PLATFORM_PCI_IO_DMA_TYPE DmaType, + IN PLATFORM_PCI_IO_INIT InitFunc, + IN OUT EFI_HANDLE *Handle OPTIONAL + ); + +#endif diff --git a/EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.c b/EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.c new file mode 100644 index 000000000000..1ce5abb137df --- /dev/null +++ b/EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.c @@ -0,0 +1,115 @@ +/** @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 + +#pragma pack (1) +typedef struct { + VENDOR_DEVICE_PATH Vendor; + UINT64 BaseAddress; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_PCI_IO_DEVICE_PATH; + +#pragma pack () + +/** + Register a platform device for PCI I/O protocol emulation + + @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 +PlatformPciIoRegisterDevice ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN PLATFORM_PCI_IO_DEVICE_TYPE DeviceType, + IN PLATFORM_PCI_IO_DMA_TYPE DmaType, + IN PLATFORM_PCI_IO_INIT InitFunc, + IN OUT EFI_HANDLE *Handle + ) +{ + PLATFORM_PCI_IO *Device; + PLATFORM_PCI_IO_DEVICE_PATH *DevicePath; + EFI_HANDLE LocalHandle; + EFI_STATUS Status; + + if (DeviceType >= PlatformPciIoDeviceMax || DmaType >= PlatformPciIoDmaMax) { + return EFI_INVALID_PARAMETER; + } + + if (Handle == NULL) { + Handle = &LocalHandle; + LocalHandle = NULL; + } + + Device = (PLATFORM_PCI_IO *)AllocateZeroPool (sizeof *Device); + if (Device == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Device->BaseAddress = BaseAddress; + Device->DeviceType = DeviceType; + Device->DmaType = DmaType; + Device->Initialize = InitFunc; + + DevicePath = (PLATFORM_PCI_IO_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, &gPlatformPciIoProtocolGuid); + DevicePath->BaseAddress = BaseAddress; + + SetDevicePathNodeLength (&DevicePath->Vendor, + sizeof (*DevicePath) - sizeof (DevicePath->End)); + SetDevicePathEndNode (&DevicePath->End); + + Status = gBS->InstallMultipleProtocolInterfaces (Handle, + &gPlatformPciIoProtocolGuid, Device, + &gEfiDevicePathProtocolGuid, DevicePath); + if (EFI_ERROR (Status)) { + goto FreeDevicePath; + } + return EFI_SUCCESS; + +FreeDevicePath: + FreePool (DevicePath); + +FreeDevice: + FreePool (Device); + + return Status; +} diff --git a/EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.inf b/EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.inf new file mode 100644 index 000000000000..282db3ab59ab --- /dev/null +++ b/EmbeddedPkg/Library/PlatformPciIoDeviceRegistrationLib/PlatformPciIoDeviceRegistrationLib.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 = 0x00010017 + BASE_NAME = PlatformPciIoDeviceRegistrationLib + FILE_GUID = 8802ae41-8184-49cb-8aec-62627cd7ceb4 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = PlatformPciIoDeviceRegistrationLib + +[Sources] + PlatformPciIoDeviceRegistrationLib.c + +[Packages] + MdePkg/MdePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + +[LibraryClasses] + DebugLib + DevicePathLib + UefiBootServicesTableLib + +[Protocols] + gPlatformPciIoProtocolGuid