EmbLogic's Blog

DEVICE DRIVER

Character Device Driver: In order to create a link between your device means your hardware either it is internal or externally attached and user application we need a set of rules which will define how your concerned device shall deal with application make sure user will get a satisfactory output as desired.

First let me give you a brief idea of architecture which helped me to create my device driver. Its is mainly divided in two basic parts first one is know as your USER LEVEL where application runs and the 2nd is your KERNEL LEVEL where your device driver is defined.

This is how a link is created between application and device through device driver.

APPLICATION——->NODE——>DEVICE DRIVER——–> DEVICE

NODE is an interface between USER LEVEL and KERNEL LEVEL..

There are few kernel defined structure and rest are user defined structure through which we can define the functionality of our device driver.

KERNEL DEFINED STRUCTURE– 1->Struct File 2->struct Inode 3->Cdev. etc

USER DEFINED STRUCTURE– 1->struct ScullDev 2-> struct Scullqset 3->struct file operations.

Lets look how all these all structure works one by one.

Scull is a memory space which is allocated in machine memory to your device. in scull we have two vital structure know as struct Sculldev and struct Scullqset. The former one is the starting point of scull as well as contains data about all the scullqset present in your scull in a way it contains metadata. its member are as fallow- 1-*scullqset 2-no of scullqset 3-datasize 4-quantum size 5-device size. and last but not the least  struct Cdev.

The later one Scullqset is a structure which store data or information. it mainly has two member first one is a pointer to next scullqset and the second one double pointer to y.our data, means first it will point to an array of pointer known as qset ,contains the add of quantum where actually our data is kept.

Struct file operations-> it generally defines the behavior of our device. it is used here to map the user level system calls to programmer defined system calls. some system calls are OPEN,CLOSE,WRITE,READ… etc

Struct Cdev—> it mainly has three member 1st one is owner which specifies about its owner name 2nd is a pointer to file operation,3rd to dev which contains major and minor no. now what is this major and minor no. lets have a look before we proceed further

Major no is a number which is given to each and every device driver we have in our machine and minor no is the number which represents your the device associated with that particular device driver. struct Cdev is your device representation in kernel Space.

Now comes kernel level structures into picture. STRUCT INODE .. as we all know that in linux everything is file either it is a text file, some kind of code or any device with each and every file there is an associated inode structure , here we will mainly concentrate and concerned about which is particularly represents our device. “inode is the only way through which we can or its better to say our application can interact with our device. main member are i_cev which points to your struct cdev. pointer to file operations.

Struct file-> members are *f_pos which takes the account of the cursor in your file. pointer to file operations , *private data which will help us to do mapping from your user level to kernal level as its stores the address of your SCULL so we can access all the data which we have stored in quantum part of scullqset from user level. this is all about the architecture now lets have  look on the operations or working.

STEPS TO BE FOLLOWED:

1. Insmod which will load our module, module is a source code which is loaded on demand.

2. Registration:register our device driver and device so that DD will get a major number and device gets its own minor number.

3.Allocation: Allocate space to Scull in machine memory.

4.Initialize Scull–> cdev_init— create link between struct inode and struct cdev… define owner.. cdev_add make attribute of device available to our kernael.

5. Sculldev initiallization: define size of qset,quantun,device..etc

6. Scull Trim. flash data if present in the memory space which is assigned to scull

7.Open: define open system call.

8. Write: before doing that allocate space to Scullqset then to qset and at last to quantum now we can write data to our quantum, LSEEK if needed.

9. Read: read whatever you have written to quantum.

10. Release: de-allocate all the space, unregister your device and DD, remove your module

Character Device Driver: In order to create a link between your device means your hardware either it is internal or externally attached and user application we need a set of rules which will define how your concerned device shall deal with application make sure user will get a satisfactory output as desired.

First let me give you a brief idea of architecture which helped me to create my device driver. Its is mainly divided in two basic parts first one is know as your USER LEVEL where application runs and the 2nd is your KERNEL LEVEL where your device driver is defined.

This is how a link is created between application and device through device driver.

APPLICATION——->NODE——>DEVICE DRIVER——–> DEVICE

NODE is an interface between USER LEVEL and KERNEL LEVEL..

There are few kernel defined structure and rest are user defined structure through which we can define the functionality of our device driver.

KERNEL DEFINED STRUCTURE– 1->Struct File 2->struct Inode 3->Cdev. etc

USER DEFINED STRUCTURE– 1->struct ScullDev 2-> struct Scullqset 3->struct file operations.

Lets look how all these all structure works one by one.

Scull is a memory space which is allocated in machine memory to your device. in scull we have two vital structure know as struct Sculldev and struct Scullqset. The former one is the starting point of scull as well as contains data about all the scullqset present in your scull in a way it contains metadata. its member are as fallow- 1-*scullqset 2-no of scullqset 3-datasize 4-quantum size 5-device size. and last but not the least  struct Cdev.

The later one Scullqset is a structure which store data or information. it mainly has two member first one is a pointer to next scullqset and the second one double pointer to y.our data, means first it will point to an array of pointer known as qset ,contains the add of quantum where actually our data is kept.

Struct file operations-> it generally defines the behavior of our device. it is used here to map the user level system calls to programmer defined system calls. some system calls are OPEN,CLOSE,WRITE,READ… etc

Struct Cdev—> it mainly has three member 1st one is owner which specifies about its owner name 2nd is a pointer to file operation,3rd to dev which contains major and minor no. now what is this major and minor no. lets have a look before we proceed further

Major no is a number which is given to each and every device driver we have in our machine and minor no is the number which represents your the device associated with that particular device driver. struct Cdev is your device representation in kernel Space.

Now comes kernel level structures into picture. STRUCT INODE .. as we all know that in linux everything is file either it is a text file, some kind of code or any device with each and every file there is an associated inode structure , here we will mainly concentrate and concerned about which is particularly represents our device. “inode is the only way through which we can or its better to say our application can interact with our device. main member are i_cev which points to your struct cdev. pointer to file operations.

Struct file-> members are *f_pos which takes the account of the cursor in your file. pointer to file operations , *private data which will help us to do mapping from your user level to kernal level as its stores the address of your SCULL so we can access all the data which we have stored in quantum part of scullqset from user level. this is all about the architecture now lets have  look on the operations or working.

STEPS TO BE FOLLOWED:

1. Insmod which will load our module, module is a source code which is loaded on demand.

2. Registration:register our device driver and device so that DD will get a major number and device gets its own minor number.

3.Allocation: Allocate space to Scull in machine memory.

4.Initialize Scull–> cdev_init— create link between struct inode and struct cdev… define owner.. cdev_add make attribute of device available to our kernael.

5. Sculldev initiallization: define size of qset,quantun,device..etc

6. Scull Trim. flash data if present in the memory space which is assigned to scull

7.Open: define open system call.

8. Write: before doing that allocate space to Scullqset then to qset and at last to quantum now we can write data to our quantum, LSEEK if needed.

9. Read: read whatever you have written to quantum.

10. Release: de-allocate all the space, unregister your device and DD, remove your module

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>