]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/StatusCode/Pei/MemoryStausCodeWorker.c
FatPkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / Pei / MemoryStausCodeWorker.c
1 /** @file
2 PEI memory status code worker.
3
4 Copyright (c) 2006 - 2010, 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 "StatusCodePei.h"
16
17 /**
18 Create the first memory status code GUID'ed HOB as initialization for memory status code worker.
19
20 @retval EFI_SUCCESS The GUID'ed HOB is created successfully.
21
22 **/
23 EFI_STATUS
24 MemoryStatusCodeInitializeWorker (
25 VOID
26 )
27 {
28 //
29 // Create memory status code GUID'ed HOB.
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 = 0;
44 PacketHeader->RecordIndex = 0;
45
46 return EFI_SUCCESS;
47 }
48
49
50 /**
51 Report status code into GUID'ed HOB.
52
53 This function reports status code into GUID'ed HOB. If not all packets are full, then
54 write status code into available entry. Otherwise, create a new packet for it.
55
56 @param CodeType Indicates the type of status code being reported.
57 @param Value Describes the current status of a hardware or
58 software entity. This includes information about the class and
59 subclass that is used to classify the entity as well as an operation.
60 For progress codes, the operation is the current activity.
61 For error codes, it is the exception.For debug codes,it is not defined at this time.
62 @param Instance The enumeration of a hardware or software entity within
63 the system. A system may contain multiple entities that match a class/subclass
64 pairing. The instance differentiates between them. An instance of 0 indicates
65 that instance information is unavailable, not meaningful, or not relevant.
66 Valid instance numbers start with 1.
67
68 @retval EFI_SUCCESS The function always return EFI_SUCCESS.
69
70 **/
71 EFI_STATUS
72 MemoryStatusCodeReportWorker (
73 IN EFI_STATUS_CODE_TYPE CodeType,
74 IN EFI_STATUS_CODE_VALUE Value,
75 IN UINT32 Instance
76 )
77 {
78
79 EFI_PEI_HOB_POINTERS Hob;
80 MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader;
81 MEMORY_STATUSCODE_RECORD *Record;
82
83 //
84 // Find GUID'ed HOBs to locate current record buffer.
85 //
86 Hob.Raw = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid);
87 ASSERT (Hob.Raw != NULL);
88
89 PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid);
90 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);
91 Record = &Record[PacketHeader->RecordIndex++];
92
93 //
94 // Save status code.
95 //
96 Record->CodeType = CodeType;
97 Record->Instance = Instance;
98 Record->Value = Value;
99
100 //
101 // If record index equals to max record number, then wrap around record index to zero.
102 //
103 // The reader of status code should compare the number of records with max records number,
104 // If it is equal to or larger than the max number, then the wrap-around had happened,
105 // so the first record is pointed by record index.
106 // If it is less then max number, index of the first record is zero.
107 //
108 if (PacketHeader->RecordIndex == PacketHeader->MaxRecordsNumber) {
109 //
110 // Wrap around record index.
111 //
112 PacketHeader->RecordIndex = 0;
113 PacketHeader->PacketIndex ++;
114 }
115
116 return EFI_SUCCESS;
117 }
118