LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices



Reply
 
Search this Thread
Old 07-22-2008, 08:10 PM   #1
stardust496
LQ Newbie
 
Registered: Jul 2008
Posts: 2

Rep: Reputation: 0
How to access device from user space process


Hello,

I have a conceptual question and hopefully this is the right forum for it!

In Linux, how can an user space process directly access a h/w device? (I know that a root process can do this)

Thanks a lot!!
 
Old 07-22-2008, 08:32 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
How a device can be accessed depends upon the device type. Typically, control is via ioctl() calls. Some devices have memory space that can be mapped into a user process, provided the process has permissions of course.

For devices with memory-mapped registers, the device's physical address range can be mapped directly into a user process.

Does this give you an idea?
 
Old 07-23-2008, 01:47 PM   #3
stardust496
LQ Newbie
 
Registered: Jul 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for the reply.

I conceptually do understand the idea of mapping the device's memory into user space memory. But what I don't understand is what happens next. If the process writes some data to that memory, how does the device know that there is some data waiting for it? The process can make an appropriate system call and let the kernel tell the device. But is it possible for the process to talk to the device directly without "kernel intervention".

Thanks!
 
Old 07-23-2008, 02:40 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
This is a wide question, because different device classes behave differently, and have different characteristics and abilities.

There are two ways for a process to cross the user/kernel space: data transfer via system calls or direct memory mapping.

When using memory mapping, there are obvious synchronization concerns, and one has to code properly to ensure that your user process does not interfere with the device driver/device interaction. Again, how this is done very much depends upon the device. Generally, this type of coding is done, for example, to read a device's EEPROM values, or blast screen data into a frame buffer.

The device and device drivers aren't usually sitting around waiting for user space data; rather, they react to events such as interrupts, and the interrupt handler for the device does what it needs to do. They also respond (indirectly) to system calls, dispatched into the appropriate standard device entry point (eg. ioctl, read, write, flush, seek, etc.).

Devices are controlled via various hardware registers: for example, set a bit, and they do something, set another bit and they do something else, read a register, and the device returns the value and clears a register (clear on read). Some devices such as Ethernet devices have rings of buffers, where network data is loaded into the next available ring buffer, and the ring buffer next/last pointer is updated, and then the device responds. There are all sorts of combinations. This may be what you mean by "talk" to the device without kernel intervention.

If you really have an interest in this stuff, consider getting the Linux device driver book (O'Reilly) and study some device drivers. It will also *require* that you read a device's specification and programming interface.

Last edited by Mr. C.; 07-23-2008 at 02:43 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to send events from kernel module to user space process yugandhar Linux - Kernel 2 02-21-2011 11:39 AM
User Space Device Driver Development ameya.verma Linux - Software 0 04-02-2008 03:26 AM
Interfacing a USB device driver into user space? ddraper Linux - Kernel 2 02-19-2008 05:33 PM
User Space Device Driver jvogel Linux - Kernel 4 10-16-2007 06:46 PM
user-space notification of USB device attached/detached rhardy Linux - Software 1 10-24-2006 04:17 PM


All times are GMT -5. The time now is 09:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration