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
17enum 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
26enum 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_PL4,
33 RAPL_DOMAIN_REG_MAX,
34};
35
36struct rapl_package;
37
38enum rapl_primitives {
39 ENERGY_COUNTER,
40 POWER_LIMIT1,
41 POWER_LIMIT2,
42 POWER_LIMIT4,
43 FW_LOCK,
44
45 PL1_ENABLE,
46 PL1_CLAMP,
47 PL2_ENABLE,
48 PL2_CLAMP,
49 PL4_ENABLE,
50
51 TIME_WINDOW1,
52 TIME_WINDOW2,
53 THERMAL_SPEC_POWER,
54 MAX_POWER,
55
56 MIN_POWER,
57 MAX_TIME_WINDOW,
58 THROTTLED_TIME,
59 PRIORITY_LEVEL,
60
61
62 AVERAGE_POWER,
63 NR_RAPL_PRIMITIVES,
64};
65
66struct rapl_domain_data {
67 u64 primitives[NR_RAPL_PRIMITIVES];
68 unsigned long timestamp;
69};
70
71#define NR_POWER_LIMITS (3)
72struct rapl_power_limit {
73 struct powercap_zone_constraint *constraint;
74 int prim_id;
75 struct rapl_domain *domain;
76 const char *name;
77 u64 last_power_limit;
78};
79
80struct rapl_package;
81
82struct rapl_domain {
83 const char *name;
84 enum rapl_domain_type id;
85 u64 regs[RAPL_DOMAIN_REG_MAX];
86 struct powercap_zone power_zone;
87 struct rapl_domain_data rdd;
88 struct rapl_power_limit rpl[NR_POWER_LIMITS];
89 u64 attr_map;
90 unsigned int state;
91 unsigned int domain_energy_unit;
92 struct rapl_package *rp;
93};
94
95struct reg_action {
96 u64 reg;
97 u64 mask;
98 u64 value;
99 int err;
100};
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117struct rapl_if_priv {
118 struct powercap_control_type *control_type;
119 struct rapl_domain *platform_rapl_domain;
120 enum cpuhp_state pcap_rapl_online;
121 u64 reg_unit;
122 u64 regs[RAPL_DOMAIN_MAX][RAPL_DOMAIN_REG_MAX];
123 int limits[RAPL_DOMAIN_MAX];
124 int (*read_raw)(int cpu, struct reg_action *ra);
125 int (*write_raw)(int cpu, struct reg_action *ra);
126};
127
128
129#define PACKAGE_DOMAIN_NAME_LENGTH 30
130
131struct rapl_package {
132 unsigned int id;
133 unsigned int nr_domains;
134 unsigned long domain_map;
135 unsigned int power_unit;
136 unsigned int energy_unit;
137 unsigned int time_unit;
138 struct rapl_domain *domains;
139 struct powercap_zone *power_zone;
140 unsigned long power_limit_irq;
141
142
143 struct list_head plist;
144 int lead_cpu;
145
146 struct cpumask cpumask;
147 char name[PACKAGE_DOMAIN_NAME_LENGTH];
148 struct rapl_if_priv *priv;
149};
150
151struct rapl_package *rapl_find_package_domain(int cpu, struct rapl_if_priv *priv);
152struct rapl_package *rapl_add_package(int cpu, struct rapl_if_priv *priv);
153void rapl_remove_package(struct rapl_package *rp);
154
155int rapl_add_platform_domain(struct rapl_if_priv *priv);
156void rapl_remove_platform_domain(struct rapl_if_priv *priv);
157
158#endif
159