Staging: hv: remove struct vmbus_driver
[deliverable/linux.git] / drivers / staging / hv / vmbus.c
CommitLineData
3e7ee490 1/*
3e7ee490
HJ
2 * Copyright (c) 2009, Microsoft Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 *
17 * Authors:
18 * Haiyang Zhang <haiyangz@microsoft.com>
19 * Hank Janssen <hjanssen@microsoft.com>
20 *
21 */
5654e932 22#include <linux/kernel.h>
0ffa63b0 23#include <linux/mm.h>
5a0e3ad6 24#include <linux/slab.h>
4983b39a 25#include "osd.h"
645954c5 26#include "logging.h"
2d82f6c7 27#include "version_info.h"
72daf320 28#include "vmbus_private.h"
3e7ee490 29
772ec4e2 30static const char *gDriverName = "vmbus";
454f18a9 31
772ec4e2
GKH
32/*
33 * Windows vmbus does not defined this.
454f18a9
BP
34 * We defined this to be consistent with other devices
35 */
36/* {c5295816-f63a-4d5f-8d1a-4daf999ca185} */
caf26a31
GKH
37static const struct hv_guid gVmbusDeviceType = {
38 .data = {
39 0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d,
40 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85
41 }
3e7ee490
HJ
42};
43
454f18a9 44/* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */
caf26a31
GKH
45static const struct hv_guid gVmbusDeviceId = {
46 .data = {
47 0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40,
48 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5
49 }
3e7ee490
HJ
50};
51
775ef25e 52static struct hv_driver *gDriver; /* vmbus driver object */
772ec4e2 53static struct hv_device *gDevice; /* vmbus root device */
3e7ee490 54
3e189519 55/*
772ec4e2
GKH
56 * VmbusChildDeviceAdd - Registers the child device with the vmbus
57 */
f346fdc2 58int VmbusChildDeviceAdd(struct hv_device *ChildDevice)
3e7ee490 59{
98293a27 60 return vmbus_child_device_register(gDevice, ChildDevice);
3e7ee490
HJ
61}
62
3e189519 63/*
772ec4e2
GKH
64 * VmbusOnDeviceAdd - Callback when the root bus device is added
65 */
66static int VmbusOnDeviceAdd(struct hv_device *dev, void *AdditionalInfo)
3e7ee490 67{
772ec4e2
GKH
68 u32 *irqvector = AdditionalInfo;
69 int ret;
3e7ee490 70
3e7ee490
HJ
71 gDevice = dev;
72
caf26a31 73 memcpy(&gDevice->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid));
772ec4e2
GKH
74 memcpy(&gDevice->deviceInstance, &gVmbusDeviceId,
75 sizeof(struct hv_guid));
3e7ee490 76
454f18a9
BP
77 /* strcpy(dev->name, "vmbus"); */
78 /* SynIC setup... */
d44890c8 79 on_each_cpu(hv_synic_init, (void *)irqvector, 1);
3e7ee490 80
454f18a9 81 /* Connect to VMBus in the root partition */
3e7ee490
HJ
82 ret = VmbusConnect();
83
454f18a9 84 /* VmbusSendEvent(device->localPortId+1); */
3e7ee490
HJ
85 return ret;
86}
87
3e189519 88/*
772ec4e2
GKH
89 * VmbusOnDeviceRemove - Callback when the root bus device is removed
90 */
91static int VmbusOnDeviceRemove(struct hv_device *dev)
3e7ee490 92{
772ec4e2 93 int ret = 0;
3e7ee490 94
e98cb276 95 vmbus_release_unattached_channels();
3e7ee490 96 VmbusDisconnect();
d44890c8 97 on_each_cpu(hv_synic_cleanup, NULL, 1);
3e7ee490
HJ
98 return ret;
99}
100
3e189519 101/*
772ec4e2
GKH
102 * VmbusOnCleanup - Perform any cleanup when the driver is removed
103 */
104static void VmbusOnCleanup(struct hv_driver *drv)
3e7ee490 105{
ee3d7ddf 106 /* struct vmbus_driver *driver = (struct vmbus_driver *)drv; */
3e7ee490 107
d44890c8 108 hv_cleanup();
3e7ee490
HJ
109}
110
3e189519 111/*
4a1494fc 112 * vmbus_on_msg_dpc - DPC routine to handle messages from the hypervisior
772ec4e2 113 */
4a1494fc 114void vmbus_on_msg_dpc(struct hv_driver *drv)
3e7ee490 115{
7692fd4d 116 int cpu = smp_processor_id();
6a0aaa18 117 void *page_addr = hv_context.synic_message_page[cpu];
772ec4e2
GKH
118 struct hv_message *msg = (struct hv_message *)page_addr +
119 VMBUS_MESSAGE_SINT;
eacb1b4d 120 struct hv_message *copied;
772ec4e2
GKH
121
122 while (1) {
f6feebe0 123 if (msg->header.message_type == HVMSG_NONE) {
772ec4e2 124 /* no msg */
3e7ee490 125 break;
772ec4e2 126 } else {
94002c07 127 copied = kmemdup(msg, sizeof(*copied), GFP_ATOMIC);
3e7ee490 128 if (copied == NULL)
3e7ee490 129 continue;
3e7ee490 130
de65a384 131 osd_schedule_callback(gVmbusConnection.WorkQueue,
e98cb276 132 vmbus_onmessage,
de65a384 133 (void *)copied);
3e7ee490
HJ
134 }
135
f6feebe0 136 msg->header.message_type = HVMSG_NONE;
3e7ee490 137
454f18a9
BP
138 /*
139 * Make sure the write to MessageType (ie set to
f6feebe0 140 * HVMSG_NONE) happens before we read the
454f18a9
BP
141 * MessagePending and EOMing. Otherwise, the EOMing
142 * will not deliver any more messages since there is
143 * no empty slot
144 */
28b6ca9c 145 mb();
3e7ee490 146
f6feebe0 147 if (msg->header.message_flags.msg_pending) {
454f18a9
BP
148 /*
149 * This will cause message queue rescan to
150 * possibly deliver another msg from the
151 * hypervisor
152 */
a51ed7d6 153 wrmsrl(HV_X64_MSR_EOM, 0);
3e7ee490
HJ
154 }
155 }
156}
157
3e189519 158/*
c722bd3e 159 * vmbus_on_event_dpc - DPC routine to handle events from the hypervisior
772ec4e2 160 */
c722bd3e 161void vmbus_on_event_dpc(struct hv_driver *drv)
3e7ee490 162{
454f18a9 163 /* TODO: Process any events */
3e7ee490
HJ
164 VmbusOnEvents();
165}
166
3e189519 167/*
097e3103 168 * vmbus_on_isr - ISR routine
772ec4e2 169 */
097e3103 170int vmbus_on_isr(struct hv_driver *drv)
3e7ee490 171{
772ec4e2 172 int ret = 0;
7692fd4d 173 int cpu = smp_processor_id();
3e7ee490 174 void *page_addr;
eacb1b4d
GKH
175 struct hv_message *msg;
176 union hv_synic_event_flags *event;
3e7ee490 177
6a0aaa18 178 page_addr = hv_context.synic_message_page[cpu];
eacb1b4d 179 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
3e7ee490 180
454f18a9 181 /* Check if there are actual msgs to be process */
f6feebe0 182 if (msg->header.message_type != HVMSG_NONE) {
772ec4e2 183 DPRINT_DBG(VMBUS, "received msg type %d size %d",
f6feebe0
HZ
184 msg->header.message_type,
185 msg->header.payload_size);
3e7ee490 186 ret |= 0x1;
772ec4e2 187 }
3e7ee490 188
454f18a9 189 /* TODO: Check if there are events to be process */
6a0aaa18 190 page_addr = hv_context.synic_event_page[cpu];
eacb1b4d 191 event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT;
3e7ee490 192
454f18a9 193 /* Since we are a child, we only need to check bit 0 */
f6feebe0
HZ
194 if (test_and_clear_bit(0, (unsigned long *) &event->flags32[0])) {
195 DPRINT_DBG(VMBUS, "received event %d", event->flags32[0]);
3e7ee490
HJ
196 ret |= 0x2;
197 }
198
3e7ee490
HJ
199 return ret;
200}
b3bfb3ce 201
3e189519 202/*
b3bfb3ce
GKH
203 * VmbusInitialize - Main entry point
204 */
a69a6691 205int VmbusInitialize(struct hv_driver *driver)
b3bfb3ce 206{
b3bfb3ce
GKH
207 int ret;
208
26c14cc1
HJ
209 DPRINT_INFO(VMBUS, "+++++++ HV Driver version = %s +++++++",
210 HV_DRV_VERSION);
b3bfb3ce
GKH
211 DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++",
212 VMBUS_REVISION_NUMBER);
213 DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++",
214 VMBUS_MESSAGE_SINT);
430a8e9a 215 DPRINT_DBG(VMBUS, "sizeof(vmbus_channel_packet_page_buffer)=%zd, "
b3bfb3ce 216 "sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%zd",
430a8e9a
HZ
217 sizeof(struct vmbus_channel_packet_page_buffer),
218 sizeof(struct vmbus_channel_packet_multipage_buffer));
b3bfb3ce 219
a69a6691
GKH
220 driver->name = gDriverName;
221 memcpy(&driver->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid));
b3bfb3ce
GKH
222
223 /* Setup dispatch table */
a69a6691
GKH
224 driver->OnDeviceAdd = VmbusOnDeviceAdd;
225 driver->OnDeviceRemove = VmbusOnDeviceRemove;
226 driver->OnCleanup = VmbusOnCleanup;
b3bfb3ce
GKH
227
228 /* Hypervisor initialization...setup hypercall page..etc */
d44890c8 229 ret = hv_init();
b3bfb3ce
GKH
230 if (ret != 0)
231 DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x",
232 ret);
a69a6691 233 gDriver = driver;
b3bfb3ce 234
b3bfb3ce
GKH
235 return ret;
236}
This page took 0.161922 seconds and 5 git commands to generate.