diff options
author | cwc22@centipede.cl.cam.ac.uk <cwc22@centipede.cl.cam.ac.uk> | 2005-03-04 02:00:12 +0000 |
---|---|---|
committer | cwc22@centipede.cl.cam.ac.uk <cwc22@centipede.cl.cam.ac.uk> | 2005-03-04 02:00:12 +0000 |
commit | cbb632d45510548238843411031df19b119e278a (patch) | |
tree | 9796088614e5eb7665d83e2bba3f534fc358ea46 /tools/libxc/xc_gnttab.c | |
parent | 6a329a59de41a0b47b42d4db57b7ed9ec14811e5 (diff) | |
download | xen-cbb632d45510548238843411031df19b119e278a.tar.gz xen-cbb632d45510548238843411031df19b119e278a.tar.bz2 xen-cbb632d45510548238843411031df19b119e278a.zip |
bitkeeper revision 1.1236.9.1 (4227c12cJQxFhBUYk0ojkmnooUw0jQ)
Grant tables work on data structures.
Diffstat (limited to 'tools/libxc/xc_gnttab.c')
-rw-r--r-- | tools/libxc/xc_gnttab.c | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/tools/libxc/xc_gnttab.c b/tools/libxc/xc_gnttab.c new file mode 100644 index 0000000000..2601c30f60 --- /dev/null +++ b/tools/libxc/xc_gnttab.c @@ -0,0 +1,143 @@ +/****************************************************************************** + * xc_gnttab.c + * + * API for manipulating and accessing grant tables + * + * Copyright (c) 2005 Christopher Clark + * based on xc_evtchn.c Copyright (c) 2004, K A Fraser. + */ + +#include "xc_private.h" +#include "xen/grant_table.h" + +static int +do_gnttab_op( int xc_handle, + unsigned long cmd, + gnttab_op_t *op, + unsigned long count ) +{ + int ret = -1; + privcmd_hypercall_t hypercall; + + hypercall.op = __HYPERVISOR_grant_table_op; + hypercall.arg[0] = cmd; + hypercall.arg[1] = (unsigned long)(op); + hypercall.arg[2] = count; + + if ( mlock(op, sizeof(*op)) != 0 ) + { + PERROR("Could not lock memory for Xen hypercall"); + goto out1; + } + + if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 ) + { + printf("do_gnttab_op: hypercall returned error %d\n", ret); + goto out2; + } + + out2: (void)munlock(op, sizeof(*op)); + out1: return ret; +} + + +int xc_gnttab_map_grant_ref(int xc_handle, + memory_t host_virt_addr, + u32 dom, + u16 ref, + u16 flags, + s16 *handle, + memory_t *dev_bus_addr) +{ + gnttab_op_t op; + int rc; + + op.u.map_grant_ref.host_virt_addr = host_virt_addr; + op.u.map_grant_ref.dom = (domid_t)dom; + op.u.map_grant_ref.ref = ref; + op.u.map_grant_ref.flags = flags; + + if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref, &op, 1)) == 0 ) + { + *handle = op.u.map_grant_ref.handle; + *dev_bus_addr = op.u.map_grant_ref.dev_bus_addr; + } + + return rc; +} + + +int xc_gnttab_unmap_grant_ref(int xc_handle, + memory_t host_virt_addr, + memory_t dev_bus_addr, + u16 handle, + s16 *status) +{ + gnttab_op_t op; + int rc; + + op.u.unmap_grant_ref.host_virt_addr = host_virt_addr; + op.u.unmap_grant_ref.dev_bus_addr = dev_bus_addr; + op.u.unmap_grant_ref.handle = handle; + + if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_unmap_grant_ref, &op, 1)) == 0 ) + *status = op.u.unmap_grant_ref.status; + + return rc; +} + +int xc_gnttab_setup_table(int xc_handle, + u32 dom, + u16 nr_frames, + s16 *status, + memory_t **frame_list) +{ + gnttab_op_t op; + int rc; + int i; + + op.u.setup_table.dom = (domid_t)dom; + op.u.setup_table.nr_frames = nr_frames; + + if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_setup_table, &op, 1)) == 0 ) + { + *status = op.u.setup_table.status; + for ( i = 0; i < nr_frames; i++ ) + { + (*frame_list)[i] = op.u.setup_table.frame_list[i]; + } + } + + return rc; +} + +int xc_gnttab_dump_table(int xc_handle, + u32 dom, + s16 *status) +{ + gnttab_op_t op; + int rc; + + op.u.dump_table.dom = (domid_t)dom; + + printf("xc_gnttab_dump_table: domain %d\n", dom); + + if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_dump_table, &op, 1)) == 0 ) + *status = op.u.dump_table.status; + + return rc; +} + +int xc_grant_interface_open(void) +{ + int fd = open("/proc/xen/grant", O_RDWR); + if ( fd == -1 ) + PERROR("Could not obtain handle on grant command interface"); + return fd; + +} + +int xc_grant_interface_close(int xc_grant_handle) +{ + return close(xc_grant_handle); +} |