From patchwork Mon Nov 11 22:02:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009937 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=iEDuoV+s; 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=cQxXreQf; 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 4XnNpc17HLz1xwF for ; Tue, 12 Nov 2024 09:03:19 +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=/UxwUZqgCb5tp+a1kEDqWmxzmlZUQuIG++XpDZP7Czk=; b=iEDuoV+sFh7y9o FOW8sP/H7FX66JwkwAm6KMBGDVONPd5jyWLesOGUqKLea+pBtut87M3orKG5hw8ASzfUF4lLYF4Pn QSpqCp5MHOy/R8EBcgnWCghzm7QV40YpbPG1QvAcltZhNfMvyp8Vj7E9G+0ZuU+fNZThBPb5cbjpJ giSWw05r04q2wYxQMlzsTuZ8YX94dyQ/KhA6Jg2WAN5LLiurVk2vXbdGZFqZ01OEZKZQvJGBXga7t NzjmHeHUTOO5kYCQga1YtAAwG+DZNm02iu1LXspvy333ueX3YncLmPefyfUfiJM5ShtuRWz0BGtsh IGlrYfE+yD02SoRNpDgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV5-00000001RM8-0tuN; Mon, 11 Nov 2024 22:03:11 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV2-00000001RKs-0scv for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:09 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-20ca388d242so50470035ad.2 for ; Mon, 11 Nov 2024 14:03:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362587; x=1731967387; 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=/eTQ+51Ayqlm4hws28hLYsecciVj5QxzxcaytKE4UNE=; b=cQxXreQfwpVyoa1UftpVMRAl3qrmmzLbIkpJqJKiY1HHqIgSUDKKzrWFiy5rqO0Wen 4WVnDdsfriHpzQmrUAr4IAfyHbp7C6OY+p01IE/gZGE1tu141FOehhjEHXXjSrIzc/Pl HbtTag8Y+nOThprAgscA1p865ycvau4/++bssSCrQS659pz8CGtC9AdpQZVMNRCFDin9 O8FgRfjdkkTN7pONFDU47e4+YuSJwMld8WV6+82PeIZg3Z15dIg79kinBX0dFuVUAk/v zpjywXEA8jgvm7BgGCaNAodLsI9aUOMZDSVAiifHp107iLLqwX8m7uqHQjc6w02cwXx2 qbVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362587; x=1731967387; 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=/eTQ+51Ayqlm4hws28hLYsecciVj5QxzxcaytKE4UNE=; b=HQdiCR2H5ePTyYE11zSIcEMcvTmIxZDqPhICiN/PvT9/F/3ZT5eTC65jI4GtDL9Oq7 rZFHNx5olR+Gc7c3BE3gZASlFr+iYT3VCI0WvmvW+coKncpqg2SJ2yENGXLX5Mh8qt6c 3fDgI0tjV14DFN4NDxIDm9AY2D2aT6KoiqPsl50/KaA41hd2uEeUTZE6AkLhNebIuEKc BnOAc3v6j3ewBSrNYr6Bz7Uh+4cu8betmotSYsPeC4StX+5UouL3AphU9FxoB+/ThkLd 6wkt3m7Qa8IOpOIR82zcnjt4PrO8bx7dXzBmX8fqtESFnZiIgc1JleL1VH0qCzPPFZSx /X/A== X-Gm-Message-State: AOJu0YwVbGt/l5Dt7K3izkKjw0xC+Y7Ge9RLjcRq/9u9G1Cfhafcq+VN lIJ1Q6XBc7sUEzf2umtZA9MksXd+OjTMffGNSV9rq8mGdYeMXw/QvKaUBfc73ABtgDnUtXiCmX6 DH9wusJ/f0oMF4p6UnR8v594rzB9FIZS6WK9GLHOdDremHh8auOj3JIiKb4DsR5WCcaziD612hI SLdEkVOKQgeYfW6NwYwn2NLmRfbaeXW9FbFFEvBbNl8xhOc90wxRo= X-Google-Smtp-Source: AGHT+IHQZIk7KOhe4VoWYvO/QSpJVOqEj861BqU0QNHaeI/G8/iNIKoxKoSeb3jmThd2yaFUjHVT9w== X-Received: by 2002:a17:902:cf12:b0:20c:528d:7063 with SMTP id d9443c01a7336-21183d4baa1mr206780755ad.19.1731362587367; Mon, 11 Nov 2024 14:03:07 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:06 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 01/11] treewide: Make carray arrays const and NULL-terminated Date: Mon, 11 Nov 2024 14:02:45 -0800 Message-ID: <20241111220304.1228821-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-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-20241111_140308_412785_82C4C99E X-CRM114-Status: GOOD ( 14.32 ) 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: This allows the compiler to generate significantly better code, because it does not have to maintain either the loop counter or loop limit. Plus there are half as many symbols to relocate. This also s [...] 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:630 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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 This allows the compiler to generate significantly better code, because it does not have to maintain either the loop counter or loop limit. Plus there are half as many symbols to relocate. This also simplifies passing carray arrays to helper functions. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- (no changes since v1) lib/sbi/sbi_ecall.c | 5 ++--- lib/sbi/tests/sbi_unit_test.c | 5 ++--- lib/utils/gpio/fdt_gpio.c | 5 ++--- lib/utils/i2c/fdt_i2c.c | 5 ++--- lib/utils/ipi/fdt_ipi.c | 5 ++--- lib/utils/irqchip/fdt_irqchip.c | 5 ++--- lib/utils/regmap/fdt_regmap.c | 5 ++--- lib/utils/reset/fdt_reset.c | 5 ++--- lib/utils/serial/fdt_serial.c | 7 +++---- lib/utils/timer/fdt_timer.c | 5 ++--- platform/generic/platform.c | 5 ++--- scripts/carray.sh | 7 +++---- 12 files changed, 26 insertions(+), 38 deletions(-) diff --git a/lib/sbi/sbi_ecall.c b/lib/sbi/sbi_ecall.c index d4fc58c5..be0b67e1 100644 --- a/lib/sbi/sbi_ecall.c +++ b/lib/sbi/sbi_ecall.c @@ -13,8 +13,7 @@ #include #include -extern struct sbi_ecall_extension *sbi_ecall_exts[]; -extern unsigned long sbi_ecall_exts_size; +extern struct sbi_ecall_extension *const sbi_ecall_exts[]; u16 sbi_ecall_version_major(void) { @@ -148,7 +147,7 @@ int sbi_ecall_init(void) struct sbi_ecall_extension *ext; unsigned long i; - for (i = 0; i < sbi_ecall_exts_size; i++) { + for (i = 0; sbi_ecall_exts[i]; i++) { ext = sbi_ecall_exts[i]; ret = SBI_ENODEV; diff --git a/lib/sbi/tests/sbi_unit_test.c b/lib/sbi/tests/sbi_unit_test.c index cd091663..d5e81568 100644 --- a/lib/sbi/tests/sbi_unit_test.c +++ b/lib/sbi/tests/sbi_unit_test.c @@ -11,8 +11,7 @@ #define ANSI_COLOR_RED "\x1b[31m" #define ANSI_COLOR_RESET "\x1b[0m" -extern struct sbiunit_test_suite *sbi_unit_tests[]; -extern unsigned long sbi_unit_tests_size; +extern struct sbiunit_test_suite *const sbi_unit_tests[]; static void run_test_suite(struct sbiunit_test_suite *suite) { @@ -48,6 +47,6 @@ void run_all_tests(void) sbi_printf("\n# Running SBIUNIT tests #\n"); - for (i = 0; i < sbi_unit_tests_size; i++) + for (i = 0; sbi_unit_tests[i]; i++) run_test_suite(sbi_unit_tests[i]); } diff --git a/lib/utils/gpio/fdt_gpio.c b/lib/utils/gpio/fdt_gpio.c index 953fa13a..eac2b863 100644 --- a/lib/utils/gpio/fdt_gpio.c +++ b/lib/utils/gpio/fdt_gpio.c @@ -13,8 +13,7 @@ #include /* List of FDT gpio drivers generated at compile time */ -extern struct fdt_gpio *fdt_gpio_drivers[]; -extern unsigned long fdt_gpio_drivers_size; +extern struct fdt_gpio *const fdt_gpio_drivers[]; static int fdt_gpio_init(const void *fdt, int nodeoff) { @@ -27,7 +26,7 @@ static int fdt_gpio_init(const void *fdt, int nodeoff) return SBI_EINVAL; /* Try all GPIO drivers one-by-one */ - for (pos = 0; pos < fdt_gpio_drivers_size; pos++) { + for (pos = 0; fdt_gpio_drivers[pos]; pos++) { drv = fdt_gpio_drivers[pos]; match = fdt_match_node(fdt, nodeoff, drv->match_table); diff --git a/lib/utils/i2c/fdt_i2c.c b/lib/utils/i2c/fdt_i2c.c index d23b40db..56891a0a 100644 --- a/lib/utils/i2c/fdt_i2c.c +++ b/lib/utils/i2c/fdt_i2c.c @@ -17,8 +17,7 @@ #include /* List of FDT i2c adapter drivers generated at compile time */ -extern struct fdt_i2c_adapter *fdt_i2c_adapter_drivers[]; -extern unsigned long fdt_i2c_adapter_drivers_size; +extern struct fdt_i2c_adapter *const fdt_i2c_adapter_drivers[]; static int fdt_i2c_adapter_init(const void *fdt, int nodeoff) { @@ -27,7 +26,7 @@ static int fdt_i2c_adapter_init(const void *fdt, int nodeoff) const struct fdt_match *match; /* Try all I2C drivers one-by-one */ - for (pos = 0; pos < fdt_i2c_adapter_drivers_size; pos++) { + for (pos = 0; fdt_i2c_adapter_drivers[pos]; pos++) { drv = fdt_i2c_adapter_drivers[pos]; match = fdt_match_node(fdt, nodeoff, drv->match_table); if (match && drv->init) { diff --git a/lib/utils/ipi/fdt_ipi.c b/lib/utils/ipi/fdt_ipi.c index c2ff9cfa..6c2feafb 100644 --- a/lib/utils/ipi/fdt_ipi.c +++ b/lib/utils/ipi/fdt_ipi.c @@ -13,8 +13,7 @@ #include /* List of FDT ipi drivers generated at compile time */ -extern struct fdt_ipi *fdt_ipi_drivers[]; -extern unsigned long fdt_ipi_drivers_size; +extern struct fdt_ipi *const fdt_ipi_drivers[]; int fdt_ipi_init(void) { @@ -23,7 +22,7 @@ int fdt_ipi_init(void) const struct fdt_match *match; const void *fdt = fdt_get_address(); - for (pos = 0; pos < fdt_ipi_drivers_size; pos++) { + for (pos = 0; fdt_ipi_drivers[pos]; pos++) { drv = fdt_ipi_drivers[pos]; noff = -1; diff --git a/lib/utils/irqchip/fdt_irqchip.c b/lib/utils/irqchip/fdt_irqchip.c index b4f054ae..0c8c76b2 100644 --- a/lib/utils/irqchip/fdt_irqchip.c +++ b/lib/utils/irqchip/fdt_irqchip.c @@ -13,8 +13,7 @@ #include /* List of FDT irqchip drivers generated at compile time */ -extern struct fdt_irqchip *fdt_irqchip_drivers[]; -extern unsigned long fdt_irqchip_drivers_size; +extern struct fdt_irqchip *const fdt_irqchip_drivers[]; #define FDT_IRQCHIP_MAX_DRIVERS 8 @@ -55,7 +54,7 @@ static int fdt_irqchip_cold_init(void) const struct fdt_match *match; const void *fdt = fdt_get_address(); - for (pos = 0; pos < fdt_irqchip_drivers_size; pos++) { + for (pos = 0; fdt_irqchip_drivers[pos]; pos++) { drv = fdt_irqchip_drivers[pos]; noff = -1; diff --git a/lib/utils/regmap/fdt_regmap.c b/lib/utils/regmap/fdt_regmap.c index 933938fb..ab991c45 100644 --- a/lib/utils/regmap/fdt_regmap.c +++ b/lib/utils/regmap/fdt_regmap.c @@ -13,8 +13,7 @@ #include /* List of FDT regmap drivers generated at compile time */ -extern struct fdt_regmap *fdt_regmap_drivers[]; -extern unsigned long fdt_regmap_drivers_size; +extern struct fdt_regmap *const fdt_regmap_drivers[]; static int fdt_regmap_init(const void *fdt, int nodeoff) { @@ -23,7 +22,7 @@ static int fdt_regmap_init(const void *fdt, int nodeoff) const struct fdt_match *match; /* Try all I2C drivers one-by-one */ - for (pos = 0; pos < fdt_regmap_drivers_size; pos++) { + for (pos = 0; fdt_regmap_drivers[pos]; pos++) { drv = fdt_regmap_drivers[pos]; match = fdt_match_node(fdt, nodeoff, drv->match_table); if (match && drv->init) { diff --git a/lib/utils/reset/fdt_reset.c b/lib/utils/reset/fdt_reset.c index 05deb75e..4b20c3e3 100644 --- a/lib/utils/reset/fdt_reset.c +++ b/lib/utils/reset/fdt_reset.c @@ -14,8 +14,7 @@ #include /* List of FDT reset drivers generated at compile time */ -extern struct fdt_reset *fdt_reset_drivers[]; -extern unsigned long fdt_reset_drivers_size; +extern struct fdt_reset *const fdt_reset_drivers[]; int fdt_reset_driver_init(const void *fdt, struct fdt_reset *drv) { @@ -46,6 +45,6 @@ void fdt_reset_init(const void *fdt) { int pos; - for (pos = 0; pos < fdt_reset_drivers_size; pos++) + for (pos = 0; fdt_reset_drivers[pos]; pos++) fdt_reset_driver_init(fdt, fdt_reset_drivers[pos]); } diff --git a/lib/utils/serial/fdt_serial.c b/lib/utils/serial/fdt_serial.c index a2a96cb2..a7129bdd 100644 --- a/lib/utils/serial/fdt_serial.c +++ b/lib/utils/serial/fdt_serial.c @@ -14,8 +14,7 @@ #include /* List of FDT serial drivers generated at compile time */ -extern struct fdt_serial *fdt_serial_drivers[]; -extern unsigned long fdt_serial_drivers_size; +extern struct fdt_serial *const fdt_serial_drivers[]; int fdt_serial_init(const void *fdt) { @@ -46,7 +45,7 @@ int fdt_serial_init(const void *fdt) } /* First check DT node pointed by stdout-path */ - for (pos = 0; pos < fdt_serial_drivers_size && -1 < noff; pos++) { + for (pos = 0; fdt_serial_drivers[pos] && -1 < noff; pos++) { drv = fdt_serial_drivers[pos]; match = fdt_match_node(fdt, noff, drv->match_table); @@ -64,7 +63,7 @@ int fdt_serial_init(const void *fdt) } /* Lastly check all DT nodes */ - for (pos = 0; pos < fdt_serial_drivers_size; pos++) { + for (pos = 0; fdt_serial_drivers[pos]; pos++) { drv = fdt_serial_drivers[pos]; noff = -1; diff --git a/lib/utils/timer/fdt_timer.c b/lib/utils/timer/fdt_timer.c index 37965f5e..a2412409 100644 --- a/lib/utils/timer/fdt_timer.c +++ b/lib/utils/timer/fdt_timer.c @@ -13,8 +13,7 @@ #include /* List of FDT timer drivers generated at compile time */ -extern struct fdt_timer *fdt_timer_drivers[]; -extern unsigned long fdt_timer_drivers_size; +extern struct fdt_timer *const fdt_timer_drivers[]; int fdt_timer_init(void) { @@ -23,7 +22,7 @@ int fdt_timer_init(void) const struct fdt_match *match; const void *fdt = fdt_get_address(); - for (pos = 0; pos < fdt_timer_drivers_size; pos++) { + for (pos = 0; fdt_timer_drivers[pos]; pos++) { drv = fdt_timer_drivers[pos]; noff = -1; diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 3b20ffbe..2ffb41e2 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -30,8 +30,7 @@ #include /* List of platform override modules generated at compile time */ -extern const struct platform_override *platform_override_modules[]; -extern unsigned long platform_override_modules_size; +extern const struct platform_override *const platform_override_modules[]; static const struct platform_override *generic_plat = NULL; static const struct fdt_match *generic_plat_match = NULL; @@ -42,7 +41,7 @@ static void fw_platform_lookup_special(const void *fdt, int root_offset) const struct fdt_match *match; int pos; - for (pos = 0; pos < platform_override_modules_size; pos++) { + for (pos = 0; platform_override_modules[pos]; pos++) { plat = platform_override_modules[pos]; if (!plat->match_table) continue; diff --git a/scripts/carray.sh b/scripts/carray.sh index 1fa2366a..72808697 100755 --- a/scripts/carray.sh +++ b/scripts/carray.sh @@ -69,10 +69,9 @@ for VAR in ${VAR_LIST}; do done printf "\n" -printf "%s *%s[] = {\n" "${TYPE_NAME}" "${ARRAY_NAME}" +printf "%s *const %s[] = {\n" "${TYPE_NAME}" "${ARRAY_NAME}" for VAR in ${VAR_LIST}; do printf "\t&%s,\n" "${VAR}" done -printf "};\n\n" - -printf "unsigned long %s_size = sizeof(%s) / sizeof(%s *);\n" "${ARRAY_NAME}" "${ARRAY_NAME}" "${TYPE_NAME}" + printf "\tNULL\n" +printf "};\n" From patchwork Mon Nov 11 22:02:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009935 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=wYvfJzeO; 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=JsiY6sY7; 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 4XnNpc1tXlz1xyG for ; Tue, 12 Nov 2024 09:03:20 +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=wWjWnoPChHtB70AdD2chuX/buO7JEIEOC5I3oDJOkXg=; b=wYvfJzeOUhl+jm SNl4K/dOxnBXlYr3USFvlnUsusQwnzihOSP0sYQRvW2Mqx2n+jRrokW//dOxwpOUoUPhgKX45il7E ulffw3h3JyHqeiZo/7D/zHIXY9pRJKCvW4dwO5mCUmn9bnBtYOIRyZEm+d7tODaeAj/WVmAJ0LOq5 /akzttdVJMZ4xrRMgZtK/RwPIoLTUEpyYR0TwAmCXN1yONvnklAAjmQ14TK96CEtroGM+wGl6mcjx 2S+AfGeDZI3IqxEV/llbOikobtN0zDclzPjujk8Y3654KivAKVbrTFCAuqXwSV47iXz4ZiHSF9bal Z8leiM7ulHUcjHzBOOfA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV6-00000001RMo-0na4; Mon, 11 Nov 2024 22:03:12 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV3-00000001RLN-1Scg for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:11 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2e2c6bc4840so3967555a91.2 for ; Mon, 11 Nov 2024 14:03:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362588; x=1731967388; 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=QKxE8H4Y7Yc4U+KO5WHCFEivy/wEtTcL/Myx5LZpHgA=; b=JsiY6sY7WgqY1B0Zl5SvB7WzvqDmVha6fRpkN1sbFiciMD4Z4+346McvdwES3S8Nki JuY3bvXpNumnhqPURDVi+a2vpvbjhCIDmEKVZ+PeGS+O2rEAVUDtc6/czx++raqdRapk vsKowDW7tpLmUgF34YykKFsujZ3QUMhzZZO/LnK/6R+2TtdPoNQr4wJ4pJwKZ+dfYNMk mYU0iV32F+rRAqMfoIXBcSpqx/IOZp/6m6myLYd5ULhS2a4qfH9KQHfzZxkoLDeQ43OE 26aGRh8ZiNNkFRR8KwCrjnzcvI/xLDSloES8ziD6Oimr4iTCnQokOob6kQUe5qiq+aRE Q2Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362588; x=1731967388; 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=QKxE8H4Y7Yc4U+KO5WHCFEivy/wEtTcL/Myx5LZpHgA=; b=iPHmxWLY+LlRXH77rrsMqH6RKhbF2kp8EexlsxPvayqq8S1ZsHF7r5TW43Z6qHOlld S8bOIaYuXiOdiOal65Nb3o7R27lisUqYW0RsQMeJpEPtp9Opl+tjXt9rJurAtic9PkPD uxVAoV14QozChPC7IWTgryjbOxbSpSJorrnbX2AqYAxlvai3575CA3Qq6nHj9+DpTedU Pp8HG4N/iaQozEopXJsVTAxiuSenHu7PCatNUZeri6HoO0qb5pUzhtV07LwQdPuOI1/C vIIkxfzDGPT5sukdEvaEwvbOQaYxmlSTrwXAUWKsUDB9AX0+mMU9I/SSQmyXQopMBkRp CO6g== X-Gm-Message-State: AOJu0YwL0afXhBwBxN8wlTMqxPqGAxmrn6W37MXHN09UVcYRIr9Zdh6B RDLRTj6gcozLg/vX5ZS+QImhYMzIUqhQoxsYjNZzRdao0hiqcax3f23Hr5OcW0bP/2sgtXkQXRI qdV2MDEoqtNcnCkQD5kvdnxQjV0wGceF/hnbSS2H9uRKbXGPmlqvitr+8UONc4joMUD/RY0wN+c 94ycyGEBviMqurqEeP8Fy/BuAbhHt3X+j/yijBWz3qHTyfTbY47Y4= X-Google-Smtp-Source: AGHT+IFcrRBps8Gd0Xw9nCTwPZUQkIXIAsR/BZNCFwgdu7epCkFXD/AmeWo2Mnnu2gcJbhE93NlTLA== X-Received: by 2002:a17:90b:4c10:b0:2e2:b513:d534 with SMTP id 98e67ed59e1d1-2e9b1783a6amr18224404a91.37.1731362588395; Mon, 11 Nov 2024 14:03:08 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:07 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 02/11] lib: utils/fdt: Add helpers for generic driver initialization Date: Mon, 11 Nov 2024 14:02:46 -0800 Message-ID: <20241111220304.1228821-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-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-20241111_140309_411418_36EB1E6C X-CRM114-Status: GOOD ( 22.50 ) 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: Currently, each driver subsystem contains its own code for matching drivers against the platform's devicetree blob. This bloats firmware size because the several FDT scanning loops are almost exact co [...] 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:102e 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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 Currently, each driver subsystem contains its own code for matching drivers against the platform's devicetree blob. This bloats firmware size because the several FDT scanning loops are almost exact copies of each other, and is confusing because the loops do have some subtle differences. Furthermore, the existing match algorithm is inefficient: it scans the FDT structure separately for each driver in the list. A faster algorithm scans the FDT blob only once, matching all drivers in the list for each `compatible` property seen. Add new helpers implementing this faster algorithm. Since they must iterate through the list of drivers, the driver structure cannot be opaque. However, since the driver list is an array of pointers, the `struct fdt_driver` can be embedded in a subsystem-specific driver structure if needed. These three helpers cover all existing use cases for driver initialization within OpenSBI. An additional benefit of centralized driver initialization is the consistent use of fdt_node_is_enabled(). Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- (no changes since v1) include/sbi_utils/fdt/fdt_driver.h | 59 ++++++++++++++++++++++ lib/utils/fdt/fdt_driver.c | 80 ++++++++++++++++++++++++++++++ lib/utils/fdt/objects.mk | 1 + 3 files changed, 140 insertions(+) create mode 100644 include/sbi_utils/fdt/fdt_driver.h create mode 100644 lib/utils/fdt/fdt_driver.c diff --git a/include/sbi_utils/fdt/fdt_driver.h b/include/sbi_utils/fdt/fdt_driver.h new file mode 100644 index 00000000..f6fd26f9 --- /dev/null +++ b/include/sbi_utils/fdt/fdt_driver.h @@ -0,0 +1,59 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * fdt_driver.h - Generic support for initializing drivers from DT nodes. + * + * Copyright (c) 2024 SiFive + */ + +#ifndef __FDT_DRIVER_H__ +#define __FDT_DRIVER_H__ + +#include + +struct fdt_driver { + const struct fdt_match *match_table; + int (*init)(const void *fdt, int nodeoff, + const struct fdt_match *match); +}; + +/** + * Initialize a driver instance for a specific DT node + * + * @param fdt devicetree blob + * @param nodeoff offset of a node in the devicetree blob + * @param drivers NULL-terminated array of drivers to match against this node + * + * @return 0 if a driver was matched and successfully initialized or a negative + * error code on failure + */ +int fdt_driver_init_by_offset(const void *fdt, int nodeoff, + const struct fdt_driver *const *drivers); + +/** + * Initialize a driver instance for each DT node that matches any of the + * provided drivers + * + * @param fdt devicetree blob + * @param drivers NULL-terminated array of drivers to match against each node + * + * @return 0 if drivers for all matches (if any) were successfully initialized + * or a negative error code on failure + */ +int fdt_driver_init_all(const void *fdt, + const struct fdt_driver *const *drivers); + +/** + * Initialize a driver instance for the first DT node that matches any of the + * provided drivers + * + * @param fdt devicetree blob + * @param drivers NULL-terminated array of drivers to match against each node + * + * @return 0 if a driver was matched and successfully initialized or a negative + * error code on failure + */ +int fdt_driver_init_one(const void *fdt, + const struct fdt_driver *const *drivers); + +#endif /* __FDT_DRIVER_H__ */ diff --git a/lib/utils/fdt/fdt_driver.c b/lib/utils/fdt/fdt_driver.c new file mode 100644 index 00000000..586ea8aa --- /dev/null +++ b/lib/utils/fdt/fdt_driver.c @@ -0,0 +1,80 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 SiFive + */ + +#include +#include +#include +#include +#include + +int fdt_driver_init_by_offset(const void *fdt, int nodeoff, + const struct fdt_driver *const *drivers) +{ + const struct fdt_driver *driver; + const struct fdt_match *match; + const void *prop; + int len, rc; + + if (!fdt_node_is_enabled(fdt, nodeoff)) + return SBI_ENODEV; + + prop = fdt_getprop(fdt, nodeoff, "compatible", &len); + if (!prop) + return SBI_ENODEV; + + while ((driver = *drivers++)) { + for (match = driver->match_table; match->compatible; match++) { + if (!fdt_stringlist_contains(prop, len, match->compatible)) + continue; + + rc = driver->init(fdt, nodeoff, match); + if (rc < 0) { + const char *name; + + name = fdt_get_name(fdt, nodeoff, NULL); + sbi_printf("%s: %s (%s) init failed: %d\n", + __func__, name, match->compatible, rc); + } + + return rc; + } + } + + return SBI_ENODEV; +} + +static int fdt_driver_init_scan(const void *fdt, + const struct fdt_driver *const *drivers, + bool one) +{ + int nodeoff, rc; + + for (nodeoff = fdt_next_node(fdt, -1, NULL); + nodeoff >= 0; + nodeoff = fdt_next_node(fdt, nodeoff, NULL)) { + rc = fdt_driver_init_by_offset(fdt, nodeoff, drivers); + if (rc == SBI_ENODEV) + continue; + if (rc < 0) + return rc; + if (one) + return 0; + } + + return one ? SBI_ENODEV : 0; +} + +int fdt_driver_init_all(const void *fdt, + const struct fdt_driver *const *drivers) +{ + return fdt_driver_init_scan(fdt, drivers, false); +} + +int fdt_driver_init_one(const void *fdt, + const struct fdt_driver *const *drivers) +{ + return fdt_driver_init_scan(fdt, drivers, true); +} diff --git a/lib/utils/fdt/objects.mk b/lib/utils/fdt/objects.mk index 5cede811..1a2298be 100644 --- a/lib/utils/fdt/objects.mk +++ b/lib/utils/fdt/objects.mk @@ -7,4 +7,5 @@ libsbiutils-objs-$(CONFIG_FDT_DOMAIN) += fdt/fdt_domain.o libsbiutils-objs-$(CONFIG_FDT_PMU) += fdt/fdt_pmu.o libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_helper.o +libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_driver.o libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_fixup.o From patchwork Mon Nov 11 22:02:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009934 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=Kj2plNMn; 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=b0m4PjBp; 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 4XnNpd01MWz1y0F for ; Tue, 12 Nov 2024 09:03:20 +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=9/XwqYW1bXRSD+mquzlYd6ZXBzC3n4xgUKpoJw4hVo4=; b=Kj2plNMncOSS3x 8drfPei5duHQEHmNUoNe+rWAM4jEteXTpIGL4YUbj7l3y2kNbKx3fN7rkwHtDsDHtxuAlaY/0Lu68 Dtge3qkpCV0X9qAogk0ujcN8+TRKVNr36tOtZlHR4KA/kGh4GnZD8/lCve6vvrck/eldWRt339bp6 zVloadSIFrKuwu7K3ky0LvTcSQ34TdwMMd7eWhO8CFCDqCV2+fHpzKI3CjaVtk0pbKJOlOdLI9+cy MMJuSEERvdianWitrfVfPYx24i/6tw8BKZuH3IBMorSMcSM5/sqHMmOIb+u7hiFJhyWiwSV/3Uwr1 nXzvDK746oWwQ3cPH2kQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV6-00000001RN3-2yFb; Mon, 11 Nov 2024 22:03:12 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV4-00000001RLl-2RY0 for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:11 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-20c8b557f91so53526005ad.2 for ; Mon, 11 Nov 2024 14:03:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362589; x=1731967389; 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=0S/7X5FFgwTcQHPI+LTvpG68DcN29fjwjz62183WOjo=; b=b0m4PjBpdk8Tkyvr6PVatkThM2QhqNEOQeDMRaskQfYniWbST4LiPrHvvRlx+hD088 Lk1olmPxBX50IIhmwlGhS3b++Rl1CwVZHcL2mkNeX2ao0KIdNRER07A8J6OoPsKa961W 5OjTsRzTKFHeTQT2DAnezEydTCGXF94SXwYeqKxmXUx5E0JlFozi2AIRwQWrdmHcOnUZ H7TTBleOYDmhlvkAsINWwD8CUilQ4LugW+4qDJ70XStgU9S4hJ119Shjpwo1fDS+AC2+ QHd0EQk5oYlS5A5CXs6tROZjpfHO8WS78Qzm064avg97a70BZV1G6M1iFmdWJTmSFyMW PJzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362589; x=1731967389; 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=0S/7X5FFgwTcQHPI+LTvpG68DcN29fjwjz62183WOjo=; b=TmCO7141+koPO0fHU6p0D5GiSSK1I7WrfMEF9wnDlBH2uezXpU4SQjtB5JjkWcQ0bZ unKxCcvNVQ55YLvowBl1pPxh7fAMGQhXoDskOeCudj55WZ2W2+rGbrIvGLiOaGGxF3CR Waoyh2uZoMPkg/WVxdSjsgx9oUBDiOsgvIFKR/p0zvFmhINF4FBfMsTyKYlN7boVKBHe bI+HkIK/ZpjHJJvOGp3vs2YLw/NAqre2EHqooaZ7lmP6nXXZw8xI2qjN9IA0aRRh90fS hXtn0vnQEMUA0Zb+ob6HziBDEVA3XAXJ0irHQ1uz8zEjZSc2NKzwSM8b7k0J02kteaPb kXSg== X-Gm-Message-State: AOJu0YzAYjvc/Ui9eUs9TiZ+Ca90anxwJi0kaGeQvfgV+60jkdr68uK6 7BzCJT5FWeLAhIjzB5oSBuLgStSCp8kVT5FQXY+SZBHfEsr3gSbxCZXx6Z3tBhAGpol0qt5pdiG /XOVTkhHFqnT6rzqJmidQQXSjmbbBHYZ+oXkn5Tn1mu0pWIVpjiWr3OuGi2ZY8WBjYdmcSUBgM2 Ks37Ttcg66iLFRcuZnQJ/f0V4EQcBtJ5EWGIEnYuN/ZfBvJQtlvc0= X-Google-Smtp-Source: AGHT+IHu7KbHmrazVNzMBK2HB40pLMxmYrpMkdsPGNiTHkQoYRVTBa7PnAIU6Hdak6Z8QeD1I7I0zw== X-Received: by 2002:a17:902:c411:b0:20c:5b80:930f with SMTP id d9443c01a7336-21183c41e75mr155694585ad.12.1731362589489; Mon, 11 Nov 2024 14:03:09 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:08 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 03/11] scripts/carray.sh: Avoid useless use of cat Date: Mon, 11 Nov 2024 14:02:47 -0800 Message-ID: <20241111220304.1228821-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-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-20241111_140310_646155_FAE4CAEB X-CRM114-Status: UNSURE ( 9.44 ) X-CRM114-Notice: Please train this message. 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: awk(1) takes input files as positional arguments, so there is no need to read the file with cat(1). Signed-off-by: Samuel Holland --- Changes in v2: - New patch for v2 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:633 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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 awk(1) takes input files as positional arguments, so there is no need to read the file with cat(1). Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- Changes in v2: - New patch for v2 scripts/carray.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/carray.sh b/scripts/carray.sh index 72808697..16c6c136 100755 --- a/scripts/carray.sh +++ b/scripts/carray.sh @@ -43,19 +43,19 @@ if [ ! -f "${CONFIG_FILE}" ]; then usage fi -TYPE_HEADER=`cat ${CONFIG_FILE} | awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }'` +TYPE_HEADER=$(awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }' "${CONFIG_FILE}") if [ -z "${TYPE_HEADER}" ]; then echo "Must specify HEADER: in input config file" usage fi -TYPE_NAME=`cat ${CONFIG_FILE} | awk '{ if ($1 == "TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }'` +TYPE_NAME=$(awk '{ if ($1 == "TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }' "${CONFIG_FILE}") if [ -z "${TYPE_NAME}" ]; then echo "Must specify TYPE: in input config file" usage fi -ARRAY_NAME=`cat ${CONFIG_FILE} | awk '{ if ($1 == "NAME:") { printf $2; exit 0; } }'` +ARRAY_NAME=$(awk '{ if ($1 == "NAME:") { printf $2; exit 0; } }' "${CONFIG_FILE}") if [ -z "${ARRAY_NAME}" ]; then echo "Must specify NAME: in input config file" usage From patchwork Mon Nov 11 22:02:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009938 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=vErBey6P; 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=eMVkPkJk; 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 4XnNpc6R76z1y0D for ; Tue, 12 Nov 2024 09:03:20 +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=f4fPDgCpEgCHhH4ipyLOFsiZwXx2u28fi/afrDkBmlE=; b=vErBey6PTgzaf1 3DFTbRRP/sGVYn7D22vQd6gNT9/1xoHs7zsW96fdgHVmEY85h1giN+jxMEVO2WW3GxwnYvlU+iq5K 7tpzk5UTcef0qLVglOfZNJ3z4g7yHdG+TZ38Qosb0ypsPOAafcxgL6bUMZ32vf14pxQlEaub+Usxu uUuD2d/fmi0Cs9DzoRMhTrb4Nd+IhNPl80+diwJpQDNBW2UiMBEA57i2wWeSdmcYo5afmOtvIOYzt Zv2qFJLeDwmzJo39fllXFmRSXxsY7jwOpfawknKZ6PvUIwLjM3sUBiyIvS5TUA4RYfSVNOxHrbWdj qSBYEyWUWuMLTou9klcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV8-00000001ROZ-1uI9; Mon, 11 Nov 2024 22:03:14 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV5-00000001RM4-2VEk for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:12 +0000 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-2e2e88cb0bbso3857463a91.3 for ; Mon, 11 Nov 2024 14:03:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362590; x=1731967390; 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=WH9zmdRrexuUsLYyrA6oSbCslQN6uSorA/tvziT0nIs=; b=eMVkPkJk8qiAmNpfnLptk4TvUe0CodQ574n8WNQzGIHtetSMBMMKZp6z9OjX9jtBwx GmA6S9W3nCLaC4mRoQMvb+HPLUfVNe0oTe22boWw4Wos8Kjhw2GlAgrMbSl4nKLZYd0O IHWclgnuQcXUX9XinS3yomHDdVyzuUkQbAqComCHfZR1BBrhg6xK8uJd2qtk1NLSNjGE seDSyxlXgFpUP+QxcW/aD4n4rs4LD0mfROfgoDVcWgVy9/7iQg/nIH5YH4FnCEmBWmWf bdle8OTNJkAIn5oKcQc2f4ED1RCaNPGG2IG+ctBebIIdCAZxzTSO/7Lwvjd8TrDikPIK b7Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362590; x=1731967390; 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=WH9zmdRrexuUsLYyrA6oSbCslQN6uSorA/tvziT0nIs=; b=gkGcmWZhKvhGEgUI3R5TBcYanacGcUciMpnB6XCptnwOG5hSxK4tRJTFLkbtAgbhUQ SyIMpOSbYJgb5dw99eAynG515plAAitqYlGA2wHY24F5Ww6ceM6EstPSx+7iZy3h/N2e vmegvFqYBu5pY2II3LtqSkDxdBRIV6Sbs+KKelrrSFTIG81ycUjQMFLaAzmYZQVMAcbt 0xUQXbTDGIIe7ofXzFgW867+gJbALtbhSJmgTmL7PgqPDOb+90537ajLBBklamMV6DUE V/vqIGQrdnGabZGCFpzrB9BihsIh0SBDw3WcE3IFbGiI/v8kxTr82tWfMi8ICjljGxoT sJjA== X-Gm-Message-State: AOJu0YypXl7iaJPmdz1O6EWrmJtVPQj8ed9qWafY38Tay7zNRaFPfoMe HunOJTpMYQT/afR11Q27/ayweeBhlliZiN7j00SXmxMiKf8W8dxINb8B01St13mytqxZrVZZCL+ 1xbpnb0OsWAMQsIK1tlwfGLEe8vD8UElcuFmLGXohTTyVpJiN41Cthm/l7/LO69Ai3Dkwf58GkU 6w3D9LXNdGTs4fSLFDLafG0vZhJzysE2kIlTTly99mqfep0w6+EpI= X-Google-Smtp-Source: AGHT+IHq9t+bi6dljiayVdZLTEOn8AdJQa0rlh0CfeKcXFPzmd3WdzSZjQenz64FnnPpX8TlxW18GA== X-Received: by 2002:a17:90b:17c8:b0:2e7:8593:8365 with SMTP id 98e67ed59e1d1-2e9b16f05e9mr18438230a91.5.1731362590435; Mon, 11 Nov 2024 14:03:10 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:10 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 04/11] scripts/carray.sh: Allow referencing a struct member Date: Mon, 11 Nov 2024 14:02:48 -0800 Message-ID: <20241111220304.1228821-5-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-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-20241111_140311_659395_625CB700 X-CRM114-Status: GOOD ( 10.50 ) 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: It can be useful to embed the objects referenced by a carray inside another struct. To avoid type punning, the generated carray code must use the correct type for the enclosing struct and member acces [...] 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:102c 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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 It can be useful to embed the objects referenced by a carray inside another struct. To avoid type punning, the generated carray code must use the correct type for the enclosing struct and member access to compute the desired object address. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- Changes in v2: - New patch for v2 scripts/carray.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/carray.sh b/scripts/carray.sh index 16c6c136..fb985c86 100755 --- a/scripts/carray.sh +++ b/scripts/carray.sh @@ -61,6 +61,13 @@ if [ -z "${ARRAY_NAME}" ]; then usage fi +MEMBER_NAME=$(awk '{ if ($1 == "MEMBER-NAME:") { printf $2; exit 0; } }' "${CONFIG_FILE}") +MEMBER_TYPE=$(awk '{ if ($1 == "MEMBER-TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }' "${CONFIG_FILE}") +if [ -n "${MEMBER_NAME}" ] && [ -z "${MEMBER_TYPE}" ]; then + echo "Must specify MEMBER-TYPE: when using MEMBER-NAME:" + usage +fi + printf "// Generated with $(basename $0) from $(basename ${CONFIG_FILE})\n" printf "#include <%s>\n\n" "${TYPE_HEADER}" @@ -69,9 +76,9 @@ for VAR in ${VAR_LIST}; do done printf "\n" -printf "%s *const %s[] = {\n" "${TYPE_NAME}" "${ARRAY_NAME}" +printf "%s *const %s[] = {\n" "${MEMBER_TYPE:-${TYPE_NAME}}" "${ARRAY_NAME}" for VAR in ${VAR_LIST}; do - printf "\t&%s,\n" "${VAR}" + printf "\t&%s,\n" "${VAR}${MEMBER_NAME:+.}${MEMBER_NAME}" done printf "\tNULL\n" printf "};\n" From patchwork Mon Nov 11 22:02:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009939 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=YfhI9U3x; 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=XmqhmbJv; 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 4XnNpk4Bpkz1xwF for ; Tue, 12 Nov 2024 09:03:26 +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=HDqi+NmF4zt0eNbk5+jltKD8HitSyjUI+CprTfOYMVA=; b=YfhI9U3xlDrRqO gQMMjE30NN2eu4QZWZG65Az1Oy579uh+9hZgaVT1USpOQkHK+yX0JsgNuq2WMgWYgppXCBzHjO7oD U+GG7kraaNTFzHRjJ9CivKmwfqJxSt7ctWvqsNDC9s7hKEek9yFO+PR23b/xO/J7059QogENAPJI0 vO8HjzQvdUlIsMJP3n6g6HSOaiK6DRQlMOVoRnK1V/gZrLtF+YsO+Q0bTJUsI9UCOs4+0rtvWNV3d DaUx2jO5Vg++1AcUSMiWfToxmLxDtUZjfQVJVAjvLDswLs9iOl8itVLlFDVUoGCkLGc9j0oBp/HWp dq4EiKPkzU0MPXW/pjvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcVC-00000001RR5-1WUQ; Mon, 11 Nov 2024 22:03:18 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV6-00000001RMp-2icQ for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:14 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-20cf3e36a76so51060925ad.0 for ; Mon, 11 Nov 2024 14:03:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362592; x=1731967392; 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=wGiNk9Sb9iau6xVwN/bKuk/+GFoqpJ3oaiujlyA7frs=; b=XmqhmbJvzEAen2cfYN72U3pd5HeMo/w3aDga/Y4axITDLXrU3Ro5p1j23dQkFAnTw/ E2hfHQQzSjYVeQZc6pFS9tdXGdgfmYdz0iJ38t0nokuXRkCrj25ipvHrQMUFxA5hxg5P JAvYHW31Iw1dS06ixuEhnlmjlVMXIfbWOb1jQ1tkTPg7MbislQOERPf2fUSe1+xJiaJc 5JNY1g1YHB3Y9dus/Uf2W59gvyIniiurK0QdS1gAGtoNHdOO+h3XXWbNfzVr5Rux+62F BdiS6RwJKUC08WLxmjCSqwUEZRRO3R956MjHGVz/CicbyAC8ofBjeWbnQMObvC/a0e8q +2yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362592; x=1731967392; 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=wGiNk9Sb9iau6xVwN/bKuk/+GFoqpJ3oaiujlyA7frs=; b=vDxPbh0jXX7TamBE4BKhwc0eAVOhx6dgLFbXaVEHIEx5h8dqrMibE5jPAOqgoGmlH/ GQ4mxCb/DWr48tFaGnL4hhVFhPVCMQWK6MnHFaCLtGZ64OHS47WgQDsb2SrLX2arxZPC mLUKXxJtvxRhO38iOD5K7W7X4cz1+vih6HW2R5KUo/A/PSgphu8F2LGqeGfodxgJWOJq UfgA6PAU9peuLc/ex7uj+O551URpTOGd2Liu4JwkfEO9LfuwwWhtAqyIfuKxlGivgTcE 7tZfBP8sRkjkj969IqcUT7NTnzghf4AnNWd86hhYhRFLlh3tf2KyCDddgy8Ht4erE0vE zHQA== X-Gm-Message-State: AOJu0YwAYgnqeVJTYrEJXe2qkgDMPcP8D8Gs2RbbEjEa7GCLer3pCnec M1nAJc5LpHfwxEhMTVS8XOAbDKgVRvE6xE+CQdXDq+5CswW1974njKSWWeP2VIw+w7NFsNusXPt Bf+u4tBh6OIHUl+o4PtZNyJ6cwuyy3p3mPJUce1LzRLNqkjp5Rwu9x7dwv86YcVJjKlTQJcH80b fgMjGbD6uIDVuTl9aNhCQ5gExm7nKd+9SZpij24ZdFedZWZiW7rcw= X-Google-Smtp-Source: AGHT+IF5C/KvTOKjZinO3+aUFawEJKVuba0dCk66PY1D0yyQQCwmM6vIzJICwXjh2KFjjk9SBMTYZA== X-Received: by 2002:a17:902:f54d:b0:20b:6d47:a3b0 with SMTP id d9443c01a7336-211835269d8mr178888605ad.21.1731362591571; Mon, 11 Nov 2024 14:03:11 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:11 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 05/11] lib: utils/gpio: Use fdt_driver for initialization Date: Mon, 11 Nov 2024 14:02:49 -0800 Message-ID: <20241111220304.1228821-6-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-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-20241111_140312_719737_DD3A6873 X-CRM114-Status: GOOD ( 17.90 ) 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: FDT gpio drivers have an extra .xlate operation, so they need to embed the `struct fdt_driver` inside the subsystem-specific type. The gpio subsystem always initializes the driver for a specific DT no [...] 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:629 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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 FDT gpio drivers have an extra .xlate operation, so they need to embed the `struct fdt_driver` inside the subsystem-specific type. The gpio subsystem always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- Changes in v2: - New patch for v2 include/sbi_utils/gpio/fdt_gpio.h | 5 ++--- include/sbi_utils/gpio/gpio.h | 2 +- lib/utils/gpio/fdt_gpio.c | 27 ++++---------------------- lib/utils/gpio/fdt_gpio_designware.c | 10 ++++++---- lib/utils/gpio/fdt_gpio_drivers.carray | 4 +++- lib/utils/gpio/fdt_gpio_sifive.c | 10 ++++++---- lib/utils/gpio/fdt_gpio_starfive.c | 10 ++++++---- 7 files changed, 28 insertions(+), 40 deletions(-) diff --git a/include/sbi_utils/gpio/fdt_gpio.h b/include/sbi_utils/gpio/fdt_gpio.h index ab9304bf..fde667e0 100644 --- a/include/sbi_utils/gpio/fdt_gpio.h +++ b/include/sbi_utils/gpio/fdt_gpio.h @@ -10,18 +10,17 @@ #ifndef __FDT_GPIO_H__ #define __FDT_GPIO_H__ +#include #include struct fdt_phandle_args; /** FDT based GPIO driver */ struct fdt_gpio { - const struct fdt_match *match_table; + struct fdt_driver driver; int (*xlate)(struct gpio_chip *chip, const struct fdt_phandle_args *pargs, struct gpio_pin *out_pin); - int (*init)(const void *fdt, int nodeoff, - const struct fdt_match *match); }; /** Get a GPIO pin using "gpios" DT property of client DT node */ diff --git a/include/sbi_utils/gpio/gpio.h b/include/sbi_utils/gpio/gpio.h index 7a3d8bbe..7027fd19 100644 --- a/include/sbi_utils/gpio/gpio.h +++ b/include/sbi_utils/gpio/gpio.h @@ -40,7 +40,7 @@ struct gpio_pin { /** Representation of a GPIO chip */ struct gpio_chip { /** Pointer to GPIO driver owning this GPIO chip */ - void *driver; + const void *driver; /** Uniquie ID of the GPIO chip assigned by the driver */ unsigned int id; /** Number of GPIOs supported by the GPIO chip */ diff --git a/lib/utils/gpio/fdt_gpio.c b/lib/utils/gpio/fdt_gpio.c index eac2b863..88ba282d 100644 --- a/lib/utils/gpio/fdt_gpio.c +++ b/lib/utils/gpio/fdt_gpio.c @@ -13,34 +13,15 @@ #include /* List of FDT gpio drivers generated at compile time */ -extern struct fdt_gpio *const fdt_gpio_drivers[]; +extern const struct fdt_driver *const fdt_gpio_drivers[]; static int fdt_gpio_init(const void *fdt, int nodeoff) { - int pos, rc; - struct fdt_gpio *drv; - const struct fdt_match *match; - /* Check "gpio-controller" property */ - if (!fdt_getprop(fdt, nodeoff, "gpio-controller", &rc)) + if (!fdt_getprop(fdt, nodeoff, "gpio-controller", NULL)) return SBI_EINVAL; - /* Try all GPIO drivers one-by-one */ - for (pos = 0; fdt_gpio_drivers[pos]; pos++) { - drv = fdt_gpio_drivers[pos]; - - match = fdt_match_node(fdt, nodeoff, drv->match_table); - if (match && drv->init) { - rc = drv->init(fdt, nodeoff, match); - if (rc == SBI_ENODEV) - continue; - if (rc) - return rc; - return 0; - } - } - - return SBI_ENOSYS; + return fdt_driver_init_by_offset(fdt, nodeoff, fdt_gpio_drivers); } static int fdt_gpio_chip_find(const void *fdt, int nodeoff, @@ -71,7 +52,7 @@ int fdt_gpio_pin_get(const void *fdt, int nodeoff, int index, struct gpio_pin *out_pin) { int rc; - struct fdt_gpio *drv; + const struct fdt_gpio *drv; struct gpio_chip *chip = NULL; struct fdt_phandle_args pargs; diff --git a/lib/utils/gpio/fdt_gpio_designware.c b/lib/utils/gpio/fdt_gpio_designware.c index 26e0a7ce..8c19b4f1 100644 --- a/lib/utils/gpio/fdt_gpio_designware.c +++ b/lib/utils/gpio/fdt_gpio_designware.c @@ -30,7 +30,7 @@ struct dw_gpio_chip { struct gpio_chip chip; }; -extern struct fdt_gpio fdt_gpio_designware; +const struct fdt_gpio fdt_gpio_designware; #define pin_to_chip(__p) container_of((__p)->chip, struct dw_gpio_chip, chip); @@ -132,8 +132,10 @@ static const struct fdt_match dw_gpio_match[] = { { }, }; -struct fdt_gpio fdt_gpio_designware = { - .match_table = dw_gpio_match, +const struct fdt_gpio fdt_gpio_designware = { + .driver = { + .match_table = dw_gpio_match, + .init = dw_gpio_init_bank, + }, .xlate = fdt_gpio_simple_xlate, - .init = dw_gpio_init_bank, }; diff --git a/lib/utils/gpio/fdt_gpio_drivers.carray b/lib/utils/gpio/fdt_gpio_drivers.carray index e863f1c5..7807777e 100644 --- a/lib/utils/gpio/fdt_gpio_drivers.carray +++ b/lib/utils/gpio/fdt_gpio_drivers.carray @@ -1,3 +1,5 @@ HEADER: sbi_utils/gpio/fdt_gpio.h -TYPE: struct fdt_gpio +TYPE: const struct fdt_gpio NAME: fdt_gpio_drivers +MEMBER-NAME: driver +MEMBER-TYPE: const struct fdt_driver diff --git a/lib/utils/gpio/fdt_gpio_sifive.c b/lib/utils/gpio/fdt_gpio_sifive.c index d96bf775..0ebc2a4f 100644 --- a/lib/utils/gpio/fdt_gpio_sifive.c +++ b/lib/utils/gpio/fdt_gpio_sifive.c @@ -60,7 +60,7 @@ static void sifive_gpio_set(struct gpio_pin *gp, int value) writel(v, (volatile void *)(chip->addr + SIFIVE_GPIO_OUTVAL)); } -extern struct fdt_gpio fdt_gpio_sifive; +const struct fdt_gpio fdt_gpio_sifive; static int sifive_gpio_init(const void *fdt, int nodeoff, const struct fdt_match *match) @@ -99,8 +99,10 @@ static const struct fdt_match sifive_gpio_match[] = { { }, }; -struct fdt_gpio fdt_gpio_sifive = { - .match_table = sifive_gpio_match, +const struct fdt_gpio fdt_gpio_sifive = { + .driver = { + .match_table = sifive_gpio_match, + .init = sifive_gpio_init, + }, .xlate = fdt_gpio_simple_xlate, - .init = sifive_gpio_init, }; diff --git a/lib/utils/gpio/fdt_gpio_starfive.c b/lib/utils/gpio/fdt_gpio_starfive.c index 55752425..4d09b65c 100644 --- a/lib/utils/gpio/fdt_gpio_starfive.c +++ b/lib/utils/gpio/fdt_gpio_starfive.c @@ -69,7 +69,7 @@ static void starfive_gpio_set(struct gpio_pin *gp, int value) writel(val, (void *)(reg_addr + STARFIVE_GPIO_OUTVAL)); } -extern struct fdt_gpio fdt_gpio_starfive; +const struct fdt_gpio fdt_gpio_starfive; static int starfive_gpio_init(const void *fdt, int nodeoff, const struct fdt_match *match) @@ -109,8 +109,10 @@ static const struct fdt_match starfive_gpio_match[] = { { }, }; -struct fdt_gpio fdt_gpio_starfive = { - .match_table = starfive_gpio_match, +const struct fdt_gpio fdt_gpio_starfive = { + .driver = { + .match_table = starfive_gpio_match, + .init = starfive_gpio_init, + }, .xlate = fdt_gpio_simple_xlate, - .init = starfive_gpio_init, }; From patchwork Mon Nov 11 22:02:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009940 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=IlCNTPmV; 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=VKutWb2w; 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 4XnNpm5Q67z1xwF for ; Tue, 12 Nov 2024 09:03:28 +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=4J7CtLD+Av9Iz36ZYVjGDlrlFce+Kqp2SyqUS8ptQhE=; b=IlCNTPmVzNF6Nc zbJszq7xK7qancHAYuL3xXu3kwjfdoBcfeAG7fIovZOvKlzp6Te1edwuhYp1srnS7ex9Oq227m7EO HoYG0FyYKe30idUxLdpMdFSS/wo/I6KsXS2CH1pvHk5i3U+RoU5eeBgRAVouQS8zWNUoSgY5fNzL/ H/YfAiDX/6qcBxi/PTw9mecL1UQACYAdWptH2YBSGSM0t/F/y5SlSPTlP3l4kzxd6s7YDU44HwIJd zA80p3AEsmySVEqGFDs/VXibDAKUjhYMDGpFNOy9VCmHGvnGrVVVWHjKsPG9WveDVGGwCC+zkTDC/ eFITGPphpKT+sL5plcAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcVE-00000001RSU-0ARz; Mon, 11 Nov 2024 22:03:20 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV7-00000001RO3-3yex for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:15 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-20ca1b6a80aso53322925ad.2 for ; Mon, 11 Nov 2024 14:03:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362593; x=1731967393; 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=H8649rlh4jfqfSG3EFGw96deB1ol3jSGUhJFBQ3uXvQ=; b=VKutWb2wscg1ijXP98C0cR7urJXZ4WxSFTn7gzU3yTptOaMcT+EzBlGcD3kThjBfJT tqbPmeShmrDsnIX7r80joPxqDTPBUSX38LQBVLpCKzS6QIBZjax17Xne8r4ZrVvNgbfg k7dHkrDyeU3+POXBgnxSb1BiyYroZI0yA9/NmlgCeqn1+uB1f7K+81mIDnQfwpRM0SOC oXk9cOBJZ3URzByI7lUDFqw688kmtczh42dd+f5z2U9c+MFVKmjPZ/JfFWNwwLgLJOd5 hNv9LXFoQLoS+vuZgS8yeIAHuguhMeNWsMehqsn31lcJ6Lie0HpquD+YHe3j4nvBCvG6 lxxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362593; x=1731967393; 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=H8649rlh4jfqfSG3EFGw96deB1ol3jSGUhJFBQ3uXvQ=; b=o3oUF+Siyj7RxEdFeEbfwnDs44yAwt+vsmknA6hSwyj+hTny7YUSXG8QcPHGo7lV2d h/CWdxIgl+pmHC2KUDFLACtrEtNk8TnJBSRp47WIZ8HGhb08oQr1k/i8j4GY3Iop5xqu YSOPhTAD3vL8t4lU95MhR5QTbrU7kYXyjImrDegmfaHruZwtmbuJWJCzfIE0Y/nZ3NXE 1CaGsDvJoIyrfGTe1YXYpws5rxvpJY5IOQJVV3WYsDCiJXbfTYRZLvoD6/cH97KSpT39 WQPAaAm+moON2wYkohNIDbGZaaXj1hK9VRL7t8ZE2tjdaEMwHuoZurIL/h3N8rYRNE9G sj9Q== X-Gm-Message-State: AOJu0YyRsSSt/oMyPjSvCZ7FTkgRyyC4yIMXdctd/GqVbsdknPyQgL4E IVIBAvTqlWT1p0UmmREYL9SSa/MDYuD2CMXgWUnc+1sqb8b9KLIi7v905RsNG4OUs814EwuObXO jpO9NuoMD0IXJBgUj7tsOd45FdUc7n7j8VJblWHTZAERLOoquMosVzV/GEULL2zzWy+/Jm88yOy /ZIYKrvYOnEQsUTFtCrGAnb4w8OADiC8UBSTBRLSStHWD+R6HDKws= X-Google-Smtp-Source: AGHT+IGGZ9FqN0oVoQ5ld/8NYdmNk6dYaCv9OfU0E+TTtoDgjX/A05aeyg8KAkknFEuozz2MqLY5jQ== X-Received: by 2002:a17:903:41c6:b0:202:cbf:2d6f with SMTP id d9443c01a7336-21183db6b71mr161696625ad.57.1731362592820; Mon, 11 Nov 2024 14:03:12 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:12 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 06/11] lib: utils/i2c: Use fdt_driver for initialization Date: Mon, 11 Nov 2024 14:02:50 -0800 Message-ID: <20241111220304.1228821-7-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-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-20241111_140314_149355_2B1DD34B X-CRM114-Status: GOOD ( 13.89 ) 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 i2c driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. It always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland --- 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:634 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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 i2c driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. It always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- (no changes since v1) include/sbi_utils/i2c/fdt_i2c.h | 8 +----- lib/utils/i2c/fdt_i2c.c | 30 ++------------------ lib/utils/i2c/fdt_i2c_adapter_drivers.carray | 2 +- lib/utils/i2c/fdt_i2c_dw.c | 2 +- lib/utils/i2c/fdt_i2c_sifive.c | 2 +- 5 files changed, 7 insertions(+), 37 deletions(-) diff --git a/include/sbi_utils/i2c/fdt_i2c.h b/include/sbi_utils/i2c/fdt_i2c.h index 65758ec2..8cae4c2a 100644 --- a/include/sbi_utils/i2c/fdt_i2c.h +++ b/include/sbi_utils/i2c/fdt_i2c.h @@ -10,15 +10,9 @@ #ifndef __FDT_I2C_H__ #define __FDT_I2C_H__ +#include #include -/** FDT based I2C adapter driver */ -struct fdt_i2c_adapter { - const struct fdt_match *match_table; - int (*init)(const void *fdt, int nodeoff, - const struct fdt_match *match); -}; - /** Get I2C adapter identified by nodeoff */ int fdt_i2c_adapter_get(const void *fdt, int nodeoff, struct i2c_adapter **out_adapter); diff --git a/lib/utils/i2c/fdt_i2c.c b/lib/utils/i2c/fdt_i2c.c index 56891a0a..d5d36c21 100644 --- a/lib/utils/i2c/fdt_i2c.c +++ b/lib/utils/i2c/fdt_i2c.c @@ -11,36 +11,11 @@ * Anup Patel */ -#include #include -#include #include /* List of FDT i2c adapter drivers generated at compile time */ -extern struct fdt_i2c_adapter *const fdt_i2c_adapter_drivers[]; - -static int fdt_i2c_adapter_init(const void *fdt, int nodeoff) -{ - int pos, rc; - struct fdt_i2c_adapter *drv; - const struct fdt_match *match; - - /* Try all I2C drivers one-by-one */ - for (pos = 0; fdt_i2c_adapter_drivers[pos]; pos++) { - drv = fdt_i2c_adapter_drivers[pos]; - match = fdt_match_node(fdt, nodeoff, drv->match_table); - if (match && drv->init) { - rc = drv->init(fdt, nodeoff, match); - if (rc == SBI_ENODEV) - continue; - if (rc) - return rc; - return 0; - } - } - - return SBI_ENOSYS; -} +extern const struct fdt_driver *const fdt_i2c_adapter_drivers[]; static int fdt_i2c_adapter_find(const void *fdt, int nodeoff, struct i2c_adapter **out_adapter) @@ -50,7 +25,8 @@ static int fdt_i2c_adapter_find(const void *fdt, int nodeoff, if (!adapter) { /* I2C adapter not found so initialize matching driver */ - rc = fdt_i2c_adapter_init(fdt, nodeoff); + rc = fdt_driver_init_by_offset(fdt, nodeoff, + fdt_i2c_adapter_drivers); if (rc) return rc; diff --git a/lib/utils/i2c/fdt_i2c_adapter_drivers.carray b/lib/utils/i2c/fdt_i2c_adapter_drivers.carray index fd51ae1a..0e8c73a4 100644 --- a/lib/utils/i2c/fdt_i2c_adapter_drivers.carray +++ b/lib/utils/i2c/fdt_i2c_adapter_drivers.carray @@ -1,3 +1,3 @@ HEADER: sbi_utils/i2c/fdt_i2c.h -TYPE: struct fdt_i2c_adapter +TYPE: const struct fdt_driver NAME: fdt_i2c_adapter_drivers diff --git a/lib/utils/i2c/fdt_i2c_dw.c b/lib/utils/i2c/fdt_i2c_dw.c index 7d14ea0d..b0905e7b 100644 --- a/lib/utils/i2c/fdt_i2c_dw.c +++ b/lib/utils/i2c/fdt_i2c_dw.c @@ -49,7 +49,7 @@ static const struct fdt_match fdt_dw_i2c_match[] = { { }, }; -struct fdt_i2c_adapter fdt_i2c_adapter_dw = { +const struct fdt_driver fdt_i2c_adapter_dw = { .match_table = fdt_dw_i2c_match, .init = fdt_dw_i2c_init, }; diff --git a/lib/utils/i2c/fdt_i2c_sifive.c b/lib/utils/i2c/fdt_i2c_sifive.c index b420a7da..40811cb4 100644 --- a/lib/utils/i2c/fdt_i2c_sifive.c +++ b/lib/utils/i2c/fdt_i2c_sifive.c @@ -265,7 +265,7 @@ static const struct fdt_match sifive_i2c_match[] = { { }, }; -struct fdt_i2c_adapter fdt_i2c_adapter_sifive = { +const struct fdt_driver fdt_i2c_adapter_sifive = { .match_table = sifive_i2c_match, .init = sifive_i2c_init, }; From patchwork Mon Nov 11 22:02:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009941 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=wuXFpX34; 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=WST1p35a; 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 4XnNpn2L9Dz1xyG for ; Tue, 12 Nov 2024 09:03:29 +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=6tEh6nwf5idF0jUbFWNuqUxxuX7WHQmTAmVnIdnLqw4=; b=wuXFpX34WI8NS7 pxB0dmm50pIsqehNeM/UI37yAynmCzmfAswQ/q2GJKZbw1omWRX6SpOnG0+3VsyhH6AECj2ELrtit js26Z4ZeX8yNrUfTK8FjACaiQ3yXsGTNAe5f99CsKPgi0qbHL0y5SOs98Dbt5YkQrz1C73sqBsMsz eQhiUFzfTelMNCn/wg2rVlnb2cl6WHzMZET9ZYt6I9M9HRXPq3K6ySnpvXOx4kIFoFTUzg3DS2Rrf 8wSRSg4E5Hvjjn98jHsuu19H4ZDJ/VtoWb63p8wgOmUq3nEGTpbQYMCF0RiY1KjeBJ1jK0YZa+v1e mxeUstSqat3rDK8TivSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcVF-00000001RU2-1hIw; Mon, 11 Nov 2024 22:03:21 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV9-00000001ROp-0MJz for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:16 +0000 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2e2ad9825a7so3762425a91.0 for ; Mon, 11 Nov 2024 14:03:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362594; x=1731967394; 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=+XfIZ1UhXVRovl+n6SFGSpuoTFvewVviXcxcFNuEMjE=; b=WST1p35a+gy4MOXkD9/goGjaBOz2PR88OPu2H/hkGgtqmM9aczA03h+PiRTCIXFd+K trzOdUd32Eg+QNyZxgYUDY4c4IBzPGtxA69ScQevvHhD2jIUiXWVBGSlkrO+A5qPison gXVAegzLjzmVueyjw5u+/7Y2lbR1IJSqZy+vYpQwpaX4O2fJxYTBNe8GnODKWAN/MRqs IoVf4zJwsPl1Wr7zXtb9I7SD1eo/yt6trRymU6PvnWEnIT8egI13xRCadXlHo8F7mEGV d/6C+zL8GF9mqOYHFKUsqcJcX6maajk6Yl5MK7HS3WdASntE3DpQOIVSwLohAJYQA6/U aLyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362594; x=1731967394; 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=+XfIZ1UhXVRovl+n6SFGSpuoTFvewVviXcxcFNuEMjE=; b=CXccVJBYzevJ9PZaQ/0bw4d8qjkOyJvzMt36ZY3wIbhub16+TMVhfhJD1/+cDTSXgY BwmcJ++s5UK3eGJMvUuL57PPt/+VusKJ8ydIAU/rQRGXgYUpeidbNxFP4x26f4Vx2h+g ol9dNjOFnZqlYcv8nKg3QUDenUhQII6z/Ll6RDt/b0AGkd3TNkIoCtZPIrqDcPWODdJw dvJ90ajl5ruuIapvKQYLQZcLWiJOSG+6qAIlpUU4k7sfeNuX3WiSLq3q9XzZSspieOWu ITEGFS3RbmEgHpBr98fn7Ww5mMXCQu4DEiSVjAHUR/zb1lIcueovSNquZgpvVeYQrK84 nDQw== X-Gm-Message-State: AOJu0Yx9gQaFseBhy+sPf+Bc7L2rxzQVVqsrNxFNwbtNwHE/PSuN6H8j l7VK03YRj6tv8Ls9rJ1lx252eHDm8mOXNPpFyDE33WzHOcyaRmGe/vifuEMN6hmXgsoW3H7r6cu FBhKPzcpyuZStoYa71jsOhIfxvA9CoMdI45eoNB/4cYOg+6FY6DFHzBb8LtaJM53g/AG7P01Jyx x/8Ozk98tPt6ecluotwhMkyFPsNwo7ufWfqXzEi2fb9ox2i0q/j+k= X-Google-Smtp-Source: AGHT+IGZid00DJbqI7ItqwyhHxFyksHdo9Oo6Y7n1t5PUXfl1hWbyGlmoG8nWb9O5hJpceWQCWCfaw== X-Received: by 2002:a17:90a:d405:b0:2e2:d3a0:4716 with SMTP id 98e67ed59e1d1-2e9b173c50fmr21835498a91.18.1731362593875; Mon, 11 Nov 2024 14:03:13 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:13 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 07/11] lib: utils/ipi: Use fdt_driver for initialization Date: Mon, 11 Nov 2024 14:02:51 -0800 Message-ID: <20241111220304.1228821-8-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-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-20241111_140315_151912_727C5225 X-CRM114-Status: GOOD ( 16.22 ) 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 ipi driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_ipi_init() performs a best-effort initialization of all matching DT nodes. Signed-off-by: Samuel Holland --- 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:1033 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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 ipi driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_ipi_init() performs a best-effort initialization of all matching DT nodes. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- Changes in v2: - New patch for v2 include/sbi_utils/ipi/fdt_ipi.h | 6 +--- lib/utils/ipi/fdt_ipi.c | 42 +++------------------------- lib/utils/ipi/fdt_ipi_drivers.carray | 2 +- lib/utils/ipi/fdt_ipi_mswi.c | 4 +-- lib/utils/ipi/fdt_ipi_plicsw.c | 4 +-- 5 files changed, 10 insertions(+), 48 deletions(-) diff --git a/include/sbi_utils/ipi/fdt_ipi.h b/include/sbi_utils/ipi/fdt_ipi.h index 161f7a2e..9b014470 100644 --- a/include/sbi_utils/ipi/fdt_ipi.h +++ b/include/sbi_utils/ipi/fdt_ipi.h @@ -11,14 +11,10 @@ #define __FDT_IPI_H__ #include +#include #ifdef CONFIG_FDT_IPI -struct fdt_ipi { - const struct fdt_match *match_table; - int (*cold_init)(const void *fdt, int nodeoff, const struct fdt_match *match); -}; - int fdt_ipi_init(void); #else diff --git a/lib/utils/ipi/fdt_ipi.c b/lib/utils/ipi/fdt_ipi.c index 6c2feafb..644c9c1c 100644 --- a/lib/utils/ipi/fdt_ipi.c +++ b/lib/utils/ipi/fdt_ipi.c @@ -7,50 +7,16 @@ * Anup Patel */ -#include -#include -#include #include /* List of FDT ipi drivers generated at compile time */ -extern struct fdt_ipi *const fdt_ipi_drivers[]; +extern const struct fdt_driver *const fdt_ipi_drivers[]; int fdt_ipi_init(void) { - int pos, noff, rc; - struct fdt_ipi *drv; - const struct fdt_match *match; - const void *fdt = fdt_get_address(); - - for (pos = 0; fdt_ipi_drivers[pos]; pos++) { - drv = fdt_ipi_drivers[pos]; - - noff = -1; - while ((noff = fdt_find_match(fdt, noff, - drv->match_table, &match)) >= 0) { - if (!fdt_node_is_enabled(fdt, noff)) - continue; - - /* drv->cold_init must not be NULL */ - if (drv->cold_init == NULL) - return SBI_EFAIL; - - rc = drv->cold_init(fdt, noff, match); - if (rc == SBI_ENODEV) - continue; - if (rc) - return rc; - - /* - * We will have multiple IPI devices on multi-die or - * multi-socket systems so we cannot break here. - */ - } - } - /* - * On some single-hart system there is no need for ipi, - * so we cannot return a failure here + * On some single-hart system there is no need for IPIs, + * so do not return a failure if no device is found. */ - return 0; + return fdt_driver_init_all(fdt_get_address(), fdt_ipi_drivers); } diff --git a/lib/utils/ipi/fdt_ipi_drivers.carray b/lib/utils/ipi/fdt_ipi_drivers.carray index 275fa9cf..006b0fd9 100644 --- a/lib/utils/ipi/fdt_ipi_drivers.carray +++ b/lib/utils/ipi/fdt_ipi_drivers.carray @@ -1,3 +1,3 @@ HEADER: sbi_utils/ipi/fdt_ipi.h -TYPE: struct fdt_ipi +TYPE: const struct fdt_driver NAME: fdt_ipi_drivers diff --git a/lib/utils/ipi/fdt_ipi_mswi.c b/lib/utils/ipi/fdt_ipi_mswi.c index c58d7722..aa37d0d0 100644 --- a/lib/utils/ipi/fdt_ipi_mswi.c +++ b/lib/utils/ipi/fdt_ipi_mswi.c @@ -61,7 +61,7 @@ static const struct fdt_match ipi_mswi_match[] = { { }, }; -struct fdt_ipi fdt_ipi_mswi = { +const struct fdt_driver fdt_ipi_mswi = { .match_table = ipi_mswi_match, - .cold_init = ipi_mswi_cold_init, + .init = ipi_mswi_cold_init, }; diff --git a/lib/utils/ipi/fdt_ipi_plicsw.c b/lib/utils/ipi/fdt_ipi_plicsw.c index a178db1b..be669980 100644 --- a/lib/utils/ipi/fdt_ipi_plicsw.c +++ b/lib/utils/ipi/fdt_ipi_plicsw.c @@ -39,7 +39,7 @@ static const struct fdt_match ipi_plicsw_match[] = { {}, }; -struct fdt_ipi fdt_ipi_plicsw = { +const struct fdt_driver fdt_ipi_plicsw = { .match_table = ipi_plicsw_match, - .cold_init = fdt_plicsw_cold_ipi_init, + .init = fdt_plicsw_cold_ipi_init, }; From patchwork Mon Nov 11 22:02:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009942 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=Kz4WS+aq; 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=BBTnUGob; 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 4XnNpt0mXPz1xwF for ; Tue, 12 Nov 2024 09:03:34 +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=o2yJ13Rw6SE6XkmdJ3szS6h538VJcZqt6tb6yVPqeRI=; b=Kz4WS+aqXBPQxt YP/rjVC0knwMkptVPlQ4LyhJGU9oNeXILf0PGJ7B/eS3eKwgRtWfyeqo/QZO4tXTS7wpQ8aDqqYA0 jhIq7+UmaPM8kAfvfLodX+1WMhd++GkLSm42nPs6hUJFG0ZC9eWCahAHcd5bP11T9LgFhFTLsPdK7 8z/NcvtfmVuUs8SPHefXMTw2vCFaOm0GnvAI0KVYbsftBkoFNYvKXHWh+K+tntZVz65XDqTxhR6Y4 N/Dyc8RaOIH+q0IS8JdV2OO2vGKWtEUfZH22B8FcdxXcXUyV3y1GDIZu0BYLmJ0e30hrfWrDYs1iU FFxA9BzmHP6Exxmy1eOg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcVJ-00000001RX4-0Aqf; Mon, 11 Nov 2024 22:03:25 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV9-00000001RPJ-3X6o for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:17 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2110a622d76so43773165ad.3 for ; Mon, 11 Nov 2024 14:03:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362595; x=1731967395; 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=Dfs56uyrmiUM9vyzd+FoJogqukbPlTKVK2RnzuOuBMU=; b=BBTnUGobnuUq8mBQBS+5JvrNuLEuzDEreI1Un9fPadb4kIKHKkcaKU/0GKVwdvM0Kv AAiMUiersj+9hLltAiUhdTX4jjs4ibs8YU/hmyMkmi863mTp457OVb04wof3eJzZfO5A N8Ycn/gRcRqkBd6ZJ3NdGb/cNONou6dUkIkSHIU9QBFIyf77qQI62KxfyRRiRrJMgcoa TEqg/vAhPf0m6D/N94RmfyHFvFRXrRbujotoW20j/ZnLyv9ZPBcju6Fy9O1IaEWGetMu y4b7pH77h+UY0dnYaqAgNphgCgus4qmuPOxGHGTOhr/p5eKB1OkLRN5xo+pVU6Ben+bq PJmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362595; x=1731967395; 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=Dfs56uyrmiUM9vyzd+FoJogqukbPlTKVK2RnzuOuBMU=; b=YjkpZZq4J0GqDoc7NrD/oxGXPef4YjDDJxCPVufKmH5jd6oa7Paw+JWt5lKrHGxWuf CfZ/2LxbsWNQt6yg3j/YHAXCzw7y+tigFaY66Kx0MSF9Gm+1W4QUuPO6SC8NGxEsfd8e 7t/s++KjhceGm97rq5141UsbnQCMjRxEMSRguFGgdqRTGCdEVIlLqSii+Jc/NQ2rfEDo Jvxs5uSBTpwKgsJiE2lQxL82m0Xxumga1s8kf9NaLm2F13qEqflKZbM8XDu6ELwj4UGF KAZou3Rfg0C0+A6hbA9Nu6DE+SHZrNTA+yYRFO1p5ov5z2ierGhsJM/naK50u5N7Yd54 TB8A== X-Gm-Message-State: AOJu0YxpepJIm25UZkYMCZ/nyNXBF4pZlEdDV3v1jCLO9PMZUY0ANWYp PYZYjXCwu1+sXBCvmdlnu6nsWHv/46lrbkx6USEcKqd7cZrrOuJhqqqCm/6fJWZAhM2CuMA+XCu 3khB+Hntey9JUMAqWCJcmNrAZqSjT9V6spmjI60tqR1dqkoBfs5Vil+p325uqp5tL1XVy9nB0jx cYY/ePRDmU3u/WDPEREhtmq+eHTVZvbur+g6LGMJP4DlALGL4pvUY= X-Google-Smtp-Source: AGHT+IFjWzjbAzLm8bahWw9QoZEHj9W1KtF6n2pLmaGj7y0q+eJkuX0kDf/7vmATKdZBb+2jgX2CsQ== X-Received: by 2002:a17:902:e549:b0:20f:c225:f28c with SMTP id d9443c01a7336-21183da3eeemr202097925ad.52.1731362594868; Mon, 11 Nov 2024 14:03:14 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:14 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 08/11] lib: utils/regmap: Use fdt_driver for initialization Date: Mon, 11 Nov 2024 14:02:52 -0800 Message-ID: <20241111220304.1228821-9-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-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-20241111_140316_104037_7FA944B2 X-CRM114-Status: GOOD ( 14.62 ) 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 regmap driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. It always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland --- 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:636 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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 regmap driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. It always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- Changes in v2: - New patch for v2 include/sbi_utils/regmap/fdt_regmap.h | 8 +------ lib/utils/regmap/fdt_regmap.c | 28 +++------------------- lib/utils/regmap/fdt_regmap_drivers.carray | 2 +- lib/utils/regmap/fdt_regmap_syscon.c | 2 +- 4 files changed, 6 insertions(+), 34 deletions(-) diff --git a/include/sbi_utils/regmap/fdt_regmap.h b/include/sbi_utils/regmap/fdt_regmap.h index de946f27..a24f7a98 100644 --- a/include/sbi_utils/regmap/fdt_regmap.h +++ b/include/sbi_utils/regmap/fdt_regmap.h @@ -10,17 +10,11 @@ #ifndef __FDT_REGMAP_H__ #define __FDT_REGMAP_H__ +#include #include struct fdt_phandle_args; -/** FDT based regmap driver */ -struct fdt_regmap { - const struct fdt_match *match_table; - int (*init)(const void *fdt, int nodeoff, - const struct fdt_match *match); -}; - /** Get regmap instance based on phandle */ int fdt_regmap_get_by_phandle(const void *fdt, u32 phandle, struct regmap **out_rmap); diff --git a/lib/utils/regmap/fdt_regmap.c b/lib/utils/regmap/fdt_regmap.c index ab991c45..2e8c2143 100644 --- a/lib/utils/regmap/fdt_regmap.c +++ b/lib/utils/regmap/fdt_regmap.c @@ -13,30 +13,7 @@ #include /* List of FDT regmap drivers generated at compile time */ -extern struct fdt_regmap *const fdt_regmap_drivers[]; - -static int fdt_regmap_init(const void *fdt, int nodeoff) -{ - int pos, rc; - struct fdt_regmap *drv; - const struct fdt_match *match; - - /* Try all I2C drivers one-by-one */ - for (pos = 0; fdt_regmap_drivers[pos]; pos++) { - drv = fdt_regmap_drivers[pos]; - match = fdt_match_node(fdt, nodeoff, drv->match_table); - if (match && drv->init) { - rc = drv->init(fdt, nodeoff, match); - if (rc == SBI_ENODEV) - continue; - if (rc) - return rc; - return 0; - } - } - - return SBI_ENOSYS; -} +extern const struct fdt_driver *const fdt_regmap_drivers[]; static int fdt_regmap_find(const void *fdt, int nodeoff, struct regmap **out_rmap) @@ -46,7 +23,8 @@ static int fdt_regmap_find(const void *fdt, int nodeoff, if (!rmap) { /* Regmap not found so initialize matching driver */ - rc = fdt_regmap_init(fdt, nodeoff); + rc = fdt_driver_init_by_offset(fdt, nodeoff, + fdt_regmap_drivers); if (rc) return rc; diff --git a/lib/utils/regmap/fdt_regmap_drivers.carray b/lib/utils/regmap/fdt_regmap_drivers.carray index c2f1c9d0..d19a932b 100644 --- a/lib/utils/regmap/fdt_regmap_drivers.carray +++ b/lib/utils/regmap/fdt_regmap_drivers.carray @@ -1,3 +1,3 @@ HEADER: sbi_utils/regmap/fdt_regmap.h -TYPE: struct fdt_regmap +TYPE: const struct fdt_driver NAME: fdt_regmap_drivers diff --git a/lib/utils/regmap/fdt_regmap_syscon.c b/lib/utils/regmap/fdt_regmap_syscon.c index ba559086..1309a55c 100644 --- a/lib/utils/regmap/fdt_regmap_syscon.c +++ b/lib/utils/regmap/fdt_regmap_syscon.c @@ -263,7 +263,7 @@ static const struct fdt_match regmap_syscon_match[] = { { }, }; -struct fdt_regmap fdt_regmap_syscon = { +const struct fdt_driver fdt_regmap_syscon = { .match_table = regmap_syscon_match, .init = regmap_syscon_init, }; From patchwork Mon Nov 11 22:02:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009943 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=wtWo1uEq; 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=OczQt+lK; 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 4XnNpt6WGgz1xyG for ; Tue, 12 Nov 2024 09:03:34 +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=ZdLQHJqXdPDKEdfX6lvQsx9qg59QVGEiAgUWNjo1IKw=; b=wtWo1uEqyuV6bG jpFIwM12SH3oMgt4rhCTF/BlHP5q4wWMixDSlfFj9ei8u65iIv6KgOn765XsPnx0Ch5PNGKW1zxTq Hizxkl5C1eQZxPzSxnwODot6bbjbD4uaTuX0jTFr3qNbZRwDbGefPoebwHOEh4QW253gXPWQIx2+G wO8CsKSVoTb/2JucnpgMzDEM29J0CW6Nk1woKUvQ4s8WOrcbb1nOFZcpZJN9anHi+o0gcQSNXELWA uXDYVMwih5gKVgrhPxfj989oKqtnN7WxwbGbCnBBm/j4k/rRrMqJAl/cnzymL/LajXxvvH4+ceRgL hyemqiqVWo1KhiSKmoWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcVL-00000001RZW-1Hg3; Mon, 11 Nov 2024 22:03:27 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcVA-00000001RQ1-3Fwr for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:19 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-20cdbe608b3so49986025ad.1 for ; Mon, 11 Nov 2024 14:03:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362596; x=1731967396; 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=Z0G7Gd7p1wCfs5wr86dH4Scgd1f+yFhix5z3tukf5qE=; b=OczQt+lKY4Mn5sRty8AKaLq2+36X+9DSzTCZ6QVog35348/T0tKgiThaEhRQwLAtu9 HpJQwgj5Lh0CwkhWjAEHtRmdG7VhcpE4wTj5LLap99Z5KGU5RF3ow6P+fh2diFQh6H+D RxHSksVVfdlPSe7UpfW0EYKtiflw81dloPcnPkPVSoe5z+NHerMgq/0fT2wETZ1sf+pj 5DLGxjVdVILHdWcsM6/T5pqmfc//seurSfjk8Ib4iUQX3lyJm6l957FD/bKuWUCLaG6h U34FyimKB5H6BowE8x5Mx1MnkbOw0oxuVswwKVw8PIYTLQNdjNcx1nCg+aeXM/MuUy+6 uB5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362596; x=1731967396; 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=Z0G7Gd7p1wCfs5wr86dH4Scgd1f+yFhix5z3tukf5qE=; b=fVBwpiYKsD4AG+HHSBgUNq6LDtH/5mPSKT9fdVojbqTB6M7K7ieX9lnkIni+HfSDH1 lFcUzsA4zggKzoUUxQT2cWhHoA+rEyQHJmBYLXxrlCYpvwB2syw2yRjNZXumdfRrGdnX fFj8GYnIG91ws73OMJwsyEPCrkosi+GW3bCuopb3dji74CDEYgi0/PQFXF1di2PNEO7V 3Bk9dmQ7lnCDHnnZsYe9hCV0IbVEqeic/wBqlZTf3QNHyV4Q9XYkfYORbr8kR3r5LL2V KUjFzGeVZIHhPA6wVwu1bN5I3fV3ywP0tilRewzv7ossfbGdBMLKNvMVvJy+Qqn3pJpW 505A== X-Gm-Message-State: AOJu0YwjRFe0gc6voq8wmMyQx4u4QNsHjFcQS9OwgVhdAvpErJBz8eh7 VgOW99dWAdQ71cwhChj8REiUZN5OZskQ7yXehLq36BCcJqYz9+1aKXG8WTBL1yj0HSKobDayB9P Hnejr+JSFAnixZIQPZ3snnirhUZihyYTIqOn02Fg6BEZfFaZd0gzd5HUDHWaDPPKGoMW9LP+znz pLL0CtKiER72960wIc4bV3GJQu3ZS08z118aZz9F+Fw12blruFWK0= X-Google-Smtp-Source: AGHT+IH1Dcy4Qmmic1ZSBeKyT80AAJ0d5buVxkjOQDeb12vb4x0uCKcnXmFbv42SA3Xb8y48vd3T3w== X-Received: by 2002:a17:902:d505:b0:20c:bea0:8d10 with SMTP id d9443c01a7336-211ab93e55cmr3186665ad.20.1731362595777; Mon, 11 Nov 2024 14:03:15 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:15 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 09/11] lib: utils/reset: Use fdt_driver for initialization Date: Mon, 11 Nov 2024 14:02:53 -0800 Message-ID: <20241111220304.1228821-10-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-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-20241111_140316_843603_BCA3CFEF X-CRM114-Status: GOOD ( 16.54 ) 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:62e 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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 Reviewed-by: Anup Patel --- (no changes since v1) 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; From patchwork Mon Nov 11 22:02:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009944 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=BJkNSg/Z; 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=ge37Qcw9; 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 4XnNpy61HWz1xwF for ; Tue, 12 Nov 2024 09:03:38 +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=aZqkqRG0I5R6igJYKfUCkkZnX+thS7rFtm7XAXSytFQ=; b=BJkNSg/ZBfSVN1 ziUAZAbwr/S0jPGvZnqc2iMUur1l17OcSJGDZDO2WjeXn4z0WupDgprBKR0tlObthQXhvvlV/QyBm l+dUgm4bUR71jloZ6DbyRbdMYOi1/ILc5bcuMshLVPXzW7UpISEG9I28aE7iwt2ZC9Uo6kOG6W8RC g71MbaO8qPcRNzbOvOcCzxrzlJbphBdby+vjuOTbXpS8nu60qGc7hve/ccgXVApiKS4hJBi7KOI9E RmN8ey7v0ddpoTnKXlNIXaOYdbW+ddJq2Nr8ZoB/AFr8OcvmMlPPLQvVX+G1QjdpiLUF2NFA6Hzfo jpOJA3QM9X7xeoeqe/Qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcVO-00000001Rc7-1DEA; Mon, 11 Nov 2024 22:03:30 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcVB-00000001RQf-2TYO for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:19 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-20ca1b6a80aso53323565ad.2 for ; Mon, 11 Nov 2024 14:03:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362597; x=1731967397; 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=MMs6VNiuxgnQW+UbhV/F8Zn0UTh3B4+3JvRh5MWpSdA=; b=ge37Qcw9HYeD5MbDUxckaX5CBGKKj8LDb6ZGkCin34qWQ3Wa+YJEphhQGrewIBqy5k YR619F2EQ0Kcxi01Wi/pvwYdistaSPzCUcKdvWv+EcYpibO06AMkXDuCPRifl09kHZ6m xqCI+OmafzOQYYsFNvTQts9/ZEEzK+CG6PQujQKpmx0uFs5jXeXaT3ZACkpTkCjuO3fn CkWTZVoJvBSQmwmJKhyz+8MNjTJ16lewyB5AMmj6BgXRqOcyI/P48lGGTEsQ+xSE+OHa vlaU5zLiS/qA04xh35vtN35MqYc+lWCr4yJ5qk3UIwyZFOoUU//BkY6BwSiSxMnNwdqJ Wbzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362597; x=1731967397; 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=MMs6VNiuxgnQW+UbhV/F8Zn0UTh3B4+3JvRh5MWpSdA=; b=INjA5/n8V2G3oclvOXxpmZBlUf3XL8xkYo8Do3eaBY8eXJn9w1/RAmkahEzX8A35RK wy2vT93gRI5gPFo3DzscJ+wEfcOgkvdtQUazaIM9/mmG7SfVT2SRQgOZcJj/9VEVFhgt j46RL0bM+XwULn99Rcd8Hb4Mm8864jUzih8Y6iDV3C5BfJDqV0GxoMNcUXgKEkH6E7gg HpUZC4It29FIqhS9gYJBk74RFuYoU0rUqazyYVEjvb8v/1ElQbkbXhLAwdgRMn118XHT LbAmD5GmJzwWGpSSQOarv03Xuywu7IZwyuOGNcCIM2KQCmY/YlWP+8dXhDAI9peqG7mo hjSw== X-Gm-Message-State: AOJu0YxygmO9C2hr6JMwyapbo///3jHany2jh+CNMKjl90fb7DzjVWof qpn3ghd36TfK2poGz0m5wJcSqdf4ebVeWFactduTntEpa8IXqPML5RKgilbMq7hwwWPluuQvs7f RojzCPjTD6uswj6WtrL70svwmZLVkskJ/BHBB3Q7+hd5dqKRn2Kym+jPeQdB3EHAiSbZDGUherY qtoPiPJSmoKbu/LEZVrAxbCCvUIAcXMkWwTLzNVzJ5sNBSFHb14qw= X-Google-Smtp-Source: AGHT+IG4LTQEWFuE1HYkEzRiG/uRZD4XmKkP52fy1WoJO/PLBlbfIMvS8l9LnqLPgdd+IQjnDhYnrg== X-Received: by 2002:a17:902:f705:b0:20c:61a2:5ca4 with SMTP id d9443c01a7336-21183c7d651mr187262625ad.10.1731362596796; Mon, 11 Nov 2024 14:03:16 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:16 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 10/11] lib: utils/serial: Use fdt_driver for initialization Date: Mon, 11 Nov 2024 14:02:54 -0800 Message-ID: <20241111220304.1228821-11-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-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-20241111_140317_692878_E1A098AE X-CRM114-Status: GOOD ( 18.39 ) 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 serial driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_serial_init() first attempts to match the chosen stdout device, and upon failure m [...] 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:629 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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 serial driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_serial_init() first attempts to match the chosen stdout device, and upon failure matches the first available serial device in the DT. It is a fatal error if no such device is found. This matches the behavior of fdt_driver_init_one(). Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- (no changes since v1) include/sbi_utils/serial/fdt_serial.h | 6 +-- lib/utils/serial/fdt_serial.c | 52 +++------------------ lib/utils/serial/fdt_serial_cadence.c | 2 +- lib/utils/serial/fdt_serial_drivers.carray | 2 +- lib/utils/serial/fdt_serial_gaisler.c | 2 +- lib/utils/serial/fdt_serial_htif.c | 2 +- lib/utils/serial/fdt_serial_litex.c | 2 +- lib/utils/serial/fdt_serial_renesas_scif.c | 2 +- lib/utils/serial/fdt_serial_shakti.c | 2 +- lib/utils/serial/fdt_serial_sifive.c | 2 +- lib/utils/serial/fdt_serial_uart8250.c | 2 +- lib/utils/serial/fdt_serial_xlnx_uartlite.c | 2 +- 12 files changed, 18 insertions(+), 60 deletions(-) diff --git a/include/sbi_utils/serial/fdt_serial.h b/include/sbi_utils/serial/fdt_serial.h index 572475c9..57776105 100644 --- a/include/sbi_utils/serial/fdt_serial.h +++ b/include/sbi_utils/serial/fdt_serial.h @@ -11,14 +11,10 @@ #define __FDT_SERIAL_H__ #include +#include #ifdef CONFIG_FDT_SERIAL -struct fdt_serial { - const struct fdt_match *match_table; - int (*init)(const void *fdt, int nodeoff, const struct fdt_match *match); -}; - int fdt_serial_init(const void *fdt); #else diff --git a/lib/utils/serial/fdt_serial.c b/lib/utils/serial/fdt_serial.c index a7129bdd..b0fa82bc 100644 --- a/lib/utils/serial/fdt_serial.c +++ b/lib/utils/serial/fdt_serial.c @@ -9,19 +9,16 @@ #include #include -#include #include #include /* List of FDT serial drivers generated at compile time */ -extern struct fdt_serial *const fdt_serial_drivers[]; +extern const struct fdt_driver *const fdt_serial_drivers[]; int fdt_serial_init(const void *fdt) { const void *prop; - struct fdt_serial *drv; - const struct fdt_match *match; - int pos, noff = -1, len, coff, rc; + int noff = -1, len, coff, rc; /* Find offset of node pointed to by stdout-path */ coff = fdt_path_offset(fdt, "/chosen"); @@ -38,50 +35,15 @@ int fdt_serial_init(const void *fdt) else noff = fdt_path_offset(fdt, prop); } - if (-1 < noff) { - if (!fdt_node_is_enabled(fdt, noff)) - noff = -1; - } } /* First check DT node pointed by stdout-path */ - for (pos = 0; fdt_serial_drivers[pos] && -1 < noff; pos++) { - drv = fdt_serial_drivers[pos]; - - match = fdt_match_node(fdt, noff, drv->match_table); - if (!match) - continue; - - /* drv->init must not be NULL */ - if (drv->init == NULL) - return SBI_EFAIL; - - rc = drv->init(fdt, noff, match); - if (rc == SBI_ENODEV) - continue; - return rc; - } - - /* Lastly check all DT nodes */ - for (pos = 0; fdt_serial_drivers[pos]; pos++) { - drv = fdt_serial_drivers[pos]; - - noff = -1; - while ((noff = fdt_find_match(fdt, noff, - drv->match_table, &match)) >= 0) { - if (!fdt_node_is_enabled(fdt, noff)) - continue; - - /* drv->init must not be NULL */ - if (drv->init == NULL) - return SBI_EFAIL; - - rc = drv->init(fdt, noff, match); - if (rc == SBI_ENODEV) - continue; + if (-1 < noff) { + rc = fdt_driver_init_by_offset(fdt, noff, fdt_serial_drivers); + if (rc != SBI_ENODEV) return rc; - } } - return SBI_ENODEV; + /* Lastly check all DT nodes */ + return fdt_driver_init_one(fdt, fdt_serial_drivers); } diff --git a/lib/utils/serial/fdt_serial_cadence.c b/lib/utils/serial/fdt_serial_cadence.c index ee7d7797..0a497a41 100644 --- a/lib/utils/serial/fdt_serial_cadence.c +++ b/lib/utils/serial/fdt_serial_cadence.c @@ -30,7 +30,7 @@ static const struct fdt_match serial_cadence_match[] = { { }, }; -struct fdt_serial fdt_serial_cadence = { +const struct fdt_driver fdt_serial_cadence = { .match_table = serial_cadence_match, .init = serial_cadence_init }; diff --git a/lib/utils/serial/fdt_serial_drivers.carray b/lib/utils/serial/fdt_serial_drivers.carray index 3517b2c8..4336f4e1 100644 --- a/lib/utils/serial/fdt_serial_drivers.carray +++ b/lib/utils/serial/fdt_serial_drivers.carray @@ -1,3 +1,3 @@ HEADER: sbi_utils/serial/fdt_serial.h -TYPE: struct fdt_serial +TYPE: const struct fdt_driver NAME: fdt_serial_drivers diff --git a/lib/utils/serial/fdt_serial_gaisler.c b/lib/utils/serial/fdt_serial_gaisler.c index cae1727d..bf2ee284 100644 --- a/lib/utils/serial/fdt_serial_gaisler.c +++ b/lib/utils/serial/fdt_serial_gaisler.c @@ -29,7 +29,7 @@ static const struct fdt_match serial_gaisler_match[] = { {}, }; -struct fdt_serial fdt_serial_gaisler = { +const struct fdt_driver fdt_serial_gaisler = { .match_table = serial_gaisler_match, .init = serial_gaisler_init }; diff --git a/lib/utils/serial/fdt_serial_htif.c b/lib/utils/serial/fdt_serial_htif.c index 43557f6c..b95caf1e 100644 --- a/lib/utils/serial/fdt_serial_htif.c +++ b/lib/utils/serial/fdt_serial_htif.c @@ -41,7 +41,7 @@ static int serial_htif_init(const void *fdt, int nodeoff, return htif_serial_init(custom, fromhost_addr, tohost_addr); } -struct fdt_serial fdt_serial_htif = { +const struct fdt_driver fdt_serial_htif = { .match_table = serial_htif_match, .init = serial_htif_init }; diff --git a/lib/utils/serial/fdt_serial_litex.c b/lib/utils/serial/fdt_serial_litex.c index 9aed719f..7c479119 100644 --- a/lib/utils/serial/fdt_serial_litex.c +++ b/lib/utils/serial/fdt_serial_litex.c @@ -33,7 +33,7 @@ static const struct fdt_match serial_litex_match[] = { { }, }; -struct fdt_serial fdt_serial_litex = { +const struct fdt_driver fdt_serial_litex = { .match_table = serial_litex_match, .init = serial_litex_init }; diff --git a/lib/utils/serial/fdt_serial_renesas_scif.c b/lib/utils/serial/fdt_serial_renesas_scif.c index 41356d1d..b42e1c45 100644 --- a/lib/utils/serial/fdt_serial_renesas_scif.c +++ b/lib/utils/serial/fdt_serial_renesas_scif.c @@ -25,7 +25,7 @@ static const struct fdt_match serial_renesas_scif_match[] = { { /* sentinel */ } }; -struct fdt_serial fdt_serial_renesas_scif = { +const struct fdt_driver fdt_serial_renesas_scif = { .match_table = serial_renesas_scif_match, .init = serial_renesas_scif_init }; diff --git a/lib/utils/serial/fdt_serial_shakti.c b/lib/utils/serial/fdt_serial_shakti.c index 2bafc99b..7a324643 100644 --- a/lib/utils/serial/fdt_serial_shakti.c +++ b/lib/utils/serial/fdt_serial_shakti.c @@ -27,7 +27,7 @@ static const struct fdt_match serial_shakti_match[] = { { }, }; -struct fdt_serial fdt_serial_shakti = { +const struct fdt_driver fdt_serial_shakti = { .match_table = serial_shakti_match, .init = serial_shakti_init }; diff --git a/lib/utils/serial/fdt_serial_sifive.c b/lib/utils/serial/fdt_serial_sifive.c index f551b78c..b1811ee9 100644 --- a/lib/utils/serial/fdt_serial_sifive.c +++ b/lib/utils/serial/fdt_serial_sifive.c @@ -30,7 +30,7 @@ static const struct fdt_match serial_sifive_match[] = { { }, }; -struct fdt_serial fdt_serial_sifive = { +const struct fdt_driver fdt_serial_sifive = { .match_table = serial_sifive_match, .init = serial_sifive_init }; diff --git a/lib/utils/serial/fdt_serial_uart8250.c b/lib/utils/serial/fdt_serial_uart8250.c index 10d201cc..af5ceac9 100644 --- a/lib/utils/serial/fdt_serial_uart8250.c +++ b/lib/utils/serial/fdt_serial_uart8250.c @@ -33,7 +33,7 @@ static const struct fdt_match serial_uart8250_match[] = { { }, }; -struct fdt_serial fdt_serial_uart8250 = { +const struct fdt_driver fdt_serial_uart8250 = { .match_table = serial_uart8250_match, .init = serial_uart8250_init, }; diff --git a/lib/utils/serial/fdt_serial_xlnx_uartlite.c b/lib/utils/serial/fdt_serial_xlnx_uartlite.c index 0a829ad2..78e3ffe4 100644 --- a/lib/utils/serial/fdt_serial_xlnx_uartlite.c +++ b/lib/utils/serial/fdt_serial_xlnx_uartlite.c @@ -29,7 +29,7 @@ static const struct fdt_match serial_xlnx_uartlite_match[] = { { }, }; -struct fdt_serial fdt_serial_xlnx_uartlite = { +const struct fdt_driver fdt_serial_xlnx_uartlite = { .match_table = serial_xlnx_uartlite_match, .init = serial_xlnx_uartlite_init, }; From patchwork Mon Nov 11 22:02:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009957 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=JWOCL1yA; 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=fyPxhs2b; 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 4XnQQZ0MtGz1xwF for ; Tue, 12 Nov 2024 10:16:03 +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=vWo2BCoPJ+9FCCH3Xhyw+s4FMJDXhv25gRjgIv8LCkA=; b=JWOCL1yA3VH1Bm WDrMYNH/bQe9FM5ncbtZ9YtB4Dn8NRBZfU5SDyBgDGwyLLcgxqcc+lPJMw8kT+irs7xcw1AA8kRjX hCcsh5Ou+ohsMwHKgwo4BoHbqb3HTradS50+ZAk3L4KY1jhlc7hwV7cgKIEf4JleEeRxS2vtSW/gc evV62xvr8mj3sZLn6jvPCUOru0ZJ58PX6OKYzMmyC3LMjvXDUo3ZDCAp43SPfI2f6s0wQcvPTaOk3 WoLowOTATW6PfyGKHSN21KD9IysX4NcGzLwykycD6pAO8nXp4FtfHc5dsNEpxHXd1wM43k5U4YK+C s1yvgDNC36AEBloA6Yxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAddR-00000001bW6-1ZQU; Mon, 11 Nov 2024 23:15:53 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcVC-00000001RRF-2ns9 for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:20 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-20ca1b6a80aso53323685ad.2 for ; Mon, 11 Nov 2024 14:03:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362598; x=1731967398; 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=NsiFJ42PWV57vYUrWi95rCFumJR7qYqXVIvFZunWplI=; b=fyPxhs2b8OrtKmtnxn7eJcEyR1knaMO0m2TnrsYedxIh3qd1Y8gwzWvcE0r5bxTIwO 7LMmoDV89h+AXU1Wz14FHiUSRxkeV4MPIAqNPmlXrPrbqaj4XYKgjbYtEZqkxaAprSCf 211V7H2h/8vTPowJE8T8HT6u7bJX51Ieoad8Pu2vmo8W3FEbx93u74/bspz+z0cMDMzh tIFVrzbco8rTPDePLBXEMvv99lVHIlULM3TNku5JPyUVb8wxsA808nymOckByXezMHxO MIxtcsZ3ZQkrejs0n1MrO/xm2LQtRxdhBB+uC7wrAPQzNeDV6TR7eJG1h4WuqBz9MJ4x Am0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362598; x=1731967398; 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=NsiFJ42PWV57vYUrWi95rCFumJR7qYqXVIvFZunWplI=; b=kmPUq7w4nEPYS8IsmFRGZz/q5p6Q6baj1OBcyrA0ZTakRK5k7xnoSGNpmqZ/LhkODG NyAzCRawMCJ//3uSlxjtOu51B1E2JREn+cSeEYBqt8OCy+0dD6dI97aat8YUhc/gj3l/ en5lTXfTHec9Bx1vzmBvlEdxBDxQZdudfDLpCzDxyzY5yTLzmCc9E8YUHq33oWWJcZ1A 4V/ljnjYQAVg+dqr1ZiF34pXnGBNdzb4KiShf1jLO4A1niOqz/rIN9H7NgUPzF4zBUfq Hstr24c9htyOQlOESbCfe4IluZmDKTZoykzUHM/5DIqZpyUG05r10YAr9mJWc5AecLqd LeAQ== X-Gm-Message-State: AOJu0YwrGFE3Q58ZBt6uiLBvhe24ihPS+uhCNlX4Jiwv47ZXD/t6EgLA E+CxYFg6Ps545CX27vzKKLCbvGGwxlbIaHWerCxrNh0QyIWnicBTuFT5yFVHxCX8sOOPuGLoVxW kaq4Au05zEA8UFT7LNsN3JC1XRqb7mX6hFIx/qKJKIAtPnIlc578y6CqkrWRnZgxGXSWoG2C72m jopMDVvW+zzVgYTfwh5gnB1hfNEYV+4cxKWAb1plOLOEcx/PVc260= X-Google-Smtp-Source: AGHT+IFpjZfS3VbYYM/ApVtuqPqdGDcc/v0GXvUyiwLTUfj3q9oQNcxH9WV/8Acy+QoO2LuytNu6zA== X-Received: by 2002:a17:902:ea12:b0:20c:c086:4998 with SMTP id d9443c01a7336-21183d7cd04mr159645645ad.55.1731362597799; Mon, 11 Nov 2024 14:03:17 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:17 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 11/11] lib: utils/timer: Use fdt_driver for initialization Date: Mon, 11 Nov 2024 14:02:55 -0800 Message-ID: <20241111220304.1228821-12-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-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-20241111_140318_816225_61978677 X-CRM114-Status: GOOD ( 16.97 ) 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 timer driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_timer_init() performs a best-effort initialization of all matching DT nodes. Signed-off-by: Samuel Holland --- 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:62a 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_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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 timer driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_timer_init() performs a best-effort initialization of all matching DT nodes. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- Changes in v2: - New patch for v2 include/sbi_utils/timer/fdt_timer.h | 6 +--- lib/utils/timer/fdt_timer.c | 39 +++--------------------- lib/utils/timer/fdt_timer_drivers.carray | 2 +- lib/utils/timer/fdt_timer_mtimer.c | 4 +-- lib/utils/timer/fdt_timer_plmt.c | 4 +-- 5 files changed, 10 insertions(+), 45 deletions(-) diff --git a/include/sbi_utils/timer/fdt_timer.h b/include/sbi_utils/timer/fdt_timer.h index 8f0469da..7bd2faf0 100644 --- a/include/sbi_utils/timer/fdt_timer.h +++ b/include/sbi_utils/timer/fdt_timer.h @@ -11,14 +11,10 @@ #define __FDT_TIMER_H__ #include +#include #ifdef CONFIG_FDT_TIMER -struct fdt_timer { - const struct fdt_match *match_table; - int (*cold_init)(const void *fdt, int nodeoff, const struct fdt_match *match); -}; - int fdt_timer_init(void); #else diff --git a/lib/utils/timer/fdt_timer.c b/lib/utils/timer/fdt_timer.c index a2412409..d00aa310 100644 --- a/lib/utils/timer/fdt_timer.c +++ b/lib/utils/timer/fdt_timer.c @@ -13,44 +13,13 @@ #include /* List of FDT timer drivers generated at compile time */ -extern struct fdt_timer *const fdt_timer_drivers[]; +extern const struct fdt_driver *const fdt_timer_drivers[]; int fdt_timer_init(void) { - int pos, noff, rc; - struct fdt_timer *drv; - const struct fdt_match *match; - const void *fdt = fdt_get_address(); - - for (pos = 0; fdt_timer_drivers[pos]; pos++) { - drv = fdt_timer_drivers[pos]; - - noff = -1; - while ((noff = fdt_find_match(fdt, noff, - drv->match_table, &match)) >= 0) { - if (!fdt_node_is_enabled(fdt, noff)) - continue; - - /* drv->cold_init must not be NULL */ - if (drv->cold_init == NULL) - return SBI_EFAIL; - - rc = drv->cold_init(fdt, noff, match); - if (rc == SBI_ENODEV) - continue; - if (rc) - return rc; - - /* - * We will have multiple timer devices on multi-die or - * multi-socket systems so we cannot break here. - */ - } - } - /* - * We can't fail here since systems with Sstc might not provide - * mtimer/clint DT node in the device tree. + * Systems with Sstc might not provide any node in the FDT, + * so do not return a failure if no device is found. */ - return 0; + return fdt_driver_init_all(fdt_get_address(), fdt_timer_drivers); } diff --git a/lib/utils/timer/fdt_timer_drivers.carray b/lib/utils/timer/fdt_timer_drivers.carray index c62ee733..1dd9fb1a 100644 --- a/lib/utils/timer/fdt_timer_drivers.carray +++ b/lib/utils/timer/fdt_timer_drivers.carray @@ -1,3 +1,3 @@ HEADER: sbi_utils/timer/fdt_timer.h -TYPE: struct fdt_timer +TYPE: const struct fdt_driver NAME: fdt_timer_drivers diff --git a/lib/utils/timer/fdt_timer_mtimer.c b/lib/utils/timer/fdt_timer_mtimer.c index e752ddc5..224534d8 100644 --- a/lib/utils/timer/fdt_timer_mtimer.c +++ b/lib/utils/timer/fdt_timer_mtimer.c @@ -162,7 +162,7 @@ static const struct fdt_match timer_mtimer_match[] = { { }, }; -struct fdt_timer fdt_timer_mtimer = { +const struct fdt_driver fdt_timer_mtimer = { .match_table = timer_mtimer_match, - .cold_init = timer_mtimer_cold_init, + .init = timer_mtimer_cold_init, }; diff --git a/lib/utils/timer/fdt_timer_plmt.c b/lib/utils/timer/fdt_timer_plmt.c index 459a1190..1e146689 100644 --- a/lib/utils/timer/fdt_timer_plmt.c +++ b/lib/utils/timer/fdt_timer_plmt.c @@ -43,7 +43,7 @@ static const struct fdt_match timer_plmt_match[] = { {}, }; -struct fdt_timer fdt_timer_plmt = { +const struct fdt_driver fdt_timer_plmt = { .match_table = timer_plmt_match, - .cold_init = fdt_plmt_cold_timer_init, + .init = fdt_plmt_cold_timer_init, };