Staging: hv: fix up sparse warning in hyperv_utils.c
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / hv / hyperv_utils.c
blobcbebad3e40a0ba753e5a711c0b34875e4ca41628
1 /*
2 * Copyright (c) 2010, Microsoft Corporation.
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.
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.
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.
17 * Authors:
18 * Haiyang Zhang <haiyangz@microsoft.com>
19 * Hank Janssen <hjanssen@microsoft.com>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/reboot.h>
28 #include "logging.h"
29 #include "osd.h"
30 #include "vmbus.h"
31 #include "VmbusPacketFormat.h"
32 #include "VmbusChannelInterface.h"
33 #include "VersionInfo.h"
34 #include "Channel.h"
35 #include "VmbusPrivate.h"
36 #include "VmbusApi.h"
37 #include "utils.h"
40 static void shutdown_onchannelcallback(void *context)
42 struct vmbus_channel *channel = context;
43 u8 *buf;
44 u32 buflen, recvlen;
45 u64 requestid;
46 u8 execute_shutdown = false;
48 struct shutdown_msg_data *shutdown_msg;
50 struct icmsg_hdr *icmsghdrp;
51 struct icmsg_negotiate *negop = NULL;
53 DPRINT_ENTER(VMBUS);
55 buflen = PAGE_SIZE;
56 buf = kmalloc(buflen, GFP_ATOMIC);
58 VmbusChannelRecvPacket(channel, buf, buflen, &recvlen, &requestid);
60 if (recvlen > 0) {
61 DPRINT_DBG(VMBUS, "shutdown packet: len=%d, requestid=%lld",
62 recvlen, requestid);
64 icmsghdrp = (struct icmsg_hdr *)&buf[
65 sizeof(struct vmbuspipe_hdr)];
67 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
68 prep_negotiate_resp(icmsghdrp, negop, buf);
69 } else {
70 shutdown_msg = (struct shutdown_msg_data *)&buf[
71 sizeof(struct vmbuspipe_hdr) +
72 sizeof(struct icmsg_hdr)];
74 switch (shutdown_msg->flags) {
75 case 0:
76 case 1:
77 icmsghdrp->status = HV_S_OK;
78 execute_shutdown = true;
80 DPRINT_INFO(VMBUS, "Shutdown request received -"
81 " gracefull shutdown initiated");
82 break;
83 default:
84 icmsghdrp->status = HV_E_FAIL;
85 execute_shutdown = false;
87 DPRINT_INFO(VMBUS, "Shutdown request received -"
88 " Invalid request");
89 break;
93 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
94 | ICMSGHDRFLAG_RESPONSE;
96 VmbusChannelSendPacket(channel, buf,
97 recvlen, requestid,
98 VmbusPacketTypeDataInBand, 0);
101 kfree(buf);
103 DPRINT_EXIT(VMBUS);
105 if (execute_shutdown == true)
106 orderly_poweroff(false);
109 static int __init init_hyperv_utils(void)
111 printk(KERN_INFO "Registering HyperV Utility Driver\n");
113 hv_cb_utils[HV_SHUTDOWN_MSG].channel->OnChannelCallback =
114 &shutdown_onchannelcallback;
115 hv_cb_utils[HV_SHUTDOWN_MSG].callback = &shutdown_onchannelcallback;
117 return 0;
120 static void exit_hyperv_utils(void)
122 printk(KERN_INFO "De-Registered HyperV Utility Driver\n");
124 hv_cb_utils[HV_SHUTDOWN_MSG].channel->OnChannelCallback =
125 &chn_cb_negotiate;
126 hv_cb_utils[HV_SHUTDOWN_MSG].callback = &chn_cb_negotiate;
129 module_init(init_hyperv_utils);
130 module_exit(exit_hyperv_utils);
132 MODULE_DESCRIPTION("Hyper-V Utilities");
133 MODULE_VERSION(HV_DRV_VERSION);
134 MODULE_LICENSE("GPL");