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