From patchwork Tue Nov 5 04:20:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2006641 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=a0ZLpMpt; 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=g5NGFjun; 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 4XjFYp73bnz1xyM for ; Tue, 5 Nov 2024 15:22:54 +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=YCuzdeLJMUg1FgXjX9lkzXN/G/tvAmzO8LmX8Bp/CIE=; b=a0ZLpMptEr3e1W Cgm2REiyY6v3qztF1Qb83OQGZtJO0o1P063eKevOo3nb/HMovegc+nYiOVSEw2LzLlW86MpEciMlY KR20ia2u3p0wq4cgPcbcvLdlHfPLPsSQ4ylcMDJzvOelOTkM5BRua83aQ0LtwtxmerifOGLbtvmoz CXYExM8xQdlHJA7LfXxOEi+b1NgHbxYNkfYNwBLBzJJvXAiSuXTrr712mR40Wx5pBrYlG9DOIzXqq vpOLSGWFF38TFHiAhsenUZjljc2MyWGDKh54Z3YzzZR1aiHJPBTZs6W9YDjeb3ywV8C5vcz2jBO92 l8z+NTp65a7ylcO6msow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5a-0000000FrKX-3tRA; Tue, 05 Nov 2024 04:22:46 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5X-0000000FrJ9-2Hqc for opensbi@lists.infradead.org; Tue, 05 Nov 2024 04:22:45 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-720be27db27so3994833b3a.2 for ; Mon, 04 Nov 2024 20:22:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1730780563; x=1731385363; 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=PcCch4rmSsYOFwhO35T3y3S2p3vD5etykxg5cC9boXI=; b=g5NGFjunBEqTV1/SwnuopyEjrj5x3TU/2WCxlMdtYu6P//dsx5Jr/rXgIuA//cITD2 KbZAtNPIR4KB9zqtVj52MlmHOMxh9zsiDBAqdKt45bXrVhrh/RxRyhozydxz0CrAcQ0I WUeY/1NgvYybq/PzYGbf0g6WnSVqDSSwOwDs33hjdJZm4G4dCgr6JVqA7xXSgGSVWyX+ lSjR9drdnF616t8z0N/+Dofl9gk9OOLLD7tJgq0Z2QpERogtCL+NPJtVCN5sqchbqT6L 2P07CWVWqBopYVKKY8iKHRE3Ih1Fq2e8yPcbfMX6KeX3PSxgO1a5pu0/WjzGd2YC4Dyf QOmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730780563; x=1731385363; 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=PcCch4rmSsYOFwhO35T3y3S2p3vD5etykxg5cC9boXI=; b=pVq04VM4LqahJwXqB1JK35ut3iVRwt8P/UbKBxlT6SwO+wuPwwmhicRlG62ngBKm3b VfvmM3rMNpbASfFgDPbcvbsvfXh/IjW80i6MN8H/0m57L0Xz9n2DS63R/s3IZvBhbjdg i3l2qd14hMrnF/7Y8u3bcdtnMKUGeinImhKtAGudZ/d4oYbGuFve/2CpaA/cJrQaYcm5 mZLBs+dCL65F//X3XRxDMfSm6GsqVx16SaAqyC7zFqLED9S9nOJtGZuOADkwuUWwkmUE 44IAr49WmZ3cS6xT9gRrHT7EY/DwZTUPSsJFwimOqYgnwR1QGTcf/ef+LMW6pzqW0s7+ YqiQ== X-Gm-Message-State: AOJu0YwXgWNVneLQBSfZyJeWD24RvagqfGUI96khybqRpnRwUaME4beZ Ohpu/tx27VPnzjsZcus1V1KNCPP6fgMl/+pco3gZlOKK9LIpcVxDuPSuwnA8HcSURnhUTLl2y/D hN/xxv6ajUWqCKDGpwfsKG3ZBKkMw4lMfKosSAvjluu9Dbuox95EPtvhhrSqgCmM6kjuYZBnnYh p6pvTp9I3qrDyyKBq3zhC4O9xg7dEt5Zx2D3OCrUNpD9Ed4L3jrwY= X-Google-Smtp-Source: AGHT+IENYoFwo4xe20YmUoZwzCTnQZB+UqlTw5UmsTLLHQPgSS+u/kx+bVhrwQs3AJ4E1hw7Vtta3A== X-Received: by 2002:a05:6a20:158a:b0:1db:e82e:c802 with SMTP id adf61e73a8af0-1dbe82ec89emr4291692637.41.1730780562565; Mon, 04 Nov 2024 20:22:42 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1e5a64sm8493782b3a.65.2024.11.04.20.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 20:22:42 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH 1/6] lib: utils/gpio: Remove fdt_gpio_driver() function Date: Mon, 4 Nov 2024 20:20:03 -0800 Message-ID: <20241105042240.2994849-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241105042240.2994849-1-samuel.holland@sifive.com> References: <20241105042240.2994849-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_202243_603672_2AE454D0 X-CRM114-Status: GOOD ( 10.02 ) 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 function looks up a chip's driver by matching known drivers against chip->driver, but that is equivalent to using chip->driver directly. 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:431 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This function looks up a chip's driver by matching known drivers against chip->driver, but that is equivalent to using chip->driver directly. Signed-off-by: Samuel Holland --- lib/utils/gpio/fdt_gpio.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/lib/utils/gpio/fdt_gpio.c b/lib/utils/gpio/fdt_gpio.c index d8d847f1..6422c45f 100644 --- a/lib/utils/gpio/fdt_gpio.c +++ b/lib/utils/gpio/fdt_gpio.c @@ -16,21 +16,6 @@ extern struct fdt_gpio *fdt_gpio_drivers[]; extern unsigned long fdt_gpio_drivers_size; -static struct fdt_gpio *fdt_gpio_driver(struct gpio_chip *chip) -{ - int pos; - - if (!chip) - return NULL; - - for (pos = 0; pos < fdt_gpio_drivers_size; pos++) { - if (chip->driver == fdt_gpio_drivers[pos]) - return fdt_gpio_drivers[pos]; - } - - return NULL; -} - static int fdt_gpio_init(const void *fdt, u32 phandle) { int pos, nodeoff, rc; @@ -112,7 +97,7 @@ int fdt_gpio_pin_get(const void *fdt, int nodeoff, int index, if (rc) return rc; - drv = fdt_gpio_driver(chip); + drv = chip->driver; if (!drv || !drv->xlate) return SBI_ENOSYS; From patchwork Tue Nov 5 04:20:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2006642 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=WYhzyKjp; 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=JtTh90Pr; 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 4XjFYq521tz1xyP for ; Tue, 5 Nov 2024 15:22:55 +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=jTaLkbeCpMqZbJVKOFKEu0PB5azK05IseOJ6BSESRk8=; b=WYhzyKjpV3cpFK 3BY3e10pyrf6uJ3oxnQgkjRgc+APkZvxp37y4AxgqOkYbV/CMhqOWrCJuIwKzAHplCtbEdR0QQa+x mNTMdSSUJnNiFGKksUajh8tOQEtjAPeqXTYCX9DHXLrPZeemsG/RwTp+tuI7lbPHLPOrm9AW8zp+Q y6deOPEV991T77DE/Pu2Cn9MMYmFW28j+jz1YiM0xV1cVFCMgFm7IDNCL98iQ3vE7zBdHK3Fni0Gh RIfmvoGJacX0Yhtz2sW+qVFWQWoGPTD9BslCU77OU874vcyyRcVcUbOhbYRMWeXQCAGRxHvW0kk4f VIdOn45RQGdJA83Btv7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5c-0000000FrLS-2HZ6; Tue, 05 Nov 2024 04:22:48 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5Y-0000000FrJY-49h6 for opensbi@lists.infradead.org; Tue, 05 Nov 2024 04:22:46 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-72061bfec2dso4652208b3a.2 for ; Mon, 04 Nov 2024 20:22:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1730780564; x=1731385364; 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=uMiN2l60v0o8JXQzbYGhcAXRYM9fjboxDAlUXXyVBxM=; b=JtTh90Pr/b5A0l3ifEYQFFMtVxAizbXZhXxoVlGQIy9mK9Y7gcQDtaB2S6SLeygcSG fR4on+rb/kQBvRazq1Y/2ulljV3vmeRnACHM7jh2sOz10/yrnElT5+Tdj4qtzygprHGK n1E30uf2tw4BbIdHUDYf2GvVcDAXZFBNK8jo98wgBAG99uYhH9YWM0qUr4X+sOlhd9bb FkTIUnCXdtdCbI+VIq0b8FEgheYCjunfX4G1F1xf0B/58bLuRAXcOtxU7EXlwyB7Td4M ZS/RJsNm5EJZbe+TdVvPRkFh2V0myWDNbFd1EqQrKJmq3aVSc6VUSQ+JOSoKPBdBffUj Et0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730780564; x=1731385364; 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=uMiN2l60v0o8JXQzbYGhcAXRYM9fjboxDAlUXXyVBxM=; b=ZtOgVp2UjKGZek7VSweUCuznCF/8sawcJ2bYFxvTwRDV0b1yzY1Qeh8JdrCa3Vb3UE dUUjzvLXGEkpKQyE5nEpI5nazuy8T7ijZnOV4JaJcUwg7Bj8y9M4HTjHo0maJnLQ4ZpR lXC/QpI1fpsIRlJf3Ve4zXr/e8/KjkjlfSOyL1WrpuhJqL5YLNWVnNFKlHDlc31e2Jx8 ILJFD64jIDwJKge3CLPdOsMI8J5H9fV3IgU+1DfhEBeQRvI59V+JMlqbx/1agGk6uCoj GSbzoUi0uHyTIeDxv8ZeFxT8zrBRw4sgS7hmhg/3Q6SzsbcChVT3E5kRKVcJRSMfwv3v MdYw== X-Gm-Message-State: AOJu0YxEVLqoVRuR1Z7enT1wltIt4Snu5tmV9BoXiHkOntscTpUXSLus gvKaS9lFcnki77DzVQiIspHciB3Z9tUGZlKsAhbCVmo51+2kjlBPY29kRerJVM5V97qIjCmpvTe PhHtur/90lJIx2qBJPlXJMtJ+JLeHo2rVex6zgdQjWjmDE1BCMOeeVEjagHctLDo2m3pbr9FJZ7 wpDhW5K6UIXohW3kRZR2e0PrOPmgmWFiS354hUgpr6AEBCY8WuXIo= X-Google-Smtp-Source: AGHT+IHT0VzaCg/76i7vJHL5Qhnz9is6qtmro2kWPKWauJADJYV2IE94mOkHBFhukRxbs2KxxoYW/A== X-Received: by 2002:a05:6a00:2e15:b0:71d:eb7d:20e4 with SMTP id d2e1a72fcca58-720c98d0527mr22083245b3a.8.1730780563767; Mon, 04 Nov 2024 20:22:43 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1e5a64sm8493782b3a.65.2024.11.04.20.22.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 20:22:43 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH 2/6] treewide: Make carray arrays const and NULL-terminated Date: Mon, 4 Nov 2024 20:20:04 -0800 Message-ID: <20241105042240.2994849-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241105042240.2994849-1-samuel.holland@sifive.com> References: <20241105042240.2994849-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_202245_057663_B35FA120 X-CRM114-Status: GOOD ( 14.51 ) 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 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:429 listed in] [list.dnswl.org] 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 --- 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 6422c45f..3c8514b1 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, u32 phandle) { @@ -32,7 +31,7 @@ static int fdt_gpio_init(const void *fdt, u32 phandle) 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 959cf57d..eb493ed9 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[]; static struct fdt_ipi *current_driver = NULL; @@ -38,7 +37,7 @@ static int fdt_ipi_cold_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 f02d2f07..8348b9d2 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, u32 phandle) { @@ -23,7 +22,7 @@ static int fdt_regmap_init(const void *fdt, int nodeoff, u32 phandle) 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 aa0494e4..5505bd31 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[]; static struct fdt_timer *current_driver = NULL; @@ -38,7 +37,7 @@ static int fdt_timer_cold_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 49d877d0..d5dbca69 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 Tue Nov 5 04:20:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2006644 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=tJ6kICG0; 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=FiSoBwxK; 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 4XjFYs08Ghz1xyQ for ; Tue, 5 Nov 2024 15:22:57 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8iKCRCzUyhOgORd4sFB6vwfCBHDF+RbTJgxiLgKcJNY=; b=tJ6kICG0LmAyZ9 wjJcCi744qz3YegA8UOthZFNSVlvxoOGfVaMPPVMCZENMaIuXTT626kU46Q3d6JHmRSfY+BN+rpdw PjjifFp33cV1TQZ5zh1dpbtaJhriUId8u7ryPl9NzcrCZwYjDvoX/dx9OgFaZ+cuLzHinf0tlbNzP IEZSI8QwOxM45QiauCOjF7dTYPFH6fZ653CFwhRHZkFs4dAM9tKchW9QuYfbfdhRBDvW5Z2+pDdRz pKsxJazBNKEoplq++4LFy6IZAvd2d+6Q/ePQ1KSqjatgIYa1ieetZ3s7oL+lkwwJE+nYvmfdK0uce 0ss4jVPqE3ueMzamTSfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5d-0000000FrLv-0QIl; Tue, 05 Nov 2024 04:22:49 +0000 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5a-0000000FrK1-091y for opensbi@lists.infradead.org; Tue, 05 Nov 2024 04:22:47 +0000 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-7ee7e87f6e4so1567368a12.2 for ; Mon, 04 Nov 2024 20:22:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1730780565; x=1731385365; 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=4h/bqKJSy3g44McmouCotb7ljfWGIQj6iUtPS3wAB+0=; b=FiSoBwxK/eXCQK70NXMNX+SFBZE5/0QXK2KgegOcCPgFORpMVgHF3wOwhwr9/jx2y5 h/Xd/ymrXbZtzB3VG8trf31PpfxBnsECnnur5f0mzX5d9jKrx4zLzOQM/GTaLpAyZNZE fyUOtT5FVTSjxI40MEjNhG/oDTCN4j6WZQ2AuUMHCcupSGipWE+cRsvZpueqNnO2QRVx zE62iWd3JHLlx1ESWOefwRXqaflJyuACyXEAMxYDbiQsEKuOn2IU7AYfX397uddqv5/F unLfesCCwYl/1quqieK67ivpQUr4u7U9YTQ1cSKEYAq+JSlprfmx7bC6S3G4FqH8vKt2 kl0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730780565; x=1731385365; 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=4h/bqKJSy3g44McmouCotb7ljfWGIQj6iUtPS3wAB+0=; b=mhivjSVNgphXU5kqwJ8SyVDnfXj5tx81YItZM8rSyY78fW9k1Ui4nQv88P06m9vbGv t+FZSAFVDvZ8NxK98yj7NJYYV5aD0rxV509GIPAxqRj6m93y1GrChGzQJ5VEJ/zz+0J9 onMdweILBYOs+897swgg8+wwkWgpMsCfXyxzIHBFtXW6AO/Ug1nGQE/o5swLKYUBHm9Z FcvnALxVmdTfIBscTuamAPT9wXBrIWqyBajt72nw64dDKNY66joETEoju5WWKk2FVI5l WFuEt4RK6dmbJwCsrWthM/VrJMAzQ5OsghOddG5k+dH+dvSNnVJSkZ2PfWsRxV81By2g vffg== X-Gm-Message-State: AOJu0YyZWYQX72ymfsqBQneF0LshSir5rhyaUvhiZnYt6xoC648BL2Fc RL774XabDZ5CxRf108qo7XXLdA4Weqy2LCGLpOPfExZvK+J8bXm0OqZggYQO8tW0cU+ic+ILu/p prHFNs6GeEIEOlnA1AQceFtaIq8uzyhYDIahnJ9Z64s8Hz2zGZKm60hRUj2/kteqbnRie+eyq5u kBPoW5vFWO8LWF/PjMdAjx9LEgjFB8wj5AJ/K1tzXHHNYRhAp5/1A= X-Google-Smtp-Source: AGHT+IEPfJvgS+64ho6KAgyfW+j6X+IgNX30VIzMyGCtyZQNDs1g8kzEnui0HAY0yIRQYCUavXaoLg== X-Received: by 2002:a05:6a21:99a8:b0:1db:eead:c588 with SMTP id adf61e73a8af0-1dbeeadc5d0mr2860643637.29.1730780564794; Mon, 04 Nov 2024 20:22:44 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1e5a64sm8493782b3a.65.2024.11.04.20.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 20:22:44 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH 3/6] lib: utils/fdt: Add helpers for generic driver initialization Date: Mon, 4 Nov 2024 20:20:05 -0800 Message-ID: <20241105042240.2994849-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241105042240.2994849-1-samuel.holland@sifive.com> References: <20241105042240.2994849-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_202246_097687_F01CB09A X-CRM114-Status: GOOD ( 22.69 ) 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:52c listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 --- 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 Tue Nov 5 04:20:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2006643 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=qlF9xyhh; 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=dXJ05twd; 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 4XjFYr5Jc8z1xyM for ; Tue, 5 Nov 2024 15:22:56 +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=zAuV8bNKynwPZTLL5SiHq/vfGNfIFTME4sW99ar73aU=; b=qlF9xyhhSlUNO1 SijOhSNmmKu62zIA9Uvc5qowa9GtscBoH+7/7Ovl6o+2zkmyXlROqqj46cpqShlbzL+EZ5Ql4iQPS rfE7fbeykm/FgP/2yPArdi/vwwnsyEAPyaVL7bqzcMMLHnvnnOU1+hUrNe6ZidJov6RYKfLxUo1j2 DY+M84PzDPJuKG+9ySmeEWEAkvMlM0ArAc1CYVf/tntv3r9BEqSH69Q9lghEPgMyTVnbx8DSlOCsw 9hGWxr5RZM/XTVlx9xRlG6w49lQm+lKmL94AVAuU02hjjUSPPTjddRX31GcssJocGcSURSAkbMxoJ l/Y30KfJ2o840jgSrbrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5d-0000000FrMd-3lEQ; Tue, 05 Nov 2024 04:22:49 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5a-0000000FrKU-46J9 for opensbi@lists.infradead.org; Tue, 05 Nov 2024 04:22:48 +0000 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-7ee4c57b037so3077887a12.0 for ; Mon, 04 Nov 2024 20:22:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1730780566; x=1731385366; 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=tbj8EwG59EjPXSHJzzL3u+e8Hw0cugK2lfOpQ0lQzvM=; b=dXJ05twd4Pl9tI3Asdv7xM6b9gw6A8D79IsqIBBPHY/qkfKTq0a+wHzSBc8cMdAaGC tNHN556OFmX8IAmaX9dBn7Wpx8+ggvE/eNKHpnE3rbEZ+PO0T8qCdHn5OMT9RIb7sVsX i5z6XDffAX5i5yWpDBgQUxEfVAmb0yMfgSJauup/Y1vjSCVVP3I/mQib2OTGQw8kfH6E k3zWqm1DN0GutiQ2cQ4Dk9Tt2Wfv7hF1Zrg1GwmHAJfgNVRWnukDHguTPVTVCgnIp/M5 t+X22KlK8kU7ts/UzDpYtvrDn5fRNJeiAunAUMOIRa+EtS7yBoqROQTum+EMi0YXT82E q2SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730780566; x=1731385366; 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=tbj8EwG59EjPXSHJzzL3u+e8Hw0cugK2lfOpQ0lQzvM=; b=eoni3MXK0ACZ7dlNllnJeDTHRf8OtfnbdNKXnMEHSu9Tvkq+Lf281S/80O1pJ1NUQy 28ulxGqN6ibxD7cXnrhXiJ/dlE16ZaYvlRcBb7CF5a5YfYWXrszfJCcJUqggZAO8ZRKr y/swVVXJQtP3wGe3e4dFVpc5bCtw7NmIv9ru2BoH3vfT7GRXF4qW+VBtlrIs7HXsQ8g/ lfbegB1HvB0NeAEGABn3/pvV8qs8ONCVLPoVZaGOS6G7r5lsTn3/pwt2SWWq8ks+UaHG 3Fo0nslJkQGS9MLoPHxhPbo6P5/jDz2XfENK/iGLFcizPwRxVnLM5dOvgSm3Rd3x4wmw joqw== X-Gm-Message-State: AOJu0YzPOg0HG8i6HFR42cAomM8lcZLu7xw+0cYhCzfl8oWEQZ9UGk7K e2lm95UQcQsGzV0eqODFEG5MHHc/HFZxiWw1E956FznJ1sXgaW5g/+pPRkxM9Ht6GKSxe8JoGlQ BmGCTBEAp7x7d2Y6+J9lvOU0nK5vbEDUSR6YW5xA6nUzevgyQSX3BrFQzYBVFdJB3yCekwl1UJo f7x/pMEH0SaOLVu/E1fDOF1H7l49pZOwWRE0NUEIACHDaC8nTC+hM= X-Google-Smtp-Source: AGHT+IFfoHNwDWm/+LAGtsSf9x5wR5GbOZ+y3G/aCTLGw6KWyWMVaxnqRDqSagsWyo3oiXMm0Slqxg== X-Received: by 2002:a05:6a20:6a0e:b0:1db:ec2b:7322 with SMTP id adf61e73a8af0-1dbec2b7a6fmr3886098637.46.1730780565810; Mon, 04 Nov 2024 20:22:45 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1e5a64sm8493782b3a.65.2024.11.04.20.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 20:22:45 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH 4/6] lib: utils/i2c: Use fdt_driver for initialization Date: Mon, 4 Nov 2024 20:20:06 -0800 Message-ID: <20241105042240.2994849-5-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241105042240.2994849-1-samuel.holland@sifive.com> References: <20241105042240.2994849-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_202247_061632_3059C9B2 X-CRM114-Status: GOOD ( 14.06 ) 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:534 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The 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 --- 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 Tue Nov 5 04:20:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2006645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=kjjgyy5a; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=kwbd+XjS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XjFYs5NJ7z1xyP for ; Tue, 5 Nov 2024 15:22:57 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yR9z0eGpwYJG4pvUYKBlrggSfylwB/akXqxspdEMTp4=; b=kjjgyy5a3/sZ6p qCza80vCy8jeHzGFa+mwKEEak3NQKJdtCBk3wjSQxzTX8yIUEmbWjesOekpcFEOMbEnuhbpyT3aF1 arhkNUj0GVMpt2UZpx4z7Kf89PTpkDFhWs2rx/HMmtaoOJhtfwRMAUp301nc5tVkjT31dfkE0Mw5M SCG8oKOYleE7KNKOOfqoJEHWPgsxuK08rdG28F0fwLN9gcEmPdicYaYTjTjzv5JC6YOgJig2B1P8g FGN5us9/3I7EXZCxJ6Aebn0girpF/DQ9+51x0g6HsNYZvmFyFAHO3Vnsp0NIxqefdbYjL36nZIJyk Gw3uWlae0NlzyJBlb8oA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5e-0000000FrMz-2IVc; Tue, 05 Nov 2024 04:22:50 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5c-0000000FrL7-14yQ for opensbi@lists.infradead.org; Tue, 05 Nov 2024 04:22:49 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-72061bfec2dso4652237b3a.2 for ; Mon, 04 Nov 2024 20:22:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1730780567; x=1731385367; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SMLk6iYksNR2WYmbXDFlh0zloEGx4d8FIX735SxoX4g=; b=kwbd+XjSqpIi1q4e14imuiuRFJ24RzfPBzHH3lnn/E853cZnTRd5BO0HfNgk5HG/5k cZzQx8Lp23f8QMr+BumKWQL7KvC5q0eiLAFmnGWNI57ZAeldLI+o0LQmrvfipBEzuULI GMFfotBpXCoYMNwj3197SpLUc4CJkBhS4mdSj9i+9L5GVYbspcJSykX1QWCFe9HdR6Qj WJsrN2IDo3NUj30lAqUJedV63U5CA+bWE3gy/4fwR1N9X0t4rcf9YM0dMNS+b5+CbbsQ x+e+spo9ZbdF8ze7DA1Nnm2Lq0ayFJ4ej2tE59LCffTWOLgzgBneDDRPKgLNiXdBy0IJ ALNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730780567; x=1731385367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SMLk6iYksNR2WYmbXDFlh0zloEGx4d8FIX735SxoX4g=; b=cuhcimFjlsV+0Y6lX1sVAuKHIAzOZ5LzC6jCL3J9L6ylOVuep64DgZX9HOKnKb+avt GO9mDjaee3XQ0zwiVaDndQkdnpEn5b+wHOBhi4/qQ1psPbtQc0tFdQL2/AFiO3xGc6gs Wj6Bl2sOfzAPVQIEPAcEI+hdy6Q8y4SsoE5E7ROBOs6VadRyVU8i2MbRnDi9btzACWDi ZqjdPHlKO/iFofr2LcqQGh4ZDaYAjBSiO8ZvYH8Rcan0Sf/kOxIxfJSuTTl5Ei0aL/zJ rLEn9El7yVVEWWBjGyDJoClSx49mTEjVmDUx9N/eunZZSItzKDlfeF6iIHTGdZJRfZEW /Z+g== X-Gm-Message-State: AOJu0YxOZFgQVCAm6buCkIQgH7SWT6olq2GWS2wKnrtGbbyzg33kLMRB 7WE4GViYManxmM0IiStvXGJ33lMMzH+rS0Ip/TkyLI7BpFJyKV5TZ/VKp3wGoKOrHZB3EHx4Y+t eD+hNX/fkEUg/N9j0BPa7eK3KTXUvmjChgRp1TqX5qnqgv0KtjTwxT/RoY4U6G63CgaEvjPSq5+ vhtSEc+T9lgMV1IfjOvTEiQc+/NCBvdE9f4P0qTpiXHWAZ7xBGNek= X-Google-Smtp-Source: AGHT+IFr3s/DfTZZRs03qGC2mAFN9JoGET2mJl0Wd+127faTIBVMktuY2EkoAdZJEhJhpLW/Aj9raQ== X-Received: by 2002:a05:6a20:7f98:b0:1db:ebbf:4b8a with SMTP id adf61e73a8af0-1dbebbf4bdcmr4586877637.7.1730780567127; Mon, 04 Nov 2024 20:22:47 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1e5a64sm8493782b3a.65.2024.11.04.20.22.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 20:22:46 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH 5/6] lib: utils/reset: Use fdt_driver for initialization Date: Mon, 4 Nov 2024 20:20:07 -0800 Message-ID: <20241105042240.2994849-6-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241105042240.2994849-1-samuel.holland@sifive.com> References: <20241105042240.2994849-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_202248_331724_C266DA67 X-CRM114-Status: GOOD ( 16.71 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The reset driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_reset_init() performs a best-effort initialization of all matching DT nodes. Platfo [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42c listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The reset driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_reset_init() performs a best-effort initialization of all matching DT nodes. Platform-specific logic expects exactly one DT node to match a single driver. This is accomplished by using fdt_driver_init_one() with a local list containing that one driver. Signed-off-by: Samuel Holland --- include/sbi_utils/reset/fdt_reset.h | 15 +------- lib/utils/reset/fdt_reset.c | 36 ++------------------ lib/utils/reset/fdt_reset_atcwdt200.c | 2 +- lib/utils/reset/fdt_reset_drivers.carray | 2 +- lib/utils/reset/fdt_reset_gpio.c | 4 +-- lib/utils/reset/fdt_reset_htif.c | 2 +- lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c | 2 +- lib/utils/reset/fdt_reset_sunxi_wdt.c | 2 +- lib/utils/reset/fdt_reset_syscon.c | 4 +-- platform/generic/sifive/fu740.c | 9 +++-- platform/generic/starfive/jh7110.c | 9 +++-- 11 files changed, 26 insertions(+), 61 deletions(-) diff --git a/include/sbi_utils/reset/fdt_reset.h b/include/sbi_utils/reset/fdt_reset.h index f126fd33..5fba3886 100644 --- a/include/sbi_utils/reset/fdt_reset.h +++ b/include/sbi_utils/reset/fdt_reset.h @@ -11,19 +11,10 @@ #define __FDT_RESET_H__ #include - -struct fdt_reset { - const struct fdt_match *match_table; - int (*init)(const void *fdt, int nodeoff, const struct fdt_match *match); -}; +#include #ifdef CONFIG_FDT_RESET -/** - * fdt_reset_driver_init() - initialize reset driver based on the device-tree - */ -int fdt_reset_driver_init(const void *fdt, struct fdt_reset *drv); - /** * fdt_reset_init() - initialize reset drivers based on the device-tree * @@ -33,10 +24,6 @@ void fdt_reset_init(const void *fdt); #else -static inline int fdt_reset_driver_init(const void *fdt, struct fdt_reset *drv) -{ - return 0; -} static inline void fdt_reset_init(const void *fdt) { } #endif diff --git a/lib/utils/reset/fdt_reset.c b/lib/utils/reset/fdt_reset.c index 4b20c3e3..633a25cd 100644 --- a/lib/utils/reset/fdt_reset.c +++ b/lib/utils/reset/fdt_reset.c @@ -7,44 +7,12 @@ * Anup Patel */ -#include -#include -#include -#include #include /* List of FDT reset drivers generated at compile time */ -extern struct fdt_reset *const fdt_reset_drivers[]; - -int fdt_reset_driver_init(const void *fdt, struct fdt_reset *drv) -{ - int noff, rc, cnt = 0; - const struct fdt_match *match; - - noff = -1; - while ((noff = fdt_find_match(fdt, noff, - drv->match_table, &match)) >= 0) { - if (!fdt_node_is_enabled(fdt, noff)) - continue; - - if (drv->init) { - rc = drv->init(fdt, noff, match); - if (!rc) - cnt++; - else if (rc != SBI_ENODEV) { - sbi_printf("%s: %s init failed, %d\n", - __func__, match->compatible, rc); - } - } - } - - return cnt > 0 ? 0 : SBI_ENODEV; -} +extern const struct fdt_driver *const fdt_reset_drivers[]; void fdt_reset_init(const void *fdt) { - int pos; - - for (pos = 0; fdt_reset_drivers[pos]; pos++) - fdt_reset_driver_init(fdt, fdt_reset_drivers[pos]); + fdt_driver_init_all(fdt, fdt_reset_drivers); } diff --git a/lib/utils/reset/fdt_reset_atcwdt200.c b/lib/utils/reset/fdt_reset_atcwdt200.c index 6ef3b134..d3e38e61 100644 --- a/lib/utils/reset/fdt_reset_atcwdt200.c +++ b/lib/utils/reset/fdt_reset_atcwdt200.c @@ -111,7 +111,7 @@ static const struct fdt_match atcwdt200_reset_match[] = { {}, }; -struct fdt_reset fdt_reset_atcwdt200 = { +const struct fdt_driver fdt_reset_atcwdt200 = { .match_table = atcwdt200_reset_match, .init = atcwdt200_reset_init, }; diff --git a/lib/utils/reset/fdt_reset_drivers.carray b/lib/utils/reset/fdt_reset_drivers.carray index 6ff799cc..2e9e86af 100644 --- a/lib/utils/reset/fdt_reset_drivers.carray +++ b/lib/utils/reset/fdt_reset_drivers.carray @@ -1,3 +1,3 @@ HEADER: sbi_utils/reset/fdt_reset.h -TYPE: struct fdt_reset +TYPE: const struct fdt_driver NAME: fdt_reset_drivers diff --git a/lib/utils/reset/fdt_reset_gpio.c b/lib/utils/reset/fdt_reset_gpio.c index de81e2eb..cf751254 100644 --- a/lib/utils/reset/fdt_reset_gpio.c +++ b/lib/utils/reset/fdt_reset_gpio.c @@ -153,7 +153,7 @@ static const struct fdt_match gpio_poweroff_match[] = { { }, }; -struct fdt_reset fdt_poweroff_gpio = { +const struct fdt_driver fdt_poweroff_gpio = { .match_table = gpio_poweroff_match, .init = gpio_reset_init, }; @@ -163,7 +163,7 @@ static const struct fdt_match gpio_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_gpio = { +const struct fdt_driver fdt_reset_gpio = { .match_table = gpio_reset_match, .init = gpio_reset_init, }; diff --git a/lib/utils/reset/fdt_reset_htif.c b/lib/utils/reset/fdt_reset_htif.c index 7c04c81c..61c907fa 100644 --- a/lib/utils/reset/fdt_reset_htif.c +++ b/lib/utils/reset/fdt_reset_htif.c @@ -32,7 +32,7 @@ static const struct fdt_match htif_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_htif = { +const struct fdt_driver fdt_reset_htif = { .match_table = htif_reset_match, .init = htif_reset_init }; diff --git a/lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c b/lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c index 368cd108..66826830 100644 --- a/lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c +++ b/lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c @@ -108,7 +108,7 @@ static const struct fdt_match sg2042_mcu_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_sg2042_mcu = { +const struct fdt_driver fdt_reset_sg2042_mcu = { .match_table = sg2042_mcu_reset_match, .init = sg2042_mcu_reset_init, }; diff --git a/lib/utils/reset/fdt_reset_sunxi_wdt.c b/lib/utils/reset/fdt_reset_sunxi_wdt.c index f4b06d23..708bf25c 100644 --- a/lib/utils/reset/fdt_reset_sunxi_wdt.c +++ b/lib/utils/reset/fdt_reset_sunxi_wdt.c @@ -71,7 +71,7 @@ static const struct fdt_match sunxi_wdt_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_sunxi_wdt = { +const struct fdt_driver fdt_reset_sunxi_wdt = { .match_table = sunxi_wdt_reset_match, .init = sunxi_wdt_reset_init, }; diff --git a/lib/utils/reset/fdt_reset_syscon.c b/lib/utils/reset/fdt_reset_syscon.c index 0dd76acb..d1a3bc0e 100644 --- a/lib/utils/reset/fdt_reset_syscon.c +++ b/lib/utils/reset/fdt_reset_syscon.c @@ -151,7 +151,7 @@ static const struct fdt_match syscon_poweroff_match[] = { { }, }; -struct fdt_reset fdt_syscon_poweroff = { +const struct fdt_driver fdt_syscon_poweroff = { .match_table = syscon_poweroff_match, .init = syscon_reset_init, }; @@ -161,7 +161,7 @@ static const struct fdt_match syscon_reboot_match[] = { { }, }; -struct fdt_reset fdt_syscon_reboot = { +const struct fdt_driver fdt_syscon_reboot = { .match_table = syscon_reboot_match, .init = syscon_reset_init, }; diff --git a/platform/generic/sifive/fu740.c b/platform/generic/sifive/fu740.c index 46dc02ae..52ca12ff 100644 --- a/platform/generic/sifive/fu740.c +++ b/platform/generic/sifive/fu740.c @@ -209,11 +209,16 @@ static const struct fdt_match da9063_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_da9063 = { +const struct fdt_driver fdt_reset_da9063 = { .match_table = da9063_reset_match, .init = da9063_reset_init, }; +static const struct fdt_driver *const sifive_fu740_reset_drivers[] = { + &fdt_reset_da9063, + NULL +}; + static u64 sifive_fu740_tlbr_flush_limit(const struct fdt_match *match) { /* @@ -232,7 +237,7 @@ static int sifive_fu740_final_init(bool cold_boot, void *fdt, int rc; if (cold_boot) { - rc = fdt_reset_driver_init(fdt, &fdt_reset_da9063); + rc = fdt_driver_init_one(fdt, sifive_fu740_reset_drivers); if (rc) sbi_printf("%s: failed to find da9063 for reset\n", __func__); diff --git a/platform/generic/starfive/jh7110.c b/platform/generic/starfive/jh7110.c index 264fe99c..6d95758f 100644 --- a/platform/generic/starfive/jh7110.c +++ b/platform/generic/starfive/jh7110.c @@ -227,11 +227,16 @@ static const struct fdt_match pm_reset_match[] = { { }, }; -static struct fdt_reset fdt_reset_pmic = { +static const struct fdt_driver fdt_reset_pmic = { .match_table = pm_reset_match, .init = pm_reset_init, }; +static const struct fdt_driver *const starfive_jh7110_reset_drivers[] = { + &fdt_reset_pmic, + NULL +}; + static int starfive_jh7110_inst_init(const void *fdt) { int noff, rc = 0; @@ -281,7 +286,7 @@ static int starfive_jh7110_final_init(bool cold_boot, void *fdt, const struct fdt_match *match) { if (cold_boot) { - fdt_reset_driver_init(fdt, &fdt_reset_pmic); + fdt_driver_init_one(fdt, starfive_jh7110_reset_drivers); } return 0; From patchwork Tue Nov 5 04:20:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2006646 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=dXmzTyAt; 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=j2uzMDC9; 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 4XjFYx3LJgz1xyM for ; Tue, 5 Nov 2024 15:23:01 +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=e3+plllOTEYsGpPeXdg/j4e6fx9OkPaFprpUVsjGit8=; b=dXmzTyAtyd1x6M uyuxdbmvimMPpRzvZOUNgHVCKpW+G5/RlbaaLktThtYMhJM6Iy070mCRs5sxX59O59sKeJDypBwrl 0yU73N8fAOLgXUnO5/aCm3PWws+nNFTgXYIvFjjb6n+O1sT4xxCVi14CT44rzdsIuNBobjpPE4k5j R1xDlmp4B2KhEgX3ox0GiazIjdPh8U7kjTeXqblbz4JHVrsk1+o6vptI7MdYdOkCdN/k3nkpCqETP hSq/+m0tJ/cCZKJ1FNWPNnDCkMi1byQ/5EWOgBhJNlHpeUYE86wepHh5dy4Gi0cYLRO1pA2n8UVor h5bK9G5bN9nf2x7en0JA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5h-0000000FrPE-0JZK; Tue, 05 Nov 2024 04:22:53 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8B5c-0000000FrLu-49Jz for opensbi@lists.infradead.org; Tue, 05 Nov 2024 04:22:50 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-720be2b27acso4085443b3a.0 for ; Mon, 04 Nov 2024 20:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1730780568; x=1731385368; 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=2BcI+DmEHX+I/8vP/5A6zHR6oaWhlRsV1ZEUaEH6z9w=; b=j2uzMDC92SnTLbDQXaWHGSwUl7Thj9N5hzpescbggkf0kyBr2hoAEfRs05P5Z/leKI waupi5zoa2VCWA1pVwsRJk+WfnmCiHXQsSQgOTt33cSa+HKBJz/shf2KJ/mJd4TDLHRt 3voxOqQ60YYMvja5VLJfcj7rthro4LqpIcieR3XL33Ovxun3yHCB3pnvD2YxfxCQeffr aRn0lfmLoBtUtoexLJjZEN9xqf1xHU2yED47barUzYbicveOoWGG8a+fIwl945f6xU5c qiSUEtUR3hZM8lQTbA62blC9YQuLvs/1nbWeduJDJIXVIezAXDQ+WgXR0+4IDoAShOCZ UQmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730780568; x=1731385368; 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=2BcI+DmEHX+I/8vP/5A6zHR6oaWhlRsV1ZEUaEH6z9w=; b=ngwypJcyTW0wuE/hLLF0RhICIzt/ddNA+/MoGCt5buomMoyC57Ix52UDnFOx4mmkUf W624UJP3rpdJLvz2WYvoMlSeGkeRxsSqBhXnp0RA1U0HTTH349ORAZdY93jnM2xkwm82 /eLDb+aO9byZZc6Tk/+a8pG76aAsl4+YFIldf89Ov7PLwXzGgqfPOllw2pOXavbN6P26 ziJpwtEhOQmevYHvC0bsmmSUkXojmBN0Jvxvxmmhx1HHE9YA7aCKj5BdCjZcFm37nTxA UbPjAJ31i7ODF/doorg8mbJW+RU+r/wIepkNSFwI6vTGzgLqzbNTWFSPz0bYSzBwNvOW l0ag== X-Gm-Message-State: AOJu0Yxl4DFGDnlJH2cZga6f6kWBcCwzW4w9TeCdjbXFw7om9F2h8qD7 FPqhm6qxX8qzKTeVOxaR08ahlwN41lWDQWlbyu9MdTpu15yZpNvtRrZGLHkAameJlZwv2pvUQBn lqVSuAzTC/W4sCGw5HBRTME4a6CnKThMrTvtVqiwe5GIuquSvVuaM9IUZRDt3Rp4JStVm0KcKQa IDNQoah1ZCoGVCF0V2bVxpyVyVuuhkycMCFeO2/lNfKsgaWQLbKFA= X-Google-Smtp-Source: AGHT+IEcQsrnMav5VKqHwO4Nsd/l6LDCMkEhxLYkBRG+kO1yt8OR1EEaJ240UOLMb1Ag+vwiMRENsg== X-Received: by 2002:a05:6a20:7354:b0:1db:d932:ddcc with SMTP id adf61e73a8af0-1dbd932e27bmr9162104637.19.1730780568186; Mon, 04 Nov 2024 20:22:48 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1e5a64sm8493782b3a.65.2024.11.04.20.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 20:22:47 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH 6/6] lib: utils/serial: Use fdt_driver for initialization Date: Mon, 4 Nov 2024 20:20:08 -0800 Message-ID: <20241105042240.2994849-7-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241105042240.2994849-1-samuel.holland@sifive.com> References: <20241105042240.2994849-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_202249_070684_77223689 X-CRM114-Status: GOOD ( 18.66 ) 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:429 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The 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 --- 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, };