comm_transp.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Linux 2.6.32 and later Kernel module for VMware MVP PVTCP Server
  3. *
  4. * Copyright (C) 2010-2013 VMware, Inc. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; see the file COPYING. If not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #line 5
  20. /**
  21. * @file
  22. *
  23. * @brief Generic shared memory transport API.
  24. */
  25. #ifndef _COMM_TRANSP_H_
  26. #define _COMM_TRANSP_H_
  27. #define INCLUDE_ALLOW_PV
  28. #define INCLUDE_ALLOW_MODULE
  29. #define INCLUDE_ALLOW_MONITOR
  30. #define INCLUDE_ALLOW_GPL
  31. #include "include_check.h"
  32. /*
  33. * Common shared memory identifier.
  34. * External handle that makes sense to both hypervisor and guest.
  35. */
  36. #define COMM_TRANSP_ID_8_ANY ((unsigned char)-1)
  37. #define COMM_TRANSP_ID_32_ANY ((unsigned int)-1)
  38. #define COMM_TRANSP_ID_64_ANY ((unsigned long long)-1)
  39. typedef struct CommTranspID {
  40. union {
  41. unsigned char d8[8];
  42. unsigned int d32[2];
  43. unsigned long long d64;
  44. };
  45. } CommTranspID;
  46. /* Basic initialization arguments. */
  47. typedef enum CommTranspInitMode {
  48. COMM_TRANSP_INIT_CREATE = 0x0,
  49. COMM_TRANSP_INIT_ATTACH = 0x1
  50. } CommTranspInitMode;
  51. typedef struct CommTranspInitArgs {
  52. unsigned int capacity; /* Shared memory capacity. */
  53. unsigned int type; /* Type / implementation using this area. */
  54. CommTranspID id; /* ID (name) of shared memory area. */
  55. CommTranspInitMode mode; /* Init mode (above). */
  56. } CommTranspInitArgs;
  57. /**
  58. * @brief Generate a type id from description (protocol) string. This function
  59. * uses djb2, a string hashing algorithm by Dan Bernstein.
  60. * (see http://www.cse.yorku.ca/~oz/hash.html)
  61. * @param str string to hash
  62. * @return 32-bit hash value
  63. */
  64. static inline unsigned int
  65. CommTransp_GetType(const char *str)
  66. {
  67. unsigned int hash = 5381;
  68. int c;
  69. while ((c = *str++))
  70. hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
  71. return hash;
  72. }
  73. #endif /* _COMM_TRANSP_H_ */