2 This code produces the Smbios protocol. It also responsible for constructing
3 SMBIOS table into system table.
5 Copyright (c) 2009 - 2010, Intel Corporation. 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
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.
16 #include "SmbiosDxe.h"
20 // Since this driver will only ever produce one instance of the
21 // protocol you are not required to dynamically allocate the PrivateData.
23 SMBIOS_INSTANCE mPrivateData
;
26 // Chassis for SMBIOS entry point structure that is to be installed into EFI system config table.
28 SMBIOS_TABLE_ENTRY_POINT
*EntryPointStructure
= NULL
;
29 SMBIOS_TABLE_ENTRY_POINT EntryPointStructureData
= {
40 // EntryPointStructureChecksum,TO BE FILLED
44 // EntryPointStructure Length
50 (UINT8
) (FixedPcdGet16 (PcdSmbiosVersion
) >> 8),
54 (UINT8
) (FixedPcdGet16 (PcdSmbiosVersion
) & 0x00ff),
56 // MaxStructureSize, TO BE FILLED
74 // IntermediateAnchorString
84 // IntermediateChecksum, TO BE FILLED
88 // StructureTableLength, TO BE FILLED
92 // StructureTableAddress, TO BE FILLED
96 // NumberOfSmbiosStructures, TO BE FILLED
108 Get the full size of smbios structure including optional strings that follow the formatted structure.
110 @param Head Pointer to the beginning of smbios structure.
111 @param Size The returned size.
112 @param NumberOfStrings The returned number of optional strings that follow the formatted structure.
114 @retval EFI_SUCCESS Size retured in Size.
115 @retval EFI_INVALID_PARAMETER Input smbios structure mal-formed or Size is NULL.
120 GetSmbiosStructureSize (
121 IN EFI_SMBIOS_TABLE_HEADER
*Head
,
123 OUT UINTN
*NumberOfStrings
130 if (Size
== NULL
|| NumberOfStrings
== NULL
) {
131 return EFI_INVALID_PARAMETER
;
134 FullSize
= Head
->Length
;
135 CharInStr
= (INT8
*)Head
+ Head
->Length
;
137 *NumberOfStrings
= 0;
140 // look for the two consecutive zeros, check the string limit by the way.
142 while (*CharInStr
!= 0 || *(CharInStr
+1) != 0) {
143 if (*CharInStr
== 0) {
148 for (StrLen
= 0 ; StrLen
< SMBIOS_STRING_MAX_LENGTH
; StrLen
++) {
149 if (*(CharInStr
+StrLen
) == 0) {
154 if (StrLen
== SMBIOS_STRING_MAX_LENGTH
) {
155 return EFI_INVALID_PARAMETER
;
158 // forward the pointer
162 *NumberOfStrings
+= 1;
166 // count ending two zeros.
174 Determin whether an SmbiosHandle has already in use.
176 @param Head Pointer to the beginning of smbios structure.
177 @param Handle A unique handle will be assigned to the SMBIOS record.
179 @retval TRUE Smbios handle already in use.
180 @retval FALSE Smbios handle is NOT used.
185 CheckSmbiosHandleExistance (
187 IN EFI_SMBIOS_HANDLE Handle
191 SMBIOS_HANDLE_ENTRY
*HandleEntry
;
193 for (Link
= Head
->ForwardLink
; Link
!= Head
; Link
= Link
->ForwardLink
) {
194 HandleEntry
= SMBIOS_HANDLE_ENTRY_FROM_LINK(Link
);
195 if (HandleEntry
->SmbiosHandle
== Handle
) {
205 Get the max SmbiosHandle that could be use.
207 @param This The EFI_SMBIOS_PROTOCOL instance.
208 @param MaxHandle The max handle that could be assigned to the SMBIOS record.
214 IN CONST EFI_SMBIOS_PROTOCOL
*This
,
215 IN OUT EFI_SMBIOS_HANDLE
*MaxHandle
218 if (This
->MajorVersion
== 2 && This
->MinorVersion
== 0) {
227 Get an SmbiosHandle that could use.
229 @param This The EFI_SMBIOS_PROTOCOL instance.
230 @param SmbiosHandle A unique handle will be assigned to the SMBIOS record.
232 @retval EFI_SUCCESS Smbios handle got.
233 @retval EFI_OUT_OF_RESOURCES Smbios handle is NOT available.
238 GetAvailableSmbiosHandle (
239 IN CONST EFI_SMBIOS_PROTOCOL
*This
,
240 IN OUT EFI_SMBIOS_HANDLE
*Handle
244 SMBIOS_INSTANCE
*Private
;
245 EFI_SMBIOS_HANDLE MaxSmbiosHandle
;
246 EFI_SMBIOS_HANDLE AvailableHandle
;
248 GetMaxSmbiosHandle(This
, &MaxSmbiosHandle
);
250 Private
= SMBIOS_INSTANCE_FROM_THIS (This
);
251 Head
= &Private
->AllocatedHandleListHead
;
252 for (AvailableHandle
= 1; AvailableHandle
< MaxSmbiosHandle
; AvailableHandle
++) {
253 if (!CheckSmbiosHandleExistance(Head
, AvailableHandle
)) {
254 *Handle
= AvailableHandle
;
259 return EFI_OUT_OF_RESOURCES
;
264 Add an SMBIOS record.
266 @param This The EFI_SMBIOS_PROTOCOL instance.
267 @param ProducerHandle The handle of the controller or driver associated with the SMBIOS information. NULL
269 @param SmbiosHandle On entry, if non-zero, the handle of the SMBIOS record. If zero, then a unique handle
270 will be assigned to the SMBIOS record. If the SMBIOS handle is already in use
271 EFI_ALREADY_STARTED is returned and the SMBIOS record is not updated.
272 @param Record The data for the fixed portion of the SMBIOS record. The format of the record is
273 determined by EFI_SMBIOS_TABLE_HEADER.Type. The size of the formatted area is defined
274 by EFI_SMBIOS_TABLE_HEADER.Length and either followed by a double-null (0x0000) or
275 a set of null terminated strings and a null.
277 @retval EFI_SUCCESS Record was added.
278 @retval EFI_OUT_OF_RESOURCES Record was not added due to lack of system resources.
279 @retval EFI_ALREADY_STARTED The SmbiosHandle passed in was already in use.
285 IN CONST EFI_SMBIOS_PROTOCOL
*This
,
286 IN EFI_HANDLE ProducerHandle
, OPTIONAL
287 IN OUT EFI_SMBIOS_HANDLE
*SmbiosHandle
,
288 IN EFI_SMBIOS_TABLE_HEADER
*Record
295 UINTN NumberOfStrings
;
298 SMBIOS_INSTANCE
*Private
;
299 EFI_SMBIOS_ENTRY
*SmbiosEntry
;
300 EFI_SMBIOS_HANDLE MaxSmbiosHandle
;
301 SMBIOS_HANDLE_ENTRY
*HandleEntry
;
302 EFI_SMBIOS_RECORD_HEADER
*InternalRecord
;
304 if (SmbiosHandle
== NULL
) {
305 return EFI_INVALID_PARAMETER
;
308 Private
= SMBIOS_INSTANCE_FROM_THIS (This
);
310 // Check whether SmbiosHandle is already in use
312 Head
= &Private
->AllocatedHandleListHead
;
313 if (*SmbiosHandle
!= 0 && CheckSmbiosHandleExistance(Head
, *SmbiosHandle
)) {
314 return EFI_ALREADY_STARTED
;
318 // when SmbiosHandle is zero, an available handle will be assigned
320 if (*SmbiosHandle
== 0) {
321 Status
= GetAvailableSmbiosHandle(This
, SmbiosHandle
);
322 if (EFI_ERROR(Status
)) {
327 // Check this handle validity
329 GetMaxSmbiosHandle(This
, &MaxSmbiosHandle
);
330 if (*SmbiosHandle
> MaxSmbiosHandle
) {
331 return EFI_INVALID_PARAMETER
;
336 // Calculate record size and string number
338 Status
= GetSmbiosStructureSize(Record
, &StructureSize
, &NumberOfStrings
);
339 if (EFI_ERROR(Status
)) {
344 // Enter into critical section
346 Status
= EfiAcquireLockOrFail (&Private
->DataLock
);
347 if (EFI_ERROR (Status
)) {
351 RecordSize
= sizeof (EFI_SMBIOS_RECORD_HEADER
) + StructureSize
;
352 TotalSize
= sizeof (EFI_SMBIOS_ENTRY
) + RecordSize
;
355 // Allocate internal buffer
357 SmbiosEntry
= AllocateZeroPool (TotalSize
);
358 if (SmbiosEntry
== NULL
) {
359 EfiReleaseLock (&Private
->DataLock
);
360 return EFI_OUT_OF_RESOURCES
;
362 HandleEntry
= AllocateZeroPool (sizeof(SMBIOS_HANDLE_ENTRY
));
363 if (HandleEntry
== NULL
) {
364 EfiReleaseLock (&Private
->DataLock
);
365 return EFI_OUT_OF_RESOURCES
;
369 // Build Handle Entry and insert into linked list
371 HandleEntry
->Signature
= SMBIOS_HANDLE_ENTRY_SIGNATURE
;
372 HandleEntry
->SmbiosHandle
= *SmbiosHandle
;
373 InsertTailList(&Private
->AllocatedHandleListHead
, &HandleEntry
->Link
);
375 InternalRecord
= (EFI_SMBIOS_RECORD_HEADER
*) (SmbiosEntry
+ 1);
376 Raw
= (VOID
*) (InternalRecord
+ 1);
379 // Build internal record Header
381 InternalRecord
->Version
= EFI_SMBIOS_RECORD_HEADER_VERSION
;
382 InternalRecord
->HeaderSize
= (UINT16
) sizeof (EFI_SMBIOS_RECORD_HEADER
);
383 InternalRecord
->RecordSize
= RecordSize
;
384 InternalRecord
->ProducerHandle
= ProducerHandle
;
385 InternalRecord
->NumberOfStrings
= NumberOfStrings
;
387 // Insert record into the internal linked list
389 SmbiosEntry
->Signature
= EFI_SMBIOS_ENTRY_SIGNATURE
;
390 SmbiosEntry
->RecordHeader
= InternalRecord
;
391 SmbiosEntry
->RecordSize
= TotalSize
;
392 InsertTailList (&Private
->DataListHead
, &SmbiosEntry
->Link
);
394 CopyMem (Raw
, Record
, StructureSize
);
395 ((EFI_SMBIOS_TABLE_HEADER
*)Raw
)->Handle
= *SmbiosHandle
;
398 // Leave critical section
400 EfiReleaseLock (&Private
->DataLock
);
405 Update the string associated with an existing SMBIOS record.
407 @param This The EFI_SMBIOS_PROTOCOL instance.
408 @param SmbiosHandle SMBIOS Handle of structure that will have its string updated.
409 @param StringNumber The non-zero string number of the string to update
410 @param String Update the StringNumber string with String.
412 @retval EFI_SUCCESS SmbiosHandle had its StringNumber String updated.
413 @retval EFI_INVALID_PARAMETER SmbiosHandle does not exist.
414 @retval EFI_UNSUPPORTED String was not added since it's longer than 64 significant characters.
415 @retval EFI_NOT_FOUND The StringNumber.is not valid for this SMBIOS record.
421 IN CONST EFI_SMBIOS_PROTOCOL
*This
,
422 IN EFI_SMBIOS_HANDLE
*SmbiosHandle
,
423 IN UINTN
*StringNumber
,
430 UINTN TargetStrOffset
;
437 SMBIOS_INSTANCE
*Private
;
438 EFI_SMBIOS_ENTRY
*SmbiosEntry
;
439 EFI_SMBIOS_ENTRY
*ResizedSmbiosEntry
;
440 EFI_SMBIOS_HANDLE MaxSmbiosHandle
;
441 EFI_SMBIOS_TABLE_HEADER
*Record
;
442 EFI_SMBIOS_RECORD_HEADER
*InternalRecord
;
445 // Check args validity
447 GetMaxSmbiosHandle(This
, &MaxSmbiosHandle
);
449 if (*SmbiosHandle
> MaxSmbiosHandle
) {
450 return EFI_INVALID_PARAMETER
;
453 if (String
== NULL
) {
457 if (*StringNumber
== 0) {
458 return EFI_NOT_FOUND
;
461 InputStrLen
= AsciiStrLen(String
);
462 if (InputStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
463 return EFI_UNSUPPORTED
;
466 Private
= SMBIOS_INSTANCE_FROM_THIS (This
);
468 // Enter into critical section
470 Status
= EfiAcquireLockOrFail (&Private
->DataLock
);
471 if (EFI_ERROR (Status
)) {
475 Head
= &Private
->DataListHead
;
476 for (Link
= Head
->ForwardLink
; Link
!= Head
; Link
= Link
->ForwardLink
) {
477 SmbiosEntry
= SMBIOS_ENTRY_FROM_LINK(Link
);
478 Record
= (EFI_SMBIOS_TABLE_HEADER
*)(SmbiosEntry
->RecordHeader
+ 1);
480 if ((UINTN
)Record
->Handle
== *SmbiosHandle
) {
482 // Find out the specified Smbios record
484 if (*StringNumber
> SmbiosEntry
->RecordHeader
->NumberOfStrings
) {
485 EfiReleaseLock (&Private
->DataLock
);
486 return EFI_NOT_FOUND
;
489 // Point to unformed string section
491 StrStart
= (CHAR8
*)Record
+ Record
->Length
;
493 for (StrIndex
= 1, TargetStrOffset
= 0; StrIndex
< *StringNumber
; StrStart
++, TargetStrOffset
++) {
495 // A string ends in 00h
497 if (*StrStart
== 0) {
502 // String section ends in double-null (0000h)
504 if (*StrStart
== 0 && *(StrStart
+ 1) == 0) {
505 EfiReleaseLock (&Private
->DataLock
);
506 return EFI_NOT_FOUND
;
510 if (*StrStart
== 0) {
516 // Now we get the string target
518 TargetStrLen
= AsciiStrLen(StrStart
);
519 if (InputStrLen
== TargetStrLen
) {
520 AsciiStrCpy(StrStart
, String
);
521 EfiReleaseLock (&Private
->DataLock
);
526 // Original string buffer size is not exactly match input string length.
527 // Re-allocate buffer is needed.
529 NewEntrySize
= SmbiosEntry
->RecordSize
+ InputStrLen
- TargetStrLen
;
530 ResizedSmbiosEntry
= AllocateZeroPool (NewEntrySize
);
532 if (ResizedSmbiosEntry
== NULL
) {
533 EfiReleaseLock (&Private
->DataLock
);
534 return EFI_OUT_OF_RESOURCES
;
537 InternalRecord
= (EFI_SMBIOS_RECORD_HEADER
*) (ResizedSmbiosEntry
+ 1);
538 Raw
= (VOID
*) (InternalRecord
+ 1);
541 // Build internal record Header
543 InternalRecord
->Version
= EFI_SMBIOS_RECORD_HEADER_VERSION
;
544 InternalRecord
->HeaderSize
= (UINT16
) sizeof (EFI_SMBIOS_RECORD_HEADER
);
545 InternalRecord
->RecordSize
= SmbiosEntry
->RecordHeader
->RecordSize
+ InputStrLen
- TargetStrLen
;
546 InternalRecord
->ProducerHandle
= SmbiosEntry
->RecordHeader
->ProducerHandle
;
547 InternalRecord
->NumberOfStrings
= SmbiosEntry
->RecordHeader
->NumberOfStrings
;
550 // Copy smbios structure and optional strings.
552 CopyMem (Raw
, SmbiosEntry
->RecordHeader
+ 1, Record
->Length
+ TargetStrOffset
);
553 CopyMem ((VOID
*)((UINTN
)Raw
+ Record
->Length
+ TargetStrOffset
), String
, InputStrLen
+ 1);
554 CopyMem ((CHAR8
*)((UINTN
)Raw
+ Record
->Length
+ TargetStrOffset
+ InputStrLen
+ 1),
555 (CHAR8
*)Record
+ Record
->Length
+ TargetStrOffset
+ TargetStrLen
+ 1,
556 SmbiosEntry
->RecordHeader
->RecordSize
- sizeof (EFI_SMBIOS_RECORD_HEADER
) - Record
->Length
- TargetStrOffset
- TargetStrLen
- 1);
561 ResizedSmbiosEntry
->Signature
= EFI_SMBIOS_ENTRY_SIGNATURE
;
562 ResizedSmbiosEntry
->RecordHeader
= InternalRecord
;
563 ResizedSmbiosEntry
->RecordSize
= NewEntrySize
;
564 InsertTailList (Link
->ForwardLink
, &ResizedSmbiosEntry
->Link
);
569 RemoveEntryList(Link
);
570 FreePool(SmbiosEntry
);
571 EfiReleaseLock (&Private
->DataLock
);
576 EfiReleaseLock (&Private
->DataLock
);
577 return EFI_INVALID_PARAMETER
;
581 Remove an SMBIOS record.
583 @param This The EFI_SMBIOS_PROTOCOL instance.
584 @param SmbiosHandle The handle of the SMBIOS record to remove.
586 @retval EFI_SUCCESS SMBIOS record was removed.
587 @retval EFI_INVALID_PARAMETER SmbiosHandle does not specify a valid SMBIOS record.
593 IN CONST EFI_SMBIOS_PROTOCOL
*This
,
594 IN EFI_SMBIOS_HANDLE SmbiosHandle
600 EFI_SMBIOS_HANDLE MaxSmbiosHandle
;
601 SMBIOS_INSTANCE
*Private
;
602 EFI_SMBIOS_ENTRY
*SmbiosEntry
;
603 SMBIOS_HANDLE_ENTRY
*HandleEntry
;
604 EFI_SMBIOS_TABLE_HEADER
*Record
;
607 // Check args validity
609 GetMaxSmbiosHandle(This
, &MaxSmbiosHandle
);
611 if (SmbiosHandle
> MaxSmbiosHandle
) {
612 return EFI_INVALID_PARAMETER
;
615 Private
= SMBIOS_INSTANCE_FROM_THIS (This
);
617 // Enter into critical section
619 Status
= EfiAcquireLockOrFail (&Private
->DataLock
);
620 if (EFI_ERROR (Status
)) {
624 Head
= &Private
->DataListHead
;
625 for (Link
= Head
->ForwardLink
; Link
!= Head
; Link
= Link
->ForwardLink
) {
626 SmbiosEntry
= SMBIOS_ENTRY_FROM_LINK(Link
);
627 Record
= (EFI_SMBIOS_TABLE_HEADER
*)(SmbiosEntry
->RecordHeader
+ 1);
628 if ((UINTN
)Record
->Handle
== SmbiosHandle
) {
630 // Remove specified smobios record from DataList
632 RemoveEntryList(Link
);
633 FreePool(SmbiosEntry
);
635 // Remove this handle from AllocatedHandleList
637 Head
= &Private
->AllocatedHandleListHead
;
638 for (Link
= Head
->ForwardLink
; Link
!= Head
; Link
= Link
->ForwardLink
) {
639 HandleEntry
= SMBIOS_HANDLE_ENTRY_FROM_LINK(Link
);
640 if ((UINTN
)HandleEntry
->SmbiosHandle
== SmbiosHandle
) {
641 RemoveEntryList(Link
);
642 FreePool(HandleEntry
);
646 EfiReleaseLock (&Private
->DataLock
);
652 // Leave critical section
654 EfiReleaseLock (&Private
->DataLock
);
655 return EFI_INVALID_PARAMETER
;
660 Allow the caller to discover all or some of the SMBIOS records.
662 @param This The EFI_SMBIOS_PROTOCOL instance.
663 @param SmbiosHandle On entry, points to the previous handle of the SMBIOS record. On exit, points to the
664 next SMBIOS record handle. If it is zero on entry, then the first SMBIOS record
665 handle will be returned. If it returns zero on exit, then there are no more SMBIOS records.
666 @param Type On entry it means return the next SMBIOS record of type Type. If a NULL is passed in
667 this functionally it ignored. Type is not modified by the GetNext() function.
668 @param Record On exit, points to the SMBIOS Record consisting of the formatted area followed by
669 the unformatted area. The unformatted area optionally contains text strings.
670 @param ProducerHandle On exit, points to the ProducerHandle registered by Add(). If no ProducerHandle was passed into Add() NULL is returned.
671 If a NULL pointer is passed in no data will be returned
673 @retval EFI_SUCCESS SMBIOS record information was successfully returned in Record.
674 SmbiosHandle is the handle of the current SMBIOS record
675 @retval EFI_NOT_FOUND The SMBIOS record with SmbiosHandle was the last available record.
681 IN CONST EFI_SMBIOS_PROTOCOL
*This
,
682 IN OUT EFI_SMBIOS_HANDLE
*SmbiosHandle
,
683 IN EFI_SMBIOS_TYPE
*Type
, OPTIONAL
684 OUT EFI_SMBIOS_TABLE_HEADER
**Record
,
685 OUT EFI_HANDLE
*ProducerHandle OPTIONAL
688 BOOLEAN StartPointFound
;
691 SMBIOS_INSTANCE
*Private
;
692 EFI_SMBIOS_ENTRY
*SmbiosEntry
;
693 EFI_SMBIOS_TABLE_HEADER
*SmbiosTableHeader
;
695 if (SmbiosHandle
== NULL
) {
696 return EFI_INVALID_PARAMETER
;
699 StartPointFound
= FALSE
;
700 Private
= SMBIOS_INSTANCE_FROM_THIS (This
);
701 Head
= &Private
->DataListHead
;
702 for (Link
= Head
->ForwardLink
; Link
!= Head
; Link
= Link
->ForwardLink
) {
703 SmbiosEntry
= SMBIOS_ENTRY_FROM_LINK(Link
);
704 SmbiosTableHeader
= (EFI_SMBIOS_TABLE_HEADER
*)(SmbiosEntry
->RecordHeader
+ 1);
707 // If SmbiosHandle is zero, the first matched SMBIOS record handle will be returned
709 if (*SmbiosHandle
== 0) {
710 if ((Type
!= NULL
) && (*Type
!= SmbiosTableHeader
->Type
)) {
714 *SmbiosHandle
= SmbiosTableHeader
->Handle
;
715 *Record
=SmbiosTableHeader
;
716 if (ProducerHandle
!= NULL
) {
717 *ProducerHandle
= SmbiosEntry
->RecordHeader
->ProducerHandle
;
723 // Start this round search from the next Smbios handle
725 if (!StartPointFound
&& (*SmbiosHandle
== SmbiosTableHeader
->Handle
)) {
726 StartPointFound
= TRUE
;
730 if (StartPointFound
) {
731 if ((Type
!= NULL
) && (*Type
!= SmbiosTableHeader
->Type
)) {
735 *SmbiosHandle
= SmbiosTableHeader
->Handle
;
736 *Record
= SmbiosTableHeader
;
737 if (ProducerHandle
!= NULL
) {
738 *ProducerHandle
= SmbiosEntry
->RecordHeader
->ProducerHandle
;
746 return EFI_NOT_FOUND
;
752 Assembles Smbios table from the SMBIOS protocol. Produce Table
753 Entry Point and return the pointer to it.
755 @param TableEntryPointStructure On exit, points to the SMBIOS entrypoint structure.
757 @retval EFI_SUCCESS Structure created sucessfully.
758 @retval EFI_NOT_READY Some of The SMBIOS records was not available yet.
759 @retval EFI_OUT_OF_RESOURCES No enough memory.
765 OUT VOID
**TableEntryPointStructure
769 UINT8
*BufferPointer
;
774 EFI_SMBIOS_HANDLE SmbiosHandle
;
775 EFI_SMBIOS_PROTOCOL
*SmbiosProtocol
;
776 EFI_PHYSICAL_ADDRESS PhysicalAddress
;
777 EFI_SMBIOS_TABLE_HEADER
*SmbiosRecord
;
778 EFI_SMBIOS_TABLE_END_STRUCTURE EndStructure
;
780 Status
= EFI_SUCCESS
;
781 BufferPointer
= NULL
;
785 // Initialize the EntryPointStructure with initial values.
787 if (EntryPointStructure
== NULL
) {
789 // Allocate memory (below 4GB)
791 PhysicalAddress
= 0xffffffff;
792 Status
= gBS
->AllocatePages (
794 EfiReservedMemoryType
,
795 EFI_SIZE_TO_PAGES (sizeof (SMBIOS_TABLE_ENTRY_POINT
)),
798 if (EFI_ERROR (Status
)) {
799 return EFI_OUT_OF_RESOURCES
;
802 EntryPointStructure
= (SMBIOS_TABLE_ENTRY_POINT
*) (UINTN
) PhysicalAddress
;
806 &EntryPointStructureData
,
807 sizeof (SMBIOS_TABLE_ENTRY_POINT
)
812 // Free the original image
814 if (EntryPointStructure
->TableAddress
!= 0) {
816 (VOID
*)(UINTN
)EntryPointStructure
->TableAddress
,
817 EFI_SIZE_TO_PAGES (EntryPointStructure
->TableLength
)
819 EntryPointStructure
->TableAddress
= 0;
823 // Locate smbios protocol to traverse smbios records.
825 Status
= gBS
->LocateProtocol (&gEfiSmbiosProtocolGuid
, NULL
, (VOID
**) &SmbiosProtocol
);
826 ASSERT_EFI_ERROR (Status
);
827 ASSERT (SmbiosProtocol
!= NULL
);
830 // Make some statistics about all the structures
832 EntryPointStructure
->NumberOfSmbiosStructures
= 0;
833 EntryPointStructure
->TableLength
= 0;
834 EntryPointStructure
->MaxStructureSize
= 0;
838 // Calculate EPS Table Length
841 Status
= SmbiosProtocol
->GetNext (
849 if (Status
== EFI_SUCCESS
) {
850 GetSmbiosStructureSize(SmbiosRecord
, &RecordSize
, &NumOfStr
);
852 // Record NumberOfSmbiosStructures, TableLength and MaxStructureSize
854 EntryPointStructure
->NumberOfSmbiosStructures
++;
855 EntryPointStructure
->TableLength
= (UINT16
) (EntryPointStructure
->TableLength
+ RecordSize
);
856 if (RecordSize
> EntryPointStructure
->MaxStructureSize
) {
857 EntryPointStructure
->MaxStructureSize
= (UINT16
) RecordSize
;
860 } while (!EFI_ERROR(Status
));
863 // Create End-Of-Table structure
865 GetMaxSmbiosHandle(SmbiosProtocol
, &SmbiosHandle
);
866 EndStructure
.Header
.Type
= EFI_SMBIOS_TYPE_END_OF_TABLE
;
867 EndStructure
.Header
.Length
= (UINT8
) sizeof (EFI_SMBIOS_TABLE_HEADER
);
868 EndStructure
.Header
.Handle
= SmbiosHandle
;
869 EndStructure
.Tailing
[0] = 0;
870 EndStructure
.Tailing
[1] = 0;
871 EntryPointStructure
->NumberOfSmbiosStructures
++;
872 EntryPointStructure
->TableLength
= (UINT16
) (EntryPointStructure
->TableLength
+ sizeof (EndStructure
));
873 if (sizeof (EndStructure
) > EntryPointStructure
->MaxStructureSize
) {
874 EntryPointStructure
->MaxStructureSize
= (UINT16
) sizeof (EndStructure
);
878 // Allocate memory (below 4GB)
880 PhysicalAddress
= 0xffffffff;
881 Status
= gBS
->AllocatePages (
883 EfiReservedMemoryType
,
884 EFI_SIZE_TO_PAGES (EntryPointStructure
->TableLength
),
887 if (EFI_ERROR (Status
)) {
888 FreePages ((VOID
*)(UINTN
)EntryPointStructure
, EFI_SIZE_TO_PAGES (EntryPointStructure
->TableLength
));
889 EntryPointStructure
= NULL
;
890 return EFI_OUT_OF_RESOURCES
;
893 EntryPointStructure
->TableAddress
= (UINT32
) PhysicalAddress
;
896 // Assemble the tables
898 BufferPointer
= (UINT8
*) (UINTN
) PhysicalAddress
;
901 Status
= SmbiosProtocol
->GetNext (
908 if (Status
== EFI_SUCCESS
) {
909 GetSmbiosStructureSize(SmbiosRecord
, &RecordSize
, &NumOfStr
);
910 CopyMem (BufferPointer
, SmbiosRecord
, RecordSize
);
911 BufferPointer
= BufferPointer
+ RecordSize
;
913 } while (!EFI_ERROR(Status
));
916 // Assemble End-Of-Table structure
918 CopyMem (BufferPointer
, &EndStructure
, sizeof (EndStructure
));
921 // Fixup checksums in the Entry Point Structure
924 EntryPointStructure
->IntermediateChecksum
= 0;
925 for (Index
= 0x10; Index
< EntryPointStructure
->EntryPointLength
; Index
++) {
926 CheckSum
= (UINT8
) (CheckSum
+ ((UINT8
*) (EntryPointStructure
))[Index
]);
929 EntryPointStructure
->IntermediateChecksum
= (UINT8
) (0 - CheckSum
);
932 EntryPointStructure
->EntryPointStructureChecksum
= 0;
933 for (Index
= 0x0; Index
< EntryPointStructure
->EntryPointLength
; Index
++) {
934 CheckSum
= (UINT8
) (CheckSum
+ ((UINT8
*) (EntryPointStructure
))[Index
]);
937 EntryPointStructure
->EntryPointStructureChecksum
= (UINT8
) (0 - CheckSum
);
940 // Returns the pointer
942 *TableEntryPointStructure
= EntryPointStructure
;
950 Installs the Smbios Table to the System Table. This function gets called
951 when the EFI_EVENT_SIGNAL_READY_TO_BOOT gets signaled
953 @param Event The event to signal
954 @param Context Event contex
959 SmbiosTableConstruction (
967 Status
= SmbiosCreateTable ((VOID
**) &Eps
);
968 if (!EFI_ERROR (Status
)) {
969 gBS
->InstallConfigurationTable (&gEfiSmbiosTableGuid
, Eps
);
976 Driver to produce Smbios protocol and register event for constructing SMBIOS table.
978 @param ImageHandle Module's image handle
979 @param SystemTable Pointer of EFI_SYSTEM_TABLE
981 @retval EFI_SUCCESS Smbios protocol installed
982 @retval Other No protocol installed, unload driver.
987 SmbiosDriverEntryPoint (
988 IN EFI_HANDLE ImageHandle
,
989 IN EFI_SYSTEM_TABLE
*SystemTable
993 EFI_EVENT ReadyToBootEvent
;
995 mPrivateData
.Signature
= SMBIOS_INSTANCE_SIGNATURE
;
996 mPrivateData
.Smbios
.Add
= SmbiosAdd
;
997 mPrivateData
.Smbios
.UpdateString
= SmbiosUpdateString
;
998 mPrivateData
.Smbios
.Remove
= SmbiosRemove
;
999 mPrivateData
.Smbios
.GetNext
= SmbiosGetNext
;
1000 mPrivateData
.Smbios
.MajorVersion
= (UINT8
) (FixedPcdGet16 (PcdSmbiosVersion
) >> 8);
1001 mPrivateData
.Smbios
.MinorVersion
= (UINT8
) (FixedPcdGet16 (PcdSmbiosVersion
) & 0x00ff);
1003 InitializeListHead (&mPrivateData
.DataListHead
);
1004 InitializeListHead (&mPrivateData
.AllocatedHandleListHead
);
1005 EfiInitializeLock (&mPrivateData
.DataLock
, TPL_NOTIFY
);
1008 // Make a new handle and install the protocol
1010 mPrivateData
.Handle
= NULL
;
1011 Status
= gBS
->InstallProtocolInterface (
1012 &mPrivateData
.Handle
,
1013 &gEfiSmbiosProtocolGuid
,
1014 EFI_NATIVE_INTERFACE
,
1015 &mPrivateData
.Smbios
1018 if (EFI_ERROR(Status
)) {
1022 // Register the event to install SMBIOS Table into EFI System Table
1024 Status
= gBS
->CreateEventEx (
1027 SmbiosTableConstruction
,
1029 &gEfiEventReadyToBootGuid
,