kvm_mips.h revision 367457
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 * $FreeBSD: stable/11/lib/libkvm/kvm_mips.h 367457 2020-11-07 18:10:59Z dim $
26 */
27
28#ifndef __KVM_MIPS_H__
29#define	__KVM_MIPS_H__
30
31#ifdef __mips__
32#include <machine/pte.h>
33#endif
34
35typedef uint64_t	mips_physaddr_t;
36
37#define	MIPS_PAGE_SHIFT		12
38#define	MIPS_PAGE_SIZE		(1 << MIPS_PAGE_SHIFT)
39#define	MIPS_PAGE_MASK		(MIPS_PAGE_SIZE - 1)
40
41#define	MIPS32_KSEG0_START	0x80000000
42#define	MIPS32_KSEG0_END	0x9fffffff
43#define	MIPS32_KSEG1_START	0xa0000000
44#define	MIPS32_KSEG1_END	0xbfffffff
45#define	MIPS64_KSEG0_START	0xffffffff80000000
46#define	MIPS64_KSEG0_END	0xffffffff9fffffff
47#define	MIPS64_KSEG1_START	0xffffffffa0000000
48#define	MIPS64_KSEG1_END	0xffffffffbfffffff
49
50#define	MIPS32_PFN_MASK		(0x1FFFFFC0)
51#define	MIPS64_PFN_MASK		0x3FFFFFFC0
52#define	MIPS_PFN_SHIFT		(6)
53
54#define	MIPS_PFN_TO_PA(pfn)	(((pfn) >> MIPS_PFN_SHIFT) << MIPS_PAGE_SHIFT)
55#define	MIPS32_PTE_TO_PFN(pte)	((pte) & MIPS32_PFN_MASK)
56#define	MIPS32_PTE_TO_PA(pte)	(MIPS_PFN_TO_PA(MIPS32_PTE_TO_PFN((pte))))
57#define	MIPS64_PTE_TO_PFN(pte)	((pte) & MIPS64_PFN_MASK)
58#define	MIPS64_PTE_TO_PA(pte)	(MIPS_PFN_TO_PA(MIPS64_PTE_TO_PFN((pte))))
59
60#ifdef __mips__
61_Static_assert(PAGE_SHIFT == MIPS_PAGE_SHIFT, "PAGE_SHIFT mismatch");
62_Static_assert(PAGE_SIZE == MIPS_PAGE_SIZE, "PAGE_SIZE mismatch");
63_Static_assert(PAGE_MASK == MIPS_PAGE_MASK, "PAGE_MASK mismatch");
64#ifdef __mips_n64
65_Static_assert((uint64_t)MIPS_KSEG0_START == MIPS64_KSEG0_START,
66    "MIPS_KSEG0_START mismatch");
67_Static_assert((uint64_t)MIPS_KSEG0_END == MIPS64_KSEG0_END,
68    "MIPS_KSEG0_END mismatch");
69_Static_assert((uint64_t)MIPS_KSEG1_START == MIPS64_KSEG1_START,
70    "MIPS_KSEG1_START mismatch");
71_Static_assert((uint64_t)MIPS_KSEG1_END == MIPS64_KSEG1_END,
72    "MIPS_KSEG1_END mismatch");
73#else
74_Static_assert((uint32_t)MIPS_KSEG0_START == MIPS32_KSEG0_START,
75    "MIPS_KSEG0_START mismatch");
76_Static_assert((uint32_t)MIPS_KSEG0_END == MIPS32_KSEG0_END,
77    "MIPS_KSEG0_END mismatch");
78_Static_assert((uint32_t)MIPS_KSEG1_START == MIPS32_KSEG1_START,
79    "MIPS_KSEG1_START mismatch");
80_Static_assert((uint32_t)MIPS_KSEG1_END == MIPS32_KSEG1_END,
81    "MIPS_KSEG1_END mismatch");
82#endif
83#if defined(__mips_n64) || defined(__mips_n32)
84_Static_assert(TLBLO_PFN_MASK == MIPS64_PFN_MASK, "TLBLO_PFN_MASK mismatch");
85#else
86_Static_assert(TLBLO_PFN_MASK == MIPS32_PFN_MASK, "TLBLO_PFN_MASK mismatch");
87#endif
88_Static_assert(TLBLO_PFN_SHIFT == MIPS_PFN_SHIFT, "TLBLO_PFN_SHIFT mismatch");
89_Static_assert(TLB_PAGE_SHIFT == MIPS_PAGE_SHIFT, "TLB_PAGE_SHIFT mismatch");
90#endif
91
92#endif /* !__KVM_MIPS_H__ */
93