1 // SPDX-License-Identifier: GPL-2.0
3 * Intel SOC Telemetry Platform Driver: Currently supports APL
4 * Copyright (c) 2015, Intel Corporation.
7 * This file provides the platform specific telemetry implementation for APL.
8 * It used the PUNIT and PMC IPC interfaces for configuring the counters.
9 * The accumulated results are fetched from SRAM.
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
16 #include <asm/cpu_device_id.h>
17 #include <asm/intel-family.h>
18 #include <asm/intel_punit_ipc.h>
19 #include <asm/intel_telemetry.h>
21 #define DRIVER_NAME "intel_telemetry"
22 #define DRIVER_VERSION "1.0.0"
24 #define TELEM_TRC_VERBOSITY_MASK 0x3
26 #define TELEM_MIN_PERIOD(x) ((x) & 0x7F0000)
27 #define TELEM_MAX_PERIOD(x) ((x) & 0x7F000000)
28 #define TELEM_SAMPLE_PERIOD_INVALID(x) ((x) & (BIT(7)))
29 #define TELEM_CLEAR_SAMPLE_PERIOD(x) ((x) &= ~0x7F)
31 #define TELEM_SAMPLING_DEFAULT_PERIOD 0xD
33 #define TELEM_MAX_EVENTS_SRAM 28
34 #define TELEM_SSRAM_STARTTIME_OFFSET 8
35 #define TELEM_SSRAM_EVTLOG_OFFSET 16
37 #define IOSS_TELEM 0xeb
38 #define IOSS_TELEM_EVENT_READ 0x0
39 #define IOSS_TELEM_EVENT_WRITE 0x1
40 #define IOSS_TELEM_INFO_READ 0x2
41 #define IOSS_TELEM_TRACE_CTL_READ 0x5
42 #define IOSS_TELEM_TRACE_CTL_WRITE 0x6
43 #define IOSS_TELEM_EVENT_CTL_READ 0x7
44 #define IOSS_TELEM_EVENT_CTL_WRITE 0x8
45 #define IOSS_TELEM_EVT_WRITE_SIZE 0x3
47 #define TELEM_INFO_SRAMEVTS_MASK 0xFF00
48 #define TELEM_INFO_SRAMEVTS_SHIFT 0x8
49 #define TELEM_SSRAM_READ_TIMEOUT 10
51 #define TELEM_INFO_NENABLES_MASK 0xFF
52 #define TELEM_EVENT_ENABLE 0x8000
54 #define TELEM_MASK_BIT 1
55 #define TELEM_MASK_BYTE 0xFF
56 #define BYTES_PER_LONG 8
57 #define TELEM_MASK_PCS_STATE 0xF
59 #define TELEM_DISABLE(x) ((x) &= ~(BIT(31)))
60 #define TELEM_CLEAR_EVENTS(x) ((x) |= (BIT(30)))
61 #define TELEM_ENABLE_SRAM_EVT_TRACE(x) ((x) &= ~(BIT(30) | BIT(24)))
62 #define TELEM_ENABLE_PERIODIC(x) ((x) |= (BIT(23) | BIT(31) | BIT(7)))
63 #define TELEM_EXTRACT_VERBOSITY(x, y) ((y) = (((x) >> 27) & 0x3))
64 #define TELEM_CLEAR_VERBOSITY_BITS(x) ((x) &= ~(BIT(27) | BIT(28)))
65 #define TELEM_SET_VERBOSITY_BITS(x, y) ((x) |= ((y) << 27))
67 enum telemetry_action {
74 struct telem_ssram_region {
77 u64 events[TELEM_MAX_EVENTS_SRAM];
80 static struct telemetry_plt_config *telm_conf;
83 * The following counters are programmed by default during setup.
84 * Only 20 allocated to kernel driver
86 static struct telemetry_evtmap
87 telemetry_apl_ioss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
88 {"SOC_S0IX_TOTAL_RES", 0x4800},
89 {"SOC_S0IX_TOTAL_OCC", 0x4000},
90 {"SOC_S0IX_SHALLOW_RES", 0x4801},
91 {"SOC_S0IX_SHALLOW_OCC", 0x4001},
92 {"SOC_S0IX_DEEP_RES", 0x4802},
93 {"SOC_S0IX_DEEP_OCC", 0x4002},
94 {"PMC_POWER_GATE", 0x5818},
95 {"PMC_D3_STATES", 0x5819},
96 {"PMC_D0I3_STATES", 0x581A},
97 {"PMC_S0IX_WAKE_REASON_GPIO", 0x6000},
98 {"PMC_S0IX_WAKE_REASON_TIMER", 0x6001},
99 {"PMC_S0IX_WAKE_REASON_VNNREQ", 0x6002},
100 {"PMC_S0IX_WAKE_REASON_LOWPOWER", 0x6003},
101 {"PMC_S0IX_WAKE_REASON_EXTERNAL", 0x6004},
102 {"PMC_S0IX_WAKE_REASON_MISC", 0x6005},
103 {"PMC_S0IX_BLOCKING_IPS_D3_D0I3", 0x6006},
104 {"PMC_S0IX_BLOCKING_IPS_PG", 0x6007},
105 {"PMC_S0IX_BLOCKING_MISC_IPS_PG", 0x6008},
106 {"PMC_S0IX_BLOCK_IPS_VNN_REQ", 0x6009},
107 {"PMC_S0IX_BLOCK_IPS_CLOCKS", 0x600B},
111 static struct telemetry_evtmap
112 telemetry_apl_pss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
113 {"IA_CORE0_C6_RES", 0x0400},
114 {"IA_CORE0_C6_CTR", 0x0000},
115 {"IA_MODULE0_C7_RES", 0x0410},
116 {"IA_MODULE0_C7_CTR", 0x000E},
117 {"IA_C0_RES", 0x0805},
120 {"SOC_S0I3_RES", 0x0409},
121 {"SOC_S0I3_CTR", 0x000A},
122 {"PCS_S0I3_CTR", 0x0009},
123 {"PCS_C1E_RES", 0x041A},
124 {"PCS_IDLE_STATUS", 0x2806},
125 {"IA_PERF_LIMITS", 0x280B},
126 {"GT_PERF_LIMITS", 0x280C},
127 {"PCS_WAKEUP_S0IX_CTR", 0x0030},
128 {"PCS_IDLE_BLOCKED", 0x2C00},
129 {"PCS_S0IX_BLOCKED", 0x2C01},
130 {"PCS_S0IX_WAKE_REASONS", 0x2C02},
131 {"PCS_LTR_BLOCKING", 0x2C03},
132 {"PC2_AND_MEM_SHALLOW_IDLE_RES", 0x1D40},
135 static struct telemetry_evtmap
136 telemetry_glk_pss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
137 {"IA_CORE0_C6_RES", 0x0400},
138 {"IA_CORE0_C6_CTR", 0x0000},
139 {"IA_MODULE0_C7_RES", 0x0410},
140 {"IA_MODULE0_C7_CTR", 0x000C},
141 {"IA_C0_RES", 0x0805},
144 {"SOC_S0I3_RES", 0x0407},
145 {"SOC_S0I3_CTR", 0x0008},
146 {"PCS_S0I3_CTR", 0x0007},
147 {"PCS_C1E_RES", 0x0414},
148 {"PCS_IDLE_STATUS", 0x2806},
149 {"IA_PERF_LIMITS", 0x280B},
150 {"GT_PERF_LIMITS", 0x280C},
151 {"PCS_WAKEUP_S0IX_CTR", 0x0025},
152 {"PCS_IDLE_BLOCKED", 0x2C00},
153 {"PCS_S0IX_BLOCKED", 0x2C01},
154 {"PCS_S0IX_WAKE_REASONS", 0x2C02},
155 {"PCS_LTR_BLOCKING", 0x2C03},
156 {"PC2_AND_MEM_SHALLOW_IDLE_RES", 0x1D40},
159 /* APL specific Data */
160 static struct telemetry_plt_config telem_apl_config = {
162 .telem_evts = telemetry_apl_pss_default_events,
165 .telem_evts = telemetry_apl_ioss_default_events,
169 /* GLK specific Data */
170 static struct telemetry_plt_config telem_glk_config = {
172 .telem_evts = telemetry_glk_pss_default_events,
175 .telem_evts = telemetry_apl_ioss_default_events,
179 static const struct x86_cpu_id telemetry_cpu_ids[] = {
180 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT, &telem_apl_config),
181 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_PLUS, &telem_glk_config),
185 MODULE_DEVICE_TABLE(x86cpu, telemetry_cpu_ids);
187 static inline int telem_get_unitconfig(enum telemetry_unit telem_unit,
188 struct telemetry_unit_config **unit_config)
190 if (telem_unit == TELEM_PSS)
191 *unit_config = &(telm_conf->pss_config);
192 else if (telem_unit == TELEM_IOSS)
193 *unit_config = &(telm_conf->ioss_config);
201 static int telemetry_check_evtid(enum telemetry_unit telem_unit,
203 enum telemetry_action action)
205 struct telemetry_unit_config *unit_config;
208 ret = telem_get_unitconfig(telem_unit, &unit_config);
214 if (len > TELEM_MAX_EVENTS_SRAM)
220 if (len > TELEM_MAX_EVENTS_SRAM)
223 if ((len > 0) && (evtmap == NULL))
229 if ((len + unit_config->ssram_evts_used) >
230 TELEM_MAX_EVENTS_SRAM)
233 if ((len > 0) && (evtmap == NULL))
239 pr_err("Unknown Telemetry action specified %d\n", action);
247 static inline int telemetry_plt_config_ioss_event(u32 evt_id, int index)
251 write_buf = evt_id | TELEM_EVENT_ENABLE;
252 write_buf <<= BITS_PER_BYTE;
255 return intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
256 IOSS_TELEM_EVENT_WRITE, &write_buf,
257 IOSS_TELEM_EVT_WRITE_SIZE, NULL, 0);
260 static inline int telemetry_plt_config_pss_event(u32 evt_id, int index)
265 write_buf = evt_id | TELEM_EVENT_ENABLE;
266 ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT,
267 index, 0, &write_buf, NULL);
272 static int telemetry_setup_iossevtconfig(struct telemetry_evtconfig evtconfig,
273 enum telemetry_action action)
275 struct intel_scu_ipc_dev *scu = telm_conf->scu;
276 u8 num_ioss_evts, ioss_period;
281 num_ioss_evts = evtconfig.num_evts;
282 ioss_period = evtconfig.period;
283 ioss_evtmap = evtconfig.evtmap;
285 /* Get telemetry EVENT CTL */
286 ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
287 IOSS_TELEM_EVENT_CTL_READ, NULL, 0,
288 &telem_ctrl, sizeof(telem_ctrl));
290 pr_err("IOSS TELEM_CTRL Read Failed\n");
294 /* Disable Telemetry */
295 TELEM_DISABLE(telem_ctrl);
297 ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
298 IOSS_TELEM_EVENT_CTL_WRITE, &telem_ctrl,
299 sizeof(telem_ctrl), NULL, 0);
301 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
306 /* Reset Everything */
307 if (action == TELEM_RESET) {
308 /* Clear All Events */
309 TELEM_CLEAR_EVENTS(telem_ctrl);
311 ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
312 IOSS_TELEM_EVENT_CTL_WRITE,
313 &telem_ctrl, sizeof(telem_ctrl),
316 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
319 telm_conf->ioss_config.ssram_evts_used = 0;
321 /* Configure Events */
322 for (idx = 0; idx < num_ioss_evts; idx++) {
323 if (telemetry_plt_config_ioss_event(
324 telm_conf->ioss_config.telem_evts[idx].evt_id,
326 pr_err("IOSS TELEM_RESET Fail for data: %x\n",
327 telm_conf->ioss_config.telem_evts[idx].evt_id);
330 telm_conf->ioss_config.ssram_evts_used++;
334 /* Re-Configure Everything */
335 if (action == TELEM_UPDATE) {
336 /* Clear All Events */
337 TELEM_CLEAR_EVENTS(telem_ctrl);
339 ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
340 IOSS_TELEM_EVENT_CTL_WRITE,
341 &telem_ctrl, sizeof(telem_ctrl),
344 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
347 telm_conf->ioss_config.ssram_evts_used = 0;
349 /* Configure Events */
350 for (index = 0; index < num_ioss_evts; index++) {
351 telm_conf->ioss_config.telem_evts[index].evt_id =
354 if (telemetry_plt_config_ioss_event(
355 telm_conf->ioss_config.telem_evts[index].evt_id,
357 pr_err("IOSS TELEM_UPDATE Fail for Evt%x\n",
361 telm_conf->ioss_config.ssram_evts_used++;
365 /* Add some Events */
366 if (action == TELEM_ADD) {
367 /* Configure Events */
368 for (index = telm_conf->ioss_config.ssram_evts_used, idx = 0;
369 idx < num_ioss_evts; index++, idx++) {
370 telm_conf->ioss_config.telem_evts[index].evt_id =
373 if (telemetry_plt_config_ioss_event(
374 telm_conf->ioss_config.telem_evts[index].evt_id,
376 pr_err("IOSS TELEM_ADD Fail for Event %x\n",
380 telm_conf->ioss_config.ssram_evts_used++;
384 /* Enable Periodic Telemetry Events and enable SRAM trace */
385 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
386 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
387 TELEM_ENABLE_PERIODIC(telem_ctrl);
388 telem_ctrl |= ioss_period;
390 ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
391 IOSS_TELEM_EVENT_CTL_WRITE,
392 &telem_ctrl, sizeof(telem_ctrl), NULL, 0);
394 pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
398 telm_conf->ioss_config.curr_period = ioss_period;
404 static int telemetry_setup_pssevtconfig(struct telemetry_evtconfig evtconfig,
405 enum telemetry_action action)
407 u8 num_pss_evts, pss_period;
412 num_pss_evts = evtconfig.num_evts;
413 pss_period = evtconfig.period;
414 pss_evtmap = evtconfig.evtmap;
417 /* Get telemetry EVENT CTL */
418 ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL,
419 0, 0, NULL, &telem_ctrl);
421 pr_err("PSS TELEM_CTRL Read Failed\n");
425 /* Disable Telemetry */
426 TELEM_DISABLE(telem_ctrl);
427 ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
428 0, 0, &telem_ctrl, NULL);
430 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
434 /* Reset Everything */
435 if (action == TELEM_RESET) {
436 /* Clear All Events */
437 TELEM_CLEAR_EVENTS(telem_ctrl);
439 ret = intel_punit_ipc_command(
440 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
441 0, 0, &telem_ctrl, NULL);
443 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
446 telm_conf->pss_config.ssram_evts_used = 0;
447 /* Configure Events */
448 for (idx = 0; idx < num_pss_evts; idx++) {
449 if (telemetry_plt_config_pss_event(
450 telm_conf->pss_config.telem_evts[idx].evt_id,
452 pr_err("PSS TELEM_RESET Fail for Event %x\n",
453 telm_conf->pss_config.telem_evts[idx].evt_id);
456 telm_conf->pss_config.ssram_evts_used++;
460 /* Re-Configure Everything */
461 if (action == TELEM_UPDATE) {
462 /* Clear All Events */
463 TELEM_CLEAR_EVENTS(telem_ctrl);
465 ret = intel_punit_ipc_command(
466 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
467 0, 0, &telem_ctrl, NULL);
469 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
472 telm_conf->pss_config.ssram_evts_used = 0;
474 /* Configure Events */
475 for (index = 0; index < num_pss_evts; index++) {
476 telm_conf->pss_config.telem_evts[index].evt_id =
479 if (telemetry_plt_config_pss_event(
480 telm_conf->pss_config.telem_evts[index].evt_id,
482 pr_err("PSS TELEM_UPDATE Fail for Event %x\n",
486 telm_conf->pss_config.ssram_evts_used++;
490 /* Add some Events */
491 if (action == TELEM_ADD) {
492 /* Configure Events */
493 for (index = telm_conf->pss_config.ssram_evts_used, idx = 0;
494 idx < num_pss_evts; index++, idx++) {
496 telm_conf->pss_config.telem_evts[index].evt_id =
499 if (telemetry_plt_config_pss_event(
500 telm_conf->pss_config.telem_evts[index].evt_id,
502 pr_err("PSS TELEM_ADD Fail for Event %x\n",
506 telm_conf->pss_config.ssram_evts_used++;
510 /* Enable Periodic Telemetry Events and enable SRAM trace */
511 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
512 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
513 TELEM_ENABLE_PERIODIC(telem_ctrl);
514 telem_ctrl |= pss_period;
516 ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
517 0, 0, &telem_ctrl, NULL);
519 pr_err("PSS TELEM_CTRL Event Enable Write Failed\n");
523 telm_conf->pss_config.curr_period = pss_period;
528 static int telemetry_setup_evtconfig(struct telemetry_evtconfig pss_evtconfig,
529 struct telemetry_evtconfig ioss_evtconfig,
530 enum telemetry_action action)
534 mutex_lock(&(telm_conf->telem_lock));
536 if ((action == TELEM_UPDATE) && (telm_conf->telem_in_use)) {
541 ret = telemetry_check_evtid(TELEM_PSS, pss_evtconfig.evtmap,
542 pss_evtconfig.num_evts, action);
546 ret = telemetry_check_evtid(TELEM_IOSS, ioss_evtconfig.evtmap,
547 ioss_evtconfig.num_evts, action);
551 if (ioss_evtconfig.num_evts) {
552 ret = telemetry_setup_iossevtconfig(ioss_evtconfig, action);
557 if (pss_evtconfig.num_evts) {
558 ret = telemetry_setup_pssevtconfig(pss_evtconfig, action);
563 if ((action == TELEM_UPDATE) || (action == TELEM_ADD))
564 telm_conf->telem_in_use = true;
566 telm_conf->telem_in_use = false;
569 mutex_unlock(&(telm_conf->telem_lock));
573 static int telemetry_setup(struct platform_device *pdev)
575 struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;
576 u32 read_buf, events, event_regs;
579 ret = intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
580 IOSS_TELEM_INFO_READ, NULL, 0,
581 &read_buf, sizeof(read_buf));
583 dev_err(&pdev->dev, "IOSS TELEM_INFO Read Failed\n");
587 /* Get telemetry Info */
588 events = (read_buf & TELEM_INFO_SRAMEVTS_MASK) >>
589 TELEM_INFO_SRAMEVTS_SHIFT;
590 event_regs = read_buf & TELEM_INFO_NENABLES_MASK;
591 if ((events < TELEM_MAX_EVENTS_SRAM) ||
592 (event_regs < TELEM_MAX_EVENTS_SRAM)) {
593 dev_err(&pdev->dev, "IOSS:Insufficient Space for SRAM Trace\n");
594 dev_err(&pdev->dev, "SRAM Events %d; Event Regs %d\n",
599 telm_conf->ioss_config.min_period = TELEM_MIN_PERIOD(read_buf);
600 telm_conf->ioss_config.max_period = TELEM_MAX_PERIOD(read_buf);
602 /* PUNIT Mailbox Setup */
603 ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_INFO, 0, 0,
606 dev_err(&pdev->dev, "PSS TELEM_INFO Read Failed\n");
610 /* Get telemetry Info */
611 events = (read_buf & TELEM_INFO_SRAMEVTS_MASK) >>
612 TELEM_INFO_SRAMEVTS_SHIFT;
613 event_regs = read_buf & TELEM_INFO_SRAMEVTS_MASK;
614 if ((events < TELEM_MAX_EVENTS_SRAM) ||
615 (event_regs < TELEM_MAX_EVENTS_SRAM)) {
616 dev_err(&pdev->dev, "PSS:Insufficient Space for SRAM Trace\n");
617 dev_err(&pdev->dev, "SRAM Events %d; Event Regs %d\n",
622 telm_conf->pss_config.min_period = TELEM_MIN_PERIOD(read_buf);
623 telm_conf->pss_config.max_period = TELEM_MAX_PERIOD(read_buf);
625 pss_evtconfig.evtmap = NULL;
626 pss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
627 pss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
629 ioss_evtconfig.evtmap = NULL;
630 ioss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
631 ioss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
633 ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
636 dev_err(&pdev->dev, "TELEMETRY Setup Failed\n");
642 static int telemetry_plt_update_events(struct telemetry_evtconfig pss_evtconfig,
643 struct telemetry_evtconfig ioss_evtconfig)
647 if ((pss_evtconfig.num_evts > 0) &&
648 (TELEM_SAMPLE_PERIOD_INVALID(pss_evtconfig.period))) {
649 pr_err("PSS Sampling Period Out of Range\n");
653 if ((ioss_evtconfig.num_evts > 0) &&
654 (TELEM_SAMPLE_PERIOD_INVALID(ioss_evtconfig.period))) {
655 pr_err("IOSS Sampling Period Out of Range\n");
659 ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
662 pr_err("TELEMETRY Config Failed\n");
668 static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period)
673 mutex_lock(&(telm_conf->telem_lock));
675 struct intel_scu_ipc_dev *scu = telm_conf->scu;
677 if (TELEM_SAMPLE_PERIOD_INVALID(ioss_period)) {
678 pr_err("IOSS Sampling Period Out of Range\n");
683 /* Get telemetry EVENT CTL */
684 ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
685 IOSS_TELEM_EVENT_CTL_READ, NULL, 0,
686 &telem_ctrl, sizeof(telem_ctrl));
688 pr_err("IOSS TELEM_CTRL Read Failed\n");
692 /* Disable Telemetry */
693 TELEM_DISABLE(telem_ctrl);
695 ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
696 IOSS_TELEM_EVENT_CTL_WRITE,
697 &telem_ctrl, sizeof(telem_ctrl),
700 pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
704 /* Enable Periodic Telemetry Events and enable SRAM trace */
705 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
706 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
707 TELEM_ENABLE_PERIODIC(telem_ctrl);
708 telem_ctrl |= ioss_period;
710 ret = intel_scu_ipc_dev_command(scu, IOSS_TELEM,
711 IOSS_TELEM_EVENT_CTL_WRITE,
712 &telem_ctrl, sizeof(telem_ctrl),
715 pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
718 telm_conf->ioss_config.curr_period = ioss_period;
722 if (TELEM_SAMPLE_PERIOD_INVALID(pss_period)) {
723 pr_err("PSS Sampling Period Out of Range\n");
728 /* Get telemetry EVENT CTL */
729 ret = intel_punit_ipc_command(
730 IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL,
731 0, 0, NULL, &telem_ctrl);
733 pr_err("PSS TELEM_CTRL Read Failed\n");
737 /* Disable Telemetry */
738 TELEM_DISABLE(telem_ctrl);
739 ret = intel_punit_ipc_command(
740 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
741 0, 0, &telem_ctrl, NULL);
743 pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
747 /* Enable Periodic Telemetry Events and enable SRAM trace */
748 TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
749 TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
750 TELEM_ENABLE_PERIODIC(telem_ctrl);
751 telem_ctrl |= pss_period;
753 ret = intel_punit_ipc_command(
754 IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
755 0, 0, &telem_ctrl, NULL);
757 pr_err("PSS TELEM_CTRL Event Enable Write Failed\n");
760 telm_conf->pss_config.curr_period = pss_period;
764 mutex_unlock(&(telm_conf->telem_lock));
769 static int telemetry_plt_get_sampling_period(u8 *pss_min_period,
774 *pss_min_period = telm_conf->pss_config.min_period;
775 *pss_max_period = telm_conf->pss_config.max_period;
776 *ioss_min_period = telm_conf->ioss_config.min_period;
777 *ioss_max_period = telm_conf->ioss_config.max_period;
783 static int telemetry_plt_reset_events(void)
785 struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;
788 pss_evtconfig.evtmap = NULL;
789 pss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
790 pss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
792 ioss_evtconfig.evtmap = NULL;
793 ioss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
794 ioss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
796 ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
799 pr_err("TELEMETRY Reset Failed\n");
805 static int telemetry_plt_get_eventconfig(struct telemetry_evtconfig *pss_config,
806 struct telemetry_evtconfig *ioss_config,
807 int pss_len, int ioss_len)
809 u32 *pss_evtmap, *ioss_evtmap;
812 pss_evtmap = pss_config->evtmap;
813 ioss_evtmap = ioss_config->evtmap;
815 mutex_lock(&(telm_conf->telem_lock));
816 pss_config->num_evts = telm_conf->pss_config.ssram_evts_used;
817 ioss_config->num_evts = telm_conf->ioss_config.ssram_evts_used;
819 pss_config->period = telm_conf->pss_config.curr_period;
820 ioss_config->period = telm_conf->ioss_config.curr_period;
822 if ((pss_len < telm_conf->pss_config.ssram_evts_used) ||
823 (ioss_len < telm_conf->ioss_config.ssram_evts_used)) {
824 mutex_unlock(&(telm_conf->telem_lock));
828 for (index = 0; index < telm_conf->pss_config.ssram_evts_used;
831 telm_conf->pss_config.telem_evts[index].evt_id;
834 for (index = 0; index < telm_conf->ioss_config.ssram_evts_used;
837 telm_conf->ioss_config.telem_evts[index].evt_id;
840 mutex_unlock(&(telm_conf->telem_lock));
845 static int telemetry_plt_add_events(u8 num_pss_evts, u8 num_ioss_evts,
846 u32 *pss_evtmap, u32 *ioss_evtmap)
848 struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;
851 pss_evtconfig.evtmap = pss_evtmap;
852 pss_evtconfig.num_evts = num_pss_evts;
853 pss_evtconfig.period = telm_conf->pss_config.curr_period;
855 ioss_evtconfig.evtmap = ioss_evtmap;
856 ioss_evtconfig.num_evts = num_ioss_evts;
857 ioss_evtconfig.period = telm_conf->ioss_config.curr_period;
859 ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
862 pr_err("TELEMETRY ADD Failed\n");
867 static int telem_evtlog_read(enum telemetry_unit telem_unit,
868 struct telem_ssram_region *ssram_region, u8 len)
870 struct telemetry_unit_config *unit_config;
871 u64 timestamp_prev, timestamp_next;
872 int ret, index, timeout = 0;
874 ret = telem_get_unitconfig(telem_unit, &unit_config);
878 if (len > unit_config->ssram_evts_used)
879 len = unit_config->ssram_evts_used;
882 timestamp_prev = readq(unit_config->regmap);
883 if (!timestamp_prev) {
884 pr_err("Ssram under update. Please Try Later\n");
888 ssram_region->start_time = readq(unit_config->regmap +
889 TELEM_SSRAM_STARTTIME_OFFSET);
891 for (index = 0; index < len; index++) {
892 ssram_region->events[index] =
893 readq(unit_config->regmap + TELEM_SSRAM_EVTLOG_OFFSET +
894 BYTES_PER_LONG*index);
897 timestamp_next = readq(unit_config->regmap);
898 if (!timestamp_next) {
899 pr_err("Ssram under update. Please Try Later\n");
903 if (timeout++ > TELEM_SSRAM_READ_TIMEOUT) {
904 pr_err("Timeout while reading Events\n");
908 } while (timestamp_prev != timestamp_next);
910 ssram_region->timestamp = timestamp_next;
915 static int telemetry_plt_raw_read_eventlog(enum telemetry_unit telem_unit,
916 struct telemetry_evtlog *evtlog,
917 int len, int log_all_evts)
919 int index, idx1, ret, readlen = len;
920 struct telem_ssram_region ssram_region;
921 struct telemetry_evtmap *evtmap;
923 switch (telem_unit) {
925 evtmap = telm_conf->pss_config.telem_evts;
929 evtmap = telm_conf->ioss_config.telem_evts;
933 pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit);
938 readlen = TELEM_MAX_EVENTS_SRAM;
940 ret = telem_evtlog_read(telem_unit, &ssram_region, readlen);
944 /* Invalid evt-id array specified via length mismatch */
945 if ((!log_all_evts) && (len > ret))
949 for (index = 0; index < ret; index++) {
950 evtlog[index].telem_evtlog = ssram_region.events[index];
951 evtlog[index].telem_evtid = evtmap[index].evt_id;
954 for (index = 0, readlen = 0; (index < ret) && (readlen < len);
956 for (idx1 = 0; idx1 < len; idx1++) {
957 /* Elements matched */
958 if (evtmap[index].evt_id ==
959 evtlog[idx1].telem_evtid) {
960 evtlog[idx1].telem_evtlog =
961 ssram_region.events[index];
972 static int telemetry_plt_read_eventlog(enum telemetry_unit telem_unit,
973 struct telemetry_evtlog *evtlog, int len, int log_all_evts)
977 mutex_lock(&(telm_conf->telem_lock));
978 ret = telemetry_plt_raw_read_eventlog(telem_unit, evtlog,
980 mutex_unlock(&(telm_conf->telem_lock));
985 static int telemetry_plt_get_trace_verbosity(enum telemetry_unit telem_unit,
991 if (verbosity == NULL)
994 mutex_lock(&(telm_conf->telem_trace_lock));
995 switch (telem_unit) {
997 ret = intel_punit_ipc_command(
998 IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL,
1001 pr_err("PSS TRACE_CTRL Read Failed\n");
1008 ret = intel_scu_ipc_dev_command(telm_conf->scu,
1009 IOSS_TELEM, IOSS_TELEM_TRACE_CTL_READ,
1010 NULL, 0, &temp, sizeof(temp));
1012 pr_err("IOSS TRACE_CTL Read Failed\n");
1019 pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit);
1023 TELEM_EXTRACT_VERBOSITY(temp, *verbosity);
1026 mutex_unlock(&(telm_conf->telem_trace_lock));
1030 static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit,
1036 verbosity &= TELEM_TRC_VERBOSITY_MASK;
1038 mutex_lock(&(telm_conf->telem_trace_lock));
1039 switch (telem_unit) {
1041 ret = intel_punit_ipc_command(
1042 IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL,
1045 pr_err("PSS TRACE_CTRL Read Failed\n");
1049 TELEM_CLEAR_VERBOSITY_BITS(temp);
1050 TELEM_SET_VERBOSITY_BITS(temp, verbosity);
1052 ret = intel_punit_ipc_command(
1053 IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL,
1056 pr_err("PSS TRACE_CTRL Verbosity Set Failed\n");
1062 ret = intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
1063 IOSS_TELEM_TRACE_CTL_READ,
1064 NULL, 0, &temp, sizeof(temp));
1066 pr_err("IOSS TRACE_CTL Read Failed\n");
1070 TELEM_CLEAR_VERBOSITY_BITS(temp);
1071 TELEM_SET_VERBOSITY_BITS(temp, verbosity);
1073 ret = intel_scu_ipc_dev_command(telm_conf->scu, IOSS_TELEM,
1074 IOSS_TELEM_TRACE_CTL_WRITE,
1075 &temp, sizeof(temp), NULL, 0);
1077 pr_err("IOSS TRACE_CTL Verbosity Set Failed\n");
1083 pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit);
1089 mutex_unlock(&(telm_conf->telem_trace_lock));
1093 static const struct telemetry_core_ops telm_pltops = {
1094 .get_trace_verbosity = telemetry_plt_get_trace_verbosity,
1095 .set_trace_verbosity = telemetry_plt_set_trace_verbosity,
1096 .set_sampling_period = telemetry_plt_set_sampling_period,
1097 .get_sampling_period = telemetry_plt_get_sampling_period,
1098 .raw_read_eventlog = telemetry_plt_raw_read_eventlog,
1099 .get_eventconfig = telemetry_plt_get_eventconfig,
1100 .update_events = telemetry_plt_update_events,
1101 .read_eventlog = telemetry_plt_read_eventlog,
1102 .reset_events = telemetry_plt_reset_events,
1103 .add_events = telemetry_plt_add_events,
1106 static int telemetry_pltdrv_probe(struct platform_device *pdev)
1108 const struct x86_cpu_id *id;
1112 id = x86_match_cpu(telemetry_cpu_ids);
1116 telm_conf = (struct telemetry_plt_config *)id->driver_data;
1118 telm_conf->pmc = dev_get_drvdata(pdev->dev.parent);
1120 mem = devm_platform_ioremap_resource(pdev, 0);
1122 return PTR_ERR(mem);
1124 telm_conf->pss_config.regmap = mem;
1126 mem = devm_platform_ioremap_resource(pdev, 1);
1128 return PTR_ERR(mem);
1130 telm_conf->ioss_config.regmap = mem;
1132 telm_conf->scu = devm_intel_scu_ipc_dev_get(&pdev->dev);
1133 if (!telm_conf->scu) {
1134 ret = -EPROBE_DEFER;
1138 mutex_init(&telm_conf->telem_lock);
1139 mutex_init(&telm_conf->telem_trace_lock);
1141 ret = telemetry_setup(pdev);
1145 ret = telemetry_set_pltdata(&telm_pltops, telm_conf);
1147 dev_err(&pdev->dev, "TELEMETRY Set Pltops Failed.\n");
1154 dev_err(&pdev->dev, "TELEMETRY Setup Failed.\n");
1159 static void telemetry_pltdrv_remove(struct platform_device *pdev)
1161 telemetry_clear_pltdata();
1164 static struct platform_driver telemetry_soc_driver = {
1165 .probe = telemetry_pltdrv_probe,
1166 .remove_new = telemetry_pltdrv_remove,
1168 .name = DRIVER_NAME,
1172 static int __init telemetry_module_init(void)
1174 return platform_driver_register(&telemetry_soc_driver);
1177 static void __exit telemetry_module_exit(void)
1179 platform_driver_unregister(&telemetry_soc_driver);
1182 device_initcall(telemetry_module_init);
1183 module_exit(telemetry_module_exit);
1186 MODULE_DESCRIPTION("Intel SoC Telemetry Platform Driver");
1187 MODULE_VERSION(DRIVER_VERSION);
1188 MODULE_LICENSE("GPL v2");