]> git.proxmox.com Git - mirror_edk2.git/blob - SourceLevelDebugPkg/Include/Library/DebugCommunicationLib.h
bc7a00b537c7ae786b377b27518911df49600674
[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 transmition. 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 /**
75 Read data from debug device and save the datas in buffer.
76
77 Reads NumberOfBytes data bytes from a debug device into the buffer
78 specified by Buffer. The number of bytes actually read is returned.
79 If the return value is less than NumberOfBytes, then the rest operation failed.
80 If NumberOfBytes is zero, then return 0.
81
82 @param Handle Debug port handle.
83 @param Buffer Pointer to the data buffer to store the data read from the debug device.
84 @param NumberOfBytes Number of bytes which will be read.
85 @param Timeout Timeout value for reading from debug device. Its unit is Microsecond.
86
87 @retval 0 Read data failed, no data is to be read.
88 @retval >0 Actual number of bytes read from debug device.
89
90 **/
91 UINTN
92 EFIAPI
93 DebugPortReadBuffer (
94 IN DEBUG_PORT_HANDLE Handle,
95 IN UINT8 *Buffer,
96 IN UINTN NumberOfBytes,
97 IN UINTN Timeout
98 );
99
100
101 /**
102 Write data from buffer to debug device.
103
104 Writes NumberOfBytes data bytes from Buffer to the debug device.
105 The number of bytes actually written to the debug device is returned.
106 If the return value is less than NumberOfBytes, then the write operation failed.
107 If NumberOfBytes is zero, then return 0.
108
109 @param Handle Debug port handle.
110 @param Buffer Pointer to the data buffer to be written.
111 @param NumberOfBytes Number of bytes to written to the debug device.
112
113 @retval 0 NumberOfBytes is 0.
114 @retval >0 The number of bytes written to the debug device.
115 If this value is less than NumberOfBytes, then the write operation failed.
116
117 **/
118 UINTN
119 EFIAPI
120 DebugPortWriteBuffer (
121 IN DEBUG_PORT_HANDLE Handle,
122 IN UINT8 *Buffer,
123 IN UINTN NumberOfBytes
124 );
125
126 /**
127 Polls a debug device to see if there is any data waiting to be read.
128
129 Polls a debug device to see if there is any data waiting to be read.
130 If there is data waiting to be read from the debug device, then TRUE is returned.
131 If there is no data waiting to be read from the debug device, then FALSE is returned.
132
133 @param Handle Debug port handle.
134
135 @retval TRUE Data is waiting to be read from the debug device.
136 @retval FALSE There is no data waiting to be read from the debug device.
137
138 **/
139 BOOLEAN
140 EFIAPI
141 DebugPortPollBuffer (
142 IN DEBUG_PORT_HANDLE Handle
143 );
144
145 #endif
146