From patchwork Thu Aug 18 10:10:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 9287397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F2F6A607FF for ; Thu, 18 Aug 2016 10:54:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4DB62902D for ; Thu, 18 Aug 2016 10:54:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9C3529081; Thu, 18 Aug 2016 10:54:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 66F542902D for ; Thu, 18 Aug 2016 10:54:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1baKvo-0003QU-Fq; Thu, 18 Aug 2016 10:52:16 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1baKt3-0000E3-9l for linux-arm-kernel@bombadil.infradead.org; Thu, 18 Aug 2016 10:49:25 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by merlin.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1baKIb-0000Ig-JO for linux-arm-kernel@lists.infradead.org; Thu, 18 Aug 2016 10:11:45 +0000 Received: by mail-wm0-x234.google.com with SMTP id o80so24579381wme.1 for ; Thu, 18 Aug 2016 03:11:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EasK/UBZu8uBbT6gSdXzrT0G3LJ9JAl9KYuHIVjHx7w=; b=ZN2NFTDlgXtx/w/l2r71MDLeVI6J8wyPPxyAXBmgYvdC7Nusm6yEqIK6aTZvU/rKCw qeYizQcnnEZEsv2HE5bN3uFkmxKXGcLk7loV15PlAklPrbdFr5QQ2VsIbUIvkIQ7t/NU YbuNfZ0c+Zn2trwFlJnvckkTLennA7GajK8qjyIVq5yuOu34im5QFC6GO3L33sD9PbZa iAOWu/tNDJE8IJ27U1txGpV7oR7P9dZy1XftOkl8ns/HtE/DqbWsZMT3FCxVvk0DXoOn fVq6DqoGnJvuz52UESBOcQQeaFsvtjvdiBjalXBHKsxrchKwHlqumMH6eIAq78EzNIqU BRcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EasK/UBZu8uBbT6gSdXzrT0G3LJ9JAl9KYuHIVjHx7w=; b=OP1GaNUOp2RGdN062ydXxBN70DnSqVLwRjMcvHviOhvFq+TSHA5Ph3zJRJl1b0aOKp vi2LrYPkmS4a2ucmzsC5HEvOy8NLB759aU9WjjPdjNbd5xzNMh4SYa6H1D1kuaG5KjGH pO2aunWPvVHgFkM3XZnAIuWdfTwBfb3nbvhUq1N87RCWlzx4SxwNYZaJRB8sUgYMXvEw S1L2GnfGQM4KeUYNOdW4wgKD7y5gdQWR3r2aCq9BfAwUk6TzRecDeYijX4amSxnw9Goc kQqSEXKGq8MpmH/3brokIaqz0MdW//vc1EYAo/oAn0R9y0CV8EOGp1Qyrv9QX4xNqGnn 66AQ== X-Gm-Message-State: AEkoouvlr38wOe2YMveth+ter1gA8lea91TqZgpLZRqH71L5qo7ywC5CuYi5tQEjmV7d7orh X-Received: by 10.194.87.67 with SMTP id v3mr692136wjz.103.1471515083669; Thu, 18 Aug 2016 03:11:23 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id f4sm30915247wmf.8.2016.08.18.03.11.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Aug 2016 03:11:23 -0700 (PDT) From: Neil Armstrong To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, sudeep.holla@arm.com Subject: [PATCH 03/13] scpi: Add legacy send, prepare and handle remote functions Date: Thu, 18 Aug 2016 12:10:56 +0200 Message-Id: <1471515066-3626-4-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471515066-3626-1-git-send-email-narmstrong@baylibre.com> References: <1471515066-3626-1-git-send-email-narmstrong@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160818_061145_755230_9908931E X-CRM114-Status: GOOD ( 16.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heiko@sntech.de, Neil Armstrong , frank.wang@rock-chips.com, khilman@baylibre.com, linux-amlogic@lists.infradead.org, wxt@rock-chips.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In order to support the legacy SCPI procotol, add specific message_send, prepare_tx and handle_remote functions since the legacy procotol do not support message queuing and does not store the command word in the tx_payload data. Signed-off-by: Neil Armstrong --- drivers/firmware/arm_scpi.c | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index 0bb6134..50b1297 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -202,6 +202,7 @@ struct scpi_chan { spinlock_t rx_lock; /* locking for the rx pending list */ struct mutex xfers_lock; u8 token; + struct scpi_xfer *t; }; struct scpi_drvinfo { @@ -364,6 +365,23 @@ static void scpi_handle_remote_msg(struct mbox_client *c, void *msg) scpi_process_cmd(ch, cmd); } +static void legacy_scpi_handle_remote_msg(struct mbox_client *c, void *__msg) +{ + struct scpi_chan *ch = + container_of(c, struct scpi_chan, cl); + struct legacy_scpi_shared_mem *mem = ch->rx_payload; + unsigned int len; + + len = ch->t->rx_len; + + ch->t->status = le32_to_cpu(mem->status); + + if (len) + memcpy_fromio(ch->t->rx_buf, mem->payload, len); + + complete(&ch->t->done); +} + static void scpi_tx_prepare(struct mbox_client *c, void *msg) { unsigned long flags; @@ -384,6 +402,15 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg) mem->command = cpu_to_le32(t->cmd); } +static void legacy_scpi_tx_prepare(struct mbox_client *c, void *__msg) +{ + struct scpi_chan *ch = + container_of(c, struct scpi_chan, cl); + + if (ch->t->tx_buf && ch->t->tx_len) + memcpy_toio(ch->tx_payload, ch->t->tx_buf, ch->t->tx_len); +} + static int legacy_high_priority_cmds[] = { LEGACY_SCPI_CMD_GET_CSS_PWR_STATE, LEGACY_SCPI_CMD_CFG_PWR_STATE_STAT, @@ -434,6 +461,48 @@ static void put_scpi_xfer(struct scpi_xfer *t, struct scpi_chan *ch) mutex_unlock(&ch->xfers_lock); } +static int legacy_scpi_send_message(u8 cmd, void *tx_buf, unsigned int tx_len, + void *rx_buf, unsigned int rx_len) +{ + int ret; + u8 chan; + struct scpi_xfer *msg; + struct scpi_chan *scpi_chan; + + chan = legacy_scpi_get_chan(cmd); + scpi_chan = scpi_info->channels + chan; + + msg = get_scpi_xfer(scpi_chan); + if (!msg) + return -ENOMEM; + + mutex_lock(&scpi_chan->xfers_lock); + + msg->cmd = PACK_LEGACY_SCPI_CMD(cmd, tx_len); + msg->tx_buf = tx_buf; + msg->tx_len = tx_len; + msg->rx_buf = rx_buf; + msg->rx_len = rx_len; + init_completion(&msg->done); + scpi_chan->t = msg; + + ret = mbox_send_message(scpi_chan->chan, &msg->cmd); + if (ret < 0) + goto out; + + if (!wait_for_completion_timeout(&msg->done, MAX_RX_TIMEOUT)) + ret = -ETIMEDOUT; + else + /* first status word */ + ret = msg->status; +out: + mutex_unlock(&scpi_chan->xfers_lock); + + put_scpi_xfer(msg, scpi_chan); + /* SCPI error codes > 0, translate them to Linux scale*/ + return ret > 0 ? scpi_to_linux_errno(ret) : ret; +} + static int __scpi_send_message(u8 cmd, void *tx_buf, unsigned int tx_len, void *rx_buf, unsigned int rx_len, bool extn) {