xref: /freebsd/sys/dev/vmware/vmci/vmci_kernel_api_1.h (revision cfd6422a5217410fbd66f7a7a8a64d9d85e61229)
1 /*-
2  * Copyright (c) 2018 VMware, Inc.
3  *
4  * SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0)
5  *
6  * $FreeBSD$
7  */
8 
9 /* Kernel API (v1) exported from the VMCI guest driver. */
10 
11 #ifndef _VMCI_KERNEL_API_1_H_
12 #define _VMCI_KERNEL_API_1_H_
13 
14 #include "vmci_call_defs.h"
15 #include "vmci_defs.h"
16 
17 /* Define version 1. */
18 #undef  VMCI_KERNEL_API_VERSION
19 #define VMCI_KERNEL_API_VERSION_1	1
20 #define VMCI_KERNEL_API_VERSION		VMCI_KERNEL_API_VERSION_1
21 
22 /* VMCI Datagram API. */
23 int	vmci_datagram_create_handle(uint32_t resource_id, uint32_t flags,
24 	    vmci_datagram_recv_cb recv_cb, void *client_data,
25 	    struct vmci_handle *out_handle);
26 int	vmci_datagram_create_handle_priv(uint32_t resource_id, uint32_t flags,
27 	    vmci_privilege_flags priv_flags, vmci_datagram_recv_cb recv_cb,
28 	    void *client_data, struct vmci_handle *out_handle);
29 int	vmci_datagram_destroy_handle(struct vmci_handle handle);
30 int	vmci_datagram_send(struct vmci_datagram *msg);
31 
32 /* VMCI Utility API. */
33 vmci_id vmci_get_context_id(void);
34 
35 /* VMCI Event API. */
36 typedef void (*vmci_event_cb)(vmci_id sub_id, struct vmci_event_data *ed,
37 		    void *client_data);
38 
39 int	vmci_event_subscribe(vmci_event_type event, vmci_event_cb callback,
40 	    void *callback_data, vmci_id *sub_id);
41 int	vmci_event_unsubscribe(vmci_id sub_id);
42 
43 /* VMCI Queue Pair API. */
44 struct vmci_qpair;
45 
46 int	vmci_qpair_alloc(struct vmci_qpair **qpair, struct vmci_handle *handle,
47 	    uint64_t produce_q_size, uint64_t consume_q_size, vmci_id peer,
48 	    uint32_t flags, vmci_privilege_flags priv_flags);
49 int	vmci_qpair_detach(struct vmci_qpair **qpair);
50 int	vmci_qpair_get_produce_indexes(const struct vmci_qpair *qpair,
51 	    uint64_t *producer_tail, uint64_t *consumer_head);
52 int	vmci_qpair_get_consume_indexes(const struct vmci_qpair *qpair,
53 	    uint64_t *consumer_tail, uint64_t *producer_head);
54 int64_t	vmci_qpair_produce_free_space(const struct vmci_qpair *qpair);
55 int64_t	vmci_qpair_produce_buf_ready(const struct vmci_qpair *qpair);
56 int64_t	vmci_qpair_consume_free_space(const struct vmci_qpair *qpair);
57 int64_t	vmci_qpair_consume_buf_ready(const struct vmci_qpair *qpair);
58 ssize_t	vmci_qpair_enqueue(struct vmci_qpair *qpair, const void *buf,
59 	    size_t buf_size, int mode);
60 ssize_t	vmci_qpair_dequeue(struct vmci_qpair *qpair, void *buf,
61 	    size_t buf_size, int mode);
62 ssize_t vmci_qpair_peek(struct vmci_qpair *qpair, void *buf,
63 	    size_t buf_size, int mode);
64 ssize_t	vmci_qpair_enquev(struct vmci_qpair *qpair, void *iov, size_t iov_size,
65 	    int mode);
66 ssize_t	vmci_qpair_dequev(struct vmci_qpair *qpair, void *iov, size_t iov_size,
67 	    int mode);
68 ssize_t	vmci_qpair_peekv(struct vmci_qpair *qpair, void *iov, size_t iov_size,
69 	    int mode);
70 
71 #endif /* !_VMCI_KERNEL_API_1_H_ */
72