summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2023-12-29 20:38:12 +0100
committerMichael Brown2023-12-29 20:38:47 +0100
commitfa62213231a882eb6bbcefa7ad1106bdb9aaeae2 (patch)
treed21bf32e896b29ee636268c8d8d46562eab7533d
parent[intel] Add PCI ID for I219-LM (23) (diff)
downloadipxe-fa62213231a882eb6bbcefa7ad1106bdb9aaeae2.tar.gz
ipxe-fa62213231a882eb6bbcefa7ad1106bdb9aaeae2.tar.xz
ipxe-fa62213231a882eb6bbcefa7ad1106bdb9aaeae2.zip
[smbios] Support scanning for the 64-bit SMBIOS3 entry point
Support scanning for the 64-bit SMBIOS3 entry point in addition to the 32-bit SMBIOS2 entry point. Prefer use of the 32-bit entry point if present, since this is guaranteed to be within accessible memory. Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/arch/x86/interface/pcbios/bios_smbios.c55
-rw-r--r--src/include/ipxe/smbios.h2
-rw-r--r--src/interface/smbios/smbios.c78
3 files changed, 120 insertions, 15 deletions
diff --git a/src/arch/x86/interface/pcbios/bios_smbios.c b/src/arch/x86/interface/pcbios/bios_smbios.c
index a8c0fc32..366679d3 100644
--- a/src/arch/x86/interface/pcbios/bios_smbios.c
+++ b/src/arch/x86/interface/pcbios/bios_smbios.c
@@ -44,11 +44,11 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
* @v smbios SMBIOS entry point descriptor structure to fill in
* @ret rc Return status code
*/
-static int bios_find_smbios ( struct smbios *smbios ) {
+static int bios_find_smbios2 ( struct smbios *smbios ) {
struct smbios_entry entry;
int rc;
- /* Scan through BIOS segment to find SMBIOS entry point */
+ /* Scan through BIOS segment to find SMBIOS 32-bit entry point */
if ( ( rc = find_smbios_entry ( real_to_user ( BIOS_SEG, 0 ), 0x10000,
&entry ) ) != 0 )
return rc;
@@ -62,4 +62,55 @@ static int bios_find_smbios ( struct smbios *smbios ) {
return 0;
}
+/**
+ * Find SMBIOS
+ *
+ * @v smbios SMBIOS entry point descriptor structure to fill in
+ * @ret rc Return status code
+ */
+static int bios_find_smbios3 ( struct smbios *smbios ) {
+ struct smbios3_entry entry;
+ int rc;
+
+ /* Scan through BIOS segment to find SMBIOS 64-bit entry point */
+ if ( ( rc = find_smbios3_entry ( real_to_user ( BIOS_SEG, 0 ), 0x10000,
+ &entry ) ) != 0 )
+ return rc;
+
+ /* Check that address is accessible */
+ if ( entry.smbios_address > ~( ( physaddr_t ) 0 ) ) {
+ DBG ( "SMBIOS3 at %08llx is inaccessible\n",
+ ( ( unsigned long long ) entry.smbios_address ) );
+ return -ENOTSUP;
+ }
+
+ /* Fill in entry point descriptor structure */
+ smbios->address = phys_to_user ( entry.smbios_address );
+ smbios->len = entry.smbios_len;
+ smbios->count = 0;
+ smbios->version = SMBIOS_VERSION ( entry.major, entry.minor );
+
+ return 0;
+}
+
+/**
+ * Find SMBIOS
+ *
+ * @v smbios SMBIOS entry point descriptor structure to fill in
+ * @ret rc Return status code
+ */
+static int bios_find_smbios ( struct smbios *smbios ) {
+ int rc;
+
+ /* Use 32-bit table if present */
+ if ( ( rc = bios_find_smbios2 ( smbios ) ) == 0 )
+ return 0;
+
+ /* Otherwise, use 64-bit table if present and accessible */
+ if ( ( rc = bios_find_smbios3 ( smbios ) ) == 0 )
+ return 0;
+
+ return rc;
+}
+
PROVIDE_SMBIOS ( pcbios, find_smbios, bios_find_smbios );
diff --git a/src/include/ipxe/smbios.h b/src/include/ipxe/smbios.h
index 42278fb2..077a67a8 100644
--- a/src/include/ipxe/smbios.h
+++ b/src/include/ipxe/smbios.h
@@ -227,6 +227,8 @@ struct smbios {
extern int find_smbios ( struct smbios *smbios );
extern int find_smbios_entry ( userptr_t start, size_t len,
struct smbios_entry *entry );
+extern int find_smbios3_entry ( userptr_t start, size_t len,
+ struct smbios3_entry *entry );
extern int find_smbios_structure ( unsigned int type, unsigned int instance,
struct smbios_structure *structure );
extern int read_smbios_structure ( struct smbios_structure *structure,
diff --git a/src/interface/smbios/smbios.c b/src/interface/smbios/smbios.c
index 12a080da..fdd14499 100644
--- a/src/interface/smbios/smbios.c
+++ b/src/interface/smbios/smbios.c
@@ -42,7 +42,27 @@ static struct smbios smbios = {
};
/**
- * Scan for SMBIOS entry point structure
+ * Calculate SMBIOS entry point structure checksum
+ *
+ * @v start Start address of region
+ * @v offset Offset of SMBIOS entry point structure
+ * @v len Length of entry point structure
+ * @ret sum Byte checksum
+ */
+static uint8_t smbios_checksum ( userptr_t start, size_t offset, size_t len ) {
+ size_t end = ( offset + len );
+ uint8_t sum;
+ uint8_t byte;
+
+ for ( sum = 0 ; offset < end ; offset++ ) {
+ copy_from_user ( &byte, start, offset, sizeof ( byte ) );
+ sum += byte;
+ }
+ return sum;
+}
+
+/**
+ * Scan for SMBIOS 32-bit entry point structure
*
* @v start Start address of region to scan
* @v len Length of region to scan
@@ -51,28 +71,20 @@ static struct smbios smbios = {
*/
int find_smbios_entry ( userptr_t start, size_t len,
struct smbios_entry *entry ) {
- 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 ) {
+ for ( ; ( offset + sizeof ( *entry ) ) <= 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 ) {
+ /* Verify checksum */
+ if ( ( sum = smbios_checksum ( start, offset,
+ entry->len ) ) != 0 ) {
DBG ( "SMBIOS at %08lx has bad checksum %02x\n",
user_to_phys ( start, offset ), sum );
continue;
@@ -90,6 +102,46 @@ int find_smbios_entry ( userptr_t start, size_t len,
}
/**
+ * Scan for SMBIOS 64-bit entry point structure
+ *
+ * @v start Start address of region to scan
+ * @v len Length of region to scan
+ * @v entry SMBIOS entry point structure to fill in
+ * @ret rc Return status code
+ */
+int find_smbios3_entry ( userptr_t start, size_t len,
+ struct smbios3_entry *entry ) {
+ static size_t offset = 0; /* Avoid repeated attempts to locate SMBIOS */
+ uint8_t sum;
+
+ /* Try to find SMBIOS */
+ for ( ; ( offset + sizeof ( *entry ) ) <= len ; offset += 0x10 ) {
+
+ /* Read start of header and verify signature */
+ copy_from_user ( entry, start, offset, sizeof ( *entry ) );
+ if ( entry->signature != SMBIOS3_SIGNATURE )
+ continue;
+
+ /* Verify checksum */
+ if ( ( sum = smbios_checksum ( start, offset,
+ entry->len ) ) != 0 ) {
+ DBG ( "SMBIOS3 at %08lx has bad checksum %02x\n",
+ user_to_phys ( start, offset ), sum );
+ continue;
+ }
+
+ /* Fill result structure */
+ DBG ( "Found SMBIOS3 v%d.%d entry point at %08lx\n",
+ entry->major, entry->minor,
+ user_to_phys ( start, offset ) );
+ return 0;
+ }
+
+ DBG ( "No SMBIOS3 found\n" );
+ return -ENODEV;
+}
+
+/**
* Find SMBIOS strings terminator
*
* @v offset Offset to start of strings