From patchwork Tue Nov 5 04:20:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2006645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=kjjgyy5a; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=kwbd+XjS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XjFYs5NJ7z1xyP for ; Tue, 5 Nov 2024 15:22:57 +1100 (AEDT) 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=yR9z0eGpwYJG4pvUYKBlrggSfylwB/akXqxspdEMTp4=; b=kjjgyy5a3/sZ6p qCza80vCy8jeHzGFa+mwKEEak3NQKJdtCBk3wjSQxzTX8yIUEmbWjesOekpcFEOMbEnuhbpyT3aF1 arhkNUj0GVMpt2UZpx4z7Kf89PTpkDFhWs2rx/HMmtaoOJhtfwRMAUp301nc5tVkjT31dfkE0Mw5M SCG8oKOYleE7KNKOOfqoJEHWPgsxuK08rdG28F0fwLN9gcEmPdicYaYTjTjzv5JC6YOgJig2B1P8g FGN5us9/3I7EXZCxJ6Aebn0girpF/DQ9+51x0g6HsNYZvmFyFAHO3Vnsp0NIxqefdbYjL36nZIJyk Gw3uWlae0NlzyJBlb8oA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5e-0000000FrMz-2IVc; Tue, 05 Nov 2024 04:22:50 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5c-0000000FrL7-14yQ for opensbi@lists.infradead.org; Tue, 05 Nov 2024 04:22:49 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-72061bfec2dso4652237b3a.2 for ; Mon, 04 Nov 2024 20:22:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1730780567; x=1731385367; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SMLk6iYksNR2WYmbXDFlh0zloEGx4d8FIX735SxoX4g=; b=kwbd+XjSqpIi1q4e14imuiuRFJ24RzfPBzHH3lnn/E853cZnTRd5BO0HfNgk5HG/5k cZzQx8Lp23f8QMr+BumKWQL7KvC5q0eiLAFmnGWNI57ZAeldLI+o0LQmrvfipBEzuULI GMFfotBpXCoYMNwj3197SpLUc4CJkBhS4mdSj9i+9L5GVYbspcJSykX1QWCFe9HdR6Qj WJsrN2IDo3NUj30lAqUJedV63U5CA+bWE3gy/4fwR1N9X0t4rcf9YM0dMNS+b5+CbbsQ x+e+spo9ZbdF8ze7DA1Nnm2Lq0ayFJ4ej2tE59LCffTWOLgzgBneDDRPKgLNiXdBy0IJ ALNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730780567; x=1731385367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SMLk6iYksNR2WYmbXDFlh0zloEGx4d8FIX735SxoX4g=; b=cuhcimFjlsV+0Y6lX1sVAuKHIAzOZ5LzC6jCL3J9L6ylOVuep64DgZX9HOKnKb+avt GO9mDjaee3XQ0zwiVaDndQkdnpEn5b+wHOBhi4/qQ1psPbtQc0tFdQL2/AFiO3xGc6gs Wj6Bl2sOfzAPVQIEPAcEI+hdy6Q8y4SsoE5E7ROBOs6VadRyVU8i2MbRnDi9btzACWDi ZqjdPHlKO/iFofr2LcqQGh4ZDaYAjBSiO8ZvYH8Rcan0Sf/kOxIxfJSuTTl5Ei0aL/zJ rLEn9El7yVVEWWBjGyDJoClSx49mTEjVmDUx9N/eunZZSItzKDlfeF6iIHTGdZJRfZEW /Z+g== X-Gm-Message-State: AOJu0YxOZFgQVCAm6buCkIQgH7SWT6olq2GWS2wKnrtGbbyzg33kLMRB 7WE4GViYManxmM0IiStvXGJ33lMMzH+rS0Ip/TkyLI7BpFJyKV5TZ/VKp3wGoKOrHZB3EHx4Y+t eD+hNX/fkEUg/N9j0BPa7eK3KTXUvmjChgRp1TqX5qnqgv0KtjTwxT/RoY4U6G63CgaEvjPSq5+ vhtSEc+T9lgMV1IfjOvTEiQc+/NCBvdE9f4P0qTpiXHWAZ7xBGNek= X-Google-Smtp-Source: AGHT+IFr3s/DfTZZRs03qGC2mAFN9JoGET2mJl0Wd+127faTIBVMktuY2EkoAdZJEhJhpLW/Aj9raQ== X-Received: by 2002:a05:6a20:7f98:b0:1db:ebbf:4b8a with SMTP id adf61e73a8af0-1dbebbf4bdcmr4586877637.7.1730780567127; Mon, 04 Nov 2024 20:22:47 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1e5a64sm8493782b3a.65.2024.11.04.20.22.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 20:22:46 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH 5/6] lib: utils/reset: Use fdt_driver for initialization Date: Mon, 4 Nov 2024 20:20:07 -0800 Message-ID: <20241105042240.2994849-6-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241105042240.2994849-1-samuel.holland@sifive.com> References: <20241105042240.2994849-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_202248_331724_C266DA67 X-CRM114-Status: GOOD ( 16.71 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The reset driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_reset_init() performs a best-effort initialization of all matching DT nodes. Platfo [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42c listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The reset driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_reset_init() performs a best-effort initialization of all matching DT nodes. Platform-specific logic expects exactly one DT node to match a single driver. This is accomplished by using fdt_driver_init_one() with a local list containing that one driver. Signed-off-by: Samuel Holland --- include/sbi_utils/reset/fdt_reset.h | 15 +------- lib/utils/reset/fdt_reset.c | 36 ++------------------ lib/utils/reset/fdt_reset_atcwdt200.c | 2 +- lib/utils/reset/fdt_reset_drivers.carray | 2 +- lib/utils/reset/fdt_reset_gpio.c | 4 +-- lib/utils/reset/fdt_reset_htif.c | 2 +- lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c | 2 +- lib/utils/reset/fdt_reset_sunxi_wdt.c | 2 +- lib/utils/reset/fdt_reset_syscon.c | 4 +-- platform/generic/sifive/fu740.c | 9 +++-- platform/generic/starfive/jh7110.c | 9 +++-- 11 files changed, 26 insertions(+), 61 deletions(-) diff --git a/include/sbi_utils/reset/fdt_reset.h b/include/sbi_utils/reset/fdt_reset.h index f126fd33..5fba3886 100644 --- a/include/sbi_utils/reset/fdt_reset.h +++ b/include/sbi_utils/reset/fdt_reset.h @@ -11,19 +11,10 @@ #define __FDT_RESET_H__ #include - -struct fdt_reset { - const struct fdt_match *match_table; - int (*init)(const void *fdt, int nodeoff, const struct fdt_match *match); -}; +#include #ifdef CONFIG_FDT_RESET -/** - * fdt_reset_driver_init() - initialize reset driver based on the device-tree - */ -int fdt_reset_driver_init(const void *fdt, struct fdt_reset *drv); - /** * fdt_reset_init() - initialize reset drivers based on the device-tree * @@ -33,10 +24,6 @@ void fdt_reset_init(const void *fdt); #else -static inline int fdt_reset_driver_init(const void *fdt, struct fdt_reset *drv) -{ - return 0; -} static inline void fdt_reset_init(const void *fdt) { } #endif diff --git a/lib/utils/reset/fdt_reset.c b/lib/utils/reset/fdt_reset.c index 4b20c3e3..633a25cd 100644 --- a/lib/utils/reset/fdt_reset.c +++ b/lib/utils/reset/fdt_reset.c @@ -7,44 +7,12 @@ * Anup Patel */ -#include -#include -#include -#include #include /* List of FDT reset drivers generated at compile time */ -extern struct fdt_reset *const fdt_reset_drivers[]; - -int fdt_reset_driver_init(const void *fdt, struct fdt_reset *drv) -{ - int noff, rc, cnt = 0; - const struct fdt_match *match; - - noff = -1; - while ((noff = fdt_find_match(fdt, noff, - drv->match_table, &match)) >= 0) { - if (!fdt_node_is_enabled(fdt, noff)) - continue; - - if (drv->init) { - rc = drv->init(fdt, noff, match); - if (!rc) - cnt++; - else if (rc != SBI_ENODEV) { - sbi_printf("%s: %s init failed, %d\n", - __func__, match->compatible, rc); - } - } - } - - return cnt > 0 ? 0 : SBI_ENODEV; -} +extern const struct fdt_driver *const fdt_reset_drivers[]; void fdt_reset_init(const void *fdt) { - int pos; - - for (pos = 0; fdt_reset_drivers[pos]; pos++) - fdt_reset_driver_init(fdt, fdt_reset_drivers[pos]); + fdt_driver_init_all(fdt, fdt_reset_drivers); } diff --git a/lib/utils/reset/fdt_reset_atcwdt200.c b/lib/utils/reset/fdt_reset_atcwdt200.c index 6ef3b134..d3e38e61 100644 --- a/lib/utils/reset/fdt_reset_atcwdt200.c +++ b/lib/utils/reset/fdt_reset_atcwdt200.c @@ -111,7 +111,7 @@ static const struct fdt_match atcwdt200_reset_match[] = { {}, }; -struct fdt_reset fdt_reset_atcwdt200 = { +const struct fdt_driver fdt_reset_atcwdt200 = { .match_table = atcwdt200_reset_match, .init = atcwdt200_reset_init, }; diff --git a/lib/utils/reset/fdt_reset_drivers.carray b/lib/utils/reset/fdt_reset_drivers.carray index 6ff799cc..2e9e86af 100644 --- a/lib/utils/reset/fdt_reset_drivers.carray +++ b/lib/utils/reset/fdt_reset_drivers.carray @@ -1,3 +1,3 @@ HEADER: sbi_utils/reset/fdt_reset.h -TYPE: struct fdt_reset +TYPE: const struct fdt_driver NAME: fdt_reset_drivers diff --git a/lib/utils/reset/fdt_reset_gpio.c b/lib/utils/reset/fdt_reset_gpio.c index de81e2eb..cf751254 100644 --- a/lib/utils/reset/fdt_reset_gpio.c +++ b/lib/utils/reset/fdt_reset_gpio.c @@ -153,7 +153,7 @@ static const struct fdt_match gpio_poweroff_match[] = { { }, }; -struct fdt_reset fdt_poweroff_gpio = { +const struct fdt_driver fdt_poweroff_gpio = { .match_table = gpio_poweroff_match, .init = gpio_reset_init, }; @@ -163,7 +163,7 @@ static const struct fdt_match gpio_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_gpio = { +const struct fdt_driver fdt_reset_gpio = { .match_table = gpio_reset_match, .init = gpio_reset_init, }; diff --git a/lib/utils/reset/fdt_reset_htif.c b/lib/utils/reset/fdt_reset_htif.c index 7c04c81c..61c907fa 100644 --- a/lib/utils/reset/fdt_reset_htif.c +++ b/lib/utils/reset/fdt_reset_htif.c @@ -32,7 +32,7 @@ static const struct fdt_match htif_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_htif = { +const struct fdt_driver fdt_reset_htif = { .match_table = htif_reset_match, .init = htif_reset_init }; diff --git a/lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c b/lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c index 368cd108..66826830 100644 --- a/lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c +++ b/lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c @@ -108,7 +108,7 @@ static const struct fdt_match sg2042_mcu_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_sg2042_mcu = { +const struct fdt_driver fdt_reset_sg2042_mcu = { .match_table = sg2042_mcu_reset_match, .init = sg2042_mcu_reset_init, }; diff --git a/lib/utils/reset/fdt_reset_sunxi_wdt.c b/lib/utils/reset/fdt_reset_sunxi_wdt.c index f4b06d23..708bf25c 100644 --- a/lib/utils/reset/fdt_reset_sunxi_wdt.c +++ b/lib/utils/reset/fdt_reset_sunxi_wdt.c @@ -71,7 +71,7 @@ static const struct fdt_match sunxi_wdt_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_sunxi_wdt = { +const struct fdt_driver fdt_reset_sunxi_wdt = { .match_table = sunxi_wdt_reset_match, .init = sunxi_wdt_reset_init, }; diff --git a/lib/utils/reset/fdt_reset_syscon.c b/lib/utils/reset/fdt_reset_syscon.c index 0dd76acb..d1a3bc0e 100644 --- a/lib/utils/reset/fdt_reset_syscon.c +++ b/lib/utils/reset/fdt_reset_syscon.c @@ -151,7 +151,7 @@ static const struct fdt_match syscon_poweroff_match[] = { { }, }; -struct fdt_reset fdt_syscon_poweroff = { +const struct fdt_driver fdt_syscon_poweroff = { .match_table = syscon_poweroff_match, .init = syscon_reset_init, }; @@ -161,7 +161,7 @@ static const struct fdt_match syscon_reboot_match[] = { { }, }; -struct fdt_reset fdt_syscon_reboot = { +const struct fdt_driver fdt_syscon_reboot = { .match_table = syscon_reboot_match, .init = syscon_reset_init, }; diff --git a/platform/generic/sifive/fu740.c b/platform/generic/sifive/fu740.c index 46dc02ae..52ca12ff 100644 --- a/platform/generic/sifive/fu740.c +++ b/platform/generic/sifive/fu740.c @@ -209,11 +209,16 @@ static const struct fdt_match da9063_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_da9063 = { +const struct fdt_driver fdt_reset_da9063 = { .match_table = da9063_reset_match, .init = da9063_reset_init, }; +static const struct fdt_driver *const sifive_fu740_reset_drivers[] = { + &fdt_reset_da9063, + NULL +}; + static u64 sifive_fu740_tlbr_flush_limit(const struct fdt_match *match) { /* @@ -232,7 +237,7 @@ static int sifive_fu740_final_init(bool cold_boot, void *fdt, int rc; if (cold_boot) { - rc = fdt_reset_driver_init(fdt, &fdt_reset_da9063); + rc = fdt_driver_init_one(fdt, sifive_fu740_reset_drivers); if (rc) sbi_printf("%s: failed to find da9063 for reset\n", __func__); diff --git a/platform/generic/starfive/jh7110.c b/platform/generic/starfive/jh7110.c index 264fe99c..6d95758f 100644 --- a/platform/generic/starfive/jh7110.c +++ b/platform/generic/starfive/jh7110.c @@ -227,11 +227,16 @@ static const struct fdt_match pm_reset_match[] = { { }, }; -static struct fdt_reset fdt_reset_pmic = { +static const struct fdt_driver fdt_reset_pmic = { .match_table = pm_reset_match, .init = pm_reset_init, }; +static const struct fdt_driver *const starfive_jh7110_reset_drivers[] = { + &fdt_reset_pmic, + NULL +}; + static int starfive_jh7110_inst_init(const void *fdt) { int noff, rc = 0; @@ -281,7 +286,7 @@ static int starfive_jh7110_final_init(bool cold_boot, void *fdt, const struct fdt_match *match) { if (cold_boot) { - fdt_reset_driver_init(fdt, &fdt_reset_pmic); + fdt_driver_init_one(fdt, starfive_jh7110_reset_drivers); } return 0;