A9芯片的mmu知识---Information returned by a translation table lookup

当进行一次MMU的translation过程时,不管是通过tlb查到的translation table descriptor,还是通过TTW查到的translation table descriptor,都会返回两种信息,一种是想要查询的物理地址,一种是这个物理地址的一些属性。
这些属性被分成三类,

A9芯片的mmu知识---Information returned by a translation table lookup - xxhalbert - xxhalbert的博客
A9芯片的mmu知识---Information returned by a translation table lookup - xxhalbert - xxhalbert的博客
 0b00 , Invalid
The associated VA is unmapped, and any attempt to access it generates a Translation fault.
Software can use bits[31:2] of the descriptor for its own purposes, because the hardware ignores
these bits.
0b01 , Page table
The descriptor gives the address of a second-level translation table, that specifies the mapping of the
associated 1MByte VA range.
0b10 , Section or Supersection
The descriptor gives the base address of the Section or Supersection. Bit[18] determines whether
the entry describes a Section or a Supersection.
If the implementation supports the PXN attribute, this encoding also defines the PXN bit as 0.
0b11 , Section or Supersection, if the implementation supports the PXN attribute
If an implementation supports the PXN attribute, this encoding is identical to 0b10 , except that it
defines the PXN bit as 1.
0b11 , Reserved, UNK/SBZP, if the implementation does not support the PXN attribute
An attempt to access the associated VA generates a Translation fault.
On an implementation that does not support the PXN attribute, this encoding must not be used.
 
 

一、Address map control(地址映射控制)
1、在translation table descriptor中有NS位标明所map的内存是secure还是non-secure的.
1)在secure translation tables中, 在descriptor中的NS bit标示了。
NS== 0, 表示映射的是一块Secure的物理地址空间。
NS== 1, 表示映射的是一块Non-Secure的物理地址空间。
2)在Non-Secure translation tables中,对应的NS位是0,没有意义,只能访问Non-Secure的空间。
arm文档中原话是:
In the Non-secure translation tables, the corresponding bit is SBZ. Non-secure accesses always access the
Non-secure physical address space, regardless of the value of this bit.
Memory accesses from Non-secure state can only access the Non-secure address map.
我的理解是在Non-secure translation tables中不应有对Secure物理空间的映射,即使有,
CPU在Non-secure的状态下,也不能访问有对secure物理地址做映射的translation table descriptor。
当cpu是处于non-secure状态的时候只能访问non-secure的地址映射.
当cpu是处于secure状态的时候能够访问non-secure的地址映射,也能访问secure的地址映射。

二、Access controls(访问控制)
这个决定在当前状态下,cpu能否访问被translation的物理地址。
1)Access permissions(访问权限)
(1)有两种,一种是由三位控制AP[2:0](当SCTLR.AFE位被置为0时)
 AP[2]AP[1:0] PL1 access Unprivileged access Description 
 0 00No access No access All accesses generate Permission faults 
 0 01 Read/writeNo access Access only at PL1 
 010 Read/write Read-only Writes at PL0 generate Permission faults 
 011 Read/write Read/write Full access 
 100 Reserved 
 101 Read-only No access Read-only, only at PL1 
 110 Read-only Read-only Read-only at any privilege level, deprecated(a) 
 111 Read-only Read-only Read-only at any privilege level(b) 
a. From VMSAv7, ARM strongly recommends use of the 0b11 encoding for Read-only at any privilege level.
b. This mapping is introduced in VMSAv7, and is reserved in VMSAv6.

(2)一种是由两位控制AP[2:1] (当SCTLR.AFE位被置为1时,AP[0]位被设为了access flag位)
Some documentation describes this as the  simplified access permissions model.
 AP[2],disable write accessAP[1],enable unprivileged access Access 
 00Read/write, only at PL1 
 0Read/write, at any privilege level 
 1Read-only, only at PL1 
 1Read-only, at any privilege level 

2)    Execute-never restrictions on instruction fetching
XN 控制为被access permissions允许的内存访问之上提供了一种附加的控制级别。
XN, Execute-never
当translation table descriptor 中XN位是1,当处理器尝试执行从所标示的内存区域读取的一条指令时一个permission fault被产生。而如果想要这个功能生效,这个区域的Domains必须被配成Client(关于Domains后面会讲到)。所以处理器能从一个内存区域中执行指令只有当处理器当前状态对于这个区域具有读权限,并且这个区域XN位被置为0。

