EmbLogic's Blog

Sbull open

Once sbull_open has its device structure pointer, it calls del_timer_sync to remove the
“media removal” timer, if any is active. Note that we do not lock the device spinlock
until after the timer has been deleted; doing otherwise invites deadlock if the timer
function runs before we can delete it. With the device locked, we call a kernel func-
tion called check_disk_change to check whether a media change has happened.

Posted in Uncategorized | Leave a comment

Basic request queue function

Queue creation and deletion
request_queue_t *blk_init_queue(request_fn_proc *request, spinlock_t *lock);

 

The arguments are, of course, the request  function for this queue and a spinlock that controls access to the  queue. 

This function allocates memory (quite a bit of memory,  actually) and can fail because of this; you should

 always check the  return value before attempting to use the queue.
 As part of the initialization of a request queue, you can set the  field queuedata 
(which is a void  * pointer) to any value you like. This field is the request  
queue's equivalent to the  private_data we have seen in other structures. 
To return a request queue to the system (at module unload time,  generally), call  blk_cleanup_queue :
 void blk_cleanup_queue(request_queue_t *);

After this call, your driver sees no more requests from the given  
queue and should not reference it again.
Posted in Uncategorized | Leave a comment

elv_next_request of block driver

The kernel provides the function elv_next_request to obtain the first incomplete
request on the queue, that function returns NULL when there are no requests to be
processed. Note that elv_next_request does not remove the request from the queue. If
you call it twice with no intervening operations, it returns the same request struc-
ture both times.

Posted in Uncategorized | Leave a comment

Basic block request flow

In block driver request function check whether request is valid or not as per filesystem request.

void request(request_queue_t *queue);

After validation ,it calls transfer function to perform the write or read operation.

sbull_transfer(dev, req->sector, req->current_nr_sectors,

                req->buffer, rq_data_dir(req));
Posted in Uncategorized | Leave a comment

Block driver main structure

struct sbull_dev {

        int size;                       /* Device size in sectors */

        u8 *data;                       /* The data array */

        short users;                    /* How many users */

        short media_change;             /* Flag a media change? */

        spinlock_t lock;                /* For mutual exclusion */

        struct request_queue *queue;    /* The device request queue */

        struct gendisk *gd;             /* The gendisk structure */

        struct timer_list timer;        /* For simulated media changes */

};

Among these member struct request_queue and struct gendisk are the main 
structure.
Posted in Uncategorized | Leave a comment

Gendisk structure

struct gendisk (declared in <linux/genhd.h>) is the kernel’s representation of an indi-
vidual disk device. In fact, the kernel also uses gendisk structures to represent parti-
tions, but driver authors need not be aware of that. There are several fields in struct
gendisk that must be initialized by a block driver.

Posted in Uncategorized | Leave a comment

Block Driver

After character devices and network devices, block devices
are another important device type of any system
?Block Devices are used for the storage of application code and data, and user
data, they are often critical to the overall performance of the
system

To manage block device, a dedicated subsystem, the block layer is in charge of
managing the block devices, together with hardware specific
device drivers

Block devices can accessed from /dev or /sys/block/

Posted in Uncategorized | Leave a comment

IDT Table

The IDT is stored in the idt_table table, which includes 256 entries. The 6-byte
idt_descr variable specifies both the size of the IDT and its address, it is used only when the
kernel initializes the idtr register with the lidt Assembly instruction. In all other cases, the
kernel refers to the idt variable to get the address of the IDT.

Posted in Uncategorized | Leave a comment

Interrupt gate

An Intel interrupt gate that cannot be accessed by a User Mode process (the gate’s
DPL field is equal to 0). All Linux interrupt handlers are activated by means of
interrupt gates, and all are restricted to Kernel Mode.

Posted in Uncategorized | Leave a comment

Modules vs Programs Modules vs Programs

A program usually begins with a main() function, executes a bunch of instructions and terminates upon completion of those instructions. Kernel modules work a bit differently. A module always begin with either the init_module or the function you specify with module_init call. This is the entry function for modules; it tells the kernel what functionality the module provides and sets up the kernel to run the module’s functions when they’re needed. Once it does this, entry function returns and the module does nothing until the kernel wants to do something with the code that the module provides.

All modules end by calling either cleanup_module or the function you specify with the module_exit call. This is the exit function for modules; it undoes whatever entry function did. It unregisters the functionality that the entry function registered.

Every module must have an entry function and an exit function. Since there’s more than one way to specify entry and exit functions.

Posted in Uncategorized | Leave a comment

How Do Modules Get Into The Kernel

When the kernel needs a feature that is not resident in the kernel, the kernel module daemon kmod ‘execs’ modprobe to load the module in. modprobe is passed a string in one of two forms:

* A module name like softdog or ppp.
* A more generic identifier like char-major-10-30.

If modprobe is handed a generic identifier, it first looks for that string in the file /etc/modprobe.conf. If it finds an alias line

Next, modprobe looks through the file /lib/modules/version/modules.dep, to see if other modules must be loaded before the requested module may be loaded. This file is created by depmod -a and contains module dependencies.

Lastly, modprobe uses insmod to first load any prerequisite modules into the kernel, and then the requested module. modprobe directs insmod to /lib/modules/version/

Posted in Uncategorized | Leave a comment

8051 programming in c

If we need to refer to single bit of controller then syntax is

sbit led p1^1;

then change in led variable reflect on 1 pin of p1 port

Posted in Uncategorized | Leave a comment

Interrupt Handling

All interrupt handlers perform the same four basic actions:
1. Save the IRQ value and the registers contents in the Kernel Mode stack.
2. Send an acknowledgment to the PIC that is servicing the IRQ line, thus allowing it to
issue further interrupts.
3. Execute the interrupt service routines (ISRs) associated with all the devices that share
the IRQ.
4. Terminate by jumping to the ret_from_intr( ) address.

Posted in Uncategorized | Leave a comment

3d globe

In 3d globe ,u need to calculate time slot using rpm of the machine.with this u can calculate which leds needs to be lighted up at that particular instant

Posted in Uncategorized | Leave a comment

Interrupt Descriptor table

A system table called Interrupt Descriptor Table (IDT) associates each interrupt or exception vector with the address of the corresponding interrupt or exception handler. The IDT must be properly initialized before the kernel enables interrupts.
The IDT format is similar to that of the GDT and of the LDTs  each entry corresponds to an interrupt or an exception vector and consists of an 8-byte descriptor.
Thus, a maximum of 256x 8=2048 bytes are required to store the IDT.

Posted in Uncategorized | Leave a comment