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 typedef uint32_t mips32_pte_t;
39 typedef uint64_t mips64_pte_t;
41 #define MIPS_PAGE_SHIFT 12
42 #define MIPS_PAGE_SIZE (1 << MIPS_PAGE_SHIFT)
43 #define MIPS_PAGE_MASK (MIPS_PAGE_SIZE - 1)
45 #define MIPS32_KSEG0_START 0x80000000
46 #define MIPS32_KSEG0_END 0x9fffffff
47 #define MIPS32_KSEG1_START 0xa0000000
48 #define MIPS32_KSEG1_END 0xbfffffff
49 #define MIPS64_KSEG0_START 0xffffffff80000000
50 #define MIPS64_KSEG0_END 0xffffffff9fffffff
51 #define MIPS64_KSEG1_START 0xffffffffa0000000
52 #define MIPS64_KSEG1_END 0xffffffffbfffffff
54 #define MIPS32_PFN_MASK (0x1FFFFFC0)
55 #define MIPS64_PFN_MASK 0x3FFFFFFC0
56 #define MIPS_PFN_SHIFT (6)
58 #define MIPS_PFN_TO_PA(pfn) (((pfn) >> MIPS_PFN_SHIFT) << MIPS_PAGE_SHIFT)
59 #define MIPS32_PTE_TO_PFN(pte) ((pte) & MIPS32_PFN_MASK)
60 #define MIPS32_PTE_TO_PA(pte) (MIPS_PFN_TO_PA(MIPS32_PTE_TO_PFN((pte))))
61 #define MIPS64_PTE_TO_PFN(pte) ((pte) & MIPS64_PFN_MASK)
62 #define MIPS64_PTE_TO_PA(pte) (MIPS_PFN_TO_PA(MIPS64_PTE_TO_PFN((pte))))
64 #define MIPS32_SWBITS_SHIFT 29
65 #define MIPS64_SWBITS_SHIFT 55
66 #define MIPS_PTE_V 0x02
67 #define MIPS32_PTE_RO ((mips32_pte_t)0x01 << MIPS32_SWBITS_SHIFT)
68 #define MIPS64_PTE_RO ((mips64_pte_t)0x01 << MIPS64_SWBITS_SHIFT)
70 static inline mips32_pte_t
71 _mips32_pte_get(kvm_t *kd, u_long pteindex)
73 mips32_pte_t *pte = _kvm_pmap_get(kd, pteindex, sizeof(*pte));
75 return _kvm32toh(kd, *pte);
78 static inline mips64_pte_t
79 _mips64_pte_get(kvm_t *kd, u_long pteindex)
81 mips64_pte_t *pte = _kvm_pmap_get(kd, pteindex, sizeof(*pte));
83 return _kvm64toh(kd, *pte);
87 _Static_assert(PAGE_SHIFT == MIPS_PAGE_SHIFT, "PAGE_SHIFT mismatch");
88 _Static_assert(PAGE_SIZE == MIPS_PAGE_SIZE, "PAGE_SIZE mismatch");
89 _Static_assert(PAGE_MASK == MIPS_PAGE_MASK, "PAGE_MASK mismatch");
91 _Static_assert((uint64_t)MIPS_KSEG0_START == MIPS64_KSEG0_START,
92 "MIPS_KSEG0_START mismatch");
93 _Static_assert((uint64_t)MIPS_KSEG0_END == MIPS64_KSEG0_END,
94 "MIPS_KSEG0_END mismatch");
95 _Static_assert((uint64_t)MIPS_KSEG1_START == MIPS64_KSEG1_START,
96 "MIPS_KSEG1_START mismatch");
97 _Static_assert((uint64_t)MIPS_KSEG1_END == MIPS64_KSEG1_END,
98 "MIPS_KSEG1_END mismatch");
100 _Static_assert((uint32_t)MIPS_KSEG0_START == MIPS32_KSEG0_START,
101 "MIPS_KSEG0_START mismatch");
102 _Static_assert((uint32_t)MIPS_KSEG0_END == MIPS32_KSEG0_END,
103 "MIPS_KSEG0_END mismatch");
104 _Static_assert((uint32_t)MIPS_KSEG1_START == MIPS32_KSEG1_START,
105 "MIPS_KSEG1_START mismatch");
106 _Static_assert((uint32_t)MIPS_KSEG1_END == MIPS32_KSEG1_END,
107 "MIPS_KSEG1_END mismatch");
109 #if defined(__mips_n64) || defined(__mips_n32)
110 _Static_assert(TLBLO_PFN_MASK == MIPS64_PFN_MASK, "TLBLO_PFN_MASK mismatch");
112 _Static_assert(TLBLO_PFN_MASK == MIPS32_PFN_MASK, "TLBLO_PFN_MASK mismatch");
114 _Static_assert(TLBLO_PFN_SHIFT == MIPS_PFN_SHIFT, "TLBLO_PFN_SHIFT mismatch");
115 _Static_assert(TLB_PAGE_SHIFT == MIPS_PAGE_SHIFT, "TLB_PAGE_SHIFT mismatch");
118 #endif /* !__KVM_MIPS_H__ */