]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c
Move Status Code Handler modules for PI implementation to MdeModulePkg.
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / Smm / MemoryStatusCodeWorker.c
1 /** @file
2 Runtime memory status code worker.
3
4 Copyright (c) 2006 - 2009, Intel Corporation
5 All rights reserved. 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 "StatusCodeHandlerSmm.h"
16
17 RUNTIME_MEMORY_STATUSCODE_HEADER *mSmmMemoryStatusCodeTable;
18
19 /**
20 Initialize SMM memory status code table as initialization for memory status code worker
21
22 @retval EFI_SUCCESS SMM memory status code table successfully initialized.
23
24 **/
25 EFI_STATUS
26 MemoryStatusCodeInitializeWorker (
27 VOID
28 )
29 {
30 EFI_STATUS Status;
31 //
32 // Allocate SMM memory status code pool.
33 //
34 Status = gSmst->SmmAllocatePool (
35 EfiRuntimeServicesData,
36 sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) + PcdGet16 (PcdStatusCodeMemorySize) * 1024,
37 (VOID**)&mSmmMemoryStatusCodeTable
38 );
39
40 ASSERT_EFI_ERROR(Status);
41 ASSERT (mSmmMemoryStatusCodeTable != NULL);
42
43 mSmmMemoryStatusCodeTable->RecordIndex = 0;
44 mSmmMemoryStatusCodeTable->NumberOfRecords = 0;
45 mSmmMemoryStatusCodeTable->MaxRecordsNumber =
46 (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);
47
48 return EFI_SUCCESS;
49 }
50
51
52 /**
53 Report status code into runtime memory. If the runtime pool is full, roll back to the
54 first record and overwrite it.
55
56 @param CodeType Indicates the type of status code being reported.
57 @param Value Describes the current status of a hardware or software entity.
58 This included information about the class and subclass that is used to
59 classify the entity as well as an operation.
60 @param Instance The enumeration of a hardware or software entity within
61 the system. 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 Status code successfully recorded in runtime memory status code table.
68
69 **/
70 EFI_STATUS
71 MemoryStatusCodeReportWorker (
72 IN EFI_STATUS_CODE_TYPE CodeType,
73 IN EFI_STATUS_CODE_VALUE Value,
74 IN UINT32 Instance,
75 IN EFI_GUID *CallerId,
76 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
77 )
78 {
79 MEMORY_STATUSCODE_RECORD *Record;
80
81 //
82 // Locate current record buffer.
83 //
84 Record = (MEMORY_STATUSCODE_RECORD *) (mSmmMemoryStatusCodeTable + 1);
85 Record = &Record[mSmmMemoryStatusCodeTable->RecordIndex++];
86
87 //
88 // Save status code.
89 //
90 Record->CodeType = CodeType;
91 Record->Value = Value;
92 Record->Instance = Instance;
93
94 //
95 // If record index equals to max record number, then wrap around record index to zero.
96 //
97 // The reader of status code should compare the number of records with max records number,
98 // If it is equal to or larger than the max number, then the wrap-around had happened,
99 // so the first record is pointed by record index.
100 // If it is less then max number, index of the first record is zero.
101 //
102 mSmmMemoryStatusCodeTable->NumberOfRecords++;
103 if (mSmmMemoryStatusCodeTable->RecordIndex == mSmmMemoryStatusCodeTable->MaxRecordsNumber) {
104 //
105 // Wrap around record index.
106 //
107 mSmmMemoryStatusCodeTable->RecordIndex = 0;
108 }
109
110 return EFI_SUCCESS;
111 }
112
113
114