From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (EUR05-AM6-obe.outbound.protection.outlook.com [40.107.22.47]) by mx.groups.io with SMTP id smtpd.web10.5609.1601673278312160596 for ; Fri, 02 Oct 2020 14:14:38 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=qWtWhWzy; spf=pass (domain: arm.com, ip: 40.107.22.47, 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=2A67lEqI6GXPHAkgJJxtwpkKZcIVqavkelDDRf3Q5Zg=; b=qWtWhWzyK18YzXxqOf8uMXxUq2ubfkcQwqwLcFtwEduAT1GVr35wix61vMSNH9q/fSPS9Wit1CRMqd/YIgSlMchvAsxMhyDJZekUQTU/xndAxom7yLn08Zqm6Oa9xiPh0Yua/IvNT/8gyUzbZuOMoBnDjTe5YDiuvmZieuajEvg= Received: from AM6P193CA0096.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::37) by DB7PR08MB3257.eurprd08.prod.outlook.com (2603:10a6:5:19::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.22; Fri, 2 Oct 2020 21:14:32 +0000 Received: from VE1EUR03FT049.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:88:cafe::2b) by AM6P193CA0096.outlook.office365.com (2603:10a6:209:88::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3433.35 via Frontend Transport; Fri, 2 Oct 2020 21:14:32 +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=pass 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 VE1EUR03FT049.mail.protection.outlook.com (10.152.19.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3433.34 via Frontend Transport; Fri, 2 Oct 2020 21:14:32 +0000 Received: ("Tessian outbound 7a6fb63c1e64:v64"); Fri, 02 Oct 2020 21:14:30 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: edd61c0462aa69db X-CR-MTA-TID: 64aa7808 Received: from ffbcc8e9eb4d.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 89197AE4-96A0-4DFF-A825-66ED00B436EF.1; Fri, 02 Oct 2020 21:14:25 +0000 Received: from EUR02-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ffbcc8e9eb4d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 02 Oct 2020 21:14:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mf4cSadqeA91o4hMaL2/MoD4W6Wi+UydlS34ug0qhtv2J50lop4sF9UsJKhvfQqtjSMsOlRP5R+nVvkJLbc3kfNQH+pxEqsBawhOq6lUd28WJ68KcEfPJYtfmnIJDxiB5NH/ia3hTh13Pzvy00pqMomH4gypviGMRdtW75ONwgEw8NvV1KCTgXusbMS6uvTs+p6vi8epGaTUeOQyRsrAtHi53Tw1Vn6y+12xo56G+UF0zpZC4FEB7NrdCuCqeMcgmE8ibyRN6wK+wxveYqsEhetfXi9aQXArjc50lcPg6M1zmblHljIaI5HkTHXZXVG/a7Ql+UnLqmsxW5JizdNH4g== 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=2A67lEqI6GXPHAkgJJxtwpkKZcIVqavkelDDRf3Q5Zg=; b=Lz3AYt69bXx7KkkobwQFtw3+fYCfmGECg/CWoikZGa5DqOIi2VGsLWiCocZiQglCs9RWfT89Lh1hhOW6TU9pKYT7SaGIYbs7koRKC0SUSaliFfMmhAH0D6veAhLch3XL3a39e94Tbw9+nBpgNHUvRHsmTq+YJApKZ5b2rIHH1HojwTI2DsAb95+PjUk2L/M7609d4hqQ8951wTfEJZbO708g2/apCrpnWsD3wLfv7f6lUS1XrsOevZY5ATetE6AqLMJZzTYQ4jniurn2XYna8M49ZsY8PZV8NapV8mOIcsaAlEOigzsrkLPKVz5eZUmq5td8baiEAcZvHT1JA6SPVg== 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=pass (p=none sp=none pct=100) 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=2A67lEqI6GXPHAkgJJxtwpkKZcIVqavkelDDRf3Q5Zg=; b=qWtWhWzyK18YzXxqOf8uMXxUq2ubfkcQwqwLcFtwEduAT1GVr35wix61vMSNH9q/fSPS9Wit1CRMqd/YIgSlMchvAsxMhyDJZekUQTU/xndAxom7yLn08Zqm6Oa9xiPh0Yua/IvNT/8gyUzbZuOMoBnDjTe5YDiuvmZieuajEvg= Received: from AM3PR05CA0116.eurprd05.prod.outlook.com (2603:10a6:207:2::18) by VI1PR08MB4318.eurprd08.prod.outlook.com (2603:10a6:803:f8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3433.34; Fri, 2 Oct 2020 21:14:23 +0000 Received: from AM5EUR03FT049.eop-EUR03.prod.protection.outlook.com (2603:10a6:207:2:cafe::fd) by AM3PR05CA0116.outlook.office365.com (2603:10a6:207:2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3433.35 via Frontend Transport; Fri, 2 Oct 2020 21:14:23 +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=pass 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 AM5EUR03FT049.mail.protection.outlook.com (10.152.17.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3433.34 via Frontend Transport; Fri, 2 Oct 2020 21:14:23 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) 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.2044.4; Fri, 2 Oct 2020 21:14:19 +0000 Received: from E107187.Arm.com (10.57.53.44) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2044.4 via Frontend Transport; Fri, 2 Oct 2020 21:14:18 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , Subject: [PATCH v5 09/15] ArmVirtPkg: 16550 UART Platform hook library Date: Fri, 2 Oct 2020 22:14:03 +0100 Message-ID: <20201002211409.43888-10-sami.mujawar@arm.com> X-Mailer: git-send-email 2.11.0.windows.3 In-Reply-To: <20201002211409.43888-1-sami.mujawar@arm.com> References: <20201002211409.43888-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3fe6acca-1e54-41c4-9e3d-08d86718280b X-MS-TrafficTypeDiagnostic: VI1PR08MB4318:|DB7PR08MB3257: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:3383;OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: kqprTn3qphJmnKtFo5OwtglydO/UTvX9x52YAqKEKp9gSvEhfj4LLHqqMNFz1HsWO/qQn4EYSkwsUEpNoXGg7x+eri+kVfWSuS3q13l/7E1drsqRH7n3ZImVUHzlVYNw/4wiW3EvjLoi1SC94qJpzubQpi8sMe84uLusNMnaM8dVH0V3OVbn49+TywEbdGH034PXxrxwAEX7wJ3F4RwacBqGs9jMV/HQXc1BwBOvoVS7l63z7ztsZSbXbaDEK14Aeis4JNySVasRgOszQ3CYl0Ul2rRMty2C1c3vMhOVjy0IjKDN3SqSFck290Rq7HKx1NyJ22n3K/ZIwlTF4zNHoc7/k7eSgGeh2HWQM72XEP+riLWykvf6E7Y7BQv5nhq+FPAu+8R6t6OTobM/wQv65uFpHbwUd1tHXOAvKky0NGZTbmZruFSHYlRjYrp5J5FuDGDESBsbybPrwFmicWsPpMVs5zUtKcVZ5kqItx1Z+E8= 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;SFS:(4636009)(39860400002)(136003)(346002)(376002)(396003)(46966005)(82740400003)(8936002)(36756003)(47076004)(336012)(82310400003)(19627235002)(81166007)(356005)(83380400001)(70586007)(83080400001)(6666004)(1076003)(70206006)(186003)(26005)(426003)(4326008)(86362001)(44832011)(5660300002)(7696005)(6916009)(30864003)(2616005)(54906003)(8676002)(316002)(966005)(478600001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4318 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT049.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 7056d319-baf5-45d5-4b0e-08d8671822de X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8cQvoNdIMUtT33avHFAWHnr1MHSeANaJEu+wmCLMW7twq/K3mJBxp7AqC99y1sV5COnGDcMiHMjlt4UabVExiyppxTxXcQmRIiRpYLE82Mq7J7gaWFG3rUUThkFUwMXCDhznJ6ylG4qdXKzPm0XUN5z/hQr57q8JzjXjrv+Gvth33vveXiQlH7tJeaDHlPOQ9Vxuhn9nwG+PVgNp31G82TZ7G0buKgAz/sbw+kBKcCZ3puw3RNidZpxEm/t+Mi89DpPdopTRwSpPUCqV/TrRfV36h936/z50j+h5F3RBiad+ihOb+nwdWeRqiN+2FQ8i+kp7p2t5z6z4A0m/d/Tzl2Rk7v5wSc9ycLoPWCX2ipuvOLuTnzL957WoXcZ23dPymAKG0Z47Y9JBhhUmGYnOsO/d2121JuSqNGroEpL9kCBOQEU4sAPJ9/zKdQCSrZbIdc6GWNG5gDjsAw6IE8AiqQpto49ybR4Vne3c1Kk46cunU2zJWB0yCIjzBZbKMGZOslO9ZimPYdhmL8Q/tZ9h1w== 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;SFS:(4636009)(39850400004)(376002)(346002)(396003)(136003)(46966005)(44832011)(7696005)(8676002)(2616005)(70206006)(6916009)(426003)(26005)(2906002)(336012)(70586007)(47076004)(186003)(478600001)(19627235002)(8936002)(36906005)(86362001)(966005)(1076003)(30864003)(54906003)(5660300002)(83380400001)(82310400003)(6666004)(36756003)(82740400003)(81166007)(316002)(4326008);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2020 21:14:32.0491 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3fe6acca-1e54-41c4-9e3d-08d86718280b 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-AuthSource: VE1EUR03FT049.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3257 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 Reviewed-by: Ard Biesheuvel --- Notes: v5: - No code changes, resending patch with v5 series. [Sami] Ref: https://edk2.groups.io/g/devel/message/62142 v4: - No code change, resending patch with v4 series. [Sami] Ref: https://edk2.groups.io/g/devel/message/61721 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)'