]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.c
ArmPlatformPkg: Remove PcdStandalone from Sec module and Introduce ArmPlatformSecExtr...
[mirror_edk2.git] / ArmPlatformPkg / ArmRealViewEbPkg / Library / GdbSerialLib / GdbSerialLib.c
1 /** @file
2 Basic serial IO abstaction for GDB
3
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include <Uefi.h>
17 #include <Library/GdbSerialLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/IoLib.h>
20 #include <Drivers/PL011Uart.h>
21
22 RETURN_STATUS
23 EFIAPI
24 GdbSerialLibConstructor (
25 VOID
26 )
27 {
28 return GdbSerialInit (115200, 0, 8, 1);
29 }
30
31 RETURN_STATUS
32 EFIAPI
33 GdbSerialInit (
34 IN UINT64 BaudRate,
35 IN UINT8 Parity,
36 IN UINT8 DataBits,
37 IN UINT8 StopBits
38 )
39 {
40 if ((Parity != 0) || (DataBits != 8) || (StopBits != 1)) {
41 return RETURN_UNSUPPORTED;
42 }
43
44 if (BaudRate != 115200) {
45 // Could add support for different Baud rates....
46 return RETURN_UNSUPPORTED;
47 }
48
49 UINT32 Base = PcdGet32 (PcdGdbUartBase);
50
51 // initialize baud rate generator to 115200 based on EB clock REFCLK24MHZ
52 MmioWrite32 (Base + UARTIBRD, UART_115200_IDIV);
53 MmioWrite32 (Base + UARTFBRD, UART_115200_FDIV);
54
55 // no parity, 1 stop, no fifo, 8 data bits
56 MmioWrite32 (Base + UARTLCR_H, 0x60);
57
58 // clear any pending errors
59 MmioWrite32 (Base + UARTECR, 0);
60
61 // enable tx, rx, and uart overall
62 MmioWrite32 (Base + UARTCR, 0x301);
63
64 return RETURN_SUCCESS;
65 }
66
67 BOOLEAN
68 EFIAPI
69 GdbIsCharAvailable (
70 VOID
71 )
72 {
73 UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;
74
75 if ((MmioRead32 (FR) & UART_RX_EMPTY_FLAG_MASK) == 0) {
76 return TRUE;
77 } else {
78 return FALSE;
79 }
80 }
81
82 CHAR8
83 EFIAPI
84 GdbGetChar (
85 VOID
86 )
87 {
88 UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;
89 UINT32 DR = PcdGet32 (PcdGdbUartBase) + UARTDR;
90
91 while ((MmioRead32 (FR) & UART_RX_EMPTY_FLAG_MASK) == 0);
92 return MmioRead8 (DR);
93 }
94
95 VOID
96 EFIAPI
97 GdbPutChar (
98 IN CHAR8 Char
99 )
100 {
101 UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;
102 UINT32 DR = PcdGet32 (PcdGdbUartBase) + UARTDR;
103
104 while ((MmioRead32 (FR) & UART_TX_EMPTY_FLAG_MASK) != 0);
105 MmioWrite8 (DR, Char);
106 return;
107 }
108
109 VOID
110 GdbPutString (
111 IN CHAR8 *String
112 )
113 {
114 while (*String != '\0') {
115 GdbPutChar (*String);
116 String++;
117 }
118 }