2 * Copyright (c) 2018 VMware, Inc.
4 * SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0)
9 /* Some common utilities used by the VMCI kernel module. */
11 #ifndef _VMCI_UTILS_H_
12 #define _VMCI_UTILS_H_
15 *------------------------------------------------------------------------------
19 * Hash function used by the Simple Datagram API. Hashes only a VMCI ID (not
20 * the full VMCI handle). Based on the djb2 hash function by Dan Bernstein.
23 * Returns guest call size.
28 *------------------------------------------------------------------------------
32 vmci_hash_id(vmci_id id, unsigned size)
37 for (i = 0; i < sizeof(id); i++)
38 hash = ((hash << 5) + hash) + (uint8_t)(id >> (i * 8));
40 return (hash & (size - 1));
43 #endif /* !_VMCI_UTILS_H_ */