Line data Source code
1 : /* $OpenBSD: xenvar.h,v 1.51 2017/07/21 20:00:47 mikeb Exp $ */
2 :
3 : /*
4 : * Copyright (c) 2015 Mike Belopuhov
5 : *
6 : * Permission to use, copy, modify, and distribute this software for any
7 : * purpose with or without fee is hereby granted, provided that the above
8 : * copyright notice and this permission notice appear in all copies.
9 : *
10 : * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 : * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 : * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 : * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 : * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 : * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 : * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 : */
18 :
19 : #ifndef _DEV_PV_XENVAR_H_
20 : #define _DEV_PV_XENVAR_H_
21 :
22 : static inline void
23 0 : clear_bit(u_int b, volatile void *p)
24 : {
25 0 : atomic_clearbits_int(((volatile u_int *)p) + (b >> 5), 1 << (b & 0x1f));
26 0 : }
27 :
28 : static inline void
29 0 : set_bit(u_int b, volatile void *p)
30 : {
31 0 : atomic_setbits_int(((volatile u_int *)p) + (b >> 5), 1 << (b & 0x1f));
32 0 : }
33 :
34 : static inline int
35 0 : test_bit(u_int b, volatile void *p)
36 : {
37 0 : return !!(((volatile u_int *)p)[b >> 5] & (1 << (b & 0x1f)));
38 : }
39 :
40 : #define XEN_MAX_NODE_LEN 64
41 : #define XEN_MAX_BACKEND_LEN 128
42 :
43 : struct xen_intsrc {
44 : SLIST_ENTRY(xen_intsrc) xi_entry;
45 : struct evcount xi_evcnt;
46 : evtchn_port_t xi_port;
47 : short xi_noclose;
48 : short xi_masked;
49 : struct refcnt xi_refcnt;
50 : struct task xi_task;
51 : struct taskq *xi_taskq;
52 : void (*xi_handler)(void *);
53 : void *xi_ctx;
54 : };
55 :
56 : struct xen_gntent {
57 : grant_entry_t *ge_table;
58 : grant_ref_t ge_start;
59 : short ge_reserved;
60 : short ge_next;
61 : short ge_free;
62 : struct mutex ge_lock;
63 : };
64 :
65 : struct xen_gntmap {
66 : grant_ref_t gm_ref;
67 : paddr_t gm_paddr;
68 : };
69 :
70 : struct xen_device {
71 : struct device *dv_dev;
72 : char dv_unit[16];
73 : LIST_ENTRY(xen_device) dv_entry;
74 : };
75 : LIST_HEAD(xen_devices, xen_device);
76 :
77 : struct xen_devlist {
78 : struct xen_softc *dl_xen;
79 : char dl_node[XEN_MAX_NODE_LEN];
80 : struct task dl_task;
81 : struct xen_devices dl_devs;
82 : SLIST_ENTRY(xen_devlist) dl_entry;
83 : };
84 : SLIST_HEAD(xen_devlists, xen_devlist);
85 :
86 : struct xen_softc {
87 : struct device sc_dev;
88 : uint32_t sc_base;
89 : void *sc_hc;
90 : uint32_t sc_features;
91 : #define XENFEAT_CBVEC (1<<8)
92 :
93 : bus_dma_tag_t sc_dmat; /* parent dma tag */
94 :
95 : struct shared_info *sc_ipg; /* HYPERVISOR_shared_info */
96 :
97 : uint32_t sc_flags;
98 : #define XSF_CBVEC 0x0001
99 :
100 : uint32_t sc_unplug;
101 :
102 : uint64_t sc_irq; /* IDT vector number */
103 : SLIST_HEAD(, xen_intsrc) sc_intrs;
104 : struct mutex sc_islck;
105 :
106 : struct xen_gntent *sc_gnt; /* grant table entries */
107 : struct mutex sc_gntlck;
108 : int sc_gntcnt; /* number of allocated frames */
109 : int sc_gntmax; /* number of allotted frames */
110 :
111 : /*
112 : * Xenstore
113 : */
114 : struct xs_softc *sc_xs; /* xenstore softc */
115 : struct task sc_ctltsk; /* control task */
116 : struct xen_devlists sc_devlists; /* device lists heads */
117 : };
118 :
119 : extern struct xen_softc *xen_sc;
120 :
121 : struct xen_attach_args {
122 : char xa_name[16];
123 : char xa_node[XEN_MAX_NODE_LEN];
124 : char xa_backend[XEN_MAX_BACKEND_LEN];
125 : int xa_domid;
126 : bus_dma_tag_t xa_dmat;
127 : };
128 :
129 : /*
130 : * Hypercalls
131 : */
132 : #define XC_MEMORY 12
133 : #define XC_OEVTCHN 16
134 : #define XC_VERSION 17
135 : #define XC_GNTTAB 20
136 : #define XC_EVTCHN 32
137 : #define XC_HVM 34
138 :
139 : int xen_hypercall(struct xen_softc *, int, int, ...);
140 : int xen_hypercallv(struct xen_softc *, int, int, ulong *);
141 :
142 : /*
143 : * Interrupts
144 : */
145 : typedef uint32_t xen_intr_handle_t;
146 :
147 : void xen_intr(void);
148 : void xen_intr_ack(void);
149 : void xen_intr_signal(xen_intr_handle_t);
150 : void xen_intr_schedule(xen_intr_handle_t);
151 : void xen_intr_barrier(xen_intr_handle_t);
152 : int xen_intr_establish(evtchn_port_t, xen_intr_handle_t *, int,
153 : void (*)(void *), void *, char *);
154 : int xen_intr_disestablish(xen_intr_handle_t);
155 : void xen_intr_enable(void);
156 : void xen_intr_mask(xen_intr_handle_t);
157 : int xen_intr_unmask(xen_intr_handle_t);
158 :
159 : /*
160 : * Miscellaneous
161 : */
162 : #define XEN_UNPLUG_NIC 0x0001 /* disable emul. NICs */
163 : #define XEN_UNPLUG_IDE 0x0002 /* disable emul. primary IDE */
164 : #define XEN_UNPLUG_IDESEC 0x0004 /* disable emul. secondary IDE */
165 :
166 : void xen_unplug_emulated(void *, int);
167 :
168 : /*
169 : * XenStore
170 : */
171 : #define XS_LIST 0x01
172 : #define XS_READ 0x02
173 : #define XS_WATCH 0x04
174 : #define XS_TOPEN 0x06
175 : #define XS_TCLOSE 0x07
176 : #define XS_WRITE 0x0b
177 : #define XS_RM 0x0d
178 : #define XS_EVENT 0x0f
179 : #define XS_ERROR 0x10
180 : #define XS_MAX 0x16
181 :
182 : struct xs_transaction {
183 : uint32_t xst_id;
184 : void *xst_cookie;
185 : };
186 :
187 : int xs_cmd(struct xs_transaction *, int, const char *, struct iovec **,
188 : int *);
189 : void xs_resfree(struct xs_transaction *, struct iovec *, int);
190 : int xs_watch(void *, const char *, const char *, struct task *,
191 : void (*)(void *), void *);
192 : int xs_getnum(void *, const char *, const char *, unsigned long long *);
193 : int xs_setnum(void *, const char *, const char *, unsigned long long);
194 : int xs_getprop(void *, const char *, const char *, char *, int);
195 : int xs_setprop(void *, const char *, const char *, char *, int);
196 : int xs_kvop(void *, int, char *, char *, size_t);
197 :
198 : #define XEN_STATE_UNKNOWN "0"
199 : #define XEN_STATE_INITIALIZING "1"
200 : #define XEN_STATE_INITWAIT "2"
201 : #define XEN_STATE_INITIALIZED "3"
202 : #define XEN_STATE_CONNECTED "4"
203 : #define XEN_STATE_CLOSING "5"
204 : #define XEN_STATE_CLOSED "6"
205 : #define XEN_STATE_RECONFIGURING "7"
206 : #define XEN_STATE_RECONFIGURED "8"
207 :
208 : int xs_await_transition(void *, const char *, const char *,
209 : const char *, int);
210 :
211 : #endif /* _DEV_PV_XENVAR_H_ */
|