init/main.c:
asmlinkage void start_kernel(void)
{
......
early_irq_init();
init_IRQ();
......
}
early_irq_init()函数有两种实现,一种是基于radix tree,一种是定义静态数组,如果要使用radix tree实现的,那么需要打开SPARSE_IRQ配置选项,由于我对数据结构不了解,所以分析以下静态数组实现方式版本的。
/kernel/irq/irqdesc.c
struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
[ ... NR_IRQS-] = {
.handle_irq = handle_bad_irq,
.depth = ,
.lock = __RAW_SPIN_LOCK_UNLOCKED(irq_desc->lock),
}
}; int __init early_irq_init(void)
{
int count, i, node = first_online_node;
struct irq_desc *desc; init_irq_default_affinity(); printk(KERN_INFO "NR_IRQS:%d\n", NR_IRQS); desc = irq_desc;
count = ARRAY_SIZE(irq_desc); for (i = ; i < count; i++) {
desc[i].kstat_irqs = alloc_percpu(unsigned int);
alloc_masks(&desc[i], GFP_KERNEL, node);
raw_spin_lock_init(&desc[i].lock);
lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
desc_set_defaults(i, &desc[i], node);
}
return arch_early_irq_init();
}
第一次见到这种初始化数组全部成员为同样内容的方式,可以学习积累下。
NR_IRQS在arch/arm/mach-s5pv210/include/mach/irqs.h下定义:
#define NR_IRQS (IRQ_EINT(31) + S5P_GPIOINT_COUNT + 1)
上面函数的核心就是调用desc_set_defaults()来初始化上述中断描述符数组,kernel/irq/irqdesc.c:
static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node)
{
int cpu; desc->irq_data.irq = irq;
desc->irq_data.chip = &no_irq_chip;
desc->irq_data.chip_data = NULL;
desc->irq_data.handler_data = NULL;
desc->irq_data.msi_desc = NULL;
irq_settings_clr_and_set(desc, ~, _IRQ_DEFAULT_INIT_FLAGS);
irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
desc->handle_irq = handle_bad_irq;
desc->depth = ;
desc->irq_count = ;
desc->irqs_unhandled = ;
desc->name = NULL;
for_each_possible_cpu(cpu)
*per_cpu_ptr(desc->kstat_irqs, cpu) = ;
desc_smp_init(desc, node);
}
最后返回时调用的arch_early_irq_init()函数并没有做事情。
接着看init_IRQ():
void __init init_IRQ(void)
{
machine_desc->init_irq();
}
machine_desc是全局变量,定义在板文件中,由于我们使用的是s5pv210,且demo板号选的是smdkv210,所以这个全局变量就在arch/arm/mach-s5pv210/mach-s5pv210.c中:
MACHINE_START(SMDKV210, "SMDKV210")
/* Maintainer: Kukjin Kim <kgene.kim@samsung.com> */
.boot_params = S5P_PA_SDRAM + 0x100,
.init_irq = s5pv210_init_irq,
.map_io = smdkv210_map_io,
.init_machine = smdkv210_machine_init,
.timer = &s5p_timer,
MACHINE_END
arch/arm/mach-s5pv210/mach-s5pv210.c中还有如下函数定义:
void __init s5pv210_init_irq(void)
{
u32 vic[]; /* S5PV210 supports 4 VIC */ /* All the VICs are fully populated. */
vic[] = ~;
vic[] = ~;
vic[] = ~;
vic[] = ~; s5p_init_irq(vic, ARRAY_SIZE(vic));
}
arch/arm/plat-s5p/irq.c
void __init s5p_init_irq(u32 *vic, u32 num_vic)
{
#ifdef CONFIG_ARM_VIC
int irq; /* initialize the VICs */
for (irq = ; irq < num_vic; irq++)
vic_init(VA_VIC(irq), VIC_BASE(irq), vic[irq], );
#endif s3c_init_vic_timer_irq(, IRQ_TIMER0); s3c_init_uart_irqs(uart_irqs, ARRAY_SIZE(uart_irqs));
}
上面涉及到的函数都是去操作VIC相关的寄存器,这部分操作还不是很清楚,先不往下继续追踪了。