In contact with the SCM before the interruption of this noun, simple understanding, in the CPU normal running program A, suddenly inserted program B, program B can be understood as an interruption. An interrupt mechanism is also provided in the Linux kernel for handling the above burst events.
first, interrupt the entrance
In the Linux kernel also has the anomaly vector table, takes the arm architecture in linux-2.6.32.50 as an example, in ARCH/ARM/KERNEL/ENTRY-ARMV. The following anomaly vector table exists in S.
__vectors_start:
ARM ( swi sys_error0 )
THUMB (svc #0 )
THUMB (NOP )
W (b) Vector_und + stubs_offset
W (LDR) pc,. LCVSWI + stubs_offset
W (b) Vector_pabt + stubs_offset
W (b) Vector_dabt + stubs_offset
W (b) VECTOR_ADDREXCPTN + stubs_offset
W (b) Vector_irq + stubs_offset
W (b) Vector_fiq + stubs_offset
. Globl __vectors_end
_ _vectors_end:
When the interrupt is generated, the interrupt processing is entered into the VECTOR_IRQ, and the corresponding code is as follows, where vector_stub is defined as a macro.
* * Interrupt Dispatcher * *
vector_stub IRQ, Irq_mode, 4
long __irq_usr @ 0 (usr_ 26/USR_32)
. Long __irq_invalid @ 1 (fiq_26/fiq_32)
. Long __irq_invalid @ 2 (irq_26/irq_32)
. Long __irq_svc @ 3 (svc_26/svc_32)
. Long __irq_invalid @ 4
Long __irq_invalid @ 5
long __irq_invalid @ 6
long __irq_invalid @ 7
long __irq_invalid @ 8
. Long __irq_invalid @ 9
. Long __irq_invalid @ a
. Long __irq_invalid @ b
. Long __irq_ Invalid @ C
. Long __irq_invalid @ D
. Long __irq_invalid @ E
. Long __irq_invalid @ F
The corresponding processing functions are different for the interrupts that occur in the management mode and in the user mode, respectively, __irq_svc and __IRQ_USR.
Second, the interrupted call procedure
takes __irq_usr as an example.
__irq_usr => irq_handler => asm_do_irq => GENERIC_HANDLE_IRQ (IRQ) => Generic_handle_irq_desc () => O_IRQ (IRQ) => handle_irq_event ()
370 irqreturn_t handle_irq_event (unsigned int IRQ, struct irqaction *action) 371 {372 irqreturn_t ret, retval = Irq_n
One;
373 unsigned int status = 0; 374 375 if (!) (
Action->flags & irqf_disabled)) 376 LOCAL_IRQ_ENABLE_IN_HARDIRQ (); 377 378 Do {379 Trace_irq_handler_entry (IRQ, action) 380 ret = Action->handler (IRQ, Action->de
V_ID);
381 Trace_irq_handler_exit (IRQ, Action, ret); 382 383 switch (ret) {384 case irq_wake_thread:389 ret = irq_handled; 395 if (UN Likely (!ACTION->THREAD_FN)) {396 Warn_no_thread (IRQ, action); 397 break; 398 } 399 408 if (likely!test_bit (irqtf_died, 409)) {4
Set_bit (Irqtf_runthread, &action->thread_flags);
411 wake_up_process (Action->thread); 412} 413 414/* Fall through to add to randomness */415 case irq_handled:416 Status |= action->flags;
417 break;
418 419 default:420 break;
421} 422 423 retval |= ret;
424 action = action->next;
425} while (action);
426 427 if (Status & Irqf_sample_random) 428 add_interrupt_randomness (IRQ);
429 local_irq_disable ();
430 431 return retval; 432}
The 380 lines in the code execute the Interrupt service program, which is written by us and registered in the system. A process such as this completes the response to an external hardware interrupt.
III. Registration of interrupt service procedures
The Linux kernel provides a set of functions to complete the registration and release of the Interrupt Service program, REQUEST_IRQ () and FREE_IRQ ().
REQUEST_IRQ (unsigned int IRQ, irq_handler_t handler, unsigned long flags,
const char *name, void *dev)
The function has five parameters, which are described below:
irq-the device number to assign
handler-a function pointer to the actual interrupt service program
typedef irqreturn_t (*irq_handler_t) (int, void *);
Flags for flags-interrupt handlers. Defined in Include/linux/interrupt.h
name-Interrupt Name
Dev-is used for disconnection in shares and is a handler parameter. This parameter can be set to NULL if you do not disconnect from the share
The registration process for the Interrupt service program is as follows:
REQUEST_IRQ () => REQUEST_THREADED_IRQ ()
1028 int REQUEST_THREADED_IRQ (unsigned int IRQ, irq_handler_t handler,
1029 irq_handler_t , THREAD_FN Long irqflags,
1030 const char *devname, void *dev_id 1031 1032 {struct irqaction ;
1033 struct IRQ_DESC *desc;
1034 int retval;
1035 ...
1081 Action->handler = handler;
1082 action->thread_fn = THREAD_FN;
1083 action->flags = irqflags;
1084 action->name = devname;
1085 action->dev_id = dev_id;
1086
1087 Chip_bus_lock (IRQ, DESC);
1088 retval = __SETUP_IRQ (IRQ, DESC, action);
1089 chip_bus_sync_unlock (IRQ, DESC);
1090 ...
1093
1113 return retval;
1114}
In line 1081 of code, the address of the interrupt service program handler is saved in the handler member of the action. In conjunction with the interrupt invocation process previously tracked, the interrupt generation in the future will execute the Interrupt service program we registered through REQUEST_IRQ.
Generally, we call REQUEST_IRQ () in the Init function in the driver, register the interrupt service program we wrote handler into the system, and when the interrupt is generated, the system passes through a series of calls that will eventually execute our interrupt service program handler. Completes the response to the interrupt. The
Free_irq () is invoked in the driver's exit function to remove the interrupt Service program handler registered to the system.