From: Vitaly Wool <vwool@ru.mvista.com>
To: Vitaly Wool <vwool@ru.mvista.com>
Cc: linux-kernel@vger.kernel.org, david-b@pacbell.net,
dpervushin@gmail.com, akpm@osdl.org, greg@kroah.com,
basicmark@yahoo.com, komal_shah802003@yahoo.com,
stephen@streetfiresound.com,
spi-devel-general@lists.sourceforge.net, Joachim_Jaeger@digi.com
Subject: [PATCH/RFC] SPI: add DMAUNSAFE analog to David Brownell's core
Date: Tue, 13 Dec 2005 19:53:17 +0300 [thread overview]
Message-ID: <20051213195317.29cfd34a.vwool@ru.mvista.com> (raw)
In-Reply-To: <20051213170629.7240d211.vwool@ru.mvista.com>
Greetings,
this patch removes nasty buffer allocation in spi core for sync message transfers. (And thus solves the problem of possible priority inversion I've pointed out before).
The write_then_read function sets the flags singalling for buffers not being DMA-safe and it's absolutely up to the controller whatta do with that.
I. e. it will prolly allocate/copy if it performs DMA transfers or just don't do anything special if it's working in PIO. It can even use a single DMA-safe buffer as David's core did (although I wouldn't encourage anyone to do that! :))
This is of coure more flexible and also more optimal as it will *not* require _redundant_ memcpy's and semaphores protection in case of PIO transfers.
Please note that this is a key patch for us in some aspects, although it's rather small! :)
Signed-off-by: Vitaly Wool <vwool@ru.mvista.com>
Signed-off-by: Dmitry Pervushin <dpervushin@gmail.com>
drivers/spi/spi.c | 35 ++++++-----------------------------
include/linux/spi/spi.h | 7 +++++++
2 files changed, 13 insertions(+), 29 deletions(-)
Index: linux-2.6.orig/drivers/spi/spi.c
===================================================================
--- linux-2.6.orig.orig/drivers/spi/spi.c
+++ linux-2.6.orig/drivers/spi/spi.c
@@ -507,10 +507,6 @@ int spi_sync(struct spi_device *spi, str
}
EXPORT_SYMBOL_GPL(spi_sync);
-#define SPI_BUFSIZ (SMP_CACHE_BYTES)
-
-static u8 *buf;
-
/**
* spi_write_then_read - SPI synchronous write followed by read
* @spi: device with which data will be exchanged
@@ -532,39 +528,28 @@ int spi_write_then_read(struct spi_devic
const u8 *txbuf, unsigned n_tx,
u8 *rxbuf, unsigned n_rx)
{
- static DECLARE_MUTEX(lock);
-
int status;
struct spi_message message;
struct spi_transfer x[2];
- /* Use preallocated DMA-safe buffer. We can't avoid copying here,
- * (as a pure convenience thing), but we can keep heap costs
- * out of the hot path.
- */
- if ((n_tx + n_rx) > SPI_BUFSIZ)
- return -EINVAL;
-
- down(&lock);
memset(x, 0, sizeof x);
+ memset(&message, 0, sizeof message);
- memcpy(buf, txbuf, n_tx);
- x[0].tx_buf = buf;
+ x[0].tx_buf = tx_buf;
x[0].len = n_tx;
+ x[0].tx_dma_unsafe = 1;
- x[1].rx_buf = buf + n_tx;
+ x[1].rx_buf = rx_buf;
x[1].len = n_rx;
+ x[1].rx_dma_unsafe = 1;
/* do the i/o */
message.transfers = x;
message.n_transfer = ARRAY_SIZE(x);
status = spi_sync(spi, &message);
- if (status == 0) {
- memcpy(rxbuf, x[1].rx_buf, n_rx);
+ if (status == 0)
status = message.status;
- }
- up(&lock);
return status;
}
EXPORT_SYMBOL_GPL(spi_write_then_read);
@@ -575,12 +560,6 @@ static int __init spi_init(void)
{
int status;
- buf = kmalloc(SPI_BUFSIZ, SLAB_KERNEL);
- if (!buf) {
- status = -ENOMEM;
- goto err0;
- }
-
status = bus_register(&spi_bus_type);
if (status < 0)
goto err1;
@@ -593,9 +572,7 @@ static int __init spi_init(void)
err2:
bus_unregister(&spi_bus_type);
err1:
- kfree(buf);
buf = NULL;
-err0:
return status;
}
Index: linux-2.6.orig/include/linux/spi/spi.h
===================================================================
--- linux-2.6.orig.orig/include/linux/spi/spi.h
+++ linux-2.6.orig/include/linux/spi/spi.h
@@ -248,6 +248,10 @@ extern struct spi_master *spi_busnum_to_
* @rx_dma: DMA address of buffer, if spi_message.is_dma_mapped
* @len: size of rx and tx buffers (in bytes)
* @cs_change: affects chipselect after this transfer completes
+ * @tx_dma_unsafe: signals to controller driver that the buffer
+ * is not DMA-safe
+ * @rx_dma_unsafe: signals to controller driver that the buffer
+ * is not DMA-safe
* @delay_usecs: microseconds to delay after this transfer before
* (optionally) changing the chipselect status, then starting
* the next transfer or completing this spi_message.
@@ -288,6 +292,9 @@ struct spi_transfer {
dma_addr_t rx_dma;
unsigned cs_change:1;
+ unsigned rx_dma_unsafe:1;
+ unsigned tx_dma_unsafe:1;
+
u16 delay_usecs;
};
next prev parent reply other threads:[~2005-12-13 16:52 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-12 15:20 [PATCH 2.6-git 0/4] SPI core refresh Vitaly Wool
2005-12-12 15:22 ` [PATCH 2.6-git 1/4] SPI core refresh: SPI core patch Vitaly Wool
2005-12-12 15:49 ` Russell King
2005-12-12 15:24 ` [PATCH 2.6-git 2/4] SPI core refresh: MTD dataflash driver Vitaly Wool
2005-12-12 15:26 ` [PATCH 2.6-git 3/4] SPI core refresh: SPI/PNX controller Vitaly Wool
2005-12-12 15:27 ` [PATCH 2.6-git 4/4] SPI core refresh: dumb EEPROM driver Vitaly Wool
2005-12-12 18:01 ` [PATCH 2.6-git 0/4] SPI core refresh Rui Sousa
2005-12-13 12:09 ` [spi-devel-general] " dmitry pervushin
2005-12-13 15:11 ` Rui Sousa
2005-12-13 17:06 ` dmitry pervushin
2005-12-14 6:57 ` Vitaly Wool
2005-12-14 14:28 ` Rui Sousa
2005-12-13 16:35 ` David Brownell
2005-12-13 18:02 ` Rui Sousa
2005-12-13 14:06 ` [PATCH/RFC] SPI: add async message handing library to David Brownell's core Vitaly Wool
2005-12-13 16:53 ` Vitaly Wool [this message]
2005-12-13 19:01 ` [PATCH/RFC] SPI: add DMAUNSAFE analog " David Brownell
2005-12-13 19:15 ` Greg KH
2005-12-14 13:50 ` Vitaly Wool
2005-12-14 17:18 ` Greg KH
2005-12-14 17:53 ` Vitaly Wool
2005-12-14 18:50 ` [PATCH/RFC] SPI: add DMAUNSAFE analog David Brownell
2005-12-14 19:29 ` Vitaly Wool
2005-12-14 19:02 ` [PATCH/RFC] SPI: add DMAUNSAFE analog to David Brownell's core David Brownell
2005-12-14 19:19 ` Vitaly Wool
2005-12-14 19:33 ` [spi-devel-general] Re: [PATCH/RFC] SPI: add DMAUNSAFE analog David Brownell
2005-12-14 19:34 ` [PATCH/RFC] SPI: add DMAUNSAFE analog to David Brownell's core Vitaly Wool
2005-12-15 6:47 ` Vitaly Wool
2005-12-15 16:44 ` Greg KH
2005-12-15 22:23 ` Vitaly Wool
2005-12-15 23:02 ` Greg KH
2005-12-16 8:37 ` Vitaly Wool
2005-12-16 17:34 ` Greg KH
2005-12-16 18:32 ` [spi-devel-general] Re: [PATCH/RFC] SPI: add DMAUNSAFE analog David Brownell
2005-12-15 20:06 ` David Brownell
2005-12-15 22:17 ` Vitaly Wool
2005-12-15 22:33 ` Greg KH
2005-12-16 3:34 ` Andy Isaacson
2005-12-16 5:17 ` Greg KH
2005-12-14 19:16 ` [PATCH/RFC] SPI: add DMAUNSAFE analog to David Brownell's core Greg KH
2005-12-14 19:30 ` Vitaly Wool
2005-12-15 10:00 ` [spi-devel-general] " dmitry pervushin
2005-12-14 17:22 ` David Brownell
2005-12-14 17:50 ` Vitaly Wool
2005-12-14 19:17 ` [PATCH/RFC] SPI: add DMAUNSAFE analog David Brownell
2005-12-14 20:11 ` Vitaly Wool
2005-12-13 21:47 ` [PATCH/RFC] SPI: add DMAUNSAFE analog to David Brownell's core Vitaly Wool
2005-12-13 22:15 ` Vitaly Wool
2005-12-14 16:55 ` David Brownell
2005-12-14 17:23 ` Vitaly Wool
2005-12-14 18:48 ` [PATCH/RFC] SPI: add async message handing library " Stephen Street
2005-12-14 19:41 ` Vitaly Wool
2005-12-14 21:19 ` Stephen Street
2005-12-14 19:31 ` [PATCH/RFC] SPI: add async message handing library David Brownell
2005-12-15 12:19 ` [PATCH/RFC] SPI: async message handing library update Vitaly Wool
2005-12-18 18:59 ` David Brownell
2005-12-19 15:40 ` [spi-devel-general] " dmitry pervushin
2005-12-20 7:23 ` David Brownell
2005-12-20 18:02 ` Vitaly Wool
2005-12-22 17:28 ` David Brownell
2005-12-22 22:10 ` Vitaly Wool
2005-12-22 23:55 ` David Brownell
2005-12-21 13:17 ` Vitaly Wool
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20051213195317.29cfd34a.vwool@ru.mvista.com \
--to=vwool@ru.mvista.com \
--cc=Joachim_Jaeger@digi.com \
--cc=akpm@osdl.org \
--cc=basicmark@yahoo.com \
--cc=david-b@pacbell.net \
--cc=dpervushin@gmail.com \
--cc=greg@kroah.com \
--cc=komal_shah802003@yahoo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=spi-devel-general@lists.sourceforge.net \
--cc=stephen@streetfiresound.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).