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, };