SMBIOS: Introduce smbios_carve_table function

Factor out some boilerplate code into a helper `smbios_carve_table`
function, which zeroes out the table memory and fills in the header
fields common to all tables.

Change-Id: Iece2f64f9151d3c79813f6264dfb3a92d98c2035
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/55907
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:
Angel Pons
2021-06-28 17:18:06 +02:00
committed by Patrick Georgi
parent ca01baa065
commit d62a5012d6
8 changed files with 94 additions and 178 deletions

View File

@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */ /* SPDX-License-Identifier: GPL-2.0-only */
#include <assert.h>
#include <string.h> #include <string.h>
#include <smbios.h> #include <smbios.h>
#include <console/console.h> #include <console/console.h>
@ -117,6 +118,18 @@ int smbios_string_table_len(u8 *start)
return len + 1; return len + 1;
} }
void *smbios_carve_table(unsigned long start, u8 type, u8 length, u16 handle)
{
struct smbios_header *t = (struct smbios_header *)start;
assert(length >= sizeof(*t));
memset(t, 0, length);
t->type = type;
t->length = length - 2;
t->handle = handle;
return t;
}
static int smbios_cpu_vendor(u8 *start) static int smbios_cpu_vendor(u8 *start)
{ {
if (cpu_have_cpuid()) { if (cpu_have_cpuid()) {
@ -241,9 +254,9 @@ static int create_smbios_type17_for_dimm(struct dimm_info *dimm,
unsigned long *current, int *handle, unsigned long *current, int *handle,
int type16_handle) int type16_handle)
{ {
struct smbios_type17 *t = (struct smbios_type17 *)*current; struct smbios_type17 *t = smbios_carve_table(*current, SMBIOS_MEMORY_DEVICE,
sizeof(*t), *handle);
memset(t, 0, sizeof(*t));
t->memory_type = dimm->ddr_type; t->memory_type = dimm->ddr_type;
if (dimm->configured_speed_mts != 0) if (dimm->configured_speed_mts != 0)
t->clock_speed = dimm->configured_speed_mts; t->clock_speed = dimm->configured_speed_mts;
@ -253,7 +266,6 @@ static int create_smbios_type17_for_dimm(struct dimm_info *dimm,
t->speed = dimm->max_speed_mts; t->speed = dimm->max_speed_mts;
else else
t->speed = dimm->ddr_frequency; t->speed = dimm->ddr_frequency;
t->type = SMBIOS_MEMORY_DEVICE;
if (dimm->dimm_size < 0x7fff) { if (dimm->dimm_size < 0x7fff) {
t->size = dimm->dimm_size; t->size = dimm->dimm_size;
} else { } else {
@ -314,11 +326,9 @@ static int create_smbios_type17_for_dimm(struct dimm_info *dimm,
/* no handle for error information */ /* no handle for error information */
t->memory_error_information_handle = 0xFFFE; t->memory_error_information_handle = 0xFFFE;
t->attributes = dimm->rank_per_dimm; t->attributes = dimm->rank_per_dimm;
t->handle = *handle;
t->phys_memory_array_handle = type16_handle; t->phys_memory_array_handle = type16_handle;
*handle += 1; *handle += 1;
t->length = sizeof(*t) - 2;
return t->length + smbios_string_table_len(t->eos); return t->length + smbios_string_table_len(t->eos);
} }
@ -379,13 +389,8 @@ static const char *get_bios_version(void)
static int smbios_write_type0(unsigned long *current, int handle) static int smbios_write_type0(unsigned long *current, int handle)
{ {
struct smbios_type0 *t = (struct smbios_type0 *)*current; struct smbios_type0 *t = smbios_carve_table(*current, SMBIOS_BIOS_INFORMATION,
int len = sizeof(*t); sizeof(*t), handle);
memset(t, 0, sizeof(*t));
t->type = SMBIOS_BIOS_INFORMATION;
t->handle = handle;
t->length = len - 2;
t->vendor = smbios_add_string(t->eos, "coreboot"); t->vendor = smbios_add_string(t->eos, "coreboot");
t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date); t->bios_release_date = smbios_add_string(t->eos, coreboot_dmi_date);
@ -424,7 +429,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;
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
return len; return len;
} }
@ -511,13 +516,9 @@ static size_t get_number_of_caches(struct cpuid_result res_deterministic_cache)
static int smbios_write_type1(unsigned long *current, int handle) static int smbios_write_type1(unsigned long *current, int handle)
{ {
struct smbios_type1 *t = (struct smbios_type1 *)*current; struct smbios_type1 *t = smbios_carve_table(*current, SMBIOS_SYSTEM_INFORMATION,
int len = sizeof(*t); sizeof(*t), handle);
memset(t, 0, sizeof(*t));
t->type = SMBIOS_SYSTEM_INFORMATION;
t->handle = handle;
t->length = len - 2;
t->manufacturer = smbios_add_string(t->eos, smbios_system_manufacturer()); t->manufacturer = smbios_add_string(t->eos, smbios_system_manufacturer());
t->product_name = smbios_add_string(t->eos, smbios_system_product_name()); t->product_name = smbios_add_string(t->eos, smbios_system_product_name());
t->serial_number = smbios_add_string(t->eos, smbios_system_serial_number()); t->serial_number = smbios_add_string(t->eos, smbios_system_serial_number());
@ -527,20 +528,16 @@ 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);
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
return len; return len;
} }
static int smbios_write_type2(unsigned long *current, int handle, const int chassis_handle) static int smbios_write_type2(unsigned long *current, int handle, const int chassis_handle)
{ {
struct smbios_type2 *t = (struct smbios_type2 *)*current; struct smbios_type2 *t = smbios_carve_table(*current, SMBIOS_BOARD_INFORMATION,
int len = sizeof(*t); sizeof(*t), handle);
memset(t, 0, sizeof(*t));
t->type = SMBIOS_BOARD_INFORMATION;
t->handle = handle;
t->length = len - 2;
t->manufacturer = smbios_add_string(t->eos, smbios_mainboard_manufacturer()); t->manufacturer = smbios_add_string(t->eos, smbios_mainboard_manufacturer());
t->product_name = smbios_add_string(t->eos, smbios_mainboard_product_name()); t->product_name = smbios_add_string(t->eos, smbios_mainboard_product_name());
t->serial_number = smbios_add_string(t->eos, smbios_mainboard_serial_number()); t->serial_number = smbios_add_string(t->eos, smbios_mainboard_serial_number());
@ -551,20 +548,16 @@ 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;
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
return len; return len;
} }
static int smbios_write_type3(unsigned long *current, int handle) static int smbios_write_type3(unsigned long *current, int handle)
{ {
struct smbios_type3 *t = (struct smbios_type3 *)*current; struct smbios_type3 *t = smbios_carve_table(*current, SMBIOS_SYSTEM_ENCLOSURE,
int len = sizeof(*t); sizeof(*t), handle);
memset(t, 0, sizeof(*t));
t->type = SMBIOS_SYSTEM_ENCLOSURE;
t->handle = handle;
t->length = len - 2;
t->manufacturer = smbios_add_string(t->eos, smbios_system_manufacturer()); t->manufacturer = smbios_add_string(t->eos, smbios_system_manufacturer());
t->bootup_state = SMBIOS_STATE_SAFE; t->bootup_state = SMBIOS_STATE_SAFE;
t->power_supply_state = SMBIOS_STATE_SAFE; t->power_supply_state = SMBIOS_STATE_SAFE;
@ -575,7 +568,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());
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
return len; return len;
} }
@ -584,8 +577,6 @@ static int smbios_write_type4(unsigned long *current, int handle)
{ {
unsigned int cpu_voltage; unsigned int cpu_voltage;
struct cpuid_result res; struct cpuid_result res;
struct smbios_type4 *t = (struct smbios_type4 *)*current;
int len = sizeof(*t);
uint16_t characteristics = 0; uint16_t characteristics = 0;
static unsigned int cnt = 0; static unsigned int cnt = 0;
char buf[8]; char buf[8];
@ -597,10 +588,8 @@ static int smbios_write_type4(unsigned long *current, int handle)
if (cpu_have_cpuid()) if (cpu_have_cpuid())
res = cpuid(1); res = cpuid(1);
memset(t, 0, sizeof(*t)); struct smbios_type4 *t = smbios_carve_table(*current, SMBIOS_PROCESSOR_INFORMATION,
t->type = SMBIOS_PROCESSOR_INFORMATION; sizeof(*t), handle);
t->handle = handle;
t->length = len - 2;
snprintf(buf, sizeof(buf), "CPU%d", cnt++); snprintf(buf, sizeof(buf), "CPU%d", cnt++);
t->socket_designation = smbios_add_string(t->eos, buf); t->socket_designation = smbios_add_string(t->eos, buf);
@ -646,7 +635,7 @@ static int smbios_write_type4(unsigned long *current, int handle)
t->serial_number = smbios_add_string(t->eos, smbios_processor_serial_number()); t->serial_number = smbios_add_string(t->eos, smbios_processor_serial_number());
t->status = SMBIOS_PROCESSOR_STATUS_CPU_ENABLED | SMBIOS_PROCESSOR_STATUS_POPULATED; t->status = SMBIOS_PROCESSOR_STATUS_CPU_ENABLED | SMBIOS_PROCESSOR_STATUS_POPULATED;
t->processor_upgrade = get_socket_type(); t->processor_upgrade = get_socket_type();
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
if (cpu_have_cpuid() && cpuid_get_max_func() >= 0x16) { if (cpu_have_cpuid() && cpuid_get_max_func() >= 0x16) {
t->current_speed = cpuid_eax(0x16); /* base frequency */ t->current_speed = cpuid_eax(0x16); /* base frequency */
t->external_clock = cpuid_ecx(0x16); t->external_clock = cpuid_ecx(0x16);
@ -697,14 +686,10 @@ static int smbios_write_type7(unsigned long *current,
const size_t max_cache_size, const size_t max_cache_size,
const size_t cache_size) const size_t cache_size)
{ {
struct smbios_type7 *t = (struct smbios_type7 *)*current;
int len = sizeof(*t);
char buf[8]; char buf[8];
memset(t, 0, sizeof(*t)); struct smbios_type7 *t = smbios_carve_table(*current, SMBIOS_CACHE_INFORMATION,
t->type = SMBIOS_CACHE_INFORMATION; sizeof(*t), handle);
t->handle = handle;
t->length = len - 2;
snprintf(buf, sizeof(buf), "CACHE%x", level); snprintf(buf, sizeof(buf), "CACHE%x", level);
t->socket_designation = smbios_add_string(t->eos, buf); t->socket_designation = smbios_add_string(t->eos, buf);
@ -755,7 +740,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;
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
return len; return len;
} }
@ -905,11 +890,9 @@ int smbios_write_type8(unsigned long *current, int *handle,
unsigned int totallen = 0, i; unsigned int totallen = 0, i;
for (i = 0; i < num_ports; i++, port++) { for (i = 0; i < num_ports; i++, port++) {
struct smbios_type8 *t = (struct smbios_type8 *)*current; struct smbios_type8 *t = smbios_carve_table(*current,
memset(t, 0, sizeof(*t)); SMBIOS_PORT_CONNECTOR_INFORMATION,
t->type = SMBIOS_PORT_CONNECTOR_INFORMATION; sizeof(*t), *handle);
t->handle = *handle;
t->length = sizeof(*t) - 2;
t->internal_reference_designator = t->internal_reference_designator =
smbios_add_string(t->eos, port->internal_reference_designator); smbios_add_string(t->eos, port->internal_reference_designator);
t->internal_connector_type = port->internal_connector_type; t->internal_connector_type = port->internal_connector_type;
@ -931,13 +914,9 @@ int smbios_write_type9(unsigned long *current, int *handle,
const enum misc_slot_length length, const enum misc_slot_length length,
const u16 id, u8 slot_char1, u8 slot_char2, u8 bus, u8 dev_func) const u16 id, u8 slot_char1, u8 slot_char2, u8 bus, u8 dev_func)
{ {
struct smbios_type9 *t = (struct smbios_type9 *)*current; struct smbios_type9 *t = smbios_carve_table(*current, SMBIOS_SYSTEM_SLOTS,
int len = sizeof(*t); sizeof(*t), *handle);
memset(t, 0, sizeof(*t));
t->type = SMBIOS_SYSTEM_SLOTS;
t->handle = *handle;
t->length = len - 2;
t->slot_designation = smbios_add_string(t->eos, name ? name : "SLOT"); t->slot_designation = smbios_add_string(t->eos, name ? name : "SLOT");
t->slot_type = type; t->slot_type = type;
/* TODO add slot_id supoort, will be "_SUN" for ACPI devices */ /* TODO add slot_id supoort, will be "_SUN" for ACPI devices */
@ -952,7 +931,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;
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
*handle += 1; *handle += 1;
return len; return len;
@ -960,14 +939,9 @@ int smbios_write_type9(unsigned long *current, int *handle,
static int smbios_write_type11(unsigned long *current, int *handle) static int smbios_write_type11(unsigned long *current, int *handle)
{ {
struct smbios_type11 *t = (struct smbios_type11 *)*current;
int len;
struct device *dev; struct device *dev;
struct smbios_type11 *t = smbios_carve_table(*current, SMBIOS_OEM_STRINGS,
memset(t, 0, sizeof(*t)); sizeof(*t), *handle);
t->type = SMBIOS_OEM_STRINGS;
t->handle = *handle;
t->length = len = sizeof(*t) - 2;
for (dev = all_devices; dev; dev = dev->next) { for (dev = all_devices; dev; dev = dev->next) {
if (dev->ops && dev->ops->get_smbios_strings) if (dev->ops && dev->ops->get_smbios_strings)
@ -979,8 +953,7 @@ static int smbios_write_type11(unsigned long *current, int *handle)
return 0; return 0;
} }
len += smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
(*handle)++; (*handle)++;
return len; return len;
@ -988,9 +961,6 @@ static int smbios_write_type11(unsigned long *current, int *handle)
static int smbios_write_type16(unsigned long *current, int *handle) static int smbios_write_type16(unsigned long *current, int *handle)
{ {
struct smbios_type16 *t = (struct smbios_type16 *)*current;
int len;
int i; int i;
uint64_t max_capacity; uint64_t max_capacity;
@ -1011,10 +981,8 @@ static int smbios_write_type16(unsigned long *current, int *handle)
} }
} }
memset(t, 0, sizeof(*t)); struct smbios_type16 *t = smbios_carve_table(*current, SMBIOS_PHYS_MEMORY_ARRAY,
t->type = SMBIOS_PHYS_MEMORY_ARRAY; sizeof(*t), *handle);
t->handle = *handle;
t->length = len = sizeof(*t) - 2;
t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD; t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD;
t->use = MEMORY_ARRAY_USE_SYSTEM; t->use = MEMORY_ARRAY_USE_SYSTEM;
@ -1031,8 +999,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;
len += smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
(*handle)++; (*handle)++;
return len; return len;
@ -1067,7 +1034,6 @@ static int smbios_write_type17(unsigned long *current, int *handle, int type16)
static int smbios_write_type19(unsigned long *current, int *handle, int type16) static int smbios_write_type19(unsigned long *current, int *handle, int type16)
{ {
struct smbios_type19 *t = (struct smbios_type19 *)*current;
int i; int i;
struct memory_info *meminfo; struct memory_info *meminfo;
@ -1075,11 +1041,10 @@ static int smbios_write_type19(unsigned long *current, int *handle, int type16)
if (meminfo == NULL) if (meminfo == NULL)
return 0; /* can't find mem info in cbmem */ return 0; /* can't find mem info in cbmem */
memset(t, 0, sizeof(*t)); struct smbios_type19 *t = smbios_carve_table(*current,
SMBIOS_MEMORY_ARRAY_MAPPED_ADDRESS,
sizeof(*t), *handle);
t->type = SMBIOS_MEMORY_ARRAY_MAPPED_ADDRESS;
t->length = sizeof(*t) - 2;
t->handle = *handle;
t->memory_array_handle = type16; t->memory_array_handle = type16;
for (i = 0; i < meminfo->dimm_cnt && i < ARRAY_SIZE(meminfo->dimm); i++) { for (i = 0; i < meminfo->dimm_cnt && i < ARRAY_SIZE(meminfo->dimm); i++) {
@ -1117,13 +1082,10 @@ static int smbios_write_type19(unsigned long *current, int *handle, int type16)
static int smbios_write_type32(unsigned long *current, int handle) static int smbios_write_type32(unsigned long *current, int handle)
{ {
struct smbios_type32 *t = (struct smbios_type32 *)*current; struct smbios_type32 *t = smbios_carve_table(*current, SMBIOS_SYSTEM_BOOT_INFORMATION,
int len = sizeof(*t); sizeof(*t), handle);
memset(t, 0, sizeof(*t)); const int len = sizeof(*t);
t->type = SMBIOS_SYSTEM_BOOT_INFORMATION;
t->handle = handle;
t->length = len - 2;
*current += len; *current += len;
return len; return len;
} }
@ -1134,13 +1096,9 @@ int smbios_write_type38(unsigned long *current, int *handle,
const u64 base_addr, const u8 base_modifier, const u64 base_addr, const u8 base_modifier,
const u8 irq) const u8 irq)
{ {
struct smbios_type38 *t = (struct smbios_type38 *)*current; struct smbios_type38 *t = smbios_carve_table(*current, SMBIOS_IPMI_DEVICE_INFORMATION,
int len = sizeof(*t); sizeof(*t), *handle);
memset(t, 0, sizeof(*t));
t->type = SMBIOS_IPMI_DEVICE_INFORMATION;
t->handle = *handle;
t->length = len - 2;
t->interface_type = interface_type; t->interface_type = interface_type;
t->ipmi_rev = ipmi_rev; t->ipmi_rev = ipmi_rev;
t->i2c_slave_addr = i2c_addr; t->i2c_slave_addr = i2c_addr;
@ -1149,9 +1107,9 @@ 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);
*current += len; *current += len;
*handle += 1; *handle += 1;
return len; return len;
} }
@ -1159,13 +1117,10 @@ int smbios_write_type41(unsigned long *current, int *handle,
const char *name, u8 instance, u16 segment, const char *name, u8 instance, u16 segment,
u8 bus, u8 device, u8 function, u8 device_type) u8 bus, u8 device, u8 function, u8 device_type)
{ {
struct smbios_type41 *t = (struct smbios_type41 *)*current; struct smbios_type41 *t = smbios_carve_table(*current,
int len = sizeof(*t); SMBIOS_ONBOARD_DEVICES_EXTENDED_INFORMATION,
sizeof(*t), *handle);
memset(t, 0, sizeof(*t));
t->type = SMBIOS_ONBOARD_DEVICES_EXTENDED_INFORMATION;
t->handle = *handle;
t->length = len - 2;
t->reference_designation = smbios_add_string(t->eos, name); t->reference_designation = smbios_add_string(t->eos, name);
t->device_type = device_type; t->device_type = device_type;
t->device_status = 1; t->device_status = 1;
@ -1175,7 +1130,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;
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
*handle += 1; *handle += 1;
return len; return len;
@ -1183,13 +1138,10 @@ int smbios_write_type41(unsigned long *current, int *handle,
static int smbios_write_type127(unsigned long *current, int handle) static int smbios_write_type127(unsigned long *current, int handle)
{ {
struct smbios_type127 *t = (struct smbios_type127 *)*current; struct smbios_type127 *t = smbios_carve_table(*current, SMBIOS_END_OF_TABLE,
int len = sizeof(*t); sizeof(*t), handle);
memset(t, 0, sizeof(*t)); const int len = sizeof(*t);
t->type = SMBIOS_END_OF_TABLE;
t->handle = handle;
t->length = len - 2;
*current += len; *current += len;
return len; return len;
} }

View File

@ -593,8 +593,6 @@ static inline u8 *elog_flash_offset_to_address(void)
*/ */
int elog_smbios_write_type15(unsigned long *current, int handle) int elog_smbios_write_type15(unsigned long *current, int handle)
{ {
struct smbios_type15 *t = (struct smbios_type15 *)*current;
int len = sizeof(*t);
uintptr_t log_address; uintptr_t log_address;
size_t elog_size = region_device_sz(&elog_state.nv_dev); size_t elog_size = region_device_sz(&elog_state.nv_dev);
@ -614,10 +612,9 @@ int elog_smbios_write_type15(unsigned long *current, int handle)
return 0; return 0;
} }
memset(t, 0, len); struct smbios_type15 *t = smbios_carve_table(*current, SMBIOS_EVENT_LOG,
t->type = SMBIOS_EVENT_LOG; sizeof(*t), handle);
t->length = len - 2;
t->handle = handle;
t->area_length = elog_size - 1; t->area_length = elog_size - 1;
t->header_offset = 0; t->header_offset = 0;
t->data_offset = sizeof(struct elog_header); t->data_offset = sizeof(struct elog_header);
@ -629,6 +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);
*current += len; *current += len;
return len; return len;
} }

View File

@ -22,17 +22,13 @@ static int smbios_write_intel_wifi(struct device *dev, int *handle, unsigned lon
u8 eos[2]; u8 eos[2];
} __packed; } __packed;
struct smbios_type_intel_wifi *t = (struct smbios_type_intel_wifi *)*current; struct smbios_type_intel_wifi *t = smbios_carve_table(*current, 0x85,
int len = sizeof(*t); sizeof(*t), *handle);
memset(t, 0, sizeof(*t));
t->type = 0x85;
t->length = len - 2;
t->handle = *handle;
/* 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");
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
*handle += 1; *handle += 1;
return len; return len;

View File

@ -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);
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 */
enum misc_slot_type; enum misc_slot_type;
enum misc_slot_length; enum misc_slot_length;

View File

@ -165,31 +165,25 @@ static void cpu_pci_domain_read_resources(struct device *dev)
#if CONFIG(GENERATE_SMBIOS_TABLES) #if CONFIG(GENERATE_SMBIOS_TABLES)
static int qemu_get_smbios_data16(int handle, unsigned long *current) static int qemu_get_smbios_data16(int handle, unsigned long *current)
{ {
struct smbios_type16 *t = (struct smbios_type16 *)*current; struct smbios_type16 *t = smbios_carve_table(*current, SMBIOS_PHYS_MEMORY_ARRAY,
int len = sizeof(*t); sizeof(*t), handle);
memset(t, 0, sizeof(*t));
t->type = SMBIOS_PHYS_MEMORY_ARRAY;
t->handle = handle;
t->length = len - 2;
t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD; t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD;
t->use = MEMORY_ARRAY_USE_SYSTEM; t->use = MEMORY_ARRAY_USE_SYSTEM;
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);
*current += len; *current += len;
return len; return len;
} }
static int qemu_get_smbios_data17(int handle, int parent_handle, unsigned long *current) static int qemu_get_smbios_data17(int handle, int parent_handle, unsigned long *current)
{ {
struct smbios_type17 *t = (struct smbios_type17 *)*current; struct smbios_type17 *t = smbios_carve_table(*current, SMBIOS_MEMORY_DEVICE,
int len; sizeof(*t), handle);
memset(t, 0, sizeof(*t));
t->type = SMBIOS_MEMORY_DEVICE;
t->handle = handle;
t->phys_memory_array_handle = parent_handle; t->phys_memory_array_handle = parent_handle;
t->length = sizeof(*t) - 2;
t->size = qemu_get_memory_size() / 1024; t->size = qemu_get_memory_size() / 1024;
t->data_width = 64; t->data_width = 64;
t->total_width = 64; t->total_width = 64;
@ -200,7 +194,8 @@ static int qemu_get_smbios_data17(int handle, int parent_handle, unsigned long *
t->speed = 200; t->speed = 200;
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);
len = t->length + smbios_string_table_len(t->eos);
const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
return len; return len;
} }

View File

@ -170,14 +170,9 @@ static int mainboard_smbios_type16(DMI_INFO *agesa_dmi, int *handle, unsigned lo
{ {
const u32 max_capacity = get_spd_offset() ? 4 : 2; /* 4GB or 2GB variant */ const u32 max_capacity = get_spd_offset() ? 4 : 2; /* 4GB or 2GB variant */
struct smbios_type16 *t = (struct smbios_type16 *)*current; struct smbios_type16 *t = smbios_carve_table(*current, SMBIOS_PHYS_MEMORY_ARRAY,
int len = sizeof(*t); sizeof(*t), *handle);
memset(t, 0, len);
t->type = SMBIOS_PHYS_MEMORY_ARRAY;
t->handle = *handle;
t->length = len - 2;
t->type = SMBIOS_PHYS_MEMORY_ARRAY;
t->use = MEMORY_ARRAY_USE_SYSTEM; t->use = MEMORY_ARRAY_USE_SYSTEM;
t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD; t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD;
t->memory_error_correction = agesa_dmi->T16.MemoryErrorCorrection; t->memory_error_correction = agesa_dmi->T16.MemoryErrorCorrection;
@ -185,22 +180,16 @@ 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);
*current += len; *current += len;
return len; return len;
} }
static int mainboard_smbios_type17(DMI_INFO *agesa_dmi, int *handle, unsigned long *current) static int mainboard_smbios_type17(DMI_INFO *agesa_dmi, int *handle, unsigned long *current)
{ {
struct smbios_type17 *t; struct smbios_type17 *t = smbios_carve_table(*current, SMBIOS_MEMORY_DEVICE,
int len; sizeof(*t), *handle + 1);
t = (struct smbios_type17 *)*current;
memset(t, 0, sizeof(*t));
t->type = SMBIOS_MEMORY_DEVICE;
t->length = sizeof(*t) - 2;
t->handle = *handle + 1;
t->phys_memory_array_handle = *handle; t->phys_memory_array_handle = *handle;
t->memory_error_information_handle = 0xfffe; t->memory_error_information_handle = 0xfffe;
t->total_width = agesa_dmi->T17[0][0][0].TotalWidth; t->total_width = agesa_dmi->T17[0][0][0].TotalWidth;
@ -223,9 +212,8 @@ 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;
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
return len; return len;
} }

View File

@ -152,14 +152,9 @@ static int mainboard_smbios_type16(DMI_INFO *agesa_dmi, int *handle,
{ {
const u32 max_capacity = get_spd_offset() ? 4 : 2; /* 4GB or 2GB variant */ const u32 max_capacity = get_spd_offset() ? 4 : 2; /* 4GB or 2GB variant */
struct smbios_type16 *t = (struct smbios_type16 *)*current; struct smbios_type16 *t = smbios_carve_table(*current, SMBIOS_PHYS_MEMORY_ARRAY,
int len = sizeof(*t); sizeof(*t), *handle);
memset(t, 0, len);
t->type = SMBIOS_PHYS_MEMORY_ARRAY;
t->handle = *handle;
t->length = len - 2;
t->type = SMBIOS_PHYS_MEMORY_ARRAY;
t->use = MEMORY_ARRAY_USE_SYSTEM; t->use = MEMORY_ARRAY_USE_SYSTEM;
t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD; t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD;
t->memory_error_correction = agesa_dmi->T16.MemoryErrorCorrection; t->memory_error_correction = agesa_dmi->T16.MemoryErrorCorrection;
@ -167,23 +162,17 @@ 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);
*current += len; *current += len;
return len; return len;
} }
static int mainboard_smbios_type17(DMI_INFO *agesa_dmi, int *handle, static int mainboard_smbios_type17(DMI_INFO *agesa_dmi, int *handle,
unsigned long *current) unsigned long *current)
{ {
struct smbios_type17 *t; struct smbios_type17 *t = smbios_carve_table(*current, SMBIOS_MEMORY_DEVICE,
int len; sizeof(*t), *handle + 1);
t = (struct smbios_type17 *)*current;
memset(t, 0, sizeof(*t));
t->type = SMBIOS_MEMORY_DEVICE;
t->length = sizeof(*t) - 2;
t->handle = *handle + 1;
t->phys_memory_array_handle = *handle; t->phys_memory_array_handle = *handle;
t->memory_error_information_handle = 0xfffe; t->memory_error_information_handle = 0xfffe;
t->total_width = agesa_dmi->T17[0][0][0].TotalWidth; t->total_width = agesa_dmi->T17[0][0][0].TotalWidth;
@ -209,9 +198,8 @@ 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;
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
return len; return len;
} }

View File

@ -28,13 +28,10 @@ static void mainboard_init(struct device *dev)
static int lumpy_smbios_type41_irq(int *handle, unsigned long *current, static int lumpy_smbios_type41_irq(int *handle, unsigned long *current,
const char *name, u8 irq, u8 addr) const char *name, u8 irq, u8 addr)
{ {
struct smbios_type41 *t = (struct smbios_type41 *)*current; struct smbios_type41 *t = smbios_carve_table(*current,
int len = sizeof(*t); SMBIOS_ONBOARD_DEVICES_EXTENDED_INFORMATION,
sizeof(*t), *handle);
memset(t, 0, sizeof(*t));
t->type = SMBIOS_ONBOARD_DEVICES_EXTENDED_INFORMATION;
t->handle = *handle;
t->length = len - 2;
t->reference_designation = smbios_add_string(t->eos, name); t->reference_designation = smbios_add_string(t->eos, name);
t->device_type = SMBIOS_DEVICE_TYPE_OTHER; t->device_type = SMBIOS_DEVICE_TYPE_OTHER;
t->device_status = 1; t->device_status = 1;
@ -44,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;
len = t->length + smbios_string_table_len(t->eos); const int len = t->length + smbios_string_table_len(t->eos);
*current += len; *current += len;
*handle += 1; *handle += 1;
return len; return len;