1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Data types and headers for RAPL support
5 * Copyright (C) 2019 Intel Corporation.
7 * Author: Zhang Rui <rui.zhang@intel.com>
10 #ifndef __INTEL_RAPL_H__
11 #define __INTEL_RAPL_H__
13 #include <linux/types.h>
14 #include <linux/powercap.h>
15 #include <linux/cpuhotplug.h>
17 enum rapl_domain_type
{
18 RAPL_DOMAIN_PACKAGE
, /* entire package/socket */
19 RAPL_DOMAIN_PP0
, /* core power plane */
20 RAPL_DOMAIN_PP1
, /* graphics uncore */
21 RAPL_DOMAIN_DRAM
, /* DRAM control_type */
22 RAPL_DOMAIN_PLATFORM
, /* PSys control_type */
26 enum rapl_domain_reg_id
{
27 RAPL_DOMAIN_REG_LIMIT
,
28 RAPL_DOMAIN_REG_STATUS
,
30 RAPL_DOMAIN_REG_POLICY
,
38 enum rapl_primitives
{
45 PL1_ENABLE
, /* power limit 1, aka long term */
46 PL1_CLAMP
, /* allow frequency to go below OS request */
47 PL2_ENABLE
, /* power limit 2, aka short term, instantaneous */
49 PL4_ENABLE
, /* power limit 4, aka max peak power */
51 TIME_WINDOW1
, /* long term */
52 TIME_WINDOW2
, /* short term */
61 /* below are not raw primitive data */
66 struct rapl_domain_data
{
67 u64 primitives
[NR_RAPL_PRIMITIVES
];
68 unsigned long timestamp
;
71 #define NR_POWER_LIMITS (3)
72 struct rapl_power_limit
{
73 struct powercap_zone_constraint
*constraint
;
74 int prim_id
; /* primitive ID used to enable */
75 struct rapl_domain
*domain
;
82 #define RAPL_DOMAIN_NAME_LENGTH 16
85 char name
[RAPL_DOMAIN_NAME_LENGTH
];
86 enum rapl_domain_type id
;
87 u64 regs
[RAPL_DOMAIN_REG_MAX
];
88 struct powercap_zone power_zone
;
89 struct rapl_domain_data rdd
;
90 struct rapl_power_limit rpl
[NR_POWER_LIMITS
];
91 u64 attr_map
; /* track capabilities */
93 unsigned int domain_energy_unit
;
94 struct rapl_package
*rp
;
105 * struct rapl_if_priv: private data for different RAPL interfaces
106 * @control_type: Each RAPL interface must have its own powercap
108 * @platform_rapl_domain: Optional. Some RAPL interface may have platform
109 * level RAPL control.
110 * @pcap_rapl_online: CPU hotplug state for each RAPL interface.
111 * @reg_unit: Register for getting energy/power/time unit.
112 * @regs: Register sets for different RAPL Domains.
113 * @limits: Number of power limits supported by each domain.
114 * @read_raw: Callback for reading RAPL interface specific
116 * @write_raw: Callback for writing RAPL interface specific
119 struct rapl_if_priv
{
120 struct powercap_control_type
*control_type
;
121 struct rapl_domain
*platform_rapl_domain
;
122 enum cpuhp_state pcap_rapl_online
;
124 u64 regs
[RAPL_DOMAIN_MAX
][RAPL_DOMAIN_REG_MAX
];
125 int limits
[RAPL_DOMAIN_MAX
];
126 int (*read_raw
)(int cpu
, struct reg_action
*ra
);
127 int (*write_raw
)(int cpu
, struct reg_action
*ra
);
130 /* maximum rapl package domain name: package-%d-die-%d */
131 #define PACKAGE_DOMAIN_NAME_LENGTH 30
133 struct rapl_package
{
134 unsigned int id
; /* logical die id, equals physical 1-die systems */
135 unsigned int nr_domains
;
136 unsigned long domain_map
; /* bit map of active domains */
137 unsigned int power_unit
;
138 unsigned int energy_unit
;
139 unsigned int time_unit
;
140 struct rapl_domain
*domains
; /* array of domains, sized at runtime */
141 struct powercap_zone
*power_zone
; /* keep track of parent zone */
142 unsigned long power_limit_irq
; /* keep track of package power limit
143 * notify interrupt enable status.
145 struct list_head plist
;
146 int lead_cpu
; /* one active cpu per package for access */
147 /* Track active cpus */
148 struct cpumask cpumask
;
149 char name
[PACKAGE_DOMAIN_NAME_LENGTH
];
150 struct rapl_if_priv
*priv
;
153 struct rapl_package
*rapl_find_package_domain(int cpu
, struct rapl_if_priv
*priv
);
154 struct rapl_package
*rapl_add_package(int cpu
, struct rapl_if_priv
*priv
);
155 void rapl_remove_package(struct rapl_package
*rp
);
157 #endif /* __INTEL_RAPL_H__ */