ia64/xen-unstable

view tools/x2d2/minixend.h @ 3697:0156bb4ae3d7

bitkeeper revision 1.1159.212.112 (4207b382VvZgSA3Pg79SQESssYJbHQ)

More x86_64 fixes.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Mon Feb 07 18:29:22 2005 +0000 (2005-02-07)
parents f5a6b3a8c9b9
children 0a4b76b6b5a0
line source
1 #ifndef MINIXEND_H__
2 #define MINIXEND_H__
4 #include <sys/types.h>
5 #include <xc.h>
7 struct list_head {
8 struct list_head *next, **pprev;
9 };
11 struct open_connection {
12 struct list_head connection_list;
13 int fd;
14 enum {
15 OC_STATE_CONNECTED,
16 OC_STATE_ERROR,
17 OC_STATE_COMMAND_PENDING
18 } state;
20 /* Buffer of stuff coming from the remote until we get a whole
21 command */
22 int buf_used;
23 int buf_allocated;
24 char *buf;
25 };
27 struct console_connection;
29 /* Only ever accessed from the domain's controlling thread, unless
30 it's dom0, in which case we perform a moderately complex dance to
31 avoid needing any sort of locking at all. */
32 struct domain {
33 struct list_head domain_list;
34 int control_evtchn; /* the local port for the doain control
35 interface event channel. */
36 int domid;
37 char *name;
38 int mem_kb;
39 enum {
40 DOM_STATE_CREATED, /* created but not built */
41 DOM_STATE_PAUSED, /* built but not started or paused */
42 DOM_STATE_RUNNING, /* running normally */
43 DOM_STATE_DEAD /* dead; either destroyed, crashed,
44 or exitted. */
45 } state;
47 unsigned long shared_info_mfn;
48 shared_info_t *shared_info;
49 control_if_t *ctrl_if;
50 CONTROL_RING_IDX tx_req_cons;
51 CONTROL_RING_IDX rx_resp_cons;
53 unsigned created_netif_backend:1;
54 unsigned plugged:1;
55 unsigned event_pending:1; /* True if an event arrived while
56 the domain was plugged. */
58 struct console_connection *cc;
60 char netif_mac[6];
62 /* Used for two purposes: waking up domain threads when
63 necessary, and synchronising access to dom0, which doesn't
64 have a domain thread. */
65 pthread_mutex_t mux;
66 pthread_cond_t cond;
68 pthread_t thread;
69 };
71 struct console_connection {
72 struct list_head list;
73 int fd;
74 struct domain *dom;
76 enum {
77 CC_STATE_PENDING,
78 CC_STATE_CONNECTED,
79 CC_STATE_ERROR
80 } state;
82 unsigned buf_allocated;
83 unsigned buf_used;
84 char *buf;
86 unsigned in_buf_allocated;
87 unsigned in_buf_used;
88 char *in_buf;
89 };
92 void *domain_thread_func(void *d);
93 void process_command(struct open_connection *oc);
95 void *xmalloc(size_t s);
96 void *xrealloc(void *x, size_t s);
97 char *xstrdup(const char *s);
99 int allocate_event_channel(struct domain *d, int event_ports[2]);
100 void *map_domain_mem(struct domain *d, unsigned long mfn);
101 void signal_domain(struct domain *d);
102 int our_system(const char *fmt, ...);
104 extern unsigned xc_handle;
105 #define EVTCHN_BIND _IO('E', 2)
106 extern int evtchn_fd;
108 #define list_item(head, type, field) \
109 ((type *)((unsigned)(head) - offsetof(type, field)))
111 #define foreach_item(iter, head, type, field) \
112 for ((iter) = list_item((head)->next, type, field); \
113 (iter) != list_item((head), type, field); \
114 (iter) = list_item((iter)->field.next, type, field))
116 #define list_insert_after(what, head) \
117 do { \
118 (what)->next = (head)->next; \
119 (what)->pprev = &(head)->next; \
120 (head)->next->pprev = &(what)->next; \
121 (head)->next = what; \
122 } while (0)
124 #define list_remove(head) \
125 (head)->next->pprev = (head)->pprev; \
126 *(head)->pprev = (head)->next;
128 #define list_foreach_safe(head, li, temp) \
129 for ((li) = (head)->next, (temp) = (li)->next; \
130 (li) != (head); \
131 (li) = (temp), (temp) = (li)->next)
133 #define LIST_HEAD(x) { (x), &(x)->next }
136 extern struct list_head head_domain;
137 extern struct list_head head_console;
139 #define foreach_domain(d) \
140 foreach_item(d, &head_domain, struct domain, domain_list)
141 #define foreach_console_connection(cc) \
142 foreach_item(cc, &head_console, struct console_connection, list)
145 #define CURRENT_LOG_LEVEL 0
147 #define PRINTF(level, ...) \
148 do { \
149 if ((level) >= CURRENT_LOG_LEVEL) \
150 printf(__VA_ARGS__); \
151 } while (0)
154 #endif /* MINIXEND_H__ */