linux-3.4.6 kernel interrupt process analysis

Each kernel version of the code will have different small part, but the general process is basically the same, just call the function name and some changes in the relationship, let's analyze the interrupt process

1: There traps.c file void __init early_trap_init (void * vectors_base) relocation function in arch / arm / kernel / at an interrupt vector table

 

Search __vectors_start know there are macro definitions found vector_stub irq, IRQ_MODE in this file in arch / arm / kernel / entry_armv.S, four to the case study of a downstream process

vector_stub is a macro.

Here to interrupt __irq_usr user-mode process came to search __irq_usr

 

There irq_handler this is a macro, or continue searching in this entry_armv.S

 

Search arch_irq_handler_default after which calls asm_do_IRQ

 

Front herein are written in assembler, asm_do_IRQ behind are used to achieve the function C

  Calls relationship is as follows:

  early_trap_init // kernel uses a virtual address, here is the original interrupt vector to the new virtual address 0x00000000 to have 0xffff0000 or can be in the kernel configuration file

    vector_stub irq // interrupt that is down to user mode analysis

      __irq_usr

        irq_handler

          arch_irq_handler_default

            asm_do_IRQ

To analyze the following asm_do_IRQ understand is how to break the 

2: listed first call graph

  asm_do_IRQ

    handle_IRQ

      generic_handle_irq

        struct irq_desc *desc = irq_to_desc(irq);

        generic_handle_irq_desc

          desc-> handle_irq (irq, desc); // desc structure is a function realized 1: 2 interrupt a resolution that is: call handler 3: interrupt clear

================================================= division line ================================================= ====

  desc-> handle_irq (irq, desc); analyze it handle_irq pointing to that function? Search __irq_set_handler find it in this letter calls desc-> handle_irq = handle in kernel / irq / chip.c in;

  Search again __irq_set_handler this function to see who is calling include / linux / irq.h in irq_set_chained_handler was then called the search function calls that get in arch / arm / plat-s3c24xx in

  s3c24xx_init_irq this function calls this function in the construct irq_desc structure that is set in the initialization interrupt function calls inside This is just an example, different interrupt initialization function can call this __irq_set_handler

  handle_edge_irq

    handle_irq_event (desc); // This function is to handle interrupts

  Hierarchy is like this, we also need to analyze the structure irq_desc this structure is defined below in include / linux / irqdesc.h listed only a portion

These are the kernel interrupt architecture are doing, which is interrupted frame, if we use our own interrupt, how do we tell the kernel? Request_irq registered with, let's analyze the following

irq_desc to interrupt number is a subscript array, there are a variety of processing functions, linked lists, etc., we want to use their own interrupt-driven, it is necessary to construct fill and then registered in this list.

 

request_irq

  request_threaded_irq

    action = kzalloc(sizeof(struct irqaction), GFP_KERNEL);    //分配一个irqaction结构体

    action->handler = handler;                //填充 把传入的参数填充到结构体
    action->thread_fn = thread_fn;
    action->flags = irqflags;
    action->name = devname;
    action->dev_id = dev_id;

    retval = __setup_irq(irq, desc, action);          //设置中断

       __irq_set_trigger

        ret = chip->irq_set_type(&desc->irq_data, flags);  //设置中断类型

    __enable_irq(desc, irq, false);              //使能中断

 

到此基本分析完毕,下一节 写一个基本中断的按键驱动程序

 

Guess you like

Origin www.cnblogs.com/x2i0e19linux/p/11718602.html