~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/firmware/hvmloader/hypercall.h

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 * hypercall.h
 
3
 * 
 
4
 * Copyright (c) 2002-2006, K A Fraser
 
5
 * 
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License version 2
 
8
 * as published by the Free Software Foundation; or, when distributed
 
9
 * separately from the Linux kernel or incorporated into other
 
10
 * software packages, subject to the following license:
 
11
 * 
 
12
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 
13
 * of this source file (the "Software"), to deal in the Software without
 
14
 * restriction, including without limitation the rights to use, copy, modify,
 
15
 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
 
16
 * and to permit persons to whom the Software is furnished to do so, subject to
 
17
 * the following conditions:
 
18
 * 
 
19
 * The above copyright notice and this permission notice shall be included in
 
20
 * all copies or substantial portions of the Software.
 
21
 * 
 
22
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
23
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
24
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
25
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
26
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
27
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
28
 * IN THE SOFTWARE.
 
29
 */
 
30
 
 
31
#ifndef __HVMLOADER_HYPERCALL_H__
 
32
#define __HVMLOADER_HYPERCALL_H__
 
33
 
 
34
#include <stdint.h>
 
35
#include <xen/xen.h>
 
36
#include "config.h"
 
37
 
 
38
/*
 
39
 * NB. Hypercall address needs to be relative to a linkage symbol for
 
40
 * some version of ld to relocate the relative calls properly.
 
41
 */
 
42
#define hypercall_pa "_start - " STR(HYPERCALL_PHYSICAL_ADDRESS)
 
43
 
 
44
#define _hypercall0(type, name)                                         \
 
45
({                                                                      \
 
46
        long __res;                                                     \
 
47
        asm volatile (                                                  \
 
48
                "call "hypercall_pa" + " STR(__HYPERVISOR_##name * 32)  \
 
49
                : "=a" (__res)                                          \
 
50
                :                                                       \
 
51
                : "memory" );                                           \
 
52
        (type)__res;                                                    \
 
53
})
 
54
 
 
55
#define _hypercall1(type, name, a1)                                     \
 
56
({                                                                      \
 
57
        long __res, __ign1;                                             \
 
58
        asm volatile (                                                  \
 
59
                "call "hypercall_pa" + " STR(__HYPERVISOR_##name * 32)  \
 
60
                : "=a" (__res), "=b" (__ign1)                           \
 
61
                : "1" ((long)(a1))                                      \
 
62
                : "memory" );                                           \
 
63
        (type)__res;                                                    \
 
64
})
 
65
 
 
66
#define _hypercall2(type, name, a1, a2)                                 \
 
67
({                                                                      \
 
68
        long __res, __ign1, __ign2;                                     \
 
69
        asm volatile (                                                  \
 
70
                "call "hypercall_pa" + " STR(__HYPERVISOR_##name * 32)  \
 
71
                : "=a" (__res), "=b" (__ign1), "=c" (__ign2)            \
 
72
                : "1" ((long)(a1)), "2" ((long)(a2))                    \
 
73
                : "memory" );                                           \
 
74
        (type)__res;                                                    \
 
75
})
 
76
 
 
77
#define _hypercall3(type, name, a1, a2, a3)                             \
 
78
({                                                                      \
 
79
        long __res, __ign1, __ign2, __ign3;                             \
 
80
        asm volatile (                                                  \
 
81
                "call "hypercall_pa" + " STR(__HYPERVISOR_##name * 32)  \
 
82
                : "=a" (__res), "=b" (__ign1), "=c" (__ign2),           \
 
83
                "=d" (__ign3)                                           \
 
84
                : "1" ((long)(a1)), "2" ((long)(a2)),                   \
 
85
                "3" ((long)(a3))                                        \
 
86
                : "memory" );                                           \
 
87
        (type)__res;                                                    \
 
88
})
 
89
 
 
90
#define _hypercall4(type, name, a1, a2, a3, a4)                         \
 
91
({                                                                      \
 
92
        long __res, __ign1, __ign2, __ign3, __ign4;                     \
 
93
        asm volatile (                                                  \
 
94
                "call "hypercall_pa" + " STR(__HYPERVISOR_##name * 32)  \
 
95
                : "=a" (__res), "=b" (__ign1), "=c" (__ign2),           \
 
96
                "=d" (__ign3), "=S" (__ign4)                            \
 
97
                : "1" ((long)(a1)), "2" ((long)(a2)),                   \
 
98
                "3" ((long)(a3)), "4" ((long)(a4))                      \
 
99
                : "memory" );                                           \
 
100
        (type)__res;                                                    \
 
101
})
 
102
 
 
103
#define _hypercall5(type, name, a1, a2, a3, a4, a5)                     \
 
104
({                                                                      \
 
105
        long __res, __ign1, __ign2, __ign3, __ign4, __ign5;             \
 
106
        asm volatile (                                                  \
 
107
                "call "hypercall_pa" + " STR(__HYPERVISOR_##name * 32)  \
 
108
                : "=a" (__res), "=b" (__ign1), "=c" (__ign2),           \
 
109
                "=d" (__ign3), "=S" (__ign4), "=D" (__ign5)             \
 
110
                : "1" ((long)(a1)), "2" ((long)(a2)),                   \
 
111
                "3" ((long)(a3)), "4" ((long)(a4)),                     \
 
112
                "5" ((long)(a5))                                        \
 
113
                : "memory" );                                           \
 
114
        (type)__res;                                                    \
 
115
})
 
116
 
 
117
static inline int
 
118
hypercall_sched_op(
 
119
        int cmd, void *arg)
 
120
{
 
121
        return _hypercall2(int, sched_op, cmd, arg);
 
122
}
 
123
 
 
124
static inline int
 
125
hypercall_memory_op(
 
126
        unsigned int cmd, void *arg)
 
127
{
 
128
        return _hypercall2(int, memory_op, cmd, arg);
 
129
}
 
130
 
 
131
static inline int
 
132
hypercall_multicall(
 
133
        void *call_list, int nr_calls)
 
134
{
 
135
        return _hypercall2(int, multicall, call_list, nr_calls);
 
136
}
 
137
 
 
138
static inline int
 
139
hypercall_event_channel_op(
 
140
        int cmd, void *arg)
 
141
{
 
142
        return _hypercall2(int, event_channel_op, cmd, arg);
 
143
}
 
144
 
 
145
static inline int
 
146
hypercall_xen_version(
 
147
        int cmd, void *arg)
 
148
{
 
149
        return _hypercall2(int, xen_version, cmd, arg);
 
150
}
 
151
 
 
152
static inline int
 
153
hypercall_console_io(
 
154
        int cmd, int count, char *str)
 
155
{
 
156
        return _hypercall3(int, console_io, cmd, count, str);
 
157
}
 
158
 
 
159
static inline int
 
160
hypercall_vm_assist(
 
161
        unsigned int cmd, unsigned int type)
 
162
{
 
163
        return _hypercall2(int, vm_assist, cmd, type);
 
164
}
 
165
 
 
166
static inline int
 
167
hypercall_vcpu_op(
 
168
        int cmd, int vcpuid, void *extra_args)
 
169
{
 
170
        return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
 
171
}
 
172
 
 
173
static inline int
 
174
hypercall_hvm_op(
 
175
        int cmd, void *arg)
 
176
{
 
177
        return _hypercall2(int, hvm_op, cmd, arg);
 
178
}
 
179
 
 
180
#endif /* __HVMLOADER_HYPERCALL_H__ */