18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
48c2ecf20Sopenharmony_ci * Copyright (C) 2008-2009 PetaLogix
58c2ecf20Sopenharmony_ci * Copyright (C) 2006 Atmark Techno, Inc.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _ASM_MICROBLAZE_MMU_H
98c2ecf20Sopenharmony_ci#define _ASM_MICROBLAZE_MMU_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci# ifndef CONFIG_MMU
128c2ecf20Sopenharmony_ci#  include <asm-generic/mmu.h>
138c2ecf20Sopenharmony_ci# else /* CONFIG_MMU */
148c2ecf20Sopenharmony_ci#  ifdef __KERNEL__
158c2ecf20Sopenharmony_ci#   ifndef __ASSEMBLY__
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* Default "unsigned long" context */
188c2ecf20Sopenharmony_citypedef unsigned long mm_context_t;
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* Hardware Page Table Entry */
218c2ecf20Sopenharmony_citypedef struct _PTE {
228c2ecf20Sopenharmony_ci	unsigned long    v:1;	/* Entry is valid */
238c2ecf20Sopenharmony_ci	unsigned long vsid:24;	/* Virtual segment identifier */
248c2ecf20Sopenharmony_ci	unsigned long    h:1;	/* Hash algorithm indicator */
258c2ecf20Sopenharmony_ci	unsigned long  api:6;	/* Abbreviated page index */
268c2ecf20Sopenharmony_ci	unsigned long  rpn:20;	/* Real (physical) page number */
278c2ecf20Sopenharmony_ci	unsigned long     :3;	/* Unused */
288c2ecf20Sopenharmony_ci	unsigned long    r:1;	/* Referenced */
298c2ecf20Sopenharmony_ci	unsigned long    c:1;	/* Changed */
308c2ecf20Sopenharmony_ci	unsigned long    w:1;	/* Write-thru cache mode */
318c2ecf20Sopenharmony_ci	unsigned long    i:1;	/* Cache inhibited */
328c2ecf20Sopenharmony_ci	unsigned long    m:1;	/* Memory coherence */
338c2ecf20Sopenharmony_ci	unsigned long    g:1;	/* Guarded */
348c2ecf20Sopenharmony_ci	unsigned long     :1;	/* Unused */
358c2ecf20Sopenharmony_ci	unsigned long   pp:2;	/* Page protection */
368c2ecf20Sopenharmony_ci} PTE;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* Values for PP (assumes Ks=0, Kp=1) */
398c2ecf20Sopenharmony_ci#  define PP_RWXX	0 /* Supervisor read/write, User none */
408c2ecf20Sopenharmony_ci#  define PP_RWRX	1 /* Supervisor read/write, User read */
418c2ecf20Sopenharmony_ci#  define PP_RWRW	2 /* Supervisor read/write, User read/write */
428c2ecf20Sopenharmony_ci#  define PP_RXRX	3 /* Supervisor read,       User read */
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* Segment Register */
458c2ecf20Sopenharmony_citypedef struct _SEGREG {
468c2ecf20Sopenharmony_ci	unsigned long    t:1;	/* Normal or I/O  type */
478c2ecf20Sopenharmony_ci	unsigned long   ks:1;	/* Supervisor 'key' (normally 0) */
488c2ecf20Sopenharmony_ci	unsigned long   kp:1;	/* User 'key' (normally 1) */
498c2ecf20Sopenharmony_ci	unsigned long    n:1;	/* No-execute */
508c2ecf20Sopenharmony_ci	unsigned long     :4;	/* Unused */
518c2ecf20Sopenharmony_ci	unsigned long vsid:24;	/* Virtual Segment Identifier */
528c2ecf20Sopenharmony_ci} SEGREG;
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ciextern void _tlbie(unsigned long va);	/* invalidate a TLB entry */
558c2ecf20Sopenharmony_ciextern void _tlbia(void);		/* invalidate all TLB entries */
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/*
588c2ecf20Sopenharmony_ci * tlb_skip size stores actual number skipped TLBs from TLB0 - every directy TLB
598c2ecf20Sopenharmony_ci * mapping has to increase tlb_skip size.
608c2ecf20Sopenharmony_ci */
618c2ecf20Sopenharmony_ciextern u32 tlb_skip;
628c2ecf20Sopenharmony_ci#   endif /* __ASSEMBLY__ */
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/*
658c2ecf20Sopenharmony_ci * The MicroBlaze processor has a TLB architecture identical to PPC-40x. The
668c2ecf20Sopenharmony_ci * instruction and data sides share a unified, 64-entry, semi-associative
678c2ecf20Sopenharmony_ci * TLB which is maintained totally under software control. In addition, the
688c2ecf20Sopenharmony_ci * instruction side has a hardware-managed, 2,4, or 8-entry, fully-associative
698c2ecf20Sopenharmony_ci * TLB which serves as a first level to the shared TLB. These two TLBs are
708c2ecf20Sopenharmony_ci * known as the UTLB and ITLB, respectively.
718c2ecf20Sopenharmony_ci */
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#  define MICROBLAZE_TLB_SIZE 64
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* For cases when you want to skip some TLB entries */
768c2ecf20Sopenharmony_ci#  define MICROBLAZE_TLB_SKIP 0
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/* Use the last TLB for temporary access to LMB */
798c2ecf20Sopenharmony_ci#  define MICROBLAZE_LMB_TLB_ID 63
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/*
828c2ecf20Sopenharmony_ci * TLB entries are defined by a "high" tag portion and a "low" data
838c2ecf20Sopenharmony_ci * portion. The data portion is 32-bits.
848c2ecf20Sopenharmony_ci *
858c2ecf20Sopenharmony_ci * TLB entries are managed entirely under software control by reading,
868c2ecf20Sopenharmony_ci * writing, and searching using the MTS and MFS instructions.
878c2ecf20Sopenharmony_ci */
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#  define TLB_LO		1
908c2ecf20Sopenharmony_ci#  define TLB_HI		0
918c2ecf20Sopenharmony_ci#  define TLB_DATA		TLB_LO
928c2ecf20Sopenharmony_ci#  define TLB_TAG		TLB_HI
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/* Tag portion */
958c2ecf20Sopenharmony_ci#  define TLB_EPN_MASK		0xFFFFFC00 /* Effective Page Number */
968c2ecf20Sopenharmony_ci#  define TLB_PAGESZ_MASK	0x00000380
978c2ecf20Sopenharmony_ci#  define TLB_PAGESZ(x)		(((x) & 0x7) << 7)
988c2ecf20Sopenharmony_ci#  define PAGESZ_1K		0
998c2ecf20Sopenharmony_ci#  define PAGESZ_4K		1
1008c2ecf20Sopenharmony_ci#  define PAGESZ_16K		2
1018c2ecf20Sopenharmony_ci#  define PAGESZ_64K		3
1028c2ecf20Sopenharmony_ci#  define PAGESZ_256K		4
1038c2ecf20Sopenharmony_ci#  define PAGESZ_1M		5
1048c2ecf20Sopenharmony_ci#  define PAGESZ_4M		6
1058c2ecf20Sopenharmony_ci#  define PAGESZ_16M		7
1068c2ecf20Sopenharmony_ci#  define TLB_VALID		0x00000040 /* Entry is valid */
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* Data portion */
1098c2ecf20Sopenharmony_ci#  define TLB_RPN_MASK		0xFFFFFC00 /* Real Page Number */
1108c2ecf20Sopenharmony_ci#  define TLB_PERM_MASK		0x00000300
1118c2ecf20Sopenharmony_ci#  define TLB_EX		0x00000200 /* Instruction execution allowed */
1128c2ecf20Sopenharmony_ci#  define TLB_WR		0x00000100 /* Writes permitted */
1138c2ecf20Sopenharmony_ci#  define TLB_ZSEL_MASK		0x000000F0
1148c2ecf20Sopenharmony_ci#  define TLB_ZSEL(x)		(((x) & 0xF) << 4)
1158c2ecf20Sopenharmony_ci#  define TLB_ATTR_MASK		0x0000000F
1168c2ecf20Sopenharmony_ci#  define TLB_W			0x00000008 /* Caching is write-through */
1178c2ecf20Sopenharmony_ci#  define TLB_I			0x00000004 /* Caching is inhibited */
1188c2ecf20Sopenharmony_ci#  define TLB_M			0x00000002 /* Memory is coherent */
1198c2ecf20Sopenharmony_ci#  define TLB_G			0x00000001 /* Memory is guarded from prefetch */
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci#  endif /* __KERNEL__ */
1228c2ecf20Sopenharmony_ci# endif /* CONFIG_MMU */
1238c2ecf20Sopenharmony_ci#endif /* _ASM_MICROBLAZE_MMU_H */
124