Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-10-2007, 04:55 PM   #1
LQ Newbie
Registered: Sep 2006
Distribution: Mint64 w/KDE
Posts: 17

Rep: Reputation: 0
How can a driver in priviledged mode block?

I am working on an embedded system that uses an ARM processor, but this question applies to others too, I think.

I am writing a driver for a device, and I want to allow blocking and non-blocking reads and writes. In my system, the driver code is executed in the supervisor mode of the processor, and the driver code is executed via a software interrupt which switches from user mode to supervisor mode in library calls.

Also, in my system a task switch cannot occur unless the CPU is in the user mode.

My question is this: if the driver is blocking, then the CPU is stuck waiting in the supervisor mode, and I can't switch processes, so how do blocking I/O's happen in this or any system in a driver which is waiting in supervisor mode?

I'm sure the answer is simple and obvious, but I'm just not seeing it.

I considered adding a routine to the library calls that polls the driver which executes only in non-blocking mode, but this seems clunky, and I haven't seen any examples or documentation where this is done.

I also considered adding wrapper functions in the driver code for user-mode access, but this again seems clunky and I haven't seen it done elsewhere.

Old 03-12-2007, 07:13 PM   #2
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,578

Rep: Reputation: 191Reputation: 191
The main thing is the function the driver runs to wait for the event (finished transfer and so on). It should not be a simple while loop (in fact it can be, if you know that the delay will be very short). Instead, you may mark the process structure somehow (usually a flag) so it will not be waken up in a normal way. Then the function causes the system to switch process to a different one.

Your orginal process can be woken up (finish the blocking function) as a result of an interrupt (or timeout, which you have probably as interrupt). Now, the interrupt routine removes the flag. It doesn't have to switch the process, it will work as usual.

If you look into that it's not that different from nonblocking mode. In fact, it is the same, but there's just a different way of handling the situation when interesting even occurs.
Old 03-20-2007, 11:17 AM   #3
LQ Newbie
Registered: Sep 2006
Distribution: Mint64 w/KDE
Posts: 17

Original Poster
Rep: Reputation: 0
Ah! of course

Ah, of course! Thanks very much. I'll name a volatile char after you!


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
problem with read call for block driver & numsectors urwithsudheer Programming 0 04-07-2006 09:10 AM
How to allocate a block of 16MB in kernel space using my driver module s_anumolu Linux - General 1 07-15-2005 01:48 AM
Why The block driver I wrote can't read? freasy Programming 2 07-17-2004 07:50 AM
cdrecord works for root, but not non-priviledged user mpdegroat Linux - Software 3 05-24-2004 12:15 PM
Hard disk now displaying "not a valid block device" when booting in rescue mode alphasure Linux - Hardware 4 06-05-2003 08:49 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:52 PM.

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