PXN, Privileged execute-never
当translation table descriptor 中PXN位被置为1,当处理器处于PL1并且尝试执行从这个内存区域中读取到的指令时,会发生Permission fault。

3) Domains
domain是一些内存区域的集合。short-descriptor translation table format 支持16个domains,并且要求软件定义translation table时为每一个memory region分配一个domain.
  • Page tables和Sections的第一级translation table entry包括一个domain域。
  • Supersections 人translation table entries不包括domain域。short-descriptor format默认supersections为domain 0.
  • Second-level translation table entries 从父级第一级页表entry遗传一个domain设置。
  • 每一个TLB entry包括一个domain field。
domain field指明了是使用的16个domains中的哪一个,在DACR中每两位定义16个domains中的一个domain的允许的访问
功能,所有的访问功能有:
No access: Any access using the translation table descriptor generates a Domain fault.
Clients: On an access using the translation table descriptor, the access permission attributes are checked. Therefore, the access might generate a Permission fault. Managers: On an access using the translation table descriptor, the access permission attributes are not checked. Therefore, the access cannot generate a Permission fault.

4) Access flag(当SCTLR.AFE被设为1,AP[0]为access flag位):
当内存对应的translation table descriptor中的Access flag被设为了0后,access flag就能察觉出
这一内存 page或 section 之后的第一次被访问。
Access flag能够被软件管理,也能够被硬件管理,但使用硬件管理是被反对的。所以我们只分
析软件管理的case:
当一个access flag被设为0的translation table entry被读入TLB,会产生一个Access flag fault。
Access flag机制期待的流程是:当一个access flag fault产生,软件重置这个导致fault产生的
translation table entry中 access flag为1,以防下次访问又产生fault。由于access flag被置为0的entries
永远不会被放入TLB,所以意味着软件改 内存中的translation table entry时,不用考虑同时刷新TLB。

三、Attributes
这个属性指的是一个处理器在当前状态中能访问的被translation的物理地址的属性。这些属性定义了访问
目标内存区域所要求的行为(内存的类型、访问cache、是否这个内存区域是共享的并因此是一致的)。
分成两种:
-----------------------Note---------------------------------------------
  • The Short-descriptor format scheme without TEX remap is the scheme used in VMSAv6.
  • The B (Bufferable), C (Cacheable), and TEX (Type extension) bit names are inherited from earlier versions
of the architecture. These names no longer adequately describe the function of the B, C, and TEX bits
由于这个原因,我们只关注TEX remap 被enabled的情形。
--------------------------------------------------------------------------
1、Memory type and attributes:
又有两种方法来表现这两种属性。
1)直接通过translation table descriptor中的bits来指定。(SCTLR.TRE bit 设为0)
表示disable remap,此时在translation table descriptor中的TEX[2:0]、C、B bits定义内存区域属性。
2)间接的,通过table descriptor中的bits指定的寄存器来指定。(SCTLR.TRE bit 设为1)
TEX remap enabled. 此时在translation table descriptor中的TEX[0]、C、B bits指明了定义内存区域属性的MMU remap registers(1、PRRR:  the Primary Region Remap Register.  2、NMRR: the Normal Memory Remap Register.)
此时translation table descriptor中的TEX[2:1] 位被重新安排作为操作系统管理的位。
在这种配置里:
  • 软件定义translation tables必须编程PRRR和NMRR去定义7种有可能的内存区域属性。
  • 在translation table descriptors中的TEX[0]、C、B bits标明了PRRR和NMRR的索引。
  • 硬件使TEX[2:1]无用,TEX[2:1]由操作系统管理。
当TEX remap 被使能:
  • TEX[0]、C、B的所有8种组合中有7种组合描述了在PRRR和NMRR中的fields中如何定义区域属性;
  • 第8种组合是由实现的芯片定义的(A9没有定义)
  • PRRR中的4个bits定义是否区域是可共享的,在下面所要说的Shareability and the S bit, with TEX remap中定义。
