1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __ACPI_ACPI_THERMAL_H
3#define __ACPI_ACPI_THERMAL_H
4
5#include <asm/ioctl.h>
6
7#define ACPI_THERMAL_MAGIC 's'
8
9#define ACPI_THERMAL_GET_TRT_LEN _IOR(ACPI_THERMAL_MAGIC, 1, unsigned long)
10#define ACPI_THERMAL_GET_ART_LEN _IOR(ACPI_THERMAL_MAGIC, 2, unsigned long)
11#define ACPI_THERMAL_GET_TRT_COUNT _IOR(ACPI_THERMAL_MAGIC, 3, unsigned long)
12#define ACPI_THERMAL_GET_ART_COUNT _IOR(ACPI_THERMAL_MAGIC, 4, unsigned long)
13
14#define ACPI_THERMAL_GET_TRT	_IOR(ACPI_THERMAL_MAGIC, 5, unsigned long)
15#define ACPI_THERMAL_GET_ART	_IOR(ACPI_THERMAL_MAGIC, 6, unsigned long)
16
17/*
18 * ACPI_THERMAL_GET_PSVT_COUNT = Number of PSVT entries
19 * ACPI_THERMAL_GET_PSVT_LEN = Total return data size (PSVT count x each
20 * PSVT entry size)
21 * ACPI_THERMAL_GET_PSVT = Get the data as an array of psvt_objects
22 */
23#define ACPI_THERMAL_GET_PSVT_LEN _IOR(ACPI_THERMAL_MAGIC, 7, unsigned long)
24#define ACPI_THERMAL_GET_PSVT_COUNT _IOR(ACPI_THERMAL_MAGIC, 8, unsigned long)
25#define ACPI_THERMAL_GET_PSVT	_IOR(ACPI_THERMAL_MAGIC, 9, unsigned long)
26
27struct art {
28	acpi_handle source;
29	acpi_handle target;
30	struct_group(data,
31		u64 weight;
32		u64 ac0_max;
33		u64 ac1_max;
34		u64 ac2_max;
35		u64 ac3_max;
36		u64 ac4_max;
37		u64 ac5_max;
38		u64 ac6_max;
39		u64 ac7_max;
40		u64 ac8_max;
41		u64 ac9_max;
42	);
43} __packed;
44
45struct trt {
46	acpi_handle source;
47	acpi_handle target;
48	u64 influence;
49	u64 sample_period;
50	u64 reserved1;
51	u64 reserved2;
52	u64 reserved3;
53	u64 reserved4;
54} __packed;
55
56#define ACPI_NR_PSVT_ELEMENTS	12
57#define ACPI_PSVT_CONTROL_KNOB	7
58#define ACPI_LIMIT_STR_MAX_LEN	8
59
60struct psvt {
61	acpi_handle source;
62	acpi_handle target;
63	u64 priority;
64	u64 sample_period;
65	u64 passive_temp;
66	u64 source_domain;
67	u64 control_knob;
68	union {
69		/* For limit_type = ACPI_TYPE_INTEGER */
70		u64 integer;
71		/* For limit_type = ACPI_TYPE_STRING */
72		char string[ACPI_LIMIT_STR_MAX_LEN];
73		char *str_ptr;
74	} limit;
75	u64 step_size;
76	u64 limit_coeff;
77	u64 unlimit_coeff;
78	/* Spec calls this field reserved, so we borrow it for type info */
79	u64 control_knob_type; /* ACPI_TYPE_STRING or ACPI_TYPE_INTEGER */
80} __packed;
81
82#define ACPI_NR_ART_ELEMENTS 13
83/* for usrspace */
84union art_object {
85	struct {
86		char source_device[8]; /* ACPI single name */
87		char target_device[8]; /* ACPI single name */
88		struct_group(data,
89			u64 weight;
90			u64 ac0_max_level;
91			u64 ac1_max_level;
92			u64 ac2_max_level;
93			u64 ac3_max_level;
94			u64 ac4_max_level;
95			u64 ac5_max_level;
96			u64 ac6_max_level;
97			u64 ac7_max_level;
98			u64 ac8_max_level;
99			u64 ac9_max_level;
100		);
101	};
102	u64 __data[ACPI_NR_ART_ELEMENTS];
103};
104
105union trt_object {
106	struct {
107		char source_device[8]; /* ACPI single name */
108		char target_device[8]; /* ACPI single name */
109		u64 influence;
110		u64 sample_period;
111		u64 reserved[4];
112	};
113	u64 __data[8];
114};
115
116union psvt_object {
117	struct {
118		char source_device[8];
119		char target_device[8];
120		u64 priority;
121		u64 sample_period;
122		u64 passive_temp;
123		u64 source_domain;
124		u64 control_knob;
125		union {
126			u64 integer;
127			char string[ACPI_LIMIT_STR_MAX_LEN];
128		} limit;
129		u64 step_size;
130		u64 limit_coeff;
131		u64 unlimit_coeff;
132		u64 control_knob_type;
133	};
134	u64 __data[ACPI_NR_PSVT_ELEMENTS];
135};
136
137#ifdef __KERNEL__
138int acpi_thermal_rel_misc_device_add(acpi_handle handle);
139int acpi_thermal_rel_misc_device_remove(acpi_handle handle);
140int acpi_parse_art(acpi_handle handle, int *art_count, struct art **arts,
141		bool create_dev);
142int acpi_parse_trt(acpi_handle handle, int *trt_count, struct trt **trts,
143		bool create_dev);
144#endif
145
146#endif /* __ACPI_ACPI_THERMAL_H */
147