From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (EUR04-DB3-obe.outbound.protection.outlook.com [40.107.6.76]) by mx.groups.io with SMTP id smtpd.web12.13756.1593005733885657709 for ; Wed, 24 Jun 2020 06:35:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=PRRUkjlN; spf=pass (domain: arm.com, ip: 40.107.6.76, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fyjnId8irKDW9xTvSx21K2Is5kMgM8siEpOB6fTjFjI=; b=PRRUkjlNSmDzgZKD/ODNNjCHX5HyMWL348inVrO+1yWCx8m78WfhcE3khgeVzktPHpjLqxoo2tiHawMBjSvmtNA1F/0iZOfnzoYPWfuVjyLe21RlDlwS18RJW94kHprYZS8aC2QQM3XVgrtnJdAMasUNx9XO2dKmkCjJXJ/aM1I= Received: from AM6P193CA0144.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::49) by HE1PR0801MB2106.eurprd08.prod.outlook.com (2603:10a6:3:4a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.23; Wed, 24 Jun 2020 13:35:30 +0000 Received: from VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::91) by AM6P193CA0144.outlook.office365.com (2603:10a6:209:85::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.20 via Frontend Transport; Wed, 24 Jun 2020 13:35:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT009.mail.protection.outlook.com (10.152.18.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.20 via Frontend Transport; Wed, 24 Jun 2020 13:35:29 +0000 Received: ("Tessian outbound 217a52b9caed:v59"); Wed, 24 Jun 2020 13:35:29 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 20d03b8cff61b8c6 X-CR-MTA-TID: 64aa7808 Received: from 197a30fbe330.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id E196DA36-BC77-4117-A5A0-6E1E1381FEBC.1; Wed, 24 Jun 2020 13:35:24 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 197a30fbe330.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 24 Jun 2020 13:35:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HICcxDYAT327UPCOa1MwRDgfVYGth7FXQLienM1SvcF897qXKz70aiP5+PG2SMgzrjcu0G85CScqiiiheomFJntAHmEe22imCurXl9tj8TjPVMKxA3CsRtZvHL9ZD132zCdbVEycPDb6aWCpdrMq2rbEpS0U0OqR1IqgmHNCpfxqsDKivA8Dd7yVLpkyKnq1weuDHOPAcjGPwlmWTGQw5/SqU9OxKQfVS9nnNegPHXFahxZhRBjhA8qqNxcgjhDr2htXpHmGA79P8UJN15g1JIKDts9nRte1EQL+dVpCchAoFthFurk9zBZFPiSO/aeIPiTnqxaXq+ftMROHwVRaXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fyjnId8irKDW9xTvSx21K2Is5kMgM8siEpOB6fTjFjI=; b=TEY4uEI6MxwSjdVhqiUYS+31bh95XvdIjm7Adp04Gud3FQxGmRYCGYWEbSIuEFskof7c8HgqngNHF0ipqB3uwPnvAz91t8pp1XugnIgepUVH+KP3Q5Ne7mW/+akR4jiLPIZyboDIUJG7JzpGDwfOY+9t6NatasQ5rAdcoPaDKhDZWMYyQB22c7ToZazVveTRLWEN7H84wGgE68GYTZ4w2piemLYErPLjQpgTSHat0YQJaZKcEHfuUYwAJLsjEebUfyATVeYEpB3yzwM4T5u2buX92YwicjjF+HwEir5m3N6AmwWewkRZnbwuOp79WSPNbd/rOXhZiOWeQBMCCBj2gg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fyjnId8irKDW9xTvSx21K2Is5kMgM8siEpOB6fTjFjI=; b=PRRUkjlNSmDzgZKD/ODNNjCHX5HyMWL348inVrO+1yWCx8m78WfhcE3khgeVzktPHpjLqxoo2tiHawMBjSvmtNA1F/0iZOfnzoYPWfuVjyLe21RlDlwS18RJW94kHprYZS8aC2QQM3XVgrtnJdAMasUNx9XO2dKmkCjJXJ/aM1I= Received: from AM6P194CA0044.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:84::21) by DB6PR0801MB1989.eurprd08.prod.outlook.com (2603:10a6:4:75::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.23; Wed, 24 Jun 2020 13:35:21 +0000 Received: from AM5EUR03FT060.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:84:cafe::51) by AM6P194CA0044.outlook.office365.com (2603:10a6:209:84::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.20 via Frontend Transport; Wed, 24 Jun 2020 13:35:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT060.mail.protection.outlook.com (10.152.16.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3131.20 via Frontend Transport; Wed, 24 Jun 2020 13:35:21 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Wed, 24 Jun 2020 13:35:11 +0000 Received: from E107187.Arm.com (10.57.22.181) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Wed, 24 Jun 2020 13:35:10 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , Subject: [PATCH v3 10/15] ArmVirtPkg: 16550 UART Platform hook library Date: Wed, 24 Jun 2020 14:34:53 +0100 Message-ID: <20200624133458.61920-11-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20200624133458.61920-1-sami.mujawar@arm.com> References: <20200624133458.61920-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFTY:;SFS:(4636009)(136003)(376002)(346002)(396003)(39860400002)(46966005)(356005)(82310400002)(2616005)(81166007)(30864003)(8676002)(86362001)(6916009)(8936002)(1076003)(5660300002)(82740400003)(47076004)(336012)(70586007)(426003)(70206006)(19627235002)(83380400001)(6666004)(44832011)(4326008)(26005)(186003)(2906002)(316002)(54906003)(7696005)(36756003)(478600001);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 30f94afc-e985-404f-7802-08d81843763a X-MS-TrafficTypeDiagnostic: DB6PR0801MB1989:|HE1PR0801MB2106: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:3383;OLM:3383; X-Forefront-PRVS: 0444EB1997 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 2E2ARFw1g6cZZHHQdKWA8YAc4F3Ml9g8ELQ4jrZDYnfMgINuOp7Z+6xH+4CTDQaToZeY+MxELzSPnf7xAHeAZftKjPxxgQLNrgIadetqWMxhIpvv9GfVMiiJ/Bu0cSjqTK0Amv2MtwQUiH6XsKbBEs9/L/JEBkx6/VTyie/bbvQFHqxxbiN7uJiT8OzuooKwBFfA3xRZV+YvdkK5e7lcqBGpjdgvJRvGd47rL/el97InZcV22d9Cq88fTQPFzxGYKgneqZuSdTLj0aGrbEYoohYr0yvBCmfpDpfRxrQAT/qFh76WKiqnTugslue9+Tbzlli6Hdm/CpwLF5WvYkQZcwgt9MfLTiX4d8fYcRQGDdPptGn3LKPqqT22pjHME5a1BqzpYqk2LLrqUmYXzQXPlg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1989 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFTY:;SFS:(4636009)(396003)(136003)(39860400002)(376002)(346002)(46966005)(30864003)(26005)(478600001)(19627235002)(6666004)(6916009)(316002)(54906003)(2906002)(5660300002)(8936002)(44832011)(36906005)(186003)(426003)(82740400003)(70206006)(336012)(2616005)(70586007)(1076003)(8676002)(4326008)(7696005)(83380400001)(86362001)(81166007)(82310400002)(36756003)(47076004);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 3a2d3153-6993-48ed-b938-08d818437160 X-Forefront-PRVS: 0444EB1997 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3rhaPSrn2mF8xKCvSslLBt/KjvSCeXthL+eS6xSWEKAQoa2ETpcAi5rBY5QyoP4r3Pwj+Q8z4XIUaWX7cszYkN0Y4dro91s3Cbdpdu0riNJ2NfC+Q74ffHzjh+2akj+vJt5Z0JZ9rORc+ZrYRb0RAJ583FIx9ck/1tZAaK3k4QYKiKJF9fOl3sd+0nDkidApcPCiavmt5Zq31983YhDYVx4dL2WjeJRgBfIzyAJMzk2jYL5zPWPZQA5Rf2SId2GYaXMfsJOfqOr9qcThkAmuJgP2peiDc+CBTw3H+eohEmjgbvdQEKWz1XNmTioaLxq7IFaXGZQYmclhlYkUJSLAX317IohOA8s8JXgyd5zHyn35finA86nEL/3HSUKWHeD5Y5TFsRst31jJda4FCNWgnA== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2020 13:35:29.6804 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 30f94afc-e985-404f-7802-08d81843763a X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB2106 Content-Type: text/plain The BaseSerialPort16550 library invokes the PlatformHookSerialPortInitialize() implemented as part of the PlatformHook library, to perform platform specific initialization required to enable use of the 16550 device. The BaseSerialPort16550 library uses the PcdSerialRegisterBase to obtain the base address of the UART for MMIO operations. Some VMMs like Kvmtool provide the base address of the console serial port in the platform device tree. This patch introduces two instances of the Platform Hook library: 1. EarlyFdt16550SerialPortHookLib - parses the platform device tree to extract the base address of the 16550 UART and update the PCD PcdSerialRegisterBase. 2. Fdt16550SerialPortHookLib - reads the GUID Hob gEarly16550UartBaseAddressGuid (that caches the base address of the 16550 UART discovered during early stages) and updates the PCD PcdSerialRegisterBase. Note: a. The PCD PcdSerialRegisterBase is configured as PatchableInModule. b. A separate patch introduces a PlatformPeiLib that trampolines the 16550 UART base address from the Pcd PcdSerialRegisterBase to the GUID Hob gEarly16550UartBaseAddressGuid. Signed-off-by: Sami Mujawar --- ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c | 138 ++++++++++++++++++++ ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf | 36 +++++ ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.c | 57 ++++++++ ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.inf | 39 ++++++ ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.uni | 14 ++ 5 files changed, 284 insertions(+) diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c new file mode 100644 index 0000000000000000000000000000000000000000..4e97302d01dc5692e046fb901663373828b532ee --- /dev/null +++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.c @@ -0,0 +1,138 @@ +/** @file + Early Platform Hook Library instance for 16550 Uart. + + Copyright (c) 2020, ARM Ltd. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +/** Get the UART base address of the console serial-port from the DT. + + This function fetches the node referenced in the "stdout-path" + property of the "chosen" node and returns the base address of + the console UART. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt). + @param [out] SerialConsoleAddress If success, contains the base address + of the console serial-port. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND Console serial-port info not found in DT. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +GetSerialConsolePortAddress ( + IN CONST VOID *Fdt, + OUT UINT64 *SerialConsoleAddress + ) +{ + CONST CHAR8 *Prop; + INT32 PropSize; + CONST CHAR8 *Path; + INT32 PathLen; + INT32 ChosenNode; + INT32 SerialConsoleNode; + INT32 Len; + CONST CHAR8 *NodeStatus; + CONST UINT64 *RegProperty; + + if ((Fdt == NULL) || (fdt_check_header (Fdt) != 0)) { + return EFI_INVALID_PARAMETER; + } + + // The "chosen" node resides at the the root of the DT. Fetch it. + ChosenNode = fdt_path_offset (Fdt, "/chosen"); + if (ChosenNode < 0) { + return EFI_NOT_FOUND; + } + + Prop = fdt_getprop (Fdt, ChosenNode, "stdout-path", &PropSize); + if (PropSize < 0) { + return EFI_NOT_FOUND; + } + + // Determine the actual path length, as a colon terminates the path. + Path = ScanMem8 (Prop, ':', PropSize); + if (Path == NULL) { + PathLen = AsciiStrLen (Prop); + } else { + PathLen = Path - Prop; + } + + // Aliases cannot start with a '/', so it must be the actual path. + if (Prop[0] == '/') { + SerialConsoleNode = fdt_path_offset_namelen (Fdt, Prop, PathLen); + } else { + // Lookup the alias, as this contains the actual path. + Path = fdt_get_alias_namelen (Fdt, Prop, PathLen); + if (Path == NULL) { + return EFI_NOT_FOUND; + } + SerialConsoleNode = fdt_path_offset (Fdt, Path); + } + + NodeStatus = fdt_getprop (Fdt, SerialConsoleNode, "status", &Len); + if ((NodeStatus != NULL) && (AsciiStrCmp (NodeStatus, "okay") != 0)) { + return EFI_NOT_FOUND; + } + + RegProperty = fdt_getprop (Fdt, SerialConsoleNode, "reg", &Len); + if (Len != 16) { + return EFI_INVALID_PARAMETER; + } + + *SerialConsoleAddress = fdt64_to_cpu (ReadUnaligned64 (RegProperty)); + + return EFI_SUCCESS; +} + +/** Platform hook to retrieve the 16550 UART base address from the platform + Device tree and store it in PcdSerialRegisterBase. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter was invalid. + @retval RETURN_NOT_FOUND Serial port information not found. + +**/ +RETURN_STATUS +EFIAPI +PlatformHookSerialPortInitialize ( + VOID + ) +{ + RETURN_STATUS Status; + VOID *DeviceTreeBase; + UINT64 SerialConsoleAddress; + + if (PcdGet64 (PcdSerialRegisterBase) != 0) { + return RETURN_SUCCESS; + } + + DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress); + if (DeviceTreeBase == NULL) { + return RETURN_NOT_FOUND; + } + + Status = GetSerialConsolePortAddress (DeviceTreeBase, &SerialConsoleAddress); + if (RETURN_ERROR (Status)) { + return Status; + } + + return (EFI_STATUS)PcdSet64S (PcdSerialRegisterBase, SerialConsoleAddress); +} + diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf new file mode 100644 index 0000000000000000000000000000000000000000..007a45eca2a622118044b527a5bc6403b706608a --- /dev/null +++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortHookLib.inf @@ -0,0 +1,36 @@ +## @file +# Early Platform Hook Library instance for 16550 Uart. +# +# Copyright (c) 2020, ARM Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = EarlyFdt16550SerialPortHookLib + MODULE_UNI_FILE = Fdt16550SerialPortHookLib.uni + FILE_GUID = FFB19961-79CC-4684-84A8-C31B0A2BBE82 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = PlatformHookLib|SEC PEI_CORE PEIM + +[Sources] + EarlyFdt16550SerialPortHookLib.c + +[LibraryClasses] + BaseLib + PcdLib + FdtLib + HobLib + +[Packages] + ArmVirtPkg/ArmVirtPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + +[Pcd] + gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.c b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.c new file mode 100644 index 0000000000000000000000000000000000000000..1100c12aef361e39cf78f0c3e4e14cc2feecfcee --- /dev/null +++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.c @@ -0,0 +1,57 @@ +/** @file + Platform Hook Library instance for 16550 Uart. + + Copyright (c) 2020, ARM Ltd. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +/** Platform hook to retrieve the 16550 UART base address from the GUID Hob + that caches the UART base address from early boot stage and store it in + PcdSerialRegisterBase. + + @retval RETURN_SUCCESS Success. + @retval RETURN_NOT_FOUND Serial Port information not found. + +**/ +RETURN_STATUS +EFIAPI +PlatformHookSerialPortInitialize ( + VOID + ) +{ + VOID *Hob; + UINT64 *UartBase; + + if (PcdGet64 (PcdSerialRegisterBase) != 0) { + return RETURN_SUCCESS; + } + + Hob = GetFirstGuidHob (&gEarly16550UartBaseAddressGuid); + if ((Hob == NULL) || (GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (*UartBase))) { + return RETURN_NOT_FOUND; + } + + UartBase = GET_GUID_HOB_DATA (Hob); + if ((UINTN)*UartBase == 0) { + return RETURN_NOT_FOUND; + } + + return (RETURN_STATUS)PcdSet64S (PcdSerialRegisterBase, (UINTN)*UartBase); +} + diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.inf b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.inf new file mode 100644 index 0000000000000000000000000000000000000000..ba789ca69041b647a4a881b03110ff853df89f65 --- /dev/null +++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.inf @@ -0,0 +1,39 @@ +## @file +# Platform Hook Library instance for 16550 Uart. +# +# Copyright (c) 2020, ARM Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = Fdt16550SerialPortHookLib + MODULE_UNI_FILE = Fdt16550SerialPortHookLib.uni + FILE_GUID = C6DFD3F0-179D-4376-89A5-F641A2E7EFB5 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = PlatformHookLib|DXE_CORE DXE_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION + CONSTRUCTOR = PlatformHookSerialPortInitialize + +[Sources] + Fdt16550SerialPortHookLib.c + +[LibraryClasses] + BaseLib + PcdLib + HobLib + +[Packages] + ArmVirtPkg/ArmVirtPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase + +[Guids] + gEarly16550UartBaseAddressGuid + diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.uni b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.uni new file mode 100644 index 0000000000000000000000000000000000000000..19a61a4a03244321bda7c88cd26128b44bfd46b4 --- /dev/null +++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/Fdt16550SerialPortHookLib.uni @@ -0,0 +1,14 @@ +// /** @file +// Platform Hook Library instance for 16550 Uart. +// +// +// Copyright (c) 2020, ARM Ltd. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "Platform Hook Library instance for 16550 Uart." + +#string STR_MODULE_DESCRIPTION #language en-US "Platform Hook Library instance for 16550 Uart." + -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'