1*2cc1121bSVineet Gupta /* SPDX-License-Identifier: GPL-2.0-only */
2*2cc1121bSVineet Gupta /*
3*2cc1121bSVineet Gupta * Copyright (C) 2004, 2007-2010, 2011-2012, 2019-20 Synopsys, Inc. (www.synopsys.com)
4*2cc1121bSVineet Gupta *
5*2cc1121bSVineet Gupta * MMUv3 (arc700) / MMUv4 (archs) are software page walked and software managed.
6*2cc1121bSVineet Gupta * This file contains the TLB access registers and commands
7*2cc1121bSVineet Gupta */
8*2cc1121bSVineet Gupta
9*2cc1121bSVineet Gupta #ifndef _ASM_ARC_MMU_ARCV2_H
10*2cc1121bSVineet Gupta #define _ASM_ARC_MMU_ARCV2_H
11*2cc1121bSVineet Gupta
12*2cc1121bSVineet Gupta /*
13*2cc1121bSVineet Gupta * TLB Management regs
14*2cc1121bSVineet Gupta */
15*2cc1121bSVineet Gupta #define ARC_REG_MMU_BCR 0x06f
16*2cc1121bSVineet Gupta
17*2cc1121bSVineet Gupta #ifdef CONFIG_ARC_MMU_V3
18*2cc1121bSVineet Gupta #define ARC_REG_TLBPD0 0x405
19*2cc1121bSVineet Gupta #define ARC_REG_TLBPD1 0x406
20*2cc1121bSVineet Gupta #define ARC_REG_TLBPD1HI 0 /* Dummy: allows common code */
21*2cc1121bSVineet Gupta #define ARC_REG_TLBINDEX 0x407
22*2cc1121bSVineet Gupta #define ARC_REG_TLBCOMMAND 0x408
23*2cc1121bSVineet Gupta #define ARC_REG_PID 0x409
24*2cc1121bSVineet Gupta #define ARC_REG_SCRATCH_DATA0 0x418
25*2cc1121bSVineet Gupta #else
26*2cc1121bSVineet Gupta #define ARC_REG_TLBPD0 0x460
27*2cc1121bSVineet Gupta #define ARC_REG_TLBPD1 0x461
28*2cc1121bSVineet Gupta #define ARC_REG_TLBPD1HI 0x463
29*2cc1121bSVineet Gupta #define ARC_REG_TLBINDEX 0x464
30*2cc1121bSVineet Gupta #define ARC_REG_TLBCOMMAND 0x465
31*2cc1121bSVineet Gupta #define ARC_REG_PID 0x468
32*2cc1121bSVineet Gupta #define ARC_REG_SCRATCH_DATA0 0x46c
33*2cc1121bSVineet Gupta #endif
34*2cc1121bSVineet Gupta
35*2cc1121bSVineet Gupta /* Bits in MMU PID reg */
36*2cc1121bSVineet Gupta #define __TLB_ENABLE (1 << 31)
37*2cc1121bSVineet Gupta #define __PROG_ENABLE (1 << 30)
38*2cc1121bSVineet Gupta #define MMU_ENABLE (__TLB_ENABLE | __PROG_ENABLE)
39*2cc1121bSVineet Gupta
40*2cc1121bSVineet Gupta /* Bits in TLB Index reg */
41*2cc1121bSVineet Gupta #define TLB_LKUP_ERR 0x80000000
42*2cc1121bSVineet Gupta
43*2cc1121bSVineet Gupta #ifdef CONFIG_ARC_MMU_V3
44*2cc1121bSVineet Gupta #define TLB_DUP_ERR (TLB_LKUP_ERR | 0x00000001)
45*2cc1121bSVineet Gupta #else
46*2cc1121bSVineet Gupta #define TLB_DUP_ERR (TLB_LKUP_ERR | 0x40000000)
47*2cc1121bSVineet Gupta #endif
48*2cc1121bSVineet Gupta
49*2cc1121bSVineet Gupta /*
50*2cc1121bSVineet Gupta * TLB Commands
51*2cc1121bSVineet Gupta */
52*2cc1121bSVineet Gupta #define TLBWrite 0x1
53*2cc1121bSVineet Gupta #define TLBRead 0x2
54*2cc1121bSVineet Gupta #define TLBGetIndex 0x3
55*2cc1121bSVineet Gupta #define TLBProbe 0x4
56*2cc1121bSVineet Gupta #define TLBWriteNI 0x5 /* write JTLB without inv uTLBs */
57*2cc1121bSVineet Gupta #define TLBIVUTLB 0x6 /* explicitly inv uTLBs */
58*2cc1121bSVineet Gupta
59*2cc1121bSVineet Gupta #ifdef CONFIG_ARC_MMU_V4
60*2cc1121bSVineet Gupta #define TLBInsertEntry 0x7
61*2cc1121bSVineet Gupta #define TLBDeleteEntry 0x8
62*2cc1121bSVineet Gupta #endif
63*2cc1121bSVineet Gupta
64*2cc1121bSVineet Gupta /* Masks for actual TLB "PD"s */
65*2cc1121bSVineet Gupta #define PTE_BITS_IN_PD0 (_PAGE_GLOBAL | _PAGE_PRESENT | _PAGE_HW_SZ)
66*2cc1121bSVineet Gupta #define PTE_BITS_RWX (_PAGE_EXECUTE | _PAGE_WRITE | _PAGE_READ)
67*2cc1121bSVineet Gupta
68*2cc1121bSVineet Gupta #define PTE_BITS_NON_RWX_IN_PD1 (PAGE_MASK_PHYS | _PAGE_CACHEABLE)
69*2cc1121bSVineet Gupta
70*2cc1121bSVineet Gupta #ifndef __ASSEMBLY__
71*2cc1121bSVineet Gupta
72*2cc1121bSVineet Gupta struct mm_struct;
73*2cc1121bSVineet Gupta extern int pae40_exist_but_not_enab(void);
74*2cc1121bSVineet Gupta
is_pae40_enabled(void)75*2cc1121bSVineet Gupta static inline int is_pae40_enabled(void)
76*2cc1121bSVineet Gupta {
77*2cc1121bSVineet Gupta return IS_ENABLED(CONFIG_ARC_HAS_PAE40);
78*2cc1121bSVineet Gupta }
79*2cc1121bSVineet Gupta
mmu_setup_asid(struct mm_struct * mm,unsigned long asid)80*2cc1121bSVineet Gupta static inline void mmu_setup_asid(struct mm_struct *mm, unsigned long asid)
81*2cc1121bSVineet Gupta {
82*2cc1121bSVineet Gupta write_aux_reg(ARC_REG_PID, asid | MMU_ENABLE);
83*2cc1121bSVineet Gupta }
84*2cc1121bSVineet Gupta
mmu_setup_pgd(struct mm_struct * mm,void * pgd)85*2cc1121bSVineet Gupta static inline void mmu_setup_pgd(struct mm_struct *mm, void *pgd)
86*2cc1121bSVineet Gupta {
87*2cc1121bSVineet Gupta /* PGD cached in MMU reg to avoid 3 mem lookups: task->mm->pgd */
88*2cc1121bSVineet Gupta #ifdef CONFIG_ISA_ARCV2
89*2cc1121bSVineet Gupta write_aux_reg(ARC_REG_SCRATCH_DATA0, (unsigned int)pgd);
90*2cc1121bSVineet Gupta #endif
91*2cc1121bSVineet Gupta }
92*2cc1121bSVineet Gupta
93*2cc1121bSVineet Gupta #else
94*2cc1121bSVineet Gupta
95*2cc1121bSVineet Gupta .macro ARC_MMU_REENABLE reg
96*2cc1121bSVineet Gupta lr \reg, [ARC_REG_PID]
97*2cc1121bSVineet Gupta or \reg, \reg, MMU_ENABLE
98*2cc1121bSVineet Gupta sr \reg, [ARC_REG_PID]
99*2cc1121bSVineet Gupta .endm
100*2cc1121bSVineet Gupta
101*2cc1121bSVineet Gupta #endif /* !__ASSEMBLY__ */
102*2cc1121bSVineet Gupta
103*2cc1121bSVineet Gupta #endif
104