Merge tag 'input-for-v6.4-rc0' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor...
[linux-block.git] / include / acpi / cppc_acpi.h
CommitLineData
b886d83c 1/* SPDX-License-Identifier: GPL-2.0-only */
337aadff
AC
2/*
3 * CPPC (Collaborative Processor Performance Control) methods used
4 * by CPUfreq drivers.
5 *
6 * (C) Copyright 2014, 2015 Linaro Ltd.
7 * Author: Ashwin Chaugule <ashwin.chaugule@linaro.org>
337aadff
AC
8 */
9
10#ifndef _CPPC_ACPI_H
11#define _CPPC_ACPI_H
12
13#include <linux/acpi.h>
8a02d998 14#include <linux/cpufreq.h>
337aadff
AC
15#include <linux/types.h>
16
866ae696 17#include <acpi/pcc.h>
337aadff
AC
18#include <acpi/processor.h>
19
4f4179fc 20/* CPPCv2 and CPPCv3 support */
4773e77c
PP
21#define CPPC_V2_REV 2
22#define CPPC_V3_REV 3
23#define CPPC_V2_NUM_ENT 21
24#define CPPC_V3_NUM_ENT 23
337aadff 25
139aee73
PP
26#define PCC_CMD_COMPLETE_MASK (1 << 0)
27#define PCC_ERROR_MASK (1 << 2)
28
4773e77c 29#define MAX_CPC_REG_ENT 21
337aadff
AC
30
31/* CPPC specific PCC commands. */
32#define CMD_READ 0
33#define CMD_WRITE 1
34
35/* Each register has the folowing format. */
36struct cpc_reg {
37 u8 descriptor;
38 u16 length;
39 u8 space_id;
40 u8 bit_width;
41 u8 bit_offset;
42 u8 access_width;
d8f85cc0 43 u64 address;
337aadff
AC
44} __packed;
45
46/*
47 * Each entry in the CPC table is either
48 * of type ACPI_TYPE_BUFFER or
49 * ACPI_TYPE_INTEGER.
50 */
51struct cpc_register_resource {
52 acpi_object_type type;
5bbb86aa 53 u64 __iomem *sys_mem_vaddr;
337aadff
AC
54 union {
55 struct cpc_reg reg;
56 u64 int_value;
57 } cpc_entry;
58};
59
60/* Container to hold the CPC details for each CPU */
61struct cpc_desc {
62 int num_entries;
63 int version;
64 int cpu_id;
80b8286a
PP
65 int write_cmd_status;
66 int write_cmd_id;
337aadff
AC
67 struct cpc_register_resource cpc_regs[MAX_CPC_REG_ENT];
68 struct acpi_psd_package domain_info;
158c998e 69 struct kobject kobj;
337aadff
AC
70};
71
72/* These are indexes into the per-cpu cpc_regs[]. Order is important. */
73enum cppc_regs {
74 HIGHEST_PERF,
75 NOMINAL_PERF,
76 LOW_NON_LINEAR_PERF,
77 LOWEST_PERF,
78 GUARANTEED_PERF,
79 DESIRED_PERF,
80 MIN_PERF,
81 MAX_PERF,
82 PERF_REDUC_TOLERANCE,
83 TIME_WINDOW,
84 CTR_WRAP_TIME,
85 REFERENCE_CTR,
86 DELIVERED_CTR,
87 PERF_LIMITED,
88 ENABLE,
89 AUTO_SEL_ENABLE,
90 AUTO_ACT_WINDOW,
91 ENERGY_PERF,
92 REFERENCE_PERF,
4773e77c
PP
93 LOWEST_FREQ,
94 NOMINAL_FREQ,
337aadff
AC
95};
96
97/*
98 * Categorization of registers as described
99 * in the ACPI v.5.1 spec.
100 * XXX: Only filling up ones which are used by governors
101 * today.
102 */
103struct cppc_perf_caps {
29523f09 104 u32 guaranteed_perf;
337aadff
AC
105 u32 highest_perf;
106 u32 nominal_perf;
337aadff 107 u32 lowest_perf;
368520a6 108 u32 lowest_nonlinear_perf;
4773e77c
PP
109 u32 lowest_freq;
110 u32 nominal_freq;
7bc1fcd3 111 u32 energy_perf;
c984f5d5 112 bool auto_sel;
337aadff
AC
113};
114
115struct cppc_perf_ctrls {
116 u32 max_perf;
117 u32 min_perf;
118 u32 desired_perf;
7bc1fcd3 119 u32 energy_perf;
337aadff
AC
120};
121
122struct cppc_perf_fb_ctrs {
123 u64 reference;
337aadff 124 u64 delivered;
158c998e 125 u64 reference_perf;
2c74d847 126 u64 wraparound_time;
337aadff
AC
127};
128
129/* Per CPU container for runtime CPPC management. */
41dd6403 130struct cppc_cpudata {
a28b2bfc 131 struct list_head node;
337aadff
AC
132 struct cppc_perf_caps perf_caps;
133 struct cppc_perf_ctrls perf_ctrls;
134 struct cppc_perf_fb_ctrs perf_fb_ctrs;
337aadff
AC
135 unsigned int shared_type;
136 cpumask_var_t shared_cpu_map;
137};
138
8a02d998 139#ifdef CONFIG_ACPI_CPPC_LIB
1757d05f 140extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf);
0654cf05 141extern int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf);
337aadff
AC
142extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs);
143extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls);
fb0b00af 144extern int cppc_set_enable(int cpu, bool enable);
337aadff 145extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps);
ae2df912 146extern bool cppc_perf_ctrs_in_pcc(void);
a28b2bfc 147extern bool acpi_cpc_valid(void);
3cc30dd0 148extern bool cppc_allow_fast_switch(void);
a28b2bfc 149extern int acpi_get_psd_map(unsigned int cpu, struct cppc_cpudata *cpu_data);
be8b88d7 150extern unsigned int cppc_get_transition_latency(int cpu);
ad3bc25a 151extern bool cpc_ffh_supported(void);
8b356e53 152extern bool cpc_supported_by_cpu(void);
ad3bc25a
BP
153extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val);
154extern int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val);
7bc1fcd3
PY
155extern int cppc_get_epp_perf(int cpunum, u64 *epp_perf);
156extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable);
c984f5d5
WK
157extern int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps);
158extern int cppc_set_auto_sel(int cpu, bool enable);
8a02d998
RW
159#else /* !CONFIG_ACPI_CPPC_LIB */
160static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf)
161{
162 return -ENOTSUPP;
163}
0654cf05
RW
164static inline int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf)
165{
166 return -ENOTSUPP;
167}
8a02d998
RW
168static inline int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs)
169{
170 return -ENOTSUPP;
171}
172static inline int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
173{
174 return -ENOTSUPP;
175}
fb0b00af
JS
176static inline int cppc_set_enable(int cpu, bool enable)
177{
178 return -ENOTSUPP;
179}
8a02d998
RW
180static inline int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps)
181{
182 return -ENOTSUPP;
183}
ae2df912
JL
184static inline bool cppc_perf_ctrs_in_pcc(void)
185{
186 return false;
187}
8a02d998
RW
188static inline bool acpi_cpc_valid(void)
189{
190 return false;
191}
3cc30dd0
PG
192static inline bool cppc_allow_fast_switch(void)
193{
194 return false;
195}
8a02d998
RW
196static inline unsigned int cppc_get_transition_latency(int cpu)
197{
198 return CPUFREQ_ETERNAL;
199}
200static inline bool cpc_ffh_supported(void)
201{
202 return false;
203}
204static inline int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val)
205{
206 return -ENOTSUPP;
207}
208static inline int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
209{
210 return -ENOTSUPP;
211}
7bc1fcd3
PY
212static inline int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)
213{
214 return -ENOTSUPP;
215}
216static inline int cppc_get_epp_perf(int cpunum, u64 *epp_perf)
217{
218 return -ENOTSUPP;
219}
c984f5d5
WK
220static inline int cppc_set_auto_sel(int cpu, bool enable)
221{
222 return -ENOTSUPP;
223}
224static inline int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps)
225{
226 return -ENOTSUPP;
227}
8a02d998 228#endif /* !CONFIG_ACPI_CPPC_LIB */
337aadff 229
337aadff 230#endif /* _CPPC_ACPI_H*/