Deleted Added
full compact
hv_util.c (255524) hv_util.c (271493)
1/*-
1/*-
2 * Copyright (c) 2009-2012 Microsoft Corp.
3 * Copyright (c) 2012 NetApp Inc.
4 * Copyright (c) 2012 Citrix Inc.
2 * Copyright (c) 2014 Microsoft Corp.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
12 * disclaimer.

--- 6 unchanged lines hidden (view full) ---

19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
10 * disclaimer.

--- 6 unchanged lines hidden (view full) ---

17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/hyperv/utilities/hv_util.c 271493 2014-09-13 02:15:31Z delphij $
27 */
28
27 */
28
29/**
29/*
30 * A common driver for all hyper-V util services.
31 */
32
33#include <sys/param.h>
34#include <sys/kernel.h>
35#include <sys/bus.h>
36#include <sys/malloc.h>
37#include <sys/module.h>

--- 10 unchanged lines hidden (view full) ---

48} time_sync_data;
49
50static void hv_shutdown_cb(void *context);
51static void hv_heartbeat_cb(void *context);
52static void hv_timesync_cb(void *context);
53
54static int hv_timesync_init(hv_vmbus_service *serv);
55
30 * A common driver for all hyper-V util services.
31 */
32
33#include <sys/param.h>
34#include <sys/kernel.h>
35#include <sys/bus.h>
36#include <sys/malloc.h>
37#include <sys/module.h>

--- 10 unchanged lines hidden (view full) ---

48} time_sync_data;
49
50static void hv_shutdown_cb(void *context);
51static void hv_heartbeat_cb(void *context);
52static void hv_timesync_cb(void *context);
53
54static int hv_timesync_init(hv_vmbus_service *serv);
55
56/**
56/*
57 * Note: GUID codes below are predefined by the host hypervisor
58 * (Hyper-V and Azure)interface and required for correct operation.
59 */
60hv_vmbus_service service_table[] = {
61 /* Shutdown Service */
62 { .guid.data = {0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49,
63 0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB},
64 .name = "Hyper-V Shutdown Service\n",

--- 10 unchanged lines hidden (view full) ---

75 .callback = hv_timesync_cb,
76 },
77
78 /* Heartbeat Service */
79 { .guid.data = {0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
80 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d},
81 .name = "Hyper-V Heartbeat Service\n",
82 .enabled = TRUE,
57 * Note: GUID codes below are predefined by the host hypervisor
58 * (Hyper-V and Azure)interface and required for correct operation.
59 */
60hv_vmbus_service service_table[] = {
61 /* Shutdown Service */
62 { .guid.data = {0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49,
63 0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB},
64 .name = "Hyper-V Shutdown Service\n",

--- 10 unchanged lines hidden (view full) ---

75 .callback = hv_timesync_cb,
76 },
77
78 /* Heartbeat Service */
79 { .guid.data = {0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
80 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d},
81 .name = "Hyper-V Heartbeat Service\n",
82 .enabled = TRUE,
83 .callback = hv_heartbeat_cb,
83 .callback = hv_heartbeat_cb,
84 },
84 },
85
86 /* KVP (Key Value Pair) Service */
87 { .guid.data = {0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d,
88 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6},
89 .name = "Hyper-V KVP Service\n",
90 .enabled = TRUE,
91 .init = hv_kvp_init,
92 .callback = hv_kvp_callback,
93 },
85};
86
87/*
88 * Receive buffer pointers. There is one buffer per utility service. The
89 * buffer is allocated during attach().
90 */
91uint8_t *receive_buffer[HV_MAX_UTIL_SERVICES];
92
94};
95
96/*
97 * Receive buffer pointers. There is one buffer per utility service. The
98 * buffer is allocated during attach().
99 */
100uint8_t *receive_buffer[HV_MAX_UTIL_SERVICES];
101
102static boolean_t destroyed_kvp = FALSE;
103
93struct hv_ictimesync_data {
94 uint64_t parenttime;
95 uint64_t childtime;
96 uint64_t roundtriptime;
97 uint8_t flags;
98} __packed;
99
100static int

--- 37 unchanged lines hidden (view full) ---

