您的位置 首页 被动

arm linux 下中止流程扼要剖析初始化

上面的这个表我们称之为异常中断向量表,表中的IRQ和FIQ位置就是用来存放处理中断函数的地址。至于选择何处存放该表,可由CPU的协处理器完成…

上面的这个表咱们称之为”异常中止向量表”,表中的IRQ和FIQ方位便是用来寄存处理中止函数的地址。至于挑选何处寄存该表,可由CPU的协处理器完结。如s3c2410下由CP15中寄存器1的位13来决议,咱们能够通过设置该位来告知体系咱们的向量表在哪。详细可参阅<>

因而,在中止初始化的时分咱们要做的便是在IRQ和FIQ的方位处放置咱们的中止处理函数地址或跳转句子跳转到咱们的中止处理函数。这个进程是在trap_init中完结的,而他由start_kernel()调用。

arch/arm/kernel/traps.c:

void __init trap_init(void)

{

unsigned long vectors = CONFIG_VECTORS_BASE;/*跳转表的寄存方位(即上面那表的寄存方位)*/

/*这些都在entry-armv.S下界说*/

extern char __stubs_start[], __stubs_end[];

extern char __vectors_start[], __vectors_end[];

extern char __kuser_helper_start[], __kuser_helper_end[];

int kuser_sz = __kuser_helper_end – __kuser_helper_start;

/*

* Copy the vectors, stubs and kuser helpers (in entry-armv.S)

* into the vector page, mapped at 0xffff0000, and ensure these

* are visible to the instruction stream.

*/

/*跳转表内容到指定的方位*/

memcpy((void *)vectors, __vectors_start, __vectors_end – __vectors_start);

memcpy((void *)vectors + 0x200, __stubs_start, __stubs_end – __stubs_start);

memcpy((void *)vectors + 0x1000 – kuser_sz, __kuser_helper_start, kuser_sz);

/*

* Copy signal return handlers into the vector page, and

* set sigreturn to be a pointer to these.

*/

memcpy((void *)KERN_SIGRETURN_CODE, sigreturn_codes,

sizeof(sigreturn_codes));

flush_icache_range(vectors, vectors + PAGE_SIZE);

modify_domain(DOMAIN_USER, DOMAIN_CLIENT);

}

上面这个函数首要便是在CONFIG_VECTORS_BASE处设置好那张跳转表,CONFIG_VECTORS_BASE在autoconf.h中界说(该文件主动成生),值为0xffff0000,而CP15下的r1[13]在体系启动的时分在汇编部分就现已设置好了。

接下来咱们就看下__vectors_start,__vectors_end,__stubs_start,__stubs_end之间的内容。

arch/arm/kernel/entry-armv.S:

.globl__vectors_start

__vectors_start:

swiSYS_ERROR0

bvector_und + stubs_offset

ldrpc, .LCvswi + stubs_offset

bvector_pabt + stubs_offset

bvector_dabt + stubs_offset

bvector_addrexcptn + stubs_offset

bvector_irq + stubs_offset

bvector_fiq + stubs_offset

.globl__vectors_end

__vectors_end:

.data

看到了吧, 便是那张跳转表。vector_irq,vector_fiq等函数咱们后边在剖析,他们就界说在__stubs_start,__stubs_end中。

至此通过traps_init后,在0xffff0000处的跳转表就形成了。当发生IRQ时,将调用bvector_irq + stubs_offset

在体系初始化的时分还会调用init_IRQ函数(也由start_kernel调用),它初始化了一个大局中止描述符表(该表保存了每个中止的一切特点信息)。并调用特定渠道的中止初始化函数。

arm/arm/kernel/Irq.c:

void __init init_IRQ(void)

{

int irq;

/*初始化中止描述符表*/

for (irq = 0; irq < NR_IRQS; irq++)

irq_desc[irq].status |= IRQ_NOREQUEST | IRQ_DELAYED_DISABLE |

IRQ_NOPROBE;

#ifdef CONFIG_SMP

bad_irq_desc.affinity = CPU_MASK_ALL;

bad_irq_desc.cpu = smp_processor_id();

#endif

init_arch_irq();/*特定渠道的中止初始化*/

}

