efi_loader: Expose SMBIOS table
Subsystems (2)
v3 cover efi_loader: Expose SMBIOS table
We generate a few tables on x86 today that really can be used on ARM just the same. One such example is the SMBIOS table, which people use with tools like "dmidecode" to identify which hardware they are running on.
We're slowly growing needs to collect serial numbers from various devices on ARM and SMBIOS seems the natural choice. So this patch set moves the current SMBIOS generation into generic code and adds serial number exposure to it.
I have verified that I get a correct serial number printed in dmidecode on the RPi3.
v1 -> v2:
- Also populate UUID
- Fix whitespace
v2 -> v3:
- Move efi smbios generation to own file
- New patch: Make type4 table available on all archs
Alexander Graf (8):
x86: Move table csum into separate header
x86: Move smbios generation into arch independent directory
efi_loader: Expose efi_install_configuration_table
smbios: Allow compilation on 64bit systems
smbios: Generate type 4 on non-x86 systems
smbios: Expose in efi_loader as table
efi_loader: Fix efi_install_configuration_table
smbios: Provide serial number
arch/x86/Kconfig | 27 ------------
arch/x86/include/asm/tables.h | 2 +
arch/x86/lib/Makefile | 1 -
arch/x86/lib/tables.c | 21 ++++------
cmd/bootefi.c | 3 ++
include/efi_api.h | 4 ++
include/efi_loader.h | 4 ++
{arch/x86/include/asm => include}/smbios.h | 8 +++-
include/tables_csum.h | 22 ++++++++++
lib/Kconfig | 33 +++++++++++++++
lib/Makefile | 1 +
lib/efi_loader/Makefile | 1 +
lib/efi_loader/efi_boottime.c | 24 ++++++-----
lib/efi_loader/efi_smbios.c | 32 +++++++++++++++
{arch/x86/lib => lib}/smbios.c | 66 +++++++++++++++++++++---------
15 files changed, 176 insertions(+), 73 deletions(-)
rename {arch/x86/include/asm => include}/smbios.h (95%)
create mode 100644 include/tables_csum.h
create mode 100644 lib/efi_loader/efi_smbios.c
rename {arch/x86/lib => lib}/smbios.c (83%)Signature · 1 line
1.8.5.6
PATCH v3 1/8 x86: Move table csum into separate header
We need the checksum function without all the other table functionality soon, so let's split it out into its own header file.
--- arch/x86/include/asm/tables.h | 2 ++ arch/x86/lib/tables.c | 12 ------------ include/tables_csum.h | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 include/tables_csum.h
arch/x86/include/asm/tables.h +2 -0
@@ -7,6 +7,8 @@#ifndef _X86_TABLES_H_#define _X86_TABLES_H_ +#include <tables_csum.h> +/* * All x86 tables happen to like the address range from 0xf0000 to 0x100000. * We use 0xf0000 as the starting address to store those tables, including
arch/x86/lib/tables.c +0 -12
@@ -38,18 +38,6 @@ static table_write table_write_funcs[] = {#endif }; -u8 table_compute_checksum (void *v,int len) -{ -u8 *bytes = v; -u8 checksum =0 ; -int i; - -for (i =0 ; i < len; i++) - checksum -= bytes[i]; - -return checksum; -} -void table_fill_string (char *dest,const char *src,size_t n,char pad) {int start, len;
include/tables_csum.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2015, Bin Meng <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _TABLES_CSUM_H_ +#define _TABLES_CSUM_H_ + +static inline u8 table_compute_checksum (void *v,int len) +{ +u8 *bytes = v; +u8 checksum =0 ; +int i; + +for (i =0 ; i < len; i++) + checksum -= bytes[i]; + +return checksum; +} + +#endif
Signature · 1 line
1.8.5.6
PATCH v3 1/8 x86: Move table csum into separate header
Hi Alex,
Quoted 11 lines · Alexander Graf
We need the checksum function without all the other table functionality soon, so let's split it out into its own header file.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Bin Meng <[email protected]>--- arch/x86/include/asm/tables.h | 2 ++ arch/x86/lib/tables.c | 12 ------------ include/tables_csum.h | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 include/tables_csum.h
Question below
Quoted 43 lines
arch/x86/include/asm/tables.h +2
-0@@ -7,6 +7,8 @@#ifndef _X86_TABLES_H_#define _X86_TABLES_H_ +#include <tables_csum.h> +/* * All x86 tables happen to like the address range from 0xf0000 to 0x100000. * We use 0xf0000 as the starting address to store those tables, including arch/x86/lib/tables.c +0
-12@@ -38,18 +38,6 @@ static table_write table_write_funcs[] = {#endif }; -u8 table_compute_checksum (void *v,int len) -{ -u8 *bytes = v; -u8 checksum =0 ; -int i; - -for (i =0 ; i < len; i++) - checksum -= bytes[i]; - -return checksum; -} -void table_fill_string (char *dest,const char *src,size_t n,char pad) {int start, len;include/tables_csum.h new file +0
-0
include/tables_csum.h line 10
Quoted 10 lines
include/tables_csum.h new file +10
-0@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2015, Bin Meng <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _TABLES_CSUM_H_ +#define _TABLES_CSUM_H_ + +static inline u8 table_compute_checksum (void *v,int len)
Why is this static inline? Shouldn't it go in a C file?
Quoted 13 lines
include/tables_csum.h new file +12
-1+{ +u8 *bytes = v; +u8 checksum =0 ; +int i; + +for (i =0 ; i < len; i++) + checksum -= bytes[i]; + +return checksum; +} + +#endif --
Quoted 2 lines
1.8.5.6
Regards,
Simon
PATCH v3 1/8 x86: Move table csum into separate header
Quoted 69 lines · Simon Glass
Hi Alex,
Quoted 11 lines · Alexander Graf
We need the checksum function without all the other table functionality soon, so let's split it out into its own header file.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Bin Meng <[email protected]>---
arch/x86/include/asm/tables.h | 2 ++ arch/x86/lib/tables.c | 12 ------------ include/tables_csum.h | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 12 deletions(-)create mode 100644
include/tables_csum.hReviewed-by Simon Glass <[email protected]>Question below
Quoted 47 lines
arch/x86/include/asm/tables.h +2
-0@@ -7,6 +7,8 @@#ifndef _X86_TABLES_H_#define _X86_TABLES_H_ +#include <tables_csum.h> +/* * All x86 tables happen to like the address range from 0xf0000 to 0x100000. * We use 0xf0000 as the starting address to store those tables, including arch/x86/lib/tables.c +0
-12@@ -38,18 +38,6 @@ static table_write table_write_funcs[] = {#endif }; -u8 table_compute_checksum (void *v,int len) -{ -u8 *bytes = v; -u8 checksum =0 ; -int i; - -for (i =0 ; i < len; i++) - checksum -= bytes[i]; - -return checksum; -} -void table_fill_string (char *dest,const char *src,size_t n,char pad) {int start, len;include/tables_csum.h new file +4
-0@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2015, Bin Meng <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+
Quoted 8 lines
include/tables_csum.h line 10
Quoted 6 lines
include/tables_csum.h new file +6
-0+*/ + +#ifndef _TABLES_CSUM_H_ +#define _TABLES_CSUM_H_ + +static inline u8 table_compute_checksum (void *v,int len)Why is this static inline? Shouldn't it go in a C file?
It could go into a C file as well, but I didn?t see many downsides of having it be a static inline. Would you prefer it in a C file?
Alex
PATCH v3 1/8 x86: Move table csum into separate header
Hi Alex,
Quoted 78 lines · Alexander Graf
Quoted 69 lines · Simon Glass
Hi Alex,
Quoted 11 lines · Alexander Graf
We need the checksum function without all the other table functionality soon, so let's split it out into its own header file.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Bin Meng <[email protected]>---
arch/x86/include/asm/tables.h | 2 ++ arch/x86/lib/tables.c | 12 ------------ include/tables_csum.h | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 12 deletions(-)create mode 100644
include/tables_csum.hReviewed-by Simon Glass <[email protected]>Question below
Quoted 47 lines
arch/x86/include/asm/tables.h +2
-0@@ -7,6 +7,8 @@#ifndef _X86_TABLES_H_#define _X86_TABLES_H_ +#include <tables_csum.h> +/* * All x86 tables happen to like the address range from 0xf0000 to 0x100000. * We use 0xf0000 as the starting address to store those tables, including arch/x86/lib/tables.c +0
-12@@ -38,18 +38,6 @@ static table_write table_write_funcs[] = {#endif }; -u8 table_compute_checksum (void *v,int len) -{ -u8 *bytes = v; -u8 checksum =0 ; -int i; - -for (i =0 ; i < len; i++) - checksum -= bytes[i]; - -return checksum; -} -void table_fill_string (char *dest,const char *src,size_t n,char pad) {int start, len;include/tables_csum.h new file +4
-0@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2015, Bin Meng <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ Quoted 8 lines
include/tables_csum.h line 10
Quoted 6 lines
include/tables_csum.h new file +6
-0+*/ + +#ifndef _TABLES_CSUM_H_ +#define _TABLES_CSUM_H_ + +static inline u8 table_compute_checksum (void *v,int len)Why is this static inline? Shouldn't it go in a C file?
Quoted 1 line
It could go into a C file as well, but I didn?t see many downsides of having it be a static inline. Would you prefer it in a C file?
Yes I think so. We normally put C code in C files. But Bin may have comments.
Regards,
Simon
PATCH v3 2/8 x86: Move smbios generation into arch independent directory
In reply to Alexander GrafWe will need the SMBIOS generation function on ARM as well going forward, so let's move it into a non arch specific location.
---
arch/x86/Kconfig | 27 ------------------------
arch/x86/lib/Makefile | 1 -
arch/x86/lib/tables.c | 2 +-
{arch/x86/include/asm => include}/smbios.h | 0
lib/Kconfig | 33 ++++++++++++++++++++++++++++++
lib/Makefile | 1 +
{arch/x86/lib => lib}/smbios.c | 4 ++--
7 files changed, 37 insertions(+), 31 deletions(-)
rename {arch/x86/include/asm => include}/smbios.h (100%)
rename {arch/x86/lib => lib}/smbios.c (99%)arch/x86/Kconfig +0 -27
@@ -457,33 +457,6 @@ config GENERATE_ACPI_TABLE by the operating system. It defines platform-independent interfaces for configuration and power management monitoring. -config GENERATE_SMBIOS_TABLE - bool "Generate an SMBIOS (System Management BIOS) table" - default y - help - The System Management BIOS (SMBIOS) specification addresses how - motherboard and system vendors present management information about - their products in a standard format by extending the BIOS interface - on Intel architecture systems. - - Check http://www.dmtf.org/standards/smbios for details. - -config SMBIOS_MANUFACTURER - string "SMBIOS Manufacturer" - depends on GENERATE_SMBIOS_TABLE - default SYS_VENDOR - help - The board manufacturer to store in SMBIOS structures. - Change this to override the default one (CONFIG_SYS_VENDOR). - -config SMBIOS_PRODUCT_NAME - string "SMBIOS Product Name" - depends on GENERATE_SMBIOS_TABLE - default SYS_BOARD - help - The product name to store in SMBIOS structures. - Change this to override the default one (CONFIG_SYS_BOARD). - endmenu config MAX_PIRQ_LINKS
arch/x86/lib/Makefile +0 -1
@@ -29,7 +29,6 @@ obj-y += relocate.o obj-y += physmem.o obj-$(CONFIG_X86_RAMTEST) += ramtest.o obj-y += sfi.o -obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o obj-y += string.o ifndef CONFIG_QEMU obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
arch/x86/lib/tables.c +1 -1
@@ -5,9 +5,9 @@*/ #include <common.h> +#include <smbios.h> #include <asm/sfi.h> #include <asm/mpspec.h> -#include <asm/smbios.h> #include <asm/tables.h> #include <asm/acpi_table.h> #include <asm/coreboot_tables.h>
include/smbios.h renamed from arch/x86/include/asm/smbios.h +0 -0
lib/Kconfig +33 -0
@@ -149,6 +149,39 @@ config SPL_OF_LIBFDT particular compatible nodes. The library operates on a flattened version of the device tree. +menu "System tables" + depends on !EFI && !SYS_COREBOOT + +config GENERATE_SMBIOS_TABLE + bool "Generate an SMBIOS (System Management BIOS) table" + default y + depends on X86 + help + The System Management BIOS (SMBIOS) specification addresses how + motherboard and system vendors present management information about + their products in a standard format by extending the BIOS interface + on Intel architecture systems. + + Check http://www.dmtf.org/standards/smbios for details. + +config SMBIOS_MANUFACTURER + string "SMBIOS Manufacturer" + depends on GENERATE_SMBIOS_TABLE + default SYS_VENDOR + help + The board manufacturer to store in SMBIOS structures. + Change this to override the default one (CONFIG_SYS_VENDOR). + +config SMBIOS_PRODUCT_NAME + string "SMBIOS Product Name" + depends on GENERATE_SMBIOS_TABLE + default SYS_BOARD + help + The product name to store in SMBIOS structures. + Change this to override the default one (CONFIG_SYS_BOARD). + +endmenu + source lib/efi/Kconfig source lib/efi_loader/Kconfig
lib/Makefile +1 -0
@@ -27,6 +27,7 @@ obj-$(CONFIG_FIT) += fdtdec_common.o obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o obj-$(CONFIG_GZIP) += gunzip.o obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o +obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o obj-y += initcall.o obj-$(CONFIG_LMB) += lmb.o obj-y += ldiv.o
lib/smbios.c renamed from arch/x86/lib/smbios.c +2 -2
@@ -7,10 +7,10 @@*/ #include <common.h> +#include <smbios.h> +#include <tables_csum.h> #include <version.h> #include <asm/cpu.h> -#include <asm/smbios.h> -#include <asm/tables.h> DECLARE_GLOBAL_DATA_PTR ;
Signature · 1 line
1.8.5.6
PATCH v3 3/8 efi_loader: Expose efi_install_configuration_table
In reply to Alexander GrafWe want to be able to add configuration table entries from our own code as well as from EFI payload code. Export the boot service function internally too, so that we can reuse it.
--- include/efi_loader.h | 2 ++ lib/efi_loader/efi_boottime.c | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-)
include/efi_loader.h +2 -0
@@ -130,6 +130,8 @@ uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type, bool overlap_only_ram);/* Called by board init to initialize the EFI memory map */ int efi_memory_init (void ); +/* Adds new or overrides configuration table entry to the system table */ +efi_status_t efi_install_configuration_table (efi_guid_t *guid,void *table);#ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER extern void *efi_bounce_buffer;
lib/efi_loader/efi_boottime.c +13 -9
@@ -37,7 +37,7 @@ static bool efi_is_direct_boot = true;* In most cases we want to pass an FDT to the payload, so reserve one slot of * config table space for it. The pointer gets populated by do_bootefi_exec(). */ -static struct efi_configuration_table EFI_RUNTIME_DATA efi_conf_table[1]; +static struct efi_configuration_table EFI_RUNTIME_DATA efi_conf_table[2];/* * The "gd" pointer lives in a register on ARM and AArch64 that we declare
@@ -375,31 +375,35 @@ static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol,return EFI_EXIT (EFI_NOT_FOUND ); } -static efi_status_t EFIAPI efi_install_configuration_table(efi_guid_t *guid, -void *table) +efi_status_t efi_install_configuration_table (efi_guid_t *guid,void *table) {int i; -EFI_ENTRY ("%p, %p" , guid, table); -/* Check for guid override */ for (i =0 ; i < systab.nr_tables; i++) {if (!guidcmp (guid, &efi_conf_table[i].guid)) { efi_conf_table[i].table = table; -return EFI_EXIT (EFI_SUCCESS ); +return EFI_SUCCESS ; } }/* No override, check for overflow */ if (i >=ARRAY_SIZE (efi_conf_table)) -return EFI_EXIT (EFI_OUT_OF_RESOURCES ); +return EFI_OUT_OF_RESOURCES ;/* Add a new entry */ memcpy (&efi_conf_table[i].guid, guid,sizeof (*guid)); efi_conf_table[i].table = table; systab.nr_tables = i; -return EFI_EXIT (EFI_SUCCESS ); +return EFI_SUCCESS ; +} + +static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid, +void *table) +{ +EFI_ENTRY ("%p, %p" , guid, table); +return EFI_EXIT (efi_install_configuration_table (guid, table)); } static efi_status_t EFIAPI efi_load_image(bool boot_policy,
@@ -750,7 +754,7 @@ static const struct efi_boot_services efi_boot_services = { .register_protocol_notify = efi_register_protocol_notify, .locate_handle = efi_locate_handle, .locate_device_path = efi_locate_device_path, - .install_configuration_table = efi_install_configuration_table, + .install_configuration_table = efi_install_configuration_table_ext, .load_image = efi_load_image, .start_image = efi_start_image, .exit = efi_exit,
Signature · 1 line
1.8.5.6
PATCH v3 3/8 efi_loader: Expose efi_install_configuration_table
Quoted 9 lines · Alexander Graf
We want to be able to add configuration table entries from our own code as well as from EFI payload code. Export the boot service function internally too, so that we can reuse it.
Signed-off-by Alexander Graf <[email protected]>--- include/efi_loader.h | 2 ++ lib/efi_loader/efi_boottime.c | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-)
PATCH v3 4/8 smbios: Allow compilation on 64bit systems
In reply to Alexander GrafThe SMBIOS generation code passes pointers as u32. That causes the compiler to warn on casts to pointers. This patch moves all address pointers to uintptr_t instead.
Technically u32 would be enough for the current SMBIOS2 style tables, but we may want to extend the code to SMBIOS3 in the future which is 64bit address capable.
--- arch/x86/lib/tables.c | 7 ++++++- include/smbios.h | 4 ++-- lib/smbios.c | 16 ++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-)
arch/x86/lib/tables.c +6 -1
@@ -12,6 +12,11 @@#include <asm/acpi_table.h> #include <asm/coreboot_tables.h> +static u32 write_smbios_table_wrapper (u32 addr) +{ +return write_smbios_table (addr); +} +/** * Function prototype to write a specific configuration table *
@@ -34,7 +39,7 @@ static table_write table_write_funcs[] = { write_acpi_tables,#endif #ifdef CONFIG_GENERATE_SMBIOS_TABLE - write_smbios_table, + write_smbios_table_wrapper,#endif };
include/smbios.h +2 -2
@@ -221,7 +221,7 @@ static inline void fill_smbios_header(void *table, int type,* @handle: the structure's handle, a unique 16-bit number * @return: size of the structure */ -typedef int (*smbios_write_type )(u32 *addr,int handle); +typedef int (*smbios_write_type )(uintptr_t *addr,int handle);/** * write_smbios_table() - Write SMBIOS table
@@ -231,6 +231,6 @@ typedef int (*smbios_write_type)(u32 *addr, int handle);* @addr: start address to write SMBIOS table * @return: end address of SMBIOS table */ -u32 write_smbios_table (u32 addr); +uintptr_t write_smbios_table (uintptr_t addr);#endif /* _SMBIOS_H_ */
lib/smbios.c +8 -8
@@ -69,7 +69,7 @@ static int smbios_string_table_len(char *start)return len +1 ; } -static int smbios_write_type0 (u32 *current,int handle) +static int smbios_write_type0 (uintptr_t *current,int handle) {struct smbios_type0 *t = (struct smbios_type0 *)*current;int len =sizeof (struct smbios_type0 );
@@ -98,7 +98,7 @@ static int smbios_write_type0(u32 *current, int handle)return len; } -static int smbios_write_type1 (u32 *current,int handle) +static int smbios_write_type1 (uintptr_t *current,int handle) {struct smbios_type1 *t = (struct smbios_type1 *)*current;int len =sizeof (struct smbios_type1 );
@@ -114,7 +114,7 @@ static int smbios_write_type1(u32 *current, int handle)return len; } -static int smbios_write_type2 (u32 *current,int handle) +static int smbios_write_type2 (uintptr_t *current,int handle) {struct smbios_type2 *t = (struct smbios_type2 *)*current;int len =sizeof (struct smbios_type2 );
@@ -132,7 +132,7 @@ static int smbios_write_type2(u32 *current, int handle)return len; } -static int smbios_write_type3 (u32 *current,int handle) +static int smbios_write_type3 (uintptr_t *current,int handle) {struct smbios_type3 *t = (struct smbios_type3 *)*current;int len =sizeof (struct smbios_type3 );
@@ -152,7 +152,7 @@ static int smbios_write_type3(u32 *current, int handle)return len; } -static int smbios_write_type4 (u32 *current,int handle) +static int smbios_write_type4 (uintptr_t *current,int handle) {struct smbios_type4 *t = (struct smbios_type4 *)*current;int len =sizeof (struct smbios_type4 );
@@ -185,7 +185,7 @@ static int smbios_write_type4(u32 *current, int handle)return len; } -static int smbios_write_type32 (u32 *current,int handle) +static int smbios_write_type32 (uintptr_t *current,int handle) {struct smbios_type32 *t = (struct smbios_type32 *)*current;int len =sizeof (struct smbios_type32 );
@@ -198,7 +198,7 @@ static int smbios_write_type32(u32 *current, int handle)return len; } -static int smbios_write_type127 (u32 *current,int handle) +static int smbios_write_type127 (uintptr_t *current,int handle) {struct smbios_type127 *t = (struct smbios_type127 *)*current;int len =sizeof (struct smbios_type127 );
@@ -221,7 +221,7 @@ static smbios_write_type smbios_write_funcs[] = { smbios_write_type127 }; -u32 write_smbios_table (u32 addr) +uintptr_t write_smbios_table (uintptr_t addr) {struct smbios_entry *se;u32 tables;
Signature · 1 line
1.8.5.6
PATCH v3 4/8 smbios: Allow compilation on 64bit systems
Quoted 8 lines · Alexander Graf
The SMBIOS generation code passes pointers as u32. That causes the compiler to warn on casts to pointers. This patch moves all address pointers to
uintptr_tinstead.Technically u32 would be enough for the current SMBIOS2 style tables, but we may want to extend the code to SMBIOS3 in the future which is 64bit address capable.
Quoted 7 lines
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Bin Meng <[email protected]>--- arch/x86/lib/tables.c | 7 ++++++- include/smbios.h | 4 ++-- lib/smbios.c | 16 ++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-)
PATCH v3 5/8 smbios: Generate type 4 on non-x86 systems
In reply to Alexander GrafThe type 4 table generation code is very x86 centric today. Refactor things out a bit to allow the tables to get generated for other architectures as well.
--- include/smbios.h | 3 +++ lib/smbios.c | 37 +++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-)
include/smbios.h +3 -0
@@ -139,6 +139,9 @@ struct __packed smbios_type3 {#define SMBIOS_PROCESSOR_STATUS_ENABLED 1#define SMBIOS_PROCESSOR_UPGRADE_NONE 6 +#define SMBIOS_PROCESSOR_FAMILY_OTHER 1 +#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 +struct __packed smbios_type4 {u8 type;u8 length;
lib/smbios.c +27 -10
@@ -10,7 +10,9 @@#include <smbios.h> #include <tables_csum.h> #include <version.h> +#ifdef CONFIG_X86 #include <asm/cpu.h> +#endif DECLARE_GLOBAL_DATA_PTR ;
@@ -152,26 +154,41 @@ static int smbios_write_type3(uintptr_t *current, int handle)return len; } -static int smbios_write_type4 (uintptr_t *current,int handle) +static void smbios_write_type4_arch (struct smbios_type4 *t) { -struct smbios_type4 *t = (struct smbios_type4 *)*current; -int len =sizeof (struct smbios_type4 ); -const char *vendor; -char *name; +u16 processor_family =SMBIOS_PROCESSOR_FAMILY_UNKNOWN ; +const char *vendor ="Unknown" ; +char *name ="Unknown" ; + +#ifdef CONFIG_X86 char processor_name[CPU_MAX_NAME_LEN ];struct cpuid_result res; -memset (t,0 ,sizeof (struct smbios_type4 )); -fill_smbios_header (t,SMBIOS_PROCESSOR_INFORMATION , len, handle); - t->processor_type =SMBIOS_PROCESSOR_TYPE_CENTRAL ; - t->processor_family = gd->arch.x86; + processor_family = gd->arch.x86; vendor =cpu_vendor_name (gd->arch.x86_vendor); - t->processor_manufacturer =smbios_add_string (t->eos, vendor); res =cpuid (1 ); t->processor_id[0 ] = res.eax; t->processor_id[1 ] = res.edx; name =cpu_get_name (processor_name); +#elif defined(CONFIG_ARM ) + processor_family =SMBIOS_PROCESSOR_FAMILY_OTHER ; + vendor ="ARM" ; +#endif + + t->processor_family = processor_family; + t->processor_manufacturer =smbios_add_string (t->eos, vendor); t->processor_version =smbios_add_string (t->eos, name); +} + +static int smbios_write_type4 (uintptr_t *current,int handle) +{ +struct smbios_type4 *t = (struct smbios_type4 *)*current; +int len =sizeof (struct smbios_type4 ); + +memset (t,0 ,sizeof (struct smbios_type4 )); +fill_smbios_header (t,SMBIOS_PROCESSOR_INFORMATION , len, handle); + t->processor_type =SMBIOS_PROCESSOR_TYPE_CENTRAL ; +smbios_write_type4_arch (t); t->status =SMBIOS_PROCESSOR_STATUS_ENABLED ; t->processor_upgrade =SMBIOS_PROCESSOR_UPGRADE_NONE ; t->l1_cache_handle =0xffff ;
Signature · 1 line
1.8.5.6
PATCH v3 5/8 smbios: Generate type 4 on non-x86 systems
Quoted 10 lines · Alexander Graf
The type 4 table generation code is very x86 centric today. Refactor things out a bit to allow the tables to get generated for other architectures as well.
Signed-off-by Alexander Graf <[email protected]>--- include/smbios.h | 3 +++ lib/smbios.c | 37 +++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-)
PATCH v3 5/8 smbios: Generate type 4 on non-x86 systems
In reply to Alexander GrafHI Alex,
Quoted 44 lines · Alexander Graf
The type 4 table generation code is very x86 centric today. Refactor things out a bit to allow the tables to get generated for other architectures as well.
Signed-off-by Alexander Graf <[email protected]>--- include/smbios.h | 3 +++ lib/smbios.c | 37 +++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-)include/smbios.h +3
-0@@ -139,6 +139,9 @@ struct __packed smbios_type3 {#define SMBIOS_PROCESSOR_STATUS_ENABLED 1#define SMBIOS_PROCESSOR_UPGRADE_NONE 6 +#define SMBIOS_PROCESSOR_FAMILY_OTHER 1 +#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 +struct __packed smbios_type4 {u8 type;u8 length;lib/smbios.c +3
-1@@ -10,7 +10,9 @@#include <smbios.h> #include <tables_csum.h> #include <version.h> +#ifdef CONFIG_X86 #include <asm/cpu.h> +#endif DECLARE_GLOBAL_DATA_PTR ;@@ -152,26 +154,41 @@ static int smbios_write_type3(uintptr_t *current, int handle)return len; } -static int smbios_write_type4 (uintptr_t *current,int handle) +static void smbios_write_type4_arch (struct smbios_type4 *t)
lib/smbios.c static int smbios_write_type3(uintptr_t *current, int handle) · line 163
Quoted 10 lines
lib/smbios.c +5
-4{ -struct smbios_type4 *t = (struct smbios_type4 *)*current; -int len =sizeof (struct smbios_type4 ); -const char *vendor; -char *name; +u16 processor_family =SMBIOS_PROCESSOR_FAMILY_UNKNOWN ; +const char *vendor ="Unknown" ; +char *name ="Unknown" ; + +#ifdef CONFIG_X86
This should use the cpu uclass. As mentioned you may need to add a new method, but it should be easy enough.
Quoted 37 lines
lib/smbios.c +19
-6char processor_name[CPU_MAX_NAME_LEN ];struct cpuid_result res; -memset (t,0 ,sizeof (struct smbios_type4 )); -fill_smbios_header (t,SMBIOS_PROCESSOR_INFORMATION , len, handle); - t->processor_type =SMBIOS_PROCESSOR_TYPE_CENTRAL ; - t->processor_family = gd->arch.x86; + processor_family = gd->arch.x86; vendor =cpu_vendor_name (gd->arch.x86_vendor); - t->processor_manufacturer =smbios_add_string (t->eos, vendor); res =cpuid (1 ); t->processor_id[0 ] = res.eax; t->processor_id[1 ] = res.edx; name =cpu_get_name (processor_name); +#elif defined(CONFIG_ARM ) + processor_family =SMBIOS_PROCESSOR_FAMILY_OTHER ; + vendor ="ARM" ; +#endif + + t->processor_family = processor_family; + t->processor_manufacturer =smbios_add_string (t->eos, vendor); t->processor_version =smbios_add_string (t->eos, name); +} + +static int smbios_write_type4 (uintptr_t *current,int handle) +{ +struct smbios_type4 *t = (struct smbios_type4 *)*current; +int len =sizeof (struct smbios_type4 ); + +memset (t,0 ,sizeof (struct smbios_type4 )); +fill_smbios_header (t,SMBIOS_PROCESSOR_INFORMATION , len, handle); + t->processor_type =SMBIOS_PROCESSOR_TYPE_CENTRAL ; +smbios_write_type4_arch (t); t->status =SMBIOS_PROCESSOR_STATUS_ENABLED ; t->processor_upgrade =SMBIOS_PROCESSOR_UPGRADE_NONE ; t->l1_cache_handle =0xffff ; --
Quoted 2 lines
1.8.5.6
Regards,
Simon
PATCH v4 5/8 smbios: Generate type 4 on non-x86 systems
The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
---
v3 -> v4:
- Use device model
--- arch/x86/cpu/baytrail/cpu.c | 1 + arch/x86/cpu/broadwell/cpu.c | 1 + arch/x86/cpu/cpu_x86.c | 13 ++++++++++ arch/x86/cpu/ivybridge/model_206ax.c | 1 + arch/x86/include/asm/cpu_x86.h | 12 +++++++++ drivers/cpu/cpu-uclass.c | 10 ++++++++ include/cpu.h | 20 +++++++++++++++ include/smbios.h | 3 +++ lib/smbios.c | 49 ++++++++++++++++++++++++++---------- 9 files changed, 97 insertions(+), 13 deletions(-)
arch/x86/cpu/baytrail/cpu.c +1 -0
@@ -141,6 +141,7 @@ static const struct cpu_ops cpu_x86_baytrail_ops = { .get_desc = cpu_x86_get_desc, .get_info = baytrail_get_info, .get_count = baytrail_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_baytrail_ids[] = {
arch/x86/cpu/broadwell/cpu.c +1 -0
@@ -743,6 +743,7 @@ static const struct cpu_ops cpu_x86_broadwell_ops = { .get_desc = cpu_x86_get_desc, .get_info = broadwell_get_info, .get_count = broadwell_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_broadwell_ids[] = {
arch/x86/cpu/cpu_x86.c +13 -0
@@ -15,9 +15,21 @@ DECLARE_GLOBAL_DATA_PTR;int cpu_x86_bind (struct udevice *dev) {struct cpu_platdata *plat =dev_get_parent_platdata (dev); +struct cpuid_result res; plat->cpu_id =fdtdec_get_int (gd->fdt_blob, dev->of_offset,"intel,apic-id" ,-1 ); + plat->family = gd->arch.x86; + res =cpuid (1 ); + plat->id[0 ] = res.eax; + plat->id[1 ] = res.edx; + +return 0 ; +} + +int cpu_x86_get_vendor (struct udevice *dev,const char **vendor) +{ + *vendor =cpu_vendor_name (gd->arch.x86_vendor);return 0 ; }
@@ -60,6 +72,7 @@ static int cpu_x86_get_count(struct udevice *dev)static const struct cpu_ops cpu_x86_ops = { .get_desc = cpu_x86_get_desc, .get_count = cpu_x86_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_ids[] = {
arch/x86/cpu/ivybridge/model_206ax.c +1 -0
@@ -478,6 +478,7 @@ static const struct cpu_ops cpu_x86_model_206ax_ops = { .get_desc = cpu_x86_get_desc, .get_info = model_206ax_get_info, .get_count = model_206ax_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_model_206ax_ids[] = {
arch/x86/include/asm/cpu_x86.h +12 -0
@@ -31,4 +31,16 @@ int cpu_x86_bind(struct udevice *dev);*/ int cpu_x86_get_desc (struct udevice *dev,char *buf,int size); +/** +* cpu_x86_get_vendor() - Get a vendor string for an x86 CPU +* +* This uses cpu_vendor_name() and is suitable to use as the get_vendor() +* method for the CPU uclass. +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to vendor string pointer +* @return: 0 if OK, -ve on error +*/ +int cpu_x86_get_vendor (struct udevice *dev,const char **vendor); +#endif /* _ASM_CPU_X86_H */
drivers/cpu/cpu-uclass.c +10 -0
@@ -44,6 +44,16 @@ int cpu_get_count(struct udevice *dev)return ops->get_count (dev); } +int cpu_get_vendor (struct udevice *dev,const char **vendor) +{ +struct cpu_ops *ops =cpu_get_ops (dev); + +if (!ops->get_info) +return -ENOSYS ; + +return ops->get_vendor (dev, vendor); +} +U_BOOT_DRIVER (cpu_bus) = { .name ="cpu_bus" , .id =UCLASS_SIMPLE_BUS ,
include/cpu.h +20 -0
@@ -21,6 +21,8 @@ struct cpu_platdata {int cpu_id;int ucode_version;ulong device_id; +u16 family; +u32 id[2 ]; };/* CPU features - mostly just a placeholder for now */
@@ -71,6 +73,15 @@ struct cpu_ops {* @return CPU count if OK, -ve on error */ int (*get_count)(struct udevice *dev); + +/** +* get_vendor() - Get vendor name of a CPU +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to put the pointer to the vendor string +* @return 0 if OK, -ve on error +*/ +int (*get_vendor)(struct udevice *dev,const char **vendor); };#define cpu_get_ops (dev) ((struct cpu_ops *)(dev)->driver->ops)
@@ -102,4 +113,13 @@ int cpu_get_info(struct udevice *dev, struct cpu_info *info);*/ int cpu_get_count (struct udevice *dev); +/** +* cpu_get_vendor() - Get vendor name of a CPU +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to put the pointer to the vendor string +* @return 0 if OK, -ve on error +*/ +int cpu_get_vendor (struct udevice *dev,const char **vendor); +#endif
include/smbios.h +3 -0
@@ -139,6 +139,9 @@ struct __packed smbios_type3 {#define SMBIOS_PROCESSOR_STATUS_ENABLED 1#define SMBIOS_PROCESSOR_UPGRADE_NONE 6 +#define SMBIOS_PROCESSOR_FAMILY_OTHER 1 +#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 +struct __packed smbios_type4 {u8 type;u8 length;
lib/smbios.c +36 -13
69 lines not on this page · raw message
Signature · 1 line
1.8.5.6
PATCH v4 5/8 smbios: Generate type 4 on non-x86 systems
Hi Alex,
Quoted 119 lines · Alexander Graf
The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
Signed-off-by Alexander Graf <[email protected]>---
v3 -> v4:
- Use device model
--- arch/x86/cpu/baytrail/cpu.c | 1 + arch/x86/cpu/broadwell/cpu.c | 1 + arch/x86/cpu/cpu_x86.c | 13 ++++++++++ arch/x86/cpu/ivybridge/model_206ax.c | 1 + arch/x86/include/asm/cpu_x86.h | 12 +++++++++ drivers/cpu/cpu-uclass.c | 10 ++++++++ include/cpu.h | 20 +++++++++++++++ include/smbios.h | 3 +++ lib/smbios.c | 49 ++++++++++++++++++++++++++---------- 9 files changed, 97 insertions(+), 13 deletions(-)arch/x86/cpu/baytrail/cpu.c +1
-0@@ -141,6 +141,7 @@ static const struct cpu_ops cpu_x86_baytrail_ops = { .get_desc = cpu_x86_get_desc, .get_info = baytrail_get_info, .get_count = baytrail_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_baytrail_ids[] = {arch/x86/cpu/broadwell/cpu.c +1
-0@@ -743,6 +743,7 @@ static const struct cpu_ops cpu_x86_broadwell_ops = { .get_desc = cpu_x86_get_desc, .get_info = broadwell_get_info, .get_count = broadwell_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_broadwell_ids[] = {arch/x86/cpu/cpu_x86.c +13
-0@@ -15,9 +15,21 @@ DECLARE_GLOBAL_DATA_PTR;int cpu_x86_bind (struct udevice *dev) {struct cpu_platdata *plat =dev_get_parent_platdata (dev); +struct cpuid_result res; plat->cpu_id =fdtdec_get_int (gd->fdt_blob, dev->of_offset,"intel,apic-id" ,-1 ); + plat->family = gd->arch.x86; + res =cpuid (1 ); + plat->id[0 ] = res.eax; + plat->id[1 ] = res.edx; + +return 0 ; +} + +int cpu_x86_get_vendor (struct udevice *dev,const char **vendor) +{ + *vendor =cpu_vendor_name (gd->arch.x86_vendor);return 0 ; }@@ -60,6 +72,7 @@ static int cpu_x86_get_count(struct udevice *dev)static const struct cpu_ops cpu_x86_ops = { .get_desc = cpu_x86_get_desc, .get_count = cpu_x86_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_ids[] = {arch/x86/cpu/ivybridge/model_206ax.c +1
-0@@ -478,6 +478,7 @@ static const struct cpu_ops cpu_x86_model_206ax_ops = { .get_desc = cpu_x86_get_desc, .get_info = model_206ax_get_info, .get_count = model_206ax_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_model_206ax_ids[] = {arch/x86/include/asm/cpu_x86.h +12
-0@@ -31,4 +31,16 @@ int cpu_x86_bind(struct udevice *dev);*/ int cpu_x86_get_desc (struct udevice *dev,char *buf,int size); +/** +* cpu_x86_get_vendor() - Get a vendor string for an x86 CPU +* +* This uses cpu_vendor_name() and is suitable to use as the get_vendor() +* method for the CPU uclass. +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to vendor string pointer +* @return: 0 if OK, -ve on error +*/ +int cpu_x86_get_vendor (struct udevice *dev,const char **vendor); +#endif /* _ASM_CPU_X86_H */ drivers/cpu/cpu-uclass.c +0
-0
drivers/cpu/cpu-uclass.c int cpu_get_count(struct udevice *dev) · line 51
Quoted 8 lines
drivers/cpu/cpu-uclass.c +5
-0@@ -44,6 +44,16 @@ int cpu_get_count(struct udevice *dev)return ops->get_count (dev); } +int cpu_get_vendor (struct udevice *dev,const char **vendor) +{ +struct cpu_ops *ops =cpu_get_ops (dev); + +if (!ops->get_info)
This should be: if (!ops->get_vendor)
Quoted 83 lines
drivers/cpu/cpu-uclass.c +5
-0+return -ENOSYS ; + +return ops->get_vendor (dev, vendor); +} +U_BOOT_DRIVER (cpu_bus) = { .name ="cpu_bus" , .id =UCLASS_SIMPLE_BUS ,include/cpu.h +20
-0@@ -21,6 +21,8 @@ struct cpu_platdata {int cpu_id;int ucode_version;ulong device_id; +u16 family; +u32 id[2 ]; };/* CPU features - mostly just a placeholder for now */ @@ -71,6 +73,15 @@ struct cpu_ops {* @return CPU count if OK, -ve on error */ int (*get_count)(struct udevice *dev); + +/** +* get_vendor() - Get vendor name of a CPU +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to put the pointer to the vendor string +* @return 0 if OK, -ve on error +*/ +int (*get_vendor)(struct udevice *dev,const char **vendor); };#define cpu_get_ops (dev) ((struct cpu_ops *)(dev)->driver->ops)@@ -102,4 +113,13 @@ int cpu_get_info(struct udevice *dev, struct cpu_info *info);*/ int cpu_get_count (struct udevice *dev); +/** +* cpu_get_vendor() - Get vendor name of a CPU +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to put the pointer to the vendor string +* @return 0 if OK, -ve on error +*/ +int cpu_get_vendor (struct udevice *dev,const char **vendor); +#endif include/smbios.h +3
-0@@ -139,6 +139,9 @@ struct __packed smbios_type3 {#define SMBIOS_PROCESSOR_STATUS_ENABLED 1#define SMBIOS_PROCESSOR_UPGRADE_NONE 6 +#define SMBIOS_PROCESSOR_FAMILY_OTHER 1 +#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 +struct __packed smbios_type4 {u8 type;u8 length;lib/smbios.c +5
-1@@ -10,7 +10,11 @@#include <smbios.h> #include <tables_csum.h> #include <version.h> -#include <asm/cpu.h> +#ifdef CONFIG_CPU +#include <cpu.h> +#include <dm.h> +#include <dm/uclass-internal.h> +#endif DECLARE_GLOBAL_DATA_PTR ;
lib/smbios.c static int smbios_write_type3(uintptr_t *current, int handle) · line 159
Quoted 4 lines
lib/smbios.c +1
-0@@ -152,26 +156,45 @@ static int smbios_write_type3(uintptr_t *current, int handle)return len; } +static void smbios_write_type4_arch (struct smbios_type4 *t)
Since now we use cpu uclass to implement this, I don't think smbios_write_type4_arch() is a proper name, as _arch may indicate this is architecture dependent, however it is not. The whole codes in this function can be put back in the original smbios_write_type4().
Quoted 44 lines
lib/smbios.c +29
-7+{ +u16 processor_family =SMBIOS_PROCESSOR_FAMILY_UNKNOWN ; +const char *vendor ="Unknown" ; +const char *name ="Unknown" ; + +#ifdef CONFIG_CPU +char processor_name[49 ]; +struct udevice *dev =NULL ; + +uclass_find_first_device (UCLASS_CPU , &dev); +if (dev) { +struct cpu_platdata *plat =dev_get_parent_platdata (dev); + +if (plat->family) + processor_family = plat->family; + t->processor_id[0 ] = plat->id[0 ]; + t->processor_id[1 ] = plat->id[1 ]; + +cpu_get_vendor (dev, &vendor); +if (!cpu_get_desc (dev, processor_name,sizeof (processor_name))) + name = processor_name; + } +#endif + + t->processor_family = processor_family; + t->processor_manufacturer =smbios_add_string (t->eos, vendor); + t->processor_version =smbios_add_string (t->eos, name); +} +static int smbios_write_type4 (uintptr_t *current,int handle) {struct smbios_type4 *t = (struct smbios_type4 *)*current;int len =sizeof (struct smbios_type4 ); -const char *vendor; -char *name; -char processor_name[CPU_MAX_NAME_LEN ]; -struct cpuid_result res;memset (t,0 ,sizeof (struct smbios_type4 ));fill_smbios_header (t,SMBIOS_PROCESSOR_INFORMATION , len, handle); t->processor_type =SMBIOS_PROCESSOR_TYPE_CENTRAL ; - t->processor_family = gd->arch.x86; - vendor =cpu_vendor_name (gd->arch.x86_vendor); - t->processor_manufacturer =smbios_add_string (t->eos, vendor);
lib/smbios.c static int smbios_write_type3(uintptr_t *current, int handle)
Quoted 10 lines
lib/smbios.c +1
-6- res =cpuid (1 ); - t->processor_id[0 ] = res.eax; - t->processor_id[1 ] = res.edx; - name =cpu_get_name (processor_name); - t->processor_version =smbios_add_string (t->eos, name); +smbios_write_type4_arch (t); t->status =SMBIOS_PROCESSOR_STATUS_ENABLED ; t->processor_upgrade =SMBIOS_PROCESSOR_UPGRADE_NONE ; t->l1_cache_handle =0xffff ; --
Regards,
Bin
PATCH v4 5/8 smbios: Generate type 4 on non-x86 systems
Quoted 128 lines · Bin Meng
Hi Alex,
Quoted 122 lines · Alexander Graf
The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
Signed-off-by Alexander Graf <[email protected]>---
v3 -> v4:
- Use device model
---arch/x86/cpu/baytrail/cpu.c | 1 + arch/x86/cpu/broadwell/cpu.c | 1 + arch/x86/cpu/cpu_x86.c | 13 ++++++++++ arch/x86/cpu/ivybridge/model_206ax.c | 1 + arch/x86/include/asm/cpu_x86.h | 12 +++++++++ drivers/cpu/cpu-uclass.c | 10 ++++++++ include/cpu.h | 20 +++++++++++++++ include/smbios.h | 3 +++ lib/smbios.c | 49 ++++++++++++++++++++++++++---------- 9 files changed, 97 insertions(+), 13 deletions(-)arch/x86/cpu/baytrail/cpu.c +1
-0@@ -141,6 +141,7 @@ static const struct cpu_ops cpu_x86_baytrail_ops = { .get_desc = cpu_x86_get_desc, .get_info = baytrail_get_info, .get_count = baytrail_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_baytrail_ids[] = {arch/x86/cpu/broadwell/cpu.c +1
-0@@ -743,6 +743,7 @@ static const struct cpu_ops cpu_x86_broadwell_ops = { .get_desc = cpu_x86_get_desc, .get_info = broadwell_get_info, .get_count = broadwell_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_broadwell_ids[] = {arch/x86/cpu/cpu_x86.c +13
-0@@ -15,9 +15,21 @@ DECLARE_GLOBAL_DATA_PTR;int cpu_x86_bind (struct udevice *dev) {struct cpu_platdata *plat =dev_get_parent_platdata (dev); +struct cpuid_result res; plat->cpu_id =fdtdec_get_int (gd->fdt_blob, dev->of_offset,"intel,apic-id" ,-1 ); + plat->family = gd->arch.x86; + res =cpuid (1 ); + plat->id[0 ] = res.eax; + plat->id[1 ] = res.edx; + +return 0 ; +} + +int cpu_x86_get_vendor (struct udevice *dev,const char **vendor) +{ + *vendor =cpu_vendor_name (gd->arch.x86_vendor);return 0 ; }@@ -60,6 +72,7 @@ static int cpu_x86_get_count(struct udevice *dev)static const struct cpu_ops cpu_x86_ops = { .get_desc = cpu_x86_get_desc, .get_count = cpu_x86_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_ids[] = {arch/x86/cpu/ivybridge/model_206ax.c +1
-0@@ -478,6 +478,7 @@ static const struct cpu_ops cpu_x86_model_206ax_ops = { .get_desc = cpu_x86_get_desc, .get_info = model_206ax_get_info, .get_count = model_206ax_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_model_206ax_ids[] = {arch/x86/include/asm/cpu_x86.h +12
-0@@ -31,4 +31,16 @@ int cpu_x86_bind(struct udevice *dev);*/ int cpu_x86_get_desc (struct udevice *dev,char *buf,int size); +/** +* cpu_x86_get_vendor() - Get a vendor string for an x86 CPU +* +* This uses cpu_vendor_name() and is suitable to use as the get_vendor() +* method for the CPU uclass. +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to vendor string pointer +* @return: 0 if OK, -ve on error +*/ +int cpu_x86_get_vendor (struct udevice *dev,const char **vendor); +#endif /* _ASM_CPU_X86_H */ drivers/cpu/cpu-uclass.c +0
-0@@ -44,6 +44,16 @@ int cpu_get_count(struct udevice *dev)return ops->get_count (dev); }
Quoted 7 lines
drivers/cpu/cpu-uclass.c int cpu_get_count(struct udevice *dev) · line 51
Quoted 5 lines
drivers/cpu/cpu-uclass.c +5
-0+int cpu_get_vendor (struct udevice *dev,const char **vendor) +{ +struct cpu_ops *ops =cpu_get_ops (dev); + +if (!ops->get_info)This should be: if (!ops->get_vendor)
Oops, thanks :).
Quoted 87 lines
Quoted 87 lines
drivers/cpu/cpu-uclass.c +5
-0+return -ENOSYS ; + +return ops->get_vendor (dev, vendor); +} +U_BOOT_DRIVER (cpu_bus) = { .name ="cpu_bus" , .id =UCLASS_SIMPLE_BUS ,include/cpu.h +20
-0@@ -21,6 +21,8 @@ struct cpu_platdata {int cpu_id;int ucode_version;ulong device_id; +u16 family; +u32 id[2 ]; };/* CPU features - mostly just a placeholder for now */ @@ -71,6 +73,15 @@ struct cpu_ops {* @return CPU count if OK, -ve on error */ int (*get_count)(struct udevice *dev); + +/** +* get_vendor() - Get vendor name of a CPU +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to put the pointer to the vendor string +* @return 0 if OK, -ve on error +*/ +int (*get_vendor)(struct udevice *dev,const char **vendor); };#define cpu_get_ops (dev) ((struct cpu_ops *)(dev)->driver->ops)@@ -102,4 +113,13 @@ int cpu_get_info(struct udevice *dev, struct cpu_info *info);*/ int cpu_get_count (struct udevice *dev); +/** +* cpu_get_vendor() - Get vendor name of a CPU +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to put the pointer to the vendor string +* @return 0 if OK, -ve on error +*/ +int cpu_get_vendor (struct udevice *dev,const char **vendor); +#endif include/smbios.h +3
-0@@ -139,6 +139,9 @@ struct __packed smbios_type3 {#define SMBIOS_PROCESSOR_STATUS_ENABLED 1#define SMBIOS_PROCESSOR_UPGRADE_NONE 6 +#define SMBIOS_PROCESSOR_FAMILY_OTHER 1 +#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 +struct __packed smbios_type4 {u8 type;u8 length;lib/smbios.c +5
-1@@ -10,7 +10,11 @@#include <smbios.h> #include <tables_csum.h> #include <version.h> -#include <asm/cpu.h> +#ifdef CONFIG_CPU +#include <cpu.h> +#include <dm.h> +#include <dm/uclass-internal.h> +#endif DECLARE_GLOBAL_DATA_PTR ;@@ -152,26 +156,45 @@ static int smbios_write_type3(uintptr_t *current, int handle)return len; }
Quoted 6 lines
lib/smbios.c static int smbios_write_type3(uintptr_t *current, int handle) · line 159
Quoted 1 line
lib/smbios.c +1
-0+static void smbios_write_type4_arch (struct smbios_type4 *t)Since now we use cpu uclass to implement this, I don't think
smbios_write_type4_arch()is a proper name, as_archmay indicate this is architecture dependent, however it is not. The whole codes in this function can be put back in the originalsmbios_write_type4().
It certainly exceeds the number of lines that I would put into a single function if I put it all back. Plus variable declaration becomes much more intransparent.
But I can rename it to smbios_write_type4_dm if you like?
Alex
PATCH v4 5/8 smbios: Generate type 4 on non-x86 systems
In reply to Simon GlassThe type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
---
v3 -> v4:
- Use device model
v4 -> v5:
- s/get_info/get_vendor/ typo
- s/smbios_write_type4_arch/smbios_write_type4_dm/
--- arch/x86/cpu/baytrail/cpu.c | 1 + arch/x86/cpu/broadwell/cpu.c | 1 + arch/x86/cpu/cpu_x86.c | 13 ++++++++++ arch/x86/cpu/ivybridge/model_206ax.c | 1 + arch/x86/include/asm/cpu_x86.h | 12 +++++++++ drivers/cpu/cpu-uclass.c | 10 ++++++++ include/cpu.h | 20 +++++++++++++++ include/smbios.h | 3 +++ lib/smbios.c | 49 ++++++++++++++++++++++++++---------- 9 files changed, 97 insertions(+), 13 deletions(-)
arch/x86/cpu/baytrail/cpu.c +1 -0
@@ -141,6 +141,7 @@ static const struct cpu_ops cpu_x86_baytrail_ops = { .get_desc = cpu_x86_get_desc, .get_info = baytrail_get_info, .get_count = baytrail_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_baytrail_ids[] = {
arch/x86/cpu/broadwell/cpu.c +1 -0
@@ -743,6 +743,7 @@ static const struct cpu_ops cpu_x86_broadwell_ops = { .get_desc = cpu_x86_get_desc, .get_info = broadwell_get_info, .get_count = broadwell_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_broadwell_ids[] = {
arch/x86/cpu/cpu_x86.c +13 -0
@@ -15,9 +15,21 @@ DECLARE_GLOBAL_DATA_PTR;int cpu_x86_bind (struct udevice *dev) {struct cpu_platdata *plat =dev_get_parent_platdata (dev); +struct cpuid_result res; plat->cpu_id =fdtdec_get_int (gd->fdt_blob, dev->of_offset,"intel,apic-id" ,-1 ); + plat->family = gd->arch.x86; + res =cpuid (1 ); + plat->id[0 ] = res.eax; + plat->id[1 ] = res.edx; + +return 0 ; +} + +int cpu_x86_get_vendor (struct udevice *dev,const char **vendor) +{ + *vendor =cpu_vendor_name (gd->arch.x86_vendor);return 0 ; }
@@ -60,6 +72,7 @@ static int cpu_x86_get_count(struct udevice *dev)static const struct cpu_ops cpu_x86_ops = { .get_desc = cpu_x86_get_desc, .get_count = cpu_x86_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_ids[] = {
arch/x86/cpu/ivybridge/model_206ax.c +1 -0
@@ -478,6 +478,7 @@ static const struct cpu_ops cpu_x86_model_206ax_ops = { .get_desc = cpu_x86_get_desc, .get_info = model_206ax_get_info, .get_count = model_206ax_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_model_206ax_ids[] = {
arch/x86/include/asm/cpu_x86.h +12 -0
@@ -31,4 +31,16 @@ int cpu_x86_bind(struct udevice *dev);*/ int cpu_x86_get_desc (struct udevice *dev,char *buf,int size); +/** +* cpu_x86_get_vendor() - Get a vendor string for an x86 CPU +* +* This uses cpu_vendor_name() and is suitable to use as the get_vendor() +* method for the CPU uclass. +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to vendor string pointer +* @return: 0 if OK, -ve on error +*/ +int cpu_x86_get_vendor (struct udevice *dev,const char **vendor); +#endif /* _ASM_CPU_X86_H */
drivers/cpu/cpu-uclass.c +10 -0
@@ -44,6 +44,16 @@ int cpu_get_count(struct udevice *dev)return ops->get_count (dev); } +int cpu_get_vendor (struct udevice *dev,const char **vendor) +{ +struct cpu_ops *ops =cpu_get_ops (dev); + +if (!ops->vendor) +return -ENOSYS ; + +return ops->get_vendor (dev, vendor); +} +U_BOOT_DRIVER (cpu_bus) = { .name ="cpu_bus" , .id =UCLASS_SIMPLE_BUS ,
include/cpu.h +20 -0
@@ -21,6 +21,8 @@ struct cpu_platdata {int cpu_id;int ucode_version;ulong device_id; +u16 family; +u32 id[2 ]; };/* CPU features - mostly just a placeholder for now */
@@ -71,6 +73,15 @@ struct cpu_ops {* @return CPU count if OK, -ve on error */ int (*get_count)(struct udevice *dev); + +/** +* get_vendor() - Get vendor name of a CPU +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to put the pointer to the vendor string +* @return 0 if OK, -ve on error +*/ +int (*get_vendor)(struct udevice *dev,const char **vendor); };#define cpu_get_ops (dev) ((struct cpu_ops *)(dev)->driver->ops)
@@ -102,4 +113,13 @@ int cpu_get_info(struct udevice *dev, struct cpu_info *info);*/ int cpu_get_count (struct udevice *dev); +/** +* cpu_get_vendor() - Get vendor name of a CPU +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to put the pointer to the vendor string +* @return 0 if OK, -ve on error +*/ +int cpu_get_vendor (struct udevice *dev,const char **vendor); +#endif
include/smbios.h +3 -0
@@ -139,6 +139,9 @@ struct __packed smbios_type3 {#define SMBIOS_PROCESSOR_STATUS_ENABLED 1#define SMBIOS_PROCESSOR_UPGRADE_NONE 6 +#define SMBIOS_PROCESSOR_FAMILY_OTHER 1 +#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 +struct __packed smbios_type4 {u8 type;u8 length;
lib/smbios.c +36 -13
69 lines not on this page · raw message
Signature · 1 line
1.8.5.6
PATCH v4 5/8 smbios: Generate type 4 on non-x86 systems
Hi Alex,
Quoted 16 lines · Alexander Graf
The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
Signed-off-by Alexander Graf <[email protected]>---
v3 -> v4:
- Use device model
v4 -> v5:
- s/get_info/get_vendor/ typo
- s/smbios_write_type4_arch/smbios_write_type4_dm/
Quoted 11 lines
--- arch/x86/cpu/baytrail/cpu.c | 1 + arch/x86/cpu/broadwell/cpu.c | 1 + arch/x86/cpu/cpu_x86.c | 13 ++++++++++ arch/x86/cpu/ivybridge/model_206ax.c | 1 + arch/x86/include/asm/cpu_x86.h | 12 +++++++++ drivers/cpu/cpu-uclass.c | 10 ++++++++ include/cpu.h | 20 +++++++++++++++ include/smbios.h | 3 +++ lib/smbios.c | 49 ++++++++++++++++++++++++++---------- 9 files changed, 97 insertions(+), 13 deletions(-)
This looks good to me, thanks.
Can you please split out the CPU uclass changes into a separate patch? Also please see a few nits below.
Quoted 80 lines
arch/x86/cpu/baytrail/cpu.c +1
-0@@ -141,6 +141,7 @@ static const struct cpu_ops cpu_x86_baytrail_ops = { .get_desc = cpu_x86_get_desc, .get_info = baytrail_get_info, .get_count = baytrail_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_baytrail_ids[] = {arch/x86/cpu/broadwell/cpu.c +1
-0@@ -743,6 +743,7 @@ static const struct cpu_ops cpu_x86_broadwell_ops = { .get_desc = cpu_x86_get_desc, .get_info = broadwell_get_info, .get_count = broadwell_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_broadwell_ids[] = {arch/x86/cpu/cpu_x86.c +13
-0@@ -15,9 +15,21 @@ DECLARE_GLOBAL_DATA_PTR;int cpu_x86_bind (struct udevice *dev) {struct cpu_platdata *plat =dev_get_parent_platdata (dev); +struct cpuid_result res; plat->cpu_id =fdtdec_get_int (gd->fdt_blob, dev->of_offset,"intel,apic-id" ,-1 ); + plat->family = gd->arch.x86; + res =cpuid (1 ); + plat->id[0 ] = res.eax; + plat->id[1 ] = res.edx; + +return 0 ; +} + +int cpu_x86_get_vendor (struct udevice *dev,const char **vendor) +{ + *vendor =cpu_vendor_name (gd->arch.x86_vendor);return 0 ; }@@ -60,6 +72,7 @@ static int cpu_x86_get_count(struct udevice *dev)static const struct cpu_ops cpu_x86_ops = { .get_desc = cpu_x86_get_desc, .get_count = cpu_x86_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_ids[] = {arch/x86/cpu/ivybridge/model_206ax.c +1
-0@@ -478,6 +478,7 @@ static const struct cpu_ops cpu_x86_model_206ax_ops = { .get_desc = cpu_x86_get_desc, .get_info = model_206ax_get_info, .get_count = model_206ax_get_count, + .get_vendor = cpu_x86_get_vendor, };static const struct udevice_id cpu_x86_model_206ax_ids[] = {arch/x86/include/asm/cpu_x86.h +1
-0@@ -31,4 +31,16 @@ int cpu_x86_bind(struct udevice *dev);*/ int cpu_x86_get_desc (struct udevice *dev,char *buf,int size); +/**
arch/x86/include/asm/cpu_x86.h int cpu_x86_bind(struct udevice *dev); · line 44
Quoted 10 lines
arch/x86/include/asm/cpu_x86.h +10
-0+* cpu_x86_get_vendor() - Get a vendor string for an x86 CPU +* +* This uses cpu_vendor_name() and is suitable to use as the get_vendor() +* method for the CPU uclass. +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to vendor string pointer +* @return: 0 if OK, -ve on error +*/ +int cpu_x86_get_vendor (struct udevice *dev,const char **vendor);
Instead of returning a pointer, can you use a buffer and size as with get_desc()? Or is there a reason why this is worse? It does make things inconsistent.
Quoted 28 lines
arch/x86/include/asm/cpu_x86.h +1
-0+#endif /* _ASM_CPU_X86_H */ drivers/cpu/cpu-uclass.c +10
-0@@ -44,6 +44,16 @@ int cpu_get_count(struct udevice *dev)return ops->get_count (dev); } +int cpu_get_vendor (struct udevice *dev,const char **vendor) +{ +struct cpu_ops *ops =cpu_get_ops (dev); + +if (!ops->vendor) +return -ENOSYS ; + +return ops->get_vendor (dev, vendor); +} +U_BOOT_DRIVER (cpu_bus) = { .name ="cpu_bus" , .id =UCLASS_SIMPLE_BUS ,include/cpu.h +0
-0
include/cpu.h struct cpu_platdata { · line 25
Quoted 5 lines
include/cpu.h +2
-0@@ -21,6 +21,8 @@ struct cpu_platdata {int cpu_id;int ucode_version;ulong device_id; +u16 family; +u32 id[2 ];
Please add comments on these. Actually I see that device_id is missing a comment, oops.
Quoted 123 lines
include/cpu.h +18
-0};/* CPU features - mostly just a placeholder for now */ @@ -71,6 +73,15 @@ struct cpu_ops {* @return CPU count if OK, -ve on error */ int (*get_count)(struct udevice *dev); + +/** +* get_vendor() - Get vendor name of a CPU +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to put the pointer to the vendor string +* @return 0 if OK, -ve on error +*/ +int (*get_vendor)(struct udevice *dev,const char **vendor); };#define cpu_get_ops (dev) ((struct cpu_ops *)(dev)->driver->ops)@@ -102,4 +113,13 @@ int cpu_get_info(struct udevice *dev, struct cpu_info *info);*/ int cpu_get_count (struct udevice *dev); +/** +* cpu_get_vendor() - Get vendor name of a CPU +* +* @dev: Device to check (UCLASS_CPU) +* @vendor: Pointer to put the pointer to the vendor string +* @return 0 if OK, -ve on error +*/ +int cpu_get_vendor (struct udevice *dev,const char **vendor); +#endif include/smbios.h +3
-0@@ -139,6 +139,9 @@ struct __packed smbios_type3 {#define SMBIOS_PROCESSOR_STATUS_ENABLED 1#define SMBIOS_PROCESSOR_UPGRADE_NONE 6 +#define SMBIOS_PROCESSOR_FAMILY_OTHER 1 +#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 +struct __packed smbios_type4 {u8 type;u8 length;lib/smbios.c +36
-14@@ -10,7 +10,11 @@#include <smbios.h> #include <tables_csum.h> #include <version.h> -#include <asm/cpu.h> +#ifdef CONFIG_CPU +#include <cpu.h> +#include <dm.h> +#include <dm/uclass-internal.h> +#endif DECLARE_GLOBAL_DATA_PTR ;@@ -152,26 +156,45 @@ static int smbios_write_type3(uintptr_t *current, int handle)return len; } +static void smbios_write_type4_dm (struct smbios_type4 *t) +{ +u16 processor_family =SMBIOS_PROCESSOR_FAMILY_UNKNOWN ; +const char *vendor ="Unknown" ; +const char *name ="Unknown" ; + +#ifdef CONFIG_CPU +char processor_name[49 ]; +struct udevice *dev =NULL ; + +uclass_find_first_device (UCLASS_CPU , &dev); +if (dev) { +struct cpu_platdata *plat =dev_get_parent_platdata (dev); + +if (plat->family) + processor_family = plat->family; + t->processor_id[0 ] = plat->id[0 ]; + t->processor_id[1 ] = plat->id[1 ]; + +cpu_get_vendor (dev, &vendor); +if (!cpu_get_desc (dev, processor_name,sizeof (processor_name))) + name = processor_name; + } +#endif + + t->processor_family = processor_family; + t->processor_manufacturer =smbios_add_string (t->eos, vendor); + t->processor_version =smbios_add_string (t->eos, name); +} +static int smbios_write_type4 (uintptr_t *current,int handle) {struct smbios_type4 *t = (struct smbios_type4 *)*current;int len =sizeof (struct smbios_type4 ); -const char *vendor; -char *name; -char processor_name[CPU_MAX_NAME_LEN ]; -struct cpuid_result res;memset (t,0 ,sizeof (struct smbios_type4 ));fill_smbios_header (t,SMBIOS_PROCESSOR_INFORMATION , len, handle); t->processor_type =SMBIOS_PROCESSOR_TYPE_CENTRAL ; - t->processor_family = gd->arch.x86; - vendor =cpu_vendor_name (gd->arch.x86_vendor); - t->processor_manufacturer =smbios_add_string (t->eos, vendor); - res =cpuid (1 ); - t->processor_id[0 ] = res.eax; - t->processor_id[1 ] = res.edx; - name =cpu_get_name (processor_name); - t->processor_version =smbios_add_string (t->eos, name); +smbios_write_type4_dm (t); t->status =SMBIOS_PROCESSOR_STATUS_ENABLED ; t->processor_upgrade =SMBIOS_PROCESSOR_UPGRADE_NONE ; t->l1_cache_handle =0xffff ; --
Quoted 2 lines
1.8.5.6
Regards,
Simon
PATCH v3 6/8 smbios: Expose in efi_loader as table
In reply to Alexander GrafWe can pass SMBIOS easily as EFI configuration table to an EFI payload. This patch adds enablement for that case.
While at it, we also enable SMBIOS generation for ARM systems, since they support EFI_LOADER.
---
v1 -> v2:
- Fix whitespace
v2 -> v3:
- Move efi smbios generation to own file
--- cmd/bootefi.c | 3 +++ include/efi_api.h | 4 ++++ include/efi_loader.h | 2 ++ include/smbios.h | 1 + lib/Kconfig | 4 ++-- lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_smbios.c | 32 ++++++++++++++++++++++++++++++++ lib/smbios.c | 6 ++++++ 8 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 lib/efi_loader/efi_smbios.c
cmd/bootefi.c +3 -0
@@ -205,6 +205,9 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt)if (!memcmp (bootefi_device_path[0 ].str,"N\0e\0t" ,6 )) loaded_image_info.device_handle = nethandle;#endif +#ifdef CONFIG_GENERATE_SMBIOS_TABLE +efi_smbios_register (); +#endif /* Initialize EFI runtime services */ efi_reset_system_init ();
include/efi_api.h +4 -0
@@ -201,6 +201,10 @@ struct efi_runtime_services {EFI_GUID (0xb1b621d5 ,0xf19c ,0x41a5 , \ 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0) +#define SMBIOS_TABLE_GUID \ + EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, \ + 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d) +struct efi_configuration_table {efi_guid_t guid;
include/efi_loader.h +2 -0
@@ -85,6 +85,8 @@ int efi_disk_register(void);int efi_gop_register (void );/* Called by bootefi to make the network interface available */ int efi_net_register (void **handle); +/* Called by bootefi to make SMBIOS tables available */ +void efi_smbios_register (void );/* Called by networking code to memorize the dhcp ack package */ void efi_net_set_dhcp_ack (void *pkt,int len);
include/smbios.h +1 -0
@@ -55,6 +55,7 @@ struct __packed smbios_entry {#define BIOS_CHARACTERISTICS_SELECTABLE_BOOT (1 << 16)#define BIOS_CHARACTERISTICS_EXT1_ACPI (1 << 0) +#define BIOS_CHARACTERISTICS_EXT1_UEFI (1 << 3)#define BIOS_CHARACTERISTICS_EXT2_TARGET (1 << 2)struct __packed smbios_type0 {
lib/Kconfig +2 -2
@@ -150,12 +150,12 @@ config SPL_OF_LIBFDT version of the device tree. menu "System tables" - depends on !EFI && !SYS_COREBOOT + depends on (!EFI && !SYS_COREBOOT) || (ARM && EFI_LOADER) config GENERATE_SMBIOS_TABLE bool "Generate an SMBIOS (System Management BIOS) table" default y - depends on X86 + depends on X86 || EFI_LOADER help The System Management BIOS (SMBIOS) specification addresses how motherboard and system vendors present management information about
lib/efi_loader/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-y += efi_memory.o obj-$(CONFIG_LCD) += efi_gop.o obj-$(CONFIG_PARTITIONS) += efi_disk.o obj-$(CONFIG_NET) += efi_net.o +obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o
lib/efi_loader/efi_smbios.c new file +32 -0
@@ -0,0 +1,32 @@ +/* +* EFI application tables support +* +* Copyright (c) 2016 Alexander Graf +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <efi_loader.h> +#include <inttypes.h> +#include <smbios.h> + +static const efi_guid_t smbios_guid =SMBIOS_TABLE_GUID ; + +void efi_smbios_register (void ) +{ +/* Map within the low 32 bits, to allow for 32bit SMBIOS tables */ +uint64_t dmi =0xffffffff ; +/* Reserve 4kb for SMBIOS */ +uint64_t pages =1 ; +int memtype =EFI_RUNTIME_SERVICES_DATA ; + +if (efi_allocate_pages (1 , memtype, pages, &dmi) !=EFI_SUCCESS ) +return ; + +/* Generate SMBIOS tables */ +write_smbios_table (dmi); + +/* And expose them to our EFI payload */ +efi_install_configuration_table (&smbios_guid, (void *)dmi); +}
lib/smbios.c +6 -0
@@ -81,14 +81,20 @@ static int smbios_write_type0(uintptr_t *current, int handle) t->vendor =smbios_add_string (t->eos,"U-Boot" ); t->bios_ver =smbios_add_string (t->eos,PLAIN_VERSION ); t->bios_release_date =smbios_add_string (t->eos,U_BOOT_DMI_DATE ); +#ifdef CONFIG_ROM_SIZE t->bios_rom_size = (CONFIG_ROM_SIZE /65536 ) -1 ; +#endif t->bios_characteristics =BIOS_CHARACTERISTICS_PCI_SUPPORTED |BIOS_CHARACTERISTICS_SELECTABLE_BOOT |BIOS_CHARACTERISTICS_UPGRADEABLE ;#ifdef CONFIG_GENERATE_ACPI_TABLE t->bios_characteristics_ext1 =BIOS_CHARACTERISTICS_EXT1_ACPI ;#endif +#ifdef CONFIG_EFI_LOADER + t->bios_characteristics_ext1 |=BIOS_CHARACTERISTICS_EXT1_UEFI ; +#endif t->bios_characteristics_ext2 =BIOS_CHARACTERISTICS_EXT2_TARGET ; + t->bios_major_release =0xff ; t->bios_minor_release =0xff ; t->ec_major_release =0xff ;
Signature · 1 line
1.8.5.6
PATCH v3 6/8 smbios: Expose in efi_loader as table
Quoted 17 lines · Alexander Graf
We can pass SMBIOS easily as EFI configuration table to an EFI payload. This patch adds enablement for that case.
While at it, we also enable SMBIOS generation for ARM systems, since they support
EFI_LOADER.Signed-off-by Alexander Graf <[email protected]>---
v1 -> v2:
- Fix whitespace
v2 -> v3:
- Move efi smbios generation to own file
Quoted 12 lines
--- cmd/bootefi.c | 3 +++ include/efi_api.h | 4 ++++ include/efi_loader.h | 2 ++ include/smbios.h | 1 + lib/Kconfig | 4 ++-- lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_smbios.c | 32 ++++++++++++++++++++++++++++++++ lib/smbios.c | 6 ++++++ 8 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 lib/efi_loader/efi_smbios.c
PATCH v3 7/8 efi_loader: Fix efi_install_configuration_table
In reply to Alexander GrafSo far we were only installing the FDT table and didn't have space to store any other. Hence nobody realized that our efi table allocation was broken in that it didn't set the indicator for the number of tables plus one.
This patch fixes it, allowing code to allocate new efi tables.
--- lib/efi_loader/efi_boottime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_boottime.c +1 -1
@@ -394,7 +394,7 @@ efi_status_t efi_install_configuration_table(efi_guid_t *guid, void *table)/* Add a new entry */ memcpy (&efi_conf_table[i].guid, guid,sizeof (*guid)); efi_conf_table[i].table = table; - systab.nr_tables = i; + systab.nr_tables = i +1 ;return EFI_SUCCESS ; }
Signature · 1 line
1.8.5.6
PATCH v3 7/8 efi_loader: Fix efi_install_configuration_table
Quoted 11 lines · Alexander Graf
So far we were only installing the FDT table and didn't have space to store any other. Hence nobody realized that our efi table allocation was broken in that it didn't set the indicator for the number of tables plus one.
This patch fixes it, allowing code to allocate new efi tables.
Signed-off-by Alexander Graf <[email protected]>--- lib/efi_loader/efi_boottime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v3 8/8 smbios: Provide serial number
In reply to Alexander GrafIf the system has a valid "serial#" environment variable set (which boards that can find it out programatically set automatically), use that as input for the serial number and UUID fields in the SMBIOS tables.
---
v1 -> v2:
- Also populate UUID
--- lib/smbios.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/smbios.c +5 -0
@@ -110,11 +110,16 @@ static int smbios_write_type1(uintptr_t *current, int handle) {struct smbios_type1 *t = (struct smbios_type1 *)*current;int len =sizeof (struct smbios_type1 ); +char *serial_str =getenv ("serial#" );memset (t,0 ,sizeof (struct smbios_type1 ));fill_smbios_header (t,SMBIOS_SYSTEM_INFORMATION , len, handle); t->manufacturer =smbios_add_string (t->eos,CONFIG_SMBIOS_MANUFACTURER ); t->product_name =smbios_add_string (t->eos,CONFIG_SMBIOS_PRODUCT_NAME ); +if (serial_str) { +strncpy ((char *)t->uuid, serial_str,sizeof (t->uuid)); + t->serial_number =smbios_add_string (t->eos, serial_str); + } len = t->length +smbios_string_table_len (t->eos); *current += len;
Signature · 1 line
1.8.5.6