vmci_driver.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * VMware VMCI Driver
  3. *
  4. * Copyright (C) 2012 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 as published by the
  8. * Free Software Foundation version 2 and no later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. */
  15. #include <linux/vmw_vmci_defs.h>
  16. #include <linux/vmw_vmci_api.h>
  17. #include <linux/atomic.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include "vmci_driver.h"
  22. #include "vmci_event.h"
  23. static bool vmci_disable_host;
  24. module_param_named(disable_host, vmci_disable_host, bool, 0);
  25. MODULE_PARM_DESC(disable_host,
  26. "Disable driver host personality (default=enabled)");
  27. static bool vmci_disable_guest;
  28. module_param_named(disable_guest, vmci_disable_guest, bool, 0);
  29. MODULE_PARM_DESC(disable_guest,
  30. "Disable driver guest personality (default=enabled)");
  31. static bool vmci_guest_personality_initialized;
  32. static bool vmci_host_personality_initialized;
  33. /*
  34. * vmci_get_context_id() - Gets the current context ID.
  35. *
  36. * Returns the current context ID. Note that since this is accessed only
  37. * from code running in the host, this always returns the host context ID.
  38. */
  39. u32 vmci_get_context_id(void)
  40. {
  41. if (vmci_guest_code_active())
  42. return vmci_get_vm_context_id();
  43. else if (vmci_host_code_active())
  44. return VMCI_HOST_CONTEXT_ID;
  45. return VMCI_INVALID_ID;
  46. }
  47. EXPORT_SYMBOL_GPL(vmci_get_context_id);
  48. static int __init vmci_drv_init(void)
  49. {
  50. int vmci_err;
  51. int error;
  52. vmci_err = vmci_event_init();
  53. if (vmci_err < VMCI_SUCCESS) {
  54. pr_err("Failed to initialize VMCIEvent (result=%d)\n",
  55. vmci_err);
  56. return -EINVAL;
  57. }
  58. if (!vmci_disable_guest) {
  59. error = vmci_guest_init();
  60. if (error) {
  61. pr_warn("Failed to initialize guest personality (err=%d)\n",
  62. error);
  63. } else {
  64. vmci_guest_personality_initialized = true;
  65. pr_info("Guest personality initialized and is %s\n",
  66. vmci_guest_code_active() ?
  67. "active" : "inactive");
  68. }
  69. }
  70. if (!vmci_disable_host) {
  71. error = vmci_host_init();
  72. if (error) {
  73. pr_warn("Unable to initialize host personality (err=%d)\n",
  74. error);
  75. } else {
  76. vmci_host_personality_initialized = true;
  77. pr_info("Initialized host personality\n");
  78. }
  79. }
  80. if (!vmci_guest_personality_initialized &&
  81. !vmci_host_personality_initialized) {
  82. vmci_event_exit();
  83. return -ENODEV;
  84. }
  85. return 0;
  86. }
  87. module_init(vmci_drv_init);
  88. static void __exit vmci_drv_exit(void)
  89. {
  90. if (vmci_guest_personality_initialized)
  91. vmci_guest_exit();
  92. if (vmci_host_personality_initialized)
  93. vmci_host_exit();
  94. vmci_event_exit();
  95. }
  96. module_exit(vmci_drv_exit);
  97. MODULE_AUTHOR("VMware, Inc.");
  98. MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface.");
  99. MODULE_VERSION("1.1.3.0-k");
  100. MODULE_LICENSE("GPL v2");