1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/arch/unicore32/mm/proc-macros.S
5 * Code specific to PKUnity SoC and UniCore ISA
7 * Copyright (C) 2001-2010 GUAN Xue-tao
9 * We need constants.h for:
14 #include <generated/asm-offsets.h>
15 #include <asm/thread_info.h>
16 #include <asm/memory.h>
19 * the cache line sizes of the I and D cache are the same
21 #define CACHE_LINESIZE 32
24 * This is the maximum size of an area which will be invalidated
25 * using the single invalidate entry instructions. Anything larger
26 * than this, and we go for the whole cache.
28 * This value should be chosen such that we choose the cheapest
31 #ifdef CONFIG_CPU_UCV2
32 #define MAX_AREA_SIZE 0x800 /* 64 cache line */
36 * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm)
38 .macro vma_vm_mm, rd, rn
39 ldw \rd, [\rn+], #VMA_VM_MM
43 * vma_vm_flags - get vma->vm_flags
45 .macro vma_vm_flags, rd, rn
46 ldw \rd, [\rn+], #VMA_VM_FLAGS
50 ldw \rd, [\rn+], #TI_TASK
51 ldw \rd, [\rd+], #TSK_ACTIVE_MM
55 * act_mm - get current->active_mm
60 ldw \rd, [\rd+], #TI_TASK
61 ldw \rd, [\rd+], #TSK_ACTIVE_MM
65 * mmid - get context id from mm pointer (mm->context.id)
68 ldw \rd, [\rn+], #MM_CONTEXT_ID
72 * mask_asid - mask the ASID from the context ID
78 .macro crval, clear, mmuset, ucset
83 #ifndef CONFIG_CPU_DCACHE_LINE_DISABLE
85 * va2pa va, pa, tbl, msk, off, err
86 * This macro is used to translate virtual address to its physical address.
89 * pa: physical address, result is stored in this register
90 * tbl, msk, off: temp registers, will be destroyed
91 * err: jump to error label if the physical address not exist
92 * NOTE: all regs must be different
94 .macro va2pa, va, pa, tbl, msk, off, err=990f
96 mov \off, \va >> #22 @ off <- index of 1st page table
97 adr \tbl, 910f @ tbl <- table of 1st page table
98 900: @ ---- handle 1, 2 page table
99 add \pa, \pa, #PAGE_OFFSET @ pa <- virt addr of page table
100 ldw \pa, [\pa+], \off << #2 @ pa <- the content of pt
101 cand.a \pa, #4 @ test exist bit
102 beq \err @ if not exist
103 and \off, \pa, #3 @ off <- the last 2 bits
104 add \tbl, \tbl, \off << #3 @ cmove table pointer
105 ldw \msk, [\tbl+], #0 @ get the mask
107 930: @ ---- handle 2nd page table
108 and \pa, \pa, \msk @ pa <- phys addr of 2nd pt
110 cntlo \tbl, \msk @ use tbl as temp reg
111 mov \off, \off >> \tbl
112 mov \off, \off >> #2 @ off <- index of 2nd pt
113 adr \tbl, 920f @ tbl <- table of 2nd pt
115 910: @ 1st level page table
116 .word 0xfffff000, 930b @ second level page table
117 .word 0xfffffc00, 930b @ second level large page table
118 .word 0x00000000, \err @ invalid
119 .word 0xffc00000, 980f @ super page
121 920: @ 2nd level page table
122 .word 0xfffff000, 980f @ page
123 .word 0xffffc000, 980f @ middle page
124 .word 0xffff0000, 980f @ large page
125 .word 0x00000000, \err @ invalid
134 .macro dcacheline_flush, addr, t1, t2
135 mov \t1, \addr << #20
136 ldw \t2, =_stext @ _stext must ALIGN(4096)
137 add \t2, \t2, \t1 >> #20
138 ldw \t1, [\t2+], #0x0000
139 ldw \t1, [\t2+], #0x1000
140 ldw \t1, [\t2+], #0x2000
141 ldw \t1, [\t2+], #0x3000