2 * Copyright (c) 2014 Microsoft Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
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.
30 * A common driver for all hyper-V util services.
33 #include <sys/param.h>
34 #include <sys/kernel.h>
36 #include <sys/malloc.h>
37 #include <sys/module.h>
38 #include <sys/reboot.h>
39 #include <sys/timetc.h>
40 #include <sys/syscallsubr.h>
42 #include <dev/hyperv/include/hyperv.h>
47 struct hv_vmbus_icmsg_hdr* icmsghdrp,
48 struct hv_vmbus_icmsg_negotiate* negop,
51 icmsghdrp->icmsgsize = 0x10;
53 negop = (struct hv_vmbus_icmsg_negotiate *)&buf[
54 sizeof(struct hv_vmbus_pipe_hdr) +
55 sizeof(struct hv_vmbus_icmsg_hdr)];
57 if (negop->icframe_vercnt >= 2 &&
58 negop->icversion_data[1].major == 3) {
59 negop->icversion_data[0].major = 3;
60 negop->icversion_data[0].minor = 0;
61 negop->icversion_data[1].major = 3;
62 negop->icversion_data[1].minor = 0;
64 negop->icversion_data[0].major = 1;
65 negop->icversion_data[0].minor = 0;
66 negop->icversion_data[1].major = 1;
67 negop->icversion_data[1].minor = 0;
70 negop->icframe_vercnt = 1;
71 negop->icmsg_vercnt = 1;
75 hv_util_attach(device_t dev)
77 struct hv_device* hv_dev;
78 struct hv_util_sc* softc;
81 hv_dev = vmbus_get_devctx(dev);
82 softc = device_get_softc(dev);
83 softc->hv_dev = hv_dev;
84 softc->receive_buffer =
85 malloc(4 * PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);
88 * These services are not performance critical and do not need
89 * batched reading. Furthermore, some services such as KVP can
90 * only handle one message from the host at a time.
91 * Turn off batched reading for all util drivers before we open the
94 hv_set_channel_read_state(hv_dev->channel, FALSE);
96 ret = hv_vmbus_channel_open(hv_dev->channel, 4 * PAGE_SIZE,
97 4 * PAGE_SIZE, NULL, 0,
98 softc->callback, softc);
106 free(softc->receive_buffer, M_DEVBUF);
111 hv_util_detach(device_t dev)
113 struct hv_device* hv_dev;
114 struct hv_util_sc* softc;
116 hv_dev = vmbus_get_devctx(dev);
118 hv_vmbus_channel_close(hv_dev->channel);
119 softc = device_get_softc(dev);
121 free(softc->receive_buffer, M_DEVBUF);