ia64/xen-unstable

view tools/xcs/xcs.h @ 6427:3428d58a85e1

merge?
author cl349@firebug.cl.cam.ac.uk
date Thu Aug 25 14:41:52 2005 +0000 (2005-08-25)
parents 4abd299ef2f6 6e899a3840b2
children b54144915ae6
line source
1 /* xcs.h
2 *
3 * public interfaces for the control interface switch (xcs).
4 *
5 * (c) 2004, Andrew Warfield
6 *
7 */
10 #ifndef __XCS_H__
11 #define __XCS_H__
13 #include <pthread.h>
14 #include <xenctrl.h>
15 #include <xen/xen.h>
16 #include <xen/io/domain_controller.h>
17 #include <xen/linux/privcmd.h>
18 #include <sys/time.h>
19 #include "xcs_proto.h"
21 /* ------[ Debug macros ]--------------------------------------------------*/
23 #if 0
24 #define DPRINTF(_f, _a...) printf ( _f , ## _a )
25 #else
26 #define DPRINTF(_f, _a...) ((void)0)
27 #endif
29 /* ------[ XCS-specific defines and types ]--------------------------------*/
31 #define MAX_DOMS 1024
32 #define XCS_SESSION_TIMEOUT 10 /* (secs) disconnected session gc timeout */
33 #define XCS_UFD_TIMEOUT 5 /* how long can connections be unbound? */
34 #define XCS_GC_INTERVAL 5 /* How often to run gc handlers. */
37 /* ------[ Other required defines ]----------------------------------------*/
39 /* Size of a machine page frame. */
40 #define PAGE_SIZE XC_PAGE_SIZE
42 #ifndef timersub /* XOPEN and __BSD don't cooperate well... */
43 #define timersub(a, b, result) \
44 do { \
45 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
46 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
47 if ((result)->tv_usec < 0) { \
48 --(result)->tv_sec; \
49 (result)->tv_usec += 1000000; \
50 } \
51 } while (0)
52 #endif /*timersub*/
54 /* ------[ Bindings Interface ]--------------------------------------------*/
56 /*forward declare connection_t */
57 typedef struct connection_st connection_t;
59 typedef struct {
60 int port;
61 u16 type;
62 } binding_key_t;
64 typedef struct binding_key_ent_st {
65 binding_key_t key;
66 struct binding_key_ent_st *next;
67 } binding_key_ent_t;
69 #define BINDING_KEYS_EQUAL(_k1, _k2) \
70 (((_k1)->port == (_k2)->port) && ((_k1)->type == (_k2)->type))
72 int xcs_bind(connection_t *con, int port, u16 type);
73 int xcs_unbind(connection_t *con, int port, u16 type);
74 void xcs_lookup(int port, u16 type, void (*f)(connection_t *, void *),
75 void *arg);
76 void init_bindings(void);
78 /* ------[ Connection Interface ]------------------------------------------*/
80 struct connection_st {
81 unsigned long id; /* Unique session id */
82 int ctrl_fd; /* TCP descriptors */
83 int data_fd; /* */
84 binding_key_ent_t *bindings; /* List of bindings */
85 connection_t *next; /* Linked list of connections */
86 struct timeval disconnect_time; /* " " */
87 }; /* previously typedefed as connection_t */
90 extern connection_t *connection_list;
92 connection_t *get_con_by_session(unsigned long session_id);
93 connection_t *connection_new();
94 void connection_free(connection_t *con);
95 int connection_add_binding(connection_t *con, binding_key_t *key);
96 int connection_remove_binding(connection_t *con, binding_key_t *key);
97 int connection_has_binding(connection_t *con, binding_key_t *key);
98 void gc_connection_list(void);
100 /* ------[ Control Channel Interfaces ]------------------------------------*/
102 typedef struct {
103 int connected;
104 int ref_count;
105 int type;
106 u32 remote_dom;
107 int local_port;
108 int remote_port;
109 control_if_t *interface;
110 ctrl_back_ring_t tx_ring;
111 ctrl_front_ring_t rx_ring;
112 int virq;
113 } control_channel_t;
115 /* cc types that we care about */
116 #define CC_TYPE_INTERDOMAIN 0
117 #define CC_TYPE_VIRQ 1
119 control_channel_t
120 *ctrl_chan_new(u32 dom, int local_port, int remote_port);
121 void ctrl_chan_free(control_channel_t *cc);
122 int ctrl_chan_init(void);
123 int ctrl_chan_notify(control_channel_t *cc);
124 int ctrl_chan_read_request(control_channel_t *cc, xcs_control_msg_t *);
125 int ctrl_chan_write_request(control_channel_t *cc,
126 xcs_control_msg_t *smsg);
127 int ctrl_chan_read_response(control_channel_t *cc, xcs_control_msg_t *);
128 int ctrl_chan_write_response(control_channel_t *cc,
129 xcs_control_msg_t *smsg);
130 int ctrl_chan_request_to_read(control_channel_t *cc);
131 int ctrl_chan_space_to_write_request(control_channel_t *cc);
132 int ctrl_chan_response_to_read(control_channel_t *cc);
133 int ctrl_chan_space_to_write_response(control_channel_t *cc);
134 int ctrl_chan_connect(control_channel_t *cc);
135 void ctrl_chan_disconnect(control_channel_t *cc);
136 int ctrl_chan_bind_virq(int virq, int *port);
138 /* ------[ Event notification interfaces ]---------------------------------*/
141 int evtchn_open(void);
142 void evtchn_close();
143 int evtchn_bind(int idx);
144 int evtchn_unbind(int idx);
145 void evtchn_unmask(u16 idx);
146 int evtchn_read();
148 #endif /* __XCS_H__ */