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