aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig31
-rw-r--r--lib/Makefile1
-rw-r--r--lib/acpi/acpi_device.c2
-rw-r--r--lib/acpi/acpi_table.c4
-rw-r--r--lib/smbios-parser.c96
-rw-r--r--lib/smbios.c120
6 files changed, 204 insertions, 50 deletions
diff --git a/lib/Kconfig b/lib/Kconfig
index 79651eaad1..7673d2e4e0 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -637,6 +637,15 @@ config FDT_FIXUP_PARTITIONS
menu "System tables"
depends on (!EFI && !SYS_COREBOOT) || (ARM && EFI_LOADER)
+config BLOBLIST_TABLES
+ bool "Put tables in a bloblist"
+ depends on X86
+ help
+ Normally tables are placed at address 0xf0000 and can be up to 64KB
+ long. With this option, tables are instead placed in the bloblist
+ with a pointer from 0xf0000. The size can then be larger and the
+ tables can be placed high in memory.
+
config GENERATE_SMBIOS_TABLE
bool "Generate an SMBIOS (System Management BIOS) table"
default y
@@ -649,21 +658,8 @@ config GENERATE_SMBIOS_TABLE
Check http://www.dmtf.org/standards/smbios for details.
-config SMBIOS_MANUFACTURER
- string "SMBIOS Manufacturer"
- depends on GENERATE_SMBIOS_TABLE
- default SYS_VENDOR
- help
- The board manufacturer to store in SMBIOS structures.
- Change this to override the default one (CONFIG_SYS_VENDOR).
-
-config SMBIOS_PRODUCT_NAME
- string "SMBIOS Product Name"
- depends on GENERATE_SMBIOS_TABLE
- default SYS_BOARD
- help
- The product name to store in SMBIOS structures.
- Change this to override the default one (CONFIG_SYS_BOARD).
+ See also SMBIOS_SYSINFO which allows SMBIOS values to be provided in
+ the devicetree.
endmenu
@@ -680,6 +676,11 @@ config OID_REGISTRY
help
Enable fast lookup object identifier registry.
+config SMBIOS_PARSER
+ bool "SMBIOS parser"
+ help
+ A simple parser for SMBIOS data.
+
source lib/efi/Kconfig
source lib/efi_loader/Kconfig
source lib/optee/Kconfig
diff --git a/lib/Makefile b/lib/Makefile
index 7c7fb9aae7..851a80ef3b 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_FIT) += fdtdec_common.o
obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o
obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o
obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
+obj-$(CONFIG_SMBIOS_PARSER) += smbios-parser.o
obj-$(CONFIG_IMAGE_SPARSE) += image-sparse.o
obj-y += ldiv.o
obj-$(CONFIG_XXHASH) += xxhash.o
diff --git a/lib/acpi/acpi_device.c b/lib/acpi/acpi_device.c
index 95dfac583f..c3439a5988 100644
--- a/lib/acpi/acpi_device.c
+++ b/lib/acpi/acpi_device.c
@@ -422,7 +422,7 @@ int acpi_device_add_power_res(struct acpi_ctx *ctx, u32 tx_state_val,
/* Method (_ON, 0, Serialized) */
acpigen_write_method_serialized(ctx, "_ON", 0);
- if (reset_gpio) {
+ if (has_reset) {
ret = acpigen_set_enable_tx_gpio(ctx, tx_state_val, dw0_read,
dw0_write, &reset, true);
if (ret)
diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
index 908d890389..a0f0961be5 100644
--- a/lib/acpi/acpi_table.c
+++ b/lib/acpi/acpi_table.c
@@ -183,8 +183,8 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
return 0;
}
-static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
- struct acpi_xsdt *xsdt)
+void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
+ struct acpi_xsdt *xsdt)
{
memset(rsdp, 0, sizeof(struct acpi_rsdp));
diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c
new file mode 100644
index 0000000000..b89f988ef9
--- /dev/null
+++ b/lib/smbios-parser.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020, Bachmann electronic GmbH
+ */
+
+#include <common.h>
+#include <smbios.h>
+
+static inline int verify_checksum(const struct smbios_entry *e)
+{
+ /*
+ * Checksums for SMBIOS tables are calculated to have a value, so that
+ * the sum over all bytes yields zero (using unsigned 8 bit arithmetic).
+ */
+ u8 *byte = (u8 *)e;
+ u8 sum = 0;
+
+ for (int i = 0; i < e->length; i++)
+ sum += byte[i];
+
+ return sum;
+}
+
+const struct smbios_entry *smbios_entry(u64 address, u32 size)
+{
+ const struct smbios_entry *entry = (struct smbios_entry *)(uintptr_t)address;
+
+ if (!address | !size)
+ return NULL;
+
+ if (memcmp(entry->anchor, "_SM_", 4))
+ return NULL;
+
+ if (verify_checksum(entry))
+ return NULL;
+
+ return entry;
+}
+
+static const struct smbios_header *next_header(const struct smbios_header *curr)
+{
+ u8 *pos = ((u8 *)curr) + curr->length;
+
+ /* search for _double_ NULL bytes */
+ while (!((*pos == 0) && (*(pos + 1) == 0)))
+ pos++;
+
+ /* step behind the double NULL bytes */
+ pos += 2;
+
+ return (struct smbios_header *)pos;
+}
+
+const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type)
+{
+ const unsigned int num_header = entry->struct_count;
+ const struct smbios_header *header = (struct smbios_header *)entry->struct_table_address;
+
+ for (unsigned int i = 0; i < num_header; i++) {
+ if (header->type == type)
+ return header;
+
+ header = next_header(header);
+ }
+
+ return NULL;
+}
+
+static const char *string_from_smbios_table(const struct smbios_header *header,
+ int idx)
+{
+ unsigned int i = 1;
+ u8 *pos;
+
+ if (!header)
+ return NULL;
+
+ pos = ((u8 *)header) + header->length;
+
+ while (i < idx) {
+ if (*pos == 0x0)
+ i++;
+
+ pos++;
+ }
+
+ return (const char *)pos;
+}
+
+const char *smbios_string(const struct smbios_header *header, int index)
+{
+ if (!header)
+ return NULL;
+
+ return string_from_smbios_table(header, index);
+}
diff --git a/lib/smbios.c b/lib/smbios.c
index 11790443e1..485a812c77 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -6,6 +6,7 @@
*/
#include <common.h>
+#include <dm.h>
#include <env.h>
#include <mapmem.h>
#include <smbios.h>
@@ -13,11 +14,22 @@
#include <version.h>
#ifdef CONFIG_CPU
#include <cpu.h>
-#include <dm.h>
#include <dm/uclass-internal.h>
#endif
/**
+ * struct smbios_write_method - Information about a table-writing function
+ *
+ * @write: Function to call
+ * @subnode_name: Name of subnode which has the information for this function,
+ * NULL if none
+ */
+struct smbios_write_method {
+ smbios_write_type write;
+ const char *subnode_name;
+};
+
+/**
* smbios_add_string() - add a string to the string area
*
* This adds a string to the string area which is appended directly after
@@ -25,7 +37,7 @@
*
* @start: string area start address
* @str: string to add
- * @return: string number in the string area
+ * @return: string number in the string area (1 or more)
*/
static int smbios_add_string(char *start, const char *str)
{
@@ -53,6 +65,28 @@ static int smbios_add_string(char *start, const char *str)
}
/**
+ * smbios_add_prop() - Add a property from the device tree
+ *
+ * @start: string area start address
+ * @node: node containing the information to write (ofnode_null() if none)
+ * @prop: property to write
+ * @return 0 if not found, else SMBIOS string number (1 or more)
+ */
+static int smbios_add_prop(char *start, ofnode node, const char *prop)
+{
+
+ if (IS_ENABLED(CONFIG_OF_CONTROL)) {
+ const char *str;
+
+ str = ofnode_read_string(node, prop);
+ if (str)
+ return smbios_add_string(start, str);
+ }
+
+ return 0;
+}
+
+/**
* smbios_string_table_len() - compute the string area size
*
* This computes the size of the string area including the string terminator.
@@ -74,7 +108,7 @@ static int smbios_string_table_len(char *start)
return len + 1;
}
-static int smbios_write_type0(ulong *current, int handle)
+static int smbios_write_type0(ulong *current, int handle, ofnode node)
{
struct smbios_type0 *t;
int len = sizeof(struct smbios_type0);
@@ -111,7 +145,7 @@ static int smbios_write_type0(ulong *current, int handle)
return len;
}
-static int smbios_write_type1(ulong *current, int handle)
+static int smbios_write_type1(ulong *current, int handle, ofnode node)
{
struct smbios_type1 *t;
int len = sizeof(struct smbios_type1);
@@ -120,12 +154,17 @@ static int smbios_write_type1(ulong *current, int handle)
t = map_sysmem(*current, len);
memset(t, 0, sizeof(struct smbios_type1));
fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle);
- t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
- t->product_name = smbios_add_string(t->eos, CONFIG_SMBIOS_PRODUCT_NAME);
+ t->manufacturer = smbios_add_prop(t->eos, node, "manufacturer");
+ t->product_name = smbios_add_prop(t->eos, node, "product");
+ t->version = smbios_add_prop(t->eos, node, "version");
if (serial_str) {
- strncpy((char *)t->uuid, serial_str, sizeof(t->uuid));
t->serial_number = smbios_add_string(t->eos, serial_str);
+ strncpy((char *)t->uuid, serial_str, sizeof(t->uuid));
+ } else {
+ t->serial_number = smbios_add_prop(t->eos, node, "serial");
}
+ t->sku_number = smbios_add_prop(t->eos, node, "sku");
+ t->family = smbios_add_prop(t->eos, node, "family");
len = t->length + smbios_string_table_len(t->eos);
*current += len;
@@ -134,7 +173,7 @@ static int smbios_write_type1(ulong *current, int handle)
return len;
}
-static int smbios_write_type2(ulong *current, int handle)
+static int smbios_write_type2(ulong *current, int handle, ofnode node)
{
struct smbios_type2 *t;
int len = sizeof(struct smbios_type2);
@@ -142,8 +181,9 @@ static int smbios_write_type2(ulong *current, int handle)
t = map_sysmem(*current, len);
memset(t, 0, sizeof(struct smbios_type2));
fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle);
- t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
- t->product_name = smbios_add_string(t->eos, CONFIG_SMBIOS_PRODUCT_NAME);
+ t->manufacturer = smbios_add_prop(t->eos, node, "manufacturer");
+ t->product_name = smbios_add_prop(t->eos, node, "product");
+ t->asset_tag_number = smbios_add_prop(t->eos, node, "asset-tag");
t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING;
t->board_type = SMBIOS_BOARD_MOTHERBOARD;
@@ -154,7 +194,7 @@ static int smbios_write_type2(ulong *current, int handle)
return len;
}
-static int smbios_write_type3(ulong *current, int handle)
+static int smbios_write_type3(ulong *current, int handle, ofnode node)
{
struct smbios_type3 *t;
int len = sizeof(struct smbios_type3);
@@ -162,7 +202,7 @@ static int smbios_write_type3(ulong *current, int handle)
t = map_sysmem(*current, len);
memset(t, 0, sizeof(struct smbios_type3));
fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle);
- t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
+ t->manufacturer = smbios_add_prop(t->eos, node, "manufacturer");
t->chassis_type = SMBIOS_ENCLOSURE_DESKTOP;
t->bootup_state = SMBIOS_STATE_SAFE;
t->power_supply_state = SMBIOS_STATE_SAFE;
@@ -176,7 +216,7 @@ static int smbios_write_type3(ulong *current, int handle)
return len;
}
-static void smbios_write_type4_dm(struct smbios_type4 *t)
+static void smbios_write_type4_dm(struct smbios_type4 *t, ofnode node)
{
u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN;
const char *vendor = "Unknown";
@@ -185,20 +225,20 @@ static void smbios_write_type4_dm(struct smbios_type4 *t)
#ifdef CONFIG_CPU
char processor_name[49];
char vendor_name[49];
- struct udevice *dev = NULL;
+ struct udevice *cpu = NULL;
- uclass_find_first_device(UCLASS_CPU, &dev);
- if (dev) {
- struct cpu_platdata *plat = dev_get_parent_platdata(dev);
+ uclass_find_first_device(UCLASS_CPU, &cpu);
+ if (cpu) {
+ struct cpu_platdata *plat = dev_get_parent_platdata(cpu);
if (plat->family)
processor_family = plat->family;
t->processor_id[0] = plat->id[0];
t->processor_id[1] = plat->id[1];
- if (!cpu_get_vendor(dev, vendor_name, sizeof(vendor_name)))
+ if (!cpu_get_vendor(cpu, vendor_name, sizeof(vendor_name)))
vendor = vendor_name;
- if (!cpu_get_desc(dev, processor_name, sizeof(processor_name)))
+ if (!cpu_get_desc(cpu, processor_name, sizeof(processor_name)))
name = processor_name;
}
#endif
@@ -208,7 +248,7 @@ static void smbios_write_type4_dm(struct smbios_type4 *t)
t->processor_version = smbios_add_string(t->eos, name);
}
-static int smbios_write_type4(ulong *current, int handle)
+static int smbios_write_type4(ulong *current, int handle, ofnode node)
{
struct smbios_type4 *t;
int len = sizeof(struct smbios_type4);
@@ -217,7 +257,7 @@ static int smbios_write_type4(ulong *current, int handle)
memset(t, 0, sizeof(struct smbios_type4));
fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle);
t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL;
- smbios_write_type4_dm(t);
+ smbios_write_type4_dm(t, node);
t->status = SMBIOS_PROCESSOR_STATUS_ENABLED;
t->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE;
t->l1_cache_handle = 0xffff;
@@ -232,7 +272,7 @@ static int smbios_write_type4(ulong *current, int handle)
return len;
}
-static int smbios_write_type32(ulong *current, int handle)
+static int smbios_write_type32(ulong *current, int handle, ofnode node)
{
struct smbios_type32 *t;
int len = sizeof(struct smbios_type32);
@@ -247,7 +287,7 @@ static int smbios_write_type32(ulong *current, int handle)
return len;
}
-static int smbios_write_type127(ulong *current, int handle)
+static int smbios_write_type127(ulong *current, int handle, ofnode node)
{
struct smbios_type127 *t;
int len = sizeof(struct smbios_type127);
@@ -262,19 +302,21 @@ static int smbios_write_type127(ulong *current, int handle)
return len;
}
-static smbios_write_type smbios_write_funcs[] = {
- smbios_write_type0,
- smbios_write_type1,
- smbios_write_type2,
- smbios_write_type3,
- smbios_write_type4,
- smbios_write_type32,
- smbios_write_type127
+static struct smbios_write_method smbios_write_funcs[] = {
+ { smbios_write_type0, },
+ { smbios_write_type1, "system", },
+ { smbios_write_type2, "baseboard", },
+ { smbios_write_type3, "chassis", },
+ { smbios_write_type4, },
+ { smbios_write_type32, },
+ { smbios_write_type127 },
};
ulong write_smbios_table(ulong addr)
{
+ ofnode parent_node = ofnode_null();
struct smbios_entry *se;
+ struct udevice *dev;
ulong table_addr;
ulong tables;
int len = 0;
@@ -284,6 +326,12 @@ ulong write_smbios_table(ulong addr)
int isize;
int i;
+ if (IS_ENABLED(CONFIG_OF_CONTROL)) {
+ uclass_first_device(UCLASS_SYSINFO, &dev);
+ if (dev)
+ parent_node = dev_read_subnode(dev, "smbios");
+ }
+
/* 16 byte align the table address */
addr = ALIGN(addr, 16);
@@ -296,7 +344,15 @@ ulong write_smbios_table(ulong addr)
/* populate minimum required tables */
for (i = 0; i < ARRAY_SIZE(smbios_write_funcs); i++) {
- int tmp = smbios_write_funcs[i]((ulong *)&addr, handle++);
+ const struct smbios_write_method *method;
+ ofnode node = ofnode_null();
+ int tmp;
+
+ method = &smbios_write_funcs[i];
+ if (IS_ENABLED(CONFIG_OF_CONTROL) && method->subnode_name)
+ node = ofnode_find_subnode(parent_node,
+ method->subnode_name);
+ tmp = method->write((ulong *)&addr, handle++, node);
max_struct_size = max(max_struct_size, tmp);
len += tmp;