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

« back to all changes in this revision

Viewing changes to tools/libxc/xc_memshr.c

  • 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
 *
 
3
 * xc_memshr.c
 
4
 *
 
5
 * Interface to low-level memory sharing functionality.
 
6
 *
 
7
 * Copyright (c) 2009 Citrix Systems, Inc. (Grzegorz Milos)
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; either version 2 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
 */
 
23
 
 
24
#include "xc_private.h"
 
25
#include <xen/memory.h>
 
26
#include <xen/grant_table.h>
 
27
 
 
28
int xc_memshr_control(int xc_handle,
 
29
                      uint32_t domid,
 
30
                      int enable)
 
31
{
 
32
    DECLARE_DOMCTL;
 
33
    struct xen_domctl_mem_sharing_op *op;
 
34
 
 
35
    domctl.cmd = XEN_DOMCTL_mem_sharing_op;
 
36
    domctl.interface_version = XEN_DOMCTL_INTERFACE_VERSION;
 
37
    domctl.domain = (domid_t)domid;
 
38
    op = &(domctl.u.mem_sharing_op);
 
39
    op->op = XEN_DOMCTL_MEM_SHARING_OP_CONTROL;
 
40
    op->u.enable = enable;
 
41
 
 
42
    return do_domctl(xc_handle, &domctl);
 
43
}
 
44
 
 
45
int xc_memshr_nominate_gfn(int xc_handle,
 
46
                           uint32_t domid,
 
47
                           unsigned long gfn,
 
48
                           uint64_t *handle)
 
49
{
 
50
    DECLARE_DOMCTL;
 
51
    struct xen_domctl_mem_sharing_op *op;
 
52
    int ret;
 
53
 
 
54
    domctl.cmd = XEN_DOMCTL_mem_sharing_op;
 
55
    domctl.interface_version = XEN_DOMCTL_INTERFACE_VERSION;
 
56
    domctl.domain = (domid_t)domid;
 
57
    op = &(domctl.u.mem_sharing_op);
 
58
    op->op = XEN_DOMCTL_MEM_SHARING_OP_NOMINATE_GFN;
 
59
    op->u.nominate.u.gfn = gfn;
 
60
 
 
61
    ret = do_domctl(xc_handle, &domctl);
 
62
    if(!ret) *handle = op->u.nominate.handle; 
 
63
 
 
64
    return ret;
 
65
}
 
66
 
 
67
int xc_memshr_nominate_gref(int xc_handle,
 
68
                            uint32_t domid,
 
69
                            grant_ref_t gref,
 
70
                            uint64_t *handle)
 
71
{
 
72
    DECLARE_DOMCTL;
 
73
    struct xen_domctl_mem_sharing_op *op;
 
74
    int ret;
 
75
 
 
76
    domctl.cmd = XEN_DOMCTL_mem_sharing_op;
 
77
    domctl.interface_version = XEN_DOMCTL_INTERFACE_VERSION;
 
78
    domctl.domain = (domid_t)domid;
 
79
    op = &(domctl.u.mem_sharing_op);
 
80
    op->op = XEN_DOMCTL_MEM_SHARING_OP_NOMINATE_GREF;
 
81
    op->u.nominate.u.grant_ref = gref;
 
82
 
 
83
    ret = do_domctl(xc_handle, &domctl);
 
84
    if(!ret) *handle = op->u.nominate.handle; 
 
85
 
 
86
    return ret;
 
87
}
 
88
 
 
89
int xc_memshr_share(int xc_handle,
 
90
                    uint64_t source_handle,
 
91
                    uint64_t client_handle)
 
92
{
 
93
    DECLARE_DOMCTL;
 
94
    struct xen_domctl_mem_sharing_op *op;
 
95
 
 
96
    domctl.cmd = XEN_DOMCTL_mem_sharing_op;
 
97
    domctl.interface_version = XEN_DOMCTL_INTERFACE_VERSION;
 
98
    domctl.domain = 0;
 
99
    op = &(domctl.u.mem_sharing_op);
 
100
    op->op = XEN_DOMCTL_MEM_SHARING_OP_SHARE;
 
101
    op->u.share.source_handle = source_handle;
 
102
    op->u.share.client_handle = client_handle;
 
103
 
 
104
    return do_domctl(xc_handle, &domctl);
 
105
}
 
106
 
 
107
int xc_memshr_domain_resume(int xc_handle,
 
108
                            uint32_t domid)
 
109
{
 
110
    DECLARE_DOMCTL;
 
111
    struct xen_domctl_mem_sharing_op *op;
 
112
 
 
113
    domctl.cmd = XEN_DOMCTL_mem_sharing_op;
 
114
    domctl.interface_version = XEN_DOMCTL_INTERFACE_VERSION;
 
115
    domctl.domain = (domid_t)domid;
 
116
    op = &(domctl.u.mem_sharing_op);
 
117
    op->op = XEN_DOMCTL_MEM_SHARING_OP_RESUME;
 
118
 
 
119
    return do_domctl(xc_handle, &domctl);
 
120
}
 
121
 
 
122
int xc_memshr_debug_gfn(int xc_handle,
 
123
                        uint32_t domid,
 
124
                        unsigned long gfn)
 
125
{
 
126
    DECLARE_DOMCTL;
 
127
    struct xen_domctl_mem_sharing_op *op;
 
128
 
 
129
    domctl.cmd = XEN_DOMCTL_mem_sharing_op;
 
130
    domctl.interface_version = XEN_DOMCTL_INTERFACE_VERSION;
 
131
    domctl.domain = (domid_t)domid;
 
132
    op = &(domctl.u.mem_sharing_op);
 
133
    op->op = XEN_DOMCTL_MEM_SHARING_OP_DEBUG_GFN;
 
134
    op->u.debug.u.gfn = gfn;
 
135
 
 
136
    return do_domctl(xc_handle, &domctl);
 
137
}
 
138
 
 
139
int xc_memshr_debug_mfn(int xc_handle,
 
140
                        uint32_t domid,
 
141
                        unsigned long mfn)
 
142
{
 
143
    DECLARE_DOMCTL;
 
144
    struct xen_domctl_mem_sharing_op *op;
 
145
 
 
146
    domctl.cmd = XEN_DOMCTL_mem_sharing_op;
 
147
    domctl.interface_version = XEN_DOMCTL_INTERFACE_VERSION;
 
148
    domctl.domain = (domid_t)domid;
 
149
    op = &(domctl.u.mem_sharing_op);
 
150
    op->op = XEN_DOMCTL_MEM_SHARING_OP_DEBUG_MFN;
 
151
    op->u.debug.u.mfn = mfn;
 
152
 
 
153
    return do_domctl(xc_handle, &domctl);
 
154
}
 
155
 
 
156
int xc_memshr_debug_gref(int xc_handle,
 
157
                         uint32_t domid,
 
158
                         grant_ref_t gref)
 
159
{
 
160
    DECLARE_DOMCTL;
 
161
    struct xen_domctl_mem_sharing_op *op;
 
162
 
 
163
    domctl.cmd = XEN_DOMCTL_mem_sharing_op;
 
164
    domctl.interface_version = XEN_DOMCTL_INTERFACE_VERSION;
 
165
    domctl.domain = (domid_t)domid;
 
166
    op = &(domctl.u.mem_sharing_op);
 
167
    op->op = XEN_DOMCTL_MEM_SHARING_OP_DEBUG_GREF;
 
168
    op->u.debug.u.gref = gref;
 
169
 
 
170
    return do_domctl(xc_handle, &domctl);
 
171
}
 
172