]>
Commit | Line | Data |
---|---|---|
dc361cc5 | 1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2007, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | PxeBcSupport.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Support routines for PxeBc\r | |
19 | \r | |
20 | \r | |
21 | **/\r | |
22 | \r | |
23 | \r | |
24 | #include "PxeBcImpl.h"\r | |
25 | \r | |
26 | \r | |
27 | /**\r | |
28 | \r | |
29 | @param Smbios Pointer to SMBIOS structure\r | |
30 | @param StringNumber String number to return. 0 is used to skip all\r | |
31 | strings and point to the next SMBIOS structure.\r | |
32 | \r | |
33 | @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == 0\r | |
34 | \r | |
35 | **/\r | |
36 | // GC_NOTO: function comment is missing 'Routine Description:'\r | |
37 | CHAR8 *\r | |
38 | GetSmbiosString (\r | |
39 | IN SMBIOS_STRUCTURE_POINTER *Smbios,\r | |
40 | IN UINT16 StringNumber\r | |
41 | )\r | |
42 | {\r | |
43 | UINT16 Index;\r | |
44 | CHAR8 *String;\r | |
45 | \r | |
46 | //\r | |
47 | // Skip over formatted section\r | |
48 | //\r | |
49 | String = (CHAR8 *) (Smbios->Raw + Smbios->Hdr->Length);\r | |
50 | \r | |
51 | //\r | |
52 | // Look through unformated section\r | |
53 | //\r | |
54 | for (Index = 1; Index <= StringNumber || StringNumber == 0; Index++) {\r | |
55 | if (StringNumber == Index) {\r | |
56 | return String;\r | |
57 | }\r | |
58 | //\r | |
59 | // Skip string\r | |
60 | //\r | |
61 | for (; *String != 0; String++)\r | |
62 | ;\r | |
63 | String++;\r | |
64 | \r | |
65 | if (*String == 0) {\r | |
66 | //\r | |
67 | // If double NULL then we are done.\r | |
68 | // Return pointer to next structure in Smbios.\r | |
69 | // if you pass in a 0 you will always get here\r | |
70 | //\r | |
71 | Smbios->Raw = (UINT8 *)++String;\r | |
72 | return NULL;\r | |
73 | }\r | |
74 | }\r | |
75 | \r | |
76 | return NULL;\r | |
77 | }\r | |
78 | \r | |
79 | \r | |
80 | /**\r | |
81 | This function gets system guid and serial number from the smbios table\r | |
82 | \r | |
83 | @param SystemGuid The pointer of returned system guid\r | |
84 | @param SystemSerialNumber The pointer of returned system serial number\r | |
85 | \r | |
86 | @retval EFI_SUCCESS Successfully get the system guid and system serial\r | |
87 | number\r | |
88 | @retval EFI_NOT_FOUND Not find the SMBIOS table\r | |
89 | \r | |
90 | **/\r | |
91 | EFI_STATUS\r | |
92 | GetSmbiosSystemGuidAndSerialNumber (\r | |
93 | IN EFI_GUID *SystemGuid,\r | |
94 | OUT CHAR8 **SystemSerialNumber\r | |
95 | )\r | |
96 | {\r | |
97 | EFI_STATUS Status;\r | |
98 | SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;\r | |
99 | SMBIOS_STRUCTURE_POINTER Smbios;\r | |
100 | SMBIOS_STRUCTURE_POINTER SmbiosEnd;\r | |
101 | UINT16 Index;\r | |
102 | \r | |
103 | Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &SmbiosTable);\r | |
104 | \r | |
105 | if (EFI_ERROR (Status)) {\r | |
106 | return EFI_NOT_FOUND;\r | |
107 | }\r | |
108 | \r | |
109 | Smbios.Hdr = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress;\r | |
110 | SmbiosEnd.Raw = (UINT8 *) (UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength);\r | |
111 | \r | |
112 | for (Index = 0; Index < SmbiosTable->TableLength; Index++) {\r | |
113 | if (Smbios.Hdr->Type == 1) {\r | |
114 | if (Smbios.Hdr->Length < 0x19) {\r | |
115 | //\r | |
116 | // Older version did not support Guid and Serial number\r | |
117 | //\r | |
118 | continue;\r | |
119 | }\r | |
120 | //\r | |
121 | // SMBIOS tables are byte packed so we need to do a byte copy to\r | |
122 | // prevend alignment faults on Itanium-based platform.\r | |
123 | //\r | |
124 | CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof (EFI_GUID));\r | |
125 | *SystemSerialNumber = GetSmbiosString (&Smbios, Smbios.Type1->SerialNumber);\r | |
126 | \r | |
127 | return EFI_SUCCESS;\r | |
128 | }\r | |
129 | //\r | |
130 | // Make Smbios point to the next record\r | |
131 | //\r | |
132 | GetSmbiosString (&Smbios, 0);\r | |
133 | \r | |
134 | if (Smbios.Raw >= SmbiosEnd.Raw) {\r | |
135 | //\r | |
136 | // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e.\r | |
137 | // given this we must double check against the length of the structure.\r | |
138 | //\r | |
139 | return EFI_SUCCESS;\r | |
140 | }\r | |
141 | }\r | |
142 | \r | |
143 | return EFI_SUCCESS;\r | |
144 | }\r | |
145 | \r | |
146 | \r | |
147 | /**\r | |
148 | GC_NOTO: Add function description\r | |
149 | \r | |
150 | @param Event GC_NOTO: add argument description\r | |
151 | @param Context GC_NOTO: add argument description\r | |
152 | \r | |
153 | @return GC_NOTO: add return values\r | |
154 | \r | |
155 | **/\r | |
156 | VOID\r | |
157 | PxeBcCommonNotify (\r | |
158 | IN EFI_EVENT Event,\r | |
159 | IN VOID *Context\r | |
160 | )\r | |
161 | {\r | |
162 | *((BOOLEAN *) Context) = TRUE;\r | |
163 | }\r | |
164 | \r | |
165 | \r | |
166 | /**\r | |
167 | Convert number to ASCII value\r | |
168 | \r | |
169 | @param Number Numeric value to convert to decimal ASCII value.\r | |
170 | @param Buffer Buffer to place ASCII version of the Number\r | |
171 | @param Length Length of Buffer.\r | |
172 | \r | |
173 | @retval none none\r | |
174 | \r | |
175 | **/\r | |
176 | VOID\r | |
177 | CvtNum (\r | |
178 | IN UINTN Number,\r | |
179 | IN UINT8 *Buffer,\r | |
180 | IN INTN Length\r | |
181 | )\r | |
182 | {\r | |
183 | UINTN Remainder;\r | |
184 | \r | |
185 | while (Length--) {\r | |
186 | Remainder = Number % 10;\r | |
187 | Number /= 10;\r | |
188 | Buffer[Length] = (UINT8) ('0' + Remainder);\r | |
189 | }\r | |
190 | }\r | |
191 | \r | |
192 | \r | |
193 | /**\r | |
194 | GC_NOTO: Add function description\r | |
195 | \r | |
196 | @param Number GC_NOTO: add argument description\r | |
197 | @param Buffer GC_NOTO: add argument description\r | |
198 | \r | |
199 | @return GC_NOTO: add return values\r | |
200 | \r | |
201 | **/\r | |
202 | UINTN\r | |
203 | UtoA10 (\r | |
204 | IN UINTN Number,\r | |
205 | IN CHAR8 *Buffer\r | |
206 | )\r | |
207 | {\r | |
208 | UINTN Index;\r | |
209 | CHAR8 TempStr[64];\r | |
210 | \r | |
211 | Index = 63;\r | |
212 | TempStr[Index] = 0;\r | |
213 | \r | |
214 | do {\r | |
215 | Index--;\r | |
216 | TempStr[Index] = (CHAR8) ('0' + (Number % 10));\r | |
217 | Number = Number / 10;\r | |
218 | } while (Number != 0);\r | |
219 | \r | |
220 | AsciiStrCpy (Buffer, &TempStr[Index]);\r | |
221 | \r | |
222 | return AsciiStrLen (Buffer);\r | |
223 | }\r | |
224 | \r | |
225 | \r | |
226 | /**\r | |
227 | Convert ASCII numeric string to a UINTN value\r | |
228 | \r | |
229 | @param Number Numeric value to convert to decimal ASCII value.\r | |
230 | @param Buffer Buffer to place ASCII version of the Number\r | |
231 | \r | |
232 | @retval Value UINTN value of the ASCII string.\r | |
233 | \r | |
234 | **/\r | |
235 | UINT64\r | |
236 | AtoU64 (\r | |
237 | IN UINT8 *Buffer\r | |
238 | )\r | |
239 | {\r | |
240 | UINT64 Value;\r | |
241 | UINT8 Character;\r | |
242 | \r | |
243 | Value = 0;\r | |
244 | while ((Character = *Buffer++) != '\0') {\r | |
245 | Value = MultU64x32 (Value, 10) + (Character - '0');\r | |
246 | }\r | |
247 | \r | |
248 | return Value;\r | |
249 | }\r | |
250 | \r |