1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2012 VMware, Inc. All rights reserved.
8 #include <linux/vmw_vmci_defs.h>
9 #include <linux/vmw_vmci_api.h>
10 #include <linux/atomic.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
15 #include "vmci_driver.h"
16 #include "vmci_event.h"
18 static bool vmci_disable_host;
19 module_param_named(disable_host, vmci_disable_host, bool, 0);
20 MODULE_PARM_DESC(disable_host,
21 "Disable driver host personality (default=enabled)");
23 static bool vmci_disable_guest;
24 module_param_named(disable_guest, vmci_disable_guest, bool, 0);
25 MODULE_PARM_DESC(disable_guest,
26 "Disable driver guest personality (default=enabled)");
28 static bool vmci_guest_personality_initialized;
29 static bool vmci_host_personality_initialized;
32 * vmci_get_context_id() - Gets the current context ID.
34 * Returns the current context ID. Note that since this is accessed only
35 * from code running in the host, this always returns the host context ID.
37 u32 vmci_get_context_id(void)
39 if (vmci_guest_code_active())
40 return vmci_get_vm_context_id();
41 else if (vmci_host_code_active())
42 return VMCI_HOST_CONTEXT_ID;
44 return VMCI_INVALID_ID;
46 EXPORT_SYMBOL_GPL(vmci_get_context_id);
48 static int __init vmci_drv_init(void)
53 vmci_err = vmci_event_init();
54 if (vmci_err < VMCI_SUCCESS) {
55 pr_err("Failed to initialize VMCIEvent (result=%d)\n",
60 if (!vmci_disable_guest) {
61 error = vmci_guest_init();
63 pr_warn("Failed to initialize guest personality (err=%d)\n",
66 vmci_guest_personality_initialized = true;
67 pr_info("Guest personality initialized and is %s\n",
68 vmci_guest_code_active() ?
69 "active" : "inactive");
73 if (!vmci_disable_host) {
74 error = vmci_host_init();
76 pr_warn("Unable to initialize host personality (err=%d)\n",
79 vmci_host_personality_initialized = true;
80 pr_info("Initialized host personality\n");
84 if (!vmci_guest_personality_initialized &&
85 !vmci_host_personality_initialized) {
92 module_init(vmci_drv_init);
94 static void __exit vmci_drv_exit(void)
96 if (vmci_guest_personality_initialized)
99 if (vmci_host_personality_initialized)
104 module_exit(vmci_drv_exit);
106 MODULE_AUTHOR("VMware, Inc.");
107 MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface.");
108 MODULE_VERSION("1.1.6.0-k");
109 MODULE_LICENSE("GPL v2");