2 * Copyright (c) 2015 John H. Baldwin <jhb@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
29 #ifndef __KVM_MIPS_H__
30 #define __KVM_MIPS_H__
33 #include <machine/pte.h>
36 typedef uint64_t mips_physaddr_t;
38 #define MIPS_PAGE_SHIFT 12
39 #define MIPS_PAGE_SIZE (1 << MIPS_PAGE_SHIFT)
40 #define MIPS_PAGE_MASK (MIPS_PAGE_SIZE - 1)
42 #define MIPS32_KSEG0_START 0x80000000
43 #define MIPS32_KSEG0_END 0x9fffffff
44 #define MIPS32_KSEG1_START 0xa0000000
45 #define MIPS32_KSEG1_END 0xbfffffff
46 #define MIPS64_KSEG0_START 0xffffffff80000000
47 #define MIPS64_KSEG0_END 0xffffffff9fffffff
48 #define MIPS64_KSEG1_START 0xffffffffa0000000
49 #define MIPS64_KSEG1_END 0xffffffffbfffffff
51 #define MIPS32_PFN_MASK (0x1FFFFFC0)
52 #define MIPS64_PFN_MASK 0x3FFFFFFC0
53 #define MIPS_PFN_SHIFT (6)
55 #define MIPS_PFN_TO_PA(pfn) (((pfn) >> MIPS_PFN_SHIFT) << MIPS_PAGE_SHIFT)
56 #define MIPS32_PTE_TO_PFN(pte) ((pte) & MIPS32_PFN_MASK)
57 #define MIPS32_PTE_TO_PA(pte) (MIPS_PFN_TO_PA(MIPS32_PTE_TO_PFN((pte))))
58 #define MIPS64_PTE_TO_PFN(pte) ((pte) & MIPS64_PFN_MASK)
59 #define MIPS64_PTE_TO_PA(pte) (MIPS_PFN_TO_PA(MIPS64_PTE_TO_PFN((pte))))
62 _Static_assert(PAGE_SHIFT == MIPS_PAGE_SHIFT, "PAGE_SHIFT mismatch");
63 _Static_assert(PAGE_SIZE == MIPS_PAGE_SIZE, "PAGE_SIZE mismatch");
64 _Static_assert(PAGE_MASK == MIPS_PAGE_MASK, "PAGE_MASK mismatch");
66 _Static_assert((uint64_t)MIPS_KSEG0_START == MIPS64_KSEG0_START,
67 "MIPS_KSEG0_START mismatch");
68 _Static_assert((uint64_t)MIPS_KSEG0_END == MIPS64_KSEG0_END,
69 "MIPS_KSEG0_END mismatch");
70 _Static_assert((uint64_t)MIPS_KSEG1_START == MIPS64_KSEG1_START,
71 "MIPS_KSEG1_START mismatch");
72 _Static_assert((uint64_t)MIPS_KSEG1_END == MIPS64_KSEG1_END,
73 "MIPS_KSEG1_END mismatch");
75 _Static_assert((uint32_t)MIPS_KSEG0_START == MIPS32_KSEG0_START,
76 "MIPS_KSEG0_START mismatch");
77 _Static_assert((uint32_t)MIPS_KSEG0_END == MIPS32_KSEG0_END,
78 "MIPS_KSEG0_END mismatch");
79 _Static_assert((uint32_t)MIPS_KSEG1_START == MIPS32_KSEG1_START,
80 "MIPS_KSEG1_START mismatch");
81 _Static_assert((uint32_t)MIPS_KSEG1_END == MIPS32_KSEG1_END,
82 "MIPS_KSEG1_END mismatch");
84 #if defined(__mips_n64) || defined(__mips_n32)
85 _Static_assert(TLBLO_PFN_MASK == MIPS64_PFN_MASK, "TLBLO_PFN_MASK mismatch");
87 _Static_assert(TLBLO_PFN_MASK == MIPS32_PFN_MASK, "TLBLO_PFN_MASK mismatch");
89 _Static_assert(TLBLO_PFN_SHIFT == MIPS_PFN_SHIFT, "TLBLO_PFN_SHIFT mismatch");
90 _Static_assert(TLB_PAGE_SHIFT == MIPS_PAGE_SHIFT, "TLB_PAGE_SHIFT mismatch");
93 #endif /* !__KVM_MIPS_H__ */