From 415eab0655a8bdfa07464e2b3f9724a198afc81f Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Tue, 3 Nov 2020 15:34:51 +0100 Subject: smbios: add parsing API Add a very simple API to be able to access SMBIOS strings like vendor, model and bios version. Signed-off-by: Christian Gmeiner Reviewed-by: Bin Meng --- include/smbios.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'include') diff --git a/include/smbios.h b/include/smbios.h index 97b9ddce237..44f49e9556b 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -237,4 +237,31 @@ typedef int (*smbios_write_type)(ulong *addr, int handle); */ ulong write_smbios_table(ulong addr); +/** + * smbios_entry() - Get a valid struct smbios_entry pointer + * + * @address: address where smbios tables is located + * @size: size of smbios table + * @return: NULL or a valid pointer to a struct smbios_entry + */ +const struct smbios_entry *smbios_entry(u64 address, u32 size); + +/** + * smbios_header() - Search for SMBIOS header type + * + * @entry: pointer to a struct smbios_entry + * @type: SMBIOS type + * @return: NULL or a valid pointer to a struct smbios_header + */ +const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type); + +/** + * smbios_string() - Return string from SMBIOS + * + * @header: pointer to struct smbios_header + * @index: string index + * @return: NULL or a valid const char pointer + */ +const char *smbios_string(const struct smbios_header *header, int index); + #endif /* _SMBIOS_H_ */ -- cgit v1.3.1 From 1779b8a96a32706dc8e2e71187889b38d9822443 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 4 Nov 2020 09:57:14 -0700 Subject: Add an assembly guard around linux/bitops.h This file can be included by any header but it includes C code. Guard it to avoid errors when compiling ASL, etc. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- include/linux/bitops.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 6b509dce58a..16f28993f5e 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -1,7 +1,7 @@ #ifndef _LINUX_BITOPS_H #define _LINUX_BITOPS_H -#ifndef USE_HOSTCC +#if !defined(USE_HOSTCC) && !defined(__ASSEMBLY__) #include #include @@ -218,6 +218,6 @@ static inline void generic_clear_bit(int nr, volatile unsigned long *addr) *p &= ~mask; } -#endif /* !USE_HOSTCC */ +#endif /* !USE_HOSTCC && !__ASSEMBLY__ */ #endif -- cgit v1.3.1 From 5019e201ccaee4bd54ba707dfc4eece885857629 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 4 Nov 2020 09:57:19 -0700 Subject: x86: acpi: Store the ACPI context in global_data At present we create the ACPI context but then drop it after generation of tables is complete. This is annoying because we have to then search for tables later. To fix this, allocate the context and store it in global_data. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- arch/x86/lib/acpi_table.c | 7 ++++++- include/asm-generic/global_data.h | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index 6d405b09fde..f0f342d8935 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -494,7 +494,7 @@ void acpi_create_ssdt(struct acpi_ctx *ctx, struct acpi_table_header *ssdt, */ ulong write_acpi_tables(ulong start_addr) { - struct acpi_ctx sctx, *ctx = &sctx; + struct acpi_ctx *ctx; struct acpi_facs *facs; struct acpi_table_header *dsdt; struct acpi_fadt *fadt; @@ -509,6 +509,11 @@ ulong write_acpi_tables(ulong start_addr) int ret; int i; + ctx = calloc(1, sizeof(*ctx)); + if (!ctx) + return log_msg_ret("mem", -ENOMEM); + gd->acpi_ctx = ctx; + start = map_sysmem(start_addr, 0); debug("ACPI: Writing ACPI tables at %lx\n", start_addr); diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index f3920437968..87d827d0f43 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -24,6 +24,7 @@ #include #include +struct acpi_ctx; struct driver_rt; typedef struct global_data gd_t; @@ -420,6 +421,12 @@ struct global_data { */ struct udevice *watchdog_dev; #endif +#ifdef CONFIG_GENERATE_ACPI_TABLE + /** + * @acpi_ctx: ACPI context pointer + */ + struct acpi_ctx *acpi_ctx; +#endif }; /** @@ -452,6 +459,12 @@ struct global_data { #define gd_dm_driver_rt() NULL #endif +#ifdef CONFIG_GENERATE_ACPI_TABLE +#define gd_acpi_ctx() gd->acpi_ctx +#else +#define gd_acpi_ctx() NULL +#endif + /** * enum gd_flags - global data flags * -- cgit v1.3.1 From d2cb7a22da0fec2b67b356e9fb58247cdff8c95e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 4 Nov 2020 09:57:25 -0700 Subject: x86: Allow putting some tables in the bloblist At present all tables are placed starting at address f0000 in memory, and can be up to 64KB in size. If the tables are very large, this may not provide enough space. Also if the tables point to other tables (such as console log or a ramoops area) then we must allocate other memory anyway. The bloblist is a nice place to put these tables since it is contiguous, which makes it easy to reserve this memory for linux using the 820 tables. Add an option to put some of the tables in the bloblist. For SMBIOS and ACPI, create suitable pointers from the f0000 region to the new location of the tables. Signed-off-by: Simon Glass Reviewed-by: Bin Meng [bmeng: squashed in http://patchwork.ozlabs.org/project/uboot/patch/ 20201105062407.1.I8091ad931cbbb5e3b6f6ababdf3f8d5db0d17bb9@changeid/] Signed-off-by: Bin Meng --- arch/x86/lib/tables.c | 49 ++++++++++++++++++++++++++++++++++++++++++++--- include/acpi/acpi_table.h | 10 ++++++++++ include/bloblist.h | 2 ++ lib/Kconfig | 9 +++++++++ lib/acpi/acpi_table.c | 4 ++-- 5 files changed, 69 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c index f7b71c5cd13..c4007fa4866 100644 --- a/arch/x86/lib/tables.c +++ b/arch/x86/lib/tables.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -13,6 +14,8 @@ #include #include +DECLARE_GLOBAL_DATA_PTR; + /** * Function prototype to write a specific configuration table * @@ -26,10 +29,16 @@ typedef ulong (*table_write)(ulong addr); * * @name: Name of table (for debugging) * @write: Function to call to write this table + * @tag: Bloblist tag if using CONFIG_BLOBLIST_TABLES + * @size: Maximum table size + * @align: Table alignment in bytes */ struct table_info { const char *name; table_write write; + enum bloblist_tag_t tag; + int size; + int align; }; static struct table_info table_list[] = { @@ -43,10 +52,10 @@ static struct table_info table_list[] = { { "mp", write_mp_table, }, #endif #ifdef CONFIG_GENERATE_ACPI_TABLE - { "acpi", write_acpi_tables, }, + { "acpi", write_acpi_tables, BLOBLISTT_ACPI_TABLES, 0x10000, 0x1000}, #endif #ifdef CONFIG_GENERATE_SMBIOS_TABLE - { "smbios", write_smbios_table, }, + { "smbios", write_smbios_table, BLOBLISTT_SMBIOS_TABLES, 0x1000, 0x100}, #endif }; @@ -66,16 +75,25 @@ void table_fill_string(char *dest, const char *src, size_t n, char pad) int write_tables(void) { - u32 rom_table_start = ROM_TABLE_ADDR; + u32 rom_table_start; u32 rom_table_end; u32 high_table, table_size; struct memory_area cfg_tables[ARRAY_SIZE(table_list) + 1]; int i; + rom_table_start = ROM_TABLE_ADDR; + debug("Writing tables to %x:\n", rom_table_start); for (i = 0; i < ARRAY_SIZE(table_list); i++) { const struct table_info *table = &table_list[i]; + int size = table->size ? : CONFIG_ROM_TABLE_SIZE; + if (IS_ENABLED(CONFIG_BLOBLIST_TABLES) && table->tag) { + rom_table_start = (ulong)bloblist_add(table->tag, size, + table->align); + if (!rom_table_start) + return log_msg_ret("bloblist", -ENOBUFS); + } rom_table_end = table->write(rom_table_start); rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN); @@ -96,6 +114,11 @@ int write_tables(void) debug("- wrote '%s' to %x, end %x\n", table->name, rom_table_start, rom_table_end); + if (rom_table_end - rom_table_start > size) { + log_err("Out of space for configuration tables: need %x, have %x\n", + rom_table_end - rom_table_start, size); + return log_msg_ret("bloblist", -ENOSPC); + } rom_table_start = rom_table_end; } @@ -105,6 +128,26 @@ int write_tables(void) write_coreboot_table(CB_TABLE_ADDR, cfg_tables); } + if (IS_ENABLED(CONFIG_BLOBLIST_TABLES)) { + void *ptr = (void *)CONFIG_ROM_TABLE_ADDR; + + /* Write an RSDP pointing to the tables */ + if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) { + struct acpi_ctx *ctx = gd_acpi_ctx(); + + acpi_write_rsdp(ptr, ctx->rsdt, ctx->xsdt); + ptr += ALIGN(sizeof(struct acpi_rsdp), 16); + } + if (IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE)) { + void *smbios; + + smbios = bloblist_find(BLOBLISTT_SMBIOS_TABLES, 0); + if (!smbios) + return log_msg_ret("smbios", -ENOENT); + memcpy(ptr, smbios, sizeof(struct smbios_entry)); + } + } + debug("- done writing tables\n"); return 0; diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h index abbca6530db..a28eb71f4d7 100644 --- a/include/acpi/acpi_table.h +++ b/include/acpi/acpi_table.h @@ -688,6 +688,16 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table); */ void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start); +/** + * acpi_write_rsdp() - Write out an RSDP indicating where the ACPI tables are + * + * @rsdp: Address to write RSDP + * @rsdt: Address of RSDT + * @xsdt: Address of XSDT + */ +void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, + struct acpi_xsdt *xsdt); + #endif /* !__ACPI__*/ #include diff --git a/include/bloblist.h b/include/bloblist.h index 2b4b6696897..8cdce61187a 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -36,6 +36,8 @@ enum bloblist_tag_t { BLOBLISTT_INTEL_VBT, /* Intel Video-BIOS table */ BLOBLISTT_TPM2_TCG_LOG, /* TPM v2 log space */ BLOBLISTT_TCPA_LOG, /* TPM log space */ + BLOBLISTT_ACPI_TABLES, /* ACPI tables for x86 */ + BLOBLISTT_SMBIOS_TABLES, /* SMBIOS tables for x86 */ BLOBLISTT_COUNT }; diff --git a/lib/Kconfig b/lib/Kconfig index 5f1b95d7d7b..8f487533e8c 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -637,6 +637,15 @@ config FDT_FIXUP_PARTITIONS menu "System tables" depends on (!EFI && !SYS_COREBOOT) || (ARM && EFI_LOADER) +config BLOBLIST_TABLES + bool "Put tables in a bloblist" + depends on X86 + help + Normally tables are placed at address 0xf0000 and can be up to 64KB + long. With this option, tables are instead placed in the bloblist + with a pointer from 0xf0000. The size can then be larger and the + tables can be placed high in memory. + config GENERATE_SMBIOS_TABLE bool "Generate an SMBIOS (System Management BIOS) table" default y diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index 908d8903893..a0f0961be5b 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -183,8 +183,8 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table) return 0; } -static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, - struct acpi_xsdt *xsdt) +void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, + struct acpi_xsdt *xsdt) { memset(rsdp, 0, sizeof(struct acpi_rsdp)); -- cgit v1.3.1 From 18434aec1b69d8490cb23ef35b2f39cf1784d1d0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 4 Nov 2020 09:57:33 -0700 Subject: acpi: Don't reset the tables with every new generation At present if SSDT and DSDT code is created, only the latter is retained for examination by the 'acpi items' command. Fix this by only resetting the list when explicitly requested. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- arch/x86/lib/acpi_table.c | 1 + drivers/core/acpi.c | 10 ++++++---- include/dm/acpi.h | 9 +++++++++ test/dm/acpi.c | 4 ++++ 4 files changed, 20 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index 423df5cbf9b..66cff822dc2 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -531,6 +531,7 @@ ulong write_acpi_tables(ulong start_addr) debug("ACPI: Writing ACPI tables at %lx\n", start_addr); + acpi_reset_items(); acpi_setup_base_tables(ctx, start); debug("ACPI: * FACS\n"); diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c index 7fe93992b5f..63a791f335e 100644 --- a/drivers/core/acpi.c +++ b/drivers/core/acpi.c @@ -268,8 +268,7 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent, if (func) { void *start = ctx->current; - log_debug("\n"); - log_debug("- %s %p\n", parent->name, func); + log_debug("- method %d, %s %p\n", method, parent->name, func); ret = device_ofdata_to_platdata(parent); if (ret) return log_msg_ret("ofdata", ret); @@ -299,7 +298,6 @@ int acpi_fill_ssdt(struct acpi_ctx *ctx) int ret; log_debug("Writing SSDT tables\n"); - item_count = 0; ret = acpi_recurse_method(ctx, dm_root(), METHOD_FILL_SSDT, TYPE_SSDT); log_debug("Writing SSDT finished, err=%d\n", ret); ret = sort_acpi_item_type(ctx, start, TYPE_SSDT); @@ -315,7 +313,6 @@ int acpi_inject_dsdt(struct acpi_ctx *ctx) int ret; log_debug("Writing DSDT tables\n"); - item_count = 0; ret = acpi_recurse_method(ctx, dm_root(), METHOD_INJECT_DSDT, TYPE_DSDT); log_debug("Writing DSDT finished, err=%d\n", ret); @@ -326,6 +323,11 @@ int acpi_inject_dsdt(struct acpi_ctx *ctx) return ret; } +void acpi_reset_items(void) +{ + item_count = 0; +} + int acpi_write_dev_tables(struct acpi_ctx *ctx) { int ret; diff --git a/include/dm/acpi.h b/include/dm/acpi.h index e8b0336f6d8..e6951b6a25d 100644 --- a/include/dm/acpi.h +++ b/include/dm/acpi.h @@ -226,6 +226,15 @@ void acpi_dump_items(enum acpi_dump_option option); */ int acpi_get_path(const struct udevice *dev, char *out_path, int maxlen); +/** + * acpi_reset_items() - Reset the list of ACPI items to empty + * + * This list keeps track of DSDT and SSDT items that are generated + * programmatically. The 'acpi items' command shows the list. Use this function + * to empty the list, before writing new items. + */ +void acpi_reset_items(void); + #endif /* __ACPI__ */ #endif diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 1f252a8d454..f5eddac10d0 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -477,6 +477,7 @@ static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts) buf = malloc(BUF_SIZE); ut_assertnonnull(buf); + acpi_reset_items(); ctx.current = buf; buf[4] = 'z'; /* sentinel */ ut_assertok(acpi_fill_ssdt(&ctx)); @@ -507,6 +508,7 @@ static int dm_test_acpi_inject_dsdt(struct unit_test_state *uts) buf = malloc(BUF_SIZE); ut_assertnonnull(buf); + acpi_reset_items(); ctx.current = buf; buf[4] = 'z'; /* sentinel */ ut_assertok(acpi_inject_dsdt(&ctx)); @@ -537,6 +539,7 @@ static int dm_test_acpi_cmd_items(struct unit_test_state *uts) buf = malloc(BUF_SIZE); ut_assertnonnull(buf); + acpi_reset_items(); ctx.current = buf; ut_assertok(acpi_fill_ssdt(&ctx)); console_record_reset(); @@ -545,6 +548,7 @@ static int dm_test_acpi_cmd_items(struct unit_test_state *uts) ut_assert_nextline("dev 'acpi-test2', type 1, size 2"); ut_assert_console_end(); + acpi_reset_items(); ctx.current = buf; ut_assertok(acpi_inject_dsdt(&ctx)); console_record_reset(); -- cgit v1.3.1 From e0028ab75a8da96b85b210adda323ca2bf3da94f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 4 Nov 2020 09:57:37 -0700 Subject: x86: Boot coral into Chrome OS by default Add a script to boot Chrome OS from the internal MMC. This involved adding a few commands and options. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- configs/chromebook_coral_defconfig | 10 +++++++--- include/configs/chromebook_coral.h | 9 ++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig index 827974f7fcf..e5ad79dcf76 100644 --- a/configs/chromebook_coral_defconfig +++ b/configs/chromebook_coral_defconfig @@ -29,8 +29,10 @@ CONFIG_BOOTSTAGE_REPORT=y CONFIG_SPL_BOOTSTAGE_RECORD_COUNT=10 CONFIG_BOOTSTAGE_STASH=y CONFIG_USE_BOOTARGS=y -CONFIG_BOOTARGS="console=ttyS2,115200n8 cros_legacy loglevel=9 init=/sbin/init oops=panic panic=-1 root=PARTUUID=35c775e7-3735-d745-93e5-d9e0238f7ed0/PARTNROFF=1 rootwait rw noinitrd vt.global_cursor_default=0 add_efi_memmap boot=local noresume noswap i915.modeset=1 nmi_watchdog=panic,lapic disablevmx=off" +CONFIG_BOOTARGS="" +CONFIG_BOOTARGS_SUBST=y CONFIG_SYS_CONSOLE_INFO_QUIET=y +CONFIG_LOGF_FUNC=y CONFIG_SPL_LOG=y CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_LAST_STAGE_INIT=y @@ -55,11 +57,11 @@ CONFIG_CMD_READ=y CONFIG_CMD_SATA=y CONFIG_CMD_SPI=y CONFIG_CMD_USB=y -# CONFIG_CMD_SETEXPR is not set CONFIG_CMD_TIME=y CONFIG_CMD_SOUND=y CONFIG_CMD_BOOTSTAGE=y CONFIG_CMD_TPM=y +CONFIG_CMD_CBFS=y CONFIG_CMD_EXT2=y CONFIG_CMD_EXT4=y CONFIG_CMD_EXT4_WRITE=y @@ -72,7 +74,6 @@ CONFIG_ISO_PARTITION=y CONFIG_EFI_PARTITION=y # CONFIG_SPL_EFI_PARTITION is not set CONFIG_ENV_OVERWRITE=y -# CONFIG_NET is not set CONFIG_REGMAP=y CONFIG_SYSCON=y CONFIG_SPL_OF_TRANSLATE=y @@ -106,10 +107,13 @@ CONFIG_USB_XHCI_HCD=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y CONFIG_VIDEO_COPY=y +CONFIG_FS_CBFS=y CONFIG_SPL_FS_CBFS=y +CONFIG_FAT_WRITE=y # CONFIG_SPL_USE_TINY_PRINTF is not set CONFIG_TPL_USE_TINY_PRINTF=y CONFIG_CMD_DHRYSTONE=y CONFIG_TPM=y # CONFIG_GZIP is not set +CONFIG_BLOBLIST_TABLES=y # CONFIG_EFI_LOADER is not set diff --git a/include/configs/chromebook_coral.h b/include/configs/chromebook_coral.h index a63c3c9eea8..d4d32758e99 100644 --- a/include/configs/chromebook_coral.h +++ b/include/configs/chromebook_coral.h @@ -11,7 +11,14 @@ #define __CONFIG_H #define CONFIG_BOOTCOMMAND \ - "fatload mmc 1:c 1000000 syslinux/vmlinuz.A; zboot 1000000" + "tpm init; tpm startup TPM2_SU_CLEAR; " \ + "read mmc 2:2 100000 0 80; setexpr loader *001004f0; " \ + "setexpr size *00100518; setexpr blocks $size / 200; " \ + "read mmc 2:2 100000 80 $blocks; setexpr setup $loader - 1000; " \ + "setexpr cmdline $loader - 2000; " \ + "part uuid mmc 2:2 uuid; setenv bootargs_U $uuid; " \ + "zboot start 100000 0 0 0 $setup $cmdline; " \ + "zboot load; zboot setup; zboot dump; zboot go" #include #include -- cgit v1.3.1 From b73d61a5565c3ab9e207a288186049806ce13e1b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 4 Nov 2020 09:59:13 -0700 Subject: x86: zimage: Add a little more logging Add logging for each part of the boot process, using a new Signed-off-by: Simon Glass Reviewed-by: Bin Meng Reviewed-by: Igor Opaniuk --- arch/x86/lib/zimage.c | 6 ++++++ common/log.c | 1 + include/log.h | 1 + 3 files changed, 8 insertions(+) (limited to 'include') diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c index a00964cc8d9..7418c9a5fed 100644 --- a/arch/x86/lib/zimage.c +++ b/arch/x86/lib/zimage.c @@ -12,10 +12,13 @@ * linux/Documentation/i386/boot.txt */ +#define LOG_CATEGORY LOGC_BOOT + #include #include #include #include +#include #include #include #include @@ -292,6 +295,7 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot, struct setup_header *hdr = &setup_base->hdr; int bootproto = get_boot_protocol(hdr, false); + log_debug("Setup E820 entries\n"); setup_base->e820_entries = install_e820_map( ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map); @@ -317,6 +321,7 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot, } if (cmd_line) { + log_debug("Setup cmdline\n"); if (bootproto >= 0x0202) { hdr->cmd_line_ptr = (uintptr_t)cmd_line; } else if (bootproto >= 0x0200) { @@ -340,6 +345,7 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot, if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) setup_base->acpi_rsdp_addr = acpi_get_rsdp_addr(); + log_debug("Setup devicetree\n"); setup_device_tree(hdr, (const void *)env_get_hex("fdtaddr", 0)); setup_video(&setup_base->screen_info); diff --git a/common/log.c b/common/log.c index 4b6f3fcd04a..ce39918e045 100644 --- a/common/log.c +++ b/common/log.c @@ -26,6 +26,7 @@ static const char *const log_cat_name[] = { "bloblist", "devres", "acpi", + "boot", }; _Static_assert(ARRAY_SIZE(log_cat_name) == LOGC_COUNT - LOGC_NONE, diff --git a/include/log.h b/include/log.h index 4d0692f155d..29f18a82dcf 100644 --- a/include/log.h +++ b/include/log.h @@ -96,6 +96,7 @@ enum log_category_t { LOGC_DEVRES, /** @LOGC_ACPI: Advanced Configuration and Power Interface (ACPI) */ LOGC_ACPI, + LOGC_BOOT, /* Related to boot process / boot image processing */ /** @LOGC_COUNT: Number of log categories */ LOGC_COUNT, -- cgit v1.3.1 From 3a8ee3df836614b68881f5b84d3197305ee1b08e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 06:32:05 -0700 Subject: board: Rename uclass to sysinfo This uclass is intended to provide a way to obtain information about a U-Boot board. But the concept of a U-Boot 'board' is the whole system, not just one circuit board, meaning that 'board' is something of a misnomer for this uclass. In addition, the name 'board' is a bit overused in U-Boot and we want to use the same uclass to provide SMBIOS information. The obvious name is 'system' but that is so vague as to be meaningless. Use 'sysinfo' instead, since this uclass is aimed at providing information on the system. Rename everything accordingly. Note: Due to the patch delta caused by the symbol renames, this patch shows some renamed files as being deleted in one place and created in another. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- arch/powerpc/dts/gdsys/gazerbeam-uboot.dtsi | 2 +- arch/sandbox/dts/test.dts | 8 +- board/gdsys/common/cmd_ioloop.c | 12 +- board/gdsys/mpc8308/gazerbeam.c | 47 ++-- board/google/chromebook_coral/coral.c | 2 +- common/spl/spl_fit.c | 15 +- configs/chromebook_coral_defconfig | 2 +- configs/gazerbeam_defconfig | 4 +- configs/sandbox64_defconfig | 4 +- configs/sandbox_defconfig | 4 +- configs/sandbox_flattree_defconfig | 4 +- configs/sandbox_spl_defconfig | 4 +- .../board/gdsys,board_gazerbeam.txt | 46 ---- .../sysinfo/gdsys,sysinfo_gazerbeam.txt | 46 ++++ drivers/Kconfig | 4 +- drivers/Makefile | 2 +- drivers/board/Kconfig | 25 -- drivers/board/Makefile | 7 - drivers/board/board-uclass.c | 71 ------ drivers/board/gazerbeam.c | 265 --------------------- drivers/board/gazerbeam.h | 17 -- drivers/board/sandbox.c | 107 --------- drivers/board/sandbox.h | 12 - drivers/sysinfo/Kconfig | 25 ++ drivers/sysinfo/Makefile | 7 + drivers/sysinfo/gazerbeam.c | 265 +++++++++++++++++++++ drivers/sysinfo/gazerbeam.h | 17 ++ drivers/sysinfo/sandbox.c | 107 +++++++++ drivers/sysinfo/sandbox.h | 12 + drivers/sysinfo/sysinfo-uclass.c | 71 ++++++ drivers/timer/mpc83xx_timer.c | 10 +- include/board.h | 213 ----------------- include/dm/uclass-id.h | 2 +- include/sysinfo.h | 213 +++++++++++++++++ test/dm/Makefile | 2 +- test/dm/board.c | 59 ----- test/dm/sysinfo.c | 59 +++++ 37 files changed, 889 insertions(+), 883 deletions(-) delete mode 100644 doc/device-tree-bindings/board/gdsys,board_gazerbeam.txt create mode 100644 doc/device-tree-bindings/sysinfo/gdsys,sysinfo_gazerbeam.txt delete mode 100644 drivers/board/Kconfig delete mode 100644 drivers/board/Makefile delete mode 100644 drivers/board/board-uclass.c delete mode 100644 drivers/board/gazerbeam.c delete mode 100644 drivers/board/gazerbeam.h delete mode 100644 drivers/board/sandbox.c delete mode 100644 drivers/board/sandbox.h create mode 100644 drivers/sysinfo/Kconfig create mode 100644 drivers/sysinfo/Makefile create mode 100644 drivers/sysinfo/gazerbeam.c create mode 100644 drivers/sysinfo/gazerbeam.h create mode 100644 drivers/sysinfo/sandbox.c create mode 100644 drivers/sysinfo/sandbox.h create mode 100644 drivers/sysinfo/sysinfo-uclass.c delete mode 100644 include/board.h create mode 100644 include/sysinfo.h delete mode 100644 test/dm/board.c create mode 100644 test/dm/sysinfo.c (limited to 'include') diff --git a/arch/powerpc/dts/gdsys/gazerbeam-uboot.dtsi b/arch/powerpc/dts/gdsys/gazerbeam-uboot.dtsi index 1c4977f20f3..3439737fa3f 100644 --- a/arch/powerpc/dts/gdsys/gazerbeam-uboot.dtsi +++ b/arch/powerpc/dts/gdsys/gazerbeam-uboot.dtsi @@ -32,7 +32,7 @@ }; board { - compatible = "gdsys,board_gazerbeam"; + compatible = "gdsys,sysinfo-gazerbeam"; csb = <&board_soc>; serdes = <&SERDES>; rxaui0 = <&RXAUI0_0>; diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 70ccb4951ad..f3b766271d3 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -1103,10 +1103,6 @@ compatible = "sandbox,sandbox_osd"; }; - board { - compatible = "sandbox,board_sandbox"; - }; - sandbox_tee { compatible = "sandbox,tee"; }; @@ -1242,6 +1238,10 @@ reset-names = "valid", "no_mask", "out_of_range"; }; + sysinfo { + compatible = "sandbox,sysinfo-sandbox"; + }; + some_regmapped-bus { #address-cells = <0x1>; #size-cells = <0x1>; diff --git a/board/gdsys/common/cmd_ioloop.c b/board/gdsys/common/cmd_ioloop.c index 3ea2bec8ebd..658756d9842 100644 --- a/board/gdsys/common/cmd_ioloop.c +++ b/board/gdsys/common/cmd_ioloop.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include "../../../drivers/misc/gdsys_soc.h" #include "../../../drivers/misc/gdsys_ioep.h" @@ -506,11 +506,11 @@ int do_ioloop(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) int do_iodev(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *ioep = NULL; - struct udevice *board; + struct udevice *sysinfo; char name[8]; int ret; - if (board_get(&board)) + if (sysinfo_get(&sysinfo)) return CMD_RET_FAILURE; if (argc > 1) { @@ -518,7 +518,8 @@ int do_iodev(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) snprintf(name, sizeof(name), "ioep%d", i); - ret = uclass_get_device_by_phandle(UCLASS_MISC, board, name, &ioep); + ret = uclass_get_device_by_phandle(UCLASS_MISC, sysinfo, name, + &ioep); if (ret || !ioep) { printf("Invalid IOEP %d\n", i); @@ -532,7 +533,8 @@ int do_iodev(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) while (1) { snprintf(name, sizeof(name), "ioep%d", i); - ret = uclass_get_device_by_phandle(UCLASS_MISC, board, name, &ioep); + ret = uclass_get_device_by_phandle(UCLASS_MISC, sysinfo, + name, &ioep); if (ret || !ioep) break; diff --git a/board/gdsys/mpc8308/gazerbeam.c b/board/gdsys/mpc8308/gazerbeam.c index c317260251e..0e7fa1e333e 100644 --- a/board/gdsys/mpc8308/gazerbeam.c +++ b/board/gdsys/mpc8308/gazerbeam.c @@ -6,7 +6,6 @@ */ #include -#include #include #include #include @@ -15,11 +14,12 @@ #include #include #include +#include #include #include #include "../common/ihs_mdio.h" -#include "../../../drivers/board/gazerbeam.h" +#include "../../../drivers/sysinfo/gazerbeam.h" DECLARE_GLOBAL_DATA_PTR; @@ -43,22 +43,22 @@ static int get_tpm(struct udevice **devp) int board_early_init_r(void) { - struct udevice *board; + struct udevice *sysinfo; struct udevice *serdes; int mc = 0; int con = 0; - if (board_get(&board)) - puts("Could not find board information device.\n"); + if (sysinfo_get(&sysinfo)) + puts("Could not find sysinfo information device.\n"); /* Initialize serdes */ - uclass_get_device_by_phandle(UCLASS_MISC, board, "serdes", &serdes); + uclass_get_device_by_phandle(UCLASS_MISC, sysinfo, "serdes", &serdes); - if (board_detect(board)) + if (sysinfo_detect(sysinfo)) puts("Device information detection failed.\n"); - board_get_int(board, BOARD_MULTICHANNEL, &mc); - board_get_int(board, BOARD_VARIANT, &con); + sysinfo_get_int(sysinfo, BOARD_MULTICHANNEL, &mc); + sysinfo_get_int(sysinfo, BOARD_VARIANT, &con); if (mc == 2 || mc == 1) dev_disable_by_path("/immr@e0000000/i2c@3100/pca9698@22"); @@ -84,18 +84,18 @@ int board_early_init_r(void) return 0; } -int checkboard(void) +int checksysinfo(void) { - struct udevice *board; + struct udevice *sysinfo; char *s = env_get("serial#"); int mc = 0; int con = 0; - if (board_get(&board)) - puts("Could not find board information device.\n"); + if (sysinfo_get(&sysinfo)) + puts("Could not find sysinfo information device.\n"); - board_get_int(board, BOARD_MULTICHANNEL, &mc); - board_get_int(board, BOARD_VARIANT, &con); + sysinfo_get_int(sysinfo, BOARD_MULTICHANNEL, &mc); + sysinfo_get_int(sysinfo, BOARD_VARIANT, &con); puts("Board: Gazerbeam "); printf("%s ", mc == 4 ? "MC4" : mc == 2 ? "MC2" : "SC"); @@ -123,20 +123,22 @@ int last_stage_init(void) { int fpga_hw_rev = 0; int i; - struct udevice *board; + struct udevice *sysinfo; struct udevice *osd; struct video_osd_info osd_info; struct udevice *tpm; int ret; - if (board_get(&board)) - puts("Could not find board information device.\n"); + if (sysinfo_get(&sysinfo)) + puts("Could not find sysinfo information device.\n"); - if (board) { - int res = board_get_int(board, BOARD_HWVERSION, &fpga_hw_rev); + if (sysinfo) { + int res = sysinfo_get_int(sysinfo, BOARD_HWVERSION, + &fpga_hw_rev); if (res) - printf("Could not determind FPGA HW revision (res = %d)\n", res); + printf("Could not determind FPGA HW revision (res = %d)\n", + res); } env_set_ulong("fpga_hw_rev", fpga_hw_rev); @@ -154,7 +156,8 @@ int last_stage_init(void) snprintf(name, sizeof(name), "rxaui%d", i); /* Disable RXAUI polarity inversion */ - ret = uclass_get_device_by_phandle(UCLASS_MISC, board, name, &rxaui); + ret = uclass_get_device_by_phandle(UCLASS_MISC, sysinfo, + name, &rxaui); if (!ret) misc_set_enabled(rxaui, false); } diff --git a/board/google/chromebook_coral/coral.c b/board/google/chromebook_coral/coral.c index f5ae48290f4..b8b923c139e 100644 --- a/board/google/chromebook_coral/coral.c +++ b/board/google/chromebook_coral/coral.c @@ -150,7 +150,7 @@ static const struct udevice_id coral_ids[] = { U_BOOT_DRIVER(coral_drv) = { .name = "coral", - .id = UCLASS_BOARD, + .id = UCLASS_SYSINFO, .of_match = coral_ids, ACPI_OPS_PTR(&coral_acpi_ops) }; diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index f5109e86d14..6418062b93a 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -6,13 +6,13 @@ #include #include -#include #include #include #include #include #include #include +#include #include #include @@ -74,7 +74,7 @@ static int spl_fit_get_image_name(const void *fit, int images, const char *type, int index, const char **outname) { - struct udevice *board; + struct udevice *sysinfo; const char *name, *str; __maybe_unused int node; int conf_node; @@ -110,19 +110,20 @@ static int spl_fit_get_image_name(const void *fit, int images, } } - if (!found && !board_get(&board)) { + if (!found && CONFIG_IS_ENABLED(SYSINFO) && !sysinfo_get(&sysinfo)) { int rc; /* - * no string in the property for this index. Check if the board - * level code can supply one. + * no string in the property for this index. Check if the + * sysinfo-level code can supply one. */ - rc = board_get_fit_loadable(board, index - i - 1, type, &str); + rc = sysinfo_get_fit_loadable(sysinfo, index - i - 1, type, + &str); if (rc && rc != -ENOENT) return rc; if (!rc) { /* - * The board provided a name for a loadable. + * The sysinfo provided a name for a loadable. * Try to match it against the description properties * first. If no matching node is found, use it as a * node name. diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig index e5ad79dcf76..d960793d9a9 100644 --- a/configs/chromebook_coral_defconfig +++ b/configs/chromebook_coral_defconfig @@ -79,7 +79,6 @@ CONFIG_SYSCON=y CONFIG_SPL_OF_TRANSLATE=y CONFIG_INTEL_ACPIGEN=y CONFIG_CPU=y -CONFIG_BOARD=y CONFIG_DM_I2C=y CONFIG_SYS_I2C_DW=y CONFIG_MISC=y @@ -100,6 +99,7 @@ CONFIG_SOUND_MAX98357A=y CONFIG_SOUND_RT5677=y CONFIG_SPI=y CONFIG_ICH_SPI=y +CONFIG_SYSINFO=y CONFIG_TPL_SYSRESET=y # CONFIG_TPM_V1 is not set CONFIG_TPM2_CR50_I2C=y diff --git a/configs/gazerbeam_defconfig b/configs/gazerbeam_defconfig index 36c2500bae1..5765ef456be 100644 --- a/configs/gazerbeam_defconfig +++ b/configs/gazerbeam_defconfig @@ -157,8 +157,6 @@ CONFIG_CLK=y CONFIG_ICS8N3QV01=y CONFIG_CPU=y CONFIG_CPU_MPC83XX=y -CONFIG_BOARD=y -CONFIG_BOARD_GAZERBEAM=y CONFIG_DM_PCA953X=y CONFIG_MPC8XXX_GPIO=y CONFIG_DM_I2C=y @@ -197,6 +195,8 @@ CONFIG_MPC83XX_SDRAM=y CONFIG_DM_RESET=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y +CONFIG_SYSINFO=y +CONFIG_SYSINFO_GAZERBEAM=y CONFIG_SYSRESET=y CONFIG_SYSRESET_MPC83XX=y CONFIG_TIMER=y diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index 23a47d158c8..dc993cd13aa 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -109,8 +109,6 @@ CONFIG_CPU=y CONFIG_DM_DEMO=y CONFIG_DM_DEMO_SIMPLE=y CONFIG_DM_DEMO_SHAPE=y -CONFIG_BOARD=y -CONFIG_BOARD_SANDBOX=y CONFIG_GPIO_HOG=y CONFIG_DM_GPIO_LOOKUP_LABEL=y CONFIG_PM8916_GPIO=y @@ -201,6 +199,8 @@ CONFIG_SOC_DEVICE=y CONFIG_SANDBOX_SPI=y CONFIG_SPMI=y CONFIG_SPMI_SANDBOX=y +CONFIG_SYSINFO=y +CONFIG_SYSINFO_SANDBOX=y CONFIG_SYSRESET=y CONFIG_TIMER=y CONFIG_TIMER_EARLY=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 8e2ef24e441..f2a767a4cde 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -131,8 +131,6 @@ CONFIG_CPU=y CONFIG_DM_DEMO=y CONFIG_DM_DEMO_SIMPLE=y CONFIG_DM_DEMO_SHAPE=y -CONFIG_BOARD=y -CONFIG_BOARD_SANDBOX=y CONFIG_DMA=y CONFIG_DMA_CHANNELS=y CONFIG_SANDBOX_DMA=y @@ -238,6 +236,8 @@ CONFIG_SOC_DEVICE=y CONFIG_SANDBOX_SPI=y CONFIG_SPMI=y CONFIG_SPMI_SANDBOX=y +CONFIG_SYSINFO=y +CONFIG_SYSINFO_SANDBOX=y CONFIG_SYSRESET=y CONFIG_TIMER=y CONFIG_TIMER_EARLY=y diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig index 6ee23c4a619..1f593eba8fd 100644 --- a/configs/sandbox_flattree_defconfig +++ b/configs/sandbox_flattree_defconfig @@ -90,8 +90,6 @@ CONFIG_CPU=y CONFIG_DM_DEMO=y CONFIG_DM_DEMO_SIMPLE=y CONFIG_DM_DEMO_SHAPE=y -CONFIG_BOARD=y -CONFIG_BOARD_SANDBOX=y CONFIG_GPIO_HOG=y CONFIG_DM_GPIO_LOOKUP_LABEL=y CONFIG_PM8916_GPIO=y @@ -177,6 +175,8 @@ CONFIG_SOC_DEVICE=y CONFIG_SANDBOX_SPI=y CONFIG_SPMI=y CONFIG_SPMI_SANDBOX=y +CONFIG_SYSINFO=y +CONFIG_SYSINFO_SANDBOX=y CONFIG_SYSRESET=y CONFIG_TIMER=y CONFIG_TIMER_EARLY=y diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig index d47a6252de1..1ac843e1bcd 100644 --- a/configs/sandbox_spl_defconfig +++ b/configs/sandbox_spl_defconfig @@ -111,8 +111,6 @@ CONFIG_CPU=y CONFIG_DM_DEMO=y CONFIG_DM_DEMO_SIMPLE=y CONFIG_DM_DEMO_SHAPE=y -CONFIG_BOARD=y -CONFIG_BOARD_SANDBOX=y CONFIG_SPL_FIRMWARE=y CONFIG_GPIO_HOG=y CONFIG_PM8916_GPIO=y @@ -196,6 +194,8 @@ CONFIG_SOC_DEVICE=y CONFIG_SANDBOX_SPI=y CONFIG_SPMI=y CONFIG_SPMI_SANDBOX=y +CONFIG_SYSINFO=y +CONFIG_SYSINFO_SANDBOX=y CONFIG_SYSRESET=y CONFIG_SPL_SYSRESET=y CONFIG_TIMER=y diff --git a/doc/device-tree-bindings/board/gdsys,board_gazerbeam.txt b/doc/device-tree-bindings/board/gdsys,board_gazerbeam.txt deleted file mode 100644 index 28c1080d904..00000000000 --- a/doc/device-tree-bindings/board/gdsys,board_gazerbeam.txt +++ /dev/null @@ -1,46 +0,0 @@ -gdsys Gazerbeam board driver - -This driver provides capabilities to access the gdsys Gazerbeam board's device -information. Furthermore, phandles to some internal devices are provided for -the board files. - -Required properties: -- compatible: should be "gdsys,board_gazerbeam" -- csb: phandle to the board's coherent system bus (CSB) device node -- rxaui[0-3]: phandles to the rxaui control device nodes -- fpga[0-1]: phandles to the board's gdsys FPGA device nodes -- ioep[0-1]: phandles to the board's IO endpoint device nodes -- ver-gpios: GPIO list to read the hardware version from -- var-gpios: GPIO list to read the hardware variant information from -- reset-gpios: GPIO list for the board's reset GPIOs - -Example: - - -board { - compatible = "gdsys,board_gazerbeam"; - csb = <&board_soc>; - serdes = <&SERDES>; - rxaui0 = <&RXAUI0>; - rxaui1 = <&RXAUI1>; - rxaui2 = <&RXAUI2>; - rxaui3 = <&RXAUI3>; - fpga0 = <&FPGA0>; - fpga1 = <&FPGA1>; - ioep0 = <&IOEP0>; - ioep1 = <&IOEP1>; - - ver-gpios = <&PPCPCA 12 0 - &PPCPCA 13 0 - &PPCPCA 14 0 - &PPCPCA 15 0>; - - /* MC2/SC-Board */ - var-gpios-mc2 = <&GPIO_VB0 0 0 /* VAR-MC_SC */ - &GPIO_VB0 11 0>; /* VAR-CON */ - /* MC4-Board */ - var-gpios-mc4 = <&GPIO_VB1 0 0 /* VAR-MC_SC */ - &GPIO_VB1 11 0>; /* VAR-CON */ - - reset-gpios = <&gpio0 1 0 &gpio0 2 1>; -}; diff --git a/doc/device-tree-bindings/sysinfo/gdsys,sysinfo_gazerbeam.txt b/doc/device-tree-bindings/sysinfo/gdsys,sysinfo_gazerbeam.txt new file mode 100644 index 00000000000..f70652d3c48 --- /dev/null +++ b/doc/device-tree-bindings/sysinfo/gdsys,sysinfo_gazerbeam.txt @@ -0,0 +1,46 @@ +gdsys Gazerbeam sysinfo driver + +This driver provides capabilities to access the gdsys Gazerbeam board's device +information. Furthermore, phandles to some internal devices are provided for +the board files. + +Required properties: +- compatible: should be "gdsys,sysinfo-gazerbeam" +- csb: phandle to the board's coherent system bus (CSB) device node +- rxaui[0-3]: phandles to the rxaui control device nodes +- fpga[0-1]: phandles to the board's gdsys FPGA device nodes +- ioep[0-1]: phandles to the board's IO endpoint device nodes +- ver-gpios: GPIO list to read the hardware version from +- var-gpios: GPIO list to read the hardware variant information from +- reset-gpios: GPIO list for the board's reset GPIOs + +Example: + + +sysinfo { + compatible = "gdsys,sysinfo-gazerbeam"; + csb = <&board_soc>; + serdes = <&SERDES>; + rxaui0 = <&RXAUI0>; + rxaui1 = <&RXAUI1>; + rxaui2 = <&RXAUI2>; + rxaui3 = <&RXAUI3>; + fpga0 = <&FPGA0>; + fpga1 = <&FPGA1>; + ioep0 = <&IOEP0>; + ioep1 = <&IOEP1>; + + ver-gpios = <&PPCPCA 12 0 + &PPCPCA 13 0 + &PPCPCA 14 0 + &PPCPCA 15 0>; + + /* MC2/SC-Board */ + var-gpios-mc2 = <&GPIO_VB0 0 0 /* VAR-MC_SC */ + &GPIO_VB0 11 0>; /* VAR-CON */ + /* MC4-Board */ + var-gpios-mc4 = <&GPIO_VB1 0 0 /* VAR-MC_SC */ + &GPIO_VB1 11 0>; /* VAR-CON */ + + reset-gpios = <&gpio0 1 0 &gpio0 2 1>; +}; diff --git a/drivers/Kconfig b/drivers/Kconfig index ed8a39c994d..b1ada1cb7f8 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -30,8 +30,6 @@ source "drivers/ddr/Kconfig" source "drivers/demo/Kconfig" -source "drivers/board/Kconfig" - source "drivers/ddr/fsl/Kconfig" source "drivers/dfu/Kconfig" @@ -114,6 +112,8 @@ source "drivers/spi/Kconfig" source "drivers/spmi/Kconfig" +source "drivers/sysinfo/Kconfig" + source "drivers/sysreset/Kconfig" source "drivers/tee/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index 33f1d536cdd..e371bc32bb8 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -27,9 +27,9 @@ obj-$(CONFIG_$(SPL_TPL_)TIMER) += timer/ obj-$(CONFIG_$(SPL_TPL_)VIRTIO) += virtio/ obj-$(CONFIG_$(SPL_)DM_MAILBOX) += mailbox/ obj-$(CONFIG_$(SPL_)REMOTEPROC) += remoteproc/ +obj-$(CONFIG_$(SPL_)SYSINFO) += sysinfo/ obj-$(CONFIG_$(SPL_TPL_)TPM) += tpm/ obj-$(CONFIG_$(SPL_TPL_)ACPI_PMC) += power/acpi_pmc/ -obj-$(CONFIG_$(SPL_)BOARD) += board/ obj-$(CONFIG_XEN) += xen/ obj-$(CONFIG_$(SPL_)FPGA) += fpga/ diff --git a/drivers/board/Kconfig b/drivers/board/Kconfig deleted file mode 100644 index 254f657049d..00000000000 --- a/drivers/board/Kconfig +++ /dev/null @@ -1,25 +0,0 @@ -menuconfig BOARD - bool "Device Information" - help - Support methods to query hardware configurations from internal - mechanisms (e.g. reading GPIO values, determining the presence of - devices on busses, etc.). This enables the usage of U-Boot with - modular board architectures. - -if BOARD - -config SPL_BOARD - depends on SPL_DM - bool "Enable board driver support in SPL" - -config BOARD_GAZERBEAM - bool "Enable board driver for the Gazerbeam board" - help - Support querying device information for the gdsys Gazerbeam board. - -config BOARD_SANDBOX - bool "Enable board driver for the Sandbox board" - help - Support querying device information for the Sandbox boards. - -endif diff --git a/drivers/board/Makefile b/drivers/board/Makefile deleted file mode 100644 index cc16361755a..00000000000 --- a/drivers/board/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ -# -# (C) Copyright 2017 -# Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc -obj-y += board-uclass.o -obj-$(CONFIG_BOARD_GAZERBEAM) += gazerbeam.o -obj-$(CONFIG_BOARD_SANDBOX) += sandbox.o diff --git a/drivers/board/board-uclass.c b/drivers/board/board-uclass.c deleted file mode 100644 index b5485e9895b..00000000000 --- a/drivers/board/board-uclass.c +++ /dev/null @@ -1,71 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * (C) Copyright 2017 - * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc - */ - -#include -#include -#include - -int board_get(struct udevice **devp) -{ - return uclass_first_device_err(UCLASS_BOARD, devp); -} - -int board_detect(struct udevice *dev) -{ - struct board_ops *ops = board_get_ops(dev); - - if (!ops->detect) - return -ENOSYS; - - return ops->detect(dev); -} - -int board_get_fit_loadable(struct udevice *dev, int index, - const char *type, const char **strp) -{ - struct board_ops *ops = board_get_ops(dev); - - if (!ops->get_fit_loadable) - return -ENOSYS; - - return ops->get_fit_loadable(dev, index, type, strp); -} - -int board_get_bool(struct udevice *dev, int id, bool *val) -{ - struct board_ops *ops = board_get_ops(dev); - - if (!ops->get_bool) - return -ENOSYS; - - return ops->get_bool(dev, id, val); -} - -int board_get_int(struct udevice *dev, int id, int *val) -{ - struct board_ops *ops = board_get_ops(dev); - - if (!ops->get_int) - return -ENOSYS; - - return ops->get_int(dev, id, val); -} - -int board_get_str(struct udevice *dev, int id, size_t size, char *val) -{ - struct board_ops *ops = board_get_ops(dev); - - if (!ops->get_str) - return -ENOSYS; - - return ops->get_str(dev, id, size, val); -} - -UCLASS_DRIVER(board) = { - .id = UCLASS_BOARD, - .name = "board", - .post_bind = dm_scan_fdt_dev, -}; diff --git a/drivers/board/gazerbeam.c b/drivers/board/gazerbeam.c deleted file mode 100644 index ed50fc530cb..00000000000 --- a/drivers/board/gazerbeam.c +++ /dev/null @@ -1,265 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * (C) Copyright 2017 - * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc - */ - -#include -#include -#include -#include -#include -#include - -#include "gazerbeam.h" - -/* Sequence number of I2C bus that holds the GPIO expanders */ -static const int I2C_BUS_SEQ_NO = 1; - -/* I2C address of SC/MC2 expander */ -static const int MC2_EXPANDER_ADDR = 0x20; -/* I2C address of MC4 expander */ -static const int MC4_EXPANDER_ADDR = 0x22; - -/* Number of the GPIO to read the SC data from */ -static const int SC_GPIO_NO; -/* Number of the GPIO to read the CON data from */ -static const int CON_GPIO_NO = 1; - -/** - * struct board_gazerbeam_priv - Private data structure for the gazerbeam board - * driver. - * @reset_gpios: GPIOs for the board's reset GPIOs. - * @var_gpios: GPIOs for the board's hardware variant GPIOs - * @ver_gpios: GPIOs for the board's hardware version GPIOs - * @variant: Container for the board's hardware variant (CON/CPU) - * @multichannel: Container for the board's multichannel variant (MC4/MC2/SC) - * @hwversion: Container for the board's hardware version - */ -struct board_gazerbeam_priv { - struct gpio_desc reset_gpios[2]; - struct gpio_desc var_gpios[2]; - struct gpio_desc ver_gpios[4]; - int variant; - int multichannel; - int hwversion; -}; - -/** - * _read_board_variant_data() - Read variant information from the hardware. - * @dev: The board device for which to determine the multichannel and device - * type information. - * - * The data read from the board's hardware (mostly hard-wired GPIOs) is stored - * in the private data structure of the driver to be used by other driver - * methods. - * - * Return: 0 if OK, -ve on error. - */ -static int _read_board_variant_data(struct udevice *dev) -{ - struct board_gazerbeam_priv *priv = dev_get_priv(dev); - struct udevice *i2c_bus; - struct udevice *dummy; - char *listname; - int mc4, mc2, sc, mc2_sc, con; - int gpio_num; - int res; - - res = uclass_get_device_by_seq(UCLASS_I2C, I2C_BUS_SEQ_NO, &i2c_bus); - if (res) { - debug("%s: Could not get I2C bus %d (err = %d)\n", - dev->name, I2C_BUS_SEQ_NO, res); - return res; - } - - if (!i2c_bus) { - debug("%s: Could not get I2C bus %d\n", - dev->name, I2C_BUS_SEQ_NO); - return -EIO; - } - - mc2_sc = !dm_i2c_probe(i2c_bus, MC2_EXPANDER_ADDR, 0, &dummy); - mc4 = !dm_i2c_probe(i2c_bus, MC4_EXPANDER_ADDR, 0, &dummy); - - if (mc2_sc && mc4) { - debug("%s: Board hardware configuration inconsistent.\n", - dev->name); - return -EINVAL; - } - - listname = mc2_sc ? "var-gpios-mc2" : "var-gpios-mc4"; - - gpio_num = gpio_request_list_by_name(dev, listname, priv->var_gpios, - ARRAY_SIZE(priv->var_gpios), - GPIOD_IS_IN); - if (gpio_num < 0) { - debug("%s: Requesting gpio list %s failed (err = %d).\n", - dev->name, listname, gpio_num); - return gpio_num; - } - - sc = dm_gpio_get_value(&priv->var_gpios[SC_GPIO_NO]); - if (sc < 0) { - debug("%s: Error while reading 'sc' GPIO (err = %d)", - dev->name, sc); - return sc; - } - - mc2 = mc2_sc ? (sc ? 0 : 1) : 0; - - if ((sc && mc2) || (sc && mc4) || (!sc && !mc2 && !mc4)) { - debug("%s: Board hardware configuration inconsistent.\n", - dev->name); - return -EINVAL; - } - - con = dm_gpio_get_value(&priv->var_gpios[CON_GPIO_NO]); - if (con < 0) { - debug("%s: Error while reading 'con' GPIO (err = %d)", - dev->name, con); - return con; - } - - priv->variant = con ? VAR_CON : VAR_CPU; - - priv->multichannel = mc4 ? 4 : (mc2 ? 2 : (sc ? 1 : 0)); - - return 0; -} - -/** - * _read_hwversion() - Read the hardware version from the board. - * @dev: The board device for which to read the hardware version. - * - * The hardware version read from the board (from hard-wired GPIOs) is stored - * in the private data structure of the driver to be used by other driver - * methods. - * - * Return: 0 if OK, -ve on error. - */ -static int _read_hwversion(struct udevice *dev) -{ - struct board_gazerbeam_priv *priv = dev_get_priv(dev); - int res; - - res = gpio_request_list_by_name(dev, "ver-gpios", priv->ver_gpios, - ARRAY_SIZE(priv->ver_gpios), - GPIOD_IS_IN); - if (res < 0) { - debug("%s: Error getting GPIO list 'ver-gpios' (err = %d)\n", - dev->name, res); - return -ENODEV; - } - - res = dm_gpio_get_values_as_int(priv->ver_gpios, - ARRAY_SIZE(priv->ver_gpios)); - if (res < 0) { - debug("%s: Error reading HW version from expander (err = %d)\n", - dev->name, res); - return res; - } - - priv->hwversion = res; - - res = gpio_free_list(dev, priv->ver_gpios, ARRAY_SIZE(priv->ver_gpios)); - if (res < 0) { - debug("%s: Error freeing HW version GPIO list (err = %d)\n", - dev->name, res); - return res; - } - - return 0; -} - -static int board_gazerbeam_detect(struct udevice *dev) -{ - int res; - - res = _read_board_variant_data(dev); - if (res) { - debug("%s: Error reading multichannel variant (err = %d)\n", - dev->name, res); - return res; - } - - res = _read_hwversion(dev); - if (res) { - debug("%s: Error reading hardware version (err = %d)\n", - dev->name, res); - return res; - } - - return 0; -} - -static int board_gazerbeam_get_int(struct udevice *dev, int id, int *val) -{ - struct board_gazerbeam_priv *priv = dev_get_priv(dev); - - switch (id) { - case BOARD_MULTICHANNEL: - *val = priv->multichannel; - break; - case BOARD_VARIANT: - *val = priv->variant; - break; - case BOARD_HWVERSION: - *val = priv->hwversion; - break; - default: - debug("%s: Integer value %d unknown\n", dev->name, id); - return -EINVAL; - } - - return 0; -} - -static const struct udevice_id board_gazerbeam_ids[] = { - { .compatible = "gdsys,board_gazerbeam" }, - { /* sentinel */ } -}; - -static const struct board_ops board_gazerbeam_ops = { - .detect = board_gazerbeam_detect, - .get_int = board_gazerbeam_get_int, -}; - -static int board_gazerbeam_probe(struct udevice *dev) -{ - struct board_gazerbeam_priv *priv = dev_get_priv(dev); - int gpio_num, i; - - gpio_num = gpio_request_list_by_name(dev, "reset-gpios", - priv->reset_gpios, - ARRAY_SIZE(priv->reset_gpios), - GPIOD_IS_OUT); - - if (gpio_num < 0) { - debug("%s: Error getting GPIO list 'reset-gpios' (err = %d)\n", - dev->name, gpio_num); - return gpio_num; - } - - /* Set startup-finished GPIOs */ - for (i = 0; i < ARRAY_SIZE(priv->reset_gpios); i++) { - int res = dm_gpio_set_value(&priv->reset_gpios[i], 0); - - if (res) { - debug("%s: Error while setting GPIO %d (err = %d)\n", - dev->name, i, res); - return res; - } - } - - return 0; -} - -U_BOOT_DRIVER(board_gazerbeam) = { - .name = "board_gazerbeam", - .id = UCLASS_BOARD, - .of_match = board_gazerbeam_ids, - .ops = &board_gazerbeam_ops, - .priv_auto_alloc_size = sizeof(struct board_gazerbeam_priv), - .probe = board_gazerbeam_probe, -}; diff --git a/drivers/board/gazerbeam.h b/drivers/board/gazerbeam.h deleted file mode 100644 index 171729d2031..00000000000 --- a/drivers/board/gazerbeam.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * (C) Copyright 2017 - * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc - * - */ - -enum { - BOARD_MULTICHANNEL, - BOARD_VARIANT, - BOARD_HWVERSION, -}; - -enum { - VAR_CON, - VAR_CPU, -}; diff --git a/drivers/board/sandbox.c b/drivers/board/sandbox.c deleted file mode 100644 index 50621e47a4f..00000000000 --- a/drivers/board/sandbox.c +++ /dev/null @@ -1,107 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * (C) Copyright 2018 - * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc - */ - -#include -#include -#include - -#include "sandbox.h" - -struct board_sandbox_priv { - bool called_detect; - int test_i1; - int test_i2; -}; - -char vacation_spots[][64] = {"R'lyeh", "Dreamlands", "Plateau of Leng", - "Carcosa", "Yuggoth", "The Nameless City"}; - -int board_sandbox_detect(struct udevice *dev) -{ - struct board_sandbox_priv *priv = dev_get_priv(dev); - - priv->called_detect = true; - priv->test_i2 = 100; - - return 0; -} - -int board_sandbox_get_bool(struct udevice *dev, int id, bool *val) -{ - struct board_sandbox_priv *priv = dev_get_priv(dev); - - switch (id) { - case BOOL_CALLED_DETECT: - /* Checks if the dectect method has been called */ - *val = priv->called_detect; - return 0; - } - - return -ENOENT; -} - -int board_sandbox_get_int(struct udevice *dev, int id, int *val) -{ - struct board_sandbox_priv *priv = dev_get_priv(dev); - - switch (id) { - case INT_TEST1: - *val = priv->test_i1; - /* Increments with every call */ - priv->test_i1++; - return 0; - case INT_TEST2: - *val = priv->test_i2; - /* Decrements with every call */ - priv->test_i2--; - return 0; - } - - return -ENOENT; -} - -int board_sandbox_get_str(struct udevice *dev, int id, size_t size, char *val) -{ - struct board_sandbox_priv *priv = dev_get_priv(dev); - int i1 = priv->test_i1; - int i2 = priv->test_i2; - int index = (i1 * i2) % ARRAY_SIZE(vacation_spots); - - switch (id) { - case STR_VACATIONSPOT: - /* Picks a vacation spot depending on i1 and i2 */ - snprintf(val, size, vacation_spots[index]); - return 0; - } - - return -ENOENT; -} - -static const struct udevice_id board_sandbox_ids[] = { - { .compatible = "sandbox,board_sandbox" }, - { /* sentinel */ } -}; - -static const struct board_ops board_sandbox_ops = { - .detect = board_sandbox_detect, - .get_bool = board_sandbox_get_bool, - .get_int = board_sandbox_get_int, - .get_str = board_sandbox_get_str, -}; - -int board_sandbox_probe(struct udevice *dev) -{ - return 0; -} - -U_BOOT_DRIVER(board_sandbox) = { - .name = "board_sandbox", - .id = UCLASS_BOARD, - .of_match = board_sandbox_ids, - .ops = &board_sandbox_ops, - .priv_auto_alloc_size = sizeof(struct board_sandbox_priv), - .probe = board_sandbox_probe, -}; diff --git a/drivers/board/sandbox.h b/drivers/board/sandbox.h deleted file mode 100644 index 2cff494f56e..00000000000 --- a/drivers/board/sandbox.h +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * (C) Copyright 2018 - * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc - */ - -enum { - BOOL_CALLED_DETECT, - INT_TEST1, - INT_TEST2, - STR_VACATIONSPOT, -}; diff --git a/drivers/sysinfo/Kconfig b/drivers/sysinfo/Kconfig new file mode 100644 index 00000000000..39141500a05 --- /dev/null +++ b/drivers/sysinfo/Kconfig @@ -0,0 +1,25 @@ +menuconfig SYSINFO + bool "Device System Information" + help + Support methods to query hardware configurations from internal + mechanisms (e.g. reading GPIO values, determining the presence of + devices on busses, etc.). This enables the usage of U-Boot with + modular board architectures. + +if SYSINFO + +config SPL_SYSINFO + depends on SPL_DM + bool "Enable board driver support in SPL" + +config SYSINFO_GAZERBEAM + bool "Enable sysinfo driver for the Gazerbeam board" + help + Support querying device information for the gdsys Gazerbeam board. + +config SYSINFO_SANDBOX + bool "Enable sysinfo driver for the Sandbox board" + help + Support querying device information for the Sandbox boards. + +endif diff --git a/drivers/sysinfo/Makefile b/drivers/sysinfo/Makefile new file mode 100644 index 00000000000..aecf0b0d47c --- /dev/null +++ b/drivers/sysinfo/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# (C) Copyright 2017 +# Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc +obj-y += sysinfo-uclass.o +obj-$(CONFIG_SYSINFO_GAZERBEAM) += gazerbeam.o +obj-$(CONFIG_SYSINFO_SANDBOX) += sandbox.o diff --git a/drivers/sysinfo/gazerbeam.c b/drivers/sysinfo/gazerbeam.c new file mode 100644 index 00000000000..9e7a4966554 --- /dev/null +++ b/drivers/sysinfo/gazerbeam.c @@ -0,0 +1,265 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2017 + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc + */ + +#include +#include +#include +#include +#include +#include + +#include "gazerbeam.h" + +/* Sequence number of I2C bus that holds the GPIO expanders */ +static const int I2C_BUS_SEQ_NO = 1; + +/* I2C address of SC/MC2 expander */ +static const int MC2_EXPANDER_ADDR = 0x20; +/* I2C address of MC4 expander */ +static const int MC4_EXPANDER_ADDR = 0x22; + +/* Number of the GPIO to read the SC data from */ +static const int SC_GPIO_NO; +/* Number of the GPIO to read the CON data from */ +static const int CON_GPIO_NO = 1; + +/** + * struct sysinfo_gazerbeam_priv - Private data structure for the gazerbeam + * sysinfo driver + * @reset_gpios: GPIOs for the sysinfo's reset GPIOs. + * @var_gpios: GPIOs for the sysinfo's hardware variant GPIOs + * @ver_gpios: GPIOs for the sysinfo's hardware version GPIOs + * @variant: Container for the sysinfo's hardware variant (CON/CPU) + * @multichannel: Container for the sysinfo's multichannel variant (MC4/MC2/SC) + * @hwversion: Container for the sysinfo's hardware version + */ +struct sysinfo_gazerbeam_priv { + struct gpio_desc reset_gpios[2]; + struct gpio_desc var_gpios[2]; + struct gpio_desc ver_gpios[4]; + int variant; + int multichannel; + int hwversion; +}; + +/** + * _read_sysinfo_variant_data() - Read variant information from the hardware. + * @dev: The sysinfo device for which to determine the multichannel and device + * type information. + * + * The data read from the sysinfo's hardware (mostly hard-wired GPIOs) is stored + * in the private data structure of the driver to be used by other driver + * methods. + * + * Return: 0 if OK, -ve on error. + */ +static int _read_sysinfo_variant_data(struct udevice *dev) +{ + struct sysinfo_gazerbeam_priv *priv = dev_get_priv(dev); + struct udevice *i2c_bus; + struct udevice *dummy; + char *listname; + int mc4, mc2, sc, mc2_sc, con; + int gpio_num; + int res; + + res = uclass_get_device_by_seq(UCLASS_I2C, I2C_BUS_SEQ_NO, &i2c_bus); + if (res) { + debug("%s: Could not get I2C bus %d (err = %d)\n", + dev->name, I2C_BUS_SEQ_NO, res); + return res; + } + + if (!i2c_bus) { + debug("%s: Could not get I2C bus %d\n", + dev->name, I2C_BUS_SEQ_NO); + return -EIO; + } + + mc2_sc = !dm_i2c_probe(i2c_bus, MC2_EXPANDER_ADDR, 0, &dummy); + mc4 = !dm_i2c_probe(i2c_bus, MC4_EXPANDER_ADDR, 0, &dummy); + + if (mc2_sc && mc4) { + debug("%s: Board hardware configuration inconsistent.\n", + dev->name); + return -EINVAL; + } + + listname = mc2_sc ? "var-gpios-mc2" : "var-gpios-mc4"; + + gpio_num = gpio_request_list_by_name(dev, listname, priv->var_gpios, + ARRAY_SIZE(priv->var_gpios), + GPIOD_IS_IN); + if (gpio_num < 0) { + debug("%s: Requesting gpio list %s failed (err = %d).\n", + dev->name, listname, gpio_num); + return gpio_num; + } + + sc = dm_gpio_get_value(&priv->var_gpios[SC_GPIO_NO]); + if (sc < 0) { + debug("%s: Error while reading 'sc' GPIO (err = %d)", + dev->name, sc); + return sc; + } + + mc2 = mc2_sc ? (sc ? 0 : 1) : 0; + + if ((sc && mc2) || (sc && mc4) || (!sc && !mc2 && !mc4)) { + debug("%s: Board hardware configuration inconsistent.\n", + dev->name); + return -EINVAL; + } + + con = dm_gpio_get_value(&priv->var_gpios[CON_GPIO_NO]); + if (con < 0) { + debug("%s: Error while reading 'con' GPIO (err = %d)", + dev->name, con); + return con; + } + + priv->variant = con ? VAR_CON : VAR_CPU; + + priv->multichannel = mc4 ? 4 : (mc2 ? 2 : (sc ? 1 : 0)); + + return 0; +} + +/** + * _read_hwversion() - Read the hardware version from the sysinfo. + * @dev: The sysinfo device for which to read the hardware version. + * + * The hardware version read from the sysinfo (from hard-wired GPIOs) is stored + * in the private data structure of the driver to be used by other driver + * methods. + * + * Return: 0 if OK, -ve on error. + */ +static int _read_hwversion(struct udevice *dev) +{ + struct sysinfo_gazerbeam_priv *priv = dev_get_priv(dev); + int res; + + res = gpio_request_list_by_name(dev, "ver-gpios", priv->ver_gpios, + ARRAY_SIZE(priv->ver_gpios), + GPIOD_IS_IN); + if (res < 0) { + debug("%s: Error getting GPIO list 'ver-gpios' (err = %d)\n", + dev->name, res); + return -ENODEV; + } + + res = dm_gpio_get_values_as_int(priv->ver_gpios, + ARRAY_SIZE(priv->ver_gpios)); + if (res < 0) { + debug("%s: Error reading HW version from expander (err = %d)\n", + dev->name, res); + return res; + } + + priv->hwversion = res; + + res = gpio_free_list(dev, priv->ver_gpios, ARRAY_SIZE(priv->ver_gpios)); + if (res < 0) { + debug("%s: Error freeing HW version GPIO list (err = %d)\n", + dev->name, res); + return res; + } + + return 0; +} + +static int sysinfo_gazerbeam_detect(struct udevice *dev) +{ + int res; + + res = _read_sysinfo_variant_data(dev); + if (res) { + debug("%s: Error reading multichannel variant (err = %d)\n", + dev->name, res); + return res; + } + + res = _read_hwversion(dev); + if (res) { + debug("%s: Error reading hardware version (err = %d)\n", + dev->name, res); + return res; + } + + return 0; +} + +static int sysinfo_gazerbeam_get_int(struct udevice *dev, int id, int *val) +{ + struct sysinfo_gazerbeam_priv *priv = dev_get_priv(dev); + + switch (id) { + case BOARD_MULTICHANNEL: + *val = priv->multichannel; + break; + case BOARD_VARIANT: + *val = priv->variant; + break; + case BOARD_HWVERSION: + *val = priv->hwversion; + break; + default: + debug("%s: Integer value %d unknown\n", dev->name, id); + return -EINVAL; + } + + return 0; +} + +static const struct udevice_id sysinfo_gazerbeam_ids[] = { + { .compatible = "gdsys,sysinfo-gazerbeam" }, + { /* sentinel */ } +}; + +static const struct sysinfo_ops sysinfo_gazerbeam_ops = { + .detect = sysinfo_gazerbeam_detect, + .get_int = sysinfo_gazerbeam_get_int, +}; + +static int sysinfo_gazerbeam_probe(struct udevice *dev) +{ + struct sysinfo_gazerbeam_priv *priv = dev_get_priv(dev); + int gpio_num, i; + + gpio_num = gpio_request_list_by_name(dev, "reset-gpios", + priv->reset_gpios, + ARRAY_SIZE(priv->reset_gpios), + GPIOD_IS_OUT); + + if (gpio_num < 0) { + debug("%s: Error getting GPIO list 'reset-gpios' (err = %d)\n", + dev->name, gpio_num); + return gpio_num; + } + + /* Set startup-finished GPIOs */ + for (i = 0; i < ARRAY_SIZE(priv->reset_gpios); i++) { + int res = dm_gpio_set_value(&priv->reset_gpios[i], 0); + + if (res) { + debug("%s: Error while setting GPIO %d (err = %d)\n", + dev->name, i, res); + return res; + } + } + + return 0; +} + +U_BOOT_DRIVER(sysinfo_gazerbeam) = { + .name = "sysinfo_gazerbeam", + .id = UCLASS_SYSINFO, + .of_match = sysinfo_gazerbeam_ids, + .ops = &sysinfo_gazerbeam_ops, + .priv_auto_alloc_size = sizeof(struct sysinfo_gazerbeam_priv), + .probe = sysinfo_gazerbeam_probe, +}; diff --git a/drivers/sysinfo/gazerbeam.h b/drivers/sysinfo/gazerbeam.h new file mode 100644 index 00000000000..171729d2031 --- /dev/null +++ b/drivers/sysinfo/gazerbeam.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2017 + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc + * + */ + +enum { + BOARD_MULTICHANNEL, + BOARD_VARIANT, + BOARD_HWVERSION, +}; + +enum { + VAR_CON, + VAR_CPU, +}; diff --git a/drivers/sysinfo/sandbox.c b/drivers/sysinfo/sandbox.c new file mode 100644 index 00000000000..62a1cb4ac65 --- /dev/null +++ b/drivers/sysinfo/sandbox.c @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2018 + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc + */ + +#include +#include +#include + +#include "sandbox.h" + +struct sysinfo_sandbox_priv { + bool called_detect; + int test_i1; + int test_i2; +}; + +char vacation_spots[][64] = {"R'lyeh", "Dreamlands", "Plateau of Leng", + "Carcosa", "Yuggoth", "The Nameless City"}; + +int sysinfo_sandbox_detect(struct udevice *dev) +{ + struct sysinfo_sandbox_priv *priv = dev_get_priv(dev); + + priv->called_detect = true; + priv->test_i2 = 100; + + return 0; +} + +int sysinfo_sandbox_get_bool(struct udevice *dev, int id, bool *val) +{ + struct sysinfo_sandbox_priv *priv = dev_get_priv(dev); + + switch (id) { + case BOOL_CALLED_DETECT: + /* Checks if the dectect method has been called */ + *val = priv->called_detect; + return 0; + } + + return -ENOENT; +} + +int sysinfo_sandbox_get_int(struct udevice *dev, int id, int *val) +{ + struct sysinfo_sandbox_priv *priv = dev_get_priv(dev); + + switch (id) { + case INT_TEST1: + *val = priv->test_i1; + /* Increments with every call */ + priv->test_i1++; + return 0; + case INT_TEST2: + *val = priv->test_i2; + /* Decrements with every call */ + priv->test_i2--; + return 0; + } + + return -ENOENT; +} + +int sysinfo_sandbox_get_str(struct udevice *dev, int id, size_t size, char *val) +{ + struct sysinfo_sandbox_priv *priv = dev_get_priv(dev); + int i1 = priv->test_i1; + int i2 = priv->test_i2; + int index = (i1 * i2) % ARRAY_SIZE(vacation_spots); + + switch (id) { + case STR_VACATIONSPOT: + /* Picks a vacation spot depending on i1 and i2 */ + snprintf(val, size, vacation_spots[index]); + return 0; + } + + return -ENOENT; +} + +static const struct udevice_id sysinfo_sandbox_ids[] = { + { .compatible = "sandbox,sysinfo-sandbox" }, + { /* sentinel */ } +}; + +static const struct sysinfo_ops sysinfo_sandbox_ops = { + .detect = sysinfo_sandbox_detect, + .get_bool = sysinfo_sandbox_get_bool, + .get_int = sysinfo_sandbox_get_int, + .get_str = sysinfo_sandbox_get_str, +}; + +int sysinfo_sandbox_probe(struct udevice *dev) +{ + return 0; +} + +U_BOOT_DRIVER(sysinfo_sandbox) = { + .name = "sysinfo_sandbox", + .id = UCLASS_SYSINFO, + .of_match = sysinfo_sandbox_ids, + .ops = &sysinfo_sandbox_ops, + .priv_auto_alloc_size = sizeof(struct sysinfo_sandbox_priv), + .probe = sysinfo_sandbox_probe, +}; diff --git a/drivers/sysinfo/sandbox.h b/drivers/sysinfo/sandbox.h new file mode 100644 index 00000000000..2cff494f56e --- /dev/null +++ b/drivers/sysinfo/sandbox.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2018 + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc + */ + +enum { + BOOL_CALLED_DETECT, + INT_TEST1, + INT_TEST2, + STR_VACATIONSPOT, +}; diff --git a/drivers/sysinfo/sysinfo-uclass.c b/drivers/sysinfo/sysinfo-uclass.c new file mode 100644 index 00000000000..6df58fe160b --- /dev/null +++ b/drivers/sysinfo/sysinfo-uclass.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2017 + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc + */ + +#include +#include +#include + +int sysinfo_get(struct udevice **devp) +{ + return uclass_first_device_err(UCLASS_SYSINFO, devp); +} + +int sysinfo_detect(struct udevice *dev) +{ + struct sysinfo_ops *ops = sysinfo_get_ops(dev); + + if (!ops->detect) + return -ENOSYS; + + return ops->detect(dev); +} + +int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type, + const char **strp) +{ + struct sysinfo_ops *ops = sysinfo_get_ops(dev); + + if (!ops->get_fit_loadable) + return -ENOSYS; + + return ops->get_fit_loadable(dev, index, type, strp); +} + +int sysinfo_get_bool(struct udevice *dev, int id, bool *val) +{ + struct sysinfo_ops *ops = sysinfo_get_ops(dev); + + if (!ops->get_bool) + return -ENOSYS; + + return ops->get_bool(dev, id, val); +} + +int sysinfo_get_int(struct udevice *dev, int id, int *val) +{ + struct sysinfo_ops *ops = sysinfo_get_ops(dev); + + if (!ops->get_int) + return -ENOSYS; + + return ops->get_int(dev, id, val); +} + +int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val) +{ + struct sysinfo_ops *ops = sysinfo_get_ops(dev); + + if (!ops->get_str) + return -ENOSYS; + + return ops->get_str(dev, id, size, val); +} + +UCLASS_DRIVER(sysinfo) = { + .id = UCLASS_SYSINFO, + .name = "sysinfo", + .post_bind = dm_scan_fdt_dev, +}; diff --git a/drivers/timer/mpc83xx_timer.c b/drivers/timer/mpc83xx_timer.c index ba7704225a3..6139252a73c 100644 --- a/drivers/timer/mpc83xx_timer.c +++ b/drivers/timer/mpc83xx_timer.c @@ -5,12 +5,12 @@ */ #include -#include #include #include #include #include #include +#include #include #include #include @@ -97,7 +97,7 @@ int interrupt_init(void) { immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; struct udevice *csb; - struct udevice *board; + struct udevice *sysinfo; struct udevice *timer; struct mpc83xx_timer_priv *timer_priv; struct clk clock; @@ -112,12 +112,12 @@ int interrupt_init(void) timer_priv = dev_get_priv(timer); - if (board_get(&board)) { - debug("%s: board device could not be fetched.\n", __func__); + if (sysinfo_get(&sysinfo)) { + debug("%s: sysinfo device could not be fetched.\n", __func__); return -ENOENT; } - ret = uclass_get_device_by_phandle(UCLASS_SIMPLE_BUS, board, + ret = uclass_get_device_by_phandle(UCLASS_SIMPLE_BUS, sysinfo, "csb", &csb); if (ret) { debug("%s: Could not retrieve CSB device (error: %d)", diff --git a/include/board.h b/include/board.h deleted file mode 100644 index 678b652b0aa..00000000000 --- a/include/board.h +++ /dev/null @@ -1,213 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * (C) Copyright 2017 - * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc - */ - -/* - * This uclass encapsulates hardware methods to gather information about a - * board or a specific device such as hard-wired GPIOs on GPIO expanders, - * read-only data in flash ICs, or similar. - * - * The interface offers functions to read the usual standard data types (bool, - * int, string) from the device, each of which is identified by a static - * numeric ID (which will usually be defined as a enum in a header file). - * - * If for example the board had a read-only serial number flash IC, we could - * call - * - * ret = board_detect(dev); - * if (ret) { - * debug("board device not found."); - * return ret; - * } - * - * ret = board_get_int(dev, ID_SERIAL_NUMBER, &serial); - * if (ret) { - * debug("Error when reading serial number from device."); - * return ret; - * } - * - * to read the serial number. - */ - -#if CONFIG_IS_ENABLED(BOARD) -struct board_ops { - /** - * detect() - Run the hardware info detection procedure for this - * device. - * @dev: The device containing the information - * - * This operation might take a long time (e.g. read from EEPROM, - * check the presence of a device on a bus etc.), hence this is not - * done in the probe() method, but later during operation in this - * dedicated method. - * - * Return: 0 if OK, -ve on error. - */ - int (*detect)(struct udevice *dev); - - /** - * get_bool() - Read a specific bool data value that describes the - * hardware setup. - * @dev: The board instance to gather the data. - * @id: A unique identifier for the bool value to be read. - * @val: Pointer to a buffer that receives the value read. - * - * Return: 0 if OK, -ve on error. - */ - int (*get_bool)(struct udevice *dev, int id, bool *val); - - /** - * get_int() - Read a specific int data value that describes the - * hardware setup. - * @dev: The board instance to gather the data. - * @id: A unique identifier for the int value to be read. - * @val: Pointer to a buffer that receives the value read. - * - * Return: 0 if OK, -ve on error. - */ - int (*get_int)(struct udevice *dev, int id, int *val); - - /** - * get_str() - Read a specific string data value that describes the - * hardware setup. - * @dev: The board instance to gather the data. - * @id: A unique identifier for the string value to be read. - * @size: The size of the buffer to receive the string data. - * @val: Pointer to a buffer that receives the value read. - * - * Return: 0 if OK, -ve on error. - */ - int (*get_str)(struct udevice *dev, int id, size_t size, char *val); - - /** - * get_fit_loadable - Get the name of an image to load from FIT - * This function can be used to provide the image names based on runtime - * detection. A classic use-case would when DTBOs are used to describe - * additionnal daughter cards. - * - * @dev: The board instance to gather the data. - * @index: Index of the image. Starts at 0 and gets incremented - * after each call to this function. - * @type: The type of image. For example, "fdt" for DTBs - * @strp: A pointer to string. Untouched if the function fails - * - * Return: 0 if OK, -ENOENT if no loadable is available else -ve on - * error. - */ - int (*get_fit_loadable)(struct udevice *dev, int index, - const char *type, const char **strp); -}; - -#define board_get_ops(dev) ((struct board_ops *)(dev)->driver->ops) - -/** - * board_detect() - Run the hardware info detection procedure for this device. - * - * @dev: The device containing the information - * - * Return: 0 if OK, -ve on error. - */ -int board_detect(struct udevice *dev); - -/** - * board_get_bool() - Read a specific bool data value that describes the - * hardware setup. - * @dev: The board instance to gather the data. - * @id: A unique identifier for the bool value to be read. - * @val: Pointer to a buffer that receives the value read. - * - * Return: 0 if OK, -ve on error. - */ -int board_get_bool(struct udevice *dev, int id, bool *val); - -/** - * board_get_int() - Read a specific int data value that describes the - * hardware setup. - * @dev: The board instance to gather the data. - * @id: A unique identifier for the int value to be read. - * @val: Pointer to a buffer that receives the value read. - * - * Return: 0 if OK, -ve on error. - */ -int board_get_int(struct udevice *dev, int id, int *val); - -/** - * board_get_str() - Read a specific string data value that describes the - * hardware setup. - * @dev: The board instance to gather the data. - * @id: A unique identifier for the string value to be read. - * @size: The size of the buffer to receive the string data. - * @val: Pointer to a buffer that receives the value read. - * - * Return: 0 if OK, -ve on error. - */ -int board_get_str(struct udevice *dev, int id, size_t size, char *val); - -/** - * board_get() - Return the board device for the board in question. - * @devp: Pointer to structure to receive the board device. - * - * Since there can only be at most one board instance, the API can supply a - * function that returns the unique device. This is especially useful for use - * in board files. - * - * Return: 0 if OK, -ve on error. - */ -int board_get(struct udevice **devp); - -/** - * board_get_fit_loadable - Get the name of an image to load from FIT - * This function can be used to provide the image names based on runtime - * detection. A classic use-case would when DTBOs are used to describe - * additionnal daughter cards. - * - * @dev: The board instance to gather the data. - * @index: Index of the image. Starts at 0 and gets incremented - * after each call to this function. - * @type: The type of image. For example, "fdt" for DTBs - * @strp: A pointer to string. Untouched if the function fails - * - * - * Return: 0 if OK, -ENOENT if no loadable is available else -ve on - * error. - */ -int board_get_fit_loadable(struct udevice *dev, int index, - const char *type, const char **strp); - -#else - -static inline int board_detect(struct udevice *dev) -{ - return -ENOSYS; -} - -static inline int board_get_bool(struct udevice *dev, int id, bool *val) -{ - return -ENOSYS; -} - -static inline int board_get_int(struct udevice *dev, int id, int *val) -{ - return -ENOSYS; -} - -static inline int board_get_str(struct udevice *dev, int id, size_t size, - char *val) -{ - return -ENOSYS; -} - -static inline int board_get(struct udevice **devp) -{ - return -ENOSYS; -} - -static inline int board_get_fit_loadable(struct udevice *dev, int index, - const char *type, const char **strp) -{ - return -ENOSYS; -} - -#endif diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 17542de2f36..e952a9967c2 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -36,7 +36,6 @@ enum uclass_id { UCLASS_AUDIO_CODEC, /* Audio codec with control and data path */ UCLASS_AXI, /* AXI bus */ UCLASS_BLK, /* Block device */ - UCLASS_BOARD, /* Device information from hardware */ UCLASS_BOOTCOUNT, /* Bootcount backing store */ UCLASS_BUTTON, /* Button */ UCLASS_CACHE, /* Cache controller */ @@ -107,6 +106,7 @@ enum uclass_id { UCLASS_SPI_GENERIC, /* Generic SPI flash target */ UCLASS_SPMI, /* System Power Management Interface bus */ UCLASS_SYSCON, /* System configuration device */ + UCLASS_SYSINFO, /* Device information from hardware */ UCLASS_SYSRESET, /* System reset device */ UCLASS_TEE, /* Trusted Execution Environment device */ UCLASS_THERMAL, /* Thermal sensor */ diff --git a/include/sysinfo.h b/include/sysinfo.h new file mode 100644 index 00000000000..c045d316b07 --- /dev/null +++ b/include/sysinfo.h @@ -0,0 +1,213 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2017 + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc + */ + +/* + * This uclass encapsulates hardware methods to gather information about a + * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders, + * read-only data in flash ICs, or similar. + * + * The interface offers functions to read the usual standard data types (bool, + * int, string) from the device, each of which is identified by a static + * numeric ID (which will usually be defined as a enum in a header file). + * + * If for example the sysinfo had a read-only serial number flash IC, we could + * call + * + * ret = sysinfo_detect(dev); + * if (ret) { + * debug("sysinfo device not found."); + * return ret; + * } + * + * ret = sysinfo_get_int(dev, ID_SERIAL_NUMBER, &serial); + * if (ret) { + * debug("Error when reading serial number from device."); + * return ret; + * } + * + * to read the serial number. + */ + +#if CONFIG_IS_ENABLED(SYSINFO) +struct sysinfo_ops { + /** + * detect() - Run the hardware info detection procedure for this + * device. + * @dev: The device containing the information + * + * This operation might take a long time (e.g. read from EEPROM, + * check the presence of a device on a bus etc.), hence this is not + * done in the probe() method, but later during operation in this + * dedicated method. + * + * Return: 0 if OK, -ve on error. + */ + int (*detect)(struct udevice *dev); + + /** + * get_bool() - Read a specific bool data value that describes the + * hardware setup. + * @dev: The sysinfo instance to gather the data. + * @id: A unique identifier for the bool value to be read. + * @val: Pointer to a buffer that receives the value read. + * + * Return: 0 if OK, -ve on error. + */ + int (*get_bool)(struct udevice *dev, int id, bool *val); + + /** + * get_int() - Read a specific int data value that describes the + * hardware setup. + * @dev: The sysinfo instance to gather the data. + * @id: A unique identifier for the int value to be read. + * @val: Pointer to a buffer that receives the value read. + * + * Return: 0 if OK, -ve on error. + */ + int (*get_int)(struct udevice *dev, int id, int *val); + + /** + * get_str() - Read a specific string data value that describes the + * hardware setup. + * @dev: The sysinfo instance to gather the data. + * @id: A unique identifier for the string value to be read. + * @size: The size of the buffer to receive the string data. + * @val: Pointer to a buffer that receives the value read. + * + * Return: 0 if OK, -ve on error. + */ + int (*get_str)(struct udevice *dev, int id, size_t size, char *val); + + /** + * get_fit_loadable - Get the name of an image to load from FIT + * This function can be used to provide the image names based on runtime + * detection. A classic use-case would when DTBOs are used to describe + * additionnal daughter cards. + * + * @dev: The sysinfo instance to gather the data. + * @index: Index of the image. Starts at 0 and gets incremented + * after each call to this function. + * @type: The type of image. For example, "fdt" for DTBs + * @strp: A pointer to string. Untouched if the function fails + * + * Return: 0 if OK, -ENOENT if no loadable is available else -ve on + * error. + */ + int (*get_fit_loadable)(struct udevice *dev, int index, + const char *type, const char **strp); +}; + +#define sysinfo_get_ops(dev) ((struct sysinfo_ops *)(dev)->driver->ops) + +/** + * sysinfo_detect() - Run the hardware info detection procedure for this device. + * + * @dev: The device containing the information + * + * Return: 0 if OK, -ve on error. + */ +int sysinfo_detect(struct udevice *dev); + +/** + * sysinfo_get_bool() - Read a specific bool data value that describes the + * hardware setup. + * @dev: The sysinfo instance to gather the data. + * @id: A unique identifier for the bool value to be read. + * @val: Pointer to a buffer that receives the value read. + * + * Return: 0 if OK, -ve on error. + */ +int sysinfo_get_bool(struct udevice *dev, int id, bool *val); + +/** + * sysinfo_get_int() - Read a specific int data value that describes the + * hardware setup. + * @dev: The sysinfo instance to gather the data. + * @id: A unique identifier for the int value to be read. + * @val: Pointer to a buffer that receives the value read. + * + * Return: 0 if OK, -ve on error. + */ +int sysinfo_get_int(struct udevice *dev, int id, int *val); + +/** + * sysinfo_get_str() - Read a specific string data value that describes the + * hardware setup. + * @dev: The sysinfo instance to gather the data. + * @id: A unique identifier for the string value to be read. + * @size: The size of the buffer to receive the string data. + * @val: Pointer to a buffer that receives the value read. + * + * Return: 0 if OK, -ve on error. + */ +int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val); + +/** + * sysinfo_get() - Return the sysinfo device for the sysinfo in question. + * @devp: Pointer to structure to receive the sysinfo device. + * + * Since there can only be at most one sysinfo instance, the API can supply a + * function that returns the unique device. This is especially useful for use + * in sysinfo files. + * + * Return: 0 if OK, -ve on error. + */ +int sysinfo_get(struct udevice **devp); + +/** + * sysinfo_get_fit_loadable - Get the name of an image to load from FIT + * This function can be used to provide the image names based on runtime + * detection. A classic use-case would when DTBOs are used to describe + * additionnal daughter cards. + * + * @dev: The sysinfo instance to gather the data. + * @index: Index of the image. Starts at 0 and gets incremented + * after each call to this function. + * @type: The type of image. For example, "fdt" for DTBs + * @strp: A pointer to string. Untouched if the function fails + * + * + * Return: 0 if OK, -ENOENT if no loadable is available else -ve on + * error. + */ +int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type, + const char **strp); + +#else + +static inline int sysinfo_detect(struct udevice *dev) +{ + return -ENOSYS; +} + +static inline int sysinfo_get_bool(struct udevice *dev, int id, bool *val) +{ + return -ENOSYS; +} + +static inline int sysinfo_get_int(struct udevice *dev, int id, int *val) +{ + return -ENOSYS; +} + +static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size, + char *val) +{ + return -ENOSYS; +} + +static inline int sysinfo_get(struct udevice **devp) +{ + return -ENOSYS; +} + +static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index, + const char *type, const char **strp) +{ + return -ENOSYS; +} + +#endif diff --git a/test/dm/Makefile b/test/dm/Makefile index 57e13ad5338..46e076ed099 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -21,7 +21,6 @@ obj-$(CONFIG_ACPIGEN) += acpigen.o obj-$(CONFIG_ACPIGEN) += acpi_dp.o obj-$(CONFIG_SOUND) += audio.o obj-$(CONFIG_BLK) += blk.o -obj-$(CONFIG_BOARD) += board.o obj-$(CONFIG_BUTTON) += button.o obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o obj-$(CONFIG_CLK) += clk.o clk_ccf.o @@ -78,6 +77,7 @@ obj-$(CONFIG_DM_SERIAL) += serial.o obj-$(CONFIG_CPU) += cpu.o obj-$(CONFIG_SOC_DEVICE) += soc.o obj-$(CONFIG_SOUND) += sound.o +obj-$(CONFIG_SYSINFO) += sysinfo.o obj-$(CONFIG_TEE) += tee.o obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o obj-$(CONFIG_DMA) += dma.o diff --git a/test/dm/board.c b/test/dm/board.c deleted file mode 100644 index f3e7f63f258..00000000000 --- a/test/dm/board.c +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * (C) Copyright 2018 - * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "../../drivers/board/sandbox.h" - -static int dm_test_board(struct unit_test_state *uts) -{ - struct udevice *board; - bool called_detect; - char str[64]; - int i; - - board_get(&board); - ut_assert(board); - - board_get_bool(board, BOOL_CALLED_DETECT, &called_detect); - ut_assert(!called_detect); - - board_detect(board); - - board_get_bool(board, BOOL_CALLED_DETECT, &called_detect); - ut_assert(called_detect); - - board_get_str(board, STR_VACATIONSPOT, sizeof(str), str); - ut_assertok(strcmp(str, "R'lyeh")); - - board_get_int(board, INT_TEST1, &i); - ut_asserteq(0, i); - - board_get_int(board, INT_TEST2, &i); - ut_asserteq(100, i); - - board_get_str(board, STR_VACATIONSPOT, sizeof(str), str); - ut_assertok(strcmp(str, "Carcosa")); - - board_get_int(board, INT_TEST1, &i); - ut_asserteq(1, i); - - board_get_int(board, INT_TEST2, &i); - ut_asserteq(99, i); - - board_get_str(board, STR_VACATIONSPOT, sizeof(str), str); - ut_assertok(strcmp(str, "Yuggoth")); - - return 0; -} - -DM_TEST(dm_test_board, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); diff --git a/test/dm/sysinfo.c b/test/dm/sysinfo.c new file mode 100644 index 00000000000..4aaa9e85bce --- /dev/null +++ b/test/dm/sysinfo.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2018 + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "../../drivers/sysinfo/sandbox.h" + +static int dm_test_sysinfo(struct unit_test_state *uts) +{ + struct udevice *sysinfo; + bool called_detect; + char str[64]; + int i; + + ut_assertok(sysinfo_get(&sysinfo)); + ut_assert(sysinfo); + + sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT, &called_detect); + ut_assert(!called_detect); + + sysinfo_detect(sysinfo); + + sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT, &called_detect); + ut_assert(called_detect); + + sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str), str); + ut_assertok(strcmp(str, "R'lyeh")); + + sysinfo_get_int(sysinfo, INT_TEST1, &i); + ut_asserteq(0, i); + + sysinfo_get_int(sysinfo, INT_TEST2, &i); + ut_asserteq(100, i); + + sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str), str); + ut_assertok(strcmp(str, "Carcosa")); + + sysinfo_get_int(sysinfo, INT_TEST1, &i); + ut_asserteq(1, i); + + sysinfo_get_int(sysinfo, INT_TEST2, &i); + ut_asserteq(99, i); + + sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str), str); + ut_assertok(strcmp(str, "Yuggoth")); + + return 0; +} + +DM_TEST(dm_test_sysinfo, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); -- cgit v1.3.1 From 78227d4eda26d5838b34e12f5080346728015fa5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 06:32:07 -0700 Subject: 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 Reviewed-by: Bin Meng --- include/smbios.h | 5 ++++- lib/smbios.c | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/smbios.h b/include/smbios.h index 44f49e9556b..1846607c3cf 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -8,6 +8,8 @@ #ifndef _SMBIOS_H_ #define _SMBIOS_H_ +#include + /* SMBIOS spec version implemented */ #define SMBIOS_MAJOR_VER 3 #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 * @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 */ -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 diff --git a/lib/smbios.c b/lib/smbios.c index 11790443e1a..b0f5e936044 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -13,7 +14,6 @@ #include #ifdef CONFIG_CPU #include -#include #include #endif @@ -25,7 +25,7 @@ * * @start: string area start address * @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) { @@ -74,7 +74,7 @@ static int smbios_string_table_len(char *start) 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; int len = sizeof(struct smbios_type0); @@ -111,7 +111,7 @@ static int smbios_write_type0(ulong *current, int handle) 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; int len = sizeof(struct smbios_type1); @@ -134,7 +134,7 @@ static int smbios_write_type1(ulong *current, int handle) 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; int len = sizeof(struct smbios_type2); @@ -154,7 +154,7 @@ static int smbios_write_type2(ulong *current, int handle) 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; int len = sizeof(struct smbios_type3); @@ -176,7 +176,7 @@ static int smbios_write_type3(ulong *current, int handle) 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; const char *vendor = "Unknown"; @@ -185,20 +185,20 @@ static void smbios_write_type4_dm(struct smbios_type4 *t) #ifdef CONFIG_CPU char processor_name[49]; char vendor_name[49]; - struct udevice *dev = NULL; + struct udevice *cpu = NULL; - uclass_find_first_device(UCLASS_CPU, &dev); - if (dev) { - struct cpu_platdata *plat = dev_get_parent_platdata(dev); + uclass_find_first_device(UCLASS_CPU, &cpu); + if (cpu) { + struct cpu_platdata *plat = dev_get_parent_platdata(cpu); if (plat->family) processor_family = plat->family; t->processor_id[0] = plat->id[0]; 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; - if (!cpu_get_desc(dev, processor_name, sizeof(processor_name))) + if (!cpu_get_desc(cpu, processor_name, sizeof(processor_name))) name = processor_name; } #endif @@ -208,7 +208,7 @@ static void smbios_write_type4_dm(struct smbios_type4 *t) 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; 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)); fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle); 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->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE; t->l1_cache_handle = 0xffff; @@ -232,7 +232,7 @@ static int smbios_write_type4(ulong *current, int handle) 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; int len = sizeof(struct smbios_type32); @@ -247,7 +247,7 @@ static int smbios_write_type32(ulong *current, int handle) 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; int len = sizeof(struct smbios_type127); @@ -274,7 +274,9 @@ static smbios_write_type smbios_write_funcs[] = { ulong write_smbios_table(ulong addr) { + ofnode node = ofnode_null(); struct smbios_entry *se; + struct udevice *dev; ulong table_addr; ulong tables; int len = 0; @@ -284,6 +286,12 @@ ulong write_smbios_table(ulong addr) int isize; 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 */ addr = ALIGN(addr, 16); @@ -296,7 +304,7 @@ ulong write_smbios_table(ulong addr) /* populate minimum required tables */ 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); len += tmp; -- cgit v1.3.1