From patchwork Wed Jan 4 13:34:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 9496957 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 43EA560237 for ; Wed, 4 Jan 2017 14:10:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3604D27F07 for ; Wed, 4 Jan 2017 14:10:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 289AF27FA6; Wed, 4 Jan 2017 14:10:26 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3683127F07 for ; Wed, 4 Jan 2017 14:10:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3F1706E726; Wed, 4 Jan 2017 14:10:10 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 165956E726 for ; Wed, 4 Jan 2017 14:10:06 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:42458 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cOlij-00006b-Tn; Wed, 04 Jan 2017 14:35:13 +0100 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Subject: [RFC 4/6] spi: Let clients do scatter/gather transfers Date: Wed, 4 Jan 2017 14:34:40 +0100 Message-Id: <20170104133442.4534-5-noralf@tronnes.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170104133442.4534-1-noralf@tronnes.org> References: <20170104133442.4534-1-noralf@tronnes.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Just a hack. Someone probably has an idea about how this should be done. Signed-off-by: Noralf Trønnes --- drivers/spi/spi.c | 24 +++++++++++++++++------- include/linux/spi/spi.h | 4 ++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 838783c..b2958be 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -808,23 +808,28 @@ static int __spi_map_msg(struct spi_master *master, struct spi_message *msg) if (!master->can_dma(master, msg->spi, xfer)) continue; - if (xfer->tx_buf != NULL) { + if (xfer->tx_buf != NULL && !xfer->tx_sg.nents) { ret = spi_map_buf(master, tx_dev, &xfer->tx_sg, (void *)xfer->tx_buf, xfer->len, DMA_TO_DEVICE); if (ret != 0) return ret; + + xfer->tx_sg_core_mapped = true; } - if (xfer->rx_buf != NULL) { + if (xfer->rx_buf != NULL && !xfer->rx_sg.nents) { ret = spi_map_buf(master, rx_dev, &xfer->rx_sg, xfer->rx_buf, xfer->len, DMA_FROM_DEVICE); if (ret != 0) { spi_unmap_buf(master, tx_dev, &xfer->tx_sg, DMA_TO_DEVICE); + xfer->tx_sg_core_mapped = false; return ret; } + + xfer->rx_sg_core_mapped = true; } } @@ -852,11 +857,16 @@ static int __spi_unmap_msg(struct spi_master *master, struct spi_message *msg) rx_dev = &master->dev; list_for_each_entry(xfer, &msg->transfers, transfer_list) { - if (!master->can_dma(master, msg->spi, xfer)) - continue; - - spi_unmap_buf(master, rx_dev, &xfer->rx_sg, DMA_FROM_DEVICE); - spi_unmap_buf(master, tx_dev, &xfer->tx_sg, DMA_TO_DEVICE); + if (xfer->rx_sg_core_mapped) { + spi_unmap_buf(master, rx_dev, &xfer->rx_sg, + DMA_FROM_DEVICE); + xfer->rx_sg.nents = 0; + } + if (xfer->tx_sg_core_mapped) { + spi_unmap_buf(master, tx_dev, &xfer->tx_sg, + DMA_TO_DEVICE); + xfer->tx_sg.nents = 0; + } } return 0; diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 4b743ac..f27fda6 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -682,6 +682,8 @@ extern void spi_res_release(struct spi_master *master, * @transfer_list: transfers are sequenced through @spi_message.transfers * @tx_sg: Scatterlist for transmit, currently not for client use * @rx_sg: Scatterlist for receive, currently not for client use + * @tx_sg_core_mapped: Scatterlist has been mapped by spi core + * @rx_sg_core_mapped: Scatterlist has been mapped by spi core * * SPI transfers always write the same number of bytes as they read. * Protocol drivers should always provide @rx_buf and/or @tx_buf. @@ -751,6 +753,8 @@ struct spi_transfer { dma_addr_t rx_dma; struct sg_table tx_sg; struct sg_table rx_sg; + bool tx_sg_core_mapped; + bool rx_sg_core_mapped; unsigned cs_change:1; unsigned tx_nbits:3;