2003-09-25 23:03:57

by Matthew Dharm

[permalink] [raw]
Subject: How do I access ioports from userspace?

I'd like to be able to access some ioports to some custom hardware directly
from userspace, without creating a specialized kernel-level driver. Is
there a way to do that?

Matt

--
Matthew Dharm Home: [email protected]
Maintainer, Linux USB Mass Storage Driver

M: No, Windows doesn't have any nag screens.
C: Then what are those blue and white screens I get every day?
-- Mike and Cobb
User Friendly, 1/4/1999


Attachments:
(No filename) (462.00 B)
(No filename) (232.00 B)
Download all attachments

2003-09-25 23:21:24

by Greg KH

[permalink] [raw]
Subject: Re: How do I access ioports from userspace?

On Thu, Sep 25, 2003 at 04:03:51PM -0700, Matthew Dharm wrote:
> I'd like to be able to access some ioports to some custom hardware directly
> from userspace, without creating a specialized kernel-level driver. Is
> there a way to do that?

/dev/port?

2003-09-26 05:26:49

by Frank v Waveren

[permalink] [raw]
Subject: Re: How do I access ioports from userspace?

On Thu, Sep 25, 2003 at 04:03:51PM -0700, Matthew Dharm wrote:
> I'd like to be able to access some ioports to some custom hardware directly
> from userspace, without creating a specialized kernel-level driver. Is
> there a way to do that?
Either use /dev/port, or if it's performance critical (but not performance
critical enough to do in kernelspace), use ioperm/iopl and inb/outb.


--
Frank v Waveren Fingerprint: 21A7 C7F3
fvw@[var.cx|stack.nl|dse.nl] ICQ#10074100 1FF3 47FF 545C CB53
Public key: hkp://wwwkeys.pgp.net/[email protected] 7BD9 09C0 3AC1 6DF2

2003-09-26 07:27:44

by Benjamin Herrenschmidt

[permalink] [raw]
Subject: Re: How do I access ioports from userspace?

On Fri, 2003-09-26 at 07:26, Frank v Waveren wrote:
> On Thu, Sep 25, 2003 at 04:03:51PM -0700, Matthew Dharm wrote:
> > I'd like to be able to access some ioports to some custom hardware directly
> > from userspace, without creating a specialized kernel-level driver. Is
> > there a way to do that?
> Either use /dev/port, or if it's performance critical (but not performance
> critical enough to do in kernelspace), use ioperm/iopl and inb/outb.

Simple note: the above will work on x86 only...

Ben.



2003-09-26 07:41:20

by Benjamin Herrenschmidt

[permalink] [raw]
Subject: Re: How do I access ioports from userspace?

On Fri, 2003-09-26 at 09:34, Frank v Waveren wrote:
> On Fri, Sep 26, 2003 at 09:27:05AM +0200, Benjamin Herrenschmidt wrote:
> > Simple note: the above will work on x86 only...

> in[bwl]/out[bwl] are available on a lot more than just x86. Mind you, the
> mechanisms are subtly different. Then again, if you're using direct hardware
> access you're not going for portability anyway.

Are they from userland ? I doubt it...

Ben.


2003-09-26 07:34:15

by Frank v Waveren

[permalink] [raw]
Subject: Re: How do I access ioports from userspace?

On Fri, Sep 26, 2003 at 09:27:05AM +0200, Benjamin Herrenschmidt wrote:
> Simple note: the above will work on x86 only...
in[bwl]/out[bwl] are available on a lot more than just x86. Mind you, the
mechanisms are subtly different. Then again, if you're using direct hardware
access you're not going for portability anyway.

--
Frank v Waveren Fingerprint: 21A7 C7F3
fvw@[var.cx|stack.nl|dse.nl] ICQ#10074100 1FF3 47FF 545C CB53
Public key: hkp://wwwkeys.pgp.net/[email protected] 7BD9 09C0 3AC1 6DF2

2003-09-26 08:29:24

by Frank v Waveren

[permalink] [raw]
Subject: Re: How do I access ioports from userspace?

On Fri, Sep 26, 2003 at 09:40:42AM +0200, Benjamin Herrenschmidt wrote:
> > in[bwl]/out[bwl] are available on a lot more than just x86. Mind you, the
> > mechanisms are subtly different. Then again, if you're using direct hardware
> > access you're not going for portability anyway.
> Are they from userland ? I doubt it...
Have a look at your include files, they're defined everywhere, and defined
to something useful almost everywhere.

--
Frank v Waveren Fingerprint: 21A7 C7F3
fvw@[var.cx|stack.nl|dse.nl] ICQ#10074100 1FF3 47FF 545C CB53
Public key: hkp://wwwkeys.pgp.net/[email protected] 7BD9 09C0 3AC1 6DF2

2003-09-26 08:56:53

by Jes Sorensen

[permalink] [raw]
Subject: Re: How do I access ioports from userspace?

>>>>> "Ben" == Benjamin Herrenschmidt <[email protected]> writes:

Ben> On Fri, 2003-09-26 at 09:34, Frank v Waveren wrote:
>> in[bwl]/out[bwl] are available on a lot more than just x86. Mind
>> you, the mechanisms are subtly different. Then again, if you're
>> using direct hardware access you're not going for portability
>> anyway.

Ben> Are they from userland ? I doubt it...

Actually yes on some architectures, ia64 emulates it the ia32
API. That said, it's certainly not something one should be encouraged
to do, using MMIO is a far better approach.

Cheers,
Jes

2003-09-28 23:08:08

by Peter Chubb

[permalink] [raw]
Subject: Re: How do I access ioports from userspace?

>>>>> "Jes" == Jes Sorensen <[email protected]> writes:

>>>>> "Ben" == Benjamin Herrenschmidt <[email protected]> writes:
Ben> On Fri, 2003-09-26 at 09:34, Frank v Waveren wrote:
>>> in[bwl]/out[bwl] are available on a lot more than just x86. Mind
>>> you, the mechanisms are subtly different. Then again, if you're
>>> using direct hardware access you're not going for portability
>>> anyway.

Ben> Are they from userland ? I doubt it...

Jes> Actually yes on some architectures, ia64 emulates it the ia32
Jes> API. That said, it's certainly not something one should be
Jes> encouraged to do, using MMIO is a far better approach.

They're available at least in i386, alpha, ia64.
However they allow access only to the first 64k of IO address space.
So you may not be able to access you device if it's in the wrong PCI
slot...

--
Dr Peter Chubb http://www.gelato.unsw.edu.au peterc AT gelato.unsw.edu.au
You are lost in a maze of BitKeeper repositories, all slightly different.