1*c2294c14SThomas Renninger /* SPDX-License-Identifier: GPL-2.0-only */
2*c2294c14SThomas Renninger /*
3*c2294c14SThomas Renninger  *  (C) 2016 SUSE Software Solutions GmbH
4*c2294c14SThomas Renninger  *           Thomas Renninger <trenn@suse.de>
5*c2294c14SThomas Renninger  */
6*c2294c14SThomas Renninger 
7*c2294c14SThomas Renninger #ifndef __CPUPOWER_RAPL_H__
8*c2294c14SThomas Renninger #define __CPUPOWER_RAPL_H__
9*c2294c14SThomas Renninger 
10*c2294c14SThomas Renninger #define PATH_TO_POWERCAP "/sys/devices/virtual/powercap"
11*c2294c14SThomas Renninger #define PATH_TO_RAPL "/sys/devices/virtual/powercap/intel-rapl"
12*c2294c14SThomas Renninger #define PATH_TO_RAPL_CLASS "/sys/devices/virtual/powercap/intel-rapl"
13*c2294c14SThomas Renninger 
14*c2294c14SThomas Renninger #define POWERCAP_MAX_CHILD_ZONES 10
15*c2294c14SThomas Renninger #define POWERCAP_MAX_TREE_DEPTH 10
16*c2294c14SThomas Renninger 
17*c2294c14SThomas Renninger #define MAX_LINE_LEN 4096
18*c2294c14SThomas Renninger #define SYSFS_PATH_MAX 255
19*c2294c14SThomas Renninger 
20*c2294c14SThomas Renninger #include <stdint.h>
21*c2294c14SThomas Renninger 
22*c2294c14SThomas Renninger struct powercap_zone {
23*c2294c14SThomas Renninger 	char name[MAX_LINE_LEN];
24*c2294c14SThomas Renninger 	/*
25*c2294c14SThomas Renninger 	 * sys_name relative to PATH_TO_POWERCAP,
26*c2294c14SThomas Renninger 	 * do not forget the / in between
27*c2294c14SThomas Renninger 	 */
28*c2294c14SThomas Renninger 	char sys_name[SYSFS_PATH_MAX];
29*c2294c14SThomas Renninger 	int tree_depth;
30*c2294c14SThomas Renninger 	struct powercap_zone *parent;
31*c2294c14SThomas Renninger 	struct powercap_zone *children[POWERCAP_MAX_CHILD_ZONES];
32*c2294c14SThomas Renninger 	/* More possible caps or attributes to be added? */
33*c2294c14SThomas Renninger 	uint32_t has_power_uw:1,
34*c2294c14SThomas Renninger 		 has_energy_uj:1;
35*c2294c14SThomas Renninger 
36*c2294c14SThomas Renninger };
37*c2294c14SThomas Renninger 
38*c2294c14SThomas Renninger int powercap_walk_zones(struct powercap_zone *zone,
39*c2294c14SThomas Renninger 			int (*f)(struct powercap_zone *zone));
40*c2294c14SThomas Renninger 
41*c2294c14SThomas Renninger struct powercap_zone *powercap_init_zones(void);
42*c2294c14SThomas Renninger int powercap_get_enabled(int *mode);
43*c2294c14SThomas Renninger int powercap_set_enabled(int mode);
44*c2294c14SThomas Renninger int powercap_get_driver(char *driver, int buflen);
45*c2294c14SThomas Renninger 
46*c2294c14SThomas Renninger int powercap_get_max_energy_range_uj(struct powercap_zone *zone, uint64_t *val);
47*c2294c14SThomas Renninger int powercap_get_energy_uj(struct powercap_zone *zone, uint64_t *val);
48*c2294c14SThomas Renninger int powercap_get_max_power_range_uw(struct powercap_zone *zone, uint64_t *val);
49*c2294c14SThomas Renninger int powercap_get_power_uw(struct powercap_zone *zone, uint64_t *val);
50*c2294c14SThomas Renninger int powercap_zone_get_enabled(struct powercap_zone *zone, int *mode);
51*c2294c14SThomas Renninger int powercap_zone_set_enabled(struct powercap_zone *zone, int mode);
52*c2294c14SThomas Renninger 
53*c2294c14SThomas Renninger 
54*c2294c14SThomas Renninger #endif /* __CPUPOWER_RAPL_H__ */
55