Thomas Gleixner | 685a6bf | 2019-05-29 16:57:36 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
George Zhang | b484b26 | 2013-01-08 15:54:39 -0800 | [diff] [blame] | 2 | /* |
| 3 | * VMware VMCI Driver |
| 4 | * |
| 5 | * Copyright (C) 2012 VMware, Inc. All rights reserved. |
George Zhang | b484b26 | 2013-01-08 15:54:39 -0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _VMCI_HANDLE_ARRAY_H_ |
| 9 | #define _VMCI_HANDLE_ARRAY_H_ |
| 10 | |
| 11 | #include <linux/vmw_vmci_defs.h> |
Vishnu DASA | 1c2eb5b | 2019-05-24 15:13:10 +0000 | [diff] [blame] | 12 | #include <linux/limits.h> |
George Zhang | b484b26 | 2013-01-08 15:54:39 -0800 | [diff] [blame] | 13 | #include <linux/types.h> |
| 14 | |
George Zhang | b484b26 | 2013-01-08 15:54:39 -0800 | [diff] [blame] | 15 | struct vmci_handle_arr { |
Vishnu DASA | 1c2eb5b | 2019-05-24 15:13:10 +0000 | [diff] [blame] | 16 | u32 capacity; |
| 17 | u32 max_capacity; |
| 18 | u32 size; |
| 19 | u32 pad; |
George Zhang | b484b26 | 2013-01-08 15:54:39 -0800 | [diff] [blame] | 20 | struct vmci_handle entries[]; |
| 21 | }; |
| 22 | |
Vishnu DASA | 1c2eb5b | 2019-05-24 15:13:10 +0000 | [diff] [blame] | 23 | #define VMCI_HANDLE_ARRAY_HEADER_SIZE \ |
| 24 | offsetof(struct vmci_handle_arr, entries) |
| 25 | /* Select a default capacity that results in a 64 byte sized array */ |
| 26 | #define VMCI_HANDLE_ARRAY_DEFAULT_CAPACITY 6 |
| 27 | /* Make sure that the max array size can be expressed by a u32 */ |
| 28 | #define VMCI_HANDLE_ARRAY_MAX_CAPACITY \ |
| 29 | ((U32_MAX - VMCI_HANDLE_ARRAY_HEADER_SIZE - 1) / \ |
| 30 | sizeof(struct vmci_handle)) |
| 31 | |
| 32 | struct vmci_handle_arr *vmci_handle_arr_create(u32 capacity, u32 max_capacity); |
George Zhang | b484b26 | 2013-01-08 15:54:39 -0800 | [diff] [blame] | 33 | void vmci_handle_arr_destroy(struct vmci_handle_arr *array); |
Vishnu DASA | 1c2eb5b | 2019-05-24 15:13:10 +0000 | [diff] [blame] | 34 | int vmci_handle_arr_append_entry(struct vmci_handle_arr **array_ptr, |
| 35 | struct vmci_handle handle); |
George Zhang | b484b26 | 2013-01-08 15:54:39 -0800 | [diff] [blame] | 36 | struct vmci_handle vmci_handle_arr_remove_entry(struct vmci_handle_arr *array, |
| 37 | struct vmci_handle |
| 38 | entry_handle); |
| 39 | struct vmci_handle vmci_handle_arr_remove_tail(struct vmci_handle_arr *array); |
| 40 | struct vmci_handle |
Vishnu DASA | 1c2eb5b | 2019-05-24 15:13:10 +0000 | [diff] [blame] | 41 | vmci_handle_arr_get_entry(const struct vmci_handle_arr *array, u32 index); |
George Zhang | b484b26 | 2013-01-08 15:54:39 -0800 | [diff] [blame] | 42 | bool vmci_handle_arr_has_entry(const struct vmci_handle_arr *array, |
| 43 | struct vmci_handle entry_handle); |
| 44 | struct vmci_handle *vmci_handle_arr_get_handles(struct vmci_handle_arr *array); |
| 45 | |
Vishnu DASA | 1c2eb5b | 2019-05-24 15:13:10 +0000 | [diff] [blame] | 46 | static inline u32 vmci_handle_arr_get_size( |
George Zhang | b484b26 | 2013-01-08 15:54:39 -0800 | [diff] [blame] | 47 | const struct vmci_handle_arr *array) |
| 48 | { |
| 49 | return array->size; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | #endif /* _VMCI_HANDLE_ARRAY_H_ */ |