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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
|
/*
* Intel SoC Core Telemetry Driver
* Copyright (C) 2015, Intel Corporation.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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.
*
* Telemetry Framework provides platform related PM and performance statistics.
* This file provides the core telemetry API implementation.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>
#include <asm/intel_telemetry.h>
#define DRIVER_NAME "intel_telemetry_core"
struct telemetry_core_config {
struct telemetry_plt_config *plt_config;
const struct telemetry_core_ops *telem_ops;
};
static struct telemetry_core_config telm_core_conf;
static int telemetry_def_update_events(struct telemetry_evtconfig pss_evtconfig,
struct telemetry_evtconfig ioss_evtconfig)
{
return 0;
}
static int telemetry_def_set_sampling_period(u8 pss_period, u8 ioss_period)
{
return 0;
}
static int telemetry_def_get_sampling_period(u8 *pss_min_period,
u8 *pss_max_period,
u8 *ioss_min_period,
u8 *ioss_max_period)
{
return 0;
}
static int telemetry_def_get_eventconfig(
struct telemetry_evtconfig *pss_evtconfig,
struct telemetry_evtconfig *ioss_evtconfig,
int pss_len, int ioss_len)
{
return 0;
}
static int telemetry_def_get_trace_verbosity(enum telemetry_unit telem_unit,
u32 *verbosity)
{
return 0;
}
static int telemetry_def_set_trace_verbosity(enum telemetry_unit telem_unit,
u32 verbosity)
{
return 0;
}
static int telemetry_def_raw_read_eventlog(enum telemetry_unit telem_unit,
struct telemetry_evtlog *evtlog,
int len, int log_all_evts)
{
return 0;
}
static int telemetry_def_read_eventlog(enum telemetry_unit telem_unit,
struct telemetry_evtlog *evtlog,
int len, int log_all_evts)
{
return 0;
}
static int telemetry_def_add_events(u8 num_pss_evts, u8 num_ioss_evts,
u32 *pss_evtmap, u32 *ioss_evtmap)
{
return 0;
}
static int telemetry_def_reset_events(void)
{
return 0;
}
static const struct telemetry_core_ops telm_defpltops = {
.set_sampling_period = telemetry_def_set_sampling_period,
.get_sampling_period = telemetry_def_get_sampling_period,
.get_trace_verbosity = telemetry_def_get_trace_verbosity,
.set_trace_verbosity = telemetry_def_set_trace_verbosity,
.raw_read_eventlog = telemetry_def_raw_read_eventlog,
.get_eventconfig = telemetry_def_get_eventconfig,
.read_eventlog = telemetry_def_read_eventlog,
.update_events = telemetry_def_update_events,
.reset_events = telemetry_def_reset_events,
.add_events = telemetry_def_add_events,
};
/**
* telemetry_update_events() - Update telemetry Configuration
* @pss_evtconfig: PSS related config. No change if num_evts = 0.
* @pss_evtconfig: IOSS related config. No change if num_evts = 0.
*
* This API updates the IOSS & PSS Telemetry configuration. Old config
* is overwritten. Call telemetry_reset_events when logging is over
* All sample period values should be in the form of:
* bits[6:3] -> value; bits [0:2]-> Exponent; Period = (Value *16^Exponent)
*
* Return: 0 success, < 0 for failure
*/
int telemetry_update_events(struct telemetry_evtconfig pss_evtconfig,
struct telemetry_evtconfig ioss_evtconfig)
{
return telm_core_conf.telem_ops->update_events(pss_evtconfig,
ioss_evtconfig);
}
EXPORT_SYMBOL_GPL(telemetry_update_events);
/**
* telemetry_set_sampling_period() - Sets the IOSS & PSS sampling period
* @pss_period: placeholder for PSS Period to be set.
* Set to 0 if not required to be updated
* @ioss_period: placeholder for IOSS Period to be set
* Set to 0 if not required to be updated
*
* All values should be in the form of:
* bits[6:3] -> value; bits [0:2]-> Exponent; Period = (Value *16^Exponent)
*
* Return: 0 success, < 0 for failure
*/
int telemetry_set_sampling_period(u8 pss_period, u8 ioss_period)
{
return telm_core_conf.telem_ops->set_sampling_period(pss_period,
ioss_period);
}
EXPORT_SYMBOL_GPL(telemetry_set_sampling_period);
/**
* telemetry_get_sampling_period() - Get IOSS & PSS min & max sampling period
* @pss_min_period: placeholder for PSS Min Period supported
* @pss_max_period: placeholder for PSS Max Period supported
* @ioss_min_period: placeholder for IOSS Min Period supported
* @ioss_max_period: placeholder for IOSS Max Period supported
*
* All values should be in the form of:
* bits[6:3] -> value; bits [0:2]-> Exponent; Period = (Value *16^Exponent)
*
* Return: 0 success, < 0 for failure
*/
int telemetry_get_sampling_period(u8 *pss_min_period, u8 *pss_max_period,
u8 *ioss_min_period, u8 *ioss_max_period)
{
return telm_core_conf.telem_ops->get_sampling_period(pss_min_period,
pss_max_period,
ioss_min_period,
ioss_max_period);
}
EXPORT_SYMBOL_GPL(telemetry_get_sampling_period);
/**
* telemetry_reset_events() - Restore the IOSS & PSS configuration to default
*
* Return: 0 success, < 0 for failure
*/
int telemetry_reset_events(void)
{
return telm_core_conf.telem_ops->reset_events();
}
EXPORT_SYMBOL_GPL(telemetry_reset_events);
/**
* telemetry_get_eventconfig() - Returns the pss and ioss events enabled
* @pss_evtconfig: Pointer to PSS related configuration.
* @pss_evtconfig: Pointer to IOSS related configuration.
* @pss_len: Number of u32 elements allocated for pss_evtconfig array
* @ioss_len: Number of u32 elements allocated for ioss_evtconfig array
*
* Return: 0 success, < 0 for failure
*/
int telemetry_get_eventconfig(struct telemetry_evtconfig *pss_evtconfig,
struct telemetry_evtconfig *ioss_evtconfig,
int pss_len, int ioss_len)
{
return telm_core_conf.telem_ops->get_eventconfig(pss_evtconfig,
ioss_evtconfig,
pss_len, ioss_len);
}
EXPORT_SYMBOL_GPL(telemetry_get_eventconfig);
/**
* telemetry_add_events() - Add IOSS & PSS configuration to existing settings.
* @num_pss_evts: Number of PSS Events (<29) in pss_evtmap. Can be 0.
* @num_ioss_evts: Number of IOSS Events (<29) in ioss_evtmap. Can be 0.
* @pss_evtmap: Array of PSS Event-IDs to Enable
* @ioss_evtmap: Array of PSS Event-IDs to Enable
*
* Events are appended to Old Configuration. In case of total events > 28, it
* returns error. Call telemetry_reset_events to reset after eventlog done
*
* Return: 0 success, < 0 for failure
*/
int telemetry_add_events(u8 num_pss_evts, u8 num_ioss_evts,
u32 *pss_evtmap, u32 *ioss_evtmap)
{
return telm_core_conf.telem_ops->add_events(num_pss_evts,
num_ioss_evts, pss_evtmap,
ioss_evtmap);
}
EXPORT_SYMBOL_GPL(telemetry_add_events);
/**
* telemetry_read_events() - Fetches samples as specified by evtlog.telem_evt_id
* @telem_unit: Specify whether IOSS or PSS Read
* @evtlog: Array of telemetry_evtlog structs to fill data
* evtlog.telem_evt_id specifies the ids to read
* @len: Length of array of evtlog
*
* Return: number of eventlogs read for success, < 0 for failure
*/
int telemetry_read_events(enum telemetry_unit telem_unit,
struct telemetry_evtlog *evtlog, int len)
{
return telm_core_conf.telem_ops->read_eventlog(telem_unit, evtlog,
len, 0);
}
EXPORT_SYMBOL_GPL(telemetry_read_events);
/**
* telemetry_raw_read_events() - Fetch samples specified by evtlog.telem_evt_id
* @telem_unit: Specify whether IOSS or PSS Read
* @evtlog: Array of telemetry_evtlog structs to fill data
* evtlog.telem_evt_id specifies the ids to read
* @len: Length of array of evtlog
*
* The caller must take care of locking in this case.
*
* Return: number of eventlogs read for success, < 0 for failure
*/
int telemetry_raw_read_events(enum telemetry_unit telem_unit,
struct telemetry_evtlog *evtlog, int len)
{
return telm_core_conf.telem_ops->raw_read_eventlog(telem_unit, evtlog,
len, 0);
}
EXPORT_SYMBOL_GPL(telemetry_raw_read_events);
/**
* telemetry_read_eventlog() - Fetch the Telemetry log from PSS or IOSS
* @telem_unit: Specify whether IOSS or PSS Read
* @evtlog: Array of telemetry_evtlog structs to fill data
* @len: Length of array of evtlog
*
* Return: number of eventlogs read for success, < 0 for failure
*/
int telemetry_read_eventlog(enum telemetry_unit telem_unit,
struct telemetry_evtlog *evtlog, int len)
{
return telm_core_conf.telem_ops->read_eventlog(telem_unit, evtlog,
len, 1);
}
EXPORT_SYMBOL_GPL(telemetry_read_eventlog);
/**
* telemetry_raw_read_eventlog() - Fetch the Telemetry log from PSS or IOSS
* @telem_unit: Specify whether IOSS or PSS Read
* @evtlog: Array of telemetry_evtlog structs to fill data
* @len: Length of array of evtlog
*
* The caller must take care of locking in this case.
*
* Return: number of eventlogs read for success, < 0 for failure
*/
int telemetry_raw_read_eventlog(enum telemetry_unit telem_unit,
struct telemetry_evtlog *evtlog, int len)
{
return telm_core_conf.telem_ops->raw_read_eventlog(telem_unit, evtlog,
len, 1);
}
EXPORT_SYMBOL_GPL(telemetry_raw_read_eventlog);
/**
* telemetry_get_trace_verbosity() - Get the IOSS & PSS Trace verbosity
* @telem_unit: Specify whether IOSS or PSS Read
* @verbosity: Pointer to return Verbosity
*
* Return: 0 success, < 0 for failure
*/
int telemetry_get_trace_verbosity(enum telemetry_unit telem_unit,
u32 *verbosity)
{
return telm_core_conf.telem_ops->get_trace_verbosity(telem_unit,
verbosity);
}
EXPORT_SYMBOL_GPL(telemetry_get_trace_verbosity);
/**
* telemetry_set_trace_verbosity() - Update the IOSS & PSS Trace verbosity
* @telem_unit: Specify whether IOSS or PSS Read
* @verbosity: Verbosity to set
*
* Return: 0 success, < 0 for failure
*/
int telemetry_set_trace_verbosity(enum telemetry_unit telem_unit, u32 verbosity)
{
return telm_core_conf.telem_ops->set_trace_verbosity(telem_unit,
verbosity);
}
EXPORT_SYMBOL_GPL(telemetry_set_trace_verbosity);
/**
* telemetry_set_pltdata() - Set the platform specific Data
* @ops: Pointer to ops structure
* @pltconfig: Platform config data
*
* Usage by other than telemetry pltdrv module is invalid
*
* Return: 0 success, < 0 for failure
*/
int telemetry_set_pltdata(const struct telemetry_core_ops *ops,
struct telemetry_plt_config *pltconfig)
{
if (ops)
telm_core_conf.telem_ops = ops;
if (pltconfig)
telm_core_conf.plt_config = pltconfig;
return 0;
}
EXPORT_SYMBOL_GPL(telemetry_set_pltdata);
/**
* telemetry_clear_pltdata() - Clear the platform specific Data
*
* Usage by other than telemetry pltdrv module is invalid
*
* Return: 0 success, < 0 for failure
*/
int telemetry_clear_pltdata(void)
{
telm_core_conf.telem_ops = &telm_defpltops;
telm_core_conf.plt_config = NULL;
return 0;
}
EXPORT_SYMBOL_GPL(telemetry_clear_pltdata);
/**
* telemetry_pltconfig_valid() - Checkif platform config is valid
*
* Usage by other than telemetry module is invalid
*
* Return: 0 success, < 0 for failure
*/
int telemetry_pltconfig_valid(void)
{
if (telm_core_conf.plt_config)
return 0;
else
return -EINVAL;
}
EXPORT_SYMBOL_GPL(telemetry_pltconfig_valid);
static inline int telemetry_get_pssevtname(enum telemetry_unit telem_unit,
const char **name,
|