xref: /freebsd/sys/dev/vmware/vmci/vmci_resource.h (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1 /*-
2  * Copyright (c) 2018 VMware, Inc.
3  *
4  * SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0)
5  */
6 
7 /* VMCI Resource Access Control API. */
8 
9 #ifndef _VMCI_RESOURCE_H_
10 #define _VMCI_RESOURCE_H_
11 
12 #include "vmci_defs.h"
13 #include "vmci_hashtable.h"
14 #include "vmci_kernel_if.h"
15 
16 #define RESOURCE_CONTAINER(ptr, type, member)				\
17 	((type *)((char *)(ptr) - offsetof(type, member)))
18 
19 typedef void(*vmci_resource_free_cb)(void *resource);
20 
21 typedef enum {
22 	VMCI_RESOURCE_TYPE_ANY,
23 	VMCI_RESOURCE_TYPE_API,
24 	VMCI_RESOURCE_TYPE_GROUP,
25 	VMCI_RESOURCE_TYPE_DATAGRAM,
26 	VMCI_RESOURCE_TYPE_DOORBELL,
27 } vmci_resource_type;
28 
29 struct vmci_resource {
30 	struct vmci_hash_entry	hash_entry;
31 	vmci_resource_type	type;
32 	/* Callback to free container object when refCount is 0. */
33 	vmci_resource_free_cb	container_free_cb;
34 	/* Container object reference. */
35 	void			*container_object;
36 };
37 
38 int	vmci_resource_init(void);
39 void	vmci_resource_exit(void);
40 void	vmci_resource_sync(void);
41 
42 vmci_id	vmci_resource_get_id(vmci_id context_id);
43 
44 int	vmci_resource_add(struct vmci_resource *resource,
45 	    vmci_resource_type resource_type,
46 	    struct vmci_handle resource_handle,
47 	    vmci_resource_free_cb container_free_cb, void *container_object);
48 void	vmci_resource_remove(struct vmci_handle resource_handle,
49 	    vmci_resource_type resource_type);
50 struct	vmci_resource *vmci_resource_get(struct vmci_handle resource_handle,
51 	    vmci_resource_type resource_type);
52 void	vmci_resource_hold(struct vmci_resource *resource);
53 int	vmci_resource_release(struct vmci_resource *resource);
54 struct	vmci_handle vmci_resource_handle(struct vmci_resource *resource);
55 
56 #endif /* !_VMCI_RESOURCE_H_ */
57