The GICv3 architecture supports the ARM TrustZone technology. Each INTID must be assigned a group and security setting.

每一个中断都需要配置安全态和分组。

中断安全态及中断分组

gicv3 为了兼容 armv8 引入了支持2种安全状态(secure state),根据 secure 状态,分为安全中断和非安全中断。也可以配置成只支持一种安全状态。显而易见,下图中前两组是安全中断,NSG1 是非安全中断。

In a system with two Security states, an interrupt is configured as one of the following:
A Group 0:ARM expects these interrupts to be handled at EL3.
A Secure Group 1:ARM expects these interrupts to be handled at Secure EL1.
A Non-secure Group 1:ARM expects these interrupts to be handled at Non-secure EL2 in systems using virtualization,or at Non-secure EL1 in systems not using virtualization.GICD_IGROUPR<n> and GICD_IGRPMODR<n> configure the interrupt group for SPIs. n is greater than zero.
GICR_IGROUPR0 and GICR_IGRPMODR0 configure the interrupt group for SGIs and PPIs.

中断安全态控制

中断安全态由 GICD_CTLR 寄存器的 DS bit,表示是否支持2种安全模式。该位为0表示支持2种安全态,为1表示只支持一种安全态,此时只有两个中断分组,分别是 group0 & 1,需要注意的是 DS 位被 置1 后只有处理器复位才能清除该标志。开启两个安全态时会在中断 configure, ack, priority drop, deactivation 中进行安全态检查。

When GICD_CTLR.DS == 0, LPIs are always Non-secure Group 1 interrupts.
When GICD_CTLR.DS == 1, LPIs are always Group 1 interrupts.When GICD_CTLR.DS == 0
• The GIC supports two Security states, Secure state and Non-secure state.
• The GIC supports three interrupt groups:
— Group 0.
— Secure Group 1.
— Non-secure Group 1.
这个时候 Group 0 中断始终是安全态的,非安全态下无法访问 Group 0 相关的寄存器。When GICD_CTLR.DS == 1:
• The GIC supports only a single Security state. This can be either Secure state or Non-secure state.
• The GIC supports two interrupt groups:
— Group 0.
— Group 1.

不同安全态下访问该寄存器的视图是不一样的:
当系统支持多个中断安全态时从 安全态 访问该寄存器:

当系统支持多个中断安全态时从 非安全态 访问该寄存器:

当系统支持1个中断安全态时从 安全或者非安全态 访问该寄存器:

中断线映射 IRQ FIQ

gicv3 将 cpu interface 从gic中抽离,放入到了cpu中,cpu interface 通过 gic stream 接口与gic IRI 进行通信。当gic要发送中断时gic 通过 gic stream 接口给 cpu interface 发送中断命令,cpu interface 收到中断命令后,根据中断线映射配置,决定是通过 IRQ 还是 FIQ 管脚向 cpu 发送中断。中断线映射根据中断 group 以及当前 cpu 所处的 el 以及 seucre 状态来决定。

Group 0 interrupts are always signaled as FIQs. Group 1 interrupts are signaled as either IRQs or FIQs depending on the current Security state and Exception level of the PE.

可以看到 group0 的中断均为 fiq, el3 时触发的中断均为 fiq,另外可以发现 cpu 在某个安全态下运行,发生了非本安全态的中断都是 fiq。这是因为通常我们会把 fiq 路由到 el3 去处理,此时 el3 的组件会完成两个安全态上下文的切换,把中断分发给相应的安全或非安全 OS 处理。fiq 路由到 el3,可由 SCR_EL3.FIQ==1 完成。

GICv3 编程模型

Interrupt Controller 中的 Distributor, Redistributor, CPU Interface 需要按照不同顺序配置。Distributor 是所有CPU都对应的,这个只要在第一个CPU启动时配置就可以了,对于 Redistributor 和 CPU Interface 是 PER-CPU 对应的,所以在SECONDARY CPU 启动时候需要配置各自的组件。

GICv3 regs

Distributor, Redistributor, CPU interfaceGICD_* 所有 PE 共享一套
GICR_* 每个 PE 各有一套CPU interface 每个 PE 各有一套
在 enable system regsiter interface 情况下是ICC_*_ELn
在 memory mapped 情况下是GICC_*

部分寄存器是内存映射的 (memory-mapped),有些是直接系统寄存器访问 (system register access)。

部分寄存器在支持 legacy 操作时采用内存映射,在 GICv3 模式下使用系统寄存器访问。

CPU interface 支持采用系统寄存器访问的方式。

In GICv3 the CPU Interface registers are accessed as System registers (ICC_*_ELn). Software must enable the System register interface before using these registers. This is controlled by the SRE bit in the ICC_SRE_ELn registers, where “n” specifies the Exception level (EL1-EL3).

