]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c
MdeModulePkg/UfsPciHcDxe: Fix EBC build error
[mirror_edk2.git] / ArmPlatformPkg / ArmVirtualizationPkg / Library / FdtPL011SerialPortLib / FdtPL011SerialPortLib.c
CommitLineData
f1f0ba19
LE
1/** @file\r
2 Serial I/O Port library functions with base address discovered from FDT\r
3\r
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
5 Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>\r
6 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
7 Copyright (c) 2014, Red Hat, Inc.<BR>\r
8\r
9 This program and the accompanying materials\r
10 are licensed and made available under the terms and conditions of the BSD License\r
11 which accompanies this distribution. The full text of the license may be found at\r
12 http://opensource.org/licenses/bsd-license.php\r
13\r
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17**/\r
18\r
19#include <Base.h>\r
20\r
21#include <Library/PcdLib.h>\r
22#include <Library/SerialPortLib.h>\r
23#include <Pi/PiBootMode.h>\r
24#include <Uefi/UefiBaseType.h>\r
25#include <Uefi/UefiMultiPhase.h>\r
26#include <Pi/PiHob.h>\r
27#include <Library/HobLib.h>\r
28#include <Guid/EarlyPL011BaseAddress.h>\r
29\r
30#include <Drivers/PL011Uart.h>\r
31\r
32STATIC UINTN mSerialBaseAddress;\r
33\r
34RETURN_STATUS\r
35EFIAPI\r
36SerialPortInitialize (\r
37 VOID\r
38 )\r
39{\r
40 return RETURN_SUCCESS;\r
41}\r
42\r
43/**\r
44\r
45 Program hardware of Serial port\r
46\r
47 @return RETURN_NOT_FOUND if no PL011 base address could be found\r
48 Otherwise, result of PL011UartInitializePort () is returned\r
49\r
50**/\r
51RETURN_STATUS\r
52EFIAPI\r
53FdtPL011SerialPortLibInitialize (\r
54 VOID\r
55 )\r
56{\r
57 VOID *Hob;\r
58 CONST UINT64 *UartBase;\r
59 UINT64 BaudRate;\r
60 UINT32 ReceiveFifoDepth;\r
61 EFI_PARITY_TYPE Parity;\r
62 UINT8 DataBits;\r
63 EFI_STOP_BITS_TYPE StopBits;\r
64\r
65 Hob = GetFirstGuidHob (&gEarlyPL011BaseAddressGuid);\r
66 if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof *UartBase) {\r
67 return RETURN_NOT_FOUND;\r
68 }\r
69 UartBase = GET_GUID_HOB_DATA (Hob);\r
70\r
71 mSerialBaseAddress = (UINTN)*UartBase;\r
72 if (mSerialBaseAddress == 0) {\r
73 return RETURN_NOT_FOUND;\r
74 }\r
75\r
76 BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);\r
77 ReceiveFifoDepth = 0; // Use the default value for Fifo depth\r
78 Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity);\r
79 DataBits = PcdGet8 (PcdUartDefaultDataBits);\r
80 StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits);\r
81\r
82 return PL011UartInitializePort (\r
83 mSerialBaseAddress, &BaudRate, &ReceiveFifoDepth,\r
84 &Parity, &DataBits, &StopBits);\r
85}\r
86\r
87/**\r
88 Write data to serial device.\r
89\r
90 @param Buffer Point of data buffer which need to be written.\r
91 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
92\r
93 @retval 0 Write data failed.\r
94 @retval !0 Actual number of bytes written to serial device.\r
95\r
96**/\r
97UINTN\r
98EFIAPI\r
99SerialPortWrite (\r
100 IN UINT8 *Buffer,\r
101 IN UINTN NumberOfBytes\r
102 )\r
103{\r
104 if (mSerialBaseAddress != 0) {\r
105 return PL011UartWrite (mSerialBaseAddress, Buffer, NumberOfBytes);\r
106 }\r
107 return 0;\r
108}\r
109\r
110/**\r
111 Read data from serial device and save the data in buffer.\r
112\r
113 @param Buffer Point of data buffer which need to be written.\r
114 @param NumberOfBytes Number of output bytes which are cached in Buffer.\r
115\r
116 @retval 0 Read data failed.\r
117 @retval !0 Actual number of bytes read from serial device.\r
118\r
119**/\r
120UINTN\r
121EFIAPI\r
122SerialPortRead (\r
123 OUT UINT8 *Buffer,\r
124 IN UINTN NumberOfBytes\r
125)\r
126{\r
127 if (mSerialBaseAddress != 0) {\r
128 return PL011UartRead (mSerialBaseAddress, Buffer, NumberOfBytes);\r
129 }\r
130 return 0;\r
131}\r
132\r
133/**\r
134 Check to see if any data is available to be read from the debug device.\r
135\r
136 @retval TRUE At least one byte of data is available to be read\r
137 @retval FALSE No data is available to be read\r
138\r
139**/\r
140BOOLEAN\r
141EFIAPI\r
142SerialPortPoll (\r
143 VOID\r
144 )\r
145{\r
146 if (mSerialBaseAddress != 0) {\r
147 return PL011UartPoll (mSerialBaseAddress);\r
148 }\r
149 return FALSE;\r
150}\r