ia64/xen-unstable

changeset 18671:a9f299b11b7f

x86: Adapt 32b guest os to 64b hypervisor platform_hypercall compatibility

Changeset 18552 (19b0a4f91712) move px transfer logic from
platform_hypercall.c to a common file to support both x86 and
ia64. However, it involves 32b guest os to 64b hypervisor (x86)
compatible issue. This patch fix the compatible issue, and make
set_px_pminfo() re-used by ia64 and x86 (32b guest os to 64b
hypervisor, and 64b guest os to 64b hypervisor).

Signed-off-by: Liu Jinsong <jinsong.liu@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Oct 21 09:47:33 2008 +0100 (2008-10-21)
parents 1eba0c88655f
children 27eec3c54d08
files xen/arch/x86/platform_hypercall.c xen/arch/x86/x86_64/Makefile xen/arch/x86/x86_64/cpu_idle.c xen/arch/x86/x86_64/cpufreq.c xen/arch/x86/x86_64/platform_hypercall.c xen/drivers/cpufreq/cpufreq.c xen/include/acpi/cpufreq/processor_perf.h xen/include/xlat.lst
line diff
     1.1 --- a/xen/arch/x86/platform_hypercall.c	Mon Oct 20 17:45:36 2008 +0100
     1.2 +++ b/xen/arch/x86/platform_hypercall.c	Tue Oct 21 09:47:33 2008 +0100
     1.3 @@ -53,15 +53,6 @@ static long cpu_frequency_change_helper(
     1.4      return cpu_frequency_change(this_cpu(freq));
     1.5  }
     1.6  
     1.7 -int xenpf_copy_px_states(struct processor_performance *pxpt,
     1.8 -        struct xen_processor_performance *dom0_px_info)
     1.9 -{
    1.10 -    if (!pxpt || !dom0_px_info)
    1.11 -        return -EINVAL;
    1.12 -    return  copy_from_compat(pxpt->states, dom0_px_info->states, 
    1.13 -                    dom0_px_info->state_count);
    1.14 -}
    1.15 -
    1.16  ret_t do_platform_op(XEN_GUEST_HANDLE(xen_platform_op_t) u_xenpf_op)
    1.17  {
    1.18      ret_t ret = 0;
    1.19 @@ -372,12 +363,13 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
    1.20          switch ( op->u.set_pminfo.type )
    1.21          {
    1.22          case XEN_PM_PX:
    1.23 -        {
    1.24 -
    1.25 -            ret = set_px_pminfo(op->u.set_pminfo.id,
    1.26 -                                &op->u.set_pminfo.perf);
    1.27 +            if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) )
    1.28 +            {
    1.29 +                ret = -ENOSYS;
    1.30 +                break;
    1.31 +            }
    1.32 +            ret = set_px_pminfo(op->u.set_pminfo.id, &op->u.set_pminfo.perf);
    1.33              break;
    1.34 -        }
    1.35   
    1.36          case XEN_PM_CX:
    1.37              if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_CX) )
     2.1 --- a/xen/arch/x86/x86_64/Makefile	Mon Oct 20 17:45:36 2008 +0100
     2.2 +++ b/xen/arch/x86/x86_64/Makefile	Tue Oct 21 09:47:33 2008 +0100
     2.3 @@ -13,6 +13,7 @@ obj-$(CONFIG_COMPAT) += domain.o
     2.4  obj-$(CONFIG_COMPAT) += physdev.o
     2.5  obj-$(CONFIG_COMPAT) += platform_hypercall.o
     2.6  obj-$(CONFIG_COMPAT) += cpu_idle.o
     2.7 +obj-$(CONFIG_COMPAT) += cpufreq.o
     2.8  
     2.9  ifeq ($(CONFIG_COMPAT),y)
    2.10  # extra dependencies
    2.11 @@ -24,4 +25,5 @@ platform_hypercall.o: ../platform_hyperc
    2.12  sysctl.o:	../sysctl.c
    2.13  traps.o:	compat/traps.c
    2.14  cpu_idle.o:	../acpi/cpu_idle.c
    2.15 +cpufreq.o:	../../../drivers/cpufreq/cpufreq.c
    2.16  endif
     3.1 --- a/xen/arch/x86/x86_64/cpu_idle.c	Mon Oct 20 17:45:36 2008 +0100
     3.2 +++ b/xen/arch/x86/x86_64/cpu_idle.c	Tue Oct 21 09:47:33 2008 +0100
     3.3 @@ -44,7 +44,7 @@ DEFINE_XEN_GUEST_HANDLE(compat_processor
     3.4      xlat_page_current = xlat_page_start; \
     3.5  } while (0)
     3.6  
     3.7 -static void *xlat_malloc(unsigned long *xlat_page_current, size_t size)
     3.8 +void *xlat_malloc(unsigned long *xlat_page_current, size_t size)
     3.9  {
    3.10      void *ret;
    3.11  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/xen/arch/x86/x86_64/cpufreq.c	Tue Oct 21 09:47:33 2008 +0100
     4.3 @@ -0,0 +1,91 @@
     4.4 +/******************************************************************************
     4.5 + * cpufreq.c -- adapt 32b compat guest to 64b hypervisor.
     4.6 + *
     4.7 + *  Copyright (C) 2008, Liu Jinsong <jinsong.liu@intel.com>
     4.8 + *
     4.9 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4.10 + *
    4.11 + *  This program is free software; you can redistribute it and/or modify
    4.12 + *  it under the terms of the GNU General Public License as published by
    4.13 + *  the Free Software Foundation; either version 2 of the License, or (at
    4.14 + *  your option) any later version.
    4.15 + *
    4.16 + *  This program is distributed in the hope that it will be useful, but
    4.17 + *  WITHOUT ANY WARRANTY; without even the implied warranty of
    4.18 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.19 + *  General Public License for more details.
    4.20 + *
    4.21 + *  You should have received a copy of the GNU General Public License along
    4.22 + *  with this program; if not, write to the Free Software Foundation, Inc.,
    4.23 + *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
    4.24 + *
    4.25 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4.26 + */
    4.27 +#include <xen/config.h>
    4.28 +#include <xen/types.h>
    4.29 +#include <xen/xmalloc.h>
    4.30 +#include <xen/guest_access.h>
    4.31 +#include <compat/platform.h>
    4.32 +
    4.33 +DEFINE_XEN_GUEST_HANDLE(compat_processor_px_t);
    4.34 +
    4.35 +#define xlat_page_start ((unsigned long)COMPAT_ARG_XLAT_VIRT_BASE)
    4.36 +
    4.37 +#define xlat_malloc_init(xlat_page_current)    do { \
    4.38 +    xlat_page_current = xlat_page_start; \
    4.39 +} while (0)
    4.40 +
    4.41 +extern void *xlat_malloc(unsigned long *xlat_page_current, size_t size);
    4.42 +
    4.43 +#define xlat_malloc_array(_p, _t, _c) ((_t *) xlat_malloc(&_p, sizeof(_t) * _c))
    4.44 +
    4.45 +extern int 
    4.46 +set_px_pminfo(uint32_t cpu, struct xen_processor_performance *perf);
    4.47 +
    4.48 +int 
    4.49 +compat_set_px_pminfo(uint32_t cpu, struct compat_processor_performance *perf)
    4.50 +{
    4.51 +    struct xen_processor_performance *xen_perf;
    4.52 +    unsigned long xlat_page_current;
    4.53 +
    4.54 +    xlat_malloc_init(xlat_page_current);
    4.55 +
    4.56 +    xen_perf = xlat_malloc_array(xlat_page_current,
    4.57 +                                  struct xen_processor_performance, 1);
    4.58 +    if ( unlikely(xen_perf == NULL) )
    4.59 +	return -EFAULT;
    4.60 +
    4.61 +#define XLAT_processor_performance_HNDL_states(_d_, _s_) do { \
    4.62 +    xen_processor_px_t *xen_states = NULL; \
    4.63 +\
    4.64 +    if ( likely((_s_)->state_count > 0) ) \
    4.65 +    { \
    4.66 +        XEN_GUEST_HANDLE(compat_processor_px_t) states; \
    4.67 +        compat_processor_px_t state; \
    4.68 +        int i; \
    4.69 +\
    4.70 +        xen_states = xlat_malloc_array(xlat_page_current, \
    4.71 +                               xen_processor_px_t, (_s_)->state_count); \
    4.72 +        if ( unlikely(xen_states == NULL) ) \
    4.73 +            return -EFAULT; \
    4.74 +\
    4.75 +        if ( unlikely(!compat_handle_okay((_s_)->states, \
    4.76 +                                (_s_)->state_count)) ) \
    4.77 +            return -EFAULT; \
    4.78 +        guest_from_compat_handle(states, (_s_)->states); \
    4.79 +\
    4.80 +        for ( i = 0; i < _s_->state_count; i++ ) \
    4.81 +        { \
    4.82 +           if ( unlikely(copy_from_guest_offset(&state, states, i, 1)) ) \
    4.83 +               return -EFAULT; \
    4.84 +           XLAT_processor_px(&xen_states[i], &state); \
    4.85 +        } \
    4.86 +    } \
    4.87 +\
    4.88 +    set_xen_guest_handle((_d_)->states, xen_states); \
    4.89 +} while (0)
    4.90 +    XLAT_processor_performance(xen_perf, perf);
    4.91 +#undef XLAT_processor_performance_HNDL_states
    4.92 +
    4.93 +    return set_px_pminfo(cpu, xen_perf);
    4.94 +}
     5.1 --- a/xen/arch/x86/x86_64/platform_hypercall.c	Mon Oct 20 17:45:36 2008 +0100
     5.2 +++ b/xen/arch/x86/x86_64/platform_hypercall.c	Tue Oct 21 09:47:33 2008 +0100
     5.3 @@ -11,14 +11,14 @@ DEFINE_XEN_GUEST_HANDLE(compat_platform_
     5.4  #define xen_platform_op_t   compat_platform_op_t
     5.5  #define do_platform_op(x)   compat_platform_op(_##x)
     5.6  
     5.7 -#define xenpf_copy_px_states compat_xenpf_copy_px_states
     5.8 -
     5.9  #define xen_processor_px    compat_processor_px
    5.10  #define xen_processor_px_t  compat_processor_px_t
    5.11  #define xen_processor_performance    compat_processor_performance
    5.12  #define xen_processor_performance_t  compat_processor_performance_t
    5.13  #define xenpf_set_processor_pminfo   compat_pf_set_processor_pminfo
    5.14  
    5.15 +#define set_px_pminfo		compat_set_px_pminfo
    5.16 +
    5.17  #define xen_processor_power     compat_processor_power
    5.18  #define xen_processor_power_t   compat_processor_power_t
    5.19  #define set_cx_pminfo           compat_set_cx_pminfo
     6.1 --- a/xen/drivers/cpufreq/cpufreq.c	Mon Oct 20 17:45:36 2008 +0100
     6.2 +++ b/xen/drivers/cpufreq/cpufreq.c	Tue Oct 21 09:47:33 2008 +0100
     6.3 @@ -34,6 +34,7 @@
     6.4  #include <xen/sched.h>
     6.5  #include <xen/timer.h>
     6.6  #include <xen/xmalloc.h>
     6.7 +#include <xen/guest_access.h>
     6.8  #include <xen/domain.h>
     6.9  #include <asm/bug.h>
    6.10  #include <asm/io.h>
    6.11 @@ -217,14 +218,8 @@ int set_px_pminfo(uint32_t acpi_id, stru
    6.12      struct processor_pminfo *pmpt;
    6.13      struct processor_performance *pxpt;
    6.14  
    6.15 -    if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) )
    6.16 -    {
    6.17 -        ret = -ENOSYS;
    6.18 -        goto out;
    6.19 -    }
    6.20 -
    6.21      cpuid = get_cpu_id(acpi_id);
    6.22 -    if ( cpuid < 0 )
    6.23 +    if ( cpuid < 0 || !dom0_px_info)
    6.24      {
    6.25          ret = -EINVAL;
    6.26          goto out;
    6.27 @@ -265,12 +260,8 @@ int set_px_pminfo(uint32_t acpi_id, stru
    6.28              ret = -ENOMEM;
    6.29              goto out;
    6.30          }
    6.31 -        if ( xenpf_copy_px_states(pxpt, dom0_px_info) )
    6.32 -        {
    6.33 -            xfree(pxpt->states);
    6.34 -            ret = -EFAULT;
    6.35 -            goto out;
    6.36 -        }
    6.37 +        copy_from_guest(pxpt->states, dom0_px_info->states, 
    6.38 +                                      dom0_px_info->state_count);
    6.39          pxpt->state_count = dom0_px_info->state_count;
    6.40          print_PSS(pxpt->states,pxpt->state_count);
    6.41      }
     7.1 --- a/xen/include/acpi/cpufreq/processor_perf.h	Mon Oct 20 17:45:36 2008 +0100
     7.2 +++ b/xen/include/acpi/cpufreq/processor_perf.h	Tue Oct 21 09:47:33 2008 +0100
     7.3 @@ -60,8 +60,5 @@ struct pm_px {
     7.4  
     7.5  extern struct pm_px *cpufreq_statistic_data[NR_CPUS];
     7.6  
     7.7 -int xenpf_copy_px_states(struct processor_performance *pxpt,
     7.8 -        struct xen_processor_performance *dom0_px_info);
     7.9 -
    7.10  int cpufreq_cpu_init(unsigned int cpuid);
    7.11  #endif /* __XEN_PROCESSOR_PM_H__ */
     8.1 --- a/xen/include/xlat.lst	Mon Oct 20 17:45:36 2008 +0100
     8.2 +++ b/xen/include/xlat.lst	Tue Oct 21 09:47:33 2008 +0100
     8.3 @@ -55,3 +55,7 @@
     8.4  !	processor_cx			platform.h
     8.5  !	processor_flags			platform.h
     8.6  !	processor_power			platform.h
     8.7 +!	pct_register			platform.h
     8.8 +!	processor_px			platform.h
     8.9 +!	psd_package			platform.h
    8.10 +!	processor_performance		platform.h