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