1 1.1 jakllsch /* $NetBSD: smbios.c,v 1.1.1.3 2021/09/30 18:50:09 jmcneill Exp $ */ 2 1.1 jakllsch 3 1.1 jakllsch /*++ 4 1.1 jakllsch 5 1.1 jakllsch Copyright (c) 2000 Intel Corporation 6 1.1 jakllsch 7 1.1 jakllsch Module Name: 8 1.1 jakllsch 9 1.1 jakllsch Smbios.c 10 1.1 jakllsch 11 1.1 jakllsch Abstract: 12 1.1 jakllsch 13 1.1 jakllsch Lib fucntions for SMBIOS. Used to get system serial number and GUID 14 1.1 jakllsch 15 1.1 jakllsch Revision History 16 1.1 jakllsch 17 1.1 jakllsch --*/ 18 1.1 jakllsch 19 1.1 jakllsch #include "lib.h" 20 1.1 jakllsch 21 1.1.1.2 jmcneill /* 22 1.1.1.2 jmcneill * We convert 32 bit values to pointers. In 64 bit mode the compiler will issue a 23 1.1.1.2 jmcneill * warning stating that the value is too small for the pointer: 24 1.1.1.2 jmcneill * "warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]" 25 1.1.1.2 jmcneill * we can safely ignore them here. 26 1.1.1.2 jmcneill */ 27 1.1.1.2 jmcneill #ifdef __GNUC__ 28 1.1.1.2 jmcneill #pragma GCC diagnostic ignored "-Wint-to-pointer-cast" 29 1.1.1.2 jmcneill #endif 30 1.1 jakllsch 31 1.1 jakllsch EFI_STATUS 32 1.1 jakllsch LibGetSmbiosSystemGuidAndSerialNumber ( 33 1.1 jakllsch IN EFI_GUID *SystemGuid, 34 1.1 jakllsch OUT CHAR8 **SystemSerialNumber 35 1.1 jakllsch ) 36 1.1 jakllsch { 37 1.1 jakllsch EFI_STATUS Status; 38 1.1 jakllsch SMBIOS_STRUCTURE_TABLE *SmbiosTable; 39 1.1 jakllsch SMBIOS_STRUCTURE_POINTER Smbios; 40 1.1 jakllsch SMBIOS_STRUCTURE_POINTER SmbiosEnd; 41 1.1 jakllsch UINT16 Index; 42 1.1 jakllsch 43 1.1 jakllsch Status = LibGetSystemConfigurationTable(&SMBIOSTableGuid, (VOID**)&SmbiosTable); 44 1.1 jakllsch if (EFI_ERROR(Status)) { 45 1.1 jakllsch return EFI_NOT_FOUND; 46 1.1 jakllsch } 47 1.1 jakllsch 48 1.1 jakllsch Smbios.Hdr = (SMBIOS_HEADER *)SmbiosTable->TableAddress; 49 1.1.1.3 jmcneill SmbiosEnd.Raw = (UINT8 *)((UINTN)SmbiosTable->TableAddress + SmbiosTable->TableLength); 50 1.1 jakllsch for (Index = 0; Index < SmbiosTable->TableLength ; Index++) { 51 1.1 jakllsch if (Smbios.Hdr->Type == 1) { 52 1.1 jakllsch if (Smbios.Hdr->Length < 0x19) { 53 1.1 jakllsch // 54 1.1 jakllsch // Older version did not support Guid and Serial number 55 1.1 jakllsch // 56 1.1 jakllsch continue; 57 1.1 jakllsch } 58 1.1 jakllsch 59 1.1 jakllsch // 60 1.1 jakllsch // SMBIOS tables are byte packed so we need to do a byte copy to 61 1.1 jakllsch // prevend alignment faults on IA-64. 62 1.1 jakllsch 63 1.1 jakllsch CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof(EFI_GUID)); 64 1.1 jakllsch *SystemSerialNumber = LibGetSmbiosString(&Smbios, Smbios.Type1->SerialNumber); 65 1.1 jakllsch return EFI_SUCCESS; 66 1.1 jakllsch } 67 1.1 jakllsch 68 1.1 jakllsch // 69 1.1 jakllsch // Make Smbios point to the next record 70 1.1 jakllsch // 71 1.1 jakllsch LibGetSmbiosString (&Smbios, -1); 72 1.1 jakllsch 73 1.1 jakllsch if (Smbios.Raw >= SmbiosEnd.Raw) { 74 1.1 jakllsch // 75 1.1 jakllsch // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e. 76 1.1 jakllsch // given this we must double check against the lenght of 77 1.1 jakllsch /// the structure. My home PC has this bug.ruthard 78 1.1 jakllsch // 79 1.1 jakllsch return EFI_SUCCESS; 80 1.1 jakllsch } 81 1.1 jakllsch } 82 1.1 jakllsch 83 1.1 jakllsch return EFI_SUCCESS; 84 1.1 jakllsch } 85 1.1 jakllsch 86 1.1 jakllsch CHAR8* 87 1.1 jakllsch LibGetSmbiosString ( 88 1.1 jakllsch IN SMBIOS_STRUCTURE_POINTER *Smbios, 89 1.1 jakllsch IN UINT16 StringNumber 90 1.1 jakllsch ) 91 1.1 jakllsch /*++ 92 1.1 jakllsch 93 1.1 jakllsch Return SMBIOS string given the string number. 94 1.1 jakllsch 95 1.1 jakllsch Arguments: 96 1.1 jakllsch Smbios - Pointer to SMBIOS structure 97 1.1 jakllsch StringNumber - String number to return. -1 is used to skip all strings and 98 1.1 jakllsch point to the next SMBIOS structure. 99 1.1 jakllsch 100 1.1 jakllsch Returns: 101 1.1 jakllsch Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1 102 1.1 jakllsch --*/ 103 1.1 jakllsch { 104 1.1 jakllsch UINT16 Index; 105 1.1 jakllsch CHAR8 *String; 106 1.1 jakllsch 107 1.1 jakllsch // 108 1.1 jakllsch // Skip over formatted section 109 1.1 jakllsch // 110 1.1 jakllsch String = (CHAR8 *)(Smbios->Raw + Smbios->Hdr->Length); 111 1.1 jakllsch 112 1.1 jakllsch // 113 1.1 jakllsch // Look through unformated section 114 1.1 jakllsch // 115 1.1 jakllsch for (Index = 1; Index <= StringNumber; Index++) { 116 1.1 jakllsch if (StringNumber == Index) { 117 1.1 jakllsch return String; 118 1.1 jakllsch } 119 1.1 jakllsch 120 1.1 jakllsch // 121 1.1 jakllsch // Skip string 122 1.1 jakllsch // 123 1.1 jakllsch for (; *String != 0; String++); 124 1.1 jakllsch String++; 125 1.1 jakllsch 126 1.1 jakllsch if (*String == 0) { 127 1.1 jakllsch // 128 1.1 jakllsch // If double NULL then we are done. 129 1.1 jakllsch // Retrun pointer to next structure in Smbios. 130 1.1 jakllsch // if you pass in a -1 you will always get here 131 1.1 jakllsch // 132 1.1 jakllsch Smbios->Raw = (UINT8 *)++String; 133 1.1 jakllsch return NULL; 134 1.1 jakllsch } 135 1.1 jakllsch } 136 1.1 jakllsch return NULL; 137 1.1 jakllsch } 138