ARM GIC(一)GICv3 基本架构和中断生命周期

GIC 简介

GIC 的全称为 General Interrupt Controller,主要作用可以归结为:
接受硬件中断信号并进行简单处理,通过一定的设置策略,分给对应的CPU进行处理。

Terminology

IRI: Interrupt Routing Infrastructure. The Distributor, Redistributor and ITS are collectively known as an IRI.
     The IRI performs interrupt grouping, interrupt prioritization, and controls the forwarding of interrupts
     to the CPU interfaces.
ITS: Interrupt translation service, is an OPTIONAL hardware mechanism in the GICv3 architecture that routes
     LPIs to the appropriate Redistributor, and the GICv4 implementations must include at least one ITS.

ARM 中断源分类

  • SGI: Software Generated Interrupt,软件产生中断,中断号是 0-15。通过向SGI寄存器写数触发,可用于CPU间的通信,比如时间同步,全局进程调度信息等。每个 PE 都有这么多 SGI 号。The Redistributor provides the configuration settings for PPIs and SGIs.
  • PPI: Private Peripheral Interrupt,私有外设中断,中断号是 16~31。这些中断一般是发送给特定的CPU的,比如每个CPU有自己对应的 Generic Timer,产生的中断信号就发送给这个特定的CPU进行处理。每个 PE 都有这么多 PPI 号。The Redistributor provides the configuration settings for PPIs and SGIs.
  • SPI: Shared Peripheral Interrupt,共享外设中断,中断号是 32~1019。比如按键触发一个中断,手机触摸屏触发的中断,共享的意思是说可以从多个 PE 中选择一个发送处理,当然也可以指定发送给某个 PE。The Distributor provides the routing configuration for SPIs, and holds all the associated routing and priority information.
  • 特殊中断号。1020-1023。这个在 GICv3 中用于指示特别的场景,例如给 EL3 的软件使用。
  • 保留中断号,1024-8191
  • LPI: Locality-specific Peripheral Interrupt,局部外设中断,中断号 >=8192 。LPI 没有 active or active and pending state,得到响应后由处理器自动转入 inactive 状态。LPIs are new in GICv3, and they are different to the other types of interruptin a number of ways . In particular, LPIs are always message-based interrupts,and their configuration is held in tables in memory rather than registers. NOTE: LPIs are only supported when GICD_CTLR.ARE_NS==1.

GIC V3 结构

在这里插入图片描述

  • The Distributor provides the routing configuration for SPIs, and holds all the associated routing and priority.
  • The Redistributor provides the configuration settings for PPIs and SGIs. A Redistributor always presents the pending interrupt with the highest priority to the CPU interface in finite time.

Distributor

The Distributor performs interrupt prioritization and distribution of SPIs and SGIs to the
Redistributors and CPU interfaces that are connected to the PEs in the system.
GICD_CTLR provides global settings for:
• Enabling affinity routing.
• Disabling security.
• Enabling Secure and Non-secure Group 1 interrupts.
• Enabling Group 0 interrupts.

For SPIs, the Distributor provides a programming interface for:
• Enabling or disabling SPIs.
• Setting the priority level of each SPI.
• Routing information for each SPI.
• Setting each SPI to be level-sensitive or edge-triggered.
• Generating message-based SPIs.
• Assigning each SPI to an interrupt group.
• Controlling the pending and active state of SPIs.

The Distributor registers are identified by the GICD_ prefix.

对所有 CPU 都有效,主要控制 SPI 的相关属性。

Redistributor (GIC_v3, v4)

For each connected PE there is a Redistributor.
Redistributors provide a programming interface for:
• Identifying, controlling, and configuring supported features to enable interrupts and
  interrupt routing of the implementation.
• Enabling or disabling SGIs and PPIs.
• Setting the priority level of SGIs and PPIs.
• Setting each PPI to be level-sensitive or edge-triggered.
• Assigning each SGI and PPI to an interrupt group.
• Controlling the pending state of SGIs and PPIs.
• Controlling the active state of SGIs and PPIs.
• Power management support for the connected PE.
• Where LPIs are supported, base address control for the data structures in memory that
  support the associated interrupt properties and their pending status.
• Where GICv4 is supported, base address control for the data structures in memory
  that support the associated virtual interrupt properties and their pending status.

The Redistributor registers are identified by the GICR_ prefix.

对各个 CPU 有效,主要控制 SGI 和 PPI 的属性。

CPU interface

Each Redistributor is connected to a CPU interface.
The CPU interface provides a programming interface for:
• General control and configuration to enable interrupt handling in accordance with the
  Security state and legacy support requirements of the implementation.
• Acknowledging an interrupt.
• Performing a priority drop.
• Deactivation of an interrupt.
• Setting an interrupt priority mask for the PE.
• Defining the preemption policy for the PE.
• Determining the highest priority pending interrupt for the PE.

对各个 CPU 有效,控制中断是否上报,中断 ack,屏蔽,抢占等。

Interrupt Prioritization

