xref: /illumos-gate/usr/src/uts/intel/io/vmm/sys/vmm_gpt.h (revision 50fe091cff3f2dccec5f588584a3ccb4f9933570)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 /* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */
12 
13 /*
14  * Copyright 2019 Joyent, Inc.
15  * Copyright 2025 Oxide Computer Company
16  */
17 
18 #ifndef _VMM_GPT_H
19 #define	_VMM_GPT_H
20 
21 #include <sys/types.h>
22 
23 /*
24  * Constants for the nodes in the GPT radix tree.  Note
25  * that, in accordance with hardware page table descriptions,
26  * the root of the tree is referred to as "LEVEL4" while the
27  * leaf level is "LEVEL1".
28  */
29 typedef enum vmm_gpt_node_level {
30 	LEVEL4 = 0,
31 	LEVEL3,
32 	LEVEL2,
33 	LEVEL1,
34 	MAX_GPT_LEVEL,
35 } vmm_gpt_node_level_t;
36 
37 struct vmm_gpt;
38 typedef struct vmm_gpt vmm_gpt_t;
39 
40 /* PTEs get a defined type to distinguish them from other uint64_t variables */
41 typedef uint64_t vmm_gpt_entry_t;
42 
43 typedef struct vmm_gpt_iter {
44 	vmm_gpt_t *vgi_gpt;
45 	uint64_t vgi_addr;
46 	uint64_t vgi_end;
47 	uint64_t vgi_current;
48 	vmm_gpt_entry_t *vgi_entries[MAX_GPT_LEVEL];
49 } vmm_gpt_iter_t;
50 
51 typedef struct vmm_gpt_iter_entry {
52 	uint64_t vgie_gpa;
53 	vmm_gpt_entry_t *vgie_ptep;
54 } vmm_gpt_iter_entry_t;
55 
56 struct vmm_pte_impl;
57 bool vmm_gpt_init(const struct vmm_pte_impl *);
58 void vmm_gpt_fini(void);
59 
60 vmm_gpt_t *vmm_gpt_alloc(void);
61 void vmm_gpt_free(vmm_gpt_t *);
62 
63 uint64_t vmm_gpt_walk(vmm_gpt_t *, uint64_t, vmm_gpt_entry_t **,
64     vmm_gpt_node_level_t);
65 void vmm_gpt_iter_init(vmm_gpt_iter_t *, vmm_gpt_t *, uint64_t, uint64_t);
66 bool vmm_gpt_iter_next(vmm_gpt_iter_t *, vmm_gpt_iter_entry_t *);
67 void vmm_gpt_populate_region(vmm_gpt_t *, uint64_t, uint64_t);
68 bool vmm_gpt_map_at(vmm_gpt_t *, vmm_gpt_entry_t *, pfn_t, uint_t, uint8_t);
69 void vmm_gpt_vacate_region(vmm_gpt_t *, uint64_t, uint64_t);
70 bool vmm_gpt_unmap(vmm_gpt_t *, uint64_t);
71 size_t vmm_gpt_unmap_region(vmm_gpt_t *, uint64_t, uint64_t);
72 uint64_t vmm_gpt_get_pmtp(vmm_gpt_t *, bool);
73 
74 bool vmm_gpte_is_mapped(const vmm_gpt_entry_t *, pfn_t *, uint_t *);
75 bool vmm_gpte_reset_accessed(vmm_gpt_entry_t *, bool);
76 bool vmm_gpte_reset_dirty(vmm_gpt_entry_t *, bool);
77 bool vmm_gpte_query_accessed(const vmm_gpt_entry_t *);
78 bool vmm_gpte_query_dirty(const vmm_gpt_entry_t *);
79 
80 bool vmm_gpt_can_track_dirty(vmm_gpt_t *);
81 
82 #endif /* _VMM_GPT_H */
83