Discussion:
pci_iomap() and pci_ioremap_bar()
Warlich, Christof
2013-06-26 07:12:36 UTC
Permalink
Hi,

can anyone explain when I should use

void __iomem *regs = pci_iomap(device, barNumber, 0);

and when

void __iomem *regs = pci_ioremap_bar(device, barNumber);

is more appropriate to map PCI memory?

Furthermore, after the mapping succeeded, when may I
directly access the mapped memory, e.g.:

char firstByte = *regs;

and when should I better use ioread8() instead?:

char firstBype = ioread8(regs);

All listed alternatives from above seems to work equally
well for me (on x86), so I'm curious to learn what might
be the difference. A guess: Does ioread8() work for both
memory mapped _and_ IO mapped registers, while the direct
access only works for the memory mapped case?

Thanks for any clarification.
JAYESH TANK
2013-06-27 08:26:36 UTC
Permalink
AFAIK, pci_ioremap_bar api provides an error-proof way (relative to
pci_ioremap) for PCI memory remap.

After the mapping is successful, in case you are writing a portable code,
use ioread8 api which provides platform abstraction to the re mapped
registers.

Hope that helps.

BR,
Jayesh


On Wed, Jun 26, 2013 at 12:42 PM, Warlich, Christof <
Post by Warlich, Christof
Hi,
can anyone explain when I should use
void __iomem *regs = pci_iomap(device, barNumber, 0);
and when
void __iomem *regs = pci_ioremap_bar(device, barNumber);
is more appropriate to map PCI memory?
Furthermore, after the mapping succeeded, when may I
char firstByte = *regs;
char firstBype = ioread8(regs);
All listed alternatives from above seems to work equally
well for me (on x86), so I'm curious to learn what might
be the difference. A guess: Does ioread8() work for both
memory mapped _and_ IO mapped registers, while the direct
access only works for the memory mapped case?
Thanks for any clarification.
_______________________________________________
Kernelnewbies mailing list
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Warlich, Christof
2013-06-28 07:17:39 UTC
Permalink
Hi Jayesh,

thanks, so I should use pci_ioremap_bar() and ioread8() and iowrite8() and the like.

What really confused me was the "re" in pci_ioremap_bar() (by the way, there is no
API called pci_ioremap(), but only pci_iomap()), suggesting that something different
may be done in these two functions apart from better error checking.

________________________________
From: JAYESH TANK [mailto:***@gmail.com]
Sent: Donnerstag, 27. Juni 2013 10:27
To: Warlich, Christof
Cc: ***@kernelnewbies.org
Subject: Re: pci_iomap() and pci_ioremap_bar()

AFAIK, pci_ioremap_bar api provides an error-proof way (relative to pci_ioremap) for PCI memory remap.

After the mapping is successful, in case you are writing a portable code, use ioread8 api which provides platform abstraction to the re mapped registers.

Hope that helps.

BR,
Jayesh


On Wed, Jun 26, 2013 at 12:42 PM, Warlich, Christof <***@siemens.com<mailto:***@siemens.com>> wrote:
Hi,

can anyone explain when I should use

void __iomem *regs = pci_iomap(device, barNumber, 0);

and when

void __iomem *regs = pci_ioremap_bar(device, barNumber);

is more appropriate to map PCI memory?

Furthermore, after the mapping succeeded, when may I
directly access the mapped memory, e.g.:

char firstByte = *regs;

and when should I better use ioread8() instead?:

char firstBype = ioread8(regs);

All listed alternatives from above seems to work equally
well for me (on x86), so I'm curious to learn what might
be the difference. A guess: Does ioread8() work for both
memory mapped _and_ IO mapped registers, while the direct
access only works for the memory mapped case?

Thanks for any clarification.

Loading...