Skip to contentSkip to conversation

virt_to_page/pci_map_page vs. pci_map_single

DISCUSSION Jamie Wellnitz 5 participants 7 messages Nov 2, 2003 – Nov 4, 2003

lore
Share & tools
lore
#0 lore raw

I see code similar to the following in a few drivers (qlogicfc, sym53c8xx, acenic does something similar):

page = virt_to_page(buffer);
offset = ((unsigned long)buffer & ~PAGE_MASK); busaddr = pci_map_page(pci_dev, page, offset, len, direction);

How is this preferable to:

pci_map_single( pci_dev, buffer, len, direction);

?

pci_map_single can't handle highmem pages (because they don't have a kernel virtual address) but doesn't virt_to_page suffer from the same limitation? Is there some benefit on architectures that don't have highmem?

Thanks,
Jamie Wellnitz
[email protected]

#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Jamie" == Jamie Wellnitz <[email protected]> writes:

Jamie> page = virt_to_page(buffer); offset = ((unsigned long)buffer & Jamie> ~PAGE_MASK); busaddr = pci_map_page(pci_dev, page, offset, len, Jamie> direction);

Jamie> How is this preferable to:

Jamie> pci_map_single( pci_dev, buffer, len, direction);

Jamie> pci_map_single can't handle highmem pages (because they don't Jamie> have a kernel virtual address) but doesn't virt_to_page suffer Jamie> from the same limitation? Is there some benefit on Jamie> architectures that don't have highmem?

virt_to_page() can handle any page in the standard kernel region including pages that are physically in 64-bit space if the architecture requires it. It doesn't handle vmalloc pages etc. but one shouldn't try and dynamically map vmalloc pages at random. pci_map_page() can handle all memory in the system though as every page that can be mapped has a struct page * entry.

pci_map_page() is the correct API to use, pci_map_single() is deprecated.

Cheers,
Jes

#2 lore raw
Quoted 8 lines · Jes Sorensen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Jamie" == Jamie Wellnitz <[email protected]> writes:

Jamie> page = virt_to_page(buffer); offset = ((unsigned long)buffer & Jamie> ~PAGE_MASK); busaddr = pci_map_page(pci_dev, page, offset, len, Jamie> direction);

Jamie> How is this preferable to:

Quoted 8 lines

Jamie> pci_map_single( pci_dev, buffer, len, direction);

Jamie> pci_map_single can't handle highmem pages (because they don't Jamie> have a kernel virtual address) but doesn't virt_to_page suffer Jamie> from the same limitation? Is there some benefit on Jamie> architectures that don't have highmem?

virt_to_page() can handle any page in the standard kernel region

What is the "standard kernel region"? ZONE_NORMAL?

Quoted 8 lines

including pages that are physically in 64-bit space if the architecture requires it. It doesn't handle vmalloc pages etc. but one shouldn't try and dynamically map vmalloc pages at random. pci_map_page() can handle all memory in the system though as every page that can be mapped has a struct page * entry.

pci_map_page() is the correct API to use, pci_map_single() is deprecated.

Are you talking about 2.4 or 2.6 or both?

The Document/DMA-mapping.txt in 2.6.0-test9 says "To map a single region, you do:" and then shows pci_map_single. Is DMA-mapping.txt in need of patching?

Quoted 3 lines

Cheers,
Jes

Thanks,
Jamie
[email protected]

#3 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Jamie" == Jamie Wellnitz <[email protected]> writes:

Quoted 1 line · Jes Sorensen
Quoted 1 line

virt_to_page() can handle any page in the standard kernel region

Jamie> What is the "standard kernel region"? ZONE_NORMAL?

Hmmm, my brain has gotten ia64ified ;-) It's basically the normal mappings of the kernel, ie. the kernel text/data/bss segments as well as anything you do not get back as a dynamic mapping such as ioremap/vmalloc/kmap.

Quoted 2 lines
Quoted 2 lines

pci_map_page() is the correct API to use, pci_map_single() is deprecated.

Jamie> Are you talking about 2.4 or 2.6 or both?

Both really.

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.

Cheers,
Jes

#4 lore raw
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · Jes Sorensen

"Jamie" == Jamie Wellnitz <[email protected]> writes:

Quoted 1 line · Jes Sorensen
Quoted 1 line
Quoted 1 line

virt_to_page() can handle any page in the standard kernel region

Jamie> What is the "standard kernel region"? ZONE_NORMAL?

Jes> Hmmm, my brain has gotten ia64ified ;-) It's basically the normal Jes> mappings of the kernel, ie. the kernel text/data/bss segments as well Jes> as anything you do not get back as a dynamic mapping such as Jes> ioremap/vmalloc/kmap.

I don't think it's safe to use virt_to_page() on static kernel addresses (text, data, and bss). For example, ia64 linux nowadays uses a virtual mapping for the static kernel memory, so it's not part of the identity-mapped segment.

	--david
#5 lore raw
Quoted 11 lines · On Mon, 3 Nov 2003 14:02:57 -0800 David Mosberger <[email protected]>…
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jes Sorensen

Jes> Hmmm, my brain has gotten ia64ified ;-) It's basically the normal Jes> mappings of the kernel, ie. the kernel text/data/bss segments as well Jes> as anything you do not get back as a dynamic mapping such as Jes> ioremap/vmalloc/kmap.

I don't think it's safe to use virt_to_page() on static kernel addresses (text, data, and bss). For example, ia64 linux nowadays uses a virtual mapping for the static kernel memory, so it's not part of the identity-mapped segment.

That's correct and it'll break on sparc64 for similar reasons.

It's also not safe to do virt_to_page() on kernel stack addresses either.

#6 lore raw
In reply to David Mosberger
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"David" == David Mosberger <[email protected]> writes:

Jes> Hmmm, my brain has gotten ia64ified ;-) It's basically the normal Jes> mappings of the kernel, ie. the kernel text/data/bss segments as Jes> well as anything you do not get back as a dynamic mapping such as Jes> ioremap/vmalloc/kmap.

David> I don't think it's safe to use virt_to_page() on static kernel David> addresses (text, data, and bss). For example, ia64 linux David> nowadays uses a virtual mapping for the static kernel memory, David> so it's not part of the identity-mapped segment.

Mmmm good point, I stand corrected. It doesn't really make sense to do it anyway, but maybe it's worth underlining in the doc if it hasn't been done so already.

Cheers,
Jes