1 /**@file
2
3 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
4 Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
5 Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 Module Name:
15
16 SmbiosMiscEntryPoint.c
17
18 Abstract:
19
20 This driver parses the mSmbiosMiscDataTable structure and reports
21 any generated data using SMBIOS protocol.
22
23 Based on files under Nt32Pkg/MiscSubClassPlatformDxe/
24 **/
25
26 #include "SmbiosMisc.h"
27
28 #define MAX_HANDLE_COUNT 0x10
29
30 EFI_HANDLE mImageHandle;
31 EFI_HII_HANDLE mHiiHandle;
32 EFI_SMBIOS_PROTOCOL *mSmbios = NULL;
33
34 //
35 // Data Table Array
36 //
37 extern EFI_MISC_SMBIOS_DATA_TABLE mSmbiosMiscDataTable[];
38 //
39 // Data Table Array Entries
40 //
41 extern UINTN mSmbiosMiscDataTableEntries;
42
43 extern UINT8 SmbiosMiscDxeStrings[];
44
45
46
47 /**
48 Standard EFI driver point. This driver parses the mSmbiosMiscDataTable
49 structure and reports any generated data using SMBIOS protocol.
50
51 @param ImageHandle Handle for the image of this driver
52 @param SystemTable Pointer to the EFI System Table
53
54 @retval EFI_SUCCESS The data was successfully stored.
55
56 **/
57 EFI_STATUS
58 EFIAPI
SmbiosMiscEntryPoint(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)59 SmbiosMiscEntryPoint(
60 IN EFI_HANDLE ImageHandle,
61 IN EFI_SYSTEM_TABLE *SystemTable
62 )
63 {
64 UINTN Index;
65 EFI_STATUS EfiStatus;
66 EFI_SMBIOS_PROTOCOL *Smbios;
67
68 mImageHandle = ImageHandle;
69
70 EfiStatus = gBS->LocateProtocol(&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);
71 if (EFI_ERROR(EfiStatus))
72 {
73 DEBUG((EFI_D_ERROR, "Could not locate SMBIOS protocol. %r\n", EfiStatus));
74 return EfiStatus;
75 }
76
77 mSmbios = Smbios;
78
79 mHiiHandle = HiiAddPackages (
80 &gEfiCallerIdGuid,
81 mImageHandle,
82 SmbiosMiscDxeStrings,
83 NULL
84 );
85 if(mHiiHandle == NULL)
86 {
87 return EFI_OUT_OF_RESOURCES;
88 }
89
90 for (Index = 0; Index < mSmbiosMiscDataTableEntries; ++Index)
91 {
92 //
93 // If the entry have a function pointer, just log the data.
94 //
95 if (mSmbiosMiscDataTable[Index].Function != NULL)
96 {
97 EfiStatus = (*mSmbiosMiscDataTable[Index].Function)(
98 mSmbiosMiscDataTable[Index].RecordData,
99 Smbios
100 );
101
102 if (EFI_ERROR(EfiStatus))
103 {
104 DEBUG((EFI_D_ERROR, "Misc smbios store error. Index=%d, ReturnStatus=%r\n", Index, EfiStatus));
105 return EfiStatus;
106 }
107 }
108 }
109
110 return EfiStatus;
111 }
112
113
114 /**
115 Logs SMBIOS record.
116
117 @param Buffer The data for the fixed portion of the SMBIOS record. The format of the record is
118 determined by EFI_SMBIOS_TABLE_HEADER.Type. The size of the formatted area is defined
119 by EFI_SMBIOS_TABLE_HEADER.Length and either followed by a double-null (0x0000) or
120 a set of null terminated strings and a null.
121 @param SmbiosHandle A unique handle will be assigned to the SMBIOS record.
122
123 @retval EFI_SUCCESS Record was added.
124 @retval EFI_OUT_OF_RESOURCES Record was not added due to lack of system resources.
125
126 **/
127 EFI_STATUS
LogSmbiosData(IN UINT8 * Buffer,IN OUT EFI_SMBIOS_HANDLE * SmbiosHandle)128 LogSmbiosData (
129 IN UINT8 *Buffer,
130 IN OUT EFI_SMBIOS_HANDLE *SmbiosHandle
131 )
132 {
133 EFI_STATUS Status;
134
135 *SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
136
137 Status = mSmbios->Add (
138 mSmbios,
139 NULL,
140 SmbiosHandle,
141 (EFI_SMBIOS_TABLE_HEADER *)Buffer
142 );
143
144 return Status;
145 }
146
147
148 VOID
GetLinkTypeHandle(IN UINT8 SmbiosType,OUT UINT16 ** HandleArray,OUT UINTN * HandleCount)149 GetLinkTypeHandle(
150 IN UINT8 SmbiosType,
151 OUT UINT16 **HandleArray,
152 OUT UINTN *HandleCount
153 )
154 {
155 EFI_STATUS Status;
156 EFI_SMBIOS_HANDLE SmbiosHandle;
157 EFI_SMBIOS_TABLE_HEADER *LinkTypeData = NULL;
158
159 if(mSmbios == NULL)
160 return ;
161
162 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
163
164 *HandleArray = AllocateZeroPool(sizeof(UINT16) * MAX_HANDLE_COUNT);
165 if (*HandleArray == NULL)
166 {
167 DEBUG ((EFI_D_INFO, "HandleArray allocate memory resource failed.\n"));
168 return;
169 }
170
171 *HandleCount = 0;
172
173 while(1)
174 {
175 Status = mSmbios->GetNext(
176 mSmbios,
177 &SmbiosHandle,
178 &SmbiosType,
179 &LinkTypeData,
180 NULL
181 );
182
183 if(!EFI_ERROR(Status))
184 {
185 (*HandleArray)[*HandleCount] = LinkTypeData->Handle;
186 (*HandleCount)++;
187 }
188 else
189 {
190 break;
191 }
192 }
193 }
194
195