13.linux Interrupt Handler

Source: Internet
Author: User

Linux Interrupt handlers

First, interrupt processing process

Enter ENTRY-ARMV in the Linux kernel code. S directory:

  

Linux Unified Portal: __irq svc.

After entering the unified portal, the program jumps to the Irq_handler designator (indicated on the same file):

  

And Irq_handler actually calls the above Arch_irq_handler_defualt. The code is in ENTRY-MACRO-MULTI.S.

  

In this interrupt handler. The most important thing is that get_irqnr_and_base gets the interrupt source that generated the interrupt and searches for the macro. Here is an example of 2410 (no 6410 found):

  

See from the program above. He mostly gets the interrupt number that generated the interrupt. Once the interrupt number is obtained, it jumps to: Asm_do_irq in Arch_irq_handler_defualt to handle interrupts:

  

After jumping to this function, the GENERIC_HANDLE_IRQ (IRQ) function is called:

  

This function will then call the GENERIC_HANDLE_IRQ_DESC function:

  

In this function will call the DESC structure, where the HANDLE_IRQ is a function pointer

Summary: In Linux: When there is an interruption, there will be a unified portal, Irq_svc. When you come in, the first step is to get the number that generates the interrupt source, and then find the IRQ_DESC structure based on the interrupt number. Then take out the pre-prepared registration handler in this structure.

To support interrupt handling, our driver must first implement an interrupt handler. The second is to register the interrupt handler function.

Second, interrupt processing program design

  

2.1 Interrupt Registration

The REQUEST_IRQ function is used to register interrupts.

int int void (*handler) (intvoidstructlongconstcharvoid*dev_id)

Returns 0 indicates success, or returns an error code

unsigned int IRQ interrupt number.

void (*handler) (int,void *) interrupt handler function.

Unsigned long flags various options related to interrupt management

In the flags parameter, you can select some options related to interrupt management, such as:irqf_disabled (sa_interrupt) If the bit is set, the expression is a "fast" interrupt handler, and if this is not set, then a "slow" Interrupt handler. irqf_shared (SA_SHIRQ) This bit indicates that the interrupt number is shared by multiple devices.

const char * devname device Name

VOID*DEV_ID used when sharing interrupts.

The main difference between a fast/slow interrupt is that a fast interrupt guarantees the atomicity of the interrupt processing (not interrupted), while a slow interrupt is not guaranteed. In other words, the "on interrupt" flag bit (processor if) is turned off when the fast-breaking handler is run, so when the service is interrupted it is not interrupted by other types of interrupts, while the other types of interrupts can still be serviced when slow interrupt processing is invoked.

2.2 Interrupt Handlers

The special point of an interrupt handler is that it runs in the context of an interrupt, and its behavior is subject to certain limitations:

1. Cannot use functions that may cause blocking
2. Cannot use functions that may cause scheduling

  

3.3 Interrupt Logoff

When the device no longer needs to use interrupts (usually when the drive is unloaded), you should log them off and use the function:

void Free_irq (unsigned int IRQ, void*dev_id)

DEV_ID refers to the number of functions in the interrupt to be written off.

13.linux Interrupt Handler

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.