xref: /linux/drivers/misc/vmw_vmci/vmci_handle_array.h (revision e7d759f31ca295d589f7420719c311870bb3166f)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * VMware VMCI Driver
4  *
5  * Copyright (C) 2012 VMware, Inc. All rights reserved.
6  */
7 
8 #ifndef _VMCI_HANDLE_ARRAY_H_
9 #define _VMCI_HANDLE_ARRAY_H_
10 
11 #include <linux/vmw_vmci_defs.h>
12 #include <linux/limits.h>
13 #include <linux/types.h>
14 
15 struct vmci_handle_arr {
16 	u32 capacity;
17 	u32 max_capacity;
18 	u32 size;
19 	u32 pad;
20 	struct vmci_handle entries[] __counted_by(capacity);
21 };
22 
23 /* Select a default capacity that results in a 64 byte sized array */
24 #define VMCI_HANDLE_ARRAY_DEFAULT_CAPACITY			6
25 
26 struct vmci_handle_arr *vmci_handle_arr_create(u32 capacity, u32 max_capacity);
27 void vmci_handle_arr_destroy(struct vmci_handle_arr *array);
28 int vmci_handle_arr_append_entry(struct vmci_handle_arr **array_ptr,
29 				 struct vmci_handle handle);
30 struct vmci_handle vmci_handle_arr_remove_entry(struct vmci_handle_arr *array,
31 						struct vmci_handle
32 						entry_handle);
33 struct vmci_handle vmci_handle_arr_remove_tail(struct vmci_handle_arr *array);
34 struct vmci_handle
35 vmci_handle_arr_get_entry(const struct vmci_handle_arr *array, u32 index);
36 bool vmci_handle_arr_has_entry(const struct vmci_handle_arr *array,
37 			       struct vmci_handle entry_handle);
38 struct vmci_handle *vmci_handle_arr_get_handles(struct vmci_handle_arr *array);
39 
40 static inline u32 vmci_handle_arr_get_size(
41 	const struct vmci_handle_arr *array)
42 {
43 	return array->size;
44 }
45 
46 
47 #endif /* _VMCI_HANDLE_ARRAY_H_ */
48