]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiDxePostCodeLibReportStatusCode/PostCode.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / PeiDxePostCodeLibReportStatusCode / PostCode.c
1 /** @file
2 Post code library instace bases on report status code library
3 PostCode Library for PEIMs and DXE drivers that send PostCode to ReportStatusCode
4
5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <PiPei.h>
11
12 #include <Library/PostCodeLib.h>
13 #include <Library/ReportStatusCodeLib.h>
14 #include <Library/PcdLib.h>
15 #include <Library/BaseLib.h>
16
17 /**
18 Converts POST code value to status code value.
19
20 This macro converts the post code to status code value. Bits 0..4 of PostCode
21 are mapped to bits 16..20 of status code value, and bits 5..7 of PostCode are mapped to bits
22 24..26 of status code value.
23
24 @param PostCode POST code value.
25
26 @return The converted status code value.
27
28 **/
29 #define POST_CODE_TO_STATUS_CODE_VALUE(PostCode) \
30 ((EFI_STATUS_CODE_VALUE) (((PostCode & 0x1f) << 16) | ((PostCode & 0x3) << 19)))
31
32 /**
33 Sends an 32-bit value to a POST card.
34
35 Sends the 32-bit value specified by Value to a POST card, and returns Value.
36 Some implementations of this library function may perform I/O operations
37 directly to a POST card device. Other implementations may send Value to
38 ReportStatusCode(), and the status code reporting mechanism will eventually
39 display the 32-bit value on the status reporting device.
40
41 PostCode() must actively prevent recursion. If PostCode() is called while
42 processing another any other Post Code Library function, then
43 PostCode() must return Value immediately.
44
45 @param Value The 32-bit value to write to the POST card.
46
47 @return The 32-bit value to write to the POST card.
48
49 **/
50 UINT32
51 EFIAPI
52 PostCode (
53 IN UINT32 Value
54 )
55 {
56 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, POST_CODE_TO_STATUS_CODE_VALUE (Value));
57 return Value;
58 }
59
60 /**
61 Sends an 32-bit value to a POST and associated ASCII string.
62
63 Sends the 32-bit value specified by Value to a POST card, and returns Value.
64 If Description is not NULL, then the ASCII string specified by Description is
65 also passed to the handler that displays the POST card value. Some
66 implementations of this library function may perform I/O operations directly
67 to a POST card device. Other implementations may send Value to ReportStatusCode(),
68 and the status code reporting mechanism will eventually display the 32-bit
69 value on the status reporting device.
70
71 PostCodeWithDescription()must actively prevent recursion. If
72 PostCodeWithDescription() is called while processing another any other Post
73 Code Library function, then PostCodeWithDescription() must return Value
74 immediately.
75
76 @param Value The 32-bit value to write to the POST card.
77 @param Description The pointer to an ASCII string that is a description of the
78 POST code value. This is an optional parameter that may
79 be NULL.
80
81 @return The 32-bit value to write to the POST card.
82
83 **/
84 UINT32
85 EFIAPI
86 PostCodeWithDescription (
87 IN UINT32 Value,
88 IN CONST CHAR8 *Description OPTIONAL
89 )
90 {
91 if (Description == NULL) {
92 REPORT_STATUS_CODE (
93 EFI_PROGRESS_CODE,
94 POST_CODE_TO_STATUS_CODE_VALUE (Value)
95 );
96 } else {
97 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
98 EFI_PROGRESS_CODE,
99 POST_CODE_TO_STATUS_CODE_VALUE (Value),
100 Description,
101 AsciiStrSize (Description)
102 );
103 }
104
105 return Value;
106 }
107
108 /**
109 Returns TRUE if POST Codes are enabled.
110
111 This function returns TRUE if the POST_CODE_PROPERTY_POST_CODE_ENABLED
112 bit of PcdPostCodePropertyMask is set. Otherwise FALSE is returned.
113
114 @retval TRUE The POST_CODE_PROPERTY_POST_CODE_ENABLED bit of
115 PcdPostCodeProperyMask is set.
116 @retval FALSE The POST_CODE_PROPERTY_POST_CODE_ENABLED bit of
117 PcdPostCodeProperyMask is clear.
118
119 **/
120 BOOLEAN
121 EFIAPI
122 PostCodeEnabled (
123 VOID
124 )
125 {
126 return (BOOLEAN)((PcdGet8 (PcdPostCodePropertyMask) & POST_CODE_PROPERTY_POST_CODE_ENABLED) != 0);
127 }
128
129 /**
130 Returns TRUE if POST code descriptions are enabled.
131
132 This function returns TRUE if the POST_CODE_PROPERTY_POST_CODE_DESCRIPTION_ENABLED
133 bit of PcdPostCodePropertyMask is set. Otherwise FALSE is returned.
134
135 @retval TRUE The POST_CODE_PROPERTY_POST_CODE_DESCRIPTION_ENABLED bit of
136 PcdPostCodeProperyMask is set.
137 @retval FALSE The POST_CODE_PROPERTY_POST_CODE_DESCRIPTION_ENABLED bit of
138 PcdPostCodeProperyMask is clear.
139
140 **/
141 BOOLEAN
142 EFIAPI
143 PostCodeDescriptionEnabled (
144 VOID
145 )
146 {
147 return (BOOLEAN)((PcdGet8 (PcdPostCodePropertyMask) & POST_CODE_PROPERTY_POST_CODE_DESCRIPTION_ENABLED) != 0);
148 }