From nobody Thu Jan 23 17:27:38 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Yf7Dq1W2mz5lDWp; Thu, 23 Jan 2025 17:27:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Yf7Dp4G6bz43dT; Thu, 23 Jan 2025 17:27:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737653258; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/2oYWOYcTuGxVLU9DNWW9OWsTSwxXmJt5yDpZHQ1Qkw=; b=SAob/+KUKhcwjcETWxC/vpy380OvmLbuSD+DtbgHL9M2ZOONH9xjOFyZXJzujEihdidA85 9sbMXSPfZ+58URONOT0tTUMJUbhymF/TmXA62OGJyeA1fz+RUDarNt0ny5NMV9Koq/3fMA KiX25bPwSh3PZCkzo9CkFLEdq6YHuKaSqvwXq7TG5vAWgeVJx8Tpik8Dv7ehs/RobWD/gh dNN3oNM0A4M/Fj3t7kLx+4o+M+bJZMJqhrb14phHIIxZt8wjd+e5wtkUvTCPgvNfyt46wf ioBJ5+7yN+7gtoafYHFct6fo0LEHfvcH1XSB/Cj+UFpGcwQZJZo76mu8ibjvQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737653258; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/2oYWOYcTuGxVLU9DNWW9OWsTSwxXmJt5yDpZHQ1Qkw=; b=uUKYIJyxhKKm9OJGigtPpzTYayFLA0k+RymsH3RN7UE8u+aQiIdo3dze8fXWzVJLqIXq0d I3BxdOJ2KN9Om9AVe89C+IkojnjcLgIGWmbts0cyuWjVb70uLrexLBgzK26j6GURzb9oFG EkkUDWkE77UtuUrjb3oP2hi7iXG3glbEIDGKW2+nWaQpvZaIh+1XA9+lmJYzL6aXS/rtzQ 5e1T+AQxdex3lMvHApA8aJGOb/iOYnYHD8mT04wAVHrTUw2AQ89uWnkuqyZOpZsPYPdiY2 2cevxtmuSR635t4Ybtx93gQg4fcWHiBF7VvrQ5niKbKSUZPQDjrdi3NvPkEVTA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737653258; a=rsa-sha256; cv=none; b=VVdzRaQkaaaIAn4Y3QWkJCxWGXsIvWHqNBEDMSgPW3m2DyJiAyAMYlUVQceYaimcLlFXyv 8xNi5z8Cqs8r3XiAsB5oDqYgOZxZBD0ml5OtQDRCOU9goqi0W0ggdw7RtR8GqO5DaL8+rv jxs7rC7vFcAlDEYpmcSH1tpqSc8AZK/TkkzSfW4+6fudaQteRiqbjKj1puvIwB8HpGKoP2 NBwutwJSCbU7Q/xsiMx6f9o6KQ/ej+Qxmyp5EcGblsQxUJniEf0rNdOBob2ArS91WKxsYg E8o5jlhYVo6baxSdz9B9jeU/qNQAppi86oggugU6vm8YCYJL/t8jpe3dk3JFUA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Yf7Dp3ph3zp0w; Thu, 23 Jan 2025 17:27:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50NHRcxL022812; Thu, 23 Jan 2025 17:27:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50NHRchQ022809; Thu, 23 Jan 2025 17:27:38 GMT (envelope-from git) Date: Thu, 23 Jan 2025 17:27:38 GMT Message-Id: <202501231727.50NHRchQ022809@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: b802926b7b14 - main - scmi: Add optional asynchronous handling of replies List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b802926b7b145d7cfe2465ac4e19f062a9eb6e6d Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=b802926b7b145d7cfe2465ac4e19f062a9eb6e6d commit b802926b7b145d7cfe2465ac4e19f062a9eb6e6d Author: Cristian Marussi AuthorDate: 2025-01-23 13:26:12 +0000 Commit: Andrew Turner CommitDate: 2025-01-23 17:26:27 +0000 scmi: Add optional asynchronous handling of replies Add the core logic to handle the replies to pending command in an asynchronous manner. Tested on: Arm Morello Board Reviewed by: andrew Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D47426 Signed-off-by: Cristian Marussi --- sys/dev/firmware/arm/scmi.c | 46 ++++++++++++++++++++++++++++++++++++++++----- sys/dev/firmware/arm/scmi.h | 1 + 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/sys/dev/firmware/arm/scmi.c b/sys/dev/firmware/arm/scmi.c index 950bbf94eeb6..0b165e413674 100644 --- a/sys/dev/firmware/arm/scmi.c +++ b/sys/dev/firmware/arm/scmi.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -94,6 +95,8 @@ struct scmi_req { bool use_polling; bool done; bool is_raw; + device_t dev; + struct task tsk; struct mtx mtx; LIST_ENTRY(scmi_req) next; int protocol_id; @@ -103,6 +106,7 @@ struct scmi_req { struct scmi_msg msg; }; +#define tsk_to_req(t) __containerof((t), struct scmi_req, tsk) #define buf_to_msg(b) __containerof((b), struct scmi_msg, payld) #define msg_to_req(m) __containerof((m), struct scmi_req, msg) #define buf_to_req(b) msg_to_req(buf_to_msg(b)) @@ -131,7 +135,9 @@ struct scmi_transport { static void scmi_transport_configure(struct scmi_transport_desc *, phandle_t); static int scmi_transport_init(struct scmi_softc *, phandle_t); static void scmi_transport_cleanup(struct scmi_softc *); -static struct scmi_reqs_pool *scmi_reqs_pool_allocate(const int, const int); +static void scmi_req_async_waiter(void *, int); +static struct scmi_reqs_pool *scmi_reqs_pool_allocate(device_t, const int, + const int); static void scmi_reqs_pool_free(struct scmi_reqs_pool *); static struct scmi_req *scmi_req_alloc(struct scmi_softc *, enum scmi_chan); static struct scmi_req *scmi_req_initialized_alloc(device_t, int, int); @@ -217,7 +223,7 @@ DRIVER_MODULE(scmi, simplebus, scmi_driver, 0, 0); MODULE_VERSION(scmi, 1); static struct scmi_reqs_pool * -scmi_reqs_pool_allocate(const int max_msg, const int max_payld_sz) +scmi_reqs_pool_allocate(device_t dev, const int max_msg, const int max_payld_sz) { struct scmi_reqs_pool *rp; struct scmi_req *req; @@ -229,6 +235,10 @@ scmi_reqs_pool_allocate(const int max_msg, const int max_payld_sz) req = malloc(sizeof(*req) + max_payld_sz, M_DEVBUF, M_ZERO | M_WAITOK); + req->dev = dev; + req->tsk.ta_context = &req->tsk; + req->tsk.ta_func = scmi_req_async_waiter; + mtx_init(&req->mtx, "req", "SCMI", MTX_SPIN); LIST_INSERT_HEAD(&rp->head, req, next); } @@ -280,14 +290,14 @@ scmi_transport_init(struct scmi_softc *sc, phandle_t node) trs->inflight_ht = hashinit(td->max_msg, M_DEVBUF, &trs->inflight_mask); trs->chans[SCMI_CHAN_A2P] = - scmi_reqs_pool_allocate(td->max_msg, td->max_payld_sz); + scmi_reqs_pool_allocate(sc->dev, td->max_msg, td->max_payld_sz); if (trs->chans[SCMI_CHAN_A2P] == NULL) { free(trs, M_DEVBUF); return (ENOMEM); } trs->chans[SCMI_CHAN_P2A] = - scmi_reqs_pool_allocate(td->max_msg, td->max_payld_sz); + scmi_reqs_pool_allocate(sc->dev, td->max_msg, td->max_payld_sz); if (trs->chans[SCMI_CHAN_P2A] == NULL) { scmi_reqs_pool_free(trs->chans[SCMI_CHAN_A2P]); free(trs, M_DEVBUF); @@ -648,7 +658,8 @@ scmi_wait_for_response(struct scmi_softc *sc, struct scmi_req *req, void **out) SCMI_COLLECT_REPLY(sc->dev, &req->msg); if (req->msg.payld[0] != 0) ret = req->msg.payld[0]; - *out = &req->msg.payld[SCMI_MSG_HDR_SIZE]; + if (out != NULL) + *out = &req->msg.payld[SCMI_MSG_HDR_SIZE]; } else { device_printf(sc->dev, "Request for token 0x%X timed-out.\n", req->token); @@ -703,6 +714,20 @@ scmi_msg_get(device_t dev, int tx_payld_sz, int rx_payld_sz) return (&req->msg); } +static void +scmi_req_async_waiter(void *context, int pending) +{ + struct task *ta = context; + struct scmi_softc *sc; + struct scmi_req *req; + + req = tsk_to_req(ta); + sc = device_get_softc(req->dev); + scmi_wait_for_response(sc, req, NULL); + + scmi_msg_put(req->dev, &req->msg); +} + void scmi_msg_put(device_t dev, struct scmi_msg *msg) { @@ -763,3 +788,14 @@ scmi_request(device_t dev, void *in, void **out) return (scmi_wait_for_response(sc, req, out)); } + +int +scmi_msg_async_enqueue(struct scmi_msg *msg) +{ + struct scmi_req *req; + + req = msg_to_req(msg); + + return taskqueue_enqueue_flags(taskqueue_thread, &req->tsk, + TASKQUEUE_FAIL_IF_PENDING | TASKQUEUE_FAIL_IF_CANCELING); +} diff --git a/sys/dev/firmware/arm/scmi.h b/sys/dev/firmware/arm/scmi.h index f5b4173272bb..990759237964 100644 --- a/sys/dev/firmware/arm/scmi.h +++ b/sys/dev/firmware/arm/scmi.h @@ -84,6 +84,7 @@ struct scmi_msg *scmi_msg_get(device_t dev, int tx_payld_sz, int rx_payld_sz); void scmi_msg_put(device_t dev, struct scmi_msg *msg); int scmi_request(device_t dev, void *in, void **); int scmi_request_tx(device_t dev, void *in); +int scmi_msg_async_enqueue(struct scmi_msg *msg); void scmi_rx_irq_callback(device_t dev, void *chan, uint32_t hdr, uint32_t rx_len); DECLARE_CLASS(scmi_driver);