对于translation table entry中TEX[0]、C、B位的每一种可能的编码,下表显示了PRRR和NMRR寄存器中哪些fields描述了内存区域属性。
 TEX[0]Memory type Inner cacheability Outer cacheability Outer Shareable  attribute(a,c)
 0PRRR[1:0] NMRR[1:0] NMRR[17:16] NOT(PRRR[24]) 
 0PRRR[3:2] NMRR[3:2] NMRR[19:18] NOT(PRRR[25]) 
 0PRRR[5:4] NMRR[5:4] NMRR[21:20] NOT(PRRR[26]) 
 0PRRR[7:6] NMRR[7:6] NMRR[23:22] NOT(PRRR[27]) 
 1PRRR[9:8] NMRR[9:8] NMRR[25:24] NOT(PRRR[28]) 
 1PRRR[11:10] NMRR[11:10] NMRR[27:26] NOT(PRRR[29]) 
 1IMPLEMENTATION DEFINED    
 1PRRR[15:14] NMRR[15:14] NMRR[31:30] NOT(PRRR[31]) 
 a. For details of the  Memory type and  Outer Shareable encodings see  PRRR, Primary Region Remap Register, VMSA on page B4-1700. For details of the  Cache attributes encodings see  Table B3-11 on page B3-1368.
b. Applies only if the memory type for the region is mapped as Normal memory.
c. Applies only if the memory type for the region is mapped as Normal or Device memory and the region is Shareable.

在A9中由于实现了Security Extensions,所以TEX remap registers和SCTLR.TRE位在Secure和Non-secure 状态下是banked.
1)首先由PRRR来决定内存是什么类型,Normal memory还是Device memory.
2)  其次,当PRRR指定为Normal memory时,NMRR决定这块内存是Inner cacheability还是Outer cacheability。
3)由DS、NS以及页表项中的S位决定内存是否支持共享。如果支持共享,由NOSn位来决定是Inner 共享还是Outer 共享。

在普通的操作中TEX remap寄存器必须是静态的。特别的,当remap寄存器被改变时,不论TLB是否cache了TEX remap的效果,都是不可预知的。
软件确保TEX remap registers 改变的同步的流程是:
1)执行 DSB 指令。确保任何使用旧的映射的内存访问己经完成。
2)写TEX remap 寄存器或SCTLR.TRE 位。
3)执行ISB指令。确保寄存器更新的同步。
4)整个TLB做Invalidate.
5)  执行DSB指令。确保上面的Invalidate的操作的完成。
6)Clean and invalidate all caches. 这个操作删除了任何与旧的映射相关的cached信息。
7)执行DSB指令。这确保第6步对cache维护操作的完成。
8)执行ISB指令。这确保指令同步。
上面的这些操作扩展了修改CP15寄存器时为了同步所做的标准操作。并且根据是否TEX remap被cache提供了实现的自由。
换句话说,如果没有开cache,就不需要做第6步以及下面的几步操作。

修改CP15寄存器时的标准同步操作为:



2、在translation table descriptor中的S bit标明了是否这个区域是可共享的。
按照是否enable TEX remap位,这也被分为两种情况:
  • Shareability and the S bit, without TEX remap
  • Shareability and the S bit, with TEX remap
用下面这个表就可以概括:
 Memory typeLPAE(a) implemented Remapping when S==0 Remapping when S==1 
 Strongly-orderedShareable Shareable 
 DeviceNo PRRR[16] PRRR[17] 
 DeviceYes Shareable Shareable 
 NormalPRRR[18] PRRR[19] 
   a. LPAE是Large Physical Address Extension的简写。

如果memory type是Strongly-ordered那么这个区域是Shareable的。
在shareability 被重新映射的情况下,PRRR中的适当的位标示了是否这个区域是共享或不共享。
PRRR[n] == 0 Not shareable.
PRRR[n] == 1 Shareable.
------Note------
当TEX remap 被使能,一个S是0的translation table entry能被映身做为Shareable memory.
------------------
3、Architectural status of PRRR and NMRR
这些寄存器的功能是由系统结构定义的,只有在使用short-descriptor translation table formats并且满足下列两种情形之一:
  • SCTLR.TRE is set to 1
  • SCTLR.TRE is set to 0 and the processor has not invoked any IMPLEMENTATION DEFINED mechanism using MMU remap.(A9不考虑这种case)

