Platform-Level Interrupt Controller(拷贝版)

Platform-Level Interrupt Controller(拷贝版)

1、interrupt sources

PLIC 只响应global中断源,不响应local中断源。
global interrupts可为level-triggered,edge-triggered,message-signalled。sources也可以使用queue来储存多个interrupts。所有的global interrupt sources都会通过gateway被转为PLIC core能接受的标准形式。
每个interrupt source都会被赋予一个从1开始的无符号整数作为标识(Interrupt Identifiers ID)。0保留为“no interrupt”,且该数数值越小优先级越大。
每个interrupt source都会绑定一个与平台相关的优先级寄存器(符合WARL),数值不能为0。硬件也可以选择将优先级直接固定为硬连接。优先级寄存器中能够修改的bits组成的全部数值都必须被支持(例如寄存器中有2个bits可以读写,那么必须支持2x2=4种优先级)。软件可以通过向寄存器中写全1/0再读出来的方式判断哪些bits硬连为0/1,哪些bits可写。
每个interrupt source都被赋予一个enable bit IE,储存在平台相关的寄存器中(符合WARL)。当然IE bits也可以硬链接为0/1。

2、interrupt targets

中断处理终端,通常为hart contexts,具体为一个RISCV CPU的特定privilege mode。
并不是所有的hart context都是interrupt target。如果CPU不支持中断转移至低优先级(delegate),则低优先级的hart context不是interrupt target。
PLIC产生的interrupt notification会标示在target的meip/heip/seip/ueip bits of mip/hip/sip/uip registers for M/H/S/U mode。只有支持delegate的处理器才会在对应lower privilege xip寄存器中置对应中断pending位。
PLIC不负责处理中断抢占(preempt)和嵌套(nest),由interrupt target处理上述问题。
interrupt target对应平台相关的priority threshold寄存器(符合WARL),只有高于该threshold的active interrupt才会发送给对应target。threshold必须支持0,表示没有interrupt被mask;通常也需要支持max priority level,表示所有interrupt都会被mask。

3、interrupt gateways

这个类似中断源和PLIC core的中继,负责将sources的各类interrupt转换为PLIC core的通用格式,同时控制向PLIC core发起request的整个流程。
gateway在收到interrupt target完成中断服务的notification后,发送新的interrupt request to PLIC core。
若interrupt source使用level-sensitive,gateway会将第一次拉高的时间点作为interrupt request。在收到interrupt completion之前,gateway不会再向PLIC core发送新的请求。如果收到interrupt completion后,source的request还拉高着,会被作为新的interrupt request。如果source request在PLIC core收到request后,target处理该request之前拉低,这个request仍然会储存在PLIC core的IP位中,即仍然会被target所响应。在中断服务程序里会判断此次request是否还需要进行处理。
若interrupt source使用edge-sensitive,gateway会将第一次符合的edge当作interrupt request。在gateway发送request到PLIC core之后,一直到interrupt completion收到前,之中的edge可以选择被丢掉,或者使用一个计数器记录pending的interrupt。
若interrupt source使用message -signalled interrupt MSI(虚拟概念),该message会经过decoder决定发送给哪个gateway,然后采用类似与edge interrupt的方式进行处理。

4、PLIC core

负责所有中断请求的仲裁和分发。
任何时候,最多只能有一个pending interrupt request存在于PLIC core中,由对应IP位保存。
PLIC core对每个interrupt source都会被赋予一个独立的priority和ID标识(见interrupt source section具体介绍)。
PLIC core包含一个matrix of interrupt enable bits IE,用以控制interrupt的enable。(见interrupt source section具体介绍)。
PLIC core对每个interrupt target都赋予一个独立的平台相关的priority threshold寄存器,用以控制interrupt发生的门限(见interrupt target section具体介绍)

5、interrupt request

由gateway发给PLIC core的中断请求。

6、interrupt notification

由PLIC core 发给各target的中断请求。
PLIC core为每个target赋予了一个external interrupt pending bit EIP,表示有待处理的interrupt。EIP的值可以被source,target或者其他源进行修改。(RISCV此处的EIP表述应该和之前的IP是同一个意思,只是名词不同)。
EIP发送给target的过程被称为interrupt notification。如果target是RISCV core,notification会赋予对应privilege level的xeip bit。一个简单的实现是将PLIC的EIP直接硬链接到target的xeip上;复杂些的设计可以通过message实现。
PLIC core只支持multicasting,即interrupt会发给所有符合条件的target,并不会选择其中之一发送。这样虽然响应较快,但会带来一些冗余处理。软件可以通过控制IE bits间接改善。首先claim的target会负责该interrupt的处理,PLIC core只保证对于EIP的修改所有对应的targets都可见。

7、interrupt claim

由target返回给PLIC core的响应信号,表示请求接受。通常实现为对一个non-idempotent memory mapped I/O device register read。
PLIC core收到claim后,会选出最高优先级的source ID,并将其对应的IP清除。这个ID会发送给target。如果ID为0,表示没有需要处理的中断。
claim被PLIC core接受后,次优先级的interrupt会显现出来,因此对应的EIP可能并不会被清0。因此target可以在退出中断服务程序前检查local xeip bit,确认是否有pending 的EIP。
PLIC支持target在EIP=0的情况下仍然发起claim。这是为了支持某些target的threshold设置为最高,不接受中断打断,但使用claim方式进行查询。。

8、interrupt completion

由target 返回给PLIC core的完成响应信号。通常实现为对一个non-idempotent memory mapped I/O device register write。

9、global interrupt handling

基本过程为:
global interrupt首先发送给interrupt gateway,由gateway负责产生interrupt request,发送给PLIC core;
PLIC core将每个interrupt request储存在内部的interrupt pending bits IP中;
PLIC core将interrupt notification发送给一个或者多个targets,如果该targets有enabled pending interrupt, 并且priority超过了per-target threshold;
当target接受了该external interrupt,会发送一个interrupt claim request给PLICcore,用以取得对应该target的最高优先级的pending interrupt,同时将对应的IP bit清零;
当target完成了中断服务,需发送一个interrupt completion message给对应的interrupt gateway表示中断完成。接下来gateway可以发送另一个interrupt request给该target。

10、control access to PLIC

in expected use case,只有machine mode才可以配置source priority, pending和IE。其他privilege level的请求通过响应的ABI/SBI/HBI向machine mode请求。
lower than machine level的interrupt handler只能claim和completion,以及配置interrupt threshold。
对相关memory mapped寄存器可以通过physical memory protection或者virtual memory page protection进行保护。

文章出处:https://blog.csdn.net/moonllz/article/details/52251788

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值