138
139
140/**
141 * Set host time based on time sync message from host
142 */
143static void
144hv_set_host_time(void *context)
145{
104struct hv_ictimesync_data {
105 uint64_t parenttime;
106 uint64_t childtime;
107 uint64_t roundtriptime;
108 uint8_t flags;
109} __packed;
110
111static int

--- 37 unchanged lines hidden (view full) ---

149
150
151/**
152 * Set host time based on time sync message from host
153 */
154static void
155hv_set_host_time(void *context)
156{
146 time_sync_data *time_msg = context;
157 time_sync_data* time_msg = (time_sync_data*) context;
147 uint64_t hosttime = time_msg->data;
148 struct timespec guest_ts, host_ts;
149 uint64_t host_tns;
150 int64_t diff;
151 int error;
152
153 host_tns = (hosttime - HV_WLTIMEDELTA) * 100;
154 host_ts.tv_sec = (time_t)(host_tns/HV_NANO_SEC_PER_SEC);

--- 93 unchanged lines hidden (view full) ---

248}
249
250/**
251 * Shutdown
252 */
253static void
254hv_shutdown_cb(void *context)
255{
158 uint64_t hosttime = time_msg->data;
159 struct timespec guest_ts, host_ts;
160 uint64_t host_tns;
161 int64_t diff;
162 int error;
163
164 host_tns = (hosttime - HV_WLTIMEDELTA) * 100;
165 host_ts.tv_sec = (time_t)(host_tns/HV_NANO_SEC_PER_SEC);

--- 93 unchanged lines hidden (view full) ---

259}
260
261/**
262 * Shutdown
263 */
264static void
265hv_shutdown_cb(void *context)
266{
256 uint8_t* buf;
267 uint8_t* buf;
257 hv_vmbus_channel* channel = context;
268 hv_vmbus_channel* channel = context;
258 uint8_t execute_shutdown = 0;
269 uint8_t execute_shutdown = 0;
259 hv_vmbus_icmsg_hdr* icmsghdrp;
270 hv_vmbus_icmsg_hdr* icmsghdrp;
260 uint32_t recv_len;
261 uint64_t request_id;
271 uint32_t recv_len;
272 uint64_t request_id;
262 int ret;
263 hv_vmbus_shutdown_msg_data* shutdown_msg;
264
265 buf = receive_buffer[HV_SHUT_DOWN];
266
267 ret = hv_vmbus_channel_recv_packet(channel, buf, PAGE_SIZE,
268 &recv_len, &request_id);
269

--- 146 unchanged lines hidden (view full) ---

416
417static int
418hv_util_detach(device_t dev)
419{
420 struct hv_device* hv_dev;
421 struct hv_vmbus_service* service;
422 size_t receive_buffer_offset;
423
273 int ret;
274 hv_vmbus_shutdown_msg_data* shutdown_msg;
275
276 buf = receive_buffer[HV_SHUT_DOWN];
277
278 ret = hv_vmbus_channel_recv_packet(channel, buf, PAGE_SIZE,
279 &recv_len, &request_id);
280

--- 146 unchanged lines hidden (view full) ---

427
428static int
429hv_util_detach(device_t dev)
430{
431 struct hv_device* hv_dev;
432 struct hv_vmbus_service* service;
433 size_t receive_buffer_offset;
434
435 if (!destroyed_kvp) {
436 hv_kvp_deinit();
437 destroyed_kvp = TRUE;
438 }
439
424 hv_dev = vmbus_get_devctx(dev);
425
426 hv_vmbus_channel_close(hv_dev->channel);
427 service = device_get_softc(dev);
428 receive_buffer_offset = service - &service_table[0];
429
430 if (service->work_queue != NULL)
431 hv_work_queue_close(service->work_queue);
432
433 free(receive_buffer[receive_buffer_offset], M_DEVBUF);
434 receive_buffer[receive_buffer_offset] = NULL;
440 hv_dev = vmbus_get_devctx(dev);
441
442 hv_vmbus_channel_close(hv_dev->channel);
443 service = device_get_softc(dev);
444 receive_buffer_offset = service - &service_table[0];
445
446 if (service->work_queue != NULL)
447 hv_work_queue_close(service->work_queue);
448
449 free(receive_buffer[receive_buffer_offset], M_DEVBUF);
450 receive_buffer[receive_buffer_offset] = NULL;
435
436 return (0);
437}
438
451 return (0);
452}
453
439static void hv_util_init(void)
454static void
455hv_util_init(void)
440{
441}
442
456{
457}
458
443static int hv_util_modevent(module_t mod, int event, void *arg)
459static int
460hv_util_modevent(module_t mod, int event, void *arg)
444{
445 switch (event) {
446 case MOD_LOAD:
447 break;
448 case MOD_UNLOAD:
461{
462 switch (event) {
463 case MOD_LOAD:
464 break;
465 case MOD_UNLOAD:
449 break;
466 break;
450 default:
451 break;
452 }
453 return (0);
454}
455
456static device_method_t util_methods[] = {
457 /* Device interface */

--- 17 unchanged lines hidden ---
467 default:
468 break;
469 }
470 return (0);
471}
472
473static device_method_t util_methods[] = {
474 /* Device interface */

--- 17 unchanged lines hidden ---