体系中总共有NR_IRQS个中止,而且每个中止都有一个中止描述符,保存在irq_desc中,该描述符保存了该中止的一切特点信息。

关于渠道smdk2410来说init_arch_irq()便是s3c24xx_init_irq()函数,这是在setup_arch()里边赋值的。

后边的内容咱们都以中止号:IRQ_WDT为例来解说:

arch/arm/mach-s3c2410/Irq.c:

/* s3c24xx_init_irq

*

* Initialise S3C2410 IRQ system

*/

void __init s3c24xx_init_irq(void)

{

unsigned long pend;

unsigned long last;

int irqno;

int i;

irqdbf(“s3c2410_init_irq: clearing interrupt status flags/n”);

/* first, clear all interrupts pending… */

/*先清掉一切的pending标志位,该位代表是否体系中触发了一个中止*/

last = 0;

for (i = 0; i < 4; i++) {

pend = __raw_readl(S3C24XX_EINTPEND);

if (pend == 0 || pend == last)

break;

__raw_writel(pend, S3C24XX_EINTPEND);

printk(“irq: clearing pending ext status %08x/n”, (int)pend);

last = pend;

}

last = 0;

for (i = 0; i < 4; i++) {

pend = __raw_readl(S3C2410_INTPND);

if (pend == 0 || pend == last)

break;

__raw_writel(pend, S3C2410_SRCPND);

__raw_writel(pend, S3C2410_INTPND);

printk(“irq: clearing pending status %08x/n”, (int)pend);

last = pend;

}

last = 0;

for (i = 0; i < 4; i++) {

pend = __raw_readl(S3C2410_SUBSRCPND);

if (pend == 0 || pend == last)

break;

printk(“irq: clearing subpending status %08x/n”, (int)pend);

__raw_writel(pend, S3C2410_SUBSRCPND);

last = pend;

}

/* register the main interrupts */

/*注册首要的中止*/

irqdbf(“s3c2410_init_irq: registering s3c2410 interrupt handlers/n”);

for (irqno = IRQ_EINT4t7; irqno <= IRQ_ADCPARENT; irqno++) {

/* set all the s3c2410 internal irqs */

switch (irqno) {

/* deal with the special IRQs (cascaded) */

case IRQ_EINT4t7:

case IRQ_EINT8t23:

case IRQ_UART0:

case IRQ_UART1:

case IRQ_UART2:

case IRQ_ADCPARENT:

set_irq_chip(irqno, &s3c_irq_level_chip);

set_irq_handler(irqno, do_level_IRQ);

break;

case IRQ_RESERVED6:

case IRQ_RESERVED24:

/* no IRQ here */

break;

default:/*IRQ_WDT便是这条通路*/

//irqdbf(“registering irq %d (s3c irq)/n”, irqno);

set_irq_chip(irqno, &s3c_irq_chip); /*为中止号设置chip*/

set_irq_handler(irqno, do_edge_IRQ); /*设置中止例程*/

set_irq_flags(irqno, IRQF_VALID);/*设置中止ready的符号*/

}

}

/* setup the cascade irq handlers */

set_irq_chained_handler(IRQ_EINT4t7, s3c_irq_demux_extint);

set_irq_chained_handler(IRQ_EINT8t23, s3c_irq_demux_extint);

set_irq_chained_handler(IRQ_UART0, s3c_irq_demux_uart0);

set_irq_chained_handler(IRQ_UART1, s3c_irq_demux_uart1);

set_irq_chained_handler(IRQ_UART2, s3c_irq_demux_uart2);

set_irq_chained_handler(IRQ_ADCPARENT, s3c_irq_demux_adc);

/* external interrupts */

for (irqno = IRQ_EINT0; irqno <= IRQ_EINT3; irqno++) {

irqdbf(“registering irq %d (ext int)/n”, irqno);

set_irq_chip(irqno, &s3c_irq_eint0t4);

set_irq_handler(irqno, do_edge_IRQ);

set_irq_flags(irqno, IRQF_VALID);

}

for (irqno = IRQ_EINT4; irqno <= IRQ_EINT23; irqno++) {

irqdbf(“registering irq %d (extended s3c irq)/n”, irqno);

set_irq_chip(irqno, &s3c_irqext_chip);

set_irq_handler(irqno, do_edge_IRQ);

set_irq_flags(irqno, IRQF_VALID);

}

/* register the uart interrupts */

irqdbf(“s3c2410: registering external interrupts/n”);

for (irqno = IRQ_S3CUART_RX0; irqno <= IRQ_S3CUART_ERR0; irqno++) {

irqdbf(“registering irq %d (s3c uart0 irq)/n”, irqno);

set_irq_chip(irqno, &s3c_irq_uart0);

set_irq_handler(irqno, do_level_IRQ);

set_irq_flags(irqno, IRQF_VALID);

}

for (irqno = IRQ_S3CUART_RX1; irqno <= IRQ_S3CUART_ERR1; irqno++) {

irqdbf(“registering irq %d (s3c uart1 irq)/n”, irqno);

set_irq_chip(irqno, &s3c_irq_uart1);

set_irq_handler(irqno, do_level_IRQ);

set_irq_flags(irqno, IRQF_VALID);

}

for (irqno = IRQ_S3CUART_RX2; irqno <= IRQ_S3CUART_ERR2; irqno++) {

irqdbf(“registering irq %d (s3c uart2 irq)/n”, irqno);

set_irq_chip(irqno, &s3c_irq_uart2);

set_irq_handler(irqno, do_level_IRQ);

set_irq_flags(irqno, IRQF_VALID);

}

for (irqno = IRQ_TC; irqno <= IRQ_ADC; irqno++) {

irqdbf(“registering irq %d (s3c adc irq)/n”, irqno);

set_irq_chip(irqno, &s3c_irq_adc);

set_irq_handler(irqno, do_edge_IRQ);

set_irq_flags(irqno, IRQF_VALID);

}

irqdbf(“s3c2410: registered interrupt handlers/n”);

}

