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>
This commit is contained in:
parent
b977c1ade3
commit
a37701afa3
|
@ -118,6 +118,11 @@ int smbios_string_table_len(u8 *start)
|
||||||
return len + 1;
|
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)
|
void *smbios_carve_table(unsigned long start, u8 type, u8 length, u16 handle)
|
||||||
{
|
{
|
||||||
struct smbios_header *t = (struct smbios_header *)start;
|
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;
|
t->phys_memory_array_handle = type16_handle;
|
||||||
|
|
||||||
*handle += 1;
|
*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"
|
#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_ext1 = BIOS_EXT1_CHARACTERISTICS_ACPI;
|
||||||
|
|
||||||
t->bios_characteristics_ext2 = BIOS_EXT2_CHARACTERISTICS_TARGET;
|
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;
|
*current += len;
|
||||||
return 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);
|
t->family = smbios_add_string(t->eos, CONFIG_MAINBOARD_FAMILY);
|
||||||
#endif
|
#endif
|
||||||
smbios_system_set_uuid(t->uuid);
|
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;
|
*current += len;
|
||||||
return 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());
|
smbios_mainboard_location_in_chassis());
|
||||||
t->board_type = smbios_mainboard_board_type();
|
t->board_type = smbios_mainboard_board_type();
|
||||||
t->chassis_handle = chassis_handle;
|
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;
|
*current += len;
|
||||||
return 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->asset_tag_number = smbios_add_string(t->eos, smbios_mainboard_asset_tag());
|
||||||
t->version = smbios_add_string(t->eos, smbios_chassis_version());
|
t->version = smbios_add_string(t->eos, smbios_chassis_version());
|
||||||
t->serial_number = smbios_add_string(t->eos, smbios_chassis_serial_number());
|
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;
|
*current += len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
@ -667,7 +672,7 @@ static int smbios_write_type4(unsigned long *current, int handle)
|
||||||
if (cpu_voltage > 0)
|
if (cpu_voltage > 0)
|
||||||
t->voltage = 0x80 | cpu_voltage;
|
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;
|
*current += len;
|
||||||
return 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->error_correction_type = smbios_cache_error_correction_type(level);
|
||||||
t->system_cache_type = type;
|
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;
|
*current += len;
|
||||||
return 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->external_connector_type = port->external_connector_type;
|
||||||
t->port_type = port->port_type;
|
t->port_type = port->port_type;
|
||||||
*handle += 1;
|
*handle += 1;
|
||||||
*current += t->length + smbios_string_table_len(t->eos);
|
const int len = smbios_full_table_len(&t->header, t->eos);
|
||||||
totallen += t->length + smbios_string_table_len(t->eos);
|
*current += len;
|
||||||
|
totallen += len;
|
||||||
}
|
}
|
||||||
return totallen;
|
return totallen;
|
||||||
}
|
}
|
||||||
|
@ -931,7 +937,7 @@ int smbios_write_type9(unsigned long *current, int *handle,
|
||||||
t->device_function_number = dev_func;
|
t->device_function_number = dev_func;
|
||||||
t->data_bus_width = SlotDataBusWidthOther;
|
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;
|
*current += len;
|
||||||
*handle += 1;
|
*handle += 1;
|
||||||
return len;
|
return len;
|
||||||
|
@ -953,7 +959,7 @@ static int smbios_write_type11(unsigned long *current, int *handle)
|
||||||
return 0;
|
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;
|
*current += len;
|
||||||
(*handle)++;
|
(*handle)++;
|
||||||
return len;
|
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;
|
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;
|
*current += len;
|
||||||
(*handle)++;
|
(*handle)++;
|
||||||
return len;
|
return len;
|
||||||
|
@ -1074,7 +1080,7 @@ static int smbios_write_type19(unsigned long *current, int *handle, int type16)
|
||||||
t->extended_ending_address--;
|
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;
|
*current += len;
|
||||||
*handle += 1;
|
*handle += 1;
|
||||||
return len;
|
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,
|
struct smbios_type32 *t = smbios_carve_table(*current, SMBIOS_SYSTEM_BOOT_INFORMATION,
|
||||||
sizeof(*t), handle);
|
sizeof(*t), handle);
|
||||||
|
|
||||||
const int len = sizeof(*t);
|
const int len = smbios_full_table_len(&t->header, t->eos);
|
||||||
*current += len;
|
*current += len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
@ -1107,7 +1113,7 @@ int smbios_write_type38(unsigned long *current, int *handle,
|
||||||
t->base_address_modifier = base_modifier;
|
t->base_address_modifier = base_modifier;
|
||||||
t->irq = irq;
|
t->irq = irq;
|
||||||
|
|
||||||
const int len = sizeof(*t);
|
const int len = smbios_full_table_len(&t->header, t->eos);
|
||||||
*current += len;
|
*current += len;
|
||||||
*handle += 1;
|
*handle += 1;
|
||||||
return len;
|
return len;
|
||||||
|
@ -1130,7 +1136,7 @@ int smbios_write_type41(unsigned long *current, int *handle,
|
||||||
t->device_number = device;
|
t->device_number = device;
|
||||||
t->function_number = function;
|
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;
|
*current += len;
|
||||||
*handle += 1;
|
*handle += 1;
|
||||||
return len;
|
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,
|
struct smbios_type127 *t = smbios_carve_table(*current, SMBIOS_END_OF_TABLE,
|
||||||
sizeof(*t), handle);
|
sizeof(*t), handle);
|
||||||
|
|
||||||
const int len = sizeof(*t);
|
const int len = smbios_full_table_len(&t->header, t->eos);
|
||||||
*current += len;
|
*current += len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -626,7 +626,7 @@ int elog_smbios_write_type15(unsigned long *current, int handle)
|
||||||
t->log_type_descriptors = 0;
|
t->log_type_descriptors = 0;
|
||||||
t->log_type_descriptor_length = 2;
|
t->log_type_descriptor_length = 2;
|
||||||
|
|
||||||
const int len = sizeof(*t);
|
const int len = smbios_full_table_len(&t->header, t->eos);
|
||||||
*current += len;
|
*current += len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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. */
|
/* Intel wifi driver expects this string to be in the table 0x85. */
|
||||||
t->str = smbios_add_string(t->eos, "KHOIHGIUCCHHII");
|
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;
|
*current += len;
|
||||||
*handle += 1;
|
*handle += 1;
|
||||||
return len;
|
return len;
|
||||||
|
|
|
@ -10,6 +10,8 @@ unsigned long smbios_write_tables(unsigned long start);
|
||||||
int smbios_add_string(u8 *start, const char *str);
|
int smbios_add_string(u8 *start, const char *str);
|
||||||
int smbios_string_table_len(u8 *start);
|
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);
|
void *smbios_carve_table(unsigned long start, u8 type, u8 length, u16 handle);
|
||||||
|
|
||||||
/* Used by mainboard to add an on-board device */
|
/* Used by mainboard to add an on-board device */
|
||||||
|
|
|
@ -173,7 +173,7 @@ static int qemu_get_smbios_data16(int handle, unsigned long *current)
|
||||||
t->memory_error_correction = MEMORY_ARRAY_ECC_NONE;
|
t->memory_error_correction = MEMORY_ARRAY_ECC_NONE;
|
||||||
t->maximum_capacity = qemu_get_memory_size();
|
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;
|
*current += len;
|
||||||
return 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->clock_speed = 200;
|
||||||
t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR);
|
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;
|
*current += len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,7 +180,7 @@ static int mainboard_smbios_type16(DMI_INFO *agesa_dmi, int *handle, unsigned lo
|
||||||
t->memory_error_information_handle = 0xfffe;
|
t->memory_error_information_handle = 0xfffe;
|
||||||
t->number_of_memory_devices = 1;
|
t->number_of_memory_devices = 1;
|
||||||
|
|
||||||
const int len = sizeof(*t);
|
const int len = smbios_full_table_len(&t->header, t->eos);
|
||||||
*current += len;
|
*current += len;
|
||||||
return 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->minimum_voltage = 1500; /* From SPD: 1.5V */
|
||||||
t->maximum_voltage = 1500;
|
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;
|
*current += len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ static int mainboard_smbios_type16(DMI_INFO *agesa_dmi, int *handle,
|
||||||
t->memory_error_information_handle = 0xfffe;
|
t->memory_error_information_handle = 0xfffe;
|
||||||
t->number_of_memory_devices = 1;
|
t->number_of_memory_devices = 1;
|
||||||
|
|
||||||
const int len = sizeof(*t);
|
const int len = smbios_full_table_len(&t->header, t->eos);
|
||||||
*current += len;
|
*current += len;
|
||||||
return 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->minimum_voltage = 1500; /* From SPD: 1.5V */
|
||||||
t->maximum_voltage = 1500;
|
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;
|
*current += len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ static int lumpy_smbios_type41_irq(int *handle, unsigned long *current,
|
||||||
t->function_number = 0;
|
t->function_number = 0;
|
||||||
t->device_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;
|
*current += len;
|
||||||
*handle += 1;
|
*handle += 1;
|
||||||
return len;
|
return len;
|
||||||
|
|
Loading…
Reference in New Issue