]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libkvm/kvm_mips.h
Add two missing eventhandler.h headers
[FreeBSD/FreeBSD.git] / lib / libkvm / kvm_mips.h
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$
26  */
27
28 #ifndef __KVM_MIPS_H__
29 #define __KVM_MIPS_H__
30
31 #ifdef __mips__
32 #include <machine/pte.h>
33 #endif
34
35 typedef uint64_t        mips_physaddr_t;
36
37 typedef uint32_t        mips32_pte_t;
38 typedef uint64_t        mips64_pte_t;
39
40 #define MIPS_PAGE_SHIFT         12
41 #define MIPS_PAGE_SIZE          (1 << MIPS_PAGE_SHIFT)
42 #define MIPS_PAGE_MASK          (MIPS_PAGE_SIZE - 1)
43
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
52
53 #define MIPS32_PFN_MASK         (0x1FFFFFC0)
54 #define MIPS64_PFN_MASK         0x3FFFFFFC0
55 #define MIPS_PFN_SHIFT          (6)
56
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))))
62
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)
68
69 static inline mips32_pte_t
70 _mips32_pte_get(kvm_t *kd, u_long pteindex)
71 {
72         mips32_pte_t *pte = _kvm_pmap_get(kd, pteindex, sizeof(*pte));
73
74         return _kvm32toh(kd, *pte);
75 }
76
77 static inline mips64_pte_t
78 _mips64_pte_get(kvm_t *kd, u_long pteindex)
79 {
80         mips64_pte_t *pte = _kvm_pmap_get(kd, pteindex, sizeof(*pte));
81
82         return _kvm64toh(kd, *pte);
83 }
84
85 #ifdef __mips__
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");
89 #ifdef __mips_n64
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");
98 #else
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");
107 #endif
108 #if defined(__mips_n64) || defined(__mips_n32)
109 _Static_assert(TLBLO_PFN_MASK == MIPS64_PFN_MASK, "TLBLO_PFN_MASK mismatch");
110 #else
111 _Static_assert(TLBLO_PFN_MASK == MIPS32_PFN_MASK, "TLBLO_PFN_MASK mismatch");
112 #endif
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");
115 #endif
116
117 #endif /* !__KVM_MIPS_H__ */