1/** @file
2  Post Code Library instance that writes post code values to I/O port 0x80.
3
4  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
5  This program and the accompanying materials
6  are licensed and made available under the terms and conditions of the BSD License
7  which accompanies this distribution.  The full text of the license may be found at
8  http://opensource.org/licenses/bsd-license.php.
9
10  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13**/
14
15#include <Base.h>
16
17#include <Library/PostCodeLib.h>
18#include <Library/PcdLib.h>
19#include <Library/IoLib.h>
20#include <Library/DebugLib.h>
21
22/**
23  Sends an 32-bit value to a POST card.
24
25  Sends the 32-bit value specified by Value to a POST card, and returns Value.
26  Some implementations of this library function may perform I/O operations
27  directly to a POST card device.  Other implementations may send Value to
28  ReportStatusCode(), and the status code reporting mechanism will eventually
29  display the 32-bit value on the status reporting device.
30
31  PostCode() must actively prevent recursion.  If PostCode() is called while
32  processing another any other Post Code Library function, then
33  PostCode() must return Value immediately.
34
35  @param  Value  The 32-bit value to write to the POST card.
36
37  @return The 32-bit value to write to the POST card.
38
39**/
40UINT32
41EFIAPI
42PostCode (
43  IN UINT32  Value
44  )
45{
46  switch (PcdGet8 (PcdPort80DataWidth)) {
47  case 8:
48    IoWrite8 (0x80, (UINT8)(Value));
49    break;
50  case 16:
51    IoWrite16 (0x80, (UINT16)(Value));
52    break;
53  case 32:
54    IoWrite32 (0x80, Value);
55    break;
56  default:
57    //
58    // Assert on the invalid data width
59    //
60    ASSERT (FALSE);
61    break;
62  }
63
64  return Value;
65}
66
67
68/**
69  Sends an 32-bit value to a POST and associated ASCII string.
70
71  Sends the 32-bit value specified by Value to a POST card, and returns Value.
72  If Description is not NULL, then the ASCII string specified by Description is
73  also passed to the handler that displays the POST card value.  Some
74  implementations of this library function may perform I/O operations directly
75  to a POST card device.  Other implementations may send Value to ReportStatusCode(),
76  and the status code reporting mechanism will eventually display the 32-bit
77  value on the status reporting device.
78
79  PostCodeWithDescription()must actively prevent recursion.  If
80  PostCodeWithDescription() is called while processing another any other Post
81  Code Library function, then PostCodeWithDescription() must return Value
82  immediately.
83
84  @param  Value        The 32-bit value to write to the POST card.
85  @param  Description  The pointer to an ASCII string that is a description of the
86                       POST code value.  This is an optional parameter that may
87                       be NULL.
88
89  @return The 32-bit value to write to the POST card.
90
91**/
92UINT32
93EFIAPI
94PostCodeWithDescription (
95  IN UINT32       Value,
96  IN CONST CHAR8  *Description  OPTIONAL
97  )
98{
99  PostCode (Value);
100  return Value;
101}
102
103
104/**
105  Returns TRUE if POST Codes are enabled.
106
107  This function returns TRUE if the POST_CODE_PROPERTY_POST_CODE_ENABLED
108  bit of PcdPostCodePropertyMask is set.  Otherwise FALSE is returned.
109
110  @retval  TRUE   The POST_CODE_PROPERTY_POST_CODE_ENABLED bit of
111                  PcdPostCodeProperyMask is set.
112  @retval  FALSE  The POST_CODE_PROPERTY_POST_CODE_ENABLED bit of
113                  PcdPostCodeProperyMask is clear.
114
115**/
116BOOLEAN
117EFIAPI
118PostCodeEnabled (
119  VOID
120  )
121{
122  return (BOOLEAN) ((PcdGet8(PcdPostCodePropertyMask) & POST_CODE_PROPERTY_POST_CODE_ENABLED) != 0);
123}
124
125
126/**
127  Returns TRUE if POST code descriptions are enabled.
128
129  This function returns TRUE if the POST_CODE_PROPERTY_POST_CODE_DESCRIPTION_ENABLED
130  bit of PcdPostCodePropertyMask is set.  Otherwise FALSE is returned.
131
132  @retval  TRUE   The POST_CODE_PROPERTY_POST_CODE_DESCRIPTION_ENABLED bit of
133                  PcdPostCodeProperyMask is set.
134  @retval  FALSE  The POST_CODE_PROPERTY_POST_CODE_DESCRIPTION_ENABLED bit of
135                  PcdPostCodeProperyMask is clear.
136
137**/
138BOOLEAN
139EFIAPI
140PostCodeDescriptionEnabled (
141  VOID
142  )
143{
144  return (BOOLEAN) ((PcdGet8(PcdPostCodePropertyMask) & POST_CODE_PROPERTY_POST_CODE_DESCRIPTION_ENABLED) != 0);
145}
146