Merge /u/esben/gnu-efi/ branch intptr-t-fix into master
[syslinux-gnu-efi.git] / lib / smbios.c
blobd349fb64baa3e61146fe92d6e05b7658f22c2891
1 /*++
3 Copyright (c) 2000 Intel Corporation
5 Module Name:
7 Smbios.c
9 Abstract:
11 Lib fucntions for SMBIOS. Used to get system serial number and GUID
13 Revision History
15 --*/
17 #include "lib.h"
20 * We convert 32 bit values to pointers. In 64 bit mode the compiler will issue a
21 * warning stating that the value is too small for the pointer:
22 * "warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]"
23 * we can safely ignore them here.
25 #ifdef __GNUC__
26 #pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
27 #endif
29 EFI_STATUS
30 LibGetSmbiosSystemGuidAndSerialNumber (
31 IN EFI_GUID *SystemGuid,
32 OUT CHAR8 **SystemSerialNumber
35 EFI_STATUS Status;
36 SMBIOS_STRUCTURE_TABLE *SmbiosTable;
37 SMBIOS_STRUCTURE_POINTER Smbios;
38 SMBIOS_STRUCTURE_POINTER SmbiosEnd;
39 UINT16 Index;
41 Status = LibGetSystemConfigurationTable(&SMBIOSTableGuid, (VOID**)&SmbiosTable);
42 if (EFI_ERROR(Status)) {
43 return EFI_NOT_FOUND;
46 Smbios.Hdr = (SMBIOS_HEADER *)SmbiosTable->TableAddress;
47 SmbiosEnd.Raw = (UINT8 *)(SmbiosTable->TableAddress + SmbiosTable->TableLength);
48 for (Index = 0; Index < SmbiosTable->TableLength ; Index++) {
49 if (Smbios.Hdr->Type == 1) {
50 if (Smbios.Hdr->Length < 0x19) {
52 // Older version did not support Guid and Serial number
54 continue;
58 // SMBIOS tables are byte packed so we need to do a byte copy to
59 // prevend alignment faults on IA-64.
61 CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof(EFI_GUID));
62 *SystemSerialNumber = LibGetSmbiosString(&Smbios, Smbios.Type1->SerialNumber);
63 return EFI_SUCCESS;
67 // Make Smbios point to the next record
69 LibGetSmbiosString (&Smbios, -1);
71 if (Smbios.Raw >= SmbiosEnd.Raw) {
73 // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e.
74 // given this we must double check against the lenght of
75 /// the structure. My home PC has this bug.ruthard
77 return EFI_SUCCESS;
81 return EFI_SUCCESS;
84 CHAR8*
85 LibGetSmbiosString (
86 IN SMBIOS_STRUCTURE_POINTER *Smbios,
87 IN UINT16 StringNumber
89 /*++
91 Return SMBIOS string given the string number.
93 Arguments:
94 Smbios - Pointer to SMBIOS structure
95 StringNumber - String number to return. -1 is used to skip all strings and
96 point to the next SMBIOS structure.
98 Returns:
99 Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1
100 --*/
102 UINT16 Index;
103 CHAR8 *String;
106 // Skip over formatted section
108 String = (CHAR8 *)(Smbios->Raw + Smbios->Hdr->Length);
111 // Look through unformated section
113 for (Index = 1; Index <= StringNumber; Index++) {
114 if (StringNumber == Index) {
115 return String;
119 // Skip string
121 for (; *String != 0; String++);
122 String++;
124 if (*String == 0) {
126 // If double NULL then we are done.
127 // Retrun pointer to next structure in Smbios.
128 // if you pass in a -1 you will always get here
130 Smbios->Raw = (UINT8 *)++String;
131 return NULL;
134 return NULL;