From: Heyi Guo <guoheyi@huawei.com>
To: <edk2-devel@lists.01.org>
Cc: <wanghaibin.wang@huawei.com>, Laszlo Ersek <lersek@redhat.com>,
"Ard Biesheuvel" <ard.biesheuvel@linaro.org>,
Julien Grall <julien.grall@arm.com>,
Heyi Guo <heyi.guo@linaro.org>
Subject: [RFC 2/3] ArmVirtPkg: add runtime instance of FdtPL011SerialPortLib
Date: Thu, 28 Feb 2019 16:05:11 +0800 [thread overview]
Message-ID: <1551341112-21645-3-git-send-email-guoheyi@huawei.com> (raw)
In-Reply-To: <1551341112-21645-1-git-send-email-guoheyi@huawei.com>
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 <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Julien Grall <julien.grall@arm.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Heyi Guo <guoheyi@huawei.com>
Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
---
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.<BR>
Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
- Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
+ Copyright (c) 2014 - 2019, Linaro Ltd. All rights reserved.<BR>
Copyright (c) 2014, Red Hat, Inc.<BR>
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2019, Huawei Technologies Co., Ltd. All rights reserved.<BR>
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 <Pi/PiHob.h>
#include <Library/HobLib.h>
#include <Guid/EarlyPL011BaseAddress.h>
+#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.<BR>
+ Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2014 - 2019, Linaro Ltd. All rights reserved.<BR>
+ Copyright (c) 2014, Red Hat, Inc.<BR>
+ Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2019, Huawei Technologies Co., Ltd. All rights reserved.<BR>
+
+ 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.<BR>
+# Copyright (c) 2019, Linaro Ltd. All rights reserved.<BR>
+# Copyright (c) 2019, Huawei Technologies Co., Ltd. All rights reserved.<BR>
#
# 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.<BR>
+ Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2014 - 2019, Linaro Ltd. All rights reserved.<BR>
+ Copyright (c) 2014, Red Hat, Inc.<BR>
+ Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2019, Huawei Technologies Co., Ltd. All rights reserved.<BR>
+
+ 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 <Base.h>
+#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.<BR>
+ Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2014 - 2019, Linaro Ltd. All rights reserved.<BR>
+ Copyright (c) 2014, Red Hat, Inc.<BR>
+ Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2019, Huawei Technologies Co., Ltd. All rights reserved.<BR>
+
+ 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 <Uefi.h>
+#include <Guid/EventGroup.h>
+#include <Library/DxeServicesTableLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
+#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.<BR>
+# Copyright (c) 2019, Linaro Ltd. All rights reserved.<BR>
+# Copyright (c) 2019, Huawei Technologies Co., Ltd. All rights reserved.<BR>
+#
+# 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
next prev parent reply other threads:[~2019-02-28 8:06 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-28 8:05 [RFC 0/3] Enable runtime serial debug for ArmVirtQemu Heyi Guo
2019-02-28 8:05 ` [RFC 1/3] MdeModulePkg/StatusCode: Add PCD to enable runtime serial debug Heyi Guo
2019-02-28 8:05 ` Heyi Guo [this message]
2019-02-28 8:05 ` [RFC 3/3] ArmVirtQemu: enable runtime debug by build flag Heyi Guo
2019-02-28 12:10 ` [RFC 0/3] Enable runtime serial debug for ArmVirtQemu Ard Biesheuvel
2019-03-01 15:27 ` Laszlo Ersek
2019-03-04 13:52 ` Heyi Guo
2019-03-12 6:56 ` Heyi Guo
2019-03-12 17:05 ` Laszlo Ersek
2019-03-12 17:28 ` Andrew Fish
2019-03-12 19:42 ` Laszlo Ersek
2019-03-13 20:16 ` Brian J. Johnson
2019-03-14 3:52 ` Andrew Fish
2019-03-16 9:41 ` Heyi Guo
2019-03-20 9:55 ` Laszlo Ersek
2019-03-20 12:16 ` Heyi Guo
2019-03-20 17:47 ` Laszlo Ersek
2019-03-21 3:23 ` Heyi Guo
2019-02-28 13:39 ` Laszlo Ersek
2019-03-01 12:24 ` Heyi Guo
2019-03-01 14:59 ` Laszlo Ersek
2019-03-01 15:14 ` Ard Biesheuvel
[not found] ` <CAFEAcA8AQjMJytpbXbBPH_YyuVW-PawhSgGeXaZGhVzRUPh9+A@mail.gmail.com>
2019-03-01 16:14 ` Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1551341112-21645-3-git-send-email-guoheyi@huawei.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox