]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/StatusCodeHandler/Pei/MemoryStausCodeWorker.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / Pei / MemoryStausCodeWorker.c
CommitLineData
3af9b388 1/** @file\r
2 PEI memory status code worker.\r
3\r
e5eed7d3
HT
4 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
3af9b388 6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "StatusCodeHandlerPei.h"\r
16\r
17/**\r
18 Worker function to create one memory status code GUID'ed HOB,\r
19 using PacketIndex to identify the packet.\r
20\r
21 @param PacketIndex Index of records packet.\r
22\r
23 @return Pointer to the memory status code packet.\r
24\r
25**/\r
26MEMORY_STATUSCODE_PACKET_HEADER *\r
27CreateMemoryStatusCodePacket (\r
28 UINT16 PacketIndex\r
29 )\r
30{\r
31 MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader;\r
32\r
33 //\r
34 // Build GUID'ed HOB with PCD defined size.\r
35 //\r
36 PacketHeader = BuildGuidHob (\r
37 &gMemoryStatusCodeRecordGuid,\r
38 PcdGet16 (PcdStatusCodeMemorySize) * 1024 + sizeof (MEMORY_STATUSCODE_PACKET_HEADER)\r
39 );\r
40 ASSERT (PacketHeader != NULL);\r
41\r
42 PacketHeader->MaxRecordsNumber = (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);\r
43 PacketHeader->PacketIndex = PacketIndex;\r
44 PacketHeader->RecordIndex = 0;\r
45\r
46 return PacketHeader;\r
47}\r
48\r
49/**\r
50 Create the first memory status code GUID'ed HOB as initialization for memory status code worker.\r
51\r
52 @retval EFI_SUCCESS The GUID'ed HOB is created successfully.\r
53\r
54**/\r
55EFI_STATUS\r
56MemoryStatusCodeInitializeWorker (\r
57 VOID\r
58 )\r
59{\r
60 //\r
61 // Create first memory status code GUID'ed HOB.\r
62 //\r
63 CreateMemoryStatusCodePacket (0);\r
64\r
65 return EFI_SUCCESS;\r
66}\r
67\r
68\r
69/**\r
70 Report status code into GUID'ed HOB.\r
71\r
72 This function reports status code into GUID'ed HOB. If not all packets are full, then\r
73 write status code into available entry. Otherwise, create a new packet for it.\r
74\r
75 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
76 @param CodeType Indicates the type of status code being reported.\r
77 @param Value Describes the current status of a hardware or\r
78 software entity. This includes information about the class and\r
79 subclass that is used to classify the entity as well as an operation.\r
80 For progress codes, the operation is the current activity.\r
81 For error codes, it is the exception.For debug codes,it is not defined at this time.\r
82 @param Instance The enumeration of a hardware or software entity within\r
83 the system. A system may contain multiple entities that match a class/subclass\r
84 pairing. The instance differentiates between them. An instance of 0 indicates\r
85 that instance information is unavailable, not meaningful, or not relevant.\r
86 Valid instance numbers start with 1.\r
87 @param CallerId This optional parameter may be used to identify the caller.\r
88 This parameter allows the status code driver to apply different rules to\r
89 different callers.\r
90 @param Data This optional parameter may be used to pass additional data.\r
91\r
92 @retval EFI_SUCCESS The function always return EFI_SUCCESS.\r
93\r
94**/\r
95EFI_STATUS\r
96MemoryStatusCodeReportWorker (\r
97 IN CONST EFI_PEI_SERVICES **PeiServices,\r
98 IN EFI_STATUS_CODE_TYPE CodeType,\r
99 IN EFI_STATUS_CODE_VALUE Value,\r
100 IN UINT32 Instance,\r
101 IN CONST EFI_GUID *CallerId,\r
102 IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL\r
103 )\r
104{\r
105\r
106 EFI_PEI_HOB_POINTERS Hob;\r
107 MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader;\r
108 MEMORY_STATUSCODE_RECORD *Record;\r
109 UINT16 PacketIndex;\r
110\r
111 Record = NULL;\r
112 PacketIndex = 0;\r
113\r
114 //\r
115 // Journal GUID'ed HOBs to find empty record entry. if found, then save status code in it.\r
116 // otherwise, create a new GUID'ed HOB.\r
117 //\r
118 Hob.Raw = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid);\r
119 while (Hob.Raw != NULL) {\r
120 PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid);\r
121\r
122 //\r
123 // Check whether pccket is full or not.\r
124 //\r
125 if (PacketHeader->RecordIndex < PacketHeader->MaxRecordsNumber) {\r
126 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);\r
127 Record = &Record[PacketHeader->RecordIndex++];\r
128 break;\r
129 }\r
130 //\r
131 // Cache number of found packet in PacketIndex.\r
132 //\r
133 PacketIndex++;\r
134\r
135 Hob.Raw = GetNextGuidHob (&gMemoryStatusCodeRecordGuid, Hob.Raw);\r
136 }\r
137\r
138 if (Record == NULL) {\r
139 //\r
140 // No available entry found, so create new packet.\r
141 //\r
142 PacketHeader = CreateMemoryStatusCodePacket (PacketIndex);\r
143\r
144 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);\r
145 Record = &Record[PacketHeader->RecordIndex++];\r
146 }\r
147\r
148 Record->CodeType = CodeType;\r
149 Record->Instance = Instance;\r
150 Record->Value = Value;\r
151\r
152 return EFI_SUCCESS;\r
153}\r