1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2020, Bachmann electronic GmbH
9 static inline int verify_checksum(const struct smbios_entry *e)
12 * Checksums for SMBIOS tables are calculated to have a value, so that
13 * the sum over all bytes yields zero (using unsigned 8 bit arithmetic).
18 for (int i = 0; i < e->length; i++)
24 const struct smbios_entry *smbios_entry(u64 address, u32 size)
26 const struct smbios_entry *entry = (struct smbios_entry *)(uintptr_t)address;
31 if (memcmp(entry->anchor, "_SM_", 4))
34 if (verify_checksum(entry))
40 static const struct smbios_header *next_header(const struct smbios_header *curr)
42 u8 *pos = ((u8 *)curr) + curr->length;
44 /* search for _double_ NULL bytes */
45 while (!((*pos == 0) && (*(pos + 1) == 0)))
48 /* step behind the double NULL bytes */
51 return (struct smbios_header *)pos;
54 const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type)
56 const unsigned int num_header = entry->struct_count;
57 const struct smbios_header *header = (struct smbios_header *)entry->struct_table_address;
59 for (unsigned int i = 0; i < num_header; i++) {
60 if (header->type == type)
63 header = next_header(header);
69 static const char *string_from_smbios_table(const struct smbios_header *header,
78 pos = ((u8 *)header) + header->length;
87 return (const char *)pos;
90 const char *smbios_string(const struct smbios_header *header, int index)
95 return string_from_smbios_table(header, index);