Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3468668pxb; Mon, 4 Apr 2022 17:57:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwf7zWUVC7Mmb0X5u43f0blwGw/z4yM9p6hd6LzDdypUXpDdsCt+jw5ruvRB+f7vDWZ9jU/ X-Received: by 2002:a17:90a:64c8:b0:1ca:a570:261 with SMTP id i8-20020a17090a64c800b001caa5700261mr1089849pjm.42.1649120274393; Mon, 04 Apr 2022 17:57:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649120274; cv=none; d=google.com; s=arc-20160816; b=nT6+C0msxNATkjkYoqWJ19vcdeQLf7NoptC6cjsUygdPGbpJWXgoa7mNMTtdTvAcBW l7TccYx6oj5b7diRrdIutPE7IdbUorQtAcpOsZNuVVVwv5NCFRlq91GymDqJ9s4RMwYG 8UE6bu3KdLGeTibon20ZIezsfGKmzzXtJYrK5HMwFxKoHoZMk6iS0ihXmb4YQEu1xGXB cjinofinHcqDL69HNs9dpTcgmVVX13JNSRi/ADuqo+IggSi+e18iNYV7VbSBH0wBEX3O sEACbYi3otNAaL1dl4gfowbTApSlzWoA9su6gjxcXA6fzrdxbOGAmtfRYgI7oMBRNqVW 9Gdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=j904Obz7z0f9BMGRXiWX07Usnwp/ORQFPcf7fLFab5g=; b=s6DApbDlaKPmXKtNIMVAVF31EQRigx7hajJwkDV2YBWygeCZMBw2fshwPa3ea1Gchs eB1jKEqJs9tfoT5K1SWV5BgjzOx7Jv/zhE0Sy4EHA8mty3rDLWts/mPPMVgcLO8hqyhQ ZK71l5i7l66pQVCoFJiE6jO0ewUeaOIZ60rkErECbz8zI3bis8Jx/9nKXp32idGBTCsT 7kRr4UwpPVAp9vD2F3ukwPmpEtjfMkjTC9cFKT6JlLUepnczDVAOMeghPKrBvHX/3RLX Jdia/VI5JlNQlHqiTrlYggPUogKqLotlD1tcYzXXUVfMPWllGk8d5ec6OjOUlklndBGP YJjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=jrxnZimP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k68-20020a633d47000000b0039958f2ceb2si1034923pga.101.2022.04.04.17.57.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 17:57:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=jrxnZimP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4CB27139861; Mon, 4 Apr 2022 17:04:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355503AbiDDJ7t (ORCPT + 99 others); Mon, 4 Apr 2022 05:59:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355176AbiDDJ7Y (ORCPT ); Mon, 4 Apr 2022 05:59:24 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [IPv6:2a01:4f8:151:8464::1:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E4083C48D for ; Mon, 4 Apr 2022 02:57:28 -0700 (PDT) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 2EEA222255; Mon, 4 Apr 2022 11:57:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1649066246; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j904Obz7z0f9BMGRXiWX07Usnwp/ORQFPcf7fLFab5g=; b=jrxnZimPuYcg7vhCzupFLMjC648tABQHXkZGvNzwa9loh5/w38AxSF79HG4Oc8Ogf6hU3U dJtO2LIPEYkNJ1Nwb2tWOkFO3syJ+71ODjRcprZBHmb2kiA37cD2+gfK2XKWtsDeImW+Oy vBx8aq5h60V3C9WpviDFdaEEDY4MBE4= From: Michael Walle To: linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Shawn Guo , Li Yang , Ulf Hansson , Sudeep Holla , Arnd Bergmann , Dan Carpenter , Michael Walle Subject: [PATCH RESEND v2 7/7] soc: fsl: guts: add serial_number support Date: Mon, 4 Apr 2022 11:56:09 +0200 Message-Id: <20220404095609.3932782-8-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220404095609.3932782-1-michael@walle.cc> References: <20220404095609.3932782-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Most layerscapes provide a security fuse processor where the vendor will store a unique id per part. Unfortunately, we cannot use the corresponding efuse driver because this driver needs to be ready early during the boot phase. To get the unique identifier, we just need to access two registers. Thus we just search the device tree for the corresponding device, map its memory to read the id and then unmap it again. Because it is likely that the offset within the fuses is dependent on the SoC, we need a per SoC data. Also, the compatible string is different among the SoCs. For now, this add support for the LS1028A SoC. Signed-off-by: Michael Walle Acked-by: Arnd Bergmann --- drivers/soc/fsl/guts.c | 48 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/drivers/soc/fsl/guts.c b/drivers/soc/fsl/guts.c index 370be923aa0f..27035de062f8 100644 --- a/drivers/soc/fsl/guts.c +++ b/drivers/soc/fsl/guts.c @@ -20,6 +20,11 @@ struct fsl_soc_die_attr { u32 mask; }; +struct fsl_soc_data { + const char *sfp_compat; + u32 uid_offset; +}; + /* SoC die attribute definition for QorIQ platform */ static const struct fsl_soc_die_attr fsl_soc_die[] = { /* @@ -110,6 +115,33 @@ static const struct fsl_soc_die_attr *fsl_soc_die_match( return NULL; } +static u64 fsl_guts_get_soc_uid(const char *compat, unsigned int offset) +{ + struct device_node *np; + void __iomem *sfp_base; + u64 uid; + + np = of_find_compatible_node(NULL, NULL, compat); + if (!np) + return 0; + + sfp_base = of_iomap(np, 0); + + uid = ioread32(sfp_base + offset); + uid <<= 32; + uid |= ioread32(sfp_base + offset + 4); + + iounmap(sfp_base); + of_node_put(np); + + return uid; +} + +static const struct fsl_soc_data ls1028a_data = { + .sfp_compat = "fsl,ls1028a-sfp", + .uid_offset = 0x21c, +}; + /* * Table for matching compatible strings, for device tree * guts node, for Freescale QorIQ SOCs. @@ -138,7 +170,7 @@ static const struct of_device_id fsl_guts_of_match[] = { { .compatible = "fsl,ls1012a-dcfg", }, { .compatible = "fsl,ls1046a-dcfg", }, { .compatible = "fsl,lx2160a-dcfg", }, - { .compatible = "fsl,ls1028a-dcfg", }, + { .compatible = "fsl,ls1028a-dcfg", .data = &ls1028a_data}, {} }; @@ -147,16 +179,20 @@ static int __init fsl_guts_init(void) struct soc_device_attribute *soc_dev_attr; static struct soc_device *soc_dev; const struct fsl_soc_die_attr *soc_die; + const struct fsl_soc_data *soc_data; + const struct of_device_id *match; struct ccsr_guts __iomem *regs; const char *machine = NULL; struct device_node *np; bool little_endian; + u64 soc_uid = 0; u32 svr; int ret; - np = of_find_matching_node_and_match(NULL, fsl_guts_of_match, NULL); + np = of_find_matching_node_and_match(NULL, fsl_guts_of_match, &match); if (!np) return 0; + soc_data = match->data; regs = of_iomap(np, 0); if (IS_ERR(regs)) { @@ -204,6 +240,13 @@ static int __init fsl_guts_init(void) if (!soc_dev_attr->revision) goto err_nomem; + if (soc_data) + soc_uid = fsl_guts_get_soc_uid(soc_data->sfp_compat, + soc_data->uid_offset); + if (soc_uid) + soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX", + soc_uid); + soc_dev = soc_device_register(soc_dev_attr); if (IS_ERR(soc_dev)) { ret = PTR_ERR(soc_dev); @@ -224,6 +267,7 @@ static int __init fsl_guts_init(void) kfree(soc_dev_attr->family); kfree(soc_dev_attr->soc_id); kfree(soc_dev_attr->revision); + kfree(soc_dev_attr->serial_number); kfree(soc_dev_attr); return ret; -- 2.30.2