-
Notifications
You must be signed in to change notification settings - Fork 10
/
libsmu.h
218 lines (189 loc) · 5.92 KB
/
libsmu.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
* Ryzen SMU Userspace Library
* Copyright (C) 2020 Leonardo Gates <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
#ifndef __LIB_SMU_H__
#define __LIB_SMU_H__
#include <stdio.h>
#include <string.h>
#include <pthread.h>
/* Version the loaded driver must use to be compatible. */
#define LIBSMU_SUPPORTED_DRIVER_VERSION "0.1.2"
/**
* SMU Mailbox Target
*/
enum smu_mailbox {
TYPE_RSMU,
TYPE_MP1,
};
/**
* Return values that can be sent from the SMU in response to a command.
*/
typedef enum {
SMU_Return_OK = 0x01,
SMU_Return_Failed = 0xFF,
SMU_Return_UnknownCmd = 0xFE,
SMU_Return_CmdRejectedPrereq = 0xFD,
SMU_Return_CmdRejectedBusy = 0xFC,
// Custom Error Code -- Does not exist in SMU.
// SMU Management failed to respond within the SMU_TIMEOUT_MS range.
SMU_Return_CommandTimeout = 0xFB,
// An invalid argument was sent to the function.
SMU_Return_InvalidArgument = 0xFA,
// Function is unsupported on the current processor.
SMU_Return_Unsupported = 0xF9,
// Insufficient buffer size specified.
SMU_Return_InsufficientSize = 0xF8,
// Failed to map physical address.
SMU_Return_MappedError = 0xF7,
// PCIe programming error.
SMU_Return_PCIFailed = 0xF6,
// Userspace Library Codes
// Driver is not currently loaded or inaccessible.
SMU_Return_DriverNotPresent = 0xF0,
// Read or write error has occurred. Check errno for last error.
SMU_Return_RWError = 0xE9,
// Driver version is incompatible.
SMU_Return_DriverVersion = 0xE8,
} smu_return_val;
/**
* Supported processor codenames with SMU capabilities.
*/
typedef enum {
CODENAME_UNDEFINED,
CODENAME_COLFAX,
CODENAME_RENOIR,
CODENAME_PICASSO,
CODENAME_MATISSE,
CODENAME_THREADRIPPER,
CODENAME_CASTLEPEAK,
CODENAME_RAVENRIDGE,
CODENAME_RAVENRIDGE2,
CODENAME_SUMMITRIDGE,
CODENAME_PINNACLERIDGE,
CODENAME_REMBRANDT,
CODENAME_VERMEER,
CODENAME_VANGOGH,
CODENAME_CEZANNE,
CODENAME_MILAN,
CODENAME_DALI,
CODENAME_COUNT
} smu_processor_codename;
/**
* SMU MP1 Interface Version [v9-v13]
*/
typedef enum {
IF_VERSION_9,
IF_VERSION_10,
IF_VERSION_11,
IF_VERSION_12,
IF_VERSION_13,
IF_VERSION_COUNT
} smu_if_version;
/**
* Mutex lock enumeration for specific components.
*/
enum SMU_MUTEX_LOCK {
SMU_MUTEX_SMN,
SMU_MUTEX_CMD,
SMU_MUTEX_PM,
SMU_MUTEX_COUNT
};
typedef struct {
/* Accessible To Users, Read-Only. */
unsigned int init;
unsigned int driver_version;
smu_processor_codename codename;
smu_if_version smu_if_version;
unsigned int smu_version;
unsigned int pm_table_size;
unsigned int pm_table_version;
/* Internal Library Use Only */
int fd_smn;
int fd_rsmu_cmd;
int fd_mp1_smu_cmd;
int fd_smu_args;
int fd_pm_table;
pthread_mutex_t lock[SMU_MUTEX_COUNT];
} smu_obj_t;
typedef union {
struct {
float args0_f;
float args1_f;
float args2_f;
float args3_f;
float args4_f;
float args5_f;
} f;
struct {
unsigned int args0;
unsigned int args1;
unsigned int args2;
unsigned int args3;
unsigned int args4;
unsigned int args5;
} i;
unsigned int args[6];
float args_f[6];
} smu_arg_t;
/**
* Initializes or frees the userspace library for use.
* Upon successful initialization, users are allowed to access the following members:
* - codename
* - smu_if_version
* - smu_version
* - pm_table_size
* - pm_table_version
*
* Returns SMU_Return_OK on success.
*/
smu_return_val smu_init(smu_obj_t* obj);
void smu_free(smu_obj_t* obj);
/**
* Returns the string representation of the SMU FW version.
*/
const char* smu_get_fw_version(smu_obj_t* obj);
/**
* Reads or writes a 32 bit word from the SMN address space.
*/
smu_return_val smu_read_smn_addr(smu_obj_t* obj, unsigned int address, unsigned int* result);
smu_return_val smu_write_smn_addr(smu_obj_t* obj, unsigned int address, unsigned int value);
/**
* Sends a command to the SMU.
* Arguments are sent in the args buffer and are also returned in it.
*
* Returns SMU_Return_OK on success.
*/
smu_return_val smu_send_command(smu_obj_t* obj, unsigned int op, smu_arg_t *args,
enum smu_mailbox mailbox);
/**
* Reads the PM table into the destination buffer.
*
* Returns an SMU_Return_OK on success.
*/
smu_return_val smu_read_pm_table(smu_obj_t* obj, unsigned char* dst, size_t dst_len);
/** HELPER METHODS **/
/**
* Converts SMU values to the string representation.
*/
const char* smu_return_to_str(smu_return_val val);
const char* smu_codename_to_str(smu_obj_t* obj);
/**
* Determines whether PM tables are supported.
* Returns 1 if they are.
*/
unsigned int smu_pm_tables_supported(smu_obj_t* obj);
#endif /* __LIB_SMU_H__ */