//----------------------------------------------------------------
// setup tx511 translation table
//
//----------------------------------------------------------------
#include "v8_mmu.h"
.text
.cfi_sections .debug_frame // put stack frame info into .debug_frame instead of .eh_frame
.global setup_ttb
.global ZeroBlock
.global __ttb0_l1
.global __ttb0_l2_ram
.global __ttb0_l3_ram_e80
.global __ttb0_l3_ram_e82
.global __ttb0_l3_ram_e84
.global __ttb0_l3_ram_e86
//----------------------------------------------------------------
// setup tx511 translation table
// level 1 table, 4 entries:
// 0000 0000 - 3FFF FFFF, 1GB block, DDR
// 4000 0000 - 7FFF FFFF, 1GB block, DDR
// 8000 0000 - BFFF FFFF, 1GB block, DDR
// C000 0000 - FFFF FFFF, point to level2 tabel
//
// level 2 table, 512 entries:
// C000 0000 - DFFF FFFF, 256 entries, 512MB DDR, 2MB block
// E000 0000 - E3FF FFFF, 32 entries, 64MB OSPI0 flash, 2MB block
// E400 0000 - E7FF FFFF, 32 entries, 64MB OSPI1 flash, 2MB block
// E800 0000 - E81F FFFF, 1 entry, point to level 3_1
// E820 0000 - E83F FFFF, 1 entry, point to level 3_2
//
//----------------------------------------------------------------
.type setup_ttb, "function"
.cfi_startproc
setup_ttb:
//
// x21 = address of L1 tables
// x22 = address of L2 tables
// x23 = address of L3 tables E80
// x24 = address of L3 tables E82
// x25 = address of L3 tables E84
// x26 = address of L3 tables E86
//
ldr x2, =0
ldr x3, =0
ldr x21, =__ttb0_l1
mov x0, x21
mov x1, #(4 << 3)
// can not call func ZeroBlock, not support nesting
loop_zero_0:
subs x1, x1, #16
stp x2, x3, [x0, #-16]!
b.ne loop_zero_0
ldr x22, =__ttb0_l2_ram
mov x1, #(512 << 3)
mov x0, x22
loop_zero_1:
subs x1, x1, #16
stp x2, x3, [x0, #-16]!
b.ne loop_zero_1
ldr x23, =__ttb0_l3_ram_e80
mov x1, #(512 << 3)
mov x0, x23
loop_zero_2:
subs x1, x1, #16
stp x2, x3, [x0, #-16]!
b.ne loop_zero_2
ldr x24, =__ttb0_l3_ram_e82
mov x1, #(512 << 3)
mov x0, x24
loop_zero_3:
subs x1, x1, #16
stp x2, x3, [x0, #-16]!
b.ne loop_zero_3
ldr x25, =__ttb0_l3_ram_e84
mov x1, #(512 << 3)
mov x0, x25
loop_zero_4:
subs x1, x1, #16
stp x2, x3, [x0, #-16]!
b.ne loop_zero_4
ldr x26, =__ttb0_l3_ram_e86
mov x1, #(512 << 3)
mov x0, x26
loop_zero_5:
subs x1, x1, #16
stp x2, x3, [x0, #-16]!
b.ne loop_zero_5
// 0000 0000 - 3FFF FFFF, 1GB block, DDR
// 4000 0000 - 7FFF FFFF, 1GB block, DDR
// 8000 0000 - BFFF FFFF, 1GB block, DDR
// 3 1G block, write to l1 table
//
ldr x1, =3
ldr x2, =0x40000000
ldr x3, =(0x00000000 | \
TT_S1_ATTR_BLOCK | \
(1 << TT_S1_ATTR_MATTR_LSB) | \
TT_S1_ATTR_NS | \
TT_S1_ATTR_AP_RW_PL1 | \
TT_S1_ATTR_SH_INNER | \
TT_S1_ATTR_AF | \
TT_S1_ATTR_nG)
mov x4, x21
loop1:
str x3, [x4], #8
add x3, x3, x2
subs x1, x1, #1
bne loop1
// C000 0000 - FFFF FFFF, point to level2 tabel, write to l1 table
orr x1, x22, #TT_S1_ATTR_PAGE
str x1, [x4]
// level 2 table: C000 0000 - DFFF FFFF, 256 entries, 512MB DDR, 2MB block
ldr x1, =256
ldr x2, =0x200000
ldr x3, =(0xC0000000 | \
TT_S1_ATTR_BLOCK | \
(1 << TT_S1_ATTR_MATTR_LSB) | \
TT_S1_ATTR_NS | \
TT_S1_ATTR_AP_RW_PL1 | \
TT_S1_ATTR_SH_INNER | \
TT_S1_ATTR_AF | \
TT_S1_ATTR_nG)
mov x4, x22
loop2_ddr:
str x3, [x4], #8
add x3, x3, x2
subs x1, x1, #1
bne loop2_ddr
// level 2 table: E000 0000 - E3FF FFFF, 32 entries, 64MB OSPI0 flash, 2MB block
ldr x1, =32
ldr x2, =0x200000
ldr x3, =(0xE0000000 | \
TT_S1_ATTR_BLOCK | \
(1 << TT_S1_ATTR_MATTR_LSB) | \
TT_S1_ATTR_NS | \
TT_S1_ATTR_AP_RW_PL1 | \
TT_S1_ATTR_SH_INNER | \
TT_S1_ATTR_AF | \
TT_S1_ATTR_nG)
loop2_ospi0:
str x3, [x4], #8
add x3, x3, x2
subs x1, x1, #1
bne loop2_ospi0
// level 2 table: E400 0000 - E7FF FFFF, 32 entries, 64MB OSPI1 flash, 2MB block
ldr x1, =32
ldr x2, =0x200000
ldr x3, =(0xE4000000 | \
TT_S1_ATTR_BLOCK | \
(1 << TT_S1_ATTR_MATTR_LSB) | \
TT_S1_ATTR_NS | \
TT_S1_ATTR_AP_RW_PL1 | \
TT_S1_ATTR_SH_INNER | \
TT_S1_ATTR_AF | \
TT_S1_ATTR_nG)
loop2_ospi1:
str x3, [x4], #8
add x3, x3, x2
subs x1, x1, #1
bne loop2_ospi1
// level 2 table: E800 0000 - E81F FFFF, 1 entry, point to level 3_1
orr x1, x23, #TT_S1_ATTR_TABLE
ldr x2, =0xE8000000
ubfx x3, x2, #21, #9
str x1, [x22, x3, lsl #3]
// level 2 table: E820 0000 - E83F FFFF, 1 entry, point to level 3_2
orr x1, x24, #TT_S1_ATTR_TABLE
ldr x2, =0xE8200000
ubfx x3, x2, #21, #9
str x1, [x22, x3, lsl #3]
// level 2 table: E840 0000 - E85F FFFF, 1 entry, point to level 3_3
orr x1, x25, #TT_S1_ATTR_TABLE
ldr x2, =0xE8400000
ubfx x3, x2, #21, #9
str x1, [x22, x3, lsl #3]
// level 2 table: E860 0000 - E87F FFFF, 1 entry, point to level 3_4
orr x1, x26, #TT_S1_ATTR_TABLE
ldr x2, =0xE8600000
ubfx x3, x2, #21, #9
str x1, [x22, x3, lsl #3]
// level 3 table: E800 0000 - E81F FFFF, 512 entry, x23
// E800 0000 - E803 FFFF, 256kB on-chip-sram
ldr x1, =0x1000
ldr x2, =4
ldr x3, =0xE8000000
ldr x4, = (TT_S1_ATTR_PAGE | \
(1 << TT_S1_ATTR_MATTR_LSB) | \
TT_S1_ATTR_NS | \
TT_S1_ATTR_AP_RW_PL1 | \
TT_S1_ATTR_SH_INNER | \
TT_S1_ATTR_AF | \
TT_S1_ATTR_nG)
loop3_sram:
ubfx x5, x3, #12, #9
orr x6, x3, x4
str x6, [x23, x5, lsl #3]
add x3, x3, x1
subs x2, x2, #1
bne loop3_sram
// level 3 table: E820 0000 - E83F FFFF, 512 entry, x24
// valid addr E820 0000 - E838 6FFF
ldr x1, =0x1000
ldr x2, =((0xE8386FFF + 1 - 0xE8200000) >> 12)
ldr x3, =0xE8200000
ldr x4, = (TT_S1_ATTR_PAGE | \
(2 << TT_S1_ATTR_MATTR_LSB) | \
TT_S1_ATTR_NS | \
TT_S1_ATTR_AP_RW_PL1 | \
TT_S1_ATTR_SH_INNER | \
TT_S1_ATTR_AF | \
TT_S1_ATTR_nG)
loop3_Top_ahb:
ubfx x5, x3, #12, #9
orr x6, x3, x4
str x6, [x24, x5, lsl #3]
add x3, x3, x1
subs x2, x2, #1
bne loop3_Top_ahb
// level 3 table: E840 0000 - E85F FFFF, 512 entry, x25
// valid addr E840 0000 - E850 FFFF
ldr x1, =0x1000
ldr x2, =((0xE850FFFF + 1 - 0xE8400000) >> 12)
ldr x3, =0xE8400000
ldr x4, = (TT_S1_ATTR_PAGE | \
(2 << TT_S1_ATTR_MATTR_LSB) | \
TT_S1_ATTR_NS | \
TT_S1_ATTR_AP_RW_PL1 | \
TT_S1_ATTR_SH_INNER | \
TT_S1_ATTR_AF | \
TT_S1_ATTR_nG)
loop3_lp_hp_gic_ddr_ahb:
ubfx x5, x3, #12, #9
orr x6, x3, x4
str x6, [x25, x5, lsl #3]
add x3, x3, x1
subs x2, x2, #1
bne loop3_lp_hp_gic_ddr_ahb
// level 3 table: E860 0000 - E87F FFFF, 512 entry, x26
// valid addr E860 0000 - E869 4FFF
ldr x1, =0x1000
ldr x2, =((0xE8694FFF + 1 - 0xE8600000) >> 12)
ldr x3, =0xE8600000
ldr x4, = (TT_S1_ATTR_PAGE | \
(2 << TT_S1_ATTR_MATTR_LSB) | \
TT_S1_ATTR_NS | \
TT_S1_ATTR_AP_RW_PL1 | \
TT_S1_ATTR_SH_INNER | \
TT_S1_ATTR_AF | \
TT_S1_ATTR_nG)
loop3_vo_vi_ahb:
ubfx x5, x3, #12, #9
orr x6, x3, x4
str x6, [x26, x5, lsl #3]
add x3, x3, x1
subs x2, x2, #1
bne loop3_vo_vi_ahb
ret
.cfi_endproc