From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=45.249.212.191; helo=huawei.com; envelope-from=guoheyi@huawei.com; receiver=edk2-devel@lists.01.org Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A7BF3211CFBD7 for ; Thu, 28 Feb 2019 00:06:43 -0800 (PST) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D6365D0EB8560FD08F03; Thu, 28 Feb 2019 16:06:37 +0800 (CST) Received: from linux-fhAnjn.huawei.com (10.175.104.222) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.408.0; Thu, 28 Feb 2019 16:06:30 +0800 From: Heyi Guo To: CC: , Laszlo Ersek , "Ard Biesheuvel" , Julien Grall , Heyi Guo Date: Thu, 28 Feb 2019 16:05:11 +0800 Message-ID: <1551341112-21645-3-git-send-email-guoheyi@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551341112-21645-1-git-send-email-guoheyi@huawei.com> References: <1551341112-21645-1-git-send-email-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.222] X-CFilter-Loop: Reflected Subject: [RFC 2/3] ArmVirtPkg: add runtime instance of FdtPL011SerialPortLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Feb 2019 08:06:44 -0000 Content-Type: text/plain We add a runtime instance inf into the same directory for code reuse. The different pieces of code are put into *Common.c and *Runtime.c. Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Julien Grall Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Heyi Guo Signed-off-by: Heyi Guo --- ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c | 29 ++++-- ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.h | 27 +++++ ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf | 3 + ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibCommon.c | 27 +++++ ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibRuntime.c | 104 ++++++++++++++++++++ ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibRuntime.inf | 58 +++++++++++ 6 files changed, 238 insertions(+), 10 deletions(-) diff --git a/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c index 2f10fb7..51e1909 100644 --- a/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c +++ b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c @@ -3,9 +3,10 @@ Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.
- Copyright (c) 2014, Linaro Ltd. All rights reserved.
+ Copyright (c) 2014 - 2019, Linaro Ltd. All rights reserved.
Copyright (c) 2014, Red Hat, Inc.
Copyright (c) 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2019, Huawei Technologies Co., Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -28,17 +29,10 @@ #include #include #include +#include "FdtPL011SerialPortLib.h" -STATIC UINTN mSerialBaseAddress; -RETURN_STATUS -EFIAPI -SerialPortInitialize ( - VOID - ) -{ - return RETURN_SUCCESS; -} +UINTN mSerialBaseAddress; /** @@ -90,6 +84,21 @@ FdtPL011SerialPortLibInitialize ( ); } +RETURN_STATUS +EFIAPI +SerialPortInitialize ( + VOID + ) +{ + if (mSerialBaseAddress == 0) { + FdtPL011SerialPortLibInitialize (); + } + + (VOID) SerialPortRuntimePrepare (); + + return RETURN_SUCCESS; +} + /** Write data to serial device. diff --git a/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.h b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.h new file mode 100644 index 0000000..25989ef --- /dev/null +++ b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.h @@ -0,0 +1,27 @@ +/** @file + + Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+ Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.
+ Copyright (c) 2014 - 2019, Linaro Ltd. All rights reserved.
+ Copyright (c) 2014, Red Hat, Inc.
+ Copyright (c) 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2019, Huawei Technologies Co., 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 _FDT_PL011_SERIAL_PORT_LIB_H_ +#define _FDT_PL011_SERIAL_PORT_LIB_H_ + +extern UINTN mSerialBaseAddress; + +RETURN_STATUS SerialPortRuntimePrepare (VOID); + +#endif diff --git a/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf index 0b06797..050c965 100644 --- a/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf +++ b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf @@ -3,6 +3,8 @@ # Component description file for PL011SerialPortLib module # # Copyright (c) 2011-2015, ARM Ltd. All rights reserved.
+# Copyright (c) 2019, Linaro Ltd. All rights reserved.
+# Copyright (c) 2019, Huawei Technologies Co., Ltd. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -25,6 +27,7 @@ [Sources.common] FdtPL011SerialPortLib.c + FdtPL011SerialPortLibCommon.c [LibraryClasses] PL011UartLib diff --git a/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibCommon.c b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibCommon.c new file mode 100644 index 0000000..68fa6a2 --- /dev/null +++ b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibCommon.c @@ -0,0 +1,27 @@ +/** @file + Serial I/O Port library functions with base address discovered from FDT + + Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+ Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.
+ Copyright (c) 2014 - 2019, Linaro Ltd. All rights reserved.
+ Copyright (c) 2014, Red Hat, Inc.
+ Copyright (c) 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2019, Huawei Technologies Co., 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 "FdtPL011SerialPortLib.h" + +RETURN_STATUS SerialPortRuntimePrepare (VOID) +{ + return RETURN_SUCCESS; +} diff --git a/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibRuntime.c b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibRuntime.c new file mode 100644 index 0000000..6ea1d02 --- /dev/null +++ b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibRuntime.c @@ -0,0 +1,104 @@ +/** @file + Serial I/O Port library functions with base address discovered from FDT + + Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+ Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.
+ Copyright (c) 2014 - 2019, Linaro Ltd. All rights reserved.
+ Copyright (c) 2014, Red Hat, Inc.
+ Copyright (c) 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2019, Huawei Technologies Co., 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 "FdtPL011SerialPortLib.h" + +STATIC EFI_EVENT mSerialVirtualAddressChangeEvent = NULL; + +RETURN_STATUS +EFIAPI +SerialPortLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + + if (!mSerialVirtualAddressChangeEvent) { + return RETURN_SUCCESS; + } + + return gBS->CloseEvent (mSerialVirtualAddressChangeEvent); +} + +VOID +EFIAPI +SerialVirtualAddressChangeCallBack ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EfiConvertPointer (0, (VOID **) &mSerialBaseAddress); +} + + +RETURN_STATUS SerialPortRuntimePrepare (VOID) +{ + RETURN_STATUS Status; + UINT64 Length = SIZE_4KB; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc = {0}; + + // For the serial port register space length is only 4KB, we don't need to + // check if the descriptor is large enough to cover the space. + Status = gDS->GetMemorySpaceDescriptor(mSerialBaseAddress, &Desc); + if (EFI_ERROR (Status) || + Desc.GcdMemoryType == EfiGcdMemoryTypeNonExistent) { + Status = gDS->AddMemorySpace ( + EfiGcdMemoryTypeMemoryMappedIo, + mSerialBaseAddress, + Length, + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + if (EFI_ERROR (Status)) { + return Status; + } + Desc.Attributes = EFI_MEMORY_UC; + } + + if ((Desc.Attributes & EFI_MEMORY_RUNTIME) == 0) { + Desc.Attributes |= EFI_MEMORY_RUNTIME; + Status = gDS->SetMemorySpaceAttributes ( + mSerialBaseAddress, + Length, + Desc.Attributes + ); + if(EFI_ERROR (Status)){ + return Status; + } + } + + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + SerialVirtualAddressChangeCallBack, + NULL, + &gEfiEventVirtualAddressChangeGuid, + &mSerialVirtualAddressChangeEvent + ); + if (EFI_ERROR (Status)) { + mSerialVirtualAddressChangeEvent = NULL; + } + + return Status; +} diff --git a/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibRuntime.inf b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibRuntime.inf new file mode 100644 index 0000000..a3f87bd --- /dev/null +++ b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLibRuntime.inf @@ -0,0 +1,58 @@ +#/** @file +# +# Component description file for PL011SerialPortLib module +# +# Copyright (c) 2011-2015, ARM Ltd. All rights reserved.
+# Copyright (c) 2019, Linaro Ltd. All rights reserved.
+# Copyright (c) 2019, Huawei Technologies Co., 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 = 0x00010005 + BASE_NAME = FdtPL011SerialPortLibRuntime + FILE_GUID = 83afbb90-38c6-11e9-aeab-203db202c950 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = SerialPortLib|DXE_RUNTIME_DRIVER + DESTRUCTOR = SerialPortLibDestructor + +[Sources.common] + FdtPL011SerialPortLib.c + FdtPL011SerialPortLibRuntime.c + +[LibraryClasses] + DxeServicesTableLib + HobLib + PL011UartLib + UefiBootServicesTableLib + UefiRuntimeLib + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + ArmVirtPkg/ArmVirtPkg.dec + ArmPkg/ArmPkg.dec + +[FixedPcd] + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits + gArmPlatformTokenSpaceGuid.PL011UartClkInHz + +[Guids] + gEarlyPL011BaseAddressGuid + +[Depex] + gEfiCpuArchProtocolGuid -- 1.8.3.1