ia64/xen-unstable

changeset 18555:19b0a4f91712

x86 and ia64: move cpufreq notify code to commone place

This patch move the cpufreq notify code from x86 specfic place to
common place, since it can be used by both x86 and ia64 cpufreq
driver.

Signed-off-by: Liu Jinsong <jinsong.liu@intel.com>
Signed-off-by: Yu Ke <ke.yu@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Sep 26 14:05:41 2008 +0100 (2008-09-26)
parents d1d9915041de
children 840c0c3c185a
files xen/arch/x86/acpi/cpufreq/cpufreq.c xen/arch/x86/platform_hypercall.c xen/arch/x86/x86_64/platform_hypercall.c xen/drivers/cpufreq/cpufreq.c xen/include/acpi/cpufreq/processor_perf.h
line diff
     1.1 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c	Fri Sep 26 14:05:09 2008 +0100
     1.2 +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c	Fri Sep 26 14:05:41 2008 +0100
     1.3 @@ -584,3 +584,21 @@ static int __init cpufreq_driver_init(vo
     1.4      return ret;
     1.5  }
     1.6  __initcall(cpufreq_driver_init);
     1.7 +
     1.8 +int cpufreq_cpu_init(unsigned int cpuid)
     1.9 +{
    1.10 +    static int cpu_count=0;
    1.11 +    int ret;
    1.12 +
    1.13 +    cpu_count++; 
    1.14 +
    1.15 +    /* Currently we only handle Intel and AMD processor */
    1.16 +    if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
    1.17 +        ret = cpufreq_add_cpu(cpuid);
    1.18 +    else if ( (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) &&
    1.19 +            (cpu_count == num_online_cpus()) )
    1.20 +        ret = powernow_cpufreq_init();
    1.21 +    else
    1.22 +        ret = -EFAULT;
    1.23 +    return ret;
    1.24 +}
     2.1 --- a/xen/arch/x86/platform_hypercall.c	Fri Sep 26 14:05:09 2008 +0100
     2.2 +++ b/xen/arch/x86/platform_hypercall.c	Fri Sep 26 14:05:41 2008 +0100
     2.3 @@ -45,6 +45,7 @@ extern spinlock_t xenpf_lock;
     2.4  
     2.5  static DEFINE_PER_CPU(uint64_t, freq);
     2.6  
     2.7 +extern int set_px_pminfo(uint32_t cpu, struct xen_processor_performance *perf);
     2.8  extern long set_cx_pminfo(uint32_t cpu, struct xen_processor_power *power);
     2.9  
    2.10  static long cpu_frequency_change_helper(void *data)
    2.11 @@ -52,6 +53,15 @@ static long cpu_frequency_change_helper(
    2.12      return cpu_frequency_change(this_cpu(freq));
    2.13  }
    2.14  
    2.15 +int xenpf_copy_px_states(struct processor_performance *pxpt,
    2.16 +        struct xen_processor_performance *dom0_px_info)
    2.17 +{
    2.18 +    if (!pxpt || !dom0_px_info)
    2.19 +        return -EINVAL;
    2.20 +    return  copy_from_compat(pxpt->states, dom0_px_info->states, 
    2.21 +                    dom0_px_info->state_count);
    2.22 +}
    2.23 +
    2.24  ret_t do_platform_op(XEN_GUEST_HANDLE(xen_platform_op_t) u_xenpf_op)
    2.25  {
    2.26      ret_t ret = 0;
    2.27 @@ -363,99 +373,9 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
    2.28          {
    2.29          case XEN_PM_PX:
    2.30          {
    2.31 -            static int cpu_count = 0;
    2.32 -            struct xenpf_set_processor_pminfo *xenpmpt = &op->u.set_pminfo;
    2.33 -            struct xen_processor_performance *xenpxpt = &op->u.set_pminfo.perf;
    2.34 -            int cpuid = get_cpu_id(xenpmpt->id);
    2.35 -            struct processor_pminfo *pmpt;
    2.36 -            struct processor_performance *pxpt;
    2.37  
    2.38 -            if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) )
    2.39 -            {
    2.40 -                ret = -ENOSYS;
    2.41 -                break;
    2.42 -            }
    2.43 -            if ( cpuid < 0 )
    2.44 -            {
    2.45 -                ret = -EINVAL;
    2.46 -                break;
    2.47 -            }
    2.48 -            pmpt = processor_pminfo[cpuid];
    2.49 -            if ( !pmpt )
    2.50 -            {
    2.51 -                pmpt = xmalloc(struct processor_pminfo);
    2.52 -                if ( !pmpt )
    2.53 -                {
    2.54 -                    ret = -ENOMEM;
    2.55 -                    break;
    2.56 -                }
    2.57 -                memset(pmpt, 0, sizeof(*pmpt));
    2.58 -                processor_pminfo[cpuid] = pmpt;
    2.59 -            }
    2.60 -            pxpt = &pmpt->perf;
    2.61 -            pmpt->acpi_id = xenpmpt->id;
    2.62 -            pmpt->id = cpuid;
    2.63 -
    2.64 -            if ( xenpxpt->flags & XEN_PX_PCT )
    2.65 -            {
    2.66 -                memcpy ((void *)&pxpt->control_register,
    2.67 -                    (void *)&xenpxpt->control_register,
    2.68 -                    sizeof(struct xen_pct_register));
    2.69 -                memcpy ((void *)&pxpt->status_register,
    2.70 -                    (void *)&xenpxpt->status_register,
    2.71 -                    sizeof(struct xen_pct_register));
    2.72 -            }
    2.73 -            if ( xenpxpt->flags & XEN_PX_PSS ) 
    2.74 -            {
    2.75 -                if ( !(pxpt->states = xmalloc_array(struct xen_processor_px,
    2.76 -                    xenpxpt->state_count)) )
    2.77 -                {
    2.78 -                    ret = -ENOMEM;
    2.79 -                    break;
    2.80 -                }
    2.81 -                if ( copy_from_compat(pxpt->states, xenpxpt->states, 
    2.82 -                    xenpxpt->state_count) )
    2.83 -                {
    2.84 -                    xfree(pxpt->states);
    2.85 -                    ret = -EFAULT;
    2.86 -                    break;
    2.87 -                }
    2.88 -                pxpt->state_count = xenpxpt->state_count;
    2.89 -            }
    2.90 -            if ( xenpxpt->flags & XEN_PX_PSD )
    2.91 -            {
    2.92 -                pxpt->shared_type = xenpxpt->shared_type;
    2.93 -                memcpy ((void *)&pxpt->domain_info,
    2.94 -                    (void *)&xenpxpt->domain_info,
    2.95 -                    sizeof(struct xen_psd_package));
    2.96 -            }
    2.97 -            if ( xenpxpt->flags & XEN_PX_PPC )
    2.98 -            {
    2.99 -                pxpt->platform_limit = xenpxpt->platform_limit;
   2.100 -
   2.101 -                if ( pxpt->init == XEN_PX_INIT )
   2.102 -                {
   2.103 -                    ret = cpufreq_limit_change(cpuid);
   2.104 -                    break;
   2.105 -                }
   2.106 -            }
   2.107 -
   2.108 -            if ( xenpxpt->flags == ( XEN_PX_PCT | XEN_PX_PSS |
   2.109 -                                     XEN_PX_PSD | XEN_PX_PPC ) )
   2.110 -            {
   2.111 -                pxpt->init = XEN_PX_INIT;
   2.112 -                cpu_count++;
   2.113 -
   2.114 -                /* Currently we only handle Intel and AMD processor */
   2.115 -                if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
   2.116 -                    ret = cpufreq_add_cpu(cpuid);
   2.117 -                else if ( (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) &&
   2.118 -                    (cpu_count == num_online_cpus()) )
   2.119 -                    ret = powernow_cpufreq_init();
   2.120 -                else
   2.121 -                    break;
   2.122 -            }
   2.123 -
   2.124 +            ret = set_px_pminfo(op->u.set_pminfo.id,
   2.125 +                                &op->u.set_pminfo.perf);
   2.126              break;
   2.127          }
   2.128   
     3.1 --- a/xen/arch/x86/x86_64/platform_hypercall.c	Fri Sep 26 14:05:09 2008 +0100
     3.2 +++ b/xen/arch/x86/x86_64/platform_hypercall.c	Fri Sep 26 14:05:41 2008 +0100
     3.3 @@ -11,6 +11,8 @@ DEFINE_XEN_GUEST_HANDLE(compat_platform_
     3.4  #define xen_platform_op_t   compat_platform_op_t
     3.5  #define do_platform_op(x)   compat_platform_op(_##x)
     3.6  
     3.7 +#define xenpf_copy_px_states compat_xenpf_copy_px_states
     3.8 +
     3.9  #define xen_processor_px    compat_processor_px
    3.10  #define xen_processor_px_t  compat_processor_px_t
    3.11  #define xen_processor_performance    compat_processor_performance
     4.1 --- a/xen/drivers/cpufreq/cpufreq.c	Fri Sep 26 14:05:09 2008 +0100
     4.2 +++ b/xen/drivers/cpufreq/cpufreq.c	Fri Sep 26 14:05:41 2008 +0100
     4.3 @@ -34,13 +34,12 @@
     4.4  #include <xen/sched.h>
     4.5  #include <xen/timer.h>
     4.6  #include <xen/xmalloc.h>
     4.7 +#include <xen/domain.h>
     4.8  #include <asm/bug.h>
     4.9 -#include <asm/msr.h>
    4.10  #include <asm/io.h>
    4.11  #include <asm/config.h>
    4.12  #include <asm/processor.h>
    4.13  #include <asm/percpu.h>
    4.14 -#include <asm/cpufeature.h>
    4.15  #include <acpi/acpi.h>
    4.16  #include <acpi/cpufreq/cpufreq.h>
    4.17  
    4.18 @@ -82,7 +81,7 @@ int cpufreq_add_cpu(unsigned int cpu)
    4.19      if (!processor_pminfo[cpu] || !(perf->init & XEN_PX_INIT))
    4.20          return 0;
    4.21  
    4.22 -    if (cpu_is_offline(cpu) || cpufreq_cpu_policy[cpu])
    4.23 +    if (!cpu_online(cpu) || cpufreq_cpu_policy[cpu])
    4.24          return -EINVAL;
    4.25  
    4.26      ret = cpufreq_statistic_init(cpu);
    4.27 @@ -158,7 +157,7 @@ int cpufreq_del_cpu(unsigned int cpu)
    4.28      if (!processor_pminfo[cpu] || !(perf->init & XEN_PX_INIT))
    4.29          return 0;
    4.30  
    4.31 -    if (cpu_is_offline(cpu) || !cpufreq_cpu_policy[cpu])
    4.32 +    if (!cpu_online(cpu) || !cpufreq_cpu_policy[cpu])
    4.33          return -EINVAL;
    4.34  
    4.35      dom = perf->domain_info.domain;
    4.36 @@ -186,3 +185,123 @@ int cpufreq_del_cpu(unsigned int cpu)
    4.37      return 0;
    4.38  }
    4.39  
    4.40 +static void print_PSS(struct xen_processor_px *ptr, int count)
    4.41 +{
    4.42 +    int i;
    4.43 +    printk(KERN_INFO "\t_PSS:\n");
    4.44 +    for (i=0; i<count; i++){
    4.45 +        printk(KERN_INFO "\tState%d: %ldMHz %ldmW %ldus %ldus 0x%lx 0x%lx\n",i,
    4.46 +                ptr[i].core_frequency,
    4.47 +                ptr[i].power, 
    4.48 +                ptr[i].transition_latency,
    4.49 +                ptr[i].bus_master_latency,
    4.50 +                ptr[i].control,
    4.51 +                ptr[i].status
    4.52 +              );
    4.53 +    }
    4.54 +}
    4.55 +
    4.56 +static void print_PSD( struct xen_psd_package *ptr)
    4.57 +{
    4.58 +    printk(KERN_INFO "\t_PSD: num_entries=%ld rev=%ld domain=%ld coord_type=%ld num_processors=%ld\n",
    4.59 +            ptr->num_entries, ptr->revision, ptr->domain, ptr->coord_type, 
    4.60 +            ptr->num_processors);
    4.61 +}
    4.62 +
    4.63 +int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *dom0_px_info)
    4.64 +{
    4.65 +    int cpu_count = 0, ret=0, cpuid;
    4.66 +    struct processor_pminfo *pmpt;
    4.67 +    struct processor_performance *pxpt;
    4.68 +
    4.69 +    if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) )
    4.70 +    {
    4.71 +        ret = -ENOSYS;
    4.72 +        goto out;
    4.73 +    }
    4.74 +
    4.75 +    cpuid = get_cpu_id(acpi_id);
    4.76 +    if ( cpuid < 0 )
    4.77 +    {
    4.78 +        ret = -EINVAL;
    4.79 +        goto out;
    4.80 +    }
    4.81 +    printk(KERN_INFO "Set CPU acpi_id(%d) cpuid(%d) Px State info:\n",
    4.82 +            acpi_id, cpuid);
    4.83 +
    4.84 +    pmpt = processor_pminfo[cpuid];
    4.85 +    if ( !pmpt )
    4.86 +    {
    4.87 +        pmpt = xmalloc(struct processor_pminfo);
    4.88 +        if ( !pmpt )
    4.89 +        {
    4.90 +            ret = -ENOMEM;
    4.91 +            goto out;
    4.92 +        }
    4.93 +        memset(pmpt, 0, sizeof(*pmpt));
    4.94 +        processor_pminfo[cpuid] = pmpt;
    4.95 +    }
    4.96 +    pxpt = &pmpt->perf;
    4.97 +    pmpt->acpi_id = acpi_id;
    4.98 +    pmpt->id = cpuid;
    4.99 +
   4.100 +    if ( dom0_px_info->flags & XEN_PX_PCT )
   4.101 +    {
   4.102 +        memcpy ((void *)&pxpt->control_register,
   4.103 +                (void *)&dom0_px_info->control_register,
   4.104 +                sizeof(struct xen_pct_register));
   4.105 +        memcpy ((void *)&pxpt->status_register,
   4.106 +                (void *)&dom0_px_info->status_register,
   4.107 +                sizeof(struct xen_pct_register));
   4.108 +    }
   4.109 +    if ( dom0_px_info->flags & XEN_PX_PSS ) 
   4.110 +    {
   4.111 +        if ( !(pxpt->states = xmalloc_array(struct xen_processor_px,
   4.112 +                        dom0_px_info->state_count)) )
   4.113 +        {
   4.114 +            ret = -ENOMEM;
   4.115 +            goto out;
   4.116 +        }
   4.117 +        if ( xenpf_copy_px_states(pxpt, dom0_px_info) )
   4.118 +        {
   4.119 +            xfree(pxpt->states);
   4.120 +            ret = -EFAULT;
   4.121 +            goto out;
   4.122 +        }
   4.123 +        pxpt->state_count = dom0_px_info->state_count;
   4.124 +        print_PSS(pxpt->states,pxpt->state_count);
   4.125 +    }
   4.126 +    if ( dom0_px_info->flags & XEN_PX_PSD )
   4.127 +    {
   4.128 +        pxpt->shared_type = dom0_px_info->shared_type;
   4.129 +        memcpy ((void *)&pxpt->domain_info,
   4.130 +                (void *)&dom0_px_info->domain_info,
   4.131 +                sizeof(struct xen_psd_package));
   4.132 +        print_PSD(&pxpt->domain_info);
   4.133 +    }
   4.134 +    if ( dom0_px_info->flags & XEN_PX_PPC )
   4.135 +    {
   4.136 +        pxpt->platform_limit = dom0_px_info->platform_limit;
   4.137 +
   4.138 +        if ( pxpt->init == XEN_PX_INIT )
   4.139 +        {
   4.140 +
   4.141 +            ret = cpufreq_limit_change(cpuid); 
   4.142 +            goto out;
   4.143 +        }
   4.144 +    }
   4.145 +
   4.146 +    if ( dom0_px_info->flags == ( XEN_PX_PCT | XEN_PX_PSS |
   4.147 +                XEN_PX_PSD | XEN_PX_PPC ) )
   4.148 +    {
   4.149 +        pxpt->init = XEN_PX_INIT;
   4.150 +        cpu_count++;
   4.151 +
   4.152 +        ret = cpufreq_cpu_init(cpuid);
   4.153 +        goto out;
   4.154 +    }
   4.155 +
   4.156 +out:
   4.157 +    return ret;
   4.158 +}
   4.159 +
     5.1 --- a/xen/include/acpi/cpufreq/processor_perf.h	Fri Sep 26 14:05:09 2008 +0100
     5.2 +++ b/xen/include/acpi/cpufreq/processor_perf.h	Fri Sep 26 14:05:41 2008 +0100
     5.3 @@ -60,4 +60,8 @@ struct pm_px {
     5.4  
     5.5  extern struct pm_px *cpufreq_statistic_data[NR_CPUS];
     5.6  
     5.7 +int xenpf_copy_px_states(struct processor_performance *pxpt,
     5.8 +        struct xen_processor_performance *dom0_px_info);
     5.9 +
    5.10 +int cpufreq_cpu_init(unsigned int cpuid);
    5.11  #endif /* __XEN_PROCESSOR_PM_H__ */