pte.h revision 202031
1178172Simp/*	$OpenBSD: pte.h,v 1.4 1998/01/28 13:46:25 pefo Exp $	*/
2178172Simp
3178172Simp/*-
4178172Simp * Copyright (c) 1988 University of Utah.
5178172Simp * Copyright (c) 1992, 1993
6178172Simp *	The Regents of the University of California.  All rights reserved.
7178172Simp *
8178172Simp * This code is derived from software contributed to Berkeley by
9178172Simp * the Systems Programming Group of the University of Utah Computer
10178172Simp * Science Department and Ralph Campbell.
11178172Simp *
12178172Simp * Redistribution and use in source and binary forms, with or without
13178172Simp * modification, are permitted provided that the following conditions
14178172Simp * are met:
15178172Simp * 1. Redistributions of source code must retain the above copyright
16178172Simp *    notice, this list of conditions and the following disclaimer.
17178172Simp * 2. Redistributions in binary form must reproduce the above copyright
18178172Simp *    notice, this list of conditions and the following disclaimer in the
19178172Simp *    documentation and/or other materials provided with the distribution.
20178172Simp * 3. All advertising materials mentioning features or use of this software
21178172Simp *    must display the following acknowledgement:
22178172Simp *	This product includes software developed by the University of
23178172Simp *	California, Berkeley and its contributors.
24178172Simp * 4. Neither the name of the University nor the names of its contributors
25178172Simp *    may be used to endorse or promote products derived from this software
26178172Simp *    without specific prior written permission.
27178172Simp *
28178172Simp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29178172Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30178172Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31178172Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32178172Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33178172Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34178172Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35178172Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36178172Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37178172Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38178172Simp * SUCH DAMAGE.
39178172Simp *
40178172Simp *	from: Utah Hdr: pte.h 1.11 89/09/03
41178172Simp *	from: @(#)pte.h 8.1 (Berkeley) 6/10/93
42178172Simp *	JNPR: pte.h,v 1.1.4.1 2007/09/10 06:20:19 girish
43178172Simp * $FreeBSD: head/sys/mips/include/pte.h 202031 2010-01-10 19:50:24Z imp $
44178172Simp */
45178172Simp
46178172Simp#ifndef _MACHINE_PTE_H_
47178172Simp#define	_MACHINE_PTE_H_
48178172Simp
49178172Simp#include <machine/endian.h>
50178172Simp
51178172Simp/*
52178172Simp * MIPS hardware page table entry
53178172Simp */
54178172Simp
55178172Simp#ifndef _LOCORE
56178172Simpstruct pte {
57178172Simp#if BYTE_ORDER == BIG_ENDIAN
58178172Simpunsigned int	pg_prot:2,		/* SW: access control */
59178172Simp		pg_pfnum:24,		/* HW: core page frame number or 0 */
60178172Simp		pg_attr:3,		/* HW: cache attribute */
61178172Simp		pg_m:1,			/* HW: modified (dirty) bit */
62178172Simp		pg_v:1,			/* HW: valid bit */
63178172Simp		pg_g:1;			/* HW: ignore pid bit */
64178172Simp#endif
65178172Simp#if BYTE_ORDER == LITTLE_ENDIAN
66178172Simpunsigned int	pg_g:1,			/* HW: ignore pid bit */
67178172Simp		pg_v:1,			/* HW: valid bit */
68178172Simp		pg_m:1,			/* HW: modified (dirty) bit */
69178172Simp		pg_attr:3,		/* HW: cache attribute */
70178172Simp		pg_pfnum:24,		/* HW: core page frame number or 0 */
71178172Simp		pg_prot:2;		/* SW: access control */
72178172Simp#endif
73178172Simp};
74178172Simp
75178172Simp/*
76178172Simp * Structure defining an tlb entry data set.
77178172Simp */
78178172Simp
79178172Simpstruct tlb {
80178172Simp	int	tlb_mask;
81178172Simp	int	tlb_hi;
82178172Simp	int	tlb_lo0;
83178172Simp	int	tlb_lo1;
84178172Simp};
85178172Simp
86178172Simptypedef unsigned long pt_entry_t;
87178172Simptypedef pt_entry_t *pd_entry_t;
88178172Simp
89178172Simp#define	PDESIZE		sizeof(pd_entry_t)	/* for assembly files */
90178172Simp#define	PTESIZE		sizeof(pt_entry_t)	/* for assembly files */
91178172Simp
92178172Simp#endif /* _LOCORE */
93178172Simp
94178172Simp#define	PT_ENTRY_NULL	((pt_entry_t *) 0)
95178172Simp
96178172Simp#define	PTE_WIRED	0x80000000	/* SW */
97178172Simp#define	PTE_W		PTE_WIRED
98178172Simp#define	PTE_RO		0x40000000	/* SW */
99178172Simp
100178172Simp#define	PTE_G		0x00000001	/* HW */
101178172Simp#define	PTE_V		0x00000002
102178172Simp/*#define	PTE_NV		0x00000000       Not Used */
103178172Simp#define	PTE_M		0x00000004
104178172Simp#define	PTE_RW		PTE_M
105178172Simp#define PTE_ODDPG       0x00001000
106178172Simp/*#define	PG_ATTR		0x0000003f  Not Used */
107178172Simp#define	PTE_UNCACHED	0x00000010
108202031Simp#ifdef CPU_SB1
109202031Simp#define	PTE_CACHE	0x00000028	/* cacheable coherent */
110202031Simp#else
111178172Simp#define	PTE_CACHE	0x00000018
112202031Simp#endif
113178172Simp/*#define	PG_CACHEMODE	0x00000038 Not Used*/
114178172Simp#define	PTE_ROPAGE	(PTE_V | PTE_RO | PTE_CACHE) /* Write protected */
115178172Simp#define	PTE_RWPAGE	(PTE_V | PTE_M | PTE_CACHE)  /* Not wr-prot not clean */
116178172Simp#define	PTE_CWPAGE	(PTE_V | PTE_CACHE)	   /* Not wr-prot but clean */
117178172Simp#define	PTE_IOPAGE	(PTE_G | PTE_V | PTE_M | PTE_UNCACHED)
118178172Simp#define	PTE_FRAME	0x3fffffc0
119178172Simp#define PTE_HVPN        0xffffe000      /* Hardware page no mask */
120178172Simp#define PTE_ASID        0x000000ff      /* Address space ID */
121178172Simp
122178172Simp#define	PTE_SHIFT	6
123178172Simp#define	pfn_is_ext(x)	((x) & 0x3c000000)
124178172Simp#define	vad_to_pfn(x)	(((unsigned)(x) >> PTE_SHIFT) & PTE_FRAME)
125178172Simp#define	vad_to_pfn64(x)	((quad_t)(x) >> PTE_SHIFT) & PTE_FRAME)
126178172Simp#define	pfn_to_vad(x)	(((x) & PTE_FRAME) << PTE_SHIFT)
127178172Simp
128179648Swkoszek/* User virtual to pte offset in page table */
129178172Simp#define	vad_to_pte_offset(adr)	(((adr) >> PGSHIFT) & (NPTEPG -1))
130178172Simp
131178172Simp#define	mips_pg_v(entry)	((entry) & PTE_V)
132178172Simp#define	mips_pg_wired(entry)	((entry) & PTE_WIRED)
133178172Simp#define	mips_pg_m_bit()		(PTE_M)
134178172Simp#define	mips_pg_rw_bit()	(PTE_M)
135178172Simp#define	mips_pg_ro_bit()	(PTE_RO)
136178172Simp#define	mips_pg_ropage_bit()	(PTE_ROPAGE)
137178172Simp#define	mips_pg_rwpage_bit()	(PTE_RWPAGE)
138178172Simp#define	mips_pg_cwpage_bit()	(PTE_CWPAGE)
139178172Simp#define	mips_pg_global_bit()	(PTE_G)
140178172Simp#define	mips_pg_wired_bit()	(PTE_WIRED)
141178172Simp#define	mips_tlbpfn_to_paddr(x)	pfn_to_vad((x))
142178172Simp#define	mips_paddr_to_tlbpfn(x)	vad_to_pfn((x))
143178172Simp
144178172Simp/* These are not used */
145178172Simp#define	PTE_SIZE_4K	0x00000000
146178172Simp#define	PTE_SIZE_16K	0x00006000
147178172Simp#define	PTE_SIZE_64K	0x0001e000
148178172Simp#define	PTE_SIZE_256K	0x0007e000
149178172Simp#define	PTE_SIZE_1M	0x001fe000
150178172Simp#define	PTE_SIZE_4M	0x007fe000
151178172Simp#define	PTE_SIZE_16M	0x01ffe000
152178172Simp
153178172Simp#endif	/* !_MACHINE_PTE_H_ */
154