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