GICv3 configuration

Global settings

使能亲和性路由和各个 group 中断。GICD_CTLR

  • Enable Affinity routing (ARE bits)
  • Enables group interrupt

Individual PE settings

redistributor 设置

唤醒即可。GICR_WAKER

  • Clear GICR_WAKER .ProcessorSleep to 0
  • Poll GICR_WAKER .ChildrenAsleep until it reads 0

cpu interface 配置

使能系统寄存器访问,设置中断屏蔽优先级,抢占配置,设置中断 EOI 模式,使能对应的中断。

  • Enable System register access ICC_SRE_ELn
  • Set priority mask and binary point registers ICC_PMR_EL1 and ICC_BPRn_EL1
    The Priority Mask sets the minimum priority an interrupt must have in order to be forwarded to the PE. The Binary Point register is used for priority grouping and preemption.
  • Set EOI mode ICC_CTLR_EL1 and ICC_CTLR_EL3
  • Enable signaling of each interrupt group
    The signalling of each interrupt group must be enabled before interrupts of that group will be forwarded by the CPU interface to the PE. To enable signaling software must write to ICC_IGRPEN1_EL1 register for Group 1 interrupts and ICC_IGRPEN0_EL1 registers for Group 0 interrupts. ICC_IGRPEN1_EL1 is banked by Security state. This means that ICC_GRPEN1_EL1 controls Group 1 for the current Security state. At EL3, software can access both Secure Group 1 interrupt enables and Non-secure Group 1 interrupt enables using ICC_IGRPEN1_EL3.

处理器设置

为了让处理器能够处理中断,处理器自身也要做相应的配置。

  • Routing controls。SCR_EL3 and HCR_EL2,分别可以配置中断到 EL3 还是 EL2 处理。
    路由选择决定了中断被哪个 el 所处理,即采用哪个异常级的中断向量表。
  • Interrupt masks。除了 GIC 会进行中断屏蔽外,处理器本身 PSTATEDAIF 也可以进行屏蔽。
  • Vector table。VBAR_ELn

以上三者除了 PSTATE 复位会有值外其他寄存器都是 UNKNOWN,因此必须初始化。

SPI PPI SGI configuration

前面把基本的环境都配置好了,对于每个中断而言,还有各自的属性需要配置。
SPI 使用 GICD_*,PPI 和 SGI 使用 GICR_*。这里属性就是中断优先级、中断分组、触发类型、使能,对于 SPI 还有目标PE。

1. Priority (GICD_IPRIORITYn, GICR_IPRIORITYn)
0x00 is the highest possible priority, and 0xFF is the lowest possible priority.
An interrupt controller is not required to implement all 8 priority bits. A minimum of 5
bits must be implemented if the GIC supports two Security states. A minimum of 4 bits
must be implemented if the GIC support only a single Security state.2. Group (GICD_IGROUPn, GICD_IGRPMODn, GICR_IGROUP0, GICR_IGRPMOD0)
前面提到了,每个中断都必须分配到中断组里去,它们可以分别是 Group 0, Secure Group 1 and Non-secure Group 1.3. Edge-triggered/level-sensitive (GICD_ICFGRn, GICR_ICFGRn)
SGIs are always treated as edge-triggered, and therefore GICR_ICFGR0 behaves as RAO/WI for these interrupts.4. Enable (GICD_ISENABLERn, GICD_ICENABLER, GICR_ISENABLER0, GICR_ICENABLER0)
Each INTID has an enable bit. Set-enable registers and Clear-enable registers remove the requirement to perform read-modify-write routines.
推荐某个中断在上面配置完成前都不要使能该中断。特别的,如果要变更某中断的配置,推荐首先不使能这个中断然后再继续操作。5. 对于 SPI 而言,还需要配置其目标 PE。GICD_IROUTERn
GICD_IROUTERn.Interrupt_Routing_Mode == 0
The SPI is to be delivered to the PE A.B.C.D, the affinity co-ordinates specified in the register.GICD_IROUTERn.Interrupt_Routing_Mode == 1
The SPI can be delivered to any connected PE that is participating in distribution of the interrupt group.
意思是每次中断触发去往哪个核不是由软件决定的。
This type of routing is referred to as 1-of-N.A PE can opt-out of receiving 1-of-N interrupts. This is controlled by the DPG1S, DPG1NS and DPG0 bits in GICR_CTLR.

后记

从上面的配置过程看,关闭或者不响应某个中断可以从各个层面去控制。
在 distributor 处可以关闭某个 group 的中断,注意这里是全局关某个 group,GICD_CTLR
在 cpu interface 处也可以关闭该 interface 某个 group 的中断,ICC_IGRPEN0_EL1 & ICC_IGRPEN1_EL1 or ICC_IGRPEN1_EL3
对于每个中断,同样有单独的使能寄存器。(GICD_ISENABLERn, GICD_ICENABLER, GICR_ISENABLER0, GICR_ICENABLER0)
当然 PE 层面也可以实现屏蔽,这是全局屏蔽。DAIF

