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 "StatusCodeHandlerPei.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
MemoryStatusCodeInitializeWorker(VOID)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  PeiServices      An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
57   @param  CodeType         Indicates the type of status code being reported.
58   @param  Value            Describes the current status of a hardware or
59                            software entity. This includes information about the class and
60                            subclass that is used to classify the entity as well as an operation.
61                            For progress codes, the operation is the current activity.
62                            For error codes, it is the exception.For debug codes,it is not defined at this time.
63   @param  Instance         The enumeration of a hardware or software entity within
64                            the system. A system may contain multiple entities that match a class/subclass
65                            pairing. The instance differentiates between them. An instance of 0 indicates
66                            that instance information is unavailable, not meaningful, or not relevant.
67                            Valid instance numbers start with 1.
68   @param  CallerId         This optional parameter may be used to identify the caller.
69                            This parameter allows the status code driver to apply different rules to
70                            different callers.
71   @param  Data             This optional parameter may be used to pass additional data.
72 
73   @retval EFI_SUCCESS      The function always return EFI_SUCCESS.
74 
75 **/
76 EFI_STATUS
77 EFIAPI
MemoryStatusCodeReportWorker(IN CONST EFI_PEI_SERVICES ** PeiServices,IN EFI_STATUS_CODE_TYPE CodeType,IN EFI_STATUS_CODE_VALUE Value,IN UINT32 Instance,IN CONST EFI_GUID * CallerId,IN CONST EFI_STATUS_CODE_DATA * Data OPTIONAL)78 MemoryStatusCodeReportWorker (
79   IN CONST  EFI_PEI_SERVICES    **PeiServices,
80   IN EFI_STATUS_CODE_TYPE       CodeType,
81   IN EFI_STATUS_CODE_VALUE      Value,
82   IN UINT32                     Instance,
83   IN CONST EFI_GUID             *CallerId,
84   IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
85   )
86 {
87 
88   EFI_PEI_HOB_POINTERS              Hob;
89   MEMORY_STATUSCODE_PACKET_HEADER   *PacketHeader;
90   MEMORY_STATUSCODE_RECORD          *Record;
91 
92   //
93   // Find GUID'ed HOBs to locate current record buffer.
94   //
95   Hob.Raw = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid);
96   ASSERT (Hob.Raw != NULL);
97 
98   PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid);
99   Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);
100   Record = &Record[PacketHeader->RecordIndex++];
101 
102   //
103   // Save status code.
104   //
105   Record->CodeType = CodeType;
106   Record->Instance = Instance;
107   Record->Value    = Value;
108 
109   //
110   // If record index equals to max record number, then wrap around record index to zero.
111   //
112   // The reader of status code should compare the number of records with max records number,
113   // If it is equal to or larger than the max number, then the wrap-around had happened,
114   // so the first record is pointed by record index.
115   // If it is less then max number, index of the first record is zero.
116   //
117   if (PacketHeader->RecordIndex == PacketHeader->MaxRecordsNumber) {
118     //
119     // Wrap around record index.
120     //
121     PacketHeader->RecordIndex = 0;
122     PacketHeader->PacketIndex ++;
123   }
124 
125   return EFI_SUCCESS;
126 }
127 
128