libpayload: configs: Add new config.featuretest to broaden CI
[coreboot2.git] / src / drivers / secunet / dmi / smbios.c
blobfb8d75ac643db0090f550a20166283168ae656c6
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <stdint.h>
4 #include <string.h>
5 #include <ctype.h>
6 #include <commonlib/helpers.h>
7 #include <uuid.h>
8 #include <console/console.h>
9 #include <device/device.h>
10 #include <device/i2c_bus.h>
11 #include <smbios.h>
13 #include "eeprom.h"
15 #define MAX_STRING_LENGTH UUID_STRLEN
17 static struct device *eeprom;
19 static const char *eeprom_read_string(const enum bx26_strings idx)
21 static char str[MAX_STRING_LENGTH + 1];
23 if (!eeprom) {
24 printk(BIOS_WARNING, "DMI: Serial EEPROM not found\n");
25 str[0] = '\0';
26 return str;
29 const size_t offset = bx26_locations[idx].offset;
30 const size_t length = MIN(bx26_locations[idx].length, MAX_STRING_LENGTH);
32 if (i2c_dev_read_at16(eeprom, (u8 *)str, length, offset) != length) {
33 printk(BIOS_WARNING, "DMI: Failed to read serial EEPROM\n");
34 str[0] = '\0';
35 } else {
36 unsigned int i;
37 /* Terminate at first non-printable character. */
38 for (i = 0; i < length; ++i) {
39 if (!isprint(str[i]))
40 break;
42 str[i] = '\0';
45 return str;
48 const char *smbios_system_manufacturer(void)
50 return eeprom_read_string(SYSTEM_MANUFACTURER);
53 const char *smbios_system_product_name(void)
55 return eeprom_read_string(SYSTEM_PRODUCT_NAME);
58 const char *smbios_system_serial_number(void)
60 return eeprom_read_string(SYSTEM_SERIAL_NUMBER);
63 const char *smbios_system_version(void)
65 return eeprom_read_string(SYSTEM_VERSION);
68 void smbios_system_set_uuid(u8 *const uuid)
70 if (parse_uuid(uuid, eeprom_read_string(SYSTEM_UUID))) {
71 printk(BIOS_WARNING, "DMI: Cannot parse UUID\n");
72 memset(uuid, 0x00, UUID_LEN);
76 const char *smbios_mainboard_serial_number(void)
78 return eeprom_read_string(BOARD_SERIAL_NUMBER);
81 const char *smbios_mainboard_version(void)
83 return eeprom_read_string(BOARD_VERSION);
86 static void enable_dev(struct device *dev)
88 if (dev->path.type != DEVICE_PATH_I2C || (dev->path.i2c.device & 0xf0) != 0x50)
89 return;
90 eeprom = dev;
93 struct chip_operations drivers_secunet_dmi_ops = {
94 .name = "secunet DMI",
95 .enable_dev = enable_dev,