xref: /openbmc/qemu/target/microblaze/mmu.h (revision 99c4a9e68eafade057e33906d23b2face24ca1ff)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth  *  Microblaze MMU emulation for qemu.
3fcf5ef2aSThomas Huth  *
4fcf5ef2aSThomas Huth  *  Copyright (c) 2009 Edgar E. Iglesias
5fcf5ef2aSThomas Huth  *
6fcf5ef2aSThomas Huth  * This library is free software; you can redistribute it and/or
7fcf5ef2aSThomas Huth  * modify it under the terms of the GNU Lesser General Public
8fcf5ef2aSThomas Huth  * License as published by the Free Software Foundation; either
9ee452036SChetan Pant  * version 2.1 of the License, or (at your option) any later version.
10fcf5ef2aSThomas Huth  *
11fcf5ef2aSThomas Huth  * This library is distributed in the hope that it will be useful,
12fcf5ef2aSThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13fcf5ef2aSThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14fcf5ef2aSThomas Huth  * Lesser General Public License for more details.
15fcf5ef2aSThomas Huth  *
16fcf5ef2aSThomas Huth  * You should have received a copy of the GNU Lesser General Public
17fcf5ef2aSThomas Huth  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18fcf5ef2aSThomas Huth  */
19fcf5ef2aSThomas Huth 
20f91005e1SMarkus Armbruster #ifndef TARGET_MICROBLAZE_MMU_H
21f91005e1SMarkus Armbruster #define TARGET_MICROBLAZE_MMU_H
22f91005e1SMarkus Armbruster 
23*3cb1a410SPhilippe Mathieu-Daudé #include "cpu.h"
24*3cb1a410SPhilippe Mathieu-Daudé 
25fcf5ef2aSThomas Huth #define MMU_R_PID    0
26fcf5ef2aSThomas Huth #define MMU_R_ZPR    1
27fcf5ef2aSThomas Huth #define MMU_R_TLBX   2
28fcf5ef2aSThomas Huth #define MMU_R_TLBLO  3
29fcf5ef2aSThomas Huth #define MMU_R_TLBHI  4
30fcf5ef2aSThomas Huth #define MMU_R_TLBSX  5
31fcf5ef2aSThomas Huth 
32fcf5ef2aSThomas Huth #define RAM_DATA     1
33fcf5ef2aSThomas Huth #define RAM_TAG      0
34fcf5ef2aSThomas Huth 
35fcf5ef2aSThomas Huth /* Tag portion */
36d2f004c3SEdgar E. Iglesias #define TLB_EPN_MASK          MAKE_64BIT_MASK(10, 64 - 10)
37fcf5ef2aSThomas Huth #define TLB_PAGESZ_MASK       0x00000380
38fcf5ef2aSThomas Huth #define TLB_PAGESZ(x)         (((x) & 0x7) << 7)
39fcf5ef2aSThomas Huth #define PAGESZ_1K             0
40fcf5ef2aSThomas Huth #define PAGESZ_4K             1
41fcf5ef2aSThomas Huth #define PAGESZ_16K            2
42fcf5ef2aSThomas Huth #define PAGESZ_64K            3
43fcf5ef2aSThomas Huth #define PAGESZ_256K           4
44fcf5ef2aSThomas Huth #define PAGESZ_1M             5
45fcf5ef2aSThomas Huth #define PAGESZ_4M             6
46fcf5ef2aSThomas Huth #define PAGESZ_16M            7
47fcf5ef2aSThomas Huth #define TLB_VALID             0x00000040 /* Entry is valid */
48fcf5ef2aSThomas Huth 
49fcf5ef2aSThomas Huth /* Data portion */
50d2f004c3SEdgar E. Iglesias #define TLB_RPN_MASK          MAKE_64BIT_MASK(10, 64 - 10)
51fcf5ef2aSThomas Huth #define TLB_PERM_MASK         0x00000300
52fcf5ef2aSThomas Huth #define TLB_EX                0x00000200 /* Instruction execution allowed */
53fcf5ef2aSThomas Huth #define TLB_WR                0x00000100 /* Writes permitted */
54fcf5ef2aSThomas Huth #define TLB_ZSEL_MASK         0x000000F0
55fcf5ef2aSThomas Huth #define TLB_ZSEL(x)           (((x) & 0xF) << 4)
56fcf5ef2aSThomas Huth #define TLB_ATTR_MASK         0x0000000F
57fcf5ef2aSThomas Huth #define TLB_W                 0x00000008 /* Caching is write-through */
58fcf5ef2aSThomas Huth #define TLB_I                 0x00000004 /* Caching is inhibited */
59fcf5ef2aSThomas Huth #define TLB_M                 0x00000002 /* Memory is coherent */
60fcf5ef2aSThomas Huth #define TLB_G                 0x00000001 /* Memory is guarded from prefetch */
61fcf5ef2aSThomas Huth 
62a2207b59SEdgar E. Iglesias /* TLBX  */
63a2207b59SEdgar E. Iglesias #define R_TBLX_MISS_SHIFT 31
64a2207b59SEdgar E. Iglesias #define R_TBLX_MISS_MASK (1U << R_TBLX_MISS_SHIFT)
65a2207b59SEdgar E. Iglesias 
66fcf5ef2aSThomas Huth #define TLB_ENTRIES    64
67fcf5ef2aSThomas Huth 
688ce97bc1SRichard Henderson typedef struct {
69fcf5ef2aSThomas Huth     /* Data and tag brams.  */
70d2f004c3SEdgar E. Iglesias     uint64_t rams[2][TLB_ENTRIES];
71fcf5ef2aSThomas Huth     /* We keep a separate ram for the tids to avoid the 48 bit tag width.  */
72fcf5ef2aSThomas Huth     uint8_t tids[TLB_ENTRIES];
73fcf5ef2aSThomas Huth     /* Control flops.  */
7496716533SEdgar E. Iglesias     uint32_t regs[3];
758ce97bc1SRichard Henderson } MicroBlazeMMU;
76fcf5ef2aSThomas Huth 
778ce97bc1SRichard Henderson typedef struct {
78fcf5ef2aSThomas Huth     uint32_t paddr;
79fcf5ef2aSThomas Huth     uint32_t vaddr;
80fcf5ef2aSThomas Huth     unsigned int size;
81fcf5ef2aSThomas Huth     unsigned int idx;
82fcf5ef2aSThomas Huth     int prot;
83fcf5ef2aSThomas Huth     enum {
84fcf5ef2aSThomas Huth         ERR_PROT, ERR_MISS, ERR_HIT
85fcf5ef2aSThomas Huth     } err;
868ce97bc1SRichard Henderson } MicroBlazeMMULookup;
87fcf5ef2aSThomas Huth 
88de73ee1aSRichard Henderson unsigned int mmu_translate(MicroBlazeCPU *cpu, MicroBlazeMMULookup *lu,
89671a0a12SJoe Komlodi                            target_ulong vaddr, MMUAccessType rw, int mmu_idx);
90f0f7e7f7SEdgar E. Iglesias uint32_t mmu_read(CPUMBState *env, bool ea, uint32_t rn);
91f0f7e7f7SEdgar E. Iglesias void mmu_write(CPUMBState *env, bool ea, uint32_t rn, uint32_t v);
928ce97bc1SRichard Henderson void mmu_init(MicroBlazeMMU *mmu);
93f91005e1SMarkus Armbruster 
94f91005e1SMarkus Armbruster #endif
95