1) PRRR, Primary Region Remap Register, VMSA
目的:   PRRR控制TEX[0]、C、B的顶级映射内存区域属性。
使用限制:只能在PL1或更高级别访问。
配置: 在实现Security Extensions时,是Banked.
A9芯片的mmu知识---Information returned by a translation table lookup - xxhalbert - xxhalbert的博客
 
Table B4-28 Memory attributes and the n value for the PRRR field descriptions
 TEX[0]n value 
 0
 0
 0
 0
 1
 1
 1
 1

TRn, bits[2n+1:2n] for values of n from 0 to 7
对于内存属性n来说主要的TEX mapping。n 的值从上图的关系中得到。这个域定义了属性n 的一个区域影射的内存类型:
00            Strongly-ordered
01 Device
10 Normal memory
11 Reserved, effect is UNPREDICTABLE.
n=6的域的意义是IMPLEMENTATION DEFINED 并且可能不同于这里给出的意义。这是因为属性组合{TEX[0]=1,C=1,B=0}是
IMPLEMENTATION DEFINED.

DS0,bit[16]
当一块设备内存的S=0时的映射,这位给出了映射的可共享的属性必须是:
  • 被映射为Device memory.
  • S bit 被设为0
有可能的值:
0 Region is not Shareable
1 Region is Shareable.

DS1, bit[17]
设备内存空间当S=1时的映射。这位给出内存区域映射的可共享属性,内存区域应满足:
  • 被映射为设备内存
  • translation table descriptor中的S位为1
有可能的值:
0 Region is not Shareable
1 Region is Shareable

NS0,bit[18]
被映射为Normal 内存空间并且S属性为0时使用这一位来表示共享属性。所以必要条件为:
  • 被映射为Normal内存
  • translation table descriptor中的S位为0
有可能的值:
0 Region is not Shareable
1 Region is Shareable

NS1,bit[19]
被映射为Normal 内存空间并且S属性为1时使用这一位来表示共享属性。所以必要条件为:
  • 被映射为Normal内存
  • translation table descriptor中的S位为1
有可能的值:
0 Region is not Shareable
1 Region is Shareable

Bit[23:20] Reserved,UNK/SBZP

NOSn,bit[24+n], for values of n from 0 to 7
内存属性n的外部可共享属性映射,如果这个区域被映射作为可共享的Normal或Device memory。n是如上表中的TEX[0]、C、B组合的值。
有可能的值:
0 Memory region is Outer Shareable.
1 Memory region is Inner Shareable.
如果这个区域是不可共享的Normal或Device 内存,这一位的值被忽略。

2) NMRR, Normal 内存remap寄存器,VMSA
目的:NMRR为被PRRR映射为Normal memory提供附加的映射控制。
访问权限:PL1或更高;与PRRR结合使用,不能单独使用。
在实现Security Extensions的芯片中是banked.
A9芯片的mmu知识---Information returned by a translation table lookup - xxhalbert - xxhalbert的博客
 ORn, bits[2n+17:2n+16], for values of n from 0 to 7
Outer Cacheable property mapping for memory attributes n, if  the region is mapped as Normal memory by the 
PRRR.TRn entry.  n 的值和上面PRRR中介绍的一样。
有可能的值:
00 Region is Non-cacheable.
01 Region is Write-Back, Write-Allocate.
10 Region is Write-Through, no Write-Allocate.
11 Region is Write-Back, no Write-Allocate.
The meaning of field with n=6 is IMPLEMENTATION DEFINED and might differ from the meaning given here.

IRn,bits[2n+1:2n], for values of n from 0 to 7
Inner Cacheable property mapping for memory attributes n, if the region is mapped as Normal memory by the PRRR.TRn entry. 
有可能的值:
00 Region is Non-cacheable.
01 Region is Write-Back, Write-Allocate.
10 Region is Write-Through, no Write-Allocate.
11 Region is Write-Back, no Write-Allocate.
The meaning of field with n=6 is IMPLEMENTATION DEFINED and might differ from the meaning given here.
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值