]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c
842bbe005b36e9f22dac8d81c6dc9c96a18ae473
[mirror_edk2.git] / ArmPlatformPkg / Library / PL011SerialPortLib / PL011SerialPortLib.c
1 /** @file
2 Serial I/O Port library functions with no library constructor/destructor
3
4
5 Copyright (c) 2008 - 2010, Apple Inc. 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 <Include/Uefi.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 #include <ArmPlatform.h>
26
27 /*
28
29 Programmed hardware of Serial port.
30
31 @return Always return EFI_UNSUPPORTED.
32
33 **/
34 RETURN_STATUS
35 EFIAPI
36 SerialPortInitialize (
37 VOID
38 )
39 {
40 // No parity, 1 stop, no fifo, 8 data bits
41 return PL011UartInitialize (
42 (UINTN)PcdGet64 (PcdSerialRegisterBase),
43 (UINTN)PcdGet64 (PcdUartDefaultBaudRate),
44 PL011_UARTLCR_H_WLEN_8);
45 }
46
47 /**
48 Write data to serial device.
49
50 @param Buffer Point of data buffer which need to be writed.
51 @param NumberOfBytes Number of output bytes which are cached in Buffer.
52
53 @retval 0 Write data failed.
54 @retval !0 Actual number of bytes writed to serial device.
55
56 **/
57 UINTN
58 EFIAPI
59 SerialPortWrite (
60 IN UINT8 *Buffer,
61 IN UINTN NumberOfBytes
62 )
63 {
64 return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
65 }
66
67 /**
68 Read data from serial device and save the datas in buffer.
69
70 @param Buffer Point of data buffer which need to be writed.
71 @param NumberOfBytes Number of output bytes which are cached in Buffer.
72
73 @retval 0 Read data failed.
74 @retval !0 Aactual number of bytes read from serial device.
75
76 **/
77 UINTN
78 EFIAPI
79 SerialPortRead (
80 OUT UINT8 *Buffer,
81 IN UINTN NumberOfBytes
82 )
83 {
84 return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
85 }
86
87 /**
88 Check to see if any data is avaiable to be read from the debug device.
89
90 @retval EFI_SUCCESS At least one byte of data is avaiable to be read
91 @retval EFI_NOT_READY No data is avaiable to be read
92 @retval EFI_DEVICE_ERROR The serial device is not functioning properly
93
94 **/
95 BOOLEAN
96 EFIAPI
97 SerialPortPoll (
98 VOID
99 )
100 {
101 return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase));
102 }