]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/StatusCode/Pei/MemoryStausCodeWorker.c
1) Check in Pei/Dxe status code;
[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. All rights reserved.
5 This software and associated documentation (if any) is furnished
6 under a license and may only be used or copied in accordance
7 with the terms of the license. Except as permitted by such
8 license, no part of this software or documentation may be
9 reproduced, stored in a retrieval system, or transmitted in any
10 form or by any means without the express written consent of
11 Intel Corporation.
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 The function always return EFI_SUCCESS
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) * 1024) + sizeof (MEMORY_STATUSCODE_PACKET_HEADER));
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
51 /**
52 Initialize memory status code.
53 Create one GUID'ed HOB with PCD defined size. If create required size
54 GUID'ed HOB failed, then ASSERT().
55
56 @return The function always return EFI_SUCCESS
57
58 **/
59 EFI_STATUS
60 MemoryStatusCodeInitializeWorker (
61 VOID
62 )
63 {
64 //
65 // Create first memory status code GUID'ed HOB.
66 //
67 CreateMemoryStatusCodePacket (0);
68
69 return EFI_SUCCESS;
70 }
71
72
73 /**
74 Report status code into GUID'ed HOB..
75
76 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions¡± below.
77
78 @param Value Describes the current status of a hardware or software entity.
79 This included information about the class and subclass that is used to classify the entity
80 as well as an operation. 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 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
83 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
84
85 @param Instance The enumeration of a hardware or software entity within the system.
86 A system may contain multiple entities that match a class/subclass pairing.
87 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
88 not meaningful, or not relevant. Valid instance numbers start with 1.
89
90 @return The function always return EFI_SUCCESS.
91
92 **/
93 EFI_STATUS
94 MemoryStatusCodeReportWorker (
95 IN EFI_STATUS_CODE_TYPE CodeType,
96 IN EFI_STATUS_CODE_VALUE Value,
97 IN UINT32 Instance
98 )
99 {
100
101 EFI_PEI_HOB_POINTERS Hob;
102 MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader;
103 MEMORY_STATUSCODE_RECORD *Record = NULL;
104 UINT16 PacketIndex = 0;;
105
106 //
107 // Journal GUID'ed HOBs to find empty record entry, if found, then save status code in it.
108 // otherwise, create a new GUID'ed HOB.
109 //
110 Hob.Raw = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid);
111 while (Hob.Raw != NULL) {
112 PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid);
113
114 //
115 // Check whether pccket is full or not.
116 //
117 if (PacketHeader->RecordIndex < PacketHeader->MaxRecordsNumber) {
118 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);
119 Record = &Record[PacketHeader->RecordIndex++];
120 break;
121 }
122 //
123 // Cache number of found packet in PacketIndex.
124 //
125 PacketIndex++;
126
127 Hob.Raw = GetNextGuidHob (&gMemoryStatusCodeRecordGuid, Hob.Raw);
128 }
129
130 if (NULL == Record) {
131 //
132 // In order to save status code , create new packet.
133 //
134 PacketHeader = CreateMemoryStatusCodePacket (PacketIndex);
135
136 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);
137 Record = &Record[PacketHeader->RecordIndex++];
138 }
139
140 Record->CodeType = CodeType;
141 Record->Instance = Instance;
142 Record->Value = Value;
143
144 return EFI_SUCCESS;
145 }