Skip to contentSkip to conversation

How do I access ioports from userspace?

DISCUSSION Matthew Dharm 6 participants 9 messages Sep 25, 2003 – Sep 28, 2003

lore
Share & tools
lore
#0 lore raw

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

Signature · 7 lines
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
#1 lore raw
Quoted 3 lines · Matthew Dharm

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?

#2 lore raw
In reply to Matthew Dharm
Quoted 3 lines · Matthew Dharm

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.

Signature · 3 lines
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
#3 lore raw
Quoted 6 lines · Frank v Waveren
Quoted 3 lines · Matthew Dharm

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.

#4 lore raw
Quoted 1 line · Benjamin Herrenschmidt

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.

Signature · 3 lines
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
#5 lore raw
Quoted 6 lines · Frank v Waveren
Quoted 1 line · Benjamin Herrenschmidt

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.

#6 lore raw
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines

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.

Signature · 3 lines
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
#7 lore raw
In reply to Benjamin Herrenschmidt
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

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

Quoted 4 lines · Frank v Waveren
Quoted 4 lines

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

#8 lore raw
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

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

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

Quoted 4 lines · Frank v Waveren
Quoted 4 lines
Quoted 4 lines

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.