Patrick Georgi has submitted this change. ( https://review.coreboot.org/c/coreboot/+/55909 )
Change subject: SMBIOS: Introduce `smbios_full_table_len` function ......................................................................
SMBIOS: Introduce `smbios_full_table_len` function
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 th3fanbus@gmail.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/55909 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Tim Wawrzynczak twawrzynczak@chromium.org Reviewed-by: Michał Żygowski michal.zygowski@3mdeb.com --- M src/arch/x86/smbios.c M src/drivers/elog/elog.c M src/drivers/wifi/generic/smbios.c M src/include/smbios.h M src/mainboard/emulation/qemu-i440fx/northbridge.c M src/mainboard/pcengines/apu1/mainboard.c M src/mainboard/pcengines/apu2/mainboard.c M src/mainboard/samsung/lumpy/mainboard.c 8 files changed, 34 insertions(+), 26 deletions(-)
Approvals: build bot (Jenkins): Verified Michał Żygowski: Looks good to me, approved Tim Wawrzynczak: Looks good to me, approved
diff --git a/src/arch/x86/smbios.c b/src/arch/x86/smbios.c index 96b5789..e686992 100644 --- a/src/arch/x86/smbios.c +++ b/src/arch/x86/smbios.c @@ -118,6 +118,11 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ } 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 48b9dc3..97555bc 100644 --- a/src/drivers/elog/elog.c +++ b/src/drivers/elog/elog.c @@ -626,7 +626,7 @@ 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 e8936be..7c697ad 100644 --- a/src/drivers/wifi/generic/smbios.c +++ b/src/drivers/wifi/generic/smbios.c @@ -28,7 +28,7 @@ /* 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 8390099..edc56f7 100644 --- a/src/include/smbios.h +++ b/src/include/smbios.h @@ -10,6 +10,8 @@ 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 2f70f98..68410b0 100644 --- a/src/mainboard/emulation/qemu-i440fx/northbridge.c +++ b/src/mainboard/emulation/qemu-i440fx/northbridge.c @@ -173,7 +173,7 @@ 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 @@ 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 87bab71..f7b34f0 100644 --- a/src/mainboard/pcengines/apu1/mainboard.c +++ b/src/mainboard/pcengines/apu1/mainboard.c @@ -180,7 +180,7 @@ 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 @@ 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 cab89a2..9371ee9 100644 --- a/src/mainboard/pcengines/apu2/mainboard.c +++ b/src/mainboard/pcengines/apu2/mainboard.c @@ -162,7 +162,7 @@ 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 @@ 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 8b76a50..d804b2b 100644 --- a/src/mainboard/samsung/lumpy/mainboard.c +++ b/src/mainboard/samsung/lumpy/mainboard.c @@ -41,7 +41,7 @@ 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;