2 * Intel SOC Telemetry Platform Driver: Currently supports APL
3 * Copyright (c) 2015, Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * This file provides the platform specific telemetry implementation for APL.
16 * It used the PUNIT and PMC IPC interfaces for configuring the counters.
17 * The accumulated results are fetched from SRAM.
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/device.h>
22 #include <linux/debugfs.h>
23 #include <linux/seq_file.h>
25 #include <linux/uaccess.h>
26 #include <linux/pci.h>
27 #include <linux/suspend.h>
28 #include <linux/platform_device.h>
30 #include <asm/cpu_device_id.h>
31 #include <asm/intel_pmc_ipc.h>
32 #include <asm/intel_punit_ipc.h>
33 #include <asm/intel_telemetry.h>
35 #define DRIVER_NAME "intel_telemetry"
36 #define DRIVER_VERSION "1.0.0"
38 #define TELEM_TRC_VERBOSITY_MASK 0x3
40 #define TELEM_MIN_PERIOD(x) ((x) & 0x7F0000)
41 #define TELEM_MAX_PERIOD(x) ((x) & 0x7F000000)
42 #define TELEM_SAMPLE_PERIOD_INVALID(x) ((x) & (BIT(7)))
43 #define TELEM_CLEAR_SAMPLE_PERIOD(x) ((x) &= ~0x7F)
45 #define TELEM_SAMPLING_DEFAULT_PERIOD 0xD
47 #define TELEM_MAX_EVENTS_SRAM 28
48 #define TELEM_MAX_OS_ALLOCATED_EVENTS 20
49 #define TELEM_SSRAM_STARTTIME_OFFSET 8
50 #define TELEM_SSRAM_EVTLOG_OFFSET 16
52 #define IOSS_TELEM_EVENT_READ 0x0
53 #define IOSS_TELEM_EVENT_WRITE 0x1
54 #define IOSS_TELEM_INFO_READ 0x2
55 #define IOSS_TELEM_TRACE_CTL_READ 0x5
56 #define IOSS_TELEM_TRACE_CTL_WRITE 0x6
57 #define IOSS_TELEM_EVENT_CTL_READ 0x7
58 #define IOSS_TELEM_EVENT_CTL_WRITE 0x8
59 #define IOSS_TELEM_EVT_CTRL_WRITE_SIZE 0x4
60 #define IOSS_TELEM_READ_WORD 0x1
61 #define IOSS_TELEM_WRITE_FOURBYTES 0x4
62 #define IOSS_TELEM_EVT_WRITE_SIZE 0x3
64 #define TELEM_INFO_SRAMEVTS_MASK 0xFF00
65 #define TELEM_INFO_SRAMEVTS_SHIFT 0x8
66 #define TELEM_SSRAM_READ_TIMEOUT 10
68 #define TELEM_INFO_NENABLES_MASK 0xFF
69 #define TELEM_EVENT_ENABLE 0x8000
71 #define TELEM_MASK_BIT 1
72 #define TELEM_MASK_BYTE 0xFF
73 #define BYTES_PER_LONG 8
74 #define TELEM_MASK_PCS_STATE 0xF
76 #define TELEM_DISABLE(x) ((x) &= ~(BIT(31)))
77 #define TELEM_CLEAR_EVENTS(x) ((x) |= (BIT(30)))
78 #define TELEM_ENABLE_SRAM_EVT_TRACE(x) ((x) &= ~(BIT(30) | BIT(24)))
79 #define TELEM_ENABLE_PERIODIC(x) ((x) |= (BIT(23) | BIT(31) | BIT(7)))
80 #define TELEM_EXTRACT_VERBOSITY(x, y) ((y) = (((x) >> 27) & 0x3))
81 #define TELEM_CLEAR_VERBOSITY_BITS(x) ((x) &= ~(BIT(27) | BIT(28)))
82 #define TELEM_SET_VERBOSITY_BITS(x, y) ((x) |= ((y) << 27))
84 #define TELEM_CPU(model, data) \
85 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&data }
87 enum telemetry_action
{
94 struct telem_ssram_region
{
97 u64 events
[TELEM_MAX_EVENTS_SRAM
];
100 static struct telemetry_plt_config
*telm_conf
;
103 * The following counters are programmed by default during setup.
104 * Only 20 allocated to kernel driver
106 static struct telemetry_evtmap
107 telemetry_apl_ioss_default_events
[TELEM_MAX_OS_ALLOCATED_EVENTS
] = {
108 {"SOC_S0IX_TOTAL_RES", 0x4800},
109 {"SOC_S0IX_TOTAL_OCC", 0x4000},
110 {"SOC_S0IX_SHALLOW_RES", 0x4801},
111 {"SOC_S0IX_SHALLOW_OCC", 0x4001},
112 {"SOC_S0IX_DEEP_RES", 0x4802},
113 {"SOC_S0IX_DEEP_OCC", 0x4002},
114 {"PMC_POWER_GATE", 0x5818},
115 {"PMC_D3_STATES", 0x5819},
116 {"PMC_D0I3_STATES", 0x581A},
117 {"PMC_S0IX_WAKE_REASON_GPIO", 0x6000},
118 {"PMC_S0IX_WAKE_REASON_TIMER", 0x6001},
119 {"PMC_S0IX_WAKE_REASON_VNNREQ", 0x6002},
120 {"PMC_S0IX_WAKE_REASON_LOWPOWER", 0x6003},
121 {"PMC_S0IX_WAKE_REASON_EXTERNAL", 0x6004},
122 {"PMC_S0IX_WAKE_REASON_MISC", 0x6005},
123 {"PMC_S0IX_BLOCKING_IPS_D3_D0I3", 0x6006},
124 {"PMC_S0IX_BLOCKING_IPS_PG", 0x6007},
125 {"PMC_S0IX_BLOCKING_MISC_IPS_PG", 0x6008},
126 {"PMC_S0IX_BLOCK_IPS_VNN_REQ", 0x6009},
127 {"PMC_S0IX_BLOCK_IPS_CLOCKS", 0x600B},
131 static struct telemetry_evtmap
132 telemetry_apl_pss_default_events
[TELEM_MAX_OS_ALLOCATED_EVENTS
] = {
133 {"IA_CORE0_C6_RES", 0x0400},
134 {"IA_CORE0_C6_CTR", 0x0000},
135 {"IA_MODULE0_C7_RES", 0x0410},
136 {"IA_MODULE0_C7_CTR", 0x000E},
137 {"IA_C0_RES", 0x0805},
140 {"SOC_S0I3_RES", 0x0409},
141 {"SOC_S0I3_CTR", 0x000A},
142 {"PCS_S0I3_CTR", 0x0009},
143 {"PCS_C1E_RES", 0x041A},
144 {"PCS_IDLE_STATUS", 0x2806},
145 {"IA_PERF_LIMITS", 0x280B},
146 {"GT_PERF_LIMITS", 0x280C},
147 {"PCS_WAKEUP_S0IX_CTR", 0x0030},
148 {"PCS_IDLE_BLOCKED", 0x2C00},
149 {"PCS_S0IX_BLOCKED", 0x2C01},
150 {"PCS_S0IX_WAKE_REASONS", 0x2C02},
151 {"PCS_LTR_BLOCKING", 0x2C03},
152 {"PC2_AND_MEM_SHALLOW_IDLE_RES", 0x1D40},
155 /* APL specific Data */
156 static struct telemetry_plt_config telem_apl_config
= {
158 .telem_evts
= telemetry_apl_pss_default_events
,
161 .telem_evts
= telemetry_apl_ioss_default_events
,
165 static const struct x86_cpu_id telemetry_cpu_ids
[] = {
166 TELEM_CPU(0x5c, telem_apl_config
),
170 MODULE_DEVICE_TABLE(x86cpu
, telemetry_cpu_ids
);
172 static inline int telem_get_unitconfig(enum telemetry_unit telem_unit
,
173 struct telemetry_unit_config
**unit_config
)
175 if (telem_unit
== TELEM_PSS
)
176 *unit_config
= &(telm_conf
->pss_config
);
177 else if (telem_unit
== TELEM_IOSS
)
178 *unit_config
= &(telm_conf
->ioss_config
);
186 static int telemetry_check_evtid(enum telemetry_unit telem_unit
,
188 enum telemetry_action action
)
190 struct telemetry_unit_config
*unit_config
;
193 ret
= telem_get_unitconfig(telem_unit
, &unit_config
);
199 if (len
> TELEM_MAX_EVENTS_SRAM
)
205 if (len
> TELEM_MAX_EVENTS_SRAM
)
208 if ((len
> 0) && (evtmap
== NULL
))
214 if ((len
+ unit_config
->ssram_evts_used
) >
215 TELEM_MAX_EVENTS_SRAM
)
218 if ((len
> 0) && (evtmap
== NULL
))
224 pr_err("Unknown Telemetry action Specified %d\n", action
);
232 static inline int telemetry_plt_config_ioss_event(u32 evt_id
, int index
)
237 write_buf
= evt_id
| TELEM_EVENT_ENABLE
;
238 write_buf
<<= BITS_PER_BYTE
;
241 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
242 IOSS_TELEM_EVENT_WRITE
, (u8
*)&write_buf
,
243 IOSS_TELEM_EVT_WRITE_SIZE
, NULL
, 0);
248 static inline int telemetry_plt_config_pss_event(u32 evt_id
, int index
)
253 write_buf
= evt_id
| TELEM_EVENT_ENABLE
;
254 ret
= intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT
,
255 index
, 0, &write_buf
, NULL
);
260 static int telemetry_setup_iossevtconfig(struct telemetry_evtconfig evtconfig
,
261 enum telemetry_action action
)
263 u8 num_ioss_evts
, ioss_period
;
268 num_ioss_evts
= evtconfig
.num_evts
;
269 ioss_period
= evtconfig
.period
;
270 ioss_evtmap
= evtconfig
.evtmap
;
272 /* Get telemetry EVENT CTL */
273 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
274 IOSS_TELEM_EVENT_CTL_READ
, NULL
, 0,
275 &telem_ctrl
, IOSS_TELEM_READ_WORD
);
277 pr_err("IOSS TELEM_CTRL Read Failed\n");
281 /* Disable Telemetry */
282 TELEM_DISABLE(telem_ctrl
);
284 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
285 IOSS_TELEM_EVENT_CTL_WRITE
,
287 IOSS_TELEM_EVT_CTRL_WRITE_SIZE
,
290 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
295 /* Reset Everything */
296 if (action
== TELEM_RESET
) {
297 /* Clear All Events */
298 TELEM_CLEAR_EVENTS(telem_ctrl
);
300 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
301 IOSS_TELEM_EVENT_CTL_WRITE
,
303 IOSS_TELEM_EVT_CTRL_WRITE_SIZE
,
306 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
309 telm_conf
->ioss_config
.ssram_evts_used
= 0;
311 /* Configure Events */
312 for (idx
= 0; idx
< num_ioss_evts
; idx
++) {
313 if (telemetry_plt_config_ioss_event(
314 telm_conf
->ioss_config
.telem_evts
[idx
].evt_id
,
316 pr_err("IOSS TELEM_RESET Fail for data: %x\n",
317 telm_conf
->ioss_config
.telem_evts
[idx
].evt_id
);
320 telm_conf
->ioss_config
.ssram_evts_used
++;
324 /* Re-Configure Everything */
325 if (action
== TELEM_UPDATE
) {
326 /* Clear All Events */
327 TELEM_CLEAR_EVENTS(telem_ctrl
);
329 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
330 IOSS_TELEM_EVENT_CTL_WRITE
,
332 IOSS_TELEM_EVT_CTRL_WRITE_SIZE
,
335 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
338 telm_conf
->ioss_config
.ssram_evts_used
= 0;
340 /* Configure Events */
341 for (index
= 0; index
< num_ioss_evts
; index
++) {
342 telm_conf
->ioss_config
.telem_evts
[index
].evt_id
=
345 if (telemetry_plt_config_ioss_event(
346 telm_conf
->ioss_config
.telem_evts
[index
].evt_id
,
348 pr_err("IOSS TELEM_UPDATE Fail for Evt%x\n",
352 telm_conf
->ioss_config
.ssram_evts_used
++;
356 /* Add some Events */
357 if (action
== TELEM_ADD
) {
358 /* Configure Events */
359 for (index
= telm_conf
->ioss_config
.ssram_evts_used
, idx
= 0;
360 idx
< num_ioss_evts
; index
++, idx
++) {
361 telm_conf
->ioss_config
.telem_evts
[index
].evt_id
=
364 if (telemetry_plt_config_ioss_event(
365 telm_conf
->ioss_config
.telem_evts
[index
].evt_id
,
367 pr_err("IOSS TELEM_ADD Fail for Event %x\n",
371 telm_conf
->ioss_config
.ssram_evts_used
++;
375 /* Enable Periodic Telemetry Events and enable SRAM trace */
376 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl
);
377 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl
);
378 TELEM_ENABLE_PERIODIC(telem_ctrl
);
379 telem_ctrl
|= ioss_period
;
381 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
382 IOSS_TELEM_EVENT_CTL_WRITE
,
384 IOSS_TELEM_EVT_CTRL_WRITE_SIZE
, NULL
, 0);
386 pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
390 telm_conf
->ioss_config
.curr_period
= ioss_period
;
396 static int telemetry_setup_pssevtconfig(struct telemetry_evtconfig evtconfig
,
397 enum telemetry_action action
)
399 u8 num_pss_evts
, pss_period
;
404 num_pss_evts
= evtconfig
.num_evts
;
405 pss_period
= evtconfig
.period
;
406 pss_evtmap
= evtconfig
.evtmap
;
409 /* Get telemetry EVENT CTL */
410 ret
= intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL
,
411 0, 0, NULL
, &telem_ctrl
);
413 pr_err("PSS TELEM_CTRL Read Failed\n");
417 /* Disable Telemetry */
418 TELEM_DISABLE(telem_ctrl
);
419 ret
= intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
420 0, 0, &telem_ctrl
, NULL
);
422 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
426 /* Reset Everything */
427 if (action
== TELEM_RESET
) {
428 /* Clear All Events */
429 TELEM_CLEAR_EVENTS(telem_ctrl
);
431 ret
= intel_punit_ipc_command(
432 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
433 0, 0, &telem_ctrl
, NULL
);
435 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
438 telm_conf
->pss_config
.ssram_evts_used
= 0;
439 /* Configure Events */
440 for (idx
= 0; idx
< num_pss_evts
; idx
++) {
441 if (telemetry_plt_config_pss_event(
442 telm_conf
->pss_config
.telem_evts
[idx
].evt_id
,
444 pr_err("PSS TELEM_RESET Fail for Event %x\n",
445 telm_conf
->pss_config
.telem_evts
[idx
].evt_id
);
448 telm_conf
->pss_config
.ssram_evts_used
++;
452 /* Re-Configure Everything */
453 if (action
== TELEM_UPDATE
) {
454 /* Clear All Events */
455 TELEM_CLEAR_EVENTS(telem_ctrl
);
457 ret
= intel_punit_ipc_command(
458 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
459 0, 0, &telem_ctrl
, NULL
);
461 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
464 telm_conf
->pss_config
.ssram_evts_used
= 0;
466 /* Configure Events */
467 for (index
= 0; index
< num_pss_evts
; index
++) {
468 telm_conf
->pss_config
.telem_evts
[index
].evt_id
=
471 if (telemetry_plt_config_pss_event(
472 telm_conf
->pss_config
.telem_evts
[index
].evt_id
,
474 pr_err("PSS TELEM_UPDATE Fail for Event %x\n",
478 telm_conf
->pss_config
.ssram_evts_used
++;
482 /* Add some Events */
483 if (action
== TELEM_ADD
) {
484 /* Configure Events */
485 for (index
= telm_conf
->pss_config
.ssram_evts_used
, idx
= 0;
486 idx
< num_pss_evts
; index
++, idx
++) {
488 telm_conf
->pss_config
.telem_evts
[index
].evt_id
=
491 if (telemetry_plt_config_pss_event(
492 telm_conf
->pss_config
.telem_evts
[index
].evt_id
,
494 pr_err("PSS TELEM_ADD Fail for Event %x\n",
498 telm_conf
->pss_config
.ssram_evts_used
++;
502 /* Enable Periodic Telemetry Events and enable SRAM trace */
503 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl
);
504 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl
);
505 TELEM_ENABLE_PERIODIC(telem_ctrl
);
506 telem_ctrl
|= pss_period
;
508 ret
= intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
509 0, 0, &telem_ctrl
, NULL
);
511 pr_err("PSS TELEM_CTRL Event Enable Write Failed\n");
515 telm_conf
->pss_config
.curr_period
= pss_period
;
520 static int telemetry_setup_evtconfig(struct telemetry_evtconfig pss_evtconfig
,
521 struct telemetry_evtconfig ioss_evtconfig
,
522 enum telemetry_action action
)
526 mutex_lock(&(telm_conf
->telem_lock
));
528 if ((action
== TELEM_UPDATE
) && (telm_conf
->telem_in_use
)) {
533 ret
= telemetry_check_evtid(TELEM_PSS
, pss_evtconfig
.evtmap
,
534 pss_evtconfig
.num_evts
, action
);
538 ret
= telemetry_check_evtid(TELEM_IOSS
, ioss_evtconfig
.evtmap
,
539 ioss_evtconfig
.num_evts
, action
);
543 if (ioss_evtconfig
.num_evts
) {
544 ret
= telemetry_setup_iossevtconfig(ioss_evtconfig
, action
);
549 if (pss_evtconfig
.num_evts
) {
550 ret
= telemetry_setup_pssevtconfig(pss_evtconfig
, action
);
555 if ((action
== TELEM_UPDATE
) || (action
== TELEM_ADD
))
556 telm_conf
->telem_in_use
= true;
558 telm_conf
->telem_in_use
= false;
561 mutex_unlock(&(telm_conf
->telem_lock
));
565 static int telemetry_setup(struct platform_device
*pdev
)
567 struct telemetry_evtconfig pss_evtconfig
, ioss_evtconfig
;
568 u32 read_buf
, events
, event_regs
;
571 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
, IOSS_TELEM_INFO_READ
,
572 NULL
, 0, &read_buf
, IOSS_TELEM_READ_WORD
);
574 dev_err(&pdev
->dev
, "IOSS TELEM_INFO Read Failed\n");
578 /* Get telemetry Info */
579 events
= (read_buf
& TELEM_INFO_SRAMEVTS_MASK
) >>
580 TELEM_INFO_SRAMEVTS_SHIFT
;
581 event_regs
= read_buf
& TELEM_INFO_NENABLES_MASK
;
582 if ((events
< TELEM_MAX_EVENTS_SRAM
) ||
583 (event_regs
< TELEM_MAX_EVENTS_SRAM
)) {
584 dev_err(&pdev
->dev
, "IOSS:Insufficient Space for SRAM Trace\n");
585 dev_err(&pdev
->dev
, "SRAM Events %d; Event Regs %d\n",
590 telm_conf
->ioss_config
.min_period
= TELEM_MIN_PERIOD(read_buf
);
591 telm_conf
->ioss_config
.max_period
= TELEM_MAX_PERIOD(read_buf
);
593 /* PUNIT Mailbox Setup */
594 ret
= intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_INFO
, 0, 0,
597 dev_err(&pdev
->dev
, "PSS TELEM_INFO Read Failed\n");
601 /* Get telemetry Info */
602 events
= (read_buf
& TELEM_INFO_SRAMEVTS_MASK
) >>
603 TELEM_INFO_SRAMEVTS_SHIFT
;
604 event_regs
= read_buf
& TELEM_INFO_SRAMEVTS_MASK
;
605 if ((events
< TELEM_MAX_EVENTS_SRAM
) ||
606 (event_regs
< TELEM_MAX_EVENTS_SRAM
)) {
607 dev_err(&pdev
->dev
, "PSS:Insufficient Space for SRAM Trace\n");
608 dev_err(&pdev
->dev
, "SRAM Events %d; Event Regs %d\n",
613 telm_conf
->pss_config
.min_period
= TELEM_MIN_PERIOD(read_buf
);
614 telm_conf
->pss_config
.max_period
= TELEM_MAX_PERIOD(read_buf
);
616 pss_evtconfig
.evtmap
= NULL
;
617 pss_evtconfig
.num_evts
= TELEM_MAX_OS_ALLOCATED_EVENTS
;
618 pss_evtconfig
.period
= TELEM_SAMPLING_DEFAULT_PERIOD
;
620 ioss_evtconfig
.evtmap
= NULL
;
621 ioss_evtconfig
.num_evts
= TELEM_MAX_OS_ALLOCATED_EVENTS
;
622 ioss_evtconfig
.period
= TELEM_SAMPLING_DEFAULT_PERIOD
;
624 ret
= telemetry_setup_evtconfig(pss_evtconfig
, ioss_evtconfig
,
627 dev_err(&pdev
->dev
, "TELEMTRY Setup Failed\n");
633 static int telemetry_plt_update_events(struct telemetry_evtconfig pss_evtconfig
,
634 struct telemetry_evtconfig ioss_evtconfig
)
638 if ((pss_evtconfig
.num_evts
> 0) &&
639 (TELEM_SAMPLE_PERIOD_INVALID(pss_evtconfig
.period
))) {
640 pr_err("PSS Sampling Period Out of Range\n");
644 if ((ioss_evtconfig
.num_evts
> 0) &&
645 (TELEM_SAMPLE_PERIOD_INVALID(ioss_evtconfig
.period
))) {
646 pr_err("IOSS Sampling Period Out of Range\n");
650 ret
= telemetry_setup_evtconfig(pss_evtconfig
, ioss_evtconfig
,
653 pr_err("TELEMTRY Config Failed\n");
659 static int telemetry_plt_set_sampling_period(u8 pss_period
, u8 ioss_period
)
664 mutex_lock(&(telm_conf
->telem_lock
));
666 if (TELEM_SAMPLE_PERIOD_INVALID(ioss_period
)) {
667 pr_err("IOSS Sampling Period Out of Range\n");
672 /* Get telemetry EVENT CTL */
673 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
674 IOSS_TELEM_EVENT_CTL_READ
, NULL
, 0,
675 &telem_ctrl
, IOSS_TELEM_READ_WORD
);
677 pr_err("IOSS TELEM_CTRL Read Failed\n");
681 /* Disable Telemetry */
682 TELEM_DISABLE(telem_ctrl
);
684 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
685 IOSS_TELEM_EVENT_CTL_WRITE
,
687 IOSS_TELEM_EVT_CTRL_WRITE_SIZE
,
690 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
694 /* Enable Periodic Telemetry Events and enable SRAM trace */
695 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl
);
696 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl
);
697 TELEM_ENABLE_PERIODIC(telem_ctrl
);
698 telem_ctrl
|= ioss_period
;
700 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
701 IOSS_TELEM_EVENT_CTL_WRITE
,
703 IOSS_TELEM_EVT_CTRL_WRITE_SIZE
,
706 pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
709 telm_conf
->ioss_config
.curr_period
= ioss_period
;
713 if (TELEM_SAMPLE_PERIOD_INVALID(pss_period
)) {
714 pr_err("PSS Sampling Period Out of Range\n");
719 /* Get telemetry EVENT CTL */
720 ret
= intel_punit_ipc_command(
721 IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL
,
722 0, 0, NULL
, &telem_ctrl
);
724 pr_err("PSS TELEM_CTRL Read Failed\n");
728 /* Disable Telemetry */
729 TELEM_DISABLE(telem_ctrl
);
730 ret
= intel_punit_ipc_command(
731 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
732 0, 0, &telem_ctrl
, NULL
);
734 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
738 /* Enable Periodic Telemetry Events and enable SRAM trace */
739 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl
);
740 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl
);
741 TELEM_ENABLE_PERIODIC(telem_ctrl
);
742 telem_ctrl
|= pss_period
;
744 ret
= intel_punit_ipc_command(
745 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
746 0, 0, &telem_ctrl
, NULL
);
748 pr_err("PSS TELEM_CTRL Event Enable Write Failed\n");
751 telm_conf
->pss_config
.curr_period
= pss_period
;
755 mutex_unlock(&(telm_conf
->telem_lock
));
760 static int telemetry_plt_get_sampling_period(u8
*pss_min_period
,
765 *pss_min_period
= telm_conf
->pss_config
.min_period
;
766 *pss_max_period
= telm_conf
->pss_config
.max_period
;
767 *ioss_min_period
= telm_conf
->ioss_config
.min_period
;
768 *ioss_max_period
= telm_conf
->ioss_config
.max_period
;
774 static int telemetry_plt_reset_events(void)
776 struct telemetry_evtconfig pss_evtconfig
, ioss_evtconfig
;
779 pss_evtconfig
.evtmap
= NULL
;
780 pss_evtconfig
.num_evts
= TELEM_MAX_OS_ALLOCATED_EVENTS
;
781 pss_evtconfig
.period
= TELEM_SAMPLING_DEFAULT_PERIOD
;
783 ioss_evtconfig
.evtmap
= NULL
;
784 ioss_evtconfig
.num_evts
= TELEM_MAX_OS_ALLOCATED_EVENTS
;
785 ioss_evtconfig
.period
= TELEM_SAMPLING_DEFAULT_PERIOD
;
787 ret
= telemetry_setup_evtconfig(pss_evtconfig
, ioss_evtconfig
,
790 pr_err("TELEMTRY Reset Failed\n");
796 static int telemetry_plt_get_eventconfig(struct telemetry_evtconfig
*pss_config
,
797 struct telemetry_evtconfig
*ioss_config
,
798 int pss_len
, int ioss_len
)
800 u32
*pss_evtmap
, *ioss_evtmap
;
803 pss_evtmap
= pss_config
->evtmap
;
804 ioss_evtmap
= ioss_config
->evtmap
;
806 mutex_lock(&(telm_conf
->telem_lock
));
807 pss_config
->num_evts
= telm_conf
->pss_config
.ssram_evts_used
;
808 ioss_config
->num_evts
= telm_conf
->ioss_config
.ssram_evts_used
;
810 pss_config
->period
= telm_conf
->pss_config
.curr_period
;
811 ioss_config
->period
= telm_conf
->ioss_config
.curr_period
;
813 if ((pss_len
< telm_conf
->pss_config
.ssram_evts_used
) ||
814 (ioss_len
< telm_conf
->ioss_config
.ssram_evts_used
)) {
815 mutex_unlock(&(telm_conf
->telem_lock
));
819 for (index
= 0; index
< telm_conf
->pss_config
.ssram_evts_used
;
822 telm_conf
->pss_config
.telem_evts
[index
].evt_id
;
825 for (index
= 0; index
< telm_conf
->ioss_config
.ssram_evts_used
;
828 telm_conf
->ioss_config
.telem_evts
[index
].evt_id
;
831 mutex_unlock(&(telm_conf
->telem_lock
));
836 static int telemetry_plt_add_events(u8 num_pss_evts
, u8 num_ioss_evts
,
837 u32
*pss_evtmap
, u32
*ioss_evtmap
)
839 struct telemetry_evtconfig pss_evtconfig
, ioss_evtconfig
;
842 pss_evtconfig
.evtmap
= pss_evtmap
;
843 pss_evtconfig
.num_evts
= num_pss_evts
;
844 pss_evtconfig
.period
= telm_conf
->pss_config
.curr_period
;
846 ioss_evtconfig
.evtmap
= ioss_evtmap
;
847 ioss_evtconfig
.num_evts
= num_ioss_evts
;
848 ioss_evtconfig
.period
= telm_conf
->ioss_config
.curr_period
;
850 ret
= telemetry_setup_evtconfig(pss_evtconfig
, ioss_evtconfig
,
853 pr_err("TELEMTRY ADD Failed\n");
858 static int telem_evtlog_read(enum telemetry_unit telem_unit
,
859 struct telem_ssram_region
*ssram_region
, u8 len
)
861 struct telemetry_unit_config
*unit_config
;
862 u64 timestamp_prev
, timestamp_next
;
863 int ret
, index
, timeout
= 0;
865 ret
= telem_get_unitconfig(telem_unit
, &unit_config
);
869 if (len
> unit_config
->ssram_evts_used
)
870 len
= unit_config
->ssram_evts_used
;
873 timestamp_prev
= readq(unit_config
->regmap
);
874 if (!timestamp_prev
) {
875 pr_err("Ssram under update. Please Try Later\n");
879 ssram_region
->start_time
= readq(unit_config
->regmap
+
880 TELEM_SSRAM_STARTTIME_OFFSET
);
882 for (index
= 0; index
< len
; index
++) {
883 ssram_region
->events
[index
] =
884 readq(unit_config
->regmap
+ TELEM_SSRAM_EVTLOG_OFFSET
+
885 BYTES_PER_LONG
*index
);
888 timestamp_next
= readq(unit_config
->regmap
);
889 if (!timestamp_next
) {
890 pr_err("Ssram under update. Please Try Later\n");
894 if (timeout
++ > TELEM_SSRAM_READ_TIMEOUT
) {
895 pr_err("Timeout while reading Events\n");
899 } while (timestamp_prev
!= timestamp_next
);
901 ssram_region
->timestamp
= timestamp_next
;
906 static int telemetry_plt_raw_read_eventlog(enum telemetry_unit telem_unit
,
907 struct telemetry_evtlog
*evtlog
,
908 int len
, int log_all_evts
)
910 int index
, idx1
, ret
, readlen
= len
;
911 struct telem_ssram_region ssram_region
;
912 struct telemetry_evtmap
*evtmap
;
914 switch (telem_unit
) {
916 evtmap
= telm_conf
->pss_config
.telem_evts
;
920 evtmap
= telm_conf
->ioss_config
.telem_evts
;
924 pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit
);
929 readlen
= TELEM_MAX_EVENTS_SRAM
;
931 ret
= telem_evtlog_read(telem_unit
, &ssram_region
, readlen
);
935 /* Invalid evt-id array specified via length mismatch */
936 if ((!log_all_evts
) && (len
> ret
))
940 for (index
= 0; index
< ret
; index
++) {
941 evtlog
[index
].telem_evtlog
= ssram_region
.events
[index
];
942 evtlog
[index
].telem_evtid
= evtmap
[index
].evt_id
;
945 for (index
= 0, readlen
= 0; (index
< ret
) && (readlen
< len
);
947 for (idx1
= 0; idx1
< len
; idx1
++) {
948 /* Elements matched */
949 if (evtmap
[index
].evt_id
==
950 evtlog
[idx1
].telem_evtid
) {
951 evtlog
[idx1
].telem_evtlog
=
952 ssram_region
.events
[index
];
963 static int telemetry_plt_read_eventlog(enum telemetry_unit telem_unit
,
964 struct telemetry_evtlog
*evtlog
, int len
, int log_all_evts
)
968 mutex_lock(&(telm_conf
->telem_lock
));
969 ret
= telemetry_plt_raw_read_eventlog(telem_unit
, evtlog
,
971 mutex_unlock(&(telm_conf
->telem_lock
));
976 static int telemetry_plt_get_trace_verbosity(enum telemetry_unit telem_unit
,
982 if (verbosity
== NULL
)
985 mutex_lock(&(telm_conf
->telem_trace_lock
));
986 switch (telem_unit
) {
988 ret
= intel_punit_ipc_command(
989 IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL
,
992 pr_err("PSS TRACE_CTRL Read Failed\n");
999 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
1000 IOSS_TELEM_TRACE_CTL_READ
, NULL
, 0, &temp
,
1001 IOSS_TELEM_READ_WORD
);
1003 pr_err("IOSS TRACE_CTL Read Failed\n");
1010 pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit
);
1014 TELEM_EXTRACT_VERBOSITY(temp
, *verbosity
);
1017 mutex_unlock(&(telm_conf
->telem_trace_lock
));
1021 static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit
,
1027 verbosity
&= TELEM_TRC_VERBOSITY_MASK
;
1029 mutex_lock(&(telm_conf
->telem_trace_lock
));
1030 switch (telem_unit
) {
1032 ret
= intel_punit_ipc_command(
1033 IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL
,
1036 pr_err("PSS TRACE_CTRL Read Failed\n");
1040 TELEM_CLEAR_VERBOSITY_BITS(temp
);
1041 TELEM_SET_VERBOSITY_BITS(temp
, verbosity
);
1043 ret
= intel_punit_ipc_command(
1044 IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL
,
1047 pr_err("PSS TRACE_CTRL Verbosity Set Failed\n");
1053 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
1054 IOSS_TELEM_TRACE_CTL_READ
, NULL
, 0, &temp
,
1055 IOSS_TELEM_READ_WORD
);
1057 pr_err("IOSS TRACE_CTL Read Failed\n");
1061 TELEM_CLEAR_VERBOSITY_BITS(temp
);
1062 TELEM_SET_VERBOSITY_BITS(temp
, verbosity
);
1064 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
1065 IOSS_TELEM_TRACE_CTL_WRITE
, (u8
*)&temp
,
1066 IOSS_TELEM_WRITE_FOURBYTES
, NULL
, 0);
1068 pr_err("IOSS TRACE_CTL Verbosity Set Failed\n");
1074 pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit
);
1080 mutex_unlock(&(telm_conf
->telem_trace_lock
));
1084 static const struct telemetry_core_ops telm_pltops
= {
1085 .get_trace_verbosity
= telemetry_plt_get_trace_verbosity
,
1086 .set_trace_verbosity
= telemetry_plt_set_trace_verbosity
,
1087 .set_sampling_period
= telemetry_plt_set_sampling_period
,
1088 .get_sampling_period
= telemetry_plt_get_sampling_period
,
1089 .raw_read_eventlog
= telemetry_plt_raw_read_eventlog
,
1090 .get_eventconfig
= telemetry_plt_get_eventconfig
,
1091 .update_events
= telemetry_plt_update_events
,
1092 .read_eventlog
= telemetry_plt_read_eventlog
,
1093 .reset_events
= telemetry_plt_reset_events
,
1094 .add_events
= telemetry_plt_add_events
,
1097 static int telemetry_pltdrv_probe(struct platform_device
*pdev
)
1099 struct resource
*res0
= NULL
, *res1
= NULL
;
1100 const struct x86_cpu_id
*id
;
1101 int size
, ret
= -ENOMEM
;
1103 id
= x86_match_cpu(telemetry_cpu_ids
);
1107 telm_conf
= (struct telemetry_plt_config
*)id
->driver_data
;
1109 res0
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1114 size
= resource_size(res0
);
1115 if (!devm_request_mem_region(&pdev
->dev
, res0
->start
, size
,
1120 telm_conf
->pss_config
.ssram_base_addr
= res0
->start
;
1121 telm_conf
->pss_config
.ssram_size
= size
;
1123 res1
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1128 size
= resource_size(res1
);
1129 if (!devm_request_mem_region(&pdev
->dev
, res1
->start
, size
,
1135 telm_conf
->ioss_config
.ssram_base_addr
= res1
->start
;
1136 telm_conf
->ioss_config
.ssram_size
= size
;
1138 telm_conf
->pss_config
.regmap
= ioremap_nocache(
1139 telm_conf
->pss_config
.ssram_base_addr
,
1140 telm_conf
->pss_config
.ssram_size
);
1141 if (!telm_conf
->pss_config
.regmap
) {
1146 telm_conf
->ioss_config
.regmap
= ioremap_nocache(
1147 telm_conf
->ioss_config
.ssram_base_addr
,
1148 telm_conf
->ioss_config
.ssram_size
);
1149 if (!telm_conf
->ioss_config
.regmap
) {
1154 mutex_init(&telm_conf
->telem_lock
);
1155 mutex_init(&telm_conf
->telem_trace_lock
);
1157 ret
= telemetry_setup(pdev
);
1161 ret
= telemetry_set_pltdata(&telm_pltops
, telm_conf
);
1163 dev_err(&pdev
->dev
, "TELEMTRY Set Pltops Failed.\n");
1171 release_mem_region(res0
->start
, resource_size(res0
));
1173 release_mem_region(res1
->start
, resource_size(res1
));
1174 if (telm_conf
->pss_config
.regmap
)
1175 iounmap(telm_conf
->pss_config
.regmap
);
1176 if (telm_conf
->ioss_config
.regmap
)
1177 iounmap(telm_conf
->ioss_config
.regmap
);
1178 dev_err(&pdev
->dev
, "TELEMTRY Setup Failed.\n");
1183 static int telemetry_pltdrv_remove(struct platform_device
*pdev
)
1185 telemetry_clear_pltdata();
1186 iounmap(telm_conf
->pss_config
.regmap
);
1187 iounmap(telm_conf
->ioss_config
.regmap
);
1192 static struct platform_driver telemetry_soc_driver
= {
1193 .probe
= telemetry_pltdrv_probe
,
1194 .remove
= telemetry_pltdrv_remove
,
1196 .name
= DRIVER_NAME
,
1200 static int __init
telemetry_module_init(void)
1202 pr_info(DRIVER_NAME
": version %s loaded\n", DRIVER_VERSION
);
1203 return platform_driver_register(&telemetry_soc_driver
);
1206 static void __exit
telemetry_module_exit(void)
1208 platform_driver_unregister(&telemetry_soc_driver
);
1211 device_initcall(telemetry_module_init
);
1212 module_exit(telemetry_module_exit
);
1214 MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
1215 MODULE_DESCRIPTION("Intel SoC Telemetry Platform Driver");
1216 MODULE_VERSION(DRIVER_VERSION
);
1217 MODULE_LICENSE("GPL");