aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xcs/xcs.h
blob: 545fc3d05f7d6de100233727bc53a7886e1d7117 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* xcs.h
 *
 * public interfaces for the control interface switch (xcs).
 *
 * (c) 2004, Andrew Warfield
 *
 */


#ifndef __XCS_H__
#define __XCS_H__

#include <pthread.h>
#include <xc.h>
#include <xen/xen.h>
#include <xen/io/domain_controller.h>
#include <xen/linux/privcmd.h>
#include <sys/time.h>
#include "xcs_proto.h"

/* ------[ Debug macros ]--------------------------------------------------*/

#if 0
#define DPRINTF(_f, _a...) printf ( _f , ## _a )
#else
#define DPRINTF(_f, _a...) ((void)0)
#endif

/* ------[ XCS-specific defines and types ]--------------------------------*/

#define MAX_DOMS            1024
#define XCS_SESSION_TIMEOUT   10 /* (secs) disconnected session gc timeout */
#define XCS_UFD_TIMEOUT        5 /* how long can connections be unbound?   */
#define XCS_GC_INTERVAL        5 /* How often to run gc handlers.          */


/* ------[ Other required defines ]----------------------------------------*/

/* Size of a machine page frame. */
#define PAGE_SIZE 4096

#if defined(__i386__)
#define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
#define wmb() __asm__ __volatile__ ( "" : : : "memory" )
#else
#error "Define barriers"
#endif

#ifndef timersub /* XOPEN and __BSD don't cooperate well... */
#define timersub(a, b, result)                                                \
  do {                                                                        \
    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                             \
    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                          \
    if ((result)->tv_usec < 0) {                                              \
      --(result)->tv_sec;                                                     \
      (result)->tv_usec += 1000000;                                           \
    }                                                                         \
  } while (0)
#endif /*timersub*/

/* ------[ Bindings Interface ]--------------------------------------------*/

/*forward declare connection_t */
typedef struct connection_st connection_t;

typedef struct {
    int    port;
    u16    type;
} binding_key_t;

typedef struct binding_key_ent_st {
    binding_key_t              key;
    struct binding_key_ent_st *next;
} binding_key_ent_t;

#define BINDING_KEYS_EQUAL(_k1, _k2) \
    (((_k1)->port == (_k2)->port) && ((_k1)->type == (_k2)->type))

int  xcs_bind(connection_t *con, int port, u16 type);
int  xcs_unbind(connection_t *con, int port, u16 type);
void xcs_lookup(int port, u16 type, void (*f)(connection_t *, void *), 
        void *arg);
void init_bindings(void);

/* ------[ Connection Interface ]------------------------------------------*/

struct connection_st {
    unsigned long      id;              /* Unique session id             */
    int                ctrl_fd;         /* TCP descriptors               */
    int                data_fd;         /*                               */
    binding_key_ent_t *bindings;        /* List of bindings              */
    connection_t      *next;            /* Linked list of connections    */
    struct timeval     disconnect_time; /*  "            "               */
}; /* previously typedefed as connection_t */


extern connection_t *connection_list;

connection_t *get_con_by_session(unsigned long session_id);
connection_t *connection_new();
void connection_free(connection_t *con);
int  connection_add_binding(connection_t *con, binding_key_t *key);
int  connection_remove_binding(connection_t *con, binding_key_t *key);
int  connection_has_binding(connection_t *con, binding_key_t *key);
void gc_connection_list(void);

/* ------[ Control Channel Interfaces ]------------------------------------*/
 
typedef struct {
    int               connected;
    int               ref_count;
    int               type;
    u32               remote_dom;
    int               local_port;
    int               remote_port;
    control_if_t     *interface;
    ctrl_back_ring_t  tx_ring;
    ctrl_front_ring_t rx_ring;
    int               virq;
} control_channel_t;

/* cc types that we care about */
#define CC_TYPE_INTERDOMAIN  0
#define CC_TYPE_VIRQ         1

control_channel_t 
     *ctrl_chan_new(u32 dom, int local_port, int remote_port);
void  ctrl_chan_free(control_channel_t *cc);
int   ctrl_chan_init(void);
int   ctrl_chan_notify(control_channel_t *cc);
int   ctrl_chan_read_request(control_channel_t *cc, xcs_control_msg_t *);
int   ctrl_chan_write_request(control_channel_t *cc, 
                            xcs_control_msg_t *smsg);
int   ctrl_chan_read_response(control_channel_t *cc, xcs_control_msg_t *);
int   ctrl_chan_write_response(control_channel_t *cc, 
                             xcs_control_msg_t *smsg);
int   ctrl_chan_request_to_read(control_channel_t *cc);
int   ctrl_chan_space_to_write_request(control_channel_t *cc);
int   ctrl_chan_response_to_read(control_channel_t *cc);
int   ctrl_chan_space_to_write_response(control_channel_t *cc);
int   ctrl_chan_connect(control_channel_t *cc);
void  ctrl_chan_disconnect(control_channel_t *cc);
int   ctrl_chan_bind_virq(int virq, int *port);

/* ------[ Event notification interfaces ]---------------------------------*/


int   evtchn_open(void);
void  evtchn_close();
int   evtchn_bind(int idx);
int   evtchn_unbind(int idx);
void  evtchn_unmask(u16 idx);
int   evtchn_read();

#endif /* __XCS_H__ */