linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Feng Tang <feng.tang@intel.com>
To: David Brownell <david-b@pacbell.net>
Cc: Masakazu Mokuno <mokuno@sm.sony.co.jp>, Greg KH <greg@kroah.com>,
	"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
	spi-devel-list <spi-devel-general@lists.sourceforge.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	"alan@lxorguk.ukuu.org.uk" <alan@lxorguk.ukuu.org.uk>
Subject: Re: [PATCH v4] serial: spi: add spi-uart driver for Maxim 3110
Date: Mon, 1 Mar 2010 10:30:07 +0800	[thread overview]
Message-ID: <20100301103007.60926192@feng-i7> (raw)
In-Reply-To: <201002261141.43002.david-b@pacbell.net>

On Sat, 27 Feb 2010 03:41:42 +0800
David Brownell <david-b@pacbell.net> wrote:

> On Friday 26 February 2010, Masakazu Mokuno wrote:
> > > +static int max3110_read_multi(struct uart_max3110 *max, u8 *buf)
> > > +{
> > > +     u16 obuf[M3110_RX_FIFO_DEPTH], ibuf[M3110_RX_FIFO_DEPTH];
> > 
> > Doing I/O on stack is guaranteed safe for spi functions?
> 
> Good catch ...  no it's not safe.
> 
> No DMA-enabled programming interface allows it, including SPI.
Hi David,

I agree that DMA working mode must not use stack as IO buffer, and spi core
code(spi.c/spi.h) has clearly message stating that. But this driver doesn't
intend to use DMA by design. In early version of this patch there is some
controller specific data which show "enable_dma = 0".

The reason of not using DMA for Maxim 3110 is, it is a low speed SPI UART
device, which only has one word (16b) TX buffer and 8 words RX buffer, using
DMA may benefit in some use case but will be over-kill for others. This
driver implement a console,  take one example of editing a file on the console,
each char we input will be echoed back on screen, which will use a spi_message
and a spi_transfer, if using DMA, that DMA operation length will be 2 bytes,
if the file been edited has 4K characters, there will be 4K DMA transactions,
which will occupy quiet some system load. 

Also whether a 16b word could be DMAed is still a question for some types of
DMA controllers, I know some platform whose DMA controllers can only  or
configured to only work with data at least 32 bits aligned. 

So in this driver, it leverages some options provided by SPI controller drivers
(pxa2xx and Designware) to chose not using DMA. 

Thanks,
Feng

> 
> The Documentation/PCI/PCI-DMA-mapping.txt file has a section with
> the oddly punctuated title "What memory is DMA'able?".  That's
> generic to all uses of DMA.  When it was moved to the PCI area,
> that information became harder to find ... but no less true for
> non-PCI contexts (sigh).  One relevant paragraph being:
> 
>   This rule also means that you may use neither kernel image addresses
>   (items in data/text/bss segments), nor module image addresses, nor
>   stack addresses for DMA.  These could all be mapped somewhere
> entirely different than the rest of physical memory.  Even if those
> classes of memory could physically work with DMA, you'd need to
> ensure the I/O buffers were cacheline-aligned.  Without that, you'd
> see cacheline sharing problems (data corruption) on CPUs with
> DMA-incoherent caches. (The CPU could write to one word, DMA would
> write to a different one in the same cache line, and one of them
> could be overwritten.)
> 
> Those cacheline sharing problems are particularly bad for the stack,
> since the data corruption often includes return addresses.
> 
> In short, passing a stack-based I/O buffer could work on some
> machines, but cause perplexing data corruption issues on others.  So
> don't try to do it any driver that claims to be portable.
> 
> - Dave
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2010-03-01  2:30 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20091229222006.1ddb28a4@feng-desktop>
2009-12-29 14:59 ` [spi-devel-general] [RFC][PATCH] serial: spi: add spi-uart driver for Maxim 3110 Baruch Siach
2009-12-29 16:05   ` Tang, Feng
2009-12-29 18:43     ` Erwin Authried
2009-12-30  1:54       ` Feng Tang
2010-02-25  4:47       ` David Brownell
2010-02-25  7:49         ` Feng Tang
2009-12-29 15:02 ` Alan Cox
2010-02-08  8:59 ` [RFC][PATCH v2] " Feng Tang
     [not found] ` <20100208165946.0e4dde83@feng-i7>
2010-02-09  0:20   ` Andrew Morton
2010-02-09  0:26     ` Grant Likely
2010-02-09  1:36       ` Feng Tang
2010-02-17 22:58         ` Greg KH
2010-02-24  5:11           ` [RFC][PATCH v3] " Feng Tang
2010-02-24 10:44             ` Alan Cox
2010-02-24 14:25               ` Grant Likely
2010-02-24 23:18             ` Andrew Morton
2010-02-25  6:39               ` Feng Tang
2010-02-25  4:43             ` David Brownell
2010-02-25  7:44               ` Feng Tang
2010-02-25  8:11                 ` David Brownell
2010-02-26  3:47             ` [PATCH v4] " Feng Tang
     [not found]             ` <20100226114729.679bb933@feng-i7>
2010-02-26  9:59               ` Masakazu Mokuno
2010-02-26 19:41                 ` David Brownell
2010-03-01  2:30                   ` Feng Tang [this message]
2010-03-02  3:38                 ` Feng Tang
2010-02-09  9:25     ` [RFC][PATCH v2] " Alan Cox
2010-03-03  2:57   ` [PATCH v5] " Feng Tang
2010-03-03  3:59     ` Grant Likely
2010-03-03  4:51     ` David Brownell
2010-03-03  5:52       ` Feng Tang
2010-03-03  6:16         ` David Brownell
2010-03-03  6:37           ` Feng Tang
2010-03-03  7:25             ` David Brownell
2010-03-03  7:42               ` Feng Tang

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=20100301103007.60926192@feng-i7 \
    --to=feng.tang@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=david-b@pacbell.net \
    --cc=greg@kroah.com \
    --cc=linux-serial@vger.kernel.org \
    --cc=mokuno@sm.sony.co.jp \
    --cc=spi-devel-general@lists.sourceforge.net \
    /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).