]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c
Use Memory Allocation Library instance for modules of type DXE_SMM_DRIVER
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / Smm / MemoryStatusCodeWorker.c
CommitLineData
3af9b388 1/** @file\r
2 Runtime memory status code worker.\r
3\r
4 Copyright (c) 2006 - 2009, Intel Corporation \r
5 All rights reserved. This program and the accompanying materials \r
6 are licensed and made available under the terms and conditions of the BSD License \r
7 which accompanies this distribution. The full text of the license may be found at \r
8 http://opensource.org/licenses/bsd-license.php \r
9 \r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13**/\r
14\r
15#include "StatusCodeHandlerSmm.h"\r
16\r
17RUNTIME_MEMORY_STATUSCODE_HEADER *mSmmMemoryStatusCodeTable;\r
18\r
19/**\r
20 Initialize SMM memory status code table as initialization for memory status code worker\r
21 \r
22 @retval EFI_SUCCESS SMM memory status code table successfully initialized.\r
23\r
24**/\r
25EFI_STATUS\r
26MemoryStatusCodeInitializeWorker (\r
27 VOID\r
28 )\r
29{\r
30 EFI_STATUS Status;\r
31 //\r
32 // Allocate SMM memory status code pool.\r
33 //\r
34 Status = gSmst->SmmAllocatePool (\r
35 EfiRuntimeServicesData,\r
36 sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) + PcdGet16 (PcdStatusCodeMemorySize) * 1024,\r
37 (VOID**)&mSmmMemoryStatusCodeTable\r
38 );\r
39\r
40 ASSERT_EFI_ERROR(Status);\r
41 ASSERT (mSmmMemoryStatusCodeTable != NULL);\r
42\r
43 mSmmMemoryStatusCodeTable->RecordIndex = 0;\r
44 mSmmMemoryStatusCodeTable->NumberOfRecords = 0;\r
45 mSmmMemoryStatusCodeTable->MaxRecordsNumber = \r
46 (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);\r
47\r
48 return EFI_SUCCESS;\r
49}\r
50\r
51\r
52/**\r
53 Report status code into runtime memory. If the runtime pool is full, roll back to the \r
54 first record and overwrite it.\r
55 \r
56 @param CodeType Indicates the type of status code being reported.\r
57 @param Value Describes the current status of a hardware or software entity.\r
58 This included information about the class and subclass that is used to\r
59 classify the entity as well as an operation.\r
60 @param Instance The enumeration of a hardware or software entity within\r
61 the system. Valid instance numbers start with 1.\r
62 @param CallerId This optional parameter may be used to identify the caller.\r
63 This parameter allows the status code driver to apply different rules to\r
64 different callers.\r
65 @param Data This optional parameter may be used to pass additional data.\r
66 \r
67 @retval EFI_SUCCESS Status code successfully recorded in runtime memory status code table.\r
68\r
69**/\r
70EFI_STATUS\r
71MemoryStatusCodeReportWorker (\r
72 IN EFI_STATUS_CODE_TYPE CodeType,\r
73 IN EFI_STATUS_CODE_VALUE Value,\r
74 IN UINT32 Instance,\r
75 IN EFI_GUID *CallerId,\r
76 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
77 )\r
78{\r
79 MEMORY_STATUSCODE_RECORD *Record;\r
80\r
81 //\r
82 // Locate current record buffer.\r
83 //\r
84 Record = (MEMORY_STATUSCODE_RECORD *) (mSmmMemoryStatusCodeTable + 1);\r
85 Record = &Record[mSmmMemoryStatusCodeTable->RecordIndex++];\r
86\r
87 //\r
88 // Save status code.\r
89 //\r
90 Record->CodeType = CodeType;\r
91 Record->Value = Value;\r
92 Record->Instance = Instance;\r
93\r
94 //\r
95 // If record index equals to max record number, then wrap around record index to zero.\r
96 //\r
97 // The reader of status code should compare the number of records with max records number,\r
98 // If it is equal to or larger than the max number, then the wrap-around had happened,\r
99 // so the first record is pointed by record index.\r
100 // If it is less then max number, index of the first record is zero.\r
101 //\r
102 mSmmMemoryStatusCodeTable->NumberOfRecords++;\r
103 if (mSmmMemoryStatusCodeTable->RecordIndex == mSmmMemoryStatusCodeTable->MaxRecordsNumber) {\r
104 //\r
105 // Wrap around record index.\r
106 //\r
107 mSmmMemoryStatusCodeTable->RecordIndex = 0;\r
108 }\r
109\r
110 return EFI_SUCCESS;\r
111}\r
112\r
113\r
114\r