Skip to contentSkip to conversation

ioremap() and CONFIG_SWAP_IO_SPACE

DISCUSSION Thomas Koeller 3 participants 5 messages Aug 25, 2004 – Oct 20, 2004 MIPS

lore
Share & tools
lore
#0 lore raw

Hi,

my platform (PMC-Sierra Yosemite in big endian mode), like many others, uses ioremap() to map device registers, such as the RM9000's OCD registers. To access those registers, the return value of ioremap() is casted to a suitable pointer type and dereferenced. This of course works, but the return value of ioremap() is documented not to be a directly dereferenceable pointer value, and accesses to ioremapped addresses should be performed using the readx/writex APIs.

I therefore decided to straighten this out and use those APIs throughout, but that did not work. The platform defines 'CONFIG_SWAP_IO_SPACE=y', which causes all accesses through readx/writex to be byte-swapped. That is not really appropriate, as the registers are in big endian order. I therefore tried to change that setting in yosemite_defconfig, only to find that every time I do 'make oldconfig' it returns to its original value of 'y'.

So here are my questions:

1. Am I right to conclude that the platform configuration should not set CONFIG_SWAP_IO_SPACE, or am I missing something?

2. What is the mechanism that causes that setting to always revert to enabled when doing 'make oldconfig'? How do I avoid that?

thanks,
Thomas

Signature · 9 lines
--------------------------------------------------

Thomas Koeller, Software Development
Basler Vision Technologies

thomas dot koeller at baslerweb dot com
http://www.baslerweb.com

==============================
#1 lore raw
Quoted 10 lines · Thomas Koeller

my platform (PMC-Sierra Yosemite in big endian mode), like many others, uses ioremap() to map device registers, such as the RM9000's OCD registers. To access those registers, the return value of ioremap() is casted to a suitable pointer type and dereferenced. This of course works, but the return value of ioremap() is documented not to be a directly dereferenceable pointer value, and accesses to ioremapped addresses should be performed using the readx/writex APIs.

In theory, ioremap() and readb() and friends are meant for PCI memory space only. RM9000's OCD registers are not PCI memory space, so there's no strict guarantee readb() and friends will actually work.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#2 lore raw
Quoted 12 lines · Geert Uytterhoeven
Quoted 10 lines · Thomas Koeller

my platform (PMC-Sierra Yosemite in big endian mode), like many others, uses ioremap() to map device registers, such as the RM9000's OCD registers. To access those registers, the return value of ioremap() is casted to a suitable pointer type and dereferenced. This of course works, but the return value of ioremap() is documented not to be a directly dereferenceable pointer value, and accesses to ioremapped addresses should be performed using the readx/writex APIs.

Quoted 4 lines

In theory, ioremap() and readb() and friends are meant for PCI memory space only. RM9000's OCD registers are not PCI memory space, so there's no strict guarantee readb() and friends will actually work.

Well, the ioremap() man page uses the term 'bus memory'; there is no reference to PCI at all. I guess there could be multiple buses on one machine with different byte swapping requirements? There is also an article written by alan cox
(http://www.kernelnewbies.org/documents/kdoc/deviceiobook.pdf)
that describes ioremap() as a general mechanism of accessing memory-mapped io devices, with no reference to PCI at all.

Anyway, if ioremap() and readx()/writex() are for PCI memory access only, how am I supposed to access memory-mapped io devices that are not on a PCI bus?

Thomas

Signature · 16 lines
--------------------------------------------------

Thomas Koeller, Software Development

Basler Vision Technologies
An der Strusbek 60-62
22926 Ahrensburg
Germany

Tel +49 (4102) 463-390
Fax +49 (4102) 463-46390

mailto:[email protected]
http://www.baslerweb.com

==============================
#3 lore raw
Quoted 11 lines · Thomas Koeller

Well, the ioremap() man page uses the term 'bus memory'; there is no reference to PCI at all. I guess there could be multiple buses on one machine with different byte swapping requirements? There is also an article written by alan cox
(http://www.kernelnewbies.org/documents/kdoc/deviceiobook.pdf)
that describes ioremap() as a general mechanism of accessing memory-mapped io devices, with no reference to PCI at all.

Anyway, if ioremap() and readx()/writex() are for PCI memory access only, how am I supposed to access memory-mapped io devices that are not on a PCI bus?

If the standard readX() / writeX() functions don't suffice for some reason then a bus specific versions in a separate header file are needed.

An example are the ISA versions. For compatibility with super old versions from before ioremap or where things on i386 at least seemed to work without ioremap a special isa_readX() / isa_writeX() is supplied. Again for compatibility reasons these macros are defined in <asm/io.h>, not in a separate header file.

Quoted 4 lines

Basler Vision Technologies
An der Strusbek 60-62
22926 Ahrensburg
Germany

Oh, not in Basel :-)

Ralf

#4 lore raw
Quoted 4 lines · Ralf Baechle

If the standard readX() / writeX() functions don't suffice for some reason then a bus specific versions in a separate header file are needed.

So I guess I will have to create something like ocd_readl()/ocd_writel().

Quoted 6 lines

An example are the ISA versions. For compatibility with super old versions from before ioremap or where things on i386 at least seemed to work without ioremap a special isa_readX() / isa_writeX() is supplied. Again for compatibility reasons these macros are defined in <asm/io.h>, not in a separate header file.

Much confusion could be avoided, then, if readX()/writeX() were name pci_readX()/pci_writeX(), and, of course, CONFIG_SWAP_IO_SPACE were named CONFIG_SWAP_PCI_SPACE.

Thomas

Signature · 9 lines
--------------------------------------------------

Thomas Koeller, Software Development
Basler Vision Technologies

thomas dot koeller at baslerweb dot com
http://www.baslerweb.com

==============================