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.
21 #include <linux/module.h>
22 #include <linux/platform_device.h>
24 #include <asm/cpu_device_id.h>
25 #include <asm/intel-family.h>
26 #include <asm/intel_pmc_ipc.h>
27 #include <asm/intel_punit_ipc.h>
28 #include <asm/intel_telemetry.h>
30 #define DRIVER_NAME "intel_telemetry"
31 #define DRIVER_VERSION "1.0.0"
33 #define TELEM_TRC_VERBOSITY_MASK 0x3
35 #define TELEM_MIN_PERIOD(x) ((x) & 0x7F0000)
36 #define TELEM_MAX_PERIOD(x) ((x) & 0x7F000000)
37 #define TELEM_SAMPLE_PERIOD_INVALID(x) ((x) & (BIT(7)))
38 #define TELEM_CLEAR_SAMPLE_PERIOD(x) ((x) &= ~0x7F)
40 #define TELEM_SAMPLING_DEFAULT_PERIOD 0xD
42 #define TELEM_MAX_EVENTS_SRAM 28
43 #define TELEM_SSRAM_STARTTIME_OFFSET 8
44 #define TELEM_SSRAM_EVTLOG_OFFSET 16
46 #define IOSS_TELEM_EVENT_READ 0x0
47 #define IOSS_TELEM_EVENT_WRITE 0x1
48 #define IOSS_TELEM_INFO_READ 0x2
49 #define IOSS_TELEM_TRACE_CTL_READ 0x5
50 #define IOSS_TELEM_TRACE_CTL_WRITE 0x6
51 #define IOSS_TELEM_EVENT_CTL_READ 0x7
52 #define IOSS_TELEM_EVENT_CTL_WRITE 0x8
53 #define IOSS_TELEM_EVT_CTRL_WRITE_SIZE 0x4
54 #define IOSS_TELEM_READ_WORD 0x1
55 #define IOSS_TELEM_WRITE_FOURBYTES 0x4
56 #define IOSS_TELEM_EVT_WRITE_SIZE 0x3
58 #define TELEM_INFO_SRAMEVTS_MASK 0xFF00
59 #define TELEM_INFO_SRAMEVTS_SHIFT 0x8
60 #define TELEM_SSRAM_READ_TIMEOUT 10
62 #define TELEM_INFO_NENABLES_MASK 0xFF
63 #define TELEM_EVENT_ENABLE 0x8000
65 #define TELEM_MASK_BIT 1
66 #define TELEM_MASK_BYTE 0xFF
67 #define BYTES_PER_LONG 8
68 #define TELEM_MASK_PCS_STATE 0xF
70 #define TELEM_DISABLE(x) ((x) &= ~(BIT(31)))
71 #define TELEM_CLEAR_EVENTS(x) ((x) |= (BIT(30)))
72 #define TELEM_ENABLE_SRAM_EVT_TRACE(x) ((x) &= ~(BIT(30) | BIT(24)))
73 #define TELEM_ENABLE_PERIODIC(x) ((x) |= (BIT(23) | BIT(31) | BIT(7)))
74 #define TELEM_EXTRACT_VERBOSITY(x, y) ((y) = (((x) >> 27) & 0x3))
75 #define TELEM_CLEAR_VERBOSITY_BITS(x) ((x) &= ~(BIT(27) | BIT(28)))
76 #define TELEM_SET_VERBOSITY_BITS(x, y) ((x) |= ((y) << 27))
78 #define TELEM_CPU(model, data) \
79 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&data }
81 enum telemetry_action
{
88 struct telem_ssram_region
{
91 u64 events
[TELEM_MAX_EVENTS_SRAM
];
94 static struct telemetry_plt_config
*telm_conf
;
97 * The following counters are programmed by default during setup.
98 * Only 20 allocated to kernel driver
100 static struct telemetry_evtmap
101 telemetry_apl_ioss_default_events
[TELEM_MAX_OS_ALLOCATED_EVENTS
] = {
102 {"SOC_S0IX_TOTAL_RES", 0x4800},
103 {"SOC_S0IX_TOTAL_OCC", 0x4000},
104 {"SOC_S0IX_SHALLOW_RES", 0x4801},
105 {"SOC_S0IX_SHALLOW_OCC", 0x4001},
106 {"SOC_S0IX_DEEP_RES", 0x4802},
107 {"SOC_S0IX_DEEP_OCC", 0x4002},
108 {"PMC_POWER_GATE", 0x5818},
109 {"PMC_D3_STATES", 0x5819},
110 {"PMC_D0I3_STATES", 0x581A},
111 {"PMC_S0IX_WAKE_REASON_GPIO", 0x6000},
112 {"PMC_S0IX_WAKE_REASON_TIMER", 0x6001},
113 {"PMC_S0IX_WAKE_REASON_VNNREQ", 0x6002},
114 {"PMC_S0IX_WAKE_REASON_LOWPOWER", 0x6003},
115 {"PMC_S0IX_WAKE_REASON_EXTERNAL", 0x6004},
116 {"PMC_S0IX_WAKE_REASON_MISC", 0x6005},
117 {"PMC_S0IX_BLOCKING_IPS_D3_D0I3", 0x6006},
118 {"PMC_S0IX_BLOCKING_IPS_PG", 0x6007},
119 {"PMC_S0IX_BLOCKING_MISC_IPS_PG", 0x6008},
120 {"PMC_S0IX_BLOCK_IPS_VNN_REQ", 0x6009},
121 {"PMC_S0IX_BLOCK_IPS_CLOCKS", 0x600B},
125 static struct telemetry_evtmap
126 telemetry_apl_pss_default_events
[TELEM_MAX_OS_ALLOCATED_EVENTS
] = {
127 {"IA_CORE0_C6_RES", 0x0400},
128 {"IA_CORE0_C6_CTR", 0x0000},
129 {"IA_MODULE0_C7_RES", 0x0410},
130 {"IA_MODULE0_C7_CTR", 0x000E},
131 {"IA_C0_RES", 0x0805},
134 {"SOC_S0I3_RES", 0x0409},
135 {"SOC_S0I3_CTR", 0x000A},
136 {"PCS_S0I3_CTR", 0x0009},
137 {"PCS_C1E_RES", 0x041A},
138 {"PCS_IDLE_STATUS", 0x2806},
139 {"IA_PERF_LIMITS", 0x280B},
140 {"GT_PERF_LIMITS", 0x280C},
141 {"PCS_WAKEUP_S0IX_CTR", 0x0030},
142 {"PCS_IDLE_BLOCKED", 0x2C00},
143 {"PCS_S0IX_BLOCKED", 0x2C01},
144 {"PCS_S0IX_WAKE_REASONS", 0x2C02},
145 {"PCS_LTR_BLOCKING", 0x2C03},
146 {"PC2_AND_MEM_SHALLOW_IDLE_RES", 0x1D40},
149 static struct telemetry_evtmap
150 telemetry_glk_pss_default_events
[TELEM_MAX_OS_ALLOCATED_EVENTS
] = {
151 {"IA_CORE0_C6_RES", 0x0400},
152 {"IA_CORE0_C6_CTR", 0x0000},
153 {"IA_MODULE0_C7_RES", 0x0410},
154 {"IA_MODULE0_C7_CTR", 0x000C},
155 {"IA_C0_RES", 0x0805},
158 {"SOC_S0I3_RES", 0x0407},
159 {"SOC_S0I3_CTR", 0x0008},
160 {"PCS_S0I3_CTR", 0x0007},
161 {"PCS_C1E_RES", 0x0414},
162 {"PCS_IDLE_STATUS", 0x2806},
163 {"IA_PERF_LIMITS", 0x280B},
164 {"GT_PERF_LIMITS", 0x280C},
165 {"PCS_WAKEUP_S0IX_CTR", 0x0025},
166 {"PCS_IDLE_BLOCKED", 0x2C00},
167 {"PCS_S0IX_BLOCKED", 0x2C01},
168 {"PCS_S0IX_WAKE_REASONS", 0x2C02},
169 {"PCS_LTR_BLOCKING", 0x2C03},
170 {"PC2_AND_MEM_SHALLOW_IDLE_RES", 0x1D40},
173 /* APL specific Data */
174 static struct telemetry_plt_config telem_apl_config
= {
176 .telem_evts
= telemetry_apl_pss_default_events
,
179 .telem_evts
= telemetry_apl_ioss_default_events
,
183 /* GLK specific Data */
184 static struct telemetry_plt_config telem_glk_config
= {
186 .telem_evts
= telemetry_glk_pss_default_events
,
189 .telem_evts
= telemetry_apl_ioss_default_events
,
193 static const struct x86_cpu_id telemetry_cpu_ids
[] = {
194 TELEM_CPU(INTEL_FAM6_ATOM_GOLDMONT
, telem_apl_config
),
195 TELEM_CPU(INTEL_FAM6_ATOM_GEMINI_LAKE
, telem_glk_config
),
199 MODULE_DEVICE_TABLE(x86cpu
, telemetry_cpu_ids
);
201 static inline int telem_get_unitconfig(enum telemetry_unit telem_unit
,
202 struct telemetry_unit_config
**unit_config
)
204 if (telem_unit
== TELEM_PSS
)
205 *unit_config
= &(telm_conf
->pss_config
);
206 else if (telem_unit
== TELEM_IOSS
)
207 *unit_config
= &(telm_conf
->ioss_config
);
215 static int telemetry_check_evtid(enum telemetry_unit telem_unit
,
217 enum telemetry_action action
)
219 struct telemetry_unit_config
*unit_config
;
222 ret
= telem_get_unitconfig(telem_unit
, &unit_config
);
228 if (len
> TELEM_MAX_EVENTS_SRAM
)
234 if (len
> TELEM_MAX_EVENTS_SRAM
)
237 if ((len
> 0) && (evtmap
== NULL
))
243 if ((len
+ unit_config
->ssram_evts_used
) >
244 TELEM_MAX_EVENTS_SRAM
)
247 if ((len
> 0) && (evtmap
== NULL
))
253 pr_err("Unknown Telemetry action specified %d\n", action
);
261 static inline int telemetry_plt_config_ioss_event(u32 evt_id
, int index
)
266 write_buf
= evt_id
| TELEM_EVENT_ENABLE
;
267 write_buf
<<= BITS_PER_BYTE
;
270 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
271 IOSS_TELEM_EVENT_WRITE
, (u8
*)&write_buf
,
272 IOSS_TELEM_EVT_WRITE_SIZE
, NULL
, 0);
277 static inline int telemetry_plt_config_pss_event(u32 evt_id
, int index
)
282 write_buf
= evt_id
| TELEM_EVENT_ENABLE
;
283 ret
= intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT
,
284 index
, 0, &write_buf
, NULL
);
289 static int telemetry_setup_iossevtconfig(struct telemetry_evtconfig evtconfig
,
290 enum telemetry_action action
)
292 u8 num_ioss_evts
, ioss_period
;
297 num_ioss_evts
= evtconfig
.num_evts
;
298 ioss_period
= evtconfig
.period
;
299 ioss_evtmap
= evtconfig
.evtmap
;
301 /* Get telemetry EVENT CTL */
302 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
303 IOSS_TELEM_EVENT_CTL_READ
, NULL
, 0,
304 &telem_ctrl
, IOSS_TELEM_READ_WORD
);
306 pr_err("IOSS TELEM_CTRL Read Failed\n");
310 /* Disable Telemetry */
311 TELEM_DISABLE(telem_ctrl
);
313 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
314 IOSS_TELEM_EVENT_CTL_WRITE
,
316 IOSS_TELEM_EVT_CTRL_WRITE_SIZE
,
319 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
324 /* Reset Everything */
325 if (action
== TELEM_RESET
) {
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 (idx
= 0; idx
< num_ioss_evts
; idx
++) {
342 if (telemetry_plt_config_ioss_event(
343 telm_conf
->ioss_config
.telem_evts
[idx
].evt_id
,
345 pr_err("IOSS TELEM_RESET Fail for data: %x\n",
346 telm_conf
->ioss_config
.telem_evts
[idx
].evt_id
);
349 telm_conf
->ioss_config
.ssram_evts_used
++;
353 /* Re-Configure Everything */
354 if (action
== TELEM_UPDATE
) {
355 /* Clear All Events */
356 TELEM_CLEAR_EVENTS(telem_ctrl
);
358 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
359 IOSS_TELEM_EVENT_CTL_WRITE
,
361 IOSS_TELEM_EVT_CTRL_WRITE_SIZE
,
364 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
367 telm_conf
->ioss_config
.ssram_evts_used
= 0;
369 /* Configure Events */
370 for (index
= 0; index
< num_ioss_evts
; index
++) {
371 telm_conf
->ioss_config
.telem_evts
[index
].evt_id
=
374 if (telemetry_plt_config_ioss_event(
375 telm_conf
->ioss_config
.telem_evts
[index
].evt_id
,
377 pr_err("IOSS TELEM_UPDATE Fail for Evt%x\n",
381 telm_conf
->ioss_config
.ssram_evts_used
++;
385 /* Add some Events */
386 if (action
== TELEM_ADD
) {
387 /* Configure Events */
388 for (index
= telm_conf
->ioss_config
.ssram_evts_used
, idx
= 0;
389 idx
< num_ioss_evts
; index
++, idx
++) {
390 telm_conf
->ioss_config
.telem_evts
[index
].evt_id
=
393 if (telemetry_plt_config_ioss_event(
394 telm_conf
->ioss_config
.telem_evts
[index
].evt_id
,
396 pr_err("IOSS TELEM_ADD Fail for Event %x\n",
400 telm_conf
->ioss_config
.ssram_evts_used
++;
404 /* Enable Periodic Telemetry Events and enable SRAM trace */
405 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl
);
406 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl
);
407 TELEM_ENABLE_PERIODIC(telem_ctrl
);
408 telem_ctrl
|= ioss_period
;
410 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
411 IOSS_TELEM_EVENT_CTL_WRITE
,
413 IOSS_TELEM_EVT_CTRL_WRITE_SIZE
, NULL
, 0);
415 pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
419 telm_conf
->ioss_config
.curr_period
= ioss_period
;
425 static int telemetry_setup_pssevtconfig(struct telemetry_evtconfig evtconfig
,
426 enum telemetry_action action
)
428 u8 num_pss_evts
, pss_period
;
433 num_pss_evts
= evtconfig
.num_evts
;
434 pss_period
= evtconfig
.period
;
435 pss_evtmap
= evtconfig
.evtmap
;
438 /* Get telemetry EVENT CTL */
439 ret
= intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL
,
440 0, 0, NULL
, &telem_ctrl
);
442 pr_err("PSS TELEM_CTRL Read Failed\n");
446 /* Disable Telemetry */
447 TELEM_DISABLE(telem_ctrl
);
448 ret
= intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
449 0, 0, &telem_ctrl
, NULL
);
451 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
455 /* Reset Everything */
456 if (action
== TELEM_RESET
) {
457 /* Clear All Events */
458 TELEM_CLEAR_EVENTS(telem_ctrl
);
460 ret
= intel_punit_ipc_command(
461 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
462 0, 0, &telem_ctrl
, NULL
);
464 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
467 telm_conf
->pss_config
.ssram_evts_used
= 0;
468 /* Configure Events */
469 for (idx
= 0; idx
< num_pss_evts
; idx
++) {
470 if (telemetry_plt_config_pss_event(
471 telm_conf
->pss_config
.telem_evts
[idx
].evt_id
,
473 pr_err("PSS TELEM_RESET Fail for Event %x\n",
474 telm_conf
->pss_config
.telem_evts
[idx
].evt_id
);
477 telm_conf
->pss_config
.ssram_evts_used
++;
481 /* Re-Configure Everything */
482 if (action
== TELEM_UPDATE
) {
483 /* Clear All Events */
484 TELEM_CLEAR_EVENTS(telem_ctrl
);
486 ret
= intel_punit_ipc_command(
487 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
488 0, 0, &telem_ctrl
, NULL
);
490 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
493 telm_conf
->pss_config
.ssram_evts_used
= 0;
495 /* Configure Events */
496 for (index
= 0; index
< num_pss_evts
; index
++) {
497 telm_conf
->pss_config
.telem_evts
[index
].evt_id
=
500 if (telemetry_plt_config_pss_event(
501 telm_conf
->pss_config
.telem_evts
[index
].evt_id
,
503 pr_err("PSS TELEM_UPDATE Fail for Event %x\n",
507 telm_conf
->pss_config
.ssram_evts_used
++;
511 /* Add some Events */
512 if (action
== TELEM_ADD
) {
513 /* Configure Events */
514 for (index
= telm_conf
->pss_config
.ssram_evts_used
, idx
= 0;
515 idx
< num_pss_evts
; index
++, idx
++) {
517 telm_conf
->pss_config
.telem_evts
[index
].evt_id
=
520 if (telemetry_plt_config_pss_event(
521 telm_conf
->pss_config
.telem_evts
[index
].evt_id
,
523 pr_err("PSS TELEM_ADD Fail for Event %x\n",
527 telm_conf
->pss_config
.ssram_evts_used
++;
531 /* Enable Periodic Telemetry Events and enable SRAM trace */
532 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl
);
533 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl
);
534 TELEM_ENABLE_PERIODIC(telem_ctrl
);
535 telem_ctrl
|= pss_period
;
537 ret
= intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
538 0, 0, &telem_ctrl
, NULL
);
540 pr_err("PSS TELEM_CTRL Event Enable Write Failed\n");
544 telm_conf
->pss_config
.curr_period
= pss_period
;
549 static int telemetry_setup_evtconfig(struct telemetry_evtconfig pss_evtconfig
,
550 struct telemetry_evtconfig ioss_evtconfig
,
551 enum telemetry_action action
)
555 mutex_lock(&(telm_conf
->telem_lock
));
557 if ((action
== TELEM_UPDATE
) && (telm_conf
->telem_in_use
)) {
562 ret
= telemetry_check_evtid(TELEM_PSS
, pss_evtconfig
.evtmap
,
563 pss_evtconfig
.num_evts
, action
);
567 ret
= telemetry_check_evtid(TELEM_IOSS
, ioss_evtconfig
.evtmap
,
568 ioss_evtconfig
.num_evts
, action
);
572 if (ioss_evtconfig
.num_evts
) {
573 ret
= telemetry_setup_iossevtconfig(ioss_evtconfig
, action
);
578 if (pss_evtconfig
.num_evts
) {
579 ret
= telemetry_setup_pssevtconfig(pss_evtconfig
, action
);
584 if ((action
== TELEM_UPDATE
) || (action
== TELEM_ADD
))
585 telm_conf
->telem_in_use
= true;
587 telm_conf
->telem_in_use
= false;
590 mutex_unlock(&(telm_conf
->telem_lock
));
594 static int telemetry_setup(struct platform_device
*pdev
)
596 struct telemetry_evtconfig pss_evtconfig
, ioss_evtconfig
;
597 u32 read_buf
, events
, event_regs
;
600 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
, IOSS_TELEM_INFO_READ
,
601 NULL
, 0, &read_buf
, IOSS_TELEM_READ_WORD
);
603 dev_err(&pdev
->dev
, "IOSS TELEM_INFO Read Failed\n");
607 /* Get telemetry Info */
608 events
= (read_buf
& TELEM_INFO_SRAMEVTS_MASK
) >>
609 TELEM_INFO_SRAMEVTS_SHIFT
;
610 event_regs
= read_buf
& TELEM_INFO_NENABLES_MASK
;
611 if ((events
< TELEM_MAX_EVENTS_SRAM
) ||
612 (event_regs
< TELEM_MAX_EVENTS_SRAM
)) {
613 dev_err(&pdev
->dev
, "IOSS:Insufficient Space for SRAM Trace\n");
614 dev_err(&pdev
->dev
, "SRAM Events %d; Event Regs %d\n",
619 telm_conf
->ioss_config
.min_period
= TELEM_MIN_PERIOD(read_buf
);
620 telm_conf
->ioss_config
.max_period
= TELEM_MAX_PERIOD(read_buf
);
622 /* PUNIT Mailbox Setup */
623 ret
= intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_INFO
, 0, 0,
626 dev_err(&pdev
->dev
, "PSS TELEM_INFO Read Failed\n");
630 /* Get telemetry Info */
631 events
= (read_buf
& TELEM_INFO_SRAMEVTS_MASK
) >>
632 TELEM_INFO_SRAMEVTS_SHIFT
;
633 event_regs
= read_buf
& TELEM_INFO_SRAMEVTS_MASK
;
634 if ((events
< TELEM_MAX_EVENTS_SRAM
) ||
635 (event_regs
< TELEM_MAX_EVENTS_SRAM
)) {
636 dev_err(&pdev
->dev
, "PSS:Insufficient Space for SRAM Trace\n");
637 dev_err(&pdev
->dev
, "SRAM Events %d; Event Regs %d\n",
642 telm_conf
->pss_config
.min_period
= TELEM_MIN_PERIOD(read_buf
);
643 telm_conf
->pss_config
.max_period
= TELEM_MAX_PERIOD(read_buf
);
645 pss_evtconfig
.evtmap
= NULL
;
646 pss_evtconfig
.num_evts
= TELEM_MAX_OS_ALLOCATED_EVENTS
;
647 pss_evtconfig
.period
= TELEM_SAMPLING_DEFAULT_PERIOD
;
649 ioss_evtconfig
.evtmap
= NULL
;
650 ioss_evtconfig
.num_evts
= TELEM_MAX_OS_ALLOCATED_EVENTS
;
651 ioss_evtconfig
.period
= TELEM_SAMPLING_DEFAULT_PERIOD
;
653 ret
= telemetry_setup_evtconfig(pss_evtconfig
, ioss_evtconfig
,
656 dev_err(&pdev
->dev
, "TELEMETRY Setup Failed\n");
662 static int telemetry_plt_update_events(struct telemetry_evtconfig pss_evtconfig
,
663 struct telemetry_evtconfig ioss_evtconfig
)
667 if ((pss_evtconfig
.num_evts
> 0) &&
668 (TELEM_SAMPLE_PERIOD_INVALID(pss_evtconfig
.period
))) {
669 pr_err("PSS Sampling Period Out of Range\n");
673 if ((ioss_evtconfig
.num_evts
> 0) &&
674 (TELEM_SAMPLE_PERIOD_INVALID(ioss_evtconfig
.period
))) {
675 pr_err("IOSS Sampling Period Out of Range\n");
679 ret
= telemetry_setup_evtconfig(pss_evtconfig
, ioss_evtconfig
,
682 pr_err("TELEMETRY Config Failed\n");
688 static int telemetry_plt_set_sampling_period(u8 pss_period
, u8 ioss_period
)
693 mutex_lock(&(telm_conf
->telem_lock
));
695 if (TELEM_SAMPLE_PERIOD_INVALID(ioss_period
)) {
696 pr_err("IOSS Sampling Period Out of Range\n");
701 /* Get telemetry EVENT CTL */
702 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
703 IOSS_TELEM_EVENT_CTL_READ
, NULL
, 0,
704 &telem_ctrl
, IOSS_TELEM_READ_WORD
);
706 pr_err("IOSS TELEM_CTRL Read Failed\n");
710 /* Disable Telemetry */
711 TELEM_DISABLE(telem_ctrl
);
713 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
714 IOSS_TELEM_EVENT_CTL_WRITE
,
716 IOSS_TELEM_EVT_CTRL_WRITE_SIZE
,
719 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
723 /* Enable Periodic Telemetry Events and enable SRAM trace */
724 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl
);
725 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl
);
726 TELEM_ENABLE_PERIODIC(telem_ctrl
);
727 telem_ctrl
|= ioss_period
;
729 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
730 IOSS_TELEM_EVENT_CTL_WRITE
,
732 IOSS_TELEM_EVT_CTRL_WRITE_SIZE
,
735 pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
738 telm_conf
->ioss_config
.curr_period
= ioss_period
;
742 if (TELEM_SAMPLE_PERIOD_INVALID(pss_period
)) {
743 pr_err("PSS Sampling Period Out of Range\n");
748 /* Get telemetry EVENT CTL */
749 ret
= intel_punit_ipc_command(
750 IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL
,
751 0, 0, NULL
, &telem_ctrl
);
753 pr_err("PSS TELEM_CTRL Read Failed\n");
757 /* Disable Telemetry */
758 TELEM_DISABLE(telem_ctrl
);
759 ret
= intel_punit_ipc_command(
760 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
761 0, 0, &telem_ctrl
, NULL
);
763 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
767 /* Enable Periodic Telemetry Events and enable SRAM trace */
768 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl
);
769 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl
);
770 TELEM_ENABLE_PERIODIC(telem_ctrl
);
771 telem_ctrl
|= pss_period
;
773 ret
= intel_punit_ipc_command(
774 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL
,
775 0, 0, &telem_ctrl
, NULL
);
777 pr_err("PSS TELEM_CTRL Event Enable Write Failed\n");
780 telm_conf
->pss_config
.curr_period
= pss_period
;
784 mutex_unlock(&(telm_conf
->telem_lock
));
789 static int telemetry_plt_get_sampling_period(u8
*pss_min_period
,
794 *pss_min_period
= telm_conf
->pss_config
.min_period
;
795 *pss_max_period
= telm_conf
->pss_config
.max_period
;
796 *ioss_min_period
= telm_conf
->ioss_config
.min_period
;
797 *ioss_max_period
= telm_conf
->ioss_config
.max_period
;
803 static int telemetry_plt_reset_events(void)
805 struct telemetry_evtconfig pss_evtconfig
, ioss_evtconfig
;
808 pss_evtconfig
.evtmap
= NULL
;
809 pss_evtconfig
.num_evts
= TELEM_MAX_OS_ALLOCATED_EVENTS
;
810 pss_evtconfig
.period
= TELEM_SAMPLING_DEFAULT_PERIOD
;
812 ioss_evtconfig
.evtmap
= NULL
;
813 ioss_evtconfig
.num_evts
= TELEM_MAX_OS_ALLOCATED_EVENTS
;
814 ioss_evtconfig
.period
= TELEM_SAMPLING_DEFAULT_PERIOD
;
816 ret
= telemetry_setup_evtconfig(pss_evtconfig
, ioss_evtconfig
,
819 pr_err("TELEMETRY Reset Failed\n");
825 static int telemetry_plt_get_eventconfig(struct telemetry_evtconfig
*pss_config
,
826 struct telemetry_evtconfig
*ioss_config
,
827 int pss_len
, int ioss_len
)
829 u32
*pss_evtmap
, *ioss_evtmap
;
832 pss_evtmap
= pss_config
->evtmap
;
833 ioss_evtmap
= ioss_config
->evtmap
;
835 mutex_lock(&(telm_conf
->telem_lock
));
836 pss_config
->num_evts
= telm_conf
->pss_config
.ssram_evts_used
;
837 ioss_config
->num_evts
= telm_conf
->ioss_config
.ssram_evts_used
;
839 pss_config
->period
= telm_conf
->pss_config
.curr_period
;
840 ioss_config
->period
= telm_conf
->ioss_config
.curr_period
;
842 if ((pss_len
< telm_conf
->pss_config
.ssram_evts_used
) ||
843 (ioss_len
< telm_conf
->ioss_config
.ssram_evts_used
)) {
844 mutex_unlock(&(telm_conf
->telem_lock
));
848 for (index
= 0; index
< telm_conf
->pss_config
.ssram_evts_used
;
851 telm_conf
->pss_config
.telem_evts
[index
].evt_id
;
854 for (index
= 0; index
< telm_conf
->ioss_config
.ssram_evts_used
;
857 telm_conf
->ioss_config
.telem_evts
[index
].evt_id
;
860 mutex_unlock(&(telm_conf
->telem_lock
));
865 static int telemetry_plt_add_events(u8 num_pss_evts
, u8 num_ioss_evts
,
866 u32
*pss_evtmap
, u32
*ioss_evtmap
)
868 struct telemetry_evtconfig pss_evtconfig
, ioss_evtconfig
;
871 pss_evtconfig
.evtmap
= pss_evtmap
;
872 pss_evtconfig
.num_evts
= num_pss_evts
;
873 pss_evtconfig
.period
= telm_conf
->pss_config
.curr_period
;
875 ioss_evtconfig
.evtmap
= ioss_evtmap
;
876 ioss_evtconfig
.num_evts
= num_ioss_evts
;
877 ioss_evtconfig
.period
= telm_conf
->ioss_config
.curr_period
;
879 ret
= telemetry_setup_evtconfig(pss_evtconfig
, ioss_evtconfig
,
882 pr_err("TELEMETRY ADD Failed\n");
887 static int telem_evtlog_read(enum telemetry_unit telem_unit
,
888 struct telem_ssram_region
*ssram_region
, u8 len
)
890 struct telemetry_unit_config
*unit_config
;
891 u64 timestamp_prev
, timestamp_next
;
892 int ret
, index
, timeout
= 0;
894 ret
= telem_get_unitconfig(telem_unit
, &unit_config
);
898 if (len
> unit_config
->ssram_evts_used
)
899 len
= unit_config
->ssram_evts_used
;
902 timestamp_prev
= readq(unit_config
->regmap
);
903 if (!timestamp_prev
) {
904 pr_err("Ssram under update. Please Try Later\n");
908 ssram_region
->start_time
= readq(unit_config
->regmap
+
909 TELEM_SSRAM_STARTTIME_OFFSET
);
911 for (index
= 0; index
< len
; index
++) {
912 ssram_region
->events
[index
] =
913 readq(unit_config
->regmap
+ TELEM_SSRAM_EVTLOG_OFFSET
+
914 BYTES_PER_LONG
*index
);
917 timestamp_next
= readq(unit_config
->regmap
);
918 if (!timestamp_next
) {
919 pr_err("Ssram under update. Please Try Later\n");
923 if (timeout
++ > TELEM_SSRAM_READ_TIMEOUT
) {
924 pr_err("Timeout while reading Events\n");
928 } while (timestamp_prev
!= timestamp_next
);
930 ssram_region
->timestamp
= timestamp_next
;
935 static int telemetry_plt_raw_read_eventlog(enum telemetry_unit telem_unit
,
936 struct telemetry_evtlog
*evtlog
,
937 int len
, int log_all_evts
)
939 int index
, idx1
, ret
, readlen
= len
;
940 struct telem_ssram_region ssram_region
;
941 struct telemetry_evtmap
*evtmap
;
943 switch (telem_unit
) {
945 evtmap
= telm_conf
->pss_config
.telem_evts
;
949 evtmap
= telm_conf
->ioss_config
.telem_evts
;
953 pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit
);
958 readlen
= TELEM_MAX_EVENTS_SRAM
;
960 ret
= telem_evtlog_read(telem_unit
, &ssram_region
, readlen
);
964 /* Invalid evt-id array specified via length mismatch */
965 if ((!log_all_evts
) && (len
> ret
))
969 for (index
= 0; index
< ret
; index
++) {
970 evtlog
[index
].telem_evtlog
= ssram_region
.events
[index
];
971 evtlog
[index
].telem_evtid
= evtmap
[index
].evt_id
;
974 for (index
= 0, readlen
= 0; (index
< ret
) && (readlen
< len
);
976 for (idx1
= 0; idx1
< len
; idx1
++) {
977 /* Elements matched */
978 if (evtmap
[index
].evt_id
==
979 evtlog
[idx1
].telem_evtid
) {
980 evtlog
[idx1
].telem_evtlog
=
981 ssram_region
.events
[index
];
992 static int telemetry_plt_read_eventlog(enum telemetry_unit telem_unit
,
993 struct telemetry_evtlog
*evtlog
, int len
, int log_all_evts
)
997 mutex_lock(&(telm_conf
->telem_lock
));
998 ret
= telemetry_plt_raw_read_eventlog(telem_unit
, evtlog
,
1000 mutex_unlock(&(telm_conf
->telem_lock
));
1005 static int telemetry_plt_get_trace_verbosity(enum telemetry_unit telem_unit
,
1011 if (verbosity
== NULL
)
1014 mutex_lock(&(telm_conf
->telem_trace_lock
));
1015 switch (telem_unit
) {
1017 ret
= intel_punit_ipc_command(
1018 IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL
,
1021 pr_err("PSS TRACE_CTRL Read Failed\n");
1028 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
1029 IOSS_TELEM_TRACE_CTL_READ
, NULL
, 0, &temp
,
1030 IOSS_TELEM_READ_WORD
);
1032 pr_err("IOSS TRACE_CTL Read Failed\n");
1039 pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit
);
1043 TELEM_EXTRACT_VERBOSITY(temp
, *verbosity
);
1046 mutex_unlock(&(telm_conf
->telem_trace_lock
));
1050 static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit
,
1056 verbosity
&= TELEM_TRC_VERBOSITY_MASK
;
1058 mutex_lock(&(telm_conf
->telem_trace_lock
));
1059 switch (telem_unit
) {
1061 ret
= intel_punit_ipc_command(
1062 IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL
,
1065 pr_err("PSS TRACE_CTRL Read Failed\n");
1069 TELEM_CLEAR_VERBOSITY_BITS(temp
);
1070 TELEM_SET_VERBOSITY_BITS(temp
, verbosity
);
1072 ret
= intel_punit_ipc_command(
1073 IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL
,
1076 pr_err("PSS TRACE_CTRL Verbosity Set Failed\n");
1082 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
1083 IOSS_TELEM_TRACE_CTL_READ
, NULL
, 0, &temp
,
1084 IOSS_TELEM_READ_WORD
);
1086 pr_err("IOSS TRACE_CTL Read Failed\n");
1090 TELEM_CLEAR_VERBOSITY_BITS(temp
);
1091 TELEM_SET_VERBOSITY_BITS(temp
, verbosity
);
1093 ret
= intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY
,
1094 IOSS_TELEM_TRACE_CTL_WRITE
, (u8
*)&temp
,
1095 IOSS_TELEM_WRITE_FOURBYTES
, NULL
, 0);
1097 pr_err("IOSS TRACE_CTL Verbosity Set Failed\n");
1103 pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit
);
1109 mutex_unlock(&(telm_conf
->telem_trace_lock
));
1113 static const struct telemetry_core_ops telm_pltops
= {
1114 .get_trace_verbosity
= telemetry_plt_get_trace_verbosity
,
1115 .set_trace_verbosity
= telemetry_plt_set_trace_verbosity
,
1116 .set_sampling_period
= telemetry_plt_set_sampling_period
,
1117 .get_sampling_period
= telemetry_plt_get_sampling_period
,
1118 .raw_read_eventlog
= telemetry_plt_raw_read_eventlog
,
1119 .get_eventconfig
= telemetry_plt_get_eventconfig
,
1120 .update_events
= telemetry_plt_update_events
,
1121 .read_eventlog
= telemetry_plt_read_eventlog
,
1122 .reset_events
= telemetry_plt_reset_events
,
1123 .add_events
= telemetry_plt_add_events
,
1126 static int telemetry_pltdrv_probe(struct platform_device
*pdev
)
1128 struct resource
*res0
= NULL
, *res1
= NULL
;
1129 const struct x86_cpu_id
*id
;
1130 int size
, ret
= -ENOMEM
;
1132 id
= x86_match_cpu(telemetry_cpu_ids
);
1136 telm_conf
= (struct telemetry_plt_config
*)id
->driver_data
;
1138 res0
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1143 size
= resource_size(res0
);
1144 if (!devm_request_mem_region(&pdev
->dev
, res0
->start
, size
,
1149 telm_conf
->pss_config
.ssram_base_addr
= res0
->start
;
1150 telm_conf
->pss_config
.ssram_size
= size
;
1152 res1
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1157 size
= resource_size(res1
);
1158 if (!devm_request_mem_region(&pdev
->dev
, res1
->start
, size
,
1164 telm_conf
->ioss_config
.ssram_base_addr
= res1
->start
;
1165 telm_conf
->ioss_config
.ssram_size
= size
;
1167 telm_conf
->pss_config
.regmap
= ioremap_nocache(
1168 telm_conf
->pss_config
.ssram_base_addr
,
1169 telm_conf
->pss_config
.ssram_size
);
1170 if (!telm_conf
->pss_config
.regmap
) {
1175 telm_conf
->ioss_config
.regmap
= ioremap_nocache(
1176 telm_conf
->ioss_config
.ssram_base_addr
,
1177 telm_conf
->ioss_config
.ssram_size
);
1178 if (!telm_conf
->ioss_config
.regmap
) {
1183 mutex_init(&telm_conf
->telem_lock
);
1184 mutex_init(&telm_conf
->telem_trace_lock
);
1186 ret
= telemetry_setup(pdev
);
1190 ret
= telemetry_set_pltdata(&telm_pltops
, telm_conf
);
1192 dev_err(&pdev
->dev
, "TELEMETRY Set Pltops Failed.\n");
1200 release_mem_region(res0
->start
, resource_size(res0
));
1202 release_mem_region(res1
->start
, resource_size(res1
));
1203 if (telm_conf
->pss_config
.regmap
)
1204 iounmap(telm_conf
->pss_config
.regmap
);
1205 if (telm_conf
->ioss_config
.regmap
)
1206 iounmap(telm_conf
->ioss_config
.regmap
);
1207 dev_err(&pdev
->dev
, "TELEMETRY Setup Failed.\n");
1212 static int telemetry_pltdrv_remove(struct platform_device
*pdev
)
1214 telemetry_clear_pltdata();
1215 iounmap(telm_conf
->pss_config
.regmap
);
1216 iounmap(telm_conf
->ioss_config
.regmap
);
1221 static struct platform_driver telemetry_soc_driver
= {
1222 .probe
= telemetry_pltdrv_probe
,
1223 .remove
= telemetry_pltdrv_remove
,
1225 .name
= DRIVER_NAME
,
1229 static int __init
telemetry_module_init(void)
1231 return platform_driver_register(&telemetry_soc_driver
);
1234 static void __exit
telemetry_module_exit(void)
1236 platform_driver_unregister(&telemetry_soc_driver
);
1239 device_initcall(telemetry_module_init
);
1240 module_exit(telemetry_module_exit
);
1242 MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
1243 MODULE_DESCRIPTION("Intel SoC Telemetry Platform Driver");
1244 MODULE_VERSION(DRIVER_VERSION
);
1245 MODULE_LICENSE("GPL");