上面这个函数结合s3c2410的data sheet很好了解,便是注册各个必要的中止,留意这儿为每个中止号注册的中止例程仅仅个全体的函数,该函数仅仅处理一些共性的操作如清中止符号位等,他会进一步调用咱们注册的中止例程来处理特定的中止。怎么注册中止会在后边剖析。

这个初始化函数调用了很多与中止相关的函数,咱们逐一剖析:

先看set_irq_chip

kernel/irq/chip.c:

/

*set_irq_chip – set the irq chip for an irq

*@irq:irq number

*@chip:pointer to irq chip description structure

*/

/*为某个中止号设置一个chip*/

int set_irq_chip(unsigned int irq, struct irq_chip *chip)

{

struct irq_desc *desc;

unsigned long flags;

if (irq >= NR_IRQS) {

printk(KERN_ERR “Trying to install chip for IRQ%d/n”, irq);

WARN_ON(1);

return -EINVAL;

}

if (!chip)

chip = &no_irq_chip;

desc = irq_desc + irq;/*获取保存该中止的中止描述符*/

spin_lock_irqsave(&desc->lock, flags);

irq_chip_set_defaults(chip); /*为chip设置一些默许的enable,disable函数*/

desc->chip = chip;/*为中止保存chip目标*/

/*

* For compatibility only:

*/

desc->chip = chip;

spin_unlock_irqrestore(&desc->lock, flags);

return 0;

}

为特定中止号初始化好chip目标,表明该中止号由这个chip操控,后边会调用到该中止号所属chip的相关函数,各个中止的chip是不同的,以IRQ_WDT为例,它的chip是s3c_irq_chip。

arch/arm/mach-s3c2410/Irq.c:

static struct irqchip s3c_irq_chip = {

.ack= s3c_irq_ack,

.mask= s3c_irq_mask,

.unmask= s3c_irq_unmask,

.set_wake= s3c_irq_wake

};

在看irq_chip_set_defaults

kernel/irq/Chip.c:

