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