Rev 3770 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3770 | Rev 3783 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Pavel Rimsky |
2 | * Copyright (c) 2008 Pavel Rimsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup sparc64 |
29 | /** @addtogroup sparc64 |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** |
32 | /** |
33 | * @file |
33 | * @file |
34 | * @brief Macros, constants and functions needed to perform a call to the |
34 | * @brief Macros, constants and functions needed to perform a call to the |
35 | * hypervisor API. For details and terminology see this document: |
35 | * hypervisor API. For details and terminology see this document: |
36 | * UltraSPARC Virtual Machine Specification (The Hypervisor API |
36 | * UltraSPARC Virtual Machine Specification (The Hypervisor API |
37 | * specification for Logical Domains). |
37 | * specification for Logical Domains). |
38 | * |
38 | * |
39 | */ |
39 | */ |
40 | 40 | ||
41 | #ifndef KERN_sparc64_sun4v_HYPERCALL_H_ |
41 | #ifndef KERN_sparc64_sun4v_HYPERCALL_H_ |
42 | #define KERN_sparc64_sun4v_HYPERCALL_H_ |
42 | #define KERN_sparc64_sun4v_HYPERCALL_H_ |
43 | 43 | ||
44 | /* SW trap numbers for hyperfast traps */ |
44 | /* SW trap numbers for hyperfast traps */ |
45 | #define FAST_TRAP 0x80 |
45 | #define FAST_TRAP 0x80 |
46 | #define MMU_MAP_ADDR 0x83 |
46 | #define MMU_MAP_ADDR 0x83 |
47 | #define MMU_UNMAP_ADDR 0x84 |
47 | #define MMU_UNMAP_ADDR 0x84 |
48 | 48 | ||
49 | /* function codes for fast traps */ |
49 | /* function codes for fast traps */ |
50 | #define MACH_DESC 0x01 |
50 | #define MACH_DESC 0x01 |
51 | #define CPU_START 0x10 |
51 | #define CPU_START 0x10 |
52 | #define CPU_STOP 0x11 |
52 | #define CPU_STOP 0x11 |
53 | #define CPU_YIELD 0x12 |
53 | #define CPU_YIELD 0x12 |
54 | #define CPU_MYID 0x16 |
54 | #define CPU_MYID 0x16 |
55 | #define CPU_STATE 0x17 |
55 | #define CPU_STATE 0x17 |
56 | #define CPU_SET_RTBA 0x18 |
56 | #define CPU_SET_RTBA 0x18 |
57 | #define CPU_GET_RTBA 0x19 |
57 | #define CPU_GET_RTBA 0x19 |
58 | #define MMU_TSB_CTX0 0x20 |
58 | #define MMU_TSB_CTX0 0x20 |
59 | #define MMU_TSB_CTXNON0 0x21 |
59 | #define MMU_TSB_CTXNON0 0x21 |
60 | #define MMU_DEMAP_PAGE 0x22 |
60 | #define MMU_DEMAP_PAGE 0x22 |
61 | #define MMU_DEMAP_CTX 0x23 |
61 | #define MMU_DEMAP_CTX 0x23 |
62 | #define MMU_DEMAP_ALL 0x24 |
62 | #define MMU_DEMAP_ALL 0x24 |
63 | #define MMU_MAP_PERM_ADDR 0x25 |
63 | #define MMU_MAP_PERM_ADDR 0x25 |
64 | #define MMU_FAULT_AREA_CONF 0x26 |
64 | #define MMU_FAULT_AREA_CONF 0x26 |
65 | #define MMU_ENABLE 0x27 |
65 | #define MMU_ENABLE 0x27 |
66 | #define MMU_UNMAP_PERM_ADDR 0x28 |
66 | #define MMU_UNMAP_PERM_ADDR 0x28 |
67 | #define MMU_TSB_CTX0_INFO 0x29 |
67 | #define MMU_TSB_CTX0_INFO 0x29 |
68 | #define MMU_TSB_CTXNON0_INFO 0x2a |
68 | #define MMU_TSB_CTXNON0_INFO 0x2a |
69 | #define MMU_FAULT_AREA_INFO 0x2b |
69 | #define MMU_FAULT_AREA_INFO 0x2b |
70 | #define CPU_MONDO_SEND 0x42 |
70 | #define CPU_MONDO_SEND 0x42 |
71 | #define CONS_GETCHAR 0x60 |
71 | #define CONS_GETCHAR 0x60 |
72 | #define CONS_PUTCHAR 0x61 |
72 | #define CONS_PUTCHAR 0x61 |
73 | 73 | ||
74 | 74 | ||
75 | /* return codes */ |
75 | /* return codes */ |
76 | #define EOK 0 /**< Successful return */ |
76 | #define EOK 0 /**< Successful return */ |
77 | #define ENOCPU 1 /**< Invalid CPU id */ |
77 | #define ENOCPU 1 /**< Invalid CPU id */ |
78 | #define ENORADDR 2 /**< Invalid real address */ |
78 | #define ENORADDR 2 /**< Invalid real address */ |
79 | #define ENOINTR 3 /**< Invalid interrupt id */ |
79 | #define ENOINTR 3 /**< Invalid interrupt id */ |
80 | #define EBADPGSZ 4 /**< Invalid pagesize encoding */ |
80 | #define EBADPGSZ 4 /**< Invalid pagesize encoding */ |
81 | #define EBADTSB 5 /**< Invalid TSB description */ |
81 | #define EBADTSB 5 /**< Invalid TSB description */ |
82 | #define EINVAL 6 /**< Invalid argument */ |
82 | #define EINVAL 6 /**< Invalid argument */ |
83 | #define EBADTRAP 7 /**< Invalid function number */ |
83 | #define EBADTRAP 7 /**< Invalid function number */ |
84 | #define EBADALIGN 8 /**< Invalid address alignment */ |
84 | #define EBADALIGN 8 /**< Invalid address alignment */ |
85 | #define EWOULDBLOCK 9 /**< Cannot complete operation without blocking */ |
85 | #define EWOULDBLOCK 9 /**< Cannot complete operation without blocking */ |
86 | #define ENOACCESS 10 /**< No access to specified resource */ |
86 | #define ENOACCESS 10 /**< No access to specified resource */ |
87 | #define EIO 11 /**< I/O Error */ |
87 | #define EIO 11 /**< I/O Error */ |
88 | #define ECPUERROR 12 /**< CPU is in error state */ |
88 | #define ECPUERROR 12 /**< CPU is in error state */ |
89 | #define ENOTSUPPORTED 13 /**< Function not supported */ |
89 | #define ENOTSUPPORTED 13 /**< Function not supported */ |
90 | #define ENOMAP 14 /**< No mapping found */ |
90 | #define ENOMAP 14 /**< No mapping found */ |
91 | #define ETOOMANY 15 /**< Too many items specified / limit reached */ |
91 | #define ETOOMANY 15 /**< Too many items specified / limit reached */ |
92 | #define ECHANNEL 16 /**< Invalid LDC channel */ |
92 | #define ECHANNEL 16 /**< Invalid LDC channel */ |
93 | #define EBUSY 17 /**< Operation failed as resource is otherwise busy */ |
93 | #define EBUSY 17 /**< Operation failed as resource is otherwise busy */ |
94 | 94 | ||
95 | 95 | ||
96 | /** |
96 | /** |
97 | * Performs a hyperfast hypervisor API call from the assembly language code. |
97 | * Performs a hyperfast hypervisor API call from the assembly language code. |
98 | * Expects the registers %o1-%o4 are properly filled with the arguments of the |
98 | * Expects the registers %o1-%o4 are properly filled with the arguments of the |
99 | * call. |
99 | * call. |
100 | * |
100 | * |
101 | * @param function_number hyperfast call function number |
101 | * @param function_number hyperfast call function number |
102 | */ |
102 | */ |
103 | #define __HYPERCALL_FAST(function_number) \ |
103 | #define __HYPERCALL_FAST(function_number) \ |
104 | set function_number, %o5; \ |
104 | set function_number, %o5; \ |
105 | ta FAST_TRAP; |
105 | ta FAST_TRAP; |
106 | 106 | ||
107 | /** |
107 | /** |
108 | * Performs a fast hypervisor API call from the assembly language code. |
108 | * Performs a fast hypervisor API call from the assembly language code. |
109 | * Expects the registers %o1-%o4 are properly filled with the arguments of the |
109 | * Expects the registers %o1-%o4 are properly filled with the arguments of the |
110 | * call. |
110 | * call. |
111 | * |
111 | * |
112 | * @param sw_trap_number software trap number |
112 | * @param sw_trap_number software trap number |
113 | */ |
113 | */ |
114 | #define __HYPERCALL_HYPERFAST(sw_trap_number) \ |
114 | #define __HYPERCALL_HYPERFAST(sw_trap_number) \ |
115 | ta (sw_trap_number); |
115 | ta (sw_trap_number); |
116 | 116 | ||
117 | 117 | ||
118 | #ifndef __ASM__ |
118 | #ifndef __ASM__ |
119 | 119 | ||
- | 120 | #include <typedefs.h> |
|
- | 121 | #include <arch/types.h> |
|
- | 122 | ||
120 | /* |
123 | /* |
121 | * Macros to be used from the C-language code; __hypercall_fastN performs |
124 | * Macros to be used from the C-language code; __hypercall_fastN performs |
122 | * a fast hypervisor API call taking exactly N arguments. |
125 | * a fast hypervisor API call taking exactly N arguments. |
123 | */ |
126 | */ |
124 | 127 | ||
125 | #define __hypercall_fast0(function_number) \ |
128 | #define __hypercall_fast0(function_number) \ |
126 | __hypercall_fast(0, 0, 0, 0, 0, function_number) |
129 | __hypercall_fast(0, 0, 0, 0, 0, function_number) |
127 | #define __hypercall_fast1(function_number, p1) \ |
130 | #define __hypercall_fast1(function_number, p1) \ |
128 | __hypercall_fast(p1, 0, 0, 0, 0, function_number) |
131 | __hypercall_fast(p1, 0, 0, 0, 0, function_number) |
129 | #define __hypercall_fast2(function_number, p1, p2) \ |
132 | #define __hypercall_fast2(function_number, p1, p2) \ |
130 | __hypercall_fast(p1, p2, 0, 0, 0, function_number) |
133 | __hypercall_fast(p1, p2, 0, 0, 0, function_number) |
131 | #define __hypercall_fast3(function_number, p1, p2, p3) \ |
134 | #define __hypercall_fast3(function_number, p1, p2, p3) \ |
132 | __hypercall_fast(p1, p2, p3, 0, 0, function_number) |
135 | __hypercall_fast(p1, p2, p3, 0, 0, function_number) |
133 | #define __hypercall_fast4(function_number, p1, p2, p3, p4) \ |
136 | #define __hypercall_fast4(function_number, p1, p2, p3, p4) \ |
134 | __hypercall_fast(p1, p2, p3, p4, 0, function_number) |
137 | __hypercall_fast(p1, p2, p3, p4, 0, function_number) |
135 | #define __hypercall_fast5(function_number, p1, p2, p3, p4, p5) \ |
138 | #define __hypercall_fast5(function_number, p1, p2, p3, p4, p5) \ |
136 | __hypercall_fast(p1, p2, p3, p4, p5, function_number) |
139 | __hypercall_fast(p1, p2, p3, p4, p5, function_number) |
137 | 140 | ||
138 | /** |
141 | /** |
139 | * Performs a fast hypervisor API call which can returns a value. |
142 | * Performs a fast hypervisor API call which can returns a value. |
140 | * |
143 | * |
141 | * @param p1 the 1st argument of the hypervisor API call |
144 | * @param p1 the 1st argument of the hypervisor API call |
142 | * @param p2 the 2nd argument of the hypervisor API call |
145 | * @param p2 the 2nd argument of the hypervisor API call |
143 | * @param p3 the 3rd argument of the hypervisor API call |
146 | * @param p3 the 3rd argument of the hypervisor API call |
144 | * @param p4 the 4th argument of the hypervisor API call |
147 | * @param p4 the 4th argument of the hypervisor API call |
145 | * @param p5 the 5th argument of the hypervisor API call |
148 | * @param p5 the 5th argument of the hypervisor API call |
146 | * @param function_number function number of the call |
149 | * @param function_number function number of the call |
147 | * @param ret1 pointer to an address where the return value |
150 | * @param ret1 pointer to an address where the return value |
148 | * of the hypercall should be saved, or NULL |
151 | * of the hypercall should be saved, or NULL |
149 | * @return error status |
152 | * @return error status |
150 | */ |
153 | */ |
151 | static inline uint64_t |
154 | static inline uint64_t |
152 | __hypercall_fast_ret1(const uint64_t p1, const uint64_t p2, const uint64_t p3, |
155 | __hypercall_fast_ret1(const uint64_t p1, const uint64_t p2, const uint64_t p3, |
153 | const uint64_t p4, const uint64_t p5, const uint64_t function_number, |
156 | const uint64_t p4, const uint64_t p5, const uint64_t function_number, |
154 | uint64_t * const ret1) |
157 | uint64_t * const ret1) |
155 | { |
158 | { |
156 | register uint64_t a6 asm("o5") = function_number; |
159 | register uint64_t a6 asm("o5") = function_number; |
157 | register uint64_t a1 asm("o0") = p1; |
160 | register uint64_t a1 asm("o0") = p1; |
158 | register uint64_t a2 asm("o1") = p2; |
161 | register uint64_t a2 asm("o1") = p2; |
159 | register uint64_t a3 asm("o2") = p3; |
162 | register uint64_t a3 asm("o2") = p3; |
160 | register uint64_t a4 asm("o3") = p4; |
163 | register uint64_t a4 asm("o3") = p4; |
161 | register uint64_t a5 asm("o4") = p5; |
164 | register uint64_t a5 asm("o4") = p5; |
162 | 165 | ||
163 | asm volatile ( |
166 | asm volatile ( |
164 | "ta %7\n" |
167 | "ta %7\n" |
165 | : "=r" (a1) |
168 | : "=r" (a1) |
166 | : "r" (a1), "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), |
169 | : "r" (a1), "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), |
167 | "i" (FAST_TRAP) |
170 | "i" (FAST_TRAP) |
168 | : "memory" |
171 | : "memory" |
169 | ); |
172 | ); |
170 | 173 | ||
171 | if (ret1 != NULL) |
174 | if (ret1 != NULL) |
172 | *ret1 = a2; |
175 | *ret1 = a2; |
173 | return a1; |
176 | return a1; |
174 | } |
177 | } |
175 | 178 | ||
176 | /** |
179 | /** |
177 | * Performs a fast hypervisor API call which return no value except for the |
180 | * Performs a fast hypervisor API call which return no value except for the |
178 | * error status. |
181 | * error status. |
179 | * |
182 | * |
180 | * @param p1 the 1st argument of the hypervisor API call |
183 | * @param p1 the 1st argument of the hypervisor API call |
181 | * @param p2 the 2nd argument of the hypervisor API call |
184 | * @param p2 the 2nd argument of the hypervisor API call |
182 | * @param p3 the 3rd argument of the hypervisor API call |
185 | * @param p3 the 3rd argument of the hypervisor API call |
183 | * @param p4 the 4th argument of the hypervisor API call |
186 | * @param p4 the 4th argument of the hypervisor API call |
184 | * @param p5 the 5th argument of the hypervisor API call |
187 | * @param p5 the 5th argument of the hypervisor API call |
185 | * @param function_number function number of the call |
188 | * @param function_number function number of the call |
186 | * @return error status |
189 | * @return error status |
187 | */ |
190 | */ |
188 | static inline uint64_t |
191 | static inline uint64_t |
189 | __hypercall_fast(const uint64_t p1, const uint64_t p2, const uint64_t p3, |
192 | __hypercall_fast(const uint64_t p1, const uint64_t p2, const uint64_t p3, |
190 | const uint64_t p4, const uint64_t p5, const uint64_t function_number) |
193 | const uint64_t p4, const uint64_t p5, const uint64_t function_number) |
191 | { |
194 | { |
192 | return __hypercall_fast_ret1(p1, p2, p3, p4, p5, function_number, |
195 | return __hypercall_fast_ret1(p1, p2, p3, p4, p5, function_number, |
193 | NULL); |
196 | NULL); |
194 | } |
197 | } |
195 | 198 | ||
196 | /** |
199 | /** |
197 | * Performs a hyperfast hypervisor API call. |
200 | * Performs a hyperfast hypervisor API call. |
198 | * |
201 | * |
199 | * @param p1 the 1st argument of the hypervisor API call |
202 | * @param p1 the 1st argument of the hypervisor API call |
200 | * @param p2 the 2nd argument of the hypervisor API call |
203 | * @param p2 the 2nd argument of the hypervisor API call |
201 | * @param p3 the 3rd argument of the hypervisor API call |
204 | * @param p3 the 3rd argument of the hypervisor API call |
202 | * @param p4 the 4th argument of the hypervisor API call |
205 | * @param p4 the 4th argument of the hypervisor API call |
203 | * @param p5 the 5th argument of the hypervisor API call |
206 | * @param p5 the 5th argument of the hypervisor API call |
204 | * @param sw_trap_number software trap number |
207 | * @param sw_trap_number software trap number |
205 | */ |
208 | */ |
206 | static inline uint64_t |
209 | static inline uint64_t |
207 | __hypercall_hyperfast(const uint64_t p1, const uint64_t p2, const uint64_t p3, |
210 | __hypercall_hyperfast(const uint64_t p1, const uint64_t p2, const uint64_t p3, |
208 | const uint64_t p4, const uint64_t p5, const uint64_t sw_trap_number) |
211 | const uint64_t p4, const uint64_t p5, const uint64_t sw_trap_number) |
209 | { |
212 | { |
210 | register uint64_t a1 asm("o0") = p1; |
213 | register uint64_t a1 asm("o0") = p1; |
211 | register uint64_t a2 asm("o1") = p2; |
214 | register uint64_t a2 asm("o1") = p2; |
212 | register uint64_t a3 asm("o2") = p3; |
215 | register uint64_t a3 asm("o2") = p3; |
213 | register uint64_t a4 asm("o3") = p4; |
216 | register uint64_t a4 asm("o3") = p4; |
214 | register uint64_t a5 asm("o4") = p5; |
217 | register uint64_t a5 asm("o4") = p5; |
215 | 218 | ||
216 | asm volatile ( |
219 | asm volatile ( |
217 | "ta %6\n" |
220 | "ta %6\n" |
218 | : "=r" (a1) |
221 | : "=r" (a1) |
219 | : "r" (a1), "r" (a2), "r" (a3), "r" (a4), "r" (a5), |
222 | : "r" (a1), "r" (a2), "r" (a3), "r" (a4), "r" (a5), |
220 | "i" (sw_trap_number) |
223 | "i" (sw_trap_number) |
221 | : "memory" |
224 | : "memory" |
222 | ); |
225 | ); |
223 | 226 | ||
224 | return a1; |
227 | return a1; |
225 | } |
228 | } |
226 | 229 | ||
227 | #endif /* ASM */ |
230 | #endif /* ASM */ |
228 | 231 | ||
229 | #endif |
232 | #endif |
230 | 233 | ||
231 | /** @} |
234 | /** @} |
232 | */ |
235 | */ |
233 | 236 |