1/* $OpenBSD: pmap.h,v 1.19 2023/12/11 22:12:53 kettenis Exp $ */
2
3/*
4 * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#ifndef _MACHINE_PMAP_H_
20#define _MACHINE_PMAP_H_
21
22#include <sys/mutex.h>
23#include <sys/queue.h>
24
25#ifdef _KERNEL
26
27#include <machine/pte.h>
28
29/* V->P mapping data */
30#define VP_IDX1_CNT 256
31#define VP_IDX1_MASK (VP_IDX1_CNT - 1)
32#define VP_IDX1_POS 20
33#define VP_IDX2_CNT 256
34#define VP_IDX2_MASK (VP_IDX2_CNT - 1)
35#define VP_IDX2_POS 12
36
37struct pmap {
38 LIST_HEAD(,slb_desc) pm_slbd;
39 int pm_refs;
40 struct pmap_statistics pm_stats;
41 struct mutex pm_mtx;
42};
43
44typedef struct pmap *pmap_t;
45
46#define PG_PMAP_MOD PG_PMAP0
47#define PG_PMAP_REF PG_PMAP1
48#define PG_PMAP_EXE PG_PMAP2
49#define PG_PMAP_UC PG_PMAP3
50
51#define PMAP_CACHE_DEFAULT 0
52#define PMAP_CACHE_CI 1 /* cache inhibit */
53#define PMAP_CACHE_WB 3 /* write-back cached */
54
55/*
56 * MD flags that we use for pmap_enter (in the pa):
57 */
58#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) /* to remove the flags */
59#define PMAP_NOCACHE 0x1 /* map uncached */
60
61extern struct pmap kernel_pmap_store;
62
63#define pmap_kernel() (&kernel_pmap_store)
64#define pmap_resident_count(pm) ((pm)->pm_stats.resident_count)
65#define pmap_wired_count(pm) ((pm)->pm_stats.wired_count)
66
67#define pmap_init_percpu() do { /* nothing */ } while (0)
68#define pmap_unuse_final(p)
69#define pmap_remove_holes(vm)
70#define pmap_update(pm)
71
72void pmap_bootstrap(void);
73void pmap_bootstrap_cpu(void);
74
75int pmap_slbd_fault(pmap_t, vaddr_t);
76int pmap_slbd_enter(pmap_t, vaddr_t);
77int pmap_set_user_slb(pmap_t, vaddr_t, vaddr_t *, vsize_t *);
78void pmap_clear_user_slb(void);
79void pmap_unset_user_slb(void);
80
81#ifdef DDB
82struct pte;
83struct pte *pmap_get_kernel_pte(vaddr_t);
84#endif
85
86#endif /* _KERNEL */
87
88struct vm_page_md {
89 struct mutex pv_mtx;
90 LIST_HEAD(,pte_desc) pv_list;
91};
92
93#define VM_MDPAGE_INIT(pg) do { \
94 mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \
95 LIST_INIT(&((pg)->mdpage.pv_list)); \
96} while (0)
97
98#endif /* _MACHINE_PMAP_H_ */