2 * VMware VMCI driver (vmciContext.h)
4 * Copyright (C) 2012 VMware, Inc. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 and no later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #ifndef _VMCI_CONTEXT_H_
17 #define _VMCI_CONTEXT_H_
19 #include <linux/vmw_vmci_defs.h>
20 #include <linux/atomic.h>
21 #include <linux/kref.h>
22 #include <linux/types.h>
23 #include <linux/wait.h>
25 #include "vmci_handle_array.h"
26 #include "vmci_datagram.h"
28 /* Used to determine what checkpoint state to get and set. */
30 VMCI_NOTIFICATION_CPT_STATE = 1,
31 VMCI_WELLKNOWN_CPT_STATE = 2,
32 VMCI_DG_OUT_STATE = 3,
34 VMCI_DG_IN_SIZE_STATE = 5,
35 VMCI_DOORBELL_CPT_STATE = 6,
38 /* Host specific struct used for signalling */
40 wait_queue_head_t wait_queue;
43 struct vmci_handle_list {
44 struct list_head node;
45 struct vmci_handle handle;
49 struct list_head list_item; /* For global VMCI list. */
52 struct list_head datagram_queue; /* Head of per VM queue. */
53 u32 pending_datagrams;
54 size_t datagram_queue_size; /* Size of datagram queue in bytes. */
57 * Version of the code that created
58 * this context; e.g., VMX.
61 spinlock_t lock; /* Locks callQueue and handle_arrays. */
64 * queue_pairs attached to. The array of
65 * handles for queue pairs is accessed
66 * from the code for QP API, and there
67 * it is protected by the QP lock. It
68 * is also accessed from the context
69 * clean up path, which does not
70 * require a lock. VMCILock is not
71 * used to protect the QP array field.
73 struct vmci_handle_arr *queue_pair_array;
75 /* Doorbells created by context. */
76 struct vmci_handle_arr *doorbell_array;
78 /* Doorbells pending for context. */
79 struct vmci_handle_arr *pending_doorbell_array;
81 /* Contexts current context is subscribing to. */
82 struct list_head notifier_list;
83 unsigned int n_notifiers;
85 struct vmci_host host_context;
88 const struct cred *cred;
89 bool *notify; /* Notify flag pointer - hosted only. */
90 struct page *notify_page; /* Page backing the notify UVA. */
93 /* VMCINotifyAddRemoveInfo: Used to add/remove remote context notifications. */
94 struct vmci_ctx_info {
99 /* VMCICptBufInfo: Used to set/get current context's checkpoint state. */
100 struct vmci_ctx_chkpt_buf_info {
109 * VMCINotificationReceiveInfo: Used to recieve pending notifications
110 * for doorbells and queue pairs.
112 struct vmci_ctx_notify_recv_info {
113 u64 db_handle_buf_uva;
114 u64 db_handle_buf_size;
115 u64 qp_handle_buf_uva;
116 u64 qp_handle_buf_size;
122 * Utilility function that checks whether two entities are allowed
123 * to interact. If one of them is restricted, the other one must
126 static inline bool vmci_deny_interaction(u32 part_one, u32 part_two)
128 return ((part_one & VMCI_PRIVILEGE_FLAG_RESTRICTED) &&
129 !(part_two & VMCI_PRIVILEGE_FLAG_TRUSTED)) ||
130 ((part_two & VMCI_PRIVILEGE_FLAG_RESTRICTED) &&
131 !(part_one & VMCI_PRIVILEGE_FLAG_TRUSTED));
134 struct vmci_ctx *vmci_ctx_create(u32 cid, u32 flags,
135 uintptr_t event_hnd, int version,
136 const struct cred *cred);
137 void vmci_ctx_destroy(struct vmci_ctx *context);
139 bool vmci_ctx_supports_host_qp(struct vmci_ctx *context);
140 int vmci_ctx_enqueue_datagram(u32 cid, struct vmci_datagram *dg);
141 int vmci_ctx_dequeue_datagram(struct vmci_ctx *context,
142 size_t *max_size, struct vmci_datagram **dg);
143 int vmci_ctx_pending_datagrams(u32 cid, u32 *pending);
144 struct vmci_ctx *vmci_ctx_get(u32 cid);
145 void vmci_ctx_put(struct vmci_ctx *context);
146 bool vmci_ctx_exists(u32 cid);
148 int vmci_ctx_add_notification(u32 context_id, u32 remote_cid);
149 int vmci_ctx_remove_notification(u32 context_id, u32 remote_cid);
150 int vmci_ctx_get_chkpt_state(u32 context_id, u32 cpt_type,
151 u32 *num_cids, void **cpt_buf_ptr);
152 int vmci_ctx_set_chkpt_state(u32 context_id, u32 cpt_type,
153 u32 num_cids, void *cpt_buf);
155 int vmci_ctx_qp_create(struct vmci_ctx *context, struct vmci_handle handle);
156 int vmci_ctx_qp_destroy(struct vmci_ctx *context, struct vmci_handle handle);
157 bool vmci_ctx_qp_exists(struct vmci_ctx *context, struct vmci_handle handle);
159 void vmci_ctx_check_signal_notify(struct vmci_ctx *context);
160 void vmci_ctx_unset_notify(struct vmci_ctx *context);
162 int vmci_ctx_dbell_create(u32 context_id, struct vmci_handle handle);
163 int vmci_ctx_dbell_destroy(u32 context_id, struct vmci_handle handle);
164 int vmci_ctx_dbell_destroy_all(u32 context_id);
165 int vmci_ctx_notify_dbell(u32 cid, struct vmci_handle handle,
168 int vmci_ctx_rcv_notifications_get(u32 context_id, struct vmci_handle_arr
169 **db_handle_array, struct vmci_handle_arr
171 void vmci_ctx_rcv_notifications_release(u32 context_id, struct vmci_handle_arr
172 *db_handle_array, struct vmci_handle_arr
173 *qp_handle_array, bool success);
175 static inline u32 vmci_ctx_get_id(struct vmci_ctx *context)
178 return VMCI_INVALID_ID;
182 #endif /* _VMCI_CONTEXT_H_ */