2 * Copyright (c) 2015 John H. Baldwin <jhb@FreeBSD.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
28 #ifndef __KVM_MIPS_H__
29 #define __KVM_MIPS_H__
32 #include <machine/pte.h>
35 typedef uint64_t mips_physaddr_t;
37 typedef uint32_t mips32_pte_t;
38 typedef uint64_t mips64_pte_t;
40 #define MIPS_PAGE_SHIFT 12
41 #define MIPS_PAGE_SIZE (1 << MIPS_PAGE_SHIFT)
42 #define MIPS_PAGE_MASK (MIPS_PAGE_SIZE - 1)
44 #define MIPS32_KSEG0_START 0x80000000
45 #define MIPS32_KSEG0_END 0x9fffffff
46 #define MIPS32_KSEG1_START 0xa0000000
47 #define MIPS32_KSEG1_END 0xbfffffff
48 #define MIPS64_KSEG0_START 0xffffffff80000000
49 #define MIPS64_KSEG0_END 0xffffffff9fffffff
50 #define MIPS64_KSEG1_START 0xffffffffa0000000
51 #define MIPS64_KSEG1_END 0xffffffffbfffffff
53 #define MIPS32_PFN_MASK (0x1FFFFFC0)
54 #define MIPS64_PFN_MASK 0x3FFFFFFC0
55 #define MIPS_PFN_SHIFT (6)
57 #define MIPS_PFN_TO_PA(pfn) (((pfn) >> MIPS_PFN_SHIFT) << MIPS_PAGE_SHIFT)
58 #define MIPS32_PTE_TO_PFN(pte) ((pte) & MIPS32_PFN_MASK)
59 #define MIPS32_PTE_TO_PA(pte) (MIPS_PFN_TO_PA(MIPS32_PTE_TO_PFN((pte))))
60 #define MIPS64_PTE_TO_PFN(pte) ((pte) & MIPS64_PFN_MASK)
61 #define MIPS64_PTE_TO_PA(pte) (MIPS_PFN_TO_PA(MIPS64_PTE_TO_PFN((pte))))
63 #define MIPS32_SWBITS_SHIFT 29
64 #define MIPS64_SWBITS_SHIFT 55
65 #define MIPS_PTE_V 0x02
66 #define MIPS32_PTE_RO ((mips32_pte_t)0x01 << MIPS32_SWBITS_SHIFT)
67 #define MIPS64_PTE_RO ((mips64_pte_t)0x01 << MIPS64_SWBITS_SHIFT)
69 static inline mips32_pte_t
70 _mips32_pte_get(kvm_t *kd, u_long pteindex)
72 mips32_pte_t *pte = _kvm_pmap_get(kd, pteindex, sizeof(*pte));
74 return _kvm32toh(kd, *pte);
77 static inline mips64_pte_t
78 _mips64_pte_get(kvm_t *kd, u_long pteindex)
80 mips64_pte_t *pte = _kvm_pmap_get(kd, pteindex, sizeof(*pte));
82 return _kvm64toh(kd, *pte);
86 _Static_assert(PAGE_SHIFT == MIPS_PAGE_SHIFT, "PAGE_SHIFT mismatch");
87 _Static_assert(PAGE_SIZE == MIPS_PAGE_SIZE, "PAGE_SIZE mismatch");
88 _Static_assert(PAGE_MASK == MIPS_PAGE_MASK, "PAGE_MASK mismatch");
90 _Static_assert((uint64_t)MIPS_KSEG0_START == MIPS64_KSEG0_START,
91 "MIPS_KSEG0_START mismatch");
92 _Static_assert((uint64_t)MIPS_KSEG0_END == MIPS64_KSEG0_END,
93 "MIPS_KSEG0_END mismatch");
94 _Static_assert((uint64_t)MIPS_KSEG1_START == MIPS64_KSEG1_START,
95 "MIPS_KSEG1_START mismatch");
96 _Static_assert((uint64_t)MIPS_KSEG1_END == MIPS64_KSEG1_END,
97 "MIPS_KSEG1_END mismatch");
99 _Static_assert((uint32_t)MIPS_KSEG0_START == MIPS32_KSEG0_START,
100 "MIPS_KSEG0_START mismatch");
101 _Static_assert((uint32_t)MIPS_KSEG0_END == MIPS32_KSEG0_END,
102 "MIPS_KSEG0_END mismatch");
103 _Static_assert((uint32_t)MIPS_KSEG1_START == MIPS32_KSEG1_START,
104 "MIPS_KSEG1_START mismatch");
105 _Static_assert((uint32_t)MIPS_KSEG1_END == MIPS32_KSEG1_END,
106 "MIPS_KSEG1_END mismatch");
108 #if defined(__mips_n64) || defined(__mips_n32)
109 _Static_assert(TLBLO_PFN_MASK == MIPS64_PFN_MASK, "TLBLO_PFN_MASK mismatch");
111 _Static_assert(TLBLO_PFN_MASK == MIPS32_PFN_MASK, "TLBLO_PFN_MASK mismatch");
113 _Static_assert(TLBLO_PFN_SHIFT == MIPS_PFN_SHIFT, "TLBLO_PFN_SHIFT mismatch");
114 _Static_assert(TLB_PAGE_SHIFT == MIPS_PAGE_SHIFT, "TLB_PAGE_SHIFT mismatch");
117 #endif /* !__KVM_MIPS_H__ */