ARM GIC (二)GICv3 中断安全态、分组及编程模型相关推荐

  1. 【转】ARM GIC中断系列(二):gicv2架构基础

    原文来自前辈:http://www.lujun.org.cn/?p=3861 真的很优秀的文章 ARM的cpu,特别是cortex-A系列的CPU,目前都是多core的cpu,因此对于多core的cp ...

  2. ARM GIC(五) ARM TrustZone如何支持安全中断 分析笔记。

    目录 CPU是如何支持安全中断的? GIC是如何支持安全中断的? 外设如何支持安全中断 TF-A2.6.0 源码分析 前几篇博文主要梳理了GIC V3架构基础,中断全生命周期,以及中断IRQ.FIQ基 ...

  3. Linux 中断管理之ARM GIC V3 初始化

    1.ARM GIC V3中断控制器介绍 GIC(Generic Interrupt Controller)是一个通用的中断控制器,用来接收硬件中断信号,并经过一定处理后,分发给对应的CPU进行处理.G ...

  4. Linux中断子系统(二)中断控制器GIC驱动分析

    Linux中断子系统(二)中断控制器GIC驱动分析 备注:   1. Kernel版本:5.4   2. 使用工具:Source Insight 4.0   3. 参考博客: Linux中断子系统(一 ...

  5. Linux 中断 —— ARM GIC 中断控制器

    GIC(Generic Interrupt Controller)是ARM公司提供的一个通用的中断控制器,其architecture specification目前有四个版本,V1-V4(V2最多支持 ...

  6. ARM GIC(三) gicv2架构

    ARM的cpu,特别是cortex-A系列的CPU,目前都是多core的cpu,因此对于多core的cpu的中断管理,就不能像单core那样简单去管理,由此arm定义了GICv2架构,来支持多核cpu ...

  7. ARM GIC简介与Linux中断处理分析

    先简单说明一下GIC(具体详尽的介绍请查阅ARM GIC相关文档) GIC即general interrupt controller. 它是一个架构,版本历经了GICv1(已弃用),GICv2,GIC ...

  8. [ARM]GIC相关知识

    ARM GIC GICv2-GICv3 重要变化 cpu interface GICv2架构,cpu interface是实现在gic内部,而且gic的寄存器,都是memory-mapped方式访问. ...

  9. Linux(十二)中断系统

    STM32 的中断系统主要有以下几个关键点: ①. 中断向量表. ②. NVIC(内嵌向量中断控制器). ③. 中断使能. ④. 中断服务函数. 中断向量表 中段向量表就是说明都有什么中断,这些中断服 ...

最新文章

  1. 快速单目三维人手和身体的运动捕捉回归与整合
  2. python中dom是什么意思_python--BOM和DOM
  3. 第五讲 计算机体系结构 内存层次
  4. 03--STL算法(常用算法)
  5. 2017.8.16 喵星球上的点名 思考记录
  6. 特斯拉召回部分进口Model S、Model X电动汽车
  7. 不会python怎么了?靠敏捷BI和数据可视化,照样去阿里腾讯
  8. ant a-table 树表格级联选择
  9. BZOJ3757: 苹果树【树上莫队】
  10. hdu 5178 pairs (线性探查问题)
  11. 小学生python游戏编程7----角色精灵定义
  12. 4.1 手工编写第一个性能测试脚本
  13. html idv垂直居中,2011最新整理idv+css标准.doc
  14. BZOJ 2563 阿狸和桃子的游戏 (贪心)
  15. 用ajax+jquery+json+css3+html5实现登录、注册、以及主页面的增删改查
  16. 上海车展:17.88万圆百万跑车梦,哪吒GT开启跑车新纪元
  17. Spring_AOP(execution表达式)
  18. Tableau画桑基图
  19. 计算机基本办公用法哪里学,使用电脑办公必须学会的七大办公技巧!
  20. PHP+MYSQL 可视化Echarts 完整源码,小白总结

热门文章

  1. 【项目经理入门期】编写里程碑计划
  2. JAVA面试大全(持续更新中...)
  3. 欧姆龙CP/CJ系列PLC以太网通讯方案
  4. Windows7+CentOS双系统同一硬盘
  5. 批量安装Windows系统
  6. python本科毕设_关于本科毕设选题请教问题
  7. 记录一次docker基础操作错误Error response from daemon: You cannot remove a running container
  8. 怎么录制明日之后游戏视频
  9. codeforces 571A Lengthening Sticks 组合数学 插板法
  10. 【雕爷学编程】Arduino动手做(67)---BMP180气压传感器