From patchwork Tue Aug 1 18:21:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 129426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2866922vqg; Tue, 1 Aug 2023 11:52:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlF8UdezURgzhfn7oF8EFAVizIvD+mfxGmCs0uZD0WjmWmtvDeFaATuLtiCSwR1xP4uawHEG X-Received: by 2002:ac2:4e95:0:b0:4fe:1e74:3f3a with SMTP id o21-20020ac24e95000000b004fe1e743f3amr2417389lfr.58.1690915978604; Tue, 01 Aug 2023 11:52:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690915978; cv=none; d=google.com; s=arc-20160816; b=pm6bcbSGHGQQd4LyUBYaqpI4sE1imPzaKPFRbEdH9jtHZ+abxUXWTJayLFCdtg8ztS 7Fq8xmWFhUMLV/Zz8nAkuKQDDMGxjW+V/7U7/xmoCygcBFaGwtnXfVH8N/IgAVbU4On7 0ySlmlTBZDOYX4xECs128ji5gIP7AGelCG88Ujn61qLbWekI1ZcUDHUV9z1OrurYB/wK 2OG6J29DF/pALZECr20+BXr5VTLDPCc2KTio6v38Rm5Opbyn9vU7F9EE5DLWt6pFmmih Ws7WO7mk64vJ1NjOBD6OWXQMb//5fr1+BOcOSAYktzdnI9Hq9dc3AAjAY/eBXomC7EOF XvtA== 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=un3Uwaotmlox+IhpuLnflkjcgnz89/YG1Do8CcofnC8=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=RSqOSrSJenglse5eaRnokvPEjRjx7jwjPct4IwaheI1mSL1Sa0EHeTU8YL20HyR1PB 1llFmog/H5OTZ/ilETNaKLdOYkSpyhlLwPbsfsjatkaXxBjihkc/60zjV5BPtz+5mcQt BqJhF/NhEUkah3gK9oh7Eu74upF5vRClZk4lR/RFqxzvN90l3FK1x8TPhWDITTuHY25U yzhhLyskO8AhNRM7mwoQPC4qkhlnnNlXaSxwqa+gdUmD24RfQd3Y65bpBgrpMQJ2pqb3 aisBg64FtCiwIypwyNyNRBHlrUwFPx155O+hGFcMJTRUEPnom0pegL5bQTwRyRghsH1h OAWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=KSm9vmu0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a50ef02000000b005222af123bfsi8687461eds.301.2023.08.01.11.52.20; Tue, 01 Aug 2023 11:52:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=KSm9vmu0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231796AbjHASVt (ORCPT + 99 others); Tue, 1 Aug 2023 14:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231734AbjHASVn (ORCPT ); Tue, 1 Aug 2023 14:21:43 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8815F2689 for ; Tue, 1 Aug 2023 11:21:39 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 9F357E0003; Tue, 1 Aug 2023 18:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1690914098; 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=un3Uwaotmlox+IhpuLnflkjcgnz89/YG1Do8CcofnC8=; b=KSm9vmu0f8IIcuOFIlEzau9XSapvbuGrbGmh2i1glN+GtLBpvJYtMLcriL7sQVfOKWyS0o PtghWB/Bn5vMHBcPOhw4J84WduNNP8bNjuuMKSVtjmaZK0sig+/YQhHXYkO/skQVsA4dVi tPbJkpVL3r0mHUfCaZPeTeKmjqe9K7sTK1gck/4Bbc/vp5CAp1SYBE7v87p+f/h5bH1eXS BPoFabs50SX8imkphZYTSwZE8aQxqKBtFjg09NStYeyj7TGiVBdvb4gLHx5tqSkrETQHnI kn31uhXsxa5z47ZpFRwqL0QMPgt7wGtHB/uvN4nMNcWNruNMK53qcQbhTU3Avw== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v7 1/7] nvmem: core: Create all cells before adding the nvmem device Date: Tue, 1 Aug 2023 20:21:26 +0200 Message-Id: <20230801182132.1058707-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230801182132.1058707-1-miquel.raynal@bootlin.com> References: <20230801182132.1058707-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com 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_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773053912857393906 X-GMAIL-MSGID: 1773053912857393906 Let's pack all the cells creation in one place, so they are all created before we add the nvmem device. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 3f8c7718412b..48659106a1e2 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -998,12 +998,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (rval) goto err_remove_cells; - dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); - - rval = device_add(&nvmem->dev); - if (rval) - goto err_remove_cells; - rval = nvmem_add_cells_from_fixed_layout(nvmem); if (rval) goto err_remove_cells; @@ -1012,6 +1006,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (rval) goto err_remove_cells; + dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); + + rval = device_add(&nvmem->dev); + if (rval) + goto err_remove_cells; + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); return nvmem; From patchwork Tue Aug 1 18:21:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 129478 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp17675vqx; Tue, 1 Aug 2023 14:14:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlHzCl6keHiNatjRr9Jh2T1V7vNmXhyTE0B8Oa47GnF8l+I+Djg311WanvVOEuP9Jzaj55Jh X-Received: by 2002:a17:906:dd:b0:99b:f465:9b8c with SMTP id 29-20020a17090600dd00b0099bf4659b8cmr3080965eji.20.1690924469332; Tue, 01 Aug 2023 14:14:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690924469; cv=none; d=google.com; s=arc-20160816; b=CxyhjhpCJryWqFLhfhSYO0eltQLrsdhWM/tsT0nNcBMEXixbvjQcP3TrXc3dXf/2Ys +AHwq1mX+0m2mdNY4MBZ7D5oKFYqKAaF+qX/ENSXnOVRaKQcZx/iV7Ag+ZTHsAYKILxd 6pAeFNQ70NawuWEARdi0rBBt79nHsn03v3MoZe1TySLc63+5+lZBDK/q0jiPnF3PPBnR oY5qwYFmQ+zaRziTXS0S2LJXLwXAfu6s+mc2Q9zO+Grnb5XafKWhguyyLdYKTcw1v61F 0ERr7g2p3bURP0mlVqJVZ9UdqPgBIhD6x3/zJgIHteRPxsG123oUsEZa3f0kmeVW8gYt tjTg== 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=X3Zr5zi6oiutEUY5SskrgH9VYy6BX6UnhftLaueXlCU=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=c5cLDPLFphTtHkOw34upJMxDNxNzUWkJgEFS1FeJjBuH+LNEQ0YB3M3YharVf8C7B3 dO8XjbCdJ20mLGSIHpDh9ABJ1H5ze30f7tp034QmCCoJWjNcdUNiPlRDxoWoLAWXGIfC DXkYmTdPdpRjn4EvRQvFsp4JQqwYBhAAXhbddnW8aLCS8sRYaEZ+G7KScH07huFPvS0f unqg7GID2f+wYUrdfnVsbta81fJns8BRSv98pnTO43AatAQdYkqn5EhsoCZodqTThHsh WC/xC7SDbtlmfbOgs53zSuRVCL+RnWrFw7x0tfU+1zcdi8TSrq3MwRQCOPd/ErfS4bsg XAdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Qwc4xWMh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j17-20020a170906279100b0098dd7b3684csi6594469ejc.994.2023.08.01.14.14.05; Tue, 01 Aug 2023 14:14:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Qwc4xWMh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232045AbjHASVw (ORCPT + 99 others); Tue, 1 Aug 2023 14:21:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231789AbjHASVo (ORCPT ); Tue, 1 Aug 2023 14:21:44 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6445D269A for ; Tue, 1 Aug 2023 11:21:41 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 5BE8CE0008; Tue, 1 Aug 2023 18:21:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1690914099; 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=X3Zr5zi6oiutEUY5SskrgH9VYy6BX6UnhftLaueXlCU=; b=Qwc4xWMhuvilEC8gbcLTJ38MSm192xYthNDF4cItf+Qlz+MmsgOA28ca3z/PmVV4hIIbGo /p77PON4HbCwGxBD36wYi/Iybj1PHNX6XKCu+CIB2or+zKU8dzSw7K+i6jMWfFXwBUOuk/ EEt8umo6taoe7vA1wcbpE4gJQ85/unuyYegiy3Y4oDdL5G5q0pKO4LSajU/zZvpkyLKfNk /Nu/NYxPne1XMEZL4DBnEM2WfCtnkTMzLGdF3RsuRRDOj2EdR4WGHxAeXoH9ecUQrbT7aA jCMpph1MLWPtg9xi5MWFRe8ebWYaB8LJuMUt2V/i8lXkOBgJDOViGKs2h+m/gA== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v7 2/7] nvmem: core: Do not open-code existing functions Date: Tue, 1 Aug 2023 20:21:27 +0200 Message-Id: <20230801182132.1058707-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230801182132.1058707-1-miquel.raynal@bootlin.com> References: <20230801182132.1058707-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com 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_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773062816749117677 X-GMAIL-MSGID: 1773062816749117677 Use of_nvmem_layout_get_container() instead of hardcoding it. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 48659106a1e2..257328887263 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -786,10 +786,10 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister); static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) { - struct device_node *layout_np, *np = nvmem->dev.of_node; + struct device_node *layout_np; struct nvmem_layout *l, *layout = ERR_PTR(-EPROBE_DEFER); - layout_np = of_get_child_by_name(np, "nvmem-layout"); + layout_np = of_nvmem_layout_get_container(nvmem); if (!layout_np) return NULL; From patchwork Tue Aug 1 18:21:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 129460 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2908953vqg; Tue, 1 Aug 2023 13:13:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlHVtKLul6kGl8TIrHuy9L1WqPuErsu6DY9gqha2hu6tiT/oSXE1teI7enT2U8YDzJcWBw7E X-Received: by 2002:a17:906:5398:b0:993:d616:7ca9 with SMTP id g24-20020a170906539800b00993d6167ca9mr3571446ejo.23.1690920806627; Tue, 01 Aug 2023 13:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690920806; cv=none; d=google.com; s=arc-20160816; b=c5mqellt3Ysl3T0QN0ZmNr56+0kWPmuJ9FJkda+TV8RklVxgzymrwOUBTrA43fBriE lvY+kCWbM7wgFPxF7WRjruRcsR+pVQQ3s0vNM0S22H9cdUs1vEv/3QlOAr3kQ9+g738L e192WgHFGpEFhjiZml8IDYyNGWULBMS4+/fEnZvvv4ex0lPK6NvS224ydlLz4nJvQhmv 0oD2ClmTBckv7lguYGvoGSvIsfrzvXDKc9zFdqsOpbzpemt3Sd0WpzBRsguNG/w59J4R Fs1HRc/lJhj26fDQwcWrb7MIIr/CRcV/r5Ye12XHLvNFZF9LQa5SKJgUDg/ayR5phYQb 7qew== 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=ZIUXjeBWaacBxz6WsBbjN0nfgEPspA1Ri8UkX9Lqn/c=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=DD/JK8747Jhq6VwlNaADEnm9vcaz6MLYQxs5ORzTn3QDhI0jjV8i6R4FIRpOCjPjjC fWggyKtIBaNU1p95GplDtA0akUA5E7k9iVUHrw7KhNI5JpVxWnkgcld+6mPDJ+hlLqXi LfLteREN88ApoCtdPPcGbD7OJ7zY+hHxYpXR2ecEL6YJJRGqTMI1MmoIF8cOVDsJxYHv 7A9FCvlZ/HbNAxBreUOrKu1XW0lxFCnEHMTlbAVAx3U0oBf5XISdpyGzbam31Jv3uBR8 yn/cJ7ne3eM46sY0KYEuHQVpIi9A1/7Zng4bf9tmfBbl6hfMa5bxorUgWfOMLwAW/Acv eqjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=m0Y3FQU7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pg25-20020a170907205900b00989623654c0si8317753ejb.823.2023.08.01.13.13.02; Tue, 01 Aug 2023 13:13:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=m0Y3FQU7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232095AbjHASVz (ORCPT + 99 others); Tue, 1 Aug 2023 14:21:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231837AbjHASVp (ORCPT ); Tue, 1 Aug 2023 14:21:45 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E53DF213E for ; Tue, 1 Aug 2023 11:21:42 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 0DF99E0006; Tue, 1 Aug 2023 18:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1690914101; 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=ZIUXjeBWaacBxz6WsBbjN0nfgEPspA1Ri8UkX9Lqn/c=; b=m0Y3FQU7ZWxAVvM4lVxGVpPnJD1KykoHWeve45Ufs3yQIG6QC9Q0wkUZGJ3Ze5diPZ4jBU 2QGQzsy//qSArcxQ3hGtTHAoaWuLEKzltIUmu6gH9D+f/0hu+v3RoXyMrrBceMuU/J6qvX wABtexQ48Lyj1yF6wUZ0aDUDs5/uV397D5k+vbYasGEIdsvE7rQGNdGWcA3h+/CyYw+LeC ZP43Qdr7QXHjN0Rh2+C1fJthZkfRiPYFP6KhNL69lGKN6U/KgX/5GbxdkGQwqVuLA9GjO6 XhxaypvVOTsIIvIY5LU/cSfljQwXQa37v9n2CaaBwYOpm62j8ysXQEvpXTR7eQ== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v7 3/7] nvmem: core: Track the registered devices Date: Tue, 1 Aug 2023 20:21:28 +0200 Message-Id: <20230801182132.1058707-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230801182132.1058707-1-miquel.raynal@bootlin.com> References: <20230801182132.1058707-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773058975733202296 X-GMAIL-MSGID: 1773058975733202296 Create a list with all the NVMEM devices registered in the subsystem. This way we can iterate through them when needed (unused for now). Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 257328887263..4e81e0aaf433 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -23,6 +23,7 @@ struct nvmem_device { struct module *owner; struct device dev; + struct list_head node; int stride; int word_size; int id; @@ -76,6 +77,9 @@ static LIST_HEAD(nvmem_cell_tables); static DEFINE_MUTEX(nvmem_lookup_mutex); static LIST_HEAD(nvmem_lookup_list); +static DEFINE_MUTEX(nvmem_devices_mutex); +static LIST_HEAD(nvmem_devices_list); + static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); static DEFINE_SPINLOCK(nvmem_layout_lock); @@ -1012,6 +1016,10 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (rval) goto err_remove_cells; + mutex_lock(&nvmem_devices_mutex); + list_add_tail(&nvmem->node, &nvmem_devices_list); + mutex_unlock(&nvmem_devices_mutex); + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); return nvmem; @@ -1037,6 +1045,10 @@ static void nvmem_device_release(struct kref *kref) blocking_notifier_call_chain(&nvmem_notifier, NVMEM_REMOVE, nvmem); + mutex_lock(&nvmem_devices_mutex); + list_del(&nvmem->node); + mutex_unlock(&nvmem_devices_mutex); + if (nvmem->flags & FLAG_COMPAT) device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); From patchwork Tue Aug 1 18:21:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 129423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2863169vqg; Tue, 1 Aug 2023 11:44:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlHlUssu7OSFkkQ5Kt87qfYTPI6rMBAEKj3H6CKIysmq8LoflmM65h+HED336jCMtJTzYLEk X-Received: by 2002:a05:6a21:3b48:b0:137:d14d:79ea with SMTP id zy8-20020a056a213b4800b00137d14d79eamr13864999pzb.25.1690915471351; Tue, 01 Aug 2023 11:44:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690915471; cv=none; d=google.com; s=arc-20160816; b=QU7TVqPv3qKXvE50gbcMBNcLdbfzO31uXx0dJr4CCexOmwz0mDMQIs57KzYz3GON3w 95bk7ZZOXybmjd43rlKT/Icb9AiNYd0pIMWvdTGHEQu56aCQ9NEZAtmUBTLd2GfPvJta JwQpaH4bIDXgfSeTskUbYue7KWsUsIHHN6lTv3uqQgoODSWRtVp5ZPIEl/Sxt7WCtOCU Mf3O5K1GLmBgJ7GiYjTaNHFOlYFJsnPdwaeQLbMjtsyz+kZMAkCuObTW7yiPSly9ASpJ ABoOed+N0YlrO/dflVdlF+nfGgv1wA7YLBnh1UHvmDyN9UVYs1O7IkUB0+ScUEjEvOEi 4EnA== 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=jd0UhfUDeWS6RJi7TPdxTJy86kv9J6eGWIB4ZKNoAwM=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=EQ/tMn9p4X96UjlzstIVPdbok7P0jx5zNDvSuThXWojB1YqxwbqZCeECa6YkttjZq8 3TYUeSp494yXDkIlMt/MYOZAp8aDvmvrHVjoza0/0x7hAw8Mo/cgtXpLXQgbbuZpTh4L qOr+0RUn6MmxVZL8Qi+JQK3z0pL/uLQOssFKgvGXThu/R6Xkwoy1i1pMgliHJIwJRuWe Ht4mahFNBKI4UrytsFGtISWZB1YtHS0GgTvS24A6mkXHoxD8j/1ywbFoxyNi+OEJ3MWX nqr8h7bjOuXJ+QDpggVcEensgraRVMGHe/HyYQVMLxMUDwNKkhczRS92d5brL5h9ivhO pQ9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=n04pfgg1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a63574b000000b00563856f6d3bsi9359835pgm.55.2023.08.01.11.44.04; Tue, 01 Aug 2023 11:44:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=n04pfgg1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231751AbjHASV6 (ORCPT + 99 others); Tue, 1 Aug 2023 14:21:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231859AbjHASVq (ORCPT ); Tue, 1 Aug 2023 14:21:46 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84DC0213D for ; Tue, 1 Aug 2023 11:21:44 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id B9957E0007; Tue, 1 Aug 2023 18:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1690914103; 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=jd0UhfUDeWS6RJi7TPdxTJy86kv9J6eGWIB4ZKNoAwM=; b=n04pfgg1wSKMjJNVxmp56VFal0ugBPYkmy5t1dDuafuMyjxUYljax85DhvCfjEDCFaMv0k qx2383RQC98jWRdXCNqVzyTf2zsl7qNZnJX6zVgutp+LXLqRpmL9lP+2nkGSP3BXBTlaLi 8S5iP6BH1olUkL83NxnzvB5gLaJ1x/4b5A5cdNUOUyeZnAzZWj0z4IpEu9PMLHaw55M8I2 mIls/wv7LKlqe9sRk1RiKlPonxJkRLZwOU6cYgGpjFFmPkmM86OatEc7iof9lhp/y/MXKe jAcF2cA90Q4EWcdUTTlaCA+5EMAJXsWhchER8BT6xv4/vNt3Ug+2e1NJXAMPjg== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v7 4/7] nvmem: core: Notify when a new layout is registered Date: Tue, 1 Aug 2023 20:21:29 +0200 Message-Id: <20230801182132.1058707-5-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230801182132.1058707-1-miquel.raynal@bootlin.com> References: <20230801182132.1058707-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com 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_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773053380805662057 X-GMAIL-MSGID: 1773053380805662057 Tell listeners a new layout was introduced and is now available. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 4 ++++ include/linux/nvmem-consumer.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 4e81e0aaf433..0406fbc7b750 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -776,12 +776,16 @@ int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner) list_add(&layout->node, &nvmem_layouts); spin_unlock(&nvmem_layout_lock); + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_LAYOUT_ADD, layout); + return 0; } EXPORT_SYMBOL_GPL(__nvmem_layout_register); void nvmem_layout_unregister(struct nvmem_layout *layout) { + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_LAYOUT_REMOVE, layout); + spin_lock(&nvmem_layout_lock); list_del(&layout->node); spin_unlock(&nvmem_layout_lock); diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index fa030d93b768..859d41431e2f 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -43,6 +43,8 @@ enum { NVMEM_REMOVE, NVMEM_CELL_ADD, NVMEM_CELL_REMOVE, + NVMEM_LAYOUT_ADD, + NVMEM_LAYOUT_REMOVE, }; #if IS_ENABLED(CONFIG_NVMEM) From patchwork Tue Aug 1 18:21:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 129422 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2862379vqg; Tue, 1 Aug 2023 11:42:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlEDJ3o6IF9B3iXdEntf4suXZCt5U3pSrEcRt4PK7ZfI1v3AfKRdTdap83TGz7kD91/Tni9+ X-Received: by 2002:a17:90a:a085:b0:268:535f:7c15 with SMTP id r5-20020a17090aa08500b00268535f7c15mr16287547pjp.0.1690915358027; Tue, 01 Aug 2023 11:42:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690915358; cv=none; d=google.com; s=arc-20160816; b=cztodI8i5aGbjzSBqD7BdfkuF/dNSId5OjsksiiFwsXqtUQsEtCSNzFI3mmbZ0/HLu Ci28DNs+ye+qaJRBQl/0np52nf91BShnEK0SLHgvwPgzLHLKYRcOxpLlxnqjr2pOchr+ Tvpgnz1qhZ4IVMYrS7twztqRAVgqxg7Khcl3jLvqJbar+ssTI4G7rftekzzbjo6laTQD 5Xo+qvdEYZuCWxGWntlY+XJYME0QX2UtzJKu/oY64ZaXUWau+juqzqU3OaEnB6c5WPkF AQ16KdvbK149vPsB55m90AplRCaqtT2WKsLolSW03JBCUNwBJqb7bQyOYnvUmkxPvOkg R0IA== 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=oQ7q+S0WA0btHb97Zj7i/4YX+TmscMRWUDpKDDLHHz0=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=gnDJ1q3kfJf6SDnrMc8+piyAXPp3xUZJUA3bJ2jf6aPsge3iaiTg/F9jPbyEkM/G8R vD5MU8bo7nX4XV9szBHJYVLA+GeR8gHP0UL/DO75+swoPGk04gzOJGtAxeDoYn9/Lmdd +EiQpWHG4ds1kTjvmLGAZFCYnq+seFahVoBCxZcxIhLbBWKzsME0K3g0uwFksarP1Ekn bbuFhuKowiHXlPdBmqnQYBBL65NMBl5s5fQMwikcbPN+TsZsrmLxhN8jxjDr2xHZspMJ +SA/LQwc0sJtTw9t8o21mN1Fut+EaotEAWHTD6NVevi3w94N5+sxP3yjNF4688+pDbhJ MqBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=lJtXERix; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pg18-20020a17090b1e1200b00262fc8d4dfesi4831369pjb.108.2023.08.01.11.42.23; Tue, 01 Aug 2023 11:42:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=lJtXERix; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232282AbjHASWB (ORCPT + 99 others); Tue, 1 Aug 2023 14:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231737AbjHASVs (ORCPT ); Tue, 1 Aug 2023 14:21:48 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 587B2269E for ; Tue, 1 Aug 2023 11:21:46 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 66D39E0004; Tue, 1 Aug 2023 18:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1690914105; 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=oQ7q+S0WA0btHb97Zj7i/4YX+TmscMRWUDpKDDLHHz0=; b=lJtXERix5BPSbkIEF3Km8JkhvAu0NMTE5qZS/buGZvl+HFE8urSb6rSitsStlr1S6j4+BC 0k7B7BGDmKEybXzY2xcCgkIXABuDTQQar5jv8I43zHqFffoiK5IZuIxieGZ3436ePOdnJI Qu1oY/SEHqd/PqCsxfRqr+eWvPNpMDaLg+xz7xz/qRCc1gp4+RNwvvfB+OHfQifGGrsqC2 cIvDSE2jFPW6jgHF/5yGF4XDsioodGgJzDEqNZUQRlDiz0O5WUCdqlf4DINnAX2amlg7aP J7pQylAk2dxHW95Rh5PXpK5WCoHSqnAlEqWufKQ0JQpUOknfop+q12u/YXeXMQ== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v7 5/7] nvmem: core: Rework layouts to become platform devices Date: Tue, 1 Aug 2023 20:21:30 +0200 Message-Id: <20230801182132.1058707-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230801182132.1058707-1-miquel.raynal@bootlin.com> References: <20230801182132.1058707-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com 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_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773053262130534832 X-GMAIL-MSGID: 1773053262130534832 Current layout support was initially written without modules support in mind. When the requirement for module support rose, the existing base was improved to adopt modularization support, but kind of a design flaw was introduced. With the existing implementation, when a storage device registers into NVMEM, the core tries to hook a layout (if any) and populates its cells immediately. This means, if the hardware description expects a layout to be hooked up, but no driver was provided for that, the storage medium will fail to probe and try later from scratch. Technically, the layouts are more like a "plus" and, even we consider that the hardware description shall be correct, we could still probe the storage device (especially if it contains the rootfs). One way to overcome this situation is to consider the layouts as devices, and leverage the existing notifier mechanism. When a new NVMEM device is registered, we can: - populate its nvmem-layout child, if any - try to modprobe the relevant driver, if relevant - try to hook the NVMEM device with a layout in the notifier And when a new layout is registered: - try to hook all the existing NVMEM devices which are not yet hooked to a layout with the new layout This way, there is no strong order to enforce, any NVMEM device creation or NVMEM layout driver insertion will be observed as a new event which may lead to the creation of additional cells, without disturbing the probes with costly (and sometimes endless) deferrals. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 132 ++++++++++++++++++++++++------- drivers/nvmem/layouts/onie-tlv.c | 39 +++++++-- drivers/nvmem/layouts/sl28vpd.c | 39 +++++++-- include/linux/nvmem-provider.h | 11 +-- 4 files changed, 172 insertions(+), 49 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 0406fbc7b750..868a6f8b3227 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -80,6 +80,7 @@ static LIST_HEAD(nvmem_lookup_list); static DEFINE_MUTEX(nvmem_devices_mutex); static LIST_HEAD(nvmem_devices_list); +struct notifier_block nvmem_nb; static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); static DEFINE_SPINLOCK(nvmem_layout_lock); @@ -795,23 +796,16 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister); static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) { struct device_node *layout_np; - struct nvmem_layout *l, *layout = ERR_PTR(-EPROBE_DEFER); + struct nvmem_layout *l, *layout = NULL; layout_np = of_nvmem_layout_get_container(nvmem); if (!layout_np) return NULL; - /* - * In case the nvmem device was built-in while the layout was built as a - * module, we shall manually request the layout driver loading otherwise - * we'll never have any match. - */ - of_request_module(layout_np); - spin_lock(&nvmem_layout_lock); list_for_each_entry(l, &nvmem_layouts, node) { - if (of_match_node(l->of_match_table, layout_np)) { + if (of_match_node(l->dev->driver->of_match_table, layout_np)) { if (try_module_get(l->owner)) layout = l; @@ -868,7 +862,7 @@ const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, const struct of_device_id *match; layout_np = of_nvmem_layout_get_container(nvmem); - match = of_match_node(layout->of_match_table, layout_np); + match = of_match_node(layout->dev->driver->of_match_table, layout_np); return match ? match->data : NULL; } @@ -887,6 +881,7 @@ EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data); struct nvmem_device *nvmem_register(const struct nvmem_config *config) { struct nvmem_device *nvmem; + struct device_node *layout_np; int rval; if (!config->dev) @@ -979,19 +974,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) goto err_put_device; } - /* - * If the driver supplied a layout by config->layout, the module - * pointer will be NULL and nvmem_layout_put() will be a noop. - */ - nvmem->layout = config->layout ?: nvmem_layout_get(nvmem); - if (IS_ERR(nvmem->layout)) { - rval = PTR_ERR(nvmem->layout); - nvmem->layout = NULL; - - if (rval == -EPROBE_DEFER) - goto err_teardown_compat; - } - if (config->cells) { rval = nvmem_add_cells(nvmem, config->cells, config->ncells); if (rval) @@ -1010,16 +992,21 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (rval) goto err_remove_cells; - rval = nvmem_add_cells_from_layout(nvmem); - if (rval) - goto err_remove_cells; - dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); rval = device_add(&nvmem->dev); if (rval) goto err_remove_cells; + /* Populate layouts as devices */ + layout_np = of_nvmem_layout_get_container(nvmem); + if (layout_np) { + rval = of_platform_populate(nvmem->dev.of_node, NULL, NULL, NULL); + if (rval) + goto err_remove_cells; + of_node_put(layout_np); + } + mutex_lock(&nvmem_devices_mutex); list_add_tail(&nvmem->node, &nvmem_devices_list); mutex_unlock(&nvmem_devices_mutex); @@ -1030,8 +1017,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_remove_cells: nvmem_device_remove_all_cells(nvmem); - nvmem_layout_put(nvmem->layout); -err_teardown_compat: if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_put_device: @@ -2137,13 +2122,100 @@ const char *nvmem_dev_name(struct nvmem_device *nvmem) } EXPORT_SYMBOL_GPL(nvmem_dev_name); +static void nvmem_try_loading_layout_driver(struct nvmem_device *nvmem) +{ + struct device_node *layout_np; + + layout_np = of_nvmem_layout_get_container(nvmem); + if (layout_np) { + of_request_module(layout_np); + of_node_put(layout_np); + } +} + +static int nvmem_try_matching_available_layout(struct nvmem_device *nvmem) +{ + int ret; + + if (nvmem->layout) + return 0; + + nvmem->layout = nvmem_layout_get(nvmem); + if (!nvmem->layout) + return 0; + + ret = nvmem_add_cells_from_layout(nvmem); + if (ret) + goto put_layout; + + return 0; + +put_layout: + nvmem_layout_put(nvmem->layout); + return ret; +} + +/* + * When an NVMEM device is registered, try to match against a layout and + * populate the cells. When an NVMEM layout is probed, ensure all NVMEM devices + * which could use it properly expose their cells. + */ +static int nvmem_notifier_call(struct notifier_block *notifier, + unsigned long event_flags, void *context) +{ + struct nvmem_device *nvmem = NULL, *tmp; + int ret; + + switch (event_flags) { + case NVMEM_ADD: + nvmem = context; + break; + case NVMEM_LAYOUT_ADD: + break; + default: + return NOTIFY_DONE; + } + + if (nvmem) { + /* + * In case the nvmem device was built-in while the layout was + * built as a module, manually request loading the layout driver. + */ + nvmem_try_loading_layout_driver(nvmem); + + /* Populate the cells of the new nvmem device from its layout, if any */ + ret = nvmem_try_matching_available_layout(nvmem); + if (ret) + return notifier_from_errno(ret); + + return NOTIFY_OK; + } + + /* NVMEM devices might be "waiting" for this layout */ + list_for_each_entry_safe(nvmem, tmp, &nvmem_devices_list, node) { + ret = nvmem_try_matching_available_layout(nvmem); + if (ret) + return notifier_from_errno(ret); + } + + return NOTIFY_OK; +} + static int __init nvmem_init(void) { - return bus_register(&nvmem_bus_type); + int ret; + + ret = bus_register(&nvmem_bus_type); + if (ret) + return ret; + + nvmem_nb.notifier_call = &nvmem_notifier_call; + return nvmem_register_notifier(&nvmem_nb); } static void __exit nvmem_exit(void) { + nvmem_unregister_notifier(&nvmem_nb); bus_unregister(&nvmem_bus_type); } diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c index 59fc87ccfcff..3d54d3be2c93 100644 --- a/drivers/nvmem/layouts/onie-tlv.c +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -13,6 +13,7 @@ #include #include #include +#include #define ONIE_TLV_MAX_LEN 2048 #define ONIE_TLV_CRC_FIELD_SZ 6 @@ -226,18 +227,46 @@ static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem, return 0; } +static int onie_tlv_probe(struct platform_device *pdev) +{ + struct nvmem_layout *layout; + + layout = devm_kzalloc(&pdev->dev, sizeof(*layout), GFP_KERNEL); + if (!layout) + return -ENOMEM; + + layout->add_cells = onie_tlv_parse_table; + layout->dev = &pdev->dev; + + platform_set_drvdata(pdev, layout); + + return nvmem_layout_register(layout); +} + +static int onie_tlv_remove(struct platform_device *pdev) +{ + struct nvmem_layout *layout = platform_get_drvdata(pdev); + + nvmem_layout_unregister(layout); + + return 0; +} + static const struct of_device_id onie_tlv_of_match_table[] = { { .compatible = "onie,tlv-layout", }, {}, }; MODULE_DEVICE_TABLE(of, onie_tlv_of_match_table); -static struct nvmem_layout onie_tlv_layout = { - .name = "ONIE tlv layout", - .of_match_table = onie_tlv_of_match_table, - .add_cells = onie_tlv_parse_table, +static struct platform_driver onie_tlv_layout = { + .driver = { + .name = "onie-tlv-layout", + .of_match_table = onie_tlv_of_match_table, + }, + .probe = onie_tlv_probe, + .remove = onie_tlv_remove, }; -module_nvmem_layout_driver(onie_tlv_layout); +module_platform_driver(onie_tlv_layout); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Miquel Raynal "); diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c index 05671371f631..ad0c39fc7943 100644 --- a/drivers/nvmem/layouts/sl28vpd.c +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #define SL28VPD_MAGIC 'V' @@ -135,18 +136,46 @@ static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvmem, return 0; } +static int sl28vpd_probe(struct platform_device *pdev) +{ + struct nvmem_layout *layout; + + layout = devm_kzalloc(&pdev->dev, sizeof(*layout), GFP_KERNEL); + if (!layout) + return -ENOMEM; + + layout->add_cells = sl28vpd_add_cells; + layout->dev = &pdev->dev; + + platform_set_drvdata(pdev, layout); + + return nvmem_layout_register(layout); +} + +static int sl28vpd_remove(struct platform_device *pdev) +{ + struct nvmem_layout *layout = platform_get_drvdata(pdev); + + nvmem_layout_unregister(layout); + + return 0; +} + static const struct of_device_id sl28vpd_of_match_table[] = { { .compatible = "kontron,sl28-vpd" }, {}, }; MODULE_DEVICE_TABLE(of, sl28vpd_of_match_table); -static struct nvmem_layout sl28vpd_layout = { - .name = "sl28-vpd", - .of_match_table = sl28vpd_of_match_table, - .add_cells = sl28vpd_add_cells, +static struct platform_driver sl28vpd_layout = { + .driver = { + .name = "kontron-sl28vpd-layout", + .of_match_table = sl28vpd_of_match_table, + }, + .probe = sl28vpd_probe, + .remove = sl28vpd_remove, }; -module_nvmem_layout_driver(sl28vpd_layout); +module_platform_driver(sl28vpd_layout); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Michael Walle "); diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index dae26295e6be..c72064780b50 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -154,8 +154,7 @@ struct nvmem_cell_table { /** * struct nvmem_layout - NVMEM layout definitions * - * @name: Layout name. - * @of_match_table: Open firmware match table. + * @dev: Device-model layout device. * @add_cells: Will be called if a nvmem device is found which * has this layout. The function will add layout * specific cells with nvmem_add_one_cell(). @@ -170,8 +169,7 @@ struct nvmem_cell_table { * cells. */ struct nvmem_layout { - const char *name; - const struct of_device_id *of_match_table; + struct device *dev; int (*add_cells)(struct device *dev, struct nvmem_device *nvmem, struct nvmem_layout *layout); void (*fixup_cell_info)(struct nvmem_device *nvmem, @@ -243,9 +241,4 @@ nvmem_layout_get_match_data(struct nvmem_device *nvmem, } #endif /* CONFIG_NVMEM */ - -#define module_nvmem_layout_driver(__layout_driver) \ - module_driver(__layout_driver, nvmem_layout_register, \ - nvmem_layout_unregister) - #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */ From patchwork Tue Aug 1 18:21:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 129459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2908913vqg; Tue, 1 Aug 2023 13:13:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlH5PcnnNh1gyz7hSPa2LetHLPm+p71zhkMVD+JzM4L1aohMGWpog9pExLiROy26xnpuRFqr X-Received: by 2002:a17:906:3046:b0:98e:419b:4cc6 with SMTP id d6-20020a170906304600b0098e419b4cc6mr3112521ejd.70.1690920801846; Tue, 01 Aug 2023 13:13:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690920801; cv=none; d=google.com; s=arc-20160816; b=WbmxG1mY/aXnJAYUyb2+mqzn2JOFqGpm7y67OtDntNLzU645ckZEUKiNYCDC+5mWop PmbqKUs50PlU+1itCRZvnbMNhyjHpWwur2ewmBqM1pF4Bk5lUOyMdsiW4W6vLTv2AOt5 YsuymkdGultLCKIPc1i9IVurMFRLpvre/9QHtwJGgMadFyJvUUVd+gRPgey4XwD2sA12 VU4C2K2/1ogo55SLQa1ppfElKPSvStQJ7NmlsgYTHMlQWvUvceNGhvXh0okldKi9r7Z+ 1JYx5ZzLK4zc8dEnvDJ9kNMnycMmZJ815OyJh6tRa+ku+PsguiUxe4NvaN7yCNl5q3jP 3/hg== 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=fgVWjsMD95oohAim9ffD6zzKWxq5jwXobYlPEBDHn2g=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=sqwshZ+Olyxe/Oisvvzxbolp4Sez53hzii2OMm0NlZArWbCkQsmoA+tJ0HqKiZLV+t iAEW4kPwGvSFv2IY9zAHqMgMxBhMNWS06feu2fjoyOpVKtGSXr6+lnBVA2qQQh3DaPRd sOxC0xFwuOu8du/YA5ozzD8nON9M6F14A4zPuKt1IKxtkxka1aWM0FDAIJw3KfNpT+w0 6hecvJTqTqp9CS6u6QrzJoUzwQNrHYNzPyRsYfXu/MBCX1vnC41oa3/0dfrNgNzgQ3rG jgj8Qa2oHtANKwHkg3up/dnu3PO7QeSixkomKnwmnAeyqU4qf6gBgZKUfRdfu9ZLX7uh NATg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Y5Dh9IwC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga6-20020a170906b84600b00993199125d8si9361268ejb.378.2023.08.01.13.12.56; Tue, 01 Aug 2023 13:13:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Y5Dh9IwC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232310AbjHASWE (ORCPT + 99 others); Tue, 1 Aug 2023 14:22:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231339AbjHASVt (ORCPT ); Tue, 1 Aug 2023 14:21:49 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0206A2690 for ; Tue, 1 Aug 2023 11:21:47 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 3C5EBE0003; Tue, 1 Aug 2023 18:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1690914106; 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=fgVWjsMD95oohAim9ffD6zzKWxq5jwXobYlPEBDHn2g=; b=Y5Dh9IwCXc6tDCKv/3n+PfJ37a5cV9pwH3K0jGu7CBnVp96Kchq50jp/tdKPxHvkzDeLlI itDJgHJUPKrWCgjHjJ5ORYV15lGWcGzs8eyXR65IKzDOXPVtAbECNL/0EW5hQRo8/d8j0w Fh/RXuomXPhCuLuz3wnd9xp6u47IOGabCRSTxuJkpwL78TAKkOfAqu58OAhyP3+5P+ei7y ZJRDM10sOr80MwV9kq4FRzEdIWR7HiHiUdAMGgOfb5JIN/veCVfdlWivbadg4ztZs3lhym f3LK2u67j8pkudU+wCTDQ9JTqqyqEmR63UQGfdgkVolTUinDblzI9FblIBKksA== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v7 6/7] ABI: sysfs-nvmem-cells: Expose cells through sysfs Date: Tue, 1 Aug 2023 20:21:31 +0200 Message-Id: <20230801182132.1058707-7-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230801182132.1058707-1-miquel.raynal@bootlin.com> References: <20230801182132.1058707-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773058970683933948 X-GMAIL-MSGID: 1773058970683933948 The binary content of nvmem devices is available to the user so in the easiest cases, finding the content of a cell is rather easy as it is just a matter of looking at a known and fixed offset. However, nvmem layouts have been recently introduced to cope with more advanced situations, where the offset and size of the cells is not known in advance or is dynamic. When using layouts, more advanced parsers are used by the kernel in order to give direct access to the content of each cell regardless of their position/size in the underlying device, but these information were not accessible to the user. By exposing the nvmem cells to the user through a dedicated cell/ folder containing one file per cell, we provide a straightforward access to useful user information without the need for re-writing a userland parser. Content of nvmem cells is usually: product names, manufacturing date, MAC addresses, etc, Signed-off-by: Miquel Raynal Reviewed-by: Greg Kroah-Hartman --- Documentation/ABI/testing/sysfs-nvmem-cells | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-nvmem-cells diff --git a/Documentation/ABI/testing/sysfs-nvmem-cells b/Documentation/ABI/testing/sysfs-nvmem-cells new file mode 100644 index 000000000000..a1d140dcbd5d --- /dev/null +++ b/Documentation/ABI/testing/sysfs-nvmem-cells @@ -0,0 +1,21 @@ +What: /sys/bus/nvmem/devices/.../cells/ +Date: May 2023 +KernelVersion: 6.5 +Contact: Miquel Raynal +Description: + The "cells" folder contains one file per cell exposed by the + NVMEM device. The name of the file is: @, with + being the cell name and its location in the NVMEM + device, in hexadecimal (without the '0x' prefix, to mimic device + tree node names). The length of the file is the size of the cell + (when known). The content of the file is the binary content of + the cell (may sometimes be ASCII, likely without trailing + character). + Note: This file is only present if CONFIG_NVMEM_SYSFS + is enabled. + + Example:: + + hexdump -C /sys/bus/nvmem/devices/1-00563/cells/product-name + 00000000 54 4e 34 38 4d 2d 50 2d 44 4e |TN48M-P-DN| + 0000000a From patchwork Tue Aug 1 18:21:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 129440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2880026vqg; Tue, 1 Aug 2023 12:15:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlHuzRHQeXGZTZ5ADbPHxD3RJZYCUVnCuddOUWWBxlQIqsIGygChvvhDmUKMyjrxhozd4jV1 X-Received: by 2002:a05:6a21:3e02:b0:11f:4707:7365 with SMTP id bk2-20020a056a213e0200b0011f47077365mr12945342pzc.38.1690917359108; Tue, 01 Aug 2023 12:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690917359; cv=none; d=google.com; s=arc-20160816; b=gI/Tdac0EMI5utZdEFpL+88TUC81mawmE3byARkx2ohvhFZlgr7TBuAlpOqXpw7kHv +S3dLJURQPnqcr2Rni8A08XVCoWhtG5tKK0WoR1a7HosH+X1D7D63RpWJGUAkxvoa51K jB/lzH1NQQSmJtdcHkc0CNMGgvrdo0ffyx5n5kB9sM21UvcC4dptTQyFN+9lFpZ2owON 0Nd0/uHdaEM2Fm6MzpXmB4c2b1gafwoIXNzsG7WpRFGic1+GZKBjSzRY2iIHz9zsKaD+ rqDMGnen+4Nt14EYE7iMj7q6d4ZCv84ZwUi2yQ1RBj6Mb6DvEaYnQqqLiq4IzJZizPZz Y9Yg== 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=wZXUbb+s305f0R0d6PSBqvTxl9Ubms9zy8HvCNQc7YE=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=GOZHo5G4U40gXLHOOiZRkX5PX2mkhsZ6mr7HiUNKpwrRUdYpUkc8TfAKzMWHTm4xgY WafKYcudvsyctQyiSleTLVMRsWxMZzqImf3s9oOlNVHG5ncoQ5NbzTrpndr+/vz1Yehi qacQJnvkXyq6oP0vL002bu/3cqbl6xwHc0pCf+RSvBjwRY1Zicyv7wHvyODE5CVVMnTf f35BPkKIMGz/cuMbQuHKk3+muSklped7OSoJ4csqIuMMcqCIgengNFf1aNTlIlU+tnZ3 5T0cBYXRfLs1YrAh92pIrth3kdnBV3SPTgTaWjyXsHwzVZIXVVkoRVEYbOojP5L+aqNi EQvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=nOLMpLd4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z8-20020a633308000000b00563fe2f03edsi9226098pgz.93.2023.08.01.12.15.45; Tue, 01 Aug 2023 12:15:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=nOLMpLd4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232406AbjHASWO (ORCPT + 99 others); Tue, 1 Aug 2023 14:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231994AbjHASVv (ORCPT ); Tue, 1 Aug 2023 14:21:51 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC8AF269A for ; Tue, 1 Aug 2023 11:21:49 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id F359FE0005; Tue, 1 Aug 2023 18:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1690914108; 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=wZXUbb+s305f0R0d6PSBqvTxl9Ubms9zy8HvCNQc7YE=; b=nOLMpLd4UInlbOOe3sFtYzpGem4yyavZiwBoz/6dbG4a60Njd723o1505zRpf2hWpTMcVb zg15v8iyqGn7ktDGmZw6tCI4ci1ILSP/0huHmt62q2mA/e1Wn+UNB1v5KRwK5GTSHbJmtP 2vIPc7RUgXBa5XtSrzqrG4Op/HzAyyedPXtNblcYej90xCSfnHg2UkLrQZOkiqzz5sefr0 IgQBGNUI9ut0dA5k3Zks2HDScjRV3V9fn0G3bH/aOblr87Dpivu2YMMIo5ThMNM06FPnp8 Moqn9kLD1MpIRWV+acaGQpgAeqlM1HCHdTzlIjWquR6poU4siWbMI1BpZnWDUA== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v7 7/7] nvmem: core: Expose cells through sysfs Date: Tue, 1 Aug 2023 20:21:32 +0200 Message-Id: <20230801182132.1058707-8-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230801182132.1058707-1-miquel.raynal@bootlin.com> References: <20230801182132.1058707-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com 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_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773055360576997439 X-GMAIL-MSGID: 1773055360576997439 The binary content of nvmem devices is available to the user so in the easiest cases, finding the content of a cell is rather easy as it is just a matter of looking at a known and fixed offset. However, nvmem layouts have been recently introduced to cope with more advanced situations, where the offset and size of the cells is not known in advance or is dynamic. When using layouts, more advanced parsers are used by the kernel in order to give direct access to the content of each cell, regardless of its position/size in the underlying device. Unfortunately, these information are not accessible by users, unless by fully re-implementing the parser logic in userland. Let's expose the cells and their content through sysfs to avoid these situations. Of course the relevant NVMEM sysfs Kconfig option must be enabled for this support to be available. Not all nvmem devices expose cells. Indeed, the .bin_attrs attribute group member will be filled at runtime only when relevant and will remain empty otherwise. In this case, as the cells attribute group will be empty, it will not lead to any additional folder/file creation. Exposed cells are read-only. There is, in practice, everything in the core to support a write path, but as I don't see any need for that, I prefer to keep the interface simple (and probably safer). The interface is documented as being in the "testing" state which means we can later add a write attribute if though relevant. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 113 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 868a6f8b3227..beecb30a1642 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -330,6 +330,43 @@ static umode_t nvmem_bin_attr_is_visible(struct kobject *kobj, return nvmem_bin_attr_get_umode(nvmem); } +static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, + const char *id, int index); + +static ssize_t nvmem_cell_attr_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, char *buf, + loff_t pos, size_t count) +{ + struct nvmem_cell_entry *entry; + struct nvmem_cell *cell = NULL; + size_t cell_sz, read_len; + void *content; + + entry = attr->private; + cell = nvmem_create_cell(entry, entry->name, 0); + if (IS_ERR(cell)) + return PTR_ERR(cell); + + if (!cell) + return -EINVAL; + + content = nvmem_cell_read(cell, &cell_sz); + if (IS_ERR(content)) { + read_len = PTR_ERR(content); + goto destroy_cell; + } + + read_len = min_t(unsigned int, cell_sz - pos, count); + memcpy(buf, content + pos, read_len); + kfree(content); + +destroy_cell: + kfree_const(cell->id); + kfree(cell); + + return read_len; +} + /* default read/write permissions */ static struct bin_attribute bin_attr_rw_nvmem = { .attr = { @@ -351,11 +388,21 @@ static const struct attribute_group nvmem_bin_group = { .is_bin_visible = nvmem_bin_attr_is_visible, }; +/* Cell attributes will be dynamically allocated */ +static struct attribute_group nvmem_cells_group = { + .name = "cells", +}; + static const struct attribute_group *nvmem_dev_groups[] = { &nvmem_bin_group, NULL, }; +static const struct attribute_group *nvmem_cells_groups[] = { + &nvmem_cells_group, + NULL, +}; + static struct bin_attribute bin_attr_nvmem_eeprom_compat = { .attr = { .name = "eeprom", @@ -411,6 +458,64 @@ static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem, device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); } +static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) +{ + struct bin_attribute **cells_attrs, *attrs; + struct nvmem_cell_entry *entry; + unsigned int ncells = 0, i = 0; + int ret = 0; + + mutex_lock(&nvmem_mutex); + + if (list_empty(&nvmem->cells)) { + nvmem_cells_group.bin_attrs = NULL; + goto unlock_mutex; + } + + /* Allocate an array of attributes with a sentinel */ + ncells = list_count_nodes(&nvmem->cells); + cells_attrs = devm_kcalloc(&nvmem->dev, ncells + 1, + sizeof(struct bin_attribute *), GFP_KERNEL); + if (!cells_attrs) { + ret = -ENOMEM; + goto unlock_mutex; + } + + attrs = devm_kcalloc(&nvmem->dev, ncells, sizeof(struct bin_attribute), GFP_KERNEL); + if (!attrs) { + ret = -ENOMEM; + goto unlock_mutex; + } + + /* Initialize each attribute to take the name and size of the cell */ + list_for_each_entry(entry, &nvmem->cells, node) { + sysfs_bin_attr_init(&attrs[i]); + attrs[i].attr.name = devm_kasprintf(&nvmem->dev, GFP_KERNEL, + "%s@%x", entry->name, + entry->offset); + attrs[i].attr.mode = 0444; + attrs[i].size = entry->bytes; + attrs[i].read = &nvmem_cell_attr_read; + attrs[i].private = entry; + if (!attrs[i].attr.name) { + ret = -ENOMEM; + goto unlock_mutex; + } + + cells_attrs[i] = &attrs[i]; + i++; + } + + nvmem_cells_group.bin_attrs = cells_attrs; + + ret = devm_device_add_groups(&nvmem->dev, nvmem_cells_groups); + +unlock_mutex: + mutex_unlock(&nvmem_mutex); + + return ret; +} + #else /* CONFIG_NVMEM_SYSFS */ static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, @@ -2148,8 +2253,16 @@ static int nvmem_try_matching_available_layout(struct nvmem_device *nvmem) if (ret) goto put_layout; +#ifdef CONFIG_NVMEM_SYSFS + ret = nvmem_populate_sysfs_cells(nvmem); + if (ret) + goto del_cells; +#endif + return 0; +del_cells: + nvmem_device_remove_all_cells(nvmem); put_layout: nvmem_layout_put(nvmem->layout); return ret;