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