发布: 13_GICv3_LPI机制

This commit is contained in:
weidongshan
2022-01-25 02:31:53 +08:00
parent 9c62fdef63
commit 9ee503774b
22 changed files with 195 additions and 54 deletions

View File

@@ -1,7 +1,8 @@
## GICv3_LPI机制
参考资料:
参考资料:这几个PDF文档在GIT仓库的`IMX6ULL\doc_pic\08_Interrupt`
* 《ARM® Generic Interrupt Controller Architecture Specification Architecture version 2.0(IHI0048B_b_gic_architecture_specification_v2).pdf》
* 《IHI0069G_gic_architecture_specification.pdf》第5章
* 《GICv3_Software_Overview_Official_Release_B.pdf》
* [ARM GICgicv3架构-LPI](http://www.lujun.org.cn/?p=3921)
@@ -70,7 +71,6 @@ GIC V3里新增加了一类中断LPI(Locality-specific Peripheral Interrupts)
* 写寄存器GITS_TRANSLATER
* 设备把数据写入GITS_TRANSLATER寄存器写入的值被称为EventID
*
* 写寄存器GICR_SETLPIR
@@ -97,37 +97,60 @@ GIC V3里新增加了一类中断LPI(Locality-specific Peripheral Interrupts)
### 2. LPI的触发方式
### 3. LPI的触发方式
LPI有两种触发中断的方式
* 使用ITS把EventID 转换为LPI INTID会用到"GITS_TRANSLATER"
* 使用GICR_SETLPIR直接转发LPI INTID
* 把INTID直接写入GICR_SETLPIR寄存器
* 使用ITS把EventID 转换为LPI INTID会用到"GITS_TRANSLATER"寄存器
这两种方法只能支持一种。
#### 1.1 使用ITS
#### 3.1 使用GICR_SETLPIR
• GICR_INVLPIR.
• GICR_INVALLR.
• GICR_SYNCR.
这个寄存器格式如下:
![image-20220118094621265](pic/10_PCI_PCIe/110_lpi_with_its_block.png)
![image-20220124233357818](pic/10_PCI_PCIe/122_gicr_setlpir.png)
#### 1.2 不使用ITS
• GICR_SETLPIR.
• GICR_CLRLPIR.
LPI支持多达8192个中断这些中断的配置信息、挂起信息都要保存在内存里。因为寄存器可没那么大空间。
![image-20220118094730343](pic/10_PCI_PCIe/111_lpi_without_its_block.png)
把LPI的中断号写入这个寄存器即可触发中断。
### 2. ITS
#### 3.2 使用ITS
#### 2.1 ITS tables
ITS的意思是Interrupt Translation Service中断转换服务。
#### 2.2 Device table
![image-20220124234144934](pic/10_PCI_PCIe/123_its.png)
能产生MSI中断的设备都有一个DeviceDI(设备ID)它产生的每一个MSI中断都有一个EventID(事件ID)。"DeviceID+EventID"组合被传入ITSIDS会把它们转换为INTID。
过程如下:
* 外设发生中断消息(Interrupt Message)到ITS
* 外设只要写GITS_TRANSLATER就可以发送消息这个寄存器格式如下
![image-20220125000929612](pic/10_PCI_PCIe/125_GITS_TRANSLATER.png)
* 消息里包含有DeviceID(哪一个设备)、EventID(这个设备的哪一个中断)
* ITS使用DeviceID在Device Table中找到一项
* 只有一个Device Table
* 每一个能发生MSI中断的设备在里面都有一项它指向这个设备的Interrupt Translation Table(中断转换表简称ITT)
* 每一个能发生MSI中断的设备都有一个ITT
* ITS使用EventID在ITT中找到一项从中返回INTID和Collection ID
* ITS使用Collection ID在Collection Table中找到一项从中返回"Target Redistributor"中断发给哪个CPU
* ITS把INTID发给Redistributor
![image-20220124235831275](pic/10_PCI_PCIe/124_its_steps.png)
![image-20220125001703070](pic/10_PCI_PCIe/126_its_tables.png)
上图中Device Table、Interrupt Translation Table、Collection Table都是在内存里但是我们不能直接去设置内存。而是通过发送ITS命令来设置这些表格。
我们不研究ITS的内部细节暂且了解这些内容即可。

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

View File

@@ -139,7 +139,7 @@ git clone https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git
* 2021.03.23 发布"Input子系统"
```shell
02_先学习输入系统应用编程
02_先学习输入系统应用编程
APP_01.输入系统框架及调试
APP_02.现场编程读取获取输入设备信息
APP_03.查询_休眠唤醒_方式读取输入数据
@@ -276,7 +276,7 @@ git clone https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git
* 2021.06.26 发布"Interrupt子系统"
```shell
11_异常向量表的安装与调用
11_异常向量表的安装与调用
```
* 2021.06.28 发布"Interrupt子系统"
@@ -456,6 +456,11 @@ git clone https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git
```shell
12_INTx中断机制源码分析
```
* 2022.01.25 发布"PCI和PCIe子系统"
```shell
13_GICv3_LPI机制
```
## 6. 联系方式
* 官网http://www.100ask.net
@@ -468,10 +473,6 @@ git clone https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git
![](wechat.jpg)
```
```
```
```

View File

@@ -1,45 +1,156 @@
## GICv3_LPI机制
参考资料:
参考资料:这几个PDF文档在GIT仓库的`IMX6ULL\doc_pic\08_Interrupt`
* 《ARM® Generic Interrupt Controller Architecture Specification Architecture version 2.0(IHI0048B_b_gic_architecture_specification_v2).pdf》
* 《IHI0069G_gic_architecture_specification.pdf》第5章
* 《GICv3_Software_Overview_Official_Release_B.pdf》
* [ARM GICgicv3架构-LPI](http://www.lujun.org.cn/?p=3921)
### 1. GICv2
### 1. LPI
框图如下:
![image-20220124120054432](pic/10_PCI_PCIe/118_gic_v2_simple.png)
![image-20220124115053802](pic/10_PCI_PCIe/117_gic_v2.png)
GIC V2有3种中断
① 软件触发中断SGISoftware Generated Interrupt
这是由软件通过写入专用仲裁单元的寄存器即软件触发中断寄存器ICDSGIR显式生成的。它最常用于CPU核间通信。SGI既可以发给所有的核也可以发送给系统中选定的一组核心。中断号0-15保留用于SGI的中断号。用于通信的确切中断号由软件决定。
② 私有外设中断PPIPrivate Peripheral Interrupt
这是由单个CPU核私有的外设生成的。PPI的中断号为16-31。它们标识CPU核私有的中断源并且独立于另一个内核上的相同中断源比如每个核的计时器。
③ 共享外设中断SPIShared Peripheral Interrupt
这是由外设生成的中断控制器可以将其路由到多个核。中断号为32-1020。SPI用于从整个系统可访问的各种外围设备发出中断信号。
在GICv2里设备向中断控制器发出中断必须使用物理上的线路
![image-20220124122926019](pic/10_PCI_PCIe/120_gicv2_with_dedicate_signal.png)
在复杂系统中有成本上千的中断时,就需要成本上千的中断信号线,这太复杂了。
于是在GICv3中引入MSI("message-based interrupts"),设备往某个地址写入数值,即可触发中断。
### 2. GICv3
#### 2.1 MSI
在GICv3里添加了MSI("message-based interrupts"),设备往某个地址写入数值,即可触发中断:
![image-20220124123100899](pic/10_PCI_PCIe/121_gicv3_with_msi.png)
使用消息来发送中断好处是可以省略硬件线路。在大型系统中有成百上千个中断使用MSI可以省下很多线路。
#### 2.2 GICv3内部结构
GIC V3里新增加了一类中断LPI(Locality-specific Peripheral Interrupts)
框图如下:
![image-20220124125512793](pic/10_PCI_PCIe/119_gic_v3.png)
对于原来的SPI它也是可以使用MSI的方式传递的这个功能是可选的。如果GICv3支持MSI方式的SPI要产生/清除中断时操作如下GIC寄存器
* 产生中断写寄存器GICD_SETSPI_NSR 或 GICD_SETSPI_SR
* 清除中断写寄存器GICD_CLRSPI_NSR 或 GICD_CLRSPI_SR
对于LPI中断有两种触发方式
* 写寄存器GITS_TRANSLATER
* 设备把数据写入GITS_TRANSLATER寄存器写入的值被称为EventID
* 写寄存器GICR_SETLPIR
#### 2.3 中断号
0~1023跟GICv2保存一致。
| INTID | 中断类型 | 描述 |
| ------------- | -------- | ------------------------ |
| 0~15 | SGI | |
| 16~31 | PPI | |
| 32~1019 | SPI | 设备发出的中断 |
| 1020~1023 | SPI | 用于特殊目的 |
| 1024~1055 | - | 保留 |
| 1056~1119 | PPI | 扩展的PPIGICv3.1才支持 |
| 1120~4095 | - | 保留 |
| 4096~5119 | SPI | 扩展的SPIGICv3.1才支持 |
| 5120~8191 | - | 保留 |
| 8192~芯片实现 | LPI | |
### 3. LPI的触发方式
LPI有两种触发中断的方式
* 使用ITS把EventID 转换为LPI INTID会用到"GITS_TRANSLATER"
* 使用GICR_SETLPIR直接转发LPI INTID
* 把INTID直接写入GICR_SETLPIR寄存器
* 使用ITS把EventID 转换为LPI INTID会用到"GITS_TRANSLATER"寄存器
这两种方法只能支持一种。
#### 1.1 使用ITS
#### 3.1 使用GICR_SETLPIR
• GICR_INVLPIR.
• GICR_INVALLR.
• GICR_SYNCR.
这个寄存器格式如下:
![image-20220118094621265](pic/10_PCI_PCIe/110_lpi_with_its_block.png)
![image-20220124233357818](pic/10_PCI_PCIe/122_gicr_setlpir.png)
#### 1.2 不使用ITS
• GICR_SETLPIR.
• GICR_CLRLPIR.
LPI支持多达8192个中断这些中断的配置信息、挂起信息都要保存在内存里。因为寄存器可没那么大空间。
![image-20220118094730343](pic/10_PCI_PCIe/111_lpi_without_its_block.png)
把LPI的中断号写入这个寄存器即可触发中断。
### 2. ITS
#### 3.2 使用ITS
#### 2.1 ITS tables
ITS的意思是Interrupt Translation Service中断转换服务。
#### 2.2 Device table
![image-20220124234144934](pic/10_PCI_PCIe/123_its.png)
能产生MSI中断的设备都有一个DeviceDI(设备ID)它产生的每一个MSI中断都有一个EventID(事件ID)。"DeviceID+EventID"组合被传入ITSIDS会把它们转换为INTID。
过程如下:
* 外设发生中断消息(Interrupt Message)到ITS
* 外设只要写GITS_TRANSLATER就可以发送消息这个寄存器格式如下
![image-20220125000929612](pic/10_PCI_PCIe/125_GITS_TRANSLATER.png)
* 消息里包含有DeviceID(哪一个设备)、EventID(这个设备的哪一个中断)
* ITS使用DeviceID在Device Table中找到一项
* 只有一个Device Table
* 每一个能发生MSI中断的设备在里面都有一项它指向这个设备的Interrupt Translation Table(中断转换表简称ITT)
* 每一个能发生MSI中断的设备都有一个ITT
* ITS使用EventID在ITT中找到一项从中返回INTID和Collection ID
* ITS使用Collection ID在Collection Table中找到一项从中返回"Target Redistributor"中断发给哪个CPU
* ITS把INTID发给Redistributor
![image-20220124235831275](pic/10_PCI_PCIe/124_its_steps.png)
![image-20220125001703070](pic/10_PCI_PCIe/126_its_tables.png)
上图中Device Table、Interrupt Translation Table、Collection Table都是在内存里但是我们不能直接去设置内存。而是通过发送ITS命令来设置这些表格。
我们不研究ITS的内部细节暂且了解这些内容即可。

Binary file not shown.

View File

@@ -78,7 +78,13 @@ rockchip_pcie_legacy_int_handler
```c
pci_enable_msi_range
msi_capability_init
ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSI);
pci_msi_domain_alloc_irqs(domain, dev, nvec, type);
msi_domain_alloc_irqs(domain, &dev->dev, nvec)
// 在ITS里设置devid
ret = ops->msi_prepare(domain, dev, nvec, &arg);
__irq_domain_alloc_irqs
```
@@ -213,11 +219,11 @@ msix_capability_init/msi_capability_init
// its_get_event_id:
// d->hwirq - its_dev->event_map.lpi_base;
msg->data = its_get_event_id(d);
// 设置msi-x的entry地址
irq_chip_write_msi_msg(irq_data, &msg);
data->chip->irq_write_msi_msg(data, msg);
pci_msi_domain_write_msg
__pci_write_msi_msg(desc, msg);
// 设置msi-x的entry地址
irq_chip_write_msi_msg(irq_data, &msg);
data->chip->irq_write_msi_msg(data, msg);
pci_msi_domain_write_msg
__pci_write_msi_msg(desc, msg);
__pci_write_msi_msg(desc, msg);
// 对于MSI-X

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB