Skip to content

Commit 197dbaa

Browse files
georgezhang11gregkh
authored andcommitted
VMCI: device driver implementaton.
VMCI driver code implementes both the host and guest personalities of the VMCI driver. Signed-off-by: George Zhang <georgezhang@vmware.com> Acked-by: Andy king <acking@vmware.com> Acked-by: Dmitry Torokhov <dtor@vmware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 83e2ec7 commit 197dbaa

2 files changed

Lines changed: 167 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
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>
22+
23+
#include "vmci_driver.h"
24+
#include "vmci_event.h"
25+
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)");
30+
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)");
35+
36+
static bool vmci_guest_personality_initialized;
37+
static bool vmci_host_personality_initialized;
38+
39+
/*
40+
* vmci_get_context_id() - Gets the current context ID.
41+
*
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.
44+
*/
45+
u32 vmci_get_context_id(void)
46+
{
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;
51+
52+
return VMCI_INVALID_ID;
53+
}
54+
EXPORT_SYMBOL_GPL(vmci_get_context_id);
55+
56+
static int __init vmci_drv_init(void)
57+
{
58+
int vmci_err;
59+
int error;
60+
61+
vmci_err = vmci_event_init();
62+
if (vmci_err < VMCI_SUCCESS) {
63+
pr_err("Failed to initialize VMCIEvent (result=%d)\n",
64+
vmci_err);
65+
return -EINVAL;
66+
}
67+
68+
if (!vmci_disable_guest) {
69+
error = vmci_guest_init();
70+
if (error) {
71+
pr_warn("Failed to initialize guest personality (err=%d)\n",
72+
error);
73+
} else {
74+
vmci_guest_personality_initialized = true;
75+
pr_info("Guest personality initialized and is %s\n",
76+
vmci_guest_code_active() ?
77+
"active" : "inactive");
78+
}
79+
}
80+
81+
if (!vmci_disable_host) {
82+
error = vmci_host_init();
83+
if (error) {
84+
pr_warn("Unable to initialize host personality (err=%d)\n",
85+
error);
86+
} else {
87+
vmci_host_personality_initialized = true;
88+
pr_info("Initialized host personality\n");
89+
}
90+
}
91+
92+
if (!vmci_guest_personality_initialized &&
93+
!vmci_host_personality_initialized) {
94+
vmci_event_exit();
95+
return -ENODEV;
96+
}
97+
98+
return 0;
99+
}
100+
module_init(vmci_drv_init);
101+
102+
static void __exit vmci_drv_exit(void)
103+
{
104+
if (vmci_guest_personality_initialized)
105+
vmci_guest_exit();
106+
107+
if (vmci_host_personality_initialized)
108+
vmci_host_exit();
109+
110+
vmci_event_exit();
111+
}
112+
module_exit(vmci_drv_exit);
113+
114+
MODULE_AUTHOR("VMware, Inc.");
115+
MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface.");
116+
MODULE_VERSION("1.0.0.0-k");
117+
MODULE_LICENSE("GPL v2");
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
16+
#ifndef _VMCI_DRIVER_H_
17+
#define _VMCI_DRIVER_H_
18+
19+
#include <linux/vmw_vmci_defs.h>
20+
#include <linux/wait.h>
21+
22+
#include "vmci_queue_pair.h"
23+
#include "vmci_context.h"
24+
25+
enum vmci_obj_type {
26+
VMCIOBJ_VMX_VM = 10,
27+
VMCIOBJ_CONTEXT,
28+
VMCIOBJ_SOCKET,
29+
VMCIOBJ_NOT_SET,
30+
};
31+
32+
/* For storing VMCI structures in file handles. */
33+
struct vmci_obj {
34+
void *ptr;
35+
enum vmci_obj_type type;
36+
};
37+
38+
u32 vmci_get_context_id(void);
39+
int vmci_send_datagram(struct vmci_datagram *dg);
40+
41+
int vmci_host_init(void);
42+
void vmci_host_exit(void);
43+
bool vmci_host_code_active(void);
44+
45+
int vmci_guest_init(void);
46+
void vmci_guest_exit(void);
47+
bool vmci_guest_code_active(void);
48+
u32 vmci_get_vm_context_id(void);
49+
50+
#endif /* _VMCI_DRIVER_H_ */

0 commit comments

Comments
 (0)