eal/linux: remove useless casts in hugepage init
[dpdk.git] / lib / librte_power / rte_power_kvm_vm.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
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  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 #include <errno.h>
34 #include <string.h>
35
36 #include <rte_log.h>
37 #include <rte_config.h>
38
39 #include "guest_channel.h"
40 #include "channel_commands.h"
41 #include "rte_power_kvm_vm.h"
42 #include "rte_power_common.h"
43
44 #define FD_PATH "/dev/virtio-ports/virtio.serial.port.poweragent"
45
46 static struct channel_packet pkt[CHANNEL_CMDS_MAX_VM_CHANNELS];
47
48
49 int
50 rte_power_kvm_vm_init(unsigned lcore_id)
51 {
52         if (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {
53                 RTE_LOG(ERR, POWER, "Core(%u) is out of range 0...%d\n",
54                                 lcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);
55                 return -1;
56         }
57         pkt[lcore_id].command = CPU_POWER;
58         pkt[lcore_id].resource_id = lcore_id;
59         return guest_channel_host_connect(FD_PATH, lcore_id);
60 }
61
62 int
63 rte_power_kvm_vm_exit(unsigned lcore_id)
64 {
65         guest_channel_host_disconnect(lcore_id);
66         return 0;
67 }
68
69 uint32_t
70 rte_power_kvm_vm_freqs(__attribute__((unused)) unsigned lcore_id,
71                 __attribute__((unused)) uint32_t *freqs,
72                 __attribute__((unused)) uint32_t num)
73 {
74         RTE_LOG(ERR, POWER, "rte_power_freqs is not implemented "
75                         "for Virtual Machine Power Management\n");
76         return -ENOTSUP;
77 }
78
79 uint32_t
80 rte_power_kvm_vm_get_freq(__attribute__((unused)) unsigned lcore_id)
81 {
82         RTE_LOG(ERR, POWER, "rte_power_get_freq is not implemented "
83                         "for Virtual Machine Power Management\n");
84         return -ENOTSUP;
85 }
86
87 int
88 rte_power_kvm_vm_set_freq(__attribute__((unused)) unsigned lcore_id,
89                 __attribute__((unused)) uint32_t index)
90 {
91         RTE_LOG(ERR, POWER, "rte_power_set_freq is not implemented "
92                         "for Virtual Machine Power Management\n");
93         return -ENOTSUP;
94 }
95
96 static inline int
97 send_msg(unsigned lcore_id, uint32_t scale_direction)
98 {
99         int ret;
100
101         if (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {
102                 RTE_LOG(ERR, POWER, "Core(%u) is out of range 0...%d\n",
103                                 lcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);
104                 return -1;
105         }
106         pkt[lcore_id].unit = scale_direction;
107         ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);
108         if (ret == 0)
109                 return 1;
110         RTE_LOG(DEBUG, POWER, "Error sending message: %s\n", strerror(ret));
111         return -1;
112 }
113
114 int
115 rte_power_kvm_vm_freq_up(unsigned lcore_id)
116 {
117         return send_msg(lcore_id, CPU_POWER_SCALE_UP);
118 }
119
120 int
121 rte_power_kvm_vm_freq_down(unsigned lcore_id)
122 {
123         return send_msg(lcore_id, CPU_POWER_SCALE_DOWN);
124 }
125
126 int
127 rte_power_kvm_vm_freq_max(unsigned lcore_id)
128 {
129         return send_msg(lcore_id, CPU_POWER_SCALE_MAX);
130 }
131
132 int
133 rte_power_kvm_vm_freq_min(unsigned lcore_id)
134 {
135         return send_msg(lcore_id, CPU_POWER_SCALE_MIN);
136 }