Subversion Repositories HelenOS

Rev

Rev 2726 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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