From patchwork Tue Aug 6 07:33:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969356 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=Ba1e353s; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=iKD/+rGB; 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 4WdQ6N35ypz1yYD for ; Tue, 6 Aug 2024 17:34:04 +1000 (AEST) 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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=snaIF4x6sTVyl/PZfM6mHm2KD9bIFbloLFq3RejbuU8=; b=Ba1e353svpO018 GZ7QrJOHGRqsercvAy4rBXRo39etuAvDWPoxqE/kevn+XJihejM4jwXyIf/Dx1zXYaEUjNhNqxHN8 mJoxIOzCjkUaPSM9QPKz3HM+QIuGt4s8fmNmwKSO62edQ/6FhSrIwdKlCHvpV3Y5LJTOXysQo9qUV f6vrCE/K0mbc0RIxFFq6KfmH753d8vwgONlsL5u6hG+Xs+QfVUHjl8J7m6C5cN3UdXjaQGSBgL+uW E0uhduzX9ZrZntjJk4NwpefO/rZ6P5JqFYVBej8BjSy73kAfiMHrKHN6v3Z6Bz4WYaZ1XGzX9COmZ pPVsh6tQvDBXIcms3RDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhg-00000000nlP-3Rhj; Tue, 06 Aug 2024 07:33:56 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhe-00000000nkB-0yew for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:33:55 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-75a6c290528so157665a12.1 for ; Tue, 06 Aug 2024 00:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929633; x=1723534433; 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=wo86vHqf7x8901wkK2oBwU0h8Tw7mYFg2056bBEVWlM=; b=iKD/+rGBuyVNKdxdWu7QYzzkqarStGNa1DckyY0smjflSNtsylUxD4KQUyBHVaJLBL IHFKGQ9qLL9zv8jnxQoWwKHu4swvnWZqMH8MFDa2INboWB3UIztyd0Q0USBXFprAAzpM y3L/gOONREmqeMYwQ+Ib26zZ/uT+XwOK36ilr8qFadepegS3EcwdWYLCND6TTtdQ+PCw Yo/HsmZTuj0vW0NRfKbla23rvQRKx1aVM3IncdT9kS3BV4HMgosGKXxghSq9qZZ/9GDb ltRJxf4ufFGbFh41+BhCH2xN2zzDqpFHnhZCO4IUbzAR1qbC4ys9criNS6PGE130yOlo 4TZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929633; x=1723534433; 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=wo86vHqf7x8901wkK2oBwU0h8Tw7mYFg2056bBEVWlM=; b=hNkXCKqZzDGaaK7nl5vqGIJF/wDn72W+GSK4zCOtuSBTWk6LLcRFzW2VEPPBYDNRdS 2xqv3vZxbb+3lUOrtl/7q2a6Lq9P1p28OuxpxCQuKBtZ6uA7SPiA7XU3w5Bi64XsnP7X iZAON3QcRN9vMt5yeeIDEoTBlcEmm/+49CfuEs+lPkdelQBHcHk4i3RmLuPhTjBCMICD K4eY3aBnmTNeAlY3vismNrRSzpE88rey0VNa9dzS2hbrjYKRK1suNqhErLiMJJCAdRu5 Hhvmmkmonre90lTD3pRo15jBauAHWc50z0+d6ohyhG1eMc1UKsl96qaHmGF8Hz0wru0C j9MA== X-Forwarded-Encrypted: i=1; AJvYcCVX3zeviwN1+SNQ/2jxRrz+MvIT6TS5UKcV+J5LO7+vSwC1hRDOj+hIsJxlpW1lrmEMSD6gCW9u+KXGWmDRjs5VDUgQm7PdhtMyOE4= X-Gm-Message-State: AOJu0YxK9rDB/09cXKkm6SFjM7SR/CxaGbkL2Ou/cWJmG5CxarJZtLfC 4vKGGeLrGwMDiHgRz3QJbcCmJsZ4mgqMX5MU95ZAnj0NyIhez8lrvWN3gxOeqqI= X-Google-Smtp-Source: AGHT+IFqgw8kVe0HXrz3WZA+Vu+HJ4JNR3NvFrRKsqEn6Q5MwYMds10ZnKDdmfbhhVnjma3mN25Ceg== X-Received: by 2002:a05:6a20:c90c:b0:1c4:c1cd:a29d with SMTP id adf61e73a8af0-1c6995ab267mr14243639637.28.1722929633031; Tue, 06 Aug 2024 00:33:53 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:33:52 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 03/16] lib: utils/mailbox: Add simple FDT based mailbox framework Date: Tue, 6 Aug 2024 13:03:25 +0530 Message-Id: <20240806073338.1856901-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003354_296887_D2F54ACB X-CRM114-Status: GOOD ( 20.25 ) 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: Add a simple FDT based mailbox framework which is built on top of the generic mailbox library. The phandle of FDT mailbox DT node is treated as the unique mailbox controller ID which is required by th [...] 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:52d 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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 Add a simple FDT based mailbox framework which is built on top of the generic mailbox library. The phandle of FDT mailbox DT node is treated as the unique mailbox controller ID which is required by the generic mailbox library. The FDT based mailbox drivers will be probed on-demand from fdt_mailbox_request_chan() called by the mailbox client drivers. Signed-off-by: Anup Patel --- include/sbi_utils/mailbox/fdt_mailbox.h | 36 +++++ lib/utils/mailbox/Kconfig | 6 + lib/utils/mailbox/fdt_mailbox.c | 142 +++++++++++++++++++ lib/utils/mailbox/fdt_mailbox_drivers.carray | 3 + lib/utils/mailbox/objects.mk | 3 + 5 files changed, 190 insertions(+) create mode 100644 include/sbi_utils/mailbox/fdt_mailbox.h create mode 100644 lib/utils/mailbox/fdt_mailbox.c create mode 100644 lib/utils/mailbox/fdt_mailbox_drivers.carray diff --git a/include/sbi_utils/mailbox/fdt_mailbox.h b/include/sbi_utils/mailbox/fdt_mailbox.h new file mode 100644 index 00000000..27f425db --- /dev/null +++ b/include/sbi_utils/mailbox/fdt_mailbox.h @@ -0,0 +1,36 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __FDT_MAILBOX_H__ +#define __FDT_MAILBOX_H__ + +#include + +struct fdt_phandle_args; + +/** FDT based mailbox driver */ +struct fdt_mailbox { + const struct fdt_match *match_table; + int (*xlate)(struct mbox_controller *mbox, + const struct fdt_phandle_args *pargs, + u32 *out_chan_args); + int (*init)(void *fdt, int nodeoff, u32 phandle, + const struct fdt_match *match); +}; + +/** Request a mailbox channel using "mboxes" DT property of client DT node */ +int fdt_mailbox_request_chan(void *fdt, int nodeoff, int index, + struct mbox_chan **out_chan); + +/** Simple xlate function to convert one mailbox FDT cell into channel args */ +int fdt_mailbox_simple_xlate(struct mbox_controller *mbox, + const struct fdt_phandle_args *pargs, + u32 *out_chan_args); + +#endif diff --git a/lib/utils/mailbox/Kconfig b/lib/utils/mailbox/Kconfig index f91a9bb9..3957bfba 100644 --- a/lib/utils/mailbox/Kconfig +++ b/lib/utils/mailbox/Kconfig @@ -2,6 +2,12 @@ menu "Mailbox Support" +config FDT_MAILBOX + bool "FDT based mailbox drivers" + depends on FDT + select MAILBOX + default n + config MAILBOX bool "Mailbox support" default n diff --git a/lib/utils/mailbox/fdt_mailbox.c b/lib/utils/mailbox/fdt_mailbox.c new file mode 100644 index 00000000..85a71429 --- /dev/null +++ b/lib/utils/mailbox/fdt_mailbox.c @@ -0,0 +1,142 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include +#include + +/* List of FDT mailbox drivers generated at compile time */ +extern struct fdt_mailbox *fdt_mailbox_drivers[]; +extern unsigned long fdt_mailbox_drivers_size; + +static struct fdt_mailbox *fdt_mailbox_driver(struct mbox_controller *mbox) +{ + int pos; + + if (!mbox) + return NULL; + + for (pos = 0; pos < fdt_mailbox_drivers_size; pos++) { + if (mbox->driver == fdt_mailbox_drivers[pos]) + return fdt_mailbox_drivers[pos]; + } + + return NULL; +} + +static int fdt_mailbox_init(void *fdt, u32 phandle) +{ + int pos, nodeoff, rc; + struct fdt_mailbox *drv; + const struct fdt_match *match; + + /* Find node offset */ + nodeoff = fdt_node_offset_by_phandle(fdt, phandle); + if (nodeoff < 0) + return nodeoff; + + /* Try all mailbox drivers one-by-one */ + for (pos = 0; pos < fdt_mailbox_drivers_size; pos++) { + drv = fdt_mailbox_drivers[pos]; + + match = fdt_match_node(fdt, nodeoff, drv->match_table); + if (match && drv->init) { + rc = drv->init(fdt, nodeoff, phandle, match); + if (rc == SBI_ENODEV) + continue; + if (rc) + return rc; + return 0; + } + } + + return SBI_ENOSYS; +} + +static int fdt_mbox_controller_find(void *fdt, u32 phandle, + struct mbox_controller **out_mbox) +{ + int rc; + struct mbox_controller *mbox = mbox_controller_find(phandle); + + if (!mbox) { + /* mailbox not found so initialize matching driver */ + rc = fdt_mailbox_init(fdt, phandle); + if (rc) + return rc; + + /* Try to find mailbox controller again */ + mbox = mbox_controller_find(phandle); + if (!mbox) + return SBI_ENOSYS; + } + + if (out_mbox) + *out_mbox = mbox; + + return 0; +} + +int fdt_mailbox_request_chan(void *fdt, int nodeoff, int index, + struct mbox_chan **out_chan) +{ + int rc; + struct mbox_chan *chan; + struct fdt_mailbox *drv; + struct fdt_phandle_args pargs; + struct mbox_controller *mbox = NULL; + u32 phandle, chan_args[MBOX_CHAN_MAX_ARGS]; + + if (!fdt || (nodeoff < 0) || (index < 0) || !out_chan) + return SBI_EINVAL; + + pargs.node_offset = pargs.args_count = 0; + rc = fdt_parse_phandle_with_args(fdt, nodeoff, + "mboxes", "#mbox-cells", + index, &pargs); + if (rc) + return rc; + + phandle = fdt_get_phandle(fdt, pargs.node_offset); + rc = fdt_mbox_controller_find(fdt, phandle, &mbox); + if (rc) + return rc; + + drv = fdt_mailbox_driver(mbox); + if (!drv || !drv->xlate) + return SBI_ENOSYS; + + rc = drv->xlate(mbox, &pargs, chan_args); + if (rc) + return rc; + + chan = mbox_controller_request_chan(mbox, chan_args); + if (!chan) + return SBI_ENOENT; + + *out_chan = chan; + return 0; +} + +int fdt_mailbox_simple_xlate(struct mbox_controller *mbox, + const struct fdt_phandle_args *pargs, + u32 *out_chan_args) +{ + int i; + + if (pargs->args_count < 1) + return SBI_EINVAL; + + out_chan_args[0] = pargs->args[0]; + for (i = 1; i < MBOX_CHAN_MAX_ARGS; i++) + out_chan_args[i] = 0; + + return 0; +} diff --git a/lib/utils/mailbox/fdt_mailbox_drivers.carray b/lib/utils/mailbox/fdt_mailbox_drivers.carray new file mode 100644 index 00000000..fd4246df --- /dev/null +++ b/lib/utils/mailbox/fdt_mailbox_drivers.carray @@ -0,0 +1,3 @@ +HEADER: sbi_utils/mailbox/fdt_mailbox.h +TYPE: struct fdt_mailbox +NAME: fdt_mailbox_drivers diff --git a/lib/utils/mailbox/objects.mk b/lib/utils/mailbox/objects.mk index 79b27e4c..2135898c 100644 --- a/lib/utils/mailbox/objects.mk +++ b/lib/utils/mailbox/objects.mk @@ -7,4 +7,7 @@ # Anup Patel # +libsbiutils-objs-$(CONFIG_FDT_MAILBOX) += mailbox/fdt_mailbox.o +libsbiutils-objs-$(CONFIG_FDT_MAILBOX) += mailbox/fdt_mailbox_drivers.carray.o + libsbiutils-objs-$(CONFIG_MAILBOX) += mailbox/mailbox.o