Thomas Gleixner | b886d83 | 2019-06-01 10:08:55 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 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> |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #ifndef _CPPC_ACPI_H |
| 11 | #define _CPPC_ACPI_H |
| 12 | |
| 13 | #include <linux/acpi.h> |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 14 | #include <linux/types.h> |
| 15 | |
Hoan Tran | 866ae69 | 2016-06-16 14:09:38 -0700 | [diff] [blame] | 16 | #include <acpi/pcc.h> |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 17 | #include <acpi/processor.h> |
| 18 | |
Prashanth Prakash | 4773e77 | 2018-04-04 12:14:50 -0600 | [diff] [blame] | 19 | /* Support CPPCv2 and CPPCv3 */ |
| 20 | #define CPPC_V2_REV 2 |
| 21 | #define CPPC_V3_REV 3 |
| 22 | #define CPPC_V2_NUM_ENT 21 |
| 23 | #define CPPC_V3_NUM_ENT 23 |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 24 | |
Prakash, Prashanth | 139aee7 | 2016-08-16 14:39:44 -0600 | [diff] [blame] | 25 | #define PCC_CMD_COMPLETE_MASK (1 << 0) |
| 26 | #define PCC_ERROR_MASK (1 << 2) |
| 27 | |
Prashanth Prakash | 4773e77 | 2018-04-04 12:14:50 -0600 | [diff] [blame] | 28 | #define MAX_CPC_REG_ENT 21 |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 29 | |
| 30 | /* CPPC specific PCC commands. */ |
| 31 | #define CMD_READ 0 |
| 32 | #define CMD_WRITE 1 |
| 33 | |
| 34 | /* Each register has the folowing format. */ |
| 35 | struct cpc_reg { |
| 36 | u8 descriptor; |
| 37 | u16 length; |
| 38 | u8 space_id; |
| 39 | u8 bit_width; |
| 40 | u8 bit_offset; |
| 41 | u8 access_width; |
| 42 | u64 __iomem address; |
| 43 | } __packed; |
| 44 | |
| 45 | /* |
| 46 | * Each entry in the CPC table is either |
| 47 | * of type ACPI_TYPE_BUFFER or |
| 48 | * ACPI_TYPE_INTEGER. |
| 49 | */ |
| 50 | struct cpc_register_resource { |
| 51 | acpi_object_type type; |
Ashwin Chaugule | 5bbb86a | 2016-08-16 14:39:38 -0600 | [diff] [blame] | 52 | u64 __iomem *sys_mem_vaddr; |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 53 | union { |
| 54 | struct cpc_reg reg; |
| 55 | u64 int_value; |
| 56 | } cpc_entry; |
| 57 | }; |
| 58 | |
| 59 | /* Container to hold the CPC details for each CPU */ |
| 60 | struct cpc_desc { |
| 61 | int num_entries; |
| 62 | int version; |
| 63 | int cpu_id; |
Prakash, Prashanth | 80b8286 | 2016-08-16 14:39:40 -0600 | [diff] [blame] | 64 | int write_cmd_status; |
| 65 | int write_cmd_id; |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 66 | struct cpc_register_resource cpc_regs[MAX_CPC_REG_ENT]; |
| 67 | struct acpi_psd_package domain_info; |
Ashwin Chaugule | 158c998 | 2016-08-16 14:39:42 -0600 | [diff] [blame] | 68 | struct kobject kobj; |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /* These are indexes into the per-cpu cpc_regs[]. Order is important. */ |
| 72 | enum cppc_regs { |
| 73 | HIGHEST_PERF, |
| 74 | NOMINAL_PERF, |
| 75 | LOW_NON_LINEAR_PERF, |
| 76 | LOWEST_PERF, |
| 77 | GUARANTEED_PERF, |
| 78 | DESIRED_PERF, |
| 79 | MIN_PERF, |
| 80 | MAX_PERF, |
| 81 | PERF_REDUC_TOLERANCE, |
| 82 | TIME_WINDOW, |
| 83 | CTR_WRAP_TIME, |
| 84 | REFERENCE_CTR, |
| 85 | DELIVERED_CTR, |
| 86 | PERF_LIMITED, |
| 87 | ENABLE, |
| 88 | AUTO_SEL_ENABLE, |
| 89 | AUTO_ACT_WINDOW, |
| 90 | ENERGY_PERF, |
| 91 | REFERENCE_PERF, |
Prashanth Prakash | 4773e77 | 2018-04-04 12:14:50 -0600 | [diff] [blame] | 92 | LOWEST_FREQ, |
| 93 | NOMINAL_FREQ, |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | /* |
| 97 | * Categorization of registers as described |
| 98 | * in the ACPI v.5.1 spec. |
| 99 | * XXX: Only filling up ones which are used by governors |
| 100 | * today. |
| 101 | */ |
| 102 | struct cppc_perf_caps { |
Srinivas Pandruvada | 29523f0 | 2018-10-15 10:37:19 -0700 | [diff] [blame] | 103 | u32 guaranteed_perf; |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 104 | u32 highest_perf; |
| 105 | u32 nominal_perf; |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 106 | u32 lowest_perf; |
Prakash, Prashanth | 368520a | 2017-03-29 13:49:59 -0600 | [diff] [blame] | 107 | u32 lowest_nonlinear_perf; |
Prashanth Prakash | 4773e77 | 2018-04-04 12:14:50 -0600 | [diff] [blame] | 108 | u32 lowest_freq; |
| 109 | u32 nominal_freq; |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | struct cppc_perf_ctrls { |
| 113 | u32 max_perf; |
| 114 | u32 min_perf; |
| 115 | u32 desired_perf; |
| 116 | }; |
| 117 | |
| 118 | struct cppc_perf_fb_ctrs { |
| 119 | u64 reference; |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 120 | u64 delivered; |
Ashwin Chaugule | 158c998 | 2016-08-16 14:39:42 -0600 | [diff] [blame] | 121 | u64 reference_perf; |
Prakash, Prashanth | 2c74d84 | 2017-03-29 13:50:00 -0600 | [diff] [blame] | 122 | u64 wraparound_time; |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | /* Per CPU container for runtime CPPC management. */ |
Srinivas Pandruvada | 41dd640 | 2016-09-01 13:37:11 -0700 | [diff] [blame] | 126 | struct cppc_cpudata { |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 127 | int cpu; |
| 128 | struct cppc_perf_caps perf_caps; |
| 129 | struct cppc_perf_ctrls perf_ctrls; |
| 130 | struct cppc_perf_fb_ctrs perf_fb_ctrs; |
| 131 | struct cpufreq_policy *cur_policy; |
| 132 | unsigned int shared_type; |
| 133 | cpumask_var_t shared_cpu_map; |
| 134 | }; |
| 135 | |
Xiongfeng Wang | 1757d05 | 2019-02-17 11:54:14 +0800 | [diff] [blame] | 136 | extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf); |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 137 | extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs); |
| 138 | extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls); |
| 139 | extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps); |
Srinivas Pandruvada | 41dd640 | 2016-09-01 13:37:11 -0700 | [diff] [blame] | 140 | extern int acpi_get_psd_map(struct cppc_cpudata **); |
Prakash, Prashanth | be8b88d | 2016-08-16 14:39:41 -0600 | [diff] [blame] | 141 | extern unsigned int cppc_get_transition_latency(int cpu); |
Borislav Petkov | ad3bc25 | 2018-12-05 00:34:56 +0100 | [diff] [blame] | 142 | extern bool cpc_ffh_supported(void); |
| 143 | extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val); |
| 144 | extern int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val); |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 145 | |
Ashwin Chaugule | 337aadf | 2015-10-02 10:01:19 -0400 | [diff] [blame] | 146 | #endif /* _CPPC_ACPI_H*/ |