pmap.h revision 330897
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1991 Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * the Systems Programming Group of the University of Utah Computer
9 * Science Department and William Jolitz of UUNET Technologies Inc.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 4. Neither the name of the University nor the names of its contributors
20 *    may be used to endorse or promote products derived from this software
21 *    without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 *	from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90
36 *	from: @(#)pmap.h        7.4 (Berkeley) 5/12/91
37 *	from: FreeBSD: src/sys/i386/include/pmap.h,v 1.70 2000/11/30
38 * $FreeBSD: stable/11/sys/sparc64/include/pmap.h 330897 2018-03-14 03:19:51Z eadler $
39 */
40
41#ifndef	_MACHINE_PMAP_H_
42#define	_MACHINE_PMAP_H_
43
44#include <sys/queue.h>
45#include <sys/_cpuset.h>
46#include <sys/_lock.h>
47#include <sys/_mutex.h>
48#include <sys/_rwlock.h>
49#include <machine/cache.h>
50#include <machine/tte.h>
51
52#define	PMAP_CONTEXT_MAX	8192
53
54typedef	struct pmap *pmap_t;
55
56struct md_page {
57	TAILQ_HEAD(, tte) tte_list;
58	struct	pmap *pmap;
59	uint32_t colors[DCACHE_COLORS];
60	int32_t	color;
61};
62
63struct pmap {
64	struct	mtx pm_mtx;
65	struct	tte *pm_tsb;
66	vm_object_t pm_tsb_obj;
67	cpuset_t pm_active;
68	u_int	pm_context[MAXCPU];
69	struct	pmap_statistics pm_stats;
70};
71
72#define	PMAP_LOCK(pmap)		mtx_lock(&(pmap)->pm_mtx)
73#define	PMAP_LOCK_ASSERT(pmap, type)					\
74				mtx_assert(&(pmap)->pm_mtx, (type))
75#define	PMAP_LOCK_DESTROY(pmap)	mtx_destroy(&(pmap)->pm_mtx)
76#define	PMAP_LOCK_INIT(pmap)	mtx_init(&(pmap)->pm_mtx, "pmap",	\
77				    NULL, MTX_DEF | MTX_DUPOK)
78#define	PMAP_LOCKED(pmap)	mtx_owned(&(pmap)->pm_mtx)
79#define	PMAP_MTX(pmap)		(&(pmap)->pm_mtx)
80#define	PMAP_TRYLOCK(pmap)	mtx_trylock(&(pmap)->pm_mtx)
81#define	PMAP_UNLOCK(pmap)	mtx_unlock(&(pmap)->pm_mtx)
82
83#define	pmap_page_get_memattr(m)	VM_MEMATTR_DEFAULT
84#define	pmap_page_is_write_mapped(m)	(((m)->aflags & PGA_WRITEABLE) != 0)
85#define	pmap_page_set_memattr(m, ma)	(void)0
86
87void	pmap_bootstrap(u_int cpu_impl);
88vm_paddr_t pmap_kextract(vm_offset_t va);
89void	pmap_kenter(vm_offset_t va, vm_page_t m);
90void	pmap_kremove(vm_offset_t);
91void	pmap_kenter_flags(vm_offset_t va, vm_paddr_t pa, u_long flags);
92void	pmap_kremove_flags(vm_offset_t va);
93boolean_t pmap_page_is_mapped(vm_page_t m);
94
95int	pmap_cache_enter(vm_page_t m, vm_offset_t va);
96
97int	pmap_remove_tte(struct pmap *pm1, struct pmap *pm2, struct tte *tp,
98			vm_offset_t va);
99
100void	pmap_map_tsb(void);
101void	pmap_set_kctx(void);
102
103#define	vtophys(va)	pmap_kextract((vm_offset_t)(va))
104
105extern	struct pmap kernel_pmap_store;
106#define	kernel_pmap	(&kernel_pmap_store)
107extern	struct rwlock_padalign tte_list_global_lock;
108extern	vm_paddr_t phys_avail[];
109extern	vm_offset_t virtual_avail;
110extern	vm_offset_t virtual_end;
111
112#ifdef PMAP_STATS
113
114SYSCTL_DECL(_debug_pmap_stats);
115
116#define	PMAP_STATS_VAR(name) \
117	static long name; \
118	SYSCTL_LONG(_debug_pmap_stats, OID_AUTO, name, CTLFLAG_RW,	\
119	    &name, 0, "")
120
121#define	PMAP_STATS_INC(var) \
122	atomic_add_long(&var, 1)
123
124#else
125
126#define	PMAP_STATS_VAR(name)
127#define	PMAP_STATS_INC(var)
128
129#endif
130
131#endif /* !_MACHINE_PMAP_H_ */
132