Linux interrupt implementation method (III): Interrupt Processing Model

Source: Internet
Author: User

Linux interrupt implementation method (III): Interrupt Processing Model

Iv. Interrupt Processing Model
To understand the relationship between desc-> handle_irq (IRQ, DESC) and the interrupt we registered, we need to understand the interrupt processing model.

4.1 Interrupt Processing Model Structure
Shows the interrupt processing model,
 
Nr_irqs indicates the maximum interrupt number, which is defined in include/ASM/ARCH/IRQ. h.
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 in include/Linux/interrupt. H, as follows:
Truct irqaction {
Irq_handler_t handler; // interrupt handler, provided during registration
Unsigned long flags; // interrupt flag, provided during registration
Cpumask_t mask; // Interrupt Mask
Const char * Name; // interrupt name
Void * dev_id; // The device ID. This topic describes the role of this parameter in detail when you interrupt sharing.
Struct irqaction * Next; // If the sharing is interrupted, continue,
Int IRQ; // interrupt number, provided at registration
Struct proc_dir_entry * dir; // descriptor pointing to the/proc/IRQ/n directory related to irqn
};

When registering an interrupt service program whose interrupt number is IRQ, the system encapsulates the corresponding irqaction struct based on the registration parameters. Write the irqaction struct with the interrupt number IRQ into irq_desc [IRQ]-> action. In this way, the device's interrupt request number is associated with the device's interrupt service routine irqaction. After the CPU receives the interrupt request, it can use the interrupt number irq_desc [] to find the interrupt service program of the device.

4.2 Handling Model of Interrupt sharing
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 Flag provided by the hardware device. That is to say, not any device can be used as the interrupt sharing source. It must be able to determine whether an interruption has occurred through its interrupt flag.
The registration method for interrupted sharing is as follows:
Int request_irq (unsigned int IRQ, irq_handler_t handler,
Ir1__shared, const char * devname, void * dev_id)

As mentioned in many authoritative documents, the dev_id parameter in the registration function that interrupts shared registration is essential and the value of dev_id must be unique. So what exactly is the use of the unique dev_id value provided here?

Based on our previous interrupt model knowledge, we can see that when an interrupt occurs, the kernel does not determine which device on the shared interrupt line has an outage, it cyclically executes all the interrupt processing functions (irqaction-> handler functions) for online registration of the interrupt ). Therefore, the irqaction-> handler function is responsible for identifying whether your hardware device has encountered an interruption and then executing the interrupt processing function. It is usually determined by reading the interrupt flag Flag provided by the hardware device. Now that the kernel cyclically executes all irqaction-> handler functions for online registration of the interrupt, it submits the process of identifying which hardware device has an interrupt to the interrupt handler itself, what is the use of the dev_id parameter of request_irq?

We recommend that you use the device structure pointer as the dev_id parameter in many documents. When the interruption arrives, the dev_id parameter passed in the hardware register is quickly used to determine whether the device is interrupted. If not, return quickly. There is no problem with this statement, and it is also the method we follow during programming. But in fact, it does not indicate why dev_id must be set to interrupt sharing.

The following explains why the dev_id parameter is required and must be unique.

When calling free_irq to deregister the interrupt processing function (the interrupted processing function is also deregistered when the driver is uninstalled), because dev_id is unique, therefore, it can be used to determine how to delete a specified interrupt handler from multiple interrupt handlers on the shared interrupt line. Without this parameter, it is impossible for the kernel to know which handler is to be deleted for the given interrupt line.

The deregister function is defined in kernel/IRQ/manage. C:
Void free_irq (unsigned int IRQ, void * dev_id)

