flat assembler
Message board for the users of flat assembler.

Index > Linux > Direct hardware access [Bit off-topic]

Author
Thread Post new topic Reply to topic
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade 21 Oct 2004, 12:31
Hey,
This is a bit off topic, but i was wondering whether direct hardware in linux was possible, for anything that is (PCI-Eth/Audio, DGA, etc)..

Is everything possible through ports, just out/in to certain ports, or through memory access?

(This isnt vital, just had an interest on the subject, so decided to ask. The linux forum is too quiet anyway Very Happy)

Thanks in advance,
Gunblade
Post 21 Oct 2004, 12:31
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 21 Oct 2004, 12:38
It is possible to do direct hardware access, but it's not easy Sad You have to use IOCTL's to set permissions, and quite possibly run the program as root. If you write a kernel module, it should be easier (though you do risk killing the kernel if you're not careful)
Post 21 Oct 2004, 12:38
View user's profile Send private message Visit poster's website Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade 21 Oct 2004, 12:42
Now thats a bloody quick answer Very Happy

So the best idea for direct access is making a kernel module?
Is there not another way of making a program execute with the permissions of the kernel? Confused

Thanks,
Gunblade
Post 21 Oct 2004, 12:42
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 21 Oct 2004, 14:09
Quote:
So the best idea for direct access is making a kernel module?


Yes.

Quote:
Is there not another way of making a program execute with the permissions of the kernel?


Not that I'm aware of. You can use IOCTL's (fairly difficult IIRC) to request read/write permission for specific ports and possibly memory ranges, but it's not easy. They aren't well documented, and you may still have to use the files in /dev for some hardware. Keep in mind that Linux (and most other modern OSes) are designed to keep hardware access from userspace to a minimum.
Post 21 Oct 2004, 14:09
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 31 Oct 2004, 11:28
Quote:
So the best idea for direct access is making a kernel module?


x11/x* is not kernel module but it's popular.

it is user-mode device driver.
so it doesn't care about kernel like openbsd, freebsd, linux, hurd, macosx, ...

--
Post 31 Oct 2004, 11:28
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 31 Oct 2004, 12:48
Does X11 directly access the hardware? I *know* that you can use IOCTL's to gain access to specific areas of the hardware, but full, unrestricted access is limited to kernel space. IOCTL's are a pain to use; which is why I suggest making a kernel module if you need direct hardware access.
Post 31 Oct 2004, 12:48
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 31 Oct 2004, 13:35
no it isn't.
x11/x* use linux's system-call.
these 250 system-call(x86) units can access to the abstract hardware.

But, in unix(monolithic) environment, it's meaningless to classify system programming and application programming, the mechanism is different, everything is file/(c programming dmr, ken)
..

--
Post 31 Oct 2004, 13:35
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 215
Location: Budapest, Hungary
Endre 03 Jan 2005, 14:36
gunblade wrote:
Hey,
This is a bit off topic, but i was wondering whether direct hardware in linux was possible, for anything that is (PCI-Eth/Audio, DGA, etc)..

Is everything possible through ports, just out/in to certain ports, or through memory access?


1.) Check out functions ioperm and iopl. With these functions (syscalls) you can get right for access to IO ports (see in/out assembly instructions).

2.) When communicating to the device, you likely need a contiguous memory place in order to serve the DMA transfer. Since you are in user space thus you are in virtual-address space. That is the virtual (or linear) addresses you see are not equal to physical ones the device needs, not speaking about that the memory you see to be virtually contiguous can physically be fregmented which is not what you want.
Here is a kernel patch I used when writing NIC drivers for MenuetOS. With this you can reach your aims, however I was able to allocate merely 4K (one page), but fortunately it was enough for me and at least I could supply DMA with it. Maybe it have been improved since then.
http://www.gelato.unsw.edu.au/IA64wiki/UserLevelDrivers

Endre.
Post 03 Jan 2005, 14:36
View user's profile Send private message Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade 06 Jan 2005, 01:55
thank you very much Endre,
that link proved very useful

And yeah, so now i see, its either a kernel device driver, or ioctl.
So thank you again Very Happy


gunblade
Post 06 Jan 2005, 01:55
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.