1 /******************************************************************************
2 * cpufreq.c -- adapt 32b compat guest to 64b hypervisor.
3 *
4 * Copyright (C) 2008, Liu Jinsong <jinsong.liu@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; If not, see <http://www.gnu.org/licenses/>.
20 *
21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 */
23 #include <xen/types.h>
24 #include <xen/xmalloc.h>
25 #include <xen/guest_access.h>
26 #include <xen/pmstat.h>
27 #include <compat/platform.h>
28
29 DEFINE_XEN_GUEST_HANDLE(compat_processor_px_t);
30
31 int
compat_set_px_pminfo(uint32_t cpu,struct compat_processor_performance * perf)32 compat_set_px_pminfo(uint32_t cpu, struct compat_processor_performance *perf)
33 {
34 struct xen_processor_performance *xen_perf;
35 unsigned long xlat_page_current;
36
37 xlat_malloc_init(xlat_page_current);
38
39 xen_perf = xlat_malloc_array(xlat_page_current,
40 struct xen_processor_performance, 1);
41 if ( unlikely(xen_perf == NULL) )
42 return -EFAULT;
43
44 #define XLAT_processor_performance_HNDL_states(_d_, _s_) do { \
45 XEN_GUEST_HANDLE(compat_processor_px_t) states; \
46 XEN_GUEST_HANDLE_PARAM(xen_processor_px_t) states_t; \
47 if ( unlikely(!compat_handle_okay((_s_)->states, (_s_)->state_count)) ) \
48 return -EFAULT; \
49 guest_from_compat_handle(states, (_s_)->states); \
50 states_t = guest_handle_cast(states, xen_processor_px_t); \
51 (_d_)->states = guest_handle_from_param(states_t, xen_processor_px_t); \
52 } while (0)
53
54 XLAT_processor_performance(xen_perf, perf);
55 #undef XLAT_processor_performance_HNDL_states
56
57 return set_px_pminfo(cpu, xen_perf);
58 }
59