Lines Matching refs:hvt

28 static void hvt_reset(struct hvutil_transport *hvt)  in hvt_reset()  argument
30 mutex_lock(&hvt->outmsg_lock); in hvt_reset()
31 kfree(hvt->outmsg); in hvt_reset()
32 hvt->outmsg = NULL; in hvt_reset()
33 hvt->outmsg_len = 0; in hvt_reset()
34 mutex_unlock(&hvt->outmsg_lock); in hvt_reset()
35 if (hvt->on_reset) in hvt_reset()
36 hvt->on_reset(); in hvt_reset()
42 struct hvutil_transport *hvt; in hvt_op_read() local
45 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_read()
47 if (wait_event_interruptible(hvt->outmsg_q, hvt->outmsg_len > 0)) in hvt_op_read()
50 mutex_lock(&hvt->outmsg_lock); in hvt_op_read()
51 if (!hvt->outmsg) { in hvt_op_read()
56 if (count < hvt->outmsg_len) { in hvt_op_read()
61 if (!copy_to_user(buf, hvt->outmsg, hvt->outmsg_len)) in hvt_op_read()
62 ret = hvt->outmsg_len; in hvt_op_read()
66 kfree(hvt->outmsg); in hvt_op_read()
67 hvt->outmsg = NULL; in hvt_op_read()
68 hvt->outmsg_len = 0; in hvt_op_read()
71 mutex_unlock(&hvt->outmsg_lock); in hvt_op_read()
78 struct hvutil_transport *hvt; in hvt_op_write() local
81 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_write()
88 if (hvt->on_msg(inmsg, count)) in hvt_op_write()
97 struct hvutil_transport *hvt; in hvt_op_poll() local
99 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_poll()
101 poll_wait(file, &hvt->outmsg_q, wait); in hvt_op_poll()
102 if (hvt->outmsg_len > 0) in hvt_op_poll()
110 struct hvutil_transport *hvt; in hvt_op_open() local
112 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_open()
118 if (hvt->mode == HVUTIL_TRANSPORT_INIT) in hvt_op_open()
119 hvt->mode = HVUTIL_TRANSPORT_CHARDEV; in hvt_op_open()
120 else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) { in hvt_op_open()
125 hvt_reset(hvt); in hvt_op_open()
126 hvt->mode = HVUTIL_TRANSPORT_CHARDEV; in hvt_op_open()
135 struct hvutil_transport *hvt; in hvt_op_release() local
137 hvt = container_of(file->f_op, struct hvutil_transport, fops); in hvt_op_release()
139 hvt->mode = HVUTIL_TRANSPORT_INIT; in hvt_op_release()
144 hvt_reset(hvt); in hvt_op_release()
151 struct hvutil_transport *hvt, *hvt_found = NULL; in hvt_cn_callback() local
154 list_for_each_entry(hvt, &hvt_list, list) { in hvt_cn_callback()
155 if (hvt->cn_id.idx == msg->id.idx && in hvt_cn_callback()
156 hvt->cn_id.val == msg->id.val) { in hvt_cn_callback()
157 hvt_found = hvt; in hvt_cn_callback()
171 if (hvt->mode == HVUTIL_TRANSPORT_INIT) in hvt_cn_callback()
172 hvt->mode = HVUTIL_TRANSPORT_NETLINK; in hvt_cn_callback()
174 if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) in hvt_cn_callback()
180 int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len) in hvutil_transport_send() argument
185 if (hvt->mode == HVUTIL_TRANSPORT_INIT) { in hvutil_transport_send()
187 } else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) { in hvutil_transport_send()
191 cn_msg->id.idx = hvt->cn_id.idx; in hvutil_transport_send()
192 cn_msg->id.val = hvt->cn_id.val; in hvutil_transport_send()
200 mutex_lock(&hvt->outmsg_lock); in hvutil_transport_send()
201 if (hvt->outmsg) { in hvutil_transport_send()
206 hvt->outmsg = kzalloc(len, GFP_KERNEL); in hvutil_transport_send()
207 memcpy(hvt->outmsg, msg, len); in hvutil_transport_send()
208 hvt->outmsg_len = len; in hvutil_transport_send()
209 wake_up_interruptible(&hvt->outmsg_q); in hvutil_transport_send()
211 mutex_unlock(&hvt->outmsg_lock); in hvutil_transport_send()
220 struct hvutil_transport *hvt; in hvutil_transport_init() local
222 hvt = kzalloc(sizeof(*hvt), GFP_KERNEL); in hvutil_transport_init()
223 if (!hvt) in hvutil_transport_init()
226 hvt->cn_id.idx = cn_idx; in hvutil_transport_init()
227 hvt->cn_id.val = cn_val; in hvutil_transport_init()
229 hvt->mdev.minor = MISC_DYNAMIC_MINOR; in hvutil_transport_init()
230 hvt->mdev.name = name; in hvutil_transport_init()
232 hvt->fops.owner = THIS_MODULE; in hvutil_transport_init()
233 hvt->fops.read = hvt_op_read; in hvutil_transport_init()
234 hvt->fops.write = hvt_op_write; in hvutil_transport_init()
235 hvt->fops.poll = hvt_op_poll; in hvutil_transport_init()
236 hvt->fops.open = hvt_op_open; in hvutil_transport_init()
237 hvt->fops.release = hvt_op_release; in hvutil_transport_init()
239 hvt->mdev.fops = &hvt->fops; in hvutil_transport_init()
241 init_waitqueue_head(&hvt->outmsg_q); in hvutil_transport_init()
242 mutex_init(&hvt->outmsg_lock); in hvutil_transport_init()
245 list_add(&hvt->list, &hvt_list); in hvutil_transport_init()
248 hvt->on_msg = on_msg; in hvutil_transport_init()
249 hvt->on_reset = on_reset; in hvutil_transport_init()
251 if (misc_register(&hvt->mdev)) in hvutil_transport_init()
255 if (hvt->cn_id.idx > 0 && hvt->cn_id.val > 0 && in hvutil_transport_init()
256 cn_add_callback(&hvt->cn_id, name, hvt_cn_callback)) in hvutil_transport_init()
259 return hvt; in hvutil_transport_init()
262 kfree(hvt); in hvutil_transport_init()
266 void hvutil_transport_destroy(struct hvutil_transport *hvt) in hvutil_transport_destroy() argument
269 list_del(&hvt->list); in hvutil_transport_destroy()
271 if (hvt->cn_id.idx > 0 && hvt->cn_id.val > 0) in hvutil_transport_destroy()
272 cn_del_callback(&hvt->cn_id); in hvutil_transport_destroy()
273 misc_deregister(&hvt->mdev); in hvutil_transport_destroy()
274 kfree(hvt->outmsg); in hvutil_transport_destroy()
275 kfree(hvt); in hvutil_transport_destroy()