From nobody Thu Apr 11 09:59:24 2024 X-Original-To: dev-commits-src-main@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 4VFZt52ndqz5H7KP; Thu, 11 Apr 2024 09:59:25 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VFZt50ZLxz4l5r; Thu, 11 Apr 2024 09:59:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712829565; 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=IjCjFiJFsvgk9xBV+rCows/epWyfz4Ov0vjwDJ3yqG0=; b=JNhlEOKYou+DFiYB4pERqcCR4inu8YWqaxaygvZUO9/ch24CgQ4WX2tJcgPP8EAuJnPdc9 ecklp/nM2v9h2QXwzcNeGJcOdARCRLfM5ZgOV0vMu0qaIA9G90VaIUwUwsck/qusrSJbVQ AEcyOW45zLaWVkvNrbydmmi4dBRiw3ezTEupOF/chIkQnsy7aFp91HTKFjYJw2t6yGg0Q9 bEMaRUnwprmVHccgKLJV2jCbP0j2bzgFEVAcEQkgANwkEjKs+aH7m/DV9AgwFH0Q5GVHo7 Y7ENkUZ4aBakKFDXBcYA7fmK4c0XwmrKj070pVo2ydmP3955PqhnmdnvMtYAKA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712829565; a=rsa-sha256; cv=none; b=i/segCsqwcKT1JTuTt2ph5yi3zDOg3xsZkz0r3Tja5tHouj3SLEQ8pBQmdRotPUSNsVLp3 DJoJEB7YZP+jF0++2xGjkU9+4/vM7r+1FDtpiLrR3YhG1Ckbq6SwUU3vutQU5AsV8QsagW CQ7imlZLhxWDWa3UJvMwsLKySA/83Q6Qqy4bujq4PqYl1oyHO8rt+L0YtS8GlLR63DNz9+ rJlnJAd6qIk4HK5h74tQl2NgbJkiVq+awYN8ECmSfvX7LweaMkTY/cxELkwhN5O7b0Cys4 CDh/3x87EJP/bnUNT9tnckPYQ2UszmiIbWM84ZnKthxKVnyPdNRH5hVOaTQlKw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712829565; 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=IjCjFiJFsvgk9xBV+rCows/epWyfz4Ov0vjwDJ3yqG0=; b=V6ZeURDfHFZ8QIgBh6MWd72xHzjzUPT75Lyu/wmG7H9BmY180p2tD5IxQNg2x9HlQHZSDn ZF3+zxi5EvCm/R+aaMI3Ek/ktFBxyJtPEvF6R7sRNSw+t1BGk19M9gS4xNCyPfPBvz0XGQ Kftc1SZ5EfDEw2ZPsEXaSj//BcLG2fZPCm093HSkawWxToZDj8HiAt1DdJPdyPj/iZigha sthua+dF78AZwc4IXiNneHzzsPM4dB4KOnArwQes3QwWNfCYA5IA7cKnz6Vcj0kPFNNtl4 qYqhCGxZbxYEr+34EIntW3VzFVIP9KphZ8jtQVhzYmbWIb3o6S2kGB1zDZKBmA== 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 4VFZt504FYz1Gb2; Thu, 11 Apr 2024 09:59:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43B9xOSh090521; Thu, 11 Apr 2024 09:59:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43B9xOh0090518; Thu, 11 Apr 2024 09:59:24 GMT (envelope-from git) Date: Thu, 11 Apr 2024 09:59:24 GMT Message-Id: <202404110959.43B9xOh0090518@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: cbcfdff05678 - main - scmi: Fix SCMI mailbox polling mechanism List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: dev-commits-src-main+owner@freebsd.org X-BeenThere: dev-commits-src-main@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: cbcfdff05678b143436f81e09f21b3c727efd805 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=cbcfdff05678b143436f81e09f21b3c727efd805 commit cbcfdff05678b143436f81e09f21b3c727efd805 Author: Cristian Marussi AuthorDate: 2023-12-07 07:06:10 +0000 Commit: Andrew Turner CommitDate: 2024-04-11 09:58:56 +0000 scmi: Fix SCMI mailbox polling mechanism When the system is cold, the SCMI stack processes commands in polling mode with the current polling mechanism being a check of the status register in the mailbox controller to see if there is any pending doorbell request. Anyway, the completion interrupt is optional by the SCMI specification and a system could have been simply designed without it: for this reason polling on the mailbox controller status registers is not going to work in all situations. Moreover even alternative SCMI transports based on shared memory, like SMC, will not have at all a mailbox controller to poll for. On the other side, the associated SCMI Shared Memory Transport defines dedicated channel flags and status bits that can be used by the agent to explicitly request a polling-based transaction, even if the completion interrupt was available, and to check afterwards when the platform has completed its processing on the outstanding command. Use SCMI/SMT specific mechanism to process transactions in polling mode. Reviewed by: andrew Tested on: Arm Morello Board Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D43042 --- sys/dev/firmware/arm/scmi.c | 2 +- sys/dev/firmware/arm/scmi_mailbox.c | 3 ++- sys/dev/firmware/arm/scmi_shmem.c | 18 ++++++++++++++++-- sys/dev/firmware/arm/scmi_shmem.h | 4 +++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/sys/dev/firmware/arm/scmi.c b/sys/dev/firmware/arm/scmi.c index 8428d17cecec..ee41ad4383c0 100644 --- a/sys/dev/firmware/arm/scmi.c +++ b/sys/dev/firmware/arm/scmi.c @@ -85,7 +85,7 @@ scmi_request_locked(struct scmi_softc *sc, struct scmi_req *req) req->msg_header |= SCMI_MSG_TYPE_CMD << SCMI_HDR_MESSAGE_TYPE_S; req->msg_header |= req->protocol_id << SCMI_HDR_PROTOCOL_ID_S; - ret = scmi_shmem_prepare_msg(sc->a2p_dev, req); + ret = scmi_shmem_prepare_msg(sc->a2p_dev, req, cold); if (ret != 0) return (ret); diff --git a/sys/dev/firmware/arm/scmi_mailbox.c b/sys/dev/firmware/arm/scmi_mailbox.c index bebdc7348b98..c7f4fda4d5c4 100644 --- a/sys/dev/firmware/arm/scmi_mailbox.c +++ b/sys/dev/firmware/arm/scmi_mailbox.c @@ -49,6 +49,7 @@ #include "scmi.h" #include "scmi_protocols.h" +#include "scmi_shmem.h" struct scmi_mailbox_softc { struct scmi_softc base; @@ -91,7 +92,7 @@ scmi_mailbox_xfer_msg(device_t dev) do { if (cold) { - if (arm_doorbell_get(sc->db)) + if (scmi_shmem_poll_msg(sc->base.a2p_dev)) break; DELAY(10000); } else { diff --git a/sys/dev/firmware/arm/scmi_shmem.c b/sys/dev/firmware/arm/scmi_shmem.c index efb6b77c6e4b..066f28777cb7 100644 --- a/sys/dev/firmware/arm/scmi_shmem.c +++ b/sys/dev/firmware/arm/scmi_shmem.c @@ -168,7 +168,7 @@ scmi_shmem_get(device_t dev, phandle_t node, int index) } int -scmi_shmem_prepare_msg(device_t dev, struct scmi_req *req) +scmi_shmem_prepare_msg(device_t dev, struct scmi_req *req, bool polling) { struct scmi_smt_header hdr = {}; uint32_t channel_status; @@ -185,7 +185,10 @@ scmi_shmem_prepare_msg(device_t dev, struct scmi_req *req) hdr.channel_status &= ~SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE; hdr.msg_header = htole32(req->msg_header); hdr.length = htole32(sizeof(req->msg_header) + req->in_size); - hdr.flags |= SCMI_SHMEM_FLAG_INTR_ENABLED; + if (!polling) + hdr.flags |= SCMI_SHMEM_FLAG_INTR_ENABLED; + else + hdr.flags &= ~SCMI_SHMEM_FLAG_INTR_ENABLED; /* Write header */ scmi_shmem_write(dev, 0, &hdr, SMT_SIZE_HEADER); @@ -239,6 +242,17 @@ scmi_shmem_read_msg_payload(device_t dev, uint8_t *buf, uint32_t buf_len) return (0); } +bool scmi_shmem_poll_msg(device_t dev) +{ + uint32_t status; + + scmi_shmem_read(dev, SMT_OFFSET_CHAN_STATUS, &status, + SMT_SIZE_CHAN_STATUS); + + return (status & (SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR | + SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE)); +} + static device_method_t shmem_methods[] = { DEVMETHOD(device_probe, shmem_probe), DEVMETHOD(device_attach, shmem_attach), diff --git a/sys/dev/firmware/arm/scmi_shmem.h b/sys/dev/firmware/arm/scmi_shmem.h index ce82a3c90d87..d46493dc0342 100644 --- a/sys/dev/firmware/arm/scmi_shmem.h +++ b/sys/dev/firmware/arm/scmi_shmem.h @@ -63,7 +63,9 @@ struct scmi_smt_header { struct scmi_req; device_t scmi_shmem_get(device_t sdev, phandle_t node, int index); -int scmi_shmem_prepare_msg(device_t dev, struct scmi_req *req); +int scmi_shmem_prepare_msg(device_t dev, struct scmi_req *req, + bool polling); +bool scmi_shmem_poll_msg(device_t); int scmi_shmem_read_msg_header(device_t dev, uint32_t *msg_header); int scmi_shmem_read_msg_payload(device_t dev, uint8_t *buf, uint32_t buf_len);