virt_to_page/pci_map_page vs. pci_map_single
Jamie> The Document/DMA-mapping.txt in 2.6.0-test9 says "To map a Jamie> single region, you do:" and then shows pci_map_single. Is Jamie> DMA-mapping.txt in need of patching?
Sounds like it needs an update.
Erm, I don't think so. pci_map_single() covers a different use case from pci_map_page().
The thing pci_map_single() can do that pci_map_page() can't is cope with contiguous regions greater than PAGE_SIZE in length (which you get either from kmalloc() or __get_free_pages()). This feature is used in the SCSI layer for instance.
There has been talk of deprecating dma_map_single() in favour of dma_map_sg() (i.e. make all transfers use scatter/gather and eliminate dma_map_single() in favour of a single sg entry table) but nothing has been done about it (at least as far as I know).
James
Quoted 8 lines · James Bottomley
Jamie> The
Document/DMA-mapping.txtin 2.6.0-test9 says "To map a Jamie> single region, you do:" and then showspci_map_single. Is Jamie> DMA-mapping.txt in need of patching?Sounds like it needs an update.
Quoted 7 lines
Erm, I don't think so.
pci_map_single()covers a different use case frompci_map_page().The thing
pci_map_single()can do thatpci_map_page()can't is cope with contiguous regions greater thanPAGE_SIZEin length (which you get either fromkmalloc()or__get_free_pages()). This feature is used in the SCSI layer for instance.
Does "pci_map_page(virt_to_page(addr))" handle contiguous regions of multiple pages? It seems like the i386 implementation will (assuming we're dealing with kmalloc'd memory). Although the semantics of map_single seem better to me than map_page, if I'm mapping a single "region" of multiple pages.
Quoted 7 lines
There has been talk of deprecating
dma_map_single()in favour ofdma_map_sg()(i.e. make all transfers use scatter/gather and eliminatedma_map_single()in favour of a single sg entry table) but nothing has been done about it (at least as far as I know).James
Thanks,
Jamie Wellnitz
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"James" == James Bottomley <[email protected]> writes:
James> Erm, I don't think so. pci_map_single() covers a different use James> case from pci_map_page().
James> The thing pci_map_single() can do that pci_map_page() can't is James> cope with contiguous regions greater than PAGE_SIZE in length James> (which you get either from kmalloc() or __get_free_pages()). James> This feature is used in the SCSI layer for instance.
The question is whether that should be allowed in the first place. Some IOMMU's will have to map it page-by-page anyway. However if it is to remain a valid use then I don't see why pci_map_page() shouldn't be able to handle it under the same conditions by passing it a size > PAGE_SIZE.
Cheers,
Jes
Quoted 10 lines · Jes Sorensen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"James" == James Bottomley <[email protected]> writes:
James> Erm, I don't think so.
pci_map_single()covers a different use James> case frompci_map_page().James> The thing
pci_map_single()can do thatpci_map_page()can't is James> cope with contiguous regions greater thanPAGE_SIZEin length James> (which you get either fromkmalloc()or__get_free_pages()). James> This feature is used in the SCSI layer for instance.
Quoted 5 lines
The question is whether that should be allowed in the first place. Some IOMMU's will have to map it page-by-page anyway. However if it is to remain a valid use then I don't see why
pci_map_page()shouldn't be able to handle it under the same conditions by passing it a size >PAGE_SIZE.
This raises a question for me regarding these rules in 2.4 versus 2.6. While fixing a bug in PPC's 2.4 pci_map_page/pci_map_sg implementations I noticed that a scatterlist created by the IDE subsystem will pass nents by page struct reference with a size > PAGE_SIZE. Is this a 2.4ism resulting from allowing both address and page reference scatterlist entries? This isn't explicitly mentioned in the DMA docs AFAICT. I'm wondering if this is the same expected behavior in 2.6 as well. If pci_map_page() is limited to size <= PAGE_SIZE then I would expect pci_map_sg() to be limited as well (and vice versa).
-Matt
Quoted 10 lines · Matt Porter
This raises a question for me regarding these rules in 2.4 versus 2.6. While fixing a bug in PPC's 2.4 pci_map_page/pci_map_sg implementations I noticed that a scatterlist created by the IDE subsystem will pass nents by page struct reference with a size >
PAGE_SIZE. Is this a 2.4ism resulting from allowing both address and page reference scatterlist entries? This isn't explicitly mentioned in the DMA docs AFAICT. I'm wondering if this is the same expected behavior in 2.6 as well. Ifpci_map_page()is limited to size <=PAGE_SIZEthen I would expectpci_map_sg()to be limited as well (and vice versa).
Not really. By design, the SG interface can handle entries that are physically contiguous.
If you have a limit on the length of your SG elements (because of the device hardware, say), you can express this to the block layer with the blk_queue_max_segment_size() API.
James
Quoted 12 lines · James Bottomley
Quoted 10 lines · Matt Porter
This raises a question for me regarding these rules in 2.4 versus 2.6. While fixing a bug in PPC's 2.4 pci_map_page/pci_map_sg implementations I noticed that a scatterlist created by the IDE subsystem will pass nents by page struct reference with a size >
PAGE_SIZE. Is this a 2.4ism resulting from allowing both address and page reference scatterlist entries? This isn't explicitly mentioned in the DMA docs AFAICT. I'm wondering if this is the same expected behavior in 2.6 as well. Ifpci_map_page()is limited to size <=PAGE_SIZEthen I would expectpci_map_sg()to be limited as well (and vice versa).
Quoted 6 lines
Not really. By design, the SG interface can handle entries that are physically contiguous.
If you have a limit on the length of your SG elements (because of the device hardware, say), you can express this to the block layer with the
blk_queue_max_segment_size()API.
Ok, then to make this clear to implementers of the pci_map_page()/pci_map_sg() APIs would the following addition to the docs be correct?
-Matt
===== Documentation/DMA-mapping.txt 1.17 vs edited =====
Documentation/DMA-mapping.txt Tue Nov 4 09:59:53 2003 renamed from Documentation/DMA-mapping.txt Sat Aug 16 11:46:50 2003 +5 -1
@@ -499,7 +499,8 @@ pci_unmap_page(dev, dma_handle, size, direction); -Here, "offset" means byte offset within the given page. +Here, "offset" means byte offset within the given page. In addition, +"size" must be <= PAGE_SIZE - offset. With scatterlists, you map a region gathered from several regions by:
@@ -520,6 +521,9 @@ advantage for cards which either cannot do scatter-gather or have very limited number of scatter-gather entries) and returns the actual number of sg entries it mapped them to. + +Note: sglist entries are not limited to PAGE_SIZE, the pci_map_sg() +implementation must handle entries with size > PAGE_SIZE. Then you should loop count times (note: this can be less than nents times) and use sg_dma_address() and sg_dma_len() macros where you previously
Quoted 5 lines · Jes Sorensen
The question is whether that should be allowed in the first place. Some IOMMU's will have to map it page-by-page anyway. However if it is to remain a valid use then I don't see why
pci_map_page()shouldn't be able to handle it under the same conditions by passing it a size >PAGE_SIZE.
I really don't see what's to be gained by doing this. map_page is for mapping one page or a fragment of it. It's designed for small zero copy stuff, like networking. To get it to map more than one page, really we should pass in an array of struct pages.
If the data you have to map is > 1 Page, then the scatter gather interface (dma_map_sg()) is a better way to handle it. dma_map_single() is for the special case of data generated in kernel, which is virtually and physically contiguous (i.e. generated by kmalloc or get_free_pages, so no highmem issues either), which we haven't passed through the SG machinery. It's special cased out in all the drivers that handle SG transactions.
James
Quoted 5 lines
I really don't see what's to be gained by doing this.
map_pageis for mapping one page or a fragment of it. It's designed for small zero copy stuff, like networking. To get it to map more than one page, really we should pass in an array of struct pages.
As an aside it would be nice if networking used the map_sg infrastructure for zero copy. Some architectures need to do things to make the DMA mapping visible to IO and at the moment we do it for each map_page.
Anton
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"James" == James Bottomley <[email protected]> writes:
Quoted 5 lines · Jes Sorensen
Quoted 5 lines
The question is whether that should be allowed in the first place. Some IOMMU's will have to map it page-by-page anyway. However if it is to remain a valid use then I don't see why
pci_map_page()shouldn't be able to handle it under the same conditions by passing it a size >PAGE_SIZE.
James> I really don't see what's to be gained by doing this. map_page James> is for mapping one page or a fragment of it. It's designed for James> small zero copy stuff, like networking. To get it to map more James> than one page, really we should pass in an array of struct James> pages.
I am totally in favor of that. I think it's a really bad idea on relying on the pci_map infrstructure to do the page chopping for multi-page mappings since the IOMMUs will normally have to chop it up anyway. The driver authors needs to be aware of this.
The above was more meant as an example of how pci_map_page() can be hacked to do the same thing as pci_map_single if we really wanted to rely on that behavior.
Cheers,
Jes