From patchwork Thu Oct 22 14:19:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1386289 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=IBz2/cH+; dkim-atps=neutral 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CH8fm160rz9s0b for ; Fri, 23 Oct 2020 01:21:04 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5C75682462; Thu, 22 Oct 2020 16:20:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="IBz2/cH+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E280B82468; Thu, 22 Oct 2020 16:20:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) (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 2097E82434 for ; Thu, 22 Oct 2020 16:20:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x144.google.com with SMTP id g7so1845950ilr.12 for ; Thu, 22 Oct 2020 07:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kuRZ9ibuFiUHRBauPNwBLtPAZHvFw0c/li0xKHDp+Qs=; b=IBz2/cH+pzgDtXS9gptN/yf0gyZNKXWCZ+2tyjUvZjfvvFqBuEKcfb57L73VuyB34x XPem1aa991i9YSsr4oNihNEgEACvZOXJA/PCaKDjd6CjpUw2cfvMk7hSN6TB2EEB9vzn e7kzmKDWdkjS0Qkyo6ftFF4did3pqaNo6WvJw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kuRZ9ibuFiUHRBauPNwBLtPAZHvFw0c/li0xKHDp+Qs=; b=buR7nRnlwLGBOyXy+wGa1bWCY8wLPw0lECcCtWdYi+fkr1xxcfXYFOXDB/U5cXFxFz 1e4wx8YkpRmHmFpD9CW3LxrRnIHeUVuQmQ4qXSRDBA1RZLNUAGgFPscGlvBy/nOxwmaB ouwTnrQJJsQfr5DNy4XidpGLz+NeDDS0r3HKGeOojKUf+WsC2Rf6tQX8MDeT78c/RCDp ZUjgmpbxxulNHcNOHw8ZGmq4OsoD+1U8f26fgBzMLog7cWZFHCPZ7UVYdPAa6yu4NRPU B7Z7VGWXikbQ99q2HkWnZ6jwMGWbsli9pY9h+vGr8dYbzVXKE555M9WXUAXzWGvkGkcW cMUA== X-Gm-Message-State: AOAM530RFcg6AaTgyWWIJrhoArpmZGoJ3qlHYL2DNvj7cloc+e/MyEqD x0tEnrXLMQxxnq7swbgZbAjBjSJXPZE0dWTt X-Google-Smtp-Source: ABdhPJzjMDZzyBF4mGgUhO/1EHjlsr4JFpK+PA+MV4Ah/4iZsF9/Fz6XqdJeQaoljMd2F2tRsNBTFw== X-Received: by 2002:a92:bb0d:: with SMTP id w13mr2183256ili.168.1603376401650; Thu, 22 Oct 2020 07:20:01 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id j3sm1211115ilq.85.2020.10.22.07.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 07:20:01 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Bernhard Messerklinger , Wolfgang Wallner , Walter Lozano , Simon Glass Subject: [PATCH v4 04/13] smbios: Allow properties to come from the device tree Date: Thu, 22 Oct 2020 08:19:39 -0600 Message-Id: <20201022141949.711984-4-sjg@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201022141949.711984-1-sjg@chromium.org> References: <20201022141949.711984-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Support a way to put SMBIOS properties in the device tree. These can be placed in a 'board' device in an 'smbios' subnode. Signed-off-by: Simon Glass --- Changes in v4: - Fix build error with vexpress_ca9x4 Changes in v3: - Use a different binding with subnodes for each table type lib/smbios.c | 98 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 17 deletions(-) diff --git a/lib/smbios.c b/lib/smbios.c index b0f5e936044..be72a98c49d 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -17,6 +17,18 @@ #include #endif +/** + * struct smbios_write_method - Informaiton about a table-writing function + * + * @write: Function to call + * @subnode_name: Name of subnode which has the information for this function, + * NULL if none + */ +struct smbios_write_method { + smbios_write_type write; + const char *subnode_name; +}; + /** * smbios_add_string() - add a string to the string area * @@ -52,6 +64,43 @@ static int smbios_add_string(char *start, const char *str) } } +/** + * smbios_add_prop_default() - Add a property from the device tree or default + * + * @start: string area start address + * @node: node containing the information to write (ofnode_null() if none) + * @prop: property to write + * @def: default string if the node has no such property + * @return 0 if not found, else SMBIOS string number (1 or more) + */ +static int smbios_add_prop_default(char *start, ofnode node, const char *prop, + const char *def) +{ + const char *str = NULL; + + if (IS_ENABLED(CONFIG_OF_CONTROL)) + str = ofnode_read_string(node, prop); + if (str) + return smbios_add_string(start, str); + else if (def) + return smbios_add_string(start, def); + + return 0; +} + +/** + * smbios_add_prop() - Add a property from the device tree + * + * @start: string area start address + * @node: node containing the information to write (ofnode_null() if none) + * @prop: property to write + * @return 0 if not found, else SMBIOS string number (1 or more) + */ +static int smbios_add_prop(char *start, ofnode node, const char *prop) +{ + return smbios_add_prop_default(start, node, prop, NULL); +} + /** * smbios_string_table_len() - compute the string area size * @@ -120,11 +169,15 @@ static int smbios_write_type1(ulong *current, int handle, ofnode node) t = map_sysmem(*current, len); memset(t, 0, sizeof(struct smbios_type1)); fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle); - t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER); - t->product_name = smbios_add_string(t->eos, CONFIG_SMBIOS_PRODUCT_NAME); + t->manufacturer = smbios_add_prop_default(t->eos, node, "manufactuer", + CONFIG_SMBIOS_MANUFACTURER); + t->product_name = smbios_add_prop_default(t->eos, node, "product", + CONFIG_SMBIOS_PRODUCT_NAME); if (serial_str) { - strncpy((char *)t->uuid, serial_str, sizeof(t->uuid)); t->serial_number = smbios_add_string(t->eos, serial_str); + strncpy((char *)t->uuid, serial_str, sizeof(t->uuid)); + } else { + t->serial_number = smbios_add_prop(t->eos, node, "serial"); } len = t->length + smbios_string_table_len(t->eos); @@ -142,8 +195,10 @@ static int smbios_write_type2(ulong *current, int handle, ofnode node) t = map_sysmem(*current, len); memset(t, 0, sizeof(struct smbios_type2)); fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle); - t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER); - t->product_name = smbios_add_string(t->eos, CONFIG_SMBIOS_PRODUCT_NAME); + t->manufacturer = smbios_add_prop_default(t->eos, node, "manufactuer", + CONFIG_SMBIOS_MANUFACTURER); + t->product_name = smbios_add_prop_default(t->eos, node, "product", + CONFIG_SMBIOS_PRODUCT_NAME); t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING; t->board_type = SMBIOS_BOARD_MOTHERBOARD; @@ -162,7 +217,8 @@ static int smbios_write_type3(ulong *current, int handle, ofnode node) t = map_sysmem(*current, len); memset(t, 0, sizeof(struct smbios_type3)); fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle); - t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER); + t->manufacturer = smbios_add_prop_default(t->eos, node, "manufactuer", + CONFIG_SMBIOS_MANUFACTURER); t->chassis_type = SMBIOS_ENCLOSURE_DESKTOP; t->bootup_state = SMBIOS_STATE_SAFE; t->power_supply_state = SMBIOS_STATE_SAFE; @@ -262,19 +318,19 @@ static int smbios_write_type127(ulong *current, int handle, ofnode node) return len; } -static smbios_write_type smbios_write_funcs[] = { - smbios_write_type0, - smbios_write_type1, - smbios_write_type2, - smbios_write_type3, - smbios_write_type4, - smbios_write_type32, - smbios_write_type127 +static struct smbios_write_method smbios_write_funcs[] = { + { smbios_write_type0, }, + { smbios_write_type1, "system", }, + { smbios_write_type2, "baseboard", }, + { smbios_write_type3, "chassis", }, + { smbios_write_type4, }, + { smbios_write_type32, }, + { smbios_write_type127 }, }; ulong write_smbios_table(ulong addr) { - ofnode node = ofnode_null(); + ofnode parent_node = ofnode_null(); struct smbios_entry *se; struct udevice *dev; ulong table_addr; @@ -289,7 +345,7 @@ ulong write_smbios_table(ulong addr) if (IS_ENABLED(CONFIG_OF_CONTROL)) { uclass_first_device(UCLASS_SYSINFO, &dev); if (dev) - node = dev_read_subnode(dev, "smbios"); + parent_node = dev_read_subnode(dev, "smbios"); } /* 16 byte align the table address */ @@ -304,7 +360,15 @@ ulong write_smbios_table(ulong addr) /* populate minimum required tables */ for (i = 0; i < ARRAY_SIZE(smbios_write_funcs); i++) { - int tmp = smbios_write_funcs[i]((ulong *)&addr, handle++, node); + const struct smbios_write_method *method; + ofnode node = ofnode_null(); + int tmp; + + method = &smbios_write_funcs[i]; + if (IS_ENABLED(CONFIG_OF_CONTROL) && method->subnode_name) + node = ofnode_find_subnode(parent_node, + method->subnode_name); + tmp = method->write((ulong *)&addr, handle++, node); max_struct_size = max(max_struct_size, tmp); len += tmp;