xref: /freebsd/sys/dev/vmware/vmci/vmci_hashtable.h (revision 95ee2897)
163a93856SMark Peek /*-
23eeb7511SMark Peek  * Copyright (c) 2018 VMware, Inc.
363a93856SMark Peek  *
48c302b2eSMark Peek  * SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0)
563a93856SMark Peek  */
663a93856SMark Peek 
763a93856SMark Peek /* Hash table for use in the APIs. */
863a93856SMark Peek 
963a93856SMark Peek #ifndef _VMCI_HASHTABLE_H_
1063a93856SMark Peek #define _VMCI_HASHTABLE_H_
1163a93856SMark Peek 
1263a93856SMark Peek #include "vmci_defs.h"
1363a93856SMark Peek #include "vmci_kernel_if.h"
1463a93856SMark Peek 
1563a93856SMark Peek struct vmci_hash_entry {
1663a93856SMark Peek 	struct vmci_handle	handle;
1763a93856SMark Peek 	int			ref_count;
1863a93856SMark Peek 	struct vmci_hash_entry	*next;
1963a93856SMark Peek };
2063a93856SMark Peek 
2163a93856SMark Peek struct vmci_hashtable {
2263a93856SMark Peek 	struct vmci_hash_entry	**entries;
2363a93856SMark Peek 	/* Number of buckets in above array. */
2463a93856SMark Peek 	int			size;
2563a93856SMark Peek 	vmci_lock		lock;
2663a93856SMark Peek };
2763a93856SMark Peek 
2863a93856SMark Peek struct	vmci_hashtable *vmci_hashtable_create(int size);
2963a93856SMark Peek void	vmci_hashtable_destroy(struct vmci_hashtable *table);
3063a93856SMark Peek void	vmci_hashtable_init_entry(struct vmci_hash_entry *entry,
3163a93856SMark Peek 	    struct vmci_handle handle);
3263a93856SMark Peek int	vmci_hashtable_add_entry(struct vmci_hashtable *table,
3363a93856SMark Peek 	    struct vmci_hash_entry *entry);
3463a93856SMark Peek int	vmci_hashtable_remove_entry(struct vmci_hashtable *table,
3563a93856SMark Peek 	    struct vmci_hash_entry *entry);
3663a93856SMark Peek struct	vmci_hash_entry *vmci_hashtable_get_entry(struct vmci_hashtable *table,
3763a93856SMark Peek 	    struct vmci_handle handle);
3863a93856SMark Peek void	vmci_hashtable_hold_entry(struct vmci_hashtable *table,
3963a93856SMark Peek 	    struct vmci_hash_entry *entry);
4063a93856SMark Peek int	vmci_hashtable_release_entry(struct vmci_hashtable *table,
4163a93856SMark Peek 	    struct vmci_hash_entry *entry);
4263a93856SMark Peek bool	vmci_hashtable_entry_exists(struct vmci_hashtable *table,
4363a93856SMark Peek 	    struct vmci_handle handle);
4463a93856SMark Peek void	vmci_hashtable_sync(struct vmci_hashtable *table);
4563a93856SMark Peek 
4663a93856SMark Peek #endif /* !_VMCI_HASHTABLE_H_ */
47