1. add EdkSerialPortLibNull.inf
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / Pei / MemoryStausCodeWorker.c
1 /** @file
2 Memory status code worker in PEI.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. 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 Module Name: MemoryStatusCodeWorker.c
14
15 **/
16
17 //
18 // Include common header file for this module.
19 //
20 #include "CommonHeader.h"
21
22 #include "PeiStatusCode.h"
23
24 /**
25 Create one memory status code GUID'ed HOB, use PacketIndex
26 to identify the packet.
27
28 @param PacketIndex Index of records packet.
29
30 @return Always return pointer of memory status code packet.
31
32 **/
33 STATIC
34 MEMORY_STATUSCODE_PACKET_HEADER *
35 CreateMemoryStatusCodePacket (
36 UINT16 PacketIndex
37 )
38 {
39 MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader;
40
41 //
42 // Build GUID'ed HOB with PCD defined size.
43 //
44 PacketHeader =
45 (MEMORY_STATUSCODE_PACKET_HEADER *) BuildGuidHob (
46 &gMemoryStatusCodeRecordGuid,
47 PcdGet16 (PcdStatusCodeMemorySize) *
48 1024 +
49 sizeof (MEMORY_STATUSCODE_PACKET_HEADER)
50 );
51 ASSERT (PacketHeader != NULL);
52
53 PacketHeader->MaxRecordsNumber = (PcdGet16 (PcdStatusCodeMemorySize) * 1024)/ sizeof (MEMORY_STATUSCODE_RECORD);
54 PacketHeader->PacketIndex = PacketIndex;
55 PacketHeader->RecordIndex = 0;
56
57 return PacketHeader;
58 }
59
60
61
62 /**
63 Initialize memory status code.
64 Create one GUID'ed HOB with PCD defined size. If create required size
65 GUID'ed HOB failed, then ASSERT().
66
67 @return The function always return EFI_SUCCESS
68
69 **/
70 EFI_STATUS
71 MemoryStatusCodeInitializeWorker (
72 VOID
73 )
74 {
75 //
76 // Create first memory status code GUID'ed HOB.
77 //
78 CreateMemoryStatusCodePacket (0);
79
80 return EFI_SUCCESS;
81 }
82
83
84 /**
85 Report status code into GUID'ed HOB..
86
87 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
88
89 @param Value Describes the current status of a hardware or software entity.
90 This included information about the class and subclass that is used to classify the entity
91 as well as an operation. For progress codes, the operation is the current activity.
92 For error codes, it is the exception. For debug codes, it is not defined at this time.
93 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
94 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
95
96 @param Instance The enumeration of a hardware or software entity within the system.
97 A system may contain multiple entities that match a class/subclass pairing.
98 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
99 not meaningful, or not relevant. Valid instance numbers start with 1.
100
101 @return The function always return EFI_SUCCESS.
102
103 **/
104 EFI_STATUS
105 MemoryStatusCodeReportWorker (
106 IN EFI_STATUS_CODE_TYPE CodeType,
107 IN EFI_STATUS_CODE_VALUE Value,
108 IN UINT32 Instance
109 )
110 {
111
112 EFI_PEI_HOB_POINTERS Hob;
113 MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader;
114 MEMORY_STATUSCODE_RECORD *Record = NULL;
115 UINT16 PacketIndex = 0;;
116
117 //
118 // Journal GUID'ed HOBs to find empty record entry, if found, then save status code in it.
119 // otherwise, create a new GUID'ed HOB.
120 //
121 Hob.Raw = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid);
122 while (Hob.Raw != NULL) {
123 PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid);
124
125 //
126 // Check whether pccket is full or not.
127 //
128 if (PacketHeader->RecordIndex < PacketHeader->MaxRecordsNumber) {
129 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);
130 Record = &Record[PacketHeader->RecordIndex++];
131 break;
132 }
133 //
134 // Cache number of found packet in PacketIndex.
135 //
136 PacketIndex++;
137
138 Hob.Raw = GetNextGuidHob (&gMemoryStatusCodeRecordGuid, Hob.Raw);
139 }
140
141 if (NULL == Record) {
142 //
143 // In order to save status code , create new packet.
144 //
145 PacketHeader = CreateMemoryStatusCodePacket (PacketIndex);
146
147 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);
148 Record = &Record[PacketHeader->RecordIndex++];
149 }
150
151 Record->CodeType = CodeType;
152 Record->Instance = Instance;
153 Record->Value = Value;
154
155 return EFI_SUCCESS;
156 }