4 * Copyright (C) 2012 VMware, Inc. All rights reserved.
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.
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
16 #include <linux/vmw_vmci_defs.h>
17 #include <linux/vmw_vmci_api.h>
18 #include <linux/atomic.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
23 #include "vmci_driver.h"
24 #include "vmci_event.h"
26 static bool vmci_disable_host
;
27 module_param_named(disable_host
, vmci_disable_host
, bool, 0);
28 MODULE_PARM_DESC(disable_host
,
29 "Disable driver host personality (default=enabled)");
31 static bool vmci_disable_guest
;
32 module_param_named(disable_guest
, vmci_disable_guest
, bool, 0);
33 MODULE_PARM_DESC(disable_guest
,
34 "Disable driver guest personality (default=enabled)");
36 static bool vmci_guest_personality_initialized
;
37 static bool vmci_host_personality_initialized
;
40 * vmci_get_context_id() - Gets the current context ID.
42 * Returns the current context ID. Note that since this is accessed only
43 * from code running in the host, this always returns the host context ID.
45 u32
vmci_get_context_id(void)
47 if (vmci_guest_code_active())
48 return vmci_get_vm_context_id();
49 else if (vmci_host_code_active())
50 return VMCI_HOST_CONTEXT_ID
;
52 return VMCI_INVALID_ID
;
54 EXPORT_SYMBOL_GPL(vmci_get_context_id
);
56 static int __init
vmci_drv_init(void)
61 vmci_err
= vmci_event_init();
62 if (vmci_err
< VMCI_SUCCESS
) {
63 pr_err("Failed to initialize VMCIEvent (result=%d)\n",
68 if (!vmci_disable_guest
) {
69 error
= vmci_guest_init();
71 pr_warn("Failed to initialize guest personality (err=%d)\n",
74 vmci_guest_personality_initialized
= true;
75 pr_info("Guest personality initialized and is %s\n",
76 vmci_guest_code_active() ?
77 "active" : "inactive");
81 if (!vmci_disable_host
) {
82 error
= vmci_host_init();
84 pr_warn("Unable to initialize host personality (err=%d)\n",
87 vmci_host_personality_initialized
= true;
88 pr_info("Initialized host personality\n");
92 if (!vmci_guest_personality_initialized
&&
93 !vmci_host_personality_initialized
) {
100 module_init(vmci_drv_init
);
102 static void __exit
vmci_drv_exit(void)
104 if (vmci_guest_personality_initialized
)
107 if (vmci_host_personality_initialized
)
112 module_exit(vmci_drv_exit
);
114 MODULE_AUTHOR("VMware, Inc.");
115 MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface.");
116 MODULE_VERSION("1.1.3.0-k");
117 MODULE_LICENSE("GPL v2");