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