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