This module allows the ARM processor to map a 32-bit virtual address
to a 40-bit physical address (supports Large physical address extensions)
and enable/disable the MMU. It does this through translation tables
in memory. The MMU hardware supports upto 3-levels of translation tables.
This module only supports the first 2 levels of translation tables.
The level1 translation table is a 32B descriptor table comprising of
four 64bit entries. There can be upto 4 level2 translation tables,
each 4KB in size and comprising of 512 64bit entries.
Each entry in the level1 table either gives the base address and
defines the attributes of a memory area of size 1GB or gives the
address of the next level of translation table and some attributes
for that translation.
Each entry in the level2 table either gives the base address and
defines the attributes of a memory area of size 2MB or gives the
address of the next level of translation table and some attributes
for that translation.
The level1 translation table is placed in an output section called
"ti.sysbios.family.arm.a15.mmuFirstLevelTableSection". Each of the
level2 translation tables are placed in output sections called
"ti.sysbios.family.arm.a15.mmuSecondLevelTableSection0",
"ti.sysbios.family.arm.a15.mmuSecondLevelTableSection1",
"ti.sysbios.family.arm.a15.mmuSecondLevelTableSection2", and
"ti.sysbios.family.arm.a15.mmuSecondLevelTableSection3". These
sections are placed into the platform's default dataMemory and
in order to minimize object file size,
specified to not be initialized via the "NOLOAD" type on GNU compilers
and "NOINIT" on TI compilers.
This module does not manage the third level descriptor tables.
The following is an example of how to place the MMU table
and how to enable L1/L2 data caching for the address range
0x80000000-0x90000000 in the *.cfg file:
The following example demonstrates how to add a peripheral's address
to the MMU table so that it can be accessed by code at runtime:
The following example demonstrates how to modify the first level MMU entry
at runtime. This example changes the descriptor type of the first level
table entry from Table (default) to Block (maps memory region of size 1GB).
The following example demonstrates how to modify the memory attributes
for a second level MMU entry at runtime.
The following example demonstrates how to use setFirstLevelDesc() to create
a mapping from the first level descriptor table to the second level
descriptor table for an unmapped first level entry.
...
Void main(Int argc, Char * argv[])
{
UInt32 peripheralBaseAddr;
Mmu_DescriptorAttrs attrs;
Mmu_initDescAttrs(&attrs);
attrs.type = Mmu_DescriptorType_TABLE;
// Note: If running in SMP mode, Mmu_setMAIR(), Mmu_setFirstLevelDesc()
// and Mmu_setSecondLevelDesc() should not be called with Hwi, Swi
// or Tasking disabled.
// This example assumes that the first level descriptor table does
// not have a valid entry for virtual address 0x40000000-0x7FFFFFFF.
// The below call will map this virtual address range in the first
// level table to the correponding second level descriptor table.
Mmu_setFirstLevelDesc((Ptr)0x40000000, (UInt64)0x0, &attrs);
// Note: Second argument to Mmu_setFirstLevelDesc() is ignored
// when attrs.type is DescriptorType_TABLE.
attrs.type = Mmu.DescriptorType_BLOCK; // BLOCK descriptor
attrs.noExecute = true; // not executable
attrs.accPerm = 0; // read/write at PL1
attrs.attrIndx = 1; // MAIR0 Byte1 describes
// memory attributes for
// each BLOCK MMU entry
// write memory region attribute in mairRegAttr[1] i.e. MAIR0 Reg Byte1
Mmu_setMAIRMeta(1, 0x0); // Mark mem regions as strongly ordered memory
// Define the base address of the 2 MB page
// the peripheral resides in.
peripheralBaseAddr = 0x40400000;
// Now that there is a first level entry for virtual addresses
// 0x40000000-0x7FFFFFFF that maps these addresses to a second
// level descriptor table, we can add a second level entry that
// maps the peripheral base address to a physical address.
Mmu_setSecondLevelDesc(peripheralBaseAddr, peripheralBaseAddr, &attrs);
}
const Mmu_NUM_LEVEL1_ENTRIES |
|
#define Mmu_NUM_LEVEL1_ENTRIES (UInt)4
const Mmu_NUM_LEVEL2_ENTRIES |
|
#define Mmu_NUM_LEVEL2_ENTRIES (UInt)512
enum Mmu_DescriptorType |
|
Different descriptor type encodings:
typedef enum Mmu_DescriptorType {
Mmu_DescriptorType_INVALID0,
// Virtual address is unmapped
Mmu_DescriptorType_BLOCK,
// Block descriptor
Mmu_DescriptorType_INVALID1,
// Virtual address is unmapped
Mmu_DescriptorType_TABLE
// Next-level table address
} Mmu_DescriptorType;
DETAILS
- Invalid or Fault entry (0b00 or 0b10)
- Block descriptor entry (0b01)
- Table descriptor entry (0b11)
If a First-level table contains only one entry, it would be skipped,
and the TTBR points to the Second-level table. This happens if the
VA address range is 30 bits or less.
struct Mmu_DescriptorAttrs |
|
Structure for setting first and second level descriptor entries
typedef struct Mmu_DescriptorAttrs {
// first level descriptor type
Bool nsTable;
// security level for subsequent levels
UInt8 apTable;
// access perm limit for subsequent levels
Bool xnTable;
// XN limit for subsequent levels
Bool pxnTable;
// PXN limit for subsequent levels
Bool noExecute;
// execute-never bit
Bool privNoExecute;
// privileged execute-never bit
Bool contiguous;
// hint bit indicating 16 adjacent table
entries point to contiguos memory
Bool notGlobal;
// not global bit
Bool accessFlag;
// access flag
UInt8 shareable;
// shareability field value 0-3
UInt8 accPerm;
// access permission bits value 0-3
Bool nonSecure;
// non-secure bit
UInt8 attrIndx;
// stage 1 memory attributes index field for
the indicated MAIRn register value 0-7
UInt8 reserved;
// Bits[58:55] reserved for software use
} Mmu_DescriptorAttrs;
DETAILS
nsTable, apTable, xnTable and pxnTable fields are used only for
DescriptorType.TABLE
noExecute, privNoExecute, contiguous, notGlobal, accessFlag, shareable,
accPerm, nonSecure and attrIndx fields are used only for
DescriptorType.BLOCK
config Mmu_A_disableUnsupported // module-wide |
|
Assert raised if Mmu_disable() called when running in SMP mode
extern const Assert_Id Mmu_A_disableUnsupported;
config Mmu_A_nullPointer // module-wide |
|
Assert raised when a pointer is null
config Mmu_A_unknownDescType // module-wide |
|
Assert raised when the descriptor type is not recognized
extern const Assert_Id Mmu_A_unknownDescType;
config Mmu_defaultAttrs // module-wide |
|
default descriptor attributes structure
config Mmu_enableMMU // module-wide |
|
Configuration parameter to enable MMU
extern const Bool Mmu_enableMMU;
config Mmu_errata798181 // module-wide |
|
Enable workaround for ARM errata 798181
extern const Bool Mmu_errata798181;
DETAILS
Errata 798181 brief description:
Moving a virtual page that is being accessed by an active process
can lead to unexpected behavior.
Mmu_disable() // module-wide |
|
Disables the MMU
DETAILS
If the MMU is already disabled, then simply return.
Otherwise this function does the following:
- If the L1 data cache is enabled, write back invalidate all
of L1 data cache.
- If the L1 program cache is enabled, invalidate all of L1
program cache.
This function is not supported when running in SMP mode and
will generate an assertion failure if called.
On ARM cores like Cortex-A15, both the cache and MMU need to be
enabled for data caching to work. Also, on certain SoC's like
Keystone 2, the caches need to be enabled for the inter-core
lock (used in SMP mode) to work. Therefore, disabling the MMU
is not permitted when running in SMP mode.
NOTE
This function does not change the cache L1 data/program settings.
Mmu_enable() // module-wide |
|
Enables the MMU
DETAILS
If the MMU is already enabled, then simply return.
Otherwise this function does the following:
- If the L1 program cache is enabled, invalidate all of L1
program cache.
This function enables the MMU on the core it is called from.
NOTE
This function does not change the L1 data/program cache settings.
Mmu_initDescAttrs() // module-wide |
|
Initializes the descriptor attribute structure
ARGUMENTS
attrs
Pointer to descriptor attribute struct
Mmu_isEnabled() // module-wide |
|
Determines if the MMU is enabled
Mmu_setFirstLevelDesc() // module-wide |
|
Sets the descriptor for the virtual address
ARGUMENTS
virtualAddr
The modified virtual address
phyAddr
The physical address
attrs
Pointer to first level descriptor attribute struct
DETAILS
The first level table entry for the virtual address is mapped
to either a physical address with the attributes specified or
maps to a second level descriptor table. The descriptor table
is effective when the MMU is enabled.
If
attrs.type is set to
DescriptorType_TABLE then the physical address which is
passed as the second argument to setFirstLevelDesc() is
ignored and the virtual address (aligned to 1GB) is mapped to
the corresponding second level descriptor table.
SEE
NOTE
If running in SMP mode, this function broadcasts to the other cores
to ensure all cores execute a barrier instruction and the MMU table
updates are visible to them. Therefore, this function should not be
called with Hwi, Swi or Tasking disabled as that would cause the
inter-core lock to be taken by the current core and will prevent the
function from broadcasting to the other cores. If not running in
SMP mode, it is okay to call this function with Hwi, Swi or Tasking
disabled.
Mmu_setMAIR() // module-wide |
|
Sets the memory attribute encoding in the MAIRn register
Void Mmu_setMAIR(UInt attrIndx, UInt attr);
ARGUMENTS
attrIndx
Select appropriate MAIR register (0 or 1)
and byte offset within the selected register
attr
Memory attribute encoding
DETAILS
MAIR0 and MAIR1 provide the memory attribute encodings to the possible
attrIndx values in a long-descriptor format
translation table entry for stage 1 translations.
attrIndx[1:0] selects the ATTRn bit-field in
the selected MAIR register.
attrIndx[2] selects the MAIR register.
Memory Attribute Indirection Register (MAIR) 0 and 1 bit assignments:
|31 | 24|23 | 16|15 | 8|7 | 0|
--------------------------------------------------------------
MAIR0 | ATTR3 | ATTR2 | ATTR1 | ATTR0 |
--------------------------------------------------------------
MAIR1 | ATTR7 | ATTR6 | ATTR5 | ATTR4 |
--------------------------------------------------------------
SYS/BIOS assigns the following defaults to MAIR0 ATTR0, ATTR1 and ATTR2:
ATTR0 -> 0x44 (mark memory region as non-cacheable normal memory)
ATTR1 -> 0x00 (mark memory region as strongly ordered and non-cacheable)
ATTR2 -> 0xFF (mark memory region as normal memory, RW cacheable and
RW allocate)
The level1 and level2 MMU Table entries use the above default
attributes created by this module and should preferably not be
changed. Please note that if the default value assigned to ATTR0 is
changed, then the
cachePlatformMemory config param may not
behave correctly as it uses this attribute to mark the memory as
non-cacheable normal memory. If ATTR1 or ATTR2 are changed, it will
affect all existing MMU Table entries which use ATTR1 or ATTR2.
For more details on MAIR0 and MAIR1 encodings please refer
v7A ARM Architecture Reference Manual
NOTE
This function only invalidates the TLB and does not flush the cache.
If the cacheability attribute of a region of memory is changed by
modifying the MAIR entry for the region, the application needs to
flush and invalidate the region of memory from the cache.
If running in SMP mode, this function broadcasts to the other cores
and ensures the MAIR entry is updated on all cores. Therefore, this
function should not be called with Hwi, Swi or Tasking disabled as
that would cause the inter-core lock to be taken by the current core
and will prevent the function from broadcasting a MAIR update request
to the other cores. If not running in SMP mode, it is okay to call
this function with Hwi, Swi or Tasking disabled.
Mmu_setSecondLevelDesc() // module-wide |
|
Sets the descriptor for the virtual address
ARGUMENTS
virtualAddr
The modified virtual address
phyAddr
The physical address
attrs
Pointer to second level descriptor attribute struct
DETAILS
The second level table entry for the virtual address is mapped
to the physical address with the attributes specified. The
descriptor table is effective when the MMU is enabled.
SEE
NOTE
If running in SMP mode, this function broadcasts to the other cores
to ensure all cores execute a barrier instruction and the MMU table
updates are visible to them. Therefore, this function should not be
called with Hwi, Swi or Tasking disabled as that would cause the
inter-core lock to be taken by the current core and will prevent the
function from broadcasting to the other cores. If not running in
SMP mode, it is okay to call this function with Hwi, Swi or Tasking
disabled.
Mmu_tlbInv() // module-wide |
|
Invalidate the TLB entries (both data and instruction) for the range of
memory within the specified starting address and byte count. The range
of addresses operated on gets quantized to page size
Void Mmu_tlbInv(Ptr startAddr, SizeT byteCnt);
Mmu_tlbInvAll() // module-wide |
|
Invalidate entire TLB (both data and instruction)
Module-Wide Built-Ins |
|
// Get this module's unique id
Bool Mmu_Module_startupDone();
// Test if this module has completed startup
// The heap from which this module allocates memory
Bool Mmu_Module_hasMask();
// Test whether this module has a diagnostics mask
Bits16 Mmu_Module_getMask();
// Returns the diagnostics mask for this module
Void Mmu_Module_setMask(Bits16 mask);
// Set the diagnostics mask for this module
const Mmu.NUM_LEVEL1_ENTRIES |
|
const Mmu.NUM_LEVEL1_ENTRIES = 4;
C SYNOPSIS
const Mmu.NUM_LEVEL2_ENTRIES |
|
const Mmu.NUM_LEVEL2_ENTRIES = 512;
C SYNOPSIS
enum Mmu.DescriptorType |
|
Different descriptor type encodings:
values of type Mmu.DescriptorType
const Mmu.DescriptorType_INVALID0;
// Virtual address is unmapped
const Mmu.DescriptorType_BLOCK;
// Block descriptor
const Mmu.DescriptorType_INVALID1;
// Virtual address is unmapped
const Mmu.DescriptorType_TABLE;
// Next-level table address
DETAILS
- Invalid or Fault entry (0b00 or 0b10)
- Block descriptor entry (0b01)
- Table descriptor entry (0b11)
If a First-level table contains only one entry, it would be skipped,
and the TTBR points to the Second-level table. This happens if the
VA address range is 30 bits or less.
C SYNOPSIS
struct Mmu.DescriptorAttrs |
|
Structure for setting first and second level descriptor entries
var obj = new Mmu.DescriptorAttrs;
// first level descriptor type
obj.nsTable = Bool ...
// security level for subsequent levels
obj.apTable = UInt8 ...
// access perm limit for subsequent levels
obj.xnTable = Bool ...
// XN limit for subsequent levels
obj.pxnTable = Bool ...
// PXN limit for subsequent levels
obj.noExecute = Bool ...
// execute-never bit
obj.privNoExecute = Bool ...
// privileged execute-never bit
obj.contiguous = Bool ...
// hint bit indicating 16 adjacent table
entries point to contiguos memory
obj.notGlobal = Bool ...
// not global bit
obj.accessFlag = Bool ...
// access flag
obj.shareable = UInt8 ...
// shareability field value 0-3
obj.accPerm = UInt8 ...
// access permission bits value 0-3
obj.nonSecure = Bool ...
// non-secure bit
obj.attrIndx = UInt8 ...
// stage 1 memory attributes index field for
the indicated MAIRn register value 0-7
obj.reserved = UInt8 ...
// Bits[58:55] reserved for software use
DETAILS
nsTable, apTable, xnTable and pxnTable fields are used only for
DescriptorType.TABLE
noExecute, privNoExecute, contiguous, notGlobal, accessFlag, shareable,
accPerm, nonSecure and attrIndx fields are used only for
DescriptorType.BLOCK
C SYNOPSIS
config Mmu.A_disableUnsupported // module-wide |
|
Assert raised if Mmu_disable() called when running in SMP mode
msg: "A_disableUnsupported: MMU disable is not supported in SMP mode."
};
C SYNOPSIS
config Mmu.A_nullPointer // module-wide |
|
Assert raised when a pointer is null
msg: "A_nullPointer: Pointer is null"
};
C SYNOPSIS
config Mmu.A_unknownDescType // module-wide |
|
Assert raised when the descriptor type is not recognized
msg: "A_unknownDescType: Descriptor type is not recognized"
};
C SYNOPSIS
config Mmu.defaultAttrs // module-wide |
|
default descriptor attributes structure
nsTable: false,
apTable: 0,
xnTable: false,
pxnTable: false,
noExecute: false,
privNoExecute: false,
contiguous: false,
notGlobal: false,
accessFlag: true,
shareable: 0,
accPerm: 0,
nonSecure: false,
attrIndx: 0,
reserved: 0
};
C SYNOPSIS
config Mmu.enableMMU // module-wide |
|
Configuration parameter to enable MMU
Mmu.enableMMU = Bool true;
C SYNOPSIS
config Mmu.errata798181 // module-wide |
|
Enable workaround for ARM errata 798181
Mmu.errata798181 = Bool true;
DETAILS
Errata 798181 brief description:
Moving a virtual page that is being accessed by an active process
can lead to unexpected behavior.
C SYNOPSIS
metaonly config Mmu.cachePlatformMemory // module-wide |
|
Flag to automatically mark platform's code/data/stack memory as
cacheable in MMU descriptor table
Mmu.cachePlatformMemory = Bool true;
DETAILS
By default, all memory regions defined in the platform an
application is built with are marked as cacheable.
If manual configuration of memory regions is required, set
this config parameter to 'false'.
SEE
metaonly config Mmu.common$ // module-wide |
|
Common module configuration parameters
DETAILS
All modules have this configuration parameter. Its name
contains the '$' character to ensure it does not conflict with
configuration parameters declared by the module. This allows
new configuration parameters to be added in the future without
any chance of breaking existing modules.
metaonly config Mmu.rovViewInfo // module-wide |
|
metaonly Mmu.initDescAttrsMeta() // module-wide |
|
Initializes the descriptor attribute structure
ARGUMENTS
attrs
Pointer to descriptor attribute struct
metaonly Mmu.setFirstLevelDescMeta() // module-wide |
|
Statically sets the descriptor for the virtual address
Mmu.
setFirstLevelDescMeta(
Ptr virtualAddr,
UInt64 phyAddr,
Mmu.DescriptorAttrs attrs)
returns Void
ARGUMENTS
virtualAddr
The modified virtual address
phyAddr
The physical address
attrs
Pointer to first level descriptor attribute struct
DETAILS
The first level table entry for the virtual address is mapped
to either a physical address with the attributes specified or
maps to a second level descriptor table. The descriptor table
is effective when the MMU is enabled.
If
attrs.type is set to
Mmu.DescriptorType_TABLE then the physical address which is
passed as the second argument to setFirstLevelDescMeta() is
ignored and the virtual address (aligned to 1GB) is mapped to
the corresponding second level descriptor table.
SEE
metaonly Mmu.setMAIRMeta() // module-wide |
|
Statically sets the memory attribute encoding in the MAIRn register
Mmu.setMAIRMeta(UInt attrIndx, UInt attr) returns Void
ARGUMENTS
attrIndx
Select appropriate MAIR register (0 or 1)
and byte offset within selected register
attr
Memory attribute encoding
DETAILS
MAIR0 and MAIR1 provide the memory attribute encodings to the possible
attrIndx values in a Long-descriptor format
translation table entry for stage 1 translations (see
setMAIR
for more details).
metaonly Mmu.setSecondLevelDescMeta() // module-wide |
|
Statically sets the descriptor for the virtual address
Mmu.
setSecondLevelDescMeta(
Ptr virtualAddr,
UInt64 phyAddr,
Mmu.DescriptorAttrs attrs)
returns Void
ARGUMENTS
virtualAddr
The modified virtual address
phyAddr
The physical address
attrs
Pointer to second level descriptor attribute struct
DETAILS
The second level table entry for the virtual address is mapped
to the physical address with the attributes specified. The
descriptor table is effective when the MMU is enabled.
SEE