数值越小优先级越高,即 0 优先级最高。优先级是 8-bit 无符号数,实际实现可以采用更少的 bits 来表示,此时相当于优先级分组,比如只用了高 4-bit 来表示,低 4-bit 将被忽略,那么原来的 256 个优先级变成了 16个优先级,原来 0-15 都映射到了 0 优先级上。

In a multiprocessor implementation, ICC_CTLR_EL1.PRIbits and ICC_CTLR_EL3.PRIbits indicate the number of priority bits implemented, independently for each target PE.

GICD_IPRIORITYR<n> 控制每个 SPI 的优先级。
GICR_IPRIORITYR<n> 控制每个 SGI 和 PPI 的优先级。

可以通过 BPR 寄存器控制中断的抢占,注意只比较 group priority

The Binary Point Registers split a priority value into two fields, the group priority and the subpriority. When
determining preemption, all interrupts with the same group priority are considered to have the same priority,
regardless of the subpriority.

Affinity Route

GICv3 uses affinity routing to identify connected PEs and to route interrupts to a specific PE or
group of PEs. The affinity of a PE is represented as four 8-bit fields:
<affinity level 3>.<affinity level 2>.<affinity level 1>.<affinity level 0>

可以把它类比成 IPv4 地址,只是个 PE 编码 :)。

每个 PE 的 affinity 放在寄存器 MPIDR_EL1 中。
在这里插入图片描述

SPIs are routed using an affinity address and the routing mode information that is held in `GICD_IROUTER<n>`.
SGIs are routed using the affinity address and routing mode information that is written by software when it
generates the SGI.

SGIs are generated using the following registers:
• ICC_SGI0R_EL1.
• ICC_SGI1R_EL1.
• ICC_ASGI1R_EL1.

Interrupt lifecycle

StateDetails
inactiveAn interrupt that is not active or pending. The interrupt source is not currently asserted.
pendingAn interrupt that is waiting to be serviced by a target processor. The interrupt source has been asserted, but the interrupt has not yet been acknowledged by a PE.
activeAn interrupt that has been acknowledged by a processor and is being serviced but has not completed
active and pendingA processor is servicing the interrupt and the GIC has a pending interrupt from same source

在这里插入图片描述

中断的生命周期和中断的触发方式息息相关。

电平触发

在这里插入图片描述

  • Inactive to Pending
    中断使能且优先级满足触发要求,cpu interface 向 PE asserts 该中断,等待 PE 处理。
  • Pending to Active & Pending
    中断处理程序中 PE ACK 了 pending 的中断。此时 cpu interface de-asserts 该中断。
  • Active and Pending to Active
    在 ACK 的基础上,中断源拉低了触发电平,这通常是中断处理程序往外设寄存器写东西,清除了该中断。
  • Active to Inactive
    中断处理程序表示中断处理完毕,EOI 了该中断。(End of Interrupt)
边沿触发

在这里插入图片描述

  • Inactive to Pending
    中断使能且优先级满足触发要求,cpu interface 向 PE asserts 该中断,等待 PE 处理。
  • Pending to Active
    中断处理程序中 PE ACK 了 pending 的中断。此时 cpu interface de-asserts 该中断。
  • Active to Active and Pending
    中断在处理时又再次触发。
  • Active and Pending to Pending
    PE 在处理完上一个中断后,EOI 该中断,之后 cpu interface re-asserts pending 的第二个中断。

主要描述 ack -> priority drop -> deactive

Activation

通过以下寄存器可以获取当前在PE上被触发的中断号,读操作会转移中断的状态到 active。
The interrupt handler reads ICC_IAR0_EL1 for Group 0 interrupts, and ICC_IAR1_EL1 for Group 1 interrupts.
This read acts as an acknowledge for the interrupt. The effects of reading ICC_IAR0_EL1 and ICC_IAR1_EL1 on the state of a returned INTID are not guaranteed to be visible until after the execution of a DSB.

Priority drop

After an interrupt has been acknowledged, a valid write to ICC_EOIR0_EL1 for Group 0 interrupts, or a valid write to ICC_EOIR1_EL1 for Group 1 interrupts, results in a priority drop. It is required for each acknowledged interrupt, even for LPIs which do not have an active state. A priority drop must be performed by the same PE that activated the interrupt.
值得注意的是,写 EOI 寄存器的顺序和读 IAR 寄存器的顺序必须是严格相反的。

Deactive

PPIs, SGIs, and SPIs have an active state in the IRI and must be deactivated.
SGIs and PPIs must be deactivated by the PE that activated the interrupt. SPIs can be deactivated by a different PE.
Interrupt deactivation is required to change the state of an interrupt either:
• From active and pending to pending.
• From active to inactive.
  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
