Commit | Line | Data |
---|---|---|
ff956826 ZR |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* | |
3 | * Data types and headers for RAPL support | |
4 | * | |
5 | * Copyright (C) 2019 Intel Corporation. | |
6 | * | |
7 | * Author: Zhang Rui <rui.zhang@intel.com> | |
8 | */ | |
9 | ||
10 | #ifndef __INTEL_RAPL_H__ | |
11 | #define __INTEL_RAPL_H__ | |
12 | ||
13 | #include <linux/types.h> | |
14 | #include <linux/powercap.h> | |
8da04e05 | 15 | #include <linux/cpuhotplug.h> |
ff956826 | 16 | |
b4288ce7 ZR |
17 | enum rapl_if_type { |
18 | RAPL_IF_MSR, /* RAPL I/F using MSR registers */ | |
19 | RAPL_IF_MMIO, /* RAPL I/F using MMIO registers */ | |
20 | }; | |
21 | ||
ff956826 ZR |
22 | enum rapl_domain_type { |
23 | RAPL_DOMAIN_PACKAGE, /* entire package/socket */ | |
24 | RAPL_DOMAIN_PP0, /* core power plane */ | |
25 | RAPL_DOMAIN_PP1, /* graphics uncore */ | |
26 | RAPL_DOMAIN_DRAM, /* DRAM control_type */ | |
27 | RAPL_DOMAIN_PLATFORM, /* PSys control_type */ | |
28 | RAPL_DOMAIN_MAX, | |
29 | }; | |
30 | ||
31 | enum rapl_domain_reg_id { | |
32 | RAPL_DOMAIN_REG_LIMIT, | |
33 | RAPL_DOMAIN_REG_STATUS, | |
34 | RAPL_DOMAIN_REG_PERF, | |
35 | RAPL_DOMAIN_REG_POLICY, | |
36 | RAPL_DOMAIN_REG_INFO, | |
8365a898 | 37 | RAPL_DOMAIN_REG_PL4, |
cb532e72 | 38 | RAPL_DOMAIN_REG_UNIT, |
ff956826 ZR |
39 | RAPL_DOMAIN_REG_MAX, |
40 | }; | |
41 | ||
35eb1f50 | 42 | struct rapl_domain; |
ff956826 ZR |
43 | |
44 | enum rapl_primitives { | |
ff956826 ZR |
45 | POWER_LIMIT1, |
46 | POWER_LIMIT2, | |
8365a898 | 47 | POWER_LIMIT4, |
045610c3 | 48 | ENERGY_COUNTER, |
ff956826 | 49 | FW_LOCK, |
f442bd27 | 50 | FW_HIGH_LOCK, |
ff956826 ZR |
51 | |
52 | PL1_ENABLE, /* power limit 1, aka long term */ | |
53 | PL1_CLAMP, /* allow frequency to go below OS request */ | |
54 | PL2_ENABLE, /* power limit 2, aka short term, instantaneous */ | |
55 | PL2_CLAMP, | |
8365a898 | 56 | PL4_ENABLE, /* power limit 4, aka max peak power */ |
ff956826 ZR |
57 | |
58 | TIME_WINDOW1, /* long term */ | |
59 | TIME_WINDOW2, /* short term */ | |
60 | THERMAL_SPEC_POWER, | |
61 | MAX_POWER, | |
62 | ||
63 | MIN_POWER, | |
64 | MAX_TIME_WINDOW, | |
65 | THROTTLED_TIME, | |
66 | PRIORITY_LEVEL, | |
67 | ||
931da6a0 ZR |
68 | PSYS_POWER_LIMIT1, |
69 | PSYS_POWER_LIMIT2, | |
70 | PSYS_PL1_ENABLE, | |
71 | PSYS_PL2_ENABLE, | |
72 | PSYS_TIME_WINDOW1, | |
73 | PSYS_TIME_WINDOW2, | |
ff956826 ZR |
74 | /* below are not raw primitive data */ |
75 | AVERAGE_POWER, | |
76 | NR_RAPL_PRIMITIVES, | |
77 | }; | |
78 | ||
79 | struct rapl_domain_data { | |
80 | u64 primitives[NR_RAPL_PRIMITIVES]; | |
81 | unsigned long timestamp; | |
82 | }; | |
83 | ||
045610c3 ZR |
84 | #define NR_POWER_LIMITS (POWER_LIMIT4 + 1) |
85 | ||
ff956826 ZR |
86 | struct rapl_power_limit { |
87 | struct powercap_zone_constraint *constraint; | |
ff956826 ZR |
88 | struct rapl_domain *domain; |
89 | const char *name; | |
f442bd27 | 90 | bool locked; |
ff956826 ZR |
91 | u64 last_power_limit; |
92 | }; | |
93 | ||
94 | struct rapl_package; | |
95 | ||
f1e8d756 ZR |
96 | #define RAPL_DOMAIN_NAME_LENGTH 16 |
97 | ||
ff956826 | 98 | struct rapl_domain { |
f1e8d756 | 99 | char name[RAPL_DOMAIN_NAME_LENGTH]; |
ff956826 | 100 | enum rapl_domain_type id; |
d978e755 | 101 | u64 regs[RAPL_DOMAIN_REG_MAX]; |
ff956826 ZR |
102 | struct powercap_zone power_zone; |
103 | struct rapl_domain_data rdd; | |
104 | struct rapl_power_limit rpl[NR_POWER_LIMITS]; | |
105 | u64 attr_map; /* track capabilities */ | |
106 | unsigned int state; | |
cb532e72 ZR |
107 | unsigned int power_unit; |
108 | unsigned int energy_unit; | |
109 | unsigned int time_unit; | |
ff956826 ZR |
110 | struct rapl_package *rp; |
111 | }; | |
112 | ||
beea8df8 | 113 | struct reg_action { |
d978e755 | 114 | u64 reg; |
beea8df8 ZR |
115 | u64 mask; |
116 | u64 value; | |
117 | int err; | |
118 | }; | |
119 | ||
7ebf8eff ZR |
120 | /** |
121 | * struct rapl_if_priv: private data for different RAPL interfaces | |
122 | * @control_type: Each RAPL interface must have its own powercap | |
123 | * control type. | |
124 | * @platform_rapl_domain: Optional. Some RAPL interface may have platform | |
125 | * level RAPL control. | |
126 | * @pcap_rapl_online: CPU hotplug state for each RAPL interface. | |
7fde2712 ZR |
127 | * @reg_unit: Register for getting energy/power/time unit. |
128 | * @regs: Register sets for different RAPL Domains. | |
0c2ddedd | 129 | * @limits: Number of power limits supported by each domain. |
beea8df8 ZR |
130 | * @read_raw: Callback for reading RAPL interface specific |
131 | * registers. | |
132 | * @write_raw: Callback for writing RAPL interface specific | |
133 | * registers. | |
e8e28c2a | 134 | * @defaults: internal pointer to interface default settings |
98ff639a | 135 | * @rpi: internal pointer to interface primitive info |
7ebf8eff ZR |
136 | */ |
137 | struct rapl_if_priv { | |
b4288ce7 | 138 | enum rapl_if_type type; |
7ebf8eff | 139 | struct powercap_control_type *control_type; |
7ebf8eff | 140 | enum cpuhp_state pcap_rapl_online; |
d978e755 ZR |
141 | u64 reg_unit; |
142 | u64 regs[RAPL_DOMAIN_MAX][RAPL_DOMAIN_REG_MAX]; | |
0c2ddedd | 143 | int limits[RAPL_DOMAIN_MAX]; |
bf44b901 ZR |
144 | int (*read_raw)(int id, struct reg_action *ra); |
145 | int (*write_raw)(int id, struct reg_action *ra); | |
e8e28c2a | 146 | void *defaults; |
98ff639a | 147 | void *rpi; |
7ebf8eff ZR |
148 | }; |
149 | ||
ff956826 ZR |
150 | /* maximum rapl package domain name: package-%d-die-%d */ |
151 | #define PACKAGE_DOMAIN_NAME_LENGTH 30 | |
152 | ||
153 | struct rapl_package { | |
154 | unsigned int id; /* logical die id, equals physical 1-die systems */ | |
155 | unsigned int nr_domains; | |
156 | unsigned long domain_map; /* bit map of active domains */ | |
ff956826 ZR |
157 | struct rapl_domain *domains; /* array of domains, sized at runtime */ |
158 | struct powercap_zone *power_zone; /* keep track of parent zone */ | |
159 | unsigned long power_limit_irq; /* keep track of package power limit | |
160 | * notify interrupt enable status. | |
161 | */ | |
162 | struct list_head plist; | |
163 | int lead_cpu; /* one active cpu per package for access */ | |
164 | /* Track active cpus */ | |
165 | struct cpumask cpumask; | |
166 | char name[PACKAGE_DOMAIN_NAME_LENGTH]; | |
7ebf8eff | 167 | struct rapl_if_priv *priv; |
ff956826 ZR |
168 | }; |
169 | ||
bf44b901 ZR |
170 | struct rapl_package *rapl_find_package_domain(int id, struct rapl_if_priv *priv, bool id_is_cpu); |
171 | struct rapl_package *rapl_add_package(int id, struct rapl_if_priv *priv, bool id_is_cpu); | |
3382388d ZR |
172 | void rapl_remove_package(struct rapl_package *rp); |
173 | ||
ff956826 | 174 | #endif /* __INTEL_RAPL_H__ */ |