Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

developerWorks Community:

  • Close [x]

IBM AIX device driver development

A tutorial on AIX device driver framework and related APIs

Gautam Raut (gautraut@in.ibm.com), Senior Software Engineer, IBM
Gautam
Gautam Raut works as a Senior Software Engineer for the Andrew File System (AFS) Team at the IBM Software Labs in Pune, India. He works with kernel and user-level debugging of dumps and crashes, as well as reported bugs on the Linux and AIX platforms. He has also worked on various AFS-specific AIX kernel components. Gautam holds M.S. in Computer Science from the University of Pune. He is a Linux enthusiast who spends his spare time exploring the Linux kernel on his Fedora 8 box.

Summary:  This tutorial illustrates the IBM® AIX® device driver framework and related application programming interfaces (APIs). Here, we shall discuss about the device switch structure, API to register device switch methods, major and minor number management, and moving data from kernel to user space.

Date:  28 Mar 2013
Level:  Intermediate PDF:  A4 and Letter (244 KB | 15 pages)Get Adobe® Reader®

Activity:  20933 views
Comments:  

Device driver basics

Major and minor numbers

Devices are treated as special files under the /dev directory. Hence, every device has a name and an associated inode or index node under its root file system. The file system entry point of every device contains major and minor numbers.

A major number is used to find this device uniquely in the system. It is an index into device switch table. Device switch table contains pointers to the device-specific methods that are essentially implementations of generic file system functions. In this manner, a file system call issued by a user process on a given device is resolved into a call to the appropriate device driver function. A minor number is used by the driver internally to distinguish between logical channels for multiplexed devices.

A major number can be obtained by a library call, genmajor().

Syntax of genmajor() is:

	int genmajor(char* name_of_device_driver)

A minor number can be obtained by a library call, genminor().

It generates either the smallest unused minor number available for a device, a preferred minor number if it is available, or a set of unused minor numbers for a device.

Syntax of genminor() is:

int *genminor (
 char * device_instance,
 /*
 Points to a character string containing the device instance name.*/
 int major_no,
 /*
  The major number of the device instance.*/
 int preferred_minor,
 /*
  Contains a single preferred minor number or a starting  
minor number for generating a set of numbers. */
 int minors_in_grp,
 /*
 Indicates how many minor numbers are to be allocated.	*/
 int inc_within_grp,
 /*
 Indicates the interval between minor numbers.*/
 int inc_btwn_grp
 /*
 Indicates the interval between groups of minor numbers.*/
);


makedev() API

Major and minor numbers for a given device needs to be packaged into a 32- or 64-bit integer, depending on the architecture. This integer has a data type dev_t. makedev() is a macro that creates dev_t from the given major and minor numbers. It is defined under <sys/sysmacros.h>. makedev64() is used to create dev_t for a 64-bit environment.

Syntax of makedev() or makedev64() is:

 dev_t makedev64(int major, int minor);


mknod() system call

It is defined in <sys/stat.h>. It is used to create an ordinary file, first-in-first-out (FIFO), or a special file. It requires root privilege to use mknod() to create a device special file.

Syntax of mknod() is:

 int mknod (
  char *Path,
  /*
   Names the new device special file.
  */
  int Mode,
  /*
   Specifies the file type, attributes, and access
   permissions.
  */
  dev_t Device
  /*
   Device number generated by makedev() subroutine.
  */
 );

5 of 15 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=AIX and UNIX, Linux
ArticleID=861832
TutorialTitle= IBM AIX device driver development
publish-date=03282013
author1-email=gautraut@in.ibm.com
author1-email-cc=