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>
16 enum rapl_domain_type
{
17 RAPL_DOMAIN_PACKAGE
, /* entire package/socket */
18 RAPL_DOMAIN_PP0
, /* core power plane */
19 RAPL_DOMAIN_PP1
, /* graphics uncore */
20 RAPL_DOMAIN_DRAM
, /* DRAM control_type */
21 RAPL_DOMAIN_PLATFORM
, /* PSys control_type */
25 enum rapl_domain_reg_id
{
26 RAPL_DOMAIN_REG_LIMIT
,
27 RAPL_DOMAIN_REG_STATUS
,
29 RAPL_DOMAIN_REG_POLICY
,
36 enum rapl_primitives
{
42 PL1_ENABLE
, /* power limit 1, aka long term */
43 PL1_CLAMP
, /* allow frequency to go below OS request */
44 PL2_ENABLE
, /* power limit 2, aka short term, instantaneous */
47 TIME_WINDOW1
, /* long term */
48 TIME_WINDOW2
, /* short term */
57 /* below are not raw primitive data */
62 struct rapl_domain_data
{
63 u64 primitives
[NR_RAPL_PRIMITIVES
];
64 unsigned long timestamp
;
67 #define NR_POWER_LIMITS (2)
68 struct rapl_power_limit
{
69 struct powercap_zone_constraint
*constraint
;
70 int prim_id
; /* primitive ID used to enable */
71 struct rapl_domain
*domain
;
80 enum rapl_domain_type id
;
81 int regs
[RAPL_DOMAIN_REG_MAX
];
82 struct powercap_zone power_zone
;
83 struct rapl_domain_data rdd
;
84 struct rapl_power_limit rpl
[NR_POWER_LIMITS
];
85 u64 attr_map
; /* track capabilities */
87 unsigned int domain_energy_unit
;
88 struct rapl_package
*rp
;
92 * struct rapl_if_priv: private data for different RAPL interfaces
93 * @control_type: Each RAPL interface must have its own powercap
95 * @platform_rapl_domain: Optional. Some RAPL interface may have platform
97 * @pcap_rapl_online: CPU hotplug state for each RAPL interface.
98 * @reg_unit: Register for getting energy/power/time unit.
99 * @regs: Register sets for different RAPL Domains.
101 struct rapl_if_priv
{
102 struct powercap_control_type
*control_type
;
103 struct rapl_domain
*platform_rapl_domain
;
104 enum cpuhp_state pcap_rapl_online
;
106 u32 regs
[RAPL_DOMAIN_MAX
][RAPL_DOMAIN_REG_MAX
];
109 /* maximum rapl package domain name: package-%d-die-%d */
110 #define PACKAGE_DOMAIN_NAME_LENGTH 30
112 struct rapl_package
{
113 unsigned int id
; /* logical die id, equals physical 1-die systems */
114 unsigned int nr_domains
;
115 unsigned long domain_map
; /* bit map of active domains */
116 unsigned int power_unit
;
117 unsigned int energy_unit
;
118 unsigned int time_unit
;
119 struct rapl_domain
*domains
; /* array of domains, sized at runtime */
120 struct powercap_zone
*power_zone
; /* keep track of parent zone */
121 unsigned long power_limit_irq
; /* keep track of package power limit
122 * notify interrupt enable status.
124 struct list_head plist
;
125 int lead_cpu
; /* one active cpu per package for access */
126 /* Track active cpus */
127 struct cpumask cpumask
;
128 char name
[PACKAGE_DOMAIN_NAME_LENGTH
];
129 struct rapl_if_priv
*priv
;
132 #endif /* __INTEL_RAPL_H__ */