ver0.1
[看前序文章有惊喜,关注W\X\G=Z+H=“浩瀚架构师”,可以解锁全部文章]
前言
前序的文章中,我们介绍了SMMU页表的架构,为我们进一步研究SMMU的工作流程打下了基础。SMMU的核心作用还是帮助总线上接入它的Master进行地址翻译。这个翻译的过程就是找到一个物理地址(总线地址)返回给设备,让它拿着这个地址访问内存。这个过程和CPU的工作流程是一样的,只是CPU的PE-Core交给MMU的总是虚拟地址,而SMMU的情况就复杂了,这个我们也会在下文中都聊到。还是希望大家在阅读本文之前建立起对页表映射、地址翻译的感觉,然后再看SMMU的页表映射过程就很容易接受了。先看看前序文章吧,再进入正文:
(1) [A-13]ARMv8/ARMv9-Memory-虚拟地址翻译(页表映射过程)
(2) [A-20][V-07]ARMv8/v9-内存虚拟化(Stage-2 Translation)
正文
1.1 SMMU的工作模式
先看一下SMMU地址翻译的大致流程,搞清楚SMMU可以工作在哪些模式下,如图1-1所示。
1.1.1 两级翻译模式
这种模式下,设备输入的虚拟地址(VA)会经历全部的地址翻译过程,从VA-IPA-PA,返回给设备PA进行总线操作访问到自己想要交互的物理内存,图1-1左侧部分。我们后面的的章节也会对这种模式做重点讨论。
1.1.2 Bypass模式
第二种模式就是Bypass模式了,图1-1右边的绿色部分,之所以和红色部分重叠,原因是这种模式下会对两级翻译模式产生交叉影响。先来看看手册中对Bypass模式的介绍:
In bypass mode, the SMMU does not have to translate the addresses of incoming transactions. A stream or entire Security state can be set to bypass. This means the output address is equivalent to the input address. However, the other input transaction attributes, for example cacheability, can still optionally be overridden. There are three types of bypass:
Global bypass
When translation is bypassed for one Security state, all transactions are bypassed translation for that Security state. Software can set SMMU_()CR0.SMMUEN to 0 to enable global bypass. Software can also optionally set SMMU()GBPA to override input attributes.
Stream bypass
This type of SMMU bypass is available when SMMU(*_)CR0.SMMUEN = 1 . This is when a StreamID selects an STE configured to bypass(STE.Config). For a stream-based bypass, the attributes are configured using STE fields. STE.
{MTCFG,MemAttr,ALLOCCFG,SHCFG,NSCFG,PRIVCFG,INSTCFG} can override any attribute before the transaction is passed to the memory system
Stage bypass