From a37701afa373dbe35f307614779f43183fd53151 Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Mon, 28 Jun 2021 17:36:53 +0200 Subject: SMBIOS: Introduce `smbios_full_table_len` function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce the `smbios_full_table_len` function to consolidate table length calculation. The case where the length of a table equals the length of the structure happens when a table has no strings. Change-Id: Ibc60075e82eb66b5d0b7132b16da000b153413f9 Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/coreboot/+/55909 Tested-by: build bot (Jenkins) Reviewed-by: Tim Wawrzynczak Reviewed-by: Michał Żygowski --- src/arch/x86/smbios.c | 40 +++++++++++++---------- src/drivers/elog/elog.c | 2 +- src/drivers/wifi/generic/smbios.c | 2 +- src/include/smbios.h | 2 ++ src/mainboard/emulation/qemu-i440fx/northbridge.c | 4 +-- src/mainboard/pcengines/apu1/mainboard.c | 4 +-- src/mainboard/pcengines/apu2/mainboard.c | 4 +-- src/mainboard/samsung/lumpy/mainboard.c | 2 +- 8 files changed, 34 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/arch/x86/smbios.c b/src/arch/x86/smbios.c index 96b57896d4..e686992bc3 100644 --- a/src/arch/x86/smbios.c +++ b/src/arch/x86/smbios.c @@ -118,6 +118,11 @@ int smbios_string_table_len(u8 *start) return len + 1; } +int smbios_full_table_len(struct smbios_header *header, u8 *str_table_start) +{ + return header->length + smbios_string_table_len(str_table_start); +} + void *smbios_carve_table(unsigned long start, u8 type, u8 length, u16 handle) { struct smbios_header *t = (struct smbios_header *)start; @@ -329,7 +334,7 @@ static int create_smbios_type17_for_dimm(struct dimm_info *dimm, t->phys_memory_array_handle = type16_handle; *handle += 1; - return t->length + smbios_string_table_len(t->eos); + return smbios_full_table_len(&t->header, t->eos); } #define VERSION_VPD "firmware_version" @@ -429,7 +434,7 @@ static int smbios_write_type0(unsigned long *current, int handle) t->bios_characteristics_ext1 = BIOS_EXT1_CHARACTERISTICS_ACPI; t->bios_characteristics_ext2 = BIOS_EXT2_CHARACTERISTICS_TARGET; - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } @@ -528,7 +533,7 @@ static int smbios_write_type1(unsigned long *current, int handle) t->family = smbios_add_string(t->eos, CONFIG_MAINBOARD_FAMILY); #endif smbios_system_set_uuid(t->uuid); - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } @@ -548,7 +553,7 @@ static int smbios_write_type2(unsigned long *current, int handle, const int chas smbios_mainboard_location_in_chassis()); t->board_type = smbios_mainboard_board_type(); t->chassis_handle = chassis_handle; - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } @@ -568,7 +573,7 @@ static int smbios_write_type3(unsigned long *current, int handle) t->asset_tag_number = smbios_add_string(t->eos, smbios_mainboard_asset_tag()); t->version = smbios_add_string(t->eos, smbios_chassis_version()); t->serial_number = smbios_add_string(t->eos, smbios_chassis_serial_number()); - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } @@ -667,7 +672,7 @@ static int smbios_write_type4(unsigned long *current, int handle) if (cpu_voltage > 0) t->voltage = 0x80 | cpu_voltage; - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } @@ -740,7 +745,7 @@ static int smbios_write_type7(unsigned long *current, t->error_correction_type = smbios_cache_error_correction_type(level); t->system_cache_type = type; - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } @@ -901,8 +906,9 @@ int smbios_write_type8(unsigned long *current, int *handle, t->external_connector_type = port->external_connector_type; t->port_type = port->port_type; *handle += 1; - *current += t->length + smbios_string_table_len(t->eos); - totallen += t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); + *current += len; + totallen += len; } return totallen; } @@ -931,7 +937,7 @@ int smbios_write_type9(unsigned long *current, int *handle, t->device_function_number = dev_func; t->data_bus_width = SlotDataBusWidthOther; - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; *handle += 1; return len; @@ -953,7 +959,7 @@ static int smbios_write_type11(unsigned long *current, int *handle) return 0; } - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; (*handle)++; return len; @@ -999,7 +1005,7 @@ static int smbios_write_type16(unsigned long *current, int *handle) } t->number_of_memory_devices = meminfo->number_of_devices; - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; (*handle)++; return len; @@ -1074,7 +1080,7 @@ static int smbios_write_type19(unsigned long *current, int *handle, int type16) t->extended_ending_address--; } - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; *handle += 1; return len; @@ -1085,7 +1091,7 @@ static int smbios_write_type32(unsigned long *current, int handle) struct smbios_type32 *t = smbios_carve_table(*current, SMBIOS_SYSTEM_BOOT_INFORMATION, sizeof(*t), handle); - const int len = sizeof(*t); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } @@ -1107,7 +1113,7 @@ int smbios_write_type38(unsigned long *current, int *handle, t->base_address_modifier = base_modifier; t->irq = irq; - const int len = sizeof(*t); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; *handle += 1; return len; @@ -1130,7 +1136,7 @@ int smbios_write_type41(unsigned long *current, int *handle, t->device_number = device; t->function_number = function; - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; *handle += 1; return len; @@ -1141,7 +1147,7 @@ static int smbios_write_type127(unsigned long *current, int handle) struct smbios_type127 *t = smbios_carve_table(*current, SMBIOS_END_OF_TABLE, sizeof(*t), handle); - const int len = sizeof(*t); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } diff --git a/src/drivers/elog/elog.c b/src/drivers/elog/elog.c index 48b9dc365f..97555bc3f2 100644 --- a/src/drivers/elog/elog.c +++ b/src/drivers/elog/elog.c @@ -626,7 +626,7 @@ int elog_smbios_write_type15(unsigned long *current, int handle) t->log_type_descriptors = 0; t->log_type_descriptor_length = 2; - const int len = sizeof(*t); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } diff --git a/src/drivers/wifi/generic/smbios.c b/src/drivers/wifi/generic/smbios.c index e8936be386..7c697ad68f 100644 --- a/src/drivers/wifi/generic/smbios.c +++ b/src/drivers/wifi/generic/smbios.c @@ -28,7 +28,7 @@ static int smbios_write_intel_wifi(struct device *dev, int *handle, unsigned lon /* Intel wifi driver expects this string to be in the table 0x85. */ t->str = smbios_add_string(t->eos, "KHOIHGIUCCHHII"); - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; *handle += 1; return len; diff --git a/src/include/smbios.h b/src/include/smbios.h index 83900990b9..edc56f706d 100644 --- a/src/include/smbios.h +++ b/src/include/smbios.h @@ -10,6 +10,8 @@ unsigned long smbios_write_tables(unsigned long start); int smbios_add_string(u8 *start, const char *str); int smbios_string_table_len(u8 *start); +struct smbios_header; +int smbios_full_table_len(struct smbios_header *header, u8 *str_table_start); void *smbios_carve_table(unsigned long start, u8 type, u8 length, u16 handle); /* Used by mainboard to add an on-board device */ diff --git a/src/mainboard/emulation/qemu-i440fx/northbridge.c b/src/mainboard/emulation/qemu-i440fx/northbridge.c index 2f70f98f93..68410b03e7 100644 --- a/src/mainboard/emulation/qemu-i440fx/northbridge.c +++ b/src/mainboard/emulation/qemu-i440fx/northbridge.c @@ -173,7 +173,7 @@ static int qemu_get_smbios_data16(int handle, unsigned long *current) t->memory_error_correction = MEMORY_ARRAY_ECC_NONE; t->maximum_capacity = qemu_get_memory_size(); - const int len = sizeof(*t); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } @@ -195,7 +195,7 @@ static int qemu_get_smbios_data17(int handle, int parent_handle, unsigned long * t->clock_speed = 200; t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR); - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } diff --git a/src/mainboard/pcengines/apu1/mainboard.c b/src/mainboard/pcengines/apu1/mainboard.c index 87bab71651..f7b34f0c3c 100644 --- a/src/mainboard/pcengines/apu1/mainboard.c +++ b/src/mainboard/pcengines/apu1/mainboard.c @@ -180,7 +180,7 @@ static int mainboard_smbios_type16(DMI_INFO *agesa_dmi, int *handle, unsigned lo t->memory_error_information_handle = 0xfffe; t->number_of_memory_devices = 1; - const int len = sizeof(*t); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } @@ -212,7 +212,7 @@ static int mainboard_smbios_type17(DMI_INFO *agesa_dmi, int *handle, unsigned lo t->minimum_voltage = 1500; /* From SPD: 1.5V */ t->maximum_voltage = 1500; - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } diff --git a/src/mainboard/pcengines/apu2/mainboard.c b/src/mainboard/pcengines/apu2/mainboard.c index cab89a289b..9371ee9290 100644 --- a/src/mainboard/pcengines/apu2/mainboard.c +++ b/src/mainboard/pcengines/apu2/mainboard.c @@ -162,7 +162,7 @@ static int mainboard_smbios_type16(DMI_INFO *agesa_dmi, int *handle, t->memory_error_information_handle = 0xfffe; t->number_of_memory_devices = 1; - const int len = sizeof(*t); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } @@ -198,7 +198,7 @@ static int mainboard_smbios_type17(DMI_INFO *agesa_dmi, int *handle, t->minimum_voltage = 1500; /* From SPD: 1.5V */ t->maximum_voltage = 1500; - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; return len; } diff --git a/src/mainboard/samsung/lumpy/mainboard.c b/src/mainboard/samsung/lumpy/mainboard.c index 8b76a50239..d804b2b974 100644 --- a/src/mainboard/samsung/lumpy/mainboard.c +++ b/src/mainboard/samsung/lumpy/mainboard.c @@ -41,7 +41,7 @@ static int lumpy_smbios_type41_irq(int *handle, unsigned long *current, t->function_number = 0; t->device_number = 0; - const int len = t->length + smbios_string_table_len(t->eos); + const int len = smbios_full_table_len(&t->header, t->eos); *current += len; *handle += 1; return len; -- cgit v1.2.3