# 学习对象在全民造车、造芯的大时代,在努力去解决卡脖子的时代,ASIC硬件、SOC底层软件、Linux Kernel等操作系统软件(内核/驱动)、软硬件方面的系统架构师等的岗位需求也越来越明显,社会一直都是非常缺人的,缺的是核心的那一小撮、领头的那一小撮,社会所缺的更是能够软硬件融合的那一小撮人……总之,要想在这个时代,站稳自己的脚跟,能够在大公司或行业上拥有一席之地,就必需深入学习底层技术原理,核心技术才是您的看家本领。本课程设计之初,主要针对SOC底层软件开发的者、系统开发者,或者励志成为这样的人。既适合资深/高级工程师来查缺补漏,又适合初级工程师入门。(理论上该课程和ASIC硬件电路设计无关,该课程偏软件,但事实购买该课程的做ASIC的同学已然超过了15%)适用人群1、芯片开发者(包括底层软件、或做ASIC硬件的)。不限行业,例如车、云、物联网、移动端等领域;2、汽车行业开发者(主机厂、tier1、SOC厂家、各级供应商);3、嵌入式开发者、kernel开发者、驱动、软件工程师;4、学生。既适合学生从入门到精通,也适合资深工程师查缺补漏;您的收益:1、全体系的掌握ARMv8/ARMv9的核心知识点(ARM基础、异常中断GIC、MMU/Cache、architecture...);2、掌握ARM架构、掌握SOC架构、掌握常规IP(gic、smmu、timer、AXI/ACE/CHI、TZC400...);3、快速熟悉常规系统软件(bootrom、spl、ATF、TEE、bootloader、kernel...), Secureboot安全启动...4、技术水平提升N个level, 掌握快速的学习方法;# 学习什么在ARM蓬勃发展的年代,不仅仅涉及到物联网IOT、移动领域(如手机)、汽车电子领域,现在还涉及到PC、服务器的,简直就是各行各业。ARMv8出来已经有10年了,ARMv9也2年时间了。在技术不断更新迭代的背景下,此时再去学习十五年前的ARMv7、二十年前的ARMv5/v6显然不是明智的选择。本课程主要基于当前最新的架构ARMv8的aarch64和ARMv9,如涉及具体的ARM Core IP主要还是以最新的ARM Core IP为主,软件架构也是以当前最主流的/未来所趋势的架构来讲解。以下也给大家列举初了一个ARM产品的timeline的总结(在本课程中有着大量的这种总结),从这张图中,您是可以清晰的看到本课程拥有独具一格的风格、拥有全网最新(且唯一)的资料总结或学习路线。# 本课程大纲和规划(课程持续更新中,课程总量统计:2022/10/02  当前是 61节课, 22小时)第一章:主要是快速学习: ARM简介、指令集、寄存器总结等。第二章:本系列视频的一大亮点,系统全面地讲解了arm异常中断gic等相关的软硬件知识,本人一直在倡导“学arm安全其实就是学arm架构,学arm架构其实就是学习arm的异常和中断”,异常中断是领着你进入架构的入门,是让你变成系统软硬件架构师的必走之路。第三章:安全专题,这也是本视频最核心的东西。因为你无论买书还是看博客等,你都很难找到讲解安全的教程,这里就是有和无的区别。本人系统的整理的安全的知识,带领你快速入门。第四章:mmu专题,透过事务看本质的讲解,白话式的演讲。在所有模块中,mmu也算是相对较简单模块。相信人人听得懂,人人学得会。第五章:cache专题,一切追求实事求是,不人云亦云,一切知识点都有迹可循,推翻了网络的很多观念。在众多模块中,cache算是一个比较难的模块。了解了cache后,才能算真正了解系统的软硬件架构。第六章:虚拟化,本人不擅长,会啥就随便讲点啥。(以后学会了再来补)第七章:architecture,就是零散和零碎的系统架构知识,如exclusive、arch timer、reset、系统启动、SOC设计、AMBA/AXI/ACE、DSU、WFE/WFI这样的。第八章: 新增的ARMv9 CCA/RME安全架构专题第九章:主要放置一些直播课。# 课程收益1、知道我学习什么,我要怎么去学习,从此之后有了一个明确的学习路线。2、认识一些共同目标的人,相互讨论问题,共同进步。勤学、共学、助学。3、ARM不再神秘,SOC不在神秘,让您短期内就能cover住全局4、熟悉ARM Architecture架构知识5、熟悉SOC架构知识6、熟悉主流的系统软件框架7、熟悉各项硬件原理和机制,如异常中断、MMU、cache、TLB、VMSA、Trustzone6、深入了解当前的系统架构、软硬件架构,能够看懂这些大家,将来也能够自己设计。7、熟悉系统的启动流程、Secureboot等8、熟悉各类标准和规范9、能够进入芯片厂商干活、能够在非芯片产生成为技术担当。10、学习资料的获取方法,会看11500多页的ARM手册,会看数以百计的ARM各项参考手册。 本课程会持续更新。也希望通过本课程的学习,能够让大家的ARMv8/ARMv9开发技术能有质的飞越,能找到自己心仪的工作。在购买之前,也建议大家看一看第一章第一节的课程介绍。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值