blob: b43ba7ed64847572d695c909757a189c23a68f0d [file] [log] [blame]
zbao7d94cf92012-07-02 14:19:14 +08001/**
2 * @file
3 *
4 * AMD Integrated Debug Debug_library Routines
5 *
6 * Contains all functions related to HDTOUT
7 *
8 * @xrefitem bom "File Content Label" "Release Content"
9 * @e project: AGESA
10 * @e sub-project: IDS
11 * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $
12 */
13/*****************************************************************************
Siyuan Wang641f00c2013-06-08 11:50:55 +080014 * Copyright (c) 2008 - 2012, Advanced Micro Devices, Inc.
15 * All rights reserved.
zbao7d94cf92012-07-02 14:19:14 +080016 *
Siyuan Wang641f00c2013-06-08 11:50:55 +080017 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are met:
19 * * Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * * Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
25 * its contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
zbao7d94cf92012-07-02 14:19:14 +080027 *
Siyuan Wang641f00c2013-06-08 11:50:55 +080028 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
zbao7d94cf92012-07-02 14:19:14 +080038 ******************************************************************************
39 */
40
41 /*----------------------------------------------------------------------------------------
42 * M O D U L E S U S E D
43 *----------------------------------------------------------------------------------------
44 */
45#include "AGESA.h"
46#include "Ids.h"
47#include "IdsLib.h"
48#include "amdlib.h"
49#include "AMD.h"
50#include "IdsDebugPrint.h"
51#include "Filecode.h"
52CODE_GROUP (G1_PEICC)
53RDATA_GROUP (G1_PEICC)
54
55#define FILECODE PROC_IDS_DEBUG_IDSDPSERIAL_FILECODE
56
57/**
58 * Determine whether IDS console is enabled.
59 *
60 *
61 * @retval TRUE Alway return true
62 *
63 **/
64STATIC BOOLEAN
65AmdIdsSerialSupport (
66 VOID
67 )
68{
69
70 return TRUE;
71}
72
73/**
74 * Get Serial customize Filter
75 *
76 * @param[in,out] Filter Filter do be filled
77 *
78 * @retval FALSE Alway return FALSE
79 *
80 **/
81STATIC BOOLEAN
82AmdIdsSerialGetFilter (
83 IN OUT UINT64 *Filter
84 )
85{
86 return FALSE;
87}
88
89
90#define IDS_SERIAL_PORT_LSR (IDS_SERIAL_PORT + 5)
91#define IDS_LSR_TRANSMIT_HOLDING_REGISTER_EMPTY_MASK BIT5
92/**
93 * Send byte to Serial Port
94 *
95 * Before use this routine, please make sure Serial Communications Chip have been initialed
96 *
97 * @param[in] ByteSended Byte to be sended
98 *
99 * @retval TRUE Byte sended successfully
100 * @retval FALSE Byte sended failed
101 *
102 **/
103STATIC BOOLEAN
104AmdIdsSerialSendByte (
105 IN CHAR8 ByteSended
106 )
107{
108 UINT32 RetryCount;
109 UINT8 Value;
110
111 //Wait until LSR.Bit5 (Transmitter holding register Empty)
112 RetryCount = 200;
113 do {
114 LibAmdIoRead (AccessWidth8, IDS_SERIAL_PORT_LSR, &Value, NULL);
115 RetryCount--;
116 } while (((Value & IDS_LSR_TRANSMIT_HOLDING_REGISTER_EMPTY_MASK) == 0) &&
117 (RetryCount > 0));
118
119 if (RetryCount == 0) {
120 //Time expired
121 return FALSE;
122 } else {
123 LibAmdIoWrite (AccessWidth8, IDS_SERIAL_PORT, &ByteSended, NULL);
124 return TRUE;
125 }
126}
127
128
129/**
130 * Print formated string
131 *
132 * @param[in] Buffer - Point to input buffer
133 * @param[in] BufferSize - Buffer size
134 * @param[in] debugPrintPrivate - Option
135 *
136**/
137STATIC VOID
138AmdIdsSerialPrint (
139 IN CHAR8 *Buffer,
140 IN UINTN BufferSize,
141 IN IDS_DEBUG_PRINT_PRIVATE_DATA *debugPrintPrivate
142 )
143{
144 BOOLEAN SendStatus;
145 UINT32 RetryCount;
146 RetryCount = 200;
147 while (BufferSize--) {
148 do {
149 if (*Buffer == '\n') {
150 SendStatus = AmdIdsSerialSendByte ('\r');
151 }
152 SendStatus = AmdIdsSerialSendByte (*Buffer);
153 RetryCount--;
154 } while ((SendStatus == FALSE) && (RetryCount > 0));
155 Buffer ++;
156 }
157}
158
159/**
160 * Init local private data
161 *
162 * @param[in] Flag - filter flag
163 * @param[in] debugPrintPrivate - Point to debugPrintPrivate
164 *
165**/
166STATIC VOID
167AmdIdsSerialInitPrivateData (
168 IN UINT64 Flag,
169 IN IDS_DEBUG_PRINT_PRIVATE_DATA *debugPrintPrivate
170 )
171{
172
173}
174
175CONST IDS_DEBUG_PRINT ROMDATA IdsDebugPrintSerialInstance =
176{
177 AmdIdsSerialSupport,
178 AmdIdsSerialGetFilter,
179 AmdIdsSerialInitPrivateData,
180 AmdIdsSerialPrint
181};
182
183
184