1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * VMware VMCI driver (vmciContext.h)
5 * Copyright (C) 2012 VMware, Inc. All rights reserved.
8 #ifndef _VMCI_CONTEXT_H_
9 #define _VMCI_CONTEXT_H_
11 #include <linux/vmw_vmci_defs.h>
12 #include <linux/atomic.h>
13 #include <linux/kref.h>
14 #include <linux/types.h>
15 #include <linux/wait.h>
17 #include "vmci_handle_array.h"
18 #include "vmci_datagram.h"
20 /* Used to determine what checkpoint state to get and set. */
22 VMCI_NOTIFICATION_CPT_STATE
= 1,
23 VMCI_WELLKNOWN_CPT_STATE
= 2,
24 VMCI_DG_OUT_STATE
= 3,
26 VMCI_DG_IN_SIZE_STATE
= 5,
27 VMCI_DOORBELL_CPT_STATE
= 6,
30 /* Host specific struct used for signalling */
32 wait_queue_head_t wait_queue
;
35 struct vmci_handle_list
{
36 struct list_head node
;
37 struct vmci_handle handle
;
41 struct list_head list_item
; /* For global VMCI list. */
44 struct list_head datagram_queue
; /* Head of per VM queue. */
45 u32 pending_datagrams
;
46 size_t datagram_queue_size
; /* Size of datagram queue in bytes. */
49 * Version of the code that created
50 * this context; e.g., VMX.
53 spinlock_t lock
; /* Locks callQueue and handle_arrays. */
56 * queue_pairs attached to. The array of
57 * handles for queue pairs is accessed
58 * from the code for QP API, and there
59 * it is protected by the QP lock. It
60 * is also accessed from the context
61 * clean up path, which does not
62 * require a lock. VMCILock is not
63 * used to protect the QP array field.
65 struct vmci_handle_arr
*queue_pair_array
;
67 /* Doorbells created by context. */
68 struct vmci_handle_arr
*doorbell_array
;
70 /* Doorbells pending for context. */
71 struct vmci_handle_arr
*pending_doorbell_array
;
73 /* Contexts current context is subscribing to. */
74 struct list_head notifier_list
;
75 unsigned int n_notifiers
;
77 struct vmci_host host_context
;
80 const struct cred
*cred
;
81 bool *notify
; /* Notify flag pointer - hosted only. */
82 struct page
*notify_page
; /* Page backing the notify UVA. */
85 /* VMCINotifyAddRemoveInfo: Used to add/remove remote context notifications. */
86 struct vmci_ctx_info
{
91 /* VMCICptBufInfo: Used to set/get current context's checkpoint state. */
92 struct vmci_ctx_chkpt_buf_info
{
101 * VMCINotificationReceiveInfo: Used to recieve pending notifications
102 * for doorbells and queue pairs.
104 struct vmci_ctx_notify_recv_info
{
105 u64 db_handle_buf_uva
;
106 u64 db_handle_buf_size
;
107 u64 qp_handle_buf_uva
;
108 u64 qp_handle_buf_size
;
114 * Utilility function that checks whether two entities are allowed
115 * to interact. If one of them is restricted, the other one must
118 static inline bool vmci_deny_interaction(u32 part_one
, u32 part_two
)
120 return ((part_one
& VMCI_PRIVILEGE_FLAG_RESTRICTED
) &&
121 !(part_two
& VMCI_PRIVILEGE_FLAG_TRUSTED
)) ||
122 ((part_two
& VMCI_PRIVILEGE_FLAG_RESTRICTED
) &&
123 !(part_one
& VMCI_PRIVILEGE_FLAG_TRUSTED
));
126 struct vmci_ctx
*vmci_ctx_create(u32 cid
, u32 flags
,
127 uintptr_t event_hnd
, int version
,
128 const struct cred
*cred
);
129 void vmci_ctx_destroy(struct vmci_ctx
*context
);
131 bool vmci_ctx_supports_host_qp(struct vmci_ctx
*context
);
132 int vmci_ctx_enqueue_datagram(u32 cid
, struct vmci_datagram
*dg
);
133 int vmci_ctx_dequeue_datagram(struct vmci_ctx
*context
,
134 size_t *max_size
, struct vmci_datagram
**dg
);
135 int vmci_ctx_pending_datagrams(u32 cid
, u32
*pending
);
136 struct vmci_ctx
*vmci_ctx_get(u32 cid
);
137 void vmci_ctx_put(struct vmci_ctx
*context
);
138 bool vmci_ctx_exists(u32 cid
);
140 int vmci_ctx_add_notification(u32 context_id
, u32 remote_cid
);
141 int vmci_ctx_remove_notification(u32 context_id
, u32 remote_cid
);
142 int vmci_ctx_get_chkpt_state(u32 context_id
, u32 cpt_type
,
143 u32
*num_cids
, void **cpt_buf_ptr
);
144 int vmci_ctx_set_chkpt_state(u32 context_id
, u32 cpt_type
,
145 u32 num_cids
, void *cpt_buf
);
147 int vmci_ctx_qp_create(struct vmci_ctx
*context
, struct vmci_handle handle
);
148 int vmci_ctx_qp_destroy(struct vmci_ctx
*context
, struct vmci_handle handle
);
149 bool vmci_ctx_qp_exists(struct vmci_ctx
*context
, struct vmci_handle handle
);
151 void vmci_ctx_check_signal_notify(struct vmci_ctx
*context
);
152 void vmci_ctx_unset_notify(struct vmci_ctx
*context
);
154 int vmci_ctx_dbell_create(u32 context_id
, struct vmci_handle handle
);
155 int vmci_ctx_dbell_destroy(u32 context_id
, struct vmci_handle handle
);
156 int vmci_ctx_dbell_destroy_all(u32 context_id
);
157 int vmci_ctx_notify_dbell(u32 cid
, struct vmci_handle handle
,
160 int vmci_ctx_rcv_notifications_get(u32 context_id
, struct vmci_handle_arr
161 **db_handle_array
, struct vmci_handle_arr
163 void vmci_ctx_rcv_notifications_release(u32 context_id
, struct vmci_handle_arr
164 *db_handle_array
, struct vmci_handle_arr
165 *qp_handle_array
, bool success
);
167 static inline u32
vmci_ctx_get_id(struct vmci_ctx
*context
)
170 return VMCI_INVALID_ID
;
174 #endif /* _VMCI_CONTEXT_H_ */