2018-03-24 20:57:00 -04:00
|
|
|
/*-
|
2018-04-07 21:32:56 -04:00
|
|
|
* Copyright (c) 2018 VMware, Inc.
|
2018-03-24 20:57:00 -04:00
|
|
|
*
|
2018-03-27 02:33:00 -04:00
|
|
|
* SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0)
|
2018-03-24 20:57:00 -04:00
|
|
|
*
|
|
|
|
|
* $FreeBSD$
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Some common utilities used by the VMCI kernel module. */
|
|
|
|
|
|
|
|
|
|
#ifndef _VMCI_UTILS_H_
|
|
|
|
|
#define _VMCI_UTILS_H_
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*------------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* vmci_hash_id --
|
|
|
|
|
*
|
|
|
|
|
* Hash function used by the Simple Datagram API. Hashes only a VMCI ID (not
|
|
|
|
|
* the full VMCI handle). Based on the djb2 hash function by Dan Bernstein.
|
|
|
|
|
*
|
|
|
|
|
* Result:
|
|
|
|
|
* Returns guest call size.
|
|
|
|
|
*
|
|
|
|
|
* Side effects:
|
|
|
|
|
* None.
|
|
|
|
|
*
|
|
|
|
|
*------------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
vmci_hash_id(vmci_id id, unsigned size)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
int hash = 5381;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(id); i++)
|
|
|
|
|
hash = ((hash << 5) + hash) + (uint8_t)(id >> (i * 8));
|
|
|
|
|
|
|
|
|
|
return (hash & (size - 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* !_VMCI_UTILS_H_ */
|