2007-12-12 23:45:24

by Aras Vaichas

[permalink] [raw]
Subject: mmaping an IO port device

Hi,

Can I implement mmap with an io port connected device on an x86 based CPU?


Background:

I've got a device driver which can be compiled for either x86 or ARM.
The driver provides an interface to an FPGA via either an IO port
(0x180) on the x86 or as a memory mapped SRAM-like device (0x30000000)
on the ARM.

To get myself an "address" for ioread calls I use:

FPGA_base = (u32) ioremap_nocache(FPGA_REG_IO_BASE, SZ_4K) for both CPU
types.

FPGA_REG_IO_BASE is set to either 0x180 or 0x30000000 for x86 and ARM
respectively.

I then call ioread16(FPGA_base + FPGA_register) for both x86 and ARM and
it all works perfectly. No problems there.

My problem is that I am now moving from ioctl calls to a mmap interface.
This isn't a problem with ARM as I can pass (0x30000000 >> PAGE_SHIFT)
to remap_pfn_range() in the .mmap fops function but I can't pass 0x180
because ... well, it's obvious.

Is there a trick?

Aras

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________


2007-12-12 23:57:38

by Aras Vaichas

[permalink] [raw]
Subject: Re: mmaping an IO port device

Aras Vaichas wrote:
> I then call ioread16(FPGA_base + FPGA_register) for both x86 and ARM
> and it all works perfectly. No problems there.
Oop, sorry I lied a little. I actually use inw/outw for the x86 version.

e.g. inw( FPGA_REG_IO_BASE + FPGA_register);

but the main problem still stands ...

Aras


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

2007-12-13 00:39:34

by H. Peter Anvin

[permalink] [raw]
Subject: Re: mmaping an IO port device

Aras Vaichas wrote:
> Hi,
>
> Can I implement mmap with an io port connected device on an x86 based CPU?
>

No.

-hpa

2007-12-13 00:53:17

by Robert Hancock

[permalink] [raw]
Subject: Re: mmaping an IO port device

Aras Vaichas wrote:
> Hi,
>
> Can I implement mmap with an io port connected device on an x86 based CPU?
>
>
> Background:
>
> I've got a device driver which can be compiled for either x86 or ARM.
> The driver provides an interface to an FPGA via either an IO port
> (0x180) on the x86 or as a memory mapped SRAM-like device (0x30000000)
> on the ARM.
>
> To get myself an "address" for ioread calls I use:
>
> FPGA_base = (u32) ioremap_nocache(FPGA_REG_IO_BASE, SZ_4K) for both CPU
> types.
>
> FPGA_REG_IO_BASE is set to either 0x180 or 0x30000000 for x86 and ARM
> respectively.
>
> I then call ioread16(FPGA_base + FPGA_register) for both x86 and ARM and
> it all works perfectly. No problems there.
>
> My problem is that I am now moving from ioctl calls to a mmap interface.
> This isn't a problem with ARM as I can pass (0x30000000 >> PAGE_SHIFT)
> to remap_pfn_range() in the .mmap fops function but I can't pass 0x180
> because ... well, it's obvious.
>
> Is there a trick?
>
> Aras

It's impossible to mmap an IO port area on x86 since IO ports are not
accessible as part of the normal memory space. The only way to get
access to IO ports in userspace is to use iopl (which requires root
privileges) and then executing inl/outl, etc. instructions directly.

--
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from [email protected]
Home Page: http://www.roberthancock.com/

2007-12-13 01:05:17

by Aras Vaichas

[permalink] [raw]
Subject: Re: mmaping an IO port device

Aras Vaichas wrote:
> Hi,
>
> Can I implement mmap with an io port connected device on an x86 based
> CPU?
>
I'll just add one more bit of information which might effect the
situation. The CPU I am using is an Elan SC520 microcontroller.

It seems that this CPU is able remap the General Purpose ports (IO
ports) into the lower 1GB of memory space.

I will investigate.

If anyone knows anything about doing this, please speak up. This is a
legacy CPU in our product range, and I don't have much experience with it.

Aras


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________