/* * intel_pstate.c: Native P state management for Intel processors * * (C) Copyright 2012 Intel Corporation * Author: Dirk Brandewie <dirk.j.brandewie@intel.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; version 2 * of the License. */#include<linux/kernel.h>#include<linux/kernel_stat.h>#include<linux/module.h>#include<linux/ktime.h>#include<linux/hrtimer.h>#include<linux/tick.h>#include<linux/slab.h>#include<linux/sched.h>#include<linux/list.h>#include<linux/cpu.h>#include<linux/cpufreq.h>#include<linux/sysfs.h>#include<linux/types.h>#include<linux/fs.h>#include<linux/debugfs.h>#include<linux/acpi.h>#include<trace/events/power.h>#include<asm/div64.h>#include<asm/msr.h>#include<asm/cpu_device_id.h>#define BYT_RATIOS 0x66a#define BYT_VIDS 0x66b#define BYT_TURBO_RATIOS 0x66c#define BYT_TURBO_VIDS 0x66d#define FRAC_BITS 8#define int_tofp(X) ((int64_t)(X) << FRAC_BITS)#define fp_toint(X) ((X) >> FRAC_BITS)staticinlineint32_tmul_fp(int32_tx,int32_ty){return((int64_t)x*(int64_t)y)>>FRAC_BITS;}staticinlineint32_tdiv_fp(int32_tx,int32_ty){returndiv_s64((int64_t)x<<FRAC_BITS,y);}staticinlineintceiling_fp(int32_tx){intmask,ret;ret=fp_toint(x);mask=(1<<FRAC_BITS)-1;if(x&mask)ret+=1;returnret;}structsample{int32_tcore_pct_busy;u64aperf;u64mperf;intfreq;ktime_ttime;};structpstate_data{intcurrent_pstate;intmin_pstate;intmax_pstate;intscaling;intturbo_pstate;};structvid_data{intmin;intmax;intturbo;int32_tratio;};struct_pid{intsetpoint;int32_tintegral;int32_tp_gain;int32_ti_gain;int32_td_gain;intdeadband;int32_tlast_err;};structcpudata{intcpu;structtimer_listtimer;structpstate_datapstate;structvid_datavid;struct_pidpid;ktime_tlast_sample_time;u64prev_aperf;u64prev_mperf;structsamplesample;};staticstructcpudata**all_cpu_data;structpstate_adjust_policy{intsample_rate_ms;intdeadband;intsetpoint;intp_gain_pct;intd_gain_pct;inti_gain_pct;};structpstate_funcs