include/linux/interrupt.h
121 static inline int __must_check
122 request_irq(unsigned int irq, irq_handler_t handler, unsigned long
123 flags, const char *name, void *dev)
124 {
125 return request_threaded_irq(irq, handler, NULL, flags, name, dev);
126 }
---------------------------------------------------------------------
kernel/irq/manage.c
1038 int request_threaded_irq(unsigned int irq, irq_handler_t handler,
1039 irq_handler_t thread_fn, unsigned long irqflags,
1040 const char *devname, void *dev_id)
1041 {
1042 struct irqaction *action;
1043 struct irq_desc *desc;
1044 int retval;
1045
1046 /*
1047 * handle_IRQ_event() always ignores IRQF_DISABLED except for
1048 * the _first_ irqaction (sigh). That can cause oopsing, but
1049 * the behavior is classified as "will not fix" so we need to
1050 * start nudging drivers away from using that idiom.
1051 */
1052 if ((irqflags & (IRQF_SHARED|IRQF_DISABLED)) ==
1053 (IRQF_SHARED|IRQF_DISABLED)) {
1054 pr_warning(
1055 "IRQ %d/%s: IRQF_DISABLED is not guaranteed on shared IRQs\n",
1056 irq, devname);
1057 }
1058
1059 #ifdef CONFIG_LOCKDEP
1060 /*
1061 * Lockdep wants atomic interrupt handlers:
1062 */
1063 irqflags |= IRQF_DISABLED;
1064 #endif
1065 /*
1066 * Sanity-check: shared interrupts must pass in a real dev-ID,
1067 * otherwise we'll have trouble later trying to figure out
1068 * which interrupt is which (messes up the interrupt freeing
1069 * logic etc).
1070 */
1071 if ((irqflags & IRQF_SHARED) && !dev_id)
1072 return -EINVAL;
1073
1074 desc = irq_to_desc(irq);
1075 if (!desc)
1076 return -EINVAL;
1077
1078 if (desc->status & IRQ_NOREQUEST)
1079 return -EINVAL;
1080
1081 if (!handler) {
1082 if (!thread_fn)
1083 return -EINVAL;
1084 handler = irq_default_primary_handler;
1085 }
1086
1087 action = kzalloc(sizeof(struct irqaction), GFP_KERNEL);
1088 if (!action)
1089 return -ENOMEM;
1090
1091 action->handler = handler;
1092 action->thread_fn = thread_fn;
1093 action->flags = irqflags;
1094 action->name = devname;
1095 action->dev_id = dev_id;
1096
1097 chip_bus_lock(irq, desc);
1098 retval = __setup_irq(irq, desc, action);
1099 chip_bus_sync_unlock(irq, desc);
1100
1101 if (retval)
1102 kfree(action);
1103
1104 #ifdef CONFIG_DEBUG_SHIRQ
1105 if (!retval && (irqflags & IRQF_SHARED)) {
1106 /*
1107 * It's a shared IRQ -- the driver ought to be prepared for it
1108 * to happen immediately, so let's make sure....
1109 * We disable the irq to make sure that a 'real' IRQ doesn't
1110 * run in parallel with our fake.
1111 */
1112 unsigned long flags;
1113
1114 disable_irq(irq);
1115 local_irq_save(flags);
1116
1117 handler(irq, dev_id);
1118
1119 local_irq_restore(flags);
1120 enable_irq(irq);
1121 }
1122 #endif
1123 return retval;
1124 }
1125 EXPORT_SYMBOL(request_threaded_irq);
---------------------------------------------------------------------
关于中断注册的例子,可在内核中搜索下request_irq。