]> git.proxmox.com Git - mirror_edk2.git/blob - 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
1 /** @file
2 Serial I/O Port library functions with no library constructor/destructor
3
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
5 Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
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
17 #include <Base.h>
18
19 #include <Library/IoLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/SerialPortLib.h>
22
23 #include <Drivers/PL011Uart.h>
24
25
26 /*
27
28 Programmed hardware of Serial port.
29
30 @return Always return RETURN_UNSUPPORTED.
31
32 **/
33 RETURN_STATUS
34 EFIAPI
35 SerialPortInitialize (
36 VOID
37 )
38 {
39 return PL011UartInitializePort (
40 (UINTN)PcdGet64 (PcdSerialRegisterBase),
41 (UINTN)PcdGet64 (PcdUartDefaultBaudRate),
42 0, // Use the default value for Fifo depth
43 (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity),
44 PcdGet8 (PcdUartDefaultDataBits),
45 (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits));
46 }
47
48 /**
49 Write data to serial device.
50
51 @param Buffer Point of data buffer which need to be written.
52 @param NumberOfBytes Number of output bytes which are cached in Buffer.
53
54 @retval 0 Write data failed.
55 @retval !0 Actual number of bytes written to serial device.
56
57 **/
58 UINTN
59 EFIAPI
60 SerialPortWrite (
61 IN UINT8 *Buffer,
62 IN UINTN NumberOfBytes
63 )
64 {
65 return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
66 }
67
68 /**
69 Read data from serial device and save the data in buffer.
70
71 @param Buffer Point of data buffer which need to be written.
72 @param NumberOfBytes Number of output bytes which are cached in Buffer.
73
74 @retval 0 Read data failed.
75 @retval !0 Actual number of bytes read from serial device.
76
77 **/
78 UINTN
79 EFIAPI
80 SerialPortRead (
81 OUT UINT8 *Buffer,
82 IN UINTN NumberOfBytes
83 )
84 {
85 return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
86 }
87
88 /**
89 Check to see if any data is available to be read from the debug device.
90
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
93 @retval EFI_DEVICE_ERROR The serial device is not functioning properly
94
95 **/
96 BOOLEAN
97 EFIAPI
98 SerialPortPoll (
99 VOID
100 )
101 {
102 return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase));
103 }