From patchwork Thu Nov 2 07:49:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viacheslav X-Patchwork-Id: 13443491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97AACC4167D for ; Thu, 2 Nov 2023 07:49:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Sf/TwMB+Fw3wzBTqj8LGxJNW4ufXGEU6l+BWEVlIg4Q=; b=kYMARihKg5Qvdq 3ixOpAlBimH2z0bzWCO5cM7QBeTvGavQ0eDj7S/tFe/jdTYrNr6uKVEGGdF+ouSL9qRBabNkXi3uG J2PPA1fnh2XnK7/utfMu75RBDKTL8I8/xMZ6SRvYjuR5kaDGjXEZ7OVW10WM0kv+4Z76HN1gRo2x9 8Z0xKIBNsuA4qO6n+M4Ce97V5NgHZxAb7ozft0Sc+j/pOdTLyjxF2Q1DzqmtA78qUB3OeJk8FSUlc I8rAEH0ApT7B5/oxf/H3S/E+kh83IM1TcAFSkgxEA+kPQqCSSwVTWjiacYMyOo6HTTKr72nAuiiCQ uOipWOJ/MZ+4lAa0Wv2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qySSM-008vFx-0Q; Thu, 02 Nov 2023 07:49:34 +0000 Received: from mx.msync.work ([62.182.159.68]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qySSE-008vEH-2y; Thu, 02 Nov 2023 07:49:32 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 25750147B80; Thu, 2 Nov 2023 07:49:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lexina.in; s=dkim; t=1698911364; h=from:subject:date:message-id:to:mime-version: content-transfer-encoding:in-reply-to:references; bh=cD6HIvwS1+eD7lmzk4U069SbWiB68SgbaID0yXccmhM=; b=XXDo3QUDQez6r8fp1+UL4OuCuhJxp2tWksc8eDpgFkHOaUPxZJmoa2+uMCxI5iTvhJknNt t1x3grkVoj+J7HAnFgMqjusL1kqqsSE+jw5avzCrhUfSgMcLwbbUpNod1Yx0ysl1s3sI5G WbWE6IDGiJuNqYaJSgsAN/38CTqhT6dwlqmEHzLb7EZzT3FKdYzCsILoDyT42qMeGxLRPt DWDGpmYr3M79+0X97AwRpev0DNOthfXdFNMtzclvZG9X2BWqJnjV4mdUxiJwv4pfMiU99r 2crUzil/ADrHYLiCALecVnT5Kj5DsE0OnN/8toOwhpcVAoBCStukjn9c3wCYKg== From: Viacheslav Bocharov To: Neil Armstrong , Kevin Hilman , Martin Blumenstingl , linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 1/4] firmware: meson-sm: change sprintf to scnprintf Date: Thu, 2 Nov 2023 10:49:13 +0300 Message-Id: <20231102074916.3280809-2-adeep@lexina.in> In-Reply-To: <20231102074916.3280809-1-adeep@lexina.in> References: <20231102074916.3280809-1-adeep@lexina.in> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231102_004927_532261_B6FE759A X-CRM114-Status: UNSURE ( 9.14 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org Update sprintf in serial_show frunction to scnprintf command to prevent sysfs buffer overflow (buffer always is PAGE_SIZE bytes). Signed-off-by: Viacheslav Bocharov --- drivers/firmware/meson/meson_sm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c index ed60f1103053..c1c694b485ee 100644 --- a/drivers/firmware/meson/meson_sm.c +++ b/drivers/firmware/meson/meson_sm.c @@ -265,7 +265,7 @@ static ssize_t serial_show(struct device *dev, struct device_attribute *attr, return ret; } - ret = sprintf(buf, "%12phN\n", &id_buf[SM_CHIP_ID_OFFSET]); + ret = scnprintf(buf, PAGE_SIZE, "%12phN\n", &id_buf[SM_CHIP_ID_OFFSET]); kfree(id_buf); From patchwork Thu Nov 2 07:49:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viacheslav X-Patchwork-Id: 13443492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE0D4C0018A for ; Thu, 2 Nov 2023 07:50:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DeGy+A91rTixJkYtgBwSLeqkXmsiQApVuRxZjPIcsZQ=; b=evFWcZ5NCN1ZMF GufmDMGtsq8/CLAzMicgrZ++VHjyBLhcqZCZilNE+tO+kmDi307MPFpCApkowkuHH+fGUWXut6paa mN3eeKUgoudaX7BYPCnDHRJ+9wp/zFA39+ljHdE3B/aAnUjEoZhXjPYXtlowa2CC8lIieKEUUUhB0 beB/zSPVylrIZTAwc+SjZmjh6Aw5uvNg0cc2D9JnOwtH4T/ixYuk0pE0r9jydbTCmUkSD0ELR3wOX ftW/wO70WBm5RF6oh1HZYoFYdGRlF6gF3nUEwfgClQXsIUGQ1r8sYrGYppqElqRgURezWn4caAwnw 71mY3c1cWcCKPi92XSpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qySSR-008vJ2-1Q; Thu, 02 Nov 2023 07:49:39 +0000 Received: from mx.msync.work ([62.182.159.68]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qySSE-008vEI-2y; Thu, 02 Nov 2023 07:49:37 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id BBE92147B81; Thu, 2 Nov 2023 07:49:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lexina.in; s=dkim; t=1698911364; h=from:subject:date:message-id:to:mime-version: content-transfer-encoding:in-reply-to:references; bh=7g9Pd3xFizPczsPF4psnwonGnJy6OcmmDqrxbFQxHFA=; b=M+uw87MkkWBDPTm4zcqCcvkJd1HPT1Mp+O3c6qIgnCLra9izQxIQo39ejYoKlNdR9sdnwU TDxY8sJRRkQeTJYXryyBrXgbOZuZwHGbbWSMFa9cA6S4mRdGXIQbtwUr58eEuO32ceqwkY MS2gNiBWZ9r1RVH/1URcfdsseaU0QvUNGL+Vx6Z1rGAVuue3J8oetuCMprR+f2lOnrCrcb vp0GgTtcpBBLxiEQ4w0kLqOeYEMJnYEopdtGWIeoEQg7YFRbV4hITOZGCZDlQvZz/aLaHR 70WDEDufucemByUhdBL/q4Y3uZd3NCq1h/8EY+s402mHOB253Tfa6EIBCXt4Zg== From: Viacheslav Bocharov To: Neil Armstrong , Kevin Hilman , Martin Blumenstingl , linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 2/4] firmware: meson_sm: Add chipid number sysfs entry Date: Thu, 2 Nov 2023 10:49:14 +0300 Message-Id: <20231102074916.3280809-3-adeep@lexina.in> In-Reply-To: <20231102074916.3280809-1-adeep@lexina.in> References: <20231102074916.3280809-1-adeep@lexina.in> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231102_004927_516019_E2743D2F X-CRM114-Status: GOOD ( 15.14 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org The Amlogic Meson SoC Secure Monitor implements a call to retrieve an unique CHIP ID with CPU ID (128 bits length) starting from the GX Family and all new families. The chipid string is simply exposed as a sysfs entry under the firmware sysfs directory. Signed-off-by: Viacheslav Bocharov --- drivers/firmware/meson/meson_sm.c | 54 ++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c index c1c694b485ee..2820f4ac871b 100644 --- a/drivers/firmware/meson/meson_sm.c +++ b/drivers/firmware/meson/meson_sm.c @@ -240,9 +240,10 @@ struct meson_sm_firmware *meson_sm_get(struct device_node *sm_node) } EXPORT_SYMBOL_GPL(meson_sm_get); -#define SM_CHIP_ID_LENGTH 119 +#define SM_CHIP_ID_LENGTH 128 #define SM_CHIP_ID_OFFSET 4 #define SM_CHIP_ID_SIZE 12 +#define SM_CHIP_IDv2_SIZE 16 static ssize_t serial_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -274,8 +275,59 @@ static ssize_t serial_show(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR_RO(serial); +static ssize_t chipid_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct platform_device *pdev = to_platform_device(dev); + struct meson_sm_firmware *fw; + uint8_t *id_buf; + int ret; + + fw = platform_get_drvdata(pdev); + + id_buf = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL); + if (!id_buf) + return -ENOMEM; + + ret = meson_sm_call_read(fw, id_buf, SM_CHIP_ID_LENGTH, SM_GET_CHIP_ID, + 2, 0, 0, 0, 0); + if (ret < 0) { + kfree(id_buf); + return ret; + } + + int version = *((unsigned int *)id_buf); + + if (version == 2) + ret = scnprintf(buf, PAGE_SIZE, "%16phN\n", &id_buf[SM_CHIP_ID_OFFSET]); + else { + /** + * Legacy 12-byte chip ID read out, transform data + * to expected order format. + */ + uint8_t *buff; + + buff = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL); + if (!buff) + return -ENOMEM; + ((uint32_t *)buff)[0] = 0; // CPU_ID is empty + /* Transform into expected order for display */ + ch = (uint8_t *)(id_buf + 4); + for (i = 0; i < 12; i++) + buff[i + 4] = ch[11 - i]; + ret = scnprintf(buf, PAGE_SIZE, "%16phN\n", &buff); + kfree(buff); + } + + kfree(id_buf); + return ret; +} + +static DEVICE_ATTR_RO(chipid); + static struct attribute *meson_sm_sysfs_attributes[] = { &dev_attr_serial.attr, + &dev_attr_chipid.attr, NULL, }; From patchwork Thu Nov 2 07:49:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viacheslav X-Patchwork-Id: 13443490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0CFECC4332F for ; Thu, 2 Nov 2023 07:49:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Rf17Z3TXd4xrQBuQG1VR2SWqo9KLsV1LgSK/zxg55+w=; b=iZNJYXXC1SKdz1 Ek3ZNsMwIl6SjQEJvzjU3gHBtuqItkm8CozFs1pmrhwULjzFhQjIzppJD0DxZNMO9u8sEUc3uPa7+ kYutJ6TKFRAbl/OLIz1gIUTpG7JCwo4WZNvvl+H2oMwhffxQv4lovHB6f/588DRTOpOyGMjmJaWRy YGA8M2AZYca3SQzn6zzWQ74tMELMEXQyYEoqaVznL6pbPvueXO97UWqN+YX3HHyu1R5MH2srg35vp Ir/ye0P9crBQ18fz79TwYUujcwytlMEWajJUGyFWfhkc9vbS6iBG+hbw1Z90kjUQTQW1RdDcpHbyk EqvR35Jz9KBCRnbE0A5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qySSP-008vHa-26; Thu, 02 Nov 2023 07:49:37 +0000 Received: from mx.msync.work ([62.182.159.68]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qySSE-008vEL-3A; Thu, 02 Nov 2023 07:49:35 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 0DC4F147AB2; Thu, 2 Nov 2023 07:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lexina.in; s=dkim; t=1698911365; h=from:subject:date:message-id:to:mime-version: content-transfer-encoding:in-reply-to:references; bh=8Xr/QweSmgY7p0LBTNCDzfvzvoqHoF5yll89vV6bmZg=; b=HWBp2KY7I80PU4n4CtgZLFQoURpXPvDGu6OdKU5iycx0g+S4FtILtkBU9671+oV8PNuLG8 hSPz04sYvUBGo8Um0j2QOafAylCkZiMhTehtGrc0Qo+Wx7s+V4WlLoPsQ4J6F9NuXaB/k4 DnPVjxzyO8NKz7VPxEyps1+FwvsjJxT7PKGtJlZvQ5jzGNgHkNDSTJSAyiciLxmtBxDpyk ZGJE4S4W0FmmvuqUcSpYmbIMOAHCi36a455PzlAyYu1xmE70vuIVb1GO3qQmjX8d1ddNUC GeqOOxSmmLhZ1kzqkveRn6wP0H90y7HIxs/1JNP1UR67+xnX6Sk88PaMMVS/Ow== From: Viacheslav Bocharov To: Neil Armstrong , Kevin Hilman , Martin Blumenstingl , linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 3/4] soc: amlogic: meson-gx-socinfo: export socinfo for use in other modules Date: Thu, 2 Nov 2023 10:49:15 +0300 Message-Id: <20231102074916.3280809-4-adeep@lexina.in> In-Reply-To: <20231102074916.3280809-1-adeep@lexina.in> References: <20231102074916.3280809-1-adeep@lexina.in> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231102_004927_511139_EB69F46E X-CRM114-Status: GOOD ( 12.73 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org Move socinfo variable to global scope and export it as meson_gx_socinfo. Signed-off-by: Viacheslav Bocharov --- drivers/soc/amlogic/meson-gx-socinfo.c | 34 +++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/drivers/soc/amlogic/meson-gx-socinfo.c b/drivers/soc/amlogic/meson-gx-socinfo.c index 6abb730344ab..0517f96a383b 100644 --- a/drivers/soc/amlogic/meson-gx-socinfo.c +++ b/drivers/soc/amlogic/meson-gx-socinfo.c @@ -24,6 +24,10 @@ #define SOCINFO_MINOR GENMASK(15, 8) #define SOCINFO_MISC GENMASK(7, 0) + +unsigned int meson_gx_socinfo; +EXPORT_SYMBOL(meson_gx_socinfo); + static const struct meson_gx_soc_id { const char *name; unsigned int id; @@ -131,10 +135,10 @@ static int __init meson_gx_socinfo_init(void) struct soc_device *soc_dev; struct device_node *np; struct regmap *regmap; - unsigned int socinfo; struct device *dev; int ret; + meson_gx_socinfo = 0; /* look up for chipid node */ np = of_find_compatible_node(NULL, NULL, "amlogic,meson-gx-ao-secure"); if (!np) @@ -160,11 +164,13 @@ static int __init meson_gx_socinfo_init(void) return -ENODEV; } - ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo); - if (ret < 0) + ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &meson_gx_socinfo); + if (ret < 0) { + meson_gx_socinfo = 0; return ret; + } - if (!socinfo) { + if (!meson_gx_socinfo) { pr_err("%s: invalid chipid value\n", __func__); return -EINVAL; } @@ -175,13 +181,13 @@ static int __init meson_gx_socinfo_init(void) soc_dev_attr->family = "Amlogic Meson"; soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%x:%x - %x:%x", - socinfo_to_major(socinfo), - socinfo_to_minor(socinfo), - socinfo_to_pack(socinfo), - socinfo_to_misc(socinfo)); + socinfo_to_major(meson_gx_socinfo), + socinfo_to_minor(meson_gx_socinfo), + socinfo_to_pack(meson_gx_socinfo), + socinfo_to_misc(meson_gx_socinfo)); soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%s (%s)", - socinfo_to_soc_id(socinfo), - socinfo_to_package_id(socinfo)); + socinfo_to_soc_id(meson_gx_socinfo), + socinfo_to_package_id(meson_gx_socinfo)); soc_dev = soc_device_register(soc_dev_attr); if (IS_ERR(soc_dev)) { @@ -194,10 +200,10 @@ static int __init meson_gx_socinfo_init(void) dev_info(dev, "Amlogic Meson %s Revision %x:%x (%x:%x) Detected\n", soc_dev_attr->soc_id, - socinfo_to_major(socinfo), - socinfo_to_minor(socinfo), - socinfo_to_pack(socinfo), - socinfo_to_misc(socinfo)); + socinfo_to_major(meson_gx_socinfo), + socinfo_to_minor(meson_gx_socinfo), + socinfo_to_pack(meson_gx_socinfo), + socinfo_to_misc(meson_gx_socinfo)); return 0; } From patchwork Thu Nov 2 07:49:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viacheslav X-Patchwork-Id: 13443493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2EE48C4332F for ; Thu, 2 Nov 2023 07:50:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=x3yIotm5ZNe3ALIeClrGXDMGpxiZqa1kKTCBTc1FmRg=; b=JjGLLBNZ7mk9Qk M8Mxr8ulsaAnV/U2eB7t4ePeeCdUALQs4gijeNIGx828LXw2ZWUDsIf1QZnt1mwY7fWSv2se5b6Rp 7hQd02kXEsuYheTx5/qBlBC8KUn4nfnINz0NXU5PG82Eyj2MyhkP9gjNbmwCqrsbFE3VR+dHGJ9JG 9GNLnr3xpoNyixDCF8HnJ4S1WURMUAVlp0NRwWg1+L4aP85Jivu6LNKYlMzzYgjXmfYU84I8PcKMR 1f8doBk7ueMkIyOwC5UA1Vun8YhxiFJyOF+c/fMLmCaA6NcwWe+celYE/ewGHYzjTZajFseqNfHxf LqJ7HNR+6ctXkYNt6SLA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qySSP-008vHE-0n; Thu, 02 Nov 2023 07:49:37 +0000 Received: from mx.msync.work ([62.182.159.68]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qySSF-008vEM-0v; Thu, 02 Nov 2023 07:49:35 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 51175147AB3; Thu, 2 Nov 2023 07:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lexina.in; s=dkim; t=1698911365; h=from:subject:date:message-id:to:mime-version: content-transfer-encoding:in-reply-to:references; bh=DjHr33z5m71WBOI9v22JQkdNrW3bAbyGgJ/hgN+H1UM=; b=XjYThrOooEoCn2gOa0CXNbfolL9znTB9eHjNnAULCFsbKw17PTWQTw8tgyMwzZXXFGR0i6 JLSM3sxt9joS5KLM3miIHWaRy7O9VU2BHfCYIiS/fWxBVtrR8qZvcSpQiyhac/HyS6g6qE PdJcKJFsxm1f6At4NLzWyhMAe2YYshagVOSQv31BuFBgRfDDLLD2ZLuH55RN3i+XqUFfR6 hUybZQmu8JKHFkMP0a/LJ+3uxFSENmSxrRRbndDZ8qwovNjRg3VP/xAedcXHTZQEqnxWyk 3AA1C4HYr/nrYiVzx1GxagiiuDoEUi4Bbv2ZHlHDlXWQ9RVLY84hZMvvVP/vgg== From: Viacheslav Bocharov To: Neil Armstrong , Kevin Hilman , Martin Blumenstingl , linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 4/4] firmware: meson_sm: use meson_gx_socinfo for compatibility Date: Thu, 2 Nov 2023 10:49:16 +0300 Message-Id: <20231102074916.3280809-5-adeep@lexina.in> In-Reply-To: <20231102074916.3280809-1-adeep@lexina.in> References: <20231102074916.3280809-1-adeep@lexina.in> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231102_004927_518099_3C7FF6CB X-CRM114-Status: GOOD ( 10.77 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org Use meson_gx_socinfo variable for chipid compatible call from meson-gx-socinfo driver if available. Signed-off-by: Viacheslav Bocharov --- drivers/firmware/meson/meson_sm.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c index 2820f4ac871b..29b53a8a6941 100644 --- a/drivers/firmware/meson/meson_sm.c +++ b/drivers/firmware/meson/meson_sm.c @@ -23,6 +23,10 @@ #include +#ifdef CONFIG_MESON_GX_SOCINFO +extern unsigned int meson_gx_socinfo; +#endif + struct meson_sm_cmd { unsigned int index; u32 smc_id; @@ -310,7 +314,19 @@ static ssize_t chipid_show(struct device *dev, struct device_attribute *attr, buff = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL); if (!buff) return -ENOMEM; - ((uint32_t *)buff)[0] = 0; // CPU_ID is empty +#ifdef CONFIG_MESON_GX_SOCINFO + uint8_t *ch; + int i; + + ((uint32_t *)buff)[0] = + ((meson_gx_socinfo & 0xff000000) | // Family ID + ((meson_gx_socinfo << 8) & 0xff0000) | // Chip Revision + ((meson_gx_socinfo >> 8) & 0xff00)); // Package ID + + ((uint32_t *)buff)[0] = htonl(((uint32_t *)buff)[0]); +#else + ((uint32)t *)buff)[0] = 0; +#endif /* Transform into expected order for display */ ch = (uint8_t *)(id_buf + 4); for (i = 0; i < 12; i++)