0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef __INTEL_RAPL_H__
0011 #define __INTEL_RAPL_H__
0012
0013 #include <linux/types.h>
0014 #include <linux/powercap.h>
0015 #include <linux/cpuhotplug.h>
0016
0017 enum rapl_domain_type {
0018 RAPL_DOMAIN_PACKAGE,
0019 RAPL_DOMAIN_PP0,
0020 RAPL_DOMAIN_PP1,
0021 RAPL_DOMAIN_DRAM,
0022 RAPL_DOMAIN_PLATFORM,
0023 RAPL_DOMAIN_MAX,
0024 };
0025
0026 enum rapl_domain_reg_id {
0027 RAPL_DOMAIN_REG_LIMIT,
0028 RAPL_DOMAIN_REG_STATUS,
0029 RAPL_DOMAIN_REG_PERF,
0030 RAPL_DOMAIN_REG_POLICY,
0031 RAPL_DOMAIN_REG_INFO,
0032 RAPL_DOMAIN_REG_PL4,
0033 RAPL_DOMAIN_REG_MAX,
0034 };
0035
0036 struct rapl_domain;
0037
0038 enum rapl_primitives {
0039 ENERGY_COUNTER,
0040 POWER_LIMIT1,
0041 POWER_LIMIT2,
0042 POWER_LIMIT4,
0043 FW_LOCK,
0044
0045 PL1_ENABLE,
0046 PL1_CLAMP,
0047 PL2_ENABLE,
0048 PL2_CLAMP,
0049 PL4_ENABLE,
0050
0051 TIME_WINDOW1,
0052 TIME_WINDOW2,
0053 THERMAL_SPEC_POWER,
0054 MAX_POWER,
0055
0056 MIN_POWER,
0057 MAX_TIME_WINDOW,
0058 THROTTLED_TIME,
0059 PRIORITY_LEVEL,
0060
0061 PSYS_POWER_LIMIT1,
0062 PSYS_POWER_LIMIT2,
0063 PSYS_PL1_ENABLE,
0064 PSYS_PL2_ENABLE,
0065 PSYS_TIME_WINDOW1,
0066 PSYS_TIME_WINDOW2,
0067
0068 AVERAGE_POWER,
0069 NR_RAPL_PRIMITIVES,
0070 };
0071
0072 struct rapl_domain_data {
0073 u64 primitives[NR_RAPL_PRIMITIVES];
0074 unsigned long timestamp;
0075 };
0076
0077 #define NR_POWER_LIMITS (3)
0078 struct rapl_power_limit {
0079 struct powercap_zone_constraint *constraint;
0080 int prim_id;
0081 struct rapl_domain *domain;
0082 const char *name;
0083 u64 last_power_limit;
0084 };
0085
0086 struct rapl_package;
0087
0088 #define RAPL_DOMAIN_NAME_LENGTH 16
0089
0090 struct rapl_domain {
0091 char name[RAPL_DOMAIN_NAME_LENGTH];
0092 enum rapl_domain_type id;
0093 u64 regs[RAPL_DOMAIN_REG_MAX];
0094 struct powercap_zone power_zone;
0095 struct rapl_domain_data rdd;
0096 struct rapl_power_limit rpl[NR_POWER_LIMITS];
0097 u64 attr_map;
0098 unsigned int state;
0099 unsigned int domain_energy_unit;
0100 struct rapl_package *rp;
0101 };
0102
0103 struct reg_action {
0104 u64 reg;
0105 u64 mask;
0106 u64 value;
0107 int err;
0108 };
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 struct rapl_if_priv {
0126 struct powercap_control_type *control_type;
0127 struct rapl_domain *platform_rapl_domain;
0128 enum cpuhp_state pcap_rapl_online;
0129 u64 reg_unit;
0130 u64 regs[RAPL_DOMAIN_MAX][RAPL_DOMAIN_REG_MAX];
0131 int limits[RAPL_DOMAIN_MAX];
0132 int (*read_raw)(int cpu, struct reg_action *ra);
0133 int (*write_raw)(int cpu, struct reg_action *ra);
0134 };
0135
0136
0137 #define PACKAGE_DOMAIN_NAME_LENGTH 30
0138
0139 struct rapl_package {
0140 unsigned int id;
0141 unsigned int nr_domains;
0142 unsigned long domain_map;
0143 unsigned int power_unit;
0144 unsigned int energy_unit;
0145 unsigned int time_unit;
0146 struct rapl_domain *domains;
0147 struct powercap_zone *power_zone;
0148 unsigned long power_limit_irq;
0149
0150
0151 struct list_head plist;
0152 int lead_cpu;
0153
0154 struct cpumask cpumask;
0155 char name[PACKAGE_DOMAIN_NAME_LENGTH];
0156 struct rapl_if_priv *priv;
0157 };
0158
0159 struct rapl_package *rapl_find_package_domain(int cpu, struct rapl_if_priv *priv);
0160 struct rapl_package *rapl_add_package(int cpu, struct rapl_if_priv *priv);
0161 void rapl_remove_package(struct rapl_package *rp);
0162
0163 #endif