iPXE
Data Structures | Defines | Functions | Variables
smbios.h File Reference

System Management BIOS. More...

#include <stdint.h>
#include <ipxe/api.h>
#include <config/general.h>
#include <ipxe/uaccess.h>
#include <ipxe/efi/efi_smbios.h>
#include <ipxe/linux/linux_smbios.h>
#include <bits/smbios.h>

Go to the source code of this file.

Data Structures

struct  smbios_entry
 SMBIOS entry point. More...
struct  smbios_header
 An SMBIOS structure header. More...
struct  smbios_structure
 SMBIOS structure descriptor. More...
struct  smbios_system_information
 SMBIOS system information structure. More...
struct  smbios_base_board_information
 SMBIOS base board information structure. More...
struct  smbios_enclosure_information
 SMBIOS enclosure information structure. More...
struct  smbios
 SMBIOS entry point descriptor. More...

Defines

#define PROVIDE_SMBIOS(_subsys, _api_func, _func)   PROVIDE_SINGLE_API ( SMBIOS_PREFIX_ ## _subsys, _api_func, _func )
 Provide an SMBIOS API implementation.
#define SMBIOS_SIGNATURE   ( ( '_' << 0 ) + ( 'S' << 8 ) + ( 'M' << 16 ) + ( '_' << 24 ) )
 Signature for SMBIOS entry point.
#define SMBIOS_TYPE_SYSTEM_INFORMATION   1
 SMBIOS system information structure type.
#define SMBIOS_TYPE_BASE_BOARD_INFORMATION   2
 SMBIOS base board information structure type.
#define SMBIOS_TYPE_ENCLOSURE_INFORMATION   3
 SMBIOS enclosure information structure type.
#define SMBIOS_TYPE_OEM_STRINGS   11
 SMBIOS OEM strings structure type.
#define SMBIOS_VERSION(major, minor)   ( ( (major) << 8 ) | (minor) )
 Calculate SMBIOS version.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
struct smbios_entry __attribute__ ((packed))
int find_smbios (struct smbios *smbios)
int find_smbios_entry (userptr_t start, size_t len, struct smbios_entry *entry)
 Scan for SMBIOS entry point structure.
int find_smbios_structure (unsigned int type, unsigned int instance, struct smbios_structure *structure)
 Find specific structure type within SMBIOS.
int read_smbios_structure (struct smbios_structure *structure, void *data, size_t len)
 Copy SMBIOS structure.
int read_smbios_string (struct smbios_structure *structure, unsigned int index, void *data, size_t len)
 Find indexed string within SMBIOS structure.
int smbios_version (void)
 Get SMBIOS version.

Variables

uint32_t signature
 Signature.
uint8_t checksum
 Checksum.
uint8_t len
 Length.
uint8_t major
 Major version.
uint8_t minor
 Minor version.
uint16_t max
 Maximum structure size.
uint8_t revision
 Entry point revision.
uint8_t formatted [5]
 Formatted area.
uint8_t dmi_signature [5]
 DMI Signature.
uint8_t dmi_checksum
 DMI checksum.
uint16_t smbios_len
 Structure table length.
uint32_t smbios_address
 Structure table address.
uint16_t smbios_count
 Number of SMBIOS structures.
uint8_t bcd_revision
 BCD revision.
uint8_t type
 Type.
uint16_t handle
 Handle.
struct smbios_structure __attribute__
struct smbios_header header
 SMBIOS structure header.
uint8_t manufacturer
 Manufacturer string.
uint8_t product
 Product string.
uint8_t version
 Version string.
uint8_t serial
 Serial number string.
uint8_t uuid [16]
 UUID.
uint8_t wakeup
 Wake-up type.
uint8_t asset_tag
 Asset tag.

Detailed Description

System Management BIOS.

Definition in file smbios.h.


Define Documentation

#define PROVIDE_SMBIOS (   _subsys,
  _api_func,
  _func 
)    PROVIDE_SINGLE_API ( SMBIOS_PREFIX_ ## _subsys, _api_func, _func )

Provide an SMBIOS API implementation.

Parameters:
_prefixSubsystem prefix
_api_funcAPI function
_funcImplementing function

Definition at line 24 of file smbios.h.

#define SMBIOS_SIGNATURE   ( ( '_' << 0 ) + ( 'S' << 8 ) + ( 'M' << 16 ) + ( '_' << 24 ) )

Signature for SMBIOS entry point.

Definition at line 35 of file smbios.h.

Referenced by efi_find_smbios(), and find_smbios_entry().

SMBIOS system information structure type.

Definition at line 117 of file smbios.h.

Referenced by smsc95xx_vm3_fetch_mac().

SMBIOS base board information structure type.

Definition at line 134 of file smbios.h.

SMBIOS enclosure information structure type.

Definition at line 153 of file smbios.h.

#define SMBIOS_TYPE_OEM_STRINGS   11

SMBIOS OEM strings structure type.

Definition at line 156 of file smbios.h.

Referenced by smsc95xx_vm3_fetch_mac().

#define SMBIOS_VERSION (   major,
  minor 
)    ( ( (major) << 8 ) | (minor) )

