Linux Kernel interrupt handling process

Source: Internet
Author: User

This article post on: http://blog.csdn.net/swt914/article/details/6574458

Kernel interrupt handling Diagram

 

1. Linux defines the Interrupt Routine Descriptor Table named irq_desc: (include/linux/irq. h)

Struct irqdesc irq_desc [NR_IRQS];

NR_IRQS indicates the number of interrupt sources.

2. irq_desc [] is an array pointing to the irq_desc_t structure. The irq_desc_t structure is the descriptor of each device interruption service routine. The member action in the Irq_desc_t struct points to the irqaction struct linked list corresponding to the interrupt number. The Irqaction struct is defined as follows:

/* Include/linux/interrupt. h */
Struct irqaction {
Irq_handler_t handler;/* points to the interrupted service program */
Unsigned long flags;/* interrupt flag */
Unsigned long mask;/* Interrupt mask */
Const char * name;/* I/O device name
Void * dev_id;/* device ID */
Struct irqaction * next;/* points to the next descriptor */
Int irq;/* IRQ line */
Struct proc_dir_entry * dir;/* the descriptor pointing to the/proc/irq/n directory related to IRQn */
};

The key handler Member points to the interrupt service program of the device, which is established when request_irq is executed.

 

3. during driver initialization, if an interrupt is used, the request_irq () function is usually called to create the irqaction struct corresponding to the driver, register it with irq_desc [irq_num]-> action linked list. Iqr_num is the interrupt number applied by the driver.

The following is a prototype of the request_irq () function:

/* kernel/irq/manage.c */
int request_irq( unsigned int irq,
         irqreturn_t ( * handler) ( int , void * , struct pt_regs * ) ,
        unsigned long irqflags,
        const char * devname,
        void * dev_id) ;

 

The irq parameter is the device interruption identifier. when registering with the irq_desc [] array, it is used as the subscript of the array. Write the first address of the irqaction struct whose interrupt number is irq to irq_desc [irq]-> action. In this way, the device's interrupt request number is associated with the device's interrupt service routine irqaction.

 

In this way, after the CPU receives the interrupt request, it can find the interrupt service program of the device through irq_desc [] based on the interrupt number. Shows the process.

 

4. Shared interruptions

The iqraction struct of different devices that share the interrupt will be added to the irqaction linked list pointed by the action Member of the irq_desc struct corresponding to the interrupt number. When the kernel is interrupted, it calls all handler functions in the linked list in turn. Therefore, if the driver needs to use the shared interrupt mechanism, the interrupt handler must be able to identify whether its own hardware is interrupted. It is usually determined by reading the interrupt flag provided by the hardware device.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.