From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.14320.1637687363037740081 for ; Tue, 23 Nov 2021 09:09:23 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: pierre.gondois@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B72AC1FB; Tue, 23 Nov 2021 09:09:22 -0800 (PST) Received: from e126645.nice.arm.com (unknown [10.34.129.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D20D73F5A1; Tue, 23 Nov 2021 09:09:21 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [PATCH v3 06/15] DynamicTablesPkg: FdtHwInfoParser: Add Serial port parser Date: Tue, 23 Nov 2021 18:08:29 +0100 Message-Id: <20211123170838.143805-7-Pierre.Gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211123170838.143805-1-Pierre.Gondois@arm.com> References: <20211123170838.143805-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pierre Gondois The Microsoft Debug Port Table 2 (DBG2), the Serial Port Console Redirector (SPCR) table are mandatory tables required for booting a standards-based operating system. The DBG2 table is used by the OS debugger while the SPCR table is used to configure the serial terminal. Additionally, the serial ports available on a platform for generic use also need to be described in DSDT/SSDT for an OS to be able to use the serial ports. The Arm Base System Architecture 1.0 specification a lists of supported serial port hardware for Arm Platforms. This list includes the following serial port UARTs: - SBSA/Generic UART - a fully 16550 compatible UART. Along, with these the PL011 UART is the most commonly used serial port hardware on Arm platforms. The serial port hardware information is described in the platform Device Tree, the bindings for which can be found at: - linux/Documentation/devicetree/bindings/serial/serial.yaml - linux/Documentation/devicetree/bindings/serial/8250.txt - linux/Documentation/devicetree/bindings/serial/arm_sbsa_uart.txt - linux/Documentation/devicetree/bindings/serial/pl011.yaml The FdtHwInfoParser implements a Serial Port Parser that parses the platform Device Tree to create CM_ARM_SERIAL_PORT_INFO objects with the following IDs: - EArmObjSerialConsolePortInfo (for use by SPCR) - EArmObjSerialDebugPortInfo (for use by DBG2) - EArmObjSerialPortInfo (for use as generic Serial Ports) The Serial Port for use by SPCR is selected by parsing the Device Tree for the '/chosen' node with the 'stdout-path' property. The next Serial Port is selected for use as the Debug Serial Port and the remaining serial ports are used as generic serial ports. The CM_ARM_SERIAL_PORT_INFO objects are encapsulated in Configuration Manager descriptor objects with the respective IDs and are added to the platform information repository. The platform Configuration Manager can then utilise this information when generating the DBG2, SPCR and the SSDT serial port tables. Signed-off-by: Pierre Gondois --- Notes: v2: - Add pl011 compatible string in serial port parser. [Sami] - Use 16550_with_GAS ID when 16550 is detected in serial port parser. [Sami] v3: - Remove trailing whitespace. [Pierre] .../Serial/ArmSerialPortParser.c | 620 ++++++++++++++++++ .../Serial/ArmSerialPortParser.h | 47 ++ 2 files changed, 667 insertions(+) create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/Ar= mSerialPortParser.c create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/Ar= mSerialPortParser.h diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerial= PortParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSeri= alPortParser.c new file mode 100644 index 000000000000..b05b04da41a6 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortPar= ser.c @@ -0,0 +1,620 @@ +/** @file + Arm Serial Port Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/serial/serial.yaml + - linux/Documentation/devicetree/bindings/serial/8250.txt + - linux/Documentation/devicetree/bindings/serial/arm_sbsa_uart.txt + - linux/Documentation/devicetree/bindings/serial/pl011.yaml +**/ + +#include + +#include "CmObjectDescUtility.h" +#include "FdtHwInfoParser.h" +#include "Serial/ArmSerialPortParser.h" + +/** List of "compatible" property values for serial port nodes. + + Any other "compatible" value is not supported by this module. +*/ +STATIC CONST COMPATIBILITY_STR SerialCompatibleStr[] =3D { + {"ns16550a"}, + {"arm,sbsa-uart"}, + {"arm,pl011"} +}; + +/** COMPATIBILITY_INFO structure for the SerialCompatible. +*/ +CONST COMPATIBILITY_INFO SerialCompatibleInfo =3D { + ARRAY_SIZE (SerialCompatibleStr), + SerialCompatibleStr +}; + +/** 16550 UART compatible strings. + + Any string of this list must be part of SerialCompatible. +*/ +STATIC CONST COMPATIBILITY_STR Serial16550CompatibleStr[] =3D { + {"ns16550a"} +}; + +/** COMPATIBILITY_INFO structure for the Serial16550Compatible. +*/ +CONST COMPATIBILITY_INFO Serial16550CompatibleInfo =3D { + ARRAY_SIZE (Serial16550CompatibleStr), + Serial16550CompatibleStr +}; + +/** SBSA UART compatible strings. + + Include PL011 as SBSA uart is a subset of PL011. + + Any string of this list must be part of SerialCompatible. +*/ +STATIC CONST COMPATIBILITY_STR SerialSbsaCompatibleStr[] =3D { + {"arm,sbsa-uart"}, + {"arm,pl011"} +}; + +/** COMPATIBILITY_INFO structure for the SerialSbsaCompatible. +*/ +CONST COMPATIBILITY_INFO SerialSbsaCompatibleInfo =3D { + ARRAY_SIZE (SerialSbsaCompatibleStr), + SerialSbsaCompatibleStr +}; + +/** Parse a serial port node. + + @param [in] Fdt Pointer to a Flattened Device Tree (Fdt= ). + @param [in] SerialPortNode Offset of a serial-port node. + @param [in] SerialPortInfo The CM_ARM_SERIAL_PORT_INFO to populate= . + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_UNSUPPORTED Unsupported. +**/ +STATIC +EFI_STATUS +EFIAPI +SerialPortNodeParser ( + IN CONST VOID * Fdt, + IN INT32 SerialPortNode, + IN CM_ARM_SERIAL_PORT_INFO * SerialPortInfo + ) +{ + EFI_STATUS Status; + INT32 IntcNode; + CONST UINT8 * SizeValue; + + INT32 AddressCells; + INT32 SizeCells; + INT32 IntCells; + + CONST UINT8 * Data; + INT32 DataSize; + UINT8 AccessSize; + + if ((Fdt =3D=3D NULL) || + (SerialPortInfo =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D FdtGetParentAddressInfo ( + Fdt, + SerialPortNode, + &AddressCells, + &SizeCells + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Don't support more than 64 bits and less than 32 bits addresses. + if ((AddressCells < 1) || + (AddressCells > 2) || + (SizeCells < 1) || + (SizeCells > 2)) { + ASSERT (0); + return EFI_ABORTED; + } + + Data =3D fdt_getprop (Fdt, SerialPortNode, "reg", &DataSize); + if ((Data =3D=3D NULL) || + (DataSize < (INT32)(sizeof (UINT32) * + GET_DT_REG_ADDRESS_OFFSET (1, AddressCells, SizeCells)) - 1)) { + // If error or not enough space. + ASSERT (0); + return EFI_ABORTED; + } + + if (AddressCells =3D=3D 2) { + SerialPortInfo->BaseAddress =3D fdt64_to_cpu (*(UINT64*)Data); + } else { + SerialPortInfo->BaseAddress =3D fdt32_to_cpu (*(UINT32*)Data); + } + + SizeValue =3D Data + (sizeof (UINT32) * + GET_DT_REG_SIZE_OFFSET (0, AddressCells, SizeCells)); + if (SizeCells =3D=3D 2) { + SerialPortInfo->BaseAddressLength =3D fdt64_to_cpu (*(UINT64*)SizeVa= lue); + } else { + SerialPortInfo->BaseAddressLength =3D fdt32_to_cpu (*(UINT32*)SizeVa= lue); + } + + // Get the associated interrupt-controller. + Status=3D FdtGetIntcParentNode (Fdt, SerialPortNode, &IntcNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + return Status; + } + + // Get the number of cells used to encode an interrupt. + Status =3D FdtGetInterruptCellsInfo (Fdt, IntcNode, &IntCells); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Data =3D fdt_getprop (Fdt, SerialPortNode, "interrupts", &DataSize); + if ((Data =3D=3D NULL) || (DataSize !=3D (IntCells * sizeof (UINT32)))= ) { + // If error or not 1 interrupt. + ASSERT (0); + return EFI_ABORTED; + } + + SerialPortInfo->Interrupt =3D FdtGetInterruptId ((CONST UINT32*)Data); + + // Note: clock-frequency is optional for SBSA UART. + Data =3D fdt_getprop (Fdt, SerialPortNode, "clock-frequency", &DataSiz= e); + if (Data !=3D NULL) { + if (DataSize < sizeof (UINT32)) { + // If error or not enough space. + ASSERT (0); + return EFI_ABORTED; + } else if (fdt_node_offset_by_phandle (Fdt, fdt32_to_cpu (*Data)) >=3D= 0) { + // "clock-frequency" can be a "clocks phandle to refer to the clk = used". + // This is not supported. + ASSERT (0); + return EFI_UNSUPPORTED; + } + SerialPortInfo->Clock =3D fdt32_to_cpu (*(UINT32*)Data); + } + + if (FdtNodeIsCompatible (Fdt, SerialPortNode, &Serial16550CompatibleIn= fo)) { + SerialPortInfo->PortSubtype =3D + EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_16550_WITH_GAS; + + /* reg-io-width: + description: | + The size (in bytes) of the IO accesses that should be performed= on the + device. There are some systems that require 32-bit accesses to = the + UART. + */ + Data =3D fdt_getprop (Fdt, SerialPortNode, "reg-io-width", &DataSize= ); + if (Data !=3D NULL) { + if (DataSize < sizeof (UINT32)) { + // If error or not enough space. + ASSERT (0); + return EFI_ABORTED; + } + + AccessSize =3D fdt32_to_cpu (*(UINT32*)Data); + if (AccessSize > EFI_ACPI_6_3_QWORD) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + SerialPortInfo->AccessSize =3D AccessSize; + } else { + // 8250/16550 defaults to byte access. + SerialPortInfo->AccessSize =3D EFI_ACPI_6_3_BYTE; + } + } else if (FdtNodeIsCompatible ( + Fdt, + SerialPortNode, + &SerialSbsaCompatibleInfo + )) { + SerialPortInfo->PortSubtype =3D + EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_SBSA_GENERIC_UART; + } else { + ASSERT (0); + return EFI_UNSUPPORTED; + } + + // Set Baudrate to 115200 by default + SerialPortInfo->BaudRate =3D 115200; + return EFI_SUCCESS; +} + +/** Find the console serial-port node in the DT. + + This function fetches the node referenced in the "stdout-path" + property of the "chosen" node. + + @param [in] Fdt Pointer to a Flattened Device Tree (= Fdt). + @param [out] SerialConsoleNode If success, contains the node offset + of the console serial-port node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. +**/ +STATIC +EFI_STATUS +EFIAPI +GetSerialConsoleNode ( + IN CONST VOID * Fdt, + OUT INT32 * SerialConsoleNode + ) +{ + CONST CHAR8 * Prop; + INT32 PropSize; + CONST CHAR8 * Path; + INT32 PathLen; + INT32 ChosenNode; + + if ((Fdt =3D=3D NULL) || + (SerialConsoleNode =3D=3D NULL)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // The "chosen" node resides at the the root of the DT. Fetch it. + ChosenNode =3D fdt_path_offset (Fdt, "/chosen"); + if (ChosenNode < 0) { + return EFI_NOT_FOUND; + } + + Prop =3D fdt_getprop (Fdt, ChosenNode, "stdout-path", &PropSize); + if ((Prop =3D=3D NULL) || (PropSize < 0)) { + return EFI_NOT_FOUND; + } + + // Determine the actual path length, as a colon terminates the path. + Path =3D ScanMem8 (Prop, ':', PropSize); + if (Path =3D=3D NULL) { + PathLen =3D (UINT32)AsciiStrLen (Prop); + } else { + PathLen =3D (INT32)(Path - Prop); + } + + // Aliases cannot start with a '/', so it must be the actual path. + if (Prop[0] =3D=3D '/') { + *SerialConsoleNode =3D fdt_path_offset_namelen (Fdt, Prop, PathLen); + return EFI_SUCCESS; + } + + // Lookup the alias, as this contains the actual path. + Path =3D fdt_get_alias_namelen (Fdt, Prop, PathLen); + if (Path =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + *SerialConsoleNode =3D fdt_path_offset (Fdt, Path); + return EFI_SUCCESS; +} + +/** CM_ARM_SERIAL_PORT_INFO dispatcher function (for a generic serial-po= rt). + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] GenericSerialInfo Pointer to a serial port info list. + @param [in] NodeCount Count of serial ports to dispatch. + @param [in] SerialObjectId Serial port object ID. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +STATIC +EFI_STATUS +EFIAPI +ArmSerialPortInfoDispatch ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN CM_ARM_SERIAL_PORT_INFO * GenericSerialInfo, + IN INT32 NodeCount, + IN EARM_OBJECT_ID SerialObjectId +) +{ + EFI_STATUS Status; + CM_OBJ_DESCRIPTOR * NewCmObjDesc; + + if ((GenericSerialInfo =3D=3D NULL) || (NodeCount =3D=3D 0)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + if ((SerialObjectId !=3D EArmObjSerialPortInfo) && + (SerialObjectId !=3D EArmObjSerialDebugPortInfo) && + (SerialObjectId !=3D EArmObjSerialConsolePortInfo)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Dispatch the Generic Serial ports + Status =3D CreateCmObjDesc ( + CREATE_CM_ARM_OBJECT_ID (SerialObjectId), + NodeCount, + GenericSerialInfo, + sizeof (CM_ARM_SERIAL_PORT_INFO) * NodeCount, + &NewCmObjDesc + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Add all the CmObjs to the Configuration Manager. + Status =3D AddMultipleCmObj (FdtParserHandle, NewCmObjDesc, 0, NULL); + ASSERT_EFI_ERROR (Status); + FreeCmObjDesc (NewCmObjDesc); + return Status; +} + +/** CM_ARM_SERIAL_PORT_INFO parser function (for debug/console serial-po= rt). + + This parser expects FdtBranch to be the debug serial-port node. + At most one CmObj is created. + The following structure is populated: + typedef struct CmArmSerialPortInfo { + UINT64 BaseAddress; // {Populated} + UINT32 Interrupt; // {Populated} + UINT64 BaudRate; // {default} + UINT32 Clock; // {Populated} + UINT16 PortSubtype; // {Populated} + UINT64 BaseAddressLength // {Populated} + } CM_ARM_SERIAL_PORT_INFO; + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + @param [in] SerialObjectId ArmNamespace Object ID for the serial por= t. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +STATIC +EFI_STATUS +EFIAPI +ArmSerialPortInfoParser ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch, + IN EARM_OBJECT_ID SerialObjectId + ) +{ + EFI_STATUS Status; + CM_ARM_SERIAL_PORT_INFO SerialInfo; + + if ((SerialObjectId !=3D EArmObjSerialDebugPortInfo) && + (SerialObjectId !=3D EArmObjSerialConsolePortInfo)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + ZeroMem (&SerialInfo, sizeof (SerialInfo)); + + Status =3D SerialPortNodeParser ( + FdtParserHandle->Fdt, + FdtBranch, + &SerialInfo + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status =3D ArmSerialPortInfoDispatch ( + FdtParserHandle, + &SerialInfo, + 1, + SerialObjectId + ); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** SerialPort dispatcher. + + This disptacher populates the CM_ARM_SERIAL_PORT_INFO structure for + the following CM_OBJ_ID: + - EArmObjSerialConsolePortInfo + - EArmObjSerialDebugPortInfo + - EArmObjSerialPortInfo + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +SerialPortDispatcher ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ) +{ + EFI_STATUS Status; + INT32 SerialConsoleNode; + INT32 SerialDebugNode; + INT32 SerialNode; + UINT32 Index; + UINT32 SerialNodeCount; + UINT32 SerialNodesRemaining; + CM_ARM_SERIAL_PORT_INFO * GenericSerialInfo; + UINT32 GenericSerialIndex; + VOID * Fdt; + + if (FdtParserHandle =3D=3D NULL) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Fdt =3D FdtParserHandle->Fdt; + + // Count the number of serial-ports. + Status =3D FdtCountCompatNodeInBranch ( + Fdt, + FdtBranch, + &SerialCompatibleInfo, + &SerialNodeCount + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + if (SerialNodeCount =3D=3D 0) { + return EFI_NOT_FOUND; + } + + // Track remaining nodes separately as SerialNodeCount + // is used in for loop below and reducing SerialNodeCount + // would result in the Generic Serial port nodes not + // being found if the serial console port node is among + // the first few serial nodes. + SerialNodesRemaining =3D SerialNodeCount; + + // Identify the serial console port. + Status =3D GetSerialConsoleNode (Fdt, &SerialConsoleNode); + if (Status =3D=3D EFI_NOT_FOUND) { + // No serial console. + SerialConsoleNode =3D -1; + } else if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } else { + // Parse the console serial-port. + Status =3D ArmSerialPortInfoParser ( + FdtParserHandle, + SerialConsoleNode, + EArmObjSerialConsolePortInfo + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + SerialNodesRemaining--; + } + + GenericSerialInfo =3D NULL; + if (SerialNodesRemaining > 1) { + // We have more than one serial port remaining. + // This means that the first serial port will + // be reserved as a debug port, and the remaining + // will be for general purpose use. + SerialNodesRemaining--; + GenericSerialInfo =3D AllocateZeroPool ( + SerialNodesRemaining * + sizeof (CM_ARM_SERIAL_PORT_INFO) + ); + if (GenericSerialInfo =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + } + + SerialNode =3D FdtBranch; + SerialDebugNode =3D -1; + GenericSerialIndex =3D 0; + for (Index =3D 0; Index < SerialNodeCount; Index++) { + // Search the next serial-port node in the branch. + Status =3D FdtGetNextCompatNodeInBranch ( + Fdt, + FdtBranch, + &SerialCompatibleInfo, + &SerialNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + if (Status =3D=3D EFI_NOT_FOUND) { + // Should have found the node. + Status =3D EFI_ABORTED; + } + goto exit_handler; + } + + // Ignore the serial console node. + if (SerialNode =3D=3D SerialConsoleNode) { + continue; + } else if (SerialDebugNode =3D=3D -1) { + // The first serial-port node, not being the console serial-port, + // will be the debug serial-port. + SerialDebugNode =3D SerialNode; + Status =3D ArmSerialPortInfoParser ( + FdtParserHandle, + SerialDebugNode, + EArmObjSerialDebugPortInfo + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + } else { + if (GenericSerialInfo =3D=3D NULL) { + // Should not be possible. + ASSERT (0); + Status =3D EFI_ABORTED; + goto exit_handler; + } + + Status =3D SerialPortNodeParser ( + Fdt, + SerialNode, + &GenericSerialInfo[GenericSerialIndex++] + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + } + } // for + + if (GenericSerialIndex > 0) { + Status =3D ArmSerialPortInfoDispatch ( + FdtParserHandle, + GenericSerialInfo, + GenericSerialIndex, + EArmObjSerialPortInfo + ); + } + +exit_handler: + if (GenericSerialInfo !=3D NULL) { + FreePool (GenericSerialInfo); + } + return Status; +} diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerial= PortParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSeri= alPortParser.h new file mode 100644 index 000000000000..5e4707849e39 --- /dev/null +++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortPar= ser.h @@ -0,0 +1,47 @@ +/** @file + Arm Serial Port Parser. + + Copyright (c) 2021, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - linux/Documentation/devicetree/bindings/serial/serial.yaml + - linux/Documentation/devicetree/bindings/serial/8250.txt +**/ + +#ifndef ARM_SERIAL_PORT_PARSER_H_ +#define ARM_SERIAL_PORT_PARSER_H_ + +/** SerialPort dispatcher. + + This disptacher populates the CM_ARM_SERIAL_PORT_INFO structure for + the following CM_OBJ_ID: + - EArmObjSerialConsolePortInfo + - EArmObjSerialDebugPortInfo + - EArmObjSerialPortInfo + + A parser parses a Device Tree to populate a specific CmObj type. None, + one or many CmObj can be created by the parser. + The created CmObj are then handed to the parser's caller through the + HW_INFO_ADD_OBJECT interface. + This can also be a dispatcher. I.e. a function that not parsing a + Device Tree but calling other parsers. + + @param [in] FdtParserHandle A handle to the parser instance. + @param [in] FdtBranch When searching for DT node name, restrict + the search to this Device Tree branch. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_ABORTED An error occurred. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND Not found. + @retval EFI_UNSUPPORTED Unsupported. +**/ +EFI_STATUS +EFIAPI +SerialPortDispatcher ( + IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, + IN INT32 FdtBranch + ); + +#endif // ARM_SERIAL_PORT_PARSER_H_ --=20 2.25.1