1 #ifndef XENCALL_PRIVATE_H
2 #define XENCALL_PRIVATE_H
3 
4 #include <xentoollog.h>
5 #include <xentoolcore_internal.h>
6 
7 #include <xencall.h>
8 
9 #include <xen/xen.h>
10 #include <xen/sys/privcmd.h>
11 
12 #ifndef PAGE_SHIFT /* Mini-os, Yukk */
13 #define PAGE_SHIFT           12
14 #endif
15 #ifndef __MINIOS__ /* Yukk */
16 #define PAGE_SIZE            (1UL << PAGE_SHIFT)
17 #define PAGE_MASK            (~(PAGE_SIZE-1))
18 #endif
19 
20 struct xencall_handle {
21     xentoollog_logger *logger, *logger_tofree;
22     unsigned flags;
23 
24                      /* partially     with /dev/     no /dev/      */
25                      /* initialised   xen/hypercall  xen/hypercall */
26     int fd;          /*    any           >= 0           >= 0       */
27     int buf_fd;      /*    any           >= 0           -1         */
28 
29     Xentoolcore__Active_Handle tc_ah;
30 
31     /*
32      * A simple cache of unused, single page, hypercall buffers
33      *
34      * Protected by a global lock.
35      */
36 #define BUFFER_CACHE_SIZE 4
37     int buffer_cache_nr;
38     void *buffer_cache[BUFFER_CACHE_SIZE];
39 
40     /*
41      * Hypercall buffer statistics. All protected by the global
42      * buffer_cache lock.
43      */
44     int buffer_total_allocations;
45     int buffer_total_releases;
46     int buffer_current_allocations;
47     int buffer_maximum_allocations;
48     int buffer_cache_hits;
49     int buffer_cache_misses;
50     int buffer_cache_toobig;
51 };
52 
53 int osdep_xencall_open(xencall_handle *xcall);
54 int osdep_xencall_close(xencall_handle *xcall);
55 
56 int osdep_hypercall(xencall_handle *xcall, privcmd_hypercall_t *hypercall);
57 
58 void *osdep_alloc_pages(xencall_handle *xcall, size_t nr_pages);
59 void osdep_free_pages(xencall_handle *xcall, void *p, size_t nr_pages);
60 
61 void buffer_release_cache(xencall_handle *xcall);
62 
63 #define PERROR(_f...) xtl_log(xcall->logger, XTL_ERROR, errno, "xencall", _f)
64 
65 #endif
66 
67 /*
68  * Local variables:
69  * mode: C
70  * c-file-style: "BSD"
71  * c-basic-offset: 4
72  * tab-width: 4
73  * indent-tabs-mode: nil
74  * End:
75  */
76