Calculate SMBIOS version.

Parameters:
majorMajor version
minorMinor version
Return values:
versionSMBIOS version

Definition at line 182 of file smbios.h.

Referenced by bios_find_smbios(), efi_find_smbios(), and smbios_fetch().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
struct smbios_entry __attribute__ ( (packed)  )
int find_smbios ( struct smbios smbios)
int find_smbios_entry ( userptr_t  start,
size_t  len,
struct smbios_entry entry 
)

Scan for SMBIOS entry point structure.

Parameters:
startStart address of region to scan
lenLength of region to scan
entrySMBIOS entry point structure to fill in
Return values:
rcReturn status code

Definition at line 52 of file smbios.c.

References assert, copy_from_user(), DBG, ENODEV, smbios_entry::len, len, smbios_entry::major, smbios_entry::minor, offset, smbios_entry::signature, SMBIOS_SIGNATURE, and user_to_phys().

Referenced by bios_find_smbios().

                                                     {
        uint8_t buf[256]; /* 256 is maximum length possible */
        static size_t offset = 0; /* Avoid repeated attempts to locate SMBIOS */
        size_t entry_len;
        unsigned int i;
        uint8_t sum;

        /* Try to find SMBIOS */
        for ( ; offset < len ; offset += 0x10 ) {

                /* Read start of header and verify signature */
                copy_from_user ( entry, start, offset, sizeof ( *entry ) );
                if ( entry->signature != SMBIOS_SIGNATURE )
                        continue;

                /* Read whole header and verify checksum */
                entry_len = entry->len;
                assert ( entry_len <= sizeof ( buf ) );
                copy_from_user ( buf, start, offset, entry_len );
                for ( i = 0, sum = 0 ; i < entry_len ; i++ ) {
                        sum += buf[i];
                }
                if ( sum != 0 ) {
                        DBG ( "SMBIOS at %08lx has bad checksum %02x\n",
                              user_to_phys ( start, offset ), sum );
                        continue;
                }

                /* Fill result structure */
                DBG ( "Found SMBIOS v%d.%d entry point at %08lx\n",
                      entry->major, entry->minor,
                      user_to_phys ( start, offset ) );
                return 0;
        }

        DBG ( "No SMBIOS found\n" );
        return -ENODEV;
}
int find_smbios_structure ( unsigned int  type,
unsigned int  instance,
struct smbios_structure structure 
)

Find specific structure type within SMBIOS.

Parameters:
typeStructure type to search for
instanceInstance of this type of structure
structureSMBIOS structure descriptor to fill in
Return values:
rcReturn status code

Definition at line 118 of file smbios.c.

References smbios::address, assert, copy_from_user(), smbios::count, count, DBG, ENOENT, find_smbios(), find_strings_terminator(), smbios_structure::header, smbios_header::len, smbios::len, smbios_structure::offset, offset, rc, smbios_structure::strings_len, smbios_header::type, and UNULL.

Referenced by smbios_fetch(), and smsc95xx_vm3_fetch_mac().

                                                                 {
        unsigned int count = 0;
        size_t offset = 0;
        size_t strings_offset;
        size_t terminator_offset;
        int rc;

        /* Find SMBIOS */
        if ( ( smbios.address == UNULL ) &&
             ( ( rc = find_smbios ( &smbios ) ) != 0 ) )
                return rc;
        assert ( smbios.address != UNULL );

        /* Scan through list of structures */
        while ( ( ( offset + sizeof ( structure->header ) ) < smbios.len )
                && ( count < smbios.count ) ) {

                /* Read next SMBIOS structure header */
                copy_from_user ( &structure->header, smbios.address, offset,
                                 sizeof ( structure->header ) );

                /* Determine start and extent of strings block */
                strings_offset = ( offset + structure->header.len );
                if ( strings_offset > smbios.len ) {
                        DBG ( "SMBIOS structure at offset %zx with length "
                              "%x extends beyond SMBIOS\n", offset,
                              structure->header.len );
                        return -ENOENT;
                }
                terminator_offset = find_strings_terminator ( strings_offset );
                if ( ! terminator_offset ) {
                        DBG ( "SMBIOS structure at offset %zx has "
                              "unterminated strings section\n", offset );
                        return -ENOENT;
                }
                structure->strings_len = ( terminator_offset - strings_offset);

                DBG ( "SMBIOS structure at offset %zx has type %d, length %x, "
                      "strings length %zx\n", offset, structure->header.type,
                      structure->header.len, structure->strings_len );

                /* If this is the structure we want, return */
                if ( ( structure->header.type == type ) &&
                     ( instance-- == 0 ) ) {
                        structure->offset = offset;
                        return 0;
                }

                /* Move to next SMBIOS structure */
                offset = ( terminator_offset + 1 );
                count++;
        }

        DBG ( "SMBIOS structure type %d not found\n", type );
        return -ENOENT;
}
int read_smbios_structure ( struct smbios_structure structure,
void *  data,
size_t  len 
)

