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