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