]>
Commit | Line | Data |
---|---|---|
3e7ee490 HJ |
1 | /* |
2 | * | |
3 | * Copyright (c) 2009, Microsoft Corporation. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms and conditions of the GNU General Public License, | |
7 | * version 2, as published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along with | |
15 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
16 | * Place - Suite 330, Boston, MA 02111-1307 USA. | |
17 | * | |
18 | * Authors: | |
19 | * Haiyang Zhang <haiyangz@microsoft.com> | |
20 | * Hank Janssen <hjanssen@microsoft.com> | |
21 | * | |
22 | */ | |
23 | ||
24 | ||
25 | #include <linux/init.h> | |
26 | #include <linux/module.h> | |
27 | #include <linux/device.h> | |
28 | #include <linux/irq.h> | |
29 | #include <linux/interrupt.h> | |
30 | #include <linux/sysctl.h> | |
31 | ||
09d50ff8 GKH |
32 | #include "include/logging.h" |
33 | #include "include/vmbus.h" | |
3e7ee490 | 34 | |
3e7ee490 | 35 | |
454f18a9 BP |
36 | /* Defines */ |
37 | ||
38 | ||
39 | /* FIXME! We need to do this dynamically for PIC and APIC system */ | |
3e7ee490 | 40 | #define VMBUS_IRQ 0x5 |
3e7ee490 | 41 | #define VMBUS_IRQ_VECTOR IRQ5_VECTOR |
3e7ee490 | 42 | |
454f18a9 BP |
43 | /* Data types */ |
44 | ||
45 | ||
46 | /* Main vmbus driver data structure */ | |
3e7ee490 | 47 | struct vmbus_driver_context { |
454f18a9 BP |
48 | /* !! These must be the first 2 fields !! */ |
49 | /* The driver field is not used in here. Instead, the bus field is */ | |
50 | /* used to represent the driver */ | |
3e7ee490 HJ |
51 | struct driver_context drv_ctx; |
52 | VMBUS_DRIVER_OBJECT drv_obj; | |
53 | ||
54 | struct bus_type bus; | |
55 | struct tasklet_struct msg_dpc; | |
56 | struct tasklet_struct event_dpc; | |
57 | ||
454f18a9 | 58 | /* The bus root device */ |
3e7ee490 HJ |
59 | struct device_context device_ctx; |
60 | }; | |
61 | ||
454f18a9 BP |
62 | |
63 | /* Static decl */ | |
64 | ||
3e7ee490 HJ |
65 | static int vmbus_match(struct device *device, struct device_driver *driver); |
66 | static int vmbus_probe(struct device *device); | |
67 | static int vmbus_remove(struct device *device); | |
68 | static void vmbus_shutdown(struct device *device); | |
3e7ee490 | 69 | static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env); |
3e7ee490 HJ |
70 | static void vmbus_msg_dpc(unsigned long data); |
71 | static void vmbus_event_dpc(unsigned long data); | |
72 | ||
3e7ee490 | 73 | static irqreturn_t vmbus_isr(int irq, void* dev_id); |
3e7ee490 HJ |
74 | |
75 | static void vmbus_device_release(struct device *device); | |
76 | static void vmbus_bus_release(struct device *device); | |
77 | ||
78 | static DEVICE_OBJECT* vmbus_child_device_create(GUID type, GUID instance, void* context); | |
79 | static void vmbus_child_device_destroy(DEVICE_OBJECT* device_obj); | |
80 | static int vmbus_child_device_register(DEVICE_OBJECT* root_device_obj, DEVICE_OBJECT* child_device_obj); | |
81 | static void vmbus_child_device_unregister(DEVICE_OBJECT* child_device_obj); | |
82 | static void vmbus_child_device_get_info(DEVICE_OBJECT *device_obj, DEVICE_INFO *device_info); | |
83 | ||
454f18a9 BP |
84 | /* static ssize_t vmbus_show_class_id(struct device *dev, struct device_attribute *attr, char *buf); */ |
85 | /* static ssize_t vmbus_show_device_id(struct device *dev, struct device_attribute *attr, char *buf); */ | |
3e7ee490 HJ |
86 | |
87 | static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, char *buf); | |
88 | ||
3e7ee490 | 89 | |
454f18a9 BP |
90 | /* Global */ |
91 | ||
3e7ee490 | 92 | |
454f18a9 BP |
93 | /* Global logging setting */ |
94 | ||
95 | /* unsigned int vmbus_loglevel= (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT); */ | |
96 | /* unsigned int vmbus_loglevel= (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT); */ | |
3e7ee490 HJ |
97 | unsigned int vmbus_loglevel= (ALL_MODULES << 16 | INFO_LVL); |
98 | EXPORT_SYMBOL(vmbus_loglevel); | |
99 | ||
100 | static int vmbus_irq = VMBUS_IRQ; | |
101 | ||
454f18a9 BP |
102 | /* Setup /proc/sys/bus/vmbus/vmbus_loglevel */ |
103 | /* Allow usage of sysctl cmd to set the logging level */ | |
3e7ee490 HJ |
104 | static struct ctl_table_header *vmbus_ctl_table_hdr; |
105 | ||
106 | static ctl_table vmbus_dev_ctl_table[] = { | |
107 | { .ctl_name = 8461, | |
108 | .procname = "vmbus_loglevel", | |
109 | .data = &vmbus_loglevel, | |
110 | .maxlen = sizeof(vmbus_loglevel), | |
111 | .mode = 0644, | |
112 | .proc_handler = &proc_dointvec }, | |
113 | { } | |
114 | }; | |
115 | ||
116 | static ctl_table vmbus_ctl_table[] = { | |
117 | { .ctl_name = CTL_DEV, | |
118 | .procname = "vmbus", | |
119 | .mode = 0555, | |
120 | .child = vmbus_dev_ctl_table }, | |
121 | { } | |
122 | }; | |
123 | ||
124 | static ctl_table vmus_root_ctl_table[] = { | |
125 | { .ctl_name = CTL_BUS, | |
126 | .procname = "bus", | |
127 | .mode = 0555, | |
128 | .child = vmbus_ctl_table }, | |
129 | { } | |
130 | }; | |
131 | ||
454f18a9 BP |
132 | |
133 | /* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */ | |
134 | ||
3e7ee490 HJ |
135 | static struct device_attribute vmbus_device_attrs[] = { |
136 | __ATTR(id, S_IRUGO, vmbus_show_device_attr, NULL), | |
137 | __ATTR(state, S_IRUGO, vmbus_show_device_attr, NULL), | |
138 | __ATTR(class_id, S_IRUGO, vmbus_show_device_attr, NULL), | |
139 | __ATTR(device_id, S_IRUGO, vmbus_show_device_attr, NULL), | |
140 | __ATTR(monitor_id, S_IRUGO, vmbus_show_device_attr, NULL), | |
141 | ||
142 | __ATTR(server_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL), | |
143 | __ATTR(server_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL), | |
144 | __ATTR(server_monitor_conn_id, S_IRUGO, vmbus_show_device_attr, NULL), | |
145 | ||
146 | __ATTR(client_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL), | |
147 | __ATTR(client_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL), | |
148 | __ATTR(client_monitor_conn_id, S_IRUGO, vmbus_show_device_attr, NULL), | |
149 | ||
150 | __ATTR(out_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL), | |
151 | __ATTR(out_read_index, S_IRUGO, vmbus_show_device_attr, NULL), | |
152 | __ATTR(out_write_index, S_IRUGO, vmbus_show_device_attr, NULL), | |
153 | __ATTR(out_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL), | |
154 | __ATTR(out_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL), | |
155 | ||
156 | __ATTR(in_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL), | |
157 | __ATTR(in_read_index, S_IRUGO, vmbus_show_device_attr, NULL), | |
158 | __ATTR(in_write_index, S_IRUGO, vmbus_show_device_attr, NULL), | |
159 | __ATTR(in_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL), | |
160 | __ATTR(in_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL), | |
161 | __ATTR_NULL | |
162 | }; | |
3e7ee490 | 163 | |
454f18a9 | 164 | /* The one and only one */ |
3e7ee490 HJ |
165 | static struct vmbus_driver_context g_vmbus_drv={ |
166 | .bus.name = "vmbus", | |
167 | .bus.match = vmbus_match, | |
3e7ee490 HJ |
168 | .bus.shutdown = vmbus_shutdown, |
169 | .bus.remove = vmbus_remove, | |
170 | .bus.probe = vmbus_probe, | |
171 | .bus.uevent = vmbus_uevent, | |
172 | .bus.dev_attrs = vmbus_device_attrs, | |
3e7ee490 HJ |
173 | }; |
174 | ||
454f18a9 BP |
175 | |
176 | /* Routines */ | |
177 | ||
3e7ee490 HJ |
178 | |
179 | ||
180 | /*++ | |
181 | ||
182 | Name: vmbus_show_device_attr() | |
183 | ||
184 | Desc: Show the device attribute in sysfs. This is invoked when user does a "cat /sys/bus/vmbus/devices/<bus device>/<attr name>" | |
185 | ||
186 | --*/ | |
187 | static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, char *buf) | |
188 | { | |
189 | struct device_context *device_ctx = device_to_device_context(dev); | |
190 | DEVICE_INFO device_info; | |
191 | ||
192 | memset(&device_info, 0, sizeof(DEVICE_INFO)); | |
193 | ||
194 | vmbus_child_device_get_info(&device_ctx->device_obj, &device_info); | |
195 | ||
196 | if (!strcmp(dev_attr->attr.name, "class_id")) | |
197 | { | |
198 | return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", | |
199 | device_info.ChannelType.Data[3], device_info.ChannelType.Data[2], device_info.ChannelType.Data[1], device_info.ChannelType.Data[0], | |
200 | device_info.ChannelType.Data[5], device_info.ChannelType.Data[4], | |
201 | device_info.ChannelType.Data[7], device_info.ChannelType.Data[6], | |
202 | device_info.ChannelType.Data[8], device_info.ChannelType.Data[9], device_info.ChannelType.Data[10], device_info.ChannelType.Data[11], device_info.ChannelType.Data[12], device_info.ChannelType.Data[13], device_info.ChannelType.Data[14], device_info.ChannelType.Data[15]); | |
203 | ||
204 | } | |
205 | else if (!strcmp(dev_attr->attr.name, "device_id")) | |
206 | { | |
207 | return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", | |
208 | device_info.ChannelInstance.Data[3], device_info.ChannelInstance.Data[2], device_info.ChannelInstance.Data[1], device_info.ChannelInstance.Data[0], | |
209 | device_info.ChannelInstance.Data[5], device_info.ChannelInstance.Data[4], | |
210 | device_info.ChannelInstance.Data[7], device_info.ChannelInstance.Data[6], | |
211 | device_info.ChannelInstance.Data[8], device_info.ChannelInstance.Data[9], device_info.ChannelInstance.Data[10], device_info.ChannelInstance.Data[11], device_info.ChannelInstance.Data[12], device_info.ChannelInstance.Data[13], device_info.ChannelInstance.Data[14], device_info.ChannelInstance.Data[15]); | |
212 | } | |
213 | else if (!strcmp(dev_attr->attr.name, "state")) | |
214 | { | |
215 | return sprintf(buf, "%d\n", device_info.ChannelState); | |
216 | } | |
217 | else if (!strcmp(dev_attr->attr.name, "id")) | |
218 | { | |
219 | return sprintf(buf, "%d\n", device_info.ChannelId); | |
220 | } | |
221 | else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) | |
222 | { | |
223 | return sprintf(buf, "%d\n", device_info.Outbound.InterruptMask); | |
224 | } | |
225 | else if (!strcmp(dev_attr->attr.name, "out_read_index")) | |
226 | { | |
227 | return sprintf(buf, "%d\n", device_info.Outbound.ReadIndex); | |
228 | } | |
229 | else if (!strcmp(dev_attr->attr.name, "out_write_index")) | |
230 | { | |
231 | return sprintf(buf, "%d\n", device_info.Outbound.WriteIndex); | |
232 | } | |
233 | else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) | |
234 | { | |
235 | return sprintf(buf, "%d\n", device_info.Outbound.BytesAvailToRead); | |
236 | } | |
237 | else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) | |
238 | { | |
239 | return sprintf(buf, "%d\n", device_info.Outbound.BytesAvailToWrite); | |
240 | } | |
241 | else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) | |
242 | { | |
243 | return sprintf(buf, "%d\n", device_info.Inbound.InterruptMask); | |
244 | } | |
245 | else if (!strcmp(dev_attr->attr.name, "in_read_index")) | |
246 | { | |
247 | return sprintf(buf, "%d\n", device_info.Inbound.ReadIndex); | |
248 | } | |
249 | else if (!strcmp(dev_attr->attr.name, "in_write_index")) | |
250 | { | |
251 | return sprintf(buf, "%d\n", device_info.Inbound.WriteIndex); | |
252 | } | |
253 | else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) | |
254 | { | |
255 | return sprintf(buf, "%d\n", device_info.Inbound.BytesAvailToRead); | |
256 | } | |
257 | else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) | |
258 | { | |
259 | return sprintf(buf, "%d\n", device_info.Inbound.BytesAvailToWrite); | |
260 | } | |
261 | else if (!strcmp(dev_attr->attr.name, "monitor_id")) | |
262 | { | |
263 | return sprintf(buf, "%d\n", device_info.MonitorId); | |
264 | } | |
265 | else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) | |
266 | { | |
267 | return sprintf(buf, "%d\n", device_info.ServerMonitorPending); | |
268 | } | |
269 | else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) | |
270 | { | |
271 | return sprintf(buf, "%d\n", device_info.ServerMonitorLatency); | |
272 | } | |
273 | else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) | |
274 | { | |
275 | return sprintf(buf, "%d\n", device_info.ServerMonitorConnectionId); | |
276 | } | |
277 | else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) | |
278 | { | |
279 | return sprintf(buf, "%d\n", device_info.ClientMonitorPending); | |
280 | } | |
281 | else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) | |
282 | { | |
283 | return sprintf(buf, "%d\n", device_info.ClientMonitorLatency); | |
284 | } | |
285 | else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) | |
286 | { | |
287 | return sprintf(buf, "%d\n", device_info.ClientMonitorConnectionId); | |
288 | } | |
289 | else | |
290 | { | |
291 | return 0; | |
292 | } | |
293 | } | |
294 | ||
295 | /*++ | |
296 | ||
297 | Name: vmbus_show_class_id() | |
298 | ||
299 | Desc: Show the device class id in sysfs | |
300 | ||
301 | --*/ | |
454f18a9 BP |
302 | /* static ssize_t vmbus_show_class_id(struct device *dev, struct device_attribute *attr, char *buf) */ |
303 | /* { */ | |
304 | /* struct device_context *device_ctx = device_to_device_context(dev); */ | |
305 | /* return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", */ | |
306 | /* device_ctx->class_id[3], device_ctx->class_id[2], device_ctx->class_id[1], device_ctx->class_id[0], */ | |
307 | /* device_ctx->class_id[5], device_ctx->class_id[4], */ | |
308 | /* device_ctx->class_id[7], device_ctx->class_id[6], */ | |
309 | /* device_ctx->class_id[8], device_ctx->class_id[9], device_ctx->class_id[10], device_ctx->class_id[11], device_ctx->class_id[12], device_ctx->class_id[13], device_ctx->class_id[14], device_ctx->class_id[15]); */ | |
310 | /* } */ | |
3e7ee490 HJ |
311 | |
312 | /*++ | |
313 | ||
314 | Name: vmbus_show_device_id() | |
315 | ||
316 | Desc: Show the device instance id in sysfs | |
317 | ||
318 | --*/ | |
454f18a9 BP |
319 | /* static ssize_t vmbus_show_device_id(struct device *dev, struct device_attribute *attr, char *buf) */ |
320 | /* { */ | |
321 | /* struct device_context *device_ctx = device_to_device_context(dev); */ | |
322 | /* return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", */ | |
323 | /* device_ctx->device_id[3], device_ctx->device_id[2], device_ctx->device_id[1], device_ctx->device_id[0], */ | |
324 | /* device_ctx->device_id[5], device_ctx->device_id[4], */ | |
325 | /* device_ctx->device_id[7], device_ctx->device_id[6], */ | |
326 | /* device_ctx->device_id[8], device_ctx->device_id[9], device_ctx->device_id[10], device_ctx->device_id[11], device_ctx->device_id[12], device_ctx->device_id[13], device_ctx->device_id[14], device_ctx->device_id[15]); */ | |
327 | /* } */ | |
3e7ee490 HJ |
328 | |
329 | /*++ | |
330 | ||
331 | Name: vmbus_bus_init() | |
332 | ||
333 | Desc: Main vmbus driver initialization routine. Here, we | |
334 | - initialize the vmbus driver context | |
335 | - setup various driver entry points | |
336 | - invoke the vmbus hv main init routine | |
337 | - get the irq resource | |
338 | - invoke the vmbus to add the vmbus root device | |
339 | - setup the vmbus root device | |
340 | - retrieve the channel offers | |
341 | --*/ | |
342 | int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) | |
343 | { | |
344 | int ret=0; | |
345 | unsigned int vector=0; | |
346 | ||
347 | struct vmbus_driver_context *vmbus_drv_ctx=&g_vmbus_drv; | |
348 | VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj; | |
349 | ||
350 | struct device_context *dev_ctx=&g_vmbus_drv.device_ctx; | |
351 | ||
352 | DPRINT_ENTER(VMBUS_DRV); | |
353 | ||
454f18a9 | 354 | /* Set this up to allow lower layer to callback to add/remove child devices on the bus */ |
3e7ee490 HJ |
355 | vmbus_drv_obj->OnChildDeviceCreate = vmbus_child_device_create; |
356 | vmbus_drv_obj->OnChildDeviceDestroy = vmbus_child_device_destroy; | |
357 | vmbus_drv_obj->OnChildDeviceAdd = vmbus_child_device_register; | |
358 | vmbus_drv_obj->OnChildDeviceRemove = vmbus_child_device_unregister; | |
359 | ||
454f18a9 | 360 | /* Call to bus driver to initialize */ |
3e7ee490 HJ |
361 | ret = pfn_drv_init(&vmbus_drv_obj->Base); |
362 | if (ret != 0) | |
363 | { | |
364 | DPRINT_ERR(VMBUS_DRV, "Unable to initialize vmbus (%d)", ret); | |
365 | goto cleanup; | |
366 | } | |
367 | ||
454f18a9 | 368 | /* Sanity checks */ |
3e7ee490 HJ |
369 | if (!vmbus_drv_obj->Base.OnDeviceAdd) |
370 | { | |
371 | DPRINT_ERR(VMBUS_DRV, "OnDeviceAdd() routine not set"); | |
372 | ret = -1; | |
373 | goto cleanup; | |
374 | } | |
375 | ||
376 | vmbus_drv_ctx->bus.name = vmbus_drv_obj->Base.name; | |
377 | ||
454f18a9 | 378 | /* Initialize the bus context */ |
3e7ee490 HJ |
379 | tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_msg_dpc, (unsigned long)vmbus_drv_obj); |
380 | tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_event_dpc, (unsigned long)vmbus_drv_obj); | |
381 | ||
454f18a9 | 382 | /* Now, register the bus driver with LDM */ |
c19fbca3 BP |
383 | ret = bus_register(&vmbus_drv_ctx->bus); |
384 | if (ret) | |
385 | { | |
386 | ret = -1; | |
387 | goto cleanup; | |
388 | } | |
3e7ee490 | 389 | |
454f18a9 | 390 | /* Get the interrupt resource */ |
3e7ee490 HJ |
391 | ret = request_irq(vmbus_irq, |
392 | vmbus_isr, | |
393 | IRQF_SAMPLE_RANDOM, | |
394 | vmbus_drv_obj->Base.name, | |
395 | NULL); | |
3e7ee490 HJ |
396 | |
397 | if (ret != 0) | |
398 | { | |
399 | DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d", vmbus_irq); | |
400 | ||
401 | bus_unregister(&vmbus_drv_ctx->bus); | |
402 | ||
403 | ret = -1; | |
404 | goto cleanup; | |
405 | } | |
3e7ee490 | 406 | vector = VMBUS_IRQ_VECTOR; |
3e7ee490 HJ |
407 | |
408 | DPRINT_INFO(VMBUS_DRV, "irq 0x%x vector 0x%x", vmbus_irq, vector); | |
409 | ||
454f18a9 | 410 | /* Call to bus driver to add the root device */ |
3e7ee490 HJ |
411 | memset(dev_ctx, 0, sizeof(struct device_context)); |
412 | ||
413 | ret = vmbus_drv_obj->Base.OnDeviceAdd(&dev_ctx->device_obj, &vector); | |
414 | if (ret != 0) | |
415 | { | |
416 | DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to add vmbus root device"); | |
417 | ||
418 | free_irq(vmbus_irq, NULL); | |
419 | ||
420 | bus_unregister(&vmbus_drv_ctx->bus); | |
421 | ||
422 | ret = -1; | |
423 | goto cleanup; | |
424 | } | |
454f18a9 | 425 | /* strcpy(dev_ctx->device.bus_id, dev_ctx->device_obj.name); */ |
09d50ff8 | 426 | dev_set_name(&dev_ctx->device, "vmbus_0_0"); |
3e7ee490 HJ |
427 | memcpy(&dev_ctx->class_id, &dev_ctx->device_obj.deviceType, sizeof(GUID)); |
428 | memcpy(&dev_ctx->device_id, &dev_ctx->device_obj.deviceInstance, sizeof(GUID)); | |
429 | ||
454f18a9 | 430 | /* No need to bind a driver to the root device. */ |
3e7ee490 | 431 | dev_ctx->device.parent = NULL; |
454f18a9 | 432 | dev_ctx->device.bus = &vmbus_drv_ctx->bus; /* NULL; vmbus_remove() does not get invoked */ |
3e7ee490 | 433 | |
454f18a9 | 434 | /* Setup the device dispatch table */ |
3e7ee490 HJ |
435 | dev_ctx->device.release = vmbus_bus_release; |
436 | ||
454f18a9 | 437 | /* Setup the bus as root device */ |
3e7ee490 HJ |
438 | device_register(&dev_ctx->device); |
439 | ||
440 | vmbus_drv_obj->GetChannelOffers(); | |
441 | ||
442 | cleanup: | |
443 | DPRINT_EXIT(VMBUS_DRV); | |
444 | ||
445 | return ret; | |
446 | } | |
447 | ||
448 | ||
449 | /*++ | |
450 | ||
451 | Name: vmbus_bus_exit() | |
452 | ||
453 | Desc: Terminate the vmbus driver. This routine is opposite of vmbus_bus_init() | |
454 | ||
455 | --*/ | |
456 | void vmbus_bus_exit(void) | |
457 | { | |
458 | VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj; | |
459 | struct vmbus_driver_context *vmbus_drv_ctx=&g_vmbus_drv; | |
460 | ||
461 | struct device_context *dev_ctx=&g_vmbus_drv.device_ctx; | |
462 | ||
463 | DPRINT_ENTER(VMBUS_DRV); | |
464 | ||
454f18a9 | 465 | /* Remove the root device */ |
3e7ee490 HJ |
466 | if (vmbus_drv_obj->Base.OnDeviceRemove) |
467 | vmbus_drv_obj->Base.OnDeviceRemove(&dev_ctx->device_obj); | |
468 | ||
469 | if (vmbus_drv_obj->Base.OnCleanup) | |
470 | vmbus_drv_obj->Base.OnCleanup(&vmbus_drv_obj->Base); | |
471 | ||
454f18a9 | 472 | /* Unregister the root bus device */ |
3e7ee490 HJ |
473 | device_unregister(&dev_ctx->device); |
474 | ||
475 | bus_unregister(&vmbus_drv_ctx->bus); | |
476 | ||
477 | free_irq(vmbus_irq, NULL); | |
478 | ||
479 | tasklet_kill(&vmbus_drv_ctx->msg_dpc); | |
480 | tasklet_kill(&vmbus_drv_ctx->event_dpc); | |
481 | ||
482 | DPRINT_EXIT(VMBUS_DRV); | |
483 | ||
484 | return; | |
485 | } | |
486 | ||
487 | /*++ | |
488 | ||
489 | Name: vmbus_child_driver_register() | |
490 | ||
491 | Desc: Register a vmbus's child driver | |
492 | ||
493 | --*/ | |
494 | void vmbus_child_driver_register(struct driver_context* driver_ctx) | |
495 | { | |
496 | VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj; | |
497 | ||
498 | DPRINT_ENTER(VMBUS_DRV); | |
499 | ||
500 | DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s", driver_ctx, driver_ctx->driver.name); | |
501 | ||
454f18a9 | 502 | /* The child driver on this vmbus */ |
3e7ee490 HJ |
503 | driver_ctx->driver.bus = &g_vmbus_drv.bus; |
504 | ||
505 | driver_register(&driver_ctx->driver); | |
506 | ||
507 | vmbus_drv_obj->GetChannelOffers(); | |
508 | ||
509 | DPRINT_EXIT(VMBUS_DRV); | |
510 | } | |
511 | ||
512 | EXPORT_SYMBOL(vmbus_child_driver_register); | |
513 | ||
514 | /*++ | |
515 | ||
516 | Name: vmbus_child_driver_unregister() | |
517 | ||
518 | Desc: Unregister a vmbus's child driver | |
519 | ||
520 | --*/ | |
521 | void vmbus_child_driver_unregister(struct driver_context* driver_ctx) | |
522 | { | |
523 | DPRINT_ENTER(VMBUS_DRV); | |
524 | ||
525 | DPRINT_INFO(VMBUS_DRV, "child driver (%p) unregistering - name %s", driver_ctx, driver_ctx->driver.name); | |
526 | ||
527 | driver_unregister(&driver_ctx->driver); | |
528 | ||
529 | driver_ctx->driver.bus = NULL; | |
530 | ||
531 | DPRINT_EXIT(VMBUS_DRV); | |
532 | } | |
533 | ||
534 | EXPORT_SYMBOL(vmbus_child_driver_unregister); | |
535 | ||
536 | /*++ | |
537 | ||
538 | Name: vmbus_get_interface() | |
539 | ||
540 | Desc: Get the vmbus channel interface. This is invoked by child/client driver that sits | |
541 | above vmbus | |
542 | --*/ | |
543 | void vmbus_get_interface(VMBUS_CHANNEL_INTERFACE *interface) | |
544 | { | |
545 | VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj; | |
546 | ||
547 | vmbus_drv_obj->GetChannelInterface(interface); | |
548 | } | |
549 | ||
550 | EXPORT_SYMBOL(vmbus_get_interface); | |
551 | ||
552 | ||
553 | /*++ | |
554 | ||
555 | Name: vmbus_child_device_get_info() | |
556 | ||
557 | Desc: Get the vmbus child device info. This is invoked to display various device attributes in sysfs. | |
558 | --*/ | |
559 | static void vmbus_child_device_get_info(DEVICE_OBJECT *device_obj, DEVICE_INFO *device_info) | |
560 | { | |
561 | VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj; | |
562 | ||
563 | vmbus_drv_obj->GetChannelInfo(device_obj, device_info); | |
564 | } | |
565 | ||
566 | ||
567 | /*++ | |
568 | ||
569 | Name: vmbus_child_device_create() | |
570 | ||
571 | Desc: Creates and registers a new child device on the vmbus. | |
572 | ||
573 | --*/ | |
574 | static DEVICE_OBJECT* vmbus_child_device_create(GUID type, GUID instance, void* context) | |
575 | { | |
576 | struct device_context *child_device_ctx; | |
577 | DEVICE_OBJECT* child_device_obj; | |
578 | ||
579 | DPRINT_ENTER(VMBUS_DRV); | |
580 | ||
454f18a9 | 581 | /* Allocate the new child device */ |
3e7ee490 HJ |
582 | child_device_ctx = kzalloc(sizeof(struct device_context), GFP_KERNEL); |
583 | if (!child_device_ctx) | |
584 | { | |
585 | DPRINT_ERR(VMBUS_DRV, "unable to allocate device_context for child device"); | |
586 | DPRINT_EXIT(VMBUS_DRV); | |
587 | ||
588 | return NULL; | |
589 | } | |
590 | ||
591 | DPRINT_DBG(VMBUS_DRV, "child device (%p) allocated - " | |
592 | "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}," | |
593 | "id {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", | |
594 | &child_device_ctx->device, | |
595 | type.Data[3], type.Data[2], type.Data[1], type.Data[0], type.Data[5], type.Data[4], type.Data[7], type.Data[6], type.Data[8], type.Data[9], type.Data[10], type.Data[11], type.Data[12], type.Data[13], type.Data[14], type.Data[15], | |
596 | instance.Data[3], instance.Data[2], instance.Data[1], instance.Data[0], instance.Data[5], instance.Data[4], instance.Data[7], instance.Data[6], instance.Data[8], instance.Data[9], instance.Data[10], instance.Data[11], instance.Data[12], instance.Data[13], instance.Data[14], instance.Data[15]); | |
597 | ||
598 | child_device_obj = &child_device_ctx->device_obj; | |
599 | child_device_obj->context = context; | |
600 | memcpy(&child_device_obj->deviceType, &type, sizeof(GUID)); | |
601 | memcpy(&child_device_obj->deviceInstance, &instance, sizeof(GUID)); | |
602 | ||
603 | memcpy(&child_device_ctx->class_id, &type, sizeof(GUID)); | |
604 | memcpy(&child_device_ctx->device_id, &instance, sizeof(GUID)); | |
605 | ||
606 | DPRINT_EXIT(VMBUS_DRV); | |
607 | ||
608 | return child_device_obj; | |
609 | } | |
610 | ||
611 | /*++ | |
612 | ||
613 | Name: vmbus_child_device_register() | |
614 | ||
615 | Desc: Register the child device on the specified bus | |
616 | ||
617 | --*/ | |
618 | static int vmbus_child_device_register(DEVICE_OBJECT* root_device_obj, DEVICE_OBJECT* child_device_obj) | |
619 | { | |
620 | int ret=0; | |
621 | struct device_context *root_device_ctx = to_device_context(root_device_obj); | |
622 | struct device_context *child_device_ctx = to_device_context(child_device_obj); | |
623 | static int device_num=0; | |
624 | ||
625 | DPRINT_ENTER(VMBUS_DRV); | |
626 | ||
627 | DPRINT_DBG(VMBUS_DRV, "child device (%p) registering", child_device_ctx); | |
454f18a9 BP |
628 | |
629 | /* Make sure we are not registered already */ | |
630 | ||
09d50ff8 | 631 | if (strlen(dev_name(&child_device_ctx->device)) != 0) |
3e7ee490 | 632 | { |
09d50ff8 | 633 | DPRINT_ERR(VMBUS_DRV, "child device (%p) already registered - busid %s", child_device_ctx, dev_name(&child_device_ctx->device)); |
3e7ee490 HJ |
634 | |
635 | ret = -1; | |
636 | goto Cleanup; | |
637 | } | |
638 | ||
454f18a9 | 639 | /* Set the device bus id. Otherwise, device_register()will fail. */ |
09d50ff8 | 640 | dev_set_name(&child_device_ctx->device, "vmbus_0_%d", InterlockedIncrement(&device_num)); |
3e7ee490 | 641 | |
454f18a9 BP |
642 | /* The new device belongs to this bus */ |
643 | child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */ | |
3e7ee490 HJ |
644 | child_device_ctx->device.parent = &root_device_ctx->device; |
645 | child_device_ctx->device.release = vmbus_device_release; | |
646 | ||
454f18a9 BP |
647 | /* Register with the LDM. This will kick off the driver/device binding...which will */ |
648 | /* eventually call vmbus_match() and vmbus_probe() */ | |
3e7ee490 HJ |
649 | ret = device_register(&child_device_ctx->device); |
650 | ||
454f18a9 | 651 | /* vmbus_probe() error does not get propergate to device_register(). */ |
3e7ee490 HJ |
652 | ret = child_device_ctx->probe_error; |
653 | ||
654 | if (ret) | |
b2aba7cc | 655 | DPRINT_ERR(VMBUS_DRV, "unable to register child device (%p)", &child_device_ctx->device); |
3e7ee490 HJ |
656 | else |
657 | DPRINT_INFO(VMBUS_DRV, "child device (%p) registered", &child_device_ctx->device); | |
658 | ||
659 | Cleanup: | |
660 | DPRINT_EXIT(VMBUS_DRV); | |
661 | ||
662 | return ret; | |
663 | } | |
664 | ||
665 | /*++ | |
666 | ||
667 | Name: vmbus_child_device_unregister() | |
668 | ||
669 | Desc: Remove the specified child device from the vmbus. | |
670 | ||
671 | --*/ | |
672 | static void vmbus_child_device_unregister(DEVICE_OBJECT* device_obj) | |
673 | { | |
674 | struct device_context *device_ctx = to_device_context(device_obj); | |
675 | ||
676 | DPRINT_ENTER(VMBUS_DRV); | |
677 | ||
678 | DPRINT_INFO(VMBUS_DRV, "unregistering child device (%p)", &device_ctx->device); | |
679 | ||
454f18a9 BP |
680 | /* Kick off the process of unregistering the device. */ |
681 | /* This will call vmbus_remove() and eventually vmbus_device_release() */ | |
3e7ee490 HJ |
682 | device_unregister(&device_ctx->device); |
683 | ||
684 | DPRINT_INFO(VMBUS_DRV, "child device (%p) unregistered", &device_ctx->device); | |
685 | ||
686 | DPRINT_EXIT(VMBUS_DRV); | |
687 | } | |
688 | ||
689 | ||
690 | /*++ | |
691 | ||
692 | Name: vmbus_child_device_destroy() | |
693 | ||
694 | Desc: Destroy the specified child device on the vmbus. | |
695 | ||
696 | --*/ | |
697 | static void vmbus_child_device_destroy(DEVICE_OBJECT* device_obj) | |
698 | { | |
699 | DPRINT_ENTER(VMBUS_DRV); | |
700 | ||
701 | DPRINT_EXIT(VMBUS_DRV); | |
702 | } | |
703 | ||
704 | /*++ | |
705 | ||
706 | Name: vmbus_uevent() | |
707 | ||
708 | Desc: This routine is invoked when a device is added or removed on the vmbus to generate a uevent to udev in the | |
709 | userspace. The udev will then look at its rule and the uevent generated here to load the appropriate driver | |
710 | ||
711 | --*/ | |
3e7ee490 HJ |
712 | static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) |
713 | { | |
714 | struct device_context *device_ctx = device_to_device_context(device); | |
715 | int i=0; | |
716 | int len=0; | |
717 | int ret; | |
718 | ||
719 | DPRINT_ENTER(VMBUS_DRV); | |
720 | ||
721 | DPRINT_INFO(VMBUS_DRV, "generating uevent - VMBUS_DEVICE_CLASS_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", | |
722 | device_ctx->class_id.Data[3], device_ctx->class_id.Data[2], device_ctx->class_id.Data[1], device_ctx->class_id.Data[0], | |
723 | device_ctx->class_id.Data[5], device_ctx->class_id.Data[4], | |
724 | device_ctx->class_id.Data[7], device_ctx->class_id.Data[6], | |
725 | device_ctx->class_id.Data[8], device_ctx->class_id.Data[9], device_ctx->class_id.Data[10], device_ctx->class_id.Data[11], | |
726 | device_ctx->class_id.Data[12], device_ctx->class_id.Data[13], device_ctx->class_id.Data[14], device_ctx->class_id.Data[15]); | |
727 | ||
728 | env->envp_idx = i; | |
729 | env->buflen = len; | |
730 | ret = add_uevent_var(env, | |
731 | "VMBUS_DEVICE_CLASS_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", | |
732 | device_ctx->class_id.Data[3], device_ctx->class_id.Data[2], device_ctx->class_id.Data[1], device_ctx->class_id.Data[0], | |
733 | device_ctx->class_id.Data[5], device_ctx->class_id.Data[4], | |
734 | device_ctx->class_id.Data[7], device_ctx->class_id.Data[6], | |
735 | device_ctx->class_id.Data[8], device_ctx->class_id.Data[9], device_ctx->class_id.Data[10], device_ctx->class_id.Data[11], | |
736 | device_ctx->class_id.Data[12], device_ctx->class_id.Data[13], device_ctx->class_id.Data[14], device_ctx->class_id.Data[15]); | |
737 | ||
738 | if (ret) | |
739 | { | |
740 | return ret; | |
741 | } | |
742 | ||
743 | ret = add_uevent_var(env, | |
744 | "VMBUS_DEVICE_DEVICE_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", | |
745 | device_ctx->device_id.Data[3], device_ctx->device_id.Data[2], device_ctx->device_id.Data[1], device_ctx->device_id.Data[0], | |
746 | device_ctx->device_id.Data[5], device_ctx->device_id.Data[4], | |
747 | device_ctx->device_id.Data[7], device_ctx->device_id.Data[6], | |
748 | device_ctx->device_id.Data[8], device_ctx->device_id.Data[9], device_ctx->device_id.Data[10], device_ctx->device_id.Data[11], | |
749 | device_ctx->device_id.Data[12], device_ctx->device_id.Data[13], device_ctx->device_id.Data[14], device_ctx->device_id.Data[15]); | |
750 | ||
751 | if (ret) | |
752 | { | |
753 | return ret; | |
754 | } | |
755 | ||
756 | env->envp[env->envp_idx] = NULL; | |
757 | ||
758 | DPRINT_EXIT(VMBUS_DRV); | |
759 | ||
760 | return 0; | |
761 | } | |
762 | ||
3e7ee490 HJ |
763 | /*++ |
764 | ||
765 | Name: vmbus_match() | |
766 | ||
767 | Desc: Attempt to match the specified device to the specified driver | |
768 | ||
769 | --*/ | |
770 | static int vmbus_match(struct device *device, struct device_driver *driver) | |
771 | { | |
772 | int match=0; | |
773 | struct driver_context *driver_ctx = driver_to_driver_context(driver); | |
774 | struct device_context *device_ctx = device_to_device_context(device); | |
775 | ||
776 | DPRINT_ENTER(VMBUS_DRV); | |
777 | ||
454f18a9 | 778 | /* We found our driver ? */ |
3e7ee490 HJ |
779 | if (memcmp(&device_ctx->class_id, &driver_ctx->class_id, sizeof(GUID)) == 0) |
780 | { | |
454f18a9 BP |
781 | /* !! NOTE: The driver_ctx is not a vmbus_drv_ctx. We typecast it here to access the */ |
782 | /* DRIVER_OBJECT field */ | |
3e7ee490 HJ |
783 | struct vmbus_driver_context *vmbus_drv_ctx = (struct vmbus_driver_context*)driver_ctx; |
784 | device_ctx->device_obj.Driver = &vmbus_drv_ctx->drv_obj.Base; | |
785 | DPRINT_INFO(VMBUS_DRV, "device object (%p) set to driver object (%p)", &device_ctx->device_obj, device_ctx->device_obj.Driver); | |
786 | ||
787 | match = 1; | |
788 | } | |
789 | ||
790 | DPRINT_EXIT(VMBUS_DRV); | |
791 | ||
792 | return match; | |
793 | } | |
794 | ||
795 | ||
796 | /*++ | |
797 | ||
798 | Name: vmbus_probe_failed_cb() | |
799 | ||
800 | Desc: Callback when a driver probe failed in vmbus_probe(). We need a callback because | |
801 | we cannot invoked device_unregister() inside vmbus_probe() since vmbus_probe() may be | |
802 | invoked inside device_register() i.e. we cannot call device_unregister() inside | |
803 | device_register() | |
804 | --*/ | |
3e7ee490 | 805 | static void vmbus_probe_failed_cb(struct work_struct *context) |
3e7ee490 HJ |
806 | { |
807 | struct device_context *device_ctx = (struct device_context*)context; | |
808 | ||
809 | ||
810 | DPRINT_ENTER(VMBUS_DRV); | |
811 | ||
454f18a9 BP |
812 | /* Kick off the process of unregistering the device. */ |
813 | /* This will call vmbus_remove() and eventually vmbus_device_release() */ | |
3e7ee490 HJ |
814 | device_unregister(&device_ctx->device); |
815 | ||
454f18a9 | 816 | /* put_device(&device_ctx->device); */ |
3e7ee490 HJ |
817 | DPRINT_EXIT(VMBUS_DRV); |
818 | } | |
819 | ||
820 | ||
821 | /*++ | |
822 | ||
823 | Name: vmbus_probe() | |
824 | ||
825 | Desc: Add the new vmbus's child device | |
826 | ||
827 | --*/ | |
828 | static int vmbus_probe(struct device *child_device) | |
829 | { | |
830 | int ret=0; | |
831 | struct driver_context *driver_ctx = driver_to_driver_context(child_device->driver); | |
832 | struct device_context *device_ctx = device_to_device_context(child_device); | |
833 | ||
834 | DPRINT_ENTER(VMBUS_DRV); | |
835 | ||
454f18a9 | 836 | /* Let the specific open-source driver handles the probe if it can */ |
3e7ee490 HJ |
837 | if (driver_ctx->probe) |
838 | { | |
839 | ret = device_ctx->probe_error = driver_ctx->probe(child_device); | |
840 | if (ret != 0) | |
841 | { | |
09d50ff8 | 842 | DPRINT_ERR(VMBUS_DRV, "probe() failed for device %s (%p) on driver %s (%d)...", dev_name(child_device), child_device, child_device->driver->name, ret); |
3e7ee490 | 843 | |
3e7ee490 | 844 | INIT_WORK(&device_ctx->probe_failed_work_item, vmbus_probe_failed_cb); |
3e7ee490 HJ |
845 | schedule_work(&device_ctx->probe_failed_work_item); |
846 | } | |
847 | } | |
848 | else | |
849 | { | |
850 | DPRINT_ERR(VMBUS_DRV, "probe() method not set for driver - %s", child_device->driver->name); | |
851 | ret = -1; | |
852 | } | |
853 | ||
854 | DPRINT_EXIT(VMBUS_DRV); | |
855 | return ret; | |
856 | } | |
857 | ||
858 | ||
859 | /*++ | |
860 | ||
861 | Name: vmbus_remove() | |
862 | ||
863 | Desc: Remove a vmbus device | |
864 | ||
865 | --*/ | |
866 | static int vmbus_remove(struct device *child_device) | |
867 | { | |
868 | int ret=0; | |
869 | struct driver_context *driver_ctx; | |
870 | ||
871 | DPRINT_ENTER(VMBUS_DRV); | |
872 | ||
454f18a9 | 873 | /* Special case root bus device */ |
3e7ee490 HJ |
874 | if (child_device->parent == NULL) |
875 | { | |
454f18a9 | 876 | /* No-op since it is statically defined and handle in vmbus_bus_exit() */ |
3e7ee490 HJ |
877 | DPRINT_EXIT(VMBUS_DRV); |
878 | return 0; | |
879 | } | |
880 | ||
881 | if (child_device->driver) | |
882 | { | |
883 | driver_ctx = driver_to_driver_context(child_device->driver); | |
884 | ||
454f18a9 | 885 | /* Let the specific open-source driver handles the removal if it can */ |
3e7ee490 HJ |
886 | if (driver_ctx->remove) |
887 | { | |
888 | ret = driver_ctx->remove(child_device); | |
889 | } | |
890 | else | |
891 | { | |
892 | DPRINT_ERR(VMBUS_DRV, "remove() method not set for driver - %s", child_device->driver->name); | |
893 | ret = -1; | |
894 | } | |
895 | } | |
896 | else | |
897 | { | |
898 | ||
899 | } | |
900 | ||
901 | DPRINT_EXIT(VMBUS_DRV); | |
902 | ||
903 | return 0; | |
904 | } | |
905 | ||
906 | /*++ | |
907 | ||
908 | Name: vmbus_shutdown() | |
909 | ||
910 | Desc: Shutdown a vmbus device | |
911 | ||
912 | --*/ | |
913 | static void vmbus_shutdown(struct device *child_device) | |
914 | { | |
915 | struct driver_context *driver_ctx; | |
916 | ||
917 | DPRINT_ENTER(VMBUS_DRV); | |
918 | ||
454f18a9 | 919 | /* Special case root bus device */ |
3e7ee490 HJ |
920 | if (child_device->parent == NULL) |
921 | { | |
454f18a9 | 922 | /* No-op since it is statically defined and handle in vmbus_bus_exit() */ |
3e7ee490 HJ |
923 | DPRINT_EXIT(VMBUS_DRV); |
924 | return; | |
925 | } | |
926 | ||
454f18a9 | 927 | /* The device may not be attached yet */ |
3e7ee490 HJ |
928 | if (!child_device->driver) |
929 | { | |
930 | DPRINT_EXIT(VMBUS_DRV); | |
931 | return; | |
932 | } | |
933 | ||
934 | driver_ctx = driver_to_driver_context(child_device->driver); | |
935 | ||
454f18a9 | 936 | /* Let the specific open-source driver handles the removal if it can */ |
3e7ee490 HJ |
937 | if (driver_ctx->shutdown) |
938 | { | |
939 | driver_ctx->shutdown(child_device); | |
940 | } | |
941 | ||
942 | DPRINT_EXIT(VMBUS_DRV); | |
943 | ||
944 | return; | |
945 | } | |
946 | ||
947 | /*++ | |
948 | ||
949 | Name: vmbus_bus_release() | |
950 | ||
951 | Desc: Final callback release of the vmbus root device | |
952 | ||
953 | --*/ | |
954 | static void vmbus_bus_release(struct device *device) | |
955 | { | |
956 | DPRINT_ENTER(VMBUS_DRV); | |
957 | DPRINT_EXIT(VMBUS_DRV); | |
958 | } | |
959 | ||
960 | /*++ | |
961 | ||
962 | Name: vmbus_device_release() | |
963 | ||
964 | Desc: Final callback release of the vmbus child device | |
965 | ||
966 | --*/ | |
967 | static void vmbus_device_release(struct device *device) | |
968 | { | |
969 | struct device_context *device_ctx = device_to_device_context(device); | |
970 | ||
971 | DPRINT_ENTER(VMBUS_DRV); | |
972 | ||
454f18a9 | 973 | /* vmbus_child_device_destroy(&device_ctx->device_obj); */ |
3e7ee490 HJ |
974 | kfree(device_ctx); |
975 | ||
454f18a9 | 976 | /* !!DO NOT REFERENCE device_ctx anymore at this point!! */ |
3e7ee490 HJ |
977 | |
978 | DPRINT_EXIT(VMBUS_DRV); | |
979 | ||
980 | return; | |
981 | } | |
982 | ||
983 | /*++ | |
984 | ||
985 | Name: vmbus_msg_dpc() | |
986 | ||
987 | Desc: Tasklet routine to handle hypervisor messages | |
988 | ||
989 | --*/ | |
990 | static void vmbus_msg_dpc(unsigned long data) | |
991 | { | |
992 | VMBUS_DRIVER_OBJECT* vmbus_drv_obj = (VMBUS_DRIVER_OBJECT*)data; | |
993 | ||
994 | DPRINT_ENTER(VMBUS_DRV); | |
995 | ||
996 | ASSERT(vmbus_drv_obj->OnMsgDpc != NULL); | |
997 | ||
454f18a9 | 998 | /* Call to bus driver to handle interrupt */ |
3e7ee490 HJ |
999 | vmbus_drv_obj->OnMsgDpc(&vmbus_drv_obj->Base); |
1000 | ||
1001 | DPRINT_EXIT(VMBUS_DRV); | |
1002 | } | |
1003 | ||
1004 | /*++ | |
1005 | ||
1006 | Name: vmbus_msg_dpc() | |
1007 | ||
1008 | Desc: Tasklet routine to handle hypervisor events | |
1009 | ||
1010 | --*/ | |
1011 | static void vmbus_event_dpc(unsigned long data) | |
1012 | { | |
1013 | VMBUS_DRIVER_OBJECT* vmbus_drv_obj = (VMBUS_DRIVER_OBJECT*)data; | |
1014 | ||
1015 | DPRINT_ENTER(VMBUS_DRV); | |
1016 | ||
1017 | ASSERT(vmbus_drv_obj->OnEventDpc != NULL); | |
1018 | ||
454f18a9 | 1019 | /* Call to bus driver to handle interrupt */ |
3e7ee490 HJ |
1020 | vmbus_drv_obj->OnEventDpc(&vmbus_drv_obj->Base); |
1021 | ||
1022 | DPRINT_EXIT(VMBUS_DRV); | |
1023 | } | |
1024 | ||
1025 | /*++ | |
1026 | ||
1027 | Name: vmbus_msg_dpc() | |
1028 | ||
1029 | Desc: ISR routine | |
1030 | ||
1031 | --*/ | |
3e7ee490 | 1032 | static irqreturn_t vmbus_isr(int irq, void* dev_id) |
3e7ee490 HJ |
1033 | { |
1034 | int ret=0; | |
1035 | VMBUS_DRIVER_OBJECT* vmbus_driver_obj = &g_vmbus_drv.drv_obj; | |
1036 | ||
1037 | DPRINT_ENTER(VMBUS_DRV); | |
1038 | ||
1039 | ASSERT(vmbus_driver_obj->OnIsr != NULL); | |
1040 | ||
454f18a9 | 1041 | /* Call to bus driver to handle interrupt */ |
3e7ee490 HJ |
1042 | ret = vmbus_driver_obj->OnIsr(&vmbus_driver_obj->Base); |
1043 | ||
454f18a9 | 1044 | /* Schedules a dpc if necessary */ |
3e7ee490 HJ |
1045 | if (ret > 0) |
1046 | { | |
1047 | if (test_bit(0, (unsigned long*)&ret)) | |
1048 | { | |
1049 | tasklet_schedule(&g_vmbus_drv.msg_dpc); | |
1050 | } | |
1051 | ||
1052 | if (test_bit(1, (unsigned long*)&ret)) | |
1053 | { | |
1054 | tasklet_schedule(&g_vmbus_drv.event_dpc); | |
1055 | } | |
1056 | ||
1057 | DPRINT_EXIT(VMBUS_DRV); | |
1058 | return IRQ_HANDLED; | |
1059 | } | |
1060 | else | |
1061 | { | |
1062 | DPRINT_EXIT(VMBUS_DRV); | |
1063 | return IRQ_NONE; | |
1064 | } | |
1065 | } | |
1066 | ||
1067 | MODULE_LICENSE("GPL"); | |
1068 | ||
1069 | ||
1070 | /*++ | |
1071 | ||
1072 | Name: vmbus_init() | |
1073 | ||
1074 | Desc: Main vmbus driver entry routine | |
1075 | ||
1076 | --*/ | |
1077 | static int __init vmbus_init(void) | |
1078 | { | |
1079 | int ret=0; | |
1080 | ||
1081 | DPRINT_ENTER(VMBUS_DRV); | |
1082 | ||
1083 | DPRINT_INFO(VMBUS_DRV, | |
1084 | "Vmbus initializing.... current log level 0x%x (%x,%x)", | |
1085 | vmbus_loglevel, HIWORD(vmbus_loglevel), LOWORD(vmbus_loglevel)); | |
454f18a9 | 1086 | /* Todo: it is used for loglevel, to be ported to new kernel. */ |
3e7ee490 HJ |
1087 | |
1088 | ret = vmbus_bus_init(VmbusInitialize); | |
1089 | ||
1090 | DPRINT_EXIT(VMBUS_DRV); | |
1091 | return ret; | |
1092 | } | |
1093 | ||
1094 | ||
1095 | ||
1096 | /*++ | |
1097 | ||
1098 | Name: vmbus_init() | |
1099 | ||
1100 | Desc: Main vmbus driver exit routine | |
1101 | ||
1102 | --*/ | |
1103 | static void __exit vmbus_exit(void) | |
1104 | { | |
1105 | DPRINT_ENTER(VMBUS_DRV); | |
1106 | ||
1107 | vmbus_bus_exit(); | |
454f18a9 | 1108 | /* Todo: it is used for loglevel, to be ported to new kernel. */ |
3e7ee490 HJ |
1109 | DPRINT_EXIT(VMBUS_DRV); |
1110 | ||
1111 | return; | |
1112 | } | |
1113 | ||
3e7ee490 HJ |
1114 | module_param(vmbus_irq, int, S_IRUGO); |
1115 | module_param(vmbus_loglevel, int, S_IRUGO); | |
3e7ee490 HJ |
1116 | |
1117 | module_init(vmbus_init); | |
1118 | module_exit(vmbus_exit); | |
454f18a9 | 1119 | /* eof */ |