V. Implementation of registration interrupted by the S3C2410 subaccount
5.1 raise the issue of sub-interrupt registration on S3C2410
Refer to the method for judging the interrupt number in section 3.5. We can see that it is only determined by using the ffset register in the S3C2410 interrupt controller. In intpnd, for eint4_7, eint8_23, int_uart0, int_adc, and other vectors with subinterruptions, javasffset cannot determine the specific interrupt number. The registration method left by the platform is as follows:
The include/ASM/ARCH/irqs. H has the following definitions:
/* Interrupts generated from the external interrupts sources */
# Define irq_eint4 s3c2410_irq (32)/* 48 */
# Define irq_eint5 s3c2410_irq (33)
# Define irq_eint6 s3c2410_irq (34)
# Define irq_eint7 s3c2410_irq (35)
# Define irq_eint8 s3c2410_irq (36)
# Define irq_eint9 s3c2410_irq (37)
# Define irq_eint10 s3c2410_irq (38)
# Define irq_eint11 s3c2410_irq (39)
# Define irq_eint12 s3c2410_irq (40)
# Define irq_eint13 s3c2410_irq (41)
# Define irq_eint14 s3c2410_irq (42)
# Define irq_eint15 s3c2410_irq (43)
# Define irq_eint16 s3c2410_irq (44)
# Define irq_eint17 s3c2410_irq (45)
# Define irq_eint18 s3c2410_irq (46)
# Define irq_eint19 s3c2410_irq (47)
# Define irq_eint20 s3c2410_irq (48)/* 64 */
# Define irq_eint21 s3c2410_irq (49)
# Define irq_eint22 s3c2410_irq (50)
# Define irq_eint23 s3c2410_irq (51)

We can see that the platform defines the interrupt number for each seed interrupt. If you want to implement the interrupt registration of eint10, you can simply follow the interrupt number irq_eint10. How is the platform Code implemented to interrupt registration?

5.2 resolve the issue of stopping registration on the S3C2410 subaccount
/* ARCH/ARM/plat-s3c24xx/IRQ. C */
Void _ init s3c24xx_init_irq (void)
{......
Set_irq_chained_handler (irq_eint4t7, initi_irq_demux_extint4t7 );
Set_irq_chained_handler (irq_eint8t23, initi_irq_demux_extint8 );
Set_irq_chained_handler (irq_uart0, initi_irq_demux_uart0 );
Set_irq_chained_handler (irq_uart1, initi_irq_demux_uart1 );
Set_irq_chained_handler (irq_uart2, initi_irq_demux_uart2 );
Set_irq_chained_handler (irq_adcparent, initi_irq_demux_adc );
......
}

During initialization, the Platform calls s3c24xx_init_irq, which registers for eint4_7, eint8_23, int_uart0, int_adc, and other interruptions. Next let's take a look at the content of the processing functions corresponding to the interrupt number with subinterrupts. Take irq_eint4t7 as an example. Other cases are similar.

/* ARCH/ARM/plat-s3c24xx/IRQ. C */
Initi_irq_demux_extint4t7 (unsigned int IRQ,
Struct irq_desc * DESC)
{
Unsigned long eintpnd = _ raw_readl (s3c24xx_eintpend );
Unsigned long eintmsk = _ raw_readl (s3c24xx_eintmask );
Eintpnd & = ~ Eintmsk;
Eintpnd & = 0xff;/* only lower irqs */

/* In eintpnd, multiple digits can be set to 1 at the same time, which is different from that in intpnd */
While (eintpnd) {// loop execution of sub-interruptions of all positions
IRQ = _ FFs (eintpnd); // calculate the first digit not 0, which is similar to the effect of clz leading 0 after arm V5
Eintpnd & = ~ (1 <IRQ); // clear the corresponding bit
IRQ + = (irq_eint4-4); // calculates the interrupt number.
Desc_handle_irq (IRQ, irq_desc + IRQ); // executes the registration function corresponding to the subinterrupt.
}
}
From the above function, we can see how the subinterrupt is registered and called. Someone may ask why the get_irqnr_and_base function in the include/ASM/arch-s3c2410/entry-macro.s file can be used to determine the interrupt number, and the corresponding subinterrupt number can be directly found?
The reason is: get_irqnr_and_base is a function provided by the platform to the system. If multiple sub-interrupts are set at the same time, one value cannot be returned (because the sub-interrupt is in progress, such as eintpnd )). However, intpnd does not have this problem.

This article from: dz3w. com original URL: http://www.dz3w.com/mcu/linux/0078340.html

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.