Subversion Repositories HelenOS

Rev

Rev 3817 | Details | Compare with Previous | Last modification | View Log | RSS feed

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