]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/StatusCodeHandler/Pei/MemoryStausCodeWorker.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / Pei / MemoryStausCodeWorker.c
1 /** @file
2 PEI memory status code worker.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "StatusCodeHandlerPei.h"
10
11 /**
12 Create the first memory status code GUID'ed HOB as initialization for memory status code worker.
13
14 @retval EFI_SUCCESS The GUID'ed HOB is created successfully.
15
16 **/
17 EFI_STATUS
18 MemoryStatusCodeInitializeWorker (
19 VOID
20 )
21 {
22 //
23 // Create memory status code GUID'ed HOB.
24 //
25 MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader;
26
27 //
28 // Build GUID'ed HOB with PCD defined size.
29 //
30 PacketHeader = BuildGuidHob (
31 &gMemoryStatusCodeRecordGuid,
32 PcdGet16 (PcdStatusCodeMemorySize) * 1024 + sizeof (MEMORY_STATUSCODE_PACKET_HEADER)
33 );
34 ASSERT (PacketHeader != NULL);
35
36 PacketHeader->MaxRecordsNumber = (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);
37 PacketHeader->PacketIndex = 0;
38 PacketHeader->RecordIndex = 0;
39
40 return EFI_SUCCESS;
41 }
42
43
44 /**
45 Report status code into GUID'ed HOB.
46
47 This function reports status code into GUID'ed HOB. If not all packets are full, then
48 write status code into available entry. Otherwise, create a new packet for it.
49
50 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
51 @param CodeType Indicates the type of status code being reported.
52 @param Value Describes the current status of a hardware or
53 software entity. This includes information about the class and
54 subclass that is used to classify the entity as well as an operation.
55 For progress codes, the operation is the current activity.
56 For error codes, it is the exception.For debug codes,it is not defined at this time.
57 @param Instance The enumeration of a hardware or software entity within
58 the system. A system may contain multiple entities that match a class/subclass
59 pairing. The instance differentiates between them. An instance of 0 indicates
60 that instance information is unavailable, not meaningful, or not relevant.
61 Valid instance numbers start with 1.
62 @param CallerId This optional parameter may be used to identify the caller.
63 This parameter allows the status code driver to apply different rules to
64 different callers.
65 @param Data This optional parameter may be used to pass additional data.
66
67 @retval EFI_SUCCESS The function always return EFI_SUCCESS.
68
69 **/
70 EFI_STATUS
71 EFIAPI
72 MemoryStatusCodeReportWorker (
73 IN CONST EFI_PEI_SERVICES **PeiServices,
74 IN EFI_STATUS_CODE_TYPE CodeType,
75 IN EFI_STATUS_CODE_VALUE Value,
76 IN UINT32 Instance,
77 IN CONST EFI_GUID *CallerId,
78 IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
79 )
80 {
81
82 EFI_PEI_HOB_POINTERS Hob;
83 MEMORY_STATUSCODE_PACKET_HEADER *PacketHeader;
84 MEMORY_STATUSCODE_RECORD *Record;
85
86 //
87 // Find GUID'ed HOBs to locate current record buffer.
88 //
89 Hob.Raw = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid);
90 ASSERT (Hob.Raw != NULL);
91
92 PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid);
93 Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);
94 Record = &Record[PacketHeader->RecordIndex++];
95
96 //
97 // Save status code.
98 //
99 Record->CodeType = CodeType;
100 Record->Instance = Instance;
101 Record->Value = Value;
102
103 //
104 // If record index equals to max record number, then wrap around record index to zero.
105 //
106 // The reader of status code should compare the number of records with max records number,
107 // If it is equal to or larger than the max number, then the wrap-around had happened,
108 // so the first record is pointed by record index.
109 // If it is less then max number, index of the first record is zero.
110 //
111 if (PacketHeader->RecordIndex == PacketHeader->MaxRecordsNumber) {
112 //
113 // Wrap around record index.
114 //
115 PacketHeader->RecordIndex = 0;
116 PacketHeader->PacketIndex ++;
117 }
118
119 return EFI_SUCCESS;
120 }
121