libsa: smbios: Favor the v3 (64-bit) entry point on non-EFI boot

When both the 32-bit and 64-bit entry points are present, the SMBIOS
specification says that the 64-bit entry point always has at least all
the structures the 32-bit entry point refers.  In other words, the
32-bit entry point is provided for compatibility, so we assume the
64-bit one has more chances to be filled with adequate values.

Doing this also increases consistency with the kernel's smbios(4)
driver.

Reviewed by:    imp, markj
MFC after:      2 weeks
Relnotes:       yes
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D49287

(cherry picked from commit 3f744fb8b2c5528c2170be113e0e4947eee3cffc)
This commit is contained in:
Olivier Certner 2025-03-03 15:38:10 +01:00
parent 5feb3c8ea6
commit 93af0db0d5
No known key found for this signature in database
GPG key ID: 8CA13040971E2627

View file

@ -180,16 +180,10 @@ static caddr_t
smbios_sigsearch(const caddr_t addr, const uint32_t len)
{
caddr_t cp;
caddr_t v2_p = NULL;
/* Search on 16-byte boundaries. */
for (cp = addr; cp < addr + len; cp += SMBIOS_STEP) {
/* v2.1, 32-bit Entry point */
if (strncmp(cp, SMBIOS_SIG, sizeof(SMBIOS_SIG) - 1) == 0 &&
smbios_checksum(cp, SMBIOS_GET8(cp, 0x05)) == 0 &&
strncmp(cp + 0x10, SMBIOS_DMI_SIG, 5) == 0 &&
smbios_checksum(cp + 0x10, 0x0f) == 0)
return (cp);
#ifdef SMBIOS_64BIT_EP
/* v3.0, 64-bit Entry point */
if (strncmp(cp, SMBIOS3_SIG, sizeof(SMBIOS3_SIG) - 1) == 0 &&
@ -205,8 +199,24 @@ smbios_sigsearch(const caddr_t addr, const uint32_t len)
return (cp);
}
#endif
/* v2.1, 32-bit Entry point */
if (strncmp(cp, SMBIOS_SIG, sizeof(SMBIOS_SIG) - 1) == 0 &&
smbios_checksum(cp, SMBIOS_GET8(cp, 0x05)) == 0 &&
strncmp(cp + 0x10, SMBIOS_DMI_SIG, 5) == 0 &&
smbios_checksum(cp + 0x10, 0x0f) == 0) {
/*
* Note that we saw this entry point, but don't return
* it right now on SMBIOS_64BIT_EP as we favor the 64-bit
* one if present.
*/
v2_p = cp;
#ifndef SMBIOS_64BIT_EP
break;
#endif
}
}
return (NULL);
return (v2_p);
}
static const char*