1
2
3
4
5
6
7
8
9
10 #ifndef __INTEL_RAPL_H__
11 #define __INTEL_RAPL_H__
12
13 #include <linux/types.h>
14 #include <linux/powercap.h>
15 #include <linux/cpuhotplug.h>
16
17 enum rapl_domain_type {
18 RAPL_DOMAIN_PACKAGE,
19 RAPL_DOMAIN_PP0,
20 RAPL_DOMAIN_PP1,
21 RAPL_DOMAIN_DRAM,
22 RAPL_DOMAIN_PLATFORM,
23 RAPL_DOMAIN_MAX,
24 };
25
26 enum rapl_domain_reg_id {
27 RAPL_DOMAIN_REG_LIMIT,
28 RAPL_DOMAIN_REG_STATUS,
29 RAPL_DOMAIN_REG_PERF,
30 RAPL_DOMAIN_REG_POLICY,
31 RAPL_DOMAIN_REG_INFO,
32 RAPL_DOMAIN_REG_MAX,
33 };
34
35 struct rapl_package;
36
37 enum rapl_primitives {
38 ENERGY_COUNTER,
39 POWER_LIMIT1,
40 POWER_LIMIT2,
41 FW_LOCK,
42
43 PL1_ENABLE,
44 PL1_CLAMP,
45 PL2_ENABLE,
46 PL2_CLAMP,
47
48 TIME_WINDOW1,
49 TIME_WINDOW2,
50 THERMAL_SPEC_POWER,
51 MAX_POWER,
52
53 MIN_POWER,
54 MAX_TIME_WINDOW,
55 THROTTLED_TIME,
56 PRIORITY_LEVEL,
57
58
59 AVERAGE_POWER,
60 NR_RAPL_PRIMITIVES,
61 };
62
63 struct rapl_domain_data {
64 u64 primitives[NR_RAPL_PRIMITIVES];
65 unsigned long timestamp;
66 };
67
68 #define NR_POWER_LIMITS (2)
69 struct rapl_power_limit {
70 struct powercap_zone_constraint *constraint;
71 int prim_id;
72 struct rapl_domain *domain;
73 const char *name;
74 u64 last_power_limit;
75 };
76
77 struct rapl_package;
78
79 struct rapl_domain {
80 const char *name;
81 enum rapl_domain_type id;
82 u64 regs[RAPL_DOMAIN_REG_MAX];
83 struct powercap_zone power_zone;
84 struct rapl_domain_data rdd;
85 struct rapl_power_limit rpl[NR_POWER_LIMITS];
86 u64 attr_map;
87 unsigned int state;
88 unsigned int domain_energy_unit;
89 struct rapl_package *rp;
90 };
91
92 struct reg_action {
93 u64 reg;
94 u64 mask;
95 u64 value;
96 int err;
97 };
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 struct rapl_if_priv {
115 struct powercap_control_type *control_type;
116 struct rapl_domain *platform_rapl_domain;
117 enum cpuhp_state pcap_rapl_online;
118 u64 reg_unit;
119 u64 regs[RAPL_DOMAIN_MAX][RAPL_DOMAIN_REG_MAX];
120 int limits[RAPL_DOMAIN_MAX];
121 int (*read_raw)(int cpu, struct reg_action *ra);
122 int (*write_raw)(int cpu, struct reg_action *ra);
123 };
124
125
126 #define PACKAGE_DOMAIN_NAME_LENGTH 30
127
128 struct rapl_package {
129 unsigned int id;
130 unsigned int nr_domains;
131 unsigned long domain_map;
132 unsigned int power_unit;
133 unsigned int energy_unit;
134 unsigned int time_unit;
135 struct rapl_domain *domains;
136 struct powercap_zone *power_zone;
137 unsigned long power_limit_irq;
138
139
140 struct list_head plist;
141 int lead_cpu;
142
143 struct cpumask cpumask;
144 char name[PACKAGE_DOMAIN_NAME_LENGTH];
145 struct rapl_if_priv *priv;
146 };
147
148 struct rapl_package *rapl_find_package_domain(int cpu, struct rapl_if_priv *priv);
149 struct rapl_package *rapl_add_package(int cpu, struct rapl_if_priv *priv);
150 void rapl_remove_package(struct rapl_package *rp);
151
152 int rapl_add_platform_domain(struct rapl_if_priv *priv);
153 void rapl_remove_platform_domain(struct rapl_if_priv *priv);
154
155 #endif