/** Sets the baud rate, receive FIFO depth, transmit/receice time out, parity, data bits, and stop bits on a serial device. @param BaudRate The requested baud rate. A BaudRate value of 0 will use the device's default interface speed. On output, the value actually set. @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the serial interface. A ReceiveFifoDepth value of 0 will use the device's default FIFO depth. On output, the value actually set. @param Timeout The requested time out for a single character in microseconds. This timeout applies to both the transmit and receive side of the interface. A Timeout value of 0 will use the device's default time out value. On output, the value actually set. @param Parity The type of parity to use on this serial device. A Parity value of DefaultParity will use the device's default parity value. On output, the value actually set. @param DataBits The number of data bits to use on the serial device. A DataBits vaule of 0 will use the device's default data bit setting. On output, the value actually set. @param StopBits The number of stop bits to use on this serial device. A StopBits value of DefaultStopBits will use the device's default number of stop bits. On output, the value actually set. @retval RETURN_SUCCESS The new attributes were set on the serial device. @retval RETURN_UNSUPPORTED The serial device does not support this operation. @retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value. @retval RETURN_DEVICE_ERROR The serial device is not functioning correctly. **/ RETURN_STATUS EFIAPI SerialPortSetAttributes ( IN OUT UINT64 *BaudRate, IN OUT UINT32 *ReceiveFifoDepth, IN OUT UINT32 *Timeout, IN OUT EFI_PARITY_TYPE *Parity, IN OUT UINT8 *DataBits, IN OUT EFI_STOP_BITS_TYPE *StopBits ) { RETURN_STATUS Status; if (mSerialBaseAddress == 0) { Status = RETURN_UNSUPPORTED; } else { Status = PL011UartInitializePort ( mSerialBaseAddress, FixedPcdGet32 (PL011UartClkInHz), BaudRate, ReceiveFifoDepth, Parity, DataBits, StopBits ); } return Status; }
/** Set new attributes to PL011. @param BaudRate The baud rate of the serial device. If the baud rate is not supported, the speed will be reduced down to the nearest supported one and the variable's value will be updated accordingly. @param ReceiveFifoDepth The number of characters the device will buffer on input. If the specified value is not supported, the variable's value will be reduced down to the nearest supported one. @param Timeout If applicable, the number of microseconds the device will wait before timing out a Read or a Write operation. @param Parity If applicable, this is the EFI_PARITY_TYPE that is computed or checked as each character is transmitted or received. If the device does not support parity, the value is the default parity value. @param DataBits The number of data bits in each character @param StopBits If applicable, the EFI_STOP_BITS_TYPE number of stop bits per character. If the device does not support stop bits, the value is the default stop bit value. @retval EFI_SUCCESS All attributes were set correctly on the serial device. @retval EFI_INVALID_PARAMETERS One or more of the attributes has an unsupported value. **/ RETURN_STATUS EFIAPI SerialPortSetAttributes ( IN OUT UINT64 *BaudRate, IN OUT UINT32 *ReceiveFifoDepth, IN OUT UINT32 *Timeout, IN OUT EFI_PARITY_TYPE *Parity, IN OUT UINT8 *DataBits, IN OUT EFI_STOP_BITS_TYPE *StopBits ) { return PL011UartInitializePort ( (UINTN)PcdGet64 (PcdSerialRegisterBase), BaudRate, ReceiveFifoDepth, Parity, DataBits, StopBits); }
/** Program hardware of Serial port @return RETURN_NOT_FOUND if no PL011 base address could be found Otherwise, result of PL011UartInitializePort () is returned **/ RETURN_STATUS EFIAPI FdtPL011SerialPortLibInitialize ( VOID ) { VOID *Hob; CONST UINT64 *UartBase; UINT64 BaudRate; UINT32 ReceiveFifoDepth; EFI_PARITY_TYPE Parity; UINT8 DataBits; EFI_STOP_BITS_TYPE StopBits; Hob = GetFirstGuidHob (&gEarlyPL011BaseAddressGuid); if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof *UartBase) { return RETURN_NOT_FOUND; } UartBase = GET_GUID_HOB_DATA (Hob); mSerialBaseAddress = (UINTN)*UartBase; if (mSerialBaseAddress == 0) { return RETURN_NOT_FOUND; } BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate); ReceiveFifoDepth = 0; // Use the default value for Fifo depth Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity); DataBits = PcdGet8 (PcdUartDefaultDataBits); StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits); return PL011UartInitializePort ( mSerialBaseAddress, FixedPcdGet32 (PL011UartClkInHz), &BaudRate, &ReceiveFifoDepth, &Parity, &DataBits, &StopBits ); }
/** Initialize controllers that must setup in the normal world This function is called by the ArmPlatformPkg/Pei or ArmPlatformPkg/Pei/PlatformPeim in the PEI phase. **/ RETURN_STATUS ArmPlatformInitialize ( IN UINTN MpId ) { RETURN_STATUS Status; UINT64 BaudRate; UINT32 ReceiveFifoDepth; EFI_PARITY_TYPE Parity; UINT8 DataBits; EFI_STOP_BITS_TYPE StopBits; Status = RETURN_SUCCESS; // // Initialize the Serial Debug UART // if (FixedPcdGet64 (PcdSerialDbgRegisterBase)) { 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); BaudRate = (UINTN)FixedPcdGet64 (PcdSerialDbgUartBaudRate); Status = PL011UartInitializePort ( (UINTN)FixedPcdGet64 (PcdSerialDbgRegisterBase), FixedPcdGet32 (PcdSerialDbgUartClkInHz), &BaudRate, &ReceiveFifoDepth, &Parity, &DataBits, &StopBits ); } return Status; }
STATIC UINT64 SerialPortGetBaseAddress ( VOID ) { UINT64 BaudRate; UINT32 ReceiveFifoDepth; EFI_PARITY_TYPE Parity; 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; RETURN_STATUS Status; DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress); if ((DeviceTreeBase == NULL) || (fdt_check_header (DeviceTreeBase) != 0)) { return 0; } // // Enumerate all FDT nodes looking for a PL011 and capture its base address // 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; } } } } return 0; }