Porting device drivers to the 2.6 kernel
The creation of these articles is funded by LWN.net subscribers. If you find this material useful, please consider subscribing to LWN to help ensure that more of it gets written.
Except when otherwise specified, all of the articles below are written by LWN editor Jonathan Corbet. The date and kernel version attached to each article notes when the article was last updated.
Recent changes
The most recent changes to this series are:
- (April 28, 2004) The Workqueue
Interface updated to include
create_singlethread_workqueue(), which was merged in 2.6.6.
- (January 6, 2004) Supporting mmap()
and Dealing with interrupts have been
updated to reflect API changes in 2.6.1.
- (November 25, 2003) The entire set of articles has been updated to reflect the 2.6.0-test10 kernel.
Getting started
Porting 'hello world' (February, 2003); which covers the changes required to update the simplest possible module to the 2.5 kernel.Compiling external modules (November, 2003; 2.6.0-test9); how to build modules with the new module loader and kernel build scheme.
More module changes (November, 2003, 2.6.0-test9) covers other changes to the module loading subsystem, including module parameters, use count management, exporting symbols, and more.
Miscellaneous changes is a collection point for changes which are too small to justify their own article. Currently covered topics include kdev_t, designated initializers, and min() and max(). It was last updated on November 3, 2003 (2.6.0-test9).
Support interfaces
Char drivers and large dev_t (November 2003, 2.6.0-test9); registration and management of char drivers in the new, large dev_t environment.The seq_file interface (September 2003; 2.6.0-test6); the easy way to implement virtual files correctly. A standalone example module is provided to demonstrate the use of this interface.
Low-level memory allocation (November, 2003; 2.6.0-test9); changes to functions for allocating chunks of memory and pages, and a description of the new mempool interface.
Per-CPU variables (November, 2003; 2.6.0-test9); the 2.6 interface for maintaining per-CPU data structures.
Timekeeping changes (November, 2003; 2.6.0-test9); changes to how the kernel manages time and time-related events.
The workqueue interface (April, 2004; 2.6.6-rc3); a description of the new deferred execution mechanism which replaces task queues (and bottom halves in general).
Creating virtual filesystems with libfs (November, 2003; 2.6.0-test9). This article, which looks at how a kernel module can create its own virtual filesystem, predates the driver porting series but fits in well with it.
DMA Changes (November, 2003, 2.6.0-test9); changes to the DMA support layer. There is also a quick reference page for the new generic DMA API.
Sleeping and mutual exclusion
Mutual exclusion with seqlocks (November, 2003, 2.6.0-test9); a description of how to use the seqlock (formerly frlock) capability which was merged into 2.5.60.The preemptible kernel (November, 2003; 2.6.0-test9); a look at how kernel preemption affects driver code and what can be done to work safely in the preemptible environment.
Sleeping and waking up (November, 2003; 2.6.0-test9); new ways of putting processes to sleep with better performance and without race conditions.
Completion events (November, 2003; 2.6.0-test9); documentation for the completion event mechanism.
Using read-copy-update (November, 2003; 2.6.0-test9); working with the read-copy-update mutual exclusion scheme.
Advanced driver tasks
Dealing with interrupts (January, 2004; 2.6.1-rc2); interrupt handling changes which are visible to device drivers.Supporting asynchronous I/O (November, 2003; 2.6.0-test9); how to write drivers which support the 2.6 asynchronous I/O interface.
Network drivers (November 2003, 2.6.0-test9); porting network drivers, with an emphasis on the new dynamic net_device allocation functions and NAPI support.
USB driver API changes (July 2003; 2.5.75); how USB drivers have changed in the 2.5 development series. This article was contributed by USB maintainer Greg Kroah-Hartman.
Block drivers
Block layer overview (November, 2003; 2.6.0-test9). The block layer has seen extensive changes in the 2.5 development series; this article gives an overview of what has been done while deferring the details for subsequent articles.A simple block driver (November, 2003; 2.6.0-test9); this article presents the simplest possible block driver (a basic ramdisk implementation) with discussion of how the basic block interfaces have changed in 2.6. Full source to a working driver is included.
The gendisk interface (November, 2003; 2.6.0-test9); how to work with the new generic disk interface, which takes on a rather larger role in 2.6.
The BIO structure (November, 2003; 2.6.0-test9); the new low-level structure representing block I/O operations.
Request queues I (November, 2003; 2.6.0-test9); the basics of block request queues in 2.6, including request processing, request preparation control, and DMA support.
Request queues II (November, 2003, 2.6.0-test9); advanced request queue topics, including command preparation, tagged command queueing, and the "make request" mode of operation.
Memory management
Supporting mmap() (January, 2004 - 2.6.1-rc2); changes in how device drivers support the mmap() system call.Zero-copy user-space access (November, 2003 - 2.6.0-test9); how to get direct-access to user space to perform zero-copy I/O. If you used the kiobuf interface for this purpose in 2.4, you'll want to look here for the 2.6 equivalent.
Atomic kmaps (November, 2003; 2.6.0-test9); quick access to high-memory via kmap_atomic().
Device model
A device model overview (November, 2003; 2.6.0-test10); an introductory look at the Linux device model and sysfs, with definitions of some commonly encountered terms.
The zen of kobjects (October, 2003; 2.6.0-test6); an attempt to demystify the kobject abstraction and its use in the kernel.
kobjects and sysfs (October, 2003; 2.6.0-test8); a description of the interaction between the kobject type and its representation in sysfs.
kobjects and hotplug events (October, 2003; 2.6.0-test6); an explanation of the kset hotplug operations and how they can be used to control how hotplug events are reported to user space. This article was written by Greg Kroah-Hartman.
Examining a kobject hierarchy (October, 2003; 2.6.0-test9); a visual exploration of the device model data structures behind /sys/block.
Device classes (November, 2003; 2.6.0-test10); how
the device class mechanism works.
Posted Feb 12, 2003 1:55 UTC (Wed)
by fdesloges (guest, #291)
[Link] (8 responses)
Posted Feb 12, 2003 9:58 UTC (Wed)
by KotH (guest, #4660)
[Link] (7 responses)
Yes, i know that LWN doesnt have as much subscribers as it should have :(
Posted Feb 12, 2003 11:00 UTC (Wed)
by bruno (subscriber, #4387)
[Link] (4 responses)
Posted Feb 12, 2003 14:14 UTC (Wed)
by Webexcess (guest, #197)
[Link] (3 responses)
I think you're oversimplifying a bit. The excellent writing at lwn.net is both its product and its advertising. How will potential subscribers be enticed if they can't see what lwn.net has to offer?
Also, the target audience largely consists of enthusiasts, many of whom are students and/or live in parts of the world where american dollars are very expensive. These are the same people that helped to build Linux into what it is today -- are you suggesting that they should be excluded?
Posted Feb 12, 2003 15:27 UTC (Wed)
by bruno (subscriber, #4387)
[Link] (2 responses)
If KotH really thinks that is important that this information be free, he can
Posted Feb 12, 2003 17:17 UTC (Wed)
by rknop (guest, #66)
[Link]
"You MUST give your work for free"... If KotH really thinks that is important that this information be free, Be fair. That's not what KotH said. He said he thought it was in LWN.net's best interest to do what they've done, because of their good reputation in the community. He's not insisting that they must do what they've done, he's just congratulating them and saying he understands why they might think it's a good idea to do that. -Rob
Posted Feb 12, 2003 19:52 UTC (Wed)
by Ross (guest, #4065)
[Link]
I think you are mischaracterizing what other people are saying. Using the device driver documentation as an advertisement was only a suggestion. We all recognize that LWN can decide what to release and when to release it. You're point is also only a suggestion. If Jonathan felt he needed to say something, I'm sure he would. You don't need to speak for him.
Posted May 8, 2003 17:05 UTC (Thu)
by LogicG8 (guest, #11076)
[Link] (1 responses)
Releasing quality content for free has nabbed at least one
Posted Dec 14, 2004 14:06 UTC (Tue)
by arafel (subscriber, #18557)
[Link]
Posted Feb 12, 2003 20:07 UTC (Wed)
by corbet (editor, #1)
[Link] (1 responses)
For what it's worth, I did consider keeping this material non-free for longer than the usual period. It is different from the usual news, and it has a slightly longer useful life. In the end, I decided against such a move; I would like these articles to be generally useful, and to serve as a contribution to the kernel project. Maintaining the same access policy also lets me fold some of the articles into the Kernel Page, which could use it - development news tends to slow down a lot during feature freezes.
So the driver porting articles go free after a week. We may yet do things differently for similar material in the future.
jon
Posted Dec 24, 2003 15:19 UTC (Wed)
by nhasan (guest, #1699)
[Link]
Posted Feb 27, 2003 15:20 UTC (Thu)
by materlik (guest, #6095)
[Link]
Posted Feb 28, 2003 20:09 UTC (Fri)
by vonbrand (subscriber, #4458)
[Link]
One minor gripe is that the articles don't default to a printable page format (yes, I do promise to buy the next book of yours regardless ;-)
Posted Jun 14, 2004 22:31 UTC (Mon)
by Marsclic (guest, #22294)
[Link] (2 responses)
Posted Oct 29, 2004 3:56 UTC (Fri)
by dkotian (guest, #25725)
[Link] (1 responses)
Posted Nov 8, 2004 18:49 UTC (Mon)
by gXyZOd (guest, #25922)
[Link]
I'm a n00b and am trying hard to learn.
Thanks for any response.
Posted Nov 26, 2004 3:30 UTC (Fri)
by prakash07 (guest, #26172)
[Link]
***parse error before dev_t;
i also added the <linux/fs.h> .
Posted May 6, 2005 21:56 UTC (Fri)
by prashy (guest, #29775)
[Link] (3 responses)
prcdd.c:6:1: warning: "__KERNEL__" redefined
This is the source code,
#if defined(CONFIG_MODVERSIONS) && ! defined(MODVERSIONS)
#define _KERNEL_
#include <linux/kernel.h>
//static int module_init(void);
#define SUCCESS 0
static int Major;
static struct file_operations fops = {
static int prcdd_init(void)
printk("<1>The assigned major number is %d \n",Major);
static void prcdd_exit(void)
static int prcdd_open(struct inode *inode, struct file *file)
MOD_INC_USE_COUNT;
static int prcdd_release(struct inode *inode, struct file *file)
MOD_DEC_USE_COUNT;
module_init(prcdd_init);
Any pointers on how to proceed from here?
Posted Apr 23, 2007 4:15 UTC (Mon)
by psh2001 (guest, #44808)
[Link] (2 responses)
Any one has any solutions for this ?
Thanks,
Posted Jun 1, 2007 8:09 UTC (Fri)
by hy71 (guest, #45546)
[Link]
thanks a lot!
Posted Jun 22, 2007 11:54 UTC (Fri)
by soorejp (guest, #38041)
[Link]
include/linux/cdev.h:24: warning: struct inode declared inside parameter list
I changed the order of header file definition from:
Posted May 13, 2005 14:33 UTC (Fri)
by tomek (guest, #29487)
[Link]
Posted Jun 15, 2005 16:59 UTC (Wed)
by DMXMusic (guest, #30434)
[Link] (1 responses)
Our company has something like 5000 of these modems on our devices in the field, and we need to support our customers.
Posted Aug 11, 2005 4:41 UTC (Thu)
by dabenavidesd (guest, #31733)
[Link]
Posted Aug 17, 2005 3:55 UTC (Wed)
by johnlin (guest, #31873)
[Link] (1 responses)
I got a problem proting device driver from 2.4 to 2.6, i.e. the asm/smplocak.h seems not in 2.6 kernel/include/asm, so could anyone help ?
Thanks
John
Posted Mar 14, 2006 10:43 UTC (Tue)
by Pype.Clicker (guest, #36458)
[Link]
Posted Jan 22, 2006 11:39 UTC (Sun)
by LSM (guest, #35368)
[Link]
Posted Feb 21, 2006 2:33 UTC (Tue)
by York (guest, #35984)
[Link]
Thank you!
Posted Feb 23, 2006 15:05 UTC (Thu)
by agllno (guest, #36084)
[Link]
Posted Mar 15, 2006 10:29 UTC (Wed)
by vikramkg82 (guest, #35972)
[Link]
i am new to device driver can any body tell me how to access the device file...exactly i need to access the harddisk inforamation at block level..or else can u tell where i can get the information about this plz
Posted May 3, 2006 17:37 UTC (Wed)
by vonbrand (subscriber, #4458)
[Link]
Some random comments...
Many thanks!
Posted Jan 30, 2011 17:37 UTC (Sun)
by coolaj86 (guest, #72649)
[Link]
I could swing a few subscribers for that privilege. Probably not enough to pay for the cost of time, but a few nonetheless.
Posted Jun 8, 2020 6:26 UTC (Mon)
by 卡卡罗特 (guest, #131501)
[Link]
Wow! Porting device drivers to the 2.5 kernel
This is highly valuable stuff. Are you certain you want to give this away
for free after only a few days ?
This alone would be a very good reason to subscribe. And as reference
stuff it will still be valuable many months down the road.
Maybe it could fit in a "available to non-subsciber 4 months later"
category ? Or make only a few articles available (and the index of course
to hook subscribers) ?
Whatever you do, thanks!
FD
I wouldnt do that. LWN has a very good reputation as information sourcePorting device drivers to the 2.5 kernel
around the open source community. A "closed for all but subscribed ppl"
policy would surely destroy that reputation.
but this is IMHO not the right way to get more.
Do you work for nothing? Do you give all your time to other in exchange Porting device drivers to the 2.5 kernel
of nothing? You can't pretend that other people do that, the people have
childrens, wives, mortgages... and work in exchange of money to pay their
bills. Sometimes you have a bussiness plan that lets you to give away
your work and get money from other sources, sometimes you need to put a
price or close the shop.
Do you work for nothing? Do you give all your time to other in exchange
of nothing?
Porting device drivers to the 2.5 kernel
The excellent writing at lwn.net is only possible if there are someone thatPorting device drivers to the 2.5 kernel
works in it full time. I think is wonderfull if someone can (and want) to
work full time in something and give it away for nothing, but I don't think
that you can say to someone "You MUST give your work for free", at the end
of the day, with your work you have the right to make whatever you want:
Give if for free, sell, rent, lease or burn it, is your work and your
decision.
study the linux kernel, write a book and put it on the web for free, instead
of criticise the actitude of lwn.net
Porting device drivers to the 2.5 kernel
Bruno,Re: Porting device drivers to the 2.5 kernel
I would just like to say that the release of this material promptedPorting device drivers to the 2.5 kernel
me to purchase a subscription. It is a delicate balance providing
open content and providing incentive to readers to subscribe. I think
that LWN has done a great job and will continue to do so in the future.
subscriber.
Make that two...Porting device drivers to the 2.5 kernel
Just as a response to all the comments here... I appreciate the input, and certainly do not feel criticized by any of the comments.
On whether this stuff should be free
How about releasing it as a book? It should provide additional revenue to LWN and give us a hard copy reference.
On whether this stuff should be free
You might think about adding a little, polite blurb asking for a small donation to the end of each article, similar to what tidbits (a free Macintosh newsletter) is doing with PayBits. Maybe one only visible to non-subscribers?
An idea that works elsewhere
Their experiences so far have not been overwhelming, but there is some money being donated because of the constant reminders on the value of filtered, edited information.
I think this deserves a place in the head of the page (perhaps replacing Old Site or Weekly edition). It is not a "Recent feature" anymore...Porting device drivers to the 2.5 kernel
This is the material that made me subscribe to this site. Keep it coming Jonnathan!
Porting device drivers to the 2.6 kernel
Porting drivers from kernel 2.4 to kernel 2.6,where can I find the documentsPorting drivers from kernel 2.4 to kernel 2.6,where can I find the documents
I'm looking for some information too.Porting drivers from kernel 2.4 to kernel 2.6,where can I find the documents
Seeing that devfs is obsolent I would have to port a module that implements a "Utime Calibration" (taken from the Kansas University Real Time patch) from the 2.4.18 to the 2.6.8/9 kernel.
Not using devfs any more in the 2.6 kernel the devfs_[register/unregister]_chrev functions are useless.
I am using the function Porting device drivers to the 2.6 kernel
alloc_chrdev_region(dev_t *dev,61,1,"prakash");
in module but while compilation it is giving the error.
please any one help me .
I am new to Linux Kernel Programming. Trying to build a basic char driver (register, open, release, unregister). When I compile the source I get the following errors, (even on kernel - 2.4). I try to compile the char drivers provided with the source and even get errors and warnings with them, here is the error dump,char device drivers on the 2.6 kernel
prcdd.c:1:1: warning: this is the location of the previous definition
prcdd.c:7:1: warning: "MODULE" redefined
prcdd.c:1:1: warning: this is the location of the previous definition
In file included from /usr/include/linux/fs.h:23,
from prcdd.c:11:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userland!
prcdd.c:12:25: asm/uaccess.h: No such file or directory
prcdd.c:17: warning: `struct file' declared inside parameter list
prcdd.c:17: warning: its scope is only this definition or declaration, which is probably not what you want
prcdd.c:17: warning: `struct inode' declared inside parameter list
prcdd.c:18: warning: `struct file' declared inside parameter list
prcdd.c:18: warning: `struct inode' declared inside parameter list
prcdd.c:26: variable `fops' has initializer but incomplete type
prcdd.c:27: unknown field `owner' specified in initializer
prcdd.c:27: warning: excess elements in struct initializer
prcdd.c:27: warning: (near initialization for `fops')
prcdd.c:28: unknown field `open' specified in initializer
prcdd.c:28: warning: excess elements in struct initializer
prcdd.c:28: warning: (near initialization for `fops')
prcdd.c:29: unknown field `release' specified in initializer
prcdd.c:29: warning: excess elements in struct initializer
prcdd.c:29: warning: (near initialization for `fops')
prcdd.c: In function `prcdd_init':
prcdd.c:34: warning: implicit declaration of function `register_chrdev'
prcdd.c:38: warning: implicit declaration of function `printk'
prcdd.c: In function `prcdd_exit':
prcdd.c:48: warning: implicit declaration of function `unregister_chrdev'
prcdd.c: At top level:
prcdd.c:55: warning: `struct file' declared inside parameter list
prcdd.c:55: warning: `struct inode' declared inside parameter list
prcdd.c:56: conflicting types for `prcdd_open'
prcdd.c:17: previous declaration of `prcdd_open'
prcdd.c: In function `prcdd_open':
prcdd.c:59: `EBUSY' undeclared (first use in this function)
prcdd.c:59: (Each undeclared identifier is reported only once
prcdd.c:59: for each function it appears in.)
prcdd.c:63: warning: implicit declaration of function `atomic_inc'
prcdd.c:63: union has no member named `usecount'
prcdd.c: At top level:
prcdd.c:67: warning: `struct file' declared inside parameter list
prcdd.c:67: warning: `struct inode' declared inside parameter list
prcdd.c:68: conflicting types for `prcdd_release'
prcdd.c:18: previous declaration of `prcdd_release'
prcdd.c: In function `prcdd_release':
prcdd.c:71: warning: implicit declaration of function `atomic_dec'
prcdd.c:71: union has no member named `usecount'
prcdd.c: At top level:
prcdd.c:26: storage size of `fops' isn't known
#include <linux/modversions.h>
#define MODVERSIONS
#endif
#define MODULE
#include <linux/module.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
//static void module_exit(void);
static int prcdd_open(struct inode *,struct file *);
static int prcdd_release(struct inode *,struct file *);
#define DEVICE_NAME "prcdd"
static int Device_open = 0;
.owner = THIS_MODULE,
.open = prcdd_open,
.release = prcdd_release,
};
{
Major = register_chrdev(0,DEVICE_NAME,&fops);
if (Major < 0)
{
printk("Registering the character device failed with %d \n",Major);
return Major;
}
return 0;
}
{
int ret = unregister_chrdev(Major,DEVICE_NAME);
if (ret < 0)
{
printk("Error in unregister_chrdev: %d \n",ret);
}
}
{
if (Device_open)
{
return -EBUSY;
}
Device_open++;
return SUCCESS;
}
{
Device_open--;
return 0;
}
module_exit(prcdd_exit);
Hi,char device drivers on the 2.6 kernel
even i am facing the same issue ...
Shiv
i am facing the same problem...char device drivers on the 2.6 kernel
could anyone give some suggestion?
I got these warnings:char device drivers on the 2.6 kernel
include/linux/cdev.h:24: warning: its scope is only this definition or declaration, which is probably not what you want
#include <linux/cdev.h>
#include <linux/fs.h>
to
#include <linux/fs.h>
#include <linux/cdev.h>
and the error gone
graphs over swearing in the linux kernel:
http://www.vidarholen.net/contents/wordcount/ Tom
swearing in the linux kernel
Here is our situation - we have a working 2.4 driver for the PCTel PCT789T chip/modem. I have been looking high and low for a 2.6 version of this driver, but nobody seems to have taken on the task of porting the driver. I'm wondering if anyone can give me a rough time estimate for porting this driver - (it's basically a serial port driver, the dsp code is in a proprietary lib file) - I have done a couple simple Unix / Linux drivers, and worked on windows display drivers for a couple years, although I have not worked on serial port drivers. Any help is very much appreciated!Porting PCTel modem driver to the 2.6 kernel
Thanks - Phil Brooks, Philip.Brooks@DMXMusic.com
Hi Phil.Porting modem drivers to the 2.6 kernel
A time ago, i tried to install a driver of my Intel 537 EP that is instaled on my ASUS board for AMD.
The driver was made for working on SuSE 9.1. However when trying to install in this OS, and compiling, following the specified steps, I've got 9 warnings.
The modem works perfectly under Windows XP (another company delivers the driver on CD besides the finished Intel chipset and other applications like Classic Phone Tools http://www.bvrp.com).
The driver is still hung in the Intel´s site, and this release supports 2.4.x and 2.6.x kernels.
Attached is my web site where is a historical record of the conversation between me and a support programmer from Intel Support Service; over all, we work in the makefile and correcting the files and dependencies of the used packages, although the trouble is still there.
Im interested in continue working about this kind of troubles. So let me know how can i help.
http://es.geocities.com/dabenavidesd/
email: dabenavidesd@unal.edu.co
Hello,Porting device drivers to the 2.6 kernel
it looks like the "Big Kernel Lock" headers have been moved from <asm/smplock.h> to <linux/smp_lock.h> between 2.4 and 2.6 ... patching the #include directive did it for me, i guess it will do for you aswell.Porting device drivers to the 2.6 kernel
This is the kind of stuff that made me subscribe to this community. Thanks Jonnathan!Porting device drivers to the 2.6 kernel
LSM Networks Blog
Dear Jonnathan:Porting device drivers to the 2.6 kernel
where are the differences between 2.4 and 2.6 about pci driver program?
How can I get the way to port a pci driver in 2.6?
Hi all,Porting device drivers to the 2.6 kernel
I want a small information about interruptible_sleep_on .I want it to make compatible for kernel version 2.6 from 2.2.So What modification i have to do or any altenatives are there. Please reply and give some details
Thanks in advance
Agnello
hiPorting device drivers to the 2.6 kernel
Porting device drivers to the 2.6 kernel
Update to 2.6.38
Porting device drivers to the 2.6 kernel