Copy SMBIOS structure.

Parameters:
structureSMBIOS structure descriptor
dataBuffer to hold SMBIOS structure
lenLength of buffer
Return values:
rcReturn status code

Definition at line 184 of file smbios.c.

References smbios::address, assert, copy_from_user(), smbios_structure::header, smbios_header::len, smbios_structure::offset, and UNULL.

Referenced by smbios_fetch(), and smsc95xx_vm3_fetch_mac().

                                                     {

        assert ( smbios.address != UNULL );

        if ( len > structure->header.len )
                len = structure->header.len;
        copy_from_user ( data, smbios.address, structure->offset, len );
        return 0;
}
int read_smbios_string ( struct smbios_structure structure,
unsigned int  index,
void *  data,
size_t  len 
)

Find indexed string within SMBIOS structure.

Parameters:
structureSMBIOS structure descriptor
indexString index
dataBuffer for string
lenLength of string buffer
Return values:
rcLength of string, or negative error

Definition at line 204 of file smbios.c.

References smbios::address, assert, copy_from_user(), DBG, ENOENT, smbios_structure::header, smbios_header::len, smbios_structure::offset, offset, smbios_structure::strings_len, strlen_user(), and UNULL.

Referenced by smbios_fetch(), and smsc95xx_vm3_fetch_mac().

                                                                      {
        size_t strings_start = ( structure->offset + structure->header.len );
        size_t strings_end = ( strings_start + structure->strings_len );
        size_t offset;
        size_t string_len;

        assert ( smbios.address != UNULL );

        /* String numbers start at 1 (0 is used to indicate "no string") */
        if ( ! index )
                return -ENOENT;

        for ( offset = strings_start ; offset < strings_end ;
              offset += ( string_len + 1 ) ) {
                /* Get string length.  This is known safe, since the
                 * smbios_strings struct is constructed so as to
                 * always end on a string boundary.
                 */
                string_len = strlen_user ( smbios.address, offset );
                if ( --index == 0 ) {
                        /* Copy string, truncating as necessary. */
                        if ( len > string_len )
                                len = string_len;
                        copy_from_user ( data, smbios.address, offset, len );
                        return string_len;
                }
        }

        DBG ( "SMBIOS string index %d not found\n", index );
        return -ENOENT;
}
int smbios_version ( void  )

Get SMBIOS version.

Return values:
versionVersion, or negative error

Definition at line 242 of file smbios.c.

References smbios::address, assert, find_smbios(), rc, UNULL, and smbios::version.

Referenced by smbios_fetch().

                            {
        int rc;

        /* Find SMBIOS */
        if ( ( smbios.address == UNULL ) &&
             ( ( rc = find_smbios ( &smbios ) ) != 0 ) )
                return rc;
        assert ( smbios.address != UNULL );

        return smbios.version;
}

Variable Documentation

Signature.

Must be equal to SMBIOS_SIGNATURE

Definition at line 81 of file smbios.h.

Checksum.

Definition at line 83 of file smbios.h.

Length.

Definition at line 85 of file smbios.h.

Major version.

Definition at line 87 of file smbios.h.

Minor version.

Definition at line 89 of file smbios.h.

Maximum structure size.

Definition at line 91 of file smbios.h.

Entry point revision.

Definition at line 93 of file smbios.h.

Formatted area.

Definition at line 95 of file smbios.h.

Referenced by uri_churi_okx(), and uri_resolve_okx().

DMI Signature.

Definition at line 97 of file smbios.h.

DMI checksum.

Definition at line 99 of file smbios.h.

Structure table length.

Definition at line 101 of file smbios.h.

Structure table address.

Definition at line 103 of file smbios.h.

Number of SMBIOS structures.

Definition at line 105 of file smbios.h.

BCD revision.

Definition at line 107 of file smbios.h.

Type.

Type string.

Definition at line 88 of file smbios.h.

SMBIOS structure header.

Definition at line 116 of file smbios.h.

Manufacturer string.

Definition at line 118 of file smbios.h.

Product string.

Definition at line 120 of file smbios.h.

Referenced by __attribute__().

Version string.

Definition at line 122 of file smbios.h.

Serial number string.

Definition at line 124 of file smbios.h.

UUID.

Definition at line 126 of file smbios.h.

Referenced by peerdisc_create(), and smbios_fetch().

Wake-up type.

Definition at line 128 of file smbios.h.

Asset tag.

Definition at line 162 of file smbios.h.