summaryrefslogtreecommitdiffstats
path: root/ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.c
diff options
context:
space:
mode:
Diffstat (limited to 'ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.c')
-rw-r--r--ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.c94
1 files changed, 34 insertions, 60 deletions
diff --git a/ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.c b/ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.c
index c340212432..dc5459b4ce 100644
--- a/ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.c
+++ b/ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.c
@@ -15,7 +15,7 @@
#include <Library/PcdLib.h>
#include <Library/PL011UartLib.h>
#include <Library/SerialPortLib.h>
-#include <libfdt.h>
+#include <Library/FdtSerialPortAddressLib.h>
RETURN_STATUS
EFIAPI
@@ -56,74 +56,48 @@ SerialPortGetBaseAddress (
UINT8 DataBits;
EFI_STOP_BITS_TYPE StopBits;
VOID *DeviceTreeBase;
- INT32 Node, Prev;
- INT32 Len;
- CONST CHAR8 *Compatible;
- CONST CHAR8 *NodeStatus;
- CONST CHAR8 *CompatibleItem;
- CONST UINT64 *RegProperty;
- UINTN UartBase;
+ FDT_SERIAL_PORTS Ports;
+ UINT64 UartBase;
RETURN_STATUS Status;
DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
- if ((DeviceTreeBase == NULL) || (fdt_check_header (DeviceTreeBase) != 0)) {
+ if (DeviceTreeBase == NULL) {
+ return 0;
+ }
+
+ Status = FdtSerialGetPorts (DeviceTreeBase, "arm,pl011", &Ports);
+ if (RETURN_ERROR (Status)) {
return 0;
}
//
- // Enumerate all FDT nodes looking for a PL011 and capture its base address
+ // Default to the first port found, but (if there are multiple ports) allow
+ // the "/chosen" node to override it. Note that if FdtSerialGetConsolePort()
+ // fails, it does not modify UartBase.
//
- for (Prev = 0; ; Prev = Node) {
- Node = fdt_next_node (DeviceTreeBase, Prev, NULL);
- if (Node < 0) {
- break;
- }
-
- Compatible = fdt_getprop (DeviceTreeBase, Node, "compatible", &Len);
- if (Compatible == NULL) {
- continue;
- }
-
- //
- // Iterate over the NULL-separated items in the compatible string
- //
- for (CompatibleItem = Compatible; CompatibleItem < Compatible + Len;
- CompatibleItem += 1 + AsciiStrLen (CompatibleItem))
- {
- if (AsciiStrCmp (CompatibleItem, "arm,pl011") == 0) {
- NodeStatus = fdt_getprop (DeviceTreeBase, Node, "status", &Len);
- if ((NodeStatus != NULL) && (AsciiStrCmp (NodeStatus, "okay") != 0)) {
- continue;
- }
-
- RegProperty = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);
- if (Len != 16) {
- return 0;
- }
-
- UartBase = (UINTN)fdt64_to_cpu (ReadUnaligned64 (RegProperty));
-
- BaudRate = (UINTN)FixedPcdGet64 (PcdUartDefaultBaudRate);
- ReceiveFifoDepth = 0; // Use the default value for Fifo depth
- Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity);
- DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);
- StopBits = (EFI_STOP_BITS_TYPE)FixedPcdGet8 (PcdUartDefaultStopBits);
-
- Status = PL011UartInitializePort (
- UartBase,
- FixedPcdGet32 (PL011UartClkInHz),
- &BaudRate,
- &ReceiveFifoDepth,
- &Parity,
- &DataBits,
- &StopBits
- );
- if (!EFI_ERROR (Status)) {
- return UartBase;
- }
- }
- }
+ UartBase = Ports.BaseAddress[0];
+ if (Ports.NumberOfPorts > 1) {
+ FdtSerialGetConsolePort (DeviceTreeBase, &UartBase);
+ }
+
+ BaudRate = (UINTN)FixedPcdGet64 (PcdUartDefaultBaudRate);
+ ReceiveFifoDepth = 0; // Use the default value for Fifo depth
+ Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity);
+ DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);
+ StopBits = (EFI_STOP_BITS_TYPE)FixedPcdGet8 (PcdUartDefaultStopBits);
+
+ Status = PL011UartInitializePort (
+ UartBase,
+ FixedPcdGet32 (PL011UartClkInHz),
+ &BaudRate,
+ &ReceiveFifoDepth,
+ &Parity,
+ &DataBits,
+ &StopBits
+ );
+ if (!RETURN_ERROR (Status)) {
+ return UartBase;
}
return 0;