/*

* Fixup enable/disable function pointers

*/

void irq_chip_set_defaults(struct irq_chip *chip)

{

if (!chip->enable)

chip->enable = default_enable;

if (!chip->disable)

chip->disable = default_disable;

if (!chip->startup)

chip->startup = default_startup;

if (!chip->shutdown)

chip->shutdown = chip->disable;

if (!chip->name)

chip->name = chip->typename;

}

很显然,假如chip没有相应的操作函数,则就给chip赋默许的操作函数。

咱们接着看set_irq_handler()

include/linux/Irq.h:

static inline void

set_irq_handler(unsigned int irq,

void fastcall (*handle)(unsigned int, struct irq_desc *,

struct pt_regs *))

{

__set_irq_handler(irq, handle, 0);

}

kernel/irq/Chip.c:

void

__set_irq_handler(unsigned int irq,

void fastcall (*handle)(unsigned int, irq_desc_t *,

struct pt_regs *),

int is_chained)

{

struct irq_desc *desc;

unsigned long flags;

if (irq >= NR_IRQS) { /*参数检查*/

printk(KERN_ERR

“Trying to install type control for IRQ%d/n”, irq);

return;

}

desc = irq_desc + irq; /*获取中止描述符的存储地址*/

if (!handle)

handle = handle_bad_irq;/*赋默许的中止handle*/

if (desc->chip == &no_irq_chip) {

printk(KERN_WARNING “Trying to install %sinterrupt handler “

“for IRQ%d/n”, is_chained ? “chained ” : ” “, irq);

/*

* Some ARM implementations install a handler for really dumb

* interrupt hardware without setting an irq_chip. This worked

* with the ARM no_irq_chip but the check in setup_irq would

* prevent us to setup the interrupt at all. Switch it to

* dummy_irq_chip for easy transition.

*/

desc->chip = &dummy_irq_chip;/*赋默许的chip*/

}

spin_lock_irqsave(&desc->lock, flags);

/* Uninstall? */

if (handle == handle_bad_irq) {

if (desc->chip != &no_irq_chip) {

desc->chip->mask(irq);

desc->chip->ack(irq);

}

desc->status |= IRQ_DISABLED;/*没有中止例程则disable掉该中止*/

desc->depth = 1;

}

desc->handle_irq = handle;/*保存中止例程,关于IRQ_WDT来说则是do_edge_IRQ */

/*由上面的调用可知,is_chained一直等于0*/

if (handle != handle_bad_irq && is_chained) {

desc->status &= ~IRQ_DISABLED;

desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;

desc->depth = 0;

desc->chip->unmask(irq);

}

spin_unlock_irqrestore(&desc->lock, flags);

}

上面这个函数便是为特定的中止设置好一个中止处理例程(这儿的例程可不是咱们request_irq注册的例程喔)。

接着看set_irq_flags()

arch/arm/kernel/Irq.c:

void set_irq_flags(unsigned int irq, unsigned int iflags)

{

struct irqdesc *desc;

unsigned long flags;

if (irq >= NR_IRQS) {

printk(KERN_ERR “Trying to set irq flags for IRQ%d/n”, irq);

return;

}

desc = irq_desc + irq;

spin_lock_irqsave(&desc->lock, flags);

desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;

if (iflags & IRQF_VALID)

desc->status &= ~IRQ_NOREQUEST;/*清掉IRQ_NOREQUEST符号*/

if (iflags & IRQF_PROBE)

desc->status &= ~IRQ_NOPROBE;

if (!(iflags & IRQF_NOAUTOEN))

desc->status &= ~IRQ_NOAUTOEN;

spin_unlock_irqrestore(&desc->lock, flags);

}

该函数首要是为特定的中止设置相应的状况符号, 而这儿咱们调用它的意图便是清掉IRQ_NOREQUEST符号,告知体系该中止现已能够被请求运用了,中止在请求的时分会检查是否有IRQ_NOREQUEST符号,如有则外表该中止还不能运用。而初始化的时分一切的中止都有这个符号。

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/beidong/277200.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部