blob: 1068bd2d52b774aa6f226311340a83e542787e30 [file] [log] [blame]
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +02001/*
2 * Microblaze MMU emulation for qemu.
3 *
4 * Copyright (c) 2009 Edgar E. Iglesias
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
Chetan Pantee452032020-10-23 12:18:21 +00009 * version 2.1 of the License, or (at your option) any later version.
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +020010 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
Blue Swirl8167ee82009-07-16 20:47:01 +000017 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +020018 */
19
Markus Armbrusterf91005e2019-06-04 20:16:18 +020020#ifndef TARGET_MICROBLAZE_MMU_H
21#define TARGET_MICROBLAZE_MMU_H
22
Philippe Mathieu-Daudé3cb1a412022-02-07 12:44:46 +010023#include "cpu.h"
24
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +020025#define MMU_R_PID 0
26#define MMU_R_ZPR 1
27#define MMU_R_TLBX 2
28#define MMU_R_TLBLO 3
29#define MMU_R_TLBHI 4
30#define MMU_R_TLBSX 5
31
32#define RAM_DATA 1
33#define RAM_TAG 0
34
35/* Tag portion */
Edgar E. Iglesiasd2f004c2018-04-16 21:03:01 +020036#define TLB_EPN_MASK MAKE_64BIT_MASK(10, 64 - 10)
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +020037#define TLB_PAGESZ_MASK 0x00000380
38#define TLB_PAGESZ(x) (((x) & 0x7) << 7)
39#define PAGESZ_1K 0
40#define PAGESZ_4K 1
41#define PAGESZ_16K 2
42#define PAGESZ_64K 3
43#define PAGESZ_256K 4
44#define PAGESZ_1M 5
45#define PAGESZ_4M 6
46#define PAGESZ_16M 7
47#define TLB_VALID 0x00000040 /* Entry is valid */
48
49/* Data portion */
Edgar E. Iglesiasd2f004c2018-04-16 21:03:01 +020050#define TLB_RPN_MASK MAKE_64BIT_MASK(10, 64 - 10)
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +020051#define TLB_PERM_MASK 0x00000300
52#define TLB_EX 0x00000200 /* Instruction execution allowed */
53#define TLB_WR 0x00000100 /* Writes permitted */
54#define TLB_ZSEL_MASK 0x000000F0
55#define TLB_ZSEL(x) (((x) & 0xF) << 4)
56#define TLB_ATTR_MASK 0x0000000F
57#define TLB_W 0x00000008 /* Caching is write-through */
58#define TLB_I 0x00000004 /* Caching is inhibited */
59#define TLB_M 0x00000002 /* Memory is coherent */
60#define TLB_G 0x00000001 /* Memory is guarded from prefetch */
61
Edgar E. Iglesiasa2207b52018-04-15 23:18:49 +020062/* TLBX */
63#define R_TBLX_MISS_SHIFT 31
64#define R_TBLX_MISS_MASK (1U << R_TBLX_MISS_SHIFT)
65
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +020066#define TLB_ENTRIES 64
67
Richard Henderson8ce97bc2020-09-02 23:18:35 -070068typedef struct {
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +020069 /* Data and tag brams. */
Edgar E. Iglesiasd2f004c2018-04-16 21:03:01 +020070 uint64_t rams[2][TLB_ENTRIES];
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +020071 /* We keep a separate ram for the tids to avoid the 48 bit tag width. */
72 uint8_t tids[TLB_ENTRIES];
73 /* Control flops. */
Edgar E. Iglesias96716532018-04-15 23:25:58 +020074 uint32_t regs[3];
Richard Henderson8ce97bc2020-09-02 23:18:35 -070075} MicroBlazeMMU;
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +020076
Richard Henderson8ce97bc2020-09-02 23:18:35 -070077typedef struct {
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +020078 uint32_t paddr;
79 uint32_t vaddr;
80 unsigned int size;
81 unsigned int idx;
82 int prot;
83 enum {
84 ERR_PROT, ERR_MISS, ERR_HIT
85 } err;
Richard Henderson8ce97bc2020-09-02 23:18:35 -070086} MicroBlazeMMULookup;
Edgar E. Iglesiasafeeceb2009-05-20 20:08:24 +020087
Richard Hendersonde73ee12020-09-04 11:31:57 -070088unsigned int mmu_translate(MicroBlazeCPU *cpu, MicroBlazeMMULookup *lu,
Joe Komlodi671a0a12021-01-21 16:18:54 -080089 target_ulong vaddr, MMUAccessType rw, int mmu_idx);
Edgar E. Iglesiasf0f7e7f2018-04-16 21:25:01 +020090uint32_t mmu_read(CPUMBState *env, bool ea, uint32_t rn);
91void mmu_write(CPUMBState *env, bool ea, uint32_t rn, uint32_t v);
Richard Henderson8ce97bc2020-09-02 23:18:35 -070092void mmu_init(MicroBlazeMMU *mmu);
Markus Armbrusterf91005e2019-06-04 20:16:18 +020093
94#endif