Skip to contentSkip to conversation

generic device DMA implementation

RFC Adam J. Richter 3 participants 4 messages Dec 5, 2002

lore
Share & tools
lore
#0 lore raw
Quoted 1 line · David Gibson

On Wed, Dec 04, 2002 at 11:47:14AM -0600, James Bottomley wrote:

[...]

Quoted 8 lines
Quoted 6 lines

The new DMA API allows a driver to advertise its level of consistent memory compliance to dma_alloc_consistent. There are essentially two levels:

- I only work with consistent memory, fail if I cannot get it, or
- I can work with inconsistent memory, try consistent first but return inconsistent if it's not available.

Do you have an example of where the second option is useful?

From a previous discussion, I understand that there are some
PCI bus parisc machines without consistent memory.

Quoted 5 lines

Off hand
the only places I can think of where you'd use a consistent_alloc() rather than map_single() and friends is in cases where the hardware's behaviour means you absolutely positively have to have consistent memory.

That would result in big rarely used branches in device
drivers or lots of ifdef's and the equivalent. With James's approach, porting a driver to support those parisc machines (for example) would involve sprinkling in some calls to macros that would compile to nothing on the other machines.

Compare the code clutter involved in allowing those
inconsistent parisc machines to run, say, the ten most popular ethernet controllers and the four most popular scsi controllers. I think the difference in the resulting source code size would already be in the hundreds of lines.

Adam J. Richter     __     ______________   575 Oroville Road
[email protected]     \ /                  Milpitas, California 95035
+1 408 309-6081         | g g d r a s i l   United States of America

"Free Software For The Rest Of Us."

#1 lore raw
Quoted 6 lines · Adam J. Richter
Quoted 1 line · David Gibson

On Wed, Dec 04, 2002 at 11:47:14AM -0600, James Bottomley wrote:

[...]

Quoted 3 lines
Quoted 3 lines

The new DMA API allows a driver to advertise its level of consistent memory compliance to dma_alloc_consistent. There are essentially two levels:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

- I only work with consistent memory, fail if I cannot get it, or
- I can work with inconsistent memory, try consistent first but return inconsistent if it's not available.

Do you have an example of where the second option is useful?

From a previous discussion, I understand that there are some
PCI bus parisc machines without consistent memory.

And there are PPCs without consistent memory, except by disabling cache.

Quoted 12 lines
Quoted 5 lines

Off hand
the only places I can think of where you'd use a consistent_alloc() rather than map_single() and friends is in cases where the hardware's behaviour means you absolutely positively have to have consistent memory.

That would result in big rarely used branches in device
drivers or lots of ifdef's and the equivalent. With James's approach, porting a driver to support those parisc machines (for example) would involve sprinkling in some calls to macros that would compile to nothing on the other machines.

Quoted 5 lines

Compare the code clutter involved in allowing those
inconsistent parisc machines to run, say, the ten most popular ethernet controllers and the four most popular scsi controllers. I think the difference in the resulting source code size would already be in the hundreds of lines.

For cases like this, I'm talking about replacing the consistent_alloc() with a kmalloc(), then using the cache flush macros. Is there any machine for which this is not sufficient?

Signature · 4 lines
David Gibson			| For every complex problem there is a
[email protected]	| solution which is simple, neat and
				| wrong.
http://www.ozlabs.org/people/dgibson
#2 lore raw
Quoted 3 lines · David Gibson

For cases like this, I'm talking about replacing the consistent_alloc() with a kmalloc(), then using the cache flush macros. Is there any machine for which this is not sufficient?

I'm not entirely sure what you mean by `using the cache flush macros,' but on one of my platforms, PCI consistent memory must be allocated from a special area.

It's also not clear what you mean by `for cases like this' -- do you mean, replace _all_ uses of xxx_alloc_consistent with kmalloc, or do you mean just those cases where pci_alloc_consistent currently returns 0?

If the former, it obviously doesn't work on my platform; if the latter, I guess this is what James' patch assumes the platform-specific dma_alloc_consistent function will do.

-Miles

Signature · 1 line
I'd rather be consing.
#3 lore raw
Quoted 8 lines · Miles Bader
Quoted 3 lines · David Gibson

For cases like this, I'm talking about replacing the consistent_alloc() with a kmalloc(), then using the cache flush macros. Is there any machine for which this is not sufficient?

I'm not entirely sure what you mean by `using the cache flush macros,' but on one of my platforms, PCI consistent memory must be allocated from a special area.

Well, yes, you only need the cache flush macros on memory that *isn't* consistent.

Quoted 3 lines

It's also not clear what you mean by `for cases like this' -- do you mean, replace _all_ uses of xxx_alloc_consistent with kmalloc, or do you mean just those cases where pci_alloc_consistent currently returns 0?

I mean replace xxx_alloc_consistent() with kmalloc() and appropriate calls to map_single() (or whatever) in those cases where we actually care about reducing our usage of (genuinely) consistent memory and it is possible to do so.

Quoted 3 lines

If the former, it obviously doesn't work on my platform; if the latter, I guess this is what James' patch assumes the platform-specific dma_alloc_consistent function will do.

Well, with James approach you need a dma_sync() of some sort in pretty much exactly the same places you need a map_single() or similar if you used kmalloc() to start with.

Signature · 4 lines
David Gibson			| For every complex problem there is a
[email protected]	| solution which is simple, neat and
				| wrong.
http://www.ozlabs.org/people/dgibson