1b886d83cSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2337aadffSAshwin Chaugule /*
3337aadffSAshwin Chaugule * CPPC (Collaborative Processor Performance Control) methods used
4337aadffSAshwin Chaugule * by CPUfreq drivers.
5337aadffSAshwin Chaugule *
6337aadffSAshwin Chaugule * (C) Copyright 2014, 2015 Linaro Ltd.
7337aadffSAshwin Chaugule * Author: Ashwin Chaugule <[email protected]>
8337aadffSAshwin Chaugule */
9337aadffSAshwin Chaugule
10337aadffSAshwin Chaugule #ifndef _CPPC_ACPI_H
11337aadffSAshwin Chaugule #define _CPPC_ACPI_H
12337aadffSAshwin Chaugule
13337aadffSAshwin Chaugule #include <linux/acpi.h>
148a02d998SRafael J. Wysocki #include <linux/cpufreq.h>
15337aadffSAshwin Chaugule #include <linux/types.h>
16337aadffSAshwin Chaugule
17866ae696SHoan Tran #include <acpi/pcc.h>
18337aadffSAshwin Chaugule #include <acpi/processor.h>
19337aadffSAshwin Chaugule
204f4179fcSRafael J. Wysocki /* CPPCv2 and CPPCv3 support */
214773e77cSPrashanth Prakash #define CPPC_V2_REV 2
224773e77cSPrashanth Prakash #define CPPC_V3_REV 3
234773e77cSPrashanth Prakash #define CPPC_V2_NUM_ENT 21
244773e77cSPrashanth Prakash #define CPPC_V3_NUM_ENT 23
25337aadffSAshwin Chaugule
26139aee73SPrakash, Prashanth #define PCC_CMD_COMPLETE_MASK (1 << 0)
27139aee73SPrakash, Prashanth #define PCC_ERROR_MASK (1 << 2)
28139aee73SPrakash, Prashanth
294773e77cSPrashanth Prakash #define MAX_CPC_REG_ENT 21
30337aadffSAshwin Chaugule
31337aadffSAshwin Chaugule /* CPPC specific PCC commands. */
32337aadffSAshwin Chaugule #define CMD_READ 0
33337aadffSAshwin Chaugule #define CMD_WRITE 1
34337aadffSAshwin Chaugule
35337aadffSAshwin Chaugule /* Each register has the folowing format. */
36337aadffSAshwin Chaugule struct cpc_reg {
37337aadffSAshwin Chaugule u8 descriptor;
38337aadffSAshwin Chaugule u16 length;
39337aadffSAshwin Chaugule u8 space_id;
40337aadffSAshwin Chaugule u8 bit_width;
41337aadffSAshwin Chaugule u8 bit_offset;
42337aadffSAshwin Chaugule u8 access_width;
43d8f85cc0SIonela Voinescu u64 address;
44337aadffSAshwin Chaugule } __packed;
45337aadffSAshwin Chaugule
46337aadffSAshwin Chaugule /*
47337aadffSAshwin Chaugule * Each entry in the CPC table is either
48337aadffSAshwin Chaugule * of type ACPI_TYPE_BUFFER or
49337aadffSAshwin Chaugule * ACPI_TYPE_INTEGER.
50337aadffSAshwin Chaugule */
51337aadffSAshwin Chaugule struct cpc_register_resource {
52337aadffSAshwin Chaugule acpi_object_type type;
535bbb86aaSAshwin Chaugule u64 __iomem *sys_mem_vaddr;
54337aadffSAshwin Chaugule union {
55337aadffSAshwin Chaugule struct cpc_reg reg;
56337aadffSAshwin Chaugule u64 int_value;
57337aadffSAshwin Chaugule } cpc_entry;
58337aadffSAshwin Chaugule };
59337aadffSAshwin Chaugule
60337aadffSAshwin Chaugule /* Container to hold the CPC details for each CPU */
61337aadffSAshwin Chaugule struct cpc_desc {
62337aadffSAshwin Chaugule int num_entries;
63337aadffSAshwin Chaugule int version;
64337aadffSAshwin Chaugule int cpu_id;
6580b8286aSPrakash, Prashanth int write_cmd_status;
6680b8286aSPrakash, Prashanth int write_cmd_id;
6760949b7bSClément Léger /* Lock used for RMW operations in cpc_write() */
68*1c10941eSPierre Gondois raw_spinlock_t rmw_lock;
69337aadffSAshwin Chaugule struct cpc_register_resource cpc_regs[MAX_CPC_REG_ENT];
70337aadffSAshwin Chaugule struct acpi_psd_package domain_info;
71158c998eSAshwin Chaugule struct kobject kobj;
72337aadffSAshwin Chaugule };
73337aadffSAshwin Chaugule
74337aadffSAshwin Chaugule /* These are indexes into the per-cpu cpc_regs[]. Order is important. */
75337aadffSAshwin Chaugule enum cppc_regs {
76337aadffSAshwin Chaugule HIGHEST_PERF,
77337aadffSAshwin Chaugule NOMINAL_PERF,
78337aadffSAshwin Chaugule LOW_NON_LINEAR_PERF,
79337aadffSAshwin Chaugule LOWEST_PERF,
80337aadffSAshwin Chaugule GUARANTEED_PERF,
81337aadffSAshwin Chaugule DESIRED_PERF,
82337aadffSAshwin Chaugule MIN_PERF,
83337aadffSAshwin Chaugule MAX_PERF,
84337aadffSAshwin Chaugule PERF_REDUC_TOLERANCE,
85337aadffSAshwin Chaugule TIME_WINDOW,
86337aadffSAshwin Chaugule CTR_WRAP_TIME,
87337aadffSAshwin Chaugule REFERENCE_CTR,
88337aadffSAshwin Chaugule DELIVERED_CTR,
89337aadffSAshwin Chaugule PERF_LIMITED,
90337aadffSAshwin Chaugule ENABLE,
91337aadffSAshwin Chaugule AUTO_SEL_ENABLE,
92337aadffSAshwin Chaugule AUTO_ACT_WINDOW,
93337aadffSAshwin Chaugule ENERGY_PERF,
94337aadffSAshwin Chaugule REFERENCE_PERF,
954773e77cSPrashanth Prakash LOWEST_FREQ,
964773e77cSPrashanth Prakash NOMINAL_FREQ,
97337aadffSAshwin Chaugule };
98337aadffSAshwin Chaugule
99337aadffSAshwin Chaugule /*
100337aadffSAshwin Chaugule * Categorization of registers as described
101337aadffSAshwin Chaugule * in the ACPI v.5.1 spec.
102337aadffSAshwin Chaugule * XXX: Only filling up ones which are used by governors
103337aadffSAshwin Chaugule * today.
104337aadffSAshwin Chaugule */
105337aadffSAshwin Chaugule struct cppc_perf_caps {
10629523f09SSrinivas Pandruvada u32 guaranteed_perf;
107337aadffSAshwin Chaugule u32 highest_perf;
108337aadffSAshwin Chaugule u32 nominal_perf;
109337aadffSAshwin Chaugule u32 lowest_perf;
110368520a6SPrakash, Prashanth u32 lowest_nonlinear_perf;
1114773e77cSPrashanth Prakash u32 lowest_freq;
1124773e77cSPrashanth Prakash u32 nominal_freq;
1137bc1fcd3SPerry Yuan u32 energy_perf;
114c984f5d5SWyes Karny bool auto_sel;
115337aadffSAshwin Chaugule };
116337aadffSAshwin Chaugule
117337aadffSAshwin Chaugule struct cppc_perf_ctrls {
118337aadffSAshwin Chaugule u32 max_perf;
119337aadffSAshwin Chaugule u32 min_perf;
120337aadffSAshwin Chaugule u32 desired_perf;
1217bc1fcd3SPerry Yuan u32 energy_perf;
122337aadffSAshwin Chaugule };
123337aadffSAshwin Chaugule
124337aadffSAshwin Chaugule struct cppc_perf_fb_ctrs {
125337aadffSAshwin Chaugule u64 reference;
126337aadffSAshwin Chaugule u64 delivered;
127158c998eSAshwin Chaugule u64 reference_perf;
1282c74d847SPrakash, Prashanth u64 wraparound_time;
129337aadffSAshwin Chaugule };
130337aadffSAshwin Chaugule
131337aadffSAshwin Chaugule /* Per CPU container for runtime CPPC management. */
13241dd6403SSrinivas Pandruvada struct cppc_cpudata {
133a28b2bfcSIonela Voinescu struct list_head node;
134337aadffSAshwin Chaugule struct cppc_perf_caps perf_caps;
135337aadffSAshwin Chaugule struct cppc_perf_ctrls perf_ctrls;
136337aadffSAshwin Chaugule struct cppc_perf_fb_ctrs perf_fb_ctrs;
137337aadffSAshwin Chaugule unsigned int shared_type;
138337aadffSAshwin Chaugule cpumask_var_t shared_cpu_map;
139337aadffSAshwin Chaugule };
140337aadffSAshwin Chaugule
1418a02d998SRafael J. Wysocki #ifdef CONFIG_ACPI_CPPC_LIB
1421757d05fSXiongfeng Wang extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf);
1430654cf05SRafael J. Wysocki extern int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf);
14412753d71SMeng Li extern int cppc_get_highest_perf(int cpunum, u64 *highest_perf);
145337aadffSAshwin Chaugule extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs);
146337aadffSAshwin Chaugule extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls);
147fb0b00afSJinzhou Su extern int cppc_set_enable(int cpu, bool enable);
148337aadffSAshwin Chaugule extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps);
149ae2df912SJeremy Linton extern bool cppc_perf_ctrs_in_pcc(void);
15050b813b1SVincent Guittot extern unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned int perf);
15150b813b1SVincent Guittot extern unsigned int cppc_khz_to_perf(struct cppc_perf_caps *caps, unsigned int freq);
152a28b2bfcSIonela Voinescu extern bool acpi_cpc_valid(void);
1533cc30dd0SPierre Gondois extern bool cppc_allow_fast_switch(void);
154a28b2bfcSIonela Voinescu extern int acpi_get_psd_map(unsigned int cpu, struct cppc_cpudata *cpu_data);
155be8b88d7SPrakash, Prashanth extern unsigned int cppc_get_transition_latency(int cpu);
156ad3bc25aSBorislav Petkov extern bool cpc_ffh_supported(void);
1578b356e53SMario Limonciello extern bool cpc_supported_by_cpu(void);
158ad3bc25aSBorislav Petkov extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val);
159ad3bc25aSBorislav Petkov extern int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val);
1607bc1fcd3SPerry Yuan extern int cppc_get_epp_perf(int cpunum, u64 *epp_perf);
1617bc1fcd3SPerry Yuan extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable);
162c984f5d5SWyes Karny extern int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps);
163c984f5d5SWyes Karny extern int cppc_set_auto_sel(int cpu, bool enable);
1642819bfefSMario Limonciello extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf);
1656c09e3b4SMario Limonciello extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator);
166279f838aSMario Limonciello extern int amd_detect_prefcore(bool *detected);
1678a02d998SRafael J. Wysocki #else /* !CONFIG_ACPI_CPPC_LIB */
cppc_get_desired_perf(int cpunum,u64 * desired_perf)1688a02d998SRafael J. Wysocki static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf)
1698a02d998SRafael J. Wysocki {
17001ced022SMario Limonciello return -EOPNOTSUPP;
1718a02d998SRafael J. Wysocki }
cppc_get_nominal_perf(int cpunum,u64 * nominal_perf)1720654cf05SRafael J. Wysocki static inline int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf)
1730654cf05SRafael J. Wysocki {
17401ced022SMario Limonciello return -EOPNOTSUPP;
1750654cf05SRafael J. Wysocki }
cppc_get_highest_perf(int cpunum,u64 * highest_perf)17612753d71SMeng Li static inline int cppc_get_highest_perf(int cpunum, u64 *highest_perf)
17712753d71SMeng Li {
17801ced022SMario Limonciello return -EOPNOTSUPP;
17912753d71SMeng Li }
cppc_get_perf_ctrs(int cpu,struct cppc_perf_fb_ctrs * perf_fb_ctrs)1808a02d998SRafael J. Wysocki static inline int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
1818a02d998SRafael J. Wysocki {
18201ced022SMario Limonciello return -EOPNOTSUPP;
1838a02d998SRafael J. Wysocki }
cppc_set_perf(int cpu,struct cppc_perf_ctrls * perf_ctrls)1848a02d998SRafael J. Wysocki static inline int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
1858a02d998SRafael J. Wysocki {
18601ced022SMario Limonciello return -EOPNOTSUPP;
1878a02d998SRafael J. Wysocki }
cppc_set_enable(int cpu,bool enable)188fb0b00afSJinzhou Su static inline int cppc_set_enable(int cpu, bool enable)
189fb0b00afSJinzhou Su {
19001ced022SMario Limonciello return -EOPNOTSUPP;
191fb0b00afSJinzhou Su }
cppc_get_perf_caps(int cpu,struct cppc_perf_caps * caps)1928a02d998SRafael J. Wysocki static inline int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps)
1938a02d998SRafael J. Wysocki {
19401ced022SMario Limonciello return -EOPNOTSUPP;
1958a02d998SRafael J. Wysocki }
cppc_perf_ctrs_in_pcc(void)196ae2df912SJeremy Linton static inline bool cppc_perf_ctrs_in_pcc(void)
197ae2df912SJeremy Linton {
198ae2df912SJeremy Linton return false;
199ae2df912SJeremy Linton }
acpi_cpc_valid(void)2008a02d998SRafael J. Wysocki static inline bool acpi_cpc_valid(void)
2018a02d998SRafael J. Wysocki {
2028a02d998SRafael J. Wysocki return false;
2038a02d998SRafael J. Wysocki }
cppc_allow_fast_switch(void)2043cc30dd0SPierre Gondois static inline bool cppc_allow_fast_switch(void)
2053cc30dd0SPierre Gondois {
2063cc30dd0SPierre Gondois return false;
2073cc30dd0SPierre Gondois }
cppc_get_transition_latency(int cpu)2088a02d998SRafael J. Wysocki static inline unsigned int cppc_get_transition_latency(int cpu)
2098a02d998SRafael J. Wysocki {
2108a02d998SRafael J. Wysocki return CPUFREQ_ETERNAL;
2118a02d998SRafael J. Wysocki }
cpc_ffh_supported(void)2128a02d998SRafael J. Wysocki static inline bool cpc_ffh_supported(void)
2138a02d998SRafael J. Wysocki {
2148a02d998SRafael J. Wysocki return false;
2158a02d998SRafael J. Wysocki }
cpc_read_ffh(int cpunum,struct cpc_reg * reg,u64 * val)2168a02d998SRafael J. Wysocki static inline int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val)
2178a02d998SRafael J. Wysocki {
21801ced022SMario Limonciello return -EOPNOTSUPP;
2198a02d998SRafael J. Wysocki }
cpc_write_ffh(int cpunum,struct cpc_reg * reg,u64 val)2208a02d998SRafael J. Wysocki static inline int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
2218a02d998SRafael J. Wysocki {
22201ced022SMario Limonciello return -EOPNOTSUPP;
2238a02d998SRafael J. Wysocki }
cppc_set_epp_perf(int cpu,struct cppc_perf_ctrls * perf_ctrls,bool enable)2247bc1fcd3SPerry Yuan static inline int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)
2257bc1fcd3SPerry Yuan {
22601ced022SMario Limonciello return -EOPNOTSUPP;
2277bc1fcd3SPerry Yuan }
cppc_get_epp_perf(int cpunum,u64 * epp_perf)2287bc1fcd3SPerry Yuan static inline int cppc_get_epp_perf(int cpunum, u64 *epp_perf)
2297bc1fcd3SPerry Yuan {
23001ced022SMario Limonciello return -EOPNOTSUPP;
2317bc1fcd3SPerry Yuan }
cppc_set_auto_sel(int cpu,bool enable)232c984f5d5SWyes Karny static inline int cppc_set_auto_sel(int cpu, bool enable)
233c984f5d5SWyes Karny {
23401ced022SMario Limonciello return -EOPNOTSUPP;
235c984f5d5SWyes Karny }
cppc_get_auto_sel_caps(int cpunum,struct cppc_perf_caps * perf_caps)236c984f5d5SWyes Karny static inline int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps)
237c984f5d5SWyes Karny {
23801ced022SMario Limonciello return -EOPNOTSUPP;
239c984f5d5SWyes Karny }
amd_get_highest_perf(unsigned int cpu,u32 * highest_perf)2402819bfefSMario Limonciello static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf)
2412819bfefSMario Limonciello {
2422819bfefSMario Limonciello return -ENODEV;
2432819bfefSMario Limonciello }
amd_get_boost_ratio_numerator(unsigned int cpu,u64 * numerator)2446c09e3b4SMario Limonciello static inline int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)
2456c09e3b4SMario Limonciello {
2466c09e3b4SMario Limonciello return -EOPNOTSUPP;
2476c09e3b4SMario Limonciello }
amd_detect_prefcore(bool * detected)248279f838aSMario Limonciello static inline int amd_detect_prefcore(bool *detected)
249279f838aSMario Limonciello {
250279f838aSMario Limonciello return -ENODEV;
251337aadffSAshwin Chaugule }
252337aadffSAshwin Chaugule #endif /* !CONFIG_ACPI_CPPC_LIB */
253337aadffSAshwin Chaugule
254337aadffSAshwin Chaugule #endif /* _CPPC_ACPI_H*/
255