From patchwork Fri Dec 6 22:54:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Mao X-Patchwork-Id: 2019565 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Wy/6tTXe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4mmx748mz1yQw for ; Sat, 7 Dec 2024 09:55:13 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1892B88815; Fri, 6 Dec 2024 23:55:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Wy/6tTXe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 361518870D; Fri, 6 Dec 2024 23:55:11 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 92BA58929D for ; Fri, 6 Dec 2024 23:55:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-qt1-x830.google.com with SMTP id d75a77b69052e-46690cbec70so17074561cf.1 for ; Fri, 06 Dec 2024 14:55:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733525707; x=1734130507; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jQ50UbUxUK/TwKTkhNVU37pK6P6lage6W4QHUzMEHZ4=; b=Wy/6tTXeCTTT+w9LIa5hV2lrK7q6RFFK9j2DEHFDFpSR8uTwBNXfxSVAeTBOY6pmNp NxByhBs3jCv2tG4qpZunj6phibohgPeWIK/+RDr+gYEAxE8P880CgViIWUFzGLd+BPkv GsW/Oho5Jx/McwtaOAe2Su2dmN9zDwSJVEluG8O6pf4vnv7pnV3As4EiOPRJ3lFvdexL dr55qEd1jX3+Z6qLwQsf3/CsR4uKkSbrxPLu0Qcxwpz9m9gugodPClis0EBvjM8jcUgK nRPvL9OVTjgMxLqSTLqN8YonK5HwyPLL0IiAWohewl3rQERBAVdNJds+8b76phXUfZB9 y1wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733525707; x=1734130507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jQ50UbUxUK/TwKTkhNVU37pK6P6lage6W4QHUzMEHZ4=; b=KdXKiSeJNbZnl9E2iQ0PIYVmBEnKjoIxiTJqQZtH9tODhXTr4LNOEXRTCzFtRHi4Vq YRN3PnL1wqcNfthLsciMFal9/bFM1Vfj1nqI8hnlug/DjcFow9GJ7jYVu+yj3bKIlFZz gyNfaQ1Kldey4OqyWexEd/yYh7tdlMr0+uIuodqtutcTHGb4xqODZ+EV2VphDlumOV5m HNpOkyggUxY/yefCs2N8z/lA2Gy5TwwSQsPWPqoVYIpeTEFd9YTOoncba6EGq0gMvaJM FA0GvGEXm3NCfKpyAU+Joxz8TD8K5DjymEKZ2WAJ2jXOlMA01tJ8mEXRwU2l32KmwOpB G4sg== X-Gm-Message-State: AOJu0YzhK6GuS50cU6D6gF2glgQKyjCrhdSUayX1dax/dqV9MG4u4y5P zAdM125sBHCoHWxgHY1PLaQ0StCuycSs3Ntu1mZj0q1CcAywzyz/Mt6LtMLFOs5RXVnbl2KkHHz P X-Gm-Gg: ASbGnctfbPrjkXiFgFoo/w2Jyu0ssZbI1MDoLmakR+3z1E3BW9ETUgpmlRSygQlJNkU vakxebSb2eHTyeF1R+ETq20X+Yn3RHvkIWqd/JuaFZ12d6L5jZNpm4WOd/qtxTZFg46jWt9pUV5 Q6SY9FqZeIb0g/dw59EfdwDarw22j21s7m0e61umJsjkT4Eqs1x6f79lIuVPb4FtmfwQjjb4wSS H7qlpzORYxwX8C4JbYx3U1t9oeGl6voT+9RdAqGgpmbZYjD/AdFMvkAqvpNpopRct1ttF8FKJcK lgIhp3aROclG/0UJ9z5MUekV3iE/JuPPu0nnhiN4SeEPYmEtEyz5 X-Google-Smtp-Source: AGHT+IHfNQ4vibbsHfkci9bN8trYMrpZ+o8gFi9yooAmx1PjjkzDAMJPoexws7MUZ8uoTgji6dsyNA== X-Received: by 2002:ac8:5e11:0:b0:461:313e:8868 with SMTP id d75a77b69052e-46734f96856mr63586971cf.50.1733525707181; Fri, 06 Dec 2024 14:55:07 -0800 (PST) Received: from ubuntu.localdomain (pool-174-114-184-37.cpe.net.cable.rogers.com. [174.114.184.37]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-467296d4d7dsm26080871cf.34.2024.12.06.14.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 14:55:06 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Tom Rini , Tuomas Tynkkynen , Simon Glass , Patrick Rudolph , Heinrich Schuchardt , Ilias Apalodimas , Stefan Roese , =?utf-8?q?Marek_Beh=C3=BAn?= , Alexander Gendin , Caleb Connolly , Wan Yee Lau , Jonas Karlman , Masahisa Kojima , Francesco Dolcini , Michal Simek , Max Krummenacher , Sughosh Ganu , Peter Robinson Subject: [PATCH v3 01/10] smbios: Refactor the smbios headfile Date: Fri, 6 Dec 2024 14:54:18 -0800 Message-Id: <20241206225438.13866-2-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241206225438.13866-1-raymond.mao@linaro.org> References: <20241206225438.13866-1-raymond.mao@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Move the smbios field definitions to a separated simple headfile, which is a prerequisite to be included by dts files. Add new definitions for cache information. This patch also includes a few of code optimizations in smbios. Signed-off-by: Raymond Mao Acked-by: Heinrich Schuchardt --- Changes in v2 - Initial patch. Changes in v3 - Miscellaneous updates. cmd/smbios.c | 4 +- include/smbios.h | 81 +++--------------- include/smbios_def.h | 194 +++++++++++++++++++++++++++++++++++++++++++ lib/smbios.c | 44 +++++----- 4 files changed, 231 insertions(+), 92 deletions(-) create mode 100644 include/smbios_def.h diff --git a/cmd/smbios.c b/cmd/smbios.c index d3bd8b12a67..2122ac04e55 100644 --- a/cmd/smbios.c +++ b/cmd/smbios.c @@ -99,12 +99,12 @@ static void smbios_print_type1(struct smbios_type1 *table) smbios_print_str("Product Name", table, table->product_name); smbios_print_str("Version", table, table->version); smbios_print_str("Serial Number", table, table->serial_number); - if (table->length >= 0x19) { + if (table->hdr.length >= SMBIOS_TYPE1_LENGTH_V21) { printf("\tUUID: %pUl\n", table->uuid); printf("\tWake-up Type: %s\n", smbios_wakeup_type_str(table->wakeup_type)); } - if (table->length >= 0x1b) { + if (table->hdr.length >= SMBIOS_TYPE1_LENGTH_V24) { smbios_print_str("SKU Number", table, table->sku_number); smbios_print_str("Family", table, table->family); } diff --git a/include/smbios.h b/include/smbios.h index 00119d7a60c..78fd14d881b 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -9,6 +9,7 @@ #define _SMBIOS_H_ #include +#include /* SMBIOS spec version implemented */ #define SMBIOS_MAJOR_VER 3 @@ -80,19 +81,14 @@ struct __packed smbios3_entry { u64 struct_table_address; }; -/* BIOS characteristics */ -#define BIOS_CHARACTERISTICS_PCI_SUPPORTED (1 << 7) -#define BIOS_CHARACTERISTICS_UPGRADEABLE (1 << 11) -#define BIOS_CHARACTERISTICS_SELECTABLE_BOOT (1 << 16) - -#define BIOS_CHARACTERISTICS_EXT1_ACPI (1 << 0) -#define BIOS_CHARACTERISTICS_EXT2_UEFI (1 << 3) -#define BIOS_CHARACTERISTICS_EXT2_TARGET (1 << 2) - -struct __packed smbios_type0 { +struct __packed smbios_header { u8 type; u8 length; u16 handle; +}; + +struct __packed smbios_type0 { + struct smbios_header hdr; u8 vendor; u8 bios_ver; u16 bios_start_segment; @@ -109,37 +105,12 @@ struct __packed smbios_type0 { char eos[SMBIOS_STRUCT_EOS_BYTES]; }; -/** - * enum smbios_wakeup_type - wake-up type - * - * These constants are used for the Wake-Up Type field in the SMBIOS - * System Information (Type 1) structure. - */ -enum smbios_wakeup_type { - /** @SMBIOS_WAKEUP_TYPE_RESERVED: Reserved */ - SMBIOS_WAKEUP_TYPE_RESERVED, - /** @SMBIOS_WAKEUP_TYPE_OTHER: Other */ - SMBIOS_WAKEUP_TYPE_OTHER, - /** @SMBIOS_WAKEUP_TYPE_UNKNOWN: Unknown */ - SMBIOS_WAKEUP_TYPE_UNKNOWN, - /** @SMBIOS_WAKEUP_TYPE_APM_TIMER: APM Timer */ - SMBIOS_WAKEUP_TYPE_APM_TIMER, - /** @SMBIOS_WAKEUP_TYPE_MODEM_RING: Modem Ring */ - SMBIOS_WAKEUP_TYPE_MODEM_RING, - /** @SMBIOS_WAKEUP_TYPE_LAN_REMOTE: LAN Remote */ - SMBIOS_WAKEUP_TYPE_LAN_REMOTE, - /** @SMBIOS_WAKEUP_TYPE_POWER_SWITCH: Power Switch */ - SMBIOS_WAKEUP_TYPE_POWER_SWITCH, - /** @SMBIOS_WAKEUP_TYPE_PCI_PME: PCI PME# */ - SMBIOS_WAKEUP_TYPE_PCI_PME, - /** @SMBIOS_WAKEUP_TYPE_AC_POWER_RESTORED: AC Power Restored */ - SMBIOS_WAKEUP_TYPE_AC_POWER_RESTORED, -}; +#define SMBIOS_TYPE1_LENGTH_V20 0x08 +#define SMBIOS_TYPE1_LENGTH_V21 0x19 +#define SMBIOS_TYPE1_LENGTH_V24 0x1b struct __packed smbios_type1 { - u8 type; - u8 length; - u16 handle; + struct smbios_header hdr; u8 manufacturer; u8 product_name; u8 version; @@ -151,13 +122,8 @@ struct __packed smbios_type1 { char eos[SMBIOS_STRUCT_EOS_BYTES]; }; -#define SMBIOS_BOARD_FEATURE_HOSTING (1 << 0) -#define SMBIOS_BOARD_MOTHERBOARD 10 - struct __packed smbios_type2 { - u8 type; - u8 length; - u16 handle; + struct smbios_header hdr; u8 manufacturer; u8 product_name; u8 version; @@ -171,14 +137,8 @@ struct __packed smbios_type2 { char eos[SMBIOS_STRUCT_EOS_BYTES]; }; -#define SMBIOS_ENCLOSURE_DESKTOP 3 -#define SMBIOS_STATE_SAFE 3 -#define SMBIOS_SECURITY_NONE 3 - struct __packed smbios_type3 { - u8 type; - u8 length; - u16 handle; + struct smbios_header hdr; u8 manufacturer; u8 chassis_type; u8 version; @@ -196,17 +156,8 @@ struct __packed smbios_type3 { char eos[SMBIOS_STRUCT_EOS_BYTES]; }; -#define SMBIOS_PROCESSOR_TYPE_CENTRAL 3 -#define SMBIOS_PROCESSOR_STATUS_ENABLED 1 -#define SMBIOS_PROCESSOR_UPGRADE_NONE 6 - -#define SMBIOS_PROCESSOR_FAMILY_OTHER 1 -#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 - struct __packed smbios_type4 { - u8 type; - u8 length; - u16 handle; + struct smbios_header hdr; u8 socket_designation; u8 processor_type; u8 processor_family; @@ -252,12 +203,6 @@ struct __packed smbios_type127 { char eos[SMBIOS_STRUCT_EOS_BYTES]; }; -struct __packed smbios_header { - u8 type; - u8 length; - u16 handle; -}; - /** * fill_smbios_header() - Fill the header of an SMBIOS table * diff --git a/include/smbios_def.h b/include/smbios_def.h new file mode 100644 index 00000000000..81c5781217f --- /dev/null +++ b/include/smbios_def.h @@ -0,0 +1,194 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2024 Linaro Limited + * Author: Raymond Mao + */ + +#ifndef _SMBIOS_DEF_H_ +#define _SMBIOS_DEF_H_ + +/* + * BIOS characteristics + */ + +#define BIOS_CHARACTERISTICS_PCI_SUPPORTED 0x80 /* BIT(7) */ +#define BIOS_CHARACTERISTICS_UPGRADEABLE 0x800 /* BIT(11) */ +#define BIOS_CHARACTERISTICS_SELECTABLE_BOOT 0x10000 /* BIT(16) */ + +#define BIOS_CHARACTERISTICS_EXT1_ACPI 1 /* BIT(0) */ +#define BIOS_CHARACTERISTICS_EXT2_UEFI 8 /* BIT(3) */ +#define BIOS_CHARACTERISTICS_EXT2_TARGET 4 /* BIT(2) */ + +/* + * System Information + */ + +#define SMBIOS_WAKEUP_TYPE_RESERVED 0 +#define SMBIOS_WAKEUP_TYPE_OTHER 1 +#define SMBIOS_WAKEUP_TYPE_UNKNOWN 2 +#define SMBIOS_WAKEUP_TYPE_APM_TIMER 3 +#define SMBIOS_WAKEUP_TYPE_MODEM_RING 4 +#define SMBIOS_WAKEUP_TYPE_LAN_REMOTE 5 +#define SMBIOS_WAKEUP_TYPE_POWER_SWITCH 6 +#define SMBIOS_WAKEUP_TYPE_PCI_PME 7 +#define SMBIOS_WAKEUP_TYPE_AC_POWER_RESTORED 8 + +/* + * Baseboard Information + */ + +#define SMBIOS_BOARD_FEAT_HOST_BOARD 1 /* BIT(0) */ +#define SMBIOS_BOARD_FEAT_REQ_AUX 2 /* BIT(1) */ +#define SMBIOS_BOARD_FEAT_REMOVABLE 4 /* BIT(2) */ +#define SMBIOS_BOARD_FEAT_REPLACEABLE 8 /* BIT(3) */ +#define SMBIOS_BOARD_FEAT_HOT_SWAPPABLE 16 /* BIT(4) */ + +#define SMBIOS_BOARD_TYPE_UNKNOWN 1 +#define SMBIOS_BOARD_TYPE_OTHER 2 +#define SMBIOS_BOARD_TYPE_SERVER_BLADE 3 +#define SMBIOS_BOARD_TYPE_CON_SWITCH 4 +#define SMBIOS_BOARD_TYPE_SM_MODULE 5 +#define SMBIOS_BOARD_TYPE_PROCESSOR_MODULE 6 +#define SMBIOS_BOARD_TYPE_IO_MODULE 7 +#define SMBIOS_BOARD_TYPE_MEM_MODULE 8 +#define SMBIOS_BOARD_TYPE_DAUGHTER_BOARD 9 +#define SMBIOS_BOARD_TYPE_MOTHERBOARD 10 +#define SMBIOS_BOARD_TYPE_PROC_MEM_MODULE 11 +#define SMBIOS_BOARD_TYPE_PROC_IO_MODULE 12 +#define SMBIOS_BOARD_TYPE_INTERCON 13 + +/* + * System Enclosure or Chassis + */ +#define SMBIOS_ENCLOSURE_UNKNOWN 2 +#define SMBIOS_ENCLOSURE_DESKTOP 3 + +#define SMBIOS_STATE_OTHER 1 +#define SMBIOS_STATE_UNKNOWN 2 +#define SMBIOS_STATE_SAFE 3 +#define SMBIOS_STATE_WARNING 4 +#define SMBIOS_STATE_CRITICAL 5 +#define SMBIOS_STATE_NONRECOVERABLE 6 + +#define SMBIOS_SECURITY_OTHER 1 +#define SMBIOS_SECURITY_UNKNOWN 2 +#define SMBIOS_SECURITY_NONE 3 +#define SMBIOS_SECURITY_EXTINT_LOCK 4 +#define SMBIOS_SECURITY_EXTINT_EN 5 + +#define SMBIOS_ENCLOSURE_OEM_UND 0 +#define SMBIOS_ENCLOSURE_HEIGHT_UND 0 +#define SMBIOS_POWCORD_NUM_UND 0 +#define SMBIOS_ELEMENT_TYPE_SELECT 0x80 /* BIT(7) */ + +/* + * Processor Information + */ + +#define SMBIOS_PROCESSOR_TYPE_OTHER 1 +#define SMBIOS_PROCESSOR_TYPE_UNKNOWN 2 +#define SMBIOS_PROCESSOR_TYPE_CENTRAL 3 +#define SMBIOS_PROCESSOR_TYPE_MATH 4 +#define SMBIOS_PROCESSOR_TYPE_DSP 5 +#define SMBIOS_PROCESSOR_TYPE_VIDEO 6 + +#define SMBIOS_PROCESSOR_STATUS_UNKNOWN 0 +#define SMBIOS_PROCESSOR_STATUS_ENABLED 1 +#define SMBIOS_PROCESSOR_STATUS_DISABLED_USER 2 +#define SMBIOS_PROCESSOR_STATUS_DISABLED_BIOS 3 +#define SMBIOS_PROCESSOR_STATUS_IDLE 4 +#define SMBIOS_PROCESSOR_STATUS_OTHER 7 + +#define SMBIOS_PROCESSOR_UPGRADE_OTHER 1 +#define SMBIOS_PROCESSOR_UPGRADE_UNKNOWN 2 +#define SMBIOS_PROCESSOR_UPGRADE_NONE 6 + +#define SMBIOS_PROCESSOR_FAMILY_OTHER 1 +#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 +#define SMBIOS_PROCESSOR_FAMILY_RSVD 255 +#define SMBIOS_PROCESSOR_FAMILY_ARMV7 256 +#define SMBIOS_PROCESSOR_FAMILY_ARMV8 257 +#define SMBIOS_PROCESSOR_FAMILY_RV32 512 +#define SMBIOS_PROCESSOR_FAMILY_RV64 513 + +#define SMBIOS_PROCESSOR_FAMILY_EXT 0xfe + +/* Processor Characteristics */ +#define SMBIOS_PROCESSOR_RSVD 1 /* BIT(0) */ +#define SMBIOS_PROCESSOR_UND 2 /* BIT(1) */ +#define SMBIOS_PROCESSOR_64BIT 4 /* BIT(2) */ +#define SMBIOS_PROCESSOR_MULTICORE 8 /* BIT(3) */ +#define SMBIOS_PROCESSOR_HWTHREAD 16 /* BIT(4) */ +#define SMBIOS_PROCESSOR_EXEC_PROT 32 /* BIT(5) */ +#define SMBIOS_PROCESSOR_ENH_VIRT 64 /* BIT(6) */ +#define SMBIOS_PROCESSOR_POW_CON 0x80 /* BIT(7) */ +#define SMBIOS_PROCESSOR_128BIT 0x100 /* BIT(8) */ +#define SMBIOS_PROCESSOR_ARM64_SOCID 0x200 /* BIT(9) */ + +/* + * Cache Information + */ + +#define SMBIOS_CACHE_SIZE_EXT_KB (2047 * 1024) /* 2047 MiB */ +#define SMBIOS_CACHE_HANDLE_NONE 0xffff + +/* System Cache Type */ +#define SMBIOS_CACHE_SYSCACHE_TYPE_OTHER 1 +#define SMBIOS_CACHE_SYSCACHE_TYPE_UNKNOWN 2 +#define SMBIOS_CACHE_SYSCACHE_TYPE_INST 3 +#define SMBIOS_CACHE_SYSCACHE_TYPE_DATA 4 +#define SMBIOS_CACHE_SYSCACHE_TYPE_UNIFIED 5 + +/* Cache Speed */ +#define SMBIOS_CACHE_SPEED_UNKNOWN 0 + +/* SRAM Type */ +#define SMBIOS_CACHE_SRAM_TYPE_UNKNOWN 2 /* BIT(1) */ + +/* Error Correction Type */ +#define SMBIOS_CACHE_ERRCORR_OTHER 1 +#define SMBIOS_CACHE_ERRCORR_UNKNOWN 2 +#define SMBIOS_CACHE_ERRCORR_NONE 3 +#define SMBIOS_CACHE_ERRCORR_PARITY 4 +#define SMBIOS_CACHE_ERRCORR_SBITECC 5 +#define SMBIOS_CACHE_ERRCORR_MBITECC 6 + +/* Cache Configuration */ +#define SMBIOS_CACHE_LEVEL_1 0 +#define SMBIOS_CACHE_LEVEL_2 1 +#define SMBIOS_CACHE_LEVEL_3 2 +#define SMBIOS_CACHE_LEVEL_4 3 +#define SMBIOS_CACHE_LEVEL_5 4 +#define SMBIOS_CACHE_LEVEL_6 5 +#define SMBIOS_CACHE_LEVEL_7 6 +#define SMBIOS_CACHE_LEVEL_8 7 +#define SMBIOS_CACHE_SOCKETED 8 /* BIT(3) */ +#define SMBIOS_CACHE_LOCATE_EXTERNAL 32 /* BIT(5) */ +#define SMBIOS_CACHE_LOCATE_RESERVED 64 /* BIT(6) */ +#define SMBIOS_CACHE_LOCATE_UNKNOWN 96 /* (BIT(5) | BIT(6)) */ +#define SMBIOS_CACHE_ENABLED 0x80 /* BIT(7) */ +#define SMBIOS_CACHE_OP_WB 0x100 /* BIT(8), Write Back */ +#define SMBIOS_CACHE_OP_VAR 0x200 /* BIT(9), Varies with Memory Address */ +#define SMBIOS_CACHE_OP_UND 0x300 /* (BIT(8) | BIT(9)), Unknown*/ + +/* Cache Granularity */ +#define SMBIOS_CACHE_GRANU_1K 0 +#define SMBIOS_CACHE_GRANU_64K 1 + +/* Cache Associativity */ +#define SMBIOS_CACHE_ASSOC_OTHER 1 +#define SMBIOS_CACHE_ASSOC_UNKNOWN 2 +#define SMBIOS_CACHE_ASSOC_DMAPPED 3 +#define SMBIOS_CACHE_ASSOC_2WAY 4 +#define SMBIOS_CACHE_ASSOC_4WAY 5 +#define SMBIOS_CACHE_ASSOC_FULLY 6 +#define SMBIOS_CACHE_ASSOC_8WAY 7 +#define SMBIOS_CACHE_ASSOC_16WAY 8 +#define SMBIOS_CACHE_ASSOC_12WAY 9 +#define SMBIOS_CACHE_ASSOC_24WAY 10 +#define SMBIOS_CACHE_ASSOC_32WAY 11 +#define SMBIOS_CACHE_ASSOC_48WAY 12 +#define SMBIOS_CACHE_ASSOC_64WAY 13 +#define SMBIOS_CACHE_ASSOC_20WAY 14 + +#endif /* _SMBIOS_DEF_H_ */ diff --git a/lib/smbios.c b/lib/smbios.c index a36d4b4e54a..1dd564a1762 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -330,10 +330,10 @@ static int smbios_write_type0(ulong *current, int handle, struct smbios_ctx *ctx) { struct smbios_type0 *t; - int len = sizeof(struct smbios_type0); + int len = sizeof(*t); t = map_sysmem(*current, len); - memset(t, 0, sizeof(struct smbios_type0)); + memset(t, 0, len); fill_smbios_header(t, SMBIOS_BIOS_INFORMATION, len, handle); smbios_set_eos(ctx, t->eos); t->vendor = smbios_add_prop(ctx, NULL, "U-Boot"); @@ -374,7 +374,7 @@ static int smbios_write_type0(ulong *current, int handle, t->ec_major_release = 0xff; t->ec_minor_release = 0xff; - len = t->length + smbios_string_table_len(ctx); + len = t->hdr.length + smbios_string_table_len(ctx); *current += len; unmap_sysmem(t); @@ -385,11 +385,11 @@ static int smbios_write_type1(ulong *current, int handle, struct smbios_ctx *ctx) { struct smbios_type1 *t; - int len = sizeof(struct smbios_type1); + int len = sizeof(*t); char *serial_str = env_get("serial#"); t = map_sysmem(*current, len); - memset(t, 0, sizeof(struct smbios_type1)); + memset(t, 0, len); fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle); smbios_set_eos(ctx, t->eos); t->manufacturer = smbios_add_prop_si(ctx, "manufacturer", @@ -403,7 +403,7 @@ static int smbios_write_type1(ulong *current, int handle, NULL); if (serial_str) { t->serial_number = smbios_add_prop(ctx, NULL, serial_str); - strncpy((char *)t->uuid, serial_str, sizeof(t->uuid)); + strlcpy((char *)t->uuid, serial_str, sizeof(t->uuid)); } else { t->serial_number = smbios_add_prop_si(ctx, "serial", SYSID_SM_SYSTEM_SERIAL, @@ -415,7 +415,7 @@ static int smbios_write_type1(ulong *current, int handle, t->family = smbios_add_prop_si(ctx, "family", SYSID_SM_SYSTEM_FAMILY, NULL); - len = t->length + smbios_string_table_len(ctx); + len = t->hdr.length + smbios_string_table_len(ctx); *current += len; unmap_sysmem(t); @@ -426,10 +426,10 @@ static int smbios_write_type2(ulong *current, int handle, struct smbios_ctx *ctx) { struct smbios_type2 *t; - int len = sizeof(struct smbios_type2); + int len = sizeof(*t); t = map_sysmem(*current, len); - memset(t, 0, sizeof(struct smbios_type2)); + memset(t, 0, len); fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle); smbios_set_eos(ctx, t->eos); t->manufacturer = smbios_add_prop_si(ctx, "manufacturer", @@ -448,11 +448,11 @@ static int smbios_write_type2(ulong *current, int handle, t->asset_tag_number = smbios_add_prop_si(ctx, "asset-tag", SYSID_SM_BASEBOARD_ASSET_TAG, NULL); - t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING; - t->board_type = SMBIOS_BOARD_MOTHERBOARD; + t->feature_flags = SMBIOS_BOARD_FEAT_HOST_BOARD; + t->board_type = SMBIOS_BOARD_TYPE_MOTHERBOARD; t->chassis_handle = handle + 1; - len = t->length + smbios_string_table_len(ctx); + len = t->hdr.length + smbios_string_table_len(ctx); *current += len; unmap_sysmem(t); @@ -463,10 +463,10 @@ static int smbios_write_type3(ulong *current, int handle, struct smbios_ctx *ctx) { struct smbios_type3 *t; - int len = sizeof(struct smbios_type3); + int len = sizeof(*t); t = map_sysmem(*current, len); - memset(t, 0, sizeof(struct smbios_type3)); + memset(t, 0, len); fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle); smbios_set_eos(ctx, t->eos); t->manufacturer = smbios_add_prop(ctx, "manufacturer", NULL); @@ -476,7 +476,7 @@ static int smbios_write_type3(ulong *current, int handle, t->thermal_state = SMBIOS_STATE_SAFE; t->security_status = SMBIOS_SECURITY_NONE; - len = t->length + smbios_string_table_len(ctx); + len = t->hdr.length + smbios_string_table_len(ctx); *current += len; unmap_sysmem(t); @@ -521,10 +521,10 @@ static int smbios_write_type4(ulong *current, int handle, struct smbios_ctx *ctx) { struct smbios_type4 *t; - int len = sizeof(struct smbios_type4); + int len = sizeof(*t); t = map_sysmem(*current, len); - memset(t, 0, sizeof(struct smbios_type4)); + memset(t, 0, len); fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle); smbios_set_eos(ctx, t->eos); t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL; @@ -535,7 +535,7 @@ static int smbios_write_type4(ulong *current, int handle, t->l2_cache_handle = 0xffff; t->l3_cache_handle = 0xffff; - len = t->length + smbios_string_table_len(ctx); + len = t->hdr.length + smbios_string_table_len(ctx); *current += len; unmap_sysmem(t); @@ -546,10 +546,10 @@ static int smbios_write_type32(ulong *current, int handle, struct smbios_ctx *ctx) { struct smbios_type32 *t; - int len = sizeof(struct smbios_type32); + int len = sizeof(*t); t = map_sysmem(*current, len); - memset(t, 0, sizeof(struct smbios_type32)); + memset(t, 0, len); fill_smbios_header(t, SMBIOS_SYSTEM_BOOT_INFORMATION, len, handle); smbios_set_eos(ctx, t->eos); @@ -563,10 +563,10 @@ static int smbios_write_type127(ulong *current, int handle, struct smbios_ctx *ctx) { struct smbios_type127 *t; - int len = sizeof(struct smbios_type127); + int len = sizeof(*t); t = map_sysmem(*current, len); - memset(t, 0, sizeof(struct smbios_type127)); + memset(t, 0, len); fill_smbios_header(t, SMBIOS_END_OF_TABLE, len, handle); *current += len; From patchwork Fri Dec 6 22:54:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Mao X-Patchwork-Id: 2019566 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=y2Q5K5tb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4mnF0nFqz1yRZ for ; Sat, 7 Dec 2024 09:55:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 930E289434; Fri, 6 Dec 2024 23:55:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="y2Q5K5tb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3B6408870D; Fri, 6 Dec 2024 23:55:25 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 03F1389434 for ; Fri, 6 Dec 2024 23:55:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-qt1-x835.google.com with SMTP id d75a77b69052e-4667931f14bso39690841cf.2 for ; Fri, 06 Dec 2024 14:55:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733525721; x=1734130521; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ndZkRBz8e+oOX0+xXuTU1p45dhwl7oHAgnohSTQkqZI=; b=y2Q5K5tbo1r8RsZ9Y5t2aus+hxjWmWTf3aawiqSxrqY6vxAO2eXR4tW9fapzO1ES5x F6Yli60X9jCrHXGnWGYBWlIskezcxSEHi//6FVrBJwWyj8/gkH+wdrHjFfRBizn3E0SM M33ySj3Fc3fKC+CoY6wQZMqdSgcSofySIq+OBTmszwqWnr3mkiqFB0kSwy+1sJww1sZE +9XSOXuzpZdQBqZ34Dxf6toaKa8Hxd0bsCgk7FdUfge/uhbLLZLjak534O6r4qVTcC1H YSMwRIQjN1IpakOU3lYEED53F0pXkO3Kb0g0HhhbQg2u78lCcK3jd4Aa+T9XUhCmgbQ0 w3/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733525721; x=1734130521; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ndZkRBz8e+oOX0+xXuTU1p45dhwl7oHAgnohSTQkqZI=; b=ncQ9p8U3DtskDPfymnnxVf6JKfhXN6CqgFntLIB3FLsnFNKoR+1UsXBfmDXoVtvboS 36ANjD6Nm7A8y17OxIGZN7Xq3NVaxImYN09yRQV86HXO3ozru6gDbteHH4IjNuD0uxGN CjltsOkGZWQlr6nQa+ymXZqeqv8xuiwwrZd+9avTV1aaDm+7M3Nxd2tthKX2L5bpU9or bW3v5HVjcTIMGLl3mATXQfBZtAEcVuHejJySn1U73dcjUVCnY//BGduar1aazOK3kdTI SZb3zH5E2HqVEUnhfMUESEP2AHx3O/HsOmKYciHi+n/mkXRPZ9Aq+2Zajh9kAWJD6Xki NFlg== X-Gm-Message-State: AOJu0Yxc1KWUrnJWGwGlb4dcBqQIGg86b4OHVzVc9IRc6+0aaBKERAoe W96xPRxgJz/W4XFMpw7iEPQjZRHVxtora5Xp7FYYUK0o1s8io0dBNmc5kC0bV7k8JR1QZPY3/ja 3 X-Gm-Gg: ASbGncs3Csy/1xqQrhfw3FER+6SW56j6NbkWpWIuMU8cfOsCkJ3DQIuTUuMzKfSHzXv 9cBpvQERzETZm/OTVeAymGAwBQdyB+oCDRlfgmGwIHj5QdJIcr/jb+VBNarVvw2zs784Y9GvUzj P/oazA58wk2IVkoWma1A3RhRot36+VPgCNkpqIoRqW+b5p7bwEoSmMMr44ELuVz9UWpmSnxV2WP I02dQ7rYcx133EzhhhAaw3UDYvmF7kE8hnw525QnleQV4EWpXuB/y/oYuH2KNsrINf0yKZoWS7t n207TWFzIzcaF0XPXK6WICEZ8M7Jn3Txe9Y5oh2es8D9pJdm X-Google-Smtp-Source: AGHT+IEh0kDW4uB+ylrMI5/74JvkCPZ7udgonwZ4ItxxUZMo0b9pDqf6KVpldG1WWmcCWzYuk5xj2g== X-Received: by 2002:a05:622a:1490:b0:466:85eb:6118 with SMTP id d75a77b69052e-46734cbceaamr83933911cf.16.1733525719998; Fri, 06 Dec 2024 14:55:19 -0800 (PST) Received: from ubuntu.localdomain (pool-174-114-184-37.cpe.net.cable.rogers.com. [174.114.184.37]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-467296d4d7dsm26080871cf.34.2024.12.06.14.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 14:55:19 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Tom Rini , Tuomas Tynkkynen , Simon Glass , Patrick Rudolph , Heinrich Schuchardt , Ilias Apalodimas , Stefan Roese , =?utf-8?q?Marek_Beh=C3=BAn?= , Jonas Karlman , Wan Yee Lau , Caleb Connolly , Alexander Gendin , Masahisa Kojima , Francesco Dolcini , Max Krummenacher , Michal Simek , Sughosh Ganu , Peter Robinson Subject: [PATCH v3 02/10] sysinfo: Add sysinfo API for accessing data area Date: Fri, 6 Dec 2024 14:54:19 -0800 Message-Id: <20241206225438.13866-3-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241206225438.13866-1-raymond.mao@linaro.org> References: <20241206225438.13866-1-raymond.mao@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add interface for sysinfo to access a data area from the platform. This is useful to save/read a memory region of platform-specific data. Signed-off-by: Raymond Mao --- Changes in v2 - None. Changes in v3 - Use void pointer to avoid casting. drivers/sysinfo/sysinfo-uclass.c | 20 ++++++++++++++++++++ include/sysinfo.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/drivers/sysinfo/sysinfo-uclass.c b/drivers/sysinfo/sysinfo-uclass.c index d77d1e3ee44..3c0cd51273e 100644 --- a/drivers/sysinfo/sysinfo-uclass.c +++ b/drivers/sysinfo/sysinfo-uclass.c @@ -99,6 +99,26 @@ int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val) return ops->get_str(dev, id, size, val); } +int sysinfo_get_data(struct udevice *dev, int id, void **data, size_t *size) +{ + struct sysinfo_priv *priv; + struct sysinfo_ops *ops; + + if (!dev) + return -ENOSYS; + + priv = dev_get_uclass_priv(dev); + ops = sysinfo_get_ops(dev); + + if (!priv->detected) + return -EPERM; + + if (!ops->get_data) + return -ENOSYS; + + return ops->get_data(dev, id, data, size); +} + UCLASS_DRIVER(sysinfo) = { .id = UCLASS_SYSINFO, .name = "sysinfo", diff --git a/include/sysinfo.h b/include/sysinfo.h index 027a463dc33..cb6cf326535 100644 --- a/include/sysinfo.h +++ b/include/sysinfo.h @@ -115,6 +115,18 @@ struct sysinfo_ops { */ int (*get_str)(struct udevice *dev, int id, size_t size, char *val); + /** + * get_data() - 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 data area to be get. + * @data: Pointer to the address of the data area. + * @size: Pointer to the size of the data area. + * + * Return: 0 if OK, -ve on error. + */ + int (*get_data)(struct udevice *dev, int id, void **data, size_t *size); + /** * 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 @@ -186,6 +198,18 @@ int sysinfo_get_int(struct udevice *dev, int id, int *val); */ int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val); +/** + * sysinfo_get_data() - Get a data area from the platform. + * @dev: The sysinfo instance to gather the data. + * @id: A unique identifier for the data area to be get. + * @data: Pointer to the address of the data area. + * @size: Pointer to the size of the data area. + * + * Return: 0 if OK, -EPERM if called before sysinfo_detect(), else -ve on + * error. + */ +int sysinfo_get_data(struct udevice *dev, int id, void **data, size_t *size); + /** * sysinfo_get() - Return the sysinfo device for the sysinfo in question. * @devp: Pointer to structure to receive the sysinfo device. @@ -241,6 +265,12 @@ static inline int sysinfo_get_str(struct udevice *dev, int id, size_t size, return -ENOSYS; } +static inline int sysinfo_get_data(struct udevice *dev, int id, void **data, + size_t *size) +{ + return -ENOSYS; +} + static inline int sysinfo_get(struct udevice **devp) { return -ENOSYS; From patchwork Fri Dec 6 22:54:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Mao X-Patchwork-Id: 2019567 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=PLRVeI+P; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4mnV3j70z1yRZ for ; Sat, 7 Dec 2024 09:55:42 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AB7AD88ACB; Fri, 6 Dec 2024 23:55:40 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="PLRVeI+P"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C06F98870D; Fri, 6 Dec 2024 23:55:39 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 513E389578 for ; Fri, 6 Dec 2024 23:55:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-e398484b60bso2568698276.1 for ; Fri, 06 Dec 2024 14:55:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733525735; x=1734130535; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4uiql7sFnLdjODsO1+IMSzCjQKghuwLZZfDPhC2MrQo=; b=PLRVeI+PBIY3CI3GHJVUFdF3ecsk0EFk8VCDly2y3xvK4Sy/Sit8o8fUgzTo9bc2jW bXELZnoXUDjyufVvHf4ISAnHskj5guRbZZkL6Ifqxvjfe5gnB08j4EYxzqd/gW40yQmw fkeTx64MsxcMHxz1kfr0yUCWFTOzefWf5ztVlD3KLaKGpkqjvRiy5vVN6pC+SwWcBzlC W6BE8o/lgueg60ZsNa9KBEUg1cceDzEKqI6yTMVRYhp5BqO5SQSkOnMSpO6WnNfXXKQh Hk4Rdmftgpzab92fpjzWvIDnS9mYQ8WWchexDbemk/QX5N19eTYXdAJmeurb6WiD5Pqg e19A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733525735; x=1734130535; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4uiql7sFnLdjODsO1+IMSzCjQKghuwLZZfDPhC2MrQo=; b=a0OQEPGSIlt+hS/gGrw8jXx111qkb4H49TGNSn3IeqHPNmAkpCH+enV+rTYaLTwcsz p6ITMfhECUtw9tsbrAkO/zNrT3g/wXW+9YeqhwZg5wkw6Dt3h7GSOtFSkOiQx6SQob4X YGQnMP3CkIK7wzfuI434xFG6SwRh+aUuhXTrn1mCo7U8/OkgJ3a5NLK0f8c3kAq9ZFrq 92L/nMnGDF0cCuboEMTiLTIaUxNSd8EbX/hFKVA8sn0JUSZ45S8yOtNJLtSwrVwQGc5W 7sk0ZYLnCKBL4PkD8Z0EIXP4PsEKs9/G/1nMDWviwnCgbiFWxeevvOaCXh1tVeMdQB6b VtLQ== X-Gm-Message-State: AOJu0Yyg2Qfu694V2JdZVzLjf0BPWgOLeouOIti7IhXI5RpLrXf3vhpv akDPoXx5TOstxvUBx1+5oywsgA92Uh0xnk/6dibk05jzlrEdrwjjaQpcHqJvlNy5/sUr+XkyI3K o X-Gm-Gg: ASbGncteMCAgELOUGc3jDc2+JkmGwDPPNsX72egZev96z92UFNDWgt3JHZydS0VdqUO I+VB9s9Bt12yyUJuDiFCS0SnyNuf4VT09LNFHu0CzRIV/bfLtNRRhkhajBLKmRfGJ8N02J7SXT5 5xQ1NuiNMsapjaEdOvwpgO1iBa6VcWPqLlJ8QegJLjVBCvFmhpMoJw04ugnDEn5gayFLgAI55r6 cKCf/3heV8W/ntQcVPKktB2Yiq4iVm2YL0Yk9Hs8llUoZ3R98PNFPJieRY8MCUrakdQG/zQzVFt U8apqWvxZEE+v+KE5zUj5joSdCdHg9OY/fza4g6ZhTgYkUJ8 X-Google-Smtp-Source: AGHT+IFqlH9nlrvrDTokJDjxLTQ+cUar4trkId36Zgt/BGcCJ1jmLfwl4LF0y/dj5xETQGDqqEtScA== X-Received: by 2002:a05:6902:70a:b0:e38:9d20:2583 with SMTP id 3f1490d57ef6-e3a0b72d31bmr5347642276.32.1733525735023; Fri, 06 Dec 2024 14:55:35 -0800 (PST) Received: from ubuntu.localdomain (pool-174-114-184-37.cpe.net.cable.rogers.com. [174.114.184.37]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-467296d4d7dsm26080871cf.34.2024.12.06.14.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 14:55:34 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Tom Rini , Tuomas Tynkkynen , Simon Glass , Patrick Rudolph , Heinrich Schuchardt , Ilias Apalodimas , Stefan Roese , =?utf-8?q?Marek_Beh=C3=BAn?= , Kever Yang , Alexander Gendin , Caleb Connolly , Jonas Karlman , Wan Yee Lau , Masahisa Kojima , Francesco Dolcini , Michal Simek , Max Krummenacher , Sughosh Ganu , Peter Robinson Subject: [PATCH v3 03/10] test/dm: add sandbox test for sysinfo_get_data Date: Fri, 6 Dec 2024 14:54:20 -0800 Message-Id: <20241206225438.13866-4-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241206225438.13866-1-raymond.mao@linaro.org> References: <20241206225438.13866-1-raymond.mao@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Adding sysinfo_get_data into sandbox ut test dm_test_sysinfo. Signed-off-by: Raymond Mao --- Changes in v3 - Initial patch. drivers/sysinfo/sandbox.c | 19 +++++++++++++++++++ drivers/sysinfo/sandbox.h | 1 + test/dm/sysinfo.c | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/drivers/sysinfo/sandbox.c b/drivers/sysinfo/sandbox.c index d39720958f0..af54fe87596 100644 --- a/drivers/sysinfo/sandbox.c +++ b/drivers/sysinfo/sandbox.c @@ -13,6 +13,7 @@ struct sysinfo_sandbox_priv { bool called_detect; int test_i1; int test_i2; + u32 test_data[2]; }; char vacation_spots[][64] = {"R'lyeh", "Dreamlands", "Plateau of Leng", @@ -24,6 +25,8 @@ int sysinfo_sandbox_detect(struct udevice *dev) priv->called_detect = true; priv->test_i2 = 100; + priv->test_data[0] = 0xabcdabcd; + priv->test_data[1] = 0xdeadbeef; return 0; } @@ -79,6 +82,21 @@ int sysinfo_sandbox_get_str(struct udevice *dev, int id, size_t size, char *val) return -ENOENT; } +int sysinfo_sandbox_get_data(struct udevice *dev, int id, void **buf, + size_t *size) +{ + struct sysinfo_sandbox_priv *priv = dev_get_priv(dev); + + switch (id) { + case DATA_TEST: + *buf = priv->test_data; + *size = sizeof(priv->test_data); + return 0; + } + + return -ENOENT; +} + static const struct udevice_id sysinfo_sandbox_ids[] = { { .compatible = "sandbox,sysinfo-sandbox" }, { /* sentinel */ } @@ -89,6 +107,7 @@ static const struct sysinfo_ops sysinfo_sandbox_ops = { .get_bool = sysinfo_sandbox_get_bool, .get_int = sysinfo_sandbox_get_int, .get_str = sysinfo_sandbox_get_str, + .get_data = sysinfo_sandbox_get_data, }; int sysinfo_sandbox_probe(struct udevice *dev) diff --git a/drivers/sysinfo/sandbox.h b/drivers/sysinfo/sandbox.h index a7cbac0ce18..47b7f5ef9fe 100644 --- a/drivers/sysinfo/sandbox.h +++ b/drivers/sysinfo/sandbox.h @@ -9,4 +9,5 @@ enum { INT_TEST1, INT_TEST2, STR_VACATIONSPOT, + DATA_TEST, }; diff --git a/test/dm/sysinfo.c b/test/dm/sysinfo.c index 6c0d2d7e4df..14ebe6b42e7 100644 --- a/test/dm/sysinfo.c +++ b/test/dm/sysinfo.c @@ -19,6 +19,9 @@ static int dm_test_sysinfo(struct unit_test_state *uts) bool called_detect = false; char str[64]; int i; + void *data = NULL; + size_t data_size = 0; + u32 gdata[] = {0xabcdabcd, 0xdeadbeef}; ut_assertok(sysinfo_get(&sysinfo)); ut_assert(sysinfo); @@ -57,6 +60,9 @@ static int dm_test_sysinfo(struct unit_test_state *uts) str)); ut_assertok(strcmp(str, "Yuggoth")); + ut_assertok(sysinfo_get_data(sysinfo, DATA_TEST, &data, &data_size)); + ut_assertok(memcmp(gdata, data, data_size)); + return 0; } DM_TEST(dm_test_sysinfo, UTF_SCAN_PDATA | UTF_SCAN_FDT); From patchwork Fri Dec 6 22:54:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Mao X-Patchwork-Id: 2019568 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=dBeK8H7X; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4mnm6gZTz1yRZ for ; Sat, 7 Dec 2024 09:55:56 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1ABF78963C; Fri, 6 Dec 2024 23:55:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="dBeK8H7X"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 873F089737; Fri, 6 Dec 2024 23:55:53 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 047C089578 for ; Fri, 6 Dec 2024 23:55:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-qt1-x835.google.com with SMTP id d75a77b69052e-466847440a6so15338121cf.2 for ; Fri, 06 Dec 2024 14:55:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733525749; x=1734130549; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2vygsRAybD5K5leo/xfheOgtfaQI1PL6VMt8n4UlKKI=; b=dBeK8H7X61h/tFr8W5qV0uKmvr6OicW2LHWrSFAUSqemJKH6KrWVZSsMXm0Venhafr sjoRk+2GdiH7+Ak5ArsLsxxvFCPnF5AHymdcEv2IwDDYQbbIoYKu5450OOijIwDu/Lnz 3PZb1wOkSqtr5m9hr+IkqMT9MZn0D/LoJFh4xK/5QmK9wwJ8TNhEtnham2mcwzakBztr Blz8MlqdFL2cT4YOBu3QY+/u0qUpBTjhGFm7NdFA+UbWpIsaRSB01LZ8LpBI8wOXPvFQ XLN/X3vBUoqQnhu3ew4GQ0FwASGsicwp0XT9aiAaAcIzWeXsY+JA7sIGdLU0b062hxSf blvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733525749; x=1734130549; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2vygsRAybD5K5leo/xfheOgtfaQI1PL6VMt8n4UlKKI=; b=VYSfnztZ91U8by3W/SnoLFLuo93M28ZYhLNWpnE7j7eOMEgOhKdEAiDAu68tObEjr4 sTAAJQjP30mxcZ1vo8tr0agiu15WLe+0PVaNAZfZJxFEQk6Eq3VIaukuH4DFVX97I8TL PuKnOCYHFgxd8x9kNfGWsFgSXCNqRXbNv5PQ8x1dUPOeO3aOuclEQ6sDYqyj5o/DJ/lA GWwpXK+yuh8BnAfZxMxcyvU9tENppi8wIjsTzokHhP8pIr4gkZWWLr4oqdzD08NOKuGj ZswjX3xt9rLGbaXTFK0+widtF8boFrCQS5l9HCJZd48u335p6ZAsWoq3DGfWYJVu5nNs 62Rw== X-Gm-Message-State: AOJu0YzVnMVbnJrCsWG7upI1PWedKNH+PkWsDVuZP6iyIdgrUCQXrHyS WGHmCtKBgcsfXDSyEKv3CiTHkhKw0LPKyVRQB1xCvio7YTv1xg/pjJ/oUO3BpcfyTCANKKuX1zJ a X-Gm-Gg: ASbGncvMuV8nfwpN1/Hc/DA4evPPkKpdUCceeSFgOmvdCQPjvkQboq9WM7/006hQe0p qLmrFZL/Zn9JpPlYSog2PvP3RRk3zB/KflNDUXSjkXnyJoOAXd16efIbow6q4YPXKUjSPXv+THQ +x5pz3gtF3h6ej59Ywx9pyejQVOsb5C4fIgFTT7Kwq+qjEZuVSkSEUcmHc2+nHyYndId5/Hfik+ UATzqjDqdsps+5X2Kk53KTIn4z4ZvXZ9opzJqiUn5kiYeOKbuxyIAXySYHV0z/97zTu4XsASzTi MvkSJyeAd9+kShjfr5zl0mY8EvpNZWS68hMiRfNaPHiErxUJ X-Google-Smtp-Source: AGHT+IEvWc0n6+0q2Oln7ZRpAuDp15+DGO8sWCIEgfYiQZlzwLkdWqiB+OM4GA+vHHdLdYLGJFsPMA== X-Received: by 2002:a05:622a:1183:b0:464:94cf:98a0 with SMTP id d75a77b69052e-46734f779cdmr65086551cf.34.1733525749372; Fri, 06 Dec 2024 14:55:49 -0800 (PST) Received: from ubuntu.localdomain (pool-174-114-184-37.cpe.net.cable.rogers.com. [174.114.184.37]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-467296d4d7dsm26080871cf.34.2024.12.06.14.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 14:55:48 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Tom Rini , Tuomas Tynkkynen , Simon Glass , Patrick Rudolph , Heinrich Schuchardt , Ilias Apalodimas , Stefan Roese , =?utf-8?q?Marek_Beh=C3=BAn?= , Jonas Karlman , Caleb Connolly , Wan Yee Lau , Alexander Gendin , Masahisa Kojima , Francesco Dolcini , Max Krummenacher , Michal Simek , Sughosh Ganu , Peter Robinson Subject: [PATCH v3 04/10] sysinfo: Add sysinfo driver and data structure for smbios Date: Fri, 6 Dec 2024 14:54:21 -0800 Message-Id: <20241206225438.13866-5-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241206225438.13866-1-raymond.mao@linaro.org> References: <20241206225438.13866-1-raymond.mao@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add sysinfo driver to retrieve smbios information (Type 4 and 7). So that the smbios library can use it for getting values from the hardware platform instead of device tree. Signed-off-by: Raymond Mao --- Changes in v2 - Move the changes to smbios.c instead of creating new file. - Move the headfile to include dir. - Combine with #6(v1) patch. - Clean-up the private data structures. - Clean-up the operations of the strings and common values. Changes in v3 - Use void pointer to avoid casting. - Rebased on the changes of SYSID_ drivers/sysinfo/smbios.c | 228 +++++++++++++++++++++++++++++++++++++++ include/smbios.h | 60 +++++++++++ include/smbios_plat.h | 79 ++++++++++++++ include/sysinfo.h | 95 +++++++++++++++- 4 files changed, 461 insertions(+), 1 deletion(-) create mode 100644 include/smbios_plat.h diff --git a/drivers/sysinfo/smbios.c b/drivers/sysinfo/smbios.c index a7ac8e3f072..99104274f72 100644 --- a/drivers/sysinfo/smbios.c +++ b/drivers/sysinfo/smbios.c @@ -5,14 +5,240 @@ */ #include +#include #include +/* platform information storage */ +struct processor_info processor_info; +struct cache_info cache_info[SYSINFO_CACHE_LVL_MAX]; +struct sysinfo_plat sysinfo_smbios_p = { + /* Processor Information */ + .processor = &processor_info, + /* Cache Information */ + .cache = &cache_info[0], +}; + +/* structure for smbios private data storage */ +struct sysinfo_plat_priv { + struct processor_info *t4; + struct smbios_type7 t7[SYSINFO_CACHE_LVL_MAX]; + u16 cache_handles[SYSINFO_CACHE_LVL_MAX]; + u8 cache_level; +}; + +static void smbios_cache_info_dump(struct smbios_type7 *cache_info) +{ + log_debug("SMBIOS Type 7 (Cache Information):\n"); + log_debug("Cache Configuration: 0x%04x\n", cache_info->config.data); + log_debug("Maximum Cache Size: %u KB\n", cache_info->max_size.data); + log_debug("Installed Size: %u KB\n", cache_info->inst_size.data); + log_debug("Supported SRAM Type: 0x%04x\n", + cache_info->supp_sram_type.data); + log_debug("Current SRAM Type: 0x%04x\n", + cache_info->curr_sram_type.data); + log_debug("Cache Speed: %u\n", cache_info->speed); + log_debug("Error Correction Type: %u\n", cache_info->err_corr_type); + log_debug("System Cache Type: %u\n", cache_info->sys_cache_type); + log_debug("Associativity: %u\n", cache_info->associativity); + log_debug("Maximum Cache Size 2: %u KB\n", cache_info->max_size2.data); + log_debug("Installed Cache Size 2: %u KB\n", + cache_info->inst_size2.data); +} + +/* weak function for the platforms not yet supported */ +__weak int sysinfo_get_cache_info(u8 level, struct cache_info *cache_info) +{ + return -ENOSYS; +} + +__weak int sysinfo_get_processor_info(struct processor_info *pinfo) +{ + return -ENOSYS; +} + +void sysinfo_cache_info_default(struct cache_info *ci) +{ + memset(ci, 0, sizeof(*ci)); + ci->config.data = SMBIOS_CACHE_LOCATE_UNKNOWN | SMBIOS_CACHE_OP_UND; + ci->supp_sram_type.fields.unknown = 1; + ci->curr_sram_type.fields.unknown = 1; + ci->speed = SMBIOS_CACHE_SPEED_UNKNOWN; + ci->err_corr_type = SMBIOS_CACHE_ERRCORR_UNKNOWN; + ci->cache_type = SMBIOS_CACHE_SYSCACHE_TYPE_UNKNOWN; +} + +static int sysinfo_plat_detect(struct udevice *dev) +{ + return 0; +} + +static int sysinfo_plat_get_str(struct udevice *dev, int id, + size_t size, char *val) +{ + struct sysinfo_plat_priv *priv = dev_get_priv(dev); + const char *str = NULL; + + switch (id) { + case SYSID_SM_PROCESSOR_MANUFACT: + str = priv->t4->manufacturer; + break; + default: + break; + } + + if (!str) + return -ENOSYS; + + strlcpy(val, str, size); + + return 0; +} + +static int sysinfo_plat_get_int(struct udevice *dev, int id, int *val) +{ + struct sysinfo_plat_priv *priv = dev_get_priv(dev); + u8 i; + + if (id >= SYSID_SM_CACHE_INFO_START && + id <= SYSID_SM_CACHE_INFO_END) { + /* For smbios type 7 */ + for (i = 0; i < priv->cache_level; i++) { + switch (id - i) { + case SYSID_SM_CACHE_MAX_SIZE: + *val = priv->t7[i].max_size.data; + return 0; + case SYSID_SM_CACHE_INST_SIZE: + *val = priv->t7[i].inst_size.data; + return 0; + case SYSID_SM_CACHE_SCACHE_TYPE: + *val = priv->t7[i].sys_cache_type; + return 0; + case SYSID_SM_CACHE_ASSOC: + *val = priv->t7[i].associativity; + return 0; + case SYSID_SM_CACHE_MAX_SIZE2: + *val = priv->t7[i].max_size2.data; + return 0; + case SYSID_SM_CACHE_INST_SIZE2: + *val = priv->t7[i].inst_size2.data; + return 0; + default: + break; + } + } + return -ENOSYS; + } + + switch (id) { + case SYSID_SM_PROCESSOR_CORE_CNT: + *val = priv->t4->core_count; + break; + case SYSID_SM_PROCESSOR_CORE_EN: + *val = priv->t4->core_enabled; + break; + case SYSID_SM_PROCESSOR_CHARA: + *val = priv->t4->characteristics; + break; + case SYSID_SM_CACHE_LEVEL: + if (!priv->cache_level) /* No cache detected */ + return -ENOSYS; + *val = priv->cache_level - 1; + break; + default: + return -ENOSYS; + } + + return 0; +} + +static int sysinfo_plat_get_data(struct udevice *dev, int id, void **buf, + size_t *size) +{ + struct sysinfo_plat_priv *priv = dev_get_priv(dev); + + switch (id) { + case SYSID_SM_PROCESSOR_ID: + *buf = priv->t4->id; + *size = sizeof(priv->t4->id); + break; + case SYSID_SM_CACHE_HANDLE: + *buf = &priv->cache_handles[0]; + *size = sizeof(priv->cache_handles); + break; + default: + return -EOPNOTSUPP; + } + return 0; +} + +static int sysinfo_plat_probe(struct udevice *dev) +{ + struct sysinfo_plat_priv *priv = dev_get_priv(dev); + struct sysinfo_plat *plat = &sysinfo_smbios_p; + u8 level; + + if (!sysinfo_get_processor_info(plat->processor)) + priv->t4 = plat->processor; + + for (level = 0; level < SYSINFO_CACHE_LVL_MAX; level++) { + struct cache_info *pcache = plat->cache + level; + + if (sysinfo_get_cache_info(level, pcache)) + break; /* no more levels */ + + /* + * Fill in the SMBIOS type 7 structure, + * skip the header members (type, length, handle), + * and the ones in DT smbios node. + */ + priv->t7[level].sys_cache_type = pcache->cache_type; + priv->t7[level].associativity = pcache->associativity; + + if (pcache->max_size > SMBIOS_CACHE_SIZE_EXT_KB) { + priv->t7[level].max_size.data = 0xFFFF; + priv->t7[level].max_size2.fields.size = + pcache->max_size / 64; + priv->t7[level].max_size2.fields.granu = + SMBIOS_CACHE_GRANU_64K; + } else { + priv->t7[level].max_size.fields.size = pcache->max_size; + priv->t7[level].max_size.fields.granu = + SMBIOS_CACHE_GRANU_1K; + priv->t7[level].max_size2.data = 0; + } + if (pcache->inst_size > SMBIOS_CACHE_SIZE_EXT_KB) { + priv->t7[level].inst_size.data = 0xFFFF; + priv->t7[level].inst_size2.fields.size = + pcache->inst_size / 64; + priv->t7[level].inst_size2.fields.granu = + SMBIOS_CACHE_GRANU_64K; + } else { + priv->t7[level].inst_size.fields.size = + pcache->inst_size; + priv->t7[level].inst_size.fields.granu = + SMBIOS_CACHE_GRANU_1K; + priv->t7[level].inst_size2.data = 0; + } + smbios_cache_info_dump(&priv->t7[level]); + } + if (!level) /* no cache detected */ + return -ENOSYS; + + priv->cache_level = level; + + return 0; +} + static const struct udevice_id sysinfo_smbios_ids[] = { { .compatible = "u-boot,sysinfo-smbios" }, { /* sentinel */ } }; static const struct sysinfo_ops sysinfo_smbios_ops = { + .detect = sysinfo_plat_detect, + .get_str = sysinfo_plat_get_str, + .get_int = sysinfo_plat_get_int, + .get_data = sysinfo_plat_get_data, }; U_BOOT_DRIVER(sysinfo_smbios) = { @@ -20,4 +246,6 @@ U_BOOT_DRIVER(sysinfo_smbios) = { .id = UCLASS_SYSINFO, .of_match = sysinfo_smbios_ids, .ops = &sysinfo_smbios_ops, + .priv_auto = sizeof(struct sysinfo_plat_priv), + .probe = sysinfo_plat_probe, }; diff --git a/include/smbios.h b/include/smbios.h index 78fd14d881b..cb4b3e08b3a 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -187,6 +187,66 @@ struct __packed smbios_type4 { char eos[SMBIOS_STRUCT_EOS_BYTES]; }; +union cache_config { + struct { + u16 level:3; + u16 bsocketed:1; + u16 rsvd0:1; + u16 locate:2; + u16 benabled:1; + u16 opmode:2; + u16 rsvd1:6; + } fields; + u16 data; +}; + +union cache_size_word { + struct { + u16 size:15; + u16 granu:1; + } fields; + u16 data; +}; + +union cache_size_dword { + struct { + u32 size:31; + u32 granu:1; + } fields; + u32 data; +}; + +union cache_sram_type { + struct { + u16 other:1; + u16 unknown:1; + u16 nonburst:1; + u16 burst:1; + u16 plburst:1; + u16 sync:1; + u16 async:1; + u16 rsvd:9; + } fields; + u16 data; +}; + +struct __packed smbios_type7 { + struct smbios_header hdr; + u8 socket_design; + union cache_config config; + union cache_size_word max_size; + union cache_size_word inst_size; + union cache_sram_type supp_sram_type; + union cache_sram_type curr_sram_type; + u8 speed; + u8 err_corr_type; + u8 sys_cache_type; + u8 associativity; + union cache_size_dword max_size2; + union cache_size_dword inst_size2; + char eos[SMBIOS_STRUCT_EOS_BYTES]; +}; + struct __packed smbios_type32 { u8 type; u8 length; diff --git a/include/smbios_plat.h b/include/smbios_plat.h new file mode 100644 index 00000000000..70089d5a2ba --- /dev/null +++ b/include/smbios_plat.h @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2024 Linaro Limited + * Author: Raymond Mao + */ +#ifndef __SMBIOS_PLAT_H +#define __SMBIOS_PLAT_H + +#include + +struct cache_info { + union cache_config config; + union cache_sram_type supp_sram_type; + union cache_sram_type curr_sram_type; + u32 line_size; + u32 associativity; + u32 max_size; + u32 inst_size; + u8 cache_type; + u8 speed; + u8 err_corr_type; + char *socket_design; +}; + +struct processor_info { + u32 id[2]; + u16 ext_clock; + u16 max_speed; + u16 curr_speed; + u16 characteristics; + u16 family2; + u16 core_count2; + u16 core_enabled2; + u16 thread_count2; + u16 thread_enabled; + u8 type; + u8 family; + u8 voltage; + u8 status; + u8 upgrade; + u8 core_count; + u8 core_enabled; + u8 thread_count; + char *socket_design; + char *manufacturer; + char *version; + char *sn; + char *asset_tag; + char *pn; +}; + +struct sysinfo_plat { + struct processor_info *processor; + struct cache_info *cache; + /* add other sysinfo structure here */ +}; + +#if defined CONFIG_SYSINFO_SMBIOS +int sysinfo_get_cache_info(u8 level, struct cache_info *cache_info); +void sysinfo_cache_info_default(struct cache_info *ci); +int sysinfo_get_processor_info(struct processor_info *pinfo); +#else +static inline int sysinfo_get_cache_info(u8 level, + struct cache_info *cache_info) +{ + return -ENOSYS; +} + +static inline void sysinfo_cache_info_default(struct cache_info *ci) +{ +} + +static inline int sysinfo_get_processor_info(struct processor_info *pinfo) +{ + return -ENOSYS; +} +#endif + +#endif /* __SMBIOS_PLAT_H */ diff --git a/include/sysinfo.h b/include/sysinfo.h index cb6cf326535..ba2ac273e8e 100644 --- a/include/sysinfo.h +++ b/include/sysinfo.h @@ -11,6 +11,8 @@ struct udevice; +#define SYSINFO_CACHE_LVL_MAX 3 + /* * This uclass encapsulates hardware methods to gather information about a * sysinfo or a specific device such as hard-wired GPIOs on GPIO expanders, @@ -42,18 +44,109 @@ struct udevice; enum sysinfo_id { SYSID_NONE, - /* For SMBIOS tables */ + /* BIOS Information (Type 0) */ + SYSID_SM_BIOS_VENDOR, + SYSID_SM_BIOS_VER, + SYSID_SM_BIOS_REL_DATE, + + /* System Information (Type 1) */ SYSID_SM_SYSTEM_MANUFACTURER, SYSID_SM_SYSTEM_PRODUCT, SYSID_SM_SYSTEM_VERSION, SYSID_SM_SYSTEM_SERIAL, + SYSID_SM_SYSTEM_WAKEUP, SYSID_SM_SYSTEM_SKU, SYSID_SM_SYSTEM_FAMILY, + + /* Baseboard (or Module) Information (Type 2) */ SYSID_SM_BASEBOARD_MANUFACTURER, SYSID_SM_BASEBOARD_PRODUCT, SYSID_SM_BASEBOARD_VERSION, SYSID_SM_BASEBOARD_SERIAL, SYSID_SM_BASEBOARD_ASSET_TAG, + SYSID_SM_BASEBOARD_FEATURE, + SYSID_SM_BASEBOARD_CHASSIS_LOCAT, + SYSID_SM_BASEBOARD_TYPE, + SYSID_SM_BASEBOARD_OBJS_NUM, + SYSID_SM_BASEBOARD_OBJS_HANDLE, + + /* System Enclosure or Chassis (Type 3) */ + SYSID_SM_ENCLOSURE_MANUFACTURER, + SYSID_SM_ENCLOSURE_VERSION, + SYSID_SM_ENCLOSURE_SERIAL, + SYSID_SM_ENCLOSURE_ASSET_TAG, + SYSID_SM_ENCLOSURE_TYPE, + SYSID_SM_ENCLOSURE_BOOTUP, + SYSID_SM_ENCLOSURE_POW, + SYSID_SM_ENCLOSURE_THERMAL, + SYSID_SM_ENCLOSURE_SECURITY, + SYSID_SM_ENCLOSURE_OEM, + SYSID_SM_ENCLOSURE_HEIGHT, + SYSID_SM_ENCLOSURE_POWCORE_NUM, + SYSID_SM_ENCLOSURE_ELEMENT_CNT, + SYSID_SM_ENCLOSURE_ELEMENT_LEN, + SYSID_SM_ENCLOSURE_ELEMENTS, + SYSID_SM_ENCLOSURE_SKU, + + /* Processor Information (Type 4) */ + SYSID_SM_PROCESSOR_SOCKET, + SYSID_SM_PROCESSOR_TYPE, + SYSID_SM_PROCESSOR_MANUFACT, + SYSID_SM_PROCESSOR_ID, + SYSID_SM_PROCESSOR_VERSION, + SYSID_SM_PROCESSOR_VOLTAGE, + SYSID_SM_PROCESSOR_EXT_CLOCK, + SYSID_SM_PROCESSOR_MAX_SPEED, + SYSID_SM_PROCESSOR_CUR_SPEED, + SYSID_SM_PROCESSOR_STATUS, + SYSID_SM_PROCESSOR_UPGRADE, + SYSID_SM_PROCESSOR_SN, + SYSID_SM_PROCESSOR_ASSET_TAG, + SYSID_SM_PROCESSOR_PN, + SYSID_SM_PROCESSOR_CORE_CNT, + SYSID_SM_PROCESSOR_CORE_EN, + SYSID_SM_PROCESSOR_THREAD_CNT, + SYSID_SM_PROCESSOR_CHARA, + SYSID_SM_PROCESSOR_FAMILY, + SYSID_SM_PROCESSOR_FAMILY2, + SYSID_SM_PROCESSOR_CORE_CNT2, + SYSID_SM_PROCESSOR_CORE_EN2, + SYSID_SM_PROCESSOR_THREAD_CNT2, + SYSID_SM_PROCESSOR_THREAD_EN, + + /* + * Cache Information (Type 7) + * Each of the id should reserve space for up to + * SYSINFO_CACHE_LVL_MAX levels of cache + */ + SYSID_SM_CACHE_LEVEL, + SYSID_SM_CACHE_HANDLE, + SYSID_SM_CACHE_INFO_START, + SYSID_SM_CACHE_SOCKET = SYSID_SM_CACHE_INFO_START, + SYSID_SM_CACHE_CONFIG = + SYSID_SM_CACHE_SOCKET + SYSINFO_CACHE_LVL_MAX, + SYSID_SM_CACHE_MAX_SIZE = + SYSID_SM_CACHE_CONFIG + SYSINFO_CACHE_LVL_MAX, + SYSID_SM_CACHE_INST_SIZE = + SYSID_SM_CACHE_MAX_SIZE + SYSINFO_CACHE_LVL_MAX, + SYSID_SM_CACHE_SUPSRAM_TYPE = + SYSID_SM_CACHE_INST_SIZE + SYSINFO_CACHE_LVL_MAX, + SYSID_SM_CACHE_CURSRAM_TYPE = + SYSID_SM_CACHE_SUPSRAM_TYPE + SYSINFO_CACHE_LVL_MAX, + SYSID_SM_CACHE_SPEED = + SYSID_SM_CACHE_CURSRAM_TYPE + SYSINFO_CACHE_LVL_MAX, + SYSID_SM_CACHE_ERRCOR_TYPE = + SYSID_SM_CACHE_SPEED + SYSINFO_CACHE_LVL_MAX, + SYSID_SM_CACHE_SCACHE_TYPE = + SYSID_SM_CACHE_ERRCOR_TYPE + SYSINFO_CACHE_LVL_MAX, + SYSID_SM_CACHE_ASSOC = + SYSID_SM_CACHE_SCACHE_TYPE + SYSINFO_CACHE_LVL_MAX, + SYSID_SM_CACHE_MAX_SIZE2 = + SYSID_SM_CACHE_ASSOC + SYSINFO_CACHE_LVL_MAX, + SYSID_SM_CACHE_INST_SIZE2 = + SYSID_SM_CACHE_MAX_SIZE2 + SYSINFO_CACHE_LVL_MAX, + SYSID_SM_CACHE_INFO_END = + SYSID_SM_CACHE_INST_SIZE2 + SYSINFO_CACHE_LVL_MAX - 1, /* For show_board_info() */ SYSID_BOARD_MODEL, From patchwork Fri Dec 6 22:54:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Mao X-Patchwork-Id: 2019569 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=sHVxnjQd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4mp10DZlz1yQw for ; Sat, 7 Dec 2024 09:56:09 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2F0E088ACB; Fri, 6 Dec 2024 23:56:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="sHVxnjQd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E46E18870D; Fri, 6 Dec 2024 23:56:06 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5DFF989434 for ; Fri, 6 Dec 2024 23:56:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-qt1-x829.google.com with SMTP id d75a77b69052e-4668d12b629so22382271cf.2 for ; Fri, 06 Dec 2024 14:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733525763; x=1734130563; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O+H896CW6tvGSIw32RI2JpNxzOWuJ3RTCbjL6vdkxus=; b=sHVxnjQdtLzaAHNl8Ccbl/FawhyvZp6YiKVTT0fFzi9S3Ytc4XfTkCvPvnJbKAryvI DBs5yVbqFD/LIyq7eibcVmp1jpsdM5fVSOBUOCZTf4CtpF5nbSCukC1kGdWHSLsKn40g aUDUAgpSKhUHFmvX0Gk+wAYRUPA9qvmJzWOJV+m5XwrZZI9IWbPb6kzcSoCGyZVDmHrA tFtYNze5JvfFv79XQyJqUBi8Tx5pRtNb/Yx7p0gSDOwC+fMmkJR1FC/KVBAclQ+BdWEZ fuPOUYiPw/l/0+rZwQrcKdYO6kJAiG/6DtG2ZwNeE9HVBlGRud/jG0qAFY+tq/WltXhS cfpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733525763; x=1734130563; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O+H896CW6tvGSIw32RI2JpNxzOWuJ3RTCbjL6vdkxus=; b=lC/VbEcLNi2SA2qZlb4BNJumOdjs4d/XQId4Hmw89r8pTt7wdZR9gbQkR4fzfU6e7P 6L8ZVx2H+g1SrcOi8umN8FZ2Ox6Y1s/bLk1qxL81DSrbdqs22KQ3HjKLvodoZNnmXL9N QZHbDh312MPSIXUyO0nuY1wPsWg27YQl+rxEilauuAq+lE7suZ8zhcRK8e3+nuYkXQeH HUp4QUx0X1yZcr7Vb6ln63mVoveOXxiQhuZTfzvbs9DDAVuHterOABH/aBZJsB8szddz k+UDvAXttJYsU0P4eT/nZxpj83lGv0bkcL/VJiKl71rH8DgCbX7Kad6QHBchE2zwvHgF mFew== X-Gm-Message-State: AOJu0Yz9DRZBr/3lvWP6npzFjMQ2FUjQfjkHlyr2Lpau9cyG3z0CPDMz hyVz+YI8UK8e4C1r/gR+mTukzjhbHN2mA1QLItdKIVRuBHZwy0TULV3hadYbYAGuEi0f0B7+e4G Y X-Gm-Gg: ASbGncteIM8ZCXM4cCrWqhNS37V5fu6tGT35amKv1Y44quAWLJLaqCs4OFoWopDrKJD Iv++0DCltPCZ/veiIPNJ1pwMOjtIQyQFVL1KiHDCWKrHgSi8nsgXXZ5z4ZoYynwg7uGOnZF+A0e T/fVv59axTnuv/Rcy80YY2yeFpv0NIxPv7UstFm0uMKGPwDDX2BIF97IIvpmE0jnFZFKP7PUr7m D5XLjQRc1EjPQuQM1LE5l1oHIIeN2AcqfqR7FoXi+TRPbatjQYLB/g3xPRQl8/r4vDQZblX8ybz 0tJRju+LMHeFYujXWQr3CJk8riV38Z5b9vvkbZqca0ksGiVB X-Google-Smtp-Source: AGHT+IHpcDZgPMMJUq+2CfbctFrRIlajqT80v4Uqu3rw5a5G7QscIGeCavG27lvQpGaBt3obWJLLXQ== X-Received: by 2002:a05:622a:8e1a:b0:467:4570:bca8 with SMTP id d75a77b69052e-4674570c03dmr13210211cf.53.1733525762940; Fri, 06 Dec 2024 14:56:02 -0800 (PST) Received: from ubuntu.localdomain (pool-174-114-184-37.cpe.net.cable.rogers.com. [174.114.184.37]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-467296d4d7dsm26080871cf.34.2024.12.06.14.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 14:56:02 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Tom Rini , Tuomas Tynkkynen , Simon Glass , Patrick Rudolph , Heinrich Schuchardt , Ilias Apalodimas , Stefan Roese , =?utf-8?q?Marek_Beh=C3=BAn?= , Jonas Karlman , Wan Yee Lau , Alexander Gendin , Caleb Connolly , Masahisa Kojima , Max Krummenacher , Francesco Dolcini , Michal Simek , Sughosh Ganu , Peter Robinson Subject: [PATCH v3 05/10] smbios: Refactor smbios library Date: Fri, 6 Dec 2024 14:54:22 -0800 Message-Id: <20241206225438.13866-6-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241206225438.13866-1-raymond.mao@linaro.org> References: <20241206225438.13866-1-raymond.mao@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Current smbios library does not fully match to the specification. It hardcodes values instead of exposing values from the device. It does not reserve the space to support dynamic length for contained object handles or elements and misses the handling of a few of fields. The refactoring of this patch includes: 1. Expose values from device via sysinfo interface. 2. Replace smbios_add_prop with smbios_add_prop_si to allow getting string values from sysinfo. 3. Add smbios_get_val_si to get values from sysinfo or device tree. 4. Use sysinfo_get_data to get data area. 5. Reserve the space of contained object handles and elements. 6. Miscellaneous fixes in smbios. Signed-off-by: Raymond Mao --- Changes in v2 - Combine with #7(v1) patch. - Move the changes of cmd/smbios.c to a separated patch. - Refactor smbios_get_val_si to get values from dt when values are not available from sysinfo driver. - Miscellaneous refactoring. Changes in v3 - Allows smbios_get_val_si to fallback to the values from device tree. - Add GENERATE_SMBIOS_TABLE_VERBOSE for the detail information. - Rebased on the changes of SYSID_ - Split the changes for detailed information of Type 3, 4 and 7 to patch #06. include/smbios.h | 14 +++- lib/Kconfig | 6 ++ lib/smbios.c | 202 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 176 insertions(+), 46 deletions(-) diff --git a/include/smbios.h b/include/smbios.h index cb4b3e08b3a..18f568f9b0d 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -122,6 +122,8 @@ struct __packed smbios_type1 { char eos[SMBIOS_STRUCT_EOS_BYTES]; }; +#define SMBIOS_TYPE2_CON_OBJ_HANDLE_SIZE sizeof(u16) + struct __packed smbios_type2 { struct smbios_header hdr; u8 manufacturer; @@ -134,6 +136,10 @@ struct __packed smbios_type2 { u16 chassis_handle; u8 board_type; u8 number_contained_objects; + /* + * Dynamic bytes will be inserted here to store the objects. + * length is equal to 'number_contained_objects'. + */ char eos[SMBIOS_STRUCT_EOS_BYTES]; }; @@ -153,12 +159,17 @@ struct __packed smbios_type3 { u8 number_of_power_cords; u8 element_count; u8 element_record_length; + /* + * Dynamic bytes will be inserted here to store the elements. + * length is equal to 'element_record_length' * 'element_record_length' + */ + u8 sku_number; char eos[SMBIOS_STRUCT_EOS_BYTES]; }; struct __packed smbios_type4 { struct smbios_header hdr; - u8 socket_designation; + u8 socket_design; u8 processor_type; u8 processor_family; u8 processor_manufacturer; @@ -184,6 +195,7 @@ struct __packed smbios_type4 { u16 core_count2; u16 core_enabled2; u16 thread_count2; + u16 thread_enabled; char eos[SMBIOS_STRUCT_EOS_BYTES]; }; diff --git a/lib/Kconfig b/lib/Kconfig index 0b089814d14..7ac58125f94 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1038,6 +1038,12 @@ config GENERATE_SMBIOS_TABLE See also SYSINFO_SMBIOS which allows SMBIOS values to be provided in the devicetree. +config GENERATE_SMBIOS_TABLE_VERBOSE + bool "Generate a verbose SMBIOS (System Management BIOS) table" + depends on GENERATE_SMBIOS_TABLE + help + Provide verbose SMBIOS information. + endmenu config LIB_RATIONAL diff --git a/lib/smbios.c b/lib/smbios.c index 1dd564a1762..e8089e91523 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -206,6 +206,43 @@ void get_str_from_dt(const struct map_sysinfo *nprop, char *str, size_t size) } } +/** + * smbios_get_val_si() - Get value from the devicetree or sysinfo + * + * @ctx: context of SMBIOS + * @prop: property to read + * @sysinfo_id: unique identifier for the value to be read + * @val_def: Default value + * Return: Valid value from sysinfo or device tree, otherwise val_def. + */ +static int smbios_get_val_si(struct smbios_ctx * __maybe_unused ctx, + const char * __maybe_unused prop, + int __maybe_unused sysinfo_id, int val_def) +{ +#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE) + int val; + + if (!ctx->dev) + return val_def; + + if (!sysinfo_get_int(ctx->dev, sysinfo_id, &val)) + return val; + + if (!IS_ENABLED(CONFIG_OF_CONTROL) || !prop) + return val_def; + + if (ofnode_valid(ctx->node) && !ofnode_read_u32(ctx->node, prop, &val)) + return val; + + /* + * If the node or property is not valid fallback and try the root + */ + if (!ofnode_read_u32(ofnode_root(), prop, &val)) + return val; +#endif + return val_def; +} + /** * smbios_add_prop_si() - Add a property from the devicetree or sysinfo * @@ -225,9 +262,6 @@ static int smbios_add_prop_si(struct smbios_ctx *ctx, const char *prop, if (!dval || !*dval) dval = NULL; - if (!prop) - return smbios_add_string(ctx, dval); - if (sysinfo_id && ctx->dev) { char val[SMBIOS_STR_MAX]; @@ -235,6 +269,9 @@ static int smbios_add_prop_si(struct smbios_ctx *ctx, const char *prop, if (!ret) return smbios_add_string(ctx, val); } + if (!prop) + return smbios_add_string(ctx, dval); + if (IS_ENABLED(CONFIG_OF_CONTROL)) { const char *str = NULL; char str_dt[128] = { 0 }; @@ -336,9 +373,11 @@ static int smbios_write_type0(ulong *current, int handle, memset(t, 0, len); fill_smbios_header(t, SMBIOS_BIOS_INFORMATION, len, handle); smbios_set_eos(ctx, t->eos); - t->vendor = smbios_add_prop(ctx, NULL, "U-Boot"); + t->vendor = smbios_add_prop_si(ctx, NULL, SYSID_SM_BIOS_VENDOR, + "U-Boot"); - t->bios_ver = smbios_add_prop(ctx, "version", PLAIN_VERSION); + t->bios_ver = smbios_add_prop_si(ctx, "version", SYSID_SM_BIOS_VER, + PLAIN_VERSION); if (t->bios_ver) gd->smbios_version = ctx->last_str; log_debug("smbios_version = %p: '%s'\n", gd->smbios_version, @@ -347,7 +386,9 @@ static int smbios_write_type0(ulong *current, int handle, print_buffer((ulong)gd->smbios_version, gd->smbios_version, 1, strlen(gd->smbios_version) + 1, 0); #endif - t->bios_release_date = smbios_add_prop(ctx, NULL, U_BOOT_DMI_DATE); + t->bios_release_date = smbios_add_prop_si(ctx, NULL, + SYSID_SM_BIOS_REL_DATE, + U_BOOT_DMI_DATE); #ifdef CONFIG_ROM_SIZE if (CONFIG_ROM_SIZE < SZ_16M) { t->bios_rom_size = (CONFIG_ROM_SIZE / 65536) - 1; @@ -392,14 +433,13 @@ static int smbios_write_type1(ulong *current, int handle, memset(t, 0, len); fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle); smbios_set_eos(ctx, t->eos); + t->manufacturer = smbios_add_prop_si(ctx, "manufacturer", SYSID_SM_SYSTEM_MANUFACTURER, NULL); t->product_name = smbios_add_prop_si(ctx, "product", - SYSID_SM_SYSTEM_PRODUCT, - NULL); - t->version = smbios_add_prop_si(ctx, "version", - SYSID_SM_SYSTEM_VERSION, + SYSID_SM_SYSTEM_PRODUCT, NULL); + t->version = smbios_add_prop_si(ctx, "version", SYSID_SM_SYSTEM_VERSION, NULL); if (serial_str) { t->serial_number = smbios_add_prop(ctx, NULL, serial_str); @@ -409,11 +449,13 @@ static int smbios_write_type1(ulong *current, int handle, SYSID_SM_SYSTEM_SERIAL, NULL); } - t->wakeup_type = SMBIOS_WAKEUP_TYPE_UNKNOWN; - t->sku_number = smbios_add_prop_si(ctx, "sku", - SYSID_SM_SYSTEM_SKU, NULL); - t->family = smbios_add_prop_si(ctx, "family", - SYSID_SM_SYSTEM_FAMILY, NULL); + t->wakeup_type = smbios_get_val_si(ctx, "wakeup-type", + SYSID_SM_SYSTEM_WAKEUP, + SMBIOS_WAKEUP_TYPE_UNKNOWN); + t->sku_number = smbios_add_prop_si(ctx, "sku", SYSID_SM_SYSTEM_SKU, + NULL); + t->family = smbios_add_prop_si(ctx, "family", SYSID_SM_SYSTEM_FAMILY, + NULL); len = t->hdr.length + smbios_string_table_len(ctx); *current += len; @@ -427,29 +469,49 @@ static int smbios_write_type2(ulong *current, int handle, { struct smbios_type2 *t; int len = sizeof(*t); + u8 *eos_addr; + /* + * reserve the space for the dynamic bytes of contained object handles. + * TODO: len += * SMBIOS_TYPE2_CON_OBJ_HANDLE_SIZE + * obj_handle_num can be from DT node "baseboard" or sysinfo driver. + */ t = map_sysmem(*current, len); memset(t, 0, len); fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle); - smbios_set_eos(ctx, t->eos); + + /* eos is at the end of the structure */ + eos_addr = (u8 *)t + len - sizeof(t->eos); + smbios_set_eos(ctx, eos_addr); + t->manufacturer = smbios_add_prop_si(ctx, "manufacturer", SYSID_SM_BASEBOARD_MANUFACTURER, NULL); t->product_name = smbios_add_prop_si(ctx, "product", - SYSID_SM_BASEBOARD_PRODUCT, - NULL); + SYSID_SM_BASEBOARD_PRODUCT, NULL); t->version = smbios_add_prop_si(ctx, "version", - SYSID_SM_BASEBOARD_VERSION, - NULL); - + SYSID_SM_BASEBOARD_VERSION, NULL); t->serial_number = smbios_add_prop_si(ctx, "serial", - SYSID_SM_BASEBOARD_SERIAL, - NULL); + SYSID_SM_BASEBOARD_SERIAL, NULL); t->asset_tag_number = smbios_add_prop_si(ctx, "asset-tag", SYSID_SM_BASEBOARD_ASSET_TAG, NULL); - t->feature_flags = SMBIOS_BOARD_FEAT_HOST_BOARD; - t->board_type = SMBIOS_BOARD_TYPE_MOTHERBOARD; + t->feature_flags = smbios_get_val_si(ctx, "feature-flags", + SYSID_SM_BASEBOARD_FEATURE, 0); + + t->chassis_location = + smbios_add_prop_si(ctx, "chassis-location", + SYSID_SM_BASEBOARD_CHASSIS_LOCAT, NULL); + t->board_type = smbios_get_val_si(ctx, "board-type", + SYSID_SM_BASEBOARD_TYPE, + SMBIOS_BOARD_TYPE_UNKNOWN); + + /* + * TODO: + * Populate the Contained Object Handles if they exist + * t->number_contained_objects = ; + */ + t->chassis_handle = handle + 1; len = t->hdr.length + smbios_string_table_len(ctx); @@ -464,17 +526,43 @@ static int smbios_write_type3(ulong *current, int handle, { struct smbios_type3 *t; int len = sizeof(*t); + u8 *eos_addr; + size_t elem_size = 0; + + /* + * reserve the space for the dynamic bytes of contained elements. + * TODO: elem_size = * + * element_count and element_record_length can be from DT node + * "chassis" or sysinfo driver. + */ + len += elem_size; t = map_sysmem(*current, len); memset(t, 0, len); fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle); - smbios_set_eos(ctx, t->eos); - t->manufacturer = smbios_add_prop(ctx, "manufacturer", NULL); - t->chassis_type = SMBIOS_ENCLOSURE_DESKTOP; - t->bootup_state = SMBIOS_STATE_SAFE; - t->power_supply_state = SMBIOS_STATE_SAFE; - t->thermal_state = SMBIOS_STATE_SAFE; - t->security_status = SMBIOS_SECURITY_NONE; + + /* eos is at the end of the structure */ + eos_addr = (u8 *)t + len - sizeof(t->eos); + smbios_set_eos(ctx, eos_addr); + + t->manufacturer = smbios_add_prop_si(ctx, "manufacturer", + SYSID_SM_ENCLOSURE_MANUFACTURER, + NULL); + t->chassis_type = smbios_get_val_si(ctx, "chassis-type", + SYSID_SM_ENCLOSURE_TYPE, + SMBIOS_ENCLOSURE_UNKNOWN); + t->bootup_state = smbios_get_val_si(ctx, "bootup-state", + SYSID_SM_ENCLOSURE_BOOTUP, + SMBIOS_STATE_UNKNOWN); + t->power_supply_state = smbios_get_val_si(ctx, "power-supply-state", + SYSID_SM_ENCLOSURE_POW, + SMBIOS_STATE_UNKNOWN); + t->thermal_state = smbios_get_val_si(ctx, "thermal-state", + SYSID_SM_ENCLOSURE_THERMAL, + SMBIOS_STATE_UNKNOWN); + t->security_status = smbios_get_val_si(ctx, "security-status", + SYSID_SM_ENCLOSURE_SECURITY, + SMBIOS_SECURITY_UNKNOWN); len = t->hdr.length + smbios_string_table_len(ctx); *current += len; @@ -510,11 +598,25 @@ static void smbios_write_type4_dm(struct smbios_type4 *t, name = processor_name; } #endif - - t->processor_family = 0xfe; - t->processor_family2 = processor_family; - t->processor_manufacturer = smbios_add_prop(ctx, NULL, vendor); - t->processor_version = smbios_add_prop(ctx, NULL, name); + if (processor_family == SMBIOS_PROCESSOR_FAMILY_UNKNOWN) + processor_family = + smbios_get_val_si(ctx, "family", + SYSID_SM_PROCESSOR_FAMILY, + SMBIOS_PROCESSOR_FAMILY_UNKNOWN); + + if (processor_family == SMBIOS_PROCESSOR_FAMILY_EXT) + t->processor_family2 = + smbios_get_val_si(ctx, "family2", + SYSID_SM_PROCESSOR_FAMILY2, + SMBIOS_PROCESSOR_FAMILY_UNKNOWN); + + t->processor_family = processor_family; + t->processor_manufacturer = + smbios_add_prop_si(ctx, "manufacturer", + SYSID_SM_PROCESSOR_MANUFACT, vendor); + t->processor_version = smbios_add_prop_si(ctx, "version", + SYSID_SM_PROCESSOR_VERSION, + name); } static int smbios_write_type4(ulong *current, int handle, @@ -527,13 +629,23 @@ static int smbios_write_type4(ulong *current, int handle, memset(t, 0, len); fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle); smbios_set_eos(ctx, t->eos); - t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL; + t->socket_design = smbios_add_prop_si(ctx, "socket-design", + SYSID_SM_PROCESSOR_SOCKET, NULL); + t->processor_type = smbios_get_val_si(ctx, "processor-type", + SYSID_SM_PROCESSOR_TYPE, + SMBIOS_PROCESSOR_TYPE_UNKNOWN); smbios_write_type4_dm(t, ctx); - t->status = SMBIOS_PROCESSOR_STATUS_ENABLED; - t->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE; - t->l1_cache_handle = 0xffff; - t->l2_cache_handle = 0xffff; - t->l3_cache_handle = 0xffff; + + t->status = smbios_get_val_si(ctx, "processor-status", + SYSID_SM_PROCESSOR_STATUS, + SMBIOS_PROCESSOR_STATUS_UNKNOWN); + t->processor_upgrade = + smbios_get_val_si(ctx, "upgrade", SYSID_SM_PROCESSOR_UPGRADE, + SMBIOS_PROCESSOR_UPGRADE_UNKNOWN); + + t->l1_cache_handle = SMBIOS_CACHE_HANDLE_NONE; + t->l2_cache_handle = SMBIOS_CACHE_HANDLE_NONE; + t->l3_cache_handle = SMBIOS_CACHE_HANDLE_NONE; len = t->hdr.length + smbios_string_table_len(ctx); *current += len; @@ -581,7 +693,7 @@ static struct smbios_write_method smbios_write_funcs[] = { { smbios_write_type2, "baseboard", }, /* Type 3 must immediately follow type 2 due to chassis handle. */ { smbios_write_type3, "chassis", }, - { smbios_write_type4, }, + { smbios_write_type4, "processor"}, { smbios_write_type32, }, { smbios_write_type127 }, }; @@ -598,7 +710,7 @@ ulong write_smbios_table(ulong addr) int i; ctx.node = ofnode_null(); - if (IS_ENABLED(CONFIG_OF_CONTROL) && CONFIG_IS_ENABLED(SYSINFO)) { + if (CONFIG_IS_ENABLED(SYSINFO)) { uclass_first_device(UCLASS_SYSINFO, &ctx.dev); if (ctx.dev) { int ret; From patchwork Fri Dec 6 22:54:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Mao X-Patchwork-Id: 2019570 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=jHOtf/rL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4mpH3FzGz1yQw for ; Sat, 7 Dec 2024 09:56:23 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 97B9989434; Fri, 6 Dec 2024 23:56:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="jHOtf/rL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C96358870D; Fri, 6 Dec 2024 23:56:20 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6A4F889434 for ; Fri, 6 Dec 2024 23:56:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-qt1-x82b.google.com with SMTP id d75a77b69052e-4667931f14bso39701431cf.2 for ; Fri, 06 Dec 2024 14:56:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733525777; x=1734130577; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jdv6GWWQ2zq/8W5Fdi6oxeWrdHVlmKoKAmCJAGw4+xI=; b=jHOtf/rLGl5eFO1Qtjp7hn0IhsL8eLzgQCcmIMIo0I0vJdS68+0/sdip85YeJry8Ia d2qkJ9+SiXBXI4jS+kkdECivgzIcQSTVjBAw6FS6jAYG1rxtEan0KJWl/g04dbUffecJ 01jImrvwpHQnnqvydXcdv6Oa9J/F9kMnzZ3OVCJJev9t13psFx9iM0zUQJQP29h1oKbh zAUSnvclWbqo8VJxRc63ltgF8OmpmZrrD1pllrR0i2XtX185f9aei9nSOHxREJtfqri1 V4hTLd+/1xax2JJgq2zvjd51lvBug/idxWQfTH8HkKmjRWWy9LTvCJqE3hMCLzyQIE9z d5sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733525777; x=1734130577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jdv6GWWQ2zq/8W5Fdi6oxeWrdHVlmKoKAmCJAGw4+xI=; b=Uns+THNUgaoL+iPmQu/RXEIz9eCjy2M0NRqW/XeWoO51cqMsyP4K+zU8EvKKnUs6Is q4oDektx17fG7rk33VUD0S1EWxDyywEGFZA7JnTY2sg/7bi6B9ctixZAaYs424MivuFL ed/1NXkuapcsTpFjTRvtTKMA4I+VLnFmvFL2IV5jJS4R8aEyIAPU0zegCIWt2BSbX6an ve4PJ/rW1gt5Vg5Fygco7b8d0hkh5agvTSXsKr5Ud6MNe7ohZc0SLQ/o97M47Be4Aerz 6vYL6b7cnLOUc2+uEr9b20f/qFJbYzc/T7ccMQVLDPfCKWxommEOIKqE/GIjKDrKQjgK DZlA== X-Gm-Message-State: AOJu0YzV7/3lfiUXeMzxMInCBbNamJKZMjdiVTRsaHGMvZpinHCYlSF1 BSTpFVkQsDFBxz5M96UiqIcmBUk45N1mudrBa8gmzmwnZn41vUDOotGXD6IDCGwcGGleSzySChg T X-Gm-Gg: ASbGncvmnSidcVDmFeT+2EBV520x5nRXX4M56Zv7NhcMbbuLLFS2Dtl1+vkqeZ7Jk7K JYg7PUfHQG5PCVwRmUuKeYdTA39e94lRGQ7h11C+XSm26eliUsyyskgp4EyqPm/qQAnUN4s5gzO 3uSWyYsnDRGw/wNGmRpH3LvsH+y4umonx2GT+mOM9oc286472odNbpObELu49z1BgnKImByzqR1 Nv5EdTSds46wnCJtGiNB1xeqZy2jMuxFKWMQIOSy7Qu45Cjbouw4aRB1HNNGQlXPH4LMR1qJYHU er3AWbr7MA7lGipq6r18ctwAdPQtg+YFN5Sl0djmhVqxeoKX X-Google-Smtp-Source: AGHT+IHY0579k+qXjRcSzHVLzAIgUmyd7StV2XpkfgXQ8k0CqV1Vxr6AR2cGflnljZdH3xYzwe4t9w== X-Received: by 2002:a05:622a:148b:b0:466:afc3:d649 with SMTP id d75a77b69052e-46734e67705mr79271681cf.36.1733525777043; Fri, 06 Dec 2024 14:56:17 -0800 (PST) Received: from ubuntu.localdomain (pool-174-114-184-37.cpe.net.cable.rogers.com. [174.114.184.37]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-467296d4d7dsm26080871cf.34.2024.12.06.14.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 14:56:15 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Tom Rini , Tuomas Tynkkynen , Simon Glass , Patrick Rudolph , Heinrich Schuchardt , Ilias Apalodimas , =?utf-8?q?Marek_Beh=C3=BAn?= , Stefan Roese , Caleb Connolly , Alexander Gendin , Wan Yee Lau , Jonas Karlman , Masahisa Kojima , Max Krummenacher , Francesco Dolcini , Michal Simek , Sughosh Ganu , Peter Robinson Subject: [PATCH v3 06/10] smbios: add detailed smbios information Date: Fri, 6 Dec 2024 14:54:23 -0800 Message-Id: <20241206225438.13866-7-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241206225438.13866-1-raymond.mao@linaro.org> References: <20241206225438.13866-1-raymond.mao@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add detailed SMBIOS information as following: 1. Missing fields in Type #3 and #4 2. Type #7 Add support to dynamic length of contained object handles and elements. As SMBIOS is a fundamental feature which is enabled for all boards, in order to avoid increasing rom size, all detailed SMBIOS information is under kconfig GENERATE_SMBIOS_TABLE_VERBOSE. Board maintainers can determine whether to select this feature. Signed-off-by: Raymond Mao --- Changes in v3 - Initial patch. lib/smbios.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 202 insertions(+), 1 deletion(-) diff --git a/lib/smbios.c b/lib/smbios.c index e8089e91523..203ed6d78b0 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -528,6 +528,8 @@ static int smbios_write_type3(ulong *current, int handle, int len = sizeof(*t); u8 *eos_addr; size_t elem_size = 0; + __maybe_unused u8 *elem_addr; + __maybe_unused u8 *sku_num_addr; /* * reserve the space for the dynamic bytes of contained elements. @@ -540,7 +542,10 @@ static int smbios_write_type3(ulong *current, int handle, t = map_sysmem(*current, len); memset(t, 0, len); fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle); - +#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE) + elem_addr = (u8 *)t + offsetof(struct smbios_type3, sku_number); + sku_num_addr = elem_addr + elem_size; +#endif /* eos is at the end of the structure */ eos_addr = (u8 *)t + len - sizeof(t->eos); smbios_set_eos(ctx, eos_addr); @@ -564,6 +569,32 @@ static int smbios_write_type3(ulong *current, int handle, SYSID_SM_ENCLOSURE_SECURITY, SMBIOS_SECURITY_UNKNOWN); +#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE) + t->version = smbios_add_prop_si(ctx, "version", + SYSID_SM_ENCLOSURE_VERSION, NULL); + t->serial_number = smbios_add_prop_si(ctx, "serial", + SYSID_SM_ENCLOSURE_SERIAL, NULL); + t->asset_tag_number = smbios_add_prop_si(ctx, "asset-tag", + SYSID_SM_BASEBOARD_ASSET_TAG, + NULL); + t->oem_defined = smbios_get_val_si(ctx, "oem-defined", + SYSID_SM_ENCLOSURE_OEM, 0); + t->height = smbios_get_val_si(ctx, "height", + SYSID_SM_ENCLOSURE_HEIGHT, 0); + t->number_of_power_cords = + smbios_get_val_si(ctx, "number-of-power-cords", + SYSID_SM_ENCLOSURE_POWCORE_NUM, 0); + + /* + * TODO: Populate the Contained Element Record if they exist + * t->element_count = ; + * t->element_record_length = ; + */ + + *sku_num_addr = smbios_add_prop_si(ctx, "sku", SYSID_SM_ENCLOSURE_SKU, + NULL); +#endif + len = t->hdr.length + smbios_string_table_len(ctx); *current += len; unmap_sysmem(t); @@ -577,6 +608,8 @@ static void smbios_write_type4_dm(struct smbios_type4 *t, u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN; const char *vendor = NULL; const char *name = NULL; + __maybe_unused void *id_data = NULL; + __maybe_unused size_t id_size = 0; #ifdef CONFIG_CPU char processor_name[49]; @@ -617,6 +650,16 @@ static void smbios_write_type4_dm(struct smbios_type4 *t, t->processor_version = smbios_add_prop_si(ctx, "version", SYSID_SM_PROCESSOR_VERSION, name); + +#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE) + if (t->processor_id[0] || t->processor_id[1] || + sysinfo_get_data(ctx->dev, SYSID_SM_PROCESSOR_ID, &id_data, + &id_size)) + return; + + if (id_data && id_size == sizeof(t->processor_id)) + memcpy((u8 *)t->processor_id, id_data, id_size); +#endif } static int smbios_write_type4(ulong *current, int handle, @@ -624,6 +667,8 @@ static int smbios_write_type4(ulong *current, int handle, { struct smbios_type4 *t; int len = sizeof(*t); + __maybe_unused void *hdl; + __maybe_unused size_t hdl_size; t = map_sysmem(*current, len); memset(t, 0, len); @@ -647,6 +692,60 @@ static int smbios_write_type4(ulong *current, int handle, t->l2_cache_handle = SMBIOS_CACHE_HANDLE_NONE; t->l3_cache_handle = SMBIOS_CACHE_HANDLE_NONE; +#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE) + t->voltage = smbios_get_val_si(ctx, "voltage", + SYSID_SM_PROCESSOR_VOLTAGE, 0); + t->external_clock = smbios_get_val_si(ctx, "external-clock", + SYSID_SM_PROCESSOR_EXT_CLOCK, 0); + t->max_speed = smbios_get_val_si(ctx, "max-speed", + SYSID_SM_PROCESSOR_MAX_SPEED, 0); + t->current_speed = smbios_get_val_si(ctx, "current-speed", + SYSID_SM_PROCESSOR_CUR_SPEED, 0); + + /* Read the cache handles */ + if (!sysinfo_get_data(ctx->dev, SYSID_SM_CACHE_HANDLE, &hdl, + &hdl_size) && + (hdl_size == SYSINFO_CACHE_LVL_MAX * sizeof(u16))) { + u16 *handle = (u16 *)hdl; + + if (*handle) + t->l1_cache_handle = *handle; + + handle++; + if (*handle) + t->l2_cache_handle = *handle; + + handle++; + if (*handle) + t->l3_cache_handle = *handle; + } + + t->serial_number = smbios_add_prop_si(ctx, "serial", + SYSID_SM_PROCESSOR_SN, NULL); + t->asset_tag = smbios_add_prop_si(ctx, "asset-tag", + SYSID_SM_PROCESSOR_ASSET_TAG, NULL); + t->part_number = smbios_add_prop_si(ctx, "part-number", + SYSID_SM_PROCESSOR_PN, NULL); + t->core_count = smbios_get_val_si(ctx, "core-count", + SYSID_SM_PROCESSOR_CORE_CNT, 0); + t->core_enabled = smbios_get_val_si(ctx, "core-enabled", + SYSID_SM_PROCESSOR_CORE_EN, 0); + t->thread_count = smbios_get_val_si(ctx, "thread-count", + SYSID_SM_PROCESSOR_THREAD_CNT, 0); + t->processor_characteristics = + smbios_get_val_si(ctx, "characteristics", + SYSID_SM_PROCESSOR_CHARA, + SMBIOS_PROCESSOR_UND); + t->core_count2 = smbios_get_val_si(ctx, "core-count2", + SYSID_SM_PROCESSOR_CORE_CNT2, 0); + t->core_enabled2 = smbios_get_val_si(ctx, "core-enabled2", + SYSID_SM_PROCESSOR_CORE_EN2, 0); + t->thread_count2 = smbios_get_val_si(ctx, "thread-count2", + SYSID_SM_PROCESSOR_THREAD_CNT2, 0); + t->thread_enabled = smbios_get_val_si(ctx, "thread-enabled", + SYSID_SM_PROCESSOR_THREAD_EN, 0); +#endif + len = t->hdr.length + smbios_string_table_len(ctx); *current += len; unmap_sysmem(t); @@ -654,6 +753,104 @@ static int smbios_write_type4(ulong *current, int handle, return len; } +#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE) + +static int smbios_write_type7_1level(ulong *current, int handle, + struct smbios_ctx *ctx, int level) +{ + struct smbios_type7 *t; + int len = sizeof(*t); + void *hdl; + size_t hdl_size; + + t = map_sysmem(*current, len); + memset(t, 0, len); + fill_smbios_header(t, SMBIOS_CACHE_INFORMATION, len, handle); + smbios_set_eos(ctx, t->eos); + + t->socket_design = smbios_add_prop_si(ctx, "socket-design", + SYSID_SM_CACHE_SOCKET + level, + NULL); + t->config.data = smbios_get_val_si(ctx, "config", + SYSID_SM_CACHE_CONFIG + level, + (level - 1) | SMBIOS_CACHE_OP_UND); + t->max_size.data = smbios_get_val_si(ctx, "max-size", + SYSID_SM_CACHE_MAX_SIZE + level, + 0); + t->inst_size.data = smbios_get_val_si(ctx, "installed-size", + SYSID_SM_CACHE_INST_SIZE + level, + 0); + t->supp_sram_type.data = + smbios_get_val_si(ctx, "supported-sram-type", + SYSID_SM_CACHE_SUPSRAM_TYPE + level, + SMBIOS_CACHE_SRAM_TYPE_UNKNOWN); + t->curr_sram_type.data = + smbios_get_val_si(ctx, "current-sram-type", + SYSID_SM_CACHE_CURSRAM_TYPE + level, + SMBIOS_CACHE_SRAM_TYPE_UNKNOWN); + t->speed = smbios_get_val_si(ctx, "speed", SYSID_SM_CACHE_SPEED + level, + 0); + t->err_corr_type = smbios_get_val_si(ctx, "error-correction-type", + SYSID_SM_CACHE_ERRCOR_TYPE + level, + SMBIOS_CACHE_ERRCORR_UNKNOWN); + t->sys_cache_type = + smbios_get_val_si(ctx, "system-cache-type", + SYSID_SM_CACHE_SCACHE_TYPE + level, + SMBIOS_CACHE_SYSCACHE_TYPE_UNKNOWN); + t->associativity = smbios_get_val_si(ctx, "associativity", + SYSID_SM_CACHE_ASSOC + level, + SMBIOS_CACHE_ASSOC_UNKNOWN); + t->max_size2.data = smbios_get_val_si(ctx, "max-size2", + SYSID_SM_CACHE_MAX_SIZE2 + level, + 0); + t->inst_size2.data = + smbios_get_val_si(ctx, "installed-size2", + SYSID_SM_CACHE_INST_SIZE2 + level, 0); + + /* Save the cache handles */ + if (!sysinfo_get_data(ctx->dev, SYSID_SM_CACHE_HANDLE, &hdl, + &hdl_size)) { + if (hdl_size == SYSINFO_CACHE_LVL_MAX * sizeof(u16)) + *((u16 *)hdl + level) = handle; + } + + len = t->hdr.length + smbios_string_table_len(ctx); + *current += len; + unmap_sysmem(t); + + return len; +} + +static int smbios_write_type7(ulong *current, int handle, + struct smbios_ctx *ctx) +{ + int len = 0; + int i, level; + ofnode parent = ctx->node; + struct smbios_ctx ctx_bak; + + memcpy(&ctx_bak, ctx, sizeof(ctx_bak)); + + /* Get the number of level */ + level = smbios_get_val_si(ctx, NULL, SYSID_SM_CACHE_LEVEL, 0); + if (level >= SYSINFO_CACHE_LVL_MAX) /* Error, return 0-length */ + return 0; + + for (i = 0; i <= level; i++) { + char buf[9] = ""; + + if (!snprintf(buf, sizeof(buf), "l%d-cache", i + 1)) + return 0; + ctx->subnode_name = buf; + ctx->node = ofnode_find_subnode(parent, ctx->subnode_name); + len += smbios_write_type7_1level(current, handle++, ctx, i); + memcpy(ctx, &ctx_bak, sizeof(*ctx)); + } + return len; +} + +#endif /* #if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE) */ + static int smbios_write_type32(ulong *current, int handle, struct smbios_ctx *ctx) { @@ -693,6 +890,10 @@ static struct smbios_write_method smbios_write_funcs[] = { { smbios_write_type2, "baseboard", }, /* Type 3 must immediately follow type 2 due to chassis handle. */ { smbios_write_type3, "chassis", }, +#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE) + /* Type 7 must ahead of type 4 to get cache handles. */ + { smbios_write_type7, "cache", }, +#endif { smbios_write_type4, "processor"}, { smbios_write_type32, }, { smbios_write_type127 }, From patchwork Fri Dec 6 22:54:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Mao X-Patchwork-Id: 2019571 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Xh5QNdv5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4mpZ5vpfz1yQw for ; Sat, 7 Dec 2024 09:56:38 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 00F3A88815; Fri, 6 Dec 2024 23:56:37 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Xh5QNdv5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 361EB8870D; Fri, 6 Dec 2024 23:56:35 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C2D5D88815 for ; Fri, 6 Dec 2024 23:56:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-qt1-x82e.google.com with SMTP id d75a77b69052e-46684744070so24779451cf.1 for ; Fri, 06 Dec 2024 14:56:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733525791; x=1734130591; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9dVPNhcK14F0dg2tmjpO+O+DWZ588ltnGQ5/nwjH4/w=; b=Xh5QNdv5kwspQm7TGX6X1i09sFv8ab+KSntD0UruJcIZ8vvfzsR4BM0kw5aAMPCfpP h9LZ80v+cYCE5UVWvO9MXkcyoLI6htPSB7ecn95fvutd5+lH3qjmYJinQ71ICuZQTlfr RSRPWTYxqfbxXVeGbwyqoWIPaBCM8CtEQSqClHdYl08wI/3PlD0EnhNh+ZBHEhNEUHwW lMchYVYBKbbN5b28eKbNYVOo9KYVPLciwNsaSdu/z3Z1tkOuG6LTGRTp8kL/awsxbjea xkGzP3FtrnebrbFRDDbne+yI1mZ9qW6y8xY65yCWRMRH9zyAoXTtHzV/Y0GeQCUjOdgD QnOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733525791; x=1734130591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9dVPNhcK14F0dg2tmjpO+O+DWZ588ltnGQ5/nwjH4/w=; b=oSHbjSI9c9Yb3dD4J9CEXrBeXioDC/sxkHknpBVg1hGfF/DSVNw1YndnO2u9OibRo/ 7BQDevcjcg67N3DYG5FFMhyiPd4+vj4+pMFMQoeGzc9kttDXhP/Qvba23rHSm3aFtgss uBIJy0aXFGfhckxYRliSH9ieyUnEW2xDOWHQ/VDjzW2Qqg1Wdtf2FuZ7R1ez9Qg2lTUD Zr4cKOfobpfLdwBmfPGN1ACnfovVT5zMYyRyNf831kICw1jRva3gFuA6J1EOY+R2tKT6 Yfez3uZ58cf/MNk7zBIyDgFwpRdP5MwapPIVNiPSylASOkvHVBkw93o+l4yHgtHSdT/N Tbww== X-Gm-Message-State: AOJu0YwGTGWaqi6TzfAcqlXZalPKhFO2a2E7BeUDQD5zaG2EqQM39uqA 5aa1rTLxq37ubXCyvCQwx5GAX4ICGaFd3aP9boTGOofY/OFlqiOGjndxwIdaVqGcfdUMit6XTdP g X-Gm-Gg: ASbGncvCkkhuFtu/NuO1BdwZ0meS3aYNmZ97jxeoJ0wEYDMnWq7zbGw6lLVcx9aoUge ULRuWuXYDmJn9fa4QA/0K/J+ADMh0xaCgTUhvsifUDZ95Wbwk+XfclIXPVXC/PCIK+dxw3ygQIw LhBnVKn+McY/6GoBfcOn239F0cClgfAvD+uudxvovTv02fUy5jKtUqDxFkr5nEAlNHutlXIHBAv JXT7POCiOLQ1Z/238Oue28JOFUMrrwxeKhpTdbeBcZxlnus3YgiS8ryBPswoZefECy2wM0j8ohY Ff8uY5TrIXquPf1VwLs/cHexrPOQJFPv4vCmDWn4boIYtx4/ X-Google-Smtp-Source: AGHT+IHPTKAaL/o3j1pSPjKrgX7Co0La2SEHDQSx9cu3JVbSFyBDOA0CEc2iMoJ/xxaPs5fuEwgyNA== X-Received: by 2002:ac8:7d91:0:b0:466:9d0e:1920 with SMTP id d75a77b69052e-46734cd37ccmr92303471cf.24.1733525791166; Fri, 06 Dec 2024 14:56:31 -0800 (PST) Received: from ubuntu.localdomain (pool-174-114-184-37.cpe.net.cable.rogers.com. [174.114.184.37]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-467296d4d7dsm26080871cf.34.2024.12.06.14.56.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 14:56:29 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Simon Glass , Tom Rini , Tuomas Tynkkynen , Patrick Rudolph , Heinrich Schuchardt , Ilias Apalodimas , Stefan Roese , =?utf-8?q?Marek_Beh=C3=BAn?= , Alexander Gendin , Jonas Karlman , Wan Yee Lau , Caleb Connolly , Masahisa Kojima , Max Krummenacher , Francesco Dolcini , Michal Simek , Sughosh Ganu , Peter Robinson Subject: [PATCH v3 07/10] armv8: Add arch-specific sysinfo platform driver Date: Fri, 6 Dec 2024 14:54:24 -0800 Message-Id: <20241206225438.13866-8-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241206225438.13866-1-raymond.mao@linaro.org> References: <20241206225438.13866-1-raymond.mao@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add sysinfo platform driver for all armv8 platforms to retrieve hardware information on processor and cache. Signed-off-by: Raymond Mao Reviewed-by: Simon Glass --- Changes in v2 - Combine with #8(v1) patch. - Remove the handling of the common strings and values. Changes in v3 - None. arch/arm/cpu/armv8/Makefile | 2 + arch/arm/cpu/armv8/sysinfo.c | 292 +++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 arch/arm/cpu/armv8/sysinfo.c diff --git a/arch/arm/cpu/armv8/Makefile b/arch/arm/cpu/armv8/Makefile index 2e71ff2dc97..b4126c61df1 100644 --- a/arch/arm/cpu/armv8/Makefile +++ b/arch/arm/cpu/armv8/Makefile @@ -46,3 +46,5 @@ obj-$(CONFIG_TARGET_BCMNS3) += bcmns3/ obj-$(CONFIG_XEN) += xen/ obj-$(CONFIG_ARMV8_CE_SHA1) += sha1_ce_glue.o sha1_ce_core.o obj-$(CONFIG_ARMV8_CE_SHA256) += sha256_ce_glue.o sha256_ce_core.o + +obj-$(CONFIG_SYSINFO_SMBIOS) += sysinfo.o diff --git a/arch/arm/cpu/armv8/sysinfo.c b/arch/arm/cpu/armv8/sysinfo.c new file mode 100644 index 00000000000..850142da37d --- /dev/null +++ b/arch/arm/cpu/armv8/sysinfo.c @@ -0,0 +1,292 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2024 Linaro Limited + * Author: Raymond Mao + */ +#include +#include +#include +#include + +union ccsidr_el1 { + struct { + u64 linesize:3; + u64 associativity:10; + u64 numsets:15; + u64 unknown:4; + u64 reserved:32; + } no_ccidx; + struct { + u64 linesize:3; + u64 associativity:21; + u64 reserved1:8; + u64 numsets:24; + u64 reserved2:8; + } ccidx_aarch64; + struct { + u64 linesize:3; + u64 associativity:21; + u64 reserved:8; + u64 unallocated:32; + } ccidx_aarch32; + u64 data; +}; + +union midr_el1 { + struct { + u64 revision:4; + u64 partnum:12; + u64 architecture:4; + u64 variant:4; + u64 implementer:8; + u64 reserved:32; + } fields; + u64 data; +}; + +enum { + CACHE_NONE, + CACHE_INST_ONLY, + CACHE_DATA_ONLY, + CACHE_INST_WITH_DATA, + CACHE_UNIFIED, +}; + +enum { + CACHE_ASSOC_DIRECT_MAPPED = 1, + CACHE_ASSOC_2WAY = 2, + CACHE_ASSOC_4WAY = 4, + CACHE_ASSOC_8WAY = 8, + CACHE_ASSOC_16WAY = 16, + CACHE_ASSOC_12WAY = 12, + CACHE_ASSOC_24WAY = 24, + CACHE_ASSOC_32WAY = 32, + CACHE_ASSOC_48WAY = 48, + CACHE_ASSOC_64WAY = 64, + CACHE_ASSOC_20WAY = 20, +}; + +enum { + VENDOR_RESERVED = 0, + VENDOR_ARM = 0x41, + VENDOR_BROADCOM = 0x42, + VENDOR_CAVIUM = 0x43, + VENDOR_DEC = 0x44, + VENDOR_FUJITSU = 0x46, + VENDOR_INFINEON = 0x49, + VENDOR_FREESCALE = 0x4d, + VENDOR_NVIDIA = 0x4e, + VENDOR_AMCC = 0x50, + VENDOR_QUALCOMM = 0x51, + VENDOR_MARVELL = 0x56, + VENDOR_INTEL = 0x69, + VENDOR_AMPERE = 0xc0, +}; + +/* + * TODO: + * To support ARMv8.3, we need to read "CCIDX, bits [23:20]" from + * ID_AA64MMFR2_EL1 to get the format of CCSIDR_EL1: + * + * 0b0000 - 32-bit format implemented for all levels of the CCSIDR_EL1. + * 0b0001 - 64-bit format implemented for all levels of the CCSIDR_EL1. + * + * Here we assume to use CCSIDR_EL1 in no CCIDX layout: + * NumSets, bits [27:13]: (Number of sets in cache) - 1 + * Associativity, bits [12:3]: (Associativity of cache) - 1 + * LineSize, bits [2:0]: (Log2(Number of bytes in cache line)) - 4 + */ +int sysinfo_get_cache_info(u8 level, struct cache_info *cinfo) +{ + u64 clidr_el1; + u32 csselr_el1; + u32 num_sets; + union ccsidr_el1 creg; + int cache_type; + + sysinfo_cache_info_default(cinfo); + + /* Read CLIDR_EL1 */ + asm volatile("mrs %0, clidr_el1" : "=r" (clidr_el1)); + debug("CLIDR_EL1: 0x%llx\n", clidr_el1); + + cache_type = (clidr_el1 >> (3 * level)) & 0x7; + if (cache_type == CACHE_NONE) /* level does not exist */ + return -1; + + switch (cache_type) { + case CACHE_INST_ONLY: + cinfo->cache_type = SMBIOS_CACHE_SYSCACHE_TYPE_INST; + break; + case CACHE_DATA_ONLY: + cinfo->cache_type = SMBIOS_CACHE_SYSCACHE_TYPE_DATA; + break; + case CACHE_UNIFIED: + cinfo->cache_type = SMBIOS_CACHE_SYSCACHE_TYPE_UNIFIED; + break; + case CACHE_INST_WITH_DATA: + cinfo->cache_type = SMBIOS_CACHE_SYSCACHE_TYPE_OTHER; + break; + default: + cinfo->cache_type = SMBIOS_CACHE_SYSCACHE_TYPE_UNKNOWN; + break; + } + + /* Select cache level */ + csselr_el1 = (level << 1); + asm volatile("msr csselr_el1, %0" : : "r" (csselr_el1)); + + /* Read CCSIDR_EL1 */ + asm volatile("mrs %0, ccsidr_el1" : "=r" (creg.data)); + debug("CCSIDR_EL1 (Level %d): 0x%llx\n", level + 1, creg.data); + + /* Extract cache size and associativity */ + cinfo->line_size = 1 << (creg.no_ccidx.linesize + 4); + + /* Map the associativity value */ + switch (creg.no_ccidx.associativity + 1) { + case CACHE_ASSOC_DIRECT_MAPPED: + cinfo->associativity = SMBIOS_CACHE_ASSOC_DMAPPED; + break; + case CACHE_ASSOC_2WAY: + cinfo->associativity = SMBIOS_CACHE_ASSOC_2WAY; + break; + case CACHE_ASSOC_4WAY: + cinfo->associativity = SMBIOS_CACHE_ASSOC_4WAY; + break; + case CACHE_ASSOC_8WAY: + cinfo->associativity = SMBIOS_CACHE_ASSOC_8WAY; + break; + case CACHE_ASSOC_16WAY: + cinfo->associativity = SMBIOS_CACHE_ASSOC_16WAY; + break; + case CACHE_ASSOC_12WAY: + cinfo->associativity = SMBIOS_CACHE_ASSOC_12WAY; + break; + case CACHE_ASSOC_24WAY: + cinfo->associativity = SMBIOS_CACHE_ASSOC_24WAY; + break; + case CACHE_ASSOC_32WAY: + cinfo->associativity = SMBIOS_CACHE_ASSOC_32WAY; + break; + case CACHE_ASSOC_48WAY: + cinfo->associativity = SMBIOS_CACHE_ASSOC_48WAY; + break; + case CACHE_ASSOC_64WAY: + cinfo->associativity = SMBIOS_CACHE_ASSOC_64WAY; + break; + case CACHE_ASSOC_20WAY: + cinfo->associativity = SMBIOS_CACHE_ASSOC_20WAY; + break; + default: + cinfo->associativity = SMBIOS_CACHE_ASSOC_UNKNOWN; + break; + } + + num_sets = creg.no_ccidx.numsets + 1; + /* Size in KB */ + cinfo->max_size = (cinfo->associativity * num_sets * cinfo->line_size) / + 1024; + + debug("L%d Cache:\n", level + 1); + debug("Number of bytes in cache line:%u\n", cinfo->line_size); + debug("Associativity of cache:%u\n", cinfo->associativity); + debug("Number of sets in cache:%u\n", num_sets); + debug("Cache size in KB:%u\n", cinfo->max_size); + + cinfo->inst_size = cinfo->max_size; + + /* + * Below fields with common values are placed under DT smbios node + * socket-design, config + * Other fields are typically specific to the implementation of the ARM + * processor by the silicon vendor: + * supp_sram_type, curr_sram_type, speed, err_corr_type + */ + + return 0; +} + +int sysinfo_get_processor_info(struct processor_info *pinfo) +{ + u64 mpidr, core_count; + union midr_el1 midr; + + /* Read the MIDR_EL1 register */ + asm volatile("mrs %0, MIDR_EL1" : "=r"(midr.data)); + /* Read the MPIDR_EL1 register */ + asm volatile("mrs %0, MPIDR_EL1" : "=r"(mpidr)); + + debug("MIDR: 0x%016llx\n", midr.data); + debug("MPIDR: 0x%016llx\n", mpidr); + debug("CPU Implementer: 0x%02x\n", midr.fields.implementer); + + switch (midr.fields.implementer) { + case VENDOR_ARM: + pinfo->manufacturer = "ARM Limited"; + break; + case VENDOR_BROADCOM: + pinfo->manufacturer = "Broadcom Corporation"; + break; + case VENDOR_CAVIUM: + pinfo->manufacturer = "Cavium Inc"; + break; + case VENDOR_DEC: + pinfo->manufacturer = "Digital Equipment Corporation"; + break; + case VENDOR_FUJITSU: + pinfo->manufacturer = "Fujitsu Ltd"; + break; + case VENDOR_INFINEON: + pinfo->manufacturer = "Infineon Technologies AG"; + break; + case VENDOR_FREESCALE: + pinfo->manufacturer = "Freescale Semiconductor Inc"; + break; + case VENDOR_NVIDIA: + pinfo->manufacturer = "NVIDIA Corporation"; + break; + case VENDOR_AMCC: + pinfo->manufacturer = + "Applied Micro Circuits Corporation"; + break; + case VENDOR_QUALCOMM: + pinfo->manufacturer = "Qualcomm Inc"; + break; + case VENDOR_MARVELL: + pinfo->manufacturer = "Marvell International Ltd"; + break; + case VENDOR_INTEL: + pinfo->manufacturer = "Intel Corporation"; + break; + case VENDOR_AMPERE: + pinfo->manufacturer = "Ampere Computing"; + break; + default: + pinfo->manufacturer = "Unknown"; + break; + } + debug("CPU part number: 0x%x\n", midr.fields.partnum); + debug("CPU revision: 0x%x\n", midr.fields.revision); + debug("CPU architecture: 0x%x\n", midr.fields.architecture); + debug("CPU variant: 0x%x\n", midr.fields.variant); + + /* Extract number of cores */ + core_count = (mpidr >> 0) & 0xFF; + pinfo->core_count = core_count + 1; + debug("CPU Core Count: %d\n", pinfo->core_count); + + pinfo->core_enabled = pinfo->core_count; + pinfo->characteristics = SMBIOS_PROCESSOR_64BIT | + SMBIOS_PROCESSOR_ARM64_SOCID; + if (pinfo->core_count > 1) + pinfo->characteristics |= SMBIOS_PROCESSOR_MULTICORE; + + /* + * Below fields with common values are placed under DT smbios node + * version, processor-type, processor-status, upgrade, family2, + * socket-design, serial, asset-tag, part-number + */ + + return 0; +} From patchwork Fri Dec 6 22:54:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Mao X-Patchwork-Id: 2019572 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=JJXOJwsk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4mpq22jBz1yQw for ; Sat, 7 Dec 2024 09:56:51 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6BF8D89607; Fri, 6 Dec 2024 23:56:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="JJXOJwsk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7AF358870D; Fri, 6 Dec 2024 23:56:48 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4584889607 for ; Fri, 6 Dec 2024 23:56:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-4668486dec2so22188841cf.3 for ; Fri, 06 Dec 2024 14:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733525805; x=1734130605; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HZsByYhbybUJ/b9kHGU44fSVl2pF79dnrJpAYeV/jEA=; b=JJXOJwsk2oezF9NyMR3TOKzxYbA8pIFEt1q0/bFOA4Vfu+fy3jUnNohZkDYxQIWU8d yBSAVsWnQ9CoAsphA5PyXWfIbU6309HYzYHy6NAioFuWIUo0RYTGIXLc6G6i/tZdXIUv qYvBN3Do3RgqWpWCcxlSEC2J7q/PyAzhX+1KV+EOS/7DUuRfsP/1+xMmvh5E2Vx5XwSx Vok/B9r+74r/9g5kIY1N5hTUdN1GovAwR7bV9OXtj9ZxcsuRuws5nKJFEfOsKqe2s9Jl W3w0Ez0lnU3cgHrb4rjd7x2wpbVQunMsg9FajVYUDg6FkSAd/7cLSKWhG8203MN1XolE xqwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733525805; x=1734130605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HZsByYhbybUJ/b9kHGU44fSVl2pF79dnrJpAYeV/jEA=; b=OenXJiyxpzVgVI8A9Qef84eDRF9BxwOgzKAZkEF8Y5IZTTkQrie92n83KmfZgioFHa AWY6Ag7//UYAOMXDQli2RHMRaE1Px/qvozi7Z0xqNR5STnrB50tmH7UE7eBqePtvfJg9 3OGk8TVCb2l4TlVg5hwIq5N+EpokBSVEiG0G89joR783t0BPYOwUuEeus2vVHEurk3O4 H0fU79WY1hEL4/0tChV4XtYnZthxamRnc7f2xyzTuk8k2ffBIu+XsUwqbwDR9BFwEwEA l0WRJrWk/WZ1+JnrfOOzNk5mVaF6gStEwOaVk11iquLsfvtJ96lVogaAw9woqZorTX95 FyLw== X-Gm-Message-State: AOJu0YybU3ZmiwfAiXDoxQeTWCYfn6xFqgK6M84gT87AqYIPWGgdquEJ duCIVEtyjxGSxjPiTEpo3/zftTI7BMDsFvudvj/zBNOjyzW2ogoi9wZ8HzxNtgQuLIwz9lR5Aat P X-Gm-Gg: ASbGncv2JvtxDRiQ1H1j7GIzfrD4DnloxAnZns+onK51xwa80ffg4MOJ84y/dLw3PNl NatwrPDhU/E9Keo9CaxXjPL331HbOZDHuK3eVaQ416aRIQ244fi3VLQFdhqTtbCg5aFxl5esovq dDQUljQbdEu8iomhP5TXsWUK0dwUHb8KxCdivSX7ckWK4MKbvKXVVuyfQs70ZgWM3MpAERvdBu/ Z/na3IwSXd9If1fsr5T6cpV/nPtrEQKijZRUe1xNute2JJ5oP5LaHjG/1Ikzwt11zxR0+0lQpRY IX7YjHpUKDm0sEnTb/z2kfA4sJ/h8nGRPvod8CRdGA5AHjPJ X-Google-Smtp-Source: AGHT+IE3Sy3qzCHf3DEoSEwz/6n4KBTQKNDhS71MuYsuQoGsOAcsQE5BHQef3vS3O8e9Y7kMMr0MLw== X-Received: by 2002:a05:622a:20e:b0:466:a0cf:b06c with SMTP id d75a77b69052e-46734fa95ecmr97377871cf.56.1733525804746; Fri, 06 Dec 2024 14:56:44 -0800 (PST) Received: from ubuntu.localdomain (pool-174-114-184-37.cpe.net.cable.rogers.com. [174.114.184.37]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-467296d4d7dsm26080871cf.34.2024.12.06.14.56.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 14:56:43 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Tom Rini , Tuomas Tynkkynen , Simon Glass , Patrick Rudolph , Heinrich Schuchardt , Ilias Apalodimas , Stefan Roese , =?utf-8?q?Marek_Beh=C3=BAn?= , Kever Yang , Jonas Karlman , Wan Yee Lau , Alexander Gendin , Caleb Connolly , Masahisa Kojima , Max Krummenacher , Michal Simek , Francesco Dolcini , Sughosh Ganu , Peter Robinson Subject: [PATCH v3 08/10] armv8: Add generic smbios information into the device tree Date: Fri, 6 Dec 2024 14:54:25 -0800 Message-Id: <20241206225438.13866-9-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241206225438.13866-1-raymond.mao@linaro.org> References: <20241206225438.13866-1-raymond.mao@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add common smbios information that can be used by all armv8 platforms and set it as default for qemu-arm64. From now smbios library can load values from here for those fields doesn't exist in the sysinfo driver. To run this with QEMU arm64, we need to dump the generated DTB from QEMU first, merge it with the one we build and then re-run QEMU with the merged DTB. ``` qemu-system-aarch64 -machine virt -machine dumpdtb=qemu.dtb cat <(dtc -I dtb qemu.dtb) <(dtc -I dtb ./dts/dt.dtb | \ grep -v /dts-v1/) | dtc - -o merged.dtb qemu-system-aarch64 -machine virt -nographic -bios u-boot.bin \ -dtb merged.dtb ``` For details please take reference on dt_qemu.rst Signed-off-by: Raymond Mao --- Changes in v2 - Initial patch. Changes in v3 - Remove all "Not Specified" strings. - Update the commit message. arch/arm/dts/qemu-arm64.dts | 4 ++ arch/arm/dts/smbios_generic.dtsi | 82 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 arch/arm/dts/smbios_generic.dtsi diff --git a/arch/arm/dts/qemu-arm64.dts b/arch/arm/dts/qemu-arm64.dts index 096b3910728..95fcf53ed74 100644 --- a/arch/arm/dts/qemu-arm64.dts +++ b/arch/arm/dts/qemu-arm64.dts @@ -7,5 +7,9 @@ /dts-v1/; +#if defined(CONFIG_SYSINFO_SMBIOS) && !defined(QFW_SMBIOS) +#include "smbios_generic.dtsi" +#endif + / { }; diff --git a/arch/arm/dts/smbios_generic.dtsi b/arch/arm/dts/smbios_generic.dtsi new file mode 100644 index 00000000000..fc168317c9e --- /dev/null +++ b/arch/arm/dts/smbios_generic.dtsi @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Default SMBIOS information for Arm64 platforms + * + * Copyright (c) 2024 Linaro Limited + * Author: Raymond Mao + */ +#include +#include + +/ { + smbios { + compatible = "u-boot,sysinfo-smbios"; + + smbios { + system { + manufacturer = CONFIG_SYS_VENDOR; + product = CONFIG_SYS_BOARD; + version = ""; + serial = ""; + wakeup-type = ; + sku = ""; + family = "armv8"; + }; + + baseboard { + manufacturer = CONFIG_SYS_VENDOR; + product = CONFIG_SYS_BOARD; + version = ""; + serial = ""; + asset-tag = ""; + chassis-location = ""; + feature-flags = ; + board-type = ; + }; + + chassis { + manufacturer = CONFIG_SYS_VENDOR; + version = ""; + serial = ""; + asset-tag = ""; + chassis-type = ; + bootup-state = ; + power-supply-state = ; + thermal-state = ; + security-status = ; + oem-defined = ; + height = ; + number-of-power-cords = ; + }; + + processor { + version = ""; + processor-type = ; + processor-status = ; + upgrade = ; + family = ; + family2 = ; + socket-design = ""; + serial = ""; + asset-tag = ""; + part-number = ""; + }; + + cache { + l1-cache { + socket-design = ""; + config = <(SMBIOS_CACHE_LEVEL_1 | + SMBIOS_CACHE_ENABLED | + SMBIOS_CACHE_OP_WB)>; + }; + + l2-cache { + socket-design = ""; + config = <(SMBIOS_CACHE_LEVEL_2 | + SMBIOS_CACHE_ENABLED | + SMBIOS_CACHE_OP_WB)>; + }; + }; + }; + }; +}; From patchwork Fri Dec 6 22:54:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Mao X-Patchwork-Id: 2019573 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=lwBUH7hR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4mq660FZz1yQw for ; Sat, 7 Dec 2024 09:57:06 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D2FF588ACB; Fri, 6 Dec 2024 23:57:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="lwBUH7hR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4DFA58870D; Fri, 6 Dec 2024 23:57:03 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5AC1088ACB for ; Fri, 6 Dec 2024 23:57:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-qt1-x834.google.com with SMTP id d75a77b69052e-46686a258c2so24061971cf.2 for ; Fri, 06 Dec 2024 14:57:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733525819; x=1734130619; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Jx5pICfHJmZwyNJdA82g06fbWvYJ824WZKEpNkwlfls=; b=lwBUH7hRV0IxwB3vUMJIFxXzUJbk64Y85k0KAWlin+8nvNe9KIqAkFLJr3JXP8DZMb G2X0hc73Kp3JpZbtoOTPcwH49tDFdUqlpYPldlm5zrRVzfOAqTX7x4RrSaIzKQScILln PahFJ8mq5d4nfiPrp0fAmqDYGpOWoYGWVVrl+mzeA+ZZi7Bj/wm9rRk41Mp74O4TmJpy ohb7IPeCZogYxV2ST2B/m0MxRkQJr3oxFqOW28SwftMTEStctTQGE+HMyykeuecn9sQa cSibVdQ2FpWRH48HkHBYQHhl9kwxw1vkOxSr+RmhD4JAMXUEVvNuNsmGUoA9uz9XTruf guyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733525819; x=1734130619; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jx5pICfHJmZwyNJdA82g06fbWvYJ824WZKEpNkwlfls=; b=YQ5yV6dxCjmoE2ayjU187PJzd1B3iwAHtyg/CMke23T+xsqwYzwsa92V2rXdNMA5De vps77kgIyJ+ZOAtbPxUkzc4DvxMwlirxc6Uh5sha+GC3v2ei+v/KJN8sgJkmNBntAcic BYHqdamLgy2eRiKs+lzZjykrF4vUiQC9SgMg978Yy/uuEKqaTMeLShmkkq+7qtS7T1Zi TUnTi9o+XKwVTvqmlyZf2JaJbfWIVm36k8h4JuznjVfE9jVvOe+Zdvoj2YqU0jwy7MIx NModAgEsw6kHixGGnRAXR3xXqMJgzc/WDhQiP13NykSKCnKXX8AAS9OIJwzLPWOqzpP1 dSFQ== X-Gm-Message-State: AOJu0YyGQ+iyqk0a3IByhIUHzQRSp5ZtJ4+AZ7TjvN4YA+TD8Ev1E7Ui dcFJik3zgN20V6D9qz35QGilBLhSfmpzF7MfLn+1Qt+AO1+hUTgpRoeQK7uSYguP7HtIEqNwpZe m X-Gm-Gg: ASbGncsMNzr90NijF4p+VLTZNF0RMI4Cnh7XsxFNO30UPsdsQFFIf4aMQ4vzJcekuu0 mdYGPkGvg7fe9lrPNX7PtQbk6XDid/y7O8uDxycqCUu8SoxqR+ja48DOYUBGJiO2Xf0w9fvSsE9 aVayGyQyBnSxtAL0yGY8Rlp8IUHtblC6vH4VzfCESQADeMDVV8SOJBYcBt0YTuUDSGe/8vP5GMH O9CHidOUC2r1UD5ytDgK24VsDv7jjONqICYp4uGreIoDyBz3vIVJSla8qI91ZQDeEsSVdyNCmJn 6o+ELVjaIyJHmVC9wjFJKoHUl6MbYrmufEggREodqL6Cw5xk X-Google-Smtp-Source: AGHT+IFaU5jl7xgCp1loifw+/eSD1LZANRKLfFA82h5PZZ8ddNo4EmfOC1qOMyRCoE99QbbHLWNy/A== X-Received: by 2002:a05:622a:18a1:b0:466:a584:69f8 with SMTP id d75a77b69052e-46734dbc98amr88297651cf.43.1733525818813; Fri, 06 Dec 2024 14:56:58 -0800 (PST) Received: from ubuntu.localdomain (pool-174-114-184-37.cpe.net.cable.rogers.com. [174.114.184.37]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-467296d4d7dsm26080871cf.34.2024.12.06.14.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 14:56:57 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Tom Rini , Tuomas Tynkkynen , Simon Glass , Patrick Rudolph , Heinrich Schuchardt , Ilias Apalodimas , =?utf-8?q?Marek_Beh=C3=BAn?= , Stefan Roese , Caleb Connolly , Jonas Karlman , Wan Yee Lau , Alexander Gendin , Masahisa Kojima , Max Krummenacher , Michal Simek , Francesco Dolcini , Sughosh Ganu , Peter Robinson Subject: [PATCH v3 09/10] cmd: update smbios cmd Date: Fri, 6 Dec 2024 14:54:26 -0800 Message-Id: <20241206225438.13866-10-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241206225438.13866-1-raymond.mao@linaro.org> References: <20241206225438.13866-1-raymond.mao@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Update the cmd according to the changes of the smbios library: 1. Refactor smbios cmd print functions to match the content defined by the specification. 2. Add new print functions for Type 3, 4 and 7. 3. Remove the fallback string "Not specified" from smbios_get_string, as the spec requires a NULL output for those undefined strings. 4. Update the test_cmd_smbios_sandbox pytest expected result to align with the smbios library changes and add new pytest test_cmd_smbios_sysinfo_verbose to test the verbose smbios output. Signed-off-by: Raymond Mao --- Changes in v2 - Initial patch. Move all changes related to cmd/smbios into this patch. - Combine with #9(v1) patch. Changes in v3 - Remove "Not specified" string from smbios_get_string. - Update pytest for smbios. cmd/smbios.c | 344 ++++++++++++++++++++++++++++++++--- include/smbios.h | 5 + test/py/tests/test_smbios.py | 18 +- 3 files changed, 336 insertions(+), 31 deletions(-) diff --git a/cmd/smbios.c b/cmd/smbios.c index 2122ac04e55..562dd7959be 100644 --- a/cmd/smbios.c +++ b/cmd/smbios.c @@ -14,16 +14,109 @@ DECLARE_GLOBAL_DATA_PTR; -static const char * const wakeup_type_strings[] = { - "Reserved", /* 0x00 */ - "Other", /* 0x01 */ - "Unknown", /* 0x02 */ - "APM Timer", /* 0x03 */ - "Modem Ring", /* 0x04 */ - "Lan Remote", /* 0x05 */ - "Power Switch", /* 0x06 */ - "PCI PME#", /* 0x07 */ - "AC Power Restored", /* 0x08 */ +static const struct str_lookup_table wakeup_type_strings[] = { + { SMBIOS_WAKEUP_TYPE_RESERVED, "Reserved" }, + { SMBIOS_WAKEUP_TYPE_OTHER, "Other" }, + { SMBIOS_WAKEUP_TYPE_UNKNOWN, "Unknown" }, + { SMBIOS_WAKEUP_TYPE_APM_TIMER, "APM Timer" }, + { SMBIOS_WAKEUP_TYPE_MODEM_RING, "Modem Ring" }, + { SMBIOS_WAKEUP_TYPE_LAN_REMOTE, "Lan Remote" }, + { SMBIOS_WAKEUP_TYPE_POWER_SWITCH, "Power Switch" }, + { SMBIOS_WAKEUP_TYPE_PCI_PME, "PCI PME#" }, + { SMBIOS_WAKEUP_TYPE_AC_POWER_RESTORED, "AC Power Restored" }, +}; + +static const struct str_lookup_table boardtype_strings[] = { + { SMBIOS_BOARD_TYPE_UNKNOWN, "Unknown" }, + { SMBIOS_BOARD_TYPE_OTHER, "Other" }, + { SMBIOS_BOARD_TYPE_SERVER_BLADE, "Server Blade" }, + { SMBIOS_BOARD_TYPE_CON_SWITCH, "Connectivity Switch" }, + { SMBIOS_BOARD_TYPE_SM_MODULE, "System Management Module" }, + { SMBIOS_BOARD_TYPE_PROCESSOR_MODULE, "Processor Module" }, + { SMBIOS_BOARD_TYPE_IO_MODULE, "I/O Module" }, + { SMBIOS_BOARD_TYPE_MEM_MODULE, "Memory Module" }, + { SMBIOS_BOARD_TYPE_DAUGHTER_BOARD, "Daughter board" }, + { SMBIOS_BOARD_TYPE_MOTHERBOARD, "Motherboard" }, + { SMBIOS_BOARD_TYPE_PROC_MEM_MODULE, "Processor/Memory Module" }, + { SMBIOS_BOARD_TYPE_PROC_IO_MODULE, "Processor/IO Module" }, + { SMBIOS_BOARD_TYPE_INTERCON, "Interconnect board" }, +}; + +static const struct str_lookup_table chassis_state_strings[] = { + { SMBIOS_STATE_OTHER, "Other" }, + { SMBIOS_STATE_UNKNOWN, "Unknown" }, + { SMBIOS_STATE_SAFE, "Safe" }, + { SMBIOS_STATE_WARNING, "Warning" }, + { SMBIOS_STATE_CRITICAL, "Critical" }, + { SMBIOS_STATE_NONRECOVERABLE, "Non-recoverable" }, +}; + +static const struct str_lookup_table chassis_security_strings[] = { + { SMBIOS_SECURITY_OTHER, "Other" }, + { SMBIOS_SECURITY_UNKNOWN, "Unknown" }, + { SMBIOS_SECURITY_NONE, "None" }, + { SMBIOS_SECURITY_EXTINT_LOCK, "External interface locked out" }, + { SMBIOS_SECURITY_EXTINT_EN, "External interface enabled" }, +}; + +static const struct str_lookup_table processor_type_strings[] = { + { SMBIOS_PROCESSOR_TYPE_OTHER, "Other" }, + { SMBIOS_PROCESSOR_TYPE_UNKNOWN, "Unknown" }, + { SMBIOS_PROCESSOR_TYPE_CENTRAL, "Central Processor" }, + { SMBIOS_PROCESSOR_TYPE_MATH, "Math Processor" }, + { SMBIOS_PROCESSOR_TYPE_DSP, "DSP Processor" }, + { SMBIOS_PROCESSOR_TYPE_VIDEO, "Video Processor" }, +}; + +static const struct str_lookup_table processor_family_strings[] = { + { SMBIOS_PROCESSOR_FAMILY_OTHER, "Other" }, + { SMBIOS_PROCESSOR_FAMILY_UNKNOWN, "Unknown" }, + { SMBIOS_PROCESSOR_FAMILY_RSVD, "Reserved" }, + { SMBIOS_PROCESSOR_FAMILY_ARMV7, "ARMv7" }, + { SMBIOS_PROCESSOR_FAMILY_ARMV8, "ARMv8" }, + { SMBIOS_PROCESSOR_FAMILY_RV32, "RISC-V RV32" }, + { SMBIOS_PROCESSOR_FAMILY_RV64, "RISC-V RV64" }, +}; + +static const struct str_lookup_table processor_upgrade_strings[] = { + { SMBIOS_PROCESSOR_UPGRADE_OTHER, "Other" }, + { SMBIOS_PROCESSOR_UPGRADE_UNKNOWN, "Unknown" }, + { SMBIOS_PROCESSOR_UPGRADE_NONE, "None" }, +}; + +static const struct str_lookup_table err_corr_type_strings[] = { + { SMBIOS_CACHE_ERRCORR_OTHER, "Other" }, + { SMBIOS_CACHE_ERRCORR_UNKNOWN, "Unknown" }, + { SMBIOS_CACHE_ERRCORR_NONE, "None" }, + { SMBIOS_CACHE_ERRCORR_PARITY, "Parity" }, + { SMBIOS_CACHE_ERRCORR_SBITECC, "Single-bit ECC" }, + { SMBIOS_CACHE_ERRCORR_MBITECC, "Multi-bit ECC" }, +}; + +static const struct str_lookup_table sys_cache_type_strings[] = { + { SMBIOS_CACHE_SYSCACHE_TYPE_OTHER, "Other" }, + { SMBIOS_CACHE_SYSCACHE_TYPE_UNKNOWN, "Unknown" }, + { SMBIOS_CACHE_SYSCACHE_TYPE_INST, "Instruction" }, + { SMBIOS_CACHE_SYSCACHE_TYPE_DATA, "Data" }, + { SMBIOS_CACHE_SYSCACHE_TYPE_UNIFIED, "Unified" }, +}; + +static const struct str_lookup_table associativity_strings[] = { + { SMBIOS_CACHE_ASSOC_OTHER, "Other" }, + { SMBIOS_CACHE_ASSOC_UNKNOWN, "Unknown" }, + { SMBIOS_CACHE_ASSOC_DMAPPED, "Direct Mapped" }, + { SMBIOS_CACHE_ASSOC_2WAY, "2-way Set-Associative" }, + { SMBIOS_CACHE_ASSOC_4WAY, "4-way Set-Associative" }, + { SMBIOS_CACHE_ASSOC_FULLY, "Fully Associative" }, + { SMBIOS_CACHE_ASSOC_8WAY, "8-way Set-Associative" }, + { SMBIOS_CACHE_ASSOC_16WAY, "16-way Set-Associative" }, + { SMBIOS_CACHE_ASSOC_12WAY, "12-way Set-Associative" }, + { SMBIOS_CACHE_ASSOC_24WAY, "24-way Set-Associative" }, + { SMBIOS_CACHE_ASSOC_32WAY, "32-way Set-Associative" }, + { SMBIOS_CACHE_ASSOC_48WAY, "48-way Set-Associative" }, + { SMBIOS_CACHE_ASSOC_64WAY, "64-way Set-Associative" }, + { SMBIOS_CACHE_ASSOC_20WAY, "20-way Set-Associative" }, + }; /** @@ -37,7 +130,7 @@ static const char *smbios_get_string(void *table, int index) { const char *str = (char *)table + ((struct smbios_header *)table)->length; - static const char fallback[] = "Not Specified"; + static const char fallback[] = ""; if (!index) return fallback; @@ -79,17 +172,53 @@ static void smbios_print_generic(struct smbios_header *table) } } -void smbios_print_str(const char *label, void *table, u8 index) +static void smbios_print_str(const char *label, void *table, u8 index) { printf("\t%s: %s\n", label, smbios_get_string(table, index)); } -const char *smbios_wakeup_type_str(u8 wakeup_type) +static void smbios_print_lookup_str(const struct str_lookup_table *table, + u16 index, u16 array_size, + const char *prefix) +{ + int i; + const char *str = NULL; + + for (i = 0; i < array_size; i++) { + if ((table + i)->idx == index) + str = (table + i)->str; + } + + if (str) + printf("\t%s: %s\n", prefix, str); + else + printf("\t%s: [%04x]\n", prefix, index); +} + +static void smbios_print_type0(struct smbios_type0 *table) { - if (wakeup_type >= ARRAY_SIZE(wakeup_type_strings)) - /* Values over 0x08 are reserved. */ - wakeup_type = 0; - return wakeup_type_strings[wakeup_type]; + printf("BIOS Information\n"); + smbios_print_str("Vendor", table, table->vendor); + smbios_print_str("BIOS Version", table, table->bios_ver); + /* Keep table->bios_start_segment as 0 for UEFI-based systems */ + smbios_print_str("BIOS Release Date", table, table->bios_release_date); + printf("\tBIOS ROM Size: 0x%02x\n", table->bios_rom_size); + printf("\tBIOS Characteristics: 0x%016llx\n", + table->bios_characteristics); + printf("\tBIOS Characteristics Extension Byte 1: 0x%02x\n", + table->bios_characteristics_ext1); + printf("\tBIOS Characteristics Extension Byte 2: 0x%02x\n", + table->bios_characteristics_ext2); + printf("\tSystem BIOS Major Release: 0x%02x\n", + table->bios_major_release); + printf("\tSystem BIOS Minor Release: 0x%02x\n", + table->bios_minor_release); + printf("\tEmbedded Controller Firmware Major Release: 0x%02x\n", + table->ec_major_release); + printf("\tEmbedded Controller Firmware Minor Release: 0x%02x\n", + table->ec_minor_release); + printf("\tExtended BIOS ROM Size: 0x%04x\n", + table->extended_bios_rom_size); } static void smbios_print_type1(struct smbios_type1 *table) @@ -101,8 +230,10 @@ static void smbios_print_type1(struct smbios_type1 *table) smbios_print_str("Serial Number", table, table->serial_number); if (table->hdr.length >= SMBIOS_TYPE1_LENGTH_V21) { printf("\tUUID: %pUl\n", table->uuid); - printf("\tWake-up Type: %s\n", - smbios_wakeup_type_str(table->wakeup_type)); + smbios_print_lookup_str(wakeup_type_strings, + table->wakeup_type, + ARRAY_SIZE(wakeup_type_strings), + "Wake-up Type"); } if (table->hdr.length >= SMBIOS_TYPE1_LENGTH_V24) { smbios_print_str("SKU Number", table, table->sku_number); @@ -112,25 +243,166 @@ static void smbios_print_type1(struct smbios_type1 *table) static void smbios_print_type2(struct smbios_type2 *table) { - u16 *handle; + int i; + u8 *addr = (u8 *)table + offsetof(struct smbios_type2, eos); - printf("Base Board Information\n"); + printf("Baseboard Information\n"); smbios_print_str("Manufacturer", table, table->manufacturer); smbios_print_str("Product Name", table, table->product_name); smbios_print_str("Version", table, table->version); smbios_print_str("Serial Number", table, table->serial_number); smbios_print_str("Asset Tag", table, table->asset_tag_number); - printf("\tFeature Flags: 0x%04x\n", table->feature_flags); + printf("\tFeature Flags: 0x%02x\n", table->feature_flags); smbios_print_str("Chassis Location", table, table->chassis_location); printf("\tChassis Handle: 0x%04x\n", table->chassis_handle); - smbios_print_str("Board Type", table, table->board_type); - printf("\tContained Object Handles: "); - handle = (void *)table->eos; - for (int i = 0; i < table->number_contained_objects; ++i) - printf("0x%04x ", handle[i]); + smbios_print_lookup_str(boardtype_strings, + table->board_type, + ARRAY_SIZE(boardtype_strings), + "Board Type"); + printf("\tNumber of Contained Object Handles: 0x%02x\n", + table->number_contained_objects); + if (!table->number_contained_objects) + return; + + printf("\tContained Object Handles:\n"); + for (i = 0; i < table->number_contained_objects; i++) { + printf("\t\tObject[%03d]:\n", i); + if (CONFIG_IS_ENABLED(HEXDUMP)) + print_hex_dump("\t\t", DUMP_PREFIX_OFFSET, 16, 1, addr, + sizeof(u16), false); + addr += sizeof(u16); + } printf("\n"); } +static void smbios_print_type3(struct smbios_type3 *table) +{ + int i; + u8 *addr = (u8 *)table + offsetof(struct smbios_type3, sku_number); + + printf("Baseboard Information\n"); + smbios_print_str("Manufacturer", table, table->manufacturer); + printf("\tType: 0x%02x\n", table->chassis_type); + smbios_print_str("Version", table, table->version); + smbios_print_str("Serial Number", table, table->serial_number); + smbios_print_str("Asset Tag", table, table->asset_tag_number); + smbios_print_lookup_str(chassis_state_strings, + table->bootup_state, + ARRAY_SIZE(chassis_state_strings), + "Boot-up State"); + smbios_print_lookup_str(chassis_state_strings, + table->power_supply_state, + ARRAY_SIZE(chassis_state_strings), + "Power Supply State"); + smbios_print_lookup_str(chassis_state_strings, + table->thermal_state, + ARRAY_SIZE(chassis_state_strings), + "Thermal State"); + smbios_print_lookup_str(chassis_security_strings, + table->security_status, + ARRAY_SIZE(chassis_security_strings), + "Security Status"); + printf("\tOEM-defined: 0x%08x\n", table->oem_defined); + printf("\tHeight: 0x%02x\n", table->height); + printf("\tNumber of Power Cords: 0x%02x\n", + table->number_of_power_cords); + printf("\tContained Element Count: 0x%02x\n", table->element_count); + printf("\tContained Element Record Length: 0x%02x\n", + table->element_record_length); + if (table->element_count) { + printf("\tContained Elements:\n"); + for (i = 0; i < table->element_count; i++) { + printf("\t\tElement[%03d]:\n", i); + if (CONFIG_IS_ENABLED(HEXDUMP)) + print_hex_dump("\t\t", DUMP_PREFIX_OFFSET, 16, + 1, addr, + table->element_record_length, + false); + printf("\t\tContained Element Type: 0x%02x\n", *addr); + printf("\t\tContained Element Minimum: 0x%02x\n", + *(addr + 1)); + printf("\t\tContained Element Maximum: 0x%02x\n", + *(addr + 2)); + addr += table->element_record_length; + } + } + smbios_print_str("SKU Number", table, *addr); +} + +static void smbios_print_type4(struct smbios_type4 *table) +{ + printf("Processor Information:\n"); + smbios_print_str("Socket Designation", table, table->socket_design); + smbios_print_lookup_str(processor_type_strings, + table->processor_type, + ARRAY_SIZE(processor_type_strings), + "Processor Type"); + smbios_print_lookup_str(processor_family_strings, + table->processor_family, + ARRAY_SIZE(processor_family_strings), + "Processor Family"); + smbios_print_str("Processor Manufacturer", table, + table->processor_manufacturer); + printf("\tProcessor ID word 0: 0x%08x\n", table->processor_id[0]); + printf("\tProcessor ID word 1: 0x%08x\n", table->processor_id[1]); + smbios_print_str("Processor Version", table, table->processor_version); + printf("\tVoltage: 0x%02x\n", table->voltage); + printf("\tExternal Clock: 0x%04x\n", table->external_clock); + printf("\tMax Speed: 0x%04x\n", table->max_speed); + printf("\tCurrent Speed: 0x%04x\n", table->current_speed); + printf("\tStatus: 0x%02x\n", table->status); + smbios_print_lookup_str(processor_upgrade_strings, + table->processor_upgrade, + ARRAY_SIZE(processor_upgrade_strings), + "Processor Upgrade"); + printf("\tL1 Cache Handle: 0x%04x\n", table->l1_cache_handle); + printf("\tL2 Cache Handle: 0x%04x\n", table->l2_cache_handle); + printf("\tL3 Cache Handle: 0x%04x\n", table->l3_cache_handle); + smbios_print_str("Serial Number", table, table->serial_number); + smbios_print_str("Asset Tag", table, table->asset_tag); + smbios_print_str("Part Number", table, table->part_number); + printf("\tCore Count: 0x%02x\n", table->core_count); + printf("\tCore Enabled: 0x%02x\n", table->core_enabled); + printf("\tThread Count: 0x%02x\n", table->thread_count); + printf("\tProcessor Characteristics: 0x%04x\n", + table->processor_characteristics); + smbios_print_lookup_str(processor_family_strings, + table->processor_family2, + ARRAY_SIZE(processor_family_strings), + "Processor Family 2"); + printf("\tCore Count 2: 0x%04x\n", table->core_count2); + printf("\tCore Enabled 2: 0x%04x\n", table->core_enabled2); + printf("\tThread Count 2: 0x%04x\n", table->thread_count2); + printf("\tThread Enabled: 0x%04x\n", table->thread_enabled); +} + +static void smbios_print_type7(struct smbios_type7 *table) +{ + printf("Cache Information:\n"); + smbios_print_str("Socket Designation", table, + table->socket_design); + printf("\tCache Configuration: 0x%04x\n", table->config.data); + printf("\tMaximum Cache Size: 0x%04x\n", table->max_size.data); + printf("\tInstalled Size: 0x%04x\n", table->inst_size.data); + printf("\tSupported SRAM Type: 0x%04x\n", table->supp_sram_type.data); + printf("\tCurrent SRAM Type: 0x%04x\n", table->curr_sram_type.data); + printf("\tCache Speed: 0x%02x\n", table->speed); + smbios_print_lookup_str(err_corr_type_strings, + table->err_corr_type, + ARRAY_SIZE(err_corr_type_strings), + "Error Correction Type"); + smbios_print_lookup_str(sys_cache_type_strings, + table->sys_cache_type, + ARRAY_SIZE(sys_cache_type_strings), + "System Cache Type"); + smbios_print_lookup_str(associativity_strings, + table->associativity, + ARRAY_SIZE(associativity_strings), + "Associativity"); + printf("\tMaximum Cache Size 2: 0x%08x\n", table->max_size2.data); + printf("\tInstalled Cache Size 2: 0x%08x\n", table->inst_size2.data); +} + static void smbios_print_type127(struct smbios_type127 *table) { printf("End Of Table\n"); @@ -192,13 +464,25 @@ static int do_smbios(struct cmd_tbl *cmdtp, int flag, int argc, pos->handle, pos->type, pos->length, (unsigned long long)map_to_sysmem(pos)); switch (pos->type) { - case 1: + case SMBIOS_BIOS_INFORMATION: + smbios_print_type0((struct smbios_type0 *)pos); + break; + case SMBIOS_SYSTEM_INFORMATION: smbios_print_type1((struct smbios_type1 *)pos); break; - case 2: + case SMBIOS_BOARD_INFORMATION: smbios_print_type2((struct smbios_type2 *)pos); break; - case 127: + case SMBIOS_SYSTEM_ENCLOSURE: + smbios_print_type3((struct smbios_type3 *)pos); + break; + case SMBIOS_PROCESSOR_INFORMATION: + smbios_print_type4((struct smbios_type4 *)pos); + break; + case SMBIOS_CACHE_INFORMATION: + smbios_print_type7((struct smbios_type7 *)pos); + break; + case SMBIOS_END_OF_TABLE: smbios_print_type127((struct smbios_type127 *)pos); break; default: diff --git a/include/smbios.h b/include/smbios.h index 18f568f9b0d..b5fed57aba2 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -38,6 +38,11 @@ enum { #define SMBIOS_INTERMEDIATE_OFFSET 16 #define SMBIOS_STRUCT_EOS_BYTES 2 +struct str_lookup_table { + u16 idx; + const char *str; +}; + struct __packed smbios_entry { u8 anchor[4]; u8 checksum; diff --git a/test/py/tests/test_smbios.py b/test/py/tests/test_smbios.py index 82b0b689830..0405a9b9d38 100644 --- a/test/py/tests/test_smbios.py +++ b/test/py/tests/test_smbios.py @@ -32,10 +32,26 @@ def test_cmd_smbios_sandbox(u_boot_console): """Run the smbios command on the sandbox""" output = u_boot_console.run_command('smbios') assert 'DMI type 0,' in output - assert 'String 1: U-Boot' in output + assert 'Vendor: U-Boot' in output assert 'DMI type 1,' in output assert 'Manufacturer: sandbox' in output assert 'DMI type 2,' in output assert 'DMI type 3,' in output assert 'DMI type 4,' in output assert 'DMI type 127,' in output + +@pytest.mark.buildconfigspec('cmd_smbios') +@pytest.mark.buildconfigspec('sysinfo_smbios') +@pytest.mark.buildconfigspec('generate_smbios_table_verbose') +def test_cmd_smbios_sysinfo_verbose(u_boot_console): + """Run the smbios command""" + output = u_boot_console.run_command('smbios') + assert 'DMI type 0,' in output + assert 'Vendor: U-Boot' in output + assert 'DMI type 1,' in output + assert 'Manufacturer: linux' in output + assert 'DMI type 2,' in output + assert 'DMI type 3,' in output + assert 'DMI type 7,' in output + assert 'DMI type 4,' in output + assert 'DMI type 127,' in output From patchwork Fri Dec 6 22:54:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Mao X-Patchwork-Id: 2019574 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=jn0BpVjI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y4mqP1pjtz1yQw for ; Sat, 7 Dec 2024 09:57:21 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4147688815; Fri, 6 Dec 2024 23:57:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="jn0BpVjI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 08EEB8870D; Fri, 6 Dec 2024 23:57:18 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D61A088815 for ; Fri, 6 Dec 2024 23:57:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-46686a258c2so24064311cf.2 for ; Fri, 06 Dec 2024 14:57:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733525834; x=1734130634; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jPouc1XXuLoKka/JGIsG0i0OsBuMBfzWPvr2c1bXqVo=; b=jn0BpVjIgS6CAthqzPaV4O+/VYQFQ+Fdhq5Xz1kO9g8le/9vfrXY9K07/9uB1ZQN96 Wp2PTldSizAqML9XbZG7MB7C0MDFuIHPxKLlhGJ+W+YdLlQ7I5lb+1RXR4xDpMEtlHJK rbIik7Uqtq0YQ8tMqITSkVZdyrEq4eLJ2kRBG05otixhegX2MQ2cNsLJdLsI0Ju834qs 6aOECjY38CITuZWgGI30dlGom3Uj0bxCSrtzzT71pHtxZpHTjInbr0hEYOWoksdgQKPI m6bCOSxsW6WIvsjfMRFEnRDACnZGp/n1C1FdueCfec1/UYAFMvaUDpk0stOi8eK4BV2Z jNbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733525834; x=1734130634; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jPouc1XXuLoKka/JGIsG0i0OsBuMBfzWPvr2c1bXqVo=; b=pN3++U9ueTUzl/nU0ddPbqLUL0P5YK3nJMZCkN7/xNe700xWl6EWZC+S8w9lRfzFvS 4RDpB6LfdyfJNnD/blPQxlKFhs7v0bca1MdiyWRmYUng8TNYzFa6ufqPBPMbOjn+eUwg uWAY5DFaQmNpN1tA1SGl9sc/sw20YtS4X21jap6Ux52tTRSN4SfKlnrOln+sFPpmaEji DKveeCwF3+nrwfxZTtCcTGKxeQkG9KLjFtCRk6AfaSftDegZG2DUF7P/qDckA1/U8+Kl kH1KN76F8BJsPU+oMoHh6a1xw6zAssHRoLVA3s/flP8yrw/MM9RoGrrE9nbAXOGDA5Ic hBJQ== X-Gm-Message-State: AOJu0Yyo86DUtuhgRp91PDiKFZWZhYlRHzhpLl/xx2B/3KiWLIhDuFNZ jhpk46gfNqygXWFPcs0Wch/L5F6QGiV/ALAuZGl4lKbyOE7MvHbUoC6PFfJnLsN3PTPm1dHnbDT h X-Gm-Gg: ASbGncu7kNIU0U09IrbZFQf1yHG/bKY+Xsheh3f98spY0VeJMJobYYxInqzJBWUkq8z PBYfEgrbZHT0LQwUq7zCTkZIgxWqQhatPid2HcvwcmLQ7klLjYCT0uCZMKueTyyAsYVz+aiKzcT CN/u6YJi09CY1opkluMCcgdy5qYrJY/ig1iiScW9AYqYZrBXH6zWjQb5B7SJzZ5IVjsQ4rNfME0 g5EbtMpJiMK6L9CnlxnF9F/r/SgjiISlApat3eMfbEuAuAYVXe+sbWgPyhJjP1m78tjL61nqxdq xqwzwZFnq1XLGd8m/80AOzyd3zWhOLFWMN08i4IIDx/G6MaI X-Google-Smtp-Source: AGHT+IEhDxFIPFb/ASICwDnqtziL/KN3aDeNnVSJn8e57LldEyytlQpZUshkZBBtgDxEKuzGoWQP9A== X-Received: by 2002:ac8:5d12:0:b0:466:a254:7341 with SMTP id d75a77b69052e-46734cc4565mr85789161cf.17.1733525833114; Fri, 06 Dec 2024 14:57:13 -0800 (PST) Received: from ubuntu.localdomain (pool-174-114-184-37.cpe.net.cable.rogers.com. [174.114.184.37]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-467296d4d7dsm26080871cf.34.2024.12.06.14.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 14:57:12 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Simon Glass , Tom Rini , Tuomas Tynkkynen , Patrick Rudolph , Heinrich Schuchardt , Ilias Apalodimas , =?utf-8?q?Marek_Beh=C3=BAn?= , Stefan Roese , Alexander Gendin , Caleb Connolly , Wan Yee Lau , Jonas Karlman , Masahisa Kojima , Michal Simek , Max Krummenacher , Francesco Dolcini , Sughosh Ganu , Peter Robinson Subject: [PATCH v3 10/10] configs: Enable sysinfo for QEMU Arm64 Date: Fri, 6 Dec 2024 14:54:27 -0800 Message-Id: <20241206225438.13866-11-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241206225438.13866-1-raymond.mao@linaro.org> References: <20241206225438.13866-1-raymond.mao@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Enable sysinfo smbios by default for arm64. When SYSINFO_SMBIOS is enabled, disable QFW_SMBIOS. Signed-off-by: Raymond Mao Reviewed-by: Simon Glass --- Changes in v2 - None. Changes in v3 - add CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE configs/qemu_arm64_defconfig | 3 +++ drivers/misc/Kconfig | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig index 8dffb91e93b..31656699d82 100644 --- a/configs/qemu_arm64_defconfig +++ b/configs/qemu_arm64_defconfig @@ -62,6 +62,8 @@ CONFIG_PCIE_ECAM_GENERIC=y CONFIG_SCSI=y CONFIG_DEBUG_UART_PL011=y CONFIG_DEBUG_UART_SHIFT=2 +CONFIG_SYSINFO=y +CONFIG_SYSINFO_SMBIOS=y CONFIG_SYSRESET=y CONFIG_SYSRESET_CMD_POWEROFF=y CONFIG_SYSRESET_PSCI=y @@ -71,3 +73,4 @@ CONFIG_USB_EHCI_PCI=y CONFIG_SEMIHOSTING=y CONFIG_MBEDTLS_LIB=y CONFIG_TPM=y +CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE=y diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 6009d55f400..da84b35e804 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -568,7 +568,7 @@ config QFW_MMIO config QFW_SMBIOS bool default y - depends on QFW && SMBIOS && !SANDBOX + depends on QFW && SMBIOS && !SANDBOX && !SYSINFO_SMBIOS help Hidden option to read SMBIOS tables from QEMU.