diff options
author | Angel Pons <th3fanbus@gmail.com> | 2021-06-28 17:18:06 +0200 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2021-07-01 07:37:21 +0000 |
commit | d62a5012d6e5904279eb56507bc2a021d2acce77 (patch) | |
tree | 2b8a4eb40ed8842ca8f237501182a3684931ac2a /src/mainboard | |
parent | ca01baa065e25242945bdfa8631694a6e903f17f (diff) |
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>
Diffstat (limited to 'src/mainboard')
-rw-r--r-- | src/mainboard/emulation/qemu-i440fx/northbridge.c | 21 | ||||
-rw-r--r-- | src/mainboard/pcengines/apu1/mainboard.c | 26 | ||||
-rw-r--r-- | src/mainboard/pcengines/apu2/mainboard.c | 26 | ||||
-rw-r--r-- | src/mainboard/samsung/lumpy/mainboard.c | 11 |
4 files changed, 26 insertions, 58 deletions
diff --git a/src/mainboard/emulation/qemu-i440fx/northbridge.c b/src/mainboard/emulation/qemu-i440fx/northbridge.c index 01d036a6a0..2f70f98f93 100644 --- a/src/mainboard/emulation/qemu-i440fx/northbridge.c +++ b/src/mainboard/emulation/qemu-i440fx/northbridge.c @@ -165,31 +165,25 @@ static void cpu_pci_domain_read_resources(struct device *dev) #if CONFIG(GENERATE_SMBIOS_TABLES) static int qemu_get_smbios_data16(int handle, unsigned long *current) { - struct smbios_type16 *t = (struct smbios_type16 *)*current; - int len = sizeof(*t); + struct smbios_type16 *t = smbios_carve_table(*current, SMBIOS_PHYS_MEMORY_ARRAY, + 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->use = MEMORY_ARRAY_USE_SYSTEM; t->memory_error_correction = MEMORY_ARRAY_ECC_NONE; t->maximum_capacity = qemu_get_memory_size(); + + const int len = sizeof(*t); *current += len; return len; } static int qemu_get_smbios_data17(int handle, int parent_handle, unsigned long *current) { - struct smbios_type17 *t = (struct smbios_type17 *)*current; - int len; + struct smbios_type17 *t = smbios_carve_table(*current, SMBIOS_MEMORY_DEVICE, + sizeof(*t), handle); - memset(t, 0, sizeof(*t)); - t->type = SMBIOS_MEMORY_DEVICE; - t->handle = handle; t->phys_memory_array_handle = parent_handle; - t->length = sizeof(*t) - 2; t->size = qemu_get_memory_size() / 1024; t->data_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->clock_speed = 200; 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; return len; } diff --git a/src/mainboard/pcengines/apu1/mainboard.c b/src/mainboard/pcengines/apu1/mainboard.c index 187f8cff3c..87bab71651 100644 --- a/src/mainboard/pcengines/apu1/mainboard.c +++ b/src/mainboard/pcengines/apu1/mainboard.c @@ -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 */ - struct smbios_type16 *t = (struct smbios_type16 *)*current; - int len = sizeof(*t); - memset(t, 0, len); - - t->type = SMBIOS_PHYS_MEMORY_ARRAY; - t->handle = *handle; - t->length = len - 2; - t->type = SMBIOS_PHYS_MEMORY_ARRAY; + struct smbios_type16 *t = smbios_carve_table(*current, SMBIOS_PHYS_MEMORY_ARRAY, + sizeof(*t), *handle); + t->use = MEMORY_ARRAY_USE_SYSTEM; t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD; 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->number_of_memory_devices = 1; + const int len = sizeof(*t); *current += len; - return len; } static int mainboard_smbios_type17(DMI_INFO *agesa_dmi, int *handle, unsigned long *current) { - struct smbios_type17 *t; - int len; + struct smbios_type17 *t = smbios_carve_table(*current, SMBIOS_MEMORY_DEVICE, + 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->memory_error_information_handle = 0xfffe; 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->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; - return len; } diff --git a/src/mainboard/pcengines/apu2/mainboard.c b/src/mainboard/pcengines/apu2/mainboard.c index 2c3b861d38..cab89a289b 100644 --- a/src/mainboard/pcengines/apu2/mainboard.c +++ b/src/mainboard/pcengines/apu2/mainboard.c @@ -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 */ - struct smbios_type16 *t = (struct smbios_type16 *)*current; - int len = sizeof(*t); - memset(t, 0, len); - - t->type = SMBIOS_PHYS_MEMORY_ARRAY; - t->handle = *handle; - t->length = len - 2; - t->type = SMBIOS_PHYS_MEMORY_ARRAY; + struct smbios_type16 *t = smbios_carve_table(*current, SMBIOS_PHYS_MEMORY_ARRAY, + sizeof(*t), *handle); + t->use = MEMORY_ARRAY_USE_SYSTEM; t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD; 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->number_of_memory_devices = 1; + const int len = sizeof(*t); *current += len; - return len; } static int mainboard_smbios_type17(DMI_INFO *agesa_dmi, int *handle, unsigned long *current) { - struct smbios_type17 *t; - int len; + struct smbios_type17 *t = smbios_carve_table(*current, SMBIOS_MEMORY_DEVICE, + 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->memory_error_information_handle = 0xfffe; 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->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; - return len; } diff --git a/src/mainboard/samsung/lumpy/mainboard.c b/src/mainboard/samsung/lumpy/mainboard.c index c2899b8e25..8b76a50239 100644 --- a/src/mainboard/samsung/lumpy/mainboard.c +++ b/src/mainboard/samsung/lumpy/mainboard.c @@ -28,13 +28,10 @@ static void mainboard_init(struct device *dev) static int lumpy_smbios_type41_irq(int *handle, unsigned long *current, const char *name, u8 irq, u8 addr) { - struct smbios_type41 *t = (struct smbios_type41 *)*current; - int len = sizeof(*t); + struct smbios_type41 *t = smbios_carve_table(*current, + 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->device_type = SMBIOS_DEVICE_TYPE_OTHER; t->device_status = 1; @@ -44,7 +41,7 @@ static int lumpy_smbios_type41_irq(int *handle, unsigned long *current, t->function_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; *handle += 1; return len; |