]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c
EmbeddedPkg/SerialDxe: Do not block UART when no data is available on the port
[mirror_edk2.git] / ArmPlatformPkg / Library / PL011SerialPortLib / PL011SerialPortLib.c
CommitLineData
1d5d0ae9 1/** @file
2 Serial I/O Port library functions with no library constructor/destructor
3
1d5d0ae9 4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
051e63bb 5 Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
1d5d0ae9 6
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15**/
16
40ab42dd 17#include <Base.h>
9dcfb8e5 18
1d5d0ae9 19#include <Library/IoLib.h>
9dcfb8e5 20#include <Library/PcdLib.h>
21#include <Library/SerialPortLib.h>
22
1d5d0ae9 23#include <Drivers/PL011Uart.h>
9dcfb8e5 24
1d5d0ae9 25
26/*
27
28 Programmed hardware of Serial port.
29
051e63bb 30 @return Always return RETURN_UNSUPPORTED.
1d5d0ae9 31
32**/
33RETURN_STATUS
34EFIAPI
35SerialPortInitialize (
36 VOID
37 )
38{
051e63bb 39 return PL011UartInitializePort (
9dcfb8e5 40 (UINTN)PcdGet64 (PcdSerialRegisterBase),
41 (UINTN)PcdGet64 (PcdUartDefaultBaudRate),
051e63bb 42 0, // Use the default value for Fifo depth
051e63bb 43 (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity),
44 PcdGet8 (PcdUartDefaultDataBits),
45 (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits));
1d5d0ae9 46}
47
48/**
49 Write data to serial device.
50
051e63bb 51 @param Buffer Point of data buffer which need to be written.
1d5d0ae9 52 @param NumberOfBytes Number of output bytes which are cached in Buffer.
53
54 @retval 0 Write data failed.
051e63bb 55 @retval !0 Actual number of bytes written to serial device.
1d5d0ae9 56
57**/
58UINTN
59EFIAPI
60SerialPortWrite (
61 IN UINT8 *Buffer,
62 IN UINTN NumberOfBytes
9dcfb8e5 63 )
1d5d0ae9 64{
9dcfb8e5 65 return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
1d5d0ae9 66}
67
68/**
051e63bb 69 Read data from serial device and save the data in buffer.
1d5d0ae9 70
051e63bb 71 @param Buffer Point of data buffer which need to be written.
1d5d0ae9 72 @param NumberOfBytes Number of output bytes which are cached in Buffer.
73
74 @retval 0 Read data failed.
051e63bb 75 @retval !0 Actual number of bytes read from serial device.
1d5d0ae9 76
77**/
78UINTN
79EFIAPI
80SerialPortRead (
81 OUT UINT8 *Buffer,
82 IN UINTN NumberOfBytes
83)
84{
9dcfb8e5 85 return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
1d5d0ae9 86}
87
88/**
051e63bb 89 Check to see if any data is available to be read from the debug device.
1d5d0ae9 90
051e63bb 91 @retval EFI_SUCCESS At least one byte of data is available to be read
92 @retval EFI_NOT_READY No data is available to be read
1d5d0ae9 93 @retval EFI_DEVICE_ERROR The serial device is not functioning properly
94
95**/
96BOOLEAN
97EFIAPI
98SerialPortPoll (
99 VOID
100 )
101{
9dcfb8e5 102 return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase));
1d5d0ae9 103}