x86: Pass an ofnode into each SMBIOS function

As a first step to obtaining SMBIOS information from the devicetree, add
an ofnode parameter to the writing functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
Simon Glass 2020-11-05 06:32:07 -07:00 committed by Bin Meng
parent 49337238ef
commit 78227d4eda
2 changed files with 30 additions and 19 deletions

View file

@ -8,6 +8,8 @@
#ifndef _SMBIOS_H_ #ifndef _SMBIOS_H_
#define _SMBIOS_H_ #define _SMBIOS_H_
#include <dm/ofnode.h>
/* SMBIOS spec version implemented */ /* SMBIOS spec version implemented */
#define SMBIOS_MAJOR_VER 3 #define SMBIOS_MAJOR_VER 3
#define SMBIOS_MINOR_VER 0 #define SMBIOS_MINOR_VER 0
@ -222,9 +224,10 @@ static inline void fill_smbios_header(void *table, int type,
* *
* @addr: start address to write the structure * @addr: start address to write the structure
* @handle: the structure's handle, a unique 16-bit number * @handle: the structure's handle, a unique 16-bit number
* @node: node containing the information to write (ofnode_null() if none)
* @return: size of the structure * @return: size of the structure
*/ */
typedef int (*smbios_write_type)(ulong *addr, int handle); typedef int (*smbios_write_type)(ulong *addr, int handle, ofnode node);
/** /**
* write_smbios_table() - Write SMBIOS table * write_smbios_table() - Write SMBIOS table

View file

@ -6,6 +6,7 @@
*/ */
#include <common.h> #include <common.h>
#include <dm.h>
#include <env.h> #include <env.h>
#include <mapmem.h> #include <mapmem.h>
#include <smbios.h> #include <smbios.h>
@ -13,7 +14,6 @@
#include <version.h> #include <version.h>
#ifdef CONFIG_CPU #ifdef CONFIG_CPU
#include <cpu.h> #include <cpu.h>
#include <dm.h>
#include <dm/uclass-internal.h> #include <dm/uclass-internal.h>
#endif #endif
@ -25,7 +25,7 @@
* *
* @start: string area start address * @start: string area start address
* @str: string to add * @str: string to add
* @return: string number in the string area * @return: string number in the string area (1 or more)
*/ */
static int smbios_add_string(char *start, const char *str) static int smbios_add_string(char *start, const char *str)
{ {
@ -74,7 +74,7 @@ static int smbios_string_table_len(char *start)
return len + 1; return len + 1;
} }
static int smbios_write_type0(ulong *current, int handle) static int smbios_write_type0(ulong *current, int handle, ofnode node)
{ {
struct smbios_type0 *t; struct smbios_type0 *t;
int len = sizeof(struct smbios_type0); int len = sizeof(struct smbios_type0);
@ -111,7 +111,7 @@ static int smbios_write_type0(ulong *current, int handle)
return len; return len;
} }
static int smbios_write_type1(ulong *current, int handle) static int smbios_write_type1(ulong *current, int handle, ofnode node)
{ {
struct smbios_type1 *t; struct smbios_type1 *t;
int len = sizeof(struct smbios_type1); int len = sizeof(struct smbios_type1);
@ -134,7 +134,7 @@ static int smbios_write_type1(ulong *current, int handle)
return len; return len;
} }
static int smbios_write_type2(ulong *current, int handle) static int smbios_write_type2(ulong *current, int handle, ofnode node)
{ {
struct smbios_type2 *t; struct smbios_type2 *t;
int len = sizeof(struct smbios_type2); int len = sizeof(struct smbios_type2);
@ -154,7 +154,7 @@ static int smbios_write_type2(ulong *current, int handle)
return len; return len;
} }
static int smbios_write_type3(ulong *current, int handle) static int smbios_write_type3(ulong *current, int handle, ofnode node)
{ {
struct smbios_type3 *t; struct smbios_type3 *t;
int len = sizeof(struct smbios_type3); int len = sizeof(struct smbios_type3);
@ -176,7 +176,7 @@ static int smbios_write_type3(ulong *current, int handle)
return len; return len;
} }
static void smbios_write_type4_dm(struct smbios_type4 *t) static void smbios_write_type4_dm(struct smbios_type4 *t, ofnode node)
{ {
u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN; u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN;
const char *vendor = "Unknown"; const char *vendor = "Unknown";
@ -185,20 +185,20 @@ static void smbios_write_type4_dm(struct smbios_type4 *t)
#ifdef CONFIG_CPU #ifdef CONFIG_CPU
char processor_name[49]; char processor_name[49];
char vendor_name[49]; char vendor_name[49];
struct udevice *dev = NULL; struct udevice *cpu = NULL;
uclass_find_first_device(UCLASS_CPU, &dev); uclass_find_first_device(UCLASS_CPU, &cpu);
if (dev) { if (cpu) {
struct cpu_platdata *plat = dev_get_parent_platdata(dev); struct cpu_platdata *plat = dev_get_parent_platdata(cpu);
if (plat->family) if (plat->family)
processor_family = plat->family; processor_family = plat->family;
t->processor_id[0] = plat->id[0]; t->processor_id[0] = plat->id[0];
t->processor_id[1] = plat->id[1]; t->processor_id[1] = plat->id[1];
if (!cpu_get_vendor(dev, vendor_name, sizeof(vendor_name))) if (!cpu_get_vendor(cpu, vendor_name, sizeof(vendor_name)))
vendor = vendor_name; vendor = vendor_name;
if (!cpu_get_desc(dev, processor_name, sizeof(processor_name))) if (!cpu_get_desc(cpu, processor_name, sizeof(processor_name)))
name = processor_name; name = processor_name;
} }
#endif #endif
@ -208,7 +208,7 @@ static void smbios_write_type4_dm(struct smbios_type4 *t)
t->processor_version = smbios_add_string(t->eos, name); t->processor_version = smbios_add_string(t->eos, name);
} }
static int smbios_write_type4(ulong *current, int handle) static int smbios_write_type4(ulong *current, int handle, ofnode node)
{ {
struct smbios_type4 *t; struct smbios_type4 *t;
int len = sizeof(struct smbios_type4); int len = sizeof(struct smbios_type4);
@ -217,7 +217,7 @@ static int smbios_write_type4(ulong *current, int handle)
memset(t, 0, sizeof(struct smbios_type4)); memset(t, 0, sizeof(struct smbios_type4));
fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle); fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle);
t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL; t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL;
smbios_write_type4_dm(t); smbios_write_type4_dm(t, node);
t->status = SMBIOS_PROCESSOR_STATUS_ENABLED; t->status = SMBIOS_PROCESSOR_STATUS_ENABLED;
t->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE; t->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE;
t->l1_cache_handle = 0xffff; t->l1_cache_handle = 0xffff;
@ -232,7 +232,7 @@ static int smbios_write_type4(ulong *current, int handle)
return len; return len;
} }
static int smbios_write_type32(ulong *current, int handle) static int smbios_write_type32(ulong *current, int handle, ofnode node)
{ {
struct smbios_type32 *t; struct smbios_type32 *t;
int len = sizeof(struct smbios_type32); int len = sizeof(struct smbios_type32);
@ -247,7 +247,7 @@ static int smbios_write_type32(ulong *current, int handle)
return len; return len;
} }
static int smbios_write_type127(ulong *current, int handle) static int smbios_write_type127(ulong *current, int handle, ofnode node)
{ {
struct smbios_type127 *t; struct smbios_type127 *t;
int len = sizeof(struct smbios_type127); int len = sizeof(struct smbios_type127);
@ -274,7 +274,9 @@ static smbios_write_type smbios_write_funcs[] = {
ulong write_smbios_table(ulong addr) ulong write_smbios_table(ulong addr)
{ {
ofnode node = ofnode_null();
struct smbios_entry *se; struct smbios_entry *se;
struct udevice *dev;
ulong table_addr; ulong table_addr;
ulong tables; ulong tables;
int len = 0; int len = 0;
@ -284,6 +286,12 @@ ulong write_smbios_table(ulong addr)
int isize; int isize;
int i; int i;
if (IS_ENABLED(CONFIG_OF_CONTROL)) {
uclass_first_device(UCLASS_SYSINFO, &dev);
if (dev)
node = dev_read_subnode(dev, "smbios");
}
/* 16 byte align the table address */ /* 16 byte align the table address */
addr = ALIGN(addr, 16); addr = ALIGN(addr, 16);
@ -296,7 +304,7 @@ ulong write_smbios_table(ulong addr)
/* populate minimum required tables */ /* populate minimum required tables */
for (i = 0; i < ARRAY_SIZE(smbios_write_funcs); i++) { for (i = 0; i < ARRAY_SIZE(smbios_write_funcs); i++) {
int tmp = smbios_write_funcs[i]((ulong *)&addr, handle++); int tmp = smbios_write_funcs[i]((ulong *)&addr, handle++, node);
max_struct_size = max(max_struct_size, tmp); max_struct_size = max(max_struct_size, tmp);
len += tmp; len += tmp;