]> git.proxmox.com Git - mirror_edk2.git/blob - SourceLevelDebugPkg/Include/Library/DebugCommunicationLib.h
ad7bccda285c1ae6b4f3ecb75f77a2de6a9cb007
[mirror_edk2.git] / SourceLevelDebugPkg / Include / Library / DebugCommunicationLib.h
1 /** @file
2 Debug Communication Library definitions.
3
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef __DEBUG_COMMUNICATION_LIB_H__
10 #define __DEBUG_COMMUNICATION_LIB_H__
11
12 typedef VOID *DEBUG_PORT_HANDLE;
13
14 /**
15 Caller provided function to be invoked at the end of DebugPortInitialize().
16
17 Refer to the description for DebugPortInitialize() for more details.
18
19 @param[in] Context The first input argument of DebugPortInitialize().
20 @param[in] DebugPortHandle Debug port handle created by Debug Communication Library.
21
22 **/
23 typedef
24 VOID
25 (EFIAPI *DEBUG_PORT_CONTINUE)(
26 IN VOID *Context,
27 IN DEBUG_PORT_HANDLE DebugPortHandle
28 );
29
30 /**
31 Initialize the debug port.
32
33 This function will initialize debug port to get it ready for data transmission. If
34 certain Debug Communication Library instance has to save some private data in the
35 stack, this function must work on the mode that doesn't return to the caller, then
36 the caller needs to wrap up all rest of logic after DebugPortInitialize() into one
37 function and pass it into DebugPortInitialize(). DebugPortInitialize() is
38 responsible to invoke the passing-in function at the end of DebugPortInitialize().
39
40 If the parameter Function is not NULL, Debug Communication Library instance will
41 invoke it by passing in the Context to be the first parameter. Debug Communication
42 Library instance could create one debug port handle to be the second parameter
43 passing into the Function. Debug Communication Library instance also could pass
44 NULL to be the second parameter if it doesn't create the debug port handle.
45
46 If the parameter Function is NULL, and Context is not NULL. At this time, Context
47 is the debug port handle created by the previous Debug Communication Library
48 instance.
49 a) If the instance can understand and continue use the private data of the previous
50 instance, it could return the same handle as passed in (as Context parameter).
51 b) If the instance does not understand, or does not want to continue use the
52 private data of the previous instance, it could ignore the input Context parameter
53 and create the new handle to be returned.
54
55 If Function() is NULL and Context is NULL, Debug Communication Library could create a
56 new handle and return it. NULL is also a valid handle to be returned.
57
58 @param[in] Context Context needed by callback function; it was optional.
59 @param[in] Function Continue function called by Debug Communication library;
60 it was optional.
61
62 @return The debug port handle created by Debug Communication Library if Function
63 is not NULL.
64
65 **/
66 DEBUG_PORT_HANDLE
67 EFIAPI
68 DebugPortInitialize (
69 IN VOID *Context,
70 IN DEBUG_PORT_CONTINUE Function
71 );
72
73 /**
74 Read data from debug device and save the datas in buffer.
75
76 Reads NumberOfBytes data bytes from a debug device into the buffer
77 specified by Buffer. The number of bytes actually read is returned.
78 If the return value is less than NumberOfBytes, then the rest operation failed.
79 If NumberOfBytes is zero, then return 0.
80
81 @param Handle Debug port handle.
82 @param Buffer Pointer to the data buffer to store the data read from the debug device.
83 @param NumberOfBytes Number of bytes which will be read.
84 @param Timeout Timeout value for reading from debug device. Its unit is Microsecond.
85
86 @retval 0 Read data failed, no data is to be read.
87 @retval >0 Actual number of bytes read from debug device.
88
89 **/
90 UINTN
91 EFIAPI
92 DebugPortReadBuffer (
93 IN DEBUG_PORT_HANDLE Handle,
94 IN UINT8 *Buffer,
95 IN UINTN NumberOfBytes,
96 IN UINTN Timeout
97 );
98
99 /**
100 Write data from buffer to debug device.
101
102 Writes NumberOfBytes data bytes from Buffer to the debug device.
103 The number of bytes actually written to the debug device is returned.
104 If the return value is less than NumberOfBytes, then the write operation failed.
105 If NumberOfBytes is zero, then return 0.
106
107 @param Handle Debug port handle.
108 @param Buffer Pointer to the data buffer to be written.
109 @param NumberOfBytes Number of bytes to written to the debug device.
110
111 @retval 0 NumberOfBytes is 0.
112 @retval >0 The number of bytes written to the debug device.
113 If this value is less than NumberOfBytes, then the write operation failed.
114
115 **/
116 UINTN
117 EFIAPI
118 DebugPortWriteBuffer (
119 IN DEBUG_PORT_HANDLE Handle,
120 IN UINT8 *Buffer,
121 IN UINTN NumberOfBytes
122 );
123
124 /**
125 Polls a debug device to see if there is any data waiting to be read.
126
127 Polls a debug device to see if there is any data waiting to be read.
128 If there is data waiting to be read from the debug device, then TRUE is returned.
129 If there is no data waiting to be read from the debug device, then FALSE is returned.
130
131 @param Handle Debug port handle.
132
133 @retval TRUE Data is waiting to be read from the debug device.
134 @retval FALSE There is no data waiting to be read from the debug device.
135
136 **/
137 BOOLEAN
138 EFIAPI
139 DebugPortPollBuffer (
140 IN DEBUG_PORT_HANDLE Handle
141 );
142
143 #endif