Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / mm / tmem-xen.c
1 /*
2  * Xen implementation for transcendent memory (tmem)
3  *
4  * Dan Magenheimer <dan.magenheimer@oracle.com> 2009
5  */
6
7 #include <linux/types.h>
8 #include <xen/interface/xen.h>
9 #include <asm/hypervisor.h>
10 #include "tmem.h"
11
12 int xen_tmem_op(u32 tmem_cmd, u32 tmem_pool, struct tmem_oid oid, u32 index,
13         unsigned long gmfn, u32 tmem_offset, u32 pfn_offset, u32 len)
14 {
15         struct tmem_op op;
16         int rc = 0;
17
18         op.cmd = tmem_cmd;
19         op.pool_id = tmem_pool;
20         BUILD_BUG_ON(sizeof(op.u.gen.oid) != sizeof(oid.oid));
21         memcpy(op.u.gen.oid, oid.oid, sizeof(op.u.gen.oid));
22         op.u.gen.index = index;
23         op.u.gen.tmem_offset = tmem_offset;
24         op.u.gen.pfn_offset = pfn_offset;
25         op.u.gen.len = len;
26         op.u.gen.cmfn = gmfn;
27         rc = HYPERVISOR_tmem_op(&op);
28         return rc;
29 }
30
31 int xen_tmem_new_pool(uint32_t tmem_cmd, struct tmem_pool_uuid uuid,
32         uint32_t flags)
33 {
34         struct tmem_op op;
35         int rc = 0;
36
37         op.cmd = tmem_cmd;
38         op.u.creat.uuid[0] = uuid.lo;
39         op.u.creat.uuid[1] = uuid.hi;
40 #ifdef TMEM_SPEC_VERSION
41         switch (flags >> TMEM_POOL_VERSION_SHIFT) {
42         case 0:
43                 flags |= TMEM_SPEC_VERSION << TMEM_POOL_VERSION_SHIFT;
44                 break;
45         case TMEM_SPEC_VERSION:
46                 break;
47         default:
48                 WARN(1, "TMEM: Bogus version %u, expecting %u\n",
49                      flags >> TMEM_POOL_VERSION_SHIFT, TMEM_SPEC_VERSION);
50                 return -ENOSYS;
51         }
52 #endif
53         op.u.creat.flags = flags;
54         rc = HYPERVISOR_tmem_op(&op);
55         return rc;
56 }