xref: /freebsd/lib/libkvm/kvm_arm.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
17f911abeSJohn Baldwin /*-
27f911abeSJohn Baldwin  * Copyright (c) 2015 John H. Baldwin <jhb@FreeBSD.org>
37f911abeSJohn Baldwin  *
47f911abeSJohn Baldwin  * Redistribution and use in source and binary forms, with or without
57f911abeSJohn Baldwin  * modification, are permitted provided that the following conditions
67f911abeSJohn Baldwin  * are met:
77f911abeSJohn Baldwin  * 1. Redistributions of source code must retain the above copyright
87f911abeSJohn Baldwin  *    notice, this list of conditions and the following disclaimer.
97f911abeSJohn Baldwin  * 2. Redistributions in binary form must reproduce the above copyright
107f911abeSJohn Baldwin  *    notice, this list of conditions and the following disclaimer in the
117f911abeSJohn Baldwin  *    documentation and/or other materials provided with the distribution.
127f911abeSJohn Baldwin  *
137f911abeSJohn Baldwin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
147f911abeSJohn Baldwin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
157f911abeSJohn Baldwin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
167f911abeSJohn Baldwin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
177f911abeSJohn Baldwin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
187f911abeSJohn Baldwin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
197f911abeSJohn Baldwin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
207f911abeSJohn Baldwin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
217f911abeSJohn Baldwin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
227f911abeSJohn Baldwin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
237f911abeSJohn Baldwin  * SUCH DAMAGE.
247f911abeSJohn Baldwin  */
257f911abeSJohn Baldwin 
267f911abeSJohn Baldwin #ifndef __KVM_ARM_H__
277f911abeSJohn Baldwin #define	__KVM_ARM_H__
287f911abeSJohn Baldwin 
297f911abeSJohn Baldwin typedef uint32_t	arm_physaddr_t;
307f911abeSJohn Baldwin typedef uint32_t	arm_pd_entry_t;
317f911abeSJohn Baldwin typedef uint32_t	arm_pt_entry_t;
327f911abeSJohn Baldwin 
337f911abeSJohn Baldwin #define	ARM_PAGE_SHIFT	12
347f911abeSJohn Baldwin #define	ARM_PAGE_SIZE	(1 << ARM_PAGE_SHIFT)	/* Page size */
357f911abeSJohn Baldwin #define	ARM_PAGE_MASK	(ARM_PAGE_SIZE - 1)
367f911abeSJohn Baldwin 
377f911abeSJohn Baldwin #define	ARM_L1_TABLE_SIZE	0x4000		/* 16K */
387f911abeSJohn Baldwin 
397f911abeSJohn Baldwin #define	ARM_L1_S_SIZE	0x00100000	/* 1M */
407f911abeSJohn Baldwin #define	ARM_L1_S_OFFSET	(ARM_L1_S_SIZE - 1)
417f911abeSJohn Baldwin #define	ARM_L1_S_FRAME	(~ARM_L1_S_OFFSET)
427f911abeSJohn Baldwin #define	ARM_L1_S_SHIFT	20
437f911abeSJohn Baldwin 
447f911abeSJohn Baldwin #define	ARM_L2_L_SIZE	0x00010000	/* 64K */
457f911abeSJohn Baldwin #define	ARM_L2_L_OFFSET	(ARM_L2_L_SIZE - 1)
467f911abeSJohn Baldwin #define	ARM_L2_L_FRAME	(~ARM_L2_L_OFFSET)
477f911abeSJohn Baldwin #define	ARM_L2_L_SHIFT	16
487f911abeSJohn Baldwin 
497f911abeSJohn Baldwin #define	ARM_L2_S_SIZE	0x00001000	/* 4K */
507f911abeSJohn Baldwin #define	ARM_L2_S_OFFSET	(ARM_L2_S_SIZE - 1)
517f911abeSJohn Baldwin #define	ARM_L2_S_FRAME	(~ARM_L2_S_OFFSET)
527f911abeSJohn Baldwin #define	ARM_L2_S_SHIFT	12
53c9057838SWill Andrews #define	ARM_L2_TEX1	0x00000080
54c9057838SWill Andrews #define	ARM_PTE2_RO	ARM_L2_TEX1
55c9057838SWill Andrews #define	ARM_L2_NX	0x00000001
56c9057838SWill Andrews #define	ARM_PTE2_NX	ARM_L2_NX
57c9057838SWill Andrews 
58c9057838SWill Andrews /*
59c9057838SWill Andrews  * Note: L2_S_PROT_W differs depending on whether the system is generic or
60c9057838SWill Andrews  *       xscale.  This isn't easily accessible in this context, so use an
61c9057838SWill Andrews  *       approximation of 'xscale' which is a subset of 'generic'.
62c9057838SWill Andrews  */
63c9057838SWill Andrews #define	ARM_L2_AP0(x)	((x) << 4)
64c9057838SWill Andrews #define	ARM_AP_W	0x01
65c9057838SWill Andrews #define	ARM_L2_S_PROT_W	(ARM_L2_AP0(ARM_AP_W))
667f911abeSJohn Baldwin 
677f911abeSJohn Baldwin #define	ARM_L1_TYPE_INV	0x00		/* Invalid (fault) */
687f911abeSJohn Baldwin #define	ARM_L1_TYPE_C	0x01		/* Coarse L2 */
697f911abeSJohn Baldwin #define	ARM_L1_TYPE_S	0x02		/* Section */
707f911abeSJohn Baldwin #define	ARM_L1_TYPE_MASK	0x03		/* Mask	of type	bits */
717f911abeSJohn Baldwin 
727f911abeSJohn Baldwin #define	ARM_L1_S_ADDR_MASK	0xfff00000	/* phys	address	of section */
737f911abeSJohn Baldwin #define	ARM_L1_C_ADDR_MASK	0xfffffc00	/* phys	address	of L2 Table */
747f911abeSJohn Baldwin 
757f911abeSJohn Baldwin #define	ARM_L2_TYPE_INV	0x00		/* Invalid (fault) */
76effb4b3cSSvatopluk Kraus #define	ARM_L2_TYPE_L	0x01		/* Large Page - 64k */
77effb4b3cSSvatopluk Kraus #define	ARM_L2_TYPE_S	0x02		/* Small Page -  4k */
78effb4b3cSSvatopluk Kraus #define	ARM_L2_TYPE_T	0x03		/* Tiny Page  -  1k - not used */
797f911abeSJohn Baldwin #define	ARM_L2_TYPE_MASK	0x03
807f911abeSJohn Baldwin 
817f911abeSJohn Baldwin #ifdef __arm__
82effb4b3cSSvatopluk Kraus #include <machine/acle-compat.h>
83effb4b3cSSvatopluk Kraus 
84*29629d9eSAndrew Turner #include <machine/pte.h>
8508674c45SSvatopluk Kraus 
867f911abeSJohn Baldwin _Static_assert(PAGE_SHIFT == ARM_PAGE_SHIFT, "PAGE_SHIFT mismatch");
877f911abeSJohn Baldwin _Static_assert(PAGE_SIZE == ARM_PAGE_SIZE, "PAGE_SIZE mismatch");
887f911abeSJohn Baldwin _Static_assert(PAGE_MASK == ARM_PAGE_MASK, "PAGE_MASK mismatch");
897f911abeSJohn Baldwin _Static_assert(L1_TABLE_SIZE == ARM_L1_TABLE_SIZE, "L1_TABLE_SIZE mismatch");
907f911abeSJohn Baldwin _Static_assert(L1_S_SIZE == ARM_L1_S_SIZE, "L1_S_SIZE mismatch");
917f911abeSJohn Baldwin _Static_assert(L1_S_OFFSET == ARM_L1_S_OFFSET, "L1_S_OFFSET mismatch");
927f911abeSJohn Baldwin _Static_assert(L1_S_FRAME == ARM_L1_S_FRAME, "L1_S_FRAME mismatch");
937f911abeSJohn Baldwin _Static_assert(L1_S_SHIFT == ARM_L1_S_SHIFT, "L1_S_SHIFT mismatch");
947f911abeSJohn Baldwin _Static_assert(L2_L_SIZE == ARM_L2_L_SIZE, "L2_L_SIZE mismatch");
957f911abeSJohn Baldwin _Static_assert(L2_L_OFFSET == ARM_L2_L_OFFSET, "L2_L_OFFSET mismatch");
967f911abeSJohn Baldwin _Static_assert(L2_L_FRAME == ARM_L2_L_FRAME, "L2_L_FRAME mismatch");
977f911abeSJohn Baldwin _Static_assert(L2_L_SHIFT == ARM_L2_L_SHIFT, "L2_L_SHIFT mismatch");
987f911abeSJohn Baldwin _Static_assert(L2_S_SIZE == ARM_L2_S_SIZE, "L2_S_SIZE mismatch");
997f911abeSJohn Baldwin _Static_assert(L2_S_OFFSET == ARM_L2_S_OFFSET, "L2_S_OFFSET mismatch");
1007f911abeSJohn Baldwin _Static_assert(L2_S_FRAME == ARM_L2_S_FRAME, "L2_S_FRAME mismatch");
1017f911abeSJohn Baldwin _Static_assert(L2_S_SHIFT == ARM_L2_S_SHIFT, "L2_S_SHIFT mismatch");
1027f911abeSJohn Baldwin _Static_assert(L1_TYPE_INV == ARM_L1_TYPE_INV, "L1_TYPE_INV mismatch");
1037f911abeSJohn Baldwin _Static_assert(L1_TYPE_C == ARM_L1_TYPE_C, "L1_TYPE_C mismatch");
1047f911abeSJohn Baldwin _Static_assert(L1_TYPE_S == ARM_L1_TYPE_S, "L1_TYPE_S mismatch");
1057f911abeSJohn Baldwin _Static_assert(L1_TYPE_MASK == ARM_L1_TYPE_MASK, "L1_TYPE_MASK mismatch");
1067f911abeSJohn Baldwin _Static_assert(L1_S_ADDR_MASK == ARM_L1_S_ADDR_MASK, "L1_S_ADDR_MASK mismatch");
1077f911abeSJohn Baldwin _Static_assert(L1_C_ADDR_MASK == ARM_L1_C_ADDR_MASK, "L1_C_ADDR_MASK mismatch");
1087f911abeSJohn Baldwin _Static_assert(L2_TYPE_INV == ARM_L2_TYPE_INV, "L2_TYPE_INV mismatch");
1097f911abeSJohn Baldwin _Static_assert(L2_TYPE_L == ARM_L2_TYPE_L, "L2_TYPE_L mismatch");
1107f911abeSJohn Baldwin _Static_assert(L2_TYPE_S == ARM_L2_TYPE_S, "L2_TYPE_S mismatch");
1117f911abeSJohn Baldwin _Static_assert(L2_TYPE_MASK == ARM_L2_TYPE_MASK, "L2_TYPE_MASK mismatch");
1127f911abeSJohn Baldwin #endif
1137f911abeSJohn Baldwin 
1147f911abeSJohn Baldwin int	_arm_native(kvm_t *);
1157f911abeSJohn Baldwin 
1167f911abeSJohn Baldwin #endif /* !__KVM_ARM_H__ */
117