xref: /freebsd/lib/libkvm/kvm_arm.h (revision 7d536dc855c85c15bf45f033d108a61b1f3cecc3)
1 /*-
2  * Copyright (c) 2015 John H. Baldwin <jhb@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef __KVM_ARM_H__
30 #define	__KVM_ARM_H__
31 
32 typedef uint32_t	arm_physaddr_t;
33 typedef uint32_t	arm_pd_entry_t;
34 typedef uint32_t	arm_pt_entry_t;
35 
36 #define	ARM_PAGE_SHIFT	12
37 #define	ARM_PAGE_SIZE	(1 << ARM_PAGE_SHIFT)	/* Page size */
38 #define	ARM_PAGE_MASK	(ARM_PAGE_SIZE - 1)
39 
40 #define	ARM_L1_TABLE_SIZE	0x4000		/* 16K */
41 
42 #define	ARM_L1_S_SIZE	0x00100000	/* 1M */
43 #define	ARM_L1_S_OFFSET	(ARM_L1_S_SIZE - 1)
44 #define	ARM_L1_S_FRAME	(~ARM_L1_S_OFFSET)
45 #define	ARM_L1_S_SHIFT	20
46 
47 #define	ARM_L2_L_SIZE	0x00010000	/* 64K */
48 #define	ARM_L2_L_OFFSET	(ARM_L2_L_SIZE - 1)
49 #define	ARM_L2_L_FRAME	(~ARM_L2_L_OFFSET)
50 #define	ARM_L2_L_SHIFT	16
51 
52 #define	ARM_L2_S_SIZE	0x00001000	/* 4K */
53 #define	ARM_L2_S_OFFSET	(ARM_L2_S_SIZE - 1)
54 #define	ARM_L2_S_FRAME	(~ARM_L2_S_OFFSET)
55 #define	ARM_L2_S_SHIFT	12
56 
57 #define	ARM_L1_TYPE_INV	0x00		/* Invalid (fault) */
58 #define	ARM_L1_TYPE_C	0x01		/* Coarse L2 */
59 #define	ARM_L1_TYPE_S	0x02		/* Section */
60 #define	ARM_L1_TYPE_MASK	0x03		/* Mask	of type	bits */
61 
62 #define	ARM_L1_S_ADDR_MASK	0xfff00000	/* phys	address	of section */
63 #define	ARM_L1_C_ADDR_MASK	0xfffffc00	/* phys	address	of L2 Table */
64 
65 #define	ARM_L2_TYPE_INV	0x00		/* Invalid (fault) */
66 #define	ARM_L2_TYPE_L	0x01		/* Large Page - 64k */
67 #define	ARM_L2_TYPE_S	0x02		/* Small Page -  4k */
68 #define	ARM_L2_TYPE_T	0x03		/* Tiny Page  -  1k - not used */
69 #define	ARM_L2_TYPE_MASK	0x03
70 
71 #ifdef __arm__
72 #include <machine/acle-compat.h>
73 
74 #if __ARM_ARCH >= 6
75 #include <machine/pte-v6.h>
76 #else
77 #include <machine/pte-v4.h>
78 #endif
79 
80 _Static_assert(PAGE_SHIFT == ARM_PAGE_SHIFT, "PAGE_SHIFT mismatch");
81 _Static_assert(PAGE_SIZE == ARM_PAGE_SIZE, "PAGE_SIZE mismatch");
82 _Static_assert(PAGE_MASK == ARM_PAGE_MASK, "PAGE_MASK mismatch");
83 _Static_assert(L1_TABLE_SIZE == ARM_L1_TABLE_SIZE, "L1_TABLE_SIZE mismatch");
84 _Static_assert(L1_S_SIZE == ARM_L1_S_SIZE, "L1_S_SIZE mismatch");
85 _Static_assert(L1_S_OFFSET == ARM_L1_S_OFFSET, "L1_S_OFFSET mismatch");
86 _Static_assert(L1_S_FRAME == ARM_L1_S_FRAME, "L1_S_FRAME mismatch");
87 _Static_assert(L1_S_SHIFT == ARM_L1_S_SHIFT, "L1_S_SHIFT mismatch");
88 _Static_assert(L2_L_SIZE == ARM_L2_L_SIZE, "L2_L_SIZE mismatch");
89 _Static_assert(L2_L_OFFSET == ARM_L2_L_OFFSET, "L2_L_OFFSET mismatch");
90 _Static_assert(L2_L_FRAME == ARM_L2_L_FRAME, "L2_L_FRAME mismatch");
91 _Static_assert(L2_L_SHIFT == ARM_L2_L_SHIFT, "L2_L_SHIFT mismatch");
92 _Static_assert(L2_S_SIZE == ARM_L2_S_SIZE, "L2_S_SIZE mismatch");
93 _Static_assert(L2_S_OFFSET == ARM_L2_S_OFFSET, "L2_S_OFFSET mismatch");
94 _Static_assert(L2_S_FRAME == ARM_L2_S_FRAME, "L2_S_FRAME mismatch");
95 _Static_assert(L2_S_SHIFT == ARM_L2_S_SHIFT, "L2_S_SHIFT mismatch");
96 _Static_assert(L1_TYPE_INV == ARM_L1_TYPE_INV, "L1_TYPE_INV mismatch");
97 _Static_assert(L1_TYPE_C == ARM_L1_TYPE_C, "L1_TYPE_C mismatch");
98 _Static_assert(L1_TYPE_S == ARM_L1_TYPE_S, "L1_TYPE_S mismatch");
99 _Static_assert(L1_TYPE_MASK == ARM_L1_TYPE_MASK, "L1_TYPE_MASK mismatch");
100 _Static_assert(L1_S_ADDR_MASK == ARM_L1_S_ADDR_MASK, "L1_S_ADDR_MASK mismatch");
101 _Static_assert(L1_C_ADDR_MASK == ARM_L1_C_ADDR_MASK, "L1_C_ADDR_MASK mismatch");
102 _Static_assert(L2_TYPE_INV == ARM_L2_TYPE_INV, "L2_TYPE_INV mismatch");
103 _Static_assert(L2_TYPE_L == ARM_L2_TYPE_L, "L2_TYPE_L mismatch");
104 _Static_assert(L2_TYPE_S == ARM_L2_TYPE_S, "L2_TYPE_S mismatch");
105 #if __ARM_ARCH < 6
106 _Static_assert(L2_TYPE_T == ARM_L2_TYPE_T, "L2_TYPE_T mismatch");
107 #endif
108 _Static_assert(L2_TYPE_MASK == ARM_L2_TYPE_MASK, "L2_TYPE_MASK mismatch");
109 #endif
110 
111 int	_arm_native(kvm_t *);
112 
113 #endif /* !__KVM_ARM_H__ */
114